Skip to contentSkip to conversation

x86/svm: Make various details private

PATCH In review Andrew Cooper 3 participants 12 messages Nov 28, 2025 – Dec 11, 2025

lore
Share & tools
lore
#0 lore raw

cover x86/svm: Make various details private

Lots of this does not need to be included into all translation units.

Andrew Cooper (3):
x86/svm: Make vmcb_struct private to svm/
x86/svm: Drop svmdebug.c
x86/svm: Drop svmdebug.h

 xen/arch/x86/hvm/svm/Makefile               |   1 -
 xen/arch/x86/hvm/svm/asid.c                 |   1 +
 xen/arch/x86/hvm/svm/emulate.c              |   1 +
 xen/arch/x86/hvm/svm/intr.c                 |   1 +
 xen/arch/x86/hvm/svm/nestedsvm.c            |   2 +-
 xen/arch/x86/hvm/svm/svm.c                  |   2 +-
 xen/arch/x86/hvm/svm/svm.h                  |  17 +
 xen/arch/x86/hvm/svm/svmdebug.c             | 179 ------
 xen/arch/x86/hvm/svm/vmcb.c                 | 163 ++++-
 xen/arch/x86/hvm/svm/vmcb.h                 | 620 +++++++++++++++++++
 xen/arch/x86/include/asm/hvm/svm/svmdebug.h |  19 -
 xen/arch/x86/include/asm/hvm/svm/vmcb.h     | 621 --------------------
 12 files changed, 804 insertions(+), 823 deletions(-)
 delete mode 100644 xen/arch/x86/hvm/svm/svmdebug.c
 create mode 100644 xen/arch/x86/hvm/svm/vmcb.h
 delete mode 100644 xen/arch/x86/include/asm/hvm/svm/svmdebug.h

base-commit: 486c7f79c0032cbd210af8f3f1d204f8eabfdbde

Signature · 1 line
2.39.5
#1 lore raw

PATCH 1/3 x86/svm: Make vmcb_struct private to svm/

The rest of Xen has no buisness knowing this structure, and it is currently included via xen/sched.h into most code. Create a new private svm/vmcb.h.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/hvm/svm/asid.c             |   1 +
 xen/arch/x86/hvm/svm/emulate.c          |   1 +
 xen/arch/x86/hvm/svm/intr.c             |   1 +
 xen/arch/x86/hvm/svm/nestedsvm.c        |   1 +
 xen/arch/x86/hvm/svm/svm.c              |   1 +
 xen/arch/x86/hvm/svm/svmdebug.c         |   2 +
 xen/arch/x86/hvm/svm/vmcb.c             |   2 +
 xen/arch/x86/hvm/svm/vmcb.h             | 617 ++++++++++++++++++++++++
 xen/arch/x86/include/asm/hvm/svm/vmcb.h | 606 -----------------------
 9 files changed, 626 insertions(+), 606 deletions(-)
 create mode 100644 xen/arch/x86/hvm/svm/vmcb.h
xen/arch/x86/hvm/svm/asid.c +1 -0
index 03f98b7a8b89..0e115243a3af 100644
@@ -9,6 +9,7 @@
 #include <asm/hvm/svm/svm.h>
 
 #include "svm.h"
+#include "vmcb.h"
 
 void svm_asid_init(const struct cpuinfo_x86 *c)
 {
xen/arch/x86/hvm/svm/emulate.c +1 -0
index 93ac1d3435f9..d8aa45590885 100644
@@ -15,6 +15,7 @@
 #include <asm/hvm/svm/vmcb.h>
 
 #include "svm.h"
+#include "vmcb.h"
 
 static unsigned long svm_nextrip_insn_length(struct vcpu *v)
 {
xen/arch/x86/hvm/svm/intr.c +1 -0
index 46186a110261..931973a9fad4 100644
@@ -26,6 +26,7 @@
 #include <xen/domain_page.h>
 
 #include "nestedhvm.h"
+#include "vmcb.h"
 
 static void svm_inject_nmi(struct vcpu *v)
 {
xen/arch/x86/hvm/svm/nestedsvm.c +1 -0
index 1813692ffb03..191466755148 100644
@@ -16,6 +16,7 @@
 
 #include "nestedhvm.h"
 #include "svm.h"
+#include "vmcb.h"
 
 #define NSVM_ERROR_VVMCB        1
 #define NSVM_ERROR_VMENTRY      2
xen/arch/x86/hvm/svm/svm.c +1 -0
index 2d7c598ffe99..14b3a427e642 100644
@@ -44,6 +44,7 @@
 
 #include "nestedhvm.h"
 #include "svm.h"
+#include "vmcb.h"
 
 void noreturn svm_asm_do_resume(void);
 
xen/arch/x86/hvm/svm/svmdebug.c +2 -0
index 9d3badcf5da0..bdb9ea3583ee 100644
@@ -10,6 +10,8 @@
 #include <asm/msr-index.h>
 #include <asm/hvm/svm/svmdebug.h>
 
+#include "vmcb.h"
+
 static void svm_dump_sel(const char *name, const struct segment_register *s)
 {
     printk("%s: %04x %04x %08x %016"PRIx64"\n",
xen/arch/x86/hvm/svm/vmcb.c +2 -0
index c57d314a2486..44fa76bf0228 100644
@@ -22,6 +22,8 @@
 #include <asm/p2m.h>
 #include <asm/spec_ctrl.h>
 
+#include "vmcb.h"
+
 struct vmcb_struct *alloc_vmcb(void)
 {
     struct vmcb_struct *vmcb;
xen/arch/x86/hvm/svm/vmcb.h new file +617 -0

617 lines not on this page · raw message

xen/arch/x86/include/asm/hvm/svm/vmcb.h +0 -606

624 lines not on this page · raw message

Signature · 1 line
2.39.5
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] x86/svm: Make vmcb_struct private to svm/

Hi,

Code motion is correct according to my scripts. A nit though...

Quoted 22 lines · Andrew Cooper

The rest of Xen has no buisness knowing this structure, and it is currently included via xen/sched.h into most code. Create a new private svm/vmcb.h.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/hvm/svm/asid.c             |   1 +
 xen/arch/x86/hvm/svm/emulate.c          |   1 +
 xen/arch/x86/hvm/svm/intr.c             |   1 +
 xen/arch/x86/hvm/svm/nestedsvm.c        |   1 +
 xen/arch/x86/hvm/svm/svm.c              |   1 +
 xen/arch/x86/hvm/svm/svmdebug.c         |   2 +
 xen/arch/x86/hvm/svm/vmcb.c             |   2 +
 xen/arch/x86/hvm/svm/vmcb.h             | 617 ++++++++++++++++++++++++
 xen/arch/x86/include/asm/hvm/svm/vmcb.h | 606 -----------------------
 9 files changed, 626 insertions(+), 606 deletions(-)
 create mode 100644 xen/arch/x86/hvm/svm/vmcb.h

[snip]

xen/arch/x86/hvm/svm/vmcb.h line 7

Quoted 13 lines
xen/arch/x86/hvm/svm/vmcb.h new file +7 -0
new file mode 100644
index 000000000000..68012948a9e3
@@ -0,0 +1,617 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef SVM_PRIVATE_VMCB_H
+#define SVM_PRIVATE_VMCB_H
+
+#include <xen/types.h>
+
+#include <asm/x86_emulate.h>

Worth commenting here that this exists because the segment selector struct lives as part of the x86 emulator even though it's part of the SVM ABI.

In an ideal world this wouldn't exist. Otherwise everything looks fine.

With or without the nit addressed

Cheers,
Alejandro

#3 lore raw

Re: [PATCH 1/3] x86/svm: Make vmcb_struct private to svm/

In reply to Andrew Cooper
Quoted 9 lines · Andrew Cooper

The rest of Xen has no buisness knowing this structure, and it is currently included via xen/sched.h into most code. Create a new private svm/vmcb.h.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

Quoted 12 lines
---
 xen/arch/x86/hvm/svm/asid.c             |   1 +
 xen/arch/x86/hvm/svm/emulate.c          |   1 +
 xen/arch/x86/hvm/svm/intr.c             |   1 +
 xen/arch/x86/hvm/svm/nestedsvm.c        |   1 +
 xen/arch/x86/hvm/svm/svm.c              |   1 +
 xen/arch/x86/hvm/svm/svmdebug.c         |   2 +
 xen/arch/x86/hvm/svm/vmcb.c             |   2 +
 xen/arch/x86/hvm/svm/vmcb.h             | 617 ++++++++++++++++++++++++
 xen/arch/x86/include/asm/hvm/svm/vmcb.h | 606 -----------------------
 9 files changed, 626 insertions(+), 606 deletions(-)
 create mode 100644 xen/arch/x86/hvm/svm/vmcb.h

I was actually hoping for the file to be moved. I notice that a few things are left in the original file, and I wonder if they couldn't be moved elsewhere up front. Yet I wouldn't insist; we can certainly do it this way round, accepting that the file name then is pretty much wrong considering what remains there.

xen/arch/x86/hvm/svm/asid.c line 12

Quoted 7 lines
xen/arch/x86/hvm/svm/asid.c +1 -0
@@ -9,6 +9,7 @@
 #include <asm/hvm/svm/svm.h>
 
 #include "svm.h"
+#include "vmcb.h"

Instead of repeating this in every .c file, couldn't svm.h include the new file? Or are you foreseeing some of the .c files requiring svm.h to (later) not need this include anymore?

Jan

#4 lore raw

Re: [PATCH 1/3] x86/svm: Make vmcb_struct private to svm/

Quoted 22 lines · Jan Beulich
Quoted 9 lines · Andrew Cooper

The rest of Xen has no buisness knowing this structure, and it is currently included via xen/sched.h into most code. Create a new private svm/vmcb.h.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

Quoted 12 lines
---
 xen/arch/x86/hvm/svm/asid.c             |   1 +
 xen/arch/x86/hvm/svm/emulate.c          |   1 +
 xen/arch/x86/hvm/svm/intr.c             |   1 +
 xen/arch/x86/hvm/svm/nestedsvm.c        |   1 +
 xen/arch/x86/hvm/svm/svm.c              |   1 +
 xen/arch/x86/hvm/svm/svmdebug.c         |   2 +
 xen/arch/x86/hvm/svm/vmcb.c             |   2 +
 xen/arch/x86/hvm/svm/vmcb.h             | 617 ++++++++++++++++++++++++
 xen/arch/x86/include/asm/hvm/svm/vmcb.h | 606 -----------------------
 9 files changed, 626 insertions(+), 606 deletions(-)
 create mode 100644 xen/arch/x86/hvm/svm/vmcb.h
Quoted 3 lines

I was actually hoping for the file to be moved. I notice that a few things are left in the original file, and I wonder if they couldn't be moved elsewhere up front.

No, they can't be moved yet.  There's other cleanup on the list, and more header dis-entangling needed first.

But I do agree the name is wrong and wants to go.

I intend to end up with svm-structs.h and svm.h only, dropping the subdir.

Quoted 10 lines

xen/arch/x86/hvm/svm/asid.c line 12

Quoted 7 lines
xen/arch/x86/hvm/svm/asid.c +1 -0
@@ -9,6 +9,7 @@
 #include <asm/hvm/svm/svm.h>
 
 #include "svm.h"
+#include "vmcb.h"

Instead of repeating this in every .c file, couldn't svm.h include the new file? Or are you foreseeing some of the .c files requiring svm.h to (later) not need this include anymore?

The other option is to merge all the current header files into one private.h first, before moving this.

~Andrew

Acked-by
#5 lore raw

Re: [PATCH 1/3] x86/svm: Make vmcb_struct private to svm/

Quoted 23 lines · Andrew Cooper
Quoted 22 lines · Jan Beulich
Quoted 21 lines · Andrew Cooper

The rest of Xen has no buisness knowing this structure, and it is currently included via xen/sched.h into most code. Create a new private svm/vmcb.h.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/hvm/svm/asid.c             |   1 +
 xen/arch/x86/hvm/svm/emulate.c          |   1 +
 xen/arch/x86/hvm/svm/intr.c             |   1 +
 xen/arch/x86/hvm/svm/nestedsvm.c        |   1 +
 xen/arch/x86/hvm/svm/svm.c              |   1 +
 xen/arch/x86/hvm/svm/svmdebug.c         |   2 +
 xen/arch/x86/hvm/svm/vmcb.c             |   2 +
 xen/arch/x86/hvm/svm/vmcb.h             | 617 ++++++++++++++++++++++++
 xen/arch/x86/include/asm/hvm/svm/vmcb.h | 606 -----------------------
 9 files changed, 626 insertions(+), 606 deletions(-)
 create mode 100644 xen/arch/x86/hvm/svm/vmcb.h
Quoted 8 lines
Quoted 3 lines

I was actually hoping for the file to be moved. I notice that a few things are left in the original file, and I wonder if they couldn't be moved elsewhere up front.

No, they can't be moved yet.  There's other cleanup on the list, and more header dis-entangling needed first.

But I do agree the name is wrong and wants to go.

Well, then let's go this route:

Jan

#6 lore raw

PATCH 2/3 x86/svm: Drop svmdebug.c

In reply to Andrew Cooper

Everything here is really VMCB functionality, so merge it into vmcb.c. Move the declarations from the global svmdebug.h to the logical vmcb.h.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/hvm/svm/Makefile               |   1 -
 xen/arch/x86/hvm/svm/nestedsvm.c            |   1 -
 xen/arch/x86/hvm/svm/svmdebug.c             | 181 --------------------
 xen/arch/x86/hvm/svm/vmcb.c                 | 159 +++++++++++++++++
 xen/arch/x86/hvm/svm/vmcb.h                 |   3 +
 xen/arch/x86/include/asm/hvm/svm/svmdebug.h |   3 -
 6 files changed, 162 insertions(+), 186 deletions(-)
 delete mode 100644 xen/arch/x86/hvm/svm/svmdebug.c
xen/arch/x86/hvm/svm/Makefile +0 -1
index 760d2954da83..8a072cafd572 100644
@@ -4,5 +4,4 @@ obj-bin-y += entry.o
 obj-y += intr.o
 obj-y += nestedsvm.o
 obj-y += svm.o
-obj-y += svmdebug.o
 obj-y += vmcb.o
xen/arch/x86/hvm/svm/nestedsvm.c +0 -1
index 191466755148..63ed6c86b775 100644
@@ -9,7 +9,6 @@
 #include <asm/hvm/svm/svm.h>
 #include <asm/hvm/svm/vmcb.h>
 #include <asm/hvm/nestedhvm.h>
-#include <asm/hvm/svm/svmdebug.h>
 #include <asm/paging.h> /* paging_mode_hap */
 #include <asm/event.h> /* for local_event_delivery_(en|dis)able */
 #include <asm/p2m.h> /* p2m_get_pagetable, p2m_get_nestedp2m */
xen/arch/x86/hvm/svm/svmdebug.c deleted +0 -181

181 lines not on this page · raw message

xen/arch/x86/hvm/svm/vmcb.c +159 -0

165 lines not on this page · raw message

xen/arch/x86/hvm/svm/vmcb.h +3 -0
index 68012948a9e3..ba554a964487 100644
@@ -553,6 +553,9 @@ int  svm_create_vmcb(struct vcpu *v);
 void svm_destroy_vmcb(struct vcpu *v);
 
 void setup_vmcb_dump(void);
+void svm_vmcb_dump(const char *from, const struct vmcb_struct *vmcb);
+bool svm_vmcb_isvalid(const char *from, const struct vmcb_struct *vmcb,
+                      const struct vcpu *v, bool verbose);
 
 /*
  * VMCB accessor functions.
xen/arch/x86/include/asm/hvm/svm/svmdebug.h +0 -3
index 2fb76ec24c76..ede13bd34048 100644
@@ -12,8 +12,5 @@
 #include <asm/hvm/svm/vmcb.h>
 
 void svm_sync_vmcb(struct vcpu *v, enum vmcb_sync_state new_state);
-void svm_vmcb_dump(const char *from, const struct vmcb_struct *vmcb);
-bool svm_vmcb_isvalid(const char *from, const struct vmcb_struct *vmcb,
-                      const struct vcpu *v, bool verbose);
 
 #endif /* __ASM_X86_HVM_SVM_SVMDEBUG_H__ */
Signature · 1 line
2.39.5
#7 lore raw

Re: [PATCH 2/3] x86/svm: Drop svmdebug.c

Hi,

Quoted 4 lines · Andrew Cooper

Everything here is really VMCB functionality, so merge it into vmcb.c. Move the declarations from the global svmdebug.h to the logical vmcb.h.

No functional change.

Not functional, but there's a single instance of style adjustment on move...

Quoted 308 lines

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/hvm/svm/Makefile               |   1 -
 xen/arch/x86/hvm/svm/nestedsvm.c            |   1 -
 xen/arch/x86/hvm/svm/svmdebug.c             | 181 --------------------
 xen/arch/x86/hvm/svm/vmcb.c                 | 159 +++++++++++++++++
 xen/arch/x86/hvm/svm/vmcb.h                 |   3 +
 xen/arch/x86/include/asm/hvm/svm/svmdebug.h |   3 -
 6 files changed, 162 insertions(+), 186 deletions(-)
 delete mode 100644 xen/arch/x86/hvm/svm/svmdebug.c
xen/arch/x86/hvm/svm/Makefile +0 -1
index 760d2954da83..8a072cafd572 100644
@@ -4,5 +4,4 @@ obj-bin-y += entry.o
 obj-y += intr.o
 obj-y += nestedsvm.o
 obj-y += svm.o
-obj-y += svmdebug.o
 obj-y += vmcb.o
xen/arch/x86/hvm/svm/nestedsvm.c +0 -1
index 191466755148..63ed6c86b775 100644
@@ -9,7 +9,6 @@
 #include <asm/hvm/svm/svm.h>
 #include <asm/hvm/svm/vmcb.h>
 #include <asm/hvm/nestedhvm.h>
-#include <asm/hvm/svm/svmdebug.h>
 #include <asm/paging.h> /* paging_mode_hap */
 #include <asm/event.h> /* for local_event_delivery_(en|dis)able */
 #include <asm/p2m.h> /* p2m_get_pagetable, p2m_get_nestedp2m */
xen/arch/x86/hvm/svm/svmdebug.c deleted +0 -181
deleted file mode 100644
index bdb9ea3583ee..000000000000
@@ -1,181 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * svmdebug.c: debug functions
- * Copyright (c) 2011, Advanced Micro Devices, Inc.
- *
- */
-
-#include <xen/sched.h>
-#include <asm/processor.h>
-#include <asm/msr-index.h>
-#include <asm/hvm/svm/svmdebug.h>
-
-#include "vmcb.h"
-
-static void svm_dump_sel(const char *name, const struct segment_register *s)
-{
-    printk("%s: %04x %04x %08x %016"PRIx64"\n",
-           name, s->sel, s->attr, s->limit, s->base);
-}
-
-void svm_vmcb_dump(const char *from, const struct vmcb_struct *vmcb)
-{
-    struct vcpu *curr = current;
-
-    /*
-     * If we are dumping the VMCB currently in context, some guest state may
-     * still be cached in hardware.  Retrieve it.
-     */
-    if ( vmcb == curr->arch.hvm.svm.vmcb )
-        svm_sync_vmcb(curr, vmcb_in_sync);
-
-    printk("Dumping guest's current state at %s...\n", from);
-    printk("Size of VMCB = %zu, paddr = %"PRIpaddr", vaddr = %p\n",
-           sizeof(struct vmcb_struct), virt_to_maddr(vmcb), vmcb);
-
-    printk("cr_intercepts = %#x dr_intercepts = %#x "
-           "exception_intercepts = %#x\n",
-           vmcb_get_cr_intercepts(vmcb), vmcb_get_dr_intercepts(vmcb),
-           vmcb_get_exception_intercepts(vmcb));
-    printk("general1_intercepts = %#x general2_intercepts = %#x\n",
-           vmcb_get_general1_intercepts(vmcb), vmcb_get_general2_intercepts(vmcb));
-    printk("iopm_base_pa = %#"PRIx64" msrpm_base_pa = %#"PRIx64" tsc_offset = %#"PRIx64"\n",
-           vmcb_get_iopm_base_pa(vmcb), vmcb_get_msrpm_base_pa(vmcb),
-           vmcb_get_tsc_offset(vmcb));
-    printk("tlb_control = %#x vintr = %#"PRIx64" int_stat = %#"PRIx64"\n",
-           vmcb->tlb_control, vmcb_get_vintr(vmcb).bytes,
-           vmcb->int_stat.raw);
-    printk("event_inj %016"PRIx64", valid? %d, ec? %d, type %u, vector %#x\n",
-           vmcb->event_inj.raw, vmcb->event_inj.v,
-           vmcb->event_inj.ev, vmcb->event_inj.type,
-           vmcb->event_inj.vector);
-    printk("exitcode = %#"PRIx64" exit_int_info = %#"PRIx64"\n",
-           vmcb->exitcode, vmcb->exit_int_info.raw);
-    printk("exitinfo1 = %#"PRIx64" exitinfo2 = %#"PRIx64"\n",
-           vmcb->exitinfo1, vmcb->exitinfo2);
-    printk("asid = %#x np_ctrl = %#"PRIx64":%s%s%s\n",
-           vmcb_get_asid(vmcb), vmcb_get_np_ctrl(vmcb),
-           vmcb_get_np(vmcb)     ? " NP"     : "",
-           vmcb_get_sev(vmcb)    ? " SEV"    : "",
-           vmcb_get_sev_es(vmcb) ? " SEV_ES" : "");
-    printk("virtual vmload/vmsave = %d, virt_ext = %#"PRIx64"\n",
-           vmcb->virt_ext.fields.vloadsave_enable, vmcb->virt_ext.bytes);
-    printk("cpl = %d efer = %#"PRIx64" star = %#"PRIx64" lstar = %#"PRIx64"\n",
-           vmcb_get_cpl(vmcb), vmcb_get_efer(vmcb), vmcb->star, vmcb->lstar);
-    printk("CR0 = 0x%016"PRIx64" CR2 = 0x%016"PRIx64"\n",
-           vmcb_get_cr0(vmcb), vmcb_get_cr2(vmcb));
-    printk("CR3 = 0x%016"PRIx64" CR4 = 0x%016"PRIx64"\n",
-           vmcb_get_cr3(vmcb), vmcb_get_cr4(vmcb));
-    printk("RSP = 0x%016"PRIx64"  RIP = 0x%016"PRIx64"\n",
-           vmcb->rsp, vmcb->rip);
-    printk("RAX = 0x%016"PRIx64"  RFLAGS=0x%016"PRIx64"\n",
-           vmcb->rax, vmcb->rflags);
-    printk("DR6 = 0x%016"PRIx64", DR7 = 0x%016"PRIx64"\n",
-           vmcb_get_dr6(vmcb), vmcb_get_dr7(vmcb));
-    printk("CSTAR = 0x%016"PRIx64" SFMask = 0x%016"PRIx64"\n",
-           vmcb->cstar, vmcb->sfmask);
-    printk("KernGSBase = 0x%016"PRIx64" PAT = 0x%016"PRIx64"\n",
-           vmcb->kerngsbase, vmcb_get_g_pat(vmcb));
-    printk("SSP = 0x%016"PRIx64" S_CET = 0x%016"PRIx64" ISST = 0x%016"PRIx64"\n",
-           vmcb->_ssp, vmcb->_msr_s_cet, vmcb->_msr_isst);
-    printk("H_CR3 = 0x%016"PRIx64" CleanBits = %#x\n",
-           vmcb_get_h_cr3(vmcb), vmcb->cleanbits.raw);
-
-    /* print out all the selectors */
-    printk("       sel attr  limit   base\n");
-    svm_dump_sel("  CS", &vmcb->cs);
-    svm_dump_sel("  DS", &vmcb->ds);
-    svm_dump_sel("  SS", &vmcb->ss);
-    svm_dump_sel("  ES", &vmcb->es);
-    svm_dump_sel("  FS", &vmcb->fs);
-    svm_dump_sel("  GS", &vmcb->gs);
-    svm_dump_sel("GDTR", &vmcb->gdtr);
-    svm_dump_sel("LDTR", &vmcb->ldtr);
-    svm_dump_sel("IDTR", &vmcb->idtr);
-    svm_dump_sel("  TR", &vmcb->tr);
-}
-
-bool svm_vmcb_isvalid(const char *from, const struct vmcb_struct *vmcb,
-                      const struct vcpu *v, bool verbose)
-{
-    bool ret = false; /* ok */
-    unsigned long cr0 = vmcb_get_cr0(vmcb);
-    unsigned long cr3 = vmcb_get_cr3(vmcb);
-    unsigned long cr4 = vmcb_get_cr4(vmcb);
-    unsigned long valid;
-    uint64_t efer = vmcb_get_efer(vmcb);
-
-#define PRINTF(fmt, args...) do { \
-    if ( !verbose ) return true; \
-    ret = true; \
-    printk(XENLOG_GUEST "%pv[%s]: " fmt, v, from, ## args); \
-} while (0)
-
-    if ( !(efer & EFER_SVME) )
-        PRINTF("EFER: SVME bit not set (%#"PRIx64")\n", efer);
-
-    if ( !(cr0 & X86_CR0_CD) && (cr0 & X86_CR0_NW) )
-        PRINTF("CR0: CD bit is zero and NW bit set (%#"PRIx64")\n", cr0);
-
-    if ( cr0 >> 32 )
-        PRINTF("CR0: bits [63:32] are not zero (%#"PRIx64")\n", cr0);
-
-    if ( (cr0 & X86_CR0_PG) &&
-         ((cr3 & 7) ||
-          ((!(cr4 & X86_CR4_PAE) || (efer & EFER_LMA)) && (cr3 & 0xfe0)) ||
-          ((efer & EFER_LMA) &&
-           (cr3 >> v->domain->arch.cpuid->extd.maxphysaddr))) )
-        PRINTF("CR3: MBZ bits are set (%#"PRIx64")\n", cr3);
-
-    valid = hvm_cr4_guest_valid_bits(v->domain);
-    if ( cr4 & ~valid )
-        PRINTF("CR4: invalid value %#lx (valid %#lx, rejected %#lx)\n",
-               cr4, valid, cr4 & ~valid);
-
-    if ( vmcb_get_dr6(vmcb) >> 32 )
-        PRINTF("DR6: bits [63:32] are not zero (%#"PRIx64")\n",
-               vmcb_get_dr6(vmcb));
-
-    if ( vmcb_get_dr7(vmcb) >> 32 )
-        PRINTF("DR7: bits [63:32] are not zero (%#"PRIx64")\n",
-               vmcb_get_dr7(vmcb));
-
-    if ( efer & ~EFER_KNOWN_MASK )
-        PRINTF("EFER: unknown bits are not zero (%#"PRIx64")\n", efer);
-
-    if ( hvm_efer_valid(v, efer, -1) )
-        PRINTF("EFER: %s (%"PRIx64")\n", hvm_efer_valid(v, efer, -1), efer);
-
-    if ( (efer & EFER_LME) && (cr0 & X86_CR0_PG) )
-    {
-        if ( !(cr4 & X86_CR4_PAE) )
-            PRINTF("EFER_LME and CR0.PG are both set and CR4.PAE is zero\n");
-        if ( !(cr0 & X86_CR0_PE) )
-            PRINTF("EFER_LME and CR0.PG are both set and CR0.PE is zero\n");
-    }
-
-    if ( (efer & EFER_LME) && (cr0 & X86_CR0_PG) && (cr4 & X86_CR4_PAE) &&
-         vmcb->cs.l && vmcb->cs.db )
-        PRINTF("EFER_LME, CR0.PG, CR4.PAE, CS.L and CS.D are all non-zero\n");
-
-    if ( !(vmcb_get_general2_intercepts(vmcb) & GENERAL2_INTERCEPT_VMRUN) )
-        PRINTF("GENERAL2_INTERCEPT: VMRUN intercept bit is clear (%#"PRIx32")\n",
-               vmcb_get_general2_intercepts(vmcb));
-
-    if ( vmcb->event_inj.resvd1 )
-        PRINTF("eventinj: MBZ bits are set (%#"PRIx64")\n",
-               vmcb->event_inj.raw);
-
-#undef PRINTF
-    return ret;
-}
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
xen/arch/x86/hvm/svm/vmcb.c +76 -0
index 44fa76bf0228..b1a79d515143 100644
@@ -228,6 +228,165 @@ void svm_destroy_vmcb(struct vcpu *v)
     svm->vmcb = NULL;
 }
 
+static void svm_dump_sel(const char *name, const struct segment_register *s)
+{
+    printk("%s: %04x %04x %08x %016"PRIx64"\n",
+           name, s->sel, s->attr, s->limit, s->base);
+}
+
+void svm_vmcb_dump(const char *from, const struct vmcb_struct *vmcb)
+{
+    struct vcpu *curr = current;
+
+    /*
+     * If we are dumping the VMCB currently in context, some guest state may
+     * still be cached in hardware.  Retrieve it.
+     */
+    if ( vmcb == curr->arch.hvm.svm.vmcb )
+        svm_sync_vmcb(curr, vmcb_in_sync);
+
+    printk("Dumping guest's current state at %s...\n", from);
+    printk("Size of VMCB = %zu, paddr = %"PRIpaddr", vaddr = %p\n",
+           sizeof(struct vmcb_struct), virt_to_maddr(vmcb), vmcb);
+
+    printk("cr_intercepts = %#x dr_intercepts = %#x "
+           "exception_intercepts = %#x\n",
+           vmcb_get_cr_intercepts(vmcb), vmcb_get_dr_intercepts(vmcb),
+           vmcb_get_exception_intercepts(vmcb));
+    printk("general1_intercepts = %#x general2_intercepts = %#x\n",
+           vmcb_get_general1_intercepts(vmcb), vmcb_get_general2_intercepts(vmcb));
+    printk("iopm_base_pa = %#"PRIx64" msrpm_base_pa = %#"PRIx64" tsc_offset = %#"PRIx64"\n",
+           vmcb_get_iopm_base_pa(vmcb), vmcb_get_msrpm_base_pa(vmcb),
+           vmcb_get_tsc_offset(vmcb));
+    printk("tlb_control = %#x vintr = %#"PRIx64" int_stat = %#"PRIx64"\n",
+           vmcb->tlb_control, vmcb_get_vintr(vmcb).bytes,
+           vmcb->int_stat.raw);
+    printk("event_inj %016"PRIx64", valid? %d, ec? %d, type %u, vector %#x\n",
+           vmcb->event_inj.raw, vmcb->event_inj.v,
+           vmcb->event_inj.ev, vmcb->event_inj.type,
+           vmcb->event_inj.vector);
+    printk("exitcode = %#"PRIx64" exit_int_info = %#"PRIx64"\n",
+           vmcb->exitcode, vmcb->exit_int_info.raw);
+    printk("exitinfo1 = %#"PRIx64" exitinfo2 = %#"PRIx64"\n",
+           vmcb->exitinfo1, vmcb->exitinfo2);
+    printk("asid = %#x np_ctrl = %#"PRIx64":%s%s%s\n",
+           vmcb_get_asid(vmcb), vmcb_get_np_ctrl(vmcb),
+           vmcb_get_np(vmcb)     ? " NP"     : "",
+           vmcb_get_sev(vmcb)    ? " SEV"    : "",
+           vmcb_get_sev_es(vmcb) ? " SEV_ES" : "");
+    printk("virtual vmload/vmsave = %d, virt_ext = %#"PRIx64"\n",
+           vmcb->virt_ext.fields.vloadsave_enable, vmcb->virt_ext.bytes);
+    printk("cpl = %d efer = %#"PRIx64" star = %#"PRIx64" lstar = %#"PRIx64"\n",
+           vmcb_get_cpl(vmcb), vmcb_get_efer(vmcb), vmcb->star, vmcb->lstar);
+    printk("CR0 = 0x%016"PRIx64" CR2 = 0x%016"PRIx64"\n",
+           vmcb_get_cr0(vmcb), vmcb_get_cr2(vmcb));
+    printk("CR3 = 0x%016"PRIx64" CR4 = 0x%016"PRIx64"\n",
+           vmcb_get_cr3(vmcb), vmcb_get_cr4(vmcb));
+    printk("RSP = 0x%016"PRIx64"  RIP = 0x%016"PRIx64"\n",
+           vmcb->rsp, vmcb->rip);
+    printk("RAX = 0x%016"PRIx64"  RFLAGS=0x%016"PRIx64"\n",
+           vmcb->rax, vmcb->rflags);
+    printk("DR6 = 0x%016"PRIx64", DR7 = 0x%016"PRIx64"\n",
+           vmcb_get_dr6(vmcb), vmcb_get_dr7(vmcb));
+    printk("CSTAR = 0x%016"PRIx64" SFMask = 0x%016"PRIx64"\n",
+           vmcb->cstar, vmcb->sfmask);
+    printk("KernGSBase = 0x%016"PRIx64" PAT = 0x%016"PRIx64"\n",
+           vmcb->kerngsbase, vmcb_get_g_pat(vmcb));
+    printk("SSP = 0x%016"PRIx64" S_CET = 0x%016"PRIx64" ISST = 0x%016"PRIx64"\n",
+           vmcb->_ssp, vmcb->_msr_s_cet, vmcb->_msr_isst);
+    printk("H_CR3 = 0x%016"PRIx64" CleanBits = %#x\n",
+           vmcb_get_h_cr3(vmcb), vmcb->cleanbits.raw);
+
+    /* print out all the selectors */
+    printk("       sel attr  limit   base\n");
+    svm_dump_sel("  CS", &vmcb->cs);
+    svm_dump_sel("  DS", &vmcb->ds);
+    svm_dump_sel("  SS", &vmcb->ss);
+    svm_dump_sel("  ES", &vmcb->es);
+    svm_dump_sel("  FS", &vmcb->fs);

xen/arch/x86/hvm/svm/vmcb.c void svm_destroy_vmcb(struct vcpu *v) · line 316

Quoted 10 lines
xen/arch/x86/hvm/svm/vmcb.c +10 -0
+    svm_dump_sel("  GS", &vmcb->gs);
+    svm_dump_sel("GDTR", &vmcb->gdtr);
+    svm_dump_sel("LDTR", &vmcb->ldtr);
+    svm_dump_sel("IDTR", &vmcb->idtr);
+    svm_dump_sel("  TR", &vmcb->tr);
+}
+
+bool svm_vmcb_isvalid(
+    const char *from, const struct vmcb_struct *vmcb, const struct vcpu *v,
+    bool verbose)

... here, which is probably unintentional. If intentional it's worth mentioning in the commit message and worth keeping in sync with the form in the prototype.

I personally prefer the former style rather than this one, FWIW.

Cheers,
Alejandro

#9 lore raw

PATCH 3/3 x86/svm: Drop svmdebug.h

In reply to Andrew Cooper

svmdebug.h now only contains the declaration for svm_sync_vmcb(), despite the function being implemented in svm.c. Move the declaration into svm.h

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/hvm/svm/svm.c                  |  1 -
 xen/arch/x86/hvm/svm/svm.h                  | 17 +++++++++++++++++
 xen/arch/x86/hvm/svm/vmcb.c                 |  2 +-
 xen/arch/x86/include/asm/hvm/svm/svmdebug.h | 16 ----------------
 xen/arch/x86/include/asm/hvm/svm/vmcb.h     | 15 ---------------
 5 files changed, 18 insertions(+), 33 deletions(-)
 delete mode 100644 xen/arch/x86/include/asm/hvm/svm/svmdebug.h
xen/arch/x86/hvm/svm/svm.c +0 -1
index 14b3a427e642..15d45cbb57c5 100644
@@ -27,7 +27,6 @@
 #include <asm/hvm/nestedhvm.h>
 #include <asm/hvm/support.h>
 #include <asm/hvm/svm/svm.h>
-#include <asm/hvm/svm/svmdebug.h>
 #include <asm/hvm/svm/vmcb.h>
 #include <asm/i387.h>
 #include <asm/idt.h>
xen/arch/x86/hvm/svm/svm.h +17 -0
index f5b0312d2dcf..cfa411ad5ae1 100644
@@ -78,6 +78,23 @@ unsigned int svm_get_task_switch_insn_len(void);
 #define _NPT_PFEC_in_gpt       33
 #define NPT_PFEC_in_gpt        (1UL<<_NPT_PFEC_in_gpt)
 
+/*
+ * VMRUN doesn't switch fs/gs/tr/ldtr and SHADOWGS/SYSCALL/SYSENTER state.
+ * Therefore, guest state is in the hardware registers when servicing a
+ * VMExit.
+ *
+ * Immediately after a VMExit, the vmcb is stale, and needs to be brought
+ * into sync by VMSAVE.  If state in the vmcb is modified, a VMLOAD is
+ * needed before the following VMRUN.
+ */
+enum vmcb_sync_state {
+    vmcb_in_sync,
+    vmcb_needs_vmsave,    /* VMCB out of sync (VMSAVE needed)? */
+    vmcb_needs_vmload,    /* VMCB dirty (VMLOAD needed)? */
+};
+
+void svm_sync_vmcb(struct vcpu *v, enum vmcb_sync_state new_state);
+
 #endif /* __X86_HVM_SVM_SVM_PRIV_H__ */
 
 /*
xen/arch/x86/hvm/svm/vmcb.c +1 -1
index b1a79d515143..7bde6e98ce03 100644
@@ -16,12 +16,12 @@
 
 #include <asm/guest-msr.h>
 #include <asm/hvm/svm/svm.h>
-#include <asm/hvm/svm/svmdebug.h>
 #include <asm/hvm/svm/vmcb.h>
 #include <asm/msr-index.h>
 #include <asm/p2m.h>
 #include <asm/spec_ctrl.h>
 
+#include "svm.h"
 #include "vmcb.h"
 
 struct vmcb_struct *alloc_vmcb(void)
xen/arch/x86/include/asm/hvm/svm/svmdebug.h deleted +0 -16
deleted file mode 100644
index ede13bd34048..000000000000
@@ -1,16 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * svmdebug.h: SVM related debug defintions
- * Copyright (c) 2011, AMD Corporation.
- *
- */
-
-#ifndef __ASM_X86_HVM_SVM_SVMDEBUG_H__
-#define __ASM_X86_HVM_SVM_SVMDEBUG_H__
-
-#include <xen/types.h>
-#include <asm/hvm/svm/vmcb.h>
-
-void svm_sync_vmcb(struct vcpu *v, enum vmcb_sync_state new_state);
-
-#endif /* __ASM_X86_HVM_SVM_SVMDEBUG_H__ */
xen/arch/x86/include/asm/hvm/svm/vmcb.h +0 -15
index 717215ff969b..41bcc9f0d862 100644
@@ -21,21 +21,6 @@ struct svm_domain {
     } osvw;
 };
 
-/*
- * VMRUN doesn't switch fs/gs/tr/ldtr and SHADOWGS/SYSCALL/SYSENTER state.
- * Therefore, guest state is in the hardware registers when servicing a
- * VMExit.
- *
- * Immediately after a VMExit, the vmcb is stale, and needs to be brought
- * into sync by VMSAVE.  If state in the vmcb is modified, a VMLOAD is
- * needed before the following VMRUN.
- */
-enum vmcb_sync_state {
-    vmcb_in_sync,
-    vmcb_needs_vmsave,    /* VMCB out of sync (VMSAVE needed)? */
-    vmcb_needs_vmload     /* VMCB dirty (VMLOAD needed)? */
-};
-
 struct svm_vcpu {
     struct vmcb_struct *vmcb;
     u64    vmcb_pa;
Signature · 1 line
2.39.5
Reviewed-by on v1 3/3
#10 lore raw

Re: [PATCH 3/3] x86/svm: Drop svmdebug.h

Quoted 41 lines · Andrew Cooper

svmdebug.h now only contains the declaration for svm_sync_vmcb(), despite the function being implemented in svm.c. Move the declaration into svm.h

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/hvm/svm/svm.c                  |  1 -
 xen/arch/x86/hvm/svm/svm.h                  | 17 +++++++++++++++++
 xen/arch/x86/hvm/svm/vmcb.c                 |  2 +-
 xen/arch/x86/include/asm/hvm/svm/svmdebug.h | 16 ----------------
 xen/arch/x86/include/asm/hvm/svm/vmcb.h     | 15 ---------------
 5 files changed, 18 insertions(+), 33 deletions(-)
 delete mode 100644 xen/arch/x86/include/asm/hvm/svm/svmdebug.h
xen/arch/x86/hvm/svm/svm.c +0 -1
index 14b3a427e642..15d45cbb57c5 100644
@@ -27,7 +27,6 @@
 #include <asm/hvm/nestedhvm.h>
 #include <asm/hvm/support.h>
 #include <asm/hvm/svm/svm.h>
-#include <asm/hvm/svm/svmdebug.h>
 #include <asm/hvm/svm/vmcb.h>
 #include <asm/i387.h>
 #include <asm/idt.h>
xen/arch/x86/hvm/svm/svm.h +3 -0
index f5b0312d2dcf..cfa411ad5ae1 100644
@@ -78,6 +78,23 @@ unsigned int svm_get_task_switch_insn_len(void);
 #define _NPT_PFEC_in_gpt       33
 #define NPT_PFEC_in_gpt        (1UL<<_NPT_PFEC_in_gpt)
 
+/*
+ * VMRUN doesn't switch fs/gs/tr/ldtr and SHADOWGS/SYSCALL/SYSENTER state.
+ * Therefore, guest state is in the hardware registers when servicing a

xen/arch/x86/hvm/svm/svm.h unsigned int svm_get_task_switch_insn_len(void); · line 93

Quoted 10 lines
xen/arch/x86/hvm/svm/svm.h +10 -0
+ * VMExit.
+ *
+ * Immediately after a VMExit, the vmcb is stale, and needs to be brought
+ * into sync by VMSAVE.  If state in the vmcb is modified, a VMLOAD is
+ * needed before the following VMRUN.
+ */
+enum vmcb_sync_state {
+    vmcb_in_sync,
+    vmcb_needs_vmsave,    /* VMCB out of sync (VMSAVE needed)? */
+    vmcb_needs_vmload,    /* VMCB dirty (VMLOAD needed)? */

extra comma on move, but this is better, IMO.

Cheers,
Alejandro

Acked-by on v1 3/3
#11 lore raw

Re: [PATCH 3/3] x86/svm: Drop svmdebug.h

In reply to Andrew Cooper
Quoted 2 lines · Andrew Cooper

svmdebug.h now only contains the declaration for svm_sync_vmcb(), despite the function being implemented in svm.c. Move the declaration into svm.h

Maybe again add "private" or "local", seeing that we have two svm.h?

Quoted 3 lines

No functional change.