Received: from pdx-out-011.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-011.esa.us-west-2.outbound.mail-perimeter.amazon.com [52.35.192.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0090D3AF665 for ; Tue, 26 May 2026 19:24:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.35.192.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779823459; cv=none; b=QLG25q2CauPeXRmmaK/mmCHLTgTzOosh7Q/1Bn/XEZzDVSlcreh3kP4p+HiKyp6nlKQciOCOuIQOFVoEOCZdG3zWDefH4DXos/o/M8BxJRyj6rQEHtcSQIE1gt9Pz9dTSEssf6iZ8QPc/i/I2bpttajbpxI7H464/UO97cSRMjw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779823459; c=relaxed/simple; bh=b7knZEsKgztU7WLv9ZOnwEFzNElW4kOlPx2dOWsnXe0=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=lN8kMOZQ9gHgX30OQI2aT4YbZIXBvuUZF2uPBAG59sTCXrwpkzsFvdF8tyjnnS/aOWneap4itrTYLkCLTkggM6gRvIWiYO+OR//bz2aN84x9o4Xff9uIq6pyc/lfeu8FrzflbzpqKBzCfj5GWY1+8Bjux1MT88SSnNCLIVr9IKg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b=I5cfoJve; arc=none smtp.client-ip=52.35.192.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b="I5cfoJve" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1779823458; x=1811359458; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=dIFTq2/xrr+CIxR+YfNM4pVNUWYzoSduvpea0XgoZPQ=; b=I5cfoJveOy/KGM0iFXyHon6wdICvFAEmx0118f6fRnGdII2o4ecibJG2 lXny7EAkAWsvnp/NENbhun9XJtOsdUZq+eJrAcsO8eu36/77KuQipoP5Z xh8gJzdwxcIRYqTx6iBo969VGyGTdcAfaIAQWcmqDVEfhrC5YdLbn5S+n PEZvTtowPSTtkWrE+ZqADTbNXsm1U8D40/jN9d3hV8T/nsUj2kj8PAvpv caIo3mHj8gAXGslp6+wQ6C1s37RP0gmuM7WRGdA/B6urY98NzYes9MoFE qaVrfxlsCUroqH+ZaahXHxSzEJJ6tN8jWgOP9yD1Hp8Nhidw577wFnOV5 w==; X-CSE-ConnectionGUID: WRN7OjDnSPa39RVebJZ87A== X-CSE-MsgGUID: YajV3FNISHuUQQU1jlPgpw== X-IronPort-AV: E=Sophos;i="6.24,170,1774310400"; d="scan'208";a="20280870" Received: from ip-10-5-12-219.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.12.219]) by internal-pdx-out-011.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2026 19:24:14 +0000 Received: from EX19MTAUWC001.ant.amazon.com [205.251.233.53:5632] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.62.206:2525] with esmtp (Farcaster) id fcdc6c9a-2802-48a0-bdaf-cab70f4081d8; Tue, 26 May 2026 19:24:14 +0000 (UTC) X-Farcaster-Flow-ID: fcdc6c9a-2802-48a0-bdaf-cab70f4081d8 Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.37; Tue, 26 May 2026 19:24:13 +0000 Received: from dev-dsk-gyokhan-1b-83b48b3c.eu-west-1.amazon.com (10.13.234.1) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.37; Tue, 26 May 2026 19:24:11 +0000 From: Gyokhan Kochmarla To: , CC: , , , , , , , Joerg Roedel , Gyokhan Kochmarla Subject: [PATCH 6.12] iommu/vt-d: Draining PRQ in sva unbind path when FPD bit set Date: Tue, 26 May 2026 19:24:01 +0000 Message-ID: <20260526192401.80768-1-gyokhan@amazon.de> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: iommu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D040UWA003.ant.amazon.com (10.13.139.6) To EX19D001UWA001.ant.amazon.com (10.13.138.214) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit From: Lu Baolu commit cf08ca81d08a04b3b304e8fb4e052f323a09783d upstream. When a device uses a PASID for SVA (Shared Virtual Address), it's possible that the PASID entry is marked as non-present and FPD bit set before the device flushes all ongoing DMA requests and removes the SVA domain. This can occur when an exception happens and the process terminates before the device driver stops DMA and calls the iommu driver to unbind the PASID. There's no need to drain the PRQ in the mm release path. Instead, the PRQ will be drained in the SVA unbind path. But in such case, intel_pasid_tear_down_entry() only checks the presence of the pasid entry and returns directly. Add the code to clear the FPD bit and drain the PRQ. Fixes: c43e1ccdebf2 ("iommu/vt-d: Drain PRQs when domain removed from RID") Suggested-by: Kevin Tian Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20241217024240.139615-1-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel Signed-off-by: Gyokhan Kochmarla --- drivers/iommu/intel/pasid.c | 22 +++++++++++++++++++++- drivers/iommu/intel/pasid.h | 6 ++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index 3d1d43675bf2..74be6b547fc0 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -245,11 +245,31 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu, struct device *dev, spin_lock(&iommu->lock); pte = intel_pasid_get_entry(dev, pasid); - if (WARN_ON(!pte) || !pasid_pte_is_present(pte)) { + if (WARN_ON(!pte)) { spin_unlock(&iommu->lock); return; } + if (!pasid_pte_is_present(pte)) { + if (!pasid_pte_is_fault_disabled(pte)) { + WARN_ON(READ_ONCE(pte->val[0]) != 0); + spin_unlock(&iommu->lock); + return; + } + + /* + * When a PASID is used for SVA by a device, it's possible + * that the pasid entry is non-present with the Fault + * Processing Disabled bit set. Clear the pasid entry and + * drain the PRQ for the PASID before return. + */ + pasid_clear_entry(pte); + spin_unlock(&iommu->lock); + intel_iommu_drain_pasid_prq(dev, pasid); + + return; + } + did = pasid_get_domain_id(pte); pgtt = pasid_pte_get_pgtt(pte); pasid_clear_present(pte); diff --git a/drivers/iommu/intel/pasid.h b/drivers/iommu/intel/pasid.h index 55cad7bfa294..8ffb01163f0e 100644 --- a/drivers/iommu/intel/pasid.h +++ b/drivers/iommu/intel/pasid.h @@ -80,6 +80,12 @@ static inline bool pasid_pte_is_present(struct pasid_entry *pte) return READ_ONCE(pte->val[0]) & PASID_PTE_PRESENT; } +/* Get FPD(Fault Processing Disable) bit of a PASID table entry */ +static inline bool pasid_pte_is_fault_disabled(struct pasid_entry *pte) +{ + return READ_ONCE(pte->val[0]) & PASID_PTE_FPD; +} + /* Get PGTT field of a PASID table entry */ static inline u16 pasid_pte_get_pgtt(struct pasid_entry *pte) { -- 2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597