From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 770DE3090EE for ; Tue, 2 Dec 2025 23:03:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764716621; cv=none; b=lrm6TLahGew3A6UhMkDdjcMCl2vte+U+fxK/l0FcgwcwaPbpqozSByPA6IMt8uOY0FshxWPjU2mK7B46TPP7quo6neY88zJY2qNN7fhqJ/pI7WN8a0Ae8azh/ywG9rZUaTI1siVALoST/wQ17+BRyXePa/jJ3gJn/AOukRCCjvI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764716621; c=relaxed/simple; bh=4cnW5iGvgdtIxwmRjvO4oUOd9FdqD+Hg5A+UkjG79FI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ltHuf01b9jshKBbe2hgws34lbEH6iIiF8zARuKxrx72kHEX7Dj98vKuy8/H//KC7m2jVxEZq2M3fd3OebvFks0hOeO4vWUAcLzZ4D6Le+U0dLShJstV4SWAFtOu4XpcSniWYZhxy1yc1DbaPa82gRsNaZH7FKbaVkIie74dFxGA= 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=OgegIKZL; arc=none smtp.client-ip=209.85.214.202 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="OgegIKZL" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2980ef53fc5so135227525ad.1 for ; Tue, 02 Dec 2025 15:03:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764716620; x=1765321420; 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=J6atgyECODfuH/pey6ac2Fk1KY/d0Gl+LFeR6KszcGM=; b=OgegIKZLqap3ZomNzu8jma8l4JwTugnCwPubnN1sExN0gUaqgq1qM9/QSuLo61qsGG X4dUDdP8mYuqMdJiU3u2lhReqcNMXR8W4OCjQXKfWxbz8I8VjVzMsJnLJec7F/xqj2NM a1gnSQJfuxwDMEvVoz1rvVLap4YR594HoB2CBSJYRsqbdUn0tb9jUAbwzxQAO3V/qpwU aBXP8beYifTFib69ImQaywIxedD/19w9OtaXd1V+7aPAp7VB6WFypL3hWyeuvH++sUUq HtFgqSDZq0kFqYDO7buxVlHPZgHrobV33U2e+C5v1SjiMXnzNmMY0QzwonU9rEA/nq46 Uyzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764716620; x=1765321420; 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=J6atgyECODfuH/pey6ac2Fk1KY/d0Gl+LFeR6KszcGM=; b=ffNpaPZOHuYvLrlc6RgjCE2X+zIxaBshaDKypxZY8UQX/qEJj6PfEhvRLfzJdCcZ/o mzfct6SQ3tWeIiFIKDPcUuhbp7x7HHHqz8xgKEA76eXbeJ0twBb3UnUMwXVxJmBKQG8a OUi0WxxfAK+GVJHvqzr7At2MllQix+4cPKV7IG29BsInVqUw75mFaeWTmtWMtBPVK26M nEa94hrKMf2XyzTZi9ezgX73hcnCubWi2+vyyR71/ns3oSPT3RNrGo4mFLOG+UxHDInO ON2kM9j9Fjv8k/BMm2AVrY+nVROBtLUHLou3hkg3AIDIv72ZYxyaTBr1eskrGNqUziF0 fnNw== X-Forwarded-Encrypted: i=1; AJvYcCV2KpwJgcuxJkc8Qlh24JU1e4jgb1DGEvqc4iPn8e6kYqLkBpJJIobvUEkBl+tQvioFY8Yth1Uq1OhYgY0=@vger.kernel.org X-Gm-Message-State: AOJu0YwuDUHsAwKFG24+MwwY9Xu3HPu7AO84chrHvCb9ltOJepE+xdF5 TGEI9Dhq1UnqiybBBuXEymZMo98eekV8JW0UqI+lEZPlLtlvCfzp7QCIEUSzPH/usMj11WEj2M7 eRoZctIr3ugZolA== X-Google-Smtp-Source: AGHT+IGxdJGTKjpFRs4VBozxyCOqfLHFZCdARJsI5cF6LF6J0BSmgS5pC8M1FIgAl44COPI/zmBCzgRvSdjQ3A== X-Received: from plbbf12.prod.google.com ([2002:a17:902:b90c:b0:290:28e2:ce59]) (user=skhawaja job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:4b0c:b0:295:50cd:e759 with SMTP id d9443c01a7336-29d683de6fcmr2373885ad.58.1764716619737; Tue, 02 Dec 2025 15:03:39 -0800 (PST) Date: Tue, 2 Dec 2025 23:02:53 +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-24-skhawaja@google.com> Subject: [RFC PATCH v2 23/32] iommu: Add an API get the preserved state of an IOMMU 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" After liveupdate kexec during boot, the state of the preserved IOMMU needs to be restored. Since the state needs to be restored by the IOMMU drivers during initialization/registration with the IOMMU core, add an API that can be used by the IOMMU drivers to fetch the preserved state. Signed-off-by: Samiullah Khawaja --- drivers/iommu/liveupdate.c | 29 +++++++++++++++++++++++++++++ include/linux/iommu-lu.h | 1 + 2 files changed, 30 insertions(+) diff --git a/drivers/iommu/liveupdate.c b/drivers/iommu/liveupdate.c index 0dfa03673178..e7ecf2e9aa4e 100644 --- a/drivers/iommu/liveupdate.c +++ b/drivers/iommu/liveupdate.c @@ -175,6 +175,35 @@ int iommu_liveupdate_unregister_flb(struct liveupdate_file_handler *handler) } EXPORT_SYMBOL(iommu_liveupdate_unregister_flb); +struct iommu_ser *iommu_get_preserved_data(u64 token, enum iommu_lu_type type) +{ + struct iommu_lu_flb_obj *obj; + struct iommus_ser *iommus; + int ret, i, idx; + + ret = liveupdate_flb_get_incoming(&iommu_flb, (void **)&obj); + if (ret) + return NULL; + + iommus = __va(obj->ser->iommus_phys); + for (i = 0, idx = 0; i < obj->ser->nr_iommus; ++i, ++idx) { + if (idx >= MAX_IOMMU_SERS) { + iommus = __va(iommus->objs.next_objs); + idx = 0; + } + + if (iommus->iommus[idx].obj.deleted) + continue; + + if (iommus->iommus[idx].token == token && + iommus->iommus[idx].type == type) + return &iommus->iommus[idx]; + } + + return NULL; +} +EXPORT_SYMBOL(iommu_get_preserved_data); + static int reserve_obj_ser(struct iommu_objs_ser **objs_ptr, u64 max_objs) { struct iommu_objs_ser *next_objs, *objs = *objs_ptr; diff --git a/include/linux/iommu-lu.h b/include/linux/iommu-lu.h index 08a659de8553..ffce7043e997 100644 --- a/include/linux/iommu-lu.h +++ b/include/linux/iommu-lu.h @@ -78,6 +78,7 @@ static inline void *iommu_domain_restored_state(struct iommu_domain *domain) } #endif +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); int iommu_preserve_device(struct iommu_domain *domain, struct device *dev); -- 2.52.0.158.g65b55ccf14-goog