From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C26254704A; Thu, 8 Oct 2026 06:00:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791439234; cv=none; b=t8rmmrMaA65vOzxdCfAiNUSiVYPzRZGFgMTWpcni9Vo7GZX5qF8yN+HMxuOtCn7DSkrm8wps+kfAJ5nckl8GOGR5oSYqhJXA4KGcGP6+oMJzc0HGuVubPdO/DtD/fv9X35OpQpnw+eog7HbXZxozyDicl2rAqNOVcIbiICIu8bE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791439234; c=relaxed/simple; bh=a1pw/P8Pmpkc4/sya8wZ0Nv6kBW0ruYgkp/ifPoOQJk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ETNccCqCv3/+cJRJ9Upjg5n+Ix2w7ClNR6bLE0ig37p1x4wo5tRjXkNsufWIEUSx3yZ+hc151JWkOQbL9OpZ/68JSbh6J1CZvl+AuFmaKjmg8u0NlmPdM3F1ayJWAr4RwFtR6ydKJQjubw0j0SiESVooTJikHwYUBTHiIP83VWE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KQ0uCr3L; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KQ0uCr3L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 124841F000FF; Thu, 8 Oct 2026 06:00:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1791439232; bh=5QMxcDy++DYkjJXJYZyvIubChEwATxZs066mDelscVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KQ0uCr3L3qdrwU76AqE7Yax2GKQ5TBVNbUqKyWl6e11lgT1BRT+w9mFT1WZsiMpJA iFdb1B7BMWnXopu7JN0QzFAZm3QT51V8USyWK/hdQt4RpD3RlCoc3ESjolneLIT+py a0l2Cla6XReu0i+VXbj0sQlaWfyj2HVcqgk9vPDYed7yuYtXS281pwpXO52SAv+1uk +qQhkCcu9PQ58JhKpqZfIVUNp1QrSU4x8NRaEIJLHUdfRBnmIFclD0KmSBHfPY+XUy CDxdJxBeBW1KCjoKx+J30KMJy3wVHEBaou6v+l6mrxZIPDjo4wilkf7KpWwehb1aO3 FfklXGdLqGCeg== From: "Aneesh Kumar K.V (Arm)" To: iommu@lists.linux.dev Cc: "Aneesh Kumar K.V (Arm)" , Alex Williamson , Alexey Kardashevskiy , Bjorn Helgaas , Catalin Marinas , Jacob Pan , Jason Gunthorpe , Joerg Roedel , Jonathan Cameron , Jonathan Hunter , Kevin Tian , Krishna Reddy , Lukas Wunner , Nicolin Chen , Robin Murphy , Samuel Ortiz , Shameer Kolothum , Steven Price , Suravee Suthikulpanit , Suzuki K Poulose , Thierry Reding , Vasant Hegde , Will Deacon , Xu Yilun , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-tegra@vger.kernel.org, Steffen Eiden , Sean Christopherson , Janosch Frank Subject: [PATCH v7 02/16] KVM: Add file back-pointer to struct kvm Date: Thu, 8 Oct 2026 11:29:41 +0530 Message-ID: <20261008055955.4014342-3-aneesh.kumar@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261008055955.4014342-1-aneesh.kumar@kernel.org> References: <20261008055955.4014342-1-aneesh.kumar@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Steffen Eiden Add kvm->file as a no-reference back-pointer to the VM file in struct kvm. The pointer is set at VM creation time and cleared under WRITE_ONCE() in kvm_vm_release() before the file is freed. Callers storing the file must take their own reference. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Steffen Eiden Acked-by: Sean Christopherson Acked-by: Janosch Frank --- include/linux/kvm_host.h | 6 ++++++ virt/kvm/kvm_main.c | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index bc3abfde8393..3c5a389361c6 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -784,6 +784,12 @@ struct kvm { * kvm_swap_active_memslots(). */ struct mutex slots_arch_lock; + /* + * Back-reference to the VM file for subsystems (e.g., VFIO). Holds no + * reference to avoid pinning the VM. Callers storing the file must + * take their own reference. + */ + struct file *file; struct mm_struct *mm; /* userspace tied to this vm */ unsigned long nr_memslot_pages; /* The two memslot sets - active and inactive (per address space) */ diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 07fc874a38e1..8e49ea809528 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1352,6 +1352,8 @@ static int kvm_vm_release(struct inode *inode, struct file *filp) kvm_irqfd_release(kvm); + WRITE_ONCE(kvm->file, NULL); + kvm_put_kvm(kvm); return 0; } @@ -5555,6 +5557,8 @@ static int kvm_dev_ioctl_create_vm(unsigned long type) goto put_kvm; } + kvm->file = file; + /* * Don't call kvm_put_kvm anymore at this point; file->f_op is * already set, with ->release() being kvm_vm_release(). In error -- 2.43.0