[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <871qahzw8m.fsf@nvidia.com>
Date: Mon, 15 Jan 2024 21:19:33 -0800
From: Rahul Rameshbabu <rrameshbabu@...dia.com>
To: ankita@...dia.com
Cc: jgg@...dia.com, alex.williamson@...hat.com, yishaih@...dia.com,
shameerali.kolothum.thodi@...wei.com, kevin.tian@...el.com,
eric.auger@...hat.com, brett.creeley@....com, horms@...nel.org,
aniketa@...dia.com, cjia@...dia.com, kwankhede@...dia.com,
targupta@...dia.com, vsethi@...dia.com, acurrid@...dia.com,
apopple@...dia.com, jhubbard@...dia.com, danw@...dia.com,
anuaggarwal@...dia.com, mochs@...dia.com, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v16 2/3] vfio/pci: implement range_intesect_range to
determine range overlap
On Mon, 15 Jan, 2024 21:15:15 +0000 <ankita@...dia.com> wrote:
> From: Ankit Agrawal <ankita@...dia.com>
>
> Add a helper function to determine an overlap between two ranges.
> If an overlap, the function returns the overlapping offset and size.
>
> The VFIO PCI variant driver emulates the PCI config space BAR offset
> registers. These offset may be accessed for read/write with a variety
> of lengths including sub-word sizes from sub-word offsets. The driver
> makes use of this helper function to read/write the targeted part of
> the emulated register.
>
> This is replicated from Yishai's work in
> https://lore.kernel.org/all/20231207102820.74820-10-yishaih@nvidia.com
>
> Signed-off-by: Ankit Agrawal <ankita@...dia.com>
> Tested-by: Ankit Agrawal <ankita@...dia.com>
> ---
> drivers/vfio/pci/vfio_pci_config.c | 28 ++++++++++++++++++++++++++++
> include/linux/vfio_pci_core.h | 6 ++++++
> 2 files changed, 34 insertions(+)
>
> diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
> index 7e2e62ab0869..b77c96fbc4b2 100644
> --- a/drivers/vfio/pci/vfio_pci_config.c
> +++ b/drivers/vfio/pci/vfio_pci_config.c
> @@ -1966,3 +1966,31 @@ ssize_t vfio_pci_config_rw(struct vfio_pci_core_device *vdev, char __user *buf,
>
> return done;
> }
> +
> +bool range_intersect_range(loff_t range1_start, size_t count1,
> + loff_t range2_start, size_t count2,
> + loff_t *start_offset,
> + size_t *intersect_count,
> + size_t *register_offset)
> +{
> + if (range1_start <= range2_start &&
> + range1_start + count1 > range2_start) {
> + *start_offset = range2_start - range1_start;
> + *intersect_count = min_t(size_t, count2,
> + range1_start + count1 - range2_start);
> + *register_offset = 0;
> + return true;
> + }
> +
> + if (range1_start > range2_start &&
> + range1_start < range2_start + count2) {
> + *start_offset = 0;
> + *intersect_count = min_t(size_t, count1,
> + range2_start + count2 - range1_start);
> + *register_offset = range1_start - range2_start;
> + return true;
> + }
> +
> + return false;
> +}
> +EXPORT_SYMBOL_GPL(range_intersect_range);
If this function is being exported, shouldn't the function name follow
the pattern of having the vfio_pci_core_* prefix like the rest of the
symbols exported in this file. Something like
vfio_pci_core_range_intersect_range?
--
Thanks,
Rahul Rameshbabu
Powered by blists - more mailing lists