From nobody Sun Feb 8 01:52:05 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 306ED1397 for ; Sat, 18 Oct 2025 00:07:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746047; cv=none; b=nBQn8I2+LYCNjN67CaPFm6Ie8PfYOVmyyo36gMODeothNfRInHDWYL7QPW797hyQEmdHAurMwafRSAFlJhOQSB09gNaNUm0H8hG4HVjQvzFdvhf4NUxdg2F/i+8w7djayzK/+yIE+t3dE7xL90R5/dUQOz2jOfuSudS9Uz4GQak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746047; c=relaxed/simple; bh=jNj/t1fXmQozileACwtwMKU1XXKgVwEcRRV43j27iqI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QG3MfiUJ+RKN/5RwAeYnG06KLiWWGv/bu0J3ImS6l7jfWUr+Dfdwg27C/oew907L0uICUxdWI1mIMC8BtuTIeGseRFscA5PGeS/taHVJvFT4ww2iU1qF2zgA4hbPofFoWBLXC+pcWdl3Qtus369Wr4VUFWxWjbOMRBotjXNyP44= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=y9w0DEBy; arc=none smtp.client-ip=209.85.216.74 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="y9w0DEBy" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-33428befc49so3923057a91.0 for ; Fri, 17 Oct 2025 17:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746045; x=1761350845; 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=lIRdeTDVJnSPIQ4l7UYy+dVw1HMydqx25E2KK+QEeEY=; b=y9w0DEByeQX4BZdteKUn9Iyw6KYGLPnqvMcGfNHzYxRpE4CNCyI4V1j9OjtQMedxt+ lYTPw0H25yPHlVCeD8Nj+zmLIfS2Wtm7KVIXQBxeEWrHnILfM68vSQwGMIcEN+I3KKZp JG8ex+PBT/nOyq9BwcbGYcpMnmIpSetgtA3iZ1O0VHdWpLY8fEC8g4kuaLMmazORCcas 3DsBomkoqdU8Es6FOmmOvzx6MrMqTtRfRWlXtnv6zU/0L1I1VV9yj3G7X71k4hopdAwr bL3viY6dvsBKl8REXR/XIsgOG3J5jq70qRCVoooZWgyT3dXo0WW9J4YfJXCJqtA52LEj DXCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746045; x=1761350845; 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=lIRdeTDVJnSPIQ4l7UYy+dVw1HMydqx25E2KK+QEeEY=; b=qQHtjP7mhNCK9rRxTErkaaYgX5z5MNoSRVzSILSPOuQ/UBC1mfrRw1MbOkQtOaabhL oUdmpAHMoRTwu9GJUCUyGGgL/Ftgh2nK0qMWlDaqxyYD6T8dhryDCQYsrx7xwNNDENxg iWH87hpkJNl6a9i57AlMM2hmzrm/uzYfpq/4FjZRugQjgAAUHQd+N2hzCl2MjJArTrP8 cmBCZMVDWHhtbjdw7xcLUlHBYQkhxB6bRX3a0AvbsNVQxoCd2cc3HDp0n9c1SMI65plE vxUGWODSzasD5UTFc5RiRaNIlh0NLJyvPXjfC5s+fQ0nWwmUoKkWge7aonA+PTAsc8VD 0pbA== X-Forwarded-Encrypted: i=1; AJvYcCWRnPaUyASBS62vM4LAB3bhffk1QnF4v2uGKzIRUBw4Hxs5P6Z/yllwZ4NoM/wP5nnhc4C2GQs/V552k5I=@vger.kernel.org X-Gm-Message-State: AOJu0YxnGqzS5Cwm28V41LYAud9q2h4ryBdt6CP2Pna6W72MD0SAtNIk TM/J+tpYrUGN5SfXzqK7CpfG22SJkr8dRxyXsmAmXPzDLjYr/IGwaqwmxXLnc1CzbGAfumXcB7a qU5viGtqi/Q== X-Google-Smtp-Source: AGHT+IGpNneZjiyeUgiPSOA0Ff+L/EkC9zJCByYhGlasmrVLxnfDuFjE0n/3azWJkzCxNEVHDOKe34jfRpQ7 X-Received: from pjg7.prod.google.com ([2002:a17:90b:3f47:b0:330:7dd8:2dc2]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1f82:b0:330:c522:6138 with SMTP id 98e67ed59e1d1-33b9e0a80f6mr11300701a91.8.1760746045501; Fri, 17 Oct 2025 17:07:25 -0700 (PDT) Date: Fri, 17 Oct 2025 17:06:53 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-2-vipinsh@google.com> Subject: [RFC PATCH 01/21] selftests/liveupdate: Build tests from the selftests/liveupdate directory From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Build selftests from liveupdate directory Signed-off-by: Vipin Sharma --- tools/testing/selftests/liveupdate/.gitignore | 7 ++++-- tools/testing/selftests/liveupdate/Makefile | 25 ++++++++++--------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/liveupdate/.gitignore b/tools/testing/= selftests/liveupdate/.gitignore index de7ca45d3892..da3a50a32aeb 100644 --- a/tools/testing/selftests/liveupdate/.gitignore +++ b/tools/testing/selftests/liveupdate/.gitignore @@ -1,2 +1,5 @@ -/liveupdate -/luo_multi_kexec +liveupdate +luo_multi_kexec +luo_multi_file +luo_multi_session +luo_unreclaimed diff --git a/tools/testing/selftests/liveupdate/Makefile b/tools/testing/se= lftests/liveupdate/Makefile index 25a6dec790bb..fbcacbd1b798 100644 --- a/tools/testing/selftests/liveupdate/Makefile +++ b/tools/testing/selftests/liveupdate/Makefile @@ -1,10 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only =20 -KHDR_INCLUDES ?=3D -I../../../usr/include -CFLAGS +=3D -Wall -O2 -Wno-unused-function -CFLAGS +=3D $(KHDR_INCLUDES) -LDFLAGS +=3D -static - # --- Test Configuration (Edit this section when adding new tests) --- LUO_SHARED_SRCS :=3D luo_test_utils.c LUO_SHARED_HDRS +=3D luo_test_utils.h @@ -25,6 +20,12 @@ TEST_GEN_PROGS :=3D $(LUO_MAIN_TESTS) =20 liveupdate_SOURCES :=3D liveupdate.c $(LUO_SHARED_SRCS) =20 +include ../lib.mk + +CFLAGS +=3D -Wall -O2 -Wno-unused-function +CFLAGS +=3D $(KHDR_INCLUDES) +LDFLAGS +=3D -static + $(OUTPUT)/liveupdate: $(liveupdate_SOURCES) $(LUO_SHARED_HDRS) $(call msg,LINK,,$@) $(Q)$(LINK.c) $^ $(LDLIBS) -o $@ @@ -33,16 +34,16 @@ $(OUTPUT)/liveupdate: $(liveupdate_SOURCES) $(LUO_SHARE= D_HDRS) $(foreach test,$(LUO_MANUAL_TESTS), \ $(eval $(test)_SOURCES :=3D $(test).c $(LUO_SHARED_SRCS))) =20 +define BUILD_RULE_TEMPLATE +$(OUTPUT)/$(1): $($(1)_SOURCES) $(LUO_SHARED_HDRS) + $(call msg,LINK,,$$@) + $(Q)$(LINK.c) $$^ $(LDLIBS) -o $$@ + $(Q)chmod +x $$@ +endef # This loop automatically generates an explicit build rule for each manual= test. # It includes dependencies on the shared headers and makes the output # executable. # Note the use of '$$' to escape automatic variables for the 'eval' comman= d. $(foreach test,$(LUO_MANUAL_TESTS), \ - $(eval $(OUTPUT)/$(test): $($(test)_SOURCES) $(LUO_SHARED_HDRS) \ - $(call msg,LINK,,$$@) ; \ - $(Q)$(LINK.c) $$^ $(LDLIBS) -o $$@ ; \ - $(Q)chmod +x $$@ \ - ) \ + $(eval $(call BUILD_RULE_TEMPLATE,$(test))) \ ) - -include ../lib.mk --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:05 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 175AAEAF9 for ; Sat, 18 Oct 2025 00:07:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746049; cv=none; b=PGR0lgKi8+VBxH5XP7rgNW3RnNyBvO+NpzOX2A7LyPtGEtSvZDa+U3AQbc/B4N/kQQy1MCG0rehDSGdcKGvLgqI3zyx9472Y0343ALvIALQQFaOgiTp9DHVFBsVF+abjCt0TVcFYCAECiQfgFO+yXm4zLx1w1HxIE62RiGGfWMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746049; c=relaxed/simple; bh=im+NROWrioLAUoKDcU09gT2O29uHv1ZmiGbPd4DQRmA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EGic/q79Gg46dpUtZn0Mq7txZX7sXRipr2gVnKZLYMtBKxl7HATU9XvIuy39pKh74fQKa+y9MHjLkh0awfTZ1B+aCDjGCTLFgOgWvdudYe/N6P3yA39F++Plfsks/avOiXJPYD8V61Cg5FHEI2df1gLRmFfb7/UwxaDylgk3GDo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=kbR9T3Om; arc=none smtp.client-ip=209.85.216.74 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kbR9T3Om" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-32eaa47c7c8so1981567a91.3 for ; Fri, 17 Oct 2025 17:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746047; x=1761350847; 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=TOMpaEfu4XDoTJxqADAIr7pPqza8QEwPDO10nSptr+w=; b=kbR9T3OmQXmuFr53LJzhhSY27qM7Y0YEtiuNVP3wbv2peVkeuKnni4j5IULcyo8hO5 rbwUQVrboGd7NKeN/nulONuBk+rOV03BRc9MHdWGXiDFGo0WbyemHYWScIRBVYHFzSO3 j/7Na8mtkYnyoS69gI8WlH1BAhfoHZOpeHwFnefyIcZtP2TRIRDbtjPeepmTPkPoBLQO W05MjYw0ErFzJCSgrKLdMAH6r3z4EGPfUws+EI/kjjtybXUJ82HlYzyFWmAeFzfbhj59 B9Ff/TXJ6LHVe/+3GIw8fkcaxYGC6r5I+5Xily0WyAi/gYYVDo3AJ0nzh4YyjqDGYFVb 0Xqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746047; x=1761350847; 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=TOMpaEfu4XDoTJxqADAIr7pPqza8QEwPDO10nSptr+w=; b=To+NwPgDFPEMPQgPxQCQ7YbwNM7zNvtpoRp5bznMi03IHPxrQhZJluKsGR94uyTfOC d8scn9SBua9OAh1bqbsIBxFWy8oLJQde708xh9+51ULRrsTyEIkTMdu2EBtcQas8Bq1q O4boRyVDQhIeQ/Ou7WtmQQRW0Dqhn5Szv4dFVhCZbrin/pV6RFhQBtj/ao9wzpX6DDSB DU/5a3Jld+beMwNlB7BGBrsaca0w8iMWejw29q5KDErxqBTAN+P9gsVgehDfggOjsTGc tGYXmnBELMlepi+cZmtc4cbugqDoXkaqyqiXJX2dHwf0H8ElAhaNo2Y0vG7uI00nKdLf MJPA== X-Forwarded-Encrypted: i=1; AJvYcCV0JlOIX9bykFpozfNUM18pmLdbmge6q6JDlkH5WosgFMSwEbMaLTNJLak3jyl2hG2IEruyMmpU7ecrCw0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxr4UAiZyR4n1NyNDLMoPbd37QGTB9M0X2BGdaZ49TV2DLC+rL3 7hoczfogg5ha5Bb5uKkrJk7UC24DSqr7Rc3btDqy/AOXvbYo/UY/kkBD9qA4Wc7+rfTjc0Viryh EA7NkIbwlCA== X-Google-Smtp-Source: AGHT+IGrRMKQ0oOHM8/+DeUTvxakoLf63/yRNJYFuzUrt0w+O2bY/RazLDAQzrZ9LelmGXwMAfCodkPK+Jmb X-Received: from pjop7.prod.google.com ([2002:a17:90a:9307:b0:33b:aa58:175c]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:d408:b0:33b:dec9:d9aa with SMTP id 98e67ed59e1d1-33bdec9da92mr4818277a91.25.1760746047288; Fri, 17 Oct 2025 17:07:27 -0700 (PDT) Date: Fri, 17 Oct 2025 17:06:54 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-3-vipinsh@google.com> Subject: [RFC PATCH 02/21] selftests/liveupdate: Create library of core live update ioctls From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Create liveupdate_util.mk library of core live update APIs which can be shared outside of liveupdate selftests, for example, VFIO selftests. Shared library avoids the need for VFIO to define its own APIs to interact with liveupdate ioctls. No functional changes intended, in this patch only few functions are moved to library without changing the code. Signed-off-by: Vipin Sharma --- tools/testing/selftests/liveupdate/Makefile | 6 +- .../liveupdate/lib/include/liveupdate_util.h | 23 +++++++ .../selftests/liveupdate/lib/libliveupdate.mk | 17 +++++ .../liveupdate/lib/liveupdate_util.c | 68 +++++++++++++++++++ .../selftests/liveupdate/luo_test_utils.c | 55 +-------------- .../selftests/liveupdate/luo_test_utils.h | 10 +-- 6 files changed, 114 insertions(+), 65 deletions(-) create mode 100644 tools/testing/selftests/liveupdate/lib/include/liveupda= te_util.h create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk create mode 100644 tools/testing/selftests/liveupdate/lib/liveupdate_util.c diff --git a/tools/testing/selftests/liveupdate/Makefile b/tools/testing/se= lftests/liveupdate/Makefile index fbcacbd1b798..79d1c525f03c 100644 --- a/tools/testing/selftests/liveupdate/Makefile +++ b/tools/testing/selftests/liveupdate/Makefile @@ -26,7 +26,9 @@ CFLAGS +=3D -Wall -O2 -Wno-unused-function CFLAGS +=3D $(KHDR_INCLUDES) LDFLAGS +=3D -static =20 -$(OUTPUT)/liveupdate: $(liveupdate_SOURCES) $(LUO_SHARED_HDRS) +include lib/libliveupdate.mk + +$(OUTPUT)/liveupdate: $(liveupdate_SOURCES) $(LUO_SHARED_HDRS) $(LIBLIVEUP= DATE_O) $(call msg,LINK,,$@) $(Q)$(LINK.c) $^ $(LDLIBS) -o $@ =20 @@ -35,7 +37,7 @@ $(foreach test,$(LUO_MANUAL_TESTS), \ $(eval $(test)_SOURCES :=3D $(test).c $(LUO_SHARED_SRCS))) =20 define BUILD_RULE_TEMPLATE -$(OUTPUT)/$(1): $($(1)_SOURCES) $(LUO_SHARED_HDRS) +$(OUTPUT)/$(1): $($(1)_SOURCES) $(LUO_SHARED_HDRS) $(LIBLIVEUPDATE_O) $(call msg,LINK,,$$@) $(Q)$(LINK.c) $$^ $(LDLIBS) -o $$@ $(Q)chmod +x $$@ diff --git a/tools/testing/selftests/liveupdate/lib/include/liveupdate_util= .h b/tools/testing/selftests/liveupdate/lib/include/liveupdate_util.h new file mode 100644 index 000000000000..f938ce60edb7 --- /dev/null +++ b/tools/testing/selftests/liveupdate/lib/include/liveupdate_util.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +#ifndef SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_UTIL_H +#define SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_UTIL_H + +#include + +#define LUO_DEVICE "/dev/liveupdate" + +int luo_open_device(void); +int luo_create_session(int luo_fd, const char *name); +int luo_retrieve_session(int luo_fd, const char *name); + +int luo_set_session_event(int session_fd, enum liveupdate_event event); +int luo_set_global_event(int luo_fd, enum liveupdate_event event); +int luo_get_global_state(int luo_fd, enum liveupdate_state *state); + +#endif /* SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_UTIL_H */ diff --git a/tools/testing/selftests/liveupdate/lib/libliveupdate.mk b/tool= s/testing/selftests/liveupdate/lib/libliveupdate.mk new file mode 100644 index 000000000000..b3fc2580a7cf --- /dev/null +++ b/tools/testing/selftests/liveupdate/lib/libliveupdate.mk @@ -0,0 +1,17 @@ +LIBLIVEUPDATE_SRCDIR :=3D $(selfdir)/liveupdate/lib + +LIBLIVEUPDATE_C :=3D liveupdate_util.c + +LIBLIVEUPDATE_OUTPUT :=3D $(OUTPUT)/libliveupdate + +LIBLIVEUPDATE_O :=3D $(patsubst %.c, $(LIBLIVEUPDATE_OUTPUT)/%.o, $(LIBLIV= EUPDATE_C)) + +LIBLIVEUPDATE_O_DIRS :=3D $(shell dirname $(LIBLIVEUPDATE_O) | uniq) +$(shell mkdir -p $(LIBLIVEUPDATE_O_DIRS)) + +CFLAGS +=3D -I$(LIBLIVEUPDATE_SRCDIR)/include + +$(LIBLIVEUPDATE_O): $(LIBLIVEUPDATE_OUTPUT)/%.o : $(LIBLIVEUPDATE_SRCDIR)/= %.c + $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ + +EXTRA_CLEAN +=3D $(LIBLIVEUPDATE_OUTPUT) \ No newline at end of file diff --git a/tools/testing/selftests/liveupdate/lib/liveupdate_util.c b/too= ls/testing/selftests/liveupdate/lib/liveupdate_util.c new file mode 100644 index 000000000000..1e6fd9dd8fb9 --- /dev/null +++ b/tools/testing/selftests/liveupdate/lib/liveupdate_util.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include + +int luo_open_device(void) +{ + return open(LUO_DEVICE, O_RDWR); +} + +int luo_create_session(int luo_fd, const char *name) +{ + struct liveupdate_ioctl_create_session arg =3D { .size =3D sizeof(arg) }; + + snprintf((char *)arg.name, LIVEUPDATE_SESSION_NAME_LENGTH, "%.*s", + LIVEUPDATE_SESSION_NAME_LENGTH - 1, name); + if (ioctl(luo_fd, LIVEUPDATE_IOCTL_CREATE_SESSION, &arg) < 0) + return -errno; + return arg.fd; +} + +int luo_retrieve_session(int luo_fd, const char *name) +{ + struct liveupdate_ioctl_retrieve_session arg =3D { .size =3D sizeof(arg) = }; + + snprintf((char *)arg.name, LIVEUPDATE_SESSION_NAME_LENGTH, "%.*s", + LIVEUPDATE_SESSION_NAME_LENGTH - 1, name); + if (ioctl(luo_fd, LIVEUPDATE_IOCTL_RETRIEVE_SESSION, &arg) < 0) + return -errno; + return arg.fd; +} + +int luo_set_session_event(int session_fd, enum liveupdate_event event) +{ + struct liveupdate_session_set_event arg =3D { .size =3D sizeof(arg) }; + + arg.event =3D event; + return ioctl(session_fd, LIVEUPDATE_SESSION_SET_EVENT, &arg); +} + +int luo_set_global_event(int luo_fd, enum liveupdate_event event) +{ + struct liveupdate_ioctl_set_event arg =3D { .size =3D sizeof(arg) }; + + arg.event =3D event; + return ioctl(luo_fd, LIVEUPDATE_IOCTL_SET_EVENT, &arg); +} + +int luo_get_global_state(int luo_fd, enum liveupdate_state *state) +{ + struct liveupdate_ioctl_get_state arg =3D { .size =3D sizeof(arg) }; + + if (ioctl(luo_fd, LIVEUPDATE_IOCTL_GET_STATE, &arg) < 0) + return -errno; + *state =3D arg.state; + return 0; +} diff --git a/tools/testing/selftests/liveupdate/luo_test_utils.c b/tools/te= sting/selftests/liveupdate/luo_test_utils.c index c0840e6e66fd..0f5bc7260ccc 100644 --- a/tools/testing/selftests/liveupdate/luo_test_utils.c +++ b/tools/testing/selftests/liveupdate/luo_test_utils.c @@ -17,39 +17,12 @@ #include #include #include - +#include #include "luo_test_utils.h" #include "../kselftest.h" =20 /* The fail_exit function is now a macro in the header. */ =20 -int luo_open_device(void) -{ - return open(LUO_DEVICE, O_RDWR); -} - -int luo_create_session(int luo_fd, const char *name) -{ - struct liveupdate_ioctl_create_session arg =3D { .size =3D sizeof(arg) }; - - snprintf((char *)arg.name, LIVEUPDATE_SESSION_NAME_LENGTH, "%.*s", - LIVEUPDATE_SESSION_NAME_LENGTH - 1, name); - if (ioctl(luo_fd, LIVEUPDATE_IOCTL_CREATE_SESSION, &arg) < 0) - return -errno; - return arg.fd; -} - -int luo_retrieve_session(int luo_fd, const char *name) -{ - struct liveupdate_ioctl_retrieve_session arg =3D { .size =3D sizeof(arg) = }; - - snprintf((char *)arg.name, LIVEUPDATE_SESSION_NAME_LENGTH, "%.*s", - LIVEUPDATE_SESSION_NAME_LENGTH - 1, name); - if (ioctl(luo_fd, LIVEUPDATE_IOCTL_RETRIEVE_SESSION, &arg) < 0) - return -errno; - return arg.fd; -} - int create_and_preserve_memfd(int session_fd, int token, const char *data) { struct liveupdate_session_preserve_fd arg =3D { .size =3D sizeof(arg) }; @@ -119,32 +92,6 @@ int restore_and_verify_memfd(int session_fd, int token, return ret; } =20 -int luo_set_session_event(int session_fd, enum liveupdate_event event) -{ - struct liveupdate_session_set_event arg =3D { .size =3D sizeof(arg) }; - - arg.event =3D event; - return ioctl(session_fd, LIVEUPDATE_SESSION_SET_EVENT, &arg); -} - -int luo_set_global_event(int luo_fd, enum liveupdate_event event) -{ - struct liveupdate_ioctl_set_event arg =3D { .size =3D sizeof(arg) }; - - arg.event =3D event; - return ioctl(luo_fd, LIVEUPDATE_IOCTL_SET_EVENT, &arg); -} - -int luo_get_global_state(int luo_fd, enum liveupdate_state *state) -{ - struct liveupdate_ioctl_get_state arg =3D { .size =3D sizeof(arg) }; - - if (ioctl(luo_fd, LIVEUPDATE_IOCTL_GET_STATE, &arg) < 0) - return -errno; - *state =3D arg.state; - return 0; -} - void create_state_file(int luo_fd, int next_stage) { char buf[32]; diff --git a/tools/testing/selftests/liveupdate/luo_test_utils.h b/tools/te= sting/selftests/liveupdate/luo_test_utils.h index e30cfcb0a596..4d371b528a01 100644 --- a/tools/testing/selftests/liveupdate/luo_test_utils.h +++ b/tools/testing/selftests/liveupdate/luo_test_utils.h @@ -11,9 +11,9 @@ #include #include #include +#include #include "../kselftest.h" =20 -#define LUO_DEVICE "/dev/liveupdate" #define STATE_SESSION_NAME "state_session" #define STATE_MEMFD_TOKEN 999 =20 @@ -30,19 +30,11 @@ struct session_info { ksft_exit_fail_msg("[%s] " fmt " (errno: %s)\n", \ __func__, ##__VA_ARGS__, strerror(errno)) =20 -int luo_open_device(void); - -int luo_create_session(int luo_fd, const char *name); -int luo_retrieve_session(int luo_fd, const char *name); =20 int create_and_preserve_memfd(int session_fd, int token, const char *data); int restore_and_verify_memfd(int session_fd, int token, const char *expect= ed_data); int verify_session_and_get_fd(int luo_fd, struct session_info *s); =20 -int luo_set_session_event(int session_fd, enum liveupdate_event event); -int luo_set_global_event(int luo_fd, enum liveupdate_event event); -int luo_get_global_state(int luo_fd, enum liveupdate_state *state); - void create_state_file(int luo_fd, int next_stage); int restore_and_read_state(int luo_fd, int *stage); void update_state_file(int session_fd, int next_stage); --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:05 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 788002DF68 for ; Sat, 18 Oct 2025 00:07:29 +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=1760746051; cv=none; b=RmhSAE/HWKuvV4APDRmOT2eGju9zOILiY61q8G3mrqtvXg1QzqJZs/o4+RrhO9o2i6wzi49gufbmeHnKRpz66yVWlepJrn8nDOnjjDHGyb2edNPhqtekqznCyDsv5691ZgzXuIaTIMEhJtlnZoEYNHyVdO/emT7z48izh9vUmqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746051; c=relaxed/simple; bh=J9W4VofzNPHVJcydvT+7yYMBRwGznJMzR/aHNqN3grE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ql4ckVsAj0oUVef5e8NBiU9wISLZhPDYREwDjVKLskzzyOmj22FY6j7fdxT3ovNP3dQUzmrEOPXPzikGOV5Q11nI6QIq2qBvBPiNUv1a+Q8l4WmTC8z9jriwjR00KMLpOXygI/wwJaFRj276iXuXbRRA++AZ32/h9wW0ZHkAn0Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QEabLOPQ; 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QEabLOPQ" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-290b13c5877so46627085ad.0 for ; Fri, 17 Oct 2025 17:07:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746049; x=1761350849; 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=zrXpTUXsPRdectGWUXdK6/cWMJ1EivPtVPHR+juuW6U=; b=QEabLOPQUwbbLyMxpVp3U0LZmIJklkAhqX6/xeKJuJPje/Eg4CBGpcc7dQVSgYK3XK 1pxRZacq3zM4Fsapzvt6F/7cCvlVUHfqdjRjphlJBymj6eX8uLBhkJmGyDTgttr34f6/ qdMGOKZpeTwrQben9U8Xi/AvX136X2ygl1i+WVRj1n/1A0XjXTw2TOGEpdvrH/TCXCgb UVqnXsDaIgrSDJgZsrZha7czFF6MirNcZzkE92T5EYt6ZZkvqSyy/l3anKg1E5u5ZoOg PF9xwe2yywCoyy4j8kyCZuT7R0CScKCcwjVNX5NVtRjOk7xrWAeVfxbxGNYuMbOlsdfj jWDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746049; x=1761350849; 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=zrXpTUXsPRdectGWUXdK6/cWMJ1EivPtVPHR+juuW6U=; b=lPemHpfaj05EFN8KpeG8K8DVxCa3MyrjWHmLA74iB6OtItMWNnaa2n6EqVpB32ULlJ ZQxqzZ9zVSYxiIZ5z6MfGkOvkxK+FRGwWQfm51hG1XQSdjhM0Pv+ZxzMiJ4jDHNSH4in Y1oxHAQ4mxHFMo/FCfoDPIX+lqt3JZBFJ+CpxXzioGDsy2CIfAJ98L/KWNQurXq4rmYx waaZ5LprfCtevnxHPsP8G8L+5dvaFBY3sLbLusM1eo2j6K2jSdF13ldAzvsqhtchTWom an1uo6Qn5SR0jU4CH19/N+McIvaBqxkUAZKeERQP9DrAyyD6x/QDP7BylQE81gmF/XLc e8Yg== X-Forwarded-Encrypted: i=1; AJvYcCXAbccb3LC7a7JuWBHD3B7TEsgXsXS0mrCwbfKPO69hLbW/j1IzDQB/jD9WuRWdGCwlyq930MWHzeVHKeE=@vger.kernel.org X-Gm-Message-State: AOJu0YwVnSuZL2I5XyYY17Mcx3WcZgq+bcanNmu+QMtw8WdwQTiVEONt QcinYYvFuAzirGpnU9pIzv4DMdK24NdToCmLRYzYYcMyfGlS8Kdf0WPU91j3yjkfIjZmFlL3em0 oq0+unHZyWw== X-Google-Smtp-Source: AGHT+IHW64ddk30kYxy1u6aO7zkiAGN29Y3gtXXrzh6xaAbx/wQ5vxDGnCf0Gb8SvNpdO7t14/3mEhrMGD6V X-Received: from plri16.prod.google.com ([2002:a17:903:32d0:b0:268:11e:8271]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ce12:b0:279:daa1:6780 with SMTP id d9443c01a7336-290cba41dd2mr64939455ad.52.1760746048654; Fri, 17 Oct 2025 17:07:28 -0700 (PDT) Date: Fri, 17 Oct 2025 17:06:55 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-4-vipinsh@google.com> Subject: [RFC PATCH 03/21] selftests/liveupdate: Move do_kexec.sh script to liveupdate/lib From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move do_kexec.sh to lib directory in the liveupdate selftest directory. Add code in libliveupdate.mk to copy the script to generated libliveupdate directory during the build. Script allows liveupdate library users to initiate kexec for liveupdate test flows. Signed-off-by: Vipin Sharma --- tools/testing/selftests/liveupdate/Makefile | 2 -- .../selftests/liveupdate/{ =3D> lib}/do_kexec.sh | 0 .../liveupdate/lib/include/liveupdate_util.h | 2 ++ .../testing/selftests/liveupdate/lib/libliveupdate.mk | 1 + .../selftests/liveupdate/lib/liveupdate_util.c | 11 +++++++++++ tools/testing/selftests/liveupdate/luo_multi_file.c | 2 -- tools/testing/selftests/liveupdate/luo_multi_kexec.c | 2 -- .../testing/selftests/liveupdate/luo_multi_session.c | 2 -- tools/testing/selftests/liveupdate/luo_unreclaimed.c | 1 - 9 files changed, 14 insertions(+), 9 deletions(-) rename tools/testing/selftests/liveupdate/{ =3D> lib}/do_kexec.sh (100%) diff --git a/tools/testing/selftests/liveupdate/Makefile b/tools/testing/se= lftests/liveupdate/Makefile index 79d1c525f03c..f203fd681afe 100644 --- a/tools/testing/selftests/liveupdate/Makefile +++ b/tools/testing/selftests/liveupdate/Makefile @@ -9,8 +9,6 @@ LUO_MANUAL_TESTS +=3D luo_multi_kexec LUO_MANUAL_TESTS +=3D luo_multi_session LUO_MANUAL_TESTS +=3D luo_unreclaimed =20 -TEST_FILES +=3D do_kexec.sh - LUO_MAIN_TESTS +=3D liveupdate =20 # --- Automatic Rule Generation (Do not edit below) --- diff --git a/tools/testing/selftests/liveupdate/do_kexec.sh b/tools/testing= /selftests/liveupdate/lib/do_kexec.sh similarity index 100% rename from tools/testing/selftests/liveupdate/do_kexec.sh rename to tools/testing/selftests/liveupdate/lib/do_kexec.sh diff --git a/tools/testing/selftests/liveupdate/lib/include/liveupdate_util= .h b/tools/testing/selftests/liveupdate/lib/include/liveupdate_util.h index f938ce60edb7..6ee9e124a1a4 100644 --- a/tools/testing/selftests/liveupdate/lib/include/liveupdate_util.h +++ b/tools/testing/selftests/liveupdate/lib/include/liveupdate_util.h @@ -11,10 +11,12 @@ #include =20 #define LUO_DEVICE "/dev/liveupdate" +#define KEXEC_SCRIPT "libliveupdate/do_kexec.sh" =20 int luo_open_device(void); int luo_create_session(int luo_fd, const char *name); int luo_retrieve_session(int luo_fd, const char *name); +int luo_session_preserve_fd(int session_fd, int fd, int token); =20 int luo_set_session_event(int session_fd, enum liveupdate_event event); int luo_set_global_event(int luo_fd, enum liveupdate_event event); diff --git a/tools/testing/selftests/liveupdate/lib/libliveupdate.mk b/tool= s/testing/selftests/liveupdate/lib/libliveupdate.mk index b3fc2580a7cf..ddb9b1a4363b 100644 --- a/tools/testing/selftests/liveupdate/lib/libliveupdate.mk +++ b/tools/testing/selftests/liveupdate/lib/libliveupdate.mk @@ -8,6 +8,7 @@ LIBLIVEUPDATE_O :=3D $(patsubst %.c, $(LIBLIVEUPDATE_OUTPUT= )/%.o, $(LIBLIVEUPDATE_ =20 LIBLIVEUPDATE_O_DIRS :=3D $(shell dirname $(LIBLIVEUPDATE_O) | uniq) $(shell mkdir -p $(LIBLIVEUPDATE_O_DIRS)) +$(shell cp -n $(LIBLIVEUPDATE_SRCDIR)/do_kexec.sh $(LIBLIVEUPDATE_OUTPUT)) =20 CFLAGS +=3D -I$(LIBLIVEUPDATE_SRCDIR)/include =20 diff --git a/tools/testing/selftests/liveupdate/lib/liveupdate_util.c b/too= ls/testing/selftests/liveupdate/lib/liveupdate_util.c index 1e6fd9dd8fb9..26fd6a7763a2 100644 --- a/tools/testing/selftests/liveupdate/lib/liveupdate_util.c +++ b/tools/testing/selftests/liveupdate/lib/liveupdate_util.c @@ -30,6 +30,17 @@ int luo_create_session(int luo_fd, const char *name) return arg.fd; } =20 +int luo_session_preserve_fd(int session_fd, int fd, int token) +{ + struct liveupdate_session_preserve_fd arg =3D { + .size =3D sizeof(arg), + .fd =3D fd, + .token =3D token + }; + + return ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0; +} + int luo_retrieve_session(int luo_fd, const char *name) { struct liveupdate_ioctl_retrieve_session arg =3D { .size =3D sizeof(arg) = }; diff --git a/tools/testing/selftests/liveupdate/luo_multi_file.c b/tools/te= sting/selftests/liveupdate/luo_multi_file.c index ae38fe8aba4c..1a4f95046c75 100644 --- a/tools/testing/selftests/liveupdate/luo_multi_file.c +++ b/tools/testing/selftests/liveupdate/luo_multi_file.c @@ -7,8 +7,6 @@ =20 #include "luo_test_utils.h" =20 -#define KEXEC_SCRIPT "./do_kexec.sh" - #define SESSION_NAME "multi_file_session" #define TOKEN_A 101 #define TOKEN_B 102 diff --git a/tools/testing/selftests/liveupdate/luo_multi_kexec.c b/tools/t= esting/selftests/liveupdate/luo_multi_kexec.c index 1f350990ee67..5cfecbc6d269 100644 --- a/tools/testing/selftests/liveupdate/luo_multi_kexec.c +++ b/tools/testing/selftests/liveupdate/luo_multi_kexec.c @@ -7,8 +7,6 @@ =20 #include "luo_test_utils.h" =20 -#define KEXEC_SCRIPT "./do_kexec.sh" - #define NUM_SESSIONS 3 =20 /* Helper to set up one session and all its files */ diff --git a/tools/testing/selftests/liveupdate/luo_multi_session.c b/tools= /testing/selftests/liveupdate/luo_multi_session.c index 9ea96d7b997f..389d4b559cb3 100644 --- a/tools/testing/selftests/liveupdate/luo_multi_session.c +++ b/tools/testing/selftests/liveupdate/luo_multi_session.c @@ -8,8 +8,6 @@ #include "luo_test_utils.h" #include "../kselftest.h" =20 -#define KEXEC_SCRIPT "./do_kexec.sh" - #define NUM_SESSIONS 5 #define FILES_PER_SESSION 5 =20 diff --git a/tools/testing/selftests/liveupdate/luo_unreclaimed.c b/tools/t= esting/selftests/liveupdate/luo_unreclaimed.c index c3921b21b97b..b31bb354bfc3 100644 --- a/tools/testing/selftests/liveupdate/luo_unreclaimed.c +++ b/tools/testing/selftests/liveupdate/luo_unreclaimed.c @@ -8,7 +8,6 @@ #include "luo_test_utils.h" #include "../kselftest.h" =20 -#define KEXEC_SCRIPT "./do_kexec.sh" =20 #define SESSION_NAME "unreclaimed_session" #define TOKEN_A 100 --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:05 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 D34A54C6D for ; Sat, 18 Oct 2025 00:07:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746052; cv=none; b=WK3Zsjor1qyD1e/7V6TE3LVNTi2wTFtT+UdG2UMV00kEGkYJ1xze64IOieH7mZuSUhefOptb5PXjmDomeH03sc6EvFMj1GcsoVWsUwxPj5kWanV+GjLBZf2RVMh309uXwZHTThW3X/8v9auG/nVOUNWoD+oAThETsSOBglqgtpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746052; c=relaxed/simple; bh=afY24gYMOzFwsN2znmzSRT26NkKpjbP7o7rl1ElinpE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=W6Tj5n3KjQp9QNoVLg9swnArqIsc2Zg63NOYlwiHo86vN5z1Pv/3UQ1afhRhZ33EdocX3dhbENh4p7uc/8pAj1zDPUR8inlUQnB6mSZXkbWkvc9OhVy3Cw6/oonji8L/TXt67MQCc8TxXUmB99/LModU6j3XPYawDNntzIlU9Fc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=oGVikpJR; arc=none smtp.client-ip=209.85.215.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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oGVikpJR" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b5535902495so1508417a12.0 for ; Fri, 17 Oct 2025 17:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746050; x=1761350850; 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=PNSocxtpFlgaY+aG50c0yJJqecHAawBvtAXPRByH/ak=; b=oGVikpJRWfx1eKWBOyvjW+yHfgyLS2+dTuKRql4FyluA9hkvehtSSNiF79yNJzxvd9 pUcrGsKrXbrVJOk1ZXZdKndVgyeLOMah8CL4EhBIxZokaYg2OGYcuYKBnYknHyPxU+rR Yc1mM94AsV92yh59xPsZ/YKhiPcGAKAObpfNvQU23eRSEeZ1CDF78CkL6iOdeZiSJo+9 3GRvd3a9cSjozKjBqOeOGPJxvjz05non/WPSSONS8BMug2Z4tsjnCQUyRpGM4xIlAmJt BbPXiYopTghsMWxCW/Dgw9L4aPtPn9tsq26ALCK9JbRbLoxdEkwCLRs1rq3Pmn6GAF2P OL3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746050; x=1761350850; 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=PNSocxtpFlgaY+aG50c0yJJqecHAawBvtAXPRByH/ak=; b=QjaAvJFpTV6K6kWGjUVFgpvgSknfrUOGPMIx8K+wJ/3NXPW8nUNDe9uhajiqFHB7rF HitfLpXbeQW2IlJMENjus6AVVIuUbWSTJyqRtHoCJRXICkUsPvfnVgCBk0714FB7wCuw QZeoZ0AS6k5p8RIAe5UJjPWdcMLZIJeL7ksREks1E2fJ4zZ0js7B3BEbXpOSwAbdNE9w M2pmKx5Gpehi0im3h1V5gzrdy+Ur0r773fE6Vtbpo+2oKvLVK6RZcFIJk8FNo3tLUqfm N7uNii4s1X+zq8wb17Ey6xoADs+UTNKg0Eme9TT9WlTwtQAi3NHS5QgN6QU/QupLksbq OV8g== X-Forwarded-Encrypted: i=1; AJvYcCXoSEa5KoRPOXGzfK/8a+1ymASleKA7FlAZFMjGv7xe9H+JW26Oad7r9FgV/ydTuiKsbX+bwFEAfPVe+RM=@vger.kernel.org X-Gm-Message-State: AOJu0YxFS6lPlRWUzeu2/ef+ryhfTGUKPlazr1rvLWc0E8WfOZAONOTI R6ZLnR2xBkiyEGfbpnIzxDosL+vffM060k2ieKKUNpZyP291TAnmuEnmmuCe+81nAMG3O7TPee2 pnKmNmq/inA== X-Google-Smtp-Source: AGHT+IGw3qLr2xyC1p/SJ0aBXpD18mw5iWsbxD0rBPbyjKzntb2EOMPX2k2cG3q5ct1J4a+SmbU/supTz48u X-Received: from plpd3.prod.google.com ([2002:a17:903:1b63:b0:290:d7ff:80f8]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2411:b0:26c:e270:6dad with SMTP id d9443c01a7336-290ccadb0bcmr53515935ad.60.1760746050041; Fri, 17 Oct 2025 17:07:30 -0700 (PDT) Date: Fri, 17 Oct 2025 17:06:56 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-5-vipinsh@google.com> Subject: [RFC PATCH 04/21] selftests/liveupdate: Move LUO ioctls calls to liveupdate library From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move liveupdate ioctls call to liveupdate library. This allows single place for luo ioctl interactions and provide other selftests to access them. Signed-off-by: Vipin Sharma --- .../liveupdate/lib/include/liveupdate_util.h | 2 ++ .../liveupdate/lib/liveupdate_util.c | 29 ++++++++++++++++++- .../selftests/liveupdate/luo_test_utils.c | 18 ++++-------- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/liveupdate/lib/include/liveupdate_util= .h b/tools/testing/selftests/liveupdate/lib/include/liveupdate_util.h index 6ee9e124a1a4..a5cb034f7692 100644 --- a/tools/testing/selftests/liveupdate/lib/include/liveupdate_util.h +++ b/tools/testing/selftests/liveupdate/lib/include/liveupdate_util.h @@ -17,6 +17,8 @@ int luo_open_device(void); int luo_create_session(int luo_fd, const char *name); int luo_retrieve_session(int luo_fd, const char *name); int luo_session_preserve_fd(int session_fd, int fd, int token); +int luo_session_unpreserve_fd(int session_fd, int token); +int luo_session_restore_fd(int session_fd, int token); =20 int luo_set_session_event(int session_fd, enum liveupdate_event event); int luo_set_global_event(int luo_fd, enum liveupdate_event event); diff --git a/tools/testing/selftests/liveupdate/lib/liveupdate_util.c b/too= ls/testing/selftests/liveupdate/lib/liveupdate_util.c index 26fd6a7763a2..96c6c1b65043 100644 --- a/tools/testing/selftests/liveupdate/lib/liveupdate_util.c +++ b/tools/testing/selftests/liveupdate/lib/liveupdate_util.c @@ -38,7 +38,34 @@ int luo_session_preserve_fd(int session_fd, int fd, int = token) .token =3D token }; =20 - return ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0; + if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0) + return -errno; + return 0; +} + +int luo_session_unpreserve_fd(int session_fd, int token) +{ + struct liveupdate_session_unpreserve_fd arg =3D { + .size =3D sizeof(arg), + .token =3D token + }; + + if (ioctl(session_fd, LIVEUPDATE_SESSION_UNPRESERVE_FD, &arg) < 0) + return -errno; + return 0; +} + +int luo_session_restore_fd(int session_fd, int token) +{ + struct liveupdate_session_restore_fd arg =3D { + .size =3D sizeof(arg), + .token =3D token + }; + + if (ioctl(session_fd, LIVEUPDATE_SESSION_RESTORE_FD, &arg) < 0) + return -errno; + return arg.fd; + } =20 int luo_retrieve_session(int luo_fd, const char *name) diff --git a/tools/testing/selftests/liveupdate/luo_test_utils.c b/tools/te= sting/selftests/liveupdate/luo_test_utils.c index 0f5bc7260ccc..b1f7b5c79c07 100644 --- a/tools/testing/selftests/liveupdate/luo_test_utils.c +++ b/tools/testing/selftests/liveupdate/luo_test_utils.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -25,7 +24,6 @@ =20 int create_and_preserve_memfd(int session_fd, int token, const char *data) { - struct liveupdate_session_preserve_fd arg =3D { .size =3D sizeof(arg) }; long page_size =3D sysconf(_SC_PAGE_SIZE); void *map =3D MAP_FAILED; int mfd =3D -1, ret =3D -1; @@ -44,9 +42,7 @@ int create_and_preserve_memfd(int session_fd, int token, = const char *data) snprintf(map, page_size, "%s", data); munmap(map, page_size); =20 - arg.fd =3D mfd; - arg.token =3D token; - if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0) + if (luo_session_preserve_fd(session_fd, mfd, token)) goto out; =20 ret =3D 0; /* Success */ @@ -61,15 +57,13 @@ int create_and_preserve_memfd(int session_fd, int token= , const char *data) int restore_and_verify_memfd(int session_fd, int token, const char *expected_data) { - struct liveupdate_session_restore_fd arg =3D { .size =3D sizeof(arg) }; long page_size =3D sysconf(_SC_PAGE_SIZE); void *map =3D MAP_FAILED; int mfd =3D -1, ret =3D -1; =20 - arg.token =3D token; - if (ioctl(session_fd, LIVEUPDATE_SESSION_RESTORE_FD, &arg) < 0) - return -errno; - mfd =3D arg.fd; + mfd =3D luo_session_restore_fd(session_fd, token); + if (mfd < 0) + return mfd; =20 map =3D mmap(NULL, page_size, PROT_READ, MAP_SHARED, mfd, 0); if (map =3D=3D MAP_FAILED) @@ -134,10 +128,8 @@ int restore_and_read_state(int luo_fd, int *stage) void update_state_file(int session_fd, int next_stage) { char buf[32]; - struct liveupdate_session_unpreserve_fd arg =3D { .size =3D sizeof(arg) }; =20 - arg.token =3D STATE_MEMFD_TOKEN; - if (ioctl(session_fd, LIVEUPDATE_SESSION_UNPRESERVE_FD, &arg) < 0) + if (luo_session_unpreserve_fd(session_fd, STATE_MEMFD_TOKEN)) fail_exit("unpreserve failed"); =20 snprintf(buf, sizeof(buf), "%d", next_stage); --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:05 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 7A1CA156661 for ; Sat, 18 Oct 2025 00:07:32 +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=1760746055; cv=none; b=lpMP1abt3BfP7DG2G2aITy8/6AkOZB0vqSEdIPTMcesr5W3z7F1g75nygavWXbWQRTBCci1MPMmrxmjxX/nHCIdJdfOeR2ZlienDY+PgyMoGEecrpo4UQ9gnfFv88HKqrNUh7/rNJIxVosTBaUpxziTcK7MBnKoW6lO2pZIyZW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746055; c=relaxed/simple; bh=WqoyuRvOF/KaAj4Kamg+Ll5XCZ1wJiFiYb83JG8QyCI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QO5+efWw3QKViiSitUy7owzr6KXpFscizJ+lHABxn5793w7PHihS2nQML4nEuVYXmPkQReH9IfaGLJJpU6E5+M+9VlVky23kOlhmQZxSwQnPIJrQUYYc2vMksR1r02JfQbQY+1lJz71bpf/fMAsvRLE+v7mR1LFWdOXqtFnisAo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=N8k8baR5; 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="N8k8baR5" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-26983c4d708so20777135ad.3 for ; Fri, 17 Oct 2025 17:07:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746052; x=1761350852; 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=TGD7bzX0Kq7IaGb+QpC13kgMXesYLGgf6obE0wlZYvA=; b=N8k8baR5x0TMJ5BpjROOTS4lWz+jivd7/GSXln/iBlHs7y5VsQe6XV5Qcov0dWGyQi WAcNV/BTmJ2qRf13/D0/winfvFWIavnaBJgxkVQ1bTBJ1AOdUMVw6+DUIbN3JYKX9FxT wJ9/6fIf/C2N6OTOQpTNZ+O/ho16oFWzegOtuKo+jQYaNdNeLMJ2TUVpUeULqaa9AJ7O QjqUOsyuNvwZNIDbu/wyZ3mDYSQ0ZlME9xX+mCcPxy4r73Q0ypJYg1OlHB1yQIzam9VG 1XTBe1qVPCLl2FSperYKbyeVjdR8W5mzuxw+f1lcfyVdKvTELbY52gcDSk7dQyYwmoYe ngNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746052; x=1761350852; 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=TGD7bzX0Kq7IaGb+QpC13kgMXesYLGgf6obE0wlZYvA=; b=Bey7UldKwVHVmNXPgNmiLKYP3as/hQHw41eOocfZU10MQRueXkGRvSo9FMBg2DbqiV 3GvClN2Q0+FpC6yWlo1W9XpWQzplAYxfSUFruJJTz7ivpJ6pckmOEfIuC5nfR5bwMiQZ HNsSVDcyGZWfoDBuFJdZ9Pu19Gie/h+095ptZgPLVS6s8zWb9hn6/G9mXYu18hEN4rij E4TulKPVyg17Si89uZ1U9ZINITfYk2nXQLJN2kajbw4s7khjMzxAdokxJODyC/xkFc/K vXgH9MSul6MhA0+Ie9PH6epU9Qtxi7kOVmyqdiUn+2VRFTA9HvcCj0fDrU7dg9LsG1mK vxpg== X-Forwarded-Encrypted: i=1; AJvYcCV9wBarS5kgnCjI5BjdV7vH3l4kqe5fhZSEPiiXdei/KpmRMhEoCdCHNnrsXbYALwJwep6gFpbd1sC4bEU=@vger.kernel.org X-Gm-Message-State: AOJu0YzZB9Dj17jJ6TitpGH+1PKylf69MxPXe5Me+YzgsdkYCmnvWVFQ WiVup1m9d2Z0MIMJcapIPH2wxqJpvGtLMKn7NsxCHvlpMt3/+GTu89RYC7dXGpQBCXunM4OgiE5 V3+oAjjbSiQ== X-Google-Smtp-Source: AGHT+IHJ850JrI8smUyVofUcQEbNFuf48VMG6+VFF6lU6eFbmxUPuJB2Z6EpOhYs4AAVGwT4qh1u+uj/tQ7N X-Received: from pjg7.prod.google.com ([2002:a17:90b:3f47:b0:330:7dd8:2dc2]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:fc4b:b0:290:8d7b:4047 with SMTP id d9443c01a7336-290c9cbc4c9mr66393955ad.21.1760746051767; Fri, 17 Oct 2025 17:07:31 -0700 (PDT) Date: Fri, 17 Oct 2025 17:06:57 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-6-vipinsh@google.com> Subject: [RFC PATCH 05/21] vfio/pci: Register VFIO live update file handler to Live Update Orchestrator From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Register VFIO live update file handler to Live Update Orchestrator. Provide stub implementation of the handler callbacks. Adding live update support in VFIO will enable a VFIO PCI device to work uninterrupted while the host kernel is being updated through a kexec reboot. Signed-off-by: Vipin Sharma --- drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci_core.c | 1 + drivers/vfio/pci/vfio_pci_liveupdate.c | 44 ++++++++++++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 6 ++++ 4 files changed, 52 insertions(+) create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c diff --git a/drivers/vfio/pci/Makefile b/drivers/vfio/pci/Makefile index cf00c0a7e55c..929df22c079b 100644 --- a/drivers/vfio/pci/Makefile +++ b/drivers/vfio/pci/Makefile @@ -2,6 +2,7 @@ =20 vfio-pci-core-y :=3D vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio= _pci_config.o vfio-pci-core-$(CONFIG_VFIO_PCI_ZDEV_KVM) +=3D vfio_pci_zdev.o +vfio-pci-core-$(CONFIG_LIVEUPDATE) +=3D vfio_pci_liveupdate.o obj-$(CONFIG_VFIO_PCI_CORE) +=3D vfio-pci-core.o =20 vfio-pci-y :=3D vfio_pci.o diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_c= ore.c index 7dcf5439dedc..0894673a9262 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -2568,6 +2568,7 @@ static void vfio_pci_core_cleanup(void) static int __init vfio_pci_core_init(void) { /* Allocate shared config space permission data used by all devices */ + vfio_pci_liveupdate_init(); return vfio_pci_init_perm_bits(); } =20 diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c new file mode 100644 index 000000000000..088f7698a72c --- /dev/null +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Liveupdate support for VFIO devices. + * + * Copyright (c) 2025, Google LLC. + * Vipin Sharma + */ + +#include +#include + +#include "vfio_pci_priv.h" + +static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_handler *ha= ndler, + u64 data, struct file **file) +{ + return -EOPNOTSUPP; +} + +static bool vfio_pci_liveupdate_can_preserve(struct liveupdate_file_handle= r *handler, + struct file *file) +{ + return -EOPNOTSUPP; +} + +static const struct liveupdate_file_ops vfio_pci_luo_fops =3D { + .retrieve =3D vfio_pci_liveupdate_retrieve, + .can_preserve =3D vfio_pci_liveupdate_can_preserve, + .owner =3D THIS_MODULE, +}; + +static struct liveupdate_file_handler vfio_pci_luo_handler =3D { + .ops =3D &vfio_pci_luo_fops, + .compatible =3D "vfio-v1", +}; + +void __init vfio_pci_liveupdate_init(void) +{ + int err =3D liveupdate_register_file_handler(&vfio_pci_luo_handler); + + if (err) + pr_err("VFIO PCI liveupdate file handler register failed, error %d.\n", = err); +} diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_p= riv.h index a9972eacb293..7779fd744ff5 100644 --- a/drivers/vfio/pci/vfio_pci_priv.h +++ b/drivers/vfio/pci/vfio_pci_priv.h @@ -107,4 +107,10 @@ static inline bool vfio_pci_is_vga(struct pci_dev *pde= v) return (pdev->class >> 8) =3D=3D PCI_CLASS_DISPLAY_VGA; } =20 +#ifdef CONFIG_LIVEUPDATE +void vfio_pci_liveupdate_init(void); +#else +static inline void vfio_pci_liveupdate_init(void) { } +#endif /* CONFIG_LIVEUPDATE */ + #endif --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:05 2026 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 6B553185E4A for ; Sat, 18 Oct 2025 00:07:34 +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=1760746056; cv=none; b=ekfVF0SfcW5zxgqeNnNrLqEtbLgn3CoSbgab3SV/U6w8e4pJW7ReU9fL+ybAXZRABZPX/jIHBx+D2QMB2K+BAJ3OzEPC2tgHGjwgsix4ZZxPyepWVNk4b9P2HB8YYBEoshpUeDSdShEMQ2blUX7oSPR5Enz4pKgsR3osLDCenWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746056; c=relaxed/simple; bh=Vz1emZSFssQs0+YdiAhMnV1XqK+h1rcwL5bhHE+USAs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PDCqObNwC3fqPRok34dhSW78E0HRKLpslHCo6X1V0iw7T6pt9xTlxyt5ZEuznbsrUbHhBQMUrmf0v9BE1p0w/aSs6A1n5udMxjXK7yIyLvJOTJfY4np0esZDcDQpCYklIB3X+WLRaDDj2E/2ABawm7kOlIoy7orgh6hEhkgRM+0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=r/fvEjjf; 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="r/fvEjjf" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-28a5b8b12bbso54595835ad.2 for ; Fri, 17 Oct 2025 17:07:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746054; x=1761350854; 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=yIRcwATFxVO1gYHmeyRDqu9oMXg8jJOvYeDFaGHRVhk=; b=r/fvEjjfsCtoWhCTv0je1iCzroYsxTgEp0bbQWgUb3cvfj6N2fEqhdisCsqXP21dFp Y8mL0b8cCufcQrlc3Wf9Pqr+T/XoiGCOpo1KJg4gadjISsjD7ry3thvZkpG80lfvhaVB X9LPTx8+r+k30DIILkPHKZWm1OCAckqQzShDeeBf6/cA5PXzdPU0Rvjhy4ejIqO7n5BY pDf/CsWVZbCB23Jv9eLAU2TR5P91vkoJadEPEkdU3gtM/HvCirB9NFarP68Kka4uDftz 2wflEk8a3LnC/pGxbSYdx2mMFapkO9pmDGkY6ePm3bCI6+ztH64MieEtTVEEnNjWkXq8 q/ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746054; x=1761350854; 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=yIRcwATFxVO1gYHmeyRDqu9oMXg8jJOvYeDFaGHRVhk=; b=IiDlFomwlQfRhnlw6vVIInnuW9IXXJXX0pJ3plZK6ODY7ZU1V16tyrA88ajlcmRTuO lo6e2C8BSAsdyEy/dKPfLxumD4xMq0XLWuT0vgoUa0PndGKOn6ShkKtmxYMcS3sunzlC PJDYzCavBdiSXhtFForvzLv1eOIezwmCB8mTU1ablEa0vNpmgm3v7KvNtY1T+xJ9z312 wm++gLN2apYZFgvB+kvhlCyJZMJfym4PkK6yyM4OpdNe8o1X1cJJS971UcXN2IhjTxNg IkZPetMogw3vQWmvO4AU6C4sRJMB2G9tP7PgqRI23FsF8cD8S/nZLIWsPKPz/Bq6TTMK 2Img== X-Forwarded-Encrypted: i=1; AJvYcCVaRnfbZMrPhKFIKJr9L+3zLKnjaqJ5xw+mHhovOsWjzkDKBvzU0hF0+mrkfToqNtNWCmNCLWABtP3G69Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yzat7jcHAzN4/uDKKFZtR7P74h57AlT19oFMCmhyq/8S/SaEBKE o01tsM9+7Q/E5tGeJe40KJ1Ms+lcEy1Gfepmffpz1JeymBlCpFbagBuS7+CzIs/EGEKWfA1Wuu6 NafUht+LZdw== X-Google-Smtp-Source: AGHT+IEmJd19+BB5PjOWAQmwa3QYicq41jg2KgMlRdI0Qd+a/0AOATqoFt4XxbQkB/KEUkYDvJMU7BdKVEY5 X-Received: from pllb6.prod.google.com ([2002:a17:902:e946:b0:290:bbbe:b3d4]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1106:b0:27e:f07c:8413 with SMTP id d9443c01a7336-290c9cf8f3amr67057365ad.9.1760746053570; Fri, 17 Oct 2025 17:07:33 -0700 (PDT) Date: Fri, 17 Oct 2025 17:06:58 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-7-vipinsh@google.com> Subject: [RFC PATCH 06/21] vfio/pci: Accept live update preservation request for VFIO cdev From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Return true in can_preserve() callback of live update file handler, if VFIO can preserve the passed VFIO cdev file. Return -EOPNOTSUPP from prepare() callback for now to fail any attempt to preserve VFIO cdev in live update. The VFIO cdev opened check ensures that the file is actually used for VFIO cdev and not for VFIO device FD which can be obtained from the VFIO group. Returning true from can_preserve() tells Live Update Orchestrator that VFIO can try to preserve the given file during live update. Actual preservation logic will be added in future patches, therefore, for now, prepare call will fail. Signed-off-by: Vipin Sharma --- drivers/vfio/pci/vfio_pci_liveupdate.c | 16 +++++++++++++++- drivers/vfio/vfio_main.c | 3 ++- include/linux/vfio.h | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index 088f7698a72c..2ce2c11cb51c 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -8,10 +8,17 @@ */ =20 #include +#include #include =20 #include "vfio_pci_priv.h" =20 +static int vfio_pci_liveupdate_prepare(struct liveupdate_file_handler *han= dler, + struct file *file, u64 *data) +{ + return -EOPNOTSUPP; +} + static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_handler *ha= ndler, u64 data, struct file **file) { @@ -21,10 +28,17 @@ static int vfio_pci_liveupdate_retrieve(struct liveupda= te_file_handler *handler, static bool vfio_pci_liveupdate_can_preserve(struct liveupdate_file_handle= r *handler, struct file *file) { - return -EOPNOTSUPP; + struct vfio_device *device =3D vfio_device_from_file(file); + + if (!device) + return false; + + guard(mutex)(&device->dev_set->lock); + return vfio_device_cdev_opened(device); } =20 static const struct liveupdate_file_ops vfio_pci_luo_fops =3D { + .prepare =3D vfio_pci_liveupdate_prepare, .retrieve =3D vfio_pci_liveupdate_retrieve, .can_preserve =3D vfio_pci_liveupdate_can_preserve, .owner =3D THIS_MODULE, diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index 38c8e9350a60..4cb47c1564f4 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -1386,7 +1386,7 @@ const struct file_operations vfio_device_fops =3D { #endif }; =20 -static struct vfio_device *vfio_device_from_file(struct file *file) +struct vfio_device *vfio_device_from_file(struct file *file) { struct vfio_device_file *df =3D file->private_data; =20 @@ -1394,6 +1394,7 @@ static struct vfio_device *vfio_device_from_file(stru= ct file *file) return NULL; return df->device; } +EXPORT_SYMBOL_GPL(vfio_device_from_file); =20 /** * vfio_file_is_valid - True if the file is valid vfio file diff --git a/include/linux/vfio.h b/include/linux/vfio.h index eb563f538dee..2443d24aa237 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -385,4 +385,6 @@ int vfio_virqfd_enable(void *opaque, int (*handler)(voi= d *, void *), void vfio_virqfd_disable(struct virqfd **pvirqfd); void vfio_virqfd_flush_thread(struct virqfd **pvirqfd); =20 +struct vfio_device *vfio_device_from_file(struct file *file); + #endif /* VFIO_H */ --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:06 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 D924319C566 for ; Sat, 18 Oct 2025 00:07:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746057; cv=none; b=JUuVbd+r6Cd+6HFWEDfDPcfzALMv7JFhEhUT6aAcuJPhKIYylWNuznYwot558fp9+x6rTz2hKZoZNn5uaXsjx4kfNn940A5W2PSLLMcRekJryy7OHFl1MyLFlappnTOP/WYWihYCF7gCvOjN46AJ3e7M2uJC95oT9KaqwLK/opI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746057; c=relaxed/simple; bh=9kz7IeKfS4YgzfgKMPszd7/uCUEYDB0UKs2xeqOId+E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ezlXHwalf+Mrck+Ja35TxScZOUMnZYuvP31HPvKtsd5+MpkFyWVOCTnG+EDkwge+b2u7yEdU17AvbAw4fjCnEgj14dsg1RlwezzKodM91yPdvF2eeUy3+VH8jHkDpm5M6vPtiDus8Td/3lGUoJmQhDiHdRVwpm7xNmQtHR/GVt4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=4hHZszIy; arc=none smtp.client-ip=209.85.216.74 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4hHZszIy" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-33428befc49so3923140a91.0 for ; Fri, 17 Oct 2025 17:07:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746055; x=1761350855; 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=FsS9kFTR9UD975XBprEHxRtCq2p91h3XBSwxLrbiSS8=; b=4hHZszIyICDX684inLL4qqhvefcGlVk81E1+bYgkII9xXJlx6fhPBFAoLa6RUzSi7c Ab0GOmYq84zm/RF74ssl/qJDKT8khHszASsgn964lqaFdlvy3gMv3Gi6CsTQGbEOHW3O IT1AbJ5bq5yyZTOK+1fkGbo5OVHqnKMFhLsHtsmBebIt++z6l+b0QwZPLl/8zWj88LP3 EIAfqoLHzv5GXxSnyxkYQXJ6olw2VmeU4oK34kuzHwY4IStATJThFlbxo98wMiudSJGG FupCI+JjwG7kghVmKWndEn2lbGaEFhyeMOwo10Rh4k+pVuhU5afh0M6oyQgzy2IHvzSi 0hrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746055; x=1761350855; 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=FsS9kFTR9UD975XBprEHxRtCq2p91h3XBSwxLrbiSS8=; b=BLC5B3Gh012UTu3+L4jKBLus9VAA4owaw2TvXCh3zFJDaIHkkT0bsIm7qckwo4ar/0 n6VenCWjtZYUuHK3hFY182mURJbLuUqsknbrx4edQZRDrNm0WhjS9LWJIDpJQ0XDUAm4 kMxp2hIdbrOgD6sE/5D2dk5poLp3GsjBcAu38zTywHS2qc+vkCG9/OUa3aWrw4fhA0jk iCsIp5j+uMwIybCfdaR6ONBZHsK5+IVWZqS+yA6vmioTfOpIf+BydthXYR5iYK8xAsld l0FWtHfuXBtxvdBBi4jD7YfYnpq5AvWdk2KkTgwkDV1rkWwI/eZCSKOvd7GalGWEO8C1 t/6A== X-Forwarded-Encrypted: i=1; AJvYcCXYnjN3YDFbdX7SOEtzJtq834LmbuFlT04DtOp69U0vglm3uxJTCOr4M5EB2dMoKCJX4drtuvuYw43g15E=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1K27yRRfo75dQNfQK2HuG8YdoG4rYJVrN56Epp0Sqik0ZFhqO JPjRkRi4pDdMco7ZECNFbEGqjURBlujPaZfZxMB+6OqTKEfI+eODArc5XLQIELO/oTWlRQMc3Iw O6MZSu00AQw== X-Google-Smtp-Source: AGHT+IGRIAXsRYc0Ud2iJi9huekvodTNwMahs7Yf+RSITKDZqjl7U0MJ3wXRjz337obRdzxOo9SfX8Vmvxkg X-Received: from pjbml19.prod.google.com ([2002:a17:90b:3613:b0:33b:ba58:40a6]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:d406:b0:32d:e027:9b26 with SMTP id 98e67ed59e1d1-33bc9d1a8e6mr7604436a91.13.1760746055286; Fri, 17 Oct 2025 17:07:35 -0700 (PDT) Date: Fri, 17 Oct 2025 17:06:59 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-8-vipinsh@google.com> Subject: [RFC PATCH 07/21] vfio/pci: Store VFIO PCI device preservation data in KHO for live update From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Create a struct to serialize VFIO PCI data and preserve it using KHO. Provide physical address of the folio to Live Update Orchestrator (LUO) in prepare() callback so that LUO can give it back after kexec. Unpreserve and free the folio in cancel() callback. Store PCI BDF value in the serialized data. BDF value is unique for each device on a host and remains same unless hardware or firmware is changed. Preserving BDF value allows VFIO to find the PCI device which LUO wants to restore in retrieve() callback after kexec. In future patches, more meaningful data will be serialized to actually preserve working of the device. Signed-off-by: Vipin Sharma --- drivers/vfio/pci/vfio_pci_liveupdate.c | 54 +++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index 2ce2c11cb51c..3eb4895ce475 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -10,13 +10,64 @@ #include #include #include +#include =20 #include "vfio_pci_priv.h" =20 +struct vfio_pci_core_device_ser { + u16 bdf; +} __packed; + +static int vfio_pci_lu_serialize(struct vfio_pci_core_device *vdev, + struct vfio_pci_core_device_ser *ser) +{ + ser->bdf =3D pci_dev_id(vdev->pdev); + return 0; +} + static int vfio_pci_liveupdate_prepare(struct liveupdate_file_handler *han= dler, struct file *file, u64 *data) { - return -EOPNOTSUPP; + struct vfio_pci_core_device_ser *ser; + struct vfio_pci_core_device *vdev; + struct vfio_device *device; + struct folio *folio; + int err; + + device =3D vfio_device_from_file(file); + vdev =3D container_of(device, struct vfio_pci_core_device, vdev); + + folio =3D folio_alloc(GFP_KERNEL | __GFP_ZERO, get_order(sizeof(*ser))); + if (!folio) + return -ENOMEM; + + ser =3D folio_address(folio); + + err =3D vfio_pci_lu_serialize(vdev, ser); + if (err) + goto err_free_folio; + + err =3D kho_preserve_folio(folio); + if (err) + goto err_free_folio; + + *data =3D virt_to_phys(ser); + + return 0; + +err_free_folio: + folio_put(folio); + return err; +} + +static void vfio_pci_liveupdate_cancel(struct liveupdate_file_handler *han= dler, + struct file *file, u64 data) +{ + struct vfio_pci_core_device_ser *ser =3D phys_to_virt(data); + struct folio *folio =3D virt_to_folio(ser); + + WARN_ON_ONCE(kho_unpreserve_folio(folio)); + folio_put(folio); } =20 static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_handler *ha= ndler, @@ -39,6 +90,7 @@ static bool vfio_pci_liveupdate_can_preserve(struct liveu= pdate_file_handler *han =20 static const struct liveupdate_file_ops vfio_pci_luo_fops =3D { .prepare =3D vfio_pci_liveupdate_prepare, + .cancel =3D vfio_pci_liveupdate_cancel, .retrieve =3D vfio_pci_liveupdate_retrieve, .can_preserve =3D vfio_pci_liveupdate_can_preserve, .owner =3D THIS_MODULE, --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:06 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 A35F11AF0B6 for ; Sat, 18 Oct 2025 00:07:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746059; cv=none; b=CLhhvcUu/bKeBUZLcUynHKkR6+n44OwyS0TQt/EKPMjfEdTyT1HHTUoH1q6yfLe1NsoIqR9wbkYsU0YDluQ1nUENkbZvJEefZ3kTZiuQh2hxj5vPDyuNvy6h3bDmfWzCnuj+2FcTrjvvgB664KmPeN0rGDt5vyEFTxxAcehn8kc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746059; c=relaxed/simple; bh=5Tvh5T5jgvY1ILBJN58+80uZX1/0HkAVQpK1u+wobjs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rg4f7Yqbci2LBjYt36waRvx+bYnQTG0WB+eMIaOEk9UDLZhPrLBPjRyySfQ6t9165PlCHKu76DtexbPsu5GFUCwxeq4Teg6VAeZOuKKVMojqeQd4ouGV87b7bM2t/hSoOmmVmqKvnJKjzvwpc2ACH5EhIUi3cpY7iJKzavhDV10= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=q2oa+Ok0; arc=none smtp.client-ip=209.85.216.73 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="q2oa+Ok0" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-33ba9047881so3245532a91.1 for ; Fri, 17 Oct 2025 17:07:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746057; x=1761350857; 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=LvhaOW8wRH/YY3gXapCStWhtrT1s7EfXHsuUhL9CnVU=; b=q2oa+Ok0n6FK/5Q/NrhbtNSlRpaybu1FmnWWJG5xwMWvEHfaMkBoQTEPwa1AlHZYqs cWiennp336Cv1nwGX1uKsyvUWlRlehg7Mc3ytvYU2jNVMlvX5DKCoZIyYEIjpH6+GaxN dCm+8PfMgnii/Yacak9i+x5A3HyobcVvbVebK5yjYVk5zJdX225dOm4qULs/uvULJtU9 GNW0OYhoUJSQSeZ0gedrKN6byn/T20mPE5iPxXLtHBRhhA5MJL7zm4gA9y0qDzrs0zog Eknx3w6MssRYFyjJAUYMIHNA6fYeYmCRN1GEGvjVR4B7YbYyVesey+1KkVBaIJVCXsb8 tq2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746057; x=1761350857; 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=LvhaOW8wRH/YY3gXapCStWhtrT1s7EfXHsuUhL9CnVU=; b=vMED3Qf/hn7gZkB0arP/uJEcbu6hJYmIlY3HYndsG2wpSSysOHQIDzMXU81U0t18hg 3LPuW9bL8nmBe3tqEQ7dQm14mXFMdcKmvJ4RnS0AwA7epvthQB9bF2LhGgueQD+LCmc3 V2rGY1TzxSjU5CHFtVJ7Gmbwxw0j+7LfdF4X2VMrrs2oehvx3YeAw9nRKSFZ/9B9XYmi 6STsKaDGFoVQ977MvALaqNPOrPCJ4pRFm2IGOP1dn040M3+wS69Mp2v+cYAyZTpfnRFi ODlgX0OLD/zKwC9/An0lDv6OVvxLTB0Mn12aOvQW+T6EAUC5ARqAiardzG3/YBgwUFBH UTtA== X-Forwarded-Encrypted: i=1; AJvYcCXql+FxiZdk430Ew32CN4lQU9vvtmTYsWuSQUBPk09HxCWrSIv1y0tL/FFxXhDJOOH7Pa6JqtS0KMMPV6g=@vger.kernel.org X-Gm-Message-State: AOJu0YzZpFJ4u9TUZjxrh3bDNKg0TpNJOs1zS33qIl+5LPru3/ekTphv PUgyKoDcVZyoahgpA++fu9Nnqh83sL8wM9DhyQokFkrtcbjR8WKmpD55nSxkDCH989GUvYQIz+v 35urMnPj/Mg== X-Google-Smtp-Source: AGHT+IEajdXrHklRoghqoCMeB0s0/wpRhkS0+hlDw6WmAOENbeivy0YrxeuPlRkhdT/oRdtLhvut8dPK/58W X-Received: from pjbtd12.prod.google.com ([2002:a17:90b:544c:b0:330:b9e9:7acc]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4ecb:b0:32e:72bd:6d5a with SMTP id 98e67ed59e1d1-33bc9b77679mr6907875a91.1.1760746057054; Fri, 17 Oct 2025 17:07:37 -0700 (PDT) Date: Fri, 17 Oct 2025 17:07:00 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-9-vipinsh@google.com> Subject: [RFC PATCH 08/21] vfio/pci: Retrieve preserved VFIO device for Live Update Orechestrator From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Retrieve VFIO device in the retrieve() callback of the LUO file handler. Deserialize the KHO data and search in the VFIO cdev class for device matching the BDF. Export needed functions from core VFIO module to others. Create anonymous inode and file struct for the device. This is similar to how VFIO group returns VFIO device FD. This is different than VFIO cdev where cdev device is connected to inode and file on devtempfs. Signed-off-by: Vipin Sharma --- drivers/vfio/pci/vfio_pci_liveupdate.c | 67 +++++++++++++++++++++++++- drivers/vfio/vfio_main.c | 17 +++++++ include/linux/vfio.h | 6 +++ 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index 3eb4895ce475..cb3ff097afbf 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -10,7 +10,9 @@ #include #include #include +#include #include +#include =20 #include "vfio_pci_priv.h" =20 @@ -70,10 +72,73 @@ static void vfio_pci_liveupdate_cancel(struct liveupdat= e_file_handler *handler, folio_put(folio); } =20 +static int match_bdf(struct device *device, const void *bdf) +{ + struct vfio_device *core_vdev =3D + container_of(device, struct vfio_device, device); + struct vfio_pci_core_device *vdev =3D + container_of(core_vdev, struct vfio_pci_core_device, vdev); + + return *(u16 *)bdf =3D=3D pci_dev_id(vdev->pdev); +} + static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_handler *ha= ndler, u64 data, struct file **file) { - return -EOPNOTSUPP; + struct vfio_pci_core_device_ser *ser; + struct vfio_device_file *df; + struct vfio_device *device; + struct folio *folio; + struct file *filep; + int err; + + folio =3D kho_restore_folio(data); + if (!folio) + return -ENOENT; + + ser =3D folio_address(folio); + device =3D vfio_find_device_in_cdev_class(&ser->bdf, match_bdf); + if (!device) + return -ENODEV; + + df =3D vfio_allocate_device_file(device); + if (IS_ERR(df)) { + err =3D PTR_ERR(df); + goto err_vfio_device_file; + } + + filep =3D anon_inode_getfile_fmode("[vfio-cdev]", &vfio_device_fops, df, + O_RDWR, FMODE_PREAD | FMODE_PWRITE); + if (IS_ERR(filep)) { + err =3D PTR_ERR(filep); + goto err_anon_inode; + } + + /* Paired with the put in vfio_device_fops_release() */ + if (!vfio_device_try_get_registration(device)) { + err =3D -ENODEV; + goto err_get_registration; + } + + put_device(&device->device); + + /* + * Use the pseudo fs inode on the device to link all mmaps + * to the same address space, allowing us to unmap all vmas + * associated to this device using unmap_mapping_range(). + */ + filep->f_mapping =3D device->inode->i_mapping; + *file =3D filep; + + return 0; + +err_get_registration: + fput(filep); +err_anon_inode: + kfree(df); +err_vfio_device_file: + put_device(&device->device); + return err; } =20 static bool vfio_pci_liveupdate_can_preserve(struct liveupdate_file_handle= r *handler, diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index 4cb47c1564f4..90ecb3544f79 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -177,6 +178,7 @@ bool vfio_device_try_get_registration(struct vfio_devic= e *device) { return refcount_inc_not_zero(&device->refcount); } +EXPORT_SYMBOL_GPL(vfio_device_try_get_registration); =20 /* * VFIO driver API @@ -502,6 +504,7 @@ vfio_allocate_device_file(struct vfio_device *device) =20 return df; } +EXPORT_SYMBOL_GPL(vfio_allocate_device_file); =20 static int vfio_df_device_first_open(struct vfio_device_file *df) { @@ -1385,6 +1388,7 @@ const struct file_operations vfio_device_fops =3D { .show_fdinfo =3D vfio_device_show_fdinfo, #endif }; +EXPORT_SYMBOL_GPL(vfio_device_fops); =20 struct vfio_device *vfio_device_from_file(struct file *file) { @@ -1716,6 +1720,19 @@ int vfio_dma_rw(struct vfio_device *device, dma_addr= _t iova, void *data, } EXPORT_SYMBOL(vfio_dma_rw); =20 +struct vfio_device *vfio_find_device_in_cdev_class(const void *data, + device_match_t match) +{ + struct device *device =3D class_find_device(vfio.device_class, NULL, data, + match); + + if (!device) + return NULL; + + return container_of(device, struct vfio_device, device); +} +EXPORT_SYMBOL_GPL(vfio_find_device_in_cdev_class); + /* * Module/class support */ diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 2443d24aa237..f98802facb24 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -386,5 +386,11 @@ void vfio_virqfd_disable(struct virqfd **pvirqfd); void vfio_virqfd_flush_thread(struct virqfd **pvirqfd); =20 struct vfio_device *vfio_device_from_file(struct file *file); +struct vfio_device *vfio_find_device_in_cdev_class(const void *data, + device_match_t match); +bool vfio_device_try_get_registration(struct vfio_device *device); +struct vfio_device_file *vfio_allocate_device_file(struct vfio_device *dev= ice); + +extern const struct file_operations vfio_device_fops; =20 #endif /* VFIO_H */ --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:06 2026 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 498221DDC1B for ; Sat, 18 Oct 2025 00:07:39 +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=1760746061; cv=none; b=n6WNnLxLOe24LhjT/uIhPwcglDCfNAf9gyEEC8bJ5Y1WsUQAT9E49HInjwRwHrAsCHeR3xZMGuH5ZhYIIYPFJv+jvLBGAShIivm3jcukUPekFfU/QYXR9tYVOnMxoN874EZqbMqNUrzKQtdzGwTCfD8a8Z5/K5U7PRk5fh8dR/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746061; c=relaxed/simple; bh=V76LbfI6Ajfy7OIRb8JcXF9vRsTvCVLWBlvUz+UEmyg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=a8PQLWS9hkCynBLd8j+yh33x5w3Twh+moEbBy/8Ixn1j61JSKYGrEQIGC7i/sOVnl8jfJeViEzRfbMEdEfzei8tZOjqwy3tRTNL5WOVmY47Lv392zSnPW8aHxdZHEN5rB7z8t7k9Etgk18QTw2WTUs8Up6F0saVbxtdePel2l58= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=G4MJr3Te; 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="G4MJr3Te" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2697410e7f9so62953645ad.2 for ; Fri, 17 Oct 2025 17:07:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746059; x=1761350859; 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=GaQ2mjvzcYnMnP1cm0axc8iEarDnxUhNwXsWFDf7Cg4=; b=G4MJr3Tef5Amf3FG17p+7c4g/NBzHmwxyZsXr+P8rDwbgd0ogtRFXOHzZ3y8jdLMP2 bQpIMmnBeUwnrmag100OIhfyB/K37VIMvuC9vEF1OKQAAmGYCuZS31CvbmJDgzJta+yx Aqtox1IkRo8Ce4A8ILiyYR6euo/OQ30eY8PHUcqw0pOSNS9sh0gBlDdndjBKNoSR2SIT mQunujn5/z+zngMmSwaKCL+MyCQ+mxCxEPTcjjhqj4b9tGsYy8Of+qRolMVw49L2elNy kHt/LcNFB9Q7lpdqIPEZBQuoPeRTcqT3VGlnKXd12DiIsVTdbxXoSpdSKsbS3lZNkQiT DP0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746059; x=1761350859; 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=GaQ2mjvzcYnMnP1cm0axc8iEarDnxUhNwXsWFDf7Cg4=; b=PFxY4iw4pdplRM+OQUWApE+chPkKyR3I7UJHcgJGkVJfODdchhV/NKv1GC8NNGrDeE yyoNOTa1fbkczdAZAqz8SbJwXjSUlAP9J3rJoSoxfR65dpqmuPJ8u2mRajhGGiVXgkTk 64Ngyh0CYTryp9U/8IE6MMI15TIY0RfMaUJTK1Zq77Jtj6NS2NYEoA6CY8BnAi8s34kz 7xHdid4ayEQU64fwFrzKs4eGaSK6nDIDyKOptQZH10FXbD2lus1ogkz2wa651pVaEtTp 2ZhyZnofNJV8rQ8HDgTfClqdW/K1Ja9W+N0X0UvqQ9KoRvl+ulOalwN8uRrZ51CJdahD y1Aw== X-Forwarded-Encrypted: i=1; AJvYcCWwoQeKNVwEziMgR1Ejle/vAA/fy4s6tym7GCPdM2HQevwDtosOjgh4s/ZGsFZwYDnjSVpw8DM8XJUckcw=@vger.kernel.org X-Gm-Message-State: AOJu0YzJ2SrOtf8mTkUsmp31P1dKYysF6g8POuG5HIP5B5yLawTR+DqH 2NRD8t4ggeQ0MQy0cvcsI2DnTBXMk5vClJwiwM5wVIWBxF1mnZ5IIQZB6A+5Co0JQO5howsbDlz CajRR9UXirw== X-Google-Smtp-Source: AGHT+IF9dj9Clef1an1TtVMDSsqxw8xp26H//zMhQIxwHrxbjHJhb8hDM1WzMLrsR8CmCfH4zUTMov9736X/ X-Received: from plri16.prod.google.com ([2002:a17:903:32d0:b0:268:11e:8271]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:cf0b:b0:24c:cb60:f6f0 with SMTP id d9443c01a7336-290cb66025amr69035715ad.58.1760746058804; Fri, 17 Oct 2025 17:07:38 -0700 (PDT) Date: Fri, 17 Oct 2025 17:07:01 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-10-vipinsh@google.com> Subject: [RFC PATCH 09/21] vfio/pci: Add Live Update finish callback implementation From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add finish() callback implentation in LUO file handler to free restored folio. Reset the VFIO device if it is not reclaimed by userspace. Signed-off-by: Vipin Sharma --- drivers/vfio/pci/vfio_pci_liveupdate.c | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index cb3ff097afbf..8e0ee01127b3 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -82,6 +82,38 @@ static int match_bdf(struct device *device, const void *= bdf) return *(u16 *)bdf =3D=3D pci_dev_id(vdev->pdev); } =20 +static void vfio_pci_liveupdate_finish(struct liveupdate_file_handler *han= dler, + struct file *file, u64 data, bool reclaimed) +{ + struct vfio_pci_core_device_ser *ser; + struct vfio_pci_core_device *vdev; + struct vfio_device *device; + struct folio *folio; + + if (reclaimed) { + folio =3D virt_to_folio(phys_to_virt(data)); + goto out_folio_put; + } else { + folio =3D kho_restore_folio(data); + } + + if (!folio) + return; + + ser =3D folio_address(folio); + + device =3D vfio_find_device_in_cdev_class(&ser->bdf, match_bdf); + if (!device) + goto out_folio_put; + + vdev =3D container_of(device, struct vfio_pci_core_device, vdev); + pci_try_reset_function(vdev->pdev); + put_device(&device->device); + +out_folio_put: + folio_put(folio); +} + static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_handler *ha= ndler, u64 data, struct file **file) { @@ -156,6 +188,7 @@ static bool vfio_pci_liveupdate_can_preserve(struct liv= eupdate_file_handler *han static const struct liveupdate_file_ops vfio_pci_luo_fops =3D { .prepare =3D vfio_pci_liveupdate_prepare, .cancel =3D vfio_pci_liveupdate_cancel, + .finish =3D vfio_pci_liveupdate_finish, .retrieve =3D vfio_pci_liveupdate_retrieve, .can_preserve =3D vfio_pci_liveupdate_can_preserve, .owner =3D THIS_MODULE, --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:06 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 1C29B1E492D for ; Sat, 18 Oct 2025 00:07:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746063; cv=none; b=keKHBwCgbqgW1VED/j79B3+VePEJuhbL73C0qa2jiJVCdVl8/rxSLObDWpn5NrnCt/INO61NsCUXuR2WqE9LWc+LuQZ2rOB/dtyQ1IbzJ40b3CjyfxiFr4K580cEk/7X+YXE9zlSox5bCy+p3eHbGh4X382+4rNFdLjvO1ri+7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746063; c=relaxed/simple; bh=+K5j39XpTNwLHlWGtorRqscxgPOaq/a9DZ3eNvEVcAo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=sQ1H3M/k8Uy8bkxy25ZCDs0fdE37vrpeGdZlHD7CYZ0cIgzcT4pSXlxb10pTwBluQc5IO+Ty/XV++7HwVBLkt5lxBH/opAmSq/J4++6UKi6cL6RGXOxABLJ4Df6t55BX2YmZyst4yXL7BsPt5RCwr4E90fyXQKb5zsKBM9umXMw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=fxbC1Xqn; arc=none smtp.client-ip=209.85.216.73 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fxbC1Xqn" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-32ec69d22b2so2314684a91.1 for ; Fri, 17 Oct 2025 17:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746060; x=1761350860; 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=qnxsirzJmf+9oD/SWVkkILfWOZE9umducoMflFiqRpQ=; b=fxbC1Xqn8W1nVGvBqnvR20qwKq5qnLQ7aKJXzkOlzYZMbt8jbveKl6biOBHq4yu4/c 8fSeul/cLUVKsf8FnwMDV2zPCoMVM0tb8nRHdZZ2Lm2ntYPrO/A2OwuyDKLx7q7Sb43n sIJCqSTOm5LtNtzC+DUYgQQ6kvBER55r01PS3e4AVbGOQL1wilCSfz8sxP5AU4gXr2++ lN2Ps/Uka90b/x5r+ZSoFs2Hj3O7uzrpWL9hApP2QKRal/YXRK5XpNx91bjfHABZgDdj SbJQ3AVBw/2SvSl0eQj81AWWsfpNzEsTwQUOEwYGRWkeCKTAt3IV+d1ZYbCt/Qj+Mgzp D6Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746060; x=1761350860; 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=qnxsirzJmf+9oD/SWVkkILfWOZE9umducoMflFiqRpQ=; b=N93grbJmJnJDrhYiHYYNfncAmhc54MsTjsdpTqtJEJxzH9MaGOHU084WtX29/EJqUC gJvbrCuRq2zM4USdzxgJTEpm7nbgqy9kucas9dZmWPrSQV/7Y+EOWKzk1+S0nAj/lj/Q sM8deNEwecCLRCzfy2aZpa/Mo2DQBVnZ1iLPvJMXu744icIv6eLchTXyXBCD95vwgiNc +SLC70bOu5WTBJFPgAAmTAKGPvwKZR5TuoMgUGuk3L/zjmGpPIckyx3cDV09Peh0iA00 vA/Z+cF/xvpiue0HIYUAQ1cmtm0eFe4uUTqL2jxk8FJuJS3RbrTdlfNq5XoBnJ4nq6LE eVJA== X-Forwarded-Encrypted: i=1; AJvYcCVqXdhGBzHhAEvhlRxBuLFWTZAUoL84DSQefk15tEvuxLP5MJWiagEic7lCvsZbZ37ZMJzkH9WoGuSMIUQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0drZBjq8XjBaRxUspB1IW4+L/pXYAi61F/veSKWczF+rfcgiD CvXVAMkLyzhFmcexc/DNBLjkTxCgMPEaLUI4vxSNM2Tmf9EM7jwtv8zhrYCV+6Uc37hd9t64fVO mCNFb9mTdMg== X-Google-Smtp-Source: AGHT+IEDeX1KBK/211Sloe9HHYyIrse9Vb0jW4j/mlSMb7ebaIyHdLdJhj4WQAl1ftyT6/JHbLuQi37Ll112 X-Received: from pjbku18.prod.google.com ([2002:a17:90b:2192:b0:33b:a383:f4df]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4d85:b0:330:4a1d:223c with SMTP id 98e67ed59e1d1-33bcf87f421mr6072321a91.15.1760746060452; Fri, 17 Oct 2025 17:07:40 -0700 (PDT) Date: Fri, 17 Oct 2025 17:07:02 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-11-vipinsh@google.com> Subject: [RFC PATCH 10/21] PCI: Add option to skip Bus Master Enable reset during kexec From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add bit field 'skip_kexec_clear_master' to struct pci_dev{}. Skip clearing Bus Master Enable bit on PCI device during kexec reboot. Devices preserved using live update might be performing a DMA transaction during kexec. Skipping clearing this bit allows a device to continue DMA while live update is in progress. Signed-off-by: Vipin Sharma --- drivers/pci/pci-driver.c | 6 ++++-- include/linux/pci.h | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 302d61783f6c..6aab358dc27a 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -513,11 +513,13 @@ static void pci_device_shutdown(struct device *dev) /* * If this is a kexec reboot, turn off Bus Master bit on the * device to tell it to not continue to do DMA. Don't touch - * devices in D3cold or unknown states. + * devices in D3cold or unknown states. Don't clear the bit + * if device has explicitly asked to skip it. * If it is not a kexec reboot, firmware will hit the PCI * devices with big hammer and stop their DMA any way. */ - if (kexec_in_progress && (pci_dev->current_state <=3D PCI_D3hot)) + if (kexec_in_progress && (pci_dev->current_state <=3D PCI_D3hot) && + !pci_dev->skip_kexec_clear_master) pci_clear_master(pci_dev); } =20 diff --git a/include/linux/pci.h b/include/linux/pci.h index d1fdf81fbe1e..8ce2d4528193 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -400,6 +400,8 @@ struct pci_dev { decoding during BAR sizing */ unsigned int wakeup_prepared:1; unsigned int skip_bus_pm:1; /* Internal: Skip bus-level PM */ + unsigned int skip_kexec_clear_master:1; /* Don't clear the Bus Master + Enable bit on kexec reboot */ unsigned int ignore_hotplug:1; /* Ignore hotplug events */ unsigned int hotplug_user_indicators:1; /* SlotCtl indicators controlled exclusively by --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:06 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 C2E411F94A for ; Sat, 18 Oct 2025 00:07:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746065; cv=none; b=ATIWirsJcGbqDHs8NrPUdvT6LaeNFvRUSODqAfQAugfpimQz1+id+CZTBT8EMonkOJ5TonRGFunUEF5NZ1L/mCoxGvMF7Flpcf1hMn94SdMuXGolnWHQV+fIhwpuu5Vuh9QYRxBCo4+Fam86eM7eorfXU/UJfoZWEyv880Idtss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746065; c=relaxed/simple; bh=Zxz213bnVu4PytMrWtldNoB5RbSMv3rpGoHLoxMbz8o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=K/O5XVV3STqXqRvS/A4qv+U/t4pdLzK/wreC1vX0hk8zeSiqvqZWGxoagkKx9Jm+8/Ixt+nUXXtfRu0o1NmcNJaOwgVk5rAoHyC/UgErENsDU0SkgeaPQsdXRPfe/xSRZ7wjhRgdIrxrGuZQgEI/jnuBYzaJ5S0qjvMmS/iXMdA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rjYNxdbg; arc=none smtp.client-ip=209.85.216.73 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rjYNxdbg" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-33bb3b235ebso4160443a91.1 for ; Fri, 17 Oct 2025 17:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746062; x=1761350862; 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=xxD/Cw9jyxG7ivQQV697wV0O8b/3dIW50+ry6yUBLsE=; b=rjYNxdbgkeA9Ic725M8o7FLT88khjBrEUJuwj09S5ZV7oDtUnH5X8zg/oJ42cSULtA 3C8rp0yyxLUem98Qm2I5yQG5wArE2cx5xiA/RkvsyMERttwiBQGynOgeuYihuomORrl9 sw9AYXrFIg9nFpJvKkFjQhU64sfYSGPvwLBBng8HPEVUUFcSXolYOJPpyDd9lt20lr1v iSkpnVjWWcW1FUJ4TVXjN74wkNLW9s2RXegGjc9rxlr/jgRNfxLd/KR10W+reMqSqQUf oYJxPobaEglhhJ3ev6zkd293Ifb2tF6+MW8XFPHTEcc7LjYOxkkR1ocS6578YtsTUx9y Qhpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746062; x=1761350862; 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=xxD/Cw9jyxG7ivQQV697wV0O8b/3dIW50+ry6yUBLsE=; b=cuyTq5wTZ+WfYyNoX5Txd9USbavPiYxhdyHkbHEHYRyzTu3Aw/1NCtJC2QEgykgbd5 3JIJwX4KfLbx3rmWxOq1aYX6uttR6SOlq4DX2vyOijlOCRkD3gUwoyw1Z+O8tSZn46JS 8RQBCGT63k8piiAns9+KeC3gYZVkNsEweDBC4X+puiX9TEeEtaFixIa8w7SmPu8ZaZG/ ZQVeghedFWcwnpSzwxVXrCPfCU73Zv1L6VLQSqsH+Q7syLQpY8piuTz321nK9FnJcN4Z oBBP875R1sSpPMkjWH4unLbj5mey7jMpy4VwAXQCc3/iu1Y5YUF/xAN3a2X2igBoQUyW VXrg== X-Forwarded-Encrypted: i=1; AJvYcCVxvCLEzoeY7jDKfM65lILo/x6wi64YF/q0DMng1dggnYDKUiQAh6jZnCVeFPgsaAGjlwz9+ozO7fSxpCg=@vger.kernel.org X-Gm-Message-State: AOJu0YzGsm71QObSMRhMTxfrcJ6kAFxskZnNahbA29FZ/Yw9Wuy3787y U98qnsNYKoFC63Vs1Pm04pqqECZu3VGW0D7f6e/5waX7Y9Lzc3tuOuBsxfYOM6oZ6jvRVjMIobO wCcb96D4B1g== X-Google-Smtp-Source: AGHT+IGvT4gSxZumpaRuwK33oT1VTteqUw6nohwluWluZWlr9C8TOLWOTIAP6j/iKx3fcI6xg3+HQZq1UcLw X-Received: from pjre17.prod.google.com ([2002:a17:90a:b391:b0:33b:51fe:1a89]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:180e:b0:32e:73fd:81a3 with SMTP id 98e67ed59e1d1-33bcf93dfbdmr7878362a91.33.1760746062232; Fri, 17 Oct 2025 17:07:42 -0700 (PDT) Date: Fri, 17 Oct 2025 17:07:03 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-12-vipinsh@google.com> Subject: [RFC PATCH 11/21] vfio/pci: Skip clearing bus master on live update device during kexec From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Set skip_kexec_clear_master on live update prepare() so that the device participating in live update can continue to perform DMA during kexec phase. Signed-off-by: Vipin Sharma --- drivers/vfio/pci/vfio_pci_liveupdate.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index 8e0ee01127b3..789b52665e35 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -54,6 +54,7 @@ static int vfio_pci_liveupdate_prepare(struct liveupdate_= file_handler *handler, goto err_free_folio; =20 *data =3D virt_to_phys(ser); + vdev->pdev->skip_kexec_clear_master =3D true; =20 return 0; =20 @@ -67,7 +68,12 @@ static void vfio_pci_liveupdate_cancel(struct liveupdate= _file_handler *handler, { struct vfio_pci_core_device_ser *ser =3D phys_to_virt(data); struct folio *folio =3D virt_to_folio(ser); + struct vfio_pci_core_device *vdev; + struct vfio_device *device; =20 + device =3D vfio_device_from_file(file); + vdev =3D container_of(device, struct vfio_pci_core_device, vdev); + vdev->pdev->skip_kexec_clear_master =3D false; WARN_ON_ONCE(kho_unpreserve_folio(folio)); folio_put(folio); } --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:06 2026 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 9817F1F3BA2 for ; Sat, 18 Oct 2025 00:07:44 +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=1760746066; cv=none; b=BrDjcJskH+izfdg/HbjwYLUgH/NFSlhsAIuayEJQgNd77CNXo9s22CbWhqyAgcnC12Ibq6OfJ4YfT3rx7vTK6pbfAtrVvuh43GpTL//PpXdLcYFetE5rj+5XIL4qfD1yg3nnY5S8M9iDVALpDriFJuZq63cDLIAD8jVocxoszok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746066; c=relaxed/simple; bh=/Zwi58c0tnVXnIkT6QEOTDduqWPDxbPVbNm/jJa1Zmk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CTgmY0LPrrfJcLCWU0ApwmOiptrJ5sCKJta/orA66I1zdT2T61eD1HgntPVuz4q8MK/fdnSPB88AIZ29QHfsCRPigT2+JemH9cZ+i7GEqh8XyIr6Nrj0DTppNeyErdg5kaf+TC386jv384DYxgGRibxu/exE/sN+c3dm+pF6A+Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CKsGIxbd; 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CKsGIxbd" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2904e9e0ef9so45624505ad.3 for ; Fri, 17 Oct 2025 17:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746064; x=1761350864; 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=pb+yM/GSLfD7F9NEd5q0iCevSvrZqDGm2r7fPtuoE4o=; b=CKsGIxbdeErOW/fHGYaTjsdg6IV0+LUHB8zpauXFiqZZa+2Ge4t1eHsT8gCrwnMp54 r8M7ZM/bwC5LRtHQ41HLTUZ0wudq3/DyKkne2F80T++y/4IMjqIawb9hpeAWVQ/4Qa7I NEzp5BGPurbCMiqENI/CoF4Bhv2vdQXmla5uS337Td2lKFIS3BIDwZ+5BNvvfLIfpUIy Km3Zyd/6opfWLQmTZwuliQR1W1IoTK360I9EfvlI2nD9yNJz7QRd3oGvhI/E/9Xulka/ o1T+ZOLf38BLVRke04ag2AvME2+qByVhsGqXge53V9ZVZbGG1oCbcqQYcQN4p41MRBc7 EBxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746064; x=1761350864; 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=pb+yM/GSLfD7F9NEd5q0iCevSvrZqDGm2r7fPtuoE4o=; b=LCoWitEO9ovWRsZd6LbSOC99og8YiSN+98hg2C0z+bTpAqskcvEjfMvgLWGShwfGFm uZ5KMnUR05rjqrgy0Jq3DyGdFdbnxh1vm3w8dfuOewLbRS5OOEffPTn9m07PihW1/DEc 4vbYRyqmTxk172IC1WLfI+MI7vBWcu0VUYOQ4akJyTbegGnmoI27tQPtm5Ydm8g4HZnm eC6V1SIx6SO0TsL9+LYYob8Pbht2WDUueEo7mRsMZkNNIBmIwpuQhkQDHY5x9ejrrdN3 0XUdvIMaqVQjqPyHvrzqvZfwm871cQmY3lENrhH3qbgb096hGUlYUBnjeV4dWot3u4rE 9rxg== X-Forwarded-Encrypted: i=1; AJvYcCVvCChmgBZNYrwo99w3/pQ1efMAm24v8cfv1+8w7aDRMcEdBHGBu3SJF7CwbiFiydNaRUndAaFLiONFdk4=@vger.kernel.org X-Gm-Message-State: AOJu0YzuShvxRsFQmYlCWiXpC3RQGb7Ve3X30MAVkdSU84h1cM0C+6q3 FAGx0RSqRTneAD97Nn+77j4bL+TCH72ONPz8HNCx4ugYKl5yvbcNg7AuzgxaWDh6aHBJRdpHkAL PJ9ZXg2TyKw== X-Google-Smtp-Source: AGHT+IFm8I2WbT23xHEc9aRTbzh15nGTE4Afs2ZbYTvSrJoFR5A/1hUgI6fsM2AyRelH/yPNccAGYfnt5l6E X-Received: from plww18.prod.google.com ([2002:a17:902:d112:b0:290:28e2:ce49]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:fc4f:b0:25c:982e:2b1d with SMTP id d9443c01a7336-290cbb474f7mr68357455ad.59.1760746063874; Fri, 17 Oct 2025 17:07:43 -0700 (PDT) Date: Fri, 17 Oct 2025 17:07:04 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-13-vipinsh@google.com> Subject: [RFC PATCH 12/21] vfio/pci: Skip clearing bus master on live update restored device From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Store the restored serialized data in struct vfio_pci_core_device{}. Skip clearing the bus master bit on the restored VFIO devices when opened for the first time after live update reboot. In the live update finish, clean up the pointer to the restored KHO data. Warn if the device open count is 0, which indicates that userspace might not have opened and restored the device. Signed-off-by: Vipin Sharma --- drivers/vfio/pci/vfio_pci_core.c | 8 ++++++-- drivers/vfio/pci/vfio_pci_liveupdate.c | 19 ++++++++++++++----- include/linux/vfio_pci_core.h | 1 + 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_c= ore.c index 0894673a9262..29236b015242 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -475,8 +475,12 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *= vdev) return ret; } =20 - /* Don't allow our initial saved state to include busmaster */ - pci_clear_master(pdev); + /* + * Don't allow our initial saved state to include busmaster. However, if + * device is participating in liveupdate then don't change this bit. + */ + if (!vdev->liveupdate_restore) + pci_clear_master(pdev); =20 ret =3D pci_enable_device(pdev); if (ret) diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index 789b52665e35..6cc94d9a0386 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -96,12 +96,10 @@ static void vfio_pci_liveupdate_finish(struct liveupdat= e_file_handler *handler, struct vfio_device *device; struct folio *folio; =20 - if (reclaimed) { + if (reclaimed) folio =3D virt_to_folio(phys_to_virt(data)); - goto out_folio_put; - } else { + else folio =3D kho_restore_folio(data); - } =20 if (!folio) return; @@ -113,7 +111,14 @@ static void vfio_pci_liveupdate_finish(struct liveupda= te_file_handler *handler, goto out_folio_put; =20 vdev =3D container_of(device, struct vfio_pci_core_device, vdev); - pci_try_reset_function(vdev->pdev); + if (reclaimed) { + guard(mutex)(&device->dev_set->lock); + if (!vfio_device_cdev_opened(device)) + pci_err(vdev->pdev, "Open count is 0, userspace might not have restored= the device.\n"); + vdev->liveupdate_restore =3D NULL; + } else { + pci_try_reset_function(vdev->pdev); + } put_device(&device->device); =20 out_folio_put: @@ -124,6 +129,7 @@ static int vfio_pci_liveupdate_retrieve(struct liveupda= te_file_handler *handler, u64 data, struct file **file) { struct vfio_pci_core_device_ser *ser; + struct vfio_pci_core_device *vdev; struct vfio_device_file *df; struct vfio_device *device; struct folio *folio; @@ -167,6 +173,9 @@ static int vfio_pci_liveupdate_retrieve(struct liveupda= te_file_handler *handler, */ filep->f_mapping =3D device->inode->i_mapping; *file =3D filep; + vdev =3D container_of(device, struct vfio_pci_core_device, vdev); + guard(mutex)(&device->dev_set->lock); + vdev->liveupdate_restore =3D ser; =20 return 0; =20 diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h index f541044e42a2..8c3fe2db7eb3 100644 --- a/include/linux/vfio_pci_core.h +++ b/include/linux/vfio_pci_core.h @@ -94,6 +94,7 @@ struct vfio_pci_core_device { struct vfio_pci_core_device *sriov_pf_core_dev; struct notifier_block nb; struct rw_semaphore memory_lock; + void *liveupdate_restore; }; =20 /* Will be exported for vfio pci drivers usage */ --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:06 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 4EEA628DB3 for ; Sat, 18 Oct 2025 00:07:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746068; cv=none; b=edOXb2WptK7e2crxZ9jXSc1SaHKRLLgSqamSYt4eQ1fjhRBso+ipTz72mjyhlL1F21DZUc+FxNCq2YxolW9aiSUIsXzuY5JFdC5eiCFuyeUnMCUy9gjWQ0e7luSiSec0qu7p3gx6bMb5OuywQwX2AxTlzvzGgJ+6/24VeWppxrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746068; c=relaxed/simple; bh=MLaNeyY6LKintgVULMgBH+iRQ/MeqKVKP+ROzIUgMg0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=l5+t2UkFMLALqI5zAmz4T+K8OeISN2dxi0ZpfflRhzQgRb7fstHiO3tizKX3OzvuJib6Ild94LddbfavlK5h3vC57bfmJaAFb4VSKVOOUhyBO75va6rt5WzdJg2Qy9Q2qho7Dzfs82lu17PvHXHl1L0T8lWQ2wE0oR8AHuF+WVo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=unQdP2H0; arc=none smtp.client-ip=209.85.216.73 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="unQdP2H0" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-33bbbb41a84so4358831a91.1 for ; Fri, 17 Oct 2025 17:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746066; x=1761350866; 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=h58y0LF9F4O7H0FAiRUz8ZqJ6jT9O63uu0+3MjjbyTk=; b=unQdP2H0pbmZMm7YAowZVqfrE6Wv87+7CAw/5Eu+skmj/IV97GCqzyF0V0l1my7KUr vohx3U5P7hQHnCsarv8YpAcABmgotcGlEKRIwQLhn0E3sa6Q7eDGgVgLSh4GNq/Lqzdh 9fPUfA8OMd2WR4ik7vJWWW3Exx19mSGn4LDAbMaba4mrfd7ZqsCkd9DY7OmCSUasQ5Ov q4uIke6rNIxBOpcnejH3KzX3HHH/Ybg0aPX7A+9o7RlBsqwqS6eSXz+a9VJ0ou7zKUZU hIlPSjDS0D51i+Ab953yQnwp6oHN12hRLWNEofptrqp4sV2/OvP1ChcqfbbHmbPPuZGK tGvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746066; x=1761350866; 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=h58y0LF9F4O7H0FAiRUz8ZqJ6jT9O63uu0+3MjjbyTk=; b=q6v2ID1EFD9HPaqetuhufbck5/7Uzgp9vMT+QZ7QPCRk+KZjHPSPX+xOdEg5KFgXgV L7UxYOwhhuUdtTO/NiBs8RoiiqcPAp6tamMchPrZ4NSeNUFehD8aQGuj/np3wxSidvrS sshys9nv9ZoCXgWs7qMkPPHux1Bj0GH9npuEICZlIxW2dMywFT4c/EisztnKyPJTAalQ TKMHYDaPU6jqk64gGDSHJvfhd7G/bOcbbZZthON14UsdvnieKO+UmZppUjWFDe+oDnP5 UQd2PXwCgHcAW72nEr4MSQsjVcL4Bmu6ru9Bc2YCMiMF+I4zEQJwcLu2wityEZ/FteP4 ehgg== X-Forwarded-Encrypted: i=1; AJvYcCX1TSt3O+giFJADRZFgqWL+Bv2bKVB8b5CZaVx5goWn5KVyZYpvQFT8rpwjwiad3yX3CYHVVtY6FiJF6EQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5FEAs6uUFNiyzZyD8QoK5tMDTbjL5eiobkQ33YPC04mHDAVlP 3DaGDaHF5Qtd3KD8j1aGybNQh+rCyVWqFcui3/mwmth0FmSk9GHw+V6tGL7XHqZzjKNRotMsROT D/lHhswzTyw== X-Google-Smtp-Source: AGHT+IHXxYwtGcIKbQ0OizZ3waxlwzCfsSoob6MqMnOla+ZwoMWcozqueK+AEj/juH0UNpmrqm1CfPxSTVkf X-Received: from pjbrv22.prod.google.com ([2002:a17:90b:2c16:b0:329:6ac4:ea2e]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3c88:b0:338:3d07:5174 with SMTP id 98e67ed59e1d1-33bcf85d01dmr6153736a91.5.1760746065605; Fri, 17 Oct 2025 17:07:45 -0700 (PDT) Date: Fri, 17 Oct 2025 17:07:05 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-14-vipinsh@google.com> Subject: [RFC PATCH 13/21] vfio/pci: Preserve VFIO PCI config space through live update From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Save and restore vconfig, pci_config_map, and rbar members of the struct vfio_pci_core_device{} during live update. Use the max size of PCI config space i.e. 4096 bytes for storing vconfig and pci_config_map irrespective of the exact size. Store the current config size which is present in the struct pci_dev{} also, to know how much actual data is present in the vconfig and the pci_config_map. vconfig represents virtual PCI config used by VFIO to virtualize certain bits of the config space in the PCI device. This should be preserved as those virtualized bits cannot be retrieved from reading hardware. pci_config_map is used to identify starting point of a capability. This is not strictly needed to be preserved and can be recreated after kexec but saving it in kHO reduces the code change. Currently, pci_config_map is populated in the same code where vconfig gets initialized. If pci_config_map is not saved then a separate flow need to be added for just populating pci_config_map. rbar is used to restore BARs after a reset. This value needs to be preserved as reset will lose this information. Signed-off-by: Vipin Sharma --- drivers/vfio/pci/vfio_pci_config.c | 17 ++++++++++++ drivers/vfio/pci/vfio_pci_liveupdate.c | 38 ++++++++++++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 5 ++++ 3 files changed, 60 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci= _config.c index 8f02f236b5b4..36a71fc3d526 100644 --- a/drivers/vfio/pci/vfio_pci_config.c +++ b/drivers/vfio/pci/vfio_pci_config.c @@ -1756,6 +1756,23 @@ int vfio_config_init(struct vfio_pci_core_device *vd= ev) vdev->pci_config_map =3D map; vdev->vconfig =3D vconfig; =20 + if (vdev->liveupdate_restore) { + ret =3D vfio_pci_liveupdate_restore_config(vdev); + if (ret) + goto out; + /* + * Liveupdate might have started after userspace writes to BARs + * but before VFIO sanitizes them which happens when BARs are + * read next time. + * + * Assume BARs are dirty so that VFIO will sanitize them + * unconditionally next time and avoid giving userspace wrong + * value. + */ + vdev->bardirty =3D true; + return 0; + } + memset(map, PCI_CAP_ID_BASIC, PCI_STD_HEADER_SIZEOF); memset(map + PCI_STD_HEADER_SIZEOF, PCI_CAP_ID_INVALID, pdev->cfg_size - PCI_STD_HEADER_SIZEOF); diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index 6cc94d9a0386..824dba2750fe 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -18,12 +18,43 @@ =20 struct vfio_pci_core_device_ser { u16 bdf; + u32 cfg_size; + u8 pci_config_map[PCI_CFG_SPACE_EXP_SIZE]; + u8 vconfig[PCI_CFG_SPACE_EXP_SIZE]; + u32 rbar[7]; } __packed; =20 +static int vfio_pci_liveupdate_deserialize_config(struct vfio_pci_core_dev= ice *vdev, + struct vfio_pci_core_device_ser *ser) +{ + struct pci_dev *pdev =3D vdev->pdev; + + if (WARN_ON_ONCE(pdev->cfg_size !=3D ser->cfg_size)) { + dev_err(&pdev->dev, "Config size in serialized (%d) not matching the one= pci_dev (%d)", + ser->cfg_size, pdev->cfg_size); + return -EINVAL; + } + + memcpy(vdev->pci_config_map, ser->pci_config_map, ser->cfg_size); + memcpy(vdev->vconfig, ser->vconfig, ser->cfg_size); + memcpy(vdev->rbar, ser->rbar, sizeof(vdev->rbar)); + return 0; +} + +static void vfio_pci_liveupdate_serialize_config(struct vfio_pci_core_devi= ce *vdev, + struct vfio_pci_core_device_ser *ser) +{ + ser->cfg_size =3D vdev->pdev->cfg_size; + memcpy(ser->pci_config_map, vdev->pci_config_map, ser->cfg_size); + memcpy(ser->vconfig, vdev->vconfig, ser->cfg_size); + memcpy(ser->rbar, vdev->rbar, sizeof(vdev->rbar)); +} + static int vfio_pci_lu_serialize(struct vfio_pci_core_device *vdev, struct vfio_pci_core_device_ser *ser) { ser->bdf =3D pci_dev_id(vdev->pdev); + vfio_pci_liveupdate_serialize_config(vdev, ser); return 0; } =20 @@ -221,3 +252,10 @@ void __init vfio_pci_liveupdate_init(void) if (err) pr_err("VFIO PCI liveupdate file handler register failed, error %d.\n", = err); } + +int vfio_pci_liveupdate_restore_config(struct vfio_pci_core_device *vdev) +{ + struct vfio_pci_core_device_ser *ser =3D vdev->liveupdate_restore; + + return vfio_pci_liveupdate_deserialize_config(vdev, ser); +} diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_p= riv.h index 7779fd744ff5..0d5aca6c2471 100644 --- a/drivers/vfio/pci/vfio_pci_priv.h +++ b/drivers/vfio/pci/vfio_pci_priv.h @@ -109,8 +109,13 @@ static inline bool vfio_pci_is_vga(struct pci_dev *pde= v) =20 #ifdef CONFIG_LIVEUPDATE void vfio_pci_liveupdate_init(void); +int vfio_pci_liveupdate_restore_config(struct vfio_pci_core_device *vdev); #else static inline void vfio_pci_liveupdate_init(void) { } +int vfio_pci_liveupdate_restore_config(struct vfio_pci_core_device *vdev) +{ + return -EINVAL; +} #endif /* CONFIG_LIVEUPDATE */ =20 #endif --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:06 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 0CA5E222586 for ; Sat, 18 Oct 2025 00:07:47 +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=1760746069; cv=none; b=sFZfVS9lWytyWs0/T7WXN0ManX/Oafl6JePtCIoC+GAXqUHLZnQdJnLMKWX4gHSYa1btR9XuBlZpwolD6FDxZh9KNBAM74BdrmXOw/uzblVI1s49Qd6XTjInqo4PpowBW+wUsaQ/adHoB2PaXhiZKaIQiZjw1wPAbZ0IMkC3aZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746069; c=relaxed/simple; bh=MFgRpcmSvyiNW2ycsfOMqpytwYLNdswjkflUzJbVBqM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ktFXoXfu294K4c0fz4PX+r4rZe5vWhoau1widDaKbAPxSyjwoJczgGB+dh0795PvAx274W6xHAWF4ghv7RQw/VzOsrxduG5qk4HZIqVXtun6ghjoUT3uEiZcHMrEmv77s/CF2mO2+YQ04HeK1dW2PN6Ar/aOPxqPBkJCq/54t6c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2t7dpM7x; 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2t7dpM7x" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-272ed8c106eso15988705ad.2 for ; Fri, 17 Oct 2025 17:07:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746067; x=1761350867; 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=KHCY6sFzZWLKuVo4O6MQDE+yc4FJeSrGIRkXpfAjMjg=; b=2t7dpM7xT5sRj2dzjCC8tHWBvbeIYM/D6BaPLa0/AOxR9uvIiAtcnb5rnAbini1hg/ 26rgE89UsuEuSf1DfU/RLE9E6xE/RK/sb37FddbHPk7cfRvnhP7HDuwpTUCa4yDfKIXS vXid0/Rp+MuN6zN/mYhVAKIsz8kFYCyU/3UvvCR1Csc97mnOEJCaIA4J6jwrckWfIny7 3ErNQRSnXAP8QfQdTTL/4dMBpGQaRA0f0yodX6ffxoF2LSsD/Fp4cCNBuNqhNFSrGtwi YW4suCx+CdutDtj8oRUVL00xfHWKRSJtmCB/6sr5pVPxrufxwz4V8khpmWENSCJc2XWH cWiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746067; x=1761350867; 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=KHCY6sFzZWLKuVo4O6MQDE+yc4FJeSrGIRkXpfAjMjg=; b=j6oMCuRCPLFSqRqh3nWXf3ZYJAAOVZZywQaYBrTefHAI8ZEUXcluNMK/S3qCPtra+g ZpMWoabaC1MU5glNPsxhYwHk1wzSfD7lrRKTIVijM/9uU2qVF6kIV7ouo6zwOMzAZB4+ eVRixwvd0OwnWAFLNE2nNcBwH1Sz4htegbivSzwe/ekyt0wSLyHEvZjEwE3YnaCAv5Gh UVWkFBPwkABgi4v+KFlJ16kJctRsSQVwJisdiOTJhQaRH22miwP2ukd60MafWPKVT15l eDL1V9F0QM0VlwqhNfn271CyMqFoAqEusoVuwxRGQ3cbXTrBl6ElCTuJA4ISJVRHOeMt JZ2g== X-Forwarded-Encrypted: i=1; AJvYcCVhY6AuHCMv0ZC3zMVJNpnEUlAZ2xVBd+jAU3Ci/IomLVAikZ+nx5Lq1P+KgAKFgXaXFcs8vTw9QeVeP00=@vger.kernel.org X-Gm-Message-State: AOJu0YwurRh6PhhXJDHtW0TBO2cQcwLWqqeGlb+XWwV9GOz/iqP2Tjoa UDD5PbCYWlZTU9eu3+abI8A/RQ+XbfbB8qcqGibYmXstO6l4BMkwcvvn5iWRLhEmdq/ZkM4ljZM sCP9nMZh2BQ== X-Google-Smtp-Source: AGHT+IHm9Bkb4nNH3Rfeek7ZAO48gSccBg2tRk1yFiUzJut212ExP9VQ22QXBuOVaPaAWO2qNwfDgLkRrWNJ X-Received: from pjff13.prod.google.com ([2002:a17:90b:562d:b0:33d:69cf:1f82]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f64f:b0:248:e3fb:4dc8 with SMTP id d9443c01a7336-290ca8d04f4mr63505285ad.39.1760746067402; Fri, 17 Oct 2025 17:07:47 -0700 (PDT) Date: Fri, 17 Oct 2025 17:07:06 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-15-vipinsh@google.com> Subject: [RFC PATCH 14/21] vfio/pci: Skip device reset on live update restored device. From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Do not reset the device when a live update preserved VFIO PCI device is opened for the first time after kexec. Save 'reset_works' to the device serialized state. If not saved then this value can only be restored by performing an actual reset, which is not desired during live update. If a device can be reset before live update then most likely it can be reset after live update unless some reset methods have been removed. In that case when actual reset is tried it will return an error. Signed-off-by: Vipin Sharma --- drivers/vfio/pci/vfio_pci_core.c | 15 ++++++++++----- drivers/vfio/pci/vfio_pci_liveupdate.c | 9 +++++++++ drivers/vfio/pci/vfio_pci_priv.h | 2 ++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_c= ore.c index 29236b015242..186a669b68a4 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -486,12 +486,17 @@ int vfio_pci_core_enable(struct vfio_pci_core_device = *vdev) if (ret) goto out_power; =20 - /* If reset fails because of the device lock, fail this path entirely */ - ret =3D pci_try_reset_function(pdev); - if (ret =3D=3D -EAGAIN) - goto out_disable_device; + if (vdev->liveupdate_restore) { + vfio_pci_liveupdate_restore_device(vdev); + } else { + /* If reset fails because of the device lock, fail this path entirely */ + ret =3D pci_try_reset_function(pdev); + if (ret =3D=3D -EAGAIN) + goto out_disable_device; + + vdev->reset_works =3D !ret; + } =20 - vdev->reset_works =3D !ret; pci_save_state(pdev); vdev->pci_saved_state =3D pci_store_saved_state(pdev); if (!vdev->pci_saved_state) diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index 824dba2750fe..82ff9f178fdc 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -22,6 +22,7 @@ struct vfio_pci_core_device_ser { u8 pci_config_map[PCI_CFG_SPACE_EXP_SIZE]; u8 vconfig[PCI_CFG_SPACE_EXP_SIZE]; u32 rbar[7]; + u8 reset_works; } __packed; =20 static int vfio_pci_liveupdate_deserialize_config(struct vfio_pci_core_dev= ice *vdev, @@ -55,6 +56,7 @@ static int vfio_pci_lu_serialize(struct vfio_pci_core_dev= ice *vdev, { ser->bdf =3D pci_dev_id(vdev->pdev); vfio_pci_liveupdate_serialize_config(vdev, ser); + ser->reset_works =3D vdev->reset_works; return 0; } =20 @@ -259,3 +261,10 @@ int vfio_pci_liveupdate_restore_config(struct vfio_pci= _core_device *vdev) =20 return vfio_pci_liveupdate_deserialize_config(vdev, ser); } + +void vfio_pci_liveupdate_restore_device(struct vfio_pci_core_device *vdev) +{ + struct vfio_pci_core_device_ser *ser =3D vdev->liveupdate_restore; + + vdev->reset_works =3D ser->reset_works; +} diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_p= riv.h index 0d5aca6c2471..ee1c7c229020 100644 --- a/drivers/vfio/pci/vfio_pci_priv.h +++ b/drivers/vfio/pci/vfio_pci_priv.h @@ -110,12 +110,14 @@ static inline bool vfio_pci_is_vga(struct pci_dev *pd= ev) #ifdef CONFIG_LIVEUPDATE void vfio_pci_liveupdate_init(void); int vfio_pci_liveupdate_restore_config(struct vfio_pci_core_device *vdev); +void vfio_pci_liveupdate_restore_device(struct vfio_pci_core_device *vdev); #else static inline void vfio_pci_liveupdate_init(void) { } int vfio_pci_liveupdate_restore_config(struct vfio_pci_core_device *vdev) { return -EINVAL; } +void vfio_pci_liveupdate_restore_device(struct vfio_pci_core_device *vdev)= { } #endif /* CONFIG_LIVEUPDATE */ =20 #endif --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:06 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 279CB226D00 for ; Sat, 18 Oct 2025 00:07:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746071; cv=none; b=sW9mP2etfZOL7N4r2axmp4wVWKwee0WN6dmTWiva3hjmn0LSvjV8aDZ6td5yUqjKXwKLdB9uImgETTaN4np0VVs6zvKPXTdNZAgXxpffoTP3nQbQHFosPQRW5VQpX9V27s6cfUmwviyHFol0fGNjYtwxTQn2HPTNgN/cfshrKFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746071; c=relaxed/simple; bh=4zEfGNBAvfxNMJ6CtPOIgpCPNW5I0Ho4sTGFaBRv8jA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VFxvW6V23ajyCx3+lkjLjtG1zsFuRwmrOOfWSRSu1ODAqF452jHW9LpUmA+Mf7nPcDA6bgLr5r8fKLwDmB6wRgtS0fRnoiljNsSNaxzVBNANS2MLE7HfgcVXJTsYhKKoApnxi5geyvmaOMoyrRzhCBYLZz9m6FDfOwfbfyjb+bA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1yIOzaAu; arc=none smtp.client-ip=209.85.216.73 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1yIOzaAu" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-3324538ceb0so4386988a91.1 for ; Fri, 17 Oct 2025 17:07:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746069; x=1761350869; 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=7IKQ2m/8YVTtgALfOzv64urRQ/jq+jvTeg0iyjCDHzo=; b=1yIOzaAuyxpGWSVzU6J1NpSNaEYauiz4b8LeCEiSOWVaJZGscMulWouBJJs/9Rfppy bnetejwjUoen5Z10REavbbNc1UFLi8bJBGy2kxFzg32HWt0ipE9S/Vt4Ibf6Fn00nFFM 1C4CzqrVqznV7dWT5LdcKZ6t/1/qw0pzaIslbNm+Gf19zmuqeOmI9hfIuFL0g43yEn1R kCs/oehZaQ/nw/F4qu00AQjsxdXOpuB+b491GwyjCrD7kXIG3VWvULs2xioj9f1eu4Qv qjKZzCnOv4vSz7mDmG76caWRAZnGnTZ7hVWTTausO7yxVWEelTStXCUdxBizlcwuFXoU Zj/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746069; x=1761350869; 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=7IKQ2m/8YVTtgALfOzv64urRQ/jq+jvTeg0iyjCDHzo=; b=OONkHupLQX+HqZVvVtjfwjGtXXIkR7qtBFl45NmoaxpyksW3LEpLBOPH06oBdtyuxc UWLjYyn/bovrr4T9cpCskJEWa9Q5Y9Ock7AYyqPxSRf/6YrdmgjfswkLZiG/Yyo5xlgu rOZ4puY+n/JUUgPIuuQ9/ovZtDtnKBapXJxNLEzDqnkBz7xrSyKyPcTXianJwHE8icHi Jt8QNTuW0rdi75aR/2oMywkVR1hp22Uoy4zqQfotGhIpLATy0HqZTjLmAr1qEYoeCFkH paGFHYc6X5iRYuhQRrx+TlIDOjsjH+XGrUb/zSyJG5YxzqyD35Ba/5P2Fm1uTVlVMPhK sjKg== X-Forwarded-Encrypted: i=1; AJvYcCVcHr1BJ4tLJ+rZYcnP7Jz0CLqWUiBev8jJYI4uBhUCgA1J73RCl6iFH+aQ/giIT0iOTDqIgPDtxvC2I64=@vger.kernel.org X-Gm-Message-State: AOJu0Yybw5hhZyXn6Eqzwa2Nsrc8t9OezasTF98CPAYjslLLuZZi+1Z2 MBQIRHSptVI/Hv6yF0JD4IwgPy02j1VCcCaAWkYhy7W388M99nYnFRBlH+ET/dm+YcOFHyGLM4f aClHR/lSo0g== X-Google-Smtp-Source: AGHT+IGi63368+j4schUOx0wr2SHTaDZh32wZixnKr/b5gJJ0dBIteyX+gJFYt89f2kz+wLVliJYYTwPu7xP X-Received: from pjbnu5.prod.google.com ([2002:a17:90b:1b05:b0:33b:c59f:b015]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:240a:b0:33b:d373:c899 with SMTP id 98e67ed59e1d1-33bd373c8ddmr4671671a91.22.1760746069495; Fri, 17 Oct 2025 17:07:49 -0700 (PDT) Date: Fri, 17 Oct 2025 17:07:07 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-16-vipinsh@google.com> Subject: [RFC PATCH 15/21] PCI: Make PCI saved state and capability structs public From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move struct pci_saved_state{} and struct pci_cap_saved_data{} to linux/pci.h so that they are available to code outside of the PCI core. These structs will be used in subsequent commits to serialize and deserialize PCI state across Live Update. Signed-off-by: Vipin Sharma --- drivers/pci/pci.c | 5 ----- drivers/pci/pci.h | 7 ------- include/linux/pci.h | 13 +++++++++++++ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index b14dd064006c..b68bf3e820ce 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1884,11 +1884,6 @@ void pci_restore_state(struct pci_dev *dev) } EXPORT_SYMBOL(pci_restore_state); =20 -struct pci_saved_state { - u32 config_space[16]; - struct pci_cap_saved_data cap[]; -}; - /** * pci_store_saved_state - Allocate and return an opaque struct containing * the device saved state. diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 09476a467cc0..973fcdf7898d 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -197,13 +197,6 @@ int pci_bridge_secondary_bus_reset(struct pci_dev *dev= ); int pci_bus_error_reset(struct pci_dev *dev); int __pci_reset_bus(struct pci_bus *bus); =20 -struct pci_cap_saved_data { - u16 cap_nr; - bool cap_extended; - unsigned int size; - u32 data[]; -}; - struct pci_cap_saved_state { struct hlist_node next; struct pci_cap_saved_data cap; diff --git a/include/linux/pci.h b/include/linux/pci.h index 8ce2d4528193..70c9b12c8c02 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1448,6 +1448,19 @@ void pci_disable_rom(struct pci_dev *pdev); void __iomem __must_check *pci_map_rom(struct pci_dev *pdev, size_t *size); void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom); =20 + +struct pci_cap_saved_data { + u16 cap_nr; + bool cap_extended; + unsigned int size; + u32 data[]; +}; + +struct pci_saved_state { + u32 config_space[16]; + struct pci_cap_saved_data cap[]; +}; + /* Power management related routines */ int pci_save_state(struct pci_dev *dev); void pci_restore_state(struct pci_dev *dev); --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:06 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 58D1E211A35 for ; Sat, 18 Oct 2025 00:07:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746074; cv=none; b=YzQTopKYK7EpFLj0lwkQZBUVaVmVsJBpHOEYdOi5VlbrTGBGRuxxwebQERU4u4ZYEtFWyaNHcsl9OH1tyD62ZHFFaBO/OoUs4pcczrhOwgjsTPfdx5AzqPlinQ7GmmMaEtBwiS0htILch6Ooat7DEHKQDCHVMH6Nhg7IrkWfd/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746074; c=relaxed/simple; bh=y0+6jsiefYgVNtwktGfAYBPXPBYUey5C8nH+I/Fgc2E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=B569jvDtaGflLk/AmaoJfQg7FIxoyGJsVa4Hv2tmpJmnZC+DaK9QeEIgFv+hKT8RHln64Ji6SPepT/E1BmgTulk5dwhT+Y9c9Mt2ytcECOJJH8Mlz9fly6FadsPrX2icl5NL6aIKT5ge68a6UMzkcQEq1EEQy1nSpoldpQH8j8c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=N3ieYWUf; arc=none smtp.client-ip=209.85.216.74 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="N3ieYWUf" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-33428befc08so5267385a91.2 for ; Fri, 17 Oct 2025 17:07:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746071; x=1761350871; 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=/CbwykVnnO5WGgcAhFzYYL9mNJY9ZB8LleHTuq5Utvo=; b=N3ieYWUfLZN3inej6Ctduj465w91ws+70Ru5mnbpluBW++m/wrXyvIx4Txt9KzsyhV YGYuxsKL6wVB8LuOGThs/yrQWoYtZl8cvLAvr5Y34LFcgKWdyE7IjBmv8BSs6EBkh3ii RVycEG3pfDWgUOF/1FFe5x13Aw4ezIBPfysOC5qkvkKAgTEeXC3Z+skYD4XLJ2kuiwmS d5OjnYTZLdUJ5Q0M4yypKweCr0IY781UG2dC4N0hu0nxVg5r/NkQc/sIBolMYqkbw8pg aeZOkdGsD1NWoN6MreT6UYYrDgd0Y+T2D6QsQFdkt7iIbJKwVhs2dLBYF6DtQc+FvKBi 90yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746071; x=1761350871; 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=/CbwykVnnO5WGgcAhFzYYL9mNJY9ZB8LleHTuq5Utvo=; b=b2fepAsBn/Pcc/YNqB/CkQXZ1OXtHR5UbGMeHlnZi7ax/WERBnexI1jvw/AiLuebj7 ctc0BZVn4AwN6hKjga37Z170M26+5ndmNvDDMoEspFB09U2m7rojiFwJD3P9Lw6vmtB0 Dak/VUKlcxHpaDbLxHkEQhnPzsoPEDoy56cY8134QOGgrVzaX+nK4zQ1EMbBHn1Cnxit 2nTGaizQfIH+UnlzrqvG7AnuZL8PcrTaGYg4LYTmfyh/kz+oQVmJ45lpB9Cp4JEfE2X6 6x5P1YEnhg3N95tMKTcqVMSlf2DwYU204tdUlIn23Z38YRnAscDXEsr29XDXUGXPNSeX bemA== X-Forwarded-Encrypted: i=1; AJvYcCW2JdYnGiMRYFn054/c7vBiexPAdArXx1W0LKFQEYZn0oBS+LvW/rx8aMyMj5ujm1H29VLpD8YtSc3d2Q8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1Qiutac7eCZjItU7UWbRavAR0t0MmaUBi8fbaiFZKFXFtYg/f rnxHSKERvr1msH4Eje2SW5fHgBTPK2yWGokkiVGlpTANhH0rkWnpeMm0KlJfwg/WYjG2RZqaW7Y Aihcjx0Ce4w== X-Google-Smtp-Source: AGHT+IFMgZVeb9mt8dds2cE993nNkSHGV/KAwWVuJR54LKVkodlfrIYg7s5lP+pcO3rzGvu6Y5VBl5u6GxQm X-Received: from pjbqx13.prod.google.com ([2002:a17:90b:3e4d:b0:32d:e4c6:7410]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:44:b0:32b:623d:ee91 with SMTP id 98e67ed59e1d1-33bcf8fd82dmr6257978a91.27.1760746070877; Fri, 17 Oct 2025 17:07:50 -0700 (PDT) Date: Fri, 17 Oct 2025 17:07:08 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-17-vipinsh@google.com> Subject: [RFC PATCH 16/21] vfio/pci: Save and restore the PCI state of the VFIO device From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Save and restore the PCI state of the VFIO device which in the normal flow is recorded by VFIO when the device FD is opened for the first time and then reapplied to PCI device when the last opened device FD is closed. Introduce "_ser" version of the struct pci_saved_state{} and struct pci_cap_saved_data{} to serialized saved PCI state for liveupdate. Store PCI state in VFIO in a separate folio as the size is indeterministic at build time to reserve space in struct vfio_pci_core_device_ser{}. Signed-off-by: Vipin Sharma --- drivers/vfio/pci/vfio_pci_core.c | 9 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 176 ++++++++++++++++++++++++- drivers/vfio/pci/vfio_pci_priv.h | 8 +- 3 files changed, 187 insertions(+), 6 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_c= ore.c index 186a669b68a4..44ea3ac8da16 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -487,7 +487,9 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *v= dev) goto out_power; =20 if (vdev->liveupdate_restore) { - vfio_pci_liveupdate_restore_device(vdev); + ret =3D vfio_pci_liveupdate_restore_device(vdev); + if (ret) + goto out_disable_device; } else { /* If reset fails because of the device lock, fail this path entirely */ ret =3D pci_try_reset_function(pdev); @@ -495,10 +497,11 @@ int vfio_pci_core_enable(struct vfio_pci_core_device = *vdev) goto out_disable_device; =20 vdev->reset_works =3D !ret; + + pci_save_state(pdev); + vdev->pci_saved_state =3D pci_store_saved_state(pdev); } =20 - pci_save_state(pdev); - vdev->pci_saved_state =3D pci_store_saved_state(pdev); if (!vdev->pci_saved_state) pci_dbg(pdev, "%s: Couldn't store saved state\n", __func__); =20 diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index 82ff9f178fdc..caef023d007a 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -13,9 +13,22 @@ #include #include #include +#include =20 #include "vfio_pci_priv.h" =20 +struct pci_cap_saved_data_ser { + u16 cap_nr; + bool cap_extended; + unsigned int size; + u32 data[]; +} __packed; + +struct pci_saved_state_ser { + u32 config_space[16]; + struct pci_cap_saved_data_ser cap[]; +} __packed; + struct vfio_pci_core_device_ser { u16 bdf; u32 cfg_size; @@ -23,6 +36,7 @@ struct vfio_pci_core_device_ser { u8 vconfig[PCI_CFG_SPACE_EXP_SIZE]; u32 rbar[7]; u8 reset_works; + u64 pci_saved_state_phys; } __packed; =20 static int vfio_pci_liveupdate_deserialize_config(struct vfio_pci_core_dev= ice *vdev, @@ -51,12 +65,150 @@ static void vfio_pci_liveupdate_serialize_config(struc= t vfio_pci_core_device *vd memcpy(ser->rbar, vdev->rbar, sizeof(vdev->rbar)); } =20 +static size_t pci_saved_state_size(struct pci_saved_state *state) +{ + struct pci_cap_saved_data *cap; + size_t size; + + /* One empty cap to denote end. */ + size =3D sizeof(struct pci_saved_state) + sizeof(struct pci_cap_saved_dat= a); + + cap =3D state->cap; + while (cap->size) { + size_t len =3D sizeof(struct pci_cap_saved_data) + cap->size; + + size +=3D len; + cap =3D (struct pci_cap_saved_data *)((u8 *)cap + len); + } + + return size; +} + +static size_t pci_saved_state_size_from_ser(struct pci_saved_state_ser *st= ate) +{ + struct pci_cap_saved_data_ser *cap; + size_t size; + + /* One empty cap to denote end. */ + size =3D sizeof(struct pci_saved_state) + sizeof(struct pci_cap_saved_dat= a); + + cap =3D state->cap; + while (cap->size) { + size_t len =3D sizeof(struct pci_cap_saved_data) + cap->size; + + size +=3D len; + cap =3D (struct pci_cap_saved_data_ser *)((u8 *)cap + len); + } + + return size; +} + +static void serialize_pci_cap_saved_data(struct pci_saved_state *state, + struct pci_saved_state_ser *state_ser) +{ + struct pci_cap_saved_data_ser *cap_ser =3D state_ser->cap; + struct pci_cap_saved_data *cap =3D state->cap; + + while (cap->size) { + cap_ser->cap_nr =3D cap->cap_nr; + cap_ser->cap_extended =3D cap->cap_extended; + cap_ser->size =3D cap->size; + memcpy(cap_ser->data, cap->data, cap_ser->size); + + cap =3D (void *)cap + sizeof(*cap) + cap->size; + cap_ser =3D (void *)cap_ser + sizeof(*cap_ser) + cap_ser->size; + } +} + +static void deserialize_pci_cap_saved_data(struct pci_saved_state *state, + struct pci_saved_state_ser *state_ser) +{ + struct pci_cap_saved_data_ser *cap_ser =3D state_ser->cap; + struct pci_cap_saved_data *cap =3D state->cap; + + while (cap_ser->size) { + cap->cap_nr =3D cap_ser->cap_nr; + cap->cap_extended =3D cap_ser->cap_extended; + cap->size =3D cap_ser->size; + memcpy(cap->data, cap_ser->data, cap_ser->size); + + cap =3D (void *)cap + sizeof(*cap) + cap->size; + cap_ser =3D (void *)cap_ser + sizeof(*cap_ser) + cap_ser->size; + } +} + +static int serialize_pci_saved_state(struct vfio_pci_core_device *vdev, + struct vfio_pci_core_device_ser *ser) +{ + struct pci_saved_state *state =3D vdev->pci_saved_state; + struct pci_saved_state_ser *state_ser; + struct folio *folio; + size_t size; + int ret; + + if (!state) + return 0; + + size =3D pci_saved_state_size(state); + + folio =3D folio_alloc(GFP_KERNEL | __GFP_ZERO, get_order(size)); + if (!folio) + return -ENOMEM; + + state_ser =3D folio_address(folio); + + memcpy(state_ser->config_space, state->config_space, + sizeof(state_ser->config_space)); + + serialize_pci_cap_saved_data(state, state_ser); + + ret =3D kho_preserve_folio(folio); + if (ret) { + folio_put(folio); + return ret; + } + + ser->pci_saved_state_phys =3D virt_to_phys(state_ser); + + return 0; +} + +static int deserialize_pci_saved_state(struct vfio_pci_core_device *vdev, + struct vfio_pci_core_device_ser *ser) +{ + struct pci_saved_state_ser *state_ser; + struct pci_saved_state *state; + size_t size; + + if (!ser->pci_saved_state_phys) + return 0; + + state_ser =3D phys_to_virt(ser->pci_saved_state_phys); + size =3D pci_saved_state_size_from_ser(state_ser); + state =3D kzalloc(size, GFP_KERNEL); + if (!state) + return -ENOMEM; + + memcpy(state->config_space, state_ser->config_space, + sizeof(state_ser->config_space)); + + deserialize_pci_cap_saved_data(state, state_ser); + vdev->pci_saved_state =3D state; + return 0; +} + static int vfio_pci_lu_serialize(struct vfio_pci_core_device *vdev, struct vfio_pci_core_device_ser *ser) { + int err; + ser->bdf =3D pci_dev_id(vdev->pdev); vfio_pci_liveupdate_serialize_config(vdev, ser); ser->reset_works =3D vdev->reset_works; + err =3D serialize_pci_saved_state(vdev, ser); + if (err) + return err; + return 0; } =20 @@ -101,12 +253,18 @@ static void vfio_pci_liveupdate_cancel(struct liveupd= ate_file_handler *handler, { struct vfio_pci_core_device_ser *ser =3D phys_to_virt(data); struct folio *folio =3D virt_to_folio(ser); + struct folio *pci_saved_state_folio; struct vfio_pci_core_device *vdev; struct vfio_device *device; =20 device =3D vfio_device_from_file(file); vdev =3D container_of(device, struct vfio_pci_core_device, vdev); vdev->pdev->skip_kexec_clear_master =3D false; + if (ser->pci_saved_state_phys) { + pci_saved_state_folio =3D virt_to_folio(phys_to_virt(ser->pci_saved_stat= e_phys)); + WARN_ON_ONCE(kho_unpreserve_folio(pci_saved_state_folio)); + folio_put(pci_saved_state_folio); + } WARN_ON_ONCE(kho_unpreserve_folio(folio)); folio_put(folio); } @@ -139,6 +297,9 @@ static void vfio_pci_liveupdate_finish(struct liveupdat= e_file_handler *handler, =20 ser =3D folio_address(folio); =20 + if (!reclaimed && ser->pci_saved_state_phys) + kho_restore_folio(ser->pci_saved_state_phys); + device =3D vfio_find_device_in_cdev_class(&ser->bdf, match_bdf); if (!device) goto out_folio_put; @@ -155,6 +316,8 @@ static void vfio_pci_liveupdate_finish(struct liveupdat= e_file_handler *handler, put_device(&device->device); =20 out_folio_put: + if (ser->pci_saved_state_phys) + folio_put(virt_to_folio(phys_to_virt(ser->pci_saved_state_phys))); folio_put(folio); } =20 @@ -174,6 +337,11 @@ static int vfio_pci_liveupdate_retrieve(struct liveupd= ate_file_handler *handler, return -ENOENT; =20 ser =3D folio_address(folio); + if (ser->pci_saved_state_phys) { + if (!kho_restore_folio(ser->pci_saved_state_phys)) + return -ENOENT; + } + device =3D vfio_find_device_in_cdev_class(&ser->bdf, match_bdf); if (!device) return -ENODEV; @@ -262,9 +430,15 @@ int vfio_pci_liveupdate_restore_config(struct vfio_pci= _core_device *vdev) return vfio_pci_liveupdate_deserialize_config(vdev, ser); } =20 -void vfio_pci_liveupdate_restore_device(struct vfio_pci_core_device *vdev) +int vfio_pci_liveupdate_restore_device(struct vfio_pci_core_device *vdev) { struct vfio_pci_core_device_ser *ser =3D vdev->liveupdate_restore; + int err; + + err =3D deserialize_pci_saved_state(vdev, ser); + if (err) + return err; =20 vdev->reset_works =3D ser->reset_works; + return 0; } diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_p= riv.h index ee1c7c229020..9d692e4d0cf7 100644 --- a/drivers/vfio/pci/vfio_pci_priv.h +++ b/drivers/vfio/pci/vfio_pci_priv.h @@ -110,14 +110,18 @@ static inline bool vfio_pci_is_vga(struct pci_dev *pd= ev) #ifdef CONFIG_LIVEUPDATE void vfio_pci_liveupdate_init(void); int vfio_pci_liveupdate_restore_config(struct vfio_pci_core_device *vdev); -void vfio_pci_liveupdate_restore_device(struct vfio_pci_core_device *vdev); +int vfio_pci_liveupdate_restore_device(struct vfio_pci_core_device *vdev); #else static inline void vfio_pci_liveupdate_init(void) { } int vfio_pci_liveupdate_restore_config(struct vfio_pci_core_device *vdev) { return -EINVAL; } -void vfio_pci_liveupdate_restore_device(struct vfio_pci_core_device *vdev)= { } +int vfio_pci_liveupdate_restore_device(struct vfio_pci_core_device *vdev) +{ + return -EOPNOTSUPP; +} + #endif /* CONFIG_LIVEUPDATE */ =20 #endif --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:06 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 8BBF622DFA5 for ; Sat, 18 Oct 2025 00:07:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746075; cv=none; b=iA4P8ZUPMRhyzZJ7YgqWwpRJaRGlRy1ruyoVa5UsYjMhcF9VepRgbWh/ZPUPOdvdNP7l9GLsggptMwSoyhmrKSnrDm0u02UruDczWORlmaM6N15R1B/MPvhDjXCFkpazF2WiYYAdUq5PUFiuSkZFZuxDVyLvcajcFbBE2zDZUok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746075; c=relaxed/simple; bh=rJ9Cp8jLPZnMO/vyHJOv9CStAj+XeO61+5EG/UnxQ6I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Z964qGPOxflUnSf02eGkoX/lnc+YASMwci5TcWYezpStL9SEP560x6/FqIxN5WFkRvz9iTECtC7R14zVl+P7XgSxeeJsU/j0go8O5QCcdxUmcIBf6KmkMLjN93vmV8SDHPgu3fdQrSj0CB0Z1a5NtBmngQ0xqjWfTNW515xS27s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=HEcscv1V; arc=none smtp.client-ip=209.85.216.74 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HEcscv1V" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-32eddb7e714so2138574a91.1 for ; Fri, 17 Oct 2025 17:07:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746073; x=1761350873; 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=HFNocetE2VbIEufyY6J89R9nWXx5czYypprM6ljkXqw=; b=HEcscv1Vg1+LRceN8YgebXldMH2/AFKMrI6eoN/gcTkQuTWVNq1/xZySMxDg10e1+i qx1QZZe51Dk9YVjcMoWtJKxpiwwx8gArfuOnc0EEp9UtBi3tV/SVhpYNX8x3T1KH3Lwf wefV/qAgxXxeBcPy/fk40s3vJZKF8oS74kzq02fKl/mQI6j+DfUwrFW9mSmOKszrcbC/ kWz9zKGdCrakboBOQDWg5sBaTQ2nt/7pV6V2y+ORY6Wu9HH9ENX+6tsjQU2H6JVS/00q GAnMx0ia6w6Eq59/PhCLg1MoGhhwR1wyZdeuRiCVZloBWyVC5H4mWmUkYlsmMICuhwHk cRlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746073; x=1761350873; 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=HFNocetE2VbIEufyY6J89R9nWXx5czYypprM6ljkXqw=; b=vwaHhsKvKJEacc7yculI1AjDPyINcVrdyq9B2E4y1tSr2Y1u9R2G1i+oGZOoeDWnkq ihTmT+hqPLFbrYb290LkYpCbvK55FjoFFR6Eg+JMbw/72XBP6uq/n8kSab5NPogqOkja 7s3ouYAvLwuwuL/pAOi6Py4ui+DjylccYNI1caB9w4QCs2x4WoDBDvpTeprxEdOlE12f m1GhwGrxferzv59tRiTfOgvtHI1/OIwyiQ9ZM4wTH+NoC89ksZFOcQoAg2vKT3HpAkVe 6pvlGB1b75hEaInXoVDnUTLuEsYCPmSv7EBovmPhFTgJ80KYETQf2U3H847XVe0Ic+dp 0Wew== X-Forwarded-Encrypted: i=1; AJvYcCUwLc2YwVNilqTHakjlCftS159wIBuGVWjCcLxq5M3UURjBpfPavXrzpszVqXCWWjJ8gCub71dUY1sQ7cY=@vger.kernel.org X-Gm-Message-State: AOJu0YwdYFgfXcjywolNnF/KBcypn4y/nxJePof8tuajVIWJDIITJ9fq RlF+kG/qzuoT9wJGTAZP1M9Sd2uepJ/0VVFrs7zX+IhdPuoLgCjtw2YOvZy8l/Xcaq5PFZaYJLF IfQxevNS0zQ== X-Google-Smtp-Source: AGHT+IFd2MPckrXbHJ+w3m/Sn9+Vb5obFxexWw8NG67z05PyUq/AF1LputymSag3PeWe72e5aqm74u1/N/Zh X-Received: from pjis18.prod.google.com ([2002:a17:90a:5d12:b0:33b:cf89:6fe6]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2411:b0:33b:cfac:d5c6 with SMTP id 98e67ed59e1d1-33bcfacd677mr4259016a91.29.1760746072971; Fri, 17 Oct 2025 17:07:52 -0700 (PDT) Date: Fri, 17 Oct 2025 17:07:09 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-18-vipinsh@google.com> Subject: [RFC PATCH 17/21] vfio/pci: Disable interrupts before going live update kexec From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Disable VFIO interrupts configured on device during live update freeze callback. As there is no way for those interrupts to be handled during kexec, better stop the interrupts and let userspace reconfigure them after kexec. Signed-off-by: Vipin Sharma --- drivers/vfio/pci/vfio_pci_liveupdate.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index caef023d007a..5d786ace6bde 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -248,6 +248,22 @@ static int vfio_pci_liveupdate_prepare(struct liveupda= te_file_handler *handler, return err; } =20 +static int vfio_pci_liveupdate_freeze(struct liveupdate_file_handler *hand= ler, + struct file *file, u64 *data) +{ + struct vfio_pci_core_device *vdev; + struct vfio_device *device; + + device =3D vfio_device_from_file(file); + vdev =3D container_of(device, struct vfio_pci_core_device, vdev); + + guard(mutex)(&vdev->igate); + if (vdev->irq_type =3D=3D VFIO_PCI_NUM_IRQS) + return 0; + return vfio_pci_set_irqs_ioctl(vdev, VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SE= T_ACTION_TRIGGER, + vdev->irq_type, 0, 0, NULL); +} + static void vfio_pci_liveupdate_cancel(struct liveupdate_file_handler *han= dler, struct file *file, u64 data) { @@ -403,6 +419,7 @@ static bool vfio_pci_liveupdate_can_preserve(struct liv= eupdate_file_handler *han =20 static const struct liveupdate_file_ops vfio_pci_luo_fops =3D { .prepare =3D vfio_pci_liveupdate_prepare, + .freeze =3D vfio_pci_liveupdate_freeze, .cancel =3D vfio_pci_liveupdate_cancel, .finish =3D vfio_pci_liveupdate_finish, .retrieve =3D vfio_pci_liveupdate_retrieve, --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:06 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 3D92023BF8F for ; Sat, 18 Oct 2025 00:07:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746077; cv=none; b=FH0mdMn4J64sTENQPDoFy9/oLv6irPYAkCAzha/dnCfeBqe0xeo+3jJi1lDmXs1D0YAPRUF/qnx866wnS5NG7RoiZde9v38EdP2cZ1P0wZAJ65WtmiCj46+QvLe1XR8oLRoczIxzOzvCm9UYnB1K6H/PxxpPSHN8dqR0K3llYT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746077; c=relaxed/simple; bh=vicAzr5G8Nj5bOl8kj0FUCuW44ReHeVMHkvxO4eBHz4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=F5y2NLQfjvMDigAAHiZTneJegGJAquclBi1ttx/htxmvTGi9RPkGVPps/TBjL9mtOwyV8kqw6gXo4TnjfHa6vvviNXp9jyD/wMmYJKoGMqiX3P1q4uHGROfWNbcD0IDWFeJrsb7pzQYAsFcyshqrix3QMcBd6qytklghQftsN1U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=U5/RTL53; arc=none smtp.client-ip=209.85.216.73 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="U5/RTL53" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-33428befbbaso2942225a91.0 for ; Fri, 17 Oct 2025 17:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746075; x=1761350875; 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=xzsZ79Fc/eYrSb6uSl+QE8GB+MXNffylOcBysTYipsc=; b=U5/RTL538N872HxOtaXPLwywRcEmzr7k54UR9c5A92Q4Ta2gMkv4b/nP5GVidOQY38 Amdd1wcy/jGp7t7+ByNp+KCEPjwzTv0hlABEZafnlifUsbJgUEozGuy64L64qsHU2Lfe XhmdnCAQr+/oxj98zFengad+R7jUgg7LQSqPcoCoV4ia+9e1uGI/0GkSLRWHfE692Jsr B+L10BhIalXvtHkhKFCusMJ5JbEkcaPoTjmUd8lvINi6GEJN6rJ9CslUOMls00eeSJUg 5OlJQ2B+tWULlzgbdg6RvvJ0RWXFq8caAl4XLjTuruAHcs0WvFL2JGmFO/ZyznSMiSvT k3Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746075; x=1761350875; 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=xzsZ79Fc/eYrSb6uSl+QE8GB+MXNffylOcBysTYipsc=; b=u+mDow6cnnR8jR090Kk5/zieHPwjdFS1NL3x/+p2qym8XjamhKOJsqr+poNKxcHFnq 38JhC97+Qj4UsItX4Gr8ku18P5u2Ty4Kbq/+vYF0Bgc0lFbzadmkFuJQTFmOWd5+lHjF j9Shnn2/Pk0r5FjBRkfLnI68YDJcFcyyhCh5p+sNfRfsCT3OkPOrmJUU5d8ko8aPUV2P YcEywM26V4C08oQ4cZ3Sa40VtMopJ7462zq4GaBI7zF8f8BumK/mvsx6xCXXaJKMHXcg 1Q6tT6kxCltw8i4HRa5CpdwQhq0exMah7z0afSirVuzzAhKADgKuijY16+wzYbdrO75L Z4Kw== X-Forwarded-Encrypted: i=1; AJvYcCUsq+KHUl/CoZEiqfIEeVX1F+pOuKoiAmZaEiZMAMJyC/18FXPK6B46N9fsjxvnXecxRkS7bf7lGpdTVIE=@vger.kernel.org X-Gm-Message-State: AOJu0YwtcoybI1ivWUjsp3CxWGsbuZeYm+c7M4nrvDZ7t4uPivix6w3v E2JWCPXLDi0So0ttMso76a6pyHO6OAkcw5xno4eIwIBDLDcI88yP5eG4sJ3bNQYMjkicS6XYjlv Lb2UFYjB7Tw== X-Google-Smtp-Source: AGHT+IH5Agotaie8Yfpd4OzcADNWVRMuZUwHnAmsdAx38ewjmLDznR7pF55YyI5GG3nzDG73A6J4oF7pzhXs X-Received: from pjbgq8.prod.google.com ([2002:a17:90b:1048:b0:33b:da89:9788]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5386:b0:32d:ea1c:a4e5 with SMTP id 98e67ed59e1d1-33bcf85128emr6136432a91.1.1760746074698; Fri, 17 Oct 2025 17:07:54 -0700 (PDT) Date: Fri, 17 Oct 2025 17:07:10 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-19-vipinsh@google.com> Subject: [RFC PATCH 18/21] vfio: selftests: Build liveupdate library in VFIO selftests From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Import and build liveupdate selftest library in VFIO selftests. It allows to use liveupdate ioctls in VFIO selftests Signed-off-by: Vipin Sharma --- tools/testing/selftests/vfio/Makefile | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/vfio/Makefile b/tools/testing/selftest= s/vfio/Makefile index 324ba0175a33..c7f271884cb4 100644 --- a/tools/testing/selftests/vfio/Makefile +++ b/tools/testing/selftests/vfio/Makefile @@ -6,16 +6,24 @@ TEST_GEN_PROGS +=3D vfio_pci_driver_test TEST_PROGS_EXTENDED :=3D run.sh include ../lib.mk include lib/libvfio.mk +include ../liveupdate/lib/libliveupdate.mk =20 CFLAGS +=3D -I$(top_srcdir)/tools/include CFLAGS +=3D -MD CFLAGS +=3D $(EXTRA_CFLAGS) =20 -$(TEST_GEN_PROGS): %: %.o $(LIBVFIO_O) - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< $(LIBVFIO_O) $(LDLIBS) -o $@ +LIBS_O :=3D $(LIBVFIO_O) +LIBS_O +=3D $(LIBLIVEUPDATE_O) + +TEST_GEN_ALL_PROGS :=3D $(TEST_GEN_PROGS) +TEST_GEN_ALL_PROGS +=3D $(TEST_GEN_PROGS_EXTENDED) + +$(TEST_GEN_ALL_PROGS): %: %.o $(LIBS_O) + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $< $(LIBS_O) $(LDLI= BS) -o $@ =20 TEST_GEN_PROGS_O =3D $(patsubst %, %.o, $(TEST_GEN_PROGS)) -TEST_DEP_FILES =3D $(patsubst %.o, %.d, $(TEST_GEN_PROGS_O) $(LIBVFIO_O)) +TEST_GEN_PROGS_O +=3D $(patsubst %, %.o, $(TEST_GEN_PROGS_EXTENDED)) +TEST_DEP_FILES =3D $(patsubst %.o, %.d, $(TEST_GEN_PROGS_O) $(LIBS_O)) -include $(TEST_DEP_FILES) =20 EXTRA_CLEAN +=3D $(TEST_GEN_PROGS_O) $(TEST_DEP_FILES) --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:06 2026 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 E7A3D23F40C for ; Sat, 18 Oct 2025 00:07:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746079; cv=none; b=AJXY+0Qfyil+Wewp4KtYVXtf/j1J1CY/RfoqIaE5yVntkCPosVPOmjM6VnL64ma9zTAbSXMIae3UV1R17HfapZ4GA+xIuUceyqCYcjhyKE0hxD16qSAVuoDmsWyD+zXVALzapr+uLdnNqTvtlWsx10sVAlsJkiXBPtT52sCHy1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746079; c=relaxed/simple; bh=M2+JBMCO1L+FuYx2GCn7BiCKdMGCnMS81y4JT/5Boo0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AKbgOMcBRkZ7y6PruNkQDTVsHKOy3vOd5eAXjTpJLCjqY1EH14QT65bauD8imsFwrrdqC96DfjARP9DHGYn56qsSpuZQU2VwQtBav5yWS00UAKUJT7KhDpQNbEIAHRDJ+gqmp1YAHXkuzJv3ip4OOVs2ms8qbiid1vHNFR6HrCY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NW2EUbBR; arc=none smtp.client-ip=209.85.215.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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NW2EUbBR" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b57cf8dba28so2240502a12.1 for ; Fri, 17 Oct 2025 17:07:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746076; x=1761350876; 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=ydhS89cP0Z2GUDxoQAtz3nc85hlQYU5pjgD7NtdLoQw=; b=NW2EUbBR593jgveIC1mF4rlUVscg6ZVWp+x6BQUackchvoiI7qJhyHIcl5SqFKR9r4 F9RcIKhrDtyk7NziKorvEgWUyujgR5piaC6VG0IlmfUfiRnl2DUSj4CmLWEHq4Jng8AW ZQlkZBwsJ1dtvBnqg8AvOIHLq6GmAwiRDiFgWmZ1ycfF0l2wLZWSou94/Ch5FNfDsXg1 mEbfqit/fqmuMQZJD5dGCs6paz5uv95E1MYQZIK2YMiZbPqpMFdQYoZuKVpjU8kVJhzw NgTM68Y4E2E1XIo8WcSzqS2ENqn1ykjFsBnQtERpxT2fJX/KQbJrQzc1pBi6/M8IUvZ3 MHZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746076; x=1761350876; 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=ydhS89cP0Z2GUDxoQAtz3nc85hlQYU5pjgD7NtdLoQw=; b=hSDyUEJleIc8qusry7zoDn/pb6Pp69Wx7lTSkHOg6X6rwzhqZsqH1/a16ISJYxlC5u iS3jGL13RIZKgq+wD7HaF518eJCdfZCuX91dI1QPoGT3O+jWlO4Dko+BIchWNcp6zeRc ZELUtxK91/env0dBqDgZwdS0CCsQG81nguxgq40GSuUDdlGRYG8KVTQ5CGf/Btc+BdhD Ai1P17l/r1CAnmpCZdGdWL0zj0jzSEjoJw8/OVXXj2jXD8Atgag9JDWSZBt9MQLQxrdk WWs3qsuP0Lll1zlwhBHiwllR38xP0YCIdaXjde70relxcSlS6IfE5jPoJqNs/75OO6PB FANA== X-Forwarded-Encrypted: i=1; AJvYcCWpY70mvIK6i3B0fgjAvN999nzakti8NXGBO4CTiKeIeCZmdA6tB8UBZ2XQQ/v1+GQrV8TA5Or0m5RNAAU=@vger.kernel.org X-Gm-Message-State: AOJu0YyxicjFiKDDx3mppH8JoXO4OVQk01yshtXB0mc4OxNwI6YUQTaY 0jrwJSFJ+IehO3qDI10n2ZTP0PTd/zNeLFDh1pY+vXBNJXoTUuanahaNGZgnhjR2FLdjm+7zlWY WRKVjop4HVw== X-Google-Smtp-Source: AGHT+IFlKo2S/6ZxOLbnUbsEzTjZo01MBS/KrDhCOEW25HVXu091cfhApJVkE8GIU3Ir27SiQDoh2GBWuOw0 X-Received: from pjis18.prod.google.com ([2002:a17:90a:5d12:b0:33b:cf89:6fe6]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5281:b0:330:a301:35f4 with SMTP id 98e67ed59e1d1-33bcf8e95dbmr7008618a91.20.1760746076272; Fri, 17 Oct 2025 17:07:56 -0700 (PDT) Date: Fri, 17 Oct 2025 17:07:11 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-20-vipinsh@google.com> Subject: [RFC PATCH 19/21] vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the given VFIO cdev FD to initialize vfio_pci_device in VFIO selftests. Add the assertion to make sure that passed cdev FD is not used with legacy VFIO APIs. If VFIO cdev FD is provided then do not open the device instead use the FD for any interaction with the device. This API will allow to write selftests where VFIO device FD is preserved using liveupdate and retrieved later using liveupdate ioctl after kexec. Signed-off-by: Vipin Sharma --- .../selftests/vfio/lib/include/vfio_util.h | 1 + .../selftests/vfio/lib/vfio_pci_device.c | 33 +++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/vfio/lib/include/vfio_util.h b/tools/t= esting/selftests/vfio/lib/include/vfio_util.h index ed31606e01b7..8ec60a62a0d1 100644 --- a/tools/testing/selftests/vfio/lib/include/vfio_util.h +++ b/tools/testing/selftests/vfio/lib/include/vfio_util.h @@ -203,6 +203,7 @@ const char *vfio_pci_get_cdev_path(const char *bdf); extern const char *default_iommu_mode; =20 struct vfio_pci_device *vfio_pci_device_init(const char *bdf, const char *= iommu_mode); +struct vfio_pci_device *vfio_pci_device_init_fd(int vfio_cdev_fd); void vfio_pci_device_cleanup(struct vfio_pci_device *device); void vfio_pci_device_reset(struct vfio_pci_device *device); =20 diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/tes= ting/selftests/vfio/lib/vfio_pci_device.c index 0921b2451ba5..cab9c74d2de8 100644 --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c @@ -486,13 +486,18 @@ static void vfio_device_attach_iommufd_pt(int device_= fd, u32 pt_id) ioctl_assert(device_fd, VFIO_DEVICE_ATTACH_IOMMUFD_PT, &args); } =20 -static void vfio_pci_iommufd_setup(struct vfio_pci_device *device, const c= har *bdf) +static void vfio_pci_iommufd_setup(struct vfio_pci_device *device, + const char *bdf, int vfio_cdev_fd) { - const char *cdev_path =3D vfio_pci_get_cdev_path(bdf); =20 - device->fd =3D open(cdev_path, O_RDWR); + if (vfio_cdev_fd > 0) { + device->fd =3D vfio_cdev_fd; + } else { + const char *cdev_path =3D vfio_pci_get_cdev_path(bdf); + device->fd =3D open(cdev_path, O_RDWR); + free((void *)cdev_path); + } VFIO_ASSERT_GE(device->fd, 0); - free((void *)cdev_path); =20 /* * Require device->iommufd to be >0 so that a simple non-0 check can be @@ -507,7 +512,9 @@ static void vfio_pci_iommufd_setup(struct vfio_pci_devi= ce *device, const char *b vfio_device_attach_iommufd_pt(device->fd, device->ioas_id); } =20 -struct vfio_pci_device *vfio_pci_device_init(const char *bdf, const char *= iommu_mode) +struct vfio_pci_device *__vfio_pci_device_init(const char *bdf, + const char *iommu_mode, + int vfio_cdev_fd) { struct vfio_pci_device *device; =20 @@ -518,10 +525,13 @@ struct vfio_pci_device *vfio_pci_device_init(const ch= ar *bdf, const char *iommu_ =20 device->iommu_mode =3D lookup_iommu_mode(iommu_mode); =20 + VFIO_ASSERT_FALSE(device->iommu_mode->container_path !=3D NULL && vfio_cd= ev_fd > 0, + "Provide either container path or VFIO cdev FD, not both.\n"); + if (device->iommu_mode->container_path) vfio_pci_container_setup(device, bdf); else - vfio_pci_iommufd_setup(device, bdf); + vfio_pci_iommufd_setup(device, bdf, vfio_cdev_fd); =20 vfio_pci_device_setup(device); vfio_pci_driver_probe(device); @@ -529,6 +539,17 @@ struct vfio_pci_device *vfio_pci_device_init(const cha= r *bdf, const char *iommu_ return device; } =20 +struct vfio_pci_device *vfio_pci_device_init(const char *bdf, + const char *iommu_mode) +{ + return __vfio_pci_device_init(bdf, iommu_mode, -1); +} + +struct vfio_pci_device *vfio_pci_device_init_fd(int vfio_cdev_fd) +{ + return __vfio_pci_device_init(NULL, "iommufd", vfio_cdev_fd); +} + void vfio_pci_device_cleanup(struct vfio_pci_device *device) { int i; --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:06 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 DC43F244668 for ; Sat, 18 Oct 2025 00:07:58 +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=1760746082; cv=none; b=ehhDvYox/+assccVxmjE6TmjZw4fdH66NlJxt1U9T97mQXLe1lKpLnAzq7lnuNahFYpyYn5eNpiXWbqxG5llH6u2HLIlCJB8SRJ6aGD/bkRkDiutWVlY43mZ+//kvgU9UudZpg9xpFOUPDGe2PTpWTTM4NRFBSAoDMhZXpSnbJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746082; c=relaxed/simple; bh=L7bQsmwx8ZEiES29AaBMBPJDcgdVXbcHzVj4Z5bbaGU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kOve5LwA759ZREUqH0ULWNAZjhN/fMtKv5Sk/G2ZsBWrVK3hkzpRzKh2mckItp0CRthAPCIb1UlP24lFOqAPVAzw86Hpkw9ZzCbnKeQpnJMJokJ0rAVy8WM9qd62NjKG6OT9BFP40xJv0Rj3BUsaGLccpOvho+3eooCtVAHqYY0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Q10bwwsl; 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Q10bwwsl" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2924b3b9d47so1042565ad.0 for ; Fri, 17 Oct 2025 17:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746078; x=1761350878; 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=jwtg4bEBkOAaSJBH9eJxsurOXu99SsbvOed4JRZ9vuM=; b=Q10bwwsl0fLetkY8IBCDDieBttB4Q0ujAEDKR+rBYDag6J5KHIr9IaYHlEg+qjUo1G 1exg07b60Ezv4gDecX6Wxi8mCRqKTPdrxKIqr9Wy3RzOpNG9/QFd/4/I3GzvRf/AJ+7h EP1aUJc2UnCDYjl9Hoi0rPo+oCdVXO2CPqHw/89+tb4aILBQoloyMKOWOS8DBrNdJV2V +WsDOJLjaxIW0+PpuG6mSgKK40CNruz2kxYsxtOJY1JWJ2sfPU5A7P5800oVlFnXke9k +XeSwsojcK/U1+7T+7/gX5hDCREFpP7su0pKahUQQyM2efFimggUZq/vWm0TUjtMh7du GVWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746078; x=1761350878; 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=jwtg4bEBkOAaSJBH9eJxsurOXu99SsbvOed4JRZ9vuM=; b=Y9fiY/B1IUa/30pLFT2eSnQeoObZnX+MvydFaluV7BJsC6TXCFyA1ULDp072lvCSn6 ToYblPMDPWcb4r26bMHGolFernwH2XhqSqdWVm0UNRilwFjzAnCTiRWzKdRhfnkBhEfq OxzixcNRiPqs6iLTvgKGUocZzrRPAVIoo6EUqnv/+xmfQEoI3h6KtOtWRxISkSnLhKcn /ZDbtebxoOqWN45iif+scYMKSfG49j53mBZGDmtkQOsNFb3QVN5sEpu0OHtrtO1oeebI IPNSOvWNkMgVWEKUdZwR3KL0hWg2UOMCoV5BtVhqa/UrFljLFX+SaJtKsL1KQzpTCVTA C5TA== X-Forwarded-Encrypted: i=1; AJvYcCX5vEz83pNPH4aJ3F+54qraG3h4JERSg0/J1lGRSOnqwVs25mk9F1rDIi3mlDUY10nhtPJBUtIBEvhZ1ao=@vger.kernel.org X-Gm-Message-State: AOJu0Ywnbuj2djLk3PQEPSH61XvDV95BvxmUWS6FKxBrhdtI+QXxwGd6 hbK120QAOCrAzDyoNyDb0HoyfCEfUDh6lII15k3BJrK7GIPnSSV+uVYmBBaSiwfdc4ypLhR8ESe AdT0EiKq+iQ== X-Google-Smtp-Source: AGHT+IGPunWrE69G7Pp3xNpNGMHvy48e05wfcB9s0P6nq+4nmRJL/y5Vc5fV/xG3iuY7KjA+wnCFMmKqGR3H X-Received: from pjbfv23.prod.google.com ([2002:a17:90b:e97:b0:33b:cfaf:ce3e]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:240d:b0:290:ac36:2ecd with SMTP id d9443c01a7336-290c9ca66famr73630705ad.14.1760746078012; Fri, 17 Oct 2025 17:07:58 -0700 (PDT) Date: Fri, 17 Oct 2025 17:07:12 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-21-vipinsh@google.com> Subject: [RFC PATCH 20/21] vfio: selftests: Add VFIO live update test From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Write a test to exercise VFIO live update support on the passed device BDF. Provide different behavior of the test based on host live update state (NORMAL or UPDATED). When test is executed in NORMAL state, initialize a VFIO PCI device and enable its Bus Master Enable bit by writing to PCI command register. Create a live update session, and pass the VFIO device FD to it for preservation. Preserve the session and then send the global live update prepare event. If everything is fine up to this point, then reboot the kernel using kexec. When test is executed in UPDATED state, retrieve the session from Live Update Orchestrator, restore the VFIO FD from the session. Use the restored FD to initialize vfio_pci_device in selftest. Move the host to NORMAL state and verify if the Bus Master Enable bit is still enabled on the VFIO device. Test will not be auto run, therefore, only build this test and let the user run the test manually with the command: ./run.sh -d 0000:6a:01.0 ./vfio_pci_liveupdate_test Signed-off-by: Vipin Sharma --- tools/testing/selftests/vfio/Makefile | 1 + .../selftests/vfio/vfio_pci_liveupdate_test.c | 106 ++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_test.c diff --git a/tools/testing/selftests/vfio/Makefile b/tools/testing/selftest= s/vfio/Makefile index c7f271884cb4..949b7fcc091e 100644 --- a/tools/testing/selftests/vfio/Makefile +++ b/tools/testing/selftests/vfio/Makefile @@ -3,6 +3,7 @@ TEST_GEN_PROGS +=3D vfio_dma_mapping_test TEST_GEN_PROGS +=3D vfio_iommufd_setup_test TEST_GEN_PROGS +=3D vfio_pci_device_test TEST_GEN_PROGS +=3D vfio_pci_driver_test +TEST_GEN_PROGS_EXTENDED +=3D vfio_pci_liveupdate_test TEST_PROGS_EXTENDED :=3D run.sh include ../lib.mk include lib/libvfio.mk diff --git a/tools/testing/selftests/vfio/vfio_pci_liveupdate_test.c b/tool= s/testing/selftests/vfio/vfio_pci_liveupdate_test.c new file mode 100644 index 000000000000..9fd0061348e0 --- /dev/null +++ b/tools/testing/selftests/vfio/vfio_pci_liveupdate_test.c @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Copyright (c) 2025, Google LLC. + * Vipin Sharma + */ + +#include +#include +#include +#include +#include +#include +#include + +#define SESSION_NAME "multi_file_session" +#define TOKEN 1234 + +static void run_pre_kexec(int luo_fd, const char *bdf) +{ + struct vfio_pci_device *device; + int session_fd; + u16 command; + + device =3D vfio_pci_device_init(bdf, "iommufd"); + + command =3D vfio_pci_config_readw(device, PCI_COMMAND); + VFIO_ASSERT_FALSE(command & PCI_COMMAND_MASTER); + + vfio_pci_config_writew(device, PCI_COMMAND, + command | PCI_COMMAND_MASTER); + + session_fd =3D luo_create_session(luo_fd, SESSION_NAME); + VFIO_ASSERT_GE(session_fd, 0, "Failed to create session %s", + SESSION_NAME); + VFIO_ASSERT_EQ(luo_session_preserve_fd(session_fd, device->fd, TOKEN), + 0, "Failed to preserve VFIO device"); + VFIO_ASSERT_EQ(luo_set_global_event(luo_fd, LIVEUPDATE_PREPARE), 0, + "Failed to set global PREPARE event"); + + VFIO_ASSERT_EQ(system(KEXEC_SCRIPT), 0, "kexec script failed"); + + sleep(10); /* Should not be reached */ + vfio_pci_device_cleanup(device); + exit(EXIT_FAILURE); +} + +static void run_post_kexec(int luo_fd, const char *bdf) +{ + int session_fd; + int vfio_fd; + struct vfio_pci_device *device; + u16 command; + + + session_fd =3D luo_retrieve_session(luo_fd, SESSION_NAME); + VFIO_ASSERT_GE(session_fd, 0, "Failed to retrieve session %s", + SESSION_NAME); + + vfio_fd =3D luo_session_restore_fd(session_fd, TOKEN); + if (vfio_fd < 0) { + printf("Failed to restore VFIO device, error %d", vfio_fd); + exit(1); + } + + device =3D vfio_pci_device_init_fd(vfio_fd); + + if (luo_set_global_event(luo_fd, LIVEUPDATE_FINISH) < 0) { + printf("Failed to set global FINISH event"); + exit(1); + } + + close(session_fd); + + command =3D vfio_pci_config_readw(device, PCI_COMMAND); + VFIO_ASSERT_TRUE(command & PCI_COMMAND_MASTER); + vfio_pci_device_cleanup(device); +} + +int main(int argc, char *argv[]) +{ + enum liveupdate_state state; + const char *device_bdf; + int luo_fd; + + device_bdf =3D vfio_selftests_get_bdf(&argc, argv); + + luo_fd =3D luo_open_device(); + VFIO_ASSERT_GE(luo_fd, 0, "Failed to open %s", LUO_DEVICE); + VFIO_ASSERT_EQ(luo_get_global_state(luo_fd, &state), 0, "Failed to get LU= O state."); + + switch (state) { + case LIVEUPDATE_STATE_NORMAL: + printf("Running pre-kexec actions.\n"); + run_pre_kexec(luo_fd, device_bdf); + break; + case LIVEUPDATE_STATE_UPDATED: + printf("Running post-kexec actions.\n"); + run_post_kexec(luo_fd, device_bdf); + break; + default: + printf("Test started in an unexpected state: %d", state); + } + + close(luo_fd); +} --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sun Feb 8 01:52:06 2026 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 DAB2A24E4C3 for ; Sat, 18 Oct 2025 00:08:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746082; cv=none; b=iakOqEQkmpABXV2GdmQzCXxvk2TgdOyET+6CNOeDSVJg7p2hSVb4iGWiI/K3MP1sYbHRvxlDcqLxCrg1d0XHsmSZ42dA29/7Y09M7MnhzE8/6Ej9GEL3WFPFQN8A8pG72xGfsYD5vBESEmDrBh8QFxeS4lb8cFVFlWZ4pCJM04o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746082; c=relaxed/simple; bh=AadBcH6XuFUx3o/uyM4DKBt13sMey6ABFLv07q0/8bs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=l92qTMBwNYiaLvLyzSTCwu9sBtF2UeTlgrUWvLdczkqqgDSV9ILJusJMmuZydjgYo73Vzp3T0pF9wQSzBbzSboYdj6UfKrqyQJgUzvGJjiwrRMz/WwNeygdzS8eLTkri5Ioah/tPK0kLClHCwT8XA0p4LmcNepmfV4bYqjYoQFE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=HmVv89H6; arc=none smtp.client-ip=209.85.215.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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HmVv89H6" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b632471eda1so2191191a12.0 for ; Fri, 17 Oct 2025 17:08:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746080; x=1761350880; 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=Wf0V49FB2cemzthaMtFIU/EunA9kfJDBrs1ERauwF5c=; b=HmVv89H6ag/Qjal6jKnudJV076pe8pdNfdacsyF/qqidCkLPbYJLAOef/hhR85QBRb lOAbqn90v8jNs78lWIBwom7ceWAsdd41xE+TSnD4iq5+vsvUy3/J+3pM1STK4tMvl/tT X6ZF5ZiIgwUgTdI5q1GA9jWmWwhe8nBzyrqPU85q1YTQCeFU2/RGDfYS9/9uK0poSJio FCX0zwsW6B2ZoJu+IUitB0wLLMfrI1kzDzwW0Bhj9v/phQfrRzGCTOgbRNkQtt310g2D qKeO9yhNfKjoH69dNQ/6GZSZq46ICoXb7lZjb9qf2mVs1oSPHWVFJa01P00Tnjk+i2kt ca2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746080; x=1761350880; 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=Wf0V49FB2cemzthaMtFIU/EunA9kfJDBrs1ERauwF5c=; b=hcqUt85iKwWdhhlRqVF/h5i0XEnfShquGcdajpSb5YQWov0VUVsPYYwXXkEibI1qT5 455xitXcvqVmxIFh2Fas/Eo6niaV6FNQhRrsi6uS2PPzliQGfHZ7kC78bKjBdhHhvYgp X01aGiEiKlftlwKIdFCdmxTM7kj+A8aKKw4iadkDcmZacJvhuoproAWOWIT71c7cQNcs dSfihUXDdOO7sOZnOjXCcvj6Xw1allrMpMrQ0CVqEIc833MrcwDq3Ndtu7vkP6b7mNRY QvCKG8XaFQK2SkNrj0OjKTBo27nwRAzuryKZ3CSLZLwTNicqpKsPRvf1sed+ez8e93o2 NbgQ== X-Forwarded-Encrypted: i=1; AJvYcCU6p7ToW7PPOJUsABGYPugBqHZ4koltBOUQJ9nS2vkosWuKu0alRhLwF5xzFxwHl0euNpPnSP0TqEBTlNM=@vger.kernel.org X-Gm-Message-State: AOJu0YzwWXB3bHzmN7P6BTgYgE9arB8gL7TqNI++gdeUMkGi69oyoVkJ aO4JERMyOQWjRZZGEVtGj//K/zSS/EONwBV5ccXqJtk05eDvE07vziO+V422XJCMy47f1L1BnVU /5xvCMtnvJg== X-Google-Smtp-Source: AGHT+IH3PSOfb25TFSyUmjh3MfKE86e6WefuP65fW8Nk0BjyxdVOlYJQBG/sYV/zeL2CFmcYNYIQrzD32GyP X-Received: from pjbfs17.prod.google.com ([2002:a17:90a:f291:b0:32e:bcc3:ea8e]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:3c8e:b0:334:9c41:bdcb with SMTP id adf61e73a8af0-334a86445ddmr6954433637.58.1760746080171; Fri, 17 Oct 2025 17:08:00 -0700 (PDT) Date: Fri, 17 Oct 2025 17:07:13 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-22-vipinsh@google.com> Subject: [RFC PATCH 21/21] vfio: selftests: Validate vconfig preservation of VFIO PCI device during live update From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Test preservation of a VFIO PCI device virtual config (vconfig in struct vfio_pci_core_device{}) during the live update. Write some random data to PCI_INTERRUPT_LINE register which is virtualized by VFIO and verify that the same data is read after kexec. Certain bits in the config space are virtualized by VFIO, so write to them don't go to the device PCI config instead they are stored in memory. After live update, vconfig should have the value same as prior to kexec, which means vconfig should be saved in KHO and later retrieved to restore the device. Signed-off-by: Vipin Sharma --- .../testing/selftests/vfio/vfio_pci_liveupdate_test.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/testing/selftests/vfio/vfio_pci_liveupdate_test.c b/tool= s/testing/selftests/vfio/vfio_pci_liveupdate_test.c index 9fd0061348e0..2d80fdcb1ef7 100644 --- a/tools/testing/selftests/vfio/vfio_pci_liveupdate_test.c +++ b/tools/testing/selftests/vfio/vfio_pci_liveupdate_test.c @@ -15,12 +15,14 @@ =20 #define SESSION_NAME "multi_file_session" #define TOKEN 1234 +#define RANDOM_DATA 0x12 =20 static void run_pre_kexec(int luo_fd, const char *bdf) { struct vfio_pci_device *device; int session_fd; u16 command; + u8 data; =20 device =3D vfio_pci_device_init(bdf, "iommufd"); =20 @@ -30,6 +32,10 @@ static void run_pre_kexec(int luo_fd, const char *bdf) vfio_pci_config_writew(device, PCI_COMMAND, command | PCI_COMMAND_MASTER); =20 + vfio_pci_config_writeb(device, PCI_INTERRUPT_LINE, RANDOM_DATA); + data =3D vfio_pci_config_readb(device, PCI_INTERRUPT_LINE); + VFIO_ASSERT_EQ(data, RANDOM_DATA); + session_fd =3D luo_create_session(luo_fd, SESSION_NAME); VFIO_ASSERT_GE(session_fd, 0, "Failed to create session %s", SESSION_NAME); @@ -51,6 +57,7 @@ static void run_post_kexec(int luo_fd, const char *bdf) int vfio_fd; struct vfio_pci_device *device; u16 command; + u8 data; =20 =20 session_fd =3D luo_retrieve_session(luo_fd, SESSION_NAME); @@ -74,6 +81,9 @@ static void run_post_kexec(int luo_fd, const char *bdf) =20 command =3D vfio_pci_config_readw(device, PCI_COMMAND); VFIO_ASSERT_TRUE(command & PCI_COMMAND_MASTER); + + data =3D vfio_pci_config_readb(device, PCI_INTERRUPT_LINE); + VFIO_ASSERT_EQ(data, RANDOM_DATA); vfio_pci_device_cleanup(device); } =20 --=20 2.51.0.858.gf9c4a03a3a-goog