From patchwork Thu Dec 2 11:34:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 519796 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3E729C433F5 for ; Thu, 2 Dec 2021 11:36:12 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 3F67222B5; Thu, 2 Dec 2021 12:35:20 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3F67222B5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1638444970; bh=agmJzAQ1MoRM9B2+a09h/RR89PgyfOJv4xMOLZ8w5wA=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=nrPJxwNV1iZs9SYuKYKuieYxlT/7/9uscvSYrj9DfaMgaDbht9SlEWYfNH2DStEIz sHd59x5/fKex9mW5JmuAqs7Z4X2G+xWdFKwhTQFVgVvVB7MGLtf0z6ZUDuGmTK6TwO 0aReE9+r9qz88lxFuCTrzZKQW8Pwv0FGUSUheq7o= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id BB4BAF802A0; Thu, 2 Dec 2021 12:35:19 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 44E3BF802E0; Thu, 2 Dec 2021 12:35:16 +0100 (CET) Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 22DBEF80290 for ; Thu, 2 Dec 2021 12:35:09 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 22DBEF80290 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="eODUng27"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QND3Ro8D" Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id E22373201EDB; Thu, 2 Dec 2021 06:35:06 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 02 Dec 2021 06:35:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=0y8JtbsXVyFw0 RGJTPJqwQvMuOVwejmh9Kq9P1lRwxQ=; b=eODUng27DWwejB7P9HVvxYeGT0+8j ebPEpJqGJx3oVD2ZIEiI9iOK36p41VeUDKV+fnqlpMiQq5eT6BQFu3txEXwC1buU Ypkj87PkBoQOGc0tBVxfC0Vak/XsuHFXjuneY7KJ2ZoAXm0AlBjrIgvGYExQv+9T FBM2y8lB26UrWuWLpzU43wH5ygOiCLT+2WBACXrSRx65Ot44auATm6a8CH7WAglq jjjl4j+WdcnlLNbxsDTr/O/yPXQkf3+TsQcQ7yISDr/KRGDo0GRqNK90adMi58lN nMmO5Tx0YN2Yf0+ptP59KZOZQ8Lh9r1BVJ2BskTtjxcwH0bt/F2XPDKcg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=0y8JtbsXVyFw0RGJTPJqwQvMuOVwejmh9Kq9P1lRwxQ=; b=QND3Ro8D xOJYg+suVQIVpxhWtd3MEI9VN0R3zoKvpBMw+PIwadUh19FV2lH6iNlpX99XqeVy xshZSLPbB9Xw9kAvNMLIe0nLqa1jfOCSE23+w+f5C60FtOOaKXsASpK1YSBFNwiZ 8eAbWHtzbk4MDEyCJrnU368FRfuGOPBcRH6v79BgH3BxAeKva9qu2LwdaeSiJKO+ M9dBoxSSz44t6PIKeXiQlhNyO8G5LiI5RK31KQB0gqG4/5qeWZwlWntI5+SVpBOp jxg7dcTjf443Aa67I2qhqZ9/y/uqQ90kw7acaU5EdkvIHcQh/niNcA7g/q3WrOWh IgnZAnjgUMS37Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrieehgdeftdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghkrghs hhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpeevfefffeekte fgveegfeelheffhfeujedtjeevtefhkeevkedtjeejvddtjefhjeenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhisehsrg hkrghmohgttghhihdrjhhp X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 2 Dec 2021 06:35:04 -0500 (EST) From: Takashi Sakamoto To: stefanr@s5r6.in-berlin.de Subject: [PATCH 1/3] firewire: Add dummy read_csr/write_csr functions Date: Thu, 2 Dec 2021 20:34:55 +0900 Message-Id: <20211202113457.24011-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211202113457.24011-1-o-takashi@sakamocchi.jp> References: <20211202113457.24011-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, linux1394-devel@lists.sourceforge.net, clemens@ladisch.de, linux-kernel@vger.kernel.org, marcan@marcan.st X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" From: Hector Martin (Hector Martin wrote) This fixes segfaults when a card gets yanked off of the PCIe bus while busy, e.g. with a userspace app trying to get the cycle time: [8638860.994310] Call Trace: [8638860.994313] ioctl_get_cycle_timer2+0x4f/0xd0 [firewire_core] [8638860.994323] fw_device_op_ioctl+0xae/0x150 [firewire_core] [8638860.994328] __x64_sys_ioctl+0x7d/0xb0 [8638860.994332] do_syscall_64+0x45/0x80 [8638860.994337] entry_SYSCALL_64_after_hwframe+0x44/0xae (Takashi Sakamoto wrote) As long as reading commit 20802224298c ("firewire: core: add forgotten dummy driver methods, remove unused ones"), three functions are not implemeted in dummy driver for reason; .read_csr, .write_csr, and .set_config_rom. In core of Linux FireWire subsystem, the callback of .set_config_rom is under acquisition of mutual exclusive for local list of card. The acquision is also done in process for removal of card, therefore it's safe for missing implementation of .set_config_rom. On the other hand, no lock primitive accompanies any call of .read_csr and .write_csr. For userspace client, check of node shutdown is done in the beginning of dispatch of ioctl request, while node shifts to shutdown state in workqueue context enough after card shifts to dummy driver. It's probable that these two functions are called for the dummy driver by the code of userspace client. In-kernel unit driver has similar situation. It's better to add implementation of the two functions for dummy driver. Signed-off-by: Hector Martin Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-card.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c index 54be88167c60..d994da6cf465 100644 --- a/drivers/firewire/core-card.c +++ b/drivers/firewire/core-card.c @@ -616,6 +616,15 @@ static struct fw_iso_context *dummy_allocate_iso_context(struct fw_card *card, return ERR_PTR(-ENODEV); } +static u32 dummy_read_csr(struct fw_card *card, int csr_offset) +{ + return 0; +} + +static void dummy_write_csr(struct fw_card *card, int csr_offset, u32 value) +{ +} + static int dummy_start_iso(struct fw_iso_context *ctx, s32 cycle, u32 sync, u32 tags) { @@ -649,6 +658,8 @@ static const struct fw_card_driver dummy_driver_template = { .send_response = dummy_send_response, .cancel_packet = dummy_cancel_packet, .enable_phys_dma = dummy_enable_phys_dma, + .read_csr = dummy_read_csr, + .write_csr = dummy_write_csr, .allocate_iso_context = dummy_allocate_iso_context, .start_iso = dummy_start_iso, .set_iso_channels = dummy_set_iso_channels, From patchwork Thu Dec 2 11:34:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 519795 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A7B54C433F5 for ; Thu, 2 Dec 2021 11:37:04 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 625622594; Thu, 2 Dec 2021 12:36:12 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 625622594 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1638445022; bh=Hc3nIev0ZEDH1IY5gZ57/Pl56H7Z3NbgHG0+3yzo9Io=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=P3+w9bTGefT6f/vOxELXerklk+rdY1IsuEfSQhwCXgBpfGXNYkQ/dxtk72khAfPM1 WliS9w7Q6TNvd89wDxifQl1nLQOEFLvi1EcakbnYJwCbSQ+eYbb7VRvP11+pvNikTB 3Uj7W/lTQ+UlBWW+48fca4ZJ1ICmS+A2hUZwvXZk= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 496F4F804EC; Thu, 2 Dec 2021 12:35:25 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 27AC6F804AD; Thu, 2 Dec 2021 12:35:23 +0100 (CET) Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 10D19F800EE for ; Thu, 2 Dec 2021 12:35:13 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 10D19F800EE Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="LFxFkEKN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="H2MbYVzw" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id DCB5E3200FA9; Thu, 2 Dec 2021 06:35:10 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 02 Dec 2021 06:35:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=dSfEsYJV8YT9G 1mY+w+3xNKGP/jLbaYvgOYk7MgI61U=; b=LFxFkEKNZPPy+UrCGmddyYj4Yfucl 1oH7uT0osUDuvU/E00EgKYNj6kciaOeNHK0sPoQkiGzjyV//d7nz/L6O1K0VYKdR emRZFjNvQL4KzUtZfb7prMMX4KVAaRYd4lShb14vg6aCJORHFABKCQ5sy73hcpez tYwpYkhrj3qGnipxLtjQ9pUmJRnfalPRlUVoImGefW6fn+QJedL+Nzm1eRr79wff C4EXTliiOhtvzbxg7VCvE4unKaSnPo0GkgsUQLMg28CQrjiNKDqH3RGSGz/SX9L/ DDh7MGQr7ChMmFrLAIcZ6oIqc4hDivRYqRmV3vFYXYp8MAlXCJXsIaauQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=dSfEsYJV8YT9G1mY+w+3xNKGP/jLbaYvgOYk7MgI61U=; b=H2MbYVzw irJUbwSjyntpffnMwaKAhWbZLmAJM9P2j1/X8ffK3OFzfVFcqI60Nx/elApANE0F KYyABJ10LaVIyfwaF4nr5mym3uo5aqthfg8Qw/04rsUq7I68ysKfFpnlG0eNtTW1 KGRxcj3eElEjswcHNtVNaTZibrhnC1/g4zOguiIqiVYXY0u2fE2lzCD8KfpUZRJJ Khy0U+yroKjaDIRn/VbzTaQ3WNEplHQ6nIoEYgDYU3yIDd/GycoWTC+LP3gujDsb tpTpKl0Pr6L9goCN7OANEQGvyHAAo1k+U0nvg3YbRcgjFr3SAJ/EAvIDdzxN2svS baPASCXp3ObzJQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrieehgdeftdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghkrghs hhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpeevfefffeekte fgveegfeelheffhfeujedtjeevtefhkeevkedtjeejvddtjefhjeenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhisehsrg hkrghmohgttghhihdrjhhp X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 2 Dec 2021 06:35:08 -0500 (EST) From: Takashi Sakamoto To: stefanr@s5r6.in-berlin.de Subject: [PATCH 2/3] firewire: add kernel API to access CYCLE_TIME register Date: Thu, 2 Dec 2021 20:34:56 +0900 Message-Id: <20211202113457.24011-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211202113457.24011-1-o-takashi@sakamocchi.jp> References: <20211202113457.24011-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, linux1394-devel@lists.sourceforge.net, clemens@ladisch.de, linux-kernel@vger.kernel.org, marcan@marcan.st X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" 1394 OHCI specification defined Isochronous Cycle Timer Register to get value of CYCLE_TIME register defined by IEEE 1394 for CSR architecture defined by ISO/IEC 13213. Unit driver can calculate packet time by compute with the value of CYCLE_TIME and timeStamp field in descriptor of each isochronous and asynchronous context. The resolution of CYCLE_TIME is 49.576 MHz, while the one of timeStamp is 8,000 Hz. Current implementation of Linux FireWire subsystem allows the driver to get the value of CYCLE_TIMER CSR register by transaction service. The transaction service has overhead in regard of access to MMIO register. This commit adds kernel API for unit driver to access the register directly. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-card.c | 28 ++++++++++++++++++++++++++++ drivers/firewire/core-cdev.c | 6 ++++-- include/linux/firewire.h | 2 ++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c index d994da6cf465..cd09de61bc4f 100644 --- a/drivers/firewire/core-card.c +++ b/drivers/firewire/core-card.c @@ -702,3 +702,31 @@ void fw_core_remove_card(struct fw_card *card) WARN_ON(!list_empty(&card->transaction_list)); } EXPORT_SYMBOL(fw_core_remove_card); + +/** + * fw_card_read_cycle_time: read from Isochronous Cycle Timer Register of 1394 OHCI in MMIO region + * for controller card. + * @card: The instance of card for 1394 OHCI controller. + * @cycle_time: The mutual reference to value of cycle time for the read operation. + * + * Read value from Isochronous Cycle Timer Register of 1394 OHCI in MMIO region for the given + * controller card. This function accesses the region without any lock primitives or IRQ mask. + * When returning successfully, the content of @value argument has value aligned to host endianness, + * formetted by CYCLE_TIME CSR Register of IEEE 1394 std. + * + * Context: Any context. + * Return: + * * 0 - Read successfully. + * * -ENODEV - The controller is unavailable due to being removed or unbound. + */ +int fw_card_read_cycle_time(struct fw_card *card, u32 *cycle_time) +{ + if (card->driver->read_csr == dummy_read_csr) + return -ENODEV; + + // It's possible to switch to dummy driver between the above and the below. This is the best + // effort to return -ENODEV. + *cycle_time = card->driver->read_csr(card, CSR_CYCLE_TIME); + return 0; +} +EXPORT_SYMBOL_GPL(fw_card_read_cycle_time); diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 9f89c17730b1..8e9670036e5c 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -1216,7 +1216,9 @@ static int ioctl_get_cycle_timer2(struct client *client, union ioctl_arg *arg) local_irq_disable(); - cycle_time = card->driver->read_csr(card, CSR_CYCLE_TIME); + ret = fw_card_read_cycle_time(card, &cycle_time); + if (ret < 0) + goto end; switch (a->clk_id) { case CLOCK_REALTIME: ktime_get_real_ts64(&ts); break; @@ -1225,7 +1227,7 @@ static int ioctl_get_cycle_timer2(struct client *client, union ioctl_arg *arg) default: ret = -EINVAL; } - +end: local_irq_enable(); a->tv_sec = ts.tv_sec; diff --git a/include/linux/firewire.h b/include/linux/firewire.h index 07967a450eaa..2f467c52bdec 100644 --- a/include/linux/firewire.h +++ b/include/linux/firewire.h @@ -150,6 +150,8 @@ static inline void fw_card_put(struct fw_card *card) kref_put(&card->kref, fw_card_release); } +int fw_card_read_cycle_time(struct fw_card *card, u32 *cycle_time); + struct fw_attribute_group { struct attribute_group *groups[2]; struct attribute_group group;