From patchwork Sat Apr 15 02:35:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13212271 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 CC2F6C77B71 for ; Sat, 15 Apr 2023 02:35:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229712AbjDOCfu (ORCPT ); Fri, 14 Apr 2023 22:35:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbjDOCft (ORCPT ); Fri, 14 Apr 2023 22:35:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBED2F1 for ; Fri, 14 Apr 2023 19:35:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8859E64079 for ; Sat, 15 Apr 2023 02:35:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C9BFC4339C; Sat, 15 Apr 2023 02:35:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526147; bh=QKCTmwgEhdmPDd8Sw+UBV1l5V9URQT9GREzq8OGv0Xk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hOZ5U5pzE4IYJiJYNzeBlT0hya3PdmEarY+OLopYjLodUck0jUkvZ0QDd0xdTdgSj /7pkqdz5SR6nI9SllGPFAsdfinGDXjQVpFTUW1JLqdYhEEleAz/PVvMyy8a+7/0Gek oe0r764DYj8Ic8I/mIxQf8Uk6J4LlYqkEOv57qE279x8HX3M1lOePqQ7tR7GqVShud X7EAP7nZ23gUJ0MBeS0GdkpwI8SyzDbUUY7qGkuSa3VIrjtCYyRk28XiUBpXTrYfbp UkTVlTMyFGZNpibQ0ozaZgeC3CGJm1nm8n4D1L5FqlMiHuD8JJw1FRHjlElbkNkWyD t6+gJOjnaNh+Q== 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 v5 01/17] PCI: endpoint: Automatically create a function specific attributes group Date: Sat, 15 Apr 2023 11:35:26 +0900 Message-Id: <20230415023542.77601-2-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> 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 tying 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 endpoint function specific attributes are duplicated and cause a crash when the endpoint function device is torn down: refcount_t: addition on 0; use-after-free. WARNING: CPU: 2 PID: 834 at lib/refcount.c:25 refcount_warn_saturate+0xc8/0x144 CPU: 2 PID: 834 Comm: rmdir Not tainted 6.3.0-rc1 #1 Hardware name: Pine64 RockPro64 v2.1 (DT) pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) ... Call trace: refcount_warn_saturate+0xc8/0x144 config_item_get+0x7c/0x80 configfs_rmdir+0x17c/0x30c vfs_rmdir+0x8c/0x204 do_rmdir+0x158/0x184 __arm64_sys_unlinkat+0x64/0x80 invoke_syscall+0x48/0x114 ... 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 specific configfs 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. alos update the documentation for the pci-epf-ntb and pci-epf-vntb function drivers 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 | 42 +++++++++---------- 3 files changed, 29 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..e255a8415bd5 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,29 @@ 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)) { + dev_err(&epf_group->epf->dev, + "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 +543,8 @@ static void pci_epf_cfs_work(struct work_struct *work) pr_err("failed to create 'secondary' EPC interface\n"); return; } + + pci_ep_cfs_add_type_group(epf_group); } static struct config_group *pci_epf_make(struct config_group *group, From patchwork Sat Apr 15 02:35:27 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: 13212272 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 7E0E7C77B72 for ; Sat, 15 Apr 2023 02:35:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229786AbjDOCfv (ORCPT ); Fri, 14 Apr 2023 22:35:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbjDOCfu (ORCPT ); Fri, 14 Apr 2023 22:35:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D318419B9 for ; Fri, 14 Apr 2023 19:35:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 524A761752 for ; Sat, 15 Apr 2023 02:35:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55746C4339E; Sat, 15 Apr 2023 02:35:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526148; bh=STEpOTUiWA9Er4cFutlf6WB7CTLqxWETo8V9g6vrMD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Aiq9iL4xM6R2nfiXAIEXOxiiyr2xTSjaPYaF8/fPSjKLZfgogEaJP0v6F4B3IXcnr Zi89nnFjosO03WYPW4HmFbCyr3RLZ86MhXT+Uj0KpRpXJANeks6neK55z0N0KdrggZ JFCchE13e+td+4GK+B9bBLuH+/DO9p0dvMmPb9m5Hx/4qbnCaaaY8JoqY8trjjeJfz t3tNTBWaWQJfLelbNW+/o6dH9YjDaNtouwTtecjvW3PmeGOvLfiCdglwyRGOU0j6u5 tgL4A4TqPgRwinzBCGIR2l78WheUPegESLNYFjIpK5lPbnLGuCdxNf8mA7kIVSvmmR zyxWHsLt46OZQ== 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 v5 02/17] PCI: endpoint: Move pci_epf_type_add_cfs() code Date: Sat, 15 Apr 2023 11:35:27 +0900 Message-Id: <20230415023542.77601-3-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> 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 e255a8415bd5..0fb6c376166f 100644 --- a/drivers/pci/endpoint/pci-ep-cfs.c +++ b/drivers/pci/endpoint/pci-ep-cfs.c @@ -509,6 +509,26 @@ static const struct config_item_type pci_epf_type = { .ct_owner = THIS_MODULE, }; +static struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf, + struct config_group *group) +{ + struct config_group *epf_type_group; + + if (!epf->driver) { + dev_err(&epf->dev, "epf device not bound to driver\n"); + return NULL; + } + + if (!epf->driver->ops->add_cfs) + return NULL; + + mutex_lock(&epf->lock); + epf_type_group = epf->driver->ops->add_cfs(epf, group); + mutex_unlock(&epf->lock); + + return epf_type_group; +} + static void pci_ep_cfs_add_type_group(struct pci_epf_group *epf_group) { struct config_group *group; diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 2036e38be093..355a6f56fcea 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -20,38 +20,6 @@ static DEFINE_MUTEX(pci_epf_mutex); static struct bus_type pci_epf_bus_type; static const struct device_type pci_epf_type; -/** - * pci_epf_type_add_cfs() - Help function drivers to expose function specific - * attributes in configfs - * @epf: the EPF device that has to be configured using configfs - * @group: the parent configfs group (corresponding to entries in - * pci_epf_device_id) - * - * Invoke to expose function specific attributes in configfs. If the function - * driver does not have anything to expose (attributes configured by user), - * return NULL. - */ -struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf, - struct config_group *group) -{ - struct config_group *epf_type_group; - - if (!epf->driver) { - dev_err(&epf->dev, "epf device not bound to driver\n"); - return NULL; - } - - if (!epf->driver->ops->add_cfs) - return NULL; - - mutex_lock(&epf->lock); - epf_type_group = epf->driver->ops->add_cfs(epf, group); - mutex_unlock(&epf->lock); - - return epf_type_group; -} -EXPORT_SYMBOL_GPL(pci_epf_type_add_cfs); - /** * pci_epf_unbind() - Notify the function driver that the binding between the * EPF device and EPC device has been lost diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index a215dc8ce693..b8441db2fa52 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -214,8 +214,6 @@ void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar, enum pci_epc_interface_type type); int pci_epf_bind(struct pci_epf *epf); void pci_epf_unbind(struct pci_epf *epf); -struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf, - struct config_group *group); int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf); void pci_epf_remove_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf); #endif /* __LINUX_PCI_EPF_H */ From patchwork Sat Apr 15 02:35:28 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: 13212273 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 D7777C77B72 for ; Sat, 15 Apr 2023 02:35:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229766AbjDOCfy (ORCPT ); Fri, 14 Apr 2023 22:35:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230209AbjDOCfw (ORCPT ); Fri, 14 Apr 2023 22:35:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F9CCF1 for ; Fri, 14 Apr 2023 19:35:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1B44B60C54 for ; Sat, 15 Apr 2023 02:35:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E4A0C4339C; Sat, 15 Apr 2023 02:35:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526150; bh=aQDV2JW3UQIZCwlOCcaEMojpX+6j4yj30/CeoQBDQ24=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Es5T7ix2F99Z2zYkgTMbAftph3lJq5UqYh1oeas5VATWWJ0q9XbApCQRj1QCgK5XX NM66t/quckb2VN3RQTdy81tUKidRxfsUxxuW/RBNGTOK7Wjv7Rof5HZtXmoLNV2ZEa 5NWO94VNxlY6iuZQ9HNIu4h96FO47Lz+219C+Jk5yn9sohIwzQPuugYHR9yRvmOKAo wmY0LS9BQ8uQ2yhtJwV/Nkb/5Rd/qJvzmUtULDhp4Gkm8ZsvOKkhMqaij/gSfQVnWT besUJaSvTCJdwL9cneFkW1FzBMLvI/Eg/LfV+YDmgUeLVyBv4pcZIYTqA2b8wLGASY DevB36U9GQgTw== 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 v5 03/17] PCI: epf-test: Fix DMA transfer completion initialization Date: Sat, 15 Apr 2023 11:35:28 +0900 Message-Id: <20230415023542.77601-4-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> 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 Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 0f9d2ec822ac..d65419735d2e 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -151,10 +151,10 @@ static int pci_epf_test_data_transfer(struct pci_epf_test *epf_test, return -EIO; } + reinit_completion(&epf_test->transfer_complete); tx->callback = pci_epf_test_dma_callback; tx->callback_param = epf_test; cookie = tx->tx_submit(tx); - reinit_completion(&epf_test->transfer_complete); ret = dma_submit_error(cookie); if (ret) { From patchwork Sat Apr 15 02:35:29 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: 13212274 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 85126C77B71 for ; Sat, 15 Apr 2023 02:35:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229782AbjDOCfz (ORCPT ); Fri, 14 Apr 2023 22:35:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbjDOCfy (ORCPT ); Fri, 14 Apr 2023 22:35:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F2EC1BEC for ; Fri, 14 Apr 2023 19:35:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E017660C54 for ; Sat, 15 Apr 2023 02:35:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBF36C433A0; Sat, 15 Apr 2023 02:35:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526152; bh=huBaLxTzVh06XNINInraNEPEMj1tw7o3/gFkYcXbs9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MQkTujyVUngIlCYVNCIhDTpmL7jjMWw77loVpnDW9/9o9CnOYbLSHaVXZQDI88lbD MDBsvGa1DvPsixfbVaVHelvRbHjf1dvN5jClEUE1QrkAM9SIpOItGa4qy3d/ruD0PW atXeSuW1xu8x08zlIO88L/F4uLClj8gTjzMU+yrW9UAJAvZlIZTm7FbAPIh4AqZMuY GtL5GCCvS8HVU5ibSSjnloMCnTm3tMUOg9anLo+XkJ39rGxHy0c9TMZIO4Nv8lceql rSkuNub0BunYNmHJZsAtv863DTgAfp9v2H9XqfHjEpcZCXLmd58XL9X4Zw0kA98+ZY iqnKB+0XykB/A== 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 v5 04/17] PCI: epf-test: Fix DMA transfer completion detection Date: Sat, 15 Apr 2023 11:35:29 +0900 Message-Id: <20230415023542.77601-5-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> 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 Sat Apr 15 02:35:30 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: 13212275 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 893F1C77B72 for ; Sat, 15 Apr 2023 02:35:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229931AbjDOCf5 (ORCPT ); Fri, 14 Apr 2023 22:35:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230211AbjDOCf4 (ORCPT ); Fri, 14 Apr 2023 22:35:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2426F1BDB for ; Fri, 14 Apr 2023 19:35:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A5F7461730 for ; Sat, 15 Apr 2023 02:35:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4C64C433D2; Sat, 15 Apr 2023 02:35:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526154; bh=cX80ud/WhHTVycg2SPu+RpTJFPUlrMDoGUp79KlHQzI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kov4Lq3A36oNNVGxiu0dJ5XEt1YCSoDPqozhP2EnA8inkhBX4jpPJUoppl3VNwNCr l4LzYQ+AtCOzuPPi3DzWU86Avc7r6Z+GZfvGMImKlkP+LbcjO2LO+5CZCIghc08hNi h7JfRrOZER9rloF2N0eoEiZuSxUDNleOPWM0S38O3JxZwX44HOElrdIoufR1DDQTjS G1E7floDy75xH1fYwR+SD1tNRiXiKo0L4+Ua10jRcj2TTLV9uVbXEaMsUxKOYJU8lD /5mX3VfBMFroWBL621JwEPzrUhXNsPRb83Itu7zwF9U2xWwCWyiwJlkpYdraOUtwzF A6ZXtbBUHjxYg== 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 v5 05/17] PCI: epf-test: Use dmaengine_submit() to initiate DMA transfer Date: Sat, 15 Apr 2023 11:35:30 +0900 Message-Id: <20230415023542.77601-6-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> 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. Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index dbea6eb0dee7..7cdc6c915ef5 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -163,7 +163,7 @@ static int pci_epf_test_data_transfer(struct pci_epf_test *epf_test, epf_test->transfer_chan = chan; tx->callback = pci_epf_test_dma_callback; tx->callback_param = epf_test; - epf_test->transfer_cookie = tx->tx_submit(tx); + epf_test->transfer_cookie = dmaengine_submit(tx); ret = dma_submit_error(epf_test->transfer_cookie); if (ret) { From patchwork Sat Apr 15 02:35:31 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: 13212276 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 3D941C77B71 for ; Sat, 15 Apr 2023 02:36:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229463AbjDOCf6 (ORCPT ); Fri, 14 Apr 2023 22:35:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230209AbjDOCf6 (ORCPT ); Fri, 14 Apr 2023 22:35:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE9C510F0 for ; Fri, 14 Apr 2023 19:35:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6977661752 for ; Sat, 15 Apr 2023 02:35:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D94EC433A0; Sat, 15 Apr 2023 02:35:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526155; bh=FpJDcnZln1I9ZPlxeszyhpBMmHgdOcfuH+S0JUm/hP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S0zyOdJVXrkMr9wnDuLpa5SmooVwwmZ+Pua1L31jeBpdL2iQKhRMEaMhzE28cPrFY K6viMeEK5+SBr8CbuumCcpAcbf0B93XUueX8wnMhIq9lWChxobD8ruzziwddX0wO+X sdK/HxjBwo/S/4aF27O7N5d//IhQXHHibJr1lvlgfXAy2j8md9LUoxoUwuwhlpJK9j uoDBWtFmeAobFXrCRVHi+VTQFB0Rs1NhlL17uwMLoqb+yuh1rOGfbYlpxoRBrjepuR mHsVkPs8Sxdtw+S2ChqWmViYavbNi8eq3WRt4nNHpBoM4ydRLMyYGdw1v9TlyCFLnh MIfD9C1ej4Qzw== 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 v5 06/17] PCI: epf-test: Simplify read/write/copy test functions Date: Sat, 15 Apr 2023 11:35:31 +0900 Message-Id: <20230415023542.77601-7-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The function pci_epf_test_cmd_handler() uses the register BAR address as a pointer to a struct pci_epf_test_reg to determine the command sent by the host and to execute the test function accordingly. There is no need for doing this assignment 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(). Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-test.c | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 7cdc6c915ef5..b8b178ac7cda 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -325,7 +325,8 @@ static void pci_epf_test_print_rate(const char *ops, u64 size, (u64)ts.tv_sec, (u32)ts.tv_nsec, rate / 1024); } -static int pci_epf_test_copy(struct pci_epf_test *epf_test) +static int pci_epf_test_copy(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) { int ret; bool use_dma; @@ -337,8 +338,6 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test) struct pci_epf *epf = epf_test->epf; struct device *dev = &epf->dev; struct pci_epc *epc = epf->epc; - enum pci_barno test_reg_bar = epf_test->test_reg_bar; - struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; src_addr = pci_epc_mem_alloc_addr(epc, &src_phys_addr, reg->size); if (!src_addr) { @@ -424,7 +423,8 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test) return ret; } -static int pci_epf_test_read(struct pci_epf_test *epf_test) +static int pci_epf_test_read(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) { int ret; void __iomem *src_addr; @@ -438,8 +438,6 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) struct device *dev = &epf->dev; struct pci_epc *epc = epf->epc; struct device *dma_dev = epf->epc->dev.parent; - enum pci_barno test_reg_bar = epf_test->test_reg_bar; - struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; src_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, reg->size); if (!src_addr) { @@ -514,7 +512,8 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) return ret; } -static int pci_epf_test_write(struct pci_epf_test *epf_test) +static int pci_epf_test_write(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) { int ret; void __iomem *dst_addr; @@ -527,8 +526,6 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test) struct device *dev = &epf->dev; struct pci_epc *epc = epf->epc; struct device *dma_dev = epf->epc->dev.parent; - enum pci_barno test_reg_bar = epf_test->test_reg_bar; - struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; dst_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, reg->size); if (!dst_addr) { @@ -673,7 +670,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) } if (command & COMMAND_WRITE) { - ret = pci_epf_test_write(epf_test); + ret = pci_epf_test_write(epf_test, reg); if (ret) reg->status |= STATUS_WRITE_FAIL; else @@ -684,7 +681,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) } if (command & COMMAND_READ) { - ret = pci_epf_test_read(epf_test); + ret = pci_epf_test_read(epf_test, reg); if (!ret) reg->status |= STATUS_READ_SUCCESS; else @@ -695,7 +692,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) } if (command & COMMAND_COPY) { - ret = pci_epf_test_copy(epf_test); + ret = pci_epf_test_copy(epf_test, reg); if (!ret) reg->status |= STATUS_COPY_SUCCESS; else From patchwork Sat Apr 15 02:35:32 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: 13212277 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 E9ABFC77B76 for ; Sat, 15 Apr 2023 02:36:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230209AbjDOCgA (ORCPT ); Fri, 14 Apr 2023 22:36:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230210AbjDOCf7 (ORCPT ); Fri, 14 Apr 2023 22:35:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C35A3F1 for ; Fri, 14 Apr 2023 19:35:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3C7CD641FA for ; Sat, 15 Apr 2023 02:35:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35B2EC433EF; Sat, 15 Apr 2023 02:35:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526157; bh=3FDUF4qc7G9ujPuaniQM6hHZ1LrGGTfU0apISt1MqQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O66VYqYXTWJIBZbZRADd+TOORP7lwZz4ngUTg5eONMscuKCNUYV9TIRhbHhwbyaZa UWjyyHeYvN3bNcAi81AloErfrRgWNzBheyxaO+7bAgwZfhea0uSc17DDExmptOSVTH ouBVPcHeQuEzBbrVNx1s1jP//eTuua9f4egU3VxNglxecN7bMTnp3H48jDvfI0WmuO NuFlQdk3aGJbxm6MEwFObAa7125ZS8whUBpcKOrYV2sSSyI3Y/oPnBlwkJoMnAhHkH GNmeB7NCF7DuX7OFQYj/YGUbKmUPqms0icOUj4kZXOyUdcecMc4Th2ALu1YNGi0/ji CRGgemOH+v/Ng== 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 v5 07/17] PCI: epf-test: Simplify pci_epf_test_raise_irq() Date: Sat, 15 Apr 2023 11:35:32 +0900 Message-Id: <20230415023542.77601-8-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> 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 using the register BAR address and simplifies the call sites as the IRQ type and IRQ numbers do not have to be passed as arguments. Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-test.c | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index b8b178ac7cda..3835e558937a 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -607,29 +607,27 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test, return ret; } -static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, u8 irq_type, - u16 irq) +static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) { struct pci_epf *epf = epf_test->epf; struct device *dev = &epf->dev; struct pci_epc *epc = epf->epc; - enum pci_barno test_reg_bar = epf_test->test_reg_bar; - struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; reg->status |= STATUS_IRQ_RAISED; - switch (irq_type) { + switch (reg->irq_type) { case IRQ_TYPE_LEGACY: pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, PCI_EPC_IRQ_LEGACY, 0); break; case IRQ_TYPE_MSI: pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, - PCI_EPC_IRQ_MSI, irq); + PCI_EPC_IRQ_MSI, reg->irq_number); break; case IRQ_TYPE_MSIX: pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, - PCI_EPC_IRQ_MSIX, irq); + PCI_EPC_IRQ_MSIX, reg->irq_number); break; default: dev_err(dev, "Failed to raise IRQ, unknown type\n"); @@ -675,8 +673,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) reg->status |= STATUS_WRITE_FAIL; else reg->status |= STATUS_WRITE_SUCCESS; - pci_epf_test_raise_irq(epf_test, reg->irq_type, - reg->irq_number); + pci_epf_test_raise_irq(epf_test, reg); goto reset_handler; } @@ -686,8 +683,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) reg->status |= STATUS_READ_SUCCESS; else reg->status |= STATUS_READ_FAIL; - pci_epf_test_raise_irq(epf_test, reg->irq_type, - reg->irq_number); + pci_epf_test_raise_irq(epf_test, reg); goto reset_handler; } @@ -697,8 +693,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) reg->status |= STATUS_COPY_SUCCESS; else reg->status |= STATUS_COPY_FAIL; - pci_epf_test_raise_irq(epf_test, reg->irq_type, - reg->irq_number); + pci_epf_test_raise_irq(epf_test, reg); goto reset_handler; } From patchwork Sat Apr 15 02:35:33 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: 13212278 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 97C63C77B71 for ; Sat, 15 Apr 2023 02:36:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230210AbjDOCgD (ORCPT ); Fri, 14 Apr 2023 22:36:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230211AbjDOCgB (ORCPT ); Fri, 14 Apr 2023 22:36:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 975E73AAD for ; Fri, 14 Apr 2023 19:36:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0395E641FA for ; Sat, 15 Apr 2023 02:36:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3ADEC433A0; Sat, 15 Apr 2023 02:35:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526159; bh=Kob2bcM5khuSL7yw+1V8Un2XnF3OjPqYRqfBVPIHvjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RU1YzkkxtW9hBgQhL5Ox0Exxi6rruaIoXI5qmX3PWDgUMuWLuu/S5eJiXDyhZqDQP YJfKlEuKDdA9T1ixOqemiTN9LaxlVxnpbVv46a+rKx7T+Ep8jubEgHulGfAr4HUKWy i61/O926MfdHqIMw3C/g6ShLMaWwMmsFB8GUy1o3AJo3ftQVPLs0ncsrlmyifSeV6P A3WOYlEx6PykNWy97e5eLAdsG2EoxJHoDI1ab+LgQjL345wnVJzdC9mVEvFaz8k+7V n0fNl6fdWdChW3OtD0wgHRAzY52s34KLkJDydTBktK5LJb7L4vqRrsy+KDq1jNJE2I zZ+uRWzi566ew== 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 v5 08/17] PCI: epf-test: Simplify IRQ test commands execution Date: Sat, 15 Apr 2023 11:35:33 +0900 Message-Id: <20230415023542.77601-9-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> 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. Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-test.c | 43 ++++++++----------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 3835e558937a..ee90ba3a957b 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -613,6 +613,7 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, struct pci_epf *epf = epf_test->epf; struct device *dev = &epf->dev; struct pci_epc *epc = epf->epc; + int count; reg->status |= STATUS_IRQ_RAISED; @@ -622,10 +623,22 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, PCI_EPC_IRQ_LEGACY, 0); break; case IRQ_TYPE_MSI: + count = pci_epc_get_msi(epc, epf->func_no, epf->vfunc_no); + if (reg->irq_number > count || count <= 0) { + dev_err(dev, "Invalid MSI IRQ number %d / %d\n", + reg->irq_number, count); + return; + } pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, PCI_EPC_IRQ_MSI, reg->irq_number); break; case IRQ_TYPE_MSIX: + count = pci_epc_get_msix(epc, epf->func_no, epf->vfunc_no); + if (reg->irq_number > count || count <= 0) { + dev_err(dev, "Invalid MSIX IRQ number %d / %d\n", + reg->irq_number, count); + return; + } pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, PCI_EPC_IRQ_MSIX, reg->irq_number); break; @@ -638,13 +651,11 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, static void pci_epf_test_cmd_handler(struct work_struct *work) { int ret; - int count; u32 command; struct pci_epf_test *epf_test = container_of(work, struct pci_epf_test, cmd_handler.work); struct pci_epf *epf = epf_test->epf; struct device *dev = &epf->dev; - struct pci_epc *epc = epf->epc; enum pci_barno test_reg_bar = epf_test->test_reg_bar; struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; @@ -660,10 +671,10 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) goto reset_handler; } - if (command & COMMAND_RAISE_LEGACY_IRQ) { - reg->status = STATUS_IRQ_RAISED; - pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, - PCI_EPC_IRQ_LEGACY, 0); + if ((command & COMMAND_RAISE_LEGACY_IRQ) || + (command & COMMAND_RAISE_MSI_IRQ) || + (command & COMMAND_RAISE_MSIX_IRQ)) { + pci_epf_test_raise_irq(epf_test, reg); goto reset_handler; } @@ -697,26 +708,6 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) goto reset_handler; } - if (command & COMMAND_RAISE_MSI_IRQ) { - count = pci_epc_get_msi(epc, epf->func_no, epf->vfunc_no); - if (reg->irq_number > count || count <= 0) - goto reset_handler; - reg->status = STATUS_IRQ_RAISED; - pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, - PCI_EPC_IRQ_MSI, reg->irq_number); - goto reset_handler; - } - - if (command & COMMAND_RAISE_MSIX_IRQ) { - count = pci_epc_get_msix(epc, epf->func_no, epf->vfunc_no); - if (reg->irq_number > count || count <= 0) - goto reset_handler; - reg->status = STATUS_IRQ_RAISED; - pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, - PCI_EPC_IRQ_MSIX, reg->irq_number); - goto reset_handler; - } - reset_handler: queue_delayed_work(kpcitest_workqueue, &epf_test->cmd_handler, msecs_to_jiffies(1)); From patchwork Sat Apr 15 02:35:34 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: 13212279 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 AE2BFC77B76 for ; Sat, 15 Apr 2023 02:36:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230213AbjDOCgE (ORCPT ); Fri, 14 Apr 2023 22:36:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjDOCgD (ORCPT ); Fri, 14 Apr 2023 22:36:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 338902108 for ; Fri, 14 Apr 2023 19:36:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C0FE0640B7 for ; Sat, 15 Apr 2023 02:36:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C162DC433A4; Sat, 15 Apr 2023 02:35:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526161; bh=cnPvIe3DUATYCmiPG5AodQ3TLNnmT+c4xQzPqpxWVjg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YiktEOdL+ohS0tAs/yNcZ0wqbssj+ydrWy8r2nY5keY1uvotEbI1bAlcl9S882WZP dwtutS6HucV9t37aDVnvTqb3zwsMDQldg5HdGXGozJH1Cxi0WdSag4t4UsgtS7pLJ2 4cp7H6SmuEVuEByhcJaFXo27lzaPZISWhpkOB7Od15q1pWmvJxQWUXlnkkPC2hWVsR cPVrnccwUGGPgXAyHxCSPXI12l6kyJyYVuSqF49ajxdSphxJrDOZ0F4PG4zVrYexa9 twVZ2N6FMqy1NY2q64l9b+8c97GCbwCIdhrBeRBc/u53KLDdPgt4IlMUT7ttuTqo9B J9hAmtG8ShKOg== 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 v5 09/17] PCI: epf-test: Improve handling of command and status registers Date: Sat, 15 Apr 2023 11:35:34 +0900 Message-Id: <20230415023542.77601-10-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> 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 using the register BAR address as a pointer to a struct pci_epf_test_reg to execute the test case and to send 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 an interrupt. However, such assignment 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()) achieve a correct synchronization with the MMIO register accesses on the RC host. Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-test.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index ee90ba3a957b..fa48e9b3c393 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -613,9 +613,14 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, struct pci_epf *epf = epf_test->epf; struct device *dev = &epf->dev; struct pci_epc *epc = epf->epc; + u32 status = reg->status | STATUS_IRQ_RAISED; int count; - reg->status |= STATUS_IRQ_RAISED; + /* + * Set the status before raising the IRQ to ensure that the host sees + * the updated value when it gets the IRQ. + */ + WRITE_ONCE(reg->status, status); switch (reg->irq_type) { case IRQ_TYPE_LEGACY: @@ -659,12 +664,12 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) enum pci_barno test_reg_bar = epf_test->test_reg_bar; struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; - command = reg->command; + command = READ_ONCE(reg->command); if (!command) goto reset_handler; - reg->command = 0; - reg->status = 0; + WRITE_ONCE(reg->command, 0); + WRITE_ONCE(reg->status, 0); if (reg->irq_type > IRQ_TYPE_MSIX) { dev_err(dev, "Failed to detect IRQ type\n"); From patchwork Sat Apr 15 02:35:35 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: 13212280 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 B74E0C77B71 for ; Sat, 15 Apr 2023 02:36:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230215AbjDOCgH (ORCPT ); Fri, 14 Apr 2023 22:36:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjDOCgG (ORCPT ); Fri, 14 Apr 2023 22:36:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 025B2199B for ; Fri, 14 Apr 2023 19:36:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8BF48640A5 for ; Sat, 15 Apr 2023 02:36:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A3B7C4339E; Sat, 15 Apr 2023 02:36:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526163; bh=cljwCRniMK/wkn0U0i5rkIm26oxLcyZRQ09HVI78h5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YZfG36PVwqR/fadg8Go7dsdz+SSs8bK+ZPjCaHPSZ7xUc/lzwMUkcQ6fmdD+kdD7I 6N4LctQm8EUXgSUhf+vfM9ZLDhrp0afV+5SWUtTFG7cMEGUurrpR9yrkLBbHHT1Ot5 gyJDGiqA7kxNY0/XDO4iM8n3EpA6iHRxqdFlz/K4sAUfb29QkYtvYMl21Bobw+FPTs EV3ZjTT9rs19ZD7QtjFaKgir/rdbOqT5frf1OKdDNV6hB5smylYRQyXbkHgFsl27MN gxdXJUfP3x3iBtZrU0HfT9BciWZOOWfFto2Ct9npRbBqmdLrKvVR4OxbSRf/sj/QFe ax2KibmgPq0uA== 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 v5 10/17] PCI: epf-test: Cleanup pci_epf_test_cmd_handler() Date: Sat, 15 Apr 2023 11:35:35 +0900 Message-Id: <20230415023542.77601-11-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> 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. Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- 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..7f482ec08754 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 0x%x\n", command); + break; } reset_handler: From patchwork Sat Apr 15 02:35:36 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: 13212281 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 6E277C77B71 for ; Sat, 15 Apr 2023 02:36:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230226AbjDOCgK (ORCPT ); Fri, 14 Apr 2023 22:36:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230060AbjDOCgK (ORCPT ); Fri, 14 Apr 2023 22:36:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F24065B8D for ; Fri, 14 Apr 2023 19:36:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 590D964B4B for ; Sat, 15 Apr 2023 02:36:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54069C433A0; Sat, 15 Apr 2023 02:36:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526164; bh=YYJHZeD6tS0XdBwd/PW+/MPA+LxHJ36xsB42mpfSO5E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X3lsP0rnTtGY/cTvnMFZHod0c4m04CWgE2Q+2/1WGGFLuCF7Xf2x1nxaRFTeXztMR MixqEj6u5iU0NpyMnY+mPCEVW2sUndBT4p1P3C218urG0GGF7QXfQxbzI2fvzFu/rd nbdAOkkHtsI7dxkX5sXZGA9MPINoiw9VEq5TKbf4C/JLOzHmkk0bwWS4HbCZb3FEEQ wUuN50fF2rQkpTT5FlDrbAHRQnVj0IuUfXa2Em/qi3zlhqikvRvo74vsuwmzriJlf/ ObOjdh1lXWPdGOrOMVdsqJcHsTqZfg87BNUBWnR546JUX8YTmHLgExZRQOK4S/eYZG 6/t7gDRvhy9IA== 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 v5 11/17] PCI: epf-test: Cleanup request result handling Date: Sat, 15 Apr 2023 11:35:36 +0900 Message-Id: <20230415023542.77601-12-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> 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 7f482ec08754..e528b0915444 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 Sat Apr 15 02:35:37 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: 13212282 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 AE3FEC77B71 for ; Sat, 15 Apr 2023 02:36:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbjDOCgO (ORCPT ); Fri, 14 Apr 2023 22:36:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230060AbjDOCgN (ORCPT ); Fri, 14 Apr 2023 22:36:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAF0F1703 for ; Fri, 14 Apr 2023 19:36:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2156364295 for ; Sat, 15 Apr 2023 02:36:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DD44C433EF; Sat, 15 Apr 2023 02:36:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526166; bh=UQud1eQPhJzFP6dbMTzs8ix8ez2vCUMK13c+42SP0mo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sq9Y8pcbscymqLJOj/hpRb4q225PawyIE3jIj3eF/HRv87hvDTnudqgD3vuXB0qJl BGY+pVI0judVzhRSnczdFq+KpC6YHnCb0KgrjI0sNFwyHfk76s+PNglpKH7+WqUzw5 27zjFpkfCVQ0fKJ5ksvqc9l0lqcns00wTvjcJTchq5Fck4DJcMW8OYZlWqQHcy8iq1 lRPo13xVe3g5vLCl2d8HVBYEimvWjz8wgBN0xRxkuBc07NZ9lt86+4nq91Novp42Vt 0qKw1OxqeuaqI6wzd2VdHBgGUdKE+yM+P7O0zm9u9UDdeLgjyMQsRRZwoZE35aLjUR X+G7EWNZqVs3w== 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 v5 12/17] PCI: epf-test: Simplify DMA support checks Date: Sat, 15 Apr 2023 11:35:37 +0900 Message-Id: <20230415023542.77601-13-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> 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. Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- 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 e528b0915444..909e3e8ac01c 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 Sat Apr 15 02:35:38 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: 13212283 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 6C959C77B72 for ; Sat, 15 Apr 2023 02:36:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230225AbjDOCgQ (ORCPT ); Fri, 14 Apr 2023 22:36:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230214AbjDOCgO (ORCPT ); Fri, 14 Apr 2023 22:36:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44B0A5FFC for ; Fri, 14 Apr 2023 19:36:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D6D0D64079 for ; Sat, 15 Apr 2023 02:36:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB3C0C433D2; Sat, 15 Apr 2023 02:36:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526168; bh=G0LOHzcvtEdKXfEDzwz1WeiaCCW1mDE2gp5mIDAgnXw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R5Dob+elXzI2mED2gQFbw7x07kAoYixg2y75RE5bs6kwVqIkchxpbMqbt9qcvxtSh m/EizFVMwi4qg9oAL72ghMw/lNjiMe8zLFr5+6ZsAr+UijM95njjMWMrhqBoPXJk8O N1P0BsBfZrHpGeD5qELuyoNNqqI9r17eYZxZEW/dLMankiA4yR4tJUrRbIXSXlqoRk 50FnWdQd0BbAdl5AdOZZz07sFugOd2dKj7uwkwmqQIcWNhvZP7bNF0QiHW8sZz0jcT Gb2dxrXwRAs/+mVNV0RiF41SYW1FzrEqHxcrJ13nqilz6l0SkzgZmez5Zyz9JJfcTc u3nNautNpY/Yw== 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 v5 13/17] PCI: epf-test: Simplify transfers result print Date: Sat, 15 Apr 2023 11:35:38 +0900 Message-Id: <20230415023542.77601-14-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> 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). Change the format of the results printed by pci_epf_test_print_rate() to be more compact without the double new line. Also use dev_info() instead of pr_info(). Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- 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 909e3e8ac01c..0bb14fb21edd 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 Sat Apr 15 02:35:39 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: 13212284 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 8563BC77B71 for ; Sat, 15 Apr 2023 02:36:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230060AbjDOCgR (ORCPT ); Fri, 14 Apr 2023 22:36:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230240AbjDOCgQ (ORCPT ); Fri, 14 Apr 2023 22:36:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23B5D19A2 for ; Fri, 14 Apr 2023 19:36:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A421F64B4B for ; Sat, 15 Apr 2023 02:36:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3D4EC4339B; Sat, 15 Apr 2023 02:36:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526170; bh=XtZGLCorVqq2jk0JppEXghjMlcoHKCBAapRT2bmupys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JJEoICe8Z46JIPKkXahfByKRtt2LGw+2xJc8jRbx2iMTtz+j/1slM8hl1HVbQH/rq U9iruSbkKSgrap6fWspFryEatDOd7jDXe3I5MvqKUJjINqQqSVRZpf7b3H3tHBanqP OYi85hC4LvLjEWILSg+TpdYWJ7cuyRERUKrFvx1kIzraTyqSrmlUyx33SmX+Yly+NQ YSpK5GlST+DfctdtLh1PqO0XOfhdHTOW7oyi6BlTIP1/cLIAUyzw1cz5mwrIorKHFl D6xb02yW5qddI/+qY2yEckDC5j3rmVDoUsdFOZr8CUhaIQn9DJHUMjxFDbd+U4Sm62 RIXypaxU8mdHQ== 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 v5 14/17] misc: pci_endpoint_test: Free IRQs before removing the device Date: Sat, 15 Apr 2023 11:35:39 +0900 Message-Id: <20230415023542.77601-15-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In pci_endpoint_test_remove(), freeing the IRQs after removing the device creates a small race window for IRQs to be received with the test device memory already released, causing the IRQ handler to access invalid memory, resulting in an oops. Free the device IRQs before removing the device to avoid this issue. Fixes: e03327122e2c ("pci_endpoint_test: Add 2 ioctl commands") Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/misc/pci_endpoint_test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index a7244de081ec..01235236e9bc 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -938,6 +938,9 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev) if (id < 0) return; + pci_endpoint_test_release_irq(test); + pci_endpoint_test_free_irq_vectors(test); + misc_deregister(&test->miscdev); kfree(misc_device->name); kfree(test->name); @@ -947,9 +950,6 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev) pci_iounmap(pdev, test->bar[bar]); } - pci_endpoint_test_release_irq(test); - pci_endpoint_test_free_irq_vectors(test); - pci_release_regions(pdev); pci_disable_device(pdev); } From patchwork Sat Apr 15 02:35:40 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: 13212285 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 2844EC77B71 for ; Sat, 15 Apr 2023 02:36:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229450AbjDOCgU (ORCPT ); Fri, 14 Apr 2023 22:36:20 -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 S230229AbjDOCgT (ORCPT ); Fri, 14 Apr 2023 22:36:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4483199B for ; Fri, 14 Apr 2023 19:36:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6DD17641FA for ; Sat, 15 Apr 2023 02:36:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C50FC433EF; Sat, 15 Apr 2023 02:36:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526171; bh=u1ezdPRrHzvtnAwZGpavSpRIrY/aHgPs0XZn5RTbmb0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VH4esIv3z240htn9P/1m/S53CzygkAvZkrjXlisqjag3gI12hF/ywbslMV+NhREIn 2AGeaGlmXy29o5mS1W+6aTn6jyCtUIkNy9a+9k6rq9qedMpb87Kr3pmqKcnDsMvNGD Y7Y3xgzJd0APHWTzbhFj6mekdCy+G3+XxxDQkjN6FXI7GkxcAzeLugT2YXc2vX7Uh3 q0l5YuhwbgnK4PNux00z6JE11KxI7r7vZNeN8zGI0RL1z+pjLo3o9ngSvOIkDiZm/X jDbkZixwM99u1rJV7+FWNecUfvQtgFfa6eLlu7yCcAKflmwISNyr63xfKVraWP+JBI tMwrhwjpgtCrw== 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 v5 15/17] misc: pci_endpoint_test: Re-init completion for every test Date: Sat, 15 Apr 2023 11:35:40 +0900 Message-Id: <20230415023542.77601-16-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> 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 Sat Apr 15 02:35: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: 13212286 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 95079C77B71 for ; Sat, 15 Apr 2023 02:36:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230251AbjDOCgY (ORCPT ); Fri, 14 Apr 2023 22:36:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230231AbjDOCgU (ORCPT ); Fri, 14 Apr 2023 22:36:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5863765B7 for ; Fri, 14 Apr 2023 19:36:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2FFE3640A5 for ; Sat, 15 Apr 2023 02:36:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34FAAC433A0; Sat, 15 Apr 2023 02:36:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526173; bh=Ux2mNoqjhFXFx6wF6g7wcbT2X5pIm7bpvZRZPLuKCBc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p2fbr+l5DWI9lxnbOZ6hJMi3sqo2w9yX9ycsRALciYL2A+rFqH5WCb+bfnEJt18Vz S5yuEozwbwKCflYrDYoONvtHQGwUZCYe0zhUKWL/Gn0iWHbmTATDkM4hwnV6DBzI37 G9+seRlt5/gnbNRjMMduY5VL3ch1CNtXjEhL/02DcWA2+0QvrOAG8Av+LKggWk0SvX fE/MpYIozolWIAoasGwihz6viFj2DNqi7K4Z3uJb6bjSpaWqyetqGv44kMNb+nnZto 6AmznPz6ioilgbv6MEaIWo3FWnVYesarHNJ8djCLjkUJZIHoJQrJyGpkfAQ8YBKyEe 6b8/SlvEzcudg== 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 v5 16/17] misc: pci_endpoint_test: Do not write status in IRQ handler Date: Sat, 15 Apr 2023 11:35:41 +0900 Message-Id: <20230415023542.77601-17-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> 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 losing the real status as set by the endpoint side before raising the next interrupt. This can prevent detecting that the STATUS_IRQ_RAISED flag was set by the endpoint. Remove this race window by not clearing the STATUS_IRQ_RAISED status flag and not rewriting that register for every IRQ received. Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/misc/pci_endpoint_test.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 24efe3b88a1f..afd2577261f8 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -159,10 +159,7 @@ static irqreturn_t pci_endpoint_test_irqhandler(int irq, void *dev_id) if (reg & STATUS_IRQ_RAISED) { test->last_irq = irq; complete(&test->irq_raised); - reg &= ~STATUS_IRQ_RAISED; } - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_STATUS, - reg); return IRQ_HANDLED; } From patchwork Sat Apr 15 02:35: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: 13212287 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 9F41AC77B71 for ; Sat, 15 Apr 2023 02:36:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230270AbjDOCg3 (ORCPT ); Fri, 14 Apr 2023 22:36:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230241AbjDOCgX (ORCPT ); Fri, 14 Apr 2023 22:36:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22D357DAA for ; Fri, 14 Apr 2023 19:36:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EC514640B7 for ; Sat, 15 Apr 2023 02:36:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F06F1C433D2; Sat, 15 Apr 2023 02:36:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681526175; bh=cj9F7YjPaqSCHyV3T+0AIzR+XeUY/aNA102SsR5duuE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qtABFsgi52p5uvitKqIXKB7w0d7YX4jGy/zkI/SBU6xQyU5zNVVVxZP1INgR8A/ML STT1uYHtKTdrsWPdBcV25wWhIo+cyZJYpN1wPBGHhGIt5Vqz6yOQ1DLlC7KEWu1UQc ZU0XcTvUfPkyI9yytfLAxqCpD682vgzIce6dp52CiBLfowiZ0ic/jaU/6lygEJo1r5 mBRJDz/Gi+9qUPsd6Y1QTNRaCyyjoB97GnXotoiOl7vbXAXcSdvPKfIvsxJRm7GlaY Fh3P07MLpSssz0D3M+CKOavXJoffKi/fXw0dHQ7Ab71UDfVyEBKCt+xX0ZQgCqHId6 hYSOhOXxV7INQ== 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 v5 17/17] misc: pci_endpoint_test: Simplify pci_endpoint_test_msi_irq() Date: Sat, 15 Apr 2023 11:35:42 +0900 Message-Id: <20230415023542.77601-18-dlemoal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230415023542.77601-1-dlemoal@kernel.org> References: <20230415023542.77601-1-dlemoal@kernel.org> 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,