All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ashish Kalra" <Ashish.Kalra@amd.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3] x86/sev: Handle DR7 accesses in the #VC handler after GHCB teardown
Date: Mon, 30 Nov 2026 22:25:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-242106@kernel.org> (raw)
In-Reply-To: <55e961099c4169dc8b3853d4b05a330c572e8b21.1796075019.git.ashish.kalra@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] x86/sev: missing opcode and DebugSwap checks in
  vc_handle_exception_no_ghcb()
--

commit c27cd4c5ad513d845adab8b2a99525e2c33cc33d
Author: Ashish Kalra <ashish.kalra@amd.com>

x86/sev: Handle DR7 accesses in the #VC handler after GHCB teardown

This commit handles DR7 read and write #VC exceptions locally after the
per-CPU and boot GHCBs have been torn down during kexec, and terminates
the guest with GHCB_TERM_NO_GHCB on any other #VC in that window.

> diff --git a/arch/x86/coco/sev/vc-handle.c b/arch/x86/coco/sev/vc-handle.c
> index 96b62b49b2b53..5b5da8efbf39e 100644
> --- a/arch/x86/coco/sev/vc-handle.c
> +++ b/arch/x86/coco/sev/vc-handle.c
> @@ -889,6 +889,32 @@ static __always_inline bool vc_from_invalid_context(struct pt_regs *regs)
>  	return is_vc2_stack(sp) && !is_vc2_stack(prev_sp);
>  }
>  
> +/* Without a GHCB, only DR7 accesses are currently handled */
> +static void vc_handle_exception_no_ghcb(struct pt_regs *regs, unsigned long exit_code)
> +{
> +	struct es_em_ctxt ctxt;
> +	long *reg;
> +
> +	if (exit_code != SVM_EXIT_READ_DR7 && exit_code != SVM_EXIT_WRITE_DR7)
> +		goto fail;
> +
> +	if (vc_init_em_ctxt(&ctxt, regs, exit_code) != ES_OK)
> +		goto fail;
> +
> +	reg = vc_insn_get_rm(&ctxt);
> +	if (!reg)
> +		goto fail;
> +
> +	if (exit_code == SVM_EXIT_READ_DR7)
> +		*reg = DR7_RESET_VALUE;
> +
> +	vc_finish_insn(&ctxt);
> +	return;

[Severity: Medium]
Should vc_handle_exception_no_ghcb() also validate the instruction with
vc_check_opcode_bytes(&ctxt, exit_code) and reject the #VC when
(sev_status & MSR_AMD64_SNP_DEBUG_SWAP) is set, as vc_handle_exitcode(),
vc_handle_dr7_read() and vc_handle_dr7_write() do?

Without vc_check_opcode_bytes(), if the hypervisor injects a #VC with
SVM_EXIT_WRITE_DR7 or SVM_EXIT_READ_DR7 at an arbitrary instruction after
snp_kexec_finish(), vc_insn_get_rm() still resolves a register pointer
from modrm.value (defaulting to &regs->ax when the instruction has no
ModRM byte), so vc_handle_exception_no_ghcb() skips the instruction via
vc_finish_insn() and, on SVM_EXIT_READ_DR7, overwrites a general-purpose
register in regs with DR7_RESET_VALUE instead of terminating the guest.
And if MSR_AMD64_SNP_DEBUG_SWAP is enabled, DR7 accesses are not
intercepted, so a #VC on the DR7 write in hw_breakpoint_disable() would
skip clearing the hardware DR7 register in the encrypted VMSA instead of
terminating.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/55e961099c4169dc8b3853d4b05a330c572e8b21.1796075019.git.ashish.kalra@amd.com?part=1

  reply	other threads:[~2026-11-30 22:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 22:12 [PATCH v3] x86/sev: Handle DR7 accesses in the #VC handler after GHCB teardown Ashish Kalra
2026-11-30 22:25 ` sashiko-bot [this message]
2026-11-30 22:53 ` Tom Lendacky
2026-12-01 15:04   ` Kalra, Ashish

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-242106@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Ashish.Kalra@amd.com \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.