mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maxim Levitsky <mlevitsk@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 0/4] KVM: x86: APICv cleanups
Date: Fri, 22 Oct 2021 17:56:54 +0300	[thread overview]
Message-ID: <9c159d2f23dc3957a2fda0301b25fca67aa21b30.camel@redhat.com> (raw)
In-Reply-To: <23d9b009-2b48-d93c-3c24-711c4757ca1b@redhat.com>

On Fri, 2021-10-22 at 12:12 +0200, Paolo Bonzini wrote:
> On 22/10/21 02:49, Sean Christopherson wrote:
> > APICv cleanups and a dissertation on handling concurrent APIC access page
> > faults and APICv inhibit updates.
> > 
> > I've tested this but haven't hammered the AVIC stuff, I'd appreciate it if
> > someone with the Hyper-V setup can beat on the AVIC toggling.
> > 
> > Sean Christopherson (4):
> >    KVM: x86/mmu: Use vCPU's APICv status when handling APIC_ACCESS
> >      memslot
> >    KVM: x86: Move SVM's APICv sanity check to common x86
> >    KVM: x86: Move apicv_active flag from vCPU to in-kernel local APIC
> >    KVM: x86: Use rw_semaphore for APICv lock to allow vCPU parallelism
> > 
> >   arch/x86/include/asm/kvm_host.h |  3 +-
> >   arch/x86/kvm/hyperv.c           |  4 +--
> >   arch/x86/kvm/lapic.c            | 46 ++++++++++---------------
> >   arch/x86/kvm/lapic.h            |  5 +--
> >   arch/x86/kvm/mmu/mmu.c          | 29 ++++++++++++++--
> >   arch/x86/kvm/svm/avic.c         |  2 +-
> >   arch/x86/kvm/svm/svm.c          |  2 --
> >   arch/x86/kvm/vmx/vmx.c          |  4 +--
> >   arch/x86/kvm/x86.c              | 59 ++++++++++++++++++++++-----------
> >   9 files changed, 93 insertions(+), 61 deletions(-)
> > 
> 
> Queued, thanks.  I only made small edits to the comment in patch
> 1, to make it very slightly shorter.
> 
> 	 * 2a. APICv is globally disabled but locally enabled, and this
> 	 *     vCPU acquires mmu_lock before __kvm_request_apicv_update
> 	 *     calls kvm_zap_gfn_range().  This vCPU will install a stale
> 	 *     SPTE, but no one will consume it as (a) no vCPUs can be
> 	 *     running due to the kick from KVM_REQ_APICV_UPDATE, and
> 	 *     (b) because KVM_REQ_APICV_UPDATE is raised before the VM
> 	 *     state is update, vCPUs attempting to service the request
> 	 *     will block on apicv_update_lock.  The update flow will
> 	 *     then zap the SPTE and release the lock.
> 
> Paolo
> 

Hi Paolo and Sean!

Could you expalain to me why the scenario when  I expalined about in my reply previous version of patch 1
is not correct?

This is the scenario I was worried about:



    vCPU0                                   vCPU1
    =====                                   =====

- disable AVIC
- VMRUN
                                        - #NPT on AVIC MMIO access
                                        - *stuck on something prior to the page fault code*
- enable AVIC
- VMRUN
                                        - *still stuck on something prior to the page fault code*

- disable AVIC:

  - raise KVM_REQ_APICV_UPDATE request
                                        
  - set global avic state to disable

  - zap the SPTE (does nothing, doesn't race
        with anything either)

  - handle KVM_REQ_APICV_UPDATE -
    - disable vCPU0 AVIC

- VMRUN
                                        - *still stuck on something prior to the page fault code*

                                                            ...
                                                            ...
                                                            ...

                                        - now vCPU1 finally starts running the page fault code.

                                        - vCPU1 AVIC is still enabled 
                                          (because vCPU1 never handled KVM_REQ_APICV_UPDATE),
                                          so the page fault code will populate the SPTE.
                                          

                                        - handle KVM_REQ_APICV_UPDATE
                                           - finally disable vCPU1 AVIC

                                        - VMRUN (vCPU1 AVIC disabled, SPTE populated)

                                                         ***boom***



Best regards,
	Maxim Levitsky


  reply	other threads:[~2021-10-22 14:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-22  0:49 Sean Christopherson
2021-10-22  0:49 ` [PATCH v2 1/4] KVM: x86/mmu: Use vCPU's APICv status when handling APIC_ACCESS memslot Sean Christopherson
2021-10-22  0:49 ` [PATCH v2 2/4] KVM: x86: Move SVM's APICv sanity check to common x86 Sean Christopherson
2021-10-22  0:49 ` [PATCH v2 3/4] KVM: x86: Move apicv_active flag from vCPU to in-kernel local APIC Sean Christopherson
2021-10-22  0:49 ` [PATCH v2 4/4] KVM: x86: Use rw_semaphore for APICv lock to allow vCPU parallelism Sean Christopherson
2021-10-22 10:12 ` [PATCH v2 0/4] KVM: x86: APICv cleanups Paolo Bonzini
2021-10-22 14:56   ` Maxim Levitsky [this message]
2021-10-22 16:43     ` Paolo Bonzini
2021-10-25 14:35       ` Sean Christopherson
2021-10-25 15:21         ` Paolo Bonzini
2021-10-25 15:59           ` Sean Christopherson
2021-10-25 16:05             ` Paolo Bonzini

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=9c159d2f23dc3957a2fda0301b25fca67aa21b30.camel@redhat.com \
    --to=mlevitsk@redhat.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    /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

all inboxes | Powered by JetHome®