From patchwork Tue Apr 28 06:28:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grzegorz Uriasz X-Patchwork-Id: 11513903 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99C9914DD for ; Tue, 28 Apr 2020 06:31:38 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 71BB4206A5 for ; Tue, 28 Apr 2020 06:31:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LFE04p88" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 71BB4206A5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jTJlV-0000F2-Uv; Tue, 28 Apr 2020 06:30:45 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jTJkl-0007z5-Ly for xen-devel@lists.xenproject.org; Tue, 28 Apr 2020 06:29:59 +0000 X-Inumbo-ID: aea86df2-8919-11ea-b07b-bc764e2007e4 Received: from mail-wm1-x342.google.com (unknown [2a00:1450:4864:20::342]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id aea86df2-8919-11ea-b07b-bc764e2007e4; Tue, 28 Apr 2020 06:29:59 +0000 (UTC) Received: by mail-wm1-x342.google.com with SMTP id x4so1372373wmj.1 for ; Mon, 27 Apr 2020 23:29:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/xdW9TlF14cno7Dox1YULYIivWRvz4pvd3kbVi7j+L4=; b=LFE04p88MpHoPldLuBL/ef/Ua1bNp9e+y/AioN8MiM9U5SHhMHb2oaOuIHdrgUrfvp OwWz5i3q1Tu4LjPp1sZH+uewJSXti8ttRSe8d4o4Yu9774I62ekPt4PWwGGhSWeKwURe Ujhqmqn4J7uo8NwSOeHNm7zB07nEI89ZLHKzkvQ6aAibNYyiRGvStPM8fWwvmlIgeLf0 kL5lPAGouNRIDqC54gdYhcUeIT8+TvQlmoaylTU7gdf5GOflOAULoHvyg0STXeW1JqD2 b3Wb8+3KZ0w1uJGCNf8Yoy4RhiJJW0ZhIBUJTUGabjsPKXlvUQHvXTzw9rBHXagIZJky 8iiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/xdW9TlF14cno7Dox1YULYIivWRvz4pvd3kbVi7j+L4=; b=RQ+aRrLA2DpPXB1QVykAnR26xrUDjC0lGMb0qPmX/x6uW0Re9tV1UZn5BlVK+XZ85E E5To4QvS9hjJ15zHwQ25u7QSPYRWta0Uz91/CGKEXuoPkw7BhUMUsyGCDncAtYTPJKGz LqYtvBHq7FwvV4wepJhoF+CUwAzj61/3MXYTrn3kX/hxTdCtsAkLh8xaQ1Q5f/K1qAUB xDc5AlmDuWgnij1cDBwVRnp00wMqNAGagzSon6vAiNJR/aaY18pB1NKO3B7uJqO4MCNc TFdiGc8ygkQ4GVAsAWbMFN/Y2khc93LtB2R+g289RmXCYnlbuV5qxg/8s7PbO/gOVpXA /GJg== X-Gm-Message-State: AGi0PubY9upUSytV46+pHkCCcZl0puaKxYSJ3DRjCUbm9hwM25WYkkBU 3pT5t2ZJoAPVcautz2iD6sw= X-Google-Smtp-Source: APiQypJjAWImZKi6yyETe7bMvdVFmRMyX+Q/xhJCHdWzOGMOtz5pIllYGMr6MRFpzeCK7ibGxixnWw== X-Received: by 2002:a1c:8106:: with SMTP id c6mr2746244wmd.88.1588055398259; Mon, 27 Apr 2020 23:29:58 -0700 (PDT) Received: from localhost.localdomain (public-gprs351065.centertel.pl. [37.47.2.154]) by smtp.gmail.com with ESMTPSA id a205sm2030564wmh.29.2020.04.27.23.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2020 23:29:57 -0700 (PDT) From: Grzegorz Uriasz To: qemu-devel@nongnu.org Subject: [PATCH 1/2] Fix undefined behaviour Date: Tue, 28 Apr 2020 06:28:46 +0000 Message-Id: <20200428062847.7764-2-gorbak25@gmail.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200428062847.7764-1-gorbak25@gmail.com> References: <20200428062847.7764-1-gorbak25@gmail.com> MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 28 Apr 2020 06:30:43 +0000 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: artur@puzio.waw.pl, Stefano Stabellini , Paul Durrant , jakub@bartmin.ski, marmarek@invisiblethingslab.com, Grzegorz Uriasz , Anthony Perard , j.nowak26@student.uw.edu.pl, xen-devel@lists.xenproject.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Signed-off-by: Grzegorz Uriasz --- hw/xen/xen_pt_load_rom.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/hw/xen/xen_pt_load_rom.c b/hw/xen/xen_pt_load_rom.c index a50a80837e..9f100dc159 100644 --- a/hw/xen/xen_pt_load_rom.c +++ b/hw/xen/xen_pt_load_rom.c @@ -38,12 +38,12 @@ void *pci_assign_dev_load_option_rom(PCIDevice *dev, fp = fopen(rom_file, "r+"); if (fp == NULL) { if (errno != ENOENT) { - error_report("pci-assign: Cannot open %s: %s", rom_file, strerror(errno)); + warn_report("pci-assign: Cannot open %s: %s", rom_file, strerror(errno)); } return NULL; } if (fstat(fileno(fp), &st) == -1) { - error_report("pci-assign: Cannot stat %s: %s", rom_file, strerror(errno)); + warn_report("pci-assign: Cannot stat %s: %s", rom_file, strerror(errno)); goto close_rom; } @@ -59,10 +59,9 @@ void *pci_assign_dev_load_option_rom(PCIDevice *dev, memset(ptr, 0xff, st.st_size); if (!fread(ptr, 1, st.st_size, fp)) { - error_report("pci-assign: Cannot read from host %s", rom_file); - error_printf("Device option ROM contents are probably invalid " - "(check dmesg).\nSkip option ROM probe with rombar=0, " - "or load from file with romfile=\n"); + warn_report("pci-assign: Cannot read from host %s", rom_file); + memory_region_unref(&dev->rom); + ptr = NULL; goto close_rom; } From patchwork Tue Apr 28 06:28:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grzegorz Uriasz X-Patchwork-Id: 11513907 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 13BED1575 for ; Tue, 28 Apr 2020 06:31:41 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E2853206A5 for ; Tue, 28 Apr 2020 06:31:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R5NuyA6+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E2853206A5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jTJlW-0000FR-7F; Tue, 28 Apr 2020 06:30:46 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jTJkq-0008HL-Uc for xen-devel@lists.xenproject.org; Tue, 28 Apr 2020 06:30:04 +0000 X-Inumbo-ID: b1ca9e74-8919-11ea-9887-bc764e2007e4 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b1ca9e74-8919-11ea-9887-bc764e2007e4; Tue, 28 Apr 2020 06:30:04 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id k13so23235831wrw.7 for ; Mon, 27 Apr 2020 23:30:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yaK0Tjz4Mh+yIXINkTHSBD8ilpF6Ag6GsRW6Q4ivbTA=; b=R5NuyA6+wVEyDRerxt4JF4uR7UXbtDIJQluhU5qdZRUx9wPQijBaoWHuKExJN5wcHQ dVVb7NvWWvf+1x2czH+0zGPevI1byLqnHr0MPTULlbp1TmfLkOR7zhSX12CHtxPziZqE gIYYkCH2yH67+b14kvapCJJAkntr5shxNmrmXBWoPuyBdwMyFzJ3yTMESUZS+Y0tVk4w DTWuCjUR+LEPcrjoz1zyxDLbyWhlSB376x47pXgSXHBY/FF+FiAJhzVWWhXvFZ2IEc+f tHNOsxrLpYTCg1pxz6A04Dsg5icQdRwAAw0m5HdjYoYhhxeOJb88DkJS8DbXJXz+Th1F xAyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yaK0Tjz4Mh+yIXINkTHSBD8ilpF6Ag6GsRW6Q4ivbTA=; b=f2Rf9mam1p9kw5Quesark8tiqfc1nUAMeOmxTHBIkKgpr7lF4KqK2SFn3M3KLhYVCv t9SwceIwCXfftfWB+aQuwZTtPwBu7rUDDRzB+PB4vvOMQ4xcq5FhgGFACaDKHIqwpzLV f/BYL3y5ZNcHk5Fi1P1ji3Sasfe7Mxdf0KVNe7C3CN6gWrW/3c+cM3Rlz2eybx+X1wdy 9bsFFAsTBRdLsffCnV5yxUtvXKKDk7iCBLwWfGu76pAv/OyRmUWIa+aZJ2tM6s56e7V3 ADP7TPqQ3WzS2arkYZYC+9cpnzUf7Y1CzD1k3yUSFmBRCYBN/Uo8uAxGYj1VQSjAp5bd z2Tg== X-Gm-Message-State: AGi0PuZZrIho/gmRMHxuWPtJjRBtxlfbSv/UfcsYcQy/rUKBTSGm598e PvxZyFsGrZRo7nEulvrG4tM= X-Google-Smtp-Source: APiQypJu6V8g7t351GQHZKstcuogANA7URIwmgoWma5c7hYJSKzrp8DyniKXjLah1RJeLvvREzjpfw== X-Received: by 2002:adf:f8c6:: with SMTP id f6mr34233073wrq.276.1588055403438; Mon, 27 Apr 2020 23:30:03 -0700 (PDT) Received: from localhost.localdomain (public-gprs351065.centertel.pl. [37.47.2.154]) by smtp.gmail.com with ESMTPSA id a205sm2030564wmh.29.2020.04.27.23.30.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2020 23:30:02 -0700 (PDT) From: Grzegorz Uriasz To: qemu-devel@nongnu.org Subject: [PATCH 2/2] Improve legacy vbios handling Date: Tue, 28 Apr 2020 06:28:47 +0000 Message-Id: <20200428062847.7764-3-gorbak25@gmail.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200428062847.7764-1-gorbak25@gmail.com> References: <20200428062847.7764-1-gorbak25@gmail.com> MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 28 Apr 2020 06:30:43 +0000 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: artur@puzio.waw.pl, Stefano Stabellini , Paul Durrant , jakub@bartmin.ski, marmarek@invisiblethingslab.com, Grzegorz Uriasz , Anthony Perard , j.nowak26@student.uw.edu.pl, xen-devel@lists.xenproject.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Signed-off-by: Grzegorz Uriasz --- hw/xen/xen_pt.c | 8 +++++-- hw/xen/xen_pt_graphics.c | 48 +++++++++++++++++++++++++++++++++++++--- hw/xen/xen_pt_load_rom.c | 2 +- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index b91082cb8b..ffc3559dd4 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -483,8 +483,12 @@ static int xen_pt_register_regions(XenPCIPassthroughState *s, uint16_t *cmd) i, r->size, r->base_addr, type); } - /* Register expansion ROM address */ - if (d->rom.base_addr && d->rom.size) { + /* + * Register expansion ROM address. If we are dealing with a ROM + * shadow copy for legacy vga devices then don't bother to map it + * as previous code creates a proper shadow copy + */ + if (d->rom.base_addr && d->rom.size && !(is_igd_vga_passthrough(d))) { uint32_t bar_data = 0; /* Re-set BAR reported by OS, otherwise ROM can't be read. */ diff --git a/hw/xen/xen_pt_graphics.c b/hw/xen/xen_pt_graphics.c index a3bc7e3921..fe0ef2685c 100644 --- a/hw/xen/xen_pt_graphics.c +++ b/hw/xen/xen_pt_graphics.c @@ -129,7 +129,7 @@ int xen_pt_unregister_vga_regions(XenHostPCIDevice *dev) return 0; } -static void *get_vgabios(XenPCIPassthroughState *s, int *size, +static void *get_sysfs_vgabios(XenPCIPassthroughState *s, int *size, XenHostPCIDevice *dev) { return pci_assign_dev_load_option_rom(&s->dev, size, @@ -137,6 +137,45 @@ static void *get_vgabios(XenPCIPassthroughState *s, int *size, dev->dev, dev->func); } +static void xen_pt_direct_vbios_copy(XenPCIPassthroughState *s, Error **errp) +{ + int fd = -1; + void *guest_bios = NULL; + void *host_vbios = NULL; + /* This is always 32 pages in the real mode reserved region */ + int bios_size = 32 << XC_PAGE_SHIFT; + int vbios_addr = 0xc0000; + + fd = open("/dev/mem", O_RDONLY); + if (fd == -1) { + error_setg(errp, "Can't open /dev/mem: %s", strerror(errno)); + return; + } + host_vbios = mmap(NULL, bios_size, + PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, fd, vbios_addr); + close(fd); + + if (host_vbios == MAP_FAILED) { + error_setg(errp, "Failed to mmap host vbios: %s", strerror(errno)); + return; + } + + memory_region_init_ram(&s->dev.rom, OBJECT(&s->dev), + "legacy_vbios.rom", bios_size, &error_abort); + guest_bios = memory_region_get_ram_ptr(&s->dev.rom); + memcpy(guest_bios, host_vbios, bios_size); + + if (munmap(host_vbios, bios_size) == -1) { + XEN_PT_LOG(&s->dev, "Failed to unmap host vbios: %s\n", strerror(errno)); + } + + cpu_physical_memory_write(vbios_addr, guest_bios, bios_size); + memory_region_set_address(&s->dev.rom, vbios_addr); + pci_register_bar(&s->dev, PCI_ROM_SLOT, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->dev.rom); + s->dev.has_rom = true; + XEN_PT_LOG(&s->dev, "Legacy VBIOS registered\n"); +} + /* Refer to Seabios. */ struct rom_header { uint16_t signature; @@ -179,9 +218,11 @@ void xen_pt_setup_vga(XenPCIPassthroughState *s, XenHostPCIDevice *dev, return; } - bios = get_vgabios(s, &bios_size, dev); + bios = get_sysfs_vgabios(s, &bios_size, dev); if (!bios) { - error_setg(errp, "VGA: Can't get VBIOS"); + XEN_PT_LOG(&s->dev, "Unable to get host VBIOS from sysfs - " + "falling back to a direct copy of memory ranges\n"); + xen_pt_direct_vbios_copy(s, errp); return; } @@ -223,6 +264,7 @@ void xen_pt_setup_vga(XenPCIPassthroughState *s, XenHostPCIDevice *dev, /* Currently we fixed this address as a primary for legacy BIOS. */ cpu_physical_memory_write(0xc0000, bios, bios_size); + XEN_PT_LOG(&s->dev, "Legacy VBIOS registered\n"); } uint32_t igd_read_opregion(XenPCIPassthroughState *s) diff --git a/hw/xen/xen_pt_load_rom.c b/hw/xen/xen_pt_load_rom.c index 9f100dc159..8cd9aa84dc 100644 --- a/hw/xen/xen_pt_load_rom.c +++ b/hw/xen/xen_pt_load_rom.c @@ -65,7 +65,7 @@ void *pci_assign_dev_load_option_rom(PCIDevice *dev, goto close_rom; } - pci_register_bar(dev, PCI_ROM_SLOT, 0, &dev->rom); + pci_register_bar(dev, PCI_ROM_SLOT, PCI_BASE_ADDRESS_SPACE_MEMORY, &dev->rom); dev->has_rom = true; *size = st.st_size; close_rom: