From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 173543F8704 for ; Wed, 20 May 2026 18:13:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779300839; cv=none; b=IhBG2DhrK0j1vJihrLSA8JjsVZ+erltKxyCGyJrQ5b/EEJsNMijvNqIcR5/noD8o6PGIkfA4N14oVgytb96uxTLPC/xbvtk/T2calq81d/BLDV6YvGxzhbLnMsyirlWxGiRrxK+uY+4V/25MCiNaRpPmpugnbYUlIf5RL+tCQUE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779300839; c=relaxed/simple; bh=WlGqgjyBORkJfksIFZslOeTBEP3DJ5gkhKNzkH/Egug=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EAX4LqTfGlDk9dE7Fnbye+ifnhE3iqhuJ5ueKtFiRFGmY2yg7ZkNb83NhqfjQ3d/PcD5weAe6y6dgMHiMumyUoqHGFjkPZruJV436SS6boqHiT30RE9h9bW7wUxdgDDSoe5FrHpgawQ+yRmlcaGg0ChK/Svcdgz2acnr1vLIXek= 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=P6ii/3KS; arc=none smtp.client-ip=209.85.214.175 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="P6ii/3KS" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2ba3b9bcf69so505ad.0 for ; Wed, 20 May 2026 11:13:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779300837; x=1779905637; 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=FjVopLxhAIzTAf2Kz8X5x4L6V6oaH+XHeIW8ypuJnu8=; b=P6ii/3KS5+sglVC2M5Pmax4dyMAFp7JyGX7E+yCiEdV8gs1flnmFCkp6YoSNEPVl3D H/6Fh4a8OzlHupVNE68ZF++BItdx0kDBo7NpRJkaRQqVQi7qVP3vExOiNOH8AugQBWpR lGFBBkFABRjzqa5fP75ilMm2KmTPLoqchlK82CNe+bZTUnLQqtBI0/yRBpEVnBzDYb9y zPr/wXCLl1qfqfbrZVf9PiYDgpu8qrhDQKBoDzg5W23FUFMsw9n2R6VodEf+m1pvGt5l 0R8f4UebZcZrnwUnAIxQrT+isoIPUA3FIWFScwE2SCY+j9L3qHIjrTZTW0bMbSgom09d uW2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779300837; x=1779905637; 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=FjVopLxhAIzTAf2Kz8X5x4L6V6oaH+XHeIW8ypuJnu8=; b=WtQedwUugzgawVesX9XId9mOrDnP2qT3+S76NKg3COKNmeNUFEBUtXq3d9Pl5Jrx8Q QDlGtNnPUzwXkL+onA5aOEdUIO7NRPYirC2OXcM0JCIFmZBeS4OGc/11D2egVbzru/pq bcjmdbqQrVYuykz5gjFpE5ZAZZDMZ08+H4V6KVlmeCHXXADTJbW1R0h/NV1HTRY2QrD+ WN0jh5K7LRHjZDMZiWvBOzCstvVQ4M7vUc+jI+NL/fapslDXTkxpRoa/IuMSYLECjUmm U2drY2eHEwqHkLza4kHLM+vw+tLLdMnLvSnGozlxFhat7e9C/lwa3yYRDXWiL8xhahfd 2dBg== X-Forwarded-Encrypted: i=1; AFNElJ8/hkq24masTv4HLwBuH4uhsKFyrLmjMIi61kKOBCSwKduWPCWIi/sYcyXSIYphn10j98Rl8PJ/C++u26s=@vger.kernel.org X-Gm-Message-State: AOJu0Yxag+cT3I/+itPUxqhQ0H2OgChJnodm9T1Xk0zisbuCOJm48zB+ J6pkPEXpZSIHeVzmsJ3IYGrKkftnXt6oPxTRG9z+UcAvfa+XUXcEPf9Xzmkq4E/Y/w== X-Gm-Gg: Acq92OEoIspmp+uFzPVRX5emxaeQpY8X83ltKk/K4tiGgAYHzOTumz7OD0VXcNBcQ2C Xm/G3eGkcwiuHABm3GoRqmmYQM6MsA+/MAg1mumyJ4AE+zPLYIPivueZKZLUG7/RJzFcBEsuzP1 os45/VZe3ykakkDiHG8AALuntqnxrfaUnHGwWA/hCVcku0f7UoxA/XBdlZ6Ld4aPf8EvDPCh9xF r6tY9ynIHliilOCnrF4BJtp4V9+3vTsVwHzkS5nHmfx/jFJSOvLElZpyQSEspF5gHfPKAxVMhAG tlptoQyxPW3Uvdo9zAqm1apw7OaDABmiKfov49RULFL07+LSrHN5GCuk2uQHezRMQLWmDejHnHS 2K/dOEGKSO9CaW9rLj9vzC9t03OjgTGi5Xtc95J6jDkHxb6G/lTey6W5WdN8Wi17BUqI/qCGIwS 4j18m+NtXF6blptTrXRNfyETHMhLM4o4ZTUxDZaurAQJ5jhebVgGjIvPRSum0JaFymaxpUpg== X-Received: by 2002:a17:903:2288:b0:2ba:6518:e4d8 with SMTP id d9443c01a7336-2be9f43b2edmr335725ad.20.1779300836839; Wed, 20 May 2026 11:13:56 -0700 (PDT) Received: from google.com (153.46.83.34.bc.googleusercontent.com. [34.83.46.153]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36a3cb327d3sm376037a91.3.2026.05.20.11.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 11:13:56 -0700 (PDT) Date: Wed, 20 May 2026 18:13:52 +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 v2 11/16] iommu/vt-d: preserve PASID table of preserved device Message-ID: References: <20260427175633.1978233-1-skhawaja@google.com> <20260427175633.1978233-12-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 Tue, May 19, 2026 at 10:35:26PM +0000, Pranjal Shrivastava wrote: >On Mon, Apr 27, 2026 at 05:56:28PM +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 | 5 +- >> drivers/iommu/intel/iommu.h | 12 +++ >> drivers/iommu/intel/liveupdate.c | 141 +++++++++++++++++++++++++++++++ >> drivers/iommu/intel/pasid.c | 7 +- >> drivers/iommu/intel/pasid.h | 9 ++ >> include/linux/kho/abi/iommu.h | 13 +++ >> 6 files changed, 184 insertions(+), 3 deletions(-) >> [snip] >> + >> +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); > >Nit: This is making me consider renaming the helper as >`iommu_preserve_folio`. I almost thought why are we preserving a single >page. Interestingly the iommu pages API uses plural of page in API name as each iopt_desc can be backed by multiple pages: iommu_free_pages() iommu_alloc_pages_*() So I will rename these to: iommu_preserve_pages() iommu_preserve_pages_list(list) iommu_unpreserve_pages() iommu_unpreserve_pages_list(list) iommu_restore_pages() > >> + 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; >> +} >> + > >[snip] > >> + >> +void pasid_cleanup_preserved_table(struct device *dev) >> +{ >> + struct pasid_table *pasid_table; >> + struct pasid_dir_entry *dir; >> + struct pasid_entry *table; >> + size_t dir_size; >> + >> + 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; >> + >> + /* Clear everything except the first entry in table. */ >> + memset(&table[1], 0, SZ_4K - sizeof(*table)); > >Nit: Is the first entry always 4K or could it change based on PAGE_SIZE? VT-d uses 4k always, but for clarity I will change this to VTD_PAGE_SIZE. > >> + >> + /* Use the folio order to calculate the size of Pasid Directory */ >> + dir_size = (1 << (folio_order(virt_to_folio(dir)) + PAGE_SHIFT)); >> + >> + /* Clear everything except the first entry in directory */ >> + memset(&dir[1], 0, dir_size - sizeof(struct pasid_dir_entry)); >> + >> + clflush_cache_range(&table[0], SZ_4K); >> + clflush_cache_range(&dir[0], dir_size); >> +} >> + > >[...] > >> +void *intel_pasid_try_restore_table(struct device *dev, u64 max_pasid) >> +{ >> + struct iommu_device_ser *ser = dev_iommu_restored_state(dev); >> + >> + if (!ser) >> + return NULL; >> + >> + BUG_ON(pasid_lu_handle_pd(phys_to_virt(ser->intel.pasid_table), >> + PASID_LU_OP_RESTORE)); >> + if (WARN_ON_ONCE(ser->intel.max_pasid != max_pasid)) { > >I'm wondering if this could be slightly relaxed to: >if (ser->intel.max_pasid < max_pasid) to ensure it's a minimum >requirement rather than an exact match? Makes sense. I will update this. > >> + pasid_lu_handle_pd(phys_to_virt(ser->intel.pasid_table), >> + PASID_LU_OP_FREE); >> + return NULL; >> + } >> + >> + return phys_to_virt(ser->intel.pasid_table); >> +} >> diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c >> index 89541b74ab8c..5cac8e95f73b 100644 >> --- a/drivers/iommu/intel/pasid.c >> +++ b/drivers/iommu/intel/pasid.c >> @@ -60,8 +60,11 @@ int intel_pasid_alloc_table(struct device *dev) >> >> size = max_pasid >> (PASID_PDE_SHIFT - 3); >> order = size ? get_order(size) : 0; >> - dir = iommu_alloc_pages_node_sz(info->iommu->node, GFP_KERNEL, >> - 1 << (order + PAGE_SHIFT)); >> + >> + dir = intel_pasid_try_restore_table(dev, 1 << (order + PAGE_SHIFT + 3)); >> + if (!dir) >> + dir = iommu_alloc_pages_node_sz(info->iommu->node, GFP_KERNEL, >> + 1 << (order + PAGE_SHIFT)); >> if (!dir) { >> kfree(pasid_table); >> return -ENOMEM; > >Thanks, >Praan Sami