From patchwork Mon Nov 21 14:37:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23811 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1627446wrr; Mon, 21 Nov 2022 06:39:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf4b0wHcyPq8XXTN2pjyBGlqQDtDJKKBrtO6nRiMZXGXqX3A/lM7fewM3wSCMG5OcCtHgmJU X-Received: by 2002:a17:90b:2d85:b0:213:258d:68ef with SMTP id sj5-20020a17090b2d8500b00213258d68efmr20718938pjb.235.1669041568410; Mon, 21 Nov 2022 06:39:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041568; cv=none; d=google.com; s=arc-20160816; b=kf6tPKmjT1jk9uCDGAybNXsPILDL4iLPw9wwmq6LM4XQfs/q0d1ROJsCNQHjGmnHa3 X7Edv6Hy81s9t0f//+N8Ffl/OkhtJKg9s8UpZ50CJhh1x6Bpj1RJxS83yy3eCbSrZq3u SCr74ATMT0w1hwRo55MPqvIKLElbieU5vGI/CcvMstfstudZmJy5mSNWQQjJS51uz+ZV t3q5jaWh9JJVT67Rr9LRbvXxcPA6oVPnINXzaLu/yCi2g6BKmDLYbpcit4Lxukj4V0Vm /G2ExWz5IAdqDHpOjiEO81Fhepku29xz3rFbeS/YvsbWPBjDQq+N5uQTwvDAsHwwY+Dx 4B/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=uxE2Dly/6+Q4uRawtSsl3v/O5OKI6xZbIMyJaFXzjoA=; b=nsCbAVB0/HARFSuXo7L3SyNUqp+Myfjn9/Z8YkixLqhuLIegaAGEG+AurClg8HPFkE go/glfwoww9ybHR1IlKO6BNnpplUgsM6I25TomasJlew4LiIQHx1t1C3xAxnJ2RYNoDU hiUQOcaTBIbq/wVHn+olf8N7TMhj6ZtSE3vjURH0k26HnELMjDDo4aQhjLNb+C8eW05t R+m4j37lYWwFNJ0lRDSSqvNDw1YcnehcPfblZifxb+Z2HP5ty2c55dWFlxvZsq91Kfb9 1utAb04TbbeAgUTi/umPGGQRTsadG5fokCswu5TJl6xl61U9m474HBJMt77ymi79WYSr UCdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=H5FvQ0HM; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=p5I9kVDh; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e9-20020a631e09000000b0046fc6e02bb9si11505117pge.253.2022.11.21.06.39.14; Mon, 21 Nov 2022 06:39:28 -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=@linutronix.de header.s=2020 header.b=H5FvQ0HM; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=p5I9kVDh; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231753AbiKUOiy (ORCPT + 99 others); Mon, 21 Nov 2022 09:38:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231373AbiKUOht (ORCPT ); Mon, 21 Nov 2022 09:37:49 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1B28606AA; Mon, 21 Nov 2022 06:37:48 -0800 (PST) Message-ID: <20221121091326.548660039@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041467; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=uxE2Dly/6+Q4uRawtSsl3v/O5OKI6xZbIMyJaFXzjoA=; b=H5FvQ0HMPFqq2/TfkTiq4NY0eoXPxKBhOuyfnrZ2HeGSZ60Qh7dSRPHAThmvdsx/6Q72SJ CSGlFqv6qbJ2+Lw2WcmT2DyINQyZYBK9GeEfhf+ViSrCsqdjuImi73OnSfhvzDc2tgLc3E Onx6X0N2Rg12QQVeiuqxVcooKsEYs2eHcWhsAP8BL3HubK18FCaiGJhlFQSqGcE5dAPOXl eJElaRgIenWRQxHz+oygtqmU47spwjbfaIToEXY/IMLD/sBHTcN/DA0P4w+i8sOZDy30Tx ULp9KiuvTQTCrUZGZIQcEV4LVACx2HmaA0B/HTlwQLQzvvvJ9SOqxUgU7kX9dg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041467; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=uxE2Dly/6+Q4uRawtSsl3v/O5OKI6xZbIMyJaFXzjoA=; b=p5I9kVDhYyGggj+rhwXTgsauKm6EWZCcnpND+ruO2nO4/QYYg9OfnUuAH/n4/HKST0eUEv xiJLh8sqbD95fZAg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe , Jason Gunthorpe Subject: [patch V2 01/33] genirq/msi: Rearrange MSI domain flags References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:37:47 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750116931900693798?= X-GMAIL-MSGID: =?utf-8?q?1750116931900693798?= These flags got added as necessary and have no obvious structure. For feature support checks and masking it's convenient to have two blocks of flags: 1) Flags to control the internal behaviour like allocating/freeing MSI descriptors. Those flags do not need any support from the underlying MSI parent domain. They are mostly under the control of the outermost domain which implements the actual MSI support. 2) Flags to expose features, e.g. PCI multi-MSI or requirements which can depend on a underlying domain. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Jason Gunthorpe --- include/linux/msi.h | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -24,6 +24,8 @@ #include #include #include +#include + #include /* Dummy shadow structures if an architecture does not define them */ @@ -432,7 +434,16 @@ struct msi_domain_info { void *data; }; -/* Flags for msi_domain_info */ +/* + * Flags for msi_domain_info + * + * Bit 0-15: Generic MSI functionality which is not subject to restriction + * by parent domains + * + * Bit 16-31: Functionality which depends on the underlying parent domain and + * can be masked out by msi_parent_ops::init_dev_msi_info() when + * a device MSI domain is initialized. + */ enum { /* * Init non implemented ops callbacks with default MSI domain @@ -444,33 +455,41 @@ enum { * callbacks. */ MSI_FLAG_USE_DEF_CHIP_OPS = (1 << 1), - /* Support multiple PCI MSI interrupts */ - MSI_FLAG_MULTI_PCI_MSI = (1 << 2), - /* Support PCI MSIX interrupts */ - MSI_FLAG_PCI_MSIX = (1 << 3), /* Needs early activate, required for PCI */ - MSI_FLAG_ACTIVATE_EARLY = (1 << 4), + MSI_FLAG_ACTIVATE_EARLY = (1 << 2), /* * Must reactivate when irq is started even when * MSI_FLAG_ACTIVATE_EARLY has been set. */ - MSI_FLAG_MUST_REACTIVATE = (1 << 5), - /* Is level-triggered capable, using two messages */ - MSI_FLAG_LEVEL_CAPABLE = (1 << 6), + MSI_FLAG_MUST_REACTIVATE = (1 << 3), /* Populate sysfs on alloc() and destroy it on free() */ - MSI_FLAG_DEV_SYSFS = (1 << 7), - /* MSI-X entries must be contiguous */ - MSI_FLAG_MSIX_CONTIGUOUS = (1 << 8), + MSI_FLAG_DEV_SYSFS = (1 << 4), /* Allocate simple MSI descriptors */ - MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS = (1 << 9), + MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS = (1 << 5), /* Free MSI descriptors */ - MSI_FLAG_FREE_MSI_DESCS = (1 << 10), + MSI_FLAG_FREE_MSI_DESCS = (1 << 6), /* * Quirk to handle MSI implementations which do not provide * masking. Currently known to affect x86, but has to be partially * handled in the core MSI code. */ - MSI_FLAG_NOMASK_QUIRK = (1 << 11), + MSI_FLAG_NOMASK_QUIRK = (1 << 7), + + /* Mask for the generic functionality */ + MSI_GENERIC_FLAGS_MASK = GENMASK(15, 0), + + /* Mask for the domain specific functionality */ + MSI_DOMAIN_FLAGS_MASK = GENMASK(31, 16), + + /* Support multiple PCI MSI interrupts */ + MSI_FLAG_MULTI_PCI_MSI = (1 << 16), + /* Support PCI MSIX interrupts */ + MSI_FLAG_PCI_MSIX = (1 << 17), + /* Is level-triggered capable, using two messages */ + MSI_FLAG_LEVEL_CAPABLE = (1 << 18), + /* MSI-X entries must be contiguous */ + MSI_FLAG_MSIX_CONTIGUOUS = (1 << 19), + }; int msi_domain_set_affinity(struct irq_data *data, const struct cpumask *mask, From patchwork Mon Nov 21 14:37:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23812 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1627467wrr; Mon, 21 Nov 2022 06:39:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf4JGfKRr8LnRgmc4LWPoQaz4UUocjwSdxaf7tM6Wbpv3OyijoPgHJ7LxpSidnd+E2yAle23 X-Received: by 2002:a63:1302:0:b0:439:e030:3fa8 with SMTP id i2-20020a631302000000b00439e0303fa8mr19832pgl.554.1669041571541; Mon, 21 Nov 2022 06:39:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041571; cv=none; d=google.com; s=arc-20160816; b=rOys+RrVNmyus8iYuCWo8r1uFZ4Q2wrYu6KibwxYiuBEqQAnAeeB6WDGZ1T6ngEQHq kyUMJ/PdrQ/gOHO2M6KV6Ov1AwXx7+2KAHDG64KwC+Q3n2v6/ZD+H77GLVbGteVG1pAU q5cxjwYuDpYYjNksLH83zyKw9+40xUxlT95PunaM0VS9Zqz+uB71NIrmWiIsr1ZJlq9H xJZLVDxKg6ai/TN6gGRLBghInelSkPlL7r09pdSab5/pMJQF+/gbMYd8ipQkvPRaOkU/ duhdE+Ym5YEI/72nWbFW8gKVxppjzQ54mKK2XnKCIeDCTpgx8m2ojxyfixmFn5sbCKF1 D6BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=zyjjCorGuKC2reAb1ZhFkEbw6ekC0gDsCqvqwlCqPS8=; b=SMZCgXTdS1qzDcbj8oTZ+w4ZNJFg1sSAv2KiFpG6uVB9o59hxj5RuI27QM3hrNGNm5 DVmmiLkZCJc20XyxHpDa3oS8WCP2BUHnbZRMqBl2CumI/0S6l6w99YPU+kc6ppRQS5hE CKfPrXKREiU86vnY65BnlNwq1W1IG3RBEHkxqywDu0c1Xh3t9RJkKay1FO3//3zVIEfN +DgvEQYs5vqk8PBU/4WY8aE53CObQogDJbgFLmGa88cOcCxw8yQi3tiDXzIOn0z9odSJ KssctfkBITsTlwlnC1kItIjAkdSLrxvY8P91sWC7bB6AYn2G5uSsyUBrvRfpy8Tate9W dFEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=PjB9FR5Y; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q23-20020a170902bd9700b0018049a28eabsi10208018pls.617.2022.11.21.06.39.17; Mon, 21 Nov 2022 06:39:31 -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=@linutronix.de header.s=2020 header.b=PjB9FR5Y; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231761AbiKUOjA (ORCPT + 99 others); Mon, 21 Nov 2022 09:39:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231605AbiKUOhv (ORCPT ); Mon, 21 Nov 2022 09:37:51 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1589773BB8; Mon, 21 Nov 2022 06:37:50 -0800 (PST) Message-ID: <20221121091326.604272160@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041468; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=zyjjCorGuKC2reAb1ZhFkEbw6ekC0gDsCqvqwlCqPS8=; b=PjB9FR5YTbezkAxg4l4oOPZXzQSkQQcuWhs2mqPpF4tyGheB7Ldej/Uoy8TjsHFm3HwDu6 BOv1pYhG9HIYfn1z0CAvyLVcow0lyFB/5MxvmhtvgfIWaxRHLXR1HYE7mzVkk/7SmjO2HS 9QMDuinQerjtHndmle2+kvJDGH8OGcry8NPTMq6gBSJXCOVRgzRnqcE6bNhDYx9spbcKHW qEknGGPZPna1svXFJQ59k8GPjiicurptkvUdcZ7SBCnbr9i5nZ3ByM4uuqmTbcFLQULpfN SUfFHDBe7410tuWbWKThuRQMB+znwZ9mdK87DzSPfBxrj1ZtLEXuTQmZuOdGqw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041468; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=zyjjCorGuKC2reAb1ZhFkEbw6ekC0gDsCqvqwlCqPS8=; b=akBvOMHFkSJ7X9at4DMMI/tB55KtYRhUhJOgiND7DHwm+2enzKdXynGJ4sagfkIFK7sgsx wh7h9XKejDNfeMAg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 02/33] genirq/msi: Provide struct msi_parent_ops References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:37:48 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750116935118084153?= X-GMAIL-MSGID: =?utf-8?q?1750116935118084153?= MSI parent domains must have some control over the MSI domains which are built on top. On domain creation they need to fill in e.g. architecture specific chip callbacks or msi domain ops to make the outermost domain parent agnostic which is obviously required for architecture independence etc. The structure contains: 1) A bitfield which exposes the supported functional features. This allows to check for features and is also used in the initialization callback to mask out unsupported features when the actual domain implementation requests a broader range, e.g. on x86 PCI multi-MSI is only supported by remapping domains but not by the underlying vector domain. The PCI/MSI code can then always request multi-MSI support, but the resulting feature set after creation might not have it set. 2) An optional string prefix which is put in front of domain and chip names during creation of the MSI domain. That allows to keep the naming schemes e.g. on x86 where PCI-MSI domains have a IR- prefix when interrupt remapping is enabled. 3) An initialization callback to sanity check the domain info of the to be created MSI domain, to restrict features and to apply changes in MSI ops and interrupt chip callbacks to accomodate to the particular MSI parent implementation and/or the underlying hierarchy. Add a conveniance function to delegate the initialization from the MSI parent domain to an underlying domain in the hierarchy. Signed-off-by: Thomas Gleixner --- V2: Renamed arguments and updated comments (Jason) --- include/linux/irqdomain.h | 5 +++++ include/linux/msi.h | 21 +++++++++++++++++++++ kernel/irq/msi.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) --- a/include/linux/irqdomain.h +++ b/include/linux/irqdomain.h @@ -46,6 +46,7 @@ struct irq_desc; struct cpumask; struct seq_file; struct irq_affinity_desc; +struct msi_parent_ops; #define IRQ_DOMAIN_IRQ_SPEC_PARAMS 16 @@ -134,6 +135,7 @@ struct irq_domain_chip_generic; * @pm_dev: Pointer to a device that can be utilized for power management * purposes related to the irq domain. * @parent: Pointer to parent irq_domain to support hierarchy irq_domains + * @msi_parent_ops: Pointer to MSI parent domain methods for per device domain init * * Revmap data, used internally by the irq domain code: * @revmap_size: Size of the linear map table @revmap[] @@ -157,6 +159,9 @@ struct irq_domain { #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY struct irq_domain *parent; #endif +#ifdef CONFIG_GENERIC_MSI_IRQ + const struct msi_parent_ops *msi_parent_ops; +#endif /* reverse map data. The linear map gets appended to the irq_domain */ irq_hw_number_t hwirq_max; --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -492,6 +492,27 @@ enum { }; +/** + * struct msi_parent_ops - MSI parent domain callbacks and configuration info + * + * @supported_flags: Required: The supported MSI flags of the parent domain + * @prefix: Optional: Prefix for the domain and chip name + * @init_dev_msi_info: Required: Callback for MSI parent domains to setup parent + * domain specific domain flags, domain ops and interrupt chip + * callbacks when a per device domain is created. + */ +struct msi_parent_ops { + u32 supported_flags; + const char *prefix; + bool (*init_dev_msi_info)(struct device *dev, struct irq_domain *domain, + struct irq_domain *msi_parent_domain, + struct msi_domain_info *msi_child_info); +}; + +bool msi_parent_init_dev_msi_info(struct device *dev, struct irq_domain *domain, + struct irq_domain *msi_parent_domain, + struct msi_domain_info *msi_child_info); + int msi_domain_set_affinity(struct irq_data *data, const struct cpumask *mask, bool force); --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -826,6 +826,47 @@ struct irq_domain *msi_create_irq_domain return domain; } +/** + * msi_parent_init_dev_msi_info - Delegate initialization of device MSI info down + * in the domain hierarchy + * @dev: The device for which the domain should be created + * @domain: The domain in the hierarchy this op is being called on + * @msi_parent_domain: The IRQ_DOMAIN_FLAG_MSI_PARENT domain for the child to + * be created + * @msi_child_info: The MSI domain info of the IRQ_DOMAIN_FLAG_MSI_DEVICE + * domain to be created + * + * Return: true on success, false otherwise + * + * This is the most complex problem of per device MSI domains and the + * underlying interrupt domain hierarchy: + * + * The device domain to be initialized requests the broadest feature set + * possible and the underlying domain hierarchy puts restrictions on it. + * + * That's trivial for a simple parent->child relationship, but it gets + * interesting with an intermediate domain: root->parent->child. The + * intermediate 'parent' can expand the capabilities which the 'root' + * domain is providing. So that creates a classic hen and egg problem: + * Which entity is doing the restrictions/expansions? + * + * One solution is to let the root domain handle the initialization that's + * why there is the @domain and the @msi_parent_domain pointer. + */ +bool msi_parent_init_dev_msi_info(struct device *dev, struct irq_domain *domain, + struct irq_domain *msi_parent_domain, + struct msi_domain_info *msi_child_info) +{ + struct irq_domain *parent = domain->parent; + + if (WARN_ON_ONCE(!parent || !parent->msi_parent_ops || + !parent->msi_parent_ops->init_dev_msi_info)) + return false; + + return parent->msi_parent_ops->init_dev_msi_info(dev, parent, msi_parent_domain, + msi_child_info); +} + int msi_domain_prepare_irqs(struct irq_domain *domain, struct device *dev, int nvec, msi_alloc_info_t *arg) { From patchwork Mon Nov 21 14:37:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23813 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1627504wrr; Mon, 21 Nov 2022 06:39:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf7uV1iABrj2MnTyJaYp35PKk2VnJUOZXhmAWX+tzBwQCsOmTNyR/uxd9fQZxF80KEsu2sQw X-Received: by 2002:aa7:9ad6:0:b0:536:e549:8480 with SMTP id x22-20020aa79ad6000000b00536e5498480mr21098622pfp.6.1669041576681; Mon, 21 Nov 2022 06:39:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041576; cv=none; d=google.com; s=arc-20160816; b=EpZGPuKY76Z5skE81C97eopyVMFT/VifVxVyMu+Vl0fv3jg/cIaJFmyaJ9MXtj/SqP X/mU1T7ZVJBJGYsYduC2qFPz90YW9p7ZrpRVerWSeg/i4sMiWJRK6YP8F+JwoB5uK+0E Evqam+tAjP9BGSqgUHvoBANxNLSvA1j38UVXpQvbH2pPBXfSlrC9HaKwW0lnjfqtfYli LGfc6BTDHcQZCLNXlWpwwSluFVQaOhbvaQbKOVQz9PgdQ0hXPmjh2fUvdaumzwFBl24G pwBOWUchQlmLjQC49yRcThfoAm1NHf8ilvbRWoNumYhZoPqOtD6YL9cIkMvRw7aAlxdM YXog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=0KuNIbc8QP6lugPXWLudbIBqNg4+9dhdUGxBbX2EfUo=; b=qigVPbxT+ZgJnTZSP4IX4Skkrrs9K1fKuav8sHykgfsKRN43/+YVbm0I1cvzaodWM7 3mXb+lBrPnVd4KErfUg16GFkzOxQbUfbEHUAE7a9ZVcZPzU1ZxBWaVzKj6yWRaAm9GK7 CPPG0Z2caif5cqJNIeJnAtfssTDU00J0EMfjVjB4No32cPes+yMTkguA3ap0ANgO9Axx 1oqmfaYRGUVIZNKS6uNco21lxnshi+ey6SEkyRQXQ4zEHQypEZEpj82y8So+qiPwfovR n1RHox/88NwCxRlL6qfdFW2tKhjoB1wcPyZ0lrdnFeLjqCZTIDtHJvlw9eGTLTiigh/M V0Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xlqwSDj7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b16-20020a170902b61000b00183243c7a2dsi10175494pls.406.2022.11.21.06.39.22; Mon, 21 Nov 2022 06:39:36 -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=@linutronix.de header.s=2020 header.b=xlqwSDj7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231773AbiKUOjF (ORCPT + 99 others); Mon, 21 Nov 2022 09:39:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231612AbiKUOhx (ORCPT ); Mon, 21 Nov 2022 09:37:53 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E17675D86; Mon, 21 Nov 2022 06:37:52 -0800 (PST) Message-ID: <20221121091326.659141858@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041470; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=0KuNIbc8QP6lugPXWLudbIBqNg4+9dhdUGxBbX2EfUo=; b=xlqwSDj7Jenc/Wfv/qCaD4qeCelneKsVYAFg6ifZ0Ra+BeZFm0HwmyFbaSbAL7EzUlmE3/ MqbkhMmEcuYlY/WpFPEsEpA2JInFtzN7Z1gTWloQE2xyxNf9AAfruL5zVKZ0FzZBe8Q9Bn Lys9M6Uw9yxOk0RjnBFuFCPhYhmxBJRwCXHbC6Fa8PwJyL9ZZbn5+dS39f2D2ip0U/EIh2 UQqVnjLk5M4GdneIPISiNzoJotrkwmmzLqeQkfampZFwBFUNPJ8oXokft/DsSM3A9erdHB oJWq7cB0aw0w2a4n09XG2PwshWAKRPikKkO6xICroUBqyhY3KWtCnIulTMexEw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041470; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=0KuNIbc8QP6lugPXWLudbIBqNg4+9dhdUGxBbX2EfUo=; b=3dC+ZuDBOttGDThBu2FSTtKdL1Is4bsOoQsUClXmHhL6xzypEdZWU2Om/LfLSHCxhUORaE evD5sKUYFFvfdfDA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 03/33] genirq/msi: Provide data structs for per device domains References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:37:49 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750116940532007721?= X-GMAIL-MSGID: =?utf-8?q?1750116940532007721?= Provide struct msi_domain_template which contains a bundle of struct irq_chip, struct msi_domain_ops and struct msi_domain_info and a name field. This template is used by MSI device domain implementations to provide the domain specific functionality, feature bits etc. When a MSI domain is created the template is duplicated in the core code so that it can be modified per instance. That means templates can be marked const at the MSI device domain code. The template is a bundle to avoid several allocations and duplications of the involved structures. The name field is used to construct the final domain and chip name via: $PREFIX-$NAME-$DEVNAME where prefix is the optional prefix of the MSI parent domain, $NAME is the provided name in template::chip and the device name so that the domain is properly identified. On x86 this results for PCI/MSI in: PCI-MSI-0000:3d:00.1 or IR-PCI-MSIX-0000:3d:00.1 depending on the domain type and the availability of remapping. Signed-off-by: Thomas Gleixner --- include/linux/msi.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -74,7 +75,6 @@ struct msi_msg { extern int pci_msi_ignore_mask; /* Helper functions */ -struct irq_data; struct msi_desc; struct pci_dev; struct platform_msi_priv_data; @@ -434,6 +434,20 @@ struct msi_domain_info { void *data; }; +/** + * struct msi_domain_template - Template for MSI device domains + * @name: Storage for the resulting name. Filled in by the core. + * @chip: Interrupt chip for this domain + * @ops: MSI domain ops + * @info: MSI domain info data + */ +struct msi_domain_template { + char name[48]; + struct irq_chip chip; + struct msi_domain_ops ops; + struct msi_domain_info info; +}; + /* * Flags for msi_domain_info * From patchwork Mon Nov 21 14:37:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23814 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1627618wrr; Mon, 21 Nov 2022 06:39:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf5LMocr7A7Nle//42kvHCxg+pz74djaccxFrjR+ij9oIjRIa1xyzRML8h/odSoLMazaj66o X-Received: by 2002:a17:902:aa88:b0:188:a793:4127 with SMTP id d8-20020a170902aa8800b00188a7934127mr3148988plr.135.1669041590383; Mon, 21 Nov 2022 06:39:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041590; cv=none; d=google.com; s=arc-20160816; b=NI4YY1wWzmR1D4uKZvvdy8rsVLCM1SRA2Wi9ctM8ZGKJieb6L7IwAF9ZMNVVCRXZPE v5LGXwdZjFIVC0l+Xa1Waci/HZ5gfd+xbhYFrkLOt4CUCZbYVquVInPycAyFEGj9ZZYS FMmQhlVdQq79KkcaSzMouULGVwAfxQhfa7npixSft4jtxmUQNMSygUuMVfkAzkqbXq59 9Q2cpx+P9LnxB8gk7QfS4r9FLOpUsqj/rdwjEGbmj4X7hyzzps3ILkUpKXadCvOh2u3K wHIf21ACq8mfOxdszF5zhLfeEyItvotgWApIDQQCv2uLXSjkCoXt16NHp8UfUqpijfzP +emg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=+EnVp4kAb6M4W1pf5Y3h6BpyD9pQdSwPS/mCr1aM3ww=; b=L398TT57nzfPjKfiJKbxOeULjyzUIachaIwNY6+UWjN4H/lfjY+YtuLrdx5YAOKay6 xy2LdUjtjSL0E3pYy2PwUH3D3Clfb56kEr22bJ+OkdGuoD33rt5w9EXNFWH/EolC9r8A 5z/UYcuxEZtzzy1yHZfdGVmCDfZ03gTmXIn9Q4cKQXUZQ8QA+6iyzPpFUtt9MvqDcfAU qsCSM/tzkiVn9OzXdRGzKXKVqA16hGiufAqHlwDkxO4bEmCpr3+k8830QJwye0xawgsr ys0M0k42WBGCDIGlIWWzB5UHolO1UQ5T+k5Qs7l6LRPONkL+r0BLF6+65jIxcXlu1BKQ copQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Zw1WnrzA; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g184-20020a636bc1000000b0047586ee5f6asi11682401pgc.857.2022.11.21.06.39.35; Mon, 21 Nov 2022 06:39:50 -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=@linutronix.de header.s=2020 header.b=Zw1WnrzA; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231670AbiKUOjN (ORCPT + 99 others); Mon, 21 Nov 2022 09:39:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231613AbiKUOhx (ORCPT ); Mon, 21 Nov 2022 09:37:53 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BF5875DAB; Mon, 21 Nov 2022 06:37:52 -0800 (PST) Message-ID: <20221121091326.714126704@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041471; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=+EnVp4kAb6M4W1pf5Y3h6BpyD9pQdSwPS/mCr1aM3ww=; b=Zw1WnrzAhW2up7twI+QxubPCa4I1ZK2c3o5rGU6fH4IYZUd/1rEWW1gHXFNBfsYp805KzJ 1tB9TRT1vGnUCqeSAaX5uNniKyDknyfJXOTtPRjVwK+WDLc3JkjNtOaKelsrLDH7HyO4iP +MaZf+Zp4qbyY5LkleRNHMfT8OD3biFFuHNkahjK6YzcpOV/oeibxArFfS3lElaAgUO/qX WiPsT3uT5vxWiTm5RbsZLWKdbXY0Usgyi6rU25PK1CQ3xNgqwlP6xCQUaXd97FuqyTnd+C EcIf08lYKDL5c8A6XD8vWDZqTN+QR7uJim0I2zhoIka84UTGeEjK0senCcQWYw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041471; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=+EnVp4kAb6M4W1pf5Y3h6BpyD9pQdSwPS/mCr1aM3ww=; b=ELjM57HbrvBL5+yH7YAMmSzY8RlotfKMsHr7QVOlEx/lM61n/mY523aTsbT2U0eHOphGAq lLyAGCdaanIuhTAQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 04/33] genirq/msi: Add size info to struct msi_domain_info References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:37:51 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750116954966275193?= X-GMAIL-MSGID: =?utf-8?q?1750116954966275193?= To allow proper range checking especially for dynamic allocations add a size field to struct msi_domain_info. If the field is 0 then the size is unknown or unlimited (up to MSI_MAX_INDEX) to provide backwards compability. Signed-off-by: Thomas Gleixner --- include/linux/msi.h | 2 ++ 1 file changed, 2 insertions(+) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -414,6 +414,7 @@ struct msi_domain_ops { * struct msi_domain_info - MSI interrupt domain data * @flags: Flags to decribe features and capabilities * @bus_token: The domain bus token + * @hwsize: The hardware table size (0 if unknown/unlimited) * @ops: The callback data structure * @chip: Optional: associated interrupt chip * @chip_data: Optional: associated interrupt chip data @@ -425,6 +426,7 @@ struct msi_domain_ops { struct msi_domain_info { u32 flags; enum irq_domain_bus_token bus_token; + unsigned int hwsize; struct msi_domain_ops *ops; struct irq_chip *chip; void *chip_data; From patchwork Mon Nov 21 14:37:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23815 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1627700wrr; Mon, 21 Nov 2022 06:39:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf7MX1DBYHpb0LrBBTJ/YOIklpbW18S7BGMbOrzgGgqPfKkdfAXkXgIh0gmv6EUx+W7OR6Qn X-Received: by 2002:a17:903:44f:b0:187:3a43:3a9d with SMTP id iw15-20020a170903044f00b001873a433a9dmr11924065plb.152.1669041599042; Mon, 21 Nov 2022 06:39:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041599; cv=none; d=google.com; s=arc-20160816; b=cIi+BKekLLPFmrwKPEQ6XWQ70Uj6ks3Q1Eiw9xI6Dle/pxGJsH2MRxLZFuhv1qAIol vVTENVfprjhsdoQK0SmCC9q6XMCbvvttJaHNrtbbQvWzTIrxCu3fd7WbOZvRH/0Pa3ro 8GMpjMG3PlOY2jQveMBki8LlG4BsTUz77x/Q3u0WEo7n40gjy26hunZ9I/tj22Ebf1yX xl4UdBjwVFmsUZwvFpp1LLEuga5Y4rmR+1DzCJucG7z3z8k4/iM2iDRUsdFM/IOTNJuO iIgmF37KyIh4JQ06fuaL283lNM8Qz9k7vPFmzvFbjkNviX0M9Ubo8C++6/oQH4K0Fjrl 2SjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=MZ8jPM+DGKOpETlDvAHwxuzbjfVqWBMalr44KdANGx8=; b=xSephLJ1C52QPYrQ5QV+1XqTwfv+I6PtItaocgBU3aRMewcKkLooekmACujRE1dLAj nnTcSTigMs0QA8ob0c7ktbviHTEbbJ9/i4zA7kP2KG8ahBpqdPM+thZAnJ9TSCbSOJ7n BIbhX/jnGmGKa7qzshh2id/qFkccnFUlGr/G27RzOtwmufApdHTPRFtiRrhSKaufgClt izn0zv0C1MiWWkm7Pbrnr0CiVajaEFSVg1yonLhnNKHfjfC1ieiPBitE7VswmRfwphTt rX56Qk25+kwr5Tc++Puyrp2xDdEDwlEUxK7IkFVME7FWt2uuU8W49/m/ExdJKjS7Cbl4 op5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=jVyiurSF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=CReccuOn; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nn10-20020a17090b38ca00b00214021e87d1si15990266pjb.173.2022.11.21.06.39.44; Mon, 21 Nov 2022 06:39:59 -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=@linutronix.de header.s=2020 header.b=jVyiurSF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=CReccuOn; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230345AbiKUOjQ (ORCPT + 99 others); Mon, 21 Nov 2022 09:39:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231622AbiKUOhy (ORCPT ); Mon, 21 Nov 2022 09:37:54 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2707A77217; Mon, 21 Nov 2022 06:37:54 -0800 (PST) Message-ID: <20221121091326.769133826@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041472; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=MZ8jPM+DGKOpETlDvAHwxuzbjfVqWBMalr44KdANGx8=; b=jVyiurSFqZAUGWno02f2IPodi3QwmpcrP1Vp2Ks0TgbJO20F/dWxDsa5dkEbr6Pg7p97Zy rPp/3DeHMD3AmuIy1U6tnu38EVMxnDmSZ5WOK1XOEDm5yDz8fIPDe/LG0uIWDMtpu8iBS4 vqdD0gGHsMTBRzfa1ctvixmDkcjkyFrvKI/cphmfB0/vKb9d53rQDJavu1Sin8HXPtqfTl 7Fwh7u9cjesrfJL67x+o31/16McsURPTx7cl1gWZUfgzl8L4mUWxY8aO6fCEOb99PrmRqm jNat6FOPDzEVcjez0lrzaaeC2yqPDyEPR3Rh21W979eeXF67X5U6AgaAagyjJw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041472; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=MZ8jPM+DGKOpETlDvAHwxuzbjfVqWBMalr44KdANGx8=; b=CReccuOnPb82wr5d0rcYob2PGyVgUsEM1kQ3zSl0zyf8wPkw1ry+mxpKf5xLJwlBnkTmpS 2Dcw+yPVAXZHm0Bw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 05/33] genirq/msi: Split msi_create_irq_domain() References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:37:52 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750116963890182040?= X-GMAIL-MSGID: =?utf-8?q?1750116963890182040?= Split the functionality of msi_create_irq_domain() so it can be reused for creating per device irq domains. No functional change. Signed-off-by: Thomas Gleixner --- kernel/irq/msi.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -796,17 +796,10 @@ static void msi_domain_update_chip_ops(s chip->irq_set_affinity = msi_domain_set_affinity; } -/** - * msi_create_irq_domain - Create an MSI interrupt domain - * @fwnode: Optional fwnode of the interrupt controller - * @info: MSI domain info - * @parent: Parent irq domain - * - * Return: pointer to the created &struct irq_domain or %NULL on failure - */ -struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode, - struct msi_domain_info *info, - struct irq_domain *parent) +static struct irq_domain *__msi_create_irq_domain(struct fwnode_handle *fwnode, + struct msi_domain_info *info, + unsigned int flags, + struct irq_domain *parent) { struct irq_domain *domain; @@ -814,7 +807,7 @@ struct irq_domain *msi_create_irq_domain if (info->flags & MSI_FLAG_USE_DEF_CHIP_OPS) msi_domain_update_chip_ops(info); - domain = irq_domain_create_hierarchy(parent, IRQ_DOMAIN_FLAG_MSI, 0, + domain = irq_domain_create_hierarchy(parent, flags | IRQ_DOMAIN_FLAG_MSI, 0, fwnode, &msi_domain_ops, info); if (domain) { @@ -827,6 +820,21 @@ struct irq_domain *msi_create_irq_domain } /** + * msi_create_irq_domain - Create an MSI interrupt domain + * @fwnode: Optional fwnode of the interrupt controller + * @info: MSI domain info + * @parent: Parent irq domain + * + * Return: pointer to the created &struct irq_domain or %NULL on failure + */ +struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode, + struct msi_domain_info *info, + struct irq_domain *parent) +{ + return __msi_create_irq_domain(fwnode, info, 0, parent); +} + +/** * msi_parent_init_dev_msi_info - Delegate initialization of device MSI info down * in the domain hierarchy * @dev: The device for which the domain should be created From patchwork Mon Nov 21 14:37:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23834 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1628980wrr; Mon, 21 Nov 2022 06:42:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf7OZvF82u14Snkorvdl3Md2NP4kjuc0Yo7Th+ntuSCSolna1eSjSkc5ORB6abYA+pFlU5Cx X-Received: by 2002:a17:907:c24a:b0:7ac:2e16:bc31 with SMTP id tj10-20020a170907c24a00b007ac2e16bc31mr15584930ejc.242.1669041735828; Mon, 21 Nov 2022 06:42:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041735; cv=none; d=google.com; s=arc-20160816; b=m/Kb2+Dv0RVL0Z9MOmhLR/ZTjIUgRReQ5v4Jps7IV8yHJK/fA7pT1PTZY6SzvM+5B2 Ku9M+WoLlfRVJeg1rlrXo5Ga+FS7boe9aP2IpmiD4HTfBGqpEDpT8VmcxqpoyPuESJLN ZHRK1L1kuZ1ojpyXQF1O48DEZWo1qoTb0L8HFqw6wffb4SE9ED1s2VAcBDhwqAIoP+e/ zeRMfzCPa8DVQDkrMUzj+c2MMh3qN2qrAejdwbRbbAighDtcmPRL+k3b5oAne1DuGFaG DHeyrGrorNxr6wtmBc98Lmzqorytbwhk6kK3y/NNq0qxgEMAEmBo8iXVM09Qiob2qPhA FKoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=xdXQN8DRlFx/ul31qn4JSIb+1+AWkLgJWGGnxBYyOqY=; b=kiqMx3vfGLUFiyJ5yXDAoTt8O4vKCT+fZ4sFHomP521it74hzNy4RAhyl29Bjr7haA UtLRWttztFUUP+mzNcgp6YcbEgcmmEMzrnIp7FLUxExzQOR50GqDpNPOKz84g0s6MUdG xHyxIX0UQzIf4sFk7doWWWpqusBLDY8rwMmqp6zhtw2e+RdaT9d+vF8YBXo413TtTFyE DdkhDQuYI3/JyNMWLw+nsvXM0Ym531q74aiSCbnUtnLymidDKVhygj3rK6AP2poiFbY1 QRcsrXWLOZ0pmPf/4P/m9x+2hY3NQ0id27GoZRmN7NMSY1YXjSeJTesk9IQ8M/joZr+r rN2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=RBGAMv2G; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=wER6yTa5; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o19-20020a170906975300b0079800b8172bsi10824405ejy.450.2022.11.21.06.41.30; Mon, 21 Nov 2022 06:42:15 -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=@linutronix.de header.s=2020 header.b=RBGAMv2G; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=wER6yTa5; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231403AbiKUOjJ (ORCPT + 99 others); Mon, 21 Nov 2022 09:39:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231624AbiKUOhz (ORCPT ); Mon, 21 Nov 2022 09:37:55 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AD8F776E2; Mon, 21 Nov 2022 06:37:55 -0800 (PST) Message-ID: <20221121091326.824201400@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041473; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=xdXQN8DRlFx/ul31qn4JSIb+1+AWkLgJWGGnxBYyOqY=; b=RBGAMv2GkppARAoYghD/kjTwWaU4eeqxK2Ubd1SizNBhAVm2TXOrkaFFnaNXfr1KZeNxD+ 52VAh+N+AZDFLoazaVlHlG6JbwZ5YtCZ8aNwdxKgTNpHuOB/UtHaNGFqMOZeFICUjYv2KP vNEb+B0KlQwGsX51jstKGCTVczJ+jV6kqzAH0QxPWObSQZEfHQh5RJRmDFrR3hY2oTntED ymtALNUY8UxS9YYtigjuKBhO7h/tz+S0PMogZ+O32cuojrRsiZ/rsSh/HIzvvtOtkpV4SL 0VSpgdE2WbQQ0FZGyHfDKDY2FGvCF9zZ1JDembFs3lwzluzpBAUwq0JWBHEUJQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041473; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=xdXQN8DRlFx/ul31qn4JSIb+1+AWkLgJWGGnxBYyOqY=; b=wER6yTa5fecL2bNV9tiYHP4MwsBQhfok1JJm+pRrG71fCNhiW4druzH9vfv4qO9rONscXQ 4wXzqJeZrLjAceBw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 06/33] genirq/irqdomain: Add irq_domain::dev for per device MSI domains References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:37:53 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117107248985559?= X-GMAIL-MSGID: =?utf-8?q?1750117107248985559?= Per device domains require the device pointer of the device which instantiated the domain for some purposes. Add the pointer to struct irq_domain. It will be used in the next step which provides the infrastructure to create per device MSI domains. Signed-off-by: Thomas Gleixner --- include/linux/irqdomain.h | 4 ++++ 1 file changed, 4 insertions(+) --- a/include/linux/irqdomain.h +++ b/include/linux/irqdomain.h @@ -132,6 +132,9 @@ struct irq_domain_chip_generic; * @gc: Pointer to a list of generic chips. There is a helper function for * setting up one or more generic chips for interrupt controllers * drivers using the generic chip library which uses this pointer. + * @dev: Pointer to the device which instantiated the irqdomain + * With per device irq domains this is not necessarily the same + * as @pm_dev. * @pm_dev: Pointer to a device that can be utilized for power management * purposes related to the irq domain. * @parent: Pointer to parent irq_domain to support hierarchy irq_domains @@ -155,6 +158,7 @@ struct irq_domain { struct fwnode_handle *fwnode; enum irq_domain_bus_token bus_token; struct irq_domain_chip_generic *gc; + struct device *dev; struct device *pm_dev; #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY struct irq_domain *parent; From patchwork Mon Nov 21 14:37:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23816 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1627773wrr; Mon, 21 Nov 2022 06:40:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf5FAG1on32gGjYV23hkNDVePWBxLeiRl66Gl45437iU059wVWGZk1Gx2HsdZdmggCviFyd7 X-Received: by 2002:a63:4087:0:b0:477:15c8:ff67 with SMTP id n129-20020a634087000000b0047715c8ff67mr1918954pga.275.1669041605379; Mon, 21 Nov 2022 06:40:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041605; cv=none; d=google.com; s=arc-20160816; b=cPUb9eKwaD8IdP49hyeOWZjZ2ZnH/xKbVR3Hzbxi1w0A8Wgnd+NhWHUiRLjuQs4SMV jiyhS1tKzJC0enOBxX9OzXhwsmu3ec4O8oUcvcjqpZkD1bpJm2q6J1u0ZDQ5Il9c/0T0 JSJPGOAvU61I4LEOs1qpxmANt8ABoGuAHmlzySNnwoV1l4zyHBzKfC0VfPzBqN15AXKd jnNUMPaF36kD2YCblmlFTWatsLzuLD9SJqhe23kC10stMMkAN5e98Y1UALJhk2Z+qqQw lEhByxKXChDW7ZOtK3H9DO0OUqZBdXu9POriG/pEkGiSHcf44vID6o/t0mQnjPVzrw+K Iajw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=oq9wU0v6PL7iYHbGT4Orruk1YT/iCTGwRGcoB7P3Fjo=; b=AaW9s4hJ8BjUrz50WLFRYdMvovsO3iOPLhZ/oiNbuqY6giLE0DLx2f3NDf50KOuekm 1/90lQcoQDzYZmw17hU9vatQ8U5nYuSGxKCWo/Hr/I7n0nL8Y4fP6PulXVRKkNRBtYBM 5mK21oJoqzYlbbJhpG8F8N0yRodlMimej+nAeWk706Rs6evuryW4jVRy237w7daZ0guK 4dayZFlIx7DoEqLv+efZeXkUUbV6DgXZEMEB4P+iZ8gI3ZseI+Gk4oXDaNfIAiMKR3y+ Lplghkf8jIKvNihb5n9NZuHdsWyyJnWZ915DLX4wQx0kCdV3DKGg4z2FqctvkfiMcfih XgGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=VUEEC3pI; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=nMkJAAfk; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r11-20020a170902c7cb00b00189253497cesi1862751pla.451.2022.11.21.06.39.50; Mon, 21 Nov 2022 06:40:05 -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=@linutronix.de header.s=2020 header.b=VUEEC3pI; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=nMkJAAfk; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231573AbiKUOjU (ORCPT + 99 others); Mon, 21 Nov 2022 09:39:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231629AbiKUOh5 (ORCPT ); Mon, 21 Nov 2022 09:37:57 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56FC77617D; Mon, 21 Nov 2022 06:37:56 -0800 (PST) Message-ID: <20221121091326.879869866@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041475; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=oq9wU0v6PL7iYHbGT4Orruk1YT/iCTGwRGcoB7P3Fjo=; b=VUEEC3pIoMz1ObdqhKXio8SkUkxuEQsyFV2yjQYFIIj0kkJrvnH7s1UkUVarLmzZsifHGy Xn+agisOOXjy0LbhfZuuEkG2D+/iGydy8aKC/+Nyv1NYUTSJwYh9jLLHXLn505NQi/T0Rh GWIL+sb9/rK8YzD5PAazNXoBteX6zefDRckueRTKDRZY6oBNbWT8p0kLMw94NJWVqczDa+ ifh01VX+hENizatodcaV6Wjk7BLOB68mZmxyf41ZFdj1HkVncdisT5ODluyZFdqBlpFWjU COHqQTQ3V9zQFwXHlJZcTUwH/46QdxY8ikYWnyUdU4oI9VutHGA++v+1QBs3kA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041475; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=oq9wU0v6PL7iYHbGT4Orruk1YT/iCTGwRGcoB7P3Fjo=; b=nMkJAAfke9hPsBgc91s/dk7GXzvznmZlidGEzWoVFfblPIDkQH2DLHBgJvX1FzFNA/b5kh QvUXkVnq2s/KfgAg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 07/33] genirq/msi: Provide msi_create/free_device_irq_domain() References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:37:54 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750116970664365886?= X-GMAIL-MSGID: =?utf-8?q?1750116970664365886?= Now that all prerequsites are in place, provide the actual interfaces for creating and removing per device interrupt domains. MSI device interrupt domains are created from the provided msi_domain_template which is duplicated so that it can be modified for the particular device. The name of the domain and the name of the interrupt chip are composed by "$(PREFIX)$(CHIPNAME)-$(DEVNAME)" $PREFIX: The optional prefix provided by the underlying MSI parent domain via msi_parent_ops::prefix. $CHIPNAME: The name of the irq_chip in the template $DEVNAME: The name of the device The domain is further initialized through a MSI parent domain callback which fills in the required functionality for the parent domain or domains further down the hierarchy. This initialization can fail, e.g. when the requested feature or MSI domain type cannot be supported. The domain pointer is stored in the pointer array inside of msi_device_data which is attached to the domain. The domain can be removed via the API or left for disposal via devres when the device is torn down. The API removal is useful e.g. for PCI to have seperate domains for MSI and MSI-X, which are mutually exclusive and always occupy the default domain id slot. Signed-off-by: Thomas Gleixner --- include/linux/msi.h | 6 ++ kernel/irq/msi.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -536,6 +536,12 @@ struct irq_domain *msi_create_irq_domain struct msi_domain_info *info, struct irq_domain *parent); +bool msi_create_device_irq_domain(struct device *dev, unsigned int domid, + const struct msi_domain_template *template, + unsigned int hwsize, void *domain_data, + void *chip_data); +void msi_remove_device_irq_domain(struct device *dev, unsigned int domid); + int msi_domain_alloc_irqs_range_locked(struct device *dev, unsigned int domid, unsigned int first, unsigned int last); int msi_domain_alloc_irqs_range(struct device *dev, unsigned int domid, --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -53,6 +53,14 @@ static inline void msi_setup_default_irq md->__irqdomains[MSI_DEFAULT_DOMAIN] = dev->msi.domain; } +static inline void msi_remove_device_irqdomains(struct device *dev, struct msi_device_data *md) +{ + int domid; + + for (domid = 0; domid < MSI_MAX_DEVICE_IRQDOMAINS; domid++) + msi_remove_device_irq_domain(dev, domid); +} + static int msi_get_domain_base_index(struct device *dev, unsigned int domid) { lockdep_assert_held(&dev->msi.data->mutex); @@ -279,6 +287,7 @@ static void msi_device_data_release(stru { struct msi_device_data *md = res; + msi_remove_device_irqdomains(dev, md); WARN_ON_ONCE(!xa_empty(&md->__store)); xa_destroy(&md->__store); dev->msi.data = NULL; @@ -875,6 +884,143 @@ bool msi_parent_init_dev_msi_info(struct msi_child_info); } +/** + * msi_create_device_irq_domain - Create a device MSI interrupt domain + * @dev: Pointer to the device + * @domid: Domain id + * @template: MSI domain info bundle used as template + * @hwsize: Maximum number of MSI table entries (0 if unknown or unlimited) + * @domain_data: Optional pointer to domain specific data which is set in + * msi_domain_info::data + * @chip_data: Optional pointer to chip specific data which is set in + * msi_domain_info::chip_data + * + * Return: True on success, false otherwise + * + * There is no firmware node required for this interface because the per + * device domains are software constructs which are actually closer to the + * hardware reality than any firmware can describe them. + * + * The domain name and the irq chip name for a MSI device domain are + * composed by: "$(PREFIX)$(CHIPNAME)-$(DEVNAME)" + * + * $PREFIX: Optional prefix provided by the underlying MSI parent domain + * via msi_parent_ops::prefix. If that pointer is NULL the prefix + * is empty. + * $CHIPNAME: The name of the irq_chip in @template + * $DEVNAME: The name of the device + * + * This results in understandable chip names and hardware interrupt numbers + * in e.g. /proc/interrupts + * + * PCI-MSI-0000:00:1c.0 0-edge Parent domain has no prefix + * IR-PCI-MSI-0000:00:1c.4 0-edge Same with interrupt remapping prefix 'IR-' + * + * IR-PCI-MSIX-0000:3d:00.0 0-edge Hardware interrupt numbers reflect + * IR-PCI-MSIX-0000:3d:00.0 1-edge the real MSI-X index on that device + * IR-PCI-MSIX-0000:3d:00.0 2-edge + * + * On IMS domains the hardware interrupt number is either a table entry + * index or a purely software managed index but it is guaranteed to be + * unique. + * + * The domain pointer is stored in @dev::msi::data::__irqdomains[]. All + * subsequent operations on the domain depend on the domain id. + * + * The domain is automatically freed when the device is removed via devres + * in the context of @dev::msi::data freeing, but it can also be + * independently removed via @msi_remove_device_irq_domain(). + */ +bool msi_create_device_irq_domain(struct device *dev, unsigned int domid, + const struct msi_domain_template *template, + unsigned int hwsize, void *domain_data, + void *chip_data) +{ + struct irq_domain *domain, *parent = dev->msi.domain; + const struct msi_parent_ops *pops; + struct msi_domain_template *bundle; + struct fwnode_handle *fwnode; + + if (!irq_domain_is_msi_parent(parent)) + return false; + + if (domid >= MSI_MAX_DEVICE_IRQDOMAINS) + return false; + + bundle = kmemdup(template, sizeof(*bundle), GFP_KERNEL); + if (!bundle) + return false; + + bundle->info.hwsize = hwsize ? hwsize : MSI_MAX_INDEX; + bundle->info.chip = &bundle->chip; + bundle->info.ops = &bundle->ops; + bundle->info.data = domain_data; + bundle->info.chip_data = chip_data; + + pops = parent->msi_parent_ops; + snprintf(bundle->name, sizeof(bundle->name), "%s%s-%s", + pops->prefix ? : "", bundle->chip.name, dev_name(dev)); + bundle->chip.name = bundle->name; + + fwnode = irq_domain_alloc_named_fwnode(bundle->name); + if (!fwnode) + goto free_bundle; + + if (msi_setup_device_data(dev)) + goto free_fwnode; + + msi_lock_descs(dev); + + if (WARN_ON_ONCE(msi_get_device_domain(dev, domid))) + goto fail; + + if (!pops->init_dev_msi_info(dev, parent, parent, &bundle->info)) + goto fail; + + domain = __msi_create_irq_domain(fwnode, &bundle->info, IRQ_DOMAIN_FLAG_MSI_DEVICE, parent); + if (!domain) + goto fail; + + domain->dev = dev; + dev->msi.data->__irqdomains[domid] = domain; + msi_unlock_descs(dev); + return true; + +fail: + msi_unlock_descs(dev); +free_fwnode: + kfree(fwnode); +free_bundle: + kfree(bundle); + return false; +} + +/** + * msi_remove_device_irq_domain - Free a device MSI interrupt domain + * @dev: Pointer to the device + * @domid: Domain id + */ +void msi_remove_device_irq_domain(struct device *dev, unsigned int domid) +{ + struct msi_domain_info *info; + struct irq_domain *domain; + + msi_lock_descs(dev); + + domain = msi_get_device_domain(dev, domid); + + if (!domain || !irq_domain_is_msi_device(domain)) + goto unlock; + + dev->msi.data->__irqdomains[domid] = NULL; + info = domain->host_data; + irq_domain_remove(domain); + kfree(container_of(info, struct msi_domain_template, info)); + +unlock: + msi_unlock_descs(dev); +} + int msi_domain_prepare_irqs(struct irq_domain *domain, struct device *dev, int nvec, msi_alloc_info_t *arg) { From patchwork Mon Nov 21 14:37:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23819 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1627921wrr; Mon, 21 Nov 2022 06:40:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf7x9rmhZKjG79Vj8lDfd+X4BWgTBb9m5i2x3XItXy3itwfe/+K0oSRz/E8l1R4IQoHeIry+ X-Received: by 2002:a63:2144:0:b0:470:8a45:32a8 with SMTP id s4-20020a632144000000b004708a4532a8mr17442961pgm.543.1669041619337; Mon, 21 Nov 2022 06:40:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041619; cv=none; d=google.com; s=arc-20160816; b=chdm4XPNuMpnRlibatdR3YHEMXaAcUSnzMTMotEO5sk+lLHF3smVSLXOBITbDlt5WG 2XxMr9gkjZAO2Dybpzfs7YtiYbVYuZuxPvShjCn7XHDW0SIdJA6Vaue9Az1fiwgBf/w8 YL58bVmP/fCz4YXoxq5E6LP3v34C6XUVEq+O/pbHw936f/XAyt/v8ia2YfRCravP+paC Q4kJ63SzWBCO7zjw9EnWZ0Rb7J+RYukPg0PLK4ChQwVYvir2pNXC6h+DFyqxxZr4N85g nu/2vNQgyY5Ixp0l4aj0RSimhBabfCMgCq5pBPlGA+zZP8GiSZXAIifRRSzSRbhRrgzy uEIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=dNla760VftgKp2xT4MRMyY8D/XKPi4S0TfNof3crvXM=; b=OinHCzwJD3kV3/a+eHRA4QyRAEVbzUO2fJYYHySlgzjh39/kOSunxtj/g5TZw6gV+1 DFtVsIQ1nBdNSw2fJtNVvoYz/3fHgo+AUXcxmTbQurHvDlnQW1O6v5XFN9PVKbaCBbQj 3NBytGpDFBDP62bCs4lmSjulSJ7EgVZhADnGIAoLdoDr8qw/o1E0wor9nDbmboHimyg9 /o3qaJPDBedsqAde5xZ652f55macW5oc1GD9VuV8mIVDBwQPhlVzYhNqnJst+F1sg29R WQgXoxgi2o2PUJ/K0/OKJ+zQpxyHdIFsfyQnfjcAM8Z41/u0NQUtW4vGcwHD94F0s0Hz uTCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=P+HYXuVq; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i8-20020aa78d88000000b0056e48944895si10557280pfr.317.2022.11.21.06.40.05; Mon, 21 Nov 2022 06:40:19 -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=@linutronix.de header.s=2020 header.b=P+HYXuVq; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231800AbiKUOjf (ORCPT + 99 others); Mon, 21 Nov 2022 09:39:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231634AbiKUOh6 (ORCPT ); Mon, 21 Nov 2022 09:37:58 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13ADC1EC; Mon, 21 Nov 2022 06:37:58 -0800 (PST) Message-ID: <20221121091326.938173210@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041476; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=dNla760VftgKp2xT4MRMyY8D/XKPi4S0TfNof3crvXM=; b=P+HYXuVqYFhqGfbPERnzjNDCBVcKkJNXxsNo4ft1ia61H91Q3hdAryUicSolv5BMOUp0UA JXz/7ubQ152DLVF8uJsQsbyoPug1bkilzs+gI6+dJTmbFEynVGmOtmP5sDStayCZcqfwJO 9rsqkUGjGN1ohYfKR+E8JxsVaidNqMVDRlgw9c9VIe8uJsvNWezISe2NJQ9yC0XmGH2a2F iPM8XUvr9N90AtoH+eBqRSb7C1L49FUOHGvGXgS2LK/fplfSj2AiLil6PYz8v/kXt9ZtG+ UNJNaqMKvQFfenF7eDYFhIx/TGsn97SqIhfxj/eQU33BDJuOX+55rYMyt7s/nA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041476; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=dNla760VftgKp2xT4MRMyY8D/XKPi4S0TfNof3crvXM=; b=WLGiQULCYKxQSd1OjNwNkXBQuflUzZVliowZe+kfm4peS/o+dR+N7F67JTaTt2BpCs21jg /NFLqHdQ54tSU6Cw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 08/33] genirq/msi: Provide msi_match_device_domain() References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:37:56 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750116984857321608?= X-GMAIL-MSGID: =?utf-8?q?1750116984857321608?= Provide an interface to match a per device domain bus token. This allows to query which type of domain is installed for a particular domain id. Will be used for PCI to avoid frequent create/remove cycles for the MSI resp. MSI-X domains. Signed-off-by: Thomas Gleixner --- include/linux/msi.h | 3 +++ kernel/irq/msi.c | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -542,6 +542,9 @@ bool msi_create_device_irq_domain(struct void *chip_data); void msi_remove_device_irq_domain(struct device *dev, unsigned int domid); +bool msi_match_device_irq_domain(struct device *dev, unsigned int domid, + enum irq_domain_bus_token bus_token); + int msi_domain_alloc_irqs_range_locked(struct device *dev, unsigned int domid, unsigned int first, unsigned int last); int msi_domain_alloc_irqs_range(struct device *dev, unsigned int domid, --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -1021,6 +1021,31 @@ void msi_remove_device_irq_domain(struct msi_unlock_descs(dev); } +/** + * msi_match_device_irq_domain - Match a device irq domain against a bus token + * @dev: Pointer to the device + * @domid: Domain id + * @bus_token: Bus token to match against the domain bus token + * + * Return: True if device domain exists and bus tokens match. + */ +bool msi_match_device_irq_domain(struct device *dev, unsigned int domid, + enum irq_domain_bus_token bus_token) +{ + struct msi_domain_info *info; + struct irq_domain *domain; + bool ret = false; + + msi_lock_descs(dev); + domain = msi_get_device_domain(dev, domid); + if (domain && irq_domain_is_msi_device(domain)) { + info = domain->host_data; + ret = info->bus_token == bus_token; + } + msi_unlock_descs(dev); + return ret; +} + int msi_domain_prepare_irqs(struct irq_domain *domain, struct device *dev, int nvec, msi_alloc_info_t *arg) { From patchwork Mon Nov 21 14:37:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23817 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1627852wrr; Mon, 21 Nov 2022 06:40:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf7TE6ELcVWxnaT1TpOj+ymbXlfXOmkm7YSy/+TvX7Aj+Q6hcVQlZ/6KyHrTaVP2avgW58Jg X-Received: by 2002:a63:3196:0:b0:476:dd18:b881 with SMTP id x144-20020a633196000000b00476dd18b881mr2806015pgx.93.1669041610843; Mon, 21 Nov 2022 06:40:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041610; cv=none; d=google.com; s=arc-20160816; b=uTtt/mZIaZrQhnberlJYyYzSzG2Lvfy05D+dG6z5k0U+go8ZUwrNmsstYavGoF/p1L D864ybbSzDIa3UEL91Qam9ZDEacntGQ+xUOssbguHW6KDI1takBDPzNfMyVWeiJ3nF7S LdJQQv8s1yiPI69732L4UCAfFlBwTwhZ6lhVRps3e64uiHWZOdZJVM8BiuhlcG9gT1+x oTSH1bapfgS2z1ZnOxeq5cG3EQ/YZa3NhKj0xZM25mI40oXpP9poJZhZ+bitdGfVifvf oQ5sYgJ/TbkAbnQRRY85vZraV6k9gNVLTbR4euegqLOtAy3wr4iYMjX/KCenjHZqepjz HADw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=/uCay4K5eU0UtN6y+QL1HudBqKBANdJSYmtvg+386uI=; b=wJUt+EFpSbeEqs+oUXpsMHvfBDy7U+Hsn2Sc5U0m224mShI34pf3UgFBq4vhri+ofB 5f3i24CQa3ULutWj+DjjXPLYJoAdnbCyACf+5E9h+SHs1xmWz0zBor8wB3ZeNrUHaVRN rPkCDtkUetl7Kp48Mwy3em7uehnjx2dSLflcAkloRVOYGtcmT+ILPCp8T8IHz1CRrXNn MfUaxj1mqyecEyXvhg10kzVHQNLBO/5T3hw4fRoaormJPO8ZAHq6Z03y65M9q2VJRmyO wQsM1j7DNB/GxiU1cjkLMjM5pedeD5CvLF6SBKaBPXiYatJw5LjY66U2DhPswImn9qWB OooA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ooEm88Uj; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Vg+Xv1GA; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p10-20020a170902eaca00b001890f02e96csi6036371pld.364.2022.11.21.06.39.56; Mon, 21 Nov 2022 06:40:10 -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=@linutronix.de header.s=2020 header.b=ooEm88Uj; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Vg+Xv1GA; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231715AbiKUOjY (ORCPT + 99 others); Mon, 21 Nov 2022 09:39:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230343AbiKUOh7 (ORCPT ); Mon, 21 Nov 2022 09:37:59 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFC80D92; Mon, 21 Nov 2022 06:37:58 -0800 (PST) Message-ID: <20221121091326.997114715@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041477; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=/uCay4K5eU0UtN6y+QL1HudBqKBANdJSYmtvg+386uI=; b=ooEm88UjCsEm5W9y811zhL+WFe07VtlieB+wKXqMDB34c3yPjy34haZgSbABZX2bFFOcrt cDbtomQVaaXhDvI4+L4DrDtldqxMuoJfEI5qAHaOYCGsp+t1uvhopPMJTEHkg65sfSdUDg 3W0SF1g6CEVPcmiXMJkJxVU3IhBsqQrmZn+X/Fj9t7zDgRiNV5mWWJ64rp9fXBEVZcDcXf /IS11ZW/XuhYZh35ya0GuCtt9Bn5zRfDbEmZX8ZLijUE3eabpYvAVGrvNfsEfgzI2WXYdR U3RjwQz4MK3LwDrVUpVSHtTAm1fCmYEmcQ/n8wfKjEs5P4mRWBhUejpTxcFDMQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041477; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=/uCay4K5eU0UtN6y+QL1HudBqKBANdJSYmtvg+386uI=; b=Vg+Xv1GAzvHAFOnp+MlzkYV2H5gMXKlmiuEdoIyZr8TJuEc0VaX+F8PhnN6Z/J2T8w49Vj KvrvlFRgrL4xqUDQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 09/33] genirq/msi: Add range checking to msi_insert_desc() References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:37:57 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750116976237367548?= X-GMAIL-MSGID: =?utf-8?q?1750116976237367548?= Per device domains provide the domain size to the core code. This allows range checking on insertion of MSI descriptors and also paves the way for dynamic index allocations which are required e.g. for IMS. This avoids external mechanisms like bitmaps on the device side and just utilizes the core internal MSI descriptor store for it. Signed-off-by: Thomas Gleixner --- kernel/irq/msi.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -74,6 +74,7 @@ static int msi_get_domain_base_index(str return domid * MSI_XA_DOMAIN_SIZE; } +static unsigned int msi_domain_get_hwsize(struct device *dev, unsigned int domid); /** * msi_alloc_desc - Allocate an initialized msi_desc @@ -116,6 +117,7 @@ static int msi_insert_desc(struct device unsigned int domid, unsigned int index) { struct msi_device_data *md = dev->msi.data; + unsigned int hwsize; int baseidx, ret; baseidx = msi_get_domain_base_index(dev, domid); @@ -124,6 +126,12 @@ static int msi_insert_desc(struct device goto fail; } + hwsize = msi_domain_get_hwsize(dev, domid); + if (index >= hwsize) { + ret = -ERANGE; + goto fail; + } + desc->msi_index = index; index += baseidx; ret = xa_insert(&md->__store, index, desc, GFP_KERNEL); @@ -179,9 +187,11 @@ static bool msi_desc_match(struct msi_de static bool msi_ctrl_range_valid(struct device *dev, struct msi_ctrl *ctrl) { + unsigned int hwsize = msi_domain_get_hwsize(dev, ctrl->domid); + if (WARN_ON_ONCE(ctrl->first > ctrl->last || - ctrl->first > MSI_MAX_INDEX || - ctrl->last > MSI_MAX_INDEX)) + ctrl->first >= hwsize || + ctrl->last >= hwsize)) return false; return true; } @@ -446,7 +456,7 @@ unsigned int msi_domain_get_virq(struct if (!dev->msi.data) return 0; - if (WARN_ON_ONCE(index > MSI_MAX_INDEX)) + if (WARN_ON_ONCE(index >= msi_domain_get_hwsize(dev, domid))) return 0; /* This check is only valid for the PCI default MSI domain */ @@ -614,6 +624,25 @@ static struct irq_domain *msi_get_device return domain; } +static unsigned int msi_domain_get_hwsize(struct device *dev, unsigned int domid) +{ + struct msi_domain_info *info; + struct irq_domain *domain; + + /* + * Retrieve the MSI domain for range checking. If there is no + * domain or the domain is not a per device domain, then assume + * full MSI range and pray that the calling subsystem knows what it + * is doing. + */ + domain = msi_get_device_domain(dev, domid); + if (domain && irq_domain_is_msi_device(domain)) { + info = domain->host_data; + return info->hwsize; + } + return MSI_MAX_INDEX + 1; +} + static inline void irq_chip_write_msi_msg(struct irq_data *data, struct msi_msg *msg) { @@ -1390,7 +1419,7 @@ int msi_domain_alloc_irqs_all_locked(str struct msi_ctrl ctrl = { .domid = domid, .first = 0, - .last = MSI_MAX_INDEX, + .last = msi_domain_get_hwsize(dev, domid) - 1, .nirqs = nirqs, }; @@ -1506,7 +1535,8 @@ void msi_domain_free_irqs_range(struct d */ void msi_domain_free_irqs_all_locked(struct device *dev, unsigned int domid) { - msi_domain_free_irqs_range_locked(dev, domid, 0, MSI_MAX_INDEX); + msi_domain_free_irqs_range_locked(dev, domid, 0, + msi_domain_get_hwsize(dev, domid) - 1); } /** From patchwork Mon Nov 21 14:37:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23818 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1627878wrr; Mon, 21 Nov 2022 06:40:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf5i+GVQBsT61EbwlWI654cMcUXh2+pmTqWpp9pt64a26UWAvmePRYJGeFbBJ6jh0SnDVYB/ X-Received: by 2002:a17:903:285:b0:189:25fb:ad0d with SMTP id j5-20020a170903028500b0018925fbad0dmr2311330plr.29.1669041614190; Mon, 21 Nov 2022 06:40:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041614; cv=none; d=google.com; s=arc-20160816; b=cMgbH2PKXtH4ayyhSH7BR3yZbxBB7dMXW6KznRCE+aiQInG/UIZT9vwek+CLwox/vv +uaFhnC+xc+XR1BTMc6QD8Oj0C7pf3ete2VwbJmsx131wpOzjZ5CzykgJKIjvM9LPcfR UjwGXHUo4/2NKzZPpNDJ/e/glXA7aWjgq+N38oEs3EmesAw1X3lpkRvyjRyVwArc2Q0V N+TfdTWqiKbmDkSFUKM6kVz1SWc9UzA0SiVCXhrcKkEd0VTKx7fAMAXUfyk+qHv8hOPy /n55Bl7M8+25Srn6RgDzw2/XwdkcPbdHSqT0gzb0KM5+s8kSp6nL52Bx+SXM/QypDd2I QdGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=osB1ROcuLYeqTjSSCjR+4n5EoRccoICYxGf0yGM+gI4=; b=bzs9JRAnSCGKjjzxsIFWYexScSGkWIG6GGD8KQZu/vmxzMeMRVGEgAznpZi9xkqsK+ OrHq3yL+le4RVLwsV9qS/yIptN7uE9tuYv3vAMOq/TRn8tHPeuMQdyD6PxORKMyskmhX R/UB3JnNXotyUA2HjqFyti+FrOGfUlGOWzEb/s4sg7x5RtHSwDSM7/X3SaV9KEQA4bnV cB1UaQcuDVqaBxjKUC+rkHeZc36wcJkUZxbvDoNgUYq1ceVC1W/dvk3IJ5uqcMfbSw3e X8z7vlvMxtWaBkOHpgQvPkq1L+DHvZKdsMujowaJqZ1cppuijV3NfKKU+qOpM/5xMnaD 9ImQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CjcF1nHV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=LxQT6oM5; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r10-20020a62e40a000000b0056cf9ed8f10si10085240pfh.329.2022.11.21.06.40.00; Mon, 21 Nov 2022 06:40:14 -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=@linutronix.de header.s=2020 header.b=CjcF1nHV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=LxQT6oM5; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229516AbiKUOja (ORCPT + 99 others); Mon, 21 Nov 2022 09:39:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231556AbiKUOiC (ORCPT ); Mon, 21 Nov 2022 09:38:02 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B587A1151; Mon, 21 Nov 2022 06:38:00 -0800 (PST) Message-ID: <20221121091327.052582141@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041478; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=osB1ROcuLYeqTjSSCjR+4n5EoRccoICYxGf0yGM+gI4=; b=CjcF1nHVVPQ+vQMM4Xjc7qK63wA+XwkrbbQ0WQKFkL9JfDBhS149n0aqLukgQaBtzKsdZZ MpOWBIY7iJxWl3o3rppF9iv1PzeGQuWoj6llmXAq0RWw2n/L3YDfpyu85OlKZBDcabh3Xh GkBmR7lkCjQsH98dngxdljpOlqLWgHnNXTkgDgT/ZWkS3/ZWRiEMwfctWlhXCIZkmP2tQ0 JNak4P1Mam/H5geM4ii9btF+IIwjSIvASV0Ypw/+3LxAR5WgojKKGU4zSPWz133npffjq0 hizgHQOUFyFOVoYBnOKhfJVP3UIjImxPLVRKzrx5A0+setcicNUdzKp+KdLcfQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041478; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=osB1ROcuLYeqTjSSCjR+4n5EoRccoICYxGf0yGM+gI4=; b=LxQT6oM5IFU5MISGXFVefKhZiDNMTu/mJbWRBEbyMObDqmgNT77lMrjmOAXxYjNaBmiZX1 dT4PRsM5MNxbE6Aw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe , "Ahmed S. Darwish" Subject: [patch V2 10/33] PCI/MSI: Split __pci_write_msi_msg() References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:37:58 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750116979455179305?= X-GMAIL-MSGID: =?utf-8?q?1750116979455179305?= The upcoming per device MSI domains will create different domains for MSI and MSI-X. Split the write message function into MSI and MSI-X helpers so they can be used by those new domain functions seperately. Signed-off-by: Ahmed S. Darwish Signed-off-by: Thomas Gleixner Signed-off-by: Thomas Gleixner Acked-by: Bjorn Helgaas --- drivers/pci/msi/msi.c | 104 +++++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 50 deletions(-) --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -180,6 +180,58 @@ void __pci_read_msi_msg(struct msi_desc } } +static inline void pci_write_msg_msi(struct pci_dev *dev, struct msi_desc *desc, + struct msi_msg *msg) +{ + int pos = dev->msi_cap; + u16 msgctl; + + pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); + msgctl &= ~PCI_MSI_FLAGS_QSIZE; + msgctl |= desc->pci.msi_attrib.multiple << 4; + pci_write_config_word(dev, pos + PCI_MSI_FLAGS, msgctl); + + pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, msg->address_lo); + if (desc->pci.msi_attrib.is_64) { + pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI, msg->address_hi); + pci_write_config_word(dev, pos + PCI_MSI_DATA_64, msg->data); + } else { + pci_write_config_word(dev, pos + PCI_MSI_DATA_32, msg->data); + } + /* Ensure that the writes are visible in the device */ + pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); +} + +static inline void pci_write_msg_msix(struct msi_desc *desc, struct msi_msg *msg) +{ + void __iomem *base = pci_msix_desc_addr(desc); + u32 ctrl = desc->pci.msix_ctrl; + bool unmasked = !(ctrl & PCI_MSIX_ENTRY_CTRL_MASKBIT); + + if (desc->pci.msi_attrib.is_virtual) + return; + /* + * The specification mandates that the entry is masked + * when the message is modified: + * + * "If software changes the Address or Data value of an + * entry while the entry is unmasked, the result is + * undefined." + */ + if (unmasked) + pci_msix_write_vector_ctrl(desc, ctrl | PCI_MSIX_ENTRY_CTRL_MASKBIT); + + writel(msg->address_lo, base + PCI_MSIX_ENTRY_LOWER_ADDR); + writel(msg->address_hi, base + PCI_MSIX_ENTRY_UPPER_ADDR); + writel(msg->data, base + PCI_MSIX_ENTRY_DATA); + + if (unmasked) + pci_msix_write_vector_ctrl(desc, ctrl); + + /* Ensure that the writes are visible in the device */ + readl(base + PCI_MSIX_ENTRY_DATA); +} + void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg) { struct pci_dev *dev = msi_desc_to_pci_dev(entry); @@ -187,63 +239,15 @@ void __pci_write_msi_msg(struct msi_desc if (dev->current_state != PCI_D0 || pci_dev_is_disconnected(dev)) { /* Don't touch the hardware now */ } else if (entry->pci.msi_attrib.is_msix) { - void __iomem *base = pci_msix_desc_addr(entry); - u32 ctrl = entry->pci.msix_ctrl; - bool unmasked = !(ctrl & PCI_MSIX_ENTRY_CTRL_MASKBIT); - - if (entry->pci.msi_attrib.is_virtual) - goto skip; - - /* - * The specification mandates that the entry is masked - * when the message is modified: - * - * "If software changes the Address or Data value of an - * entry while the entry is unmasked, the result is - * undefined." - */ - if (unmasked) - pci_msix_write_vector_ctrl(entry, ctrl | PCI_MSIX_ENTRY_CTRL_MASKBIT); - - writel(msg->address_lo, base + PCI_MSIX_ENTRY_LOWER_ADDR); - writel(msg->address_hi, base + PCI_MSIX_ENTRY_UPPER_ADDR); - writel(msg->data, base + PCI_MSIX_ENTRY_DATA); - - if (unmasked) - pci_msix_write_vector_ctrl(entry, ctrl); - - /* Ensure that the writes are visible in the device */ - readl(base + PCI_MSIX_ENTRY_DATA); + pci_write_msg_msix(entry, msg); } else { - int pos = dev->msi_cap; - u16 msgctl; - - pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); - msgctl &= ~PCI_MSI_FLAGS_QSIZE; - msgctl |= entry->pci.msi_attrib.multiple << 4; - pci_write_config_word(dev, pos + PCI_MSI_FLAGS, msgctl); - - pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, - msg->address_lo); - if (entry->pci.msi_attrib.is_64) { - pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI, - msg->address_hi); - pci_write_config_word(dev, pos + PCI_MSI_DATA_64, - msg->data); - } else { - pci_write_config_word(dev, pos + PCI_MSI_DATA_32, - msg->data); - } - /* Ensure that the writes are visible in the device */ - pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); + pci_write_msg_msi(dev, entry, msg); } -skip: entry->msg = *msg; if (entry->write_msi_msg) entry->write_msi_msg(entry, entry->write_msi_msg_data); - } void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg) From patchwork Mon Nov 21 14:37:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23820 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1627982wrr; Mon, 21 Nov 2022 06:40:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf4tkyk8UlBsG0kxIzTlMVB3pIuQ/CU1z08mbCR/rwnICx4sg4tKwA4G1+vOoA3d6KYMS2e3 X-Received: by 2002:a63:f64c:0:b0:476:f43d:5514 with SMTP id u12-20020a63f64c000000b00476f43d5514mr7808524pgj.236.1669041625128; Mon, 21 Nov 2022 06:40:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041625; cv=none; d=google.com; s=arc-20160816; b=wcarhRVsM9LMkEaB23ZcLTPj7vqVuDQ79agb/Oy8BcHS/kUie7NUmsYzysLlUlXXwo pyAUL/REzVG4moQx9cZATHwWsK+0HMkBSjrRkYpJY8wwdSSfDtRL4wPnfjOs+EYj2A5L YxV5In45u+ZMzHJcUY6zrDvUnG6f2TpZmoBzl+hAY/v6my0rwXlEG95f/QdOaVdrl9bj VSxGUNg9KNOpQt4m8qQf4P7ihU+xfHNL1zo22KTk2w3qtEVtuAOMLPe56P/SHMDK+zN4 V2SThRfAg6hf5mwdO9xf8Ygalj4iyc0COY9ZbNhO06MbJrLoimBe5wxez+U0nU1+La1j p4YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=XOCTiVJYLOJ/gUiXKzxrtpKOfabpzthMbAvZS4RWDg4=; b=oV/wQFSvVtcEgqokMLvXM9RINJOmS80jdBMO9XuB+dYSkJ6vhiPVP3S5OK35J7AFB+ Uxd6gxEk51B1fl3IwWoqrgkQFuQ2epn62u9bc84zOzuO7WKe0cB1aY5zg0NzVqFBDkYO kMsgMWFTMq71RZSvzBulKr4bJHRg/SCCs1YMti4Y+soIgYO6Occ/dE9O7kKF8FG9fgk5 CBVCNxtee5YaFMule0YMPtkZHkxi89Cw2XL0HLObYLR4ny5Z+3a9rGphmTIlpAbf9UCj ahTQ5t+ty6SkY3e27G1+0YNws7dOf5lLq9fIAiVc8aElfifOfkX/S0M6jBy8fXT4yLyv /3eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tKqf0m8+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g5-20020a63f405000000b0047015d155b9si11266810pgi.459.2022.11.21.06.40.11; Mon, 21 Nov 2022 06:40:25 -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=@linutronix.de header.s=2020 header.b=tKqf0m8+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231804AbiKUOjm (ORCPT + 99 others); Mon, 21 Nov 2022 09:39:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231637AbiKUOiC (ORCPT ); Mon, 21 Nov 2022 09:38:02 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59A4978B0B; Mon, 21 Nov 2022 06:38:01 -0800 (PST) Message-ID: <20221121091327.108540195@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041480; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=XOCTiVJYLOJ/gUiXKzxrtpKOfabpzthMbAvZS4RWDg4=; b=tKqf0m8+CVNR9w1aNa5wKoLGZB3ikf7efE4j9jUxS7j1nYsWeatkQNndBZ0Y14Tf2u7fi5 vz8v3ZT9/OA+5zzkZEcuUl0TMje5pRsx1ZTvKXjeLBm4J7tY+oMH1flZVvfFNoOblu2bVe N0nAAHLUIPJXGdSfHakNa3+oqgpDREDgrc9pBc+1kdlvSt8ZtTAAejFuGQA5kWsyzA+Szb tAfugd+Qzh/c266P266lk4sUvh67D3HFD5HpHig9atEVOcfbFIp2IsG37AC3drl0zh9Iyj wtNhtd+uEOMEAGarcoszNTfmub9bRUTZY3ehAeZrJnBAnXfCBwE8T7MTnBrFDw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041480; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=XOCTiVJYLOJ/gUiXKzxrtpKOfabpzthMbAvZS4RWDg4=; b=lKKF1NQKQeMvpAgwrorbz6RFxVwDyRuSuAVcVbiS8c5MvcWmYdtt7cCy8hDnBooxZ/cH7V lD/MqMoRmMQglGDw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 11/33] genirq/msi: Provide BUS_DEVICE_PCI_MSI[X] References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:37:59 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750116991149269289?= X-GMAIL-MSGID: =?utf-8?q?1750116991149269289?= Provide new bus tokens for the upcoming per device PCI/MSI and PCI/MSIX interrupt domains. Signed-off-by: Thomas Gleixner --- include/linux/irqdomain_defs.h | 2 ++ kernel/irq/msi.c | 4 ++++ 2 files changed, 6 insertions(+) --- a/include/linux/irqdomain_defs.h +++ b/include/linux/irqdomain_defs.h @@ -21,6 +21,8 @@ enum irq_domain_bus_token { DOMAIN_BUS_TI_SCI_INTA_MSI, DOMAIN_BUS_WAKEUP, DOMAIN_BUS_VMD_MSI, + DOMAIN_BUS_PCI_DEVICE_MSI, + DOMAIN_BUS_PCI_DEVICE_MSIX, }; #endif /* _LINUX_IRQDOMAIN_DEFS_H */ --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -1147,6 +1147,8 @@ static bool msi_check_reservation_mode(s switch(domain->bus_token) { case DOMAIN_BUS_PCI_MSI: + case DOMAIN_BUS_PCI_DEVICE_MSI: + case DOMAIN_BUS_PCI_DEVICE_MSIX: case DOMAIN_BUS_VMD_MSI: break; default: @@ -1172,6 +1174,8 @@ static int msi_handle_pci_fail(struct ir { switch(domain->bus_token) { case DOMAIN_BUS_PCI_MSI: + case DOMAIN_BUS_PCI_DEVICE_MSI: + case DOMAIN_BUS_PCI_DEVICE_MSIX: case DOMAIN_BUS_VMD_MSI: if (IS_ENABLED(CONFIG_PCI_MSI)) break; From patchwork Mon Nov 21 14:38:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23821 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1628041wrr; Mon, 21 Nov 2022 06:40:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf5uCAItu3ui7Bwtgwh/G/n+nuG+CuE2ZBPfBpYNCnSms5BYJKViwQc5bLRmhaE9pNlkmUlE X-Received: by 2002:a63:fe16:0:b0:46b:8e9:7d5f with SMTP id p22-20020a63fe16000000b0046b08e97d5fmr857524pgh.597.1669041630619; Mon, 21 Nov 2022 06:40:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041630; cv=none; d=google.com; s=arc-20160816; b=unlXaIof9Zb2hv8LZ/OVhfxJyrfihzeDI4DAwsgcgdE/x6eeKWvFA9rgI6axQpBkbV 3DAjZwgOUrUxnuYPJ5gJtVr+TOJosRxruOXSct4digzogGO+IgJtcqNn1UItkpl8EffS t1AKr8vq0n9/9MYj5/Qw9OLPsinV1ie7D/+945QUhP8EPn7RINQ/z0nguN4T2ZnbG8+M Wz+v/3zB1B7ROlWQGj1NQHf+KnLNCj+k6jNEsECaqAvyEwDjQvLuKPm9Oc0dsPWhwMav ZrVu7XR9j40cNPg7ytDPer0sKhNYDWoBjMpUnCPvkWdkhRdEB34So7DywtU5jUaLVOh+ TGgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=WxwA11DtpivrCyoDEYoza2C0ym/L3DXjD/JxMmBTYVU=; b=IecuANgHOAP83Wr9fC/0DbteOWyg3QYOv/MoIDS9Tuvz3xj0NrERX41HETL59XPSJs 9D7Jb+713yXDFwQkX3IydvvbrB7PAUOmJ1O7RlxM4TSMo73r59kLcIH9d4F/9AboDfRM vKEsaNFvFm1MidpjOF4mHHYFMOuFrfQyDGZQh4SU/B6ubVXkDNifFqfEkq0zAzbVZDa/ J1Y0W1qSVo5W7J57j972Qklqx9Jmk5bpBG5HvhKwARpaoQi4TfuNJSah4z1SqvS5KhEi 0YIvMvJxvaFEscknPoo3Za0TyKIM1r2v8QtyR4fyyZvlB5Xgy3R4yJZk6xUUf3JqxJFO gBKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xC30HMnC; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s6-20020a056a0008c600b0056c057b09b0si11333155pfu.216.2022.11.21.06.40.15; Mon, 21 Nov 2022 06:40:30 -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=@linutronix.de header.s=2020 header.b=xC30HMnC; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231809AbiKUOjt (ORCPT + 99 others); Mon, 21 Nov 2022 09:39:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231644AbiKUOiE (ORCPT ); Mon, 21 Nov 2022 09:38:04 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC0DE9039B; Mon, 21 Nov 2022 06:38:02 -0800 (PST) Message-ID: <20221121091327.163146917@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041481; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=WxwA11DtpivrCyoDEYoza2C0ym/L3DXjD/JxMmBTYVU=; b=xC30HMnC74NdMcPyguSTnNkb27BKqoi9qHkRgtvm4stuXLLmyj4x3YYT0VqEvFRoPEyHT7 gpZ8iYdEWDQRXp5Md9TrY23BywGyXDtjjmS1gegF7JhjXwzkpuP5bCK2eNBUr7NnsswmP2 aP/d6RPNgkfzhhgrS6gHXRV0iqlskNv3qwBRbUChqlS5ktWVlgAsr6JgmyJeEVTJKw/WOm 0C6WahPT2C1RCrDEMTOlchGfb4QnZwybMXKG6OnvnaoDd+dAlon+8j+B5maRVgeb5Xap5b 6CZ9Ec7T/LXh5s/liuTgh4jL0HQpHQ8YYVqSYooxJZZx7z+/vubsYeMO8Xdo4Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041481; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=WxwA11DtpivrCyoDEYoza2C0ym/L3DXjD/JxMmBTYVU=; b=78kb6N7g5y32EuS/ldr5Oe/PfB9CcO4HTrSOTGHY6BIskUOHDE/tFX5aDdjaYZXUv1+4/O 6neqgyo+3LhAJdBg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe , "Ahmed S. Darwish" Subject: [patch V2 12/33] PCI/MSI: Add support for per device MSI[X] domains References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:01 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750116996897668744?= X-GMAIL-MSGID: =?utf-8?q?1750116996897668744?= Provide a template and the necessary callbacks to create PCI/MSI and PCI/MSI-X domains. The domains are created when MSI or MSI-X is enabled. The domain's lifetime is either the device lifetime or in case that e.g. MSI-X was tried first and failed, then the MSI-X domain is removed and a MSI domain is created as both are mutually exclusive and reside in the default domain ID slot of the per device domain pointer array. Also expand pci_msi_domain_supports() to handle feature checks correctly even in the case that the per device domain was not yet created by checking the features supported by the MSI parent. Add the necessary setup calls into the MSI and MSI-X enable code path. These setup calls are backwards compatible. They return success when there is no parent domain found, which means the existing global domains or the legacy allocation path keep just working. Co-developed-by: Ahmed S. Darwish Signed-off-by: Ahmed S. Darwish Signed-off-by: Thomas Gleixner Acked-by: Bjorn Helgaas --- drivers/pci/msi/irqdomain.c | 188 +++++++++++++++++++++++++++++++++++++++++++- drivers/pci/msi/msi.c | 16 +++ drivers/pci/msi/msi.h | 2 3 files changed, 201 insertions(+), 5 deletions(-) --- a/drivers/pci/msi/irqdomain.c +++ b/drivers/pci/msi/irqdomain.c @@ -139,6 +139,170 @@ struct irq_domain *pci_msi_create_irq_do } EXPORT_SYMBOL_GPL(pci_msi_create_irq_domain); +/* + * Per device MSI[-X] domain functionality + */ +static void pci_device_domain_set_desc(msi_alloc_info_t *arg, struct msi_desc *desc) +{ + arg->desc = desc; + arg->hwirq = desc->msi_index; +} + +static void pci_mask_msi(struct irq_data *data) +{ + struct msi_desc *desc = irq_data_get_msi_desc(data); + + pci_msi_mask(desc, BIT(data->irq - desc->irq)); +} + +static void pci_unmask_msi(struct irq_data *data) +{ + struct msi_desc *desc = irq_data_get_msi_desc(data); + + pci_msi_unmask(desc, BIT(data->irq - desc->irq)); +} + +#ifdef CONFIG_GENERIC_IRQ_RESERVATION_MODE +# define MSI_REACTIVATE MSI_FLAG_MUST_REACTIVATE +#else +# define MSI_REACTIVATE 0 +#endif + +#define MSI_COMMON_FLAGS (MSI_FLAG_FREE_MSI_DESCS | \ + MSI_FLAG_ACTIVATE_EARLY | \ + MSI_FLAG_DEV_SYSFS | \ + MSI_REACTIVATE) + +static struct msi_domain_template pci_msi_template = { + .chip = { + .name = "PCI-MSI", + .irq_mask = pci_mask_msi, + .irq_unmask = pci_unmask_msi, + .irq_write_msi_msg = pci_msi_domain_write_msg, + .flags = IRQCHIP_ONESHOT_SAFE, + }, + + .ops = { + .set_desc = pci_device_domain_set_desc, + }, + + .info = { + .flags = MSI_COMMON_FLAGS | MSI_FLAG_MULTI_PCI_MSI, + .bus_token = DOMAIN_BUS_PCI_DEVICE_MSI, + }, +}; + +static void pci_mask_msix(struct irq_data *data) +{ + pci_msix_mask(irq_data_get_msi_desc(data)); +} + +static void pci_unmask_msix(struct irq_data *data) +{ + pci_msix_unmask(irq_data_get_msi_desc(data)); +} + +static struct msi_domain_template pci_msix_template = { + .chip = { + .name = "PCI-MSIX", + .irq_mask = pci_mask_msix, + .irq_unmask = pci_unmask_msix, + .irq_write_msi_msg = pci_msi_domain_write_msg, + .flags = IRQCHIP_ONESHOT_SAFE, + }, + + .ops = { + .set_desc = pci_device_domain_set_desc, + }, + + .info = { + .flags = MSI_COMMON_FLAGS | MSI_FLAG_PCI_MSIX, + .bus_token = DOMAIN_BUS_PCI_DEVICE_MSIX, + }, +}; + +static bool pci_match_device_domain(struct pci_dev *pdev, enum irq_domain_bus_token bus_token) +{ + return msi_match_device_irq_domain(&pdev->dev, MSI_DEFAULT_DOMAIN, bus_token); +} + +static bool pci_create_device_domain(struct pci_dev *pdev, struct msi_domain_template *tmpl, + unsigned int hwsize) +{ + struct irq_domain *domain = dev_get_msi_domain(&pdev->dev); + + if (!domain || !irq_domain_is_msi_parent(domain)) + return true; + + return msi_create_device_irq_domain(&pdev->dev, MSI_DEFAULT_DOMAIN, tmpl, + hwsize, NULL, NULL); +} + +/** + * pci_setup_msi_device_domain - Setup a device MSI interrupt domain + * @pdev: The PCI device to create the domain on + * + * Return: + * True when: + * - The device does not have a MSI parent irq domain associated, + * which keeps the legacy architecture specific and the global + * PCI/MSI domain models working + * - The MSI domain exists already + * - The MSI domain was successfully allocated + * False when: + * - MSI-X is enabled + * - The domain creation fails. + * + * The created MSI domain is preserved until: + * - The device is removed + * - MSI is disabled and a MSI-X domain is created + */ +bool pci_setup_msi_device_domain(struct pci_dev *pdev) +{ + if (WARN_ON_ONCE(pdev->msix_enabled)) + return false; + + if (pci_match_device_domain(pdev, DOMAIN_BUS_PCI_DEVICE_MSI)) + return true; + if (pci_match_device_domain(pdev, DOMAIN_BUS_PCI_DEVICE_MSIX)) + msi_remove_device_irq_domain(&pdev->dev, MSI_DEFAULT_DOMAIN); + + return pci_create_device_domain(pdev, &pci_msi_template, 1); +} + +/** + * pci_setup_msix_device_domain - Setup a device MSI-X interrupt domain + * @pdev: The PCI device to create the domain on + * @hwsize: The size of the MSI-X vector table + * + * Return: + * True when: + * - The device does not have a MSI parent irq domain associated, + * which keeps the legacy architecture specific and the global + * PCI/MSI domain models working + * - The MSI-X domain exists already + * - The MSI-X domain was successfully allocated + * False when: + * - MSI is enabled + * - The domain creation fails. + * + * The created MSI-X domain is preserved until: + * - The device is removed + * - MSI-X is disabled and a MSI domain is created + */ +bool pci_setup_msix_device_domain(struct pci_dev *pdev, unsigned int hwsize) +{ + if (WARN_ON_ONCE(pdev->msix_enabled)) + return false; + + if (pci_match_device_domain(pdev, DOMAIN_BUS_PCI_DEVICE_MSIX)) + return true; + if (pci_match_device_domain(pdev, DOMAIN_BUS_PCI_DEVICE_MSI)) + msi_remove_device_irq_domain(&pdev->dev, MSI_DEFAULT_DOMAIN); + + return pci_create_device_domain(pdev, &pci_msix_template, hwsize); +} + /** * pci_msi_domain_supports - Check for support of a particular feature flag * @pdev: The PCI device to operate on @@ -152,13 +316,33 @@ bool pci_msi_domain_supports(struct pci_ { struct msi_domain_info *info; struct irq_domain *domain; + unsigned int supported; domain = dev_get_msi_domain(&pdev->dev); if (!domain || !irq_domain_is_hierarchy(domain)) return mode == ALLOW_LEGACY; - info = domain->host_data; - return (info->flags & feature_mask) == feature_mask; + + if (!irq_domain_is_msi_parent(domain)) { + /* + * For "global" PCI/MSI interrupt domains the associated + * msi_domain_info::flags is the authoritive source of + * information. + */ + info = domain->host_data; + supported = info->flags; + } else { + /* + * For MSI parent domains the supported feature set + * is avaliable in the parent ops. This makes checks + * possible before actually instantiating the + * per device domain because the parent is never + * expanding the PCI/MSI functionality. + */ + supported = domain->msi_parent_ops->supported_flags; + } + + return (supported & feature_mask) == feature_mask; } /* --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -436,6 +436,9 @@ int __pci_enable_msi_range(struct pci_de if (rc) return rc; + if (!pci_setup_msi_device_domain(dev)) + return -ENODEV; + for (;;) { if (affd) { nvec = irq_calc_affinity_vectors(minvec, nvec, affd); @@ -787,9 +790,13 @@ int __pci_enable_msix_range(struct pci_d if (!pci_msix_validate_entries(dev, entries, nvec, hwsize)) return -EINVAL; - /* PCI_IRQ_VIRTUAL is a horrible hack! */ - if (nvec > hwsize && !(flags & PCI_IRQ_VIRTUAL)) - nvec = hwsize; + if (hwsize < nvec) { + /* Keep the IRQ virtual hackery working */ + if (flags & PCI_IRQ_VIRTUAL) + hwsize = nvec; + else + nvec = hwsize; + } if (nvec < minvec) return -ENOSPC; @@ -798,6 +805,9 @@ int __pci_enable_msix_range(struct pci_d if (rc) return rc; + if (!pci_setup_msix_device_domain(dev, hwsize)) + return -ENODEV; + for (;;) { if (affd) { nvec = irq_calc_affinity_vectors(minvec, nvec, affd); --- a/drivers/pci/msi/msi.h +++ b/drivers/pci/msi/msi.h @@ -105,6 +105,8 @@ enum support_mode { }; bool pci_msi_domain_supports(struct pci_dev *dev, unsigned int feature_mask, enum support_mode mode); +bool pci_setup_msi_device_domain(struct pci_dev *pdev); +bool pci_setup_msix_device_domain(struct pci_dev *pdev, unsigned int hwsize); /* Legacy (!IRQDOMAIN) fallbacks */ From patchwork Mon Nov 21 14:38:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23822 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1628079wrr; Mon, 21 Nov 2022 06:40:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf7LjYODLlLA4ER6cTv2oO8nyFixBDVjiDfbRatIkIH+q0tPCti6hprJLRBbnfX3iZFIpuOO X-Received: by 2002:aa7:9257:0:b0:56c:cea7:8650 with SMTP id 23-20020aa79257000000b0056ccea78650mr1264643pfp.40.1669041634552; Mon, 21 Nov 2022 06:40:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041634; cv=none; d=google.com; s=arc-20160816; b=Fjv9TVPLw1YqSmg/rfkkLTYGPiWK9GcM4/Doocv2CUVMYMZdoNpKv2+OWjw1/Su0xV 8NHPChsW8v5OTc63U27ipbnWknAml0nyR90/M1k7iiKalttraMRUVQLQ8geHVXGRMY9P OP/pslEClrfM+8EYksX5FWB1xtIj65DB0x0dLHePhwPRk7Fmo9XiKzzXK5EzgTxweWfR N2xe8oVSeP7q5EiUTtuJzY/DmQSteATQNM8iQdla7HIAcBiYXp+dFEceMz2JddBOfeHN bmF4YHZdf+FzOC5W6REjg6mmrpTC7QaxuTagGAPY0w9eqETHjs9MF7w175lgiuRdftnB Q4sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=Bult+QOTyn3yk1J2BaE5BOxLAmykZwJ6i9DuwWbDSqo=; b=skjPwtcxTnPfqalI4H80GLfBAaVetX2BL4xdwVPgkTBlwkmKD8syQ69w61LhmNnpIn rssj9YX0Ftj00DSohOmal6hNiIz+k3BZCLg/WGbGWKg5zx/QhjJ4+fbLzVjMVjizeSdS 608FZriLtHKyySS2wyBx1SsIXUBDWQjfLnJE4MQK/yLfVKl6C6JYhtFgd1hv0mkdtLiV cbd4I9KwzelqKK6FQF17I629TYWa/Hzg1tsedvHvQo6W/Z5ar0CA7XLzf8h0YgXL8zge DslICCaVshYZefCuLSjINvqw/miX8UT5qf9tIKW45fDzdg/w2fD+lrvGrI4FG9zQO4tS w4JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=eE1BHc3s; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sh7-20020a17090b524700b0021870b9d3c7si10012441pjb.45.2022.11.21.06.40.19; Mon, 21 Nov 2022 06:40:34 -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=@linutronix.de header.s=2020 header.b=eE1BHc3s; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231816AbiKUOjv (ORCPT + 99 others); Mon, 21 Nov 2022 09:39:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231646AbiKUOiF (ORCPT ); Mon, 21 Nov 2022 09:38:05 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7C1B2657; Mon, 21 Nov 2022 06:38:03 -0800 (PST) Message-ID: <20221121091327.217466288@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041482; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=Bult+QOTyn3yk1J2BaE5BOxLAmykZwJ6i9DuwWbDSqo=; b=eE1BHc3stVMCwQrQAUDAd1nHoGWQdcQRs+M83JPkeKRX6ctN69qY9uhrxVx+LGlCZBtVK5 /UmGPqsaz9IAchDZlM/jqQg1h4m/KVoXckfZQtklH3mqgmsX9Wq747EwulwN7W1qDtRExs 8yJt+xRDhvzVmuhQq3BQqBHJm+oXRuBS5cnFV7v83jYdHsT5Hl4SaeStepYgzapVosU9Sr iGGGeAxY5uvkWllvrDFOn1zEW5rJUpsIfV5DnUund0raH+BDZrfho4ukLZBJ789LsD8LIQ rrqvdW/0LOoxVVzh2gOeSfS4oZcgtU1wghZ309ZPJhfRTc2N337csp7GVYoQ/w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041482; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=Bult+QOTyn3yk1J2BaE5BOxLAmykZwJ6i9DuwWbDSqo=; b=Os+MLmx8pPA3/dTcyFjd+KvxxvEdJhEiShuNmjwR+j09rn94U86q8zQPV2aq5Tsmz+6Wna rx9gcWt6WWF8GkDg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 13/33] x86/apic/vector: Provide MSI parent domain References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:02 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117000776021835?= X-GMAIL-MSGID: =?utf-8?q?1750117000776021835?= Enable MSI parent domain support in the x86 vector domain and fixup the checks in the iommu implementations to check whether device::msi::domain is the default MSI parent domain. That keeps the existing logic to protect e.g. devices behind VMD working. The interrupt remap PCI/MSI code still works because the underlying vector domain still provides the same functionality. None of the other x86 PCI/MSI, e.g. XEN and HyperV, implementations are affected either. They still work the same way both at the low level and the PCI/MSI implementations they provide. Signed-off-by: Thomas Gleixner --- V2: Fix kernel doc (robot) --- arch/x86/include/asm/msi.h | 6 + arch/x86/include/asm/pci.h | 1 arch/x86/kernel/apic/msi.c | 176 ++++++++++++++++++++++++++---------- drivers/iommu/amd/iommu.c | 2 drivers/iommu/intel/irq_remapping.c | 2 5 files changed, 138 insertions(+), 49 deletions(-) --- a/arch/x86/include/asm/msi.h +++ b/arch/x86/include/asm/msi.h @@ -62,4 +62,10 @@ typedef struct x86_msi_addr_hi { struct msi_msg; u32 x86_msi_msg_get_destid(struct msi_msg *msg, bool extid); +#define X86_VECTOR_MSI_FLAGS_SUPPORTED \ + (MSI_GENERIC_FLAGS_MASK | MSI_FLAG_PCI_MSIX) + +#define X86_VECTOR_MSI_FLAGS_REQUIRED \ + (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS) + #endif /* _ASM_X86_MSI_H */ --- a/arch/x86/include/asm/pci.h +++ b/arch/x86/include/asm/pci.h @@ -92,6 +92,7 @@ void pcibios_scan_root(int bus); struct irq_routing_table *pcibios_get_irq_routing_table(void); int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq); +bool pci_dev_has_default_msi_parent_domain(struct pci_dev *dev); #define HAVE_PCI_MMAP #define arch_can_pci_mmap_wc() pat_enabled() --- a/arch/x86/kernel/apic/msi.c +++ b/arch/x86/kernel/apic/msi.c @@ -142,67 +142,131 @@ msi_set_affinity(struct irq_data *irqd, return ret; } -/* - * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices, - * which implement the MSI or MSI-X Capability Structure. +/** + * pci_dev_has_default_msi_parent_domain - Check whether the device has the default + * MSI parent domain associated + * @dev: Pointer to the PCI device */ -static struct irq_chip pci_msi_controller = { - .name = "PCI-MSI", - .irq_unmask = pci_msi_unmask_irq, - .irq_mask = pci_msi_mask_irq, - .irq_ack = irq_chip_ack_parent, - .irq_retrigger = irq_chip_retrigger_hierarchy, - .irq_set_affinity = msi_set_affinity, - .flags = IRQCHIP_SKIP_SET_WAKE | - IRQCHIP_AFFINITY_PRE_STARTUP, -}; +bool pci_dev_has_default_msi_parent_domain(struct pci_dev *dev) +{ + struct irq_domain *domain = dev_get_msi_domain(&dev->dev); -int pci_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec, - msi_alloc_info_t *arg) + if (!domain) + domain = dev_get_msi_domain(&dev->bus->dev); + if (!domain) + return false; + + return domain == x86_vector_domain; +} + +/** + * x86_msi_prepare - Setup of msi_alloc_info_t for allocations + * @domain: The domain for which this setup happens + * @dev: The device for which interrupts are allocated + * @nvec: The number of vectors to allocate + * @alloc: The allocation info structure to initialize + * + * This function is to be used for all types of MSI domains above the x86 + * vector domain and any intermediates. It is always invoked from the + * top level interrupt domain. The domain specific allocation + * functionality is determined via the @domain's bus token which allows to + * map the X86 specific allocation type. + */ +static int x86_msi_prepare(struct irq_domain *domain, struct device *dev, + int nvec, msi_alloc_info_t *alloc) { - init_irq_alloc_info(arg, NULL); - if (to_pci_dev(dev)->msix_enabled) - arg->type = X86_IRQ_ALLOC_TYPE_PCI_MSIX; - else - arg->type = X86_IRQ_ALLOC_TYPE_PCI_MSI; + struct msi_domain_info *info = domain->host_data; - return 0; + init_irq_alloc_info(alloc, NULL); + + switch (info->bus_token) { + case DOMAIN_BUS_PCI_DEVICE_MSI: + alloc->type = X86_IRQ_ALLOC_TYPE_PCI_MSI; + return 0; + case DOMAIN_BUS_PCI_DEVICE_MSIX: + alloc->type = X86_IRQ_ALLOC_TYPE_PCI_MSIX; + return 0; + default: + return -EINVAL; + } } -EXPORT_SYMBOL_GPL(pci_msi_prepare); -static struct msi_domain_ops pci_msi_domain_ops = { - .msi_prepare = pci_msi_prepare, -}; +/** + * x86_init_dev_msi_info - Domain info setup for MSI domains + * @dev: The device for which the domain should be created + * @domain: The (root) domain providing this callback + * @real_parent: The real parent domain of the to initialize domain + * @info: The domain info for the to initialize domain + * + * This function is to be used for all types of MSI domains above the x86 + * vector domain and any intermediates. The domain specific functionality + * is determined via the @real_parent. + */ +static bool x86_init_dev_msi_info(struct device *dev, struct irq_domain *domain, + struct irq_domain *real_parent, struct msi_domain_info *info) +{ + const struct msi_parent_ops *pops = real_parent->msi_parent_ops; + + /* MSI parent domain specific settings */ + switch (real_parent->bus_token) { + case DOMAIN_BUS_ANY: + /* Only the vector domain can have the ANY token */ + if (WARN_ON_ONCE(domain != real_parent)) + return false; + info->chip->irq_set_affinity = msi_set_affinity; + /* See msi_set_affinity() for the gory details */ + info->flags |= MSI_FLAG_NOMASK_QUIRK; + break; + default: + WARN_ON_ONCE(1); + return false; + } + + /* Is the target supported? */ + switch(info->bus_token) { + case DOMAIN_BUS_PCI_DEVICE_MSI: + case DOMAIN_BUS_PCI_DEVICE_MSIX: + break; + default: + WARN_ON_ONCE(1); + return false; + } + + /* + * Mask out the domain specific MSI feature flags which are not + * supported by the real parent. + */ + info->flags &= pops->supported_flags; + /* Enforce the required flags */ + info->flags |= X86_VECTOR_MSI_FLAGS_REQUIRED; + + /* This is always invoked from the top level MSI domain! */ + info->ops->msi_prepare = x86_msi_prepare; + + info->chip->irq_ack = irq_chip_ack_parent; + info->chip->irq_retrigger = irq_chip_retrigger_hierarchy; + info->chip->flags |= IRQCHIP_SKIP_SET_WAKE | + IRQCHIP_AFFINITY_PRE_STARTUP; -static struct msi_domain_info pci_msi_domain_info = { - .flags = MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS | - MSI_FLAG_PCI_MSIX | MSI_FLAG_NOMASK_QUIRK, - - .ops = &pci_msi_domain_ops, - .chip = &pci_msi_controller, - .handler = handle_edge_irq, - .handler_name = "edge", + info->handler = handle_edge_irq; + info->handler_name = "edge"; + + return true; +} + +static const struct msi_parent_ops x86_vector_msi_parent_ops = { + .supported_flags = X86_VECTOR_MSI_FLAGS_SUPPORTED, + .init_dev_msi_info = x86_init_dev_msi_info, }; struct irq_domain * __init native_create_pci_msi_domain(void) { - struct fwnode_handle *fn; - struct irq_domain *d; - if (disable_apic) return NULL; - fn = irq_domain_alloc_named_fwnode("PCI-MSI"); - if (!fn) - return NULL; - - d = pci_msi_create_irq_domain(fn, &pci_msi_domain_info, - x86_vector_domain); - if (!d) { - irq_domain_free_fwnode(fn); - pr_warn("Failed to initialize PCI-MSI irqdomain.\n"); - } - return d; + x86_vector_domain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT; + x86_vector_domain->msi_parent_ops = &x86_vector_msi_parent_ops; + return x86_vector_domain; } void __init x86_create_pci_msi_domain(void) @@ -210,7 +274,25 @@ void __init x86_create_pci_msi_domain(vo x86_pci_msi_default_domain = x86_init.irqs.create_pci_msi_domain(); } +/* Keep around for hyperV and the remap code below */ +int pci_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec, + msi_alloc_info_t *arg) +{ + init_irq_alloc_info(arg, NULL); + + if (to_pci_dev(dev)->msix_enabled) + arg->type = X86_IRQ_ALLOC_TYPE_PCI_MSIX; + else + arg->type = X86_IRQ_ALLOC_TYPE_PCI_MSI; + return 0; +} +EXPORT_SYMBOL_GPL(pci_msi_prepare); + #ifdef CONFIG_IRQ_REMAP +static struct msi_domain_ops pci_msi_domain_ops = { + .msi_prepare = pci_msi_prepare, +}; + static struct irq_chip pci_msi_ir_controller = { .name = "IR-PCI-MSI", .irq_unmask = pci_msi_unmask_irq, --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -812,7 +812,7 @@ static void amd_iommu_set_pci_msi_domain(struct device *dev, struct amd_iommu *iommu) { if (!irq_remapping_enabled || !dev_is_pci(dev) || - pci_dev_has_special_msi_domain(to_pci_dev(dev))) + !pci_dev_has_default_msi_parent_domain(to_pci_dev(dev))) return; dev_set_msi_domain(dev, iommu->msi_domain); --- a/drivers/iommu/intel/irq_remapping.c +++ b/drivers/iommu/intel/irq_remapping.c @@ -1107,7 +1107,7 @@ static int reenable_irq_remapping(int ei */ void intel_irq_remap_add_device(struct dmar_pci_notify_info *info) { - if (!irq_remapping_enabled || pci_dev_has_special_msi_domain(info->dev)) + if (!irq_remapping_enabled || !pci_dev_has_default_msi_parent_domain(info->dev)) return; dev_set_msi_domain(&info->dev->dev, map_dev_to_ir(info->dev)); From patchwork Mon Nov 21 14:38:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23823 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1628099wrr; Mon, 21 Nov 2022 06:40:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf7d7n1lUxMvyw0d9LanI5an/zfUTQDxCuHS4eMx1e01MfeOOMA7r5L1aV0bSuzuhG4kDgfJ X-Received: by 2002:a63:4e0c:0:b0:476:dd4f:a2c7 with SMTP id c12-20020a634e0c000000b00476dd4fa2c7mr1304173pgb.523.1669041637100; Mon, 21 Nov 2022 06:40:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041637; cv=none; d=google.com; s=arc-20160816; b=bFo3To6IGPqVZf1gzYEfbSDxXiSY3h9ZkB+GaaKa3GEoljtZCoEQBt/3kZ4Mmi0h0q 86MSBZi9WbVudxnSsbAguLcA4BuKM+Hy112qm8JWgNOb545yQ6ebm4CatIlB1S+li+RW ifLa8VxKcbBLO0KVkYHt50Uw8sEYwj5pGU4St5dz4y37nbnlVa1KQQgvF52onpXaxxnL T9xfHQ4YT7IN2ityzMSVjelYzOH6k1hkvbxZT9kTYdYX7UkKDSC+Hy6erYEAfoSaI6Vj u+1rxiEjEIjqhfA1Uj4soJPrc2v1044nUK+DFSYUnQcct8+H12jGRUBzZN1+tfUwKiTF epRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=pglOtQogKZeQllvETY7CSk7rnX36uaU40AecgPWhjoQ=; b=DDK1FjOkRrtfgARrjFfNbcpyY2FpUEplNxoU93KEmTm1Ce/jNeAK59KIJGyRePPHga /uz+o7oKk4MUCNIwcme9AArtSz7P/2Ly7Js9z7sBXhDm+np08Qb5G7eLkFKsVEx/Tk6V eiHvPGaDl/Ij4UWpCrrv4vRROqnwb2ujNDiVNrMSk7YvPJUc0wW1WlDcMVkzmZ9GL+6u rhQGq+6se4Z2y4GU5VNs0m/2k9ntzBnT0ksbmc5IXHS/E1Zv/biMaeO19K9e+GxzNMR2 xIO4t8+LQ58t2hXEHK6HQrJL5oJkqDJjyoND3fBVdxbWm3hDluRGEqwaxXJmey9n5ZlE giig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=391M42bB; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rm1-20020a17090b3ec100b0020ad4d5b9e8si16037571pjb.89.2022.11.21.06.40.21; Mon, 21 Nov 2022 06:40:37 -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=@linutronix.de header.s=2020 header.b=391M42bB; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231822AbiKUOj5 (ORCPT + 99 others); Mon, 21 Nov 2022 09:39:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231565AbiKUOiH (ORCPT ); Mon, 21 Nov 2022 09:38:07 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED46D9152D; Mon, 21 Nov 2022 06:38:05 -0800 (PST) Message-ID: <20221121091327.271728371@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041483; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=pglOtQogKZeQllvETY7CSk7rnX36uaU40AecgPWhjoQ=; b=391M42bBt6zLla3u1QfX8pFEu7R357b3+nCAD3BmLZ5p1BBDOUjjpcKkNPe/banH7YtiUO q1QBbThvPTFWQ91FwQnNXhmGzZrZeuZMlhLvQ4o4vaUtnOk6lAYZmVeDwrQKy1ccpmD4fh qxa8waJZiHYml7mqDk/gDwdgW/UpOe6z2HFENoF2KWRm2TPwQw0PyZ6WDx0rbAn8zVfVji juZVSoO1N+ozdmfSEV5n+bx7AO6DoWVV7PKPHNbsUM4SPv1oM/Jnitm5lkc4/dCdI2/lMM qSGqNQHh/eDmMGzAXdQeWBSmTuYRDyRQlsW6/iCQx1GYcKfFXxeCpV7eFMklWA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041483; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=pglOtQogKZeQllvETY7CSk7rnX36uaU40AecgPWhjoQ=; b=Ek5r2C0PHrpj7mIvSrtps1M2Vcl7Jw8jYkqwi3nsLAi9V2DZ1DeQflV54Jf48xz9X3aYvo zT7J24GKIx5wBoCg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 14/33] PCI/MSI: Remove unused pci_dev_has_special_msi_domain() References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:03 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117003611247593?= X-GMAIL-MSGID: =?utf-8?q?1750117003611247593?= The check for special MSI domains like VMD which prevents the interrupt remapping code to overwrite device::msi::domain is not longer required and has been replaced by an x86 specific version which is aware of MSI parent domains. Remove it. Signed-off-by: Thomas Gleixner Acked-by: Bjorn Helgaas --- drivers/pci/msi/irqdomain.c | 21 --------------------- include/linux/msi.h | 1 - 2 files changed, 22 deletions(-) --- a/drivers/pci/msi/irqdomain.c +++ b/drivers/pci/msi/irqdomain.c @@ -414,24 +414,3 @@ struct irq_domain *pci_msi_get_device_do DOMAIN_BUS_PCI_MSI); return dom; } - -/** - * pci_dev_has_special_msi_domain - Check whether the device is handled by - * a non-standard PCI-MSI domain - * @pdev: The PCI device to check. - * - * Returns: True if the device irqdomain or the bus irqdomain is - * non-standard PCI/MSI. - */ -bool pci_dev_has_special_msi_domain(struct pci_dev *pdev) -{ - struct irq_domain *dom = dev_get_msi_domain(&pdev->dev); - - if (!dom) - dom = dev_get_msi_domain(&pdev->bus->dev); - - if (!dom) - return true; - - return dom->bus_token != DOMAIN_BUS_PCI_MSI; -} --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -606,7 +606,6 @@ struct irq_domain *pci_msi_create_irq_do struct irq_domain *parent); u32 pci_msi_domain_get_msi_rid(struct irq_domain *domain, struct pci_dev *pdev); struct irq_domain *pci_msi_get_device_domain(struct pci_dev *pdev); -bool pci_dev_has_special_msi_domain(struct pci_dev *pdev); #else /* CONFIG_PCI_MSI */ static inline struct irq_domain *pci_msi_get_device_domain(struct pci_dev *pdev) { From patchwork Mon Nov 21 14:38:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23824 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1628137wrr; Mon, 21 Nov 2022 06:40:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf6uKyyHnSXtoIFrOCacUefvtXh7Bz1mu1qw5lAP40Um//+kLYmcDsc4lQZh7y6N0kpqC6sA X-Received: by 2002:a17:903:1206:b0:186:a2ef:7a74 with SMTP id l6-20020a170903120600b00186a2ef7a74mr2977164plh.148.1669041642188; Mon, 21 Nov 2022 06:40:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041642; cv=none; d=google.com; s=arc-20160816; b=K3Pbs4fv8luMZN3ObZzBPazEwQeCZ2AS9KCANFCy1uxUYzTrM39FeHEKbTe6cB4Dsi F7ZS1LtQkYXk31iNgxA1Hy4DIYFAO7//deUAMxdTnUBH1qkL5USGT/ABQjbGZO/dZS66 88IbYBO2FpgKZc0lf9vizBaOtihiF2E/hR7muO3x0iPIC7Mb3+BLLRWqp/21CchhGgja igrdmiv4qGbfjzwziRZpdlAosNFhp0p3ZwLeE10iHKQ1pZYepZIpUPs4KN6R+f2WRk6B 5OLEuMgNqUOrv4IO/l6PBqPr68uthYehbE3BvvvGV8o8719lDOsSpO+dCo3vpYJFaOGQ KyDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=OWDR1HVKygNBsw9mLHuKFZNGcf87XagJ2m0BnhitI40=; b=iLZsT2MeJzD3/u7Vyhf43/W7l9eWPBYoPRg2UbSDB/MaQzv++yCHGoNbwJL8YG+lt1 UxcDKQcz+e2gAMN49lvVkZYaJUlKIIUG6P2PIiJzEQvQvuyzbQ3pz1VtTa3Waak60wae hgCnYx8p3gJXTXf3lY/PA9tFdRA28V14v7RAa1D3g6JFFwOTJ+ZXISrgb7b5DymiB24q nLNJjOc/RAj7OKsbahYCsmrFB8N7y9krkQfhudpnDBnDt3GzhxeLZeU/0HmGnFKJPqJW 38vJABtqEaztZQW3SymRKgWzRqYCOgusRVMUp8xmzcJvvu7BDu9BPS2dc8lFkVoJHJro +ndw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MYJ30Z2I; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="jx/7uiun"; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j2-20020a056a00130200b0056bb26401dcsi11190817pfu.207.2022.11.21.06.40.28; Mon, 21 Nov 2022 06:40:42 -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=@linutronix.de header.s=2020 header.b=MYJ30Z2I; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="jx/7uiun"; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231830AbiKUOkA (ORCPT + 99 others); Mon, 21 Nov 2022 09:40:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231654AbiKUOiH (ORCPT ); Mon, 21 Nov 2022 09:38:07 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 754CF79356; Mon, 21 Nov 2022 06:38:06 -0800 (PST) Message-ID: <20221121091327.326195230@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041485; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=OWDR1HVKygNBsw9mLHuKFZNGcf87XagJ2m0BnhitI40=; b=MYJ30Z2I3+/4UN65MSl2Kn8D8g2XvMPskxphwjy0BVd0+xS/viqw9G59t19VywcVstzSqA gDCg3d/hLBXDtH+I+WcB6/JnONfYtlclmpiTbua+Fkxb08oW9VXDeGD9RZOh3ZlcJXdF10 EnAs5ySwFrp69pXOqjGLUzVP27GD+O4Omv1eZGo1BuaBi1TkpIjIL3U897lsyjmGZ8jQTg 8Uzv0KbHOidX3GT8cCGaDP0qdgag7/+n7dTaTFShuoBTVmwnGlOhmmQeKhwEhp5j8bIMXo GnuzUEc/NXCVegygI4cjLnPjpI261od9/2CMVvjtlw7BqmYlNceExhnmpuZfPw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041485; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=OWDR1HVKygNBsw9mLHuKFZNGcf87XagJ2m0BnhitI40=; b=jx/7uiun/9dkAJ6LcERIt0FGUS+gIXzv08q4ciOcwH0wxWPp5K6cMi1JNJGzS4I+A8t3+p 0lSzsanOwTOr68CA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 15/33] iommu/vt-d: Switch to MSI parent domains References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:04 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117009033522279?= X-GMAIL-MSGID: =?utf-8?q?1750117009033522279?= Remove the global PCI/MSI irqdomain implementation and provide the required MSI parent ops so the PCI/MSI code can detect the new parent and setup per device domains. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/apic/msi.c | 2 ++ drivers/iommu/intel/iommu.h | 1 - drivers/iommu/intel/irq_remapping.c | 27 ++++++++++++--------------- include/linux/irqdomain_defs.h | 1 + 4 files changed, 15 insertions(+), 16 deletions(-) --- a/arch/x86/kernel/apic/msi.c +++ b/arch/x86/kernel/apic/msi.c @@ -217,6 +217,8 @@ static bool x86_init_dev_msi_info(struct /* See msi_set_affinity() for the gory details */ info->flags |= MSI_FLAG_NOMASK_QUIRK; break; + case DOMAIN_BUS_DMAR: + break; default: WARN_ON_ONCE(1); return false; --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -600,7 +600,6 @@ struct intel_iommu { #ifdef CONFIG_IRQ_REMAP struct ir_table *ir_table; /* Interrupt remapping info */ struct irq_domain *ir_domain; - struct irq_domain *ir_msi_domain; #endif struct iommu_device iommu; /* IOMMU core code handle */ int node; --- a/drivers/iommu/intel/irq_remapping.c +++ b/drivers/iommu/intel/irq_remapping.c @@ -82,6 +82,7 @@ static const struct irq_domain_ops intel static void iommu_disable_irq_remapping(struct intel_iommu *iommu); static int __init parse_ioapics_under_ir(void); +static const struct msi_parent_ops dmar_msi_parent_ops; static bool ir_pre_enabled(struct intel_iommu *iommu) { @@ -230,7 +231,7 @@ static struct irq_domain *map_dev_to_ir( { struct dmar_drhd_unit *drhd = dmar_find_matched_drhd_unit(dev); - return drhd ? drhd->iommu->ir_msi_domain : NULL; + return drhd ? drhd->iommu->ir_domain : NULL; } static int clear_entries(struct irq_2_iommu *irq_iommu) @@ -573,10 +574,10 @@ static int intel_setup_irq_remapping(str pr_err("IR%d: failed to allocate irqdomain\n", iommu->seq_id); goto out_free_fwnode; } - iommu->ir_msi_domain = - arch_create_remap_msi_irq_domain(iommu->ir_domain, - "INTEL-IR-MSI", - iommu->seq_id); + + irq_domain_update_bus_token(iommu->ir_domain, DOMAIN_BUS_DMAR); + iommu->ir_domain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT; + iommu->ir_domain->msi_parent_ops = &dmar_msi_parent_ops; ir_table->base = page_address(pages); ir_table->bitmap = bitmap; @@ -620,9 +621,6 @@ static int intel_setup_irq_remapping(str return 0; out_free_ir_domain: - if (iommu->ir_msi_domain) - irq_domain_remove(iommu->ir_msi_domain); - iommu->ir_msi_domain = NULL; irq_domain_remove(iommu->ir_domain); iommu->ir_domain = NULL; out_free_fwnode: @@ -644,13 +642,6 @@ static void intel_teardown_irq_remapping struct fwnode_handle *fn; if (iommu && iommu->ir_table) { - if (iommu->ir_msi_domain) { - fn = iommu->ir_msi_domain->fwnode; - - irq_domain_remove(iommu->ir_msi_domain); - irq_domain_free_fwnode(fn); - iommu->ir_msi_domain = NULL; - } if (iommu->ir_domain) { fn = iommu->ir_domain->fwnode; @@ -1437,6 +1428,12 @@ static const struct irq_domain_ops intel .deactivate = intel_irq_remapping_deactivate, }; +static const struct msi_parent_ops dmar_msi_parent_ops = { + .supported_flags = X86_VECTOR_MSI_FLAGS_SUPPORTED | MSI_FLAG_MULTI_PCI_MSI, + .prefix = "IR-", + .init_dev_msi_info = msi_parent_init_dev_msi_info, +}; + /* * Support of Interrupt Remapping Unit Hotplug */ --- a/include/linux/irqdomain_defs.h +++ b/include/linux/irqdomain_defs.h @@ -23,6 +23,7 @@ enum irq_domain_bus_token { DOMAIN_BUS_VMD_MSI, DOMAIN_BUS_PCI_DEVICE_MSI, DOMAIN_BUS_PCI_DEVICE_MSIX, + DOMAIN_BUS_DMAR, }; #endif /* _LINUX_IRQDOMAIN_DEFS_H */ From patchwork Mon Nov 21 14:38:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23826 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1628292wrr; Mon, 21 Nov 2022 06:41:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf7h2TrhpeMuWOJkof+CJM5czbJjDK6t9y9EXlTIAJ1l6fumfkZQBzVROqdsqmy/D3rgtFwu X-Received: by 2002:aa7:9ad6:0:b0:536:e549:8480 with SMTP id x22-20020aa79ad6000000b00536e5498480mr21104677pfp.6.1669041660810; Mon, 21 Nov 2022 06:41:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041660; cv=none; d=google.com; s=arc-20160816; b=m+WVSCLh1lHBSxLyTuvO5k60PnvELgnznv4GaAX7h2mdGJM0OAaOUGqOpmY/q6ILyK 3e0gPwm2BtKO9Uuc0K9jBqw2ijl3SX3Q84WR6N5iUbfc5hyG+WaVnEUIraGr6OtMjwKI oEpmlZnIlntgeO8fu2KHmDtjepXdz9NXtSeH19mS+KPDgrZ4+Y8E05Vs5VmU6G8D57N0 rWVrZzcii/zqqkfeipZmKCwR7LvhWFF6kKmw24HWgHOYigkFghohxH55H9ZoFw+vvmHv mYUlAR69aR2EkDYlVu8Zgyf7UZ3XnsYzxThFzKcI0tdfMwV+gLV0mjaWjJN/qTcqEDeU BAJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=5F8g3aU97Z6Kyag3K9E0SkLjFZeBlcTh6td6sXBxDio=; b=IHN/jYTf5iz7yDABk4n6PfXakqJllsY+cNeIuE8lX1xNEw1KyP4gRXAq5l0wFrwI69 k0ZXXylEe7zlio+PFhUYwDKr2flBbjLU+Qg42HHCg2okZFNmgAbgRBRuCBKool1wGyv5 QpGcWv+DL8smgtiSCb7UxIie3abK2n3re/l2UWyYKsp/BmNxZ3v5p0BLXLNeK39fymKN bu/3vx3/YyF30YVpbOnqHQJkGk70cuin967xDUeTnTxGPsDRvfujo4xvwU/gGkWiLvfn +1VXMrCQ6YI+TuULOu4f4EFG2B9V9PqoWjlNJej9p2VmPGAWNRP4LAqafL2w1af5cFq1 tFzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=14ISXTXW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kk11-20020a17090b4a0b00b0021382853a8asi17454556pjb.81.2022.11.21.06.40.29; Mon, 21 Nov 2022 06:41:00 -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=@linutronix.de header.s=2020 header.b=14ISXTXW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231835AbiKUOkE (ORCPT + 99 others); Mon, 21 Nov 2022 09:40:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231664AbiKUOiI (ORCPT ); Mon, 21 Nov 2022 09:38:08 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FCB7922CA; Mon, 21 Nov 2022 06:38:07 -0800 (PST) Message-ID: <20221121091327.380047723@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=5F8g3aU97Z6Kyag3K9E0SkLjFZeBlcTh6td6sXBxDio=; b=14ISXTXWtPaZo7l3cDp+TchW4UXM37ZxlFo4TsEqh+DhlN4UAeWItQidICeIq4uA/WsozG VGJLEH5AhKZ3gn5WvwwLBNHDgYJ7Lkg2ZEgihzzELDGPxuKR3ym8/v7IhllfCeRiEFQzp2 ohCK6GU1nNO1Jav6krYbhjmPPFst6eS0AfUetQacYLQ1K1dHC8qgWa9bRNAHjGk/f875fy Txba/FIGAdDq4D7+mQpKhEJ0DAtyeTNQ3bIpiosSHX29X+B3/NYAOTasNTkmYCkhXecrbs 9uMCwz+Gasp7NqxIpN8PwyITXQcOon4JG5HNF/rzMmg97RLt7zI9FWERqxSfdA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=5F8g3aU97Z6Kyag3K9E0SkLjFZeBlcTh6td6sXBxDio=; b=XM/yho+7anV7Ex+cxUNC9nH6VnOT3ao9pzIV/KhLTVZOs4sl5F/NRA1Z6xraHb3yCWlnKR R4ruqX4rd/r0dzDA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 16/33] iommu/amd: Switch to MSI base domains References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:06 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117028576812515?= X-GMAIL-MSGID: =?utf-8?q?1750117028576812515?= Remove the global PCI/MSI irqdomain implementation and provide the required MSI parent ops so the PCI/MSI code can detect the new parent and setup per device domains. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/apic/msi.c | 1 + drivers/iommu/amd/amd_iommu_types.h | 1 - drivers/iommu/amd/iommu.c | 19 +++++++++++++------ include/linux/irqdomain_defs.h | 1 + 4 files changed, 15 insertions(+), 7 deletions(-) --- a/arch/x86/kernel/apic/msi.c +++ b/arch/x86/kernel/apic/msi.c @@ -218,6 +218,7 @@ static bool x86_init_dev_msi_info(struct info->flags |= MSI_FLAG_NOMASK_QUIRK; break; case DOMAIN_BUS_DMAR: + case DOMAIN_BUS_AMDVI: break; default: WARN_ON_ONCE(1); --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -734,7 +734,6 @@ struct amd_iommu { u8 max_counters; #ifdef CONFIG_IRQ_REMAP struct irq_domain *ir_domain; - struct irq_domain *msi_domain; struct amd_irte_ops *irte_ops; #endif --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -815,7 +815,7 @@ amd_iommu_set_pci_msi_domain(struct devi !pci_dev_has_default_msi_parent_domain(to_pci_dev(dev))) return; - dev_set_msi_domain(dev, iommu->msi_domain); + dev_set_msi_domain(dev, iommu->ir_domain); } #else /* CONFIG_IRQ_REMAP */ @@ -3648,6 +3648,12 @@ static struct irq_chip amd_ir_chip = { .irq_compose_msi_msg = ir_compose_msi_msg, }; +static const struct msi_parent_ops amdvi_msi_parent_ops = { + .supported_flags = X86_VECTOR_MSI_FLAGS_SUPPORTED | MSI_FLAG_MULTI_PCI_MSI, + .prefix = "IR-", + .init_dev_msi_info = msi_parent_init_dev_msi_info, +}; + int amd_iommu_create_irq_domain(struct amd_iommu *iommu) { struct fwnode_handle *fn; @@ -3655,16 +3661,17 @@ int amd_iommu_create_irq_domain(struct a fn = irq_domain_alloc_named_id_fwnode("AMD-IR", iommu->index); if (!fn) return -ENOMEM; - iommu->ir_domain = irq_domain_create_tree(fn, &amd_ir_domain_ops, iommu); + iommu->ir_domain = irq_domain_create_hierarchy(arch_get_ir_parent_domain(), 0, 0, + fn, &amd_ir_domain_ops, iommu); if (!iommu->ir_domain) { irq_domain_free_fwnode(fn); return -ENOMEM; } - iommu->ir_domain->parent = arch_get_ir_parent_domain(); - iommu->msi_domain = arch_create_remap_msi_irq_domain(iommu->ir_domain, - "AMD-IR-MSI", - iommu->index); + irq_domain_update_bus_token(iommu->ir_domain, DOMAIN_BUS_AMDVI); + iommu->ir_domain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT; + iommu->ir_domain->msi_parent_ops = &amdvi_msi_parent_ops; + return 0; } --- a/include/linux/irqdomain_defs.h +++ b/include/linux/irqdomain_defs.h @@ -24,6 +24,7 @@ enum irq_domain_bus_token { DOMAIN_BUS_PCI_DEVICE_MSI, DOMAIN_BUS_PCI_DEVICE_MSIX, DOMAIN_BUS_DMAR, + DOMAIN_BUS_AMDVI, }; #endif /* _LINUX_IRQDOMAIN_DEFS_H */ From patchwork Mon Nov 21 14:38:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23825 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1628214wrr; Mon, 21 Nov 2022 06:40:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf6kx+VZrJeHuqhBcbVH9z9Y/RePFh4crKpL4YRsf/TIRL3CmYxmFr15Nkl9MO2oySii/9Qk X-Received: by 2002:a17:902:aa06:b0:182:f36b:3221 with SMTP id be6-20020a170902aa0600b00182f36b3221mr331918plb.36.1669041649214; Mon, 21 Nov 2022 06:40:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041649; cv=none; d=google.com; s=arc-20160816; b=yheb79HnurPLs/5foBHZV22kXVavluWLvnbHQgUhOvYV1+09suesaYy8e/oyXpO+sR FrpTp7UV1laAI73ScmVvYhJHuKPHg1wOlG1dUM5JoPYqR1PJ7wmxcxjWr2/W4vbYCqp6 WZQj3HR20wOWuc6MKqEqoHP+45SuJvy2Uk2bSua78XVKxcHcY5bzacltDdugzZRfjKI/ HINfUJwkmrf7nU67GPSUHnzh2NyS02vyxKSU13J9q1nu3P7tV3xyc295h92yR0hLvqvU wadT20aUyj8HzGu9Nh8LsugM7feNr9Y2OEJZSCbJV94Ax9Nd9dK8PokMj3D9T7hGZOmG ZKYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=T4PJKhvy3BXQPG8m3pythcilM8fEjCtnrP9dFwguEN8=; b=xJieUFf5zZ6nQ+6Qfrf5IBK/K5fKJmmN3ufCuSrGlFZxvepWEd1k/mk1BR3pOWd8Tn ue9Rh8x/77BC3fzAfwg7E+H89jzDPCvz5aEwzvCAZ131g66b9TLWNHOYbY0EaA1NM60/ Ey6nJbhHuvI4cqIhzlYSDyp3zy4z4YmDCn2rw69eaDXIM8SB979HgWpiUydKJZej5WbF dGDKwci+0H0Eg6HgnudjMpJDDle9+jjW/EU/RIJKMF16RFIG+fl1B9DTfEfP1C8jTYvP Cy2O8wihkW037XvmbtNaJW++pkyq1jWarLLi84Oee1bfGqeYhe9dUIwztZ1wy4LtvzMl oFkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=RtPrEADL; dkim=neutral (no key) header.i=@linutronix.de header.b=aWd8PCCv; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e3-20020a170902ed8300b001868a25da0dsi6383261plj.40.2022.11.21.06.40.34; Mon, 21 Nov 2022 06:40:49 -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=@linutronix.de header.s=2020 header.b=RtPrEADL; dkim=neutral (no key) header.i=@linutronix.de header.b=aWd8PCCv; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231839AbiKUOkK (ORCPT + 99 others); Mon, 21 Nov 2022 09:40:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231567AbiKUOiJ (ORCPT ); Mon, 21 Nov 2022 09:38:09 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E347F942D5; Mon, 21 Nov 2022 06:38:08 -0800 (PST) Message-ID: <20221121091327.434824195@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041487; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=T4PJKhvy3BXQPG8m3pythcilM8fEjCtnrP9dFwguEN8=; b=RtPrEADLQ4F09PZEf7MRYrk1DKs2OkxJk+s5MlC4pyGrdJej891wfDCd/fORtsNyjHvFQP RF+zvuDHRAxMziDZ34F3pVHKeRVjp3Cvs4LFBD8gG8xekg1V7XgG7EfuZe47+uCgM7lX+7 3o+9jAaM9ZMm+cSIkIyxQn3tuIl813XQY0dgkrh9CUS3HLkPWyvQS7U2NJdjE7BzVdyt3B SZyjsRFiPdcZVT6b/EjzhbI1/vUGwdTQVWNef/ehw/+VJXu7VmXhE5ziy8WO/ttIGMmqiV YpX0XjOvpRmltFPubbY0V2LzT8Kan8XqOnFCui/kVnm5wSPfpdjPt3u+HnDSnw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041487; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=T4PJKhvy3BXQPG8m3pythcilM8fEjCtnrP9dFwguEN8=; b=aWd8PCCvc63ClVG88p5VQoROv7Oe2rDRMPbz7IjkMKsR8wjbom7ao8Gw5pclxgYa9dt8x1 Z4aYP3crdT1MP3BA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 17/33] x86/apic/msi: Remove arch_create_remap_msi_irq_domain() References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:07 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117016790880026?= X-GMAIL-MSGID: =?utf-8?q?1750117016790880026?= and related code which is not longer required now that the interrupt remap code has been converted to MSI parent domains. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/irq_remapping.h | 4 --- arch/x86/kernel/apic/msi.c | 42 ----------------------------------- 2 files changed, 1 insertion(+), 45 deletions(-) --- a/arch/x86/include/asm/irq_remapping.h +++ b/arch/x86/include/asm/irq_remapping.h @@ -44,10 +44,6 @@ extern int irq_remapping_reenable(int); extern int irq_remap_enable_fault_handling(void); extern void panic_if_irq_remap(const char *msg); -/* Create PCI MSI/MSIx irqdomain, use @parent as the parent irqdomain. */ -extern struct irq_domain * -arch_create_remap_msi_irq_domain(struct irq_domain *par, const char *n, int id); - /* Get parent irqdomain for interrupt remapping irqdomain */ static inline struct irq_domain *arch_get_ir_parent_domain(void) { --- a/arch/x86/kernel/apic/msi.c +++ b/arch/x86/kernel/apic/msi.c @@ -277,7 +277,7 @@ void __init x86_create_pci_msi_domain(vo x86_pci_msi_default_domain = x86_init.irqs.create_pci_msi_domain(); } -/* Keep around for hyperV and the remap code below */ +/* Keep around for hyperV */ int pci_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec, msi_alloc_info_t *arg) { @@ -291,46 +291,6 @@ int pci_msi_prepare(struct irq_domain *d } EXPORT_SYMBOL_GPL(pci_msi_prepare); -#ifdef CONFIG_IRQ_REMAP -static struct msi_domain_ops pci_msi_domain_ops = { - .msi_prepare = pci_msi_prepare, -}; - -static struct irq_chip pci_msi_ir_controller = { - .name = "IR-PCI-MSI", - .irq_unmask = pci_msi_unmask_irq, - .irq_mask = pci_msi_mask_irq, - .irq_ack = irq_chip_ack_parent, - .irq_retrigger = irq_chip_retrigger_hierarchy, - .flags = IRQCHIP_SKIP_SET_WAKE | - IRQCHIP_AFFINITY_PRE_STARTUP, -}; - -static struct msi_domain_info pci_msi_ir_domain_info = { - .flags = MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS | - MSI_FLAG_MULTI_PCI_MSI | MSI_FLAG_PCI_MSIX, - .ops = &pci_msi_domain_ops, - .chip = &pci_msi_ir_controller, - .handler = handle_edge_irq, - .handler_name = "edge", -}; - -struct irq_domain *arch_create_remap_msi_irq_domain(struct irq_domain *parent, - const char *name, int id) -{ - struct fwnode_handle *fn; - struct irq_domain *d; - - fn = irq_domain_alloc_named_id_fwnode(name, id); - if (!fn) - return NULL; - d = pci_msi_create_irq_domain(fn, &pci_msi_ir_domain_info, parent); - if (!d) - irq_domain_free_fwnode(fn); - return d; -} -#endif - #ifdef CONFIG_DMAR_TABLE /* * The Intel IOMMU (ab)uses the high bits of the MSI address to contain the From patchwork Mon Nov 21 14:38:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23829 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1628410wrr; Mon, 21 Nov 2022 06:41:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf4CHK93H1lQ16QUydUFooIS2u8ZITpueqHusQvPzLZEjyeNcXCtxuSV8STPsd3KcTcCQaXC X-Received: by 2002:a17:906:60c4:b0:7a2:36c7:31ea with SMTP id f4-20020a17090660c400b007a236c731eamr1109364ejk.210.1669041672091; Mon, 21 Nov 2022 06:41:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041672; cv=none; d=google.com; s=arc-20160816; b=qrihZUDY4Va5InfYCy3B+o5clz5GaIG5ZcPInLQrClnUpX3NQ3tkY3QIEi+Q1oX3Rh I0xs8KhypLBSGG5QkqfA3gPZnN8P75MMhjeBByYHwqfl33gtOxKcih22SvLH02UG3Bl5 FrEjLPoDnmzjpfZPBlVXS0SowlvxWWjl7Gsol08ozRT7C4+tndJxgHG/KXA7fuZdojcZ yNQIymQEGIGaYDJyJAB/7RDUIoZNK5VcRjbZg5Y612W3a7RVmWMmvnxHKVyMJMEggjiJ /LEqxtE68a3T2T6xfBDM2o4dNHwn932E+VUj8pdxu0KJpKINemYUmKiBlrdUfW0XMttH R2+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=cFx6dbaS3ynUGuWTq2v8hXwBFa/HBDy+17s0E2mkPoM=; b=h4lLCqCWWK79lcU8PLME9lslwEQ64d53YQfg+P04m2FiEsM58buwkf3ByoS8CMsK2e 59dxHchDxgXxL20A0BcEbTzPhW8/Eg0aanF6p3TI+YH8lTPYTV988uCGAytHGGoyFc9G /bicVdwoyN28XYXY6fQlWWdvxvX2ZjsMNliLqqho9+ny37QvRaoUjuFAFcL5BZkPxAbB 7ux52xTTzIddycEx4HNBwSvox1bMHWvvHS2y5S4TmUuo0J9nZL5v2484hPh2U0rcxdtB IjC4ZOy3yxspuedjPYnDR91GEv1UCyFZeijjRJvVO/A4IIATXDoCvAYqDid+ItcgJXJL rp8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=4ntO2jsO; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gz20-20020a170906f2d400b007ae3958c7c9si9127998ejb.999.2022.11.21.06.40.37; Mon, 21 Nov 2022 06:41:12 -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=@linutronix.de header.s=2020 header.b=4ntO2jsO; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231848AbiKUOkO (ORCPT + 99 others); Mon, 21 Nov 2022 09:40:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231676AbiKUOiL (ORCPT ); Mon, 21 Nov 2022 09:38:11 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 793ED93723; Mon, 21 Nov 2022 06:38:10 -0800 (PST) Message-ID: <20221121091327.489131583@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041488; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=cFx6dbaS3ynUGuWTq2v8hXwBFa/HBDy+17s0E2mkPoM=; b=4ntO2jsOMBcMQVVu6K5tb8rs4a5ulGHGJrLiz8k2RdhV7w+ti8dr3UbSXzi+37XYCYbUwW TGQKFsaBnrUugaTl6OcHMkorcxIHSo66Tap2KxaECUG8QnwYwpyNrW/V+Y9LR41kR51ymT 7gyEXjteFWTm4grkGwqIn/SKn6P3DQC7LIxfKwZTMCmDFTIFyokKIXNLq78hN4coNm3gUP uNzdo7dXYYscCXCvvLPyX0GRt6Ycq1OefhWSlpan9b+ahh6HqxMeuVQo5wIEx9QTnJq+HF AYZhqjlUNOmVDohcSwjeaf5BVFw9KtG6gbcuWTJSquCGvVCa/Z7cZPHkqO73aA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041488; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=cFx6dbaS3ynUGuWTq2v8hXwBFa/HBDy+17s0E2mkPoM=; b=Zm9TCIE+T02R/nWzRR2Cqvo/6OUXrCvX38/MlPUZkdidEN5wxKJbfcb6lnoTR6irL4yDFe E2iEh7a/YBECFuBQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 18/33] genirq/msi: Provide struct msi_map References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:08 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117040333706337?= X-GMAIL-MSGID: =?utf-8?q?1750117040333706337?= A simple struct to hold a MSI index / Linux interrupt number pair. It will be returned from the dynamic vector allocation function and handed back to the corresponding free() function. Signed-off-by: Thomas Gleixner --- include/linux/msi_api.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/include/linux/msi_api.h +++ b/include/linux/msi_api.h @@ -18,6 +18,19 @@ enum msi_domain_ids { MSI_MAX_DEVICE_IRQDOMAINS, }; +/** + * msi_map - Mapping between MSI index and Linux interrupt number + * @index: The MSI index, e.g. slot in the MSI-X table or + * a software managed index if >= 0. If negative + * the allocation function failed and it contains + * the error code. + * @virq: The associated Linux interrupt number + */ +struct msi_map { + int index; + int virq; +}; + unsigned int msi_domain_get_virq(struct device *dev, unsigned int domid, unsigned int index); /** From patchwork Mon Nov 21 14:38:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23827 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1628291wrr; Mon, 21 Nov 2022 06:41:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf4QDypALV7AHIq+EcIqeJpBFlh3VPSbwqW/Z37up/mdzozO9JJzuEzoViha36qRNQF4ISf6 X-Received: by 2002:a63:470e:0:b0:440:69bc:c972 with SMTP id u14-20020a63470e000000b0044069bcc972mr380322pga.86.1669041660646; Mon, 21 Nov 2022 06:41:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041660; cv=none; d=google.com; s=arc-20160816; b=DKfaASt3UEajxr6pnBqMeDRL8dIou/kjcuqa/O6pKQ6eT8FGgAcCAF+pxJ/0LdTVrI sIwm7yjRCQju3vG5VbHTj1TOq0Ic8YtJ9C4x+ASoBz5roYYP2frCT/5vxn/FKFrtOgik K+eqHQJEksqlVn+UUkXRYkMGu4jmh0G1fFU3cPJ2uCgi0wmOtxsjztpzKQK2f+oWbfKa Sk9sI1Jup4wCP4K5ksF1XIUtCbKOZz0DRrR/Ugv90ZXadJE/B0ijpZe4pMhFM7gOrO1B qHXQp5RG8N4TErG5LSrB3XGlrFj8MrBpUqd+W/PgoGMniPZbk9jfulfKNCMrHjowlSgk vA/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=TpR1wEbG/Wo0WW0drKjzPBv3GD8sCJ8ij4dxCieYEi4=; b=yXngjml8KT1sBFLayBLVzbTtGSdfb0yt+5cL4Vt081rO1FBiJ+BPhGKAnTcUCJGa3R lwh5lJmU0MdSYhbfxxiMohwpMCMw9dA1eZdkOILvS7Jzj9+Flzv5hreQqrcTuloLX5Hy P9puSL5+1yovuUhcEZYpUqN8lIfI7h9g0lQmi3nV7iNU9j5QP7w+H8IUg+5NrXtLtPKI x0DM9gNVwq6E5XKj0ZnfAusQui83thVKC+lgsWP6SsICsy58+OR60uUBl6z+zDhPnlWk dDQb4a+7r8krM6j3zisMd4+hNjlsPZWaeFFkDIjMY5Nvxibd4GZoYPEIoyXpHoPL8bw3 uWjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=boEzxceG; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j13-20020a056a00174d00b0056dc342ea54si12032537pfc.206.2022.11.21.06.40.45; Mon, 21 Nov 2022 06:41:00 -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=@linutronix.de header.s=2020 header.b=boEzxceG; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231734AbiKUOkT (ORCPT + 99 others); Mon, 21 Nov 2022 09:40:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231689AbiKUOiM (ORCPT ); Mon, 21 Nov 2022 09:38:12 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F86293737; Mon, 21 Nov 2022 06:38:11 -0800 (PST) Message-ID: <20221121091327.546352933@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041490; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=TpR1wEbG/Wo0WW0drKjzPBv3GD8sCJ8ij4dxCieYEi4=; b=boEzxceGwga/4l4WI3M49ixM1qKuf902SAk5l7XjmXIUhMmHwHtoGn6S+cNno7lthH6f49 FY0+6f0rhfZShW12K2hC6TDzMY8lOJt3KHWL7Cu0Te2OutLLD1a8iSCYWabqzTcnI8VkhI 8VOGweAyq0indNR8ij7aveLxew6fiQkD4FgGWgY9K4if7FAgjI5g9tbBkptfOtznFHyS0u YnB9GPyenUjubrLD4hKPRfPM7RXkZbztGSo2X3xTZOgCU4W20NwnnKyL24WOeQ7fyLkRej D3Se01bEPRyunajWqPxzq++nZqP0watcRmuzsg853sY0mv+0GfFrkVflGH6D9w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041490; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=TpR1wEbG/Wo0WW0drKjzPBv3GD8sCJ8ij4dxCieYEi4=; b=8SxTnGwUpnz/eHpEzw+XHQcUvf4J25tXxaf20pnh5OyYxflN/m2nfUssZYiI3+XzN9sLR3 lpOhY2E5q68YH8Cw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 19/33] genirq/msi: Provide msi_desc::msi_data References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:09 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117028193118079?= X-GMAIL-MSGID: =?utf-8?q?1750117028193118079?= The upcoming support for PCI/IMS requires to store some information related to the message handling in the MSI descriptor, e.g. PASID or a pointer to a queue. Provide a generic storage struct which maps over the existing PCI specific storage which means the size of struct msi_desc is not getting bigger. It contains a iomem pointer for device memory based IMS and a union of a u64 and a void pointer which allows the device specific IMS implementations to store the necessary information. The iomem pointer is set up by the domain allocation functions. The data union msi_dev_cookie is going to be handed in when allocating an interrupt on an IMS domain so the irq chip callbacks of the IMS domain have the necessary per vector information available. It also comes in handy when cleaning up the platform MSI code for wire to MSI bridges which need to hand down the type information to the underlying interrupt domain. For the core code the cookie is opaque and meaningless. It just stores it during an allocation through the upcoming interfaces for IMS and wire to MSI brigdes. Signed-off-by: Thomas Gleixner --- include/linux/msi.h | 38 +++++++++++++++++++++++++++++++++++++- include/linux/msi_api.h | 17 +++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -125,6 +125,38 @@ struct pci_msi_desc { }; }; +/** + * union msi_domain_cookie - Opaque MSI domain specific data + * @value: u64 value store + * @ptr: Pointer to domain specific data + * @iobase: Domain specific IOmem pointer + * + * The content of this data is implementation defined and used by the MSI + * domain to store domain specific information which is requried for + * interrupt chip callbacks. + */ +union msi_domain_cookie { + u64 value; + void *ptr; + void __iomem *iobase; +}; + +/** + * struct msi_desc_data - Generic MSI descriptor data + * @dcookie: Cookie for MSI domain specific data which is required + * for irq_chip callbacks + * @icookie: Cookie for the MSI interrupt instance provided by + * the usage site to the allocation function + * + * The content of this data is implementation defined, e.g. PCI/IMS + * implementations define the meaning of the data. The MSI core ignores + * this data completely. + */ +struct msi_desc_data { + union msi_domain_cookie dcookie; + union msi_instance_cookie icookie; +}; + #define MSI_MAX_INDEX ((unsigned int)USHRT_MAX) /** @@ -142,6 +174,7 @@ struct pci_msi_desc { * * @msi_index: Index of the msi descriptor * @pci: PCI specific msi descriptor data + * @data: Generic MSI descriptor data */ struct msi_desc { /* Shared device/bus type independent data */ @@ -161,7 +194,10 @@ struct msi_desc { void *write_msi_msg_data; u16 msi_index; - struct pci_msi_desc pci; + union { + struct pci_msi_desc pci; + struct msi_desc_data data; + }; }; /* --- a/include/linux/msi_api.h +++ b/include/linux/msi_api.h @@ -19,6 +19,23 @@ enum msi_domain_ids { }; /** + * union msi_instance_cookie - MSI instance cookie + * @value: u64 value store + * @ptr: Pointer to usage site specific data + * + * This cookie is handed to the IMS allocation function and stored in the + * MSI descriptor for the interrupt chip callbacks. + * + * The content of this cookie is MSI domain implementation defined. For + * PCI/IMS implementations this could be a PASID or a pointer to queue + * memory. + */ +union msi_instance_cookie { + u64 value; + void *ptr; +}; + +/** * msi_map - Mapping between MSI index and Linux interrupt number * @index: The MSI index, e.g. slot in the MSI-X table or * a software managed index if >= 0. If negative From patchwork Mon Nov 21 14:38:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23828 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1628333wrr; Mon, 21 Nov 2022 06:41:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf4pbojHtScYT8MnA3bsXzmi0Bcbqmk8XsyR3/zAu+4xdE9og9SNG7toqGSXssT6i0zYbRzY X-Received: by 2002:a17:903:41c8:b0:186:5eab:8631 with SMTP id u8-20020a17090341c800b001865eab8631mr336125ple.134.1669041664946; Mon, 21 Nov 2022 06:41:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041664; cv=none; d=google.com; s=arc-20160816; b=ymOhN07iWj9hibDUIWtPXVreIak5Kni+Cq6aTnyFn0NMUcC0Iyf6r6P0+6JRBOBvyP 0K3A6r6ORO4tYR17zw8OC3iDY6CN01VQ11Lq0pQolhRmdD2xYE6VLvKhz/K2+6oU7T5x Zp+pMeq0v/q/hM5QrmNF52pMuVLtkQkPsjn3FGLqKp4hsPDPZIGjYVRdQw29K8F0AkUG SvHfEJ7e8e3/R5ixSrPaV7uwXqdUbEHRSD1EsTDoLFmVH0LPJepRc7h8cI8HaBggRHYJ azQtA9utaa/xMAt2AYcf1lgVOf61yuT4VNU2Ry3YAhRoSZPErgxYVmaEF1JoLOu3unoE yEag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=1Ia7eZriEUpBkiV/NLqg7niZ6fMKSxoDJkKbYDvtHyI=; b=gG5EYHGLqKplEo1XyR1188wamvp0egaRcHDXb0Nn51src7ykqTkVaNSnKaAcvn5bA0 daTIGKi/dca6ax1YD96JZGEO5772w00FOxeP/bZ2RHkR5rFxC9NHGOaDoopMcNWKbHzI s6asnTtgsAOFHqrvjl985kB1SgKw8zn6OSdk6nbeN9JKGpnb+KnajuG0gJGWr37HkXa+ pNsRS2LlxtrPFu48/V66j2HS6N1SQsHF0iONdkliWZDNtC2RFT6G69eeVHcCCFkbpUcU NE9kXx0l+p+1J6jcEDYkN/YJUuFJhsIrzfatJmwoFMygHYs9pZ5fX2FaStOI0/EFN6TK C4rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=4ALiouWm; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dc8-20020a056a0035c800b005732e831bbbsi8620438pfb.336.2022.11.21.06.40.49; Mon, 21 Nov 2022 06:41:04 -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=@linutronix.de header.s=2020 header.b=4ALiouWm; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231548AbiKUOkW (ORCPT + 99 others); Mon, 21 Nov 2022 09:40:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231693AbiKUOiN (ORCPT ); Mon, 21 Nov 2022 09:38:13 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A209FC7687; Mon, 21 Nov 2022 06:38:12 -0800 (PST) Message-ID: <20221121091327.604532862@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041491; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=1Ia7eZriEUpBkiV/NLqg7niZ6fMKSxoDJkKbYDvtHyI=; b=4ALiouWmVkPRnT0vTcSPsOaIdfz4pn6W50xbL45ycypOo/a78qwl3e4jYa9vI28IfBmqlD FDnvxoiuLyiB9PmRDyjIKiLV8pvbWdhvgwD0p/bSalOqrXyEs2OoXTWzXgAr4fdrshc4Gu g7e49ttJnijI06uYdFUELqJb6GFnAitKSHuT8tYoe3tt1nAdhJ/uRUqgQytgH2qkSBf5W1 R+r+4+uvLWXIkylOfnDsRadgug9ShopI1nm54EloqDXQW/crZdZNZ7BpOPFQy9LDpYXiRV xreGFARzGdap8ROM1ZHuk1FQIm1MjhX/0/GOuCRkDhn/mCSEgPYOd6wRK9V9lQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041491; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=1Ia7eZriEUpBkiV/NLqg7niZ6fMKSxoDJkKbYDvtHyI=; b=AxaLkvG0WXuwHg5a829R4zwLLIr7zTby4dzJQ5g4oyZ1A/gtehkDNr3C+ECAXdMfwXzlIT YSlZB34oKn7fdsCA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 20/33] genirq/msi: Provide msi_domain_ops::prepare_desc() References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:11 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117032672576802?= X-GMAIL-MSGID: =?utf-8?q?1750117032672576802?= The existing MSI domain ops msi_prepare() and set_desc() turned out to be unsuitable for implementing IMS support. msi_prepare() does not operate on the MSI descriptors. set_desc() lacks an irq_domain pointer and has a completely different purpose. Introduce a prepare_desc() op which allows IMS implementations to amend an MSI descriptor which was allocated by the core code, e.g. by adjusting the iomem base or adding some data based on the allocated index. This is way better than requiring that all IMS domain implementations preallocate the MSI descriptor and then allocate the interrupt. Signed-off-by: Thomas Gleixner --- include/linux/msi.h | 6 +++++- kernel/irq/msi.c | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -402,6 +402,8 @@ struct msi_domain_info; * @msi_init: Domain specific init function for MSI interrupts * @msi_free: Domain specific function to free a MSI interrupts * @msi_prepare: Prepare the allocation of the interrupts in the domain + * @prepare_desc: Optional function to prepare the allocated MSI descriptor + * in the domain * @set_desc: Set the msi descriptor for an interrupt * @domain_alloc_irqs: Optional function to override the default allocation * function. @@ -413,7 +415,7 @@ struct msi_domain_info; * @get_hwirq, @msi_init and @msi_free are callbacks used by the underlying * irqdomain. * - * @msi_check, @msi_prepare and @set_desc are callbacks used by the + * @msi_check, @msi_prepare, @prepare_desc and @set_desc are callbacks used by the * msi_domain_alloc/free_irqs*() variants. * * @domain_alloc_irqs, @domain_free_irqs can be used to override the @@ -436,6 +438,8 @@ struct msi_domain_ops { int (*msi_prepare)(struct irq_domain *domain, struct device *dev, int nvec, msi_alloc_info_t *arg); + void (*prepare_desc)(struct irq_domain *domain, msi_alloc_info_t *arg, + struct msi_desc *desc); void (*set_desc)(msi_alloc_info_t *arg, struct msi_desc *desc); int (*domain_alloc_irqs)(struct irq_domain *domain, --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -1285,6 +1285,9 @@ static int __msi_domain_alloc_irqs(struc if (WARN_ON_ONCE(allocated >= ctrl->nirqs)) return -EINVAL; + if (ops->prepare_desc) + ops->prepare_desc(domain, &arg, desc); + ops->set_desc(&arg, desc); virq = __irq_domain_alloc_irqs(domain, -1, desc->nvec_used, From patchwork Mon Nov 21 14:38:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23830 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1628433wrr; Mon, 21 Nov 2022 06:41:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf7UpAxVCu6LQN5rPnmHCrC2mO861kFwd5UF+gJ3WaefT13kp3ZOfTt+XJpBIuoxEIMmJNFs X-Received: by 2002:a17:902:d592:b0:186:8930:20e6 with SMTP id k18-20020a170902d59200b00186893020e6mr3570103plh.64.1669041674737; Mon, 21 Nov 2022 06:41:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041674; cv=none; d=google.com; s=arc-20160816; b=WH2tJfXhftpr6NX9O4TyHvT/3x87sN5Yp9YqZ/FnPh56xnT6ePWcA5AiiAx9IYX6OM FixzfmJpjfoWdNx8jixu+m6Rykq3VoJZFLXmpfugtopzbWP0KDxwDVqi7a59bIg8PRki 5YExZBEu4BB8aRGL7DLl1ebFS55LmDi+X7tJq8yJJkKjoowlpgHFGIOvwOcOOWw6bQ5Z BBi/eu1+arXmRYC9yu/pclTZn0KuRVgUR4wLOasYgDtL1oitPV4droZ++Bte8xcWZKZV il1tZj7j+2mw9eue1NcMhGnOeSSJqCCSLXlIHFUEc4utV82CWUlDS3Df/pzDiMW6n2JB 0slQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=rFAZUOe7/xJ1t1dV08jaEyOugs45JE8N4r9GO+/5wfE=; b=JAhKWJIWXATKBbDOUCMoJuQN/a3uHE8ULrAq5u0zcgVYW0PW/SMJ6gUZ2VwTFviS7P 7DoeU/FzyGgbgyX8AyQ9HB2i5JRLiGRm6NykyC2hqGhtg9qmAk2hNLPKN8aYH6QhHTJk IXjoHfOmgVIijDeUf5BQaSD1tvNBZNOHfBgC2HthX1ASXPLiacE6deccf3/USK33yLwu YnlJVoC8zNeCtUh8Wl54IEXD4Z1JsR1NomFxX8xLFWH/kSoqT+lnJDvbN1YwEnUb75T+ eKU8FCdljkGx8q5FGxu/pn/qHw7GpctKE6ROoibWDTPvbxYIdhy1rj1T4FdboIgjs5OR NYPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ezvKf5fv; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x189-20020a6386c6000000b0046ff5785764si10840688pgd.38.2022.11.21.06.41.00; Mon, 21 Nov 2022 06:41:14 -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=@linutronix.de header.s=2020 header.b=ezvKf5fv; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231872AbiKUOkd (ORCPT + 99 others); Mon, 21 Nov 2022 09:40:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231584AbiKUOif (ORCPT ); Mon, 21 Nov 2022 09:38:35 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7A09C80D6; Mon, 21 Nov 2022 06:38:13 -0800 (PST) Message-ID: <20221121091327.660407141@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041492; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=rFAZUOe7/xJ1t1dV08jaEyOugs45JE8N4r9GO+/5wfE=; b=ezvKf5fvUsX4oJGcOgrhbx2M8TXP9jAhXcbTiYEYIUdqFahxvVZUWsuY4pV3OOi8M6XJAG mtEdy5mKgjy0gDRQTGL6xSq8x0Yg9pLaUQnXHZ0ssnYSa7gg4O3DwzZl8zVz/yI/M0v2QA h2eYGtai/tCJZ7eScTimwdi2MXphHi+Rryp+qIi9WisVFL12FL/rXUuDpxP6kPGPYCZ+7h ox9TjvzNmk/S33U9G2ysjzxLeh6ukkMZAOPDS9OZuoKN7Z2Ej6NZSH5Dg4QsjOnZ5Apnxc 7dpX9ZgsECsx2uy9/6htMUmEYpg/66K2ST2qquMZT1BL/jxFmgCfWcISRZoKPQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041492; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=rFAZUOe7/xJ1t1dV08jaEyOugs45JE8N4r9GO+/5wfE=; b=m1O4btEed4JHjpjaD4aBEz5/1H2XgJ3A/5QixpPORdr9GXi5MIiBHRTyy+X1361uqEon0G R49NMyPn6V3kVbAQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 21/33] genirq/msi: Provide msi_domain_alloc_irq_at() References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:12 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117042713288700?= X-GMAIL-MSGID: =?utf-8?q?1750117042713288700?= For supporting post MSI-X enable allocations and for the upcoming PCI/IMS support a seperate interface is required which allows not only the allocation of a specific index, but also the allocation of any, i.e. the next free index. The latter is especially required for IMS because IMS completely does away with index to functionality mappings which are often found in MSI/MSI-X implementation. But even with MSI-X there are devices where only the first few indices have a fixed functionality and the rest is freely assignable by software, e.g. to queues. msi_domain_alloc_irq_at() is also different from the range based interfaces as it always enforces that the MSI descriptor is allocated by the core code and not preallocated by the caller like the PCI/MSI[-X] enable code path does. msi_domain_alloc_irq_at() can be invoked with the index argument set to MSI_ANY_INDEX which makes the core code pick the next free index. The irq domain can provide a prepare_desc() operation callback in its msi_domain_ops to do domain specific post allocation initialization before the actual Linux interrupt and the associated interrupt descriptor and hierarchy alloccations are conducted. The function also takes an optional @cookie argument which is of type union msi_dev_cookie. This cookie is not used by the core code and is stored in the allocated msi_desc::data::cookie. The meaning of the cookie is completely implementation defined. In case of IMS this might be a PASID or a pointer to a device queue, but for the MSI core it's opaque and not used in any way. The function returns a struct msi_map which on success contains the allocated index number and the Linux interrupt number so the caller can spare the index to Linux interrupt number lookup. On failure map::index contains the error code and map::virq is 0. Signed-off-by: Thomas Gleixner --- V2: Fix the recursive allocation issue and the index calculation (Reinette) --- include/linux/msi.h | 4 + include/linux/msi_api.h | 7 ++ kernel/irq/msi.c | 113 +++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 113 insertions(+), 11 deletions(-) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -80,6 +80,7 @@ struct pci_dev; struct platform_msi_priv_data; struct device_attribute; struct irq_domain; +struct irq_affinity_desc; void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg); #ifdef CONFIG_GENERIC_MSI_IRQ @@ -591,6 +592,9 @@ int msi_domain_alloc_irqs_range(struct d unsigned int first, unsigned int last); int msi_domain_alloc_irqs_all_locked(struct device *dev, unsigned int domid, int nirqs); +struct msi_map msi_domain_alloc_irq_at(struct device *dev, unsigned int domid, unsigned int index, + const struct irq_affinity_desc *affdesc, + union msi_instance_cookie *cookie); void msi_domain_free_irqs_range_locked(struct device *dev, unsigned int domid, unsigned int first, unsigned int last); --- a/include/linux/msi_api.h +++ b/include/linux/msi_api.h @@ -48,6 +48,13 @@ struct msi_map { int virq; }; +/* + * Constant to be used for dynamic allocations when the allocation + * is any free MSI index (entry in the MSI-X table or a software + * managed index. + */ +#define MSI_ANY_INDEX UINT_MAX + unsigned int msi_domain_get_virq(struct device *dev, unsigned int domid, unsigned int index); /** --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -40,6 +40,7 @@ static inline int msi_sysfs_create_group /* Invalid XA index which is outside of any searchable range */ #define MSI_XA_MAX_INDEX (ULONG_MAX - 1) #define MSI_XA_DOMAIN_SIZE (MSI_MAX_INDEX + 1) +#define MSI_ANY_INDEX UINT_MAX static inline void msi_setup_default_irqdomain(struct device *dev, struct msi_device_data *md) { @@ -127,18 +128,34 @@ static int msi_insert_desc(struct device } hwsize = msi_domain_get_hwsize(dev, domid); - if (index >= hwsize) { - ret = -ERANGE; - goto fail; - } - desc->msi_index = index; - index += baseidx; - ret = xa_insert(&md->__store, index, desc, GFP_KERNEL); - if (ret) - goto fail; - return 0; + if (index == MSI_ANY_INDEX) { + struct xa_limit limit; + unsigned int index; + + limit.min = baseidx; + limit.max = baseidx + hwsize - 1; + + /* Let the xarray allocate a free index within the limits */ + ret = xa_alloc(&md->__store, &index, desc, limit, GFP_KERNEL); + if (ret) + goto fail; + desc->msi_index = index - baseidx; + return 0; + } else { + if (index >= hwsize) { + ret = -ERANGE; + goto fail; + } + + desc->msi_index = index; + index += baseidx; + ret = xa_insert(&md->__store, index, desc, GFP_KERNEL); + if (ret) + goto fail; + return 0; + } fail: msi_free_desc(desc); return ret; @@ -333,7 +350,7 @@ int msi_setup_device_data(struct device msi_setup_default_irqdomain(dev, md); - xa_init(&md->__store); + xa_init_flags(&md->__store, XA_FLAGS_ALLOC); mutex_init(&md->mutex); md->__iter_idx = MSI_XA_MAX_INDEX; dev->msi.data = md; @@ -1433,6 +1450,80 @@ int msi_domain_alloc_irqs_all_locked(str return msi_domain_alloc_locked(dev, &ctrl); } +/** + * msi_domain_alloc_irq_at - Allocate an interrupt from a MSI interrupt domain at + * a given index - or at the next free index + * + * @dev: Pointer to device struct of the device for which the interrupts + * are allocated + * @domid: Id of the interrupt domain to operate on + * @index: Index for allocation. If @index == %MSI_ANY_INDEX the allocation + * uses the next free index. + * @affdesc: Optional pointer to an interrupt affinity descriptor structure + * @icookie: Optional pointer to a domain specific per instance cookie. If + * non-NULL the content of the cookie is stored in msi_desc::data. + * Must be NULL for MSI-X allocations + * + * This requires a MSI interrupt domain which lets the core code manage the + * MSI descriptors. + * + * Return: struct msi_map + * + * On success msi_map::index contains the allocated index number and + * msi_map::virq the corresponding Linux interrupt number + * + * On failure msi_map::index contains the error code and msi_map::virq + * is %0. + */ +struct msi_map msi_domain_alloc_irq_at(struct device *dev, unsigned int domid, unsigned int index, + const struct irq_affinity_desc *affdesc, + union msi_instance_cookie *icookie) +{ + struct msi_ctrl ctrl = { .domid = domid, .nirqs = 1, }; + struct msi_domain_info *info; + struct irq_domain *domain; + struct msi_map map = { }; + struct msi_desc *desc; + int ret; + + msi_lock_descs(dev); + domain = msi_get_device_domain(dev, domid); + if (!domain) { + map.index = -ENODEV; + goto unlock; + } + + desc = msi_alloc_desc(dev, 1, affdesc); + if (!desc) { + map.index = -ENOMEM; + goto unlock; + } + + if (icookie) + desc->data.icookie = *icookie; + + ret = msi_insert_desc(dev, desc, domid, index); + if (ret) { + map.index = ret; + goto unlock; + } + + ctrl.first = ctrl.last = desc->msi_index; + info = domain->host_data; + + ret = __msi_domain_alloc_irqs(dev, domain, &ctrl); + if (ret) { + map.index = ret; + msi_domain_free_locked(dev, &ctrl); + } else { + map.index = desc->msi_index; + map.virq = desc->irq; + } +unlock: + msi_unlock_descs(dev); + return map; +} + static void __msi_domain_free_irqs(struct device *dev, struct irq_domain *domain, struct msi_ctrl *ctrl) { From patchwork Mon Nov 21 14:38:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23831 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1628717wrr; Mon, 21 Nov 2022 06:41:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf6TmSJl2WtqBA8AAJPIIc8NILlOnS5izQ6D29MKBE08q5m1/6ow+PYVsxSgUvF4VjQxNOV7 X-Received: by 2002:a17:906:805:b0:78d:8267:3379 with SMTP id e5-20020a170906080500b0078d82673379mr15517178ejd.415.1669041707254; Mon, 21 Nov 2022 06:41:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041707; cv=none; d=google.com; s=arc-20160816; b=JiDEqoLfiqqSnMjdkhKtQ6xidXLeNi/blCrv5KWLUkfGEKsQUzJbrJBRST0u1988gX rhJXzxuAyJ2ol669QcgQOGGgEqSMzWIGt+Ej4OmXdwWWBph5DTXRwdYcC93saGhAdYq5 Mx+umNowZNq3kjvipE3b3M0nePrUydv3RWoveIOJSmkdj3GMVmQlPg+TVY39h0W1E2lD HfXz/fyI8pxdNBPWbssmPHF2pY/R4l5mr21cnDp/cyATZTwhusfBg2qezsioh0AXCEYW XAPuSIRQLyOoQsGuItZnpUYjsqprvcEZN62ijScXrw5H9dVMZowdij1CHoax8vlSsv5s Pa6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=fGweWjopcEmhFfptqFTrW/NIWQ/1hQiFq3/Kny0SMZ4=; b=HOlo6wZPKYK1gIUCnYCDl5q53hOXUFE5e6UNOBk3zMjng+PfPT3a1wWci8BHH4nsk3 f+8Rej5qnkVkz4GVY5fMkMrExRNuY4kZKaEzPe9qRlFOvUVoCYAeT8q39OsAiIB9BRqA tSE6v2BhSJ3OOSOX8DqqgovYLVQW2KsXb/0ApLz5iH/kQFhulLSuqjC4Z9/gBq9pbUoA fH2JbFWGRNNYmhNdDUTdOChYgplpNDeA5aaFCctFeCyFlN4kAPsAzYq75T2oQZB4nrjk Pe204StTpJk2XuZoC5rKNiE7ZfqNmRNbcszXNWQWL5GHIb7sw55P2mTFkoFx2l0YWdNw 1JCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="0trFOjA/"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i14-20020a05640242ce00b0046751a6076bsi10988471edc.318.2022.11.21.06.41.08; Mon, 21 Nov 2022 06:41:47 -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=@linutronix.de header.s=2020 header.b="0trFOjA/"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231891AbiKUOkg (ORCPT + 99 others); Mon, 21 Nov 2022 09:40:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231593AbiKUOil (ORCPT ); Mon, 21 Nov 2022 09:38:41 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71E07C846F; Mon, 21 Nov 2022 06:38:15 -0800 (PST) Message-ID: <20221121091327.713589628@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041493; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=fGweWjopcEmhFfptqFTrW/NIWQ/1hQiFq3/Kny0SMZ4=; b=0trFOjA/R44BZgXeMIkt/zQa2KLYiFV47dS2jCKICJRADEWo3P+4K45ud54/XltrjjP0pr MDLf3zpmiqd7lmkbDv6vPaq1TcE6MpgRHzXv0Bb7i5hLDUW72+h5VmQwmVSVncl+/XpMKs wR8xedSJng6RivjUrfpw6RkBH/PRmCeZ3eFRXA+Y3q2//RffGFdn24XVp5YimRek+J/dhM D5+WSx78xnHdQxTIj5UaNqBFtZBZZ012TWHFJ568ehpMkBq/+39Hl7RCDs1LiRtcZISleS lBerxyrCVYJOmX2Tu3fcws/i2IqK4RVELbISH7tvkLWlgV9JPxNp0meazhk1KA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041493; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=fGweWjopcEmhFfptqFTrW/NIWQ/1hQiFq3/Kny0SMZ4=; b=1tH5asyB/T4QpgfzvDVzIhaPZE1I9+3rllXFlXeotjJXAOBr9MAPDa6wAdRRqPmydeLDPz 3+HngMWEkWKcRxCg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe , Jason Gunthorpe Subject: [patch V2 22/33] genirq/msi: Provide MSI_FLAG_MSIX_ALLOC_DYN References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:13 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117077107782737?= X-GMAIL-MSGID: =?utf-8?q?1750117077107782737?= Provide a new MSI feature flag in preparation for dynamic MSIX allocation after the initial MSI-X enable has been done. This needs to be an explicit MSI interrupt domain feature because quite some implementations (both interrupt domains and legacy allocation mode) have clear expectations that the allocation code is only invoked when MSI-X is about to be enabled. They either talk to hypervisors or do some other work and are not prepared to be invoked on an already MSI-X enabled device. This is also explicit MSI-X only because rewriting the size of the MSI entries is only possible when disabling MSI which in turn might cause lost interrupts on the device. Signed-off-by: Thomas Gleixner Reviewed-by: Jason Gunthorpe --- include/linux/msi.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -546,7 +546,8 @@ enum { MSI_FLAG_LEVEL_CAPABLE = (1 << 18), /* MSI-X entries must be contiguous */ MSI_FLAG_MSIX_CONTIGUOUS = (1 << 19), - + /* PCI/MSI-X vectors can be dynamically allocated/freed post MSI-X enable */ + MSI_FLAG_PCI_MSIX_ALLOC_DYN = (1 << 20), }; /** From patchwork Mon Nov 21 14:38:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23832 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1628730wrr; Mon, 21 Nov 2022 06:41:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf4guZ1/ViCcVMb0yNvYJxa10V2MwObth9Ei6O7cJu+0zdwsEDQCnUqZlbotuuESqTw52sWs X-Received: by 2002:a17:906:a212:b0:7b2:804f:a31c with SMTP id r18-20020a170906a21200b007b2804fa31cmr15496129ejy.523.1669041708512; Mon, 21 Nov 2022 06:41:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041708; cv=none; d=google.com; s=arc-20160816; b=BVC1MWNfN7mJ23xeXjbaWjuu5exWrQpdjAbGdIGg/tG2IFh/NamOiH54Tv8+IELDOq H6HKQl/BHVqQkODondt68q7/of1awqzBr4V5zbNenlNLDKcZ5wB/d9B2cZdUzv1yBfoO luQNi99IMgpfeHn7Dxpsb7g9qpAJEqQBvqkoqGGCB2O9MsQAM5rAgMhAhN/R4defEq8+ eotmX95Ajz0dcjIi2ZiulRvNR66hoKlGzcV6PriAvO2a9ntRU7450BvogvaT/+xi7hdw ItGHbXWI6Hs85bP6kpJ/vo1c7jQGSskMgpRWNzy5SOWBytzFJObQVif08NxrtloQaC9W kovw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=aPZsUav27NBNGy9CDcKsBA6eS6rPiDVMzp1pfp5Kt2c=; b=lkknpE4uxD4EAYS6OzxVTKEZ9tzhLA9RE5i+7vV8nE+C8gi58bCMpAJIC7y/vR2o1q LQluMSrasaAX9ja7zH0woRtlZq8wx/2qE+PQMXEOvEOVW6Xp2/cehMLJ78655RTSgrar yXN099Aa9bdWzWh5ATCWdYu1pmfjwgPvcZ3q/4uDladIdg5MXxQOOiBt9KIcK7WfFkJ2 QyMgg/N4tdo6nAUvjETpPhLn89NiZfLL6500H9v6isy3nEl4ky3Fr3Tjkb1pUb6kvq5+ 1DIVSj2hyDf9oW/zRjpKP1yrFTzqfVKmXnVIf1a502J0Rv2JLwwPLS5swP0TSTytq8vU RXFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="MP/SuT1e"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n10-20020a05640205ca00b004680dcb8900si10191040edx.213.2022.11.21.06.41.11; Mon, 21 Nov 2022 06:41:48 -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=@linutronix.de header.s=2020 header.b="MP/SuT1e"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231298AbiKUOkn (ORCPT + 99 others); Mon, 21 Nov 2022 09:40:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231720AbiKUOim (ORCPT ); Mon, 21 Nov 2022 09:38:42 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A90EBC72E1; Mon, 21 Nov 2022 06:38:16 -0800 (PST) Message-ID: <20221121091327.765751899@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041495; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=aPZsUav27NBNGy9CDcKsBA6eS6rPiDVMzp1pfp5Kt2c=; b=MP/SuT1eRbh9P77txd5gKe8HLBx8vQPoQ+Mf25IhzIhO+02JL8aKP/Wlqz2cEC6svkSOhM VCHDdpCOoFCpyQYQ001wNdgqeFrXcf0i+ZL8IBMvsCZqnLMnyfn84bKCbKVQM4ulpd6wgY oZjNfwUTGtjkzozAMfKYsSXhboQVGldg7a3ztLqg72B176HqYxGWmPMB61T5t9zNalwueY KsVT86hs42C2ipGA5OqROd97slYSI8WvhoYbGUJ8w9ArXLZBW6ARY7Ea3SHLgwEb+ydudG tDiCLJ1jLvkajQMI+RlYWF2CJV2QMIl1U+2TJKkT4MtBn0rEgLrKULx2a/TTpg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041495; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=aPZsUav27NBNGy9CDcKsBA6eS6rPiDVMzp1pfp5Kt2c=; b=AbZBfS5PtDXSGoS216fyH+iusnOJ175SCbLGv0W1kvqPWzCUH4jctX6x1aqQoXMDA3ToWx EuLX9euk0Hg3hIDA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 23/33] PCI/MSI: Split MSI-X descriptor setup References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:14 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117078483824976?= X-GMAIL-MSGID: =?utf-8?q?1750117078483824976?= The upcoming mechanism to allocate MSI-X vectors after enabling MSI-X needs to share some of the MSI-X descriptor setup. The regular descriptor setup on enable has the following code flow: 1) Allocate descriptor 2) Setup descriptor with PCI specific data 3) Insert descriptor 4) Allocate interrupts which in turn scans the inserted descriptors This cannot be easily changed because the PCI/MSI code needs to handle the legacy architecture specific allocation model and the irq domain model where quite some domains have the assumption that the above flow is how it works. Ideally the code flow should look like this: 1) Invoke allocation at the MSI core 2) MSI core allocates descriptor 3) MSI core calls back into the irq domain which fills in the domain specific parts This could be done for underlying parent MSI domains which support post-enable allocation/free but that would create significantly different code pathes for MSI/MSI-X enable. Though for dynamic allocation which wants to share the allocation code with the upcoming PCI/IMS support it's the right thing to do. Split the MSI-X descriptor setup into the preallocation part which just sets the index and fills in the horrible hack of virtual IRQs and the real PCI specific MSI-X setup part which solely depends on the index in the descriptor. This allows to provide a common dynamic allocation interface at the MSI core level for both PCI/MSI-X and PCI/IMS. Signed-off-by: Thomas Gleixner Acked-by: Bjorn Helgaas --- drivers/pci/msi/msi.c | 72 +++++++++++++++++++++++++++++++------------------- drivers/pci/msi/msi.h | 2 + 2 files changed, 47 insertions(+), 27 deletions(-) --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -569,34 +569,56 @@ static void __iomem *msix_map_region(str return ioremap(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE); } -static int msix_setup_msi_descs(struct pci_dev *dev, void __iomem *base, - struct msix_entry *entries, int nvec, - struct irq_affinity_desc *masks) +/** + * msix_prepare_msi_desc - Prepare a half initialized MSI descriptor for operation + * @dev: The PCI device for which the descriptor is prepared + * @desc: The MSI descriptor for preparation + * + * This is separate from msix_setup_msi_descs() below to handle dynamic + * allocations for MSI-X after initial enablement. + * + * Ideally the whole MSI-X setup would work that way, but there is no way to + * support this for the legacy arch_setup_msi_irqs() mechanism and for the + * fake irq domains like the x86 XEN one. Sigh... + * + * The descriptor is zeroed and only @desc::msi_index and @desc::affinity + * are set. When called from msix_setup_msi_descs() then the is_virtual + * attribute is initialized as well. + * + * Fill in the rest. + */ +void msix_prepare_msi_desc(struct pci_dev *dev, struct msi_desc *desc) +{ + desc->nvec_used = 1; + desc->pci.msi_attrib.is_msix = 1; + desc->pci.msi_attrib.is_64 = 1; + desc->pci.msi_attrib.default_irq = dev->irq; + desc->pci.mask_base = dev->msix_base; + desc->pci.msi_attrib.can_mask = !pci_msi_ignore_mask && + !desc->pci.msi_attrib.is_virtual; + + if (desc->pci.msi_attrib.can_mask) { + void __iomem *addr = pci_msix_desc_addr(desc); + + desc->pci.msix_ctrl = readl(addr + PCI_MSIX_ENTRY_VECTOR_CTRL); + } +} + +static int msix_setup_msi_descs(struct pci_dev *dev, struct msix_entry *entries, + int nvec, struct irq_affinity_desc *masks) { int ret = 0, i, vec_count = pci_msix_vec_count(dev); struct irq_affinity_desc *curmsk; struct msi_desc desc; - void __iomem *addr; memset(&desc, 0, sizeof(desc)); - desc.nvec_used = 1; - desc.pci.msi_attrib.is_msix = 1; - desc.pci.msi_attrib.is_64 = 1; - desc.pci.msi_attrib.default_irq = dev->irq; - desc.pci.mask_base = base; - for (i = 0, curmsk = masks; i < nvec; i++, curmsk++) { desc.msi_index = entries ? entries[i].entry : i; desc.affinity = masks ? curmsk : NULL; desc.pci.msi_attrib.is_virtual = desc.msi_index >= vec_count; - desc.pci.msi_attrib.can_mask = !pci_msi_ignore_mask && - !desc.pci.msi_attrib.is_virtual; - if (desc.pci.msi_attrib.can_mask) { - addr = pci_msix_desc_addr(&desc); - desc.pci.msix_ctrl = readl(addr + PCI_MSIX_ENTRY_VECTOR_CTRL); - } + msix_prepare_msi_desc(dev, &desc); ret = msi_insert_msi_desc(&dev->dev, &desc); if (ret) @@ -629,9 +651,8 @@ static void msix_mask_all(void __iomem * writel(ctrl, base + PCI_MSIX_ENTRY_VECTOR_CTRL); } -static int msix_setup_interrupts(struct pci_dev *dev, void __iomem *base, - struct msix_entry *entries, int nvec, - struct irq_affinity *affd) +static int msix_setup_interrupts(struct pci_dev *dev, struct msix_entry *entries, + int nvec, struct irq_affinity *affd) { struct irq_affinity_desc *masks = NULL; int ret; @@ -640,7 +661,7 @@ static int msix_setup_interrupts(struct masks = irq_create_affinity_masks(nvec, affd); msi_lock_descs(&dev->dev); - ret = msix_setup_msi_descs(dev, base, entries, nvec, masks); + ret = msix_setup_msi_descs(dev, entries, nvec, masks); if (ret) goto out_free; @@ -678,7 +699,6 @@ static int msix_setup_interrupts(struct static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries, int nvec, struct irq_affinity *affd) { - void __iomem *base; int ret, tsize; u16 control; @@ -696,15 +716,13 @@ static int msix_capability_init(struct p pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control); /* Request & Map MSI-X table region */ tsize = msix_table_size(control); - base = msix_map_region(dev, tsize); - if (!base) { + dev->msix_base = msix_map_region(dev, tsize); + if (!dev->msix_base) { ret = -ENOMEM; goto out_disable; } - dev->msix_base = base; - - ret = msix_setup_interrupts(dev, base, entries, nvec, affd); + ret = msix_setup_interrupts(dev, entries, nvec, affd); if (ret) goto out_disable; @@ -719,7 +737,7 @@ static int msix_capability_init(struct p * which takes the MSI-X mask bits into account even * when MSI-X is disabled, which prevents MSI delivery. */ - msix_mask_all(base, tsize); + msix_mask_all(dev->msix_base, tsize); pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_MASKALL, 0); pcibios_free_irq(dev); --- a/drivers/pci/msi/msi.h +++ b/drivers/pci/msi/msi.h @@ -84,6 +84,8 @@ static inline __attribute_const__ u32 ms return (1 << (1 << desc->pci.msi_attrib.multi_cap)) - 1; } +void msix_prepare_msi_desc(struct pci_dev *dev, struct msi_desc *desc); + /* Subsystem variables */ extern int pci_msi_enable; From patchwork Mon Nov 21 14:38:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23835 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1629026wrr; Mon, 21 Nov 2022 06:42:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf6FP9Gv7CYH2iQ+tCz6/JRosJ0h+npBztQkZjfgYi/0SQkTby8hId1sv+YyzZpEiaq28MMN X-Received: by 2002:a17:906:2dcb:b0:7b2:8a70:8fb7 with SMTP id h11-20020a1709062dcb00b007b28a708fb7mr15930107eji.163.1669041741522; Mon, 21 Nov 2022 06:42:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041741; cv=none; d=google.com; s=arc-20160816; b=0iHZS9KOaZ0+4vly9NBl/KpHvxvBqNpJhLDA0Qh3pwUKoXJQsCpOOSUkwG85gb16eh 1oSZe1ZtaGHwkMa0gJUc4/RYb6HTNZy1HdVWZhwZDw8Y69iYBDE2kGN0MoAihBktKczp 6lbX/KQYIgbzm/WBvNTEj/O/7FU9EM+8BJPqF92+/Ut9wNc4Y6DAB0l6WEZVcDsqlz4s MB6As/Ck/jVu+buBTgli+yrMDcyfyxXE253QWImxnrgYQeOcQV29vgoBiVqgtpKwuYwi ASJCT8MBJf2S9Q8rRZDc09CmJ/8l4/+KUYEBljIruqoxmp4AeZVcjuGg/qww7BC/YYKP u++g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=jPRMH9ANd3Y1Xl+LkBRLSL32jXRgRoZHrUPJTpoWc4w=; b=ifqaxDKAyg/XyDOyvK003vXRBKuSaKhg1GcN4fuyek9SvdTbGhf11zn8bOavEyrw/5 1thaEkU8BH0xw0Ys9NC6Abd5adFrL6wDo1zD7mE6DPn5hv3uYnhls/aQsNySTPlpWAPd Ud87W2OLoWtNs0NlDSfrcRWSzSM03R/+umEiSgvPnKWkQndzK4IhcSUsLXEvNgdG0Dgh GNiQnU0+AbUTuADFXslbtmj4zoX5se82/EBlFVxZvXo63NQtRKt6uUyfvvZHvHZpGex4 b4wS0dHAVYhOVH3Tq2pxTYGjr3gqOF5IV/qjNMOyUoXHqfNninmyn+wYHVtQJVyRz3JJ 2HDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QAyxdW6h; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg13-20020a170907a40d00b007ae4ed48290si11013501ejc.279.2022.11.21.06.41.18; Mon, 21 Nov 2022 06:42:21 -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=@linutronix.de header.s=2020 header.b=QAyxdW6h; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231838AbiKUOkq (ORCPT + 99 others); Mon, 21 Nov 2022 09:40:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231725AbiKUOin (ORCPT ); Mon, 21 Nov 2022 09:38:43 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3640C900F; Mon, 21 Nov 2022 06:38:17 -0800 (PST) Message-ID: <20221121091327.817612499@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041496; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=jPRMH9ANd3Y1Xl+LkBRLSL32jXRgRoZHrUPJTpoWc4w=; b=QAyxdW6h4sEX+AbOWBAvdjH57yGH+aQr6mTBG5rtDFmVg5qPzm94rcyOtu6n1/2NOEOjHG 8mtB7wgZG+/SeMhngvjdMShENcu37cSHRYCbM5G/R0rsFpBujjDVARJKBZaZHXsTXVj8DR +w5sevvdAhMTf30QKj9KvoP3kPLfZydnyJfK4Wd9JKoeZv5LSyyuQ4931QcJqefR+tupdW L/gZefLOfpBgSGRyWxtN+0Krgpukyd3rsYW1Ziqu1YEMKVrb/8WPXpWM+tX2XKXB/Jf+nY vH1HM608y3ZHSsXhWL9pNMTqaDOxxxcaZ/+gZvQioSDHffPb2ymCbzWw5Bbqhg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041496; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=jPRMH9ANd3Y1Xl+LkBRLSL32jXRgRoZHrUPJTpoWc4w=; b=+Aq08sUBX75c5DnBj1c1zdU+rBdYklHxGULnWz5ywt1uWk4RCag051MzVzbxyhWOitNgaJ 64OLROZGxAURy1Bg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe , Jason Gunthorpe Subject: [patch V2 24/33] PCI/MSI: Provide prepare_desc() MSI domain op References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:16 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117112958810666?= X-GMAIL-MSGID: =?utf-8?q?1750117112958810666?= The setup of MSI descriptors for PCI/MSI-X interrupts depends partially on the MSI index for which the descriptor is initialized. Dynamic MSI-X vector allocation post MSI-X enablement allows to allocate vectors at a given index or at any free index in the available table range. The latter requires that the descriptor is initialized after the MSI core has chosen an index. Implement the prepare_desc() op in the PCI/MSI-X specific msi_domain_ops which is invoked before the core interrupt descriptor and the associated Linux interrupt number is allocated. That callback is also provided for the upcoming PCI/IMS implementations so the implementation specific interrupt domain can do their domain specific initialization of the MSI descriptors. Signed-off-by: Thomas Gleixner Reviewed-by: Jason Gunthorpe Acked-by: Bjorn Helgaas --- V2: Reworded changelog (Bjorn) --- drivers/pci/msi/irqdomain.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/drivers/pci/msi/irqdomain.c +++ b/drivers/pci/msi/irqdomain.c @@ -202,6 +202,14 @@ static void pci_unmask_msix(struct irq_d pci_msix_unmask(irq_data_get_msi_desc(data)); } +static void pci_msix_prepare_desc(struct irq_domain *domain, msi_alloc_info_t *arg, + struct msi_desc *desc) +{ + /* Don't fiddle with preallocated MSI descriptors */ + if (!desc->pci.mask_base) + msix_prepare_msi_desc(to_pci_dev(desc->dev), desc); +} + static struct msi_domain_template pci_msix_template = { .chip = { .name = "PCI-MSIX", @@ -212,6 +220,7 @@ static struct msi_domain_template pci_ms }, .ops = { + .prepare_desc = pci_msix_prepare_desc, .set_desc = pci_device_domain_set_desc, }, From patchwork Mon Nov 21 14:38:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23833 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1628810wrr; Mon, 21 Nov 2022 06:41:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf5bv0hN2gOBZhlSeJfuW1Tj7FwL2oz7wCOptFkRrrWfVURZ3bP3K0AHXEUtDpDwsib0uTf/ X-Received: by 2002:a17:907:2bf5:b0:7ae:7eca:46ad with SMTP id gv53-20020a1709072bf500b007ae7eca46admr16296995ejc.198.1669041719821; Mon, 21 Nov 2022 06:41:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041719; cv=none; d=google.com; s=arc-20160816; b=fXAjoGsnrrpskl7RV+VKacGfLgdaQAPFgY0zfRK8HlY+Ac1wPUUR8IrOIt3bs6rY4N 0ZIQO/19LJglVxgnJHwUSShAsMRll5+d9dN4TpVASRWo2VRxPJb9iGn6qmrr+giAtgWw bW19tAiwYJ07byEpAJMCske/7rDI/8oVe632lTERvmzvJf0u/oAKZEnr9urZYsFmXvXl aA2ug8VSw3D+xYx98ozrXZzJ7SgsYHcy/eUtsz1RlIK1UPFwRX84hhT4thD93lX7PiIG 1coRA+ngPyED/94xC1qx7dVs/Dz3/fEBmOXbzaA0wO0jmjfMV0Dhh2flc6Z9EugEd1ln mlzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=ySZBnEyGuRxlvnKXenaibefk4WZuhy1dihAtBCTEudU=; b=HntQ3AseoR6OLPmhXTIsx08yKaxiTOsmaVSUfr0iNvcQ/NKE2G55oy+kgyixmtkCnM tNE0XI6AjuviGCW+jKoRiTTKMg0Ne3hSoe5+EwF5cTA7MWdICCnVhUW5sZ2zWQb4QJ4U pldDAeGd8nviQJI65lndf9RNBuXTwa3d2Q+ykrOHz+XuLv7gqPOX3KQWnoGclcadDfEm GzBJcPypa1W9GGiaI1Xrl85ibJucmID/lB601DYVxZZJUrfNJ1CcJatjtabZ0qiWw8ZQ Eo15JQJBB7hVpWqaBL6dK24iQSiHPcR25WKHcwL6FKWATp5taWUX1pJbJvlYfc73NTUJ Ae+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=vDkTvONU; dkim=neutral (no key) header.i=@linutronix.de header.b=7D5J7FBn; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f16-20020a056402355000b004637be0f76csi10590544edd.186.2022.11.21.06.41.23; Mon, 21 Nov 2022 06:41:59 -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=@linutronix.de header.s=2020 header.b=vDkTvONU; dkim=neutral (no key) header.i=@linutronix.de header.b=7D5J7FBn; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231897AbiKUOky (ORCPT + 99 others); Mon, 21 Nov 2022 09:40:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231735AbiKUOiq (ORCPT ); Mon, 21 Nov 2022 09:38:46 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 182F1C8C80; Mon, 21 Nov 2022 06:38:18 -0800 (PST) Message-ID: <20221121091327.869774994@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041497; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=ySZBnEyGuRxlvnKXenaibefk4WZuhy1dihAtBCTEudU=; b=vDkTvONU4ycWxcJHHxqgO6wzZknMZKOx5ir55rLZMR3QAYSJqRYuZVTRl3fzINaODHhXfR GnGXLlW8WBXNsEon+oB54WjtapRuJog/kXZ5kBw8vE1aSOgPSssXDi3dJLVdDRwUjQ/Uy0 MGHXKc6F1sOFUXu2N453cIaagcO4SjbUe10dj3JCEMRaEdThxiUdNzxxG43O6kPMjti42g KD26wNhsM2AYJyEKTRfY55N5mieZY4vzZT0hBoWBqV18ROlkJl2SSyzqY44mEOfpoFg+O/ 03UO7EdvbJijq/K9uxNXLEmbDPU/RkqNBKIY2nr8o5QvGQt9OpDq1TIG3DvSVQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041497; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=ySZBnEyGuRxlvnKXenaibefk4WZuhy1dihAtBCTEudU=; b=7D5J7FBno5xLszNZN2vuCu3a4wHcbaXMhn9N8S22CQb2S2j+YOb7NrbNtGOiYMlFt8at4u b/p6LCvgVIgkcKDQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 25/33] PCI/MSI: Provide post-enable dynamic allocation interfaces for MSI-X References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:17 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117090569505935?= X-GMAIL-MSGID: =?utf-8?q?1750117090569505935?= MSI-X vectors can be allocated after the initial MSI-X enablement, but this needs explicit support of the underlying interrupt domains. Provide a function to query the ability and functions to allocate/free individual vectors post-enable. The allocation can either request a specific index in the MSI-X table or with the index argument MSI_ANY_INDEX it allocates the next free vector. The return value is a struct msi_map which on success contains both index and the Linux interrupt number. In case of failure index is negative and the Linux interrupt number is 0. The allocation function is for a single MSI-X index at a time as that's sufficient for the most urgent use case VFIO to get rid of the 'disable MSI-X, reallocate, enable-MSI-X' cycle which is prone to lost interrupts and redirections to the legacy and obviously unhandled INTx. As single index allocation is also sufficient for the use cases Jason Gunthorpe pointed out: Allocation of a MSI-X or IMS vector for a network queue. See Link below. Signed-off-by: Thomas Gleixner Acked-by: Bjorn Helgaas Link: https://lore.kernel.org/all/20211126232735.547996838@linutronix.de --- V2: Added Link to previous discussions (Bjorn) --- drivers/pci/msi/api.c | 67 ++++++++++++++++++++++++++++++++++++++++++++ drivers/pci/msi/irqdomain.c | 3 + include/linux/pci.h | 6 +++ 3 files changed, 75 insertions(+), 1 deletion(-) --- a/drivers/pci/msi/api.c +++ b/drivers/pci/msi/api.c @@ -113,6 +113,73 @@ int pci_enable_msix_range(struct pci_dev EXPORT_SYMBOL(pci_enable_msix_range); /** + * pci_msix_can_alloc_dyn - Query whether dynamic allocation after enabling + * MSI-X is supported + * + * @dev: PCI device to operate on + * + * Return: True if supported, false otherwise + */ +bool pci_msix_can_alloc_dyn(struct pci_dev *dev) +{ + if (!dev->msix_cap) + return false; + + return pci_msi_domain_supports(dev, MSI_FLAG_PCI_MSIX_ALLOC_DYN, DENY_LEGACY); +} +EXPORT_SYMBOL_GPL(pci_msix_can_alloc_dyn); + +/** + * pci_msix_alloc_irq_at - Allocate an MSI-X interrupt after enabling MSI-X + * at a given MSI-X vector index or any free vector index + * + * @dev: PCI device to operate on + * @index: Index to allocate. If @index == MSI_ANY_INDEX this allocates + * the next free index in the MSI-X table + * @affdesc: Optional pointer to an affinity descriptor structure. NULL otherwise + * + * Return: A struct msi_map + * + * On success msi_map::index contains the allocated index (>= 0) and + * msi_map::virq the allocated Linux interrupt number (> 0). + * + * On fail msi_map::index contains the error code and msi_map::virq + * is set to 0. + */ +struct msi_map pci_msix_alloc_irq_at(struct pci_dev *dev, unsigned int index, + const struct irq_affinity_desc *affdesc) +{ + struct msi_map map = { .index = -ENOTSUPP }; + + if (!dev->msix_enabled) + return map; + + if (!pci_msix_can_alloc_dyn(dev)) + return map; + + return msi_domain_alloc_irq_at(&dev->dev, MSI_DEFAULT_DOMAIN, index, affdesc, NULL); +} +EXPORT_SYMBOL_GPL(pci_msix_alloc_irq_at); + +/** + * pci_msix_free_irq - Free an interrupt on a PCI/MSIX interrupt domain + * which was allocated via pci_msix_alloc_irq_at() + * + * @dev: The PCI device to operate on + * @map: A struct msi_map describing the interrupt to free + * as returned from the allocation function. + */ +void pci_msix_free_irq(struct pci_dev *dev, struct msi_map map) +{ + if (WARN_ON_ONCE(map.index < 0 || map.virq <= 0)) + return; + if (WARN_ON_ONCE(!pci_msix_can_alloc_dyn(dev))) + return; + msi_domain_free_irqs_range(&dev->dev, MSI_DEFAULT_DOMAIN, map.index, map.index); +} +EXPORT_SYMBOL_GPL(pci_msix_free_irq); + +/** * pci_disable_msix() - Disable MSI-X interrupt mode on device * @dev: the PCI device to operate on * --- a/drivers/pci/msi/irqdomain.c +++ b/drivers/pci/msi/irqdomain.c @@ -225,7 +225,8 @@ static struct msi_domain_template pci_ms }, .info = { - .flags = MSI_COMMON_FLAGS | MSI_FLAG_PCI_MSIX, + .flags = MSI_COMMON_FLAGS | MSI_FLAG_PCI_MSIX | + MSI_FLAG_PCI_MSIX_ALLOC_DYN, .bus_token = DOMAIN_BUS_PCI_DEVICE_MSIX, }, }; --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -1559,6 +1560,11 @@ int pci_alloc_irq_vectors_affinity(struc unsigned int max_vecs, unsigned int flags, struct irq_affinity *affd); +bool pci_msix_can_alloc_dyn(struct pci_dev *dev); +struct msi_map pci_msix_alloc_irq_at(struct pci_dev *dev, unsigned int index, + const struct irq_affinity_desc *affdesc); +void pci_msix_free_irq(struct pci_dev *pdev, struct msi_map map); + void pci_free_irq_vectors(struct pci_dev *dev); int pci_irq_vector(struct pci_dev *dev, unsigned int nr); const struct cpumask *pci_irq_get_affinity(struct pci_dev *pdev, int vec); From patchwork Mon Nov 21 14:38:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23836 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1629288wrr; Mon, 21 Nov 2022 06:42:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf5j1NbsihWrg5S1iRvg0stfQSniI22PqarCKpYmsn2EVvKYPR+3HT9UMcmYHmsn+Z4EXOtw X-Received: by 2002:aa7:c941:0:b0:469:172:4f46 with SMTP id h1-20020aa7c941000000b0046901724f46mr14064249edt.130.1669041774283; Mon, 21 Nov 2022 06:42:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041774; cv=none; d=google.com; s=arc-20160816; b=NeqDrPqq0d1lMYBJ1E7FPu8VxKaVssq2ew2iCK6XG7J3L3diIl7NCAvcnS0isDQINt uSsvNFgYEaAlj9Gm+9eeR9StPkZmYmO9Kdm8vIag8CHqglLIZGFyVCDXnJq04WFxVkHt P4l9HKru/Jex23QV2tF2Awzy6Q5Al1zYHYnaa3PMdYdGhu9Q+LZBX+uquY4fXPZ89NZQ xJYPn2icxsiSJm4B071D/o53VjsPye9y8dhM7UPmwYgne2HlD6ugHmymJuc6/jWEAZyw dGxu762iw5w4Pn9x+aSCW7mCK/PQpcRlYNp6DvCLqMnWGRtf7KUFpGgHaGs5wAXTgiOs xqtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=IEK08cS7O6Uv3gBo3cg3kU1MfAmms/KMIPye21Vs0c0=; b=d34dDHS+sSg4oVB4LagyVvCiHejSdqEpeALar8vUoVxZb7yWRyGy913szgqJjdgebW QR3KPqD5GuE72PCb90SWYrFwqs/JF1VthXX3wKjrugJMjMrmk85WWSko7ZkY2yoC63dP vZPehNMbIj08SlguuHGFH85b7mG/th3VcuHH8e9qnoMQyP2Sh6BG0kas63zmnbnyL/+J 0AP9Rz8PGyjVDPoxtmb75Ako0XesCGXmVcylYM78CmFsgN0+OBaHExqm/HUgCAjxFyYU CW072zN0BNDoCvQ7fLJuqvTu16J9wUGl+mfrIB9jbgfh0WnM3aARqyyyDuhQmeHSKjzY HMLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=FOjNyluw; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=VC1cKWs2; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr13-20020a1709073f8d00b007ad95fdd21csi10609094ejc.761.2022.11.21.06.41.33; Mon, 21 Nov 2022 06:42:54 -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=@linutronix.de header.s=2020 header.b=FOjNyluw; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=VC1cKWs2; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231913AbiKUOk7 (ORCPT + 99 others); Mon, 21 Nov 2022 09:40:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231747AbiKUOiw (ORCPT ); Mon, 21 Nov 2022 09:38:52 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 460E1C8CA1; Mon, 21 Nov 2022 06:38:20 -0800 (PST) Message-ID: <20221121091327.922123028@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041498; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=IEK08cS7O6Uv3gBo3cg3kU1MfAmms/KMIPye21Vs0c0=; b=FOjNyluwYTVfgbUlUqvSpufgSPqPWBkjwYPpLU0srHbeiYCTZSwo7lp5CK1h5FxATnNEAo 4vCpTPc0Br1TqaIk/94fe/heYvuRWm2RayisFudNKNyYRCi9DFxnnDx5pHRrI4PmtLyktt XtLnWmZIAaM3JEXu9SGcOAAOiYxQgjOS5OnS/9maUcsIWCvlHoEh5GJukurohD9GCK1xpb 2EwBMLzcv1npoHqA+jBBKEpOpRlKm42sySIHvCjuA/myYZSW1a7zDjtUOm15Aq9ctqFOfp 7MnxHN1ZQWZv7nSLLh2sTznP9CFekTYRhAvYAiPwpR6naKlvuGEYAtVP5pxhew== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041498; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=IEK08cS7O6Uv3gBo3cg3kU1MfAmms/KMIPye21Vs0c0=; b=VC1cKWs2sBNafNezyRr5qwKNgCj2GyUHsobAOCxlVslC+hu/v3pASNRv4wDoPBHbOwsoq3 pK26hIf97k96nODg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 26/33] x86/apic/msi: Enable MSI_FLAG_PCI_MSIX_ALLOC_DYN References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:18 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117147431435461?= X-GMAIL-MSGID: =?utf-8?q?1750117147431435461?= x86 MSI irqdomains can handle MSI-X allocation post MSI-X enable just out of the box - on the vector domain and on the remapping domains, Add the feature flag to the supported feature list Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/msi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/include/asm/msi.h +++ b/arch/x86/include/asm/msi.h @@ -63,7 +63,7 @@ struct msi_msg; u32 x86_msi_msg_get_destid(struct msi_msg *msg, bool extid); #define X86_VECTOR_MSI_FLAGS_SUPPORTED \ - (MSI_GENERIC_FLAGS_MASK | MSI_FLAG_PCI_MSIX) + (MSI_GENERIC_FLAGS_MASK | MSI_FLAG_PCI_MSIX | MSI_FLAG_PCI_MSIX_ALLOC_DYN) #define X86_VECTOR_MSI_FLAGS_REQUIRED \ (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS) From patchwork Mon Nov 21 14:38:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23837 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1629362wrr; Mon, 21 Nov 2022 06:43:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf4gm472rBC5oQ3X47vEGRS+G4TeJ1pn4y7OJKI89AGKPfhzgQDC7H0yA9/bWli2LZuWnrrH X-Received: by 2002:a17:906:ce28:b0:780:8c5d:f86 with SMTP id sd8-20020a170906ce2800b007808c5d0f86mr15737037ejb.391.1669041782451; Mon, 21 Nov 2022 06:43:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669041782; cv=none; d=google.com; s=arc-20160816; b=siTdbbOIdqTQCdhOwuCEgCs0ASVDeoOWTOpm6aB/cSlgRHZZMxBZtCI39JuvuSreVK whjq95XKkxHYr3QVIf5MEj56QO7fYohEOEFLohDffTxLw2VlXkKoVJeXC6L11nJ8TUKe FqTCVgpCLaRrb1ATv89FD9YtBMqma3zUE64Zp2DFLXKWjCI+sRFUdSlGXRadAya2qLa3 2gMIHLumdtn7SqgwhITbOTh9157p+/Tuqdk048vm/wCuOShg7freCVVRXWFtuuovkFxm fZuYShpmjL7yTp9mZqTyOKNmdPFblTwYHFMWv/eLUwTNdsWwC3Y8VFd0EP09n8F8x/+t fvPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=7ozm1W9vDFfSIoLTXblkyRUQVqcZdWLOTQR4Ad9y7GE=; b=Dqic3+eLZ4XXjbRNWsiAD0fPg3KENp2mVuMjoUgMcgQmIpP4XbN4uCvFS1srw2SK+t KCjFtMmf+yF6XV4dlbQNnfLVR4n0fxYwv7dSb/wWsjjwtfmqBMdmYuNYOf85ilyXsrKi Ttef8u7AmKuBVBF/M9Uo2CvhL3e/C1Jd31SHyd/jOBtZEJiUJX47lRfCSU12KsX8FQbh 2bs87KscTuWPu7w1/6IjSG+CuimYsJpjINfkMu1SsDE2JjjtZpDHVmdL5TETXomblCob kq3ye+1jhZ108Zwxj5PpC2AjMVAbkUpGo112GXqIrsg7jV7XKYvKoqcrUwnO6HAWpA58 L8ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LhyPLCQA; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=wFcT822C; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i5-20020a05640242c500b00456e33b69e1si10570135edc.347.2022.11.21.06.42.27; Mon, 21 Nov 2022 06:43:02 -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=@linutronix.de header.s=2020 header.b=LhyPLCQA; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=wFcT822C; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231783AbiKUOlJ (ORCPT + 99 others); Mon, 21 Nov 2022 09:41:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231488AbiKUOjJ (ORCPT ); Mon, 21 Nov 2022 09:39:09 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D2CCC769F; Mon, 21 Nov 2022 06:38:21 -0800 (PST) Message-ID: <20221121091327.974140298@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041500; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=7ozm1W9vDFfSIoLTXblkyRUQVqcZdWLOTQR4Ad9y7GE=; b=LhyPLCQAlQHr9qTA1Ov1RETf6QOK21scp548PxBrBrcSgTLtgu3tx6hBXW6pxwdzdk7OJO 8b7fiFl6zWF2xK2qhaBeOyYHJWfjB/qLEo1iRYSFhkzPM3iA3nnvRQLHEyCb6wjUW9TPWG T/b85oB1D2A4HmnGxVuKbDpxwXpwKVHT8t4BE4a2DBLMIXIepfBfrK3aN6Ooq0Q47H4KbV vys+RRBzHlW4F5xwAlsY31feT/DgvE7c203LkV+kqSErylFwaiBFk/W3oDlG+VkhJBjiU6 iGvYrduZqr6rZQGDGsxVseXs1HW6MAzAWDnO+Gka65SSU/rPpyIjzaKdgM5vYg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041500; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=7ozm1W9vDFfSIoLTXblkyRUQVqcZdWLOTQR4Ad9y7GE=; b=wFcT822CR/M3YtgqkGDDY1oHnMwc1eEUZaiI1oHqaWHZT+lcZLG85Qm845cZgcbFJnmcBz lq4DQI0kv9m+ncAw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 27/33] genirq/msi: Provide constants for PCI/IMS support References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:19 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117156337501037?= X-GMAIL-MSGID: =?utf-8?q?1750117156337501037?= Provide the necessary constants for PCI/IMS support: - A new bus token for MSI irqdomain identification - A MSI feature flag for the MSI irqdomains to signal support - A secondary domain id The latter expands the device internal domain pointer storage array from 1 to 2 entries. That extra pointer is mostly unused today, but the alternative solutions would not be free either and would introduce more complexity all over the place. Trade the 8bytes for simplicity. Signed-off-by: Thomas Gleixner --- include/linux/irqdomain_defs.h | 1 + include/linux/msi.h | 2 ++ include/linux/msi_api.h | 1 + 3 files changed, 4 insertions(+) --- a/include/linux/irqdomain_defs.h +++ b/include/linux/irqdomain_defs.h @@ -25,6 +25,7 @@ enum irq_domain_bus_token { DOMAIN_BUS_PCI_DEVICE_MSIX, DOMAIN_BUS_DMAR, DOMAIN_BUS_AMDVI, + DOMAIN_BUS_PCI_DEVICE_IMS, }; #endif /* _LINUX_IRQDOMAIN_DEFS_H */ --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -529,6 +529,8 @@ enum { MSI_FLAG_MSIX_CONTIGUOUS = (1 << 19), /* PCI/MSI-X vectors can be dynamically allocated/freed post MSI-X enable */ MSI_FLAG_PCI_MSIX_ALLOC_DYN = (1 << 20), + /* Support for PCI/IMS */ + MSI_FLAG_PCI_IMS = (1 << 21), }; /** --- a/include/linux/msi_api.h +++ b/include/linux/msi_api.h @@ -15,6 +15,7 @@ struct device; */ enum msi_domain_ids { MSI_DEFAULT_DOMAIN, + MSI_SECONDARY_DOMAIN, MSI_MAX_DEVICE_IRQDOMAINS, }; From patchwork Mon Nov 21 14:38:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23838 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1632804wrr; Mon, 21 Nov 2022 06:49:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Ia4o1IYDIzpqi50aE2RJhqDt3q0Am9OmniTq5c0NDEfH/GXrfXrmbpmnbuFlzXqz2LkT8 X-Received: by 2002:a17:90a:4905:b0:212:fd8c:523a with SMTP id c5-20020a17090a490500b00212fd8c523amr20908959pjh.52.1669042182972; Mon, 21 Nov 2022 06:49:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669042182; cv=none; d=google.com; s=arc-20160816; b=IEuI10bxi/xX1dW+ySHoVkhqPcfSKedoU228trgb9+ueH/PXCC3UGvB2TWcBVmRchy EXS0Ee/KMvkITWQwHT7PXOmy5jWQN6fHq4HxRnJ1S1Xm7wH3nUlyEehEjl4DeoAghpQK Klp+BbVe5LYf0VIqxwG8PnzV1/xa/FSj8JHCe/YlcebYJaXFHQ3QP4c0AZ8zG1aSin9s 1b32ur8qdBj5WjSkKsC+3MmU1K1/EOwzu/dtLshTZ5pC2lXmr/tCYF+bjYDH9L1zGsen IPMiQjciqhQXgsl4O9doFDx8MOh7gVzxcE5KlgMGKa+OLpP2o14DA0LrSEPnenmo7Ewh xEhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=dPsIsUTlWmyEo9zstL3A7RgXpEoaaZrG8HYlS9a0uvQ=; b=GZXB6vzi460NeA9SONfsXaZY4jPmICsENP9Ez+jIcjPQgIrqxg2wZiT9MovEcNSHvE VcT8kBltau3rtKCqlBi4ElArqcqME5CxvQxxPRjtJhhLNpDOU9XA7KCLEp6xu6LCkMPt B51PrxNOv37WMdLOWQXryKxoAPMLG7c1l79Jdjeetrh7M7wp5jgnlcGNiRQ3pJAl80Yp N/U7lPRxSaU7U8H6qdruKHU4GD/f8JIbECVlvFJbfE5QGnmC+Utd6fIEyrr+GfUY14hB BP4s1xdCV4kVg/AQQJyPDmc6YeDf+3tYKSmfHDQIKNuTVoh+WrBdtVRo7drVjH5NY++/ I+jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JglSAlvk; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=RI0AvfYJ; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w24-20020a17090a8a1800b00218b41176a9si2612227pjn.182.2022.11.21.06.49.26; Mon, 21 Nov 2022 06:49:42 -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=@linutronix.de header.s=2020 header.b=JglSAlvk; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=RI0AvfYJ; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231687AbiKUOlP (ORCPT + 99 others); Mon, 21 Nov 2022 09:41:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231490AbiKUOjM (ORCPT ); Mon, 21 Nov 2022 09:39:12 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A30FC80D7; Mon, 21 Nov 2022 06:38:22 -0800 (PST) Message-ID: <20221121091328.026206487@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041501; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=dPsIsUTlWmyEo9zstL3A7RgXpEoaaZrG8HYlS9a0uvQ=; b=JglSAlvkoT93jFng1mXI8Xf/zFG0jlpT/jwqUNY06+Ky3te+1WrjDQoGWJJjH5fql9GSMj h5e2dRXcLcYqPR9CU8ZgD/UNomBHM5nzrk9tCnY+pjJLRzoLPXKrTJHDij9bprbOacnKl9 kTnDQ8lbyzgYbJODEX/8k+VoimWaN2Gpyk9mYnFF2HGiQ0ho3n2iIm2AF16EOaVEhWSpCw RG1lRoSLSdR/Zm6xlFvVOgAnWKkVS9wG9hJu4uIEyMFj7gdjS0GhsVj1QotpxUnPBD2UYT 6iNCFD4beXzfjJa6QseP+mD3THhlekOzpCqrPMDVewbeQp7bYoB5exkotgE4Ww== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041501; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=dPsIsUTlWmyEo9zstL3A7RgXpEoaaZrG8HYlS9a0uvQ=; b=RI0AvfYJNxBkTf4pYxjTYuca9HBGvMWiBuMSms34qGjav9Ed8HKwEQChZqwifhcu+7/Pkb VEEYQ08eMz1bSTDw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 28/33] PCI/MSI: Provide IMS (Interrupt Message Store) support References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:21 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117575790233849?= X-GMAIL-MSGID: =?utf-8?q?1750117575790233849?= IMS (Interrupt Message Store) is a new specification which allows implementation specific storage of MSI messages contrary to the strict standard specified MSI and MSI-X message stores. This requires new device specific interrupt domains to handle the implementation defined storage which can be an array in device memory or host/guest memory which is shared with hardware queues. Add a function to create IMS domains for PCI devices. IMS domains are using the new per device domain mechanism and are configured by the device driver via a template. IMS domains are created as secondary device domains so they work side on side with MSI[-X] on the same device. The IMS domains have a few constraints: - The index space is managed by the core code. Device memory based IMS provides a storage array with a fixed size which obviously requires an index. But there is no association between index and functionality so the core can randomly allocate an index in the array. Queue memory based IMS does not have the concept of an index as the storage is somewhere in memory. In that case the index is purely software based to keep track of the allocations. - There is no requirement for consecutive index ranges This is currently a limitation of the MSI core and can be implemented if there is a justified use case by changing the internal storage from xarray to maple_tree. For now it's single vector allocation. - The interrupt chip must provide the following callbacks: - irq_mask() - irq_unmask() - irq_write_msi_msg() - The interrupt chip must provide the following optional callbacks when the irq_mask(), irq_unmask() and irq_write_msi_msg() callbacks cannot operate directly on hardware, e.g. in the case that the interrupt message store is in queue memory: - irq_bus_lock() - irq_bus_unlock() These callbacks are invoked from preemptible task context and are allowed to sleep. In this case the mandatory callbacks above just store the information. The irq_bus_unlock() callback is supposed to make the change effective before returning. - Interrupt affinity setting is handled by the underlying parent interrupt domain and communicated to the IMS domain via irq_write_msi_msg(). IMS domains cannot have a irq_set_affinity() callback. That's a reasonable restriction similar to the PCI/MSI device domain implementations. The domain is automatically destroyed when the PCI device is removed. Signed-off-by: Thomas Gleixner --- drivers/pci/msi/irqdomain.c | 59 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 5 +++ 2 files changed, 64 insertions(+) --- a/drivers/pci/msi/irqdomain.c +++ b/drivers/pci/msi/irqdomain.c @@ -355,6 +355,65 @@ bool pci_msi_domain_supports(struct pci_ return (supported & feature_mask) == feature_mask; } +/** + * pci_create_ims_domain - Create a secondary IMS domain for a PCI device + * @pdev: The PCI device to operate on + * @template: The MSI info template which describes the domain + * @hwsize: The size of the hardware entry table or 0 if the domain + * is purely software managed + * @data: Optional pointer to domain specific data to be stored + * in msi_domain_info::data + * + * Return: True on success, false otherwise + * + * An IMS domain is expected to have the following constraints: + * - The index space is managed by the core code + * + * - There is no requirement for consecutive index ranges + * + * - The interrupt chip must provide the following callbacks: + * - irq_mask() + * - irq_unmask() + * - irq_write_msi_msg() + * + * - The interrupt chip must provide the following optional callbacks + * when the irq_mask(), irq_unmask() and irq_write_msi_msg() callbacks + * cannot operate directly on hardware, e.g. in the case that the + * interrupt message store is in queue memory: + * - irq_bus_lock() + * - irq_bus_unlock() + * + * These callbacks are invoked from preemptible task context and are + * allowed to sleep. In this case the mandatory callbacks above just + * store the information. The irq_bus_unlock() callback is supposed + * to make the change effective before returning. + * + * - Interrupt affinity setting is handled by the underlying parent + * interrupt domain and communicated to the IMS domain via + * irq_write_msi_msg(). + * + * The domain is automatically destroyed when the PCI device is removed. + */ +bool pci_create_ims_domain(struct pci_dev *pdev, const struct msi_domain_template *template, + unsigned int hwsize, void *data) +{ + struct irq_domain *domain = dev_get_msi_domain(&pdev->dev); + + if (!domain || !irq_domain_is_msi_parent(domain)) + return -ENOTSUPP; + + if (template->info.bus_token != DOMAIN_BUS_PCI_DEVICE_IMS || + !(template->info.flags & MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS) || + !(template->info.flags & MSI_FLAG_FREE_MSI_DESCS) || + !template->chip.irq_mask || !template->chip.irq_unmask || + !template->chip.irq_write_msi_msg || template->chip.irq_set_affinity) + return -EINVAL; + + return msi_create_device_irq_domain(&pdev->dev, MSI_SECONDARY_DOMAIN, template, + hwsize, data, NULL); +} +EXPORT_SYMBOL_GPL(pci_create_ims_domain); + /* * Users of the generic MSI infrastructure expect a device to have a single ID, * so with DMA aliases we have to pick the least-worst compromise. Devices with --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2487,6 +2487,11 @@ static inline bool pci_is_thunderbolt_at void pci_uevent_ers(struct pci_dev *pdev, enum pci_ers_result err_type); #endif +struct msi_domain_template; + +bool pci_create_ims_domain(struct pci_dev *pdev, const struct msi_domain_template *template, + unsigned int hwsize, void *data); + #include #define pci_printk(level, pdev, fmt, arg...) \ From patchwork Mon Nov 21 14:38:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23840 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1633886wrr; Mon, 21 Nov 2022 06:52:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf5z79/YWRwSW9BnMoO4OAIrvcRjZ0xtrO9WRs3CSRmZ0U07QJSjr/V9yBX5b4nvIneQENWD X-Received: by 2002:a17:902:e3ca:b0:189:870:ef5d with SMTP id r10-20020a170902e3ca00b001890870ef5dmr1751436ple.28.1669042320339; Mon, 21 Nov 2022 06:52:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669042320; cv=none; d=google.com; s=arc-20160816; b=L5QNhQvCRa4Gu2mIIq/rnk/alfhBcxoFWGt/y3/2Smsr9dRYnaFqiZKL0dYOo5m1fl 8b5gP6gCytJ064Q3GVgfSSABCjyq6IErVotw2nx4LHtiZLtR4XWyWHPlrmoPlT43SeNI DiMDsOOqoThiqzKOVNyqXm7aBSDfgM/Qxx/YoC5C8/rB62ae0zeTqpbfVC2Jut+Kg+0o yUWy/LbpMQF/pnfrWhUuk47zru8LWnLy1AuisXRKcyKMLhNvt6SYQng6LUsZnM3Wh4x6 ok+xOs01oqMS1bZZG1WA8nw4xMbAfFwioqJFVCOh8mThUbtFPeVfktl9d3w3jwgdlAjh 0/Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=oTFonI9s2+7/R67swuFjwyJq+l+zO53FG0LUQy4ZgBs=; b=sZjL/Wo+5GEtQhrNJRz+aDD0bq5EaRNe+DQ/LrgyJOzPpJzps376JD3PVosriVokgv PA8ZOxFc+yMxtJ4ySy2UDpHBXiH8MtEB/nkzY3gf3oZFw5ann109h8OZopwnd9xxWap9 9AgpBpdI4voRGqejk/qN6meqPlx7RFxL5kUdX2JIcaDOaH+qlcrraGhQ835eEOs/oxVo PDsGFqqrAMKxT5GuqIPCPbvtA8KCXCuhjkyziDHkT2sw/+Qu/ori2uTFHTShKyz4MLcD eBU9CQzYyBxOh/If4VEyRjxrToWm84Std8MaT2OqR55v3fdF/HEZ2P/IOxVnlcl2A1Ri q9xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mjRAE9vH; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=iG9q5JtZ; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e2-20020aa78242000000b005633766252asi10592428pfn.313.2022.11.21.06.51.46; Mon, 21 Nov 2022 06:52:00 -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=@linutronix.de header.s=2020 header.b=mjRAE9vH; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=iG9q5JtZ; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231929AbiKUOlW (ORCPT + 99 others); Mon, 21 Nov 2022 09:41:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231330AbiKUOjO (ORCPT ); Mon, 21 Nov 2022 09:39:14 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 067A5C8CA4; Mon, 21 Nov 2022 06:38:23 -0800 (PST) Message-ID: <20221121091328.078449899@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041502; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=oTFonI9s2+7/R67swuFjwyJq+l+zO53FG0LUQy4ZgBs=; b=mjRAE9vHso4a6W9Xodl04Js6/meJynxAfTVudocXC11HSo0MKcFfikTU0udFb60x4JnDiG fED3uoOmA1MY7G1C5yU/qtH1Jb315cR8jhj1b0EhDEBwUye/ieoCLXz4YhbXA1IxfN+lMk SkSb5FhZ/Y2yi3irhYltZWdoNTVifGnqXORmrR2i9/CeAl++w/2Cd9Nmvr2L/bcjXNTDmG UjwGX6DVQi2YC9kxUf5IYp/rV/eUkdhEGQvQq8xKW58n0QacKIita8DeksyKJ4+IUDBS4G WIy11i//Q2fM1FBkVV2AaWeuxbGXssnZ7wiJuciQ5qDntl1SQiNacqqldhZxgQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041502; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=oTFonI9s2+7/R67swuFjwyJq+l+zO53FG0LUQy4ZgBs=; b=iG9q5JtZdxyDYLgcIYoaNSVasOHl0ONiqrMnhCZEUgyWtrMhUrEQLFd11pXR1YbuTQ34og eov3F28TNsZedNBg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 29/33] PCI/MSI: Provide pci_ims_alloc/free_irq() References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:22 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117719771135164?= X-GMAIL-MSGID: =?utf-8?q?1750117719771135164?= Single vector allocation which allocates the next free index in the IMS space. The free function releases. All allocated vectors are released also via pci_free_vectors() which is also releasing MSI/MSI-X vectors. Signed-off-by: Thomas Gleixner Acked-by: Bjorn Helgaas --- drivers/pci/msi/api.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 3 +++ 2 files changed, 53 insertions(+) --- a/drivers/pci/msi/api.c +++ b/drivers/pci/msi/api.c @@ -361,6 +361,56 @@ const struct cpumask *pci_irq_get_affini EXPORT_SYMBOL(pci_irq_get_affinity); /** + * pci_ims_alloc_irq - Allocate an interrupt on a PCI/IMS interrupt domain + * @dev: The PCI device to operate on + * @icookie: Pointer to an IMS implementation specific cookie for this + * IMS instance (PASID, queue ID, pointer...). + * The cookie content is copied into the MSI descriptor for the + * interrupt chip callbacks or domain specific setup functions. + * @affdesc: Optional pointer to an interrupt affinity descriptor + * + * There is no index for IMS allocations as IMS is an implementation + * specific storage and does not have any direct associations between + * index, which might be a pure software construct, and device + * functionality. This association is established by the driver either via + * the index - if there is a hardware table - or in case of purely software + * managed IMS implementation the association happens via the + * irq_write_msi_msg() callback of the implementation specific interrupt + * chip, which utilizes the provided @cookie to store the MSI message in + * the appropriate place. + * + * Return: A struct msi_map + * + * On success msi_map::index contains the allocated index (>= 0) and + * msi_map::virq the allocated Linux interrupt number (> 0). + * + * On fail msi_map::index contains the error code and msi_map::virq + * is set to 0. + */ +struct msi_map pci_ims_alloc_irq(struct pci_dev *dev, union msi_instance_cookie *icookie, + const struct irq_affinity_desc *affdesc) +{ + return msi_domain_alloc_irq_at(&dev->dev, MSI_SECONDARY_DOMAIN, MSI_ANY_INDEX, + affdesc, icookie); +} +EXPORT_SYMBOL_GPL(pci_ims_alloc_irq); + +/** + * pci_ims_free_irq - Allocate an interrupt on a PCI/IMS interrupt domain + * which was allocated via pci_ims_alloc_irq() + * @dev: The PCI device to operate on + * @map: A struct msi_map describing the interrupt to free as + * returned from pci_ims_alloc_irq() + */ +void pci_ims_free_irq(struct pci_dev *dev, struct msi_map map) +{ + if (WARN_ON_ONCE(map.index < 0 || !map.virq)) + return; + msi_domain_free_irqs_range(&dev->dev, MSI_SECONDARY_DOMAIN, map.index, map.index); +} +EXPORT_SYMBOL_GPL(pci_ims_free_irq); + +/** * pci_free_irq_vectors() - Free previously allocated IRQs for a device * @dev: the PCI device to operate on * --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2491,6 +2491,9 @@ struct msi_domain_template; bool pci_create_ims_domain(struct pci_dev *pdev, const struct msi_domain_template *template, unsigned int hwsize, void *data); +struct msi_map pci_ims_alloc_irq(struct pci_dev *pdev, union msi_instance_cookie *icookie, + const struct irq_affinity_desc *affdesc); +void pci_ims_free_irq(struct pci_dev *pdev, struct msi_map map); #include From patchwork Mon Nov 21 14:38:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23841 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1634563wrr; Mon, 21 Nov 2022 06:53:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf6sDA64vHTRnrvkqeXgU8HaaF/VCh1eNtBGKKVCebhyYgBYI+6Ib0kJnOM7ZxDl6PSdZ+cq X-Received: by 2002:a17:902:d0d3:b0:186:f1b6:c3dd with SMTP id n19-20020a170902d0d300b00186f1b6c3ddmr11715205pln.20.1669042411450; Mon, 21 Nov 2022 06:53:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669042411; cv=none; d=google.com; s=arc-20160816; b=bLMojJyez+Mq2w9KMG0nE5zae5TNMDdKWvKqyGTiYwhteLIyLAqwP/Uu1G8yEvJoQd oEmK8v09V53/jvPVPC0n1B1SyvJPlGPfK4UnJ6HDy7VgIC7y4lqVXjFKrnxY3IBAVR7Z g7HeOkGh1kHBHhjEmaVlPEDqMTZEXf9vp/4odkDBidjOCfhFrqu7pmW9YTR/YNhQQeP/ LLRny6ybx0CO+2W+LMLZNPn6rzQlaJmST5sC02KyrZEcc3TbQjym4kKsCozeJuPOvUTu m19gNKf185DhPuaIMf5bfi8NTYixGUcEArPyY0GV6EC5keu+EAuc59OU3vwkXkeJxLCT 5niA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=QDMaEx7ktXTUaBjXhcwy3JcriisNhamDQjdxbqkUVcQ=; b=1LN7cdkX5qyRVwB3AoD0fz5oc67eWwK8AU+EhKBWM8HX9UtTyagbJyHzS1WegC+ILY FBf4iNyau/LMfxFioh5S7tbIaF/8+YqvbMKI+4b+bw2PZLR0awX6MamtFz8qUk8AW5wq RNajYcdMaicQijE2dUSQnThA6o8K9xl5B42gAS7zN2gHMWxpI9SJ3m1au6gTRAS2cYn7 4QSltuCwF1accHhFCJyglBfr4L0sTkzf6vW+AHx4un/PRy8u9fvCxVe38sUiOBpoi3cx Y+5MtpsWwgoSCFzd4Ryu8Ex7vacyhbb4VgwIpejiWnRs92FVyGp2t+e6dJCbGRaohCh0 WqsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0U8XVxBR; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=+vKigeOR; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w1-20020aa78581000000b0056c25866e36si10422201pfn.79.2022.11.21.06.53.14; Mon, 21 Nov 2022 06:53:31 -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=@linutronix.de header.s=2020 header.b=0U8XVxBR; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=+vKigeOR; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231938AbiKUOlb (ORCPT + 99 others); Mon, 21 Nov 2022 09:41:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230495AbiKUOjc (ORCPT ); Mon, 21 Nov 2022 09:39:32 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1248BC76AC; Mon, 21 Nov 2022 06:38:25 -0800 (PST) Message-ID: <20221121091328.131771866@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041503; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=QDMaEx7ktXTUaBjXhcwy3JcriisNhamDQjdxbqkUVcQ=; b=0U8XVxBRJ8Vp/L2pbxJS5DkmJ6EglhHxDqHc/FFNSt/z9Z4FW7zwXXFTf0FPzf439iVdsB Vi/OCNdvyipjwXFMBOitBBWNy4808ajkdGXK+CmlMQuw7kBnbuIpJGqY7EbkdxiAx0EXsN py372Iz/61ExERDtt0PTJQtdf5XxwhubaqpQRjrgdY5oiWwZm9pJchwGbyyGhpXnWADmAV ywMOUCJYy5gsLM5QLXsmHabar4bF2357T7+kWqgDO+uhrdQmr0kfzZwSflaB3y1eOiUBbd xSuh9xfuF6Ktgawg/rpmL8w66w5UD91M/99IrMezDnC/70mr7YSz43WeKFR/rQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041503; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=QDMaEx7ktXTUaBjXhcwy3JcriisNhamDQjdxbqkUVcQ=; b=+vKigeORtD6RIyVV9dLEHEachwRvpZSi1kWUpZyKjFTLZUEY67FAAdK/UDwbrEVFi9ASJr kj6KeXgh3eKjG4CQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 30/33] x86/apic/msi: Enable PCI/IMS References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:23 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117815513829388?= X-GMAIL-MSGID: =?utf-8?q?1750117815513829388?= Enable IMS in the domain init and allocation mapping code, but do not enable it on the vector domain as discussed in various threads on LKML. The interrupt remap domains can expand this setting like they do with PCI multi MSI. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/apic/msi.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/arch/x86/kernel/apic/msi.c +++ b/arch/x86/kernel/apic/msi.c @@ -184,6 +184,7 @@ static int x86_msi_prepare(struct irq_do alloc->type = X86_IRQ_ALLOC_TYPE_PCI_MSI; return 0; case DOMAIN_BUS_PCI_DEVICE_MSIX: + case DOMAIN_BUS_PCI_DEVICE_IMS: alloc->type = X86_IRQ_ALLOC_TYPE_PCI_MSIX; return 0; default: @@ -230,6 +231,10 @@ static bool x86_init_dev_msi_info(struct case DOMAIN_BUS_PCI_DEVICE_MSI: case DOMAIN_BUS_PCI_DEVICE_MSIX: break; + case DOMAIN_BUS_PCI_DEVICE_IMS: + if (!(pops->supported_flags & MSI_FLAG_PCI_IMS)) + return false; + break; default: WARN_ON_ONCE(1); return false; From patchwork Mon Nov 21 14:38:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23842 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1635440wrr; Mon, 21 Nov 2022 06:55:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf5wP65XTcwRMRMIRSfiqNEUsnzQ5D5eAo6PKs9Vq54OiOa8qNoF+Lb2mvrCyhFyPyEpDFYR X-Received: by 2002:a17:902:e807:b0:186:fb90:5774 with SMTP id u7-20020a170902e80700b00186fb905774mr112604plg.137.1669042524037; Mon, 21 Nov 2022 06:55:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669042524; cv=none; d=google.com; s=arc-20160816; b=qZB7jW8MXiCg3lu+OSEgGjDEC2sYPrUJYlzFlyAN+qYKqh93jvcu1lf4wHa9i4MEJe WNJakgD6woH6ReOlPk9MB6C/ow44Q2mVHp8QNu35zWosi3gu5QyS6HiS2Nsijr167sKC 9xcKM2pA0RQX85uUHcQCjaAYyM3eRU02rjvGNoJCJGKmkQ3RsqwkA1JDrUllkx7kIznU x5oPCJ7SdQCLduJWtROcEWmhAaNibcXqeceZ0jTk4Aep7m9Xln3hqfPJuKQ+b6UhnI9o g2xkSoWXN0GeGG9VRnf4Qbl6lL5fIvgn2KsM05fD0XJDjFGcjBSjzxlab3TQXgD4lAXx 7DpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=SuhbIxDBU+pgQkYaRbDZDx3XYR1ZMR159u+r/p3oNuI=; b=hCgwQ3G1/KWP7MjRJlgPY9vV0zrJ7vrB0aHjx/W6QnC2ShFUlSPHK4ICE3qXirMZwo NgP+scJhQt1fAVn/d7rk348g+ElrBCT1kw0DNCUusX8XWJkZoBJwxpTuokIW7iVoI5jm cAhqnd9ebwrwbI//3geG3VRisZs7TtB37+uaE0Q6Vbo4fuwOy1HiCO8lbHNgsRG7KtSA 47UQVagCQn2Kl1+rDxyr+iT0nZYZbH7pA9cYUJFrETOXwO5VDvPnP7Z+KH4MwYG9XLZt 36xB9kE/UtwsOpGZiveuOp9/e9frXAdAtzkpGToXqjkzl+Y/nhxZt6T7NFG6L3MnZi/H RQJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1psr2+6P; dkim=neutral (no key) header.i=@linutronix.de header.b=Rn8pzIZk; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o23-20020a63fb17000000b0046f75b665b8si10898210pgh.757.2022.11.21.06.55.06; Mon, 21 Nov 2022 06:55:24 -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=@linutronix.de header.s=2020 header.b=1psr2+6P; dkim=neutral (no key) header.i=@linutronix.de header.b=Rn8pzIZk; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231934AbiKUOlZ (ORCPT + 99 others); Mon, 21 Nov 2022 09:41:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231714AbiKUOjY (ORCPT ); Mon, 21 Nov 2022 09:39:24 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F270EC846A; Mon, 21 Nov 2022 06:38:26 -0800 (PST) Message-ID: <20221121091328.184455059@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=SuhbIxDBU+pgQkYaRbDZDx3XYR1ZMR159u+r/p3oNuI=; b=1psr2+6PEXY3YBQmmhtpss+e/EXa3fcuidPDiz2U/W/zlXsB2qLo8iCUiCbS/WujW3vE+h OXmLxsn8RCKMB14O6J4EekalasMdPu5542sb/8pz9abolCY9H2piNBDYa6c0a7lp+hRzoz fDbLxngNyek74VO0HsgdxY8ojuKCW0YldMTPdi+egcKZDdPxJDvehtF4066jgo1+3juDb8 q2LDrF4ftSwgbcXMmFNKh1gZuUo4Qj8lh64UQF8VFe1V5J6cYYY91uAYV6zLY5eXU/8kZ3 V8wBr9qz0yqwUrtTI6VQ7A7IbugtHPhbhK8pcaAFQlE31nxaTvGPchh741n2TQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=SuhbIxDBU+pgQkYaRbDZDx3XYR1ZMR159u+r/p3oNuI=; b=Rn8pzIZk+L7xOktcHzTRG9gckCOFAhYH4n4XxaFboCMQqeHg4TQPOweQ7JbeSWvSySHefJ N4ipPb0kY1QPg9Aw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 31/33] iommu/vt-d: Enable PCI/IMS References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:24 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117933708714565?= X-GMAIL-MSGID: =?utf-8?q?1750117933708714565?= PCI/IMS works like PCI/MSI-X in the remapping. Just add the feature flag. Signed-off-by: Thomas Gleixner --- drivers/iommu/intel/irq_remapping.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/iommu/intel/irq_remapping.c +++ b/drivers/iommu/intel/irq_remapping.c @@ -1429,7 +1429,9 @@ static const struct irq_domain_ops intel }; static const struct msi_parent_ops dmar_msi_parent_ops = { - .supported_flags = X86_VECTOR_MSI_FLAGS_SUPPORTED | MSI_FLAG_MULTI_PCI_MSI, + .supported_flags = X86_VECTOR_MSI_FLAGS_SUPPORTED | + MSI_FLAG_MULTI_PCI_MSI | + MSI_FLAG_PCI_IMS, .prefix = "IR-", .init_dev_msi_info = msi_parent_init_dev_msi_info, }; From patchwork Mon Nov 21 14:38:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23839 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1633857wrr; Mon, 21 Nov 2022 06:51:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf4T9jTYobs7uZbz85ygEKMMwi2pnC4Di4H2GCEjb1NCqso94VOvfyTCSUDVyeSNlTChLBOi X-Received: by 2002:a17:90a:17cb:b0:218:a9e2:196a with SMTP id q69-20020a17090a17cb00b00218a9e2196amr6913781pja.245.1669042316067; Mon, 21 Nov 2022 06:51:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669042316; cv=none; d=google.com; s=arc-20160816; b=B69COGAI5ezO3w4nDKa0vp0UvRD88Ujpnl3mB3i43RS/3gIUWL0g1jP853W2Rt4MLE YAKd7Y+o7BPRSmmWcAh/MI21fS2LzXkVec6IXv3yvUUu3uMxImRniUDAQs+lgyl6YE/Y KcoK69biEKUEX5I4CdcNNsnnMZJdUO7PPl5fwwBLsE08Yf4xdjD2N4hO+ydAbfoZjdYi SE+bw9o5d6KI/Yez5fGvyuIHTESu5o0cdyGpRGNRjzzXHcMbhYg/5ak3IRSZuMM0T257 0YOcWvdJPtpH7GrkrL8yhiKMKteSBSV8S/lDUFR2Ycmg+OVYIbYk82jSueRNOFHujf1M ZiCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=vuCfp3+0SFn3kyyf+6t5pZzLC+oocOyU3+0CroYzbSc=; b=u1sUfZaKntywtJnp2MXCbj2DLO0s43vuME2RhmsSibsV+mlr2K0ox+ImAvhYgOos7O kMgbOatN3JU8+sZlvwtYCXzseWYLS5N7v+wtLfDpPkYSpN4aJjMxs6kU5Fd6ubABwTQf dXR8aHHLP/KeJoeZaNYS0x5WkOJX0dWQ0g6HZ4kOsq690FLoKjIwCmawQyJxn/2oKmCv eyue2tvaH5MFh5N+XsrNlDYUi3vaiVVgncN1Sb+f/bvx9WkjsCzq8Nr+vywja5sWwUNW AV1LuZGaLG6pwlOkhMcbBzrxS8R3kzEybvXMgP5qrpHzeBUY0PPpR27+209NyBVxfOc9 8ugg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Yg+8EfB0; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=WX0QowPn; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l17-20020a170903121100b00186f9d4400esi12343837plh.346.2022.11.21.06.51.40; Mon, 21 Nov 2022 06:51:56 -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=@linutronix.de header.s=2020 header.b=Yg+8EfB0; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=WX0QowPn; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231944AbiKUOlf (ORCPT + 99 others); Mon, 21 Nov 2022 09:41:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231828AbiKUOj7 (ORCPT ); Mon, 21 Nov 2022 09:39:59 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B808AC80FB; Mon, 21 Nov 2022 06:38:27 -0800 (PST) Message-ID: <20221121091328.236473819@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041506; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=vuCfp3+0SFn3kyyf+6t5pZzLC+oocOyU3+0CroYzbSc=; b=Yg+8EfB0o47msNysn1k4RIEvMk4PKjJ/EtKbJJs1ESh4pVXoedf3RCnlxK7UoYNzCBH+ZZ sxSrNNFNCw6mp8+qeF6Agx990r1jaBUCb2yH8jkV+lmNji6UQejygwaeLxnRelW4NN6elQ 5weU8MGbOqb+MkQGiQPLt05u+IZB0rXS1tFsXgL3PXPU9vRWNvwpkD50aVZAjK1cKIAoYg W0mDC+bCQ8yo9bisVhksFlKTm2qP97tZMZpR9MEelx97xm/TbUgUQu3rQw0dTeRslFiDj0 yhWGNapN+pY5ollPgVE/YHISoAUPWAGdWLMPPldS31l45NEUpOdd/UbLoLpqKQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041506; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=vuCfp3+0SFn3kyyf+6t5pZzLC+oocOyU3+0CroYzbSc=; b=WX0QowPnzLAI27QygZUlE4lr7KZkT5x9fkHH4mm+WN52FVoVpdEy1qoQmRnaf2WZngn660 9yBjskh2q7f1QTDw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 32/33] iommu/amd: Enable PCI/IMS References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:26 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750117715728945802?= X-GMAIL-MSGID: =?utf-8?q?1750117715728945802?= PCI/IMS works like PCI/MSI-X in the remapping. Just add the feature flag. Signed-off-by: Thomas Gleixner --- drivers/iommu/amd/iommu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -3649,7 +3649,9 @@ static struct irq_chip amd_ir_chip = { }; static const struct msi_parent_ops amdvi_msi_parent_ops = { - .supported_flags = X86_VECTOR_MSI_FLAGS_SUPPORTED | MSI_FLAG_MULTI_PCI_MSI, + .supported_flags = X86_VECTOR_MSI_FLAGS_SUPPORTED | + MSI_FLAG_MULTI_PCI_MSI | + MSI_FLAG_PCI_IMS, .prefix = "IR-", .init_dev_msi_info = msi_parent_init_dev_msi_info, }; From patchwork Mon Nov 21 14:38:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 23843 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1636083wrr; Mon, 21 Nov 2022 06:56:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf6rdnPAwwgQ1lhW9OMEf8S9Ul6X7a2MYae2pbxGyHpfJBaXhD4QpuEwjNFKd/CXUkcWLa52 X-Received: by 2002:a63:1859:0:b0:476:c9bd:c0d9 with SMTP id 25-20020a631859000000b00476c9bdc0d9mr2206015pgy.415.1669042616195; Mon, 21 Nov 2022 06:56:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669042616; cv=none; d=google.com; s=arc-20160816; b=ptsH/XOJ8xFF0Rbpqu1u/UTdIL8GNq2XqcW6J4Gwa9q8bnw+flJF5RmGQR2833If0s lFQv3PP+czVKekG4Un3DzpR+wHq12Z5H0Ma1uGFVfZX7yJV0KZktXHou6sARLAylmhSy HMFNMCv2yboTOPmG1OT0UsC0iwpkJMKFCXcGODW3EV3I15EsEUUTcZAusCBWz4qFJXI8 NiSR/tIGhw/n0V+41mpajFwjIFq6Y5Qr+6JsSr2iCc1535lAUmpeojUpAZZHA1U3/FhG Bwzg+bB58+TPLwD7rOE7yzu0cjMSF4CStBQwQBMhdwPfMkyo3bdUleD6i2no4TVeCjIM FLyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=sW8r56oF49A4i8rN512SjZ6u9WBK7UD+PEe8Hh+LXW0=; b=kVSRN1TA+4FYrLX+Rr+UpAPKJa3xgo6hb+1mc4knaVvxveRKU3yKHJmiYq2hfLNn54 2nfsutL1yziUfSEudbG6lgDqd69Tk6Zh9bcSxpGcS7zBuQ2olKaguOtEbDBDl7dHPnpR WRQRVZ5Sl4GULdDelLpCRxuJWKhowMBJ++pRF52VWd9/BAme0VQo79157jIVGKFqyVkA qHmTE8Zc7Q0p5muF6tv3bFIL7ipevwJVU/jFT38u3Jj3gO6msp97REfGbMSS6WFUkRHW Z4UTmE21XMQVP9uBt37eb32V2+PvuxRZHckVOl7i/QOeRWngW5XAmm+7IB6/qyvUxjbE 9jMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SdPw+Wl+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=TiuEbxSx; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qe1-20020a17090b4f8100b00202eab3e1b5si16809332pjb.10.2022.11.21.06.56.40; Mon, 21 Nov 2022 06:56:56 -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=@linutronix.de header.s=2020 header.b=SdPw+Wl+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=TiuEbxSx; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232056AbiKUOmZ (ORCPT + 99 others); Mon, 21 Nov 2022 09:42:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231893AbiKUOkx (ORCPT ); Mon, 21 Nov 2022 09:40:53 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7D75C80FA; Mon, 21 Nov 2022 06:38:29 -0800 (PST) Message-ID: <20221121091328.288703733@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669041507; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=sW8r56oF49A4i8rN512SjZ6u9WBK7UD+PEe8Hh+LXW0=; b=SdPw+Wl+kDHuGGrZ0q/4ybOoO9Hlw7u8mXXfPPS8QTL3b/KW6LnGHkmTWYSsU3vXn7HrsI OhYCSWbbfER3hKvTAf7X+s9eOpGdM9YAOE2Ln+sP1sju/aRSxZsMDKwgPscKLFdQpJm7a7 593nzWy45MdJve5g4/b5OjY/WSz+ERlKIolytlaSlEmA3s70C5maNqP+JH+XONz2OCVyyL jOa2RjOrW87y/ew1q1BFVM1lFSLLHLtvUuph2LnxPZhA7yvlR3uBCz6MJkozcBv7qPkKsZ 5Mv6E7rpiHjMPpdsEmBOSpxEGNcdB4uClVLKCS/KiBn3KVg5U+AdcRkWADolfg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669041507; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=sW8r56oF49A4i8rN512SjZ6u9WBK7UD+PEe8Hh+LXW0=; b=TiuEbxSxnValWkGhp2Z7cDVYyIkNBjyh5r0Mlk08rDRHWt0bi6ZfA4Qpy46f8Rn3KHEPnY xTGuVK7oKkCTZwBw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V2 33/33] irqchip: Add IDXD Interrupt Message Store driver References: <20221121083657.157152924@linutronix.de> MIME-Version: 1.0 Date: Mon, 21 Nov 2022 15:38:27 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1750118030037236360?= X-GMAIL-MSGID: =?utf-8?q?1750118030037236360?= Provide a driver for the Intel IDXD IMS implementation. The implementation uses a large message store array in device memory. The IMS domain implementation is minimal and just provides the required irq_chip callbacks and one domain callback which prepares the MSI descriptor for easy usage in the irq_chip callbacks. The necessary iobase is stored in the irqdomain and the PASID which is required for operation is handed in via msi_instance_cookie in the allocation function. Not much to see here. A few lines of code and a filled in template is all what's needed. Signed-off-by: Thomas Gleixner --- drivers/irqchip/Kconfig | 7 + drivers/irqchip/Makefile | 1 drivers/irqchip/irq-pci-intel-idxd.c | 143 +++++++++++++++++++++++++++++ include/linux/irqchip/irq-pci-intel-idxd.h | 22 ++++ 4 files changed, 173 insertions(+) --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -695,4 +695,11 @@ config SUNPLUS_SP7021_INTC chained controller, routing all interrupt source in P-Chip to the primary controller on C-Chip. +config PCI_INTEL_IDXD_IMS + tristate "Intel IDXD Interrupt Message Store controller" + depends on PCI_MSI + help + Support for Intel IDXD IMS Interrupt Message Store controller + with IMS slot storage in a slot array in device memory + endmenu --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -121,3 +121,4 @@ obj-$(CONFIG_IRQ_IDT3243X) += irq-idt32 obj-$(CONFIG_APPLE_AIC) += irq-apple-aic.o obj-$(CONFIG_MCHP_EIC) += irq-mchp-eic.o obj-$(CONFIG_SUNPLUS_SP7021_INTC) += irq-sp7021-intc.o +obj-$(CONFIG_PCI_INTEL_IDXD_IMS) += irq-pci-intel-idxd.o --- /dev/null +++ b/drivers/irqchip/irq-pci-intel-idxd.c @@ -0,0 +1,143 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Interrupt chip and domain for Intel IDXD with hardware array based + * interrupt message store (IMS). + */ +#include +#include +#include +#include +#include + +#include + +MODULE_LICENSE("GPL"); + +/** + * struct ims_slot - The hardware layout of a slot in the memory table + * @address_lo: Lower 32bit address + * @address_hi: Upper 32bit address + * @data: Message data + * @ctrl: Control word + */ +struct ims_slot { + u32 address_lo; + u32 address_hi; + u32 data; + u32 ctrl; +} __packed; + +/* Bit to mask the interrupt in the control word */ +#define CTRL_VECTOR_MASKBIT BIT(0) +/* Bit to enable PASID in the control word */ +#define CTRL_PASID_ENABLE BIT(3) +/* Position of PASID.LSB in the control word */ +#define CTRL_PASID_SHIFT 12 + +static inline void iowrite32_and_flush(u32 value, void __iomem *addr) +{ + iowrite32(value, addr); + ioread32(addr); +} + +static void idxd_mask(struct irq_data *data) +{ + struct msi_desc *desc = irq_data_get_msi_desc(data); + struct ims_slot __iomem *slot = desc->data.dcookie.iobase; + u32 cval = (u32)desc->data.icookie.value; + + iowrite32_and_flush(cval | CTRL_VECTOR_MASKBIT, &slot->ctrl); +} + +static void idxd_unmask(struct irq_data *data) +{ + struct msi_desc *desc = irq_data_get_msi_desc(data); + struct ims_slot __iomem *slot = desc->data.dcookie.iobase; + u32 cval = (u32)desc->data.icookie.value; + + iowrite32_and_flush(cval, &slot->ctrl); +} + +static void idxd_write_msi_msg(struct irq_data *data, struct msi_msg *msg) +{ + struct msi_desc *desc = irq_data_get_msi_desc(data); + struct ims_slot __iomem *slot = desc->data.dcookie.iobase; + + iowrite32(msg->address_lo, &slot->address_lo); + iowrite32(msg->address_hi, &slot->address_hi); + iowrite32_and_flush(msg->data, &slot->data); +} + +static void idxd_shutdown(struct irq_data *data) +{ + struct msi_desc *desc = irq_data_get_msi_desc(data); + struct ims_slot __iomem *slot = desc->data.dcookie.iobase; + + iowrite32(0, &slot->address_lo); + iowrite32(0, &slot->address_hi); + iowrite32(0, &slot->data); + iowrite32_and_flush(CTRL_VECTOR_MASKBIT, &slot->ctrl); +} + +static void idxd_prepare_desc(struct irq_domain *domain, msi_alloc_info_t *arg, + struct msi_desc *desc) +{ + struct msi_domain_info *info = domain->host_data; + struct ims_slot __iomem *slot; + + /* Set up the slot address for the irq_chip callbacks */ + slot = (__force struct ims_slot __iomem *) info->data; + slot += desc->msi_index; + desc->data.dcookie.iobase = slot; + + /* Mask the interrupt for paranoia sake */ + iowrite32_and_flush(CTRL_VECTOR_MASKBIT, &slot->ctrl); + + /* + * The caller provided PASID. Shift it to the proper position + * and set the PASID enable bit. + */ + desc->data.icookie.value <<= CTRL_PASID_SHIFT; + desc->data.icookie.value |= CTRL_PASID_ENABLE; + + arg->hwirq = desc->msi_index; +} + +static const struct msi_domain_template idxd_ims_template = { + .chip = { + .name = "PCI-IDXD", + .irq_mask = idxd_mask, + .irq_unmask = idxd_unmask, + .irq_write_msi_msg = idxd_write_msi_msg, + .irq_shutdown = idxd_shutdown, + .flags = IRQCHIP_ONESHOT_SAFE, + }, + + .ops = { + .prepare_desc = idxd_prepare_desc, + }, + + .info = { + .flags = MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS | + MSI_FLAG_FREE_MSI_DESCS | + MSI_FLAG_PCI_IMS, + .bus_token = DOMAIN_BUS_PCI_DEVICE_IMS, + }, +}; + +/** + * pci_intel_idxd_create_ims_domain - Create a IDXD IMS domain + * @pdev: IDXD PCI device to operate on + * @slots: Pointer to the mapped slot memory arrray + * @nr_slots: The number of slots in the array + * + * Returns: True on success, false otherwise + * + * The domain is automatically destroyed when the @pdev is destroyed + */ +bool pci_intel_idxd_create_ims_domain(struct pci_dev *pdev, void __iomem *slots, + unsigned int nr_slots) +{ + return pci_create_ims_domain(pdev, &idxd_ims_template, nr_slots, (__force void *)slots); +} +EXPORT_SYMBOL_GPL(pci_intel_idxd_create_ims_domain); --- /dev/null +++ b/include/linux/irqchip/irq-pci-intel-idxd.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* (C) Copyright 2022 Thomas Gleixner */ + +#ifndef _LINUX_IRQCHIP_IRQ_PCI_INTEL_IDXD_H +#define _LINUX_IRQCHIP_IRQ_PCI_INTEL_IDXD_H + +#include +#include +#include + +/* + * Conveniance macro to wrap the PASID for interrupt allocation + * via pci_ims_alloc_irq(pdev, INTEL_IDXD_DEV_COOKIE(pasid)) + */ +#define INTEL_IDXD_DEV_COOKIE(pasid) (union msi_instance_cookie) { .value = (pasid), } + +struct pci_dev; + +bool pci_intel_idxd_create_ims_domain(struct pci_dev *pdev, void __iomem *slots, + unsigned int nr_slots); + +#endif