From nobody Mon May 13 23:26:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709120059; cv=none; d=zohomail.com; s=zohoarc; b=hGVz8I4MwyYdxgOf61OMhFu2CnCk9l0Ye1bx/KiWX3rn/erG1tRVsOsSow4+JT3PYN1VnAILcUMEzts4bKZbMdCHxrWEVs+8SOKg7JPYzwxebaAZr71cr1I79Xlakr5Oq/fVP1zM8JSxT/ddp+ezGaamU70Vdv+ySl4yOWY7mmw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120059; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WM47wdy4Cb/mp1eobpOxgb3rFoDQbhprTWLPDZcJhAo=; b=HBjzTha56ZJ+4dbnGYWkzb+88FQmAL/iu4eGEKGXPHNA9fcxhDRJAgXvz1TnK8WJPce6Ro/r9b5t5YewVTGnkRAQ3Brm3zhE6gILI2daVv7jaVqH8g/7m3fJdrd9BzVtQBqcSTt/fsYNOKbB30R73X/xrtzwtJxaExfrc8lJd+w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120058971365.40570309812335; Wed, 28 Feb 2024 03:34:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfIC9-0000ga-74; Wed, 28 Feb 2024 06:33:53 -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 1rfIBz-0000bI-Hk for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:33:48 -0500 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfIBs-0006YA-Kf for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:33:43 -0500 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1dc418fa351so5459055ad.1 for ; Wed, 28 Feb 2024 03:33:34 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id jz5-20020a170903430500b001dc41904d3bsm3128601plb.61.2024.02.28.03.33.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Feb 2024 03:33:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709120013; x=1709724813; 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=WM47wdy4Cb/mp1eobpOxgb3rFoDQbhprTWLPDZcJhAo=; b=LdOcJL84pER8wpeoTjZpI8Pt7UUv7JwzG8WuxghqnUKLhyBPqts25BFFGVB5j4dlTr wJEiRE3owiGAOsR8mwDNWG+Yeyz8valATi+PguO+OFnaH6NdBWhe8blVd3otMZPhuNzP YYIruPV549hv9A3rGx0bvcf3x0Q3M14/g2UcmwdD4+dtcpq+HC38AgVupmFX99qcsF7p I3zDUhWu0iBAzivCRZNWrDk6hy3yCmi46h/sybA9gsAoc8M+6gX7BVw6IDXNcStNN7N6 2hTVxjONF7L0Lx+UHZCs30PtHn8qMjM57/hjbgqVTZv3NbLdFVF7+AvNJoHM902b2muQ Sasw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120013; x=1709724813; 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=WM47wdy4Cb/mp1eobpOxgb3rFoDQbhprTWLPDZcJhAo=; b=xDE4cp0WRfJeP6+ss94Dw+ipiRkjUxVcmajtThZSF98Y29kn/7DlyOPCeWSE8xTYvN RJHhy/IPxquv7kTmRnCwZzayuprQtxKXlkSD384XleT2K5tBu3iOHBC4vzIz+KGJpKyP ++z/8vTzareZRRCknrkRpN1IlC6C7GE/uaXMwoQ381zfUpgFM3zVZt0f+w68st3Hoi4+ lu1X0cOQI9ekZsDikiMXBbzxcycoglYdXQTwlwsrZKD0XK+eDR7N/XlOd0UHQtYZMefp o5jjrxRB/jWxIYERYM8FlIQKlRj9V7n5a0Z/8ypNeV6UI31Uvx7E1UOMCQpPmlfkjSEs yXdQ== X-Gm-Message-State: AOJu0YxQiLtKupR/CGBBToAGvBnbEQTLjOnRRun0WQuWBIOYy5g467wN 8grkRxnS3ByMjbaLJxDpj4lWTeVBATj7OG2e/fhbnCZsFW3e47cU8I/7CpS594g= X-Google-Smtp-Source: AGHT+IGQpgps2S10/Nvj6qmU4b+svH/KrNWP4jZCGiGnOlKRhuNBcpWRl2cAJy8oAqpf9d3M9OvMXA== X-Received: by 2002:a17:903:234a:b0:1db:b8dc:a016 with SMTP id c10-20020a170903234a00b001dbb8dca016mr2949665plh.7.1709120013303; Wed, 28 Feb 2024 03:33:33 -0800 (PST) From: Akihiko Odaki Date: Wed, 28 Feb 2024 20:33:12 +0900 Subject: [PATCH v8 01/15] hw/nvme: Use pcie_sriov_num_vfs() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240228-reuse-v8-1-282660281e60@daynix.com> References: <20240228-reuse-v8-0-282660281e60@daynix.com> In-Reply-To: <20240228-reuse-v8-0-282660281e60@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_Goater?= , 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 , qemu-stable@nongnu.org X-Mailer: b4 0.12.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::633; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x633.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709120060758100003 nvme_sriov_pre_write_ctrl() used to directly inspect SR-IOV configurations to know the number of VFs being disabled due to SR-IOV configuration writes, but the logic was flawed and resulted in out-of-bound memory access. It assumed PCI_SRIOV_NUM_VF always has the number of currently enabled VFs, but it actually doesn't in the following cases: - PCI_SRIOV_NUM_VF has been set but PCI_SRIOV_CTRL_VFE has never been. - PCI_SRIOV_NUM_VF was written after PCI_SRIOV_CTRL_VFE was set. - VFs were only partially enabled because of realization failure. It is a responsibility of pcie_sriov to interpret SR-IOV configurations and pcie_sriov does it correctly, so use pcie_sriov_num_vfs(), which it provides, to get the number of enabled VFs before and after SR-IOV configuration writes. Cc: qemu-stable@nongnu.org Fixes: CVE-2024-26328 Fixes: 11871f53ef8e ("hw/nvme: Add support for the Virtualization Managemen= t command") Suggested-by: Michael S. Tsirkin Signed-off-by: Akihiko Odaki --- hw/nvme/ctrl.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index f026245d1e9e..7a56e7b79b4d 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -8466,36 +8466,26 @@ static void nvme_pci_reset(DeviceState *qdev) nvme_ctrl_reset(n, NVME_RESET_FUNCTION); } =20 -static void nvme_sriov_pre_write_ctrl(PCIDevice *dev, uint32_t address, - uint32_t val, int len) +static void nvme_sriov_post_write_config(PCIDevice *dev, uint16_t old_num_= vfs) { NvmeCtrl *n =3D NVME(dev); NvmeSecCtrlEntry *sctrl; - uint16_t sriov_cap =3D dev->exp.sriov_cap; - uint32_t off =3D address - sriov_cap; - int i, num_vfs; + int i; =20 - if (!sriov_cap) { - return; - } - - if (range_covers_byte(off, len, PCI_SRIOV_CTRL)) { - if (!(val & PCI_SRIOV_CTRL_VFE)) { - num_vfs =3D pci_get_word(dev->config + sriov_cap + PCI_SRIOV_N= UM_VF); - for (i =3D 0; i < num_vfs; i++) { - sctrl =3D &n->sec_ctrl_list.sec[i]; - nvme_virt_set_state(n, le16_to_cpu(sctrl->scid), false); - } - } + for (i =3D pcie_sriov_num_vfs(dev); i < old_num_vfs; i++) { + sctrl =3D &n->sec_ctrl_list.sec[i]; + nvme_virt_set_state(n, le16_to_cpu(sctrl->scid), false); } } =20 static void nvme_pci_write_config(PCIDevice *dev, uint32_t address, uint32_t val, int len) { - nvme_sriov_pre_write_ctrl(dev, address, val, len); + uint16_t old_num_vfs =3D pcie_sriov_num_vfs(dev); + pci_default_write_config(dev, address, val, len); pcie_cap_flr_write_config(dev, address, val, len); + nvme_sriov_post_write_config(dev, old_num_vfs); } =20 static const VMStateDescription nvme_vmstate =3D { --=20 2.43.2 From nobody Mon May 13 23:26:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709120074; cv=none; d=zohomail.com; s=zohoarc; b=TbR0dIv/ggRTEXJGPCC4dvwF7a/t4DYOJ8zOfRNzTfDo18k4WPmh7mM5xkbt6HUyB1vS+EB0J7RzMqWGWE33egYN9T2fAUR/2htmxIUJvVMmwo+2gXv2ukl0Ekwh5BrEvkfh1mmphi6bQzV8WLGP9PuOG5aL0M+qyAunfBf0ALY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120074; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XAlWXKGj/Qs8kksBVXE9dWWgaRg5MiFxbRpTNiPgudE=; b=IW8PNc8bifnAJDCm3dL/0IkebyhXAmArvt46/h6GkT17xHnr0fdYYhG1XVcjb8EbJdBRr20v1GunxPI9/c7cPuIeivpUYMP+AR8UrdY+b+/MXv0uLeDNZtEk9P/QijpE1qVIyO2E8lkT0pPeRurG/70D37TtLAnMboW2xu3oRi4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120073903924.9414246573263; Wed, 28 Feb 2024 03:34:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfICB-0000ip-V8; Wed, 28 Feb 2024 06:33:56 -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 1rfIC3-0000c6-O3 for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:33:48 -0500 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfIBw-0006mm-Qa for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:33:46 -0500 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-5dbf7b74402so4279427a12.0 for ; Wed, 28 Feb 2024 03:33:39 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id sy12-20020a17090b2d0c00b00296f4fc7e60sm1371368pjb.12.2024.02.28.03.33.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Feb 2024 03:33:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709120019; x=1709724819; 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=XAlWXKGj/Qs8kksBVXE9dWWgaRg5MiFxbRpTNiPgudE=; b=KQUEQMshagDzEoYZ9GG73q2nHRIlEIbIa6QJfJbbEcEobgGrt4h8YU5fqBO9xeRNTI gfWsyoGqg8OsOCfOKw6v/HUkEfV+9uGAQWg/Qgo9Xtm4ih5PKG0H71UPcvTdit0O+MR/ KFkcmD108S1U6TNly1sEed8p9oNOf9g3z4DkEctII+Wq6jIyjQejsyt3iL/7dTlkSHmq p/i21C3toAVuhlb+IFdQW0HdAkbqNPkZzSS4zxRp6XvYWGLe8Rm9gQbWsHBlSscuBKhq WBEEian009EJjklzB9YinUBuyqO8avHY4vKYN2O3s/ewQ4D2Kjr8VJ4mYF7PtceD/8sQ yw6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120019; x=1709724819; 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=XAlWXKGj/Qs8kksBVXE9dWWgaRg5MiFxbRpTNiPgudE=; b=d7hLM5kO2XvEr7n61UyeRk2N/6j3L7sG9BSdXknrm7s2bzRqthGuJl0S1mioG2ixJ0 tcUetrJIdbzfPC3LLsVs4uUy6/lGB519g1TypZ2HZJJ4idbg19p4uigxKwxn5U4UYotH jYwGUtnWE6qXTNJJWefflBO08WDE1S73f6xKS8nkrhW/h70Mz8etPE4icBTyOAgq+a85 Ta/rKEuxs1usE5EITpR9Qg7AO/LWQqBYi5FQe/UuTTmhdmrrcdWkhWdICR5WTDsUQOYM /xqRvKzMaiMDjPaaCGTDbrhAcQuRgIy6efSgz+2lOJZiWmE255alDYf5ykp7CzU5i5CL uvDA== X-Gm-Message-State: AOJu0YyzfKfZzgsrQsINTt6kLbwUoxQEjdgoAt6kEJX69X3xEq9e++bI H3RTVY6WI0eJZN7wqHputpNF4kWbTlU02ZgkHqFro3NlTQDc82o2cbbb8pecF0o= X-Google-Smtp-Source: AGHT+IHUCKL+RRgnVKgUePt5+zVino+WeuA+cSJ01uo48yXZN4JQzMAr3YWGiQHX4aOj+vAGNGp9cQ== X-Received: by 2002:a05:6a21:6315:b0:1a1:139d:bdf1 with SMTP id wu21-20020a056a21631500b001a1139dbdf1mr3414867pzb.56.1709120018857; Wed, 28 Feb 2024 03:33:38 -0800 (PST) From: Akihiko Odaki Date: Wed, 28 Feb 2024 20:33:13 +0900 Subject: [PATCH v8 02/15] pcie_sriov: Validate NumVFs MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240228-reuse-v8-2-282660281e60@daynix.com> References: <20240228-reuse-v8-0-282660281e60@daynix.com> In-Reply-To: <20240228-reuse-v8-0-282660281e60@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_Goater?= , 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 , qemu-stable@nongnu.org X-Mailer: b4 0.12.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::52d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x52d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709120074791100005 The guest may write NumVFs greater than TotalVFs and that can lead to buffer overflow in VF implementations. Cc: qemu-stable@nongnu.org Fixes: CVE-2024-26327 Fixes: 7c0fa8dff811 ("pcie: Add support for Single Root I/O Virtualization = (SR/IOV)") Signed-off-by: Akihiko Odaki Reviewed-by: Sriram Yagnaraman --- hw/pci/pcie_sriov.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index a1fe65f5d801..da209b7f47fd 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -176,6 +176,9 @@ static void register_vfs(PCIDevice *dev) =20 assert(sriov_cap > 0); num_vfs =3D pci_get_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF); + if (num_vfs > pci_get_word(dev->config + sriov_cap + PCI_SRIOV_TOTAL_V= F)) { + return; + } =20 dev->exp.sriov_pf.vf =3D g_new(PCIDevice *, num_vfs); =20 --=20 2.43.2 From nobody Mon May 13 23:26:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709120222; cv=none; d=zohomail.com; s=zohoarc; b=DjXrI9ELgfMelNMKSTLPrg09lccXaLfICeKvBhEt86OLW5cbzFZ642bq35sp0eCVPEgn/o3PGYQV6w5t7bYhbQhHWlzguUHxyKKoj2cerHxOoJbQciIycr/tB58JS/9TwAmDvWNOOxJ0AAbOgzlemwotwwPSf6jxLyrY/9NH4/4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120222; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CWn2MCi797aQrb9iMuPcNohCGcLthp8Y3kdNV7UN6ps=; b=hso7nfcPk8lJaCxw31V2u4dIqdStSeSsoZpkH4iXxD9WcnIq5fO7buIYvgIlUDuPArY6Qxin7kHKwrSRt1/Bj9eC6xOM/BMcGoixTcK7JND6MCvVjTopQU262uasNy98f7R/+V1HVpaKK8orU47Cnvg5S9XInTAbPq2SxruUJpQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120222905493.25753008193806; Wed, 28 Feb 2024 03:37:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfICA-0000he-7K; Wed, 28 Feb 2024 06:33:54 -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 1rfIC4-0000d2-Tx for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:33:51 -0500 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfIC2-000758-In for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:33:48 -0500 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-29a858a0981so3565837a91.0 for ; Wed, 28 Feb 2024 03:33:45 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id y33-20020a17090a53a400b0029ab5abcbe1sm1479420pjh.20.2024.02.28.03.33.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Feb 2024 03:33:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709120024; x=1709724824; 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=CWn2MCi797aQrb9iMuPcNohCGcLthp8Y3kdNV7UN6ps=; b=1aX+GV9jaPStVC6hHP1JJBGsGkzYASSnedunJI9qctj1YVoEWZuTKl/YLhm0fsrVch /SxGAqB4RaoVHZrKjcPtPd7KkOqEcKUATiTzmrykwOV2nf0gieSnxS+yxaCOZAr4vJ+g kQlP7gKnOwvzbj6gUCo8oa/w++RFV+rvoQs31FWK91rfWwQ3UFdeHPq4TOYKOh6w7fLh cBH3ahEQP0Haf8G9/ZGEyo+8M8/QiN+Fk5kUNeO4myjsPbaXP6VppGOdmn0eVzeW6xM9 ytec0HWOKmjDo5frx6hwOkP5IwBtLzRaQf9AGs6S6dKnmcDF6Hii6jghDVHwDLq0ri9T kjTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120024; x=1709724824; 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=CWn2MCi797aQrb9iMuPcNohCGcLthp8Y3kdNV7UN6ps=; b=kwgT6nL4driz4gJfJfdzTsSRsHMbiVdctGoKSqYdWcU03LihNqV0UxLnrgTlufvO4J N3sl8IQz0uJa7WCT2815BMzwylCfcxCj1qPkpzYFDN6BcsFdWMNpU5AcUj5RQwBTbNCH rBTvkuYqcnfbA9VwsMrHxNvvf0l5Wuh5Rhz/mTDkhzbE7cC9ernAbdB4sCsk2wvtKeh7 OAQb8Ry39HE6cvSIFVHVGLSbGX9wX9NKQeJZQ9jqqg1aR0mcTbac3kUhxBOLLAJJSUML CuMQMVU47e1mH9r5QN5J3+zFpv6hDA5C1RHNuM2RhSIhd/2S1x/oZR03dqFpWdphLFsR qEmA== X-Gm-Message-State: AOJu0YwquV6CGXd0Ew/L/n/i2iHgr5fSXNTAhF0ssqtS3KqbyJXYbkqB U4KbZb5tzONChuuhAT7uFs5zw36vu4X+77/7cOIwwFAhD11CJ/veps5HDpZ48ys= X-Google-Smtp-Source: AGHT+IHwgwi26XEQx6gP5z79C8pLaugSOP1j+hBDSgmWxfW4foRaSMSHNVoKmB1Wi0QD/m3c2/uUFA== X-Received: by 2002:a17:90a:fd8c:b0:299:d17:a558 with SMTP id cx12-20020a17090afd8c00b002990d17a558mr11286386pjb.21.1709120024046; Wed, 28 Feb 2024 03:33:44 -0800 (PST) From: Akihiko Odaki Date: Wed, 28 Feb 2024 20:33:14 +0900 Subject: [PATCH v8 03/15] pcie_sriov: Reset SR-IOV extended capability MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240228-reuse-v8-3-282660281e60@daynix.com> References: <20240228-reuse-v8-0-282660281e60@daynix.com> In-Reply-To: <20240228-reuse-v8-0-282660281e60@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_Goater?= , 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: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::102b; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x102b.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709120223390100001 pcie_sriov_pf_disable_vfs() is called when resetting the PF, but it only disables VFs and does not reset SR-IOV extended capability, leaking the state and making the VF Enable register inconsistent with the actual state. Replace pcie_sriov_pf_disable_vfs() with pcie_sriov_pf_reset(), which does not only disable VFs but also resets the capability. Signed-off-by: Akihiko Odaki Reviewed-by: Sriram Yagnaraman --- include/hw/pci/pcie_sriov.h | 4 ++-- hw/net/igb.c | 2 +- hw/nvme/ctrl.c | 2 +- hw/pci/pcie_sriov.c | 26 ++++++++++++++++++-------- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/include/hw/pci/pcie_sriov.h b/include/hw/pci/pcie_sriov.h index 095fb0c9edf9..b77eb7bf58ac 100644 --- a/include/hw/pci/pcie_sriov.h +++ b/include/hw/pci/pcie_sriov.h @@ -58,8 +58,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); =20 -/* Reset SR/IOV VF Enable bit to unregister all VFs */ -void pcie_sriov_pf_disable_vfs(PCIDevice *dev); +/* Reset SR/IOV */ +void pcie_sriov_pf_reset(PCIDevice *dev); =20 /* Get logical VF number of a VF - only valid for VFs */ uint16_t pcie_sriov_vf_number(PCIDevice *dev); diff --git a/hw/net/igb.c b/hw/net/igb.c index 0b5c31a58bba..9345506f81ec 100644 --- a/hw/net/igb.c +++ b/hw/net/igb.c @@ -493,7 +493,7 @@ static void igb_qdev_reset_hold(Object *obj) =20 trace_e1000e_cb_qdev_reset_hold(); =20 - pcie_sriov_pf_disable_vfs(d); + pcie_sriov_pf_reset(d); igb_core_reset(&s->core); } =20 diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 7a56e7b79b4d..7c0d3f108724 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -7116,7 +7116,7 @@ static void nvme_ctrl_reset(NvmeCtrl *n, NvmeResetTyp= e rst) } =20 if (rst !=3D NVME_RESET_CONTROLLER) { - pcie_sriov_pf_disable_vfs(pci_dev); + pcie_sriov_pf_reset(pci_dev); } } =20 diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index da209b7f47fd..51b66d1bb342 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -249,16 +249,26 @@ void pcie_sriov_config_write(PCIDevice *dev, uint32_t= address, } =20 =20 -/* Reset SR/IOV VF Enable bit to trigger an unregister of all VFs */ -void pcie_sriov_pf_disable_vfs(PCIDevice *dev) +/* Reset SR/IOV */ +void pcie_sriov_pf_reset(PCIDevice *dev) { uint16_t sriov_cap =3D dev->exp.sriov_cap; - if (sriov_cap) { - uint32_t val =3D pci_get_byte(dev->config + sriov_cap + PCI_SRIOV_= CTRL); - if (val & PCI_SRIOV_CTRL_VFE) { - val &=3D ~PCI_SRIOV_CTRL_VFE; - pcie_sriov_config_write(dev, sriov_cap + PCI_SRIOV_CTRL, val, = 1); - } + if (!sriov_cap) { + return; + } + + pci_set_word(dev->config + sriov_cap + PCI_SRIOV_CTRL, 0); + unregister_vfs(dev); + + /* + * Default is to use 4K pages, software can modify it + * to any of the supported bits + */ + pci_set_word(dev->config + sriov_cap + PCI_SRIOV_SYS_PGSIZE, 0x1); + + for (uint16_t i =3D 0; i < PCI_NUM_REGIONS; i++) { + pci_set_quad(dev->config + sriov_cap + PCI_SRIOV_BAR + i * 4, + dev->exp.sriov_pf.vf_bar_type[i]); } } =20 --=20 2.43.2 From nobody Mon May 13 23:26:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709120211; cv=none; d=zohomail.com; s=zohoarc; b=JB7qjsulyspG/JU2N6woOkR1yxM8zmxX2firgD19qrKMyEbmjgU/iKL0a1VaIjFxBPvTH/FSRBsZDJWgXz/2zhmmJE7fR6tWxn9hJi3NRl+QUPKF6ua7DLmzaHXkWkoEy/mDVichcUSc4Z0QLHTs8VYWDWbPy6yi188rEfjVpco= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120211; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=H8o4sAtnRR5uX1iMzz8pEZTUAdiHV73SVw/pyfxc/jI=; b=I75QwfCsaTE0+VbQEdSUGwVCOVLBKs2b15UHyIbO/FXCNeTXgUqfXE+a5hutbRYDAtGBnS7zH2/YL6YFrEmN2KX5M4dkkFKwCl1bbLWSFNJxpRtvxA2HlkRVhkVuBsIQi1SB5M6z/DX/fgEuM8nxZlNpdVASCYIqv5O824NPPnI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120211413237.81233843140956; Wed, 28 Feb 2024 03:36:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfICL-0000ls-39; Wed, 28 Feb 2024 06:34:05 -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 1rfICJ-0000lE-GO for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:03 -0500 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 1rfIC6-00079R-DF for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:03 -0500 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6e4d48a5823so4384448b3a.1 for ; Wed, 28 Feb 2024 03:33:50 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id r3-20020aa78443000000b006e4f1e6f145sm7642378pfn.33.2024.02.28.03.33.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Feb 2024 03:33:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709120029; x=1709724829; 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=H8o4sAtnRR5uX1iMzz8pEZTUAdiHV73SVw/pyfxc/jI=; b=qOcKG4p0PYDRpomqpOfQ+IZcyeGVpLaVeS7MzGR0eWk0HMhs3MVr7C9iaSaVr14dTi fomTRLktpMDVcL7C01WES/+QyVL1NqIIkgTXrJkBSWBw5VLjXJoQYfxkbO1g/8Yh9ICa qDqI1AhAeoNXCpbjDPPt+9dzxp1qhzZEp+1matJg80ahfnyRQfXyfSsaeXXTh+B9OW00 m2CTIXl2ABDFN2b7UjEaavsh+iUWQL6oVk4v3Swhs3xjdG2bfs20XMxG2IDNzftVZAI9 cs/IayyimWVeHRx1p9CuWuvo87fRUBqgb3aXhAPt2FIQnLTvAcK4SuR2ajd93fxXTdOR RAvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120029; x=1709724829; 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=H8o4sAtnRR5uX1iMzz8pEZTUAdiHV73SVw/pyfxc/jI=; b=QyVjjGZVNPKn8bl/SuxkmqL9GZiv3PVsQ8p78bTO/cyHfJLx7N1CHgNslr4l9pjyvQ TEp45PSj8XcxmfwS9iJ8RSIj2xIZFde88yvN0fVfJcwU/aN8mnsHdbGFTsQt+zIHWvYy hCT8JNAOiPDXxp2EpBVeTX5fAoNq9RMI8OrbBhCsXhMoch/Q5egwFUdUVdNULUYe79Qm bAAB2ptUUyPwp7aSMRgMA0J7JuI+wUyeLLYVnDKAqU1grN0JakyEh6TYVmznbPix6JQA 6ervGdEdxvjUFiAYwBPllQ/NjRsXk8sodQpbOsfK/snOqA5kXaQavRXyv4Pa2HJ+iAZM rooQ== X-Gm-Message-State: AOJu0Yy8Qm9LKj5/RRgKJrCR3Q5wvXon8PuU/qdZ/Nlfx0zrQ1vyELmV RSCxM58Tty0zVIYDycHX4wGu7wucrlyvNsbegG1JnnNYYvoed7co0mDV3bB0ktQ= X-Google-Smtp-Source: AGHT+IEVe2izAXn/PZVy96z14kgzilPuHyuFHoOLjXs8Hu/KR1x8qPSIyvBTovMk1Mj/DEa/WmTVMA== X-Received: by 2002:aa7:8814:0:b0:6e5:6589:f949 with SMTP id c20-20020aa78814000000b006e56589f949mr1051234pfo.1.1709120028762; Wed, 28 Feb 2024 03:33:48 -0800 (PST) From: Akihiko Odaki Date: Wed, 28 Feb 2024 20:33:15 +0900 Subject: [PATCH v8 04/15] pcie_sriov: Do not reset NumVFs after disabling VFs MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240228-reuse-v8-4-282660281e60@daynix.com> References: <20240228-reuse-v8-0-282660281e60@daynix.com> In-Reply-To: <20240228-reuse-v8-0-282660281e60@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_Goater?= , 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: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709120213286100003 The spec does not NumVFs is reset after disabling VFs except when resetting the PF. Clearing it is guest visible and out of spec, even though Linux doesn't rely on this value being preserved, so we never noticed. Fixes: 7c0fa8dff811 ("pcie: Add support for Single Root I/O Virtualization = (SR/IOV)") Signed-off-by: Akihiko Odaki --- hw/pci/pcie_sriov.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index 51b66d1bb342..e9b23221d713 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -215,7 +215,6 @@ static void unregister_vfs(PCIDevice *dev) g_free(dev->exp.sriov_pf.vf); dev->exp.sriov_pf.vf =3D NULL; dev->exp.sriov_pf.num_vfs =3D 0; - pci_set_word(dev->config + dev->exp.sriov_cap + PCI_SRIOV_NUM_VF, 0); } =20 void pcie_sriov_config_write(PCIDevice *dev, uint32_t address, @@ -260,6 +259,8 @@ void pcie_sriov_pf_reset(PCIDevice *dev) pci_set_word(dev->config + sriov_cap + PCI_SRIOV_CTRL, 0); unregister_vfs(dev); =20 + pci_set_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF, 0); + /* * Default is to use 4K pages, software can modify it * to any of the supported bits --=20 2.43.2 From nobody Mon May 13 23:26:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709120196; cv=none; d=zohomail.com; s=zohoarc; b=DSSl9CjyfwzYqKr70B+hBTXN3dBUyPQ/CRAp3SCPlIXgcCrm5xJA/TAS8XXjy+sqcYZFlPuZRkLNEahfpwz3wTmOjBv9/1bax3pspd2TZ+/ZmH+GudADMN0c0l/JFg7yiZD74ZprwSasrt0O2g2g7SMxO3DiK40a0/vbWMntyI4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120196; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NRg9XEk8ieabjRBH3umLjrDCheGnL9tHvYE3lVOEyqg=; b=jscqzxTu12RdLYe2Jw+0n2SluPreTePSTM7FVOi7PNssauH46TTDZ9ZGAfCiOL0or4RKjGz8151oK700OUUzuwxlcpLBtOx2NaPEaWcxFFAYBbnr4aCyjt8XNMaJspy587bvR7U32lxOnD70OnK8RSEEejGC6HvmoRO6sdEbWMc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120196517371.372200083243; Wed, 28 Feb 2024 03:36:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfICG-0000kE-BX; Wed, 28 Feb 2024 06:34: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 1rfICE-0000jy-QQ for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:33:58 -0500 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfICC-0007AQ-2w for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:33:58 -0500 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-5d8b887bb0cso4234079a12.2 for ; Wed, 28 Feb 2024 03:33:55 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id d19-20020a170902729300b001dccff4287csm239577pll.202.2024.02.28.03.33.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Feb 2024 03:33:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709120033; x=1709724833; 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=NRg9XEk8ieabjRBH3umLjrDCheGnL9tHvYE3lVOEyqg=; b=NuHlBjgfS37TUzdw61d+mZfKjKZ9L/teSXScVl72SR+Z0Nq0OYfJFEMqsg0Z3gLZ99 24qD6mnOFWQT9Fpm12nFEZFeuaelzcZcskmYKz470kCLqYgqJhKQFiEtgSGvhp2BnFUW Fkfv94IYD5NeQ9uz8CX0O/s1yfwZg4zdRIfalomNxoPbv2Xwi387JPCowUCbxuwMvdt5 Umo2/ELXui/r0sKAGhsM5CWaIM/WTvK+mgEa5CtbSqli1N8ey6CN5e3ikWNUtsQs5v2C +kOlTT61tH/ScVP1mITNLNDYUQgkI1Ii1yrqkgh03W+sBlbRGpG65KBcfm6x+aqr7q6M codg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120033; x=1709724833; 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=NRg9XEk8ieabjRBH3umLjrDCheGnL9tHvYE3lVOEyqg=; b=w9+nZiQOrnCx5dhQ6H7u3kdto+ds/oEqTDnVLI5dg67FiHqsHtU8uZlzocDNh7nwd2 GuSEpAEDT/zsyF4ebUopbfYfeheQjcJAoU+EMcrQzP8dy3PLpCHXUdvCv9BQvSAWbF9B OagNlZLCJtoATqNStSUU2cj8QEuCTSLToJnJbNIRnwqnmkgU7yk/IwBfZryURcEY52kf zRgx9k8D/PDkKf23KnOegZGrr+cxwhOeMib+QZEzVuE6gH6XJijJ6gOo1a93JNH3h51k XUSonji4Xmpqv5XUahzviBItTyIlz+Y9xk+qDQUxIem5cmHfBjn216fJUcZBIvqX7HC5 LEWw== X-Gm-Message-State: AOJu0YyfwdkvrhKXBGViAFS0VM52C7VeV9RBdBMEim2c/H8rkFBAk3kr FFp2YG2eFh8QPnXvTGI67QakfqQ6XbmJqhOXTJQsU393qzoOFlfk9Q0Tf0fPprM= X-Google-Smtp-Source: AGHT+IH1so2QMbXVySVNtchOocIJxnh+3DMvZLw2D6lXN8QMvGevJPtP1JyqT9J/1/zMGEvsadA5+w== X-Received: by 2002:a05:6a21:9204:b0:1a0:de5c:d02b with SMTP id tl4-20020a056a21920400b001a0de5cd02bmr6245225pzb.1.1709120033337; Wed, 28 Feb 2024 03:33:53 -0800 (PST) From: Akihiko Odaki Date: Wed, 28 Feb 2024 20:33:16 +0900 Subject: [PATCH v8 05/15] hw/pci: Always call pcie_sriov_pf_reset() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240228-reuse-v8-5-282660281e60@daynix.com> References: <20240228-reuse-v8-0-282660281e60@daynix.com> In-Reply-To: <20240228-reuse-v8-0-282660281e60@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_Goater?= , 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: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::533; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x533.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709120197204100001 Call pcie_sriov_pf_reset() from pci_do_device_reset() just as we do for msi_reset() and msix_reset() to prevent duplicating code for each SR-IOV PF. Signed-off-by: Akihiko Odaki Reviewed-by: Sriram Yagnaraman --- hw/net/igb.c | 2 -- hw/nvme/ctrl.c | 4 ---- hw/pci/pci.c | 1 + 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/hw/net/igb.c b/hw/net/igb.c index 9345506f81ec..9b37523d6df8 100644 --- a/hw/net/igb.c +++ b/hw/net/igb.c @@ -488,12 +488,10 @@ static void igb_pci_uninit(PCIDevice *pci_dev) =20 static void igb_qdev_reset_hold(Object *obj) { - PCIDevice *d =3D PCI_DEVICE(obj); IGBState *s =3D IGB(obj); =20 trace_e1000e_cb_qdev_reset_hold(); =20 - pcie_sriov_pf_reset(d); igb_core_reset(&s->core); } =20 diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 7c0d3f108724..c1af4b87b34a 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -7114,10 +7114,6 @@ static void nvme_ctrl_reset(NvmeCtrl *n, NvmeResetTy= pe rst) sctrl =3D &n->sec_ctrl_list.sec[i]; nvme_virt_set_state(n, le16_to_cpu(sctrl->scid), false); } - - if (rst !=3D NVME_RESET_CONTROLLER) { - pcie_sriov_pf_reset(pci_dev); - } } =20 if (rst !=3D NVME_RESET_CONTROLLER) { diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 6496d027ca61..e7a39cb203ae 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -409,6 +409,7 @@ static void pci_do_device_reset(PCIDevice *dev) =20 msi_reset(dev); msix_reset(dev); + pcie_sriov_pf_reset(dev); } =20 /* --=20 2.43.2 From nobody Mon May 13 23:26:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709120191; cv=none; d=zohomail.com; s=zohoarc; b=nT/TYlTMdgkJzy/5RaJO75DU8ymeuUAY7wVFiXT7NYSZS+GUGz/805p461VAN+PuWDKgS8wJM9S+Yrj0cjrbDQVagP/gvLB2Rw2H7LLyQnZeaaMRPNKLqip/7mvAPMb7KBDzwOHTyVp04pQEvp7oUyWQwznreXG6P8TpwpcR1BU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120191; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lyOTxnkcJD9Fch8p801dtN80LFjIP1Z0j9VlXnqzBNg=; b=k004u4Z0QkIOV16lZHnPt58YdTD8W0kH+jsaCLwesbuAm/iYs55qshjOJs77VVPNetLDuxQ2dVsXP/vFvyvWL3+w9w8tADXnb98ApkLl17XJn+trXk0LhzjUj13k1gmNLSIiy/vooMBLOIoy5VDmv1cEfdF+DB6Xvd92opX/djc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120191612512.4307197723431; Wed, 28 Feb 2024 03:36:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfICR-0000oU-0A; Wed, 28 Feb 2024 06:34:11 -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 1rfICP-0000nb-HX for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:09 -0500 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfICF-0007BH-VM for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:09 -0500 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-299e4b352cdso3952118a91.0 for ; Wed, 28 Feb 2024 03:33:59 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id p16-20020a17090b011000b00299e946b9cdsm1395862pjz.20.2024.02.28.03.33.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Feb 2024 03:33:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709120038; x=1709724838; 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=lyOTxnkcJD9Fch8p801dtN80LFjIP1Z0j9VlXnqzBNg=; b=Debzxpr0N3N4uMg4HqNkA9oF8htGmSIhSHyMBqENQQlU4Ypma+/Wgdwo++jFbF6kje MHd9AOyV0xbE2+WGq3lYiE3FkolFelxK3m2nUfXR1J5EjvgsTDpXYkJlg6Y9l/RhYdBg bwggo9/H+GB82jmaooO7USOHxhQNN7yctu9Mau2v7mxMvJXIK8C+dLVjDTAdUDEWWLen tlkkfe8WGAglX4SQ/cZs95hOtU5HbaHP9+k6CX4j/AeqnK37dZFS6guPTzpQjQXnNm1x HQwOXPm9VEHcBUzWo9OX5umdEXMkgPXC9FUrCTaErNbXD8RrhDuFw2kALPHALJJyYwLc 1CTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120038; x=1709724838; 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=lyOTxnkcJD9Fch8p801dtN80LFjIP1Z0j9VlXnqzBNg=; b=raZRKoClCAlYzF0KvtKAWB7pN4GYAiZokLRlA/xYtnLWxiYBVDTxJZvm90YjeZv/lj Fyn7jAGLIgu+0yYMO2fJ3JX4oPv1bK2HExWqwdrWC4ZTUILKLgimEdn45CBLYKSrntpj ywaY4WvnEF2YFX8XSLAa/D3Z1jiY1L41Y2gt8v9JeeJr3ZEozhAfNipf5vnzRmJOyS3/ T6FMl5/2posYJVmaVk6aoAlyLFnL+wyoRGEGAXeWkYbI/tjBjBV0HJ3VPDTdEkfJhx+n ypOo2gP+nNWwa3RgoihjdxJdyjryBjsOog0wPPBatrv+DeYmQQsjINlayqmRrXMkVsna V/Ig== X-Gm-Message-State: AOJu0YzJD++XDIBQt7KmFbdcL2Np+KMd+R8tm8yHllR9dPspfnLKc/2N 4Gzok5OEw/2j7QjZrM1lTYfo88Wjf0R4eth6NxnL6AHJZG4BKz2qC+kfrYO7YeE= X-Google-Smtp-Source: AGHT+IGoTzptUe/SFVSpTJ/FAwBpzKlGji+IbETZ1h+3nF9X2hr8jIRT5bdDthNJ4TU1DjqcArZZqg== X-Received: by 2002:a17:90a:7564:b0:29a:82c1:5ab0 with SMTP id q91-20020a17090a756400b0029a82c15ab0mr9487833pjk.44.1709120038574; Wed, 28 Feb 2024 03:33:58 -0800 (PST) From: Akihiko Odaki Date: Wed, 28 Feb 2024 20:33:17 +0900 Subject: [PATCH v8 06/15] hw/pci: Rename has_power to enabled MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240228-reuse-v8-6-282660281e60@daynix.com> References: <20240228-reuse-v8-0-282660281e60@daynix.com> In-Reply-To: <20240228-reuse-v8-0-282660281e60@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_Goater?= , 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: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::1036; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1036.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709120193206100001 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) } =20 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); +} =20 #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; =20 /* 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; =20 new_addr =3D pci_bar_address(d, i, r->type, r->size); - if (!d->has_power) { + if (!d->enabled) { new_addr =3D PCI_BAR_UNMAPPED; } =20 @@ -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); } =20 msi_write_config(d, addr, val_in, l); @@ -2811,18 +2811,18 @@ MSIMessage pci_get_msi_message(PCIDevice *dev, int = vector) return msg; } =20 -void pci_set_power(PCIDevice *d, bool state) +void pci_set_enabled(PCIDevice *d, bool state) { - if (d->has_power =3D=3D state) { + if (d->enabled =3D=3D state) { return; } =20 - d->has_power =3D state; + d->enabled =3D 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, uin= t32_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; } =20 @@ -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; } =20 --=20 2.43.2 From nobody Mon May 13 23:26:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709120095; cv=none; d=zohomail.com; s=zohoarc; b=WQof3NdmskNEqiKbg8Gqi1dOqOoU14kJSAcHDBQBEgNLGa7OXf9JcXM2gQ7KjD20yo2n7sGp1oObALCadnteLxCCFMRAXvu1/eiuqRCLJXCWbzOKH/JFjYvtFaREsE9d4qPl0tIkOUeXsAKZuMM5dSLfIm02NqPBLII++37DdHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120095; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Hp/9hxQDBtPEY0OINim6FUiDAX4NmkB4mD/jfDe7uLw=; b=QuGxvmQfiuddyWCZmj4ILgDIs0vtVjyVqbcO7qgtZYeKnC5QcDZ5tzvPHl9kIlJ+EnYY/qfH700oqFLqNqUYHEOLMH1UURdX38pvyjfnbX4KunwM/+ZoaK0wZ6g8zYJ+yT8DkUdIQhcuhsClIWwl0QUv3gKEFi96972ONgY+x9A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120095313240.2075328037123; Wed, 28 Feb 2024 03:34:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfICN-0000my-G2; Wed, 28 Feb 2024 06:34:07 -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 1rfICM-0000mH-4e for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:06 -0500 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfICK-0007DA-M5 for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:05 -0500 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-5cedfc32250so4948949a12.0 for ; Wed, 28 Feb 2024 03:34:04 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id s7-20020a170902a50700b001dcc2951c02sm1862556plq.286.2024.02.28.03.34.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Feb 2024 03:34:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709120043; x=1709724843; 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=Hp/9hxQDBtPEY0OINim6FUiDAX4NmkB4mD/jfDe7uLw=; b=tselFCSb7c9lCXfg8ryWxvCSozoqShwu9nESNdD42yWqS18B3Jan26R2uvqJ77oJJS fkcVFZCefE27jnC/0s3ksAK1G0rHaMZaNtDFX3il0q5561VUesTqhWmAcAnqzIquzPJT KCHoIm/aNyqX74yHi+6dpW8JCK8LOAowZnAsIydpZKtArQGMHMQyYR9mFZCXZAa68tBr oFYiP96Zc7ily49qvJFKYQxfQRU5m1xMCyVPhACZ27T5wpKhkaNvyIpQGU5L+IaNkq5F xXIkG+CyoAkqshiZ85ovBiQTxjnS7luEtevoDVojalcKwRQERkyeEp0wUH3N9gzltbfd dEQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120043; x=1709724843; 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=Hp/9hxQDBtPEY0OINim6FUiDAX4NmkB4mD/jfDe7uLw=; b=Cf7zbYAk8jFrD29BUUqgiAKS/sE/FhRicD9kq6+wnjorUXkSnhH7VdoXN7TLX749zn iMEypZ0UGWmnmPe9V/WgnSj4hS5+GvjVDQyLZI0HpMB4OfGUhYb/qNbyY4Nql1k/8ybG 0iB0g4GzR2ct/m5qYhm64ET0QlRCMdcvK7M9Rvn2zO/QD05XqvzMkOUC/HJOwSSzJtVd kOoE1aQ1RTWA4NEerHzUSuWEnJBmLRSRTKCr2HlrLaSY3N3NbL2swvdLUJj839RrNXUm EqZ+3eyDogFkl7nUwnNeckMYO1JDRqeJO7rksuqZLKANVJ0hCyONc9or8L0aM/vTBMDp 3dHg== X-Gm-Message-State: AOJu0YxHoFYXUnuXgs3E/NARyfTH54atYW68jf1OjI/ckPP23sT5pPtj VVpVY2wqcpc43GhlIsZ8FlnVTEvd6xj3VlYUB6B3tFCZfltBlDtl2sx9Tb+c8NI= X-Google-Smtp-Source: AGHT+IHlaoZemaOyDcT+bGEhmIXzIEUc6wR35siPff0S9uv4XJ3Ky0SdskY74qS5ErqKh7CUEyGXNA== X-Received: by 2002:a05:6a21:920b:b0:1a0:adbc:7a96 with SMTP id tl11-20020a056a21920b00b001a0adbc7a96mr5093298pzb.36.1709120043259; Wed, 28 Feb 2024 03:34:03 -0800 (PST) From: Akihiko Odaki Date: Wed, 28 Feb 2024 20:33:18 +0900 Subject: [PATCH v8 07/15] pcie_sriov: Do not manually unrealize MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240228-reuse-v8-7-282660281e60@daynix.com> References: <20240228-reuse-v8-0-282660281e60@daynix.com> In-Reply-To: <20240228-reuse-v8-0-282660281e60@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_Goater?= , 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: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::52b; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x52b.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709120096864100001 A device gets automatically unrealized when being unparented. Signed-off-by: Akihiko Odaki --- hw/pci/pcie_sriov.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index e9b23221d713..8b1fd2a89ad7 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -17,7 +17,6 @@ #include "hw/qdev-properties.h" #include "qemu/error-report.h" #include "qemu/range.h" -#include "qapi/error.h" #include "trace.h" =20 static PCIDevice *register_vf(PCIDevice *pf, int devfn, @@ -204,11 +203,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 =3D 0; i < num_vfs; i++) { - Error *err =3D NULL; PCIDevice *vf =3D 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)); } --=20 2.43.2 From nobody Mon May 13 23:26:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709120096; cv=none; d=zohomail.com; s=zohoarc; b=kEph2OiD1pSelue9cmjT8fQOppLli66nX3IJwUrN8jhFYVoTbL61FqzI1YyNfYlmZ3/2KePkfhWV3p/IHiwYSUcKmhvNZtNRrT7C7Qg95fATWBtI51iQE8wGdp9Ceo8z5w1Fg70X790UEEp9W17UC9EgvrYmXOheAMUxigio8zQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120096; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uV1ibXGMyFPSo4HdTqR65s4DN3sl3gXZLpAugg0lg1I=; b=LPBNHpfOF0GNZCZqEy5THfDLhn9hMPFenDMWhHB0TbClsl02jPDAa7vBXBDC/lrtOJJEXlZ+RKhK7mfjxJGIu62mrO763zcF92BErw3P13AuzJB2U3JWfBOnxDkjsh6sXaOg9osr8m0PYjlMes8atGROr6echbX/t+f3s3k9ZXM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120096749516.2893372770029; Wed, 28 Feb 2024 03:34:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfICU-0000sC-SC; Wed, 28 Feb 2024 06:34:14 -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 1rfICR-0000oo-D6 for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:11 -0500 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 1rfICP-0007EA-5p for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:11 -0500 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1dcafff3c50so23244255ad.0 for ; Wed, 28 Feb 2024 03:34:08 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id d17-20020a170902729100b001db7d3276fbsm3090628pll.27.2024.02.28.03.34.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Feb 2024 03:34:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709120048; x=1709724848; 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=uV1ibXGMyFPSo4HdTqR65s4DN3sl3gXZLpAugg0lg1I=; b=zUZco97oJEjIGGAoG3ymV1lcxYzlJe8Nwgr2bU8yGCkkxPH5sYbRcSW3KB+IOwMOd9 MhtdOW67FuFz+g2v/XWJO1tVPbKBALw1d1/ca//YWS+MPmqHdM089L8jws9W/bqhjVWt dMCydBkkIDRQoeGYQR2fpcTfs881tslmOnnkcaVkzbu+hNO47ZTIUm/xTvCxUJQI4sRK 9LtPvYlwvue0N2CoxHlgdiEaUGHZrPlo+PO3DStsv9FcjEtd/iQZKESjzNBlC5v0r05h zuNI/fHQbbWrWmkHpYyXU7YCkf0YfPaFaw7xTwsr7kOSeK6mx6/4/yEL+AEjv23TidDD 8tCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120048; x=1709724848; 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=uV1ibXGMyFPSo4HdTqR65s4DN3sl3gXZLpAugg0lg1I=; b=eXwLWzjqiVwBnteByV+YoLhdI0I8ebe3BcJKdzPcbPLxv5Es9H9pcHgzwvK4VfSw1j UD5KuZjoI/sbTxlAf+2lNYbDGjJP3Pf/Jn7JUQWgmOfa1bi8OluvqlgBtoFuR3bqoUCR YvFh1IA2p49uXZc31lzR3Os4fvHlJRa+pwemnx3cQLfrHrw2r0BabiRo+OvAeAr+4GOx fdu3rHr7egy1qp08Bt4R5Rm5KiGP5CqNixpelYFSJ7p6IjrkN2ouMygVsG1QS3BroOeD DmHgWMrlLzr9WcNGAyV67KJ76q9N8qocMOT5zpwLx6xmr66v0LCoSov0ZZ8uqqHZOYew 8nMw== X-Gm-Message-State: AOJu0YznagMpMMhy4i4PDKkC4uS7up6q8gjb1fwgisJsVZw/fS84fFUh qUTKfQXhJ7as1yzjEjQ4zOYZ5d+v6ppQLp9cFeuZECr7lJ49RvycXYym4ALEsCg= X-Google-Smtp-Source: AGHT+IGn+8vImIBL2w4kuW9E1/YPURgxEOX4Gp45QW2u4Lv1r8R8lVUyxGtMeeRDaLdC5/1LKe212g== X-Received: by 2002:a17:902:e74e:b0:1dc:211f:96d0 with SMTP id p14-20020a170902e74e00b001dc211f96d0mr18197370plf.3.1709120047945; Wed, 28 Feb 2024 03:34:07 -0800 (PST) From: Akihiko Odaki Date: Wed, 28 Feb 2024 20:33:19 +0900 Subject: [PATCH v8 08/15] pcie_sriov: Reuse SR-IOV VF device instances MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240228-reuse-v8-8-282660281e60@daynix.com> References: <20240228-reuse-v8-0-282660281e60@daynix.com> In-Reply-To: <20240228-reuse-v8-0-282660281e60@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_Goater?= , 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: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709120098919100005 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 --- docs/pcie_sriov.txt | 8 ++-- include/hw/pci/pci.h | 5 --- include/hw/pci/pci_device.h | 15 +++++++ include/hw/pci/pcie_sriov.h | 6 +-- hw/net/igb.c | 13 ++++-- hw/nvme/ctrl.c | 24 +++++++---- hw/pci/pci.c | 2 +- hw/pci/pcie_sriov.c | 102 +++++++++++++++++++---------------------= ---- 8 files changed, 95 insertions(+), 80 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. ... =20 /* 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; + } =20 /* Set up individual VF BARs (parameters as for normal BARs) */ pcie_sriov_pf_init_vf_bar( ... ) 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); =20 -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); } =20 +static inline void pci_set_power(PCIDevice *pci_dev, bool state) +{ + /* + * Don't change the enabled state of VFs when powering on/off the devi= ce. + * + * 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); =20 /* DMA access functions */ diff --git a/include/hw/pci/pcie_sriov.h b/include/hw/pci/pcie_sriov.h index b77eb7bf58ac..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 */ }; =20 @@ -27,10 +26,11 @@ struct PCIESriovVF { uint16_t vf_number; /* Logical VF number of this function */ }; =20 -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); =20 /* 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) =20 pcie_ari_init(pci_dev, 0x150); =20 - 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; + } =20 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 c1af4b87b34a..98c3e942077c 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -8027,7 +8027,8 @@ static uint64_t nvme_bar_size(unsigned total_queues, = unsigned total_irqs, return bar_size; } =20 -static void nvme_init_sriov(NvmeCtrl *n, PCIDevice *pci_dev, uint16_t offs= et) +static bool nvme_init_sriov(NvmeCtrl *n, PCIDevice *pci_dev, uint16_t offs= et, + Error **errp) { uint16_t vf_dev_id =3D n->params.use_intel_id ? PCI_DEVICE_ID_INTEL_NVME : PCI_DEVICE_ID_REDHAT_N= VME; @@ -8036,12 +8037,17 @@ static void nvme_init_sriov(NvmeCtrl *n, PCIDevice = *pci_dev, uint16_t offset) le16_to_cpu(cap->vifrsm), NULL, NULL); =20 - 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_v= fs, + NVME_VF_OFFSET, NVME_VF_STRIDE, + errp)) { + return false; + } =20 pcie_sriov_pf_init_vf_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64, bar_size); + + return true; } =20 static int nvme_add_pm_capability(PCIDevice *pci_dev, uint8_t offset) @@ -8120,6 +8126,12 @@ static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *pc= i_dev, Error **errp) return false; } =20 + 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); =20 if (n->params.cmb_size_mb) { @@ -8130,10 +8142,6 @@ static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *pc= i_dev, Error **errp) nvme_init_pmr(n, pci_dev); } =20 - if (!pci_is_vf(pci_dev) && n->params.sriov_max_vfs) { - nvme_init_sriov(n, pci_dev, 0x120); - } - return true; } =20 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 8b1fd2a89ad7..d934cd7d0e64 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -19,15 +19,25 @@ #include "qemu/range.h" #include "trace.h" =20 -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 =3D 0; i < total_vfs; i++) { + PCIDevice *vf =3D 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 =3D NULL; +} =20 -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) { + BusState *bus =3D qdev_get_parent_bus(&dev->qdev); + int32_t devfn =3D dev->devfn + vf_offset; uint8_t *cfg =3D dev->config + offset; uint8_t *wmask; =20 @@ -35,7 +45,6 @@ void pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, offset, PCI_EXT_CAP_SRIOV_SIZEOF); dev->exp.sriov_cap =3D offset; dev->exp.sriov_pf.num_vfs =3D 0; - dev->exp.sriov_pf.vfname =3D g_strdup(vfname); dev->exp.sriov_pf.vf =3D NULL; =20 pci_set_word(cfg + PCI_SRIOV_VF_OFFSET, vf_offset); @@ -68,13 +77,35 @@ void pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, pci_set_word(wmask + PCI_SRIOV_SYS_PGSIZE, 0x553); =20 qdev_prop_set_bit(&dev->qdev, "multifunction", true); + + dev->exp.sriov_pf.vf =3D g_new(PCIDevice *, total_vfs); + + for (uint16_t i =3D 0; i < total_vfs; i++) { + PCIDevice *vf =3D pci_new(devfn, vfname); + vf->exp.sriov_vf.pf =3D dev; + vf->exp.sriov_vf.vf_number =3D 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] =3D vf; + devfn +=3D vf_stride; + } + + return true; } =20 void pcie_sriov_pf_exit(PCIDevice *dev) { - unregister_vfs(dev); - g_free((char *)dev->exp.sriov_pf.vfname); - dev->exp.sriov_pf.vfname =3D NULL; + uint8_t *cfg =3D dev->config + dev->exp.sriov_cap; + + unparent_vfs(dev, pci_get_word(cfg + PCI_SRIOV_TOTAL_VF)); } =20 void pcie_sriov_pf_init_vf_bar(PCIDevice *dev, int region_num, @@ -140,38 +171,11 @@ void pcie_sriov_vf_register_bar(PCIDevice *dev, int r= egion_num, } } =20 -static PCIDevice *register_vf(PCIDevice *pf, int devfn, const char *name, - uint16_t vf_num) -{ - PCIDevice *dev =3D pci_new(devfn, name); - dev->exp.sriov_vf.pf =3D pf; - dev->exp.sriov_vf.vf_number =3D vf_num; - PCIBus *bus =3D pci_get_bus(pf); - Error *local_err =3D 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 =3D dev->exp.sriov_cap; - uint16_t vf_offset =3D - pci_get_word(dev->config + sriov_cap + PCI_SRIOV_VF_OFFSET); - uint16_t vf_stride =3D - pci_get_word(dev->config + sriov_cap + PCI_SRIOV_VF_STRIDE); - int32_t devfn =3D dev->devfn + vf_offset; =20 assert(sriov_cap > 0); num_vfs =3D pci_get_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF); @@ -179,18 +183,10 @@ static void register_vfs(PCIDevice *dev) return; } =20 - dev->exp.sriov_pf.vf =3D g_new(PCIDevice *, num_vfs); - trace_sriov_register_vfs(dev->name, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), num_vfs); for (i =3D 0; i < num_vfs; i++) { - dev->exp.sriov_pf.vf[i] =3D register_vf(dev, devfn, - dev->exp.sriov_pf.vfname, i); - if (!dev->exp.sriov_pf.vf[i]) { - num_vfs =3D i; - break; - } - devfn +=3D vf_stride; + pci_set_enabled(dev->exp.sriov_pf.vf[i], true); } dev->exp.sriov_pf.num_vfs =3D num_vfs; } @@ -203,12 +199,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 =3D 0; i < num_vfs; i++) { - PCIDevice *vf =3D 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 =3D NULL; dev->exp.sriov_pf.num_vfs =3D 0; } =20 @@ -230,14 +222,10 @@ void pcie_sriov_config_write(PCIDevice *dev, uint32_t= address, PCI_FUNC(dev->devfn), off, val, len); =20 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); } } } --=20 2.43.2 From nobody Mon May 13 23:26:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709120080; cv=none; d=zohomail.com; s=zohoarc; b=h+E0TN3WufHKeiBkLEPBo4UmQpt//JCV0nJQ1v4ZD6Ubf2pV6Y6PbbF9RU5CXalv9n6Jxr4YC0hjSYaNxpFXQS1cl8aZZL3EQuhhIGdjexnTRGSkuNVcyGzV3VL0qYnuH53AikYL9Y8tdBZy1axLBneUv5zu/iiLCW8gqBPTuqc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120080; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vwQMc7eTDkdxhjLzMvuMnyMxWvXIcpUjn8IJsLlj/Nc=; b=TwxjkwKrOEqyblUR8ixINm4S9l+HazBz4bp0fhqHEzFI/Vs8AfEwLEN9B3H6LDb0K5gPP3bR5SDEhcwTLflQS1BqKa5VC66JXWZmnn6LcFwOyINoX+dZWQb35dYEFdGcuZvX2CdX/Ol7KiWjGvzwmnZ1b0MtOETalWd8AYJuoO8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120080124980.5741475454537; Wed, 28 Feb 2024 03:34:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfICX-0000xy-R7; Wed, 28 Feb 2024 06:34:17 -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 1rfICW-0000sY-GL for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:16 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfICU-0007Es-Rz for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:16 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1dca8b86ee7so27209125ad.2 for ; Wed, 28 Feb 2024 03:34:13 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id bi2-20020a170902bf0200b001dcc18e1c10sm2153933plb.174.2024.02.28.03.34.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Feb 2024 03:34:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709120052; x=1709724852; 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=vwQMc7eTDkdxhjLzMvuMnyMxWvXIcpUjn8IJsLlj/Nc=; b=o61frJ7dajGf6xP11TlaXAdNxT0YhKoYXCX5dNIOpzdLy7fj4rJWZGIoEi0cM/lWor d62unzaf/I5xepw9+GbbpJWtm6xEOvaJX0Ygm3oZ4FOLNDJuvekPEQD7uJgQvNf1M6jZ di6tjYPhtnDFJHvm8FV+kIA0H3PzriMRNuPosgD5h3+F+ft7Z9NbDPI3tJHl3lSjrI1M qzHco1MLV68maiXTSMVPjmwcEEUhq6zQJyXzq+owrzbZ/BexqSSuUS2C5c85BWD8ULpt ap7T6zk1MqBreSxaZXbQEFGrTHU3EAoe/fPe/yjSy69xYpAx9goZHsVGHhCJ/deJyRa6 xwlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120052; x=1709724852; 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=vwQMc7eTDkdxhjLzMvuMnyMxWvXIcpUjn8IJsLlj/Nc=; b=cz0LBvub7t9thoW57uNmvezxjxUgCA6OjEVZ0gEH/1SlhE8iaqJlOrv1K//uGt9sEG CK9WNiccD2HRsCogs7qBUY26SVv4hykaanY8anqTuLc15QDesvMhOyUKV93nBaQWlvVF cTYkJgWWh4Pm1PgFXrSjkHD8eeSpejoU6bNCsVDma+jn+vPCYQ9VSvfm6ESWG3ssSftu 6fd+EvNOTOW0PV8dbvE/PTBpFEVlXliow8SCChxF94hdHclYBkv18Pi05pk4WM6HTWol sccZsZ/8q+7JcCH1i68XnahpColPs3fbWKu981/XHEBdTMcUzt+sYQXxYT+5+BNpszDb tXSA== X-Gm-Message-State: AOJu0Yz1AG+TnqG84nhI3jXkOTpdkFE1OGJV81F11jPciItMY3jw3fcB UUD2IeICMTij+Wf+YfydwHFj0jQlKhH3JfdX1mEYKV89JPXG2vGByItxFeOqWPBRXiZNZNsoVFH n X-Google-Smtp-Source: AGHT+IGq91bTptl/mv2TAlN4+n99Gh409tCWZaD6HuTTEiWFf/dQJ8x1aRqbo8yqgn6+hdkS8eTGNw== X-Received: by 2002:a17:902:eccb:b0:1dc:a282:6606 with SMTP id a11-20020a170902eccb00b001dca2826606mr9641723plh.14.1709120052508; Wed, 28 Feb 2024 03:34:12 -0800 (PST) From: Akihiko Odaki Date: Wed, 28 Feb 2024 20:33:20 +0900 Subject: [PATCH v8 09/15] pcie_sriov: Release VFs failed to realize MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240228-reuse-v8-9-282660281e60@daynix.com> References: <20240228-reuse-v8-0-282660281e60@daynix.com> In-Reply-To: <20240228-reuse-v8-0-282660281e60@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_Goater?= , 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: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::62d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709120080819100001 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 d934cd7d0e64..8710ee95b26d 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -86,6 +86,8 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, vf->exp.sriov_vf.vf_number =3D i; =20 if (!qdev_realize(&vf->qdev, bus, errp)) { + object_unparent(OBJECT(vf)); + object_unref(vf); unparent_vfs(dev, i); return false; } --=20 2.43.2 From nobody Mon May 13 23:26:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709120223; cv=none; d=zohomail.com; s=zohoarc; b=CwbF9EmK0evLwgN9/9IfzweerB071dt62PB5UOlrxYSJgAyqipLa92JHLW+eAVwZkd8lMX23TlirvYl2XbQ4AZnUf3xZgz0k9EKGK1Ef3cojytRL0A5+Kr2HP3a9/RhQaM9Q5XYiEMvwdLBw4UKfotPU3/rKsrVGWbJRYm0ceLs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120223; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=n60IjDHaz7q1D7DDq4+a1GNpkeEaPlCZ35n5E8Xd1EI=; b=epfHGOUEZMnpkUp64HMgynhEBy45BTrvAguiOa0r9m5yxagpePSleIiNkp4n4OjDBR1wYO9bQZEbxjq7kFforFzopqTfFgrXVIDZChanmrlIl2es+CTuzKzzWx0oCPO5zWCdJto1wsQf5jp44N2SDV7XtZwsF/getopdStcAZgw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120223645389.56453837936067; Wed, 28 Feb 2024 03:37:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfICd-0001Is-IU; Wed, 28 Feb 2024 06:34: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 1rfICb-0001Ew-Bd for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:21 -0500 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfICZ-0007FP-FD for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:21 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1db6e0996ceso40449185ad.2 for ; Wed, 28 Feb 2024 03:34:18 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id p3-20020a170902e34300b001db8a5ea0a3sm3112821plc.94.2024.02.28.03.34.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Feb 2024 03:34:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709120057; x=1709724857; 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=n60IjDHaz7q1D7DDq4+a1GNpkeEaPlCZ35n5E8Xd1EI=; b=MkPz711e2NCWNnKG5EE1BXg+KreItJ5HWoxtxgawVY3D4061Cy+wMA/Oq7PKXUQFU9 bA+Yot4vMOSruScxoruXwnkSXLcbTAFVcd9zxK6eUsLDpNAPsDo5lNaYEXH4Wutxuy+/ vIfTFFJHrSrSsN21o02KVhO8E2VKfYp98uapKeRNKGJPCKz3sndx831nB6H2JrPEOZjh mMNYHi+9cWOcuN7ecxqWvbfLHvZvv8jX40S0ukrVHoFbCl7DN/l/bsyd2b4JBiRqt7zr mXDPRGvoFsoyVgGVwIDdj1utk+g+DunbV99CnkXHYxWwBTRrrVrixxz5sD72u9xCuRe6 TK8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120057; x=1709724857; 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=n60IjDHaz7q1D7DDq4+a1GNpkeEaPlCZ35n5E8Xd1EI=; b=o+Dm0jREtkuhykT5CH7xG6heyVt0bXZKqzIjCvFiSaHD39vgsVCEmr8t9bPqP4oVjk 1sJR5xDn+SdQO2FDWABFMlwgV420Kps4eQwTybOVw1Z5Xn0oo58/Vf7OIHBA5LfNUfyz LRRatsbGPACXLx9DSfJDQnvSfYDpGfkmK1bJTMkwyOGPwJb2EPScx1f5NvaejlDW7kQA k6XXU0JarVQpWEhaLRUySGxero3BklxFwP0mPy6VZ+6E05aIOH8xrZ21i1bqx03dRUvd GBg7x/eCihtMUUCljBdVq6eN+RrXaqiOtUoTUX6UR2nCzViaD67L1RoLsIP0JAy2jJ67 Kpfg== X-Gm-Message-State: AOJu0YxtCrKZp3TYFnS7V2IdNTAldawBPkPahhRdhhC4ydo8mh54XRMN yQO0jhcR1ks7SRsA7MZe63R4XmTZXB+qnYBE6HQCOTrYVKiLL7OhYZ/uN5uEDss= X-Google-Smtp-Source: AGHT+IFtGGSxQEc8hfk5fC+RrlCvjq0+lKzR8fZcEg5TagqTkv/lSOkWX9ouKgtbvuViNOg9fm6Rng== X-Received: by 2002:a17:902:e842:b0:1dc:78bc:ad0a with SMTP id t2-20020a170902e84200b001dc78bcad0amr14867050plg.36.1709120057229; Wed, 28 Feb 2024 03:34:17 -0800 (PST) From: Akihiko Odaki Date: Wed, 28 Feb 2024 20:33:21 +0900 Subject: [PATCH v8 10/15] pcie_sriov: Remove num_vfs from PCIESriovPF MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240228-reuse-v8-10-282660281e60@daynix.com> References: <20240228-reuse-v8-0-282660281e60@daynix.com> In-Reply-To: <20240228-reuse-v8-0-282660281e60@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_Goater?= , 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: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::62b; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62b.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709120225409100005 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" =20 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 8710ee95b26d..fb48c1a18c9a 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -44,7 +44,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 =3D offset; - dev->exp.sriov_pf.num_vfs =3D 0; dev->exp.sriov_pf.vf =3D NULL; =20 pci_set_word(cfg + PCI_SRIOV_VF_OFFSET, vf_offset); @@ -173,6 +172,12 @@ void pcie_sriov_vf_register_bar(PCIDevice *dev, int re= gion_num, } } =20 +static void clear_ctrl_vfe(PCIDevice *dev) +{ + uint8_t *ctrl =3D 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; @@ -182,6 +187,7 @@ static void register_vfs(PCIDevice *dev) assert(sriov_cap > 0); num_vfs =3D pci_get_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF); if (num_vfs > pci_get_word(dev->config + sriov_cap + PCI_SRIOV_TOTAL_V= F)) { + clear_ctrl_vfe(dev); return; } =20 @@ -190,20 +196,18 @@ static void register_vfs(PCIDevice *dev) for (i =3D 0; i < num_vfs; i++) { pci_set_enabled(dev->exp.sriov_pf.vf[i], true); } - dev->exp.sriov_pf.num_vfs =3D num_vfs; } =20 static void unregister_vfs(PCIDevice *dev) { - uint16_t num_vfs =3D dev->exp.sriov_pf.num_vfs; uint16_t i; + uint8_t *cfg =3D dev->config + dev->exp.sriov_cap; =20 trace_sriov_unregister_vfs(dev->name, PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn), num_vfs); - for (i =3D 0; i < num_vfs; i++) { + PCI_FUNC(dev->devfn)); + for (i =3D 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 =3D 0; } =20 void pcie_sriov_config_write(PCIDevice *dev, uint32_t address, @@ -229,6 +233,9 @@ void pcie_sriov_config_write(PCIDevice *dev, uint32_t a= ddress, } else { unregister_vfs(dev); } + } else if (range_covers_byte(off, len, PCI_SRIOV_NUM_VF)) { + clear_ctrl_vfe(dev); + unregister_vfs(dev); } } =20 @@ -291,7 +298,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; @@ -299,5 +306,10 @@ PCIDevice *pcie_sriov_get_vf_at_index(PCIDevice *dev, = int n) =20 uint16_t pcie_sriov_num_vfs(PCIDevice *dev) { - return dev->exp.sriov_pf.num_vfs; + uint16_t sriov_cap =3D dev->exp.sriov_cap; + uint8_t *cfg =3D 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 42430869ce05..b30e31619787 100644 --- a/hw/pci/trace-events +++ b/hw/pci/trace-events @@ -14,5 +14,5 @@ msix_write_config(char *name, bool enabled, bool masked) = "dev %s enabled %d mask =20 # 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, u= int32_t val, uint32_t len) "%s %02x:%x: sriov offset 0x%x val 0x%x len %d" --=20 2.43.2 From nobody Mon May 13 23:26:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709120130; cv=none; d=zohomail.com; s=zohoarc; b=RvT1hBks3Fm4rxfyskeErSzjGEmUplsSwOShfjuW003qNAiG4zMK9cPmLrQpsbw7za2mnmDPRPdn8IM96mTVuhu1ayq9+NL+mWjDncwmDBRRkCnsuYczYa0RtXc5kv7fGtaCVfFIpycwn7W0bmjl8eQ7HO7USqYTHaGUy30lt2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120130; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=53XyZW+eFVvoAPfI8083D4zbyq4zLHK5w/Vl/6iTbj0=; b=W+1fQgEMCjTFx7gWEvqCvqRH/qazC9Bu0YsBPPOQiuTdrQTAOQFOVROux3N4ZO2pHpmH3fzT9FsqpwsHSFNY5VoUnv2Jz6Ybjaw98UCwwsEh1Lu90jt9WOdIhRDGqkmkcIyES2OLYI7IvXi4vuq6ze5TLyk6s3KJSVRjSedts+c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120130483510.83934622695574; Wed, 28 Feb 2024 03:35:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfICi-0001R1-F0; Wed, 28 Feb 2024 06:34: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 1rfICg-0001Qe-F3 for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:26 -0500 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfICd-0007G6-Ph for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:26 -0500 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-6e4b03f0903so696715a34.3 for ; Wed, 28 Feb 2024 03:34:23 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id c2-20020a63a402000000b005e45b337b34sm7432721pgf.0.2024.02.28.03.34.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Feb 2024 03:34:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709120062; x=1709724862; 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=53XyZW+eFVvoAPfI8083D4zbyq4zLHK5w/Vl/6iTbj0=; b=x+bvAwc2UYIy5z7TykwnOxdqo6y6AxoLtRZrVtDWwj5axCvenOqBMdVAe2gK2rgTV/ 7OIaK8U26RnPyB6Fnw5AznIGSjCb3oNLCl00Ysmck3YhrxnymRZ7R4xn/RDObTZuSKlf CdpMmtgV+QIaPJ+VTFJPJayGxjl1kzKNGcO9+W4Hs9n8qcCy8O6iZyi3gzNFc1VaIOUM FUexy3NIYiDiCikDCuGTkMWuU47VRWJclUS49yHVQdediGLsxBmrbI6vi4tn8NowkWaE m01l1FhuJZxI9wLBsdw4jyhL8uOHLgXvs1torArAqFJfJ5k4ekL+OB8Ki4sAedHRzEvE jJ0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120062; x=1709724862; 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=53XyZW+eFVvoAPfI8083D4zbyq4zLHK5w/Vl/6iTbj0=; b=qOX3IYZVrRtG5miYpOlPt7AgZl2iSbXftnGo7Ayg+7xn3MEbCIJ0NUmQL+/aNeyKL9 CYQZtJkidgZLwosdOVGmsJKhapKuk9NRWu+xhEOOwSo+F+qH89J1LE8IYGpuzD/pHHub VQVPWrOfpaQ/zKIQm5zoxhtQ/PadZ85XT4Tt/OWVP4T+icFKPase7X1E/cvv3NjuINgQ Y0BbrOQnJhRzABis7q+kdC3o5xa9sv0s6wG2eFvbQmFV017hv1npRbMJqkRVAhQ6Aj2R FnTcrOupvBdxo807dtzF+RgKevJCJAknEWyRS9zyKMjAWuoykmMeAnVDoIa9p4so7QqD R3rA== X-Gm-Message-State: AOJu0YxKL3DIZM7mk8yUgC1km3z4Fx0FnMHRFQHmid/jxbNAb5xQqDPL Z2kyTFLirT5cu5rDY8X00JAHBYw9KUVUyo/WsUJh9mSxHw2dstAAG92IvC74BjY= X-Google-Smtp-Source: AGHT+IFIt/H0kJ6j7elWz2sy8w2zoDCZSYOwdSHkT59AjYX5MGpCW+olhyG2Et+2a8z11ebapiqUOQ== X-Received: by 2002:a05:6830:144d:b0:6e4:696d:14e0 with SMTP id w13-20020a056830144d00b006e4696d14e0mr12703758otp.37.1709120062354; Wed, 28 Feb 2024 03:34:22 -0800 (PST) From: Akihiko Odaki Date: Wed, 28 Feb 2024 20:33:22 +0900 Subject: [PATCH v8 11/15] pcie_sriov: Register VFs after migration MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240228-reuse-v8-11-282660281e60@daynix.com> References: <20240228-reuse-v8-0-282660281e60@daynix.com> In-Reply-To: <20240228-reuse-v8-0-282660281e60@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_Goater?= , 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: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::32d; envelope-from=akihiko.odaki@daynix.com; helo=mail-ot1-x32d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709120131018100002 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); =20 +void pcie_sriov_pf_post_load(PCIDevice *dev); + /* Reset SR/IOV */ void pcie_sriov_pf_reset(PCIDevice *dev); =20 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 ver= sion_id) return !pci_is_express((PCIDevice *)opaque); } =20 +static int pci_post_load(void *opaque, int version_id) +{ + pcie_sriov_pf_post_load(opaque); + return 0; +} + const VMStateDescription vmstate_pci_device =3D { .name =3D "PCIDevice", .version_id =3D 2, .minimum_version_id =3D 1, + .post_load =3D pci_post_load, .fields =3D (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 fb48c1a18c9a..09a53ed30027 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -239,6 +239,13 @@ void pcie_sriov_config_write(PCIDevice *dev, uint32_t = address, } } =20 +void pcie_sriov_pf_post_load(PCIDevice *dev) +{ + if (dev->exp.sriov_cap) { + register_vfs(dev); + } +} + =20 /* Reset SR/IOV */ void pcie_sriov_pf_reset(PCIDevice *dev) --=20 2.43.2 From nobody Mon May 13 23:26:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709120224; cv=none; d=zohomail.com; s=zohoarc; b=b5WssxcHL1ZSUXFTme2ZWKUoef54Z4IRbUGALlTjNYXvhNY1/0pdv7nAZHhBUgk24DlNRKWBajNFG/qyNVXSEWsd0OWI/uJT8yJna42OJ8TO0IjabeMIt4HZrijePL4cdIILHDroU8cSGSULOuASSL16nzzvT422j6/mCn6eSZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120224; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YPSiR6IwHlPrV1jxSt9NcR1fgHWl/R9keZ4bHjE5Nwo=; b=DzgJImLQLiIy3punzqbDPuqvPog2Gh1bgJiKfbVwJ8kZs1vCWaw0UzNrMDaU1rT6GadT8Uymu0lc6YKIp16BkxXJA/jh3TEF903vdjm8OcWWEl5Wm1U5gT4Uy8PT6Gf8q2nKaQjihU7ns7WMoPmIe2Au7RYG4CgPOqVIbGyoAg4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120224347701.3077850320241; Wed, 28 Feb 2024 03:37:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfICq-0001Zj-BN; Wed, 28 Feb 2024 06:34:36 -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 1rfICn-0001Xg-0v for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:33 -0500 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 1rfICl-0007Gx-7N for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:32 -0500 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6d9f94b9186so4737700b3a.0 for ; Wed, 28 Feb 2024 03:34:29 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id v14-20020a1709028d8e00b001db81640315sm3078458plo.91.2024.02.28.03.34.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Feb 2024 03:34:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709120067; x=1709724867; 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=YPSiR6IwHlPrV1jxSt9NcR1fgHWl/R9keZ4bHjE5Nwo=; b=Nd5s4j1WTpEsffUDxXZkwwg8nGpxPL6LLdxNwSUHtofJwEjn812evSH+CimBSZn8Zz AzZ2VXlTeA5H4SY0sf8G+nDOsn5PJodj0pWiBZZhgowfnIwAKN+fX2iuP55AseEG1WJa 8+sSGZhLqY01Ng0Np6mteGGb1iroUg56Hokczt07u7VExSqNpGpbE5ePRRIkq5PCGJWk AaX9mimsfQ+RH4jzvi99/u+ec5rx0NtdCie3Lpwxo2+Lxsp+Wr8nWGnSqcLnye+Zbzwy 4PE5Wst2u1RCeoGr9RQ1Q8mDaYUhQ3IQzv1ckIqvc2qgPz6Wou/1+49SL9+oVsjmhXMc IJww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120067; x=1709724867; 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=YPSiR6IwHlPrV1jxSt9NcR1fgHWl/R9keZ4bHjE5Nwo=; b=uZrkLoUjwoKxeKV2rsPO8jb5z1x3Hrj0wa6WGsG1GcoDnCEwLqcdcpTtI3YBHTiq5v ziHl2bobRnh5SzJkJGuID0vK9ae33kWycAKFPndX6aehCdyjVG/HZANHwN82B829u2U9 RjW+qenbtf16DuJTglc6fw9uLdC+uNEJMP3ujyEQI13me+NnTik0k/0O6ZdEvgs68/b4 eFOX5ApyH5PV4/uKmQLY0jqxqWO6reFYutvoUoRu0l0vcCk9NnC5neqCSehqDpTqwZlP O5/MOQyHcpvGQEMsWN7JPppNt/S1ZHdwiF/Ob/pKyHitgkn2jcyJf2/zrIxgor9tt1wG Ew5Q== X-Gm-Message-State: AOJu0YwX0h5pCTSuaDLT1oIEti1jHbR+jhNbrgoyYtpZsLgikMVbhEGW Zkc+qnr7mw24aC/rvU2jcjIOkyYjk4z3iSmrym03bmWM7vPQXRnQGclKmfnNpUM= X-Google-Smtp-Source: AGHT+IGkKI+Y235zLvt/oRSPJKcfgRKk4cd7NSzr36e6vIhB15SK4lWgj/53BKggjB1qeoq8qPJuHw== X-Received: by 2002:a05:6a20:b209:b0:1a0:e647:5d58 with SMTP id eh9-20020a056a20b20900b001a0e6475d58mr4426049pzb.23.1709120067473; Wed, 28 Feb 2024 03:34:27 -0800 (PST) From: Akihiko Odaki Date: Wed, 28 Feb 2024 20:33:23 +0900 Subject: [PATCH v8 12/15] hw/pci: Replace -1 with UINT32_MAX for romsize MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240228-reuse-v8-12-282660281e60@daynix.com> References: <20240228-reuse-v8-0-282660281e60@daynix.com> In-Reply-To: <20240228-reuse-v8-0-282660281e60@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_Goater?= , 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: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709120225435100007 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 =3D -1; if (romsize !=3D -1) { ... } When -1 is assigned to romsize, -1 will be implicitly casted into uint32_t, resulting in UINT32_MAX. On contrary, when evaluating romsize !=3D -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[] =3D { 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); } =20 - if (pci_dev->romsize !=3D -1 && !is_power_of_2(pci_dev->romsize)) { + if (pci_dev->romsize !=3D UINT32_MAX && !is_power_of_2(pci_dev->romsiz= e)) { error_setg(errp, "ROM size %u is not a power of two", pci_dev->rom= size); return; } @@ -2359,7 +2359,7 @@ static void pci_add_option_rom(PCIDevice *pdev, bool = is_default_rom, return; } =20 - if (load_file || pdev->romsize =3D=3D -1) { + if (load_file || pdev->romsize =3D=3D UINT32_MAX) { path =3D qemu_find_file(QEMU_FILE_TYPE_BIOS, pdev->romfile); if (path =3D=3D NULL) { path =3D 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 !=3D -1) { + if (pdev->romsize !=3D 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); =20 - if (dev->romsize !=3D -1) { + if (dev->romsize !=3D 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); --=20 2.43.2 From nobody Mon May 13 23:26:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709120135; cv=none; d=zohomail.com; s=zohoarc; b=FHTFC8YKFSp0eziYmVl9cHspGmL1cjvXpud/EEEPVyMptspZdR43yJQoQwAopI1vNf9kUJkLV/NKLCt300P50zhvndYqvzAheJ9JbiT5AhFMo3v2xNs0DoaeCcTmKjGFUabG04iSHxf69wi9tDKbX2PwACCRbWdwlkQs5CAoSDU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120135; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qNr8IpM/BgnyhwNeoHVIpQAv1RPcCThHB7TyMR3DGSw=; b=gt7kO5mRKu2gQ5j7wI0b+IGT+5tcRJAvBugPUYZ5FrGZvAGum/vEdG4Lgyprof1cHp9moB5Rs/KPD1uVA8xzAicP1hjSioe1bglPUNtKO7qVuiCxuVH8g7ur+gW3IflOqRn4wa04ez5HiRICAE0tTlL/SIXlMIuKn6Quvpgwnsc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170912013575032.557318183910866; Wed, 28 Feb 2024 03:35:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfICs-0001bU-5o; Wed, 28 Feb 2024 06:34:38 -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 1rfICp-0001ZM-1r for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:35 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfICn-0007J9-H6 for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:34 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1dc13fb0133so40056635ad.3 for ; Wed, 28 Feb 2024 03:34:33 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id kb16-20020a170903339000b001d94e6a7685sm3118049plb.234.2024.02.28.03.34.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Feb 2024 03:34:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709120072; x=1709724872; 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=qNr8IpM/BgnyhwNeoHVIpQAv1RPcCThHB7TyMR3DGSw=; b=A3kZ2QibxYblQXm9M0N4hJrEpJ+5o2iXvz8GymQnAHtCjNH8AGhdB6h1/vQEpFiAM8 5s4Gw02mSXaEmhrXGG52Qn8otKFL21JraUwrf89Ua0V6QtLrBYCJxCO95EFqFfIdR9Jl DHvMJepYpH0PttEGW1J9fAl0mkYOi7WGhmp3xjqkaVSlUESx00HSLTVeO4D2INkbvPHQ Ds0f74AOnXI0bUj1WtusoXayPvSzqUA74riZkcV5TXr2hLsT7pAEHpWVJxQAtsPXuWSq Y9zUurnWD8sa+weitYVY9xnWqZ5P4qfAUE2WfmRvFK09jtvuht3kLKLX/mKCw+OpuzP2 mNGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120072; x=1709724872; 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=qNr8IpM/BgnyhwNeoHVIpQAv1RPcCThHB7TyMR3DGSw=; b=iMH9+mSX9Js65PGVUTcBqzsnf90BIGK4DnkcKEg3wvKDh3s0JEDBD/HHzjlSLxiNDS p0nqRNIXmFXspz90PevjJi3dSDW3jGcH8/SP6mn2Wa15Zn1rHDvpu+GA814G4J+i0byj +JwZLuHHQZjOo/cN9g4gEgLHdG8VM9zQjigiZn0ZVVHu3qHQ7ijMsEc/TsMwXCJ2BeI1 RkYbNnwr7Lkx+4tFMuJ0dtaxCe5O49PmIHclNEu2JB3Z2TmgXT8mSVmBXv088VLuy2k6 z70sRQ4nT4gc5rUdgsSSbRugZJiscJ0F9fcaYMri/Pj3dFFPL7RJ/gkeIZly983vzWuv O1NA== X-Gm-Message-State: AOJu0YyBHcgLjUnRbZYhuHldUK0Re5IymlYRVXSlspxXPse235UnAlMp UC5wbzUCUgHikJChozl1S0PGpLAilh7RcSIbxB4SCoc6LedUFNmafuwosIiy6Fs= X-Google-Smtp-Source: AGHT+IHaAr/9NqHn6dDudsu1a1zHBCsel/s503fgNIlr42wrMSR+AMGskRjwZnf8+gSw3AryNnytOA== X-Received: by 2002:a17:902:700a:b0:1db:cfa0:4045 with SMTP id y10-20020a170902700a00b001dbcfa04045mr11172426plk.60.1709120072031; Wed, 28 Feb 2024 03:34:32 -0800 (PST) From: Akihiko Odaki Date: Wed, 28 Feb 2024 20:33:24 +0900 Subject: [PATCH v8 13/15] hw/pci: Use UINT32_MAX as a default value for rombar MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240228-reuse-v8-13-282660281e60@daynix.com> References: <20240228-reuse-v8-0-282660281e60@daynix.com> In-Reply-To: <20240228-reuse-v8-0-282660281e60@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_Goater?= , 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: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::62d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709120137180100001 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 =3D 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 =3D memory_region_get_ram_ptr(&qxl->r= om_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 Reviewed-by: Markus Armbruster --- 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[] =3D { 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, --=20 2.43.2 From nobody Mon May 13 23:26:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709120090; cv=none; d=zohomail.com; s=zohoarc; b=R27EkSjLe1/EEUl0uz9EXFvE3zEyr+kEfslRLtDoRKzCXLJz+cbLQ5HTLoFQRdqRcIYo73PIdX8YiR9snnLjj8ucvGDuE4jMs7XVnB8Ell3R8WfCLMLeztWYgmRu/+JccuBoxw/zIBu9DBNhJYRjRtR3JR7ApScJzJB3mf9C2Do= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120090; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DmGmO2NRoFLE9iEpGFg0X79YxkUKCW6XJ2bCMIxOKKA=; b=WvXqQ9g7ZEmundJkqQ5PrHTzzCigr7y6aFsWl1EATM5tV6lGK/1q7BV6jHZshKJvPZU/yrzX0xbu8PbMXd8ajzB749TxmdN+22W1Ep88RJAs9ejR+ce5saWYvIpuMjFQD76jQts8BLY7zg8kXZ1TSTJK7R+ZREYAXEvC3KxqB1Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120090882605.4658221721056; Wed, 28 Feb 2024 03:34:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfICv-0001jo-Eu; Wed, 28 Feb 2024 06:34:41 -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 1rfICu-0001eJ-6k for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:40 -0500 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfICs-0007KO-Gi for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:39 -0500 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2998950e951so3701256a91.2 for ; Wed, 28 Feb 2024 03:34:38 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id y32-20020a17090a53a300b0029932d64c2bsm1492351pjh.17.2024.02.28.03.34.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Feb 2024 03:34:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709120077; x=1709724877; 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=DmGmO2NRoFLE9iEpGFg0X79YxkUKCW6XJ2bCMIxOKKA=; b=Xl6iY+M4RZn7lhiflCYj0FZxOP+6huNX0wqyP//5NSE54JiU3eZZEry34u3JWD2Hxc vH2jFJHOoTJQvj6pek+NaTX5LOdJL3RgEu3DMl9t9RYnaFNOStjm/KDWGUtyqqgeD1h7 TQ6IzHLwug+nv0Fo7e6qcyGmZVoZh0dCV5K//zR7EKuN4jGhQzksbwuqf4mNLxp8vhqg /15tnDH8n2/HmcKCmNdIjMTivhOSdDCB2ol+bdiUfkgy/17EQNygknk62+kltoJjP3a8 qwztCrkVS/rYQ/XECHXxVdF0bukkxUf98ZA2hq5u5qOfTjLWfxiViT1M12Zr1zGtipFs ad4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120077; x=1709724877; 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=DmGmO2NRoFLE9iEpGFg0X79YxkUKCW6XJ2bCMIxOKKA=; b=t68q7/lvEH+Eki26Mr7Lbr+Nn5G+tyyZ2LzMM6A4bYY9eBbuLxad2FwOTQ1kakNpXf v++Mfn4wVp6yxQfNi4UgFRbExKiwq1RpBeBOJcOEBMwkpNdsiNq+MMtj8aPkNJiEe3Un WEthhfPHfVXX/vTG1mLMM2pQgEFlwFXjbx1/nnYeyFlYCq0Jrukmu8CHNFUgXU6jtOZq xeV8kH3nJpd2TbMCOvC5NP127E7RoHMcZMEtQX+FQ8H20kOiUawh3daa3GSb30wmdq73 LaQEs9A0/IOOQ4/E5QB9OaQ8vIA0aUX9y/VD7X+SmU/WNU7J5xX0C7hjJdwjCz+5+cnC cz4g== X-Gm-Message-State: AOJu0YwHtTI8sB4RK3I6GvYgFEPBhgN2SEb0ZsnyfmvnkdXdOX9L1WWd 1svQQTKOdCsnClSfr0nU7kP12uci4MxN9LZe1saFEHIUcVnAQREYuwcKzuQdn88= X-Google-Smtp-Source: AGHT+IHRGtlJAhcokCxkVkcUONGVdKlKQurt6rFhLt/3v61ekpaSbSrfHlrUbj5oklU4lZBOKMdP4Q== X-Received: by 2002:a17:90a:f308:b0:299:5ebb:1ee0 with SMTP id ca8-20020a17090af30800b002995ebb1ee0mr9212723pjb.28.1709120077235; Wed, 28 Feb 2024 03:34:37 -0800 (PST) From: Akihiko Odaki Date: Wed, 28 Feb 2024 20:33:25 +0900 Subject: [PATCH v8 14/15] hw/pci: Determine if rombar is explicitly enabled MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240228-reuse-v8-14-282660281e60@daynix.com> References: <20240228-reuse-v8-0-282660281e60@daynix.com> In-Reply-To: <20240228-reuse-v8-0-282660281e60@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_Goater?= , 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: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::102d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x102d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709120092843100003 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 Reviewed-by: Markus Armbruster --- 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); } =20 +static inline bool pci_rom_bar_explicitly_enabled(PCIDevice *dev) +{ + return dev->rom_bar && dev->rom_bar !=3D 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 4fa387f0430d..647f15b2a060 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 =3D cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK); off_t offset =3D vdev->config_offset + PCI_ROM_ADDRESS; - DeviceState *dev =3D DEVICE(vdev); char *name; int fd =3D vdev->vbasedev.fd; =20 @@ -1046,7 +1045,7 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev) } =20 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); --=20 2.43.2 From nobody Mon May 13 23:26:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709120130; cv=none; d=zohomail.com; s=zohoarc; b=lEajWqVtbkX8LhFQfNQvxdBeqR5kny08GbmfMonktjAnLM+ZDM9kLCr5+GuqHoJXpAbWz/0Q/9KRKcwKrqqqf7NXk3mLwjmH9V9f7Cgli3AcJD1qRl0J7CCVTb1PI8g1CXribmxhoAwBOjx0NZHZb8ApwqDskuwBJWaIuGXXjic= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120130; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FEXfVsaC8WiwQLHzBhL9P9YmKLGvJ5rGOGPmQWC7dng=; b=O0ltekL98vq8lRBFKLYwA8MDPZHJG2sBhdqjpr4r8OkE0+midAtTKO/i0rfO+e3f0qMnlHTsoOsv3cBX8dXvsnC/yXGbkllK87glgwb6VeMnnEeNdVnyZIniVh2N8WJ/z6pL+xwtUqiZ/EcTEQcDfMV8yTGA6qQssf7Jce6oV04= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120129917242.91362197983892; Wed, 28 Feb 2024 03:35:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfID1-00022N-Dq; Wed, 28 Feb 2024 06:34: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 1rfICz-00020D-RR for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:45 -0500 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfICy-0007LC-7z for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:34:45 -0500 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-5e42b4bbfa4so3862375a12.1 for ; Wed, 28 Feb 2024 03:34:43 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id m14-20020a17090ade0e00b0029a4efc0231sm1373952pjv.56.2024.02.28.03.34.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Feb 2024 03:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709120082; x=1709724882; 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=FEXfVsaC8WiwQLHzBhL9P9YmKLGvJ5rGOGPmQWC7dng=; b=j998qUCsPx+oitD0HEn8CCWBacETt2AnJ/6Y5e73bxocx5DYGz2N+cas/zoATmF2ds IoKCbl8yZpO1Y3j2m9aYA/pqcStbfbWhUPgjaQXWO+xL38tv22p+nyR2r3HBxGzvwJDw zfT2XfJwesgK5S1GPzMXc9jKfJnF48uzDG3q5pcxtehSR4C3At/p/VGL1JDA7tx8SZtD jPkhov1W3VvFiiX2jG1ImXRLpFgyDPEgv+6w3c96nrFYpNXA5QuJ9EpeRdKovM3SVgj6 RpFeaGMzB+L2NfvXVfuecC2ko9J5jRqxovI1LcVpa0D8rMs460dDjTg4lZR1CEg/nfoo wZvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120082; x=1709724882; 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=FEXfVsaC8WiwQLHzBhL9P9YmKLGvJ5rGOGPmQWC7dng=; b=LQwOO+CvOhGC3VaxXGhgRHJulBkKEK5i1C73rgyR1WYNQWJyfA/QsnUpNNGMm647Zu VlnlwG6YNSLFs8Z1hDXzKwqoS/8PumzAw4wHi/LKseS3SSR3a5/Yn0Z6xZxb/lMAVxew ITRUB0biXCXa90Pl3aJ2791ioKSkrEpwmXrvLN4JHxfp5mBAHmyXu5jOFRsVx+Q+jcZ1 qnS4IDMmng1qr066IiNTuKEq0MMo68lnICzq5D78KIs33PzP55EzGk0Rb1bAa7zVURPh RYpdkAI4B0bZcBxjKeeF7E6jD5fs9gkYmuED14IBlWl/zrgUuGz6gH0Zn8HNxnH9ZIiT Ljtg== X-Gm-Message-State: AOJu0Yy7Xi8+k5ba/bxBWgEY3moc2q5iwvJnxVXbDei77qtFB2A7v7uQ J56RmDq1PVR5x6UoowJ2CXEpXW3nFNNWxAaCWNzPRHzpBBi6Cxthou8w8NFxG/0= X-Google-Smtp-Source: AGHT+IFFd17WvflZaq66nmdvXhJak2r01wCePE4lRX4MR4ZFwBxkTQzNFqyfuq2L79jN7Ut3HwhauA== X-Received: by 2002:a17:90a:2e88:b0:29a:b6d7:be22 with SMTP id r8-20020a17090a2e8800b0029ab6d7be22mr7253532pjd.17.1709120081958; Wed, 28 Feb 2024 03:34:41 -0800 (PST) From: Akihiko Odaki Date: Wed, 28 Feb 2024 20:33:26 +0900 Subject: [PATCH v8 15/15] hw/qdev: Remove opts member MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240228-reuse-v8-15-282660281e60@daynix.com> References: <20240228-reuse-v8-0-282660281e60@daynix.com> In-Reply-To: <20240228-reuse-v8-0-282660281e60@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_Goater?= , 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: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::52d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x52d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709120131005100001 It is no longer used. Signed-off-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daud=C3=A9 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 =3D NULL; } =20 - qobject_unref(dev->opts); g_free(dev->id); } =20 diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index a13db763e5dd..71c00f62ee38 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -625,6 +625,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *op= ts, char *id; DeviceState *dev =3D NULL; BusState *bus =3D NULL; + QDict *properties; =20 driver =3D qdict_get_try_str(opts, "driver"); if (!driver) { @@ -705,13 +706,14 @@ DeviceState *qdev_device_add_from_qdict(const QDict *= opts, } =20 /* set properties */ - dev->opts =3D qdict_clone_shallow(opts); - qdict_del(dev->opts, "driver"); - qdict_del(dev->opts, "bus"); - qdict_del(dev->opts, "id"); + properties =3D qdict_clone_shallow(opts); + qdict_del(properties, "driver"); + qdict_del(properties, "bus"); + qdict_del(properties, "id"); =20 - object_set_properties_from_keyval(&dev->parent_obj, dev->opts, from_js= on, + object_set_properties_from_keyval(&dev->parent_obj, properties, from_j= son, errp); + qobject_unref(properties); if (*errp) { goto err_del_dev; } --=20 2.43.2