[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] x86/svm: Intercept CR0 writes selectively


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>
  • From: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
  • Date: Tue, 8 Sep 2026 15:09:12 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UpaGsNzzJWRgZ78NXPfKGfndninYraoAyb0SMbIgvtU=; b=tQQlQQEATJ88rmDVJQF4V5/Zl/IKMHOREICE0j5DHVJFlX/w3hk6yBlbVRELinuQ9mmI9k5R3M/df+YAklfYmlZbGFQtCWNgxeZrsq1wvzVee/TCTDCrZi7rvXMQPWJgZ/GxHuB2Ml72iMBIkIPefthQlxIQQr450wEggRmg3k7I6Hg4t1TBRhz5OmzOJGCwu9nrDqeqqvM/ebo380FnRlNpTRAlnjIxgdF7v11HTrK3W6t/J6XxzNeB1xHKky7L2VFcyUbGOgVKvBYZPmy6vJ9ngP57YGytvfFwCEKPRr9Sb8ByXewq7SPNDeTUk+VDlTxH7tiQUaJvuDVDzFv/mg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sSa+SlxtlDRH7MLMeJhbGOTkMCKUxW9AsL/WzzhTcs9X9eBhfA93nmpkXf0t5YOmof88Qh3WheXhRTia/+c0KJjamttcUUSvnv3bLImZqEL3vO/Etj7PlyxLrilimnkPqZK1127o2tKI4WIYMvKZAeI8yQEqavqhL6VUqQfbJ6rsyAf/qzJl6l8aV6EQ1TihfkwMK0Bfo8TmcV7Yyz9HenZRFwnbkKDts1AvWTKGoCuhuQFQuYI80Yg+El2GtMEp/jguJn3WlBegKBGeI1oXXexnZc91jEJRnpEhJBdR1ggvXXCb6QPFAtyFUGFHzx8ewCRWtLyZGWHvjSoLeLu9Gg==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 08 Sep 2026 14:09:44 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.