From patchwork Sun May 22 10:21:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Kiarie X-Patchwork-Id: 9130899 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 43B6E60761 for ; Sun, 22 May 2016 10:27:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E9BD28192 for ; Sun, 22 May 2016 10:27:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62CB4281A7; Sun, 22 May 2016 10:27:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C4CB228192 for ; Sun, 22 May 2016 10:27:53 +0000 (UTC) Received: from localhost ([::1]:42688 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4Qbw-0005OQ-6H for patchwork-qemu-devel@patchwork.kernel.org; Sun, 22 May 2016 06:27:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34936) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4QWx-0001Db-Rx for qemu-devel@nongnu.org; Sun, 22 May 2016 06:22:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b4QWr-0000ZQ-3S for qemu-devel@nongnu.org; Sun, 22 May 2016 06:22:38 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33784) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4QWq-0000ZL-MZ for qemu-devel@nongnu.org; Sun, 22 May 2016 06:22:37 -0400 Received: by mail-wm0-x242.google.com with SMTP id 67so7539051wmg.0 for ; Sun, 22 May 2016 03:22:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0qdsgs5lyl/w582SwYzA+HouFTRozpEYvuU6v0azkhU=; b=J0cKZ6j2Z84sVabMo4M93wTUL/iMAQ7nGXQMZDPT8OcZPqZadRxwJ/CfBAd6iOuizJ 6BBmd3l8USL/xLMmYecJPViUxj+mqBT3kmXC+HLDN7/YbohqsNujRgds3S6yP9u5lbYD LMyMhime1xDS/0B5UDo+UcaQ6Ekwtwq0KUzd1yw7ztdNDR/gJb/yxF2RLtG2FxniigHD O651KDwSuQDZi3Ol/q10SrvvUF1MsLKTpT21DQkb77kCbxJzdeUl2tYBkTFZwW9SyfQf UPfRRS/WPmi+loroKWbu3Y1aQKrSLBu4P6mJLf8QbMQg0HNZcVDK2lUvmUGueUYZ7UsP lHMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0qdsgs5lyl/w582SwYzA+HouFTRozpEYvuU6v0azkhU=; b=b53ygmzt/+qF51Hj+IEWaoYIichwKnGNFEoh37AVNv//EjX28sx2MizMmq3OJlGd7S sqqpnwz6mxeALAk1ZtA4bJztbQpagmtDda9EdBDMoCTh6x48VmZgHXZ1Va2siz74ervR fEralCj9GpopmPu5X4Qc7BROYRQOv6ZIcxPiDF/gyxgpsQMPhpHeD1tXQd0NztiKLSKl oY1CzlgjiiW1p2FGdpgSo23nP4viGNsrMPfTKLgQB5TW1MwvEx1em7OsKQHjASPgDNvp 45SUi9i+jSgb+Io2yC1TbuPTvdA3qVkGYcRRxC1cguyFBqw2PZELgp0nxga6+Ok+2ZhW YiCg== X-Gm-Message-State: AOPr4FVZoCfEoiZIfG1nQVd7sRglSkweRnQl2Uzj1ZsTTKBCzYPZ1biLgW0A/TqDdvNdAw== X-Received: by 10.28.165.216 with SMTP id o207mr11152942wme.31.1463912556091; Sun, 22 May 2016 03:22:36 -0700 (PDT) Received: from debian.flybox.orange ([154.122.6.169]) by smtp.googlemail.com with ESMTPSA id u4sm29189515wjz.4.2016.05.22.03.22.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 May 2016 03:22:35 -0700 (PDT) From: David Kiarie To: qemu-devel@nongnu.org Date: Sun, 22 May 2016 13:21:53 +0300 Message-Id: <1463912514-12658-4-git-send-email-davidkiarie4@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1463912514-12658-1-git-send-email-davidkiarie4@gmail.com> References: <1463912514-12658-1-git-send-email-davidkiarie4@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [V11 3/4] hw/core: provision for overriding emulated IOMMU X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, peterx@redhat.com, valentine.sinitsyn@gmail.com, jan.kiszka@web.de, marcel@redhat.com, David Kiarie Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Added an enum, subject to review, to machine properties which it used to override iommu emulated from Intel to AMD. Signed-off-by: David Kiarie --- hw/core/machine.c | 29 ++++++++++++++++++++++++++--- include/hw/boards.h | 1 + include/hw/i386/intel_iommu.h | 1 + qemu-options.hx | 7 +++++-- util/qemu-config.c | 8 ++++++-- 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 6dbbc85..fe44e25 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -15,6 +15,8 @@ #include "qapi/error.h" #include "qapi-visit.h" #include "qapi/visitor.h" +#include "hw/i386/amd_iommu.h" +#include "hw/i386/intel_iommu.h" #include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "qemu/error-report.h" @@ -297,9 +299,26 @@ static void machine_set_iommu(Object *obj, bool value, Error **errp) { MachineState *ms = MACHINE(obj); + ms->iommu_type = TYPE_INTEL; ms->iommu = value; } +static void machine_set_iommu_override(Object *obj, const char *value, + Error **errp) +{ + MachineState *ms = MACHINE(obj); + + /* ensure a valid iommu type */ + if (g_strcmp0(value, AMD_IOMMU_STR) == 0) { + ms->iommu_type = TYPE_AMD; + } else if (g_strcmp0(value, INTEL_IOMMU_STR) == 0) { + ms->iommu_type = TYPE_INTEL; + } else { + error_setg(errp, "Invalid IOMMU type %s", value); + return; + } +} + static void machine_set_suppress_vmdesc(Object *obj, bool value, Error **errp) { MachineState *ms = MACHINE(obj); @@ -473,10 +492,14 @@ static void machine_initfn(Object *obj) "Firmware image", NULL); object_property_add_bool(obj, "iommu", - machine_get_iommu, - machine_set_iommu, NULL); + machine_get_iommu, machine_set_iommu, NULL); object_property_set_description(obj, "iommu", - "Set on/off to enable/disable Intel IOMMU (VT-d)", + "Set on to enable IOMMU emulation", + NULL); + object_property_add_str(obj, "x-iommu-type", + NULL, machine_set_iommu_override, NULL); + object_property_set_description(obj, "x-iommu-type", + "Set on to override emulated IOMMU to AMD IOMMU", NULL); object_property_add_bool(obj, "suppress-vmdesc", machine_get_suppress_vmdesc, diff --git a/include/hw/boards.h b/include/hw/boards.h index dbe6745..5b7eeda 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -158,6 +158,7 @@ struct MachineState { bool igd_gfx_passthru; char *firmware; bool iommu; + IommuType iommu_type; bool suppress_vmdesc; bool enforce_config_section; diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index b024ffa..539530c 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -27,6 +27,7 @@ #define TYPE_INTEL_IOMMU_DEVICE "intel-iommu" #define INTEL_IOMMU_DEVICE(obj) \ OBJECT_CHECK(IntelIOMMUState, (obj), TYPE_INTEL_IOMMU_DEVICE) +#define INTEL_IOMMU_STR "intel" /* DMAR Hardware Unit Definition address (IOMMU unit) */ #define Q35_HOST_BRIDGE_IOMMU_ADDR 0xfed90000ULL diff --git a/qemu-options.hx b/qemu-options.hx index 6106520..81217d3 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -38,7 +38,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " kvm_shadow_mem=size of KVM shadow MMU\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n" - " iommu=on|off controls emulated Intel IOMMU (VT-d) support (default=off)\n" + " iommu=on|off controls emulated IOMMU support(default: off)\n" + " x-iommu-type=amd|intel overrides emulated IOMMU to AMD IOMMU (default: intel)\n" " igd-passthru=on|off controls IGD GFX passthrough support (default=off)\n" " aes-key-wrap=on|off controls support for AES key wrapping (default=on)\n" " dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n" @@ -74,7 +75,9 @@ Enables or disables memory merge support. This feature, when supported by the host, de-duplicates identical memory pages among VMs instances (enabled by default). @item iommu=on|off -Enables or disables emulated Intel IOMMU (VT-d) support. The default is off. +Enables and disables IOMMU emulation. The default is off. +@item x-iommu-type=on|off +Overrides emulated IOMMU from AMD IOMMU. By default Intel IOMMU is emulated. @item aes-key-wrap=on|off Enables or disables AES key wrapping support on s390-ccw hosts. This feature controls whether AES wrapping keys will be created to allow diff --git a/util/qemu-config.c b/util/qemu-config.c index fb97307..8886abf 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -213,8 +213,12 @@ static QemuOptsList machine_opts = { .help = "firmware image", },{ .name = "iommu", - .type = QEMU_OPT_BOOL, - .help = "Set on/off to enable/disable Intel IOMMU (VT-d)", + .type = QEMU_OPT_BOOL, + .help = "Set on/off to enable iommu", + },{ + .name = "x-iommu-type", + .type = QEMU_OPT_STRING, + .help = "Overrides emulated IOMMU from Intel to AMD", },{ .name = "suppress-vmdesc", .type = QEMU_OPT_BOOL,