Skip to content

Commit

Permalink
KVM: x86: Calls is_64_bit_hypercall() instead of is_64_bit_mode() in …
Browse files Browse the repository at this point in the history
…complete_hypercall_exit()

hygon inclusion
category: bugfix
CVE: NA

---------------------------

In the commit b5aead0 ("KVM: x86: Assume a 64-bit hypercall for
guests with protected state"), is_64_bit_mode() will trigger warning,
as the following messages, for SEV-ES or CSV2 guest.

[85350.053201] ------------[ cut here ]------------
[85350.053206] WARNING: CPU: 2 PID: 68989 at arch/x86/kvm/x86.h:156 complete_hypercall_exit+0x6a/0x70 [kvm]
[85350.053299] Modules linked in: kvm_amd(OE) kvm(OE) ccp(E) irqbypass(E) vhost_net(E) vhost(E) vhost_iotlb(E) tap(E) fuse(E) xt_CHECKSUM(E) xt_MASQUERADE(E) xt_conntrack(E) ipt_REJECT(E) nf_reject_ipv4(E) ip6table_mangle(E) ip6table_nat(E) iptable_mangle(E) iptable_nat(E) nf_nat(E) nf_conntrack(E) nf_defrag_ipv6(E) nf_defrag_ipv4(E) nf_tables(E) libcrc32c(E) nfnetlink(E) ip6table_filter(E) ip6_tables(E) iptable_filter(E) tun(E) bridge(E) stp(E) llc(E) rfkill(E) vfat(E) fat(E) binfmt_misc(E) intel_rapl_msr(E) intel_rapl_common(E) amd64_edac(E) edac_mce_amd(E) crct10dif_pclmul(E) crc32_pclmul(E) acpi_ipmi(E) ipmi_ssif(E) ipmi_si(E) ast(E) joydev(E) mousedev(E) ghash_clmulni_intel(E) rapl(E) ipmi_devintf(E) drm_shmem_helper(E) drm_kms_helper(E) ipmi_msghandler(E) sg(E) k10temp(E) acpi_cpufreq(E) squashfs(E) loop(E) parport_pc(E) ppdev(E) lp(E) parport(E) drm(E) ip_tables(E) sd_mod(E) t10_pi(E) crc64_rocksoft(E) crc64(E) ahci(E) igb(E) i2c_designware_platform(E) libahci(E) i2c_algo_bit(E) dca(E) i2c_piix4(E)
[85350.053421]  i2c_designware_core(E) crc32c_intel(E) libata(E) i2c_core(E) [last unloaded: kvm(OE)]
[85350.053432] CPU: 2 PID: 68989 Comm: qemu-system-x86 Tainted: GF       W  OE      6.6.7-for-openanolis #5
[85350.053438] Hardware name: HYGON HongHaiA1b/HongHaiA1, BIOS A1633050 02/02/2023
[85350.053441] RIP: 0010:complete_hypercall_exit+0x6a/0x70 [kvm]
[85350.053511] Code: e8 9b fb ff ff 48 83 c4 08 5b 5d e9 60 68 68 d8 48 8d 54 24 04 48 89 e6 48 89 ef e8 40 db 12 00 8b 44 24 04 85 c0 74 c4 eb c4 <0f> 0b eb b5 66 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90
[85350.053514] RSP: 0018:ffffc90000ea3e28 EFLAGS: 00010202
[85350.053519] RAX: ffff8881419f0000 RBX: 0000000000000000 RCX: ffff8881003ad780
[85350.053522] RDX: 0000606fc0a29bc0 RSI: 00000000fffffe01 RDI: ffff888b5dc20000
[85350.053525] RBP: ffff888b5dc20000 R08: 0000000000000001 R09: 0000000000000000
[85350.053527] R10: ffffc90000ea3ee8 R11: 0000000000000000 R12: ffff88810fe1ea00
[85350.053530] R13: ffff888b5dc20000 R14: ffff888b5dc20048 R15: 0000000000000000
[85350.053532] FS:  00007eff45528700(0000) GS:ffff88903f080000(0000) knlGS:0000000000000000
[85350.053536] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[85350.053539] CR2: 0000000000000000 CR3: 00000001415d2000 CR4: 00000000003506e0
[85350.053541] Call Trace:
[85350.053545]  <TASK>
[85350.053550]  ? __warn+0x84/0x140
[85350.053558]  ? complete_hypercall_exit+0x6a/0x70 [kvm]
[85350.053627]  ? report_bug+0x1bd/0x1d0
[85350.053635]  ? handle_bug+0x3c/0x70
[85350.053640]  ? exc_invalid_op+0x18/0x70
[85350.053645]  ? asm_exc_invalid_op+0x1a/0x20
[85350.053655]  ? complete_hypercall_exit+0x6a/0x70 [kvm]
[85350.053724]  kvm_arch_vcpu_ioctl_run+0x3dd/0x410 [kvm]
[85350.053796]  kvm_vcpu_ioctl+0x277/0x6c0 [kvm]
[85350.053855]  __x64_sys_ioctl+0x92/0xd0
[85350.053864]  do_syscall_64+0x3f/0x90
[85350.053868]  entry_SYSCALL_64_after_hwframe+0x6e/0xd8
[85350.053874] RIP: 0033:0x7eff486c33ab
[85350.053878] Code: 0f 1e fa 48 8b 05 e5 7a 0d 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff ff ff c3 66 0f 1f 44 00 00 f3 0f 1e fa b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d b5 7a 0d 00 f7 d8 64 89 01 48
[85350.053881] RSP: 002b:00007eff45527848 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
[85350.053886] RAX: ffffffffffffffda RBX: 000000000000ae80 RCX: 00007eff486c33ab
[85350.053888] RDX: 0000000000000000 RSI: 000000000000ae80 RDI: 0000000000000010
[85350.053891] RBP: 0000563586e32430 R08: 0000563584ff1d30 R09: 00007eff455276a4
[85350.053893] R10: 00007eff4552769c R11: 0000000000000246 R12: 0000000000000000
[85350.053896] R13: 00005635856bcd60 R14: 0000000000000000 R15: 0000000000000000
[85350.053904]  </TASK>
[85350.053906] ---[ end trace 0000000000000000 ]---

Use is_64_bit_hypercall() instead of is_64_bit_mode() in
complete_hypercall_exit() to avoid warning when the SEV-ES or CSV2
guest invoking KVM_HC_MAP_GPA_RANGE hypercall.

Fixes: b5aead0 ("KVM: x86: Assume a 64-bit hypercall for guests with protected state")
Signed-off-by: hanliyang <hanliyang@hygon.cn>
  • Loading branch information
hanliyang authored and Avenger-285714 committed Aug 19, 2024
1 parent 935671c commit 9bcbc83
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -9855,8 +9855,13 @@ static int complete_hypercall_exit(struct kvm_vcpu *vcpu)
{
u64 ret = vcpu->run->hypercall.ret;

if (!is_64_bit_mode(vcpu))
/* Use is_64_bit_hypercall() instead of is_64_bit_mode() for Hygon CPUs */
if (is_x86_vendor_hygon()) {
if (!is_64_bit_hypercall(vcpu))
ret = (u32)ret;
} else if (!is_64_bit_mode(vcpu)) {
ret = (u32)ret;
}
kvm_rax_write(vcpu, ret);
++vcpu->stat.hypercalls;
return kvm_skip_emulated_instruction(vcpu);
Expand Down

0 comments on commit 9bcbc83

Please sign in to comment.