From nobody Wed Nov 12 05:27:49 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 ARC-Seal: i=1; a=rsa-sha256; t=1568620903; cv=none; d=zoho.com; s=zohoarc; b=PeHxW6/p1mzGwqT/dERzTeKcbdkqh2vSr4TCVDlp4Yc0IkN/XrYrK2hwEjKYQGw6anBoOoHMwOZhWN6tbbipnkM3BOEUfsabeML0lGwEV63icG3/1LeWsqo9ubosL7/TYS+KnQupfdwH8rWv3sZPfppm2YcWQu37zu9RWjakA5A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568620903; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=BjH2TzMvzqwAMOzIz/+i0NSNmxHIzxUqaNnq5C+7JfE=; b=NzoQhi0HfFM+zXsz7dt6YccCYnp3Q4pLaaT67btE9eUrzvaGR1GxNpou6rlpe6paCE+z3ITZ9PbG9Uj8Who1KG0OSx1Pv6DwtMuQaxtmWY8LvZN492A9hFBA517e6/VLVzgo/FHfOER64NxjV1EJgnjXpkHRUxNxBEm/PPH9e54= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568620903153801.8511919837391; Mon, 16 Sep 2019 01:01:43 -0700 (PDT) Received: from localhost ([::1]:59692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9lx3-0007Vz-4v for importer@patchew.org; Mon, 16 Sep 2019 04:01:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54429) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9luW-0005t5-Kx for qemu-devel@nongnu.org; Mon, 16 Sep 2019 03:59:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i9luV-00067h-6b for qemu-devel@nongnu.org; Mon, 16 Sep 2019 03:59:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54990) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i9luU-00067J-Th for qemu-devel@nongnu.org; Mon, 16 Sep 2019 03:58:59 -0400 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 234A15859E for ; Mon, 16 Sep 2019 07:58:58 +0000 (UTC) Received: by mail-pl1-f200.google.com with SMTP id w5so12393806pll.0 for ; Mon, 16 Sep 2019 00:58:58 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id p20sm50321443pgi.81.2019.09.16.00.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 00:58:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EXTPHZvxdYPl0NvqchbK5dciGXGNCV49fqEARsUfqC4=; b=KJ6bYIo9K7Jyw2r5AgWmxP8UDxHrPOOaLf2zbkMzpfPUuVmhq4Kqe0K9b1RXdZExwJ LcRhvzZjv0KUMk4G7Q3XWqXqjxWIY5YFa/HdUDxleVYzKLL22Cwq725A+7Q1y3Z52dDR SuuIeAADW9aCB1GyvZIeHOXQkRjJ3bfAMhXGsW1H8SrOW/38wYVWdy/PcP6iEJTj4ZXn uWfcry9Wk38sw240BDvJsp/rbECvlq4Jv4YpQcHhJppmOu8lbIFUXcFY1jHb6Bnu21gp mYJZbsCvAXV7BvizRA5bVYMlVbagfGkUET0OZ0fFjT2/iN9bk43piZrbL4r122xfUYqM K5Mg== X-Gm-Message-State: APjAAAUSGX5u/9aq1t7dh/XJLgf2kActiNU0A1sfgRN9ey6F9DK84GdC 9bNfkqvntZ9rAMVM97hD/Cy66VAslu6NqvJtHCdn+BmXPAWc7Sy80Y4FDgSqJOJeKgZVq9DUfkB Iw7ecw7Z1YQwONp4= X-Received: by 2002:a17:90a:cd01:: with SMTP id d1mr9538492pju.99.1568620737057; Mon, 16 Sep 2019 00:58:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJBjDbjGMgEAffq5IacvFLJeamX9sicfwtcV2al0NAyeiwKznCCb1Zq7CEJkTJnl6h5xkN/A== X-Received: by 2002:a17:90a:cd01:: with SMTP id d1mr9538472pju.99.1568620736844; Mon, 16 Sep 2019 00:58:56 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 16 Sep 2019 15:58:36 +0800 Message-Id: <20190916075839.390-2-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916075839.390-1-peterx@redhat.com> References: <20190916075839.390-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/4] intel_iommu: Sanity check vfio-pci config on machine init done 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S. Tsirkin" , Jason Wang , Alex Williamson , peterx@redhat.com, Bandan Das , Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This check was previously only happened when the IOMMU is enabled in the guest. It was always too late because the enabling of IOMMU normally only happens during the boot of guest OS. It means that we can bail out and exit directly during the guest OS boots if the configuration of devices are not supported. Or, if the guest didn't enable vIOMMU at all, then the user can use the guest normally but as long as it reconfigure the guest OS to enable the vIOMMU then reboot, the user will see the panic right after the reset when the next boot starts. Let's make this failure even earlier so that we force the user to use caching-mode for vfio-pci devices when with the vIOMMU. So the user won't get surprise at least during execution of the guest, which seems a bit nicer. This will affect some user who didn't enable vIOMMU in the guest OS but was using vfio-pci and the vtd device in the past. However I hope it's not a majority because not enabling vIOMMU with the device attached is actually meaningless. We still keep the old assertion for safety so far because the hotplug path could still reach it, so far. Signed-off-by: Peter Xu --- hw/i386/intel_iommu.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 75ca6f9c70..17fc309b3d 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -64,6 +64,13 @@ static void vtd_address_space_refresh_all(IntelIOMMUState *s); static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n); =20 +static void vtd_panic_require_caching_mode(void) +{ + error_report("We need to set caching-mode=3Don for intel-iommu to enab= le " + "device assignment with IOMMU protection."); + exit(1); +} + static void vtd_define_quad(IntelIOMMUState *s, hwaddr addr, uint64_t val, uint64_t wmask, uint64_t w1cmask) { @@ -2929,9 +2936,7 @@ static void vtd_iommu_notify_flag_changed(IOMMUMemory= Region *iommu, IntelIOMMUState *s =3D vtd_as->iommu_state; =20 if (!s->caching_mode && new & IOMMU_NOTIFIER_MAP) { - error_report("We need to set caching-mode=3Don for intel-iommu to = enable " - "device assignment with IOMMU protection."); - exit(1); + vtd_panic_require_caching_mode(); } =20 /* Update per-address-space notifier flags */ @@ -3699,6 +3704,32 @@ static bool vtd_decide_config(IntelIOMMUState *s, Er= ror **errp) return true; } =20 +static int vtd_machine_done_notify_one(Object *child, void *unused) +{ + IntelIOMMUState *iommu =3D INTEL_IOMMU_DEVICE(x86_iommu_get_default()); + + /* + * We hard-coded here because vfio-pci is the only special case + * here. Let's be more elegant in the future when we can, but so + * far there seems to be no better way. + */ + if (object_dynamic_cast(child, "vfio-pci") && !iommu->caching_mode) { + vtd_panic_require_caching_mode(); + } + + return 0; +} + +static void vtd_machine_done_hook(Notifier *notifier, void *unused) +{ + object_child_foreach_recursive(object_get_root(), + vtd_machine_done_notify_one, NULL); +} + +static Notifier vtd_machine_done_notify =3D { + .notify =3D vtd_machine_done_hook, +}; + static void vtd_realize(DeviceState *dev, Error **errp) { MachineState *ms =3D MACHINE(qdev_get_machine()); @@ -3744,6 +3775,7 @@ static void vtd_realize(DeviceState *dev, Error **err= p) pci_setup_iommu(bus, vtd_host_dma_iommu, dev); /* Pseudo address space under root PCI bus. */ pcms->ioapic_as =3D vtd_host_dma_iommu(bus, s, Q35_PSEUDO_DEVFN_IOAPIC= ); + qemu_add_machine_init_done_notifier(&vtd_machine_done_notify); } =20 static void vtd_class_init(ObjectClass *klass, void *data) --=20 2.21.0 From nobody Wed Nov 12 05:27:49 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 ARC-Seal: i=1; a=rsa-sha256; t=1568620915; cv=none; d=zoho.com; s=zohoarc; b=cOEV3vCfFKLXX+WmubOnHzolNMSBJTX3QHD0xml3Oo6JbfIinHMGMCPk187afVBLW727WxVX1rbqLpQYLZXuA8yMUTkkLDdBZr3lYPYqim+3Ra3R2YZjaUfxSr31Q337guIOZCR+nZ7x6O6QGGZsx86K8U3JxlYpdNxeKmqUfIo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568620915; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=cXOmlWO8ljAa72/sH1R3UY9ZLnDnSqDcQL1NEw4IvA4=; b=a/kF4Ys7N52vBwTk+SK9dmPYWZZulyGCLCmd7v4D8Lxnj4vPsB0Rvg+/JvEznqqB2B9Vph6HPg/BxujONDIRJ217iqF5zild6bSLDa8HGOSjnj3uXt/zXlXmFm4NtkmBpgzhup8Z8yf96jFW2AWKMHwQuFMpLYQ3gpMcCptJn8w= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568620915011522.9220180936375; Mon, 16 Sep 2019 01:01:55 -0700 (PDT) Received: from localhost ([::1]:59694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9lxI-0007h7-NP for importer@patchew.org; Mon, 16 Sep 2019 04:01:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54448) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9lub-00060Z-1r for qemu-devel@nongnu.org; Mon, 16 Sep 2019 03:59:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i9luZ-0006Ae-Hw for qemu-devel@nongnu.org; Mon, 16 Sep 2019 03:59:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i9luZ-00069Q-77 for qemu-devel@nongnu.org; Mon, 16 Sep 2019 03:59:03 -0400 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6CB1F81DEC for ; Mon, 16 Sep 2019 07:59:02 +0000 (UTC) Received: by mail-pf1-f200.google.com with SMTP id u12so2310357pfn.19 for ; Mon, 16 Sep 2019 00:59:02 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id p20sm50321443pgi.81.2019.09.16.00.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 00:59:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LChkR9HngsP+fjSd5r3ZpOSU+lcRIkGLqSV6q1LGR9A=; b=Mfp+UoPww7FzzHgraZhTMyFLo8fDWEeVsH4bSGuF4HeiOT8Tfp6e+WTUchoucCtxcg 1e+6zr74/YWOnogOiKe+UVGizg1qSk/al56Mkd2IIsQI5r7vFccu9tfqY2FalZu8LqSC vPMrbf8aENpriHr0xqJq9CIp3HdORbkhbCZqf3cqXIScjDmmooVFJGy3f1cjSHUvKHxx SzoCsobx0EbmVz22KHX0u89xOCSxfOp659CjOpqEiY3ukuGXU2hb0xWjwJi0tCjMPsC/ PoyDzQ1qexD1V4UM37xAGSDsNhpvYbpdZ5NmOHWoihOynQmOKiyarumJW24B4QPdIq+f zIYw== X-Gm-Message-State: APjAAAW326AOgCdIeaIkMlRzJotlC886WFqvDtVp5ulG+/8WBlljS/A8 n2vylBcn2i9wL2bveqleqswsWqdJ0SnhRKxCFRWAeowEbD9wosULNp5uq4wCN7f7NWzsnnUtXLW 0JV6D3mNZWt+9bAw= X-Received: by 2002:a17:902:6e17:: with SMTP id u23mr39874701plk.205.1568620741448; Mon, 16 Sep 2019 00:59:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1JYzrFh8qrWSXCcZd2TDZAUsd+4EIhgfCp+bA3ZmbnLP1poPKKdQ4NWAP2wCnmMzNrMKnzg== X-Received: by 2002:a17:902:6e17:: with SMTP id u23mr39874683plk.205.1568620741251; Mon, 16 Sep 2019 00:59:01 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 16 Sep 2019 15:58:37 +0800 Message-Id: <20190916075839.390-3-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916075839.390-1-peterx@redhat.com> References: <20190916075839.390-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/4] qdev/machine: Introduce hotplug_allowed hook 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S. Tsirkin" , Jason Wang , Alex Williamson , peterx@redhat.com, Bandan Das , Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Introduce this new per-machine hook to give any machine class a chance to do a sanity check on the to-be-hotplugged device as a sanity test. This will be used for x86 to try to detect some illegal configuration of devices, e.g., possible conflictions between vfio-pci and x86 vIOMMU. Signed-off-by: Peter Xu --- hw/core/qdev.c | 17 +++++++++++++++++ include/hw/boards.h | 9 +++++++++ include/hw/qdev-core.h | 1 + qdev-monitor.c | 7 +++++++ 4 files changed, 34 insertions(+) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 60d66c2f39..cbad6c1d55 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -237,6 +237,23 @@ HotplugHandler *qdev_get_machine_hotplug_handler(Devic= eState *dev) return NULL; } =20 +bool qdev_hotplug_allowed(DeviceState *dev, Error **errp) +{ + MachineState *machine; + MachineClass *mc; + Object *m_obj =3D qdev_get_machine(); + + if (object_dynamic_cast(m_obj, TYPE_MACHINE)) { + machine =3D MACHINE(m_obj); + mc =3D MACHINE_GET_CLASS(machine); + if (mc->hotplug_allowed) { + return mc->hotplug_allowed(machine, dev, errp); + } + } + + return true; +} + HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev) { if (dev->parent_bus) { diff --git a/include/hw/boards.h b/include/hw/boards.h index 2289536e48..be18a5c032 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -166,6 +166,13 @@ typedef struct { * The function pointer to hook different machine specific functions for * parsing "smp-opts" from QemuOpts to MachineState::CpuTopology and mo= re * machine specific topology fields, such as smp_dies for PCMachine. + * @hotplug_allowed: + * If the hook is provided, then it'll be called for each device + * hotplug to check whether the device hotplug is allowed. Return + * true to grant allowance or false to reject the hotplug. When + * false is returned, an error must be set to show the reason of + * the rejection. If the hook is not provided, all hotplug will be + * allowed. */ struct MachineClass { /*< private >*/ @@ -224,6 +231,8 @@ struct MachineClass { =20 HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev); + bool (*hotplug_allowed)(MachineState *state, DeviceState *dev, + Error **errp); CpuInstanceProperties (*cpu_index_to_instance_props)(MachineState *mac= hine, unsigned cpu_inde= x); const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine); diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index de70b7a19a..aa123f88cb 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -280,6 +280,7 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int = alias_id, int required_for_version); HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev); HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev); +bool qdev_hotplug_allowed(DeviceState *dev, Error **errp); /** * qdev_get_hotplug_handler: Get handler responsible for device wiring * diff --git a/qdev-monitor.c b/qdev-monitor.c index 8fe5c2cad2..148df9cacf 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -615,6 +615,13 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **e= rrp) /* create device */ dev =3D DEVICE(object_new(driver)); =20 + /* Check whether the hotplug is allowed by the machine */ + if (qdev_hotplug && !qdev_hotplug_allowed(dev, &err)) { + /* Error must be set in the machine hook */ + assert(err); + goto err_del_dev; + } + if (bus) { qdev_set_parent_bus(dev, bus); } else if (qdev_hotplug && !qdev_get_machine_hotplug_handler(dev)) { --=20 2.21.0 From nobody Wed Nov 12 05:27:49 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 ARC-Seal: i=1; a=rsa-sha256; t=1568620919; cv=none; d=zoho.com; s=zohoarc; b=aOfFnCuWCkG7vHa5Ydc6AIIMi8iO7ahC9+Z0f4vtBT9uxNuNbJS916kuuryAeFEP35LIXHSkeQq/yvjJZvaSlPwfyFEn7Es+y1IVNgqRVTS+5yA6IliLjaxE378SoD77YE+VkNpAsNcsBIjN7Sr3lXyy/GjlRmdiOpyfIFVXmQI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568620919; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=2pHrNtJIMVhC55v/60eL2XVobxNv31r4ZZ5aNHMaJTE=; b=QB25llqSQDmkDvVj7DMQqv2qKbs1ebiMarnGLF2mglcXcYZyLfDZ4WKSKhIwIaT/zUWA8vuLKBbo/eQLdDC8qGtwutKaO9E2C96c62KcMDS3HM0Ptwd4j+FMUD1E/WWqje407uXTjkRFHsg29sCM+uXGWd0V7ln/vYCoI/as+kg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568620919737905.2392387874146; Mon, 16 Sep 2019 01:01:59 -0700 (PDT) Received: from localhost ([::1]:59696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9lxN-0007m3-KR for importer@patchew.org; Mon, 16 Sep 2019 04:01:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54462) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9luf-00065l-Ay for qemu-devel@nongnu.org; Mon, 16 Sep 2019 03:59:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i9lue-0006DL-21 for qemu-devel@nongnu.org; Mon, 16 Sep 2019 03:59:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34430) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i9lud-0006Cv-Q3 for qemu-devel@nongnu.org; Mon, 16 Sep 2019 03:59:07 -0400 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E92F94E926 for ; Mon, 16 Sep 2019 07:59:06 +0000 (UTC) Received: by mail-pl1-f198.google.com with SMTP id y2so3861649plk.19 for ; Mon, 16 Sep 2019 00:59:06 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id p20sm50321443pgi.81.2019.09.16.00.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 00:59:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yTFkaA7FK1OtMJ5ZNEIyQVGHTHHaCs6uZL+0B9ty2Rc=; b=UL8wS7wGoTP6UqD5GcKkO9CqTeieWiTlje3ZVYFb+OptiRuzLTfwrCNFhkfbfJFIjo WfaHWdGSW0ZCnze+Sg39QdFTyj57A3q27bErHl0IzsX1iFFeSpETdaRyE0FGHSdis9pB gsbJCB6IzQ7LEUNd0rrrQpGy4Q7TMHeNx4l7yYuOwe5EO78ibc9ZiBP6OCmvhHMq4Dza +jtnTAO1svgBgdiQjqS57pAC4HLmUDiCKPJyhvboCNhhc4IhlbRW1DO2H3X5Dz7fGZhU RxYY/nxkyWy2C7Aw/Bii9gI1FxopNyAEMrpS0jMduPOnF/7bra2ly1FYtgvVoB8OYpPC uxKQ== X-Gm-Message-State: APjAAAUqpKf6xyqbi0bPx0sEwViuDSSZONMCiPmpx00gwegjbP4wAKwm HzvGu2EG+PhVm+zNlciywpZkHnvQIi0kYDICsfnCxDd9I6/n/Fk6PsY+K+vQZ/mWT8uMBuLnGoC aJzRo7VF5S5Zf7nY= X-Received: by 2002:a62:3083:: with SMTP id w125mr70558233pfw.102.1568620745921; Mon, 16 Sep 2019 00:59:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqyvVB+BB49/z3oDpVv8YcFiaZgt1auvp2Z+s4bu/1iUW9zj8mDLeKUZExmrMkLlbQMlbHhIlg== X-Received: by 2002:a62:3083:: with SMTP id w125mr70558216pfw.102.1568620745766; Mon, 16 Sep 2019 00:59:05 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 16 Sep 2019 15:58:38 +0800 Message-Id: <20190916075839.390-4-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916075839.390-1-peterx@redhat.com> References: <20190916075839.390-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 3/4] pc/q35: Disallow vfio-pci hotplug without VT-d caching mode 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S. Tsirkin" , Jason Wang , Alex Williamson , peterx@redhat.com, Bandan Das , Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Instead of bailing out when trying to hotplug a vfio-pci device with below configuration: -device intel-iommu,caching-mode=3Doff With this we can return a warning message to the user via QMP/HMP and the VM will continue to work after failing the hotplug: (qemu) device_add vfio-pci,bus=3Droot.3,host=3D05:00.0,id=3Dvfio1 Error: Device assignment is not allowed without enabling caching-mode=3Do= n for Intel IOMMU. Signed-off-by: Peter Xu --- hw/i386/pc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index bad866fe44..0a6fa6e549 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -2944,6 +2944,26 @@ static void x86_nmi(NMIState *n, int cpu_index, Erro= r **errp) } } =20 + +static bool pc_hotplug_allowed(MachineState *ms, DeviceState *dev, Error *= *errp) +{ + X86IOMMUState *iommu =3D x86_iommu_get_default(); + IntelIOMMUState *intel_iommu; + + if (iommu && + object_dynamic_cast((Object *)iommu, TYPE_INTEL_IOMMU_DEVICE) && + object_dynamic_cast((Object *)dev, "vfio-pci")) { + intel_iommu =3D INTEL_IOMMU_DEVICE(iommu); + if (!intel_iommu->caching_mode) { + error_setg(errp, "Device assignment is not allowed without " + "enabling caching-mode=3Don for Intel IOMMU."); + return false; + } + } + + return true; +} + static void pc_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); @@ -2968,6 +2988,7 @@ static void pc_machine_class_init(ObjectClass *oc, vo= id *data) pcmc->pvh_enabled =3D true; assert(!mc->get_hotplug_handler); mc->get_hotplug_handler =3D pc_get_hotplug_handler; + mc->hotplug_allowed =3D pc_hotplug_allowed; mc->cpu_index_to_instance_props =3D pc_cpu_index_to_props; mc->get_default_cpu_node_id =3D pc_get_default_cpu_node_id; mc->possible_cpu_arch_ids =3D pc_possible_cpu_arch_ids; --=20 2.21.0 From nobody Wed Nov 12 05:27:49 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 ARC-Seal: i=1; a=rsa-sha256; t=1568621137; cv=none; d=zoho.com; s=zohoarc; b=ZmuGe24DaQOckiM6lwi/7b+BNZAyvsByLnPYXgF0dRiuKswH9SgUQePkXbP6vWWZRSJhjeU1l9d6AuEHA7Xf6jS1G8Yi5Awirp20ivWOq90Yp5ALSGUiZsXTpJTUoNPq/1imfYIBwRPWWgfinssovAfc8fzigbHcAv6SmskPISg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568621137; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=Q9okMm6Rb0H1ZavHnOSQF85KyavwYDarcF3NW/AZJuc=; b=PgqJIvwAucn+CaM62Hre0tb9bHQ6X2cxPVLVJWXDtTPla0NM8UEnmhIvE1uaMe0OhlMEemK/d7/X1pdJ1ZDj39P+VRnpUc1nZo+oImkWawzsbeO/NbQBoJJiY8KTcZgSEn8Pa9cMAtqiWg4ZxFmrFzP3WFvj8GvNoyd2Rk9kxt4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568621137599853.0443914318918; Mon, 16 Sep 2019 01:05:37 -0700 (PDT) Received: from localhost ([::1]:59736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9m0u-0002eG-7v for importer@patchew.org; Mon, 16 Sep 2019 04:05:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54497) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9luj-0006B7-6n for qemu-devel@nongnu.org; Mon, 16 Sep 2019 03:59:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i9lui-0006Fn-2Y for qemu-devel@nongnu.org; Mon, 16 Sep 2019 03:59:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40060) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i9luh-0006FK-TZ for qemu-devel@nongnu.org; Mon, 16 Sep 2019 03:59:12 -0400 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 333F788306 for ; Mon, 16 Sep 2019 07:59:11 +0000 (UTC) Received: by mail-pg1-f197.google.com with SMTP id r35so9877432pgb.2 for ; Mon, 16 Sep 2019 00:59:11 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id p20sm50321443pgi.81.2019.09.16.00.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 00:59:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Sd75Sl64YfC71rpaDKMmxyQH/rUSVoFuK0rLbD5VCyU=; b=eG1AJErg9a+J1T6zZkF+aqatc/DHc0rFRHOJr2oNZcElT5AE3GvCz8GZnBDJVHDi4K gGr3SFkflbq1bcOSR0PxtulI2q1hk+lwUFQX4VjDlOH5whQlgXmFAvjc8V8WUe7wWTLG 9SZBQePEaxPOFOOHZajz2w3oejcfHdG1ynW/W0ToMaNR1fz0s4MEegFTXRyCPe4SXIXI 1ewm+4Lcxe+jxesHkx6Ne6UEwEQgf2GzH5Vg1zD+POFc9J0HNc3CPMy/apkyYYzImBb/ 2+05rVp0/n9s01YP44p/yJoWPCkxHSaLi6PhjQHaqWDSQMrp7RB2DwSZJNHMxyBGmupf QzRQ== X-Gm-Message-State: APjAAAUW6qSYFl416gu5HYtxfTIkHiWxgFj7YWgdxaK1OAhguzN5lJTX B8V+KLWG53LOOx01y4U4C9GBDtR9LYEdJMi7uJYZZfSpf68lIrZ0y0wz4gozfuEfegRKQH8zFEy plHjGeW5cGO/i1mo= X-Received: by 2002:a17:902:54f:: with SMTP id 73mr24803368plf.329.1568620750383; Mon, 16 Sep 2019 00:59:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqwrJ9IHL9ttpV32BC8XJFkXF7f+RIXyc69Umca68/zrFzxV2RxYLdPDT+DoSjr3EXx199I3+w== X-Received: by 2002:a17:902:54f:: with SMTP id 73mr24803355plf.329.1568620750214; Mon, 16 Sep 2019 00:59:10 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 16 Sep 2019 15:58:39 +0800 Message-Id: <20190916075839.390-5-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916075839.390-1-peterx@redhat.com> References: <20190916075839.390-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 4/4] intel_iommu: Remove the caching-mode check during flag change 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S. Tsirkin" , Jason Wang , Alex Williamson , peterx@redhat.com, Bandan Das , Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" That's never a good place to stop QEMU process... Since now we have both the machine done sanity check and also the hotplug handler, we can safely remove this to avoid that. Signed-off-by: Peter Xu --- hw/i386/intel_iommu.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 17fc309b3d..070816c355 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2935,10 +2935,6 @@ static void vtd_iommu_notify_flag_changed(IOMMUMemor= yRegion *iommu, VTDAddressSpace *vtd_as =3D container_of(iommu, VTDAddressSpace, iommu= ); IntelIOMMUState *s =3D vtd_as->iommu_state; =20 - if (!s->caching_mode && new & IOMMU_NOTIFIER_MAP) { - vtd_panic_require_caching_mode(); - } - /* Update per-address-space notifier flags */ vtd_as->notifier_flags =3D new; =20 --=20 2.21.0