From nobody Sat Feb 7 06:45:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626214355090992.8726321352239; Tue, 13 Jul 2021 15:12:35 -0700 (PDT) Received: from localhost ([::1]:37536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3Qdk-0001gH-QE for importer@patchew.org; Tue, 13 Jul 2021 18:12:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54948) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QbY-0006TP-DZ for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31990) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QbU-0007X5-8b for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:15 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-267-DNJ4NA3INuGNSg3l8Lxyow-1; Tue, 13 Jul 2021 18:10:10 -0400 Received: by mail-wr1-f71.google.com with SMTP id g9-20020adff3c90000b0290140a25efc6dso339914wrp.5 for ; Tue, 13 Jul 2021 15:10:10 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id c12sm127554wrr.90.2021.07.13.15.10.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:10:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214211; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3i4DyvYX94w5eyf6eVKq7jHnyEBcb4z6P2pthb6TVgs=; b=J+nS/rai8MMQyoB/c5/GIv2CgS+Qvx0yKQfLwmMmosVZX2zt46xPabREyLPOLoHBOFAAgi 3XH4AMbQlN1o7BVElBAcsoMvl78qGF3YBvIjeui4cXBaIhfm3fL9McW1b1vh6LK41zMdOx 8ZpLXHUbQWOZ53ErpogtZgdo2mZtMBM= X-MC-Unique: DNJ4NA3INuGNSg3l8Lxyow-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=3i4DyvYX94w5eyf6eVKq7jHnyEBcb4z6P2pthb6TVgs=; b=jNTXgdm+mDdnEDd+TUXLuAP+HeV7T+XmJA03kFwe3ePC7uJAbPZmuZIxBaye5N5MT1 u582IIRO9FsBeGCX7abFyTPLdUcfg7WXaVXb9LnP1AL2SkOm9/LwsjJy69353DBxMCuS vOVUv/k9rt2obzfNfvs9qhoDt2y3BiwIJlo7O1cSutiAFkCNiEc4yX5NAddt978nltdo hkaQvZ7ZXwigvlRMrpIQGGgY3WbFrW3ZEOz41nMNGYlHQDnTsUsqTu7Zr648DI6XEIgz sMp+fZScPk5mi6F0vbuy1q2Sf89F8OdAHZ1SZAWQE1QJ8p4HlaIDLkUxqbpfSugMU975 +OLg== X-Gm-Message-State: AOAM5317RqkocLLMQcQMOZWrdmy82PU1yWPIf6aZLd/tLTXfF2AW14A/ sMhE2GIrhQCgO2vUQ+ZaMK2p+HlIlNOu5Z0UR5H3Bcmiy06aCCKtvQ0hmMo+o6Tcj3l3NEvd7z/ 8/pPPzIotBpJllJOd6PLvKr2iGes8/SOs5KxHhmSm0brEHu+u1FtXJqKoBdjU X-Received: by 2002:a5d:5403:: with SMTP id g3mr8352637wrv.403.1626214208906; Tue, 13 Jul 2021 15:10:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvhNfx7P79vA5XzpPELzCRYI2jwMw25Uzq3Mecly5j2/kKgkcLLhgz/dngbUZYK5yVB8QcnQ== X-Received: by 2002:a5d:5403:: with SMTP id g3mr8352598wrv.403.1626214208626; Tue, 13 Jul 2021 15:10:08 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:05 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 01/23] hw/i386/acpi-build: Add ACPI PCI hot-plug methods to Q35 Message-ID: <20210713220946.212562-2-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Eduardo Habkost , Richard Henderson , Julia Suvorova , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , Paolo Bonzini , Igor Mammedov , Aurelien Jarno , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626214356822100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Julia Suvorova Implement notifications and gpe to support q35 ACPI PCI hot-plug. Use 0xcc4 - 0xcd7 range for 'acpi-pci-hotplug' io ports. Signed-off-by: Julia Suvorova Reviewed-by: Igor Mammedov Reviewed-by: Marcel Apfelbaum Message-Id: <20210713004205.775386-2-jusual@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: David Gibson --- hw/i386/acpi-build.h | 4 ++++ include/hw/acpi/ich9.h | 2 ++ include/hw/acpi/pcihp.h | 3 ++- hw/acpi/pcihp.c | 6 +++--- hw/acpi/piix4.c | 4 +++- hw/i386/acpi-build.c | 30 +++++++++++++++++++----------- 6 files changed, 33 insertions(+), 16 deletions(-) diff --git a/hw/i386/acpi-build.h b/hw/i386/acpi-build.h index 74df5fc612..487ec7710f 100644 --- a/hw/i386/acpi-build.h +++ b/hw/i386/acpi-build.h @@ -5,6 +5,10 @@ =20 extern const struct AcpiGenericAddress x86_nvdimm_acpi_dsmio; =20 +/* PCI Hot-plug registers bases. See docs/spec/acpi_pci_hotplug.txt */ +#define ACPI_PCIHP_SEJ_BASE 0x8 +#define ACPI_PCIHP_BNMR_BASE 0x10 + void acpi_setup(void); =20 #endif diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h index df519e40b5..596120d97f 100644 --- a/include/hw/acpi/ich9.h +++ b/include/hw/acpi/ich9.h @@ -28,6 +28,8 @@ #include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/tco.h" =20 +#define ACPI_PCIHP_ADDR_ICH9 0x0cc4 + typedef struct ICH9LPCPMRegs { /* * In ich9 spec says that pm1_cnt register is 32bit width and diff --git a/include/hw/acpi/pcihp.h b/include/hw/acpi/pcihp.h index 2dd90aea30..af1a169fc3 100644 --- a/include/hw/acpi/pcihp.h +++ b/include/hw/acpi/pcihp.h @@ -55,7 +55,8 @@ typedef struct AcpiPciHpState { } AcpiPciHpState; =20 void acpi_pcihp_init(Object *owner, AcpiPciHpState *, PCIBus *root, - MemoryRegion *address_space_io, bool bridges_enabled); + MemoryRegion *address_space_io, bool bridges_enabled, + uint16_t io_base); =20 void acpi_pcihp_device_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c index 4999277d57..d98a284b7a 100644 --- a/hw/acpi/pcihp.c +++ b/hw/acpi/pcihp.c @@ -37,7 +37,6 @@ #include "qom/qom-qobject.h" #include "trace.h" =20 -#define ACPI_PCIHP_ADDR 0xae00 #define ACPI_PCIHP_SIZE 0x0018 #define PCI_UP_BASE 0x0000 #define PCI_DOWN_BASE 0x0004 @@ -488,10 +487,11 @@ static const MemoryRegionOps acpi_pcihp_io_ops =3D { }; =20 void acpi_pcihp_init(Object *owner, AcpiPciHpState *s, PCIBus *root_bus, - MemoryRegion *address_space_io, bool bridges_enabled) + MemoryRegion *address_space_io, bool bridges_enabled, + uint16_t io_base) { s->io_len =3D ACPI_PCIHP_SIZE; - s->io_base =3D ACPI_PCIHP_ADDR; + s->io_base =3D io_base; =20 s->root =3D root_bus; s->legacy_piix =3D !bridges_enabled; diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c index 0bd23d74e2..48f7a1edbc 100644 --- a/hw/acpi/piix4.c +++ b/hw/acpi/piix4.c @@ -49,6 +49,8 @@ #define GPE_BASE 0xafe0 #define GPE_LEN 4 =20 +#define ACPI_PCIHP_ADDR_PIIX4 0xae00 + struct pci_status { uint32_t up; /* deprecated, maintained for migration compatibility */ uint32_t down; @@ -607,7 +609,7 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion= *parent, =20 if (s->use_acpi_hotplug_bridge || s->use_acpi_root_pci_hotplug) { acpi_pcihp_init(OBJECT(s), &s->acpi_pci_hotplug, bus, parent, - s->use_acpi_hotplug_bridge); + s->use_acpi_hotplug_bridge, ACPI_PCIHP_ADDR_PIIX4); } =20 s->cpu_hotplug_legacy =3D true; diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 357437ff1d..e1c246d6e8 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -219,10 +219,6 @@ static void acpi_get_pm_info(MachineState *machine, Ac= piPmInfo *pm) /* w2k requires FADT(rev1) or it won't boot, keep PC compatible */ pm->fadt.rev =3D 1; pm->cpu_hp_io_base =3D PIIX4_CPU_HOTPLUG_IO_BASE; - pm->pcihp_io_base =3D - object_property_get_uint(obj, ACPI_PCIHP_IO_BASE_PROP, NULL); - pm->pcihp_io_len =3D - object_property_get_uint(obj, ACPI_PCIHP_IO_LEN_PROP, NULL); } if (lpc) { uint64_t smi_features =3D object_property_get_uint(lpc, @@ -238,6 +234,10 @@ static void acpi_get_pm_info(MachineState *machine, Ac= piPmInfo *pm) pm->smi_on_cpu_unplug =3D !!(smi_features & BIT_ULL(ICH9_LPC_SMI_F_CPU_HOT_UNPLUG_BIT)); } + pm->pcihp_io_base =3D + object_property_get_uint(obj, ACPI_PCIHP_IO_BASE_PROP, NULL); + pm->pcihp_io_len =3D + object_property_get_uint(obj, ACPI_PCIHP_IO_LEN_PROP, NULL); =20 /* The above need not be conditional on machine type because the reset= port * happens to be the same on PIIX (pc) and ICH9 (q35). */ @@ -392,6 +392,9 @@ static void build_append_pci_bus_devices(Aml *parent_sc= ope, PCIBus *bus, =20 if (!pdev) { if (bsel) { /* add hotplug slots for non present devices */ + if (pci_bus_is_express(bus) && slot > 0) { + break; + } dev =3D aml_device("S%.02X", PCI_DEVFN(slot, 0)); aml_append(dev, aml_name_decl("_SUN", aml_int(slot))); aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16))= ); @@ -521,7 +524,7 @@ static void build_append_pci_bus_devices(Aml *parent_sc= ope, PCIBus *bus, QLIST_FOREACH(sec, &bus->child, sibling) { int32_t devfn =3D sec->parent_dev->devfn; =20 - if (pci_bus_is_root(sec) || pci_bus_is_express(sec)) { + if (pci_bus_is_root(sec)) { continue; } =20 @@ -1251,7 +1254,7 @@ static void build_piix4_isa_bridge(Aml *table) aml_append(table, scope); } =20 -static void build_piix4_pci_hotplug(Aml *table) +static void build_x86_acpi_pci_hotplug(Aml *table, uint64_t pcihp_addr) { Aml *scope; Aml *field; @@ -1260,20 +1263,22 @@ static void build_piix4_pci_hotplug(Aml *table) scope =3D aml_scope("_SB.PCI0"); =20 aml_append(scope, - aml_operation_region("PCST", AML_SYSTEM_IO, aml_int(0xae00), 0x08)= ); + aml_operation_region("PCST", AML_SYSTEM_IO, aml_int(pcihp_addr), 0= x08)); field =3D aml_field("PCST", AML_DWORD_ACC, AML_NOLOCK, AML_WRITE_AS_ZE= ROS); aml_append(field, aml_named_field("PCIU", 32)); aml_append(field, aml_named_field("PCID", 32)); aml_append(scope, field); =20 aml_append(scope, - aml_operation_region("SEJ", AML_SYSTEM_IO, aml_int(0xae08), 0x04)); + aml_operation_region("SEJ", AML_SYSTEM_IO, + aml_int(pcihp_addr + ACPI_PCIHP_SEJ_BASE), 0x= 04)); field =3D aml_field("SEJ", AML_DWORD_ACC, AML_NOLOCK, AML_WRITE_AS_ZER= OS); aml_append(field, aml_named_field("B0EJ", 32)); aml_append(scope, field); =20 aml_append(scope, - aml_operation_region("BNMR", AML_SYSTEM_IO, aml_int(0xae10), 0x08)= ); + aml_operation_region("BNMR", AML_SYSTEM_IO, + aml_int(pcihp_addr + ACPI_PCIHP_BNMR_BASE), 0= x08)); field =3D aml_field("BNMR", AML_DWORD_ACC, AML_NOLOCK, AML_WRITE_AS_ZE= ROS); aml_append(field, aml_named_field("BNUM", 32)); aml_append(field, aml_named_field("PIDX", 32)); @@ -1407,7 +1412,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, build_piix4_isa_bridge(dsdt); build_isa_devices_aml(dsdt); if (pm->pcihp_bridge_en || pm->pcihp_root_en) { - build_piix4_pci_hotplug(dsdt); + build_x86_acpi_pci_hotplug(dsdt, pm->pcihp_io_base); } build_piix4_pci0_int(dsdt); } else { @@ -1455,6 +1460,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, } build_q35_isa_bridge(dsdt); build_isa_devices_aml(dsdt); + if (pm->pcihp_bridge_en) { + build_x86_acpi_pci_hotplug(dsdt, pm->pcihp_io_base); + } build_q35_pci0_int(dsdt); if (pcms->smbus && !pcmc->do_not_add_smb_acpi) { build_smb0(dsdt, pcms->smbus, ICH9_SMB_DEV, ICH9_SMB_FUNC); @@ -1489,7 +1497,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, { aml_append(scope, aml_name_decl("_HID", aml_string("ACPI0006"))); =20 - if (misc->is_piix4 && (pm->pcihp_bridge_en || pm->pcihp_root_en)) { + if (pm->pcihp_bridge_en || pm->pcihp_root_en) { method =3D aml_method("_E01", 0, AML_NOTSERIALIZED); aml_append(method, aml_acquire(aml_name("\\_SB.PCI0.BLCK"), 0xFFFF)); --=20 MST From nobody Sat Feb 7 06:45:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626214973743949.0821234312572; Tue, 13 Jul 2021 15:22:53 -0700 (PDT) Received: from localhost ([::1]:43412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3Qnk-0007l8-L8 for importer@patchew.org; Tue, 13 Jul 2021 18:22:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qbc-0006Wv-AJ for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22537) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QbY-0007ZU-CZ for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:19 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-276-iAqPiY9sOJmY0CucJwAofQ-1; Tue, 13 Jul 2021 18:10:14 -0400 Received: by mail-wr1-f69.google.com with SMTP id p4-20020a5d63840000b0290126f2836a61so336708wru.6 for ; Tue, 13 Jul 2021 15:10:14 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id r17sm3475523wmq.13.2021.07.13.15.10.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214215; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=9QZG8Wl50+7PmAQdBrLDebzFMtsRxXny/OdYWszhAo8=; b=HeQbU+wE/JirbLzGFkAwKzyPDd8QZtqMzoeueWjks1LJa6uNXSs9x+SlhcHK8yfcx+D7P+ Ejb8LaB/VrAYZUzaJnbXRroLg0n6SfdUnnEFvvfNpcY4BwZweZJaT3xq3fz9nwoBhB/Wer Q15mGeuHXhcHIF4lKgzyRb966zaRm9A= X-MC-Unique: iAqPiY9sOJmY0CucJwAofQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=9QZG8Wl50+7PmAQdBrLDebzFMtsRxXny/OdYWszhAo8=; b=rIawBh+G0cYp38mE97HDTrJAmpE1IVNAZoU1c9s8n2Q6fVB4aSaWio54jFYcZJ86wO 5z/r8ZKZB5FusePzvNF5lONe9SLBHT/h/ljge3/4Nbkq6FOIjVzrGFQdTrGcya/wCnBs n3GHWXHlRveboS0neyJ0JFwzHr6yK10VGK5SOP9111NwsiL+BEip+mSpLRoU6L4cX4Ev 0gWC8UJI1BKFHcV/4D6pyclUcagnkSizTNxQl+4P/PrnIRYVRtncikFB0YH4yYFCNCU3 7waH40iv8IwSdvD1nzurHjI7tynpE69wqn0FAwzWyA265E5vlim5I3pYX3/lH+Ruy+I/ RMJg== X-Gm-Message-State: AOAM530NurFgRjiyF8VlB5b2GQYiPY3905dL4wSMelcvfrgi97vQXVpy pUA1Un9Me/u2umKJwt8XFLPxQ0ajwDHw54urnYm2HB61p76jYO5SBMQxWuCwFLaVQNYmvlSyDH2 sklmmSX9DP7sF9eO4Jar2FB2SvB0lIWL2BB/4h9RYOTDnp8xPJy2jKncnpPvE X-Received: by 2002:a7b:c4d2:: with SMTP id g18mr7469400wmk.146.1626214212936; Tue, 13 Jul 2021 15:10:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJbrOA9QleCXnGTEWrmJxNkuE1hEkUsbVvMfIOq8KpSxySyEVFjSeD1LH9Dx3BpmMjATySUg== X-Received: by 2002:a7b:c4d2:: with SMTP id g18mr7469356wmk.146.1626214212563; Tue, 13 Jul 2021 15:10:12 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:09 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 02/23] hw/acpi/ich9: Enable ACPI PCI hot-plug Message-ID: <20210713220946.212562-3-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Eduardo Habkost , Richard Henderson , Julia Suvorova , Igor Mammedov , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626214974247100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Julia Suvorova Add acpi_pcihp to ich9_pm as part of 'acpi-pci-hotplug-with-bridge-support' option. Set default to false. Signed-off-by: Julia Suvorova Signed-off-by: Marcel Apfelbaum Reviewed-by: Igor Mammedov Message-Id: <20210713004205.775386-3-jusual@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: David Gibson --- hw/i386/acpi-build.h | 1 + include/hw/acpi/ich9.h | 3 ++ hw/acpi/acpi-x86-stub.c | 6 ++++ hw/acpi/ich9.c | 70 +++++++++++++++++++++++++++++++++++++++++ hw/acpi/pcihp.c | 12 +++++-- hw/i386/acpi-build.c | 14 ++++++--- 6 files changed, 100 insertions(+), 6 deletions(-) diff --git a/hw/i386/acpi-build.h b/hw/i386/acpi-build.h index 487ec7710f..0dce155c8c 100644 --- a/hw/i386/acpi-build.h +++ b/hw/i386/acpi-build.h @@ -10,5 +10,6 @@ extern const struct AcpiGenericAddress x86_nvdimm_acpi_ds= mio; #define ACPI_PCIHP_BNMR_BASE 0x10 =20 void acpi_setup(void); +Object *acpi_get_i386_pci_host(void); =20 #endif diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h index 596120d97f..a329ce43ab 100644 --- a/include/hw/acpi/ich9.h +++ b/include/hw/acpi/ich9.h @@ -24,6 +24,7 @@ #include "hw/acpi/acpi.h" #include "hw/acpi/cpu_hotplug.h" #include "hw/acpi/cpu.h" +#include "hw/acpi/pcihp.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/tco.h" @@ -55,6 +56,8 @@ typedef struct ICH9LPCPMRegs { AcpiCpuHotplug gpe_cpu; CPUHotplugState cpuhp_state; =20 + bool use_acpi_hotplug_bridge; + AcpiPciHpState acpi_pci_hotplug; MemHotplugState acpi_memory_hotplug; =20 uint8_t disable_s3; diff --git a/hw/acpi/acpi-x86-stub.c b/hw/acpi/acpi-x86-stub.c index f88d6a090b..e9e46c5c5f 100644 --- a/hw/acpi/acpi-x86-stub.c +++ b/hw/acpi/acpi-x86-stub.c @@ -1,7 +1,13 @@ #include "qemu/osdep.h" #include "hw/i386/pc.h" +#include "hw/i386/acpi-build.h" =20 void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid, const CPUArchIdList *apic_ids, GArray *entry) { } + +Object *acpi_get_i386_pci_host(void) +{ + return NULL; +} diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c index 4daa79ec8d..2f4eb453ac 100644 --- a/hw/acpi/ich9.c +++ b/hw/acpi/ich9.c @@ -217,6 +217,26 @@ static const VMStateDescription vmstate_cpuhp_state = =3D { } }; =20 +static bool vmstate_test_use_pcihp(void *opaque) +{ + ICH9LPCPMRegs *s =3D opaque; + + return s->use_acpi_hotplug_bridge; +} + +static const VMStateDescription vmstate_pcihp_state =3D { + .name =3D "ich9_pm/pcihp", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D vmstate_test_use_pcihp, + .fields =3D (VMStateField[]) { + VMSTATE_PCI_HOTPLUG(acpi_pci_hotplug, + ICH9LPCPMRegs, + NULL, NULL), + VMSTATE_END_OF_LIST() + } +}; + const VMStateDescription vmstate_ich9_pm =3D { .name =3D "ich9_pm", .version_id =3D 1, @@ -238,6 +258,7 @@ const VMStateDescription vmstate_ich9_pm =3D { &vmstate_memhp_state, &vmstate_tco_io_state, &vmstate_cpuhp_state, + &vmstate_pcihp_state, NULL } }; @@ -259,6 +280,10 @@ static void pm_reset(void *opaque) } pm->smi_en_wmask =3D ~0; =20 + if (pm->use_acpi_hotplug_bridge) { + acpi_pcihp_reset(&pm->acpi_pci_hotplug, true); + } + acpi_update_sci(&pm->acpi_regs, pm->irq); } =20 @@ -297,6 +322,18 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *p= m, pm->enable_tco =3D true; acpi_pm_tco_init(&pm->tco_regs, &pm->io); =20 + if (pm->use_acpi_hotplug_bridge) { + acpi_pcihp_init(OBJECT(lpc_pci), + &pm->acpi_pci_hotplug, + pci_get_bus(lpc_pci), + pci_address_space_io(lpc_pci), + true, + ACPI_PCIHP_ADDR_ICH9); + + qbus_set_hotplug_handler(BUS(pci_get_bus(lpc_pci)), + OBJECT(lpc_pci)); + } + pm->irq =3D sci_irq; qemu_register_reset(pm_reset, pm); pm->powerdown_notifier.notify =3D pm_powerdown_req; @@ -368,6 +405,20 @@ static void ich9_pm_set_enable_tco(Object *obj, bool v= alue, Error **errp) s->pm.enable_tco =3D value; } =20 +static bool ich9_pm_get_acpi_pci_hotplug(Object *obj, Error **errp) +{ + ICH9LPCState *s =3D ICH9_LPC_DEVICE(obj); + + return s->pm.use_acpi_hotplug_bridge; +} + +static void ich9_pm_set_acpi_pci_hotplug(Object *obj, bool value, Error **= errp) +{ + ICH9LPCState *s =3D ICH9_LPC_DEVICE(obj); + + s->pm.use_acpi_hotplug_bridge =3D value; +} + void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm) { static const uint32_t gpe0_len =3D ICH9_PMIO_GPE0_LEN; @@ -376,6 +427,7 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs = *pm) pm->disable_s3 =3D 0; pm->disable_s4 =3D 0; pm->s4_val =3D 2; + pm->use_acpi_hotplug_bridge =3D false; =20 object_property_add_uint32_ptr(obj, ACPI_PM_PROP_PM_IO_BASE, &pm->pm_io_base, OBJ_PROP_FLAG_READ); @@ -399,6 +451,9 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs = *pm) object_property_add_bool(obj, ACPI_PM_PROP_TCO_ENABLED, ich9_pm_get_enable_tco, ich9_pm_set_enable_tco); + object_property_add_bool(obj, "acpi-pci-hotplug-with-bridge-support", + ich9_pm_get_acpi_pci_hotplug, + ich9_pm_set_acpi_pci_hotplug); } =20 void ich9_pm_device_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *= dev, @@ -406,6 +461,11 @@ void ich9_pm_device_pre_plug_cb(HotplugHandler *hotplu= g_dev, DeviceState *dev, { ICH9LPCState *lpc =3D ICH9_LPC_DEVICE(hotplug_dev); =20 + if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + acpi_pcihp_device_pre_plug_cb(hotplug_dev, dev, errp); + return; + } + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) && !lpc->pm.acpi_memory_hotplug.is_enabled) { error_setg(errp, @@ -441,6 +501,9 @@ void ich9_pm_device_plug_cb(HotplugHandler *hotplug_dev= , DeviceState *dev, } else { acpi_cpu_plug_cb(hotplug_dev, &lpc->pm.cpuhp_state, dev, errp); } + } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + acpi_pcihp_device_plug_cb(hotplug_dev, &lpc->pm.acpi_pci_hotplug, + dev, errp); } else { error_setg(errp, "acpi: device plug request for not supported devi= ce" " type: %s", object_get_typename(OBJECT(dev))); @@ -473,6 +536,10 @@ void ich9_pm_device_unplug_request_cb(HotplugHandler *= hotplug_dev, =20 acpi_cpu_unplug_request_cb(hotplug_dev, &lpc->pm.cpuhp_state, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + acpi_pcihp_device_unplug_request_cb(hotplug_dev, + &lpc->pm.acpi_pci_hotplug, + dev, errp); } else { error_setg(errp, "acpi: device unplug request for not supported de= vice" " type: %s", object_get_typename(OBJECT(dev))); @@ -490,6 +557,9 @@ void ich9_pm_device_unplug_cb(HotplugHandler *hotplug_d= ev, DeviceState *dev, } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU) && !lpc->pm.cpu_hotplug_legacy) { acpi_cpu_unplug_cb(&lpc->pm.cpuhp_state, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + acpi_pcihp_device_unplug_cb(hotplug_dev, &lpc->pm.acpi_pci_hotplug, + dev, errp); } else { error_setg(errp, "acpi: device unplug for not supported device" " type: %s", object_get_typename(OBJECT(dev))); diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c index d98a284b7a..9fdc6342b0 100644 --- a/hw/acpi/pcihp.c +++ b/hw/acpi/pcihp.c @@ -30,6 +30,8 @@ #include "hw/pci-host/i440fx.h" #include "hw/pci/pci.h" #include "hw/pci/pci_bridge.h" +#include "hw/pci/pci_host.h" +#include "hw/i386/acpi-build.h" #include "hw/acpi/acpi.h" #include "hw/pci/pci_bus.h" #include "migration/vmstate.h" @@ -103,6 +105,7 @@ static void *acpi_set_bsel(PCIBus *bus, void *opaque) static void acpi_set_pci_info(void) { static bool bsel_is_set; + Object *host =3D acpi_get_i386_pci_host(); PCIBus *bus; unsigned bsel_alloc =3D ACPI_PCIHP_BSEL_DEFAULT; =20 @@ -111,7 +114,11 @@ static void acpi_set_pci_info(void) } bsel_is_set =3D true; =20 - bus =3D find_i440fx(); /* TODO: Q35 support */ + if (!host) { + return; + } + + bus =3D PCI_HOST_BRIDGE(host)->bus; if (bus) { /* Scan all PCI buses. Set property to enable acpi based hotplug. = */ pci_for_each_bus_depth_first(bus, acpi_set_bsel, NULL, &bsel_alloc= ); @@ -121,13 +128,14 @@ static void acpi_set_pci_info(void) static void acpi_pcihp_disable_root_bus(void) { static bool root_hp_disabled; + Object *host =3D acpi_get_i386_pci_host(); PCIBus *bus; =20 if (root_hp_disabled) { return; } =20 - bus =3D find_i440fx(); + bus =3D PCI_HOST_BRIDGE(host)->bus; if (bus) { /* setting the hotplug handler to NULL makes the bus non-hotplugga= ble */ qbus_set_hotplug_handler(BUS(bus), NULL); diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index e1c246d6e8..bc966a4110 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -299,7 +299,7 @@ static void acpi_get_misc_info(AcpiMiscInfo *info) * Because of the PXB hosts we cannot simply query TYPE_PCI_HOST_BRIDGE. * On i386 arch we only have two pci hosts, so we can look only for them. */ -static Object *acpi_get_i386_pci_host(void) +Object *acpi_get_i386_pci_host(void) { PCIHostState *host; =20 @@ -320,7 +320,10 @@ static void acpi_get_pci_holes(Range *hole, Range *hol= e64) Object *pci_host; =20 pci_host =3D acpi_get_i386_pci_host(); - g_assert(pci_host); + + if (!pci_host) { + return; + } =20 range_set_bounds1(hole, object_property_get_uint(pci_host, @@ -1765,6 +1768,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, PCIBus *bus =3D NULL; =20 pci_host =3D acpi_get_i386_pci_host(); + if (pci_host) { bus =3D PCI_HOST_BRIDGE(pci_host)->bus; } @@ -2321,7 +2325,9 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg) QObject *o; =20 pci_host =3D acpi_get_i386_pci_host(); - g_assert(pci_host); + if (!pci_host) { + return false; + } =20 o =3D object_property_get_qobject(pci_host, PCIE_HOST_MCFG_BASE, NULL); if (!o) { @@ -2351,7 +2357,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState= *machine) AcpiPmInfo pm; AcpiMiscInfo misc; AcpiMcfgInfo mcfg; - Range pci_hole, pci_hole64; + Range pci_hole =3D {}, pci_hole64 =3D {}; uint8_t *u; size_t aml_len =3D 0; GArray *tables_blob =3D tables->table_data; --=20 MST From nobody Sat Feb 7 06:45:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162621438493284.29328639139021; Tue, 13 Jul 2021 15:13:04 -0700 (PDT) Received: from localhost ([::1]:39688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3QeF-00037Q-Si for importer@patchew.org; Tue, 13 Jul 2021 18:13:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qbe-0006X4-4t for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31661) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qbc-0007bV-BU for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:21 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-563-8GD9ywi4P_GTrAbTKhdtcQ-1; Tue, 13 Jul 2021 18:10:18 -0400 Received: by mail-wm1-f70.google.com with SMTP id l17-20020a05600c4f11b0290225ef65c35dso969620wmq.2 for ; Tue, 13 Jul 2021 15:10:18 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id q81sm1412969wme.18.2021.07.13.15.10.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:10:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214219; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Hx1EPiPggxOFuAl77QnkazGCnyRccijDT3bkBz4qVPY=; b=UUx9JYjz9T3l0StwPbObbnBfIVueZPF8zvKl55xySTFvJBtsCUqQj/Ik02RlWgGKvlKXlw jOTD49xPaG8SKsVIbhlMAi3kjJGX41IK7636skkYunSlVLIuFiz+WFKMaRdMnVua+oqwWG vm0pOq7U7YuAeDEnvVtilCtB0umom4I= X-MC-Unique: 8GD9ywi4P_GTrAbTKhdtcQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Hx1EPiPggxOFuAl77QnkazGCnyRccijDT3bkBz4qVPY=; b=sIGNBedj3MfCr8Ezd3SocoPtXVir0wpXHEdCZqFEiyQH0eFlJvoaWQxFzyB8+8Ayxq eDBphO5rwMWgCwdKbuibQUBOSQgVFY/xZZZ5RmVcyc5eefPMWPdmsLcCG5n0m13mdGY6 dc+6OefFOrmdwhL3XVV0Wcn8ZIcwqePrWQIIvTCKB21hOrCBpO0HpFUsmdmhGqsN1voO eC/q/9+VeVpXeXWw97U5BqvSnGuvJPgjRgLs9puh4W5GAWEI3sd69PBWRHs3+2lxcte0 yM4IO5l2AsCpLrxmZa+7uK1rD+kprLOdBKDyKRlZPFrqxfhvDVMYJ4P0/9ZvKaHe7QS6 +omg== X-Gm-Message-State: AOAM531rTPpaW+pdTENVIhkhKgWjKmhrz7Joe+nkehmix/POFaw/suBn 45Ga6OnAWfpWtc7eAXQ3Cj58n1pqhcjzsdEE/KT30n0wJNh5A1huIjiv6ayv6OUzPcIhuk2bzrl scFYZnamidpLh1Hg7cJSTvHgWpB+XcsPCmrfzarMQ1KQDrQSiogONsvvGhyVN X-Received: by 2002:a1c:7e44:: with SMTP id z65mr408789wmc.1.1626214216627; Tue, 13 Jul 2021 15:10:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzakRcGuN6ePndKT9arscPNmug3IpZ6s5RhkrkWH9R9/aiHiA2a8x4NWC4lsBXxpB3V4E5YXg== X-Received: by 2002:a1c:7e44:: with SMTP id z65mr408748wmc.1.1626214216263; Tue, 13 Jul 2021 15:10:16 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:12 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 03/23] hw/pci/pcie: Do not set HPC flag if acpihp is used Message-ID: <20210713220946.212562-4-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Eduardo Habkost , Richard Henderson , Julia Suvorova , Paolo Bonzini , Igor Mammedov , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626214387065100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Julia Suvorova Instead of changing the hot-plug type in _OSC register, do not set the 'Hot-Plug Capable' flag. This way guest will choose ACPI hot-plug if it is preferred and leave the option to use SHPC with pcie-pci-bridge. The ability to control hot-plug for each downstream port is retained, while 'hotplug=3Doff' on the port means all hot-plug types are disabled. Signed-off-by: Julia Suvorova Reviewed-by: Igor Mammedov Reviewed-by: Marcel Apfelbaum Reviewed-by: David Gibson Message-Id: <20210713004205.775386-4-jusual@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/pci/pcie_port.h | 5 ++++- hw/acpi/pcihp.c | 8 ++++++++ hw/core/machine.c | 1 - hw/i386/pc_q35.c | 11 +++++++++++ hw/pci/pcie.c | 8 +++++++- hw/pci/pcie_port.c | 1 + 6 files changed, 31 insertions(+), 3 deletions(-) diff --git a/include/hw/pci/pcie_port.h b/include/hw/pci/pcie_port.h index bea8ecad0f..e25b289ce8 100644 --- a/include/hw/pci/pcie_port.h +++ b/include/hw/pci/pcie_port.h @@ -57,8 +57,11 @@ struct PCIESlot { /* Disable ACS (really for a pcie_root_port) */ bool disable_acs; =20 - /* Indicates whether hot-plug is enabled on the slot */ + /* Indicates whether any type of hot-plug is allowed on the slot */ bool hotplug; + + bool native_hotplug; + QLIST_ENTRY(PCIESlot) next; }; =20 diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c index 9fdc6342b0..f4d706e47d 100644 --- a/hw/acpi/pcihp.c +++ b/hw/acpi/pcihp.c @@ -31,6 +31,7 @@ #include "hw/pci/pci.h" #include "hw/pci/pci_bridge.h" #include "hw/pci/pci_host.h" +#include "hw/pci/pcie_port.h" #include "hw/i386/acpi-build.h" #include "hw/acpi/acpi.h" #include "hw/pci/pci_bus.h" @@ -336,6 +337,13 @@ void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug= _dev, AcpiPciHpState *s, object_dynamic_cast(OBJECT(dev), TYPE_PCI_BRIDGE)) { PCIBus *sec =3D pci_bridge_get_sec_bus(PCI_BRIDGE(pdev)); =20 + /* Remove all hot-plug handlers if hot-plug is disabled on slo= t */ + if (object_dynamic_cast(OBJECT(dev), TYPE_PCIE_SLOT) && + !PCIE_SLOT(pdev)->hotplug) { + qbus_set_hotplug_handler(BUS(sec), NULL); + return; + } + qbus_set_hotplug_handler(BUS(sec), OBJECT(hotplug_dev)); /* We don't have to overwrite any other hotplug handler yet */ assert(QLIST_EMPTY(&sec->child)); diff --git a/hw/core/machine.c b/hw/core/machine.c index 57c18f909a..11c26eeabd 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -584,7 +584,6 @@ static void machine_set_memdev(Object *obj, const char = *value, Error **errp) ms->ram_memdev_id =3D g_strdup(value); } =20 - static void machine_init_notify(Notifier *notifier, void *data) { MachineState *machine =3D MACHINE(qdev_get_machine()); diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 46a0f196f4..04b4a4788d 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -37,6 +37,7 @@ #include "sysemu/kvm.h" #include "hw/kvm/clock.h" #include "hw/pci-host/q35.h" +#include "hw/pci/pcie_port.h" #include "hw/qdev-properties.h" #include "hw/i386/x86.h" #include "hw/i386/pc.h" @@ -136,6 +137,7 @@ static void pc_q35_init(MachineState *machine) ram_addr_t lowmem; DriveInfo *hd[MAX_SATA_PORTS]; MachineClass *mc =3D MACHINE_GET_CLASS(machine); + bool acpi_pcihp; =20 /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory * and 256 Mbytes for PCI Express Enhanced Configuration Access Mapping @@ -236,6 +238,15 @@ static void pc_q35_init(MachineState *machine) object_property_set_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP, OBJECT(lpc), &error_abort); =20 + acpi_pcihp =3D object_property_get_bool(OBJECT(lpc), + "acpi-pci-hotplug-with-bridge-su= pport", + NULL); + + if (acpi_pcihp) { + object_register_sugar_prop(TYPE_PCIE_SLOT, "native-hotplug", + "false", true); + } + /* irq lines */ gsi_state =3D pc_gsi_create(&x86ms->gsi, pcmc->pci_enabled); =20 diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index fd0fa157e8..6e95d82903 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -529,7 +529,13 @@ void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s) PCI_EXP_SLTCAP_PIP | PCI_EXP_SLTCAP_AIP | PCI_EXP_SLTCAP_ABP); - if (s->hotplug) { + + /* + * Enable native hot-plug on all hot-plugged bridges unless + * hot-plug is disabled on the slot. + */ + if (s->hotplug && + (s->native_hotplug || DEVICE(dev)->hotplugged)) { pci_long_test_and_set_mask(dev->config + pos + PCI_EXP_SLTCAP, PCI_EXP_SLTCAP_HPS | PCI_EXP_SLTCAP_HPC); diff --git a/hw/pci/pcie_port.c b/hw/pci/pcie_port.c index eb563ad435..da850e8dde 100644 --- a/hw/pci/pcie_port.c +++ b/hw/pci/pcie_port.c @@ -148,6 +148,7 @@ static Property pcie_slot_props[] =3D { DEFINE_PROP_UINT8("chassis", PCIESlot, chassis, 0), DEFINE_PROP_UINT16("slot", PCIESlot, slot, 0), DEFINE_PROP_BOOL("hotplug", PCIESlot, hotplug, true), + DEFINE_PROP_BOOL("native-hotplug", PCIESlot, native_hotplug, true), DEFINE_PROP_END_OF_LIST() }; =20 --=20 MST From nobody Sat Feb 7 06:45:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162621550925546.62580904399283; Tue, 13 Jul 2021 15:31:49 -0700 (PDT) Received: from localhost ([::1]:42636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3QwO-0000wG-4i for importer@patchew.org; Tue, 13 Jul 2021 18:31:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55774) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QeI-0004ZS-Vl for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:13:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55853) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QeH-0001Ft-Dv for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:13:06 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-wGJlETSbMGWEQRnkywzYuQ-1; Tue, 13 Jul 2021 18:10:20 -0400 Received: by mail-wm1-f71.google.com with SMTP id y6-20020a7bc1860000b0290227b53c7cefso154069wmi.1 for ; Tue, 13 Jul 2021 15:10:20 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id l24sm3452028wmi.30.2021.07.13.15.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:10:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214384; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rnZmrpdt3JApfVreMKFcNarnw8Jq+7AjA6w24KOMdJg=; b=A3W4bO3kzhBFhda4cz/GicrtJ5UiAByZmr4+Wr/V9csKWxJqSUNAcA+Tl5z+Izo3d7OSmK dZlZSljOJLKwwz1+uxUbqRBIM/erSmiOFzcVqLeID2tQMDGQ+QQ66P7ro1wmvd1IWtP47b kdoxGpJE5TelIkQCHbyTlDLO35KxOjQ= X-MC-Unique: wGJlETSbMGWEQRnkywzYuQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=rnZmrpdt3JApfVreMKFcNarnw8Jq+7AjA6w24KOMdJg=; b=QU3e10yOGvsSlA1128WsstfyJxSE+82xkl/AFkfadFoRc3ov3XLEKtrBZI30RRLpnu t7oW8O6aPZ1rEvnFoGl5f2AvCk86Afl8PfFLoy52UglceWP0OfOrBMzc3BZyvyKVrBNV NhBoteMKyllRA2lg6evTBjIK4Bp+NNwL07O3FwFZoh3lTDNHjMHtNq5TqOEijSfoD6aa He/+BrnMOrCxxdtCvMAGtBnnrrKuCN5fUVl1LJ+EQaMhAPSLh+cFWWQ8U+KYEFxCOZ/E TkDRNDgF8PjHp6UIZbZmhLCNDrd1YV4hfw+UssfNt4SlTC+kU/sBthiA/N4CGichERgJ 2mMQ== X-Gm-Message-State: AOAM5313CgFB4cmHprfGfbzTL9U21o+OipIcoU/+FYVwM2vlZwFmfvSi Ym2G1z2rtsyrzJ+pV+azfBzeson1tGWxYyGb+/+yEzFxuF/fC8HWUsvIqf1SVvyv1V2wc0cqdsM kizOzTphthl7dS46RwZH9pPl3bxcQuspP6V7tiKgQ35AUJBHIYfkfzX2L9uqY X-Received: by 2002:adf:c5d2:: with SMTP id v18mr8527894wrg.386.1626214219478; Tue, 13 Jul 2021 15:10:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdzz3bEUOywHFnqb/VTv9et5wSKLMkC4N26VJuhjg3hFNr7Nfag3flL1TPknrB4EkXEKsqxQ== X-Received: by 2002:adf:c5d2:: with SMTP id v18mr8527882wrg.386.1626214219317; Tue, 13 Jul 2021 15:10:19 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:16 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 04/23] bios-tables-test: Allow changes in DSDT ACPI tables Message-ID: <20210713220946.212562-5-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Julia Suvorova , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626215511144100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Julia Suvorova All DSDT Q35 tables will be modified because ACPI hot-plug is enabled by default. Signed-off-by: Julia Suvorova Reviewed-by: Igor Mammedov Reviewed-by: Marcel Apfelbaum Message-Id: <20210713004205.775386-5-jusual@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/qtest/bios-tables-test-allowed-diff.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/qtest/bios-tables-test-allowed-diff.h b/tests/qtest/bios= -tables-test-allowed-diff.h index dfb8523c8b..c5167f48af 100644 --- a/tests/qtest/bios-tables-test-allowed-diff.h +++ b/tests/qtest/bios-tables-test-allowed-diff.h @@ -1 +1,12 @@ /* List of comma-separated changed AML files to ignore */ +"tests/data/acpi/q35/DSDT", +"tests/data/acpi/q35/DSDT.tis", +"tests/data/acpi/q35/DSDT.bridge", +"tests/data/acpi/q35/DSDT.mmio64", +"tests/data/acpi/q35/DSDT.ipmibt", +"tests/data/acpi/q35/DSDT.cphp", +"tests/data/acpi/q35/DSDT.memhp", +"tests/data/acpi/q35/DSDT.acpihmat", +"tests/data/acpi/q35/DSDT.numamem", +"tests/data/acpi/q35/DSDT.dimmpxm", +"tests/data/acpi/q35/DSDT.nohpet", --=20 MST From nobody Sat Feb 7 06:45:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626214515396393.5720530619658; Tue, 13 Jul 2021 15:15:15 -0700 (PDT) Received: from localhost ([::1]:48894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3QgM-0000qx-Am for importer@patchew.org; Tue, 13 Jul 2021 18:15:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55026) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qbl-0006ez-6N for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43038) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qbj-0007hz-F8 for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:28 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-573-8kYCzsaNMue6nogLqOMP1w-1; Tue, 13 Jul 2021 18:10:25 -0400 Received: by mail-wm1-f70.google.com with SMTP id m31-20020a05600c3b1fb02902082e9b2132so971035wms.5 for ; Tue, 13 Jul 2021 15:10:25 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id t22sm283246wmi.22.2021.07.13.15.10.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:10:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214226; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=VuLuulZoA+GBhWrc6iIgJsgWdXQ39YAw9fcUpNmdcKo=; b=SajJFllPValNOi6BrcnhCc1bi7CNfgMg8rlc3nJSLcH2BANLMgaAiapiK8GfdVtpSYo0Im NHsG2silbrQbzTRVCeFsiqrEZhLuoWV8IStH+qnH8kxxgWcSZ/bOPrWo+zJ/KC1/m41u36 xSHETX2IiTWkVl3hoWDyOZzKEZOqn64= X-MC-Unique: 8kYCzsaNMue6nogLqOMP1w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=VuLuulZoA+GBhWrc6iIgJsgWdXQ39YAw9fcUpNmdcKo=; b=pz85x6eRk4sqG7K4+gNXmfKLCnP++YYv8dBolE0T+P1GbKQLwjGFihgFp4UaPtB0eN 09jmrK00/YfmS6k4NzeC/YJcRRCD4C1nF2wIJ2qHk362xr/Yfl5g6qUlAHXGBZCuwpPS g0MoJnD5rT765rTZs1ioTvFHjguk3NinK7eXjz3hzmHmzsnakKeYxDtTRObhThUm+Y2s nx0r3Od2ZyDy93cxGYr9sFJlodkuUo0EQH57txt7cySW0A08kgBvFCgZhvBo/gnnPxm1 kaveVVBU9C/xeq+vDRe4zXsL5seJ7rQ0SkfAlNpOuhAgECT2TJOD1Jc2C19pNve//6HO XQZA== X-Gm-Message-State: AOAM5326YoQsSq9pWrz1UB9N/CmFC0n4qAPOdQHQSavsDZHzcOjEZjCM SSG3p+Nr+bl9IPCygToKrhxoqEeuHABaRbX6gyNP1o8sKLCI1c8QKv2m13GFF3tHVhAkmsXErYv PO309TpEEQhG/hs25DaJpPT4aK3u8uFF6YDRfHA4fSjFuN6zIg2/uH87Eub1a X-Received: by 2002:a5d:4c8c:: with SMTP id z12mr8775572wrs.97.1626214223610; Tue, 13 Jul 2021 15:10:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3er7tzuUYJbw3XpwF3jCBZpyvbRhVai343v77n/95LrZA9/5QsMiMTwLovw6utan8qdjXKw== X-Received: by 2002:a5d:4c8c:: with SMTP id z12mr8775543wrs.97.1626214223378; Tue, 13 Jul 2021 15:10:23 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:19 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 05/23] hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35 Message-ID: <20210713220946.212562-6-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Eduardo Habkost , Richard Henderson , Julia Suvorova , Igor Mammedov , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626214516589100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Julia Suvorova Q35 has three different types of PCI devices hot-plug: PCIe Native, SHPC Native and ACPI hot-plug. This patch changes the default choice for cold-plugged bridges from PCIe Native to ACPI Hot-plug with ability to use SHPC and PCIe Native for hot-plugged bridges. This is a list of the PCIe Native hot-plug issues that led to this change: * no racy behavior during boot (see 110c477c2ed) * no delay during deleting - after the actual power off software must wait at least 1 second before indicating about it. This case is quite important for users, it even has its own bug: https://bugzilla.redhat.com/show_bug.cgi?id=3D1594168 * no timer-based behavior - in addition to the previous example, the attention button has a 5-second waiting period, during which the operation can be canceled with a second press. While this looks fine for manual button control, automation will result in the need to queue or drop events, and the software receiving events in all sort of unspecified combinations of attention/power indicator states, which is racy and uppredictable. * fixes: * https://bugzilla.redhat.com/show_bug.cgi?id=3D1752465 * https://bugzilla.redhat.com/show_bug.cgi?id=3D1690256 To return to PCIe Native hot-plug: -global ICH9-LPC.acpi-pci-hotplug-with-bridge-support=3Doff Known issue: older linux guests need the following flag to allow hotplugged pci express devices to use io: -device pcie-root-port,io-reserve=3D4096. io is unusual for pci express so this seems minor. We'll fix this by a follow up patch. Signed-off-by: Julia Suvorova Reviewed-by: Igor Mammedov Message-Id: <20210713004205.775386-6-jusual@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: David Gibson --- hw/acpi/ich9.c | 2 +- hw/i386/pc.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c index 2f4eb453ac..778e27b659 100644 --- a/hw/acpi/ich9.c +++ b/hw/acpi/ich9.c @@ -427,7 +427,7 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs = *pm) pm->disable_s3 =3D 0; pm->disable_s4 =3D 0; pm->s4_val =3D 2; - pm->use_acpi_hotplug_bridge =3D false; + pm->use_acpi_hotplug_bridge =3D true; =20 object_property_add_uint32_ptr(obj, ACPI_PM_PROP_PM_IO_BASE, &pm->pm_io_base, OBJ_PROP_FLAG_READ); diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 8e1220db72..7e03848792 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -98,6 +98,7 @@ GlobalProperty pc_compat_6_0[] =3D { { "qemu64" "-" TYPE_X86_CPU, "family", "6" }, { "qemu64" "-" TYPE_X86_CPU, "model", "6" }, { "qemu64" "-" TYPE_X86_CPU, "stepping", "3" }, + { "ICH9-LPC", "acpi-pci-hotplug-with-bridge-support", "off" }, }; const size_t pc_compat_6_0_len =3D G_N_ELEMENTS(pc_compat_6_0); =20 --=20 MST From nobody Sat Feb 7 06:45:13 2026 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=1626215421; cv=none; d=zohomail.com; s=zohoarc; b=fdAqsy9uvksn74F6krKHD3c0f6WaXim9SMUD4A7zPfhA3awW5W/8lktUE1OCCZb9LJdE8o5ThT8agSXTzoeV+3w7KWOQLzsvnygOYolWpCeTQ9Yhu0M5tGRvP3l0udLvVGLXc/K9A8OEmElogn2Q03I8vsH/tU4qKMzV/waXjKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626215421; h=Content-Type:Cc: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=pxbNJIFUIVQZ8eiUNei7sLj1LzsgmxfPLrXR8qYMHRc=; b=k8+xtVTuiDzYOKYL7AdDf3NcGons8Ju2Cl8kgBksE14ue1sdb/hkyK150JNNqKjEreBsOIK5OkKrhq13jc3ycbBC4rjK2rOGWJxRuvp1ZnKo4a1niiph3KIlpTocYmi7G7YfuPVnhUk50CCntXzMcv6jHRrqugNS2kVNFjqI5Vc= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626215421545949.7996639397278; Tue, 13 Jul 2021 15:30:21 -0700 (PDT) Received: from localhost ([::1]:38784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3Qux-0006dO-TT for importer@patchew.org; Tue, 13 Jul 2021 18:30:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QeH-0004RO-2u for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:13:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34860) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QeE-0001EA-71 for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:13:04 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-158-8GxZs48vPIuVxosVoPVpow-1; Tue, 13 Jul 2021 18:10:29 -0400 Received: by mail-wm1-f70.google.com with SMTP id j141-20020a1c23930000b0290212502cb19aso158120wmj.0 for ; Tue, 13 Jul 2021 15:10:28 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id m4sm139422wrs.14.2021.07.13.15.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:10:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214381; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=pxbNJIFUIVQZ8eiUNei7sLj1LzsgmxfPLrXR8qYMHRc=; b=HJlOKwXWEQvxozkYlk6q1fy2zOkVwzOI6hH7m+jKCdrKQfn5Zy6GyRuY6On6TVlVyQI2C+ XkAXDJm2IBxzzYsshsIYeu0wOIQqyMqjoGSnkqbvWQPDVAAUpLwN4EGu1i6bo7O1GOT+YC AGoaNZ4n8UJ1EufHDMpIKyJxYg7opZE= X-MC-Unique: 8GxZs48vPIuVxosVoPVpow-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=pxbNJIFUIVQZ8eiUNei7sLj1LzsgmxfPLrXR8qYMHRc=; b=C4mVZgJrhgi1VVcZeVMbDRP216husQaP3iEtWWJOkcDueeOd9MO8dF2N0+IrIqsPt9 0TmrrD/TcyCWf8rEr8+h49i37SRLiKz/9OqGBNnIbcCVe8RrLTiWI7fYrKKRhvRv3eGf v92AgGd7gB0L5PcShg7+eInv8nLkxDuZu/ut3zOQjMF9yiOtifzBkI+jeLxwApUMKBah YhEUye/h1BrQCiqkHEfDRUYW+OJnXQGLQKmZIKEr0mSQDYvL38jYS1x1EwoNnGn5hXBx q3u4GYqlxyELw3B0Uzufjv5K+Z6zJ5EAkZ1pnjzrbQ2W29f38lK+AbHtBOBr5aRF+8Dk IUgQ== X-Gm-Message-State: AOAM533Vjf0SSoOYPPuWEq1l7G5mgPw9+RqEX5WBWJrFVLtOGzf6BV73 Ldl+9FmAXSSeIjHcoetSKSjf1NpmWokbJ8j+pNMZqJBwXflDo3MYNi98dm35PYq3MssbGmx9mwC PEzFAOMq442CPuYjmPmuXZLKAAnnrHDhNDnsx+Acv23tth9fj/MCwrASFNhex X-Received: by 2002:a05:600c:35c6:: with SMTP id r6mr438074wmq.14.1626214227439; Tue, 13 Jul 2021 15:10:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTimTJLLtcm+wbG00Bcal5xpgAD+oLCH35a+nZ86gZ+ktKf4BGakLouxCo9ljBzFhrXb4VaQ== X-Received: by 2002:a05:600c:35c6:: with SMTP id r6mr438051wmq.14.1626214227117; Tue, 13 Jul 2021 15:10:27 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:23 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 06/23] bios-tables-test: Update golden binaries Message-ID: <20210713220946.212562-7-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Julia Suvorova , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1626215423769100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Julia Suvorova Add ACPI hot-plug registers to DSDT Q35 tables. Changes in the tables: + Scope (_SB.PCI0) + { + OperationRegion (PCST, SystemIO, 0x0CC4, 0x08) + Field (PCST, DWordAcc, NoLock, WriteAsZeros) + { + PCIU, 32, + PCID, 32 + } + + OperationRegion (SEJ, SystemIO, 0x0CCC, 0x04) + Field (SEJ, DWordAcc, NoLock, WriteAsZeros) + { + B0EJ, 32 + } + + OperationRegion (BNMR, SystemIO, 0x0CD4, 0x08) + Field (BNMR, DWordAcc, NoLock, WriteAsZeros) + { + BNUM, 32, + PIDX, 32 + } + + Mutex (BLCK, 0x00) + Method (PCEJ, 2, NotSerialized) + { + Acquire (BLCK, 0xFFFF) + BNUM =3D Arg0 + B0EJ =3D (One << Arg1) + Release (BLCK) + Return (Zero) + } + + Method (AIDX, 2, NotSerialized) + { + Acquire (BLCK, 0xFFFF) + BNUM =3D Arg0 + PIDX =3D (One << Arg1) + Local0 =3D PIDX /* \_SB_.PCI0.PIDX */ + Release (BLCK) + Return (Local0) + } + + Method (PDSM, 6, Serialized) + { + If ((Arg0 =3D=3D ToUUID ("e5c937d0-3553-4d7a-9117-ea4d19c3434d= ") /* Device Labeling Interface */)) + { + Local0 =3D AIDX (Arg4, Arg5) + If ((Arg2 =3D=3D Zero)) + { + If ((Arg1 =3D=3D 0x02)) + { + If (!((Local0 =3D=3D Zero) | (Local0 =3D=3D 0xFFFF= FFFF))) + { + Return (Buffer (One) + { + 0x81 = // . + }) + } + } + + Return (Buffer (One) + { + 0x00 = // . + }) + } + ElseIf ((Arg2 =3D=3D 0x07)) + { + Local1 =3D Package (0x02) + { + Zero, + "" + } + Local1 [Zero] =3D Local0 + Return (Local1) + } + } + } + } + ... Scope (_GPE) { Name (_HID, "ACPI0006" /* GPE Block Device */) // _HID: Hardware = ID + Method (_E01, 0, NotSerialized) // _Exx: Edge-Triggered GPE, xx= =3D0x00-0xFF + { + Acquire (\_SB.PCI0.BLCK, 0xFFFF) + \_SB.PCI0.PCNT () + Release (\_SB.PCI0.BLCK) + } ... + + Device (PHPR) + { + Name (_HID, "PNP0A06" /* Generic Container Device */) // _HID= : Hardware ID + Name (_UID, "PCI Hotplug resources") // _UID: Unique ID + Name (_STA, 0x0B) // _STA: Status + Name (_CRS, ResourceTemplate () // _CRS: Current Resource Set= tings + { + IO (Decode16, + 0x0CC4, // Range Minimum + 0x0CC4, // Range Maximum + 0x01, // Alignment + 0x18, // Length + ) + }) + } } ... And if there is a port in configuration: Device (S10) { Name (_ADR, 0x00020000) // _ADR: Address + Name (BSEL, Zero) + Device (S00) + { + Name (_SUN, Zero) // _SUN: Slot User Number + Name (_ADR, Zero) // _ADR: Address + Method (_EJ0, 1, NotSerialized) // _EJx: Eject Device= , x=3D0-9 + { + PCEJ (BSEL, _SUN) + } + + Method (_DSM, 4, Serialized) // _DSM: Device-Specific= Method + { + Return (PDSM (Arg0, Arg1, Arg2, Arg3, BSEL, _SUN)) + } + } + ... + Method (DVNT, 2, NotSerialized) + { + If ((Arg0 & One)) + { + Notify (S00, Arg1) + } ... Signed-off-by: Julia Suvorova Message-Id: <20210713004205.775386-7-jusual@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/qtest/bios-tables-test-allowed-diff.h | 11 ----------- tests/data/acpi/q35/DSDT | Bin 7859 -> 8289 bytes tests/data/acpi/q35/DSDT.acpihmat | Bin 9184 -> 9614 bytes tests/data/acpi/q35/DSDT.bridge | Bin 7877 -> 11003 bytes tests/data/acpi/q35/DSDT.cphp | Bin 8323 -> 8753 bytes tests/data/acpi/q35/DSDT.dimmpxm | Bin 9513 -> 9943 bytes tests/data/acpi/q35/DSDT.ipmibt | Bin 7934 -> 8364 bytes tests/data/acpi/q35/DSDT.memhp | Bin 9218 -> 9648 bytes tests/data/acpi/q35/DSDT.mmio64 | Bin 8990 -> 9419 bytes tests/data/acpi/q35/DSDT.nohpet | Bin 7717 -> 8147 bytes tests/data/acpi/q35/DSDT.numamem | Bin 7865 -> 8295 bytes tests/data/acpi/q35/DSDT.tis | Bin 8465 -> 8894 bytes 12 files changed, 11 deletions(-) diff --git a/tests/qtest/bios-tables-test-allowed-diff.h b/tests/qtest/bios= -tables-test-allowed-diff.h index c5167f48af..dfb8523c8b 100644 --- a/tests/qtest/bios-tables-test-allowed-diff.h +++ b/tests/qtest/bios-tables-test-allowed-diff.h @@ -1,12 +1 @@ /* List of comma-separated changed AML files to ignore */ -"tests/data/acpi/q35/DSDT", -"tests/data/acpi/q35/DSDT.tis", -"tests/data/acpi/q35/DSDT.bridge", -"tests/data/acpi/q35/DSDT.mmio64", -"tests/data/acpi/q35/DSDT.ipmibt", -"tests/data/acpi/q35/DSDT.cphp", -"tests/data/acpi/q35/DSDT.memhp", -"tests/data/acpi/q35/DSDT.acpihmat", -"tests/data/acpi/q35/DSDT.numamem", -"tests/data/acpi/q35/DSDT.dimmpxm", -"tests/data/acpi/q35/DSDT.nohpet", diff --git a/tests/data/acpi/q35/DSDT b/tests/data/acpi/q35/DSDT index cccf92f0466fa4eaf2e9e06675b3b102c7a8eb86..842533f53e6db40935c3cdecd1d= 182edba6c17d4 100644 GIT binary patch delta 466 zcmdmN`_O^QCDauXIPPtIak zAUQdci)n%Iq}s^|43iUh{sRHS5=3DB8~#>OQ;f?=3DWf0@2A?TpzYIYyru7HSX=3DAqfOH`-McSBME?12>6O_{w~AM zs2<(q#S-8V5X2Gh;pxH~;1^)vXkf;`5g!WTIeRL2LFaQ7^vWU|F delta 57 zcmaFpu-TT&CD*D+yKS90tV5j&1XHSFZh5+Z_5Jv7JJX{>njRGK! zGf+HK0Z6zgL^lMxdc`wxpW)$RiEiWuah#nDT)lu2PJX^YjNDfs+CUsOVt(t-l7wM diff --git a/tests/data/acpi/q35/DSDT.bridge b/tests/data/acpi/q35/DSDT.bri= dge index eb5d27d95b2cdeda5f7e1f6b151cfea02e6bd907..55ad4bd7ab4759d68031b2f1d03= 07355a7332fe7 100644 GIT binary patch delta 3198 zcmb7{PjBNy7{Ebzd(?3;ItCjk3cyfap1s>(;m2R;mDzf?)%1mvr$RXI0q}wJmcRyGxq%P zuaBe_71=3D%4P#92N&%?#cyB()e z^@POlsv^1P2^2=3DTP^p4ZwrWR0;?LkV6h_&q*Yfs(`BB~#%7@1LOn=3D=3DrDpk>4M|FMO zZeor0*IZ~Zgt!}6-edZkCAjH-)u0x_+IVS%bsM@lW1CKGzIzz=3Do2j&-{ju}g-_F)I zweK_k)Uv-AwKlSzeAei$`=3D_j%^;?SAP5%-q`jNitRSFN7yZ-pC7>!!cp`ilXu#Vl0p#rR- z)s~+Bx3VB?xEEE)-nWlrZ~wqd+Lm1?6}Fk|)lnG-`TftoXg~S#6aPgnH*=3D|8s=3D~4_ zt)9+3dyMUAd(Zr@R^R2;PtJpaCwnFHNM%f9a@naIGWX&gr+~#y-2x(*OkeaW)q;Ry zk5$moGaihZ+QYGHwoX5#a`&PnIfY_yyFhGV6oQXul%*gUG^B_G5l2BLGr}B7j2N*Y z2A`rc5ajJ}EEI_#(hy`y1_g-|BhGXlWmF-^CIy)x$V}uQn-pYL_IU8zXCp%%QV^Mf z$k7=3D^kN00OWsV?oks(_YL?MO}fx#{J0)};qh9p6dL4h2~t$ii62I7X3zXvENNGWg_m1cDSPNQxk-n~+-> zyA))R7>gl;Pr0B$kX;IrCP+GRkP-#aLk4GhbO;4mq999=3D8RaktSMCtxPIL$b$q*wG zmBAf@hGdx_%TXbYK|!*_$WF=3DN{f(@@2ACA&E?lZtPL|bof*dM;kuPGKeUd;ZsM#d zu%~z`X?4}JrXr#!hC%`X$C$v8QIMm7fZaQA@+ipJ1F^};>Yzd^dDcuYYzcO_P+?OK z2OhQsn@;FqW3YRK3R{DHAXL~KEa;)a_F!oa6}AU!EN^ue&YE!Y5*QS~f=3DOEJYrHw| zCDgEvk(T@Vm9L?O<%RrwU%&GAP{XVzzth)6J}Bt-873oDfV1FJoLB>m{f0R*(AaZx z$j83Jt2^-XsE7PL(C|hL{0?dyR(%c6xvb6bAde3lzZ8VttC4dw%|4LxXsZct@8Y9tH*`1^^Ot5>o&G diff --git a/tests/data/acpi/q35/DSDT.cphp b/tests/data/acpi/q35/DSDT.cphp index e55d12990c98d8eed760b858ce18a036b612da1c..ccde2add9f87db0c0eaf0cc1557= 17d5744e4ef40 100644 GIT binary patch delta 466 zcmZp6+~~sP66_LUsKmg)=3D(&;WH&eZUpP*iRuv2`1v!_9HLx6K|2qX6q9xjgPMgb7V z87LmA03=3D)#q8ox;z2X_U&+u@uL^pDSIL=3DN6u3kV1CqLgHM(!&RZ6J=3DblV7N>LV%}B zghDi|3JX7L{X5Lv2h8IU|1-=3DKy-2z7khyaD-#1RLt;TfM$Fl2~Uj?rg^g&M>|NCE-Qej(B7NCF@g0=3D}Y~kIV5h zsz*0@u>^Po1aZWBc)IWg_yrg^8kjL~#D{`-&YlV$`6UH8rRkG5%FD7H;W@&?C^7kp Zd?uG4OAN?D0XLS(ZVI;SB5WXA7y#g;hnxTa delta 57 zcmdn!((K6P66_MvtiZs)7_^b=3DH`8VnmetaXB9kx53o{Ei3T{?Z;Afm%qnOU=3D#u5`B N>=3DZ9xH~FoiEdbPr5E}ph diff --git a/tests/data/acpi/q35/DSDT.dimmpxm b/tests/data/acpi/q35/DSDT.di= mmpxm index 95901f94c0d445919cb84dd1f6d98c646ae8176e..b062e30117f955c7a2ac9629a05= 12324bbd28bf2 100644 GIT binary patch delta 500 zcmZ4Kb=3D{ZCCDauXIPPtIak zAUQdci)n%Iq}s^|43iUh{sRHS5=3DB8~#>OQ;f?=3DWf0@2A?T6g=3D`v3UW%*Cx@%ZvK`?$!ow&rxk@FI%a0`nG&EEVc?F8u9J{t{m|mo-VwO&H~3^jZa^I-tdz5?tSm&`@XmD^P=3DGxwR;r+n0^pBTugx@MNxhi+R{7=3DIs)ae{Qa zZmGCv?5hOoWwZyBMU2c+h-5h%4*eE)_@@`J4R{F2alH?er92z@XJalN=3D5z3Vy`Ex3 zu;EyfL3x6oj4YpLbq~EDOFJM))3z82Qn%;S1Jsj-?1BD5 zG7Nit2HQ7IEKms&<@45*_wY1#%*wp>$N z10>s64gcM6wBDG2kzFIXF@ZZ|Yvxg(pMp7ZRT6LkS4YX%##){Q$J{#WVOLiRN5_8m iauXIPPtIak zAUQdci)n%Iq}s^|43iUh{sRHS5=3DB8~#>OQ;f?=3DWf0@2A?T<+5bHs-N?E!|mf=3D7NyK~8DaL66_Mfq{6_!cz+|;Z>G&EEL!s7BJu74t{m|mo-VwO&H4 b7bx>HPX4Wu&gsSy6CdmpFJL!0N7WVpu^|&B diff --git a/tests/data/acpi/q35/DSDT.mmio64 b/tests/data/acpi/q35/DSDT.mmi= o64 index 77d46369e48efca9a9e5024542c77cd26144beff..2e0a772a85275c9c3b4c9317d98= cc7c3d27417f3 100644 GIT binary patch delta 479 zcmZWl%}T>S7~Ji@Y1C9x)PoXRr3XPH_=3DDb>O|+>dU78kztt36!iee6WP!L;BUUlyh zp)Vjlg1v}>9()BazJiCkOBDq7Ffg<8&G3D<8_%YoJ9_1L1^`I!g|E&)Y6Qrp|k$q^kRffs;{un1nv#XYZ zO?^ipP}@dZK%T|OD27OuvtG|{aEE_-0h@q_kQ~=3DLK%UF9p?@~!;$c1q@5k%OdJOB1 zH56<|X(Kf%NN=3Dl8AI|cbbv^cJO*|sY=3DUE4bUXZ2xAef*{Ary?>oKp`_PwcS=3DI@75z zY89Gf~gPY5jIs-T>1(DGmt(vHd;|L@ije>S delta 71 zcmX@@InRyDCDauXIPPtIak zAUQdci)n%Iq}s^|43iUh{sRHS5=3DB8~#>OQ;f?=3DWf0@2A?TqMI{i_!+&To4i;8JOY9sCI|Qh7&rnA=3D7D+yKS90tV5j&1XHSFZh5+Z_5Jv7JJX{>njRGK! zGf+HK0Z6zgL^lMxdc`wxpW)$RiEiWuah#nDT)lu2PJX^YjNDfs+CUsylgPr07oIMSq8v>kzLm0V_@NjWNHwu6_ z&Oq@{1t8&~5Zw^$>J`t(eTIjNCAyIt#Bp{qaP+slXajMao%}+56#_h6 zA{3$-oqU|V8AMbAoL#+`qLo3s|NjdzKq?9<>lrf{K!!xCgT$9Gh-f>7t;daNwt#`7$zt1{09PtC5nQ~jEzfx1j9n{1)`I)xY!GXSeY1j84?Q;IuaQe zmLzUwWxg%RBR&+wbM{p5$S*0#DNUdJR#ukn2+t87Mv2J+ da+#d|nlT^?1>7e$$=3DR`quz@Vuyk9Pe2>{`!ixL0; delta 62 zcmdnzI?;*CCD (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626215108264984.4360293634809; Tue, 13 Jul 2021 15:25:08 -0700 (PDT) Received: from localhost ([::1]:52140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3Qpr-00058t-0t for importer@patchew.org; Tue, 13 Jul 2021 18:25:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qbr-0006q8-IU for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28545) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qbp-0007l3-8W for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:35 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-343-t0PmG9lbMNSJvuNdHn8qSA-1; Tue, 13 Jul 2021 18:10:31 -0400 Received: by mail-wr1-f72.google.com with SMTP id g9-20020adff3c90000b0290140a25efc6dso340271wrp.5 for ; Tue, 13 Jul 2021 15:10:31 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id o11sm262160wmq.1.2021.07.13.15.10.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:10:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214232; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=31CzBqlNtzKmeLcB0ac8hxCFBRfN/IS/yRARZnMPd0g=; b=AVEWBUpAuyr36M58HzwnXb9d5cm5hepA5PQ1UVtX5lxH5Mfe1Tuc8szqxTvhh4/bDsICWm VPwRPgu4EFlUl9DpkItrsA940uTP7j71EgOOZ8GE9CEO1ogSHaGENeJD3xgvIQInl5q027 y4PvWtJGtnIS5cc/+qaWk9Z4e/gdo0U= X-MC-Unique: t0PmG9lbMNSJvuNdHn8qSA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=31CzBqlNtzKmeLcB0ac8hxCFBRfN/IS/yRARZnMPd0g=; b=OUOyHKpgKKizUOlEeKRxDRA5OJTmJGimZu0HBNIB+9D48uu+ocYfFqNGPuk/AzGx1L B88Q/VNRaXdU5R/obPITcRtEwZ5+lacxq4afYY3B7i5PiTFCvudnU5fJ0b/kpi1Xvr4t ts8ogeMH8etyBWXSpT2EMmd+2aAO/8Yq2XFPkTXHcnhJslCf60IKpPRHo7TotG+IaQKG 6EEAXbQvCR/IHfxmF1fhiwYpzCRQnS/K/AwTKZeDse+ezeqntUwy0Z6U14UsurcuQWgZ nLs40rNBHJ+hSoosr1TAfFv+BnRgbZJifpEdLLUkgi3dOZaO8d9ANSuegQiyqZbG+hf3 B5Dg== X-Gm-Message-State: AOAM53138kTYRjj/NKt5nCDIWBxTWSctXTczK37OnaT/i/IsupDAz93f 444bbgRD2qiT03LFtA0ujWFFYLZhAUanzqGSWGhTqJXV7Yq4t+6sFiXTNHYVfayzua8ChJjWlC2 6u6A5WgI48qMvTYcK/5Vs1xpB684in6H6ld2NNrtvJaFSe2vfHKJXP1xOjPe8 X-Received: by 2002:a05:6000:18c8:: with SMTP id w8mr8439636wrq.90.1626214229918; Tue, 13 Jul 2021 15:10:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw28iSNrS22+/tL/A9phnQFLodCSOwW1EejNjMPKEdgp7fOzoWf4rvQayV8EC1g8pRs9EGHFQ== X-Received: by 2002:a05:6000:18c8:: with SMTP id w8mr8439611wrq.90.1626214229675; Tue, 13 Jul 2021 15:10:29 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:27 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 07/23] vhost-user-rng: Add vhost-user-rng implementation Message-ID: <20210713220946.212562-8-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Mathieu Poirier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1626215109930100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mathieu Poirier Following in the footsteps of what whas done for vhost-user-i2c and virtiofsd, introduce a random number generator (RNG) backend that communicates with a vhost-user server to retrieve entropy. That way another VMM could be using the same vhost-user daemon and avoid having to write yet another RNG driver. Signed-off-by: Mathieu Poirier Message-Id: <20210710005929.1702431-2-mathieu.poirier@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost-user-rng.h | 33 ++++ hw/virtio/vhost-user-rng.c | 294 +++++++++++++++++++++++++++++ hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 1 + 4 files changed, 333 insertions(+) create mode 100644 include/hw/virtio/vhost-user-rng.h create mode 100644 hw/virtio/vhost-user-rng.c diff --git a/include/hw/virtio/vhost-user-rng.h b/include/hw/virtio/vhost-u= ser-rng.h new file mode 100644 index 0000000000..071539996d --- /dev/null +++ b/include/hw/virtio/vhost-user-rng.h @@ -0,0 +1,33 @@ +/* + * Vhost-user RNG virtio device + * + * Copyright (c) 2021 Mathieu Poirier + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef _QEMU_VHOST_USER_RNG_H +#define _QEMU_VHOST_USER_RNG_H + +#include "hw/virtio/virtio.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" +#include "chardev/char-fe.h" + +#define TYPE_VHOST_USER_RNG "vhost-user-rng" +OBJECT_DECLARE_SIMPLE_TYPE(VHostUserRNG, VHOST_USER_RNG) + +struct VHostUserRNG { + /*< private >*/ + VirtIODevice parent; + CharBackend chardev; + struct vhost_virtqueue *vhost_vq; + struct vhost_dev vhost_dev; + VhostUserState vhost_user; + VirtQueue *req_vq; + bool connected; + + /*< public >*/ +}; + +#endif /* _QEMU_VHOST_USER_RNG_H */ diff --git a/hw/virtio/vhost-user-rng.c b/hw/virtio/vhost-user-rng.c new file mode 100644 index 0000000000..3825266bdf --- /dev/null +++ b/hw/virtio/vhost-user-rng.c @@ -0,0 +1,294 @@ +/* + * Vhost-user RNG virtio device + * + * Copyright (c) 2021 Mathieu Poirier + * + * Implementation seriously tailored on vhost-user-i2c.c + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/virtio-bus.h" +#include "hw/virtio/vhost-user-rng.h" +#include "qemu/error-report.h" +#include "standard-headers/linux/virtio_ids.h" + +static void vu_rng_start(VirtIODevice *vdev) +{ + VHostUserRNG *rng =3D VHOST_USER_RNG(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + int i; + + if (!k->set_guest_notifiers) { + error_report("binding does not support guest notifiers"); + return; + } + + ret =3D vhost_dev_enable_notifiers(&rng->vhost_dev, vdev); + if (ret < 0) { + error_report("Error enabling host notifiers: %d", -ret); + return; + } + + ret =3D k->set_guest_notifiers(qbus->parent, rng->vhost_dev.nvqs, true= ); + if (ret < 0) { + error_report("Error binding guest notifier: %d", -ret); + goto err_host_notifiers; + } + + rng->vhost_dev.acked_features =3D vdev->guest_features; + ret =3D vhost_dev_start(&rng->vhost_dev, vdev); + if (ret < 0) { + error_report("Error starting vhost-user-rng: %d", -ret); + goto err_guest_notifiers; + } + + /* + * guest_notifier_mask/pending not used yet, so just unmask + * everything here. virtio-pci will do the right thing by + * enabling/disabling irqfd. + */ + for (i =3D 0; i < rng->vhost_dev.nvqs; i++) { + vhost_virtqueue_mask(&rng->vhost_dev, vdev, i, false); + } + + return; + +err_guest_notifiers: + k->set_guest_notifiers(qbus->parent, rng->vhost_dev.nvqs, false); +err_host_notifiers: + vhost_dev_disable_notifiers(&rng->vhost_dev, vdev); +} + +static void vu_rng_stop(VirtIODevice *vdev) +{ + VHostUserRNG *rng =3D VHOST_USER_RNG(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + + if (!k->set_guest_notifiers) { + return; + } + + vhost_dev_stop(&rng->vhost_dev, vdev); + + ret =3D k->set_guest_notifiers(qbus->parent, rng->vhost_dev.nvqs, fals= e); + if (ret < 0) { + error_report("vhost guest notifier cleanup failed: %d", ret); + return; + } + + vhost_dev_disable_notifiers(&rng->vhost_dev, vdev); +} + +static void vu_rng_set_status(VirtIODevice *vdev, uint8_t status) +{ + VHostUserRNG *rng =3D VHOST_USER_RNG(vdev); + bool should_start =3D status & VIRTIO_CONFIG_S_DRIVER_OK; + + if (!vdev->vm_running) { + should_start =3D false; + } + + if (rng->vhost_dev.started =3D=3D should_start) { + return; + } + + if (should_start) { + vu_rng_start(vdev); + } else { + vu_rng_stop(vdev); + } +} + +static uint64_t vu_rng_get_features(VirtIODevice *vdev, + uint64_t requested_features, Error **e= rrp) +{ + /* No feature bits used yet */ + return requested_features; +} + +static void vu_rng_handle_output(VirtIODevice *vdev, VirtQueue *vq) +{ + /* + * Not normally called; it's the daemon that handles the queue; + * however virtio's cleanup path can call this. + */ +} + +static void vu_rng_guest_notifier_mask(VirtIODevice *vdev, int idx, bool m= ask) +{ + VHostUserRNG *rng =3D VHOST_USER_RNG(vdev); + + vhost_virtqueue_mask(&rng->vhost_dev, vdev, idx, mask); +} + +static bool vu_rng_guest_notifier_pending(VirtIODevice *vdev, int idx) +{ + VHostUserRNG *rng =3D VHOST_USER_RNG(vdev); + + return vhost_virtqueue_pending(&rng->vhost_dev, idx); +} + +static void vu_rng_connect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserRNG *rng =3D VHOST_USER_RNG(vdev); + + if (rng->connected) { + return; + } + + rng->connected =3D true; + + /* restore vhost state */ + if (virtio_device_started(vdev, vdev->status)) { + vu_rng_start(vdev); + } +} + +static void vu_rng_disconnect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserRNG *rng =3D VHOST_USER_RNG(vdev); + + if (!rng->connected) { + return; + } + + rng->connected =3D false; + + if (rng->vhost_dev.started) { + vu_rng_stop(vdev); + } +} + +static void vu_rng_event(void *opaque, QEMUChrEvent event) +{ + DeviceState *dev =3D opaque; + + switch (event) { + case CHR_EVENT_OPENED: + vu_rng_connect(dev); + break; + case CHR_EVENT_CLOSED: + vu_rng_disconnect(dev); + break; + case CHR_EVENT_BREAK: + case CHR_EVENT_MUX_IN: + case CHR_EVENT_MUX_OUT: + /* Ignore */ + break; + } +} + +static void vu_rng_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserRNG *rng =3D VHOST_USER_RNG(dev); + int ret; + + if (!rng->chardev.chr) { + error_setg(errp, "missing chardev"); + return; + } + + if (!vhost_user_init(&rng->vhost_user, &rng->chardev, errp)) { + return; + } + + virtio_init(vdev, "vhost-user-rng", VIRTIO_ID_RNG, 0); + + rng->req_vq =3D virtio_add_queue(vdev, 4, vu_rng_handle_output); + if (!rng->req_vq) { + error_setg_errno(errp, -1, "virtio_add_queue() failed"); + goto virtio_add_queue_failed; + } + + rng->vhost_dev.nvqs =3D 1; + rng->vhost_dev.vqs =3D g_new0(struct vhost_virtqueue, rng->vhost_dev.n= vqs); + if (!rng->vhost_dev.vqs) { + error_setg_errno(errp, -1, "memory allocation failed"); + goto vhost_dev_init_failed; + } + + ret =3D vhost_dev_init(&rng->vhost_dev, &rng->vhost_user, + VHOST_BACKEND_TYPE_USER, 0, errp); + if (ret < 0) { + error_setg_errno(errp, -ret, "vhost_dev_init() failed"); + goto vhost_dev_init_failed; + } + + qemu_chr_fe_set_handlers(&rng->chardev, NULL, NULL, vu_rng_event, NULL, + dev, NULL, true); + + return; + +vhost_dev_init_failed: + virtio_delete_queue(rng->req_vq); +virtio_add_queue_failed: + virtio_cleanup(vdev); + vhost_user_cleanup(&rng->vhost_user); +} + +static void vu_rng_device_unrealize(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserRNG *rng =3D VHOST_USER_RNG(dev); + + vu_rng_set_status(vdev, 0); + + vhost_dev_cleanup(&rng->vhost_dev); + g_free(rng->vhost_dev.vqs); + rng->vhost_dev.vqs =3D NULL; + virtio_delete_queue(rng->req_vq); + virtio_cleanup(vdev); + vhost_user_cleanup(&rng->vhost_user); +} + +static const VMStateDescription vu_rng_vmstate =3D { + .name =3D "vhost-user-rng", + .unmigratable =3D 1, +}; + +static Property vu_rng_properties[] =3D { + DEFINE_PROP_CHR("chardev", VHostUserRNG, chardev), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vu_rng_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + + device_class_set_props(dc, vu_rng_properties); + dc->vmsd =3D &vu_rng_vmstate; + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + + vdc->realize =3D vu_rng_device_realize; + vdc->unrealize =3D vu_rng_device_unrealize; + vdc->get_features =3D vu_rng_get_features; + vdc->set_status =3D vu_rng_set_status; + vdc->guest_notifier_mask =3D vu_rng_guest_notifier_mask; + vdc->guest_notifier_pending =3D vu_rng_guest_notifier_pending; +} + +static const TypeInfo vu_rng_info =3D { + .name =3D TYPE_VHOST_USER_RNG, + .parent =3D TYPE_VIRTIO_DEVICE, + .instance_size =3D sizeof(VHostUserRNG), + .class_init =3D vu_rng_class_init, +}; + +static void vu_rng_register_types(void) +{ + type_register_static(&vu_rng_info); +} + +type_init(vu_rng_register_types) diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index 0eda25c4e1..69066ab14e 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -58,3 +58,8 @@ config VIRTIO_MEM depends on LINUX depends on VIRTIO_MEM_SUPPORTED select MEM_DEVICE + +config VHOST_USER_RNG + bool + default y + depends on VIRTIO && VHOST_USER diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index fbff9bc9d4..e386791f2a 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -25,6 +25,7 @@ virtio_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: f= iles('vhost-user-vsock. virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu.c'= )) virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) +virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rn= g.c')) =20 virtio_pci_ss =3D ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-= pci.c')) --=20 MST From nobody Sat Feb 7 06:45:13 2026 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=1626214468; cv=none; d=zohomail.com; s=zohoarc; b=U3CVNLm6rk5aeJ25EyZs/OE+KEvMCxOqaVEcEvEGOF2I2ZqZwl1GmKv2PnJAUYQSj9a/zpizn7UOzZtOYewHUnkqkJP51+Ne/tm6O0MEFcE6ZhBS9QzMWOFtuzwA+Ch2wcOabGZkhKM3BI25CAr8XpB+xttcP5vp5ar8yXfLHOM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626214468; h=Content-Type:Cc: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=eLX+VgoliycDY7YdStrkhro6BU4WBbY46NLKml+nghU=; b=PJDniWe2qB9dfqa/0/z3GCziMh75XrbuPqJT5aBitoDhNd/pek9e1IPQ+mPiEmB/94tl2wmqx5h/7wxe/2KXIMMks/sD7h1YyGh6yRlQceZl+Dhl5rHp9x0fedM5XN4niarru/aQefPkrLwJBc7Yr4QlJUMkgXwi3PL5v+WludU= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626214468169141.17101686753176; Tue, 13 Jul 2021 15:14:28 -0700 (PDT) Received: from localhost ([::1]:46186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3Qfa-0007RV-2v for importer@patchew.org; Tue, 13 Jul 2021 18:14:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55062) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qbt-0006vl-UQ for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47302) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qbs-0007no-3l for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:37 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-379-sX_8-amNOpyT8qD3Zi5LPA-1; Tue, 13 Jul 2021 18:10:34 -0400 Received: by mail-wm1-f71.google.com with SMTP id j141-20020a1c23930000b0290212502cb19aso158219wmj.0 for ; Tue, 13 Jul 2021 15:10:33 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id p8sm2301318wmc.24.2021.07.13.15.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:10:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214235; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=eLX+VgoliycDY7YdStrkhro6BU4WBbY46NLKml+nghU=; b=AmjupiUIUqoooYzmNrXL0ezqaENZ0ZIKqhP4IL5kipdTeW8u6hWA3TxjuvnN6qVXAgjf/X YX6hYpsDpb50YFzOe+PYt/45HrB67RN7m7j1gXbLpSLtdvHcbkw3HBBTe41s+ZGHECiqcw tTKFSjWO0toL6GN0wNMeLxG3Kvg15rA= X-MC-Unique: sX_8-amNOpyT8qD3Zi5LPA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=eLX+VgoliycDY7YdStrkhro6BU4WBbY46NLKml+nghU=; b=C4F2srtPOO/V6knECowZke38JAxkHVVmNV/Mbi4uUQtbiwIByY4mWHtj0noYDPUrNp wyMTRvjaGI3iOIgIGszu0l4wYwOY+D3lxdoNhVvKt1S6FRIZ2BCLVzq4ddQZoJtjaiCR tRM5UN8Wq2alcAUu+Y63OFFuK9koXUZUrfLkWbc7hnVoTaJd1ZzmE1euYFOmqy3kWao2 LGnP2dQMK4ZRA6z+jmupJTH7QJpamcEozAOCkns4l/TDhwY+IuQWL7p9GY8ogywXDx33 fBnAntsvT5jFpZfpcoaUnet0J5KF2rZg6/zj2i/Orr8XvneMlLPH/ioP4QFUQWwuklec 1B8A== X-Gm-Message-State: AOAM5335W3c9wLQIYPxNCDLbIcBWkauXnx4bLsorjqweVAzBTf8+YVZF CYGPpCmM/iOl9a9vbFyUi6lFudzuNwXSIH0t3l4QNp9lEhcmzhtAqAj2jMgZTOY+04HunEnnzNV 2dmxZ4J1EpbWEPdogFyUbw4lB+tT9Nn0/c9Z3Z/NO0uDqq2rxentiMlLgPgGy X-Received: by 2002:a05:6000:186e:: with SMTP id d14mr8324503wri.188.1626214232629; Tue, 13 Jul 2021 15:10:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUplZTwTOLisY1PJs8SS7eVghIV4Pw/DeumgnouRIpeqnqAgzL3givlRB/WkKYp8JazXpmbQ== X-Received: by 2002:a05:6000:186e:: with SMTP id d14mr8324479wri.188.1626214232350; Tue, 13 Jul 2021 15:10:32 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:29 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 08/23] vhost-user-rng-pci: Add vhost-user-rng-pci implementation Message-ID: <20210713220946.212562-9-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Mathieu Poirier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1626214468703100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mathieu Poirier This patch provides a PCI bus interface to the vhost-user-rng backed. The implentation is similar to what was done for vhost-user-i2c-pci and vhost-user-fs-pci. Signed-off-by: Mathieu Poirier Message-Id: <20210710005929.1702431-3-mathieu.poirier@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-user-rng-pci.c | 79 ++++++++++++++++++++++++++++++++++ hw/virtio/meson.build | 1 + 2 files changed, 80 insertions(+) create mode 100644 hw/virtio/vhost-user-rng-pci.c diff --git a/hw/virtio/vhost-user-rng-pci.c b/hw/virtio/vhost-user-rng-pci.c new file mode 100644 index 0000000000..ffff2de39f --- /dev/null +++ b/hw/virtio/vhost-user-rng-pci.c @@ -0,0 +1,79 @@ +/* + * Vhost-user RNG virtio device PCI glue + * + * Copyright (c) 2021 Mathieu Poirier + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/vhost-user-rng.h" +#include "virtio-pci.h" + +struct VHostUserRNGPCI { + VirtIOPCIProxy parent_obj; + VHostUserRNG vdev; +}; + +typedef struct VHostUserRNGPCI VHostUserRNGPCI; + +#define TYPE_VHOST_USER_RNG_PCI "vhost-user-rng-pci-base" + +DECLARE_INSTANCE_CHECKER(VHostUserRNGPCI, VHOST_USER_RNG_PCI, + TYPE_VHOST_USER_RNG_PCI) + +static Property vhost_user_rng_pci_properties[] =3D { + DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, + DEV_NVECTORS_UNSPECIFIED), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vhost_user_rng_pci_realize(VirtIOPCIProxy *vpci_dev, Error **e= rrp) +{ + VHostUserRNGPCI *dev =3D VHOST_USER_RNG_PCI(vpci_dev); + DeviceState *vdev =3D DEVICE(&dev->vdev); + + if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { + vpci_dev->nvectors =3D 1; + } + + qdev_realize(vdev, BUS(&vpci_dev->bus), errp); +} + +static void vhost_user_rng_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k =3D PCI_DEVICE_CLASS(klass); + k->realize =3D vhost_user_rng_pci_realize; + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + device_class_set_props(dc, vhost_user_rng_pci_properties); + pcidev_k->vendor_id =3D PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id =3D 0; /* Set by virtio-pci based on virtio id */ + pcidev_k->revision =3D 0x00; + pcidev_k->class_id =3D PCI_CLASS_COMMUNICATION_OTHER; +} + +static void vhost_user_rng_pci_instance_init(Object *obj) +{ + VHostUserRNGPCI *dev =3D VHOST_USER_RNG_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VHOST_USER_RNG); +} + +static const VirtioPCIDeviceTypeInfo vhost_user_rng_pci_info =3D { + .base_name =3D TYPE_VHOST_USER_RNG_PCI, + .non_transitional_name =3D "vhost-user-rng-pci", + .instance_size =3D sizeof(VHostUserRNGPCI), + .instance_init =3D vhost_user_rng_pci_instance_init, + .class_init =3D vhost_user_rng_pci_class_init, +}; + +static void vhost_user_rng_pci_register(void) +{ + virtio_pci_types_register(&vhost_user_rng_pci_info); +} + +type_init(vhost_user_rng_pci_register); diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index e386791f2a..1430b370e6 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -26,6 +26,7 @@ virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('= virtio-rng.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu.c'= )) virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rn= g.c')) +virtio_ss.add(when: ['CONFIG_VHOST_USER_RNG', 'CONFIG_VIRTIO_PCI'], if_tru= e: files('vhost-user-rng-pci.c')) =20 virtio_pci_ss =3D ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-= pci.c')) --=20 MST From nobody Sat Feb 7 06:45:13 2026 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=1626214506; cv=none; d=zohomail.com; s=zohoarc; b=j1lYTAKuaXNCKIotpwEazgxYTMitOX4ZPZwyhJfIkDnDlmazUuA4ZvC7R6rO30z0qJX4jQKyyaSeG3zQ3h7kED3Xy5SM+FJrQSbIRxBGUlBJ/IVX9qKRgKycG5OsM+rVqYHm+wbQX/yZ01TJtzR1nB+fc+zJXUJ88avp6j0Wfyo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626214506; h=Content-Type:Cc: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=Nwt5D+O37EI9JTIj95dT3HENULJgFW8wgXA6wdMi6G4=; b=Ywtb4vnShdBsdVP4FTvkNHr7U0XRwKw+YxHPu4TnFLmsU5d7/i7p1K479mdS9zzFvqMrIpIqqj4Go5MkICidIAh4IhPsT1KyucbmPL9ZczksNHTIKwBhwq9NsxwzgFRhYz41R7lAvu0yku0epaletZ09uWTPIF40V+bKtWghJ6E= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626214506669673.1190565974596; Tue, 13 Jul 2021 15:15:06 -0700 (PDT) Received: from localhost ([::1]:48412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3QgD-0000Xo-9p for importer@patchew.org; Tue, 13 Jul 2021 18:15:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qbz-000790-2S for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41199) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qbw-0007sl-Gr for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:42 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-216-e7LWc6DVPvydKmiXZ57SmA-1; Tue, 13 Jul 2021 18:10:37 -0400 Received: by mail-wm1-f71.google.com with SMTP id o18-20020a05600c5112b029022c3d638485so152796wms.2 for ; Tue, 13 Jul 2021 15:10:37 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id r67sm3519406wma.6.2021.07.13.15.10.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214239; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Nwt5D+O37EI9JTIj95dT3HENULJgFW8wgXA6wdMi6G4=; b=d5fPJJ26iQUCnJ4UeE2b3B+0ZVjrdGRSiZ5OwpGV3wAC6fhcm7nx73hL+bUXJCTsSZjWQ4 lM8mWOSh4C7y/ooLd3Yf6slXv/0zwVDKggm7tl2NBOZIFFFprW8zY/dx6xJtusTdG2wc62 eEF41JfLKYdCnkbAmLionyUsBZHWkHg= X-MC-Unique: e7LWc6DVPvydKmiXZ57SmA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Nwt5D+O37EI9JTIj95dT3HENULJgFW8wgXA6wdMi6G4=; b=UCmvoh9YrASO/jCVTqQ7lW7oiMAT3hbkO9JxS2tXCnyTwTeBj9uIXzySCpqEyNc4bA 7gqVEafwhaok6c3Kirr92VcZvdcOfAFB9ZPQEoyjJiedPUDjvshOKurNJq4AptZyGcVL gvg1fNN4RLUE0nceJlQqN+PhH+n1XCgDmLBwi18EQs+aE/PWhDHGWhC/bVpftduyCR7T IS4jCwojIxe84ws4uy5JBu1toaXuxpWpcFgQlwBeah94A9UpfH58n0BRuqcDlvmLMAP7 0q1aZ/7RI6XPvQGn5f5zwtTFwMjUjam7Q/F1IZ4kNtMEgGjl3WzcapSV1ggd7CD3DmQx P0ZQ== X-Gm-Message-State: AOAM532lSJyBIC3RPgMl2KqcITIoga+dnpNVgf8hFstVRf8OMol646xu z8SdKqvOww6tLSVm45peExhQnUhAtYknD93cY5xfwsvt3J28zCl2go2qiJPUvD5rENm602WWLIN R6hDHe6O6r2WM5sCPbAxzhbpvgIjDDqfonkXte8TXSzsMaaIMcw3pwYvQe4aK X-Received: by 2002:adf:ef03:: with SMTP id e3mr4631557wro.316.1626214236234; Tue, 13 Jul 2021 15:10:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxW00VrdTOq2oANYkw9E9UGdXbTDqBeeELVxciXwJ0gbuOu9W4I/2J/s1gKWUCDKzcpZCHNyw== X-Received: by 2002:adf:ef03:: with SMTP id e3mr4631524wro.316.1626214235925; Tue, 13 Jul 2021 15:10:35 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:32 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 09/23] vhost-user-rng: backend: Add RNG vhost-user daemon implementation Message-ID: <20210713220946.212562-10-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Mathieu Poirier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1626214507619100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mathieu Poirier This patch provides the vhost-user backend implementation to work in tandem with the vhost-user-rng implementation of the QEMU VMM. It uses the vhost-user API so that other VMM can re-use the interface without having to write the driver again. Signed-off-by: Mathieu Poirier Message-Id: <20210710005929.1702431-4-mathieu.poirier@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tools/vhost-user-rng/main.c | 403 +++++++++++++++++++++++ tools/meson.build | 8 + tools/vhost-user-rng/50-qemu-rng.json.in | 5 + tools/vhost-user-rng/meson.build | 10 + 4 files changed, 426 insertions(+) create mode 100644 tools/vhost-user-rng/main.c create mode 100644 tools/vhost-user-rng/50-qemu-rng.json.in create mode 100644 tools/vhost-user-rng/meson.build diff --git a/tools/vhost-user-rng/main.c b/tools/vhost-user-rng/main.c new file mode 100644 index 0000000000..c3b8f69227 --- /dev/null +++ b/tools/vhost-user-rng/main.c @@ -0,0 +1,403 @@ +/* + * VIRTIO RNG Emulation via vhost-user + * + * Copyright (c) 2021 Mathieu Poirier + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#define G_LOG_DOMAIN "vhost-user-rng" +#define G_LOG_USE_STRUCTURED 1 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qemu/cutils.h" +#include "subprojects/libvhost-user/libvhost-user-glib.h" +#include "subprojects/libvhost-user/libvhost-user.h" + +#ifndef container_of +#define container_of(ptr, type, member) ({ \ + const typeof(((type *) 0)->member) * __mptr =3D (ptr); \ + (type *) ((char *) __mptr - offsetof(type, member)); }) +#endif + +typedef struct { + VugDev dev; + struct itimerspec ts; + timer_t rate_limit_timer; + pthread_mutex_t rng_mutex; + pthread_cond_t rng_cond; + int64_t quota_remaining; + bool activate_timer; + GMainLoop *loop; +} VuRNG; + +static gboolean print_cap, verbose; +static gchar *source_path, *socket_path; +static gint source_fd, socket_fd =3D -1; + +/* Defaults tailored on virtio-rng.c */ +static uint32_t period_ms =3D 1 << 16; +static uint64_t max_bytes =3D INT64_MAX; + +static void check_rate_limit(union sigval sv) +{ + VuRNG *rng =3D sv.sival_ptr; + bool wakeup =3D false; + + pthread_mutex_lock(&rng->rng_mutex); + /* + * The timer has expired and the guest has used all available + * entropy, which means function vu_rng_handle_request() is waiting + * on us. As such wake it up once we're done here. + */ + if (rng->quota_remaining =3D=3D 0) { + wakeup =3D true; + } + + /* + * Reset the entropy available to the guest and tell function + * vu_rng_handle_requests() to start the timer before using it. + */ + rng->quota_remaining =3D max_bytes; + rng->activate_timer =3D true; + pthread_mutex_unlock(&rng->rng_mutex); + + if (wakeup) { + pthread_cond_signal(&rng->rng_cond); + } +} + +static void setup_timer(VuRNG *rng) +{ + struct sigevent sev; + int ret; + + memset(&rng->ts, 0, sizeof(struct itimerspec)); + rng->ts.it_value.tv_sec =3D period_ms / 1000; + rng->ts.it_value.tv_nsec =3D (period_ms % 1000) * 1000000; + + /* + * Call function check_rate_limit() as if it was the start of + * a new thread when the timer expires. + */ + sev.sigev_notify =3D SIGEV_THREAD; + sev.sigev_notify_function =3D check_rate_limit; + sev.sigev_value.sival_ptr =3D rng; + /* Needs to be NULL if defaults attributes are to be used. */ + sev.sigev_notify_attributes =3D NULL; + ret =3D timer_create(CLOCK_MONOTONIC, &sev, &rng->rate_limit_timer); + if (ret < 0) { + fprintf(stderr, "timer_create() failed\n"); + } + +} + + +/* Virtio helpers */ +static uint64_t rng_get_features(VuDev *dev) +{ + if (verbose) { + g_info("%s: replying", __func__); + } + return 0; +} + +static void rng_set_features(VuDev *dev, uint64_t features) +{ + if (verbose && features) { + g_autoptr(GString) s =3D g_string_new("Requested un-handled featur= e"); + g_string_append_printf(s, " 0x%" PRIx64 "", features); + g_info("%s: %s", __func__, s->str); + } +} + +static void vu_rng_handle_requests(VuDev *dev, int qidx) +{ + VuRNG *rng =3D container_of(dev, VuRNG, dev.parent); + VuVirtq *vq =3D vu_get_queue(dev, qidx); + VuVirtqElement *elem; + size_t to_read; + int len, ret; + + for (;;) { + /* Get element in the vhost virtqueue */ + elem =3D vu_queue_pop(dev, vq, sizeof(VuVirtqElement)); + if (!elem) { + break; + } + + /* Get the amount of entropy to read from the vhost server */ + to_read =3D elem->in_sg[0].iov_len; + + pthread_mutex_lock(&rng->rng_mutex); + + /* + * We have consumed all entropy available for this time slice. + * Wait for the timer (check_rate_limit()) to tell us about the + * start of a new time slice. + */ + if (rng->quota_remaining =3D=3D 0) { + pthread_cond_wait(&rng->rng_cond, &rng->rng_mutex); + } + + /* Start the timer if the last time slice has expired */ + if (rng->activate_timer =3D=3D true) { + rng->activate_timer =3D false; + ret =3D timer_settime(rng->rate_limit_timer, 0, &rng->ts, NULL= ); + if (ret < 0) { + fprintf(stderr, "timer_settime() failed\n"); + } + } + + /* Make sure we don't read more than it's available */ + if (rng->quota_remaining < to_read) { + to_read =3D rng->quota_remaining; + } + + len =3D read(source_fd, elem->in_sg[0].iov_base, to_read); + + /* Simply return 0 if an error occurs */ + if (len < 0) { + len =3D 0; + } + + rng->quota_remaining -=3D len; + + pthread_mutex_unlock(&rng->rng_mutex); + + vu_queue_push(dev, vq, elem, len); + free(elem); + } + + vu_queue_notify(dev, vq); +} + +static void +vu_rng_queue_set_started(VuDev *dev, int qidx, bool started) +{ + VuVirtq *vq =3D vu_get_queue(dev, qidx); + + g_debug("queue started %d:%d\n", qidx, started); + + if (!qidx) { + vu_set_queue_handler(dev, vq, started ? vu_rng_handle_requests : N= ULL); + } +} + +/* + * Any messages not handled here are processed by the libvhost library + * itself. + */ +static int rng_process_msg(VuDev *dev, VhostUserMsg *msg, int *do_reply) +{ + VuRNG *rng =3D container_of(dev, VuRNG, dev.parent); + + if (msg->request =3D=3D VHOST_USER_NONE) { + g_main_loop_quit(rng->loop); + return 1; + } + + return 0; +} + +static const VuDevIface vuiface =3D { + .set_features =3D rng_set_features, + .get_features =3D rng_get_features, + .queue_set_started =3D vu_rng_queue_set_started, + .process_msg =3D rng_process_msg, +}; + +static gboolean hangup(gpointer user_data) +{ + GMainLoop *loop =3D (GMainLoop *) user_data; + + g_printerr("%s: caught hangup/quit signal, quitting", __func__); + g_main_loop_quit(loop); + return true; +} + +static void panic(VuDev *dev, const char *msg) +{ + g_critical("%s\n", msg); + exit(EXIT_FAILURE); +} + +/* Print vhost-user.json backend program capabilities */ +static void print_capabilities(void) +{ + printf("{\n"); + printf(" \"type\": \"RNG\"\n"); + printf(" \"filename\": [ RNG source ]\n"); + printf("}\n"); +} + +static GOptionEntry options[] =3D { + { "socket-path", 's', 0, G_OPTION_ARG_FILENAME, &socket_path, + "Location of vhost-user Unix domain socket, incompatible with --fd", + "PATH" }, + { "fd", 'f', 0, G_OPTION_ARG_INT, &socket_fd, + "Specify the backend file-descriptor, incompatible with --socket-pat= h", + "FD" }, + { "period", 'p', 0, G_OPTION_ARG_INT, &period_ms, + "Time needed (in ms) to transfer a maximum amount of byte", NULL }, + { "max-bytes", 'm', 0, G_OPTION_ARG_INT64, &max_bytes, + "Maximum amount of byte that can be transferred in a period", NULL }, + { "filename", 'n', 0, G_OPTION_ARG_FILENAME, &source_path, + "RNG source, defaults to /dev/urandom", "PATH" }, + { "print-capabilities", 'c', 0, G_OPTION_ARG_NONE, &print_cap, + "Output to stdout the backend capabilities in JSON format and exit", + NULL}, + { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, + "Be more verbose in output", NULL}, + { NULL } +}; + +int main(int argc, char *argv[]) +{ + GError *error =3D NULL; + GOptionContext *context; + g_autoptr(GSocket) socket =3D NULL; + char default_source[] =3D "/dev/urandom"; + char *source =3D default_source; + VuRNG rng; + + context =3D g_option_context_new("vhost-user emulation of RNG device"); + g_option_context_add_main_entries(context, options, "vhost-user-rng"); + if (!g_option_context_parse(context, &argc, &argv, &error)) { + g_printerr("option parsing failed: %s\n", error->message); + exit(1); + } + + if (print_cap) { + print_capabilities(); + exit(0); + } + + if (!socket_path && socket_fd < 0) { + g_printerr("Please specify either --fd or --socket-path\n"); + exit(EXIT_FAILURE); + } + + if (socket_path && socket_fd > 0) { + g_printerr("Either --fd or --socket-path, not both\n"); + exit(EXIT_FAILURE); + } + + if (max_bytes > INT64_MAX) { + g_printerr("'max-bytes' parameter must be non-negative, " + "and less than 2^63\n"); + exit(EXIT_FAILURE); + } + + if (period_ms <=3D 0) { + g_printerr("'period' parameter expects a positive integer\n"); + exit(EXIT_FAILURE); + } + + /* + * Now create a vhost-user socket that we will receive messages + * on. Once we have our handler set up we can enter the glib main + * loop. + */ + if (socket_path) { + g_autoptr(GSocketAddress) addr =3D g_unix_socket_address_new(socke= t_path); + g_autoptr(GSocket) bind_socket =3D g_socket_new(G_SOCKET_FAMILY_UN= IX, + G_SOCKET_TYPE_STREAM, + G_SOCKET_PROTOCOL_DE= FAULT, + &error); + + if (!g_socket_bind(bind_socket, addr, false, &error)) { + g_printerr("Failed to bind to socket at %s (%s).\n", + socket_path, error->message); + exit(EXIT_FAILURE); + } + if (!g_socket_listen(bind_socket, &error)) { + g_printerr("Failed to listen on socket %s (%s).\n", + socket_path, error->message); + } + g_message("awaiting connection to %s", socket_path); + socket =3D g_socket_accept(bind_socket, NULL, &error); + if (!socket) { + g_printerr("Failed to accept on socket %s (%s).\n", + socket_path, error->message); + } + } else { + socket =3D g_socket_new_from_fd(socket_fd, &error); + if (!socket) { + g_printerr("Failed to connect to FD %d (%s).\n", + socket_fd, error->message); + exit(EXIT_FAILURE); + } + } + + /* Overwrite default RNG source with what user provided, if any */ + if (source_path) { + source =3D source_path; + } + + source_fd =3D open(source, O_RDWR); + if (source_fd < 0) { + g_printerr("Failed to open RNG source %s\n", source); + g_socket_close(socket, &error); + unlink(socket_path); + exit(EXIT_FAILURE); + } + + /* catch exit signals */ + g_unix_signal_add(SIGHUP, hangup, rng.loop); + g_unix_signal_add(SIGINT, hangup, rng.loop); + + /* + * Create the main loop first so all the various sources can be + * added. As well as catching signals we need to ensure vug_init + * can add it's GSource watches. + */ + rng.loop =3D g_main_loop_new(NULL, FALSE); + + if (!vug_init(&rng.dev, 1, g_socket_get_fd(socket), + panic, &vuiface)) { + g_printerr("Failed to initialize libvhost-user-glib.\n"); + exit(EXIT_FAILURE); + } + + rng.quota_remaining =3D max_bytes; + rng.activate_timer =3D true; + pthread_mutex_init(&rng.rng_mutex, NULL); + pthread_cond_init(&rng.rng_cond, NULL); + setup_timer(&rng); + + if (verbose) { + g_info("period_ms: %d tv_sec: %ld tv_nsec: %lu\n", + period_ms, rng.ts.it_value.tv_sec, rng.ts.it_value.tv_nsec); + } + + g_message("entering main loop, awaiting messages"); + g_main_loop_run(rng.loop); + g_message("finished main loop, cleaning up"); + + g_main_loop_unref(rng.loop); + vug_deinit(&rng.dev); + timer_delete(rng.rate_limit_timer); + close(source_fd); + unlink(socket_path); +} diff --git a/tools/meson.build b/tools/meson.build index 3e5a0abfa2..66b0a11fbb 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -24,3 +24,11 @@ endif if have_virtiofsd subdir('virtiofsd') endif + +have_virtiorng =3D (have_system and + have_tools and + 'CONFIG_LINUX' in config_host) + +if have_virtiorng + subdir('vhost-user-rng') +endif diff --git a/tools/vhost-user-rng/50-qemu-rng.json.in b/tools/vhost-user-rn= g/50-qemu-rng.json.in new file mode 100644 index 0000000000..9186c3c6fe --- /dev/null +++ b/tools/vhost-user-rng/50-qemu-rng.json.in @@ -0,0 +1,5 @@ +{ + "description": "QEMU vhost-user-rng", + "type": "bridge", + "binary": "@libexecdir@/vhost-user-rng" +} diff --git a/tools/vhost-user-rng/meson.build b/tools/vhost-user-rng/meson.= build new file mode 100644 index 0000000000..4dc386daf3 --- /dev/null +++ b/tools/vhost-user-rng/meson.build @@ -0,0 +1,10 @@ +executable('vhost-user-rng', files( + 'main.c'), + dependencies: [qemuutil, glib, gio, rt], + install: true, + install_dir: get_option('libexecdir')) + +configure_file(input: '50-qemu-rng.json.in', + output: '50-qemu-rng.json', + configuration: config_host, + install_dir: qemu_datadir / 'vhost-user') --=20 MST From nobody Sat Feb 7 06:45:13 2026 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=1626215648; cv=none; d=zohomail.com; s=zohoarc; b=AW4sq+5+pOQswOq/NipcuVjobqzrChyPcgQK3EdNgs2tjDWNWERZb4wwLOKEiIt5crMHOagZamPZsB0uJ/8Qw3n/G8NsSuulxdkjD7QTl14fFg/yRHsSqjByu8hl8ERshlJv+vgXtndUnNnkze6qrcvSZgMj7OGNxls5r29EggI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626215648; h=Content-Type:Cc: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=2j8JeaRNU7honPrSPdps+w1y4dHjJhJPeexiXUjAfAU=; b=ndp1TKblgJe8W9MPJz52TtBSEXOxWxAMmJv20clkRfM93W8tHlk9BGUPLMkVvxcj6tlcfuqyBI71VGoymkSQpCWjpg9tsvT4r9hjNPaRYOB6fj23tnh6YzAyRV/avhY0jFXdvmzyZ4ZrMmL39ASBR7BG1pQbBzIrbWga85n86JI= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626215648191354.6426037745947; Tue, 13 Jul 2021 15:34:08 -0700 (PDT) Received: from localhost ([::1]:49866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3Qyd-0005lt-5q for importer@patchew.org; Tue, 13 Jul 2021 18:34:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55934) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QfE-0007Qx-M2 for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:14:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28142) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QfC-0001oQ-UN for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:14:04 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-495-aT1p3KTKOo-AYMh8DCyZig-1; Tue, 13 Jul 2021 18:10:39 -0400 Received: by mail-wm1-f72.google.com with SMTP id p9-20020a7bcc890000b02902190142995dso966526wma.4 for ; Tue, 13 Jul 2021 15:10:39 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id h15sm108585wrq.88.2021.07.13.15.10.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:10:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214442; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=2j8JeaRNU7honPrSPdps+w1y4dHjJhJPeexiXUjAfAU=; b=XWipdkl4AgcRqQ313kACUL7hYIrHGSoVfHGWbw7wt202xm2T+wD0nnD8OOMPQB8w29GUCC 5ZxrupHoEk6EzG/H5LRiLncGfQVviB/C8Rj0285NjJcRgI7TJcAUnMH8Y8QKoB2MmI32r0 SguGbMIaC8lmkC+KJbDKjtPO2MXR76A= X-MC-Unique: aT1p3KTKOo-AYMh8DCyZig-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=2j8JeaRNU7honPrSPdps+w1y4dHjJhJPeexiXUjAfAU=; b=iWyq9Z1/bz2RVzr2OUuE8GEbPYhm08NuuUy+lGBjmYlNeDDCMt7BP1bq68dxNTRJKS lmQsauSPtRdFQ2G6slKeU86PPF3ewKoluqu0JGTwkj6/JQZJoEi1pEZWcGbc0lGljo3U +isXSeOoA+Y24BrP5wsPHdurJ2q+ssywahVGNLjeYX9HJJA3Sd2JzxsV257y2MbKSdYz UG5tjugzfLXCIYZTM8BD45rMEhiX4p1wD+6+PD5YjAvp9c5Yc0AVLn8SlvF8fcZ7H9VP pZ2vT7fcW+Br8R/K/CsxMix/SLherllQSmj7ePWfVgfguh4TYdZ2n2huMDq+h1daxjXT Lr0g== X-Gm-Message-State: AOAM5302U0ykjnr9a50X46Ub9Qz+ByV02zurgKEOnhi7bevuv3ANv0iR O4C51r9TbKHdozs0lVFMkwIrnR272pIgYwMcrpLP354NTWTyaD8lmDBIEQbBVo/ZhU8fYFYSElX rMVu/140hkC+epwVhgtvOsaK9JHdUTYSrNNSnvyhxTQFFQhkWkUJUyOUV+E0R X-Received: by 2002:a5d:6786:: with SMTP id v6mr8599801wru.290.1626214238523; Tue, 13 Jul 2021 15:10:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/lkoBjhY5OkOfpGb4zj9kVBB4+P7VEuDaps1UiOLb4VTY4yCMme3Wkko5omNabR6r6ZeI9w== X-Received: by 2002:a5d:6786:: with SMTP id v6mr8599782wru.290.1626214238292; Tue, 13 Jul 2021 15:10:38 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:36 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 10/23] docs: Add documentation for vhost based RNG implementation Message-ID: <20210713220946.212562-11-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Mathieu Poirier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1626215648749100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mathieu Poirier Add description and example for the vhost-user based RNG implementation. Tailored on Viresh Kumar's vhost-user-i2c documentation. Signed-off-by: Mathieu Poirier Message-Id: <20210710005929.1702431-5-mathieu.poirier@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- docs/tools/index.rst | 1 + docs/tools/vhost-user-rng.rst | 74 +++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 docs/tools/vhost-user-rng.rst diff --git a/docs/tools/index.rst b/docs/tools/index.rst index d923834a73..9d80fa89ec 100644 --- a/docs/tools/index.rst +++ b/docs/tools/index.rst @@ -15,5 +15,6 @@ Contents: qemu-nbd qemu-pr-helper qemu-trace-stap + vhost-user-rng virtfs-proxy-helper virtiofsd diff --git a/docs/tools/vhost-user-rng.rst b/docs/tools/vhost-user-rng.rst new file mode 100644 index 0000000000..7f69d7bb3c --- /dev/null +++ b/docs/tools/vhost-user-rng.rst @@ -0,0 +1,74 @@ +QEMU vhost-user-rng - RNG emulation backend +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Synopsis +-------- + +**vhost-user-rng** [*OPTIONS*] + +Description +----------- + +This program is a vhost-user backend that emulates a VirtIO random number +generator (RNG). It uses the host's random number generator pool, +/dev/urandom by default but configurable at will, to satisfy requests from +guests. + +This program is designed to work with QEMU's ``-device +vhost-user-rng-pci`` but should work with any virtual machine monitor +(VMM) that supports vhost-user. See the Examples section below. + +Options +------- + +.. program:: vhost-user-rng + +.. option:: -h, --help + + Print help. + +.. option:: -v, --verbose + + Increase verbosity of output + +.. option:: -s, --socket-path=3DPATH + + Listen on vhost-user UNIX domain socket at PATH. Incompatible with --fd. + +.. option:: -f, --fd=3DFDNUM + + Accept connections from vhost-user UNIX domain socket file descriptor FD= NUM. + The file descriptor must already be listening for connections. + Incompatible with --socket-path. + +.. option:: -p, --period + + Rate, in milliseconds, at which the RNG hardware can generate random dat= a. + Used in conjunction with the --max-bytes option. + +.. option:: -m, --max-bytes + + In conjuction with the --period parameter, provides the maximum number o= f byte + per milliseconds a RNG device can generate. + +Examples +-------- + +The daemon should be started first: + +:: + + host# vhost-user-rng --socket-path=3Drng.sock --period=3D1000 --max-byte= s=3D4096 + +The QEMU invocation needs to create a chardev socket the device can +use to communicate as well as share the guests memory over a memfd. + +:: + + host# qemu-system \ + -chardev socket,path=3D$(PATH)/rng.sock,id=3Drng0 \ + -device vhost-user-rng-pci,chardev=3Drng0 \ + -m 4096 \ + -object memory-backend-file,id=3Dmem,size=3D4G,mem-path=3D/dev/shm,s= hare=3Don \ + -numa node,memdev=3Dmem \ + ... --=20 MST From nobody Sat Feb 7 06:45:13 2026 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=1626214690; cv=none; d=zohomail.com; s=zohoarc; b=cta10LjhaGzeddh5DXXsitg2XC7yr0ieH3bVXh6JLjam4y2uY5u+X4DrxA9ZDjHm6KSkFJ5XInhPsC9xW6LNvrUXKN6NTAmSN0YYFK/MJAi59DSD9CIE5a5pxVXh3cgNZll91uIQ9u2hB87v0m9JNvX4BDLiTXCBtMtcD8DiaFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626214690; h=Content-Type:Cc: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=f/yL9X7yv98T/bg8H5tdQO8Tp7NdclLbM6Zin1PZync=; b=LKb2Oipk8E7XFhjPPjvJywFV8e22X6dkrFyI7UXUS2xv4GeGnOLK8CqqYe2K1Vt4w6j5FlETXX+s4arg+7/8v38mr5rZDv9aIPIbDMzhPbRG1Aipi6TpZ7ntylvZWz142U0LHU++cvN+zWrUsQM5ZWL/3ebOHgEWWBFdpibUQYA= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626214690975382.6193461522572; Tue, 13 Jul 2021 15:18:10 -0700 (PDT) Received: from localhost ([::1]:56958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3QjA-0006Jy-Ra for importer@patchew.org; Tue, 13 Jul 2021 18:18:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qc4-0007Np-2z for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44065) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qc0-0007xB-LL for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:47 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-19-VBdLvG2WN0mJz7094GZkFw-1; Tue, 13 Jul 2021 18:10:42 -0400 Received: by mail-wm1-f70.google.com with SMTP id m40-20020a05600c3b28b02901f42375a73fso150641wms.5 for ; Tue, 13 Jul 2021 15:10:42 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id z7sm129039wrt.47.2021.07.13.15.10.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:10:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214244; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=f/yL9X7yv98T/bg8H5tdQO8Tp7NdclLbM6Zin1PZync=; b=BTNdG8uFeQSj8EErZ8o7j/G2Z2guNZAfDMPX0C0yMLndlT877Pj1qTyStzEZY/jQzVhet0 j5ZvRn+q5Tciz6Fyb0JFhDJMmURC1U+l+tktYKXEOHNzjhIHCaqPRSS7UdcQbdHcT1wv8V JSs0d1kcTt5RkGbds5APTyObJ98AvV8= X-MC-Unique: VBdLvG2WN0mJz7094GZkFw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=f/yL9X7yv98T/bg8H5tdQO8Tp7NdclLbM6Zin1PZync=; b=OOlUTG9gHqZ59cOTwriArTQ6IDsGXliNCUrQmcqlgy2Q/gvkdvZX6j+wSQWUpMR4k5 b+Z4XgWIKorNaSO6ukKWhAiFxeViD+dz3WanSNjXFIgjW9cvsrO3ylCkJpttDPKrjJXE By8DP6DjofVe2Lyiy1S7GZ9cyYTwDDNiVVu1M/IbTRRfFyvbxAXKP4TUirqYx3lg10lP M+xGTum146VZzOzfyTTf0FrjLyeSP1euwnpL8yuUpmKPD/eE/kIKcoL/JTsncSHd5E2d 1Eg7IKhZxn+yALjXNIJOk34cADB5MqhjI1qLVGZI2WFLXCun98Mm1pmNf/y1VRij9pj+ GEJw== X-Gm-Message-State: AOAM533tIS/h5Jgz6zWW7385Tb6lg0EOHKT4MvqyzE4pkulMx4IDFDr1 9OIz0DQgXYCOWjogPlOkXRx2ymWXjl6zqFLIfHFHb36jMCDxRdUfvQbaj33IVBwTF1nPAI5ETat 1ojpKVEKHNBRHdOnI31ForPHxMpU9KwyoOCFQI9UBIbyxEyRQEG9vmGsix4Dq X-Received: by 2002:adf:e507:: with SMTP id j7mr8649515wrm.152.1626214241217; Tue, 13 Jul 2021 15:10:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqccBVZV1yCbaNcCSujACsjbzBIxbuyBFeSyTqXCodXOQrrbmYDjQsksNf60R3f/yq5MgF/A== X-Received: by 2002:adf:e507:: with SMTP id j7mr8649488wrm.152.1626214240937; Tue, 13 Jul 2021 15:10:40 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:38 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 11/23] hw/virtio: add boilerplate for vhost-user-i2c device Message-ID: <20210713220946.212562-12-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Viresh Kumar Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1626214692574100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Viresh Kumar This creates the QEMU side of the vhost-user-i2c device which connects to the remote daemon. It is based of vhost-user-fs code. Signed-off-by: Viresh Kumar Message-Id: Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost-user-i2c.h | 28 +++ hw/virtio/vhost-user-i2c.c | 288 +++++++++++++++++++++++++++++ hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 1 + 4 files changed, 322 insertions(+) create mode 100644 include/hw/virtio/vhost-user-i2c.h create mode 100644 hw/virtio/vhost-user-i2c.c diff --git a/include/hw/virtio/vhost-user-i2c.h b/include/hw/virtio/vhost-u= ser-i2c.h new file mode 100644 index 0000000000..deae47a76d --- /dev/null +++ b/include/hw/virtio/vhost-user-i2c.h @@ -0,0 +1,28 @@ +/* + * Vhost-user i2c virtio device + * + * Copyright (c) 2021 Viresh Kumar + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef _QEMU_VHOST_USER_I2C_H +#define _QEMU_VHOST_USER_I2C_H + +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" + +#define TYPE_VHOST_USER_I2C "vhost-user-i2c-device" +OBJECT_DECLARE_SIMPLE_TYPE(VHostUserI2C, VHOST_USER_I2C) + +struct VHostUserI2C { + VirtIODevice parent; + CharBackend chardev; + struct vhost_virtqueue *vhost_vq; + struct vhost_dev vhost_dev; + VhostUserState vhost_user; + VirtQueue *vq; + bool connected; +}; + +#endif /* _QEMU_VHOST_USER_I2C_H */ diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c new file mode 100644 index 0000000000..d172632bb0 --- /dev/null +++ b/hw/virtio/vhost-user-i2c.c @@ -0,0 +1,288 @@ +/* + * Vhost-user i2c virtio device + * + * Copyright (c) 2021 Viresh Kumar + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/virtio-bus.h" +#include "hw/virtio/vhost-user-i2c.h" +#include "qemu/error-report.h" +#include "standard-headers/linux/virtio_ids.h" + +/* Remove this once the header is updated in Linux kernel */ +#ifndef VIRTIO_ID_I2C_ADAPTER +#define VIRTIO_ID_I2C_ADAPTER 34 +#endif + +static void vu_i2c_start(VirtIODevice *vdev) +{ + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + VHostUserI2C *i2c =3D VHOST_USER_I2C(vdev); + int ret, i; + + if (!k->set_guest_notifiers) { + error_report("binding does not support guest notifiers"); + return; + } + + ret =3D vhost_dev_enable_notifiers(&i2c->vhost_dev, vdev); + if (ret < 0) { + error_report("Error enabling host notifiers: %d", -ret); + return; + } + + ret =3D k->set_guest_notifiers(qbus->parent, i2c->vhost_dev.nvqs, true= ); + if (ret < 0) { + error_report("Error binding guest notifier: %d", -ret); + goto err_host_notifiers; + } + + i2c->vhost_dev.acked_features =3D vdev->guest_features; + + ret =3D vhost_dev_start(&i2c->vhost_dev, vdev); + if (ret < 0) { + error_report("Error starting vhost-user-i2c: %d", -ret); + goto err_guest_notifiers; + } + + /* + * guest_notifier_mask/pending not used yet, so just unmask + * everything here. virtio-pci will do the right thing by + * enabling/disabling irqfd. + */ + for (i =3D 0; i < i2c->vhost_dev.nvqs; i++) { + vhost_virtqueue_mask(&i2c->vhost_dev, vdev, i, false); + } + + return; + +err_guest_notifiers: + k->set_guest_notifiers(qbus->parent, i2c->vhost_dev.nvqs, false); +err_host_notifiers: + vhost_dev_disable_notifiers(&i2c->vhost_dev, vdev); +} + +static void vu_i2c_stop(VirtIODevice *vdev) +{ + VHostUserI2C *i2c =3D VHOST_USER_I2C(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + + if (!k->set_guest_notifiers) { + return; + } + + vhost_dev_stop(&i2c->vhost_dev, vdev); + + ret =3D k->set_guest_notifiers(qbus->parent, i2c->vhost_dev.nvqs, fals= e); + if (ret < 0) { + error_report("vhost guest notifier cleanup failed: %d", ret); + return; + } + + vhost_dev_disable_notifiers(&i2c->vhost_dev, vdev); +} + +static void vu_i2c_set_status(VirtIODevice *vdev, uint8_t status) +{ + VHostUserI2C *i2c =3D VHOST_USER_I2C(vdev); + bool should_start =3D status & VIRTIO_CONFIG_S_DRIVER_OK; + + if (!vdev->vm_running) { + should_start =3D false; + } + + if (i2c->vhost_dev.started =3D=3D should_start) { + return; + } + + if (should_start) { + vu_i2c_start(vdev); + } else { + vu_i2c_stop(vdev); + } +} + +static uint64_t vu_i2c_get_features(VirtIODevice *vdev, + uint64_t requested_features, Error **e= rrp) +{ + /* No feature bits used yet */ + return requested_features; +} + +static void vu_i2c_handle_output(VirtIODevice *vdev, VirtQueue *vq) +{ + /* + * Not normally called; it's the daemon that handles the queue; + * however virtio's cleanup path can call this. + */ +} + +static void vu_i2c_guest_notifier_mask(VirtIODevice *vdev, int idx, bool m= ask) +{ + VHostUserI2C *i2c =3D VHOST_USER_I2C(vdev); + + vhost_virtqueue_mask(&i2c->vhost_dev, vdev, idx, mask); +} + +static bool vu_i2c_guest_notifier_pending(VirtIODevice *vdev, int idx) +{ + VHostUserI2C *i2c =3D VHOST_USER_I2C(vdev); + + return vhost_virtqueue_pending(&i2c->vhost_dev, idx); +} + +static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserI2C *i2c) +{ + vhost_user_cleanup(&i2c->vhost_user); + virtio_delete_queue(i2c->vq); + virtio_cleanup(vdev); + g_free(i2c->vhost_dev.vqs); + i2c->vhost_dev.vqs =3D NULL; +} + +static int vu_i2c_connect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserI2C *i2c =3D VHOST_USER_I2C(vdev); + + if (i2c->connected) { + return 0; + } + i2c->connected =3D true; + + /* restore vhost state */ + if (virtio_device_started(vdev, vdev->status)) { + vu_i2c_start(vdev); + } + + return 0; +} + +static void vu_i2c_disconnect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserI2C *i2c =3D VHOST_USER_I2C(vdev); + + if (!i2c->connected) { + return; + } + i2c->connected =3D false; + + if (i2c->vhost_dev.started) { + vu_i2c_stop(vdev); + } +} + +static void vu_i2c_event(void *opaque, QEMUChrEvent event) +{ + DeviceState *dev =3D opaque; + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserI2C *i2c =3D VHOST_USER_I2C(vdev); + + switch (event) { + case CHR_EVENT_OPENED: + if (vu_i2c_connect(dev) < 0) { + qemu_chr_fe_disconnect(&i2c->chardev); + return; + } + break; + case CHR_EVENT_CLOSED: + vu_i2c_disconnect(dev); + break; + case CHR_EVENT_BREAK: + case CHR_EVENT_MUX_IN: + case CHR_EVENT_MUX_OUT: + /* Ignore */ + break; + } +} + +static void vu_i2c_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserI2C *i2c =3D VHOST_USER_I2C(dev); + int ret; + + if (!i2c->chardev.chr) { + error_setg(errp, "vhost-user-i2c: missing chardev"); + return; + } + + if (!vhost_user_init(&i2c->vhost_user, &i2c->chardev, errp)) { + return; + } + + virtio_init(vdev, "vhost-user-i2c", VIRTIO_ID_I2C_ADAPTER, 0); + + i2c->vhost_dev.nvqs =3D 1; + i2c->vq =3D virtio_add_queue(vdev, 4, vu_i2c_handle_output); + i2c->vhost_dev.vqs =3D g_new0(struct vhost_virtqueue, i2c->vhost_dev.n= vqs); + + ret =3D vhost_dev_init(&i2c->vhost_dev, &i2c->vhost_user, + VHOST_BACKEND_TYPE_USER, 0, errp); + if (ret < 0) { + do_vhost_user_cleanup(vdev, i2c); + } + + qemu_chr_fe_set_handlers(&i2c->chardev, NULL, NULL, vu_i2c_event, NULL, + dev, NULL, true); +} + +static void vu_i2c_device_unrealize(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserI2C *i2c =3D VHOST_USER_I2C(dev); + + /* This will stop vhost backend if appropriate. */ + vu_i2c_set_status(vdev, 0); + vhost_dev_cleanup(&i2c->vhost_dev); + do_vhost_user_cleanup(vdev, i2c); +} + +static const VMStateDescription vu_i2c_vmstate =3D { + .name =3D "vhost-user-i2c", + .unmigratable =3D 1, +}; + +static Property vu_i2c_properties[] =3D { + DEFINE_PROP_CHR("chardev", VHostUserI2C, chardev), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vu_i2c_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + + device_class_set_props(dc, vu_i2c_properties); + dc->vmsd =3D &vu_i2c_vmstate; + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + vdc->realize =3D vu_i2c_device_realize; + vdc->unrealize =3D vu_i2c_device_unrealize; + vdc->get_features =3D vu_i2c_get_features; + vdc->set_status =3D vu_i2c_set_status; + vdc->guest_notifier_mask =3D vu_i2c_guest_notifier_mask; + vdc->guest_notifier_pending =3D vu_i2c_guest_notifier_pending; +} + +static const TypeInfo vu_i2c_info =3D { + .name =3D TYPE_VHOST_USER_I2C, + .parent =3D TYPE_VIRTIO_DEVICE, + .instance_size =3D sizeof(VHostUserI2C), + .class_init =3D vu_i2c_class_init, +}; + +static void vu_i2c_register_types(void) +{ + type_register_static(&vu_i2c_info); +} + +type_init(vu_i2c_register_types) diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index 69066ab14e..6c917d7f1f 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -63,3 +63,8 @@ config VHOST_USER_RNG bool default y depends on VIRTIO && VHOST_USER + +config VHOST_USER_I2C + bool + default y + depends on VIRTIO && VHOST_USER diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 1430b370e6..948e668ed3 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -27,6 +27,7 @@ virtio_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files= ('virtio-iommu.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rn= g.c')) virtio_ss.add(when: ['CONFIG_VHOST_USER_RNG', 'CONFIG_VIRTIO_PCI'], if_tru= e: files('vhost-user-rng-pci.c')) +virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2= c.c')) =20 virtio_pci_ss =3D ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-= pci.c')) --=20 MST From nobody Sat Feb 7 06:45:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626214839018128.59721379756195; Tue, 13 Jul 2021 15:20:39 -0700 (PDT) Received: from localhost ([::1]:37326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3QlZ-0003cT-VL for importer@patchew.org; Tue, 13 Jul 2021 18:20:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qc5-0007Sr-ED for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50679) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qc3-0007yY-B3 for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:49 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-395-Fhy54vN6NUGF8lJE5qY-tQ-1; Tue, 13 Jul 2021 18:10:45 -0400 Received: by mail-wm1-f70.google.com with SMTP id i7-20020a05600c3547b0290229a389ceb2so948532wmq.0 for ; Tue, 13 Jul 2021 15:10:45 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id d18sm237257wmp.46.2021.07.13.15.10.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:10:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214246; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pGNVy1FELi8qpaAI6ieUTmFEXCRocQuU2XFIwFNetIA=; b=T4vgEuT9A9m9tx5IJ9CweyKTLP47jC4sxVjDF8m4zTTqJED7dKuSdMAjYqvx23Jl15sUPF JUbyR8c8zkp7w/g4ilIFn3hP3xwsDXB1KTlkIaOdb0egH+tW+VQWwiDJfPXAWg3NjsubxA FpF3jVGTkP1xtXOju4InA041f/svHqk= X-MC-Unique: Fhy54vN6NUGF8lJE5qY-tQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=pGNVy1FELi8qpaAI6ieUTmFEXCRocQuU2XFIwFNetIA=; b=CBnSYxMmxFjvtR33/a+s68ouS3WihaJ5n1kOsjF8JPI+3tifMWEXTzcWHD1i3MmO5k L+dLz2+L7HV7u0kHQ18pYQnCiqC4SQd8ipJzPr3yJ+vL9Qr3irwkWokk2w0t2CwsRlbH 4tK8K/huGmZRVz2nc6alzishem38CR+zuos2DOKa1qfSci/TVWxQoUiUFsUR2YlwFPdM z6HF999MX+PB6WNoEGQLdHnNaQHj0iLStcvsTi5AUFLVywsQE4DBCwXnCYGvcsN5Q/Ha jbtMkgoYQWzK9sFphobb6KhBnS5L6n45wtKDulp/ZHei9xqxknhWwpPF7jFPhXbVavPs c7fg== X-Gm-Message-State: AOAM533TtupQ/Cgr2b3Okkxzf6KUo0FZswmMHiMSnRYMpyfQISZrXJoB p8CycNQ00R4cn8bNiIVrfhVbRzh9CWuAYDt287yL676MjmWSmmfgf9AOKoTjcwO62LYSHEdvXK2 IpHwrRAQ5VCQDq97Wjaz+BqRGi2IQVJsZz8nW7CBF68jdeuEK3e2MhS1oKkld X-Received: by 2002:a5d:6804:: with SMTP id w4mr8365540wru.417.1626214243818; Tue, 13 Jul 2021 15:10:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtFqUSpxjemS90mOp60GTDvrKlEl5h7op4sTcM69V9cpukYGvEcui1lfjRIqqLtH1qYphw+Q== X-Received: by 2002:a5d:6804:: with SMTP id w4mr8365517wru.417.1626214243579; Tue, 13 Jul 2021 15:10:43 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:41 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 12/23] hw/virtio: add vhost-user-i2c-pci boilerplate Message-ID: <20210713220946.212562-13-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Disposition: inline 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=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Alex =?utf-8?Q?Benn=C3=A9e?= , Viresh Kumar Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626214840300100001 From: Viresh Kumar This allows is to instantiate a vhost-user-i2c device as part of a PCI bus. It is mostly boilerplate which looks pretty similar to the vhost-user-fs-pci device. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Viresh Kumar Message-Id: <8a083eaa57d93feaab12acd1f94b225879212f20.1625806763.git.viresh= .kumar@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-user-i2c-pci.c | 69 ++++++++++++++++++++++++++++++++++ hw/virtio/meson.build | 1 + 2 files changed, 70 insertions(+) create mode 100644 hw/virtio/vhost-user-i2c-pci.c diff --git a/hw/virtio/vhost-user-i2c-pci.c b/hw/virtio/vhost-user-i2c-pci.c new file mode 100644 index 0000000000..70b7b65fd9 --- /dev/null +++ b/hw/virtio/vhost-user-i2c-pci.c @@ -0,0 +1,69 @@ +/* + * Vhost-user i2c virtio device PCI glue + * + * Copyright (c) 2021 Viresh Kumar + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/vhost-user-i2c.h" +#include "virtio-pci.h" + +struct VHostUserI2CPCI { + VirtIOPCIProxy parent_obj; + VHostUserI2C vdev; +}; + +typedef struct VHostUserI2CPCI VHostUserI2CPCI; + +#define TYPE_VHOST_USER_I2C_PCI "vhost-user-i2c-pci-base" + +DECLARE_INSTANCE_CHECKER(VHostUserI2CPCI, VHOST_USER_I2C_PCI, + TYPE_VHOST_USER_I2C_PCI) + +static void vhost_user_i2c_pci_realize(VirtIOPCIProxy *vpci_dev, Error **e= rrp) +{ + VHostUserI2CPCI *dev =3D VHOST_USER_I2C_PCI(vpci_dev); + DeviceState *vdev =3D DEVICE(&dev->vdev); + + vpci_dev->nvectors =3D 1; + qdev_realize(vdev, BUS(&vpci_dev->bus), errp); +} + +static void vhost_user_i2c_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k =3D PCI_DEVICE_CLASS(klass); + k->realize =3D vhost_user_i2c_pci_realize; + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + pcidev_k->vendor_id =3D PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id =3D 0; /* Set by virtio-pci based on virtio id */ + pcidev_k->revision =3D 0x00; + pcidev_k->class_id =3D PCI_CLASS_COMMUNICATION_OTHER; +} + +static void vhost_user_i2c_pci_instance_init(Object *obj) +{ + VHostUserI2CPCI *dev =3D VHOST_USER_I2C_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VHOST_USER_I2C); +} + +static const VirtioPCIDeviceTypeInfo vhost_user_i2c_pci_info =3D { + .base_name =3D TYPE_VHOST_USER_I2C_PCI, + .non_transitional_name =3D "vhost-user-i2c-pci", + .instance_size =3D sizeof(VHostUserI2CPCI), + .instance_init =3D vhost_user_i2c_pci_instance_init, + .class_init =3D vhost_user_i2c_pci_class_init, +}; + +static void vhost_user_i2c_pci_register(void) +{ + virtio_pci_types_register(&vhost_user_i2c_pci_info); +} + +type_init(vhost_user_i2c_pci_register); diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 948e668ed3..08629c8f2c 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -28,6 +28,7 @@ virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('= virtio-mem.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rn= g.c')) virtio_ss.add(when: ['CONFIG_VHOST_USER_RNG', 'CONFIG_VIRTIO_PCI'], if_tru= e: files('vhost-user-rng-pci.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2= c.c')) +virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_I2C'], if_tru= e: files('vhost-user-i2c-pci.c')) =20 virtio_pci_ss =3D ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-= pci.c')) --=20 MST From nobody Sat Feb 7 06:45:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162621501574999.59574906844375; Tue, 13 Jul 2021 15:23:35 -0700 (PDT) Received: from localhost ([::1]:45974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3QoQ-00012C-OE for importer@patchew.org; Tue, 13 Jul 2021 18:23:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55142) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QcA-0007cH-TZ for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49028) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qc9-00082c-1e for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:10:54 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-594-yz9r0FBhPf-NLov82dvbNg-1; Tue, 13 Jul 2021 18:10:49 -0400 Received: by mail-wm1-f72.google.com with SMTP id x6-20020a7bc2060000b0290218ad9a8d4aso968940wmi.1 for ; Tue, 13 Jul 2021 15:10:49 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id r19sm118068wrg.74.2021.07.13.15.10.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:10:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214252; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3J1FzfuBru52M0OTYvHXT9ubbEEIGS4eMsEdSAk30s8=; b=d7fBYREpCM6hXRdWD1q1f52Pa9HVBfzTD3fGjRYZfXoz4FWNNZ2qBY0l//DJUaWt6ZwAr2 XhifXzZ4ZdgqD5DPpdNW0RRsZaJ4CM0Km6YW6E/3HvnodxBw71sFBvQyeiuzgoPz+lwd9A hfaDTkEHOkTz5t86T8GEyybt6aAcuVk= X-MC-Unique: yz9r0FBhPf-NLov82dvbNg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=3J1FzfuBru52M0OTYvHXT9ubbEEIGS4eMsEdSAk30s8=; b=eLxBKdi4nEACRI6bKSgrd92xwtXjbyNNnmtJJ+ImN64DTfwSi60Ex1La8xeR6Z9gzN 6ITD/t0U4VqPyZktYaE7FMIMTNk+bswZ+mgs2Z5FOKjdJc8OlD8hG29pewXWBO5qzs6y exFgtLaLYTGS2k/lEgkPwFxJ4DiJx3p0qOK1gxu4afRss20dtgI88h8eC8KD/S0soWNK 33aPJyTn+fGPwbeL4c14A2J0leQEBLhk3KxB/o41y0iarAVPTWFTSqbHauWlDu+oNMpz zgQfzdDaXy1yCMbx6pSyFnNFor/3qkoLUj0+eTLaK2Bq2uNCvlrE+IOPkaq7QCzAPgVA gViA== X-Gm-Message-State: AOAM531DeEG4MWzbOEOElhgf1/5RiWmDXBp5+4AwPRRYtVZ7M+7OPdNq X+l7i4a7SgqNHEIGTSXdEBa0mhNWwSHaPRDIuYnoTyxrLsX5KA9tBq6wsb2wBJeDcg0hALE428x LsqydsdzM0IZx4jco0JM8o9+S7mof5QrbGyxVqG+Yal1c3F0cmuTF3JA/HlKO X-Received: by 2002:a05:600c:224a:: with SMTP id a10mr416444wmm.7.1626214248358; Tue, 13 Jul 2021 15:10:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxACicG0Ga3JT3SAf/SoV6G0ZgLyLOOmAOaYGPZjKEllmOr4blPI5kdQpkkwA+t1Z4Do+bE4w== X-Received: by 2002:a05:600c:224a:: with SMTP id a10mr416417wmm.7.1626214248167; Tue, 13 Jul 2021 15:10:48 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:44 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 13/23] docs: Add '-device intel-iommu' entry Message-ID: <20210713220946.212562-14-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Thomas Huth , Yi Liu , Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= , Jason Wang , Peter Xu , Maxim Levitsky , Eric Auger , Alex Williamson , Jing Zhao , Gerd Hoffmann , Paolo Bonzini , Lei Yang , Chao Yang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626215016882100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Peter Xu The parameters of intel-iommu device are non-trivial to understand. Add an entry for it so that people can reference to it when using. There're actually a few more options there, but I hide them explicitly beca= use they shouldn't be used by normal QEMU users. Cc: Chao Yang Cc: Lei Yang Cc: Jing Zhao Cc: Jason Wang Cc: Michael S. Tsirkin Cc: Alex Williamson Reviewed-by: Jason Wang Reviewed-by: Yi Liu Signed-off-by: Peter Xu Message-Id: <20210707154114.197580-1-peterx@redhat.com> Reviewed-by: Maxim Levitsky Reviewed-by: Eric Auger Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- qemu-options.hx | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/qemu-options.hx b/qemu-options.hx index 8965dabc83..0fcc8973dd 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -926,6 +926,39 @@ SRST =20 ``-device pci-ipmi-bt,bmc=3Did`` Like the KCS interface, but defines a BT interface on the PCI bus. + +``-device intel-iommu[,option=3D...]`` + This is only supported by ``-machine q35``, which will enable Intel VT= -d + emulation within the guest. It supports below options: + + ``intremap=3Don|off`` (default: auto) + This enables interrupt remapping feature. It's required to enable + complete x2apic. Currently it only supports kvm kernel-irqchip mo= des + ``off`` or ``split``, while full kernel-irqchip is not yet support= ed. + The default value is "auto", which will be decided by the mode of + kernel-irqchip. + + ``caching-mode=3Don|off`` (default: off) + This enables caching mode for the VT-d emulated device. When + caching-mode is enabled, each guest DMA buffer mapping will genera= te an + IOTLB invalidation from the guest IOMMU driver to the vIOMMU devic= e in + a synchronous way. It is required for ``-device vfio-pci`` to work + with the VT-d device, because host assigned devices requires to se= tup + the DMA mapping on the host before guest DMA starts. + + ``device-iotlb=3Don|off`` (default: off) + This enables device-iotlb capability for the emulated VT-d device.= So + far virtio/vhost should be the only real user for this parameter, + paired with ats=3Don configured for the device. + + ``aw-bits=3D39|48`` (default: 39) + This decides the address width of IOVA address space. The address + space has 39 bits width for 3-level IOMMU page tables, and 48 bits= for + 4-level IOMMU page tables. + + Please also refer to the wiki page for general scenarios of VT-d + emulation in QEMU: https://wiki.qemu.org/Features/VT-d. + ERST =20 DEF("name", HAS_ARG, QEMU_OPTION_name, --=20 MST From nobody Sat Feb 7 06:45:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162621464296950.83526223420699; Tue, 13 Jul 2021 15:17:22 -0700 (PDT) Received: from localhost ([::1]:54692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3QiP-0004pJ-Si for importer@patchew.org; Tue, 13 Jul 2021 18:17:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QcG-0007ll-At for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22610) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QcD-00084j-8o for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:00 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-92-nnmIpw0GO7mFgVgd0XC7hw-1; Tue, 13 Jul 2021 18:10:53 -0400 Received: by mail-wm1-f72.google.com with SMTP id x6-20020a7bc2060000b0290218ad9a8d4aso968985wmi.1 for ; Tue, 13 Jul 2021 15:10:52 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id y6sm244379wma.48.2021.07.13.15.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:10:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=x7ZuFpyOa5DAu/c2wYuyH48s1IkBMXPNPbP+hmJeKHY=; b=eaImL3ehT8nFsRWiKSDk76ShvgAZIeWBeqLLDo92LC8fKFvXw+9hBUvQ0KPu8gjKHVjBdC AYpCZR3Q4OGXWcyvqXO4dMZYsgNJHbt/b41enDqj3yx8KotZkRzfQCp0Nz0m2aWWnYcR3U RrNBo2K/yIgkTKMq3z2JkCOKPGpHfqE= X-MC-Unique: nnmIpw0GO7mFgVgd0XC7hw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=x7ZuFpyOa5DAu/c2wYuyH48s1IkBMXPNPbP+hmJeKHY=; b=mrxidnIeeUfsd5v6/sW3VSt2Ye2jfBudqF70e6mueZsOufsih1eBsOGivxVNK1IpQF /fYOs/ZA44K5TY3fRbt3b+Ht79zX4ofcQu4UFfmYsu+tStUh1Q/+E+mG2dPzbx9p8SyG 05fgy7JrNUDiFsBnHw0Ia4H/vSE/QppJa0AN7/Q6I6ZAXe3q6TfQn9aPO5j6ex4LZH+7 HcRON53XkQbO/c0XGGTVy7SggqvVFTpGIq0Dgfc8Bkt9fGrBYTZRBm6M9z1NY0oDAR3x p9eT1b9XxAzgqfEzRTRpRuHMrryL4LogCjfnQiUKbaijWMv1xYihk7Einsyb10iIeTRP 9ngw== X-Gm-Message-State: AOAM533CyFU0pzzhQ83OWTiuOI1YVK8aV4QXTuF7UtBV9pmbW/LJt8hh rZAPQmis4GS5AhXqmOCH5jnFj10DulfU9VlIwDT1KDbCbDrzuzSjMrH+NesdBxm+Z96gF8oxW0Z V80nLCqAwH7UEptBWmD940yEGj3zBSlLd3Xeiw/FgX1x6Dg3qtJnjnUnoZ8AM X-Received: by 2002:a5d:64ee:: with SMTP id g14mr8851104wri.66.1626214251766; Tue, 13 Jul 2021 15:10:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxh5cmZBmBnPWo4HnVAsmN5e8Wr45QbVi/pbGVArXNTGGrLuA2Tw3ftc7wV0v4SofyEzu2XWA== X-Received: by 2002:a5d:64ee:: with SMTP id g14mr8851075wri.66.1626214251546; Tue, 13 Jul 2021 15:10:51 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:48 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 14/23] hw/pci/pci_host: Allow PCI host to bypass iommu Message-ID: <20210713220946.212562-15-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Xingang Wang , Eric Auger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626214644102100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xingang Wang Add a new bypass_iommu property for PCI host and use it to check whether devices attached to the PCI root bus will bypass iommu. In pci_device_iommu_address_space(), check the property and avoid getting iommu address space for devices bypass iommu. Signed-off-by: Xingang Wang Reviewed-by: Eric Auger Message-Id: <1625748919-52456-2-git-send-email-wangxingang5@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/pci/pci.h | 1 + include/hw/pci/pci_host.h | 1 + hw/pci/pci.c | 18 +++++++++++++++++- hw/pci/pci_host.c | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 6be4e0c460..f4d51b672b 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -480,6 +480,7 @@ void pci_for_each_bus(PCIBus *bus, =20 PCIBus *pci_device_root_bus(const PCIDevice *d); const char *pci_root_bus_path(PCIDevice *dev); +bool pci_bus_bypass_iommu(PCIBus *bus); PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn); int pci_qdev_find_device(const char *id, PCIDevice **pdev); void pci_bus_get_w64_range(PCIBus *bus, Range *range); diff --git a/include/hw/pci/pci_host.h b/include/hw/pci/pci_host.h index 52e038c019..c6f4eb4585 100644 --- a/include/hw/pci/pci_host.h +++ b/include/hw/pci/pci_host.h @@ -43,6 +43,7 @@ struct PCIHostState { uint32_t config_reg; bool mig_enabled; PCIBus *bus; + bool bypass_iommu; =20 QLIST_ENTRY(PCIHostState) next; }; diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 377084f1a8..27d588e268 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -416,6 +416,22 @@ const char *pci_root_bus_path(PCIDevice *dev) return rootbus->qbus.name; } =20 +bool pci_bus_bypass_iommu(PCIBus *bus) +{ + PCIBus *rootbus =3D bus; + PCIHostState *host_bridge; + + if (!pci_bus_is_root(bus)) { + rootbus =3D pci_device_root_bus(bus->parent_dev); + } + + host_bridge =3D PCI_HOST_BRIDGE(rootbus->qbus.parent); + + assert(host_bridge->bus =3D=3D rootbus); + + return host_bridge->bypass_iommu; +} + static void pci_root_bus_init(PCIBus *bus, DeviceState *parent, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, @@ -2718,7 +2734,7 @@ AddressSpace *pci_device_iommu_address_space(PCIDevic= e *dev) =20 iommu_bus =3D parent_bus; } - if (iommu_bus && iommu_bus->iommu_fn) { + if (!pci_bus_bypass_iommu(bus) && iommu_bus && iommu_bus->iommu_fn) { return iommu_bus->iommu_fn(bus, iommu_bus->iommu_opaque, devfn); } return &address_space_memory; diff --git a/hw/pci/pci_host.c b/hw/pci/pci_host.c index 8ca5fadcbd..cf02f0d6a5 100644 --- a/hw/pci/pci_host.c +++ b/hw/pci/pci_host.c @@ -222,6 +222,7 @@ const VMStateDescription vmstate_pcihost =3D { static Property pci_host_properties_common[] =3D { DEFINE_PROP_BOOL("x-config-reg-migration-enabled", PCIHostState, mig_enabled, true), + DEFINE_PROP_BOOL("bypass-iommu", PCIHostState, bypass_iommu, false), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 MST From nobody Sat Feb 7 06:45:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16262151486511009.141463827007; Tue, 13 Jul 2021 15:25:48 -0700 (PDT) Received: from localhost ([::1]:54346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3QqZ-0006bC-GD for importer@patchew.org; Tue, 13 Jul 2021 18:25:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QcH-0007no-ED for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26088) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QcG-00085i-0q for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:01 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-337-edn1VnOwNse186E3IdJkPQ-1; Tue, 13 Jul 2021 18:10:57 -0400 Received: by mail-wr1-f72.google.com with SMTP id z6-20020a5d4c860000b029013a10564614so317136wrs.15 for ; Tue, 13 Jul 2021 15:10:57 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id r17sm3476726wmq.13.2021.07.13.15.10.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:10:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214258; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZFXStzDbpHZ3x7owVBtjJeqaH/pfDgxn4UIZ7oQ1Es0=; b=VsvwKzJ3bxorIypQsx6T4fmkz7HwMwwSqjxIhnrSfJS6uuol7wL48tshwZQON57w3JrSjn Im7evG6+y6BrTTf/ayghUQ3rbRcTlh+cewHTpI0CcaKIRFTAQr4lJ6tfQ7ZYBeoDmQdZTT 7iZFDIXRdKFk3sB6DE4hdTv3T4ze57Y= X-MC-Unique: edn1VnOwNse186E3IdJkPQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ZFXStzDbpHZ3x7owVBtjJeqaH/pfDgxn4UIZ7oQ1Es0=; b=g+LEXkOTWzUAbPvhdD9GXvwPKEe2vcltAUUa1pZNYGbdbkhYNCQh1ef9VOManl7M6q fYW9jpvlvCAHvk1uym1KQlAtw6Py/rdn22xdLgCED46+MYN3rLSHbi9sL8vzgM4pbhEA 6fFagByN12U2fKLaAbRdybOW0n0bqJP+HvZKpNUdsRTSlBxiCWEWgMhvrlPxXRKObCZm Ktwm6Yo1uzbRCaJ7Wh4LtVncpsdVjiDdcgNiEA40bhYhMqLrMpuzCsoDkoYi2LrTysSZ yksPwl1brik6kzQUfpc26FoVnOMv88F47C/zKe5kGrDJJGAZCmp+jh4fM7QIadyTaEog DEjA== X-Gm-Message-State: AOAM533hyEX/FRNTs3XYk8jfe9u+a1BdR1PlASfFxPXkrJNkjOBIQkZs eUvWEyzef7te7+wv0Xw/IxYS00eXdKRqk4Jz+e4OSsEspuUNTog86F98jIUE69thHhCMoN3JuyH OxSqm8/0lyotTl/Wljff7xaWfnrLscjcbiTYyJN4u575LLNKhE+oJGDDlGHKY X-Received: by 2002:a7b:c5d8:: with SMTP id n24mr7592936wmk.51.1626214255858; Tue, 13 Jul 2021 15:10:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0ZzWe9I73aGGO7j1OwNTiA6zd2fs/BshULqswmanHj9MZR8RlEoEEEdK4yMo1FKKHirTXUg== X-Received: by 2002:a7b:c5d8:: with SMTP id n24mr7592917wmk.51.1626214255693; Tue, 13 Jul 2021 15:10:55 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:52 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 15/23] hw/pxb: Add a bypass iommu property Message-ID: <20210713220946.212562-16-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Xingang Wang , Eric Auger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626215150207100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xingang Wang Add a bypass_iommu property for pci_expander_bridge, the property is used to indicate whether pxb root bus will bypass iommu. By default the bypass_iommu is disabled, and it can be enabled with: qemu -device pxb-pcie,bus_nr=3D0x10,addr=3D0x1,bypass_iommu=3Dtrue Signed-off-by: Xingang Wang Reviewed-by: Eric Auger Message-Id: <1625748919-52456-3-git-send-email-wangxingang5@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/pci-bridge/pci_expander_bridge.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expand= er_bridge.c index aedded1064..7112dc3062 100644 --- a/hw/pci-bridge/pci_expander_bridge.c +++ b/hw/pci-bridge/pci_expander_bridge.c @@ -57,6 +57,7 @@ struct PXBDev { =20 uint8_t bus_nr; uint16_t numa_node; + bool bypass_iommu; }; =20 static PXBDev *convert_to_pxb(PCIDevice *dev) @@ -255,6 +256,7 @@ static void pxb_dev_realize_common(PCIDevice *dev, bool= pcie, Error **errp) bus->map_irq =3D pxb_map_irq_fn; =20 PCI_HOST_BRIDGE(ds)->bus =3D bus; + PCI_HOST_BRIDGE(ds)->bypass_iommu =3D pxb->bypass_iommu; =20 pxb_register_bus(dev, bus, &local_err); if (local_err) { @@ -301,6 +303,7 @@ static Property pxb_dev_properties[] =3D { /* Note: 0 is not a legal PXB bus number. */ DEFINE_PROP_UINT8("bus_nr", PXBDev, bus_nr, 0), DEFINE_PROP_UINT16("numa_node", PXBDev, numa_node, NUMA_NODE_UNASSIGNE= D), + DEFINE_PROP_BOOL("bypass_iommu", PXBDev, bypass_iommu, false), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 MST From nobody Sat Feb 7 06:45:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626215323389822.4647506551674; Tue, 13 Jul 2021 15:28:43 -0700 (PDT) Received: from localhost ([::1]:34774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3QtO-0003yG-9i for importer@patchew.org; Tue, 13 Jul 2021 18:28:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55932) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QfE-0007OS-3Q for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:14:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48381) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QfC-0001o5-EB for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:14:03 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-221-yzeknj2UPr25h3NdzCYzMg-1; Tue, 13 Jul 2021 18:11:00 -0400 Received: by mail-wr1-f72.google.com with SMTP id 32-20020adf82a30000b029013b21c75294so317391wrc.14 for ; Tue, 13 Jul 2021 15:11:00 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id t22sm284297wmi.22.2021.07.13.15.10.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:10:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214441; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wGJK3zOQMsPUthycRa07iCj/XcAJGJjnk+sZAHLKKJI=; b=JtJR5lYlDWiaC44H1Nkjk+o2ETyuwWbJbm4MQzLDHsrwyMAZHD8BIeIuol/aomeY5bcSg8 p1tJq11BKAEwHzwXAOigHLShKTVjl6uHV35ySv3pIP1v6NBBjAtJJs88y3CyfNinZErGni ulsy5bgF/WxC6xu/40q/G6tFlWKXKWY= X-MC-Unique: yzeknj2UPr25h3NdzCYzMg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=wGJK3zOQMsPUthycRa07iCj/XcAJGJjnk+sZAHLKKJI=; b=pBG8bGNDyZRrKWU4DYGBBMFnlkzCmLlLasX/qdF7q4rhIYA82oI0OhQz+2hStfPsyP CJNboK22ns/J/+uBCmT+L9ZKZPXs7rD+kr8A209zr+jxv0a7YAQqfdtT4AxVTSiwWwsj oiX58F7yaZQ/PQTzvwzfa0PBt0H3NnMCd297c4VfY5GnG9C1Ivz4Elt8ADgETfT2T4V7 +ruqWdjoF6nQ015SoqDzl/jNkrmote+3DSnVCmtnqwo/ciMZvETEcBEc+lq9XE1OK5RQ f9vGzKlo5/RvUgf2e+GCipA6mzm6dp6wTFr0WMWdGdl2D0KkbkmCtGeAHJcGks5GggyD 4UdQ== X-Gm-Message-State: AOAM530zhj2hSshJFy+FEi0B6F/N9lhvGJX5VV45wNtynv0OWh1K3X0P Ee2Xg+EJ+U123Mu0gkLk0ftTf4tIDQNPtpGsszWbFIiIr60FYYOgT+4swW/YL0mISzq41GjF+lR wb+VHrLID5mf3jUMDCWySOnNvbl+fMFt+bbGrxj7pZ0WU9FuTkoPhqzuMT/yv X-Received: by 2002:a05:600c:4896:: with SMTP id j22mr7327332wmp.43.1626214259328; Tue, 13 Jul 2021 15:10:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzx/Gmoq5ndgjugVPG6wwPGM9kRMcqJU/sjnPw7tKEhC0xlg9QuX7UHQlIKjsh4RHFgcy2gow== X-Received: by 2002:a05:600c:4896:: with SMTP id j22mr7327313wmp.43.1626214259099; Tue, 13 Jul 2021 15:10:59 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:56 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 16/23] hw/arm/virt: Add default_bus_bypass_iommu machine option Message-ID: <20210713220946.212562-17-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no 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: , Cc: Peter Maydell , qemu-arm@nongnu.org, Xingang Wang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626215324658100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xingang Wang Add a default_bus_bypass_iommu machine option to enable/disable bypass_iommu for default root bus. The option is disabled by default and can be enabled with: $QEMU -machine virt,iommu=3Dsmmuv3,default_bus_bypass_iommu=3Dtrue Signed-off-by: Xingang Wang Message-Id: <1625748919-52456-4-git-send-email-wangxingang5@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/arm/virt.h | 1 + hw/arm/virt.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 921416f918..9661c46699 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -147,6 +147,7 @@ struct VirtMachineState { OnOffAuto acpi; VirtGICType gic_version; VirtIOMMUType iommu; + bool default_bus_bypass_iommu; VirtMSIControllerType msi_controller; uint16_t virtio_iommu_bdf; struct arm_boot_info bootinfo; diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 93ab9d21ea..81eda46b0b 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1367,6 +1367,7 @@ static void create_pcie(VirtMachineState *vms) } =20 pci =3D PCI_HOST_BRIDGE(dev); + pci->bypass_iommu =3D vms->default_bus_bypass_iommu; vms->bus =3D pci->bus; if (vms->bus) { for (i =3D 0; i < nb_nics; i++) { @@ -2322,6 +2323,21 @@ static void virt_set_iommu(Object *obj, const char *= value, Error **errp) } } =20 +static bool virt_get_default_bus_bypass_iommu(Object *obj, Error **errp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(obj); + + return vms->default_bus_bypass_iommu; +} + +static void virt_set_default_bus_bypass_iommu(Object *obj, bool value, + Error **errp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(obj); + + vms->default_bus_bypass_iommu =3D value; +} + static CpuInstanceProperties virt_cpu_index_to_props(MachineState *ms, unsigned cpu_index) { @@ -2661,6 +2677,13 @@ static void virt_machine_class_init(ObjectClass *oc,= void *data) "Set the IOMMU type. " "Valid values are none and smmuv= 3"); =20 + object_class_property_add_bool(oc, "default_bus_bypass_iommu", + virt_get_default_bus_bypass_iommu, + virt_set_default_bus_bypass_iommu); + object_class_property_set_description(oc, "default_bus_bypass_iommu", + "Set on/off to enable/disable " + "bypass_iommu for default root b= us"); + object_class_property_add_bool(oc, "ras", virt_get_ras, virt_set_ras); object_class_property_set_description(oc, "ras", @@ -2728,6 +2751,9 @@ static void virt_instance_init(Object *obj) /* Default disallows iommu instantiation */ vms->iommu =3D VIRT_IOMMU_NONE; =20 + /* The default root bus is attached to iommu by default */ + vms->default_bus_bypass_iommu =3D false; + /* Default disallows RAS instantiation */ vms->ras =3D false; =20 --=20 MST From nobody Sat Feb 7 06:45:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626214784840639.9557768841815; Tue, 13 Jul 2021 15:19:44 -0700 (PDT) Received: from localhost ([::1]:34860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3Qkh-0001xN-I6 for importer@patchew.org; Tue, 13 Jul 2021 18:19:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QcO-000800-I6 for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31466) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QcM-0008Ad-Vw for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:08 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-398--2N1GXkdNsmtCd2Pfi66SQ-1; Tue, 13 Jul 2021 18:11:04 -0400 Received: by mail-wm1-f71.google.com with SMTP id z127-20020a1c7e850000b02901e46e4d52c0so965271wmc.6 for ; Tue, 13 Jul 2021 15:11:04 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id d8sm140342wra.41.2021.07.13.15.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:11:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214266; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LX+oDa7Ni38sjuf/A7aYFuvPqrITohA/75NP3/6hdW8=; b=SqzKHaPD2Hq6kn2V0Cd2hCSZUtC4RSLx/XVo8LAsDj9GuE0CfU+9lLDgAiBEtpK52dndn5 sNu37yyop0KQ3+4YgjulHM6PJl4QzFiXcW9Gs1/WVnIbyvE9l+ZX/AXSXngvSUz77lzH6E TXe3DKvPc81sFGjTGL59l6jHTH+Nza4= X-MC-Unique: -2N1GXkdNsmtCd2Pfi66SQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=LX+oDa7Ni38sjuf/A7aYFuvPqrITohA/75NP3/6hdW8=; b=eABkNS7YPr3fwRBSB1hd57ilxqg3ukBTHce+z1u/tUjdlXWy8dAephP3aMi6gRo+pw uBQU8hLMch1t65f45WvQU4C9AVtQo+tMZ10m9z/hUBStaCiAelyFCwlD337id/qrtVsD LvgeuUVYRyxeIAzPb2i0P4YTVJDhvmmqy4wG5MMbydpIaytpJVWyDrb+Sx5+6WXT9pc0 BnVrEMBJTVQwDNyO/Lsw4GqE+bTYPl7z4NMwpLYATH6uIV2QhUQf/2IL93KcHSu2CZOM vOLru2fK3s5fXpJL3OTizZbVpDs9M61gKMTLW2MVwdgc55z1OjnuInZBm1Qx1kAhNc26 IKjA== X-Gm-Message-State: AOAM532aVo3oaWg0QBute6d5GiI/ZHeQyM65Czuwp0gLXo7mb/oEb3J4 OuFhSkkUbASCmLWNOLw8JeLcZ0SVmv4SPlRnuYvZh/l9L3bg9mYlVKkCyeNH3I6whj9iLd7IwNm USE+9JyTnAQGb/PuX85NWV5tvwCzG2JHx22gLwyVVOPLoMe+IJDTr8aIEP0E/ X-Received: by 2002:a05:6000:1107:: with SMTP id z7mr8698486wrw.228.1626214263232; Tue, 13 Jul 2021 15:11:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZQ06Err8txTdsvxvq8tqB+wRHHi2MrpmlVivPHBhf1rraYuN3WvT7yxuZ5GRWtiJvFTnpAA== X-Received: by 2002:a05:6000:1107:: with SMTP id z7mr8698468wrw.228.1626214263072; Tue, 13 Jul 2021 15:11:03 -0700 (PDT) Date: Tue, 13 Jul 2021 18:10:59 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 17/23] hw/i386: Add a default_bus_bypass_iommu pc machine option Message-ID: <20210713220946.212562-18-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Eduardo Habkost , Richard Henderson , Paolo Bonzini , Xingang Wang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626214786340100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xingang Wang Add a default_bus_bypass_iommu pc machine option to enable/disable bypass_iommu for default root bus. The option is disabled by default and can be enabled with: $QEMU -machine q35,default_bus_bypass_iommu=3Dtrue Signed-off-by: Xingang Wang Message-Id: <1625748919-52456-5-git-send-email-wangxingang5@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/i386/pc.h | 1 + hw/i386/pc.c | 20 ++++++++++++++++++++ hw/pci-host/q35.c | 2 ++ 3 files changed, 23 insertions(+) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 87294f2632..fd741119fa 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -44,6 +44,7 @@ typedef struct PCMachineState { bool sata_enabled; bool pit_enabled; bool hpet_enabled; + bool default_bus_bypass_iommu; uint64_t max_fw_size; =20 /* NUMA information: */ diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 7e03848792..f784a9a91f 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1523,6 +1523,21 @@ static void pc_machine_set_hpet(Object *obj, bool va= lue, Error **errp) pcms->hpet_enabled =3D value; } =20 +static bool pc_machine_get_default_bus_bypass_iommu(Object *obj, Error **e= rrp) +{ + PCMachineState *pcms =3D PC_MACHINE(obj); + + return pcms->default_bus_bypass_iommu; +} + +static void pc_machine_set_default_bus_bypass_iommu(Object *obj, bool valu= e, + Error **errp) +{ + PCMachineState *pcms =3D PC_MACHINE(obj); + + pcms->default_bus_bypass_iommu =3D value; +} + static void pc_machine_get_max_ram_below_4g(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) @@ -1622,6 +1637,7 @@ static void pc_machine_initfn(Object *obj) #ifdef CONFIG_HPET pcms->hpet_enabled =3D true; #endif + pcms->default_bus_bypass_iommu =3D false; =20 pc_system_flash_create(pcms); pcms->pcspk =3D isa_new(TYPE_PC_SPEAKER); @@ -1746,6 +1762,10 @@ static void pc_machine_class_init(ObjectClass *oc, v= oid *data) object_class_property_add_bool(oc, "hpet", pc_machine_get_hpet, pc_machine_set_hpet); =20 + object_class_property_add_bool(oc, "default_bus_bypass_iommu", + pc_machine_get_default_bus_bypass_iommu, + pc_machine_set_default_bus_bypass_iommu); + object_class_property_add(oc, PC_MACHINE_MAX_FW_SIZE, "size", pc_machine_get_max_fw_size, pc_machine_set_max_fw_size, NULL, NULL); diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index 0f37cf056a..ab5a47aff5 100644 --- a/hw/pci-host/q35.c +++ b/hw/pci-host/q35.c @@ -65,6 +65,8 @@ static void q35_host_realize(DeviceState *dev, Error **er= rp) s->mch.address_space_io, 0, TYPE_PCIE_BUS); PC_MACHINE(qdev_get_machine())->bus =3D pci->bus; + pci->bypass_iommu =3D + PC_MACHINE(qdev_get_machine())->default_bus_bypass_iommu; qdev_realize(DEVICE(&s->mch), BUS(pci->bus), &error_fatal); } =20 --=20 MST From nobody Sat Feb 7 06:45:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626215265727753.2589140772734; Tue, 13 Jul 2021 15:27:45 -0700 (PDT) Received: from localhost ([::1]:60198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3QsS-00026r-OR for importer@patchew.org; Tue, 13 Jul 2021 18:27:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QcS-00089b-2O for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52087) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QcQ-0008DW-Do for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:11 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-204-VVDjhnYpPMKy9YlynQmhDA-1; Tue, 13 Jul 2021 18:11:08 -0400 Received: by mail-wr1-f69.google.com with SMTP id k3-20020a5d52430000b0290138092aea94so308122wrc.20 for ; Tue, 13 Jul 2021 15:11:08 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id a10sm142944wrm.12.2021.07.13.15.11.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:11:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214269; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Cem/scxwfuu8t6UBmBGhZX6mWJ6otnXd6jtrNMLMn2M=; b=UOllR5ay5BUej4yOF8gcAHw4Yh/e/tOM1nbQVET4PtKHV8Myp8mbsttdKJiEtcyxpyC8Fw XGkIkqdSmQKfg2aUh9G78sVFM4dtR8Wg49Dw6Ap9+KtQaepIODN68Yb+E/onAjmkpSk1nW JCPO0SGQPLXjyyqxUw4YRb/vfh/90hY= X-MC-Unique: VVDjhnYpPMKy9YlynQmhDA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Cem/scxwfuu8t6UBmBGhZX6mWJ6otnXd6jtrNMLMn2M=; b=uQnP2ECXal95ed6h7hWxadc5U3ShPZqGDvPpaWMCFukdubUVbtukDfjFRG2/sUcINt XY0cLDnXcGrKf7j9vp9sr8WJRriBUgZMK/c5qZndR+QUQphCJYdLH/n+on1ybcwLTHcJ 4rzFzoOqnn3zceBGWMFyOcc0GryclhfUeDnIHmjssg25DzzWPTqaYPdW64MsGKL2vlms xg2DI8pOoSBh3o90CIa7l3DRGC8hjkZ0S2A+pNV3vrqRHuUbblrx0zj0zHWGjSdaiiab 0LWUXfwITVC947X10pbUzsqx67HPo9AHO+0SIjkx4EnfcIsWz/y2D51+kC1iu5DNmRkx LLNA== X-Gm-Message-State: AOAM5315EeSvi5ZSK9OJJnXuKAJo6EgXfcAWNME5+EdBN6gBhObbvKSt VmkPWEqOrk/lwxrN77W1f1v240of45IJwVFu3I3IH5Cz7Ta/RYaEdjWq0oZ8tucr1WfI7WaR2P/ wScUrgjMyPJ5xkpTEa44YuDDrS/Njkx4tzj6fFyAXywYTa4GUPASUuN75UhS/ X-Received: by 2002:a5d:6a05:: with SMTP id m5mr8642708wru.253.1626214267063; Tue, 13 Jul 2021 15:11:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkqv5GQFuX8QmGr6LKnmVhZ5kCYGAXxB9xfdxwNdzSW+56WF01NL+trIFMyyptad6LYRRGcQ== X-Received: by 2002:a5d:6a05:: with SMTP id m5mr8642683wru.253.1626214266849; Tue, 13 Jul 2021 15:11:06 -0700 (PDT) Date: Tue, 13 Jul 2021 18:11:03 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 18/23] hw/pci: Add pci_bus_range() to get PCI bus number range Message-ID: <20210713220946.212562-19-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Xingang Wang , Eric Auger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626215266709100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xingang Wang This helps to get the min and max bus number of a PCI bus hierarchy. Signed-off-by: Xingang Wang Reviewed-by: Eric Auger Message-Id: <1625748919-52456-6-git-send-email-wangxingang5@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/pci/pci.h | 1 + hw/pci/pci.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index f4d51b672b..d0f4266e37 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -450,6 +450,7 @@ static inline PCIBus *pci_get_bus(const PCIDevice *dev) return PCI_BUS(qdev_get_parent_bus(DEVICE(dev))); } int pci_bus_num(PCIBus *s); +void pci_bus_range(PCIBus *bus, int *min_bus, int *max_bus); static inline int pci_dev_bus_num(const PCIDevice *dev) { return pci_bus_num(pci_get_bus(dev)); diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 27d588e268..23d2ae2ab2 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -537,6 +537,22 @@ int pci_bus_num(PCIBus *s) return PCI_BUS_GET_CLASS(s)->bus_num(s); } =20 +/* Returns the min and max bus numbers of a PCI bus hierarchy */ +void pci_bus_range(PCIBus *bus, int *min_bus, int *max_bus) +{ + int i; + *min_bus =3D *max_bus =3D pci_bus_num(bus); + + for (i =3D 0; i < ARRAY_SIZE(bus->devices); ++i) { + PCIDevice *dev =3D bus->devices[i]; + + if (dev && PCI_DEVICE_GET_CLASS(dev)->is_bridge) { + *min_bus =3D MIN(*min_bus, dev->config[PCI_SECONDARY_BUS]); + *max_bus =3D MAX(*max_bus, dev->config[PCI_SUBORDINATE_BUS]); + } + } +} + int pci_bus_numa_node(PCIBus *bus) { return PCI_BUS_GET_CLASS(bus)->numa_node(bus); --=20 MST From nobody Sat Feb 7 06:45:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626215045715787.8469979607846; Tue, 13 Jul 2021 15:24:05 -0700 (PDT) Received: from localhost ([::1]:47920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3Qou-0002Hb-6q for importer@patchew.org; Tue, 13 Jul 2021 18:24:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55312) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QcW-0008No-AP for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50818) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QcT-0008FO-SL for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:16 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-601-JvaEMn_xPj-oWOi1568ffA-1; Tue, 13 Jul 2021 18:11:11 -0400 Received: by mail-wm1-f71.google.com with SMTP id v25-20020a1cf7190000b0290197a4be97b7so147471wmh.9 for ; Tue, 13 Jul 2021 15:11:11 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id e11sm188985wrt.0.2021.07.13.15.11.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:11:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214272; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=2tkVF2ulgVK1I83asV+DkCniiWWlnhyo+M2eGWekklE=; b=AYm/4riVC53MXycCzUhRiPvLiwCbzmVMQ5vPzkpqwO0RcNskUV9V8TTZp37lBgZLkKoXSV /iNIVs7y8Mz3mi95X7jX5sll65u/uOs0Uo8STOeo9qouc5lZg/C0duMlhrQWuLMm7+Zv0o A/Aqo6/3fQoSHK0yJlzJE5VJh5/VzPY= X-MC-Unique: JvaEMn_xPj-oWOi1568ffA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=2tkVF2ulgVK1I83asV+DkCniiWWlnhyo+M2eGWekklE=; b=NW+O0PPr1HuhWBtAYJf2ohekfPS5b3HchyAVuy7yPlmnAbVl6VZgkyWhXQLXi5DAmS aSiU3vMJAyldHlOwh9plWHMkOHZwS07q9ptDctwZNKkuCoP4ruk4GJpleiX6hK3/LzHS Ve6Yv/eFt7CZ69xZT3F6y/FG+AiYICeVuNxS++NQey3r9a0xHEVXqc0YKhTUawYxeuC6 3SSgEsFR5QORa8vRxeUWlq3VhcuvRQlCNM35rC/paehXjIZn9ipMZ/ZO2qcHL2zkpFa+ w5b9t8tjESrGaedRM07cW9QSmcejCVyTFOnEaVgw3gk/MIBJ3KSrb8WwEuwI3HSJPsJP dJ8g== X-Gm-Message-State: AOAM532KQqRZE95ChX/6WpaRIB6N4DYJUoUWlNufVz+aoXUTkdCkmKft kjmBWJz2es6LinoIsWmzP3wIalxu1WY+rQ9nhW3Nybsk87dIsfJyiq0AdBh/dX7FnlUoKURCR2F B2d++zAwJpKYkLws8HY22ak6orNkA+KByIP/4np9Svz3Y0WFAQGr3GOclNZU+ X-Received: by 2002:a1c:1dd4:: with SMTP id d203mr430979wmd.28.1626214270254; Tue, 13 Jul 2021 15:11:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxU9n1lTQLUOQKTw2cLvvAvQQ8FJBdKDhzBDiGTc6+aqfFXgr5JQ/CgGASke0vGARkLi6ZbaQ== X-Received: by 2002:a1c:1dd4:: with SMTP id d203mr430956wmd.28.1626214270020; Tue, 13 Jul 2021 15:11:10 -0700 (PDT) Date: Tue, 13 Jul 2021 18:11:07 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 19/23] hw/arm/virt-acpi-build: Add IORT support to bypass SMMUv3 Message-ID: <20210713220946.212562-20-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no 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: , Cc: Peter Maydell , Igor Mammedov , qemu-arm@nongnu.org, Xingang Wang , Shannon Zhao Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626215046489100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xingang Wang When we build IORT table with SMMUv3 and bypass iommu feature enabled, we can no longer setup one map from RC to SMMUv3 covering the whole RIDs. We need to walk the PCI bus and check whether the root bus will bypass iommu, setup RC -> SMMUv3 -> ITS map for RC which will not bypass iommu. When a SMMUv3 node exist, we setup the idmap from SMMUv3 to ITS covering the whole RIDs, and only modify the map from RC to SMMUv3. We build RC -> SMMUv3 -> ITS map for root bus with bypass_iommu disabled, and build idmap from RC to ITS directly for the rest of the whole RID space. For example we run qemu with command line: qemu/build/aarch64-softmmu/qemu-system-aarch64 \ -kernel arch/arm64/boot/Image \ -enable-kvm \ -cpu host \ -m 8G \ -smp 8,sockets=3D2,cores=3D4,threads=3D1 \ -machine virt,kernel_irqchip=3Don,gic-version=3D3,iommu=3Dsmmuv3,default_b= us_bypass_iommu=3Dtrue \ -drive file=3D./QEMU_EFI-pflash.raw,if=3Dpflash,format=3Draw,unit=3D0,read= only=3Don \ -device pxb-pcie,bus_nr=3D0x10,id=3Dpci.10,bus=3Dpcie.0,addr=3D0x3.0x1 \ -device pxb-pcie,bus_nr=3D0x20,id=3Dpci.20,bus=3Dpcie.0,addr=3D0x3.0x2,byp= ass_iommu=3Dtrue \ -device pcie-root-port,port=3D0x20,chassis=3D1,id=3Dpci.1,bus=3Dpcie.0,add= r=3D0x2 \ -device pcie-root-port,port=3D0x20,chassis=3D11,id=3Dpci.11,bus=3Dpci.10,a= ddr=3D0x1 \ -device pcie-root-port,port=3D0x20,chassis=3D21,id=3Dpci.21,bus=3Dpci.20,a= ddr=3D0x1 \ -device virtio-scsi-pci,id=3Dscsi0,bus=3Dpci.1,addr=3D0x1 \ -device virtio-scsi-pci,id=3Dscsi1,bus=3Dpci.11,addr=3D0x1 \ -device virtio-scsi-pci,id=3Dscsi2,bus=3Dpci.21,addr=3D0x1 \ -initrd /mnt/davinci/wxg/kill-linux/rootfs/mfs.cpio.gz \ -nographic \ -append "rdinit=3Dinit console=3DttyAMA0 earlycon=3Dpl011,0x9000000 nokasl= r" \ And we get guest configuration: -+-[0000:20]---01.0-[21]-- +-[0000:10]---01.0-[11]-- \-[0000:00]-+-00.0 Device 1b36:0008 +-01.0 Device 1af4:1000 \-02.0-[01]-- With bypass_iommu enabled, the attached devices will bypass iommu. /sys/class/iommu/smmu3.0x0000000009050000/ |-- device -> ../../../arm-smmu-v3.0.auto |-- devices | `-- 0000:10:01.0 -> ../../../../../pci0000:10/0000:10:01.0 Signed-off-by: Xingang Wang Message-Id: <1625748919-52456-7-git-send-email-wangxingang5@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/arm/virt-acpi-build.c | 114 +++++++++++++++++++++++++++++++++++---- 1 file changed, 103 insertions(+), 11 deletions(-) diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index f1024843dd..037cc1fd82 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -44,6 +44,7 @@ #include "hw/acpi/tpm.h" #include "hw/pci/pcie_host.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/pci-host/gpex.h" #include "hw/arm/virt.h" #include "hw/mem/nvdimm.h" @@ -239,23 +240,89 @@ static void acpi_dsdt_add_tpm(Aml *scope, VirtMachine= State *vms) } #endif =20 +/* Build the iort ID mapping to SMMUv3 for a given PCI host bridge */ +static int +iort_host_bridges(Object *obj, void *opaque) +{ + GArray *idmap_blob =3D opaque; + + if (object_dynamic_cast(obj, TYPE_PCI_HOST_BRIDGE)) { + PCIBus *bus =3D PCI_HOST_BRIDGE(obj)->bus; + + if (bus && !pci_bus_bypass_iommu(bus)) { + int min_bus, max_bus; + + pci_bus_range(bus, &min_bus, &max_bus); + + AcpiIortIdMapping idmap =3D { + .input_base =3D min_bus << 8, + .id_count =3D (max_bus - min_bus + 1) << 8, + }; + g_array_append_val(idmap_blob, idmap); + } + } + + return 0; +} + +static int iort_idmap_compare(gconstpointer a, gconstpointer b) +{ + AcpiIortIdMapping *idmap_a =3D (AcpiIortIdMapping *)a; + AcpiIortIdMapping *idmap_b =3D (AcpiIortIdMapping *)b; + + return idmap_a->input_base - idmap_b->input_base; +} + static void build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) { - int nb_nodes, iort_start =3D table_data->len; + int i, nb_nodes, rc_mapping_count, iort_start =3D table_data->len; AcpiIortIdMapping *idmap; AcpiIortItsGroup *its; AcpiIortTable *iort; AcpiIortSmmu3 *smmu; size_t node_size, iort_node_offset, iort_length, smmu_offset =3D 0; AcpiIortRC *rc; + GArray *smmu_idmaps =3D g_array_new(false, true, sizeof(AcpiIortIdMapp= ing)); + GArray *its_idmaps =3D g_array_new(false, true, sizeof(AcpiIortIdMappi= ng)); =20 iort =3D acpi_data_push(table_data, sizeof(*iort)); =20 if (vms->iommu =3D=3D VIRT_IOMMU_SMMUV3) { + AcpiIortIdMapping next_range =3D {0}; + + object_child_foreach_recursive(object_get_root(), + iort_host_bridges, smmu_idmaps); + + /* Sort the smmu idmap by input_base */ + g_array_sort(smmu_idmaps, iort_idmap_compare); + + /* + * Split the whole RIDs by mapping from RC to SMMU, + * build the ID mapping from RC to ITS directly. + */ + for (i =3D 0; i < smmu_idmaps->len; i++) { + idmap =3D &g_array_index(smmu_idmaps, AcpiIortIdMapping, i); + + if (next_range.input_base < idmap->input_base) { + next_range.id_count =3D idmap->input_base - next_range.inp= ut_base; + g_array_append_val(its_idmaps, next_range); + } + + next_range.input_base =3D idmap->input_base + idmap->id_count; + } + + /* Append the last RC -> ITS ID mapping */ + if (next_range.input_base < 0xFFFF) { + next_range.id_count =3D 0xFFFF - next_range.input_base; + g_array_append_val(its_idmaps, next_range); + } + nb_nodes =3D 3; /* RC, ITS, SMMUv3 */ + rc_mapping_count =3D smmu_idmaps->len + its_idmaps->len; } else { nb_nodes =3D 2; /* RC, ITS */ + rc_mapping_count =3D 1; } =20 iort_length =3D sizeof(*iort); @@ -307,13 +374,13 @@ build_iort(GArray *table_data, BIOSLinker *linker, Vi= rtMachineState *vms) } =20 /* Root Complex Node */ - node_size =3D sizeof(*rc) + sizeof(*idmap); + node_size =3D sizeof(*rc) + sizeof(*idmap) * rc_mapping_count; iort_length +=3D node_size; rc =3D acpi_data_push(table_data, node_size); =20 rc->type =3D ACPI_IORT_NODE_PCI_ROOT_COMPLEX; rc->length =3D cpu_to_le16(node_size); - rc->mapping_count =3D cpu_to_le32(1); + rc->mapping_count =3D cpu_to_le32(rc_mapping_count); rc->mapping_offset =3D cpu_to_le32(sizeof(*rc)); =20 /* fully coherent device */ @@ -321,20 +388,45 @@ build_iort(GArray *table_data, BIOSLinker *linker, Vi= rtMachineState *vms) rc->memory_properties.memory_flags =3D 0x3; /* CCA =3D CPM =3D DCAS = =3D 1 */ rc->pci_segment_number =3D 0; /* MCFG pci_segment */ =20 - /* Identity RID mapping covering the whole input RID range */ - idmap =3D &rc->id_mapping_array[0]; - idmap->input_base =3D 0; - idmap->id_count =3D cpu_to_le32(0xFFFF); - idmap->output_base =3D 0; - if (vms->iommu =3D=3D VIRT_IOMMU_SMMUV3) { - /* output IORT node is the smmuv3 node */ - idmap->output_reference =3D cpu_to_le32(smmu_offset); + AcpiIortIdMapping *range; + + /* translated RIDs connect to SMMUv3 node: RC -> SMMUv3 -> ITS */ + for (i =3D 0; i < smmu_idmaps->len; i++) { + idmap =3D &rc->id_mapping_array[i]; + range =3D &g_array_index(smmu_idmaps, AcpiIortIdMapping, i); + + idmap->input_base =3D cpu_to_le32(range->input_base); + idmap->id_count =3D cpu_to_le32(range->id_count); + idmap->output_base =3D cpu_to_le32(range->input_base); + /* output IORT node is the smmuv3 node */ + idmap->output_reference =3D cpu_to_le32(smmu_offset); + } + + /* bypassed RIDs connect to ITS group node directly: RC -> ITS */ + for (i =3D 0; i < its_idmaps->len; i++) { + idmap =3D &rc->id_mapping_array[smmu_idmaps->len + i]; + range =3D &g_array_index(its_idmaps, AcpiIortIdMapping, i); + + idmap->input_base =3D cpu_to_le32(range->input_base); + idmap->id_count =3D cpu_to_le32(range->id_count); + idmap->output_base =3D cpu_to_le32(range->input_base); + /* output IORT node is the ITS group node (the first node) */ + idmap->output_reference =3D cpu_to_le32(iort_node_offset); + } } else { + /* Identity RID mapping covering the whole input RID range */ + idmap =3D &rc->id_mapping_array[0]; + idmap->input_base =3D cpu_to_le32(0); + idmap->id_count =3D cpu_to_le32(0xFFFF); + idmap->output_base =3D cpu_to_le32(0); /* output IORT node is the ITS group node (the first node) */ idmap->output_reference =3D cpu_to_le32(iort_node_offset); } =20 + g_array_free(smmu_idmaps, true); + g_array_free(its_idmaps, true); + /* * Update the pointer address in case table_data->data moves during ab= ove * acpi_data_push operations. --=20 MST From nobody Sat Feb 7 06:45:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626214700190228.9477531134529; Tue, 13 Jul 2021 15:18:20 -0700 (PDT) Received: from localhost ([::1]:57270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3QjL-0006WC-4u for importer@patchew.org; Tue, 13 Jul 2021 18:18:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qca-0000B1-KR for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55256) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3QcY-0008JK-6v for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:20 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-511-zXj1Ayn9N2qcQu6Au1po1g-1; Tue, 13 Jul 2021 18:11:16 -0400 Received: by mail-wm1-f71.google.com with SMTP id v25-20020a1cf7190000b0290197a4be97b7so147544wmh.9 for ; Tue, 13 Jul 2021 15:11:16 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id r4sm115204wre.84.2021.07.13.15.11.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:11:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214277; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5PzNQJlTGNrpijxK0VyVgr7xwJWYbOTHaTkK7HI7uYg=; b=SElgyys7cu1JAvAt4rA64IS9nJVeNoZ9LL7mesrizVeUrePhnnJuqKpzRo4dhR1///KSRu c+rCWuPTw00HSzNQla+WI61hUpzQbByDLbPUetMmTdz8cjldqYsvrhvB6YzZXcNR7i6GnV 1OrKkrHTZP0wVj/PvJHItkNs2La8804= X-MC-Unique: zXj1Ayn9N2qcQu6Au1po1g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=5PzNQJlTGNrpijxK0VyVgr7xwJWYbOTHaTkK7HI7uYg=; b=rYcbM13GXKVw04LsngvqGk/izZMJPKIIOyKMKKkW2BTEAukFLXGRfFHA7l1y48Qvm0 qFhsntdgJqTasCgXhxPChVqsNgCPANf1LJmRF9dCX8sftedatl7po9/kWGNLZ673Ln4g xhHZ9sZfYc9ouje6frmcx3xn7l/mcZcNpVDXOo4YL3WSrbcwj8E0SDMvFGMpn5Y5VkeW H+cSyh2TvVUfeuEF9/SqQpiVBn/gmq1b0eTRmRTD0DbCrJD8RzgN0sh4twYJ0cbESWZ9 2taOGNN8zdttEm/RQOmSOx6G0KG1vo5To3q9FBDl5nx46BTB5ljXfdc2B4jUCv3+kSyG pB7A== X-Gm-Message-State: AOAM531OjvwGHsVW8aqTwWHzvJloaTYmsWNyE0EXpqj9bzrBd48VN1Gt DLIMHbTFIq8VP8qIEfdWQUWJj0nviZ/5bLKwQDNlZ72mRAZf75PKQdwANtrnmH3Tp5kqM+QNMT5 xfpXzHbt+sDc8bipYivKqy4jBPGCQN/IC7k6rCXy8XrqiFOCRVktJfoAiTM1c X-Received: by 2002:adf:eccf:: with SMTP id s15mr8299797wro.176.1626214274867; Tue, 13 Jul 2021 15:11:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLS6osSrZ+ob3TO3W29OKjdwb3Y+cUd/B5Zq54nl4mPcYSWzmUh5qmnPMyUN2pjB5xcoG1oQ== X-Received: by 2002:adf:eccf:: with SMTP id s15mr8299765wro.176.1626214274619; Tue, 13 Jul 2021 15:11:14 -0700 (PDT) Date: Tue, 13 Jul 2021 18:11:10 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 20/23] hw/i386/acpi-build: Add DMAR support to bypass iommu Message-ID: <20210713220946.212562-21-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Disposition: inline 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=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Xingang Wang , Richard Henderson , Igor Mammedov , Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626214701756100001 From: Xingang Wang In DMAR table, the drhd is set to cover all PCI devices when intel_iommu is on. To support bypass iommu feature, we need to walk the PCI bus with bypass_iommu disabled and add explicit scope data in DMAR drhd structure. /mnt/sdb/wxg/qemu-next/qemu/build/x86_64-softmmu/qemu-system-x86_64 \ -machine q35,accel=3Dkvm,default_bus_bypass_iommu=3Dtrue \ -cpu host \ -m 16G \ -smp 36,sockets=3D2,cores=3D18,threads=3D1 \ -device pxb-pcie,bus_nr=3D0x10,id=3Dpci.10,bus=3Dpcie.0,addr=3D0x3 \ -device pxb-pcie,bus_nr=3D0x20,id=3Dpci.20,bus=3Dpcie.0,addr=3D0x4,bypass_= iommu=3Dtrue \ -device pcie-root-port,port=3D0x1,chassis=3D1,id=3Dpci.11,bus=3Dpci.10,add= r=3D0x0 \ -device pcie-root-port,port=3D0x2,chassis=3D2,id=3Dpci.21,bus=3Dpci.20,add= r=3D0x0 \ -device virtio-scsi-pci,id=3Dscsi0,bus=3Dpci.11,addr=3D0x0 \ -device virtio-scsi-pci,id=3Dscsi1,bus=3Dpci.21,addr=3D0x0 \ -drive file=3D/mnt/sdb/wxg/fedora-48g.qcow2,format=3Dqcow2,if=3Dnone,id=3D= drive-scsi0-0-0-0,cache=3Dnone,aio=3Dnative \ -device scsi-hd,bus=3Dscsi1.0,channel=3D0,scsi-id=3D0,lun=3D0,drive=3Ddriv= e-scsi0-0-0-0,id=3Dscsi0-0-0-0,bootindex=3D1 \ -device intel-iommu \ -nographic \ And we get the guest configuration: ~ lspci -vt -+-[0000:20]---00.0-[21]----00.0 Red Hat, Inc. Virtio SCSI +-[0000:10]---00.0-[11]----00.0 Red Hat, Inc. Virtio SCSI \-[0000:00]-+-00.0 Intel Corporation 82G33/G31/P35/P31 Express DRAM Contr= oller +-01.0 Device 1234:1111 +-02.0 Intel Corporation 82574L Gigabit Network Connection +-03.0 Red Hat, Inc. QEMU PCIe Expander bridge +-04.0 Red Hat, Inc. QEMU PCIe Expander bridge +-1f.0 Intel Corporation 82801IB (ICH9) LPC Interface Control= ler +-1f.2 Intel Corporation 82801IR/IO/IH (ICH9R/DO/DH) 6 port S= ATA Controller [AHCI mode] \-1f.3 Intel Corporation 82801I (ICH9 Family) SMBus Controller With bypass_iommu enabled on root bus, the attached devices will bypass iom= mu: /sys/class/iommu/dmar0 =E2=94=9C=E2=94=80=E2=94=80 devices =E2=94=82=C2=A0=C2=A0 =E2=94=9C=E2=94=80=E2=94=80 0000:10:00.0 -> ../../../= ../pci0000:10/0000:10:00.0 =E2=94=82=C2=A0=C2=A0 =E2=94=94=E2=94=80=E2=94=80 0000:11:00.0 -> ../../../= ../pci0000:10/0000:10:00.0/0000:11:00.0 Signed-off-by: Xingang Wang Message-Id: <1625748919-52456-8-git-send-email-wangxingang5@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/acpi-build.c | 68 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index bc966a4110..7efc6285ac 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2022,6 +2022,56 @@ build_srat(GArray *table_data, BIOSLinker *linker, M= achineState *machine) x86ms->oem_table_id); } =20 +/* + * Insert DMAR scope for PCI bridges and endpoint devcie + */ +static void +insert_scope(PCIBus *bus, PCIDevice *dev, void *opaque) +{ + GArray *scope_blob =3D opaque; + AcpiDmarDeviceScope *scope =3D NULL; + + if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_BRIDGE)) { + /* Dmar Scope Type: 0x02 for PCI Bridge */ + build_append_int_noprefix(scope_blob, 0x02, 1); + } else { + /* Dmar Scope Type: 0x01 for PCI Endpoint Device */ + build_append_int_noprefix(scope_blob, 0x01, 1); + } + + /* length */ + build_append_int_noprefix(scope_blob, + sizeof(*scope) + sizeof(scope->path[0]), 1); + /* reserved */ + build_append_int_noprefix(scope_blob, 0, 2); + /* enumeration_id */ + build_append_int_noprefix(scope_blob, 0, 1); + /* bus */ + build_append_int_noprefix(scope_blob, pci_bus_num(bus), 1); + /* device */ + build_append_int_noprefix(scope_blob, PCI_SLOT(dev->devfn), 1); + /* function */ + build_append_int_noprefix(scope_blob, PCI_FUNC(dev->devfn), 1); +} + +/* For a given PCI host bridge, walk and insert DMAR scope */ +static int +dmar_host_bridges(Object *obj, void *opaque) +{ + GArray *scope_blob =3D opaque; + + if (object_dynamic_cast(obj, TYPE_PCI_HOST_BRIDGE)) { + PCIBus *bus =3D PCI_HOST_BRIDGE(obj)->bus; + + if (bus && !pci_bus_bypass_iommu(bus)) { + pci_for_each_device(bus, pci_bus_num(bus), insert_scope, + scope_blob); + } + } + + return 0; +} + /* * VT-d spec 8.1 DMA Remapping Reporting Structure * (version Oct. 2014 or later) @@ -2041,6 +2091,15 @@ build_dmar_q35(GArray *table_data, BIOSLinker *linke= r, const char *oem_id, /* Root complex IOAPIC use one path[0] only */ size_t ioapic_scope_size =3D sizeof(*scope) + sizeof(scope->path[0]); IntelIOMMUState *intel_iommu =3D INTEL_IOMMU_DEVICE(iommu); + GArray *scope_blob =3D g_array_new(false, true, 1); + + /* + * A PCI bus walk, for each PCI host bridge. + * Insert scope for each PCI bridge and endpoint device which + * is attached to a bus with iommu enabled. + */ + object_child_foreach_recursive(object_get_root(), + dmar_host_bridges, scope_blob); =20 assert(iommu); if (x86_iommu_ir_supported(iommu)) { @@ -2054,8 +2113,9 @@ build_dmar_q35(GArray *table_data, BIOSLinker *linker= , const char *oem_id, /* DMAR Remapping Hardware Unit Definition structure */ drhd =3D acpi_data_push(table_data, sizeof(*drhd) + ioapic_scope_size); drhd->type =3D cpu_to_le16(ACPI_DMAR_TYPE_HARDWARE_UNIT); - drhd->length =3D cpu_to_le16(sizeof(*drhd) + ioapic_scope_size); - drhd->flags =3D ACPI_DMAR_INCLUDE_PCI_ALL; + drhd->length =3D + cpu_to_le16(sizeof(*drhd) + ioapic_scope_size + scope_blob->len); + drhd->flags =3D 0; /* Don't include all pci device */ drhd->pci_segment =3D cpu_to_le16(0); drhd->address =3D cpu_to_le64(Q35_HOST_BRIDGE_IOMMU_ADDR); =20 @@ -2069,6 +2129,10 @@ build_dmar_q35(GArray *table_data, BIOSLinker *linke= r, const char *oem_id, scope->path[0].device =3D PCI_SLOT(Q35_PSEUDO_DEVFN_IOAPIC); scope->path[0].function =3D PCI_FUNC(Q35_PSEUDO_DEVFN_IOAPIC); =20 + /* Add scope found above */ + g_array_append_vals(table_data, scope_blob->data, scope_blob->len); + g_array_free(scope_blob, true); + if (iommu->dt_supported) { atsr =3D acpi_data_push(table_data, sizeof(*atsr)); atsr->type =3D cpu_to_le16(ACPI_DMAR_TYPE_ATSR); --=20 MST From nobody Sat Feb 7 06:45:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626214852275641.4814258860555; Tue, 13 Jul 2021 15:20:52 -0700 (PDT) Received: from localhost ([::1]:37610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3Qlj-0003nP-Tn for importer@patchew.org; Tue, 13 Jul 2021 18:20:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qce-0000Rm-T5 for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53510) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qcc-0008N5-0o for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:24 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-422-iXcQ75oEPsK4SEG411b2tA-1; Tue, 13 Jul 2021 18:11:19 -0400 Received: by mail-wr1-f72.google.com with SMTP id d9-20020adffbc90000b029011a3b249b10so334804wrs.3 for ; Tue, 13 Jul 2021 15:11:19 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id o11sm263555wmq.1.2021.07.13.15.11.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:11:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214281; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=flEK484QxMT1aHuKxIzbr2uWeLGle3LeEcxZhYEt/9E=; b=aCil7zAxXxtjxc8XzwtgeWyPXHqU2lQUAyQgDO6gnG8ZE2b2FXcm2Kx++GUhzNOpcJaRJN GYvVCbqs0MF4sL6qZDcnpjS4p8yS43cfG6nH96yDTX3O717FPXaXiVlfgWrRPRd8xxu23g BxnLvsi7y1ELN81ydP3wS/Q5uIJKIhw= X-MC-Unique: iXcQ75oEPsK4SEG411b2tA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=flEK484QxMT1aHuKxIzbr2uWeLGle3LeEcxZhYEt/9E=; b=jyIOPRe+wVElQma/Wk2mz2cNblD3rfXSheto6CnhxXevgqNpQlzjODNUzLBmeUa3y+ OGdr5gkB1g8QCySYEC6nWfR35lLLwfQhP2fBELFvamVXlXsC4rYyR+5O1yQ8Wb5Z0WuQ d9p7ZuvCEikqnTloAmxUS0WJIIPT2FDVQS6ussO9xgtbMgMjkP8EXLG8ogjbedXRTCRH gmTW7axD92rXT2Cr4Ro2Vry2SS2rH/H7vSwmtsnAV0rByNqmNft4gM5I1Jv5wj7FxAKU c3cL7BEjEarHxeMx9bSoTJOA7m5H1lR1OQcSLMBfscf6ViXzanqvXYSldRBXYxTv/lLN IB7w== X-Gm-Message-State: AOAM532h4sJa/D2/91Svl0RiVhlvBwG4mWnukKmIGMPoeZLczjhutzbp bddvMcspEuJE85jUNWYY4DyTsALrRZULQaFZ9zz98Q5cwrv9lygyy/eT5VwCxmsg37sKxthCNxK aeU579DooI01Ke1ps6TdSgvF2vBGPc8WzB8PCdhtFJOQz2Zz+eqVffZBhX807 X-Received: by 2002:a05:6000:10c3:: with SMTP id b3mr8497278wrx.271.1626214278480; Tue, 13 Jul 2021 15:11:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLlEFDx1orgfBLk5oh4WlQ45ddz/PCP/CySmd1a13+CuF562YCIERHuyPL0/uwK/Wh1enqtA== X-Received: by 2002:a05:6000:10c3:: with SMTP id b3mr8497261wrx.271.1626214278346; Tue, 13 Jul 2021 15:11:18 -0700 (PDT) Date: Tue, 13 Jul 2021 18:11:15 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 21/23] hw/i386/acpi-build: Add IVRS support to bypass iommu Message-ID: <20210713220946.212562-22-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Xingang Wang , Richard Henderson , Igor Mammedov , Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626214853224100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xingang Wang Check bypass_iommu to exclude the devices which will bypass iommu. Signed-off-by: Xingang Wang Message-Id: <1625748919-52456-9-git-send-email-wangxingang5@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/acpi-build.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 7efc6285ac..17836149fe 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2263,7 +2263,7 @@ ivrs_host_bridges(Object *obj, void *opaque) if (object_dynamic_cast(obj, TYPE_PCI_HOST_BRIDGE)) { PCIBus *bus =3D PCI_HOST_BRIDGE(obj)->bus; =20 - if (bus) { + if (bus && !pci_bus_bypass_iommu(bus)) { pci_for_each_device(bus, pci_bus_num(bus), insert_ivhd, ivhd_b= lob); } } --=20 MST From nobody Sat Feb 7 06:45:13 2026 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=1626215178; cv=none; d=zohomail.com; s=zohoarc; b=Q9D85imCKf270uFATB1htkZVzXbupNIFAnf93thaM0orX7i8DCguK0QkxaOXEWA8hLD+EtY+QX2h9MGBHBV7Df4iDThG1l+c+ayNcrrxzd7PNEQsAMpa3YMuDdetfB9B1GuY7NGtaGfuvW7GnLpEIDKubaRgrTj/i/Y1qvqTtG0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626215178; h=Content-Type:Cc: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=5HVhx8nlAexWU/TA8sFPnLNT9sR3fwWdWFVm7BbK6mM=; b=oBF2WX7HbF9b2PDUQ1YQhACNlYIGBwEHo9FVya3iDWfDCwrANKhmLuT7EPZHnFTtakCWct7UUbv+/sfKKW4ZjyhYawxyDSfEKEdTI1v3dbzGMgGJvuNjxfLOuVf4i/j0aFjs/uXay843cuMaQWz4+X8exQ/+pwLMT0H1tmYdNhM= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626215178171678.8783244514167; Tue, 13 Jul 2021 15:26:18 -0700 (PDT) Received: from localhost ([::1]:56004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3Qr3-0007lJ-5b for importer@patchew.org; Tue, 13 Jul 2021 18:26:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55402) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qch-0000Yq-Ij for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27065) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qcf-0008PE-DM for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:27 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-590-FMX6MJFMN8uBU-ZnTrIGuA-1; Tue, 13 Jul 2021 18:11:23 -0400 Received: by mail-wm1-f71.google.com with SMTP id p3-20020a05600c3583b02901f55d71e34aso153281wmq.4 for ; Tue, 13 Jul 2021 15:11:22 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id x8sm104990wrt.93.2021.07.13.15.11.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214284; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5HVhx8nlAexWU/TA8sFPnLNT9sR3fwWdWFVm7BbK6mM=; b=ZNnL9AhdGTLubtPW68s3XiWwT5/koISz4HNZURLbcFoTKqqV+yVBINbRelU4MF9yUzBgyh Fj5dTDdbhhiZaCBePLP7MNkkhGp+A1XCDnEdbiTF9JGlgSNxVHuZtOXdyXWWTgpIX91xoM gZVbVUig4NtROP0uJJydgMYawS5zvUE= X-MC-Unique: FMX6MJFMN8uBU-ZnTrIGuA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=5HVhx8nlAexWU/TA8sFPnLNT9sR3fwWdWFVm7BbK6mM=; b=O5wAbfB5yn+HbkhU567NIqV/iVFFTtXaKm9NZQiiq8W7SS17PQZDYUfX8DTFvMxIZm u1gbx8w6wkzlTBqUMMAuetga8pgnrKHYTC8Rcy6+I7TZwxhIjl+ayP1XUCunmqdc7CKa R7adWUZIZEWSnAi/BN1OYx+BCBKhNDAvb7ERIMCpX/DNFv+eIDAhP+xHNWE+kVY3dy6E YWXPF9jelVBRh2h+iaGWUC4whC3XYosEqCqlM9wgdQl6VoOdIwUFw5mhffqUSbpjkazL RQQ5pQB6EO+v6nOeIpNOBipTaEQnYlPrgkB4StL5jIUzs9tqjm8eUT2T7iuMXStm5NgK JcWA== X-Gm-Message-State: AOAM5336gr0wL+2WKyiA8Uz48rnnTsXBH/Cv9bz2z5QFH0LtwGtKN6Dh tFMjtDcdsyaLxCAtoeSTw99NlDByzNDtpPrlcq0K9W7p8cP87sw6muDyOW25HKCEwsgdbc/tpRe vvP89GLcRwAEGEWHwuXzhsonQ9cF0DZO9biJcQHxktlIf0NcUNMD7O0pMi+Gt X-Received: by 2002:a05:600c:1c93:: with SMTP id k19mr7517912wms.125.1626214281620; Tue, 13 Jul 2021 15:11:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7cjlm/uoF7doU3bNjhoDS45J0pOn6TNp6F12NAN0MmMIewzksOL+RpKB9VeolC3XU3AFr9w== X-Received: by 2002:a05:600c:1c93:: with SMTP id k19mr7517875wms.125.1626214281254; Tue, 13 Jul 2021 15:11:21 -0700 (PDT) Date: Tue, 13 Jul 2021 18:11:18 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 22/23] docs: Add documentation for iommu bypass Message-ID: <20210713220946.212562-23-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Xingang Wang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1626215180262100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xingang Wang Signed-off-by: Xingang Wang Message-Id: <1625748919-52456-10-git-send-email-wangxingang5@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- docs/bypass-iommu.txt | 89 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 docs/bypass-iommu.txt diff --git a/docs/bypass-iommu.txt b/docs/bypass-iommu.txt new file mode 100644 index 0000000000..e6677bddd3 --- /dev/null +++ b/docs/bypass-iommu.txt @@ -0,0 +1,89 @@ +BYPASS IOMMU PROPERTY +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Description +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Traditionally, there is a global switch to enable/disable vIOMMU. All +devices in the system can only support go through vIOMMU or not, which +is not flexible. We introduce this bypass iommu property to support +coexist of devices go through vIOMMU and devices not. This is useful to +passthrough devices with no-iommu mode and devices go through vIOMMU in +the same virtual machine. + +PCI host bridges have a bypass_iommu property. This property is used to +determine whether the devices attached on the PCI host bridge will bypass +virtual iommu. The bypass_iommu property is valid only when there is a +virtual iommu in the system, it is implemented to allow some devices to +bypass vIOMMU. When bypass_iommu property is not set for a host bridge, +the attached devices will go through vIOMMU by default. + +Usage +=3D=3D=3D=3D=3D +The bypass iommu feature support PXB host bridge and default main host +bridge, we add a bypass_iommu property for PXB and default_bus_bypass_iommu +for machine. Note that default_bus_bypass_iommu is available only when +the 'q35' machine type on x86 architecture and the 'virt' machine type +on AArch64. Other machine types do not support bypass iommu for default +root bus. + +1. The following is the bypass iommu options: + (1) PCI expander bridge + qemu -device pxb-pcie,bus_nr=3D0x10,addr=3D0x1,bypass_iommu=3Dtrue + (2) Arm default host bridge + qemu -machine virt,iommu=3Dsmmuv3,default_bus_bypass_iommu=3Dtrue + (3) X86 default root bus bypass iommu: + qemu -machine q35,default_bus_bypass_iommu=3Dtrue + +2. Here is the detailed qemu command line for 'virt' machine with PXB on +AArch64: + +qemu-system-aarch64 \ + -machine virt,kernel_irqchip=3Don,iommu=3Dsmmuv3,default_bus_bypass_iommu= =3Dtrue \ + -device pxb-pcie,bus_nr=3D0x10,id=3Dpci.10,bus=3Dpcie.0,addr=3D0x3.0x1 \ + -device pxb-pcie,bus_nr=3D0x20,id=3Dpci.20,bus=3Dpcie.0,addr=3D0x3.0x2,by= pass_iommu=3Dtrue \ + +And we got: + - a default host bridge which bypass SMMUv3 + - a pxb host bridge which go through SMMUv3 + - a pxb host bridge which bypass SMMUv3 + +3. Here is the detailed qemu command line for 'q35' machine with PXB on +x86 architecture: + +qemu-system-x86_64 \ + -machine q35,accel=3Dkvm,default_bus_bypass_iommu=3Dtrue \ + -device pxb-pcie,bus_nr=3D0x10,id=3Dpci.10,bus=3Dpcie.0,addr=3D0x3 \ + -device pxb-pcie,bus_nr=3D0x20,id=3Dpci.20,bus=3Dpcie.0,addr=3D0x4,bypass= _iommu=3Dtrue \ + -device intel-iommu \ + +And we got: + - a default host bridge which bypass iommu + - a pxb host bridge which go through iommu + - a pxb host bridge which bypass iommu + +Limitations +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +There might be potential security risk when devices bypass iommu, because +devices might send malicious dma request to virtual machine if there is no +iommu isolation. So it would be necessary to only bypass iommu for trusted +device. + +Implementation +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +The bypass iommu feature includes: + - Address space + Add bypass iommu property check of PCI Host and do not get iommu address + space for devices bypass iommu. + - Arm SMMUv3 support + We traverse all PCI root bus and get bus number ranges, then build expl= icit + RID mapping for devices which do not bypass iommu. + - X86 IOMMU support + To support Intel iommu, we traverse all PCI host bridge and get informa= tion + of devices which do not bypass iommu, then fill the DMAR drhd struct wi= th + explicit device scope info. To support AMD iommu, add check of bypass i= ommu + when traverse the PCI hsot bridge. + - Machine and PXB options + We add bypass iommu options in machine option for default root bus, and= add + option for PXB also. Note that the default value of bypass iommu is fal= se, + so that the devices will by default go through iommu if there exist one. + --=20 MST From nobody Sat Feb 7 06:45:13 2026 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=1626215017; cv=none; d=zohomail.com; s=zohoarc; b=DfBw3zfSHFOYyqZBSzonYPbSnGorBqCk1m+ktOMhFXYmTdVQhRHEbcBzASGtHEM1dvwxMtv3epqI2K4lP5UsUgKIPJLppz8uFx+dejlj13nrp1DR5CvI9HjPO+L0PfwLJyTKgaekgT4GuPk/7jMJrKNvDprKObD4oKcr97hDWac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626215017; h=Content-Type:Cc: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=+Y7ACOxj8SZNzmvjevV0tlJBqxfRYd9WxWuOxlZmTHg=; b=bXaltqQYv0in7ycbuF/N96NYtDr8HIeKtHe8CJITNe5zcBVJkWvKK3qg0oDDd2ehtSWDbcc1YUgelbAcYaPup81CYv1tMQ91umvfkrOV/FaE4/1s0vlRv+qYpBfXsTtxBro5vaQ12GrOTZKLPb7TnRsbqqbsvmcVe9PHqbjbIZg= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626215017956432.0219483733082; Tue, 13 Jul 2021 15:23:37 -0700 (PDT) Received: from localhost ([::1]:46166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3QoS-00019n-QZ for importer@patchew.org; Tue, 13 Jul 2021 18:23:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55414) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qcj-0000eY-Vf for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42407) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Qci-0008Qf-E4 for qemu-devel@nongnu.org; Tue, 13 Jul 2021 18:11:29 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-439-GYQMA7quMTm4-K6EI9l0kw-1; Tue, 13 Jul 2021 18:11:26 -0400 Received: by mail-wr1-f72.google.com with SMTP id z6-20020a5d4c860000b029013a10564614so317621wrs.15 for ; Tue, 13 Jul 2021 15:11:26 -0700 (PDT) Received: from redhat.com ([2.55.15.23]) by smtp.gmail.com with ESMTPSA id e15sm133588wrp.29.2021.07.13.15.11.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 15:11:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626214287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+Y7ACOxj8SZNzmvjevV0tlJBqxfRYd9WxWuOxlZmTHg=; b=AlU2k4SR8KxlYAfjw/PcDWaSvsZp31xXajDLTrHGOc2KuCQyl+B5u01hVdLZcMgXLDAYpX WgLN8IjWweixA/poFiW44+5WdwsZe3slUahLYZi3H6Zl68qwOJk2WSzb2FDlSt6xwvUWlJ NQ4yj+EdJJZacMKpllnoKpBhBWMUtdE= X-MC-Unique: GYQMA7quMTm4-K6EI9l0kw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+Y7ACOxj8SZNzmvjevV0tlJBqxfRYd9WxWuOxlZmTHg=; b=FNt0i8j39rY7AG+IAWUCtUi0blF+DI+M6LyhbN+5Ni5JgFyHd+bDJCj1IUuq3krqn1 Ob7F7Hupnix6n/ujO0Lc51gNN/c9XJA/mA99Lpj88lTxuOxAYLCouSakI3S3SFDLtRsH mFi0fXVGSXXhgzGMDjZk3MTK9URpvBP29Fk3ihI3HwqJXoXMUVwb4OWnDUhWQ1y/+iR/ UUAt8iGdYURfDMf2f48BrmU8q8irLcQfGmiHvrfjgeqv1C7PZWIFrAL6RGsusd8jxcFF DWSZ4vD/I1nyn3qL19am1eVxtY2n8hdv3Oa9xYVrOniH4R8f4g99d/N/aV4UA8KrbO4T 7vbA== X-Gm-Message-State: AOAM532xf4bHMudBMu5q5IQyDq6PNvLHkc+b1uNxLZF5txhCZPxCmxSh SZ3APvF+GnrugO+Lx2PB0mfYkQhNipPPuXmBduaNGti7nZQ8Um8xbpidLuJd5E2sJyHXyrGkLZF 4Se3isoT/xsRN1+1qCELq3eZ7p77eBgggbWkWwbF3s5KEK1rnVUDK7UipTwm0 X-Received: by 2002:a05:600c:4105:: with SMTP id j5mr7621324wmi.49.1626214284898; Tue, 13 Jul 2021 15:11:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeG0J9nQ1pqKYdzy8y2uoxiIn1c7cOEEoSpwg65ujK2RIRe7CXwpMrOP7iWD96dmLATnlNcg== X-Received: by 2002:a05:600c:4105:: with SMTP id j5mr7621300wmi.49.1626214284694; Tue, 13 Jul 2021 15:11:24 -0700 (PDT) Date: Tue, 13 Jul 2021 18:11:21 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 23/23] vhost-vsock: SOCK_SEQPACKET feature bit support Message-ID: <20210713220946.212562-24-mst@redhat.com> References: <20210713220946.212562-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210713220946.212562-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Cc: Peter Maydell , Arseny Krasnov , Stefano Garzarella Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1626215018974100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arseny Krasnov This adds processing of VIRTIO_VSOCK_F_SEQPACKET features bit. Guest negotiates it with vhost, thus both will know that SOCK_SEQPACKET supported by peer. Signed-off-by: Arseny Krasnov Message-Id: <20210622144747.2949134-1-arseny.krasnov@kaspersky.com> Reviewed-by: Stefano Garzarella Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-vsock.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c index 777cafe70d..1b1a5c70ed 100644 --- a/hw/virtio/vhost-vsock.c +++ b/hw/virtio/vhost-vsock.c @@ -21,6 +21,11 @@ #include "hw/virtio/vhost-vsock.h" #include "monitor/monitor.h" =20 +const int feature_bits[] =3D { + VIRTIO_VSOCK_F_SEQPACKET, + VHOST_INVALID_FEATURE_BIT +}; + static void vhost_vsock_get_config(VirtIODevice *vdev, uint8_t *config) { VHostVSock *vsock =3D VHOST_VSOCK(vdev); @@ -108,8 +113,11 @@ static uint64_t vhost_vsock_get_features(VirtIODevice = *vdev, uint64_t requested_features, Error **errp) { - /* No feature bits used yet */ - return requested_features; + VHostVSockCommon *vvc =3D VHOST_VSOCK_COMMON(vdev); + + virtio_add_feature(&requested_features, VIRTIO_VSOCK_F_SEQPACKET); + return vhost_get_features(&vvc->vhost_dev, feature_bits, + requested_features); } =20 static const VMStateDescription vmstate_virtio_vhost_vsock =3D { --=20 MST