From patchwork Fri Mar 15 03:57:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13593043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 299DEC54E58 for ; Fri, 15 Mar 2024 03:59:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkyhn-00029N-4y; Thu, 14 Mar 2024 23:58:03 -0400 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 1rkyhl-00028Q-Ap for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:01 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rkyhj-0001zF-IC for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:01 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1def3340682so304075ad.1 for ; Thu, 14 Mar 2024 20:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1710475078; x=1711079878; 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=wI3L0RzaFLeIPtf2T81Fap99N2O3oFKdQ/+MlIH6obw=; b=SYRS8f3/AQ8NPLEVk+aht0h99UBSfesJg2zjnH9QSxAQqyxJqd4y8DCocaYsh56D/Q aj1gnpAu+j9eFbnhqoH1UViCMz4A6HSaGp1SIzYH9YCsNUB6mJJO2nUAxxGwqUNPJUEm Zkt405xmBmvsJbCCaNWv4DWYlhCEhM5ceckv1Woba5LSmKTVMzbVZ27cHxiHDM+MJiva ujwl0nuqSh9N1v3hWsyj0LeRMjCGDC2IfbxbljvCyIw1RnqG2kMoQg9Cc0yjxOK3WHvv t+DbqumxxRj959nYNsqWR+zqUHT86IBb3AAXeyPP3N7ceT/okvDSaE53h8txbrhS0ueD 2AJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710475078; x=1711079878; 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=wI3L0RzaFLeIPtf2T81Fap99N2O3oFKdQ/+MlIH6obw=; b=LZCHhNOG77hn3jOz0c3lTQMO6PUSIZjaNPgPJNxORe+4BlDBishbu1SdjjibW2koRI TpOgZX0rZsKuqI7WxV7xCJ7YNq4Lx/xetZDrCwZRbiDoXQtLzVUZQYTQDBSo9P+Fgqn0 ajTH1OyEZT1FBXwwXJKnPtzZryCV+ue6gPlY+GT3XEazKkA2J7Fu+uFBj8nk7L16Wcop XiNyJYn6/NXFAkYKOjBTmnRjn86siC2DvRMeNXEinHOWwfSkJu0ltfp6nkyZgCkkwHB+ 8UnGEZyjAuUklEJ99AmRz4M8LnIwnxxc1wF685BfmgiRsuLD0Bo97aV+tSA7mH/a/7U4 RGuA== X-Gm-Message-State: AOJu0YxFpqL5vDGDdVmQuFAfTUmgKpoVxDcLthoNuC+RBtm8Oeq7Pi1G d4NHE6OdwXz7gN4BTKmfeBcIiP3khq1dsdpFThjYUDedV5B56PQhR7x6lcURHzs= X-Google-Smtp-Source: AGHT+IF40Jlrczdk2yhVefyEodoCDQ9nJscNPV4m0pir6ylpYx7UINDEsqU/6uryJndOXBa9mmmNwQ== X-Received: by 2002:a17:903:41ce:b0:1de:de7d:d3a8 with SMTP id u14-20020a17090341ce00b001dede7dd3a8mr3765393ple.61.1710475078023; Thu, 14 Mar 2024 20:57:58 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id u12-20020a170903124c00b001dd66642652sm2595849plh.190.2024.03.14.20.57.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Mar 2024 20:57:57 -0700 (PDT) From: Akihiko Odaki Date: Fri, 15 Mar 2024 12:57:48 +0900 Subject: [PATCH for 9.1 v9 01/11] hw/pci: Rename has_power to enabled MIME-Version: 1.0 Message-Id: <20240315-reuse-v9-1-67aa69af4d53@daynix.com> References: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> In-Reply-To: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> To: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "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 , Sriram Yagnaraman , Jason Wang , Keith Busch , Klaus Jensen , Markus Armbruster Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::630; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x630.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The renamed state will not only represent powering state of PFs, but also represent SR-IOV VF enablement in the future. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci.h | 7 ++++++- include/hw/pci/pci_device.h | 2 +- hw/pci/pci.c | 14 +++++++------- hw/pci/pci_host.c | 4 ++-- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index eaa3fc99d884..6c92b2f70008 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -642,6 +642,11 @@ static inline void pci_irq_pulse(PCIDevice *pci_dev) } MSIMessage pci_get_msi_message(PCIDevice *dev, int vector); -void pci_set_power(PCIDevice *pci_dev, bool state); +void pci_set_enabled(PCIDevice *pci_dev, bool state); + +static inline void pci_set_power(PCIDevice *pci_dev, bool state) +{ + pci_set_enabled(pci_dev, state); +} #endif diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index d3dd0f64b273..d57f9ce83884 100644 --- a/include/hw/pci/pci_device.h +++ b/include/hw/pci/pci_device.h @@ -56,7 +56,7 @@ typedef struct PCIReqIDCache PCIReqIDCache; struct PCIDevice { DeviceState qdev; bool partially_hotplugged; - bool has_power; + bool enabled; /* PCI config space */ uint8_t *config; diff --git a/hw/pci/pci.c b/hw/pci/pci.c index e7a39cb203ae..8bde13f7cd1e 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1525,7 +1525,7 @@ static void pci_update_mappings(PCIDevice *d) continue; new_addr = pci_bar_address(d, i, r->type, r->size); - if (!d->has_power) { + if (!d->enabled) { new_addr = PCI_BAR_UNMAPPED; } @@ -1613,7 +1613,7 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val_in, int pci_update_irq_disabled(d, was_irq_disabled); memory_region_set_enabled(&d->bus_master_enable_region, (pci_get_word(d->config + PCI_COMMAND) - & PCI_COMMAND_MASTER) && d->has_power); + & PCI_COMMAND_MASTER) && d->enabled); } msi_write_config(d, addr, val_in, l); @@ -2811,18 +2811,18 @@ MSIMessage pci_get_msi_message(PCIDevice *dev, int vector) return msg; } -void pci_set_power(PCIDevice *d, bool state) +void pci_set_enabled(PCIDevice *d, bool state) { - if (d->has_power == state) { + if (d->enabled == state) { return; } - d->has_power = state; + d->enabled = state; pci_update_mappings(d); memory_region_set_enabled(&d->bus_master_enable_region, (pci_get_word(d->config + PCI_COMMAND) - & PCI_COMMAND_MASTER) && d->has_power); - if (!d->has_power) { + & PCI_COMMAND_MASTER) && d->enabled); + if (!d->enabled) { pci_device_reset(d); } } diff --git a/hw/pci/pci_host.c b/hw/pci/pci_host.c index dfe6fe618401..0d82727cc9dd 100644 --- a/hw/pci/pci_host.c +++ b/hw/pci/pci_host.c @@ -86,7 +86,7 @@ void pci_host_config_write_common(PCIDevice *pci_dev, uint32_t addr, * allowing direct removal of unexposed functions. */ if ((pci_dev->qdev.hotplugged && !pci_get_function_0(pci_dev)) || - !pci_dev->has_power || is_pci_dev_ejected(pci_dev)) { + !pci_dev->enabled || is_pci_dev_ejected(pci_dev)) { return; } @@ -111,7 +111,7 @@ uint32_t pci_host_config_read_common(PCIDevice *pci_dev, uint32_t addr, * allowing direct removal of unexposed functions. */ if ((pci_dev->qdev.hotplugged && !pci_get_function_0(pci_dev)) || - !pci_dev->has_power || is_pci_dev_ejected(pci_dev)) { + !pci_dev->enabled || is_pci_dev_ejected(pci_dev)) { return ~0x0; } From patchwork Fri Mar 15 03:57:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13593044 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1BA0CC54E58 for ; Fri, 15 Mar 2024 03:59:26 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkyhr-0002AL-DE; Thu, 14 Mar 2024 23:58:07 -0400 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 1rkyhp-00029c-Fw for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:05 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rkyho-0001zv-1h for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:05 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1dd8dd198d0so12430065ad.3 for ; Thu, 14 Mar 2024 20:58:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1710475082; x=1711079882; 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=mcCPQWk0Vl3Dmy9Os9eAS88Yp3n8TTfYv/+AY1WsjkQ=; b=qJs8hmFOstfLyC26zH3BXyskAbkDO9VeBhmVcWsE9zXJTR+NIGgZX5/axpztwPFGBA MJhkZ9MHS4hP8dpIFY9fV21/9at30EbxPIIimGimxwkCDVTLbmWRJiSjuqp4q8GxqfwC tvpLTkDORCd5F0zX+/eC27XziT+Tf57LBxVT8ooCq8hR/lMe7D8QNNlHT02swUvk3Sla l8n1ZibC088/o/CHwt1jUlDFTM0Rxpy/uo3Dh+14gtKVKtSP/Sh/H1Cbxu2liVgwlBGn ZoW/6BvNFB2A2rP63grfUhEUwtoN6URgVjeBnPgYGpnAHpsP7hAVGzVtfFzBfqLkLzy+ 8YNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710475082; x=1711079882; 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=mcCPQWk0Vl3Dmy9Os9eAS88Yp3n8TTfYv/+AY1WsjkQ=; b=tmHZqlec9nq2gr5KRCj53eT0Zyyw5uncu1f2MM0l9WEVhWq5sLC9UjwWm7XevRbTvV Kc0voM3KjKl5KtF9ORXHEwSpNzwuT9pUlNVsD8YecVY4nYBgYxjJsdiVcp+fEng+n8ys +IsWIppU4+81y8wF1P3lJKEm+qKa+1nekzkS+20zwauBnbiyszL0LPlgZLeRi4i8sUHb TYTSWGoFxd1qHQ+fiXYkoeJ+2/JdZiDwJlyZATGxb09P8AfBwgA/CEKJarNMc7XHcCVQ qCkXnN8LCSTRiRO8CLSrCUPc7kT06XLabwKFyesnWapqs9wDeIs5VmmJt8S/38g4xWEP eiWg== X-Gm-Message-State: AOJu0YxVz5wwyAmt3m8R4OEr9SjTp65DTshd445NC9luR9mzm3tbAX4M 2LMOR+AuGDJurjddQ1dbjIegG/0D+HclSf+7YEDxi8EXyxNsMgLOq4dMN2pP79A= X-Google-Smtp-Source: AGHT+IEHQHuNN90Vc1p8fCS5AP9jp9r0jQk/scnvcHfK87/eYky1ALO6entdbcCjLpIUa+6kRBrN0A== X-Received: by 2002:a17:902:f551:b0:1dd:138:4e0b with SMTP id h17-20020a170902f55100b001dd01384e0bmr2538951plf.40.1710475082670; Thu, 14 Mar 2024 20:58:02 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id w19-20020a170902c79300b001dd0a41447fsm2595177pla.233.2024.03.14.20.57.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Mar 2024 20:58:02 -0700 (PDT) From: Akihiko Odaki Date: Fri, 15 Mar 2024 12:57:49 +0900 Subject: [PATCH for 9.1 v9 02/11] pcie_sriov: Do not manually unrealize MIME-Version: 1.0 Message-Id: <20240315-reuse-v9-2-67aa69af4d53@daynix.com> References: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> In-Reply-To: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> To: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "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 , Sriram Yagnaraman , Jason Wang , Keith Busch , Klaus Jensen , Markus Armbruster Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::62a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62a.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org A device gets automatically unrealized when being unparented. Signed-off-by: Akihiko Odaki --- hw/pci/pcie_sriov.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index e9b23221d713..499becd5273f 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -204,11 +204,7 @@ static void unregister_vfs(PCIDevice *dev) trace_sriov_unregister_vfs(dev->name, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), num_vfs); for (i = 0; i < num_vfs; i++) { - Error *err = NULL; PCIDevice *vf = dev->exp.sriov_pf.vf[i]; - if (!object_property_set_bool(OBJECT(vf), "realized", false, &err)) { - error_reportf_err(err, "Failed to unplug: "); - } object_unparent(OBJECT(vf)); object_unref(OBJECT(vf)); } From patchwork Fri Mar 15 03:57:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13593039 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 72766C54E58 for ; Fri, 15 Mar 2024 03:59:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkyhw-0002B0-0l; Thu, 14 Mar 2024 23:58:12 -0400 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 1rkyhu-0002AV-Dl for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:10 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rkyhs-00020i-Nn for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:10 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1dddaa02d22so10099555ad.2 for ; Thu, 14 Mar 2024 20:58:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1710475087; x=1711079887; 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=JZY+m9QbrWLbhg7NE+NHzZT+JN1j9QodAfG99v72Ph0=; b=CJhTBAFjkCNrGNF5xijm4k1dykChPTgpx3/f8JPMxI19hWdSqu5KNnfgjy4bRxVy5Z sqsCKueY/6EshT3roh7Ip1owXnTAdNpoPW1FdG6s5EGcIdEBpQcH5zlX9fWrAU1U1M6v 0m60FkhPOG/TsFy7cQgwl7VM5coXcIwMM9X85duoEExlzFyl25msCHFlavNERxcI60f5 lKX6yhC6JzU9e7kZCc9NIUt5l51jHn5/iOcrH8LKoOsq0Ae0T2tOJKVjKa1FcvRYqjoe mY3EtTQukbxs1FTpJIjBmuUbco3PvoJkPNo6zDb/7vPgBFz2mY0oMwR42rG8/mUBgEp6 BO6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710475087; x=1711079887; 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=JZY+m9QbrWLbhg7NE+NHzZT+JN1j9QodAfG99v72Ph0=; b=HMMiGSK9pWL/cCjSvhv+f4ZLH94etQFIU1Fi2QIZDiJ9FiJQIuywrdSULQ4rstAv4H Xcj9TiDD6bPd/LTVIF2JdrIZAjNnW6rMFsxdci1CgIUOjhSwX4nYqb172aYDeGRhLjRj vO6CEl+gtEdonsWKaiLdKik6q7U4AV7Z77ixUClOSQDUIhEwn8UjVjZuUf4GEwPEL8rW 0PIi885vafLVv2MIaZRT4+iWKnNp/cJlcOWZsvCygk02zh4ZN6PeWvuFcV3TmeDxA1DW H6bodU62R9UbHcQFsbOS4APWXz9zpvSelkHhUofVnyoTm2OIVblK/sOROAN51T6q4XQH Jzzw== X-Gm-Message-State: AOJu0Yzf5mPJELoOcpi2HRYdGr8FOi8WYdNWdpBtZj6Mp3OxRe0qhGIl 9kAuhfKRZXO8Zda/bqV8T3kHrssLVpBZRkLIKVvtFKtDOJVOPrZ8aM8RSgd2v0U= X-Google-Smtp-Source: AGHT+IEASVO9/V0GefIZByujHLID6J1WPWHWek22eZLXcD7g+nexLxbmj5hwBW2SMy/Qw/beZSWcvA== X-Received: by 2002:a17:902:c412:b0:1dd:a2d5:8e84 with SMTP id k18-20020a170902c41200b001dda2d58e84mr2188898plk.27.1710475087313; Thu, 14 Mar 2024 20:58:07 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id p18-20020a170902e75200b001dcc158df20sm2613112plf.97.2024.03.14.20.58.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Mar 2024 20:58:07 -0700 (PDT) From: Akihiko Odaki Date: Fri, 15 Mar 2024 12:57:50 +0900 Subject: [PATCH for 9.1 v9 03/11] pcie_sriov: Ensure VF function number does not overflow MIME-Version: 1.0 Message-Id: <20240315-reuse-v9-3-67aa69af4d53@daynix.com> References: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> In-Reply-To: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> To: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "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 , Sriram Yagnaraman , Jason Wang , Keith Busch , Klaus Jensen , Markus Armbruster Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::636; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x636.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org pci_new() aborts when creating a VF with a function number equals to or is greater than PCI_DEVFN_MAX. Signed-off-by: Akihiko Odaki --- docs/pcie_sriov.txt | 8 +++++--- include/hw/pci/pcie_sriov.h | 5 +++-- hw/net/igb.c | 13 ++++++++++--- hw/nvme/ctrl.c | 24 ++++++++++++++++-------- hw/pci/pcie_sriov.c | 19 +++++++++++++++++-- 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/docs/pcie_sriov.txt b/docs/pcie_sriov.txt index a47aad0bfab0..ab2142807f79 100644 --- a/docs/pcie_sriov.txt +++ b/docs/pcie_sriov.txt @@ -52,9 +52,11 @@ setting up a BAR for a VF. ... /* Add and initialize the SR/IOV capability */ - pcie_sriov_pf_init(d, 0x200, "your_virtual_dev", - vf_devid, initial_vfs, total_vfs, - fun_offset, stride); + if (!pcie_sriov_pf_init(d, 0x200, "your_virtual_dev", + vf_devid, initial_vfs, total_vfs, + fun_offset, stride, errp)) { + return; + } /* Set up individual VF BARs (parameters as for normal BARs) */ pcie_sriov_pf_init_vf_bar( ... ) diff --git a/include/hw/pci/pcie_sriov.h b/include/hw/pci/pcie_sriov.h index b77eb7bf58ac..3e16a269f526 100644 --- a/include/hw/pci/pcie_sriov.h +++ b/include/hw/pci/pcie_sriov.h @@ -27,10 +27,11 @@ struct PCIESriovVF { uint16_t vf_number; /* Logical VF number of this function */ }; -void pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, +bool 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); + uint16_t vf_offset, uint16_t vf_stride, + Error **errp); 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 9b37523d6df8..907259fd8b3b 100644 --- a/hw/net/igb.c +++ b/hw/net/igb.c @@ -447,9 +447,16 @@ 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, - IGB_82576_VF_DEV_ID, IGB_MAX_VF_FUNCTIONS, IGB_MAX_VF_FUNCTIONS, - IGB_VF_OFFSET, IGB_VF_STRIDE); + if (!pcie_sriov_pf_init(pci_dev, IGB_CAP_SRIOV_OFFSET, + TYPE_IGBVF, IGB_82576_VF_DEV_ID, + IGB_MAX_VF_FUNCTIONS, IGB_MAX_VF_FUNCTIONS, + IGB_VF_OFFSET, IGB_VF_STRIDE, + errp)) { + pcie_cap_exit(pci_dev); + igb_cleanup_msix(s); + msi_uninit(pci_dev); + return; + } pcie_sriov_pf_init_vf_bar(pci_dev, IGBVF_MMIO_BAR_IDX, PCI_BASE_ADDRESS_MEM_TYPE_64 | PCI_BASE_ADDRESS_MEM_PREFETCH, diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index c2b17de9872c..bd31d5432654 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -8048,7 +8048,8 @@ out: return pow2ceil(bar_size); } -static void nvme_init_sriov(NvmeCtrl *n, PCIDevice *pci_dev, uint16_t offset) +static bool nvme_init_sriov(NvmeCtrl *n, PCIDevice *pci_dev, uint16_t offset, + Error **errp) { uint16_t vf_dev_id = n->params.use_intel_id ? PCI_DEVICE_ID_INTEL_NVME : PCI_DEVICE_ID_REDHAT_NVME; @@ -8057,12 +8058,17 @@ 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, - n->params.sriov_max_vfs, n->params.sriov_max_vfs, - NVME_VF_OFFSET, NVME_VF_STRIDE); + if (!pcie_sriov_pf_init(pci_dev, offset, "nvme", vf_dev_id, + n->params.sriov_max_vfs, n->params.sriov_max_vfs, + NVME_VF_OFFSET, NVME_VF_STRIDE, + errp)) { + return false; + } pcie_sriov_pf_init_vf_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64, bar_size); + + return true; } static int nvme_add_pm_capability(PCIDevice *pci_dev, uint8_t offset) @@ -8155,6 +8161,12 @@ static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev, Error **errp) return false; } + if (!pci_is_vf(pci_dev) && n->params.sriov_max_vfs && + !nvme_init_sriov(n, pci_dev, 0x120, errp)) { + msix_uninit(pci_dev, &n->bar0, &n->bar0); + return false; + } + nvme_update_msixcap_ts(pci_dev, n->conf_msix_qsize); if (n->params.cmb_size_mb) { @@ -8165,10 +8177,6 @@ static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev, Error **errp) nvme_init_pmr(n, pci_dev); } - if (!pci_is_vf(pci_dev) && n->params.sriov_max_vfs) { - nvme_init_sriov(n, pci_dev, 0x120); - } - return true; } diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index 499becd5273f..f0bde0d3fc79 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -24,14 +24,27 @@ static PCIDevice *register_vf(PCIDevice *pf, int devfn, const char *name, uint16_t vf_num); static void unregister_vfs(PCIDevice *dev); -void pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, +bool 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) + uint16_t vf_offset, uint16_t vf_stride, + Error **errp) { uint8_t *cfg = dev->config + offset; uint8_t *wmask; + if (total_vfs) { + uint16_t ari_cap = pcie_find_capability(dev, PCI_EXT_CAP_ID_ARI); + uint16_t first_vf_devfn = dev->devfn + vf_offset; + uint16_t last_vf_devfn = first_vf_devfn + vf_stride * (total_vfs - 1); + + if ((!ari_cap && PCI_SLOT(dev->devfn) != PCI_SLOT(last_vf_devfn)) || + last_vf_devfn >= PCI_DEVFN_MAX) { + error_setg(errp, "VF function number overflows"); + return false; + } + } + pcie_add_capability(dev, PCI_EXT_CAP_ID_SRIOV, 1, offset, PCI_EXT_CAP_SRIOV_SIZEOF); dev->exp.sriov_cap = offset; @@ -69,6 +82,8 @@ void pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, pci_set_word(wmask + PCI_SRIOV_SYS_PGSIZE, 0x553); qdev_prop_set_bit(&dev->qdev, "multifunction", true); + + return true; } void pcie_sriov_pf_exit(PCIDevice *dev) From patchwork Fri Mar 15 03:57:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13593040 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 24D05C54E66 for ; Fri, 15 Mar 2024 03:59:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkyi0-0002Gh-TN; Thu, 14 Mar 2024 23:58:16 -0400 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 1rkyhz-0002FL-BW for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:15 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rkyhx-00021M-89 for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:15 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1dc75972f25so12284715ad.1 for ; Thu, 14 Mar 2024 20:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1710475092; x=1711079892; 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=m5C2rBlI//oLooTsItMZl8g/a1AZQSTXFEXjiEK6iuY=; b=l1hLVzusGvjKzulsvAml4O73PMZ7XHbAxjRoUaYHCkDGCiYsGqi2QkDb9gSbhSpzXV hDlqqVKtkMc85GEc0fSg2EQch0bupiEyFDePjGVEFVlDOvp0x2szosPQbgIN2bBmn0cB 9uOTETNKCa8uSXoQYp12uFkHIqAaGCjJ1jXsb5vRXukREDhigx4K5rv8z95Gf1+dt/Vm oruhoycXe+uZatBWsb7uj3s3J5m8sleJ9aanDCvJtu5gRUUFVZV8iFXu7dkWHQsDwURq UMHpzpVDvdzL0dF5qTAaJbFriMYquieQEmw5nysQl3OEnPkKU5bH52kb8Z1X8z/ZQT8l 6WGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710475092; x=1711079892; 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=m5C2rBlI//oLooTsItMZl8g/a1AZQSTXFEXjiEK6iuY=; b=kkekTgb+sEClCi2rmb2dzM574U79ztxId6rd0bygbPkdgLuw6efNQGPCKGrqu1ZE26 0Wv8RrwCUtAnVPXMAEO0UyKyIJEUp5o79e+apfepsXQLtqFDL8KeGY8trZvFEOA0ZBmb L44cOriLEX7kkjV5JDMYDML1bVMYeHGHc9EmX90dwBBs3Bj3sAecDDzDkGx8jK1hbhv8 Vx+x3fMczG9bmLEYrewmXrhe1wZvGABIQVYih9ZPW632NbZKtK+XiwBgYM4v0lf9uFDQ pusKhl1QYOp1NQfkHJwTLKfLm4ihxtGE9x1p/NbEe5/hq4yLFcWDgJfR2iY5r52DlZYp MU1A== X-Gm-Message-State: AOJu0YynfqUC1vA0b9P5Jv/i9uSe4osqrrq9cEuNcovrYZ9y9dBa92/a pufE3minjdSxGKizj+J7NV08kOnpA+E5zz+Ya9BsaA4d8hJ4+3ZETtmEnuKRCF8= X-Google-Smtp-Source: AGHT+IF/X6jOoRsgY0tnfo0XQEnm6XnBqE5CzgK6qII16m4Yr2n/7puQWRhgLygrxi10JohtlJVIUA== X-Received: by 2002:a17:902:7796:b0:1dc:fc0b:6a41 with SMTP id o22-20020a170902779600b001dcfc0b6a41mr3245102pll.59.1710475092099; Thu, 14 Mar 2024 20:58:12 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id q6-20020a170902a3c600b001dede7dd3c7sm2107716plb.111.2024.03.14.20.58.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Mar 2024 20:58:11 -0700 (PDT) From: Akihiko Odaki Date: Fri, 15 Mar 2024 12:57:51 +0900 Subject: [PATCH for 9.1 v9 04/11] pcie_sriov: Reuse SR-IOV VF device instances MIME-Version: 1.0 Message-Id: <20240315-reuse-v9-4-67aa69af4d53@daynix.com> References: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> In-Reply-To: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> To: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "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 , Sriram Yagnaraman , Jason Wang , Keith Busch , Klaus Jensen , Markus Armbruster Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::62c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62c.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Disable SR-IOV VF devices by reusing code to power down PCI devices instead of removing them when the guest requests to disable VFs. This allows to realize devices and report VF realization errors at PF realization time. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci.h | 5 --- include/hw/pci/pci_device.h | 15 +++++++ include/hw/pci/pcie_sriov.h | 1 - hw/pci/pci.c | 2 +- hw/pci/pcie_sriov.c | 95 +++++++++++++++++++-------------------------- 5 files changed, 56 insertions(+), 62 deletions(-) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 6c92b2f70008..442017b4865d 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -644,9 +644,4 @@ static inline void pci_irq_pulse(PCIDevice *pci_dev) MSIMessage pci_get_msi_message(PCIDevice *dev, int vector); void pci_set_enabled(PCIDevice *pci_dev, bool state); -static inline void pci_set_power(PCIDevice *pci_dev, bool state) -{ - pci_set_enabled(pci_dev, state); -} - #endif diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index d57f9ce83884..ca151325085d 100644 --- a/include/hw/pci/pci_device.h +++ b/include/hw/pci/pci_device.h @@ -205,6 +205,21 @@ static inline uint16_t pci_get_bdf(PCIDevice *dev) return PCI_BUILD_BDF(pci_bus_num(pci_get_bus(dev)), dev->devfn); } +static inline void pci_set_power(PCIDevice *pci_dev, bool state) +{ + /* + * Don't change the enabled state of VFs when powering on/off the device. + * + * When powering on, VFs must not be enabled immediately but they must + * wait until the guest configures SR-IOV. + * When powering off, their corresponding PFs will be reset and disable + * VFs. + */ + if (!pci_is_vf(pci_dev)) { + pci_set_enabled(pci_dev, state); + } +} + uint16_t pci_requester_id(PCIDevice *dev); /* DMA access functions */ diff --git a/include/hw/pci/pcie_sriov.h b/include/hw/pci/pcie_sriov.h index 3e16a269f526..4b1133f79e15 100644 --- a/include/hw/pci/pcie_sriov.h +++ b/include/hw/pci/pcie_sriov.h @@ -18,7 +18,6 @@ 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 */ PCIDevice **vf; /* Pointer to an array of num_vfs VF devices */ }; diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 8bde13f7cd1e..750c2ba696d1 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2822,7 +2822,7 @@ void pci_set_enabled(PCIDevice *d, bool state) memory_region_set_enabled(&d->bus_master_enable_region, (pci_get_word(d->config + PCI_COMMAND) & PCI_COMMAND_MASTER) && d->enabled); - if (!d->enabled) { + if (d->qdev.realized) { pci_device_reset(d); } } diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index f0bde0d3fc79..faadb0d2ea85 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -20,9 +20,16 @@ #include "qapi/error.h" #include "trace.h" -static PCIDevice *register_vf(PCIDevice *pf, int devfn, - const char *name, uint16_t vf_num); -static void unregister_vfs(PCIDevice *dev); +static void unparent_vfs(PCIDevice *dev, uint16_t total_vfs) +{ + for (uint16_t i = 0; i < total_vfs; i++) { + PCIDevice *vf = dev->exp.sriov_pf.vf[i]; + object_unparent(OBJECT(vf)); + object_unref(OBJECT(vf)); + } + g_free(dev->exp.sriov_pf.vf); + dev->exp.sriov_pf.vf = NULL; +} bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, const char *vfname, uint16_t vf_dev_id, @@ -30,6 +37,8 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, uint16_t vf_offset, uint16_t vf_stride, Error **errp) { + BusState *bus = qdev_get_parent_bus(&dev->qdev); + int32_t devfn = dev->devfn + vf_offset; uint8_t *cfg = dev->config + offset; uint8_t *wmask; @@ -49,7 +58,6 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, offset, PCI_EXT_CAP_SRIOV_SIZEOF); dev->exp.sriov_cap = offset; dev->exp.sriov_pf.num_vfs = 0; - dev->exp.sriov_pf.vfname = g_strdup(vfname); dev->exp.sriov_pf.vf = NULL; pci_set_word(cfg + PCI_SRIOV_VF_OFFSET, vf_offset); @@ -83,14 +91,34 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, qdev_prop_set_bit(&dev->qdev, "multifunction", true); + dev->exp.sriov_pf.vf = g_new(PCIDevice *, total_vfs); + + for (uint16_t i = 0; i < total_vfs; i++) { + PCIDevice *vf = pci_new(devfn, vfname); + vf->exp.sriov_vf.pf = dev; + vf->exp.sriov_vf.vf_number = i; + + if (!qdev_realize(&vf->qdev, bus, errp)) { + unparent_vfs(dev, i); + return false; + } + + /* set vid/did according to sr/iov spec - they are not used */ + pci_config_set_vendor_id(vf->config, 0xffff); + pci_config_set_device_id(vf->config, 0xffff); + + dev->exp.sriov_pf.vf[i] = vf; + devfn += vf_stride; + } + return true; } void pcie_sriov_pf_exit(PCIDevice *dev) { - unregister_vfs(dev); - g_free((char *)dev->exp.sriov_pf.vfname); - dev->exp.sriov_pf.vfname = NULL; + uint8_t *cfg = dev->config + dev->exp.sriov_cap; + + unparent_vfs(dev, pci_get_word(cfg + PCI_SRIOV_TOTAL_VF)); } void pcie_sriov_pf_init_vf_bar(PCIDevice *dev, int region_num, @@ -156,38 +184,11 @@ 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); - Error *local_err = NULL; - - qdev_realize(&dev->qdev, &bus->qbus, &local_err); - if (local_err) { - error_report_err(local_err); - return NULL; - } - - /* 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); - - return dev; -} - static void register_vfs(PCIDevice *dev) { uint16_t num_vfs; uint16_t i; uint16_t sriov_cap = dev->exp.sriov_cap; - uint16_t vf_offset = - pci_get_word(dev->config + sriov_cap + PCI_SRIOV_VF_OFFSET); - uint16_t vf_stride = - pci_get_word(dev->config + sriov_cap + PCI_SRIOV_VF_STRIDE); - int32_t devfn = dev->devfn + vf_offset; assert(sriov_cap > 0); num_vfs = pci_get_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF); @@ -195,18 +196,10 @@ static void register_vfs(PCIDevice *dev) return; } - dev->exp.sriov_pf.vf = g_new(PCIDevice *, num_vfs); - trace_sriov_register_vfs(dev->name, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), num_vfs); for (i = 0; i < num_vfs; i++) { - dev->exp.sriov_pf.vf[i] = register_vf(dev, devfn, - dev->exp.sriov_pf.vfname, i); - if (!dev->exp.sriov_pf.vf[i]) { - num_vfs = i; - break; - } - devfn += vf_stride; + pci_set_enabled(dev->exp.sriov_pf.vf[i], true); } dev->exp.sriov_pf.num_vfs = num_vfs; } @@ -219,12 +212,8 @@ static void unregister_vfs(PCIDevice *dev) trace_sriov_unregister_vfs(dev->name, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), num_vfs); for (i = 0; i < num_vfs; i++) { - PCIDevice *vf = dev->exp.sriov_pf.vf[i]; - object_unparent(OBJECT(vf)); - object_unref(OBJECT(vf)); + pci_set_enabled(dev->exp.sriov_pf.vf[i], false); } - g_free(dev->exp.sriov_pf.vf); - dev->exp.sriov_pf.vf = NULL; dev->exp.sriov_pf.num_vfs = 0; } @@ -246,14 +235,10 @@ void pcie_sriov_config_write(PCIDevice *dev, uint32_t address, PCI_FUNC(dev->devfn), off, val, len); if (range_covers_byte(off, len, PCI_SRIOV_CTRL)) { - if (dev->exp.sriov_pf.num_vfs) { - if (!(val & PCI_SRIOV_CTRL_VFE)) { - unregister_vfs(dev); - } + if (val & PCI_SRIOV_CTRL_VFE) { + register_vfs(dev); } else { - if (val & PCI_SRIOV_CTRL_VFE) { - register_vfs(dev); - } + unregister_vfs(dev); } } } From patchwork Fri Mar 15 03:57:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13593046 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 89ED9C54E58 for ; Fri, 15 Mar 2024 03:59:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkyi8-0002RH-CC; Thu, 14 Mar 2024 23:58:24 -0400 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 1rkyi6-0002LR-NL for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:22 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rkyi2-00022F-2b for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:22 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6e6b5432439so1720094b3a.1 for ; Thu, 14 Mar 2024 20:58:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1710475097; x=1711079897; 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=JVzrVk4TYQYUBhxw61sjy4ZQEhn6xPnWNjuBpVS2XV0=; b=QMaEZde5CE5wPv2EFrtF7jmOoEg0dy/QK4zv7Ze8jKgWIU80inP8ez8SrX0u6BxWOO H0ROVy/5StA0Co2gokLMO9Wv7tVZUJ5SRnq31jAZYdA2By2YSQ8uT7W7GFN/0N0y380T eUW7tNUT9Xk4dz2Lo4iAOnh1iFeNZ+Q496P6MIgJdMoUUnlyA6WiKns4z854xiqCSGPC 6jWmzT/iuTmA+OKPYHF9P3dTvZg4tKnEyJzN0kJOXkkTpesbPs8kzkHnYyglCWP0S9oz hkJUYqjlz/g+apQUvDBveoGa7OA2SYFEkVyOxn2uGnTpESWtOwWVEIDuiHbqGZq3cZ/Y gxrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710475097; x=1711079897; 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=JVzrVk4TYQYUBhxw61sjy4ZQEhn6xPnWNjuBpVS2XV0=; b=UYsIFbkgNzHrakJ23c1RzG3wmw33DrLGyND2KxjNtHG1yuO4QenU8iV67bXAZoT+ue sYcOpDD8M/aeEDCpLWSo1Y0XJEh324IQOXj1r6h0/GftcUkxG6d74FcNID8NsIcs9KIh 29fFFBnEuNQ6k96/bjS4D1dbpkLpYdWRfkWtrWg/vP8PdYpp5848nY4l36Ll2lXMJ+Qv IfZ+WT5RRc5GI+fusOlEq21PEGyg1v+GXpT+cGk3MXbXuv7UBJL5lI3oc9gw2DVO/TUA r5TyexSiqXmrkQnFUBkxwWKQYbmhw0InCGTWJjipAj8hpgfHmXR16TFBH+ISx2yml2nY Y/aQ== X-Gm-Message-State: AOJu0YwqUPuapDMzEZA3XeyQVT4L47g7H5tZ0iUZz8HGJ+KJOoc4mj3O vp7duEvzn0LyR7vfaG2mqy8M3G3L0aD8Nqa+fPOjJ+nmcFOSqSvwPvQeHdWIC6c= X-Google-Smtp-Source: AGHT+IFdKHo8ExtBRg3tM8aB6aRu4iLkkt0TxQQWXqYNTkAeiwV1EeiJrz6UThceJy1f1jqzMTqGfw== X-Received: by 2002:a05:6a00:8506:b0:6e6:fb33:efcc with SMTP id ha6-20020a056a00850600b006e6fb33efccmr211427pfb.1.1710475096791; Thu, 14 Mar 2024 20:58:16 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id lc24-20020a056a004f5800b006e6bda407b6sm2333903pfb.202.2024.03.14.20.58.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Mar 2024 20:58:16 -0700 (PDT) From: Akihiko Odaki Date: Fri, 15 Mar 2024 12:57:52 +0900 Subject: [PATCH for 9.1 v9 05/11] pcie_sriov: Release VFs failed to realize MIME-Version: 1.0 Message-Id: <20240315-reuse-v9-5-67aa69af4d53@daynix.com> References: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> In-Reply-To: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> To: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "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 , Sriram Yagnaraman , Jason Wang , Keith Busch , Klaus Jensen , Markus Armbruster Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::42a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42a.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Release VFs failed to realize just as we do in unregister_vfs(). Fixes: 7c0fa8dff811 ("pcie: Add support for Single Root I/O Virtualization (SR/IOV)") 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 faadb0d2ea85..9bd7f8acc3f4 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -99,6 +99,8 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, vf->exp.sriov_vf.vf_number = i; if (!qdev_realize(&vf->qdev, bus, errp)) { + object_unparent(OBJECT(vf)); + object_unref(vf); unparent_vfs(dev, i); return false; } From patchwork Fri Mar 15 03:57:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13593042 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 73068C54E66 for ; Fri, 15 Mar 2024 03:59:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkyiB-0002WR-LV; Thu, 14 Mar 2024 23:58:27 -0400 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 1rkyi9-0002SG-Mj for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:25 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rkyi7-000238-2X for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:24 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1dc75972f25so12285175ad.1 for ; Thu, 14 Mar 2024 20:58:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1710475101; x=1711079901; 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=/bk8kIUPcbuJdZE/HDHtbLZ+ZTo6wIMTkuNvFugn220=; b=vE4Ji6/perX+TmRrY436q1NI19SeMSePmKA7VEv6S+XGhrhoOjcBElP0h8PtzEE28k ymKSUVUQVRxYLyjnErcO1S+8Z9xQI9a/9V+U7vNtrk4CK4MRVmmitiAnEdWYBr3xEqqj dpvO+l/r7yMxQ7a9L6FJBgcZHQUCD8xpxDHevheZouY8jbGtBkfiT8TUxEcskNlWAX9c Ce4LQkn0An3vHEQELgkA6XYAlQdrPG1Au9UfFAujQf2ugrIFl4Dx/lrPs0p8yS/iyfm1 MqB/hAI4qnB4Fq5Ob6gt/2H3aPyOXF4ebHo1FUfe+k+WYD4yQ4kz/QYQqlDZG+aUnUnB 0w6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710475101; x=1711079901; 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=/bk8kIUPcbuJdZE/HDHtbLZ+ZTo6wIMTkuNvFugn220=; b=O26gSQX1JjQYNqd8ejJme7NI5Ik5j+3mYJ2pP9tdCHB67YcK70iWCjqfstFL2xn6fU yfLwud2vLCV2LQaU9GgUf8+4mTTxKAsgJik83vKAeiPXJ4sNJsGXRrOntBGes+bxzsDt 7QAVtxKUHxUy5robFIFi4vyQL8TZWx/B4EuDIt1nta4Gn4V1IYvGCDhRSMS2asWmAVT1 vHQiJW363YYWsovZ/A8A5+nEYMgANCaRvHx0YDggTMAqrMj5xTb3SFfSWPOhyW/GAv4P Ir+DRHtk+H7BZo9o7+yKL6TTfHk1BLuoYFF3/j7fT3ddb1VeTXG/q0vW9O5Esv+qzoAu jurw== X-Gm-Message-State: AOJu0Yy2sDf2O2lvzjTh6Azju6m0ZqF5pMbNC42+vsbxaptbrSUel1TR w49AVb2iX7SKz5xNJ/pF/Xj8PXhkj3iImr5ANC8l4Jn6fuRdOMBsc0NRsboBxhzCyTNm/+y2Dtm Z X-Google-Smtp-Source: AGHT+IG/PEt1J9F+80L0Op3tWM7DcPRbcEwYzSc606VkRxWUK57h+y93mJBaLtoANuLW6iPgo+A0pg== X-Received: by 2002:a17:903:2284:b0:1dd:6fc5:1c5c with SMTP id b4-20020a170903228400b001dd6fc51c5cmr4647756plh.52.1710475101581; Thu, 14 Mar 2024 20:58:21 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id j13-20020a170902da8d00b001dd6c0800b4sm2603326plx.188.2024.03.14.20.58.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Mar 2024 20:58:21 -0700 (PDT) From: Akihiko Odaki Date: Fri, 15 Mar 2024 12:57:53 +0900 Subject: [PATCH for 9.1 v9 06/11] pcie_sriov: Remove num_vfs from PCIESriovPF MIME-Version: 1.0 Message-Id: <20240315-reuse-v9-6-67aa69af4d53@daynix.com> References: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> In-Reply-To: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> To: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "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 , Sriram Yagnaraman , Jason Wang , Keith Busch , Klaus Jensen , Markus Armbruster Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::62e; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62e.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org num_vfs is not migrated so use PCI_SRIOV_CTRL_VFE and PCI_SRIOV_NUM_VF instead. Signed-off-by: Akihiko Odaki --- include/hw/pci/pcie_sriov.h | 1 - hw/pci/pcie_sriov.c | 28 ++++++++++++++++++++-------- hw/pci/trace-events | 2 +- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/include/hw/pci/pcie_sriov.h b/include/hw/pci/pcie_sriov.h index 4b1133f79e15..793d03c5f12e 100644 --- a/include/hw/pci/pcie_sriov.h +++ b/include/hw/pci/pcie_sriov.h @@ -16,7 +16,6 @@ #include "hw/pci/pci.h" 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 */ PCIDevice **vf; /* Pointer to an array of num_vfs VF devices */ }; diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index 9bd7f8acc3f4..fae6acea4acb 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -57,7 +57,6 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, pcie_add_capability(dev, PCI_EXT_CAP_ID_SRIOV, 1, offset, PCI_EXT_CAP_SRIOV_SIZEOF); dev->exp.sriov_cap = offset; - dev->exp.sriov_pf.num_vfs = 0; dev->exp.sriov_pf.vf = NULL; pci_set_word(cfg + PCI_SRIOV_VF_OFFSET, vf_offset); @@ -186,6 +185,12 @@ void pcie_sriov_vf_register_bar(PCIDevice *dev, int region_num, } } +static void clear_ctrl_vfe(PCIDevice *dev) +{ + uint8_t *ctrl = dev->config + dev->exp.sriov_cap + PCI_SRIOV_CTRL; + pci_set_word(ctrl, pci_get_word(ctrl) & ~PCI_SRIOV_CTRL_VFE); +} + static void register_vfs(PCIDevice *dev) { uint16_t num_vfs; @@ -195,6 +200,7 @@ 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 > pci_get_word(dev->config + sriov_cap + PCI_SRIOV_TOTAL_VF)) { + clear_ctrl_vfe(dev); return; } @@ -203,20 +209,18 @@ static void register_vfs(PCIDevice *dev) for (i = 0; i < num_vfs; i++) { pci_set_enabled(dev->exp.sriov_pf.vf[i], true); } - dev->exp.sriov_pf.num_vfs = num_vfs; } static void unregister_vfs(PCIDevice *dev) { - uint16_t num_vfs = dev->exp.sriov_pf.num_vfs; uint16_t i; + uint8_t *cfg = dev->config + dev->exp.sriov_cap; trace_sriov_unregister_vfs(dev->name, PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn), num_vfs); - for (i = 0; i < num_vfs; i++) { + PCI_FUNC(dev->devfn)); + for (i = 0; i < pci_get_word(cfg + PCI_SRIOV_TOTAL_VF); i++) { pci_set_enabled(dev->exp.sriov_pf.vf[i], false); } - dev->exp.sriov_pf.num_vfs = 0; } void pcie_sriov_config_write(PCIDevice *dev, uint32_t address, @@ -242,6 +246,9 @@ void pcie_sriov_config_write(PCIDevice *dev, uint32_t address, } else { unregister_vfs(dev); } + } else if (range_covers_byte(off, len, PCI_SRIOV_NUM_VF)) { + clear_ctrl_vfe(dev); + unregister_vfs(dev); } } @@ -304,7 +311,7 @@ PCIDevice *pcie_sriov_get_pf(PCIDevice *dev) PCIDevice *pcie_sriov_get_vf_at_index(PCIDevice *dev, int n) { assert(!pci_is_vf(dev)); - if (n < dev->exp.sriov_pf.num_vfs) { + if (n < pcie_sriov_num_vfs(dev)) { return dev->exp.sriov_pf.vf[n]; } return NULL; @@ -312,5 +319,10 @@ PCIDevice *pcie_sriov_get_vf_at_index(PCIDevice *dev, int n) uint16_t pcie_sriov_num_vfs(PCIDevice *dev) { - return dev->exp.sriov_pf.num_vfs; + uint16_t sriov_cap = dev->exp.sriov_cap; + uint8_t *cfg = dev->config + sriov_cap; + + return sriov_cap && + (pci_get_word(cfg + PCI_SRIOV_CTRL) & PCI_SRIOV_CTRL_VFE) ? + pci_get_word(cfg + PCI_SRIOV_NUM_VF) : 0; } diff --git a/hw/pci/trace-events b/hw/pci/trace-events index 19643aa8c6b0..e98f575a9d19 100644 --- a/hw/pci/trace-events +++ b/hw/pci/trace-events @@ -14,7 +14,7 @@ msix_write_config(char *name, bool enabled, bool masked) "dev %s enabled %d mask # hw/pci/pcie_sriov.c sriov_register_vfs(const char *name, int slot, int function, int num_vfs) "%s %02x:%x: creating %d vf devs" -sriov_unregister_vfs(const char *name, int slot, int function, int num_vfs) "%s %02x:%x: Unregistering %d vf devs" +sriov_unregister_vfs(const char *name, int slot, int function) "%s %02x:%x: Unregistering vf devs" sriov_config_write(const char *name, int slot, int fun, uint32_t offset, uint32_t val, uint32_t len) "%s %02x:%x: sriov offset 0x%x val 0x%x len %d" # pcie.c From patchwork Fri Mar 15 03:57:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13593048 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D0FABC54E66 for ; Fri, 15 Mar 2024 03:59:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkyiQ-0002gB-DM; Thu, 14 Mar 2024 23:58:42 -0400 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 1rkyiJ-0002dC-8Z for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:36 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rkyiD-00023h-6Q for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:30 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6e6b54a28d0so1465475b3a.2 for ; Thu, 14 Mar 2024 20:58:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1710475107; x=1711079907; 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=d2B5PcXjV/WvrmnePjI8Cyfuht09Wwa24XAfpuPwLPk=; b=KUygdhwGydOSZxg5fzJvyPeJXKzYO+6TSvm59Wj/Fux97vVqDf5ZVQBFE0TxXHLWTf RAcpNPSVwBOkGVoohX7uWofdHO4jEjjZMBYLbKvJim/rhKe31z3Nxi9FPKBVa9nK3Hvi uIG+Ts1i4KnIJVr1Y4bMaZ2FUg1bgteu/flOLnIRm7LmCCBKeaBycMyvQ8RYaChAHkS4 WF9njlL4t450HjdpHDTYErrYVSUbNaIzRoYSSPmFLl8BO6MMbBHBxHjVJqIdZr8IRI69 wMrgfgaAhVReZaolluY57ygddTwp5XFEEXSZjNlWut/VJyJiLRdB9OnKsSEnUdax38C2 zESw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710475107; x=1711079907; 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=d2B5PcXjV/WvrmnePjI8Cyfuht09Wwa24XAfpuPwLPk=; b=wejXyFWR3jdthpI8X0YirtIjUtfJZV1CCre3gewQuU9CmQdDbBqSW0xN5grX5pOFM+ k+dzy5Kb9yOJyzUlVGyRzUZgbG+Hwg3jFbP12vQkRRMVLS2/ND1RhL3lHwW9ssFT7n6R 9VoOkYgwPbj/ppIgHo7Duku2iSmAdpV5AryJ+lKdFgMUpw0kLpe0BdL20+mDOc6PDMI8 rdFkUZhJu/K2TfeoS0cnNmvC3N5C/b7pjcr0a/KgOI7rsRM/uibcZJ37nfPcvKZ3VPWp 6EB3B9aiWHWa7BbOSWXvM0yacIN+t54ZdvmtCN61mVn4J9VceHw7wHkD1GLwxzewz1qj /EaQ== X-Gm-Message-State: AOJu0Yy2xhk29aVrF/O5jStFwSLx2sKBkwacUKQCO3Pxmx81dJxdztct L5syG90/x7ZYezH4qq5+U7vVmijg+mBdHDE9GcktXpnoG6X+ViA3G/qVRi1vkVQ= X-Google-Smtp-Source: AGHT+IFF8gJBBOG5sl40yPgi/PIsx15roazvTmbQh+Y+7KklQ6EHeCaeoCHq5jpQmPrvmiaYrocOiw== X-Received: by 2002:a05:6a00:22c8:b0:6e6:9f03:6a6d with SMTP id f8-20020a056a0022c800b006e69f036a6dmr2220382pfj.3.1710475106833; Thu, 14 Mar 2024 20:58:26 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id t188-20020a625fc5000000b006e6f8e9ab6asm328734pfb.15.2024.03.14.20.58.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Mar 2024 20:58:26 -0700 (PDT) From: Akihiko Odaki Date: Fri, 15 Mar 2024 12:57:54 +0900 Subject: [PATCH for 9.1 v9 07/11] pcie_sriov: Register VFs after migration MIME-Version: 1.0 Message-Id: <20240315-reuse-v9-7-67aa69af4d53@daynix.com> References: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> In-Reply-To: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> To: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "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 , Sriram Yagnaraman , Jason Wang , Keith Busch , Klaus Jensen , Markus Armbruster Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::433; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x433.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org pcie_sriov doesn't have code to restore its state after migration, but igb, which uses pcie_sriov, naively claimed its migration capability. Add code to register VFs after migration and fix igb migration. Fixes: 3a977deebe6b ("Intrdocue igb device emulation") Signed-off-by: Akihiko Odaki --- include/hw/pci/pcie_sriov.h | 2 ++ hw/pci/pci.c | 7 +++++++ hw/pci/pcie_sriov.c | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/include/hw/pci/pcie_sriov.h b/include/hw/pci/pcie_sriov.h index 793d03c5f12e..d576a8c6be19 100644 --- a/include/hw/pci/pcie_sriov.h +++ b/include/hw/pci/pcie_sriov.h @@ -57,6 +57,8 @@ void pcie_sriov_pf_add_sup_pgsize(PCIDevice *dev, uint16_t opt_sup_pgsize); void pcie_sriov_config_write(PCIDevice *dev, uint32_t address, uint32_t val, int len); +void pcie_sriov_pf_post_load(PCIDevice *dev); + /* Reset SR/IOV */ void pcie_sriov_pf_reset(PCIDevice *dev); diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 750c2ba696d1..54b375da2d26 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -733,10 +733,17 @@ static bool migrate_is_not_pcie(void *opaque, int version_id) return !pci_is_express((PCIDevice *)opaque); } +static int pci_post_load(void *opaque, int version_id) +{ + pcie_sriov_pf_post_load(opaque); + return 0; +} + const VMStateDescription vmstate_pci_device = { .name = "PCIDevice", .version_id = 2, .minimum_version_id = 1, + .post_load = pci_post_load, .fields = (const VMStateField[]) { VMSTATE_INT32_POSITIVE_LE(version_id, PCIDevice), VMSTATE_BUFFER_UNSAFE_INFO_TEST(config, PCIDevice, diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index fae6acea4acb..56523ab4e833 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -252,6 +252,13 @@ void pcie_sriov_config_write(PCIDevice *dev, uint32_t address, } } +void pcie_sriov_pf_post_load(PCIDevice *dev) +{ + if (dev->exp.sriov_cap) { + register_vfs(dev); + } +} + /* Reset SR/IOV */ void pcie_sriov_pf_reset(PCIDevice *dev) From patchwork Fri Mar 15 03:57:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13593047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5252BC54E66 for ; Fri, 15 Mar 2024 03:59:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkyiU-0002no-VU; Thu, 14 Mar 2024 23:58:47 -0400 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 1rkyiM-0002fY-Ig for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:38 -0400 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 1rkyiJ-00024H-22 for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:36 -0400 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3c1a1e1e539so1383301b6e.1 for ; Thu, 14 Mar 2024 20:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1710475111; x=1711079911; 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=TDKYAJW0u4AL8dsA1W9VjtJSLz1K/O17feCu17WZXfU=; b=Y/nqSp+1DdS24dWHs47/Da0kqSNLOOecI1zcXLrGlNAVAGMQKOBs6WaUmOwG6P3jeY aCpJeB8mlHIUeG4HEURScW9rMdIu1lbDKBIb1BkHjWheSIN812+x9lnNfmpGsJoHJsLx j9omxnFDXmP+ckfY9MGXL5eBPAN+b7cRCcer92uTNqnUn91Ddho1P6cUO4JBZSNBccE9 793P3K+br1HDmOalvPZD3wJUyPvP6l97BKzqmpbgwtR7xlpT7v96tCcgtEFbRpjBBx61 NvfCGecHCKQov/YLmCeLfB31km+RjEqK3SaX4EF2G72lwj5k7kfPrbz/pqtAEY8KiUvN MVAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710475111; x=1711079911; 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=TDKYAJW0u4AL8dsA1W9VjtJSLz1K/O17feCu17WZXfU=; b=d/GX4TtQFoxZv0bKVgu+xbiN8lYxmjvWURHqUyFO1oyPyHX+QqNIkOe6qAdtg3e34z 1i7MvIYRn+0tYcECEgdHu4a4Eo97CLSMmyBYa2LZC5Cqej0oGxh6phGWUsstlpKjwUO4 RFNWx/TrAbrYio+jxNRlFowiY4KqjcE5kddIDpcZWTbTxCb1qykyr71mfgOAI+KCYYgy l392oeYNRjWYun/8UqEJAbjmedhuFj5h4Ng0BRBE6f846Kvn5hkfzyLI4wqMkdpvNWCx 4UjB8C1NYdon4wGZPzxGnr1U7uKeLCDIm5nyJLt23LcbWVM+Olu45kw3nOlcmz0XtzIK RHcQ== X-Gm-Message-State: AOJu0YwPLjBsB2xgupiDK++FhLC3u0+rrj/UrsN1k6pmP+XSSZk8JUKJ n7cLr8bSpI5Jbc0BwWhOK9lx+lif30/sJoFqwwh0Q6PNhxFjyf71HogTMpe+G/A= X-Google-Smtp-Source: AGHT+IGycaDNaiM9ORQeqjrrYPmrgSfB7hPe+1atlfpsb+ZznYPdg3+JbQ9k5ijEfr7b4hAT7gsFOA== X-Received: by 2002:a05:6808:1304:b0:3c3:5226:72b9 with SMTP id y4-20020a056808130400b003c3522672b9mr4593310oiv.54.1710475111685; Thu, 14 Mar 2024 20:58:31 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id c2-20020a056a00008200b006e6c843dbe9sm2351997pfj.204.2024.03.14.20.58.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Mar 2024 20:58:31 -0700 (PDT) From: Akihiko Odaki Date: Fri, 15 Mar 2024 12:57:55 +0900 Subject: [PATCH for 9.1 v9 08/11] hw/pci: Replace -1 with UINT32_MAX for romsize MIME-Version: 1.0 Message-Id: <20240315-reuse-v9-8-67aa69af4d53@daynix.com> References: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> In-Reply-To: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> To: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "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 , Sriram Yagnaraman , Jason Wang , Keith Busch , Klaus Jensen , Markus Armbruster Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org romsize is an uint32_t variable. Specifying -1 as an uint32_t value is obscure way to denote UINT32_MAX. Worse, if int is wider than 32-bit, it will change the behavior of a construct like the following: romsize = -1; if (romsize != -1) { ... } When -1 is assigned to romsize, -1 will be implicitly casted into uint32_t, resulting in UINT32_MAX. On contrary, when evaluating romsize != -1, romsize will be casted into int, and it will be a comparison of UINT32_MAX and -1, and result in false. Replace -1 with UINT32_MAX for statements involving the variable to clarify the intent and prevent potential breakage. Signed-off-by: Akihiko Odaki Reviewed-by: Markus Armbruster --- hw/pci/pci.c | 8 ++++---- hw/xen/xen_pt_load_rom.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 54b375da2d26..84df07a2789b 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -70,7 +70,7 @@ static bool pcie_has_upstream_port(PCIDevice *dev); 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("romsize", PCIDevice, romsize, UINT32_MAX), DEFINE_PROP_UINT32("rombar", PCIDevice, rom_bar, 1), DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present, QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false), @@ -2073,7 +2073,7 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp) g_cmp_uint32, NULL); } - if (pci_dev->romsize != -1 && !is_power_of_2(pci_dev->romsize)) { + if (pci_dev->romsize != UINT32_MAX && !is_power_of_2(pci_dev->romsize)) { error_setg(errp, "ROM size %u is not a power of two", pci_dev->romsize); return; } @@ -2359,7 +2359,7 @@ static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom, return; } - if (load_file || pdev->romsize == -1) { + if (load_file || pdev->romsize == UINT32_MAX) { path = qemu_find_file(QEMU_FILE_TYPE_BIOS, pdev->romfile); if (path == NULL) { path = g_strdup(pdev->romfile); @@ -2378,7 +2378,7 @@ static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom, pdev->romfile); return; } - if (pdev->romsize != -1) { + if (pdev->romsize != UINT_MAX) { if (size > pdev->romsize) { error_setg(errp, "romfile \"%s\" (%u bytes) " "is too large for ROM size %u", diff --git a/hw/xen/xen_pt_load_rom.c b/hw/xen/xen_pt_load_rom.c index 03422a8a7148..6bc64acd3352 100644 --- a/hw/xen/xen_pt_load_rom.c +++ b/hw/xen/xen_pt_load_rom.c @@ -53,7 +53,7 @@ void *pci_assign_dev_load_option_rom(PCIDevice *dev, } fseek(fp, 0, SEEK_SET); - if (dev->romsize != -1) { + if (dev->romsize != UINT_MAX) { if (st.st_size > dev->romsize) { error_report("ROM BAR \"%s\" (%ld bytes) is too large for ROM size %u", rom_file, (long) st.st_size, dev->romsize); From patchwork Fri Mar 15 03:57:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13593050 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6C103C54E58 for ; Fri, 15 Mar 2024 04:00:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkyiZ-0002xl-Ag; Thu, 14 Mar 2024 23:58:51 -0400 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 1rkyiO-0002fz-K4 for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:42 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rkyiM-000258-Da for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:39 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1dc29f1956cso11731595ad.0 for ; Thu, 14 Mar 2024 20:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1710475116; x=1711079916; 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=4udzfC4o8hc15auoNaG3g6zD6/NN7zzxG/2gffAwrMo=; b=hmGGEnMpLvMFoLA1Noszt57+RQQwBis0XBgzPLZjEAfTj4hahBsGkD9TUJDgzoXJcH 7TQcGWAF//jb+EBn7oS8grLPlRJzu6KhCgEnrvyXrIpsPsvPxd77uEt6a1fSeh9dkYyf YUoaI3SLolNWraDBRaxPrlnYOT8tlzXRje6GkP8M7PUI7NETKVJQvMoCNX5YeAWzJEEa R/xT1FAeL9Vzshj8/PwkC30pP0whPANljshlF0ZeAnHmEDIJq7gxS2X56wrqQ7iyMHfL UQRs7Fk1wpufKNmoOELlvdjjZg7/RDFp6HlerYn71C8LEkOIWNiAxNDnvGTdB/ZKHS2D Xwmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710475116; x=1711079916; 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=4udzfC4o8hc15auoNaG3g6zD6/NN7zzxG/2gffAwrMo=; b=vABGZKAONIAmFspU01qk8uOqiOguaZnjT+f2J1ElTZHNFif+sTs9HZoWpDScSm9cEI i0ccRkPDnprAsdvbxrazU0xMN25zpZ2N1PF98VE1UDj8d3FOVrRq5ne7K69S3TsE0dtB b1sOPcCLp9ys3By3ILAmubIvHIGCo3ww6+siuhc9lCfjOiuFThISYYfhGK/MLASPip5Z duyc9BVAeeXpLl9GPKTg7Nu2xS/7RFXjP31XkvAYl9frCF9WR1WjOU7sR/a2h2Tpm2zw s2yXkQzNa722QCJDnenNeSUE1QMb68EDpgW62ldKBoXtXvJhuQ3jdJk05lKjvqWbhH6f s5qA== X-Gm-Message-State: AOJu0YwJ6f2x+oirAY29U6DD/ql/ZbRhO9Fsq6jcs06yZkVyZe+qQlAi BFRcyNdTQGk0sC7mdte2LdKgg4bp0p1pMdP+kINWETQWJoHqYnOxD9uwvIBAJkc= X-Google-Smtp-Source: AGHT+IG04ULe+P9n7+jUXa7jAVuPiYVC9wXQBgEuc+yRgIUADi0exz2SqtoXxrrHx3tZnnkJmtQdag== X-Received: by 2002:a17:902:ed0b:b0:1dd:6f4c:c67 with SMTP id b11-20020a170902ed0b00b001dd6f4c0c67mr1906323pld.24.1710475116316; Thu, 14 Mar 2024 20:58:36 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id ky6-20020a170902f98600b001dcfbbb1ddesm2609086plb.7.2024.03.14.20.58.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Mar 2024 20:58:36 -0700 (PDT) From: Akihiko Odaki Date: Fri, 15 Mar 2024 12:57:56 +0900 Subject: [PATCH for 9.1 v9 09/11] hw/pci: Use UINT32_MAX as a default value for rombar MIME-Version: 1.0 Message-Id: <20240315-reuse-v9-9-67aa69af4d53@daynix.com> References: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> In-Reply-To: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> To: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "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 , Sriram Yagnaraman , Jason Wang , Keith Busch , Klaus Jensen , Markus Armbruster Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::62a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62a.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Currently there is no way to distinguish the case that rombar is explicitly specified as 1 and the case that rombar is not specified. Set rombar UINT32_MAX by default to distinguish these cases just as it is done for addr and romsize. It was confirmed that changing the default value to UINT32_MAX will not change the behavior by looking at occurences of rom_bar. $ git grep -w rom_bar hw/display/qxl.c:328: QXLRom *rom = memory_region_get_ram_ptr(&d->rom_bar); hw/display/qxl.c:431: qxl_set_dirty(&qxl->rom_bar, 0, qxl->rom_size); hw/display/qxl.c:1048: QXLRom *rom = memory_region_get_ram_ptr(&qxl->rom_bar); hw/display/qxl.c:2131: memory_region_init_rom(&qxl->rom_bar, OBJECT(qxl), "qxl.vrom", hw/display/qxl.c:2154: PCI_BASE_ADDRESS_SPACE_MEMORY, &qxl->rom_bar); hw/display/qxl.h:101: MemoryRegion rom_bar; hw/pci/pci.c:74: DEFINE_PROP_UINT32("rombar", PCIDevice, rom_bar, 1), hw/pci/pci.c:2329: if (!pdev->rom_bar) { hw/vfio/pci.c:1019: if (vdev->pdev.romfile || !vdev->pdev.rom_bar) { hw/xen/xen_pt_load_rom.c:29: if (dev->romfile || !dev->rom_bar) { include/hw/pci/pci_device.h:150: uint32_t rom_bar; rom_bar refers to a different variable in qxl. It is only tested if the value is 0 or not in the other places. If a user explicitly set UINT32_MAX, we still cannot distinguish that from the implicit default. However, it is unlikely to be a problem as nobody would type literal UINT32_MAX (0xffffffff or 4294967295) by chance. Signed-off-by: Akihiko Odaki --- hw/pci/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 84df07a2789b..cb5ac46e9f27 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, UINT32_MAX), - DEFINE_PROP_UINT32("rombar", PCIDevice, rom_bar, 1), + DEFINE_PROP_UINT32("rombar", PCIDevice, rom_bar, UINT32_MAX), DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present, QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false), DEFINE_PROP_BIT("x-pcie-lnksta-dllla", PCIDevice, cap_present, From patchwork Fri Mar 15 03:57:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13593045 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0B63BC54E66 for ; Fri, 15 Mar 2024 03:59:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkyib-000336-VU; Thu, 14 Mar 2024 23:58:54 -0400 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 1rkyiY-0002vt-DD for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:50 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rkyiR-00027Y-28 for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:49 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6e6ca2ac094so1581111b3a.0 for ; Thu, 14 Mar 2024 20:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1710475121; x=1711079921; 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=oLo7FjY3sQapHlGUhu+VfIZ4mAq3zY4BNX3rIrtFMUM=; b=AgCYTazLLbNC9L8xeqxlx+IyM7FWYgslaxBAJ26NBRPVXR82Z2Nl/CWf6c8B8s/VU3 XlYu5wQrk8tddn51pRvmrK7MxLZXq7nAeIk5kYCHjQUtfO99HTM3Y1JqyNP5pb/6e3Xo 21iHry9h1Nr6mowQr8b+qQpP+BdXM2hhB4NSPEi14dEqiuBOiiiBqUxYeQ5mzGCmw2AH 7yXBVy7CVPJXQr2SLUluUINSQ6YcHU05n3jQFSo6w9ywczG1zMudHWvsUGhE/IlHwlp4 bh3pyo7Blu0enerrp/HSgHWR4+k+CnwrtXuaVqeleTjzlicJsq2EplXUyWl4xvBLC6gy Zkog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710475121; x=1711079921; 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=oLo7FjY3sQapHlGUhu+VfIZ4mAq3zY4BNX3rIrtFMUM=; b=GY5glCvjYdRf9K4ryAyse7zocbBhRYz6e7tqjI1XL/B9OXmQCIr30t3zxXZwXo6m71 jeWj3uHN8usGxIonlNg2tzBjyTof0ZUiSmKrcskXNZ+OBXE0o68do5TYTTJL8FDIIT41 BGCy48QNUPLZxYtY+YgYnF6NvMudMbpeeFkNnClsu88MnzOHXhoN/PwAEwxX/dlsH9BN HoKfa5W1+XzwHtxgtej9mFc5+CbX1qkLGQFfbtUKHkJBu96xKSD8bjQGD5NcS9XKt/Ez sTGqn4tJfVTal/q5/xm9X4OMsbDPT8qrO3NWSOhMTnLRZ536hX8y4PVUC3hjABuioObQ ww4g== X-Gm-Message-State: AOJu0Yzt3Sugvw1qOnRqQBPHy7RofbC/mxPpzHGRE2CC6aRi+8uON8Gg d8n1pjUmtWv+IqIBRLkL9JlQ+SEewi4MAMmFaRq0h0bv2uWTBAbxWx6dzO/Cx4nnD8pu1CV96/e 5 X-Google-Smtp-Source: AGHT+IFPbjf86OGs/CjfALsurWtt2/8U0OS+FF/bIPdmxeWiKVYOiN2lOHxCMXQGbdELl9Q54lthdQ== X-Received: by 2002:a05:6a00:181f:b0:6e6:767f:f807 with SMTP id y31-20020a056a00181f00b006e6767ff807mr4370583pfa.10.1710475121530; Thu, 14 Mar 2024 20:58:41 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id y125-20020a62ce83000000b006e6b2ba1577sm2434280pfg.138.2024.03.14.20.58.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Mar 2024 20:58:41 -0700 (PDT) From: Akihiko Odaki Date: Fri, 15 Mar 2024 12:57:57 +0900 Subject: [PATCH for 9.1 v9 10/11] hw/pci: Determine if rombar is explicitly enabled MIME-Version: 1.0 Message-Id: <20240315-reuse-v9-10-67aa69af4d53@daynix.com> References: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> In-Reply-To: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> To: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "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 , Sriram Yagnaraman , Jason Wang , Keith Busch , Klaus Jensen , Markus Armbruster Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::430; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x430.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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. Add an infrastructure to determine if rombar is explicitly enabled to hw/pci. This changes the semantics of UINT32_MAX, which has always been a valid value to explicitly say rombar is enabled to denote the implicit default value. Nobody should have been set UINT32_MAX to rombar however, considering that its meaning was no different from 1 and typing a literal UINT32_MAX (0xffffffff or 4294967295) is more troublesome. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci_device.h | 5 +++++ hw/vfio/pci.c | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index ca151325085d..6be0f989ebe0 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 dev->rom_bar && dev->rom_bar != UINT32_MAX; +} + static inline void pci_set_power(PCIDevice *pci_dev, bool state) { /* diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 64780d1b7933..8708d2c1e2a2 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1012,7 +1012,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; @@ -1046,7 +1045,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 Fri Mar 15 03:57:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13593049 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 44B35C54E58 for ; Fri, 15 Mar 2024 04:00:07 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkyie-0003AU-V6; Thu, 14 Mar 2024 23:58:56 -0400 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 1rkyib-00033M-Sc for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:53 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rkyiY-0002Ao-3r for qemu-devel@nongnu.org; Thu, 14 Mar 2024 23:58:52 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6e6b54a28d0so1465647b3a.2 for ; Thu, 14 Mar 2024 20:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1710475127; x=1711079927; 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=H7E9EG3dQmBUyTgcienZoEqzuD43Z4lt38iAA+Vg5x8=; b=s7B5hDwZOSTh5sJF8xG0kWX9SllzSvH99xMXeYB+JTcudGgC16kTTOhwV+ljh//F3I fmn6+r8FS4Ze6wzi5Wt1nQlkMLqtjvkX8mlcEGCaPOqQTJIRcnOJIcKx6b/koOcbNdka /2iWITcRAPL1BH247GQnyN2eS7X77NujoyHuyivXM2gHmFm2Um09GijIiuXZMkUKuX1w UUBVMKQegjzOAMtT1uoAnrjMmEPeTUDabpsEIHD7ZzpHsPB9/1G3cDgYQJAfnrl0VaR4 hfe8utVAx0g2EJ35HRI5SGja4H32EOCKEcHWdozQ9wYVF9ndyPuGN6faSMIzmbxzTsHe EtDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710475127; x=1711079927; 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=H7E9EG3dQmBUyTgcienZoEqzuD43Z4lt38iAA+Vg5x8=; b=l9TVM5zunvO3h37Tht5F1zSghPncJvzxzxfj3cx8bdI4cnV8ohV9vfDiy1DhbxaqHH zX3U0yjGjPzQE24I/G8/oHYA7zFg8vZmSMuMelXXoYyXltauTyTi4gfmiZ+1qL0+4IjT im3Q4II1FblqNxoBqJz4o0tWrmXaWoIlWPIjwGrkHXEhYP7v75yE7MM1wfZ3zI4MDDHn 0jha11ZZaWds23jcvB5JO74kiCcSf0UP/igV7F9ZFWIYwV5e069K544rKLPY+Ya8UaMY kwUx13PPpdS73z36d9X2iwuI1MOEQNB/ahNjc+Xo4k9fCr/5q/dBZqBA0Dl5yzayvbD4 ud0Q== X-Gm-Message-State: AOJu0YyIWqlzvHzzrKHLiAI1Vp511JwhWJehWO+09N1zI68ZluV3lCjU U1eI35V0L/eTxZNgJU4GKf1orjNx+T/hUZY69KG1AnSptkfU0QOrZGQRpBswTYg= X-Google-Smtp-Source: AGHT+IEc5a39ura361pMdIfLf4Is7ZrDwERnRR5ici/jr9CQxuauaUYCmzUY1/y1sN4P3SyTtRlYFQ== X-Received: by 2002:a05:6a20:9191:b0:1a1:8c5e:874f with SMTP id v17-20020a056a20919100b001a18c5e874fmr2591860pzd.57.1710475126369; Thu, 14 Mar 2024 20:58:46 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id u7-20020a170902b28700b001dbcfb23d6csm2583479plr.267.2024.03.14.20.58.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Mar 2024 20:58:46 -0700 (PDT) From: Akihiko Odaki Date: Fri, 15 Mar 2024 12:57:58 +0900 Subject: [PATCH for 9.1 v9 11/11] hw/qdev: Remove opts member MIME-Version: 1.0 Message-Id: <20240315-reuse-v9-11-67aa69af4d53@daynix.com> References: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> In-Reply-To: <20240315-reuse-v9-0-67aa69af4d53@daynix.com> To: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "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 , Sriram Yagnaraman , Jason Wang , Keith Busch , Klaus Jensen , Markus Armbruster Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::42a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42a.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org It is no longer used. Signed-off-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Markus Armbruster --- include/hw/qdev-core.h | 4 ---- hw/core/qdev.c | 1 - system/qdev-monitor.c | 12 +++++++----- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 9228e96c87e9..5954404dcbfe 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 c68d0f7c512f..7349c9a86be8 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 c1243891c38f..6bcf5e23e6de 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -624,6 +624,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) { @@ -704,13 +705,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; }