linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Tian, Kevin" <kevin.tian@intel.com>
To: Lu Baolu <baolu.lu@linux.intel.com>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"Raj, Ashok" <ashok.raj@intel.com>,
	"Jiang, Dave" <dave.jiang@intel.com>,
	"Dey, Megha" <megha.dey@intel.com>,
	"dwmw2@infradead.org" <dwmw2@infradead.org>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"rafael@kernel.org" <rafael@kernel.org>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	"Kumar, Sanjay K" <sanjay.k.kumar@intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"bhelgaas@google.com" <bhelgaas@google.com>,
	"kwankhede@nvidia.com" <kwankhede@nvidia.com>,
	"will@kernel.org" <will@kernel.org>,
	"leon@kernel.org" <leon@kernel.org>,
	"netanelg@mellanox.com" <netanelg@mellanox.com>,
	"maz@kernel.org" <maz@kernel.org>,
	"vkoul@kernel.org" <vkoul@kernel.org>,
	"jgg@mellanox.com" <jgg@mellanox.com>,
	"yan.y.zhao@linux.intel.com" <yan.y.zhao@linux.intel.com>,
	"shahafs@mellanox.com" <shahafs@mellanox.com>,
	"parav@mellanox.com" <parav@mellanox.com>,
	"alex.williamson@redhat.com" <alex.williamson@redhat.com>,
	"Ortiz, Samuel" <samuel.ortiz@intel.com>,
	"Williams, Dan J" <dan.j.williams@intel.com>,
	"Luck, Tony" <tony.luck@intel.com>,
	"Hossain, Mona" <mona.hossain@intel.com>,
	"iommu@lists.linux-foundation.org"
	<iommu@lists.linux-foundation.org>,
	"Pan, Jacob jun" <jacob.jun.pan@intel.com>,
	"dmaengine@vger.kernel.org" <dmaengine@vger.kernel.org>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"Woodhouse, David" <dwmw@amazon.co.uk>
Subject: RE: [RFC PATCH v3 2/2] platform-msi: Add platform check for subdevice irq domain
Date: Thu, 14 Jan 2021 03:03:52 +0000	[thread overview]
Message-ID: <BN6PR11MB18758E47B2CC114E0AE3CD578CA80@BN6PR11MB1875.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20210114013003.297050-3-baolu.lu@linux.intel.com>

> From: Lu Baolu
> Sent: Thursday, January 14, 2021 9:30 AM
> 
> The pci_subdevice_msi_create_irq_domain() should fail if the underlying
> platform is not able to support IMS (Interrupt Message Storage). Otherwise,
> the isolation of interrupt is not guaranteed.
> 
> For x86, IMS is only supported on bare metal for now. We could enable it
> in the virtualization environments in the future if interrupt HYPERCALL
> domain is supported or the hardware has the capability of interrupt
> isolation for subdevices.
> 
> Cc: David Woodhouse <dwmw@amazon.co.uk>
> Cc: Leon Romanovsky <leon@kernel.org>
> Cc: Kevin Tian <kevin.tian@intel.com>
> Suggested-by: Thomas Gleixner <tglx@linutronix.de>
> Link: https://lore.kernel.org/linux-
> pci/87pn4nk7nn.fsf@nanos.tec.linutronix.de/
> Link: https://lore.kernel.org/linux-
> pci/877dqrnzr3.fsf@nanos.tec.linutronix.de/
> Link: https://lore.kernel.org/linux-
> pci/877dqqmc2h.fsf@nanos.tec.linutronix.de/
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> ---
>  arch/x86/pci/common.c       | 71
> +++++++++++++++++++++++++++++++++++++
>  drivers/base/platform-msi.c |  8 +++++
>  include/linux/msi.h         |  1 +
>  3 files changed, 80 insertions(+)
> 
> diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c
> index 3507f456fcd0..9deb826fb242 100644
> --- a/arch/x86/pci/common.c
> +++ b/arch/x86/pci/common.c
> @@ -12,6 +12,7 @@
>  #include <linux/init.h>
>  #include <linux/dmi.h>
>  #include <linux/slab.h>
> +#include <linux/iommu.h>
> 
>  #include <asm/acpi.h>
>  #include <asm/segment.h>
> @@ -724,3 +725,73 @@ struct pci_dev *pci_real_dma_dev(struct pci_dev
> *dev)
>  	return dev;
>  }
>  #endif
> +
> +/*
> + * We want to figure out which context we are running in. But the hardware
> + * does not introduce a reliable way (instruction, CPUID leaf, MSR, whatever)
> + * which can be manipulated by the VMM to let the OS figure out where it
> runs.
> + * So we go with the below probably on_bare_metal() function as a
> replacement
> + * for definitely on_bare_metal() to go forward only for the very simple
> reason
> + * that this is the only option we have.
> + */
> +static const char * const vmm_vendor_name[] = {
> +	"QEMU", "Bochs", "KVM", "Xen", "VMware", "VMW", "VMware Inc.",
> +	"innotek GmbH", "Oracle Corporation", "Parallels", "BHYVE"
> +};
> +
> +static void read_type0_virtual_machine(const struct dmi_header *dm, void
> *p)
> +{
> +	u8 *data = (u8 *)dm + 0x13;
> +
> +	/* BIOS Information (Type 0) */
> +	if (dm->type != 0 || dm->length < 0x14)
> +		return;
> +
> +	/* Bit 4 of BIOS Characteristics Extension Byte 2*/
> +	if (*data & BIT(4))
> +		*((bool *)p) = true;
> +}
> +
> +static bool smbios_virtual_machine(void)
> +{
> +	bool bit_present = false;
> +
> +	dmi_walk(read_type0_virtual_machine, &bit_present);
> +
> +	return bit_present;
> +}
> +
> +static bool on_bare_metal(struct device *dev)
> +{
> +	int i;
> +
> +	if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
> +		return false;
> +
> +	if (smbios_virtual_machine())
> +		return false;
> +
> +	if (iommu_capable(dev->bus, IOMMU_CAP_VIOMMU))
> +		return false;
> +
> +	for (i = 0; i < ARRAY_SIZE(vmm_vendor_name); i++)
> +		if (dmi_match(DMI_SYS_VENDOR, vmm_vendor_name[i]))
> +			return false;

Thinking more I wonder whether this check is actually useful here. As Leon
and David commented, the same vendor name can be used both for VM
and bare metal instances. It implies that both bare metal and VM might be
misinterpreted with this check. This might not be what we want originally -
find heuristics to indicate a VM environment and tolerate misinterpreting 
VM as bare metal in corner cases (but not vice versa).

Thomas?

Thanks
Kevin


      reply	other threads:[~2021-01-14  3:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-14  1:30 [RFC PATCH v3 0/2] Add platform check for subdevice irq domain Lu Baolu
2021-01-14  1:30 ` [RFC PATCH v3 1/2] iommu: Add capability IOMMU_CAP_VIOMMU Lu Baolu
2021-01-14 13:26   ` Leon Romanovsky
2021-01-14 23:49     ` Lu Baolu
2021-01-15  6:31       ` Leon Romanovsky
2021-01-16  1:20         ` Lu Baolu
2021-01-16  8:39           ` Leon Romanovsky
2021-01-16  8:47             ` Lu Baolu
2021-01-17  5:30               ` Leon Romanovsky
2021-01-15  4:46   ` Jason Wang
2021-01-14  1:30 ` [RFC PATCH v3 2/2] platform-msi: Add platform check for subdevice irq domain Lu Baolu
2021-01-14  3:03   ` Tian, Kevin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BN6PR11MB18758E47B2CC114E0AE3CD578CA80@BN6PR11MB1875.namprd11.prod.outlook.com \
    --to=kevin.tian@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=ashok.raj@intel.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=dwmw2@infradead.org \
    --cc=dwmw@amazon.co.uk \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jacob.jun.pan@intel.com \
    --cc=jgg@mellanox.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=megha.dey@intel.com \
    --cc=mona.hossain@intel.com \
    --cc=netanelg@mellanox.com \
    --cc=parav@mellanox.com \
    --cc=pbonzini@redhat.com \
    --cc=rafael@kernel.org \
    --cc=samuel.ortiz@intel.com \
    --cc=sanjay.k.kumar@intel.com \
    --cc=shahafs@mellanox.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=vkoul@kernel.org \
    --cc=will@kernel.org \
    --cc=yan.y.zhao@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).