From nobody Sun May 19 11:06:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1591888585; cv=none; d=zohomail.com; s=zohoarc; b=mxYAJe/4MYJbxjbX2LI3hd8CeuqT0X9LnFUljnv1uJPO94+STF18Rs/EnbFWpzGMxnXTsrVNxBavBDW5CBL4xQxFVFz8MFDWBn/u4DIVlUddxNBjxPOfnKegNsLSHh386ylW5HGtajKjffglS2yJXvE53oO2NXyUl6ZrLFSurE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591888585; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BzIL894sotKgNVfIxuhlNLClyj4ig+qMlBQA2j5VmFI=; b=JqEG7airaYNQKGGxvdACPVfhqHGhV4RwXZDo/j5V35y4rO8vuKfRGTqXGkvtPtC5r9S/252BGy4zqEMgANOqItcJy+vRXh+c7wTQV9xQRJbtdgVwO8b8Z/AqcTqRvqzbSTD2Y3XoxxHOrZjlGHJPYRuj13s7zHBOm2RVALSgwPY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591888585896298.5160369592188; Thu, 11 Jun 2020 08:16:25 -0700 (PDT) Received: from localhost ([::1]:54334 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjOwI-0006gt-GD for importer@patchew.org; Thu, 11 Jun 2020 11:16:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51392) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjOse-0004ew-MR for qemu-devel@nongnu.org; Thu, 11 Jun 2020 11:12:37 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:54556 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jjOsZ-0003Sr-EB for qemu-devel@nongnu.org; Thu, 11 Jun 2020 11:12:34 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-1-dI14MvCLNmm3b-neVNbW4A-1; Thu, 11 Jun 2020 11:12:27 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7F6D9107ACCA; Thu, 11 Jun 2020 15:12:26 +0000 (UTC) Received: from laptop.redhat.com (ovpn-114-197.ams2.redhat.com [10.36.114.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03C978FF61; Thu, 11 Jun 2020 15:12:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591888349; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BzIL894sotKgNVfIxuhlNLClyj4ig+qMlBQA2j5VmFI=; b=B8/nmQ743GL4uvUi3W1Z6rPU9D/Cc/dUeH6bMk3ua7c8YTcsRpwDLscIviDBj70x2ZetFI laOrGH2ucAgOwGMP1OArFdOJKE6xBKdHIAZ/smnWqs/pzSch5y110TDTUq9jjCBlO4MFZ2 6s4OA+EfCX3UDyOAn71aX2vJJGs6l48= X-MC-Unique: dI14MvCLNmm3b-neVNbW4A-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, mst@redhat.com, armbru@redhat.com, pbonzini@redhat.com, jean-philippe@linaro.org, bbhushan2@marvell.com, peterx@redhat.com Subject: [PATCH v3 1/5] qdev: Introduce DEFINE_PROP_RESERVED_REGION Date: Thu, 11 Jun 2020 17:12:05 +0200 Message-Id: <20200611151209.22547-2-eric.auger@redhat.com> In-Reply-To: <20200611151209.22547-1-eric.auger@redhat.com> References: <20200611151209.22547-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.120; envelope-from=eric.auger@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/11 08:37:10 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Introduce a new property defining a reserved region: , , . This will be used to encode reserved IOVA regions. For instance, in virtio-iommu use case, reserved IOVA regions will be passed by the machine code to the virtio-iommu-pci device (an array of those). The type of the reserved region will match the virtio_iommu_probe_resv_mem subtype value: - VIRTIO_IOMMU_RESV_MEM_T_RESERVED (0) - VIRTIO_IOMMU_RESV_MEM_T_MSI (1) on PC/Q35 machine, this will be used to inform the virtio-iommu-pci device it should bypass the MSI region. The reserved region will be: 0xfee00000, 0xfeefffff, 1. On ARM, we can declare the ITS MSI doorbell as an MSI region to prevent MSIs from being mapped on guest side. Signed-off-by: Eric Auger Reviewed-by: Markus Armbruster --- v11 -> v12: - rename into DEFINE_PROP_RESERVED_REGION - do not use g_strsplit anymore, use endptr instead - remove 0x references --- include/exec/memory.h | 6 +++ include/hw/qdev-properties.h | 3 ++ include/qemu/typedefs.h | 1 + hw/core/qdev-properties.c | 89 ++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 3e00cdbbfa..3ee8224fa7 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -57,6 +57,12 @@ struct MemoryRegionMmio { CPUWriteMemoryFunc *write[3]; }; =20 +struct ReservedRegion { + hwaddr low; + hwaddr high; + unsigned int type; +}; + typedef struct IOMMUTLBEntry IOMMUTLBEntry; =20 /* See address_space_translate: bit 0 is read, bit 1 is write. */ diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index f161604fb6..03bf850a7e 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -19,6 +19,7 @@ extern const PropertyInfo qdev_prop_string; extern const PropertyInfo qdev_prop_chr; extern const PropertyInfo qdev_prop_tpm; extern const PropertyInfo qdev_prop_macaddr; +extern const PropertyInfo qdev_prop_reserved_region; extern const PropertyInfo qdev_prop_on_off_auto; extern const PropertyInfo qdev_prop_multifd_compression; extern const PropertyInfo qdev_prop_losttickpolicy; @@ -183,6 +184,8 @@ extern const PropertyInfo qdev_prop_pcie_link_width; DEFINE_PROP(_n, _s, _f, qdev_prop_drive_iothread, BlockBackend *) #define DEFINE_PROP_MACADDR(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr) +#define DEFINE_PROP_RESERVED_REGION(_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_reserved_region, ReservedRegion) #define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \ DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto) #define DEFINE_PROP_MULTIFD_COMPRESSION(_n, _s, _f, _d) \ diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index ecf3cde26c..85c4f891f4 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -59,6 +59,7 @@ typedef struct ISABus ISABus; typedef struct ISADevice ISADevice; typedef struct IsaDma IsaDma; typedef struct MACAddr MACAddr; +typedef struct ReservedRegion ReservedRegion; typedef struct MachineClass MachineClass; typedef struct MachineState MachineState; typedef struct MemoryListener MemoryListener; diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index cc924815da..15b84adbee 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -14,6 +14,7 @@ #include "qapi/visitor.h" #include "chardev/char.h" #include "qemu/uuid.h" +#include "qemu/cutils.h" =20 void qdev_prop_set_after_realize(DeviceState *dev, const char *name, Error **errp) @@ -577,6 +578,94 @@ const PropertyInfo qdev_prop_macaddr =3D { .set =3D set_mac, }; =20 +/* --- Reserved Region --- */ + +/* + * accepted syntax version: + * ,, + * where low/high addresses are uint64_t in hexadecimal + * and type is an unsigned integer in decimal + */ +static void get_reserved_region(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + DeviceState *dev =3D DEVICE(obj); + Property *prop =3D opaque; + ReservedRegion *rr =3D qdev_get_prop_ptr(dev, prop); + char buffer[64]; + char *p =3D buffer; + + snprintf(buffer, sizeof(buffer), "0x%"PRIx64",0x%"PRIx64",%u", + rr->low, rr->high, rr->type); + + visit_type_str(v, name, &p, errp); +} + +static void set_reserved_region(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + DeviceState *dev =3D DEVICE(obj); + Property *prop =3D opaque; + ReservedRegion *rr =3D qdev_get_prop_ptr(dev, prop); + Error *local_err =3D NULL; + const char *endptr; + char *str; + int ret; + + if (dev->realized) { + qdev_prop_set_after_realize(dev, name, errp); + return; + } + + visit_type_str(v, name, &str, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + ret =3D qemu_strtou64(str, &endptr, 16, &rr->low); + if (ret) { + error_setg(errp, "Failed to decode reserved region low addr"); + error_append_hint(errp, + "should be an address in hexadecimal\n"); + goto out; + } + if (*endptr !=3D ',') { + goto separator_error; + } + + ret =3D qemu_strtou64(endptr + 1, &endptr, 16, &rr->high); + if (ret) { + error_setg(errp, "Failed to decode reserved region high addr"); + error_append_hint(errp, + "should be an address in hexadecimal\n"); + goto out; + } + if (*endptr !=3D ',') { + goto separator_error; + } + + ret =3D qemu_strtoui(endptr + 1, &endptr, 10, &rr->type); + if (ret) { + error_setg(errp, "Failed to decode reserved region type"); + error_append_hint(errp, "should be an unsigned integer in decimal\= n"); + } + goto out; + +separator_error: + error_setg(errp, "reserved region fields must be separated with commas= "); +out: + g_free(str); + return; +} + +const PropertyInfo qdev_prop_reserved_region =3D { + .name =3D "reserved_region", + .description =3D "Reserved Region, example: 0xFEE00000,0xFEEFFFFF,0", + .get =3D get_reserved_region, + .set =3D set_reserved_region, +}; + /* --- on/off/auto --- */ =20 const PropertyInfo qdev_prop_on_off_auto =3D { --=20 2.20.1 From nobody Sun May 19 11:06:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1591888752; cv=none; d=zohomail.com; s=zohoarc; b=hDmcJ+OhOY3gw23iPLOylEcNxG74Ino1dqFI0Ec6p9Ld+mv8NfgykJsf9VW/EOb9DK++JAZYq6mCQyICCKf2gHcKt+Nft4Izg/dHygDPDHYWuDl5F5w5cUX/qDZNhvUMNUrerdFcDfp9dOELBcjGiLALa/WFpI4oqNnLy083v2k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591888752; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EG9/EteMQ7YFZhz4LAPnTuvoSkpBzI4tpCBXknkBiuI=; b=aMH6ddn+l+mxp+M7O00BV9+ep4MMo2ztKAKEeyOLwZmU7GHSSv7KoyGg49B6/jBBBB9lhIGEmPKIwtVEB7RrUHffwTh0B9aRkG7fbiSz9Hqji4wYCQJD16UwztT/xDVCT09GvOQrMCxzHC1gC1hCslREzQz3y1fXh8OPtsgnM8M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591888752377873.8837972197375; Thu, 11 Jun 2020 08:19:12 -0700 (PDT) Received: from localhost ([::1]:58720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjOz0-0000yT-Ub for importer@patchew.org; Thu, 11 Jun 2020 11:19:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjOsk-0004iK-T5 for qemu-devel@nongnu.org; Thu, 11 Jun 2020 11:12:43 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:34430 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jjOsg-0003U2-Tr for qemu-devel@nongnu.org; Thu, 11 Jun 2020 11:12:42 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-9-WKoxITT1MFO-IuEYh2XM6Q-1; Thu, 11 Jun 2020 11:12:30 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8D9FC461; Thu, 11 Jun 2020 15:12:29 +0000 (UTC) Received: from laptop.redhat.com (ovpn-114-197.ams2.redhat.com [10.36.114.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE91F8FF61; Thu, 11 Jun 2020 15:12:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591888356; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EG9/EteMQ7YFZhz4LAPnTuvoSkpBzI4tpCBXknkBiuI=; b=bbrHs7OkvvONHiizZJXBRYL19GsCC44FRSCAnXgqvftWNQEukDYcct9uv828cNPEmdYJb0 iYPRQ21jcTkgeyjPfdrEgplA31yT9090R1C2fwrrYxGmK2OR5/qhI9YlMWtcLO+tBMD0EO QadicBGpZBb8eeJONVxI8kGKJOnAYSU= X-MC-Unique: WKoxITT1MFO-IuEYh2XM6Q-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, mst@redhat.com, armbru@redhat.com, pbonzini@redhat.com, jean-philippe@linaro.org, bbhushan2@marvell.com, peterx@redhat.com Subject: [PATCH v3 2/5] virtio-iommu: Implement RESV_MEM probe request Date: Thu, 11 Jun 2020 17:12:06 +0200 Message-Id: <20200611151209.22547-3-eric.auger@redhat.com> In-Reply-To: <20200611151209.22547-1-eric.auger@redhat.com> References: <20200611151209.22547-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.120; envelope-from=eric.auger@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/11 08:37:10 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This patch implements the PROBE request. At the moment, only THE RESV_MEM property is handled. The first goal is to report iommu wide reserved regions such as the MSI regions set by the machine code. On x86 this will be the IOAPIC MSI region, [0xFEE00000 - 0xFEEFFFFF], on ARM this may be the ITS doorbell. In the future we may introduce per device reserved regions. This will be useful when protecting host assigned devices which may expose their own reserved regions Signed-off-by: Eric Auger Reviewed-by: Jean-Philippe Brucker --- v2 -> v3: - on probe, do not fill the reminder of the buffer with zeroes as the buffer was already zero initialized (Bharat) v1 -> v2: - move the unlock back to the same place - remove the push label and factorize the code after the out label - fix a bunch of cpu_to_leX according to the latest spec revision - do not remove sizeof(last) from free space - check the ep exists --- include/hw/virtio/virtio-iommu.h | 2 + hw/virtio/virtio-iommu.c | 91 ++++++++++++++++++++++++++++++-- hw/virtio/trace-events | 1 + 3 files changed, 90 insertions(+), 4 deletions(-) diff --git a/include/hw/virtio/virtio-iommu.h b/include/hw/virtio/virtio-io= mmu.h index e653004d7c..49eb105cd8 100644 --- a/include/hw/virtio/virtio-iommu.h +++ b/include/hw/virtio/virtio-iommu.h @@ -53,6 +53,8 @@ typedef struct VirtIOIOMMU { GHashTable *as_by_busptr; IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX]; PCIBus *primary_bus; + ReservedRegion *reserved_regions; + uint32_t nb_reserved_regions; GTree *domains; QemuMutex mutex; GTree *endpoints; diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 483883ec1d..be1527c1d6 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -38,6 +38,7 @@ =20 /* Max size */ #define VIOMMU_DEFAULT_QUEUE_SIZE 256 +#define VIOMMU_PROBE_SIZE 512 =20 typedef struct VirtIOIOMMUDomain { uint32_t id; @@ -378,6 +379,62 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s, return ret; } =20 +static ssize_t virtio_iommu_fill_resv_mem_prop(VirtIOIOMMU *s, uint32_t ep, + uint8_t *buf, size_t free) +{ + struct virtio_iommu_probe_resv_mem prop =3D {}; + size_t size =3D sizeof(prop), length =3D size - sizeof(prop.head), tot= al; + int i; + + total =3D size * s->nb_reserved_regions; + + if (total > free) { + return -ENOSPC; + } + + for (i =3D 0; i < s->nb_reserved_regions; i++) { + prop.head.type =3D cpu_to_le16(VIRTIO_IOMMU_PROBE_T_RESV_MEM); + prop.head.length =3D cpu_to_le16(length); + prop.subtype =3D s->reserved_regions[i].type; + prop.start =3D cpu_to_le64(s->reserved_regions[i].low); + prop.end =3D cpu_to_le64(s->reserved_regions[i].high); + + memcpy(buf, &prop, size); + + trace_virtio_iommu_fill_resv_property(ep, prop.subtype, + prop.start, prop.end); + buf +=3D size; + } + return total; +} + +/** + * virtio_iommu_probe - Fill the probe request buffer with + * the properties the device is able to return and add a NONE + * property at the end. + */ +static int virtio_iommu_probe(VirtIOIOMMU *s, + struct virtio_iommu_req_probe *req, + uint8_t *buf) +{ + uint32_t ep_id =3D le32_to_cpu(req->endpoint); + size_t free =3D VIOMMU_PROBE_SIZE; + ssize_t count; + + if (!virtio_iommu_mr(s, ep_id)) { + return VIRTIO_IOMMU_S_NOENT; + } + + count =3D virtio_iommu_fill_resv_mem_prop(s, ep_id, buf, free); + if (count < 0) { + return VIRTIO_IOMMU_S_INVAL; + } + buf +=3D count; + free -=3D count; + + return VIRTIO_IOMMU_S_OK; +} + static int virtio_iommu_iov_to_req(struct iovec *iov, unsigned int iov_cnt, void *req, size_t req_sz) @@ -407,15 +464,27 @@ virtio_iommu_handle_req(detach) virtio_iommu_handle_req(map) virtio_iommu_handle_req(unmap) =20 +static int virtio_iommu_handle_probe(VirtIOIOMMU *s, + struct iovec *iov, + unsigned int iov_cnt, + uint8_t *buf) +{ + struct virtio_iommu_req_probe req; + int ret =3D virtio_iommu_iov_to_req(iov, iov_cnt, &req, sizeof(req)); + + return ret ? ret : virtio_iommu_probe(s, &req, buf); +} + static void virtio_iommu_handle_command(VirtIODevice *vdev, VirtQueue *vq) { VirtIOIOMMU *s =3D VIRTIO_IOMMU(vdev); struct virtio_iommu_req_head head; struct virtio_iommu_req_tail tail =3D {}; + size_t output_size =3D sizeof(tail), sz; VirtQueueElement *elem; unsigned int iov_cnt; struct iovec *iov; - size_t sz; + void *buf =3D NULL; =20 for (;;) { elem =3D virtqueue_pop(vq, sizeof(VirtQueueElement)); @@ -452,6 +521,17 @@ static void virtio_iommu_handle_command(VirtIODevice *= vdev, VirtQueue *vq) case VIRTIO_IOMMU_T_UNMAP: tail.status =3D virtio_iommu_handle_unmap(s, iov, iov_cnt); break; + case VIRTIO_IOMMU_T_PROBE: + { + struct virtio_iommu_req_tail *ptail; + + output_size =3D s->config.probe_size + sizeof(tail); + buf =3D g_malloc0(output_size); + + ptail =3D (struct virtio_iommu_req_tail *) + (buf + s->config.probe_size); + ptail->status =3D virtio_iommu_handle_probe(s, iov, iov_cnt, b= uf); + } default: tail.status =3D VIRTIO_IOMMU_S_UNSUPP; } @@ -459,12 +539,13 @@ static void virtio_iommu_handle_command(VirtIODevice = *vdev, VirtQueue *vq) =20 out: sz =3D iov_from_buf(elem->in_sg, elem->in_num, 0, - &tail, sizeof(tail)); - assert(sz =3D=3D sizeof(tail)); + buf ? buf : &tail, output_size); + assert(sz =3D=3D output_size); =20 - virtqueue_push(vq, elem, sizeof(tail)); + virtqueue_push(vq, elem, sz); virtio_notify(vdev, vq); g_free(elem); + g_free(buf); } } =20 @@ -667,6 +748,7 @@ static void virtio_iommu_device_realize(DeviceState *de= v, Error **errp) s->config.page_size_mask =3D TARGET_PAGE_MASK; s->config.input_range.end =3D -1UL; s->config.domain_range.end =3D 32; + s->config.probe_size =3D VIOMMU_PROBE_SIZE; =20 virtio_add_feature(&s->features, VIRTIO_RING_F_EVENT_IDX); virtio_add_feature(&s->features, VIRTIO_RING_F_INDIRECT_DESC); @@ -676,6 +758,7 @@ static void virtio_iommu_device_realize(DeviceState *de= v, Error **errp) virtio_add_feature(&s->features, VIRTIO_IOMMU_F_MAP_UNMAP); virtio_add_feature(&s->features, VIRTIO_IOMMU_F_BYPASS); virtio_add_feature(&s->features, VIRTIO_IOMMU_F_MMIO); + virtio_add_feature(&s->features, VIRTIO_IOMMU_F_PROBE); =20 qemu_mutex_init(&s->mutex); =20 diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 6427a0047d..23109f69bb 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -74,3 +74,4 @@ virtio_iommu_get_domain(uint32_t domain_id) "Alloc domain= =3D%d" virtio_iommu_put_domain(uint32_t domain_id) "Free domain=3D%d" virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_= t sid) "0x%"PRIx64" -> 0x%"PRIx64 " for sid=3D%d" virtio_iommu_report_fault(uint8_t reason, uint32_t flags, uint32_t endpoin= t, uint64_t addr) "FAULT reason=3D%d flags=3D%d endpoint=3D%d address =3D0x= %"PRIx64 +virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t = start, uint64_t end) "dev=3D %d, type=3D%d start=3D0x%"PRIx64" end=3D0x%"PR= Ix64 --=20 2.20.1 From nobody Sun May 19 11:06:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1591888954; cv=none; d=zohomail.com; s=zohoarc; b=mitsNAKWiB22dERHx9+N4T7cg16bnbgmBFS1ctCzjlFz3xmjqeIBICWNjIk95JW7pi5/c8u2rNum9pcK9J7BBA6yVm7GrYx548Z7C+HBJR5yhx8uqWuRxeAxDiTrbuH/5RXqZZ2ZSZCqoyvzhJC8uNyjLxRiWNOYkqfuAmza7Fk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591888954; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Szx7mFHhdUv+8B7blyxvd05ss7JydUiFKHj0I95qeOM=; b=X8LHhjMTzZIRTKWOEybEc57p71enWdFi3pZ7+VMgwZGPfhNO3xKc0Z/3ZA+cKCJey+WGXwmbL7ePY3PVi9cgk/wLccOEW2yiHUbViRONzpwqqp+Y7THQD+ntVQMaw+BFHaA8CrX+HX/FDcnqjlx5NmBO1upwUaG9AeXrPd6zzh0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591888954237744.5571517460442; Thu, 11 Jun 2020 08:22:34 -0700 (PDT) Received: from localhost ([::1]:38048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjP2G-00066c-Iy for importer@patchew.org; Thu, 11 Jun 2020 11:22:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjOsl-0004ir-7p for qemu-devel@nongnu.org; Thu, 11 Jun 2020 11:12:43 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:30149 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jjOsg-0003Tv-60 for qemu-devel@nongnu.org; Thu, 11 Jun 2020 11:12:42 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-120-MaC6aQJiN5qnnWVroscO7A-1; Thu, 11 Jun 2020 11:12:34 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE2A0835B43; Thu, 11 Jun 2020 15:12:32 +0000 (UTC) Received: from laptop.redhat.com (ovpn-114-197.ams2.redhat.com [10.36.114.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id E51948FF81; Thu, 11 Jun 2020 15:12:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591888355; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Szx7mFHhdUv+8B7blyxvd05ss7JydUiFKHj0I95qeOM=; b=U3BA4MzqqGI5RvrgAVcwZAlpya9WjV5o/MO+7OPXe5blaASk6b35FcnpW3pFbHo+csXrBq ntna0z1RhK5PvMkZayPpb4h/7+cm3Zti2zeAvpr07exL8N4QVR8nfMNjtw6d4RCXCOZVpk Oz/INqh6jric3RnOKzjDwASru7z4AH8= X-MC-Unique: MaC6aQJiN5qnnWVroscO7A-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, mst@redhat.com, armbru@redhat.com, pbonzini@redhat.com, jean-philippe@linaro.org, bbhushan2@marvell.com, peterx@redhat.com Subject: [PATCH v3 3/5] virtio-iommu: Handle reserved regions in the translation process Date: Thu, 11 Jun 2020 17:12:07 +0200 Message-Id: <20200611151209.22547-4-eric.auger@redhat.com> In-Reply-To: <20200611151209.22547-1-eric.auger@redhat.com> References: <20200611151209.22547-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.120; envelope-from=eric.auger@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/11 03:29:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" When translating an address we need to check if it belongs to a reserved virtual address range. If it does, there are 2 cases: - it belongs to a RESERVED region: the guest should neither use this address in a MAP not instruct the end-point to DMA on them. We report an error - It belongs to an MSI region: we bypass the translation. Signed-off-by: Eric Auger Reviewed-by: Peter Xu Reviewed-by: Jean-Philippe Brucker --- v1 -> v2: - use addr when testing addr belongs to the reserved region and use a block local variable --- hw/virtio/virtio-iommu.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index be1527c1d6..03535a6a14 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -604,6 +604,7 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemory= Region *mr, hwaddr addr, uint32_t sid, flags; bool bypass_allowed; bool found; + int i; =20 interval.low =3D addr; interval.high =3D addr + 1; @@ -637,6 +638,25 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemor= yRegion *mr, hwaddr addr, goto unlock; } =20 + for (i =3D 0; i < s->nb_reserved_regions; i++) { + ReservedRegion *reg =3D &s->reserved_regions[i]; + + if (addr >=3D reg->low && addr <=3D reg->high) { + switch (reg->type) { + case VIRTIO_IOMMU_RESV_MEM_T_MSI: + entry.perm =3D flag; + break; + case VIRTIO_IOMMU_RESV_MEM_T_RESERVED: + default: + virtio_iommu_report_fault(s, VIRTIO_IOMMU_FAULT_R_MAPPING, + VIRTIO_IOMMU_FAULT_F_ADDRESS, + sid, addr); + break; + } + goto unlock; + } + } + if (!ep->domain) { if (!bypass_allowed) { error_report_once("%s %02x:%02x.%01x not attached to any domai= n", --=20 2.20.1 From nobody Sun May 19 11:06:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1591888815; cv=none; d=zohomail.com; s=zohoarc; b=BWdYk+LIp+fIZBenT2ayyBa2vOYomQ4gOJkbMSSZujRdWKzWgKF7occgV4GYa1Z8IcqEFizRlnGpUYXNAJUSWP9rF57UDUlyGRvK6KhaQz5KqAb6ol4EdGb+WTkBAXz2JDR/7Hg8Mh2dbhKYc2JxUVY10qdtZ+kVwsUmG/++uNY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591888815; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WCTTBivJXDHLFnK3lN4w62tWJmBEn8J2JUhNXMMZ4lA=; b=lzoLcfPDVWrtz3Hq2p1pei+xBxefJQ1DymOlPKka6/CvoPFUpLQ+U62bkJBJePaZZm84QfkpxMUVNmiAG7+Nlxij8tGNTqNLAqaHTpA7EHYeGR8Ar6LCMpKoqxKQ+UePLCdDUaBLso9YTkAhK/ncvb+th7iJ0ZaKe9XgrlDzWrc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159188881597766.86902501035956; Thu, 11 Jun 2020 08:20:15 -0700 (PDT) Received: from localhost ([::1]:34066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjP02-0003dF-JY for importer@patchew.org; Thu, 11 Jun 2020 11:20:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjOss-0004sP-0P for qemu-devel@nongnu.org; Thu, 11 Jun 2020 11:12:50 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:26410 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jjOsp-0003YL-Na for qemu-devel@nongnu.org; Thu, 11 Jun 2020 11:12:49 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-46-EHOCoz0FO8-FPWo1FatYIQ-1; Thu, 11 Jun 2020 11:12:45 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D73341005512; Thu, 11 Jun 2020 15:12:43 +0000 (UTC) Received: from laptop.redhat.com (ovpn-114-197.ams2.redhat.com [10.36.114.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E6D38FF61; Thu, 11 Jun 2020 15:12:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591888366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WCTTBivJXDHLFnK3lN4w62tWJmBEn8J2JUhNXMMZ4lA=; b=Ho3SzpFvC/uicabY1l9nVb+G3m//yXUkZGl+h6YL8M3FPcmHkotB/7DBpeCc+H7f6LMENZ mVXd+sbaYrEDclXQ862MsnjunU3mNFgyYyiwbR3rF0BcxWIJsvZsD6jdHB4NbEKaxpxi3R 2PAbp23V8ZUruLCD77XMoHy9G1EqFRw= X-MC-Unique: EHOCoz0FO8-FPWo1FatYIQ-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, mst@redhat.com, armbru@redhat.com, pbonzini@redhat.com, jean-philippe@linaro.org, bbhushan2@marvell.com, peterx@redhat.com Subject: [PATCH v3 4/5] virtio-iommu-pci: Add array of Interval properties Date: Thu, 11 Jun 2020 17:12:08 +0200 Message-Id: <20200611151209.22547-5-eric.auger@redhat.com> In-Reply-To: <20200611151209.22547-1-eric.auger@redhat.com> References: <20200611151209.22547-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/11 03:29:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The machine may need to pass reserved regions to the virtio-iommu-pci device (such as the MSI window on x86). So let's add an array of Interval properties. Signed-off-by: Eric Auger Reviewed-by: Jean-Philippe Brucker --- v12 -> v12: - added Jean's R-b --- hw/virtio/virtio-iommu-pci.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/virtio/virtio-iommu-pci.c b/hw/virtio/virtio-iommu-pci.c index 3dfbf55b47..44ae9ebc11 100644 --- a/hw/virtio/virtio-iommu-pci.c +++ b/hw/virtio/virtio-iommu-pci.c @@ -33,6 +33,9 @@ struct VirtIOIOMMUPCI { =20 static Property virtio_iommu_pci_properties[] =3D { DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0), + DEFINE_PROP_ARRAY("reserved-regions", VirtIOIOMMUPCI, + vdev.nb_reserved_regions, vdev.reserved_regions, + qdev_prop_reserved_region, ReservedRegion), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.20.1 From nobody Sun May 19 11:06:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1591889028; cv=none; d=zohomail.com; s=zohoarc; b=S2UmAyn5FD+FJqbHtI2vUnYet7N0/2u1XNeMKUYOrgxzOGuXgsHWWuFzzDpiOO57GVcmNDHUryBPTWAE64sdv2I/SPA4zbRG8S2btLxRa2l3/fz82oi/uQTusuVAPXBSqJIAnwJCUSkk2hGWk4RXMktdxErdwrOauFWa3e7ltro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591889028; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=etSKwmHIuRxmvuLy4Ysxortsu0bSspOTDF7irDUHZ+c=; b=VTALPVGPQDl2Oo5CbDWhJxIygCuJ/r8j4lXEilEtebPNrPPrRBaV0qzOYvn7QG6hsIyb5oxO3EKrjvfyStbTpWOKq9X9MT8R6WToq1H5/kdv7lRofcF5tc+QdH6hIrg5r7znd8FCSkSaTgzVl8C48w9yTIsf1a3e49Ww5NFd3gk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591889028618552.3392769011142; Thu, 11 Jun 2020 08:23:48 -0700 (PDT) Received: from localhost ([::1]:41650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjP3T-0007ec-CQ for importer@patchew.org; Thu, 11 Jun 2020 11:23:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjOsu-0004vP-Hr for qemu-devel@nongnu.org; Thu, 11 Jun 2020 11:12:56 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:58659 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jjOss-0003Zz-Gh for qemu-devel@nongnu.org; Thu, 11 Jun 2020 11:12:51 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-335-lvXWdkubOgusbROoqBEFAQ-1; Thu, 11 Jun 2020 11:12:48 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ECB681009610; Thu, 11 Jun 2020 15:12:46 +0000 (UTC) Received: from laptop.redhat.com (ovpn-114-197.ams2.redhat.com [10.36.114.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 452FF8FF81; Thu, 11 Jun 2020 15:12:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591888369; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=etSKwmHIuRxmvuLy4Ysxortsu0bSspOTDF7irDUHZ+c=; b=DcKQlFI20Z9l2eAHTleIE1YvWfVZuldE3WEUcNYSEj5Hj3f3KBjSu/zjF2DuPzdjqsM6Xo oLiAwY6o1ZCnz/jyTdcGbb4vJCcjFxxiou8MTjvcoPDQ2k354kdAqHZgszilF9+6RH05dn Z6slT4cab3PPslF7aQICp5SZ2HXY1EM= X-MC-Unique: lvXWdkubOgusbROoqBEFAQ-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, mst@redhat.com, armbru@redhat.com, pbonzini@redhat.com, jean-philippe@linaro.org, bbhushan2@marvell.com, peterx@redhat.com Subject: [PATCH v3 5/5] hw/arm/virt: Let the virtio-iommu bypass MSIs Date: Thu, 11 Jun 2020 17:12:09 +0200 Message-Id: <20200611151209.22547-6-eric.auger@redhat.com> In-Reply-To: <20200611151209.22547-1-eric.auger@redhat.com> References: <20200611151209.22547-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.120; envelope-from=eric.auger@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/11 08:37:10 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" At the moment the virtio-iommu translates MSI transactions. This behavior is inherited from ARM SMMU. The virt machine code knows where the guest MSI doorbells are so we can easily declare those regions as VIRTIO_IOMMU_RESV_MEM_T_MSI. With that setting the guest will not map MSIs through the IOMMU and those transactions will be simply bypassed. Depending on which MSI controller is in use (ITS or GICV2M), we declare either: - the ITS interrupt translation space (ITS_base + 0x10000), containing the GITS_TRANSLATOR or - The GICV2M single frame, containing the MSI_SETSP_NS register. Signed-off-by: Eric Auger Reviewed-by: Jean-Philippe Brucker --- v2 -> v3: - Add a new value to VirtMSIControllerType v1 -> v2: - Test which MSI controller is instantiated - If GICV2M is in use, declare its doorbell as an MSI doorbell too --- include/hw/arm/virt.h | 7 +++++++ hw/arm/virt.c | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 31878ddc72..a18b6b397b 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -96,6 +96,12 @@ typedef enum VirtIOMMUType { VIRT_IOMMU_VIRTIO, } VirtIOMMUType; =20 +typedef enum VirtMSIControllerType { + VIRT_MSI_CTRL_NONE, + VIRT_MSI_CTRL_GICV2M, + VIRT_MSI_CTRL_ITS, +} VirtMSIControllerType; + typedef enum VirtGICType { VIRT_GIC_VERSION_MAX, VIRT_GIC_VERSION_HOST, @@ -136,6 +142,7 @@ typedef struct { OnOffAuto acpi; VirtGICType gic_version; VirtIOMMUType iommu; + VirtMSIControllerType msi_controller; uint16_t virtio_iommu_bdf; struct arm_boot_info bootinfo; MemMapEntry *memmap; diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 37462a6f78..451b150459 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -602,6 +602,7 @@ static void create_its(VirtMachineState *vms) sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, vms->memmap[VIRT_GIC_ITS].base= ); =20 fdt_add_its_gic_node(vms); + vms->msi_controller =3D VIRT_MSI_CTRL_ITS; } =20 static void create_v2m(VirtMachineState *vms) @@ -622,6 +623,7 @@ static void create_v2m(VirtMachineState *vms) } =20 fdt_add_v2m_gic_node(vms); + vms->msi_controller =3D VIRT_MSI_CTRL_GICV2M; } =20 static void create_gic(VirtMachineState *vms) @@ -2149,8 +2151,24 @@ out: static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + VirtMachineState *vms =3D VIRT_MACHINE(hotplug_dev); + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { virt_memory_pre_plug(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { + /* we declare a VIRTIO_IOMMU_RESV_MEM_T_MSI region */ + + if (vms->msi_controller =3D=3D VIRT_MSI_CTRL_ITS) { + /* GITS_TRANSLATER page */ + qdev_prop_set_uint32(dev, "len-reserved-regions", 1); + qdev_prop_set_string(dev, "reserved-regions[0]", + "0x8090000, 0x809FFFF, 1"); + } else if (vms->msi_controller =3D=3D VIRT_MSI_CTRL_GICV2M) { + /* MSI_SETSPI_NS page */ + qdev_prop_set_uint32(dev, "len-reserved-regions", 1); + qdev_prop_set_string(dev, "reserved-regions[0]", + "0x8020000, 0x8020FFF, 1"); + } } } =20 --=20 2.20.1