From patchwork Thu Mar 30 08:53:41 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: 13193675 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 D5979C6FD1D for ; Thu, 30 Mar 2023 08:54:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229624AbjC3IyH (ORCPT ); Thu, 30 Mar 2023 04:54:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjC3IyG (ORCPT ); Thu, 30 Mar 2023 04:54:06 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63822420F for ; Thu, 30 Mar 2023 01:54:04 -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=1680166444; x=1711702444; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1e2OamP7r55F0zsilJj9y5bwk7gTaGYciJ+mu0rhE98=; b=f3HPv3ZBMCHQEAey753gUuu8HD3WX+ShHERtVxxIpAApEEoqJExkBkes hKsuIYPlJ3yck40i/zYVe/6A0FatGr1FY+nveFq6JO5xuLR30OAZ0iqj0 NV+QZ6EvYpoD2SmlHqzmf6PMRjyszQn3GbSg3rDhmLpeK/M/BK4eIXaSS j418v+ut6t3CuaNsWojwM27un5MplBxyjieqHYhDOZQyq37iExu1wAceE yGFKJlAzfLs/GVdFy54QKFqH99fAvdwN3kMe09WwluPVXQIoCuQTSLP9q Jrvw9VkzZYvnx3q0rovo0IrUTO9qqMTMyxBK9Dpz9NpZBEgamLTxcRTdb Q==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310414" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:04 +0800 IronPort-SDR: xlw6aBSkBeTOj7JVEXgPjVCQnm3tWytQ9HvaQ/HIdamlMjUGOTfLJX491/lDY/6kPLDVayUVGk TF6mcTakbn5Is8sHgCdfxD/9dP2zoGFP7jmy/lcaSQueqcpntf/WnBgj6UAkI+ob1AIj5uIEC+ jK+c81yIQkf6jXBXtgj1cfgd40D3oJru1JSj+fTt6GOaecE5x8U5aP4iAPJeB2gqGHh9lwi6I0 Cb+f0q9DtxvHbEbBv5QbOpYbj6XRCMjY1wYUp2QHCdgbKA5lGUKKBa0Y4vUJlGrULhrAh1xmMf RGc= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:12 -0700 IronPort-SDR: lk00E7XpHTEoM/Ug9xADv8twSN1gy7oq8lj6PlI4NoaHuFmOnfv7iF7iUIsmzU3TuptW8opCqo 8wY1O11ozdtZWM/yuGfxQUv2g6YD0KrA/cgxRBOjPZwp+J6k+sk2rHu/lkbZnCZp2G/hLYbDKj HlDq2fqoYazM6Z2Z38bgRsYt/zSHI3Uj//ol3/UvmIx3XnZOQdZCxl3KdLnSLeqBue6lefqacv ZckXJ8Vvvhh1Jtk/TZHl3G48/8oHdLBq/XL4eHieXOhTkcrYz6bXUxkRRNDSSbkicmf5imfOTP 7CE= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:04 -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 4PnHK76f4cz1RtW1 for ; Thu, 30 Mar 2023 01:54:03 -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=1680166442; x=1682758443; bh=1e2OamP7r55F0zsilJ j9y5bwk7gTaGYciJ+mu0rhE98=; b=I/65rKCFF7JmCH5fQVqKKJDTs0QgdmN3MM 76EHqhg+6er3lMKsFyHWWW+0xREBS30CK4OIdHsMxY73WQLG93CmYSRDzvyeLpZm oW3RIBNMccxxDLHgh5g5AjrqkULOVwa8Uu0A+JcgTV1y4Rqo/D6iyA5GRwL4qoPD n3e8zhNhoiX3qta1oTOY2N73qp7FKinJvcEwnAN+4bOC47djjVJzOb4aaAAFe4X5 zT4Bw4j06cFCTF44jMjYyHozE7xGamW1ILvR+BoPMsPKgJl/LjREHYyrEb/dQlOn gvRK/u5nOeX1zessYRq5fkNv0qCWQXSR+s8EytOdTafGM978pk9Q== 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 Gmc99x5-CdTJ for ; Thu, 30 Mar 2023 01:54:02 -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 4PnHK43rPbz1RtVn; Thu, 30 Mar 2023 01:54:00 -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 v4 01/17] PCI: endpoint: Automatically create a function specific attributes group Date: Thu, 30 Mar 2023 17:53:41 +0900 Message-Id: <20230330085357.2653599-2-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-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 Reviewed-by: Manivannan Sadhasivam --- 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 Thu Mar 30 08:53:42 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: 13193676 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 0E0C0C761AF for ; Thu, 30 Mar 2023 08:54:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229635AbjC3IyI (ORCPT ); Thu, 30 Mar 2023 04:54:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229655AbjC3IyH (ORCPT ); Thu, 30 Mar 2023 04:54:07 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D741265AC for ; Thu, 30 Mar 2023 01:54:05 -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=1680166445; x=1711702445; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t8/FKltNGowk82a8oQeUA1AG8yskCDoRScDUWbaQaEo=; b=pWzN2hHy1YjBwBjAM8zH10dOnvEbnD790FbtpQJ5dLJplUxBrlC6kinv YUsaRV01Sd+exQZLK31IZGYmMBN12FXKUZrN4KfE0NIWhtbACt6qQvKNJ o8Rhi3BFlp6jsE3m4jlzHXolK8Kr1ZabbD8dVzqRQFDbwu8kX1DJ/gARE pT29ESJHzvZVT/iDBDVVBFdzCED4vhDr68CAH0D+qqyCPpzvLCxXRJFq7 n5BlU6hAX+yKT7dP5I1qcuoLEOWhqfeoPOaQhb8vVYbwWn3Y76/0YVzrC 9oMq2KbMZ/UW7Q5uATRiKzrmxtohUTlxojyWZCPZpd/VaBfSQGhzeUoVu g==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310417" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:05 +0800 IronPort-SDR: NGwivpLgyiolLa2GuIH7p69skUQBTJVxTvelanxukG9hnXA/AgTTolMa91H38jPP1U9AUwGtRb NvO1DAXmox0vKv+b7l0kgSLOB+XdFL9ZfM0hwcyUEasvm1n3z6rs7Woov9x/HJ+JSISCQrlEcg 7MmVooeLAzbNrwfV1jSORkJn+FoH1TPMjyQ9JffVotBUUJYO7ViZo9+PmSZAL38GX4xZa6Otp6 xwyvCiWAufDnxiqwAuuzDpBuKcrjpPP3nnHiW6ZlQmMmr1jlTZ017EVzR3My7S5wBRHfM9UOSb 2QI= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:13 -0700 IronPort-SDR: YO8ts3LNpVZRMrn+pqoqECl5lWsiCRVbQ5SSbFISiJh9adsJ1ZuknCZXF+qODFGcIPr0f27FAl BkIYa7VGfUZRpRiagxGAjlQf8y84KEFhYIkhfnRqv7jd1fGHIf02HNpDxbSUQGmRBCWFD17XIc 5xYs5W4HOWDF6FChkSlKO0iBrAXoLl0Azg+Qh/rmWIGOvo/lRebx8cXyAP52MgWkQaYF9adG16 fGFd/SpdfeBWts7PiJbHKUZVqkqhwB+lhYyluw5GgBTjvpJfqgmdlXn/sOB/b2Mvzw8DEt9Xpi exo= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:05 -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 4PnHK90Gnlz1RtVq for ; Thu, 30 Mar 2023 01:54:05 -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=1680166444; x=1682758445; bh=t8/FKltNGowk82a8oQ eUA1AG8yskCDoRScDUWbaQaEo=; b=MRJfVo4vQsSE2YLem8E5k1RL/TBwCjOkAX OCdIMbuay9mt7rPW525Rhqn6B/AWLIpM/9EojxhGr4JwzwyN8AwcvisUWdTrdBoW hK++7J/FA3ryahAuzlpQIz4EyK5dt7wRXIESvYUVeOEe4vZM0OZWW6LNNuFOR3m7 qjH75zonjgF6xz4ow3hpwWT6vrBHTjQMorsaoDOMYDUdVcRh5FkpaLCTHUAdAddw DMupUd3Sj0zjO54DL4esJPcgwZqRVAQus+DsKPWPbl08DA9tcr1P1o6ZfWnZBiLZ 59SwQibNsdtNY9FCYggSe7ZDRYKEDAejxineZYsJc/9/cynjzjaw== 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 frXFfXjLAx7B for ; Thu, 30 Mar 2023 01:54:04 -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 4PnHK62hRFz1RtVm; Thu, 30 Mar 2023 01:54:02 -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 v4 02/17] PCI: endpoint: Move pci_epf_type_add_cfs() code Date: Thu, 30 Mar 2023 17:53:42 +0900 Message-Id: <20230330085357.2653599-3-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-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 Thu Mar 30 08:53:43 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: 13193677 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 35D11C77B62 for ; Thu, 30 Mar 2023 08:54:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229683AbjC3IyJ (ORCPT ); Thu, 30 Mar 2023 04:54:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjC3IyH (ORCPT ); Thu, 30 Mar 2023 04:54:07 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CC02420F for ; Thu, 30 Mar 2023 01:54:07 -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=1680166447; x=1711702447; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mBNv4vFEtRrRogU1bpDNqFs895hGS3croCKNhICIOZA=; b=aqcWXpNPFU1CVH565NxKmR4nHmZwHrIYQ4jYi8QwAX/ZlGm9m+tHsfHg dH90wlhf+9/e22AnKjEeDKHYlcTVv9VnLq+kSOsRHwTKwgd4G2UrfwP4Y F5xAji+71NI1tXPkvPMdjXoWOy9fMTZ8FH+QbYuVjnBzM5OuFd/ZImNuD QGbNg5GLy5Dvf4wdViYVFASC7ZYe4/Wa8HnxGz4XH4txapc84MXCoX0Qt Cdbk68BkukKN8mWlMGc8r0kKar6lBM5zLq8lAn6ZCMMeZOtnpiiJSjBYG 9++0QE4Kx1c9N4GM3tr3u1QwUFGk6xn5Y4jy9maN1ypSweBURJ0FrU5aX A==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310424" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:06 +0800 IronPort-SDR: ti5aybD4mnmPQHgLoo5VORg71ipRDFl2/ec+kgylXz+h4EVuGhIROXg998I007bb9FEuvWL/t9 RR0jMtQ2B9ylLENFKCWIL0arsK9KQ41oUxXdWHkk/SdBskOuEo7FKYyflwvYorDHSrJGLIk7fQ XiKzERvthDNoCx0j+0iPSkJVUaa0D2UOcGwsmISI9M5yl/Ld3Z8EKFzJgdSWjBLjYAVKjrvDPY Rd/zGLX+bh/spNdkS/y/5XIab9c79iHHBoTYkEVJOLfFi81OguM/CVUycHkjRbqVqBO0q8WBXQ /ic= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:15 -0700 IronPort-SDR: JFP2elDmSsahMtTLJxXowoeZJrsmlFbKtb3vke0GuI1h6tDkxW27v5MKeqTBXwvzs3HY3bQT6w VTYwVNeE42E1kHhNCcqkmTD8xSKLxodsu67ggB2E93pSURCo8lRwMEOlsGcxrqBxtryW/k5gUM COSSjmdMEn3VZ1qHWs6h6cj/shvK9nZEJi0mHxu2Iirfzss/YTwhXCedl/MnoIoOEa3s6FcyP4 gFeRl1j/U5VdjlEag0Sp+x0dKYo30WVfMP6kotaucWpQhE7HYU+OCmJLwcmbXGSgDFoL3eJxq6 jd8= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:07 -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 4PnHKB4Jvrz1RtVv for ; Thu, 30 Mar 2023 01:54:06 -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=1680166446; x=1682758447; bh=mBNv4vFEtRrRogU1bp DNqFs895hGS3croCKNhICIOZA=; b=Ud1bf1coUzdxUD2gsW0OeI0axQETcidBSB jmsrnMoxm993/OIhJvo8O+1ByML8Lyj7lwGtlqMkeAb6UQvz7+zXrIjG2dBsYY1M LTCSp/vicO8m7X4cnR1mtmNGVrmikhOwLcY8zrsVHYNepRoL1YNos6fT3P0Bbabm NP+bUr52qNXmxcibwLWZtq1wMbqspMSkVC9OPgvn0CGTtZMKjnPWgHPoyU6oNiTB xXfYckRhlzUficZt2Eo4JiWSd2bqsSN8mv1ySR7U/sxzDr3bwu7Ui/C5whdPa/q2 ccPyuBE2Z8gfAE/MTIDqRVVYNQOuRbUVhKGS8ixNva2JvoNvib7w== 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 NrxqscnpOzaD for ; Thu, 30 Mar 2023 01:54:06 -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 4PnHK83p79z1RtVn; Thu, 30 Mar 2023 01:54:04 -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 v4 03/17] PCI: epf-test: Fix DMA transfer completion initialization Date: Thu, 30 Mar 2023 17:53:43 +0900 Message-Id: <20230330085357.2653599-4-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-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 Thu Mar 30 08:53:44 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: 13193678 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 9B200C761AF for ; Thu, 30 Mar 2023 08:54:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229655AbjC3IyM (ORCPT ); Thu, 30 Mar 2023 04:54:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjC3IyK (ORCPT ); Thu, 30 Mar 2023 04:54:10 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 979056A6A for ; Thu, 30 Mar 2023 01:54:09 -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=1680166449; x=1711702449; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+HydAFEgNOgg0eVz7b8c5RJLJ0jDAA9i/cU2toh3C2E=; b=Jm/Gb74e1W+Y0unq3UGB3mCE/XUWIyVJqHFE3WbJmUGQXMH5iAOmrlYx xJ4T1VXLlaozENMzN7v9QpO+j3IMO3WKTro9Uf61LeaXQYnOT/pl5euim v0hqcNyvI8oIn29LtuzbGKLw/+Dra9v9+mxEqX8pFkbyIdHvuRl+z4NfV K5l9CjCKkHb2CMuSijMkXr9CMBYLWQa2bIrJq062NAgc9oaSg8e9dWkXZ U8BTedrpGKhPi5cbe6c1e5uoNIOGCI8dAXRVzRxcrLS+B1pSaAWV5JfIU vcXoLOAHZ6ARQtVYgY4XD3zO7/7ZStrnlNuG6bNufGri0YmUxs7K3Kc7v g==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310432" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:08 +0800 IronPort-SDR: KdBkAYwfq4WSYrVA4pEALcDQXOTKbV3I6dhksSuaQjcQHPngEsVB0l9w/CXeZWZvUgqWm4KUJy IYe6rhvBpDTJ0uB0dtAfRW6mP6GKpOqgUWxnBTMPNSNWL68cXBah8KZwhxSuoekycJUoGSyxaM tfmfT+18fbhytZc8w1nnrhte6d19WXmGf2D5OFCqd6BxVc7b17hdBOKwx8PuCz9yaVWRf2frY9 PnKBx72GkuuIBmyxgI++xzD1AW3Yv20PQfE3Vcmrp6sgQL3hT9xlFyxVNXFjfBdamq6VkOJefM JNs= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:17 -0700 IronPort-SDR: Azr5VUi8ZrxLyUsyuSG0aCSo55NsPBnFpLlUIQdCpFytHfWC0TsSOP5fT2tYdxhhoqZip17P6/ pRJZKXjcttFu70m+uUfuWa/AcAeGmC0fnh5zRIeafas98ONqhsKZzoKWZNh7BcoFXNBKRHteQ1 CoRVEeQ5hgWvyriotQl3xXwiNU0EUCbSZu/D8f4t2POhE1ci9AQ5xPYzb65ypilNZftGo8Pr7w O530UtoTa0IE8ILEPSpiWbHShBrtILrwf6wJeeqOg0Rhn2Ok2T0NyF6hDF4cLptaKQKSDYnFXY oew= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:09 -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 4PnHKD3q6tz1RtVp for ; Thu, 30 Mar 2023 01:54:08 -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=1680166447; x=1682758448; bh=+HydAFEgNOgg0eVz7b 8c5RJLJ0jDAA9i/cU2toh3C2E=; b=qJqb4vinKufLfO70wsGT7rPSuFVTempvQz iXZwZJ0rOLmR33WdSt+JE6W2gOdmsz0zoMpTkjAg0krspVol3gOAasXuI+5G//Gy z2q4/zrAd6dEeKg7jjgcL/dNdSvmCciHqPf5xcb2FqK2yMncRqgWx4tC3QBbXg57 138zSA+71C6JcC9lgdZsJoxEaoxTG/CmeO8VKQ/UHE1sE2I4VZ2MGV+OIUO1PIW1 a/WQeTiRojcVo/kHNAlbuXlxXi362tfHFNvHP5OjuyWGG7Fkzd9BVfSUlkpfETCu Uk75XASHuk6nGrDhm9brUDdtZtwHPbVK8GG9VLoK6a97qkSmIavQ== 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 xFAIRifsGjmD for ; Thu, 30 Mar 2023 01:54:07 -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 4PnHKB2yhpz1RtVm; Thu, 30 Mar 2023 01:54:06 -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 v4 04/17] PCI: epf-test: Fix DMA transfer completion detection Date: Thu, 30 Mar 2023 17:53:44 +0900 Message-Id: <20230330085357.2653599-5-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-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 Reviewed-by: Manivannan Sadhasivam --- 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 Thu Mar 30 08:53:45 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: 13193679 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 BCA71C6FD1D for ; Thu, 30 Mar 2023 08:54:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229436AbjC3IyN (ORCPT ); Thu, 30 Mar 2023 04:54:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229792AbjC3IyL (ORCPT ); Thu, 30 Mar 2023 04:54:11 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A58817AAB for ; Thu, 30 Mar 2023 01:54:10 -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=1680166450; x=1711702450; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s337vsR4bX90nEJfYlGg1DUOEOdyobGliyQs10wRS+U=; b=SQhWO00x2VhDVFeplirBcTUyQBITiehvwvXsNvX9t0rq5OR+r1lDfnYI QU/0OOwEbuD8FrjZy3PPryGBQ+p+mNsy9eRLHlXinsGfZW1cz/Ho/nW2w DQd/BN03elOMT3pXW7zG4IQZUkWgsrqv7JisTdg2d0zUH7/wN98XbPtrA PEeR6TpDA0OuBQVp6ROrjvSwD2OEjT2hPAIPRphgnsRW1NBk0kO9vvEI7 Nvzi+E2/Y7lE6xfLjZ6DoHDp9x7Bg4AXPG+CDhyRGs7b7JWHnXnd/kdGn qFrYnc4SJg0J2Bpz9Lbxmzwlp0543xXzyA2pEUZOMDWx6TS1ZSHGV2pUK A==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310440" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:10 +0800 IronPort-SDR: TZWLR2PfjoGZTub6sHvPSgO1JoUVVmsYqPb+lCoIgEk8x0t3pX2qqKsSRhFWTVoNYO1X72nLhp q2tVQm7TK6Dlil2kzjvCHvqO9bq8h8vYC9wyzNif1/zpwr/88Rp/XXzZQR3aDGGvOUHu6528Dv 0sOXPsy8noKSI3M5drjYuL/lMnr9uzzOYLnJkvWtSqU7FfSFnDuECe4qqJgvnSKH0Pn6lo8A0a jcKmVt+8UlEOpQJ1g7cxZfSeyjhpXQXoe8Djp+Ae4lcCJAhhytP1m/97oOkD09+PB/s+Z8IM4d dKU= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:18 -0700 IronPort-SDR: Cgr8/3QmxSzjw0ZfDoLfdoFnWvRIiGUItyuLjgqSDTKFfg07cV4b7Wq0oO0jsWHKLbjYQ6GZ30 viWnYNDy7SGOFK+ra77Or2KQeHuMUSFQS+K75IZ1DRlxnwAchv/RcaaL3B3umAcGWMKwig7ORb 4hkMT3FcnFTeqG6ZDENMk5UOJGGwvjYL7IV1qKQD2Rckja0aA2lR0sRrkQH0F8bZYSZlLwFzQW 0lYASok3oN5Q6SYo2N/fLmTH65U/FOGbDwwWwwlSlw1Azf2Coba3/SHYerZYKoYWue6ld2EaQf 9Io= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:10 -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 4PnHKG0mzrz1RtVx for ; Thu, 30 Mar 2023 01:54:10 -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=1680166449; x=1682758450; bh=s337vsR4bX90nEJfYl Gg1DUOEOdyobGliyQs10wRS+U=; b=lGqTFYFaA5yaIOCmLP7bJcrlZW9N16FdXb fhgJSX23Ka7cvusJ1LmUqrhgJzG4V9Wqskrx5hDNnxfZhr4gxcfYk2tu2rJOYrFC bd97Mr7xfHFY2+BdrgdnRYyxGQd1XcL1m21GPUy5W57/WYx9C5GHs2bhTxPUI+Md L45pL6RloBXCWCleY/MbRNJdb5m0lZVkbIpNT/ib4hDmQqorRbiZuoffIO+MRmSu TGptQ6vXmQn31NkuNX59ySh0HkMp1ia460TQWFGp+6IyYF8fEBawS0DcHh26ZZop R7C9SX21dW6ZEhQaJwJxzVKorgL/Rmg2Mqsh9dhL6d6fHU4lGeNA== 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 sMvp8qFiqRqk for ; Thu, 30 Mar 2023 01:54:09 -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 4PnHKD0vFfz1RtVn; Thu, 30 Mar 2023 01:54:07 -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 v4 05/17] PCI: epf-test: Use dmaengine_submit() to initiate DMA transfer Date: Thu, 30 Mar 2023 17:53:45 +0900 Message-Id: <20230330085357.2653599-6-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-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 Thu Mar 30 08:53:46 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: 13193680 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 79F86C77B62 for ; Thu, 30 Mar 2023 08:54:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229795AbjC3IyO (ORCPT ); Thu, 30 Mar 2023 04:54:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229710AbjC3IyN (ORCPT ); Thu, 30 Mar 2023 04:54:13 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EC8F3AA5 for ; Thu, 30 Mar 2023 01:54:12 -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=1680166452; x=1711702452; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CbKzr7JuTqmzPKIp5lOMS5tv+EX8Bq8JL59U7x90uT8=; b=EzwTcdmIMvSw04XWFL0ZiJ95g2ahiEBTA0o/31RQeJvdc3cyP+LcAT3k 5OVUeypLkAS3OPdTJiKmSgHlyUtUR3uq6eQwbPZxTr8JLVoj7c4U5qmFd srqQ6W72/QLtKhDpfEFCJumh7ikebZu1JHBurxcoMTEFwR+OER5BKHTrY /LsQr1j9yxt2dRs/AYXKqh9svRy2Bh4XP+KNSRiQU8k/oGqFmC/LyOgpc yhN2p5H/PUW1bMjRk96ZaKOSUK3ovzm0h+QSarUt7hABOQrDImKn58n+i dAl8ioEUJflJKJT7m+Bsa+i0tclYsxwcxNBJRIKidxHAfXIcZVhHz72Xo Q==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310446" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:12 +0800 IronPort-SDR: 0RnKVsmd4jvlRtpW/AIj7F8/kAAxKxrNppRWtJOMXSPqWAk5BPwGOFlfJgDVtNld0EbBm6P+xw 9fgzyVlhBwYkdz87vdB2puQFY58YZi3BKUC6V+jB/BuhGaVcHeH3LBJVjI7tmS4lr9jc8wZCmZ sCTzjLX9ABvKOfdJpaYCn77fFjGcM0vAaAJbCEQH8ZsyodlKW7x5MK7svRNz1jS2K6HOWI5Jqv EvfTOpkmtJl+B/wIiHiM+ZKEk7G+RdHMjTeNy/eNymTai8b/+lQDJrUyemeZEcrxCcijC5DgE3 CVM= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:20 -0700 IronPort-SDR: v528uEtrfgNrEJTWtksfVfRilCrr/FMiNgJx1/xzttqA61T3pbEHlawStwwqaJhcVOK3v8TfKu SD7rtMmBiyhzUlmAYw9OGjw6llihnP0P8NYiROqehzsqX+qiVivi+3JHAfN2xbWzsFchW1qbTv rbM2WIFwXfcDsvKG8w8nNC9UAwXbPGtg8PNOalJU45BBAKSqkIsxNpSuIt2V4nxxLJuDItojWu mREsbh9jil1RdWcnUXrbASB4q/kobv+zzEnq0qjOqgKbsq2ZUXWGINtFdaaHuw9GS6cI5IY4EJ I3Q= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:12 -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 4PnHKH6jp1z1RtVp for ; Thu, 30 Mar 2023 01:54:11 -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=1680166451; x=1682758452; bh=CbKzr7JuTqmzPKIp5l OMS5tv+EX8Bq8JL59U7x90uT8=; b=OoJ3huLvL53Y6BNiyZHWOH0zui1C1JYHYg jcA/pBY1S1/W2ZPoZavjOSMTsqy7PZX2Jgd4CSxkzuM+dnL6TbRnuYJLQ2li0/0p Fv3DS+dzrF1HDGmPzYbykFqWF+mP01YS2HNZ3LRnJZD9c6G9DtkfH3Nc+e938uHr 4E4UFTQeCumkDEcCmc7wn2FTiRUnhjdU9OQ43Ylw+llKW6aIw6nJ//rt6ZR0UiY/ 0fdkaDu5vVt1UBCmUsx3t+BrvDVDHZN0d7yycN4KzSi8H1hamutRl1OEwroLErZ4 2eMFRvb/ocQ2X6whNm7I9tKvESkGdpzb1GynKPEoJnuZMKOx9HGA== 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 c79uT0MqLC2V for ; Thu, 30 Mar 2023 01:54:11 -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 4PnHKF5yPTz1RtVm; Thu, 30 Mar 2023 01:54:09 -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 v4 06/17] PCI: epf-test: Simplify read/write/copy test functions Date: Thu, 30 Mar 2023 17:53:46 +0900 Message-Id: <20230330085357.2653599-7-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-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 Thu Mar 30 08:53:47 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: 13193681 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 45A42C761AF for ; Thu, 30 Mar 2023 08:54:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229710AbjC3IyQ (ORCPT ); Thu, 30 Mar 2023 04:54:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229705AbjC3IyP (ORCPT ); Thu, 30 Mar 2023 04:54:15 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21FC63AA5 for ; Thu, 30 Mar 2023 01:54:14 -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=1680166454; x=1711702454; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=J/a1XPwL+xSkbmNIxhIJYkrLti8dXBeJ4FmvtofrtKI=; b=bNcAsa/3g6AXKz/Gpk3JYZLCKiw+vWbLokFsy4mNrakMDk2mJ66u2N4U JwP/YMtomqtJcD/rlhcQA7xTAcbaJo8HOQ3xZbqwGamWyCsLrKhkwzSoL 2wgPSfETC/zVFUu8sCFKL2F3uDk1Pz4euxkGvyo7QfHGpWBfgHBqL+q5G +Oy46dPOpfUppZtMRccO1GZTJjr92YW1SodzbeTV1gq8LZu+dWy+yQ+X3 IJHD87ybRbGjCMObjlIEcwl5lEHDL5M+5ZZqcnwvCcboLR7HCFmpVuINd CUYAcRq+V0UwJfuYCDFLpMccNZWCCLk7LiBx0zkZnLHT3NW5fmSYYusoJ w==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310451" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:13 +0800 IronPort-SDR: b0dmW0FLt+vseg+fRo6IHeo1o3iQIlQKoncS/7rYWjTGcWDggYSIfv2w6z+/xY+R2rq6km2ZuD QMu92VrFuoKYyyoI3zlKaJYirL/EjWVWPj3wjM6IYej5wZ7nCfx5HCN0TRATmgzgFuttsh9XK8 70eyDVMFjz3v0Kzyo8kYdRe3s5Q/e4piZwX2jjOFI0AyNW3wA/kuXhXDyTOPUgp7YUt8sVaGiM IDPzR4gPcdO738xgoRkAEvJXHwmIPTSavLPhipbkp8+lF6ElspKrApQG53LJWPJ23tuZQgdd3T kA4= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:22 -0700 IronPort-SDR: xpQYWOxgu/Z+woLcOwONcDpAZYgdPX4WAw7a2VDOtpww5L555a6lKX/a5EFYWYQFpSvA7a5VBo JnRdp/1NyFztuLv8scD35w2fAx+xJzpV/oji+6pgmGe82w1qDtIwkxAvpxihx5nNz8A5Vbycg0 MeYiX+yKCyAGm1/RxkXha4QKir1tn2wPG5isgzmFe9dVZO9XG/khfoiYBqZwHfVEzurVNMj5PC ol5JAEku+jPrLsjUdcLK1bca1ZL9LRcw04zu2gyhXSuOpA1w762kGGBdQ8nrcL4n7UPNL1RWIS ne8= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:14 -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 4PnHKK5Wh8z1RtVx for ; Thu, 30 Mar 2023 01:54:13 -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=1680166453; x=1682758454; bh=J/a1XPwL+xSkbmNIxh IJYkrLti8dXBeJ4FmvtofrtKI=; b=ECIwQyBM3X5Euzy28NsaWD5jxwSozBDFtf UYHrLTbI9WOcg9EDo+zEzGfjVbaoJ+y1lU9jPyL/PcjgrXiqUhE++Ga4Onx9OKVb XF3lPdUVmCabrbQCivlGxfSOxB984ecbxvAsm5hRcmUbNnNnGf2danZF/GTw+MzM 1qEyTB9RHKpx0zwsAeQ9CYzaHhGP/qwh7tUSGsXqs2nB9/l4h/I9D+EFtEx7/zVe t9AL80XpTHgY1fRCbE+NSvycyB6IvNTa4tUr+jHbAhs21z+X/OGY5t6nuhLOTVvK HW+1qRr8OFvBhN1I2+HJixOUFol/M8bB2JK9AmpTwUZZVn9uBzEg== 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 3wdQtvFm7T4s for ; Thu, 30 Mar 2023 01:54:13 -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 4PnHKH366Cz1RtVn; Thu, 30 Mar 2023 01:54:11 -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 v4 07/17] PCI: epf-test: Simplify pci_epf_test_raise_irq() Date: Thu, 30 Mar 2023 17:53:47 +0900 Message-Id: <20230330085357.2653599-8-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-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 Thu Mar 30 08:53:48 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: 13193682 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 96A25C77B61 for ; Thu, 30 Mar 2023 08:54:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229869AbjC3IyT (ORCPT ); Thu, 30 Mar 2023 04:54:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229705AbjC3IyS (ORCPT ); Thu, 30 Mar 2023 04:54:18 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37B7C7683 for ; Thu, 30 Mar 2023 01:54:16 -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=1680166456; x=1711702456; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NO8Rhu//AxIrrspALxKn62RC+pXJTNz3Th/wi13bFi8=; b=Oue2dFy0LreUfwbl2hW+Qlhpe2SCo7MjQqjTqCNrzawI4AXIEItG9CIw RnqFkxNWVCpQlv1QJ+U7KSnQccYUOyNZwCWSG9XKOud4Ns5nX8EgNRBz2 ItAOGp6TgvHpj2dFfvdMxrXAw4mk4Wbek0CmXoC8fR/bGtGmHmxM64JiX CbCN9obU4gpAv2y8ZDfDsbtdFSvcc4Z6qFaePXQw8ygQKUYgjFponLYZY kDBhKdKw3pXkehydkkeiOviIqLRH+56JTPMR6Bh5d8KA6yqKEq4ye/gau 3cm/TTFGiMlz6gzvDeG6w59SzGqhyzCRw/GqC7dtlecAuuLIOjEq63AtJ g==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310458" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:15 +0800 IronPort-SDR: xGHI4jukKiyHsiNX8j7Y/USOCP6XmtrYxUVyu230VxDneJbs3kn1Kt+166BbpUgDSj4JNFh7e/ Sj2iR9+or08tnI0bTXHO3Bc+C6J1T0BaffVEpzC/0sQyGT6p2lBtAOV5iDOmx36hQ1DkpHMSew IdHajtABL0iWyV7gv5zcFhB+6vC977Y2lPg6VMuyIJG0i52fKt23N3yvUcIM0pZVNlKnNE3U5/ Z2njA026Fe5GZ25bRkBSbmLE0dDv48rLQjvntJ9sJ4SEXvqZRCreqOnFaYDqHBURpnKbT4gsT+ +Os= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:24 -0700 IronPort-SDR: EoRkssIR/DDkASiuZulXfN0BPaU1OPf3cW7DviN3EvTD71xWjJvDp7zD56NeH3ttYgrdcwOuX5 BZY9c2wsRnCq1+1LW4G3JqXnxO7zfcln3IsWPKi+YnGhx0RQKAfzcbm5fPyimzQ51BeawEFhAq WaPDmxcCC7TYQxt8TuBre3XKKxRXWcyN1FG2qVzTCaOaCJMqSup0oMj9/e4X5l0FPuJureLGeL 722v+btNLli79D9oaTF+oak/lWEYX5N2Z7FvdmwA/jrhM1hpNCsSHjpW0g384hIBc51O4S1XRW dYw= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:16 -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 4PnHKM5C33z1RtVw for ; Thu, 30 Mar 2023 01:54:15 -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=1680166454; x=1682758455; bh=NO8Rhu//AxIrrspALx Kn62RC+pXJTNz3Th/wi13bFi8=; b=MbCgBwh4lVlt0qktFIcbrGdwSoaUt3SYCM RZ1YohS2B0kqjA6uLAHX8wGERipY/dk8xIr1CKtyGKbMI/t1l7jnpdvvuSrrny+F Bs7HWvM3g6ADKTo2NuAbB5lyeow/9T72lYkmEE8aXRecVhcjySWOAxsIMLQxXZfE wC60Ee9N4a7nekalrgBMMeUv3hyhGW8pUFLerF6APdp08REWviw7NUanXXZ2nxs0 uB0KNmvGqAAbmtSIBklQhoX90s+kdeJA+ImPIzA/pt7QJoPthhWx/p9+RBdVxu0D U6uuAfejy18zNz1LE/WDo562kavf57VF/OIS5qlLiVI8k9x25MAQ== 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 fzxJsMXhkE-y for ; Thu, 30 Mar 2023 01:54:14 -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 4PnHKK2rgQz1RtVm; Thu, 30 Mar 2023 01:54:13 -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 v4 08/17] PCI: epf-test: Simplify IRQ test commands execution Date: Thu, 30 Mar 2023 17:53:48 +0900 Message-Id: <20230330085357.2653599-9-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-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 Thu Mar 30 08:53:49 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: 13193683 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 99D9DC761AF for ; Thu, 30 Mar 2023 08:54:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229950AbjC3IyZ (ORCPT ); Thu, 30 Mar 2023 04:54:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229961AbjC3IyV (ORCPT ); Thu, 30 Mar 2023 04:54:21 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35A326EA5 for ; Thu, 30 Mar 2023 01:54:18 -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=1680166458; x=1711702458; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hccwggJJwzfgdDztJNFo5zJ5OiRPzd+iDuSC1/Wq8lQ=; b=nxKex7RiAooyL2+gtNwCYChwZxbJe43W4LyEeE/aIZbjFQWflEyawZGv h+5GcbK3yYbB/6izZMpbkYxchW8Q7GnjTdFnojnxyi+aWtlIhicOqyag9 8xZqfCSL/awImhLSpcUjH8kO6vODGTFeg0F6ZjYAU50d07yrQiBAMMZ8I 3gUBcZDINtslbGiDbd/FJetbsTcbiQDFAHoBICTDlkfwg5yn8TkctM8ro SyFDOP/0mhWsUW61rO73YlyvgAleKU7sEYKlXUhv6yND9inF1U6t+RNnp SFHeIAt8vkm191uLQ7u2Jnw6+KA9vytLHGNWfX5+4MqtFGKPMNT65u8v8 g==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310467" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:18 +0800 IronPort-SDR: SGYQhnB58WdkGgvfzQfzCOm24sm5pZHGFyjKDawq4xNm4VSPC6Q5t3kXm7doEt9/9om3DdG4ux 6cLPEKOBqqIt0hwLfBZZxCumfJ0QvU2cVtUH9j26m3bYoY5fBqUdvsMHSGF1rcUpM0LhYxd2hR WcpFfAqhvy9wzZFWcMHBPPiwsBtxL3PSePQ7pU14Lnpym6qoJGpzQ7zUflRId23HhPma8LjMMF sqUsGVQO0As7/9QzK/mtYURdXq+s/45VYq28QT/MHE8Tpup1I3k//2TSv3jeFjaODsP6IwIQsK NyI= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:26 -0700 IronPort-SDR: pn3StfRpEzalnzx36M1t5Lgy42mgZxPjaGBcryp0eg9qYCwJmXfSrrWAg8OKBjyPHe5vshPQsD FU14Hbzcj3t2ll9oKg+4ZbIhag/U58U6YDFk0NEfvlIT+3vGeGm0a91AOaiK2kRz4BDsvHUjbl 4fOwa9F8pZRESieBmv5L5Cdbo48la/dhPbzHAUroli870AoUxv/QxJG2L55I4SDNS4PPGY4bds ZJYHKnnebvXaO9jiVNv9i36MgnTQHZVACBw+2yzI7MYIox5MBEoN7IilDN1jsQ6JFBynuYpIwg /ms= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:18 -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 4PnHKP62hwz1RtW1 for ; Thu, 30 Mar 2023 01:54:17 -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=1680166456; x=1682758457; bh=hccwggJJwzfgdDztJN Fo5zJ5OiRPzd+iDuSC1/Wq8lQ=; b=aPNl9TZPNnyqrAj12LVLli8oq5J15uw6Vy xbiI2sjRMx8vg8tWys1428UIG0P5GrhSUSAxP7uZIOuTbYLVyr/fxmwAEt07GjS5 NeoATS5YmFJB2rr202CNWj0wZKELUrj1/IzMphyGiNJmEIEfefDflU9Pj5M4of3S bCPPZHUcFV8zrYdh63NqeRUzTQFkbGUFdy+dVgim6vz9Rz4M/XIqTtxi5BE+sAFQ PAs8BbA12wUR6/EoeqRNq1lAEqQkZNtLpeHchHlLAL7b3hOizc4BPf0YNZEO1Tx9 qzp4yMAKXlXW37ck4ht28LYEx4gq0rEIiHqZ6tcgZ40SkDLW8afA== 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 ABqGDr16b0YR for ; Thu, 30 Mar 2023 01:54:16 -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 4PnHKM1jPHz1RtVn; Thu, 30 Mar 2023 01:54:14 -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 v4 09/17] PCI: epf-test: Improve handling of command and status registers Date: Thu, 30 Mar 2023 17:53:49 +0900 Message-Id: <20230330085357.2653599-10-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-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 Thu Mar 30 08:53:50 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: 13193684 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 7EF06C6FD1D for ; Thu, 30 Mar 2023 08:54:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229718AbjC3Iy0 (ORCPT ); Thu, 30 Mar 2023 04:54:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229904AbjC3IyY (ORCPT ); Thu, 30 Mar 2023 04:54:24 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66605420F for ; Thu, 30 Mar 2023 01:54:20 -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=1680166460; x=1711702460; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mxCZujNEUTbNED023BSGdq18vAZhegc8Tr7mjQSp0FE=; b=fz0D5LGC9e9PUIIFBVAn2lP1RzC6f7F7bvT1GlihiexghIneA/vib85G BnWB5Lx0PbqAVm4jnrwbTknQHmSyVQeS4SQbBnnlG36/TzpBbd1JbWtqU K7qvThOPEdeOZIlP/ape+Kr9Sgt/Zt6rWX2gzN2M4eNhBhZXRkdTMOAnk T/mvj+vmODHikjhkkNjeGVZqPkMWyMZWu2QQaplbURiOxhGE8588Z11qQ cUs74/jYK89nPMFRLHsevFuE6xl9T9JqFRTchpikOYXbWaM+MTAEOQLuG 6pFumgc5zAV2CxUxgROHrPRfRF6NaWbwk4i1KCpIBFVaBlQrmsGYgwDVG g==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310473" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:19 +0800 IronPort-SDR: 7eaByLetD4HQUrndY8gP/LFE8b1I1Y0uinWFdFOS/ZmOCc9QG757e5nbsmeS/VcVQGsgY3Cm5o OLMkJ5tamqLuSoDx5LsQAHRyPuJQ0k1DLIA+yU43gMPsOcq34N2qXd6rLSFQQ8SRgr2lrbhVv3 H9juJ7HIMbPR8pu/al5rn4VNflFR8eHXNKLHfX+Ws+RDEuXEUBrHh80okWom0rXqZy4wXuwKG6 CnbqhSfCQ2JHiLW8Lf5kSlTumvXRTKybfOIGOqWvkilVbSQ8ZhFyCjtet1sVh+TJCS6V3pvaMO ubA= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:28 -0700 IronPort-SDR: Rcr35KPj/y1OXHigoVKlAHAfJ5T2kHT/Cj4BfSsbX9nyr81AvEtId68pyaGWxJLyI/gJqWJR8g 7mQFbGx7xUnE6J4qVtozAxi9WHmepYJM4i0oe+uuzuLYYIi4AMzUuVkWc72PjqK2NiNN3KmEfz vDtm54UWB9fwc06K3LxQZfCiblJxKgkdYVFsdSMKttfOy6Kj7XAmEs9aLb0qkCnsBUXZXlcY20 BZnFE1DpyjC2TgXeAbDAUtYQJVKJ5YBlQGz4w+9HeGtLZ4UeY7rNjkDadjAcklBOne+k5vjxhb MFY= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:20 -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 4PnHKR3q8Wz1RtVy for ; Thu, 30 Mar 2023 01:54:19 -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=1680166458; x=1682758459; bh=mxCZujNEUTbNED023B SGdq18vAZhegc8Tr7mjQSp0FE=; b=fHhJ7yGQToP2N4LbTSpr5wnoxYS4GSfFU5 /VCBi6Q+kC9+CYm54NVyDfEMp8OPE5Yb+/mPmitlLoSrDm9K0FmGOK776RGXIG87 QbHEfR5xvBt0m2pDntbUDTYPbqKVZ5vJCivRoxHfEm48Wxel3CYMvS7jM5h/jgEA dvgCj5L6Lx0yNNulU09e+61QtRQklkTeJ0nSLyob7pHwZwR2IOPuJkQmIAO3072+ gakipZdf6f49tnCpsbRGub5SXNzEW6j6tiBPsmtQJImF0yUlDghAQPzSel+/gK2F xptWiY+sPko5Ls6yumjtcF6PloY/wpm1yTpexEeStve5dzhMAZkA== 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 RQQfRiQlT-Xc for ; Thu, 30 Mar 2023 01:54:18 -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 4PnHKP22P8z1RtVp; Thu, 30 Mar 2023 01:54:17 -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 v4 10/17] PCI: epf-test: Cleanup pci_epf_test_cmd_handler() Date: Thu, 30 Mar 2023 17:53:50 +0900 Message-Id: <20230330085357.2653599-11-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-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 Thu Mar 30 08:53:51 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: 13193685 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 1276CC761AF for ; Thu, 30 Mar 2023 08:54:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229792AbjC3Iyf (ORCPT ); Thu, 30 Mar 2023 04:54:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbjC3Iy2 (ORCPT ); Thu, 30 Mar 2023 04:54:28 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 067817DA1 for ; Thu, 30 Mar 2023 01:54:21 -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=1680166461; x=1711702461; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bjOf5YrytMiY/Eh6f8Y0+JmyxlGKJ3hBvshVZDfAR4M=; b=g2RkTvkhSdwxftMOudxpDFnhBTF/nvNryeX36h8fZLfNc3/bIPfKi7Y0 Z3A5UD8vGn7zqhPFHt0YtNpajeMv8n6N4D4awckeXnnqXvtXxxvJp+/xH iR7ZAMJHYP7hfCS4becyrp6PJLZU6Kqrouz2NhYtYbvRmVl6Y+H8kGy+f nQ7Sy4si/JsC4KHRJVubzEjDgxSGJWRBSM/3ban+FFSwryPz/SyYBfORj 1IT14L5cdpDRHFrzPoCpq9dduLGg6Rh32JaQQk0QRIvNhoJHR6CxmrTHg 86WGK5iFQAdZ1oI8bHtNl4pJy4AH/LaGc8uNcrYvKgNkBYlTxpNmSfYE6 Q==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310475" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:21 +0800 IronPort-SDR: dDhCxCwOeQjACfQ9HWPKzZANM8RQpeLm2jMZZWMTX/3ZakTot3My3adEqGOh9ALz/c60BqQpg0 tNaRoCpm1rzU5ngEvPzG2B6ezMXEfoHCJT8mqdvhTJWaBgWNwcd08n1/ieAlLI8wOd8uP1D0Pu XL4UvI5jwKhE4mnmLsqLAfk04GXzcZZbpgXYRA+0UnszYaeTWOLRGAtbP+qRDbIVXSImp9kI1r T5Oruo8OVQo+9BxduBzpIj0cV2z5DLZlFuX7DaktoYnid8E2g+cRU46ZtQCqQjg6gNU734iOAK Rqg= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:30 -0700 IronPort-SDR: BHUMTmeizuKVWUug5ZIWU/TEa9Sp6pgtlr3EdCAZarDMVgxfb84a6TQfUnbiXekNwDRQfnKALo iKO71yI1m8umb/qEiAwk8Tx1/4F/bFO1TuheabN68Aw5eBvMwLvRNR8001piAavqrCtGDRCnDS bym09opPcHRQMwCjOkKkJkMUBdGov1nzNkLHvYUjoOd47UDP1Owe2U1e566IvfY5BFrI8MubcT iqsrKMjNs4qRedrEl2m7CkRVrv2C7ZKd+O3XWvf/97lQwJ4ywxXJwwuHvGYlZsM7UBRv0UkR+r nA8= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:22 -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 4PnHKT3bCBz1RtVt for ; Thu, 30 Mar 2023 01:54:21 -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=1680166460; x=1682758461; bh=bjOf5YrytMiY/Eh6f8 Y0+JmyxlGKJ3hBvshVZDfAR4M=; b=jBAlTyOqG8BDTKnctiknVZ4VW5uAW+rhx8 H3pl2RTc5rlCVUI0+NWN5PpvrmWe2D/kfjgOzqwhfspSZ4UxBYS8WXfYBCdLt+41 KN6EaOatqo8N9RhNiq5Z2G29T9dvkNWUvCyH5oZtQglkD88l7abCbSaWFlCBgmwr TYNwvwcm2sDa3xKH5rm6tQa2+T16pGsW1ueg2EB/JDxHg7UMLJR5SSx7IbNhKRde hBM6ZcecJ3h5ztSjSKQTjiZLTsjbCfw8jnPggbpOutPGQgGDeM3+7cN4mhaeOl+S 20plq4dkBkU7696gac2Vss8ZLnPa0Pnl9xcBTfoJZfyYWbAuqvRg== 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 zuP3RZehrw2d for ; Thu, 30 Mar 2023 01:54:20 -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 4PnHKR1BpWz1RtVm; Thu, 30 Mar 2023 01:54:18 -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 v4 11/17] PCI: epf-test: Cleanup request result handling Date: Thu, 30 Mar 2023 17:53:51 +0900 Message-Id: <20230330085357.2653599-12-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Each of the test functions pci_epf_test_write(), pci_epf_test_read() and pci_epf_test_copy() return an int result which is used by pci_epf_test_cmd_handler() to set a success or error bit in the request status. In the spirit of keeping the processing of each test case self-contained within its own test function, move the request status field update from pci_epf_test_cmd_handler() to each of these test functions and change these functions declaration to returning void. Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-test.c | 46 +++++++++---------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index c2a14f828bdf..35bdb03f6ee1 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -325,8 +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, - struct pci_epf_test_reg *reg) +static void pci_epf_test_copy(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) { int ret; bool use_dma; @@ -420,11 +420,14 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test, pci_epc_mem_free_addr(epc, src_phys_addr, src_addr, reg->size); err: - return ret; + if (!ret) + reg->status |= STATUS_COPY_SUCCESS; + else + reg->status |= STATUS_COPY_FAIL; } -static int pci_epf_test_read(struct pci_epf_test *epf_test, - struct pci_epf_test_reg *reg) +static void pci_epf_test_read(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) { int ret; void __iomem *src_addr; @@ -509,11 +512,14 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test, pci_epc_mem_free_addr(epc, phys_addr, src_addr, reg->size); err: - return ret; + if (!ret) + reg->status |= STATUS_READ_SUCCESS; + else + reg->status |= STATUS_READ_FAIL; } -static int pci_epf_test_write(struct pci_epf_test *epf_test, - struct pci_epf_test_reg *reg) +static void pci_epf_test_write(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) { int ret; void __iomem *dst_addr; @@ -604,7 +610,10 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test, pci_epc_mem_free_addr(epc, phys_addr, dst_addr, reg->size); err: - return ret; + if (!ret) + reg->status |= STATUS_WRITE_SUCCESS; + else + reg->status |= STATUS_WRITE_FAIL; } static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, @@ -655,7 +664,6 @@ 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; u32 command; struct pci_epf_test *epf_test = container_of(work, struct pci_epf_test, cmd_handler.work); @@ -683,27 +691,15 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) pci_epf_test_raise_irq(epf_test, reg); 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_write(epf_test, reg); pci_epf_test_raise_irq(epf_test, reg); 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_read(epf_test, reg); pci_epf_test_raise_irq(epf_test, reg); 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_copy(epf_test, reg); pci_epf_test_raise_irq(epf_test, reg); break; default: From patchwork Thu Mar 30 08:53:52 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: 13193686 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 481B2C6FD1D for ; Thu, 30 Mar 2023 08:54:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229833AbjC3Iyf (ORCPT ); Thu, 30 Mar 2023 04:54:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230159AbjC3Iyb (ORCPT ); Thu, 30 Mar 2023 04:54:31 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 050377EC3 for ; Thu, 30 Mar 2023 01:54:23 -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=1680166463; x=1711702463; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HpHoCX+FLiV3OKsXvxlbDREwVOxEqmIg95XgCiUrpLE=; b=QlTfhe2IILrJU8Xgam7IVORB5yIfGoNosydHKcjjzr2d+iZreRpPxqPl HO/HlqTY4A/lVBA0/3VpRXcFdEtGpHaCCEyJhc391xobwwSTt7YysHc3e eGw9zcoyb6O2NeAmEReQkupjtzcPq4IwgqAnBAyAa+Hre7mhHOZ3C18mf Cm3V/NybriJ9LNsXa4BDQ0yVvRkloqyv7ZCjQKntp45UCa3JJ5WKvfPP/ 6ARdjOshfIyegyPA1vThNl1WiklkQOb3CBLxKWA8dTx/lhuu4B5+wJHrK ZOoRB0xgKIG1BvH+67S/543kbpAUi8Qc/eC0OmS7jOrHSXd+/HF/T2oVU Q==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310481" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:23 +0800 IronPort-SDR: Pj5jWpkGIptI3aQ+Z+HNz1KphkPbtPKE1A8C5Y+cR4ihVXd9wNoKGYmowQpu5U5t9qO6ZGMv/d En8oGjrM86o6a3cJtUvQxa4xaKD/zr+NAlUxc1Bxd1ULKNDRbTpC2UIwK6JPdGK8jcJ0aNEa69 iNtTW3EZdDiouHU4Rvz3czYuA8PDWnk0B54nF0i3DW7OuTuduh33Kcy8PvyWvTv9HuYjdLSfFT UThzTwf8FbqNlzLNIjeS3bktRk/bnfh0GRJVRHKmM6jKaEVTUS16IE9f+Nw72feD6y6ECZflGP fpU= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:31 -0700 IronPort-SDR: w6t36u8LQITYBhlF8aH5V5JmC5zX32BsyYm2dEho1/MR4f16LX0pa1P3R2airc5JInHQKE3ukF n9dmkP8auxTDweRHbSB7MEKuOIgbxs2WwXEX6UnOHAHZhwvEYrEzeDE08e/WoVtb/vw7CtEGtR ldaPHWhY9ijKLePfLeVaPCV9W94IcFMUj5FjEsA+qjj2MqcvWrSEgDYwsbAvTpf3Dr3XED/c7x LwNId4vResShUbTm3A0N/mKC9msQfMfgBCtzftMiJPhVGYWtU8/MfhzoK5om6jLvjLEEGTA5Hu CIM= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:24 -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 4PnHKW2VZ0z1RtVx for ; Thu, 30 Mar 2023 01:54:23 -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=1680166462; x=1682758463; bh=HpHoCX+FLiV3OKsXvx lbDREwVOxEqmIg95XgCiUrpLE=; b=WIt0KMs3TjoW+iso1kJWYf1/n/cyuM7sCs e3+briDxf0dX3oTDTvSY+f4yrvCG4xLALbKxieqYNgXzl9jXbxBkFjYCbyyN/OcQ m6PyrAkA1UlwC0mS+xO56rIqjOBA+BRMKUmW9FN8YKBMeknws/0mzuxxwKXg1O84 NzC/uVJdKhGqAQ+U2yJlkFIkoFmqXsTpTBL5pXj0H228SykZLjGFuFKkHLgNW5gE rmutF96Khv63W9Guk6e5+grP8Xn5XSjfh5qs+qJc3nDQZEQuEFp6vq3rkTK29TyL WwnJO5qH+IuJRUv3f5/hLgybt1g2ep9K6ZWeuE6fbsjOBIuE2pOA== 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 vUKGSHLlv3Kk for ; Thu, 30 Mar 2023 01:54:22 -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 4PnHKS6F0Wz1RtVn; Thu, 30 Mar 2023 01:54:20 -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 v4 12/17] PCI: epf-test: Simplify DMA support checks Date: Thu, 30 Mar 2023 17:53:52 +0900 Message-Id: <20230330085357.2653599-13-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-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 35bdb03f6ee1..b6398b8ba5ed 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -329,7 +329,6 @@ static void 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 void 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 void 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); @@ -433,7 +426,6 @@ static void 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; @@ -464,14 +456,7 @@ static void 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)) { @@ -496,7 +481,8 @@ static void 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) @@ -524,7 +510,6 @@ static void 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; @@ -558,14 +543,7 @@ static void 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)) { @@ -592,7 +570,8 @@ static void 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 @@ -679,6 +658,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 Thu Mar 30 08:53:53 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: 13193687 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 624BFC761AF for ; Thu, 30 Mar 2023 08:54:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229961AbjC3Iyh (ORCPT ); Thu, 30 Mar 2023 04:54:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229848AbjC3Iyc (ORCPT ); Thu, 30 Mar 2023 04:54:32 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 768DD7D80 for ; Thu, 30 Mar 2023 01:54:25 -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=1680166465; x=1711702465; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sbB+rxwdLquQhlGuPLL4KXBL+q5ejPkT0n+IOvq5fEk=; b=NwV2laRpUYUGAHNe5mzrELSgDKt3cKx5WogRCYaRgYpRt1F8qfGi8RNT wwnW+CPyFJXcKTlZ5iISPIpNXSuGPfQCAMm52L5/R5s5inG2qeh+pQ5oT XDLztg1YYAWGVLBOuWOC+jdMoPieUEn8ksiCaz+uQY3KHLvzPqzwAW0ZG LVhY/FS9XDo0Ig7jTibNIQb+h7K6c62Jtt2hc51AfSi19jjBU0w2XC72P ezWEovWP3FVwARnKhSm+3LW03DDq2WCZ+71CZDPbvswJusYwJ005/BWHO Tza5FOSYPPfLrSefRC9ND+V9CyxmjvfqtcYrCp9vcZ+Ys7dV1q5OQ0jLI A==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310487" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:25 +0800 IronPort-SDR: Ee+DnCWwFeyw4CSvDMaJ3gfsXmrrKuOStw1wZljxEMAhJCtau1h3sEkB9isycKTbEBcxt2jQO1 qV8FbfBmXo9KBSvWGz/Cq61Ly3LU5HG+6kxs0xbZX43oRWu5OuAAXwGZFhgpnB1Vf/NLzl6eKd djzVq1GW6bTwl2FiiwqpmjDAVtZyDum9gAk8E0FKfTY/tlTIfIjiVHVom4ilMnMDK0dN+fXE/Y 4ZsRqSa96UxMwZdqT297FQZ74p1SdOXAzYpV/rso3GrQvptfp4gdvfw/00uFxO0TSJ52ndpSbQ IVs= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:33 -0700 IronPort-SDR: gONSR/quxq9vvzzTK1KHLjB1tIpPeW7orzZ5nRUktB0uyN4T3yKHk6boFFDuOxqI4JpATRdN+7 lvUXHkBMyDTPm4e/AXL/0xisUq115glDEsPNfylbD2N/m1XiICglC06TkLF1QF2dZMdrs7xgHe NXp4bpvHxUdVENxD6S9oC0XFSRMF3A2R2O0/zE+PT9gcui6U/OXg1AI4ym8SA/7+gTcHkfcPHl N0Nr8s64Kdw08srKB/qjQYA9CTxdMyTJ3tp9YqF7ifZiqA3CEcOPztXSVcHPcJrRGHhsEhZUv/ Y20= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:25 -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 4PnHKX72khz1RtW2 for ; Thu, 30 Mar 2023 01:54:24 -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=1680166464; x=1682758465; bh=sbB+rxwdLquQhlGuPL L4KXBL+q5ejPkT0n+IOvq5fEk=; b=LzB6kiiuRnnIn99IzZH40dW3v+14TJZj7X ggZOJC0EMit1TTWhLy7Ak9EZPZxzqCPukPyzHS8QYE8I9s00M7GUyQzVFpKTUxXm +SlIP+oy3ngrPkb5jY7aFkpCL8x+4zWKzwMpChb7ye7vqSsxfE0g/KtOVdAW6ctW /Em41MzBQYKsq6IJs80nt09ct8xRniF8r7fnx4rTL1ZMVi4FiMyQ8idgYqNIEIJq uINk2LR2kVXMkKtzoOpFlVZ/XJLS/gVL4B5SdhrqrE5N73Y/bauHMnGCM9eZTw6o K39/dyRlUYMmiNLQQe+pH5liB1uBmlOSPYWYuzyOEgF97clxTHgQ== 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 ez-PUIe-KobK for ; Thu, 30 Mar 2023 01:54:24 -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 4PnHKV4Sxqz1RtVm; Thu, 30 Mar 2023 01:54:22 -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 v4 13/17] PCI: epf-test: Simplify transfers result print Date: Thu, 30 Mar 2023 17:53:53 +0900 Message-Id: <20230330085357.2653599-14-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-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 b6398b8ba5ed..bfab5f246e5b 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 void pci_epf_test_copy(struct pci_epf_test *epf_test, @@ -397,7 +386,7 @@ static void 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: @@ -481,7 +470,7 @@ static void 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); @@ -570,7 +559,7 @@ static void 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 Thu Mar 30 08:53:54 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: 13193688 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 C48BAC761AF for ; Thu, 30 Mar 2023 08:54:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229820AbjC3Iyo (ORCPT ); Thu, 30 Mar 2023 04:54:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230051AbjC3Iyh (ORCPT ); Thu, 30 Mar 2023 04:54:37 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BF0E7EC1 for ; Thu, 30 Mar 2023 01:54:28 -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=1680166468; x=1711702468; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c6fb/ATpu4bjomFurbyO/sIS4IvcEwK34bItru+sYXM=; b=E4RM6BwlX8mZcc0AnzxdKpG98NoU+5H6VAGqIK3ju//s7D/BvHQI/Hzq TYLreW4gj+0Bu7w/6RMatgVRjKmQcu3lYRq3QbY5OniXZKYst+PgKEiKE 58+oZSghWtBN6t5SycmJRbHOzI+AJ4mt8aWJl4QJ5qp68ilp/uNi8XrUo IvPYVpr8/aoPYn3BdWGCJbBbb/kCScSTcP3A0Obyt8BeQ10QtXxewd46N zh06uuDplUWU7Pyr7TjOlfdSAqTcNjMSco4FXhJGbWbGml8CPd+LTTPV9 XjRzGtfzWqbLHntXkFPJH6jKWL0ylIIp9tiH98/tH6Fr7N9EzI23bvZxa g==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310490" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:26 +0800 IronPort-SDR: tOy1UuApEzm9H0iFguCq6DrSJpdz6Dj1Pet47mfv66h6AzUHEXmqMpzyKvmIAYN/sGJgDqFjcF Z/Hxvmlwkoq6/u4re88W7j5vQAO/3a4IkazFTUhIUE7Uwtq+SRfF+M2Z3qwYOq7B0avljUQDUW TZxRabrTo4QvoFeUKu/oCQaA2NK45EwIDqvT9lke55TUf9K4z6AWK2sCs22eUaTNq1ljQJus+Y +z8jZhKWhd/f/hXwDD1RuQ/rQPi7aFZX+414o9/6UFYRfbawjZ0Ynygvp0I3h86tBS23FcmO1M PLo= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:34 -0700 IronPort-SDR: fYCcU+P9VOu1yQqp5AJEUWNkPEUcYw5vGiPUlWO5WLh1tVDKnsXXb+oBTPm0xXlL/D/GkkJ0qy 89D77UXNiEPnQZZWULcTpuWFm667ay9yLf+cvFRMYy/TIngDVa8E8XrMhXqAYCltCaL1cNtucn FF0BU8KdVPyBjvMFTaurf1st3uuFk6tGb+5B7/RLkgUke3OHPh9byJfZzkd5/i3FrT+PFO3mXX s61I9gcMvbp/xME0bkIyOKnwGVtNMVNDkAVr9Gc7bwx3JogGstgu+LxD9ZBIaRXPBu9wsmARWV trg= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:26 -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 4PnHKZ29n3z1RtVv for ; Thu, 30 Mar 2023 01:54:26 -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=1680166465; x=1682758466; bh=c6fb/ATpu4bjomFurb yO/sIS4IvcEwK34bItru+sYXM=; b=FxKJCv33s3R6Tdsr8jhJDzmD9BG77tPnQA q9dwM2Zqz9B3NaEdGiZ0sFcEB6FNP7ua3VU3xUxgyr5BaJlk7qTefEz6dRsU+PZY c9pz/N3Q/wFYwthCS5XTQxxrC/qicLJd3n6zE4bDaeQUz8oHiTXNlzewdc7xg/24 Hdo9SH6rk/4zJgSGLCMGBwWr0Y0YFzg1oMiiJZe9TzTHY1bGJI0oWKJOmaXqDoz7 7/l84D3Bg92dV/DYQhe+H/q0AGCKeFkdiPcLN7j1oG7ijMZZ/RAGfLsht+5VWQW6 y5coBlyNLFYFWyaVMfOpM1wddl/oQT+4+VfZDUP82kiDM66+GDIA== 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 slpYdqnETC0m for ; Thu, 30 Mar 2023 01:54:25 -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 4PnHKX1qPXz1RtVp; Thu, 30 Mar 2023 01:54:24 -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 v4 14/17] misc: pci_endpoint_test: Free IRQs before removing the device Date: Thu, 30 Mar 2023 17:53:54 +0900 Message-Id: <20230330085357.2653599-15-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-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 Thu Mar 30 08:53:55 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: 13193689 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 82FBCC6FD1D for ; Thu, 30 Mar 2023 08:54:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229612AbjC3Iyx (ORCPT ); Thu, 30 Mar 2023 04:54:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230165AbjC3Iyi (ORCPT ); Thu, 30 Mar 2023 04:54:38 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 975CD7683 for ; Thu, 30 Mar 2023 01:54:30 -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=1680166470; x=1711702470; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9hc8RCCLWTxRBYC9gxcz8ZAIDPbMiGNQupCTpkbGyu0=; b=KVlkG3sC22/CDBmI9t3K1LVTCizMYmQUZIDUKsWhLZbTVIEVHsptGpmy ht216MjYtu/5bqPM/6AfBWW0bWb1CSs8Muf/Y3ACQzYfis9F8x7YClZ9N Ao/vL/QAg/8O/g9U3DCB9i7a+ZmYjeQ3jTrRVDt6eAlsrIarzuHQqmps1 8ptCtGUIx2yKT5lUFRswjqYJY/xqb2jZ6XcxF38QQ9xW2smPJOS0umW9+ j4BqaJ8Lq2F07dTWlSFmFhHhvYWemO62I4pvcDrLyFYQFN+0F6QJBbJJT 62wziVLX+c3uzJjKcpIuZPIFW5lK4Es3qO4Qq+0+5JALrjp0OBa+TsVSM Q==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310494" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:28 +0800 IronPort-SDR: KO1byRHEdli5DY7Gzhzoj470motfKvqGj9ufgYyPZiww4Np7995qA8QOy5YWMyMx8SgF1yAJST f60DQtpLCofAd08y3FU+uTGVAjQZAveOMVeGOlJnJfn32HX18DfiX0o+EVn0cdJaaNMV0is2i8 kbonqTuthRVNZ3TpRChBWDP+ydnxkXxRa6pGehXgJqo7VSOXP8MWJZXoS+9wYPyBh50UuCsj8p UP56jjTLrGC8L9haICon5ehMYD9Iwb7Tr5Rm4U4uDu0UFUsH75+ta3VmOMbdxUG4CnUTZXb919 tmQ= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:36 -0700 IronPort-SDR: UWr4IAs+gBzMmmQ6SqNCpcCywpWpbwyZOwbKvUJrSJ9LTLTISnugwkFCgr6g1/FFeay8x8to+x oFnIc4O/TZHDd9OCPdcoz2oxRzem6bIQoXvUugV7Fzj5SzLNFzCq2Ah1nPdwKzAQ/Aq44Vb2jR wye0+9QH+V3wlkK2Z49hlzALTo8l6xBenDzKTxLpIYfuFlI7pl8TK3/fbbM58UeZmiIJSD/UJT Tx9GW6dBBJaG0PaqTICk93oE8D5UTuTQKZGS/RaSvPqDWtP2jwMQ47oyZdkl8OZm6YBnZgyRil 9l4= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:28 -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 4PnHKc1DMHz1RtVy for ; Thu, 30 Mar 2023 01:54:28 -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=1680166467; x=1682758468; bh=9hc8RCCLWTxRBYC9gx cz8ZAIDPbMiGNQupCTpkbGyu0=; b=It1nm9n07mW732LZlHkWDZ3RakaZhPJx9a kcRg9v+5g1H1Xwqf30/HDRUvrgBALuHlCQuPFAYOANB4OeKdbo3FMnhcuaza5Ntk JTkbh/CUsq1VD0hAJ7qfWP9C7w/geH55xr7saYthOp427w63sB7VwIFFvE5iXeHN pKRQxtgSzOGR1QOUgV4vlZeCQXfQvaaA7/0OlOyoL+EsdFDHqbnyQfrMETzYNsj4 IyOlnWZi0/W3GIg1b+rmp06d7lGWWucNhsU7sPLlLPJ2PvLqz6A7lyDroZn0mwTv r2p3Nl7XI5XJOjM9jywpBleVNIX6MkbNoEaNlCeIF9m9jX80Nuyg== 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 eugez6Q_F31N for ; Thu, 30 Mar 2023 01:54:27 -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 4PnHKZ1JjFz1RtVm; Thu, 30 Mar 2023 01:54:25 -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 v4 15/17] misc: pci_endpoint_test: Re-init completion for every test Date: Thu, 30 Mar 2023 17:53:55 +0900 Message-Id: <20230330085357.2653599-16-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-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 Reviewed-by: Manivannan Sadhasivam --- 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 Thu Mar 30 08:53:56 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: 13193690 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 B4B4BC761AF for ; Thu, 30 Mar 2023 08:54:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbjC3Iyx (ORCPT ); Thu, 30 Mar 2023 04:54:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230033AbjC3Iyp (ORCPT ); Thu, 30 Mar 2023 04:54:45 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 106D97ABE for ; Thu, 30 Mar 2023 01:54:32 -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=1680166473; x=1711702473; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nNNBPPwx3BeLf51ftFKDBjdeNrqS7hVotbLqERxh9VU=; b=QEYffDV4RDVjgO7W0csyNqUalvACAY8JE5LWjD3Nkp5HA+xmnFH6EMGz UzmwDvxqiCyGYYyI/S9Bh+p4AwJ8RoMEP+qFdCuQztluBHAz1JPYX6Vtc 7aJMalsjGeruZyWmRS4qtJihBKBZodNtz4F11gcemtZvwsg4JTXuO+ErU EJ3krw4hi+LuzukRGfdVWiuPCkeU0JBQwgMzZ5B71VYCeC0lCwFjWmzQU aaOJ9nVmFLAD+hlDQ2liKXhmz48AeO62leb0S7hwTohhWF4xMtm86O7NT 4v3MuhoCY6LQNVj8AVI08LY7T8+Xv/eP0IkeZokmQy8sykD8Qi9qkcMzX g==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310496" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:30 +0800 IronPort-SDR: 05K367hqL39CWZuyqpEmfgeG63tQB5sisGsa6/VrmsIFb9kKnn5O8v2TgcWTDH2u56z1VaqRDw 3VKoXqur3309IkShBSSuDbk2bWALPjPLhD0L8+O+7QSP9xrYglb6OUFEpNm5/Lxy53Em44TClZ ert8JYS4fBXVcOw5ispIg8kZC9CuWxXne4efICdVc0CVPmqnkb+B/f1lSOWLdoG9x8AkDjmL+F OJr0YRJBCCK7HZvpAkgzf+LY8EEbMHQY9Jz2te7Ra4SEFwqE9kobXDEPqX3e03FEfw2vuzjxyG Qp8= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:38 -0700 IronPort-SDR: TM2ap8c4VMbOoyv6VSEkXs84Xx+48Psr/j8OI0V/dywg58AnCchCNsbTmPbJr04InozrypR5WM Laop1ORB/WKoktgBu/2lq2MygwQgTyVnlNjC4h4ueJAyn6stbrbiiQN171rHQaV75JS+rPgpqC AG7NGJusFaHL/aI0WxrDRA8IVn9y5VlDxav1reuOL2Geeab9CkOa+MdXXoI1CE2as8Klsw/EHj Jpzt5c91BgijeXwyxIxwx3BIU4DnaR2UCnYqtj1pqP/Qbq4/5ebeumBvRXVr0rJtePVOZV3mdE 4Ds= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:30 -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 4PnHKd5dZTz1RtVy for ; Thu, 30 Mar 2023 01:54:29 -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=1680166469; x=1682758470; bh=nNNBPPwx3BeLf51ftF KDBjdeNrqS7hVotbLqERxh9VU=; b=JtMq/OTySw4afmsOWIw5Cwvj3hcYmrbvQN 5wAvhpSYmvjeWo48RcA0QS5c8sqoiepeTAqut+yWXjNjB33lv4pvk1rsIPzHKuqC oxXF50qdPDSiBwMoNeazZVV9R8OmpTLRZ7AnxEZ7slB5IacUMw69AV5RKu6cFqw9 kBxclDQ4EE5WCk9IGhPRLEW+j6xN3t8OvpxQ5m2/VS/D0jxijVIg4HtgjUUucZ7e L27jHOd/HnOFPrOpYjqdaJKFO6p670lNGqdX7SrgHr7Mbtqt09VbgCNqVRPDktSO kn3Ex89TY4UpaJLqd3ga3bNl9alTtdyg4nUPBkXcUXGWOW2sP4OQ== 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 E8T-2S0-gv2J for ; Thu, 30 Mar 2023 01:54:29 -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 4PnHKb68tWz1RtVn; Thu, 30 Mar 2023 01:54:27 -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 v4 16/17] misc: pci_endpoint_test: Do not write status in IRQ handler Date: Thu, 30 Mar 2023 17:53:56 +0900 Message-Id: <20230330085357.2653599-17-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-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 Thu Mar 30 08:53:57 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: 13193691 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 D376AC6FD1D for ; Thu, 30 Mar 2023 08:54:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230033AbjC3Iyz (ORCPT ); Thu, 30 Mar 2023 04:54:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229949AbjC3Iyx (ORCPT ); Thu, 30 Mar 2023 04:54:53 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 257617ED1 for ; Thu, 30 Mar 2023 01:54: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=1680166478; x=1711702478; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p+MxxNmS9DVwNUcLA55VvIMV4ImTHL2q/nFJco681WM=; b=cZLi7chO8bJo/hNW2iBY6yhjn6H5Sey/8YUvbhBkSrafVzSeBEh+u6Xc qsq8sMUMgQhbtqCI0wUAtpOggCd0hKZXEuFfckVh8/QX8DZw+alcXpMrB QAvjBzZ5QE6qnSlJJWs5RgiKw51Kw3pVCD2upezrhvAQhzW7Yup4kqWms 0ABrV9oskIyzwUH9witdAN9315JJGs/Px0VRm4qUDlWdsOx2nMS3GU04E Kegge0hhYSJbJSciRqkWUb+kGgxs8ZnIwvSqVUPLQ79lgXBQRT7krsImf 60Na52qZ5F3AwbcYoME1X57DaqMc10E2gFy0mjbAIm3EIACmsTHF4UCVg g==; X-IronPort-AV: E=Sophos;i="5.98,303,1673884800"; d="scan'208";a="331310499" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Mar 2023 16:54:31 +0800 IronPort-SDR: bq841QrrVwDk4UnCkRF1FBHBmmqDXIenBDgduXavjpHuGeLwiXSOm9GyqVJrwjoSRxBt2PfcHJ ad2KQXZgAffbbTu6p0rwx/Bnfp00b75KFM9Jp3bMW79SUX3sViZtOx2aqqeJu+zKD5/CA3TQHo uBndvAVrPEVRxc2PllxaubdUfKXEzAf+fxHDf6WthMFfKiYyqF9sSJXydhgb0/3EkAQHUnGgoH hrMHWC8qOq5zkEeDPfovjqzCZYCubb8BzxkwIr78fl5DhhB6iATL8hcF/+kY6U+bKGfHwTlFI/ spo= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:10:40 -0700 IronPort-SDR: ZyaoWfojku3VnrfCj+vCFyukk4xtQvklRJnI3jZ5uJCcJt5jSgXcOkd1WRrf2IyPcMb4pICsRY e9T25zsJAo6/jJN2puIbjZLeknUUa6bzV/x7d0z2L0J9Op6/YE3NLPnkcrcsrSoUQhnvluxvqM MYI7ZX53I6yYswaOsIdmR1qYvzB+ckHSKqAo4CQfqO5xzhdjYhyxAJ9zLZtjxmy+exdHznyC7T 2lPRIvRC4f7gxttKY2qT1pIwPyUZqHfVM/1qzyF4FVZso1JEdJGdALUNYcup68g8F9NkEeaIGN E2o= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Mar 2023 01:54:32 -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 4PnHKg3ZBcz1RtVv for ; Thu, 30 Mar 2023 01:54:31 -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=1680166470; x=1682758471; bh=p+MxxNmS9DVwNUcLA5 5VvIMV4ImTHL2q/nFJco681WM=; b=A64jJXPLc6V4e7mO/hGyesoVqemGKER85r 9Fv0K+mxYfRuWvOgolbOD2mXYtdTrWdHuMhbowzyHdD7th39j/snJjguKojWapu6 o/jRxO9OtWy0n6Av6fWN+d5VwGzgVsSC0rpWyGjqT0nNtK4D7JUcnUcePgQuwGAZ VXlYBbthsFakAAK6xMOsUYuz2KH3K9fqpkXI4Ln9/W8Dx7Ut1q1d6PcqDk7eSlhI aKq0XKdg1Uq/tp+V0tgOEYiVT5D4uJYrRnrRGVpC3gU5ZO00ITzOFhiLa5u5r+Z4 BRTh93iHyoWqqBYCja70DCWatH4p4kGioQA7kMVAa6rGAgELv7qA== 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 qpnvgEXMjTvI for ; Thu, 30 Mar 2023 01:54:30 -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 4PnHKd361Vz1RtVm; Thu, 30 Mar 2023 01:54: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 v4 17/17] misc: pci_endpoint_test: Simplify pci_endpoint_test_msi_irq() Date: Thu, 30 Mar 2023 17:53:57 +0900 Message-Id: <20230330085357.2653599-18-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330085357.2653599-1-damien.lemoal@opensource.wdc.com> References: <20230330085357.2653599-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,