From patchwork Sun Jun 14 22:12:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grzegorz Uriasz X-Patchwork-Id: 11603443 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 5B382913 for ; Sun, 14 Jun 2020 22:13:43 +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 36E352067B for ; Sun, 14 Jun 2020 22:13:43 +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="S0YApsTe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 36E352067B 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 1jkarR-0000B4-P1; Sun, 14 Jun 2020 22:12:17 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jkarQ-00009r-Md for xen-devel@lists.xenproject.org; Sun, 14 Jun 2020 22:12:16 +0000 X-Inumbo-ID: 1941eeb2-ae8c-11ea-b7bb-bc764e2007e4 Received: from mail-ed1-x543.google.com (unknown [2a00:1450:4864:20::543]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1941eeb2-ae8c-11ea-b7bb-bc764e2007e4; Sun, 14 Jun 2020 22:12:13 +0000 (UTC) Received: by mail-ed1-x543.google.com with SMTP id c35so10124983edf.5 for ; Sun, 14 Jun 2020 15:12:13 -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=F2zlyMIKfLVDpbJSsJPj/zZztFJH8ixIurr3m9NMur4=; b=S0YApsTeJu5e/fblFRbEgUob92Yv1YnnRSUio+NYsQH6n5INj0+wUhrecL/1N/xJjf SSm0J7Kt9nMSfPUQPMCO0YsqxBMKDvR3xOpoiKWruwFbI/UrW53imvkfhsFN0Ge5IIRP PNxQqM9y46Ad6iyPnQqGiKTD3jK5jy2iWA/0gVs6HVfhErOtqyqeAbpBtspfGDJyde3I HV7wHZx4iGUyIsh3lwayBAf7j5SGrRwnASy8rL2ADi7ag79KWMHpcjYu9ZWhK9p8fRAn QMtJoHlNkL0xALXdy4uol9Sv1CPZcEYbx48gSip8qH91Wj6R6szOGvpB7vnwYwKVjYY6 GYAA== 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=F2zlyMIKfLVDpbJSsJPj/zZztFJH8ixIurr3m9NMur4=; b=W34IDcnyKTiYVFJGL6qWlnZ5ZAzYWf9leoDdycY0CcZgIDWo4GghImv2ch64zjEbYX GFXi6HeSDiwB7cAQmiXCsGp+wrj5AOPmDBITH7yuE2JqC2VSBAaNKXRfTly/qN1+Zp1F 6F0LuPf1CjDim2gFoOc12nRnzXi/y+w04ahp6qs2SS+kw87TsVhukKo5Y237YcE8lrPJ GT3UG4M/z4jRabERiaPTMMl9J009dCtj+0gZFu2ygHgA21yI1J7vnMR7daLwT1sh+aYm XQO8EQfuuXzL9i8RQCRqFxGiR4j539cztphgmgaBgJijPEMcOvtvGMPpLwKMu+0CCFaT DRSA== X-Gm-Message-State: AOAM530Ttbue4j5LP4URCPkzQuBoHF2kYa/WqEJJ7s+Z++NccU+qiYd2 6WSmC4FZBBQ21+oQ5W7CIErT0s8A7eU7wg== X-Google-Smtp-Source: ABdhPJwjNFrm+gUduG2OvP3Fe30QR7Gt+WVgIEU4/reWGAeKtzYMyjGDi9XOsk8lHZ2Sy0Fa0n/icQ== X-Received: by 2002:a50:fb92:: with SMTP id e18mr20499391edq.135.1592172732450; Sun, 14 Jun 2020 15:12:12 -0700 (PDT) Received: from localhost.localdomain (public-gprs354212.centertel.pl. [37.47.14.229]) by smtp.gmail.com with ESMTPSA id o13sm7772828ejb.46.2020.06.14.15.12.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jun 2020 15:12:12 -0700 (PDT) From: Grzegorz Uriasz To: xen-devel@lists.xenproject.org Subject: [PATCH 1/3] tools/libxl: Grant VGA IO port permission for stubdom/target domain Date: Sun, 14 Jun 2020 22:12:01 +0000 Message-Id: <87d74a21bde95cfc7c53fad56bf8f0e47724953e.1592171394.git.gorbak25@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 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: Wei Liu , jakub@bartmin.ski, Ian Jackson , marmarek@invisiblethingslab.com, Grzegorz Uriasz , j.nowak26@student.uw.edu.pl, Anthony PERARD , contact@puzio.waw.pl Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" When qemu is running inside a linux based stubdomain, qemu does not have the necessary permissions to map the ioports to the target domain. Currently, libxl is granting permissions only for the VGA RAM memory region and not passing the required ioports. This patch grants the required permission for the necessary vga io ports. Signed-off-by: Grzegorz Uriasz --- tools/libxl/libxl_pci.c | 99 ++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 26 deletions(-) diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 957ff5c8e9..436190f790 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -2441,17 +2441,75 @@ void libxl__device_pci_destroy_all(libxl__egc *egc, uint32_t domid, } } +static int libxl__grant_legacy_vga_permissions(libxl__gc *gc, const uint32_t domid) { + int ret, i; + uint64_t vga_iomem_start = 0xa0000 >> XC_PAGE_SHIFT; + uint64_t vga_iomem_npages = 0x20; + uint32_t stubdom_domid = libxl_get_stubdom_id(CTX, domid); + uint64_t vga_ioport_start[] = {0x3B0, 0x3C0}; + uint64_t vga_ioport_size[] = {0xC, 0x20}; + + /* VGA RAM */ + ret = xc_domain_iomem_permission(CTX->xch, stubdom_domid, + vga_iomem_start, vga_iomem_npages, 1); + if (ret < 0) { + LOGED(ERROR, domid, + "failed to give stubdom%d access to iomem range " + "%"PRIx64"-%"PRIx64" for VGA passthru", + stubdom_domid, + vga_iomem_start, (vga_iomem_start + (vga_iomem_npages << XC_PAGE_SHIFT) - 1)); + return ret; + } + ret = xc_domain_iomem_permission(CTX->xch, domid, + vga_iomem_start, vga_iomem_npages, 1); + if (ret < 0) { + LOGED(ERROR, domid, + "failed to give dom%d access to iomem range " + "%"PRIx64"-%"PRIx64" for VGA passthru", + domid, vga_iomem_start, (vga_iomem_start + (vga_iomem_npages << XC_PAGE_SHIFT) - 1)); + return ret; + } + + /* VGA IOPORTS */ + for (i = 0 ; i < 2 ; i++) { + ret = xc_domain_ioport_permission(CTX->xch, stubdom_domid, + vga_ioport_start[i], vga_ioport_size[i], 1); + if (ret < 0) { + LOGED(ERROR, domid, + "failed to give stubdom%d access to ioport range " + "%"PRIx64"-%"PRIx64" for VGA passthru", + stubdom_domid, + vga_ioport_start[i], (vga_ioport_start[i] + vga_ioport_size[i] - 1)); + return ret; + } + ret = xc_domain_ioport_permission(CTX->xch, domid, + vga_ioport_start[i], vga_ioport_size[i], 1); + if (ret < 0) { + LOGED(ERROR, domid, + "failed to give dom%d access to ioport range " + "%"PRIx64"-%"PRIx64" for VGA passthru", + domid, vga_ioport_start[i], (vga_ioport_start[i] + vga_ioport_size[i] - 1)); + return ret; + } + } + + return 0; +} + +static int libxl__grant_igd_opregion_permission(libxl__gc *gc, const uint32_t domid) { + return 0; +} + int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid, libxl_domain_config *const d_config) { - int i, ret; + int i, ret = 0; + bool vga_found = false, igd_found = false; if (!libxl_defbool_val(d_config->b_info.u.hvm.gfx_passthru)) return 0; - for (i = 0 ; i < d_config->num_pcidevs ; i++) { - uint64_t vga_iomem_start = 0xa0000 >> XC_PAGE_SHIFT; - uint32_t stubdom_domid; + for (i = 0 ; i < d_config->num_pcidevs && !igd_found ; i++) { libxl_device_pci *pcidev = &d_config->pcidevs[i]; unsigned long pci_device_class; @@ -2460,30 +2518,19 @@ int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid, if (pci_device_class != 0x030000) /* VGA class */ continue; - stubdom_domid = libxl_get_stubdom_id(CTX, domid); - ret = xc_domain_iomem_permission(CTX->xch, stubdom_domid, - vga_iomem_start, 0x20, 1); - if (ret < 0) { - LOGED(ERROR, domid, - "failed to give stubdom%d access to iomem range " - "%"PRIx64"-%"PRIx64" for VGA passthru", - stubdom_domid, - vga_iomem_start, (vga_iomem_start + 0x20 - 1)); - return ret; - } - ret = xc_domain_iomem_permission(CTX->xch, domid, - vga_iomem_start, 0x20, 1); - if (ret < 0) { - LOGED(ERROR, domid, - "failed to give dom%d access to iomem range " - "%"PRIx64"-%"PRIx64" for VGA passthru", - domid, vga_iomem_start, (vga_iomem_start + 0x20 - 1)); - return ret; - } - break; + vga_found = true; + if (pcidev->bus == 0 && pcidev->dev == 2 && pcidev->func == 0) + igd_found = true; } - return 0; + if (vga_found) + ret = libxl__grant_legacy_vga_permissions(gc, domid); + if (ret < 0) + return ret; + if (igd_found) + ret = libxl__grant_igd_opregion_permission(gc, domid); + + return ret; } static int libxl_device_pci_compare(const libxl_device_pci *d1, From patchwork Sun Jun 14 22:12:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grzegorz Uriasz X-Patchwork-Id: 11603445 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 620C6913 for ; Sun, 14 Jun 2020 22:13:49 +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 3A09D2067B for ; Sun, 14 Jun 2020 22:13:49 +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="adGPkbzd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3A09D2067B 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 1jkarX-0000BP-1L; Sun, 14 Jun 2020 22:12:23 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jkarV-00009r-Mu for xen-devel@lists.xenproject.org; Sun, 14 Jun 2020 22:12:21 +0000 X-Inumbo-ID: 1a644538-ae8c-11ea-bb8b-bc764e2007e4 Received: from mail-ej1-x644.google.com (unknown [2a00:1450:4864:20::644]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1a644538-ae8c-11ea-bb8b-bc764e2007e4; Sun, 14 Jun 2020 22:12:15 +0000 (UTC) Received: by mail-ej1-x644.google.com with SMTP id mb16so15382762ejb.4 for ; Sun, 14 Jun 2020 15:12:15 -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=K9vVjeVfBAmD5toSQvhwolJYZoUXP1UxEwduLBU73+A=; b=adGPkbzd1pDFW3MMUjjil8woWTnpy+IswqfHTBgRpgUbyY0AVHlMEKG1ayjzQFjxGz 5G3gUp4An2Nvf5+xtlvUBunXcYc2WLQX42O7pVQmwJH/zJWgWgTIEr54qGeS/VuALz1Q 9wUpKwpddrfCgGMAKXevlA9ZRN+cEoWSsfsAwIBmt5lrAV/7cEXZ7u4de4sv1XjYr3HV FbEAYtti7lgeykcE0PlstCDtmD++QZDXkd+CQYw1hpNja4QvDqV5OIyA3PjeVLUtNQPE 1DNv4GtjP2YW3QlKlZDr/H5zzlG4vL6HpcWB4eHWUmFvZsSHBKFGFLXqAbmu10LaxikN gzYg== 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=K9vVjeVfBAmD5toSQvhwolJYZoUXP1UxEwduLBU73+A=; b=ZGrwSYmnc1eJpEuYifzTk2Zr+TCDrYgbQ8Ksw8Ovw/xtywTrV5E/Wca15mbX7fUhpw WKR6UIpVlF0wPeL4JgC8gnVhH0xu96LbGApKVmK6neZ4IKpa725gSEoSqiyoOU9wKAoU MmVOcQSpK+O9k1WKK0mgK4wHJUJFfON+1wsp1GlhRrLADbRusoV1pedZSVq6S5CeLrcu bad4mf/MKCj/YfRHbSB4Q6Kr+s3lPqQorETM4CMWRhZlUnXl/qXJi3E7gU7oNS4Ujywi CxLaOlDniuBwFWIIhUkz6Jz/lmLCYR6c19URmPVgIIXu/oQ6XkTERChxLfM/bQ5RS2/p vjQA== X-Gm-Message-State: AOAM530pQpzJp4BTzGOw2Agh8W/T5+s2tT5OCbArFRK7PWJrOnLu//QI DsVA8qfluWAVVKV4UzIQgplNQtlLC4QrdQ== X-Google-Smtp-Source: ABdhPJxxMqGxxS/Bt2pPFAmezto6oZ1Tkhi9T994RozWfo95KLi4xIcCkyj/iEhidE91AhWez433ig== X-Received: by 2002:a17:906:b1c3:: with SMTP id bv3mr23526685ejb.292.1592172734456; Sun, 14 Jun 2020 15:12:14 -0700 (PDT) Received: from localhost.localdomain (public-gprs354212.centertel.pl. [37.47.14.229]) by smtp.gmail.com with ESMTPSA id o13sm7772828ejb.46.2020.06.14.15.12.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jun 2020 15:12:13 -0700 (PDT) From: Grzegorz Uriasz To: xen-devel@lists.xenproject.org Subject: [PATCH 2/3] tools/libxl: Grant permission for mapping opregions to the target domain Date: Sun, 14 Jun 2020 22:12:02 +0000 Message-Id: <18bebc4af48b83d71b3247082434b958be84b841.1592171394.git.gorbak25@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 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: Wei Liu , jakub@bartmin.ski, Ian Jackson , marmarek@invisiblethingslab.com, Grzegorz Uriasz , j.nowak26@student.uw.edu.pl, Anthony PERARD , contact@puzio.waw.pl Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" IGD VGA devices require a special opregion MMIO region which functions as an extra BAR in the PCI configuration space. Right now qemu is assigning those permissions - this is failing inside a linux based stubdomain as the stubdomain is not privileged. This patch grants the permissions for opregions in libxl instead of qemu. Granting permissions in qemu may be removed when this patch get's merged - for now linux based stubdomains which use IGD's need to patch qemu and include this patch in xen for IGD passthrough to work. Signed-off-by: Grzegorz Uriasz --- tools/libxl/libxl_pci.c | 46 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 436190f790..48b1d8073b 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -2497,7 +2497,51 @@ static int libxl__grant_legacy_vga_permissions(libxl__gc *gc, const uint32_t dom } static int libxl__grant_igd_opregion_permission(libxl__gc *gc, const uint32_t domid) { - return 0; + char* sysfs_path; + FILE* f; + uint32_t igd_host_opregion; + int ret = 0; + uint32_t stubdom_domid = libxl_get_stubdom_id(CTX, domid); + + sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/config", 0, 0, 2, 0); + f = fopen(sysfs_path, "r"); + if (!f) { + LOGED(ERROR, domid, "Unable to access IGD config space"); + return ERROR_FAIL; + } + + ret = fseek(f, 0xfc, SEEK_SET); + if (ret < 0) { + LOGED(ERROR, domid, "Unable to lseek in PCI config space"); + goto out; + } + + ret = fread((void*)&igd_host_opregion, 4, 1, f); + if (ret < 0) { + LOGED(ERROR, domid, "Unable to read opregion register"); + goto out; + } + + ret = xc_domain_iomem_permission(CTX->xch, stubdom_domid, + (unsigned long)(igd_host_opregion >> XC_PAGE_SHIFT), 0x3, 1); + if (ret < 0) { + LOGED(ERROR, domid, + "failed to give stubdom%d access to %"PRIx32" opregions for igd passthrough", stubdom_domid, igd_host_opregion); + goto out; + } + + ret = xc_domain_iomem_permission(CTX->xch, domid, + (unsigned long)(igd_host_opregion >> XC_PAGE_SHIFT), 0x3, 1); + if (ret < 0) { + LOGED(ERROR, domid, + "failed to give dom%d access to %"PRIx32" opregions for igd passthrough", domid, igd_host_opregion); + goto out; + } + + out: + if(f) + fclose(f); + return ret; } int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid, From patchwork Sun Jun 14 22:12:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grzegorz Uriasz X-Patchwork-Id: 11603447 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 927E5913 for ; Sun, 14 Jun 2020 22:13:52 +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 6E6D42067B for ; Sun, 14 Jun 2020 22:13:52 +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="nekzYCKt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E6D42067B 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 1jkarc-0000Ci-9P; Sun, 14 Jun 2020 22:12:28 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jkara-00009r-NB for xen-devel@lists.xenproject.org; Sun, 14 Jun 2020 22:12:26 +0000 X-Inumbo-ID: 1b898bb2-ae8c-11ea-8496-bc764e2007e4 Received: from mail-ej1-x643.google.com (unknown [2a00:1450:4864:20::643]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1b898bb2-ae8c-11ea-8496-bc764e2007e4; Sun, 14 Jun 2020 22:12:17 +0000 (UTC) Received: by mail-ej1-x643.google.com with SMTP id gl26so15342904ejb.11 for ; Sun, 14 Jun 2020 15:12:17 -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=kLRVBuDUDaOcgBVQ0wo5+UBjW8DkKN77rftCvaZTsIA=; b=nekzYCKtPlBwtlHnKvgZ9CzTcRT1AtzMXQnmTO+Ob3xGKrOHXKGXinBUOlfitQfQxj ZCEHH+Iun4a2lBF8xkAiON++UnRrbOE31OymdlD0PHC3t+wuYyKyIx2nU0d+Y/fyFv47 h6YeG9ALHOj+CJkXbphz5+cW8Qk/pF8Et213L8PHGdTIRvvbp1tgu/o6e5MUujYWcjCn q/x7AIO7U6QTbmFsuSrYCN502H+bD8/oj9kCiClP2/2dYf00xGN6Rq51llar0eVlwksR KTZdIAsPZTBTCQRjBd0iprT2fWDeovBcOmWB6bTZBKw1kOVLJbpWTKtIWE4or+AFvc4/ 5DtA== 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=kLRVBuDUDaOcgBVQ0wo5+UBjW8DkKN77rftCvaZTsIA=; b=g8PP/JF8ae/cdlqh+0tDrVLCHie4S6s+iYAoC/tJx4dR72a4MnTGB6d4b4CPrZP/dl /RfCYSFigBsZV7qUrhpG8zhK4MD3XN58N5y907VkRtcdSdOsY9ahOlMGd+bFsLdf9EsY J/JWj/btUes8XZOjDMqBpHaphDH/QoYh0BqtHeYPcVLiPYgiQr/JAvN5W9DJ3edZUpxd KmU1jv/NPtUWbui3EnLLdjS7rsK7SWlBgt0YWHdLMpeTiSlVRGlmRsNW7kd9m1R4s5n9 ZhKSJlBqXB/2YksiHq87Ta+9CXx7h7+JsK4Wrw2cW58UNI0ntpShD/iT5SysvKZXfkDc h5Zw== X-Gm-Message-State: AOAM530F8Xc7fJ0aRrU43gjKtvaVrnlUX5rYmRhxueUe5XhWrwQ1XAHU hfiCjqBeaE774jp0ML6Q14FKE6u41GBXeQ== X-Google-Smtp-Source: ABdhPJz0czg6GoGOiQFBr78sHMKFKu2xW2RrdQcRTPNKDp6zAcszpEcJ6ykOIpV0LcbSQwAIhSlTJg== X-Received: by 2002:a17:907:2162:: with SMTP id rl2mr21608022ejb.365.1592172736358; Sun, 14 Jun 2020 15:12:16 -0700 (PDT) Received: from localhost.localdomain (public-gprs354212.centertel.pl. [37.47.14.229]) by smtp.gmail.com with ESMTPSA id o13sm7772828ejb.46.2020.06.14.15.12.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jun 2020 15:12:15 -0700 (PDT) From: Grzegorz Uriasz To: xen-devel@lists.xenproject.org Subject: [PATCH 3/3] tools/libxl: Directly map VBIOS to stubdomain Date: Sun, 14 Jun 2020 22:12:03 +0000 Message-Id: <9817b73ea628c7ac86903bb9aa7fcfecf4f7b900.1592171394.git.gorbak25@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 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: Wei Liu , jakub@bartmin.ski, Ian Jackson , marmarek@invisiblethingslab.com, Grzegorz Uriasz , j.nowak26@student.uw.edu.pl, Anthony PERARD , contact@puzio.waw.pl Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" When passing through a IGD VGA device qemu needs to copy the host VBIOS to the target domain. Right now the current implementation on the qemu side is one big undefined behavior as described in my qemu patchset here: https://patchew.org/QEMU/20200428062847.7764-1-gorbak25@gmail.com/ This patch is tied to the linked patchset for qemu but fortunately this patch still works without the qemu part merged. When the qemu part gets merged then qemu will access the VBIOS using /dev/mem - this is required as currently the linux kernel forbids accessing this memory region when the VBIOS is corrupted - which will always be the case as described in the linked patchset. When qemu is running inside a linux based stubdomain then the stubdomain does not have access to the VBIOS. This patch maps the VBIOS to the stubdomain so qemu with my fixes may create a shadow copy for the target domain. Signed-off-by: Grzegorz Uriasz --- tools/libxl/libxl_pci.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 48b1d8073b..9b9564dd73 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -2445,6 +2445,8 @@ static int libxl__grant_legacy_vga_permissions(libxl__gc *gc, const uint32_t dom int ret, i; uint64_t vga_iomem_start = 0xa0000 >> XC_PAGE_SHIFT; uint64_t vga_iomem_npages = 0x20; + uint64_t vga_vbios_start = 0xc0000 >> XC_PAGE_SHIFT; + uint64_t vga_vbios_npages = 0x20; uint32_t stubdom_domid = libxl_get_stubdom_id(CTX, domid); uint64_t vga_ioport_start[] = {0x3B0, 0x3C0}; uint64_t vga_ioport_size[] = {0xC, 0x20}; @@ -2460,6 +2462,7 @@ static int libxl__grant_legacy_vga_permissions(libxl__gc *gc, const uint32_t dom vga_iomem_start, (vga_iomem_start + (vga_iomem_npages << XC_PAGE_SHIFT) - 1)); return ret; } + ret = xc_domain_iomem_permission(CTX->xch, domid, vga_iomem_start, vga_iomem_npages, 1); if (ret < 0) { @@ -2470,6 +2473,13 @@ static int libxl__grant_legacy_vga_permissions(libxl__gc *gc, const uint32_t dom return ret; } + /* VGA ROM */ + ret = xc_domain_memory_mapping(CTX->xch, stubdom_domid, vga_vbios_start, vga_vbios_start, vga_vbios_npages, DPCI_ADD_MAPPING); + if (ret < 0) { + LOGED(ERROR, domid, "failed to map VBIOS to stubdom%d", stubdom_domid); + return ret; + } + /* VGA IOPORTS */ for (i = 0 ; i < 2 ; i++) { ret = xc_domain_ioport_permission(CTX->xch, stubdom_domid,