From patchwork Wed Mar 8 09:02:58 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: 13165468 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 2E108C678D5 for ; Wed, 8 Mar 2023 09:04:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229814AbjCHJEX (ORCPT ); Wed, 8 Mar 2023 04:04:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229603AbjCHJER (ORCPT ); Wed, 8 Mar 2023 04:04:17 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AFF2198B for ; Wed, 8 Mar 2023 01:03:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266215; x=1709802215; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IKpKIi+RDytzszzbrjWeKwDxiVX4G2UiJ0s8BP61ZHk=; b=FKdR2Ur7IPoHgromvSPpyN2xQKOc0jKI+Iik/PCJt3RgWgE+2CBfyVNy cV+pG7q1evXpSmd3Cp04l4IH+cceMaO6MeWk3PpZxMwatE28d4DlYQZck EPPlwGFrySnmgajKW2kla7bLwMe5G7w2gGqvcHdW0eSvrNqG8gQFIhubg G0g6AYwW8+7mhb3SFcvwhaUgleROimW6mqli1rXJs1DhoOnx7j92kXS24 fFP1LzHov2GtsTxMb3ObJJyczugCQ6oRjHN7R+escEnLLY4qm1wqk1wbD bM8OX+TttbUM3TAdj/xRsZ0WZM33KKCjYiGTEhXVhVvwArR+ff2EVvw1W g==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880535" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:19 +0800 IronPort-SDR: a39kCNWP3vTbo2V80wiIWJKIgZi5a+JSmvs5J41RMiXr/adNayOjqU1TZwMTO09tTY7rZDVQ2R hozPuFV8HHBU0kCVsoYibAOcOaGq7cgotYNrAz+cseCCu8sxcMGU1xG62k7NwwIHqIvAwCdajG amaAs0q50Bn6L8IYre7sX7IrJie6Nti3BKCjk7ctM+3SFsdCeInJrw3RWhbFranuPVFbtAd7kI 8Mu7dPWAru5yZrTl+rnQzZ9jphmRGhc+NPhD2Scyqd5G4KrKM39QMqYIXfE7ClpXgm6YWXJ/o0 Gsc= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:16 -0800 IronPort-SDR: qWXW+YVt7VhcyCD/10iXzOx613pkXgiXs+5RtXeW+gC+W5KNIdHiTAaz/JPOxssh9WNrOku2r/ 2rnKYFoxaTNkxjv4HfppejbqEdVCLZvJ1cCIYymhXd6UumEyL7HvdrmvrembN3fJM6xvA6WkeL zGBC50K5/XyusxxgXW6GE0IqF5qPX9bMe2MSlCvN9+7LctfrJRhypA3hWjL/Ddetf7mvtZP/t3 UEgktU3SGw9Ks2tzkrZZWWlx/c0mhCJD+BOnRea62yP4v0CvUB4FltDi4aueNU/S7uIOQqNg7Q gV0= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:20 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmYz3TnMz1Rwt8 for ; Wed, 8 Mar 2023 01:03:19 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266198; x=1680858199; bh=IKpKIi+RDytzszzbrj WeKwDxiVX4G2UiJ0s8BP61ZHk=; b=Y57hFjK/rVcDReqYVMlqXnG4xbTOblJvRL RC3sGQzlvokmS7QalF6+C8BPxuR9qO+NyOkL7nD8sPgE0uKAitWZN2fQK2FlVMcj 7KP1/QhMDv5Bm7UDNj71yrCHaIMdiCk4wIZAnoHuMZuposgzkXlUhMSxCY7CFXaT Xwy3LOmEGU6s7Wt0RJ0UocFx2GxJztZB8HHhmhd+uB0xWWcgE5f77q/w1yN3s31M petZgyy1yf4PN2p/1L4ro68W6gaNWRY8CfcO/oeNiYKBPj1S5QVDE2MY0SLfRV3r 1Di1oVLw5buhUjUWiT+np0H94vLOiBKv18Inq9pY1hpk0QRdXJOA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ZHG-z1sjiOnh for ; Wed, 8 Mar 2023 01:03:18 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmYw6XjTz1RvTp; Wed, 8 Mar 2023 01:03:16 -0800 (PST) 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 v2 01/16] PCI: endpoint: Automatically create a function specific attributes group Date: Wed, 8 Mar 2023 18:02:58 +0900 Message-Id: <20230308090313.1653-2-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org A PCI endpoint function driver can define function specific attributes under its function configfs directory using the add_cfs() endpoint driver operation. This is done by tighing up the mkdir operation for the function configfs directory to a call to the add_cfs() operation. However, there are no checks preventing the user from repeatedly creating function specific attribute directories with different names, resulting in the same endpoing specific attributes group being added multiple times, which also result in an invalid refernce 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 func0/ |-- baseclass_code |-- cache_line_size |-- ... `-- vendorid 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: func0/ |-- attrs | |-- db_count | |-- mw1 | |-- mw2 | |-- mw3 | |-- mw4 | |-- num_mws | `-- spad_count |-- attrs2 | |-- db_count | |-- mw1 | |-- mw2 | |-- mw3 | |-- mw4 | |-- num_mws | `-- spad_count |-- baseclass_code |-- cache_line_size |-- ... `-- vendorid The function specific attributes are duplicated and cause a crash when the function is tore down: [ 9740.729598] ------------[ cut here ]------------ [ 9740.730071] refcount_t: addition on 0; use-after-free. [ 9740.730564] WARNING: CPU: 2 PID: 834 at lib/refcount.c:25 refcount_warn_saturate+0xc8/0x144 [ 9740.735593] CPU: 2 PID: 834 Comm: rmdir Not tainted 6.3.0-rc1 #1 [ 9740.736133] Hardware name: Pine64 RockPro64 v2.1 (DT) [ 9740.736586] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 9740.737210] pc : refcount_warn_saturate+0xc8/0x144 [ 9740.737648] lr : refcount_warn_saturate+0xc8/0x144 [ 9740.738085] sp : ffff800009cebc90 [ 9740.738385] x29: ffff800009cebc90 x28: ffff0000019ed700 x27: ffff0000040c3900 [ 9740.739032] x26: 0000000000000000 x25: ffff800009325320 x24: ffff0000012da000 [ 9740.739678] x23: ffff000003bd9a80 x22: ffff000005ee9580 x21: ffff000003bd9ad8 [ 9740.740324] x20: ffff0000f36cd2c8 x19: ffff0000012da2b8 x18: 0000000000000006 [ 9740.740969] x17: 0000000000000000 x16: 0000000000000000 x15: 0765076507720766 [ 9740.741615] x14: 072d077207650774 x13: ffff800009281000 x12: 000000000000056d [ 9740.742261] x11: 00000000000001cf x10: ffff8000092d9000 x9 : ffff800009281000 [ 9740.742906] x8 : 00000000ffffefff x7 : ffff8000092d9000 x6 : 80000000fffff000 [ 9740.743552] x5 : ffff0000f7771b88 x4 : 0000000000000000 x3 : 0000000000000027 [ 9740.744197] x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff0000019ed700 [ 9740.744842] Call trace: [ 9740.745068] refcount_warn_saturate+0xc8/0x144 [ 9740.745475] config_item_get+0x7c/0x80 [ 9740.745822] configfs_rmdir+0x17c/0x30c [ 9740.746174] vfs_rmdir+0x8c/0x204 [ 9740.746482] do_rmdir+0x158/0x184 [ 9740.746787] __arm64_sys_unlinkat+0x64/0x80 [ 9740.747171] invoke_syscall+0x48/0x114 [ 9740.747519] el0_svc_common.constprop.0+0x44/0xec [ 9740.747948] do_el0_svc+0x38/0x98 [ 9740.748255] el0_svc+0x2c/0x84 [ 9740.748541] el0t_64_sync_handler+0xf4/0x120 [ 9740.748932] el0t_64_sync+0x190/0x194 [ 9740.749269] ---[ end trace 0000000000000000 ]--- [ 9740.749754] ------------[ cut here ]------------ Fix this by modifying pci_epf_cfs_work() to execute the new function pci_ep_cfs_add_type_group() which itself calls pci_epf_type_add_cfs() to obtain the function specific attribute group and the group name (directory name) from the endpoint function driver. If the function driver defines an attribute group, pci_ep_cfs_add_type_group() then proceeds to register this group using configfs_register_group(), thus automatically exposing the function type pecific onfigfs attributes to the user. E.g.: 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/delete directories in the endpoint function configfs directory. The pci_epf_type_group_ops group operations are thus removed. Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/pci-ep-cfs.c | 41 ++++++++++++++----------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/drivers/pci/endpoint/pci-ep-cfs.c b/drivers/pci/endpoint/pci-ep-cfs.c index 4b8ac0ac84d5..b16fc6093c20 100644 --- a/drivers/pci/endpoint/pci-ep-cfs.c +++ b/drivers/pci/endpoint/pci-ep-cfs.c @@ -23,6 +23,7 @@ struct pci_epf_group { struct config_group group; struct config_group primary_epc_group; struct config_group secondary_epc_group; + struct config_group *type_group; struct delayed_work cfs_work; struct pci_epf *epf; int index; @@ -502,34 +503,28 @@ static struct configfs_item_operations pci_epf_ops = { .release = pci_epf_release, }; -static struct config_group *pci_epf_type_make(struct config_group *group, - const char *name) -{ - struct pci_epf_group *epf_group = to_pci_epf_group(&group->cg_item); - struct config_group *epf_type_group; - - epf_type_group = pci_epf_type_add_cfs(epf_group->epf, group); - return epf_type_group; -} - -static void pci_epf_type_drop(struct config_group *group, - struct config_item *item) -{ - config_item_put(item); -} - -static struct configfs_group_operations pci_epf_type_group_ops = { - .make_group = &pci_epf_type_make, - .drop_item = &pci_epf_type_drop, -}; - static const struct config_item_type pci_epf_type = { - .ct_group_ops = &pci_epf_type_group_ops, .ct_item_ops = &pci_epf_ops, .ct_attrs = pci_epf_attrs, .ct_owner = THIS_MODULE, }; +static void pci_ep_cfs_add_type_group(struct pci_epf_group *epf_group) +{ + struct config_group *group; + + group = pci_epf_type_add_cfs(epf_group->epf, &epf_group->group); + if (!group) + return; + + if (IS_ERR(group)) { + pr_err("failed to create epf type specific attributes\n"); + return; + } + + configfs_register_group(&epf_group->group, group); +} + static void pci_epf_cfs_work(struct work_struct *work) { struct pci_epf_group *epf_group; @@ -547,6 +542,8 @@ static void pci_epf_cfs_work(struct work_struct *work) pr_err("failed to create 'secondary' EPC interface\n"); return; } + + pci_ep_cfs_add_type_group(epf_group); } static struct config_group *pci_epf_make(struct config_group *group, From patchwork Wed Mar 8 09:02:59 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: 13165469 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 93250C64EC4 for ; Wed, 8 Mar 2023 09:04:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229621AbjCHJEY (ORCPT ); Wed, 8 Mar 2023 04:04:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbjCHJES (ORCPT ); Wed, 8 Mar 2023 04:04:18 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D7E3B3729 for ; Wed, 8 Mar 2023 01:03:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266216; x=1709802216; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=83skHeTyuuHUEsf609nh/HewU5bhrZRbY23BMMXBCaI=; b=iBiCFl36iPoI1LSkXjM2oBIDVoRJkMQzNLPuUy7Ui3GiMuqvaKUylFGf Bl08GLoVRxV1pQg+7o8PqElEPln4nCxknvqe8Gm6ghXEohKdw4bCisb8Z p72kBg/TYvpwjaRSEPg01ucHfYGW0jMG0+ff2Hokw4b1YN0l9FAXCMvFJ oH9Qjv0ZYdkoHWvWvBbmmZrzAo2AHs/u0BwLfrrXSv6d/FySZzSDZ0GTZ kgEDTYj90XiSXDYl+GPtnaBlFaiA8fhalwtYAUd5VIxMzF49QsbhXmCqC D8ET1seuMTWV/KIxi7ES+Jt/7dyRoC2kxM0IYqocsKQutSPKDL//7OJ+Z g==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880540" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:21 +0800 IronPort-SDR: 7qSSh5MhhCZxxtW+INF+/N4HSe6/r7AYZv8DCPtXK6WBhzmKmpSgxl4UYtRS7k7kKCHeMw+l70 220QKnHVTDR6xt7n3UXAnx4wvoP7/NdYJ/7EPEYd6n2X/q8OaHUMdoSYwuBmfUWjwgHEVqxtY0 tfdBi9bndwd6+mzHK0X7/2/sRKz76Q8fxb8z09mWEMRa2rAeYUvqgPbzqbWlDoMNgkNZNnq8ZV ZrDBbw5zL79KDa7xYbyJPWKP6sZDI4YnNV2w40g59EJojeS22NINvgK6EXr0uK43fuXp+ju4d8 7Rk= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:18 -0800 IronPort-SDR: qznXmorHrEcYnq9G/u4YAS1f0TUfwOXxGLoFzBAEut0to1qbA6BWcRfLbFyV4c8W2N10VmEUHc MVnKw5E0LFeh7bgoiZ7vX/J65vDX/MUYvANiO/kpVba+rpQKkb/fir9uO08mNMeQtvqwjqxLiQ nsZQeEJyr3o6FzIRNyIc8nP0+r8jKjSHfONvXXai6Kw33QsqFFypdcgna2eaa1/BZfKScaG5Xa gxKaHXhaJtPgqhS/h1ryT5Jzkr6VDcDSRT0VHODBiEq7CqVe1avWxrG/EpAaQV4PHReuY30c0N zbo= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:22 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmZ10z5tz1Rwrq for ; Wed, 8 Mar 2023 01:03:21 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266200; x=1680858201; bh=83skHeTyuuHUEsf609 nh/HewU5bhrZRbY23BMMXBCaI=; b=ZkPhC2UAiigjAK5HUKy8KAmVYpCG6S8rYU rVvfW9mEOA9ZwiPVUWJLUQkP2PAM9T7Xpl2CVhH9/tmyoj/k/AY17JcbHL3wnvRS wU4rlauF7NzpKZPwMXIj1oLCmRPA9zwep2KQ1XyJW9IIP2BDMkVOBXEtFaveyDs/ /Q28gxFymCPSMxp+35eF/YkQKmRUoGypNPl4FJRy2+HigD5kDxcZUobRAOWC1m4h OjzaGaBFpGJ/A7VKmo4iKb0qS1jO56YHOTFmKx63rO8EefYPPTAQ6HJeEn1baWDU U+e/emI4L+zXijJOWmZ3QsZ6mRqtLYH6bvz86zfp/R1JOSCxlbVQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id REhxR2V6Wj7U for ; Wed, 8 Mar 2023 01:03:20 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmYy4ZLjz1RvLy; Wed, 8 Mar 2023 01:03:18 -0800 (PST) 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 v2 02/16] PCI: endpoint: Move pci_epf_type_add_cfs() code Date: Wed, 8 Mar 2023 18:02:59 +0900 Message-Id: <20230308090313.1653-3-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org pci_epf_type_add_cfs() is called only from pci_ep_cfs_add_type_group() in drivers/pci/endpoint/pci-ep-cfs.c, so there is no need to export this function and we can move its code from pci-epf-core.c to pci-ep-cfs.c as a static function. Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/pci-ep-cfs.c | 20 ++++++++++++++++++ drivers/pci/endpoint/pci-epf-core.c | 32 ----------------------------- include/linux/pci-epf.h | 2 -- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/drivers/pci/endpoint/pci-ep-cfs.c b/drivers/pci/endpoint/pci-ep-cfs.c index b16fc6093c20..3a05e9b5a4e9 100644 --- a/drivers/pci/endpoint/pci-ep-cfs.c +++ b/drivers/pci/endpoint/pci-ep-cfs.c @@ -509,6 +509,26 @@ static const struct config_item_type pci_epf_type = { .ct_owner = THIS_MODULE, }; +static struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf, + struct config_group *group) +{ + struct config_group *epf_type_group; + + if (!epf->driver) { + dev_err(&epf->dev, "epf device not bound to driver\n"); + return NULL; + } + + if (!epf->driver->ops->add_cfs) + return NULL; + + mutex_lock(&epf->lock); + epf_type_group = epf->driver->ops->add_cfs(epf, group); + mutex_unlock(&epf->lock); + + return epf_type_group; +} + static void pci_ep_cfs_add_type_group(struct pci_epf_group *epf_group) { struct config_group *group; diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 2036e38be093..355a6f56fcea 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -20,38 +20,6 @@ static DEFINE_MUTEX(pci_epf_mutex); static struct bus_type pci_epf_bus_type; static const struct device_type pci_epf_type; -/** - * pci_epf_type_add_cfs() - Help function drivers to expose function specific - * attributes in configfs - * @epf: the EPF device that has to be configured using configfs - * @group: the parent configfs group (corresponding to entries in - * pci_epf_device_id) - * - * Invoke to expose function specific attributes in configfs. If the function - * driver does not have anything to expose (attributes configured by user), - * return NULL. - */ -struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf, - struct config_group *group) -{ - struct config_group *epf_type_group; - - if (!epf->driver) { - dev_err(&epf->dev, "epf device not bound to driver\n"); - return NULL; - } - - if (!epf->driver->ops->add_cfs) - return NULL; - - mutex_lock(&epf->lock); - epf_type_group = epf->driver->ops->add_cfs(epf, group); - mutex_unlock(&epf->lock); - - return epf_type_group; -} -EXPORT_SYMBOL_GPL(pci_epf_type_add_cfs); - /** * pci_epf_unbind() - Notify the function driver that the binding between the * EPF device and EPC device has been lost diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index a215dc8ce693..b8441db2fa52 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -214,8 +214,6 @@ void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar, enum pci_epc_interface_type type); int pci_epf_bind(struct pci_epf *epf); void pci_epf_unbind(struct pci_epf *epf); -struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf, - struct config_group *group); int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf); void pci_epf_remove_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf); #endif /* __LINUX_PCI_EPF_H */ From patchwork Wed Mar 8 09:03:00 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: 13165470 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 B8014C64EC4 for ; Wed, 8 Mar 2023 09:04:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229889AbjCHJEa (ORCPT ); Wed, 8 Mar 2023 04:04:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbjCHJE1 (ORCPT ); Wed, 8 Mar 2023 04:04:27 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B28D28237 for ; Wed, 8 Mar 2023 01:04:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266251; x=1709802251; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VGNqT1k82z7drWFYM5NgfNIaHrg6B+xRVIL+gTOAs7Y=; b=Ha2dRCoTvbJQhjgq5Q7e8tf7p5tN74F/EyaA00KPZFEtPPoe/LdeTBjf wDPvdFDh5oXbw9hKHDfVVtSZBUQJw/KdFsVsFH4RafvSrxrBMfa/Gn/Os Jk2vM/O55FkW4EALeLfJ9PdixWYZqVQGIdld/lHwj0cmgi5WnmV2weskZ u+RGBoC9iKNNWKA6flNWmzAQYbxpwFKt2chTTaNfP9wCo6qnm4Sk7p0cT tK07VrvglHOnr5VQePhFK2WFbWnUFpoMwsi22Y+0wgZqYE+HdqRj4/EVL WgpiTTAi9Dr/m3b60dMVRtJSZmlO9ABVT6iDKfoGFlPxxeFSKleB2pfrZ A==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880543" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:23 +0800 IronPort-SDR: ZL9goySBlCp6NkZEFdBaUqvgOgx6k9fdjc2ZLIb5T8rNgvoUPjSPUO41GEQpHZV5HXv6HzIBwy 6RO3rw2uvY41cMt50yuUWzhhUScwqaY9BDLYQa2U+Mzn/LbmmpWYLNxFmDyLRQmWLGW7s6tdYZ 3ogT1eKUU8/DQ0qp8o334to15572ipRxIWyFGyOqHAshCvaL0XYD19j9E5qKtvAvgCulRuJMUb bkGt1XeqelO25xWfCMo7yyr6ODv+5Kcbmn5WkaqrGgdj8bWKG/Cm6553gFoduAdqIrXv5HyAnG eus= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:20 -0800 IronPort-SDR: PczpF6iinySX+lN+9n6UUqU7qJeccX7nDMfPr2eODp5KUu0O0sCRHD1fzKo0hhqJIOcePXWa31 uY6dkbyeDFnVLntK+H1zzZ9PDO1iyaHD/PATBNvl1VINKxNYkbgwwBpSnmA3N3eg7PZlkZ/G+x NOYZc6PITGhjuNsQzeSKl41uYYui+MmCuMMvR8gAc0j/WY9Q7ZCcqKUJ0Ig333dLL8LrPo1+b/ co1RpWf8OdN6uIldL3tISZmx4AGAcFXesJ87OzC7nNX42VL2DsTu1WXVrE3JALHJC0ed/SDZCk 9BY= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:24 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmZ265j9z1RwvL for ; Wed, 8 Mar 2023 01:03:22 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266202; x=1680858203; bh=VGNqT1k82z7drWFYM5 NgfNIaHrg6B+xRVIL+gTOAs7Y=; b=HStkEYa0KcVnhGDvp6rC+q8zJAqu+L8khH hbfTm9Pd/Ycu7xgTN8dAUN0inwYzcXBPGaB/zeXH6zeZKdM4Mr+B5DsgrtJfRFGN MlCMyl1QCETtQ4Rym4PYxV9APFbCIyJxEX7XghWeBUvtU63A2LkP888GfVv+aqAg hHBRwJhKf5W0bomiJVdBkZfKLQ/wGW0j/bmmtYIg6ehSi0yQ/o6yjOUYCoQFiYb5 8OkEpt4G/8de9DxpG2pb8PBnQru1eG8ydvAQI6xO5W1+ufOD6SZSAPgcsLp87IYP l27nU6LRktLoPM1i6awaJt1azWhEtpGTDZgg+V9u+h+0sm7om0iQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id uc-hptn-PAiX for ; Wed, 8 Mar 2023 01:03:22 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmZ04SXQz1RvTp; Wed, 8 Mar 2023 01:03:20 -0800 (PST) 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 v2 03/16] PCI: epf-test: Fix DMA transfer completion initialization Date: Wed, 8 Mar 2023 18:03:00 +0900 Message-Id: <20230308090313.1653-4-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Re-initialize the transfer_complete DMA transfer completion before calling tx_submit(), to avoid seeing the DMA transfer complete before the completion is initialized, thus potentially losing the completion notification. Fixes: 8353813c88ef ("PCI: endpoint: Enable DMA tests for endpoints with DMA capabilities") 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 Wed Mar 8 09:03:01 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: 13165472 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 E3730C742A7 for ; Wed, 8 Mar 2023 09:04:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230161AbjCHJEd (ORCPT ); Wed, 8 Mar 2023 04:04:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229767AbjCHJE1 (ORCPT ); Wed, 8 Mar 2023 04:04:27 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E1E23B0E9 for ; Wed, 8 Mar 2023 01:04:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266258; x=1709802258; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pgP6j3ThKHkldq+XHZBPzJ6mOm42AtjAZKYFIlZCE9A=; b=J8GY1q1tsG5yn3oKOGkT6UkmOxOQD610KZmie5z7vT0RrO7bcM3TMcwa 7wrNdPRJa5/nNbmvwEz7O+DlnlscczsEfGnb9SG+vyqKoTfkecC7KsHOT nws6yQVcBRVvF3iWRArY3P7oczKnTJ7IM1zUqrfqvySyrRtdKdiPandSm WYYbRWNvXC/6zUTBgdKXl+f59syr1vS07/CnLoIMrLqP8xTRec0pPGIrR lZDAJksJzJ0NmdEVMfskZidpOWQHyrbYIQj7o/yzhXyvHo9M/zplzFzA3 lbtz2mEqDc9MEF2VONewIwRQ5QbleM8ir1D4Fckv3pY9sywtwlqGd4IzL Q==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880546" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:24 +0800 IronPort-SDR: BwqgS020vtocrFfLC/a79P9J4zJ0cnyt0DrRwPKxJ8h5fvEP76Oa+qs+Rh55qHyYbvzdQujP2/ OTVTQH60Ran5oqr6mK5dq6jOHOzuTgMcWp8BYXNlZqHjXIpOyYOJ9vtFCjt4ELPaXhkHMakV9e 8IbXZNIeYPUnI/IqdmlLJXupUFVT1JOTKIpkqTnB/gAAAwzpq/miu+CW8U7UUeyGh/fwor/+uO RNnUpSBmQptVKtWlsWjsCci3JJumYR+K+CJeH7M4Ya0YTUHsavCYmVsrQwn7EbYvzCQ77spjys fTk= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:22 -0800 IronPort-SDR: LJk4S+PZTJ8pokWRz1wMfrTGLgWdo2BkZRCgpFzTXfhi0OLrXcL/UqQ9XOxN4LjttCt8HKDZBH QExkPwx3KzQhrbs7IhYndSBYSw56pQJ5s+V9hHVNmlAb5hr8ZfQE/7suN/6unETjSZUfkKBLt0 ePRxdJXWcM6+ZTDgcD5kPB6lmyd7/+a7YQKyU28hJU+EZZJAFPuftComRRxRFV65vo4YApdhyx MDASmaoUjkWLySOVB2HsbBDefZWp85ITuDt/Wwb4CTr/0RNqCnR+AHCDTRijNOxeothZ3+KaI3 tSU= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:26 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmZ45XqHz1RwvT for ; Wed, 8 Mar 2023 01:03:24 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266203; x=1680858204; bh=pgP6j3ThKHkldq+XHZ BPzJ6mOm42AtjAZKYFIlZCE9A=; b=OZcPfqD6otk00vf4bF3gaw9yUsOGIuJTJI l56PCnv1YjUpopmVr0CIyZdkU58r9xZhdoVxug5KCkZt8UEaWxhRcFVorM/HbPm5 vU2JED00/5J2NYOju1mmQXanvItUdEWPLkngEqNn4em7OsVmAf6xi8E+q6TNxld0 r6TIM+nuMWJLanNHNLueb6R0rFddLhBw65d2YGeatPbAV74+8QLZjxU/65azC928 pbgNnxmWGobUW6u0IjMK896AXlCCK4Sj38gM5y/Zr8YDFY3798l7lqn/k1o7GZ8K iuxg5Vi5C/vo+7/eE+/NX636zTF9BZtE/mPPlDa523WuEP57rY3Q== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id NLO9OmUV5oAi for ; Wed, 8 Mar 2023 01:03:23 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmZ235lVz1RvLy; Wed, 8 Mar 2023 01:03:22 -0800 (PST) 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 v2 04/16] PCI: epf-test: Fix DMA transfer completion detection Date: Wed, 8 Mar 2023 18:03:01 +0900 Message-Id: <20230308090313.1653-5-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org pci_epf_test_data_transfer() and pci_epf_test_dma_callback() are not handling DMA transfer completion correctly, leading to completion notifications to the RP side that are too early. This problem can be detected when the RP 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") Signed-off-by: Damien Le Moal --- drivers/pci/endpoint/functions/pci-epf-test.c | 40 ++++++++++++++----- 1 file changed, 29 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..557fbb91c729 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,35 @@ 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; + } + + WARN_ON(epf_test->transfer_status != DMA_COMPLETE); + +terminate: + dmaengine_terminate_sync(chan); + + return ret; } struct epf_dma_filter { From patchwork Wed Mar 8 09:03:02 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: 13165471 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 DC076C678D5 for ; Wed, 8 Mar 2023 09:04:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230170AbjCHJEb (ORCPT ); Wed, 8 Mar 2023 04:04:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbjCHJE1 (ORCPT ); Wed, 8 Mar 2023 04:04:27 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E50142BFC for ; Wed, 8 Mar 2023 01:04:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266258; x=1709802258; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s5gDd/B2Yq1tEK5yBf6Y6lCpaU94/+jEDozwfQvzxWI=; b=LRFhf2YB8lMAQTVJJdyZozCRcvI5/+qtn4dCZNcYO4nMV4uesuOgS9xy kDFtY35jcKh6zrqGVOmI21q8YT7oavY8fqR63keFwFL9lp/SVzoaEQF3R RvLOseM7432jKCdLwGc4GEow4hfckOeQwipY1Qo5BTeZsxysUSEhD6cXH CBKW/RAwV+HH3W/fi0EaQEVg2iihWydripMPa7Zi8YcZV7WBi50cXORPk FJBHC6Ps6bjJJEGrPpKvDbjOeMcUcODVXljwnWyRAq+YN0GaAiO7v3Msd Ju3hO/EFKR7jUImKtKqcy+OsCfnaECcEyH8QVqlVOHocMae7NNxDifJTB Q==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880549" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:26 +0800 IronPort-SDR: sVh2xhd+aeg6JvbJEmVtezTYWlb+oHh990b6WD7tXsR1MI/ntksHspGHmUxUk9BF5XF/ykkSvJ 22DeWxCgwFB5DKlXhFcp+jYCVxteVdcQbSzYMilkENr8ODKN0x5yS7P5fOHFxrNvH92SQL2JHe pww/rvhOqXhPNtMs7DjIkA69ihe+O0IpR+0FHfhvSvT1wVQ35/slqL31vISOGjUyYNytDYaNyU JqfO/QhY3udO/jj/FfHwsSiAlirBxBT7Je1FK639b6EM1KTe9myY/5gbZ/ih3hgbCUI8/0DUFM Ixc= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:23 -0800 IronPort-SDR: HXfdFrh9Y3qhtIBz5tkrDtR6//Hb91oUmG038HA6uA1JC586ktjWcsGKloKr6phj+Ea30s0mL4 NKefYRkURTZijedipGUzLzaUkYbf9jV1TTU3Aq+WHn54FNSrdVQ5SOM9Mbqt1Dq5NLZ3v2mM13 ggX+nFdGZriSSx+slwZl5sCoK7JAP6mtNZiqko9Hfsrg6FxRWi2fKuW/Nzic/pmAJcg7yk9WJp Xg6bGo3/6xlIj7KM3WZR3G8M2bZegJyQWsiQaEkuNQ0LzKyteHkNboW3CSDrcHH73ag0Wd080b IX8= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:27 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmZ623b3z1Rwtm for ; Wed, 8 Mar 2023 01:03:26 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266205; x=1680858206; bh=s5gDd/B2Yq1tEK5yBf 6Y6lCpaU94/+jEDozwfQvzxWI=; b=NFwk+cOJUi7drX904Q1UIP+jqsU8vEU4ix WNvmM4M2EkxP1Q0K35Wki1exbrT7RpjWJUeSr0sEGwgF4d0FSLC0hgfXhIwPoyN0 tfgoPfewUw9AC0BhDg4oGmiJx0IA3+gzcKtAQY7UvEHfuOJh3sTjUHLwXIQNWlZ3 6dfvcNqyu3ImDP6Gs4jC7uZtV6pbEgffZJySBXIPxiXFNmeqtoz+uPc1VackVkRU giIJBhlqnfSy87P4SB64gOSyqzQPoCrenPu4h781I8cuMj6iw71+87SbLuS92yhk xFyNwAh4kVhKCpg6wDTmQYbn2zXitBWapzZfrT+e/Ko1tpgGHvdw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 61eLRHYxaIh1 for ; Wed, 8 Mar 2023 01:03:25 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmZ41JNLz1RvTp; Wed, 8 Mar 2023 01:03:23 -0800 (PST) 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 v2 05/16] PCI: epf-test: Use dmaengine_submit() to initiate DMA transfer Date: Wed, 8 Mar 2023 18:03:02 +0900 Message-Id: <20230308090313.1653-6-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Instead of an open coded call to the tx_submit() operation of struct dma_async_tx_descriptor, use the helper function dmaengine_submit(). No functional change is introduced with this. 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 557fbb91c729..3dce9827bd2a 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 Wed Mar 8 09:03:03 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: 13165474 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 E2C75C678D5 for ; Wed, 8 Mar 2023 09:04:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230051AbjCHJEi (ORCPT ); Wed, 8 Mar 2023 04:04:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230183AbjCHJEc (ORCPT ); Wed, 8 Mar 2023 04:04:32 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65DDA12BD9 for ; Wed, 8 Mar 2023 01:04:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266267; x=1709802267; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=axABW2wroxclMYood3Xo6NYAibU+vC4k1ymAe31QsQo=; b=alnMzTy2UEXotOtNOJ4wU+lwh7gY+CfdwbNX5AGRv6Y8JD4z7UxWqdV7 dJvFb87gbu9XPAf0B8E0BDwBb2DZxanI1kahSNSHIs8G6nL6lzt/jJBby Wg/4QLnsJXbKoHB3teT9W1VsCc0wFUS/u37CFm4U61SNyvlXP9g8jy83+ HDkCYZqvlayOLe78pQ9Lfhc19I6q1qb30nFTEzw2i6A4qMeAX2uzt5jFw OsA70198FD/Iob6It0t5qDkGRD5z1EyBwhHiwaXwAhVawLIs8NlCYhcJW 2IVzP4Qb1YkWS34ZAsFfog5/T5rx1WYVgnQY18+3uT25tTlLoNwWXCXky Q==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880553" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:28 +0800 IronPort-SDR: Heev435MYclUB+F34DfEN3zXCjHnRXKzq/9hPHkBHn1op22fIgTZhwEYy93OQxKpuif2C5Tzh6 oV4O8lG1RwfxZZiAqHIWYmwg5yxGJOIl6ZmVSFl1jQZaq6jzGmgKdc978e8xPTrcLSPe5cc4lt 4bznmdMMQ3/v2wutPtRliTyxvyWwLKDSwZGnyAppVIVstqk14RujF1w/aeVkFzaav8o5z77aeX scLTLPuSxAzWFJARRpsdznbESR8rtqrmZGE3uHsrZlKBI9AX61afHcZwKlvL8Njnqhzb+wmufx kxA= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:25 -0800 IronPort-SDR: /ziJwRfRNPQt1vEl9yS5eqSL8JSspTu0amGT9rUTB1oi5s6LH09RMpF6wmME47HqfiTtCq29b5 LL15pquUtDlllFVSXd1GG26Zh6yExh5R3Tca+9BUhG+CoGqErwUuDVxWhLusVJvsfXY4/Lcprp UjVSVsB3cXGSi/2PvBzJRYXBmOIJow3udHOGS6z3TktYKxXLvLpk8DcGnllxN2KdLNe/uW2U79 DbaY3WzVHlATZ0/FIEAMDHDh+FDlWSM8+/1UEaPFQ+IZrOzS0BnmG8bpv8tlqVGqh8o/ZC/NJl AVk= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:29 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmZ82t5lz1RwvL for ; Wed, 8 Mar 2023 01:03:28 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266207; x=1680858208; bh=axABW2wroxclMYood3 Xo6NYAibU+vC4k1ymAe31QsQo=; b=Vd72WMh+KAdkt8feiACbPMtI+Z+ra2cKi5 2PMR3//ny7r29Hy+Hw/3afq+VFAH6RzamblBhNbcOWI+xutcjuWSDsRHwrssbixz /glcXOUkOqL5bXYp8ZT58d6WC2+cPvjwDSFAHnA29UczRGeI8HVN2xgyfxl3t2nh 7WG13AJ00Uf81Ov0gNwhctZzdr3EghB4ipK6/I7FmmiAl6q6Bm+J3uiIDtg8Lmy/ Ko4D5Oo9myr7Wn1flpy9bGvRmo3+QQlqGM4OdeBMrt2Dt2uCSlHdEAnGJfvcH6kL HGMhojR6/S0CkgoD5Es0q7+wHTdV88ZQXIEfz8QxUyesipty5aqQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id WIx3_vRH4jUj for ; Wed, 8 Mar 2023 01:03:27 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmZ60Sjcz1RvLy; Wed, 8 Mar 2023 01:03:25 -0800 (PST) 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 v2 06/16] PCI: epf-test: Simplify read/write/copy test functions Date: Wed, 8 Mar 2023 18:03:03 +0900 Message-Id: <20230308090313.1653-7-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The function pci_epf_test_cmd_handler() casts the register bar to a struct pci_epf_test_reg to determine the command sent by the host and execute the test function accordingly. So there is no need for doing this cast again in each of the read, write and copy test functions. We can simply pass the reg pointer as an argument to the functions pci_epf_test_write(), pci_epf_test_read() and pci_epf_test_copy(). 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 3dce9827bd2a..1fc245d79a8e 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -327,7 +327,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; @@ -339,8 +340,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) { @@ -426,7 +425,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; @@ -440,8 +440,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) { @@ -516,7 +514,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; @@ -529,8 +528,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) { @@ -675,7 +672,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 @@ -686,7 +683,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 @@ -697,7 +694,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 Wed Mar 8 09:03:04 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: 13165475 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 BD786C74A44 for ; Wed, 8 Mar 2023 09:04:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230317AbjCHJEj (ORCPT ); Wed, 8 Mar 2023 04:04:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230187AbjCHJEc (ORCPT ); Wed, 8 Mar 2023 04:04:32 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A54602CC40 for ; Wed, 8 Mar 2023 01:04:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266267; x=1709802267; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=638WqZK8FgjF4CUXeYsyIP0jDJjPgD/t0ydHPdvUXp8=; b=DnNnKRiJjRTIi8W74KJogpfkyB6Ohin5I0XTI4Dkh8g7MVcVu6xIdt8A 7O7pDzUGCoE4tQ17cfCpNv+YF8nw2Jw9uenKSRgUzP4gbR0tRjXf4/DOJ b/AWTf+0FC8YZHdagWS4iRWjDmchwReLbIrsOGJhSPKAYlMuuRFdiBTfu BlrFL8UMopEs7MMF9sZhJEXGzp7OnXay+xRa0RspKJWelLE17+IEr+INS ZUcbRy3NXdeQLxjDaoebaUx9BATuq6UIf2BveoBmUUi1DaPLTxbkA6XrF X+I8K71t6yjSqQTTmOAsoWN+qqzYzeILzwVf/M4GIgBR7x1fOV7uHT5KY w==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880555" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:30 +0800 IronPort-SDR: ZjjaT7ZYro8MwX+88/alwuM5aLOWXWdT5GC919RXV1tqmf/rFHdVvbnCt2pQGayrUaAKP8GMbK wKHN2rISAmp8Kl4rwf58AlIHLgG65p2pSosezS5u9BguM129O8+shlU+erjllJmMhsGF9QPWxp 3UgWqEEakoQ/agUQFbYCD/xA88jiAGmtSQY/j4ww73CF8qfht5F2c52wNnAYIQd/3oEdqlV1a1 gjbpOONPilZErwdCd27m/MEkClkr2ZbLolJtqmWE3fSIodDBa3iuiJ1odQuLm8xmrZHUKgWDzH 3rg= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:27 -0800 IronPort-SDR: abzDq5aGUpSpeS1c6Pa6w+qyr9Y2/ZnJL2DIbtx0Or7vqzO6m2utsBjN3cOeuJWr+LhM5UBygF RIVi8B4HMDzwXItoU2/klTjSKvSsYZNXTc1G+1UdU4XcN1TemDXjxP3qpM0NwACILwQis55bbx VpQyruZySqgpAa36/ATO9z9yqn81voNfskW/rCELfpexJZ2vPXlgGMFhWK4h8fb2fumsIXqi8a gNU2iYYyd+5Ier4+RW0mrXKbCHbCdRv0B+VHbD+eIWZdPjahdBleKtUJTXrkRlyOus+eNErmDR psQ= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:31 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmZB0dF0z1RwvL for ; Wed, 8 Mar 2023 01:03:30 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266209; x=1680858210; bh=638WqZK8FgjF4CUXeY syIP0jDJjPgD/t0ydHPdvUXp8=; b=kOTavP7PnpaDpcbHPruSLqGSKGeDlRG74n eOqP/v75TssGQel256JObWptD5uWkMLeiDW6gWfWmG4PYqCzjrKdhBZ3xveHN7wG jg7jw0KwnWDouaqABCp1tx+ph7OKk22naHuwNzv7FTE2t85aUASVW8CCR67UHDa/ Xg9JS9gwlV6KNWGqAVY9FiDVAYg6ZeYYBveXNE2iKxbCUkMj7rM4KvAS7BEOY+Nj hzPwaQ4cLQOdQgPoim5+BV0eqxXl6lj9ihocp2r/rln75yn0TfEYBxuLFkEcm2Vu xvJvARITuFyHKoanDgNqbKxhlH+KwSo4aJuo/3i4Rq0XSRgLDPJg== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id OzJtKNdo46GU for ; Wed, 8 Mar 2023 01:03:29 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmZ762Dpz1RvTp; Wed, 8 Mar 2023 01:03:27 -0800 (PST) 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 v2 07/16] PCI: epf-test: Simply pci_epf_test_raise_irq() Date: Wed, 8 Mar 2023 18:03:04 +0900 Message-Id: <20230308090313.1653-8-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Change the interface of the function pci_epf_test_raise_irq() to directly pass a pointer to the struct pci_epf_test_reg defining the test being executed. This avoids the need for grabbing this pointer with a cast of the register bar and simplifies the call sites as the irq type and irq numbers do not have to be passed as arguments. 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 1fc245d79a8e..6f4ef5251452 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -609,29 +609,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"); @@ -677,8 +675,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; } @@ -688,8 +685,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; } @@ -699,8 +695,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 Wed Mar 8 09:03:05 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: 13165473 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 9746CC6FD1F for ; Wed, 8 Mar 2023 09:04:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230295AbjCHJEg (ORCPT ); Wed, 8 Mar 2023 04:04:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbjCHJEc (ORCPT ); Wed, 8 Mar 2023 04:04:32 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C82CB13DD3 for ; Wed, 8 Mar 2023 01:04:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266267; x=1709802267; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fRrs/340bIvCq/+Ph+3JgCm2ZB+BGr+A5wzPz1zbALc=; b=OoGQBym/+oMsffsQTgAHrPvmCV4KDc6RZ57MXePHH5J4FnbAvDLKHdwT MkYpwXRL+Zy2h8mDwBWG7oWsJyc2mDSYqSkYiXDutakF30d8wAk/DIQ27 NnEWg4Vh5quZZe1QGulFOJ+g4SkJJTxzrfhPNuvdlhzPurmiVkxYHp3we ZpACC+qWlv42nesUc/HUvLlKbZonELN+tSzXr/czRFFf0bznaqoaZPQJQ zjW8YNxwPu/crq+KZCDRv4iH5g9JjGVZhRiONzwL9e6AXGG1bt2QovDch CPDeZCLhWvHGiZLpOWo2EDRyHOFmVUCUvLX4ABEw41WpCtBQ1L3C0WEKN A==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880561" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:32 +0800 IronPort-SDR: jPqAhkaJRSWnTCapLbCw8wk55UDCemJIHknk78p5xE/ULmEa4CvFkPVWUhN9vktTodMgGhDArr iPXhSsaZ2yqePuGsYOPl0r9NJt8SHRHm1MT/J5CxWx94JkC8EHMJUFPrhU96PXRTBLffIg4ZOZ e78HGv7rGIHNQ8ZFI2vvAvTj8G1baAhYBD/Imm1kKikeq7/zB2F4B3oidC3hzGQzqi7AUABGBB 4C4oqysKLncSJTywpqTS9O3KCvJZLIv/1ZZWhMNTqWVwRKt6cfHn6V5usbtEaNyALvsVidBAoS ap0= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:29 -0800 IronPort-SDR: QC3TpMyI/W/Pe8/cbX8QVeKXoQNBNlYc8sbawRDxTf339giMLGskFD1MvkereqT9O2H2rMfDQy 9kPXbQHqwVMaHINZYwWUQ5Wk/SM1+RHdWCAGrTDzTVat0wd3AYqRzntz72/3E0DFEw85n/roqV FgjtHtC2LLM5OYeqzSRYHBG7qZVnttf/ewbEwq1w+wIQh4JQfMBL72ztIvxNiQrwEXF67cp9E1 ofiPJ9bP4Q5E2NdG/73JIa+2A4v2jPpx6Nq+gjWSKEbKipsp5gQmuQGWB366KNMSMGpcy7tZ4B aX4= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:33 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmZD1Xqqz1Rwtl for ; Wed, 8 Mar 2023 01:03:32 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266211; x=1680858212; bh=fRrs/340bIvCq/+Ph+ 3JgCm2ZB+BGr+A5wzPz1zbALc=; b=LLDOb8s2b++pJl0bnRKn+tF68bwafaFH2B g2cYOQw45lwDb+usErfnkYgbNLrDwza0oTI0mbVBzDDwQKP4Iv1ui83Arxkw4Qiw LZwxpF9+dpGKSNLob6i7eUvqTjHWyp4Xqu3LkHr8m3mBhOfihkR9k9OZ/NiHeDKb i5XETXWPCZyE8pjxl6c1z2+dN9f+ljXuuzYljSH8RRQypc+6tn4qCO7fpOSyoq8R 6SH8CXmLHy6rdmHHUJWrmtqQaQiqu4r32b+CuYpknRd2uKvuL2nFBwd8+a+eQpMx rLD2Jh7jp/9uxU5WM5m32HQx58bawZ+rrw2UxUfKZSD9np50qeIQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id xs_yrhurhnjG for ; Wed, 8 Mar 2023 01:03:31 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmZ95dgHz1RvLy; Wed, 8 Mar 2023 01:03:29 -0800 (PST) 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 v2 08/16] PCI: epf-test: Simplify IRQ test commands execution Date: Wed, 8 Mar 2023 18:03:05 +0900 Message-Id: <20230308090313.1653-9-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org For the commands COMMAND_RAISE_LEGACY_IRQ, COMMAND_RAISE_MSI_IRQ and COMMAND_RAISE_MSIX_IRQ, the function pci_epf_test_cmd_handler() sets the STATUS_IRQ_RAISED status flag and calls the epc function pci_epc_raise_irq() directly. However, this is also exactly what the pci_epf_test_raise_irq() function does. Avoid duplicating these operations by directly using pci_epf_test_raise_irq() for the IRQ test commands. It is OK to do so as the host side endpoint test driver always set the correct irq type for the IRQ test commands. At the same time, the irq number check done for the COMMAND_RAISE_MSI_IRQ and COMMAND_RAISE_MSIX_IRQ commands can also be moved to pci_epf_test_raise_irq() to also check the IRQ number requested by the host for other test commands. Overall, this significantly simplifies the pci_epf_test_cmd_handler() function. 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 6f4ef5251452..43d623682850 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -615,6 +615,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; @@ -624,10 +625,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; @@ -640,13 +653,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]; @@ -662,10 +673,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; } @@ -699,26 +710,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 Wed Mar 8 09:03:06 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: 13165476 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 3E526C678D5 for ; Wed, 8 Mar 2023 09:04:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230061AbjCHJEq (ORCPT ); Wed, 8 Mar 2023 04:04:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230208AbjCHJEf (ORCPT ); Wed, 8 Mar 2023 04:04:35 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CE8A2BF0F for ; Wed, 8 Mar 2023 01:04:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266271; x=1709802271; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fn+76CMFq1pO5tJWIXTlXSR3vcfIIGSz5Meag7dwkN8=; b=f8w302tSbeFSF8pwO9E1DFsIN7/hr8BuFrUoqWTfv9rTZuXIOKfXK4Yy +yToHsDKtjWrtBACjnfp8+uKzszrfEQJa9jJJTCgkJrvPlN2s1jP/7lpq tEwW+36LzGOBFEgWIlNLk7d0i0GLRg8fViUl0YrU9N974wC1soXyMCsIm wCEScoJ3L0wBDA5dEmTaOZ220bEy91/kXDfWPp2kRtGfcDyTNV8IjDA/m RD+hlwHzdxrrzEDz4sXES9bBHjkIAbWYIxXbZU2QkHpjpFH73F0GAk3/y QIhCja97DigS8wu/QGnBYRgLz9zUt6Lq1C4oFhX3iizClMpDbmtXko6eu w==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880563" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:33 +0800 IronPort-SDR: ye8UXIKBuOeepX+XzukCJpfwc0Qb+n4Yo1Kg4EkMjEVOf95aSMkjCygaIhiD3u42d65jtTBbqZ mJVttToRdm+79zcBha3998xIssnfIR3I4T1BxPonPFwXpG1dGWCi25fNYveFAW9TOqfPLilx0U p5qcGBDvwJvBNi97qGhMPb+SEbOeQ64WzYXeBv/bNrNu+0jtvzlIaeOjzVbeKQnLrxwig3Q6Rm 7bD82rSDuKGSRq15URAOVgniw1mhZM479nxHECs+G9wPcW6Ec7lfw/IIBf1yrX8CgiMhi5IiCg wCc= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:31 -0800 IronPort-SDR: FzWXxXzjZGjIv+2Si8o1/qkkXCRXLoMK/v+DSdpzVxr8wAl+D8Pbig7Xr57YYhLrUMqk7IOwbh OTBUbxpYytcdZmrzXccxJZyz/DzQ8pcN+iNRjZ6BUiT2iPFfWPH+zgpAN2rvh9JHpdbuMD7g/H MwqUICUTjok9CjE7AbTzf5p6UQPuMvL0HLwiKW+KEmJ+suc2vaD/omLrnhd3MtBuh2pwfXU2TN nc/Q3UBRvO2Q2Dj1XT6Xd/pKiiAYiZlIn7gwDMiNLorEz8fNrZPsFipFZhNC2gWFLxKKf6UPW7 ydc= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:35 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmZF5nXGz1RwtC for ; Wed, 8 Mar 2023 01:03:33 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266213; x=1680858214; bh=fn+76CMFq1pO5tJWIX TlXSR3vcfIIGSz5Meag7dwkN8=; b=MiXmWqCppG5gCmfPQq0bRMH8UEE3qMKsLl 2vefZQP3qojSoOtdsMg3exvyNrQbeJRJPYIxTm0MKilrMaNJ9XL05HhW0uCJox8P k56+Q6ZwwCcEqjQsImcmJYDqSS9P3wyMw0V5/7ltkWZx8O62L8JDt5PNPzvYgb+0 QF4dEdlnerWxBgChbtF3phEb6D4pyHsQsARawees2JBerBzB57ejwOBRh0pN1iYJ Wzu7Ivhbs1ss3sAvMOVHebE5udf5LT0B2pLo28MAihPCTIqVD619Yi7k+8DqXhF5 pIl/zbKqlZK2H9NRCXf5FJI3cbwkJO9ETYyMXy0WPq1Fiy8ru38g== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id G-no83OBx68T for ; Wed, 8 Mar 2023 01:03:33 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmZC3J6fz1RvTp; Wed, 8 Mar 2023 01:03:31 -0800 (PST) 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 v2 09/16] PCI: epf-test: Improve handling of command and status registers Date: Wed, 8 Mar 2023 18:03:06 +0900 Message-Id: <20230308090313.1653-10-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The pci-epf-test driver uses the test register bar memory directly to get and execute a test registers set by the RC side and defined using a struct pci_epf_test_reg. This direct use relies on a casts of the register bar to get a pointer to a struct pci_epf_test_reg to execute the test case and sending back the test result through the status field of struct pci_epf_test_reg. In practice, the status field is always updated before an interrupt is raised in pci_epf_test_raise_irq(), to ensure that the RC side sees the updated status when receiving the interrupts. However, such cast-based direct access does not ensure that changes to the status register make it to memory, and so visible to the host, before an interrupt is raised, thus potentially resulting in the RC host not seeing the correct status result for a test. Avoid this potential problem by using READ_ONCE()/WRITE_ONCE() when accessing the command and status fields of a pci_epf_test_reg structure. This ensure that a test start (pci_epf_test_cmd_handler() function) and completion (with the function pci_epf_test_raise_irq()) achive a correct synchronization with the host side mmio register accesses. 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 43d623682850..e0cf8c2bf6db 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -615,9 +615,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: @@ -661,12 +666,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 Wed Mar 8 09:03:07 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: 13165477 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 E7B04C678D5 for ; Wed, 8 Mar 2023 09:05:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229929AbjCHJEt (ORCPT ); Wed, 8 Mar 2023 04:04:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230299AbjCHJEh (ORCPT ); Wed, 8 Mar 2023 04:04:37 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 840793609E for ; Wed, 8 Mar 2023 01:04:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266272; x=1709802272; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YIUrKj8Ou8+6NLVJQAB+2QGq2T8Z8NPAgdYDNBm9+Kg=; b=ikYlJGnairq5xZIhnlSSKzQA8T7SJVAw8AV/8idtKujnM5GSxCiOIlMJ dUiFZ/6gH69DF+97WUJ21mrM4ZCeJNPLTPMICCwJbCfVbxze8vnJlyLuu 8uArZ7YE028a1J6FgTI7TDM5/qZatCV692+5rQ7vY5erwiIBQW5vRTiDr UrROJ7pwXXXxZu+WqWV2UzPyfgy6vQqnTKwbd3RCLWL9AsnygwmIv8GFd QcKPO/2P58MilulWEekKb3VYq9Jm1P42niJsbsmf4+sXGF8YPrZeaH8a5 cgo2nyLX5vI69jHzOGCZXoK0RpsosOlcVXRTmogLpNNMRjZ/JKNqEfO/F Q==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880565" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:35 +0800 IronPort-SDR: 2uSFk838ho2n4aJ8duWN8uauMdwzLHzII1WifcB0gfLrKb/FKsxGF//y3TYh9m5ZPuPiOZGKxm 8fO0L2W0SP+huVcjs/vaNgSFBEYRfRc67oBfuBG3FFnp/YpqDAR1AV8iyTqdbQ6GSi9mcPu9s6 I1MfZE1aRKOY6rZGuXYxUvp2qj7a4U1cYnm7IJDhSILOBiqk9E9hKKitmjZv/iUR5Bcsb9gXVz 3ocmKbWSPLCsdx8iGcmutixlkG6xGLYVZrSasP1RrxmIDO/jO7r14lrhXiZphkZeUV+6ISKfxV QcE= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:32 -0800 IronPort-SDR: JkUCtK4q2o7m5bMWw8AF1i/keiGXa/JnZeXWiH2Tw0V7bFy2hIFpNfO7Sm4b6Fz63qxWFFtlws 8vk0ySr/N1nOahssghAO9QIAL2tByo8dYNSbZPPJ//zFqO9Np5RmVl7+j1pKaKCMCq+5S/ZuWw p2d7pKFaHta6qgsM7zGpIBqY+COqlBQ50umHSjmzQtJ6X0VliiKuybve9MZWbKZwXQnH+oyxFU FyOZSB1WLzRYJJMmY6YbP2S/D1Lh7YyD+tGXV7YKcbdYOxODMznjGt3otP5sGFGgTXRMRSjX7T hnA= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:37 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmZH3KDtz1RwtC for ; Wed, 8 Mar 2023 01:03:35 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266214; x=1680858215; bh=YIUrKj8Ou8+6NLVJQA B+2QGq2T8Z8NPAgdYDNBm9+Kg=; b=UUNG9TfLEGtVSh6u5lqiehBcjf52zG99Lp IQnJLTlDTmpDj9kEQMJMXYxvHl57TduGgRQ75afY/1nQf/XDODbqrkuDq2JBZbCs GAUeQ7JXYsN7dVuiNlU1KSioLs0AZqoYlnnV8tJf5PX/6tCOWVJMST3wJyNhwI30 Ta8Fz/F6H9XiIRaGS15sxJPvYu7zkfxbQEbl/pHJxPJlwBrGaLbXGLQlaHV3GKmv QO6lDK5PiYWMFidvDs74h/PEWjfZRJHNhv9mdIpm+UI7MGWW4i5RbujqJPaSGZae GBEx7nk2ocLr3d4mo+PEbqkxgBFNIZojefV5zw66RGqocTE7FbzQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id VaoLX2bXjxIB for ; Wed, 8 Mar 2023 01:03:34 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmZF2Jrfz1RvLy; Wed, 8 Mar 2023 01:03:33 -0800 (PST) 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 v2 10/16] PCI: epf-test: Cleanup pci_epf_test_cmd_handler() Date: Wed, 8 Mar 2023 18:03:07 +0900 Message-Id: <20230308090313.1653-11-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Command codes are never combined together as flags into a single value. Thus we can replace the series of "if" tests in pci_epf_test_cmd_handler() with a cleaner switch-case statement. This also allows checking that we got a valid command and print an error message if we did not. 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 e0cf8c2bf6db..d1b5441391fb 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -678,41 +678,39 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) goto reset_handler; } - if ((command & COMMAND_RAISE_LEGACY_IRQ) || - (command & COMMAND_RAISE_MSI_IRQ) || - (command & COMMAND_RAISE_MSIX_IRQ)) { + switch (command) { + case COMMAND_RAISE_LEGACY_IRQ: + case COMMAND_RAISE_MSI_IRQ: + case COMMAND_RAISE_MSIX_IRQ: pci_epf_test_raise_irq(epf_test, reg); - goto reset_handler; - } - - if (command & COMMAND_WRITE) { + break; + case COMMAND_WRITE: ret = pci_epf_test_write(epf_test, reg); if (ret) reg->status |= STATUS_WRITE_FAIL; else reg->status |= STATUS_WRITE_SUCCESS; pci_epf_test_raise_irq(epf_test, reg); - goto reset_handler; - } - - if (command & COMMAND_READ) { + break; + case COMMAND_READ: ret = pci_epf_test_read(epf_test, reg); if (!ret) reg->status |= STATUS_READ_SUCCESS; else reg->status |= STATUS_READ_FAIL; pci_epf_test_raise_irq(epf_test, reg); - goto reset_handler; - } - - if (command & COMMAND_COPY) { + break; + case COMMAND_COPY: ret = pci_epf_test_copy(epf_test, reg); if (!ret) reg->status |= STATUS_COPY_SUCCESS; else reg->status |= STATUS_COPY_FAIL; pci_epf_test_raise_irq(epf_test, reg); - goto reset_handler; + break; + default: + dev_err(dev, "Invalid command\n"); + break; } reset_handler: From patchwork Wed Mar 8 09:03:08 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: 13165478 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 F136BC64EC4 for ; Wed, 8 Mar 2023 09:05:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229629AbjCHJFE (ORCPT ); Wed, 8 Mar 2023 04:05:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230311AbjCHJEh (ORCPT ); Wed, 8 Mar 2023 04:04:37 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B63FBBA6 for ; Wed, 8 Mar 2023 01:04:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266273; x=1709802273; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RAJsnh9eMj1J3xd5auGSvxnCGfbqyyD8ow/+wuTkITM=; b=Nx0HM6C59v+CPYDH1PvAUGvpvho/BmyYl4xM0LJNZEAd/9LLE8vsCCQS ZC3HyzB6Wv/9zfLzs8O3fZY2aVzIOLSZWgiA9q1VldMcPmei8JaX+0lqo jqwBnhckPecFDVKdfA3f5HgGmrxA/8ZZT0hd6wvQPlbJ2cEfnqz2nItBr edEVZMnx58vyaKSnpjE/NnhhlZtwEKUq8wisO78fCRd1l/o0jEWSK+J6i BUjCMx9oupn2Dc7gxc2ct9aXyve6LKPADPeAQK4oQb5NhAJ6BtsVffXhU sdr+ORkjL6s+gZ+k79bptIYtc4I3HpTbDNQEFDWCYPg/Y5at4OvOCXst4 w==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880567" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:37 +0800 IronPort-SDR: 8oPLnCTIJYncq4QLBt6peOalE6Fol4BRmXIyxjO90+2Oi3dSfEGiIyMe7xF1uNkMAkH+Ugxcjg /Gh0m5M6gK6//D/TpYZOeu/3mMmnnvUMv9SKv4SI/ZKZTazapXQC7sK8yNvv0mOtt3K70yoVLm B8uQuG6lkb397+xz5EdEmmdcZzm+t48ZDSPGZepiR52m7ppFTWVYe8TO0F+Yn5qGaVR6W5QyyB mDG2IuhgE4xof0PfPYB33YG5FBs6I4wijpJ+SfRj+Pth7xL4vcXzZyYh0aEBwBF01jWq38kQ0k /fw= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:35 -0800 IronPort-SDR: m1Sb9YuEboVbWBaI3WbjETGf660jBQx9c/rQK1za4v+H0cJ4io8IYgiRlh2i9FYNUIm4fV9pOd HdcSv/vYP8sMLhVOPVp2rYE33Dx92iJTZWdw+gyaoGwLEKyUDeyR2KZ4TAm053CcBxGM4ldho+ ZIkxSiArh89AdvMmiQDLRSJz80h51ULm6lDmKYIMbpaeipCQmCWtX3jD9qL/nowJA8DGVJa//5 85+3Fm64LKKQmx/mndy2tWhUFVaVD6vZ1R96USY1XDLttsXEGswRyHwJTDnjdculXXH5xB5D6E zYU= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:39 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmZK4Gncz1RwvT for ; Wed, 8 Mar 2023 01:03:37 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266216; x=1680858217; bh=RAJsnh9eMj1J3xd5au GSvxnCGfbqyyD8ow/+wuTkITM=; b=SySrlM0ktmdVjV93HwqToEewWpSAgEyMe2 J1TeQpIGNEa7sIgG8TcVqHZZrqDB/+SXDgotawK7K7QaUtBqAUNm4nv+PSyc2kX0 WUuHvz0ZQpQuDy45HNyi3iLq3oxxncz2+ABnr4elqOzqkj3vX77gu/Avo4uuuiHw R/UZBwumF86AuufyE6qCVcb/9f1UX4Oxf68cKrvUNUv+vakoptMwstFZnp0GzB6M a4W8yaPhRJzEcjp0/I7vAsNscD5rOTp4+R0xDzy+pCD5wHC6vyHMhZwKY51olncL wMooCDNxzZ/XUsMHU6deaev5p/ZLViv8VJVtJwQgkcxRjtvd9Zqw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id JiSncpuGOzRR for ; Wed, 8 Mar 2023 01:03:36 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmZH1mRjz1RvTp; Wed, 8 Mar 2023 01:03:34 -0800 (PST) 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 v2 11/16] PCI: epf-test: Simplify dma support checks Date: Wed, 8 Mar 2023 18:03:08 +0900 Message-Id: <20230308090313.1653-12-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org There is no need to have each read, write and copy test functions check for the FLAG_USE_DMA flag against the dma support status indicated by epf_test->dma_supported. Move this test to the command handler function pci_epf_test_cmd_handler() to check once for all cases. 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 d1b5441391fb..eaa252a170a2 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -331,7 +331,6 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test, struct pci_epf_test_reg *reg) { int ret; - bool use_dma; void __iomem *src_addr; void __iomem *dst_addr; phys_addr_t src_phys_addr; @@ -374,14 +373,7 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test, } ktime_get_ts64(&start); - use_dma = !!(reg->flags & FLAG_USE_DMA); - if (use_dma) { - if (!epf_test->dma_supported) { - dev_err(dev, "Cannot transfer data using DMA\n"); - ret = -EINVAL; - goto err_map_addr; - } - + if (reg->flags & FLAG_USE_DMA) { if (epf_test->dma_private) { dev_err(dev, "Cannot transfer data using DMA\n"); ret = -EINVAL; @@ -407,7 +399,8 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test, kfree(buf); } ktime_get_ts64(&end); - pci_epf_test_print_rate("COPY", reg->size, &start, &end, use_dma); + pci_epf_test_print_rate("COPY", reg->size, &start, &end, + reg->flags & FLAG_USE_DMA); err_map_addr: pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, dst_phys_addr); @@ -432,7 +425,6 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test, void __iomem *src_addr; void *buf; u32 crc32; - bool use_dma; phys_addr_t phys_addr; phys_addr_t dst_phys_addr; struct timespec64 start, end; @@ -463,14 +455,7 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test, goto err_map_addr; } - use_dma = !!(reg->flags & FLAG_USE_DMA); - if (use_dma) { - if (!epf_test->dma_supported) { - dev_err(dev, "Cannot transfer data using DMA\n"); - ret = -EINVAL; - goto err_dma_map; - } - + if (reg->flags & FLAG_USE_DMA) { dst_phys_addr = dma_map_single(dma_dev, buf, reg->size, DMA_FROM_DEVICE); if (dma_mapping_error(dma_dev, dst_phys_addr)) { @@ -495,7 +480,8 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test, ktime_get_ts64(&end); } - pci_epf_test_print_rate("READ", reg->size, &start, &end, use_dma); + pci_epf_test_print_rate("READ", reg->size, &start, &end, + reg->flags & FLAG_USE_DMA); crc32 = crc32_le(~0, buf, reg->size); if (crc32 != reg->checksum) @@ -520,7 +506,6 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test, int ret; void __iomem *dst_addr; void *buf; - bool use_dma; phys_addr_t phys_addr; phys_addr_t src_phys_addr; struct timespec64 start, end; @@ -554,14 +539,7 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test, get_random_bytes(buf, reg->size); reg->checksum = crc32_le(~0, buf, reg->size); - use_dma = !!(reg->flags & FLAG_USE_DMA); - if (use_dma) { - if (!epf_test->dma_supported) { - dev_err(dev, "Cannot transfer data using DMA\n"); - ret = -EINVAL; - goto err_dma_map; - } - + if (reg->flags & FLAG_USE_DMA) { src_phys_addr = dma_map_single(dma_dev, buf, reg->size, DMA_TO_DEVICE); if (dma_mapping_error(dma_dev, src_phys_addr)) { @@ -588,7 +566,8 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test, ktime_get_ts64(&end); } - pci_epf_test_print_rate("WRITE", reg->size, &start, &end, use_dma); + pci_epf_test_print_rate("WRITE", reg->size, &start, &end, + reg->flags & FLAG_USE_DMA); /* * wait 1ms inorder for the write to complete. Without this delay L3 @@ -673,6 +652,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 Wed Mar 8 09:03:09 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: 13165479 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 C8F8EC6FD1F for ; Wed, 8 Mar 2023 09:05:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229725AbjCHJFF (ORCPT ); Wed, 8 Mar 2023 04:05:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230117AbjCHJEk (ORCPT ); Wed, 8 Mar 2023 04:04:40 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E878799D4B for ; Wed, 8 Mar 2023 01:04:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266275; x=1709802275; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1v6zSkVcces00UqmQZtB9XTYzrL0xxc030Wi2sVS0DQ=; b=f7kmSYs3ANLvF/NxbfPwXEPB67cuVNwdNBZ3ETcpSxTiS+LPI6MnEeWM 5Xrkl97EemmxrTnwHpGhDyhUC9+4f+/F609nA6GWDB4bECv8RP/sZCjnM iHshqXSG0TCXuZJzwLK8WPirbyDHaqMoidVUJ02/ucK9wF2Ru0MXjzyWx svXEYVDCowdWpn5aYdIm0Yp5y+3cfMCpF3T5zoVIdrRQzbh9A99ZWx+fl Tjn1YrHxTRR9GV3d6TlwnHYswoFbjBsYsHSu0HidSJ6CtrYjLOlddeh89 RWN6h4/hEwsTRmKvQ3dACKOgg2DyrAzQtFL9rDpEiSj1RJDFswsl7ptNz w==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880571" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:39 +0800 IronPort-SDR: XU9Tjm0DJ6ccFjLULdd3hMW3DVZFseCSwMHkWJ/RYmqJSNfz+094ZiOoq40mdDUjoGldqGX8Eh EDthZZnVuaf1zE4ubTW/cTwHBr5c5hmboOQupQS8wGv0aEDyhz2/m8xDIwjCvZZMxfgiKTxcrh EYPXDW/PQ0dfJcFyXcvoTFPGF6M1XAp85qm1kEvXlr5HMqLTXdRH4tlMJmlHB08FKJfMS6YvAM 3ducUdBYb4eiWLX5Vq/JrweS38aPjZQF0wCimBYFtAwqqJsaKFCbfn+g1y1WcGy2cs7qmd9/wE 5Fk= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:37 -0800 IronPort-SDR: DYE7OnMNvGBQ7CGiJdOgDOS2Yblrx90xofcHKgS4II5OksWtBRoAE7QvWAaNGWFEIrQbblhJOM yAHCI3MKuawVFV4I83Hcq2KPCzlYPMMG/SPoLS71mMVMc58oH6WKw7hsc2rO8jnb4c9HSIXMCn 5q+fEqYbHz9iPe+znz9hMQpSyM9rY3hQ3DaG6a3XkfERH2U/QatLJRIF7gX+WEUK1IGv22farM mRpgMtfSZQNqT9o4ozn3JxeiUu0oFqC+nLpNzO2ENUMhbPD7hVCLZwll+ko5s0daQmc4O1vtFO O/Q= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:41 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmZM39cdz1RwvL for ; Wed, 8 Mar 2023 01:03:39 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266218; x=1680858219; bh=1v6zSkVcces00UqmQZ tB9XTYzrL0xxc030Wi2sVS0DQ=; b=FOixOZfTFZMWo7HFbErO5qghkz9rcNsyA9 WehFef2oYnXRHak2aNImKSDhC5f3BX44m+RhB1Ou6oWiS9iow8qX2VNPtphBsgLc 16Kw99Snlji3118wYj8DE46twa37okvuDBVV5fioGh8zW3dRLEexqzPPD5fkOB/C fvoSGZ9o5vIddnZkbP9eJbT2oX2lAZMhimR4Z+K2Av3mSvX8LeknXIjWfDJTlU3l bGQIhLWseujF/EsRFq9CbP8MB/rTIgfsIhfHB6/yl8dZmwImMglImJDVAJapAsP0 zIx4lqTXWyLv7lCIxY6nRGHHtlpoR1RTqT7GV54cvW2su352BAhQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ksoNDZuMg8wR for ; Wed, 8 Mar 2023 01:03:38 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmZJ6tlFz1RvLy; Wed, 8 Mar 2023 01:03:36 -0800 (PST) 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 v2 12/16] PCI: epf-test: Simplify transfers result print Date: Wed, 8 Mar 2023 18:03:09 +0900 Message-Id: <20230308090313.1653-13-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In pci_epf_test_print_rate(), instead of open coding a reduction loop to allow for a division by a 32-bits ns value, simply use div64_u64() to calculate the transfer rate. To match the printed unit of KB/s, this calculation divides the rate by 1000 instead of 1024 (that would be KiB/s unit). The format of the results printed by pci_epf_test_print_rate() is also changed to be more compact without the double new line. dev_info() is used instead of pr_info(). 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 eaa252a170a2..9021c4acc743 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -297,34 +297,23 @@ static void pci_epf_test_clean_dma_chan(struct pci_epf_test *epf_test) return; } -static void pci_epf_test_print_rate(const char *ops, u64 size, +static void pci_epf_test_print_rate(struct pci_epf_test *epf_test, + const char *op, u64 size, struct timespec64 *start, struct timespec64 *end, bool dma) { - struct timespec64 ts; - u64 rate, ns; - - ts = timespec64_sub(*end, *start); - - /* convert both size (stored in 'rate') and time in terms of 'ns' */ - ns = timespec64_to_ns(&ts); - rate = size * NSEC_PER_SEC; - - /* Divide both size (stored in 'rate') and ns by a common factor */ - while (ns > UINT_MAX) { - rate >>= 1; - ns >>= 1; - } - - if (!ns) - return; + struct timespec64 ts = timespec64_sub(*end, *start); + u64 rate = 0, ns; /* calculate the rate */ - do_div(rate, (uint32_t)ns); + ns = timespec64_to_ns(&ts); + if (ns) + rate = div64_u64(size * NSEC_PER_SEC, ns * 1000); - pr_info("\n%s => Size: %llu bytes\t DMA: %s\t Time: %llu.%09u seconds\t" - "Rate: %llu KB/s\n", ops, size, dma ? "YES" : "NO", - (u64)ts.tv_sec, (u32)ts.tv_nsec, rate / 1024); + dev_info(&epf_test->epf->dev, + "%s => Size: %llu B, DMA: %s, Time: %llu.%09u s, Rate: %llu KB/s\n", + op, size, dma ? "YES" : "NO", + (u64)ts.tv_sec, (u32)ts.tv_nsec, rate); } static int pci_epf_test_copy(struct pci_epf_test *epf_test, @@ -399,7 +388,7 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test, kfree(buf); } ktime_get_ts64(&end); - pci_epf_test_print_rate("COPY", reg->size, &start, &end, + pci_epf_test_print_rate(epf_test, "COPY", reg->size, &start, &end, reg->flags & FLAG_USE_DMA); err_map_addr: @@ -480,7 +469,7 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test, ktime_get_ts64(&end); } - pci_epf_test_print_rate("READ", reg->size, &start, &end, + pci_epf_test_print_rate(epf_test, "READ", reg->size, &start, &end, reg->flags & FLAG_USE_DMA); crc32 = crc32_le(~0, buf, reg->size); @@ -566,7 +555,7 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test, ktime_get_ts64(&end); } - pci_epf_test_print_rate("WRITE", reg->size, &start, &end, + pci_epf_test_print_rate(epf_test, "WRITE", reg->size, &start, &end, reg->flags & FLAG_USE_DMA); /* From patchwork Wed Mar 8 09:03:10 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: 13165480 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 4F77DC74A44 for ; Wed, 8 Mar 2023 09:05:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229727AbjCHJFH (ORCPT ); Wed, 8 Mar 2023 04:05:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230344AbjCHJEm (ORCPT ); Wed, 8 Mar 2023 04:04:42 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 469B3BB for ; Wed, 8 Mar 2023 01:04:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266277; x=1709802277; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c6fb/ATpu4bjomFurbyO/sIS4IvcEwK34bItru+sYXM=; b=DeHxM8oEp8m4zkWj3/+nopJYm7Ah1i3iY5psvmOMrsa/9KHFLUfi3RBv eZWCPp5kHWIpXcLLAlNVZAm9SdHYVr4c0aTddX9xRDYHs1l00Upzk5cz1 QVSBiPWnIHvRHQafYnNwzoPffKnTNumH1ijS/UCimhgo3QiwBAGvsWlt0 0qVxc5GgUKKovDEwve1p5fyjM+M5Wnx9UYo9lKWYOvR+21aITW0pTSK7/ UWbdNUPq4O++3O7W/W+GZyGT1FkLtJJxKAN8p1X3TRkJ0d3h97kVg6uq+ 7JqTiF+kN7PSPgZZdRStfJTt1/5fGndxFv4iLo+A8Um8Vx3u/Vlrz12JG g==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880577" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:41 +0800 IronPort-SDR: n/zPGuPZF6uOBklpYlL8B625G5xjH8n1IOivPdZsjbIyomxm6fRnL37sAMTR4YJpL9bou1tSyq 4XMgjDkMp4YVo/Qa2/27LkUorUflyTUEp49nEzl+dTMED41qk7ZS0spA958c+0URy+T0rN//Kk le3+di6BTcli/dRkrBdjsWLWMM2oVOHAwRCkcW6yX9zFNu4Qp0/kzGwX8t+fYFnVlalnv12vtb RhCJbQ0ySwvIoE8ZlBhIWlLyUDxC5uzkN6IAMiBVrSuhQ9GwHGj9e6efSUHHmJLpxl69rU4XGu /xw= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:38 -0800 IronPort-SDR: si2Y5ICgJk/S6ThnQWDxssv69IuZGfrYaaXx9lpOjsHvFlbrcE28N6gqyvoWVFxBclXXuP0DAf EJbA153GkaYmmFpXlwUQUo+fNcC9YP4Va5umlLrHvlp1y5X5wFkdOmdeABuedaar+aTOY/W30W 23JEjziTbCYovo1DuElRz3IV/rFNtr4fS25G1s1/9NhSm0MtzEDbJpfpWVy8olz+qi/8yVr8v6 44E5rTSkB0CO7Qgc/RumhYCxzZbM9fgqy1uRGFuqr/RFCZHc9jPsji7LOSAXKquEyOTV/eshCQ q1o= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:42 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmZP0fN4z1RwtC for ; Wed, 8 Mar 2023 01:03:41 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266220; x=1680858221; bh=c6fb/ATpu4bjomFurb yO/sIS4IvcEwK34bItru+sYXM=; b=SD5Y+A2QNAkZwql1A0LGUSLq1xuMzvwUBq 8r6LTW7eHVhnjTOjzn5MXnN4fiRDDXaSgYlzoRZTScpJIs0gMjgUkyO3eSOQGLZS vYppmLkAWaysWUT3Mrjgo423BOhwSdH6NOeMZAF9VyFd/P4tTNnKa3xqMlElPyNr +bFBz3EcjeiyLWtpsmvLoUL4Y0auTLAhbvioHh2gnrZkSUp4LSd4ZOH0bdGUO5rx p52qX2aJGDkvNppZV//N2R2L45uvoN/Fm2BefVMDv6W1KLglKyLHRnlzmdzw83Eb hZPTNSwEk5hcNOwggWJCJHE9zo9Oiv4eSvwzi/r4/cponOkWxO6g== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id fRL7czUNH1sl for ; Wed, 8 Mar 2023 01:03:40 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmZL6sqFz1RvTp; Wed, 8 Mar 2023 01:03:38 -0800 (PST) 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 v2 13/16] misc: pci_endpoint_test: Free IRQs before removing the device Date: Wed, 8 Mar 2023 18:03:10 +0900 Message-Id: <20230308090313.1653-14-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In pci_endpoint_test_remove(), freeing the IRQs after removing the device creates a small race window for IRQs to be received with the test device memory already released, causing the IRQ handler to access invalid memory, resulting in an oops. Free the device IRQs before removing the device to avoid this issue. Fixes: e03327122e2c ("pci_endpoint_test: Add 2 ioctl commands") Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/misc/pci_endpoint_test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index a7244de081ec..01235236e9bc 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -938,6 +938,9 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev) if (id < 0) return; + pci_endpoint_test_release_irq(test); + pci_endpoint_test_free_irq_vectors(test); + misc_deregister(&test->miscdev); kfree(misc_device->name); kfree(test->name); @@ -947,9 +950,6 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev) pci_iounmap(pdev, test->bar[bar]); } - pci_endpoint_test_release_irq(test); - pci_endpoint_test_free_irq_vectors(test); - pci_release_regions(pdev); pci_disable_device(pdev); } From patchwork Wed Mar 8 09:03:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13165481 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 9956FC678D5 for ; Wed, 8 Mar 2023 09:05:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229646AbjCHJFG (ORCPT ); Wed, 8 Mar 2023 04:05:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230325AbjCHJEm (ORCPT ); Wed, 8 Mar 2023 04:04:42 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AF21133 for ; Wed, 8 Mar 2023 01:04:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266277; x=1709802277; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9hc8RCCLWTxRBYC9gxcz8ZAIDPbMiGNQupCTpkbGyu0=; b=YuqG4vAuTtp7Q1zuTsaSW7onlrqCwGUfNKRrPNsud1o8e3X3ld383JpJ Pxuo9bVS85iE3iMV1LwDHSFI6diUpFQAmYWcKBYe/j92zJ5ehZSSrlPAI elIiJQi7LL3/QbjUnIYHSsdRVYyBj+1XcO4KXMXVPgKgkEdB80hOsBbdf 1DsT0IkR1H7n2hojUB1dxV7dFJWrlIB5ZFu5dLkhNRmQST3hpWVTufZ4M FS2pcN3mfSNcoz36RVDZnRequCqzXsTSsDtkPc1fFQpTvNxU6ZG2QcBVa abM6uD74BCQsrx7Eeqq6i7rCGFbaFDtcFujmonjKKscsHe3CtASWz7nQT Q==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880581" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:43 +0800 IronPort-SDR: oAEKaXXGxgKWJtDaJCq/S7TSwv/LBmP6ZdNOjKMEMAUVi8Cj+BYuC/Ma/JkIb68TsLClmaMe3j MdF0td2bxVjW5oHBQYrsS1uFvSbuc4xdujRmdvwYHfdCi/jcRoVSEMFTF0aUbRAQTuN7IkWZmC tS5zBS4p5HlFVyhwXq8cKa6F/7v2hRja++74l+EHqC9EZNzNgzUMN0llk9sbEKiVRBm0+Jztwa ijmctqzNtZP7cLOeg4NjEb7rOdq3+vIPyN7HeoUvxJ3dp0f/QOSMc7yQJ/oOCTqiiyN3jgF0Qy rak= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:40 -0800 IronPort-SDR: w6h6vFbn1opjfUSeS+qNgd19ZFSG27fcST0otiZ/nvKJMCpxYqcc9ctsfufq6aFI2tAenwhVt4 3dP8buYs0XwOZfRoLydT1FVvZyIqwx7WRXRINlUH6TQ12xWnPRfqGbo5boVyx7vMZa52FqZ6dS YwGjT+OoIw2Fkk0Nu2wjdilwssct8yEZC8C/LeWI1IYX4+Dq/BmrQleFt2PcmsSEOBDqambmf6 wyw7QgfAwYM/bAU8D6/gG8mR+2nRGWU7jOryomfcHoVmZILoeo+QCUSL+F+bZFVtDh0+Z48fXz CRk= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:44 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmZQ5pZZz1Rwtl for ; Wed, 8 Mar 2023 01:03:42 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266222; x=1680858223; bh=9hc8RCCLWTxRBYC9gx cz8ZAIDPbMiGNQupCTpkbGyu0=; b=GGESRD8ykAEIZy+v+8YqSlvBylNUrtmITc YSabG2OqH3rYaoPONCLhns7HMfdKkdz6got+mW6XkbdiXbCm/W8XoOPrJELaNwfM v4rSGV1N/1/siFAUDQLezfWt2NJ6obTLv1I3HMrFTNca2stUm0M2KBRpFyeKIZGw 7I+iiZRLyoKo5bRRD04TWSkiYNsonUynV7aSt7AQuOm1jn46qT7F74esRBTLbgIZ 3RUzp3Ze1s/t6yNHgL2wzlSK4KycwDTBEwUwcO1mI4yHPpp+b+FIb1W62YE0iuW9 Q0mQbXFDwzvDU+GGE4YWjH4jdmvi5X6eOITYMRacpLb8eJe4Vc4g== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id nVpX_4eoLj3w for ; Wed, 8 Mar 2023 01:03:42 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmZN611Zz1RvLy; Wed, 8 Mar 2023 01:03:40 -0800 (PST) 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 v2 14/16] misc: pci_endpoint_test: Re-init completion for every test Date: Wed, 8 Mar 2023 18:03:11 +0900 Message-Id: <20230308090313.1653-15-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The irq_raised completion used to detect the end of a test case is initialized when the test device is probed, but never reinitialized again before a test case. As a result, the irq_raised completion synchronization is effective only for the first ioctl test case executed. Any subsequent call to wait_for_completion() by another ioctl() call will immediately return, potentially too early, leading to false positive failures. Fix this by reinitializing the irq_raised completion before starting a new ioctl() test command. Fixes: 2c156ac71c6b ("misc: Add host side PCI driver for PCI test function device") Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/misc/pci_endpoint_test.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 01235236e9bc..24efe3b88a1f 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -729,6 +729,10 @@ static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, struct pci_dev *pdev = test->pdev; mutex_lock(&test->mutex); + + reinit_completion(&test->irq_raised); + test->last_irq = -ENODATA; + switch (cmd) { case PCITEST_BAR: bar = arg; From patchwork Wed Mar 8 09:03:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13165483 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 1D69BC64EC4 for ; Wed, 8 Mar 2023 09:05:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229690AbjCHJFH (ORCPT ); Wed, 8 Mar 2023 04:05:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230208AbjCHJEr (ORCPT ); Wed, 8 Mar 2023 04:04:47 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F30E09AFDB for ; Wed, 8 Mar 2023 01:04:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266279; x=1709802279; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nNNBPPwx3BeLf51ftFKDBjdeNrqS7hVotbLqERxh9VU=; b=OXCTEIDIj0yxNgsqmX2qALt3gut0ylG3QPYtTFH5vjq3rchdBPe2zu7n kz0mwd4p7pSJoKCPZkSFkPhAgLWviE8NLzXBR991Mf90AMUxTOmG8AQ8R VgSXBykYuFmM6u99UxNGUf/CN9TuNS7MnBt9saYBhg2esw8EyGCVNoAz8 YWAdOCXfB9CYGPOzOcH9iRZy9Hc3lk+ShGj5Rmrjh68CpEqaeNxSsOnlI Weqb4NZ0fuwMjmTH8w17jOKYNLWoLrVsurrnH1wbC4ZXOPDlzVClPRykL y4rlZ33x95fDQBeKFgNLBBCRMIqHNxYX7G3BWwkSePl/N/BE55/S/giDv w==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880582" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:44 +0800 IronPort-SDR: 9LreVowlPPKXM7oevq8PCTVeEZHywabT9v9IWbVrMFCdvkUbIn4CenrVVOvLbzyqymqf7z92cX PjHvWkqj9cU7iKvBTT8HfsPnvBRIrXihwnorGGRgYTpZK7NGPGeXknGHlurhsUY/eqHvgH59EM wq0mS4ALGkjciHtDefhB97W59aWoDNdPvHaDe4xOh1WliJTrhxdbhR/tFsMGmf7fXUwM5MNsXP TlXvS3EY/PgKvS3qBkTKM2xXN5WQxStpy3XR1+QmL6eUkWHvFJyfwBFR2DCamI574NPP+VlcMe TvU= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:42 -0800 IronPort-SDR: nxQtXTc4CZi90YVwTnMS3nMoT+caqqYgtWkzkQhRdqcEfLfV9C8M4G9HDyZWt2ZriIeK40vZxy kgb5iahCaEiSuA5mkQ6e4zUj8z5Is3A19rhNmdHqteX0ZLnetJaTrUJusXDVjZFbDedUFC3pOr JmyHQYZ7WuIEiPQtX/fm384qeuW0d5YKRYFKczMo3kPWf8slkMi/6fLOB8krovoC3UaJ0TiEJJ DUe0BwSU5H4r0A/hKsXz6G6gbMcIDIQFwY9xiNmuMIfDvLjdrHgw1RJRAagGlagNCeoKdhjkVL eZk= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:46 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmZS4Szcz1RwqL for ; Wed, 8 Mar 2023 01:03:44 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266224; x=1680858225; bh=nNNBPPwx3BeLf51ftF KDBjdeNrqS7hVotbLqERxh9VU=; b=TGPl+6/vUwxSaiJMCycHS0F6ymENj01AhH RUbLECRmf+BJLlWb7eCZV7o63Pud21vULUyXSEs651hptZmsmv2yJxRJgbTC0tmv 4Apni0r0dOI2PYCTY8esP/+3D+Lo8yZf1j45vszI8NcP+kKtXoisDNPX/zR7pGsK W7LjvySxdv6bc9nYj9LsyQoLZSUu9WlWMeBirzZT3kaEoO12wWAiumjWyq3FEO9W toSSWQfR/NTxwe8ccgHHMg0MHS2bPasrX9FldCluCq3qFZSVAHvgxo3P1BCsPssg 0VVR/ofTV5qwqO9RuebIAdBSKAlaodw6sOMDhsRwIHRgZiIpnWVw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id YUAHgLgvA0D2 for ; Wed, 8 Mar 2023 01:03:44 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmZQ4Sy9z1RvTp; Wed, 8 Mar 2023 01:03:42 -0800 (PST) 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 v2 15/16] misc: pci_endpoint_test: Do not write status in IRQ handler Date: Wed, 8 Mar 2023 18:03:12 +0900 Message-Id: <20230308090313.1653-16-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org pci_endpoint_test_irqhandler() always rewrites the status register when an IRQ is raised, either as-is if STATUS_IRQ_RAISED is not set, or with STATUS_IRQ_RAISED cleared if that flag is set. The first case creates a race window with the endpoint side, meaning that the host side test driver may end up reading what it just wrote, thus loosing the real status as set by the endpoint side before raising the next interrupt. This can prevent detecting that the STATUS_IRQ_RAISED flag was set by the endpoint. Remove this race window by not clearing the STATUS_IRQ_RAISED status flag and not rewriting that register for every IRQ received. Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/misc/pci_endpoint_test.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 24efe3b88a1f..afd2577261f8 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -159,10 +159,7 @@ static irqreturn_t pci_endpoint_test_irqhandler(int irq, void *dev_id) if (reg & STATUS_IRQ_RAISED) { test->last_irq = irq; complete(&test->irq_raised); - reg &= ~STATUS_IRQ_RAISED; } - pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_STATUS, - reg); return IRQ_HANDLED; } From patchwork Wed Mar 8 09:03:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13165482 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 C3574C6FD1F for ; Wed, 8 Mar 2023 09:05:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229880AbjCHJFI (ORCPT ); Wed, 8 Mar 2023 04:05:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230395AbjCHJEy (ORCPT ); Wed, 8 Mar 2023 04:04:54 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE6053585 for ; Wed, 8 Mar 2023 01:04:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1678266282; x=1709802282; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p+MxxNmS9DVwNUcLA55VvIMV4ImTHL2q/nFJco681WM=; b=YK0pU2A8FFrLiv3jumXhrJ4eRRhtRNKci1tldnyBthpghNoUwDZE112o KONWP03ifIkgKgCCir4omAqw1CBhiOf4bnSVod8bxxmsnwrKQzg61vy9s d5xjUz37idp8nswGkv/Ug218T/55BeA598kvCLJV9iozjr6bT35EaSAP8 8aywpJCGhloH/ewrjZ9kO1OlMtz8CRWMKLRlx2qKwZomYWjz3qSoF1Spa m37sEi5WngqMTW1p8BRetFXG6eKtiS1WWaa44HvL1MvAfNVTjRYU8M3rO gi7eLUwra0xR7lnM3VqfS6LwBul4IZ7bCaMXBtdtEKDSjHTBLaSOEIs1A w==; X-IronPort-AV: E=Sophos;i="5.98,243,1673884800"; d="scan'208";a="224880586" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2023 17:03:46 +0800 IronPort-SDR: ZgoFqAACgxbFgp8aLME0Qeh29UPNq+RSqnrQc57cuqLStV/xCIxuoJpd1y3ygu8DkEiYj88qVD 6FeKUpAayoPhrmeVji5VJ6iwJfpSX8HtBYn5Ym+uP1rQyCe2kImZpN3d98Na4gr9kKfsYxB6zw w+a+TvRtYZjsrNQnfhjpzrskZ2PWhc2NSvOopMIMpDamvoeTb6uaeUSAxzDf77jkNWjuEPTMT6 0FPb5Y9Q2tR7AoVsq8sHP3pfzpZARE6bgnst0CzR0WNZG3Z8nOiTCbQkmy9YQR5j5jxBR+6+9w P6s= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 00:14:43 -0800 IronPort-SDR: P+scogfpD+55Ot0WLx7z7xQgtDEihu+tZIo7I2CCuEQ+WXd1XrwEMkGDv25IHoy11MxgeO+dZ/ xSlUKdBh5CoOplExCgbu95kumjxY1uDx3SRmLKVluqaxL/3bwEz5Kkc0Wpjntv+HNB/tsMsVXj 7Cbnmq7e3Sn7lZZu4gPsYIyKp1Th+oZebeoLDfUWac5Ra1nUS4U3SWJ9x4oDFRwfBw3YQjtBAP 6c8IVelKBsTwVasMMQHJR6tixujn1f1fn93+g8kEFMgOSdoucepPO93kElxwETiVnnQ0CODrXR 05c= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Mar 2023 01:03:47 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4PWmZV2Hkgz1Rwt8 for ; Wed, 8 Mar 2023 01:03:46 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1678266225; x=1680858226; bh=p+MxxNmS9DVwNUcLA5 5VvIMV4ImTHL2q/nFJco681WM=; b=JmpBHP3mLqVQ1y/vDhExWvC7oXLkJfzuVj 4AICeGynPa222qAgRt0Pf5/XNwFBnOuWb+prS2csn26XWUl6dk04o3F4VjmuyB++ rr2SNVZPTSgR60NpYg3yBhrRyG/ZdLHWgMY0BIDp/5Dpqy/Li9j6GW5jl4wnzNRh UjftQCszs6N3ja2EL1cTTFQzVpGnYDAQjtYYOGU/WtYafEyxZ0FurSLWQavD6v3f OOtHC2f+PRmps/FHnOAS5xV7MflmPXg5vSlQShEQFedr3ZUv+Cnzrj3pgn1ofD+f 8pDRB0pBDNYnQvIKwAO0zJoB8AglTOjZfwzs/SOS7f5Adu0huTqQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id OPxXSL1arS2W for ; Wed, 8 Mar 2023 01:03:45 -0800 (PST) Received: from ephost.wdc.com (unknown [10.225.163.68]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PWmZS2q1tz1RvTr; Wed, 8 Mar 2023 01:03:44 -0800 (PST) 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 v2 16/16] misc: pci_endpoint_test: Simplify pci_endpoint_test_msi_irq() Date: Wed, 8 Mar 2023 18:03:13 +0900 Message-Id: <20230308090313.1653-17-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> References: <20230308090313.1653-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Simplify the code of pci_endpoint_test_msi_irq() by correctly using booleans: remove the msix comparison to false as that variable is already a boolean, and directly return the result of the comparison of the raised interrupt number. Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/misc/pci_endpoint_test.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index afd2577261f8..ed4d0ef5e5c3 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -313,21 +313,17 @@ static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test, struct pci_dev *pdev = test->pdev; pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, - msix == false ? IRQ_TYPE_MSI : - IRQ_TYPE_MSIX); + msix ? IRQ_TYPE_MSIX : IRQ_TYPE_MSI); pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, msi_num); pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, - msix == false ? COMMAND_RAISE_MSI_IRQ : - COMMAND_RAISE_MSIX_IRQ); + msix ? COMMAND_RAISE_MSIX_IRQ : + COMMAND_RAISE_MSI_IRQ); val = wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); if (!val) return false; - if (pci_irq_vector(pdev, msi_num - 1) == test->last_irq) - return true; - - return false; + return pci_irq_vector(pdev, msi_num - 1) == test->last_irq; } static int pci_endpoint_test_validate_xfer_params(struct device *dev,