mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tianyu Lan <Tianyu.Lan@microsoft.com>
To: Vitaly Kuznetsov <vkuznets@redhat.com>,
	Tianyu Lan <Tianyu.Lan@microsoft.com>
Cc: "pbonzini@redhat.com" <pbonzini@redhat.com>,
	"rkrcmar@redhat.com" <rkrcmar@redhat.com>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"x86@kernel.org" <x86@kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	KY Srinivasan <kys@microsoft.com>
Subject: Re: [RFC Patch 3/3] KVM/x86: Add tlb_remote_flush callback support for vmcs
Date: Thu, 14 Jun 2018 10:13:46 +0000	[thread overview]
Message-ID: <f868a339-03fc-4ba6-4882-4bb6232f599d@microsoft.com> (raw)
In-Reply-To: <87h8m8qbso.fsf@vitty.brq.redhat.com>

Hi Vitaly:
	Thanks for your review.

On 6/12/2018 11:12 PM, Vitaly Kuznetsov wrote:
> Tianyu Lan <Tianyu.Lan@microsoft.com> writes:
> 
>> Register tlb_remote_flush callback for vmcs when hyperv capability of
>> nested guest mapping flush is detected. The interface can help to reduce
>> overhead when flush ept table among vcpus for nested VM. The tradition way
>> is to send IPIs to all affected vcpus and executes INVEPT on each vcpus.
>> It will trigger several vmexits for IPI and INVEPT emulation. Hyperv provides
>> such hypercall to do flush for all vcpus.
>>
>> Signed-off-by: Lan Tianyu <Tianyu.Lan@microsoft.com>
>> ---
>>   arch/x86/kvm/vmx.c | 15 +++++++++++++++
>>   1 file changed, 15 insertions(+)
>>
>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>> index e50beb76d846..6cb241c05690 100644
>> --- a/arch/x86/kvm/vmx.c
>> +++ b/arch/x86/kvm/vmx.c
>> @@ -4737,6 +4737,17 @@ static inline void __vmx_flush_tlb(struct kvm_vcpu *vcpu, int vpid,
>>   	}
>>   }
>>
>> +static int vmx_remote_flush_tlb(struct kvm *kvm)
>> +{
>> +	struct kvm_vcpu *vcpu = kvm_get_vcpu(kvm, 0);
>> +
>> +	if (!VALID_PAGE(vcpu->arch.mmu.root_hpa))
>> +		return -1;
> 
> Why vcpu0? Can arch.mmu.root_hpa-s differ across vCPUs? What happens if
> they do?

Yes, it may take place that arch.mmu.root_hpa is differ across vCPUs.
We may check all vcpu root_hpa and use the hypercall when there is only 
one validated ept table. If not, go back to current way.

static int hv_remote_flush_tlb()
{
         struct kvm_vcpu *vcpu;
         u64 root_hpa = INVALID_PAGE;
         int i;

         kvm_for_each_vcpu(i, vcpu, kvm) {
                 if (!VALID_PAGE(vcpu->arch.mmu.root_hpa))
                         continue;

                 if (!VALID_PAGE(root_hpa))
                         root_hpa = vcpu->arch.mmu.root_hpa;
                 else if (root_hpa != vcpu->arch.mmu.root_hpa) {
                         return -1;
                 }
         }

         if (!VALID_PAGE(root_hpa))
                 return -1;

         return hyperv_flush_guest_mapping(construct_eptp(vcpu,
                 root_hpa));
}


> 
>> +
>> +	return hyperv_flush_guest_mapping(construct_eptp(vcpu,
>> +		vcpu->arch.mmu.root_hpa));
>> +}
> 
> The 'vmx_remote_flush_tlb' name looks generic enough but it is actually
> Hyper-V-specific. I'd suggest renaming to something like
> hv_remote_flush_tlb().
> 
>> +
>>   static void vmx_flush_tlb(struct kvm_vcpu *vcpu, bool invalidate_gpa)
>>   {
>>   	__vmx_flush_tlb(vcpu, to_vmx(vcpu)->vpid, invalidate_gpa);
>> @@ -7495,6 +7506,10 @@ static __init int hardware_setup(void)
>>   	if (enable_ept && !cpu_has_vmx_ept_2m_page())
>>   		kvm_disable_largepages();
>>
>> +	if (ms_hyperv.nested_features & HV_X64_NESTED_GUSET_MAPPING_FLUSH
>> +	    && enable_ept)
>> +		kvm_x86_ops->tlb_remote_flush = vmx_remote_flush_tlb;
>> +
>>   	if (!cpu_has_vmx_ple()) {
>>   		ple_gap = 0;
>>   		ple_window = 0;
> 

  reply	other threads:[~2018-06-14 10:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-04  9:08 [RFC Patch 0/3] KVM/x86/hyper-V: Introduce PV guest address space mapping flush support Tianyu Lan
2018-06-04  9:08 ` [RFC Patch 1/3] X86/Hyper-V: Add flush HvFlushGuestPhysicalAddressSpace hypercall support Tianyu Lan
2018-06-05 16:59   ` Michael Kelley (EOSG)
2018-06-06  5:36     ` Tianyu Lan
2018-06-04  9:08 ` [RFC Patch 2/3] KVM: Add tlb remote flush callback in kvm_x86_ops Tianyu Lan
2018-06-04  9:08 ` [RFC Patch 3/3] KVM/x86: Add tlb_remote_flush callback support for vmcs Tianyu Lan
2018-06-12 15:05   ` Vitaly Kuznetsov
2018-06-12 15:12   ` Vitaly Kuznetsov
2018-06-14 10:13     ` Tianyu Lan [this message]
2018-06-14 10:33       ` Vitaly Kuznetsov
2018-06-14 14:52         ` Tianyu Lan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f868a339-03fc-4ba6-4882-4bb6232f599d@microsoft.com \
    --to=tianyu.lan@microsoft.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@redhat.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome