From nobody Tue Dec 2 02:17:25 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 59B952701CB; Thu, 20 Nov 2025 09:29:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763630955; cv=none; b=J1i3BvAypmzACGx+k3NUjUgXl81CFFRW/tqCVY2krO72jxJ8EdSueq6h90/xd2UMgVK2Ss/Mip+X/OkcCqK8PQlzxyZ8xUvJDSN4RhXBwIL5n4BGW2YKF3Ob++8LWxC/FhrpjMrhN6AH+RiusHy+KApwO2vPeyvv2TITK63rPKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763630955; c=relaxed/simple; bh=Lf+kWGlyk4dILuBBuzgoUTcs6RorNiR6HiVQt7aIne4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l7M2jsCZYkHFlMNnKVh6q8bMOi5FQf+rwvBASmM3lUctcYQjdxNKclI0Csk61b/yT570gVJPjvWQcp117/k2n8WRl6mjcLvMZ8Pn/WPNS6zT2R5mYSHSzeUfYjS4LehU+/EQD19TpNkWHedc8ZTZ5iTOmhNU+/I06yx0B+48zKE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sXL6WcNL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sXL6WcNL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2455C4CEF1; Thu, 20 Nov 2025 09:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763630954; bh=Lf+kWGlyk4dILuBBuzgoUTcs6RorNiR6HiVQt7aIne4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sXL6WcNLp3wSGx7BunP6AQaMqVtZqsej0m3hOHdrNgJ4QQgo8/zDoo3gLrWCRri6W wwILPPUUVO37MwH7vTnsNXFn6k+q4iVVdaU+ci5zQUpPEYLm5iF7egpO2o7k5u0UJ1 HwdB05Nmu4xyC6C1CahNSKAax0BZyPrfGpzvEtGaKqpRMs3PRdusrHsDnp7mWwXAeg gRDgVXrHhrq65be4pARBcEQoAGuS3lo8A1wcdY0jUY4culPV+tRNiDyXsEK0HxjdRk TCB32lrHzKioPUAyhTFfXVvlV3Ph8LK0fyt+1iHSzzxd14qNt31MTNhMf6M6h3HNml +0FogN0XwNl9A== From: Leon Romanovsky To: Bjorn Helgaas , Logan Gunthorpe , Jens Axboe , Robin Murphy , Joerg Roedel , Will Deacon , Marek Szyprowski , Jason Gunthorpe , Leon Romanovsky , Andrew Morton , Jonathan Corbet , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Kees Cook , "Gustavo A. R. Silva" , Ankit Agrawal , Yishai Hadas , Shameer Kolothum , Kevin Tian , Alex Williamson Cc: Krishnakant Jaju , Matt Ochs , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, iommu@lists.linux.dev, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, kvm@vger.kernel.org, linux-hardening@vger.kernel.org, Vivek Kasireddy , Alex Mastro , Nicolin Chen Subject: [PATCH v9 08/11] vfio/pci: Share the core device pointer while invoking feature functions Date: Thu, 20 Nov 2025 11:28:27 +0200 Message-ID: <20251120-dmabuf-vfio-v9-8-d7f71607f371@nvidia.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251120-dmabuf-vfio-v9-0-d7f71607f371@nvidia.com> References: <20251120-dmabuf-vfio-v9-0-d7f71607f371@nvidia.com> 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" X-Mailer: b4 0.15-dev-a6db3 Content-Transfer-Encoding: quoted-printable From: Vivek Kasireddy There is no need to share the main device pointer (struct vfio_device *) with all the feature functions as they only need the core device pointer. Therefore, extract the core device pointer once in the caller (vfio_pci_core_ioctl_feature) and share it instead. Signed-off-by: Vivek Kasireddy Reviewed-by: Kevin Tian Tested-by: Alex Mastro Tested-by: Nicolin Chen Signed-off-by: Leon Romanovsky --- drivers/vfio/pci/vfio_pci_core.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_c= ore.c index 7dcf5439dedc..ca9a95716a85 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -299,11 +299,9 @@ static int vfio_pci_runtime_pm_entry(struct vfio_pci_c= ore_device *vdev, return 0; } =20 -static int vfio_pci_core_pm_entry(struct vfio_device *device, u32 flags, +static int vfio_pci_core_pm_entry(struct vfio_pci_core_device *vdev, u32 f= lags, void __user *arg, size_t argsz) { - struct vfio_pci_core_device *vdev =3D - container_of(device, struct vfio_pci_core_device, vdev); int ret; =20 ret =3D vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET, 0); @@ -320,12 +318,10 @@ static int vfio_pci_core_pm_entry(struct vfio_device = *device, u32 flags, } =20 static int vfio_pci_core_pm_entry_with_wakeup( - struct vfio_device *device, u32 flags, + struct vfio_pci_core_device *vdev, u32 flags, struct vfio_device_low_power_entry_with_wakeup __user *arg, size_t argsz) { - struct vfio_pci_core_device *vdev =3D - container_of(device, struct vfio_pci_core_device, vdev); struct vfio_device_low_power_entry_with_wakeup entry; struct eventfd_ctx *efdctx; int ret; @@ -376,11 +372,9 @@ static void vfio_pci_runtime_pm_exit(struct vfio_pci_c= ore_device *vdev) up_write(&vdev->memory_lock); } =20 -static int vfio_pci_core_pm_exit(struct vfio_device *device, u32 flags, +static int vfio_pci_core_pm_exit(struct vfio_pci_core_device *vdev, u32 fl= ags, void __user *arg, size_t argsz) { - struct vfio_pci_core_device *vdev =3D - container_of(device, struct vfio_pci_core_device, vdev); int ret; =20 ret =3D vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET, 0); @@ -1473,11 +1467,10 @@ long vfio_pci_core_ioctl(struct vfio_device *core_v= dev, unsigned int cmd, } EXPORT_SYMBOL_GPL(vfio_pci_core_ioctl); =20 -static int vfio_pci_core_feature_token(struct vfio_device *device, u32 fla= gs, - uuid_t __user *arg, size_t argsz) +static int vfio_pci_core_feature_token(struct vfio_pci_core_device *vdev, + u32 flags, uuid_t __user *arg, + size_t argsz) { - struct vfio_pci_core_device *vdev =3D - container_of(device, struct vfio_pci_core_device, vdev); uuid_t uuid; int ret; =20 @@ -1504,16 +1497,19 @@ static int vfio_pci_core_feature_token(struct vfio_= device *device, u32 flags, int vfio_pci_core_ioctl_feature(struct vfio_device *device, u32 flags, void __user *arg, size_t argsz) { + struct vfio_pci_core_device *vdev =3D + container_of(device, struct vfio_pci_core_device, vdev); + switch (flags & VFIO_DEVICE_FEATURE_MASK) { case VFIO_DEVICE_FEATURE_LOW_POWER_ENTRY: - return vfio_pci_core_pm_entry(device, flags, arg, argsz); + return vfio_pci_core_pm_entry(vdev, flags, arg, argsz); case VFIO_DEVICE_FEATURE_LOW_POWER_ENTRY_WITH_WAKEUP: - return vfio_pci_core_pm_entry_with_wakeup(device, flags, + return vfio_pci_core_pm_entry_with_wakeup(vdev, flags, arg, argsz); case VFIO_DEVICE_FEATURE_LOW_POWER_EXIT: - return vfio_pci_core_pm_exit(device, flags, arg, argsz); + return vfio_pci_core_pm_exit(vdev, flags, arg, argsz); case VFIO_DEVICE_FEATURE_PCI_VF_TOKEN: - return vfio_pci_core_feature_token(device, flags, arg, argsz); + return vfio_pci_core_feature_token(vdev, flags, arg, argsz); default: return -ENOTTY; } --=20 2.51.1