From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 DB85823184F for ; Mon, 28 Jul 2025 20:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753736164; cv=none; b=jXE2WVLH6CwRUf2P+uUjTnyeWy/0UP3jtvWdj69JNixdNgKgqOpCjmWjaSY0ZZ6mXhA0HAus/igOHNUdCxwGAIdFF0XIAR6Jwx/6AGlSrjQKX3GJ3eC9WNH2FxfMPreeZQ+bg6y+vbcyr6dC9ZRLJYhiRDTVniO5gAcDbq/yeiM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753736164; c=relaxed/simple; bh=nRpzG9wCRVLX56km469LJwsErSpZhF+6HuuhqwgnJd0=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PLS9VVEkfwx2lfRUOln5lmdBXxshoXKe4Ui02rHu0DiO6xoP7+6zIQECyKNTQzp3tQRQPsvRsBUmCJmL/aCP377ayx4wTETUj2KxIDCFBhLJEJzwOTJ5TmE2dx7/NPyiKBJSTqjpsyDRlH1Spoa6ya0IDTWrNi7Etl80ozCQubs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=BksYy3et; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BksYy3et" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1753736159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3lAhpTjpbvFQu27uIQ7LZXIQUIKIfZHhU7pyfNlOjpc=; b=BksYy3etYjW8K7sUTxLeFPie7KXRx9gJQ/sRIXOQjL/L9ALBu5I2yr4R5f4NiDCtD5+PvE CKuTKYDC+hk1I9vxXzZZqsl4FgjlHMko4Uu8bw/QIZZlBIvxkvkHi/jV1nMNHpPmujxv/e Tuu4KvgWYUSB2iogdIyG/pXMEShBn8M= Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-5SbhHrG5NL-l_BBiDlK1pg-1; Mon, 28 Jul 2025 16:55:58 -0400 X-MC-Unique: 5SbhHrG5NL-l_BBiDlK1pg-1 X-Mimecast-MFC-AGG-ID: 5SbhHrG5NL-l_BBiDlK1pg_1753736158 Received: by mail-il1-f198.google.com with SMTP id e9e14a558f8ab-3e3ea64a166so451985ab.0 for ; Mon, 28 Jul 2025 13:55:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753736157; x=1754340957; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3lAhpTjpbvFQu27uIQ7LZXIQUIKIfZHhU7pyfNlOjpc=; b=seqnWnpDnCj4Sfl/qI80Jz3XM6pbPIwIdLn/ahqIIwZeYXsvyT1OvkTYylJG+7xpOr esHGl6g1JvWUj3GbXdgmOx+nM1Y1J4Gzv8oQ8BtoE9vKINK/Mn1MneehXvn0aQ0rpgCM 1YN8YcQ9BEdpzSlvj+dfsQrM8VHBM5ORIoQKE44n7v+SNnGAoCZMVRwTyAVWHwmbYQwS UTNwsYGaLYh6q8DDIKlXl5MFdb8B3xz3BvHRG1TA0VLxoyPbB5/Uf5LsnkCHmm/BtmEL FVKXdzaiFtyD1DarDc/DV8K4kjM3fq6zSgahApmqzVPu/yloa/OOHUtSVors/v2TA5f5 P+wQ== X-Forwarded-Encrypted: i=1; AJvYcCUc6XXOUzrD7La2Xex377TOoszx8jBrx0EiwihayEM4XBBejrNdGrAAcPvdrz98NolVNGqpG5XDYck=@vger.kernel.org X-Gm-Message-State: AOJu0YwfpZUz1r6mRVclEj50nu+K8skHqT2uYo+OAUlErkRMfQe+NPnW PWqHxkNiJCNhZsYtjcM+i7bhsNb4U8SCRiTHiLiEKu7UUXPN0f8whufxat88zfRSy9+UmY6oqRl Jbo62auyP8JWev0Gfa5LZwjmr/L8gWGI65X2aExykbHa96bSPmbCYR1DFrqmxnQ== X-Gm-Gg: ASbGnct51uZpsxr39efqMy2Zjy5htSCvwTPYE3V+zI5V1UyW6+WyrDIlTm/n+Smej8U aS70yNCpNbX62K2tz41oM/UndbW+Bke+kMDgb/x1cAx+3Rozahh1kUp3KJgbFCJ3Ica1KCp1cdq YfA9y510EcvpF1JniEF/w9XhVVTuVoXdpyJRuHI/bJM37chAqtmjFNPfhYlWgf+ItNo4jrmnGlD eR7/FtW3zg2ksZE2cRoD06dNgdc0sKdDmmSRHMi1ZRFrUqLqG2GGQxzedXCsuEh3B77TkzeFt6r K7Hu78gAppDfipLliZ9rrhtPkq0yvYEbVMbqBrAfjHU= X-Received: by 2002:a05:6e02:3389:b0:3e3:e461:4617 with SMTP id e9e14a558f8ab-3e3e4614777mr12699225ab.2.1753736157534; Mon, 28 Jul 2025 13:55:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaMLNGgu4ToITqnk/t+y4I2RkNZuq3J6YSgL+Stwkf8Y5Ta3HhAl493hrL7HwiUxfbSIOjGA== X-Received: by 2002:a05:6e02:3389:b0:3e3:e461:4617 with SMTP id e9e14a558f8ab-3e3e4614777mr12698925ab.2.1753736157034; Mon, 28 Jul 2025 13:55:57 -0700 (PDT) Received: from redhat.com ([38.15.36.11]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-508c9341e4csm2109194173.76.2025.07.28.13.55.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jul 2025 13:55:55 -0700 (PDT) Date: Mon, 28 Jul 2025 14:55:53 -0600 From: Alex Williamson To: Leon Romanovsky Cc: Vivek Kasireddy , Christoph Hellwig , Jason Gunthorpe , Andrew Morton , Bjorn Helgaas , Christian =?UTF-8?B?S8O2bmln?= , dri-devel@lists.freedesktop.org, iommu@lists.linux.dev, Jens Axboe , =?UTF-8?B?SsOpcsO0bWU=?= Glisse , 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: Re: [PATCH 09/10] vfio/pci: Share the core device pointer while invoking feature functions Message-ID: <20250728145553.53e94d49.alex.williamson@redhat.com> In-Reply-To: <19f71a0f4d1a5db8c712cb4d094ccf2f10dc22c5.1753274085.git.leonro@nvidia.com> References: <19f71a0f4d1a5db8c712cb4d094ccf2f10dc22c5.1753274085.git.leonro@nvidia.com> X-Mailer: Claws Mail 4.3.1 (GTK 3.24.43; x86_64-redhat-linux-gnu) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 23 Jul 2025 16:00:10 +0300 Leon Romanovsky wrote: > 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_core.c > index 1e675daab5753..5512d13bb8899 100644 > --- a/drivers/vfio/pci/vfio_pci_core.c > +++ b/drivers/vfio/pci/vfio_pci_core.c > @@ -301,11 +301,9 @@ static int vfio_pci_runtime_pm_entry(struct vfio_pci_core_device *vdev, > return 0; > } > > -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 flags, > void __user *arg, size_t argsz) > { > - struct vfio_pci_core_device *vdev = > - container_of(device, struct vfio_pci_core_device, vdev); > int ret; > > ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET, 0); > @@ -322,12 +320,10 @@ static int vfio_pci_core_pm_entry(struct vfio_device *device, u32 flags, > } > > 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) I'm tempted to fix the line wrapping here, but I think this patch stands on its own. Even if it's rather trivial, it makes sense to consolidate and standardize on the vfio_pci_core_device getting passed around within vfio_pci_core.c. Any reason not to split this off? Thanks, Alex > { > - struct vfio_pci_core_device *vdev = > - container_of(device, struct vfio_pci_core_device, vdev); > struct vfio_device_low_power_entry_with_wakeup entry; > struct eventfd_ctx *efdctx; > int ret; > @@ -378,11 +374,9 @@ static void vfio_pci_runtime_pm_exit(struct vfio_pci_core_device *vdev) > up_write(&vdev->memory_lock); > } > > -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 flags, > void __user *arg, size_t argsz) > { > - struct vfio_pci_core_device *vdev = > - container_of(device, struct vfio_pci_core_device, vdev); > int ret; > > ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET, 0); > @@ -1475,11 +1469,10 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, > } > EXPORT_SYMBOL_GPL(vfio_pci_core_ioctl); > > -static int vfio_pci_core_feature_token(struct vfio_device *device, u32 flags, > - 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 = > - container_of(device, struct vfio_pci_core_device, vdev); > uuid_t uuid; > int ret; > > @@ -1506,16 +1499,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 = > + 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; > }