From nobody Thu Nov 14 06:59:40 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=1708431964; cv=none; d=zohomail.com; s=zohoarc; b=VQtHwClYgeccKM8sTMy9aZEsArZGhHQpvTGVJkEzqLTntBjdoD7w4OnlKU2o5QkEsEXFfZ69D9gVU8GSJaN/D3JztvfiFix7io1l2wno6mr9FGJDG9JxW2QMHeHl5ooMZ7q3MjOdshgQszaIbWXd2rQsPA3VpxXQDZdMLZcKMbo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708431964; 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=3qtvS6V6fNKUkSPChGjLTrgPISzBF9C8NB+nT/PVebg=; b=QUvbuzx1XvBGYGCoDs2mc3cYD/wF7cHyxs2OLMHpNTaPFBmBEE2gNBCRCZraP+nremUnzhwxi0z7O2uqFlvG/PceTSggcuIJ9pjdAThhFAMrIyK149ILFqy9TY7pZL6ouLbU7LVjpUFRCwZnoOqkwAcsn5z+ljY9cgheZMa3Gl0= 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 17084319649653.074537727659731; Tue, 20 Feb 2024 04:26:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcPBN-0004iA-UT; Tue, 20 Feb 2024 07:25:13 -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 1rcPBG-0004hU-4r for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:02 -0500 Received: from mail-oa1-x2b.google.com ([2001:4860:4864:20::2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcPB0-0005qD-Pq for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:01 -0500 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-204f50f305cso4152701fac.3 for ; Tue, 20 Feb 2024 04:24:46 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id bz3-20020a056a02060300b005dab535fac2sm5375622pgb.90.2024.02.20.04.24.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 04:24:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708431885; x=1709036685; 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=3qtvS6V6fNKUkSPChGjLTrgPISzBF9C8NB+nT/PVebg=; b=z6VR6TQBfP27/Umv3UOx9WpwB4XOn5sLMGWC5vlhwmPHuV8XA7TR5c4iEnrXL0jz/Z miSxy/jtjdGB8U3VrZw/5Q2oc7zbphye9GP+8af/YTRwyxUMH/2xLBWL2JtMbnxJzem3 3eYPJR3gaaQV6aEELm8VoESCqT82JVvFuSEMO6kudaOQLGabKBxgbQwx/6fjsoIqJ1qs uVrAUNNbBWugB+G5kDCqmVclqWU727UUmh77UkmDxef//xCCd6Uvq8ZyRge24ACVJndU Fs8qIDoNAuAYZ19x1hvN80krl7LZcMz9F3vp7KgwQAnaRPq4BZBTMxBXLF2f/Op3IS9f 3xqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708431885; x=1709036685; 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=3qtvS6V6fNKUkSPChGjLTrgPISzBF9C8NB+nT/PVebg=; b=QaRwIDu9OD6VLDWFGgfCROsnt3Z0IdytqCNEMEXPy36BndssgDgmvzjhMXAzEtepts t2hUw0jIc+46PPaPALFSrU+jGqXXOBje7ILGhYYfEOFQ1yNUIAaeLgy3MrArjDcLvXAA WNhC96Y04+3N41lvTUfDQEFG1a1fY2qlFP7LJuDCOjxsCB4NbOcO1tdHO/Ic/FCRyMFD psvdMEIGgZoROIp3qIOGGE8nsTQsFxb+zZ4YewJyHD1N0EvvGkZaEeZtC7anB8r7tbKz YNUDjmhTVl98tBnmFzNB8NXGnF3GGkb50SisVUrxonWv7+vntcEFcsDX/+nBSQqAeO3i jFbw== X-Gm-Message-State: AOJu0YzW82RUdw+U5JqrsmsvV0fUPePLg/hNaUCA6OseqpXgs1iFmuEa 4spR4ROsjTtp/JL/6ydFRWy5J6RvDx2eWKs6uMtutNSLsSnhzfbnNSjc/yNbcLA= X-Google-Smtp-Source: AGHT+IFM6gFQT9fPI38uScPbt9Qs6t+0Tkpq5Gtftp8ECgaK+QOo3Miak9MHKAjWDdOMMC5T860J1g== X-Received: by 2002:a05:6870:41c4:b0:21e:6b7a:bdcb with SMTP id z4-20020a05687041c400b0021e6b7abdcbmr12046277oac.22.1708431885502; Tue, 20 Feb 2024 04:24:45 -0800 (PST) From: Akihiko Odaki Date: Tue, 20 Feb 2024 21:24:36 +0900 Subject: [PATCH v6 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: <20240220-reuse-v6-1-2e42a28b0cf2@daynix.com> References: <20240220-reuse-v6-0-2e42a28b0cf2@daynix.com> In-Reply-To: <20240220-reuse-v6-0-2e42a28b0cf2@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 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=2001:4860:4864:20::2b; envelope-from=akihiko.odaki@daynix.com; helo=mail-oa1-x2b.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: 1708431965729100001 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.1 From nobody Thu Nov 14 06:59:40 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=1708431953; cv=none; d=zohomail.com; s=zohoarc; b=FCPIqiY0pl7Qs9Ac0BQuWB4NtlEtIwtdNJPMzeYhiEPOQ+57TYjQ9+qh3HzEerzfGHnEVo9XtBeu3ta++NlpYOofQnN0xEVfCPNLiW/oYin74WPJXqR2THeAiVQBD8MHjHoxKSYcsW+xkX6Kja8sX3c0LMI6bSAVmbOXXDCmSuI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708431953; 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=E/Otirits4N/P66fEjvcSSTgES/jWUIXlIMqWKsiQLI=; b=AdGOTOrcJK8nbLa/BYyYtAX21LENyWdAPhC/RbvgjneHOHlJCI31PL/Y1pXtkN4ngzjOyfk1jyz1B8XYL85RqTYwteYcWCBIpCjGLAbmZxYM2sU64NEEKaKBivFUCFSPIvkenK3/tNR80zRhRnNxKLcPrvlJ6SWcLGpCxpbSIv8= 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 1708431953564858.4311441046303; Tue, 20 Feb 2024 04:25:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcPBw-00055g-Qq; Tue, 20 Feb 2024 07:25:45 -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 1rcPBJ-0004iC-Ic for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:07 -0500 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcPB7-0005qm-6P for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:04 -0500 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-5d3912c9a83so3991911a12.3 for ; Tue, 20 Feb 2024 04:24:52 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id h11-20020a63530b000000b005dc3fc53f19sm6391874pgb.7.2024.02.20.04.24.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 04:24:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708431891; x=1709036691; 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=E/Otirits4N/P66fEjvcSSTgES/jWUIXlIMqWKsiQLI=; b=GdafWnyM60VUZLJjHvJTWWCkyPtb/agTZn9/KBZTTT6JM5/XwhTx/pTYhLDUAGHgL0 WFDwx6lzxidB0uJlj0aPRLcZY76rWzH2G2RMlz6GWgYhoF+L6bcH/2h4HWARbi48AKmc Hx+JetEcGnrEcyMxLdXlfeBH2gyK+GS6v2Z+UKZa6vu9b+1XemvAcLECb4HONkoqRt+K 4YsMT3yVg1lwDen/kc4LwtyhzQaGru9qG2qwbWssTZzuXz/KlsQ8gdRRjlmTJbEWEfUO J2LeVPx7l6n27lR4M9qSXpujici6i8YMCRv9OCj05hOtY8iAFipoSvBFPJNlTyM1Stg2 FFew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708431891; x=1709036691; 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=E/Otirits4N/P66fEjvcSSTgES/jWUIXlIMqWKsiQLI=; b=e4YosGLHpucRwj+rVmW29L8EPmE7AdMrHmFlqxAhoDMqmSfysRSD2jUOiH/BaWtyRf qkLwzAaY35DRh1nOoAQpKu+t1ITzD5QiQcs5BGWbxu3w4RjXayroZGNugsmA6Y+fOKLT veK0MD14A/rPZBdambIEDiraCDntswT8F1XXgT/DE0Nm7hARMsYgq2+dTWrwKzM4QJpA DcRZhgHn4GI8fwN6dt74O0520Qf2Tm7TfRqpjiPFvY9yVNpYt9B4QAdkTeRKBv0uF9nY sma8Vs4xkck6oB381OL3zGvQSszqdP8whget6adUsm5AOSYH0R6XRlaCgkztGF/M7Pug 1ZBA== X-Gm-Message-State: AOJu0Yw2gTFUqXDHW/JTR+U3A5ROzBETV8M4nLmyrW5bg1BzI+mdVATw tnS/DU9kfDf5pZTq2kirzI8k2NOTpQkLjxj7b/973LjLINxl6ZmQTuCd461UO6I= X-Google-Smtp-Source: AGHT+IHaKSjeKuE61R6DRpvPmK9GfuEv4lA0oGIBCEJStj0KvTNNLUHe1QAjECOstHB89AgjUeYe5Q== X-Received: by 2002:a17:90a:5ae6:b0:299:879a:7da2 with SMTP id n93-20020a17090a5ae600b00299879a7da2mr5107821pji.11.1708431891112; Tue, 20 Feb 2024 04:24:51 -0800 (PST) From: Akihiko Odaki Date: Tue, 20 Feb 2024 21:24:37 +0900 Subject: [PATCH v6 02/15] pcie_sriov: Validate NumVFs MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240220-reuse-v6-2-2e42a28b0cf2@daynix.com> References: <20240220-reuse-v6-0-2e42a28b0cf2@daynix.com> In-Reply-To: <20240220-reuse-v6-0-2e42a28b0cf2@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 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::532; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x532.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: 1708431955843100005 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 --- 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.1 From nobody Thu Nov 14 06:59:40 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=1708432029; cv=none; d=zohomail.com; s=zohoarc; b=d6jioNjZUlv1gzAx378MI8FP3d44mFKcexaFr4NNWa/uLmmav7IqCY4OXNglzVujmhINRQGTnPlFurS/CVz7ayzJDgRfeB9Wa1cgEUAX037BbDti8Ixytido+VB7wqzerkf/UNvvEH67IHBQVZKVOh4yIF49SPiDBZZKHI4RliY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708432029; 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=/1f/zlVn5z3BkLnWlQs+cCnklNwxyMuq+kYjftlM008=; b=kkHcV8md7dqHuEOMrYcLp6KiWkhnKmOoROVrMEUnToj08uyH3I7fWR5NLKeEnrplCZf1ANGdlvz+kW8cXUKCVKZOpMoRzqB8jjex361ibQdgpT4Sl6at0kbqi0NhlPuGeyNzpduMErefB+MaXuSPEO7CGADW77N7xKe4JEZy1X0= 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 1708432029068410.4255021984429; Tue, 20 Feb 2024 04:27:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcPBy-0005Au-4T; Tue, 20 Feb 2024 07:25:46 -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 1rcPBT-0004k6-EE for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:18 -0500 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcPBB-0005qw-ND for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:09 -0500 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1db6e0996ceso39155275ad.2 for ; Tue, 20 Feb 2024 04:24:57 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id kp14-20020a170903280e00b001dbcb39dd69sm5649001plb.298.2024.02.20.04.24.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 04:24:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708431896; x=1709036696; 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=/1f/zlVn5z3BkLnWlQs+cCnklNwxyMuq+kYjftlM008=; b=rTPeqZoVVRka5nYY6Rbjh1BH1sqet4zxoVn8COoU4Ue5eIQqFIMB2VtYeUxPNSDWSI a/B8Btqaf9JPGWBNVpH5yvPfDIlB/rZ4P7setkYUpZuo/fktqi+AKoJ27seupb9d1Ss9 a/bT/OQe47I7cwQI1YPX7KOHjVLoPjHO3P06FcjUB4OPFNX5Q4c7xMQpPSazOKgp0ccZ d3Q7Kpu8GLoakaCzdHvE4bouWHTZTr3gL0n104gueCMdXgFj/pZfv69a1Km3dIG4T1N3 Kd6Vqi9nlC9roKOMmrXg7pcbiHudfHp3onpKP1dqaYq1CPgy+pjUxX0d5/UrYaYMX4a+ 8Peg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708431896; x=1709036696; 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=/1f/zlVn5z3BkLnWlQs+cCnklNwxyMuq+kYjftlM008=; b=VdAvu5qio8gT238olqBuGEqbFtpukNZz7eDg1rPOFfxwQOVnpHHTXkV5PcB64tcMa0 qr6ja5C5/ecRLQkCPsgbSNzIeznCPopqIzXGDEwjXMa/Ncjzn0KQ2VTVKWjLudl23pkF /jYa6UfgXcx2FMWcZuEHbfyfCArw2pQWrivOt1Uilg1qrOyqW77P45l7/c2n/fhHralf dTnnOqfPqO+MIBQJVi+fInLYcRGpXG/DCpX50/FeDeYhmLabMNEHXXQJJQFX0Gm7XZbx 0nPvqElpI9PnoOJSGiVNatvbF3O4WL7sOl2pfcD3er5KYpjeFUyiT1kmlEjjV20Ft6Gp GNKA== X-Gm-Message-State: AOJu0Yw+i+ad/m8B3SpWJwIlI3voLIu8YGmWKv4sRChA00YEaoPlllFP kV0h8YklwmmXLpS1uYM8Y/ydSetbF3tw5YBFo3t7IG8G5uUtujZZsWJQoEQcdCM= X-Google-Smtp-Source: AGHT+IH2Gl1aJq+6M3YnOo7f8OOo3tW/rzlGZBzADeRTwUhxklmAWsjFMLOE0ehXta5sN3gRg+NrYA== X-Received: by 2002:a17:902:eccf:b0:1db:f513:28cf with SMTP id a15-20020a170902eccf00b001dbf51328cfmr6572998plh.23.1708431895859; Tue, 20 Feb 2024 04:24:55 -0800 (PST) From: Akihiko Odaki Date: Tue, 20 Feb 2024 21:24:38 +0900 Subject: [PATCH v6 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: <20240220-reuse-v6-3-2e42a28b0cf2@daynix.com> References: <20240220-reuse-v6-0-2e42a28b0cf2@daynix.com> In-Reply-To: <20240220-reuse-v6-0-2e42a28b0cf2@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 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::62a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=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: 1708432029910100003 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 --- 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.1 From nobody Thu Nov 14 06:59:40 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=1708431954; cv=none; d=zohomail.com; s=zohoarc; b=Mmi6VoW+1IbOM2lLxJjtQ62yGZqd3v9MvFa3Hloy75lJ2yN3dYuW6An7d4rIdtOJD7tEQyq9VwHzRDENtbrw/niNOOHe9L6D8bMX9IFJoiKu3nVz/3bzHnMXGUmVbNHY9GFydvlkfTVden0RHU6fVEmahiYV5ZVeUJunOEd8fyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708431954; 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=oEGv7dA87enISvNwWKVp+KmYZzRr7ttxpncFC9B4Uog=; b=EgZX+8x1HeS2pywB8ZR8OEjF6pIqq/cjtGZomcMh1nT9WqnXINYJESPNv4PY9NCaXsmKEU1hyDFt/KGj3/n1cVo/5rAd+sOVLeImeFMd+2slzCoI9h9pclj/Zdp52PtTVT1vaBDOUIdI+DMLcrxJtGMf4Ibz6Yznk0a+jenECuI= 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 1708431954180517.5382270876022; Tue, 20 Feb 2024 04:25:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcPBt-0004t5-DF; Tue, 20 Feb 2024 07:25: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 1rcPBL-0004iP-LZ for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:09 -0500 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcPBG-0005rV-TO for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:07 -0500 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-5d4d15ec7c5so4414148a12.1 for ; Tue, 20 Feb 2024 04:25:02 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id z11-20020aa7888b000000b006e0465879b2sm6658366pfe.70.2024.02.20.04.24.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 04:25:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708431901; x=1709036701; 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=oEGv7dA87enISvNwWKVp+KmYZzRr7ttxpncFC9B4Uog=; b=qkiG+hbyP9rAOwRXIVyARGGwTivMwoiyS8JUSSMKzXC9RYw6GlHKNTEWjs6MeklYSh QAAIjEZFg3IPPYgyTOoGp2sB4qg9RONkmEybQLbsn7WP7L7tuE9ycReRXO0fjM0CZkBG a6U7c/5PWoJVVAM0UK9cXxaHodnPvQWEAcyFsdI3VNLt7MsymRsm+RDv71tsiOzM9Oqx Uu0vOOEqtctcuL8/uRF1i4tr/4lQmUtgyRUg5qJ7JA48F11hKEpLMrrfTlvITiVddMi5 UmhNHdj0VvOmqDcHm9UpHKvYUiqh3Y6vE2gy6MpuwirzgD/rtUtSlIHeAwm9y4X+ahoH uN1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708431901; x=1709036701; 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=oEGv7dA87enISvNwWKVp+KmYZzRr7ttxpncFC9B4Uog=; b=adsS1+d+PeDDHq28zdtNSCqvNXyqpCa5hFXaaVwHHng+XvJmZOhONsIr1nqFo5wBfN muYJuheWRDIxeuOmZ5XRM5kKzr59x2WjKjRmB4PA9nhHUUloVAzJHmk/vD74OLoyBCgX l66RbSsn26lqJnQXr8raNgR9lxGpfMpJ0iWhDlaGZpE3lDfXfM2O0CzEBN3P6YYkAs/m cse7ABAICAad/YoTVA2OFMxhvE1n5hGphfCa1k9fvlFcyXzk4fOESUI+CK7D4WRtc5k7 G2W5CCKFy/J5sBEVx0zuQRmpfMlmX3uUS1duzAiv5ZxM29nwqGGOTpVQX4lqIMFO67Vp zHgQ== X-Gm-Message-State: AOJu0Yz2Iu2+5P+7G3obDbCWzbrGG2sDYqSLm6ynt41oIKFcGj/BtLNB 3sfC0F7/QHB1B5wRFXQtnJjSLpcIztJVJgPn947PC8bGoVydJbZfzZdBOHFqiho= X-Google-Smtp-Source: AGHT+IHCa/KbTDKBpUcdL9a7h6N0etVKaFhUSO19iq5vA0cGz7TaoPt7s2y0FqYLQJ4wToa2LUOBFA== X-Received: by 2002:a05:6a21:918b:b0:1a0:60b2:451 with SMTP id tp11-20020a056a21918b00b001a060b20451mr17993223pzb.7.1708431901031; Tue, 20 Feb 2024 04:25:01 -0800 (PST) From: Akihiko Odaki Date: Tue, 20 Feb 2024 21:24:39 +0900 Subject: [PATCH v6 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: <20240220-reuse-v6-4-2e42a28b0cf2@daynix.com> References: <20240220-reuse-v6-0-2e42a28b0cf2@daynix.com> In-Reply-To: <20240220-reuse-v6-0-2e42a28b0cf2@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 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::536; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x536.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: 1708431955807100003 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.1 From nobody Thu Nov 14 06:59:40 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=1708431956; cv=none; d=zohomail.com; s=zohoarc; b=W7eAt0GzW9rczykQ9dnKhWHFAVMPB693bK66QNu4zZuo1p3NPkJ5YvAwj3c5HU0uvXJ6fJyzc8CmQgu1GF94tbKeXIwvHh1S6X6WkkvovuODVpkO/ltjwPjoLQEsVGKc0ZLk79iit74cy3NRKFRrF1xisCk5ScpkhJTO3zwtHSM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708431956; 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=3hB+WbDK4cCm7RTBoj9AyHJpy8Jl15j9ME3jFPJODBw=; b=KosJ5CjIa1hHiHGpixb+KUiBNpbka8Kr2+5LR8sO4UORfHxXvGJc/OxsFj+0xRYNtJfAJemlI+P/S//5fJYxONSx8YwVkmKqxG6ocLqNS45EEhkcya5nxjTatGz35KHH28ale1fqxj3rTzTXjaAGy/xMibgonTr3t1HkPkO2xmk= 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 1708431956608858.3843196194803; Tue, 20 Feb 2024 04:25:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcPBx-00056N-Rl; Tue, 20 Feb 2024 07:25:45 -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 1rcPBU-0004kJ-OU for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:24 -0500 Received: from mail-oa1-x2f.google.com ([2001:4860:4864:20::2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcPBM-00062u-8Q for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:13 -0500 Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-2185d368211so3235283fac.3 for ; Tue, 20 Feb 2024 04:25:07 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id l18-20020a637012000000b005c6e8fa9f24sm6498658pgc.49.2024.02.20.04.25.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 04:25:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708431907; x=1709036707; 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=3hB+WbDK4cCm7RTBoj9AyHJpy8Jl15j9ME3jFPJODBw=; b=N2BcQxoF3tyk9L/EWq/DyYk58p97D/DDRapTP6Iac3LVqUQxqRC3Pft4ABj1eR80MQ yNsmZcybVG6X0Zhejady0Arco/OIeXbcfmRKakiQIT7R5bMv+c+oPpMLQyHNd0K9wuYN PkfY9XSjij89Rk5aOeOZ4VTxHbcaOMLsCRZLT1OGtmSng3jss7NPjX+j4d33285cTZC2 lywpVW8a+ldATQevB+66FM079BHQdup4/ov6nvKAxU2F/6izrkuGqqSR3NYRR1qcyFaD AxoHw1KxSURQWSjysnb5ClAbN++5IKoqeP0a1lsokpl8/q/Bya9E5rZaxQ9x0bz+SAis tW7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708431907; x=1709036707; 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=3hB+WbDK4cCm7RTBoj9AyHJpy8Jl15j9ME3jFPJODBw=; b=GNktWLY7kDpJ3Oqramk/Rk4o+9bLADP7I/dPVyvFiQnnBzU5ChGu6LEe6ne2Pgy+tH WItwKjq6qtyNg6Nf/rocunpizroHhRT5BBiPgWSzcsUegrpMLvKqAhuCVF1pnENB4jCI 3GJJOOMAPgBF5HylGPYjIO5oBypoOU5F5MVB4l4Cj245UuXGa+dwkmgOHAVUNfEavZqS 17gW3JOTwH0vpfvdr8RYL5+6h8vBRlFbdjNuTxA7yGFzQ8eXpSz0eNmZeTxPzOkIKej7 JmJvzrioaM93ywwvZDsOAS3OsnouNWtIc8+FyFl1/gxZBklmhVDO3UBjh1EVHcu8KLtH 9E/w== X-Gm-Message-State: AOJu0YyLeikjzmbF0cNTTHGijmaXczz4ddokZTvpYBP2X9bsNNryno6O 3YAFzftDXF46WIbq4mzrI8JHHe95knD/SAxafRjYGGvjip5cTlZRwD7hOHRCtkE= X-Google-Smtp-Source: AGHT+IG79sj3dgQcNT5fbSGu9xfueYsqG8dCJKhCCuWONUwyIcf/6LbkKk1gUAgIghEp1UqtY8jL/Q== X-Received: by 2002:a05:6870:91d6:b0:21e:d8c5:a217 with SMTP id c22-20020a05687091d600b0021ed8c5a217mr6378474oaf.10.1708431906992; Tue, 20 Feb 2024 04:25:06 -0800 (PST) From: Akihiko Odaki Date: Tue, 20 Feb 2024 21:24:40 +0900 Subject: [PATCH v6 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: <20240220-reuse-v6-5-2e42a28b0cf2@daynix.com> References: <20240220-reuse-v6-0-2e42a28b0cf2@daynix.com> In-Reply-To: <20240220-reuse-v6-0-2e42a28b0cf2@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 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=2001:4860:4864:20::2f; envelope-from=akihiko.odaki@daynix.com; helo=mail-oa1-x2f.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: 1708431957603100013 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 --- 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.1 From nobody Thu Nov 14 06:59:40 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=1708432047; cv=none; d=zohomail.com; s=zohoarc; b=ei0HlwiCVp4pT/Jfu7gVmE4p8MnuehsNmz6r4C/X0Gny4S7WtUUjpfyJlZdS/geeqVXYS6m1CBDt8Hb+Tpia9G6/CHzAbSunGKTVj8PqI/DTK4UD0j6en92yyadiQ72WYLXkBvlHlvn2DoUT3ArWVRZMxR2xsfkGjLLxAErQcxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708432047; 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=biLtOdxmw7ScC2PCt1aJFruhA/YjrGKZOxrMI1yTmlI=; b=ZJBvrCN8PgyAeD5JlO7yW1W794DE7xYysSrczcolrew05daGa4cu+5BbbjKbedp3m5V0ENVQJFeZd0W1GQ0IOLEWkiX8ZsQHxx719lvsczvWeqrVaSA1jnnuS6iQMf7GYoFqe0E60igSY9lAi5RzcgsuNcXCMVAvRICcW9/Jgxk= 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 170843204799032.46751805545398; Tue, 20 Feb 2024 04:27:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcPBz-0005Gq-Iz; Tue, 20 Feb 2024 07:25: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 1rcPBY-0004mI-BF for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:25 -0500 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcPBU-00063W-FS for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:19 -0500 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6e0a37751cbso4037910b3a.2 for ; Tue, 20 Feb 2024 04:25:12 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id e15-20020a056a0000cf00b006e3be1a64f7sm5307286pfj.160.2024.02.20.04.25.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 04:25:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708431912; x=1709036712; 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=biLtOdxmw7ScC2PCt1aJFruhA/YjrGKZOxrMI1yTmlI=; b=VjwJj5kIkR2kjIfh5lYZ50vdGlTw8DawN5uR4UFtFlRNA5IOBIVQsgrn9cvp5C5Tj+ BTtOmKsABFLqQhvn1bf4MOo4VzoNwbQFMpJECwpAUxo4pAko3RaD8Y0CuxYPdPiPjQwf r5pCgq6DSlIHPbJuDUWZA3lo8xH+Gii+bjTarZ/qDJtsWLmhqKZgaSCgewqIUXVgDGzK +t3Xjpj2p0TXTZ34P+OH9subBwBjxr1WGneE9wKCdvAdNljWoJHFvYOrPUGRCWqLgp8S qRNG73Vse2dtdrgd+eT9E5m18c0zqBiVlIhi/xEbnL6GJXgnSqnFvThYTOxBtYBDBy4/ EFUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708431912; x=1709036712; 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=biLtOdxmw7ScC2PCt1aJFruhA/YjrGKZOxrMI1yTmlI=; b=DuF71DdB+o5esWO10CSltCsPtnRPA4C8zKUdYSiEk3Xq6BE9nC/FTloum7IkHhOLty BnBHgKFdS/7KYww8ZWrDtpR1+5c9EFIhTC/pSkrouX8nWgNIADhL2axHHSzl3MGozurO 3YA3c+LoKKCJo0ZPDHHkpZIdxP+c/Ra2h7p2dEboa5BNXg+rVPkti/VA78/p7CxXeRdh uor+PYN3rPduVFwYwxTcAhK78FTg1phxfIVHz4KUDDhZtNA9drHKZcX6b78HbYUpbc61 cgoLn8rKY56i5ele90u3/Rwqldwvx16NNQiztB/fNgRqoV8msp2+4vOzgE+Mkz2lrbdM E5jQ== X-Gm-Message-State: AOJu0YxjSRfu1PtcYOPTV2nGy/SqV3BUGfpGWxnX7A1xLSI1e9Sc4V6b EA3DpFoH1u6PDMXw3tQT1V0MRfQAoiZnS0sOjyLO0xdlR+Dds7rWC9tu9uNXhcw= X-Google-Smtp-Source: AGHT+IES+twjYRRKeqDkEtOEzECODUkMY2tZfJ1LeuaMTcvfj+JuwKZpyMJ/r43rirvCktjAABWh6A== X-Received: by 2002:a05:6a21:3401:b0:1a0:9115:48c8 with SMTP id yn1-20020a056a21340100b001a0911548c8mr7658665pzb.51.1708431911994; Tue, 20 Feb 2024 04:25:11 -0800 (PST) From: Akihiko Odaki Date: Tue, 20 Feb 2024 21:24:41 +0900 Subject: [PATCH v6 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: <20240220-reuse-v6-6-2e42a28b0cf2@daynix.com> References: <20240220-reuse-v6-0-2e42a28b0cf2@daynix.com> In-Reply-To: <20240220-reuse-v6-0-2e42a28b0cf2@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 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::434; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x434.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: 1708432049860100003 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.1 From nobody Thu Nov 14 06:59:40 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=1708432028; cv=none; d=zohomail.com; s=zohoarc; b=WoBFvCmkzsARQM+PmMy7Kbywhm6oWowrKPRqWQo+ZdfBnVhTE3jOPSYdSfiAEgp6MhsJKScbAvc0+1BReCtOPXs8bGetBisp3tZ1YBhn/nLukLUmcWmqs5Pb0XRFylJwyKqRzJYebM8f5euXYoB8fGtKRNUx/7wT0QgkZMRYaR8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708432028; 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=U6xQkliuU6eOM0QvuV0WWcKEWCKwljQhzYcjj1xV+Kc=; b=lKeUGV/RajUZJeWPSZyYmbqKy7SRELzyU8TXzslRPR9REeQI8ksVOruNzEmZMTc0sjZIJR6b+8uA13dG5XpFSgdN0f2kYtax5f3YNLL2SmkdEkWheYhU9BCgn5QXaxg8unt/OMS/uKmuzpfPSvtUNYJqXf5N5eQgbHKDpCKkK7E= 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 1708432028910945.258315835725; Tue, 20 Feb 2024 04:27:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcPBz-0005FF-8R; Tue, 20 Feb 2024 07:25: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 1rcPBf-0004oY-DC for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:35 -0500 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcPBd-00064M-7R for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:26 -0500 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3bbb4806f67so3708159b6e.3 for ; Tue, 20 Feb 2024 04:25:19 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id k15-20020a6568cf000000b005dc5129ba9dsm5478284pgt.72.2024.02.20.04.25.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 04:25:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708431917; x=1709036717; 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=U6xQkliuU6eOM0QvuV0WWcKEWCKwljQhzYcjj1xV+Kc=; b=jXGRP+bvHuPQHvoO8/4izt1bugN5X/0B8mQDfBkML2CzJuucZz5bUtbb9PsRhFvwJ0 XytfpHX6TrnvLWtsB509UDQtFZj5HN0YYX6j7+dQ3wUsDsh+KPxWIfrbIJq2Xa+oCcVQ /sYAQ0cuplq2vhXTg3om2S49NsqgL4XUjg9kgPathu3ZvFmNbY5E2C/g7MqxJx5568Ps yrqZHxNdeXh9cYMpm8rLMejXccF9wMyE15SXwy3JPXqBNosIQ0mSj8BQbwGUFe3YvjUY VVnj6ZjUbGw3S9S/zcFhnTXdXjZmNkRIbdNjt6o1mrONoke73kzBM1ed5iu1wpk3X9oT /akg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708431917; x=1709036717; 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=U6xQkliuU6eOM0QvuV0WWcKEWCKwljQhzYcjj1xV+Kc=; b=vyQGWhiix9+nF0Mc/zUCGpOOAgOLKgEOSa8mDqGYRdK090d/4VKnJhYmqf+Ntp3kSK RrVqjVIPYj5O6AztYnTnosQv7qxcNXZfLwIuhUu0mY5CUuPTII0Dq6cDs3r/HUN/AgRY RB81mLirNSsZHGJySVfEX5oGw23PoqfqZxAEwrSkprpvxc+JUk+me3bDWx0Kq4hjJU5L X4xRus5moxqqJcYWl6mWXYRfKXKMJcFHiWOvECwa+q7yDg/29mr4ocBhH82L7iO+F9/9 utcAI6tpTvIMxiWreipUZFUghFI1dui/Z+Rk8ZwuFSDto7ofBVoThJcj4lrPsE2bBjoW 3yuA== X-Gm-Message-State: AOJu0Yxi3V2eT3ShEJb6V/uBRU4FdBjp4fvnvxWGjz2Dw5zZAPWF0o1d R13fzpSxnyaeR7QY9nXIXqyiMt+Jgq/14S4UOrk0MATYrEGGKm8ml46rOXOR69g= X-Google-Smtp-Source: AGHT+IEx5FX6CsBMKGLSOhm5LnDZUGHVIz4kuh1bFvSTyN9iJOxup7w7OSX9E9cW/0LTaW+uJhLBlg== X-Received: by 2002:a05:6871:5b03:b0:21e:e091:7709 with SMTP id op3-20020a0568715b0300b0021ee0917709mr5140879oac.45.1708431917225; Tue, 20 Feb 2024 04:25:17 -0800 (PST) From: Akihiko Odaki Date: Tue, 20 Feb 2024 21:24:42 +0900 Subject: [PATCH v6 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: <20240220-reuse-v6-7-2e42a28b0cf2@daynix.com> References: <20240220-reuse-v6-0-2e42a28b0cf2@daynix.com> In-Reply-To: <20240220-reuse-v6-0-2e42a28b0cf2@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 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::22b; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x22b.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: 1708432029886100001 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.1 From nobody Thu Nov 14 06:59:40 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=1708431992; cv=none; d=zohomail.com; s=zohoarc; b=JJGwfKwXy4xihN6BHq+yyBrtz1zX4H7kjuzvpGKnP4lbhei4tLh5+dRQKgtaktUXYJ6RA2nCoRr7f7lHphd/SQ9FILVIP/Ucs8g5z3Ijska7vgUwrPPzGKhXxfdaRLrSOMSllTX6WuDCCK0FVpULK7cMDGhj/Lz8T3C8sysJGpo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708431992; 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=kbWc2PijaNJNeL1q4k+BRCaY1rCJHKh+bIfr0MnJgIA=; b=NDcMM8z9QPURqKInW7Q5VuqEVzbzoiPNlTJKPbELCd2UNll+/2C9kEPfzpwLH14mx/5/6PLdD1PvoeVKAmDUApjq2/muurM5KXyCzQPAMfA5m6t4HCIFMHs+0DDX90wIv567PKlZ2SaDbsJdLAvm6ujN96YvwcMwu2lV2Ge3dyU= 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 1708431992312259.13509911839344; Tue, 20 Feb 2024 04:26:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcPC1-0005Mx-8k; Tue, 20 Feb 2024 07:25:49 -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 1rcPBg-0004qs-UT for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:35 -0500 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcPBd-00068N-8U for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:28 -0500 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6e457fab0e2so1110873b3a.0 for ; Tue, 20 Feb 2024 04:25:24 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id c7-20020a62f847000000b006e0e35c1e55sm6605679pfm.79.2024.02.20.04.25.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 04:25:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708431922; x=1709036722; 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=kbWc2PijaNJNeL1q4k+BRCaY1rCJHKh+bIfr0MnJgIA=; b=Th3sDDyEO5piDw2Uce1tzmCTJ9DpBBAzlgpcQFtedjnd8/dOaAg7KgZy5IqfI+RBw2 IWJcVfQ9GvYJF5ZLuf399VSqcckJPAZvEglkzKCi5YetoOFpDDATzyBJmLtveg/bObYw QadMg2peqyV+N6tbu0m2aR8H11GVB+Ps/4jeo+i2r9aLfEem6LI+IHHQf700P0qgMWnt jvJqcYWKMZoJb+5ifQu5NYM+BwCL3lDidIVYTb20SBRBBjiy9jYBa+uwPBQwv7A80lc7 Z8++t+pEzPEU7TbxoZaLnOjMMqhAdQaGw+rjt3lAtNHLCiT8VwZlZKTxeeNDMS7XPguH emBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708431922; x=1709036722; 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=kbWc2PijaNJNeL1q4k+BRCaY1rCJHKh+bIfr0MnJgIA=; b=jC6u4InD8zmSHpfvi9W2yDaEGK2StvHmbl8U1h5qTApJ+vJp4UEwdrVGRI0G3/b8vy vcve11FOMnS6nlSj28vsp0sEUS9uVlkweYsdCjFowylIpUMwq6n0mH4XVkwYn7feCs3g CTryrtnRGQvAismbZrKumIgRKH/4QFTT1NuZywSxA1A8HQ/vK4ccZDkC8KuBX8GlZSSQ JH54/W5bPtFQiqndowRALpaOvJX3csM+QVeuJuhc9+DwwJ/yAhfgC/kj1t+c3MOXez1+ vOL8qTr7XZ0+sQlDdWlhpFsvdEDSsIT/w80fSOgm1tXRwgdCCNY3MiZzxc+IhXMfGwTc c1+g== X-Gm-Message-State: AOJu0YxJ39GxPMDoRmFL3cD0fWAsKrYwGMYps+6+iQ6DSgkL3VhoEyVk dv44YV8j/m+5sxTGoZXKTAjTu6Kplow0k+NDA13nXrT723QVh0sHF7/DpBIngPs= X-Google-Smtp-Source: AGHT+IGNarJ1hxp3u1bI56/D+ggbAMYB8zWWqGCGK53t0KUCBVy3D2p8yVZEWjOZ1Krjbr78jNpFBA== X-Received: by 2002:a05:6a00:3016:b0:6e4:74d9:6f0f with SMTP id ay22-20020a056a00301600b006e474d96f0fmr4795326pfb.0.1708431922372; Tue, 20 Feb 2024 04:25:22 -0800 (PST) From: Akihiko Odaki Date: Tue, 20 Feb 2024 21:24:43 +0900 Subject: [PATCH v6 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: <20240220-reuse-v6-8-2e42a28b0cf2@daynix.com> References: <20240220-reuse-v6-0-2e42a28b0cf2@daynix.com> In-Reply-To: <20240220-reuse-v6-0-2e42a28b0cf2@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 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::436; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x436.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: 1708431993751100005 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.1 From nobody Thu Nov 14 06:59:40 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=1708432016; cv=none; d=zohomail.com; s=zohoarc; b=Ns19DlXy9KRbaEVX7pHGlu9o1cHtMyhvB+ldZYx33eNb2tIOIBcsvLxnOgRoX0/TVkpAE3JyY2QXAP6NvlxPzrOylWuDaY8AkE3/UJ+lxb9lK79vMsej2OtMlSue0WmdGoFxMLL+WzjktnntqBLFWZgAf/o09He1GGZ/vCDrUkY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708432016; 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=Q1P1QXlqV1/8uL6odiFFlW7Vd89tnDTB/dL2O/F70JE=; b=KGJs40KFpW8g9x06PUbqyq/4rYpJ6xASEpdsf7HsZ8SH6gVR49eFaZH29licje6If7k0k/i1jMv4T0Yc9GMSzervfvPQhXAWBJ8vsCSB7ghyS/E6l2JrIoV2z0unds9B2290YD030U11qLIRfagZFoM2JSWdFsFTHzNc9zDDk44= 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 1708432016242170.07487220597557; Tue, 20 Feb 2024 04:26:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcPBz-0005Ft-FZ; Tue, 20 Feb 2024 07:25: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 1rcPBj-0004rV-Nx for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:37 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcPBg-0006Br-S3 for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:30 -0500 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1d918008b99so43706285ad.3 for ; Tue, 20 Feb 2024 04:25:28 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id h15-20020a170902f7cf00b001db4433ef95sm6076392plw.152.2024.02.20.04.25.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 04:25:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708431927; x=1709036727; 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=Q1P1QXlqV1/8uL6odiFFlW7Vd89tnDTB/dL2O/F70JE=; b=y0AaDbFFXW/Qxq1AoOlE8346bXgTUkYK02F3RCPFaxNSYoJbqs82TAkuzvfLpAg2Y0 TVKpc93oO5uWXobX/NOcZhX2YI/y9ZVvTqqvobrFgz62Gy6d6YeGQWr3y3mkl7QJ7L2l /4yGR+ZCcuvPWMpc0Prl9vpqnSaLb8UI7VKRXRzQz554rbThWDREnxJxsqj1h3bJIPeN QWLYTfPpIy4CVZjYrm9LS1kj6p6x/PIwwmsXll1woRRp90cbIKmS56Co38HCBwUQKL8C aRwAK3F5qli2cRY8g4zqt3Ts09yVMHWJT5yBeRFOtLtrOggpPBqA9WlAHih8KUo9KoBN 6QxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708431927; x=1709036727; 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=Q1P1QXlqV1/8uL6odiFFlW7Vd89tnDTB/dL2O/F70JE=; b=nNhBtxPiaXOn+RNwE9956ArBlyRhieLs5gFVjCNwAviyG4iLLOpsIlUbx3uV0+wT+6 s/4DZ+LtGwMxMMk2ni3XYVNgkNaK/9ntxTdyutna5L+K+6h7NJdx3Gy9DeGMOD2fyz0/ g3XFUFdkfE8Kv1yq8cf7cON9hjfUPVkowgRMOF5zMXapJevQ9gc4DrRLKaeu3Q8LBXlS +rwD88OSYdnnwS9sOnw1CVMMQ8CbCKZm2gda9sX8qUIzardpNvDTyKihs42NzenZ8qCw T5hlB5H6Xp5aZkjo/7V/5oZs4vM8HnFOukg/GVklD9voUGckDpvqKjiljDDcz0o9qUwA ac+Q== X-Gm-Message-State: AOJu0YwO6XHCqe8d0OAu6epRK1DOG/UI7NICldYWp+aykbsEwshE6m4u C9g/u2GjCEdUZVqQ9NoRcMLuA8TD6bYl6mG0ROQ5oD+72YjyaQj5xfIl95CvbAY= X-Google-Smtp-Source: AGHT+IGYFCmi4+3aZ3aCfla1odpTNTheopDtaVHPuFGRrpQc5mMJCpOY5FCQ7fTvwyHBR7zc2xA08g== X-Received: by 2002:a17:902:9347:b0:1db:95f0:4876 with SMTP id g7-20020a170902934700b001db95f04876mr12927281plp.68.1708431927654; Tue, 20 Feb 2024 04:25:27 -0800 (PST) From: Akihiko Odaki Date: Tue, 20 Feb 2024 21:24:44 +0900 Subject: [PATCH v6 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: <20240220-reuse-v6-9-2e42a28b0cf2@daynix.com> References: <20240220-reuse-v6-0-2e42a28b0cf2@daynix.com> In-Reply-To: <20240220-reuse-v6-0-2e42a28b0cf2@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 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::629; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x629.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: 1708432017770100001 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.1 From nobody Thu Nov 14 06:59:40 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=1708432048; cv=none; d=zohomail.com; s=zohoarc; b=bNMYhcVio+aoMx0pD54qoFVQmZJKcVGIhts7gGFBh1CMlMZVyVX0ZCYB5xhbZldgYeMrs3jyvj7Frz1R9gSODjbgyUk4BZovuSXaInW+5jdSQRFqbk0NPbORSvKBN5ia07R8J3eqnnBdKeqkinF2P4CeWeZu1ke/ZMWzGG5PVCE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708432048; 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=512kyfl4mUEUDTsjiH69u6gvpMmtttv5Fvemo/ortGY=; b=HSqaTHVLehfsuPDZYvpI6YFQQpXIa6JXfs+Yezxy2tgdjfon0YPP8M220+uI0ul4kkLhpd0UY7E4HS0yQNgdbS2NYYYYhgC+vENjSLwKaJ4bQv3BDOJi4OxV9YkXr9MamcZa4xTuloQ9PqkY3o7R3k9WILkD4Dh4Qw6OaDCCbiU= 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 1708432048742190.4795232012708; Tue, 20 Feb 2024 04:27:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcPC3-0005Un-0R; Tue, 20 Feb 2024 07:25:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rcPBt-0004y0-Di for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:41 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcPBo-0006CO-WF for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:40 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1dc1ff58fe4so1910365ad.1 for ; Tue, 20 Feb 2024 04:25:33 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id e19-20020a170902ed9300b001dbbe63ff12sm6080541plj.66.2024.02.20.04.25.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 04:25:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708431932; x=1709036732; 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=512kyfl4mUEUDTsjiH69u6gvpMmtttv5Fvemo/ortGY=; b=2HDGulXnp25LpqRH1sWLEg4cKRVfyS9eehraPvTLs6itaCqEwv4Hv614/7LH+mkyO/ F1rcVa3pNrxa8JGDnWkXBIQCIpFXZ2i3ximxjFl1R7u2nImvy5LwvQndFq/XB85FitRp uDYifQRmBRrYOkN1+gANesDLVUKZvtAeP304VwKWzdzukwlSHPggfQRh1VYChqoKtGm0 poZDA+KyoeOduKbiPzxethPAtcIGuGWX9/JXIGnJad7F6R5e7wuo4qzPAgXD01O+45/s EMknEBpw7xGq6cl5eAK66dje8xj4usOEgLDWnRkeYgzBpJem5CF0jmdC7YQD1OgYIPdA wcmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708431932; x=1709036732; 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=512kyfl4mUEUDTsjiH69u6gvpMmtttv5Fvemo/ortGY=; b=C0Bzyi75TU6t5BkLO5fa2O2WLj/dWULMDB0MdNjPgmY7XgWFl0f/o2+yFrQY9oXH8R 7jIIrHL+DcXLm3bghE2cyURKIyrGmzfUc24Fg6jJ34ydqoerjMoN5pmG6XQlvMEvMj2f jtjqRGF3KXsGtv0G1gKUd5krpmhPc02H33+nLiHDyypw6QeokWQQ0DzKbIOrEAUVoGmW tFzLlKC03kcgPHeJd9tTNQDhTyJ6kKsZ8yzgE4ZY+qJYPPjSLfD+TE09RkwpZGBXg31S rB6yMFVUW1EfL/hiUMy0K/4YIo8yMQEOkD0L56VseNATBth9xs6qPXchXEodrGC2rALi PI0A== X-Gm-Message-State: AOJu0YxWA+KfMvbBHQvj1IUAJ6Bc1X8+ANA7Pki1FYZXdqCB7/k5K7Bg 1WauIwr3PJ4nnLsW3pLdAkTM1k5mZrYLbSP9d0/Angzy72zcwbJvlTFsRdSTmN8= X-Google-Smtp-Source: AGHT+IFcerYaere4MoEb1neV0nibrzO5aaN3XS/9Trj5bnEhHRzp0e7S+UB9VruYJEwk6eaIy1AnWQ== X-Received: by 2002:a17:903:2350:b0:1db:fcc8:7d70 with SMTP id c16-20020a170903235000b001dbfcc87d70mr4898089plh.49.1708431932274; Tue, 20 Feb 2024 04:25:32 -0800 (PST) From: Akihiko Odaki Date: Tue, 20 Feb 2024 21:24:45 +0900 Subject: [PATCH v6 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: <20240220-reuse-v6-10-2e42a28b0cf2@daynix.com> References: <20240220-reuse-v6-0-2e42a28b0cf2@daynix.com> In-Reply-To: <20240220-reuse-v6-0-2e42a28b0cf2@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 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::62c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+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: 1708432049885100004 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.1 From nobody Thu Nov 14 06:59:40 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=1708432028; cv=none; d=zohomail.com; s=zohoarc; b=GOYbrP34WtYESepRJlpmyd/NVDZklr8OAnMioTretfQ169ppsif8Ap0s0LjuwvvPrrtZjGy5YG8qH7OAsMNTPvWJBgLwaufEuXZuRQpCkJK+/h2n7C8cghqrYjYPbU9ylCUbivPbgAfgjXj3rFTxOMqV6y3xh9w6aJQIuDEoxG4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708432028; 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=nx+YxyPM604jNXU1B1YXm0e5pQ0GXOm984QmGrq4zA4=; b=gFb+rBdT5tm4GlS1AbJVtWtgbCh7mqMMYa7BLAllXVhWpGhXa2x0LTnUtjGaeXw5NnLB+QTBjO6L125A2et614BBetvlGWtw08HHvQg+1U/RXvaHYlQV18YRgeqnKkG5fzIKe2gfyUMVc91/uGwswfWfdORb/OtTLv05yEpK+pA= 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 1708432028467205.06245619451352; Tue, 20 Feb 2024 04:27:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcPC2-0005Rv-Bv; Tue, 20 Feb 2024 07:25:50 -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 1rcPBv-00051M-1K for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:44 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcPBr-0006DB-9I for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:42 -0500 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1d7232dcb3eso29456845ad.2 for ; Tue, 20 Feb 2024 04:25:37 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id a19-20020a170902ee9300b001dbb0348733sm4189838pld.67.2024.02.20.04.25.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 04:25:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708431937; x=1709036737; 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=nx+YxyPM604jNXU1B1YXm0e5pQ0GXOm984QmGrq4zA4=; b=vrDGGXjhM+D8r8XfT0gOkLmM41n2DfCBo9r+2/vu5373ZQpr9V1VZSCf+6eCPzR8TI 6aBDG6D+qdap+dDdBkhvzRm9CDoJ2pVBDixdfY08tDi4eG7ROaXBO+ipmDJeC9jys2L0 1vy3eNcrWEeutYXEGIeghviqki1IYT9SavlvoVfprG1eouqtYIXPAzoc4VdI07BvljaW ZTUqj70yUQV7i8UGnDU8rOGd7etfYXHGc8CaEZcuECh49Y7kwjW6pHLHnVJociEbNVCT nzjdkIR9CLIXHI3xsnwrVIWAvV4CKQ58jTUt8ILIKNxq6oWbM4xvA+ya16WKT4/jvc0n zZmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708431937; x=1709036737; 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=nx+YxyPM604jNXU1B1YXm0e5pQ0GXOm984QmGrq4zA4=; b=wZ2m4l4/0HOifxjfU8hNVbvlIgkfSgB4/6QWISpyTCII11pqlexb6ySe1EH0oDF1hs 35Heu6iHV9+YCoxj2tlZPra6ZTGnQUIgRD0SvHRUis2on/ikp7kJ5nYkY/ibvs1I7xye vA0XrelVrGPE6VnU5ny4WjDGmxcvS0OwqqdA+QEMm9hgO0budVYfvstazWexwHWDsos5 yu2ZpFEpcJ7FgA973BUKjfw3iVGkjdEEFIl6AcFxPnzWX1/y5ZOnyV1E47AvxDAYABm2 mxJXuziY0abc0xV19yiozQeM17PCbXI7/EA/ZY6i/bij1O38Ft9HZe0hijxV0vIIrbu8 JEPg== X-Gm-Message-State: AOJu0YwyTODbmpX0azGvV9AAVQeHjfzIFXGDXhXDASOupzEksuvwsmJV RqSMYTWcpOV35VD6OUgU8Jk61l7XNtXuR2dqRkWpCRxTQAzxGvNC8AlBcasYvjQ= X-Google-Smtp-Source: AGHT+IHSUBJqKNlHfy15uOM+naw0VZ4F7WiW5P5MZkC93YvKH+ccoZFAFP5IiNrar1vkH3oNmebOiQ== X-Received: by 2002:a17:902:dac6:b0:1db:916e:d77a with SMTP id q6-20020a170902dac600b001db916ed77amr16352732plx.2.1708431936816; Tue, 20 Feb 2024 04:25:36 -0800 (PST) From: Akihiko Odaki Date: Tue, 20 Feb 2024 21:24:46 +0900 Subject: [PATCH v6 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: <20240220-reuse-v6-11-2e42a28b0cf2@daynix.com> References: <20240220-reuse-v6-0-2e42a28b0cf2@daynix.com> In-Reply-To: <20240220-reuse-v6-0-2e42a28b0cf2@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 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::631; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x631.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: 1708432029887100002 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.1 From nobody Thu Nov 14 06:59:40 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=1708432002; cv=none; d=zohomail.com; s=zohoarc; b=JHITFbW0fVt0CUTQZsega0vHj1sR/84YlQAjICNJZ+M7sLVey+dl7NZzivaB9iiXa86wJ+4q2bCsCIij10mc34b/kiA3wrZTTcPAzB+fbgZGj4Vv4HRBWiu9mf7UH68FvW0bS59d1GMvaAbtdMQjJQ1YXmYXex2qLZmEajbcgA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708432002; 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=2CSd9i6jUkmyRdPPv1psHKlWQIuoE+JKADHe2JQGZio=; b=jqCa53Qpq7iKaMngzmFQHpnGqqhZcC/J5iBnTQLFV+0aoDgfOy1J4VIYMq+SvJFbnMPFAIVmQ7rh8eKj7duvwBVURT3qk1KZjltBRWT4uPKJJ8h55FEP0UqvlQkvFPFCIKxhGpPgFuGxXJ3kocKZ/sPBkb0BFuMMyzEOzNLUG3c= 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 1708432002866538.9961704055177; Tue, 20 Feb 2024 04:26:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcPC5-0005bl-MN; Tue, 20 Feb 2024 07:25: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 1rcPBx-0005Ae-Tu for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:45 -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 1rcPBu-0006F1-PC for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:45 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1dc13fb0133so6435685ad.3 for ; Tue, 20 Feb 2024 04:25:42 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id o16-20020a17090323d000b001db7e461d8asm6185261plh.130.2024.02.20.04.25.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 04:25:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708431941; x=1709036741; 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=2CSd9i6jUkmyRdPPv1psHKlWQIuoE+JKADHe2JQGZio=; b=TeKG8FB5QHPAvbE4enKqIlJnuyNcHzesIehSYBpnBSXv7eFYmazhxbSNMdyIWX+uWj rC4iJzh0GtTccSB64rptQSwoDPCg+x1tWnkwVr91a7NblAE1HmYBEZXyS2PX782XUskf G9+ftqWFa6/nDYZI9h0/oLPEid3g4zopyp1OornP62PLg7g0A3iHayFizgoDfJrS2ETc eVpo27b80t4Bi3Xgm3Xi634KP7BKHKCIoi27WWDAHvakZudrs4xthXIttZ1y+2x08gLj oWZjvVNSStBaqOV/wRFLt8VNbkP3XO0E6y5RKCISRnUpVtYXTY8nf5h7T/k1BZd6PtlF z6vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708431941; x=1709036741; 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=2CSd9i6jUkmyRdPPv1psHKlWQIuoE+JKADHe2JQGZio=; b=ewpttiUmsp8lQ9ZJbqsoBgyzyE9ABv/W9VgfJrfQm+wsKBR72yfIhe9ciCkY404WVY wvO2l7d33tgnobcRdN2mnc/BUCvdOSnfQzc2VelS8KDJKuQbs36uKnueu5KT1eMeT9d3 vYqE2Nm9psj887sCaZS2SrN2x1Yzjt52tQ6A9wbrC0Ea2dWl/PhhGhHz2wxuahkFgELw /iK8UcE1xCW3+r5UEyMYKj7GSh9nEQi1CrTbLHaAZyEu/ktz5InuRIjr9S+FcXjuKxwW Hyxtxqzxrq6XxqEEV729RFqcn/POgTifs8Baw/sc6P51QE88YCZhZRe2kn0fchWpN7bG G3dQ== X-Gm-Message-State: AOJu0YyVORpcyuIkcvUxgxE/Nbg5O1wg5OFNgp+xOSVIKHcMMsiD4iev las5XLSSo8SFZNCVsWp5/m1d0uSvDmjN829yFjlXn1hDruF7chiaiB2O6vd/vto= X-Google-Smtp-Source: AGHT+IF3Zx+4V77tBK/Ad6xoliCjosSFH3K+Rze4e8kymnyK4KWltrL/5BMcZs1ZJQNqObq45NhtYQ== X-Received: by 2002:a17:902:b112:b0:1db:d184:c458 with SMTP id q18-20020a170902b11200b001dbd184c458mr6049225plr.44.1708431941341; Tue, 20 Feb 2024 04:25:41 -0800 (PST) From: Akihiko Odaki Date: Tue, 20 Feb 2024 21:24:47 +0900 Subject: [PATCH v6 12/15] hw/pci: Use -1 as a default value for rombar MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240220-reuse-v6-12-2e42a28b0cf2@daynix.com> References: <20240220-reuse-v6-0-2e42a28b0cf2@daynix.com> In-Reply-To: <20240220-reuse-v6-0-2e42a28b0cf2@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 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: 1708432003778100001 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 -1 by default to distinguish these cases just as it is done for addr and romsize. It was confirmed that changing the default value to -1 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. Signed-off-by: Akihiko Odaki --- hw/pci/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 54b375da2d26..909c5b3ee4ee 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, -1), - DEFINE_PROP_UINT32("rombar", PCIDevice, rom_bar, 1), + DEFINE_PROP_UINT32("rombar", PCIDevice, rom_bar, -1), DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present, QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false), DEFINE_PROP_BIT("x-pcie-lnksta-dllla", PCIDevice, cap_present, --=20 2.43.1 From nobody Thu Nov 14 06:59:40 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=1708431998; cv=none; d=zohomail.com; s=zohoarc; b=YqXtfGGhxEIt+76oKQJ8USXX01wBQzrYBrAvsYj9RDfeeIaxUtOdLH73eigJKvVpAWpiSUfme6Jp0rUTEF5LgjXkI4UcoOlrn75JQ9nQ7LLDEBlKE5W0Tbh2vsGu8+aTsEiKGnKXbtCHAq48ELPqKliRWQb1mcZdhAVKKRGrnTs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708431998; 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=9dP8CIVGa2z+MJbr16ngrSkEvcO51KPNeCuX2Tm5UMI=; b=MmZg8dnMZn/Mntkx6tR0quak8govA1fQ5/182C8+/ECRleXGnbzCEnZrgkN3HfqfUyUWinDP8pjE36F/75OXr5xCgwuBGFOAR8g75DPfuLnG+hDBNBAxFmbRAjtwhFTLe1VKcsWU0X6lFxXMUprQoCL9cOcnZxvxRQvJvTpWhi0= 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 1708431998312631.299323834356; Tue, 20 Feb 2024 04:26:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcPC4-0005Xy-FP; Tue, 20 Feb 2024 07:25:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rcPC1-0005Pe-PD for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:49 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcPC0-0006Jb-68 for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:49 -0500 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-299e4b352cdso312190a91.0 for ; Tue, 20 Feb 2024 04:25:47 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id w3-20020a17090a528300b002990d91d31dsm7162833pjh.15.2024.02.20.04.25.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 04:25:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708431947; x=1709036747; 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=9dP8CIVGa2z+MJbr16ngrSkEvcO51KPNeCuX2Tm5UMI=; b=bGWEY4+tMRQG+UiL7ZN31mgXcseCVlziJ0f++58MowsyMGnYTptpmgT4EsfNHs2GJ0 AXJZEyz0I9JUN6hGi/EHTzvOWqW/q7h9AHuAxrwZhNQkFFdXH4DVKSRbVvOoPeq56LRd DQgyqbcctp//yvcIMlHWwKIQ92DPa0npUHoTcMicUH/tUppnx9PVQ78TQh6yE8sT3FPX wnE18k2mUTnG/5G56LCoSGgl3gagXBf7qtdMid/2Yr/3LcmsSy3W1xG4xR08cW7uq7kW 50Ww/ukiCInDrdPTSDvamR0rRUZD+3RniACpyzfXFmcbKxEFEdn3xSOx76Tyzi9jHeIH xe6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708431947; x=1709036747; 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=9dP8CIVGa2z+MJbr16ngrSkEvcO51KPNeCuX2Tm5UMI=; b=DJEYmuGpSr4xqYJQcii4fBD6Yk3U+yo6t0xD3fLXbVVqB31qjSrxJUIGEtsH5Sa1ay ZS44257VR3ll9TdS7SiwgePmPWAVE24OB91xsyrmqoEFwZT67928cPAxkKt31W007f2Q B7YqO5mYl2UiDzsaAqNbq7oELZzzPc4o2oB6c6gjcAppvoPz2okjg9Xslvl7s0j2CoQD QkDD9X/wd63c1GH3hLAbISsrVSRRnEOuts+3+Xcys6xs49MNTtybO0/wH19ca/mSNPvG i3QMw/cokW8FGn6T6L60cWQx2qKyCWOqt0g5pSJIN3hdM+q0CkQAOEYUx03PUKuEL+zw RYGw== X-Gm-Message-State: AOJu0Yz3RemHcfL0SLAXXkYsT7qCpXRqi/vVItSM80WJqrgjYjeSK+wI mwytwE2+XxnNqpxKYkDI9pZC7wTQbI1ETfn990JTmP1GHCdhoPKhm5qoFEFzonY= X-Google-Smtp-Source: AGHT+IGgAMZDhpBFFvxV3YmQXCoq5xY/wQk14+5bfR/GSY3DpBnAO6q69sKAuORmTilryIcuNVwiIg== X-Received: by 2002:a17:90a:dd82:b0:299:5186:1989 with SMTP id l2-20020a17090add8200b0029951861989mr7202411pjv.37.1708431946771; Tue, 20 Feb 2024 04:25:46 -0800 (PST) From: Akihiko Odaki Date: Tue, 20 Feb 2024 21:24:48 +0900 Subject: [PATCH v6 13/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: <20240220-reuse-v6-13-2e42a28b0cf2@daynix.com> References: <20240220-reuse-v6-0-2e42a28b0cf2@daynix.com> In-Reply-To: <20240220-reuse-v6-0-2e42a28b0cf2@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 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::1029; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1029.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: 1708431999740100001 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. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci_device.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index ca151325085d..c4fdc96ef50d 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 -1; +} + static inline void pci_set_power(PCIDevice *pci_dev, bool state) { /* --=20 2.43.1 From nobody Thu Nov 14 06:59:40 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=1708431972; cv=none; d=zohomail.com; s=zohoarc; b=bH6C07xCKHVxoNTV07SFP/ypMphWl3VDwTnw128R3EUUERQm02pZesghaAx4U/i6d27Xgsf8GSf95X9Xel+qJ97mXfYxXoxsAMYKYOBn+aQbOjg9ZiUp0f0o6RT3EXQX04vGcdFMAUbCe9nWLk+OH4rBWisO8PYghpG0ouIkbZQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708431972; 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=uKib9lFhkqfQp/XBira3ThQ631U3FRHMXLPB53AQUH4=; b=jJwA6BLZ8Md7y52L63XtPMjGUzNvvchXLseCakEte6Jx8WKlVNITw1iIDKiC2nTbz7kQX0JWjB7uB7to88w4/mPV/Tc6O8FhGP2g0fvCyXEuMyurK6EWq545Nt4g9/3W5LYA8e6RnK6wroR6P2Dy2tdSVlTohsT9DbDANPZe1Cg= 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 1708431972236928.8913955935803; Tue, 20 Feb 2024 04:26:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcPCF-00068y-0C; Tue, 20 Feb 2024 07:26:03 -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 1rcPC6-0005mk-ES for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:54 -0500 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcPC4-0006KC-Nf for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:54 -0500 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6e0a37751cbso4038382b3a.2 for ; Tue, 20 Feb 2024 04:25:52 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id r12-20020aa78b8c000000b006e3a9bdeb99sm5471510pfd.40.2024.02.20.04.25.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 04:25:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708431951; x=1709036751; 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=uKib9lFhkqfQp/XBira3ThQ631U3FRHMXLPB53AQUH4=; b=idJRrDQUmEmzigJ2pZDBG+8ZKm7mXs3/c17eUnJXAqq8qKhhd70LCfZaMRW5Gf3Id1 zDhvPm28CiBUyKNSFdLCObmKxyLxKJNd52aJhrSJDKFLp+lnnM8YUIw4f8txwQp1cNbs SfoXRT8eimV7iVc8oPutL7U5Yp95DOdtT8x9a60f31m2GjCtb1nyjdlvoHvn2uJD2qUP 4yCWN6CkhF04Yzxun3992Nagn2+4N1JZuLC05Ny0+/jmihaScDAd8lmp/ND9sCJ+Icd1 ZnwZT6RIxfaDmASr/o0wmWGsUwHZULLeRhbHBIuWzFJSYpIyiQZbCmcPACIGlDwgelvT kJnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708431951; x=1709036751; 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=uKib9lFhkqfQp/XBira3ThQ631U3FRHMXLPB53AQUH4=; b=QAHQWLwr31O//2aMCzFIBo6JowTCncXKPxshXa9WRd8I5cY0wfQYXB1w52UyCccbJT dvmiX5FFbHA8mrL5m15q6Qh32AucO284dzoV+Kk6fOw+uT9o+0Ko6/wswJTq23C7Lg+k OYMNsEl6kQrhbepJD5ETh7W4JOZ03n5elXnid4GwnTdADvoSPPyPXIEFVPLdeKcLxO5g 6RXKJT9naeOyqMc9MwYyOFl7B/aqPvjXWTvleIDpiLZQGakRUD1/bNbgMDg0qmUZb8N+ Tj+/K7comTnGPei7tc0bbaLAeZxDKlK1apQEkylKym1Zc1it5fdx4PcVms1jJd0LUCLN 4U3g== X-Gm-Message-State: AOJu0YyWXnjp3ei2tJeLGFSjjAu3T9TbCP5ALquvsvxdpXj2hZehtsrs B/I4m2llQH1853U+qMbdWqhOsOUYScAMRUMXcJUkHlSY8Pv1aTpucEGEcyvzsUg= X-Google-Smtp-Source: AGHT+IGHQhWt3hQOOgyuN4ZRBDyOXrUpLWwspMDvTvjtlvwEBQnGA6qrrY4yNCH3q4q8MGk1ZK3ghw== X-Received: by 2002:a05:6a00:7295:b0:6e1:29ee:aae8 with SMTP id ll21-20020a056a00729500b006e129eeaae8mr10793993pfb.25.1708431951444; Tue, 20 Feb 2024 04:25:51 -0800 (PST) From: Akihiko Odaki Date: Tue, 20 Feb 2024 21:24:49 +0900 Subject: [PATCH v6 14/15] vfio: Avoid inspecting option QDict for rombar MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240220-reuse-v6-14-2e42a28b0cf2@daynix.com> References: <20240220-reuse-v6-0-2e42a28b0cf2@daynix.com> In-Reply-To: <20240220-reuse-v6-0-2e42a28b0cf2@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 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::42d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42d.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: 1708431973644100001 Use pci_rom_bar_explicitly_enabled() to determine if rombar is explicitly enabled. Signed-off-by: Akihiko Odaki --- hw/vfio/pci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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.1 From nobody Thu Nov 14 06:59:40 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=1708431990; cv=none; d=zohomail.com; s=zohoarc; b=W+K7ZMTZoCstgHig4dJo8NjMDeTJgjrOJWUAIj7kZrn7Dh41hJwSruetGzYdOWdGmeKqVYlAycvS9eu4ZWdfzm64a9oZYH6VtLQtl5GmQkk6EIU82s1sZQ89CmqKipGGkPTHPpA6wpfi0EoIoCalK+TVlwwQvALnKIIXOPwD1d8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708431990; 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=UlKagWgW/Suhx5XrwPdfnlsQ3+kK6LLiHW7W/dUMHaY=; b=Kmhhd5exPFw4PuHX/JCI+Hw1jmAt0ixjRNDnZGrNBiXyS2HLjjlOjfi8LRjjGsel6FjVd+Gj/DYeQn1r0BUqVRDqeK05Y3SpZfMML7SLz20+tBFO04T+pZUjkDd1jGoLE2mTkHrlMq1KQvF98AUMXyaM6e//PFjpOec5i+JKgqQ= 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 1708431990134398.34640025675617; Tue, 20 Feb 2024 04:26:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcPCL-0006Qt-H1; Tue, 20 Feb 2024 07:26:09 -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 1rcPCA-00060N-UG for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:26:00 -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 1rcPC9-0006Kc-7z for qemu-devel@nongnu.org; Tue, 20 Feb 2024 07:25:58 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1dba6b9b060so26182245ad.1 for ; Tue, 20 Feb 2024 04:25:56 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id ko6-20020a17090307c600b001dc10796959sm1700921plb.284.2024.02.20.04.25.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 04:25:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708431956; x=1709036756; 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=UlKagWgW/Suhx5XrwPdfnlsQ3+kK6LLiHW7W/dUMHaY=; b=QVpQfLvRz372Q+a92914tV18cxEVjKREcPCd2WXXeLeqFUND0v48GaHYRl8LONJWfz HQIstCX1JJRzuO51qQPpyLp9oX97DxpUzSaeFzBimIfOZ/C90mhvWoHFGGDoH72tbsrG r0tEFiES+GUss7sApsKaeUTTNIkOEYx/2t4lX3OrGEAROCmlwtKCWoPBLz10gv1NklhT WGGh6BqEoHieQ34cP8n+A3UYeX+Tf0VjCmRdIBJK5DiuRTVYcYREabdXKXDNkN/IRjcG +grAMlkZPnevf516PF13/odFBDuzSzk7rEofZH7eNHpQOoP6MIXdYwHeuxGwMaOF8Kcq AM+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708431956; x=1709036756; 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=UlKagWgW/Suhx5XrwPdfnlsQ3+kK6LLiHW7W/dUMHaY=; b=AnRrHZ++/oiRzhlPn2QnRtTviCdDVIzMJ6PHxtlJsO31TImo8pjRa6BDsnrfAQ0agn vvd2uojM6woqisLY8DeIb+HeqCUIyW6ClvAbHlXX1c8592iT6vSog9G0GayuJQFA0Ih6 ePR39Sq2Z5Zj4nBiu5w71hod6EgRobNaTVP6/8tQC2h0xCTW68vjMGI6gepHIRbTsBH0 Ke3uC+3TGwQxiyHL+ha6kjHNVKiSvxg0mZLimQ6fmeCHFDV9r2ZMU9AvBZpbh3gPSP4w UZc1nAdlC4wrMC8r6Cz8fKNtuJdVWDwCx2CwIxnSQ/5dk20O2YU57w9WdvDnnJcFHpxT QHkQ== X-Gm-Message-State: AOJu0YwJnElsDVeAAJ2WXsrgJUFjFrwh/xe1sSzTT9HTFY+9BJDV3ifz cG9Dn368JXZbq6IzhaltlzICshbVZzfDszH+dZSSj0qc7nAZlWJizhQYTLIvjbw= X-Google-Smtp-Source: AGHT+IEeIAWtGETAzOIxdaBUCjr99X3nyHlqYq9vG/XsVMzqBDlxsY6oz8YL40IiB7FEiSBMx3pFfA== X-Received: by 2002:a17:902:da81:b0:1db:cb4c:1202 with SMTP id j1-20020a170902da8100b001dbcb4c1202mr11680911plx.8.1708431956035; Tue, 20 Feb 2024 04:25:56 -0800 (PST) From: Akihiko Odaki Date: Tue, 20 Feb 2024 21:24:50 +0900 Subject: [PATCH v6 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: <20240220-reuse-v6-15-2e42a28b0cf2@daynix.com> References: <20240220-reuse-v6-0-2e42a28b0cf2@daynix.com> In-Reply-To: <20240220-reuse-v6-0-2e42a28b0cf2@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 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: 1708431991734100001 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.1