From nobody Fri May 3 12:12:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1592172763; cv=none; d=zohomail.com; s=zohoarc; b=bAmOJHNf+6gaL5PE0UsXe2YOtrD7tuQBI/iZzZUM5yQNc8TeLLU3rAmVGwWgv/V7QqJF2WYlTb8inreNM0JJneT1SMoDYDHTYNwGFqeznhrNMHla19+xA3qQclZ3T2PZz1ZgpKb3/Ta+q9wKYJCCMqzy5VpAHO32VZgtFQs8Hnk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592172763; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=F2zlyMIKfLVDpbJSsJPj/zZztFJH8ixIurr3m9NMur4=; b=Rkeaju5ApNqqBWuLx0T0KomqZXXccfMn77HzCCJA7HveiXDw9WWGKgHInc9PKEodbhMQ9BwgvT9StOstJ/vTPP4Wywuw5uKusi+fsKmjL1SaBarrckEwFtCyzjkWUgNc164JOeg3pReGEPyLW+BZlshv9a7tXEG1QhXukr7594Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1592172763697386.3281802578423; Sun, 14 Jun 2020 15:12:43 -0700 (PDT) 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 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) 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) X-Inumbo-ID: 1941eeb2-ae8c-11ea-b7bb-bc764e2007e4 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) 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 Content-Transfer-Encoding: quoted-printable 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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, } } =20 +static int libxl__grant_legacy_vga_permissions(libxl__gc *gc, const uint32= _t domid) { + int ret, i; + uint64_t vga_iomem_start =3D 0xa0000 >> XC_PAGE_SHIFT; + uint64_t vga_iomem_npages =3D 0x20; + uint32_t stubdom_domid =3D libxl_get_stubdom_id(CTX, domid); + uint64_t vga_ioport_start[] =3D {0x3B0, 0x3C0}; + uint64_t vga_ioport_size[] =3D {0xC, 0x20}; + + /* VGA RAM */ + ret =3D 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 =3D 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 =3D 0 ; i < 2 ; i++) { + ret =3D 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_s= ize[i] - 1)); + return ret; + } + ret =3D 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_i= oport_size[i] - 1)); + return ret; + } + } + + return 0; +} + +static int libxl__grant_igd_opregion_permission(libxl__gc *gc, const uint3= 2_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 =3D 0; + bool vga_found =3D false, igd_found =3D false; =20 if (!libxl_defbool_val(d_config->b_info.u.hvm.gfx_passthru)) return 0; =20 - for (i =3D 0 ; i < d_config->num_pcidevs ; i++) { - uint64_t vga_iomem_start =3D 0xa0000 >> XC_PAGE_SHIFT; - uint32_t stubdom_domid; + for (i =3D 0 ; i < d_config->num_pcidevs && !igd_found ; i++) { libxl_device_pci *pcidev =3D &d_config->pcidevs[i]; unsigned long pci_device_class; =20 @@ -2460,30 +2518,19 @@ int libxl__grant_vga_iomem_permission(libxl__gc *gc= , const uint32_t domid, if (pci_device_class !=3D 0x030000) /* VGA class */ continue; =20 - stubdom_domid =3D libxl_get_stubdom_id(CTX, domid); - ret =3D 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 =3D 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 =3D true; + if (pcidev->bus =3D=3D 0 && pcidev->dev =3D=3D 2 && pcidev->func = =3D=3D 0) + igd_found =3D true; } =20 - return 0; + if (vga_found) + ret =3D libxl__grant_legacy_vga_permissions(gc, domid); + if (ret < 0) + return ret; + if (igd_found) + ret =3D libxl__grant_igd_opregion_permission(gc, domid); + + return ret; } =20 static int libxl_device_pci_compare(const libxl_device_pci *d1, --=20 2.27.0 From nobody Fri May 3 12:12:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1592172764; cv=none; d=zohomail.com; s=zohoarc; b=P+A2JZLESwqN4YasHMZ6pPca46M6OJaXGSih1CtcZCHyUf9oUYcGDAWPQ8rTcHNMwbFxGlenTrME4Oqivkoyqt5W3ZhQIKuRUsQ/Dky20L4e0sprVedHf0mOf5A+a/Iu5wAAmmswD3GdUo8PuW7ijHQswSTOCuo4fVZsFnR1DPc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592172764; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=K9vVjeVfBAmD5toSQvhwolJYZoUXP1UxEwduLBU73+A=; b=Uk5ceVx+THV3ByVMl2+7erBlyW4sOR1jKWT/NoZplxc14gqRdtqNGcB7YU84veL3T4OrU8mhpXEwAjI4y8i4m2f24+8m/I1YB2TiQAFrjtmBi4qIW+PEpnjFbKnieeV16GKYc463+3VIiQd+8PwuJ/YymypuNgqk6vFrOo6lz/U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1592172764327280.75020912015816; Sun, 14 Jun 2020 15:12:44 -0700 (PDT) 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 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) 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) X-Inumbo-ID: 1a644538-ae8c-11ea-bb8b-bc764e2007e4 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) 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 Content-Transfer-Encoding: quoted-printable 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 th= ose 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 rem= oved when this patch get's merged - for now linux based stubdomains which use IG= D's need to patch qemu and include this patch in xen for IGD passthrough to wor= k. 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 } =20 static int libxl__grant_igd_opregion_permission(libxl__gc *gc, const uint3= 2_t domid) { - return 0; + char* sysfs_path; + FILE* f; + uint32_t igd_host_opregion; + int ret =3D 0; + uint32_t stubdom_domid =3D libxl_get_stubdom_id(CTX, domid); + + sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/config", 0, 0, 2, 0); + f =3D fopen(sysfs_path, "r"); + if (!f) { + LOGED(ERROR, domid, "Unable to access IGD config space"); + return ERROR_FAIL; + } + + ret =3D fseek(f, 0xfc, SEEK_SET); + if (ret < 0) { + LOGED(ERROR, domid, "Unable to lseek in PCI config space"); + goto out; + } + + ret =3D fread((void*)&igd_host_opregion, 4, 1, f); + if (ret < 0) { + LOGED(ERROR, domid, "Unable to read opregion register"); + goto out; + } + + ret =3D 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 =3D 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; } =20 int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid, --=20 2.27.0 From nobody Fri May 3 12:12:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1592172764; cv=none; d=zohomail.com; s=zohoarc; b=QOOl544qzRcCJQI3ODiqQR+iMEsSCySFKr7srZ5j/1L4nA2xRw/Sq7fYkL7C2Aug5g1sDf6G9ASlAlwG60fc2UXaqdaIm93WZX4EUuNIDcHIrm3kAfWPebafuoumkYQRgg8YJPm/cls8BukK/+aXz+wESgi81dKikfRGfFfDM2k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592172764; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kLRVBuDUDaOcgBVQ0wo5+UBjW8DkKN77rftCvaZTsIA=; b=VykOSeehtZGXAYuEtQ0bJYqIWrwlSKRVxbcC+SQKwVwgEUKDQpesYst8jRhF3xeAdoJSz0bE2CLIhBEetFv0IMjgo7a5skt/78bQ/mc2wV9kvLAWgNRsDEApTf0ZpCgIz5YMAySHbyRQltki6SxbMeg+NKS8u0uCBg4V2axVUog= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 159217276446485.9395756252959; Sun, 14 Jun 2020 15:12:44 -0700 (PDT) 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 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) 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) X-Inumbo-ID: 1b898bb2-ae8c-11ea-8496-bc764e2007e4 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) 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 Content-Transfer-Encoding: quoted-printable 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 =3D 0xa0000 >> XC_PAGE_SHIFT; uint64_t vga_iomem_npages =3D 0x20; + uint64_t vga_vbios_start =3D 0xc0000 >> XC_PAGE_SHIFT; + uint64_t vga_vbios_npages =3D 0x20; uint32_t stubdom_domid =3D libxl_get_stubdom_id(CTX, domid); uint64_t vga_ioport_start[] =3D {0x3B0, 0x3C0}; uint64_t vga_ioport_size[] =3D {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 =3D 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; } =20 + /* VGA ROM */ + ret =3D xc_domain_memory_mapping(CTX->xch, stubdom_domid, vga_vbios_st= art, vga_vbios_start, vga_vbios_npages, DPCI_ADD_MAPPING); + if (ret < 0) { + LOGED(ERROR, domid, "failed to map VBIOS to stubdom%d", stubdom_do= mid); + return ret; + } + /* VGA IOPORTS */ for (i =3D 0 ; i < 2 ; i++) { ret =3D xc_domain_ioport_permission(CTX->xch, stubdom_domid, --=20 2.27.0