From patchwork Wed Feb 15 03:21:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13141251 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 64F35C61DA4 for ; Wed, 15 Feb 2023 03:22:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232750AbjBODWL (ORCPT ); Tue, 14 Feb 2023 22:22:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbjBODWE (ORCPT ); Tue, 14 Feb 2023 22:22:04 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0C972B60B for ; Tue, 14 Feb 2023 19:22:01 -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=1676431321; x=1707967321; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9t4V26W1BTuWwWINggkU+hrMt8+NDJ3nkX3Khu54WcU=; b=O9AbTTfpAGEna2xPe6q+wZEpuIyI8z7DJhbda3Cjlv97CLPeWfWZljLg JriHU7Q7nkSiRHFk9w4RMr6e2Xc9DcHUi/7cr9X6WwJpFll2tjZIYCYCQ CpnyarsbZnmRmOMTh1hXnLboqL0oXXvk0K2qJYE88zAKiC5Gr0TtBFQOo RNub4tXGc5LwX2FFkpJLqyfRdQRy9TRm3XrDjQJoRftZJT4d9mq5cQuNk AqvhkCq2XYYLMTyuEMzt7KEoM2Yn0ns/DFXfF1OsHpq9noiFTTQY3a2CR YyMwACwqplMLjGRD7sj5z7VbSErtiOldcrlhjEDILAWL/MrdvlsvZFdOY Q==; X-IronPort-AV: E=Sophos;i="5.97,298,1669046400"; d="scan'208";a="223351448" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 11:22:01 +0800 IronPort-SDR: xwQV5QSHseobRiQzcbIVZgQYyHzMa00XsQw14+xQf3UM5UAF8IkRVmZF0bhyVUknNaa5eR48Jk XaVc/T2dtlV9l03DuAnt96KlCy4BWaoBfhHmyxYAjNvOViR+/neHpB3u+S29dDa6F/Qp0oHoyi 4K0ySS7p3w0fn2yuHwqOrRs5lomzGOFCdHVIQpg7aEQ9FlCQspuyXS8vFBLr79xuXSir9NEean nF3yYhUc9wYeyeU+CPApNEWPxE5weIiaXhlNngUppxhEsalmb1ADHnYJIkaaRQzj9aNIdMtdyz 3Cg= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 18:33:24 -0800 IronPort-SDR: ItWtpvgz6mt/P5xiBswSwHY/mr9UF5kGWOBzMKVhJt+iw3NjFYd+ZMw2KyjB/5Zd6/d980P/jI eEiWCl74en72a7jPuEpcuWKV1Tc0Bc4my3HsX+efBmndsYu9Oqqmrktw0zZwsq4UkLIYiOUqfV 4A0fF6yUVmCZKCz3puDoh9LdIte3scOkV7YAIFZMwdf7HifbsThTSsT3gbTdsDSAgymCjwT7lP DbeA183B3AArsswqttxtQdP7KSqz87cQPRCt8lYHu4dG1gL3RWh1jEFBz2i7D2X93y01FokbGM Jr4= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 19:22:00 -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 4PGjzs1n7qz1Rwtm for ; Tue, 14 Feb 2023 19:22:01 -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=1676431320; x=1679023321; bh=9t4V26W1BTuWwWINgg kU+hrMt8+NDJ3nkX3Khu54WcU=; b=NYgdShkICzz5D9YR4S7NXxHIJuHWJIhxNJ TOwhBJZqIFik3aRjNh7B/mLNpJLH3eUw71nR3MLXxEPPkaB9MtYgyq9HWIF9Huj7 VqWTgopoKT0o76AW/CIOoON2/lhSrX/4wavpPK3NYoNTbrGpuSIQzCUI+f1RYgFM 5/x0+sNaiyCyJxjb4dlXnbojh0xfrpdmr+zI7LetzMTynp1mIJQgTLiaZgkeqqcd CYsoSIHN0CqK4GY9kXET8H13MPmWlp1IJJRUmbTGeeoxQ+AgCJU6b8ADEBSfCaaw 3DWbaZSpoxuZ2WvC6DGqmhdTAqKVE0iXJouzEVoguuoJ58H+zwGA== 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 FQA1tqDGmdf2 for ; Tue, 14 Feb 2023 19:22:00 -0800 (PST) Received: from fedora.flets-east.jp (unknown [10.225.163.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PGjzp5km3z1RvTp; Tue, 14 Feb 2023 19:21:58 -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 01/12] pci: endpoint: Automatically create a function type attributes group Date: Wed, 15 Feb 2023 12:21:44 +0900 Message-Id: <20230215032155.74993-2-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230215032155.74993-1-damien.lemoal@opensource.wdc.com> References: <20230215032155.74993-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 using the add_cfs() endpoint driver operation. However, this attributes group is not created automatically when the function is created and rather relies on the user creating a directory within the endpoint function configfs directory to initialize the attributes. While working, this approach is dangerous as nothing prevents the user from creating multiple directories with differenti (wrong) names that all will contain the same attributes. 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 from the 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 configfs attributes to the user. 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 --- 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 d4850bdd837f..1fb31f07199f 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 Feb 15 03:21:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13141253 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 D597AC05027 for ; Wed, 15 Feb 2023 03:22:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232533AbjBODWM (ORCPT ); Tue, 14 Feb 2023 22:22:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232625AbjBODWF (ORCPT ); Tue, 14 Feb 2023 22:22:05 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D95032E6D for ; Tue, 14 Feb 2023 19:22:03 -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=1676431323; x=1707967323; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tIhg+9TmISWM6CNSYvtDKqRKlDI0RorvIeEG5cf809A=; b=dK+0Lls973nm8PV7JmHwsqafY9zUNYOmopPk6QyYiXVN4Xm/8FUxEGa+ JNmuEPO2A+64Rd0AYst2WhWeSLPmD0q7p9zIVIkVyN5YA0mlKFhwV3H0H x4rs6Ya8IPVd5w5GqfJWhsb7aXc5+EB8nPI/mG6h30LVFHqB+PK/14Kv0 W46WrwceH8O5TMpzPKMy6rwruMGkJam7Np+Yg4vRFdotXo8MRbcFb0PAm AWo6CTFwkUKGD0DiNPkdQkmT0Lwj9vHEW6mO1DndLGUGnS9aPa1B6NzHf +srzujDI8yu38haJtlMQK5EBO4PW7S42TgGAw58iagXLuBoHvKiKmkXlg Q==; X-IronPort-AV: E=Sophos;i="5.97,298,1669046400"; d="scan'208";a="223351449" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 11:22:03 +0800 IronPort-SDR: iuiDCmGlQn+OC+Dr3DIFM/Tf1hpqmQtW0saiFpNB6gCsgQQNRAtJugUjElqC1HAg2cjlqZ+e1s P2rIyh/D9++kTEXDQGYMQ0JOuz4mM1VqIgi8V4eBuSc6MX1F3zs4OTH+Go9HB3JFBhpnPXuwAI LO4u6S53TEGobclyVy016Yc28EF/t6zkWpq3G7XT4enXuzO+l8qx+4tWdkZyC/ZKxhIcRVufx1 Iu3K13GOV7TnB7fc3rkZVwU29Ga1kV7ETTWtX0MNEBOG9MuHaAa14Afim71pnbglii37shS6xD hIU= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 18:33:26 -0800 IronPort-SDR: 7c7MiDWGXmYqh6BWfZEtvcBtUkoHMujV+zekkmn59G62UpmrEQZxRc0iXSvUhv7wPH039F9pJk vEfnAPTGNnVZG4+bzg5FRfkxyIfqcfS8PyZJRC5S9Z8LKFnDqjCmnfn46olJNsqCVI6W6w1y++ t1wPmuSOgjUue1gbsbd6cEhr5jMt/xqWq/Y5mRnrEmeHmVGBgoYefe08dK7lEDxuZYLRQ1TyA5 cpGIMJXJPGUzBrghUgbavF2NcUAeXiECgJrwTtJyh6ifUdt23dAeH9B8t1nFLGHFne0ogNlZl2 qz4= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 19:22:02 -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 4PGjzt6yX8z1Rwrq for ; Tue, 14 Feb 2023 19:22:02 -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=1676431322; x=1679023323; bh=tIhg+9TmISWM6CNSYv tDKqRKlDI0RorvIeEG5cf809A=; b=sMvF/L4b7G6NqMN6Nb9s/NqtHgOhbTKJhT yHw3BqtT49RAkSQiX510mdPvOgIEI0wURsXq9MiDzsaDHAQv4fw0Y44MNim4ZC2i qriYf72pygDZ3UR12WTynDx+lRYKDbA6oWl3hFWl5lBSv9+tJ7cCiJHyNvZQPgY+ 08pv2cog71beIe06anQKAdkKkv8FaArS0aPw2YKctevm9eEEIlD2/CoTZW5Kt7cb okVSIP1Vgi8uB4a0BqI4k5h1TJUmm229cs8BtdD/34V/Gsb0rZfaRgSUGtPZptUg vjp6EEljTJNgiH+XDA7P1Hk8Ua4lajh9Sdy3xZRy9cw5Q/pTnPlQ== 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 CE5k9rfupvgH for ; Tue, 14 Feb 2023 19:22:02 -0800 (PST) Received: from fedora.flets-east.jp (unknown [10.225.163.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PGjzr4WVjz1RvLy; Tue, 14 Feb 2023 19:22:00 -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 02/12] pci: endpoint: do not export pci_epf_type_add_cfs() Date: Wed, 15 Feb 2023 12:21:45 +0900 Message-Id: <20230215032155.74993-3-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230215032155.74993-1-damien.lemoal@opensource.wdc.com> References: <20230215032155.74993-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 it and function drivers should not call this function directly. Remove the export for this function and move its declaration to the internal header file drivers/pci/endpoint/pci-epf.h. Signed-off-by: Damien Le Moal --- drivers/pci/endpoint/pci-ep-cfs.c | 3 ++- drivers/pci/endpoint/pci-epf-core.c | 12 +++++------- drivers/pci/endpoint/pci-epf.h | 14 ++++++++++++++ include/linux/pci-epf.h | 2 -- 4 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 drivers/pci/endpoint/pci-epf.h diff --git a/drivers/pci/endpoint/pci-ep-cfs.c b/drivers/pci/endpoint/pci-ep-cfs.c index 1fb31f07199f..62b3b9e306fa 100644 --- a/drivers/pci/endpoint/pci-ep-cfs.c +++ b/drivers/pci/endpoint/pci-ep-cfs.c @@ -11,9 +11,10 @@ #include #include -#include #include +#include "pci-epf.h" + static DEFINE_IDR(functions_idr); static DEFINE_MUTEX(functions_mutex); static struct config_group *functions_group; diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 9ed556936f48..db121a58a586 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -12,24 +12,23 @@ #include #include -#include #include +#include "pci-epf.h" + 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 + * pci_epf_type_add_cfs() - Get a function driver specific attribute group. * @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. + * Called from pci_ep_cfs_add_type_group() when the function is created. + * If the function driver does not have anything to expose, return NULL. */ struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf, struct config_group *group) @@ -50,7 +49,6 @@ struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf, return epf_type_group; } -EXPORT_SYMBOL_GPL(pci_epf_type_add_cfs); /** * pci_epf_unbind() - Notify the function driver that the binding between the diff --git a/drivers/pci/endpoint/pci-epf.h b/drivers/pci/endpoint/pci-epf.h new file mode 100644 index 000000000000..b2f351afd623 --- /dev/null +++ b/drivers/pci/endpoint/pci-epf.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * PCI Endpoint *Function* (EPF) internal header file + */ + +#ifndef PCI_EPF_H +#define PCI_EPF_H + +#include + +struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf, + struct config_group *group); + +#endif /* PCI_EPF_H */ diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 009a07147c61..b89cd8515073 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -209,8 +209,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 Feb 15 03:21:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13141252 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 BA5F3C64EC7 for ; Wed, 15 Feb 2023 03:22:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232845AbjBODWN (ORCPT ); Tue, 14 Feb 2023 22:22:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232665AbjBODWK (ORCPT ); Tue, 14 Feb 2023 22:22:10 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B51532E7C for ; Tue, 14 Feb 2023 19:22:05 -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=1676431325; x=1707967325; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IwvAJLtuxZiowQVqD/EJeUOtDRGFm5IRLsmzFadJxXc=; b=hxN/XFkkjUdN9ibhLSEXlXDExjij+sY525/u5Ifffuna6Lc3UPytWuZV QVCrbb/XOWdlgiTFBEa+JHZPkIy7QLzlxmGdjHfbTFCf2pVdMHpTrNtmQ GT/SzfRRObU9wvRm+d0/NmDQxXfdOGf4GKPgnK3SNQg1ioAgK/Qqy4xsS gQiSbrDGBnGXGfYekYKKgefDXfTMn+AREcn/X/lVYaeIVC0FP1IL/j83z C5tBafpet4lqmvJo+2tlAb0jf8J/e5qFzu3isxU/uEaBvmlQd5X4Jrien MwQj9PfsVGOMP03XXp/Wok9OgP1Ao0lqbT+vHA92Trs2+B3NV2VF0tv8f Q==; X-IronPort-AV: E=Sophos;i="5.97,298,1669046400"; d="scan'208";a="223351451" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 11:22:05 +0800 IronPort-SDR: 3QjOGe3gPBu+pWzRcUDQ8rUcd9ZFWZF17KCJettod0ZPP9AWjBYTlZs7Tvk/UWvo86T1jSE1EE vC7HQWbUw9ytQ+D+tBucATs6vtUsb75NPe93Fw6PaMtTOTF+ezZ3nXZ6jeNpDTfT1QHzHgIhDN L/B7Jh7NbV+k1uIEUlEHN5yfRSRDCyy9wuIASI70+ob1xTE6YJcTQ9N+Oy1Yto73xuVitnMNZr tgjl7HOQlHFe1GJdzfZM1CVCwGbeRLPaZ9fRw/1+JU7VQeX9ztjd+GHX+avF5T6glguK37oA8i 1Ss= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 18:33:28 -0800 IronPort-SDR: pADATaYUvJcNB7EjjREKNQ+b5eA1+nqSHMeqQVXFkk6bH4eGXhudtS5/ZnxsyMhq5GPBLwOE/M Do5lLSh1trLsNd8o3sslRVYbYzVi2DGKHuel9x12cg7bl55H1R2PVoN5svIHSPJfswbf6vbKml 24GAipVhHtCDU92076/FeDrNJiaOfyboM6GXnXthRGNmw18nkfo27nyzGIw8HB/tlmkTwUYk+5 kZ7Obf6jXUKB87kyKpZHHlMFSI/Yt9W16yBjnzE3ffbuowqRrIyy3sohRxieFKNlNatrX9n2F8 P8E= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 19:22:04 -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 4PGjzx0MyKz1RwvT for ; Tue, 14 Feb 2023 19:22:05 -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=1676431324; x=1679023325; bh=IwvAJLtuxZiowQVqD/ EJeUOtDRGFm5IRLsmzFadJxXc=; b=KG0q7RbmpTbdE3/vfAEdJexcgemlT4UkHR s7sZ40Iv3B5U/FAtLimd89Eya+2nShFmFgP27GocxorySRclLtasX/zqhy7gaZ+9 dz83kzNkniRSBALgg4ym/7sEFcjutBk8B7x5rNViHPq7wwtkV0CwUaa7VPDqfMfd B1VPd5MC7U+Bw0PyhQaTPV1/59Dd0S8VgRhEFK/Aasis5yrv2FG95MJ3j2O/3Gp7 j31QjhFXWvpz+MT5klkUDJHpyrOroG29J6hQkqo6IcizTYlMMGbI4twohX6iIhlI Yh5DQe0S6zRRYdpA80GJFOBAy+CGiuzYOWYJ1BR3fLP66xdPmUdQ== 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 c3DuPnfgDrY5 for ; Tue, 14 Feb 2023 19:22:04 -0800 (PST) Received: from fedora.flets-east.jp (unknown [10.225.163.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PGjzt3c2Gz1RvTp; Tue, 14 Feb 2023 19:22:02 -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 03/12] pci: epf-test: Fix DMA transfer completion detection Date: Wed, 15 Feb 2023 12:21:46 +0900 Message-Id: <20230215032155.74993-4-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230215032155.74993-1-damien.lemoal@opensource.wdc.com> References: <20230215032155.74993-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org pci_epf_test_data_transfer() and pci_epf_test_dma_callback() are not handling DMA transfer completion correctly, leading to completion notifications to the RC side that are too early. This problem can be detected when the RC side is running an IOMMU with messages such as: pci-endpoint-test 0000:0b:00.0: AMD-Vi: Event logged [IO_PAGE_FAULT domain=0x001c address=0xfff00000 flags=0x0000] When running the pcitest.sh tests: the address used for a previous test transfer generates the above error while the next test transfer is running. Fix this by testing the dma transfer status in pci_epf_test_dma_callback() and notifying the completion only when the transfer status is DMA_COMPLETE or DMA_ERROR. Furthermore, in pci_epf_test_data_transfer(), be paranoid and check again the transfer status and always call dmaengine_terminate_sync() before returning. While at it, also modify the channel tx submit call to use dmaengine_submit() instead of the hard coded call to the tx_submit() operation. Signed-off-by: Damien Le Moal --- drivers/pci/endpoint/functions/pci-epf-test.c | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 55283d2379a6..030769893efb 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)) { @@ -151,26 +159,36 @@ static int pci_epf_test_data_transfer(struct pci_epf_test *epf_test, return -EIO; } + 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); - reinit_completion(&epf_test->transfer_complete); + epf_test->transfer_cookie = dmaengine_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 Feb 15 03:21:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13141254 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 563A9C64ED6 for ; Wed, 15 Feb 2023 03:22:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229483AbjBODWP (ORCPT ); Tue, 14 Feb 2023 22:22:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232349AbjBODWM (ORCPT ); Tue, 14 Feb 2023 22:22:12 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8967532E42 for ; Tue, 14 Feb 2023 19:22:07 -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=1676431327; x=1707967327; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ulTFomFNmfH7tQJKLFImDfoeozX3ww0CC3AYjVDn1+4=; b=Cdfmnq1OovEguTNXHCggk0EIIr4f2JuA8V5tUFtLDNxxJGj3llAukt6k nvzMaFY+LJwN5qa9LDEuyvz4J3XXsD16PHz5Rny+IfrXUVn7ppvQKjFa8 F0atAic21R1pZK7slCl67QL3xcAnmMq7u8C6e9QeCm4TkejLuaHTPebwf HisvZyOmEWIaZ+l5hgwF/ay7SIiul4uNdCDsiMXK+CRf+8AtG873gwRrV NRzq84ufroFEroxD5toA0pmglwdXEttFCzvcn/oM4YC/n8RokFDsqq2I8 N9nUQm6uyJVjODNkyxLBwuGYmoCRBgx78zxQ84rOcPF8mnhRmWYCP4Dzd A==; X-IronPort-AV: E=Sophos;i="5.97,298,1669046400"; d="scan'208";a="223351453" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 11:22:07 +0800 IronPort-SDR: rQvR8wLJ501OpIjjPoPi3GBcQn2G5bTyz8e5uanfM/s6K1JnoLHIR0J+JRRx5dha9z/96gTlX1 zquFlR/jFciIpv+w3xpZ8iYbjQyMjAUx6H7oHCwyQZi1TlFCH8YwVrqshjvo7EP7nDsPcsXVpI bk6LTS+k1DwU/CXD2nIQZ8QvCpuILU0es0CHZFZGLpxOgsGskjVltznRt2dW/NwpZQvF5HIOWM ALoaroAn3ZERKN5N2YBnTE67NG+e9I9fFi3+WPza6Utewf8MUs3AxfxTDJ7cjdOzYORPDWXhHP AIc= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 18:33:30 -0800 IronPort-SDR: 1gmvSo6NWwlSkEyFom0AyIekEa9H7YqGtCFT0y/a/ZdFXq8jgf9HNcwASACcO3uETSgitHlWH5 bVZXDkKKK9+C7hDnJfs3xrqPj+tiU7Ucq8rMj+AMNs0+3v2N0QrTnxStIRlfylNu8TEVDaMW3e cmWR4OiSnXPRIdXIiibAvwbwqg8wLQNAT8JSizjfDIoqO5V61t0QFcyeVAnKDSv9xHrn+5tl3O Byv4liJry9Tuj89f1V/l+YIGQWGeJdwuPz5c7L22JM6J3QTJEvTbYqQltSG3jRWu2H24BrbFtA sGU= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 19:22:06 -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 4PGjzy6fy6z1RwvL for ; Tue, 14 Feb 2023 19:22:06 -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=1676431326; x=1679023327; bh=ulTFomFNmfH7tQJKLF ImDfoeozX3ww0CC3AYjVDn1+4=; b=A/0PfAo8CK3cfZlSb7FH0F4kz9iBlhqBFJ Zj6Zks1e4p3u5yCm/x8LKX5G63oZRTcZFY88f1HG0/Yr16Ptjks70q/S3HyBwX3s k0AE9zGqO8WpeDe0ABR5ENvRSlifLzRIi+ZTJT4reLnr6lX8ytDUDfX8NfNpz2FB 2fk0CEQ1SEi8SV/lpMeebv02XgD8fYd7zYfWYwalofzsWdmHP36JdeHRq6Zm7169 tkY76ICMHEZWqB5EK4IbeGgkv2NW7KCGBPC4gb8Srx8YzVVoxgL7Q9o26rtaH4CG yIsGtEVhHP2q1glalsHraevGTOVmp35k4zMZ1TmBDoXfcTeyyU+A== 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 28OaNLOOrVMC for ; Tue, 14 Feb 2023 19:22:06 -0800 (PST) Received: from fedora.flets-east.jp (unknown [10.225.163.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PGjzw3Mysz1RvLy; Tue, 14 Feb 2023 19:22:04 -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 04/12] pci: epf-test: Use driver registers as volatile Date: Wed, 15 Feb 2023 12:21:47 +0900 Message-Id: <20230215032155.74993-5-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230215032155.74993-1-damien.lemoal@opensource.wdc.com> References: <20230215032155.74993-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 struct pci_epf_test_reg directly from the test register bar memory to execute tests cases sent by the RC side. Make sure to declare pci_epf_test_reg use as volatile to ensure that modifications to the fields of that structure make it to memory to be seen by the RC side on completion. Also initialize the test register bar to 0 when it is allocated. Signed-off-by: Damien Le Moal --- drivers/pci/endpoint/functions/pci-epf-test.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 030769893efb..df3074667bbc 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -340,7 +340,7 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test) 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]; + volatile 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) { @@ -441,7 +441,7 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) 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]; + volatile 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) { @@ -530,7 +530,7 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test) 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]; + volatile 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) { @@ -619,7 +619,7 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, u8 irq_type, 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]; + volatile struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; reg->status |= STATUS_IRQ_RAISED; @@ -653,7 +653,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) 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]; + volatile struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; command = reg->command; if (!command) @@ -911,6 +911,7 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) dev_err(dev, "Failed to allocated register space\n"); return -ENOMEM; } + memset(base, 0, test_reg_size); epf_test->reg[test_reg_bar] = base; for (bar = 0; bar < PCI_STD_NUM_BARS; bar += add) { From patchwork Wed Feb 15 03:21:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13141255 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 4FDD2C61DA4 for ; Wed, 15 Feb 2023 03:22:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232544AbjBODWP (ORCPT ); Tue, 14 Feb 2023 22:22:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232679AbjBODWM (ORCPT ); Tue, 14 Feb 2023 22:22:12 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D1DA3344C for ; Tue, 14 Feb 2023 19:22:09 -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=1676431328; x=1707967328; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g2jL7drT0Rd/3YHYSO/OIKxRb2xaVI6wTuLxf3tSNSA=; b=qrVI24fGYfhwQpWP7zqSdrk/YKcC4llMS9IIBYy2Z8skWurbmRwyUplb emlijrOWypatqr8xrFo+ZTVYlhL4+a5F/E4b469BkdaEAFJc/xiG5SZh3 5uNkvAXkAQ/RuqAaA2nUXDVpBJjSRCiPYfBpGX0Z00IQoLJZj3Yvnv10W mt3fzUxiJyommMdDi00B+JaJuLdhnmOQTzof7QleSOF1GjBhazyIJdoer e6yiHhJNfFLkii4lVd1dR5VFiNcjxp3eqUmp2kKxyW6Zv+mZPsgQW8ZQl fPoD/XPWeIcvNQ6P/8X5mlKquP9JrIc3AdAE+FkGih3J0cP2C4m/jJA4l w==; X-IronPort-AV: E=Sophos;i="5.97,298,1669046400"; d="scan'208";a="223351454" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 11:22:08 +0800 IronPort-SDR: HjbATAQgcRiFNFOGP1gRH4wNvh+79rJKk3eTW5jKPp9sN7AWgHVWW/Z3BL+ytOdKVUodVLCEzx cSBr9uo3A8LKqduTN9krXYqUvqUOsojrXnvxXvsIZ++cJVPuuZ7fLk/B0eJAssEoStf8gvO8IR PTgR7Mtv4yzyH9RRS5P3Xehe+xvLY0nsliWe41BEI8LT9bHlzfw5hiyrw4tMLRJCHSbG6RkCOj nBMedd6OyFRejq4Ba1iFEfX8uQIeFHrxIHQdSCrx0ZI5QtBj+M2bD6nk2Ux0E+XIRuS86kspLf ueg= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 18:33:31 -0800 IronPort-SDR: pW3PQrgv3mp5fuDbpEsKPtlIb9YYNNj3MFU+zy4LOMEaZ+djMEzNsW3AS9gqPkWGD3DJeqTs84 MxB3oVsDbjxHmiIpZd0OAXNVHrNhQ5KZOD76vJEvOj42oxdaSXY0opgUl3ckEL2HsRkMVAHXZP OWwslJ/erillNktbdWvorSXePtZVuEmbZOQ6CZVXvr4IFhzoqR1pJ0ulugz+00aIn5yGkMzJJK e7J4EH1cm9nGDTlFJDEa8TRfXUJ/Ci3N5wAGOdHbFqA5W8QyKLOR3xD0dslHJ9Zh6tAbRM1gv/ bbI= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 19:22:08 -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 4PGk005hkSz1RvTr for ; Tue, 14 Feb 2023 19:22:08 -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=1676431327; x=1679023328; bh=g2jL7drT0Rd/3YHYSO /OIKxRb2xaVI6wTuLxf3tSNSA=; b=P5VgxkoUw92pCyPvsZDv8icWswFeprezUB PvqIIeXPhR0XQQpA95phJppcy2ZCrbxqtdl53plSrRne06XRxRdzoYTA1bXXnrZu AdY7Ng6V9rGqT9JAr13u+eQvRVp/nrVdXIoLtnz0L0D0kgiUm+ujU9gWqL5KmADv pT0RCVyYONKPXTtJjGIt5RwEM7PaVOnbwrRwuNunh83IWkaHqtMD0ZJWo+XqXWOs H5XK8x0cI01BFYloq2vu9q9hDGvqAmNz2bRXqfIynS4XFG46+xId+dxZnrJdtTSn zPu+KvBzIIVzxsB75OpOTDbNYsPT7KX38FZ27cj24Z/7hmFerCTw== 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 6qVGL_-qYt-0 for ; Tue, 14 Feb 2023 19:22:07 -0800 (PST) Received: from fedora.flets-east.jp (unknown [10.225.163.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PGjzy2vgLz1RvTp; Tue, 14 Feb 2023 19:22:06 -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 05/12] pci: epf-test: Simplify dma support checks Date: Wed, 15 Feb 2023 12:21:48 +0900 Message-Id: <20230215032155.74993-6-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230215032155.74993-1-damien.lemoal@opensource.wdc.com> References: <20230215032155.74993-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. The functions pci_epf_test_write(), pci_epf_test_read() and pci_epf_test_copy() are modified to add the use_dma boolean argument to indicate if transfers should be done using DMA or mmio accesses. Signed-off-by: Damien Le Moal Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-test.c | 43 ++++++------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index df3074667bbc..e07868c99531 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -327,10 +327,9 @@ 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, bool use_dma) { int ret; - bool use_dma; void __iomem *src_addr; void __iomem *dst_addr; phys_addr_t src_phys_addr; @@ -375,14 +374,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 (epf_test->dma_private) { dev_err(dev, "Cannot transfer data using DMA\n"); ret = -EINVAL; @@ -426,13 +418,12 @@ 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, bool use_dma) { int ret; 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; @@ -465,14 +456,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; - } - dst_phys_addr = dma_map_single(dma_dev, buf, reg->size, DMA_FROM_DEVICE); if (dma_mapping_error(dma_dev, dst_phys_addr)) { @@ -516,12 +500,11 @@ 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, bool use_dma) { 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; @@ -557,14 +540,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; - } - src_phys_addr = dma_map_single(dma_dev, buf, reg->size, DMA_TO_DEVICE); if (dma_mapping_error(dma_dev, src_phys_addr)) { @@ -647,6 +623,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) int ret; int count; u32 command; + bool use_dma; struct pci_epf_test *epf_test = container_of(work, struct pci_epf_test, cmd_handler.work); struct pci_epf *epf = epf_test->epf; @@ -662,6 +639,12 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) reg->command = 0; reg->status = 0; + use_dma = reg->flags & FLAG_USE_DMA; + if (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; @@ -675,7 +658,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, use_dma); if (ret) reg->status |= STATUS_WRITE_FAIL; else @@ -686,7 +669,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, use_dma); if (!ret) reg->status |= STATUS_READ_SUCCESS; else @@ -697,7 +680,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, use_dma); if (!ret) reg->status |= STATUS_COPY_SUCCESS; else From patchwork Wed Feb 15 03:21:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13141256 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 C8C53C05027 for ; Wed, 15 Feb 2023 03:22:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231549AbjBODWT (ORCPT ); Tue, 14 Feb 2023 22:22:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229773AbjBODWN (ORCPT ); Tue, 14 Feb 2023 22:22:13 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B9E13345A for ; Tue, 14 Feb 2023 19:22:11 -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=1676431330; x=1707967330; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=miWCyUP1x/mMlv5q6IoApDuVbCCiPqu3nFRQhVuY9xY=; b=IFsVOAYkUpbRcaZNF8W+qCkLbkks2GaTT6ABsKWxWTEt2e5/SbpR+kZj mJEU36vnfxlydZMJwKwsXCI15zohJyT7m65O4tJN2xT97FF0HsQhNgXW5 JTAIstu1Yan6N4T3MwP8NQeL0orw+Uf2/y5tGLuwgmQre12oMS65kBSqq 68H0tgxZJmI78A7B1JYCEYsZj3oUuwMhm4idfisGC1waG173n2fEN/FEH WPIcgXE5ES9NW72JLw0ScE1Hr7Vr6HNt3AtA1zl+vW614RrHZ6sD960oH 65zaAFT3MlfTbub2Z01jlGG9tSkFlU2O/+IdTuIJsrMGVAMtkqqF/vBLr g==; X-IronPort-AV: E=Sophos;i="5.97,298,1669046400"; d="scan'208";a="223351456" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 11:22:10 +0800 IronPort-SDR: Jzmu4uR0IQK7woyVxwMzwllX7uDFmN61IE1SZooP1AyHs2iNW3cU6schudm+m9D8/MePSHm7vk 34zPQdO2BVfLtTYf/0/kpXvj/cr0jiwO7LkgOebQZV4Y2pk32d7bugWeRXwu1t4RIPYDHFL7Pv O2SvHlIrFIYQGrU6aYg3+Z68oxep/E4UimWPPyzs5GhzmnJJBP+z2TnOqzSEMhpNkbHAmHWnD5 bODRJFKdiGi0rOco2W+liyjDedIOr/ySfBVfZVoaCsDne4JnZ3mgKWAQCDiMDjypHZPzpX907t 3og= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 18:33:33 -0800 IronPort-SDR: 7kVAIXhBk0XrAiIgQoFb0uAJNrjIB+i3PZFDTgJdMbgma4Bnyaj1MEbc6IleUHY2vG4Yw8uv2L Ssetv85o1onAB7eE/Wr6bUSdgaWkcgUnMGm77iLMZeZOh1WvhfLHA1gvZIUpdB0qswb5/A1vFg c4u2pNS32vlgXcFrWYLj75U4VP8MLbAprh1yuzwE/FC4uYmaVf2KhOIJ7aTpjPh7cAi9azzppS 9J0J+XvoQSKbyyowPVDAmMDHurTKBormSIC64VetuGgtGkbU+xJ8XCWiA6hDutcjTGmx0h2ny2 AXc= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 19:22:10 -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 4PGk025kQ2z1RwtC for ; Tue, 14 Feb 2023 19:22:10 -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=1676431329; x=1679023330; bh=miWCyUP1x/mMlv5q6I oApDuVbCCiPqu3nFRQhVuY9xY=; b=gqG6g/4Rm+tJbzm6gWiBgjcpkdrRrUEzy+ Ganvm03ErSipIWd9VLmAcO9kfGzhTX7nMeDrm9TM/gKK1WEVvba1NWkZkfTU07Rp 1YZ9YwAAqA8Xy8MCkKCKkQN4VLEXfnYzU9169N8/cK2zx7KtOsXj1kFhvg1TlUm9 4qIoutlHOc7B7d8lgbHQCSdFzpPCc/NSFnqns9yooEfRRBCjFLJAkRfGsWo+aUtA j6ngHfddYSvFU1YhRDbuykw1Rich/l40qCualQuGUvLI53BrtDe7f+vMf3TP6QYg ADSaI5vKwZ4bHKib5DGHfjoDJjIntNKGlArnVoE4WuJthpeYFZbw== 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 zOzdwdsGQTg7 for ; Tue, 14 Feb 2023 19:22:09 -0800 (PST) Received: from fedora.flets-east.jp (unknown [10.225.163.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PGk00244Kz1RvLy; Tue, 14 Feb 2023 19:22:07 -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 06/12] pci: epf-test: Simplify transfers result print Date: Wed, 15 Feb 2023 12:21:49 +0900 Message-Id: <20230215032155.74993-7-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230215032155.74993-1-damien.lemoal@opensource.wdc.com> References: <20230215032155.74993-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 disivision by a 32-bits ns value, simply use div64_u64() to calculate the 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 | 42 ++++++++----------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index e07868c99531..f630393e8208 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, bool use_dma) @@ -400,7 +389,8 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test, bool use_dma) kfree(buf); } ktime_get_ts64(&end); - pci_epf_test_print_rate("COPY", reg->size, &start, &end, use_dma); + pci_epf_test_print_rate(epf_test, "COPY", reg->size, &start, &end, + use_dma); err_map_addr: pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, dst_phys_addr); @@ -481,7 +471,8 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test, bool use_dma) ktime_get_ts64(&end); } - pci_epf_test_print_rate("READ", reg->size, &start, &end, use_dma); + pci_epf_test_print_rate(epf_test, "READ", reg->size, &start, &end, + use_dma); crc32 = crc32_le(~0, buf, reg->size); if (crc32 != reg->checksum) @@ -567,7 +558,8 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test, bool use_dma) ktime_get_ts64(&end); } - pci_epf_test_print_rate("WRITE", reg->size, &start, &end, use_dma); + pci_epf_test_print_rate(epf_test, "WRITE", reg->size, &start, &end, + use_dma); /* * wait 1ms inorder for the write to complete. Without this delay L3 From patchwork Wed Feb 15 03:21:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13141257 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 5CD1BC6379F for ; Wed, 15 Feb 2023 03:22:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232665AbjBODWV (ORCPT ); Tue, 14 Feb 2023 22:22:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232735AbjBODWS (ORCPT ); Tue, 14 Feb 2023 22:22:18 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D998234000 for ; Tue, 14 Feb 2023 19:22:13 -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=1676431333; x=1707967333; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yy8bnIircEMfRxG6DHZUyEhd5BscnXdzmdZ5rinTOmA=; b=GVmfN+jJuWDcb8XKCohgV9EG0hrtSpZPV49KAwQ75aiT4j+g9RI2TsBt rhtv5xdSt473IDgJTyHFrG118eTahXGaBFNTuPhLMozigl+0SDoIBPnnk 2YWt5kdEUhuRI/v1HMe1bXFwq8m9UVn7hNsniaDsicOfiKwZuQl1BNYCT lnwIdbUry/tIhbNEklaICu1jaGwxQBeMRxm4okkfQCjq09h7nhYALJb8R kP5BFJu1Tfu+ucMHUehUvVYzGl9s91ZfJaK/waWB3/QuLHPr9EoSBChE8 FiRhhKW1IFqiFCDBM8GBHW+7DgW/sH4qVZCDt2GsPvvmZQhd/Z1/sYD1H Q==; X-IronPort-AV: E=Sophos;i="5.97,298,1669046400"; d="scan'208";a="223351459" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 11:22:13 +0800 IronPort-SDR: K3W1e2eSI2KHr1TCeXH5erZLn6UAR3Hj+HI1DcA3iseTZDmWTL+33nHi8mNU+yMBfmcjSmDKfW CjmaqkkKrChCaiCi6aNXVwVLb4os+pxBBP1XW1KFeH/14JyiUlnnGHx5gvD6fyorskCTWHgcRp Qi5G0WpXDcNvCjrct4ZWoniPxiIaJez0OwMiX0Ah8G8r5FNP4F23BhJJyVi7DJa5R7ZyFYruFE scUcIL46vIO4IYXNHky02ZG0MF6EVi+85O1ie+3RkwgZgQVkCq1arOsXIX7ebBoSCyt0Wb9/wY mus= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 18:33:36 -0800 IronPort-SDR: xdEp9I3S77K3FKHAs4om8nAfsYDB/7HD8Ho9G8K0aVekpbm6aWe+159Y5l58HfLcK0Dv0N5ejR m/eJsgkkHmuiSIf//4oJLutrV0q2TZo0IrquHq4PYqJDmTk3R1pqDxdi04GGkAZs0JMfWVc7r6 CZ7F4/D7uGwaWTiiVDbo15EtvCyuOgs25pxauNtZDth43IVbWDyjJESyTNtuqNnFe4kBpvwR09 JMZrrUpsmUE5wXNeA9lhezfuxue5oSCU20/NiRLMYcJaNiHgM0cbWJW1fB+242mgRyiKT9u+YU AwA= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 19:22:12 -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 4PGk051mS1z1Rwrq for ; Tue, 14 Feb 2023 19:22:13 -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=1676431331; x=1679023332; bh=yy8bnIircEMfRxG6DH ZUyEhd5BscnXdzmdZ5rinTOmA=; b=NGns3HIq8bkxpM1vlwrK+u8qRt2zyn9L1+ gpC3cS+f5TXoa29t0YmcBZodtmhLmfIDMYGV/XkDuWKXL4Hi79lm1Lz3uV8pY4Tg AlJwhLkeELsaUOl4pCMK2AGeINzhqLxTEB8cPz0I1lBCHvOvVoNn1E4SbpyJtzBa SIqu+OPKJPtwqSbwtOApgngu0E2o31akVa/Z1xDC+aNow3iRXDZHloOvZ71K3IZB nIG9ogOJ4jlDeiu732NsVcaLbomDDAgUp3RCPZgcPonhfLAQkHjSyFUpz2JL61Xj ehGmczMjDRopTT8hsI9gTF8uzbNp6Ma8VxTwunjUoNkNlyn9bKvA== 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 v7R7m_BgwpF5 for ; Tue, 14 Feb 2023 19:22:11 -0800 (PST) Received: from fedora.flets-east.jp (unknown [10.225.163.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PGk022zy0z1RvTp; Tue, 14 Feb 2023 19:22:10 -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 07/12] pci: epf-test: Add debug and error messages Date: Wed, 15 Feb 2023 12:21:50 +0900 Message-Id: <20230215032155.74993-8-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230215032155.74993-1-damien.lemoal@opensource.wdc.com> References: <20230215032155.74993-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Make the pci-epf-test driver more verbose with dynamic debug messages using dev_dbg(). Also add some dev_err() error messages to help troubleshoot issues. Signed-off-by: Damien Le Moal --- drivers/pci/endpoint/functions/pci-epf-test.c | 69 +++++++++++++++---- 1 file changed, 56 insertions(+), 13 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index f630393e8208..9b791f4a7ffb 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -330,6 +330,10 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test, bool use_dma) enum pci_barno test_reg_bar = epf_test->test_reg_bar; volatile struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + dev_dbg(&epf->dev, + "COPY src addr 0x%llx, dst addr 0x%llx, %u B\n", + reg->src_addr, reg->dst_addr, reg->size); + src_addr = pci_epc_mem_alloc_addr(epc, &src_phys_addr, reg->size); if (!src_addr) { dev_err(dev, "Failed to allocate source address\n"); @@ -380,6 +384,8 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test, bool use_dma) buf = kzalloc(reg->size, GFP_KERNEL); if (!buf) { + dev_err(dev, "Alloc %zu B for copy failed\n", + (size_t)reg->size); ret = -ENOMEM; goto err_map_addr; } @@ -424,6 +430,9 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test, bool use_dma) enum pci_barno test_reg_bar = epf_test->test_reg_bar; volatile struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + dev_dbg(&epf->dev, "READ src addr 0x%llx, %u B\n", + reg->src_addr, reg->size); + src_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, reg->size); if (!src_addr) { dev_err(dev, "Failed to allocate address\n"); @@ -442,6 +451,8 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test, bool use_dma) buf = kzalloc(reg->size, GFP_KERNEL); if (!buf) { + dev_err(dev, "Alloc %zu B for read failed\n", + (size_t)reg->size); ret = -ENOMEM; goto err_map_addr; } @@ -506,6 +517,9 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test, bool use_dma) enum pci_barno test_reg_bar = epf_test->test_reg_bar; volatile struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + dev_dbg(&epf->dev, "WRITE dst addr 0x%llx, %u B\n", + reg->dst_addr, reg->size); + dst_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, reg->size); if (!dst_addr) { dev_err(dev, "Failed to allocate address\n"); @@ -524,6 +538,8 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test, bool use_dma) buf = kzalloc(reg->size, GFP_KERNEL); if (!buf) { + dev_err(dev, "Alloc %zu B for write failed\n", + (size_t)reg->size); ret = -ENOMEM; goto err_map_addr; } @@ -580,7 +596,7 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test, bool use_dma) return ret; } -static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, u8 irq_type, +static int pci_epf_test_raise_irq(struct pci_epf_test *epf_test, u8 irq_type, u16 irq) { struct pci_epf *epf = epf_test->epf; @@ -588,26 +604,35 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, u8 irq_type, struct pci_epc *epc = epf->epc; enum pci_barno test_reg_bar = epf_test->test_reg_bar; volatile struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + int ret; reg->status |= STATUS_IRQ_RAISED; switch (irq_type) { case IRQ_TYPE_LEGACY: - pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, - PCI_EPC_IRQ_LEGACY, 0); + dev_dbg(&epf->dev, "RAISE legacy IRQ\n"); + ret = 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); + dev_dbg(&epf->dev, "RAISE MSI IRQ %d\n", (int)irq); + ret = pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, + PCI_EPC_IRQ_MSI, irq); break; case IRQ_TYPE_MSIX: - pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, - PCI_EPC_IRQ_MSIX, irq); + dev_dbg(&epf->dev, "RAISE MSIX IRQ %d\n", (int)irq); + ret = pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, + PCI_EPC_IRQ_MSIX, irq); break; default: dev_err(dev, "Failed to raise IRQ, unknown type\n"); - break; + return -EINVAL; } + + if (ret) + dev_err(dev, "Raise IRQ failed %d\n", ret); + + return ret; } static void pci_epf_test_cmd_handler(struct work_struct *work) @@ -684,8 +709,11 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) 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) + if (reg->irq_number > count || count <= 0) { + dev_err(dev, "Invalid MSI %d / %d\n", + (int)reg->irq_number, (int)count); 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); @@ -694,14 +722,19 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) 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) + if (reg->irq_number > count || count <= 0) { + dev_err(dev, "Invalid MSIX %d / %d\n", + (int)reg->irq_number, (int)count); 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; } + dev_err(dev, "Unknown command 0x%x\n", command); + reset_handler: queue_delayed_work(kpcitest_workqueue, &epf_test->cmd_handler, msecs_to_jiffies(1)); @@ -828,12 +861,14 @@ static int pci_epf_test_notifier(struct notifier_block *nb, unsigned long val, switch (val) { case CORE_INIT: + dev_dbg(&epf->dev, "CORE_INIT event\n"); ret = pci_epf_test_core_init(epf); if (ret) return NOTIFY_BAD; break; case LINK_UP: + dev_dbg(&epf->dev, "LINK_UP event\n"); queue_delayed_work(kpcitest_workqueue, &epf_test->cmd_handler, msecs_to_jiffies(1)); break; @@ -875,8 +910,12 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) test_reg_size = test_reg_bar_size + msix_table_size + pba_size; if (epc_features->bar_fixed_size[test_reg_bar]) { - if (test_reg_size > bar_size[test_reg_bar]) + if (test_reg_size > bar_size[test_reg_bar]) { + dev_err(&epf->dev, "BAR %d: %zu B > %zu B\n", + (int)test_reg_bar, test_reg_size, + (size_t)bar_size[test_reg_bar]); return -ENOMEM; + } test_reg_size = bar_size[test_reg_bar]; } @@ -938,8 +977,10 @@ static int pci_epf_test_bind(struct pci_epf *epf) bool linkup_notifier = false; bool core_init_notifier = false; - if (WARN_ON_ONCE(!epc)) + if (WARN_ON_ONCE(!epc)) { + dev_err(&epf->dev, "No controller\n"); return -EINVAL; + } epc_features = pci_epc_get_features(epc, epf->func_no, epf->vfunc_no); if (!epc_features) { @@ -950,8 +991,10 @@ static int pci_epf_test_bind(struct pci_epf *epf) linkup_notifier = epc_features->linkup_notifier; core_init_notifier = epc_features->core_init_notifier; test_reg_bar = pci_epc_get_first_free_bar(epc_features); - if (test_reg_bar < 0) + if (test_reg_bar < 0) { + dev_err(&epf->dev, "No free BAR\n"); return -EINVAL; + } pci_epf_configure_bar(epf, epc_features); epf_test->test_reg_bar = test_reg_bar; From patchwork Wed Feb 15 03:21:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13141258 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 BEDB5C05027 for ; Wed, 15 Feb 2023 03:22:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229773AbjBODWW (ORCPT ); Tue, 14 Feb 2023 22:22:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232625AbjBODWV (ORCPT ); Tue, 14 Feb 2023 22:22:21 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD1C23344C for ; Tue, 14 Feb 2023 19:22:14 -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=1676431334; x=1707967334; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HqW3zLj+zMnKFjU8rhX70g8NHjaasT8LhoX1MesHtKg=; b=i5/IZqAsg/1qL6PT1tRiY8ILCw06KeVdJmBBwcSRPYg1sGN8Cq2PQ+4M aHdN+WiKJeiyfMNkMRlRBCy7dXGyK6HVC432Bl/lZCzpNDymrfZNKXsOD lJ+bqxrlTdLCXpUuPbWVwnED8Lnw0o1vaB4fjJC3vRMa+ij3T+UCYPIYI SBuWdVGuxgWIiDO33nqZTEBAsCVbLuHxgXgOQuJY0ut4h89IJVyP1qFPx wS+XkaF2Cr7ysw+ie1Yq6Mz8lu3j5vS2Aip2DuvjHNpKwkAtr7A8ixCMn 2JnQxf+7Cjr04vUZVECemtJCOlfPmlTUwXq3M5ymLvhsFW4sZhW6oqAQ0 A==; X-IronPort-AV: E=Sophos;i="5.97,298,1669046400"; d="scan'208";a="223351461" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 11:22:14 +0800 IronPort-SDR: Xh4pMNtNiPoZ3DSydnwpfZ++zNe1STsCa1Pnzx5OFlsdIPITPsk5NtCHwtOYGBsDzYjByZI0+e f8nbkIcM+uRgAhf1mk0vUWVt2jRtvFngQqN/n2yKhdhQnvmnN6VqnRIHskGU3E+MlCeXwV/TyZ yGPtQccXunUxH34ATiB45sTEXwGAX4Qa4Cahpy/67OIubaE085pcUjPxigERLvFedmmmleYoca QtYu6Chn0Tib5nzwta1uHvhaWt7RJRBXtW9SiQLKNaHxXp6IvMqTrks7IP7gRxz2odV1mISUsL 0mo= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 18:33:37 -0800 IronPort-SDR: xcX0tbCPkW2FQ/LW1MNOs96oD8AzGIM6+z4uDhTJ8KJvuViWf0t5vM9/Q91jO0oDxdT5zQ8t9K ZjrQumFeh69qZbKXwMrJyH99Sl54jlMCxFSzHDzKnFVnUoc1uCGBIKsSmn3+scJhS9f03uid2V 9BfH0T2pCBcCNpXucxZ+Ugcly+XxePcVOseXec7d0fV47G30rmxyAfeOKb0z2lnPZuerwIlgtA fWmoG+lEb/jLgf9VOeXYVji7NOqRH1jPr2YNV2wVBK+YwbKqmdXX5siOV+m0YC7bHM+jxI829B Xs4= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 19:22:13 -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 4PGk062jTvz1Rwrq for ; Tue, 14 Feb 2023 19:22:14 -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=1676431333; x=1679023334; bh=HqW3zLj+zMnKFjU8rh X70g8NHjaasT8LhoX1MesHtKg=; b=dPOgLoO9gz4WrWrcHO18RXiljBxkku6YJ0 AyBLxNJGvnwP3aIE6nD/yp3Uqwcy1L9p8CgZHBL7W/f0AQ0+wwEo4IIdtMtot+vy HnpmYCyDg0EqOoLjts/kRhFL1F3OxI8UEBKw+9S2LW+R4NTZfUMm4B6HI4i4GGsL RgZ3a6SUV04LwX25pN58loV/Z7ejYY0n6Ghl/rTlcC1kk93NgwXgUPGyxyejLRw2 Ovq6el3y2xgzNzpu+S1ZUNgQqUoEGatRXz668Atsjmxw3bkwHCgSxPMEGKx3LUPq MF7zm1uDB2IOaGu7TB/zdjaRqbMfuNipuvfZ3BD3xmyqXkXNzNCA== 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 mfwWDFnmLhCF for ; Tue, 14 Feb 2023 19:22:13 -0800 (PST) Received: from fedora.flets-east.jp (unknown [10.225.163.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PGk041bt0z1RvLy; Tue, 14 Feb 2023 19:22:12 -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 08/12] misc: pci_endpoint_test: Free IRQs before removing the device Date: Wed, 15 Feb 2023 12:21:51 +0900 Message-Id: <20230215032155.74993-9-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230215032155.74993-1-damien.lemoal@opensource.wdc.com> References: <20230215032155.74993-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. 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 11530b4ec389..e27d471cc847 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -937,6 +937,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); @@ -946,9 +949,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 Feb 15 03:21:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13141259 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 E2DACC05027 for ; Wed, 15 Feb 2023 03:22:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232248AbjBODWZ (ORCPT ); Tue, 14 Feb 2023 22:22:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232655AbjBODWY (ORCPT ); Tue, 14 Feb 2023 22:22:24 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F162A32E76 for ; Tue, 14 Feb 2023 19:22:16 -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=1676431336; x=1707967336; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dJAY0cfcit6GrAbz/aj8uVJ/E88JV8yo1qsmIy6zvY8=; b=EDYvam0kJd/7sUO9k+thvvpjPbn9om+W1b2vCMG8o+xmlY0TSkffDpVU F17h6M974GyXzUsvN+5TIoFe263A9N/QFuvrE8rOnBPYHzsDMvLhZSTDw pJUT/XM2Rs1aw96hE1m7AY/lCx9g3i2u0/fKgo519Hhr4RMO4z1UwLHT5 3NiSIWMk0xxKeUq8wWwujD+/Acg291usqFFTIsbpiT7BfPaZ5qhU+qu6i FAhUmYUJ9OHoh5LX8S4OrIbYjsW5X1RZ56rh69HUerYj8MAmuF/ElAzHS IMWBwIB+sGeAZLpzXoCsCBL9eAconBZHYhGqOZncYfbJ1QXHuzkJcQtmd Q==; X-IronPort-AV: E=Sophos;i="5.97,298,1669046400"; d="scan'208";a="223351464" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 11:22:16 +0800 IronPort-SDR: zhevCybJ0T9CldeY5uwSnmhMMkrOF9k0rahfjAyhpJSi9CnNuy8MlVJHwvMJk+WAWYoYz0iGLT 2PAF5icUJSQLPCQvy/plH9JkwPH8gpO8RzQsW6e8CFsFs7JHKKnyQs3wypzy/7q8oG3iCd0DVo YmMwLAirtwEApxAkDzGAo8WiqfKl1SxxTFS/a2XOCZ76tG3HaOcAYCuIMcH9QyMGLoZrmrrZ/W vFhBDxqEiGjFkezRngNF5MSsvH2DQoLaU7cmAb7IURFR1s6HzLFkeXp9etlVvrxi2d3sz1h81H UTE= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 18:33:39 -0800 IronPort-SDR: I0wXkBLL6OXxBKqA+J4dUW1SAv81YQiUKEQAqSTFWoDoZG+d243lUx8ICHoZVVeBfxwejybW9M cqIzY3Ikwlr7k/cet2UDCiBJWj9/cDWeTnAWfhifTBAVBR4DyfhXgUIHgeG/GHEKtjPjr02nVF uw9glk+HLF1AFppo9+zz/F1geXyBD4ywqx4CopAYxKxs4OCAt/i9t0IaqzTgQSuG7oqq9Q6Ak9 ZAMr66RRh9pvFkzNTX4lNBejX0ux5DAcQp2azVJ+DjdB8iqyZSd4fvzAWeUxNA0pFn4Obj+afP 92g= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 19:22:15 -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 4PGk081kJSz1RwtC for ; Tue, 14 Feb 2023 19:22:16 -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=1676431335; x=1679023336; bh=dJAY0cfcit6GrAbz/a j8uVJ/E88JV8yo1qsmIy6zvY8=; b=e2jrhZ6dmvCSgGt/Ch4Oea1kfypTe3LcTy oN/lrxjySvYJetk6d6s+3nCO5vhF6N9QrYyiJ0xuuN3EBpgYsCoI0HmnTMx6bsmJ XcYg28svYDLigPGKppWCUr31zbTMKnfIN5O2fSPrE8MLNhMjW+CcgUubm6f6y8lB +aBBm9lbe/8u4X0Zamg3KrnKr/dS2k82yFgz6Glwh/6sOja3WB7NhRdjsqT8R9CD Sv/DmoU7uvfJUtidh0+BUEKHYjo889WTsrJMej1l52fJWsceL0ksjqBCS5O3+2WV OHlsMf011bnrDa/UYE0ZXrsGXfohIxbXHD4s6kODaiD+ufwkb3EQ== 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 UQOTBHkDVL6q for ; Tue, 14 Feb 2023 19:22:15 -0800 (PST) Received: from fedora.flets-east.jp (unknown [10.225.163.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PGk061pVDz1RvTp; Tue, 14 Feb 2023 19:22:13 -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 09/12] misc: pci_endpoint_test: Do not write status in IRQ handler Date: Wed, 15 Feb 2023 12:21:52 +0900 Message-Id: <20230215032155.74993-10-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230215032155.74993-1-damien.lemoal@opensource.wdc.com> References: <20230215032155.74993-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 e27d471cc847..c1370950c79d 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -158,10 +158,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 Feb 15 03:21:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13141260 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 A755BC05027 for ; Wed, 15 Feb 2023 03:22:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232349AbjBODWb (ORCPT ); Tue, 14 Feb 2023 22:22:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229581AbjBODWa (ORCPT ); Tue, 14 Feb 2023 22:22:30 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F0C42B60B for ; Tue, 14 Feb 2023 19:22:19 -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=1676431338; x=1707967338; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2VT/sdm6SvvLqOCHKDAB8W/lpODc5iwnE+Tpa+Nv/gU=; b=AoJ71rNZAvmYzg6XGNCv4CqJ5/8lnSnfvcEosOhL7Izvol6ONGFTSv6G B+1kWul7Qg7eu7YaUDIBHb8KSr/NWCwiJ09kUIekfo5XEg9uDUG+NmFfd bFf60Loz6iWr6TB35xRIXKZHNhv951k8aCNqSTqLQgQK1YIz3iCWL1UM6 GRxZtCk5io7RL1J8E+3fXwtV7h6ISH5eZUi+Tv4ysLJqLWt/GUZ3xMY5j nJGZDtywO+2nqavHFFM3TUb+Jx5xcnkeHsRxokAJZIrZJpLOMjE9zCCPV nVQoI1GRTkPMgKr3JYEC3xJvM7vUuSw/FL+vU8KiCmjOKXCwoKRZpiUEO g==; X-IronPort-AV: E=Sophos;i="5.97,298,1669046400"; d="scan'208";a="223351471" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 11:22:18 +0800 IronPort-SDR: kHcKWJu3mSNyIcTeCXYqtMywD9Yw4VOH9bRskrUxmYPlFi5jEHb8TDG4T0J88XrKt0bk8xOTd7 zzS6S2xEQmArY4/ebS9r3TEGWKlZVJeOD73b2s9NFTUGfvis6ZFf5a88TZiM643gRGD4Di06gI U7DLdJc/FhxYC0qmRHFj/AQpCeKRPkSFeQ/YeqDUovP8d7hGJQ08G+op6DNrXdC5cVUGzwPAMV tVxFneHe5vUjRWNZp1p8lacy30FwxOsx6OlUjpDuYCGnbOKZM4MZumsV5gQglh+dLmgVrvKgRQ 5fk= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 18:33:41 -0800 IronPort-SDR: +QhHBKRIN2T3ccIQS53qPCKlqJRfzlQmpzSqYYgGq3oVOtqvF7VZlTQA/wMYOhkL5B/pSDTLbJ xwm+f+MuRf+pwXeTYYKja7nhJn4Iigm9veFVKqHMtDgvBQRwjXZUBFsmTaIMbmhIlrOcTaugxu 1RS84QpFyMQXIyb52Iik255PViF7GAxgSCw/ISmTbY1JLpV4NgWYXWNa68dPHbxVhrq520bQHQ hJGCkjA9DPVhwllKQUmY1Am4cq9hxmwDmGwXlbc6/bU7m8ELfL6u24efUOAsOPyQ42NgtwD7vh t7E= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 19:22:18 -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 4PGk0B03r3z1RwvT for ; Tue, 14 Feb 2023 19:22:17 -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=1676431337; x=1679023338; bh=2VT/sdm6SvvLqOCHKD AB8W/lpODc5iwnE+Tpa+Nv/gU=; b=QpaDgsL+UMmyIuhAExPnkZOcufiBYsrbHc iBgu/VcIvaDaKsnxL7N5wkJWtLiP6bCWvHl/7r99Qy/oy6zv4IiaES0Lha2tetGX t0hJIyTWrH5opVCdQ2uEzuX0evUznxangb4EJq6GNs40WZbEIB+sl05xG7EdotSM Pj7QlyKmbF8anAxR7c7wMpMWzjT5g4ykccdjJraAcHEwPvLVYRSLGismKFjOr44d IRMnOxO976Gi2emyYaD7hWUUHfTDHfNuW433FTBCurr57dWKRFZ0llwc4NBpJrRV 1KQDHMdpNIEVdDHPy1RVdpzX7ecG/vz/0WJI5nJNxMGmn1+rYjCQ== 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 RxP1_eGbswAf for ; Tue, 14 Feb 2023 19:22:17 -0800 (PST) Received: from fedora.flets-east.jp (unknown [10.225.163.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PGk076PK3z1RvLy; Tue, 14 Feb 2023 19:22:15 -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 10/12] misc: pci_endpoint_test: Re-init completion for every test Date: Wed, 15 Feb 2023 12:21:53 +0900 Message-Id: <20230215032155.74993-11-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230215032155.74993-1-damien.lemoal@opensource.wdc.com> References: <20230215032155.74993-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. Signed-off-by: Damien Le Moal --- drivers/misc/pci_endpoint_test.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index c1370950c79d..baab08f983a2 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -725,6 +725,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 = -1; + switch (cmd) { case PCITEST_BAR: bar = arg; From patchwork Wed Feb 15 03:21:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13141261 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 4D102C05027 for ; Wed, 15 Feb 2023 03:22:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231236AbjBODWe (ORCPT ); Tue, 14 Feb 2023 22:22:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230196AbjBODWd (ORCPT ); Tue, 14 Feb 2023 22:22:33 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25E6C3346B for ; Tue, 14 Feb 2023 19:22:21 -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=1676431340; x=1707967340; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1vL+k2GBBnXNHmaxFgAGdZo/Iu3gdaY71xSDrxRY62k=; b=WsSuqedu0Q7Omfa02Mic0KCa6nB6FeknuE9VqEolXWfSWquREbduEEdD bMtaIFFPgXTbkWQ5LOOLSQUlXv6Xe6pPY1dmmvOUUk5UDXXHSGgvJ9WSL GPXGWgy/n4hJJUa4I6sYYppPD/HoCyww4cUlgrQwvgb+XGQr0cuwKDvn4 Yhw1iUFodBWO3VqZd6LqaOMGc+UCGRJGWN1vz14CAy743RUqyp0857tWC 2cYzTbBzc6TWnr0lCv8iJW+Gl3faefWeq89WMv1QqtIPS4HUSEil57Jb7 WDFTeh/60w0x05kxddWvE01DFghiARylI5tQS/mOIwrm8UYZFVsDrX8Hu w==; X-IronPort-AV: E=Sophos;i="5.97,298,1669046400"; d="scan'208";a="223351472" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 11:22:19 +0800 IronPort-SDR: 2BupE+Igmv68uv8tJTh21cnGJvSX7XxykeMEYSW4QTtiOU8AqTTeHUdjrIS80y1UHvMnPpXSWo zDMlCnh1gcjECs8vE7qVAUcxJDZsfALR2bLrqg5pKxL5h8fMynsBgRph1gNbS3BmOUp/yD5oHW Zk5T2HDxZ9Ymdw9kpLubuTp0zwJJUDUpoyknhUKzXGX4t+kNFYDeK1c/b9P+7Uur2lr0fyyxkP /o9afVa5TVq3lNZszkG2jmIfWRL4s+OeuiJxq1aRt0gHGllSyDRgJTikO/E2o8hdDAuJ88+Slw DDg= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 18:33:42 -0800 IronPort-SDR: 14lMAcLt11FSymkIHX5gnHgepKNf/1hrFTn04WCZwCw+2G/XoiFql9EHuEsfZzM45N+lKUL8XF 55tGWJpz4o+I/TUbjPLXt5F5tCI9MIHwMeFRVLp8cjm98pJyjrTaDmQhCfFsWkIP/y74Iv7hy5 eQ55PI8ha/vdE4cwFZ5TWVUq3FhPCCsI1LaMT04bEbXjXcgOhDcnWcIOz/1B7LQFrAK+dm2tTY Y8/WsTbeOuJ5OSfJlPVlbqDKuK9EgL+ZdW1kPKRhbI57scTwtl3lVnMiBC98rVIM04tVwxt7q7 czc= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 19:22:19 -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 4PGk0C55YRz1Rwt8 for ; Tue, 14 Feb 2023 19:22: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=1676431339; x=1679023340; bh=1vL+k2GBBnXNHmaxFg AGdZo/Iu3gdaY71xSDrxRY62k=; b=kBPdGaSqzO5tKuXy7ty2jjT/V1AGTrYOhz M6LDcBBHMtu0Pp/V4V2H1BfRr1YxCngQ3RhUpuA9B/IdttKb95AgJoOzz6fcg4u5 hsGrVHg5rkmNmLzSS0SzNVfwHAJREaWWMq0C6QCUFzNq8eX116/a9vg8dh7teGk3 Z8+BQDF4BiwTRkLW2uHiDTn82rQAe5tpcmwtzIp094C3ABwATUOrEajl/unGEVEu pBT1Xru34yqaeYDEIab2OIlZCDPKmxYGGX36ciudYyuAAbRWXXTQNVMmXaZF+eRq 2HicUugsHWVCCStarv5K8y+7qfy8BUO/tonjZtnxqtAHwUrcE9+w== 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 jCyoRjOAxzU9 for ; Tue, 14 Feb 2023 19:22:19 -0800 (PST) Received: from fedora.flets-east.jp (unknown [10.225.163.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PGk094jV6z1RvTp; Tue, 14 Feb 2023 19:22:17 -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 11/12] misc: pci_endpoint_test: Simplify pci_endpoint_test_msi_irq() Date: Wed, 15 Feb 2023 12:21:54 +0900 Message-Id: <20230215032155.74993-12-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230215032155.74993-1-damien.lemoal@opensource.wdc.com> References: <20230215032155.74993-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 baab08f983a2..b05d3db85da8 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -312,21 +312,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, From patchwork Wed Feb 15 03:21:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13141262 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 19B42C05027 for ; Wed, 15 Feb 2023 03:22:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229551AbjBODWi (ORCPT ); Tue, 14 Feb 2023 22:22:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230196AbjBODWh (ORCPT ); Tue, 14 Feb 2023 22:22:37 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 231C633465 for ; Tue, 14 Feb 2023 19:22:24 -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=1676431343; x=1707967343; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YbCnBFArn6l4X/m37mmtEuQyaVaLiec7s7udE1ICfj4=; b=XSmeM8FTT6Ptn4q9fP/QwDHtFpzMo3NkdiOUADU8bHDBvMyUiiB3j/h0 6Ew+9Rtp8/CrTV4MA0kgygD6PHj//csvx2Y/Gjz8qXZiJWZEdrTwYgONP ItFFjGfv4A7c3UhtDzf34eH5+mFRdCs8aFXcg00Vp2cFITAptlk7UP+bu NJVUxsNH/QGJS86PHMopOXG5VyGPfFsASyPIWrr9ZCUGfcXMgjfz463QJ JbkdKUYsm8V9aiQeRKAB7kHpU+LMUvvV+DXh3t59VA2BNrQ9QEuQTUHn5 dVRn9TVDjiRNc14QR96OprEZH3bZB7xYuoQx0avYEJE901SJ5C8/gWh+m g==; X-IronPort-AV: E=Sophos;i="5.97,298,1669046400"; d="scan'208";a="223351475" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 11:22:22 +0800 IronPort-SDR: VIN+n8H8+Ti1nJLXUSqRJUm7y5wYejN1vDnDGsu08HoLuNT+ONPSJ2Re1+KkhVBs+yYWkG8Yt8 6hYAk5cTcKBpICZ698tXznavhtq6vLkZIv+u1oKLCBwc9O0FyPe+z5kKXAsMwWkTvGAQ7Z0JkI PAKi1ddyUo3+9Qfdh1dlTxHCmLfB5SY3ZKlKAtz8PWx9oT0zq/miM56BEJObhZ/gz9B6NExYuB eQG8KgCj6CQzmoWORlklPdDMd5PDb60quYtnzsuH5cPIbfENarMT2Bw+uUxxlucx+zfXAk/gMq pb4= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 18:33:45 -0800 IronPort-SDR: l8eiJVzIhTXZTiRUr7y/jkML8zt8002g6rl9ezo6w77eXp4zoaQ7zZ26DkO3PIyj00luoGwbNP uCSfaAJrmmyGLWE8wBX3agINUVs4HBhL1kavFN3TEmVp6K2IJQhZe6ylwizR3eiUV1U8gHhx6J fAT4b/5X+JHT/2TbbFkko4THFhbVGtwUPURNmTKYObf5qZNaRigC935xPpArFW3DIsjcDZ4msy LQLkXzAoug+ZBIa0BuLfrzto097RZ7g0rhSKvfSCiBV8DPmKLpMeKodWuy7nFqjhN9aMatZ/1J 2sw= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2023 19:22:21 -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 4PGk0F5zzkz1RwvT for ; Tue, 14 Feb 2023 19:22: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=1676431340; x=1679023341; bh=YbCnBFArn6l4X/m37m mtEuQyaVaLiec7s7udE1ICfj4=; b=bx5yK9Zrw82x6ywebyhDK9OcsJ9ZszD9zi /Rcz/sSRuo3NdrCk9Vo0WArPKnjwbKEGZ/I3+9LNFyez2Qr08ZDuQMc19KNUlmoT 04O2XidNTVL2Hah2Mik7bwjKEzVdJSeLMlhxPcaoZk221WBcx9KFxyDIoyayJ4+M 154kvFKjsPUHiOaLzEtzytd5FUrtYLnZ7zLlteMhx5j6BvYHe+FltnpfBcX3BFE6 7CVR+9QF6W4AMLTsTVtH8bBTILE2bnX8U9EAbAFldvZz9SmGceaj3CpG2Ns5kZQw DvkLhDZz99kRpZQjqoe6XZgnYXXQ5AlQAZYucfwpJ93v3pnmNOMQ== 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 pTGcD9H_Kjv1 for ; Tue, 14 Feb 2023 19:22:20 -0800 (PST) Received: from fedora.flets-east.jp (unknown [10.225.163.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4PGk0C3flkz1RvLy; Tue, 14 Feb 2023 19:22:19 -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 12/12] misc: pci_endpoint_test: Add debug and error messages Date: Wed, 15 Feb 2023 12:21:55 +0900 Message-Id: <20230215032155.74993-13-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230215032155.74993-1-damien.lemoal@opensource.wdc.com> References: <20230215032155.74993-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Add dynamic debug messages with dev_dbg() to help troubleshoot issues when running the endpoint tests. The debug messages for errors detected in pci_endpoint_test_validate_xfer_params() are changed to error messages. Signed-off-by: Damien Le Moal --- drivers/misc/pci_endpoint_test.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index b05d3db85da8..c47f6e708ea2 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -267,12 +267,15 @@ static bool pci_endpoint_test_bar(struct pci_endpoint_test *test, u32 val; int size; struct pci_dev *pdev = test->pdev; + struct device *dev = &pdev->dev; if (!test->bar[barno]) return false; size = pci_resource_len(pdev, barno); + dev_dbg(dev, "Test BAR %d, %d B\n", (int)barno, size); + if (barno == test->test_reg_bar) size = 0x4; @@ -291,6 +294,10 @@ static bool pci_endpoint_test_bar(struct pci_endpoint_test *test, static bool pci_endpoint_test_legacy_irq(struct pci_endpoint_test *test) { u32 val; + struct pci_dev *pdev = test->pdev; + struct device *dev = &pdev->dev; + + dev_dbg(dev, "Test legacy IRQ\n"); pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, IRQ_TYPE_LEGACY); @@ -310,6 +317,9 @@ static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test, { u32 val; struct pci_dev *pdev = test->pdev; + struct device *dev = &pdev->dev; + + dev_dbg(dev, "Test MSI%s %d\n", msix ? "X" : "", msi_num); pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, msix ? IRQ_TYPE_MSIX : IRQ_TYPE_MSI); @@ -329,12 +339,12 @@ static int pci_endpoint_test_validate_xfer_params(struct device *dev, struct pci_endpoint_test_xfer_param *param, size_t alignment) { if (!param->size) { - dev_dbg(dev, "Data size is zero\n"); + dev_err(dev, "Data size is zero\n"); return -EINVAL; } if (param->size > SIZE_MAX - alignment) { - dev_dbg(dev, "Maximum transfer data size exceeded\n"); + dev_err(dev, "Maximum transfer data size exceeded\n"); return -EINVAL; } @@ -444,6 +454,10 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, dst_addr = orig_dst_addr; } + dev_dbg(dev, + "Test COPY align %zu, src phys addr 0x%llx, dst phys addr 0x%llx, %zu B\n", + alignment, src_phys_addr, dst_phys_addr, size); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_DST_ADDR, lower_32_bits(dst_phys_addr)); pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_DST_ADDR, @@ -549,6 +563,10 @@ static bool pci_endpoint_test_write(struct pci_endpoint_test *test, addr = orig_addr; } + dev_dbg(dev, + "Test WRITE align %zu, phys addr 0x%llx, %zu B\n", + alignment, phys_addr, size); + crc32 = crc32_le(~0, addr, size); pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_CHECKSUM, crc32); @@ -647,6 +665,10 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test, addr = orig_addr; } + dev_dbg(dev, + "Test READ align %zu, phys addr 0x%llx, %zu B\n", + alignment, phys_addr, size); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_DST_ADDR, lower_32_bits(phys_addr)); pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_DST_ADDR,