diff mbox series

[04/11] KVM: SVM: Use common kvm_apic_write_nodecode() for AVIC write traps

Message ID 20220204214205.3306634-5-seanjc@google.com (mailing list archive)
State New, archived
Headers show
Series KVM: x86: Prep work for VMX IPI virtualization | expand

Commit Message

Sean Christopherson Feb. 4, 2022, 9:41 p.m. UTC
Use the common kvm_apic_write_nodecode() to handle AVIC/APIC-write traps
instead of open coding the same exact code.  This will allow making the
low level lapic helpers inaccessible outside of lapic.c code.

Opportunistically clean up the params to eliminate a bunch of svm=>vcpu
reflection.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/svm/avic.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Comments

kernel test robot Feb. 4, 2022, 11:14 p.m. UTC | #1
Hi Sean,

I love your patch! Yet something to improve:

[auto build test ERROR on 17179d0068b20413de2355f84c75a93740257e20]

url:    https://github.com/0day-ci/linux/commits/Sean-Christopherson/KVM-x86-Prep-work-for-VMX-IPI-virtualization/20220205-054418
base:   17179d0068b20413de2355f84c75a93740257e20
config: x86_64-allmodconfig (https://download.01.org/0day-ci/archive/20220205/202202050720.YPm113nN-lkp@intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/528172fca9c0e8fac06680430bf69a55e4559974
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Sean-Christopherson/KVM-x86-Prep-work-for-VMX-IPI-virtualization/20220205-054418
        git checkout 528172fca9c0e8fac06680430bf69a55e4559974
        # save the config file to linux build tree
        mkdir build_dir
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash arch/x86/kvm/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   arch/x86/kvm/svm/avic.c: In function 'avic_unaccel_trap_write':
>> arch/x86/kvm/svm/avic.c:486:35: error: 'svm' undeclared (first use in this function); did you mean 'sem'?
     486 |   if (avic_handle_apic_id_update(&svm->vcpu))
         |                                   ^~~
         |                                   sem
   arch/x86/kvm/svm/avic.c:486:35: note: each undeclared identifier is reported only once for each function it appears in


vim +486 arch/x86/kvm/svm/avic.c

ef0f64960d012cb Joerg Roedel        2020-03-31  478  
528172fca9c0e8f Sean Christopherson 2022-02-04  479  static int avic_unaccel_trap_write(struct kvm_vcpu *vcpu)
ef0f64960d012cb Joerg Roedel        2020-03-31  480  {
528172fca9c0e8f Sean Christopherson 2022-02-04  481  	u32 offset = to_svm(vcpu)->vmcb->control.exit_info_1 &
ef0f64960d012cb Joerg Roedel        2020-03-31  482  				AVIC_UNACCEL_ACCESS_OFFSET_MASK;
ef0f64960d012cb Joerg Roedel        2020-03-31  483  
ef0f64960d012cb Joerg Roedel        2020-03-31  484  	switch (offset) {
ef0f64960d012cb Joerg Roedel        2020-03-31  485  	case APIC_ID:
ef0f64960d012cb Joerg Roedel        2020-03-31 @486  		if (avic_handle_apic_id_update(&svm->vcpu))
ef0f64960d012cb Joerg Roedel        2020-03-31  487  			return 0;
ef0f64960d012cb Joerg Roedel        2020-03-31  488  		break;
ef0f64960d012cb Joerg Roedel        2020-03-31  489  	case APIC_LDR:
528172fca9c0e8f Sean Christopherson 2022-02-04  490  		if (avic_handle_ldr_update(vcpu))
ef0f64960d012cb Joerg Roedel        2020-03-31  491  			return 0;
ef0f64960d012cb Joerg Roedel        2020-03-31  492  		break;
ef0f64960d012cb Joerg Roedel        2020-03-31  493  	case APIC_DFR:
528172fca9c0e8f Sean Christopherson 2022-02-04  494  		avic_handle_dfr_update(vcpu);
ef0f64960d012cb Joerg Roedel        2020-03-31  495  		break;
ef0f64960d012cb Joerg Roedel        2020-03-31  496  	default:
ef0f64960d012cb Joerg Roedel        2020-03-31  497  		break;
ef0f64960d012cb Joerg Roedel        2020-03-31  498  	}
ef0f64960d012cb Joerg Roedel        2020-03-31  499  
528172fca9c0e8f Sean Christopherson 2022-02-04  500  	kvm_apic_write_nodecode(vcpu, offset);
ef0f64960d012cb Joerg Roedel        2020-03-31  501  	return 1;
ef0f64960d012cb Joerg Roedel        2020-03-31  502  }
ef0f64960d012cb Joerg Roedel        2020-03-31  503  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Sean Christopherson Feb. 7, 2022, 4:16 p.m. UTC | #2
On Sat, Feb 05, 2022, kernel test robot wrote:
> All errors (new ones prefixed by >>):
> 
>    arch/x86/kvm/svm/avic.c: In function 'avic_unaccel_trap_write':
> >> arch/x86/kvm/svm/avic.c:486:35: error: 'svm' undeclared (first use in this function); did you mean 'sem'?
>      486 |   if (avic_handle_apic_id_update(&svm->vcpu))
>          |                                   ^~~
>          |                                   sem
>    arch/x86/kvm/svm/avic.c:486:35: note: each undeclared identifier is reported only once for each function it appears in
> 
> 
> vim +486 arch/x86/kvm/svm/avic.c
> 
> ef0f64960d012cb Joerg Roedel        2020-03-31  478  
> 528172fca9c0e8f Sean Christopherson 2022-02-04  479  static int avic_unaccel_trap_write(struct kvm_vcpu *vcpu)
> ef0f64960d012cb Joerg Roedel        2020-03-31  480  {
> 528172fca9c0e8f Sean Christopherson 2022-02-04  481  	u32 offset = to_svm(vcpu)->vmcb->control.exit_info_1 &
> ef0f64960d012cb Joerg Roedel        2020-03-31  482  				AVIC_UNACCEL_ACCESS_OFFSET_MASK;
> ef0f64960d012cb Joerg Roedel        2020-03-31  483  
> ef0f64960d012cb Joerg Roedel        2020-03-31  484  	switch (offset) {
> ef0f64960d012cb Joerg Roedel        2020-03-31  485  	case APIC_ID:
> ef0f64960d012cb Joerg Roedel        2020-03-31 @486  		if (avic_handle_apic_id_update(&svm->vcpu))
> ef0f64960d012cb Joerg Roedel        2020-03-31  487  			return 0;

Doh, I did all my testing with avic_handle_apic_id_update() completely removed
(because it's broken), but obviously forgot to rebuild without that patch when
posting.
diff mbox series

Patch

diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c
index ecc81c48c0ca..462ab073db38 100644
--- a/arch/x86/kvm/svm/avic.c
+++ b/arch/x86/kvm/svm/avic.c
@@ -476,10 +476,9 @@  static void avic_handle_dfr_update(struct kvm_vcpu *vcpu)
 	svm->dfr_reg = dfr;
 }
 
-static int avic_unaccel_trap_write(struct vcpu_svm *svm)
+static int avic_unaccel_trap_write(struct kvm_vcpu *vcpu)
 {
-	struct kvm_lapic *apic = svm->vcpu.arch.apic;
-	u32 offset = svm->vmcb->control.exit_info_1 &
+	u32 offset = to_svm(vcpu)->vmcb->control.exit_info_1 &
 				AVIC_UNACCEL_ACCESS_OFFSET_MASK;
 
 	switch (offset) {
@@ -488,18 +487,17 @@  static int avic_unaccel_trap_write(struct vcpu_svm *svm)
 			return 0;
 		break;
 	case APIC_LDR:
-		if (avic_handle_ldr_update(&svm->vcpu))
+		if (avic_handle_ldr_update(vcpu))
 			return 0;
 		break;
 	case APIC_DFR:
-		avic_handle_dfr_update(&svm->vcpu);
+		avic_handle_dfr_update(vcpu);
 		break;
 	default:
 		break;
 	}
 
-	kvm_lapic_reg_write(apic, offset, kvm_lapic_get_reg(apic, offset));
-
+	kvm_apic_write_nodecode(vcpu, offset);
 	return 1;
 }
 
@@ -549,7 +547,7 @@  int avic_unaccelerated_access_interception(struct kvm_vcpu *vcpu)
 	if (trap) {
 		/* Handling Trap */
 		WARN_ONCE(!write, "svm: Handling trap read.\n");
-		ret = avic_unaccel_trap_write(svm);
+		ret = avic_unaccel_trap_write(vcpu);
 	} else {
 		/* Handling Fault */
 		ret = kvm_emulate_instruction(vcpu, 0);