linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	peterx@redhat.com
Subject: Re: [PATCH 3/7] vfio/pci: Use vfio_device_unmap_mapping_range()
Date: Tue, 10 Aug 2021 10:53:50 +0200	[thread overview]
Message-ID: <YRI+nsVAr3grftB4@infradead.org> (raw)
In-Reply-To: <162818325518.1511194.1243290800645603609.stgit@omen>

On Thu, Aug 05, 2021 at 11:07:35AM -0600, Alex Williamson wrote:
> +static void vfio_pci_zap_bars(struct vfio_pci_device *vdev)
>  {
> +	vfio_device_unmap_mapping_range(&vdev->vdev,
> +			VFIO_PCI_INDEX_TO_OFFSET(VFIO_PCI_BAR0_REGION_INDEX),
> +			VFIO_PCI_INDEX_TO_OFFSET(VFIO_PCI_ROM_REGION_INDEX) -
> +			VFIO_PCI_INDEX_TO_OFFSET(VFIO_PCI_BAR0_REGION_INDEX));

Maybe make this a little more readable by having local variables:

> +static int vfio_pci_bar_vma_to_pfn(struct vm_area_struct *vma,
> +				   unsigned long *pfn)
>  {
> +	struct vfio_pci_device *vdev = vma->vm_private_data;
> +	struct pci_dev *pdev = vdev->pdev;
> +	int index;
> +	u64 pgoff;
>  
> +	index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT);

Nit: initialization at declaration time would be nice.

>  static vm_fault_t vfio_pci_mmap_fault(struct vm_fault *vmf)
>  {
>  	struct vm_area_struct *vma = vmf->vma;
>  	struct vfio_pci_device *vdev = vma->vm_private_data;
> +	unsigned long vaddr, pfn;
> +	vm_fault_t ret = VM_FAULT_SIGBUS;
>  
> +	if (vfio_pci_bar_vma_to_pfn(vma, &pfn))
> +		return ret;
>  
> +	down_read(&vdev->memory_lock);
>  
> +	if (__vfio_pci_memory_enabled(vdev)) {
> +		for (vaddr = vma->vm_start;
> +		     vaddr < vma->vm_end; vaddr += PAGE_SIZE, pfn++) {
> +			ret = vmf_insert_pfn(vma, vaddr, pfn);
> +			if (ret != VM_FAULT_NOPAGE) {
> +				zap_vma_ptes(vma, vma->vm_start,
> +					     vaddr - vma->vm_start);
> +				break;
> +			}
> +		}

Unwinding this with a goto for the not enabled case would be a little easier
to read.

  parent reply	other threads:[~2021-08-10  8:58 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-05 17:06 [PATCH 0/7] vfio: device fd address space and vfio-pci mmap invalidation cleanup Alex Williamson
2021-08-05 17:07 ` [PATCH 1/7] vfio: Create vfio_fs_type with inode per device Alex Williamson
2021-08-10  8:43   ` Christoph Hellwig
2021-08-10 14:52     ` Alex Williamson
2021-08-10 14:57       ` Christoph Hellwig
2021-08-10 18:49         ` Peter Xu
2021-08-10 21:16           ` Alex Williamson
2021-08-10 22:18             ` Peter Xu
2021-08-05 17:07 ` [PATCH 2/7] vfio: Export unmap_mapping_range() wrapper Alex Williamson
2021-08-10  8:45   ` Christoph Hellwig
2021-08-10 18:56   ` Peter Xu
2021-08-05 17:07 ` [PATCH 3/7] vfio/pci: Use vfio_device_unmap_mapping_range() Alex Williamson
2021-08-06  1:04   ` Jason Gunthorpe
2021-08-06 20:17     ` Alex Williamson
2021-08-10  8:51       ` Christoph Hellwig
2021-08-10 11:57         ` Jason Gunthorpe
2021-08-10 12:55           ` Christoph Hellwig
2021-08-10 21:50             ` Alex Williamson
2021-08-11 11:57               ` Jason Gunthorpe
2021-08-10  8:53   ` Christoph Hellwig [this message]
2021-08-10 19:02     ` Peter Xu
2021-08-10 20:51       ` Alex Williamson
2021-08-10 18:48   ` Peter Xu
2021-08-10 19:59     ` Alex Williamson
2021-08-10 20:20       ` Peter Xu
2021-08-05 17:07 ` [PATCH 4/7] vfio,vfio-pci: Add vma to pfn callback Alex Williamson
2021-08-06  1:01   ` Jason Gunthorpe
2021-08-10  9:00     ` Christoph Hellwig
2021-08-10  9:00   ` Christoph Hellwig
2021-08-05 17:08 ` [PATCH 5/7] mm/interval_tree.c: Export vma interval tree iterators Alex Williamson
2021-08-05 17:08 ` [PATCH 6/7] vfio: Add vfio_device_io_remap_mapping_range() Alex Williamson
2021-08-10  9:04   ` Christoph Hellwig
2021-08-05 17:08 ` [PATCH 7/7] vfio/pci: Remove map-on-fault behavior Alex Williamson
2021-08-10  9:11   ` Christoph Hellwig
2021-08-10 15:04     ` Alex Williamson
2021-08-10 20:54   ` Peter Xu
2021-08-10 21:45     ` Alex Williamson
2021-08-10 22:27       ` Peter Xu

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=YRI+nsVAr3grftB4@infradead.org \
    --to=hch@infradead.org \
    --cc=alex.williamson@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterx@redhat.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;
as well as URLs for NNTP newsgroup(s).