Linux Confidential Computing Development
 help / color / mirror / Atom feed
From: "Nikunj A. Dadhania" <nikunj@amd.com>
To: Ashish Kalra <Ashish.Kalra@amd.com>, <tglx@kernel.org>,
	<mingo@redhat.com>, <bp@alien8.de>, <dave.hansen@linux.intel.com>,
	<x86@kernel.org>, <hpa@zytor.com>, <thomas.lendacky@amd.com>,
	<Srikanth.Aithal@amd.com>
Cc: <kvm@vger.kernel.org>, <linux-coco@lists.linux.dev>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4] x86/sev: Handle DR7 accesses in the #VC handler after GHCB teardown
Date: Thu, 3 Dec 2026 16:19:12 +0530	[thread overview]
Message-ID: <896e1333-9407-4028-b188-160dd40f0c3e@amd.com> (raw)
In-Reply-To: <4f8dc645aafd49c65dfa5456f097b4d3122862e4.1796158168.git.ashish.kalra@amd.com>



On 12/2/2026 2:30 AM, Ashish Kalra wrote:
> From: Ashish Kalra <ashish.kalra@amd.com>
> 
> machine_kexec() calls hw_breakpoint_disable(), which writes DR7. On
> SEV-ES/SNP guests that do not have DebugSwap enabled, DR7 accesses are
> intercepted and delivered to the guest as a #VC exception, which is
> normally serviced through the GHCB.
> 
> By the time machine_kexec() runs, snp_kexec_finish() (called from
> native_machine_shutdown()) has already converted the per-CPU GHCBs and
> the boot GHCB back to private, set boot_ghcb to NULL and cleared
> sev_cfg.ghcbs_initialized. The DR7 write therefore raises a #VC that
> dereferences a NULL GHCB pointer and the kexec fails.
> 
> Before commit 3645eb7e3915 ("x86/fred: Fix early boot failures on
> SEV-ES/SNP guests"), __sev_get_ghcb() returned the per-CPU GHCB in this
> window. That page had already been converted back to private, so the
> hypervisor could not read the request nor write a response, and the
> guest treated its own stale GHCB contents as a successful reply. The DR7
> write was silently dropped and the kexec only worked by accident. Since
> that commit, __sev_get_ghcb() returns the now NULL boot_ghcb instead.
> 
> The GHCB MSR protocol cannot help here: apart from CPUID, it has no
> request that corresponds to an intercepted instruction, so a DR7 access
> cannot be forwarded to the hypervisor without a GHCB.
> 
> Instead, once the GHCBs have been torn down, handle the #VC without a
> GHCB: verify that it is a genuine DR7 access and complete it locally,
> returning the reset value for reads and dropping writes. This is safe
> because, without DebugSwap, the hypervisor only tracks the DR7 value and
> cannot load it into the encrypted VMSA, and the kexec'ed kernel writes
> DR7 again in cpu_init(). Only DR7 accesses are currently handled this
> way; any other #VC in that window terminates the guest with a new,
> specific reason code instead of dereferencing a NULL GHCB.
> 
> Fixes: 3074152e56c9 ("x86/sev: Convert shared memory back to private on kexec")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>

Tested SEV-SNP guest with this patch, kexec kernel boots fine and
the DR7 write is handled locally.

I also built a test kernel that does an RDMSR after the GHCBs are
torn down. The guest terminates with 0x1:0xd (GHCB_TERM_VC_NO_GHCB),
as intended.

Reviewed-by: Nikunj A Dadhania nikunj@amd.com
Tested-by: Nikunj A Dadhania nikunj@amd.com


      parent reply	other threads:[~2026-12-03 10:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 21:00 [PATCH v4] x86/sev: Handle DR7 accesses in the #VC handler after GHCB teardown Ashish Kalra
2026-12-02 12:46 ` Aithal, Srikanth
2026-12-03 10:49 ` Nikunj A. Dadhania [this message]

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=896e1333-9407-4028-b188-160dd40f0c3e@amd.com \
    --to=nikunj@amd.com \
    --cc=Ashish.Kalra@amd.com \
    --cc=Srikanth.Aithal@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=thomas.lendacky@amd.com \
    --cc=x86@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox