[3/6] KVM: x86: Mark x2APIC DFR reg as non-existent for x2APIC

Message ID 20230107011025.565472-4-seanjc@google.com
State New
Headers
Series KVM: x86: x2APIC reserved bits/regs fixes |

Commit Message

Sean Christopherson Jan. 7, 2023, 1:10 a.m. UTC
  Mark APIC_DFR as being invalid/non-existent in x2APIC mode instead of
handling it as a one-off check in kvm_x2apic_msr_read().  This will allow
reusing "valid_reg_mask" to generate VMX's interception bitmaps for
x2APIC.  Handling DFR in the common read path may also fix the Hyper-V
PV MSR interface, if that can coexist with x2APIC.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/lapic.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
  

Comments

Maxim Levitsky Jan. 8, 2023, 4:43 p.m. UTC | #1
On Sat, 2023-01-07 at 01:10 +0000, Sean Christopherson wrote:
> Mark APIC_DFR as being invalid/non-existent in x2APIC mode instead of
> handling it as a one-off check in kvm_x2apic_msr_read().  This will allow
> reusing "valid_reg_mask" to generate VMX's interception bitmaps for
> x2APIC.  Handling DFR in the common read path may also fix the Hyper-V
> PV MSR interface, if that can coexist with x2APIC.
> 
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>  arch/x86/kvm/lapic.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index bf53e4752f30..c49b13418638 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -1541,7 +1541,6 @@ static int kvm_lapic_reg_read(struct kvm_lapic *apic, u32 offset, int len,
>  		APIC_REG_MASK(APIC_TASKPRI) |
>  		APIC_REG_MASK(APIC_PROCPRI) |
>  		APIC_REG_MASK(APIC_LDR) |
> -		APIC_REG_MASK(APIC_DFR) |
>  		APIC_REG_MASK(APIC_SPIV) |
>  		APIC_REGS_MASK(APIC_ISR, APIC_ISR_NR) |
>  		APIC_REGS_MASK(APIC_TMR, APIC_ISR_NR) |
> @@ -1562,12 +1561,13 @@ static int kvm_lapic_reg_read(struct kvm_lapic *apic, u32 offset, int len,
>  		valid_reg_mask |= APIC_REG_MASK(APIC_LVTCMCI);
>  
>  	/*
> -	 * ARBPRI and ICR2 are not valid in x2APIC mode.  WARN if KVM reads ICR
> -	 * in x2APIC mode as it's an 8-byte register in x2APIC and needs to be
> -	 * manually handled by the caller.
> +	 * ARBPRI, DFR, and ICR2 are not valid in x2APIC mode.  WARN if KVM
> +	 * reads ICR in x2APIC mode as it's an 8-byte register in x2APIC and
> +	 * needs to be manually handled by the caller.
>  	 */
>  	if (!apic_x2apic_mode(apic))
>  		valid_reg_mask |= APIC_REG_MASK(APIC_ARBPRI) |
> +				  APIC_REG_MASK(APIC_DFR) |
>  				  APIC_REG_MASK(APIC_ICR2);
>  	else
>  		WARN_ON_ONCE(offset == APIC_ICR);
> @@ -3141,9 +3141,6 @@ int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data)
>  	if (!lapic_in_kernel(vcpu) || !apic_x2apic_mode(apic))
>  		return 1;
>  
> -	if (reg == APIC_DFR)
> -		return 1;
> -
>  	return kvm_lapic_msr_read(apic, reg, data);
>  }
>  


Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Best regards,
	Maxim Levitsky
  

Patch

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index bf53e4752f30..c49b13418638 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1541,7 +1541,6 @@  static int kvm_lapic_reg_read(struct kvm_lapic *apic, u32 offset, int len,
 		APIC_REG_MASK(APIC_TASKPRI) |
 		APIC_REG_MASK(APIC_PROCPRI) |
 		APIC_REG_MASK(APIC_LDR) |
-		APIC_REG_MASK(APIC_DFR) |
 		APIC_REG_MASK(APIC_SPIV) |
 		APIC_REGS_MASK(APIC_ISR, APIC_ISR_NR) |
 		APIC_REGS_MASK(APIC_TMR, APIC_ISR_NR) |
@@ -1562,12 +1561,13 @@  static int kvm_lapic_reg_read(struct kvm_lapic *apic, u32 offset, int len,
 		valid_reg_mask |= APIC_REG_MASK(APIC_LVTCMCI);
 
 	/*
-	 * ARBPRI and ICR2 are not valid in x2APIC mode.  WARN if KVM reads ICR
-	 * in x2APIC mode as it's an 8-byte register in x2APIC and needs to be
-	 * manually handled by the caller.
+	 * ARBPRI, DFR, and ICR2 are not valid in x2APIC mode.  WARN if KVM
+	 * reads ICR in x2APIC mode as it's an 8-byte register in x2APIC and
+	 * needs to be manually handled by the caller.
 	 */
 	if (!apic_x2apic_mode(apic))
 		valid_reg_mask |= APIC_REG_MASK(APIC_ARBPRI) |
+				  APIC_REG_MASK(APIC_DFR) |
 				  APIC_REG_MASK(APIC_ICR2);
 	else
 		WARN_ON_ONCE(offset == APIC_ICR);
@@ -3141,9 +3141,6 @@  int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data)
 	if (!lapic_in_kernel(vcpu) || !apic_x2apic_mode(apic))
 		return 1;
 
-	if (reg == APIC_DFR)
-		return 1;
-
 	return kvm_lapic_msr_read(apic, reg, data);
 }