All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ross Lagerwall <ross.lagerwall@citrix.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>,
	Jan Beulich <jbeulich@suse.com>
Cc: "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 15:09:12 +0100	[thread overview]
Message-ID: <c9ad35cb-119a-4c71-bc51-d558b4b0ed74@citrix.com> (raw)
In-Reply-To: <ef71d534-1bd2-4837-90d4-adf1822fc4ba@citrix.com>

On 9/8/26 2:57 PM, Andrew Cooper wrote:
> 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.

I did try Jan's suggestion which fixes the initial problem but crashes when
dom0 brings up its second vCPU.

If keeping Shadow guests using full CR0_WRITE is acceptable, I'll update the
patch to do that since there are surely better things to do than spending time
making Shadow improvements.

Ross


      reply	other threads:[~2026-09-08 14:09 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
2026-09-08 14:09     ` Ross Lagerwall [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=c9ad35cb-119a-4c71-bc51-d558b4b0ed74@citrix.com \
    --to=ross.lagerwall@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jason.andryuk@amd.com \
    --cc=jbeulich@suse.com \
    --cc=roger@xenproject.org \
    --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.