From nobody Tue Apr 16 18:43:29 2024 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=1565595990; cv=none; d=zoho.com; s=zohoarc; b=K5BO/huB1tHJtVhhlRWJLPDPZ88sKTNxGdYNa/Iur7d8hRY31xlFmZKMk4KLybYdtxtXowMtWwajU4uUIyVtjyYgbHALejuI+1cOZqLC3GHStiddmaUb77Zq34aM1EwA3VFjnIzYaQzKRSM0bX0jSEUKaoV0GxgjF3UBaVvsYcw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565595990; 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=/RddpD4U/uvkTQBHUlrj6JKlm4EFO0cmLwADivRnN0c=; b=oP1GVQQmIuB6/iNRf4xaAoqep/hCXQTrs+CLB2lfFV4mOGIj5Cas5Yx5FvRls/gp/gKjqYJUORgyhiBg/9J7n7K/ly2QCOAshUfKVnPrde+30MSM1CmH/zs5xpgZHFo9Tnnq1KveofAtbf3NxiBQ6YWTYQpZCxPwpaJBjx0q+bs= 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 1565595990220960.9567065845192; Mon, 12 Aug 2019 00:46:30 -0700 (PDT) Received: from localhost ([::1]:43503 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hx52D-0005e9-A5 for importer@patchew.org; Mon, 12 Aug 2019 03:46:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51252) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hx51R-00043f-Aq for qemu-devel@nongnu.org; Mon, 12 Aug 2019 03:45:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hx51P-0007di-Nw for qemu-devel@nongnu.org; Mon, 12 Aug 2019 03:45:41 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41942) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hx51P-0007cV-EZ for qemu-devel@nongnu.org; Mon, 12 Aug 2019 03:45:39 -0400 Received: by mail-wr1-f65.google.com with SMTP id j16so1437014wrr.8 for ; Mon, 12 Aug 2019 00:45:37 -0700 (PDT) Received: from xz-x1.redhat.com (net77-43-52-122.mclink.it. [77.43.52.122]) by smtp.gmail.com with ESMTPSA id a84sm15909450wmf.29.2019.08.12.00.45.35 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 00:45:36 -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=/RddpD4U/uvkTQBHUlrj6JKlm4EFO0cmLwADivRnN0c=; b=ZyJ3d+f+zT5fgxbQQkn4IhL3HlSW7xL8lCBddhQePTsK8bWucSvTXPGGbu4gSpzvKO pk85BAXocuffnEpWmuddPlm/lXzFO46+0qSdv5l35u8v7IYw/AEYNEeFhC+N08NZbXbm O3Em7LoI+0gBFPDYyMb5i+0diUPeX5m39xbKsGdXatK9tU/AQ3jaWLi4ns6B/Is7KJqj xaHqXupNiO/nkjHr/pE9QNEOO2He7rs88Q5MammVqIfqZRbMpq0f/UR8+X8yrhMgae/7 iZThAJ4wSwfaWp1Yjz5XXcKzryOtf0V1+0IagsqRoJ5Ehfw8dSnQxKqDpP6U8y1baByT Stzg== X-Gm-Message-State: APjAAAUXdW0qgZ71bGhgFSjPV1mxJh+rSDfq9H5Virkty8mMmMszbBiu HAGeKLmT4QqUThVRac0KzjumBhtZzRKbhw== X-Google-Smtp-Source: APXvYqxqr+2cK6s8/wrE80i/+84bisxo6p5MkWyjenzgG22xS3d3EbTL2jQMpSS3UYSKsscoc7mvMQ== X-Received: by 2002:adf:cd08:: with SMTP id w8mr2854034wrm.147.1565595936665; Mon, 12 Aug 2019 00:45:36 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 12 Aug 2019 09:45:28 +0200 Message-Id: <20190812074531.28970-2-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812074531.28970-1-peterx@redhat.com> References: <20190812074531.28970-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] [fuzzy] X-Received-From: 209.85.221.65 Subject: [Qemu-devel] [PATCH RFC 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 Reviewed-by: Eric Auger --- 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 de86f53b4e..642dd595ed 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -61,6 +61,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) { @@ -2926,9 +2933,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 */ @@ -3696,6 +3701,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()); @@ -3741,6 +3772,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 Tue Apr 16 18:43:29 2024 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=1565596045; cv=none; d=zoho.com; s=zohoarc; b=Znk2net8kXctKNAXwbnDiTf0qsqo4w5CgxvdSsxNTPKbURpW/K9/WWTuHH9yZuz2dZ23AHI6i1pF6M/zqDdlSx9u1ebRjnJ04g6zlbqNZwtlc/Tjgbkd4aWakuwUqWKK0FWQ+71pLw2D0FEt3ZBMVeQugNuS9Ao7wLRdrRU534g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565596045; 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=lTmpuaaCdK+p1SsvLRVZxUAT9brrOBbHnhL4uMZgKJs=; b=aY698f0BMPl2eQJmZv5l/L24RxJDzKKJPV1qv0DE/35kGZCJW/604TPo5CsjD1bLXNNX6dJuOFrQqV3aO82M26edl1gDsOvld6FRMqZd7b9BnPDxey2xD41IxuS4NnmpWZYwZSY9s5N4/bQDMQTZNmfKc4poK1THQNtUaE2rXPg= 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 1565596045958745.0786847778646; Mon, 12 Aug 2019 00:47:25 -0700 (PDT) Received: from localhost ([::1]:43518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hx537-0007rJ-4s for importer@patchew.org; Mon, 12 Aug 2019 03:47:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51249) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hx51R-00043e-3Y for qemu-devel@nongnu.org; Mon, 12 Aug 2019 03:45:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hx51P-0007dl-Nz for qemu-devel@nongnu.org; Mon, 12 Aug 2019 03:45:41 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45040) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hx51P-0007cx-Es for qemu-devel@nongnu.org; Mon, 12 Aug 2019 03:45:39 -0400 Received: by mail-wr1-f68.google.com with SMTP id p17so103686393wrf.11 for ; Mon, 12 Aug 2019 00:45:38 -0700 (PDT) Received: from xz-x1.redhat.com (net77-43-52-122.mclink.it. [77.43.52.122]) by smtp.gmail.com with ESMTPSA id a84sm15909450wmf.29.2019.08.12.00.45.36 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 00:45:37 -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=lTmpuaaCdK+p1SsvLRVZxUAT9brrOBbHnhL4uMZgKJs=; b=TNXcNOPwC6V64YDLj+Gi8N2nhqX5a2W68O8EI3Ckk9ujg16mX/CHqttGfLoJpKGUAK ZwwmkVa/wsGSPcfZSffi7M2JVdNZ8QSQAI85GPynjnGw5E9ECnrZXfIrz8QRpfDlzhBQ 1YbNZ44TMZhWvTDDaz+XnaGj6jkc8JatgKLCKos4GtghDc03MCC7nvh/bJ1mv4H92wZX XuBNgB1MtTgA3pIY8Cqa3LMLjNISSelIkOC55N6ICI+VVrC5CQK+HKJ9Rgfp5FjZQSMu +GCmWBSQqm5qfc1P/gWDWN9rz4utQoyNk7bm7BaV/CiebBZXSVngLAbBPT4lbLyh07q8 8H/Q== X-Gm-Message-State: APjAAAUFk0bby0vA7lYrH/GCOMm4oQemKL3sz3PkhPJqv8cltxq0xQjp dcvfLT7+b9rvxkDH5tqCmIZ4X2vKEBk38A== X-Google-Smtp-Source: APXvYqwYyrYt3CyKED8drAxVo2rPv72ZkhD4VNuZOp69dfJgrsJ9LAOLsSSfzFeTG+OWMJmo/DsdJQ== X-Received: by 2002:a5d:5348:: with SMTP id t8mr37981882wrv.159.1565595937867; Mon, 12 Aug 2019 00:45:37 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 12 Aug 2019 09:45:29 +0200 Message-Id: <20190812074531.28970-3-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812074531.28970-1-peterx@redhat.com> References: <20190812074531.28970-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] [fuzzy] X-Received-From: 209.85.221.68 Subject: [Qemu-devel] [PATCH RFC 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 Reviewed-by: Eric Auger --- 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 94ebc0a4a1..d792b43c37 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -236,6 +236,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 a71d1a53a5..1cf63be45d 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 >*/ @@ -223,6 +230,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 136df7774c..88e7ec4b60 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -284,6 +284,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 58222c2211..6c80602771 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -614,6 +614,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 Tue Apr 16 18:43:29 2024 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=1565595992; cv=none; d=zoho.com; s=zohoarc; b=gKJm6tukBkvhDmMSCRAujysaQVNAVgpHOY4E3aUf7o9gqDIRfgfB7ZtNLrdaHAC/h4+L6X/J1oArN9Pf920fmhYN/ShssdYIBkUPKxNBBm6EpHGVY1ghW5rORc23DnVGcwKphnLwK1Hs8r8+IkLE2snWIk0yTudIQyKL1F7byBM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565595992; 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=sfojkDzCf1eY0fx+WFbDa7MyAVQy0gSxC1MNFuOMis4=; b=PKQOu2tCs0qGTNvvNU4h47s+Vl3FYx6M3PwAmQx9eTB1ZLV7d2L4bpeflecLrCGaDuACRRLPOgMgDSo6CkIkk+rFGTcoYCzp8FJXVwN5HFCsfFlSqhR19HZyUaGcEdxDBG9MpyPAMLRdJM5H6sdXDNOif0+5aUOLyTjoClD+Xos= 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 1565595992079508.96755992966587; Mon, 12 Aug 2019 00:46:32 -0700 (PDT) Received: from localhost ([::1]:43504 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hx52E-0005ee-1o for importer@patchew.org; Mon, 12 Aug 2019 03:46:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51270) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hx51S-000448-Hx for qemu-devel@nongnu.org; Mon, 12 Aug 2019 03:45:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hx51R-0007ec-JK for qemu-devel@nongnu.org; Mon, 12 Aug 2019 03:45:42 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43613) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hx51R-0007eG-Dc for qemu-devel@nongnu.org; Mon, 12 Aug 2019 03:45:41 -0400 Received: by mail-wr1-f68.google.com with SMTP id p13so29115066wru.10 for ; Mon, 12 Aug 2019 00:45:41 -0700 (PDT) Received: from xz-x1.redhat.com (net77-43-52-122.mclink.it. [77.43.52.122]) by smtp.gmail.com with ESMTPSA id a84sm15909450wmf.29.2019.08.12.00.45.37 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 00:45:39 -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=sfojkDzCf1eY0fx+WFbDa7MyAVQy0gSxC1MNFuOMis4=; b=CuAfCroGejqHXCbUoznh/ncQzR+Pu8wlnRE3YcPGL8wJ9D/Uiq1Zd358NVMsCT5TDY z4qc/HMAbZvkCnzgoItvSb8hZ7ZyZ1MnN2wiPX6ma68lqXxZUgAjBizEX91qOncKiQL+ SuvU7M0a3B1+e9GqUy6owg1t7rRxs/JED+UhFtSg5jJmokmAxH+uM6Iscm3p8pqBbMAg shbdqI9M+geISQIJ7OBzAdLCS+6I0RcJw1WGyfipYaEgsZLMXf3re+GGOTx33JaxqstC fEASfoaUF/xHyN6L2/9yYxoVnkhi4ZBJFdTnMfOAcSIIulzuk5bizzIUUiLVXzeLIhFG iKiw== X-Gm-Message-State: APjAAAWTOGqL5lk8LqitnnXNAg49wgFvqLIcYaU1E8ajSUODt5ZA76ba 4/dZnMRqgcarh41DY3mFUnB1PVB/UOIz5w== X-Google-Smtp-Source: APXvYqwqSWMV4UkiuBdWjf9nu3MtKEONGWpySABlNg94ZHCwOUrGtyIjnmWEyNrFuL2EliPP0yVzQQ== X-Received: by 2002:a5d:6b07:: with SMTP id v7mr28574416wrw.169.1565595940401; Mon, 12 Aug 2019 00:45:40 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 12 Aug 2019 09:45:30 +0200 Message-Id: <20190812074531.28970-4-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812074531.28970-1-peterx@redhat.com> References: <20190812074531.28970-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] [fuzzy] X-Received-From: 209.85.221.68 Subject: [Qemu-devel] [PATCH RFC 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 Reviewed-by: Eric Auger --- hw/i386/pc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 549c437050..4ea00c7bd2 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -2905,6 +2905,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); @@ -2929,6 +2949,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 Tue Apr 16 18:43:29 2024 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=1565595995; cv=none; d=zoho.com; s=zohoarc; b=CidG+PG5OkYY1JdnCrWGvJWdGDVMFR16Q6FgxO1Kp9AKSdxnizh2R+cmwqSVYEMFMVk7lfxQ5+wYDNigqZMoTmBE54kloNEBva4sXRqRc6cRC4AZBkEuc91sbVdq5rGjRercYm6lnrlRNuI+v5r5OKLiYtWoiYYMOJN606bnmjs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565595995; 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=RDsG20k8yVofF8t9UymKDQFqIL+ySKvJDtTXty8WtCk=; b=Hpb5i4WKvtK83as+iFCCubXOA9Xd31gGWkJ+Zu81mRaLpcTsQAOsBQf/RqemIwozLaoL7JZoufizkfAnlXHqIPDdFK4wWGv1zHK6UebqpiBJXzWcZ57JQZ9P/wMnr8Dl53hVzjnYVp0pcEGFg1LGB+jAzXjVarGJl5dlBXFhglM= 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 1565595995967447.1532248786933; Mon, 12 Aug 2019 00:46:35 -0700 (PDT) Received: from localhost ([::1]:43506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hx52J-0005ti-2D for importer@patchew.org; Mon, 12 Aug 2019 03:46:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51288) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hx51U-000496-Vk for qemu-devel@nongnu.org; Mon, 12 Aug 2019 03:45:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hx51U-0007fM-3D for qemu-devel@nongnu.org; Mon, 12 Aug 2019 03:45:44 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:40134) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hx51T-0007f9-U3 for qemu-devel@nongnu.org; Mon, 12 Aug 2019 03:45:44 -0400 Received: by mail-wr1-f66.google.com with SMTP id r1so4604840wrl.7 for ; Mon, 12 Aug 2019 00:45:43 -0700 (PDT) Received: from xz-x1.redhat.com (net77-43-52-122.mclink.it. [77.43.52.122]) by smtp.gmail.com with ESMTPSA id a84sm15909450wmf.29.2019.08.12.00.45.40 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 00:45:42 -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=RDsG20k8yVofF8t9UymKDQFqIL+ySKvJDtTXty8WtCk=; b=CFqSufbk2gCz8HApESXBrG4/PZGaBbhQpEh4eXEOu266QR6hJacBksdl3i7vtoZyHR x3BgSNi/jLjNrEKd+954N7pFHYmjX/SUxrVaTEFPbnm4hcqPSKx2Pr7Zx4Wkz0DvDG7k 1WkXYafACE5KEMMa3Krt0bR2Vkl2+K82bL56oppvLuPjcPbpYhDfxh/qpIhDFLeZWRYQ ipKMNpSaQr/1cQYJmOjWr35wYOR6Qvttf1EbDK3kir4QFSwCrAL1KAykHrw0Y3Qwf9UK iH7ezgsbOYcr4weRCp8+a+U73lzbSivfO5JyTN1f/9ri13xvS/NWpqgJZj0p3B4Yd+nm BLbQ== X-Gm-Message-State: APjAAAW2XdjsrI4oQV0wbQ59YlDnJp29s4za25EMK/G4i31Vg9fokk20 iXCLiEXbMTGC15Xu2doRoyBQwNZSeexs1g== X-Google-Smtp-Source: APXvYqwLMvFtM7QbmCnKR225ZLij0ipSwVowg80bETE3bUL9r5laaPfYomGqzzCi39n5Z8RNbmTbrg== X-Received: by 2002:adf:a2cd:: with SMTP id t13mr19811607wra.251.1565595942814; Mon, 12 Aug 2019 00:45:42 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 12 Aug 2019 09:45:31 +0200 Message-Id: <20190812074531.28970-5-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812074531.28970-1-peterx@redhat.com> References: <20190812074531.28970-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] [fuzzy] X-Received-From: 209.85.221.66 Subject: [Qemu-devel] [PATCH RFC 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 Reviewed-by: Eric Auger --- 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 642dd595ed..93b26b633b 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2932,10 +2932,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