From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 109772F3600; Sat, 23 May 2026 00:18:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779495486; cv=none; b=RwvjLjrxhQjPpIydPS6fc+lPJWpI2qDcQ3Dh7Fvi5PIIguKyu7Zv0lLRdv/qa8K0DW8rUeHM/fGwypimzGoiSKWp5AcdtZaGAWzPqBG8y47/apA77RuBVO4/TOrFyrkCbteeADgr83keo0c/VaXeGkCNZjkLSr4Nhji7EZnWOFU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779495486; c=relaxed/simple; bh=ANakWQaknMXXsAq6xM/DVcFwZND6TYcVasm1Hl8cgcQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iPVp26HyKc1U3kEskzSMcDwXJidjk55ZZhJERNeTvB2zSl85U8wx6Vea9Srok6kzcTurgOPg+GebqlSqG8B5gwZW/4c75E0PcvtDAMzK6SND/uR3gfQ7imUNh6cTLDPnFgAyKDbCefYWagEgQkPcFMp5RUYZ0+cqwh1eCnLa8kg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rM8hJfP+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rM8hJfP+" Received: by smtp.kernel.org (Postfix) with ESMTPS id 6B977C4E693; Sat, 23 May 2026 00:18:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779495485; bh=ANakWQaknMXXsAq6xM/DVcFwZND6TYcVasm1Hl8cgcQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=rM8hJfP+or/uDUXfrI4P7cBLZ5CWNFhqYHTstjSgwAzegqWr4Wl3H2S+UEIsGS9Dp NPBpS6ZzHy6BoS46OoazIJ6eq/Tzz0Uvf8RIloKeteFpYICqs9t1U4wOxmlXLaczZp dUaGnJJZ1SnTW8l7F/IvQZvOUf5/k8tP02wXu8Mb/u/OJLsdQMeNpwuT1/ZLg17Hqn g0VLzaubS+jHibaSplpSAZu2G3vWUmknLmdRV4s9HzvE4VKqtSikqQzq1g5GwFl9/T JF3QLFSGahtz8dr/V2Z4vDTzIxbCIl8HjesKWeesS88mLpW/LqGyLiaIMrcrjIVJnl rpOQtPE8cs+lg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5668FCD5BB0; Sat, 23 May 2026 00:18:05 +0000 (UTC) From: Ackerley Tng via B4 Relay Date: Fri, 22 May 2026 17:18:07 -0700 Subject: [PATCH v7 25/42] KVM: selftests: Add selftests global for guest memory attributes capability Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260522-gmem-inplace-conversion-v7-25-2f0fae496530@google.com> References: <20260522-gmem-inplace-conversion-v7-0-2f0fae496530@google.com> In-Reply-To: <20260522-gmem-inplace-conversion-v7-0-2f0fae496530@google.com> To: aik@amd.com, andrew.jones@linux.dev, binbin.wu@linux.intel.com, brauner@kernel.org, chao.p.peng@linux.intel.com, david@kernel.org, ira.weiny@intel.com, jmattson@google.com, jthoughton@google.com, michael.roth@amd.com, oupton@kernel.org, pankaj.gupta@amd.com, qperret@google.com, rick.p.edgecombe@intel.com, rientjes@google.com, shivankg@amd.com, steven.price@arm.com, tabba@google.com, willy@infradead.org, wyihan@google.com, yan.y.zhao@intel.com, forkloop@google.com, pratyush@kernel.org, suzuki.poulose@arm.com, aneesh.kumar@kernel.org, liam@infradead.org, Paolo Bonzini , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Shuah Khan , Shuah Khan , Vishal Annapurve , Andrew Morton , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Youngjun Park , Qi Zheng , Shakeel Butt , Kiryl Shutsemau , Jason Gunthorpe , Vlastimil Babka Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, Ackerley Tng X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779495480; l=2393; i=ackerleytng@google.com; s=20260225; h=from:subject:message-id; bh=enbUgkpN5h/kbke93UGvFu3sgIUAtIDKKDJ2JxjAPS4=; b=cq43NauVbSuTkfNQxrY6AxxrRbsYkVnxUiU7zsR/kcjwwvKFnwaFPQdYFFkTWltwYeNv+hxww exhTnvT5zWtC9GsLEnK6/trmWqLRuO5b+scP3403jP2D8BlK9lODSIM X-Developer-Key: i=ackerleytng@google.com; a=ed25519; pk=sAZDYXdm6Iz8FHitpHeFlCMXwabodTm7p8/3/8xUxuU= X-Endpoint-Received: by B4 Relay for ackerleytng@google.com/20260225 with auth_id=649 X-Original-From: Ackerley Tng Reply-To: ackerleytng@google.com 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/testing/selftests/kvm/include/test_util.h index d9b433b834f1b..c280c3233f502 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -115,6 +115,8 @@ struct guest_random_state { extern u32 guest_random_seed; extern struct guest_random_state guest_rng; +extern bool kvm_has_gmem_attributes; + struct guest_random_state new_guest_random_state(u32 seed); u32 guest_random_u32(struct guest_random_state *state); diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 4eaf553fbab11..daa0c1e835a71 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -24,6 +24,8 @@ u32 guest_random_seed; struct guest_random_state guest_rng; static u32 last_guest_seed; +bool kvm_has_gmem_attributes; + static size_t vcpu_mmap_sz(void); int __open_path_or_exit(const char *path, int flags, const char *enoent_help) @@ -521,6 +523,7 @@ struct kvm_vm *__vm_create(struct vm_shape shape, u32 nr_runnable_vcpus, } guest_rng = new_guest_random_state(guest_random_seed); sync_global_to_guest(vm, guest_rng); + sync_global_to_guest(vm, kvm_has_gmem_attributes); kvm_arch_vm_post_create(vm, nr_runnable_vcpus); @@ -2287,6 +2290,8 @@ void __attribute((constructor)) kvm_selftest_init(void) guest_random_seed = last_guest_seed = random(); pr_info("Random seed: 0x%x\n", guest_random_seed); + kvm_has_gmem_attributes = kvm_has_cap(KVM_CAP_GUEST_MEMFD_MEMORY_ATTRIBUTES); + kvm_selftest_arch_init(); } -- 2.54.0.794.g4f17f83d09-goog