From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 41D45175A71 for ; Sat, 21 Mar 2026 13:27:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774099634; cv=none; b=SysGTRN4VzUXG6J770XXMaXtTIraW4Ee7OoYS/5z4CkmD5QsFoi2xCJQ3Wj+yyWIpdfqzZnsEeezJAbNAqCZhCZULB1eNHt3qkr+NRp9xaVS/Ek3VqkdBVce7B9sNaabXnsM6qfzc1Keq5QpZH8UycOIeZrNvs2XG78XRCtpwcY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774099634; c=relaxed/simple; bh=pi5Cr+wPz3p8f6WVyTUc6OTVwoqra6jg8txqrOsu920=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GvLxm+ENur+77Ph63BcUJNyaMMH7UQTPOzgl0V/JtHxEPM3oaVdspToqGXXJf7XPBA2jFgh+nSSJxUbaP8d8E/bcWfwlKJHlpAoGcwd1dbagx7QX+coQ2VVNPMvu6CINtSqaiZFySIEuQzzTOwuT8dOmapv4Sc6KQxEOBhpBKT0= 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=gOWZGiK3; arc=none smtp.client-ip=209.85.214.170 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="gOWZGiK3" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2b04c9e3eb7so69995ad.0 for ; Sat, 21 Mar 2026 06:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774099631; x=1774704431; 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=H1Fj4N/UpgbJKkAFov6kcwTbNCL5sZLLzanhyYdr1VI=; b=gOWZGiK3U6Z7+3v1GfOmT/l5A58FOsbsqyfE6Cx87lmO+GErEOcY6VBjH4gIvLj9SI /Fm2YDtAl56i99MzQpOcY4jInxC3tLHMAPcEqQ+P0BWFq1CBCBpwIXCuna96DipFepnD 51ayk7b95e4Kk2T4x6tKv4fx4byKWQ1jbtwqKWyKDhLTTT1xvKFuss3UoTBjgE1s1Oq5 NhUSH0hXwsDM7HLUJGOv+fmaJCDy6csGlHg27jBcvdn4z0GZsBDdXMd1AdWD9CGNv68h YFHoKs11c4YCNRsGCqqSktSXZlH5eRU7Me9VAwccDO+VyjQRrWfQWU4gtV3c1HvtBvcH q28w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774099631; x=1774704431; 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=H1Fj4N/UpgbJKkAFov6kcwTbNCL5sZLLzanhyYdr1VI=; b=mOLyyrgjV3dpJWbRndOIahfMoQSgE2rs6CEHMyMdo+/1IbrGFeTCJoEGDkhJdJBvNJ 9ZTaocfUsdYSDUxV7yyt/YDYsz2ztGnuVF7PZr0WQUZgc9gWfzoTAKtkfnel8tKC/lfM CHK022qaxBYhSk4FRaPaCcM1/BKsnwPuH34qOMOia+8NXTYEnIwuBROLqojUHceu2v90 AoIw8h5BPsWd4AAeFdJbB/mNjf9b/MxeriPilqsw9ciksPwggOYUhe/OGC/8t8xe+0oN 54979ODPAEZpiV2Dd9BFN8Qkb862Sz0KW7Qzv78p7IRcWFI/5IxyCG57pwI47GzCH8sW W3CA== X-Forwarded-Encrypted: i=1; AJvYcCWMKp6Wmg3GWiPUH62v/Pk86PDoQqUwATguFGSZ5wZ4wlYQnyY1zzpbyOwd5zGwD/SURl5C14V7zwgEBwc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/oGkvE6WL1EamdsyxsVWPay00O8XpRLPxuwrjSu5E+ipFwhon 17s9kNxKWEagOj6V8yT8rL3mZo6ML0H0cmkbJfi4bxR/vIhDwt4Q2xgjJP3WCv0XU/lurg8Pu9j Ya0u+X27o X-Gm-Gg: ATEYQzypqADJQRmW3c6CCKU24v5He2CRJ77/ZTrInLclW9c2Lny0b5GPq/lCVfvqrMG UHrOpWd3X8M6hQU2rTlYaQGJEzfyx1svVpZhMcxmda+NwRjeT8rpFyo9TV3uXWHO8KVjiBpYncN JjtWm1mk53OCCRumuvB8OJ6L7yRPdex40/vbC4guWegtQTaKYzKfpOMuhRQODT5khdLrAceo5NR gyfHmnghL7sIrQ9HxQI0HSCljlk/+w/lSlyZzivvg8p+FD6BOM3ooaqMDQhHznlHoi0nQasIIGe NHGuwPUDVpsVZrEW2vI411I98nSCwU9YvS9QQim7f6DCo8JDN47T9kHiMb9Xb+nDbQZoS9x2cgG wTD8RdcBry6z+4wxdnbLfdIB0sXs9RLMgBnyD8AQ1HctmtDiGj0C/j/Y5M1gQ9/26Bce5Otx33/ mN1x2dRZH734fz3cdKWuzqxhXKmSOgKET/MhWTWNoO3fLWFsXGpnn7bDSk09KfKax+HZuX X-Received: by 2002:a17:902:db0d:b0:2ae:d10c:6382 with SMTP id d9443c01a7336-2b08b4432c2mr2182545ad.20.1774099630892; Sat, 21 Mar 2026 06:27:10 -0700 (PDT) Received: from google.com (10.129.124.34.bc.googleusercontent.com. [34.124.129.10]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35bd26cde44sm1729954a91.4.2026.03.21.06.27.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2026 06:27:09 -0700 (PDT) Date: Sat, 21 Mar 2026 13:27:00 +0000 From: Pranjal Shrivastava To: Samiullah Khawaja 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 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> 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 Content-Disposition: inline In-Reply-To: On Fri, Mar 20, 2026 at 11:01:59PM +0000, Pranjal Shrivastava wrote: > On Tue, Feb 03, 2026 at 10:09:40PM +0000, Samiullah Khawaja wrote: > > Add implementation of the device and iommu presevation in a separate > > file. Also set the device and iommu preserve/unpreserve ops in the > > struct iommu_ops. > > > > During normal shutdown the iommu translation is disabled. Since the root > > table is preserved during live update, it needs to be cleaned up and the > > context entries of the unpreserved devices need to be cleared. > > > > Signed-off-by: Samiullah Khawaja > > --- > > drivers/iommu/intel/Makefile | 1 + > > drivers/iommu/intel/iommu.c | 47 ++++++++++- > > drivers/iommu/intel/iommu.h | 27 +++++++ > > drivers/iommu/intel/liveupdate.c | 134 +++++++++++++++++++++++++++++++ > > 4 files changed, 205 insertions(+), 4 deletions(-) > > create mode 100644 drivers/iommu/intel/liveupdate.c > > > > diff --git a/drivers/iommu/intel/Makefile b/drivers/iommu/intel/Makefile > > index ada651c4a01b..d38fc101bc35 100644 > > --- a/drivers/iommu/intel/Makefile > > +++ b/drivers/iommu/intel/Makefile > > @@ -6,3 +6,4 @@ obj-$(CONFIG_INTEL_IOMMU_DEBUGFS) += debugfs.o > > obj-$(CONFIG_INTEL_IOMMU_SVM) += svm.o > > obj-$(CONFIG_IRQ_REMAP) += irq_remapping.o > > obj-$(CONFIG_INTEL_IOMMU_PERF_EVENTS) += perfmon.o > > +obj-$(CONFIG_IOMMU_LIVEUPDATE) += liveupdate.o > > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c > > index 134302fbcd92..c95de93fb72f 100644 > > --- a/drivers/iommu/intel/iommu.c > > +++ b/drivers/iommu/intel/iommu.c > > @@ -16,6 +16,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -52,6 +53,8 @@ static int rwbf_quirk; > > [ ---- snip >8 ----- ] > > + > > +int intel_iommu_preserve(struct iommu_device *iommu_dev, struct iommu_ser *ser) > > +{ > > + struct intel_iommu *iommu; > > + int ret; > > + > > + iommu = container_of(iommu_dev, struct intel_iommu, iommu); > > + > > + spin_lock(&iommu->lock); > > Minor note: We call this with the session->mutex acquired which is a > sleepable/preemptable context whereas spin_lock disables preemption and > puts us in an atomic context. > > While iommu_context_addr() happens to be safe here because it uses > GFP_ATOMIC & we pass alloc=0, we are heavily relying on the assumption > that iommu_context_addr() or other helpers will never sleep or attempt > a GFP_KERNEL allocation under the hood. > > Given how easy it would be for a future refactor to accidentally > introduce a sleeping lock inside any of the other helpers, I'd recommend > adding an explicit comment here warning that this runs in an atomic > context (same for unpreserve below). > Thinking a little more about this, I think we shall instead add a comment in the core API docs, mentioning that these helpers (like iommu_preserve_page etc.) can be called from atomic context and hence should not acquire any mutexes as we can't be certain of the context the drivers call them in. Thanks, Praan