From nobody Sat Nov 30 12:32:29 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=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1604926269; cv=none; d=zohomail.com; s=zohoarc; b=MoFowYXQcJhtxIT5IRyGjhUZrSiSZQDKRlyAYRGaqvq3m+XqW0raksRIFjPTIGjrHMrEcRYKws6LI75t87k7UXegKN+GLH+Llbqr7MwEhgqjP7ydk45Yw2PYsR5lJ3pED9gEl2IPIqWgC80wfhAGxGUS5/gLRs31oB0eYw+CbfA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604926269; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=1rzuTCzz2KF+DRZQjteexLeZTdzBj+314YEg3qH31eU=; b=lWxYzJaW/rjGhLWpYr3jzJHfP++GyamR6W5MiqWSFJQzxW+c8SeCdkeXePgD1lC+M0sFueUmyenUPfGRkXRT3pUp/LpG2LHBbvbAeaTK13T/7y571IaojEfgNH4UpMr8WDmoDcbt7XTxDc5BhhdhRvqAuKZWXc4rtc18xQULYho= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1604926269456822.6115176100492; Mon, 9 Nov 2020 04:51:09 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.22467.48782 (Exim 4.92) (envelope-from ) id 1kc6d9-0003vi-3H; Mon, 09 Nov 2020 12:50:43 +0000 Received: by outflank-mailman (output) from mailman id 22467.48782; Mon, 09 Nov 2020 12:50:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6d8-0003vY-VG; Mon, 09 Nov 2020 12:50:42 +0000 Received: by outflank-mailman (input) for mailman id 22467; Mon, 09 Nov 2020 12:50:41 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6d7-0003tf-G8 for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:50:41 +0000 Received: from mail-lf1-x141.google.com (unknown [2a00:1450:4864:20::141]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 65cd7055-ea58-471e-ab4b-c97dca5b8bec; Mon, 09 Nov 2020 12:50:36 +0000 (UTC) Received: by mail-lf1-x141.google.com with SMTP id a25so3369148lfb.2 for ; Mon, 09 Nov 2020 04:50:35 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:34 -0800 (PST) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6d7-0003tf-G8 for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:50:41 +0000 Received: from mail-lf1-x141.google.com (unknown [2a00:1450:4864:20::141]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 65cd7055-ea58-471e-ab4b-c97dca5b8bec; Mon, 09 Nov 2020 12:50:36 +0000 (UTC) Received: by mail-lf1-x141.google.com with SMTP id a25so3369148lfb.2 for ; Mon, 09 Nov 2020 04:50:35 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:34 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 65cd7055-ea58-471e-ab4b-c97dca5b8bec 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; bh=1rzuTCzz2KF+DRZQjteexLeZTdzBj+314YEg3qH31eU=; b=S6tl/cpgNDnUIxTskwzefT2OcCf0wYW5IaEF+pGqwIKBOuIcCUH2BcvRYHPqlqI1aR 1gNG2n/XcW+n1z1aieFzT7m+uHrSmtUL13xhONepAHj5uGGxGOo5mSulraPtUUGNXdk4 PkaDGOrmV9iy8I8+zqBUlZ8uffd8lGDHyWmlB5LicP9KJIgbexggybZvxyCKvMe4NvKW h6ckFRAlbFgjOKxl68B2wYdQuyJm5BpX+zER0tvHBh1EaurrT9hMLlGYFxiKM1v2m2f+ XyTGI8XpTj5SSzvLIYWYAz6+MRpvmi1QXJ6wD/el3bR9kVwg7HK8WzMlYWRyBQGmsgHg sxjw== 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; bh=1rzuTCzz2KF+DRZQjteexLeZTdzBj+314YEg3qH31eU=; b=mYeJFBoBR5FDMmsimYRnYPmz70vxnEueiAZRQjD9rF8x3F72OmzqYTwS4sXnSNItOf Rw7wQPI6D8AXk+e5ReKoqYAUocvJxylww7l/1Jlbt9Yvr+h93sqwS5Zz/vwExiw2BEk7 Ei4E/MByNMuiy6qvWqcTcLPmZ2RcyxGfYloo8wrqZTwA8ng1I171NlMUmZtAdsQfpO3O Wv3RjC9co1Yc5g/KunQV3nEWht5fmoKU19rJK6brHloXFQh+8dAgKzAi3EaEBrcI0K0K FHghbKkXY8aOdlM+xYn7BieSQS1m+WTvVVGurUY/HV1qt11uWozVGGiWvrcsVG/q4vGk 75Ug== X-Gm-Message-State: AOAM5311aL+pNemyRvPcJnREPY0u2j9du3lTfzsQMiwLCMMVhpJTvUT/ xTTZC1nYmE16kwZhvAY9Lf4T/fSsxaSd7j7B X-Google-Smtp-Source: ABdhPJxDFoHXaz68fLZTaNjkSD8UMocF3QfpIF4hXTbn9tp8pmsusBJgEQvGxDLl+4M/wzGd4N7iMA== X-Received: by 2002:a19:90b:: with SMTP id 11mr6026088lfj.316.1604926234923; Mon, 09 Nov 2020 04:50:34 -0800 (PST) From: Oleksandr Andrushchenko To: Rahul.Singh@arm.com, Bertrand.Marquis@arm.com, julien.grall@arm.com, jbeulich@suse.com, roger.pau@citrix.com, sstabellini@kernel.org, xen-devel@lists.xenproject.org Cc: iwj@xenproject.org, wl@xen.org, Oleksandr Andrushchenko Subject: [PATCH 01/10] pci/pvh: Allow PCI toolstack code run with PVH domains on ARM Date: Mon, 9 Nov 2020 14:50:22 +0200 Message-Id: <20201109125031.26409-2-andr2000@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201109125031.26409-1-andr2000@gmail.com> References: <20201109125031.26409-1-andr2000@gmail.com> X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko According to https://wiki.xenproject.org/wiki/Linux_PVH: Items not supported by PVH - PCI pass through (as of Xen 4.10) Allow running PCI remove code on ARM and do not assert for PVH domains. Signed-off-by: Oleksandr Andrushchenko --- tools/libxl/Makefile | 4 ++++ tools/libxl/libxl_pci.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile index 241da7fff6f4..f3806aafcb4e 100644 --- a/tools/libxl/Makefile +++ b/tools/libxl/Makefile @@ -130,6 +130,10 @@ endif =20 LIBXL_LIBS +=3D -lyajl =20 +ifeq ($(CONFIG_ARM),y) +CFALGS +=3D -DCONFIG_ARM +endif + LIBXL_OBJS =3D flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o \ libxl_internal.o libxl_utils.o libxl_uuid.o \ diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index bc5843b13701..b93cf976642b 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -1915,8 +1915,10 @@ static void do_pci_remove(libxl__egc *egc, uint32_t = domid, goto out_fail; } } else { + /* PCI passthrough can also run on ARM PVH */ +#ifndef CONFIG_ARM assert(type =3D=3D LIBXL_DOMAIN_TYPE_PV); - +#endif char *sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/resource",= pcidev->domain, pcidev->bus, pcidev->dev, pcidev->fun= c); FILE *f =3D fopen(sysfs_path, "r"); --=20 2.17.1 From nobody Sat Nov 30 12:32:29 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=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1604926270; cv=none; d=zohomail.com; s=zohoarc; b=T3AeYAk7uI7MCfsbZniKMqtQ5j8/fUKfC3d5nRKZY0wWDr1dnkGkRRitM6w6LmRHG67VwFtavIeDz3/2JHOmhmwXtYx6fB1GaYVr1rqkBiQQwxsu9i0hDY+m/j8/ULhkGW9tVHdPoZjovaahI4LwJd1Zxx17+wxA6V1CEo9WFsA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604926270; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=0raAmTH7axJ0YbWj1RALaYgyVMCqkwur6fbc6S2x+mQ=; b=DBjT9cAEUwRudqZogZETClo4jF0uwdRcPtu8D+iXvGV6oSnYrnW3XRUP2W13Ezsg9X1nleE7hWC0e1ai0ZYuu6Wbzq72eahY6zYr2bekB/w6cJCqqfPcTO3FFUpSdDVKpfVT+g167BBu49vZd7iRyHGjvl0LTZsOCPFMzGhMRb8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1604926270975955.6684648203825; Mon, 9 Nov 2020 04:51:10 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.22468.48794 (Exim 4.92) (envelope-from ) id 1kc6dE-0003yZ-C7; Mon, 09 Nov 2020 12:50:48 +0000 Received: by outflank-mailman (output) from mailman id 22468.48794; Mon, 09 Nov 2020 12:50:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dE-0003yS-8F; Mon, 09 Nov 2020 12:50:48 +0000 Received: by outflank-mailman (input) for mailman id 22468; Mon, 09 Nov 2020 12:50: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 1kc6dC-0003tf-GG for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:50:46 +0000 Received: from mail-lj1-x22a.google.com (unknown [2a00:1450:4864:20::22a]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d3ff9ada-bce0-421f-b7dd-51132a6a6695; Mon, 09 Nov 2020 12:50:37 +0000 (UTC) Received: by mail-lj1-x22a.google.com with SMTP id h23so5662951ljg.13 for ; Mon, 09 Nov 2020 04:50:37 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:35 -0800 (PST) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dC-0003tf-GG for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:50:46 +0000 Received: from mail-lj1-x22a.google.com (unknown [2a00:1450:4864:20::22a]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d3ff9ada-bce0-421f-b7dd-51132a6a6695; Mon, 09 Nov 2020 12:50:37 +0000 (UTC) Received: by mail-lj1-x22a.google.com with SMTP id h23so5662951ljg.13 for ; Mon, 09 Nov 2020 04:50:37 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:35 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d3ff9ada-bce0-421f-b7dd-51132a6a6695 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; bh=0raAmTH7axJ0YbWj1RALaYgyVMCqkwur6fbc6S2x+mQ=; b=PMkxzd3meXfxMFb+8V9v7umIklIQVDgU3Yej5GLf8NU7kAmMU2+X+iujw4xkvoPWDZ Fm/28ucP6ws+K2JsF3+RpNyd7b6UwSmSOHJh85uxzWU994fDaFsECOoIbCHjR1prI4yU 64eHPDI4OgRvuOqOUEqXAzGgTRhri8UvuIRYqKmWb2PUtZrH4WabsDma9liElDpwz7as j4D8EPtr5S2d5pa4JGAhP3pVYZ8xGTwjkK0lbRPgJI/mqdvu9ywBmCcLBjSbegicuWlt r9myYOftERyVCLaQPMnDbSM29lZW/loDtF+lNO+cwK27Yf3Iql1Qak7N2Ca/XgdZzDZE LqUg== 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; bh=0raAmTH7axJ0YbWj1RALaYgyVMCqkwur6fbc6S2x+mQ=; b=mUuxg36vtPtT76VLpOey1FIxB3yqOt6KeFX7knzis4E7rBJJ7PvoFFVH7vwn/rU1E5 LIpOYonDKLj0cD6Uh8/mbRVv//gojnXjCIaACX+V457vvp++ScGth8UNXAe7d/D+3474 bgIudVKR5rXGU8hZXLaKR3ZQCFELjepYNgpC939+ZQ8IdBwSrdFNZfo220kQtdzs284s dFd3lrm07pHJsH97uYyE80kMTRajkm0mOoo66oBSa44TV5FFD8zhwycp0tdMcvqzsfQK BOJr54VoK7a15foXsswtIFpCoU9ExktFtPZRy8J6DZVOgR/M6UYemnHqinh+dbzTPfwO ZVQg== X-Gm-Message-State: AOAM531pz4c5Iv3Vg/bt6bipIwoxVS7Sdx9dsxeYfo5Rx51QtErdLhcC rimt9U27DvEtBZbKFJp9DkU= X-Google-Smtp-Source: ABdhPJzP9fZHRdiYOs6Ll6Bu1EWUvCyMJ+eVtThjJRLcocKF8qx9PQqAen8FQrTxH96C4NWdi/wfBA== X-Received: by 2002:a2e:9694:: with SMTP id q20mr139176lji.279.1604926236043; Mon, 09 Nov 2020 04:50:36 -0800 (PST) From: Oleksandr Andrushchenko To: Rahul.Singh@arm.com, Bertrand.Marquis@arm.com, julien.grall@arm.com, jbeulich@suse.com, roger.pau@citrix.com, sstabellini@kernel.org, xen-devel@lists.xenproject.org Cc: iwj@xenproject.org, wl@xen.org, Oleksandr Andrushchenko Subject: [PATCH 02/10] arm/pci: Maintain PCI assignable list Date: Mon, 9 Nov 2020 14:50:23 +0200 Message-Id: <20201109125031.26409-3-andr2000@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201109125031.26409-1-andr2000@gmail.com> References: <20201109125031.26409-1-andr2000@gmail.com> X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko The original code depends on pciback to manage assignable device list. The functionality which is implemented by the pciback and the toolstack and which is relevant/missing/needed for ARM: 1. pciback is used as a database for assignable PCI devices, e.g. xl pci-assignable-{add|remove|list} manipulates that list. So, whenever the toolstack needs to know which PCI devices can be passed through it reads that from the relevant sysfs entries of the pciback. 2. pciback is used to hold the unbound PCI devices, e.g. when passing throu= gh a PCI device it needs to be unbound from the relevant device driver and = bound to pciback (strictly speaking it is not required that the device is boun= d to pciback, but pciback is again used as a database of the passed through P= CI devices, so we can re-bind the devices back to their original drivers wh= en guest domain shuts down) 1. As ARM doesn't use pciback implement the above with additional sysctls: - XEN_SYSCTL_pci_device_set_assigned - XEN_SYSCTL_pci_device_get_assigned - XEN_SYSCTL_pci_device_enum_assigned 2. Extend struct pci_dev to hold assignment state. Signed-off-by: Oleksandr Andrushchenko --- tools/libxc/include/xenctrl.h | 9 +++ tools/libxc/xc_domain.c | 1 + tools/libxc/xc_misc.c | 46 +++++++++++++++ tools/libxl/Makefile | 4 ++ tools/libxl/libxl_pci.c | 105 ++++++++++++++++++++++++++++++++-- xen/arch/arm/sysctl.c | 66 ++++++++++++++++++++- xen/drivers/passthrough/pci.c | 93 ++++++++++++++++++++++++++++++ xen/include/public/sysctl.h | 40 +++++++++++++ xen/include/xen/pci.h | 12 ++++ 9 files changed, 370 insertions(+), 6 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 4c89b7294c4f..77029013da7d 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2652,6 +2652,15 @@ int xc_livepatch_replace(xc_interface *xch, char *na= me, uint32_t timeout, uint32 int xc_domain_cacheflush(xc_interface *xch, uint32_t domid, xen_pfn_t start_pfn, xen_pfn_t nr_pfns); =20 +typedef xen_sysctl_pci_device_enum_assigned_t xc_pci_device_enum_assigned_= t; + +int xc_pci_device_set_assigned(xc_interface *xch, uint32_t machine_sbdf, + bool assigned); +int xc_pci_device_get_assigned(xc_interface *xch, uint32_t machine_sbdf); + +int xc_pci_device_enum_assigned(xc_interface *xch, + xc_pci_device_enum_assigned_t *e); + /* Compat shims */ #include "xenctrl_compat.h" =20 diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 71829c2bce3e..d515191e9243 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -2321,6 +2321,7 @@ int xc_domain_soft_reset(xc_interface *xch, domctl.domain =3D domid; return do_domctl(xch, &domctl); } + /* * Local variables: * mode: C diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c index 3820394413a9..d439c4ba1019 100644 --- a/tools/libxc/xc_misc.c +++ b/tools/libxc/xc_misc.c @@ -988,6 +988,52 @@ int xc_livepatch_replace(xc_interface *xch, char *name= , uint32_t timeout, uint32 return _xc_livepatch_action(xch, name, LIVEPATCH_ACTION_REPLACE, timeo= ut, flags); } =20 +int xc_pci_device_set_assigned( + xc_interface *xch, + uint32_t machine_sbdf, + bool assigned) +{ + DECLARE_SYSCTL; + + sysctl.cmd =3D XEN_SYSCTL_pci_device_set_assigned; + sysctl.u.pci_set_assigned.machine_sbdf =3D machine_sbdf; + sysctl.u.pci_set_assigned.assigned =3D assigned; + + return do_sysctl(xch, &sysctl); +} + +int xc_pci_device_get_assigned( + xc_interface *xch, + uint32_t machine_sbdf) +{ + DECLARE_SYSCTL; + + sysctl.cmd =3D XEN_SYSCTL_pci_device_get_assigned; + sysctl.u.pci_get_assigned.machine_sbdf =3D machine_sbdf; + + return do_sysctl(xch, &sysctl); +} + +int xc_pci_device_enum_assigned(xc_interface *xch, + xc_pci_device_enum_assigned_t *e) +{ + int ret; + DECLARE_SYSCTL; + + sysctl.cmd =3D XEN_SYSCTL_pci_device_enum_assigned; + sysctl.u.pci_enum_assigned.idx =3D e->idx; + sysctl.u.pci_enum_assigned.report_not_assigned =3D e->report_not_assig= ned; + ret =3D do_sysctl(xch, &sysctl); + if ( ret ) + errno =3D EINVAL; + else + { + e->domain =3D sysctl.u.pci_enum_assigned.domain; + e->machine_sbdf =3D sysctl.u.pci_enum_assigned.machine_sbdf; + } + return ret; +} + /* * Local variables: * mode: C diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile index f3806aafcb4e..6f76ba35aec7 100644 --- a/tools/libxl/Makefile +++ b/tools/libxl/Makefile @@ -130,6 +130,10 @@ endif =20 LIBXL_LIBS +=3D -lyajl =20 +ifeq ($(CONFIG_X86),y) +CFALGS +=3D -DCONFIG_PCIBACK +endif + ifeq ($(CONFIG_ARM),y) CFALGS +=3D -DCONFIG_ARM endif diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index b93cf976642b..41f89b8aae10 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -319,6 +319,7 @@ retry_transaction2: =20 static int get_all_assigned_devices(libxl__gc *gc, libxl_device_pci **list= , int *num) { +#ifdef CONFIG_PCIBACK char **domlist; unsigned int nd =3D 0, i; =20 @@ -356,6 +357,33 @@ static int get_all_assigned_devices(libxl__gc *gc, lib= xl_device_pci **list, int } } } +#else + libxl_ctx *ctx =3D libxl__gc_owner(gc); + int ret; + xc_pci_device_enum_assigned_t e; + + *list =3D NULL; + *num =3D 0; + + memset(&e, 0, sizeof(e)); + do { + ret =3D xc_pci_device_enum_assigned(ctx->xch, &e); + if ( ret && errno =3D=3D EINVAL ) + break; + *list =3D realloc(*list, sizeof(libxl_device_pci) * (e.idx + 1)); + if (*list =3D=3D NULL) + return ERROR_NOMEM; + + pcidev_struct_fill(*list + e.idx, + e.domain, + e.machine_sbdf >> 8 & 0xff, + PCI_SLOT(e.machine_sbdf), + PCI_FUNC(e.machine_sbdf), + 0 /*vdevfn*/); + e.idx++; + } while (!ret); + *num =3D e.idx; +#endif libxl__ptr_add(gc, *list); =20 return 0; @@ -411,13 +439,20 @@ static int sysfs_write_bdf(libxl__gc *gc, const char = * sysfs_path, libxl_device_pci *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *nu= m) { GC_INIT(ctx); - libxl_device_pci *pcidevs =3D NULL, *new, *assigned; + libxl_device_pci *pcidevs =3D NULL, *new; + int r; +#ifdef CONFIG_PCIBACK + libxl_device_pci *assigned; + int num_assigned; struct dirent *de; DIR *dir; - int r, num_assigned; +#else + xc_pci_device_enum_assigned_t e; +#endif =20 *num =3D 0; =20 +#ifdef CONFIG_PCIBACK r =3D get_all_assigned_devices(gc, &assigned, &num_assigned); if (r) goto out; =20 @@ -453,6 +488,32 @@ libxl_device_pci *libxl_device_pci_assignable_list(lib= xl_ctx *ctx, int *num) =20 closedir(dir); out: +#else + memset(&e, 0, sizeof(e)); + e.report_not_assigned =3D 1; + do { + r =3D xc_pci_device_enum_assigned(ctx->xch, &e); + if ( r && errno =3D=3D EINVAL ) + break; + new =3D realloc(pcidevs, (e.idx + 1) * sizeof(*new)); + if (NULL =3D=3D new) + continue; + + pcidevs =3D new; + new =3D pcidevs + e.idx; + + memset(new, 0, sizeof(*new)); + + pcidev_struct_fill(new, + e.domain, + e.machine_sbdf >> 8 & 0xff, + PCI_SLOT(e.machine_sbdf), + PCI_FUNC(e.machine_sbdf), + 0 /*vdevfn*/); + e.idx++; + } while (!r); + *num =3D e.idx; +#endif GC_FREE; return pcidevs; } @@ -606,6 +667,7 @@ bool libxl__is_igd_vga_passthru(libxl__gc *gc, return false; } =20 +#ifdef CONFIG_PCIBACK /* * A brief comment about slots. I don't know what slots are for; however, * I have by experimentation determined: @@ -648,11 +710,13 @@ out: fclose(f); return rc; } +#endif =20 static int pciback_dev_is_assigned(libxl__gc *gc, libxl_device_pci *pcidev) { - char * spath; int rc; +#ifdef CONFIG_PCIBACK + char * spath; struct stat st; =20 if ( access(SYSFS_PCIBACK_DRIVER, F_OK) < 0 ) { @@ -663,22 +727,27 @@ static int pciback_dev_is_assigned(libxl__gc *gc, lib= xl_device_pci *pcidev) } return -1; } - spath =3D GCSPRINTF(SYSFS_PCIBACK_DRIVER"/"PCI_BDF, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); rc =3D lstat(spath, &st); - if( rc =3D=3D 0 ) return 1; if ( rc < 0 && errno =3D=3D ENOENT ) return 0; LOGE(ERROR, "Accessing %s", spath); return -1; +#else + libxl_ctx *ctx =3D libxl__gc_owner(gc); + + rc =3D xc_pci_device_get_assigned(ctx->xch, pcidev_encode_bdf(pcidev)); + return rc =3D=3D 0 ? 1 : 0; +#endif } =20 static int pciback_dev_assign(libxl__gc *gc, libxl_device_pci *pcidev) { +#ifdef CONFIG_PCIBACK int rc; =20 if ( (rc=3Dpciback_dev_has_slot(gc, pcidev)) < 0 ) { @@ -697,10 +766,17 @@ static int pciback_dev_assign(libxl__gc *gc, libxl_de= vice_pci *pcidev) return ERROR_FAIL; } return 0; +#else + libxl_ctx *ctx =3D libxl__gc_owner(gc); + + return xc_pci_device_set_assigned(ctx->xch, pcidev_encode_bdf(pcidev), + true); +#endif } =20 static int pciback_dev_unassign(libxl__gc *gc, libxl_device_pci *pcidev) { +#ifdef CONFIG_PCIBACK /* Remove from pciback */ if ( sysfs_dev_unbind(gc, pcidev, NULL) < 0 ) { LOG(ERROR, "Couldn't unbind device!"); @@ -716,6 +792,12 @@ static int pciback_dev_unassign(libxl__gc *gc, libxl_d= evice_pci *pcidev) } } return 0; +#else + libxl_ctx *ctx =3D libxl__gc_owner(gc); + + return xc_pci_device_set_assigned(ctx->xch, pcidev_encode_bdf(pcidev), + false); +#endif } =20 #define PCIBACK_INFO_PATH "/libxl/pciback" @@ -780,10 +862,15 @@ static int libxl__device_pci_assignable_add(libxl__gc= *gc, =20 /* See if the device exists */ spath =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF, dom, bus, dev, func); +#ifdef CONFIG_PCI_SYSFS_DOM0 if ( lstat(spath, &st) ) { LOGE(ERROR, "Couldn't lstat %s", spath); return ERROR_FAIL; } +#else + (void)st; + printf("IMPLEMENT_ME: %s lstat %s\n", __func__, spath); +#endif =20 /* Check to see if it's already assigned to pciback */ rc =3D pciback_dev_is_assigned(gc, pcidev); @@ -1350,8 +1437,12 @@ static void pci_add_dm_done(libxl__egc *egc, =20 if (f =3D=3D NULL) { LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path); +#ifdef CONFIG_PCI_SYSFS_DOM0 rc =3D ERROR_FAIL; goto out; +#else + goto out_no_irq; +#endif } for (i =3D 0; i < PROC_PCI_NUM_RESOURCES; i++) { if (fscanf(f, "0x%llx 0x%llx 0x%llx\n", &start, &end, &flags) !=3D= 3) @@ -1522,7 +1613,11 @@ static int libxl_pcidev_assignable(libxl_ctx *ctx, l= ibxl_device_pci *pcidev) break; } free(pcidevs); +#ifdef CONFIG_PCIBACK return i !=3D num; +#else + return 1; +#endif } =20 static void device_pci_add_stubdom_wait(libxl__egc *egc, diff --git a/xen/arch/arm/sysctl.c b/xen/arch/arm/sysctl.c index f87944e8473c..84e933b2eb45 100644 --- a/xen/arch/arm/sysctl.c +++ b/xen/arch/arm/sysctl.c @@ -10,6 +10,7 @@ #include #include #include +#include #include =20 void arch_do_physinfo(struct xen_sysctl_physinfo *pi) @@ -20,7 +21,70 @@ void arch_do_physinfo(struct xen_sysctl_physinfo *pi) long arch_do_sysctl(struct xen_sysctl *sysctl, XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) { - return -ENOSYS; + long ret =3D 0; + bool copyback =3D 0; + + switch ( sysctl->cmd ) + { + case XEN_SYSCTL_pci_device_set_assigned: + { + u16 seg; + u8 bus, devfn; + uint32_t machine_sbdf; + + machine_sbdf =3D sysctl->u.pci_set_assigned.machine_sbdf; + +#if 0 + ret =3D xsm_pci_device_set_assigned(XSM_HOOK, d); + if ( ret ) + break; +#endif + + seg =3D machine_sbdf >> 16; + bus =3D PCI_BUS(machine_sbdf); + devfn =3D PCI_DEVFN2(machine_sbdf); + + pcidevs_lock(); + ret =3D pci_device_set_assigned(seg, bus, devfn, + !!sysctl->u.pci_set_assigned.assigne= d); + pcidevs_unlock(); + break; + } + case XEN_SYSCTL_pci_device_get_assigned: + { + u16 seg; + u8 bus, devfn; + uint32_t machine_sbdf; + + machine_sbdf =3D sysctl->u.pci_set_assigned.machine_sbdf; + + seg =3D machine_sbdf >> 16; + bus =3D PCI_BUS(machine_sbdf); + devfn =3D PCI_DEVFN2(machine_sbdf); + + pcidevs_lock(); + ret =3D pci_device_get_assigned(seg, bus, devfn); + pcidevs_unlock(); + break; + } + case XEN_SYSCTL_pci_device_enum_assigned: + { + ret =3D pci_device_enum_assigned(sysctl->u.pci_enum_assigned.repor= t_not_assigned, + sysctl->u.pci_enum_assigned.idx, + &sysctl->u.pci_enum_assigned.domain, + &sysctl->u.pci_enum_assigned.machin= e_sbdf); + copyback =3D 1; + break; + } + default: + ret =3D -ENOSYS; + break; + } + if ( copyback && (!ret || copyback > 0) && + __copy_to_guest(u_sysctl, sysctl, 1) ) + ret =3D -EFAULT; + + return ret; } =20 /* diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 98e8a2fade60..49b4279c63bd 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -879,6 +879,43 @@ int pci_remove_device(u16 seg, u8 bus, u8 devfn) return ret; } =20 +#ifdef CONFIG_ARM +int pci_device_set_assigned(u16 seg, u8 bus, u8 devfn, bool assigned) +{ + struct pci_dev *pdev; + + pdev =3D pci_get_pdev(seg, bus, devfn); + if ( !pdev ) + { + printk(XENLOG_ERR "Can't find PCI device %04x:%02x:%02x.%u\n", + seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); + return -ENODEV; + } + + pdev->assigned =3D assigned; + printk(XENLOG_ERR "pciback %sassign PCI device %04x:%02x:%02x.%u\n", + assigned ? "" : "de-", + seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); + + return 0; +} + +int pci_device_get_assigned(u16 seg, u8 bus, u8 devfn) +{ + struct pci_dev *pdev; + + pdev =3D pci_get_pdev(seg, bus, devfn); + if ( !pdev ) + { + printk(XENLOG_ERR "Can't find PCI device %04x:%02x:%02x.%u\n", + seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); + return -ENODEV; + } + + return pdev->assigned ? 0 : -ENODEV; +} +#endif + #ifndef CONFIG_ARM /*TODO :Implement MSI support for ARM */ static int pci_clean_dpci_irq(struct domain *d, @@ -1821,6 +1858,62 @@ int iommu_do_pci_domctl( return ret; } =20 +#ifdef CONFIG_ARM +struct list_assigned { + uint32_t cur_idx; + uint32_t from_idx; + bool assigned; + domid_t *domain; + uint32_t *machine_sbdf; +}; + +static int _enum_assigned_pci_devices(struct pci_seg *pseg, void *arg) +{ + struct list_assigned *ctxt =3D arg; + struct pci_dev *pdev; + + list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) + { + if ( pdev->assigned =3D=3D ctxt->assigned ) + { + if ( ctxt->cur_idx =3D=3D ctxt->from_idx ) + { + *ctxt->domain =3D pdev->domain->domain_id; + *ctxt->machine_sbdf =3D pdev->sbdf.sbdf; + return 1; + } + ctxt->cur_idx++; + } + } + return 0; +} + +int pci_device_enum_assigned(bool report_not_assigned, + uint32_t from_idx, domid_t *domain, + uint32_t *machine_sbdf) +{ + struct list_assigned ctxt =3D { + .assigned =3D !report_not_assigned, + .cur_idx =3D 0, + .from_idx =3D from_idx, + .domain =3D domain, + .machine_sbdf =3D machine_sbdf, + }; + int ret; + + pcidevs_lock(); + ret =3D pci_segments_iterate(_enum_assigned_pci_devices, &ctxt); + pcidevs_unlock(); + /* + * If not found then report as EINVAL to mark + * enumeration process finished. + */ + if ( !ret ) + return -EINVAL; + return 0; +} +#endif + /* * Local variables: * mode: C diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index a07364711794..5ca73c538688 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1062,6 +1062,40 @@ typedef struct xen_sysctl_cpu_policy xen_sysctl_cpu_= policy_t; DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpu_policy_t); #endif =20 +/* + * These are to emulate pciback device (de-)assignment used by the tools + * to track current device assignments: all the PCI devices that can + * be passed through must be assigned to the pciback to mark them + * as such. As on ARM we do not run pci{back|front} and are emulating + * PCI host bridge in Xen, so we need to maintain the assignments on our + * own in Xen itself. + * + * Note on xen_sysctl_pci_device_get_assigned: ENOENT is used to report + * that there are no assigned devices left. + */ +struct xen_sysctl_pci_device_set_assigned { + /* IN */ + /* FIXME: is this really a machine SBDF or as Domain-0 sees it? */ + uint32_t machine_sbdf; + uint8_t assigned; +}; + +struct xen_sysctl_pci_device_get_assigned { + /* IN */ + uint32_t machine_sbdf; +}; + +struct xen_sysctl_pci_device_enum_assigned { + /* IN */ + uint32_t idx; + uint8_t report_not_assigned; + /* OUT */ + domid_t domain; + uint32_t machine_sbdf; +}; +typedef struct xen_sysctl_pci_device_enum_assigned xen_sysctl_pci_device_e= num_assigned_t; +DEFINE_XEN_GUEST_HANDLE(xen_sysctl_pci_device_enum_assigned_t); + struct xen_sysctl { uint32_t cmd; #define XEN_SYSCTL_readconsole 1 @@ -1092,6 +1126,9 @@ struct xen_sysctl { #define XEN_SYSCTL_livepatch_op 27 /* #define XEN_SYSCTL_set_parameter 28 */ #define XEN_SYSCTL_get_cpu_policy 29 +#define XEN_SYSCTL_pci_device_set_assigned 30 +#define XEN_SYSCTL_pci_device_get_assigned 31 +#define XEN_SYSCTL_pci_device_enum_assigned 32 uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */ union { struct xen_sysctl_readconsole readconsole; @@ -1122,6 +1159,9 @@ struct xen_sysctl { #if defined(__i386__) || defined(__x86_64__) struct xen_sysctl_cpu_policy cpu_policy; #endif + struct xen_sysctl_pci_device_set_assigned pci_set_assigned; + struct xen_sysctl_pci_device_get_assigned pci_get_assigned; + struct xen_sysctl_pci_device_enum_assigned pci_enum_assigned; uint8_t pad[128]; } u; }; diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index 2bc4aaf4530c..7bf439de4de0 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -132,6 +132,13 @@ struct pci_dev { =20 /* Data for vPCI. */ struct vpci *vpci; +#ifdef CONFIG_ARM + /* + * Set if this PCI device is eligible for pass through, + * e.g. just like it was assigned to pciback driver. + */ + bool assigned; +#endif }; =20 #define for_each_pdev(domain, pdev) \ @@ -168,6 +175,11 @@ const unsigned long *pci_get_ro_map(u16 seg); int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *, nodeid_t node); int pci_remove_device(u16 seg, u8 bus, u8 devfn); +int pci_device_set_assigned(u16 seg, u8 bus, u8 devfn, bool assigned); +int pci_device_get_assigned(u16 seg, u8 bus, u8 devfn); +int pci_device_enum_assigned(bool report_not_assigned, + uint32_t from_idx, domid_t *domain, + uint32_t *machine_sbdf); int pci_ro_device(int seg, int bus, int devfn); int pci_hide_device(unsigned int seg, unsigned int bus, unsigned int devfn= ); struct pci_dev *pci_get_pdev(int seg, int bus, int devfn); --=20 2.17.1 From nobody Sat Nov 30 12:32:29 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=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1604926268; cv=none; d=zohomail.com; s=zohoarc; b=TZs62grrWZCUEr2uPI51dFKOSqUhRWKC6jXhOS98SJb5RVxA6UkBJS5M3y/uSdr9JwJMpVA59cdw08kWpoK2zGEZgkfRqj3sxv/SJDoUltbElgoYwfUlbQ72EN9LeUIWloQsuY0B7aWMbgzhkhP3kDyLt4FNja+LTywQIk/3ISQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604926268; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=7Mun79oNB4+e5ttsNU806SzMPrzXSy2ZLLighcxfMfY=; b=IktPeNQaRbySPuK2XNrWRJm1Er9AzeSiXyuoxJh1SOG31juMfsOw1a7L/PQI8KV8bV+J7QRLO/C4z4ufGxO4NHW9rDyWM4X4bVcq+7D7RlYfP6GEfd5mkUyeNCvDfP1GaAMJEFPtRaJMMe5eGE4/UEkrdzXdBe/wjOmmDX09/iA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1604926268770692.9185639376152; Mon, 9 Nov 2020 04:51:08 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.22469.48806 (Exim 4.92) (envelope-from ) id 1kc6dI-00042q-SL; Mon, 09 Nov 2020 12:50:52 +0000 Received: by outflank-mailman (output) from mailman id 22469.48806; Mon, 09 Nov 2020 12:50:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dI-00042f-NV; Mon, 09 Nov 2020 12:50:52 +0000 Received: by outflank-mailman (input) for mailman id 22469; Mon, 09 Nov 2020 12:50:51 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dH-0003tf-GO for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:50:51 +0000 Received: from mail-lj1-x244.google.com (unknown [2a00:1450:4864:20::244]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a51ad763-8346-45f2-a425-f8c9c9eb7af3; Mon, 09 Nov 2020 12:50:38 +0000 (UTC) Received: by mail-lj1-x244.google.com with SMTP id y25so9221562lja.9 for ; Mon, 09 Nov 2020 04:50:38 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:36 -0800 (PST) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dH-0003tf-GO for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:50:51 +0000 Received: from mail-lj1-x244.google.com (unknown [2a00:1450:4864:20::244]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a51ad763-8346-45f2-a425-f8c9c9eb7af3; Mon, 09 Nov 2020 12:50:38 +0000 (UTC) Received: by mail-lj1-x244.google.com with SMTP id y25so9221562lja.9 for ; Mon, 09 Nov 2020 04:50:38 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:36 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a51ad763-8346-45f2-a425-f8c9c9eb7af3 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; bh=7Mun79oNB4+e5ttsNU806SzMPrzXSy2ZLLighcxfMfY=; b=WWIUxIatMUUQ/JCfsQDdZYnmWvE8T2h2OJYWDZzrFG0esbosTsAYeB4Q+V8boBfWVh +qDaIT+FtaVwJz540oMHyEzAJazvA3r80XjsSxFlmi+VVHqSc6uwgYLsT4v88nlj6K+0 dSs66fjRUduKWocG6OrWGyX28LuDGQcuX0uzIzb/Iq0lYHZzvuHBAK4fneo9aafA5e5q elPLqZjK0gViriEOHK6HHLTzIvf5JWKlsFUM5+IJGACKSA3WGiyu7/gTmz963wusTJ+p SU1D6b7iwR9IN4g6c4eLX6Cy2g6XsdcnqmzAH8rlK2CqqCYedBWywIMrVpBBP+gJ7Z6x lSGA== 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; bh=7Mun79oNB4+e5ttsNU806SzMPrzXSy2ZLLighcxfMfY=; b=D72ikbGeU1SsPiJgZF6MpbY+RmhTdxoeLVTJRRhzr/yAWpTWf3x7c1CtQH7+QKAHd4 0+/WMp0QD+4xeMz6/eGxD9TXoznpiTVxk6cFnexU4saJjlkqHotS2lvEpzScdKf8wB1H tgjdSW2W3wjG2oGhpmmnoo5N73mhNmR6SMQgqTkT9BgHRUmF/UkzJgVAfWguoszGsbWA 2ZwasWvEcB2ezIsNuzxaVe285cgCHxCT43XuO2BcgT9TJUK63CbCly2vxNoL9Wt80Sjh WF37nTSXT1QeaaWeCh0BeHzXoQSE/DNvNFtE2P5KAkscxHXIHX+s9+Nl9mwYqoGNoY+J QV4Q== X-Gm-Message-State: AOAM531gVoEMnUBIX4QeZ3uFrKtwRFX8ygQ6Hpcb13smXxfs849wX5L6 40VKD3/Py85Wra9V59u44MY= X-Google-Smtp-Source: ABdhPJyQgmzrX5saLyJOhkpBy66jZinX+gIfrfFvi2zgYffNfrppcrxhlT7B3mFNp8jlF7tFrs9X4Q== X-Received: by 2002:a05:651c:2db:: with SMTP id f27mr5734043ljo.394.1604926237424; Mon, 09 Nov 2020 04:50:37 -0800 (PST) From: Oleksandr Andrushchenko To: Rahul.Singh@arm.com, Bertrand.Marquis@arm.com, julien.grall@arm.com, jbeulich@suse.com, roger.pau@citrix.com, sstabellini@kernel.org, xen-devel@lists.xenproject.org Cc: iwj@xenproject.org, wl@xen.org, Oleksandr Andrushchenko Subject: [PATCH 03/10] xen/arm: Setup MMIO range trap handlers for hardware domain Date: Mon, 9 Nov 2020 14:50:24 +0200 Message-Id: <20201109125031.26409-4-andr2000@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201109125031.26409-1-andr2000@gmail.com> References: <20201109125031.26409-1-andr2000@gmail.com> X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko In order vPCI to work it needs all access to PCI configuration space access to be synchronized among all entities, e.g. hardware domain and guests. For that implement PCI host bridge specific callbacks to propelry setup those ranges depending on host bridge implementation. This callback is optional and may not be used by non-ECAM host bridges. Signed-off-by: Oleksandr Andrushchenko --- xen/arch/arm/pci/pci-host-common.c | 16 ++++++++++++++++ xen/arch/arm/pci/pci-host-generic.c | 15 +++++++++++++-- xen/arch/arm/vpci.c | 16 +++++++++++++++- xen/include/asm-arm/pci.h | 7 +++++++ 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host= -common.c index b011c7eff3c8..b81184d34980 100644 --- a/xen/arch/arm/pci/pci-host-common.c +++ b/xen/arch/arm/pci/pci-host-common.c @@ -219,6 +219,22 @@ struct device *pci_find_host_bridge_device(struct devi= ce *dev) } return dt_to_dev(bridge->dt_node); } + +int pci_host_iterate_bridges(struct domain *d, + int (*clb)(struct domain *d, + struct pci_host_bridge *bridge)) +{ + struct pci_host_bridge *bridge; + int err; + + list_for_each_entry( bridge, &pci_host_bridges, node ) + { + err =3D clb(d, bridge); + if ( err ) + return err; + } + return 0; +} /* * Local variables: * mode: C diff --git a/xen/arch/arm/pci/pci-host-generic.c b/xen/arch/arm/pci/pci-hos= t-generic.c index 54dd123e95c7..469df3da0116 100644 --- a/xen/arch/arm/pci/pci-host-generic.c +++ b/xen/arch/arm/pci/pci-host-generic.c @@ -85,12 +85,23 @@ int pci_ecam_config_read(struct pci_host_bridge *bridge= , uint32_t sbdf, return 0; } =20 +static int pci_ecam_register_mmio_handler(struct domain *d, + struct pci_host_bridge *bridge, + const struct mmio_handler_ops *o= ps) +{ + struct pci_config_window *cfg =3D bridge->sysdata; + + register_mmio_handler(d, ops, cfg->phys_addr, cfg->size, NULL); + return 0; +} + /* ECAM ops */ struct pci_ecam_ops pci_generic_ecam_ops =3D { .bus_shift =3D 20, .pci_ops =3D { - .read =3D pci_ecam_config_read, - .write =3D pci_ecam_config_write, + .read =3D pci_ecam_config_read, + .write =3D pci_ecam_config_write, + .register_mmio_handler =3D pci_ecam_register_mmio_handler, } }; =20 diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 49e473ab0d10..2b9bf34c8fe6 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -80,11 +80,25 @@ static const struct mmio_handler_ops vpci_mmio_handler = =3D { .write =3D vpci_mmio_write, }; =20 +static int vpci_setup_mmio_handler(struct domain *d, + struct pci_host_bridge *bridge) +{ + if ( bridge->ops->register_mmio_handler ) + return bridge->ops->register_mmio_handler(d, bridge, + &vpci_mmio_handler); + return 0; +} + + int domain_vpci_init(struct domain *d) { - if ( !has_vpci(d) || is_hardware_domain(d) ) + if ( !has_vpci(d) ) return 0; =20 + if ( is_hardware_domain(d) ) + return pci_host_iterate_bridges(d, vpci_setup_mmio_handler); + + /* Guest domains use what is programmed in their device tree. */ register_mmio_handler(d, &vpci_mmio_handler, GUEST_VPCI_ECAM_BASE,GUEST_VPCI_ECAM_SIZE,NULL); =20 diff --git a/xen/include/asm-arm/pci.h b/xen/include/asm-arm/pci.h index ba23178f67ab..e3a02429b8d4 100644 --- a/xen/include/asm-arm/pci.h +++ b/xen/include/asm-arm/pci.h @@ -27,6 +27,7 @@ #include #include #include +#include =20 #ifdef CONFIG_ARM_PCI =20 @@ -64,6 +65,9 @@ struct pci_ops { uint32_t sbdf, int where, int size, u32 *val); int (*write)(struct pci_host_bridge *bridge, uint32_t sbdf, int where, int size, u32 val); + int (*register_mmio_handler)(struct domain *d, + struct pci_host_bridge *bridge, + const struct mmio_handler_ops *ops); }; =20 /* @@ -101,6 +105,9 @@ void pci_init(void); bool dt_pci_parse_bus_range(struct dt_device_node *dev, struct pci_config_window *cfg); =20 +int pci_host_iterate_bridges(struct domain *d, + int (*clb)(struct domain *d, + struct pci_host_bridge *bridge)); #else /*!CONFIG_ARM_PCI*/ struct arch_pci_dev { }; static inline void pci_init(void) { } --=20 2.17.1 From nobody Sat Nov 30 12:32:29 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=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1604926272; cv=none; d=zohomail.com; s=zohoarc; b=XI+gap+/pxTgJo0XnteFQjj6zhh6S5dGRerc0FYLudVq0kpSHZfd7bxXQYXtKLjOHg7e94U+/5c14ulxKn9SGiGglv18LP50df6MKW0DgBwgHlbds/PNrBZ2SMosdq10ZAdFQQY1DY4vCcHx5HCJxfMV5LTTm/csM2q1w1JPipI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604926272; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=PUERNr5enj9JC+Z7u0WMW7Vxpi+i1ufmU0togeFlHo0=; b=jeztw/qH2G3hkOydOpgP2MIZ8Sm6j/eFooBQu241/64ni+fenPAdY9k0KynBr/ZOiRSr70eA3jAOz8AtfbuSyg9kNLAu2wDSBqo8Q7ccjDr0N1M+qyyT/cM4zHyie9cpy2wUozInja/zfOBo84U4zEK6RCYLZom3Do9XGLkrSG0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1604926272720847.475394134654; Mon, 9 Nov 2020 04:51:12 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.22471.48818 (Exim 4.92) (envelope-from ) id 1kc6dO-00048k-64; Mon, 09 Nov 2020 12:50:58 +0000 Received: by outflank-mailman (output) from mailman id 22471.48818; Mon, 09 Nov 2020 12:50:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dO-00048c-2K; Mon, 09 Nov 2020 12:50:58 +0000 Received: by outflank-mailman (input) for mailman id 22471; Mon, 09 Nov 2020 12:50:56 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dM-0003tf-GV for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:50:56 +0000 Received: from mail-lj1-x243.google.com (unknown [2a00:1450:4864:20::243]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b7f8e413-9a77-403b-9adb-a160bd28eaa2; Mon, 09 Nov 2020 12:50:39 +0000 (UTC) Received: by mail-lj1-x243.google.com with SMTP id 11so10138049ljf.2 for ; Mon, 09 Nov 2020 04:50:39 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:38 -0800 (PST) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dM-0003tf-GV for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:50:56 +0000 Received: from mail-lj1-x243.google.com (unknown [2a00:1450:4864:20::243]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b7f8e413-9a77-403b-9adb-a160bd28eaa2; Mon, 09 Nov 2020 12:50:39 +0000 (UTC) Received: by mail-lj1-x243.google.com with SMTP id 11so10138049ljf.2 for ; Mon, 09 Nov 2020 04:50:39 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:38 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b7f8e413-9a77-403b-9adb-a160bd28eaa2 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; bh=PUERNr5enj9JC+Z7u0WMW7Vxpi+i1ufmU0togeFlHo0=; b=ANLRTH/4Hv3bHw8eON/a0Fq8FEpojEHcja+6e0UW2+ObVjfMN1VQpp/h6Il4p0fjre 1/DnkOA4VpgHyY90+eIFSrwo0FToUsb8RclBLNOxRU1t5EZsRnqGb3ZNPFKmRXT4xnmY XoR7+URrhpmjZWptwHnuFuvTYPGFWCc32LM9n6ItABHncX57D3W6Os7pkcLkd1/UOdqm NrcHEtBmqjUZR8VcB6AICzcaDiboqs2KmyFB9TAz1K3Snjgg/L8rnByfJAEluRxD/CQq 7fp06FQgKXqFmonTlk5vqol2WQXkGD5OeUiquzzmSDmvyjmxVJ0dUWHH/r6tHVcQ4E0D A4Ew== 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; bh=PUERNr5enj9JC+Z7u0WMW7Vxpi+i1ufmU0togeFlHo0=; b=lcE5aq74yjtSQNmXmmi6luO63zEU1VdptoHTDx6FGfgO/5gSy5nG88F5m8GjPzEIMR ZqFGUf6atCww+K3xmcDVqpYk79wXcASk7IwtxUUsBRRdjBi0LMOdYKN5Sqv+7ZyvPYvk F8nAJz0soiRole8wDxi7rM1IUJkSM3NSkt1nsVBArzxWdNzi4GAF25PBy38dIursBu15 Ex507irkynDwJvpvjDqfnBKLfwx4jh8XimXLWcDyg7pn4XFWul0B8gRUEI7cM7l6Iyq1 1RSxLenOmAaVC89OaqMBuRYDOFVssGH3/R/6gHTuHy7zg8cHQ262CWrb/PFa//mOz14a C5jQ== X-Gm-Message-State: AOAM533nWVPO99/pzlpDt3yMVrvkcUxJ4iVUreR7w5ib2b97xN/eIsXB RHdNJpQuC9IEuxrpxpGUbkw= X-Google-Smtp-Source: ABdhPJxpHQoFZaGQdiyFojJGSAIuDJP5u+AqQp44p0HbAoz1/DbVFC+0Clu3bBtYGLbmbtezoClYRA== X-Received: by 2002:a05:651c:544:: with SMTP id q4mr6213912ljp.468.1604926238541; Mon, 09 Nov 2020 04:50:38 -0800 (PST) From: Oleksandr Andrushchenko To: Rahul.Singh@arm.com, Bertrand.Marquis@arm.com, julien.grall@arm.com, jbeulich@suse.com, roger.pau@citrix.com, sstabellini@kernel.org, xen-devel@lists.xenproject.org Cc: iwj@xenproject.org, wl@xen.org, Oleksandr Andrushchenko Subject: [PATCH 04/10] [WORKAROUND] xen/arm: Update hwdom's p2m to trap ECAM space Date: Mon, 9 Nov 2020 14:50:25 +0200 Message-Id: <20201109125031.26409-5-andr2000@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201109125031.26409-1-andr2000@gmail.com> References: <20201109125031.26409-1-andr2000@gmail.com> X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko Host bridge controller's ECAM space is mapped into Domain-0's p2m, thus it is not possible to trap the same for vPCI via MMIO handlers. For this to work we need to unmap those mappings in p2m. TODO (Julien): It would be best if we avoid the map/unmap operation. So, maybe we want to introduce another way to avoid the mapping. Maybe by changing the type of the controller to "PCI_HOSTCONTROLLER" and checking if this is a PCI hostcontroller avoid the mapping. Signed-off-by: Oleksandr Andrushchenko --- xen/arch/arm/domain_build.c | 10 +++++++++- xen/arch/arm/pci/pci-host-common.c | 15 +++++++++++++++ xen/arch/arm/pci/pci-host-generic.c | 28 ++++++++++++++++++++++++++++ xen/include/asm-arm/pci.h | 2 ++ 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 1f83f9048146..3f696d2a6672 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2566,7 +2566,15 @@ int __init construct_dom0(struct domain *d) if ( rc < 0 ) return rc; =20 - return construct_domain(d, &kinfo); + rc =3D construct_domain(d, &kinfo); + if ( rc < 0 ) + return rc; + +#ifdef CONFIG_HAS_PCI + if ( has_vpci(d) ) + rc =3D pci_host_bridge_update_mappings(d); +#endif + return rc; } =20 /* diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host= -common.c index b81184d34980..b6c4d7b636b1 100644 --- a/xen/arch/arm/pci/pci-host-common.c +++ b/xen/arch/arm/pci/pci-host-common.c @@ -235,6 +235,21 @@ int pci_host_iterate_bridges(struct domain *d, } return 0; } + +static int pci_host_bridge_update_mapping(struct domain *d, + struct pci_host_bridge *bridge) +{ + if ( !bridge->ops->update_mappings ) + return 0; + + return bridge->ops->update_mappings(d, bridge); +} + +int pci_host_bridge_update_mappings(struct domain *d) +{ + return pci_host_iterate_bridges(d, pci_host_bridge_update_mapping); +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/pci/pci-host-generic.c b/xen/arch/arm/pci/pci-hos= t-generic.c index 469df3da0116..772c53c881bc 100644 --- a/xen/arch/arm/pci/pci-host-generic.c +++ b/xen/arch/arm/pci/pci-host-generic.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include =20 /* @@ -85,6 +87,31 @@ int pci_ecam_config_read(struct pci_host_bridge *bridge,= uint32_t sbdf, return 0; } =20 +/* + * TODO: This is called late on domain creation to mangle p2m if needed: + * for ECAM host controller for mmio region traps to work for Domain-0 + * we need to unmap those mappings in p2m. + * This is WIP: + * julieng: I think it would be best if we avoid the map/unmap operation. + * So maybe we want to introduce another way to avoid the mapping. + * Maybe by changing the type of the controller to "PCI_HOSTCONTROLLER" + * and check if this is a PCI hostcontroller avoid the mapping. + */ +static int pci_ecam_update_mappings(struct domain *d, + struct pci_host_bridge *bridge) +{ + struct pci_config_window *cfg =3D bridge->sysdata; + int ret; + + /* Only for control domain which owns this PCI host bridge. */ + if ( !is_control_domain(d) ) + return 0; + + ret =3D unmap_regions_p2mt(d, gaddr_to_gfn(cfg->phys_addr), + cfg->size >> PAGE_SHIFT, INVALID_MFN); + return ret; +} + static int pci_ecam_register_mmio_handler(struct domain *d, struct pci_host_bridge *bridge, const struct mmio_handler_ops *o= ps) @@ -101,6 +128,7 @@ struct pci_ecam_ops pci_generic_ecam_ops =3D { .pci_ops =3D { .read =3D pci_ecam_config_read, .write =3D pci_ecam_config_write, + .update_mappings =3D pci_ecam_update_mappings, .register_mmio_handler =3D pci_ecam_register_mmio_handler, } }; diff --git a/xen/include/asm-arm/pci.h b/xen/include/asm-arm/pci.h index e3a02429b8d4..d94e8a6628de 100644 --- a/xen/include/asm-arm/pci.h +++ b/xen/include/asm-arm/pci.h @@ -65,6 +65,7 @@ struct pci_ops { uint32_t sbdf, int where, int size, u32 *val); int (*write)(struct pci_host_bridge *bridge, uint32_t sbdf, int where, int size, u32 val); + int (*update_mappings)(struct domain *d, struct pci_host_bridge *bridg= e); int (*register_mmio_handler)(struct domain *d, struct pci_host_bridge *bridge, const struct mmio_handler_ops *ops); @@ -108,6 +109,7 @@ bool dt_pci_parse_bus_range(struct dt_device_node *dev, int pci_host_iterate_bridges(struct domain *d, int (*clb)(struct domain *d, struct pci_host_bridge *bridge)); +int pci_host_bridge_update_mappings(struct domain *d); #else /*!CONFIG_ARM_PCI*/ struct arch_pci_dev { }; static inline void pci_init(void) { } --=20 2.17.1 From nobody Sat Nov 30 12:32:29 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=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1604926277; cv=none; d=zohomail.com; s=zohoarc; b=TBwn+dWKt5y+f/FhSe1hzVAeOapQMS9TCdHrzJHNVoJUXG7d19CRJiOB0W3Pey8TDIjL8pCrPjoF54q0AJkEOxllwXg6pS75QIqM6uIO3O5NvDqVGVhgffDee8W8UcdNWZhsRju9USwhh8L1EV8g6skXuW0m9eUwUPjW7/XJnDQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604926277; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=elscKxOwLIVI2A3WOH0c4hFjfpu+AwWsnBd8zoJ5TOA=; b=km7AfLRK7XD2SWKAQOwqFGQQhQMUo715WWtWe68FjO3L3FLaWXgKWFhhW0ieibzeBcYq6NhseneQ3gn4P1ovGMj5N0YyJ3t5jM/uVF4569VogUceN4OAvLLXjVID8mNUkbDKAUrpkVqHIQwCckGYkMVL8pxdLEt4zmX4QYEdzAM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1604926277079284.6609364693769; Mon, 9 Nov 2020 04:51:17 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.22472.48830 (Exim 4.92) (envelope-from ) id 1kc6dT-0004EK-FF; Mon, 09 Nov 2020 12:51:03 +0000 Received: by outflank-mailman (output) from mailman id 22472.48830; Mon, 09 Nov 2020 12:51:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dT-0004EC-BS; Mon, 09 Nov 2020 12:51:03 +0000 Received: by outflank-mailman (input) for mailman id 22472; Mon, 09 Nov 2020 12:51:01 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dR-0003tf-Gi for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:51:01 +0000 Received: from mail-lj1-x244.google.com (unknown [2a00:1450:4864:20::244]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c8ab388e-186e-4278-85b1-ae6cd3f5dd61; Mon, 09 Nov 2020 12:50:40 +0000 (UTC) Received: by mail-lj1-x244.google.com with SMTP id v18so10142740ljc.3 for ; Mon, 09 Nov 2020 04:50:40 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:39 -0800 (PST) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dR-0003tf-Gi for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:51:01 +0000 Received: from mail-lj1-x244.google.com (unknown [2a00:1450:4864:20::244]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c8ab388e-186e-4278-85b1-ae6cd3f5dd61; Mon, 09 Nov 2020 12:50:40 +0000 (UTC) Received: by mail-lj1-x244.google.com with SMTP id v18so10142740ljc.3 for ; Mon, 09 Nov 2020 04:50:40 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:39 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c8ab388e-186e-4278-85b1-ae6cd3f5dd61 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; bh=elscKxOwLIVI2A3WOH0c4hFjfpu+AwWsnBd8zoJ5TOA=; b=tcBYbtRH2U39Q1/VskmmFKup9IujI+FTY0QpLU5U/Yh07iYlW+oqc2viPjbmGpZahi r4yzVmyJBqSCQ+G+mjsVmM2o/9WqseNIo20QzBFJkj8ETEKmLQSec4Eg10kgzjaocY87 VAMGGUMrPrqy4LUCnoKGM1v48QgSrYcgvBWeokYCMJdJ1Xz+8zZKiECPhs/pZ3yMOXml AWUkDBaLJfnEHcWrFdm7+I6bMTbFfT5bkxReyUDS7yITWvsiD55px+35Z1vjh4IqlHzV DiFLMCqIZ+tAtySx9n8FN3jVRl3oqVn8QU/xXFlvQKTlngXL9YOvCP8KE1lgMCyVk9jA tUQA== 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; bh=elscKxOwLIVI2A3WOH0c4hFjfpu+AwWsnBd8zoJ5TOA=; b=g4kfgPFmAUOCQoi3Dk1Apr6uFRSLccSFgV9WyC08IRRaCKCRsLsJX0SgMJgeYvMkPu xVfTFOr4DQzywa8PX4hisQZ7uy2FriZ8KMrwnqgIH+cEmbDZidukk134AZvdm/6Li7+g nS6fflZbG8U/sFABCPBr86e/uFs8NLmhdVLcn/ydFpcjeJZgO4UFEPgdj04xsQIfgJsY QGsEwScVLUJFLmsXTd1luNydk1SBfLW5LX9fcC118qu0e0u77Jf+r7jKmgIC7kM/mphQ 9FsXSRmv7RqUWowWmgQ6boAjoVhuGlKMCgOB/7sEl/ZshlHoCK1xY2gFWqQi158wKsB/ dotA== X-Gm-Message-State: AOAM532s+JcMK00HURZdCAghgQVG1rjJPFgrKGkACMRPxXWTeVuOxKsp q2HxWrQnbING5VmRiVy2TOo= X-Google-Smtp-Source: ABdhPJx5rXKcbnC2dQR2fqaqdXLLpOHbJpRTETelBk1X2W2GGtWTbGTJqdBYK60sg1nIaSGbU2Z2TA== X-Received: by 2002:a2e:5d4:: with SMTP id 203mr6214273ljf.137.1604926239612; Mon, 09 Nov 2020 04:50:39 -0800 (PST) From: Oleksandr Andrushchenko To: Rahul.Singh@arm.com, Bertrand.Marquis@arm.com, julien.grall@arm.com, jbeulich@suse.com, roger.pau@citrix.com, sstabellini@kernel.org, xen-devel@lists.xenproject.org Cc: iwj@xenproject.org, wl@xen.org, Oleksandr Andrushchenko Subject: [PATCH 05/10] xen/arm: Process pending vPCI map/unmap operations Date: Mon, 9 Nov 2020 14:50:26 +0200 Message-Id: <20201109125031.26409-6-andr2000@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201109125031.26409-1-andr2000@gmail.com> References: <20201109125031.26409-1-andr2000@gmail.com> X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko vPCI may map and unmap PCI device memory (BARs) being passed through which may take a lot of time. For this those operations may be deferred to be performed later, so that they can be safely preempted. Run the corresponding vPCI code while switching a vCPU. Signed-off-by: Oleksandr Andrushchenko --- xen/arch/arm/traps.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 8f40d0e0b6b1..1c54dc0cdd51 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -33,6 +33,7 @@ #include #include #include +#include =20 #include #include @@ -2253,6 +2254,11 @@ static void check_for_vcpu_work(void) { struct vcpu *v =3D current; =20 + local_irq_enable(); + if ( has_vpci(v->domain) && vpci_process_pending(v) ) + raise_softirq(SCHEDULE_SOFTIRQ); + local_irq_disable(); + if ( likely(!v->arch.need_flush_to_ram) ) return; =20 --=20 2.17.1 From nobody Sat Nov 30 12:32:29 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=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1604926285; cv=none; d=zohomail.com; s=zohoarc; b=aG/miPnt8AT+vDz0ULX5ZTONndbuSiKCOhRvAiY1Fj6NqeCm2yrDmAiry4Pj3MAsf8X/9pnl5BHukVFYa8p1XkJujfeXKRI1J/CH/cgyV/G+SLu4htSCWAQmGmJwi+j/Cv+ccVWX3HdBYVekLE1kNKUXrYlBsBB9YP16VGZjfaI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604926285; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=4uUYf7LbdujIXi0hlvWg2yt1O+62hgozBNucQm/XVxE=; b=Ul4x6DaUpSDtmPqhpVlhkOJFmeo4Q/Ow2BPbL9sNyCCIPReTjt2miCVa4ftGdQDxmybRV4BSx+1RgH4zcme7t8EivsI+8qRDkmngPP70YmWAUI5UdwBxQuQiYMu5A/OH3qLK7dsXEU7CuwKtQdfo8FEbFi8EPXGf9gPht7in/GM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1604926285581993.359418333818; Mon, 9 Nov 2020 04:51:25 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.22475.48842 (Exim 4.92) (envelope-from ) id 1kc6dX-0004JH-PX; Mon, 09 Nov 2020 12:51:07 +0000 Received: by outflank-mailman (output) from mailman id 22475.48842; Mon, 09 Nov 2020 12:51:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dX-0004J9-Lg; Mon, 09 Nov 2020 12:51:07 +0000 Received: by outflank-mailman (input) for mailman id 22475; Mon, 09 Nov 2020 12:51:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dW-0003tf-Gq for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:51:06 +0000 Received: from mail-lj1-x242.google.com (unknown [2a00:1450:4864:20::242]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9df39a4f-6d66-4634-bf58-8d1c09321705; Mon, 09 Nov 2020 12:50:41 +0000 (UTC) Received: by mail-lj1-x242.google.com with SMTP id r17so4485213ljg.5 for ; Mon, 09 Nov 2020 04:50:41 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:40 -0800 (PST) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dW-0003tf-Gq for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:51:06 +0000 Received: from mail-lj1-x242.google.com (unknown [2a00:1450:4864:20::242]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9df39a4f-6d66-4634-bf58-8d1c09321705; Mon, 09 Nov 2020 12:50:41 +0000 (UTC) Received: by mail-lj1-x242.google.com with SMTP id r17so4485213ljg.5 for ; Mon, 09 Nov 2020 04:50:41 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:40 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9df39a4f-6d66-4634-bf58-8d1c09321705 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; bh=4uUYf7LbdujIXi0hlvWg2yt1O+62hgozBNucQm/XVxE=; b=nuwE9B9bn+tdWxbabj0uNIsC6wr3xTqxw523yvetQHGv9ujFCwj5IpveMzBLiEuxW5 CzBHsvYtNJNSfdoCNVPN2gibjCnBV8cmoZ/G182Pq7LZ/B6bSc4p46PfxWc20qhTq4bf yJ5H6rcqP5nWWjUHaiFILNhnbohX21o/MgrRAUU9q3byvwB4QQlNfCcalA2T4plp6Mry czXMqb2Yt3f0tjy9mMUWuTWC8I8AFmbkZoRFT/pprF5e0ye9ZfPZedRyyewF7DGHSvz+ xFNpUVJW6vsMfeXp/zN/ln613ZS9gXC5/BwunyyBjkN6wxXaIA1M1qDBwisLr3i3yREW L5fg== 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; bh=4uUYf7LbdujIXi0hlvWg2yt1O+62hgozBNucQm/XVxE=; b=tGA1NsK2O635NrFwhsWnHTHJKbbs6b067pV9K8s+DGJoSdby3N54iy9wlncmhtK+PT +IhrmiHmDEKhkHFXc/cUYhxTC4OPhdYpu0hqFZ0pmoLX4G29iwpZ2JFMqt7ig/Jxd6j/ DbRQISp0HZ3eIxfSLXfUKSlQkmcAjK8ZjGVXQVe/o1urdo35vq74upQ1WhytXkcMMWQn 58vKLkwSPGAsZ4jx5TqgU9QcPPuaNBJenqSPl2HFWLxzfwOXUUCBwu5ieP5I/GKSWXF7 62+P5b2YwNNv9uVRzj5vGof7Talwc9YU4lY9TgjuYVjdFjWS1fopqhK+O4xFjzJr3Fth VC6A== X-Gm-Message-State: AOAM5339VLqtFA/TXl2oWsuZcwg+1rO2EbTCqMc3LLkGUI0RogmCRcAW xDNsld7jwa/3h8v0K6gN+eM= X-Google-Smtp-Source: ABdhPJzEeHBOgXtCrM/P1zLK3bmDqq8tzFO+IcwdqhxWfb94Tao7VH7AAbtiw041BJADLaam0L9ihA== X-Received: by 2002:a2e:b54a:: with SMTP id a10mr5764786ljn.139.1604926240752; Mon, 09 Nov 2020 04:50:40 -0800 (PST) From: Oleksandr Andrushchenko To: Rahul.Singh@arm.com, Bertrand.Marquis@arm.com, julien.grall@arm.com, jbeulich@suse.com, roger.pau@citrix.com, sstabellini@kernel.org, xen-devel@lists.xenproject.org Cc: iwj@xenproject.org, wl@xen.org, Oleksandr Andrushchenko Subject: [PATCH 06/10] vpci: Make every domain handle its own BARs Date: Mon, 9 Nov 2020 14:50:27 +0200 Message-Id: <20201109125031.26409-7-andr2000@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201109125031.26409-1-andr2000@gmail.com> References: <20201109125031.26409-1-andr2000@gmail.com> X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko At the moment there is an identity mapping between how a guest sees its BARs and how they are programmed into guest domain's p2m. This is not going to work as guest domains have their own view on the BARs. Extend existing vPCI BAR handling to allow every domain to have its own view of the BARs: only hardware domain sees physical memory addresses in this case and for the rest those are emulated, including logic required for the guests to detect memory sizes and properties. While emulating BAR access for the guests create a link between the virtual BAR address and physical one: use full memory address while creating range sets used to map/unmap corresponding address spaces and exploit the fact that PCI BAR value doesn't use 8 lower bits of the memory address. Use those bits to pass physical BAR's index, so we can build/remove proper p2m mappings. Signed-off-by: Oleksandr Andrushchenko --- xen/drivers/vpci/header.c | 276 ++++++++++++++++++++++++++++++++++---- xen/drivers/vpci/vpci.c | 1 + xen/include/xen/vpci.h | 24 ++-- 3 files changed, 265 insertions(+), 36 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index f74f728884c0..7dc7c70e24f2 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -31,14 +31,87 @@ struct map_data { struct domain *d; bool map; + struct pci_dev *pdev; }; =20 +static struct vpci_header *get_vpci_header(struct domain *d, + const struct pci_dev *pdev); + +static struct vpci_header *get_hwdom_vpci_header(const struct pci_dev *pde= v) +{ + if ( unlikely(list_empty(&pdev->vpci->headers)) ) + return get_vpci_header(hardware_domain, pdev); + + /* hwdom's header is always the very first entry. */ + return list_first_entry(&pdev->vpci->headers, struct vpci_header, node= ); +} + +static struct vpci_header *get_vpci_header(struct domain *d, + const struct pci_dev *pdev) +{ + struct list_head *prev; + struct vpci_header *header; + struct vpci *vpci =3D pdev->vpci; + + list_for_each( prev, &vpci->headers ) + { + struct vpci_header *this =3D list_entry(prev, struct vpci_header, = node); + + if ( this->domain_id =3D=3D d->domain_id ) + return this; + } + printk(XENLOG_DEBUG "--------------------------------------" \ + "Adding new vPCI BAR headers for domain %d: " PRI_pci" \n", + d->domain_id, pdev->sbdf.seg, pdev->sbdf.bus, + pdev->sbdf.dev, pdev->sbdf.fn); + header =3D xzalloc(struct vpci_header); + if ( !header ) + { + printk(XENLOG_ERR + "Failed to add new vPCI BAR headers for domain %d: " PRI_pc= i" \n", + d->domain_id, pdev->sbdf.seg, pdev->sbdf.bus, + pdev->sbdf.dev, pdev->sbdf.fn); + return NULL; + } + + if ( !is_hardware_domain(d) ) + { + struct vpci_header *hwdom_header =3D get_hwdom_vpci_header(pdev); + + /* Make a copy of the hwdom's BARs as the initial state for vBARs.= */ + memcpy(header, hwdom_header, sizeof(*header)); + } + + header->domain_id =3D d->domain_id; + list_add_tail(&header->node, &vpci->headers); + return header; +} + +static struct vpci_bar *get_vpci_bar(struct domain *d, + const struct pci_dev *pdev, + int bar_idx) +{ + struct vpci_header *vheader; + + vheader =3D get_vpci_header(d, pdev); + if ( !vheader ) + return NULL; + + return &vheader->bars[bar_idx]; +} + static int map_range(unsigned long s, unsigned long e, void *data, unsigned long *c) { const struct map_data *map =3D data; - int rc; - + unsigned long mfn; + int rc, bar_idx; + struct vpci_header *header =3D get_hwdom_vpci_header(map->pdev); + + bar_idx =3D s & ~PCI_BASE_ADDRESS_MEM_MASK; + s =3D PFN_DOWN(s); + e =3D PFN_DOWN(e); + mfn =3D _mfn(PFN_DOWN(header->bars[bar_idx].addr)); for ( ; ; ) { unsigned long size =3D e - s + 1; @@ -52,11 +125,15 @@ static int map_range(unsigned long s, unsigned long e,= void *data, * - {un}map_mmio_regions doesn't support preemption. */ =20 - rc =3D map->map ? map_mmio_regions(map->d, _gfn(s), size, _mfn(s)) - : unmap_mmio_regions(map->d, _gfn(s), size, _mfn(s)); + rc =3D map->map ? map_mmio_regions(map->d, _gfn(s), size, mfn) + : unmap_mmio_regions(map->d, _gfn(s), size, mfn); if ( rc =3D=3D 0 ) { - *c +=3D size; + /* + * Range set is not expressed in frame numbers and the size + * is the number of frames, so update accordingly. + */ + *c +=3D size << PAGE_SHIFT; break; } if ( rc < 0 ) @@ -67,8 +144,9 @@ static int map_range(unsigned long s, unsigned long e, v= oid *data, break; } ASSERT(rc < size); - *c +=3D rc; + *c +=3D rc << PAGE_SHIFT; s +=3D rc; + mfn +=3D rc; if ( general_preempt_check() ) return -ERESTART; } @@ -84,7 +162,7 @@ static int map_range(unsigned long s, unsigned long e, v= oid *data, static void modify_decoding(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) { - struct vpci_header *header =3D &pdev->vpci->header; + struct vpci_header *header =3D get_hwdom_vpci_header(pdev); bool map =3D cmd & PCI_COMMAND_MEMORY; unsigned int i; =20 @@ -136,6 +214,7 @@ bool vpci_process_pending(struct vcpu *v) struct map_data data =3D { .d =3D v->domain, .map =3D v->vpci.cmd & PCI_COMMAND_MEMORY, + .pdev =3D v->vpci.pdev, }; int rc =3D rangeset_consume_ranges(v->vpci.mem, map_range, &data); =20 @@ -168,7 +247,8 @@ bool vpci_process_pending(struct vcpu *v) static int __init apply_map(struct domain *d, const struct pci_dev *pdev, struct rangeset *mem, uint16_t cmd) { - struct map_data data =3D { .d =3D d, .map =3D true }; + struct map_data data =3D { .d =3D d, .map =3D true, + .pdev =3D (struct pci_dev *)pdev }; int rc; =20 while ( (rc =3D rangeset_consume_ranges(mem, map_range, &data)) =3D=3D= -ERESTART ) @@ -205,7 +285,7 @@ static void defer_map(struct domain *d, struct pci_dev = *pdev, =20 static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_= only) { - struct vpci_header *header =3D &pdev->vpci->header; + struct vpci_header *header; struct rangeset *mem =3D rangeset_new(NULL, NULL, 0); struct pci_dev *tmp, *dev =3D NULL; #ifdef CONFIG_X86 @@ -217,6 +297,11 @@ static int modify_bars(const struct pci_dev *pdev, uin= t16_t cmd, bool rom_only) if ( !mem ) return -ENOMEM; =20 + if ( is_hardware_domain(current->domain) ) + header =3D get_hwdom_vpci_header(pdev); + else + header =3D get_vpci_header(current->domain, pdev); + /* * Create a rangeset that represents the current device BARs memory re= gion * and compare it against all the currently active BAR memory regions.= If @@ -225,12 +310,15 @@ static int modify_bars(const struct pci_dev *pdev, ui= nt16_t cmd, bool rom_only) * First fill the rangeset with all the BARs of this device or with th= e ROM * BAR only, depending on whether the guest is toggling the memory dec= ode * bit of the command register, or the enable bit of the ROM BAR regis= ter. + * + * Use the PCI reserved bits of the BAR to pass BAR's index. */ for ( i =3D 0; i < ARRAY_SIZE(header->bars); i++ ) { const struct vpci_bar *bar =3D &header->bars[i]; - unsigned long start =3D PFN_DOWN(bar->addr); - unsigned long end =3D PFN_DOWN(bar->addr + bar->size - 1); + unsigned long start =3D (bar->addr & PCI_BASE_ADDRESS_MEM_MASK) | = i; + unsigned long end =3D (bar->addr & PCI_BASE_ADDRESS_MEM_MASK) + + bar->size - 1; =20 if ( !MAPPABLE_BAR(bar) || (rom_only ? bar->type !=3D VPCI_BAR_ROM @@ -251,9 +339,11 @@ static int modify_bars(const struct pci_dev *pdev, uin= t16_t cmd, bool rom_only) /* Remove any MSIX regions if present. */ for ( i =3D 0; msix && i < ARRAY_SIZE(msix->tables); i++ ) { - unsigned long start =3D PFN_DOWN(vmsix_table_addr(pdev->vpci, i)); - unsigned long end =3D PFN_DOWN(vmsix_table_addr(pdev->vpci, i) + - vmsix_table_size(pdev->vpci, i) - 1); + unsigned long start =3D (vmsix_table_addr(pdev->vpci, i) & + PCI_BASE_ADDRESS_MEM_MASK) | i; + unsigned long end =3D (vmsix_table_addr(pdev->vpci, i) & + PCI_BASE_ADDRESS_MEM_MASK ) + + vmsix_table_size(pdev->vpci, i) - 1; =20 rc =3D rangeset_remove_range(mem, start, end); if ( rc ) @@ -273,6 +363,8 @@ static int modify_bars(const struct pci_dev *pdev, uint= 16_t cmd, bool rom_only) */ for_each_pdev ( pdev->domain, tmp ) { + struct vpci_header *header; + if ( tmp =3D=3D pdev ) { /* @@ -289,11 +381,14 @@ static int modify_bars(const struct pci_dev *pdev, ui= nt16_t cmd, bool rom_only) continue; } =20 - for ( i =3D 0; i < ARRAY_SIZE(tmp->vpci->header.bars); i++ ) + header =3D get_vpci_header(tmp->domain, pdev); + + for ( i =3D 0; i < ARRAY_SIZE(header->bars); i++ ) { - const struct vpci_bar *bar =3D &tmp->vpci->header.bars[i]; - unsigned long start =3D PFN_DOWN(bar->addr); - unsigned long end =3D PFN_DOWN(bar->addr + bar->size - 1); + const struct vpci_bar *bar =3D &header->bars[i]; + unsigned long start =3D (bar->addr & PCI_BASE_ADDRESS_MEM_MASK= ) | i; + unsigned long end =3D (bar->addr & PCI_BASE_ADDRESS_MEM_MASK) + + bar->size - 1; =20 if ( !bar->enabled || !rangeset_overlaps_range(mem, start, end= ) || /* @@ -357,7 +452,7 @@ static void cmd_write(const struct pci_dev *pdev, unsig= ned int reg, pci_conf_write16(pdev->sbdf, reg, cmd); } =20 -static void bar_write(const struct pci_dev *pdev, unsigned int reg, +static void bar_write_hwdom(const struct pci_dev *pdev, unsigned int reg, uint32_t val, void *data) { struct vpci_bar *bar =3D data; @@ -377,14 +472,17 @@ static void bar_write(const struct pci_dev *pdev, uns= igned int reg, { /* If the value written is the current one avoid printing a warnin= g. */ if ( val !=3D (uint32_t)(bar->addr >> (hi ? 32 : 0)) ) + { + struct vpci_header *header =3D get_hwdom_vpci_header(pdev); + gprintk(XENLOG_WARNING, "%04x:%02x:%02x.%u: ignored BAR %lu write with memory = decoding enabled\n", pdev->seg, pdev->bus, slot, func, - bar - pdev->vpci->header.bars + hi); + bar - header->bars + hi); + } return; } =20 - /* * Update the cached address, so that when memory decoding is enabled * Xen can map the BAR into the guest p2m. @@ -403,10 +501,89 @@ static void bar_write(const struct pci_dev *pdev, uns= igned int reg, pci_conf_write32(pdev->sbdf, reg, val); } =20 +static uint32_t bar_read_hwdom(const struct pci_dev *pdev, unsigned int re= g, + void *data) +{ + return vpci_hw_read32(pdev, reg, data); +} + +static void bar_write_guest(const struct pci_dev *pdev, unsigned int reg, + uint32_t val, void *data) +{ + struct vpci_bar *vbar =3D data; + bool hi =3D false; + + if ( vbar->type =3D=3D VPCI_BAR_MEM64_HI ) + { + ASSERT(reg > PCI_BASE_ADDRESS_0); + vbar--; + hi =3D true; + } + vbar->addr &=3D ~(0xffffffffull << (hi ? 32 : 0)); + vbar->addr |=3D (uint64_t)val << (hi ? 32 : 0); +} + +static uint32_t bar_read_guest(const struct pci_dev *pdev, unsigned int re= g, + void *data) +{ + struct vpci_bar *vbar =3D data; + uint32_t val; + bool hi =3D false; + + if ( vbar->type =3D=3D VPCI_BAR_MEM64_HI ) + { + ASSERT(reg > PCI_BASE_ADDRESS_0); + vbar--; + hi =3D true; + } + + if ( vbar->type =3D=3D VPCI_BAR_MEM64_LO || vbar->type =3D=3D VPCI_BAR= _MEM64_HI ) + { + if ( hi ) + val =3D vbar->addr >> 32; + else + val =3D vbar->addr & 0xffffffff; + if ( val =3D=3D ~0 ) + { + /* Guests detects BAR's properties and sizes. */ + if ( !hi ) + { + val =3D 0xffffffff & ~(vbar->size - 1); + val |=3D vbar->type =3D=3D VPCI_BAR_MEM32 ? PCI_BASE_ADDRE= SS_MEM_TYPE_32 + : PCI_BASE_ADDRESS_MEM= _TYPE_64; + val |=3D vbar->prefetchable ? PCI_BASE_ADDRESS_MEM_PREFETC= H : 0; + } + else + val =3D vbar->size >> 32; + vbar->addr &=3D ~(0xffffffffull << (hi ? 32 : 0)); + vbar->addr |=3D (uint64_t)val << (hi ? 32 : 0); + } + } + else if ( vbar->type =3D=3D VPCI_BAR_MEM32 ) + { + val =3D vbar->addr; + if ( val =3D=3D ~0 ) + { + if ( !hi ) + { + val =3D 0xffffffff & ~(vbar->size - 1); + val |=3D vbar->type =3D=3D VPCI_BAR_MEM32 ? PCI_BASE_ADDRE= SS_MEM_TYPE_32 + : PCI_BASE_ADDRESS_MEM= _TYPE_64; + val |=3D vbar->prefetchable ? PCI_BASE_ADDRESS_MEM_PREFETC= H : 0; + } + } + } + else + { + val =3D vbar->addr; + } + return val; +} + static void rom_write(const struct pci_dev *pdev, unsigned int reg, uint32_t val, void *data) { - struct vpci_header *header =3D &pdev->vpci->header; + struct vpci_header *header =3D get_hwdom_vpci_header(pdev); struct vpci_bar *rom =3D data; uint8_t slot =3D PCI_SLOT(pdev->devfn), func =3D PCI_FUNC(pdev->devfn); uint16_t cmd =3D pci_conf_read16(pdev->sbdf, PCI_COMMAND); @@ -452,15 +629,56 @@ static void rom_write(const struct pci_dev *pdev, uns= igned int reg, rom->addr =3D val & PCI_ROM_ADDRESS_MASK; } =20 +static uint32_t bar_read_dispatch(const struct pci_dev *pdev, unsigned int= reg, + void *data) +{ + struct vpci_bar *vbar, *bar =3D data; + + if ( is_hardware_domain(current->domain) ) + return bar_read_hwdom(pdev, reg, data); + + vbar =3D get_vpci_bar(current->domain, pdev, bar->index); + if ( !vbar ) + return ~0; + + return bar_read_guest(pdev, reg, vbar); +} + +static void bar_write_dispatch(const struct pci_dev *pdev, unsigned int re= g, + uint32_t val, void *data) +{ + struct vpci_bar *bar =3D data; + + if ( is_hardware_domain(current->domain) ) + bar_write_hwdom(pdev, reg, val, data); + else + { + struct vpci_bar *vbar =3D get_vpci_bar(current->domain, pdev, bar-= >index); + + if ( !vbar ) + return; + bar_write_guest(pdev, reg, val, vbar); + } +} + +/* + * FIXME: This is called early while adding vPCI handlers which is done + * by and for hwdom. + */ static int init_bars(struct pci_dev *pdev) { uint16_t cmd; uint64_t addr, size; unsigned int i, num_bars, rom_reg; - struct vpci_header *header =3D &pdev->vpci->header; - struct vpci_bar *bars =3D header->bars; + struct vpci_header *header; + struct vpci_bar *bars; int rc; =20 + header =3D get_hwdom_vpci_header(pdev); + if ( !header ) + return -ENOMEM; + bars =3D header->bars; + switch ( pci_conf_read8(pdev->sbdf, PCI_HEADER_TYPE) & 0x7f ) { case PCI_HEADER_TYPE_NORMAL: @@ -496,11 +714,12 @@ static int init_bars(struct pci_dev *pdev) uint8_t reg =3D PCI_BASE_ADDRESS_0 + i * 4; uint32_t val; =20 + bars[i].index =3D i; if ( i && bars[i - 1].type =3D=3D VPCI_BAR_MEM64_LO ) { bars[i].type =3D VPCI_BAR_MEM64_HI; - rc =3D vpci_add_register(pdev->vpci, vpci_hw_read32, bar_write= , reg, - 4, &bars[i]); + rc =3D vpci_add_register(pdev->vpci, bar_read_dispatch, + bar_write_dispatch, reg, 4, &bars[i]); if ( rc ) { pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd); @@ -540,8 +759,8 @@ static int init_bars(struct pci_dev *pdev) bars[i].size =3D size; bars[i].prefetchable =3D val & PCI_BASE_ADDRESS_MEM_PREFETCH; =20 - rc =3D vpci_add_register(pdev->vpci, vpci_hw_read32, bar_write, re= g, 4, - &bars[i]); + rc =3D vpci_add_register(pdev->vpci, bar_read_dispatch, + bar_write_dispatch, reg, 4, &bars[i]); if ( rc ) { pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd); @@ -558,6 +777,7 @@ static int init_bars(struct pci_dev *pdev) rom->type =3D VPCI_BAR_ROM; rom->size =3D size; rom->addr =3D addr; + rom->index =3D num_bars; header->rom_enabled =3D pci_conf_read32(pdev->sbdf, rom_reg) & PCI_ROM_ADDRESS_ENABLE; =20 diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index a5293521a36a..728029da3e9c 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -69,6 +69,7 @@ int __hwdom_init vpci_add_handlers(struct pci_dev *pdev) return -ENOMEM; =20 INIT_LIST_HEAD(&pdev->vpci->handlers); + INIT_LIST_HEAD(&pdev->vpci->headers); spin_lock_init(&pdev->vpci->lock); =20 for ( i =3D 0; i < NUM_VPCI_INIT; i++ ) diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index c3501e9ec010..54423bc6556d 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -55,16 +55,14 @@ uint32_t vpci_hw_read32(const struct pci_dev *pdev, uns= igned int reg, */ bool __must_check vpci_process_pending(struct vcpu *v); =20 -struct vpci { - /* List of vPCI handlers for a device. */ - struct list_head handlers; - spinlock_t lock; - #ifdef __XEN__ - /* Hide the rest of the vpci struct from the user-space test harness. = */ struct vpci_header { + struct list_head node; + /* Domain that owns this view of the BARs. */ + domid_t domain_id; /* Information about the PCI BARs of this device. */ struct vpci_bar { + int index; uint64_t addr; uint64_t size; enum { @@ -88,8 +86,18 @@ struct vpci { * is mapped into guest p2m) if there's a ROM BAR on the device. */ bool rom_enabled : 1; - /* FIXME: currently there's no support for SR-IOV. */ - } header; +}; +#endif + +struct vpci { + /* List of vPCI handlers for a device. */ + struct list_head handlers; + spinlock_t lock; + +#ifdef __XEN__ + /* Hide the rest of the vpci struct from the user-space test harness. = */ + /* List of vPCI headers for all domains. */ + struct list_head headers; =20 #ifdef CONFIG_X86 /* MSI data. */ --=20 2.17.1 From nobody Sat Nov 30 12:32:29 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=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1604926286; cv=none; d=zohomail.com; s=zohoarc; b=PtWGn9ewrh22QyiwB+ZJCXrfaZkZtMWVqPXsFhVULxl4h0YmcQKzRPn3ZBnvOYs+8wWRhKh8amSfQbfClZIwp4uw0/lm8wjCXp0nZ9Lsr//gbdHTzLj1pydnMsrwfFcKd1CuitsEyNYRxM00fXsFKjnfhoiCGa5msBfuy5gE4Rw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604926286; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=eTzgC8wjlZZ5dW1kDk0Apl54Fj76f3KrpZyQEpkVwKo=; b=cc/sRJgghAQ4Mhtuz1ycCe/QRV6KnidXMV3R/ox9K4Bl8LLxd3IOw/SfweHyf1vMG3qxudJUPpog/dQd9vnZennqVssp+miqBH6s60ezpgR7ltM1dIKl3cZEbPhKyEAb5pGlltyy+oy9aptbeZkB87qda9ZmQ0NqL8Q7CceuUjw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1604926286522787.6247841666087; Mon, 9 Nov 2020 04:51:26 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.22480.48854 (Exim 4.92) (envelope-from ) id 1kc6dd-0004QU-CV; Mon, 09 Nov 2020 12:51:13 +0000 Received: by outflank-mailman (output) from mailman id 22480.48854; Mon, 09 Nov 2020 12:51:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dd-0004QF-5l; Mon, 09 Nov 2020 12:51:13 +0000 Received: by outflank-mailman (input) for mailman id 22480; Mon, 09 Nov 2020 12:51:11 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6db-0003tf-H3 for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:51:11 +0000 Received: from mail-lj1-x242.google.com (unknown [2a00:1450:4864:20::242]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id dc348a48-5985-497a-b14c-cb2c93794339; Mon, 09 Nov 2020 12:50:43 +0000 (UTC) Received: by mail-lj1-x242.google.com with SMTP id 23so10119541ljv.7 for ; Mon, 09 Nov 2020 04:50:42 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:41 -0800 (PST) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6db-0003tf-H3 for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:51:11 +0000 Received: from mail-lj1-x242.google.com (unknown [2a00:1450:4864:20::242]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id dc348a48-5985-497a-b14c-cb2c93794339; Mon, 09 Nov 2020 12:50:43 +0000 (UTC) Received: by mail-lj1-x242.google.com with SMTP id 23so10119541ljv.7 for ; Mon, 09 Nov 2020 04:50:42 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:41 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: dc348a48-5985-497a-b14c-cb2c93794339 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; bh=eTzgC8wjlZZ5dW1kDk0Apl54Fj76f3KrpZyQEpkVwKo=; b=Q+1kyGk5oARHjB8whVHpRnlcQGZvtUwLqYbMqdS2JgNepCo6HOCtrkgLU4lRbnd8Yh HiwTsu7E+ujayTEFUS5+o8cbaTGs5LrUWHtG8VOtipdlzsAgSrFWEGZTqySzl6Xpr82Q ILuyttgBKhz0I8XuKJgP0/RHWouG8xbM/KEMucYHrWTmTpk3XLk0oxxKJfjqSZ3MsOaP w1F2b3JLfnFvA8OdZObmhzlJfBUkmeIyQciEUQaNYChFd7vCou/T1NEBFjGUNiRItvT7 sAjBFf/ixmlga0rH4j6IGQCEKR8S43/jU9w9FSDawd0FME2xd9VysITBFGikF6FrXXKH OJfA== 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; bh=eTzgC8wjlZZ5dW1kDk0Apl54Fj76f3KrpZyQEpkVwKo=; b=FwAEvUhu6vBOIcoF8r9MpUnpLFiyM3W6u0GDQMZvU39JAPHIifQlcmkHXnUslyQu+I 08jCxlV8YDbxeiwtvaCmxkbOiCEjbUjkYPGVdEqHdfQJgyFlBSH8//Olj0KE3e5XcVxz FTZs7ZkA5LemYgjzi+Xpn6mfyuPQb0quQHal9BcCNoRnVpeyb4g7YeXKFLR27DDAfJpR ZpkE8XJYB1IirGKx+amHYdyjT/2GsSi5RCiJADuY29fp+bbzqf3c4T4mU4By/sP2fxl9 ZW88nxNvXI6iRvX9TPxsd6Yp+JZ7o838J5hsNKP/S8v/9tzkuZBvlACYhgJBm2NAgV6e 6KlQ== X-Gm-Message-State: AOAM533eFebnC6GcK4evJ7WnGOfagamGOQnIFc25IuJ60BsIljpJnZ5G LuKljgnzfAwYBGbEYSnGMjBe1r3DpfZdD5c7 X-Google-Smtp-Source: ABdhPJwcPThVD8W/eKCaLs5uWrQq++GkIkgz3jehLAFccyEViZGB673ffnnnOCit0z69w08y6AN6Vg== X-Received: by 2002:a2e:b701:: with SMTP id j1mr6333703ljo.242.1604926241939; Mon, 09 Nov 2020 04:50:41 -0800 (PST) From: Oleksandr Andrushchenko To: Rahul.Singh@arm.com, Bertrand.Marquis@arm.com, julien.grall@arm.com, jbeulich@suse.com, roger.pau@citrix.com, sstabellini@kernel.org, xen-devel@lists.xenproject.org Cc: iwj@xenproject.org, wl@xen.org, Oleksandr Andrushchenko Subject: [PATCH 07/10] xen/arm: Do not hardcode phycial PCI device addresses Date: Mon, 9 Nov 2020 14:50:28 +0200 Message-Id: <20201109125031.26409-8-andr2000@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201109125031.26409-1-andr2000@gmail.com> References: <20201109125031.26409-1-andr2000@gmail.com> X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko As vPCI now takes care of the proper p2m mappings for PCI devices there is no more need to hardcode anything. Signed-off-by: Oleksandr Andrushchenko --- xen/include/public/arch-arm.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index 2411ac9f7b0a..59baf1014fe3 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -444,15 +444,8 @@ typedef uint64_t xen_callback_t; #define GUEST_VPCI_MEM_CPU_ADDR xen_mk_ullong(0x04020000) #define GUEST_VPCI_IO_CPU_ADDR xen_mk_ullong(0xC0200800) =20 -/* - * This is hardcoded values for the real PCI physical addresses. - * This will be removed once we read the real PCI-PCIe physical - * addresses form the config space and map to the guest memory map - * when assigning the device to guest via VPCI. - * - */ #define GUEST_VPCI_PREFETCH_MEM_PCI_ADDR xen_mk_ullong(0x4000000000) -#define GUEST_VPCI_MEM_PCI_ADDR xen_mk_ullong(0x50000000) +#define GUEST_VPCI_MEM_PCI_ADDR xen_mk_ullong(0x04020000) #define GUEST_VPCI_IO_PCI_ADDR xen_mk_ullong(0x00000000) =20 #define GUEST_VPCI_PREFETCH_MEM_SIZE xen_mk_ullong(0x100000000) --=20 2.17.1 From nobody Sat Nov 30 12:32:29 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=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1604926292; cv=none; d=zohomail.com; s=zohoarc; b=QvNmKHlL3vUySxK6uqZKLe3Aq6id0Fs6UQ24wdiFTa9DOiv/YigJlSbdqFD4rs+DpayZTc8YJU+m5kSgqHpChpqijijI+iztRf/8krv/DYsmJCnrvA+p60TC67zXzqsYdHOT2c+JmmIko3Xnl1OAXapsZM8CmxRQF3pgHl8o9Rc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604926292; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=nvNmRBs0yMdCUG+5+G3i3M5jvG9+T7PAVH/ULtYwZd8=; b=HN5HpnUKKQz+YLHVBpTZunJre6iTVuFWPkbkS4fCSA4Ierdl0xILNTdB7jbYoUgLw/t3AX/bFnSraxPFcnASxoHN+mdF58bmE/K7vDpOxYE7URi9CBiEATuZGmaihSENr7gE3Vp/Ec8HUdZ302SHWWw1AZYr5RQNJLvmZQwF04M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1604926292518253.4051381689925; Mon, 9 Nov 2020 04:51:32 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.22485.48866 (Exim 4.92) (envelope-from ) id 1kc6di-0004XL-Mf; Mon, 09 Nov 2020 12:51:18 +0000 Received: by outflank-mailman (output) from mailman id 22485.48866; Mon, 09 Nov 2020 12:51:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6di-0004X6-IX; Mon, 09 Nov 2020 12:51:18 +0000 Received: by outflank-mailman (input) for mailman id 22485; Mon, 09 Nov 2020 12:51:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dg-0003tf-HB for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:51:16 +0000 Received: from mail-lf1-x143.google.com (unknown [2a00:1450:4864:20::143]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9373c888-deb2-488e-818e-fa0740b97367; Mon, 09 Nov 2020 12:50:44 +0000 (UTC) Received: by mail-lf1-x143.google.com with SMTP id f11so5953619lfs.3 for ; Mon, 09 Nov 2020 04:50:44 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:42 -0800 (PST) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dg-0003tf-HB for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:51:16 +0000 Received: from mail-lf1-x143.google.com (unknown [2a00:1450:4864:20::143]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9373c888-deb2-488e-818e-fa0740b97367; Mon, 09 Nov 2020 12:50:44 +0000 (UTC) Received: by mail-lf1-x143.google.com with SMTP id f11so5953619lfs.3 for ; Mon, 09 Nov 2020 04:50:44 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:42 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9373c888-deb2-488e-818e-fa0740b97367 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; bh=nvNmRBs0yMdCUG+5+G3i3M5jvG9+T7PAVH/ULtYwZd8=; b=BhLucB5unsgmpqCexxIviXoItX2knYBdsgr+yYELfc6dr8nME0oNQOEI3yc8ktBgNQ j5qG9gXFioPOtAz9b1XK70s8Q7w3Qo+on1JDA/vcCoN1xAwNuClbRiCFKnIpiKdJ/2bK fGyPd6VUEqYTvU9skirT/6Fp6HSM6ToAyr52K+IoSd8ASPbwjfS4EiYUIrBFa6m9ZA4B Reext1joqqooXwsl7kXl7+z2os2td3jxJkZlcBWSrQcGrT2tX8xo18fauv0twLpimoY8 WojJROH0jW7I9TJnPUy8gNbladV7e9Oz9GkwPe5VVe+QHLcX6aw+rG7/46lOqMPmbeY8 SN5g== 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; bh=nvNmRBs0yMdCUG+5+G3i3M5jvG9+T7PAVH/ULtYwZd8=; b=WXirXJ3Slfo/KxpylhnAgvXlFO8qIn479DhhaM7jHHnU0nNOsecY5K+i1FHRLeDbqd iFnPIJ1cGSTANWq6CEz1Exe1TYdGQ8wC1udjsbQ1kILx3DwhQ6aDxsNR7GWcwRNpsiO9 kExnRtwJ3+latMRh6r8no/agu965hLcq9xH8XooQWq2ybfbkzJ/j9AuEK+OQfkYxUiU5 MbUldKT9zoJt/FunsRiFt8v2u9udiBhy6Y02pG88MWt/JoakDTuUiied51TA9ex1e9Uy H77rR01TPYPH5zYx4/YPiDPlxhfLeaADKelyQNzARgalDz/nz6sFC8zmkx3jIXLg7KsW 1LOg== X-Gm-Message-State: AOAM531q+C3dP2JhgSn+vzeohBvBKv0XXmPlxjAccgirkgbnbN893Vzm 9yd1TCEZVtMKx5X5m1BNKnA= X-Google-Smtp-Source: ABdhPJwIxNZ+eFf7k5nHNhhjoeffUH3DJiF6DgEDs7OPTcsBJLtqcKWT+tf2/kVSMShVjyHxOj/DWw== X-Received: by 2002:ac2:57d3:: with SMTP id k19mr6188423lfo.386.1604926243125; Mon, 09 Nov 2020 04:50:43 -0800 (PST) From: Oleksandr Andrushchenko To: Rahul.Singh@arm.com, Bertrand.Marquis@arm.com, julien.grall@arm.com, jbeulich@suse.com, roger.pau@citrix.com, sstabellini@kernel.org, xen-devel@lists.xenproject.org Cc: iwj@xenproject.org, wl@xen.org, Oleksandr Andrushchenko Subject: [PATCH 08/10] vpci/arm: Allow updating BAR's header for non-ECAM bridges Date: Mon, 9 Nov 2020 14:50:29 +0200 Message-Id: <20201109125031.26409-9-andr2000@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201109125031.26409-1-andr2000@gmail.com> References: <20201109125031.26409-1-andr2000@gmail.com> X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko Non-ECAM host bridges in hwdom go directly to PCI config space, not through vpci (they use their specific method for accessing PCI configuration, e.g. dedicated registers etc.). Thus hwdom's vpci BARs are never updated via vPCI MMIO handlers, so implement a dedicated method for a PCI host bridge, so it has a chance to update the initial state of the device BARs. Note, we rely on the fact that control/hardware domain will not update physical BAR locations for the given devices. Signed-off-by: Oleksandr Andrushchenko --- xen/arch/arm/pci/pci-host-common.c | 13 +++++++++++++ xen/drivers/vpci/header.c | 9 ++++++++- xen/include/asm-arm/pci.h | 8 ++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host= -common.c index b6c4d7b636b1..5f4239afa41f 100644 --- a/xen/arch/arm/pci/pci-host-common.c +++ b/xen/arch/arm/pci/pci-host-common.c @@ -250,6 +250,19 @@ int pci_host_bridge_update_mappings(struct domain *d) return pci_host_iterate_bridges(d, pci_host_bridge_update_mapping); } =20 +void pci_host_bridge_update_bar_header(const struct pci_dev *pdev, + struct vpci_header *header) +{ + struct pci_host_bridge *bridge; + + bridge =3D pci_find_host_bridge(pdev->seg, pdev->bus); + if ( unlikely(!bridge) ) + return; + + if ( bridge->ops->update_bar_header ) + bridge->ops->update_bar_header(pdev, header); +} + /* * Local variables: * mode: C diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 7dc7c70e24f2..1f326c894d16 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -77,7 +77,14 @@ static struct vpci_header *get_vpci_header(struct domain= *d, if ( !is_hardware_domain(d) ) { struct vpci_header *hwdom_header =3D get_hwdom_vpci_header(pdev); - +#ifdef CONFIG_ARM + /* + * Non-ECAM host bridges in hwdom go directly to PCI + * config space, not through vpci. Thus hwdom's vpci BARs are + * never updated. + */ + pci_host_bridge_update_bar_header(pdev, hwdom_header); +#endif /* Make a copy of the hwdom's BARs as the initial state for vBARs.= */ memcpy(header, hwdom_header, sizeof(*header)); } diff --git a/xen/include/asm-arm/pci.h b/xen/include/asm-arm/pci.h index d94e8a6628de..723b2a99b6e1 100644 --- a/xen/include/asm-arm/pci.h +++ b/xen/include/asm-arm/pci.h @@ -60,6 +60,9 @@ struct pci_config_window { /* Forward declaration as pci_host_bridge and pci_ops depend on each other= . */ struct pci_host_bridge; =20 +struct pci_dev; +struct vpci_header; + struct pci_ops { int (*read)(struct pci_host_bridge *bridge, uint32_t sbdf, int where, int size, u32 *val); @@ -69,6 +72,8 @@ struct pci_ops { int (*register_mmio_handler)(struct domain *d, struct pci_host_bridge *bridge, const struct mmio_handler_ops *ops); + void (*update_bar_header)(const struct pci_dev *pdev, + struct vpci_header *header); }; =20 /* @@ -110,6 +115,9 @@ int pci_host_iterate_bridges(struct domain *d, int (*clb)(struct domain *d, struct pci_host_bridge *bridge)); int pci_host_bridge_update_mappings(struct domain *d); +void pci_host_bridge_update_bar_header(const struct pci_dev *pdev, + struct vpci_header *header); + #else /*!CONFIG_ARM_PCI*/ struct arch_pci_dev { }; static inline void pci_init(void) { } --=20 2.17.1 From nobody Sat Nov 30 12:32:29 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=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1604926299; cv=none; d=zohomail.com; s=zohoarc; b=bXBEPktaTnv6boISMO1lQNHzWo9tKapJz6NiBZbPLz1iIHMll4kKWUziFkt57bvCikyDymPO8zZIVeXYu+teMivnk68HSGVktyVvF+XRKybEL/IyCQfujg+L29ezLM8WJ32ytNFQ9fgHGpTTAtOkdSLYSXxk+47FBlP3v7/a7To= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604926299; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=eL99YnEMb+Fyva1t76PgaT1/+PMUISpx/gf+bW+r/cI=; b=RswG7Sc28pkfht5Y7tXZMZHS2KmX2o/34u2Q8SibMr/PbOY4ohIwMx+Gwv/PkEZgUzG5Lfaam4Ip1yTmMRBz+N7AntWUj49VR3r5DIFlWTonfvKsgi8gIFIhGmRR/0Jq6//UoiNHYi/olq6HlIUvp4AzZ17eC8EAG0F5t8XRevA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1604926299406917.7190260690985; Mon, 9 Nov 2020 04:51:39 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.22489.48878 (Exim 4.92) (envelope-from ) id 1kc6dn-0004d0-0P; Mon, 09 Nov 2020 12:51:23 +0000 Received: by outflank-mailman (output) from mailman id 22489.48878; Mon, 09 Nov 2020 12:51:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dm-0004cp-Su; Mon, 09 Nov 2020 12:51:22 +0000 Received: by outflank-mailman (input) for mailman id 22489; Mon, 09 Nov 2020 12:51:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dl-0003tf-HP for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:51:21 +0000 Received: from mail-lj1-x241.google.com (unknown [2a00:1450:4864:20::241]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id aabbabcf-60b4-4731-b85c-19f807f3690c; Mon, 09 Nov 2020 12:50:45 +0000 (UTC) Received: by mail-lj1-x241.google.com with SMTP id o24so3432507ljj.6 for ; Mon, 09 Nov 2020 04:50:45 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:43 -0800 (PST) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dl-0003tf-HP for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:51:21 +0000 Received: from mail-lj1-x241.google.com (unknown [2a00:1450:4864:20::241]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id aabbabcf-60b4-4731-b85c-19f807f3690c; Mon, 09 Nov 2020 12:50:45 +0000 (UTC) Received: by mail-lj1-x241.google.com with SMTP id o24so3432507ljj.6 for ; Mon, 09 Nov 2020 04:50:45 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:43 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: aabbabcf-60b4-4731-b85c-19f807f3690c 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; bh=eL99YnEMb+Fyva1t76PgaT1/+PMUISpx/gf+bW+r/cI=; b=HIz0YaOhkTYT9bi7q3vjfOFzs5nAscZaPl/ok3a0KcURNAkpcnAiB3ZSQlhsq94anU 8pcS45urcHNlE+SWTJ0ceIR/qq5Ap5XZjYN2mGXHgu8WxpgtxzKUygvzDM/rX7vg5fJ3 B8gahy9qZ0YZYpztX6gD1R1fHu4UKOXdBQE3VFJEU81+YCH2Di3atrwl0TMwAPJ/dhQl oNqcHsI2aiS/wtwHpxkWtq0Y7V9OoE6Wx8fktrP9tuvfzgmMlF1LgklQy2Z/EyDdb+D6 +ly2E/EHTcQmmmUjMwzhSzyMj9hdv2saHe6ey0FFT9txiM63byBTE/ydvFb9NVMYmVTT gTGg== 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; bh=eL99YnEMb+Fyva1t76PgaT1/+PMUISpx/gf+bW+r/cI=; b=cXzlTRHJBu0qvY5ZK9A83FGA23XaMQptoUeCV2rUQk89dwkmvE593A3/2z2WNGh3bk W8d7ZbOrwikR0ck+P2tHhEoG4Fw2kGt6TbgBqXN+Ie39QGh/0lcUHNWR0l53DL+PRiJq sHkhtCbK7pivfZPA8qQvVAp6kM4eItKU5ACg2B3lY5qoyW/y9bu7W3Ya4Mz0EMo57dwQ FhUC6K6O8DIkR4Xs7O+SX8YTwMdJCFVrWOqd4iPMdq3ctPtW/D3FJpRFo0nCnwUaTBVA JZEIxxOl1YCaUdr9aF8/LsnkSGQP9oC1EL7YL91JN8UHvx8QYWILQySL7ymtae/3IL9S ZMMA== X-Gm-Message-State: AOAM532eP1DoZq3dCQQjlMAg5yYpphmETjbP3VbNeDHHj598LMWNRYrL DG9A76mt76B4hQs7MJ6pADk= X-Google-Smtp-Source: ABdhPJxgeKI9dEyPqiYGy3kiXhmC5roPNZKfR08jh66HPMOL1bYYFLCoIBl0CtpPpcDIcSW8vJH91w== X-Received: by 2002:a2e:9207:: with SMTP id k7mr1622007ljg.71.1604926244200; Mon, 09 Nov 2020 04:50:44 -0800 (PST) From: Oleksandr Andrushchenko To: Rahul.Singh@arm.com, Bertrand.Marquis@arm.com, julien.grall@arm.com, jbeulich@suse.com, roger.pau@citrix.com, sstabellini@kernel.org, xen-devel@lists.xenproject.org Cc: iwj@xenproject.org, wl@xen.org, Oleksandr Andrushchenko Subject: [PATCH 09/10] vpci/rcar: Implement vPCI.update_bar_header callback Date: Mon, 9 Nov 2020 14:50:30 +0200 Message-Id: <20201109125031.26409-10-andr2000@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201109125031.26409-1-andr2000@gmail.com> References: <20201109125031.26409-1-andr2000@gmail.com> X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko Update hardware domain's BAR header as R-Car Gen3 is a non-ECAM host controller, so vPCI MMIO handlers do not work for it in hwdom. Signed-off-by: Oleksandr Andrushchenko --- xen/arch/arm/pci/pci-host-rcar-gen3.c | 69 +++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/xen/arch/arm/pci/pci-host-rcar-gen3.c b/xen/arch/arm/pci/pci-h= ost-rcar-gen3.c index ec14bb29a38b..353ac2bfd6e6 100644 --- a/xen/arch/arm/pci/pci-host-rcar-gen3.c +++ b/xen/arch/arm/pci/pci-host-rcar-gen3.c @@ -23,6 +23,7 @@ #include #include #include +#include =20 /* Error values that may be returned by PCI functions */ #define PCIBIOS_SUCCESSFUL 0x00 @@ -307,12 +308,80 @@ int pci_rcar_gen3_config_write(struct pci_host_bridge= *bridge, uint32_t _sbdf, return ret; } =20 +static void pci_rcar_gen3_hwbar_init(const struct pci_dev *pdev, + struct vpci_header *header) + +{ + static bool once =3D true; + struct vpci_bar *bars =3D header->bars; + unsigned int num_bars; + int i; + + /* Run only once. */ + if (!once) + return; + once =3D false; + + printk("\n\n ------------------------ %s -------------------\n", __fun= c__); + switch ( pci_conf_read8(pdev->sbdf, PCI_HEADER_TYPE) & 0x7f ) + { + case PCI_HEADER_TYPE_NORMAL: + num_bars =3D PCI_HEADER_NORMAL_NR_BARS; + break; + + case PCI_HEADER_TYPE_BRIDGE: + num_bars =3D PCI_HEADER_BRIDGE_NR_BARS; + break; + + default: + return; + } + + for ( i =3D 0; i < num_bars; i++ ) + { + uint8_t reg =3D PCI_BASE_ADDRESS_0 + i * 4; + + if ( bars[i].type =3D=3D VPCI_BAR_MEM64_HI ) + { + /* + * Skip hi part of the 64-bit register: it is read + * together with the lower part. + */ + continue; + } + + if ( bars[i].type =3D=3D VPCI_BAR_IO ) + { + /* Skip IO. */ + continue; + } + + if ( bars[i].type =3D=3D VPCI_BAR_MEM64_LO ) + { + /* Read both hi and lo parts of the 64-bit BAR. */ + bars[i].addr =3D + (uint64_t)pci_conf_read32(pdev->sbdf, reg + 4) << 32 | + pci_conf_read32(pdev->sbdf, reg); + } + else if ( bars[i].type =3D=3D VPCI_BAR_MEM32 ) + { + bars[i].addr =3D pci_conf_read32(pdev->sbdf, reg); + } + else + { + /* Expansion ROM? */ + continue; + } + } +} + /* R-Car Gen3 ops */ static struct pci_ecam_ops pci_rcar_gen3_ops =3D { .bus_shift =3D 20, /* FIXME: this is not used by RCar */ .pci_ops =3D { .read =3D pci_rcar_gen3_config_read, .write =3D pci_rcar_gen3_config_write, + .update_bar_header =3D pci_rcar_gen3_hwbar_init, } }; =20 --=20 2.17.1 From nobody Sat Nov 30 12:32:29 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=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1604926802; cv=none; d=zohomail.com; s=zohoarc; b=UnH+JJlQjVMvW3pPD1eE0MF/gMsVmrd1njgmXRPZ5V9mY3YZtSY8tcWTDsfPfYWKf9mTlTSMuDwucM+Nqtx9urcUC/gRkZfszh3wQdWP7UwO1gtYIualR/d428Z4gTbiwi4vaJGPSDzUO/pElRr5Uo0CJHw9NNg9ep0I37t79zM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604926802; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=LgLl6GM036W1KRVdmwK/U4Ej5BMvrSeEvhXdIuom+ac=; b=kVuWiw1EK23ftwz1J13z7X05lk8ys/SDKTWXGGjovtk+uXdmGj+Wzx9RAyUlGLwiE4g2HWSQyAVEFFnOOtZzp2TmUGrG/CWHD/9Rf3A63xj9756ZqIZJTdwCxTLX/H8ag78GTPJ5fJEYygXZQv8guo9iDU0QonIxwnl3MWm5BtA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1604926802795898.5741141442209; Mon, 9 Nov 2020 05:00:02 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.22530.48890 (Exim 4.92) (envelope-from ) id 1kc6lq-0005HW-Oi; Mon, 09 Nov 2020 12:59:42 +0000 Received: by outflank-mailman (output) from mailman id 22530.48890; Mon, 09 Nov 2020 12:59:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6lq-0005HP-Lf; Mon, 09 Nov 2020 12:59:42 +0000 Received: by outflank-mailman (input) for mailman id 22530; Mon, 09 Nov 2020 12:59:41 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dq-0003tf-HT for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:51:26 +0000 Received: from mail-lj1-x243.google.com (unknown [2a00:1450:4864:20::243]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 82cd251f-0a00-4bda-afad-5c275205e25e; Mon, 09 Nov 2020 12:50:46 +0000 (UTC) Received: by mail-lj1-x243.google.com with SMTP id s9so8391861ljo.11 for ; Mon, 09 Nov 2020 04:50:46 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:44 -0800 (PST) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kc6dq-0003tf-HT for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 12:51:26 +0000 Received: from mail-lj1-x243.google.com (unknown [2a00:1450:4864:20::243]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 82cd251f-0a00-4bda-afad-5c275205e25e; Mon, 09 Nov 2020 12:50:46 +0000 (UTC) Received: by mail-lj1-x243.google.com with SMTP id s9so8391861ljo.11 for ; Mon, 09 Nov 2020 04:50:46 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i1sm1736447lfr.176.2020.11.09.04.50.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 04:50:44 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 82cd251f-0a00-4bda-afad-5c275205e25e 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; bh=LgLl6GM036W1KRVdmwK/U4Ej5BMvrSeEvhXdIuom+ac=; b=iVAQBM0OfQj5dQiwPcEeoDLByL/4ourFSArcjdgeei6AGbR9xIJ9A6b1V7HKm4Sa1G 6CFmgvdfXlktq0S1j7o3FB+nxuUnNv13LHnW7nWGaD7A37gu5gowSHhDfeP6x5TwXooG h8DGnR36m1NMJUxH74sENUrm9yHZenghpc8Sbe87gsrDe0s984czdwWuN3wxA7/nRtMU eMYusiu0i0FP63MKqiNSFKmnZdTZWL465Ie/ggj2VLUR28u0HXtd+LFWQmX8Aqr32yJH svYFxvWVec3cKbaOJI46lOvsWbfsZkaC+8LWH9DEYGsOGHjkGXH2W7E3XZe/B4EsRbmS cwqQ== 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; bh=LgLl6GM036W1KRVdmwK/U4Ej5BMvrSeEvhXdIuom+ac=; b=g8f2/DTfwYzBF6jXtYvfbksz3V9YKuMmDvfPphjeXHG6lD8xHNVy0kxhIbbTLrOMUh K1jqBQHYEpmo0jlyyaEe9BQuxxGBwK9teGRyudV7zx+WZFCPuBYuXHspO+kaYWq5BwHy EPvC3BmCc+huB5Kz7aEcXtGx89zyHgXGDXCiqnCLQgePOY2iyJ40j5Q/cwjTgIbbpPMm vNDcjtYqanp9+biC3RpsnTZjhbJ1PIDJLeJUZ9ZGpl5NdMOwKo0WJGZu4KdT8qvqAYyz LM9D+GykJOk9AYvwvaPdAj2OaTzW+l7Vao8+9mF0NiYq6lUamzWmwmGn5/32OfW3HBgU rgtw== X-Gm-Message-State: AOAM530GcDFmANHKeM8zbGaOsOcyzLYaqUnwf0fu2u/hW/FMxHUtC1mj o5Q/lNhaE5LzqBACtCtT4y4= X-Google-Smtp-Source: ABdhPJy6R+2G+Qrko7GXDmhFwZ5TybTy9d9/cnVEZZCiAFf7wsNOj+yFYPCBcswfB0YeugnM8l8ntg== X-Received: by 2002:a2e:9ad0:: with SMTP id p16mr1347028ljj.424.1604926245382; Mon, 09 Nov 2020 04:50:45 -0800 (PST) From: Oleksandr Andrushchenko To: Rahul.Singh@arm.com, Bertrand.Marquis@arm.com, julien.grall@arm.com, jbeulich@suse.com, roger.pau@citrix.com, sstabellini@kernel.org, xen-devel@lists.xenproject.org Cc: iwj@xenproject.org, wl@xen.org, Oleksandr Andrushchenko Subject: [PATCH 10/10] [HACK] vpci/rcar: Make vPCI know DomD is hardware domain Date: Mon, 9 Nov 2020 14:50:31 +0200 Message-Id: <20201109125031.26409-11-andr2000@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201109125031.26409-1-andr2000@gmail.com> References: <20201109125031.26409-1-andr2000@gmail.com> X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko Signed-off-by: Oleksandr Andrushchenko --- xen/drivers/vpci/header.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 1f326c894d16..d5738ecca93d 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -34,13 +34,19 @@ struct map_data { struct pci_dev *pdev; }; =20 +static bool is_hardware_domain_DomD(const struct domain *d) +{ + return d->domain_id =3D=3D 1; +} + static struct vpci_header *get_vpci_header(struct domain *d, const struct pci_dev *pdev); =20 static struct vpci_header *get_hwdom_vpci_header(const struct pci_dev *pde= v) { + /* TODO: this should be for the hardware_domain, not current->domain. = */ if ( unlikely(list_empty(&pdev->vpci->headers)) ) - return get_vpci_header(hardware_domain, pdev); + return get_vpci_header(current->domain, pdev); =20 /* hwdom's header is always the very first entry. */ return list_first_entry(&pdev->vpci->headers, struct vpci_header, node= ); @@ -74,7 +80,7 @@ static struct vpci_header *get_vpci_header(struct domain = *d, return NULL; } =20 - if ( !is_hardware_domain(d) ) + if ( !is_hardware_domain_DomD(d) ) { struct vpci_header *hwdom_header =3D get_hwdom_vpci_header(pdev); #ifdef CONFIG_ARM @@ -304,7 +310,7 @@ static int modify_bars(const struct pci_dev *pdev, uint= 16_t cmd, bool rom_only) if ( !mem ) return -ENOMEM; =20 - if ( is_hardware_domain(current->domain) ) + if ( is_hardware_domain_DomD(current->domain) ) header =3D get_hwdom_vpci_header(pdev); else header =3D get_vpci_header(current->domain, pdev); @@ -641,7 +647,7 @@ static uint32_t bar_read_dispatch(const struct pci_dev = *pdev, unsigned int reg, { struct vpci_bar *vbar, *bar =3D data; =20 - if ( is_hardware_domain(current->domain) ) + if ( is_hardware_domain_DomD(current->domain) ) return bar_read_hwdom(pdev, reg, data); =20 vbar =3D get_vpci_bar(current->domain, pdev, bar->index); @@ -656,7 +662,7 @@ static void bar_write_dispatch(const struct pci_dev *pd= ev, unsigned int reg, { struct vpci_bar *bar =3D data; =20 - if ( is_hardware_domain(current->domain) ) + if ( is_hardware_domain_DomD(current->domain) ) bar_write_hwdom(pdev, reg, val, data); else { --=20 2.17.1