From nobody Thu Sep 24 12:05:52 2026 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 D3BD5407CF1; Thu, 24 Sep 2026 08:59:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790240343; cv=none; b=QGmdJkZvDOQapP2KgwG2p+wBUxePB5b/WEFVInPPCfgh7uw8ubYmKldyduh9EVl01R+CwgKLH1sqcRjJwZHH3/z2FIUnJu1OdHsQebzABZOM95OutVg6IEGsGywbPFWodHOsvMHy4dkNuVmh2xUsHm5YpGj32m8M9k59b73XzGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790240343; c=relaxed/simple; bh=N5xjJ43H6LVIEP47qdjzgN2ngxPJH/ZqiqzQ7X5Sqi4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L90SIFxLmDDuuqZ8034uRezp07dlQFTXaTddcEfLlsaTkCd5Qal3AHWpI6E05juPeuIZ1x8ofPHvUXpn1ZdeINoAUM3JWk5mK3HdFoI7LE+ct0yfhfbk+aH+8/v3OuRSf0/iFyxxy4NFg1wF1Typfd1KOGok/KuhAjt96/QnvbE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=N76B7Aj9; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="N76B7Aj9" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 68O5bcc41334222; Thu, 24 Sep 2026 08:58:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=AfwhzV SUaurBzJJbI5e3/z081SfoueGXHXFoKKsRDgo=; b=N76B7Aj9cghQK62Algyacc uYyZZAKgYR9aneBT34BSMxprnS12uAkyyI01L1q3ouYwis8iWn2YCBJ0MU2FSc6h sFxyhwGCTi2wmkjvxVOfxc4nOmnEVlkTFEcMbjY+2eOQVvNF9CRwHHMO0J0lkAx+ lxFGq/5fkW0iS5GmRQONEkQpk3bmbbjx8a9sMw5Agk5KKylhmfBHN4LtZjQQCjNI dHtjXLT54pYbkvzoWG+scWWLEf6Qdrh8l96R6miHenCsWywvUoe2sVayz2k+EcR8 G6IBH/SZh/UzIT3KcKJI0ki1YPzO+0cXdptYZSPcFKpo9N09vSgTNCwPOSU3c6NA == Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4gskgsfxv9-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Sep 2026 08:58:44 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 68O5ln1M1497550; Thu, 24 Sep 2026 08:58:43 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4gvbu8vsm8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Sep 2026 08:58:43 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 68O8wdXO27066708 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Sep 2026 08:58:39 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6303B20040; Thu, 24 Sep 2026 08:58:39 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1C1E52004E; Thu, 24 Sep 2026 08:58:39 +0000 (GMT) Received: from [127.0.1.1] (unknown [9.87.85.9]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 24 Sep 2026 08:58:39 +0000 (GMT) From: Steffen Eiden Date: Thu, 24 Sep 2026 10:58:30 +0200 Subject: [PATCH v3 1/5] KVM: Introduce file_to_kvm_() infrastructure Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260924-vfio-v3-1-4a294307797b@linux.ibm.com> References: <20260924-vfio-v3-0-4a294307797b@linux.ibm.com> In-Reply-To: <20260924-vfio-v3-0-4a294307797b@linux.ibm.com> To: Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Matthew Rosato , Farhan Ali , Eric Farman , Tony Krowiak , Halil Pasic , Jason Herne , Harald Freudenberger , Holger Dengler , Alex Williamson Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Steffen Eiden X-Mailer: b4 0.14.3 X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=V/XoQuni c=1 sm=1 tr=0 ts=6ab4e644 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=IkcTkHD0fZMA:10 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=1XWaLZrsAAAA:8 a=VnNF1IyMAAAA:8 a=VUxmUKdmKFa5Qofq_fQA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-ORIG-GUID: uLuEqufaIZ5cs6NYHZQ9U-l5gHNBpHat X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTI0MDAzNiBTYWx0ZWRfX1gL9LwzebFpf UQ5EwtFcQeIWml0jVpycKvVrAKxLsoThRLGTo5WCK5s5sDRk3xSo+lvJQq4PlADil9FlF2fsf85 So6H1qP+pVj6fjo1cT4JiNTAcO4+dj2Ij7Uh/yFPZIjYTVGE5JKb41NSkzLDjeJuNUSpzOx+2vQ WUXcp4C1XqU/91Dr/xaXF3xkuhEy0Zwn54n8nm43UbAG3UN3SYlTgOdkUWNYakP9zicM7KPXn/U 7Hjtc0P+CioVo1pXbjcOX3qjOtnh2B69CJ7A7zgc1Ch4Kn0L5EwUkNw5V7dVTosBMh/fqjAvYxg hMcIk7+XZVxBkKNP/oU14ef1TGjqchRufqCyDANYFqvX2314c41ZCCHJfw7DRgkPHJsEAeyoRlb KDpO2woOwECmj68S/i4D7ZXEIgs+aHyBQGfyk6e7Sg4R28ARJsFLT9uL4zqD9/VhBhezB6sUrNS YuuZ6h8kM6bbyBBRFaQ== X-Proofpoint-Spam-Info: AW1haW4tMjYwOTI0MDAzNiBTYWx0ZWRfXwryqhvXVDEPs 05/A7Y/xxjBsEumw+h3kRWJWwHkjPE3Kd92fkYttPTgMVNoqbx5YQOPqAuPYZh6Vg4HhXe86aDa O0PCPZVuSVOrhQFoGkIGD3IOOu/inHI= X-Proofpoint-GUID: T5-PJYg2jz5ldbzAFUNTefVn7Qg7dTCs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-09-24_02,2026-09-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 malwarescore=0 clxscore=1015 phishscore=0 bulkscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609240036 Add a macro mechanism that generates an opt-in and arch-namespaced file_to_kvm_() to convert a file reference to a kvm object if the file handle represents a kvm handle. Activate for x86 and for s390 (native KVM only). Suggested-by: Sean Christopherson Signed-off-by: Steffen Eiden --- arch/s390/include/asm/kvm_host_s390.h | 2 ++ arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/Makefile | 1 + include/linux/kvm_host.h | 12 ++++++++++++ virt/kvm/kvm_main.c | 11 +++++++++++ 5 files changed, 28 insertions(+) diff --git a/arch/s390/include/asm/kvm_host_s390.h b/arch/s390/include/asm/= kvm_host_s390.h index cd692f8fb764..8a7eed5847e1 100644 --- a/arch/s390/include/asm/kvm_host_s390.h +++ b/arch/s390/include/asm/kvm_host_s390.h @@ -27,6 +27,8 @@ #include #include =20 +#define kvm_file_to_kvm_arch s390 + #define KVM_HAVE_MMU_RWLOCK #define KVM_MAX_VCPUS 255 =20 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index 683bb8bf43a9..e460073ff176 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -44,6 +44,8 @@ =20 #include =20 +#define kvm_file_to_kvm_arch x86 + #define __KVM_HAVE_ARCH_VCPU_DEBUGFS =20 /* diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile index 0474604ab8a1..e6d395ede9e2 100644 --- a/arch/x86/kvm/Makefile +++ b/arch/x86/kvm/Makefile @@ -61,6 +61,7 @@ exports_grep_trailer :=3D --include=3D'*.[ch]' -nrw $(src= tree)/virt/kvm $(srctree)/a -e kvm_page_track_unregister_notifier \ -e kvm_write_track_add_gfn \ -e kvm_write_track_remove_gfn \ + -e kvm_file_to_kvm_fn \ -e kvm_get_kvm \ -e kvm_get_kvm_safe \ -e kvm_put_kvm diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 03bfc92864b6..e840ceda9f16 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1082,6 +1082,18 @@ void kvm_get_kvm(struct kvm *kvm); bool kvm_get_kvm_safe(struct kvm *kvm); void kvm_put_kvm(struct kvm *kvm); bool file_is_kvm(struct file *file); + +/* + * Architectures define kvm_file_to_kvm_arch to + * to get a typed, arch-namespaced helper: + * + * struct kvm *file_to_kvm_(struct file *file) + */ +#ifdef kvm_file_to_kvm_arch +#define kvm_file_to_kvm_fn CONCATENATE(file_to_kvm_, kvm_file_to_kvm_arch) +struct kvm *kvm_file_to_kvm_fn(struct file *file); +#endif /* kvm_file_to_kvm_arch */ + void kvm_put_kvm_no_destroy(struct kvm *kvm); =20 static inline struct kvm_memslots *__kvm_memslots(struct kvm *kvm, int as_= id) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 65eb26a0520d..0172ca94f82e 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -5496,6 +5496,17 @@ bool file_is_kvm(struct file *file) } EXPORT_SYMBOL_FOR_KVM_INTERNAL(file_is_kvm); =20 +#ifdef kvm_file_to_kvm_arch +struct kvm *kvm_file_to_kvm_fn(struct file *file) +{ + if (!file || file->f_op !=3D &kvm_vm_fops) + return NULL; + + return file->private_data; +} +EXPORT_SYMBOL_GPL(kvm_file_to_kvm_fn); +#endif + static int kvm_dev_ioctl_create_vm(unsigned long type) { char fdname[ITOA_MAX_LEN + 1]; --=20 2.53.0 From nobody Thu Sep 24 12:05:52 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 855D3440A0A; Thu, 24 Sep 2026 08:59:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790240345; cv=none; b=M9jyKmVF0KWUmUeO8lLKR2ydKYsw0VCV+oPT098rki9Yn8MozavN0uJVHpSEC4ZWTm7ruvXhbruQrdMiUxCt/71UebyVbHstgpvum5g/Z44+5sKyMm2KwGIYuOJVD1jOD6QWqonkHfHhTMksNMKSIqylAtGDQ1BGhyjhBqyhF5E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790240345; c=relaxed/simple; bh=bDTBRAzPlPATxeusRNeByCdY7fVBeElH5D0aVqA+zuc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ll5jdoET7lYaLyC0Rv8u5V9DvDzi/+apoMdfy8cK/x+xA5FaLc+KCnRXevhhZ4X6BUTxxbZqjarwdRfglCDO9lmwimIz9Rdjo12r+pDJrDIyTmIvbkjbCIUcBWj1N4GT7z5wYY2QqOt9DmKfQ2OilpegqorH6bHCnqRBljOVZEo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=P6xPJO9X; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="P6xPJO9X" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 68O5c4jj1180562; Thu, 24 Sep 2026 08:58:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=wwppUw 3ADf1sHTrYBhmISaYmlB4JBrEimBCGEmGK/3g=; b=P6xPJO9Xtsxvsi0+ls1rWR CLDQ0xwYu4mxvzn33lJ4oVpICz4006i6fVOekyGzvXdTojxgewxk3j3OnYhkRyFQ WFeMBJdoxC9GanNNrBflnL70DzjS16gHEnq8NHiK8Cu+7jz6U0dEkH9J5n4qQu2z MR3PloSRoYZGHre04Rp2H8mcPNQh8rNnlGOm3Mu58XJQD7cUVCAVANblhPJsk9s/ aCkGjCSIdQL5jM70nlvGufOPErH+rGUGXJPbw49owCY/SO/qSe0JZlAmlzUPoti2 dUfXpgUPI8vS9yw0ag95UinMn9k+e+nT4/QZNtDjMly547UMbZX+6GDk0o27KHEw == Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4gske1qdet-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Sep 2026 08:58:44 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 68O5ldEY212411; Thu, 24 Sep 2026 08:58:43 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4gvu7e9412-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Sep 2026 08:58:43 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 68O8wdtV27066710 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Sep 2026 08:58:39 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A9E7420040; Thu, 24 Sep 2026 08:58:39 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 664362004B; Thu, 24 Sep 2026 08:58:39 +0000 (GMT) Received: from [127.0.1.1] (unknown [9.87.85.9]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 24 Sep 2026 08:58:39 +0000 (GMT) From: Steffen Eiden Date: Thu, 24 Sep 2026 10:58:31 +0200 Subject: [PATCH v3 2/5] KVM: Add file back-pointer to struct kvm Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260924-vfio-v3-2-4a294307797b@linux.ibm.com> References: <20260924-vfio-v3-0-4a294307797b@linux.ibm.com> In-Reply-To: <20260924-vfio-v3-0-4a294307797b@linux.ibm.com> To: Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Matthew Rosato , Farhan Ali , Eric Farman , Tony Krowiak , Halil Pasic , Jason Herne , Harald Freudenberger , Holger Dengler , Alex Williamson Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Steffen Eiden X-Mailer: b4 0.14.3 X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-ORIG-GUID: xI7UUMHWEUIGPCBirjqTeV813jRKW4xy X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTI0MDAzNiBTYWx0ZWRfX38C+FGOPUprG +ReWIkZpSEpn5RF818sfGUvBXb2NqZQ0vcfuf4tKfVUIGqCfxBwicOHfIw1bc4XLVZvJIEDGJD/ vE8e8IEEDWSO6GOIZzSIE5COjD62zgylEr+RP9rN3WoggNYKpnvKU/VeGCiX5ghqkMvcWrcdO6F 4NyXsmFIBiULdaZswmwN1LDJ6en9oBKR0jR3E+C1FCBQ3M5RZT8sB1m3EtWGjoh4MBeEJtgyb5s e3UM/QJQgcLedbGCpaZ8j78AlEv+4WrRdZoVrvsg1++2EUmbl7+XQHbaii7n8h/BqqVezNWsTRw 4ukbTCMr0/ITOtque7kW3ZTAExYS4qdLRX181oiJ7LLqj12TPM0Hd2nHZ0XuDAHfoiEW4LBB4pW KO+ZbD3SAzlE9d4JJ+OCfK0RZMpJdexQtaslQP0TCOHV2JacyrhceszNUfT8gRFM31oP6q4RXpH xyUJLZVQjA7O4BdSIXg== X-Authority-Analysis: v=2.4 cv=O/KsLx9W c=1 sm=1 tr=0 ts=6ab4e644 cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=IkcTkHD0fZMA:10 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=1XWaLZrsAAAA:8 a=VnNF1IyMAAAA:8 a=cw4uO_N-L75IYahiFhcA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Info: AW1haW4tMjYwOTI0MDAzNiBTYWx0ZWRfX1vvCZ7XCdFNA 1wfS7qPhSCnQGE8JpDb0UYPnOo0Wy16/wBadVafNYHw4iduPnR0cM354JIb7GipneYZiwK3tmP/ QStVK2mb8Q62ccCY1czNNKu4+MPZyUg= X-Proofpoint-GUID: 07eN4urjFPJge3Kc4XbpdxsHMAteikMn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-09-24_02,2026-09-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 phishscore=0 impostorscore=0 suspectscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609240036 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 --- 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 e840ceda9f16..943b108f01cd 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 0172ca94f82e..bab71d398236 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) =20 kvm_irqfd_release(kvm); =20 + WRITE_ONCE(kvm->file, NULL); + kvm_put_kvm(kvm); return 0; } @@ -5532,6 +5534,8 @@ static int kvm_dev_ioctl_create_vm(unsigned long type) goto put_kvm; } =20 + kvm->file =3D 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 --=20 2.53.0 From nobody Thu Sep 24 12:05:52 2026 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 C12B537F010; Thu, 24 Sep 2026 08:59:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790240342; cv=none; b=l8e5TnhPVUrztBX4WfvmXeoB40m7KEBry30qrqRGDFT2aaOB8fnK6i0f3/vWQ+Wll+mZbI5gBPU9moFrnW8iHm3MoR+ZrJri5+BLlFd1NSMJlhRAw3muGM70j88MeoL2kL27piBI5taWlCjHpCnRspKiqyaYTLxEBlu2SW5GkhM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790240342; c=relaxed/simple; bh=Kenrhn+UDzuMaur6gMV5zYyMoKgY8g4sw250kds7mBY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Aipp1C35xzm7s1t18jH4FGZ+fVjr5MLxHx3euti+JRt35UTli3BurwZXBd2DCdHfssksr+A/M+J17DzcB3HNuwbvXYucC+K6wV9VmSAXZYY+vRF3A5wSrNHiCWeZRde8StF3ida+hYvDuTsdnmCTcv/yfbTbEbgLphE/NTZfM10= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=oAIopnMk; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="oAIopnMk" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 68O5cSNF1335411; Thu, 24 Sep 2026 08:58:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=LtdnIF my0U0w37qPOTcZQX+JKb9EABiAddZDctDHt74=; b=oAIopnMk8d5xh8XQ8E6l6c IE0WcfLLyd5mcqc4FsI3QPdZBjJ2wP7d+FJ3csQuNNXtBoY2IRN+vpbaWpvqRPv9 fXSQE8ME8i3dPzwGymiZvImUEr6fu8522Y+F/aOmLFS7uEwToP9KoFjwhb3C51Oi ngAtACWQi2NJxs6pXvEs+KxMEZyxZNhyAZUoxIsFjqMOunVHoONv8q8NThtMU4m2 55dlYbPu4vZiC/g7pPMdugdgxXoACcGtRolFaRcTSI8DH2wpnxX57nAGaD6xw4h+ g2Q+fmJf5sbrfRI7sjpbfmOxIACWj6YVcrvXWGBxMan7IRwMznxbeFEQZzvXWapQ == Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4gskgsfxva-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Sep 2026 08:58:44 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 68O5lTo31501452; Thu, 24 Sep 2026 08:58:44 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4gvbt2vsrk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Sep 2026 08:58:43 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 68O8weWa31982202 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Sep 2026 08:58:40 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 00A1320040; Thu, 24 Sep 2026 08:58:40 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ADB0120043; Thu, 24 Sep 2026 08:58:39 +0000 (GMT) Received: from [127.0.1.1] (unknown [9.87.85.9]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 24 Sep 2026 08:58:39 +0000 (GMT) From: Steffen Eiden Date: Thu, 24 Sep 2026 10:58:32 +0200 Subject: [PATCH v3 3/5] KVM: x86: Use file_to_kvm_x86() in SEV Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260924-vfio-v3-3-4a294307797b@linux.ibm.com> References: <20260924-vfio-v3-0-4a294307797b@linux.ibm.com> In-Reply-To: <20260924-vfio-v3-0-4a294307797b@linux.ibm.com> To: Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Matthew Rosato , Farhan Ali , Eric Farman , Tony Krowiak , Halil Pasic , Jason Herne , Harald Freudenberger , Holger Dengler , Alex Williamson Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Steffen Eiden X-Mailer: b4 0.14.3 X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=V/XoQuni c=1 sm=1 tr=0 ts=6ab4e645 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=IkcTkHD0fZMA:10 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=1XWaLZrsAAAA:8 a=VnNF1IyMAAAA:8 a=JZHfIBTrcVpj99XhhAcA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-ORIG-GUID: jo-HCn64oLn9anyleR7rf3k8tQl-undb X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTI0MDAzNiBTYWx0ZWRfX4VH4Ygfi8zuD NruH2l8Ochg/VJSuyrBbNzmDrfvJPNIGy3xEpleCAPP6hiTAZMWo6VHsRTZYXTuLcFpFZhdP7K1 qvUkc2rRjsdZdSvUETGK8lVnpul4Pniau2fLnNyreJYtcHSv0vHpUZsJtCsr27ihbsZUxp0X+ai 9e1erqct2JQEeUI+wc2K0rD6suMGR8l2+6v/yKuHstqYYgR/18BP6xo6oin9X+Wlogn9zHxPCEG pLcbhFjl7lZ36PJ4sZnXhggTFqIKLMKhoOklXAaZo7TNpoUdxHJbaSB8dkro0RSdipnjLZiQgB/ 3yaGUoWP/CtVZzW5ENLR2iXqRo472gtPRZC0Y+OZlIO4WVlwinbowiWd/sIEeruGEARYbJgOZdc u1c3u/AxHP1v7CiFcFcxKPvwHdrK4xviKurvojSXw2c70lNHUebeIR7VUV8wnpwXFTSqjWNG9/o as2aGi+X9gVjjY/8uqA== X-Proofpoint-Spam-Info: AW1haW4tMjYwOTI0MDAzNiBTYWx0ZWRfX+NGaPCLavOwS qsjegNU+eIZ/Ov11Qniat5e841grjLNpMk9nPc1DxY541Gkzo/cVJ3yGe5YMh6HvhK6FoI6pd0W lLyWB0GI99AUJH70os9AmAHTFAbsuyU= X-Proofpoint-GUID: 96MUqAWqgqHzWSymKXSHrgukD0y2Ptpw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-09-24_02,2026-09-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 malwarescore=0 clxscore=1015 phishscore=0 bulkscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609240036 Use the new arch-namespaced helper instead of open-coding the file check and private_data cast separately. Suggested-by: Sean Christopherson Signed-off-by: Steffen Eiden --- arch/x86/kvm/svm/sev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 5705723f1f41..6b0eacde4f06 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2145,10 +2145,10 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, u= nsigned int source_fd) if (fd_empty(f)) return -EBADF; =20 - if (!file_is_kvm(fd_file(f))) + source_kvm =3D file_to_kvm_x86(fd_file(f)); + if (!source_kvm) return -EBADF; =20 - source_kvm =3D fd_file(f)->private_data; ret =3D sev_lock_two_vms(kvm, source_kvm); if (ret) return ret; @@ -2866,10 +2866,10 @@ int sev_vm_copy_enc_context_from(struct kvm *kvm, u= nsigned int source_fd) if (fd_empty(f)) return -EBADF; =20 - if (!file_is_kvm(fd_file(f))) + source_kvm =3D file_to_kvm_x86(fd_file(f)); + if (!source_kvm) return -EBADF; =20 - source_kvm =3D fd_file(f)->private_data; ret =3D sev_lock_two_vms(kvm, source_kvm); if (ret) return ret; --=20 2.53.0 From nobody Thu Sep 24 12:05:52 2026 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 0C29043F0A8; Thu, 24 Sep 2026 08:59:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790240344; cv=none; b=EEA69DUVsUD9WKQw4KoY/2QEAEUpFabsmjBmw1GzXy160jr+hL53DcGHSOlav7N3ajLO1s3HhPM2ukEwmxVAClaFbJkPU1KdB/8TIYBtgQvPeZMyy3FhpDL2Tp8nPgRJPHMwKZMhvGNpRo7AdojWlgyb89pymxZMRDn0CoE4mFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790240344; c=relaxed/simple; bh=fd6778e29XNEI3+N8W0pdJml7IFWfyjFJLGUsJtmQRU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C+pWRokPsJ0OXdAqFAsk0EtZSCqdzIyVW6dLTDea6wulAQUxoIfnglGOTX0sARLgKIGKJ4nzDc3cZDJv8jBEClZAx+yLRVtTbNsRpCDkoR805fVufO7aEJ2qk6iP0mLacGtsO4LW4D4IwvAaTHxVTYQjzLGRdmzdXd2U2rnwH+k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=ecZRILPI; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="ecZRILPI" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 68O5bNUK1341290; Thu, 24 Sep 2026 08:58:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=f9XOmv 8kULPkafi+OZ7b5379pL8xGM0CcXIL4I44Es8=; b=ecZRILPIY9nUS03oK13kw9 wQmAM8SXllZa2doTI5f98JC/WSNknusSFxbpiw7wf7Aa9AtufpjDM8pwkMNZIXU5 ImBcdEdGNVirZNGO2m6g8kc4TLWKrXGjVhncfVDVmJxxNtnPzsH1H7fxr+Ito5XW ep6IDridHcUeFAuEMplRnSzvk2RrVRjyn73mHa2dWvSghOSFWhYDwTowuMESn8nW 4kh+XoC8rvUMk8ZpqwfyS3z6e6vjVsohUyBf+X4R9QNXW8Ywdji+E4SjGTMUn6JK iXeOY9IM+1Wn8bD0qg+dZ8HpycwbJpc7Nc39wl/yDHIJIV6wuX74a4W/DUHBmygQ == Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4gskg2r1s1-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Sep 2026 08:58:45 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 68O5lUsj1554258; Thu, 24 Sep 2026 08:58:44 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4gvb6qmx1y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Sep 2026 08:58:44 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 68O8weaB17105286 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Sep 2026 08:58:40 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6056120040; Thu, 24 Sep 2026 08:58:40 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 055172004B; Thu, 24 Sep 2026 08:58:40 +0000 (GMT) Received: from [127.0.1.1] (unknown [9.87.85.9]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 24 Sep 2026 08:58:39 +0000 (GMT) From: Steffen Eiden Date: Thu, 24 Sep 2026 10:58:33 +0200 Subject: [PATCH v3 4/5] KVM/vfio: Use file-based reference counting for KVM Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260924-vfio-v3-4-4a294307797b@linux.ibm.com> References: <20260924-vfio-v3-0-4a294307797b@linux.ibm.com> In-Reply-To: <20260924-vfio-v3-0-4a294307797b@linux.ibm.com> To: Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Matthew Rosato , Farhan Ali , Eric Farman , Tony Krowiak , Halil Pasic , Jason Herne , Harald Freudenberger , Holger Dengler , Alex Williamson Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Steffen Eiden , Jason Gunthorpe X-Mailer: b4 0.14.3 X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-ORIG-GUID: -M4nHqi71Ziuee5KGkiCFT04xvBGwVix X-Authority-Analysis: v=2.4 cv=I43w19gg c=1 sm=1 tr=0 ts=6ab4e645 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=IkcTkHD0fZMA:10 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=Ikd4Dj_1AAAA:8 a=1XWaLZrsAAAA:8 a=VnNF1IyMAAAA:8 a=NcvOO2zV9weGGrCt3WIA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTI0MDAzNiBTYWx0ZWRfX5I2XN4lG8emY qg49fTJgtTUUUsgMelkNuOZ6IAyKceFpGahvpjGrH4WO1w0fmiLbQL77D/KhwfeCVEPp+WNegYT XkhB4WzfA8Sz6zpNQkrg1hET/AyywaY8emD1Fki0ypAXIH7myAtrRdSSQukRluT9vOJqZ7JlCA1 2dwfD8/fNrTUraGQU2QBY0fDeoAQsM+SwEmmIR6oRZqrn25PU08+us+V1NQ7Mqi+IcL13ZgEA3X TH5GXS89kwPCjlnJYgzPfaVeeoYlZnRlK3tDN6BzPbvj3EzLnMZmEE1cczLwF2nNhUrk9Otl6wu N2FCBjhiDwiKLqMmYMd6RO946x5Vuqgo67IyrlF0jBP0RJSOZKi8AL9LknSxUKT7yxI6Teeb1vN bFVhOsIIrOKm7Ba4f8s8LaEWyZQ2mvKwFA1eLsASpcu/JXzFeGkxqtdspl9uQEb9rjt9J2OrYlX ul/o61nC/MDKr8WpAwA== X-Proofpoint-Spam-Info: AW1haW4tMjYwOTI0MDAzNiBTYWx0ZWRfXy+oQSa4eMz94 s0JfjxYZkzeW0XSKAJcMQjjdt2RP5o3M73o64F5nWyreqsFgodzowmnmuoU0Lf2y4wm6yzPPNjZ jSFRC00vqwIAu5bAdAZ2qKlYmKpNCOc= X-Proofpoint-GUID: L66wX3uKRDku4nJmIGQDYJtudQVqUFH2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-09-24_02,2026-09-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1015 adultscore=0 suspectscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 phishscore=0 priorityscore=1501 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609240036 Replace manual module reference counting with file-based reference counting for KVM integration. Previously, VFIO used symbol_get() to obtain function pointers for kvm_get_kvm_safe() and kvm_put_kvm(), then manually tracked module references through these symbols. This approach required storing the put_kvm function pointer in each device and carefully managing symbol references. Pass struct file pointers instead of struct kvm pointers throughout the VFIO-KVM interface, leveraging the kernel's existing file reference counting via get_file()/get_file_active() and fput(). Convert the x86 page-track API and update s390 vfio to use file_to_kvm_(). This simplifies the code and removes all remaining externally exported symbols for KVM which would appear twice for when a second concurrent KVM module is introduced. Suggested-by: Jason Gunthorpe Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Steffen Eiden --- arch/s390/include/asm/kvm_host_s390.h | 2 +- arch/s390/kvm/s390/pci.c | 9 ++++-- arch/x86/include/asm/kvm_page_track.h | 8 ++--- arch/x86/kvm/mmu/page_track.c | 22 +++++++++----- drivers/s390/crypto/vfio_ap_ops.c | 20 ++++++++---- drivers/vfio/group.c | 11 ++++++- drivers/vfio/vfio.h | 12 ++++---- drivers/vfio/vfio_main.c | 57 +++++++++++--------------------= ---- include/linux/vfio.h | 5 ++- virt/kvm/vfio.c | 13 +++++--- 10 files changed, 85 insertions(+), 74 deletions(-) diff --git a/arch/s390/include/asm/kvm_host_s390.h b/arch/s390/include/asm/= kvm_host_s390.h index 8a7eed5847e1..9519b8028b10 100644 --- a/arch/s390/include/asm/kvm_host_s390.h +++ b/arch/s390/include/asm/kvm_host_s390.h @@ -722,7 +722,7 @@ static inline void kvm_arch_vcpu_unblocking(struct kvm_= vcpu *vcpu) {} void kvm_arch_free_vm(struct kvm *kvm); =20 struct zpci_kvm_hook { - int (*kvm_register)(void *opaque, struct kvm *kvm); + int (*kvm_register)(void *opaque, struct file *kvm_file); void (*kvm_unregister)(void *opaque); }; =20 diff --git a/arch/s390/kvm/s390/pci.c b/arch/s390/kvm/s390/pci.c index 82892e1e03d9..d79bd3bdc68e 100644 --- a/arch/s390/kvm/s390/pci.c +++ b/arch/s390/kvm/s390/pci.c @@ -498,17 +498,22 @@ static void kvm_s390_pci_dev_release(struct zpci_dev = *zdev) * available, enable them and let userspace indicate whether or not they w= ill * be used (specify SHM bit to disable). */ -static int kvm_s390_pci_register_kvm(void *opaque, struct kvm *kvm) +static int kvm_s390_pci_register_kvm(void *opaque, struct file *kvm_file) { struct zpci_dev *zdev =3D opaque; + struct kvm *kvm; int rc; =20 if (!zdev) return -EINVAL; =20 + kvm =3D file_to_kvm_s390(kvm_file); + if (!kvm) + return -ENOENT; + mutex_lock(&zdev->kzdev_lock); =20 - if (zdev->kzdev || zdev->gisa !=3D 0 || !kvm) { + if (zdev->kzdev || zdev->gisa !=3D 0) { mutex_unlock(&zdev->kzdev_lock); return -EINVAL; } diff --git a/arch/x86/include/asm/kvm_page_track.h b/arch/x86/include/asm/k= vm_page_track.h index 3d040741044b..046a25c8fe4f 100644 --- a/arch/x86/include/asm/kvm_page_track.h +++ b/arch/x86/include/asm/kvm_page_track.h @@ -44,13 +44,13 @@ struct kvm_page_track_notifier_node { struct kvm_page_track_notifier_node *node); }; =20 -int kvm_page_track_register_notifier(struct kvm *kvm, +int kvm_page_track_register_notifier(struct file *file, struct kvm_page_track_notifier_node *n); -void kvm_page_track_unregister_notifier(struct kvm *kvm, +void kvm_page_track_unregister_notifier(struct file *file, struct kvm_page_track_notifier_node *n); =20 -int kvm_write_track_add_gfn(struct kvm *kvm, gfn_t gfn); -int kvm_write_track_remove_gfn(struct kvm *kvm, gfn_t gfn); +int kvm_write_track_add_gfn(struct file *file, gfn_t gfn); +int kvm_write_track_remove_gfn(struct file *file, gfn_t gfn); #else /* * Allow defining a node in a structure even if page tracking is disabled,= e.g. diff --git a/arch/x86/kvm/mmu/page_track.c b/arch/x86/kvm/mmu/page_track.c index 7e8195a311bb..f12558dfcd81 100644 --- a/arch/x86/kvm/mmu/page_track.c +++ b/arch/x86/kvm/mmu/page_track.c @@ -16,6 +16,8 @@ #include #include =20 +#include + #include "mmu.h" #include "mmu_internal.h" #include "page_track.h" @@ -237,10 +239,11 @@ static int kvm_enable_external_write_tracking(struct = kvm *kvm) * register the notifier so that event interception for the tracked guest * pages can be received. */ -int kvm_page_track_register_notifier(struct kvm *kvm, +int kvm_page_track_register_notifier(struct file *file, struct kvm_page_track_notifier_node *n) { struct kvm_page_track_notifier_head *head; + struct kvm *kvm =3D file_to_kvm_x86(file); int r; =20 if (!kvm || kvm->mm !=3D current->mm) @@ -252,7 +255,7 @@ int kvm_page_track_register_notifier(struct kvm *kvm, return r; } =20 - kvm_get_kvm(kvm); + get_file(file); =20 head =3D &kvm->arch.track_notifier_head; =20 @@ -267,10 +270,11 @@ EXPORT_SYMBOL_GPL(kvm_page_track_register_notifier); * stop receiving the event interception. It is the opposed operation of * kvm_page_track_register_notifier(). */ -void kvm_page_track_unregister_notifier(struct kvm *kvm, +void kvm_page_track_unregister_notifier(struct file *file, struct kvm_page_track_notifier_node *n) { struct kvm_page_track_notifier_head *head; + struct kvm *kvm =3D file_to_kvm_x86(file); =20 head =3D &kvm->arch.track_notifier_head; =20 @@ -279,7 +283,7 @@ void kvm_page_track_unregister_notifier(struct kvm *kvm, write_unlock(&kvm->mmu_lock); synchronize_srcu(&head->track_srcu); =20 - kvm_put_kvm(kvm); + fput(file); } EXPORT_SYMBOL_GPL(kvm_page_track_unregister_notifier); =20 @@ -336,11 +340,12 @@ void kvm_page_track_delete_slot(struct kvm *kvm, stru= ct kvm_memory_slot *slot) * add guest page to the tracking pool so that corresponding access on that * page will be intercepted. * - * @kvm: the guest instance we are interested in. + * @file: the VM file of the guest instance we are interested in. * @gfn: the guest page. */ -int kvm_write_track_add_gfn(struct kvm *kvm, gfn_t gfn) +int kvm_write_track_add_gfn(struct file *file, gfn_t gfn) { + struct kvm *kvm =3D file_to_kvm_x86(file); struct kvm_memory_slot *slot; int idx; =20 @@ -366,11 +371,12 @@ EXPORT_SYMBOL_GPL(kvm_write_track_add_gfn); * remove the guest page from the tracking pool which stops the intercepti= on * of corresponding access on that page. * - * @kvm: the guest instance we are interested in. + * @file: the VM file of the guest instance we are interested in. * @gfn: the guest page. */ -int kvm_write_track_remove_gfn(struct kvm *kvm, gfn_t gfn) +int kvm_write_track_remove_gfn(struct file *file, gfn_t gfn) { + struct kvm *kvm =3D file_to_kvm_x86(file); struct kvm_memory_slot *slot; int idx; =20 diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_a= p_ops.c index 940c0ff668be..556e643244f2 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -1822,17 +1822,27 @@ static const struct attribute_group *vfio_ap_mdev_a= ttr_groups[] =3D { =20 /** * vfio_ap_mdev_set_kvm - sets all data for @matrix_mdev that are needed - * to manage AP resources for the guest whose state is represented by @kvm + * to manage AP resources for the guest whose state is represented by + * @kvm_file * * @matrix_mdev: a mediated matrix device - * @kvm: reference to KVM instance + * @kvm_file: the KVM VM file this vfio device is associated with * - * Return: 0 if no other mediated matrix device has a reference to @kvm; + * Return: 0 if no other mediated matrix device has a reference to the VM; * otherwise, returns an -EPERM. */ static int vfio_ap_mdev_set_kvm(struct ap_matrix_mdev *matrix_mdev, - struct kvm *kvm) + struct file *kvm_file) { + struct kvm *kvm; + + if (!kvm_file) + return -ENOENT; + + kvm =3D file_to_kvm_s390(kvm_file); + if (!kvm) + return -ENOENT; + if (kvm->arch.crypto.crycbd) { get_update_locks_for_kvm(kvm); if (kvm->arch.crypto.pqap_hook) { @@ -1841,7 +1851,6 @@ static int vfio_ap_mdev_set_kvm(struct ap_matrix_mdev= *matrix_mdev, } kvm->arch.crypto.pqap_hook =3D &matrix_mdev->pqap_hook; =20 - kvm_get_kvm(kvm); matrix_mdev->kvm =3D kvm; vfio_ap_mdev_update_guest_apcb(matrix_mdev); release_update_locks_for_kvm(kvm); @@ -1894,7 +1903,6 @@ static void vfio_ap_mdev_unset_kvm(struct ap_matrix_m= dev *matrix_mdev) matrix_mdev->kvm =3D NULL; =20 release_update_locks_for_kvm(kvm); - kvm_put_kvm(kvm); } } =20 diff --git a/drivers/vfio/group.c b/drivers/vfio/group.c index b2299e5bc6df..5bf8cbdff377 100644 --- a/drivers/vfio/group.c +++ b/drivers/vfio/group.c @@ -860,11 +860,20 @@ bool vfio_group_enforced_coherent(struct vfio_group *= group) return ret; } =20 -void vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm) +void vfio_group_set_kvm(struct vfio_group *group, struct file *kvm) { + struct file *old; + + if (kvm) + get_file(kvm); + spin_lock(&group->kvm_ref_lock); + old =3D group->kvm; group->kvm =3D kvm; spin_unlock(&group->kvm_ref_lock); + + if (old) + fput(old); } =20 /** diff --git a/drivers/vfio/vfio.h b/drivers/vfio/vfio.h index 7728bc99b63d..9b619951a5d0 100644 --- a/drivers/vfio/vfio.h +++ b/drivers/vfio/vfio.h @@ -23,7 +23,7 @@ struct vfio_device_file { u8 access_granted; u32 devid; /* only valid when iommufd is valid */ spinlock_t kvm_ref_lock; /* protect kvm field */ - struct kvm *kvm; + struct file *kvm; struct iommufd_ctx *iommufd; /* protected by struct vfio_device_set::lock= */ }; =20 @@ -88,7 +88,7 @@ struct vfio_group { #endif enum vfio_group_type type; struct mutex group_lock; - struct kvm *kvm; + struct file *kvm; struct file *opened_file; struct iommufd_ctx *iommufd; spinlock_t kvm_ref_lock; @@ -107,7 +107,7 @@ void vfio_device_group_unuse_iommu(struct vfio_device *= device); void vfio_df_group_close(struct vfio_device_file *df); struct vfio_group *vfio_group_from_file(struct file *file); bool vfio_group_enforced_coherent(struct vfio_group *group); -void vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm); +void vfio_group_set_kvm(struct vfio_group *group, struct file *kvm); bool vfio_device_has_container(struct vfio_device *device); int __init vfio_group_init(void); void vfio_group_cleanup(void); @@ -165,7 +165,7 @@ static inline bool vfio_group_enforced_coherent(struct = vfio_group *group) return true; } =20 -static inline void vfio_group_set_kvm(struct vfio_group *group, struct kvm= *kvm) +static inline void vfio_group_set_kvm(struct vfio_group *group, struct fil= e *kvm) { } =20 @@ -429,11 +429,11 @@ static inline void vfio_virqfd_exit(void) #endif =20 #if IS_ENABLED(CONFIG_KVM) -void vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm); +void vfio_device_get_kvm_safe(struct vfio_device *device, struct file *kvm= ); void vfio_device_put_kvm(struct vfio_device *device); #else static inline void vfio_device_get_kvm_safe(struct vfio_device *device, - struct kvm *kvm) + struct file *kvm) { } =20 diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index 423ead48aafe..ed96acfa8635 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -472,36 +472,14 @@ void vfio_unregister_group_dev(struct vfio_device *de= vice) EXPORT_SYMBOL_GPL(vfio_unregister_group_dev); =20 #if IS_ENABLED(CONFIG_KVM) -void vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm) +void vfio_device_get_kvm_safe(struct vfio_device *device, struct file *kvm) { - void (*pfn)(struct kvm *kvm); - bool (*fn)(struct kvm *kvm); - bool ret; - lockdep_assert_held(&device->dev_set->lock); =20 if (!kvm) return; =20 - pfn =3D symbol_get(kvm_put_kvm); - if (WARN_ON(!pfn)) - return; - - fn =3D symbol_get(kvm_get_kvm_safe); - if (WARN_ON(!fn)) { - symbol_put(kvm_put_kvm); - return; - } - - ret =3D fn(kvm); - symbol_put(kvm_get_kvm_safe); - if (!ret) { - symbol_put(kvm_put_kvm); - return; - } - - device->put_kvm =3D pfn; - device->kvm =3D kvm; + device->kvm =3D get_file(kvm); } =20 void vfio_device_put_kvm(struct vfio_device *device) @@ -511,14 +489,7 @@ void vfio_device_put_kvm(struct vfio_device *device) if (!device->kvm) return; =20 - if (WARN_ON(!device->put_kvm)) - goto clear; - - device->put_kvm(device->kvm); - device->put_kvm =3D NULL; - symbol_put(kvm_put_kvm); - -clear: + fput(device->kvm); device->kvm =3D NULL; } #endif @@ -1544,9 +1515,13 @@ bool vfio_file_enforced_coherent(struct file *file) } EXPORT_SYMBOL_GPL(vfio_file_enforced_coherent); =20 -static void vfio_device_file_set_kvm(struct file *file, struct kvm *kvm) +static void vfio_device_file_set_kvm(struct file *file, struct file *kvm) { struct vfio_device_file *df =3D file->private_data; + struct file *old; + + if (kvm) + get_file(kvm); =20 /* * The kvm is first recorded in the vfio_device_file, and will @@ -1554,28 +1529,32 @@ static void vfio_device_file_set_kvm(struct file *f= ile, struct kvm *kvm) * iommufd successfully in the vfio device cdev path. */ spin_lock(&df->kvm_ref_lock); + old =3D df->kvm; df->kvm =3D kvm; spin_unlock(&df->kvm_ref_lock); + + if (old) + fput(old); } =20 /** * vfio_file_set_kvm - Link a kvm with VFIO drivers - * @file: VFIO group file or VFIO device file - * @kvm: KVM to link + * @vfio_file: VFIO group file or VFIO device file + * @kvm: KVM file to link * * When a VFIO device is first opened the KVM will be available in * device->kvm if one was associated with the file. */ -void vfio_file_set_kvm(struct file *file, struct kvm *kvm) +void vfio_file_set_kvm(struct file *vfio_file, struct file *kvm) { struct vfio_group *group; =20 - group =3D vfio_group_from_file(file); + group =3D vfio_group_from_file(vfio_file); if (group) vfio_group_set_kvm(group, kvm); =20 - if (vfio_device_from_file(file)) - vfio_device_file_set_kvm(file, kvm); + if (vfio_device_from_file(vfio_file)) + vfio_device_file_set_kvm(vfio_file, kvm); } EXPORT_SYMBOL_GPL(vfio_file_set_kvm); =20 diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 45f08986359e..0cc91c6f96d2 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -54,7 +54,7 @@ struct vfio_device { struct list_head dev_set_list; unsigned int migration_flags; u8 precopy_info_v2; - struct kvm *kvm; + struct file *kvm; =20 /* Members below here are private, not for driver use */ unsigned int index; @@ -66,7 +66,6 @@ struct vfio_device { unsigned int open_count; struct completion comp; struct iommufd_access *iommufd_access; - void (*put_kvm)(struct kvm *kvm); struct inode *inode; #if IS_ENABLED(CONFIG_IOMMUFD) struct iommufd_device *iommufd_device; @@ -378,7 +377,7 @@ static inline bool vfio_file_has_dev(struct file *file,= struct vfio_device *devi #endif bool vfio_file_is_valid(struct file *file); bool vfio_file_enforced_coherent(struct file *file); -void vfio_file_set_kvm(struct file *file, struct kvm *kvm); +void vfio_file_set_kvm(struct file *vfio_file, struct file *kvm); =20 #define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long)) =20 diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c index 6cdc4e9a333a..19548a430942 100644 --- a/virt/kvm/vfio.c +++ b/virt/kvm/vfio.c @@ -35,15 +35,15 @@ struct kvm_vfio { bool noncoherent; }; =20 -static void kvm_vfio_file_set_kvm(struct file *file, struct kvm *kvm) +static void kvm_vfio_file_set_kvm(struct file *vfio_file, struct file *kvm) { - void (*fn)(struct file *file, struct kvm *kvm); + void (*fn)(struct file *vfio_file, struct file *kvm); =20 fn =3D symbol_get(vfio_file_set_kvm); if (!fn) return; =20 - fn(file, kvm); + fn(vfio_file, kvm); =20 symbol_put(vfio_file_set_kvm); } @@ -144,6 +144,7 @@ static int kvm_vfio_file_add(struct kvm_device *dev, un= signed int fd) { struct kvm_vfio *kv =3D dev->private; struct kvm_vfio_file *kvf; + struct file *kvm_file __free(fput) =3D NULL; struct file *filp __free(fput) =3D NULL; =20 filp =3D fget(fd); @@ -154,6 +155,10 @@ static int kvm_vfio_file_add(struct kvm_device *dev, u= nsigned int fd) if (!kvm_vfio_file_is_valid(filp)) return -EINVAL; =20 + kvm_file =3D get_file_active(&dev->kvm->file); + if (!kvm_file) + return -ENOENT; + guard(mutex)(&kv->lock); =20 list_for_each_entry(kvf, &kv->file_list, node) { @@ -168,7 +173,7 @@ static int kvm_vfio_file_add(struct kvm_device *dev, un= signed int fd) kvf->file =3D get_file(filp); list_add_tail(&kvf->node, &kv->file_list); =20 - kvm_vfio_file_set_kvm(kvf->file, dev->kvm); + kvm_vfio_file_set_kvm(kvf->file, kvm_file); kvm_vfio_update_coherency(dev); =20 return 0; --=20 2.53.0 From nobody Thu Sep 24 12:05:52 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 854BC440A08; Thu, 24 Sep 2026 08:59:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790240345; cv=none; b=c1liYUZylCYELiZ7yZ8Roy4RmRxhzy+QHvJJimMtjzlgXQRrnheE23qbdlR/kbbjLxf8tIiv+VczKWDS94+G1SNR0MaUv+sqJ0+jf7GGVmV3sDf3YucvEUXgvoew5+m1w4JPghMuKc9qkrLLtdQ6DqhbkoB47FHs/QH0JD+T5+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790240345; c=relaxed/simple; bh=u73LKcm8bGY5Aw4Nqfini1ABcjD5R9crFx9O6wvqB2k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UMx2na5Wa23uqQw8P1wTQpE+zIdHkJCX3RpJ+mfEh2NO+bGLVNTkDQgsOiiXOfD857PJeuwgCBZvkn6gUlyUw5Rw5+IOGCY6/9nYEoSGNP6/P9Cs8Owp7FM9/H80BpPpIL30z2NJ8QRLrpdi+9BWOpwsS8TK2FxB9PZxFAyaJbc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=X55jAFnx; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="X55jAFnx" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 68O5bpPZ1179971; Thu, 24 Sep 2026 08:58:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=SYAa3I M/+xKk/8iMdL2vB2N3OhtXJgQijRnR9BRL4WM=; b=X55jAFnxc9SRykfm7I+msh AniYYCqh5vWY465Nj2WtVA5ttNXoml0cM6jjrKaQljIYhtp1Ix2WL5vl5PJykAvQ A1FpT7LmIg01vLZlmuDc8BSENJxZztFfr4Ln7UguDOgJwQXx2Ki4uGji6WKxgQFk NZ1L5kUAneix3DrmbjuVhYBBKmPkOSxHfM2/XTsO+a01OW2P8ATs1iy1lygN0LYu cpaTR15CpCB8TN6fbBtDeSzSoWb/t+TrXVisJ1mH9AUCWgzHp5QkZDhm6KRUnf+M y0dVIhbzlV5s8MNRo5tvxuuxvYZCIKxyHd3oL1TUywFB9kMyZw6EsECKSiJUtRBw == Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4gske1qdf1-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Sep 2026 08:58:45 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 68O5lTo41501452; Thu, 24 Sep 2026 08:58:44 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4gvbt2vsrn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Sep 2026 08:58:44 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 68O8weCc31982204 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Sep 2026 08:58:40 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A7EDC20040; Thu, 24 Sep 2026 08:58:40 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 640D420043; Thu, 24 Sep 2026 08:58:40 +0000 (GMT) Received: from [127.0.1.1] (unknown [9.87.85.9]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 24 Sep 2026 08:58:40 +0000 (GMT) From: Steffen Eiden Date: Thu, 24 Sep 2026 10:58:34 +0200 Subject: [PATCH v3 5/5] KVM: Restrict kvm_get_kvm/kvm_put_kvm export to internal KVM modules Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260924-vfio-v3-5-4a294307797b@linux.ibm.com> References: <20260924-vfio-v3-0-4a294307797b@linux.ibm.com> In-Reply-To: <20260924-vfio-v3-0-4a294307797b@linux.ibm.com> To: Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Matthew Rosato , Farhan Ali , Eric Farman , Tony Krowiak , Halil Pasic , Jason Herne , Harald Freudenberger , Holger Dengler , Alex Williamson Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Steffen Eiden X-Mailer: b4 0.14.3 X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-ORIG-GUID: 3U_JyZXUK6kzha80TThf9iX5kysaqgN5 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTI0MDAzNiBTYWx0ZWRfX+UozSMrUe7oQ KJLJ9/RoPyYGe1Whh6XGM0fNt38TDVSHcuDIaGsD48Q+/TtnLStkxjJQCoTSfhvn2e3WVS61FXY dcYVLmnZPqZO45+xfrQ+bFRkkiSrYVChFT7d6+JnCnJw6GRK/yzPy0gqACCFQ7BKpBA8lJq8Pbs C3i55lOwAW7SzNwkHTXYdPaYPpSaCh8yyMnQt/X0w0+Ltgev/noKIYuyD1AxhEjdlOFZdQJhzAd iZi92m/YlL/zPtkC8spsoJltQCdEuUHqjicyIzSdjwPKL+fk/6qgOjb5aKT6cgmRjabL0ScsEXe QROv4vlJuODh+kac5X8Ci7+MRlct+pgC7zbUIRvlw2XE0114GBcGAgJjohSsbOpVq+yM33mRlOM T/U1Ejt0TAAYcJw2r5jg7i/ZlB53BCaIXlSe6GhJqfbcLM0k06GqYnbB7AkWlGJvi1WF8CmET5k w8eM7Eof5MolfUvkvEg== X-Authority-Analysis: v=2.4 cv=O/KsLx9W c=1 sm=1 tr=0 ts=6ab4e645 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=IkcTkHD0fZMA:10 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=1XWaLZrsAAAA:8 a=VnNF1IyMAAAA:8 a=cWV-k8hB2h86IYwIXi4A:9 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Info: AW1haW4tMjYwOTI0MDAzNiBTYWx0ZWRfX1agVaYczpMPP ceFYguFyJZDh5HbizcNcQIu4QFq6mSMs7pdJdgGQTlvUfVhdai7jbI5qEh/QvNwXlNg1KUbYEaK FjiWabEBvu9BuniXGsrzH5PHlSUaRsw= X-Proofpoint-GUID: R4Dokp0rHAU3A5bWzsAfiJTwsbqOF3v7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-09-24_02,2026-09-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 phishscore=0 impostorscore=0 suspectscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609240036 Switch kvm_get_kvm, kvm_get_kvm_safe, and kvm_put_kvm from EXPORT_SYMBOL_GPL to EXPORT_SYMBOL_FOR_KVM_INTERNAL. These symbols are now only used within KVM itself. No external module needs them now that VFIO uses file-based reference counting. Remove the corresponding exemptions from the x86 KVM Makefile exports check. Suggested-by: Sean Christopherson Signed-off-by: Steffen Eiden --- arch/x86/kvm/Makefile | 5 +---- virt/kvm/kvm_main.c | 6 +++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile index e6d395ede9e2..c6bf463f5032 100644 --- a/arch/x86/kvm/Makefile +++ b/arch/x86/kvm/Makefile @@ -61,10 +61,7 @@ exports_grep_trailer :=3D --include=3D'*.[ch]' -nrw $(sr= ctree)/virt/kvm $(srctree)/a -e kvm_page_track_unregister_notifier \ -e kvm_write_track_add_gfn \ -e kvm_write_track_remove_gfn \ - -e kvm_file_to_kvm_fn \ - -e kvm_get_kvm \ - -e kvm_get_kvm_safe \ - -e kvm_put_kvm + -e kvm_file_to_kvm_fn =20 # Force grep to emit a goofy group separator that can in turn be replaced = with # the above newline macro (newlines in Make are a nightmare). Note, grep = only diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index bab71d398236..891a67cb365a 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1314,7 +1314,7 @@ void kvm_get_kvm(struct kvm *kvm) { refcount_inc(&kvm->users_count); } -EXPORT_SYMBOL_GPL(kvm_get_kvm); +EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_get_kvm); =20 /* * Make sure the vm is not during destruction, which is a safe version of @@ -1324,14 +1324,14 @@ bool kvm_get_kvm_safe(struct kvm *kvm) { return refcount_inc_not_zero(&kvm->users_count); } -EXPORT_SYMBOL_GPL(kvm_get_kvm_safe); +EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_get_kvm_safe); =20 void kvm_put_kvm(struct kvm *kvm) { if (refcount_dec_and_test(&kvm->users_count)) kvm_destroy_vm(kvm); } -EXPORT_SYMBOL_GPL(kvm_put_kvm); +EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_put_kvm); =20 /* * Used to put a reference that was taken on behalf of an object associated --=20 2.53.0