From patchwork Sat Mar 25 07:02:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13187637 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66929C6FD1F for ; Sat, 25 Mar 2023 07:02:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231915AbjCYHCh (ORCPT ); Sat, 25 Mar 2023 03:02:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231417AbjCYHCg (ORCPT ); Sat, 25 Mar 2023 03:02:36 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E69914200 for ; Sat, 25 Mar 2023 00:02:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1679727753; x=1711263753; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1e2OamP7r55F0zsilJj9y5bwk7gTaGYciJ+mu0rhE98=; b=kRvbWJjgax8FPuGQVQMF/NeL5bPrGyfj87LZ2EHXOufZkxZ/km0HzQaS UbQOajBinIdPISrdSTUm3RDrIw/qfFSo+sHYVbXLsUQl7SICSdpQY9a+W GKEQXTOIfLybuLD5jFstVsZBAMGGFdtlho8T12ARFT9SQZkuCRtMQhLUe zV/pNDpWKzqmSFvDvuchn4m+04XHpGyGVde+Y5Z0mqmHg66WneyuyuKOv 7hmEoo40pfXui2LTy9+B1U5VeEH6laeMkAx/p3xSbLSNmf+KCCPxoorxO HcYCL0iixNjZ5A/AyHZpzf2YY8g86OVRzruBBCl0LlP2gLnaOm5Dmo0AR g==; X-IronPort-AV: E=Sophos;i="5.98,289,1673884800"; d="scan'208";a="224756679" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2023 15:02:33 +0800 IronPort-SDR: /NO65C1rKtMomlKX6ejNEOD49Rzo22lMOkmRX3EvWXqUUvW4b0vIX+Yr9uAgeKUFJo7BxTznY4 iGGU1eR2mFcGXzBC32GPbg/cvLf1BguuRv5uStAKzxn271PmdbseIulCd6yAlxP/I4X3OTm0az bzkeLnA7kD8UlqbhI72ZXUA6D7HwmdqFdYFMcrPTLIsl1tR/ZC4fRiK6YKmoFI2uosKIgAYOSh dFhLgD+H7M3PtUUDkNe7YTA/NT95bH4FOgpUSdPrU/cDEOSxRM7PvekZIK+QOgPDPRjeErCH0y drY= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Mar 2023 23:18:48 -0700 IronPort-SDR: PosaadPInUzQFFvCvqevdXjn49ruPX55Dm2hnNRLXl/Xu2h86L065uhjmJlkDZTNYSZDYvlzfZ yxEXMqL/sDwwsm3RbgML3arlC04puwzDA/6SG+8ANdMttVt+G2olbGOusfMIRa2FcgSyliPCo/ fpv6fT7Hh43qgfm0IxTsq1VJuDrFwv+oR/t5hMlRGasFq8I7JJ/MDMl2+BM2Ou3V1aEstC8c8o Sa38NaEhyqK3gH1f8waffCtBsmEScP/+LS23WLegoL2kz1LE+7c5QCHuCRhcngopXAbB/j/675 82Y= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Mar 2023 00:02:34 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pk94n2rQ8z1RtVt for ; Sat, 25 Mar 2023 00:02:33 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1679727751; x=1682319752; bh=1e2OamP7r55F0zsilJ j9y5bwk7gTaGYciJ+mu0rhE98=; b=A8pdAbjuaKZ82IdiH2QaLy1bmqtA0DY3VK pOf7W8sj7yUJXR+kRQtpFJd9w0KFwPJkoZta0jGCGf0p8enPa94tSCeMTPdTYubs Methl+2R7xCAkVlvHKb2yQth3wLF+sq3xdoqYJFD0CHnjSpgPSckgHkGodZv9CCW qsujkEqOVj1kASrYfx1mJt/5utlOsFudi6D+J5jjB1fGSoj6JBKJp58qlWIewB/4 +2GLJbYGulllgaV/rhn+x4eJnnABcoY52QOu+iXuGH47BkaLkEi1WbxCepY9Cz8C AtAAzwOnJx3JjRfASffRYh7CKhCJ2tGxCTBM6kVf/VWz7YYSQIoQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id DK7yuC5Lqy1n for ; Sat, 25 Mar 2023 00:02:31 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pk94j5w4bz1RtVn; Sat, 25 Mar 2023 00:02:29 -0700 (PDT) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v3 01/16] PCI: endpoint: Automatically create a function specific attributes group Date: Sat, 25 Mar 2023 16:02:11 +0900 Message-Id: <20230325070226.511323-2-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> References: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org A PCI endpoint function driver can define function specific attributes under its function configfs directory using the add_cfs() endpoint driver operation. This is done by tighing up the mkdir operation for the function configfs directory to a call to the add_cfs() operation. However, there are no checks preventing the user from repeatedly creating function specific attribute directories with different names, resulting in the same endpoint specific attributes group being added multiple times, which also result in an invalid reference counting for the attribute groups. E.g., using the pci-epf-ntb function driver as an example, the user creates the function as follows: $ modprobe pci-epf-ntb $ cd /sys/kernel/config/pci_ep/functions/pci_epf_ntb $ mkdir func0 $ tree func0 func0/ |-- baseclass_code |-- cache_line_size |-- ... `-- vendorid $ mkdir func0/attrs $ tree func0 func0/ |-- attrs | |-- db_count | |-- mw1 | |-- mw2 | |-- mw3 | |-- mw4 | |-- num_mws | `-- spad_count |-- baseclass_code |-- cache_line_size |-- ... `-- vendorid At this point, the function can be started by linking the EP controller. However, if the user mistakenly creates again a directory: $ mkdir func0/attrs2 $ tree func0 func0/ |-- attrs | |-- db_count | |-- mw1 | |-- mw2 | |-- mw3 | |-- mw4 | |-- num_mws | `-- spad_count |-- attrs2 | |-- db_count | |-- mw1 | |-- mw2 | |-- mw3 | |-- mw4 | |-- num_mws | `-- spad_count |-- baseclass_code |-- cache_line_size |-- ... `-- vendorid The function specific attributes are duplicated and cause a crash when the function is tore down: [ 9740.729598] ------------[ cut here ]------------ [ 9740.730071] refcount_t: addition on 0; use-after-free. [ 9740.730564] WARNING: CPU: 2 PID: 834 at lib/refcount.c:25 refcount_warn_saturate+0xc8/0x144 [ 9740.735593] CPU: 2 PID: 834 Comm: rmdir Not tainted 6.3.0-rc1 #1 [ 9740.736133] Hardware name: Pine64 RockPro64 v2.1 (DT) [ 9740.736586] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 9740.737210] pc : refcount_warn_saturate+0xc8/0x144 [ 9740.737648] lr : refcount_warn_saturate+0xc8/0x144 [ 9740.738085] sp : ffff800009cebc90 [ 9740.738385] x29: ffff800009cebc90 x28: ffff0000019ed700 x27: ffff0000040c3900 [ 9740.739032] x26: 0000000000000000 x25: ffff800009325320 x24: ffff0000012da000 [ 9740.739678] x23: ffff000003bd9a80 x22: ffff000005ee9580 x21: ffff000003bd9ad8 [ 9740.740324] x20: ffff0000f36cd2c8 x19: ffff0000012da2b8 x18: 0000000000000006 [ 9740.740969] x17: 0000000000000000 x16: 0000000000000000 x15: 0765076507720766 [ 9740.741615] x14: 072d077207650774 x13: ffff800009281000 x12: 000000000000056d [ 9740.742261] x11: 00000000000001cf x10: ffff8000092d9000 x9 : ffff800009281000 [ 9740.742906] x8 : 00000000ffffefff x7 : ffff8000092d9000 x6 : 80000000fffff000 [ 9740.743552] x5 : ffff0000f7771b88 x4 : 0000000000000000 x3 : 0000000000000027 [ 9740.744197] x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff0000019ed700 [ 9740.744842] Call trace: [ 9740.745068] refcount_warn_saturate+0xc8/0x144 [ 9740.745475] config_item_get+0x7c/0x80 [ 9740.745822] configfs_rmdir+0x17c/0x30c [ 9740.746174] vfs_rmdir+0x8c/0x204 [ 9740.746482] do_rmdir+0x158/0x184 [ 9740.746787] __arm64_sys_unlinkat+0x64/0x80 [ 9740.747171] invoke_syscall+0x48/0x114 [ 9740.747519] el0_svc_common.constprop.0+0x44/0xec [ 9740.747948] do_el0_svc+0x38/0x98 [ 9740.748255] el0_svc+0x2c/0x84 [ 9740.748541] el0t_64_sync_handler+0xf4/0x120 [ 9740.748932] el0t_64_sync+0x190/0x194 [ 9740.749269] ---[ end trace 0000000000000000 ]--- [ 9740.749754] ------------[ cut here ]------------ Fix this by modifying pci_epf_cfs_work() to execute the new function pci_ep_cfs_add_type_group() which itself calls pci_epf_type_add_cfs() to obtain the function specific attribute group and the group name (directory name) from the endpoint function driver. If the function driver defines an attribute group, pci_ep_cfs_add_type_group() then proceeds to register this group using configfs_register_group(), thus automatically exposing the function type pecific onfigfs attributes to the user. E.g.: $ modprobe pci-epf-ntb $ cd /sys/kernel/config/pci_ep/functions/pci_epf_ntb $ mkdir func0 $ tree func0 func0/ |-- baseclass_code |-- cache_line_size |-- ... |-- pci_epf_ntb.0 | |-- db_count | |-- mw1 | |-- mw2 | |-- mw3 | |-- mw4 | |-- num_mws | `-- spad_count |-- primary |-- ... `-- vendorid With this change, there is no need for the user to create or delete directories in the endpoint function attributes directory. The pci_epf_type_group_ops group operations are thus removed. The documentation for the pci-epf-ntb and pci-epf-vntb function drivers are updated to reflect this change, removing the explanations showing the need to manually create the sub-directory for the function specific attributes. Signed-off-by: Damien Le Moal --- Documentation/PCI/endpoint/pci-ntb-howto.rst | 11 ++--- Documentation/PCI/endpoint/pci-vntb-howto.rst | 13 +++--- drivers/pci/endpoint/pci-ep-cfs.c | 41 +++++++++---------- 3 files changed, 28 insertions(+), 37 deletions(-) diff --git a/Documentation/PCI/endpoint/pci-ntb-howto.rst b/Documentation/PCI/endpoint/pci-ntb-howto.rst index 1884bf29caba..4261e7157ef1 100644 --- a/Documentation/PCI/endpoint/pci-ntb-howto.rst +++ b/Documentation/PCI/endpoint/pci-ntb-howto.rst @@ -88,13 +88,10 @@ commands can be used:: # echo 0x104c > functions/pci_epf_ntb/func1/vendorid # echo 0xb00d > functions/pci_epf_ntb/func1/deviceid -In order to configure NTB specific attributes, a new sub-directory to func1 -should be created:: - - # mkdir functions/pci_epf_ntb/func1/pci_epf_ntb.0/ - -The NTB function driver will populate this directory with various attributes -that can be configured by the user:: +The PCI endpoint framework also automatically creates a sub-directory in the +function attribute directory. This sub-directory has the same name as the name +of the function device and is populated with the following NTB specific +attributes that can be configured by the user:: # ls functions/pci_epf_ntb/func1/pci_epf_ntb.0/ db_count mw1 mw2 mw3 mw4 num_mws diff --git a/Documentation/PCI/endpoint/pci-vntb-howto.rst b/Documentation/PCI/endpoint/pci-vntb-howto.rst index 4ab8e4a26d4b..70d3bc90893f 100644 --- a/Documentation/PCI/endpoint/pci-vntb-howto.rst +++ b/Documentation/PCI/endpoint/pci-vntb-howto.rst @@ -84,13 +84,10 @@ commands can be used:: # echo 0x1957 > functions/pci_epf_vntb/func1/vendorid # echo 0x0809 > functions/pci_epf_vntb/func1/deviceid -In order to configure NTB specific attributes, a new sub-directory to func1 -should be created:: - - # mkdir functions/pci_epf_vntb/func1/pci_epf_vntb.0/ - -The NTB function driver will populate this directory with various attributes -that can be configured by the user:: +The PCI endpoint framework also automatically creates a sub-directory in the +function attribute directory. This sub-directory has the same name as the name +of the function device and is populated with the following NTB specific +attributes that can be configured by the user:: # ls functions/pci_epf_vntb/func1/pci_epf_vntb.0/ db_count mw1 mw2 mw3 mw4 num_mws @@ -103,7 +100,7 @@ A sample configuration for NTB function is given below:: # echo 1 > functions/pci_epf_vntb/func1/pci_epf_vntb.0/num_mws # echo 0x100000 > functions/pci_epf_vntb/func1/pci_epf_vntb.0/mw1 -A sample configuration for virtual NTB driver for virutal PCI bus:: +A sample configuration for virtual NTB driver for virtual PCI bus:: # echo 0x1957 > functions/pci_epf_vntb/func1/pci_epf_vntb.0/vntb_vid # echo 0x080A > functions/pci_epf_vntb/func1/pci_epf_vntb.0/vntb_pid diff --git a/drivers/pci/endpoint/pci-ep-cfs.c b/drivers/pci/endpoint/pci-ep-cfs.c index 4b8ac0ac84d5..b16fc6093c20 100644 --- a/drivers/pci/endpoint/pci-ep-cfs.c +++ b/drivers/pci/endpoint/pci-ep-cfs.c @@ -23,6 +23,7 @@ struct pci_epf_group { struct config_group group; struct config_group primary_epc_group; struct config_group secondary_epc_group; + struct config_group *type_group; struct delayed_work cfs_work; struct pci_epf *epf; int index; @@ -502,34 +503,28 @@ static struct configfs_item_operations pci_epf_ops = { .release = pci_epf_release, }; -static struct config_group *pci_epf_type_make(struct config_group *group, - const char *name) -{ - struct pci_epf_group *epf_group = to_pci_epf_group(&group->cg_item); - struct config_group *epf_type_group; - - epf_type_group = pci_epf_type_add_cfs(epf_group->epf, group); - return epf_type_group; -} - -static void pci_epf_type_drop(struct config_group *group, - struct config_item *item) -{ - config_item_put(item); -} - -static struct configfs_group_operations pci_epf_type_group_ops = { - .make_group = &pci_epf_type_make, - .drop_item = &pci_epf_type_drop, -}; - static const struct config_item_type pci_epf_type = { - .ct_group_ops = &pci_epf_type_group_ops, .ct_item_ops = &pci_epf_ops, .ct_attrs = pci_epf_attrs, .ct_owner = THIS_MODULE, }; +static void pci_ep_cfs_add_type_group(struct pci_epf_group *epf_group) +{ + struct config_group *group; + + group = pci_epf_type_add_cfs(epf_group->epf, &epf_group->group); + if (!group) + return; + + if (IS_ERR(group)) { + pr_err("failed to create epf type specific attributes\n"); + return; + } + + configfs_register_group(&epf_group->group, group); +} + static void pci_epf_cfs_work(struct work_struct *work) { struct pci_epf_group *epf_group; @@ -547,6 +542,8 @@ static void pci_epf_cfs_work(struct work_struct *work) pr_err("failed to create 'secondary' EPC interface\n"); return; } + + pci_ep_cfs_add_type_group(epf_group); } static struct config_group *pci_epf_make(struct config_group *group, From patchwork Sat Mar 25 07:02:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13187638 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17570C6FD1C for ; Sat, 25 Mar 2023 07:02:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231922AbjCYHCi (ORCPT ); Sat, 25 Mar 2023 03:02:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231904AbjCYHCg (ORCPT ); Sat, 25 Mar 2023 03:02:36 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EC591517B for ; Sat, 25 Mar 2023 00:02:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1679727754; x=1711263754; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t8/FKltNGowk82a8oQeUA1AG8yskCDoRScDUWbaQaEo=; b=Ycfy1rKaDs4kZ06CgQ5AlZs2Hv5Q3v6vGZHBTsHrdJnjVodQVhV4PqLa pxBWG8EkyvUL1JXNx5u20MXaSiWdVkhzKVu+V9syEO/NjA3X02daAxXf4 BGOR+RDZ0Mj7WFrQP7kX7nD2QuPT38RvXHvaFFHdBv9fshQEm5QS5+zp6 nkqgg9M3Gj/05JVTWlOScbRMIt34LX0QGH9tIR/y4jbQ2CJ9KbOVgazJl pTeVAOZl30cl+gXWhN0s7sG/il6AMjLuDpINHk2UKuJEDFEluf2ClXh/Z snCzw/R6TtMw7JaY788xzN4MzF+VsfEHujILvCXirk/OiAkExNxos4VCK g==; X-IronPort-AV: E=Sophos;i="5.98,289,1673884800"; d="scan'208";a="224756684" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2023 15:02:34 +0800 IronPort-SDR: fWxO0y98z2Ae93PZ/Lw9G+ESoGFMCDN/KH8G7Ioo4Nn2NybXLghkdhPGlP1mcUw76jZq6v2L3n eNxxmUU8CaRfb/zGNFl3vnxOd0cXTxygEy7dxkflMBmCCp/H8++js6i5yBx0mQRS1hhPhRXyq4 bScL1BBofKzb6ZrYQFL/CzkiP+juKakPJC54raAn3UFXOoHRHpuyNTeQMQAwg0zq96bLBKuM1p PSmG4OzAEFtPENBwo5/M1vOuIvgGm/c7xbwa5c2iVj3f68UbGBm04EzwbVrx+JiO9HMmPZNsGt Y1g= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Mar 2023 23:18:49 -0700 IronPort-SDR: MDHx7M06iZXo0qqp6908vV/KLik+iTDgtSfqEWTr4XyhQOehxAwCwoLHdp5IRBEU5FxE37cKZ9 uYf5TM2mciP+Qj/noSqEAN/tQak0bCnFb7PIhxBDXV44deKcgUsZabbbO10qM3l2Fq/bPgCUw9 N798FMM4l1+n2Kv1r341Chj9oC1h1VHu/kO4G56OPJBWvbROVCf7G8+FjuWr9bGXoVjduOAA8j XsO0DXoiv1jh2VkbV2x0C67FUAFdZKB/KMK64WldEL3t1uz4XNUu+YQl9BRmOJecfxZ8JsulFp k8E= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Mar 2023 00:02:35 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pk94p3dqyz1RtW0 for ; Sat, 25 Mar 2023 00:02:34 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1679727753; x=1682319754; bh=t8/FKltNGowk82a8oQ eUA1AG8yskCDoRScDUWbaQaEo=; b=TM7myIhv9ZDWbEVA0HP56mwOKR1mKC7KMn 2z22cdZkSR24IvUWnoUHPXA6QeQi7TEN6+7IJvqPpLiLjlKtxmSBXjPqgULHH1zT JHIYCjvLkzHHHkGNkq5y3yht10nlPcvw7VZ6SA15LPtKwVxeGy0bl3vsJsGXym60 ddL0iO0O8iTq3Esm+ewH/Lj6d9GPEC+rTgNUgdmPiRKRfWNIAWbGTFvJA90qwn48 bGCMpD0HVI6bjV+14RHzSwKltfFBcWoEA5n63OONMBnzTry2lHTzBq+UEGkF9mg0 /HbkpWl3XHje++PaXhec7x7FRvN30rylA68/JpMu0+neLP6NZirQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id uYiYi_yGn3Q5 for ; Sat, 25 Mar 2023 00:02:33 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pk94l4nq5z1RtVm; Sat, 25 Mar 2023 00:02:31 -0700 (PDT) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v3 02/16] PCI: endpoint: Move pci_epf_type_add_cfs() code Date: Sat, 25 Mar 2023 16:02:12 +0900 Message-Id: <20230325070226.511323-3-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> References: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org pci_epf_type_add_cfs() is called only from pci_ep_cfs_add_type_group() in drivers/pci/endpoint/pci-ep-cfs.c, so there is no need to export this function and we can move its code from pci-epf-core.c to pci-ep-cfs.c as a static function. Reviewed-by: Manivannan Sadhasivam Signed-off-by: Damien Le Moal --- drivers/pci/endpoint/pci-ep-cfs.c | 20 ++++++++++++++++++ drivers/pci/endpoint/pci-epf-core.c | 32 ----------------------------- include/linux/pci-epf.h | 2 -- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/drivers/pci/endpoint/pci-ep-cfs.c b/drivers/pci/endpoint/pci-ep-cfs.c index b16fc6093c20..3a05e9b5a4e9 100644 --- a/drivers/pci/endpoint/pci-ep-cfs.c +++ b/drivers/pci/endpoint/pci-ep-cfs.c @@ -509,6 +509,26 @@ static const struct config_item_type pci_epf_type = { .ct_owner = THIS_MODULE, }; +static struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf, + struct config_group *group) +{ + struct config_group *epf_type_group; + + if (!epf->driver) { + dev_err(&epf->dev, "epf device not bound to driver\n"); + return NULL; + } + + if (!epf->driver->ops->add_cfs) + return NULL; + + mutex_lock(&epf->lock); + epf_type_group = epf->driver->ops->add_cfs(epf, group); + mutex_unlock(&epf->lock); + + return epf_type_group; +} + static void pci_ep_cfs_add_type_group(struct pci_epf_group *epf_group) { struct config_group *group; diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 2036e38be093..355a6f56fcea 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -20,38 +20,6 @@ static DEFINE_MUTEX(pci_epf_mutex); static struct bus_type pci_epf_bus_type; static const struct device_type pci_epf_type; -/** - * pci_epf_type_add_cfs() - Help function drivers to expose function specific - * attributes in configfs - * @epf: the EPF device that has to be configured using configfs - * @group: the parent configfs group (corresponding to entries in - * pci_epf_device_id) - * - * Invoke to expose function specific attributes in configfs. If the function - * driver does not have anything to expose (attributes configured by user), - * return NULL. - */ -struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf, - struct config_group *group) -{ - struct config_group *epf_type_group; - - if (!epf->driver) { - dev_err(&epf->dev, "epf device not bound to driver\n"); - return NULL; - } - - if (!epf->driver->ops->add_cfs) - return NULL; - - mutex_lock(&epf->lock); - epf_type_group = epf->driver->ops->add_cfs(epf, group); - mutex_unlock(&epf->lock); - - return epf_type_group; -} -EXPORT_SYMBOL_GPL(pci_epf_type_add_cfs); - /** * pci_epf_unbind() - Notify the function driver that the binding between the * EPF device and EPC device has been lost diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index a215dc8ce693..b8441db2fa52 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -214,8 +214,6 @@ void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar, enum pci_epc_interface_type type); int pci_epf_bind(struct pci_epf *epf); void pci_epf_unbind(struct pci_epf *epf); -struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf, - struct config_group *group); int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf); void pci_epf_remove_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf); #endif /* __LINUX_PCI_EPF_H */ From patchwork Sat Mar 25 07:02:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13187639 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 014A7C7619A for ; Sat, 25 Mar 2023 07:02:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231925AbjCYHCi (ORCPT ); Sat, 25 Mar 2023 03:02:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231417AbjCYHCh (ORCPT ); Sat, 25 Mar 2023 03:02:37 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C04214200 for ; Sat, 25 Mar 2023 00:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1679727756; x=1711263756; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mBNv4vFEtRrRogU1bpDNqFs895hGS3croCKNhICIOZA=; b=LLxnY16/iCXFzwnhHDtGWkut/iIhkjg8id+CSWuojkkyuzJjMGyn7sqn pXU9Fe4+AYKTcD1d/cS0fPSa6NKwULSG0wADj4zeUNrStU6vp5zZBSWVd 8Y/HtnE8lRie3pUoALCgE/nDs1djCRRLpBgu0eBWGQwvaLXu6YEmt3mDO NtBeLT8ps23dwwFRy8klJVzfH6P7rI076y3uLU6YalCSpCLqPO/m7Aza2 lYxzwsh8Y3tjrqV32teZQQHmUC3+sCPU6A6qJqFeEQlud8jI2eIEZ7CWk 0s9V60PnbnpknocwfXpDmmdxwiLWFQkSlz4CkTeOOLLpfteNOcTL6eZuP g==; X-IronPort-AV: E=Sophos;i="5.98,289,1673884800"; d="scan'208";a="224756692" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2023 15:02:36 +0800 IronPort-SDR: sQJgW0QUnE3zjMwOLInm7aRsdf/ZEdWnlzi60QcJWxZ0BWI+7kk9horJXSTjV55RKDHGnL9kFq Tq38ZMWpK9c901iwL7nr57e6flYHUDn1dSJANAc8dErbwAtvEurgG1C+AkL/oFXx3ALT1vsYqY EKjiLRyCzDUMo/iusApyDOlKiRhfAUN00BLGqcmsbeMdfzienAlEvG3n140nP2kD7kOTs8WMkb K1z0q1hr3HE61enYkBNHAAnq8nqctK2CrL5UjNOy5RLkAHX4KS1qYEdY9dxHHP7mwok04gwrYb ap4= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Mar 2023 23:18:51 -0700 IronPort-SDR: jQHb5vp/SUAPzdggVibGzOa4+gi4giz+r0xqv/U4NhuG3oovq74KPUEsq6QzvN9DS4yYi2Pu+i mW6FRFWr72pSNjnRN8tlPA+Ft/h04t/unPITs1jKHJywOAuO2HqrsQorrGXUn20rUKOA4skfrc UZE/wkQSvJbvyrO9QR9SKgy3Fsud6cwa2/FdR6wETiTyGqIdufKsAs57gRiq+mZSUTPJmcO2e9 QTrXC5xYXii/ufvFsR3PCYsYTVlgq02NWGrL4sNGR10U9lc4eIqOKX2c4T8RknlsV8UeBcX2uu UhM= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Mar 2023 00:02:37 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pk94r0ghBz1RtVt for ; Sat, 25 Mar 2023 00:02:36 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1679727755; x=1682319756; bh=mBNv4vFEtRrRogU1bp DNqFs895hGS3croCKNhICIOZA=; b=Y+yUHVN481irTSxovwlRnTHO8VRH5axgyH xK9ew9B3qLNNwTY/ik6/AWg61btuuqAlGR1I8LNSAqdmZbyOIPKkqnBl5uiYwrQY hRzr3t1/tbD4Ri9QAcFhiJTruS2SkK9iJjriGsvt6h6s14lGti13YpePm1ITzH45 DdfcbqT77EiyQazsMcR6I1Z3l+aUNTfMZl7BM5e/jDW0Ggrrx6gZGkLGHGp3isIW mGqB140C7tKSQHd26LMSbSEQP344NaUICNjnFSxqWecPOoem0uR6+XA7T9Gknuy/ nc78uyHVltuddgddh+eHnuWma4Rut3f2cXWzTJGzXjiPrezD1IdQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id dAWpUvHBtgPm for ; Sat, 25 Mar 2023 00:02:35 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pk94n69J2z1RtVn; Sat, 25 Mar 2023 00:02:33 -0700 (PDT) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v3 03/16] PCI: epf-test: Fix DMA transfer completion initialization Date: Sat, 25 Mar 2023 16:02:13 +0900 Message-Id: <20230325070226.511323-4-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> References: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Re-initialize the transfer_complete DMA transfer completion before calling tx_submit(), to avoid seeing the DMA transfer complete before the completion is initialized, thus potentially losing the completion notification. Fixes: 8353813c88ef ("PCI: endpoint: Enable DMA tests for endpoints with DMA capabilities") Cc: stable@vger.kernel.org Reviewed-by: Manivannan Sadhasivam Signed-off-by: Damien Le Moal --- drivers/pci/endpoint/functions/pci-epf-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 0f9d2ec822ac..d65419735d2e 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -151,10 +151,10 @@ static int pci_epf_test_data_transfer(struct pci_epf_test *epf_test, return -EIO; } + reinit_completion(&epf_test->transfer_complete); tx->callback = pci_epf_test_dma_callback; tx->callback_param = epf_test; cookie = tx->tx_submit(tx); - reinit_completion(&epf_test->transfer_complete); ret = dma_submit_error(cookie); if (ret) { From patchwork Sat Mar 25 07:02:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13187640 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E632FC6FD1F for ; Sat, 25 Mar 2023 07:02:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231904AbjCYHCl (ORCPT ); Sat, 25 Mar 2023 03:02:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231417AbjCYHCk (ORCPT ); Sat, 25 Mar 2023 03:02:40 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DCB01714F for ; Sat, 25 Mar 2023 00:02:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1679727758; x=1711263758; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+HydAFEgNOgg0eVz7b8c5RJLJ0jDAA9i/cU2toh3C2E=; b=YPoF/7/SeXBQPAmTOd2rBjKl5v5M7ojFbXFVg/bHeZ+oe2SWDhMWuWjo ohwyhanr9Q0KaxESwMkfKJZOQK2MmB2VE6SEDOHg8IXzDzQOP2DGuIqD4 kKx5aGPRnp9h4MVeapy2luUno9KDyB/Ts7kADv+5kMkg9zh+mhKMyUsVo hANRpFd06dsCDkQPka9Pbt5L4eCVwbt1f/CsGGli3bYCD2cbMqy9mCDPz 6U4JjtHpXwQ8bHCwCDt5vOUeUt2MOYEzRJGPKEJ6oluSbB1vCy2hAl+fG XEOPL7uq97M18pPjIIUvNe0KA0lf3QKQd9h4GwBc4EH4pfmAoKccN4gda Q==; X-IronPort-AV: E=Sophos;i="5.98,289,1673884800"; d="scan'208";a="224756720" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2023 15:02:38 +0800 IronPort-SDR: IKkSbYJGxB2aVcXKeVvQcdDRnxRE2u14MmkHsBA0ibjUkxGC8bT51IsHVviG73c1oziyZvhPUE vIHv23UIU54zC9xVnFRcB/hXzs1ifX0yLHm9Nn0SU+h5VeT5g/Fi5QDp35TKr8H+YC8vD1xpEm HiW3IV3UWh530gB3vB7pzl+YBLQ5iIMdwVxLc4z+kyO4tddcYKFMynNFjrOSuuB20Ti2MfsVAu tZ6l2zK2eD3HMhgMi6eZllxRhARiozGvQj17sb3d+uxjZ2swF0XGBdMZvcIs7DuJj9hMVLd+Eb ArU= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Mar 2023 23:18:53 -0700 IronPort-SDR: P6FwWbHsisEm0Du2o4FrtpRuYsZp0jAOruveJJjXefMMPVrwpae8ao0yMaZRr6YDaj5SzTlMsF JTqBbkZO2rrGSFRUZlnjVHOeaZIeC1yBqqE8vQ5EkMnSYc95dvnOn26C3fNxIwDGCA4BghPfkj ctm7WrGgh/7xRv837FFQ2MWva26QQL1tkntEzLgaiOtvT22B4ohiaK5gJ8dV9oczGSUuQJGtuu gN4IauzBexP3WZBGl1VadtNV+tbqroiHkAgK7XmXsIRl9HeE4S5ne1YfyEma2tLGufvuWpDOiH Pwk= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Mar 2023 00:02:39 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pk94t0gZLz1RtVy for ; Sat, 25 Mar 2023 00:02:38 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1679727757; x=1682319758; bh=+HydAFEgNOgg0eVz7b 8c5RJLJ0jDAA9i/cU2toh3C2E=; b=qSRQ5HsTrUIp6DsbwcWn7mV7suWRexZkch QFqi7/jySg4kWZaBufB749K7upS4QcKBr/6zXwWPjzyomNqgqFvWhfj2wrCBYddc z3VYpGmLtLZkIELLXn+bosAD9jP1HQhoiX0P8alszPNigx5iu4G3qNX89Ce1CWN7 0RgkZG6cxgue7eunDDxzh4U5KigBZCRSrPrCKioox08TwdrjTUe4AX4LOBc8MOze RuE95Hl1geZPNp/Zwp77s6ytnpPWHo/KLwX0L7mvF+ReAGS0ONyVEK5HdxGa8YWG K60c4kt1Jy09uVdLWZr/oUYANxubaQUfntWwsnOTsyhND6Z1bO3Q== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 5co-RQh3-Y5Q for ; Sat, 25 Mar 2023 00:02:37 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pk94q5HdXz1RtVm; Sat, 25 Mar 2023 00:02:35 -0700 (PDT) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v3 04/16] PCI: epf-test: Fix DMA transfer completion detection Date: Sat, 25 Mar 2023 16:02:14 +0900 Message-Id: <20230325070226.511323-5-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> References: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org pci_epf_test_data_transfer() and pci_epf_test_dma_callback() are not handling DMA transfer completion correctly, leading to completion notifications to the RC side that are too early. This problem can be detected when the RC side is running an IOMMU with messages such as: pci-endpoint-test 0000:0b:00.0: AMD-Vi: Event logged [IO_PAGE_FAULT domain=0x001c address=0xfff00000 flags=0x0000] When running the pcitest.sh tests: the address used for a previous test transfer generates the above error while the next test transfer is running. Fix this by testing the dma transfer status in pci_epf_test_dma_callback() and notifying the completion only when the transfer status is DMA_COMPLETE or DMA_ERROR. Furthermore, in pci_epf_test_data_transfer(), be paranoid and check again the transfer status and always call dmaengine_terminate_sync() before returning. Fixes: 8353813c88ef ("PCI: endpoint: Enable DMA tests for endpoints with DMA capabilities") Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal --- drivers/pci/endpoint/functions/pci-epf-test.c | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index d65419735d2e..dbea6eb0dee7 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -54,6 +54,9 @@ struct pci_epf_test { struct delayed_work cmd_handler; struct dma_chan *dma_chan_tx; struct dma_chan *dma_chan_rx; + struct dma_chan *transfer_chan; + dma_cookie_t transfer_cookie; + enum dma_status transfer_status; struct completion transfer_complete; bool dma_supported; bool dma_private; @@ -85,8 +88,14 @@ static size_t bar_size[] = { 512, 512, 1024, 16384, 131072, 1048576 }; static void pci_epf_test_dma_callback(void *param) { struct pci_epf_test *epf_test = param; - - complete(&epf_test->transfer_complete); + struct dma_tx_state state; + + epf_test->transfer_status = + dmaengine_tx_status(epf_test->transfer_chan, + epf_test->transfer_cookie, &state); + if (epf_test->transfer_status == DMA_COMPLETE || + epf_test->transfer_status == DMA_ERROR) + complete(&epf_test->transfer_complete); } /** @@ -120,7 +129,6 @@ static int pci_epf_test_data_transfer(struct pci_epf_test *epf_test, struct dma_async_tx_descriptor *tx; struct dma_slave_config sconf = {}; struct device *dev = &epf->dev; - dma_cookie_t cookie; int ret; if (IS_ERR_OR_NULL(chan)) { @@ -152,25 +160,33 @@ static int pci_epf_test_data_transfer(struct pci_epf_test *epf_test, } reinit_completion(&epf_test->transfer_complete); + epf_test->transfer_chan = chan; tx->callback = pci_epf_test_dma_callback; tx->callback_param = epf_test; - cookie = tx->tx_submit(tx); + epf_test->transfer_cookie = tx->tx_submit(tx); - ret = dma_submit_error(cookie); + ret = dma_submit_error(epf_test->transfer_cookie); if (ret) { - dev_err(dev, "Failed to do DMA tx_submit %d\n", cookie); - return -EIO; + dev_err(dev, "Failed to do DMA tx_submit %d\n", ret); + goto terminate; } dma_async_issue_pending(chan); ret = wait_for_completion_interruptible(&epf_test->transfer_complete); if (ret < 0) { - dmaengine_terminate_sync(chan); - dev_err(dev, "DMA wait_for_completion_timeout\n"); - return -ETIMEDOUT; + dev_err(dev, "DMA wait_for_completion interrupted\n"); + goto terminate; } - return 0; + if (epf_test->transfer_status == DMA_ERROR) { + dev_err(dev, "DMA transfer failed\n"); + ret = -EIO; + } + +terminate: + dmaengine_terminate_sync(chan); + + return ret; } struct epf_dma_filter { From patchwork Sat Mar 25 07:02:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13187641 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DEDDC6FD1C for ; Sat, 25 Mar 2023 07:02:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231945AbjCYHCn (ORCPT ); Sat, 25 Mar 2023 03:02:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231417AbjCYHCm (ORCPT ); Sat, 25 Mar 2023 03:02:42 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AD8618B07 for ; Sat, 25 Mar 2023 00:02:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1679727760; x=1711263760; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s337vsR4bX90nEJfYlGg1DUOEOdyobGliyQs10wRS+U=; b=XAGxImA+l7PUJg90vL6uDLRDGIEIo89n6Cp15lecQFaT0ecNr0nkVKGT LfUml0qQN2m9C5sEp+kXN5/HfZ7OHF3FWm7adLttNeErPIs87xmcZnrc6 1z4ECTW/pwVC+G2/aGCBVYK0+V9D1Pdksuz4Uy2a5J/GmyAS+ILXc+lwn QwVCGeBPQWWKuqTUk1Ht3LB6qciH7/D63KU0Kfn7l0xKIcW22mBMkZCeF 3ytRet6EEVOPLL1PdrEPo3RZYzGk+zZvTwX0TptUCL+M3WbHKlXaIQ9X8 PcTeOHeymMLsnIWETaZZP2ki2qgvToRiwhokOZI90plUVc5pahLQCbVxj A==; X-IronPort-AV: E=Sophos;i="5.98,289,1673884800"; d="scan'208";a="224756738" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2023 15:02:39 +0800 IronPort-SDR: A7lQxxa2UiHe85lnp6i1j/fMxMBMieQZMGffaE3h2hMKvtJ2RVFF2sLTeufs2jSo+93m3oZmRs tVDGC5PHBkkRnEYocyv7TMOEsYTrqLV0KrF7l/QCgDLczq21Oiriv+es8pYU/f4r/jKUtIsZ4Y Wubp0Jn0+7kXvX+Nu+6Twux3V1hfqJiv0iu3E1pFdGH+M7+VTDwkINU3svi75xKSjBK2uYM8dg uYlpslBcGnN7NH2XUONZ0cIug6CXWzgEmq/IQPqiO9BPrQdDVXa3SB7BLN6ILWvxKTxgGIshG8 gAY= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Mar 2023 23:18:54 -0700 IronPort-SDR: gqvuuWtgiWf1CXuNvAWZg6KLTKazb1v9tQ3zaQkKOb03VfHVfKPoRRGaV9H2CqoVrVQfdK6AxD GOsIp9+NzYrQrFIWXpuo0en5DaCHTfeN4zhmQj/XkBZdR0w0asH5nrrB6zXUIrjIcQstorNUri QoNX7FxcfmdIrgFtUxlyQyxSCsrs5RK784X7C85RyJ8Ayp0XbUTaQmE2s9aYlHKH8cNGKqFRGt 9btXwRmINTslZtHwdVZadb+bHJaZjw2i4TwlKxELNToVIys5U52d2zE0srT3DRuY/7QDo/tgDz qjM= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Mar 2023 00:02:40 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pk94v4xlmz1RtW0 for ; Sat, 25 Mar 2023 00:02:39 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1679727759; x=1682319760; bh=s337vsR4bX90nEJfYl Gg1DUOEOdyobGliyQs10wRS+U=; b=BMUp3NVobPt2vrxBYV3658GiNlJ5Hoc7xN 7YYCncVG2OV1lJqxTVjGrVxI1MyUSmM7clKU4L+o5JNARrClnXytf1/5AHyH5sMe kPlIpe9/XxDR8P0ydgWSu65fcOYCxsOA3ZQpR4hnXzghzMeAPkOfUI4sKOrCCxel BGYZZZ+gbRx3dOlDU5IhPEjW2S0DU3sEl12exlKhyrkqy1ARvfL1m+U04UuGqab7 YmreWGicywSPUDq0Jtjgk23pVfCWrEQgJ5wBsicGc37VYccI+L0NifUFkWKwHmKT m8km4EgXfKWzARrU1tofsG9UZc4UCD3XwSYiwTlrBJtTLXbmMEQA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id jXVvpOipUhX9 for ; Sat, 25 Mar 2023 00:02:39 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pk94s4TH5z1RtVn; Sat, 25 Mar 2023 00:02:37 -0700 (PDT) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v3 05/16] PCI: epf-test: Use dmaengine_submit() to initiate DMA transfer Date: Sat, 25 Mar 2023 16:02:15 +0900 Message-Id: <20230325070226.511323-6-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> References: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Instead of an open coded call to the tx_submit() operation of struct dma_async_tx_descriptor, use the helper function dmaengine_submit(). No functional change is introduced with this. Reviewed-by: Manivannan Sadhasivam Signed-off-by: Damien Le Moal --- drivers/pci/endpoint/functions/pci-epf-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index dbea6eb0dee7..7cdc6c915ef5 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -163,7 +163,7 @@ static int pci_epf_test_data_transfer(struct pci_epf_test *epf_test, epf_test->transfer_chan = chan; tx->callback = pci_epf_test_dma_callback; tx->callback_param = epf_test; - epf_test->transfer_cookie = tx->tx_submit(tx); + epf_test->transfer_cookie = dmaengine_submit(tx); ret = dma_submit_error(epf_test->transfer_cookie); if (ret) { From patchwork Sat Mar 25 07:02:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13187642 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E55C5C6FD1F for ; Sat, 25 Mar 2023 07:02:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231417AbjCYHCp (ORCPT ); Sat, 25 Mar 2023 03:02:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231927AbjCYHCn (ORCPT ); Sat, 25 Mar 2023 03:02:43 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CCCB15C9A for ; Sat, 25 Mar 2023 00:02:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1679727762; x=1711263762; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CbKzr7JuTqmzPKIp5lOMS5tv+EX8Bq8JL59U7x90uT8=; b=UkrEEVjPywlgTqb1bOfJ8ypr8t+HLXiX1w+47BIFHT7HU9xn63L4Uo5p KMHcaebpo26+W6vmeLYFBixvtKhGNzhwCHF5fS4xhUK4CYCxuU/GLkElM z4ABA8Y8mQ8Vv8APmTJ/jptgFrhNmOJR2vi9PbLWdIdh0uG8MiQBFy3G8 nivs7uc320HmYIRZZ212QVpoTjoagrdU95zwywlJ+I+VJD85Qbe170ev8 45pdkYZxXPtA/pEkeaGR7iHuiVNnWkcV8hKY1d6bl+PEvmHeD7pYkV3iR C3OzHbZN4AlY6OMDBGHyesdz2XhnRI4gw78NTD25UhTwr4cABfUJA/Gp/ A==; X-IronPort-AV: E=Sophos;i="5.98,289,1673884800"; d="scan'208";a="224756763" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2023 15:02:41 +0800 IronPort-SDR: 2yOu20Zur7+IimbyCCJmehDnvbdIiZaCri6RObtkoAwohU5t2BLNmJQBbZWZq4NTiueMk0czE8 uoLh8EN7R5hzgyxb+6cEcg0rsowxqhFMoQ5EvXklaaSxIvd0iYAl5rf251ycM1Af2rwUq9i3Yk znAIxj6RdLbOBeRtzORQ3tPkshn5BPE8aKXwAtkVOFIHj5LoWoouIwIjOweoX8UcvOD7oR/br/ 7xc3idCHukj4QL7DoxBTCUx0LCHG9YBBfX4Vs2Z3KZSVXn5Sy/0cUVwG4pXE0TGNGc7hT7GAlB Tw0= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Mar 2023 23:18:56 -0700 IronPort-SDR: ohOx9Zx2KWrnzphMy+6VFmabxssmAeJduOPaMHlLapzwpPTBh1c9QD2gLONmk1zgbUf2RpskB9 C2Ls2A8HXxjAYLZpm1LBSQSqf0DlBemolW3EoCeJCmNmcfRWFu4NDJJFtS/VvsQZ0Ai60haRb5 JbNU8mFPdGvwyHXMeCFrDd8RvGfc0FlSWNJrsUBnP7BWzrldL4HZM9x7swVmcq7f/QYPLVUEH6 WCY3mVOBm5SzHtU0terP6fZzTVmk937hQPEw5JseO5enRTwDZkns8Btzf5Msod/84QEwLdojCV tgM= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Mar 2023 00:02:42 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pk94x4y68z1RtVy for ; Sat, 25 Mar 2023 00:02:41 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1679727760; x=1682319761; bh=CbKzr7JuTqmzPKIp5l OMS5tv+EX8Bq8JL59U7x90uT8=; b=gYPc2k3e+Xh6ehVJfwlO142r+EhketQZ5i hUFxVjQ/bEUxQUgYTSShC9+mdltAV2d/WCYt1OrUPU5xxtIWMQ2wdKicI3em5/92 V5N+bzBySZ4F3u2xLgqjrAZnUcMfNHqoa2QX6EI4LUNSFgRbTJmQDG3hBD32jGwM RH8Dhs6FAGoFm5ywQIESvoRRSjxfw2jSF4ley+fMGa+hpXgd2j9g3so8Y7ss8P9k gdMHU8njbiiILwkotWZ48bpfmYsYMXR67loEaj9+2YrCbYx7oWTNIbBIc+HxgXoh vF7eczBIkCWeyITEkREin1yjJcv/kuNggU3Brij0VlyaOzXDfcLw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id co2-8XSUNP7z for ; Sat, 25 Mar 2023 00:02:40 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pk94v2Lqpz1RtVm; Sat, 25 Mar 2023 00:02:39 -0700 (PDT) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v3 06/16] PCI: epf-test: Simplify read/write/copy test functions Date: Sat, 25 Mar 2023 16:02:16 +0900 Message-Id: <20230325070226.511323-7-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> References: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The function pci_epf_test_cmd_handler() casts the register bar to a struct pci_epf_test_reg to determine the command sent by the host and execute the test function accordingly. So there is no need for doing this cast again in each of the read, write and copy test functions. We can simply pass the reg pointer as an argument to the functions pci_epf_test_write(), pci_epf_test_read() and pci_epf_test_copy(). Reviewed-by: Manivannan Sadhasivam Signed-off-by: Damien Le Moal --- drivers/pci/endpoint/functions/pci-epf-test.c | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 7cdc6c915ef5..b8b178ac7cda 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -325,7 +325,8 @@ static void pci_epf_test_print_rate(const char *ops, u64 size, (u64)ts.tv_sec, (u32)ts.tv_nsec, rate / 1024); } -static int pci_epf_test_copy(struct pci_epf_test *epf_test) +static int pci_epf_test_copy(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) { int ret; bool use_dma; @@ -337,8 +338,6 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test) struct pci_epf *epf = epf_test->epf; struct device *dev = &epf->dev; struct pci_epc *epc = epf->epc; - enum pci_barno test_reg_bar = epf_test->test_reg_bar; - struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; src_addr = pci_epc_mem_alloc_addr(epc, &src_phys_addr, reg->size); if (!src_addr) { @@ -424,7 +423,8 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test) return ret; } -static int pci_epf_test_read(struct pci_epf_test *epf_test) +static int pci_epf_test_read(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) { int ret; void __iomem *src_addr; @@ -438,8 +438,6 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) struct device *dev = &epf->dev; struct pci_epc *epc = epf->epc; struct device *dma_dev = epf->epc->dev.parent; - enum pci_barno test_reg_bar = epf_test->test_reg_bar; - struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; src_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, reg->size); if (!src_addr) { @@ -514,7 +512,8 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) return ret; } -static int pci_epf_test_write(struct pci_epf_test *epf_test) +static int pci_epf_test_write(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) { int ret; void __iomem *dst_addr; @@ -527,8 +526,6 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test) struct device *dev = &epf->dev; struct pci_epc *epc = epf->epc; struct device *dma_dev = epf->epc->dev.parent; - enum pci_barno test_reg_bar = epf_test->test_reg_bar; - struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; dst_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, reg->size); if (!dst_addr) { @@ -673,7 +670,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) } if (command & COMMAND_WRITE) { - ret = pci_epf_test_write(epf_test); + ret = pci_epf_test_write(epf_test, reg); if (ret) reg->status |= STATUS_WRITE_FAIL; else @@ -684,7 +681,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) } if (command & COMMAND_READ) { - ret = pci_epf_test_read(epf_test); + ret = pci_epf_test_read(epf_test, reg); if (!ret) reg->status |= STATUS_READ_SUCCESS; else @@ -695,7 +692,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) } if (command & COMMAND_COPY) { - ret = pci_epf_test_copy(epf_test); + ret = pci_epf_test_copy(epf_test, reg); if (!ret) reg->status |= STATUS_COPY_SUCCESS; else From patchwork Sat Mar 25 07:02:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13187643 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A027C6FD1C for ; Sat, 25 Mar 2023 07:02:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231934AbjCYHCq (ORCPT ); Sat, 25 Mar 2023 03:02:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231932AbjCYHCp (ORCPT ); Sat, 25 Mar 2023 03:02:45 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 162CB15882 for ; Sat, 25 Mar 2023 00:02:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1679727763; x=1711263763; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=J/a1XPwL+xSkbmNIxhIJYkrLti8dXBeJ4FmvtofrtKI=; b=B22xgbGqvRO9+EUWGO00Xnsh8Gye/QVvKruEY1AAD/tK2N8fZC0QzzR7 c+oqVSRNEUbC9I+Fd5LvhutZjO25IHbVm3uzsyulZyFkOt1YNSWSXFvbx XM1rkDZIRLTqyhXTnlO1LYuvzAtEwakpCJZhnUomfQm2xvBQxGeY8MyT2 aOLiOiOr7oqWgHBUueDO4vJ5umMcUaKg0p9eqlLlfKmHgYb1HYAqSkYy8 mfL6mqg09fF3k6WN9Of5lzSwK6Ss00CFZbp7TtntsxSOnEcBQat6WAlZh uuLIHwhw/HFN01IxDE0OFq2W+zJizGrRGZdoMpmFAtnbOk9A+9n7WwTUe A==; X-IronPort-AV: E=Sophos;i="5.98,289,1673884800"; d="scan'208";a="224756795" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2023 15:02:43 +0800 IronPort-SDR: GC5yQSVtuUuBT+RUddMyEtxSJ523zIKuPSUrjYvIisLEA3pfeWxTGhrfuF51wUf0xTCNtt9RsS bRgCuBwWce98nK+M+PStTVzeBnv8UX/JoI0hCtEOQiGr22dJSfdjdHBVGlXUK4hlEwl0ruPYJa BB8Bvkyr+a5NHEu+00KKoC7ha5gL/9DwIVA6EN4RtBtOCm41rj6bofbRL0crYm7fHQnI+daBMM FFCucvUZ45z56MWkxq0HJUyE5QWCI6WBh3P6tmiC2ZzW6Fl+StyG9RmUWLGorC6viO9K2nWDRi /d0= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Mar 2023 23:18:58 -0700 IronPort-SDR: c2q8SaOz/kPwhKE5g/h0O6nxnEho124mp4XriLdSqijaApaIrbbfaine1FfeFjtHHBDZr2CvfH apYMAor6REEyWY1m362s/Ua+TclvgTNchj2ki5qnA9pmqzKglstflIQ0q1doz/7JwfS5FGjjgC nV/UqKwTCA5XObOFM6sU8zhRudUFlIN14bhbk9vvL7AIMUE8l/xHXRtE3O/Dkb9RjAu6ZrhNfM guaBjOjA1DffRJsQ4s/GU3/Ocv135ui65xpmebHp8wC5m8HqQ70/hfmjwYkNrj+1RMgnV/jtqV q/Q= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Mar 2023 00:02:44 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pk94z2hdjz1RtW0 for ; Sat, 25 Mar 2023 00:02:43 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1679727762; x=1682319763; bh=J/a1XPwL+xSkbmNIxh IJYkrLti8dXBeJ4FmvtofrtKI=; b=ErpSNvL+jGfnqqLqQn+/QHDaiidQDcOs/n 0qE3jJgGN1O+ZN6jPfeKfzGvv+sV+Xm9xQbMPMzBw+tWfKc8oPxjH4+ydg+ojYG8 XrptPtDHAY86CTM+KWSZpzCOKKXhiD2gIlYYz3cNDHoXN9TtlBUDOWt/pdO6I2+b FeRtpI/CuJU1v/7sjiYfIfPRCFa88s6nC6IxU2fOif0oYbgN1ijAjAfouiFQuaR6 tmT8TAs4ryq8/i14j5xZFr9BxPUkY3A8OQLQ7dbeIketMql2ZSsuhtnQpZwPd0I3 MZTEMyRy9ltk07vR447NImNlvt/A+W43qR/wCrI8AOZUt4JKT9hQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id QTBnAcb7mLx5 for ; Sat, 25 Mar 2023 00:02:42 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pk94x007sz1RtVn; Sat, 25 Mar 2023 00:02:40 -0700 (PDT) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v3 07/16] PCI: epf-test: Simply pci_epf_test_raise_irq() Date: Sat, 25 Mar 2023 16:02:17 +0900 Message-Id: <20230325070226.511323-8-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> References: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Change the interface of the function pci_epf_test_raise_irq() to directly pass a pointer to the struct pci_epf_test_reg defining the test being executed. This avoids the need for grabbing this pointer with a cast of the register bar and simplifies the call sites as the irq type and irq numbers do not have to be passed as arguments. Reviewed-by: Manivannan Sadhasivam Signed-off-by: Damien Le Moal --- drivers/pci/endpoint/functions/pci-epf-test.c | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index b8b178ac7cda..3835e558937a 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -607,29 +607,27 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test, return ret; } -static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, u8 irq_type, - u16 irq) +static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) { struct pci_epf *epf = epf_test->epf; struct device *dev = &epf->dev; struct pci_epc *epc = epf->epc; - enum pci_barno test_reg_bar = epf_test->test_reg_bar; - struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; reg->status |= STATUS_IRQ_RAISED; - switch (irq_type) { + switch (reg->irq_type) { case IRQ_TYPE_LEGACY: pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, PCI_EPC_IRQ_LEGACY, 0); break; case IRQ_TYPE_MSI: pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, - PCI_EPC_IRQ_MSI, irq); + PCI_EPC_IRQ_MSI, reg->irq_number); break; case IRQ_TYPE_MSIX: pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, - PCI_EPC_IRQ_MSIX, irq); + PCI_EPC_IRQ_MSIX, reg->irq_number); break; default: dev_err(dev, "Failed to raise IRQ, unknown type\n"); @@ -675,8 +673,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) reg->status |= STATUS_WRITE_FAIL; else reg->status |= STATUS_WRITE_SUCCESS; - pci_epf_test_raise_irq(epf_test, reg->irq_type, - reg->irq_number); + pci_epf_test_raise_irq(epf_test, reg); goto reset_handler; } @@ -686,8 +683,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) reg->status |= STATUS_READ_SUCCESS; else reg->status |= STATUS_READ_FAIL; - pci_epf_test_raise_irq(epf_test, reg->irq_type, - reg->irq_number); + pci_epf_test_raise_irq(epf_test, reg); goto reset_handler; } @@ -697,8 +693,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) reg->status |= STATUS_COPY_SUCCESS; else reg->status |= STATUS_COPY_FAIL; - pci_epf_test_raise_irq(epf_test, reg->irq_type, - reg->irq_number); + pci_epf_test_raise_irq(epf_test, reg); goto reset_handler; } From patchwork Sat Mar 25 07:02:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13187644 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF900C6FD1C for ; Sat, 25 Mar 2023 07:02:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231927AbjCYHCy (ORCPT ); Sat, 25 Mar 2023 03:02:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231932AbjCYHCr (ORCPT ); Sat, 25 Mar 2023 03:02:47 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECB7D14200 for ; Sat, 25 Mar 2023 00:02:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1679727765; x=1711263765; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NO8Rhu//AxIrrspALxKn62RC+pXJTNz3Th/wi13bFi8=; b=SobxFBuzRMjpbkB8dJ802xmDMBaqa+XpHaqGVpC245g+rrBDWzQ/dOwL cRJyI1EELVvajIq4A4g1NM2IkmI6qjiPm3TeHv5gJMDiZQL8xD3nEykW9 EIsBtWsdLw1mxRUujuDtEPAo+sTGSg2h2BbGR/TDSfrb6FcJMuIaZWPUw FLROcHeNfraoaE4EfP0eido8QNL5PJyIxFM0pQVZtLtUHy6fp/X5zJt6q opXPpm4ugToYiIxi9/hCJXuOXwASeTTcBtJHCuNYKTgdGrag/N//glPG4 MO93maYdO6Tsj9uF7/6ObFoyasVbJ3V48XJowrJQdvT31SX6FZsJl2MYr A==; X-IronPort-AV: E=Sophos;i="5.98,289,1673884800"; d="scan'208";a="224756820" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2023 15:02:45 +0800 IronPort-SDR: 2PzuYsQJF6K9t6DMrg6egjELBgRdmwh+9J7EwqBxqFhOq3vHhWgycffQDZ4EKQ05Z4UrIpL9oz /mz1P30kTwwaHcBnaM45D32G1ag3Ae4otb/ayYPJK3OsfjLlr3kPZ4clqHZK6OQwac6Kl+SQnS dZi9gtDCDUubeZ58m7xple9BDEySTskqPod9y8hjpgCBh5EKCeYUyD8QJOzryD7g1mACe/BtEh 6mpdzZcPRxHDLOv3eE1QuMmNqKNd8tP8IMH30dk7tQl+akVpszxEopxKrCgCPnkP9/Oh6Y/z6S FRg= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Mar 2023 23:19:00 -0700 IronPort-SDR: tYbPvMcy1wuX59SY3TOhlLI9DbP3C1rLj2jZPzViaWwWMi3ERqf2isT5HgCxEHsM+uHldKkPWW PeqRnfEMwHidJzcXxf+vKGk5GU8ZIvrdu3si1GR6oeeKtQ5rzsAqtMoMCuk8E9wEXyvwSKYTDf mJ90X8+6e2+e0yWVOM9pqVuL+dOtqyvehKwVC6ejI5I8euJlNMnZZRiOIttHMZIw1eduNZEykb XjpvsDQuQ9IAdLhfGT4MAbqu2nA1o9hiC6wEzy/RwKdNJ90Ynxl5l2ufBXO/msR//okbzsikH1 6is= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Mar 2023 00:02:46 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pk9513hz0z1RtW3 for ; Sat, 25 Mar 2023 00:02:45 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1679727764; x=1682319765; bh=NO8Rhu//AxIrrspALx Kn62RC+pXJTNz3Th/wi13bFi8=; b=IZbevq3P1kCnnHQPqS5uoG1IlnbUhoF1ts 12vfsPichJMeIer/cqJjqbMsA1n3HIVzLbeSiULxj5qMDeMcY4lQ1epJa5buxTV2 2tONzoQDv5DNpiLW6RuNu38qxlRABrRrY3k8DmdEPlIfJ9jSagFnwEvLZ/jAAm6/ 5ryqJ6ZzXqz6HAwwSAkL+QiKnxPXM/6Oh8lNCPiOfEVgDGa/MJda2nO+++OEkxwU 3JUdSLellbIuHSNxodu1mHp5zhVtFacj7rz3lET9pRcT2L9stRj4BJIVDHsTkIsn 0mfSVVKjjY+K603ntCKR1iiLqq2Qv0W+S3a/NnHIYSPxFePHrsZw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id XUkkJq8Vfhhn for ; Sat, 25 Mar 2023 00:02:44 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pk94y60Cbz1RtVm; Sat, 25 Mar 2023 00:02:42 -0700 (PDT) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v3 08/16] PCI: epf-test: Simplify IRQ test commands execution Date: Sat, 25 Mar 2023 16:02:18 +0900 Message-Id: <20230325070226.511323-9-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> References: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org For the commands COMMAND_RAISE_LEGACY_IRQ, COMMAND_RAISE_MSI_IRQ and COMMAND_RAISE_MSIX_IRQ, the function pci_epf_test_cmd_handler() sets the STATUS_IRQ_RAISED status flag and calls the epc function pci_epc_raise_irq() directly. However, this is also exactly what the pci_epf_test_raise_irq() function does. Avoid duplicating these operations by directly using pci_epf_test_raise_irq() for the IRQ test commands. It is OK to do so as the host side endpoint test driver always set the correct irq type for the IRQ test commands. At the same time, the irq number check done for the COMMAND_RAISE_MSI_IRQ and COMMAND_RAISE_MSIX_IRQ commands can also be moved to pci_epf_test_raise_irq() to also check the IRQ number requested by the host for other test commands. Overall, this significantly simplifies the pci_epf_test_cmd_handler() function. Reviewed-by: Manivannan Sadhasivam Signed-off-by: Damien Le Moal --- drivers/pci/endpoint/functions/pci-epf-test.c | 43 ++++++++----------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 3835e558937a..ee90ba3a957b 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -613,6 +613,7 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, struct pci_epf *epf = epf_test->epf; struct device *dev = &epf->dev; struct pci_epc *epc = epf->epc; + int count; reg->status |= STATUS_IRQ_RAISED; @@ -622,10 +623,22 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, PCI_EPC_IRQ_LEGACY, 0); break; case IRQ_TYPE_MSI: + count = pci_epc_get_msi(epc, epf->func_no, epf->vfunc_no); + if (reg->irq_number > count || count <= 0) { + dev_err(dev, "Invalid MSI IRQ number %d / %d\n", + reg->irq_number, count); + return; + } pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, PCI_EPC_IRQ_MSI, reg->irq_number); break; case IRQ_TYPE_MSIX: + count = pci_epc_get_msix(epc, epf->func_no, epf->vfunc_no); + if (reg->irq_number > count || count <= 0) { + dev_err(dev, "Invalid MSIX IRQ number %d / %d\n", + reg->irq_number, count); + return; + } pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, PCI_EPC_IRQ_MSIX, reg->irq_number); break; @@ -638,13 +651,11 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, static void pci_epf_test_cmd_handler(struct work_struct *work) { int ret; - int count; u32 command; struct pci_epf_test *epf_test = container_of(work, struct pci_epf_test, cmd_handler.work); struct pci_epf *epf = epf_test->epf; struct device *dev = &epf->dev; - struct pci_epc *epc = epf->epc; enum pci_barno test_reg_bar = epf_test->test_reg_bar; struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; @@ -660,10 +671,10 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) goto reset_handler; } - if (command & COMMAND_RAISE_LEGACY_IRQ) { - reg->status = STATUS_IRQ_RAISED; - pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, - PCI_EPC_IRQ_LEGACY, 0); + if ((command & COMMAND_RAISE_LEGACY_IRQ) || + (command & COMMAND_RAISE_MSI_IRQ) || + (command & COMMAND_RAISE_MSIX_IRQ)) { + pci_epf_test_raise_irq(epf_test, reg); goto reset_handler; } @@ -697,26 +708,6 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) goto reset_handler; } - if (command & COMMAND_RAISE_MSI_IRQ) { - count = pci_epc_get_msi(epc, epf->func_no, epf->vfunc_no); - if (reg->irq_number > count || count <= 0) - goto reset_handler; - reg->status = STATUS_IRQ_RAISED; - pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, - PCI_EPC_IRQ_MSI, reg->irq_number); - goto reset_handler; - } - - if (command & COMMAND_RAISE_MSIX_IRQ) { - count = pci_epc_get_msix(epc, epf->func_no, epf->vfunc_no); - if (reg->irq_number > count || count <= 0) - goto reset_handler; - reg->status = STATUS_IRQ_RAISED; - pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, - PCI_EPC_IRQ_MSIX, reg->irq_number); - goto reset_handler; - } - reset_handler: queue_delayed_work(kpcitest_workqueue, &epf_test->cmd_handler, msecs_to_jiffies(1)); From patchwork Sat Mar 25 07:02:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13187645 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A730CC6FD1F for ; Sat, 25 Mar 2023 07:02:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231932AbjCYHCz (ORCPT ); Sat, 25 Mar 2023 03:02:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231958AbjCYHCv (ORCPT ); Sat, 25 Mar 2023 03:02:51 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE2201816A for ; Sat, 25 Mar 2023 00:02:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1679727767; x=1711263767; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hccwggJJwzfgdDztJNFo5zJ5OiRPzd+iDuSC1/Wq8lQ=; b=VqA/kCzkvqUaTYMlS9eJSuBQZsRsLRkhzzyQPgzNRoDt6hk7f2KumSNP Dt8J8H8t5CziZfUTo6J+9Sa4v9I6HaYeFK2QW0Og6YXXkXFwxzba2GZwh F7L/Sg8Wnw0ABdhSZeFP2SpGounGs6+1b5XYLDYUdg8TQFCyrlHNKNhhl h0ldan76R+/4dq8Lsv2BC3g9rUyv8teqQpEuwUBllQHPWc3yAaGYVaRWG G9JQ+yRGUEhWIjgLrGyS0eEsv6sTyGmMnGmy4n/D70BcUsYIua9pEHM36 mzMFNPAXAVSwzGKRV4/S+yJ7uaBQP7hMu67aT7Z1ZGU+ULaXdBA/nNKvW w==; X-IronPort-AV: E=Sophos;i="5.98,289,1673884800"; d="scan'208";a="224756844" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2023 15:02:47 +0800 IronPort-SDR: Rnh9vKATpC1xoP4Z20pNSiiwnDZf6+VRyhqjPV9bseOLFlHgmUbS+kcGx7UG0xfw3rjDhj7aIf WyCkIZ0zDs1lWtRGKl4P5Gtost8NWMzshf+3ckVN9UWeX3h0ljTCncfur1mNQ3LhRCMLs4LoXz CGuobIEam5+oqnrUhmpkr378GGoUNuzi/rPu1SUALVZlbmtx2xBdVkO/MUp3Thy0cPLbiQkgXJ O3UVFYF3pBpXn/6d9xEJiCFJmM3eAMgyVkri0YFLLHy2rZDvdE++/mjgS2GW6gTgLR7bqHPoq5 hmo= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Mar 2023 23:19:02 -0700 IronPort-SDR: 9FGKLGevL2vRveG8EusDme1qhEI1tF1th0hJlZIxFBQusKvsFSmZ/LkcP/Mo7tLAwhICa8cuT2 8TjKwzzsEtFtFD8rkwCiOFWNEzzrLWhxekGooqDbWKaz9kDtCRMU8czopbBHTCH/SFAd76R4MD lDut/i8/Gt4EYQAZkyv6bDOj4VU+6zMU+4VNo9tncSPqxBa/1To2kkb5epq5SquabtZx83ykvX 2AqDoqHFkJduy/+o+EpNk1lnDsYQbuNmLuNtaKAyZJ1ptDbwilUZNZl/4abK5121YZBifBJzWz 4xY= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Mar 2023 00:02:48 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pk9531K75z1RtVq for ; Sat, 25 Mar 2023 00:02:47 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1679727766; x=1682319767; bh=hccwggJJwzfgdDztJN Fo5zJ5OiRPzd+iDuSC1/Wq8lQ=; b=ORjXzP76DgZwxyU91yulctmtiUnNlOLf9h SCOnas/IPiNuw+Ej3PK/Rlz3UuloPNfoh7c9Q8/GvG3MH+ckVZ/IVUwFoAs4cD6e NsAkRDEkM9zrFGqiUH6xq8hJU8rqagTxso2quw+UC8HPXg8QFtIRpLtkPnoidNQ6 YMzQ45iA3c8vzl1Sv48nVpdrCPVzmZvnnkM0jEq/Sxm5gR6kmBBJwWIJUMrbzSw4 ITOhZ2qk1fU90VedJs0kiFGjHgVIejvT1s/WNUepgZ/oOf2GnvUJ+/LETUty5hyX go9406Bx+eVhqbTJV4wpCK1KteF2x03AxZURHGduMEp1uuIGbNGQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ypLLjA7LriHr for ; Sat, 25 Mar 2023 00:02:46 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pk950662gz1RtVt; Sat, 25 Mar 2023 00:02:44 -0700 (PDT) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v3 09/16] PCI: epf-test: Improve handling of command and status registers Date: Sat, 25 Mar 2023 16:02:19 +0900 Message-Id: <20230325070226.511323-10-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> References: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The pci-epf-test driver uses the test register bar memory directly to get and execute a test registers set by the RC side and defined using a struct pci_epf_test_reg. This direct use relies on a casts of the register bar to get a pointer to a struct pci_epf_test_reg to execute the test case and sending back the test result through the status field of struct pci_epf_test_reg. In practice, the status field is always updated before an interrupt is raised in pci_epf_test_raise_irq(), to ensure that the RC side sees the updated status when receiving the interrupts. However, such cast-based direct access does not ensure that changes to the status register make it to memory, and so visible to the host, before an interrupt is raised, thus potentially resulting in the RC host not seeing the correct status result for a test. Avoid this potential problem by using READ_ONCE()/WRITE_ONCE() when accessing the command and status fields of a pci_epf_test_reg structure. This ensure that a test start (pci_epf_test_cmd_handler() function) and completion (with the function pci_epf_test_raise_irq()) achive a correct synchronization with the host side mmio register accesses. Reviewed-by: Manivannan Sadhasivam Signed-off-by: Damien Le Moal --- drivers/pci/endpoint/functions/pci-epf-test.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index ee90ba3a957b..fa48e9b3c393 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -613,9 +613,14 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, struct pci_epf *epf = epf_test->epf; struct device *dev = &epf->dev; struct pci_epc *epc = epf->epc; + u32 status = reg->status | STATUS_IRQ_RAISED; int count; - reg->status |= STATUS_IRQ_RAISED; + /* + * Set the status before raising the IRQ to ensure that the host sees + * the updated value when it gets the IRQ. + */ + WRITE_ONCE(reg->status, status); switch (reg->irq_type) { case IRQ_TYPE_LEGACY: @@ -659,12 +664,12 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) enum pci_barno test_reg_bar = epf_test->test_reg_bar; struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; - command = reg->command; + command = READ_ONCE(reg->command); if (!command) goto reset_handler; - reg->command = 0; - reg->status = 0; + WRITE_ONCE(reg->command, 0); + WRITE_ONCE(reg->status, 0); if (reg->irq_type > IRQ_TYPE_MSIX) { dev_err(dev, "Failed to detect IRQ type\n"); From patchwork Sat Mar 25 07:02:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13187646 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 364B1C7619A for ; Sat, 25 Mar 2023 07:02:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231956AbjCYHC4 (ORCPT ); Sat, 25 Mar 2023 03:02:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231964AbjCYHCx (ORCPT ); Sat, 25 Mar 2023 03:02:53 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D661A16AC7 for ; Sat, 25 Mar 2023 00:02:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1679727769; x=1711263769; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mxCZujNEUTbNED023BSGdq18vAZhegc8Tr7mjQSp0FE=; b=n8eGSLEJmakUThu8VsNM7UD+pv0xF7oYuE3b8sXUwJZrp7ZTBUEeCk8f mIXFv1ccaTOc7aB8FlYDDG7mggnw5zy2acxqTA5Z1T3AAcc/X57agByxe wnoRctUj/iUHdCz9KHr0wGmDUOns44xu3P3Tl4tSQI97O74YcRvJHND8w kUlH/CqitWylh12rUkISJb7WfLVzyAmx2yPrfu+tXrKtWZvsOHR3U4JJq U0ZjP6pQ49sG0rne2cdf/DrCe8WhoayIcLK+6WA8U5qB1Ogi8shcYaD6n Oz97BreLJK4PKLurNXEc+9d1ArbWIE6wSicN9F3d71eLd5DqF4xjs4vVD g==; X-IronPort-AV: E=Sophos;i="5.98,289,1673884800"; d="scan'208";a="224756874" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2023 15:02:49 +0800 IronPort-SDR: taO9EbDo8XzBAYzp4IAJmw/olpBs3J51WCBbQOKOAWln0d3AJA57pL2vYcJDwka/Yz9Zdki0+6 UKo3RbxbkV2ppcDVrM03sQx8m2UwZvr+UOGrrCcZQ3UmD7FYo2g4mndqNNd72nECXRftGhpbgG 73sLnOJRhuZIdR6u4v7y5EY/lNvtOnewCPbGDAKZguKJ3IiZJqORDCL3NFLfYs68y4xy9zo999 OFHlY44qUQlAB1qLeNKIUQNGYcTz0jyiormx4+JAnmN3COA/hyC1HaI9AcKP5uBHznWYZYF6Kh 58M= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Mar 2023 23:19:04 -0700 IronPort-SDR: lnWwSbnUsVKZJ4+84IaRL3I3WjBcIK9rGNkE/zigrh+WBmzHcPftVj3Owc+j6BJYEpKO8n8Smb U3krIIj4QUCeY1UnXIG7jusTN84PPDqvUTKLljxmgjB13qMEKto0qjjfV8FVM7wJs4CFdnlDCm mwQtuH+si+lWKFVS8qh+Lo2cnJfd0X0kPIC1iHQ7JguLZv59EaXvCsToa0VA9Mbobj1Qw6xUhc Ny0pahDXgB3y+A2L0414s5054H+CrNteD8+lRDg/P6gQmrfZ6P2NxnWLDQF8Ij8Vr1MUhX+FI5 KbE= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Mar 2023 00:02:50 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pk9550n4jz1RtW2 for ; Sat, 25 Mar 2023 00:02:49 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1679727768; x=1682319769; bh=mxCZujNEUTbNED023B SGdq18vAZhegc8Tr7mjQSp0FE=; b=iYunxu81F4LmZrsfAi3xWIkivYiM82pEEE IlnVmZnkpCTX8U88sutbMqvwyMg5eg6iaRcKtdyAUgqL20y+WynB/xd9HVmiZZce 2NvaxC16jopZ+JyQjP/dZ4xxEubuZZFhhxFHIUiEtEgoM0364T3c91BLYPoPcv5Z AMR93QZhedkDM+6Kd2yeFyRBlDiz+3VaAJw8Zk78f00Yan6coTSb+RSk3EYfVhrT k6sFIv2kbOnw/RVaJ6SE1sUWAHKtIBx41wTswqlG0rz1yRmST9SE3b9uMG6XvwP3 txB69V7MNBlQ3R3J0EXOT5hkzQXg61tPtUfUGspb8jysztq0LsDg== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id SQ7RXJkvpXNp for ; Sat, 25 Mar 2023 00:02:48 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pk9525K2Tz1RtVm; Sat, 25 Mar 2023 00:02:46 -0700 (PDT) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v3 10/16] PCI: epf-test: Cleanup pci_epf_test_cmd_handler() Date: Sat, 25 Mar 2023 16:02:20 +0900 Message-Id: <20230325070226.511323-11-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> References: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Command codes are never combined together as flags into a single value. Thus we can replace the series of "if" tests in pci_epf_test_cmd_handler() with a cleaner switch-case statement. This also allows checking that we got a valid command and print an error message if we did not. Reviewed-by: Manivannan Sadhasivam Signed-off-by: Damien Le Moal --- drivers/pci/endpoint/functions/pci-epf-test.c | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index fa48e9b3c393..c2a14f828bdf 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -676,41 +676,39 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) goto reset_handler; } - if ((command & COMMAND_RAISE_LEGACY_IRQ) || - (command & COMMAND_RAISE_MSI_IRQ) || - (command & COMMAND_RAISE_MSIX_IRQ)) { + switch (command) { + case COMMAND_RAISE_LEGACY_IRQ: + case COMMAND_RAISE_MSI_IRQ: + case COMMAND_RAISE_MSIX_IRQ: pci_epf_test_raise_irq(epf_test, reg); - goto reset_handler; - } - - if (command & COMMAND_WRITE) { + break; + case COMMAND_WRITE: ret = pci_epf_test_write(epf_test, reg); if (ret) reg->status |= STATUS_WRITE_FAIL; else reg->status |= STATUS_WRITE_SUCCESS; pci_epf_test_raise_irq(epf_test, reg); - goto reset_handler; - } - - if (command & COMMAND_READ) { + break; + case COMMAND_READ: ret = pci_epf_test_read(epf_test, reg); if (!ret) reg->status |= STATUS_READ_SUCCESS; else reg->status |= STATUS_READ_FAIL; pci_epf_test_raise_irq(epf_test, reg); - goto reset_handler; - } - - if (command & COMMAND_COPY) { + break; + case COMMAND_COPY: ret = pci_epf_test_copy(epf_test, reg); if (!ret) reg->status |= STATUS_COPY_SUCCESS; else reg->status |= STATUS_COPY_FAIL; pci_epf_test_raise_irq(epf_test, reg); - goto reset_handler; + break; + default: + dev_err(dev, "Invalid command\n"); + break; } reset_handler: From patchwork Sat Mar 25 07:02:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13187647 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FB65C77B60 for ; Sat, 25 Mar 2023 07:02:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231928AbjCYHC4 (ORCPT ); Sat, 25 Mar 2023 03:02:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231976AbjCYHCy (ORCPT ); Sat, 25 Mar 2023 03:02:54 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DC7715CA6 for ; Sat, 25 Mar 2023 00:02:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1679727771; x=1711263771; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sBuTYkv/S3ZLZG82d1SOcoTgDB/NCZvWuNNGG6u/bhE=; b=qIWDpik28/5Rg2TZ8p/N/YaORkygDzvFo/ud9BLSb7V0cQBrWKiMvvE1 ud2UaMFhSb9qiHK32q/HZQppIBmS7h9BckFgxC82ynockCQClH4lYQjbk PwAbr803PE5N/D/PayfmITyLq07LRyAPqvCRFPpJ3f1PknAMKi1vnO6Tc j7dOYjNuoKvzwJeUGfGFXCCU2YJIMHgHuJWzjOLaV1pAIU0n0xWoykJWt xDI8HwK62715L4qvQ4lTmPkOlWNL7EuOsWnzc8EsZelEBXondX3SmyZ0L CPL71w2iWnuALnByhiNWK5XSczFdwb/TDU0d8sWguL0N/4V0QOKRKNiVz Q==; X-IronPort-AV: E=Sophos;i="5.98,289,1673884800"; d="scan'208";a="224756901" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2023 15:02:51 +0800 IronPort-SDR: lzGhswX5Ie/mPJAzJbYaD0mwhhvgJlspSrdpRVRhEcnhGnpVIhhFctISILOGSXsVixYJ4Y0tDL BeZ/DDS5Lemmt5Bml0elt3/oVVN4dgSoDmXz9FlNk5KuVd5j5u9QAKorURSXBPpOIp0Ct65zqP R3ZD1mzxu+51tTbJD0TM7azNk/SaciYMKBjern75BYymJMBz248QTz4CPOiaaaVZ/kvYEiW0Eb jDB3P8c0PfSXOIeKphYYcwyMfiBvjcGzGfZ/3pQP8bK7VHU68vZWUq69tk8K/VUZd5iU5xlQjT juU= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Mar 2023 23:19:06 -0700 IronPort-SDR: MBN/bOV20uxPZOnwqg/JFBhJdgUTxDDK22Xr5dq1ybGTkt/j7O/NjlN1RD+kG7yxdpftu/hpZa fh8wR1VubD5h2shvYejnXCSsnSadQHJf2U5ZbLjwRPOu6AQQTfylRRwoxyLr1NwK20dHO5XS6m OGRMAqQJr5VQ6WVig5jaPtSogNA1wk8W6Iby8yoyg9NsAnOWiORcaQYT5QSlwxPZ0WfArZ2NoV lo1Vp7TgBcSs0Iz7IGCftHehHm4O5VmBSy1OK76UgfDlXr3ApheKONVMxn7942tyQf+b7CBmBj m3w= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Mar 2023 00:02:52 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pk9566d1Fz1RtVw for ; Sat, 25 Mar 2023 00:02:50 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1679727770; x=1682319771; bh=sBuTYkv/S3ZLZG82d1 SOcoTgDB/NCZvWuNNGG6u/bhE=; b=sFaNCUeNT9Kd8T1C9hMxQsYVubOWNQPNh5 ZGys35WNlFbQaKsky7ufQRVityOETbJpj2eJLjngCBHhQXUkqNh8rctluXxo2ujA CkNWdJMZ9qBLBJFcDBEhImn/iaAk5QiY7926le7YOFD/3Iuy12wNcvIJYoMF7pvX bCIt3PPxRhv8II2OPpvRnxzoRxQ0HXD/zNGrT/8riLXQWdcJtWrVW9nfgRHJaaym hzYNbwyROW8vEY+ws40a8Gz9WKRhuDmR6XDDbjBOJZAyiXlBVXVFGZqc3gypiWyl VcjneMyDp6lg1Bqft4KoQAt3JXJb7O9NJx7fZSMeGbrtCzjZkuaQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id XoQjKVIxyzCd for ; Sat, 25 Mar 2023 00:02:50 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pk954469hz1RtVp; Sat, 25 Mar 2023 00:02:48 -0700 (PDT) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v3 11/16] PCI: epf-test: Simplify dma support checks Date: Sat, 25 Mar 2023 16:02:21 +0900 Message-Id: <20230325070226.511323-12-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> References: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org There is no need to have each read, write and copy test functions check for the FLAG_USE_DMA flag against the dma support status indicated by epf_test->dma_supported. Move this test to the command handler function pci_epf_test_cmd_handler() to check once for all cases. Reviewed-by: Manivannan Sadhasivam Signed-off-by: Damien Le Moal --- drivers/pci/endpoint/functions/pci-epf-test.c | 45 +++++++------------ 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index c2a14f828bdf..abc50d5bff97 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -329,7 +329,6 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test, struct pci_epf_test_reg *reg) { int ret; - bool use_dma; void __iomem *src_addr; void __iomem *dst_addr; phys_addr_t src_phys_addr; @@ -372,14 +371,7 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test, } ktime_get_ts64(&start); - use_dma = !!(reg->flags & FLAG_USE_DMA); - if (use_dma) { - if (!epf_test->dma_supported) { - dev_err(dev, "Cannot transfer data using DMA\n"); - ret = -EINVAL; - goto err_map_addr; - } - + if (reg->flags & FLAG_USE_DMA) { if (epf_test->dma_private) { dev_err(dev, "Cannot transfer data using DMA\n"); ret = -EINVAL; @@ -405,7 +397,8 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test, kfree(buf); } ktime_get_ts64(&end); - pci_epf_test_print_rate("COPY", reg->size, &start, &end, use_dma); + pci_epf_test_print_rate("COPY", reg->size, &start, &end, + reg->flags & FLAG_USE_DMA); err_map_addr: pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, dst_phys_addr); @@ -430,7 +423,6 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test, void __iomem *src_addr; void *buf; u32 crc32; - bool use_dma; phys_addr_t phys_addr; phys_addr_t dst_phys_addr; struct timespec64 start, end; @@ -461,14 +453,7 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test, goto err_map_addr; } - use_dma = !!(reg->flags & FLAG_USE_DMA); - if (use_dma) { - if (!epf_test->dma_supported) { - dev_err(dev, "Cannot transfer data using DMA\n"); - ret = -EINVAL; - goto err_dma_map; - } - + if (reg->flags & FLAG_USE_DMA) { dst_phys_addr = dma_map_single(dma_dev, buf, reg->size, DMA_FROM_DEVICE); if (dma_mapping_error(dma_dev, dst_phys_addr)) { @@ -493,7 +478,8 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test, ktime_get_ts64(&end); } - pci_epf_test_print_rate("READ", reg->size, &start, &end, use_dma); + pci_epf_test_print_rate("READ", reg->size, &start, &end, + reg->flags & FLAG_USE_DMA); crc32 = crc32_le(~0, buf, reg->size); if (crc32 != reg->checksum) @@ -518,7 +504,6 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test, int ret; void __iomem *dst_addr; void *buf; - bool use_dma; phys_addr_t phys_addr; phys_addr_t src_phys_addr; struct timespec64 start, end; @@ -552,14 +537,7 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test, get_random_bytes(buf, reg->size); reg->checksum = crc32_le(~0, buf, reg->size); - use_dma = !!(reg->flags & FLAG_USE_DMA); - if (use_dma) { - if (!epf_test->dma_supported) { - dev_err(dev, "Cannot transfer data using DMA\n"); - ret = -EINVAL; - goto err_dma_map; - } - + if (reg->flags & FLAG_USE_DMA) { src_phys_addr = dma_map_single(dma_dev, buf, reg->size, DMA_TO_DEVICE); if (dma_mapping_error(dma_dev, src_phys_addr)) { @@ -586,7 +564,8 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test, ktime_get_ts64(&end); } - pci_epf_test_print_rate("WRITE", reg->size, &start, &end, use_dma); + pci_epf_test_print_rate("WRITE", reg->size, &start, &end, + reg->flags & FLAG_USE_DMA); /* * wait 1ms inorder for the write to complete. Without this delay L3 @@ -671,6 +650,12 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) WRITE_ONCE(reg->command, 0); WRITE_ONCE(reg->status, 0); + if ((READ_ONCE(reg->flags) & FLAG_USE_DMA) && + !epf_test->dma_supported) { + dev_err(dev, "Cannot transfer data using DMA\n"); + goto reset_handler; + } + if (reg->irq_type > IRQ_TYPE_MSIX) { dev_err(dev, "Failed to detect IRQ type\n"); goto reset_handler; From patchwork Sat Mar 25 07:02:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13187648 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69152C6FD1C for ; Sat, 25 Mar 2023 07:02:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231960AbjCYHC5 (ORCPT ); Sat, 25 Mar 2023 03:02:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231954AbjCYHCz (ORCPT ); Sat, 25 Mar 2023 03:02:55 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29B1F15882 for ; Sat, 25 Mar 2023 00:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1679727773; x=1711263773; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f6vOJtQ60F3eVOPUSRn4w9ivZnAhueTWkWhHYuFb/Io=; b=DAlqeOzY+QHw+CClor5YzHU6yoPCOcMv7bBYbgHrR7oHXh1LuZBVVcR4 GtzyYoNUZQeKJ4fCdIZG7MihkFB8jq7NM8QPXWIOQDuswr8jsSy/WO3Rj vohvoxm2uDhl+RM3kQ8opI+iguI93Hq8TqbfDdayiBR5CeKrkzkVH8mK7 WwqlY2G8xLGDZA+EZCUkNZ2HHfoaiV7AZtaXmGK/E9PGt30nnZ3bg9jye Vwc3JDS3Gn0QkFqP6tg0fia5Wj7QAjED2/wLEesitz+fWIFljdvgEADtH tRoYOxbhki3yV+T2rJfofQs6sRhJ+w1s1ESX8GCa3iQMPoUYEZ1S+8r4S Q==; X-IronPort-AV: E=Sophos;i="5.98,289,1673884800"; d="scan'208";a="224756910" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2023 15:02:53 +0800 IronPort-SDR: CKaDzh/thx61V8nVdG3+8I1pyjR4KXN3xlJZqZ2WI19phzJmo+IG6QDN75XCIuFvQjx5uNGQXM egQlFUY48ZvVlRHianV5dIiN5jJ/fmYWHdR0qEkmJY9/Evkp4j7hhLmCMlmZZlgih+naMTz3X8 nCs4XzIVKw4/BLAyjSHFdgiRVoucFpL8YNunnBilgODQfSIZRsvLeRoV6YUmfIS9AmFMg3GSdL 8PQtVH3SsvqwM5oPa7tfBtULHsNksUw2aTZDeFQkdENjkUIOnScG8ZFAD3GnS9FvB6uX1dqHBo EhQ= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Mar 2023 23:19:07 -0700 IronPort-SDR: jWqexu0nYpScKtEcFPI+IVQ9e1Dj9zM0vV9Cp33IC2kHmubvyzSwHiNNq59ctjLuYilpmMpWog ZSI3KrdLv+0mm7OL51wopB++b5xN3Q5pCEQOsjDi4qQN3FUD688QdAi5tiNtr3co8wSViYZnzv ap/MEDRWFQGkqnDd9rpmUpm7A8NawPRCJOh4XDy4ONocX3eOtIM/+Kswpn+MpHrPJ11NXG2hid UePYFZagaTI0Z3JgbnqLBnhuNGPqxxOkbq34xajtEepNlh4ni+2fqu8QmM4rNy2EUVw6ECSO3y eEo= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Mar 2023 00:02:54 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pk95902Mgz1RtVp for ; Sat, 25 Mar 2023 00:02:52 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1679727771; x=1682319772; bh=f6vOJtQ60F3eVOPUSR n4w9ivZnAhueTWkWhHYuFb/Io=; b=Fyk1GC7t1d/x6SyTg9DPvxsRrFNU6NCPhO JmBSzuEPrSlygYdi0qdAMdQm2dKjF4aG1WyfuyY2ACyliVmhCQJSLtWR3mIf1vTp jf6ktvybY8fp/JIBdTqp1leYQQ6v2JG1J+pZh0Y2Ph+ILjErEPxMulM9R1NCSwqx oXK955jha1Iur/7Z3Fa2DNc5PORY1nkPedLklyQCTdAfVZtVqgbu9nyARGYoHPDR kYXgv+wfFvP1pW2HOg5mEJ4gtWyNQ1CF6NjvIKo1jAG37ZBCx8jkeLZMQnZf+FrU cNrjy+4uqaVpLdPHIj46BMwIbt1OvRN370dMLp9RURbgqfbW9AxA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id N-pv8Y4LQr57 for ; Sat, 25 Mar 2023 00:02:51 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pk9562cvFz1RtVm; Sat, 25 Mar 2023 00:02:50 -0700 (PDT) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v3 12/16] PCI: epf-test: Simplify transfers result print Date: Sat, 25 Mar 2023 16:02:22 +0900 Message-Id: <20230325070226.511323-13-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> References: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In pci_epf_test_print_rate(), instead of open coding a reduction loop to allow for a division by a 32-bits ns value, simply use div64_u64() to calculate the transfer rate. To match the printed unit of KB/s, this calculation divides the rate by 1000 instead of 1024 (that would be KiB/s unit). The format of the results printed by pci_epf_test_print_rate() is also changed to be more compact without the double new line. dev_info() is used instead of pr_info(). Reviewed-by: Manivannan Sadhasivam Signed-off-by: Damien Le Moal --- drivers/pci/endpoint/functions/pci-epf-test.c | 39 +++++++------------ 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index abc50d5bff97..7250219af853 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -295,34 +295,23 @@ static void pci_epf_test_clean_dma_chan(struct pci_epf_test *epf_test) return; } -static void pci_epf_test_print_rate(const char *ops, u64 size, +static void pci_epf_test_print_rate(struct pci_epf_test *epf_test, + const char *op, u64 size, struct timespec64 *start, struct timespec64 *end, bool dma) { - struct timespec64 ts; - u64 rate, ns; - - ts = timespec64_sub(*end, *start); - - /* convert both size (stored in 'rate') and time in terms of 'ns' */ - ns = timespec64_to_ns(&ts); - rate = size * NSEC_PER_SEC; - - /* Divide both size (stored in 'rate') and ns by a common factor */ - while (ns > UINT_MAX) { - rate >>= 1; - ns >>= 1; - } - - if (!ns) - return; + struct timespec64 ts = timespec64_sub(*end, *start); + u64 rate = 0, ns; /* calculate the rate */ - do_div(rate, (uint32_t)ns); + ns = timespec64_to_ns(&ts); + if (ns) + rate = div64_u64(size * NSEC_PER_SEC, ns * 1000); - pr_info("\n%s => Size: %llu bytes\t DMA: %s\t Time: %llu.%09u seconds\t" - "Rate: %llu KB/s\n", ops, size, dma ? "YES" : "NO", - (u64)ts.tv_sec, (u32)ts.tv_nsec, rate / 1024); + dev_info(&epf_test->epf->dev, + "%s => Size: %llu B, DMA: %s, Time: %llu.%09u s, Rate: %llu KB/s\n", + op, size, dma ? "YES" : "NO", + (u64)ts.tv_sec, (u32)ts.tv_nsec, rate); } static int pci_epf_test_copy(struct pci_epf_test *epf_test, @@ -397,7 +386,7 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test, kfree(buf); } ktime_get_ts64(&end); - pci_epf_test_print_rate("COPY", reg->size, &start, &end, + pci_epf_test_print_rate(epf_test, "COPY", reg->size, &start, &end, reg->flags & FLAG_USE_DMA); err_map_addr: @@ -478,7 +467,7 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test, ktime_get_ts64(&end); } - pci_epf_test_print_rate("READ", reg->size, &start, &end, + pci_epf_test_print_rate(epf_test, "READ", reg->size, &start, &end, reg->flags & FLAG_USE_DMA); crc32 = crc32_le(~0, buf, reg->size); @@ -564,7 +553,7 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test, ktime_get_ts64(&end); } - pci_epf_test_print_rate("WRITE", reg->size, &start, &end, + pci_epf_test_print_rate(epf_test, "WRITE", reg->size, &start, &end, reg->flags & FLAG_USE_DMA); /* From patchwork Sat Mar 25 07:02:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13187649 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30C1FC6FD1F for ; Sat, 25 Mar 2023 07:03:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231958AbjCYHDA (ORCPT ); Sat, 25 Mar 2023 03:03:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231946AbjCYHC7 (ORCPT ); Sat, 25 Mar 2023 03:02:59 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC968166FD for ; Sat, 25 Mar 2023 00:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1679727774; x=1711263774; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c6fb/ATpu4bjomFurbyO/sIS4IvcEwK34bItru+sYXM=; b=SXEURKL3yXm1lj1FsyMVgfL0T9hpd7ZwXqxiTX8Hg7+itIpGelzsQ1m6 /h9nEj7F2VSDZHSenmYey3Mx8rcT/F3zZGC5s/LSPDpLVQT/I7DSuYYAI Ca+5Zu2XVcy6ctmc/UR1HzoNvJZ8KfIJaaA3OpmdNcWUBMqOXTqk/dKCf vAiSYUgiHNWfK8jCPTOP0WirkVTZuAt0luxGx6JIxX3G9v0z/8c9icNQX V+R9xkIApMd6HqthnVFhx2TrMQOTYXodx7xBKCOrA6mk9VVAJhbmgXo7z qhmzJAkAcNbVTfrV2oCeV5q31wxxJqlO+3/yDEkyL8mVCSr+/ViCiydzW g==; X-IronPort-AV: E=Sophos;i="5.98,289,1673884800"; d="scan'208";a="224756914" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2023 15:02:54 +0800 IronPort-SDR: Xj32pD+NBZcLFnUVuP6cQIkMoi3ocj29VbG27Y28ABNOK+9wHX3WL9+rVQ71P8e73RrJFQAmIx Ov4tGhB+ufsSLBEcercupeaoNjdrhrRvF8hhm8o26XtSQL5w+ddgv2JDB9fphaflbQ3N8MJO1q abbW7+Jz44ZNwNnySVeWH4+a/YsETsxbJvwgVVFvDPngjxBy/P/glF02JbA18UUoWMjdVj4NU+ rRiNY1RyQ4/QRf63lCSGTdDeU8sNiHT8ZbP0jbe1HoK1XSi/snJNx8eNQoSmBP2NNEt0xNepuZ jl4= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Mar 2023 23:19:09 -0700 IronPort-SDR: sqYLNDLtobcSI76eAYWWiXg5Vmk6w1vm7p0Xai0/+mucUhXMbdx3aZfcj0/W1aDcrJUY/ral55 GcsKnQz79O653ubjAeIosqWiipZGhExTaMw5+pWhWB9SW4KBIqos4DWtrwYSyR09TdYLny2ocl 1KVh3cXZ42qe4ZSjQ+DInxbqzNZA2512NotF1OX/hiGOHoF2rKpbjy5+USwv3vO2u3thvV6KhF s8BMtObNnnVyh5cdZ9quMO6ExVO6Q7zi3mOnlBkiJv7DgY3ctfohsztpXvJzKeq7L15a6ITdlw dLA= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Mar 2023 00:02:55 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pk95B3Pgmz1RtVy for ; Sat, 25 Mar 2023 00:02:54 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1679727773; x=1682319774; bh=c6fb/ATpu4bjomFurb yO/sIS4IvcEwK34bItru+sYXM=; b=G/GlGhN4Yc/681OmHAJT2EJaai00I0hN15 IpWZTI+fbDg06kjb47fixzXOhU3uVDgzG42Cmshyr0HLU/ev4udYPD31famC/l6+ PuJvcuFnoE2Kd4bHdo3JXKzFduF+PcBimq3zv/Gwa09fjAlZgLqORnOHPetjgXXq KkDBFxOWqSUUPLIatzUntoQphJ9xxX5j79F7sSzdUfk9NM4dHJIoA5BawY7i59bf tcZlDG5jFz5usjm8M5LGYuQVkdovKXGKm8VTsVSLkLcOsdH4fzJxAgTuuIfZDII3 x8xmVUGPAg9SHjvGZcqEdkbWxK9KXVz7E9gAeyTFBqZbj/BfubGg== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 7c041ywl5Fss for ; Sat, 25 Mar 2023 00:02:53 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pk9581lN4z1RtVn; Sat, 25 Mar 2023 00:02:52 -0700 (PDT) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v3 13/16] misc: pci_endpoint_test: Free IRQs before removing the device Date: Sat, 25 Mar 2023 16:02:23 +0900 Message-Id: <20230325070226.511323-14-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> References: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In pci_endpoint_test_remove(), freeing the IRQs after removing the device creates a small race window for IRQs to be received with the test device memory already released, causing the IRQ handler to access invalid memory, resulting in an oops. Free the device IRQs before removing the device to avoid this issue. Fixes: e03327122e2c ("pci_endpoint_test: Add 2 ioctl commands") Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/misc/pci_endpoint_test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index a7244de081ec..01235236e9bc 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -938,6 +938,9 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev) if (id < 0) return; + pci_endpoint_test_release_irq(test); + pci_endpoint_test_free_irq_vectors(test); + misc_deregister(&test->miscdev); kfree(misc_device->name); kfree(test->name); @@ -947,9 +950,6 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev) pci_iounmap(pdev, test->bar[bar]); } - pci_endpoint_test_release_irq(test); - pci_endpoint_test_free_irq_vectors(test); - pci_release_regions(pdev); pci_disable_device(pdev); } From patchwork Sat Mar 25 07:02:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13187650 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25C05C7619A for ; Sat, 25 Mar 2023 07:03:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231946AbjCYHDC (ORCPT ); Sat, 25 Mar 2023 03:03:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231954AbjCYHDA (ORCPT ); Sat, 25 Mar 2023 03:03:00 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A88C576AC for ; Sat, 25 Mar 2023 00:02:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1679727776; x=1711263776; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9hc8RCCLWTxRBYC9gxcz8ZAIDPbMiGNQupCTpkbGyu0=; b=ZEJTVdsaBMS0Rio1xApWsNUwzLLksar4jsihd+F0Pw5wi7yKu7fQXqMd FyDHrwv6C40UT5b56Cw+bWIupvHSxHWZovGFIqk8SJlw7yyMY2aPu+ttK UCxWQtQB9mwfqJerNoHR3eJZ+I5YoxPNwaQmZe/tZ3Pp0uP/9u1W37pfv oz8OOZdZqOdwX5eYe1lRNDa/BPcrioBSulqEOv3mLHtnSLyZLUeUoMUzw Tf3CJUsKDBFM2qnhOq6gxDRkwO4RrcPKE8yutlA1GPdh48Or7F67+zjML OjUFCIun8+e3cd7a1c7weXdb4G7nzkdHrAnwlQUTqfR2uNbFIDv9uHtdS g==; X-IronPort-AV: E=Sophos;i="5.98,289,1673884800"; d="scan'208";a="224756919" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2023 15:02:56 +0800 IronPort-SDR: Q2aag1xP/q6MAy3fcrefbssWeN2m7qsQdhoBRWRBfaybQXWPSjVbyXzlPPPJltD8aWUDmMQ/zj 2Ohk/jMFgmKdOcU2vS4RKmt5jnn1mOSSedXI6d1nLSHjvNTw2E2YokdXvIn6Inrh5S/yLwrYoG ijvMptJMRYm7FgcPYNFfjOzgYgDlwBbisb4e2wInm8Hod2ofAH48ovKfD67mEvUUYiRlYfhlew b11JGOIyxE6n0O1LPSJL500JmL2snohDp9VFi7R5hF4ehqKrBNYt/kZgYjAS60HXBpmnwZQhiU eA0= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Mar 2023 23:19:11 -0700 IronPort-SDR: YEHH5W7QcuAuAOZst4MpINVe1VPch7GV4KVOHkzbd7RskHeV+g/vP+/ID9zbmg6n0WujnUCt/h 1lBfwPacSC7wLBEmFvtdOWdAgPlSnVhGpCYW/DjTOSm7hQKt79KbG4Itzim+YuCCnlp6fQwUxn 5k5Lh1oeh+ONPVI8ZnP3bFNjTPPntgd4PgYhothcKvosHTGYvauyDZtpc8n4CxZc8zdtXPDylY /DOvs0icj8rH0KzUMAG96fppMqzYSUapEQ161fdfHmomWnoyEJzKeNak2FYO0W0+Psx6f++veR D9I= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Mar 2023 00:02:57 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pk95D1RPPz1RtW0 for ; Sat, 25 Mar 2023 00:02:56 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1679727775; x=1682319776; bh=9hc8RCCLWTxRBYC9gx cz8ZAIDPbMiGNQupCTpkbGyu0=; b=ZdeuN38sM1qA0XgchFb/3INIsVfdvtLKAz mHUMIDJCyl7g1vWdOCAUuYQ6bAC49x/e0HzXk601ABa921G0zHd/W9cttwkboeS9 Xbf+wB1wdVgdNJVPSTkKiVg3xShoRPU2hU+3eN/VnAq7zBhMFancRVNK2NjA937B qSXDZFWMWatZMSvGZ4FzMr3V382FtDVAQEmRbUxUUO0PXBlHx6HaaXkIKES0ns3W w8mw0E0e/JOmlOuQKyS+XFgFI2ktbLONPpQycyTQSATrSi9Sw85rTHCSk92FaOki 5eXwDmL8ZqtjeLwHQUabK/3OJr10V4o6GILCixGYRSSvneL3AgUw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id CcnUm1hTYjdj for ; Sat, 25 Mar 2023 00:02:55 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pk95B1NXmz1RtVm; Sat, 25 Mar 2023 00:02:53 -0700 (PDT) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v3 14/16] misc: pci_endpoint_test: Re-init completion for every test Date: Sat, 25 Mar 2023 16:02:24 +0900 Message-Id: <20230325070226.511323-15-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> References: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The irq_raised completion used to detect the end of a test case is initialized when the test device is probed, but never reinitialized again before a test case. As a result, the irq_raised completion synchronization is effective only for the first ioctl test case executed. Any subsequent call to wait_for_completion() by another ioctl() call will immediately return, potentially too early, leading to false positive failures. Fix this by reinitializing the irq_raised completion before starting a new ioctl() test command. Fixes: 2c156ac71c6b ("misc: Add host side PCI driver for PCI test function device") Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal --- drivers/misc/pci_endpoint_test.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 01235236e9bc..24efe3b88a1f 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -729,6 +729,10 @@ static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, struct pci_dev *pdev = test->pdev; mutex_lock(&test->mutex); + + reinit_completion(&test->irq_raised); + test->last_irq = -ENODATA; + switch (cmd) { case PCITEST_BAR: bar = arg; From patchwork Sat Mar 25 07:02:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13187651 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72419C6FD1F for ; Sat, 25 Mar 2023 07:03:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231926AbjCYHDE (ORCPT ); Sat, 25 Mar 2023 03:03:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231959AbjCYHDC (ORCPT ); Sat, 25 Mar 2023 03:03:02 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A4329EEF for ; Sat, 25 Mar 2023 00:02:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1679727778; x=1711263778; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nNNBPPwx3BeLf51ftFKDBjdeNrqS7hVotbLqERxh9VU=; b=FsftmrEyvv8zFLRX+3MFUMF3L10wyDeJS1MAkovSMjs2dQOMjvfX+aUI aOED1dimpDEQcFgwrk6iEL05iEyap1jF5eKc8ySWU5yG1wD91BGh4SYd/ E719DuQclNi/HqEVBNYFR3EoJVLeMmEbTvqjTNSWKDG00s7DRNhHj1nqd Vuwl/5/mEB/OWzFsbX3hr05IsLMC3GXVfnecUXKa3MWPj+67xINx9V6gK msp2l05rW+n7IZZU/cHVA/bOQSF12EOoQf66b1U17LJHLQvZXN1hwG6Lu VZKK+8ulVEqNQcgXnQOONoBdZXqr+tDJfLDc0dIW//fXB7E6R5c1GhS9y w==; X-IronPort-AV: E=Sophos;i="5.98,289,1673884800"; d="scan'208";a="224756924" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2023 15:02:57 +0800 IronPort-SDR: E8ff1rfPxiPbCb9a1TExwJ+JlORZ9f37JD1q8Zf4oRYtFNUPfgaCSad8bJuOln1PNdC1WGps/C S4ej4ZuJlCqTszO0HvSCtYNbj7vVsEUtr9XPnS69sx+w/xH/PJ1qMBmXw/eWUDavTl+3KdmVgr AurhsMLIgm3+mfBSVkfXYKqpzu5bO4ULfh9Ffy8OkoAk7n0jOBnRh8ncYm0sPJImIMSJ2y+TzD XUSjArZtKi19I6imfYNdQu0APMLMXdCvO7kIqqgEHEh6G28u4BhIX7GUDsWTZzoznsVDwHi7HK QIo= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Mar 2023 23:19:12 -0700 IronPort-SDR: fw/cdYMMccZ3GcRKkGjetMd7httdGQYDrRpe+mSdFjf5RYDf+VW4mViCejXjfq69XMcUiC3ow4 pk/ffnU1GoDtA+zjEajUp/9gbbYccVaJfv5euItlyaX+i+4fku3dU9VZUKU65tdhWeYaKePZYA 8Q+FEMbBBuJGSqEKmHHZijjV3kMvFrPqJn4TEXiktnyIDYcgCYGxiJOn//tZfrQ6qEsX5tM9yv FbAvLNTaNDcnTd7dXF9ujN+AqzZXF4CTSrFZ0lIff6vVE0uA8DbIDzoYWADagmJV6j/ORgwmt/ x4k= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Mar 2023 00:02:58 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pk95F5Qcwz1RtVt for ; Sat, 25 Mar 2023 00:02:57 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1679727777; x=1682319778; bh=nNNBPPwx3BeLf51ftF KDBjdeNrqS7hVotbLqERxh9VU=; b=XWwpfcbUHnLI5c5fimTdv/CJvgvE5uUsEr InGAa4He1kowskrbL3glrKgS5eAZ/S+nU9HjH6Zx8vfsDtKageWnOmbivT8+JdBI p5zreJv64LfW1fkLgc8/3aZFAZzEr5997Dt68HeF8v6H6JSL1YdmDA7Nbap169Ni pmF/3ylcdwC+nirfaAZJjBVaoiANScBIZfkcseXBvPjHOwNv8wcIghcf34OoHYxD mADghavU+nWnjv5DBGWF+qMEBDbtli/jr/6H60hzOKTaQWgmSMo7DGTXD2FQ6bsO h0M4+Km9vnh5fvwQ8nTHFO/A+0oh5L5AgfOC3y3AC8ZVcow7I0yA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id o7Leb_j5UwnC for ; Sat, 25 Mar 2023 00:02:57 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pk95C5gZrz1RtVn; Sat, 25 Mar 2023 00:02:55 -0700 (PDT) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v3 15/16] misc: pci_endpoint_test: Do not write status in IRQ handler Date: Sat, 25 Mar 2023 16:02:25 +0900 Message-Id: <20230325070226.511323-16-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> References: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org pci_endpoint_test_irqhandler() always rewrites the status register when an IRQ is raised, either as-is if STATUS_IRQ_RAISED is not set, or with STATUS_IRQ_RAISED cleared if that flag is set. The first case creates a race window with the endpoint side, meaning that the host side test driver may end up reading what it just wrote, thus loosing the real status as set by the endpoint side before raising the next interrupt. This can prevent detecting that the STATUS_IRQ_RAISED flag was set by the endpoint. Remove this race window by not clearing the STATUS_IRQ_RAISED status flag and not rewriting that register for every IRQ received. Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/misc/pci_endpoint_test.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 24efe3b88a1f..afd2577261f8 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -159,10 +159,7 @@ static irqreturn_t pci_endpoint_test_irqhandler(int irq, void *dev_id) if (reg & STATUS_IRQ_RAISED) { test->last_irq = irq; complete(&test->irq_raised); - reg &= ~STATUS_IRQ_RAISED; } - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_STATUS, - reg); return IRQ_HANDLED; } From patchwork Sat Mar 25 07:02:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13187652 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43270C6FD1C for ; Sat, 25 Mar 2023 07:03:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231959AbjCYHDI (ORCPT ); Sat, 25 Mar 2023 03:03:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231963AbjCYHDH (ORCPT ); Sat, 25 Mar 2023 03:03:07 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FB3AE071 for ; Sat, 25 Mar 2023 00:03:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1679727782; x=1711263782; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p+MxxNmS9DVwNUcLA55VvIMV4ImTHL2q/nFJco681WM=; b=VWl8kGbiDFRxXf0sDaHEstrDPpQY4yf5Qd9vYgL3EfM/mINilMFe1/j+ Ak/rFlUUxNNzFnil+2sRB4OSmVofORyR6w9zUMqnbuxOl4Kj5gkYMeybC u3/qIK57kaL0cruOuT1gZB7k7wCKyqn6SEgazj6TkPk+Sm5FAIqB/zj0Z bEU4fjTQ/CiQcIDnWwcij4zTAM5X07Ol+smlMpCW8UlwTH5BtFWBlvdt+ D6wyINVca2rfzXm7ASsIJZLdTRqESbsw2Oojqy7A4WevpARlKKEXW8czu 5KvMNPU7n3LQ6jA5jdtBKFrvfaYZHXerYyI7uLqVOEwz8NRbygRJqRoJc A==; X-IronPort-AV: E=Sophos;i="5.98,289,1673884800"; d="scan'208";a="224756931" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Mar 2023 15:02:59 +0800 IronPort-SDR: HvLVtuQ2GuoomnmtmE/gEGpf87Q02v548I6E5nRB0lzqIQGmbcqr8y9nrMNb2wHJAIMjwqTQSn lmbn3GZxauMPsuel/j/9HDSgO3jwexDX63Z1i9q6i2agfH8Jmj0e+0DXy8b5nR7+HtWv2sr9BF PN84vMn2DIydwJYMpHPLZx8ZInAvW3rxAkd6K6RzU9R3q2GuHN8WEPl+jeKZLMNFer4psH39u9 A9e8Nyy8GJGblJ0BQVvI79Z34jHJkb8L4n2WWKRp81FS2d7SsZzfu3uxwCAmz0fhi9uk0scVXk NP8= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Mar 2023 23:19:14 -0700 IronPort-SDR: vuG0wFlbc5jJK/xT3HAm1SyFBDC9XttmtDyhl3n0Dfi5W/dS/79JpWWBPwMJNvE8UZFhXzJ967 GwEyHBclQYIaK10fFy2djj3R6tPp6jP5CAUufB93P09FRGo9xaZ9sx2nv/R++K0NmwRIlfctaK v5norezaqbW+3VuS6czkIrNOiyD5GwzQCf0Iiw2Kl5/ZiIW0pvADfYcx/ABz/NfP44Q884rZIo B7HDslsxiZclfxAJHvCxxDD2FWLfBspaRsUQFtTbiOnH7EPybfHZTVG3A9AXN+o4ZGIXVCgOiO c+o= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Mar 2023 00:03:00 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pk95H3yQsz1RtVw for ; Sat, 25 Mar 2023 00:02:59 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1679727778; x=1682319779; bh=p+MxxNmS9DVwNUcLA5 5VvIMV4ImTHL2q/nFJco681WM=; b=F7gOef9JVRsRe0kzwgoFYK3QAFQZSpvaV/ 1vkTlkWbmJvzkWvpF1Kh8yjEBbSM1FHeatjONlTLshkweIQ+/Sv8Fknzm18cO70M /9RZyTERvc0IobleB5GFquG9BNJqFM3iEq2HbNYm/4ytliF6CoW2tygVNpUvs7+4 Jwxf7jlNzLfykDMjkCB5MumHRVv7VRE+Xqu03FzutaVrt5xz0KCIO2+P2oRscUy7 SDpw3djl5pNo7Bz0nrckJwrL44CunqYqPBCG35l+vd5rwweL0Afe8WUrRdQvQWxJ Urd1n+Qme/f3HyFmkc94FGBY5itSQkJKIb1jw49ZGHc14kS167zw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id OFEOvCaWvJVB for ; Sat, 25 Mar 2023 00:02:58 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pk95F39cdz1RtVm; Sat, 25 Mar 2023 00:02:57 -0700 (PDT) From: Damien Le Moal To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Rick Wertenbroek , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v3 16/16] misc: pci_endpoint_test: Simplify pci_endpoint_test_msi_irq() Date: Sat, 25 Mar 2023 16:02:26 +0900 Message-Id: <20230325070226.511323-17-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> References: <20230325070226.511323-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Simplify the code of pci_endpoint_test_msi_irq() by correctly using booleans: remove the msix comparison to false as that variable is already a boolean, and directly return the result of the comparison of the raised interrupt number. Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/misc/pci_endpoint_test.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index afd2577261f8..ed4d0ef5e5c3 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -313,21 +313,17 @@ static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test, struct pci_dev *pdev = test->pdev; pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, - msix == false ? IRQ_TYPE_MSI : - IRQ_TYPE_MSIX); + msix ? IRQ_TYPE_MSIX : IRQ_TYPE_MSI); pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, msi_num); pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, - msix == false ? COMMAND_RAISE_MSI_IRQ : - COMMAND_RAISE_MSIX_IRQ); + msix ? COMMAND_RAISE_MSIX_IRQ : + COMMAND_RAISE_MSI_IRQ); val = wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); if (!val) return false; - if (pci_irq_vector(pdev, msi_num - 1) == test->last_irq) - return true; - - return false; + return pci_irq_vector(pdev, msi_num - 1) == test->last_irq; } static int pci_endpoint_test_validate_xfer_params(struct device *dev,