From patchwork Tue Oct 26 18:20:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 516222 Delivered-To: patch@linaro.org Received: by 2002:ac0:c404:0:0:0:0:0 with SMTP id t4csp635738imj; Tue, 26 Oct 2021 11:44:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVlZIXZOQACaDO9UoUUZElhqpkitrt9sDgSJPts95Sl+EyYniGvrMD1Bu7UNVmg8h7EdNX X-Received: by 2002:a05:6808:1409:: with SMTP id w9mr330406oiv.59.1635273840646; Tue, 26 Oct 2021 11:44:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635273840; cv=none; d=google.com; s=arc-20160816; b=Xug2++L/bed8f2KZmVjcfKrAkgCcHzj/I1d/RuoOwT7rssTu5STklnFmuUmlKlJkRn IjeLMu0hC2iOoQ8zUfXGsuLJ1DIdDJojxxDzH933FL/8teXSQ3e7u+oKK2wZZ7CFASG5 Cdd5/uKM6AwQMBld+cnnOjs914mYZBs5JaJAf3sSN+geaiSmJEpF7jXp14GKOGQLiQOF HY/POF1Jqi4TJ6jIu8W//yQvnxy0k1GHWHD22XyY6sSOPkIC4124XGZOFBarj1OiT8dI kSk5ryJJDq9YHFb9waGr/56+XwMfMzgvi+aJf1Ow6BOTMENoi5KIq6uBMEMkzhtVjAFT zM4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=xqIyMvIPvA/nhtPgAQiuKI2im/vy4yOf0VdzA8CiiMk=; b=DhHaHTbLKWc64nnoOh26J41JSDAAYWePnrYV5JFX8SocoaPBVYkepETHXqBSAOUbzX 7C1vQBhsUJs3KKygvx6+qAdu8+XM4einqsbsKQ7wcRy3Z0gks7M3qpDCMlt279O1MLp5 06q/ixbHtZBG2BLtlTAEBI/zDoehEYdixyKBvi8gh2MhUsF2xRewE/eDZZnXZvYSyJ34 rI5bGWgI20LSS7aG8MUjIbexBbhQSA+vQB/BhqpJK5J+6hIYpdii5YL5AsSrJY/FrKe9 8+xhWbmu5ubyc6cUPj+w5zS8HRrIYHyt4+exMufnnAGFfXbaic1w3wu7VOYQmfYQVY31 hp+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oOfXajWt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d20si23420468otf.64.2021.10.26.11.44.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Oct 2021 11:44:00 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oOfXajWt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfRQW-0007Ha-00 for patch@linaro.org; Tue, 26 Oct 2021 14:44:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfR8V-0005tJ-DQ for qemu-devel@nongnu.org; Tue, 26 Oct 2021 14:25:23 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:45637) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mfR8I-0006kI-59 for qemu-devel@nongnu.org; Tue, 26 Oct 2021 14:25:22 -0400 Received: by mail-wr1-x432.google.com with SMTP id o14so3616976wra.12 for ; Tue, 26 Oct 2021 11:25:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xqIyMvIPvA/nhtPgAQiuKI2im/vy4yOf0VdzA8CiiMk=; b=oOfXajWtIbNwkJkuAyjtpIJkjFLrET2X3YqQz5kMSOtEsz/uSpnAmwc/WHu3cCQj52 mlTw6qb/64SR99mLqtMQjp5VZOcL+tLabkf9iOrkHh08PjdQfvo5sB+iRdbceO7Fz993 zGnN7ZhXqiFc8CFxNp3aV073xo72/xeE36Yw0stMmLrE739J5Rn2851n8mRCRVJajkUg RkKxJq2sw3ogBv9sxh3bOfvuPN9J7y/e+rutmzsObUDHx1WIrba1OkzFSBmvc797n2Ld liNHSRHNr2vxYMJIK189W3Fqre7NRjujArOzTklQQznFdhCL+9Fw2mOCXeNUYrTwPvUv 2fow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xqIyMvIPvA/nhtPgAQiuKI2im/vy4yOf0VdzA8CiiMk=; b=ty/YHUjNADmAt3+nMMeoI3ZE9aNQpDtOmNKool26mfYbx3sxprmSFW3+UUtkA4BHF9 L8f8mRVB9zXeytiIaoU5jSpKHVQTAm0YaNjRicAYtN2XjqZYhVgOYl/1U+vSQSZscPtt M34Tun3NtSXr0yCvTddVzbLvqoDH1WThEyLmTi2RR7yM1TDxN+eDsabAWczuuS1AQC0S dWebs4PcrUBBHO3qHHLiauJE2aptWFKKbne0gGdsooNldmYpV6fOpaBo8D15ARxVzF3Z bewx731lsiP+5jQzTe7/xE8XCTaVjAF4QGClanrVf5KJ2yIuTuqPxdQQKXtNrCbCesbG aN9Q== X-Gm-Message-State: AOAM532pq1X2ukiNDmJaNu3ymzfQYW3b+FY1y/iftxQ2nK9hcecG+Tpw /f9wSQF3r9Y9hHyUDfSSXdhCPg== X-Received: by 2002:adf:82b0:: with SMTP id 45mr5452012wrc.120.1635272708269; Tue, 26 Oct 2021 11:25:08 -0700 (PDT) Received: from localhost.localdomain (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id b19sm1275283wmj.9.2021.10.26.11.25.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 11:25:07 -0700 (PDT) From: Jean-Philippe Brucker To: mst@redhat.com, imammedo@redhat.com Subject: [PATCH v6 3/7] hw/i386/pc: Move IOMMU singleton into PCMachineState Date: Tue, 26 Oct 2021 19:20:22 +0100 Message-Id: <20211026182024.2642038-4-jean-philippe@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211026182024.2642038-1-jean-philippe@linaro.org> References: <20211026182024.2642038-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=jean-philippe@linaro.org; helo=mail-wr1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: Jean-Philippe Brucker , ehabkost@redhat.com, jasowang@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org, peterx@redhat.com, eric.auger@redhat.com, ani@anisinha.ca, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We're about to support a third vIOMMU for x86, virtio-iommu which doesn't inherit X86IOMMUState. Move the IOMMU singleton into PCMachineState, so it can be shared between all three vIOMMUs. The x86_iommu_get_default() helper is still needed by KVM and IOAPIC to fetch the default IRQ-remapping IOMMU. Since virtio-iommu doesn't support IRQ remapping, this interface doesn't need to change for the moment. We could later replace X86IOMMUState with an "IRQ remapping IOMMU" interface if necessary. Reviewed-by: Eric Auger Reviewed-by: Igor Mammedov Signed-off-by: Jean-Philippe Brucker --- include/hw/i386/pc.h | 1 + hw/i386/pc.c | 12 +++++++++++- hw/i386/x86-iommu.c | 26 ++++++++------------------ 3 files changed, 20 insertions(+), 19 deletions(-) -- 2.33.0 diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 11426e26dc..b72e5bf9d1 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -35,6 +35,7 @@ typedef struct PCMachineState { I2CBus *smbus; PFlashCFI01 *flash[2]; ISADevice *pcspk; + DeviceState *iommu; /* Configuration options: */ uint64_t max_ram_below_4g; diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 54e4c00dce..fcbf328e8d 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1330,6 +1330,15 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI) || object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI)) { pc_virtio_md_pci_pre_plug(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_X86_IOMMU_DEVICE)) { + PCMachineState *pcms = PC_MACHINE(hotplug_dev); + + if (pcms->iommu) { + error_setg(errp, "QEMU does not support multiple vIOMMUs " + "for x86 yet."); + return; + } + pcms->iommu = dev; } } @@ -1384,7 +1393,8 @@ static HotplugHandler *pc_get_hotplug_handler(MachineState *machine, if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) || object_dynamic_cast(OBJECT(dev), TYPE_CPU) || object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI) || - object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI)) { + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI) || + object_dynamic_cast(OBJECT(dev), TYPE_X86_IOMMU_DEVICE)) { return HOTPLUG_HANDLER(machine); } diff --git a/hw/i386/x86-iommu.c b/hw/i386/x86-iommu.c index dc968c7a53..01d11325a6 100644 --- a/hw/i386/x86-iommu.c +++ b/hw/i386/x86-iommu.c @@ -77,25 +77,17 @@ void x86_iommu_irq_to_msi_message(X86IOMMUIrq *irq, MSIMessage *msg_out) msg_out->data = msg.msi_data; } -/* Default X86 IOMMU device */ -static X86IOMMUState *x86_iommu_default = NULL; - -static void x86_iommu_set_default(X86IOMMUState *x86_iommu) +X86IOMMUState *x86_iommu_get_default(void) { - assert(x86_iommu); + MachineState *ms = MACHINE(qdev_get_machine()); + PCMachineState *pcms = + PC_MACHINE(object_dynamic_cast(OBJECT(ms), TYPE_PC_MACHINE)); - if (x86_iommu_default) { - error_report("QEMU does not support multiple vIOMMUs " - "for x86 yet."); - exit(1); + if (pcms && + object_dynamic_cast(OBJECT(pcms->iommu), TYPE_X86_IOMMU_DEVICE)) { + return X86_IOMMU_DEVICE(pcms->iommu); } - - x86_iommu_default = x86_iommu; -} - -X86IOMMUState *x86_iommu_get_default(void) -{ - return x86_iommu_default; + return NULL; } static void x86_iommu_realize(DeviceState *dev, Error **errp) @@ -131,8 +123,6 @@ static void x86_iommu_realize(DeviceState *dev, Error **errp) if (x86_class->realize) { x86_class->realize(dev, errp); } - - x86_iommu_set_default(X86_IOMMU_DEVICE(dev)); } static Property x86_iommu_properties[] = {