From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexey Kardashevskiy Subject: Re: [RFC PATCH kernel] vfio-pci: Fix sparse capability when no parts of MSIX BAR can be mapped Date: Thu, 30 Nov 2017 17:00:35 +1100 Message-ID: References: <20171123045626.17542-1-aik@ozlabs.ru> <20171129112702.51d0a493@t450s.home> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: Alex Williamson Return-path: Received: from mail-it0-f68.google.com ([209.85.214.68]:44178 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750816AbdK3GAl (ORCPT ); Thu, 30 Nov 2017 01:00:41 -0500 Received: by mail-it0-f68.google.com with SMTP id b5so6945462itc.3 for ; Wed, 29 Nov 2017 22:00:41 -0800 (PST) In-Reply-To: <20171129112702.51d0a493@t450s.home> Content-Language: en-AU Sender: kvm-owner@vger.kernel.org List-ID: On 30/11/17 05:27, Alex Williamson wrote: > On Thu, 23 Nov 2017 15:56:26 +1100 > Alexey Kardashevskiy wrote: > >> It is currently possible to have a sparse capability with 1 areas which >> starts at 0 and 0 bytes long. One example is: >> >> Texas Instruments TUSB73x0 SuperSpeed USB 3.0 xHCI Host Controller >> [...] >> Region 0: Memory at 3fe280000000 (64-bit, non-prefetchable) [size=64K] >> Region 2: Memory at 3fe280010000 (64-bit, non-prefetchable) [size=8K] >> [...] >> Capabilities: [c0] MSI-X: Enable+ Count=8 Masked- >> Vector table: BAR=2 offset=00000000 >> PBA: BAR=2 offset=00001000 >> >> With PAGE_SIZE=64K, MSIX BAR occupies the entire BAR2 and cannot be >> mapped. >> >> This makes it explicit - if sparse->areas is empty, then advertise >> nr_areas as 0. >> >> Signed-off-by: Alexey Kardashevskiy >> --- >> >> QEMU gets it right as vfio_setup_region_sparse_mmaps() checks for size >> after QEMU's 24acf72b9a291ce "vfio: Handle zero-length sparse mmap ranges" >> but why not make it explicit in the first place? >> >> >> --- >> drivers/vfio/pci/vfio_pci.c | 4 ++++ >> 1 file changed, 4 insertions(+) >> >> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c >> index f041b1a..a201c45 100644 >> --- a/drivers/vfio/pci/vfio_pci.c >> +++ b/drivers/vfio/pci/vfio_pci.c >> @@ -597,6 +597,10 @@ static int msix_sparse_mmap_cap(struct vfio_pci_device *vdev, >> i++; >> } >> >> + /* With all alignments, there are no gaps left to mmap */ >> + if (i == 0) >> + sparse->nr_areas = 0; >> + > > Ok, but why does 0 become a special case? Shouldn't we set > sparse->nr_areas = i? Thanks, This is what is returned to QEMU now - 1 sparse region, starts at 0, 0 bytes long. I am missing the point in having such region... > > Alex > >> ret = vfio_info_add_capability(caps, VFIO_REGION_INFO_CAP_SPARSE_MMAP, >> sparse); >> kfree(sparse); > -- Alexey