From patchwork Tue Jan 24 07:11:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 47572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2011023wrn; Mon, 23 Jan 2023 23:18:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXskUO2oMuE5DDdTD7w7fzThjRbXRZ8UrVx8EjYPDAP1fD9snAYdSVgOqF3uwWNOeYwG1oLG X-Received: by 2002:a05:6402:547:b0:499:bec8:4d with SMTP id i7-20020a056402054700b00499bec8004dmr40078548edx.32.1674544706748; Mon, 23 Jan 2023 23:18:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674544706; cv=none; d=google.com; s=arc-20160816; b=iWkVDP6guvtDtl101gNV81F0Ca5aD4WcfcT5ES6X7V3SMMTk8qk5ZzzLZPprTVLG+a 7CTWhh1DvrlBshALwbDn0vvpwK/FTDLOuBtQ/89WmSWVY1D02BRkOTg2J4tp+FjR7vuX QUBnjLQq3mFDf2P/dX47uQwc1693anZhceJyFGHAcmX5I8n6oR2co2/N1YT5doU8KAyO PiAZX3zoW9Gi7WXgYf0UERrHhOaJ+oZQsOPLPS2jWse1aSgy8WpZyUPOZVsNyHpKxvUl SdfAb+ejHN00XnKGVcQecvVkrJ9sEq2djy8tML+1w3GWFQux/d1vQoLi+AYZM5ON9Vv0 /qIA== 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=MtspVR08c2Hzxz4d1S9naljhmqqgR/iHq8R5vgVdVO8=; b=fb4Pul32/FDYzcFrcbH3Ur1guZwdPMZHu60xQ650Ug1mur54iX0YjCI/QdeXhbe0xE WP1JpUWMxfFbdGMnedl3u13/QP83X/tEcxynBnLQeIDZiSr6TGZXD9Hj4UUVl3m1Qa5n FBkcJ2ee0tnug4xDNnp89LexqBgGNo+6yhPrVNBB6Qsjdt47qXWD1pgiaaIcaNJlMe2S DJHqonIWE2MBXnk+UCCPMILNkGfVCYqxIs1aa7Y7OwgFnlTlzDkOi6FrDbsuTkl9eYGY JfsClatfGajETayo4m9vMmIWknoXYNdT5/RE+h2uR9RLxodJSZbmSSi6sG9iWoWWom+e 2FMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jLkKilHT; 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 b22-20020aa7c916000000b0049e7d30f950si2045393edt.539.2023.01.23.23.18.03; Mon, 23 Jan 2023 23:18:26 -0800 (PST) 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=jLkKilHT; 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 S233480AbjAXHNB (ORCPT + 99 others); Tue, 24 Jan 2023 02:13:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233486AbjAXHM4 (ORCPT ); Tue, 24 Jan 2023 02:12:56 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DDC535B5 for ; Mon, 23 Jan 2023 23:12:42 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id k13so13938569plg.0 for ; Mon, 23 Jan 2023 23:12:42 -0800 (PST) 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=MtspVR08c2Hzxz4d1S9naljhmqqgR/iHq8R5vgVdVO8=; b=jLkKilHTzY/C2gsXwduuwbnZbxommKG4NDPVIPHJS2s8XV3xmC21LPWVZya5CgL+XE BB7Tt0eTbwzy0TWpJGBKvITSxZn7LozlbKEjzK7hX3hZkE9iiNrHTmU2TDkEo1z9CcxM ZL2llotCUra8/97oBsOoJNlLRGLBFVP6LRsIJxp7eFyapgP+WKTRz1h92P506qq8mPcj SaGFIFz/NiYdU5bramL0TmwIJGD1J+kLE/RglKXkZbZkIrhvn7Aft839Y5ZV57ZqE2d8 m23KSjfN29rKbUUj/oacO1QuuCzwyIXMc6BcAKl3dGygF2uSAsg2XOByhzQNawYUirxM I0/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=MtspVR08c2Hzxz4d1S9naljhmqqgR/iHq8R5vgVdVO8=; b=ltBdjpUaMczHRIKZwteSgTyroDNlVUveGe/alrvv39AKbs2SuBYq3hCMv6ZlOpuLI/ XikPvWaMiPi/MXiVyHjPt+XyRQzucOtUiV9opQFqnQuchw/8104oWs+vdTqe8Rm4oPtj RTkClzX+9/ooEAxCFKG+btBJZkQd4Eg/hcZJWXpJq4U1B4dY2T5drrjQLFZvH2SzbRVm 69YH6Z+n7bX22yPTVte7hGwmbltxU09N0U+TspavJ42Un46SVebEAfl6IfPJzzZ2xt38 f2bGDZ9tPL65wcsNO7GHlcRRTczgtB55L2IlZjHHFmdMjmf2t92ep0SREoeKguQePA/F u4XA== X-Gm-Message-State: AFqh2krvKq73dKumO9FwH4t/HR+sWXnPbO8tzVzI6SmbR4q3VWYUXFGY e5l3DCUG2gr7VA0cWWQq4r0q X-Received: by 2002:a17:90a:c298:b0:229:b5e:2e03 with SMTP id f24-20020a17090ac29800b002290b5e2e03mr28940773pjt.32.1674544362064; Mon, 23 Jan 2023 23:12:42 -0800 (PST) Received: from localhost.localdomain ([117.193.209.165]) by smtp.gmail.com with ESMTPSA id 7-20020a17090a174700b00219220edf0dsm736041pjm.48.2023.01.23.23.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 23:12:41 -0800 (PST) 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 v5 4/5] PCI: endpoint: Use callback mechanism for passing events from EPC to EPF Date: Tue, 24 Jan 2023 12:41:57 +0530 Message-Id: <20230124071158.5503-5-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230124071158.5503-1-manivannan.sadhasivam@linaro.org> References: <20230124071158.5503-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 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?1755887390681499353?= X-GMAIL-MSGID: =?utf-8?q?1755887390681499353?= 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 Signed-off-by: Manivannan Sadhasivam --- 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 55283d2379a6..2fe161747e51 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) 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 2c023db8f51c..7cb9587c6548 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 009a07147c61..fa629c191f00 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 @@ -139,6 +146,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; @@ -168,6 +176,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; }; /**