From patchwork Tue Oct 25 14:50:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 10856 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1059203wru; Tue, 25 Oct 2022 08:09:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7LBnG/h7YAOhK44yWBSQ2gOdzVmTbBX6+DFi03wGVvRMeJ2M+taG6OD3XmyRcGr1D8KMRP X-Received: by 2002:a05:6402:2707:b0:45c:d8a3:6cfc with SMTP id y7-20020a056402270700b0045cd8a36cfcmr36526030edd.269.1666710596599; Tue, 25 Oct 2022 08:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666710596; cv=none; d=google.com; s=arc-20160816; b=Pyjd2X4SL9n7HjIoc1ld3PQRoLmcu+qCFbdv0oBUWC9ocboG8WIx9A1Jn7cOnDtXWO l176UANYwXGjt3I2Ul6tkubRHz41wuUVQua9jJmBXGi7vVW95/cZW0dyZrKSs1mdP0uS x19IU7gABtxqfOMfAfpTVXgdM253kyk0JUTXdwN7ZFCc5zCO8zAlSp0usPz96qNPP4ce Zk4Bn2KZ8kM5Ca/4vjdndqz0APrdlsd2nWicsKhSSHQ5CwVUOG2THvw5tpSivUcibsY+ /DEc4i+8CRWeBvLwXh/yy2817Y835W/awcjoJnxI6Xc767I3eQk4OR5BF6+y+fidG/Jj OrYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1hyDFi6BwQQxvnWgZlqZn5l8SdU7JiBSKsGQ5Uy8Nc4=; b=aYfwnIjkrB2PKiQ+rZQJeCXThn6yUsHzDghVFzL1L3WlKcDtTWRtk9bnbbem1u+rTw PCx9HHbZTiroiI11tty0bdfMPdnlqu8DvXJNmc9RPeV1hFCtiyy5X7ghjTymuRTxL3rx pqws90fHC16wxc228wqkTdZY41BjM4Cp7tJb/Bwg2WGc0ZS1HJnf+vZQEjZonCIuQ7no 16QWp9xi93tBUBAuU0BXuJC0PM1nnpgFHpU+JKDRZHt/v3PyUsCm/ON2rTJiJjPUJKNW ArN1AkgPaK1Mii8GreL2z9RejYHmfdntPLlsXZaldlJtyyhJUecClG4Z73GGgEgmi+LR zg3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B+Ho+V5z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb3-20020a1709071c8300b007919d2f6517si3445629ejc.737.2022.10.25.08.09.26; Tue, 25 Oct 2022 08:09:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B+Ho+V5z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232877AbiJYOv0 (ORCPT + 99 others); Tue, 25 Oct 2022 10:51:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232806AbiJYOvU (ORCPT ); Tue, 25 Oct 2022 10:51:20 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D0DE19DDA5 for ; Tue, 25 Oct 2022 07:51:19 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id s22-20020a17090a075600b002130d2ad62aso5426996pje.2 for ; Tue, 25 Oct 2022 07:51:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1hyDFi6BwQQxvnWgZlqZn5l8SdU7JiBSKsGQ5Uy8Nc4=; b=B+Ho+V5zB8khfJJf/JNSmJRTSBXzjK3/x2iH3IUW+3k8ukGumO3PIT4Oqu0Ueygspo Vax2mYHRn2gpHjoLFcFFmWflLnvWKnMY9lYch7r2RvnYa9NaxwNLlKdOHv6NxwoPqHKb E2Ft8mkq25TGJCuJ2K7Wn0a77Rua6pyNJ0UHG6tAGUFmEiVT3pnuTayxVJVMJslVe3ZO 41Ddwg65oinyJTz77lx+aN0zPcydn/SJnS45njc2YRDeuIIJ7sx6rn1iFvMKCb6g3gd7 2c3NrnvBmGQhyfYPpMlquqS4Q8pfJhArF6UC494/fU/JNumwwESFGCrhQlCl0ZQ403vg gO/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1hyDFi6BwQQxvnWgZlqZn5l8SdU7JiBSKsGQ5Uy8Nc4=; b=Ses4bC9Tar7jNVTeLfimNrGOCt2brSUfe5TBRqtPTVWgOJe1b9IQ5Vo380aNoLiydr v4BfD+jaGotKZKD0WJ1LcRu+cAVYgzP/RALS6Zf5/G2ZDAaqJYUFD19TdCymSY4UZs6v vnQbj97WpyfFt7hBBd3QvOILD5qnPvuH6N2vNSQhAvUx+mRyuAelFL9GDtRcu56WJKQX LyyDZAkbdlwxwyjXPGfQ/iVlbqs4pTLdlhhTo7S9bTMwEiyYejw6ufzSwkuboTSYZniC +/U52ZWuUL5cplvEvwiGM7UnFzpcF18CmD9JdYvLmZk4wFO+nl9DuYKmMiaBYdHjffJK T3TQ== X-Gm-Message-State: ACrzQf31mUQrWV/9gWvTpJiDxgzloWhZY9dT7Bo5YL5I+yh57/DBh28C JBQDQbe/QWfbBmsUON36uaIXv6jeGsNkNATUOA== X-Received: by 2002:a17:90b:1c82:b0:1ee:eb41:b141 with SMTP id oo2-20020a17090b1c8200b001eeeb41b141mr46560042pjb.143.1666709478981; Tue, 25 Oct 2022 07:51:18 -0700 (PDT) Received: from localhost.localdomain ([117.193.208.236]) by smtp.gmail.com with ESMTPSA id n14-20020a170903110e00b00180cf894b67sm1318765plh.130.2022.10.25.07.51.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 07:51:18 -0700 (PDT) From: Manivannan Sadhasivam To: kishon@kernel.org, lpieralisi@kernel.org, bhelgaas@google.com Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kw@linux.com, robh@kernel.org, vidyas@nvidia.com, vigneshr@ti.com, Manivannan Sadhasivam , Kishon Vijay Abraham I Subject: [PATCH v4 1/5] PCI: dra7xx: Use threaded IRQ handler for "dra7xx-pcie-main" IRQ Date: Tue, 25 Oct 2022 20:20:57 +0530 Message-Id: <20221025145101.116393-2-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221025145101.116393-1-manivannan.sadhasivam@linaro.org> References: <20221025145101.116393-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747672730252474433?= X-GMAIL-MSGID: =?utf-8?q?1747672730252474433?= The "dra7xx-pcie-main" hard IRQ handler is just printing the IRQ status and calling the dw_pcie_ep_linkup() API if LINK_UP status is set. But the execution of dw_pcie_ep_linkup() depends on the EPF driver and may take more time depending on the EPF implementation. In general, hard IRQ handlers are supposed to return quickly and not block for so long. Moreover, there is no real need of the current IRQ handler to be a hard IRQ handler. So switch to the threaded IRQ handler for the "dra7xx-pcie-main" IRQ. Acked-by: Kishon Vijay Abraham I Signed-off-by: Manivannan Sadhasivam --- drivers/pci/controller/dwc/pci-dra7xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/controller/dwc/pci-dra7xx.c b/drivers/pci/controller/dwc/pci-dra7xx.c index 38462ed11d07..4ae807e7cf79 100644 --- a/drivers/pci/controller/dwc/pci-dra7xx.c +++ b/drivers/pci/controller/dwc/pci-dra7xx.c @@ -840,7 +840,7 @@ static int dra7xx_pcie_probe(struct platform_device *pdev) } dra7xx->mode = mode; - ret = devm_request_irq(dev, irq, dra7xx_pcie_irq_handler, + ret = devm_request_threaded_irq(dev, irq, NULL, dra7xx_pcie_irq_handler, IRQF_SHARED, "dra7xx-pcie-main", dra7xx); if (ret) { dev_err(dev, "failed to request irq\n"); From patchwork Tue Oct 25 14:50:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 10852 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1057945wru; Tue, 25 Oct 2022 08:07:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5u0D1jTq0qvYgb+4wiNSOYD/ybhP8hKS/CVr+jbFXJ/5Pfn0RRy43uW1BD/aNG3KirpxgI X-Received: by 2002:a17:90b:3886:b0:213:1e8:b8a6 with SMTP id mu6-20020a17090b388600b0021301e8b8a6mr14339262pjb.225.1666710474305; Tue, 25 Oct 2022 08:07:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666710474; cv=none; d=google.com; s=arc-20160816; b=dIaajyyAXruiCihcSt8QYBhUW3mT2z+9OzodK10Z62tI1WRJxq966gVq0kFPW0JjfO d6OPSEZsWIf+bCcmc8MfAn6knlkCfxmz5q08qGA3fSbUxfOMFkt1WJexe7uisjr2Fof3 aZL0Oo/L/T5Jw4jFpOMHIkzzTmRZ6/Xe4SP1gecGBH37H0BDzq8nAZsR3OKZqpt6ws6R Nv4MeoivBuCiexpVRNW+U36WqxE6thqHHHdNa88hLjyfmqt5nMEh/wniBzRCtbQLoqUg IXJRD5SPGYOaQ16xPzdYeDle6Y5tJNr/y+ps04P1yK1h3zTusbOHXw/orLwGuJ6I23HS dcYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xlR6S9guDT9sPWfcvESvWKmdq7t2wt4CcZ/x6tOD8xg=; b=eeI2p5bE0AVsvEggc61ZaYg2SxkKZSKqCxTJ/vaZ1GJrhd3Vj37bd+vfutDYIXr4N0 qdg3ieNFb+uwXqXfoZ+ztfF4YtKnFGh0ne+UrJ6aIS1ErE+9cLSTUhe8L/vIvPltZuUx RDiDZ8J5nbm+xhHaY0S/uuYHPNGE+bmGb3AEBd4KQPqeioSClRMBpJ9310VSbegfPy6I dO1i3yLrcfdArwFwtKi24napRgcT6zKADLpls3cbATqioDa3Ld6JY0sf9b7UoyGvByyX xT+HbKk74/cBfDWMSnFSwcuTvHaXV3uHZdjvZZYNPI3pc72fXL7DHd5byOlsNsNBS56i y82w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X8hhfHjP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mw6-20020a17090b4d0600b00212d63cd243si15255104pjb.109.2022.10.25.08.07.20; Tue, 25 Oct 2022 08:07:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X8hhfHjP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232850AbiJYOv2 (ORCPT + 99 others); Tue, 25 Oct 2022 10:51:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232860AbiJYOvZ (ORCPT ); Tue, 25 Oct 2022 10:51:25 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A16819E00C for ; Tue, 25 Oct 2022 07:51:24 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id c24so11148129pls.9 for ; Tue, 25 Oct 2022 07:51:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xlR6S9guDT9sPWfcvESvWKmdq7t2wt4CcZ/x6tOD8xg=; b=X8hhfHjP0ZTomxWkO4/xuAcDDkxtY8PakMk51H+wqHBEn4jVYn2wMHVizShCttm02p RlSOodLMjzDprEhF00Y08hBCBy/rUHPuNPpvEVN7yoJLWsuEK0VKflDMgQTpNfPyZG8X NcoxL++w7sMiyvAv4n9x34NbvvOb2wwEB680t2KzQAXLHYf9W+gt8t3YBCS7/rX+TKAr ZFb/b+oxQajUVk5pOeGS94yP96EU93RgXWslI1p9TRbrCQzbFCiGPkk4iIBjjkUmUBIE /ykkGGBlkfe7C/6EiYpOx8jlUjzUOf3wSp215wI9ohcP8AFDRQlwOu2/Y328fv8p8aY6 0qqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xlR6S9guDT9sPWfcvESvWKmdq7t2wt4CcZ/x6tOD8xg=; b=jpJBbtKBVS6Q+aAaKOirhGdp/UNCdzXrjGRLYtXfvOvctrMdQDCdSC2NmIWnhui+BY /q1i134i7Hidlu3fqixwPDp1NwM7TLO/2sWCiF4y6M9itqDqBVtxJ2K1aKlqwDcgLwMf 1UkVz3SX9Zcbpkvxy9YyLiboLrEJrHV0EGB8mBA6RUOCCYklkqArrZ18h3P7c6FO20e5 oBq3WXeREkLJfQOa/hcY2FUUs7IrmAWM3bsJN85sFlhHlnHq3W7Ua+7gKYU+im7OW4Lu nPH3/c0s3g99LG9RHYi7+bDB8Qaoz4p86CmexbhpHNk5xy6r5jMhM0jBjZzRtW19qi7M PlnQ== X-Gm-Message-State: ACrzQf1EX85b7l3jIC2y5j1z7K0suus+pSFRPgRlP2z4YKYHd2y4SX4S wRI/UiF5YdteIBkjfS3teVzH X-Received: by 2002:a17:902:bd05:b0:179:bbad:acff with SMTP id p5-20020a170902bd0500b00179bbadacffmr38091051pls.170.1666709483815; Tue, 25 Oct 2022 07:51:23 -0700 (PDT) Received: from localhost.localdomain ([117.193.208.236]) by smtp.gmail.com with ESMTPSA id n14-20020a170903110e00b00180cf894b67sm1318765plh.130.2022.10.25.07.51.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 07:51:22 -0700 (PDT) From: Manivannan Sadhasivam To: kishon@kernel.org, lpieralisi@kernel.org, bhelgaas@google.com Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kw@linux.com, robh@kernel.org, vidyas@nvidia.com, vigneshr@ti.com, Manivannan Sadhasivam Subject: [PATCH v4 2/5] PCI: tegra194: Move dw_pcie_ep_linkup() to threaded IRQ handler Date: Tue, 25 Oct 2022 20:20:58 +0530 Message-Id: <20221025145101.116393-3-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221025145101.116393-1-manivannan.sadhasivam@linaro.org> References: <20221025145101.116393-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747672602761563609?= X-GMAIL-MSGID: =?utf-8?q?1747672602761563609?= dw_pcie_ep_linkup() may take more time to execute depending on the EPF driver implementation. Calling this API in the hard IRQ handler is not encouraged since the hard IRQ handlers are supposed to complete quickly. So move the dw_pcie_ep_linkup() call to threaded IRQ handler. Signed-off-by: Manivannan Sadhasivam --- drivers/pci/controller/dwc/pcie-tegra194.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c index 1b6b437823d2..a0d231b7a435 100644 --- a/drivers/pci/controller/dwc/pcie-tegra194.c +++ b/drivers/pci/controller/dwc/pcie-tegra194.c @@ -287,6 +287,7 @@ struct tegra_pcie_dw { struct gpio_desc *pex_refclk_sel_gpiod; unsigned int pex_rst_irq; int ep_state; + long link_status; }; static inline struct tegra_pcie_dw *to_tegra_pcie(struct dw_pcie *pci) @@ -450,9 +451,13 @@ static void pex_ep_event_hot_rst_done(struct tegra_pcie_dw *pcie) static irqreturn_t tegra_pcie_ep_irq_thread(int irq, void *arg) { struct tegra_pcie_dw *pcie = arg; + struct dw_pcie_ep *ep = &pcie->pci.ep; struct dw_pcie *pci = &pcie->pci; u32 val, speed; + if (test_and_clear_bit(0, &pcie->link_status)) + dw_pcie_ep_linkup(ep); + speed = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA) & PCI_EXP_LNKSTA_CLS; clk_set_rate(pcie->core_clk, pcie_gen_freq[speed - 1]); @@ -499,7 +504,6 @@ static irqreturn_t tegra_pcie_ep_irq_thread(int irq, void *arg) static irqreturn_t tegra_pcie_ep_hard_irq(int irq, void *arg) { struct tegra_pcie_dw *pcie = arg; - struct dw_pcie_ep *ep = &pcie->pci.ep; int spurious = 1; u32 status_l0, status_l1, link_status; @@ -515,7 +519,8 @@ static irqreturn_t tegra_pcie_ep_hard_irq(int irq, void *arg) link_status = appl_readl(pcie, APPL_LINK_STATUS); if (link_status & APPL_LINK_STATUS_RDLH_LINK_UP) { dev_dbg(pcie->dev, "Link is up with Host\n"); - dw_pcie_ep_linkup(ep); + set_bit(0, &pcie->link_status); + return IRQ_WAKE_THREAD; } } From patchwork Tue Oct 25 14:50:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 10851 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1057813wru; Tue, 25 Oct 2022 08:07:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7mWdExCsGQmP4W4sYXgR3JRL07bZHcQ0yp/0ekxH1zfxA4lZNs1AgqyTQNsasziDbqNQhY X-Received: by 2002:a65:4bc3:0:b0:439:103b:fc35 with SMTP id p3-20020a654bc3000000b00439103bfc35mr32955619pgr.248.1666710461378; Tue, 25 Oct 2022 08:07:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666710461; cv=none; d=google.com; s=arc-20160816; b=WST+h0I8LzWHFpHLUP1kge8MlSvpdDf89McLIt6uLNZIETsIJ96QcDZfLqv95mTqDt KZMnYmIScq8D1cSCX3dZ2uiJjdOXRzXZQguQ52F4xwdjm8LKdXDNvFZQplEf8bEmq3vX xpTYllf9ORVFUAeBfjiq/nDOuyaff8nPcIB8Mqalyj5P+LKWCTWAhhT5n+6ZCN6oAF6E /EqMRicIY4jVWpCYNfGQgyULG7IMj/Q/nQT2InN0bv027837RaPRbZtdwrqHew0WW3I3 a8iAAyTYsta4JaWD3oTkzadH6fjRdlUiXQ5XM3DrRU8PhCZF6YmdSr/n/vfta/WQ/cZ4 kfig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jlONzOG1Sfig+UyBXL2V5B2sybs7pn6sgdhK0vy4e48=; b=XwKlS7SRIV3XVta2Xw+nLfWlEWaQeN/Ax6fIdOBuwMs62Iq0P4EkJ1T8BfgaRqax/b uINOQLshseZdoC4GCJ8iVb/Br6D5jssPxBYEm9RWztD4GWq7KY/CIzTrD+zGo0QponxR tmEPg3ucSRSR/+vbR0oFYY/fab3vLnTtKJH1UscG5spafjDqUCTwW8nvM6BshHfImaan eLrj6OD9DtJDhfTR4TDSBFJFDOmZmIeaeeV+hp+YU9broGLxOO4Dgym2ZaGs1iKBBvke MHiLo1yvuDuGplPTC06RoXREiWbfrn3pgalBE3WqlUfWTIJsKMiPKlQFCxjZRUJ1lEsu cvAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="L37DM/hg"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p11-20020a17090ab90b00b002130aa8a7c7si3186384pjr.113.2022.10.25.08.07.09; Tue, 25 Oct 2022 08:07:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="L37DM/hg"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230012AbiJYOvg (ORCPT + 99 others); Tue, 25 Oct 2022 10:51:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232904AbiJYOva (ORCPT ); Tue, 25 Oct 2022 10:51:30 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96FB11A2E07 for ; Tue, 25 Oct 2022 07:51:29 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id w189so10585563pfw.4 for ; Tue, 25 Oct 2022 07:51:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jlONzOG1Sfig+UyBXL2V5B2sybs7pn6sgdhK0vy4e48=; b=L37DM/hgXDmzR5hLLsgWEwzvZg7/FD4jPz3U3YlRCDu+vIAHyT8zpE9qbH/LBNhaY/ 2N6lR1HgTyDoWSxWAD/FQi81drHaZpmOSqjamnWyDrqcCAJdy0B5qmwfPlC7JEbd6Rbr fwMOLbaUnp0HEkhTDEVgP4muugSNAgVjuPymKFl1EEJTyFub36iSPFbBcmGWm9ZBbE8W UNxF+9KsobFWG125JxOehz588g45HreQ1+LaQ9ivOmheEhQtkwJMNcgc8qbsQAVycpm9 Ksb5NPlU0c7oi6PJI8MfUYnracno5TH+b9Dy5BI9bcHlUJnhI+x06XcNYdhgYBM+YQRh y48A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jlONzOG1Sfig+UyBXL2V5B2sybs7pn6sgdhK0vy4e48=; b=fkNe36J44VWBNuFxLLU/DKHZAhIFpnaIUD/ATxiIYChgR/MxpEnV1UfLIsDTixvePs 1SJuXi/hrYouj2kVe+/q+uQ57jvqC1ca2cEj0Jyn1NSGt50YZ3Uf2MN9RDT4Lz7QfmTn 3Rnt1NC4l/8GLEw2cmU5CKGYZcKiTqWN4/1LDD1mxBZ7jtxeQBhInSEgDAqLnJxpFMjK hQTxfXu1szY79/+vinNAK4DJmVPAb81E1Nr24ZbU60oq8waazGfvMRkqzRixK6rpiYS5 VlYQkndUbLqFYZACe5Z9MejnW7+LQAd9MhOhpA9ngkCsEKSbuWq7saAXIfDcSBlwzyjF Pz2Q== X-Gm-Message-State: ACrzQf1OEdPzIugA9iy2RlSDPgEnoJPBNgfJl2Y+EXyBJl79mJIkxa2a ntU//uuolP0uYdtJkROzgaY2 X-Received: by 2002:a63:a13:0:b0:440:a593:b79f with SMTP id 19-20020a630a13000000b00440a593b79fmr32533408pgk.557.1666709489059; Tue, 25 Oct 2022 07:51:29 -0700 (PDT) Received: from localhost.localdomain ([117.193.208.236]) by smtp.gmail.com with ESMTPSA id n14-20020a170903110e00b00180cf894b67sm1318765plh.130.2022.10.25.07.51.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 07:51:28 -0700 (PDT) From: Manivannan Sadhasivam To: kishon@kernel.org, lpieralisi@kernel.org, bhelgaas@google.com Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kw@linux.com, robh@kernel.org, vidyas@nvidia.com, vigneshr@ti.com, Manivannan Sadhasivam , Kishon Vijay Abraham I Subject: [PATCH v4 3/5] PCI: endpoint: Use a separate lock for protecting epc->pci_epf list Date: Tue, 25 Oct 2022 20:20:59 +0530 Message-Id: <20221025145101.116393-4-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221025145101.116393-1-manivannan.sadhasivam@linaro.org> References: <20221025145101.116393-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747672588606847083?= X-GMAIL-MSGID: =?utf-8?q?1747672588606847083?= The EPC controller maintains a list of EPF drivers added to it. For protecting this list against the concurrent accesses, the epc->lock (used for protecting epc_ops) has been used so far. Since there were no users trying to use epc_ops and modify the pci_epf list simultaneously, this was not an issue. But with the addition of callback mechanism for passing the events, this will be a problem. Because the pci_epf list needs to be iterated first for getting hold of the EPF driver and then the relevant event specific callback needs to be called for the driver. If the same epc->lock is used, then it will result in a deadlock scenario. For instance, ... mutex_lock(&epc->lock); list_for_each_entry(epf, &epc->pci_epf, list) { epf->event_ops->core_init(epf); | |-> pci_epc_set_bar(); | |-> mutex_lock(&epc->lock) # DEADLOCK ... So to fix this issue, use a separate lock called "list_lock" for protecting the pci_epf list against the concurrent accesses. This lock will also be used by the callback mechanism. Acked-by: Kishon Vijay Abraham I Signed-off-by: Manivannan Sadhasivam --- drivers/pci/endpoint/pci-epc-core.c | 9 +++++---- include/linux/pci-epc.h | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 3bc9273d0a08..6cce430d431b 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -613,7 +613,7 @@ int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf, if (type == SECONDARY_INTERFACE && epf->sec_epc) return -EBUSY; - mutex_lock(&epc->lock); + mutex_lock(&epc->list_lock); func_no = find_first_zero_bit(&epc->function_num_map, BITS_PER_LONG); if (func_no >= BITS_PER_LONG) { @@ -640,7 +640,7 @@ int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf, list_add_tail(list, &epc->pci_epf); ret: - mutex_unlock(&epc->lock); + mutex_unlock(&epc->list_lock); return ret; } @@ -672,11 +672,11 @@ void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf, list = &epf->sec_epc_list; } - mutex_lock(&epc->lock); + mutex_lock(&epc->list_lock); clear_bit(func_no, &epc->function_num_map); list_del(list); epf->epc = NULL; - mutex_unlock(&epc->lock); + mutex_unlock(&epc->list_lock); } EXPORT_SYMBOL_GPL(pci_epc_remove_epf); @@ -773,6 +773,7 @@ __pci_epc_create(struct device *dev, const struct pci_epc_ops *ops, } mutex_init(&epc->lock); + mutex_init(&epc->list_lock); INIT_LIST_HEAD(&epc->pci_epf); ATOMIC_INIT_NOTIFIER_HEAD(&epc->notifier); diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index a48778e1a4ee..fe729dfe509b 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -122,6 +122,7 @@ struct pci_epc_mem { * struct pci_epc - represents the PCI EPC device * @dev: PCI EPC device * @pci_epf: list of endpoint functions present in this EPC device + * list_lock: Mutex for protecting pci_epf list * @ops: function pointers for performing endpoint operations * @windows: array of address space of the endpoint controller * @mem: first window of the endpoint controller, which corresponds to @@ -139,6 +140,7 @@ struct pci_epc_mem { struct pci_epc { struct device dev; struct list_head pci_epf; + struct mutex list_lock; const struct pci_epc_ops *ops; struct pci_epc_mem **windows; struct pci_epc_mem *mem; From patchwork Tue Oct 25 14:51:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 10853 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1057960wru; Tue, 25 Oct 2022 08:07:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7MqdqgSS38M39zTB1SxYKl5LPvWqmoxVGkf5Sw3nQX2bIVH30CKXK/OoWWdRLbwSK/ZjUS X-Received: by 2002:a17:90a:2bcb:b0:20a:ea55:32ef with SMTP id n11-20020a17090a2bcb00b0020aea5532efmr80905002pje.59.1666710476541; Tue, 25 Oct 2022 08:07:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666710476; cv=none; d=google.com; s=arc-20160816; b=iCsZ94Z1ZLRAXUAWtYIO+dzrpzBGPu7swSFzBKqHx6OmXzmGCp6870MffAF4dsRg6T xImVa/8JaPlwVztKSSKFSm4BnTaf9I4u1L/C5icXQqgIl8Qwub1kgoRQMxLaquZnyszl THw+k4WXYuP+9Pq1IrpYjux4MP02dmhHCCKJYz2/wZFN4CBvP++i8T4EEzCN3Om/WcNM 5ahmA8PKqjyJHMBLJX9xtYvLuWGwvxpIhhCGwfkvzunJ9QIkD6V7rqlwl8sZm/4st/T/ 8o07UEDMv+qUYl85oHnNrhCnRR+48qn9g6c4jyOeuo+4xLET/1pYJv/VWwAvYLz2LRg1 eqjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LPUYLN9W4BCvOlmHzhNojWMMlWjMPl6lRakt+Zvfz6k=; b=QBz9bhbecjPOjZqrxW/0vIa0ZZY3If1YeLWXxTPAAGRCXOwBxpdJpjTsuXjrkE7isu LRbUuAW/Qrx1KGWnhFpsDw+56zmWOIYZ2AWXzy+gKgiL4Cfnz56Vb/zFUnEWs3rNIIpY 08/sBa0SsxkZIhxjFYwHTggarCEuU4Gt3qklrjiM49EJvVmHF9dZr/0NyvpbGvoEJyry 9B8u7gFK54X5IAyXmcxXic32YTq54XVz/woZcrxejoKx7FfoIR0nJgNOucqe2zh91Wiw lry0Giy8KOlD5WcH5fi0KGxusPnm+Cy/W20nGpbJt6nDA3umtgQXu81kovNJuObPafHR 9gXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PC67dz8I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h5-20020a170902f54500b001865d57b179si1522552plf.47.2022.10.25.08.07.35; Tue, 25 Oct 2022 08:07:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PC67dz8I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232048AbiJYOvm (ORCPT + 99 others); Tue, 25 Oct 2022 10:51:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232955AbiJYOvg (ORCPT ); Tue, 25 Oct 2022 10:51:36 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4D8719E92B for ; Tue, 25 Oct 2022 07:51:34 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id f193so11733571pgc.0 for ; Tue, 25 Oct 2022 07:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LPUYLN9W4BCvOlmHzhNojWMMlWjMPl6lRakt+Zvfz6k=; b=PC67dz8I4/JvtNy1bfJNkh5c+zWwXWKjXoxDj7L25zpv2LJLtomaKwVDKr80lSj7pQ b71cZXfskDT3U5cV0/wc+0pwslfshGx9MErUURt48Wg0m2dve0EOZE89oMagI2GhWSgc 0FV7LZqhDtL3UMx2xImkRR44QXCYA6P7YmwnB3fH/sqLn4trX5e1rJacFN67jW0MJO6b /4kICPK23APQHIC3ItVUOXoS7uUYXQ4oKw//qFMe7xOxXOh1BMa/qh43Q26ol4ZUWp0j VpEdvXJCoMi5vYzvdeW8FI8SyIJ0NUADI/UlioFLJ1/tmg/72b5DEFbcfwL+WAS7e/zR 9Xug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LPUYLN9W4BCvOlmHzhNojWMMlWjMPl6lRakt+Zvfz6k=; b=ekA3c/PE3rgaR6XkhBIif6uYNG5F26/iq2T3UgYka03wsAnUA6kB8G2dRMspYBmoup JBV9bBW3p0z+ZvS1vRyL94Psupr/rI0mEQOXHKU2NAlL3PEd5pKdHRs4rsxh2GWRQekk zBQCGNNi5uShmjIXpWfXju99DQEt8GySSZjIHTvb/OpJA3HzcQcYW8nXx+SLBiUrTkzp Eiu1ll/+RTmRu2D9s9MI17JJSBeC6ebyNGA3A0cpgEH7u7VO3NGhSUMFanYC7q/z6/YB Pq3R9yuG3TX0mz390+xcTkTegothjJ7mej5Innkw4zkOQbjOWtu1Z/+SDwjCtsvjtQ/o /m0Q== X-Gm-Message-State: ACrzQf3BAywIq3bE0uW0ksufi4sNO7YCZcrk7sq4rFMxY5uFEPaOLmWT kggFSoAknU8lysGskQFgPTab X-Received: by 2002:a63:8:0:b0:460:e669:a0c4 with SMTP id 8-20020a630008000000b00460e669a0c4mr33328164pga.475.1666709494244; Tue, 25 Oct 2022 07:51:34 -0700 (PDT) Received: from localhost.localdomain ([117.193.208.236]) by smtp.gmail.com with ESMTPSA id n14-20020a170903110e00b00180cf894b67sm1318765plh.130.2022.10.25.07.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 07:51:33 -0700 (PDT) From: Manivannan Sadhasivam To: kishon@kernel.org, lpieralisi@kernel.org, bhelgaas@google.com Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kw@linux.com, robh@kernel.org, vidyas@nvidia.com, vigneshr@ti.com, Manivannan Sadhasivam Subject: [PATCH v4 4/5] PCI: endpoint: Use callback mechanism for passing events from EPC to EPF Date: Tue, 25 Oct 2022 20:21:00 +0530 Message-Id: <20221025145101.116393-5-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221025145101.116393-1-manivannan.sadhasivam@linaro.org> References: <20221025145101.116393-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747672604802789499?= X-GMAIL-MSGID: =?utf-8?q?1747672604802789499?= Instead of using the notifiers for passing the events from EPC to EPF, let's introduce a callback based mechanism where the EPF drivers can populate relevant callbacks for EPC events they want to subscribe. The use of notifiers in kernel is not recommended if there is a real link between the sender and receiver, like in this case. Also, the existing atomic notifier forces the notification functions to be in atomic context while the caller may be in non-atomic context. For instance, the two in-kernel users of the notifiers, pcie-qcom and pcie-tegra194, both are calling the notifier functions in non-atomic context (from threaded IRQ handlers). This creates a sleeping in atomic context issue with the existing EPF_TEST driver that calls the EPC APIs that may sleep. For all these reasons, let's get rid of the notifier chains and use the simple callback mechanism for signalling the events from EPC to EPF drivers. This preserves the context of the caller and avoids the latency of going through a separate interface for triggering the notifications. As a first step of the transition, the core_init() callback is introduced in this commit, that'll replace the existing CORE_INIT notifier used for signalling the init complete event from EPC. During the occurrence of the event, EPC will go over the list of EPF drivers attached to it and will call the core_init() callback if available. Signed-off-by: Manivannan Sadhasivam Acked-by: Kishon Vijay Abraham I --- drivers/pci/endpoint/functions/pci-epf-test.c | 13 ++++++------- drivers/pci/endpoint/pci-epc-core.c | 11 ++++++++++- include/linux/pci-epf.h | 11 ++++++++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index a6f906a96669..868de17e1ad2 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -826,20 +826,17 @@ static int pci_epf_test_core_init(struct pci_epf *epf) return 0; } +static const struct pci_epc_event_ops pci_epf_test_event_ops = { + .core_init = pci_epf_test_core_init, +}; + static int pci_epf_test_notifier(struct notifier_block *nb, unsigned long val, void *data) { struct pci_epf *epf = container_of(nb, struct pci_epf, nb); struct pci_epf_test *epf_test = epf_get_drvdata(epf); - int ret; switch (val) { - case CORE_INIT: - ret = pci_epf_test_core_init(epf); - if (ret) - return NOTIFY_BAD; - break; - case LINK_UP: queue_delayed_work(kpcitest_workqueue, &epf_test->cmd_handler, msecs_to_jiffies(1)); @@ -1010,6 +1007,8 @@ static int pci_epf_test_probe(struct pci_epf *epf, const struct pci_epf_device_i INIT_DELAYED_WORK(&epf_test->cmd_handler, pci_epf_test_cmd_handler); + epf->event_ops = &pci_epf_test_event_ops; + epf_set_drvdata(epf, epf_test); return 0; } diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 6cce430d431b..8bb60528f530 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -707,10 +707,19 @@ EXPORT_SYMBOL_GPL(pci_epc_linkup); */ void pci_epc_init_notify(struct pci_epc *epc) { + struct pci_epf *epf; + if (!epc || IS_ERR(epc)) return; - atomic_notifier_call_chain(&epc->notifier, CORE_INIT, NULL); + mutex_lock(&epc->list_lock); + list_for_each_entry(epf, &epc->pci_epf, list) { + mutex_lock(&epf->lock); + if (epf->event_ops && epf->event_ops->core_init) + epf->event_ops->core_init(epf); + mutex_unlock(&epf->lock); + } + mutex_unlock(&epc->list_lock); } EXPORT_SYMBOL_GPL(pci_epc_init_notify); diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 0c94cc1513bc..a06f3b4c8bee 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -18,7 +18,6 @@ struct pci_epf; enum pci_epc_interface_type; enum pci_notify_event { - CORE_INIT, LINK_UP, }; @@ -72,6 +71,14 @@ struct pci_epf_ops { struct config_group *group); }; +/** + * struct pci_epf_event_ops - Callbacks for capturing the EPC events + * @core_init: Callback for the EPC initialization complete event + */ +struct pci_epc_event_ops { + int (*core_init)(struct pci_epf *epf); +}; + /** * struct pci_epf_driver - represents the PCI EPF driver * @probe: ops to perform when a new EPF device has been bound to the EPF driver @@ -140,6 +147,7 @@ struct pci_epf_bar { * @is_vf: true - virtual function, false - physical function * @vfunction_num_map: bitmap to manage virtual function number * @pci_vepf: list of virtual endpoint functions associated with this function + * @event_ops: Callbacks for capturing the EPC events */ struct pci_epf { struct device dev; @@ -170,6 +178,7 @@ struct pci_epf { unsigned int is_vf; unsigned long vfunction_num_map; struct list_head pci_vepf; + const struct pci_epc_event_ops *event_ops; }; /** From patchwork Tue Oct 25 14:51:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 10854 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1058388wru; Tue, 25 Oct 2022 08:08:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7vlXZibBB7l7dUjNzSbttW9jfvMk8jcAiLUEgwJ7HjgqHov3c1gKYCOjcgcBrGkm9kV4oG X-Received: by 2002:a63:5a63:0:b0:42f:e143:80d4 with SMTP id k35-20020a635a63000000b0042fe14380d4mr33708526pgm.456.1666710521865; Tue, 25 Oct 2022 08:08:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666710521; cv=none; d=google.com; s=arc-20160816; b=pDqXgJh8QhgKSuu+hcuNMWL3nvk6rJFB6QWdIEyqge4fVP9QZjhyRvFStsHDwAHSyz wR48ya0AijpNPl+kfQg9IhoDb+W0tRmMPCaMU4FJ5yJnIuFwIVihqzbH7dNUof1xoCD+ uxQFmWPFtISC1shsXYsVVBRH+Joc/ykEa0CmzeQpvJXSM2xLbDXHR6X9PU7g+0PwaEuB 2gQSXUrzsFdl9Dp7J6YF8nEs/JKlnLZl53Y78nP5NnAtX2BZZRyAO9yzubb0DDb4r+Rw wIZjiS+Nc1wGIOKBdBiM7pkmzwfpCd/44IcKLgqT7SK4Ef7orpcW2mGMKFbven41sjr6 QhLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bw7Z4RPMjDlTxfP4goNyQMmLIpU75uA8NpA0GGnvc1U=; b=ewv2nWvJngTuHn72dH+yrmKWPCqF4xBO/lOd6stNl8F+5hnD7PB4brtXBJaludKGQn j9lnAfsuw90xUtaYmLJYH62v0jO+q7H4288H+PdJ+B/Wpadv7CnYPREUjz+87mvy4e0e b/6SfpQ4U0GhTwgSXQaj/urusoks4GP4z0ZmnnudjTEIoafTV97p4tJIfBRceOO/LpOA Jx/h0nTllBqa3TfBS63J90dexrGYU8+DlrfzuIi5zXurJuiabSoNRgeWpXh0mdyWbe+D mxCAtcx/6Ac0tZrBuxsqDiC71SfRObAQGzCcRxGE85H7lqnh74Adzkr3pLXQWt6aqd9w Sa4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a+CBb66s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o5-20020a170903300500b0017f6a4fd6fbsi2707998pla.123.2022.10.25.08.08.18; Tue, 25 Oct 2022 08:08:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a+CBb66s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233090AbiJYOvw (ORCPT + 99 others); Tue, 25 Oct 2022 10:51:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232042AbiJYOvl (ORCPT ); Tue, 25 Oct 2022 10:51:41 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 375CD1A1B22 for ; Tue, 25 Oct 2022 07:51:40 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id b11so4972734pjp.2 for ; Tue, 25 Oct 2022 07:51:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bw7Z4RPMjDlTxfP4goNyQMmLIpU75uA8NpA0GGnvc1U=; b=a+CBb66sbj/Sz7N6QD3LS0g4wzZIu36Wff1DAp/4R6CHM51XXrgt3G/ReeeyqfhQXo lU7Ln7fxIHwTcoII7sG7oxtibSdW7/F4TFwDDV4o+tfi4ksSR5Zk3hqBrfu7QrTNo+N4 Q9tZT04kbu9dFMGvEH7Xm/QZEj9Xi7mrq2Pba+vLo7ouPPiiJixb25LsbqK/IqhuS+Ex y9YsldAAinuYOFi9tjLA0mzgnV//NrT6V1DOA8cAlIs3BNjC4RvAPDm692+I0hcS+MyN H4Hcf18wj7JWAETiaWA8MsuzK7CRTjw81LXiOVt0KPq755/vc5To8c7WulgTnF3OfijI ySwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bw7Z4RPMjDlTxfP4goNyQMmLIpU75uA8NpA0GGnvc1U=; b=HdN2vFG2SvNkzTQWhQx/ePcaOGsoswQreSwndHp2D+KvkXjU6Ocw5ERmXVct3DiieU KarPzSnmolNvHwt+rBstD3lTaVeDN2O90c+oDY0RN6VqzhXXHl076zS81ymM02U1ie8t t5n3S1+QZpnjmeW+yxNFeAPhLEAx93FuPrv+dw+qDtR4rbJ02cp0n9hem+SG2lIbBr9e btz+YAV3X8sfD9xkHui1SdnwemBEn1Y7v+UvVh/qqvSnWsqgVxiYgE8Zu7j9RynKIlIp bSN57sVg3fIU6PnNK/VdtbE4fCiltKe5qeN52sCdeHqkk13uPepnYBBd4rzJPf1HxdPk 7N6Q== X-Gm-Message-State: ACrzQf0R4KMTyWQ4y2gkTrg/BV3WhEuoBmYy+uATHmeD6qPcpjHoP5rU ikmTS2QKeNwFYpIWtFqbMwfj X-Received: by 2002:a17:90a:cf06:b0:212:d9ab:811b with SMTP id h6-20020a17090acf0600b00212d9ab811bmr23939171pju.65.1666709499611; Tue, 25 Oct 2022 07:51:39 -0700 (PDT) Received: from localhost.localdomain ([117.193.208.236]) by smtp.gmail.com with ESMTPSA id n14-20020a170903110e00b00180cf894b67sm1318765plh.130.2022.10.25.07.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 07:51:38 -0700 (PDT) From: Manivannan Sadhasivam To: kishon@kernel.org, lpieralisi@kernel.org, bhelgaas@google.com Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kw@linux.com, robh@kernel.org, vidyas@nvidia.com, vigneshr@ti.com, Manivannan Sadhasivam Subject: [PATCH v4 5/5] PCI: endpoint: Use link_up() callback in place of LINK_UP notifier Date: Tue, 25 Oct 2022 20:21:01 +0530 Message-Id: <20221025145101.116393-6-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221025145101.116393-1-manivannan.sadhasivam@linaro.org> References: <20221025145101.116393-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747672651723079143?= X-GMAIL-MSGID: =?utf-8?q?1747672651723079143?= As a part of the transition towards callback mechanism for signalling the events from EPC to EPF, let's use the link_up() callback in the place of the LINK_UP notifier. This also removes the notifier support completely from the PCI endpoint framework. Signed-off-by: Manivannan Sadhasivam Acked-by: Kishon Vijay Abraham I --- drivers/pci/endpoint/functions/pci-epf-test.c | 33 ++++++------------- drivers/pci/endpoint/pci-epc-core.c | 12 +++++-- include/linux/pci-epc.h | 8 ----- include/linux/pci-epf.h | 8 ++--- 4 files changed, 22 insertions(+), 39 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 868de17e1ad2..f75045f2dee3 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -826,30 +826,21 @@ static int pci_epf_test_core_init(struct pci_epf *epf) return 0; } -static const struct pci_epc_event_ops pci_epf_test_event_ops = { - .core_init = pci_epf_test_core_init, -}; - -static int pci_epf_test_notifier(struct notifier_block *nb, unsigned long val, - void *data) +int pci_epf_test_link_up(struct pci_epf *epf) { - struct pci_epf *epf = container_of(nb, struct pci_epf, nb); struct pci_epf_test *epf_test = epf_get_drvdata(epf); - switch (val) { - case LINK_UP: - queue_delayed_work(kpcitest_workqueue, &epf_test->cmd_handler, - msecs_to_jiffies(1)); - break; - - default: - dev_err(&epf->dev, "Invalid EPF test notifier event\n"); - return NOTIFY_BAD; - } + queue_delayed_work(kpcitest_workqueue, &epf_test->cmd_handler, + msecs_to_jiffies(1)); - return NOTIFY_OK; + return 0; } +static const struct pci_epc_event_ops pci_epf_test_event_ops = { + .core_init = pci_epf_test_core_init, + .link_up = pci_epf_test_link_up, +}; + static int pci_epf_test_alloc_space(struct pci_epf *epf) { struct pci_epf_test *epf_test = epf_get_drvdata(epf); @@ -976,12 +967,8 @@ static int pci_epf_test_bind(struct pci_epf *epf) if (ret) epf_test->dma_supported = false; - if (linkup_notifier || core_init_notifier) { - epf->nb.notifier_call = pci_epf_test_notifier; - pci_epc_register_notifier(epc, &epf->nb); - } else { + if (!linkup_notifier && !core_init_notifier) queue_work(kpcitest_workqueue, &epf_test->cmd_handler.work); - } return 0; } diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 8bb60528f530..c0954fddcc14 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -690,10 +690,19 @@ EXPORT_SYMBOL_GPL(pci_epc_remove_epf); */ void pci_epc_linkup(struct pci_epc *epc) { + struct pci_epf *epf; + if (!epc || IS_ERR(epc)) return; - atomic_notifier_call_chain(&epc->notifier, LINK_UP, NULL); + mutex_lock(&epc->list_lock); + list_for_each_entry(epf, &epc->pci_epf, list) { + mutex_lock(&epf->lock); + if (epf->event_ops && epf->event_ops->link_up) + epf->event_ops->link_up(epf); + mutex_unlock(&epf->lock); + } + mutex_unlock(&epc->list_lock); } EXPORT_SYMBOL_GPL(pci_epc_linkup); @@ -784,7 +793,6 @@ __pci_epc_create(struct device *dev, const struct pci_epc_ops *ops, mutex_init(&epc->lock); mutex_init(&epc->list_lock); INIT_LIST_HEAD(&epc->pci_epf); - ATOMIC_INIT_NOTIFIER_HEAD(&epc->notifier); device_initialize(&epc->dev); epc->dev.class = pci_epc_class; diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index fe729dfe509b..301bb0e53707 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -135,7 +135,6 @@ struct pci_epc_mem { * @group: configfs group representing the PCI EPC device * @lock: mutex to protect pci_epc ops * @function_num_map: bitmap to manage physical function number - * @notifier: used to notify EPF of any EPC events (like linkup) */ struct pci_epc { struct device dev; @@ -151,7 +150,6 @@ struct pci_epc { /* mutex to protect against concurrent access of EP controller */ struct mutex lock; unsigned long function_num_map; - struct atomic_notifier_head notifier; }; /** @@ -194,12 +192,6 @@ static inline void *epc_get_drvdata(struct pci_epc *epc) return dev_get_drvdata(&epc->dev); } -static inline int -pci_epc_register_notifier(struct pci_epc *epc, struct notifier_block *nb) -{ - return atomic_notifier_chain_register(&epc->notifier, nb); -} - struct pci_epc * __devm_pci_epc_create(struct device *dev, const struct pci_epc_ops *ops, struct module *owner); diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index a06f3b4c8bee..bc613f0df7e3 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -17,10 +17,6 @@ struct pci_epf; enum pci_epc_interface_type; -enum pci_notify_event { - LINK_UP, -}; - enum pci_barno { NO_BAR = -1, BAR_0, @@ -74,9 +70,11 @@ struct pci_epf_ops { /** * struct pci_epf_event_ops - Callbacks for capturing the EPC events * @core_init: Callback for the EPC initialization complete event + * @link_up: Callback for the EPC link up event */ struct pci_epc_event_ops { int (*core_init)(struct pci_epf *epf); + int (*link_up)(struct pci_epf *epf); }; /** @@ -135,7 +133,6 @@ struct pci_epf_bar { * @driver: the EPF driver to which this EPF device is bound * @id: Pointer to the EPF device ID * @list: to add pci_epf as a list of PCI endpoint functions to pci_epc - * @nb: notifier block to notify EPF of any EPC events (like linkup) * @lock: mutex to protect pci_epf_ops * @sec_epc: the secondary EPC device to which this EPF device is bound * @sec_epc_list: to add pci_epf as list of PCI endpoint functions to secondary @@ -164,7 +161,6 @@ struct pci_epf { struct pci_epf_driver *driver; const struct pci_epf_device_id *id; struct list_head list; - struct notifier_block nb; /* mutex to protect against concurrent access of pci_epf_ops */ struct mutex lock;