From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 63D1C3090C6 for ; Tue, 2 Dec 2025 23:03:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764716624; cv=none; b=ZNQSaJhY0SPS30RRQgsOcZK6hZCjpOgB5Ra3+9qqkj9PbSrDrdYlhfTtR6yF7iYJalDtIXXSXW1WMULP5ejo3j1SigDal9e1IXn6WnGcsCpgA7Phj2iABqIybQF1Xdsqkx27L0ON3EEpCeAkGsOVnNxm2EsowLuTrPrXN/k2WOc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764716624; c=relaxed/simple; bh=l6FB8BOFQGdBKeD2DQc1ZM9wSnaceow2usRLYrMCWWQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=uQL9h5TSnqQa00u4ptHCbq9flU2JIYamdnmKF2+8FWWVjx8icqS7Q1Hwvi90HMFGfl4emTAOuRC6ta4UUzvdJ9pdJFT+wx5npfrk8SnVTJEd50w6vnHjnq+X7jauGACOV9tnAmuQADq3OdRVOvgvYGVhy8s/ySdqZFbTWLweEoo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--skhawaja.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=XJBIqRQJ; arc=none smtp.client-ip=209.85.210.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--skhawaja.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XJBIqRQJ" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-7c7957d978aso5722050b3a.1 for ; Tue, 02 Dec 2025 15:03:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764716623; x=1765321423; 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=SPEjNOez0fL5I+Zr7fias5PbR6Pw1WeqxOD3IbrOXLU=; b=XJBIqRQJiZCHXtLj3SnZ6UMG5qfZ3kKHfkcuNOgEf7VZtlLydUC/a2JQtdHk93mFsO ssRjciSabvrDGjzKqNjowewLJUJhT6sUkeXX5pGfBNlAdXDksc2EIb0zqBEnYpWro/oT xDrHGW0Ec8sEb/MqYISD0JLhYcE761lzdtTqz+5VpM/6qCsabKw5YHz35gjS90lztzNA zqbkL701PmHj77zbYGPA9xF9fXtJJKPu4O5fOmC8hI/7UbIfmTsTs8u7MkuNP0kPoQGM SJpSQMuRqZewLG0Qg2ZMyM3dYzYGQg6JbTTE1fWQhF5dT8P2IYa1+9iUWX07LQA/Ajxq DraA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764716623; x=1765321423; 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=SPEjNOez0fL5I+Zr7fias5PbR6Pw1WeqxOD3IbrOXLU=; b=ZAeLkURz+71B94aNddnRa9INGOPiNExiY9VFevOpgelKFgP7wR1fji6ILrF00mjjA1 y4hUse/qok1Dv58FIn+4bbsFtDoZYWZRzoGB5Po8CUu97otFa4ERshWPCaXLp5kPOMAz 2+G7CiCtiW0IFxNgZZ3cSG2HlNvqMYSZESe1QSYYzPUQYWHpQ9Ndzz+3qiM3hBh3Ddal P10bzw6jgePcVE7JZEgKzn/WuDM9tMvKP0D5BI7d3aT82edpPtcoyZfx9q8Qp5Elk0wF 84YQIt3TZD7pJZa5+96fH0s25uP6pNHB/Hrp5Gb4Rq6B1WbEuL/F9E9qWWusmDMLBbI7 2QqQ== X-Forwarded-Encrypted: i=1; AJvYcCWBps4HpuFPWLQp3trRPD1f2S9iL3j2kSQhZojph9IX5R3JHFdu5G66QWn9HCNmrafePRsA/todIJSInxY=@vger.kernel.org X-Gm-Message-State: AOJu0Yw6nLb+UkJIJ6Mc2Ye/IkfnJI3Ol97RYiDCS0BDy51uWp+0FlGO LPOz1PnH6Ix5yrzcytDz+8RI0nPgtp0MpQoRSTKtMJ3ywuJUfq1g4t/tvfOMOmwhE0Bd6Psfp29 +ZjQ6OIEJoItO5Q== X-Google-Smtp-Source: AGHT+IG8TUiO5xGtIQxkKYqtztDo1ilNyy6FvW4+Ir/EDflQtNxbeNuGgHrYLt33IHdx0TE0Cs2pn3JB+VdJeA== X-Received: from pgee23.prod.google.com ([2002:a63:1e17:0:b0:be5:9a9b:6b5d]) (user=skhawaja job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:328b:b0:342:1f0:9af3 with SMTP id adf61e73a8af0-363f5e267c8mr507984637.29.1764716622743; Tue, 02 Dec 2025 15:03:42 -0800 (PST) Date: Tue, 2 Dec 2025 23:02:55 +0000 In-Reply-To: <20251202230303.1017519-1-skhawaja@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251202230303.1017519-1-skhawaja@google.com> X-Mailer: git-send-email 2.52.0.158.g65b55ccf14-goog Message-ID: <20251202230303.1017519-26-skhawaja@google.com> Subject: [RFC PATCH v2 25/32] iommu: Add helper APIs to fetch preserved device state From: Samiullah Khawaja To: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Pasha Tatashin , Jason Gunthorpe , iommu@lists.linux.dev Cc: Samiullah Khawaja , Robin Murphy , Pratyush Yadav , Kevin Tian , Alex Williamson , linux-kernel@vger.kernel.org, Saeed Mahameed , Adithya Jayachandran , Parav Pandit , Leon Romanovsky , William Tu , Vipin Sharma , dmatlack@google.com, YiFei Zhu , Chris Li , praan@google.com Content-Type: text/plain; charset="UTF-8" Add two APIs to fetch state of the preserved devices. An API to iterate through state of all preserved devices and another API to fetch the state of a single preserved device. Note that these APIs only fetch the preserved state from the previous kernel. Signed-off-by: Samiullah Khawaja --- drivers/iommu/liveupdate.c | 68 ++++++++++++++++++++++++++++++++++++++ include/linux/iommu-lu.h | 2 ++ 2 files changed, 70 insertions(+) diff --git a/drivers/iommu/liveupdate.c b/drivers/iommu/liveupdate.c index e7ecf2e9aa4e..1ca97612c501 100644 --- a/drivers/iommu/liveupdate.c +++ b/drivers/iommu/liveupdate.c @@ -175,6 +175,74 @@ int iommu_liveupdate_unregister_flb(struct liveupdate_file_handler *handler) } EXPORT_SYMBOL(iommu_liveupdate_unregister_flb); +int iommu_for_each_preserved_device(int (*fn)(struct device_ser *ser, void *arg), void *arg) +{ + struct iommu_lu_flb_obj *obj; + struct devices_ser *devices; + int ret, i, idx; + + ret = liveupdate_flb_get_incoming(&iommu_flb, (void **)&obj); + if (ret) + return -ENOENT; + + devices = __va(obj->ser->devices_phys); + for (i = 0, idx = 0; i < obj->ser->nr_devices; ++i, ++idx) { + if (idx >= MAX_DEVICE_SERS) { + devices = __va(devices->objs.next_objs); + idx = 0; + } + + if (devices->devices[idx].obj.deleted) + continue; + + ret = fn(&devices->devices[idx], arg); + if (ret) + return ret; + } + + return 0; +} +EXPORT_SYMBOL(iommu_for_each_preserved_device); + +static inline bool device_ser_match(struct device_ser *match, + struct pci_dev *pdev) +{ + return match->devid == pci_dev_id(pdev) && match->pci_domain == pci_domain_nr(pdev->bus); +} + +struct device_ser *iommu_get_device_preserved_data(struct device *dev) +{ + struct iommu_lu_flb_obj *obj; + struct devices_ser *devices; + int ret, i, idx; + + if (!dev_is_pci(dev)) + return NULL; + + ret = liveupdate_flb_get_incoming(&iommu_flb, (void **)&obj); + if (ret) + return NULL; + + devices = __va(obj->ser->devices_phys); + for (i = 0, idx = 0; i < obj->ser->nr_devices; ++i, ++idx) { + if (idx >= MAX_DEVICE_SERS) { + devices = __va(devices->objs.next_objs); + idx = 0; + } + + if (devices->devices[idx].obj.deleted) + continue; + + if (device_ser_match(&devices->devices[idx], to_pci_dev(dev))) { + devices->devices[idx].obj.incoming = true; + return &devices->devices[idx]; + } + } + + return NULL; +} +EXPORT_SYMBOL(iommu_get_device_preserved_data); + struct iommu_ser *iommu_get_preserved_data(u64 token, enum iommu_lu_type type) { struct iommu_lu_flb_obj *obj; diff --git a/include/linux/iommu-lu.h b/include/linux/iommu-lu.h index ffce7043e997..d0226ec19b2f 100644 --- a/include/linux/iommu-lu.h +++ b/include/linux/iommu-lu.h @@ -78,6 +78,8 @@ static inline void *iommu_domain_restored_state(struct iommu_domain *domain) } #endif +int iommu_for_each_preserved_device(int (*fn)(struct device_ser *ser, void *arg), void *arg); +struct device_ser *iommu_get_device_preserved_data(struct device *dev); struct iommu_ser *iommu_get_preserved_data(u64 token, enum iommu_lu_type type); int iommu_domain_preserve(struct iommu_domain *domain, struct iommu_domain_ser **ser); int iommu_domain_unpreserve(struct iommu_domain *domain); -- 2.52.0.158.g65b55ccf14-goog