From nobody Thu Apr 2 21:58:33 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 549E53859CE for ; Mon, 23 Mar 2026 23:58:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774310325; cv=none; b=uK52YJy+5NtmXLTjH40uOpnnj9KDR4Qj2euwK15LfnDPHGaQxujyVvcWqDaVReQ+PNtsWDPHwPpe7CTXn4U26fiSTJxdFbcqI1bfXL3yKrbHNr36cDOq/bZWSiHXkTvKXjSMChqSq7hCMOt6P55xN68GtbAOX0LdoupXS+roOC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774310325; c=relaxed/simple; bh=vLDgiBBZd58h0T0ReKqdykl5DlgchHSnpVYqQ6ykqu8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ihzvpoow4fIXQPGWSBxFcTjy1LhnizQgG3ITht5gYlD6t0XkGXKhF2P4l4rxIOgmmS2+IzLAzVTScJRpDgP3qvsRWSZKffVwClugJyVB9wVs6KI25D5IAp8tcZ9HZ9EhJRQ+s/gYCuXvTWk+fFuzSmF3UphKkdnuj1mBsPTmPuI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=F1gkYkqP; arc=none smtp.client-ip=209.85.214.201 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=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="F1gkYkqP" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2b056b2f0cfso8989565ad.0 for ; Mon, 23 Mar 2026 16:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774310323; x=1774915123; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Gw5NKF4E66vyohb8n/pa3diZrC0/+CJM8Skon/TvWYk=; b=F1gkYkqPc+XdbjhbEZ9eztV6hD5/Rd6mu4MK2/mGOdF+e97YHQIKpaKbenq82XSibi RxDRMPgvRENeXLq8GmvoRQPUY73un6Q/Fcb/sJsjhgH/imGRygfZsL60y0maJPtIeF9u iS1QzMZ7xzBL/tHsROAf+j7U9GqftIp/slvyx/m+U1Y1cfIg+CDuK+N5P4oseShqs65J uvSFfTzxUi0u8H3qaymMi6nT8dOdWM43zYNyCHhlKvPimNxhJ85Vbg97BjS8V/7BHz0s U49yfXPQO4CN5glC9UZFv+4lb3mMMX3RdXiFliIpkWXKJ4aU5ejVeZlOyQdobWqwEM4F wwPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774310323; x=1774915123; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Gw5NKF4E66vyohb8n/pa3diZrC0/+CJM8Skon/TvWYk=; b=n5gzdtAoIFbGtgYxs2+lmJyz57BObKUTgfDPUdZQrRbt7o1tyGR9mVyVSd8w/A+iPZ AJIuGue1r1h62j+luD9LSgFpCN9/RsdJK5Tdger134/ldJUD21j73r/4ZFc0ySolz0hp SSDjT21lZnoRbFD1pWJo/7iYv/JyvJXTZk5L5zBJ8Sou6pYOgyScmTCAfW6rFdV9aWkh f7Dw7msjxPZZKZvWQ23vJS5Lh4WzSzox9P/EWdHiMzNWH/+GhYa14Z6c/vK571NpaVJL VxnmB4+utUZGj8sqWXA/5UXcG1+HPqHVue4MWD0whfCID6vv4GXkMx4eBRBmtZvL7znP 9TuA== X-Forwarded-Encrypted: i=1; AJvYcCUcsJAuv/yQCLhv9iEbhjOqBiMxAZsaItnx7Q71aVWklzog0BI8Y0dexpAd1VoAQyGkJ99o/gptCUYVXKw=@vger.kernel.org X-Gm-Message-State: AOJu0YyW5uiev8ufbHWOCz5hA86VYGf4rb2kXIcIenXY5ODQaOyN0Kn8 zxtq7pHo61mesDgqJeHn2OxAYhDBbv4Z120EqYpiPBqtCJ96SIQJw+Vs4MNs8joIOes5ZH++wjU HYKP9V3oErpdwmg== X-Received: from plar5.prod.google.com ([2002:a17:902:c7c5:b0:2b0:5a1f:4fdf]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d507:b0:2b0:5795:9ead with SMTP id d9443c01a7336-2b0825e35e3mr130027435ad.0.1774310322445; Mon, 23 Mar 2026 16:58:42 -0700 (PDT) Date: Mon, 23 Mar 2026 23:57:55 +0000 In-Reply-To: <20260323235817.1960573-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260323235817.1960573-1-dmatlack@google.com> X-Mailer: git-send-email 2.53.0.983.g0bb29b3bc5-goog Message-ID: <20260323235817.1960573-4-dmatlack@google.com> Subject: [PATCH v3 03/24] PCI: Require Live Update preserved devices are in singleton iommu_groups From: David Matlack To: Alex Williamson , Bjorn Helgaas Cc: Adithya Jayachandran , Alexander Graf , Alex Mastro , Andrew Morton , Ankit Agrawal , Arnd Bergmann , Askar Safin , "Borislav Petkov (AMD)" , Chris Li , Dapeng Mi , David Matlack , David Rientjes , Feng Tang , Jacob Pan , Jason Gunthorpe , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Kees Cook , Kevin Tian , kexec@lists.infradead.org, kvm@vger.kernel.org, Leon Romanovsky , Leon Romanovsky , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org, Li RongQing , Lukas Wunner , Marco Elver , "=?UTF-8?q?Micha=C5=82=20Winiarski?=" , Mike Rapoport , Parav Pandit , Pasha Tatashin , "Paul E. McKenney" , Pawan Gupta , "Peter Zijlstra (Intel)" , Pranjal Shrivastava , Pratyush Yadav , Raghavendra Rao Ananta , Randy Dunlap , Rodrigo Vivi , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Vipin Sharma , Vivek Kasireddy , William Tu , Yi Liu , Zhu Yanjun Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Require that Live Update preserved devices are in singleton iommu_groups during preservation (outgoing kernel) and retrieval (incoming kernel). PCI devices preserved across Live Update will be allowed to perform memory transactions throughout the Live Update. Thus IOMMU groups for preserved devices must remain fixed. Since all current use cases for Live Update are for PCI devices in singleton iommu_groups, require that as a starting point. This avoids the complexity of needing to enforce arbitrary iommu_group topologies while still allowing all current use cases. Suggested-by: Jason Gunthorpe Signed-off-by: David Matlack --- drivers/pci/liveupdate.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c index bec7b3500057..a3dbe06650ff 100644 --- a/drivers/pci/liveupdate.c +++ b/drivers/pci/liveupdate.c @@ -75,6 +75,8 @@ * * * The device must not be a Physical Function (PF). * + * * The device must be the only device in its IOMMU group. + * * Preservation Behavior * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * @@ -105,6 +107,7 @@ =20 #include #include +#include #include #include #include @@ -222,6 +225,31 @@ static void pci_ser_delete(struct pci_ser *ser, struct= pci_dev *dev) ser->nr_devices--; } =20 +static int count_devices(struct device *dev, void *__nr_devices) +{ + (*(int *)__nr_devices)++; + return 0; +} + +static int pci_liveupdate_validate_iommu_group(struct pci_dev *dev) +{ + struct iommu_group *group; + int nr_devices =3D 0; + + group =3D iommu_group_get(&dev->dev); + if (group) { + iommu_group_for_each_dev(group, &nr_devices, count_devices); + iommu_group_put(group); + } + + if (nr_devices !=3D 1) { + pci_warn(dev, "Live Update preserved devices must be in singleton iommu = groups!"); + return -EINVAL; + } + + return 0; +} + int pci_liveupdate_preserve(struct pci_dev *dev) { struct pci_dev_ser new =3D INIT_PCI_DEV_SER(dev); @@ -232,6 +260,10 @@ int pci_liveupdate_preserve(struct pci_dev *dev) if (dev->is_virtfn || dev->is_physfn) return -EINVAL; =20 + ret =3D pci_liveupdate_validate_iommu_group(dev); + if (ret) + return ret; + guard(mutex)(&pci_flb_outgoing_lock); =20 if (dev->liveupdate_outgoing) @@ -357,7 +389,7 @@ int pci_liveupdate_retrieve(struct pci_dev *dev) if (!dev->liveupdate_incoming) return -EINVAL; =20 - return 0; + return pci_liveupdate_validate_iommu_group(dev); } EXPORT_SYMBOL_GPL(pci_liveupdate_retrieve); =20 --=20 2.53.0.983.g0bb29b3bc5-goog