From nobody Thu Oct 2 02:05:45 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 0C017283FFC; Thu, 25 Sep 2025 13:18:59 +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=1758806340; cv=none; b=icS5fUUDxE1Be32m/O897UbTtAQxdTLQ52UbROOBxcIV3Tsa4+lLiUq2lHOCK6nmMdrHbkl45sUbnqlDjTPjSCsOw2+sH9ubpKNiXkXxv8kMz0O20zMxB3GzrsRYwAZ6ACjSkrIB0LlNs+gTijgwxmewiuzDWrCNI4X9J1QfWp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758806340; c=relaxed/simple; bh=iaKDo8+GXeu4wXRq9Qaze1AB6MboGJIHM+btEoU720U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aWqQhTTtBkauc0I1dIFnQOGdUdWOwykud2z/eJ1/C6LCIxCMODGtWzmATt/mGNAkPbMYVy+B8t68eQj4ESkDGtCdqo9X07uuZVBm46DXe4N7u4BVmcDBZfAq2xV3bGijBSMQFEVQrNDlW8sF2fVrEoP5BHZkqyet6bsYjx9Wm2w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PPRxNcAE; 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="PPRxNcAE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FFE2C4CEF0; Thu, 25 Sep 2025 13:18:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758806339; bh=iaKDo8+GXeu4wXRq9Qaze1AB6MboGJIHM+btEoU720U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PPRxNcAER0sBWU04ti7ERNNBjC4G0s3V1tSjBJcRkLsU27oCADu167yr+SKaKuJsV 3cxMTsFtjpObe+gkW2NlpiwqylI1bAjB+9UeAFjc120uXcKXRhetP6xq7q74RVf87B y46YRc12SJmkX26594tJiP5IyYUGlZwvCeM4FSHaS3WTlN6BlhzMoDMRVpdQQ9fEvL ZgkbbZHTmFBDD1WwZiK6z8vmuNgMg3D/DIvKBXsp20NSTz83EptJGRfomKMu9xlX7a cd8k2BAfxMFUmK37XcjUessk/YtP+t+hk5M03BU0Jx4lRwIemZaMzOvNCUKt1Hhvzu TuQn5w2tocV+g== From: Leon Romanovsky To: Alex Williamson Cc: Vivek Kasireddy , Jason Gunthorpe , Andrew Morton , Bjorn Helgaas , =?UTF-8?q?Christian=20K=C3=B6nig?= , dri-devel@lists.freedesktop.org, iommu@lists.linux.dev, Jens Axboe , Joerg Roedel , kvm@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org, Logan Gunthorpe , Marek Szyprowski , Robin Murphy , Sumit Semwal , Will Deacon Subject: [PATCH v3 09/10] vfio/pci: Share the core device pointer while invoking feature functions Date: Thu, 25 Sep 2025 16:14:37 +0300 Message-ID: <6bf5ecfd312ba0f2e71873322def45c7e42a1b1d.1758804980.git.leon@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 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 356a0e2fd3780..17bf711a929c4 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -302,11 +302,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); @@ -323,12 +321,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; @@ -379,11 +375,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); @@ -1476,11 +1470,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 @@ -1507,16 +1500,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.0