From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jason Gunthorpe Date: Sun, 3 Dec 2023 10:07:56 -0400 Subject: [PATCH 05/26] vfio: KVM: Pass get/put helpers from KVM to VFIO, don't do circular lookup In-Reply-To: References: <20230916003118.2540661-1-seanjc@google.com> <20230916003118.2540661-6-seanjc@google.com> <20230918152110.GI13795@ziepe.ca> <20230918160258.GL13795@ziepe.ca> Message-ID: <20231203140756.GI1489931@ziepe.ca> List-Id: To: kvm-riscv@lists.infradead.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Fri, Dec 01, 2023 at 04:51:55PM -0800, Sean Christopherson wrote: > There's one more wrinkle: this patch is buggy in that it doesn't ensure the liveliness > of KVM-the-module, i.e. nothing prevents userspace from unloading kvm.ko while VFIO > still holds a reference to a kvm structure, and so invoking ->put_kvm() could jump > into freed code. To fix that, KVM would also need to pass along a module pointer :-( Maybe we should be refcounting the struct file not the struct kvm? Then we don't need special helpers and it keeps the module alive correctly. Jason