lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YRI+nsVAr3grftB4@infradead.org>
Date:   Tue, 10 Aug 2021 10:53:50 +0200
From:   Christoph Hellwig <hch@...radead.org>
To:     Alex Williamson <alex.williamson@...hat.com>
Cc:     Jason Gunthorpe <jgg@...dia.com>, linux-kernel@...r.kernel.org,
        kvm@...r.kernel.org, peterx@...hat.com
Subject: Re: [PATCH 3/7] vfio/pci: Use vfio_device_unmap_mapping_range()

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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ