From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 2F4DA2DB7A0 for ; Thu, 19 Mar 2026 16:28:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773937689; cv=none; b=mND6qXGMGZgU5E2YNl7r8HARku4nvNww731it0jPD16STXxvpy3UY3htH80OvgOu76+7JfS++dTod6Tove8uDCIdiyNjpuuQ4Q2ywt5AbnRCuxr88/NiuGhTqglstEUzJWHBJmO/8nj+GApC7mII8m5fMdyFp93tNgIshJH5Kzk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773937689; c=relaxed/simple; bh=Ci8R0RcgT3R07Pso4NtY3exaPjxumuK/t2Ur7NUnLVw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cVHBwZBfazrGZp6V4TQGZJwnWAj+O71mrtCPR5OOpOD33228+5kgNx10I5QpShfwpQfN+UwrbVCjWYaDBCiXLLfindZnlI1yQcIGkgCLUEBfV1/uniX4Otnm4c85DMo7Q1R8u7YuLmx6pT0NrT7FoqzCa2XR3cFd1jKIKZqsG2U= 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=JUYoEJV2; arc=none smtp.client-ip=209.85.214.178 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="JUYoEJV2" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2b04c9e3eb7so95195ad.0 for ; Thu, 19 Mar 2026 09:28:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773937681; x=1774542481; 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=z8zoqnsuMjvOgf8bCpxiEMnB3Rfs/RX4TqY+c0PAvBo=; b=JUYoEJV2I23Pb7HDhu9gporUfMxEnK05ZUN/YHAL/eesTH9I8P/YP0cFgmIaw13WRK nPHKxetblPJBSg+REqN42YHOIXu+IfZGfF59AtAkduLG0Jb0kkYrNnVNR+fDUXB9eJze HPp3BySkKS62ZXwKci8izzIMvByLPvg6/VBmeqUWRl0sAPXL86OmRC59DKXEYjK62vin Us8xhWdCHa5T1I741ZUAkG+3f/5AmaxHZ3Eij2JfWwhewqTiUcPij0ZmBrNsm+bAKbGv o6GvJE07rDT+7s803Ev4skdFCEy/aaSAW5N31FLFMD+BpMzlgax+MfznkMQzBN+uptpJ YLmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773937681; x=1774542481; 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=z8zoqnsuMjvOgf8bCpxiEMnB3Rfs/RX4TqY+c0PAvBo=; b=Jhy3xCC6GJze2rfK4/Rp3ZYFP1ZW3NNLwf43NaMkOTg8OMe8g/UH95Yh+ivzXMTY5U EhB070kUYxES/k8iivRJcWLpNnDy1GMMuhHHFY8NemVWPAbLHrnV6S2UutaOC6eVCy47 hlRQsncKlkPkwhhakv4d78q27kU2wv0JgQFgZO2ivNj1SZvCM334FCUh8FKjSZ4jDetY IJ823sHemIX1PTLmKiB7S7rN4H4yFhrY3qWykUa2oziQaIDs9/kfeOo3tB0roxPlhhMq 2S1GVIKX3qp8pp6FXvUrIWWjWcslurFOwPPWGwSyVsaGXv2lwlryp+oaWb2QtZuNfZGU 5nWg== X-Forwarded-Encrypted: i=1; AJvYcCUpAziRjKeTiie7I2Jf9MhGDvujB/lyFvQrXjfBTnx4uDrBMbwNdk+MsDaghrJTIaQt5ElgH38CKnL/r7c=@vger.kernel.org X-Gm-Message-State: AOJu0YyjgDk+ltHJwCAmL9Er/H1VBkDCoAT5fNJKgmwf7tWnuY3vzgl8 uWDOzb4vn63kpLnQoi0dOU8WrSUbhu6EC9jf/Od0A6dhzQuNtZSRGtK89SRJFQaVAg== X-Gm-Gg: ATEYQzwdpFqtc7q18mgOCjJyl7iNsfSChZqnXULk7FRyETSHlNXUXss+xe1mxRouD8p eqNLzfs303kcogR9cjVSrB9jFl+vEB+cgfpAB6st6Xm2AxxSa9t80WHh8Pk4bogwYjKN7ltKMs7 FkTxd++EXTFoONGQvs9NudvQeCz8xkJUCE9bLDwTy+hzB4jmk5rUpcVB/19HgOx4RKyJBP8JnoO SqchUU/VDTuxcMDWK8NBseIhH/Rv8g9Ie5zz1Rqky0WfQ9vdCWx7pS41WHMJXcItXVoDqQVezRL oIXNAtZv8PrORtlCUmNspnEL6BRGLfu1Fv8vW2pmjgOp45hB2h8lp6rB2mz58wz1mygSEsMGz0F DF3g5KstJS9aC5Ghg0pQZT1hnxQ3twPbX2+8fv81FvYHWmcCTwv+ZUxgkgKhPD6ycBirsdVyzyE QdEWQNoJGWndFO3DJJU25723RAsIlDO3RfDpLknAzq0VuMXjM5K8VZIgVD3o8N2w== X-Received: by 2002:a17:902:ccc4:b0:2a7:d266:d84a with SMTP id d9443c01a7336-2b079fbb39emr2323775ad.17.1773937680332; Thu, 19 Mar 2026 09:28:00 -0700 (PDT) Received: from google.com (168.136.83.34.bc.googleusercontent.com. [34.83.136.168]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c741e5691b8sm5635536a12.25.2026.03.19.09.27.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2026 09:27:59 -0700 (PDT) Date: Thu, 19 Mar 2026 16:27:55 +0000 From: Samiullah Khawaja To: Vipin Sharma 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 , Pranjal Shrivastava , YiFei Zhu Subject: Re: [PATCH 06/14] iommu/vt-d: Implement device and iommu preserve/unpreserve ops Message-ID: References: <20260203220948.2176157-1-skhawaja@google.com> <20260203220948.2176157-7-skhawaja@google.com> <20260317221907.GD2582517.vipinsh@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: <20260317221907.GD2582517.vipinsh@google.com> On Thu, Mar 19, 2026 at 09:04:31AM -0700, Vipin Sharma wrote: >On Tue, Feb 03, 2026 at 10:09:40PM +0000, Samiullah Khawaja wrote: >> /* >> * Take a root_entry and return the Lower Context Table Pointer (LCTP) >> * if marked present. >> @@ -2378,8 +2379,10 @@ void intel_iommu_shutdown(void) >> /* Disable PMRs explicitly here. */ >> iommu_disable_protect_mem_regions(iommu); >> >> - /* Make sure the IOMMUs are switched off */ >> - iommu_disable_translation(iommu); >> + if (!__maybe_clean_unpreserved_context_entries(iommu)) { >> + /* Make sure the IOMMUs are switched off */ >> + iommu_disable_translation(iommu); >> + } > >I think instead of having a "maybe" function where it might or might not >clear the context entry, it will be simpler to just make if-else >explicit here. > >@@ -2375,8 +2375,11 @@ void intel_iommu_shutdown(void) > /* Disable PMRs explicitly here. */ > iommu_disable_protect_mem_regions(iommu); > >- /* Make sure the IOMMUs are switched off */ >- iommu_disable_translation(iommu); >+ if (iommu->iommu.outgoing_preserved_state) This is only defined when CONFIG_LIVEUPDATE is enabled and would need the #ifdefs :(. But I can add a function, iommu_outgoing_preserved_state() or iommu_is_outgoing_preserved() that would return NULL or false respectively when liveupdate is disabled, in the skeleton patch to check this. I will update this in the next revision. >+ clear_unpreserved_context_entries(); >+ else >+ /* Make sure the IOMMUs are switched off */ >+ iommu_disable_translation(iommu); > } > } > >clear_unpreserved_context_entries() will explicitly do what >__maybe_clean_unpreserved_context_entries() is doing. > >> } >> } >> >> @@ -2902,6 +2905,38 @@ static const struct iommu_dirty_ops intel_second_stage_dirty_ops = { >> .set_dirty_tracking = intel_iommu_set_dirty_tracking, >> }; >> >> +#ifdef CONFIG_IOMMU_LIVEUPDATE >> +static bool __maybe_clean_unpreserved_context_entries(struct intel_iommu *iommu) > >Nit: s/clean/clear, this matches domain_context_clear(). Agreed. > >> +{ >> + struct device_domain_info *info; >> + struct pci_dev *pdev = NULL; >> + >> + if (!iommu->iommu.outgoing_preserved_state) >> + return false; >> + >> + for_each_pci_dev(pdev) { >> + info = dev_iommu_priv_get(&pdev->dev); >> + if (!info) >> + continue; >> + >> + if (info->iommu != iommu) >> + continue; >> + >> + if (dev_iommu_preserved_state(&pdev->dev)) >> + continue; >> + >> + domain_context_clear(info); >> + } >> + >> + return true; >> +} >> +++ b/drivers/iommu/intel/liveupdate.c >> @@ -0,0 +1,134 @@ >> +// SPDX-License-Identifier: GPL-2.0-only >> + >> +/* >> + * Copyright (C) 2025, Google LLC >> + * Author: Samiullah Khawaja >> + */ >> + >> +#define pr_fmt(fmt) "iommu: liveupdate: " fmt >Should this be 'DMAR: liveupdate' to be consistent with other files in >intel iommu? Agreed. Will change. > >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +#include "iommu.h" >> +#include "../iommu-pages.h" >> + >> +static void unpreserve_iommu_context(struct intel_iommu *iommu, int end) > >Nit: Can this be unpreserve_iommu_context_table(), similar to existing >free_context_table()? Same for corresponding preserve function Agreed. I will change this. > >> +{ >> + struct context_entry *context; >> + int i; >> + >> + if (end < 0) >> + end = ROOT_ENTRY_NR; > >Can't we just pass ROOT_ENTRY_NR as end value instead of -1? Yes, we can do that. Will update. > Thanks, Sami