From nobody Mon Feb 9 12:45:36 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) (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 D66B6126F3B; Mon, 9 Feb 2026 04:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770611420; cv=none; b=LEcCIbaW/QFkYbjtc/ThWRYaY3XqTVwlRt9lt8cwn/lq5ORVOd4l2/8CmdKikC/NIcBqlVbUyY7LJhym7Dxoj/HHUcYBme2QtLgkqMd0kkp+878LwpBxMvfys32tM0Rr2SYpWi3v9/07PqAVtZ3nDw44UmsecLQz2TkxIr0WNtQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770611420; c=relaxed/simple; bh=C52bEq3TH6+WHwZGbu1J0ND/tgmNrbDcmiG6ddcdr3g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Eh9RAK31nwBJW9S+2sskNMAnA3uciQP942DT5K6YM1Rf+vDmxVKcWgMJMyzhVviHZbKPrwn7x63+BqtUQpWAxwT7lOPxObn6q/VoHB22ZHMRPFmzvsuincSJ5vyO6q9bytrXVvvtU60byjFnBS+IqCyD8U37KTyu96SY5FAf2ro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=QBzsauYQ; arc=none smtp.client-ip=220.197.31.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="QBzsauYQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=7Z X6gO4s1/g6DTK9BvrcJ2ewwGz0oC37XJnSwSguWaE=; b=QBzsauYQJaiYyPbJMB NxlyZSZRmrthq4RX9KNMLoKMJAiUF8RcuCNdZf6VQgIscDiJxdsWJCbAqv2Ovhts LHMgL+2lLmOzGm+b2F+7syFNuj2ZuLwWMgQAvq5wxS+e2Lq7eQGPIYoHS9LvsSa/ dl+iPLSU31THRfS9ZlFPZmXP4= Received: from 163.com (unknown []) by gzsmtp2 (Coremail) with SMTP id PSgvCgD3F+yvYolpOQZEQw--.25673S3; Mon, 09 Feb 2026 12:29:36 +0800 (CST) From: Zhiquan Li To: seanjc@google.com, pbonzini@redhat.com, shuah@kernel.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, zhiquan_li@163.com Subject: [PATCH RESEND 1/5] KVM: x86: selftests: Add CPU vendor detection for Hygon Date: Mon, 9 Feb 2026 12:13:01 +0800 Message-ID: <20260209041305.64906-2-zhiquan_li@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260209041305.64906-1-zhiquan_li@163.com> References: <20260209041305.64906-1-zhiquan_li@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: PSgvCgD3F+yvYolpOQZEQw--.25673S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxWFW5Zw48Zr1xJF4kWr1fCrg_yoW5Jw45pF ykAr1rKF10gFnxta4xXr4ktryxWrZ7Wa10q3yUZry3Aa12yry7Xrs7Ka4jvrZI9FWrW3s8 Zas7tF4YgFsrZaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pi89N5UUUUU= X-CM-SenderInfo: 52kl13xdqbzxi6rwjhhfrp/xtbC6hCBammJYrA9QgAA3c Content-Type: text/plain; charset="utf-8" Currently some KVM selftests are failed on Hygon CPUs due to missing vendor detection and edge-case handling specific to Hygon's architecture. Add CPU vendor detection for Hygon and add a global variable "host_cpu_is_hygon" as the basic facility for the following fixes. Signed-off-by: Zhiquan Li --- tools/testing/selftests/kvm/include/x86/processor.h | 6 ++++++ tools/testing/selftests/kvm/lib/x86/processor.c | 3 +++ 2 files changed, 9 insertions(+) diff --git a/tools/testing/selftests/kvm/include/x86/processor.h b/tools/te= sting/selftests/kvm/include/x86/processor.h index 57d62a425109..9ac18e0fca54 100644 --- a/tools/testing/selftests/kvm/include/x86/processor.h +++ b/tools/testing/selftests/kvm/include/x86/processor.h @@ -21,6 +21,7 @@ =20 extern bool host_cpu_is_intel; extern bool host_cpu_is_amd; +extern bool host_cpu_is_hygon; extern uint64_t guest_tsc_khz; =20 #ifndef MAX_NR_CPUID_ENTRIES @@ -701,6 +702,11 @@ static inline bool this_cpu_is_amd(void) return this_cpu_vendor_string_is("AuthenticAMD"); } =20 +static inline bool this_cpu_is_hygon(void) +{ + return this_cpu_vendor_string_is("HygonGenuine"); +} + static inline uint32_t __this_cpu_has(uint32_t function, uint32_t index, uint8_t reg, uint8_t lo, uint8_t hi) { diff --git a/tools/testing/selftests/kvm/lib/x86/processor.c b/tools/testin= g/selftests/kvm/lib/x86/processor.c index 36104d27f3d9..bbd3336f22eb 100644 --- a/tools/testing/selftests/kvm/lib/x86/processor.c +++ b/tools/testing/selftests/kvm/lib/x86/processor.c @@ -21,6 +21,7 @@ vm_vaddr_t exception_handlers; bool host_cpu_is_amd; bool host_cpu_is_intel; +bool host_cpu_is_hygon; bool is_forced_emulation_enabled; uint64_t guest_tsc_khz; =20 @@ -671,6 +672,7 @@ void kvm_arch_vm_post_create(struct kvm_vm *vm, unsigne= d int nr_vcpus) =20 sync_global_to_guest(vm, host_cpu_is_intel); sync_global_to_guest(vm, host_cpu_is_amd); + sync_global_to_guest(vm, host_cpu_is_hygon); sync_global_to_guest(vm, is_forced_emulation_enabled); sync_global_to_guest(vm, pmu_errata_mask); =20 @@ -1303,6 +1305,7 @@ void kvm_selftest_arch_init(void) { host_cpu_is_intel =3D this_cpu_is_intel(); host_cpu_is_amd =3D this_cpu_is_amd(); + host_cpu_is_hygon =3D this_cpu_is_hygon(); is_forced_emulation_enabled =3D kvm_is_forced_emulation_enabled(); =20 kvm_init_pmu_errata(); --=20 2.43.0 From nobody Mon Feb 9 12:45:36 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.5]) (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 EF25026B95B; Mon, 9 Feb 2026 04:30:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770611407; cv=none; b=kaKAeH1Ya0NcIvYlpZFTg1YjILiBJ3VGrZ5xerrIDaxsXXGdCrb737cy9kE7f78Lk6wwNHsAmwMp92eynZqD+Azgg9CpsAHosn5S0RAWbDqSi9Oiyr319AWR4F/3TKSxzsUTGh0y3jjJs6vg0qJMAUgjt96VLTaWGmW8UXkPKMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770611407; c=relaxed/simple; bh=c7YoCkM2BmZJdHk5jLwsWyiMECmd1q2WP5rs2cebOqo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SrDm1xusKIut7ENUl/j22hG7iy7iKFh8v7oeLa6NADXfUWyB7YmNEsxokKZyYW5LymbTU3h5TlwwuWmKPJTQjdHc8BjFMvfobkwT/jLHuzIKiqvSg1PMJhJCLvTPX+SRide7hpswMlKcBIaoOEOCG49hJvlPzuVZoYgYBDJAMX0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=HtxkG33z; arc=none smtp.client-ip=117.135.210.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="HtxkG33z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=wR rHYlhhICurRuaTmyvIiO5aCoWfhZPWn5WuToLYHEE=; b=HtxkG33ztbKbHKsY74 rID1tGVXD3YA2NI41GVML+QKE9N9bwH4L4gDRSr4AaBkwvIVZkw9Pkf66FdNLRdj dqeURzAmAn42JmMjKY+CzB7Mls8Crtfb9gl/HmsqVMAwqwHwhrDYmxqif3l8cg09 nTKzk6Wocrpjf54Um0Lw/oSsw= Received: from 163.com (unknown []) by gzsmtp2 (Coremail) with SMTP id PSgvCgD3F+yvYolpOQZEQw--.25673S4; Mon, 09 Feb 2026 12:29:36 +0800 (CST) From: Zhiquan Li To: seanjc@google.com, pbonzini@redhat.com, shuah@kernel.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, zhiquan_li@163.com Subject: [PATCH RESEND 2/5] KVM: x86: selftests: Alter the instruction of hypercall on Hygon Date: Mon, 9 Feb 2026 12:13:02 +0800 Message-ID: <20260209041305.64906-3-zhiquan_li@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260209041305.64906-1-zhiquan_li@163.com> References: <20260209041305.64906-1-zhiquan_li@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: PSgvCgD3F+yvYolpOQZEQw--.25673S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7ury8XrWkKw4rGF1UZryDAwb_yoW8AF4kp3 WkJw1FkF1IqF1aya4xGr4kXry8GrZrWay8tw4IyFZxAF17Jw1xXF47KF12kasxuFZ5Zwnx Z3Z2vF1Uur1UJwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRHGQDUUUUU= X-CM-SenderInfo: 52kl13xdqbzxi6rwjhhfrp/xtbCwhCBammJYrCJQgAA3A Content-Type: text/plain; charset="utf-8" Hygon architecture uses VMMCALL as guest hypercall instruction. Now, the test like "fix hypercall" uses VMCALL and then results in test failure. Utilize the Hygon-specific flag to identify if the test is running on Hygon CPU and alter the instruction of hypercall if needed. Signed-off-by: Zhiquan Li --- tools/testing/selftests/kvm/lib/x86/processor.c | 3 ++- tools/testing/selftests/kvm/x86/fix_hypercall_test.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/x86/processor.c b/tools/testin= g/selftests/kvm/lib/x86/processor.c index bbd3336f22eb..64f9ecd2387d 100644 --- a/tools/testing/selftests/kvm/lib/x86/processor.c +++ b/tools/testing/selftests/kvm/lib/x86/processor.c @@ -1229,7 +1229,8 @@ const struct kvm_cpuid_entry2 *get_cpuid_entry(const = struct kvm_cpuid2 *cpuid, "1: vmmcall\n\t" \ "2:" \ : "=3Da"(r) \ - : [use_vmmcall] "r" (host_cpu_is_amd), inputs); \ + : [use_vmmcall] "r" \ + (host_cpu_is_amd || host_cpu_is_hygon), inputs); \ \ r; \ }) diff --git a/tools/testing/selftests/kvm/x86/fix_hypercall_test.c b/tools/t= esting/selftests/kvm/x86/fix_hypercall_test.c index 762628f7d4ba..0377ab5b1238 100644 --- a/tools/testing/selftests/kvm/x86/fix_hypercall_test.c +++ b/tools/testing/selftests/kvm/x86/fix_hypercall_test.c @@ -52,7 +52,7 @@ static void guest_main(void) if (host_cpu_is_intel) { native_hypercall_insn =3D vmx_vmcall; other_hypercall_insn =3D svm_vmmcall; - } else if (host_cpu_is_amd) { + } else if (host_cpu_is_amd || host_cpu_is_hygon) { native_hypercall_insn =3D svm_vmmcall; other_hypercall_insn =3D vmx_vmcall; } else { --=20 2.43.0 From nobody Mon Feb 9 12:45:36 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2]) (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 135FA126F3B; Mon, 9 Feb 2026 04:30:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770611413; cv=none; b=APoM0idQQ+mnRgT47Y8H4HPJUYKMD6woPEBdlizlEDsG2K+PvVw7nVvRJEu4nd89KkQo/ViXsGp6w5bkbDfoYtPbdBeAb6uRRHMNhrMBP9fVah9wIGd4/zOwH76EWLYgC52kSxWlJ3DpaBg/4V9oVHJVXIcDsQizpOGBr9GCdOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770611413; c=relaxed/simple; bh=VPNs08T7JRAAD+FtB2viQACpxJDWKcCN819zahfODp4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fbdGKWbSYpGQ+oAErPGAM1MYSWbYU36gGhN2Vzy9PMvs18HUxKeJGgDL6tIqDkMpkcvu6oQe17YR55qx6a+Yy1y0aPd47jtzJwsmNl+3M8neJmbPB/NXMNEGsL/pybDC2kYU9QObxqlMicj9pqnVB+D2pobworf8slA6GT+2MBQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=A+bQ1oOp; arc=none smtp.client-ip=220.197.31.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="A+bQ1oOp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=i1 +c8F8gRCphXAzoD8IgyPUlkrVbg7Bop7xNGBSKdQ8=; b=A+bQ1oOp3GMLB+JkWh VSB3YXtEI9jeBuK5ntF9lMoMZPm7YXNMgvvUyokxuatOUGdzk9bBcscS1bNNlgyX F3MayAnJo5JQ9VadmLie9K0gJBQKSOFPPw2j80y8vl5x5nRLiKHI1sibu7i6lRk1 pFUkuMh2MvrV4qebgDCGiLULo= Received: from 163.com (unknown []) by gzsmtp2 (Coremail) with SMTP id PSgvCgD3F+yvYolpOQZEQw--.25673S5; Mon, 09 Feb 2026 12:29:37 +0800 (CST) From: Zhiquan Li To: seanjc@google.com, pbonzini@redhat.com, shuah@kernel.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, zhiquan_li@163.com Subject: [PATCH RESEND 3/5] KVM: x86: selftests: Avoid failures due to reserved memory address regions on Hygon Date: Mon, 9 Feb 2026 12:13:03 +0800 Message-ID: <20260209041305.64906-4-zhiquan_li@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260209041305.64906-1-zhiquan_li@163.com> References: <20260209041305.64906-1-zhiquan_li@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: PSgvCgD3F+yvYolpOQZEQw--.25673S5 X-Coremail-Antispam: 1Uf129KBjvJXoW7CFykCr1Uuw4UJF1DKr4kJFb_yoW8ZF1Dpa 4fCw45WF48GF1ay3yxXws7ZFyvkFn7CF4xKryjy343u3W5WF13Zr4Sk3WYvrW3CrWrZw13 Aa4fJF4Duw4jqaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UzxRDUUUUU= X-CM-SenderInfo: 52kl13xdqbzxi6rwjhhfrp/xtbC6hGBammJYrE9UgAA3M Content-Type: text/plain; charset="utf-8" There are similar reserved memory address regions for Hygon architecture, mapping memory into these regions and accessing to them results in a #PF. Hygon CSV also makes the "physical address space width reduction", the reduced physical address bits are reported by bits 11:6 of CPUID[0x8000001f].EBX as well, so the existed logic is totally applicable for Hygon processors. Following test failures are fixed by this change: - access_tracking_perf_test - demand_paging_test - dirty_log_perf_test - dirty_log_test - kvm_page_table_test - memslot_modification_stress_test - pre_fault_memory_test - x86/dirty_log_page_splitting_test Signed-off-by: Zhiquan Li --- tools/testing/selftests/kvm/lib/x86/processor.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/x86/processor.c b/tools/testin= g/selftests/kvm/lib/x86/processor.c index 64f9ecd2387d..252b04c8e944 100644 --- a/tools/testing/selftests/kvm/lib/x86/processor.c +++ b/tools/testing/selftests/kvm/lib/x86/processor.c @@ -1270,8 +1270,8 @@ unsigned long vm_compute_max_gfn(struct kvm_vm *vm) =20 max_gfn =3D (1ULL << (guest_maxphyaddr - vm->page_shift)) - 1; =20 - /* Avoid reserved HyperTransport region on AMD processors. */ - if (!host_cpu_is_amd) + /* Avoid reserved HyperTransport region on AMD or Hygon processors. */ + if (!host_cpu_is_amd && !host_cpu_is_hygon) return max_gfn; =20 /* On parts with <40 physical address bits, the area is fully hidden */ @@ -1285,7 +1285,7 @@ unsigned long vm_compute_max_gfn(struct kvm_vm *vm) =20 /* * Otherwise it's at the top of the physical address space, possibly - * reduced due to SME by bits 11:6 of CPUID[0x8000001f].EBX. Use + * reduced due to SME or CSV by bits 11:6 of CPUID[0x8000001f].EBX. Use * the old conservative value if MAXPHYADDR is not enumerated. */ if (!this_cpu_has_p(X86_PROPERTY_MAX_PHY_ADDR)) --=20 2.43.0 From nobody Mon Feb 9 12:45:36 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) (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 0921F27C84E; Mon, 9 Feb 2026 04:30:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770611407; cv=none; b=tefrwUNO2ghcjJPS85CSUXEyp/qNdFLt5deAXDUpMUap/aAWV5UL6ELQD/7wjXdlxM1v0BVsJENB5CZTbJPnsc1qN3n0a6ovdUac/uAy9UNFN6O7IQ9fihPgB97S+xcwBqwp+KzNZgVCoJaxCahzUtdGzo3N0klmJ/VsIi8Ev6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770611407; c=relaxed/simple; bh=o9qiTqabUcEszYYfsg4Is62Jj/x8xBjHa7n1BMSgtzQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KOsfpeN79QKzW3NUwNSPaLlgF+YwzFQXP/T+qa3hVpzL0eyjtWDG8eiDdgNFHbS5BAqWrkV6CM7VWh8mPmwwLnV+P3FhuzyVDqpMOqbJPLQAx41nQNuFgabQHHzhS2wplIKrDBZSwrjwn6A1uQUWHeyKAcOzTaJypZi7c2t0T5E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=Yc8vvzWm; arc=none smtp.client-ip=220.197.31.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="Yc8vvzWm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=xb 0PMGnfuKaBxrfKeA17F7puvY7wMgDlhlpI5Sayuno=; b=Yc8vvzWmAqYNw2Q4Z+ cCZZ/WNZ0G6Vevn8K1bqgGCc9UvnJtJPeFJEs+T7UOGXBKeQAaB8vbELns3/5GMj UY9434fYElh8VkWAnaYMFrREpcO6qICmn1zENp2U0NHlkbxt9Z+nGSiDVrJmvh0t +FM6jDDNI+hqYGdRjO5LkT0ck= Received: from 163.com (unknown []) by gzsmtp2 (Coremail) with SMTP id PSgvCgD3F+yvYolpOQZEQw--.25673S6; Mon, 09 Feb 2026 12:29:37 +0800 (CST) From: Zhiquan Li To: seanjc@google.com, pbonzini@redhat.com, shuah@kernel.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, zhiquan_li@163.com Subject: [PATCH RESEND 4/5] KVM: x86: selftests: Allow the PMU event filter test for Hygon Date: Mon, 9 Feb 2026 12:13:04 +0800 Message-ID: <20260209041305.64906-5-zhiquan_li@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260209041305.64906-1-zhiquan_li@163.com> References: <20260209041305.64906-1-zhiquan_li@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: PSgvCgD3F+yvYolpOQZEQw--.25673S6 X-Coremail-Antispam: 1Uf129KBjvJXoWxJr4xtF4kWFyfKw4DJry3XFb_yoW8CF45pF yruw1avF48KFnxA3W8G34kWr4fAw1kWF4kt3sIgry8Zr1UJw1Iqr42ka43ta1YkFWFqw1Y ya47tFy5ua4UKaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziDPEDUUUUU= X-CM-SenderInfo: 52kl13xdqbzxi6rwjhhfrp/xtbC6hGBammJYrE9WgAA3E Content-Type: text/plain; charset="utf-8" At present, the PMU event filter test is only available for Intel and AMD architecture conditionally, but it is applicable for Hygon architecture as well. Since all known Hygon processors can re-use the test cases, so it isn't necessary to create a wrapper like other architectures, using the "host_cpu_is_hygon" variable should be enough. Signed-off-by: Zhiquan Li --- tools/testing/selftests/kvm/x86/pmu_event_filter_test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c b/tool= s/testing/selftests/kvm/x86/pmu_event_filter_test.c index 1c5b7611db24..e6badd9a2a2a 100644 --- a/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c +++ b/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c @@ -842,14 +842,14 @@ int main(int argc, char *argv[]) TEST_REQUIRE(kvm_has_cap(KVM_CAP_PMU_EVENT_FILTER)); TEST_REQUIRE(kvm_has_cap(KVM_CAP_PMU_EVENT_MASKED_EVENTS)); =20 - TEST_REQUIRE(use_intel_pmu() || use_amd_pmu()); + TEST_REQUIRE(use_intel_pmu() || use_amd_pmu() || host_cpu_is_hygon); guest_code =3D use_intel_pmu() ? intel_guest_code : amd_guest_code; =20 vm =3D vm_create_with_one_vcpu(&vcpu, guest_code); =20 TEST_REQUIRE(sanity_check_pmu(vcpu)); =20 - if (use_amd_pmu()) + if (use_amd_pmu() || host_cpu_is_hygon) test_amd_deny_list(vcpu); =20 test_without_filter(vcpu); @@ -862,7 +862,7 @@ int main(int argc, char *argv[]) supports_event_mem_inst_retired() && kvm_cpu_property(X86_PROPERTY_PMU_NR_GP_COUNTERS) >=3D 3) vcpu2 =3D vm_vcpu_add(vm, 2, intel_masked_events_guest_code); - else if (use_amd_pmu()) + else if (use_amd_pmu() || host_cpu_is_hygon) vcpu2 =3D vm_vcpu_add(vm, 2, amd_masked_events_guest_code); =20 if (vcpu2) --=20 2.43.0 From nobody Mon Feb 9 12:45:36 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.5]) (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 4B99A219EB; Mon, 9 Feb 2026 04:30:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770611437; cv=none; b=fQoF0B58WIV1v88CC79IcwthTiRmQUWVJDt1y1Nvd7JBpkLZi0uzLdYg3Z64Bq20oW7HzEKbV22TfSLa8E3YwfZPhDrCLNXUL88I7+OWhHW8v95rYL7o/K+BpMEhJhDrK58mml8mC6ckj44SRvu4movtc9Ed7iJG7yrU9zTEBaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770611437; c=relaxed/simple; bh=mg6Np9dLlQ9jkpUBZKs9K2GVpmriauqZmwB9RUasGXw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TNAUt0RwyL7kUsK7T2dpHDqUynRwoQNluFnWuhf7AI3QoDdgvUSoVldissgSMqDhJUOtMWieDNFVN/zaX4GnXL2DnM+eePfOovseGPtjb4Ylleyf9/FQ5stfsWof+O8DfOt/r2AySea9hG6kX2tFaml8q331EUUSdSdMKezXIj4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=beWiTdqm; arc=none smtp.client-ip=117.135.210.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="beWiTdqm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=p0 WWBaXeK1hJhUNXLmueWvDpkraa8hWuQq+v3jxbXV0=; b=beWiTdqmpGNBHpUDIE hfiA5ZOwTcRLTlSoO1aOBmol0IIEBAQQOS28bt8iE3ihSZpFSHQBR3en5Y7sPRjK xxwl3mG54LnoXMRa4XrlEp3L77KS87T3CYvu8xlHL4t7o1lLzSvVMPz/Q9nijkT+ fFLbjZ+eUQZ0yBs4lJsCQswI4= Received: from 163.com (unknown []) by gzsmtp2 (Coremail) with SMTP id PSgvCgD3F+yvYolpOQZEQw--.25673S7; Mon, 09 Feb 2026 12:29:37 +0800 (CST) From: Zhiquan Li To: seanjc@google.com, pbonzini@redhat.com, shuah@kernel.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, zhiquan_li@163.com Subject: [PATCH RESEND 5/5] KVM: x86: selftests: Fix write MSR_TSC_AUX reserved bits test failure on Hygon Date: Mon, 9 Feb 2026 12:13:05 +0800 Message-ID: <20260209041305.64906-6-zhiquan_li@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260209041305.64906-1-zhiquan_li@163.com> References: <20260209041305.64906-1-zhiquan_li@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: PSgvCgD3F+yvYolpOQZEQw--.25673S7 X-Coremail-Antispam: 1Uf129KBjvJXoWxWw1xXFyrtrW3CF4rWryrCrg_yoW5ZrWfpa n2gw4YgrZrKa42qa9rXF1kGF4rArn7Gry0grnaq3y7Zwn5Ary2qr4xKayfXa4xZrWSvr98 ZF47tr42kw4DAaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziD5rsUUUUU= X-CM-SenderInfo: 52kl13xdqbzxi6rwjhhfrp/xtbCwhGBammJYrGJVQAA3X Content-Type: text/plain; charset="utf-8" On Hygon processors either RDTSCP or RDPID is supported in the host, MSR_TSC_AUX is able to be accessed. The write reserved bits test for MSR_TSC_AUX while RDPID as "feature" and RDTSCP as "feature2" is failed on Hygon CPUs which only support RDTSCP but not support RDPID. In current design, if RDPID is not supported, vCPU0 and vCPU1 write reserved bits expects #GP, however, it is not applicable for Hygon CPUs. Since on Hygon architecture whether or not RDPID is supported in the host, once RDTSCP is supported, MSR_TSC_AUX is able to be accessed, vCPU0 and vCPU1 drop bits 63:32 and write successfully. Therefore, the expectation of writing MSR_TSC_AUX reserved bits on Hygon CPUs should be: 1) either RDTSCP or RDPID is supported case, and both are supported case, expect success and a truncated value, not #GP. 2) neither RDTSCP nor RDPID is supported, expect #GP. Signed-off-by: Zhiquan Li --- tools/testing/selftests/kvm/x86/msrs_test.c | 26 +++++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/x86/msrs_test.c b/tools/testing/se= lftests/kvm/x86/msrs_test.c index 40d918aedce6..2f1e800fe691 100644 --- a/tools/testing/selftests/kvm/x86/msrs_test.c +++ b/tools/testing/selftests/kvm/x86/msrs_test.c @@ -77,11 +77,11 @@ static bool ignore_unsupported_msrs; static u64 fixup_rdmsr_val(u32 msr, u64 want) { /* - * AMD CPUs drop bits 63:32 on some MSRs that Intel CPUs support. KVM - * is supposed to emulate that behavior based on guest vendor model + * AMD and Hygon CPUs drop bits 63:32 on some MSRs that Intel CPUs suppor= t. + * KVM is supposed to emulate that behavior based on guest vendor model * (which is the same as the host vendor model for this test). */ - if (!host_cpu_is_amd) + if (!host_cpu_is_amd && !host_cpu_is_hygon) return want; =20 switch (msr) { @@ -94,6 +94,17 @@ static u64 fixup_rdmsr_val(u32 msr, u64 want) } } =20 +/* + * On Hygon processors either RDTSCP or RDPID is supported in the host, + * MSR_TSC_AUX is able to be accessed. + */ +static bool is_hygon_msr_tsc_aux_supported(const struct kvm_msr *msr) +{ + return host_cpu_is_hygon && + msr->index =3D=3D MSR_TSC_AUX && + (this_cpu_has(msr->feature) || this_cpu_has(msr->feature2)); +} + static void __rdmsr(u32 msr, u64 want) { u64 val; @@ -174,9 +185,14 @@ void guest_test_reserved_val(const struct kvm_msr *msr) /* * If the CPU will truncate the written value (e.g. SYSENTER on AMD), * expect success and a truncated value, not #GP. + * + * On Hygon CPUs whether or not RDPID is supported in the host, once RDTS= CP + * is supported, MSR_TSC_AUX is able to be accessed. So, for either RDTS= CP + * or RDPID is supported case and both are supported case, expect + * success and a truncated value, not #GP. */ - if (!this_cpu_has(msr->feature) || - msr->rsvd_val =3D=3D fixup_rdmsr_val(msr->index, msr->rsvd_val)) { + if (!is_hygon_msr_tsc_aux_supported(msr) && (!this_cpu_has(msr->feature) = || + msr->rsvd_val =3D=3D fixup_rdmsr_val(msr->index, msr->rsvd_val))) { u8 vec =3D wrmsr_safe(msr->index, msr->rsvd_val); =20 __GUEST_ASSERT(vec =3D=3D GP_VECTOR, --=20 2.43.0