From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796429021; b=rgT5QBCTpvBYejDg6y617QR4Bo2zBHrDdPZpv5B0Iw6+l5ORPeq30I1YvC5JfM08ylHD tef+QcgI9P+fKsKEGV1YPhM2R1NYTHZJXm0fmmrrWlR57fTad/O89pey8k0iJYj4MA7wv JlapLlVer7ghb2d1Lpz222503cG1WllNGMjZUNqMTCKQKVsRZcCtKZ5T8CqCl4XPRnwE2 OaCWFUcTqnqcQfQ/Nm4uk51DrckNZ+upPVU85BJPhQnoWk+y29ntk23h9WG5ivS8+igup Y0QiB1pxD1V39WOkP02eThZazsG2D7PD439KFiZnjnlwF0lgLJVB8hTx89ZPvC+g9ww== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796429021; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=IRKs5pmGyqeiZwMAHUnhYrUvclnRdP3yxiAyU9RG7BE=; b=kLo9XB57w5kUiBI2Z6MsxS3mqeL6IAq/sfYi25qzQuoMdbcS4gyIZPXpplQUvi2QkX6x M0jhXDG92TP4AuGRrAxoW9bYw8xBNT2a7PkavPilzmK1dctSDcMh7XeWJP0+1jaKOpxQS RixSLl7SPxFkOG2Ga313BV9k31XxvnIuXtlTTjMxFhK/li2NCgMtd+gsVNpmpDcJPhgRJ 26jRoDPtDiQUB9QFzsxV/RKSFRRDBgiIaUTF0SESrzs8Ai9W2EZcj+wSJXuZ3fudePVHl fwDFtUX/HRxflqMpkwqO4Wl15NTfXd7RTKmPwumCDZ9igU+BOohnOvv9FAkOf0kGHYQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=AQPl1Vae; arc=none smtp.remote-ip=209.85.214.176 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35A62606A32C for ; Sat, 5 Dec 2026 00:03:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 35A62606A32C 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.a=rsa-sha256 header.s=20260707 header.b=AQPl1Vae Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2f048bc09d7so20105ad.0 for ; Fri, 04 Dec 2026 16:03:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796429019; x=1797033819; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=IRKs5pmGyqeiZwMAHUnhYrUvclnRdP3yxiAyU9RG7BE=; b=AQPl1Vaem1emaPip1QlAAfAbH2SbmDjTHfjABw//w24yIte1MIsX6jHNKToObNsdFl 0zgl6zIhyNYE4L+OKv0yv1Qss+pKxz6k62vlzUewZ3ry85rql2j89qlRGxhjJP9Fjhwv qX5jPY0tmN0oq9SBfe9/oBnaBiFq2GgIzIdS4V5QE8rl1ZYSDvztLJvDv/ul5gdKIxzD B658UqHpH6zBlhaqKXEmPrSAn8ei8txuoUZzzNIeU3PQWL/gKM/fY/rJf5CDwRMcymiK l+cxDqcuClw8N3RLthdKiukkXxzwhfeIXa+yvxNPnuIkx9XnFfx/+k1WNiswKJ0Ni1TN egzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796429019; x=1797033819; h=in-reply-to:content-disposition:content-type: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 :content-type; bh=IRKs5pmGyqeiZwMAHUnhYrUvclnRdP3yxiAyU9RG7BE=; b=pBw9OBlGatkTPHxCuXpxx7+jMANWvYxEqchN+WRThjDpmy6qAbQ1hZJI46SolV7nMZ 7KXFwBm2ZLXge6hG8ykhCYqtIItNvF+XqrgaIDuLBa5IpDhj3AtcCA81BMw8y6hr0Jtj 7cP1a1EQuTMOEhoknDzlWmBRk6N0jKchhmXJp4t8TvyPc+P/F7zOdAfYg2vTSCRw9U7p U4LksZkxjwC/Sn+Rc6eVpPyl2ttuAwlS1IahcX6+MtYENqiGmQp0ub/Zjt8DERwGFof7 +UszFFhnwjVwASP1yi3AQmHF1r/mrWXxGlDwbQFszP1GQJYxesE4OUpY9TpdGW8YNrY1 iTJQ== X-Forwarded-Encrypted: i=1; AL+hErHkodW3uUGIyBtJAhpyGLx3SKbM35VbyS8rworxKCxFuER22JzrzAEYx/qWGBOHj/paGj4=@vger.kernel.org X-Gm-Message-State: AB4q+uE/B6xbmSbFGkjZhkMlOg3UlGSUMF5VMZ1uBBD8m+Us1Rv/C4BO 44RD9OPjqltM0Q+b3tBa4P3tKHRydQOv3k0C8Zrjz6Ggr+2agpccfidNdNC5sJPf/g== X-Gm-Gg: AZFdTZepPQ6iwRMxpuY4wSQ6O9fwWhSOjzML0yHTMJYJv2dc8NMis8ZNOeOGm1Bz7ck 12gKCWxhne/a00vVqMJZA00G3WfGbYK7Lh/SjM9A1eTs4ukkDCsy5XMFU/wGbXZMXEyFHEMJsqP BIeghh4AjOXt3T0Z7BvD25Vl0b852Z4NZNtO+h7hJGC8vnq5omuCEFIthRGBnkrdTofWVSkjugn 5B6tmIHCocea3I75F+HwrYsO6tBQDHtFRIiy7FsVnPC7KnqwZ8r2612hOFdV9xuFH45EyeBKFKn PX0B5WX2NliKZdGLNBd8eYeJHHWNM3Pt0a2DLEi3p7LkFFtiNNux2ae5E9o3uxvg/IxrTFgAPqg E7gGeO6waVjxCl51fUWf4EFudvsxqQ13X7M5xu34B9hxyxiE1wYpfhx3I0jA+pxz3sSGkjSQQZg LwKysd1SzSTPdUNV9I92w70RTh7GXdCMmVurC0BiQJHLBKO1+Tx0y/uCz/yu2FlgVk1T+jJnpQ7 uhodbhhcMLeT7RX+jvKNNs4lM2VSHyljucJv3tbyTfhawQeoKME1BralnhVBfEtcC9UK4oTSKGB 1BkIc3xE+Eg+xNf4rkmNB+wb1MB9Gg/GyhJoZlI92pnzIUepy07CGoq7lqG4yprlPJgD9RBXoKP KdkGWFtqeMMUZPFHzEAUw X-Received: by 2002:a17:903:320b:b0:2ef:ff51:d7de with SMTP id d9443c01a7336-2f1eca57922mr842135ad.10.1796429018649; Fri, 04 Dec 2026 16:03:38 -0800 (PST) Received: from google.com (25.75.145.34.bc.googleusercontent.com. [34.145.75.25]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5ddabfda4sm6356203a91.0.2026.12.04.16.03.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 16:03:36 -0800 (PST) Date: Sat, 5 Dec 2026 00:03:32 +0000 From: Samiullah Khawaja To: Baolu Lu Cc: Joerg Roedel , Will Deacon , Jason Gunthorpe , David Woodhouse , Robin Murphy , Kevin Tian , Alex Williamson , Shuah Khan , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Pratyush Yadav , Pasha Tatashin , David Matlack , Andrew Morton , Pranjal Shrivastava , Vipin Sharma , Ankit Soni , Nicolin Chen , John Starks Subject: Re: [PATCH v8 11/18] iommu/vt-d: Restore IOMMU state and reclaimed domain ids Message-ID: References: <20261123044949.3610702-1-skhawaja@google.com> <20261123044949.3610702-12-skhawaja@google.com> <8f1bb7da-9cca-422c-b046-b053c92ec9c5@linux.intel.com> X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <8f1bb7da-9cca-422c-b046-b053c92ec9c5@linux.intel.com> On Fri, Dec 04, 2026 at 02:55:01PM +0800, Baolu Lu wrote: >On 11/23/26 12:49, Samiullah Khawaja wrote: >>During boot fetch the preserved state of IOMMU unit and if found then >>restore the state. >> >>- Reuse the root_table that was preserved in the previous kernel. >>- Reclaim the domain ids of the preserved domains for each preserved >> devices so these are not acquired by another domain. > >The commit message is out of date. This change also forces the iommu on >when preserved state exists, rejects hot-plug of a restored unit and >panics on any restore failure. Please add these changes and the reasons >for them. > >Nit: "reclaimed domain ids" in the subject should be "reclaim domain >IDs", and "for each preserved devices" should be "for each preserved >device". Will update. > >> >>Signed-off-by: Samiullah Khawaja >>--- >> drivers/iommu/intel/iommu.c | 86 ++++++++++++++++--- >> drivers/iommu/intel/iommu.h | 14 ++++ >> drivers/iommu/intel/liveupdate.c | 139 +++++++++++++++++++++++++++++++ >> 3 files changed, 226 insertions(+), 13 deletions(-) >> >>diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c >>index 6c86c155d12b..691bfe34e575 100644 >>--- a/drivers/iommu/intel/iommu.c >>+++ b/drivers/iommu/intel/iommu.c >>@@ -987,6 +987,8 @@ static void iommu_disable_translation(struct intel_iommu *iommu) >> static void release_dmar_iommu(struct intel_iommu *iommu) >> { >>+ intel_iommu_handle_drhd_restore_failure(iommu); > >The name is misleading. This function doesn't handle anything, it just >panics if the iommu has retored state. Perhaps rename it something like >intel_iommu_assert_not_restored()? Yes, this is much better. Will update. > >>+ >> /* >> * All iommu domains must have been detached from the devices, >> * hence there should be no domain IDs in use. >>@@ -1452,7 +1454,7 @@ static void intel_iommu_init_qi(struct intel_iommu *iommu) >> * Returns 0 when the ID is reserved, was already reserved, or cannot be >> * re-assigned, and a negative errno for a genuine allocation failure. >> */ >>-static int reserve_domain_id(struct intel_iommu *iommu, int did) >>+int reserve_domain_id(struct intel_iommu *iommu, int did) >> { >> int ret; >>@@ -1743,12 +1745,16 @@ static int copy_translation_tables(struct intel_iommu *iommu) >> static int __init init_dmars(void) >> { >>+ struct iommu_hw_ser *iommu_ser; >> struct dmar_drhd_unit *drhd; >> struct intel_iommu *iommu; >> int ret; >> for_each_iommu(iommu, drhd) { >>+ iommu_ser = iommu_get_restored_state(iommu->reg_phys, >>+ IOMMU_SER_TYPE_INTEL); > >iommu_get_restored_state() is called for the same iommu in five places >in iommu.c. How aobut look it up once here and cache it in struct >intel_iommu, and use the cached value in all the other places? Hmm.. yes I think that can be done. But we only want to keep that set during early boot during iommu init. We can actually use the "iommu_ser" in struct iommu_device for this and unset it for the iommus when the init is done. > >> if (drhd->ignored) { >>+ intel_iommu_handle_drhd_restore_failure(iommu); >> iommu_disable_translation(iommu); >> continue; >> } >>@@ -1766,7 +1772,9 @@ static int __init init_dmars(void) >> } >> intel_iommu_init_qi(iommu); >>- init_translation_status(iommu); >>+ >>+ if (!iommu_ser) >>+ init_translation_status(iommu); >> if (translation_pre_enabled(iommu) && !is_kdump_kernel()) { >> iommu_disable_translation(iommu); >>@@ -1775,14 +1783,18 @@ static int __init init_dmars(void) >> iommu->name); >> } >>- /* >>- * TBD: >>- * we could share the same root & context tables >>- * among all IOMMU's. Need to Split it later. >>- */ >>- ret = iommu_alloc_root_entry(iommu); >>- if (ret) >>- goto free_iommu; >>+ if (iommu_ser) { >>+ intel_iommu_liveupdate_restore_root_table(iommu, iommu_ser); > >The check that the hardware still matches the preserved state (TES, >RTADDR, SMT) runs here. How about run the sanity checks first, right >after above lookup, so that on a mismatch we panic before changing >anything. Sounds good. I can wrap the lookup, the sanity check and the iommu_ser caching into one function intel_iommu_liveupdate_restore() that is implemented in liveupdate.c. This can call iommu_get_restored_state() internally. > >>+ } else { >>+ /* >>+ * TBD: >>+ * we could share the same root & context tables >>+ * among all IOMMU's. Need to Split it later. >>+ */ >>+ ret = iommu_alloc_root_entry(iommu); >>+ if (ret) >>+ goto free_iommu; >>+ } >> if (translation_pre_enabled(iommu)) { >> pr_info("Translation already enabled - trying to copy translation structures\n"); >>@@ -1818,7 +1830,11 @@ static int __init init_dmars(void) >> */ >> for_each_active_iommu(iommu, drhd) { >> iommu_flush_write_buffer(iommu); >>- iommu_set_root_entry(iommu); >>+ >>+ iommu_ser = iommu_get_restored_state(iommu->reg_phys, >>+ IOMMU_SER_TYPE_INTEL); >>+ if (!iommu_ser) >>+ iommu_set_root_entry(iommu); >> } >> check_tylersburg_isoch(); >>@@ -2247,6 +2263,15 @@ static int intel_iommu_add(struct dmar_drhd_unit *dmaru) >> struct intel_iommu *iommu = dmaru->iommu; >> int ret; >>+ /* >>+ * Hot-add of an IOMMU with preserved state is not supported. A >>+ * preserved IOMMU is restored during boot, so it should never get >>+ * here. >>+ */ >>+ if (WARN_ON(iommu_get_restored_state(iommu->reg_phys, >>+ IOMMU_SER_TYPE_INTEL))) >>+ return -EBUSY; >>+ >> /* >> * Disable translation if already enabled prior to OS handover. >> */ >>@@ -2689,6 +2714,33 @@ static __init void tboot_force_iommu(void) >> no_iommu = 0; >> } >>+/* >>+ * Devices preserved across a live update keep doing DMA through the preserved >>+ * translation tables, so the IOMMUs can't be turned off. Force them on if the >>+ * previous kernel preserved any IOMMU state. >>+ */ >>+static void __init liveupdate_force_iommu(void) >>+{ >>+ struct dmar_drhd_unit *drhd; >>+ >>+ if (dmar_policy_on()) >>+ return; >>+ >>+ for_each_drhd_unit(drhd) { >>+ if (!iommu_get_restored_state(drhd->reg_base_addr, >>+ IOMMU_SER_TYPE_INTEL)) >>+ continue; >>+ >>+ pr_warn("Forcing Intel-IOMMU to enabled for live update\n"); >>+ >>+ /* No concurrent access to dmar_policy at this point. */ >>+ dmar_policy = DMAR_FORCE_ON; > >This skips the precedence rules in dmar_can_force_on(). In particular, >it overrides DMAR_FW_OFF, which no force_on may override. Please add a >DMAR_FORCEON_LIVEUPDATE level to dmar_can_force_on(), document where it >sits in the precedence, and panic if it can't be honored. See below. > >>+ no_iommu = 0; >>+ pci_request_acs(); > >pci_request_acs() here comes too late for devices that have already been >enumerated. Hmm.. the ACS configuration of the preserved devices should also be preserved and pci_enable_acs() is called during driver probe so most devices will get it. But this is still inconsistent and it can miss the non-preserved devices/bridges that are probed before this point. Doing the force on properly needs the check in dmar_required(), so pci_request_acs() is called early like it is done for tboot and platform opt-in. That would require changing the point at which the KHO/LUO data is available during boot. Basically this: https://lore.kernel.org/all/20261005064018.1558-3-Ankit.Soni@amd.com/ I think we can panic here if preserved state is found and the IOMMU is not enabled, instead of doing force_on, and add separate patches later to add force on logic once the KHO/LUO stuff is moved early. This way the pci_request_acs() will be done at the right time also. Note that doing a check here and doing a panic() is not too late as the ACS configuration of the preserved devices (including their parent bridges) is also preserved and the IOMMU state is also intact at this point. > >>+ return; >>+ } >>+} >>+ >> int __init intel_iommu_init(void) >> { >> int ret = -ENODEV; >>@@ -2716,6 +2768,8 @@ int __init intel_iommu_init(void) >> goto out_free_dmar; >> } >>+ liveupdate_force_iommu(); >>+ >> up_write(&dmar_global_lock); >> /* >>@@ -2797,7 +2851,8 @@ int __init intel_iommu_init(void) >> * to avoid unnecessary lock order splat. >> */ >> up_read(&dmar_global_lock); >>- iommu_device_register(&iommu->iommu, &intel_iommu_ops, NULL); >>+ if (iommu_device_register(&iommu->iommu, &intel_iommu_ops, NULL)) >>+ intel_iommu_handle_drhd_restore_failure(iommu); >> down_read(&dmar_global_lock); >> iommu_pmu_register(iommu); >>@@ -2808,7 +2863,12 @@ int __init intel_iommu_init(void) >> /* Finally, we enable the DMA remapping hardware. */ >> for_each_iommu(iommu, drhd) { >>- if (!drhd->ignored && !translation_pre_enabled(iommu)) >>+ /* >>+ * The translation of a restored IOMMU was never disabled, so >>+ * don't touch its GCMD register. >>+ */ >>+ if (!drhd->ignored && !translation_pre_enabled(iommu) && >>+ !iommu_get_restored_state(iommu->reg_phys, IOMMU_SER_TYPE_INTEL)) >> iommu_enable_translation(iommu); >> iommu_disable_protect_mem_regions(iommu); > >[...] > >>diff --git a/drivers/iommu/intel/liveupdate.c b/drivers/iommu/intel/liveupdate.c >>index c0c121bc3ea5..d43947879e78 100644 >>--- a/drivers/iommu/intel/liveupdate.c >>+++ b/drivers/iommu/intel/liveupdate.c >>@@ -304,6 +304,145 @@ static int preserve_iommu_context_tables(struct device_domain_info *info) >> return 0; >> } >>+static int restore_context_table(struct intel_iommu *iommu, >>+ struct iommu_hw_ser *ser, >>+ u8 bus, u8 devfn, u64 root_val) >>+{ >>+ bool present = root_val & 1; >>+ >>+ /* >>+ * The root entries of unpreserved context tables are cleared during >>+ * shutdown, so the preserved bitmap must match the present bits. >>+ */ >>+ if (is_context_table_preserved(iommu, ser, bus, devfn) != present) >>+ return -EINVAL; >>+ >>+ if (present) >>+ iommu_restore_pages(root_val & VTD_PAGE_MASK); >>+ >>+ return 0; >>+} >>+ >>+static int restore_iommu_context(struct intel_iommu *iommu, >>+ struct iommu_hw_ser *ser) >>+{ >>+ struct root_entry *root; >>+ int ret; >>+ int i; >>+ >>+ for (i = 0; i < ROOT_ENTRY_NR; i++) { >>+ root = &iommu->root_entry[i]; >>+ >>+ ret = restore_context_table(iommu, ser, i, 0, root->lo); >>+ if (ret) >>+ return ret; >>+ >>+ if (!sm_supported(iommu)) >>+ continue; >>+ >>+ ret = restore_context_table(iommu, ser, i, 0x80, root->hi); >>+ if (ret) >>+ return ret; >>+ } >>+ >>+ return 0; >>+} >>+ >>+static int _restore_used_domain_ids(struct iommu_device_ser *ser, void *arg) >>+{ >>+ int id = ser->attachment.attachment_id; >>+ struct iommu_hw_ser *iommu_hw_ser; >>+ struct intel_iommu *iommu = arg; >>+ >>+ if (WARN_ON(!ser->iommu_phys)) >>+ return 0; >>+ >>+ iommu_hw_ser = phys_to_virt(ser->iommu_phys); >>+ if (iommu_hw_ser->type != IOMMU_SER_TYPE_INTEL) >>+ return 0; >>+ >>+ /* Only allocate domain ID from associated IOMMU HW unit */ >>+ if (iommu_hw_ser->intel.phys_addr != iommu->reg_phys) >>+ return 0; >>+ >>+ /* An out of range domain ID means the preserved state is corrupt. */ >>+ if (id < 0 || id >= iommu->max_domain_id) >>+ return -EINVAL; >>+ >>+ return reserve_domain_id(iommu, id); >>+} >>+ >>+/** >>+ * intel_iommu_liveupdate_restore_root_table() - Restore root table and reclaim domain IDs >>+ * @iommu: Target IOMMU >>+ * @iommu_ser: Serialized IOMMU hardware state from previous kernel >>+ * >>+ * Restores the preserved root table and context tables for the IOMMU hardware >>+ * instance across Live Update, and reclaims all domain IDs previously allocated >>+ * to preserved devices so they are not reused. >>+ * >>+ * The preserved devices keep doing DMA through the preserved translation >>+ * tables, so a failure to restore them is fatal. >>+ */ >>+void intel_iommu_liveupdate_restore_root_table(struct intel_iommu *iommu, >>+ struct iommu_hw_ser *iommu_ser) > >The name is not accurate because this function also restores the context >tables and reclaims domain IDs. > >How about intel_iommu_liveupdate_restore()? As you suggested above and in my reply, I can move the sanity checks and other initialization like reclaiming domain ids to a separate function intel_iommu_liveupdate_restore(). And this function can continue to restore only root table and context tables? Or this function can be renamed and called earlier in the lookup loop, but that means the root_entry will be set earlier and that is inconsistent. > >>+{ >>+ u64 rtaddr; >>+ u32 gsts; >>+ int ret; >>+ >>+ /* >>+ * The kernel command line might have changed across kexec, e.g. >>+ * intel_iommu=sm_off, so make sure the preserved tables are in the >>+ * format this kernel is going to use. >>+ */ >>+ if (iommu_ser->intel.sm_enabled != sm_supported(iommu)) >>+ panic("%s: preserved scalable mode %u does not match current %u\n", >>+ iommu->name, iommu_ser->intel.sm_enabled, >>+ sm_supported(iommu)); >>+ >>+ /* >>+ * The preserved devices are still translated by the hardware, so it >>+ * must be using the preserved root table. >>+ */ >>+ gsts = readl(iommu->reg + DMAR_GSTS_REG); >>+ rtaddr = readq(iommu->reg + DMAR_RTADDR_REG); >>+ if (!(gsts & DMA_GSTS_TES) || >>+ (rtaddr & VTD_PAGE_MASK) != iommu_ser->intel.root_table || >>+ !!(rtaddr & DMA_RTADDR_SMT) != !!iommu_ser->intel.sm_enabled) >>+ panic("%s: hardware state does not match preserved state (GSTS 0x%x, RTADDR 0x%llx)\n", >>+ iommu->name, gsts, rtaddr); >>+ >>+ iommu_restore_pages(iommu_ser->intel.root_table); >>+ iommu->root_entry = phys_to_virt(iommu_ser->intel.root_table); >>+ >>+ ret = restore_iommu_context(iommu, iommu_ser); >>+ if (ret) >>+ panic("%s: failed to restore preserved context tables\n", >>+ iommu->name); >>+ >>+ ret = iommu_for_each_restored_device(_restore_used_domain_ids, iommu); >>+ if (ret) >>+ panic("%s: failed to reclaim preserved domain IDs: %d\n", >>+ iommu->name, ret); >>+} >>+ >>+/** >>+ * intel_iommu_handle_drhd_restore_failure() - Handle DRHD restore failure >>+ * @iommu: Target IOMMU >>+ */ >>+void intel_iommu_handle_drhd_restore_failure(struct intel_iommu *iommu) >>+{ >>+ /* >>+ * The preserved devices keep doing DMA through the preserved >>+ * translation tables, so a failure to restore and register the IOMMU >>+ * is fatal. >>+ */ >>+ if (iommu_get_restored_state(iommu->reg_phys, IOMMU_SER_TYPE_INTEL)) >>+ panic("%s: failed to restore IOMMU with preserved state\n", >>+ iommu->name); >>+} >>+ >> /** >> * intel_iommu_preserve_device() - Intel IOMMU callback to preserve device state >> * @dev: Target device > >Thanks, >baolu > Thanks, Sami