From nobody Tue Nov 26 12:46:26 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=1706952819; cv=none; d=zohomail.com; s=zohoarc; b=b/NrPtHq1vZcud5il0MdiTSkDMYe5GrlCTEmcQI1PvK0IxFsVKp3ZYdq91C8kQILOnP1ng/TH1T3y7ifNzzPuMH3sTHoNkXvCuEEhQ/4IxCX6U4PJnx9ZZG1v71eyb7m/ehiUXWNjMX6wpRK1Ouqj0SRY89A8u4txXjiMuAFN4Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706952819; 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=/Zrx+cM9JnBC8UHWhVfp2cUkKCiTKN/0k3qIHo/fadQ=; b=VdRUFafLE4KdT4SVLVT0nxh8rFVPkUX7K80yYOV5+RMxXs0rpK5OAv3c0qAXZW5KmvyN2wdv+mH6X5gqgO4kcAOS8Y9XgFmWGuAU/VB26SlV9yPlG/EGGyLEVWPgeERQb4dMT7Fohf13zY/C2NrvDakXqHRpq1f0hCnMTOI2t88= 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 1706952819567243.3121269905372; Sat, 3 Feb 2024 01:33:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rWCNs-0003xx-1c; Sat, 03 Feb 2024 04:32:24 -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 1rWCNq-0003x5-Ll for qemu-devel@nongnu.org; Sat, 03 Feb 2024 04:32:22 -0500 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rWCNp-0005hh-5Q for qemu-devel@nongnu.org; Sat, 03 Feb 2024 04:32:22 -0500 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6ddc1fad6ddso2458640b3a.0 for ; Sat, 03 Feb 2024 01:32:20 -0800 (PST) Received: from localhost ([157.82.200.138]) by smtp.gmail.com with UTF8SMTPSA id f4-20020a056a000b0400b006e02cdad499sm617591pfu.99.2024.02.03.01.32.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 03 Feb 2024 01:32:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1706952740; x=1707557540; 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=/Zrx+cM9JnBC8UHWhVfp2cUkKCiTKN/0k3qIHo/fadQ=; b=AUGMcw+5SSTo5cexcieeYKFPvJ9bOp0N7hXyEAqDXZlEWvDVGB75/vtqaph2SOODfk P/ncS0EOYBemnUJpqBnLGRBn1wmCR2p6Us2kKwlJXDri3RGy1aG17LNOJ9c4FO82EaAo RnFWUr6raeLNPpj++zdoGz3XafH1HmP8r4k50oKVG17kzUlw+PdD0xGIdXt8LgXeNYae cd7Ar32Zw7w/g1+u2lneagPOegNQQ1Lw5TqmSzEqMNjv/1t+LH7lZ23pplunzjkvCYEu KzAd0dTZUwEhu/Y81oILSaimLQXXAwUALEe5+jmT4+hfgLU7zdh2itzD9PODjXn8q9Kn 4cTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706952740; x=1707557540; 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=/Zrx+cM9JnBC8UHWhVfp2cUkKCiTKN/0k3qIHo/fadQ=; b=HLAsy2/wpgIzDQCMzzxUhArvVFsOljyicLc0Ym+szyJgcaSOHhf3Aks9J23+9xAzwJ UTMVVmz7T1vANGK2I9mUoSF93K5ASYiaZG3EuTNuf61HSHVD9D1xyLGoD61kXMPYgn2j YI7KWbpl2BVMzBskMT6i9YX87ZCCooKIDmXdiCblznfyeuJduInhVKiP3wp86LeM1or3 dOvB/p04NQXCvwuy3AsfQd1l5mI3RpEhgjCtNSwy8R6Sw0ZyQzVOqHQ1R03Qh7KuTXQT iyJ70ji6gPYa0VK+xRBKAfzsY/WHcDAHtDLD5CeaGL5vvoJIw7LQAU12wKRpOeCF6jn4 lV9w== X-Gm-Message-State: AOJu0YwBwrU6nrzfyUQckuZD1rEJ0qaWLzFxuBRGyNEJ7ueXr+EuPXrD jUoFXvjEOgUdOa4wsr96bfwX6VUwOeLaKC5XK9k5DzFxXiRZ4rzCzwQQF1eWChE= X-Google-Smtp-Source: AGHT+IH62ZGdKCr8i/rqEc1456iWcjLZR00cRyHq9nd/iB1ejHZHJYpFJx/9uSG8CzOnidIvFWgORw== X-Received: by 2002:a05:6a00:1823:b0:6e0:25a0:f6c with SMTP id y35-20020a056a00182300b006e025a00f6cmr2576754pfa.33.1706952739949; Sat, 03 Feb 2024 01:32:19 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUrVPY9EJDWqCXDSpLPjk21XnUY/HrjgfRuB6Lnb8xGx28/lvjKCL9G/08OYMhf13GNXWd4oFDCvvve2opLEJ9D963zx6nxTtTnDJQMK085KzyKoA55++YOvJs44cNER60jPKJDpSogev0WJd3jMFE8yxYQTmADzqMknKfFnHwHPn68oLkHmdUms4bP/wk2LxRgSaUPImDwchygibcnQrGupurJbhqdrYRpuKvrtdxsjuG7ZpHU3wHSk4Kiqza5pDoRNuanGm3geCzBO2zZ7m1RCyP5P+eLd+7vjbeKt1kj0RgzRTCJEYdvuqJhG7f/Us0BqVNygIa9kti6CzzGMl8FFttOcLYByHvTmsO94Al5z8XK0AGCGGI/nCJvkw8URoORqVVvmzBDq8Ltip5UEl9uh97jA4vg3LsC6fcqYg== From: Akihiko Odaki Date: Sat, 03 Feb 2024 18:31:55 +0900 Subject: [PATCH 1/6] 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: <20240203-reuse-v1-1-5be8c5ce6338@daynix.com> References: <20240203-reuse-v1-0-5be8c5ce6338@daynix.com> In-Reply-To: <20240203-reuse-v1-0-5be8c5ce6338@daynix.com> To: "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::42a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+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: 1706952821410100001 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. PCIDevice::rom_bar is changed to have -1 by the default to tell rombar is explicitly enabled. It is consistent with other properties like addr and romsize. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci_device.h | 5 +++++ hw/pci/pci.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index d3dd0f64b273..54fa0676abf1 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; +} + uint16_t pci_requester_id(PCIDevice *dev); =20 /* DMA access functions */ diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 76080af580d7..d08548d8ffe9 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.0 From nobody Tue Nov 26 12:46:26 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=1706952823; cv=none; d=zohomail.com; s=zohoarc; b=agunheCOfxKDvUFzhJ2aOS4osLDf08PEIqGnWBFDdm38dSBkVUxiCnfPEfp/WbSJvknso16gnxRmQ47WryyLP5ZjgA266triY/tcaNjkNbBejxO7hRA7anGD6U8CGExNMISynnJpb/FtjLMLHL1rMkV0k341LmIkKJH72UoGVfc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706952823; 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=KshG4XdFN/TjxiO4+Kgrx0bCb7ZBpfjPIzIbQ6JKIZk=; b=XfEga8a5AdeM95FBdrrJnjEzgpXk96I3XV3IhQCud2r2kdl56kXlC3LsXgmuhf40ZpOKZ99ekXZxdVVf1rQnEaMgMzc9oc+XmkWt7tXeVB16fSGtg7aS/HXY2o9npj1Uh4Frj+nL9DUAPwQMpvbNoNNWjes2+djnDhpyszu2mxY= 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 1706952823003983.9729980151723; Sat, 3 Feb 2024 01:33:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rWCO0-0003zL-37; Sat, 03 Feb 2024 04:32:32 -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 1rWCNv-0003yU-5B for qemu-devel@nongnu.org; Sat, 03 Feb 2024 04:32:27 -0500 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rWCNt-0005iO-PY for qemu-devel@nongnu.org; Sat, 03 Feb 2024 04:32:26 -0500 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-5ce2aada130so2714443a12.1 for ; Sat, 03 Feb 2024 01:32:25 -0800 (PST) Received: from localhost ([157.82.200.138]) by smtp.gmail.com with UTF8SMTPSA id u26-20020aa7839a000000b006dfbecb5027sm3108142pfm.171.2024.02.03.01.32.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 03 Feb 2024 01:32:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1706952744; x=1707557544; 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=KshG4XdFN/TjxiO4+Kgrx0bCb7ZBpfjPIzIbQ6JKIZk=; b=ofcbErmUoYtRIb11ONDVUp/1BPx6uHT1QIkMQiQOJ8jL8VWgzK6HwfZrRK+4SPV802 A1yVmz4vdHm2PBtB1ug+Rfx6dEf2CCm/4Df7P+LVQYouPvjPrWU2fxzEUXCEck/+wJkC f9zaW0K601RIP4e2h+RNOY7fY5VPPdezvqqOnOkqccBIjaGQU0I6qrNXoYofOHFjh19l QSPVLwsfFUbiid0MW6TFQrKFHenjfljfIPMJYHsN/gyfbhQOnhL4Xsqd5gwHxYx7/p1B yVt1PDQ1/7k9mO7cH5/PzhFkjApLnCrcx0peyDL2Z3B8L50ThAqZHU6AcZmPMgVwLStM XC8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706952744; x=1707557544; 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=KshG4XdFN/TjxiO4+Kgrx0bCb7ZBpfjPIzIbQ6JKIZk=; b=Qskfgai2XX3dxcnqMgOqney6cm+p0uKvDpwXUmEfU5qxTq9EcM1qico5NZuBnoi55J LFw6gxzzhIhe78V7GcAItBOHR19fR7DaqFTsP1E///Basb9or7py7c0QGdlQFLmmuxte R6G6jRQVN+kJ69dKFRG5A3GMRtLpNf8/6FVe0TGQ26Sa8GyZppzySmEVqV7DsjAxeEYx rq9/Rb4vkAVKXz9OFz5/2YkTQgnflVpnLQeL1ab7JwrYCRGExIIChR6vWdLHbCEls9Hk jVTvXnpulT6POaof2MGA4BQi9OsaiZqY1LZIssCd3hZZ0BNTZ5BFUJrb3/YX+JAXS76d 4G1g== X-Gm-Message-State: AOJu0YxbSrvqwzy1aZ12/wty14+eXtXWp4pp/BSQKx5i3ECig1hAwqs8 WqZFQA1wF57chIQlq7vnXuiL3+FvVzaM1ZTGUus1KPqZhBdTplqpOHfS+cgg8Ox5b9KwcYgxmgU 7 X-Google-Smtp-Source: AGHT+IEQJf/kkDi0o0mkmhjmXwbxQNb/9Uno1/N+3iTDOGG9dqItVHvJZM4jmsGAvinGkGxxT6TjJw== X-Received: by 2002:a05:6a20:dd9d:b0:19e:5517:c317 with SMTP id kw29-20020a056a20dd9d00b0019e5517c317mr2098338pzb.24.1706952744563; Sat, 03 Feb 2024 01:32:24 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVut9Amib5yMWBuCJUHwjP9g8muCTXWx6WsPBGKsozNaLdI25IEcVTOlYfAU1E4UAJ6V+CycbKoWS27lAP2mqrR5CiiSti8IA64dMjnBhH1mqzBFiSPDpOlQkpj2kvnhVfXBGdq7oKGdRhtVFh49VgqLrY9+bEcQCalqJTN0EnbwBdXyWew1bC2Zet6UNmJNN7njt5fYh3Wl+dOj/jQryhUFdCGtdYm2o0V+xYN5R6pb1FO7sVwj/eUGA4xGW+66S9ZjhUUGkuFHJYD2c/beFuxxHEsn2cttfOqLiNZ0YgdpJqA1EUZ4dLP83GHVM5qSNkqElZT3rvubbnMUCDy5snztsEKMCtKf6NMwggueyI4KBUIlkmGvlLP3Fjc0m/7QrK4VsC8QOTDyJTTi8xABUTZWk9j+XrPUWABOPi5AA== From: Akihiko Odaki Date: Sat, 03 Feb 2024 18:31:56 +0900 Subject: [PATCH 2/6] 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: <20240203-reuse-v1-2-5be8c5ce6338@daynix.com> References: <20240203-reuse-v1-0-5be8c5ce6338@daynix.com> In-Reply-To: <20240203-reuse-v1-0-5be8c5ce6338@daynix.com> To: "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::52f; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x52f.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: 1706952823368100006 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 d7fe06715c4b..44178ac9355f 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1010,7 +1010,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 @@ -1044,7 +1043,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.0 From nobody Tue Nov 26 12:46:26 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=1706952826; cv=none; d=zohomail.com; s=zohoarc; b=ebVO8qHSRLfe4DrEHEMuXaRsBZJ0KtqPcZrcoyN3oitk0zxss9lJU/6lZQKD76ODuPmeGQhu3KF4dg9Rys1K7npXjOhF7aXJeLZw/ic6Ilv6phx+6TNmc6NaulyFc1wLC2WsO6HUQNT+zAlDrTaBRsluSSNxFBXdAK1bfGcwU+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706952826; 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=EtHvqx0pYo51UarG6u8auC68i9+0d57qDsSmnOr8C/4=; b=OquCbz/c1SGv7QzD8UXzeBY7szrw3u+l7ddlpVxPnT0SUInes+7ekC2hOvhvAMFltF8S6UoPW/VM+RwpLNgsf7hK+XiHVenDSBYV4Gm1PHkWjBqZO6UFidcYLCb2TasqIM7A2+OnqcdjE2Xzmw/GE0kBpA3WOGGJYm9ubxEFFbY= 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 1706952826943284.4156412923386; Sat, 3 Feb 2024 01:33:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rWCO4-000428-MV; Sat, 03 Feb 2024 04:32:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rWCO0-0003zP-8H for qemu-devel@nongnu.org; Sat, 03 Feb 2024 04:32:33 -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 1rWCNy-0005ip-Fb for qemu-devel@nongnu.org; Sat, 03 Feb 2024 04:32:31 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1d93b525959so25779955ad.0 for ; Sat, 03 Feb 2024 01:32:30 -0800 (PST) Received: from localhost ([157.82.200.138]) by smtp.gmail.com with UTF8SMTPSA id y5-20020a170902ed4500b001d8c8c903c0sm2902310plb.149.2024.02.03.01.32.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 03 Feb 2024 01:32:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1706952749; x=1707557549; 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=EtHvqx0pYo51UarG6u8auC68i9+0d57qDsSmnOr8C/4=; b=ixuvQ4Y65maedC0EkbzAi3gleq4OVpAvwflRNALOBw9qpSR/A4w8/Kw1BmuTSBevq+ pTbmFjfDLmPGF3rhl3JnM8tfK49VqD2V4PFEMI7Em6qHTkXs3Wq8iAEAZqR0ziRekgP0 P9BfNNPB5emknnX5XvDF4XYYIcWlD8YLoeOjK7sxIJcT+8eiWPBuAqqPEHcmLIwheYWX xAn0A4CQ7zLRi2m57+HvNhCfKTkEHNvx+YlPGBRzD4AbHouKLkGmxcBZlxHT7Kw9Ibwz JDKzNolgqVxfKZenh41ZdFqkKQAfkqMR7/B9MJpXardPnLLHY7gqBVe1KvdSUGPQ6uxp KDZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706952749; x=1707557549; 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=EtHvqx0pYo51UarG6u8auC68i9+0d57qDsSmnOr8C/4=; b=bzInMLPS7XL1pqU8oNEy6H2OeEKCfsnGzkNEGeApmcgEI0Z+clfk6HrORVwxIb6dx2 5Kv7SDvDTG8/P9Oz2k7NZmenMngX93H+3AkW+v7TO3kawOf5flBKpY5x+h36ACEbVwd+ yNVwqyl5OyaM8mixfu6Vb976uOvQfKfB7O503KSuTlkdFhtTH4OG9lL8gwDinrhy6J2M tHkkQYTd9LEyNFbarkrpCczB4UZBOVRczFngHNzz/t5Wwubn/MqRvL417rozdzEU4KFG +p3c7DhOlnbjDHMlnKNK6dAIbbHO95hCyIgs3JunVOjSBaxLuRPptJXGn9lY/tdtrIW0 ChOA== X-Gm-Message-State: AOJu0Yzf4ZGRyrdpuz9lc44fRhLNriiMAPSgjrf4hpxoUaILas/4ieA7 K4yYQytfit4HSPYl++L+7UntU1vxCbEGn5iHDxazv7BOT8c2hCieplGJs/IQeVE= X-Google-Smtp-Source: AGHT+IEacleu1elGvodEq8Gbr/cuF0OM08zPap+G8GNbBnui0R4BJOIxJRoNTk4AjYJesJLbyCV2xg== X-Received: by 2002:a17:902:ecc6:b0:1d8:cfc9:a323 with SMTP id a6-20020a170902ecc600b001d8cfc9a323mr1482124plh.34.1706952749093; Sat, 03 Feb 2024 01:32:29 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVQCum7n4aL15VbAV0BDsaBuBMRTfSTzJEBKrwxcnrYcKAg3I35Xech0cI9iBQirAmXxsJU/R05wf7pe6nfH6yMP6LHWhRjR4UHxO5nXxnJeImaZnPX8Y6sdCkJZ0ca+VsvjNJ3IstcIjvDKApTQzKe6WSafGHQfoed5grbftyJI3uDBvnaG5/HgvALNNWTHA2fiEGHMGMzUsWMWw8lnGfElrelP4wkw6qPAsJqXu79OmH5pk7xgaGyM1zt835i4SqpFk1qheoXoFhWdv8Qr+8nUBtMC+U8MAOs4SK/dyEVqxcScENygdt6wT1X+9eQudwX4Rg1Wgv2dHIk5ZesL9ve8HRX3gPpP6jrlVxA1HFEDt3JIt7y7gcDmqmnlSoeIGMmXWDAztGgK77NAwU9dVQiLlQv14Lg0EeB+v4vPw== From: Akihiko Odaki Date: Sat, 03 Feb 2024 18:31:57 +0900 Subject: [PATCH 3/6] hw/qdev: Remove opts member MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240203-reuse-v1-3-5be8c5ce6338@daynix.com> References: <20240203-reuse-v1-0-5be8c5ce6338@daynix.com> In-Reply-To: <20240203-reuse-v1-0-5be8c5ce6338@daynix.com> To: "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: 1706952827407100002 It is no longer used. Signed-off-by: Akihiko Odaki --- 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 151d9682380d..6befbca31117 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 43d863b0c5b0..c98691a90d48 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.0 From nobody Tue Nov 26 12:46:26 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=1706952810; cv=none; d=zohomail.com; s=zohoarc; b=BCFbTuaAIF2lKs7bt73VYOJ0lqP7oFmao+HHfnaPupS+yzD0rSy3/fR3BIXsGI/OFJ4FQacyFJF/ROlnV1fCb21AlsadkNZkVhiTgIALWy4smrDtVssNgXl8Xi++CD4KdIMc5icCCiKMyzTMKaO675IoaHIAoktonP5A9PXmf4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706952810; 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=sVsDDgcIpEBlmcq1EWawWovzpkmUUsK5fa5lmtMzwhw=; b=Gv9sukFF4aM6sAUNUvLpbuuSQjb7CMEzzwcUQzvYPRISCLaYLwnD/So9IUfU1+yLpO1Q/Ni4Ba1uP8J5VN8IoKooK46OTGH0l1cbDWyAHoQzl+1stGAP5MoRrqkDojzXxW2+UtMQBQEosmmrPk2NRASdmr0pkMVNQET/vg9VN2o= 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 1706952810580261.007011248353; Sat, 3 Feb 2024 01:33:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rWCO7-000434-HY; Sat, 03 Feb 2024 04:32:39 -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 1rWCO4-00042C-SW for qemu-devel@nongnu.org; Sat, 03 Feb 2024 04:32:36 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rWCO2-0005jS-Sr for qemu-devel@nongnu.org; Sat, 03 Feb 2024 04:32:36 -0500 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1d7881b1843so25181315ad.3 for ; Sat, 03 Feb 2024 01:32:34 -0800 (PST) Received: from localhost ([157.82.200.138]) by smtp.gmail.com with UTF8SMTPSA id ju3-20020a170903428300b001d91b6175afsm2942612plb.18.2024.02.03.01.32.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 03 Feb 2024 01:32:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1706952753; x=1707557553; 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=sVsDDgcIpEBlmcq1EWawWovzpkmUUsK5fa5lmtMzwhw=; b=VD+uFFDYNXi9z2nmw/tuvv6npDUM+6WIXlSQEfikUB1evrhrI2RvYaR99IagIaEtBC xMROuo/IXBROZNl6mMp9nb/xq2lfBsQ3qxerOt9aX6/DD4KlGoNWQhWkSiyyykuXNQao f2BhA2zQeoBgd5D9ESsPU3hgfMqLSBpET0uoH8O1vpLqEoD0quza6LxLzcSZeNG8Xpvc Wwe5Sm8/9VVQDuTs+ppxMyi5Yf7RflCBZ8s74DWQHjvWP9aieYuJd99u1Rj8ul419kmn vlPStUig84FjdsFYjdEkggD04e9xrWtclmMmlKL/MO49kW14hyY63RSEnC/UlaI/JVAT TpPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706952753; x=1707557553; 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=sVsDDgcIpEBlmcq1EWawWovzpkmUUsK5fa5lmtMzwhw=; b=oqY9KxEvuSZI4fk/qy83mreMgag2XHtqXZkuXymlAECxg6P81B2YVc4BI24T0BbaR5 GLv/JIrOynLkC4YHp5GUV8mFnbREUwYs6FyGry+BqSeSuICz7ShjEbUHUQDdBeLfw1XT BgmzO6ziuoI7DITPMiAT+SX1hyGjXQVeTMVoX9IqcqB45Hmnlv2NbYqg4WiN+9QPehCH N5V/OoWhk/IExSDNO5Yvw4cXVLY/729bCPyXGVyCd8mDUjF8fy1Ahn3Xs/WTN1obZnnv UNmqjbNsvtHNcuwUteulUdFGYa59GEqBEyGBFFs0qQwwWdIRETsZ3jXw9m3C3Jor/Ee0 Y/Jw== X-Gm-Message-State: AOJu0YypVyh6n71re0++CIVgEFD+AdjEMXqFTtO+H3gxZ8G87cR2YbKf HAZ0kab35mzZVG5LZgnnPhY5q93IhX6weifYJNkJ9yJY53MUKnYZ25qQgPiv92o= X-Google-Smtp-Source: AGHT+IGPl9Z0OOt/hQqn596JPYaEEXEA7VV5j9GioSiECfI7AwWnM7L6AwPIJ8/q2flNtdojmSzxdg== X-Received: by 2002:a17:903:987:b0:1d9:4282:4be8 with SMTP id mb7-20020a170903098700b001d942824be8mr5724116plb.25.1706952753543; Sat, 03 Feb 2024 01:32:33 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXSpNiJntVrtkq+zRDdsb2A3POy0ilLtfSN8t4jSKTt07fsbCNkiyDB6RQcYxy7K5Z20eZyPR+W/usV0MaYRK+FaW1nGZb5xL/PrnCl3+ZKE4uEmjUF+s4PXT8bgB/vM3gBu8YZlSKcBCjev8SJHy9VvGiDa/lPkloEAaKNSdPX1/9zgetBCsqS0cYUSM+HRydNB73XUuuzkJK4lhAcaOVIAw/rRt0kCoP1LXjCeW0tsWbDylgNJeZqaCXLeXgGLfVrHDDW+15fPd1jIyn9lCLp0fgUfLxpEO18aaV1t1XCx8iGrErDVTvhzfsYDUluKdDChEOdgjM2mztIeKZ50e8MBgVt5kA1I9p3OSUEUk2TErrRA9zX9oScZR/PI77Mjlsa9o/rXhf690eBL77eD9hxUIvR/ZpHOgp/eQg/uQ== From: Akihiko Odaki Date: Sat, 03 Feb 2024 18:31:58 +0900 Subject: [PATCH 4/6] pcie_sriov: Validate NumVFs MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240203-reuse-v1-4-5be8c5ce6338@daynix.com> References: <20240203-reuse-v1-0-5be8c5ce6338@daynix.com> In-Reply-To: <20240203-reuse-v1-0-5be8c5ce6338@daynix.com> To: "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::62e; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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: 1706952811895100004 The guest may write NumVFs greater than TotalVFs and that can lead to buffer overflow in VF implementations. 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.0 From nobody Tue Nov 26 12:46:26 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=1706952810; cv=none; d=zohomail.com; s=zohoarc; b=f2TQ+HR3EesP+HSi9zuknumY/8EpsVME89oavK+yxxckGAwnsID8crF0FaNZO06UHtv0Rzm9cTy5p2iY9Zzn0FJEHl+V5iTB8cr+WXUGosN3o+Vlkncq9xNF1DlPqZARS8eTzY23YiwSIPIqo6QzrPCoIShxtfIoNCuyr1BIH1U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706952810; 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=O5s4CI8u6yFAzv8Zzh+M5M/SLXPij4iKAgyQPOnnT+w=; b=iTVa4IwHXLQVEguIef39jM6peUwzwNocRY6fT0DN58dRhKEBgnq5iVL+t5WFqf4QgCsNoN3JnmCdySHoezgpRSCoi5NPBDPl611bopsRc2c7hXoV2fUB2hu+CzHn0OPCw8b919LGI143UvOub0gZ+dCsSNvKbFRGtEQ8A0GMyGs= 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 1706952810599206.80921366165194; Sat, 3 Feb 2024 01:33:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rWCOF-00044C-3z; Sat, 03 Feb 2024 04:32: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 1rWCOD-00043r-EG for qemu-devel@nongnu.org; Sat, 03 Feb 2024 04:32:45 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rWCO7-0005k0-Ap for qemu-devel@nongnu.org; Sat, 03 Feb 2024 04:32:43 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1d93b525959so25780495ad.0 for ; Sat, 03 Feb 2024 01:32:39 -0800 (PST) Received: from localhost ([157.82.200.138]) by smtp.gmail.com with UTF8SMTPSA id kn12-20020a170903078c00b001d9602f3dbesm2918305plb.24.2024.02.03.01.32.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 03 Feb 2024 01:32:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1706952758; x=1707557558; 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=O5s4CI8u6yFAzv8Zzh+M5M/SLXPij4iKAgyQPOnnT+w=; b=jydO+nS7xtrdAsVtTMRIE3jeEpfZcDyURuwlE8qtGFjmPnSp/QZIezR2xA6m7rSrn5 wN7pzdFxauc06axKnAUgI8VgbTwpDpndDXKNlelp2UXFkl/B1gH6GbMTIFWGK5yGOrQl HCEye/LjvqXiXZtGbCOG/KY97Sm58CjwdORy6rkNJTWrBj+sDEuaxqPwFZMOpiajgGe8 Z7cRjt1dQD2WAbQd9iplvUv5fTehjVV/YxQze0G1tQkPBsaeebL9nIEyEoer3zp/SK0e dr1cDEL6hUvhiKS3/grkLkxSYfHU6nfcJ7PpXq2lpC1Ulmjovajzvd2kWcCf9MVLnDxP o6Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706952758; x=1707557558; 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=O5s4CI8u6yFAzv8Zzh+M5M/SLXPij4iKAgyQPOnnT+w=; b=a7Qs3CSVBNQtU3C0MsAAbsy8qvrfkjC2h9uXe5NO58apsxFk+NuhsehomZZjLVbYQE 76LvshJv43DfzSfonb6SYUvc4ngTnZgo7q0J7KVRHvhXWDDk3jh/c4PvxKDIIuMEwmbL 1FJvxZN6W+tt25Gcm8Q0tWxNWu3aBa1Zy0GKE6kddA7BUae1oJjBzK0zF6+KHarRVPI7 ieGX942TRDtBr/YUeRJsNlyY4kaamAdh1kBtDGdCd5aU+NB/ypoXaZiQLHwfzDjCIjaX iR6RxYW6IRbjtkERTr6UPoQR5+hi1PWb0XmzaQvYQhNJid1OEH+XEpldNykFCQxsqfRr xbiA== X-Gm-Message-State: AOJu0YxgDnBk7efqeTdcuam8d1NqZs/tsCykiMKkYkcSnptXjPNzzk9f 0Yhqr7bEp4b0qcwR4k11xuan3HvqxN9RTW/e469Tv9yXv49oBxvgJVrSqL89FP0= X-Google-Smtp-Source: AGHT+IEIZE1IQKWD8StlvSoaZ7sgd3HjgZtmulmizBNqZrhldMxjYA7rGoXwvMApvfT57VwNEM9KBw== X-Received: by 2002:a17:902:d489:b0:1d5:6d76:997a with SMTP id c9-20020a170902d48900b001d56d76997amr1236888plg.28.1706952758079; Sat, 03 Feb 2024 01:32:38 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVzBwOINhxi63hoa6yuv3V9+hvmUou0H68iF8/TFB+ynO7vZSwtk9CzOvNZP1yuNK52qIE2Nu40ferlXGWjqokuwbNosq+vl8TUidm+zjlMs6FpZ1p0FKIq/23RU8w3OY1/5/0/m1+vtnuDq8UAG3KDfz1ZuRLmmJqS5M6d2s7L/DoySjOPgRseKL+oK7hnKcr7q9oxx6uLV7/n6wNwv8iV6GlhTgDEqMxYUoJod4y1/gzrESR5J8YZdq/t7xbIfU8YM/KMyq9k/Kp4Yjp1/cmCsaHL20090nKP9k/MSnvA8z6+wbV3DDwfuG2/Ars/weu+SXYnyAplwA5ssZDP/MKFr9+1Lh81qVKy/Ao+IEr7/AB4npwZp62g7Irw1mDE36wW6MVHfJVgE/Y5WXpYKK0XRq8p+gm8G4RApllY7Q== From: Akihiko Odaki Date: Sat, 03 Feb 2024 18:31:59 +0900 Subject: [PATCH 5/6] 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: <20240203-reuse-v1-5-5be8c5ce6338@daynix.com> References: <20240203-reuse-v1-0-5be8c5ce6338@daynix.com> In-Reply-To: <20240203-reuse-v1-0-5be8c5ce6338@daynix.com> To: "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::630; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x630.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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: 1706952811908100007 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 | 2 +- include/hw/pci/pci_device.h | 2 +- include/hw/pci/pcie_sriov.h | 6 +-- hw/net/igb.c | 13 ++++-- hw/nvme/ctrl.c | 29 +++++++------ hw/pci/pci.c | 18 ++++---- hw/pci/pci_host.c | 4 +- hw/pci/pcie.c | 4 +- hw/pci/pcie_sriov.c | 100 ++++++++++++++++++++--------------------= ---- 10 files changed, 97 insertions(+), 89 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 fa6313aabc43..fae83b9b723c 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -643,6 +643,6 @@ 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); =20 #endif diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index 54fa0676abf1..f5aba8ae2675 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 is_enabled; =20 /* PCI config space */ uint8_t *config; diff --git a/include/hw/pci/pcie_sriov.h b/include/hw/pci/pcie_sriov.h index 095fb0c9edf9..d9a39daccac4 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 0b5c31a58bba..1079a33d4000 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 f026245d1e9e..a356a452ad47 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -8031,7 +8031,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; @@ -8040,12 +8041,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) @@ -8124,6 +8130,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) { @@ -8134,10 +8146,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 @@ -8159,7 +8167,6 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pc= i_dev) NvmeIdCtrl *id =3D &n->id_ctrl; uint8_t *pci_conf =3D pci_dev->config; uint64_t cap =3D ldq_le_p(&n->bar.cap); - NvmeSecCtrlEntry *sctrl =3D nvme_sctrl(n); uint32_t ctratt; =20 id->vid =3D cpu_to_le16(pci_get_word(pci_conf + PCI_VENDOR_ID)); @@ -8263,10 +8270,6 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *p= ci_dev) =20 stl_le_p(&n->bar.vs, NVME_SPEC_VER); n->bar.intmc =3D n->bar.intms =3D 0; - - if (pci_is_vf(pci_dev) && !sctrl->scs) { - stl_le_p(&n->bar.csts, NVME_CSTS_FAILED); - } } =20 static int nvme_init_subsys(NvmeCtrl *n, Error **errp) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index d08548d8ffe9..a72a2d47b840 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1522,7 +1522,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->is_enabled) { new_addr =3D PCI_BAR_UNMAPPED; } =20 @@ -1610,7 +1610,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->is_enabled); } =20 msi_write_config(d, addr, val_in, l); @@ -2179,7 +2179,9 @@ static void pci_qdev_realize(DeviceState *qdev, Error= **errp) return; } =20 - pci_set_power(pci_dev, true); + if (!pci_is_vf(pci_dev)) { + pci_set_enabled(pci_dev, true); + } =20 pci_dev->msi_trigger =3D pci_msi_trigger; } @@ -2835,18 +2837,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->is_enabled =3D=3D state) { return; } =20 - d->has_power =3D state; + d->is_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->is_enabled); + if (!d->is_enabled) { pci_device_reset(d); } } diff --git a/hw/pci/pci_host.c b/hw/pci/pci_host.c index dfe6fe618401..d7e13d72ce07 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->is_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->is_enabled || is_pci_dev_ejected(pci_dev)) { return ~0x0; } =20 diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 6db0cf69cd8a..f34c157e1fd3 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -394,7 +394,9 @@ static void pcie_set_power_device(PCIBus *bus, PCIDevic= e *dev, void *opaque) { bool *power =3D opaque; =20 - pci_set_power(dev, *power); + if (!pci_is_vf(dev)) { + pci_set_enabled(dev, *power); + } } =20 static void pcie_cap_update_power(PCIDevice *hotplug_dev) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index da209b7f47fd..9ba34cf8f8ed 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -20,15 +20,29 @@ #include "qapi/error.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 unrealize_vfs(PCIDevice *dev, uint16_t total_vfs) +{ + for (uint16_t i =3D 0; i < total_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)); + } + 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 @@ -36,7 +50,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); @@ -69,13 +82,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)) { + unrealize_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; + + unrealize_vfs(dev, pci_get_word(cfg + PCI_SRIOV_TOTAL_VF)); } =20 void pcie_sriov_pf_init_vf_bar(PCIDevice *dev, int region_num, @@ -141,38 +176,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); @@ -180,18 +188,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; } @@ -204,16 +204,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++) { - 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)); + 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; pci_set_word(dev->config + dev->exp.sriov_cap + PCI_SRIOV_NUM_VF, 0); } --=20 2.43.0 From nobody Tue Nov 26 12:46:26 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=1706952843; cv=none; d=zohomail.com; s=zohoarc; b=XP60WOf5qfC3pCnRg6oh4VAlM7BupNSCOTaWE28+139uKgbzpMjUJnFblcTcN+7V7QLKWLbapc/ZdmUJNq2qwyQELtQyebASLFVOD6FsZt9JUaDyjBI/JXp2ycSCmhy7r9yJfppXs1f/QZk2vOkYA0UusL/ILBJBrQeHGt9ib8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706952843; 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=HYSjFZHgQ2mbSqHRTj9z4C9g2BrbZ8iNuTfeoBp92uM=; b=LtBZ0K2frlS6/uJTmKuvd+kI1PiNaTb499OJ1xWcgl2Ou6GcdjIpbVwgg3hmXNMcILZS9oFdc1tEbHRpA20yfSOvtuolbR6qKQoEKHiYDBm3C9IzQxVxY2Mcl0bL4b9JhZBpMiMuWrVOB+8ZW62ztum9eoMMFy4hMGUY650x4jM= 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 1706952843180679.2421765181801; Sat, 3 Feb 2024 01:34:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rWCOI-00049d-3W; Sat, 03 Feb 2024 04:32: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 1rWCOG-00044X-CX for qemu-devel@nongnu.org; Sat, 03 Feb 2024 04:32:48 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rWCOD-0005kf-3U for qemu-devel@nongnu.org; Sat, 03 Feb 2024 04:32:47 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1d958e0d73dso12989335ad.1 for ; Sat, 03 Feb 2024 01:32:43 -0800 (PST) Received: from localhost ([157.82.200.138]) by smtp.gmail.com with UTF8SMTPSA id j21-20020a170902c3d500b001d7610fdb7csm2884316plj.226.2024.02.03.01.32.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 03 Feb 2024 01:32:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1706952762; x=1707557562; 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=HYSjFZHgQ2mbSqHRTj9z4C9g2BrbZ8iNuTfeoBp92uM=; b=jL7UHS+H8p7wM73OZ3Mgzf0kPMppZ6RTMmDHXoD8qUZcCO/H2o0/idGQ+IY88XynuS HsxkYuDASEsqM/k0kxI8gwAw+sthJikKrjZLCYiCgV0N6diDzQtRBFUu6SaoRjJGOHHw TLG9H+N2E+AaM3wEvwtcJfZA7/PCRoKl+2NfBD6UfeYoOei90cQtM+eaxzmCEF0J95rj 2Irkz3NxdB/HPJyRBGDfulzviNDcuP2Dk5BO3SUYJfgpg6rIqquusJWY1oRygjbt1tfG eTkeyeyDeD2DVAPBX5odTieDo27Tkvsl+iqbf7HZmacNCNjeYXmE7zbWfFCDqZETtoa8 9EPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706952762; x=1707557562; 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=HYSjFZHgQ2mbSqHRTj9z4C9g2BrbZ8iNuTfeoBp92uM=; b=LM0YiljW1+G7SmjJkcP40FEEIV5GukfAeFiW8V/x55e1ueQt1xsB7XBXE3GtnWy5pK cLwWgv0bXFh5DbzWmu5JiZWAbnp0Gsj+v2i3jl4VcctxXaPREPqIw4tiEsPLdjgrCMrG QWwsU2QeRGx6fWZfKZ0FzkkBB1IHfzUMgePEec8pSuOXSMo9297rXL8InSN6Ic4KDA7D Xq8H/HYRUvpy5BFwSxhwnlY3doE08f8JtRVfz7HfsPVJlfvd7KtsClRYi6j5INJhp+F9 HsaL8ejGJvoDWNybNAfWU64PpeXyxn6NNyOZx3ZRbJ6rCJKk/tup1OBVQ3gFujm8k8EU IzIw== X-Gm-Message-State: AOJu0Yzv0MUSZC1F1We22OIE0765aojDWA9bqdH3p1Cl+1zcN0ftgsCc jxLXAt21/zEvycFA+hh4bgINEYGUUIKyvy6xZQ6IEBMQ7p5cD3MzeY318y/WTJk= X-Google-Smtp-Source: AGHT+IFHh8OIlJipxLVkpu9RnisnYTIBXlOI+2/luFbNUWvGW5L70auwT/6pjFkoG36AVQReAb6PiA== X-Received: by 2002:a17:903:22c4:b0:1d7:1a90:65ba with SMTP id y4-20020a17090322c400b001d71a9065bamr1747296plg.25.1706952762559; Sat, 03 Feb 2024 01:32:42 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVU9y+cwhOt9lniJMAc70W8Eu4EquWpR0TdS4+87r7J6BDHTnGVaSdOoF59YhoO1u9xFvK6RzvhdprYPGFudwO6ergT8rLAH05snf9NbQxJBMqF2PKvVzYcnf5XEC+jkAkvlozYrGUfgeaLJ2o8YmRBXPiA0oDAHw6ZrxOCU4nT6KFyIJsQ4of6Q3YenOFfYw8zlx2gEgADJLB0p0Btr9UiKtWIJI1M1ktu1wSUQyMIDygAGJOdp+G5u8GEc0wqTWVl9hrw1SIrba0HroDBZdUMN5x4mGsRbITnYAeqo7GIDc+Ib55OiJyfzU/8nA5ivmmgx10gnI0vPVPpbaDwDmRxjPeV+Q1p32sTYLrib9k9aY2LJ5TG1HRdVBkzPRLXFg7bEKTiVZOs+q/Bvg2beTy6dI9gKw+pXccv5MQJ2w== From: Akihiko Odaki Date: Sat, 03 Feb 2024 18:32:00 +0900 Subject: [PATCH 6/6] 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: <20240203-reuse-v1-6-5be8c5ce6338@daynix.com> References: <20240203-reuse-v1-0-5be8c5ce6338@daynix.com> In-Reply-To: <20240203-reuse-v1-0-5be8c5ce6338@daynix.com> To: "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::630; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x630.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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: 1706952845411100003 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 9ba34cf8f8ed..9d668b8d6c17 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -91,6 +91,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); unrealize_vfs(dev, i); return false; } --=20 2.43.0