Skip to contentSkip to conversation

x86/hvm: {svm,vmx} {c,h} cleanup

PATCH In review Xenia Ragiadakou 3 participants 45 messages Feb 24, 2023 – Mar 1, 2023

lore
Share & tools
lore
#0 lore raw

v3 cover x86/hvm: {svm,vmx} {c,h} cleanup

This patch series attempts a cleanup of files {svm,vmx} files and headers by removing redundant headers and sorting the rest, reducing the scope of declarations and definitions, moving functions used only by internal {svm,vmx} code to private headers, fix coding style, replace u* with uint*_t types etc.

This series aims to address the comments made on v2.

Main changes from the v2 series:
- move all internal svm/vmx declarations found in external headers into private headers
- add SPDX tags and guards to the new headers
- take the opportunity to fix coding style issues and rearrange the code per Jan's suggestion
- replace u* with uint*_t
- rebased to the latest staging

There are more detailed per-patch changesets.

Xenia Ragiadakou (14):
x86/svm: move declarations used only by svm code from svm.h to private
header
x86/svm: make asid.h private
x86/svm: delete header asm/hvm/svm/intr.h
x86/svm: make emulate.h private
x86/svm: move nestedsvm declarations used only by svm code to private
header
x86/svm: move vmcb declarations used only by svm code to private
header
x86/svm: move svmdebug.h declarations to private vmcb.h and delete it x86/vmx: move vmx_update_debug_state() in vmcs.c and declare it static x86/vmx: remove unused included headers from vmx.h x86/vmx: move declarations used only by vmx code from vmx.h to private
headers
x86/vmx: remove unused included headers from vmx.c x86/vmx: declare nvmx_enqueue_n2_exceptions() static x86/vmx: move vvmx declarations used only by vmx code to private
header
x86/vmx: move vmcs declarations used only by vmx code to private
header

 xen/arch/x86/hvm/svm/asid.c                   |   4 +-
 xen/arch/x86/hvm/svm/asid.h                   |  38 ++
 xen/arch/x86/hvm/svm/emulate.c                |   4 +-
 .../x86/{include/asm => }/hvm/svm/emulate.h   |  20 +-
 xen/arch/x86/hvm/svm/intr.c                   |   4 +-
 xen/arch/x86/hvm/svm/nestedhvm.h              |  77 +++
 xen/arch/x86/hvm/svm/nestedsvm.c              |   7 +-
 xen/arch/x86/hvm/svm/svm.c                    |  10 +-
 xen/arch/x86/hvm/svm/svm.h                    |  62 ++
 xen/arch/x86/hvm/svm/svmdebug.c               |   3 +-
 xen/arch/x86/hvm/svm/vmcb.c                   |   3 +-
 xen/arch/x86/hvm/svm/vmcb.h                   | 597 ++++++++++++++++++
 xen/arch/x86/hvm/vmx/intr.c                   |   4 +
 xen/arch/x86/hvm/vmx/pi.h                     |  78 +++
 xen/arch/x86/hvm/vmx/realmode.c               |   2 +
 xen/arch/x86/hvm/vmx/vmcs.c                   |  17 +-
 xen/arch/x86/hvm/vmx/vmcs.h                   | 100 +++
 xen/arch/x86/hvm/vmx/vmx.c                    |  76 +--
 xen/arch/x86/hvm/vmx/vmx.h                    | 416 ++++++++++++
 xen/arch/x86/hvm/vmx/vvmx.c                   |   4 +
 xen/arch/x86/hvm/vmx/vvmx.h                   | 187 ++++++
 xen/arch/x86/include/asm/hvm/svm/asid.h       |  49 --
 xen/arch/x86/include/asm/hvm/svm/intr.h       |  25 -
 xen/arch/x86/include/asm/hvm/svm/nestedsvm.h  |  53 +-
 xen/arch/x86/include/asm/hvm/svm/svm.h        |  41 --
 xen/arch/x86/include/asm/hvm/svm/svmdebug.h   |  30 -
 xen/arch/x86/include/asm/hvm/svm/vmcb.h       | 575 +----------------
 xen/arch/x86/include/asm/hvm/vmx/vmcs.h       | 118 +---
 xen/arch/x86/include/asm/hvm/vmx/vmx.h        | 453 +------------
 xen/arch/x86/include/asm/hvm/vmx/vvmx.h       | 165 +----
 30 files changed, 1685 insertions(+), 1537 deletions(-)
 create mode 100644 xen/arch/x86/hvm/svm/asid.h
 rename xen/arch/x86/{include/asm => }/hvm/svm/emulate.h (73%)
 create mode 100644 xen/arch/x86/hvm/svm/nestedhvm.h
 create mode 100644 xen/arch/x86/hvm/svm/svm.h
 create mode 100644 xen/arch/x86/hvm/svm/vmcb.h
 create mode 100644 xen/arch/x86/hvm/vmx/pi.h
 create mode 100644 xen/arch/x86/hvm/vmx/vmcs.h
 create mode 100644 xen/arch/x86/hvm/vmx/vmx.h
 create mode 100644 xen/arch/x86/hvm/vmx/vvmx.h
 delete mode 100644 xen/arch/x86/include/asm/hvm/svm/asid.h
 delete mode 100644 xen/arch/x86/include/asm/hvm/svm/intr.h
 delete mode 100644 xen/arch/x86/include/asm/hvm/svm/svmdebug.h
Signature · 1 line
2.37.2
#1 lore raw

PATCH v3 1/14 x86/svm: move declarations used only by svm code from svm.h to private header

Create a new private header in arch/x86/hvm/svm called svm.h and move there all definitions and declarations that are used solely by svm code.

Take the opportunity to remove the forward declaration of struct vcpu, that is a leftover since the removal of svm_update_guest_cr()'s declaration.

Take the opportunity to re-arrange the header as follows, all structures first, then all variable decalarations, all function delarations, and finally all inline functions.

No functional change intended.

---

Changes in v3:
- add SPDX identifier in priv header, reported by Andrew
- add #ifndef header guard, reported by Andrew and Jan
- move svm_invlpga() as well, it was not called anyway
- fold patch removing redundant forward declaration of struct vcpu into this patch, suggested by Andrew
- rearrange the header in the way Jan's proposed
- update commit message

 xen/arch/x86/hvm/svm/nestedsvm.c       |  1 +
 xen/arch/x86/hvm/svm/svm.c             |  2 +
 xen/arch/x86/hvm/svm/svm.h             | 62 ++++++++++++++++++++++++++
 xen/arch/x86/include/asm/hvm/svm/svm.h | 41 -----------------
 4 files changed, 65 insertions(+), 41 deletions(-)
 create mode 100644 xen/arch/x86/hvm/svm/svm.h
xen/arch/x86/hvm/svm/nestedsvm.c +1 -0
index 77f7547360..a341ccc876 100644
@@ -27,6 +27,7 @@
 #include <asm/event.h> /* for local_event_delivery_(en|dis)able */
 #include <asm/p2m.h> /* p2m_get_pagetable, p2m_get_nestedp2m */
 
+#include "svm.h"
 
 #define NSVM_ERROR_VVMCB        1
 #define NSVM_ERROR_VMENTRY      2
xen/arch/x86/hvm/svm/svm.c +2 -0
index 9c43227b76..6d394e4fe3 100644
@@ -55,6 +55,8 @@
 
 #include <public/sched.h>
 
+#include "svm.h"
+
 void noreturn svm_asm_do_resume(void);
 
 u32 svm_feature_flags;
xen/arch/x86/hvm/svm/svm.h new file +62 -0

62 lines not on this page · raw message

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

51 lines not on this page · raw message

Signature · 1 line
2.37.2
#2 lore raw

PATCH v3 2/14 x86/svm: make asid.h private

In reply to Xenia Ragiadakou

The asm/hvm/svm/asid.h is used only internally by the SVM code, so it can be changed into a private header.

Take the opportunity to use an SPDX tag for the licence and remove included but unused xen/types.h.

No functional change intended.

---

Changes in v3:
- new patch

 xen/arch/x86/hvm/svm/asid.c             |  3 +-
 xen/arch/x86/hvm/svm/asid.h             | 38 +++++++++++++++++++
 xen/arch/x86/hvm/svm/svm.c              |  2 +-
 xen/arch/x86/include/asm/hvm/svm/asid.h | 49 -------------------------
 4 files changed, 41 insertions(+), 51 deletions(-)
 create mode 100644 xen/arch/x86/hvm/svm/asid.h
 delete mode 100644 xen/arch/x86/include/asm/hvm/svm/asid.h
xen/arch/x86/hvm/svm/asid.c +2 -1
index ab06dd3f3a..1128434878 100644
@@ -17,9 +17,10 @@
 
 #include <asm/amd.h>
 #include <asm/hvm/nestedhvm.h>
-#include <asm/hvm/svm/asid.h>
 #include <asm/hvm/svm/svm.h>
 
+#include "asid.h"
+
 void svm_asid_init(const struct cpuinfo_x86 *c)
 {
     int nasids = 0;
xen/arch/x86/hvm/svm/asid.h new file +38 -0
new file mode 100644
index 0000000000..4dd6abb5fb
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * asid.h: handling ASIDs in SVM.
+ *
+ * Copyright (c) 2007, Advanced Micro Devices, Inc.
+ */
+
+#ifndef __X86_HVM_SVM_ASID_PRIV_H__
+#define __X86_HVM_SVM_ASID_PRIV_H__
+
+#include <asm/hvm/asid.h>
+#include <asm/processor.h>
+
+void svm_asid_init(const struct cpuinfo_x86 *c);
+void svm_asid_handle_vmrun(void);
+
+static inline void svm_asid_g_invlpg(struct vcpu *v, unsigned long g_linear)
+{
+#if 0
+    /* Optimization? */
+    svm_invlpga(g_linear, v->arch.hvm.svm.vmcb->guest_asid);
+#endif
+
+    /* Safe fallback. Take a new ASID. */
+    hvm_asid_flush_vcpu(v);
+}
+
+#endif /* __X86_HVM_SVM_ASID_PRIV_H__ */
+
+/*
+ * 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/svm.c +1 -1
index 6d394e4fe3..793a10eaca 100644
@@ -37,7 +37,6 @@
 #include <asm/hvm/monitor.h>
 #include <asm/hvm/nestedhvm.h>
 #include <asm/hvm/support.h>
-#include <asm/hvm/svm/asid.h>
 #include <asm/hvm/svm/emulate.h>
 #include <asm/hvm/svm/nestedsvm.h>
 #include <asm/hvm/svm/svm.h>
@@ -55,6 +54,7 @@
 
 #include <public/sched.h>
 
+#include "asid.h"
 #include "svm.h"
 
 void noreturn svm_asm_do_resume(void);
xen/arch/x86/include/asm/hvm/svm/asid.h deleted +0 -49

49 lines not on this page · raw message

Signature · 1 line
2.37.2
#3 lore raw

PATCH v3 2/14 x86/svm: Remove the asm/hvm/svm/asid.h header

Fold svm_asid_g_invlpg() into its single caller, deleting the #if 0 which has been present for the entire 16 years this helper has existed: c/s 322a078ab140 "[HVM][SVM] Reintroduce ASIDs."

Move the two remaining prototypes into the private svm.h, forward declaring cpuinfo_x86 in preference to including asm/processor.h

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Xenia Ragiadakou <[email protected]>

---
 xen/arch/x86/hvm/svm/asid.c             |  3 +-
 xen/arch/x86/hvm/svm/svm.c              |  4 +-
 xen/arch/x86/hvm/svm/svm.h              |  4 ++
 xen/arch/x86/include/asm/hvm/svm/asid.h | 49 -------------------------
 4 files changed, 8 insertions(+), 52 deletions(-)
 delete mode 100644 xen/arch/x86/include/asm/hvm/svm/asid.h
xen/arch/x86/hvm/svm/asid.c +2 -1
index ab06dd3f3ae2..150d8dfc8178 100644
@@ -17,9 +17,10 @@
 
 #include <asm/amd.h>
 #include <asm/hvm/nestedhvm.h>
-#include <asm/hvm/svm/asid.h>
 #include <asm/hvm/svm/svm.h>
 
+#include "svm.h"
+
 void svm_asid_init(const struct cpuinfo_x86 *c)
 {
     int nasids = 0;
xen/arch/x86/hvm/svm/svm.c +2 -2
index 6d394e4fe3bc..46ae0b6602e2 100644
@@ -37,7 +37,6 @@
 #include <asm/hvm/monitor.h>
 #include <asm/hvm/nestedhvm.h>
 #include <asm/hvm/support.h>
-#include <asm/hvm/svm/asid.h>
 #include <asm/hvm/svm/emulate.h>
 #include <asm/hvm/svm/nestedsvm.h>
 #include <asm/hvm/svm/svm.h>
@@ -2421,7 +2420,8 @@ static bool cf_check is_invlpg(
 
 static void cf_check svm_invlpg(struct vcpu *v, unsigned long linear)
 {
-    svm_asid_g_invlpg(v, linear);
+    /* Safe fallback. Take a new ASID. */
+    hvm_asid_flush_vcpu(v);
 }
 
 static bool cf_check svm_get_pending_event(
xen/arch/x86/hvm/svm/svm.h +4 -0
index f700f26f9082..b8178f62161b 100644
@@ -12,6 +12,10 @@
 #include <xen/types.h>
 
 struct cpu_user_regs;
+struct cpuinfo_x86;
+
+void svm_asid_init(const struct cpuinfo_x86 *c);
+void svm_asid_handle_vmrun(void);
 
 unsigned long *svm_msrbit(unsigned long *msr_bitmap, uint32_t msr);
 void __update_guest_eip(struct cpu_user_regs *regs, unsigned int inst_len);
xen/arch/x86/include/asm/hvm/svm/asid.h deleted +0 -49

49 lines not on this page · raw message

Signature · 1 line
2.30.2
author Reviewed-by on v3 2/14
#4 lore raw

Re: [PATCH v3 02/14 - ALT] x86/svm: Remove the asm/hvm/svm/asid.h header

Quoted 10 lines · Andrew Cooper

Fold svm_asid_g_invlpg() into its single caller, deleting the #if 0 which has been present for the entire 16 years this helper has existed: c/s 322a078ab140 "[HVM][SVM] Reintroduce ASIDs."

Move the two remaining prototypes into the private svm.h, forward declaring cpuinfo_x86 in preference to including asm/processor.h

No functional change.

#5 lore raw

PATCH v3 3/14 x86/svm: delete header asm/hvm/svm/intr.h

In reply to Xenia Ragiadakou

Delete asm/hvm/svm/intr.h because it contains only the declaration of svm_intr_assist() which is referenced only by assembly.

No functional change intended.

---

Changes in v3:
- new patch, suggested by Andrew

 xen/arch/x86/hvm/svm/intr.c             |  1 -
 xen/arch/x86/include/asm/hvm/svm/intr.h | 25 -------------------------
 2 files changed, 26 deletions(-)
 delete mode 100644 xen/arch/x86/include/asm/hvm/svm/intr.h
xen/arch/x86/hvm/svm/intr.c +0 -1
index 9525f35593..d21e930af0 100644
@@ -29,7 +29,6 @@
 #include <asm/hvm/io.h>
 #include <asm/hvm/vlapic.h>
 #include <asm/hvm/svm/svm.h>
-#include <asm/hvm/svm/intr.h>
 #include <asm/hvm/nestedhvm.h> /* for nestedhvm_vcpu_in_guestmode */
 #include <asm/vm_event.h>
 #include <xen/event.h>
xen/arch/x86/include/asm/hvm/svm/intr.h deleted +0 -25
deleted file mode 100644
index ae52d9f948..0000000000
@@ -1,25 +0,0 @@
-/*
- * intr.h: SVM Architecture related definitions
- * Copyright (c) 2005, AMD Corporation.
- * Copyright (c) 2004, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#ifndef __ASM_X86_HVM_SVM_INTR_H__
-#define __ASM_X86_HVM_SVM_INTR_H__
-
-void svm_intr_assist(void);
-
-#endif /* __ASM_X86_HVM_SVM_INTR_H__ */
Signature · 1 line
2.37.2
#6 lore raw

PATCH v3 4/14 x86/svm: make emulate.h private

In reply to Xenia Ragiadakou

The header asm/hvm/svm/emulate.h is used only internally by the SVM code, so it can be changed into a private header.

Take the opportunity to use an SPDX tag for the licence.

No functional change intended.

---

Changes in v3:
- new patch

 xen/arch/x86/hvm/svm/emulate.c                |  3 ++-
 .../x86/{include/asm => }/hvm/svm/emulate.h   | 20 +++++--------------
 xen/arch/x86/hvm/svm/nestedsvm.c              |  2 +-
 xen/arch/x86/hvm/svm/svm.c                    |  2 +-
 4 files changed, 9 insertions(+), 18 deletions(-)
 rename xen/arch/x86/{include/asm => }/hvm/svm/emulate.h (73%)
xen/arch/x86/hvm/svm/emulate.c +2 -1
index 16fc134883..4a84b4e761 100644
@@ -24,7 +24,8 @@
 #include <asm/hvm/hvm.h>
 #include <asm/hvm/svm/svm.h>
 #include <asm/hvm/svm/vmcb.h>
-#include <asm/hvm/svm/emulate.h>
+
+#include "emulate.h"
 
 static unsigned long svm_nextrip_insn_length(struct vcpu *v)
 {
xen/arch/x86/hvm/svm/emulate.h renamed from xen/arch/x86/include/asm/hvm/svm/emulate.h +5 -15
similarity index 73%
rename from xen/arch/x86/include/asm/hvm/svm/emulate.h
rename to xen/arch/x86/hvm/svm/emulate.h
index eb1a8c24af..c0d27772a5 100644
@@ -1,23 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * emulate.h: SVM instruction emulation bits.
+ *
  * Copyright (c) 2005, AMD Corporation.
  * Copyright (c) 2004, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef __ASM_X86_HVM_SVM_EMULATE_H__
-#define __ASM_X86_HVM_SVM_EMULATE_H__
+#ifndef __X86_HVM_SVM_EMULATE_PRIV_H__
+#define __X86_HVM_SVM_EMULATE_PRIV_H__
 
 /*
  * Encoding for svm_get_insn_len().  We take X86EMUL_OPC() for the main
@@ -53,7 +43,7 @@ struct vcpu;
 unsigned int svm_get_insn_len(struct vcpu *v, unsigned int instr_enc);
 unsigned int svm_get_task_switch_insn_len(void);
 
-#endif /* __ASM_X86_HVM_SVM_EMULATE_H__ */
+#endif /* __X86_HVM_SVM_EMULATE_PRIV_H__ */
 
 /*
  * Local variables:
xen/arch/x86/hvm/svm/nestedsvm.c +1 -1
index a341ccc876..5f5752ce21 100644
@@ -17,7 +17,6 @@
  */
 
 #include <asm/hvm/support.h>
-#include <asm/hvm/svm/emulate.h>
 #include <asm/hvm/svm/svm.h>
 #include <asm/hvm/svm/vmcb.h>
 #include <asm/hvm/nestedhvm.h>
@@ -27,6 +26,7 @@
 #include <asm/event.h> /* for local_event_delivery_(en|dis)able */
 #include <asm/p2m.h> /* p2m_get_pagetable, p2m_get_nestedp2m */
 
+#include "emulate.h"
 #include "svm.h"
 
 #define NSVM_ERROR_VVMCB        1
xen/arch/x86/hvm/svm/svm.c +1 -1
index 793a10eaca..c767a3eb76 100644
@@ -37,7 +37,6 @@
 #include <asm/hvm/monitor.h>
 #include <asm/hvm/nestedhvm.h>
 #include <asm/hvm/support.h>
-#include <asm/hvm/svm/emulate.h>
 #include <asm/hvm/svm/nestedsvm.h>
 #include <asm/hvm/svm/svm.h>
 #include <asm/hvm/svm/svmdebug.h>
@@ -55,6 +54,7 @@
 #include <public/sched.h>
 
 #include "asid.h"
+#include "emulate.h"
 #include "svm.h"
 
 void noreturn svm_asm_do_resume(void);
Signature · 1 line
2.37.2
#7 lore raw

Re: [PATCH v3 04/14] x86/svm: make emulate.h private

Quoted 8 lines · Xenia Ragiadakou

The header asm/hvm/svm/emulate.h is used only internally by the SVM code, so it can be changed into a private header.

Take the opportunity to use an SPDX tag for the licence.

No functional change intended.

The name emulate.h is rather stale now.  We used to have a full ad-hoc x86 emulator in emulate.{h,c}, before the work to use one single emulator (rather than the 4(?) we had at the time).

Nowadays, it's just the the instruction length helpers, which you can see are wrappers around x86_insn_length() which is the main emulator.

Given that it's now just two function declarations and a few constants for the instr_enc field, it would be better to just move them into the private svm.h (like I did the asid declarations) and remove the header entirely.

~Andrew

#8 lore raw

PATCH v3 4/14 x86/svm: Remove the asm/hvm/svm/emulate.h header

In reply to Xenia Ragiadakou

These days, this is just two length helpers. Move into the private svm.h

No functional change intended.

---
CC: Jan Beulich <[email protected]>
CC: Xenia Ragiadakou <[email protected]>

---
 xen/arch/x86/hvm/svm/emulate.c             |  3 +-
 xen/arch/x86/hvm/svm/nestedsvm.c           |  1 -
 xen/arch/x86/hvm/svm/svm.c                 |  1 -
 xen/arch/x86/hvm/svm/svm.h                 | 33 +++++++++++
 xen/arch/x86/include/asm/hvm/svm/emulate.h | 66 ----------------------
 5 files changed, 35 insertions(+), 69 deletions(-)
 delete mode 100644 xen/arch/x86/include/asm/hvm/svm/emulate.h
xen/arch/x86/hvm/svm/emulate.c +2 -1
index 16fc134883cf..391f0255162e 100644
@@ -24,7 +24,8 @@
 #include <asm/hvm/hvm.h>
 #include <asm/hvm/svm/svm.h>
 #include <asm/hvm/svm/vmcb.h>
-#include <asm/hvm/svm/emulate.h>
+
+#include "svm.h"
 
 static unsigned long svm_nextrip_insn_length(struct vcpu *v)
 {
xen/arch/x86/hvm/svm/nestedsvm.c +0 -1
index a341ccc8760e..c0b5474756f4 100644
@@ -17,7 +17,6 @@
  */
 
 #include <asm/hvm/support.h>
-#include <asm/hvm/svm/emulate.h>
 #include <asm/hvm/svm/svm.h>
 #include <asm/hvm/svm/vmcb.h>
 #include <asm/hvm/nestedhvm.h>
xen/arch/x86/hvm/svm/svm.c +0 -1
index 46ae0b6602e2..97783b7f1118 100644
@@ -37,7 +37,6 @@
 #include <asm/hvm/monitor.h>
 #include <asm/hvm/nestedhvm.h>
 #include <asm/hvm/support.h>
-#include <asm/hvm/svm/emulate.h>
 #include <asm/hvm/svm/nestedsvm.h>
 #include <asm/hvm/svm/svm.h>
 #include <asm/hvm/svm/svmdebug.h>
xen/arch/x86/hvm/svm/svm.h +33 -0
index b8178f62161b..d2a781fc3fb5 100644
@@ -13,6 +13,7 @@
 
 struct cpu_user_regs;
 struct cpuinfo_x86;
+struct vcpu;
 
 void svm_asid_init(const struct cpuinfo_x86 *c);
 void svm_asid_handle_vmrun(void);
@@ -43,6 +44,38 @@ static inline void svm_invlpga(unsigned long linear, uint32_t asid)
         "a" (linear), "c" (asid) );
 }
 
+/*
+ * Encoding for svm_get_insn_len().  We take X86EMUL_OPC() for the main
+ * opcode, shifted left to make room for the ModRM byte.
+ *
+ * The Grp7 instructions have their ModRM byte expressed in octal for easier
+ * cross referencing with the opcode extension table.
+ */
+#define INSTR_ENC(opc, modrm) (((opc) << 8) | (modrm))
+
+#define INSTR_PAUSE       INSTR_ENC(X86EMUL_OPC_F3(0, 0x90), 0)
+#define INSTR_INT3        INSTR_ENC(X86EMUL_OPC(   0, 0xcc), 0)
+#define INSTR_ICEBP       INSTR_ENC(X86EMUL_OPC(   0, 0xf1), 0)
+#define INSTR_HLT         INSTR_ENC(X86EMUL_OPC(   0, 0xf4), 0)
+#define INSTR_XSETBV      INSTR_ENC(X86EMUL_OPC(0x0f, 0x01), 0321)
+#define INSTR_VMRUN       INSTR_ENC(X86EMUL_OPC(0x0f, 0x01), 0330)
+#define INSTR_VMCALL      INSTR_ENC(X86EMUL_OPC(0x0f, 0x01), 0331)
+#define INSTR_VMLOAD      INSTR_ENC(X86EMUL_OPC(0x0f, 0x01), 0332)
+#define INSTR_VMSAVE      INSTR_ENC(X86EMUL_OPC(0x0f, 0x01), 0333)
+#define INSTR_STGI        INSTR_ENC(X86EMUL_OPC(0x0f, 0x01), 0334)
+#define INSTR_CLGI        INSTR_ENC(X86EMUL_OPC(0x0f, 0x01), 0335)
+#define INSTR_INVLPGA     INSTR_ENC(X86EMUL_OPC(0x0f, 0x01), 0337)
+#define INSTR_RDTSCP      INSTR_ENC(X86EMUL_OPC(0x0f, 0x01), 0371)
+#define INSTR_INVD        INSTR_ENC(X86EMUL_OPC(0x0f, 0x08), 0)
+#define INSTR_WBINVD      INSTR_ENC(X86EMUL_OPC(0x0f, 0x09), 0)
+#define INSTR_WRMSR       INSTR_ENC(X86EMUL_OPC(0x0f, 0x30), 0)
+#define INSTR_RDTSC       INSTR_ENC(X86EMUL_OPC(0x0f, 0x31), 0)
+#define INSTR_RDMSR       INSTR_ENC(X86EMUL_OPC(0x0f, 0x32), 0)
+#define INSTR_CPUID       INSTR_ENC(X86EMUL_OPC(0x0f, 0xa2), 0)
+
+unsigned int svm_get_insn_len(struct vcpu *v, unsigned int instr_enc);
+unsigned int svm_get_task_switch_insn_len(void);
+
 /* TSC rate */
 #define DEFAULT_TSC_RATIO       0x0000000100000000ULL
 #define TSC_RATIO_RSVD_BITS     0xffffff0000000000ULL
xen/arch/x86/include/asm/hvm/svm/emulate.h deleted +0 -66

66 lines not on this page · raw message

Signature · 1 line
2.30.2
#10 lore raw

PATCH v3 5/14 x86/svm: move nestedsvm declarations used only by svm code to private header

In reply to Xenia Ragiadakou

Create a new private header in arch/x86/hvm/svm called nestedsvm.h and move there all definitions and declarations that are used only by svm code and don't need to reside in an external header.

No functional change intended.

---

Changes in v3:
- new patch

 xen/arch/x86/hvm/svm/intr.c                  |  2 +
 xen/arch/x86/hvm/svm/nestedhvm.h             | 77 ++++++++++++++++++++
 xen/arch/x86/hvm/svm/nestedsvm.c             |  2 +-
 xen/arch/x86/hvm/svm/svm.c                   |  2 +-
 xen/arch/x86/hvm/svm/svm.h                   |  2 +-
 xen/arch/x86/include/asm/hvm/svm/nestedsvm.h | 53 +-------------
 6 files changed, 86 insertions(+), 52 deletions(-)
 create mode 100644 xen/arch/x86/hvm/svm/nestedhvm.h
xen/arch/x86/hvm/svm/intr.c +2 -0
index d21e930af0..dbb0022190 100644
@@ -37,6 +37,8 @@
 #include <xen/domain_page.h>
 #include <asm/hvm/trace.h>
 
+#include "nestedhvm.h"
+
 static void svm_inject_nmi(struct vcpu *v)
 {
     struct vmcb_struct *vmcb = v->arch.hvm.svm.vmcb;
xen/arch/x86/hvm/svm/nestedhvm.h new file +77 -0

77 lines not on this page · raw message

xen/arch/x86/hvm/svm/nestedsvm.c +1 -1
index 5f5752ce21..80b72b5dee 100644
@@ -20,13 +20,13 @@
 #include <asm/hvm/svm/svm.h>
 #include <asm/hvm/svm/vmcb.h>
 #include <asm/hvm/nestedhvm.h>
-#include <asm/hvm/svm/nestedsvm.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 */
 
 #include "emulate.h"
+#include "nestedhvm.h"
 #include "svm.h"
 
 #define NSVM_ERROR_VVMCB        1
xen/arch/x86/hvm/svm/svm.c +1 -1
index c767a3eb76..4b74ee3d7c 100644
@@ -37,7 +37,6 @@
 #include <asm/hvm/monitor.h>
 #include <asm/hvm/nestedhvm.h>
 #include <asm/hvm/support.h>
-#include <asm/hvm/svm/nestedsvm.h>
 #include <asm/hvm/svm/svm.h>
 #include <asm/hvm/svm/svmdebug.h>
 #include <asm/hvm/svm/vmcb.h>
@@ -55,6 +54,7 @@
 
 #include "asid.h"
 #include "emulate.h"
+#include "nestedhvm.h"
 #include "svm.h"
 
 void noreturn svm_asm_do_resume(void);
xen/arch/x86/hvm/svm/svm.h +1 -1
index 9e65919757..f700f26f90 100644
@@ -36,7 +36,7 @@ static inline void svm_invlpga(unsigned long linear, uint32_t asid)
         ".byte 0x0f,0x01,0xdf"
         : /* output */
         : /* input */
-        "a" (linear), "c" (asid));
+        "a" (linear), "c" (asid) );
 }
 
 /* TSC rate */
xen/arch/x86/include/asm/hvm/svm/nestedsvm.h +4 -49

74 lines not on this page · raw message

Signature · 1 line
2.37.2
#11 lore raw

Re: [PATCH v3 05/14] x86/svm: move nestedsvm declarations used only by svm code to private header

Quoted 17 lines · Xenia Ragiadakou
xen/arch/x86/hvm/svm/nestedhvm.h new file +11 -0
new file mode 100644
index 0000000000..43245e13de
@@ -0,0 +1,77 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * nestedsvm.h: Nested Virtualization
+ *
+ * Copyright (c) 2011, Advanced Micro Devices, Inc
+ */
+
+#ifndef __X86_HVM_SVM_NESTEDHVM_PRIV_H__
+#define __X86_HVM_SVM_NESTEDHVM_PRIV_H__
+
+#include <xen/mm.h>

xen/arch/x86/hvm/svm/nestedhvm.h line 21

Quoted 10 lines
xen/arch/x86/hvm/svm/nestedhvm.h new file +10 -0
+#include <xen/types.h>
+
+#include <asm/hvm/vcpu.h>
+#include <asm/hvm/hvm.h>
+#include <asm/hvm/nestedhvm.h>
+#include <asm/msr-index.h>
+
+/* SVM specific intblk types, cannot be an enum because gcc 4.5 complains */
+/* GIF cleared */
+#define hvm_intblk_svm_gif      hvm_intblk_arch

I know you're just moving code, but I simply don't believe this comment.

This additional delta seems to compile fine:

xen/arch/x86/hvm/svm/intr.c +0 -0
index dbb0022190a8..111b10673cf4 100644
@@ -154,7 +154,7 @@ void svm_intr_assist(void)

             return;

         intblk = hvm_interrupt_blocked(v, intack); -        if ( intblk == hvm_intblk_svm_gif ) +        if ( intblk == hvm_intblk_arch ) /* GIF */ { ASSERT(nestedhvm_enabled(v->domain)); return;

(quoted diff) +0 -0

b/xen/arch/x86/hvm/svm/nestedhvm.h
index 43245e13deb7..c7747daae24a 100644

xen/arch/x86/hvm/svm/nestedhvm.h +0 -0
@@ -16,10 +16,6 @@

 #include <asm/hvm/nestedhvm.h>
 #include <asm/msr-index.h>

-/* SVM specific intblk types, cannot be an enum because gcc 4.5 complains */
-/* GIF cleared */
-#define hvm_intblk_svm_gif      hvm_intblk_arch
-
 #define vcpu_nestedsvm(v) (vcpu_nestedhvm(v).u.nsvm)

 /* True when l1 guest enabled SVM in EFER */

(quoted diff) +0 -0

b/xen/arch/x86/hvm/svm/nestedsvm.c
index 92316c6624ce..1794eb2105be 100644

xen/arch/x86/hvm/svm/nestedsvm.c +0 -0
@@ -1247,7 +1247,7 @@ enum hvm_intblk cf_check nsvm_intr_blocked(struct

vcpu *v)
     ASSERT(nestedhvm_enabled(v->domain));

     if ( !nestedsvm_gif_isset(v) )
-        return hvm_intblk_svm_gif;
+        return hvm_intblk_arch;

     if ( nestedhvm_vcpu_in_guestmode(v) )
     {

but the first hunk demonstrates an error in the original logic. Architecturally, GIF can become set for SKINIT, and in systems where SVM isn't available.

I'm unsure whether its better to fix this up in this patch, or defer it for later.

xen/arch/x86/hvm/svm/nestedhvm.h line 27

Quoted 6 lines
xen/arch/x86/hvm/svm/nestedhvm.h new file +6 -0
+
+#define vcpu_nestedsvm(v) (vcpu_nestedhvm(v).u.nsvm)
+
+/* True when l1 guest enabled SVM in EFER */
+#define nsvm_efer_svm_enabled(v) \
+    (!!((v)->arch.hvm.guest_efer & EFER_SVME))

This seems to be the only use of asm/msr-index.h, and it's a macro so the header is actually unused.

I'd drop the include - its a very common header anyway.

~Andrew

#12 lore raw

Re: [PATCH v3 05/14] x86/svm: move nestedsvm declarations used only by svm code to private header

Quoted 80 lines · Andrew Cooper
Quoted 17 lines · Xenia Ragiadakou
xen/arch/x86/hvm/svm/nestedhvm.h new file +11 -0
new file mode 100644
index 0000000000..43245e13de
@@ -0,0 +1,77 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * nestedsvm.h: Nested Virtualization
+ *
+ * Copyright (c) 2011, Advanced Micro Devices, Inc
+ */
+
+#ifndef __X86_HVM_SVM_NESTEDHVM_PRIV_H__
+#define __X86_HVM_SVM_NESTEDHVM_PRIV_H__
+
+#include <xen/mm.h>

xen/arch/x86/hvm/svm/nestedhvm.h line 21

Quoted 10 lines
xen/arch/x86/hvm/svm/nestedhvm.h new file +10 -0
+#include <xen/types.h>
+
+#include <asm/hvm/vcpu.h>
+#include <asm/hvm/hvm.h>
+#include <asm/hvm/nestedhvm.h>
+#include <asm/msr-index.h>
+
+/* SVM specific intblk types, cannot be an enum because gcc 4.5 complains */
+/* GIF cleared */
+#define hvm_intblk_svm_gif      hvm_intblk_arch

I know you're just moving code, but I simply don't believe this comment.

This additional delta seems to compile fine:

xen/arch/x86/hvm/svm/intr.c +1 -1
index dbb0022190a8..111b10673cf4 100644
@@ -154,7 +154,7 @@ void svm_intr_assist(void)
              return;
 
          intblk = hvm_interrupt_blocked(v, intack);
-        if ( intblk == hvm_intblk_svm_gif )
+        if ( intblk == hvm_intblk_arch ) /* GIF */
          {
              ASSERT(nestedhvm_enabled(v->domain));
              return;
xen/arch/x86/hvm/svm/nestedhvm.h +0 -1
index 43245e13deb7..c7747daae24a 100644
@@ -16,10 +16,6 @@
  #include <asm/hvm/nestedhvm.h>
  #include <asm/msr-index.h>
 
-/* SVM specific intblk types, cannot be an enum because gcc 4.5

complains */

xen/arch/x86/hvm/svm/nestedhvm.h +0 -3
-/* GIF cleared */
-#define hvm_intblk_svm_gif      hvm_intblk_arch
-
  #define vcpu_nestedsvm(v) (vcpu_nestedhvm(v).u.nsvm)
 
  /* True when l1 guest enabled SVM in EFER */
xen/arch/x86/hvm/svm/nestedsvm.c +1 -1
index 92316c6624ce..1794eb2105be 100644
@@ -1247,7 +1247,7 @@ enum hvm_intblk cf_check nsvm_intr_blocked(struct
 vcpu *v)
      ASSERT(nestedhvm_enabled(v->domain));
 
      if ( !nestedsvm_gif_isset(v) )
-        return hvm_intblk_svm_gif;
+        return hvm_intblk_arch;
 
      if ( nestedhvm_vcpu_in_guestmode(v) )

     {

Quoted 6 lines

but the first hunk demonstrates an error in the original logic. Architecturally, GIF can become set for SKINIT, and in systems where SVM isn't available.

I'm unsure whether its better to fix this up in this patch, or defer it for later.

I think this change merits its own patch.

Quoted 11 lines

xen/arch/x86/hvm/svm/nestedhvm.h line 27

Quoted 7 lines
xen/arch/x86/hvm/svm/nestedhvm.h new file +6 -0
+
+#define vcpu_nestedsvm(v) (vcpu_nestedhvm(v).u.nsvm)
+
+/* True when l1 guest enabled SVM in EFER */
+#define nsvm_efer_svm_enabled(v) \
+    (!!((v)->arch.hvm.guest_efer & EFER_SVME))

This seems to be the only use of asm/msr-index.h, and it's a macro so the header is actually unused.

Quoted 1 line

I'd drop the include - its a very common header anyway.

Feel free to drop it. There was not in the other header. I have a tendency to include headers for everything.

Quoted 2 lines

~Andrew

Signature · 1 line
Xenia
#13 lore raw

Re: [PATCH v3 05/14] x86/svm: move nestedsvm declarations used only by svm code to private header

Quoted 79 lines · Xenia Ragiadakou
Quoted 77 lines · Andrew Cooper
Quoted 27 lines · Xenia Ragiadakou
xen/arch/x86/hvm/svm/nestedhvm.h new file +19 -0
new file mode 100644
index 0000000000..43245e13de
@@ -0,0 +1,77 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * nestedsvm.h: Nested Virtualization
+ *
+ * Copyright (c) 2011, Advanced Micro Devices, Inc
+ */
+
+#ifndef __X86_HVM_SVM_NESTEDHVM_PRIV_H__
+#define __X86_HVM_SVM_NESTEDHVM_PRIV_H__
+
+#include <xen/mm.h>
+#include <xen/types.h>
+
+#include <asm/hvm/vcpu.h>
+#include <asm/hvm/hvm.h>
+#include <asm/hvm/nestedhvm.h>
+#include <asm/msr-index.h>
+
+/* SVM specific intblk types, cannot be an enum because gcc 4.5

complains */

xen/arch/x86/hvm/svm/nestedhvm.h

Quoted 2 lines
xen/arch/x86/hvm/svm/nestedhvm.h new file +2 -0
+/* GIF cleared */
+#define hvm_intblk_svm_gif      hvm_intblk_arch

I know you're just moving code, but I simply don't believe this comment.

This additional delta seems to compile fine:

xen/arch/x86/hvm/svm/intr.c +1 -1
index dbb0022190a8..111b10673cf4 100644
@@ -154,7 +154,7 @@ void svm_intr_assist(void)
               return;
             intblk = hvm_interrupt_blocked(v, intack);
-        if ( intblk == hvm_intblk_svm_gif )
+        if ( intblk == hvm_intblk_arch ) /* GIF */
           {
               ASSERT(nestedhvm_enabled(v->domain));
               return;
xen/arch/x86/hvm/svm/nestedhvm.h +0 -0
index 43245e13deb7..c7747daae24a 100644
@@ -16,10 +16,6 @@
   #include <asm/hvm/nestedhvm.h>
   #include <asm/msr-index.h>

  -/* SVM specific intblk types, cannot be an enum because gcc 4.5 complains */

xen/arch/x86/hvm/svm/nestedhvm.h +0 -3
-/* GIF cleared */
-#define hvm_intblk_svm_gif      hvm_intblk_arch
-

  #define vcpu_nestedsvm(v) (vcpu_nestedhvm(v).u.nsvm) /* True when l1 guest enabled SVM in EFER */

xen/arch/x86/hvm/svm/nestedsvm.c +1 -1
index 92316c6624ce..1794eb2105be 100644
@@ -1247,7 +1247,7 @@ enum hvm_intblk cf_check nsvm_intr_blocked(struct
 vcpu *v)
       ASSERT(nestedhvm_enabled(v->domain));
         if ( !nestedsvm_gif_isset(v) )
-        return hvm_intblk_svm_gif;
+        return hvm_intblk_arch;
         if ( nestedhvm_vcpu_in_guestmode(v) )
       {
 
Quoted 8 lines
Quoted 6 lines

but the first hunk demonstrates an error in the original logic. Architecturally, GIF can become set for SKINIT, and in systems where SVM isn't available.

I'm unsure whether its better to fix this up in this patch, or defer it for later.

I think this change merits its own patch.

Yeah, it probably does.

Seeing as you've reviewed my two alt patches, I'll commit some more as I've already resolved the conflicts around adjacent headers.

~Andrew

#14 lore raw

PATCH v3 1/1 x86/svm: Decouple types in struct nestedsvm

In reply to Xenia Ragiadakou

struct nestedvm uses mostly plain integer types, except for virt_ext_t which is a union wrapping two bitfield names. But the nested virt logic only ever deals with it as full opaque register.

Switch it to being a plain uint64_t, allowing us to hide even more of the SVM internal infrastructure.

---
CC: Jan Beulich <[email protected]>
CC: Xenia Ragiadakou <[email protected]>

This allows virt_ext_t to move out of the public vmcb.h along with all other vmcb types.

---
 xen/arch/x86/hvm/svm/nestedsvm.c             | 4 ++--
 xen/arch/x86/include/asm/hvm/svm/nestedsvm.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/svm/nestedsvm.c +2 -2
index 92316c6624ce..153a37f2f227 100644
@@ -164,7 +164,7 @@ int cf_check nsvm_vcpu_reset(struct vcpu *v)
     svm->ns_exception_intercepts = 0;
     svm->ns_general1_intercepts = 0;
     svm->ns_general2_intercepts = 0;
-    svm->ns_virt_ext.bytes = 0;
+    svm->ns_virt_ext = 0;
 
     svm->ns_hap_enabled = 0;
     svm->ns_vmcb_guestcr3 = 0;
@@ -526,7 +526,7 @@ static int nsvm_vmcb_prepare4vmrun(struct vcpu *v, struct cpu_user_regs *regs)
 
     /* LBR and other virtualization */
     if ( !clean.lbr )
-        svm->ns_virt_ext = ns_vmcb->virt_ext;
+        svm->ns_virt_ext = ns_vmcb->virt_ext.bytes;
 
     n2vmcb->virt_ext.bytes =
         n1vmcb->virt_ext.bytes | ns_vmcb->virt_ext.bytes;
xen/arch/x86/include/asm/hvm/svm/nestedsvm.h +1 -1
index 94d45d2e8d47..184248bbd7c5 100644
@@ -44,7 +44,7 @@ struct nestedsvm {
     uint32_t ns_general2_intercepts;
 
     /* Cached real lbr and other virtual extentions of the l2 guest */
-    virt_ext_t ns_virt_ext;
+    uint64_t ns_virt_ext;
 
     /* Cached real MSR permission bitmaps of the l2 guest */
     unsigned long *ns_cached_msrpm;
Signature · 1 line
2.30.2
author Reviewed-by on v3 1/1
#15 lore raw

Re: [PATCH v3 05.5/14] x86/svm: Decouple types in struct nestedsvm

Quoted 8 lines · Andrew Cooper

struct nestedvm uses mostly plain integer types, except for virt_ext_t which is a union wrapping two bitfield names. But the nested virt logic only ever deals with it as full opaque register.

Switch it to being a plain uint64_t, allowing us to hide even more of the SVM internal infrastructure.

Signature · 1 line
Xenia
#16 lore raw

Re: [PATCH v3 05.5/14] x86/svm: Decouple types in struct nestedsvm

Quoted 8 lines · Xenia Ragiadakou
Quoted 6 lines · Andrew Cooper

struct nestedvm uses mostly plain integer types, except for virt_ext_t which
is a union wrapping two bitfield names.  But the nested virt logic only ever
deals with it as full opaque register.

Quoted 8 lines
Quoted 5 lines

Switch it to being a plain uint64_t, allowing us to hide even more of the SVM
internal infrastructure.

On second thoughts, the fact that this patch compiles means its a write-only variable.

Lemme experiment quickly with an alternate patch.

~Andrew

#17 lore raw

PATCH v3 6/14 x86/svm: move vmcb declarations used only by svm code to private header

In reply to Xenia Ragiadakou

Create a new private header in arch/x86/hvm/svm called vmcb.h and move there all definitions and declarations that are used only by svm code and don't need to reside in an external header.

Take the opportunity to replace u* with uint*_t and remove redundant blank lines.

No functional change intended.

---

Changes in v3:
- new patch

 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             | 591 ++++++++++++++++++++++++
 xen/arch/x86/include/asm/hvm/svm/vmcb.h | 575 +----------------------
 9 files changed, 604 insertions(+), 571 deletions(-)
 create mode 100644 xen/arch/x86/hvm/svm/vmcb.h
xen/arch/x86/hvm/svm/asid.c +1 -0
index 1128434878..05ba2df9d5 100644
@@ -20,6 +20,7 @@
 #include <asm/hvm/svm/svm.h>
 
 #include "asid.h"
+#include "vmcb.h"
 
 void svm_asid_init(const struct cpuinfo_x86 *c)
 {
xen/arch/x86/hvm/svm/emulate.c +1 -0
index 4a84b4e761..573d005127 100644
@@ -26,6 +26,7 @@
 #include <asm/hvm/svm/vmcb.h>
 
 #include "emulate.h"
+#include "vmcb.h"
 
 static unsigned long svm_nextrip_insn_length(struct vcpu *v)
 {
xen/arch/x86/hvm/svm/intr.c +1 -0
index dbb0022190..2655c5b4c8 100644
@@ -38,6 +38,7 @@
 #include <asm/hvm/trace.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 80b72b5dee..efbd9bbb77 100644
@@ -28,6 +28,7 @@
 #include "emulate.h"
 #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 4b74ee3d7c..86b1bf3242 100644
@@ -56,6 +56,7 @@
 #include "emulate.h"
 #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 bce86f0ef7..ade74dfd8f 100644
@@ -21,6 +21,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 ba93375e87..1d512fedb0 100644
@@ -30,6 +30,8 @@
 #include <asm/hvm/svm/svmdebug.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 +591 -0

591 lines not on this page · raw message

xen/arch/x86/include/asm/hvm/svm/vmcb.h +4 -571

606 lines not on this page · raw message

Signature · 1 line
2.37.2
#18 lore raw

PATCH v3 7/14 x86/svm: move svmdebug.h declarations to private vmcb.h and delete it

In reply to Xenia Ragiadakou

Move the declarations in svmdebug.h to private vmcb.h because are vmcb specific and are used only by internal svm code, and delete svmdebug.h.

No functional change intended.

---

Changes in v3:
- new patch, suggested by Andrew

 xen/arch/x86/hvm/svm/nestedsvm.c            |  1 -
 xen/arch/x86/hvm/svm/svm.c                  |  1 -
 xen/arch/x86/hvm/svm/svmdebug.c             |  1 -
 xen/arch/x86/hvm/svm/vmcb.c                 |  1 -
 xen/arch/x86/hvm/svm/vmcb.h                 |  6 +++++
 xen/arch/x86/include/asm/hvm/svm/svmdebug.h | 30 ---------------------
 6 files changed, 6 insertions(+), 34 deletions(-)
 delete mode 100644 xen/arch/x86/include/asm/hvm/svm/svmdebug.h
xen/arch/x86/hvm/svm/nestedsvm.c +0 -1
index efbd9bbb77..201da7d531 100644
@@ -20,7 +20,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/svm.c +0 -1
index 86b1bf3242..0a1b447e36 100644
@@ -38,7 +38,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/hvm/trace.h>
 #include <asm/iocap.h>
xen/arch/x86/hvm/svm/svmdebug.c +0 -1
index ade74dfd8f..7fd0753116 100644
@@ -19,7 +19,6 @@
 #include <xen/sched.h>
 #include <asm/processor.h>
 #include <asm/msr-index.h>
-#include <asm/hvm/svm/svmdebug.h>
 
 #include "vmcb.h"
 
xen/arch/x86/hvm/svm/vmcb.c +0 -1
index 1d512fedb0..657b4b1670 100644
@@ -27,7 +27,6 @@
 #include <asm/msr-index.h>
 #include <asm/p2m.h>
 #include <asm/hvm/svm/svm.h>
-#include <asm/hvm/svm/svmdebug.h>
 #include <asm/spec_ctrl.h>
 
 #include "vmcb.h"
xen/arch/x86/hvm/svm/vmcb.h +6 -0
index c58625fd80..80143164e5 100644
@@ -11,6 +11,7 @@
 
 #include <xen/types.h>
 
+#include <asm/hvm/svm/vmcb.h>
 #include <asm/x86_emulate.h>
 
 /* general 1 intercepts */
@@ -518,6 +519,11 @@ void svm_destroy_vmcb(struct vcpu *v);
 
 void setup_vmcb_dump(void);
 
+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);
+
 /*
  * VMCB accessor functions.
  */
xen/arch/x86/include/asm/hvm/svm/svmdebug.h deleted +0 -30
deleted file mode 100644
index 330c1d91aa..0000000000
@@ -1,30 +0,0 @@
-/*
- * svmdebug.h: SVM related debug defintions
- * Copyright (c) 2011, AMD Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#ifndef __ASM_X86_HVM_SVM_SVMDEBUG_H__
-#define __ASM_X86_HVM_SVM_SVMDEBUG_H__
-
-#include <asm/types.h>
-#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.37.2
#19 lore raw

PATCH v3 8/14 x86/vmx: move vmx_update_debug_state() in vmcs.c and declare it static

In reply to Xenia Ragiadakou

Move vmx_update_debug_state() in vmcs.c because it is used only in this file and limit its scope to this file by declaring it static and removing its declaration from vmx.h.

No functional change intended.

---

Changes in v3:
- apply the change before moving the declarations into private headers to avoid churn, suggested by Jan

 xen/arch/x86/hvm/vmx/vmcs.c            | 12 ++++++++++++
 xen/arch/x86/hvm/vmx/vmx.c             | 12 ------------
 xen/arch/x86/include/asm/hvm/vmx/vmx.h |  1 -
 3 files changed, 12 insertions(+), 13 deletions(-)
xen/arch/x86/hvm/vmx/vmcs.c +12 -0
index ed71ecfb62..d3c75b3803 100644
@@ -1868,6 +1868,18 @@ void vmx_vmentry_failure(void)
 
 void noreturn vmx_asm_do_vmentry(void);
 
+static void vmx_update_debug_state(struct vcpu *v)
+{
+    if ( v->arch.hvm.debug_state_latch )
+        v->arch.hvm.vmx.exception_bitmap |= 1U << TRAP_int3;
+    else
+        v->arch.hvm.vmx.exception_bitmap &= ~(1U << TRAP_int3);
+
+    vmx_vmcs_enter(v);
+    vmx_update_exception_bitmap(v);
+    vmx_vmcs_exit(v);
+}
+
 void cf_check vmx_do_resume(void)
 {
     struct vcpu *v = current;
xen/arch/x86/hvm/vmx/vmx.c +0 -12
index 0ec33bcc18..294c8490b4 100644
@@ -1613,18 +1613,6 @@ static void cf_check vmx_update_host_cr3(struct vcpu *v)
     vmx_vmcs_exit(v);
 }
 
-void vmx_update_debug_state(struct vcpu *v)
-{
-    if ( v->arch.hvm.debug_state_latch )
-        v->arch.hvm.vmx.exception_bitmap |= 1U << TRAP_int3;
-    else
-        v->arch.hvm.vmx.exception_bitmap &= ~(1U << TRAP_int3);
-
-    vmx_vmcs_enter(v);
-    vmx_update_exception_bitmap(v);
-    vmx_vmcs_exit(v);
-}
-
 static void cf_check vmx_update_guest_cr(
     struct vcpu *v, unsigned int cr, unsigned int flags)
 {
xen/arch/x86/include/asm/hvm/vmx/vmx.h +0 -1
index f6308ed656..82a9487b40 100644
@@ -88,7 +88,6 @@ void cf_check vmx_vlapic_msr_changed(struct vcpu *v);
 struct hvm_emulate_ctxt;
 void vmx_realmode_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt);
 void vmx_realmode(struct cpu_user_regs *regs);
-void vmx_update_debug_state(struct vcpu *v);
 void vmx_update_exception_bitmap(struct vcpu *v);
 void vmx_update_cpu_exec_control(struct vcpu *v);
 void vmx_update_secondary_exec_control(struct vcpu *v);
Signature · 1 line
2.37.2
Acked-by on v3 8/14
#20 lore raw

Re: [PATCH v3 08/14] x86/vmx: move vmx_update_debug_state() in vmcs.c and declare it static

Quoted 7 lines · Xenia Ragiadakou

Move vmx_update_debug_state() in vmcs.c because it is used only in this file and limit its scope to this file by declaring it static and removing its declaration from vmx.h.

No functional change intended.

#21 lore raw

PATCH v3 9/14 x86/vmx: remove unused included headers from vmx.h

In reply to Xenia Ragiadakou

Do not include the headers:
asm/i387.h
asm/hvm/trace.h
asm/processor.h
asm/regs.h
because none of the declarations and macro definitions in them is used in this file. Sort the rest of the headers alphabetically. Include asm/i387.h in vmx.c, needed for vcpu_restore_fpu_lazy().

Take the opportunity to include xen/types.h in the place of asm/types.h and replace u* with uint*_t and bool_t with bool.

No functional change intended.

---

Changes in v3:
- reword the commit message to not look like a bug fix, reported by JAn
- include xen/types.h instead of asm/types.h and use uint*_t instead of u*, suggested by Jan

 xen/arch/x86/hvm/vmx/vmx.c             |  1 +
 xen/arch/x86/include/asm/hvm/vmx/vmx.h | 15 ++++++---------
 2 files changed, 7 insertions(+), 9 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +1 -0
index 294c8490b4..232107bd79 100644
@@ -43,6 +43,7 @@
 #include <asm/hvm/vmx/vmcs.h>
 #include <public/sched.h>
 #include <public/hvm/ioreq.h>
+#include <asm/i387.h>
 #include <asm/hvm/vpic.h>
 #include <asm/hvm/vlapic.h>
 #include <asm/x86_emulate.h>
xen/arch/x86/include/asm/hvm/vmx/vmx.h +6 -9
index 82a9487b40..f5720c393c 100644
@@ -19,20 +19,17 @@
 #define __ASM_X86_HVM_VMX_VMX_H__
 
 #include <xen/sched.h>
-#include <asm/types.h>
-#include <asm/regs.h>
+#include <xen/types.h>
+
 #include <asm/asm_defns.h>
-#include <asm/processor.h>
-#include <asm/p2m.h>
-#include <asm/i387.h>
-#include <asm/hvm/trace.h>
 #include <asm/hvm/vmx/vmcs.h>
+#include <asm/p2m.h>
 
 extern int8_t opt_ept_exec_sp;
 
 typedef union {
     struct {
-        u64 r       :   1,  /* bit 0 - Read permission */
+        uint64_t r  :   1,  /* bit 0 - Read permission */
         w           :   1,  /* bit 1 - Write permission */
         x           :   1,  /* bit 2 - Execute permission */
         emt         :   3,  /* bits 5:3 - EPT Memory type */
@@ -49,7 +46,7 @@ typedef union {
         _rsvd       :   1,  /* bit 62 - reserved */
         suppress_ve :   1;  /* bit 63 - suppress #VE */
     };
-    u64 epte;
+    uint64_t epte;
 } ept_entry_t;
 
 typedef struct {
@@ -595,7 +592,7 @@ void vmx_inject_extint(int trap, uint8_t source);
 void vmx_inject_nmi(void);
 
 void ept_walk_table(struct domain *d, unsigned long gfn);
-bool_t ept_handle_misconfig(uint64_t gpa);
+bool ept_handle_misconfig(uint64_t gpa);
 int epte_get_entry_emt(struct domain *d, gfn_t gfn, mfn_t mfn,
                        unsigned int order, bool *ipat, p2m_type_t type);
 void setup_ept_dump(void);
Signature · 1 line
2.37.2
#22 lore raw

PATCH v3 10/14 x86/vmx: move declarations used only by vmx code from vmx.h to private headers

In reply to Xenia Ragiadakou

Create two new private headers in arch/x86/hvm/vmx called vmx.h and pi.h. Move all the definitions and declarations that are used solely by vmx code into the private vmx.h, apart from the ones related to posted interrupts that are moved into pi.h.

EPT related declarations and definitions stay in asm/hvm/vmx/vmx.h because they are used in arch/x86/mm and drivers/passthrough/vtd.

Also, __vmread(), used in arch/x86/cpu, and consequently the opcodes stay in asm/hvm/vmx/vmx.h.

Take the opportunity during the movement to replace u* with uint*_t, fix minor coding style issues and reduce scope of GAS_VMX_OP definition. Also, rearrange the code in the following way, place all structures first, then all variable decalarations, all function delarations, and finally all inline functions.

No functional change intended.

---

Changes in v3:
- add SPDX identifier, reported by Andrew
- add #ifndef header guard, reported by Andrew and Jan
- fold patch reducing the scope of GAS_VMX_OP definition into this, suggested by Jan
- put pi related declarations in a separate priv header, suggested by Jan
- perform minor coding style fixes pointed out by Jan
- replace u* with uint*_t, suggested by Jan
- rearrange the header in the way Jan's proposed
- rebase to the latest staging

 xen/arch/x86/hvm/vmx/intr.c            |   2 +
 xen/arch/x86/hvm/vmx/pi.h              |  78 +++++
 xen/arch/x86/hvm/vmx/realmode.c        |   2 +
 xen/arch/x86/hvm/vmx/vmcs.c            |   2 +
 xen/arch/x86/hvm/vmx/vmx.c             |   3 +
 xen/arch/x86/hvm/vmx/vmx.h             | 416 +++++++++++++++++++++++
 xen/arch/x86/hvm/vmx/vvmx.c            |   2 +
 xen/arch/x86/include/asm/hvm/vmx/vmx.h | 439 -------------------------
 8 files changed, 505 insertions(+), 439 deletions(-)
 create mode 100644 xen/arch/x86/hvm/vmx/pi.h
 create mode 100644 xen/arch/x86/hvm/vmx/vmx.h
xen/arch/x86/hvm/vmx/intr.c +2 -0
index 6a8316de0e..c8db501759 100644
@@ -38,6 +38,8 @@
 #include <asm/hvm/trace.h>
 #include <asm/vm_event.h>
 
+#include "vmx.h"
+
 /*
  * A few notes on virtual NMI and INTR delivery, and interactions with
  * interruptibility states:
xen/arch/x86/hvm/vmx/pi.h new file +78 -0

78 lines not on this page · raw message

xen/arch/x86/hvm/vmx/realmode.c +2 -0
index 4ac93e0810..5591660230 100644
@@ -23,6 +23,8 @@
 #include <asm/hvm/vmx/vmx.h>
 #include <asm/hvm/vmx/vmcs.h>
 
+#include "vmx.h"
+
 static void realmode_deliver_exception(
     unsigned int vector,
     unsigned int insn_len,
xen/arch/x86/hvm/vmx/vmcs.c +2 -0
index d3c75b3803..4eb2571abb 100644
@@ -43,6 +43,8 @@
 #include <asm/tboot.h>
 #include <asm/apic.h>
 
+#include "vmx.h"
+
 static bool_t __read_mostly opt_vpid_enabled = 1;
 boolean_param("vpid", opt_vpid_enabled);
 
xen/arch/x86/hvm/vmx/vmx.c +3 -0
index 232107bd79..cb8b133ed5 100644
@@ -62,6 +62,9 @@
 #include <asm/prot-key.h>
 #include <public/arch-x86/cpuid.h>
 
+#include "pi.h"
+#include "vmx.h"
+
 static bool_t __initdata opt_force_ept;
 boolean_param("force-ept", opt_force_ept);
 
xen/arch/x86/hvm/vmx/vmx.h new file +416 -0

416 lines not on this page · raw message

xen/arch/x86/hvm/vmx/vvmx.c +2 -0
index 674cdabb07..0bda8430b9 100644
@@ -29,6 +29,8 @@
 #include <asm/hvm/vmx/vvmx.h>
 #include <asm/hvm/nestedhvm.h>
 
+#include "vmx.h"
+
 static DEFINE_PER_CPU(u64 *, vvmcs_buf);
 
 static void nvmx_purge_vvmcs(struct vcpu *v);
xen/arch/x86/include/asm/hvm/vmx/vmx.h +0 -439

503 lines not on this page · raw message

Signature · 1 line
2.37.2
#23 lore raw

Re: [PATCH v3 10/14] x86/vmx: move declarations used only by vmx code from vmx.h to private headers

xen/arch/x86/hvm/vmx/pi.h line 9

Quoted 12 lines · Xenia Ragiadakou
xen/arch/x86/hvm/vmx/pi.h new file +9 -0
@@ -0,0 +1,78 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * pi.h: VMX Posted Interrupts
+ *
+ * Copyright (c) 2004, Intel Corporation.
+ */
+
+#ifndef __X86_HVM_VMX_PI_PRIV_H__
+#define __X86_HVM_VMX_PI_PRIV_H__

I can see that you need something to disambiguate the two vmx.h. But here you don't need the PRIV infix, do you? Even in the private vmx.h I'd like to ask to consider e.g. __VMX_H__ as the guard (and then __PI_H__ here), rather than one which doesn't really match the filename.

Jan

#24 lore raw

Re: [PATCH v3 10/14] x86/vmx: move declarations used only by vmx code from vmx.h to private headers

Quoted 11 lines · Jan Beulich
Quoted 10 lines · Xenia Ragiadakou
xen/arch/x86/hvm/vmx/pi.h new file +7 -0
@@ -0,0 +1,78 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * pi.h: VMX Posted Interrupts
+ *
+ * Copyright (c) 2004, Intel Corporation.
+ */
+
Quoted 8 lines

xen/arch/x86/hvm/vmx/pi.h line 9

Quoted 2 lines
xen/arch/x86/hvm/vmx/pi.h new file +2 -0
+#ifndef __X86_HVM_VMX_PI_PRIV_H__
+#define __X86_HVM_VMX_PI_PRIV_H__

I can see that you need something to disambiguate the two vmx.h. But here you don't need the PRIV infix, do you? Even in the private vmx.h I'd like to ask to consider e.g. __VMX_H__ as the guard (and then __PI_H__ here), rather than one which doesn't really match the filename.

I do agree that adding _PRIV_ is off target.
For the purpose of disambiguation, the header guards need to conform to a well specified pattern guaranteed not to be used for anything else. For that reason I would suggest the guard to include the path, not just the file name.
In any case, the pattern that is used to generate the header guards should be mentioned in the coding style doc.

Quoted 2 lines

Jan

Signature · 1 line
Xenia
#25 lore raw

Re: [PATCH v3 10/14] x86/vmx: move declarations used only by vmx code from vmx.h to private headers

Quoted 22 lines · Xenia Ragiadakou
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Xenia Ragiadakou
xen/arch/x86/hvm/vmx/pi.h new file +7 -0
@@ -0,0 +1,78 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * pi.h: VMX Posted Interrupts
+ *
+ * Copyright (c) 2004, Intel Corporation.
+ */
+
Quoted 8 lines

xen/arch/x86/hvm/vmx/pi.h line 9

Quoted 2 lines
xen/arch/x86/hvm/vmx/pi.h new file +2 -0
+#ifndef __X86_HVM_VMX_PI_PRIV_H__
+#define __X86_HVM_VMX_PI_PRIV_H__

I can see that you need something to disambiguate the two vmx.h. But here you don't need the PRIV infix, do you? Even in the private vmx.h I'd like to ask to consider e.g. __VMX_H__ as the guard (and then __PI_H__ here), rather than one which doesn't really match the filename.

Quoted 5 lines

I do agree that adding _PRIV_ is off target.
For the purpose of disambiguation, the header guards need to conform to a well specified pattern guaranteed not to be used for anything else. For that reason I would suggest the guard to include the path, not just the file name.

But as we see the path can be ambiguous, unless all non-private headers had an "INCLUDE" infix. Hence my proposal would be no path at all for private headers, and path (as we frequently but perhaps not consistently have it) for non-private ones.

Quoted 2 lines

In any case, the pattern that is used to generate the header guards should be mentioned in the coding style doc.

Perhaps.

Jan

#26 lore raw

Re: [PATCH v3 10/14] x86/vmx: move declarations used only by vmx code from vmx.h to private headers

In reply to Xenia Ragiadakou
Quoted 10 lines · Xenia Ragiadakou

Create two new private headers in arch/x86/hvm/vmx called vmx.h and pi.h. Move all the definitions and declarations that are used solely by vmx code into the private vmx.h, apart from the ones related to posted interrupts that are moved into pi.h.

EPT related declarations and definitions stay in asm/hvm/vmx/vmx.h because they are used in arch/x86/mm and drivers/passthrough/vtd.

Also, __vmread(), used in arch/x86/cpu, and consequently the opcodes stay in asm/hvm/vmx/vmx.h.

Every time I read the vpmu code, I get increasingly sad.

That is dangerously unsafe, and comes with a chance of exploding completely.

That __vmread() is in NMI context, which means current isn't safe to deference (we might hit in the middle of a context switch), and more generally there's no guarantee that the loaded VMCS is the one associated with current (we might hit in the middle of a remote VMCS access).

vpmu is generally not supported, and BTS needs further custom enablement because it is only useable with a custom bus analyser.

The __vmread() needs deleting - its absolutely not safe to say.

I'm tempted to hardwire the return 0, and punt the problem to whomever next uses BTS.

Alternatively, MSR_DBGCTL needs wiring into the hvm_get_reg() infrastructure, but I'm not convinced this will actually work in either of the two problem cases above, hence preferring the previous option.

Thoughts?

~Andrew

#27 lore raw

Re: [PATCH v3 10/14] x86/vmx: move declarations used only by vmx code from vmx.h to private headers

Quoted 21 lines · Andrew Cooper
Quoted 10 lines · Xenia Ragiadakou

Create two new private headers in arch/x86/hvm/vmx called vmx.h and pi.h. Move all the definitions and declarations that are used solely by vmx code into the private vmx.h, apart from the ones related to posted interrupts that are moved into pi.h.

EPT related declarations and definitions stay in asm/hvm/vmx/vmx.h because they are used in arch/x86/mm and drivers/passthrough/vtd.

Also, __vmread(), used in arch/x86/cpu, and consequently the opcodes stay in asm/hvm/vmx/vmx.h.

Every time I read the vpmu code, I get increasingly sad.

That is dangerously unsafe, and comes with a chance of exploding completely.

That __vmread() is in NMI context, which means current isn't safe to deference (we might hit in the middle of a context switch), and more generally there's no guarantee that the loaded VMCS is the one associated with current (we might hit in the middle of a remote VMCS access).

Quoted 5 lines

vpmu is generally not supported, and BTS needs further custom enablement because it is only useable with a custom bus analyser.

The __vmread() needs deleting - its absolutely not safe to say.

to stay*

Quoted 11 lines

I'm tempted to hardwire the return 0, and punt the problem to whomever next uses BTS.

Alternatively, MSR_DBGCTL needs wiring into the hvm_get_reg() infrastructure, but I'm not convinced this will actually work in either of the two problem cases above, hence preferring the previous option.

Thoughts?

~Andrew

#28 lore raw

Re: [PATCH v3 10/14] x86/vmx: move declarations used only by vmx code from vmx.h to private headers

In reply to Andrew Cooper
Quoted 14 lines · Andrew Cooper
Quoted 10 lines · Xenia Ragiadakou

Create two new private headers in arch/x86/hvm/vmx called vmx.h and pi.h. Move all the definitions and declarations that are used solely by vmx code into the private vmx.h, apart from the ones related to posted interrupts that are moved into pi.h.

EPT related declarations and definitions stay in asm/hvm/vmx/vmx.h because they are used in arch/x86/mm and drivers/passthrough/vtd.

Also, __vmread(), used in arch/x86/cpu, and consequently the opcodes stay in asm/hvm/vmx/vmx.h.

Every time I read the vpmu code, I get increasingly sad.

Quoted 7 lines

That is dangerously unsafe, and comes with a chance of exploding completely.

That __vmread() is in NMI context, which means current isn't safe to deference (we might hit in the middle of a context switch), and more generally there's no guarantee that the loaded VMCS is the one associated with current (we might hit in the middle of a remote VMCS access).

Are you mixing up oprofile (using NMI) and vPMU (using an ordinary vectored interrupt)? Or am I overlooking a vPMU mode of operation where NMI could be used (i.e. other than apic_intr_init()'s calling of set_direct_apic_vector() and other than pmu_interrupt() invoking vpmu_do_interrupt() /after/ acking the IRQ at the LAPIC)?

Jan

Quoted 16 lines

vpmu is generally not supported, and BTS needs further custom enablement because it is only useable with a custom bus analyser.

The __vmread() needs deleting - its absolutely not safe to say.

I'm tempted to hardwire the return 0, and punt the problem to whomever next uses BTS.

Alternatively, MSR_DBGCTL needs wiring into the hvm_get_reg() infrastructure, but I'm not convinced this will actually work in either of the two problem cases above, hence preferring the previous option.

Thoughts?

~Andrew

#29 lore raw

PATCH v3 11/14 x86/vmx: remove unused included headers from vmx.c

In reply to Xenia Ragiadakou

Do not include the headers:
asm/hvm/vpic.h
asm/hvm/vpt.h
asm/io.h
asm/mce.h
asm/mem_sharing.h
asm/regs.h
public/arch-x86/cpuid.h
public/hvm/save.h
because none of the declarations and macro definitions in them is used. Sort the rest of the headers alphabetically.

No functional change intended.

---

Changes in v3:
- none

 xen/arch/x86/hvm/vmx/vmx.c | 56 +++++++++++++++++---------------------
 1 file changed, 25 insertions(+), 31 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +25 -31
index cb8b133ed5..9b009ebcef 100644
@@ -15,52 +15,46 @@
  * this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <xen/domain_page.h>
 #include <xen/guest_access.h>
+#include <xen/hypercall.h>
 #include <xen/init.h>
+#include <xen/irq.h>
 #include <xen/lib.h>
 #include <xen/param.h>
-#include <xen/trace.h>
+#include <xen/perfc.h>
 #include <xen/sched.h>
-#include <xen/irq.h>
 #include <xen/softirq.h>
-#include <xen/domain_page.h>
-#include <xen/hypercall.h>
-#include <xen/perfc.h>
-#include <asm/current.h>
-#include <asm/io.h>
-#include <asm/iocap.h>
-#include <asm/regs.h>
+#include <xen/trace.h>
+
+#include <asm/altp2m.h>
+#include <asm/apic.h>
 #include <asm/cpufeature.h>
-#include <asm/processor.h>
+#include <asm/current.h>
+#include <asm/gdbsx.h>
 #include <asm/debugreg.h>
-#include <asm/msr.h>
-#include <asm/p2m.h>
-#include <asm/mem_sharing.h>
+#include <asm/event.h>
 #include <asm/hvm/emulate.h>
 #include <asm/hvm/hvm.h>
+#include <asm/hvm/monitor.h>
+#include <asm/hvm/nestedhvm.h>
 #include <asm/hvm/support.h>
-#include <asm/hvm/vmx/vmx.h>
+#include <asm/hvm/trace.h>
+#include <asm/hvm/vlapic.h>
 #include <asm/hvm/vmx/vmcs.h>
-#include <public/sched.h>
-#include <public/hvm/ioreq.h>
+#include <asm/hvm/vmx/vmx.h>
+#include <asm/iocap.h>
 #include <asm/i387.h>
-#include <asm/hvm/vpic.h>
-#include <asm/hvm/vlapic.h>
-#include <asm/x86_emulate.h>
-#include <asm/hvm/vpt.h>
-#include <public/hvm/save.h>
-#include <asm/hvm/trace.h>
-#include <asm/hvm/monitor.h>
-#include <asm/xenoprof.h>
-#include <asm/gdbsx.h>
-#include <asm/apic.h>
-#include <asm/hvm/nestedhvm.h>
-#include <asm/altp2m.h>
-#include <asm/event.h>
-#include <asm/mce.h>
 #include <asm/monitor.h>
+#include <asm/msr.h>
+#include <asm/processor.h>
 #include <asm/prot-key.h>
-#include <public/arch-x86/cpuid.h>
+#include <asm/p2m.h>
+#include <asm/xenoprof.h>
+#include <asm/x86_emulate.h>
+
+#include <public/sched.h>
+#include <public/hvm/ioreq.h>
 
 #include "pi.h"
 #include "vmx.h"
Signature · 1 line
2.37.2
#30 lore raw

PATCH v3 12/14 x86/vmx: declare nvmx_enqueue_n2_exceptions() static

In reply to Xenia Ragiadakou

Reduce the scope of nvmx_enqueue_n2_exceptions() to static because it is used only in this file.

Take the opportunity to remove a trailing space.

---

Changes in v3:
- add Jan's R-b tag

 xen/arch/x86/hvm/vmx/vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/vmx/vmx.c +1 -1
index 9b009ebcef..72d8f058f7 100644
@@ -1897,7 +1897,7 @@ static void cf_check vmx_update_guest_efer(struct vcpu *v)
         vmx_set_msr_intercept(v, MSR_EFER, VMX_MSR_R);
 }
 
-void nvmx_enqueue_n2_exceptions(struct vcpu *v, 
+static void nvmx_enqueue_n2_exceptions(struct vcpu *v,
             unsigned long intr_fields, int error_code, uint8_t source)
 {
     struct nestedvmx *nvmx = &vcpu_2_nvmx(v);
Signature · 1 line
2.37.2
#31 lore raw

PATCH v3 13/14 x86/vmx: move vvmx declarations used only by vmx code to private header

In reply to Xenia Ragiadakou

Create a new private header in arch/x86/hvm/vmx called vvmx.h and move there all definitions and declarations that are used only by vmx code and don't need to reside in an external header.

Take the opportunity to replace u* with uint*_t, bool_t with bool and to re-arrange the header as follows, all structures first, then all variable decalarations, all function delarations, and finally all inline functions.

No functional change intended.

---

Changes in v3:
- new patch

 xen/arch/x86/hvm/vmx/intr.c             |   1 +
 xen/arch/x86/hvm/vmx/vmcs.c             |   2 +-
 xen/arch/x86/hvm/vmx/vmx.c              |   1 +
 xen/arch/x86/hvm/vmx/vvmx.c             |   1 +
 xen/arch/x86/hvm/vmx/vvmx.h             | 187 ++++++++++++++++++++++++
 xen/arch/x86/include/asm/hvm/vmx/vvmx.h | 165 +--------------------
 6 files changed, 198 insertions(+), 159 deletions(-)
 create mode 100644 xen/arch/x86/hvm/vmx/vvmx.h
xen/arch/x86/hvm/vmx/intr.c +1 -0
index c8db501759..8431937f42 100644
@@ -39,6 +39,7 @@
 #include <asm/vm_event.h>
 
 #include "vmx.h"
+#include "vvmx.h"
 
 /*
  * A few notes on virtual NMI and INTR delivery, and interactions with
xen/arch/x86/hvm/vmx/vmcs.c +1 -1
index 4eb2571abb..3d0f6be5bb 100644
@@ -34,7 +34,6 @@
 #include <asm/hvm/io.h>
 #include <asm/hvm/nestedhvm.h>
 #include <asm/hvm/vmx/vmx.h>
-#include <asm/hvm/vmx/vvmx.h>
 #include <asm/hvm/vmx/vmcs.h>
 #include <asm/flushtlb.h>
 #include <asm/monitor.h>
@@ -44,6 +43,7 @@
 #include <asm/apic.h>
 
 #include "vmx.h"
+#include "vvmx.h"
 
 static bool_t __read_mostly opt_vpid_enabled = 1;
 boolean_param("vpid", opt_vpid_enabled);
xen/arch/x86/hvm/vmx/vmx.c +1 -0
index 72d8f058f7..73ab4e9816 100644
@@ -58,6 +58,7 @@
 
 #include "pi.h"
 #include "vmx.h"
+#include "vvmx.h"
 
 static bool_t __initdata opt_force_ept;
 boolean_param("force-ept", opt_force_ept);
xen/arch/x86/hvm/vmx/vvmx.c +1 -0
index 0bda8430b9..0af5411076 100644
@@ -30,6 +30,7 @@
 #include <asm/hvm/nestedhvm.h>
 
 #include "vmx.h"
+#include "vvmx.h"
 
 static DEFINE_PER_CPU(u64 *, vvmcs_buf);
 
xen/arch/x86/hvm/vmx/vvmx.h new file +187 -0

187 lines not on this page · raw message

xen/arch/x86/include/asm/hvm/vmx/vvmx.h +7 -158

189 lines not on this page · raw message

Signature · 1 line
2.37.2
#32 lore raw

PATCH v3 14/14 x86/vmx: move vmcs declarations used only by vmx code to private header

In reply to Xenia Ragiadakou

Create a new private header in arch/x86/hvm/vmx called vmcs.h and move there all definitions and declarations that are used only by vmx code and don't need to reside in an external header.

Take the opportunity to replace u* with uint*_t, bool_t with bool and to re-arrange the header as follows, all structures first, then all variable declarations, all function delarations, and finally all inline functions.

No functional change intended.

---

Changes in v3:
- new patch

 xen/arch/x86/hvm/vmx/intr.c             |   1 +
 xen/arch/x86/hvm/vmx/vmcs.c             |   1 +
 xen/arch/x86/hvm/vmx/vmcs.h             | 100 ++++++++++++++++++++
 xen/arch/x86/hvm/vmx/vmx.c              |   1 +
 xen/arch/x86/hvm/vmx/vvmx.c             |   1 +
 xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 118 +++++-------------------
 6 files changed, 128 insertions(+), 94 deletions(-)
 create mode 100644 xen/arch/x86/hvm/vmx/vmcs.h
xen/arch/x86/hvm/vmx/intr.c +1 -0
index 8431937f42..d8387e7215 100644
@@ -38,6 +38,7 @@
 #include <asm/hvm/trace.h>
 #include <asm/vm_event.h>
 
+#include "vmcs.h"
 #include "vmx.h"
 #include "vvmx.h"
 
xen/arch/x86/hvm/vmx/vmcs.c +1 -0
index 3d0f6be5bb..57e19e8dad 100644
@@ -42,6 +42,7 @@
 #include <asm/tboot.h>
 #include <asm/apic.h>
 
+#include "vmcs.h"
 #include "vmx.h"
 #include "vvmx.h"
 
xen/arch/x86/hvm/vmx/vmcs.h new file +100 -0

100 lines not on this page · raw message

xen/arch/x86/hvm/vmx/vmx.c +1 -0
index 73ab4e9816..c5f6902206 100644
@@ -57,6 +57,7 @@
 #include <public/hvm/ioreq.h>
 
 #include "pi.h"
+#include "vmcs.h"
 #include "vmx.h"
 #include "vvmx.h"
 
xen/arch/x86/hvm/vmx/vvmx.c +1 -0
index 0af5411076..d0a6fa2d20 100644
@@ -29,6 +29,7 @@
 #include <asm/hvm/vmx/vvmx.h>
 #include <asm/hvm/nestedhvm.h>
 
+#include "vmcs.h"
 #include "vmx.h"
 #include "vvmx.h"
 
xen/arch/x86/include/asm/hvm/vmx/vmcs.h +24 -94

230 lines not on this page · raw message

Signature · 1 line
2.37.2
#33 lore raw
In reply to Xenia Ragiadakou
Quoted 7 lines · Xenia Ragiadakou

There are more detailed per-patch changesets.

Xenia Ragiadakou (14):
x86/svm: move declarations used only by svm code from svm.h to private
header
x86/svm: make asid.h private
x86/svm: delete header asm/hvm/svm/intr.h

Thankyou for this work.  I've acked and committed patches 1 and 3.

Note that you had one hunk in patch 5 (whitespace correction in svm_invlpga) that obviously should have been in patch 1, so I've moved it.

Looking at asid.h, I still can't bare to keep it even in that state, so I've constructed an alternative which I'll email out in a moment.

~Andrew

#34 lore raw
Quoted 9 lines · Andrew Cooper
Quoted 7 lines · Xenia Ragiadakou

There are more detailed per-patch changesets.

Xenia Ragiadakou (14):
x86/svm: move declarations used only by svm code from svm.h to private
header
x86/svm: make asid.h private
x86/svm: delete header asm/hvm/svm/intr.h

Quoted 4 lines

Thankyou for this work.  I've acked and committed patches 1 and 3.

Note that you had one hunk in patch 5 (whitespace correction in svm_invlpga) that obviously should have been in patch 1, so I've moved it.

Thanks, I missed that ...

Quoted 3 lines

Looking at asid.h, I still can't bare to keep it even in that state, so I've constructed an alternative which I'll email out in a moment.

I 'm also in favor of less headers.

Quoted 2 lines

~Andrew

Signature · 1 line
Xenia
#35 lore raw
Quoted 18 lines · Xenia Ragiadakou
Quoted 10 lines · Andrew Cooper
Quoted 8 lines · Xenia Ragiadakou

There are more detailed per-patch changesets.

Xenia Ragiadakou (14):
   x86/svm: move declarations used only by svm code from svm.h to private
     header
   x86/svm: make asid.h private
   x86/svm: delete header asm/hvm/svm/intr.h

Quoted 5 lines

Thankyou for this work.  I've acked and committed patches 1 and 3.

Note that you had one hunk in patch 5 (whitespace correction in svm_invlpga) that obviously should have been in patch 1, so I've moved it.

Quoted 7 lines

Thanks, I missed that  ...

Quoted 3 lines

Looking at asid.h, I still can't bare to keep it even in that state, so I've constructed an alternative which I'll email out in a moment.

I 'm also in favor of less headers.

I've committed as far as the nestedhvm move.  At that point, I've sent out a small patch to try and help decouple later changes.

But I think we want to change tact slightly at this point, so I'm not going to do any further tweaking on commit.

Next, I think we want to rename asm/hvm/svm/svm.h to asm/hvm/svm.h, updating the non-SVM include paths as we go.  Probably best to chain-include the other svm/hvm/svm/*.h headers temporarily, so we've only got one tree-wide cleanup of the external include paths.

Quick tangent - I will be making all of that cpu_has_svm_* infrastructure disappear by moving it into the normal CPUID handling, but I've not had sufficient time to finish that yet.

Next, hvm/svm/nestedsvm.h can merge straight into hvm/svm.h, and disappear (after my decoupling patch has gone in).

After that, hvm/svm/vmcb.h can be cleanly split in half.  struct svm_{domain,vcpu} can move sideways into hvm/svm.h (with a forward declaration of vmcb_struct), as can the svm msr intercept declarations. Everything else can move to being a private vmcb.h

Finally your svmdebug.h can come at the end, pretty much in the same shape it is now.  One thing to say is that right now, you've left enum vmcb_sync_state public, but it's type is already decoupled by virtue of struct svm_vcpu having a uint8_t field rather than an enum field.

And I think that cleanly gets rid of the entire asm/hvm/svm/* dir, which is a great position to get to.

Beyond that, you will want to clean up the hvm msr intercept handling as hvm_funcs, which I think will decouple the vpmu files from svm/vmx specifically, but that will want to be a separate series.

How does this sound?

Thanks,

~Andrew

#36 lore raw
Quoted 59 lines · Andrew Cooper
Quoted 18 lines · Xenia Ragiadakou
Quoted 10 lines · Andrew Cooper
Quoted 8 lines · Xenia Ragiadakou

There are more detailed per-patch changesets.

Xenia Ragiadakou (14):
   x86/svm: move declarations used only by svm code from svm.h to
private
     header
   x86/svm: make asid.h private
   x86/svm: delete header asm/hvm/svm/intr.h

Quoted 5 lines

Thankyou for this work.  I've acked and committed patches 1 and 3.

Note that you had one hunk in patch 5 (whitespace correction in svm_invlpga) that obviously should have been in patch 1, so I've moved it.

Quoted 7 lines

Thanks, I missed that  ...

Quoted 3 lines

Looking at asid.h, I still can't bare to keep it even in that state, so I've constructed an alternative which I'll email out in a moment.

I 'm also in favor of less headers.

I've committed as far as the nestedhvm move.  At that point, I've sent out a small patch to try and help decouple later changes.

But I think we want to change tact slightly at this point, so I'm not going to do any further tweaking on commit.

Next, I think we want to rename asm/hvm/svm/svm.h to asm/hvm/svm.h, updating the non-SVM include paths as we go.  Probably best to chain-include the other svm/hvm/svm/*.h headers temporarily, so we've only got one tree-wide cleanup of the external include paths.

Quick tangent - I will be making all of that cpu_has_svm_* infrastructure disappear by moving it into the normal CPUID handling, but I've not had sufficient time to finish that yet.

Next, hvm/svm/nestedsvm.h can merge straight into hvm/svm.h, and disappear (after my decoupling patch has gone in).

After that, hvm/svm/vmcb.h can be cleanly split in half.  struct svm_{domain,vcpu} can move sideways into hvm/svm.h (with a forward declaration of vmcb_struct), as can the svm msr intercept declarations. Everything else can move to being a private vmcb.h

Finally your svmdebug.h can come at the end, pretty much in the same shape it is now.  One thing to say is that right now, you've left enum vmcb_sync_state public, but it's type is already decoupled by virtue of struct svm_vcpu having a uint8_t field rather than an enum field.

And I think that cleanly gets rid of the entire asm/hvm/svm/* dir, which is a great position to get to.

Quoted 5 lines

Beyond that, you will want to clean up the hvm msr intercept handling as hvm_funcs, which I think will decouple the vpmu files from svm/vmx specifically, but that will want to be a separate series.

How does this sound?

Thanks for the review. I think it sounds good.

The last part i.e the hvm msr intercept handling as hvm_funcs, I have it already I just didn't have the chance to send it yet (because the changes affect {svm,vmx}.h). I will rebase and send it on Monday for review to verify that we are on the same page.

Quoted 4 lines

Thanks,

~Andrew

Signature · 1 line
Xenia
#37 lore raw
In reply to Andrew Cooper
Quoted 8 lines · Andrew Cooper

But I think we want to change tact slightly at this point, so I'm not going to do any further tweaking on commit.

Next, I think we want to rename asm/hvm/svm/svm.h to asm/hvm/svm.h, updating the non-SVM include paths as we go.  Probably best to chain-include the other svm/hvm/svm/*.h headers temporarily, so we've only got one tree-wide cleanup of the external include paths.

Quoted 6 lines

Quick tangent - I will be making all of that cpu_has_svm_* infrastructure disappear by moving it into the normal CPUID handling, but I've not had sufficient time to finish that yet.

Next, hvm/svm/nestedsvm.h can merge straight into hvm/svm.h, and disappear (after my decoupling patch has gone in).

Why would you want to fold hvm/svm/nestedsvm.h into hvm/svm/svm.h? The latter doesn't use anything from the former, does it? And it also doesn't include it right now. Since nested is still far from being properly functional, and since most guests don't use it, I'd rather see struct nestedvcpu's union to become a union of two pointers, which get space allocated only for nested-enabled guests. Yet it's only the use there which makes it necessary to globally expose the struct right now.

Jan

#38 lore raw
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper

But I think we want to change tact slightly at this point, so I'm not going to do any further tweaking on commit.

Next, I think we want to rename asm/hvm/svm/svm.h to asm/hvm/svm.h, updating the non-SVM include paths as we go.  Probably best to chain-include the other svm/hvm/svm/*.h headers temporarily, so we've only got one tree-wide cleanup of the external include paths.

Quoted 8 lines
Quoted 6 lines

Quick tangent - I will be making all of that cpu_has_svm_* infrastructure disappear by moving it into the normal CPUID handling, but I've not had sufficient time to finish that yet.

Next, hvm/svm/nestedsvm.h can merge straight into hvm/svm.h, and disappear (after my decoupling patch has gone in).

Why would you want to fold hvm/svm/nestedsvm.h into hvm/svm/svm.h? The latter doesn't use anything from the former, does it?

It's about what else uses them.

hvm_vcpu needs both svm_vcpu and nestedsvm, so both headers are always included in tandem.

nestedsvm is literally just one struct now, and no subsystem ought to have multiple headers when one will do.

The resulting "unified" svm.h will have very little in it, but everything in it (including nestedsvm) should be there.

~Andrew

#39 lore raw
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Andrew Cooper

But I think we want to change tact slightly at this point, so I'm not going to do any further tweaking on commit.

Next, I think we want to rename asm/hvm/svm/svm.h to asm/hvm/svm.h, updating the non-SVM include paths as we go.  Probably best to chain-include the other svm/hvm/svm/*.h headers temporarily, so we've only got one tree-wide cleanup of the external include paths.

Quick tangent - I will be making all of that cpu_has_svm_* infrastructure disappear by moving it into the normal CPUID handling, but I've not had sufficient time to finish that yet.

Next, hvm/svm/nestedsvm.h can merge straight into hvm/svm.h, and disappear (after my decoupling patch has gone in).

Quoted 7 lines
Quoted 2 lines

Why would you want to fold hvm/svm/nestedsvm.h into hvm/svm/svm.h? The latter doesn't use anything from the former, does it?

It's about what else uses them.

hvm_vcpu needs both svm_vcpu and nestedsvm, so both headers are always included in tandem.

Well, yes, that's how things are today. But can you explain to me why hvm_vcpu has to know nestedsvm's layout? If the field was a pointer, a forward decl of that struct would suffice, and any entity in the rest of Xen not caring about struct nestedsvm would no longer see it (and hence also no longer be re-built if a change is made there).

Quoted 2 lines

nestedsvm is literally just one struct now, and no subsystem ought to have multiple headers when one will do.

When one will do, yes. Removing build dependencies is a good reason to have separate headers, though.

Jan

#40 lore raw
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Andrew Cooper

But I think we want to change tact slightly at this point, so I'm not going to do any further tweaking on commit.

Next, I think we want to rename asm/hvm/svm/svm.h to asm/hvm/svm.h, updating the non-SVM include paths as we go.  Probably best to chain-include the other svm/hvm/svm/*.h headers temporarily, so we've only got one tree-wide cleanup of the external include paths.

Quick tangent - I will be making all of that cpu_has_svm_* infrastructure disappear by moving it into the normal CPUID handling, but I've not had sufficient time to finish that yet.

Next, hvm/svm/nestedsvm.h can merge straight into hvm/svm.h, and disappear (after my decoupling patch has gone in).

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Why would you want to fold hvm/svm/nestedsvm.h into hvm/svm/svm.h? The latter doesn't use anything from the former, does it?

It's about what else uses them.

hvm_vcpu needs both svm_vcpu and nestedsvm, so both headers are always included in tandem.

Well, yes, that's how things are today. But can you explain to me why hvm_vcpu has to know nestedsvm's layout?

Because it's part of the same single memory allocation.

Quoted 4 lines

If the field was a pointer,
a forward decl of that struct would suffice, and any entity in the rest of Xen not caring about struct nestedsvm would no longer see it (and hence also no longer be re-built if a change is made there).

Yes, you could hide it as a pointer.  The cost of doing so is an unnecessary extra memory allocation, and extra pointer handling on create/destroy, not to mention extra pointer chasing in memory during use.

Quoted 4 lines
Quoted 2 lines

nestedsvm is literally just one struct now, and no subsystem ought to have multiple headers when one will do.

When one will do, yes. Removing build dependencies is a good reason to have separate headers, though.

Its not the only only option, and an #ifdef CONFIG_NESTED_VIRT inside the struct would be an equally acceptable way of doing this which wouldn't involve making an extra memory allocation.

Everything you've posed here is way out of scope for Xenia's series. You are welcome to try and make the changes in the future if you want, but you're going to have a uphill battle trying to justify it as a sensible move.

~Andrew

#41 lore raw
Quoted 20 lines · Andrew Cooper
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Andrew Cooper
Quoted 17 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper

But I think we want to change tact slightly at this point, so I'm not going to do any further tweaking on commit.

Next, I think we want to rename asm/hvm/svm/svm.h to asm/hvm/svm.h, updating the non-SVM include paths as we go.  Probably best to chain-include the other svm/hvm/svm/*.h headers temporarily, so we've only got one tree-wide cleanup of the external include paths.

Quoted 6 lines

Quick tangent - I will be making all of that cpu_has_svm_* infrastructure disappear by moving it into the normal CPUID handling, but I've not had sufficient time to finish that yet.

Next, hvm/svm/nestedsvm.h can merge straight into hvm/svm.h, and disappear (after my decoupling patch has gone in).

Why would you want to fold hvm/svm/nestedsvm.h into hvm/svm/svm.h? The latter doesn't use anything from the former, does it?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

It's about what else uses them.

hvm_vcpu needs both svm_vcpu and nestedsvm, so both headers are always included in tandem.

Well, yes, that's how things are today. But can you explain to me why hvm_vcpu has to know nestedsvm's layout?

Because it's part of the same single memory allocation.

Which keeps growing, and sooner or later we'll need to find something again to split off, so we won't exceed a page in size. The nested structures would, to me, look to be prime candidates for such.

Quoted 9 lines
Quoted 4 lines

If the field was a pointer,
a forward decl of that struct would suffice, and any entity in the rest of Xen not caring about struct nestedsvm would no longer see it (and hence also no longer be re-built if a change is made there).

Yes, you could hide it as a pointer.  The cost of doing so is an unnecessary extra memory allocation, and extra pointer handling on create/destroy, not to mention extra pointer chasing in memory during use.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

nestedsvm is literally just one struct now, and no subsystem ought to have multiple headers when one will do.

When one will do, yes. Removing build dependencies is a good reason to have separate headers, though.

Its not the only only option, and an #ifdef CONFIG_NESTED_VIRT inside the struct would be an equally acceptable way of doing this which wouldn't involve making an extra memory allocation.

That would make it a build-time decision, but then on NESTED_VIRT=y hypervisors there might still be guests not meaning to use that functionality, and for quite some time that may actually be a majority.

Quoted 1 line

Everything you've posed here is way out of scope for Xenia's series.

There was never an intention to extend the scope of the work she's doing. Instead I was trying to limit the scope by suggesting to avoid a piece of rework which later may want undoing.

Jan

#42 lore raw
Quoted 56 lines · Jan Beulich
Quoted 20 lines · Andrew Cooper
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Andrew Cooper
Quoted 17 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper

But I think we want to change tact slightly at this point, so I'm not going to do any further tweaking on commit.

Next, I think we want to rename asm/hvm/svm/svm.h to asm/hvm/svm.h, updating the non-SVM include paths as we go.  Probably best to chain-include the other svm/hvm/svm/*.h headers temporarily, so we've only got one tree-wide cleanup of the external include paths.

Quoted 6 lines

Quick tangent - I will be making all of that cpu_has_svm_* infrastructure disappear by moving it into the normal CPUID handling, but I've not had sufficient time to finish that yet.

Next, hvm/svm/nestedsvm.h can merge straight into hvm/svm.h, and disappear (after my decoupling patch has gone in).

Why would you want to fold hvm/svm/nestedsvm.h into hvm/svm/svm.h? The latter doesn't use anything from the former, does it?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

It's about what else uses them.

hvm_vcpu needs both svm_vcpu and nestedsvm, so both headers are always included in tandem.

Well, yes, that's how things are today. But can you explain to me why hvm_vcpu has to know nestedsvm's layout?

Because it's part of the same single memory allocation.

Which keeps growing, and sooner or later we'll need to find something again to split off, so we won't exceed a page in size. The nested structures would, to me, look to be prime candidates for such.

Quoted 9 lines
Quoted 4 lines

If the field was a pointer,
a forward decl of that struct would suffice, and any entity in the rest of Xen not caring about struct nestedsvm would no longer see it (and hence also no longer be re-built if a change is made there).

Yes, you could hide it as a pointer.  The cost of doing so is an unnecessary extra memory allocation, and extra pointer handling on create/destroy, not to mention extra pointer chasing in memory during use.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

nestedsvm is literally just one struct now, and no subsystem ought to have multiple headers when one will do.

When one will do, yes. Removing build dependencies is a good reason to have separate headers, though.

Its not the only only option, and an #ifdef CONFIG_NESTED_VIRT inside the struct would be an equally acceptable way of doing this which wouldn't involve making an extra memory allocation.

That would make it a build-time decision, but then on NESTED_VIRT=y hypervisors there might still be guests not meaning to use that functionality, and for quite some time that may actually be a majority.

Quoted 5 lines
Quoted 1 line

Everything you've posed here is way out of scope for Xenia's series.

There was never an intention to extend the scope of the work she's doing. Instead I was trying to limit the scope by suggesting to avoid a piece of rework which later may want undoing.

Can I suggest to leave hvm/svm/svm.h and hvm/svm/nestedsvm.h separate for now?

Quoted 2 lines

Jan

Signature · 1 line
Xenia
#43 lore raw
Quoted 58 lines · Xenia Ragiadakou
Quoted 56 lines · Jan Beulich
Quoted 20 lines · Andrew Cooper
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Andrew Cooper
Quoted 17 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper

But I think we want to change tact slightly at this point, so I'm not going to do any further tweaking on commit.

Next, I think we want to rename asm/hvm/svm/svm.h to asm/hvm/svm.h, updating the non-SVM include paths as we go.  Probably best to chain-include the other svm/hvm/svm/*.h headers temporarily, so we've only got one tree-wide cleanup of the external include paths.

Quoted 6 lines

Quick tangent - I will be making all of that cpu_has_svm_* infrastructure disappear by moving it into the normal CPUID handling, but I've not had sufficient time to finish that yet.

Next, hvm/svm/nestedsvm.h can merge straight into hvm/svm.h, and disappear (after my decoupling patch has gone in).

Why would you want to fold hvm/svm/nestedsvm.h into hvm/svm/svm.h? The latter doesn't use anything from the former, does it?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

It's about what else uses them.

hvm_vcpu needs both svm_vcpu and nestedsvm, so both headers are always included in tandem.

Well, yes, that's how things are today. But can you explain to me why hvm_vcpu has to know nestedsvm's layout?

Because it's part of the same single memory allocation.

Which keeps growing, and sooner or later we'll need to find something again to split off, so we won't exceed a page in size. The nested structures would, to me, look to be prime candidates for such.

Quoted 9 lines
Quoted 4 lines

If the field was a pointer,
a forward decl of that struct would suffice, and any entity in the rest of Xen not caring about struct nestedsvm would no longer see it (and hence also no longer be re-built if a change is made there).

Yes, you could hide it as a pointer.  The cost of doing so is an unnecessary extra memory allocation, and extra pointer handling on create/destroy, not to mention extra pointer chasing in memory during use.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

nestedsvm is literally just one struct now, and no subsystem ought to have multiple headers when one will do.

When one will do, yes. Removing build dependencies is a good reason to have separate headers, though.

Its not the only only option, and an #ifdef CONFIG_NESTED_VIRT inside the struct would be an equally acceptable way of doing this which wouldn't involve making an extra memory allocation.

That would make it a build-time decision, but then on NESTED_VIRT=y hypervisors there might still be guests not meaning to use that functionality, and for quite some time that may actually be a majority.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Everything you've posed here is way out of scope for Xenia's series.

There was never an intention to extend the scope of the work she's doing. Instead I was trying to limit the scope by suggesting to avoid a piece of rework which later may want undoing.

Can I suggest to leave hvm/svm/svm.h and hvm/svm/nestedsvm.h separate for now?

As per before - that's my preference. It'll be Andrew who you would need to convince, as he did suggest the folding.

Jan

#44 lore raw
Quoted 53 lines · Jan Beulich
Quoted 52 lines · Xenia Ragiadakou
Quoted 51 lines · Jan Beulich
Quoted 20 lines · Andrew Cooper
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Andrew Cooper
Quoted 17 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper

But I think we want to change tact slightly at this point, so I'm not going to do any further tweaking on commit.

Next, I think we want to rename asm/hvm/svm/svm.h to asm/hvm/svm.h, updating the non-SVM include paths as we go.  Probably best to chain-include the other svm/hvm/svm/*.h headers temporarily, so we've only got one tree-wide cleanup of the external include paths.

Quoted 6 lines

Quick tangent - I will be making all of that cpu_has_svm_* infrastructure disappear by moving it into the normal CPUID handling, but I've not had sufficient time to finish that yet.

Next, hvm/svm/nestedsvm.h can merge straight into hvm/svm.h, and disappear (after my decoupling patch has gone in).

Why would you want to fold hvm/svm/nestedsvm.h into hvm/svm/svm.h? The latter doesn't use anything from the former, does it?

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

It's about what else uses them.

hvm_vcpu needs both svm_vcpu and nestedsvm, so both headers are always included in tandem.

Well, yes, that's how things are today. But can you explain to me why hvm_vcpu has to know nestedsvm's layout?

Because it's part of the same single memory allocation.

Which keeps growing, and sooner or later we'll need to find something again to split off, so we won't exceed a page in size. The nested structures would, to me, look to be prime candidates for such.

Quoted 8 lines
Quoted 4 lines

If the field was a pointer,
a forward decl of that struct would suffice, and any entity in the rest of Xen not caring about struct nestedsvm would no longer see it (and hence also no longer be re-built if a change is made there).

Yes, you could hide it as a pointer.  The cost of doing so is an unnecessary extra memory allocation, and extra pointer handling on create/destroy, not to mention extra pointer chasing in memory during use.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

nestedsvm is literally just one struct now, and no subsystem ought to have multiple headers when one will do.

When one will do, yes. Removing build dependencies is a good reason to have separate headers, though.

Its not the only only option, and an #ifdef CONFIG_NESTED_VIRT inside the struct would be an equally acceptable way of doing this which wouldn't involve making an extra memory allocation.

That would make it a build-time decision, but then on NESTED_VIRT=y hypervisors there might still be guests not meaning to use that functionality, and for quite some time that may actually be a majority.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Everything you've posed here is way out of scope for Xenia's series.

There was never an intention to extend the scope of the work she's doing. Instead I was trying to limit the scope by suggesting to avoid a piece of rework which later may want undoing.

Can I suggest to leave hvm/svm/svm.h and hvm/svm/nestedsvm.h separate for now?

As per before - that's my preference. It'll be Andrew who you would need to convince, as he did suggest the folding.

Please fold them.

I have strong doubts that they would actually be unfolded, even if we did want to make nested virt a build time choice.

(I'm not actually convinced that the existing nestedvcpu structure will survive first-pass design of a working nested virt solution.)

~Andrew