From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: [PATCH v2 3/4] vfio: vfio-pci device assignment driver Date: Tue, 14 Aug 2012 22:33:34 +0200 Message-ID: <502AB61E.9040008@siemens.com> References: <20120802190936.16069.89673.stgit@bling.home> <20120802191749.16069.22367.stgit@bling.home> <502A8DAB.6010406@siemens.com> <1344971368.4683.314.camel@ul30vt.home> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: "aliguori@us.ibm.com" , "qemu-devel@nongnu.org" , "kvm@vger.kernel.org" , "aik@ozlabs.ru" To: Alex Williamson Return-path: Received: from david.siemens.de ([192.35.17.14]:34983 "EHLO david.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754496Ab2HNUdr (ORCPT ); Tue, 14 Aug 2012 16:33:47 -0400 In-Reply-To: <1344971368.4683.314.camel@ul30vt.home> Sender: kvm-owner@vger.kernel.org List-ID: On 2012-08-14 21:09, Alex Williamson wrote: >>> +static void vfio_map_bar(VFIODevice *vdev, int nr) >>> +{ >>> + VFIOBAR *bar = &vdev->bars[nr]; >>> + unsigned size = bar->size; >>> + char name[64]; >>> + uint32_t pci_bar; >>> + uint8_t type; >>> + int ret; >>> + >>> + /* Skip both unimplemented BARs and the upper half of 64bit BARS. */ >>> + if (!size) { >>> + return; >>> + } >>> + >>> + snprintf(name, sizeof(name), "VFIO %04x:%02x:%02x.%x BAR %d", >>> + vdev->host.domain, vdev->host.bus, vdev->host.slot, >>> + vdev->host.function, nr); >>> + >>> + /* Determine what type of BAR this is for registration */ >>> + ret = pread(vdev->fd, &pci_bar, sizeof(pci_bar), >>> + vdev->config_offset + PCI_BASE_ADDRESS_0 + (4 * nr)); >>> + if (ret != sizeof(pci_bar)) { >>> + error_report("vfio: Failed to read BAR %d (%s)\n", nr, strerror(errno)); >>> + return; >>> + } >>> + >>> + pci_bar = le32_to_cpu(pci_bar); >>> + type = pci_bar & (pci_bar & PCI_BASE_ADDRESS_SPACE_IO ? >>> + ~PCI_BASE_ADDRESS_IO_MASK : ~PCI_BASE_ADDRESS_MEM_MASK); >>> + >>> + /* A "slow" read/write mapping underlies all BARs */ >>> + memory_region_init_io(&bar->mem, &vfio_bar_ops, bar, name, size); >>> + pci_register_bar(&vdev->pdev, nr, type, &bar->mem); >>> + >>> + /* >>> + * We can't mmap areas overlapping the MSIX vector table, so we >>> + * potentially insert a direct-mapped subregion before and after it. >>> + */ >>> + if (vdev->msix && vdev->msix->table_bar == nr) { >>> + size = vdev->msix->table_offset & TARGET_PAGE_MASK; >>> + } >>> + >>> + strncat(name, " mmap", sizeof(name) - strlen(name) - 1); >> >> This could generate an unterminated name if we actually have to cut the >> appended string. You could set name[sizeof(name)-1] = 0. > > strncat adds the terminator, that's why we have the -1 so that there's > space for it. strlen does not include the terminator. Yep, you are right, forget what I said. Jan -- Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:35617) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1No3-0007w7-6b for qemu-devel@nongnu.org; Tue, 14 Aug 2012 16:33:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T1No2-0001o8-4p for qemu-devel@nongnu.org; Tue, 14 Aug 2012 16:33:39 -0400 Received: from david.siemens.de ([192.35.17.14]:33591) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1No1-0001n2-RR for qemu-devel@nongnu.org; Tue, 14 Aug 2012 16:33:38 -0400 Message-ID: <502AB61E.9040008@siemens.com> Date: Tue, 14 Aug 2012 22:33:34 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <20120802190936.16069.89673.stgit@bling.home> <20120802191749.16069.22367.stgit@bling.home> <502A8DAB.6010406@siemens.com> <1344971368.4683.314.camel@ul30vt.home> In-Reply-To: <1344971368.4683.314.camel@ul30vt.home> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 3/4] vfio: vfio-pci device assignment driver List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex Williamson Cc: "aik@ozlabs.ru" , "aliguori@us.ibm.com" , "qemu-devel@nongnu.org" , "kvm@vger.kernel.org" On 2012-08-14 21:09, Alex Williamson wrote: >>> +static void vfio_map_bar(VFIODevice *vdev, int nr) >>> +{ >>> + VFIOBAR *bar = &vdev->bars[nr]; >>> + unsigned size = bar->size; >>> + char name[64]; >>> + uint32_t pci_bar; >>> + uint8_t type; >>> + int ret; >>> + >>> + /* Skip both unimplemented BARs and the upper half of 64bit BARS. */ >>> + if (!size) { >>> + return; >>> + } >>> + >>> + snprintf(name, sizeof(name), "VFIO %04x:%02x:%02x.%x BAR %d", >>> + vdev->host.domain, vdev->host.bus, vdev->host.slot, >>> + vdev->host.function, nr); >>> + >>> + /* Determine what type of BAR this is for registration */ >>> + ret = pread(vdev->fd, &pci_bar, sizeof(pci_bar), >>> + vdev->config_offset + PCI_BASE_ADDRESS_0 + (4 * nr)); >>> + if (ret != sizeof(pci_bar)) { >>> + error_report("vfio: Failed to read BAR %d (%s)\n", nr, strerror(errno)); >>> + return; >>> + } >>> + >>> + pci_bar = le32_to_cpu(pci_bar); >>> + type = pci_bar & (pci_bar & PCI_BASE_ADDRESS_SPACE_IO ? >>> + ~PCI_BASE_ADDRESS_IO_MASK : ~PCI_BASE_ADDRESS_MEM_MASK); >>> + >>> + /* A "slow" read/write mapping underlies all BARs */ >>> + memory_region_init_io(&bar->mem, &vfio_bar_ops, bar, name, size); >>> + pci_register_bar(&vdev->pdev, nr, type, &bar->mem); >>> + >>> + /* >>> + * We can't mmap areas overlapping the MSIX vector table, so we >>> + * potentially insert a direct-mapped subregion before and after it. >>> + */ >>> + if (vdev->msix && vdev->msix->table_bar == nr) { >>> + size = vdev->msix->table_offset & TARGET_PAGE_MASK; >>> + } >>> + >>> + strncat(name, " mmap", sizeof(name) - strlen(name) - 1); >> >> This could generate an unterminated name if we actually have to cut the >> appended string. You could set name[sizeof(name)-1] = 0. > > strncat adds the terminator, that's why we have the -1 so that there's > space for it. strlen does not include the terminator. Yep, you are right, forget what I said. Jan -- Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux