lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <55ef796b-6433-b72f-6f5c-b7499284c9a4@redhat.com>
Date:   Sat, 19 Feb 2022 11:03:49 +0100
From:   Paolo Bonzini <pbonzini@...hat.com>
To:     Sean Christopherson <seanjc@...gle.com>
Cc:     linux-kernel@...r.kernel.org, kvm@...r.kernel.org
Subject: Re: [PATCH v2 14/18] KVM: x86/mmu: avoid indirect call for get_cr3

On 2/18/22 21:30, Sean Christopherson wrote:
> On Thu, Feb 17, 2022, Paolo Bonzini wrote:
>> Most of the time, calls to get_guest_pgd result in calling
>> kvm_read_cr3 (the exception is only nested TDP).  Hardcode
>> the default instead of using the get_cr3 function, avoiding
>> a retpoline if they are enabled.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@...hat.com>
>> ---
>>   arch/x86/kvm/mmu.h             | 13 +++++++++++++
>>   arch/x86/kvm/mmu/mmu.c         | 15 +++++----------
>>   arch/x86/kvm/mmu/paging_tmpl.h |  2 +-
>>   arch/x86/kvm/x86.c             |  2 +-
>>   4 files changed, 20 insertions(+), 12 deletions(-)
>>
>> diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
>> index 1d0c1904d69a..1808d6814ddb 100644
>> --- a/arch/x86/kvm/mmu.h
>> +++ b/arch/x86/kvm/mmu.h
>> @@ -116,6 +116,19 @@ static inline void kvm_mmu_load_pgd(struct kvm_vcpu *vcpu)
>>   					  vcpu->arch.mmu->shadow_root_level);
>>   }
>>   
>> +static inline gpa_t __kvm_mmu_get_guest_pgd(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu)
>> +{
> 
> I'd prefer to do what we do for page faults.  That approach avoids the need for a
> comment to document NULL and avoids a conditional when RETPOLINE is not enabled.
> 
> Might be worth renaming get_cr3 => get_guest_cr3 though.

I did it this way to avoid a slightly gratuitous extern function just 
because kvm_mmu_get_guest_pgd and kvm_read_cr3 are both inline.  But at 
least it's not an export since there are no callers in vmx/svm, so it's 
okay to do it as you suggested.

> #ifdef CONFIG_RETPOLINE
> 	if (mmu->get_guest_pgd = get_guest_cr3)
> 		return kvm_read_cr3(vcpu);
> #endif
> 	return mmu->get_guest_pgd(vcpu);
> 
> 
>> +	if (!mmu->get_guest_pgd)
>> +		return kvm_read_cr3(vcpu);
>> +	else
>> +		return mmu->get_guest_pgd(vcpu);
>> +}
>> +
>> +static inline gpa_t kvm_mmu_get_guest_pgd(struct kvm_vcpu *vcpu)
>> +{
>> +	return __kvm_mmu_get_guest_pgd(vcpu, vcpu->arch.mmu);
> 
> I'd much prefer we don't provide an @vcpu-only variant and force the caller to
> provide the mmu.

No problem.

Paolo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ