Commit ed60920e authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini
Browse files

KVM: SVM: Use common kvm_apic_write_nodecode() for AVIC write traps



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: default avatarSean Christopherson <seanjc@google.com>
Message-Id: <20220204214205.3306634-5-seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent b031f104
Loading
Loading
Loading
Loading
+7 −9
Original line number Original line Diff line number Diff line
@@ -477,30 +477,28 @@ static void avic_handle_dfr_update(struct kvm_vcpu *vcpu)
	svm->dfr_reg = dfr;
	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 = to_svm(vcpu)->vmcb->control.exit_info_1 &
	u32 offset = svm->vmcb->control.exit_info_1 &
				AVIC_UNACCEL_ACCESS_OFFSET_MASK;
				AVIC_UNACCEL_ACCESS_OFFSET_MASK;


	switch (offset) {
	switch (offset) {
	case APIC_ID:
	case APIC_ID:
		if (avic_handle_apic_id_update(&svm->vcpu))
		if (avic_handle_apic_id_update(vcpu))
			return 0;
			return 0;
		break;
		break;
	case APIC_LDR:
	case APIC_LDR:
		if (avic_handle_ldr_update(&svm->vcpu))
		if (avic_handle_ldr_update(vcpu))
			return 0;
			return 0;
		break;
		break;
	case APIC_DFR:
	case APIC_DFR:
		avic_handle_dfr_update(&svm->vcpu);
		avic_handle_dfr_update(vcpu);
		break;
		break;
	default:
	default:
		break;
		break;
	}
	}


	kvm_lapic_reg_write(apic, offset, kvm_lapic_get_reg(apic, offset));
	kvm_apic_write_nodecode(vcpu, offset);

	return 1;
	return 1;
}
}


@@ -550,7 +548,7 @@ int avic_unaccelerated_access_interception(struct kvm_vcpu *vcpu)
	if (trap) {
	if (trap) {
		/* Handling Trap */
		/* Handling Trap */
		WARN_ONCE(!write, "svm: Handling trap read.\n");
		WARN_ONCE(!write, "svm: Handling trap read.\n");
		ret = avic_unaccel_trap_write(svm);
		ret = avic_unaccel_trap_write(vcpu);
	} else {
	} else {
		/* Handling Fault */
		/* Handling Fault */
		ret = kvm_emulate_instruction(vcpu, 0);
		ret = kvm_emulate_instruction(vcpu, 0);