From patchwork Fri May 11 19:06:05 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: 10394855 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 BDFB060540 for ; Fri, 11 May 2018 19:07:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A54BB28581 for ; Fri, 11 May 2018 19:07:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 991342858D; Fri, 11 May 2018 19:07:57 +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=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0057C28F91 for ; Fri, 11 May 2018 19:07:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 868826B0683; Fri, 11 May 2018 15:07:55 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 818C96B0684; Fri, 11 May 2018 15:07:55 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 707D26B0685; Fri, 11 May 2018 15:07:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f70.google.com (mail-oi0-f70.google.com [209.85.218.70]) by kanga.kvack.org (Postfix) with ESMTP id 4907A6B0683 for ; Fri, 11 May 2018 15:07:55 -0400 (EDT) Received: by mail-oi0-f70.google.com with SMTP id j12-v6so3421608oiw.10 for ; Fri, 11 May 2018 12:07:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=J+lZ6VZ7pv4fnArcFHcoMHIRX6P3jVFgjajwGyqHMTc=; b=EP3qsMGiPi39OanI57LYFTqFQLZVsFRkl6f2UgH6MygqcuPTJn1E7W19kdgtAkZ4lI dJGhlPhvJBe1ED97Xf8vd5jjl6I5ZX1e8KfR1/BH0A8l3pPsDxq0gwST/shtFP6oKm1B MqfFOGehJEsl7kQKqlLWiHODpnI2r77U1VLUgaGqA23uJBcvKIWUe8+uYZXiPYgVs/D6 8rdgYXg+W5LNkIuD3DwYDKxZtTtPg4Q/fZ3HqfHeq1hQ3ourK4zAgkQOkbDGZJuaffCc z03ZhlJIGobj+fZOVtijIIKzJPBhrc9YiICzppRbY+eIskxHz1WEPh4jFjqJo0UD5gQz IRYA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jean-philippe.brucker@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jean-philippe.brucker@arm.com X-Gm-Message-State: ALKqPwdrdzb0udSlBGUEEF/PNNIzUJ4RH4RXrjLUsbVw3suiUlD39SP+ H8dlIcNCT5rf9i3Lz9BBeWVYLjhCAelVY+Gf0mWd9akZ7tp6ayoHRY1YQ/FQUnd4ZOcYkEiSCA5 1jZxoY+I2X7hOuIxiEtC1dwkhY2pzTtHeWpyrokHwjLWtrvrBSuYPX0qSmKhAFvyO+w== X-Received: by 2002:a9d:3bf7:: with SMTP id k110-v6mr4515034otc.172.1526065675019; Fri, 11 May 2018 12:07:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrF0y4sSBBUw7zxiE8ZfitNXAyjG1v3X8eXtwjnzNuOTjH64IVP7vrVqZIycZDys4i/HJ5Z X-Received: by 2002:a9d:3bf7:: with SMTP id k110-v6mr4514992otc.172.1526065674258; Fri, 11 May 2018 12:07:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526065674; cv=none; d=google.com; s=arc-20160816; b=RUVm4EWRuz3LOy+aa47Gpax1VNt90XhBs14zSOH+fY8GvxA0atFkasdRhvhf29Yigd fyOUVNNKnk82RAcWIMiMIqa4rBNvb1GZK9Jxkp9JcAgKsiqZZem6EKC6DY/AIvI7fGjf KgyOsV4A4Zlo0XihJYSmr5wHXXn+Xx58QsKm1WRWlI1KJ8YMe6Omd2NIQoW7BXa/qjEu Z9Gd0wH/SpARWf7VfWDFWlhApz+R/wH1GN1NjzbvpEZYwZ8oPNPMWmNr07OOExzkHJJf /FaAau3U9ryHepyBETyjgWveFg4HJx7ak86eTDY1P9dH224fCZCIGROWu2AyZDguELK6 CrMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=J+lZ6VZ7pv4fnArcFHcoMHIRX6P3jVFgjajwGyqHMTc=; b=qJopv9aaelEeKn+ffsnPtqGs+mLuJae7BCkCPiG7q66CxVS5chHE5wy19ZsI7XJ80m 6J37ckjC28Mom3yRvcKaH+i8LsOnAndMRDaI8M3FDGmc/k5ZpAaIOL2Ctw6QQYc3wsXy Uq3fkRzbm/A0LQttidFScHr0Uik+5ZSHJ900pEopGiQbo/KS3dmLPiVrrzC4kMw8eDsO JBk9iVCPN9FY1FR3XqeYBzRbdo+KSNp4fgFwlXY4Pw4cTeAW6K5jviqZwEK2hj202LAb r5aytd8sLX2S+vAcNFIqht4yjZTfadymJA+h21DNuK8janrH6PqSLi7dX+n+NNQdZwbL Gr8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jean-philippe.brucker@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jean-philippe.brucker@arm.com Received: from foss.arm.com (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id w91-v6si1353285otb.77.2018.05.11.12.07.54 for ; Fri, 11 May 2018 12:07:54 -0700 (PDT) Received-SPF: pass (google.com: domain of jean-philippe.brucker@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jean-philippe.brucker@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jean-philippe.brucker@arm.com 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 D65A81713; Fri, 11 May 2018 12:07:53 -0700 (PDT) Received: from ostrya.cambridge.arm.com (ostrya.cambridge.arm.com [10.1.210.33]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 988053F23C; Fri, 11 May 2018 12:07:48 -0700 (PDT) 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, linux-mm@kvack.org Cc: joro@8bytes.org, will.deacon@arm.com, robin.murphy@arm.com, alex.williamson@redhat.com, tn@semihalf.com, liubo95@huawei.com, thunder.leizhen@huawei.com, xieyisheng1@huawei.com, xuzaibo@huawei.com, ilias.apalodimas@linaro.org, jonathan.cameron@huawei.com, liudongdong3@huawei.com, shunyong.yang@hxt-semitech.com, nwatters@codeaurora.org, okaya@codeaurora.org, jcrouse@codeaurora.org, rfranz@cavium.com, dwmw2@infradead.org, jacob.jun.pan@linux.intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kevin.tian@intel.com, baolu.lu@linux.intel.com, robdclark@gmail.com, christian.koenig@amd.com, bharatku@xilinx.com, rgummal@xilinx.com Subject: [PATCH v2 04/40] iommu/sva: Add a mm_exit callback for device drivers Date: Fri, 11 May 2018 20:06:05 +0100 Message-Id: <20180511190641.23008-5-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180511190641.23008-1-jean-philippe.brucker@arm.com> References: <20180511190641.23008-1-jean-philippe.brucker@arm.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP When an mm exits, devices that were bound to it must stop performing DMA on its PASID. Let device drivers register a callback to be notified on mm exit. Add the callback to the sva_param structure attached to struct device. Signed-off-by: Jean-Philippe Brucker --- v1->v2: use iommu_sva_device_init instead of a separate function --- drivers/iommu/iommu-sva.c | 11 ++++++++++- include/linux/iommu.h | 9 +++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c index 6ac679c48f3c..0700893c679d 100644 --- a/drivers/iommu/iommu-sva.c +++ b/drivers/iommu/iommu-sva.c @@ -303,6 +303,7 @@ static void io_mm_detach_locked(struct iommu_bond *bond) * @dev: the device * @features: bitmask of features that need to be initialized * @max_pasid: max PASID value supported by the device + * @mm_exit: callback to notify the device driver of an mm exiting * * Users of the bind()/unbind() API must call this function to initialize all * features required for SVA. @@ -313,13 +314,20 @@ static void io_mm_detach_locked(struct iommu_bond *bond) * description. Setting @max_pasid to a non-zero value smaller than this limit * overrides it. * + * If the driver intends to share process address spaces, it should pass a valid + * @mm_exit handler. Otherwise @mm_exit can be NULL. After @mm_exit returns, the + * device must not issue any more transaction with the PASID given as argument. + * The handler gets an opaque pointer corresponding to the drvdata passed as + * argument of bind(). + * * The device should not be performing any DMA while this function is running, * otherwise the behavior is undefined. * * Return 0 if initialization succeeded, or an error. */ int iommu_sva_device_init(struct device *dev, unsigned long features, - unsigned int max_pasid) + unsigned int max_pasid, + iommu_mm_exit_handler_t mm_exit) { int ret; struct iommu_sva_param *param; @@ -337,6 +345,7 @@ int iommu_sva_device_init(struct device *dev, unsigned long features, param->features = features; param->max_pasid = max_pasid; + param->mm_exit = mm_exit; INIT_LIST_HEAD(¶m->mm_list); /* diff --git a/include/linux/iommu.h b/include/linux/iommu.h index d5f21719a5a0..439c8fffd836 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -61,6 +61,7 @@ struct iommu_fault_event; typedef int (*iommu_fault_handler_t)(struct iommu_domain *, struct device *, unsigned long, int, void *); typedef int (*iommu_dev_fault_handler_t)(struct iommu_fault_event *, void *); +typedef int (*iommu_mm_exit_handler_t)(struct device *dev, int pasid, void *); struct iommu_domain_geometry { dma_addr_t aperture_start; /* First address that can be mapped */ @@ -231,6 +232,7 @@ struct iommu_sva_param { unsigned int min_pasid; unsigned int max_pasid; struct list_head mm_list; + iommu_mm_exit_handler_t mm_exit; }; /** @@ -980,17 +982,20 @@ static inline int iommu_sva_unbind_device(struct device *dev, int pasid) #ifdef CONFIG_IOMMU_SVA extern int iommu_sva_device_init(struct device *dev, unsigned long features, - unsigned int max_pasid); + unsigned int max_pasid, + iommu_mm_exit_handler_t mm_exit); extern int iommu_sva_device_shutdown(struct device *dev); extern int __iommu_sva_bind_device(struct device *dev, struct mm_struct *mm, int *pasid, unsigned long flags, void *drvdata); extern int __iommu_sva_unbind_device(struct device *dev, int pasid); extern void __iommu_sva_unbind_dev_all(struct device *dev); + #else /* CONFIG_IOMMU_SVA */ static inline int iommu_sva_device_init(struct device *dev, unsigned long features, - unsigned int max_pasid) + unsigned int max_pasid, + iommu_mm_exit_handler_t mm_exit) { return -ENODEV; }