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 4181014A095; Mon, 6 Jan 2025 15:50:37 +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=1736178637; cv=none; b=fWrC3rIzS+KjAWXQ9WYImUDZohm5iqX0m67seXx9j+FVTfwHp1ULTDVS3bzD1W6zk6fNjx+hZwYX4iw0GOuQIz6EylrgV39qnC7Lu9CoaNQIa7KvoxKC7p48uroT8MlTIILH+6jaCwlrbZ5HZq+xaVfK32YYPPNNc/Q1kq1a13E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736178637; c=relaxed/simple; bh=49EO99zNfYJXf6ESRBqydqgQARDH76jEbBALHkYxndg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XIjgww9TXOKLkzKnQu2lzjf6gfqwwVEevQIUtv+z9Dow5zbQKXNPPYz+LEk8VFVhmEbH7XVNazbrc/rJNcCn+RCxo6+PLeOEtFAoqxkWbGAPxk7Hl9jxxkHWucHwh15Ys2n/2GC9PA6r1NgxAQxy8KX0jR8tjViQKphe2iKqldk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=2irU+UqG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="2irU+UqG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91CE5C4CEDF; Mon, 6 Jan 2025 15:50:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1736178637; bh=49EO99zNfYJXf6ESRBqydqgQARDH76jEbBALHkYxndg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2irU+UqGU5/DNwQbNo+HFynOL4tpqJ/DoI71eM+m/FdLXlkdrSHEkmjk9qsOWMnWk Oq46blCB+lkAVjQnV2CSP0frcI7F3jQym5WLBdsDbCwdlmsxe0RydUIUt8BiBKUjCY Wf0E4854rIiS0oBm8A5VoVPm7fML6gYLQOlWU3dQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tom Lendacky , Xiaoyao Li , Nikunj A Dadhania , Binbin Wu , Kai Huang , Sean Christopherson Subject: [PATCH 5.15 044/168] KVM: x86: Play nice with protected guests in complete_hypercall_exit() Date: Mon, 6 Jan 2025 16:15:52 +0100 Message-ID: <20250106151140.127863316@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106151138.451846855@linuxfoundation.org> References: <20250106151138.451846855@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sean Christopherson commit 9b42d1e8e4fe9dc631162c04caa69b0d1860b0f0 upstream. Use is_64_bit_hypercall() instead of is_64_bit_mode() to detect a 64-bit hypercall when completing said hypercall. For guests with protected state, e.g. SEV-ES and SEV-SNP, KVM must assume the hypercall was made in 64-bit mode as the vCPU state needed to detect 64-bit mode is unavailable. Hacking the sev_smoke_test selftest to generate a KVM_HC_MAP_GPA_RANGE hypercall via VMGEXIT trips the WARN: ------------[ cut here ]------------ WARNING: CPU: 273 PID: 326626 at arch/x86/kvm/x86.h:180 complete_hypercall_exit+0x44/0xe0 [kvm] Modules linked in: kvm_amd kvm ... [last unloaded: kvm] CPU: 273 UID: 0 PID: 326626 Comm: sev_smoke_test Not tainted 6.12.0-smp--392e932fa0f3-feat #470 Hardware name: Google Astoria/astoria, BIOS 0.20240617.0-0 06/17/2024 RIP: 0010:complete_hypercall_exit+0x44/0xe0 [kvm] Call Trace: kvm_arch_vcpu_ioctl_run+0x2400/0x2720 [kvm] kvm_vcpu_ioctl+0x54f/0x630 [kvm] __se_sys_ioctl+0x6b/0xc0 do_syscall_64+0x83/0x160 entry_SYSCALL_64_after_hwframe+0x76/0x7e ---[ end trace 0000000000000000 ]--- Fixes: b5aead0064f3 ("KVM: x86: Assume a 64-bit hypercall for guests with protected state") Cc: stable@vger.kernel.org Cc: Tom Lendacky Reviewed-by: Xiaoyao Li Reviewed-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky Reviewed-by: Binbin Wu Reviewed-by: Kai Huang Link: https://lore.kernel.org/r/20241128004344.4072099-2-seanjc@google.com Signed-off-by: Sean Christopherson Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8946,7 +8946,7 @@ static int complete_hypercall_exit(struc { u64 ret = vcpu->run->hypercall.ret; - if (!is_64_bit_mode(vcpu)) + if (!is_64_bit_hypercall(vcpu)) ret = (u32)ret; kvm_rax_write(vcpu, ret); ++vcpu->stat.hypercalls;