From nobody Mon Feb 9 10:38:28 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.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 F29252FFDF4; Tue, 20 Jan 2026 09:16:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768900570; cv=none; b=mVbJd2FYQWjI4linLtAMlZpfJUDhLGvW7RXB5kb3k7UgdYkUlMsWEkSYC8BOvu0E79+GGxk7ffGeo50p2SeXqJkh6Wx8cxXOhEUPQLGR9gapCiGtzMJRVQom/T7UhdcMKsbeOoeoDykV/ca7OfCvBftzj8mIY+D5QQQba+CqYMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768900570; c=relaxed/simple; bh=C52bEq3TH6+WHwZGbu1J0ND/tgmNrbDcmiG6ddcdr3g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uikzVvAscaWb7DSStO/jvKayLijvdEKKrYwrCstltlOvjZjbd56a72yC8H+avIbwm66n7o+j814F7rI7k3C8ETL4jHRF9TMqKtjCJVmtWeb9B3TZHndnALT+28Ip+AalyOzxqgVw7ZJRogc9vAP6RGeKdTxIN6UqOCFzyb2uty0= 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=IDkxIKqk; arc=none smtp.client-ip=220.197.31.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="IDkxIKqk" 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=IDkxIKqkehwn+oTOWM cnDSdutlOLh0dhotRPwJTvS25O0xdfodJ31fZvyCOTUUKJqJ8NGSQB5EfKVYmWCu E6frdMIy9TVjf++bteTZzd7srLFKKtD3drIKk+2zsPYHFXpRYuWfsAwa4+afM0e2 +Hm2K9ZkeZECN0yWBEF85iGR4= Received: from 163.com (unknown []) by gzga-smtp-mtada-g0-0 (Coremail) with SMTP id _____wCn5zu4R29pIOfPGw--.26432S3; Tue, 20 Jan 2026 17:15:41 +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 1/5] KVM: x86: selftests: Add CPU vendor detection for Hygon Date: Tue, 20 Jan 2026 17:14:44 +0800 Message-ID: <20260120091449.526798-2-zhiquan_li@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260120091449.526798-1-zhiquan_li@163.com> References: <20260120091449.526798-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: _____wCn5zu4R29pIOfPGw--.26432S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxWFW5Zw48Zr1xJF4kWr1fCrg_yoW5Jw45pF ykAr1rKF10gFnxta4xXr4ktryxWrZ7Wa10q3yUZry3Aa12yry7Xrs7Ka4jvrZI9FWrW3s8 Zas7tF4YgFsrZaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRVVb-UUUUU= X-CM-SenderInfo: 52kl13xdqbzxi6rwjhhfrp/xtbC6h43IGlvR77HQgAA3Z 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 10:38:28 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.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 79F8E3AA182; Tue, 20 Jan 2026 09:16:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768900570; cv=none; b=PELF5NM58h6YI/2n/rb48/uVIhQ79dZ4laVWsNw8/TsI4hyUwicPrAWMaA6hR3zB//T0bNxkLS0ojiP1a5bdx+8n8ly+ZjVGegC4I6twQPlzBEYM0/iOi5le13PU8gWUTK89ExDzR5xyBLuZXvad4Ziql1q4EC4OJP/Qir05y0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768900570; c=relaxed/simple; bh=m9yRsZxqZ72hs3JIeNkMtMnPukmK9ziztVXzSQGfZgQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jOhVWSbDL/unMyjnHzKKjmBlMt39wfkazO3PyOLjys4XGPAWR3NM1ae+j0aVYF9eKQBBNqi0YKwxEWWOOobMFxzovlxKOV4ONdlGQ6SZ1EH4Mqdka+VwdGN1sjE0Et2+tFrEOaOtUKf9f1pZ0J2O/5FISrBqiRlEx631MW/KOFA= 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=TExkpRhP; arc=none smtp.client-ip=117.135.210.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="TExkpRhP" 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=9/ 37MfyB2vsEX90dMNuzNx9fIxgfnpHXIinZTsCQAo0=; b=TExkpRhPOkZ2uc64Sr 4NRRJwM0phSWsPhIu3YHR5E8T3hd2cpqRDL0tsSDa5QQH5DbYiPnmKelnlRzskJX IZIt7tZCz3VtJ2wnM8mDZ7LP1B4bG2tll0RpHBRnaCe85Xd4H7tsCfeNig+Hd3nk osm1Hj29R7vcAbMdfnW5yjluQ= Received: from 163.com (unknown []) by gzga-smtp-mtada-g0-0 (Coremail) with SMTP id _____wCn5zu4R29pIOfPGw--.26432S4; Tue, 20 Jan 2026 17:15:42 +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 2/5] KVM: x86: selftests: Alter the hypercall instruction on Hygon Date: Tue, 20 Jan 2026 17:14:45 +0800 Message-ID: <20260120091449.526798-3-zhiquan_li@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260120091449.526798-1-zhiquan_li@163.com> References: <20260120091449.526798-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: _____wCn5zu4R29pIOfPGw--.26432S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7uryUuFyDuFykCryrZFyDAwb_yoW8Ar13p3 WkJw1FkF1IqF1aya4xWw4kXr18GrZrWay0yws2yFZxAF17Jw1xXF47KF12kasxuFZ5Z3Zx Z3Z2va1Uur1UJwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zilfOOUUUUU= X-CM-SenderInfo: 52kl13xdqbzxi6rwjhhfrp/xtbC6h43IGlvR77HTAAA3X Content-Type: text/plain; charset="utf-8" Hygon architecture uses VMMCALL as guest hypercall instruction, so utilize the Hygon specific flag to avoid the test like "fix hypercall" running into the wrong branches and using VMCALL, then causing failure. 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 10:38:28 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3]) (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 7A39B3B52F7; Tue, 20 Jan 2026 09:16:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768900568; cv=none; b=Kipi7lDVX6UtCf8kV6SIBYt7RNoPRK7AhBMBLZoF0I+tJXDvhTJeF69pyAYAJz1zGqvpXi2BifrN/WXnmA0cYOQd7s/3IgKELhC0yr5Z//fJr/uIeFKE4bbS+2/a1ud02LSnRnc3HwCJZzjdDco9n+4/HW1ix4awcdCeP6PWPzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768900568; c=relaxed/simple; bh=3JMOXPfQ61LnCVtpjwhEPTm3T/iAtHe/zWJvFIpZ4z8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hVHivz5GqemRPGd4NqYkxn4Nhk9A4gLGqmBUQXOfDTET8qBEpQ7d0Q8ysfXNrEZwo/u6TJULxaa61JaSX/cQnn5yy7qf3Nr1KqDhpjjz9xa/WYYhVLofvQN4m3U3mY4MH9D1+cKcPVlzXhTWT8HOcQ0Nl0CiPUCkceDmQe2/3Sk= 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=i1v16RnV; arc=none smtp.client-ip=220.197.31.3 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="i1v16RnV" 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=Jx mNh8O5HvOhLdLZe6X+x7Ug4eY7zYzmJLmKHOIq20c=; b=i1v16RnVypOocKQ1yO EYnp0vSWDs9JyWkO7s4wWfWa9lWsd3hwJuw0aCArymHgsCq0iGMyJ60X90VbKZHd 5bGUwfQTN8YGlFERk9UZn3ci1+Ip10ve/xHih0qLVcRuImsV+PG+r4DsqJiUFV/C rlL5WrEo9nFvoOvQSbBPhREO8= Received: from 163.com (unknown []) by gzga-smtp-mtada-g0-0 (Coremail) with SMTP id _____wCn5zu4R29pIOfPGw--.26432S5; Tue, 20 Jan 2026 17:15:43 +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 3/5] KVM: x86: selftests: Avoid failures due to reserved memory address regions on Hygon Date: Tue, 20 Jan 2026 17:14:46 +0800 Message-ID: <20260120091449.526798-4-zhiquan_li@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260120091449.526798-1-zhiquan_li@163.com> References: <20260120091449.526798-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: _____wCn5zu4R29pIOfPGw--.26432S5 X-Coremail-Antispam: 1Uf129KBjvJXoW7CFykCr1Utr4fXr18Jr4Dtwb_yoW8ZF1Upa 4fCw45WF48GF1ay3yxXws7ZFyvkFn7CF4xKryjy343u3W5WF13Xr4Sk3WYvrW3CrWrZw13 Aa4fJF4DZw4jqaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRm9a9UUUUU= X-CM-SenderInfo: 52kl13xdqbzxi6rwjhhfrp/xtbCwh83IGlvR7++ewAA3x Content-Type: text/plain; charset="utf-8" There are similar reserved memory address regions for Hygon architecture, mapping memory into these regions and accesses 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 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 10:38:28 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 E8A92500965; Tue, 20 Jan 2026 09:16:04 +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=1768900568; cv=none; b=UAIwsE71pkYhrgmes753dO8a3Lgchlw2O2VCxcYtECxld72ydwsnhAEOSxzfR5xJtt3gkGazg5Qkdz9B8AFvC+09zP0sBUAPUnt5Sr7gCvFUAUK4RE83+ijowNAz6f6GkLwWjlm2S1O8DfBpW80Ol4jj8teD2cFxYzN4bMrWPIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768900568; c=relaxed/simple; bh=887RL4BDFs3BO7HY/4FBnCKpsH5a9PRYlIJWBKHjmMA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YlgPytGM45D+GiyM+eZfXjzoNaMWUBtgGgdFE1VEra9fg7o411Obrw5+8E9MU0P1vdOmmmdSfPtuEa8xhed0ydHTwrsHJ4UvnXG91x3x3wzNoWZTzbgbvXe0+5hKwRx0UyMEcWnooTEDAf6uptc8uSMTnsZcqRGYQ+obaZT1NAg= 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=Uc9OglCo; 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="Uc9OglCo" 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=sc dheWsKkBb8qVp39GFAKOTPxt9U9/o1zR2spPZolHI=; b=Uc9OglCovbhNGTmh7c Q6bYpUfP20gdG9/Kqrd7l/aOlzkkjSxvEFuKN43+43a0PEYWFW5MZCUdrntBac0n yfcFAiZBuQAMPmBlGAlKvhQThY8/zo0nfO4iK63ciGMzznBqPls0TTzwQNeLPQ1S V6I2xhdtQxRKFUOXsYDRQ+WdQ= Received: from 163.com (unknown []) by gzga-smtp-mtada-g0-0 (Coremail) with SMTP id _____wCn5zu4R29pIOfPGw--.26432S6; Tue, 20 Jan 2026 17:15:43 +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 4/5] KVM: x86: selftests: Allow the PMU event filter test for Hygon Date: Tue, 20 Jan 2026 17:14:47 +0800 Message-ID: <20260120091449.526798-5-zhiquan_li@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260120091449.526798-1-zhiquan_li@163.com> References: <20260120091449.526798-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: _____wCn5zu4R29pIOfPGw--.26432S6 X-Coremail-Antispam: 1Uf129KBjvJXoWxJr4xtF4kWFyDJF4DCw1xZrb_yoW8CF13pF yruw1avF48KFnIk3WxG34kWr4fAw1kWF4kJ3s0gry8Zr1UJw1Iqr4jka43ta1YkFWFqw1Y yay7tFy5C34UKaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pMsjj9UUUUU= X-CM-SenderInfo: 52kl13xdqbzxi6rwjhhfrp/xtbC6R83IGlvR7-EQgAA3Z 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 directly. 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 10:38:28 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 3365A3C1979; Tue, 20 Jan 2026 09:16:07 +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=1768900570; cv=none; b=dbGooo4C2TKzvmC8NrZwuncFySKn4IeLcVu1sdPvKPrIvuo2YbPuxhYST21qKHERgZZpbh3VMXLXhrQBCMu0/oJG/BmblMitPerdn47GAOdbEcfu9z/QLxAjUPIUNYCqnJDHJ2CQd8Whc1TkxlZI0XfBUsMrUcVa1oCj1IvbQoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768900570; c=relaxed/simple; bh=+LSKJXTL0Oi0zIuWeuP0lkYB6M5EUphYk6I5LcY7gDk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qs3TaDM7aZ6mcd+LrXVse8+bpFQDuNTQJyUfZtXrSGzIlyNyUayxb+HAx7WXsTLWfe4lAz30unD47O4muZz21A2Ylhw4ViUwoeLqQ58kd0i0C4BF/1nVN0Suj5WcTtgIK24X5EevsuXvvJVPFlznogEqix4Yqt2TTFHQgmwByMw= 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=dVcKek7i; 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="dVcKek7i" 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=al 8hUm54zf4NpyVr8Q4r3YPQ1wLQggAbykFHpaZ9yp0=; b=dVcKek7i1vEzAFhtTg 32JH0rGMfPqs4Sry8AFtuiFdq1j7NfhTetww7DuNXMxvfbG7v92RxXnz+cQXmno3 UVvDGamzBVRjO7SZ6OTGuUA/+uhB7Ea11GrrE4ITUOkrjAGo6dGuwYCnIaveQ7tC z8wMlo7AwQ3O51+2WytvVtELc= Received: from 163.com (unknown []) by gzga-smtp-mtada-g0-0 (Coremail) with SMTP id _____wCn5zu4R29pIOfPGw--.26432S7; Tue, 20 Jan 2026 17:15:44 +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 5/5] KVM: x86: selftests: Fix write MSR_TSC_AUX reserved bits test failure on Hygon Date: Tue, 20 Jan 2026 17:14:48 +0800 Message-ID: <20260120091449.526798-6-zhiquan_li@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260120091449.526798-1-zhiquan_li@163.com> References: <20260120091449.526798-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: _____wCn5zu4R29pIOfPGw--.26432S7 X-Coremail-Antispam: 1Uf129KBjvJXoWxWw1xXFyrtrW3Ar18AFy3twb_yoW5Zrykpa 92kw4YgrZrKa42qa9rXF1kGF4rArn7Gry0grnaq3y7Zwn5Ary7Xr4xKayrXay7ZrWSvr98 ZF47tw42kw4DAaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pMsjj9UUUUU= X-CM-SenderInfo: 52kl13xdqbzxi6rwjhhfrp/xtbCwgA4IWlvR8C+mgAA3+ 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 with 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 results of write 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