From: Alex Williamson <alex.williamson@redhat.com>
To: "Tian, Kevin" <kevin.tian@intel.com>
Cc: Ankit Agrawal <ankita@nvidia.com>,
Zhi Wang <zhi.wang.linux@gmail.com>,
Jason Gunthorpe <jgg@nvidia.com>,
Yishai Hadas <yishaih@nvidia.com>,
"mst@redhat.com" <mst@redhat.com>,
"shameerali.kolothum.thodi@huawei.com"
<shameerali.kolothum.thodi@huawei.com>,
"clg@redhat.com" <clg@redhat.com>,
"oleksandr@natalenko.name" <oleksandr@natalenko.name>,
"K V P, Satyanarayana" <satyanarayana.k.v.p@intel.com>,
"eric.auger@redhat.com" <eric.auger@redhat.com>,
"brett.creeley@amd.com" <brett.creeley@amd.com>,
"horms@kernel.org" <horms@kernel.org>,
Rahul Rameshbabu <rrameshbabu@nvidia.com>,
Aniket Agashe <aniketa@nvidia.com>, Neo Jia <cjia@nvidia.com>,
Kirti Wankhede <kwankhede@nvidia.com>,
"Tarun Gupta (SW-GPU)" <targupta@nvidia.com>,
Vikram Sethi <vsethi@nvidia.com>,
"Currid, Andy" <acurrid@nvidia.com>,
Alistair Popple <apopple@nvidia.com>,
"John Hubbard" <jhubbard@nvidia.com>,
Dan Williams <danw@nvidia.com>,
"Anuj Aggarwal (SW-GPU)" <anuaggarwal@nvidia.com>,
Matt Ochs <mochs@nvidia.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"virtualization@lists.linux-foundation.org"
<virtualization@lists.linux-foundation.org>
Subject: Re: [PATCH v17 3/3] vfio/nvgrace-gpu: Add vfio pci variant module for grace hopper
Date: Thu, 8 Feb 2024 09:09:47 -0700 [thread overview]
Message-ID: <20240208090947.1254e72c.alex.williamson@redhat.com> (raw)
In-Reply-To: <BN9PR11MB527640ADE99D92210977E7CA8C442@BN9PR11MB5276.namprd11.prod.outlook.com>
On Thu, 8 Feb 2024 07:21:40 +0000
"Tian, Kevin" <kevin.tian@intel.com> wrote:
> > From: Ankit Agrawal <ankita@nvidia.com>
> > Sent: Thursday, February 8, 2024 3:13 PM
> > >> > + * Determine how many bytes to be actually read from the
> > >> > device memory.
> > >> > + * Read request beyond the actual device memory size is
> > >> > filled with ~0,
> > >> > + * while those beyond the actual reported size is skipped.
> > >> > + */
> > >> > + if (offset >= memregion->memlength)
> > >> > + mem_count = 0;
> > >>
> > >> If mem_count == 0, going through nvgrace_gpu_map_and_read() is not
> > >> necessary.
> > >
> > > Harmless, other than the possibly unnecessary call through to
> > > nvgrace_gpu_map_device_mem(). Maybe both
> > nvgrace_gpu_map_and_read()
> > > and nvgrace_gpu_map_and_write() could conditionally return 0 as their
> > > first operation when !mem_count. Thanks,
> > >
> > >Alex
> >
> > IMO, this seems like adding too much code to reduce the call length for a
> > very specific case. If there aren't any strong opinion on this, I'm planning to
> > leave this code as it is.
>
> a slight difference. if mem_count==0 the result should always succeed
> no matter nvgrace_gpu_map_device_mem() succeeds or not. Of course
> if it fails it's already a big problem probably nobody cares about the subtle
> difference when reading non-exist range.
>
> but regarding to readability it's still clearer:
>
> if (mem_count)
> nvgrace_gpu_map_and_read();
>
The below has better flow imo vs conditionalizing the call to
map_and_read/write and subsequent error handling, but I don't think
either adds too much code. Thanks,
Alex
--- a/drivers/vfio/pci/nvgrace-gpu/main.c
+++ b/drivers/vfio/pci/nvgrace-gpu/main.c
@@ -429,6 +429,9 @@ nvgrace_gpu_map_and_read(struct nvgrace_gpu_vfio_pci_core_device *nvdev,
u64 offset = *ppos & VFIO_PCI_OFFSET_MASK;
int ret;
+ if (!mem_count)
+ return 0;
+
/*
* Handle read on the BAR regions. Map to the target device memory
* physical address and copy to the request read buffer.
@@ -547,6 +550,9 @@ nvgrace_gpu_map_and_write(struct nvgrace_gpu_vfio_pci_core_device *nvdev,
loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
int ret;
+ if (!mem_count)
+ return 0;
+
ret = nvgrace_gpu_map_device_mem(index, nvdev);
if (ret)
return ret;
next prev parent reply other threads:[~2024-02-08 16:09 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-05 23:01 [PATCH v17 0/3] vfio/nvgrace-gpu: Add vfio pci variant module for grace hopper ankita
2024-02-05 23:01 ` [PATCH v17 1/3] vfio/pci: rename and export do_io_rw() ankita
2024-02-08 6:14 ` Tian, Kevin
2024-02-05 23:01 ` [PATCH v17 2/3] vfio/pci: rename and export range_intesect_range ankita
2024-02-08 6:19 ` Tian, Kevin
2024-02-08 6:43 ` Ankit Agrawal
2024-02-05 23:01 ` [PATCH v17 3/3] vfio/nvgrace-gpu: Add vfio pci variant module for grace hopper ankita
2024-02-07 22:32 ` Zhi Wang
2024-02-07 23:27 ` Alex Williamson
2024-02-08 7:12 ` Ankit Agrawal
2024-02-08 7:21 ` Tian, Kevin
2024-02-08 11:13 ` Ankit Agrawal
2024-02-08 16:09 ` Alex Williamson [this message]
2024-02-09 9:24 ` Ankit Agrawal
2024-02-07 23:34 ` Alex Williamson
2024-02-08 6:47 ` Ankit Agrawal
2024-02-08 7:14 ` Tian, Kevin
2024-02-09 9:20 ` Ankit Agrawal
2024-02-09 15:55 ` Alex Williamson
2024-02-09 17:19 ` Jason Gunthorpe
2024-02-09 18:00 ` Alex Williamson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240208090947.1254e72c.alex.williamson@redhat.com \
--to=alex.williamson@redhat.com \
--cc=acurrid@nvidia.com \
--cc=aniketa@nvidia.com \
--cc=ankita@nvidia.com \
--cc=anuaggarwal@nvidia.com \
--cc=apopple@nvidia.com \
--cc=brett.creeley@amd.com \
--cc=cjia@nvidia.com \
--cc=clg@redhat.com \
--cc=danw@nvidia.com \
--cc=eric.auger@redhat.com \
--cc=horms@kernel.org \
--cc=jgg@nvidia.com \
--cc=jhubbard@nvidia.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=kwankhede@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mochs@nvidia.com \
--cc=mst@redhat.com \
--cc=oleksandr@natalenko.name \
--cc=rrameshbabu@nvidia.com \
--cc=satyanarayana.k.v.p@intel.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=targupta@nvidia.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=vsethi@nvidia.com \
--cc=yishaih@nvidia.com \
--cc=zhi.wang.linux@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox