mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Al Viro <viro@zeniv.linux.org.uk>,
	David Matlack <dmatlack@google.com>
Subject: [PATCH 0/3] KVM: Fix KVM-owned file refcounting of KVM module(s)
Date: Wed, 18 Oct 2023 13:46:21 -0700	[thread overview]
Message-ID: <20231018204624.1905300-1-seanjc@google.com> (raw)

Clean up a KVM module refcounting mess that Al pointed out in the context
of the guest_memfd series.  The worst behavior was recently introduced by
an ill-fated attempt to fix a bug in x86's async #PF code.  Instead of
fixing the underlying bug of not flushing a workqueue (see patch 2), KVM
fudged around the bug by gifting every VM a reference to the KVM module.

That made the reproducer happy (hopefully there was actually a reproducer
at one point), but it didn't fully fix the use-after-free bug, it just made
the bug harder to hit.  E.g. as pointed out by Al, if kvm_destroy_vm() is
preempted after putting the last KVM module reference, KVM can be unloaded
before kvm_destroy_vm() completes, and scheduling back in the associated
task will explode (preemption isn't strictly required, it's just the most
obvious path to failure).

Then after applying that "fix", we/I made an even bigger goof by relying on
the nonexistent "protection" provided by the VM's reference and removed the
code which guaranteed that the KVM module would be pinned until *after* the
last reference to a KVM-owned file was put.

Undo the mess we created and fix the original async #PF workqueue bug.

Sean Christopherson (3):
  KVM: Set file_operations.owner appropriately for all such structures
  KVM: Always flush async #PF workqueue when vCPU is being destroyed
  Revert "KVM: Prevent module exit until all VMs are freed"

 arch/x86/kvm/debugfs.c |  1 +
 virt/kvm/async_pf.c    | 15 ++++++++++++---
 virt/kvm/kvm_main.c    | 18 ++++++++----------
 3 files changed, 21 insertions(+), 13 deletions(-)


base-commit: 437bba5ad2bba00c2056c896753a32edf80860cc
-- 
2.42.0.655.g421f12c284-goog


             reply	other threads:[~2023-10-18 20:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-18 20:46 Sean Christopherson [this message]
2023-10-18 20:46 ` [PATCH 1/3] KVM: Set file_operations.owner appropriately for all such structures Sean Christopherson
2023-10-18 20:46 ` [PATCH 2/3] KVM: Always flush async #PF workqueue when vCPU is being destroyed Sean Christopherson
2023-10-23 18:24   ` David Matlack
2023-10-24  8:21   ` Xu Yilun
2023-10-24 15:49     ` Sean Christopherson
2023-10-25  4:25       ` Xu Yilun
2023-10-18 20:46 ` [PATCH 3/3] Revert "KVM: Prevent module exit until all VMs are freed" Sean Christopherson
2023-12-01 23:30 ` [PATCH 0/3] KVM: Fix KVM-owned file refcounting of KVM module(s) Sean Christopherson

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=20231018204624.1905300-1-seanjc@google.com \
    --to=seanjc@google.com \
    --cc=dmatlack@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=viro@zeniv.linux.org.uk \
    /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®