From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19937C38BE5 for ; Mon, 24 Feb 2020 18:24:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CC35921775 for ; Mon, 24 Feb 2020 18:24:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="hQ7R/j32" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC35921775 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5A7986B0036; Mon, 24 Feb 2020 13:24:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 556C96B0037; Mon, 24 Feb 2020 13:24:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41F8F6B006C; Mon, 24 Feb 2020 13:24:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0241.hostedemail.com [216.40.44.241]) by kanga.kvack.org (Postfix) with ESMTP id 27AD56B0036 for ; Mon, 24 Feb 2020 13:24:38 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C8313181AC9CC for ; Mon, 24 Feb 2020 18:24:37 +0000 (UTC) X-FDA: 76525846194.28.nerve66_628d6cc978862 X-HE-Tag: nerve66_628d6cc978862 X-Filterd-Recvd-Size: 5950 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Mon, 24 Feb 2020 18:24:37 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id e8so11577359wrm.5 for ; Mon, 24 Feb 2020 10:24:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5ke1+5YSOcxDNzSzBBGnaN+kOVlCxvSlETx/6pQryQw=; b=hQ7R/j32SLrNiw6cB+MKzedjV5jb7wC2uDlPXljxSGn/Mm+e8K6vJRpSEh03PvC4u9 6SWVO6jkqy8f1MhFEXuwvn5CVzySq1eAR0OMIHnH231Ilx59ro788ZXbVKhAb08vEu3x 2DRDRX3reoEDjA1nXPvHdhi3NlMMHALRilHOP4FbegQ6bDl+MXF72BSCvs01Iga0ey/V lRA5BpuJcyT4Bo+4XEn4NxJCsLV3waRxK/XqqsUDdfn1vY0NKse5RC5ThKKbEOiOSL6S WBTlf6zQcjBQmTv4KAcSJKa3LHmn9N03VuV6CMiAjWvmhiZgf7OibmnfYlq8z45tqDXq +QmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5ke1+5YSOcxDNzSzBBGnaN+kOVlCxvSlETx/6pQryQw=; b=ZtyCvWmlYRWbzW8HeSj8dkSofqy9phiY5pJkmgfUjuA+rj5V7eMr0ta1+gurTviRsa fzQbzidr42LV0IOD22pIiXXs4AzwLFddkw6pGTcWr6ZOKovGyw/ICi+8UMFRiqpsRwu8 kbFwEw2jRJFcGz8csYjb9uK/17pYdyT1EGBvEn8VVk48PSN/BZvx+7vNY2W3kFbCskNB /Sfy6/QedAMpDNH1V9bcvaybCrJG7EcvxrgtbvRHiWFdS4b9fdbhPkoWHBb5eL99B9TV 9FTnr87mWtCZHCTCOlce/hGzRZGsLB9jYVgtpD/ILAgO6LJbP55kGmz3BpruI8TcmuiL 2OIA== X-Gm-Message-State: APjAAAXsbE4qNGCQ8sJdozZtWqEXBM+iRONBTzFqeq/wFFn000eral2m 2x6RdngJiq8fQhY6h2S7T+dvWw== X-Google-Smtp-Source: APXvYqxKuED5BtGA+H9sncjVVYaPSWdkOdWHekAifEqs9Cn+ZBcftrmVm7FgSaad06EVLWBinDxKzg== X-Received: by 2002:adf:df83:: with SMTP id z3mr67641748wrl.389.1582568676229; Mon, 24 Feb 2020 10:24:36 -0800 (PST) Received: from localhost.localdomain ([2001:171b:c9a8:fbc0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id n3sm304255wmc.27.2020.02.24.10.24.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2020 10:24:35 -0800 (PST) From: Jean-Philippe Brucker To: iommu@lists.linux-foundation.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-mm@kvack.org Cc: joro@8bytes.org, robh+dt@kernel.org, mark.rutland@arm.com, catalin.marinas@arm.com, will@kernel.org, robin.murphy@arm.com, kevin.tian@intel.com, baolu.lu@linux.intel.com, Jonathan.Cameron@huawei.com, jacob.jun.pan@linux.intel.com, christian.koenig@amd.com, yi.l.liu@intel.com, zhangfei.gao@linaro.org, Jean-Philippe Brucker Subject: [PATCH v4 06/26] iommu/sva: Register page fault handler Date: Mon, 24 Feb 2020 19:23:41 +0100 Message-Id: <20200224182401.353359-7-jean-philippe@linaro.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200224182401.353359-1-jean-philippe@linaro.org> References: <20200224182401.353359-1-jean-philippe@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: From: Jean-Philippe Brucker When enabling SVA, register the fault handler. Device driver will registe= r an I/O page fault queue before or after calling iommu_sva_enable. The fault queue must be flushed before any io_mm is freed, to make sure that its PASID isn't used in any fault queue, and can be reallocated. Add iopf_queue_flush() calls in a few strategic locations. Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/Kconfig | 1 + drivers/iommu/iommu-sva.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index e4a42e1708b4..211684e785ea 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -106,6 +106,7 @@ config IOMMU_DMA config IOMMU_SVA bool select IOASID + select IOMMU_PAGE_FAULT select IOMMU_API select MMU_NOTIFIER =20 diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c index bfd0c477f290..494ca0824e4b 100644 --- a/drivers/iommu/iommu-sva.c +++ b/drivers/iommu/iommu-sva.c @@ -366,6 +366,8 @@ static void io_mm_release(struct mmu_notifier *mn, st= ruct mm_struct *mm) dev_WARN(dev, "possible leak of PASID %u", io_mm->pasid); =20 + iopf_queue_flush_dev(dev, io_mm->pasid); + /* unbind() frees the bond, we just detach it */ io_mm_detach_locked(bond); } @@ -442,11 +444,20 @@ static void iommu_sva_unbind_locked(struct iommu_bo= nd *bond) =20 void iommu_sva_unbind_generic(struct iommu_sva *handle) { + int pasid; struct iommu_param *param =3D handle->dev->iommu_param; =20 if (WARN_ON(!param)) return; =20 + /* + * Caller stopped the device from issuing PASIDs, now make sure they ar= e + * out of the fault queue. + */ + pasid =3D iommu_sva_get_pasid_generic(handle); + if (pasid !=3D IOMMU_PASID_INVALID) + iopf_queue_flush_dev(handle->dev, pasid); + mutex_lock(¶m->sva_lock); mutex_lock(&iommu_sva_lock); iommu_sva_unbind_locked(to_iommu_bond(handle)); @@ -484,6 +495,10 @@ int iommu_sva_enable(struct device *dev, struct iomm= u_sva_param *sva_param) goto err_unlock; } =20 + ret =3D iommu_register_device_fault_handler(dev, iommu_queue_iopf, dev)= ; + if (ret) + goto err_unlock; + dev->iommu_param->sva_param =3D new_param; mutex_unlock(¶m->sva_lock); return 0; @@ -521,6 +536,7 @@ int iommu_sva_disable(struct device *dev) goto out_unlock; } =20 + iommu_unregister_device_fault_handler(dev); kfree(param->sva_param); param->sva_param =3D NULL; out_unlock: --=20 2.25.0