From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C697731D375 for ; Mon, 23 Mar 2026 18:52:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774291922; cv=none; b=lbiK09cMSR1UBYyeJq/44dPrz/Sn8Z/DBQfgGJlCavUAmtdwfJjwj7A90thc47gRcl+YVoSCy76hpTjtwpFGKcP/r+R/ExdylitLnu9vsg4S6ISR19fpGnpNgz48wZBtrmbSwhlBIm5wySbX/7J15qJsiXDoj5VijzG2s+1YuOA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774291922; c=relaxed/simple; bh=6QaR2oqSKNEPRho9RH+KkOaiYFeaDuoiPM8PClvNLCg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oPyPXqoqKXBMS6ZJQDHwGgASJvaPhqaLFxFYBZgnizXsevuI3/9elYkB/MwWw+AuWgGU1PQ7zgKUrydmJWlZpYuPnItPUqR7Ljsj+gWYniewaptJjJYlNtCIbpLoJjYS/os2ukFfUQ2f1aAesQ6aoEHg2axgWIVlHJYnwB5Ml6Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MVzWSQF/; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MVzWSQF/" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2b052562254so19195ad.0 for ; Mon, 23 Mar 2026 11:52:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774291920; x=1774896720; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=g99lbUMVIyYkGv//TAIg6GhZ5xFInnNUBZAXzDDYysU=; b=MVzWSQF//EYTZzwu2/ftz07BmbsEX4k7uadWjJS7Y71KMSmAM+0Aujr5pFw6CDEzm/ jic1sWe4ieULdPH52EZLo7tCw85VS67GBrh+75dna/VqEenbVSG1OxfoffQml1dgvwn9 ZRx1lcEb/glSINOML8EtCmUvxuuYfxZe4id/1Zus0R52XsO/62ICFUNri01MMQArWIT8 QYhUmetdpePNePg4K+ymPduWdKFM/mFmWBFvJU8Vyd/Lw6/s/Q0m82q4BckOWGZuapNI G8NhH7ffIKaN7y/LSzHFT/2sqXf/7znjdDAqIMxoBDthImYfdACLUi0LpmbY7ogZzFvx jlcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774291920; x=1774896720; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g99lbUMVIyYkGv//TAIg6GhZ5xFInnNUBZAXzDDYysU=; b=rp+RpgjvgRw8+ia4ytADra2HY+SfIzMcBthi4uqypZN8xhwOZGNI56cIu+ik+Fw2MD miTkEU1Spq8YlGhuF8Pfz8JU1QbDD7kPfkWFNvonOgwkW9orMFXC9GeR1nHkoTGYYvtJ Vw7znfIQRlWeBKU+cJsJa6HI9131Ta15nVi7TIV64XOf6HZjAtN5XvfzcYKCnn9GTp02 alEKvPV8dBpUrV/xPTTHXHE7Q7hpySfGr4QhS/SlnTmq3Nc4XUi3pfNB2LVRKWwkiPm7 QOu2LJAgc7xxUNCNcBrcXyDG+vu+NVqQsLko2N77AcfHHNGhLIY5YJT2MZC8TvP4TBtc DuWg== X-Forwarded-Encrypted: i=1; AJvYcCVrcOBolaFBtp8UKhLlZvSZWwIR8sOPvLs25ad9Zt/cqDYIoXtxKwk3TxgysLw5WtOvpFe+z0Ao2unrKyM=@vger.kernel.org X-Gm-Message-State: AOJu0YxplxC/MpiQJTxe4Sihmk/uAFrZ/+m2e6g4WklwG7DjClQpHKO/ s6ppViU0ncPDGj2m904HWr3baUS0ihPebh3+FDgJN4PP3d6G5hlf9U3AwdDVctMj9Q== X-Gm-Gg: ATEYQzzh7G9CeYg7hA4huVb1Ceb42/+W2oOePG+/y4JDiJJDr+pJZNn87OdiWSi78zR fBO0hFn4xFFU0R+RxIV0vBzypDuFexCGZEUsxqAqSMAxS7KHe5/1DVta1OaYKM+LzXoS3xlctF4 D+zMi0kk7/8PK1eg3dNHTrxPpiz6DvE5JKqi+jtTQ4IMEQ6+fikHyDQup+YqVx3ZGrsNvacI0AP qR5gY/Q9XfEvX6tDpYgkr6T1h6s6NmiCrMRU1dT4gkot+mAeLpjNc7q33ePmekw0+xd66fhsG65 +GYyAu/aGE4bSC/Wuk54KhWLNhCMxSAiE6xbL5HLEGikbFWDlcp1oLkgu9rjD21Y2QgJBJnG+AV Oyn+FXV9RzV2cGC+2ibYAGHR19/h4yvWzCFM/6oB9HvAG4mtw92gS80ydNAKg6s9JbHO2dTMfFF ZqobYRfahEiLy/RJ3BSc3YY6/OLtFa09HqCp2+/KOW9cl84oys0EEvK/jPXLW9/w== X-Received: by 2002:a17:902:f94d:b0:2b0:9a61:9d9 with SMTP id d9443c01a7336-2b0a5573ecfmr326635ad.9.1774291919398; Mon, 23 Mar 2026 11:51:59 -0700 (PDT) Received: from google.com (168.136.83.34.bc.googleusercontent.com. [34.83.136.168]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b0836b15fbsm153483935ad.81.2026.03.23.11.51.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 11:51:58 -0700 (PDT) Date: Mon, 23 Mar 2026 18:51:55 +0000 From: Samiullah Khawaja To: Pranjal Shrivastava Cc: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Jason Gunthorpe , Robin Murphy , Kevin Tian , Alex Williamson , Shuah Khan , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Saeed Mahameed , Adithya Jayachandran , Parav Pandit , Leon Romanovsky , William Tu , Pratyush Yadav , Pasha Tatashin , David Matlack , Andrew Morton , Chris Li , Vipin Sharma , YiFei Zhu Subject: Re: [PATCH 09/14] iommu/vt-d: preserve PASID table of preserved device Message-ID: References: <20260203220948.2176157-1-skhawaja@google.com> <20260203220948.2176157-10-skhawaja@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: On Mon, Mar 23, 2026 at 06:19:18PM +0000, Pranjal Shrivastava wrote: >On Tue, Feb 03, 2026 at 10:09:43PM +0000, Samiullah Khawaja wrote: >> In scalable mode the PASID table is used to fetch the io page tables. >> Preserve and restore the PASID table of the preserved devices. >> >> Signed-off-by: Samiullah Khawaja >> --- >> drivers/iommu/intel/iommu.c | 4 +- >> drivers/iommu/intel/iommu.h | 5 ++ >> drivers/iommu/intel/liveupdate.c | 130 +++++++++++++++++++++++++++++++ >> drivers/iommu/intel/pasid.c | 7 +- >> drivers/iommu/intel/pasid.h | 9 +++ >> include/linux/kho/abi/iommu.h | 8 ++ >> 6 files changed, 160 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c >> index 83faad53f247..2d0dae57f5a2 100644 >> --- a/drivers/iommu/intel/iommu.c >> +++ b/drivers/iommu/intel/iommu.c >> @@ -2944,8 +2944,10 @@ static bool __maybe_clean_unpreserved_context_entries(struct intel_iommu *iommu) >> if (info->iommu != iommu) >> continue; >> >> - if (dev_iommu_preserved_state(&pdev->dev)) >> + if (dev_iommu_preserved_state(&pdev->dev)) { >> + pasid_cleanup_preserved_table(&pdev->dev); >> continue; >> + } >> >> domain_context_clear(info); >> } >> diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h >> index 057bd6035d85..d24d6aeaacc0 100644 >> --- a/drivers/iommu/intel/iommu.h >> +++ b/drivers/iommu/intel/iommu.h >> @@ -1286,6 +1286,7 @@ int intel_iommu_preserve(struct iommu_device *iommu, struct iommu_ser *iommu_ser >> void intel_iommu_unpreserve(struct iommu_device *iommu, struct iommu_ser *iommu_ser); >> void intel_iommu_liveupdate_restore_root_table(struct intel_iommu *iommu, >> struct iommu_ser *iommu_ser); >> +void pasid_cleanup_preserved_table(struct device *dev); >> #else >> static inline int intel_iommu_preserve_device(struct device *dev, struct device_ser *device_ser) >> { >> @@ -1309,6 +1310,10 @@ static inline void intel_iommu_liveupdate_restore_root_table(struct intel_iommu >> struct iommu_ser *iommu_ser) >> { >> } >> + >> +static inline void pasid_cleanup_preserved_table(struct device *dev) >> +{ >> +} >> #endif >> >> #ifdef CONFIG_INTEL_IOMMU_SVM >> diff --git a/drivers/iommu/intel/liveupdate.c b/drivers/iommu/intel/liveupdate.c >> index 6dcb5783d1db..53bb5fe3a764 100644 >> --- a/drivers/iommu/intel/liveupdate.c >> +++ b/drivers/iommu/intel/liveupdate.c >> @@ -14,6 +14,7 @@ >> #include >> >> #include "iommu.h" >> +#include "pasid.h" >> #include "../iommu-pages.h" >> >> static void unpreserve_iommu_context(struct intel_iommu *iommu, int end) >> @@ -113,9 +114,89 @@ void intel_iommu_liveupdate_restore_root_table(struct intel_iommu *iommu, >> iommu->reg_phys, iommu_ser->intel.root_table); >> } >> >> +enum pasid_lu_op { >> + PASID_LU_OP_PRESERVE = 1, >> + PASID_LU_OP_UNPRESERVE, >> + PASID_LU_OP_RESTORE, >> + PASID_LU_OP_FREE, >> +}; >> + >> +static int pasid_lu_do_op(void *table, enum pasid_lu_op op) >> +{ >> + int ret = 0; >> + >> + switch (op) { >> + case PASID_LU_OP_PRESERVE: >> + ret = iommu_preserve_page(table); >> + break; >> + case PASID_LU_OP_UNPRESERVE: >> + iommu_unpreserve_page(table); >> + break; >> + case PASID_LU_OP_RESTORE: >> + iommu_restore_page(virt_to_phys(table)); >> + break; >> + case PASID_LU_OP_FREE: >> + iommu_free_pages(table); >> + break; >> + } >> + >> + return ret; >> +} >> + >> +static int pasid_lu_handle_pd(struct pasid_dir_entry *dir, enum pasid_lu_op op) >> +{ >> + struct pasid_entry *table; >> + int ret; >> + >> + /* Only preserve first table for NO_PASID. */ >> + table = get_pasid_table_from_pde(&dir[0]); >> + if (!table) >> + return -EINVAL; >> + >> + ret = pasid_lu_do_op(table, op); >> + if (ret) >> + return ret; >> + >> + ret = pasid_lu_do_op(dir, op); >> + if (ret) >> + goto err; >> + >> + return 0; >> +err: >> + if (op == PASID_LU_OP_PRESERVE) >> + pasid_lu_do_op(table, PASID_LU_OP_UNPRESERVE); >> + >> + return ret; >> +} >> + >> +void pasid_cleanup_preserved_table(struct device *dev) >> +{ >> + struct pasid_table *pasid_table; >> + struct pasid_dir_entry *dir; >> + struct pasid_entry *table; >> + >> + pasid_table = intel_pasid_get_table(dev); >> + if (!pasid_table) >> + return; >> + >> + dir = pasid_table->table; >> + table = get_pasid_table_from_pde(&dir[0]); >> + if (!table) >> + return; >> + >> + /* Cleanup everything except the first entry. */ >> + memset(&table[1], 0, SZ_4K - sizeof(*table)); >> + memset(&dir[1], 0, SZ_4K - sizeof(struct pasid_dir_entry)); > >(Not too familiar with Intel IOMMU / VT-d) >We seem to hardcode SZ_4K when clearing the directory entries. But in >intel_pasid_alloc_table(), the allocation size seems to depend on >max_pasid which could be larger than one page (order > 0)? > >If the directory is multi-page, won't we leave the trailing pages >and full of stale PDE pointers that the HW could still walk? Agreed. It should cleanup based on max_pasid. Will update. > >> + >> + clflush_cache_range(&table[0], SZ_4K); >> + clflush_cache_range(&dir[0], SZ_4K); >> +} >> + > >[ ------ >8 ------ ] > >Thanks, >Praan