From patchwork Mon Feb 12 18:33:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 10214527 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 991CE60153 for ; Mon, 12 Feb 2018 21:35:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84F9D28C75 for ; Mon, 12 Feb 2018 21:35:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76A2128D1B; Mon, 12 Feb 2018 21:35:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E234628C75 for ; Mon, 12 Feb 2018 21:35:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2ov/3x9exqXiFVG9nxgWddkw4VYUeolC/8wkBH2RiYE=; b=WrSKrU1b5qRqaOVj7CH5kTSmB4 x0EoMHUR3stehOdJHyr2uUQm+nh4us6cgvK8xxR1m1mptGehhMB9q1N9KST+j9MOZspi3eEcDRgoT mZfMoI3hFoHAMO2k2gfBSRRf2MR4v1IAjp9wZFFn5izwoSpMK0/pjBfTkZnVJYUGSVeRo6fyRgn6G 8C3ShTOfhjxRRmWsdycIXD8suc9WGgsmgDqJ0xYD2wKOmikwCVuZk6p7MrJi1Evcb9Q4OMIsSfmCf HiMowR6/KIFn8vJWKlbjQ7BortlJ0nZR+3N33KcaxujkO4hMeDg4K5Pu1tu2v8JV0oMG4f35DlQMt ZmIYrVRw==; Received: from [198.137.202.133] (helo=bombadil.infradead.org) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1elLkY-0004jh-Kn; Mon, 12 Feb 2018 21:34:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2ov/3x9exqXiFVG9nxgWddkw4VYUeolC/8wkBH2RiYE=; b=RZYbeKVG/DBrfWr5zvwkJPh1QA FCUVoaRGvlhh5PSgsLed8JUTUn6SyrBEmQHmM10+4zZgIvwnL/sF6DNNit3R2zS2KHBr+g7rsOVyx Q5UPbJXNdxE3pbUFME5a3QqLMGFKSCYuy+huJU3d7G9lrQrjnG/eITlW2jZDHKKRfmxKLBB0xHMnh JjtPNUQGUWQ0QfHBY67pdvWz8UDWZ6+eBwdCftlzbYvYSylhPAJYV4tljoFY4KBJiR/IiMB4jitmQ WY5kePirX0RSx/ah5DiHJ0qMDrbe3MfomdqEq8Z0O1r3To+/Lrqdsrlg1JzRIY+v3Xq80DWyatSq9 GDxhjekA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1elIxF-0001lQ-Kn; Mon, 12 Feb 2018 18:35:53 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1elItL-0003De-0i for linux-arm-kernel@lists.infradead.org; Mon, 12 Feb 2018 18:31:54 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CF02C1435; Mon, 12 Feb 2018 10:31:46 -0800 (PST) Received: from e106794-lin.cambridge.arm.com (e106794-lin.cambridge.arm.com [10.1.210.24]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F21243F24D; Mon, 12 Feb 2018 10:31:40 -0800 (PST) From: Jean-Philippe Brucker To: linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org, iommu@lists.linux-foundation.org, kvm@vger.kernel.org Subject: [PATCH 09/37] iommu/fault: Let handler return a fault response Date: Mon, 12 Feb 2018 18:33:24 +0000 Message-Id: <20180212183352.22730-10-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180212183352.22730-1-jean-philippe.brucker@arm.com> References: <20180212183352.22730-1-jean-philippe.brucker@arm.com> X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, xieyisheng1@huawei.com, ilias.apalodimas@linaro.org, catalin.marinas@arm.com, xuzaibo@huawei.com, jonathan.cameron@huawei.com, will.deacon@arm.com, okaya@codeaurora.org, yi.l.liu@intel.com, lorenzo.pieralisi@arm.com, ashok.raj@intel.com, tn@semihalf.com, joro@8bytes.org, bharatku@xilinx.com, rfranz@cavium.com, lenb@kernel.org, jacob.jun.pan@linux.intel.com, alex.williamson@redhat.com, robh+dt@kernel.org, thunder.leizhen@huawei.com, bhelgaas@google.com, shunyong.yang@hxt-semitech.com, dwmw2@infradead.org, liubo95@huawei.com, rjw@rjwysocki.net, jcrouse@codeaurora.org, robdclark@gmail.com, hanjun.guo@linaro.org, sudeep.holla@arm.com, robin.murphy@arm.com, christian.koenig@amd.com, nwatters@codeaurora.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP It is really convenient to let fault handlers return the action to perform on the fault immediately, instead of having to call iommu_page_response with a crafted structure. Update IOMMU_PAGE_RESP* values to encompass most needs: - IOMMU_PAGE_RESP_HANDLED means "I took ownership of the fault and will send a response later" - IOMMU_PAGE_RESP_CONTINUE means "I didn't handle the fault, let the next handler in the chain take care of it" - IOMMU_PAGE_RESP_SUCCESS, IOMMU_PAGE_RESP_INVALID, IOMMU_PAGE_RESP_FAILURE are the PCI PRI values, and mean respectively "fault fixed, retry the translation", "could not fix the fault, abort the translation" and "unexpected fault, disable PRI". Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/io-pgfault.c | 8 +++++++- drivers/iommu/iommu.c | 5 ++++- include/linux/iommu.h | 30 ++++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/io-pgfault.c b/drivers/iommu/io-pgfault.c index 565ec01a1b5f..484a39710d3f 100644 --- a/drivers/iommu/io-pgfault.c +++ b/drivers/iommu/io-pgfault.c @@ -63,6 +63,9 @@ static int iommu_fault_complete(struct iommu_domain *domain, struct device *dev, if (status == IOMMU_PAGE_RESP_HANDLED) return 0; + if (WARN_ON(status == IOMMU_PAGE_RESP_CONTINUE)) + return -EINVAL; + /* * There was an internal error with handling the recoverable fault. Try * to complete the fault if possible. @@ -272,7 +275,10 @@ int iommu_report_device_fault(struct device *dev, struct iommu_fault_event *evt) if (iommu_has_device_fault_handler(dev)) { struct iommu_fault_param *param = dev->iommu_param->fault_param; - return param->handler(evt, param->data); + ret = param->handler(evt, param->data); + if (ret != IOMMU_PAGE_RESP_CONTINUE) + return iommu_fault_complete(domain, dev, evt, ret); + ret = -ENOSYS; } /* If the handler is blocking, handle fault in the workqueue */ diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index c475893ec7dc..9bec8390694c 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -805,7 +805,10 @@ EXPORT_SYMBOL_GPL(iommu_group_unregister_notifier); * @data: private data passed as argument to the callback * * When an IOMMU fault event is received, call this handler with the fault event - * and data as argument. + * and data as argument. If the fault is recoverable (IOMMU_FAULT_PAGE_REQ), the + * handler can either return a status code (IOMMU_PAGE_RESP_*) to complete the + * fault, or return IOMMU_PAGE_RESP_HANDLED and complete the fault later by + * calling iommu_page_response(). * * Return 0 if the fault handler was installed successfully, or an error. */ diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 65e56f28e0ce..d29991be9401 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -189,6 +189,29 @@ enum page_response_type { IOMMU_PAGE_GROUP_RESP, }; +/** + * enum page_response_code - Return status of fault handlers, telling the IOMMU + * driver how to proceed with the fault. + * + * @IOMMU_FAULT_STATUS_HANDLED: Stop processing the fault, and do not send a + * reply to the device. + * @IOMMU_FAULT_STATUS_CONTINUE: Fault was not handled. Call the next handler, + * or terminate. + * @IOMMU_FAULT_STATUS_SUCCESS: Fault has been handled and the page tables + * populated, retry the access. This is "Success" in PCI PRI. + * @IOMMU_FAULT_STATUS_FAILURE: General error. Drop all subsequent faults from + * this device if possible. This is "Response Failure" in PCI PRI. + * @IOMMU_FAULT_STATUS_INVALID: Could not handle this fault, don't retry the + * access. This is "Invalid Request" in PCI PRI. + */ +enum page_response_code { + IOMMU_PAGE_RESP_HANDLED = 0, + IOMMU_PAGE_RESP_CONTINUE, + IOMMU_PAGE_RESP_SUCCESS, + IOMMU_PAGE_RESP_INVALID, + IOMMU_PAGE_RESP_FAILURE, +}; + /** * Generic page response information based on PCI ATS and PASID spec. * @addr: servicing page address @@ -202,12 +225,7 @@ enum page_response_type { struct page_response_msg { u64 addr; u32 pasid; - u32 resp_code:4; -#define IOMMU_PAGE_RESP_SUCCESS 0 -#define IOMMU_PAGE_RESP_INVALID 1 -#define IOMMU_PAGE_RESP_HANDLED 2 -#define IOMMU_PAGE_RESP_FAILURE 0xF - + enum page_response_code resp_code; u32 pasid_present:1; u32 page_req_group_id : 9; enum page_response_type type;