Received: by 10.192.165.156 with SMTP id m28csp1134959imm; Mon, 16 Apr 2018 14:52:28 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+cyUCXsQ2mssM/BJRTinB093Kr5eMHaKLwQSsuxziJKFV2cR6BcRcP2QO1KtFECpc6+jH+ X-Received: by 10.99.99.68 with SMTP id x65mr10450180pgb.34.1523915548250; Mon, 16 Apr 2018 14:52:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523915548; cv=none; d=google.com; s=arc-20160816; b=pYLd2tmh6S4XmSQwpE9MJzqifzuO+7rwjxI2LbVdbToe2wt+gwTCTH2Ss0d1Yzm31h P4uwDI5t1FeezMT7G0ycr5F/Gjq2EUI5PjG2TX8HjRONkTzpZGlkra8mT+YqqF4eMIlA 2JgCb8PCo/V79aJlZ/znm3dzNekFLjPB8NKeFJcok8GNH6BO+nxd/PUR6Q+Co/3zqjdI WZDuNv5DbUJg5ZQuTEIYf75W71D3mqigkCl4l9QHf91PZoH/1UAjngsIdvTIxfRBMDxh AJReNcqH7JSywYBHO3pGAmo+3Hb8b0cFravQXOU5aghD0BowlLXfIS0g/qc+8apHlX5x hJIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=QUX6srGcy5lwVAUN3QisN6XvvdB7bEWDPoy60zyTgcU=; b=cU+iDx1kCBMeAeSTiyS6WbZMMjT2kEv6eShYeWL3C2umLs8U+H2XJVEip3aHRtS+yh KJgkDEySDSJ9bP9+an2BAqoTtqpSototJtKgKTAJ8ZOvu52CSJi1zY++5FoFiBqm0b8h Ieh7KZ9E5OZjf9+dLlZ7wcyOPW50PCFdfG8rOFpBPU8hUq80XpJwxXspBk50J5ORkj66 Mv2/WbI9TsXBjP/htca//Hrn6g/vIOcK44KmyepLMO5nzO0+aZSoIeCPYz4Q6frgbFqt FLaEOXm+kCYXBk4fyzlbLNMsHKMkDh6m9++Lof/9xkWLdcGf6KRRMjI+t2iGaeocwI1c P51g== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u17si10052557pgv.383.2018.04.16.14.52.14; Mon, 16 Apr 2018 14:52:28 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753083AbeDPVtM (ORCPT + 99 others); Mon, 16 Apr 2018 17:49:12 -0400 Received: from mga09.intel.com ([134.134.136.24]:12290 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753006AbeDPVqu (ORCPT ); Mon, 16 Apr 2018 17:46:50 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Apr 2018 14:46:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,460,1517904000"; d="scan'208";a="34740188" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga006.jf.intel.com with ESMTP; 16 Apr 2018 14:46:43 -0700 From: Jacob Pan To: iommu@lists.linux-foundation.org, LKML , Joerg Roedel , David Woodhouse , Greg Kroah-Hartman , Alex Williamson , Jean-Philippe Brucker Cc: Rafael Wysocki , "Liu, Yi L" , "Tian, Kevin" , Raj Ashok , Jean Delvare , "Christoph Hellwig" , "Lu Baolu" , Jacob Pan Subject: [PATCH v4 17/22] iommu/intel-svm: report device page request Date: Mon, 16 Apr 2018 14:49:06 -0700 Message-Id: <1523915351-54415-18-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523915351-54415-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1523915351-54415-1-git-send-email-jacob.jun.pan@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the source device of a page request has its PASID table pointer bound 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 reporting API to send fault events, 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. Recoverable faults, such as page request reporting is not limitted to guest use. In kernel driver can also request a chance to receive fault notifications. Signed-off-by: Jacob Pan Signed-off-by: Ashok Raj --- drivers/iommu/intel-svm.c | 73 ++++++++++++++++++++++++++++++++++++++++------- include/linux/iommu.h | 1 + 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c index e8cd984..a8186f8 100644 --- a/drivers/iommu/intel-svm.c +++ b/drivers/iommu/intel-svm.c @@ -577,6 +577,58 @@ static bool is_canonical_address(u64 addr) return (((saddr << shift) >> shift) == saddr); } +static int prq_to_iommu_prot(struct page_req_dsc *req) +{ + int prot = 0; + + if (req->rd_req) + prot |= IOMMU_FAULT_READ; + if (req->wr_req) + prot |= IOMMU_FAULT_WRITE; + if (req->exe_req) + prot |= IOMMU_FAULT_EXEC; + if (req->priv_req) + prot |= IOMMU_FAULT_PRIV; + + return prot; +} + +static int intel_svm_prq_report(struct intel_iommu *iommu, + struct page_req_dsc *desc) +{ + int ret = 0; + struct iommu_fault_event event; + struct pci_dev *pdev; + + memset(&event, 0, sizeof(struct iommu_fault_event)); + pdev = pci_get_domain_bus_and_slot(iommu->segment, + 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; + } + + /* Fill in event data for device specific processing */ + event.type = IOMMU_FAULT_PAGE_REQ; + event.addr = (u64)desc->addr << VTD_PAGE_SHIFT; + event.pasid = desc->pasid; + event.page_req_group_id = desc->prg_index; + event.prot = prq_to_iommu_prot(desc); + event.last_req = desc->lpig; + event.pasid_valid = 1; + /* keep track of PRQ so that when the response comes back, we know + * whether we do group response or stream response. SRR[0] and + * private[54:32] bits in the descriptor are stored. + */ + event.iommu_private = *(u64 *)desc; + ret = iommu_report_device_fault(&pdev->dev, &event); + pci_dev_put(pdev); + + return ret; +} + static irqreturn_t prq_event_thread(int irq, void *d) { struct intel_iommu *iommu = d; @@ -625,6 +677,16 @@ static irqreturn_t prq_event_thread(int irq, void *d) goto no_pasid; } } + /* If address is not canonical, return invalid response */ + if (!is_canonical_address(address)) + goto bad_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_report(iommu, req)) + goto prq_advance; result = QI_RESP_INVALID; /* Since we're using init_mm.pgd directly, we should never take @@ -635,9 +697,6 @@ static irqreturn_t prq_event_thread(int irq, void *d) if (!mmget_not_zero(svm->mm)) goto bad_req; - /* If address is not canonical, return invalid response */ - if (!is_canonical_address(address)) - goto bad_req; down_read(&svm->mm->mmap_sem); vma = find_extend_vma(svm->mm, address); @@ -670,12 +729,6 @@ static irqreturn_t prq_event_thread(int irq, void *d) if (WARN_ON(&sdev->list == &svm->devs)) sdev = NULL; - - if (sdev && sdev->ops && sdev->ops->fault_cb) { - int rwxp = (req->rd_req << 3) | (req->wr_req << 2) | - (req->exe_req << 1) | (req->priv_req); - sdev->ops->fault_cb(sdev->dev, req->pasid, req->addr, req->private, rwxp, result); - } /* We get here in the error case where the PASID lookup failed, and these can be NULL. Do not use them below this point! */ sdev = NULL; @@ -701,7 +754,7 @@ static irqreturn_t prq_event_thread(int irq, void *d) qi_submit_sync(&resp, iommu); } - + prq_advance: head = (head + sizeof(*req)) & PRQ_RING_MASK; } diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 40088d6..0933f72 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -42,6 +42,7 @@ * if the IOMMU page table format is equivalent. */ #define IOMMU_PRIV (1 << 5) +#define IOMMU_EXEC (1 << 6) struct iommu_ops; struct iommu_group; -- 2.7.4