All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Ben Gardon <bgardon@google.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	Paolo Bonzini <pbonzini@redhat.com>,
	David Matlack <dmatlack@google.com>,
	Anish Ghulati <aghulati@google.com>
Subject: Re: [PATCH] KVM: x86: Use SRCU to protect zap in __kvm_set_or_clear_apicv_inhibit
Date: Wed, 2 Nov 2022 19:47:20 +0000	[thread overview]
Message-ID: <Y2LJSE5nuHZJV7fF@google.com> (raw)
In-Reply-To: <20221102193020.1091939-1-bgardon@google.com>

On Wed, Nov 02, 2022, Ben Gardon wrote:
> kvm_zap_gfn_range must be called in an SRCU read-critical section, but

Please add parantheses when referencing functions, i.e. kvm_zap_gfn_range().

> there is no SRCU annotation in __kvm_set_or_clear_apicv_inhibit.

__kvm_set_or_clear_apicv_inhibit()

> Add the needed SRCU annotation.

It's not an annotation, acquiring SRCU is very much functional code.

> Tested: ran tools/testing/selftests/kvm/x86_64/debug_regs on a DBG
> 	build. This patch causes the suspicious RCU warning to disappear.
> 	Note that the warning is hit in __kvm_zap_rmaps, so
> 	kvm_memslots_have_rmaps must return true in order for this to
> 	repro (i.e. the TDP MMU must be off or nesting in use.)

Please provide the stack trace or at least a verbal description of what paths
can reach __kvm_set_or_clear_apicv_inhibit() without holding SRCU, i.e. explain
why this bug isn't being hit left and right.

E.g.

  Unconditionally take KVM's SRCU lock in __kvm_set_or_clear_apicv_inhibit()
  when zapping virtual APIC SPTEs.  SRCU must be held when zapping SPTEs in
  shadow MMUs to protect the gfn=>memslot translation (the TDP MMU walks all
  roots and so doesn't dereference memslots).

  In most cases, the inhibits are updated during KVM_RUN and so SRCU is
  already held, but other ioctls() can also modify inhibits and don't
  acquire SRCU, e.g. KVM_SET_GUEST_DEBUG and KVM_SET_LAPIC.  Acquire SRCU
  unconditionally to avoid playing whack-a-mole, as nesting SRCU locks is
  safe and this is not a hot path.

> Fixes: 36222b117e36 ("KVM: x86: don't disable APICv memslot when inhibited")

Reported-by?  IIRC this originated in a syzkaller report?

  reply	other threads:[~2022-11-02 19:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-02 19:30 [PATCH] KVM: x86: Use SRCU to protect zap in __kvm_set_or_clear_apicv_inhibit Ben Gardon
2022-11-02 19:47 ` Sean Christopherson [this message]
2022-11-02 20:39   ` Ben Gardon

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=Y2LJSE5nuHZJV7fF@google.com \
    --to=seanjc@google.com \
    --cc=aghulati@google.com \
    --cc=bgardon@google.com \
    --cc=dmatlack@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.