From patchwork Sat Dec 2 08:00:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1870873 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=tKWyFLVG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sj2Vf2RmNz1ySh for ; Sat, 2 Dec 2023 19:03:22 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9Kvj-0004Jf-H9; Sat, 02 Dec 2023 03:00:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9KvY-0004I8-Id for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:00:43 -0500 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9KvV-0004wL-Pz for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:00:40 -0500 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-1faf56466baso896786fac.3 for ; Sat, 02 Dec 2023 00:00:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1701504035; x=1702108835; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=nifxH5Ik7WtdTWPOluQ6Dk90tFkOKKIHCCiZQjqggm0=; b=tKWyFLVGdx5JF3IoLtjdPuhpXwKcx7LRFR109SjAQ9Mcwxq6WMZ7Ow/RCrEpcsRjB/ D9jQS7n5LzqudmvbtBBcTKKXkvpKUifuQf01ZqHDPpofgGdRGiGHcQo9+mtkjuypcEUI vPTexbgskTqp3Z/ZJ2q2uQO0geiKB1YnIBiPSMQs4oIuS/0GhvGMSCzxmd04LzDQey8j QGR/sMEZbK2Mapxbydh1WaegAr3ip6+nxNNbvEZLZFJpefoSuSxd2/8i4kyS22vohlCO TEP7kDRBacHfVxEGD9WHNBUJKXNtj6Jg4JYXaXfwwphrfX3/mgwjPqxPf8grc1sJ5RO6 cjJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701504035; x=1702108835; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nifxH5Ik7WtdTWPOluQ6Dk90tFkOKKIHCCiZQjqggm0=; b=TdhhrbSVGUEedS4XaxMX5PKqTlGz73uW3qLNsg32c/jiVWyHlIgGpKWaawLA8TxgpF 1yWdkBlidGqL0HrkSfJZwxPFEGkDZ49UWkh7kOGAbJhwI+8r2X61KXF+GHFVFVBNQN9u KbaQ61b8FFQVzc/G5RVeGkVC3RYOSf/cX2zd5f1kUVtQl5sfMMDbWnX32zKnLO92B5Wu vVMRsI9RMVfpV4/e06itNcFuNDeqLURLnuSHONSWtkjAKU91zgzUsh42XHgQUcBAH1F7 6bQtShXpP5t0WhjO5VZINWOHUqbc9t8VMDJJbAvBu08rUU7bLhAVpO3Edptbq5VzIX7t BmaA== X-Gm-Message-State: AOJu0Yw+S4gifJCKsCgRCC/nCQphYHgpPjkNR0lXYs7rmVsI5Qp9dW7u SQRWSK18VS+k5DyZNVbnlBhLVQ== X-Google-Smtp-Source: AGHT+IFvn1mUUHFyNEu1N1UpK1OajUfnJSAZsNIBLWwj+zcI6v2p0dT2kmY8PUL5XcXsJ3Fj8e5EAA== X-Received: by 2002:a05:6870:f78e:b0:1fb:75b:2fb5 with SMTP id fs14-20020a056870f78e00b001fb075b2fb5mr1236316oab.76.1701504035166; Sat, 02 Dec 2023 00:00:35 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id z23-20020a17090a015700b00285be64e529sm404492pje.39.2023.12.02.00.00.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 00:00:34 -0800 (PST) From: Akihiko Odaki Date: Sat, 02 Dec 2023 17:00:24 +0900 Subject: [PATCH 01/14] vfio: Avoid inspecting option QDict for rombar MIME-Version: 1.0 Message-Id: <20231202-sriov-v1-1-32b3570f7bd6@daynix.com> References: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> In-Reply-To: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> To: "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.12.4 Received-SPF: none client-ip=2001:4860:4864:20::2a; envelope-from=akihiko.odaki@daynix.com; helo=mail-oa1-x2a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org vfio determines if rombar is explicitly enabled by inspecting QDict. Inspecting QDict is not nice because QDict is untyped and depends on the details on the external interface. Instead of inspecting QDict, inspect PCIDevice::rom_bar. PCIDevice::rom_bar is changed to have -1 by the default to tell rombar is explicitly enabled. It is consistent with other properties like addr and romsize. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci_device.h | 5 +++++ hw/pci/pci.c | 2 +- hw/vfio/pci.c | 3 +-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index d3dd0f64b2..5b6436992f 100644 --- a/include/hw/pci/pci_device.h +++ b/include/hw/pci/pci_device.h @@ -205,6 +205,11 @@ static inline uint16_t pci_get_bdf(PCIDevice *dev) return PCI_BUILD_BDF(pci_bus_num(pci_get_bus(dev)), dev->devfn); } +static inline bool pci_rom_bar_explicitly_enabled(PCIDevice *dev) +{ + return d->rom_bar && d->rom_bar != -1; +} + uint16_t pci_requester_id(PCIDevice *dev); /* DMA access functions */ diff --git a/hw/pci/pci.c b/hw/pci/pci.c index c49417abb2..53c59a5b9f 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -71,7 +71,7 @@ static Property pci_props[] = { DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1), DEFINE_PROP_STRING("romfile", PCIDevice, romfile), DEFINE_PROP_UINT32("romsize", PCIDevice, romsize, -1), - DEFINE_PROP_UINT32("rombar", PCIDevice, rom_bar, 1), + DEFINE_PROP_UINT32("rombar", PCIDevice, rom_bar, -1), DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present, QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false), DEFINE_PROP_BIT("x-pcie-lnksta-dllla", PCIDevice, cap_present, diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index c62c02f7b6..bc29ce9194 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1008,7 +1008,6 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev) { uint32_t orig, size = cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK); off_t offset = vdev->config_offset + PCI_ROM_ADDRESS; - DeviceState *dev = DEVICE(vdev); char *name; int fd = vdev->vbasedev.fd; @@ -1042,7 +1041,7 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev) } if (vfio_opt_rom_in_denylist(vdev)) { - if (dev->opts && qdict_haskey(dev->opts, "rombar")) { + if (pci_rom_bar_explicitly_enabled(&vdev->pdev)) { warn_report("Device at %s is known to cause system instability" " issues during option rom execution", vdev->vbasedev.name); From patchwork Sat Dec 2 08:00:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1870864 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=FuT+3Tsh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sj2Sk4f6sz23nT for ; Sat, 2 Dec 2023 19:01:41 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9Kvk-0004K2-Un; Sat, 02 Dec 2023 03:00:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9Kvb-0004IB-An for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:00:49 -0500 Received: from mail-oo1-xc2f.google.com ([2607:f8b0:4864:20::c2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9KvZ-0004xC-Le for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:00:43 -0500 Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-58d08497aa1so1954959eaf.0 for ; Sat, 02 Dec 2023 00:00:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1701504040; x=1702108840; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=2S+QsDyqDyIlvvpRINrQ1P4xjH1/QaHDNGsQRs2XIL0=; b=FuT+3TshDdtjiqOmbcjuLrVdRjmS81QRqKfBI/Kdkfvfy9VpLnLXXdMhddWWeHC9a2 JZ8bVzZUhbVcN89BuNFeU9DD9NUi1u5fjQ7luiFCSNZZfO1u4D9dcre1lI2jDnb2OxEz dmdUgrQ1FDPkQVu8lM7b9lAkE/yorvJO/JF6ImdfNkKohT3ql39Aw9pRwY8T8KuKBtEr ttnk1itKK09R3RZRJcA1BLW27wnvVvh4n7xQK5nS1w16P8QlCOz1n6X6Vmb6FtMl43wb DdKRe4j2v3jBcviZ6mJMkGkOH+oZJaGAJfBfW64WHmqlx6OUGzHAIbvSLodfONJ5GhWt bvPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701504040; x=1702108840; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2S+QsDyqDyIlvvpRINrQ1P4xjH1/QaHDNGsQRs2XIL0=; b=dHBPkwV99p3XeTp+yxWLppiqZovqgRSX0a0XvglT0ehkX7HNvJsPyiALD5NCioZVSC dJMEPvW19kCt0FZk3tx18Yc+GpBzoOJUxEdKrG/V2LM8Oo8AXVCuicmL0KTTDTs1Offp gtjSipV47v7uQbyCqLQkldaIArfsfpFfJIRB/hxZKKu68hTQzBu529AHcnfOlF8DHMfo pQdmhrCj2jtvcTnt5wEYAD6cWmFHn9AZwo0zSOHNenvzFm+KpklJ4MbASS6k+hdO9ZtW EbVLiP6ePFkmPC29kDmP3Xh7ognfCQnQRSYsbzogcc6f1pSqf5M0gvaT9iGpg28YS7xH h5Tw== X-Gm-Message-State: AOJu0YxkIkyJO0ioQ0bmy4Q141c7iOYvTBrc0CX2YxMdRV4MXtxR/OHD e9zS5y2hD41l3KywldMpK7dYFg== X-Google-Smtp-Source: AGHT+IHVQe5TIvceBmipGBNc1CxkcZYyB9SChYBRLbRmmLgxNpX5zFcYZ7sAQCH2mojhfNlk3ic8IQ== X-Received: by 2002:a05:6358:896:b0:170:911:8b80 with SMTP id m22-20020a056358089600b0017009118b80mr982336rwj.28.1701504040152; Sat, 02 Dec 2023 00:00:40 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id 1-20020a17090a000100b0027722832498sm6730481pja.52.2023.12.02.00.00.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 00:00:39 -0800 (PST) From: Akihiko Odaki Date: Sat, 02 Dec 2023 17:00:25 +0900 Subject: [PATCH 02/14] hw/qdev: Remove opts member MIME-Version: 1.0 Message-Id: <20231202-sriov-v1-2-32b3570f7bd6@daynix.com> References: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> In-Reply-To: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> To: "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.12.4 Received-SPF: none client-ip=2607:f8b0:4864:20::c2f; envelope-from=akihiko.odaki@daynix.com; helo=mail-oo1-xc2f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It is no longer used. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci_device.h | 2 +- include/hw/qdev-core.h | 4 ---- hw/core/qdev.c | 1 - system/qdev-monitor.c | 12 +++++++----- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index 5b6436992f..8e287c5414 100644 --- a/include/hw/pci/pci_device.h +++ b/include/hw/pci/pci_device.h @@ -205,7 +205,7 @@ static inline uint16_t pci_get_bdf(PCIDevice *dev) return PCI_BUILD_BDF(pci_bus_num(pci_get_bus(dev)), dev->devfn); } -static inline bool pci_rom_bar_explicitly_enabled(PCIDevice *dev) +static inline bool pci_rom_bar_explicitly_enabled(PCIDevice *d) { return d->rom_bar && d->rom_bar != -1; } diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 151d968238..6befbca311 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -237,10 +237,6 @@ struct DeviceState { * @pending_deleted_expires_ms: optional timeout for deletion events */ int64_t pending_deleted_expires_ms; - /** - * @opts: QDict of options for the device - */ - QDict *opts; /** * @hotplugged: was device added after PHASE_MACHINE_READY? */ diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 43d863b0c5..c98691a90d 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -706,7 +706,6 @@ static void device_finalize(Object *obj) dev->canonical_path = NULL; } - qobject_unref(dev->opts); g_free(dev->id); } diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index a13db763e5..71c00f62ee 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -625,6 +625,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts, char *id; DeviceState *dev = NULL; BusState *bus = NULL; + QDict *properties; driver = qdict_get_try_str(opts, "driver"); if (!driver) { @@ -705,13 +706,14 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts, } /* set properties */ - dev->opts = qdict_clone_shallow(opts); - qdict_del(dev->opts, "driver"); - qdict_del(dev->opts, "bus"); - qdict_del(dev->opts, "id"); + properties = qdict_clone_shallow(opts); + qdict_del(properties, "driver"); + qdict_del(properties, "bus"); + qdict_del(properties, "id"); - object_set_properties_from_keyval(&dev->parent_obj, dev->opts, from_json, + object_set_properties_from_keyval(&dev->parent_obj, properties, from_json, errp); + qobject_unref(properties); if (*errp) { goto err_del_dev; } From patchwork Sat Dec 2 08:00:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1870869 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=raG8ubyC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sj2T55tNZz1ySh for ; Sat, 2 Dec 2023 19:02:01 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9Kvn-0004Kz-91; Sat, 02 Dec 2023 03:01:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9Kvg-0004IS-TG for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:00:49 -0500 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9Kve-0004yR-NX for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:00:48 -0500 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-1fb04b2251bso510056fac.0 for ; Sat, 02 Dec 2023 00:00:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1701504045; x=1702108845; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=vEZSvELmMn+CZAABU4UFznXntadvaecyTxpcvBhacJw=; b=raG8ubyCjw63i3WfjYpq6JzcDsXn0D8prKKwRLHMavmQFhxFK6vCLi8jbuufkBnvqA G6JXqjGIrllo1q4TmmJhO0tloouU4lVajciQ5mfqRmXj7o7XfIbyxsxBoHH9/wNTIlUy H/CA2Uz/5ny4n/zIBpSeaUg+jqAPpeH+RLClRpP8FEnIHEYiUMFnuULbgQw5NQRIharU 8jZOVmlVYgP8dtI+JcLPZ4rKQ8SoGqBvpEUf5EQXtSuH7hOFkaYQ67+ln0djpFfR6abf AFEjodNUp+Gt9/1xZkfxXQweiWFIKlnDSIoZScwEj7PFxF65De1XdGBFsuPn3LnGdZFH 4giA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701504045; x=1702108845; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vEZSvELmMn+CZAABU4UFznXntadvaecyTxpcvBhacJw=; b=lG0+Rjko8WS753JJKnR93PYRlayAz1g5xo07nYOCx2kqYmD2eBAog5dx0E/87eV6Pg hkeSynfcFBVapUFzR1qKBWAMPxXg4ZO/hM/FZvfmIvnwQZjaG2iyp+jOryWCpC/hTmut cTa/7+N8U7VyZUbdw8wBpjHqI15yWd1q6bmyRc4pgZr9TKtBBHNPjlPN+XbchtYgKYq3 db+QdlXvDmXATMlLDlXWR1BH1NBXNO/eZGzFW8MyilCkTlFBv5taKlJkquCT62lwbmQf MajxE6lYjgD3D4z3OTLveR7Wo2ELRULgIMEi07jAQJPQ2h4/U/rJvRhxchAkikvoG3Xf JMdg== X-Gm-Message-State: AOJu0YxHEtzMT+wzClaUJduqVBpIZJ16biSwFPhLx2CfZ4emXevk3fuG dB1lcHF2fxNkFnIjUEQm1vATQw== X-Google-Smtp-Source: AGHT+IGAl67z3a/aDV7FWG8vBviS0LIZNv65Vrp/DLSXRuKZijKJCgFo0GYNGuk4Eaaf7OVEg3cizQ== X-Received: by 2002:a05:6870:c0b:b0:1fa:edc2:892e with SMTP id le11-20020a0568700c0b00b001faedc2892emr1224357oab.11.1701504045535; Sat, 02 Dec 2023 00:00:45 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id a11-20020a17090acb8b00b00286541736a4sm2813051pju.29.2023.12.02.00.00.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 00:00:45 -0800 (PST) From: Akihiko Odaki Date: Sat, 02 Dec 2023 17:00:26 +0900 Subject: [PATCH 03/14] qdev: Add DeviceClass::hide() MIME-Version: 1.0 Message-Id: <20231202-sriov-v1-3-32b3570f7bd6@daynix.com> References: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> In-Reply-To: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> To: "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.12.4 Received-SPF: none client-ip=2001:4860:4864:20::31; envelope-from=akihiko.odaki@daynix.com; helo=mail-oa1-x31.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org DeviceClass::hide() is a better alternative to DeviceListener::hide_device() that does not need listener registration and is contained in specific devices that need the hiding capability. Signed-off-by: Akihiko Odaki --- include/hw/qdev-core.h | 33 +++++++++++++++++++++++---------- system/qdev-monitor.c | 11 +++++++++++ 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 6befbca311..de221b6f02 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -56,16 +56,15 @@ * Hiding a device * --------------- * - * To hide a device, a DeviceListener function hide_device() needs to - * be registered. It can be used to defer adding a device and - * therefore hide it from the guest. The handler registering to this - * DeviceListener can save the QOpts passed to it for re-using it - * later. It must return if it wants the device to be hidden or - * visible. When the handler function decides the device shall be - * visible it will be added with qdev_device_add() and realized as any - * other device. Otherwise qdev_device_add() will return early without - * adding the device. The guest will not see a "hidden" device until - * it was marked visible and qdev_device_add called again. + * To hide a device, a DeviceClass function hide() needs to be registered. It + * can be used to defer adding a device and therefore hide it from the guest. + * The handler can save the QOpts passed to it for re-using it later. It must + * return if it wants the device to be hidden or visible. When the handler + * function decides the device shall be visible it will be added with + * qdev_device_add() and realized as any other device. Otherwise + * qdev_device_add() will return early without adding the device. The guest + * will not see a "hidden" device until it was marked visible and + * qdev_device_add called again. * */ @@ -90,6 +89,8 @@ typedef enum DeviceCategory { DEVICE_CATEGORY_MAX } DeviceCategory; +typedef bool (*DeviceHide)(DeviceClass *dc, const QDict *device_opts, + bool from_json, Error **errp); typedef void (*DeviceRealize)(DeviceState *dev, Error **errp); typedef void (*DeviceUnrealize)(DeviceState *dev); typedef void (*DeviceReset)(DeviceState *dev); @@ -151,6 +152,18 @@ struct DeviceClass { bool hotpluggable; /* callbacks */ + /** + * @hide: informs qdev if a device should be visible or hidden. + * + * This callback is called upon init of the DeviceState. + * We can hide a failover device depending for example on the device + * opts. + * + * On errors, it returns false and errp is set. Device creation + * should fail in this case. + */ + DeviceHide hide; + /** * @reset: deprecated device reset method pointer * diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index 71c00f62ee..639beabc5f 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -669,6 +669,17 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts, return NULL; } + if (dc->hide) { + if (dc->hide(dc, opts, from_json, errp)) { + if (bus && !qbus_is_hotpluggable(bus)) { + error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name); + } + return NULL; + } else if (*errp) { + return NULL; + } + } + if (phase_check(PHASE_MACHINE_READY) && bus && !qbus_is_hotpluggable(bus)) { error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name); return NULL; From patchwork Sat Dec 2 08:00:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1870868 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=jrIIeuK9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sj2T36WfGz1ySh for ; Sat, 2 Dec 2023 19:01:59 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9Kw9-0004O2-4h; Sat, 02 Dec 2023 03:01:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9Kvl-0004K6-TM for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:00:53 -0500 Received: from mail-il1-x12e.google.com ([2607:f8b0:4864:20::12e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9Kvk-0004zd-7l for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:00:53 -0500 Received: by mail-il1-x12e.google.com with SMTP id e9e14a558f8ab-35c18e55633so12373205ab.2 for ; Sat, 02 Dec 2023 00:00:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1701504051; x=1702108851; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Bj8XVIcfBYxFCt7yVr0gyoBi8ZlaEENnjEghOjifY8I=; b=jrIIeuK9mldjdWmrTFtJDYi54EqW0GcbmzTMs1zBt8Tmrw/27Ldx1MLakuywnnherw kzvKASXC8CP1T0lplz4srN1ynT22Sla7W3+BiJ8TG6rU3EtrkZillHO3H08jaCVbO63n xLx9tMq7+NWM/DiQ5n+9nZYbm+J0YqBL1R/3pvWWp8cJGWE3FzxN47LhkEcmJ3NaXOkf ryAz2/aykkCTC6OM4sdT/0kQGks8en9nlm+9FCZPZQzRa5I8OXK17LepdxaJGIVHFpxK WF4B22VbBcansVTF00cC8EZSwikG1UNuolD+CVJjwp07ModOdAMnkCk7dlamOBI5XdX3 LM5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701504051; x=1702108851; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Bj8XVIcfBYxFCt7yVr0gyoBi8ZlaEENnjEghOjifY8I=; b=bEkqj/FQiZDeHf74MaSCfQkKFkUtJ28gNLoipPKn+CNVyD8pG8IlvqkxqVMyQOhHIv jm51+PX0S5Kzmc8wDdgtayyqmqzjElHLPsTVbDjUEof+WCEbLtpGL01gkUTSme6WxnCO j0zlR8X1qZpL4gjeiPkLr32lQfPCvTH1xSKYQufbT1laNUCe2sI8X+bQEayP8x63r6Om 9g3C51gLTKjfRKdxPqyVeDtQQvJksxSGV9n3QFhQbcImI2bLD8NY3AheabCWoITPW8sZ YsJ1oW2j0NNmAdfLLKsJINXweih+gkOO1IRJ5VwnEz6TZEGFHL5IHTRqgrUYiRQYZYHE YhBw== X-Gm-Message-State: AOJu0YwNeESJqosECA9Hiby2vbvbl5AJb/P4yT4sMGMklE697qh6Smi4 bGE1O2uHxvPQaUMJx2jKzsm1yg== X-Google-Smtp-Source: AGHT+IG6Xiul2ufJptSl6rNTgX/WyEaTOhl3ssbdyNFFtxdeVXcZh8guEm61cpqewSpBe2uVM9+hZg== X-Received: by 2002:a92:cb4d:0:b0:35d:5995:798b with SMTP id f13-20020a92cb4d000000b0035d5995798bmr1130440ilq.37.1701504050726; Sat, 02 Dec 2023 00:00:50 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id bg6-20020a17090b0d8600b00286558ad352sm2735558pjb.8.2023.12.02.00.00.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 00:00:50 -0800 (PST) From: Akihiko Odaki Date: Sat, 02 Dec 2023 17:00:27 +0900 Subject: [PATCH 04/14] hw/pci: Add pci-failover MIME-Version: 1.0 Message-Id: <20231202-sriov-v1-4-32b3570f7bd6@daynix.com> References: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> In-Reply-To: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> To: "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.12.4 Received-SPF: none client-ip=2607:f8b0:4864:20::12e; envelope-from=akihiko.odaki@daynix.com; helo=mail-il1-x12e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org pci-failover allows to create a device capable of failover without relying on DeviceListener::hide_device(), which intrudes the pci-device implementation from outside. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci_device.h | 14 ++++++++++++++ hw/pci/pci.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index 8e287c5414..a7bfb192e8 100644 --- a/include/hw/pci/pci_device.h +++ b/include/hw/pci/pci_device.h @@ -9,6 +9,11 @@ typedef struct PCIDeviceClass PCIDeviceClass; DECLARE_OBJ_CHECKERS(PCIDevice, PCIDeviceClass, PCI_DEVICE, TYPE_PCI_DEVICE) +#define TYPE_PCI_FAILOVER "pci-failover" +typedef struct PCIFailoverClass PCIFailoverClass; +DECLARE_CLASS_CHECKERS(PCIFailoverClass, PCI_FAILOVER, TYPE_PCI_FAILOVER) +#define PCI_FAILOVER(obj) INTERFACE_CHECK(PciFailover, (obj), TYPE_PCI_FAILOVER) + /* * Implemented by devices that can be plugged on CXL buses. In the spec, this is * actually a "CXL Component, but we name it device to match the PCI naming. @@ -162,6 +167,15 @@ struct PCIDevice { uint32_t acpi_index; }; +struct PCIFailoverClass { + /* private */ + InterfaceClass parent_class; + + /* public */ + bool (* set_primary)(DeviceState *dev, const QDict *device_opts, + bool from_json, Error **errp); +}; + static inline int pci_intx(PCIDevice *pci_dev) { return pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1; diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 53c59a5b9f..3d07246f8e 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -46,6 +46,7 @@ #include "hw/pci/msix.h" #include "hw/hotplug.h" #include "hw/boards.h" +#include "qapi/qmp/qdict.h" #include "qapi/error.h" #include "qemu/cutils.h" #include "pci-internal.h" @@ -2050,6 +2051,40 @@ PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn) return bus->devices[devfn]; } +static bool pci_qdev_hide(DeviceClass *dc, const QDict *device_opts, + bool from_json, Error **errp) +{ + const char *standby_id; + DeviceState *dev; + ObjectClass *class; + ObjectClass *interface; + + if (!device_opts) { + return false; + } + + if (!qdict_haskey(device_opts, "failover_pair_id")) { + return false; + } + + standby_id = qdict_get_str(device_opts, "failover_pair_id"); + dev = qdev_find_recursive(sysbus_get_default(), standby_id); + if (!dev) { + error_setg(errp, "failover pair not found"); + return false; + } + + class = object_get_class(OBJECT(dev)); + interface = object_class_dynamic_cast(class, TYPE_PCI_FAILOVER); + if (!interface) { + error_setg(errp, "failover pair does not support failover"); + return false; + } + + return ((PCIFailoverClass *)interface)->set_primary(dev, device_opts, + from_json, errp); +} + #define ONBOARD_INDEX_MAX (16 * 1024 - 1) static void pci_qdev_realize(DeviceState *qdev, Error **errp) @@ -2653,6 +2688,7 @@ static void pci_device_class_init(ObjectClass *klass, void *data) { DeviceClass *k = DEVICE_CLASS(klass); + k->hide = pci_qdev_hide; k->realize = pci_qdev_realize; k->unrealize = pci_qdev_unrealize; k->bus_type = TYPE_PCI_BUS; @@ -2861,6 +2897,12 @@ static const TypeInfo pci_device_type_info = { .class_base_init = pci_device_class_base_init, }; +static const TypeInfo pci_failover_type_info = { + .name = TYPE_PCI_FAILOVER, + .parent = TYPE_INTERFACE, + .class_size = sizeof(PCIFailoverClass), +}; + static void pci_register_types(void) { type_register_static(&pci_bus_info); @@ -2870,6 +2912,7 @@ static void pci_register_types(void) type_register_static(&cxl_interface_info); type_register_static(&pcie_interface_info); type_register_static(&pci_device_type_info); + type_register_static(&pci_failover_type_info); } type_init(pci_register_types) From patchwork Sat Dec 2 08:00:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1870863 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=b9XJBbB2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sj2Sk49fWz1ySh for ; Sat, 2 Dec 2023 19:01:41 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9Kw9-0004O7-4x; Sat, 02 Dec 2023 03:01:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9Kvt-0004Lc-20 for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:02 -0500 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9Kvp-00050W-8D for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:00:58 -0500 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-6d7f3a4bbc6so970019a34.2 for ; Sat, 02 Dec 2023 00:00:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1701504055; x=1702108855; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=aq8m7VGcssqI78XGOxjsweJbMFDzrgiYzBdT9vBPUfc=; b=b9XJBbB2aCOw3MMvo6HE1iUlRJYx66nJw6BX2LWUb9ujDwznN2UPV1msIv0WhXU0IU LJq6Wt1IsOFVTYM8HFo6aO58Pxt0zUhHXOUuyJcJRCPyi+lC7veeqTJp9wRr8fUvpGTk acC0AdQU53KuL9WcLKC4G+RRx4Nk0h31InoKyjMt90+sNeAV8mMiRaCNm6GUC7+7V6vc 2vYQHrBxD5P5GPcO2AwBKHOpKn4v7ErvSJ8WAudyjVcwhMQh8DJ9GKqi6zPaggtLNhej lnXImSWy1uZDf6RA8vysbxbjMn0LBQg+pZUqJcKVcHRLWPlp2Z1YwVeGV0ZwHL+RPG4/ 8XFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701504055; x=1702108855; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aq8m7VGcssqI78XGOxjsweJbMFDzrgiYzBdT9vBPUfc=; b=MVC7H5A4EH1EIJPyQwRfZ1l4ZkJEPBIZ16KoNhcleUj/oc4dsDTIjDRKhcyIwGHGwP rulqjbASkQrtMU/ox4f4Oxg+ZxZsOEm2HaKqEEKu3sqki7ZDS8QiR9QmCyUis5udW/lM gZimizIAlBJCut/Ep+xBZ41IAkt6Du9BYOm1mXIhOiV5prbpnExaKf+BQMZI8j3ANrvc VPE8xVqsHR9A3T1Hcmt7CpQAtZAMLdh7jhzZadLmHWxSz25oEpNc6wl7Thn2to4qPXXG LgQFpifIFc27y+EWi3A/RIQTnLS2RP9hF4/5F3JG7JLCgDa+gwrRWipV7FlVfLKO8GUE xzIg== X-Gm-Message-State: AOJu0YyEIrUz9DtBAxBzJ6K1hir91dcYW95wbG22GhogDuCP8bB4hNZv m1fX2dibESzXuTwhb1Tpy3+W3A== X-Google-Smtp-Source: AGHT+IGP5DDkVd5YZHh+wEb+YwuRFEC5HDnv3mv3jAtKS7Ycukej4oyk+1C96W8a54tLTbhwEF0N5A== X-Received: by 2002:a54:458c:0:b0:3b8:b063:8275 with SMTP id z12-20020a54458c000000b003b8b0638275mr992499oib.119.1701504055569; Sat, 02 Dec 2023 00:00:55 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id w24-20020aa78598000000b006cdd1561dcbsm4087492pfn.134.2023.12.02.00.00.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 00:00:55 -0800 (PST) From: Akihiko Odaki Date: Sat, 02 Dec 2023 17:00:28 +0900 Subject: [PATCH 05/14] virtio-net: Implement pci-failover MIME-Version: 1.0 Message-Id: <20231202-sriov-v1-5-32b3570f7bd6@daynix.com> References: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> In-Reply-To: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> To: "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.12.4 Received-SPF: none client-ip=2607:f8b0:4864:20::32f; envelope-from=akihiko.odaki@daynix.com; helo=mail-ot1-x32f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This change removes the parsing of pci-device's failover_pair_id property from virtio-net, and lets pci-device to report an error if an unknown ID is specified for the property. Signed-off-by: Akihiko Odaki --- include/hw/virtio/virtio-net.h | 3 ++- hw/net/virtio-net.c | 24 ++++-------------------- hw/virtio/virtio-net-pci.c | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 55977f01f0..753cab4b32 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -218,7 +218,6 @@ struct VirtIONet { /* primary failover device is hidden*/ bool failover_primary_hidden; bool failover; - DeviceListener primary_listener; QDict *primary_opts; bool primary_opts_from_json; Notifier migration_state; @@ -233,6 +232,8 @@ size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev, unsigned out_num); void virtio_net_set_netclient_name(VirtIONet *n, const char *name, const char *type); +bool virtio_net_set_primary(VirtIONet *n, const QDict *device_opts, + bool from_json, Error **errp); uint64_t virtio_net_supported_guest_offloads(const VirtIONet *n); #endif diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 80c56f0cfc..7def9a1200 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3536,19 +3536,11 @@ static void virtio_net_migration_state_notifier(Notifier *notifier, void *data) virtio_net_handle_migration_primary(n, s); } -static bool failover_hide_primary_device(DeviceListener *listener, - const QDict *device_opts, - bool from_json, - Error **errp) +bool virtio_net_set_primary(VirtIONet *n, const QDict *device_opts, + bool from_json, Error **errp) { - VirtIONet *n = container_of(listener, VirtIONet, primary_listener); - const char *standby_id; - - if (!device_opts) { - return false; - } - - if (!qdict_haskey(device_opts, "failover_pair_id")) { + if (!n->failover) { + error_setg(errp, "failover pair does not support failover"); return false; } @@ -3557,11 +3549,6 @@ static bool failover_hide_primary_device(DeviceListener *listener, return false; } - standby_id = qdict_get_str(device_opts, "failover_pair_id"); - if (g_strcmp0(standby_id, n->netclient_name) != 0) { - return false; - } - /* * The hide helper can be called several times for a given device. * Check there is only one primary for a virtio-net device but @@ -3621,9 +3608,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) } if (n->failover) { - n->primary_listener.hide_device = failover_hide_primary_device; qatomic_set(&n->failover_primary_hidden, true); - device_listener_register(&n->primary_listener); migration_add_notifier(&n->migration_state, virtio_net_migration_state_notifier); n->host_features |= (1ULL << VIRTIO_NET_F_STANDBY); @@ -3789,7 +3774,6 @@ static void virtio_net_device_unrealize(DeviceState *dev) if (n->failover) { qobject_unref(n->primary_opts); - device_listener_unregister(&n->primary_listener); migration_remove_notifier(&n->migration_state); } else { assert(n->primary_opts == NULL); diff --git a/hw/virtio/virtio-net-pci.c b/hw/virtio/virtio-net-pci.c index e03543a70a..e421cd9cea 100644 --- a/hw/virtio/virtio-net-pci.c +++ b/hw/virtio/virtio-net-pci.c @@ -64,10 +64,19 @@ static void virtio_net_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) qdev_realize(vdev, BUS(&vpci_dev->bus), errp); } +static bool virtio_net_pci_set_primary(DeviceState *dev, + const QDict *device_opts, + bool from_json, Error **errp) +{ + return virtio_net_set_primary(&VIRTIO_NET_PCI(dev)->vdev, device_opts, + from_json, errp); +} + static void virtio_net_pci_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + PCIFailoverClass *pfc = PCI_FAILOVER_CLASS(klass); VirtioPCIClass *vpciklass = VIRTIO_PCI_CLASS(klass); k->romfile = "efi-virtio.rom"; @@ -75,6 +84,7 @@ static void virtio_net_pci_class_init(ObjectClass *klass, void *data) k->device_id = PCI_DEVICE_ID_VIRTIO_NET; k->revision = VIRTIO_PCI_ABI_VERSION; k->class_id = PCI_CLASS_NETWORK_ETHERNET; + pfc->set_primary = virtio_net_pci_set_primary; set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); device_class_set_props(dc, virtio_net_properties); vpciklass->realize = virtio_net_pci_realize; @@ -98,6 +108,10 @@ static const VirtioPCIDeviceTypeInfo virtio_net_pci_info = { .instance_size = sizeof(VirtIONetPCI), .instance_init = virtio_net_pci_instance_init, .class_init = virtio_net_pci_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_PCI_FAILOVER }, + { } + }, }; static void virtio_net_pci_register(void) From patchwork Sat Dec 2 08:00:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1870875 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=IL9QxYvh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sj2Vy1QNfz1ySh for ; Sat, 2 Dec 2023 19:03:38 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9KwA-0004Pk-S9; Sat, 02 Dec 2023 03:01:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9Kvv-0004Mh-Kd for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:04 -0500 Received: from mail-il1-x135.google.com ([2607:f8b0:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9Kvt-00051Q-49 for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:03 -0500 Received: by mail-il1-x135.google.com with SMTP id e9e14a558f8ab-35d396ae91fso10315205ab.3 for ; Sat, 02 Dec 2023 00:01:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1701504060; x=1702108860; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=FtHitzkUtA9s8p+8tFrhebFAAv44x+6SLPyGvXp0SkM=; b=IL9QxYvh1BMyCo4CVdKMX8Utf66FpjiMk3MfMPIKTwM5yac0lHBcHwt5fuVo5pBzPV FEVFZ6iMaSRwBk3WgTWSrF6F9MNShlUDwurhTaqBdQEg777OGCrWirg4FV48bY+PIAf+ YPaYqIADTAVnF1h18QieNRXZaHof8Gh4bpEgMrgZNMPCbX52uOeSPhTtQu49lTJWM7aR oo/kJkPnopVSfXCqZfxpPbl2kFNCKCzf/SLuZHlJYa2dccmqc+JPVVl6Y0ahNkmPMNej TsfFuJJ75gwIjHSC8rh2XvnnYTBH/zhUISmgT8zJcaFvXMgn+1O/O1G4S5MuXasg8HW4 mraA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701504060; x=1702108860; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FtHitzkUtA9s8p+8tFrhebFAAv44x+6SLPyGvXp0SkM=; b=CUZ7ha7cgBZiqh496Apr4R/zio3A17NBnqo408wns5ZWeagdBt6/dhLzaYHEapchpl goB9w0dZFa6FEU/3H4j4dW+5eTxwN67o0jAiZDRpk3YnJDBFE+VZdfx9/DCh3x8bczun ZDvWxC6zgJ8CzU/RPtiDIcasgPPAdNA5es6GPm+jqk7ph+R5PJsdkGiHotkAt4Ejsxpm 6yLCIWRB1fXjcWu+Hao1sSdrDFXjiTo4jyZhDL4J1k6VnFKtq3CcdrG43yW/BR4dg2Xh +JSs7ai5pkWqWJUaiz5wBIeneejAtKWn/8IXE1OHpOBeiOGsDO6Icf6Qjir3SZPw2DGz IRpw== X-Gm-Message-State: AOJu0YzXLHQkXNQhylDdf7c/tRl2NQvu0X9jmaHDpYQ9Ahj7/E8Rkn/w 2X2+Cbg2fXELAg2CtI+X/OtDCg== X-Google-Smtp-Source: AGHT+IGcx+erN1zGqRmllSQfRVjs05PCWY8p+aRCrjJ9b9gyZwc4QuuWB8kCWb379lfuRW8j8InqOw== X-Received: by 2002:a05:6e02:154b:b0:35d:59a2:332d with SMTP id j11-20020a056e02154b00b0035d59a2332dmr1098657ilu.49.1701504060175; Sat, 02 Dec 2023 00:01:00 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id q11-20020a170902a3cb00b001a98f844e60sm4587690plb.263.2023.12.02.00.00.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 00:00:59 -0800 (PST) From: Akihiko Odaki Date: Sat, 02 Dec 2023 17:00:29 +0900 Subject: [PATCH 06/14] qdev: Remove DeviceListener::hide_device() MIME-Version: 1.0 Message-Id: <20231202-sriov-v1-6-32b3570f7bd6@daynix.com> References: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> In-Reply-To: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> To: "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.12.4 Received-SPF: none client-ip=2607:f8b0:4864:20::135; envelope-from=akihiko.odaki@daynix.com; helo=mail-il1-x135.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It is no longer used. Signed-off-by: Akihiko Odaki --- include/hw/qdev-core.h | 24 ------------------------ hw/core/qdev.c | 18 ------------------ system/qdev-monitor.c | 9 --------- 3 files changed, 51 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index de221b6f02..9acf6f79c4 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -306,17 +306,6 @@ struct DeviceState { struct DeviceListener { void (*realize)(DeviceListener *listener, DeviceState *dev); void (*unrealize)(DeviceListener *listener, DeviceState *dev); - /* - * This callback is called upon init of the DeviceState and - * informs qdev if a device should be visible or hidden. We can - * hide a failover device depending for example on the device - * opts. - * - * On errors, it returns false and errp is set. Device creation - * should fail in this case. - */ - bool (*hide_device)(DeviceListener *listener, const QDict *device_opts, - bool from_json, Error **errp); QTAILQ_ENTRY(DeviceListener) link; }; @@ -1054,19 +1043,6 @@ static inline void qbus_mark_full(BusState *bus) void device_listener_register(DeviceListener *listener); void device_listener_unregister(DeviceListener *listener); -/** - * qdev_should_hide_device() - check if device should be hidden - * - * @opts: options QDict - * @from_json: true if @opts entries are typed, false for all strings - * @errp: pointer to error object - * - * When a device is added via qdev_device_add() this will be called. - * - * Return: if the device should be added now or not. - */ -bool qdev_should_hide_device(const QDict *opts, bool from_json, Error **errp); - typedef enum MachineInitPhase { /* current_machine is NULL. */ PHASE_NO_MACHINE, diff --git a/hw/core/qdev.c b/hw/core/qdev.c index c98691a90d..e61a147016 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -224,24 +224,6 @@ void device_listener_unregister(DeviceListener *listener) QTAILQ_REMOVE(&device_listeners, listener, link); } -bool qdev_should_hide_device(const QDict *opts, bool from_json, Error **errp) -{ - ERRP_GUARD(); - DeviceListener *listener; - - QTAILQ_FOREACH(listener, &device_listeners, link) { - if (listener->hide_device) { - if (listener->hide_device(listener, opts, from_json, errp)) { - return true; - } else if (*errp) { - return false; - } - } - } - - return false; -} - void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, int required_for_version) { diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index 639beabc5f..42aac94b8c 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -660,15 +660,6 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts, } } - if (qdev_should_hide_device(opts, from_json, errp)) { - if (bus && !qbus_is_hotpluggable(bus)) { - error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name); - } - return NULL; - } else if (*errp) { - return NULL; - } - if (dc->hide) { if (dc->hide(dc, opts, from_json, errp)) { if (bus && !qbus_is_hotpluggable(bus)) { From patchwork Sat Dec 2 08:00:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1870870 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=qUFIsiUp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sj2V73382z23nT for ; Sat, 2 Dec 2023 19:02:55 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9KwF-0004QZ-6s; Sat, 02 Dec 2023 03:01:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9Kw3-0004OM-26 for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:16 -0500 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9Kw0-00052w-9g for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:09 -0500 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-517ab9a4a13so1089614a12.1 for ; Sat, 02 Dec 2023 00:01:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1701504066; x=1702108866; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=QAYyku7fpNHviK5U06HOAT5ynzSeWxO3H+3lWwncrV4=; b=qUFIsiUp6Y3uh4yKdTiP2+gKEWCENTYo5QfR0oeoy1sgLBrGE7Sm/Qq3Sh6HHlNzOd qq0+OLsYsrhrJunmujtbwtcQARzj1FZWHuKg7iJ17X2EMv7ngwibPe4CKbPE19CDFtBW jROgJW1toANYjK60lzF8jV2X33mpGDuORzoFSh1foqdeEu5AGsdfnBM94xSgFTCmUWnZ cYvL2gR3ELqgCkQCeanrhkb+I1KmDaZN0KLPy0hC1OIE1ng6JpnT5OyCC0CpaxJPfKzB rC4Rd484Vw1PSp/T5Nu4b78VcEmv9gPeImjpHmx3Y0iQcRKBwtgPwgaj9yc2suKnnFYD xnrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701504066; x=1702108866; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QAYyku7fpNHviK5U06HOAT5ynzSeWxO3H+3lWwncrV4=; b=OJxJqGFwdLcpz/qywvOLOCQQEbfVaUAwxQivGpvqmKc/UjGo+ZUxdm5cqLS9jEuMYW 1AUvnzyluRUahVleXJPfm3KxTsy0CWgbnsMjeQkCMeoAGb1OBS+H/yTs810STWe9+8/Q crLOv0Ujjn+Wp5Dn/cv1nf9UQZgYKdVyVKV2yniW5QA7xvpfNbYUwItMdQyVcb9BSBEn kYG+Hy2dK3uxqswZZ4RyGauofc5S+x7aBeAACOpuJ00rGMHVLvFkmP68iBh7W4DmHW1j fG91ZznijQT5sPUwqw6wAJIskJjrF1oAoIQBhw9SVCeQ8Z8/Sr7wd7T87DdsVNAIA+KF hgcQ== X-Gm-Message-State: AOJu0YxK4yvafq4FmULXomB9LeKLOO9vUvOm/Rsp034XHI2PG5YsoRp8 k4SJ+rrBsayOwyMThL5nO/DyxQ== X-Google-Smtp-Source: AGHT+IGLq2bSgHxf58UrE0lvYBapyzTh027hMmhqiPI1/drn5SiKHXxA+Se68P/X9gJozXldZFjYkg== X-Received: by 2002:a17:902:f2d2:b0:1d0:6ffd:e2bc with SMTP id h18-20020a170902f2d200b001d06ffde2bcmr672433plc.86.1701504065688; Sat, 02 Dec 2023 00:01:05 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id 13-20020a170902c20d00b001cc2f9fd74csm2386885pll.189.2023.12.02.00.01.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 00:01:05 -0800 (PST) From: Akihiko Odaki Date: Sat, 02 Dec 2023 17:00:30 +0900 Subject: [PATCH 07/14] hw/pci: Add hide() MIME-Version: 1.0 Message-Id: <20231202-sriov-v1-7-32b3570f7bd6@daynix.com> References: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> In-Reply-To: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> To: "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.12.4 Received-SPF: none client-ip=2607:f8b0:4864:20::531; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x531.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org hide() can be implemented to prevent creating a PCI device and get device options. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci_device.h | 2 ++ hw/pci/pci.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index a7bfb192e8..deae29f070 100644 --- a/include/hw/pci/pci_device.h +++ b/include/hw/pci/pci_device.h @@ -29,6 +29,8 @@ DECLARE_CLASS_CHECKERS(PCIFailoverClass, PCI_FAILOVER, TYPE_PCI_FAILOVER) struct PCIDeviceClass { DeviceClass parent_class; + bool (*hide)(PCIDeviceClass *pc, const QDict *device_opts, bool from_json, + Error **errp); void (*realize)(PCIDevice *dev, Error **errp); PCIUnregisterFunc *exit; PCIConfigReadFunc *config_read; diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 3d07246f8e..67d8ae3f61 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2054,11 +2054,19 @@ PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn) static bool pci_qdev_hide(DeviceClass *dc, const QDict *device_opts, bool from_json, Error **errp) { + PCIDeviceClass *pc = PCI_DEVICE_CLASS(dc); const char *standby_id; DeviceState *dev; ObjectClass *class; ObjectClass *interface; + if (pc->hide) { + bool hide = pc->hide(pc, device_opts, from_json, errp); + if (hide || *errp) { + return hide; + } + } + if (!device_opts) { return false; } From patchwork Sat Dec 2 08:00:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1870871 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=xJz+ZuCa; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sj2VB65Xmz1ySh for ; Sat, 2 Dec 2023 19:02:58 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9KwE-0004QJ-GH; Sat, 02 Dec 2023 03:01:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9Kw5-0004OP-N9 for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:16 -0500 Received: from mail-oo1-xc32.google.com ([2607:f8b0:4864:20::c32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9Kw3-00053b-Ue for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:13 -0500 Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-58cdc801f69so1941271eaf.3 for ; Sat, 02 Dec 2023 00:01:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1701504071; x=1702108871; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=a7VZ9FFVn8e4TPvOcMNmTKk40w7o48Xb7nbGO94COXw=; b=xJz+ZuCa55tqFTkw8ogzbbWQ3iDX1dFYe18IInYmdKxWGgrSzXF6mOWeo4DjI4pCt2 AAdHiw09z3beQt5tb6gFYQwKXUsGgWRGfqDMytza+uklqXT7hY2uE3cUIYHB7YHjmtrF lLNR/DX4+YEKt3buS4OikIJ3J7BcuqLefkF3yknzi7ew9jDRqC1HcMe4xQeRmI8TMFTQ M0hixvxFM2PPj1icUi+Auz9E+yUxtC5RlJ+1DioyttIotNYWlFcR0qFLsrVgaRVxoNOJ LlbH7vbUcWhjukGEoZJA7QVYnffcLHjkq6SVCBdF3hgoQBhJMp82M45vVsehtVygELXL NxGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701504071; x=1702108871; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a7VZ9FFVn8e4TPvOcMNmTKk40w7o48Xb7nbGO94COXw=; b=HRbymeFKfrvi1Gc6kHkpeU9QLpTT5Vl04WNDpWzkFkLtg1ZGnwU3qy1jx5cEoqaFba zz1Jwvot3G/CqG+bpinvQ1WHJ1XTf76M6JE/GQQYT1udJc7a20i9bPjhj8WyJzF4cOBl ARQr4vJ95mnC4gnU4fKcgW2XBb27LRfJafOkRcvMt2XVbe9GwcZA2FcjUbe62yg3ie3L fkri0q/af1vE9r4gWWtiA8GEF4fBqywJZk+M6DG8RVCgqBUR0c8IcFcBtQ55FqJZK8jq OISaqP2Dsn8WxRc4erbplM60435zK56ccGMY5Ve1wJQbO8kFCgRERQj+rxdNDA5pEfqI PbgQ== X-Gm-Message-State: AOJu0YwMAEOmVU1inm4cs3B3Yr4YZ+vAi/yI/2NeYGEPHU+pO3HXqYhv 2PmFkGo17gTDNRG5UcgqNelJDw== X-Google-Smtp-Source: AGHT+IGiQMioan8eJJanprvh178TFAmpI+yMoG1D4Aqzx29PRDz9v/Dgha+A6mtWQcABpAdmyh2d6Q== X-Received: by 2002:a05:6358:280e:b0:170:17eb:9c45 with SMTP id k14-20020a056358280e00b0017017eb9c45mr1433305rwb.38.1701504070779; Sat, 02 Dec 2023 00:01:10 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id ij9-20020a170902ab4900b001cfd2c5ae6fsm2887482plb.25.2023.12.02.00.01.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 00:01:10 -0800 (PST) From: Akihiko Odaki Date: Sat, 02 Dec 2023 17:00:31 +0900 Subject: [PATCH 08/14] qdev: Add qdev_device_new_from_qdict() MIME-Version: 1.0 Message-Id: <20231202-sriov-v1-8-32b3570f7bd6@daynix.com> References: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> In-Reply-To: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> To: "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.12.4 Received-SPF: none client-ip=2607:f8b0:4864:20::c32; envelope-from=akihiko.odaki@daynix.com; helo=mail-oo1-xc32.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org qdev_device_new_from_qdict() can be used to create a device from QDict without realizing it. Signed-off-by: Akihiko Odaki --- include/monitor/qdev.h | 2 ++ system/qdev-monitor.c | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index 1d57bf6577..013108a7dd 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -11,6 +11,8 @@ int qdev_device_help(QemuOpts *opts); DeviceState *qdev_device_add(QemuOpts *opts, Error **errp); DeviceState *qdev_device_add_from_qdict(const QDict *opts, bool from_json, Error **errp); +DeviceState *qdev_device_new_from_qdict(const QDict *opts, bool from_json, + BusState **busp, Error **errp); /** * qdev_set_id: parent the device and set its id if provided. diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index 42aac94b8c..028b97f2b5 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -618,6 +618,25 @@ const char *qdev_set_id(DeviceState *dev, char *id, Error **errp) DeviceState *qdev_device_add_from_qdict(const QDict *opts, bool from_json, Error **errp) +{ + DeviceState *dev; + BusState *bus; + + dev = qdev_device_new_from_qdict(opts, from_json, &bus, errp); + if (!dev) { + return NULL; + } + + if (!qdev_realize(dev, bus, errp)) { + object_unparent(OBJECT(dev)); + object_unref(OBJECT(dev)); + } + + return dev; +} + +DeviceState *qdev_device_new_from_qdict(const QDict *opts, bool from_json, + BusState **busp, Error **errp) { ERRP_GUARD(); DeviceClass *dc; @@ -720,9 +739,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts, goto err_del_dev; } - if (!qdev_realize(dev, bus, errp)) { - goto err_del_dev; - } + *busp = bus; return dev; err_del_dev: From patchwork Sat Dec 2 08:00:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1870867 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=j1jSt+C1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sj2T22f2yz1ySh for ; Sat, 2 Dec 2023 19:01:58 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9KwH-0004Qi-IP; Sat, 02 Dec 2023 03:01:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9KwA-0004Pg-Nj for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:18 -0500 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9Kw9-000564-8p for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:18 -0500 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3b8b00e44ceso492125b6e.2 for ; Sat, 02 Dec 2023 00:01:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1701504076; x=1702108876; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=TZILP9ZpP2XzCcOVK4GZRYCbHpA7EhX2b/3i1rkHZjc=; b=j1jSt+C1xAPPBor8m6JoLGjIGoJSVoVmT/GAADhXc6eK9jOrrH4M9dzS7oNepJwFcB vV8mxO2b6t7yMsbBgG/KZWnduaY6ZY5nf7s0OZByxSagQkLHtU69MP5nUC41kdUt86U9 9AFBCxowYzWWKQPIM/4Imt/H4R80c6thjWfdqVgBsI56Wpi0yECYfwdgw2IQuws/yKMI ED3xkitafNde0uDObS9CAcBy8jYcYJiAzGhzCvnXL31Qwitvt0wwx92JFd/1PLngwySt q1d50xcO1FhmAQbmWwbkrgaropsGrHvdxxwRwWL369VwHfwFqHV1B104E4sXojG4iYYZ Jk6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701504076; x=1702108876; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TZILP9ZpP2XzCcOVK4GZRYCbHpA7EhX2b/3i1rkHZjc=; b=AapdpBpMfq+dMk7HhLPuC4NxhfLz282DGZr5SC3OLgjEwLPnmL3ltp0rzg5TSf0gOJ vm1D4h0GvZVbItPsQ6wA7YBJWpPJ9AzazSuv8z13KH+ECwNVS5LP9oSQX2AI/iHpwOpU X+5E55ZBR6jNs5aAACX8Pm1ioJhctbZBRpxZa//bcl9CRHOuSg8bktZmwWHV+GMUK3tS qeKNFBVBRg+P/Hy7CnyWOVK4sg8rdGE38PuOqECq1tsQe9t7w6H/dHSA2L2xf5MM6Iv5 jSZ/odNnbpid5B4yQd1rTO1OBl+/FZnmUPwI8xmaIO/PHFfDZHftYMARdGIoNqjVYJgh vh5w== X-Gm-Message-State: AOJu0YzWDmZRB9+ed+8rOCq3SY4Gp4DvzrWHlQ28qlFHV46ge42616W6 9qRpQZlUuoDPD+MMCtvHniIeLg== X-Google-Smtp-Source: AGHT+IGcqEGLFmwEespOAWOTPKGgwXLLsPfsj/OudGsQRbK7uajSv0WBOCUjS3hWBjUErdiNoq3nlQ== X-Received: by 2002:a05:6808:6489:b0:3b8:b204:b32b with SMTP id fh9-20020a056808648900b003b8b204b32bmr724560oib.10.1701504076000; Sat, 02 Dec 2023 00:01:16 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id ei11-20020a17090ae54b00b002864f7464a0sm3094593pjb.31.2023.12.02.00.01.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 00:01:15 -0800 (PST) From: Akihiko Odaki Date: Sat, 02 Dec 2023 17:00:32 +0900 Subject: [PATCH 09/14] hw/pci: Do not add ROM BAR for SR-IOV VF MIME-Version: 1.0 Message-Id: <20231202-sriov-v1-9-32b3570f7bd6@daynix.com> References: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> In-Reply-To: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> To: "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.12.4 Received-SPF: none client-ip=2607:f8b0:4864:20::230; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x230.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org A SR-IOV VF cannot have a ROM BAR. Co-developed-by: Yui Washizu Signed-off-by: Akihiko Odaki --- hw/pci/pci.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 67d8ae3f61..54d9e0f4cf 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2419,6 +2419,14 @@ static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom, return; } + if (pci_is_vf(pdev)) { + if (pdev->rom_bar && pdev->rom_bar != -1) { + error_setg(errp, "ROM BAR cannot be enabled for SR-IOV VF"); + } + + return; + } + if (load_file || pdev->romsize == -1) { path = qemu_find_file(QEMU_FILE_TYPE_BIOS, pdev->romfile); if (path == NULL) { From patchwork Sat Dec 2 08:00:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1870866 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=qzztkFsM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sj2Sy2k7Dz1ySh for ; Sat, 2 Dec 2023 19:01:54 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9KwO-0004Uw-RS; Sat, 02 Dec 2023 03:01:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9KwK-0004T1-8s for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:28 -0500 Received: from mail-oo1-xc2f.google.com ([2607:f8b0:4864:20::c2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9KwH-000570-R0 for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:28 -0500 Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-58dd3528497so1797595eaf.3 for ; Sat, 02 Dec 2023 00:01:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1701504080; x=1702108880; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=EJKlP980j1vymql3ZbAFDs9X/sipZ2vUntUb8CsD+hw=; b=qzztkFsMiZXicgKfZAErMlb45/Ek14P59Fk0lqXcPsmP8bJ5YQgL49mOk3e/UzbeeA PRivRHWsdaPGPsnPlltX30aVl2JSX9z7xA95aA0Qj8PtcdDQXKM82XdGqvS5GzXUhTkr k5w0PIK/VotXO8qRm3ZvoMK/pq3sS7yU+ZbpJdZTEnt8BM/lK5sMScC5MkNhHoeTZCa3 /U4dGp7ZKIfTTEbeBr49FXPdA2IcHSA625Oo44kAk8iF4+MecIm3F1tEsAmFILAGJdjf 8h3UEMJTu5uh7+rv7A2/vkulpEzGMa0KAgS2ma1ttJJFZ4NWQeZc+1Xpby70R8VaNzkc 4VTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701504080; x=1702108880; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EJKlP980j1vymql3ZbAFDs9X/sipZ2vUntUb8CsD+hw=; b=YYIBSFGZzDRSDn+rowFLmwhP6772DzPHS+h527SaAmtJ4f/YN9n+E0xXEWfuyWghcB 21opVpuRMqFyoEPqzl2upA5k5YCYzxbHyRk6/khLhe4wmZ/Z/zorMuuJfWLmUtIq7iSu htzTO2OVJk7Q0dXpmexUdbEU4kQUieGc7HTr4vLSHQtNujMHpKVX7gpri89eCfU3CUKu Nv3yN8UD/abhIYiurVcVBsXPprbX8rgB09JDJjviAmgQwVbAru/azwFR42kdcQtB1RkJ Vdp3e0QMPGDEy5DHG4nC1q/nDWSgm3AN6LryzqbQCSAYkCtlPaqN3zP2lhN9NlyBL2kU 7QhQ== X-Gm-Message-State: AOJu0Yz0CtPGQbPdtiVJmeKCyxgsSApD3XyMX0ApWgLRY2ee87ernfGa c8IN/mBaRPMM/BT3vLgLnLTXvw== X-Google-Smtp-Source: AGHT+IGl1xSaOUVIStAYcsjT9z1wwbZHHdfzfiQI1mWTWFnzs+CqB5eJ7dLu+B0vvqwtuVmVo5I4XA== X-Received: by 2002:a05:6358:524d:b0:170:17ea:f4de with SMTP id c13-20020a056358524d00b0017017eaf4demr1029361rwa.43.1701504080606; Sat, 02 Dec 2023 00:01:20 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id h2-20020a170902f7c200b001d0695106c4sm1260063plw.105.2023.12.02.00.01.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 00:01:20 -0800 (PST) From: Akihiko Odaki Date: Sat, 02 Dec 2023 17:00:33 +0900 Subject: [PATCH 10/14] msix: Call pcie_sriov_vf_register_bar() for SR-IOV VF MIME-Version: 1.0 Message-Id: <20231202-sriov-v1-10-32b3570f7bd6@daynix.com> References: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> In-Reply-To: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> To: "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.12.4 Received-SPF: none client-ip=2607:f8b0:4864:20::c2f; envelope-from=akihiko.odaki@daynix.com; helo=mail-oo1-xc2f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org A SR-IOV VF needs to use pcie_sriov_vf_register_bar() instead of pci_register_bar(). Co-developed-by: Yui Washizu Signed-off-by: Akihiko Odaki --- hw/pci/msix.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/pci/msix.c b/hw/pci/msix.c index ab8869d9d0..3b94ce389f 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -421,8 +421,12 @@ int msix_init_exclusive_bar(PCIDevice *dev, unsigned short nentries, return ret; } - pci_register_bar(dev, bar_nr, PCI_BASE_ADDRESS_SPACE_MEMORY, - &dev->msix_exclusive_bar); + if (pci_is_vf(dev)) { + pcie_sriov_vf_register_bar(dev, bar_nr, &dev->msix_exclusive_bar); + } else { + pci_register_bar(dev, bar_nr, PCI_BASE_ADDRESS_SPACE_MEMORY, + &dev->msix_exclusive_bar); + } return 0; } From patchwork Sat Dec 2 08:00:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1870874 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=qzwPYb9B; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sj2Vt56PFz1ySh for ; Sat, 2 Dec 2023 19:03:34 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9KwQ-0004VB-Nq; Sat, 02 Dec 2023 03:01:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9KwL-0004UF-Hc for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:30 -0500 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9KwJ-00057e-5T for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:29 -0500 Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-58ce8513da1so1835970eaf.2 for ; Sat, 02 Dec 2023 00:01:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1701504085; x=1702108885; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=55rVeQPmJn6G2IWu8r2Sq8kbSZfBOqAtZltJfVWEVs0=; b=qzwPYb9BTPoTqb6wYvTx/4qLj6VJRTnn6H0Q7pww7rRWOSG2UvaomYs1h/XGWyHpqD yUIWBHi8pWUXbA8tPkXUI+0vROki2JAXMeJ2Ft3j7g2VW3j28Gu4tNRMm0a8T1WNaG+P 1R0jRFX+AqCW5l5z9h5iIdWyOWbV26sZSxnLv/NDLOQ0UbQm5mjkJn5Y06WFbEUwr5+a bNel8Zoi0ER1ewXGSRpjjvuACj1tjEzUhVqSJdz2HoOSNQCD/fwyBei8CaQfFxdHGPx0 5XtfcgHkVbcOIkfO+cgFk6zd5NGGN43xovObMVKww90U7cC7QZ99R5fI+CzajYqjWiv7 L30A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701504085; x=1702108885; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=55rVeQPmJn6G2IWu8r2Sq8kbSZfBOqAtZltJfVWEVs0=; b=vy3CAF3Vt/glrax1uGp0KD7r2djv1ijaXxIjEJI/WrHxYR5jsllKXXvihzOD02qzRP KrHD857jV1ljurOMGV5UYR4wPDIJ7WXEDsb0e7dq7dh6cXCj0JyvPydgEOCImr+6632C 908ZtMNQ05nNsWucIlCGg54udKE9s8w/x+4RYGptCwDjPaQnWA3UwOJvCSdrp5+4bJIq hgGTAKDd9gKoLDOz7YZS4o9Ebib+nwT5ZQo4nHNxwDd1+Nhxj9NY+oCO3LfjkOvO3p1U wsJmwWgmmRBEz9CkI3mdaRXJieszIvhsASbsFW9dX0HWUvRWS3nwQmEFKRwJfNcErjeT M4DA== X-Gm-Message-State: AOJu0Ywg6WeJQAVXn9ItIpRU2PxfJfG3inKTa1gZX+1Ch3+3PIoWh/30 mmBGdRAc/rcxhZQo25Oi24/N2g== X-Google-Smtp-Source: AGHT+IEoiuhkeMVLRcKxzu5GZmWfQ/RKqbs4AZIypGvdDcqylu9Z2YiV7WOHJxeaJ1Zw43ZYQoo00A== X-Received: by 2002:a05:6358:4285:b0:16d:d0e7:e7ee with SMTP id s5-20020a056358428500b0016dd0e7e7eemr1152106rwc.28.1701504085334; Sat, 02 Dec 2023 00:01:25 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id ep13-20020a17090ae64d00b0028672722301sm579417pjb.40.2023.12.02.00.01.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 00:01:24 -0800 (PST) From: Akihiko Odaki Date: Sat, 02 Dec 2023 17:00:34 +0900 Subject: [PATCH 11/14] pcie_sriov: Release VFs failed to realize MIME-Version: 1.0 Message-Id: <20231202-sriov-v1-11-32b3570f7bd6@daynix.com> References: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> In-Reply-To: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> To: "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.12.4 Received-SPF: none client-ip=2607:f8b0:4864:20::c2b; envelope-from=akihiko.odaki@daynix.com; helo=mail-oo1-xc2b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Release VFs failed to realize just as we do in unregister_vfs(). Signed-off-by: Akihiko Odaki --- hw/pci/pcie_sriov.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index 5ef8950940..3ec786d341 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -153,6 +153,8 @@ static PCIDevice *register_vf(PCIDevice *pf, int devfn, const char *name, qdev_realize(&dev->qdev, &bus->qbus, &local_err); if (local_err) { error_report_err(local_err); + object_unparent(OBJECT(dev)); + object_unref(dev); return NULL; } From patchwork Sat Dec 2 08:00:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1870876 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=bazWa6Uh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sj2WC49Zqz1ySh for ; Sat, 2 Dec 2023 19:03:51 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9KwW-0004WU-Pq; Sat, 02 Dec 2023 03:01:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9KwP-0004V2-OV for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:34 -0500 Received: from mail-oo1-xc2a.google.com ([2607:f8b0:4864:20::c2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9KwN-000595-Qg for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:33 -0500 Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-58a42c3cbb8so1837189eaf.3 for ; Sat, 02 Dec 2023 00:01:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1701504090; x=1702108890; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=z8QsyW6l5I9S2QTemJwIB3U4zf0/ves6SUfycgaph7Q=; b=bazWa6UhHLvTNPsLsD19ua9kmxrpyfR/c/otbKY32PoLI2k4mJrT3C4K++0qduxTPr fGDjPZWLVxQoB3AfL7XjDIe3xeYOJ9YT3bi5UbDsNMlRQ16fJcqdnpfvlG88tn8iBeqC OuzWKdaslLDn1dfJZY18ZEVOTScvbgIh4ckKX6qIrM5V7iRChRIewVAzDW42/fCpIJd1 QOexdSn6yPqBRYyG3TXzszTzjWV89/HIJVS7M+m0ylCZdkyjyrsV1W4APrlUkgJHq0v/ AfkCyVQLylUMSIVSCalsCLpaWj8Z6GVQ0l0lGZvRus29jjFaiQKlhTGkpLTWn0/sWMEK 1oHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701504090; x=1702108890; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z8QsyW6l5I9S2QTemJwIB3U4zf0/ves6SUfycgaph7Q=; b=khPYp0avCClM8qg/vGJRPUdFQtSisfDbDg7WaSWqDwQnVKyStZEIKiU4/tDu6TCxUS cJP57W5Xf9hHg3yrydHO3GGrP19pht2NR8Unj6VZbK4oAaP+3wGCMjv6Vz5CzvLilda2 tg06pM85ePqWQFAxI/dDjqM66TYJPH0zFyxxm3btLZ3s+nncc5hjs9mDzHa6CdnUjS+z nI5sBKNRVeDjRpsUOx/29ixPS2faH4gFJdtKBJ0uOffF0fcUqx38CiCv7REjU3Smykn+ 8Vpy0lR+orOeHJQJGIaUaYczrOIpJcogC01/p+KZqtgIDle3MOOUXy7VaqQC3tzjWSej oCpw== X-Gm-Message-State: AOJu0YziBzMbEL6BP/RMF979oVBagrxXY0hgIFc5K3UcGnSozf+6xgsD P8JXFjBJkGsnoCSuuQMKSXpTtg== X-Google-Smtp-Source: AGHT+IFQqExgZnzHND5ybjcxum/RDBReygnwa3pDDqzLP4XmnLTKfBaKi9+5GMc7Jaznp2nkPiE4Fw== X-Received: by 2002:a05:6358:f59:b0:170:17eb:2056 with SMTP id c25-20020a0563580f5900b0017017eb2056mr594681rwj.63.1701504090616; Sat, 02 Dec 2023 00:01:30 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id b11-20020a1709027e0b00b001bbb7af4963sm4633318plm.68.2023.12.02.00.01.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 00:01:30 -0800 (PST) From: Akihiko Odaki Date: Sat, 02 Dec 2023 17:00:35 +0900 Subject: [PATCH 12/14] pcie_sriov: Allow to specify VF device options MIME-Version: 1.0 Message-Id: <20231202-sriov-v1-12-32b3570f7bd6@daynix.com> References: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> In-Reply-To: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> To: "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.12.4 Received-SPF: none client-ip=2607:f8b0:4864:20::c2a; envelope-from=akihiko.odaki@daynix.com; helo=mail-oo1-xc2a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Specifying VF device options will be useful to create VFs based on conventional device emulation code which have user-configurable options. Signed-off-by: Akihiko Odaki --- docs/pcie_sriov.txt | 2 +- include/hw/pci/pcie_sriov.h | 13 ++++++-- hw/net/igb.c | 2 +- hw/nvme/ctrl.c | 2 +- hw/pci/pcie_sriov.c | 73 ++++++++++++++++++++++++++++++++++++--------- 5 files changed, 72 insertions(+), 20 deletions(-) diff --git a/docs/pcie_sriov.txt b/docs/pcie_sriov.txt index a47aad0bfa..dc70b40ae2 100644 --- a/docs/pcie_sriov.txt +++ b/docs/pcie_sriov.txt @@ -52,7 +52,7 @@ setting up a BAR for a VF. ... /* Add and initialize the SR/IOV capability */ - pcie_sriov_pf_init(d, 0x200, "your_virtual_dev", + pcie_sriov_pf_init(d, 0x200, "your_virtual_dev", NULL, vf_devid, initial_vfs, total_vfs, fun_offset, stride); diff --git a/include/hw/pci/pcie_sriov.h b/include/hw/pci/pcie_sriov.h index 095fb0c9ed..aa3d81fa44 100644 --- a/include/hw/pci/pcie_sriov.h +++ b/include/hw/pci/pcie_sriov.h @@ -15,10 +15,16 @@ #include "hw/pci/pci.h" +typedef struct PCIESriovVFOpts { + QDict *device_opts; + bool from_json; +} PCIESriovVFOpts; + struct PCIESriovPF { uint16_t num_vfs; /* Number of virtual functions created */ uint8_t vf_bar_type[PCI_NUM_REGIONS]; /* Store type for each VF bar */ const char *vfname; /* Reference to the device type used for the VFs */ + PCIESriovVFOpts *vfopts; /* Poiner to an array of VF options */ PCIDevice **vf; /* Pointer to an array of num_vfs VF devices */ }; @@ -28,9 +34,10 @@ struct PCIESriovVF { }; void pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, - const char *vfname, uint16_t vf_dev_id, - uint16_t init_vfs, uint16_t total_vfs, - uint16_t vf_offset, uint16_t vf_stride); + const char *vfname, PCIESriovVFOpts *vfopts, + uint16_t vf_dev_id, uint16_t init_vfs, + uint16_t total_vfs, uint16_t vf_offset, + uint16_t vf_stride); void pcie_sriov_pf_exit(PCIDevice *dev); /* Set up a VF bar in the SR/IOV bar area */ diff --git a/hw/net/igb.c b/hw/net/igb.c index 8089acfea4..8168d401cb 100644 --- a/hw/net/igb.c +++ b/hw/net/igb.c @@ -447,7 +447,7 @@ static void igb_pci_realize(PCIDevice *pci_dev, Error **errp) pcie_ari_init(pci_dev, 0x150); - pcie_sriov_pf_init(pci_dev, IGB_CAP_SRIOV_OFFSET, TYPE_IGBVF, + pcie_sriov_pf_init(pci_dev, IGB_CAP_SRIOV_OFFSET, TYPE_IGBVF, NULL, IGB_82576_VF_DEV_ID, IGB_MAX_VF_FUNCTIONS, IGB_MAX_VF_FUNCTIONS, IGB_VF_OFFSET, IGB_VF_STRIDE); diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index f026245d1e..91bbccb49f 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -8040,7 +8040,7 @@ static void nvme_init_sriov(NvmeCtrl *n, PCIDevice *pci_dev, uint16_t offset) le16_to_cpu(cap->vifrsm), NULL, NULL); - pcie_sriov_pf_init(pci_dev, offset, "nvme", vf_dev_id, + pcie_sriov_pf_init(pci_dev, offset, "nvme", NULL, vf_dev_id, n->params.sriov_max_vfs, n->params.sriov_max_vfs, NVME_VF_OFFSET, NVME_VF_STRIDE); diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index 3ec786d341..4e73559dc1 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -15,8 +15,11 @@ #include "hw/pci/pcie.h" #include "hw/pci/pci_bus.h" #include "hw/qdev-properties.h" +#include "monitor/qdev.h" #include "qemu/error-report.h" #include "qemu/range.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qobject.h" #include "qapi/error.h" #include "trace.h" @@ -25,9 +28,10 @@ static PCIDevice *register_vf(PCIDevice *pf, int devfn, static void unregister_vfs(PCIDevice *dev); void pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, - const char *vfname, uint16_t vf_dev_id, - uint16_t init_vfs, uint16_t total_vfs, - uint16_t vf_offset, uint16_t vf_stride) + const char *vfname, PCIESriovVFOpts *vfopts, + uint16_t vf_dev_id, uint16_t init_vfs, + uint16_t total_vfs, uint16_t vf_offset, + uint16_t vf_stride) { uint8_t *cfg = dev->config + offset; uint8_t *wmask; @@ -37,6 +41,7 @@ void pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, dev->exp.sriov_cap = offset; dev->exp.sriov_pf.num_vfs = 0; dev->exp.sriov_pf.vfname = g_strdup(vfname); + dev->exp.sriov_pf.vfopts = vfopts; dev->exp.sriov_pf.vf = NULL; pci_set_word(cfg + PCI_SRIOV_VF_OFFSET, vf_offset); @@ -76,6 +81,16 @@ void pcie_sriov_pf_exit(PCIDevice *dev) unregister_vfs(dev); g_free((char *)dev->exp.sriov_pf.vfname); dev->exp.sriov_pf.vfname = NULL; + + if (dev->exp.sriov_pf.vfopts) { + uint8_t *cfg = dev->config + dev->exp.sriov_cap; + + for (uint16_t i = 0; i < pci_get_word(cfg + PCI_SRIOV_TOTAL_VF); i++) { + qobject_unref(dev->exp.sriov_pf.vfopts[i].device_opts); + } + + g_free(dev->exp.sriov_pf.vfopts); + } } void pcie_sriov_pf_init_vf_bar(PCIDevice *dev, int region_num, @@ -144,25 +159,50 @@ void pcie_sriov_vf_register_bar(PCIDevice *dev, int region_num, static PCIDevice *register_vf(PCIDevice *pf, int devfn, const char *name, uint16_t vf_num) { - PCIDevice *dev = pci_new(devfn, name); - dev->exp.sriov_vf.pf = pf; - dev->exp.sriov_vf.vf_number = vf_num; - PCIBus *bus = pci_get_bus(pf); + PCIDevice *pci_dev; + BusState *bus = qdev_get_parent_bus(DEVICE(pf)); Error *local_err = NULL; - qdev_realize(&dev->qdev, &bus->qbus, &local_err); + if (pf->exp.sriov_pf.vfopts) { + BusState *local_bus; + PCIESriovVFOpts *vfopts = pf->exp.sriov_pf.vfopts + vf_num; + DeviceState *dev = qdev_device_new_from_qdict(vfopts->device_opts, + vfopts->from_json, + &local_bus, &local_err); + if (!dev) { + error_report_err(local_err); + return NULL; + } + + pci_dev = PCI_DEVICE(dev); + + if (bus != local_bus) { + error_report("unexpected SR-IOV VF parent bus"); + goto fail; + } + } else { + pci_dev = pci_new(devfn, name); + } + + pci_dev->exp.sriov_vf.pf = pf; + pci_dev->exp.sriov_vf.vf_number = vf_num; + + qdev_realize(&pci_dev->qdev, bus, &local_err); if (local_err) { error_report_err(local_err); - object_unparent(OBJECT(dev)); - object_unref(dev); - return NULL; + goto fail; } /* set vid/did according to sr/iov spec - they are not used */ - pci_config_set_vendor_id(dev->config, 0xffff); - pci_config_set_device_id(dev->config, 0xffff); + pci_config_set_vendor_id(pci_dev->config, 0xffff); + pci_config_set_device_id(pci_dev->config, 0xffff); - return dev; + return pci_dev; + +fail: + object_unparent(OBJECT(pci_dev)); + object_unref(pci_dev); + return NULL; } static void register_vfs(PCIDevice *dev) @@ -170,6 +210,8 @@ static void register_vfs(PCIDevice *dev) uint16_t num_vfs; uint16_t i; uint16_t sriov_cap = dev->exp.sriov_cap; + uint16_t total_vfs = + pci_get_word(dev->config + sriov_cap + PCI_SRIOV_TOTAL_VF); uint16_t vf_offset = pci_get_word(dev->config + sriov_cap + PCI_SRIOV_VF_OFFSET); uint16_t vf_stride = @@ -178,6 +220,9 @@ static void register_vfs(PCIDevice *dev) assert(sriov_cap > 0); num_vfs = pci_get_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF); + if (num_vfs > total_vfs) { + return; + } dev->exp.sriov_pf.vf = g_new(PCIDevice *, num_vfs); assert(dev->exp.sriov_pf.vf); From patchwork Sat Dec 2 08:00:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1870872 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=eVmDDLGA; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sj2VS0hGwz1ySh for ; Sat, 2 Dec 2023 19:03:12 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9Kwa-0004jL-Kd; Sat, 02 Dec 2023 03:01:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9KwX-0004dN-GD for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:41 -0500 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9KwS-00059x-CG for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:39 -0500 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3b83ed78a91so1177676b6e.1 for ; Sat, 02 Dec 2023 00:01:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1701504095; x=1702108895; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=JguH82PUwVfOszRffb4OflLmTzbPcjtVzvpIUdtjwWc=; b=eVmDDLGARMrHn/1ldZHBAHgScEgto6l0r52QLp28k6mhzVbZTwbI74Mph4tNM9mCXq /l+WaKTPQ+U4E3bTc2raSWY/fPk+qLpcfzkyFOriQpa30eSVzraGWrvthOPZUcDog0uP YoJ/qRorIIh8aPuDvW1ML0IpzSYF0/kwpw1+3SwsBhyk38P2Okk0UUS2cNhaSaJF7kOX ew4YjIjbJeg5h8nAkWYN3dDOWZ1CLUAeSdLcXwzacAEHgHE3DhPuTdPF7KoOzkr7hW5y 1z4ZnpJ+JBdaLgJghQdna4F6R1I35HSqnhP06XhYw3GDh7OfXbZlkR2Ru2qltWbQmnkV j1tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701504095; x=1702108895; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JguH82PUwVfOszRffb4OflLmTzbPcjtVzvpIUdtjwWc=; b=pAuwByI9MCexeplqgiRDJk6zhVwTzeIUwEPlqycL1qVGLQpuQe2dJQK9wq5ghJOM4y uCZSGsu/ekFtlNgw6pt5i3oH8zR0rZJBhKbcbTfztN0GHdIgSyHd5Zvf//dqlzy20B2h rEgiT4pQDn9GxwEAsfAG0eGA5Ex6WFCMaWTUA/tBCOCjEt5Nz1DNbJn+kGkhrh+7ylQd pubQewoVtfiHlMsfef83hMMWFyfANsx9fg+dcKOapWfJkQVwMmslVRFb/uaRXjQMYKeS dyxZ7+UPf7TaXkx/a1mxjevWJJBdIcOmaTlYzApUIczxtcR7oZD5691AQbqnS09mNcvV enJA== X-Gm-Message-State: AOJu0Yxy7xJA+Djq6Evmd4kHVVS+2BQvNLklHYm9J1R9PXAe9qhRPnYA N9I4TQvzii6VVBwLAe33FJCw1w== X-Google-Smtp-Source: AGHT+IER8dKbWh85bPXvAiPMWgYhKUFZ5XJbzQsCXrPHejUi4BL9e1YK97ssYTvVF7way7J6tcJ1dA== X-Received: by 2002:a05:6808:30a7:b0:3b8:6057:b087 with SMTP id bl39-20020a05680830a700b003b86057b087mr1508948oib.9.1701504095289; Sat, 02 Dec 2023 00:01:35 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id d16-20020a170902ced000b001d076ebf328sm508543plg.8.2023.12.02.00.01.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 00:01:35 -0800 (PST) From: Akihiko Odaki Date: Sat, 02 Dec 2023 17:00:36 +0900 Subject: [PATCH 13/14] virtio-pci: add SR-IOV capability MIME-Version: 1.0 Message-Id: <20231202-sriov-v1-13-32b3570f7bd6@daynix.com> References: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> In-Reply-To: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> To: "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.12.4 Received-SPF: none client-ip=2607:f8b0:4864:20::22f; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x22f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This enables SR-IOV emulation on virtio-pci devices. It introduces a property 'sriov-pf' to state that the device will be a VF, and it will be paired with the PF identified with the property. Currently this feature needs to be explicitly enabled by a subclass. Co-developed-by: Yui Washizu Signed-off-by: Akihiko Odaki --- include/hw/virtio/virtio-pci.h | 2 + hw/virtio/virtio-pci.c | 208 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 201 insertions(+), 9 deletions(-) diff --git a/include/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h index 5a3f182f99..0cd781ea98 100644 --- a/include/hw/virtio/virtio-pci.h +++ b/include/hw/virtio/virtio-pci.h @@ -105,6 +105,7 @@ struct VirtioPCIClass { PCIDeviceClass parent_class; DeviceRealize parent_dc_realize; void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp); + bool sriov_supported; }; typedef struct VirtIOPCIRegion { @@ -159,6 +160,7 @@ struct VirtIOPCIProxy { uint32_t gfselect; uint32_t guest_features[2]; VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX]; + GArray *sriov_vfs; VirtIOIRQFD *vector_irqfd; int nvqs_with_notifiers; diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 205dbf24fb..3f1b3db9b7 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -26,6 +26,9 @@ #include "hw/pci/pci.h" #include "hw/pci/pci_bus.h" #include "hw/qdev-properties.h" +#include "monitor/qdev.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qobject.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/log.h" @@ -49,6 +52,18 @@ * configuration space */ #define VIRTIO_PCI_CONFIG_SIZE(dev) VIRTIO_PCI_CONFIG_OFF(msix_enabled(dev)) +typedef struct VirtIOPCISriovVF { + ObjectClass *class; + PCIESriovVFOpts opts; + struct { + pcibus_t size; + uint8_t type; + } io_regions[PCI_NUM_REGIONS]; + uint16_t devfn; +} VirtIOPCISriovVF; + +static GHashTable *sriov_vfs; + static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size, VirtIOPCIProxy *dev); static void virtio_pci_reset(DeviceState *qdev); @@ -1912,6 +1927,18 @@ static void virtio_pci_pre_plugged(DeviceState *d, Error **errp) VirtIOPCIProxy *proxy = VIRTIO_PCI(d); VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); + if (d->id) { + if (pci_is_vf(&proxy->pci_dev)) { + if (g_hash_table_contains(sriov_vfs, d->id)) { + error_setg(errp, "a function cannot be SR-IOV PF and VF at the same time"); + return; + } + } else { + proxy->sriov_vfs = g_hash_table_lookup(sriov_vfs, d->id); + virtio_add_feature(&vdev->host_features, VIRTIO_F_SR_IOV); + } + } + if (virtio_pci_modern(proxy)) { virtio_add_feature(&vdev->host_features, VIRTIO_F_VERSION_1); } @@ -1919,10 +1946,26 @@ static void virtio_pci_pre_plugged(DeviceState *d, Error **errp) virtio_add_feature(&vdev->host_features, VIRTIO_F_BAD_FEATURE); } +static gint virtio_pci_sriov_vfs_compare(gconstpointer a, gconstpointer b) +{ + return ((VirtIOPCISriovVF *)a)->devfn - ((VirtIOPCISriovVF *)b)->devfn; +} + +static void virtio_pci_register_bar(VirtIOPCIProxy *proxy, int region_num, + uint8_t type, MemoryRegion *memory) +{ + if (pci_is_vf(&proxy->pci_dev)) { + pcie_sriov_vf_register_bar(&proxy->pci_dev, region_num, memory); + } else { + pci_register_bar(&proxy->pci_dev, region_num, type, memory); + } +} + /* This is called by virtio-bus just after the device is plugged. */ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) { VirtIOPCIProxy *proxy = VIRTIO_PCI(d); + VirtioPCIClass *k = VIRTIO_PCI_GET_CLASS(d); VirtioBusState *bus = &proxy->bus; bool legacy = virtio_pci_legacy(proxy); bool modern; @@ -2026,18 +2069,18 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) memory_region_init(&proxy->io_bar, OBJECT(proxy), "virtio-pci-io", 0x4); - pci_register_bar(&proxy->pci_dev, proxy->modern_io_bar_idx, - PCI_BASE_ADDRESS_SPACE_IO, &proxy->io_bar); + virtio_pci_register_bar(proxy, proxy->modern_io_bar_idx, + PCI_BASE_ADDRESS_SPACE_IO, &proxy->io_bar); virtio_pci_modern_io_region_map(proxy, &proxy->notify_pio, ¬ify_pio.cap); } - pci_register_bar(&proxy->pci_dev, proxy->modern_mem_bar_idx, - PCI_BASE_ADDRESS_SPACE_MEMORY | - PCI_BASE_ADDRESS_MEM_PREFETCH | - PCI_BASE_ADDRESS_MEM_TYPE_64, - &proxy->modern_bar); + virtio_pci_register_bar(proxy, proxy->modern_mem_bar_idx, + PCI_BASE_ADDRESS_SPACE_MEMORY | + PCI_BASE_ADDRESS_MEM_PREFETCH | + PCI_BASE_ADDRESS_MEM_TYPE_64, + &proxy->modern_bar); proxy->config_cap = virtio_pci_add_mem_cap(proxy, &cfg.cap); cfg_mask = (void *)(proxy->pci_dev.wmask + proxy->config_cap); @@ -2072,8 +2115,92 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) &virtio_pci_config_ops, proxy, "virtio-pci", size); - pci_register_bar(&proxy->pci_dev, proxy->legacy_io_bar_idx, - PCI_BASE_ADDRESS_SPACE_IO, &proxy->bar); + virtio_pci_register_bar(proxy, proxy->legacy_io_bar_idx, + PCI_BASE_ADDRESS_SPACE_IO, &proxy->bar); + } + + if (proxy->sriov_vfs) { + uint16_t first_devfn; + uint16_t stride; + PCIESriovVFOpts *opts; + + if (!k->sriov_supported) { + error_setg(errp, "SR-IOV is not supported by this device type"); + return; + } + + if (!pci_is_express(&proxy->pci_dev)) { + error_setg(errp, "PCI Express is required for SR-IOV"); + return; + } + + g_array_sort(proxy->sriov_vfs, virtio_pci_sriov_vfs_compare); + + first_devfn = g_array_index(proxy->sriov_vfs, VirtIOPCISriovVF, 0).devfn; + if (first_devfn <= proxy->pci_dev.devfn) { + error_setg(errp, "a VF function number is less than the PF function number"); + return; + } + + stride = proxy->sriov_vfs->len < 2 ? + 0 : + (g_array_index(proxy->sriov_vfs, VirtIOPCISriovVF, 1).devfn - + first_devfn); + + for (uint16_t i = 0; i < proxy->sriov_vfs->len; i++) { + VirtIOPCISriovVF *vf = &g_array_index(proxy->sriov_vfs, + VirtIOPCISriovVF, + i); + if (vf->class != object_get_class(OBJECT(proxy))) { + error_setg(errp, "a VF and its paired PF have different types"); + return; + } + + for (size_t j = 0; j < PCI_NUM_REGIONS; j++) { + if (j == PCI_ROM_SLOT) { + continue; + } + + if (vf->io_regions[j].size != proxy->pci_dev.io_regions[j].size || + vf->io_regions[j].type != proxy->pci_dev.io_regions[j].type) { + error_setg(errp, "inconsistent SR-IOV BARs"); + } + } + + if (vf->devfn - first_devfn != stride * i) { + error_setg(errp, "inconsistent SR-IOV stride"); + return; + } + } + + opts = g_new(PCIESriovVFOpts, proxy->sriov_vfs->len); + + for (uint16_t i = 0; i < proxy->sriov_vfs->len; i++) { + opts[i] = g_array_index(proxy->sriov_vfs, VirtIOPCISriovVF, i).opts; + qobject_ref(opts[i].device_opts); + } + + pcie_sriov_pf_init(&proxy->pci_dev, PCI_CONFIG_SPACE_SIZE, + proxy->pci_dev.name, opts, + PCI_DEVICE_ID_VIRTIO_10_BASE + + virtio_bus_get_vdev_id(bus), + proxy->sriov_vfs->len, proxy->sriov_vfs->len, + first_devfn - proxy->pci_dev.devfn, + stride); + + for (int i = 0; i < PCI_NUM_REGIONS; i++) { + if (i == PCI_ROM_SLOT) { + continue; + } + + VirtIOPCISriovVF *vf = &g_array_index(proxy->sriov_vfs, + VirtIOPCISriovVF, + 0); + uint8_t type = vf->io_regions[i].type; + size = vf->io_regions[i].size; + + pcie_sriov_pf_init_vf_bar(&proxy->pci_dev, i, type, size); + } } } @@ -2093,9 +2220,69 @@ static void virtio_pci_device_unplugged(DeviceState *d) if (modern_pio) { virtio_pci_modern_io_region_unmap(proxy, &proxy->notify_pio); } + if (proxy->sriov_vfs) { + pcie_sriov_pf_exit(&proxy->pci_dev); + } } } +static bool virtio_pci_hide(PCIDeviceClass *pc, const QDict *device_opts, + bool from_json, Error **errp) +{ + const char *pf; + GArray *array; + QDict *cloned_device_opts; + VirtIOPCISriovVF vf; + DeviceState *dev; + PCIDevice *pci_dev; + + if (!device_opts) { + return false; + } + + pf = qdict_get_try_str(device_opts, "sriov-pf"); + if (!pf) { + return false; + } + + cloned_device_opts = qdict_clone_shallow(device_opts); + qdict_del(cloned_device_opts, "sriov-pf"); + + dev = qdev_device_add_from_qdict(cloned_device_opts, from_json, errp); + if (!dev) { + qobject_unref(cloned_device_opts); + return false; + } + + pci_dev = PCI_DEVICE(dev); + vf.class = object_get_class(OBJECT(dev)); + vf.opts.device_opts = cloned_device_opts; + vf.opts.from_json = from_json; + + for (size_t i = 0; i < PCI_NUM_REGIONS; i++) { + vf.io_regions[i].size = pci_dev->io_regions[i].size; + vf.io_regions[i].type = pci_dev->io_regions[i].type; + } + + vf.devfn = pci_dev->devfn; + + qdev_unplug(dev, errp); + if (*errp) { + qobject_unref(cloned_device_opts); + return false; + } + + array = g_hash_table_lookup(sriov_vfs, pf); + if (!array) { + array = g_array_new(false, false, sizeof(VirtIOPCISriovVF)); + g_hash_table_insert(sriov_vfs, g_strdup(pf), array); + } + + g_array_append_val(array, vf); + + return true; +} + static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) { VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev); @@ -2325,7 +2512,10 @@ static void virtio_pci_class_init(ObjectClass *klass, void *data) VirtioPCIClass *vpciklass = VIRTIO_PCI_CLASS(klass); ResettableClass *rc = RESETTABLE_CLASS(klass); + sriov_vfs = g_hash_table_new(g_str_hash, g_str_equal); + device_class_set_props(dc, virtio_pci_properties); + k->hide = virtio_pci_hide; k->realize = virtio_pci_realize; k->exit = virtio_pci_exit; k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; From patchwork Sat Dec 2 08:00:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1870877 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=Tz+2+18X; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sj2Wp19Ftz1ySh for ; Sat, 2 Dec 2023 19:04:22 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9Kwd-0004jj-7a; Sat, 02 Dec 2023 03:01:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9KwZ-0004j1-O0 for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:44 -0500 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9KwX-0005B3-8y for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:01:42 -0500 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6cde11fb647so3013887b3a.1 for ; Sat, 02 Dec 2023 00:01:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1701504100; x=1702108900; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=s16ZI44hQXkr05xkfwm1J4giXFLAF4fylGs8gYJ7YV8=; b=Tz+2+18XlKLIAg/buM0ulDrWq3wKlMnWMMiuHG2oXY3wiQVkZRhVQJuUCrOsozriO8 CX0sfGDy6Gamyyjlbo+SRiIB0RrrqjuwutZMPgnDHvHbshcSa+/35iWeEypv019xj662 PN4PD60lAQsuziC17yruGXvs0dESnXdbP19PKgPbdR4RxImfFu1ix+Gm5b4cBHrH27OD qI5WA0CJ/xPXI1+bLVxc7HgP3aQC3X9BhlfOJvOi8MfXNqzl83VhievM4J6ikeSnY+5w oeqxSAIL2okPB58Y5wSr+Y2U/lx/hbehW1bnyXjmXazAHvOlIsp5gogu0vl5WfCiFOwu 8IRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701504100; x=1702108900; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s16ZI44hQXkr05xkfwm1J4giXFLAF4fylGs8gYJ7YV8=; b=nZ4M47UKuH6ar/CqmpMsM0kIww3njISR3YPyDsEHW+rmMK42jmMhnpdukqY9+4JNLH p6fR0IT0u3QUhF3ZibWH9SCKwLvk/sHTgT5jkV/PlQKSKXl1vcVprCbnjrx+ukSvmVaI PSDuCuXGNnlrdMYSWdeROKaAPKYc3L63lmzD2vkHPBij/mZSqnFGyJ8Z3MD1vy1WWtR8 zNhavKZIm9oUIUHu5S9uhaSy0rQ5ogzEMNx2n0uoVEgpW4hQUQNSE5XuHPIZIWjbWC/2 efe257/Dbauxki4ydWQRCl07zTLRQJgAykqA4r/zRf76zOSQwE7kLzP3EKb708sxLUsc 0/gw== X-Gm-Message-State: AOJu0Yzup20cuyzom3Szgx4DuMeclnku7NIxGiud1OcrxhIYU9qd0jlO x4NAdEGn6ASEBy99GZhsKHOB6Q== X-Google-Smtp-Source: AGHT+IEty8qzuzQIfSTtaye/71tSTJiDe2P17w2pG40Kgezvk15MuIHER/U5tNX6RNLVHmMRG9utgQ== X-Received: by 2002:a05:6a20:1454:b0:18c:6559:37f8 with SMTP id a20-20020a056a20145400b0018c655937f8mr1088959pzi.34.1701504099822; Sat, 02 Dec 2023 00:01:39 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id z27-20020aa79e5b000000b00686b649cdd0sm4114160pfq.86.2023.12.02.00.01.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 00:01:39 -0800 (PST) From: Akihiko Odaki Date: Sat, 02 Dec 2023 17:00:37 +0900 Subject: [PATCH 14/14] virtio-net: Add SR-IOV capability MIME-Version: 1.0 Message-Id: <20231202-sriov-v1-14-32b3570f7bd6@daynix.com> References: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> In-Reply-To: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> To: "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.12.4 Received-SPF: none client-ip=2607:f8b0:4864:20::42c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This enables the SR-IO capability previously added to virtio-pci for virtio-net-pci. Buglink: https://issues.redhat.com/browse/RHEL-1216 Signed-off-by: Akihiko Odaki --- hw/virtio/virtio-net-pci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/virtio/virtio-net-pci.c b/hw/virtio/virtio-net-pci.c index e421cd9cea..421d69e206 100644 --- a/hw/virtio/virtio-net-pci.c +++ b/hw/virtio/virtio-net-pci.c @@ -88,6 +88,7 @@ static void virtio_net_pci_class_init(ObjectClass *klass, void *data) set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); device_class_set_props(dc, virtio_net_properties); vpciklass->realize = virtio_net_pci_realize; + vpciklass->sriov_supported = true; } static void virtio_net_pci_instance_init(Object *obj)