Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1344645ybe; Fri, 13 Sep 2019 15:10:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwEeR96Hx6fhxj6YTYmXhXvdRobQZfB4gpN37M2vnXeQ6VmTJhAF+7gh142R2EnOMDsdVBe X-Received: by 2002:a50:e885:: with SMTP id f5mr49000351edn.163.1568412608255; Fri, 13 Sep 2019 15:10:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568412608; cv=none; d=google.com; s=arc-20160816; b=K1VlFxCDsQCEMQ3tejIcKVkNS7Xsit1Eo426MQCWuc6+m/UeloFfA4woLArxUs9IWB taEn3D4MHurElushxpUYIXemBnMWGBPzW9fdHq2f6vHz9kDKUXrYmzrXeyjF4Fpv+GIe Ol0JxRkj13oAtmbHxofqf5eDal3EaN+y3ipY6AErYdFzBPLzkpicvb0uePCCzigt4mn7 R+EZX+5GJrF3GDs806Zg6i48gD961ndd7ME3tT5YpF7xYfWW6LEfV8CYmJxstowaTJhm uVOY0ZQIG7iRJzJaw/HQi2gcUqg4HGe61XEEEp+uiURsPPxpv+U1PSVZXSbTpn/xdY1D DHsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=AePSMFdBF+tjdZ43JSVTcsUD7kT5TTx2M/ZCiwEQaDw=; b=t7DaxQuoxNeA7UrorHu5A9VVkF6EDeYdza2ICUemEawDwxYYI4z0GFFogvWaGJYXFs gfPoAp0pihZphB9UD4o2Dpjfco6+w2Z4+oQPC1V6HkggpKCuCgH1CWjBVKzsdO+x49Yc rrPDBPQ+oqWWZF994JWZW5+bCX3SR/E64Y6x06noCmG0SMZZNRWFRPtyq4duhdhSnGgm 9QPGoxcGcl7raIBqOTT2uxfCwX54XK1FdpV4iqm6aOuj9IfJ8/VK281ynDJjIZ3QXQc9 Rc8FTm7FP7ZhtU1c72zwnTpZV+gcVi686AHp2vPYSakRsjjf9zNk1IKLMWkYF/3r88lp Lbqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j47si18461084ede.117.2019.09.13.15.09.45; Fri, 13 Sep 2019 15:10:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390378AbfIMWHH convert rfc822-to-8bit (ORCPT + 99 others); Fri, 13 Sep 2019 18:07:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51290 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389689AbfIMWHH (ORCPT ); Fri, 13 Sep 2019 18:07:07 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EC45308FBA9; Fri, 13 Sep 2019 22:07:06 +0000 (UTC) Received: from x1.home (ovpn-118-102.phx2.redhat.com [10.3.118.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1517760BF1; Fri, 13 Sep 2019 22:07:04 +0000 (UTC) Date: Fri, 13 Sep 2019 16:07:04 -0600 From: Alex Williamson To: Megha Dey Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-pci@vger.kernel.org, maz@kernel.org, bhelgaas@google.com, rafael@kernel.org, gregkh@linuxfoundation.org, tglx@linutronix.de, hpa@zytor.com, jgg@mellanox.com, ashok.raj@intel.com, megha.dey@intel.com, jacob.jun.pan@intel.com, Jacob Pan , Sanjay Kumar Subject: Re: [RFC V1 3/7] x86/ims: Add support for a new IMS irq domain Message-ID: <20190913160704.03d4df6c@x1.home> In-Reply-To: <1568338328-22458-4-git-send-email-megha.dey@linux.intel.com> References: <1568338328-22458-1-git-send-email-megha.dey@linux.intel.com> <1568338328-22458-4-git-send-email-megha.dey@linux.intel.com> Organization: Red Hat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 13 Sep 2019 22:07:06 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 12 Sep 2019 18:32:04 -0700 Megha Dey wrote: > This patch adds support for the creation of a new IMS irq domain. It > creates a new irq_chip associated with the IMS domain and adds the > necessary domain operations to it. > > Cc: Jacob Pan > Signed-off-by: Sanjay Kumar > Signed-off-by: Megha Dey > --- > arch/x86/include/asm/msi.h | 4 ++ > arch/x86/kernel/apic/Makefile | 1 + > arch/x86/kernel/apic/ims.c | 93 ++++++++++++++++++++++++++++++++++++++++ > arch/x86/kernel/apic/msi.c | 4 +- > drivers/vfio/mdev/mdev_core.c | 6 +++ > drivers/vfio/mdev/mdev_private.h | 1 - > include/linux/mdev.h | 2 + > 7 files changed, 108 insertions(+), 3 deletions(-) > create mode 100644 arch/x86/kernel/apic/ims.c > > diff --git a/arch/x86/include/asm/msi.h b/arch/x86/include/asm/msi.h > index 25ddd09..51f9d25 100644 > --- a/arch/x86/include/asm/msi.h > +++ b/arch/x86/include/asm/msi.h > @@ -11,4 +11,8 @@ int pci_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec, > > void pci_msi_set_desc(msi_alloc_info_t *arg, struct msi_desc *desc); > > +struct msi_domain_info; > + > +irq_hw_number_t msi_get_hwirq(struct msi_domain_info *info, > + msi_alloc_info_t *arg); > #endif /* _ASM_X86_MSI_H */ > diff --git a/arch/x86/kernel/apic/Makefile b/arch/x86/kernel/apic/Makefile > index a6fcaf16..75a2270 100644 > --- a/arch/x86/kernel/apic/Makefile > +++ b/arch/x86/kernel/apic/Makefile > @@ -12,6 +12,7 @@ obj-y += hw_nmi.o > > obj-$(CONFIG_X86_IO_APIC) += io_apic.o > obj-$(CONFIG_PCI_MSI) += msi.o > +obj-$(CONFIG_MSI_IMS) += ims.o > obj-$(CONFIG_SMP) += ipi.o > > ifeq ($(CONFIG_X86_64),y) > diff --git a/arch/x86/kernel/apic/ims.c b/arch/x86/kernel/apic/ims.c > new file mode 100644 > index 0000000..d9808a5 > --- /dev/null > +++ b/arch/x86/kernel/apic/ims.c > @@ -0,0 +1,93 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright © 2019 Intel Corporation. > + * > + * Author: Megha Dey > + */ > + > +#include > +#include > +#include > +#include > + > +/* > + * Determine if a dev is mdev or not. Return NULL if not mdev device. > + * Return mdev's parent dev if success. > + */ > +static inline struct device *mdev_to_parent(struct device *dev) > +{ > + struct device *ret = NULL; > + struct device *(*fn)(struct device *dev); > + struct bus_type *bus = symbol_get(mdev_bus_type); > + > + if (bus && dev->bus == bus) { > + fn = symbol_get(mdev_dev_to_parent_dev); > + ret = fn(dev); > + symbol_put(mdev_dev_to_parent_dev); > + symbol_put(mdev_bus_type); Leaks a reference to the mdev module if dev->bus != bus. The new version of dev_is_mdev() unconditionally leaks a reference. Thanks, Alex > + } > + > + return ret; > +} > + > +static struct pci_dev *ims_get_pci_dev(struct device *dev) > +{ > + struct pci_dev *pdev; > + > + if (dev_is_mdev(dev)) { > + struct device *parent = mdev_to_parent(dev); > + > + pdev = to_pci_dev(parent); > + } else { > + pdev = to_pci_dev(dev); > + } > + > + return pdev; > +} > + > +int dev_ims_prepare(struct irq_domain *domain, struct device *dev, int nvec, > + msi_alloc_info_t *arg) > +{ > + struct pci_dev *pdev = ims_get_pci_dev(dev); > + > + init_irq_alloc_info(arg, NULL); > + arg->msi_dev = pdev; > + arg->type = X86_IRQ_ALLOC_TYPE_MSIX; > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(dev_ims_prepare); > + > +#ifdef CONFIG_IRQ_REMAP > + > +static struct msi_domain_ops dev_ims_domain_ops = { > + .get_hwirq = msi_get_hwirq, > + .msi_prepare = dev_ims_prepare, > +}; > + > +static struct irq_chip dev_ims_ir_controller = { > + .name = "IR-DEV-IMS", > + .irq_unmask = dev_ims_unmask_irq, > + .irq_mask = dev_ims_mask_irq, > + .irq_ack = irq_chip_ack_parent, > + .irq_retrigger = irq_chip_retrigger_hierarchy, > + .irq_set_vcpu_affinity = irq_chip_set_vcpu_affinity_parent, > + .flags = IRQCHIP_SKIP_SET_WAKE, > + .irq_write_msi_msg = dev_ims_write_msg, > +}; > + > +static struct msi_domain_info ims_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 = &dev_ims_domain_ops, > + .chip = &dev_ims_ir_controller, > + .handler = handle_edge_irq, > + .handler_name = "edge", > +}; > + > +struct irq_domain *arch_create_ims_irq_domain(struct irq_domain *parent) > +{ > + return pci_msi_create_irq_domain(NULL, &ims_ir_domain_info, parent); > +} > + > +#endif > diff --git a/arch/x86/kernel/apic/msi.c b/arch/x86/kernel/apic/msi.c > index 435bcda..65da813 100644 > --- a/arch/x86/kernel/apic/msi.c > +++ b/arch/x86/kernel/apic/msi.c > @@ -84,7 +84,7 @@ void native_teardown_msi_irq(unsigned int irq) > irq_domain_free_irqs(irq, 1); > } > > -static irq_hw_number_t pci_msi_get_hwirq(struct msi_domain_info *info, > +irq_hw_number_t msi_get_hwirq(struct msi_domain_info *info, > msi_alloc_info_t *arg) > { > return arg->msi_hwirq; > @@ -116,7 +116,7 @@ void pci_msi_set_desc(msi_alloc_info_t *arg, struct msi_desc *desc) > EXPORT_SYMBOL_GPL(pci_msi_set_desc); > > static struct msi_domain_ops pci_msi_domain_ops = { > - .get_hwirq = pci_msi_get_hwirq, > + .get_hwirq = msi_get_hwirq, > .msi_prepare = pci_msi_prepare, > .set_desc = pci_msi_set_desc, > }; > diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c > index b558d4c..cecc6a6 100644 > --- a/drivers/vfio/mdev/mdev_core.c > +++ b/drivers/vfio/mdev/mdev_core.c > @@ -33,6 +33,12 @@ struct device *mdev_parent_dev(struct mdev_device *mdev) > } > EXPORT_SYMBOL(mdev_parent_dev); > > +struct device *mdev_dev_to_parent_dev(struct device *dev) > +{ > + return to_mdev_device(dev)->parent->dev; > +} > +EXPORT_SYMBOL(mdev_dev_to_parent_dev); > + > void *mdev_get_drvdata(struct mdev_device *mdev) > { > return mdev->driver_data; > diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h > index 7d92295..c21f130 100644 > --- a/drivers/vfio/mdev/mdev_private.h > +++ b/drivers/vfio/mdev/mdev_private.h > @@ -36,7 +36,6 @@ struct mdev_device { > }; > > #define to_mdev_device(dev) container_of(dev, struct mdev_device, dev) > -#define dev_is_mdev(d) ((d)->bus == &mdev_bus_type) > > struct mdev_type { > struct kobject kobj; > diff --git a/include/linux/mdev.h b/include/linux/mdev.h > index 0ce30ca..9dcbffe 100644 > --- a/include/linux/mdev.h > +++ b/include/linux/mdev.h > @@ -144,5 +144,7 @@ void mdev_unregister_driver(struct mdev_driver *drv); > struct device *mdev_parent_dev(struct mdev_device *mdev); > struct device *mdev_dev(struct mdev_device *mdev); > struct mdev_device *mdev_from_dev(struct device *dev); > +struct device *mdev_dev_to_parent_dev(struct device *dev); > > +#define dev_is_mdev(d) ((d)->bus == symbol_get(mdev_bus_type)) > #endif /* MDEV_H */