iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Jacob Pan <jacob.jun.pan@linux.intel.com>
Cc: iommu@lists.linux-foundation.org,
	LKML <linux-kernel@vger.kernel.org>,
	Joerg Roedel <joro@8bytes.org>,
	David Woodhouse <dwmw2@infradead.org>,
	"Liu, Yi L" <yi.l.liu@intel.com>,
	Lan Tianyu <tianyu.lan@intel.com>,
	"Tian, Kevin" <kevin.tian@intel.com>,
	Raj Ashok <ashok.raj@intel.com>,
	Jean Delvare <khali@linux-fr.org>
Subject: Re: [RFC 8/9] iommu/intel-svm: notify page request to guest
Date: Thu, 22 Jun 2017 16:53:58 -0600	[thread overview]
Message-ID: <20170622165358.70cfe33b@w520.home> (raw)
In-Reply-To: <1497478983-77580-9-git-send-email-jacob.jun.pan@linux.intel.com>

On Wed, 14 Jun 2017 15:23:02 -0700
Jacob Pan <jacob.jun.pan@linux.intel.com> wrote:

> If the source device of a page request has its PASID table pointer
> bond to a guest, the first level page tables are owned by the guest.
> In this case, we shall let guest OS to manage page fault.
> 
> This patch uses the IOMMU fault notification API to send notifications,
> possibly via VFIO, to the guest OS. Once guest pages are fault in, guest
> will issue page response which will be passed down via the invalidation
> passdown APIs.
> 
> Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
> Signed-off-by: Ashok Raj <ashok.raj@intel.com>
> ---
>  drivers/iommu/intel-svm.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 80 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c
> index 23c4276..d1d2d23 100644
> --- a/drivers/iommu/intel-svm.c
> +++ b/drivers/iommu/intel-svm.c
> @@ -525,6 +525,80 @@ static bool access_error(struct vm_area_struct *vma, struct page_req_dsc *req)
>  	return (requested & ~vma->vm_flags) != 0;
>  }
>  
> +static int prq_to_iommu_prot(struct page_req_dsc *req)
> +{
> +	int prot = 0;
> +
> +	if (req->rd_req)
> +		prot |= IOMMU_READ;
> +	if (req->wr_req)
> +		prot |= IOMMU_WRITE;
> +	if (req->exe_req)
> +		prot |= IOMMU_EXEC;
> +	if (req->priv_req)
> +		prot |= IOMMU_PRIV;
> +
> +	return prot;
> +}
> +
> +static int intel_svm_prq_notify(struct device *dev, struct page_req_dsc *desc)
> +{
> +	int ret = 0;
> +	struct iommu_fault_event *event;
> +	struct pci_dev *pdev;
> +	struct device_domain_info *info;
> +	unsigned long buf_offset;
> +
> +	/**
> +	 * If caller does not provide struct device, this is the case where
> +	 * guest PASID table is bond to the device. So we need to retrieve
> +	 * struct device from the page request deescriptor then proceed.
> +	 */
> +	if (!dev) {
> +		pdev = pci_get_bus_and_slot(desc->bus, desc->devfn);
> +		if (!pdev) {
> +			pr_err("No PCI device found for PRQ [%02x:%02x.%d]\n",
> +				desc->bus, PCI_SLOT(desc->devfn),
> +				PCI_FUNC(desc->devfn));
> +			return -ENODEV;
> +		}
> +		/**
> +		 * Make sure PASID table pointer is bond to guest, if yes notify
> +		 * handler in the guest, e.g. via VFIO.
> +		 */
> +		info = pdev->dev.archdata.iommu;
> +		if (!info || !info->pasid_tbl_bond) {
> +			pr_debug("PRQ device pasid table not bond.\n");

I can "bond" two things together, they are then "bound".

> +			return -EINVAL;
> +		}
> +		dev = &pdev->dev;

Leaks pdev reference.  Both normal and error path.

> +	}
> +
> +	pr_debug("Notify PRQ device [%02x:%02x.%d]\n",
> +		desc->bus, PCI_SLOT(desc->devfn),
> +		PCI_FUNC(desc->devfn));
> +	event = kzalloc(sizeof(*event) + sizeof(*desc), GFP_KERNEL);
> +	if (!event)
> +		return -ENOMEM;
> +
> +	get_device(dev);
> +	/* Fill in event data for device specific processing */
> +	event->dev = dev;
> +	buf_offset = offsetofend(struct iommu_fault_event, length);
> +	memcpy(buf_offset + event, desc, sizeof(*desc));
> +	event->addr = desc->addr;
> +	event->pasid = desc->pasid;
> +	event->prot = prq_to_iommu_prot(desc);
> +	event->length = sizeof(*desc);
> +	event->flags = IOMMU_FAULT_PAGE_REQ;
> +
> +	ret = iommu_fault_notifier_call_chain(event);
> +	put_device(dev);
> +	kfree(event);
> +
> +	return ret;
> +}
> +
>  static irqreturn_t prq_event_thread(int irq, void *d)
>  {
>  	struct intel_iommu *iommu = d;
> @@ -548,7 +622,12 @@ static irqreturn_t prq_event_thread(int irq, void *d)
>  		handled = 1;
>  
>  		req = &iommu->prq[head / sizeof(*req)];
> -
> +		/**
> +		 * If prq is to be handled outside iommu driver via receiver of
> +		 * the fault notifiers, we skip the page response here.
> +		 */
> +		if (!intel_svm_prq_notify(NULL, req))
> +			continue;
>  		result = QI_RESP_FAILURE;
>  		address = (u64)req->addr << VTD_PAGE_SHIFT;
>  		if (!req->pasid_present) {

  reply	other threads:[~2017-06-22 22:53 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-14 22:22 [RFC 0/9] IOMMU driver changes for shared virtual memory virtualization Jacob Pan
2017-06-14 22:22 ` [RFC 4/9] iommu/vt-d: Add iommu do invalidate function Jacob Pan
     [not found]   ` <1497478983-77580-5-git-send-email-jacob.jun.pan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-06-22 22:52     ` Alex Williamson
     [not found] ` <1497478983-77580-1-git-send-email-jacob.jun.pan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-06-14 22:22   ` [RFC 1/9] iommu: Introduce bind_pasid_table API function Jacob Pan
     [not found]     ` <1497478983-77580-2-git-send-email-jacob.jun.pan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-06-22 22:52       ` Alex Williamson
     [not found]         ` <20170622165201.3d8fe75d-DGNDKt5SQtizQB+pC5nmwQ@public.gmane.org>
2017-06-23 18:20           ` Jacob Pan
2017-06-14 22:22   ` [RFC 2/9] iommu/vt-d: add bind_pasid_table function Jacob Pan
     [not found]     ` <1497478983-77580-3-git-send-email-jacob.jun.pan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-06-22 22:52       ` Alex Williamson
     [not found]         ` <20170622165215.5989e02c-DGNDKt5SQtizQB+pC5nmwQ@public.gmane.org>
2017-06-23 18:19           ` Jacob Pan
2017-06-23 18:59             ` Alex Williamson
2017-06-23 20:21               ` Jacob Pan
2017-06-14 22:22   ` [RFC 3/9] iommu: Introduce iommu do invalidate API function Jacob Pan
     [not found]     ` <1497478983-77580-4-git-send-email-jacob.jun.pan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-06-22 22:52       ` Alex Williamson
2017-06-14 22:22   ` [RFC 5/9] iommu: Introduce fault notifier API Jacob Pan
     [not found]     ` <1497478983-77580-6-git-send-email-jacob.jun.pan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-06-22 22:53       ` Alex Williamson
     [not found]         ` <20170622165317.20f3ebde-DGNDKt5SQtizQB+pC5nmwQ@public.gmane.org>
2017-06-23 18:59           ` Jacob Pan
2017-06-23 19:15             ` Alex Williamson
     [not found]               ` <20170623131551.6aeb9af7-DGNDKt5SQtizQB+pC5nmwQ@public.gmane.org>
2017-06-26 15:27                 ` Jacob Pan
2017-06-26 15:32                   ` Alex Williamson
2017-06-14 22:23   ` [RFC 6/9] iommu/vt-d: track device with pasid table bond to a guest Jacob Pan
     [not found]     ` <1497478983-77580-7-git-send-email-jacob.jun.pan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-06-22 22:54       ` Alex Williamson
2017-06-14 22:23   ` [RFC 7/9] iommu/dmar: notify unrecoverable faults Jacob Pan
     [not found]     ` <1497478983-77580-8-git-send-email-jacob.jun.pan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-06-22 22:54       ` Alex Williamson
     [not found]         ` <20170622165416.6ea718f1-DGNDKt5SQtizQB+pC5nmwQ@public.gmane.org>
2017-06-23 20:19           ` Jacob Pan
2017-06-14 22:23   ` [RFC 8/9] iommu/intel-svm: notify page request to guest Jacob Pan
2017-06-22 22:53     ` Alex Williamson [this message]
2017-06-23 20:16       ` Jacob Pan
2017-06-23 20:34         ` Alex Williamson
     [not found]           ` <20170623143434.2473215b-DGNDKt5SQtizQB+pC5nmwQ@public.gmane.org>
2017-06-23 21:33             ` Jacob Pan
2017-06-14 22:23 ` [RFC 9/9] iommu/intel-svm: replace dev ops with generic fault notifier Jacob Pan

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=20170622165358.70cfe33b@w520.home \
    --to=alex.williamson@redhat.com \
    --cc=ashok.raj@intel.com \
    --cc=dwmw2@infradead.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jacob.jun.pan@linux.intel.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=khali@linux-fr.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tianyu.lan@intel.com \
    --cc=yi.l.liu@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).