* [PATCH] KVM: VMX: Add helpers to identify interrupt type from intr_info
@ 2020-06-09 1:45 Sean Christopherson
2020-06-15 16:12 ` Paolo Bonzini
0 siblings, 1 reply; 2+ messages in thread
From: Sean Christopherson @ 2020-06-09 1:45 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, kvm, linux-kernel
Add is_intr_type() and is_intr_type_n() to consolidate the boilerplate
code for querying a specific type of interrupt given an encoded value
from VMCS.VM_{ENTER,EXIT}_INTR_INFO, with and without an associated
vector respectively.
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
I wrote and proposed a version of this patch a while back[*], but AFAICT
never posted it as a formal patch.
[*] https://lkml.kernel.org/r/20190819233537.GG1916@linux.intel.com
arch/x86/kvm/vmx/vmcs.h | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/arch/x86/kvm/vmx/vmcs.h b/arch/x86/kvm/vmx/vmcs.h
index 5c0ff80b85c0..7a3675fddec2 100644
--- a/arch/x86/kvm/vmx/vmcs.h
+++ b/arch/x86/kvm/vmx/vmcs.h
@@ -72,11 +72,24 @@ struct loaded_vmcs {
struct vmcs_controls_shadow controls_shadow;
};
+static inline bool is_intr_type(u32 intr_info, u32 type)
+{
+ const u32 mask = INTR_INFO_VALID_MASK | INTR_INFO_INTR_TYPE_MASK;
+
+ return (intr_info & mask) == (INTR_INFO_VALID_MASK | type);
+}
+
+static inline bool is_intr_type_n(u32 intr_info, u32 type, u8 vector)
+{
+ const u32 mask = INTR_INFO_VALID_MASK | INTR_INFO_INTR_TYPE_MASK |
+ INTR_INFO_VECTOR_MASK;
+
+ return (intr_info & mask) == (INTR_INFO_VALID_MASK | type | vector);
+}
+
static inline bool is_exception_n(u32 intr_info, u8 vector)
{
- return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VECTOR_MASK |
- INTR_INFO_VALID_MASK)) ==
- (INTR_TYPE_HARD_EXCEPTION | vector | INTR_INFO_VALID_MASK);
+ return is_intr_type_n(intr_info, INTR_TYPE_HARD_EXCEPTION, vector);
}
static inline bool is_debug(u32 intr_info)
@@ -106,28 +119,23 @@ static inline bool is_gp_fault(u32 intr_info)
static inline bool is_machine_check(u32 intr_info)
{
- return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VECTOR_MASK |
- INTR_INFO_VALID_MASK)) ==
- (INTR_TYPE_HARD_EXCEPTION | MC_VECTOR | INTR_INFO_VALID_MASK);
+ return is_exception_n(intr_info, MC_VECTOR);
}
/* Undocumented: icebp/int1 */
static inline bool is_icebp(u32 intr_info)
{
- return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VALID_MASK))
- == (INTR_TYPE_PRIV_SW_EXCEPTION | INTR_INFO_VALID_MASK);
+ return is_intr_type(intr_info, INTR_TYPE_PRIV_SW_EXCEPTION);
}
static inline bool is_nmi(u32 intr_info)
{
- return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VALID_MASK))
- == (INTR_TYPE_NMI_INTR | INTR_INFO_VALID_MASK);
+ return is_intr_type(intr_info, INTR_TYPE_NMI_INTR);
}
static inline bool is_external_intr(u32 intr_info)
{
- return (intr_info & (INTR_INFO_VALID_MASK | INTR_INFO_INTR_TYPE_MASK))
- == (INTR_INFO_VALID_MASK | INTR_TYPE_EXT_INTR);
+ return is_intr_type(intr_info, INTR_TYPE_EXT_INTR);
}
enum vmcs_field_width {
--
2.26.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] KVM: VMX: Add helpers to identify interrupt type from intr_info
2020-06-09 1:45 [PATCH] KVM: VMX: Add helpers to identify interrupt type from intr_info Sean Christopherson
@ 2020-06-15 16:12 ` Paolo Bonzini
0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2020-06-15 16:12 UTC (permalink / raw)
To: Sean Christopherson
Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
linux-kernel
On 09/06/20 03:45, Sean Christopherson wrote:
> Add is_intr_type() and is_intr_type_n() to consolidate the boilerplate
> code for querying a specific type of interrupt given an encoded value
> from VMCS.VM_{ENTER,EXIT}_INTR_INFO, with and without an associated
> vector respectively.
>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
>
> I wrote and proposed a version of this patch a while back[*], but AFAICT
> never posted it as a formal patch.
>
> [*] https://lkml.kernel.org/r/20190819233537.GG1916@linux.intel.com
>
> arch/x86/kvm/vmx/vmcs.h | 32 ++++++++++++++++++++------------
> 1 file changed, 20 insertions(+), 12 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx/vmcs.h b/arch/x86/kvm/vmx/vmcs.h
> index 5c0ff80b85c0..7a3675fddec2 100644
> --- a/arch/x86/kvm/vmx/vmcs.h
> +++ b/arch/x86/kvm/vmx/vmcs.h
> @@ -72,11 +72,24 @@ struct loaded_vmcs {
> struct vmcs_controls_shadow controls_shadow;
> };
>
> +static inline bool is_intr_type(u32 intr_info, u32 type)
> +{
> + const u32 mask = INTR_INFO_VALID_MASK | INTR_INFO_INTR_TYPE_MASK;
> +
> + return (intr_info & mask) == (INTR_INFO_VALID_MASK | type);
> +}
> +
> +static inline bool is_intr_type_n(u32 intr_info, u32 type, u8 vector)
> +{
> + const u32 mask = INTR_INFO_VALID_MASK | INTR_INFO_INTR_TYPE_MASK |
> + INTR_INFO_VECTOR_MASK;
> +
> + return (intr_info & mask) == (INTR_INFO_VALID_MASK | type | vector);
> +}
> +
> static inline bool is_exception_n(u32 intr_info, u8 vector)
> {
> - return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VECTOR_MASK |
> - INTR_INFO_VALID_MASK)) ==
> - (INTR_TYPE_HARD_EXCEPTION | vector | INTR_INFO_VALID_MASK);
> + return is_intr_type_n(intr_info, INTR_TYPE_HARD_EXCEPTION, vector);
> }
>
> static inline bool is_debug(u32 intr_info)
> @@ -106,28 +119,23 @@ static inline bool is_gp_fault(u32 intr_info)
>
> static inline bool is_machine_check(u32 intr_info)
> {
> - return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VECTOR_MASK |
> - INTR_INFO_VALID_MASK)) ==
> - (INTR_TYPE_HARD_EXCEPTION | MC_VECTOR | INTR_INFO_VALID_MASK);
> + return is_exception_n(intr_info, MC_VECTOR);
> }
>
> /* Undocumented: icebp/int1 */
> static inline bool is_icebp(u32 intr_info)
> {
> - return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VALID_MASK))
> - == (INTR_TYPE_PRIV_SW_EXCEPTION | INTR_INFO_VALID_MASK);
> + return is_intr_type(intr_info, INTR_TYPE_PRIV_SW_EXCEPTION);
> }
>
> static inline bool is_nmi(u32 intr_info)
> {
> - return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VALID_MASK))
> - == (INTR_TYPE_NMI_INTR | INTR_INFO_VALID_MASK);
> + return is_intr_type(intr_info, INTR_TYPE_NMI_INTR);
> }
>
> static inline bool is_external_intr(u32 intr_info)
> {
> - return (intr_info & (INTR_INFO_VALID_MASK | INTR_INFO_INTR_TYPE_MASK))
> - == (INTR_INFO_VALID_MASK | INTR_TYPE_EXT_INTR);
> + return is_intr_type(intr_info, INTR_TYPE_EXT_INTR);
> }
>
> enum vmcs_field_width {
>
Queued, thnkas.
Paolo
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-15 16:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-09 1:45 [PATCH] KVM: VMX: Add helpers to identify interrupt type from intr_info Sean Christopherson
2020-06-15 16:12 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).