From nobody Sun Nov 24 14:44:45 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=1723531147; cv=none; d=zohomail.com; s=zohoarc; b=hR+kaMaW1MXghL92xQJMMC52OY6M+abXz2kfKjtXxk90qPNhjaIEdsu4aHrTqaVl8hq7syc3rpuBqbtkMzPGOeNUzjw58EVsDT9g93ZTNHNKuKH//YBs1HiCwtPl8z8mohujLn+LxQBMte7cHUn6Qus3+tyo78bWcATNnKEyds0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723531147; 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=XtLHnn9U6eyio3FDZY7yCUtQSaVZBT8Hqm8aVmtB1Sg=; b=ghLNjtbqmwUwgUkjpyz3zPQ2+QIiDH3rb2uM0O1nNm366gH3AWl6ktMH/vpLVqZC6a1xIazKgfeUjOI/wwf1bsGuIFGBN45hmpEDRMt1FqmotaUyKhSFh0KaMHkWIjdLOmPBeA5gPVcN1se8gp5ves4HluHXRwFmClR3rsLbzJQ= 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 17235311478411004.4789923547321; Mon, 12 Aug 2024 23:39:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sdlA7-00074M-Ah; Tue, 13 Aug 2024 02:37:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sdlA4-0006xs-Nt for qemu-devel@nongnu.org; Tue, 13 Aug 2024 02:37:41 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sdlA2-0006Th-Uu for qemu-devel@nongnu.org; Tue, 13 Aug 2024 02:37:40 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1fc5296e214so48823945ad.0 for ; Mon, 12 Aug 2024 23:37:38 -0700 (PDT) Received: from localhost ([157.82.202.230]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-201cd1b8dc6sm6609525ad.219.2024.08.12.23.37.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Aug 2024 23:37:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1723531057; x=1724135857; 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=XtLHnn9U6eyio3FDZY7yCUtQSaVZBT8Hqm8aVmtB1Sg=; b=rFhCVqYu5JlasfHk7p2Jl/PWLa9if8IoAdRJJOuCEA5cUUTa9gCFq6sX6pDHDg47Nx qVa/mfK4L0Q6ySCJxD1BrCZG+1LYsnEu2h5To+PcAcBcOfbDBvKJq9zJX8HkipWeffYT 4xFnXJwCda9tuZCEhXuvoacwr7beYc6Xwj1KzMqvzSzasUcg4ePOBKh+71eFRZmdd73K es20dqsONXx8aorJjg3mspOqhFw+qaz6iNBrD6/Gt1abkofsJ5tLTZ/dBdT922xADD8z D1euK/I3pzrdY6izmNGeBjqv9PnTlBU38x6nYbwNWrRXQjPBUdk8Vs4wOLU92pSABqbI 62qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723531057; x=1724135857; 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=XtLHnn9U6eyio3FDZY7yCUtQSaVZBT8Hqm8aVmtB1Sg=; b=hnrpnmr4DmTrl1RyS0NSL1/is4ebe/9El1D9cUjbin85497U3bTI/UcQnGJ95qmKOD bridYlhk32+2MenYYe66W+MS1QJGxomqE8Xoh/zFZGF7hJFGnPMs5pZedHwmJwgLzjUq Kg0lqyxHvtCChsLCes3MIojbsvDlqWxwpZ66NCqaVfJufOv8junvJYpY2x5dKZ/+HrIh q7Hsp+31685eGKpI0TnfIyMUlIr2KqwuH8Puov1KGdGgOv2cSxVEQPlTxOJd5dmi1ETc Sy5GAYdlYRIo6vQdSVCr7/skHzI3MUR+4kxExuVlWwqgsrwLq4xkGXunqVQzUa43TbBR qEKg== X-Gm-Message-State: AOJu0YwAwKR+ps9YvXjj7QZu1d4GovXJRGrbNudy7CRpRMRCq3aH6EL8 Gnq0K2EttL5O1gAiI37lcbWg0VlXp0GnK8cA1Ybp16lAGSexD6icG/z4C5g/EZ8= X-Google-Smtp-Source: AGHT+IH+oOu07OUmzoKngWVeUyLvLcA8nJ/81oRiB2mQhrarVd0nr9eorQDcaHEj+SJxOPax5VlbZQ== X-Received: by 2002:a17:902:d50f:b0:1fb:7435:c2c7 with SMTP id d9443c01a7336-201ca22924bmr27851605ad.57.1723531057606; Mon, 12 Aug 2024 23:37:37 -0700 (PDT) From: Akihiko Odaki Date: Tue, 13 Aug 2024 15:37:05 +0900 Subject: [PATCH for-9.2 v7 6/9] virtio-pci: Implement SR-IOV PF MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240813-sriov-v7-6-8515e3774df7@daynix.com> References: <20240813-sriov-v7-0-8515e3774df7@daynix.com> In-Reply-To: <20240813-sriov-v7-0-8515e3774df7@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 , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 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::634; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x634.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: 1723531148365116600 Allow user to attach SR-IOV VF to a virtio-pci PF. Signed-off-by: Akihiko Odaki --- include/hw/virtio/virtio-pci.h | 1 + hw/virtio/virtio-pci.c | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h index 9e67ba38c748..34539f2f6722 100644 --- a/include/hw/virtio/virtio-pci.h +++ b/include/hw/virtio/virtio-pci.h @@ -152,6 +152,7 @@ struct VirtIOPCIProxy { uint32_t modern_io_bar_idx; uint32_t modern_mem_bar_idx; int config_cap; + uint16_t last_pcie_cap_offset; uint32_t flags; bool disable_modern; bool ignore_backend_features; diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 9534730bba19..0c8fcc5627d5 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1955,6 +1955,7 @@ static void virtio_pci_device_plugged(DeviceState *d,= Error **errp) uint8_t *config; uint32_t size; VirtIODevice *vdev =3D virtio_bus_get_device(bus); + int16_t res; =20 /* * Virtio capabilities present without @@ -2100,6 +2101,14 @@ static void virtio_pci_device_plugged(DeviceState *d= , Error **errp) pci_register_bar(&proxy->pci_dev, proxy->legacy_io_bar_idx, PCI_BASE_ADDRESS_SPACE_IO, &proxy->bar); } + + res =3D pcie_sriov_pf_init_from_user_created_vfs(&proxy->pci_dev, + proxy->last_pcie_cap_of= fset, + errp); + if (res > 0) { + proxy->last_pcie_cap_offset +=3D res; + virtio_add_feature(&vdev->host_features, VIRTIO_F_SR_IOV); + } } =20 static void virtio_pci_device_unplugged(DeviceState *d) @@ -2187,7 +2196,7 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Er= ror **errp) =20 if (pcie_port && pci_is_express(pci_dev)) { int pos; - uint16_t last_pcie_cap_offset =3D PCI_CONFIG_SPACE_SIZE; + proxy->last_pcie_cap_offset =3D PCI_CONFIG_SPACE_SIZE; =20 pos =3D pcie_endpoint_cap_init(pci_dev, 0); assert(pos > 0); @@ -2207,9 +2216,9 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Er= ror **errp) pci_set_word(pci_dev->config + pos + PCI_PM_PMC, 0x3); =20 if (proxy->flags & VIRTIO_PCI_FLAG_AER) { - pcie_aer_init(pci_dev, PCI_ERR_VER, last_pcie_cap_offset, + pcie_aer_init(pci_dev, PCI_ERR_VER, proxy->last_pcie_cap_offse= t, PCI_ERR_SIZEOF, NULL); - last_pcie_cap_offset +=3D PCI_ERR_SIZEOF; + proxy->last_pcie_cap_offset +=3D PCI_ERR_SIZEOF; } =20 if (proxy->flags & VIRTIO_PCI_FLAG_INIT_DEVERR) { @@ -2234,9 +2243,9 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Er= ror **errp) } =20 if (proxy->flags & VIRTIO_PCI_FLAG_ATS) { - pcie_ats_init(pci_dev, last_pcie_cap_offset, + pcie_ats_init(pci_dev, proxy->last_pcie_cap_offset, proxy->flags & VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED); - last_pcie_cap_offset +=3D PCI_EXT_CAP_ATS_SIZEOF; + proxy->last_pcie_cap_offset +=3D PCI_EXT_CAP_ATS_SIZEOF; } =20 if (proxy->flags & VIRTIO_PCI_FLAG_INIT_FLR) { @@ -2263,6 +2272,7 @@ static void virtio_pci_exit(PCIDevice *pci_dev) bool pcie_port =3D pci_bus_is_express(pci_get_bus(pci_dev)) && !pci_bus_is_root(pci_get_bus(pci_dev)); =20 + pcie_sriov_pf_exit(&proxy->pci_dev); msix_uninit_exclusive_bar(pci_dev); if (proxy->flags & VIRTIO_PCI_FLAG_AER && pcie_port && pci_is_express(pci_dev)) { --=20 2.46.0