* [PATCH] x86/trapnr: Add event type macros to <asm/trapnr.h>
@ 2023-07-06 5:14 Xin Li
2023-07-06 6:45 ` Peter Zijlstra
0 siblings, 1 reply; 3+ messages in thread
From: Xin Li @ 2023-07-06 5:14 UTC (permalink / raw)
To: linux-kernel, kvm, x86
Cc: tglx, mingo, bp, dave.hansen, hpa, seanjc, pbonzini, xin3.li
Intel VT-x classifies events into eight different types, which is
inherited by FRED for event identification. As such, event type
becomes a common x86 concept, and should be defined in a common x86
header.
Add event type macros to <asm/trapnr.h>, and use it in <asm/vmx.h>.
Suggested-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Signed-off-by: Xin Li <xin3.li@intel.com>
---
arch/x86/include/asm/trapnr.h | 18 ++++++++++++++++++
arch/x86/include/asm/vmx.h | 17 +++++++++--------
2 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/arch/x86/include/asm/trapnr.h b/arch/x86/include/asm/trapnr.h
index f5d2325aa0b7..356af7ceab4d 100644
--- a/arch/x86/include/asm/trapnr.h
+++ b/arch/x86/include/asm/trapnr.h
@@ -2,6 +2,24 @@
#ifndef _ASM_X86_TRAPNR_H
#define _ASM_X86_TRAPNR_H
+/*
+ * Event type codes used by both Intel VT-x and FRED
+ */
+/* Maskable external interrupt */
+#define EVENT_TYPE_HWINT 0
+#define EVENT_TYPE_RESERVED 1
+#define EVENT_TYPE_NMI 2
+/* Hardware exceptions (e.g., page fault) */
+#define EVENT_TYPE_HWFAULT 3
+/* Software interrupt (INT n) */
+#define EVENT_TYPE_SWINT 4
+/* INT1 (ICEBP) */
+#define EVENT_TYPE_PRIVSW 5
+/* Software exception (INT3 or INTO) */
+#define EVENT_TYPE_SWFAULT 6
+/* VT-x MTF or FRED SYSCALL/SYSENTER */
+#define EVENT_TYPE_OTHER 7
+
/* Interrupts/Exceptions */
#define X86_TRAP_DE 0 /* Divide-by-zero */
diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
index 0d02c4aafa6f..15a096fceb1d 100644
--- a/arch/x86/include/asm/vmx.h
+++ b/arch/x86/include/asm/vmx.h
@@ -17,6 +17,7 @@
#include <linux/types.h>
#include <uapi/asm/vmx.h>
+#include <asm/trapnr.h>
#include <asm/vmxfeatures.h>
#define VMCS_CONTROL_BIT(x) BIT(VMX_FEATURE_##x & 0x1f)
@@ -374,14 +375,14 @@ enum vmcs_field {
#define VECTORING_INFO_DELIVER_CODE_MASK INTR_INFO_DELIVER_CODE_MASK
#define VECTORING_INFO_VALID_MASK INTR_INFO_VALID_MASK
-#define INTR_TYPE_EXT_INTR (0 << 8) /* external interrupt */
-#define INTR_TYPE_RESERVED (1 << 8) /* reserved */
-#define INTR_TYPE_NMI_INTR (2 << 8) /* NMI */
-#define INTR_TYPE_HARD_EXCEPTION (3 << 8) /* processor exception */
-#define INTR_TYPE_SOFT_INTR (4 << 8) /* software interrupt */
-#define INTR_TYPE_PRIV_SW_EXCEPTION (5 << 8) /* ICE breakpoint - undocumented */
-#define INTR_TYPE_SOFT_EXCEPTION (6 << 8) /* software exception */
-#define INTR_TYPE_OTHER_EVENT (7 << 8) /* other event */
+#define INTR_TYPE_EXT_INTR (EVENT_TYPE_HWINT << 8) /* external interrupt */
+#define INTR_TYPE_RESERVED (EVENT_TYPE_RESERVED << 8) /* reserved */
+#define INTR_TYPE_NMI_INTR (EVENT_TYPE_NMI << 8) /* NMI */
+#define INTR_TYPE_HARD_EXCEPTION (EVENT_TYPE_HWFAULT << 8) /* processor exception */
+#define INTR_TYPE_SOFT_INTR (EVENT_TYPE_SWINT << 8) /* software interrupt */
+#define INTR_TYPE_PRIV_SW_EXCEPTION (EVENT_TYPE_PRIVSW << 8) /* ICE breakpoint - undocumented */
+#define INTR_TYPE_SOFT_EXCEPTION (EVENT_TYPE_SWFAULT << 8) /* software exception */
+#define INTR_TYPE_OTHER_EVENT (EVENT_TYPE_OTHER << 8) /* other event */
/* GUEST_INTERRUPTIBILITY_INFO flags. */
#define GUEST_INTR_STATE_STI 0x00000001
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/trapnr: Add event type macros to <asm/trapnr.h>
2023-07-06 5:14 [PATCH] x86/trapnr: Add event type macros to <asm/trapnr.h> Xin Li
@ 2023-07-06 6:45 ` Peter Zijlstra
2023-07-06 7:25 ` Li, Xin3
0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2023-07-06 6:45 UTC (permalink / raw)
To: Xin Li
Cc: linux-kernel, kvm, x86, tglx, mingo, bp, dave.hansen, hpa, seanjc,
pbonzini
On Wed, Jul 05, 2023 at 10:14:43PM -0700, Xin Li wrote:
> +/*
> + * Event type codes used by both Intel VT-x and FRED
> + */
> +/* Maskable external interrupt */
> +#define EVENT_TYPE_HWINT 0
> +#define EVENT_TYPE_RESERVED 1
> +#define EVENT_TYPE_NMI 2
> +/* Hardware exceptions (e.g., page fault) */
> +#define EVENT_TYPE_HWFAULT 3
> +/* Software interrupt (INT n) */
> +#define EVENT_TYPE_SWINT 4
> +/* INT1 (ICEBP) */
> +#define EVENT_TYPE_PRIVSW 5
> +/* Software exception (INT3 or INTO) */
> +#define EVENT_TYPE_SWFAULT 6
> +/* VT-x MTF or FRED SYSCALL/SYSENTER */
> +#define EVENT_TYPE_OTHER 7
So I know tglx hates on tail comments, but I find the below *MUCH* more
readable than the above horror show.
> -#define INTR_TYPE_EXT_INTR (0 << 8) /* external interrupt */
> -#define INTR_TYPE_RESERVED (1 << 8) /* reserved */
> -#define INTR_TYPE_NMI_INTR (2 << 8) /* NMI */
> -#define INTR_TYPE_HARD_EXCEPTION (3 << 8) /* processor exception */
> -#define INTR_TYPE_SOFT_INTR (4 << 8) /* software interrupt */
> -#define INTR_TYPE_PRIV_SW_EXCEPTION (5 << 8) /* ICE breakpoint - undocumented */
> -#define INTR_TYPE_SOFT_EXCEPTION (6 << 8) /* software exception */
> -#define INTR_TYPE_OTHER_EVENT (7 << 8) /* other event */
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] x86/trapnr: Add event type macros to <asm/trapnr.h>
2023-07-06 6:45 ` Peter Zijlstra
@ 2023-07-06 7:25 ` Li, Xin3
0 siblings, 0 replies; 3+ messages in thread
From: Li, Xin3 @ 2023-07-06 7:25 UTC (permalink / raw)
To: Peter Zijlstra
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org,
tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, hpa@zytor.com, Christopherson,, Sean,
pbonzini@redhat.com
> > +/*
> > + * Event type codes used by both Intel VT-x and FRED */
> > +/* Maskable external interrupt */
> > +#define EVENT_TYPE_HWINT 0
> > +#define EVENT_TYPE_RESERVED 1
> > +#define EVENT_TYPE_NMI 2
> > +/* Hardware exceptions (e.g., page fault) */
> > +#define EVENT_TYPE_HWFAULT 3
> > +/* Software interrupt (INT n) */
> > +#define EVENT_TYPE_SWINT 4
> > +/* INT1 (ICEBP) */
> > +#define EVENT_TYPE_PRIVSW 5
> > +/* Software exception (INT3 or INTO) */
> > +#define EVENT_TYPE_SWFAULT 6
> > +/* VT-x MTF or FRED SYSCALL/SYSENTER */
> > +#define EVENT_TYPE_OTHER 7
>
> So I know tglx hates on tail comments, but I find the below *MUCH* more readable
> than the above horror show.
Agree, sometimes a tail comment looks much better.
Maybe tglx could give more specific directions on when it's okay to use
tail comments.
Thanks!
Xin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-06 7:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-06 5:14 [PATCH] x86/trapnr: Add event type macros to <asm/trapnr.h> Xin Li
2023-07-06 6:45 ` Peter Zijlstra
2023-07-06 7:25 ` Li, Xin3
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox