From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <jbeulich@suse.com>,
Ross Lagerwall <ross.lagerwall@citrix.com>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger@xenproject.org>,
"Jason Andryuk" <jason.andryuk@amd.com>,
"Teddy Astie" <teddy.astie@vates.tech>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH v2] x86/svm: Intercept CR0 writes selectively
Date: Tue, 8 Sep 2026 14:57:05 +0100 [thread overview]
Message-ID: <ef71d534-1bd2-4837-90d4-adf1822fc4ba@citrix.com> (raw)
In-Reply-To: <8fbc99b1-d98b-4f52-b9ea-bd84e8bfa2ca@suse.com>
On 08/09/2026 9:44 am, Jan Beulich wrote:
> On 04.09.2026 14:23, Ross Lagerwall wrote:
>> @@ -2517,6 +2518,7 @@ void asmlinkage svm_vmexit_handler(void)
>> hvm_sanitize_regs_fields(
>> regs, !(vmcb_get_efer(vmcb) & EFER_LMA) || !(vmcb->cs.l));
>>
>> + v->arch.hvm.guest_cr[0] = vmcb_get_cr0(vmcb);
>> v->arch.hvm.guest_cr[2] = vmcb_get_cr2(vmcb);
>> if ( paging_mode_hap(v->domain) )
>> v->arch.hvm.guest_cr[3] = v->arch.hvm.hw_cr[3] = vmcb_get_cr3(vmcb);
> gitlab-CI says no to this patch [1], and I think it's the change above which
> gets in the way of running guests in shadow mode (as is the case for the two
> qemu-smoke-x86_64-*-pvh tests). svm_update_guest_cr() has
>
> value = v->arch.hvm.guest_cr[0];
> if ( paging_mode_shadow(v->domain) )
> value |= X86_CR0_PG | X86_CR0_WP;
> vmcb_set_cr0(vmcb, value);
>
> i.e. upon reading back the guest's CR0 value we would wrongly record it
> having PG (and WP) enabled, at which point shadow code would try to use the
> still-zero CR3 as page table base. I think values need merging here, with
> only TS and MP taken from what vmcb_get_cr0() returns.
Yes this is broken for Shadow.
Shadow shouldn't be trying to use CR0_WRITE_SEL. What's in the VMCB is
unrelated to the guest's choice of value, and reverse engineering it is
fragile.
Use full CR0_WRITE for Shadow guests, and use CR0_WRITE_SEL for HAP only.
~Andrew
next prev parent reply other threads:[~2026-09-08 13:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 12:23 [PATCH v2] x86/svm: Intercept CR0 writes selectively Ross Lagerwall
2026-09-07 12:24 ` Jan Beulich
2026-09-08 8:44 ` Jan Beulich
2026-09-08 13:57 ` Andrew Cooper [this message]
2026-09-08 14:09 ` Ross Lagerwall
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=ef71d534-1bd2-4837-90d4-adf1822fc4ba@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=jason.andryuk@amd.com \
--cc=jbeulich@suse.com \
--cc=roger@xenproject.org \
--cc=ross.lagerwall@citrix.com \
--cc=teddy.astie@vates.tech \
--cc=xen-devel@lists.xenproject.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 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.