From nobody Wed May 15 04:31:52 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=1568621364; cv=none; d=zoho.com; s=zohoarc; b=TB8uJEkHq6h+8xCbt0XHhFps1gHWWYPylaBcpLPbYaVny8bmohEqx+DS3QgcQEr5Is+VqEc/UrfRru982ZDZ7+jpFAe2JJNe+hiBiTS3XWKem6uDC7uiRPQEL7llEsXKzcfI+47w3JZC90qdCmR2xN0/N8/gC15olC3WWWNfZvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568621364; 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=/OJ9KNhMGzAg5fOf0w/DEoVEVTtjfS38DmGw575854w=; b=fLWGwxVznXnSgn7ZG+GlVzf0GQlSYBG7Q99RlQfRp3zpIjx2LdOI2PBC+VneQBuqfdK5WHDz6uuA6vQPHW3oiBJ/7r2KTpXoFBGY9ezfdKPuXPt6J+kIJy+Q8POg6YcoVM9XY4TjdUXlQ7xt4Ldva/oR1W8ehGsqBUrIqofTtrk= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568621364299404.8940104858067; Mon, 16 Sep 2019 01:09:24 -0700 (PDT) Received: from localhost ([::1]:59782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9m4R-00060J-Mt for importer@patchew.org; Mon, 16 Sep 2019 04:09:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55945) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9m2s-0004rJ-Qt for qemu-devel@nongnu.org; Mon, 16 Sep 2019 04:07:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i9m2r-00026S-HU for qemu-devel@nongnu.org; Mon, 16 Sep 2019 04:07:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38022) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i9m2r-00026G-9k for qemu-devel@nongnu.org; Mon, 16 Sep 2019 04:07:37 -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 8F25983F3D for ; Mon, 16 Sep 2019 08:07:36 +0000 (UTC) Received: by mail-pl1-f198.google.com with SMTP id 70so10796646ple.1 for ; Mon, 16 Sep 2019 01:07:36 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id r12sm43051515pgb.73.2019.09.16.01.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 01:07:34 -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=nKl8CBZiHmXRaSy5myWUeqxs+ilBwf/wRKOrGyD7BZk=; b=avQwJJPNXrucjKSCp52oNMBc4SfJaQHlWsBqHmxlwSb0csmcMC5qbbEV0qa/y/KzI3 +bxUfU12Mvg4PoOrJoBucbNVI688qxQ4KP8ozCpRwHTJPpA6MU8Rzmp84pBgdZCZm4C8 xOoY9+Ca/Jx1DoF8pC7OBjZlbO5VcFXpZEGFs85YBzBtFLWd4yhwiY7cePHM8mA4Vh6F pXIl3AtYduqhL3bWjA+9UiZdc8C4hvpJ6Ibo5zfH623fmCZ+du1Qi3oaxd43833kPBcY w9oZQDdchOTY/01zRbAdmbFIxQFrpluthFJCN8VTMdwKPgFoDioEjrFePmZq7NeaOhYN ei+Q== X-Gm-Message-State: APjAAAXiHrSKPaBJ/diwcPk1QlaR85Mlf63bk1PTBMIu69MvxqdxWshG /X8L3SXWY9xfm/45pROCML4S96JSkI4zRvQ1QplwwYpMkLZ2+bBEpmmqPPRI3tcAtCeQleddI8u s5iOl5BJLb9yv/5U= X-Received: by 2002:a63:6097:: with SMTP id u145mr55686716pgb.227.1568621255632; Mon, 16 Sep 2019 01:07:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqyZAK4uFk2ziEouYfuiYu42mFxULSp82tsLZbOw0SbYn/EfEckQP5CCQ5P9ZvFvu2es/mpoKg== X-Received: by 2002:a63:6097:: with SMTP id u145mr55686703pgb.227.1568621255358; Mon, 16 Sep 2019 01:07:35 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 16 Sep 2019 16:07:15 +0800 Message-Id: <20190916080718.3299-2-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916080718.3299-1-peterx@redhat.com> References: <20190916080718.3299-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 v3 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, Eric Auger , 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. Reviewed-by: Eric Auger Signed-off-by: Peter Xu --- hw/i386/intel_iommu.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 75ca6f9c70..bed8ffe446 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -35,6 +35,7 @@ #include "hw/i386/x86-iommu.h" #include "hw/pci-host/q35.h" #include "sysemu/kvm.h" +#include "sysemu/sysemu.h" #include "hw/i386/apic_internal.h" #include "kvm_i386.h" #include "migration/vmstate.h" @@ -64,6 +65,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 +2937,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 +3705,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 +3776,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 May 15 04:31:52 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=1568621506; cv=none; d=zoho.com; s=zohoarc; b=ayH+iZcUl3lKimRxaV1mSrwtffCY2mwxeJVXv20OyN+WFWzCalPdqcI+u6oZlFeOHo8O6d8E66K9YrIc+ZQZy5sv5sax+Pnhxi8v5wNrjIiJEEti/nzblKX2CxtrmiqO7BHg16z5CbqColUvUc3JJxPS2IUEElcV7tTUqQFry2k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568621506; 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=3MXaLNGHEjkW4XiprXcwAOD4ZjYK5lPMcEs2zh7AbmM=; b=muKc7l+ES17pTsCt9TOfLQQVVwdyQyRK3okLsWCAC9jZx8YE5FHkvLg4MRi1TC77DzXbi3j3BJHVoEAJS7DgU1lphLIW227vKnXJL9bRyYjj/J87MmLYo0+dD8buqKhRX/cVnIrO6c34MEvbeevL5KDVDWsfwu7lvdrXltiW2gs= 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 1568621506623749.5031083638186; Mon, 16 Sep 2019 01:11:46 -0700 (PDT) Received: from localhost ([::1]:59808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9m6q-0008Vy-Sz for importer@patchew.org; Mon, 16 Sep 2019 04:11:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55983) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9m2x-0004wa-L9 for qemu-devel@nongnu.org; Mon, 16 Sep 2019 04:07:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i9m2w-00028F-7y for qemu-devel@nongnu.org; Mon, 16 Sep 2019 04:07:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37972) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i9m2w-00027j-0I for qemu-devel@nongnu.org; Mon, 16 Sep 2019 04:07:42 -0400 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.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 42881C057F2C for ; Mon, 16 Sep 2019 08:07:41 +0000 (UTC) Received: by mail-pf1-f197.google.com with SMTP id 194so25845881pfu.3 for ; Mon, 16 Sep 2019 01:07:41 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id r12sm43051515pgb.73.2019.09.16.01.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 01:07: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=bnN7K5Xo2dCypYqOs+nUuanAlqTG6zTwZJ4Gt3nUhbs=; b=Vw2kd/M4CaGZeTCxBSth1rp2haMh6QNrN2vWwVid5TngTQfR2WNXT/6HAnIITUjfrf MZfL6tcZ3juluaytZYzL2wgmJD0ZiqpdyWRdoIxZcXkIh7M7+jcAspWWFOh5x/+crM1v gVo9z6zs2eqtoP1EPtQajnHAzYRBWBw8GwXFWRi0FQ83hIuzfybiGb1g/OzfVD9v3wat f1KCRc3sSs5HuMFMUOOcKM0ImRUd/oKKnLGUd0p3ZTPc/kYn2V593fFrXJYs38u62zSs sFgG8vpvRyx4axjRi7QDthZ5Vwa/iIq9cxPV2VLNxBcrfFcjQzADWNG9Z2HDXmM11qWc H/lQ== X-Gm-Message-State: APjAAAWCsewT5cugRazlYSzMmo7x6dAhVYXRn0ivbzcDFNHd9aGhF8Rm 4EzDlvzSrV7JVZYrXVzf/ij+WW/Qi41KpIyOv4GPBJsV5W3ePwsANMFmzNJKiPQD23TW32xOcTt 62mhr61HHgNZ4nv4= X-Received: by 2002:aa7:80ca:: with SMTP id a10mr52220393pfn.96.1568621260420; Mon, 16 Sep 2019 01:07:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqyC7lRWCvXNKpA79rEQh7y8YxospED3eirnBQbXXeJDdwPrBKBWkrrgWBaqvL4g0fC134FRgw== X-Received: by 2002:aa7:80ca:: with SMTP id a10mr52220375pfn.96.1568621260219; Mon, 16 Sep 2019 01:07:40 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 16 Sep 2019 16:07:16 +0800 Message-Id: <20190916080718.3299-3-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916080718.3299-1-peterx@redhat.com> References: <20190916080718.3299-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 v3 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, Eric Auger , 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. Reviewed-by: Eric Auger 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 May 15 04:31:52 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=1568621639; cv=none; d=zoho.com; s=zohoarc; b=ntCYSIrSXpWewHhXc2yhe8RbilwEopN+xuiBzkyatXkFtgr2aHE06aID04FKwaAJPJKeYI4Itt9HGulR/MiPOeqptVMHKNKGJfEWvdjhTD03MvERGWDLx54E1jbyoQAS3eixi/BK0aFm7VuzU4JHKE9HJ39m+We/KYbC2z4CPp0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568621639; 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=Dz28e1NYmHt1huTZydyKHQ9Y8Bj2BqJyt4OGz9hbVc8=; b=b+/PeYsGioAUuu7gx6oH7z0NBj9xTGhbPSE7Sv1HZRIU5pUiKuEPSv9pl5NQNM1IrZUqmPtPzHM15D1G9prjDTEVpngIgrWi5fWWP62qn5VveYjQj8lN3Y4hfKUzUNhnV4E9zVY0j9nnmAg9YyOY+vKtIDC5gKy2G+K0Y0cgahA= 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 156862163929992.20984982088385; Mon, 16 Sep 2019 01:13:59 -0700 (PDT) Received: from localhost ([::1]:59826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9m8x-0002Z4-RB for importer@patchew.org; Mon, 16 Sep 2019 04:13:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55999) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9m31-000520-Ve for qemu-devel@nongnu.org; Mon, 16 Sep 2019 04:07:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i9m30-0002A4-Rn for qemu-devel@nongnu.org; Mon, 16 Sep 2019 04:07:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36774) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i9m30-00029o-KC for qemu-devel@nongnu.org; Mon, 16 Sep 2019 04:07:46 -0400 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (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 E28264E926 for ; Mon, 16 Sep 2019 08:07:45 +0000 (UTC) Received: by mail-pl1-f199.google.com with SMTP id y18so1946239pll.17 for ; Mon, 16 Sep 2019 01:07:45 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id r12sm43051515pgb.73.2019.09.16.01.07.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 01:07:44 -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=w4YQkHRbAbpUMWjqlM+JKSO/9Aa2mvQClFqu2zmR7Cs=; b=OtJoWD2amFJcBBplSHKTDMPTd4zp5aqMsXXU6kw6vXjuG846Z88JO+nOS9c9kwB3lB tbhdXuZ9VkrmWwXXzbMM5E15gxOyRqipyMaevAVUsiOZVpVMEFv6T14lXcuGybucAMWL gW5o0kWeHZZwyM6VmMUeI7eBcVhTdX0zFGlV/dXBQ3XdMld0ZRb8BHR5Bhw57uSbtiHs SH1srLOvDlfqUQD/TR+JAWZjAF5ja2hQSEHPX6WEkQ5fhn7Svy/x2HhZGH1MqwLTR0+y w2x8TE6gMKilG2QrnOW2F2KZOf7tOWjxoU1F6fl20awx4Fzg5La8deNNJtmU+eyhvVzm fMEQ== X-Gm-Message-State: APjAAAWafuDC5NUo/lYv/mo+z59zWt0RJAebuoKL3vB8fevxIPEGYWiW lEIkPoc9u9ltBFPKAATm7UAtKCbqS2YFuhDrgGG8bUC9GofbYQ8daYDqjQwGtTR0qtYiyL9Psy+ LzwSjgWIV2ZUfxB8= X-Received: by 2002:a17:902:6f0f:: with SMTP id w15mr40939017plk.200.1568621265152; Mon, 16 Sep 2019 01:07:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqyY8y/5KQ4cJjx+NMoALbWDhGCiryj/G1MdFekoqxjP9Th4h8FTBQllNinNiJs2BbHpTE9EIw== X-Received: by 2002:a17:902:6f0f:: with SMTP id w15mr40938988plk.200.1568621264923; Mon, 16 Sep 2019 01:07:44 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 16 Sep 2019 16:07:17 +0800 Message-Id: <20190916080718.3299-4-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916080718.3299-1-peterx@redhat.com> References: <20190916080718.3299-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 v3 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, Eric Auger , 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. Reviewed-by: Eric Auger 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 May 15 04:31:52 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=1568621523; cv=none; d=zoho.com; s=zohoarc; b=hGXgJPH4edBUIBkZT4KyIIvly062CGmrk8pLgsVmxWksIBeaMulUOZXtmXrgikCDBrVgcjv1Snq+ME2efapD3HSCBA46VmULegrH2ZDXqpJlU50jchGYZnIFRlVkd+1Iw8TQRClqtqW4siHxcXThOfv760u2oQ0BKixp/uQQ0wY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568621523; 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=nmE6cphgGSfuRpSYHmBaH3flkReKC3mKIpc0TIUSO10=; b=VmSkq6jyJP+q1su8u64BKqwF05m+kUrgNRseBI/y0GUClqH/1GMXKGMhKpXeNXbcqB5947fB4KMcaCGrVDwSTyWu9zSjmOVC2OQGc38WOo385ZTYWQYywNiAoMZBJNIHis8pmFef2tW19MZW0ANGWAOVIttEkwkfzutM/TgmVKY= 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 1568621523385434.7103534716658; Mon, 16 Sep 2019 01:12:03 -0700 (PDT) Received: from localhost ([::1]:59810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9m78-0000K7-0K for importer@patchew.org; Mon, 16 Sep 2019 04:12:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56022) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9m36-00057r-Jm for qemu-devel@nongnu.org; Mon, 16 Sep 2019 04:07:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i9m35-0002DN-JQ for qemu-devel@nongnu.org; Mon, 16 Sep 2019 04:07:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38698) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i9m35-0002Cx-CB for qemu-devel@nongnu.org; Mon, 16 Sep 2019 04:07:51 -0400 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.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 A4B31C055673 for ; Mon, 16 Sep 2019 08:07:50 +0000 (UTC) Received: by mail-pg1-f200.google.com with SMTP id h10so4095358pgh.11 for ; Mon, 16 Sep 2019 01:07:50 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id r12sm43051515pgb.73.2019.09.16.01.07.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 01:07:48 -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=ZFeNVkx/j6RSMxkpoM7GQeDxNvolVV9ALPcNdbnD3Qk=; b=GMNfbbZDDOyoikPeRzMscrxQwpzHQWKQZz36FBem0woL0UBebVxpcHE0GsJzr/Rh2P tJJlzL/TMWcWUlYRxT2DJznANme0ukHwknz9nvU6/Dk2chOYfWWNmlHzvwXTzbTdcLgV gtzrdCJLrDYwHyqwpoGipLFtiDprGR9fK9iu/3p6lpxDK9hQPEUvCcLhhHUPtFuthjX+ d34FbqY2VZYVv7UhUTvnPOfRPKm8ohprj7b1q5YzPSMGaBtTGa5QTCfYROZajhf5d+BT hos5zpD1xP50lErnyR6UrBDh07tPwOx1W4r3y42kHcyzDnTel2RmfX1xY8sa5EBXN+XR fL3Q== X-Gm-Message-State: APjAAAXsNL4oo+SQdFINXnOBseEBnX4bbSjxyCAVzTWDKH/L5QkKYfCU eugkbdMPnUPfm90v3vvkTXP1hAhqDrqRg0BFjy2qwbbP2xtbrBrQRMiGVR6KlGtCN5flH0RZsiq T0EOQXo+H12SZwIs= X-Received: by 2002:a17:90a:b282:: with SMTP id c2mr19253820pjr.135.1568621269826; Mon, 16 Sep 2019 01:07:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkFFwjEfZlp/nZTRkhUNzWW0Wdn8A/aiyl/jiPz+lt+ghFCdhyDeygM2YmhE//epS/A/d0Qg== X-Received: by 2002:a17:90a:b282:: with SMTP id c2mr19253800pjr.135.1568621269652; Mon, 16 Sep 2019 01:07:49 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 16 Sep 2019 16:07:18 +0800 Message-Id: <20190916080718.3299-5-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916080718.3299-1-peterx@redhat.com> References: <20190916080718.3299-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 v3 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, Eric Auger , 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. Reviewed-by: Eric Auger 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 bed8ffe446..f1de8fdb75 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2936,10 +2936,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