From nobody Wed Feb 11 07:50:16 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 2B4BD38F95D for ; Mon, 2 Feb 2026 22:30:49 +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=1770071450; cv=none; b=ryJg9e2pGvBlE8vzARGc9UPw64AjIKU5Li9jNdkhqPhDNbqzYiWuMMGfYqsJ2yCb4lqvM/VqHvuVpru/8tMUlKAhiHhi5PQHiUh6knj0uVemLt4f2B0LvYy/B82SN1YKMZObKX45hqziVset7ehTFlhofyhJjDBpRCxI93AUA8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770071450; c=relaxed/simple; bh=cCejNhvt76UNSe20VwpAkdKK8YRqq35Jr/Lc5Fy4AxY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Infg4+ioJaP+dKQkK4jIoCYIjM17I4p7/3UrJJgslUroYlxh3Bs671hONAax/aRKfGkAnJJXSIwTNu6N2cNgqcLLEbC11hSwSl2ZmFLAGh26ry9Q2KKcrBlKnRmG5bwvUnKR4tGAfupfvk7Eg5BAVztDJiKlgu45la2O+pHoWjU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ackerleytng.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=n+M0JWyC; 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--ackerleytng.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="n+M0JWyC" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2a863be8508so64756125ad.2 for ; Mon, 02 Feb 2026 14:30:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770071449; x=1770676249; 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=lp6r0BczMMAAPO3s3DGH7VMU4KkeGwOWlm5O8YplfuE=; b=n+M0JWyCykfRozAVeM1Q0Je/kEkSeWjro10HhV7cXZmlxHb5Xh46Txto6wIpuFn08C YAXRDPw/ATJ6AuZkWL9YGHtylKi9oXMqTaCq41lQQAgowH74K5Pqmq7foF1n6021nhr9 cn4l7nKUwA7Znz/hJ1Br9hDGUTbtxskzbUeYRpAluxSlFmtA1TbyS+7VumKrxjquZoPF 2XCKQ2eIRlGSRkUy/VA6AGyBuDostnFtXnsUoa9aUMWgNujz34/HMZtpEZ16Tm5f6elb 6Xaf7nizrbfT6PUBpVNStxV8YXB7399cPaULXoVWn0gvcFLI9miHxgraAybYwgFIQKlS 6g9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770071449; x=1770676249; 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=lp6r0BczMMAAPO3s3DGH7VMU4KkeGwOWlm5O8YplfuE=; b=tP+LjIzZ+rZXer9/38J0iPWlR305irADzlmbTT9ToQAcMk3G9EJHT51sxCCS9/CY8N uycdpxkCntZlhIMoe+QRsA/3ZORr+CcoHS8dy6sKdAXiOuKAEpiapwhU1/b1tonA9a+L CFWo7fp9CGZIwWvfq9zaCEZURQFPYKN+MXqlJ3tOEBkuArSuSduIsalRSBNEO5n/Fzmu SWCr/3eVqzvWIrgvCfHiXpEynKbeQK8/86PO4JB44070SaofdMGqnOhNZsDnCVHWrunF TQf7G+1DDC/2mb3hMZVGdRHtLKOIQNLMRvlbGPhmFLSxKfGuDrPmkn3rL5VhsJDwYtpW ZHig== X-Forwarded-Encrypted: i=1; AJvYcCVAjZxUPy7RXu0MVia79uw1psfpfET6suSAo2HEQHwQagpIa7ZiHKZDW5vmoGe1rrj9iOPMjX8+5sZZ7sA=@vger.kernel.org X-Gm-Message-State: AOJu0YzRkyTQ85yx1CwzDqrxhlWVPU+S8MbwV/3kHk6yGkMRdYjEG89o ajwly+JOj+TPp+L4tfMO5f6HJSV5Wq1/CiyYaHSG6PStKx8Z0mzbiSgAUqqS9V5lYYQZ9D8firD 6OxCmsSsAIlxg3kSpkorHWq6xAg== X-Received: from pgct17.prod.google.com ([2002:a05:6a02:5291:b0:c63:5610:9a42]) (user=ackerleytng job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f64d:b0:295:888e:9fff with SMTP id d9443c01a7336-2a8d7ed95f4mr145055055ad.20.1770071448632; Mon, 02 Feb 2026 14:30:48 -0800 (PST) Date: Mon, 2 Feb 2026 14:29:54 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.53.0.rc1.225.gd81095ad13-goog Message-ID: Subject: [RFC PATCH v2 16/37] KVM: selftests: Add selftests global for guest memory attributes capability From: Ackerley Tng To: kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-trace-kernel@vger.kernel.org, x86@kernel.org Cc: aik@amd.com, andrew.jones@linux.dev, binbin.wu@linux.intel.com, bp@alien8.de, brauner@kernel.org, chao.p.peng@intel.com, chao.p.peng@linux.intel.com, chenhuacai@kernel.org, corbet@lwn.net, dave.hansen@linux.intel.com, david@kernel.org, hpa@zytor.com, ira.weiny@intel.com, jgg@nvidia.com, jmattson@google.com, jroedel@suse.de, jthoughton@google.com, maobibo@loongson.cn, mathieu.desnoyers@efficios.com, maz@kernel.org, mhiramat@kernel.org, michael.roth@amd.com, mingo@redhat.com, mlevitsk@redhat.com, oupton@kernel.org, pankaj.gupta@amd.com, pbonzini@redhat.com, prsampat@amd.com, qperret@google.com, ricarkol@google.com, rick.p.edgecombe@intel.com, rientjes@google.com, rostedt@goodmis.org, seanjc@google.com, shivankg@amd.com, shuah@kernel.org, steven.price@arm.com, tabba@google.com, tglx@linutronix.de, vannapurve@google.com, vbabka@suse.cz, willy@infradead.org, wyihan@google.com, yan.y.zhao@intel.com, Ackerley Tng Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Sean Christopherson Add a global variable, kvm_has_gmem_attributes, to make the result of checking for KVM_CAP_GUEST_MEMFD_MEMORY_ATTRIBUTES available to all tests. kvm_has_gmem_attributes is true if guest_memfd tracks memory attributes, as opposed to VM-level tracking. This global variable is synced to the guest for testing convenience, to avoid introducing subtle bugs when host/guest state is desynced. Signed-off-by: Sean Christopherson Signed-off-by: Ackerley Tng --- tools/testing/selftests/kvm/include/test_util.h | 2 ++ tools/testing/selftests/kvm/lib/kvm_util.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testin= g/selftests/kvm/include/test_util.h index b4872ba8ed12..2871a4292847 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -113,6 +113,8 @@ struct guest_random_state { extern uint32_t guest_random_seed; extern struct guest_random_state guest_rng; =20 +extern bool kvm_has_gmem_attributes; + struct guest_random_state new_guest_random_state(uint32_t seed); uint32_t guest_random_u32(struct guest_random_state *state); =20 diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/sel= ftests/kvm/lib/kvm_util.c index ce2b0273b26c..4f464ad8dffd 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -24,6 +24,8 @@ uint32_t guest_random_seed; struct guest_random_state guest_rng; static uint32_t last_guest_seed; =20 +bool kvm_has_gmem_attributes; + static size_t vcpu_mmap_sz(void); =20 int __open_path_or_exit(const char *path, int flags, const char *enoent_he= lp) @@ -488,6 +490,7 @@ struct kvm_vm *__vm_create(struct vm_shape shape, uint3= 2_t nr_runnable_vcpus, } guest_rng =3D new_guest_random_state(guest_random_seed); sync_global_to_guest(vm, guest_rng); + sync_global_to_guest(vm, kvm_has_gmem_attributes); =20 kvm_arch_vm_post_create(vm, nr_runnable_vcpus); =20 @@ -2332,6 +2335,8 @@ void __attribute((constructor)) kvm_selftest_init(voi= d) guest_random_seed =3D last_guest_seed =3D random(); pr_info("Random seed: 0x%x\n", guest_random_seed); =20 + kvm_has_gmem_attributes =3D kvm_has_cap(KVM_CAP_GUEST_MEMFD_MEMORY_ATTRIB= UTES); + kvm_selftest_arch_init(); } =20 --=20 2.53.0.rc1.225.gd81095ad13-goog