From nobody Mon May 6 01:38:38 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=1593005302; cv=none; d=zohomail.com; s=zohoarc; b=j8uFm3LiXoAvuWh6Dj+2caS6axa/LoAszPIPbmglpRoFh8r/UhREdyDdXqy2n/OEWET5stUs93t7/0U9252JOQb/lbxV4L47xh/AS/RZnJWSz/Yro8aLlBuSU1URvC99DL+fKMfayp6dKrIdRdme9Pud3NWatbjslpJtCZY0Wcw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593005302; 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=WAK/W84jAur/PUSfA1VCWzUZ02CpgS7V7bmvGIOqIRM=; b=XItZGeY7+LXIhyNXUhYLYYIU9o8PEZi+3GQGlIv7z5GXAJEdBujG0z50CmelnIKTp6ylf/RPBZEg+9aRBQRIdqIT7bkEpdwH748etHKZ/ukH0USpd2qSXEQo4gUBxlv76i2R19zplh3hDNAmNs/toH0+5lfdgl26WybKwJg6efY= 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 1593005302814128.5447718457749; Wed, 24 Jun 2020 06:28:22 -0700 (PDT) Received: from localhost ([::1]:40040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jo5Rt-0000is-0S for importer@patchew.org; Wed, 24 Jun 2020 09:28:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46702) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jo5Qs-0007jx-Rl for qemu-devel@nongnu.org; Wed, 24 Jun 2020 09:27:18 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:32257 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 1jo5QL-0001dX-IE for qemu-devel@nongnu.org; Wed, 24 Jun 2020 09:27:18 -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-266-REU7tnYpNke1YbA8jn0X1Q-1; Wed, 24 Jun 2020 09:26:43 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B7DEE19067E1; Wed, 24 Jun 2020 13:26:41 +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 4979D10016DA; Wed, 24 Jun 2020 13:26:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593005204; 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=WAK/W84jAur/PUSfA1VCWzUZ02CpgS7V7bmvGIOqIRM=; b=glpFbf/Zpw6JANJc9dZqGHgpq/C36PB7/5rX8JK7guPKsXj5X9v2z9O2mwn8g4SuD75lxO RKxfPyUK9EvBLwKrjWolHjcCZiMIAOB7HOFMBnv3yK7RvDfEtfv+hPhRdNgC/o/lx8ZLI1 2PLgSQwGG5HEPN5EOlLl6AISaXe6E/M= X-MC-Unique: REU7tnYpNke1YbA8jn0X1Q-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 v5 1/5] qdev: Introduce DEFINE_PROP_RESERVED_REGION Date: Wed, 24 Jun 2020 15:26:21 +0200 Message-Id: <20200624132625.27453-2-eric.auger@redhat.com> In-Reply-To: <20200624132625.27453-1-eric.auger@redhat.com> References: <20200624132625.27453-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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/24 00:34:35 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 Reviewed-by: Michael S. Tsirkin --- v4 -> v5: - type becomes an unsigned + comment/error rewording v3 -> v4: - use ':' instead of commas as separators. - rearrange error messages - check snprintf returned value - dared to keep Markus' R-b despite those changes --- 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 7207025bd4..84ee5b7a01 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -51,6 +51,12 @@ extern bool global_dirty_log; =20 typedef struct MemoryRegionOps MemoryRegionOps; =20 +struct ReservedRegion { + hwaddr low; + hwaddr high; + unsigned 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 5252bb6b1a..95d0e7201d 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; @@ -184,6 +185,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 ce4a78b687..15f5047bf1 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -58,6 +58,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 ead35d7ffd..55d06b1021 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -15,6 +15,7 @@ #include "chardev/char.h" #include "qemu/uuid.h" #include "qemu/units.h" +#include "qemu/cutils.h" =20 void qdev_prop_set_after_realize(DeviceState *dev, const char *name, Error **errp) @@ -578,6 +579,94 @@ const PropertyInfo qdev_prop_macaddr =3D { .set =3D set_mac, }; =20 +/* --- Reserved Region --- */ + +/* + * Accepted syntax: + * :: + * where low/high addresses are uint64_t in hexadecimal + * and type is a non-negative decimal integer + */ +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; + int rc; + + rc =3D snprintf(buffer, sizeof(buffer), "0x%"PRIx64":0x%"PRIx64":%u", + rr->low, rr->high, rr->type); + assert(rc < sizeof(buffer)); + + 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, "start address of '%s'" + " must be a hexadecimal integer", name); + goto out; + } + if (*endptr !=3D ':') { + goto separator_error; + } + + ret =3D qemu_strtou64(endptr + 1, &endptr, 16, &rr->high); + if (ret) { + error_setg(errp, "end address of '%s'" + " must be a hexadecimal integer", name); + goto out; + } + if (*endptr !=3D ':') { + goto separator_error; + } + + ret =3D qemu_strtoui(endptr + 1, &endptr, 10, &rr->type); + if (ret) { + error_setg(errp, "type of '%s'" + " must be a non-negative decimal integer", name); + } + goto out; + +separator_error: + error_setg(errp, "reserved region fields must be separated with ':'"); +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 Mon May 6 01:38:38 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=1593005500; cv=none; d=zohomail.com; s=zohoarc; b=B7Oiirp809N7dFu0R+JoZaXaOQRsFPytoR04ut2kFbrvaO3WNqZVlSNHPwDoSnH4VUgHT7/VQl0Kqprg4rDLWRnPOqKZdSWXja9Usabxw4M1cPNrnlDWT44ZXx7N/ag65L7R+kIwhBiGCb8iTEWI313DSHfZ8u4W5e6ZyIu5ZSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593005500; 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=MWXvmyqWoIxSs98UdCxr8fJGHpnAa7vxi+UAOVmabs0=; b=Jd5C/qJNaGjEeoJfCddztlcDVhQ/GI9Kxii9Ui7YD7LyF7NrH8vXrHSW7H8D7x2TClHbDenT2r2n3i1AIlH0mwBbFEMUvULq0DC9dUFp3dRLfVFWuHatIJzSXurOVYKrdq8Jy20U2hw4TfVAxfyJPHcchY+aG+f2NwYZA7WH328= 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 1593005500099622.26769748424; Wed, 24 Jun 2020 06:31:40 -0700 (PDT) Received: from localhost ([::1]:52116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jo5V5-0006h9-4r for importer@patchew.org; Wed, 24 Jun 2020 09:31:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46726) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jo5Qt-0007kS-61 for qemu-devel@nongnu.org; Wed, 24 Jun 2020 09:27:19 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:20073 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 1jo5QO-0001fy-Av for qemu-devel@nongnu.org; Wed, 24 Jun 2020 09:27:18 -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-315-QHnZrfHWO5uH9uZY85090w-1; Wed, 24 Jun 2020 09:26:45 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 81C2D804003; Wed, 24 Jun 2020 13:26:44 +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 19CF810016DA; Wed, 24 Jun 2020 13:26:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593005207; 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=MWXvmyqWoIxSs98UdCxr8fJGHpnAa7vxi+UAOVmabs0=; b=WJoJ2ZBLZ2btsIDiqwXGBfa4SGyKsoiqItuQZDyWLk/09n3FcVm8D58NREaopGpvHCrm4K e5574FlSlFM82u1y906KUQP6sMrv2Zbm5JcnDmBMHAlYpK9bT0nYeby9FcjYNqloeQtGoJ dsF2OCq79piVgghLoPijttGUA2PcIp4= X-MC-Unique: QHnZrfHWO5uH9uZY85090w-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 v5 2/5] virtio-iommu: Implement RESV_MEM probe request Date: Wed, 24 Jun 2020 15:26:22 +0200 Message-Id: <20200624132625.27453-3-eric.auger@redhat.com> In-Reply-To: <20200624132625.27453-1-eric.auger@redhat.com> References: <20200624132625.27453-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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/24 02:33:25 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 Reviewed-by: Michael S. Tsirkin --- v4 -> v5: - assert if reserved region type is different from RESERVED or MSI v3 -> v4: - removed any reference to the NONE property that does not exist anymore. 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 | 92 ++++++++++++++++++++++++++++++-- hw/virtio/trace-events | 1 + 3 files changed, 91 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..aabc3e36b1 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,63 @@ 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; + assert(prop.subtype =3D=3D VIRTIO_IOMMU_RESV_MEM_T_RESERVED || + prop.subtype =3D=3D VIRTIO_IOMMU_RESV_MEM_T_MSI); + 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 + */ +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 +465,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 +522,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 +540,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 +749,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 +759,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 Mon May 6 01:38:38 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=1593005428; cv=none; d=zohomail.com; s=zohoarc; b=XDBe5YdQ10Ft04f+7RCJjtqgV/SNkJTOWowxvPjziqHCQ5RyqoCb41/GuGTFBLDononQ9hgf3FLlSns3DXVVp9d9KL6zUeTnXwcr7r7FMzQ+P87S8ih+jAcnQO6o6SH4iIrWgMt0PiZgc70Xt9KkaPxVVy60pA9t6G0tMaEVSdU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593005428; 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=p3FPLjT36SjvV+71rdV1iXukcID/hmcJ8af0vvcyUEw=; b=MBKmyUafViFnSXKUkPHUqW27fBaZm4RvqggtR+x+nG7rE9326LgZH+hMgPyDuW6H/EsQ7tx7k6/Yr80ilOtCLL+OORqmAlm9grXH2LyFNDOeX4HssCvMDdhJIfox3AxcUU9eMDRiaQuERdox4p0IGvVG0YNZ3d6zWMFM1T1iuIg= 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 1593005428647839.8605817925103; Wed, 24 Jun 2020 06:30:28 -0700 (PDT) Received: from localhost ([::1]:47732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jo5Ts-0003us-Av for importer@patchew.org; Wed, 24 Jun 2020 09:30:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46724) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jo5Qt-0007kR-5o for qemu-devel@nongnu.org; Wed, 24 Jun 2020 09:27:19 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:39285 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 1jo5QR-0001hM-3j for qemu-devel@nongnu.org; Wed, 24 Jun 2020 09:27:18 -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-422-Htt-Gwm0MR6iNsuse-pHDA-1; Wed, 24 Jun 2020 09:26:48 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4FAA11005512; Wed, 24 Jun 2020 13:26:47 +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 D697110027B5; Wed, 24 Jun 2020 13:26:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593005210; 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=p3FPLjT36SjvV+71rdV1iXukcID/hmcJ8af0vvcyUEw=; b=cZw4uAvwMCiF+uFF/TAAxOrhgYqPek/H1aljNo3YTUzY2IqV1F2GKVc5kETHQvEX6OPX/y OA8JZc4NIndIPyFJ7UVIaQx7uAhX2UrNNXxFRVevY0lbZYt0AmDcX6c5NKY6YITrsATIta ZE/RpM+Bhsa38zIJpts3PZp/zpBUKh4= X-MC-Unique: Htt-Gwm0MR6iNsuse-pHDA-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 v5 3/5] virtio-iommu: Handle reserved regions in the translation process Date: Wed, 24 Jun 2020 15:26:23 +0200 Message-Id: <20200624132625.27453-4-eric.auger@redhat.com> In-Reply-To: <20200624132625.27453-1-eric.auger@redhat.com> References: <20200624132625.27453-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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/24 03:27:53 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" 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 Reviewed-by: Michael S. Tsirkin --- 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 aabc3e36b1..d0541ec4ad 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -605,6 +605,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; @@ -638,6 +639,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 Mon May 6 01:38:38 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=1593005323; cv=none; d=zohomail.com; s=zohoarc; b=mjFRiOJRFuX1khYer6AydRTp+5rinwYWGwzvWwjmroXNEKSWzCUE2t7WVoCbHKN2f3p4dwp6+CSPkclY6SHVmAW/PAvIsXgbz/YsnVe0rJljTEq8/gzFub2uHGsn9tCcOsEhqWo6bp60oCqaB2KYQii8uhYFJZijLolKTu9YyYk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593005323; 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=EEJC5V3lK/VQAM8iH0Zn+wfUIgAwt0asMzG0ygzjCmQ=; b=dboPS8JvXdtybDJowLimRx1ttv9AoPGOY0FyYZKm5ZZXri6muLRZRKMGhMjLYrsEg2OI2kNT17ODJQ03/w+duooTs3vvxIvL8sUD4InL3gMvAY18rRE0QLJeGVhlF7S3sCsqmGGmDmEMYGC0slu+hZbLkqAQs4ZwRqiwx29SfXk= 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 1593005323387541.5795341393056; Wed, 24 Jun 2020 06:28:43 -0700 (PDT) Received: from localhost ([::1]:41378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jo5SE-0001GU-6z for importer@patchew.org; Wed, 24 Jun 2020 09:28:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46716) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jo5Qt-0007kB-0d for qemu-devel@nongnu.org; Wed, 24 Jun 2020 09:27:19 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:57891 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 1jo5Qc-0001p2-FW for qemu-devel@nongnu.org; Wed, 24 Jun 2020 09:27:18 -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-231-ewigfKSKPZWFU_XPLYyxlw-1; Wed, 24 Jun 2020 09:27:00 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EEE6F800C60; Wed, 24 Jun 2020 13:26:58 +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 A4132100239F; Wed, 24 Jun 2020 13:26:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593005221; 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=EEJC5V3lK/VQAM8iH0Zn+wfUIgAwt0asMzG0ygzjCmQ=; b=Uqv8Mysix2WI9bS7ymL3RddzfBT1T5CG1embfC6P4xnwHSuIIXYijJ1XzUkEM0cigCfMQD BqhEBez4wYpNF2WWCtZyqwAEjM1IDEhHO65cCCqo1CliBZVAJCCXPiCTyg8b/wgyjsTOrc KjbII0Q3ZPNMm0XpmiYOTwHwgofDh9M= X-MC-Unique: ewigfKSKPZWFU_XPLYyxlw-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 v5 4/5] virtio-iommu-pci: Add array of Interval properties Date: Wed, 24 Jun 2020 15:26:24 +0200 Message-Id: <20200624132625.27453-5-eric.auger@redhat.com> In-Reply-To: <20200624132625.27453-1-eric.auger@redhat.com> References: <20200624132625.27453-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.81; 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/24 01:59:40 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" The machine may need to pass reserved regions to the virtio-iommu-pci device (such as the MSI window on x86 or the MSI doorbells on ARM). So let's add an array of Interval properties. Note: if some reserved regions are already set by the machine code - which should be the case in general -, the length of the property array is already set and prevents the end-user from modifying them. For example, attempting to use: -device virtio-iommu-pci,\ len-reserved-regions=3D1,reserved-regions[0]=3D0xfee00000:0xfeefffff:1 would result in the following error message: -device virtio-iommu-pci,len-reserved-regions=3D1,len-reserved-regions=3D1, reserved-regions[0]=3D0xfee00000:0xfeefffff:1: array size property len-reserved-regions may not be set more than once Otherwise, for example, adding two reserved regions is achieved using the following options: -device virtio-iommu-pci,addr=3D0xa,len-reserved-regions=3D2,\ reserved-regions[0]=3D0xfee00000:0xfeefffff:1,\ reserved-regions[1]=3D0x1000000:100ffff:1 Signed-off-by: Eric Auger Reviewed-by: Jean-Philippe Brucker Reviewed-by: Michael S. Tsirkin --- v3 -> v4: - added examples in the commit message as suggested by Markus - 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 632533abaf..d0746fa93c 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 Mon May 6 01:38:38 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=1593005324; cv=none; d=zohomail.com; s=zohoarc; b=F9kr0A7vAhxze+x32XnaWNqLXiROvdEU5reZn8lC7PvW93ywCOIQNVrYLDKLk9fsgx8iCx37PE85AKeTGI612ZrrgTnAnjlY8CuNGcaCZ9+uXnrBV/Sm/fFrC9gwOS9vh1bk0xcA47XXcE2kPwvsBT3svjWEQX7WOLi0Exl2t8Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593005324; 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=ntfAOaCI8FsWFg2XJLaPdm8Y+EgB6Ug4QecggYSwpuM=; b=VooiQ4zmcdX/P8EhGv8MESqqZiK34kjUlUyl3Jidqg8+TyJjzfRTkJy5wR1avQhFEqrpB0T55zPfvdRSNjq5yAxXp05okX8GfaDQOY4mmdPG4M7UntrXkVQvnMy3Th6IGpcNzZQkMbj5P+gv5Z7cS3Gd7G4TlNUThKYmBNIWM/E= 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 1593005324443528.5741280227023; Wed, 24 Jun 2020 06:28:44 -0700 (PDT) Received: from localhost ([::1]:41386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jo5SF-0001Gh-41 for importer@patchew.org; Wed, 24 Jun 2020 09:28:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jo5Qs-0007k6-Up for qemu-devel@nongnu.org; Wed, 24 Jun 2020 09:27:18 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:48874 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 1jo5Qf-0001pj-1P for qemu-devel@nongnu.org; Wed, 24 Jun 2020 09:27:18 -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-349-1Vxja1jPNvCoJ0XmBqtLiA-1; Wed, 24 Jun 2020 09:27:03 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BD2DF804003; Wed, 24 Jun 2020 13:27:01 +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 4FE6210016DA; Wed, 24 Jun 2020 13:26:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593005224; 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=ntfAOaCI8FsWFg2XJLaPdm8Y+EgB6Ug4QecggYSwpuM=; b=NHwS4M6uZZMKFsHLZ8adtpsYKqTQmM77Y0No5r5sdja8Wp1U1tYG/m+xgdyTc7hJ2XEVbt kkXtnwrsCNNA5Q5mguEyeXKx+4pB6gJgJcsXOJlvhrTAi0Goi1GaMIzjGEf3zUQYxEFzkO /vLX/3yVPIuhxXGxAflzFXtwqfB0tn0= X-MC-Unique: 1Vxja1jPNvCoJ0XmBqtLiA-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 v5 5/5] hw/arm/virt: Let the virtio-iommu bypass MSIs Date: Wed, 24 Jun 2020 15:26:25 +0200 Message-Id: <20200624132625.27453-6-eric.auger@redhat.com> In-Reply-To: <20200624132625.27453-1-eric.auger@redhat.com> References: <20200624132625.27453-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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/24 02:33:25 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 Reviewed-by: Michael S. Tsirkin --- v3 -> v4: - use ':' as separators 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 caceb1e4a0..75cf31fcba 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