From patchwork Fri Feb 21 12:22:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985349 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 051B2C021B5 for ; Fri, 21 Feb 2025 12:24:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS3I-0004Pu-BU; Fri, 21 Feb 2025 07:22:44 -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 1tlS3C-0004PD-UL for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:22:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS3B-0006yt-89 for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:22:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140554; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=aOcHI/6ihrxObB+6D978/KQRlCQdnjX6vRn12oDIrAY=; b=PJlSV4gHVvRzP59pUiPVR8/8RSV+XZFFWyJGAIi1KZBFL6lxYF61H21aYhlzQLiaI64cTh t2C4tOUz3NPTB2EV0n21M81Sy/3xV/n55wRieEp2JHLb//xBDf6j57EayNH/TciQSmQTo8 tRLRA4/bnVM/0CdwgFAfwgOGuflhVHA= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-635-qhjWwqXeO020XroAKl4-PQ-1; Fri, 21 Feb 2025 07:22:32 -0500 X-MC-Unique: qhjWwqXeO020XroAKl4-PQ-1 X-Mimecast-MFC-AGG-ID: qhjWwqXeO020XroAKl4-PQ_1740140551 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-38f255d44acso931277f8f.0 for ; Fri, 21 Feb 2025 04:22:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140551; x=1740745351; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=aOcHI/6ihrxObB+6D978/KQRlCQdnjX6vRn12oDIrAY=; b=wz9YneiDeLFZ3wvxITB6F5nhAlTbrAqFYlomWTaVpDC2Jvh+Ourlaa7m/yYzVlFMzl Acu3xVOSpqZ+CHcItBabg5tUAcZL7RH8P5kzyUpoq/OteuZnkvlUyqxocJSKNl1GfsRE OUSkHZI1bFFixH5XNS1yRyG5S+JGRGF58VumzD1z7BjrgQp32WVGBz7BYmDWhSvMifRV j8R6Djrg8znTO7Q9dV2RE9/AmEhP1YvUgYrFbypZ0eNkXM3y0WC3+RttoltszCKyr+Ti cxe2C+NQj2I3CfhIeUbb4qV1JB4zLp26/0fTC3PY7Bzv3TnKL4TnGK6ItEZA8gESmXkc hJhg== X-Gm-Message-State: AOJu0YxU9DdHzOG6AjcFwTnF2haMbA1r42baVRFcBpugLsXrbKguHA5g BF+TQ7Lq/gYswzd8EOWichQ3dW5DPsX2of8umacYVb9G87gaxahmAdrVCcFud3HQOS4AWpZgXuO AFr2o1S4Ns/mGljOh2oDJpuh1hgBns6IX1j/DEjHcQHLCX6FtUCh0eKh5Ix1lIskUXYDSQdS/W5 9wvqA++Wm8IW2xsAqZo/uYUalCslEBfQ== X-Gm-Gg: ASbGnctcGx82wMQByzeeP1dZoM6jRwsZNZHdOQY0U8ShwVl4YnqcsWFLTFt/FCEYVPd oILpBXMWOTxFS8akVMs4+LouKkQwZqOvgo6mkUg3jFE4zzolegwzKP4j21gAY8oE+dooaAd9O1B /BVZDvRRSTRlGq2MvU1H0um1OgohPhJNj64N36akLm+88cktukdF+ZVzugMgOvRFUypU+PiZT0r 7sqzM9DI7bs8a4ptbU8M3WIu8kG09Vg5uGHHr7oKQQLTh28egR/rVBUhqTT/WJddl/pyZh1+IuN JFPSLA== X-Received: by 2002:a05:6000:4025:b0:38b:d7c3:3768 with SMTP id ffacd0b85a97d-38f6e946edbmr2026434f8f.12.1740140551153; Fri, 21 Feb 2025 04:22:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IErmAESHos3VULoU2lru6dRQ25ywZWT3YY+u+cL68nfcp0ji68vis2RnXs9dmxkipZJXCg5cQ== X-Received: by 2002:a05:6000:4025:b0:38b:d7c3:3768 with SMTP id ffacd0b85a97d-38f6e946edbmr2026414f8f.12.1740140550708; Fri, 21 Feb 2025 04:22:30 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b0371c67sm15582315e9.34.2025.02.21.04.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:22:30 -0800 (PST) Date: Fri, 21 Feb 2025 07:22:27 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Thomas Huth , Zhao Liu , devel@lists.libvirt.org Subject: [PULL 01/41] docs/about: Change notes on x86 machine type deprecation into a general one Message-ID: <6f9a1a01433738811c9795dcf29f299c60835558.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Thomas Huth We now have a general note about versioned machine types getting deprecated and removed at the beginning of the deprecated.rst file, so we should also have a general note about this in removed-features.rst (which will also apply to versioned non-x86 machine types) instead of listing individual old machine types in the document. Signed-off-by: Thomas Huth Message-Id: <20250116064644.65670-1-thuth@redhat.com> Reviewed-by: Zhao Liu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- docs/about/deprecated.rst | 7 ------- docs/about/removed-features.rst | 11 +++++------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 4a3c302962..7b42d6eecc 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -236,13 +236,6 @@ deprecated; use the new name ``dtb-randomness`` instead. The new name better reflects the way this property affects all random data within the device tree blob, not just the ``kaslr-seed`` node. -``pc-i440fx-2.4`` up to ``pc-i440fx-2.12`` (since 9.1) -'''''''''''''''''''''''''''''''''''''''''''''''''''''' - -These old machine types are quite neglected nowadays and thus might have -various pitfalls with regards to live migration. Use a newer machine type -instead. - PPC 405 ``ref405ep`` machine (since 9.1) '''''''''''''''''''''''''''''''''''''''' diff --git a/docs/about/removed-features.rst b/docs/about/removed-features.rst index c6616ce05e..156c0c253c 100644 --- a/docs/about/removed-features.rst +++ b/docs/about/removed-features.rst @@ -972,6 +972,11 @@ from Linux in 2021, and is not supported anymore by QEMU either. System emulator machines ------------------------ +Note: Versioned machine types that have been introduced in a QEMU version +that has initially been released more than 6 years before are considered +obsolete and will be removed without further notice in this document. +Please use newer machine types instead. + ``s390-virtio`` (removed in 2.6) '''''''''''''''''''''''''''''''' @@ -1006,12 +1011,6 @@ mips ``fulong2e`` machine alias (removed in 6.0) This machine has been renamed ``fuloong2e``. -``pc-0.10`` up to ``pc-i440fx-2.3`` (removed in 4.0 up to 9.0) -'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' - -These machine types were very old and likely could not be used for live -migration from old QEMU versions anymore. Use a newer machine type instead. - Raspberry Pi ``raspi2`` and ``raspi3`` machines (removed in 6.2) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' From patchwork Fri Feb 21 12:22:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985388 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8E2DDC021AA for ; Fri, 21 Feb 2025 12:32:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS3N-0004Qi-9k; Fri, 21 Feb 2025 07:22: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 1tlS3G-0004Pg-3W for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:22:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS3E-0006zB-8C for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:22:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140558; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hoj9zHkQc68Myno7gmXyzMQyAEjnKBSFykdtmN9gSKo=; b=bhZCsDbXKJ2ZjOLk7KJidBIN+KlLOACNA4mPd2x+jZFfD7oHNi85CcwDNkMApnFasSFhY7 HdnSTaRnMPjLb8Uf39zB2D9mH0SnM5ZBi3HFFi3KmbP1SlwxK1bSQevK/DGUJcMr9tdP7L abGqPdOn2nVjO0cn9SYsMNJKBJ6/jgI= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-658-Bl5B60hUMK-I2o09nWKg5Q-1; Fri, 21 Feb 2025 07:22:37 -0500 X-MC-Unique: Bl5B60hUMK-I2o09nWKg5Q-1 X-Mimecast-MFC-AGG-ID: Bl5B60hUMK-I2o09nWKg5Q_1740140556 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-38f628ff78eso1073025f8f.1 for ; Fri, 21 Feb 2025 04:22:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140555; x=1740745355; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hoj9zHkQc68Myno7gmXyzMQyAEjnKBSFykdtmN9gSKo=; b=BaTyJdA37j0aCMHpZMnFzhQU0saGadyXERRzIinWN4ZvHP735D4ekOgzXqKlO3/JwD xgxbW2c7o0QtkEI9+Wu7BYifM+TMj7tbCBCbYrKTATpiwBGGRgkZ5iChARnxUY8JGA05 YVdEpjXw2X9OQI3IiM+aUs3QywzOMyJwo7JCY8hbvHM1Is80oTtxVmVadK8MgDMhCli+ mkGkcRV6IJw2V5DpcW6sbkUkRFl5CNCMJz5ycCU8Yx170SwyaUwnJaP9bP4Vq8WT45HK CWtqFVg3ejSJFJuKtvfAEjEbNh6iR2HgS1DM0S0aiCwKxcNE/CZpQODB1pO3E8ABGNpZ XJgQ== X-Gm-Message-State: AOJu0Yz+NfjpGVxGQylLEQ+/p+Q15H5Re0yatMj1iO7D0/RdUjv7otxH OO7R0+3EmCzJj4cPjbr0rhbhNdwqToyRk98IOwNtl/SEQ25cJtoyRpor7IRtPV8KP5l8YRy2to9 EwId9tRqqiDXYVNAl6DSshoZmAS+BAs94570ZEhax3qJ20N2rH0DD0y/bD9mHj8VJH9fTlgeNbX VyilJ7LRRusnF3wGnaLyCImBcF8E5bBw== X-Gm-Gg: ASbGnctK86j5zQuaihmzrlkbeaoc+nbE3tDoN24/G83ZSLxfwq9LjXlGWAah+MVvhzz Pw1AWj8tacJDA8IKNWEpgRs5o/qo36bMAv5jIvFEeLyOjI3jd1mOF6cfDVZW6SsiaFDzI+pWrRO V9Ni07pIBYurb1PHnHX1Jj4j+kV/mhhjrP0km/87wxddK1ayiSXHiCZ3QNgpQ5Q9J1JK8VkBZan VRT+hMjzewtUDErm7EwcUKuduoXnN4a/tVKB21qo9V7a2W8FvgfjheXCXhRJ/AJzmZYZ8SV9Zsn xHk2Ew== X-Received: by 2002:a5d:5f94:0:b0:38f:2b52:f059 with SMTP id ffacd0b85a97d-38f61633567mr6317272f8f.27.1740140555456; Fri, 21 Feb 2025 04:22:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHC/lDqWS3/xYESMbj44WDsA1JtY2jXIJrcRr3bwF/vaBwluQWd2DmmHE+TCJQ3iIedZgijhA== X-Received: by 2002:a5d:5f94:0:b0:38f:2b52:f059 with SMTP id ffacd0b85a97d-38f61633567mr6317242f8f.27.1740140555036; Fri, 21 Feb 2025 04:22:35 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce65dsm15949635e9.1.2025.02.21.04.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:22:34 -0800 (PST) Date: Fri, 21 Feb 2025 07:22:31 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Jason Wang Subject: [PULL 02/41] hw/net: Fix NULL dereference with software RSS Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Akihiko Odaki When an eBPF program cannot be attached, virtio_net_load_ebpf() returns false, and virtio_net_device_realize() enters the code path to handle errors because of this, but it causes NULL dereference because no error is generated. Change virtio_net_load_ebpf() to return false only when a fatal error occurred. Fixes: b5900dff14e5 ("hw/net: report errors from failing to use eBPF RSS FDs") Signed-off-by: Akihiko Odaki Message-Id: <20250116-software-v1-1-9e5161b534d8@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/net/virtio-net.c | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 85e14b788c..d64941bf8e 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1352,18 +1352,25 @@ exit: static bool virtio_net_load_ebpf(VirtIONet *n, Error **errp) { - bool ret = false; - - if (virtio_net_attach_ebpf_to_backend(n->nic, -1)) { - trace_virtio_net_rss_load(n, n->nr_ebpf_rss_fds, n->ebpf_rss_fds); - if (n->ebpf_rss_fds) { - ret = virtio_net_load_ebpf_fds(n, errp); - } else { - ret = ebpf_rss_load(&n->ebpf_rss, errp); - } + if (!virtio_net_attach_ebpf_to_backend(n->nic, -1)) { + return true; } - return ret; + trace_virtio_net_rss_load(n, n->nr_ebpf_rss_fds, n->ebpf_rss_fds); + + /* + * If user explicitly gave QEMU RSS FDs to use, then + * failing to use them must be considered a fatal + * error. If no RSS FDs were provided, QEMU is trying + * eBPF on a "best effort" basis only, so report a + * warning and allow fallback to software RSS. + */ + if (n->ebpf_rss_fds) { + return virtio_net_load_ebpf_fds(n, errp); + } + + ebpf_rss_load(&n->ebpf_rss, &error_warn); + return true; } static void virtio_net_unload_ebpf(VirtIONet *n) @@ -3913,23 +3920,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) net_rx_pkt_init(&n->rx_pkt); if (virtio_has_feature(n->host_features, VIRTIO_NET_F_RSS)) { - Error *err = NULL; - if (!virtio_net_load_ebpf(n, &err)) { - /* - * If user explicitly gave QEMU RSS FDs to use, then - * failing to use them must be considered a fatal - * error. If no RSS FDs were provided, QEMU is trying - * eBPF on a "best effort" basis only, so report a - * warning and allow fallback to software RSS. - */ - if (n->ebpf_rss_fds) { - error_propagate(errp, err); - } else { - warn_report("unable to load eBPF RSS: %s", - error_get_pretty(err)); - error_free(err); - } - } + virtio_net_load_ebpf(n, errp); } } From patchwork Fri Feb 21 12:22:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985346 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6E7F4C021AA for ; Fri, 21 Feb 2025 12:23:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS3Q-0004Xz-Ub; Fri, 21 Feb 2025 07:22: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 1tlS3I-0004Pw-E3 for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:22:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS3G-0006zZ-F2 for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:22:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140561; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=2kxcyww6qI/yOi6ipYazJfpY4N/lEp2Wmj/5+d4jfT0=; b=VXCxPDY2rD84uDwG9z9r3fkdxNgiMORBaF4KysjDScv2GLsUgs1sHZQz9vtE3H8o1nQzKK FHW3W/EeSGTkT8TbhQVjUGSDkUNqmjyDM9+5S1+/GS3HQnoa7HebYYxbQidaKjGhgGAcZi ZcrXOROHUsUbwY9e/RBmxz+tAhGIR5w= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-444-P_j2QwBLNd2MmVZXMN59Rw-1; Fri, 21 Feb 2025 07:22:40 -0500 X-MC-Unique: P_j2QwBLNd2MmVZXMN59Rw-1 X-Mimecast-MFC-AGG-ID: P_j2QwBLNd2MmVZXMN59Rw_1740140559 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4399a5afcb3so18577605e9.3 for ; Fri, 21 Feb 2025 04:22:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140559; x=1740745359; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2kxcyww6qI/yOi6ipYazJfpY4N/lEp2Wmj/5+d4jfT0=; b=rQZ+wA3ZFoklUTF6g51Lff3+j2ixtePsWVH9Pe1Q3wj0+BovV848DRA6Z8CFyB616+ g9Zm17gDaFic/5k7vURgRu9Ns3c0Mv32ywCUT39YKy+8s+eBhaO0vOxc/Qnm5lVHlSLY Z4HXTATgnuwrYGiOxfCRzFh8Ff4gqt1SexwwY9ou/USkx8pVNfUiwC8FHOsGxp3NpT1A X5JZ753vvgSCk8jtUev2uNATWynnJooyrozG3gkzpJLyLWWWo+5ucN6dfE5E15WL+foQ 3nXtzhFheW22tCwXZkQwDV6v/IgNMGmDZjC1Pnzspe6iCqZMqkBBXL5DOWmMXyx3rOxx 9oww== X-Gm-Message-State: AOJu0YyDwKr9dUX65lyLKkxc9yKa7IZx8Tg56MBJfL34AvV21QLwIN4U D79/8p6CjepG26bAmHD9bsS2qBZQHuSmrVp6JhSxTBKv8biw8jcTm1NkaBLSm+nWOmGg012IXzj GATKVFOhFnz7h11QFfgaa6QzH9MJfhNWmCRwFG12/pehpoepaet1V0NTFQIooHRZhNZvG/0GegF aBhiGBJA6deA76CBgZX41B933oNlx0xw== X-Gm-Gg: ASbGnct2EWq7cg14ywmXv3V14UF8kG7aF8q1DdiopO0yVDU0bf1Nfuls33Ig4TL47A7 GNgZp9rtznqgS8WaXBXt1CFkhy+3I5bw7p+mKj2e2UR/BHcvWbI9/mcI7Qw7XPvLQdr13HOtF8f LehEhPv2d4kl6m+BoKIj1dkAxOgR8nJNOL4DEyDRm/h+lTJtkh5C2aU90H8T6J//6Z6F0TYsp87 +B96R4J/zgusqFf2FpUliFCcZHck0HgtDFuo763KsopavZwHw9Jzj4S1/ULdp11M+yd7U8W3sQr hB6bOA== X-Received: by 2002:a05:600c:3107:b0:439:98ca:e39b with SMTP id 5b1f17b1804b1-439ae21e4bbmr26685075e9.29.1740140558725; Fri, 21 Feb 2025 04:22:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IEN4YcJ9vKJa+eo1RGTH1NKKhEOeELWzpnWtdqCEJZ5+b9iJ2ykD60ZMRSsOBSq1sy22GS2Zg== X-Received: by 2002:a05:600c:3107:b0:439:98ca:e39b with SMTP id 5b1f17b1804b1-439ae21e4bbmr26684715e9.29.1740140558292; Fri, 21 Feb 2025 04:22:38 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b0371db0sm15456915e9.37.2025.02.21.04.22.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:22:37 -0800 (PST) Date: Fri, 21 Feb 2025 07:22:35 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Shivaprasad G Bhat , Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , qemu-ppc@nongnu.org Subject: [PULL 03/41] hw/ppc/spapr_pci: Do not create DT for disabled PCI device Message-ID: <5731b005246297ab5b91975f52fcd525e08507cd.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Akihiko Odaki Disabled means it is a disabled SR-IOV VF and hidden from the guest. Do not create DT when starting the system and also keep the disabled PCI device not linked to DRC, which generates DT in case of hotplug. Signed-off-by: Akihiko Odaki Reviewed-by: Shivaprasad G Bhat Tested-by: Shivaprasad G Bhat Message-Id: <20250116-reuse-v20-1-7cb370606368@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/ppc/spapr_pci.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 904227d9aa..b94e4ba131 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1283,8 +1283,7 @@ static void spapr_dt_pci_device_cb(PCIBus *bus, PCIDevice *pdev, PciWalkFdt *p = opaque; int err; - if (p->err) { - /* Something's already broken, don't keep going */ + if (p->err || !pdev->enabled) { return; } @@ -1572,6 +1571,14 @@ static void spapr_pci_plug(HotplugHandler *plug_handler, SpaprDrc *drc = drc_from_dev(phb, pdev); uint32_t slotnr = PCI_SLOT(pdev->devfn); + /* + * If DR or the PCI device is disabled we don't need to do anything + * in the case of hotplug or coldplug callbacks. + */ + if (!pdev->enabled) { + return; + } + g_assert(drc); if (IS_PCI_BRIDGE(plugged_dev)) { @@ -1647,6 +1654,11 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler, SpaprDrc *drc = drc_from_dev(phb, pdev); g_assert(drc); + + if (!drc->dev) { + return; + } + g_assert(drc->dev == plugged_dev); if (!spapr_drc_unplug_requested(drc)) { From patchwork Fri Feb 21 12:22:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985359 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9F10EC021B3 for ; Fri, 21 Feb 2025 12:26:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS3O-0004Un-L2; Fri, 21 Feb 2025 07:22: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 1tlS3M-0004QQ-Hw for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:22:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS3K-0006zw-BN for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:22:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140564; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0bNjdF5JuUjHCo2SOdNSUp94YzkHH1wWG4NRbjF7uhw=; b=H9LMrr/JY4vNmuJB4PfzmbDNwIOsm18uRiduTagVAH0bb0YYroPRsTGAkHLnAXcIJ63TT8 C5IQrt++0vs49JyixOktfPK8E+/rgMU4u8nFKa7qOFI41xoHy/XkHILWbTJ1kWWubWprEc ubp+8pkRCU2Olou3vYm6F6fonTah5S4= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-637-kc2rI-o0M7WvCS0-w1JoyA-1; Fri, 21 Feb 2025 07:22:43 -0500 X-MC-Unique: kc2rI-o0M7WvCS0-w1JoyA-1 X-Mimecast-MFC-AGG-ID: kc2rI-o0M7WvCS0-w1JoyA_1740140562 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-38f628ff78eso1073118f8f.1 for ; Fri, 21 Feb 2025 04:22:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140562; x=1740745362; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=0bNjdF5JuUjHCo2SOdNSUp94YzkHH1wWG4NRbjF7uhw=; b=AK2Tkx+MFT9xZolQbj5PkRBRUUouwIHTadAYaDGqB7PImHlOrWH52URVlR//MNuZ+2 LKay9mr6qbLx+W6u+WoSxgGudKXam5h4uRE648kPiUn9b0oqqXW5AVJ30y5F39prqbb2 +ECzCHSq7lN2zsBbSL0PbXMFLiSa/SVuNqs8TmwzmL8O2VnilZT0VtcsONDwEnJoJGHD 8AAVYQFDL96JN0xyCBSGMQKyM4DGqN7inR1SqvZr/jHfK4dQpX1wnNM1lsFSL65rECLp /a+LDtcMDBmRH/5Noe6HqV2+lnUeg3o5aqoKQRCGOt+I/DFn0U7Iy2Tttf/OYOKrr025 i5Xg== X-Gm-Message-State: AOJu0YzFBLu7pIfeZVGZA1mhCR54sy0UuWNdDL3EwLR7XxeunIZnuAh7 k4jNeUe/nr86MNMfMlHeliDV8cya3FrIHhhHUrl7KGnG+ggcmyUcFFD++ys5L19aRzrjPyi1Dxm 5OgfaETmvg+ER5e09Vdb+zXuqpRsObg4nPxmfzfpyTFrg9S9NQ+U7Y7V2+KAP+HRZhctF1LIGkm 34/KkILJBhGbXCROSgU98Ow17oQQNkIg== X-Gm-Gg: ASbGncvKxDzG2kCctOJQPbSg6FmVKJbqgdTyOxSNWJgEMWCKwMebG6pevyJ3oPGI9sK Vs3ebyxNQYfzRQlHRx6XCa7Y/hzb6/zNp/WrQ+kuvnHrgdRRBDk+CBIx6aM7wHwx9WOTzPaTjjo /q0QCs5Y/nCI9lfTkk19FXnvLdQYJfu4j+ViZygVuIbpsYS4XX0OG5zVdkxyCfMreCy4sMvshgJ TEMGn8ZCuVuK67PE1aPYYOiKPcG+50X94fJ9KGSWkNo8MGWCDTkD+MnSHYE8DkLLUsLdZbObH66 2s2dpw== X-Received: by 2002:a05:6000:1a87:b0:38f:3ec3:4801 with SMTP id ffacd0b85a97d-38f616323bamr6689937f8f.25.1740140561789; Fri, 21 Feb 2025 04:22:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IHP8Lu5T3G6KwX0s36LKuCZMOXl5Nr+A2vHjtWT0conKupsh+PZkNU9WdkcSKo3XX8Mqj+bOw== X-Received: by 2002:a05:6000:1a87:b0:38f:3ec3:4801 with SMTP id ffacd0b85a97d-38f616323bamr6689914f8f.25.1740140561459; Fri, 21 Feb 2025 04:22:41 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce404sm15950885e9.7.2025.02.21.04.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:22:40 -0800 (PST) Date: Fri, 21 Feb 2025 07:22:38 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Shivaprasad G Bhat , Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , qemu-ppc@nongnu.org Subject: [PULL 04/41] hw/ppc/spapr_pci: Do not reject VFs created after a PF Message-ID: <3bc31441ba31c94f12b7b96b1960abb4c1f21ee8.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Akihiko Odaki A PF may automatically create VFs and the PF may be function 0. Signed-off-by: Akihiko Odaki Reviewed-by: Shivaprasad G Bhat Tested-by: Shivaprasad G Bhat Message-Id: <20250116-reuse-v20-2-7cb370606368@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/ppc/spapr_pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index b94e4ba131..e0a9d50edc 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1549,7 +1549,9 @@ static void spapr_pci_pre_plug(HotplugHandler *plug_handler, * hotplug, we do not allow functions to be hotplugged to a * slot that already has function 0 present */ - if (plugged_dev->hotplugged && bus->devices[PCI_DEVFN(slotnr, 0)] && + if (plugged_dev->hotplugged && + !pci_is_vf(pdev) && + bus->devices[PCI_DEVFN(slotnr, 0)] && PCI_FUNC(pdev->devfn) != 0) { error_setg(errp, "PCI: slot %d function 0 already occupied by %s," " additional functions can no longer be exposed to guest.", From patchwork Fri Feb 21 12:22:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985344 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 640C9C021B5 for ; Fri, 21 Feb 2025 12:23:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS3Q-0004Y5-Vq; Fri, 21 Feb 2025 07:22: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 1tlS3O-0004V3-Hn for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:22:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS3M-00070Y-UZ for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:22:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140568; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7MQix8FGUYJVo/KUMfZ0aNvVpXePxV+3xwtbN+SCMWk=; b=druYtbjCd6dpn4MzN5V6ALL23t789u46dl+xUwmsap7zsPyMgTRtLjW2dM9Ryn1qgfo4bB m5aQmI+g4qvfC9ylWXjgnWCdSjDvKb/36u0gT26FSYuj17ND4C8HG+bEMrHYLPD1/SeTF+ A6VgzdYCO2FZKhlRq9Mk23HmUwBRVUg= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-FLsUqF-YOh2O203JQdHCbA-1; Fri, 21 Feb 2025 07:22:46 -0500 X-MC-Unique: FLsUqF-YOh2O203JQdHCbA-1 X-Mimecast-MFC-AGG-ID: FLsUqF-YOh2O203JQdHCbA_1740140566 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-38f2f78aee1so940948f8f.0 for ; Fri, 21 Feb 2025 04:22:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140565; x=1740745365; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7MQix8FGUYJVo/KUMfZ0aNvVpXePxV+3xwtbN+SCMWk=; b=Aa4ojany2VYTMi5XsVPEt4BNa5pcu42Z+8lnZpv/phl5yonmfMkmT6QVZvLcuH28s7 GCW2tlJ0g2+EhYu2Cq2pX26MeIwARSX9svygx3XVCEQINyaIoM6eSmUp/wTZHJZi8AID dEPUQgu4cALpYPIbpfPpKG3MNhfdS3tM4Jot3swhxssxkmSKQ5A5plhd/bwXisxAwcYT +U2DRAitIKcrRmIqM41FXMDHG42AD9nUXKFrfF91kVgEoqzEQYVqT/PfFv88OwDVg/WL rm32sQJ91AjYBU+Ky7jfnKMzv+9g+f+7xcNOLC9fznkyrFxwcIkv1oXLzbqm++KKm1JV F7zQ== X-Gm-Message-State: AOJu0YzZV7vUm/L50OHffgfvmNWfUEHEcL8JYMccl4lYYOkySjfgi3DB Au+AUIv92LtVl3NFTjBhKMC1OiCWO5IVb2OL3MdvgQ9hDEDAFYehxhaDCWYT9AA0X3STckrFfRm hS9NPDNxFRBov6gd9+a7GGMa6ViCXdOD+XOk57MstSY2KcYrVd3BPQkCKTNw/a1JzQDvrVlRcqs 0zNtxwSg7JkgJApgKHaQB4iAriA1G96Q== X-Gm-Gg: ASbGncte/6iFha3WZSlew4hgEAUxJ4oPcoiMo5V4EFsBRRYBZs7Jh/Sm773hcnXXdX4 KussXvZvMFMfA9L8oh1OYitpH/rD3IWAE9RgdtPWK0f26f2wPje2cWyHLUOUwl7NIZG6C8llQUU hzsYwbPvZT5HUf2yEyuyLe7R+tpOOFbmUhb5lhtzSQrYV1MJig9wg4pQryBMWOaufq0sc1TW/MV 0A8JClbH9WsfXhmHJjxrkUlR9SfdA/bRbrlzETzI91RjqSkHHih7MGnV2+NxoBVBDjH9RGkbg8T 3xvVyg== X-Received: by 2002:a05:6000:4601:b0:38d:e363:494b with SMTP id ffacd0b85a97d-38f614b6e05mr5807387f8f.8.1740140565496; Fri, 21 Feb 2025 04:22:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrAnCXaIYDuswyI624BgoJT7WSDuQgIwmDuFOSOQPkmR5Qq/oSSfJJ031qH7RaRMR3m2YJNw== X-Received: by 2002:a05:6000:4601:b0:38d:e363:494b with SMTP id ffacd0b85a97d-38f614b6e05mr5807357f8f.8.1740140565134; Fri, 21 Feb 2025 04:22:45 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f259f7987sm22856411f8f.87.2025.02.21.04.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:22:44 -0800 (PST) Date: Fri, 21 Feb 2025 07:22:41 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Matthew Rosato , Eric Farman , Thomas Huth , Halil Pasic , Christian Borntraeger , Richard Henderson , David Hildenbrand , Ilya Leoshkevich , qemu-s390x@nongnu.org Subject: [PULL 05/41] s390x/pci: Avoid creating zpci for VFs Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Akihiko Odaki VFs are automatically created by PF, and creating zpci for them will result in unexpected usage of fids. Currently QEMU does not support multifunction for s390x so we don't need zpci for VFs anyway. Signed-off-by: Akihiko Odaki Message-Id: <20250116-reuse-v20-3-7cb370606368@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/s390x/s390-pci-bus.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c index eead269cc2..8c5eb69f7d 100644 --- a/hw/s390x/s390-pci-bus.c +++ b/hw/s390x/s390-pci-bus.c @@ -1080,6 +1080,16 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev, pbdev = s390_pci_find_dev_by_target(s, dev->id); if (!pbdev) { + /* + * VFs are automatically created by PF, and creating zpci for them + * will result in unexpected usage of fids. Currently QEMU does not + * support multifunction for s390x so we don't need zpci for VFs + * anyway. + */ + if (pci_is_vf(pdev)) { + return; + } + pbdev = s390_pci_device_new(s, dev->id, errp); if (!pbdev) { return; @@ -1167,7 +1177,10 @@ static void s390_pcihost_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, int32_t devfn; pbdev = s390_pci_find_dev_by_pci(s, PCI_DEVICE(dev)); - g_assert(pbdev); + if (!pbdev) { + g_assert(pci_is_vf(pci_dev)); + return; + } s390_pci_generate_plug_event(HP_EVENT_STANDBY_TO_RESERVED, pbdev->fh, pbdev->fid); @@ -1206,7 +1219,11 @@ static void s390_pcihost_unplug_request(HotplugHandler *hotplug_dev, * we've checked the PCI device already (to prevent endless recursion). */ pbdev = s390_pci_find_dev_by_pci(s, PCI_DEVICE(dev)); - g_assert(pbdev); + if (!pbdev) { + g_assert(pci_is_vf(PCI_DEVICE(dev))); + return; + } + pbdev->pci_unplug_request_processed = true; qdev_unplug(DEVICE(pbdev), errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) { From patchwork Fri Feb 21 12:22:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985347 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 20596C021B6 for ; Fri, 21 Feb 2025 12:23:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS3X-0004Zx-Rg; Fri, 21 Feb 2025 07:22:59 -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 1tlS3W-0004ZT-3g for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:22:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS3U-00071T-EY for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:22:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140575; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=26tq86svg637C07OX8DshZCvDsSMROWAQUan5uH5kpM=; b=iFBHcpU4qhxcYCAyZHw1bUD9TzxxHbvKcDhZHVcuo7S8q6Bme9zlBCW261NUuV5QQfqmqA 2wTHc7AYATeZzKaOYv8ZHLdVtOSAvNEoHygUrSyhp10eMRpcIQUB6ZJKsX8lUuzh0th/ix d0Ger6J9b5TSfJil5zOPlJ9NmP4NM2c= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-390-TEUdQM_FP3aFZ0GvvxykhQ-1; Fri, 21 Feb 2025 07:22:53 -0500 X-MC-Unique: TEUdQM_FP3aFZ0GvvxykhQ-1 X-Mimecast-MFC-AGG-ID: TEUdQM_FP3aFZ0GvvxykhQ_1740140572 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-38f443b4949so1040449f8f.3 for ; Fri, 21 Feb 2025 04:22:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140571; x=1740745371; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=26tq86svg637C07OX8DshZCvDsSMROWAQUan5uH5kpM=; b=lAVWwkArapSZFaMuLGOuGFTpBxWd7ysTjn2/5xdDVcjrs3aRTzLPcWFICtaEn7xwH5 PEGKncplqPKTIOpaMifhaHu1WRtKCKF81lRRqA2zrebIaA3lNsAp+1DG13B7lXwSN247 kuPyGL09zmVC1Si/jolnRUOHuMFarROjnb2MpD+oLgXgCYhFi/vNdeSz67OyM9mYrKqO RAbjknfwRe+g79CQp5n3bbPA2ovIX/9L0h3mO7Jn7JSBpmSwQ3L3ZQHKoaZuC+z8R/H6 K/mErsNmM74R3HlRNdMk1fwHEBqSNf74FGUHWoQgIzO8Td5/eQuFyWFdjOW4aUcBIf9F Tnfw== X-Gm-Message-State: AOJu0Yymq+Fra+rwbuX6wpWFcsfJftJFhag9FdbnpMQLlzo9zbmXuCCL OmnMLx7mYIHI/jMB5NQiqkqL6vivzqJlux6rclkNCm4rKA0QJ+fofMLpQ99Fig3PYtRzdPgLL1D bqIgdFA9gtk17NX7M2PAuTmngewP4eIVHOuLyVdaCaLkxfJwDHD9azFw6xoXwqH/E6LEhWvpODD Fw1TxjUA8nNWF1472jvLLK0fJ/Q/wMDg== X-Gm-Gg: ASbGncttrrjZwBOHnyg07+UZViIcudsul+Re6eozLl+z6n67CZufctNLgxuCgvAqTcs dCl3PyvxqvcGg56IVbk/xTsHkN+c1X7hHJutBdQSHFKbrBN1urSzYENimEbMPIhqtFW1e0ox2Jh oMjKrnsO5/Ykaf/s0C6hN4u0hRRPxJhF1Kax4EFOIbYoXbVIT3U94l39/bn5PVC6WAfU8NCCjxh 3zRoM9rAQ1CkX9IlipNG9Mq3Hn8vGvh1Ib1Lf7nZ3qYgT+usE5HI0m53pOWpyHneDg0qvfXHkIT 2MBGpg== X-Received: by 2002:a05:6000:154b:b0:38f:4c30:7cdd with SMTP id ffacd0b85a97d-38f6f09789fmr2233275f8f.37.1740140571472; Fri, 21 Feb 2025 04:22:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHazsbrA/wnDsUbmCsibfGvMWDzQxt4IYp8gV9JJtD7VKvDc2uEmnEZYtqK5JhJs5uksfSEEA== X-Received: by 2002:a05:6000:154b:b0:38f:4c30:7cdd with SMTP id ffacd0b85a97d-38f6f09789fmr2233245f8f.37.1740140571003; Fri, 21 Feb 2025 04:22:51 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02f3e26sm15800895e9.23.2025.02.21.04.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:22:50 -0800 (PST) Date: Fri, 21 Feb 2025 07:22:45 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Matthew Rosato , Eric Farman , Thomas Huth , Richard Henderson , David Hildenbrand , Ilya Leoshkevich , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org Subject: [PULL 06/41] s390x/pci: Allow plugging SR-IOV devices Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Akihiko Odaki The guest cannot use VFs due to the lack of multifunction support but can use PFs. Signed-off-by: Akihiko Odaki Message-Id: <20250116-reuse-v20-4-7cb370606368@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/s390x/s390-pci-bus.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c index 8c5eb69f7d..c396d55c72 100644 --- a/hw/s390x/s390-pci-bus.c +++ b/hw/s390x/s390-pci-bus.c @@ -974,7 +974,14 @@ static void s390_pcihost_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { PCIDevice *pdev = PCI_DEVICE(dev); - if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) { + /* + * Multifunction is not supported due to the lack of CLP. However, + * do not check for multifunction capability for SR-IOV devices because + * SR-IOV devices automatically add the multifunction capability whether + * the user intends to use the functions other than the PF. + */ + if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION && + !pdev->exp.sriov_cap) { error_setg(errp, "multifunction not supported in s390"); return; } From patchwork Fri Feb 21 12:22:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985345 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AFF69C021AA for ; Fri, 21 Feb 2025 12:23:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS3k-0004cs-G5; Fri, 21 Feb 2025 07:23:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS3e-0004bp-7h for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS3b-000727-Bk for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=G0XVE7dDqExIfNSqEU8DxvlpmcQMz4iRneIR4IAtIjk=; b=YRtMdUQRLHyfhUmGHmzfnw0X8PZYmHlsp/N2z/fvBd6MWcKQcKQhMY37GZZMW8wq/6M9DF cOJC5QsCJhN8juyLw4lnPz3YzNNaeb4YeOb2okG+SDEJr7AwAK2pZaidM72AVFsFNhxqLz 2hjeRsm/qgLG23dsu4oo65xiLrghP/w= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-640-40TqBTOUN1ORNuqiZkb8JA-1; Fri, 21 Feb 2025 07:23:00 -0500 X-MC-Unique: 40TqBTOUN1ORNuqiZkb8JA-1 X-Mimecast-MFC-AGG-ID: 40TqBTOUN1ORNuqiZkb8JA_1740140579 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-439a0e28cfaso10953635e9.2 for ; Fri, 21 Feb 2025 04:22:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140578; x=1740745378; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=G0XVE7dDqExIfNSqEU8DxvlpmcQMz4iRneIR4IAtIjk=; b=XyuqLAgmJQQOJ1UBbPDj+lUDOyjW+NjLFObGCAf1JD4NW7VpsPztMtk0ESbptfNlD3 iTl1QI3cJNR15en9wOtnhLMGPQDpUUA5SIs/L3CN9OPrLEAR86BckkeWUHksP5UjTcRS 32sm6Jgk1ZfFAzaXISGiqhtuVvIzEdLPPSmGb85cgwekuMY3w9ELMif71qbVnf9wBxQk Qba6KOJLHQkP1xMKVlUSPNJN0lUHZfL+wmwHJOBbQJijXH+AaPzWKzujY7jgHhYMG2Yn qgdWG6IoXv7vO83e2+sX9f0RR8KRXROFZdtLmdOQaJCfW0ndnPU6zqWK6ISC8stk8nY8 5ovQ== X-Gm-Message-State: AOJu0YzYRRzUmoVXnEZWFQgJGv+2qpNxeCgh/Ncg7ZJxmNbtypCQ8hW0 wRIKCbv4pw7Y3A/YZlch+OiUJweAGnnWIGu8XQbyXLuGY4d9yHzRpPXdroIV6t+gLGPiA2c4wyb H6SDKwSqdE9A7PyFe8FtdDHQq24D7XZW8QDlbnBJ7gaHDK4bXU2gFrSfVd1sqg5FsWqPRnpXRae T1d/+wi8L6zJGsFCi5wDNhUUdq1uYeTA== X-Gm-Gg: ASbGncv2Xvd0SUCr34BiFMeLj5K49rsIz6azWBtEn4bMhaG3mAfwOzOG3Lr+K6Q+QMa zN/dufX0tCHUyFJKsfyBS3vdE6IEyOiX3g3OgSTfBgCfzuqp0jm/VvdC4L3pjoGphJTkLIJmFTw BqM0GhxgzzzyNF71xTptlusxLzDLGMg2i+2+KCfr3bqTMgbdGk/MJD1t0Wzbhwsg+VGBmpQuTW5 z5yg2x8lqnDmPeU2kDeo3bCqXyWiKOsaq0P5p1UpxzTR7mvu81TeusMOpfZI3AtkUiJ+ZFCZeD8 +PszEw== X-Received: by 2002:a05:600c:19c7:b0:439:a1c7:7b27 with SMTP id 5b1f17b1804b1-439ae1d7c76mr21777695e9.1.1740140578286; Fri, 21 Feb 2025 04:22:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGHILvs6eZM2erNuLxpktrsk0IO0exqVd6D3UQox2wttJkm2Rk9KctrHPoxbRZadUuT96La0Q== X-Received: by 2002:a05:600c:19c7:b0:439:a1c7:7b27 with SMTP id 5b1f17b1804b1-439ae1d7c76mr21777385e9.1.1740140577838; Fri, 21 Feb 2025 04:22:57 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258b4344sm23576279f8f.13.2025.02.21.04.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:22:57 -0800 (PST) Date: Fri, 21 Feb 2025 07:22:51 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Matthew Rosato , Eric Farman , Thomas Huth , Richard Henderson , David Hildenbrand , Ilya Leoshkevich , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org Subject: [PULL 07/41] s390x/pci: Check for multifunction after device realization Message-ID: <2c968f465392316d09e44f4a9f7e378999e5c011.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Akihiko Odaki The SR-IOV PFs set the multifunction bit during device realization so check them after that. There is no functional change because we explicitly ignore the multifunction bit for SR-IOV devices. Signed-off-by: Akihiko Odaki Message-Id: <20250116-reuse-v20-5-7cb370606368@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/s390x/s390-pci-bus.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c index c396d55c72..913d72cc74 100644 --- a/hw/s390x/s390-pci-bus.c +++ b/hw/s390x/s390-pci-bus.c @@ -971,21 +971,7 @@ static void s390_pcihost_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, "this device"); } - if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { - PCIDevice *pdev = PCI_DEVICE(dev); - - /* - * Multifunction is not supported due to the lack of CLP. However, - * do not check for multifunction capability for SR-IOV devices because - * SR-IOV devices automatically add the multifunction capability whether - * the user intends to use the functions other than the PF. - */ - if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION && - !pdev->exp.sriov_cap) { - error_setg(errp, "multifunction not supported in s390"); - return; - } - } else if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) { + if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) { S390PCIBusDevice *pbdev = S390_PCI_DEVICE(dev); if (!s390_pci_alloc_idx(s, pbdev)) { @@ -1076,6 +1062,18 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev, } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { pdev = PCI_DEVICE(dev); + /* + * Multifunction is not supported due to the lack of CLP. However, + * do not check for multifunction capability for SR-IOV devices because + * SR-IOV devices automatically add the multifunction capability whether + * the user intends to use the functions other than the PF. + */ + if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION && + !pdev->exp.sriov_cap) { + error_setg(errp, "multifunction not supported in s390"); + return; + } + if (!dev->id) { /* In the case the PCI device does not define an id */ /* we generate one based on the PCI address */ From patchwork Fri Feb 21 12:22:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985348 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E98DEC021B3 for ; Fri, 21 Feb 2025 12:23:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS3o-0004n3-Bw; Fri, 21 Feb 2025 07:23:16 -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 1tlS3f-0004cO-K5 for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS3e-00072Z-0i for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140584; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3ztxZYHC/wgNt/4DA2+N5Hjvx7lOPTBhePRhwRi2JF0=; b=IG20LH4VcfZT+MMehrnkFmcNUwaJ9WS8RDq36ioQLHIlEB3rPHHtAsO3fM0RAp7RDKHOrd ID4cJDS75HDhEnvVQBrhwsgWCgG9lSHrxlT3UwJLPe0A1AxqT9v6aYjrUKJwdErS53igFC tz7tdCnCncOTH8bYk0yIINCuHyV5Y/A= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-1-dh5asD9iNnWS0b41WCtdSA-1; Fri, 21 Feb 2025 07:23:03 -0500 X-MC-Unique: dh5asD9iNnWS0b41WCtdSA-1 X-Mimecast-MFC-AGG-ID: dh5asD9iNnWS0b41WCtdSA_1740140582 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4399a5afc72so10241825e9.3 for ; Fri, 21 Feb 2025 04:23:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140581; x=1740745381; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3ztxZYHC/wgNt/4DA2+N5Hjvx7lOPTBhePRhwRi2JF0=; b=Kzsu/TqBidv8KsNuKxUZ8839O8vVp+gutpcd7E+DdAh+yVoscz9Sywz8Yu7hlhnjRv dKJ7XZh3IpKSSPXAKtDFVvm/hoL9d6wiGYCvEcNeCTkjNjRa37z2FB0QbyPccZiw+nVH gRM/Y05fOC34gaYIHvfRqQnArZHXVmFK5lMNyNWwdv8WiOncWaFoJ54Naq8Xvln7rkHl ly2WbNVAUpRSeshFgd0RiKjx2XGrUD/Hkp3FBr89QQ0C8rqiQ9uAbvkPbr3waZu4i5az Bcs+b+tp4N8so4GBrT2K60dlIrMFegW4F+UKLKzdHcBYlbrwFrhJo7FxBpITdn+b9n+r tymw== X-Gm-Message-State: AOJu0Yz/EOwHIM4ChvdQb1mglNTLhpv0rwmd0t2ReR2Mqg9h2ygDHNe9 NejHORqd3bsFN8UHap1lNe2p5WIkR30df01P6M0tHV3RzdJctnTVNH5saE0b8mOik0wSF4kqUwi 89hDp8ErRXaCyBYoINCI//ACmWHz9vKCw0IaJ+LKyvWUhHe2R1ZShjkdmAygXlpqe1VSt/CfYPT SdWQD2l+D64mBThjR0fEj8STGSWqBGKA== X-Gm-Gg: ASbGncvk6HemloYvmd+xF83ly3LuIiRZpmBcC4Kjv+fSfpu1znoYXeMD9MKOHD4C+bE 5EEpf1gto0jL1b8yMgU4A3d/MZBxX4Sz5q6iuEGG23m8wp3hzAs7dVxqF+jvq6ot1V/9H0nCYif 7N6P3aU8Kk5OVPVYxByXcnlyLIVE6tEcW8zP0R9k76n2OcP4F5CTLJjsnFU7JpDFkadsEZy7aZf EKxzXRrQhmO6rQ9G0hQcmU0wosjIQbbfWuDgLq30a7LvL32yFDcw6fqssNs5jxVqgl1xgxKoTvO +zzoUQ== X-Received: by 2002:a05:600c:19ce:b0:439:94ef:3766 with SMTP id 5b1f17b1804b1-439aebc3138mr20844155e9.19.1740140581474; Fri, 21 Feb 2025 04:23:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGeT4HQFf67yVdc8AorOK+9fKjah8vcnrXEqsk8/ReKKkZjjU5gx/L3XBezBIzeHa5WUxGlVg== X-Received: by 2002:a05:600c:19ce:b0:439:94ef:3766 with SMTP id 5b1f17b1804b1-439aebc3138mr20843865e9.19.1740140581064; Fri, 21 Feb 2025 04:23:01 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b030bd09sm15790615e9.29.2025.02.21.04.22.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:00 -0800 (PST) Date: Fri, 21 Feb 2025 07:22:58 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Philippe =?utf-8?q?Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Marcel Apfelbaum Subject: [PULL 08/41] pcie_sriov: Do not manually unrealize Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Akihiko Odaki A device gets automatically unrealized when being unparented. Signed-off-by: Akihiko Odaki Message-Id: <20250116-reuse-v20-6-7cb370606368@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daudé --- hw/pci/pcie_sriov.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index e9b23221d7..499becd527 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -204,11 +204,7 @@ static void unregister_vfs(PCIDevice *dev) trace_sriov_unregister_vfs(dev->name, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), num_vfs); for (i = 0; i < num_vfs; i++) { - Error *err = NULL; PCIDevice *vf = dev->exp.sriov_pf.vf[i]; - if (!object_property_set_bool(OBJECT(vf), "realized", false, &err)) { - error_reportf_err(err, "Failed to unplug: "); - } object_unparent(OBJECT(vf)); object_unref(OBJECT(vf)); } From patchwork Fri Feb 21 12:23:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985363 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E4573C021B5 for ; Fri, 21 Feb 2025 12:28:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS3p-0004r0-VU; Fri, 21 Feb 2025 07:23:18 -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 1tlS3l-0004j2-Fx for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS3j-00073R-0o for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140590; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3X006yARdsa1uDQPAY1F+3/wP7iCnB6iiPTNqNOmGNU=; b=KzbwC6C0DWPRwdzGbRDd6IDOOEM+wuyf3O4vIvXuTIXCnK+Nsat0AGcyg3SQTPJZyG0Rcr BexQJTUqm/IgFZ2TvYzan+WK1Lx1PEilpcZZAtN6PzV/DiLw5FhcoHFPqYP/XWHJh21Lpj G9Qy2kJn3RMeoeZQxViYdJJPLM8Q294= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-321-DI_v996zNpyrY-tGfs-eNA-1; Fri, 21 Feb 2025 07:23:07 -0500 X-MC-Unique: DI_v996zNpyrY-tGfs-eNA-1 X-Mimecast-MFC-AGG-ID: DI_v996zNpyrY-tGfs-eNA_1740140586 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-439a5c4dfb2so9887495e9.1 for ; Fri, 21 Feb 2025 04:23:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140585; x=1740745385; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3X006yARdsa1uDQPAY1F+3/wP7iCnB6iiPTNqNOmGNU=; b=Rwz+SnicPBIKfXNqdwTgG6WTOro7xJxEqmJc0G3K3BP7+RdIp+FadVQlYvKqMN60aa AuXOUn+ml0A472lJpiBLCB9+ueB5z4zly+goF1OsjfJ9ruDkn40mNCh2m0uth/5V1ZN5 ZqHwRJTjEC90sNZIAgvMqWcL8fCnh9BbfJ4YbbIZIoOdHrwddbd2Yf+EECBUEZHzFyWn MnkzijQjhYPJm1WBZKFoTbBHAtl7N8Dq7iCOM7czmzE60kwGJUJNmNMVwxUnSaLP8VAm C3JqDE3Yg1WHZ9kG2aHhdu4Ga7an4+X6bIJFIYP7Lq5Pyk5+BS1XPHNon6TmdZ4+w5GU x2GA== X-Gm-Message-State: AOJu0YxpgAG7Y5hhzyjnm4Xa56kJi6qmBse0AWQckXMsrDC3SemfqL5X 3VepY9fu7rStEvkTWXq+Bi5x0W1E4GcoJeNu6Z5ID+HxqYS6faQ7uaHR+8eJ2fBulWMrywMpveL iHcad9QLTVLMMhSAHmHadqPUdiYRk+be6Vq2OzobvXkFRvcT2XWhqCiCBwLya/pOW6onovvBnPq 715uux647CItUfDHE/Dy5KAGBcEgawzQ== X-Gm-Gg: ASbGnct/0WwDHlY42pmoVfcEGzmoCQ1ZMItawmHxwUWsOBHarHzMOE2kPtKG2ILqsdr X0GL5MRgXJnYxpd9dPErMFcvLRqAGrnC7UcCjrCAqsySrqegCR1VW7pr+9SERIyH/Z+MAI/HCdv WtG3eyWPFysjUW36WimsBETNBUaqh3S6uwev/t75JuwJ+FYPjSmLgsEI2IvP0pcggL0BljMSnYg uuud2YoO4vSKcp28AHeQbQSLKUewSLLhxsd3hRwxesESV/CVcCgzQ0DcacBJRBhNtVoJBn1wIG7 BpFl9Q== X-Received: by 2002:a05:600c:1906:b0:439:8a62:db42 with SMTP id 5b1f17b1804b1-439ae1e62fbmr22332275e9.8.1740140584918; Fri, 21 Feb 2025 04:23:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IGv1H8u6kapWtJY8xXVCTdaZK8LelvoT5Hnf/t9Bnr3swOsyuRCQb8phmi6WPRSc4k9r3h/Vw== X-Received: by 2002:a05:600c:1906:b0:439:8a62:db42 with SMTP id 5b1f17b1804b1-439ae1e62fbmr22331935e9.8.1740140584442; Fri, 21 Feb 2025 04:23:04 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce65dsm15963415e9.1.2025.02.21.04.23.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:03 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:01 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Marcel Apfelbaum , Sriram Yagnaraman , Jason Wang , Keith Busch , Klaus Jensen , Jesper Devantier , qemu-block@nongnu.org Subject: [PULL 09/41] pcie_sriov: Ensure VF addr does not overflow Message-ID: <3391d68e906114c364c173c7f3f7389d47d15a11.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Akihiko Odaki pci_new() aborts when creating a VF with addr >= PCI_DEVFN_MAX. Signed-off-by: Akihiko Odaki Message-Id: <20250116-reuse-v20-7-7cb370606368@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- docs/pcie_sriov.txt | 8 +++++--- include/hw/pci/pcie_sriov.h | 5 +++-- hw/net/igb.c | 10 +++++++--- hw/nvme/ctrl.c | 22 ++++++++++++++-------- hw/pci/pcie_sriov.c | 14 ++++++++++++-- 5 files changed, 41 insertions(+), 18 deletions(-) diff --git a/docs/pcie_sriov.txt b/docs/pcie_sriov.txt index a47aad0bfa..ab2142807f 100644 --- a/docs/pcie_sriov.txt +++ b/docs/pcie_sriov.txt @@ -52,9 +52,11 @@ setting up a BAR for a VF. ... /* Add and initialize the SR/IOV capability */ - pcie_sriov_pf_init(d, 0x200, "your_virtual_dev", - vf_devid, initial_vfs, total_vfs, - fun_offset, stride); + if (!pcie_sriov_pf_init(d, 0x200, "your_virtual_dev", + vf_devid, initial_vfs, total_vfs, + fun_offset, stride, errp)) { + return; + } /* Set up individual VF BARs (parameters as for normal BARs) */ pcie_sriov_pf_init_vf_bar( ... ) diff --git a/include/hw/pci/pcie_sriov.h b/include/hw/pci/pcie_sriov.h index 450cbef6c2..aa704e8f9d 100644 --- a/include/hw/pci/pcie_sriov.h +++ b/include/hw/pci/pcie_sriov.h @@ -27,10 +27,11 @@ typedef struct PCIESriovVF { uint16_t vf_number; /* Logical VF number of this function */ } PCIESriovVF; -void pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, +bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, const char *vfname, uint16_t vf_dev_id, uint16_t init_vfs, uint16_t total_vfs, - uint16_t vf_offset, uint16_t vf_stride); + uint16_t vf_offset, uint16_t vf_stride, + Error **errp); void pcie_sriov_pf_exit(PCIDevice *dev); /* Set up a VF bar in the SR/IOV bar area */ diff --git a/hw/net/igb.c b/hw/net/igb.c index 4d93ce629f..c965fc2fb6 100644 --- a/hw/net/igb.c +++ b/hw/net/igb.c @@ -446,9 +446,13 @@ static void igb_pci_realize(PCIDevice *pci_dev, Error **errp) pcie_ari_init(pci_dev, 0x150); - pcie_sriov_pf_init(pci_dev, IGB_CAP_SRIOV_OFFSET, TYPE_IGBVF, - IGB_82576_VF_DEV_ID, IGB_MAX_VF_FUNCTIONS, IGB_MAX_VF_FUNCTIONS, - IGB_VF_OFFSET, IGB_VF_STRIDE); + if (!pcie_sriov_pf_init(pci_dev, IGB_CAP_SRIOV_OFFSET, TYPE_IGBVF, + IGB_82576_VF_DEV_ID, IGB_MAX_VF_FUNCTIONS, + IGB_MAX_VF_FUNCTIONS, IGB_VF_OFFSET, IGB_VF_STRIDE, + errp)) { + igb_cleanup_msix(s); + return; + } pcie_sriov_pf_init_vf_bar(pci_dev, IGBVF_MMIO_BAR_IDX, PCI_BASE_ADDRESS_MEM_TYPE_64 | PCI_BASE_ADDRESS_MEM_PREFETCH, diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 68903d1d70..8175751518 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -8481,7 +8481,8 @@ out: return pow2ceil(bar_size); } -static void nvme_init_sriov(NvmeCtrl *n, PCIDevice *pci_dev, uint16_t offset) +static bool nvme_init_sriov(NvmeCtrl *n, PCIDevice *pci_dev, uint16_t offset, + Error **errp) { uint16_t vf_dev_id = n->params.use_intel_id ? PCI_DEVICE_ID_INTEL_NVME : PCI_DEVICE_ID_REDHAT_NVME; @@ -8490,12 +8491,16 @@ static void nvme_init_sriov(NvmeCtrl *n, PCIDevice *pci_dev, uint16_t offset) le16_to_cpu(cap->vifrsm), NULL, NULL); - pcie_sriov_pf_init(pci_dev, offset, "nvme", vf_dev_id, - n->params.sriov_max_vfs, n->params.sriov_max_vfs, - NVME_VF_OFFSET, NVME_VF_STRIDE); + if (!pcie_sriov_pf_init(pci_dev, offset, "nvme", vf_dev_id, + n->params.sriov_max_vfs, n->params.sriov_max_vfs, + NVME_VF_OFFSET, NVME_VF_STRIDE, errp)) { + return false; + } pcie_sriov_pf_init_vf_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64, bar_size); + + return true; } static int nvme_add_pm_capability(PCIDevice *pci_dev, uint8_t offset) @@ -8620,6 +8625,11 @@ static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev, Error **errp) return false; } + if (!pci_is_vf(pci_dev) && n->params.sriov_max_vfs && + !nvme_init_sriov(n, pci_dev, 0x120, errp)) { + return false; + } + nvme_update_msixcap_ts(pci_dev, n->conf_msix_qsize); pcie_cap_deverr_init(pci_dev); @@ -8649,10 +8659,6 @@ static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev, Error **errp) nvme_init_pmr(n, pci_dev); } - if (!pci_is_vf(pci_dev) && n->params.sriov_max_vfs) { - nvme_init_sriov(n, pci_dev, 0x120); - } - return true; } diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index 499becd527..91c64c988e 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -24,14 +24,22 @@ static PCIDevice *register_vf(PCIDevice *pf, int devfn, const char *name, uint16_t vf_num); static void unregister_vfs(PCIDevice *dev); -void pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, +bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, const char *vfname, uint16_t vf_dev_id, uint16_t init_vfs, uint16_t total_vfs, - uint16_t vf_offset, uint16_t vf_stride) + uint16_t vf_offset, uint16_t vf_stride, + Error **errp) { + int32_t devfn = dev->devfn + vf_offset; uint8_t *cfg = dev->config + offset; uint8_t *wmask; + if (total_vfs && + (uint32_t)devfn + (uint32_t)(total_vfs - 1) * vf_stride >= PCI_DEVFN_MAX) { + error_setg(errp, "VF addr overflows"); + return false; + } + pcie_add_capability(dev, PCI_EXT_CAP_ID_SRIOV, 1, offset, PCI_EXT_CAP_SRIOV_SIZEOF); dev->exp.sriov_cap = offset; @@ -69,6 +77,8 @@ void pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, pci_set_word(wmask + PCI_SRIOV_SYS_PGSIZE, 0x553); qdev_prop_set_bit(&dev->qdev, "multifunction", true); + + return true; } void pcie_sriov_pf_exit(PCIDevice *dev) From patchwork Fri Feb 21 12:23:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985342 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 982B0C021B3 for ; Fri, 21 Feb 2025 12:23:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS3r-0004uO-54; Fri, 21 Feb 2025 07:23:19 -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 1tlS3o-0004n8-6I for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS3k-00073V-Ce for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140591; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=scidcpthAR0TJWBqQT5UtCSnzM8INobCgdjwksC9/UU=; b=Vqta7CRQNBe8tAHr/cpDGRM8ucK+ZNm+qZHH2xefINSaRPg2aFl/aezUhwUuIV2IRDztvm iDGATYRKdYonJTZvFaaF/weX/1JONAWek9NEkR7odplsaxAuXidCdMLxOy8ruzezIlHLem 6NjdibkZvYHIdE04txrkG31lWx+vpC0= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-246-cQoBxxyAMhWn7OY3fUR3Mg-1; Fri, 21 Feb 2025 07:23:10 -0500 X-MC-Unique: cQoBxxyAMhWn7OY3fUR3Mg-1 X-Mimecast-MFC-AGG-ID: cQoBxxyAMhWn7OY3fUR3Mg_1740140589 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-38f44be93a8so1064670f8f.1 for ; Fri, 21 Feb 2025 04:23:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140588; x=1740745388; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=scidcpthAR0TJWBqQT5UtCSnzM8INobCgdjwksC9/UU=; b=s84o6Q59iGbXS+1JIOk7Sxe0SLwsrK0metzD4ahT0nn6eKfZLzzW36/S81Erjgf2HP LUjdfgme4j4JhQOObwEU1BUhNMsZnrgwhqWlwToNqMiwVX6XNLr1tq2EuSogaFIdUU+q lueA053MAldjHuSucD1O1M5l+OumIuN+bKMYw3dnxISRQ/yZMKHv6csWuKgb3OcoCr/h qReKURHP4i7obby4eIaQlTEjseCtSvurxAQrkLyeTkWFH06jsuDv8ZSDzphCa9z91NWC c5GjOp1D+XP+I/dp9/7vuFalSknp3ZhltnFOPwuIxqpoy7p07T7UE3L3FEiikv1+wK1z SEUw== X-Gm-Message-State: AOJu0YyeUMwL1aFGTAyfw/fKyOylDsIqaWghx/YVPiiw7bybUelVfBpt udHki5w/LslqsCsbMZiY/L8UcDN45OkkX/Tr3l/wjDxhCDxM4pgVdU19HYqr4YA0XdDEfhQXX8u 8TlsvJsan18o2kZfP3wm7qrNAyzojlTFT5PuFFUOl3Rjysnn0WeiOAdZBn+ipaY7+Nw9s1fknxh 46Ef/8asEeo/jaa9yXr2AFaABElzq64A== X-Gm-Gg: ASbGncvMfd7GlAdXJs7jfuBIm2M284oHDKufjRxoX7OsQjKJ6FofovT8j5L7HH7qSd7 vb2c60f2W3tqvnlco/mxQ7P3zT1ID0xOg8MVMB9VqDeJRe0p03CduDTsiCf0qXSGWL2Elm38xz7 mSCAoVU8W0HeODykbjz+WXwn/0F6wPYAAAdGNWnDIqV9og/w3J18+BB1M+zdBnTBTJRAsv2AmaP 6rsMUs6khKnhHCo25yhwAQt4qYqYRdtzoM9QFivrHpMJeYfl1TxtSIP2l/OC6Dn75TYOXx/iM4S bLdV2Q== X-Received: by 2002:a05:6000:188f:b0:38f:277a:4eb6 with SMTP id ffacd0b85a97d-38f6e4bdf02mr2448572f8f.0.1740140588328; Fri, 21 Feb 2025 04:23:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrrUOzSJRerlT4CS6/y5fUKc+0bJYhH2HuRNdPEOvZOIy5Ts+dLe4+wHX+zt1b4JWdCP/jCg== X-Received: by 2002:a05:6000:188f:b0:38f:277a:4eb6 with SMTP id ffacd0b85a97d-38f6e4bdf02mr2448551f8f.0.1740140587847; Fri, 21 Feb 2025 04:23:07 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258b44b2sm22963137f8f.20.2025.02.21.04.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:06 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:04 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Marcel Apfelbaum Subject: [PULL 10/41] pcie_sriov: Reuse SR-IOV VF device instances Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Akihiko Odaki 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 Message-Id: <20250116-reuse-v20-8-7cb370606368@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/pci/pcie_sriov.h | 1 - hw/pci/pci.c | 14 +++++- hw/pci/pcie_sriov.c | 94 +++++++++++++++---------------------- 3 files changed, 51 insertions(+), 58 deletions(-) diff --git a/include/hw/pci/pcie_sriov.h b/include/hw/pci/pcie_sriov.h index aa704e8f9d..70649236c1 100644 --- a/include/hw/pci/pcie_sriov.h +++ b/include/hw/pci/pcie_sriov.h @@ -18,7 +18,6 @@ typedef 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 */ } PCIESriovPF; diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 2afa423925..3e29b30d55 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2963,7 +2963,17 @@ MSIMessage pci_get_msi_message(PCIDevice *dev, int vector) void pci_set_power(PCIDevice *d, bool state) { - pci_set_enabled(d, state); + /* + * Don't change the enabled state of VFs when powering on/off the device. + * + * When powering on, VFs must not be enabled immediately but they must + * wait until the guest configures SR-IOV. + * When powering off, their corresponding PFs will be reset and disable + * VFs. + */ + if (!pci_is_vf(d)) { + pci_set_enabled(d, state); + } } void pci_set_enabled(PCIDevice *d, bool state) @@ -2977,7 +2987,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 (qdev_is_realized(&d->qdev)) { pci_device_reset(d); } } diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index 91c64c988e..f1993bc553 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -20,9 +20,16 @@ #include "qapi/error.h" #include "trace.h" -static PCIDevice *register_vf(PCIDevice *pf, int devfn, - const char *name, uint16_t vf_num); -static void unregister_vfs(PCIDevice *dev); +static void unparent_vfs(PCIDevice *dev, uint16_t total_vfs) +{ + for (uint16_t i = 0; i < total_vfs; i++) { + PCIDevice *vf = dev->exp.sriov_pf.vf[i]; + object_unparent(OBJECT(vf)); + object_unref(OBJECT(vf)); + } + g_free(dev->exp.sriov_pf.vf); + dev->exp.sriov_pf.vf = NULL; +} bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, const char *vfname, uint16_t vf_dev_id, @@ -30,6 +37,7 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, uint16_t vf_offset, uint16_t vf_stride, Error **errp) { + BusState *bus = qdev_get_parent_bus(&dev->qdev); int32_t devfn = dev->devfn + vf_offset; uint8_t *cfg = dev->config + offset; uint8_t *wmask; @@ -44,7 +52,6 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, offset, PCI_EXT_CAP_SRIOV_SIZEOF); dev->exp.sriov_cap = offset; dev->exp.sriov_pf.num_vfs = 0; - dev->exp.sriov_pf.vfname = g_strdup(vfname); dev->exp.sriov_pf.vf = NULL; pci_set_word(cfg + PCI_SRIOV_VF_OFFSET, vf_offset); @@ -78,14 +85,34 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, qdev_prop_set_bit(&dev->qdev, "multifunction", true); + dev->exp.sriov_pf.vf = g_new(PCIDevice *, total_vfs); + + for (uint16_t i = 0; i < total_vfs; i++) { + PCIDevice *vf = pci_new(devfn, vfname); + vf->exp.sriov_vf.pf = dev; + vf->exp.sriov_vf.vf_number = i; + + if (!qdev_realize(&vf->qdev, bus, errp)) { + unparent_vfs(dev, i); + return false; + } + + /* set vid/did according to sr/iov spec - they are not used */ + pci_config_set_vendor_id(vf->config, 0xffff); + pci_config_set_device_id(vf->config, 0xffff); + + dev->exp.sriov_pf.vf[i] = vf; + devfn += vf_stride; + } + return true; } void pcie_sriov_pf_exit(PCIDevice *dev) { - unregister_vfs(dev); - g_free((char *)dev->exp.sriov_pf.vfname); - dev->exp.sriov_pf.vfname = NULL; + uint8_t *cfg = dev->config + dev->exp.sriov_cap; + + unparent_vfs(dev, pci_get_word(cfg + PCI_SRIOV_TOTAL_VF)); } void pcie_sriov_pf_init_vf_bar(PCIDevice *dev, int region_num, @@ -151,38 +178,11 @@ void pcie_sriov_vf_register_bar(PCIDevice *dev, int region_num, } } -static PCIDevice *register_vf(PCIDevice *pf, int devfn, const char *name, - uint16_t vf_num) -{ - PCIDevice *dev = pci_new(devfn, name); - dev->exp.sriov_vf.pf = pf; - dev->exp.sriov_vf.vf_number = vf_num; - PCIBus *bus = pci_get_bus(pf); - Error *local_err = NULL; - - qdev_realize(&dev->qdev, &bus->qbus, &local_err); - if (local_err) { - error_report_err(local_err); - return NULL; - } - - /* set vid/did according to sr/iov spec - they are not used */ - pci_config_set_vendor_id(dev->config, 0xffff); - pci_config_set_device_id(dev->config, 0xffff); - - return dev; -} - static void register_vfs(PCIDevice *dev) { uint16_t num_vfs; uint16_t i; uint16_t sriov_cap = dev->exp.sriov_cap; - uint16_t vf_offset = - pci_get_word(dev->config + sriov_cap + PCI_SRIOV_VF_OFFSET); - uint16_t vf_stride = - pci_get_word(dev->config + sriov_cap + PCI_SRIOV_VF_STRIDE); - int32_t devfn = dev->devfn + vf_offset; assert(sriov_cap > 0); num_vfs = pci_get_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF); @@ -190,18 +190,10 @@ static void register_vfs(PCIDevice *dev) return; } - dev->exp.sriov_pf.vf = g_new(PCIDevice *, num_vfs); - trace_sriov_register_vfs(dev->name, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), num_vfs); for (i = 0; i < num_vfs; i++) { - dev->exp.sriov_pf.vf[i] = register_vf(dev, devfn, - dev->exp.sriov_pf.vfname, i); - if (!dev->exp.sriov_pf.vf[i]) { - num_vfs = i; - break; - } - devfn += vf_stride; + pci_set_enabled(dev->exp.sriov_pf.vf[i], true); } dev->exp.sriov_pf.num_vfs = num_vfs; } @@ -214,12 +206,8 @@ static void unregister_vfs(PCIDevice *dev) trace_sriov_unregister_vfs(dev->name, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), num_vfs); for (i = 0; i < num_vfs; i++) { - PCIDevice *vf = dev->exp.sriov_pf.vf[i]; - object_unparent(OBJECT(vf)); - object_unref(OBJECT(vf)); + pci_set_enabled(dev->exp.sriov_pf.vf[i], false); } - g_free(dev->exp.sriov_pf.vf); - dev->exp.sriov_pf.vf = NULL; dev->exp.sriov_pf.num_vfs = 0; } @@ -241,14 +229,10 @@ void pcie_sriov_config_write(PCIDevice *dev, uint32_t address, PCI_FUNC(dev->devfn), off, val, len); if (range_covers_byte(off, len, PCI_SRIOV_CTRL)) { - if (dev->exp.sriov_pf.num_vfs) { - if (!(val & PCI_SRIOV_CTRL_VFE)) { - unregister_vfs(dev); - } + if (val & PCI_SRIOV_CTRL_VFE) { + register_vfs(dev); } else { - if (val & PCI_SRIOV_CTRL_VFE) { - register_vfs(dev); - } + unregister_vfs(dev); } } } From patchwork Fri Feb 21 12:23:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985351 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 80B52C021AA for ; Fri, 21 Feb 2025 12:24:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS3s-0004wo-Cl; Fri, 21 Feb 2025 07:23:20 -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 1tlS3q-0004sT-7J for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS3o-000748-Jn for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140595; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=mfkx6yp82DqPMaxn6p6MT4av8h+ImeBPBY6drzozmNw=; b=D+x4hVrbdIzEhTg9q5XnSVJdQj8Pq7KNibR+u9rTPz5kpzZOY1TaRguK7tF1dtK+rCJ6at Tbi6clLIb+PQQrdF6CSEjSpNLCHfAjnbkv/OyZeaigXfPeRuUXUGQzP55xLWVB4ip+Pbrn 9uCNnAtQR/eo0FWEXk5h0xdQjPhDb/A= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-215-BllzbMgHNWOw-fNmXp0PiQ-1; Fri, 21 Feb 2025 07:23:12 -0500 X-MC-Unique: BllzbMgHNWOw-fNmXp0PiQ-1 X-Mimecast-MFC-AGG-ID: BllzbMgHNWOw-fNmXp0PiQ_1740140592 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4398e841963so22344115e9.3 for ; Fri, 21 Feb 2025 04:23:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140591; x=1740745391; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=mfkx6yp82DqPMaxn6p6MT4av8h+ImeBPBY6drzozmNw=; b=mnjYYlsNEodpSWe3XzzvzY34ppNJm0ldCTpMk4dKCN0HrC8y85IOTpHx8AiyJUTaXK AgRrrVxK/xed3IlwcLhjiuNz0mC349xHELfDCSvOqEIljkyx0zp3eE8bC/gV5FVPFztC gp+xEC1sJavrjU0vB4y74PhxOcjpqmvTj68xnq5PJDXXp0PQef7ENuDFSyvnS2f9Q9Al rQgoEPS+m8dv0lJnEEEZFOCDtQEhIcgYflD4Ztm1mc8C1zmeGq+C1/Sv8w5B5y+H5ACx BFXCGmxuVHFiThA+nPXcpY6KSJKGfshF2HU9dVuizSfONzL5kTpYJw9qVAy31KLGOzh0 mgKA== X-Gm-Message-State: AOJu0YzpFqHuVXyndfIyVRSV2asdRw798Ka5bPfIHHEJiaW9iYdbCQE6 L0syBideh3L2M8Ej/W1NmA4/U94AxuaHCfuUbNU1mk+8vwucjmwnc8kTOsqQjMdOqIqEa/24JFn UFkFEUdL+jGuBRVzxdjGTqF3lo4zfrb4oZ57pxD2HX9YTK2RaEtDxyfndMlwK+7/LWnyaKlA3Lw VjDNlcBZlss/INcW//h2Tx0wdRh1STiA== X-Gm-Gg: ASbGncukpwJCDL5hcrUpii/wp1vdP8nqQ6YLMqu24f3ncoJL1kvNxnJpc+4vvm6CED2 aypYereLxOpSK62MYzOAQaF4m8KZfyrrpb+kZ4wMRjaio0HyxCIGbRCQC0WD8A3wyxbHXSoyxDb /MYOJSwMUlORvAUsypxHgIv6LNF2HVs5888JXhgQbhSLcP13bLNCbLzpVU7BkkUvo0aXWnO1ulq JTMz4q+lNhBlCHYHnKADZqqRfBDaPCBu/ab2cUYPo1RpKNcWGg8mJR1VQlEGta1PNLdaqta3sZO Q1RiMw== X-Received: by 2002:a05:600c:3c89:b0:439:9ba1:5f7e with SMTP id 5b1f17b1804b1-439aebb2b9dmr18708365e9.21.1740140591200; Fri, 21 Feb 2025 04:23:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IH0QupHHnVtVEJcYunHZyS4po6F8CyMlLkfnJFkrKRsEqrEoTWdQDqjuT7zqGuqMerrOuEO2w== X-Received: by 2002:a05:600c:3c89:b0:439:9ba1:5f7e with SMTP id 5b1f17b1804b1-439aebb2b9dmr18708015e9.21.1740140590788; Fri, 21 Feb 2025 04:23:10 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f69b3ca41sm3596761f8f.27.2025.02.21.04.23.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:10 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:08 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Marcel Apfelbaum Subject: [PULL 11/41] pcie_sriov: Release VFs failed to realize Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Akihiko Odaki 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 Message-Id: <20250116-reuse-v20-9-7cb370606368@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- 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 f1993bc553..db087bb933 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -93,6 +93,8 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, vf->exp.sriov_vf.vf_number = i; if (!qdev_realize(&vf->qdev, bus, errp)) { + object_unparent(OBJECT(vf)); + object_unref(vf); unparent_vfs(dev, i); return false; } From patchwork Fri Feb 21 12:23:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985362 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B1CF1C021B3 for ; Fri, 21 Feb 2025 12:28:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS3y-00058p-BF; Fri, 21 Feb 2025 07:23:26 -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 1tlS3w-0004yR-Ah for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS3u-00074a-KY for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140602; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=24rqHDBhYxq+r3JiigQWSM+5Xsth2RmvFt80HgCZtbE=; b=gbu2micGNTF+jXyOtibBRe5LdNOJNy2Q+qXa+MJ84/Blt5Hk9MZahEHCBBIC2Scpv18C2B vxr4WZaWDNRYRHKXY4ngeBMQrUf6gPHPYPCQZGPN2pVII5GB7O75AERw3f97jhbyhg1GY4 8Gt2/JbGfc2RhNWVOixfqtdm+82vZYA= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-310-b-nXkWR_NZGqstCkbU_lBw-1; Fri, 21 Feb 2025 07:23:18 -0500 X-MC-Unique: b-nXkWR_NZGqstCkbU_lBw-1 X-Mimecast-MFC-AGG-ID: b-nXkWR_NZGqstCkbU_lBw_1740140597 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4399c5ba9e4so10937205e9.3 for ; Fri, 21 Feb 2025 04:23:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140597; x=1740745397; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=24rqHDBhYxq+r3JiigQWSM+5Xsth2RmvFt80HgCZtbE=; b=I3qm2tKq4lES+e0hdmOxUkRamRF7ZlHt4ZROHO+9aQfid/UgLqoxszqvayIJvQzIz4 U7CEXYXYl0PoW3/kXhDm0FdmdRmhSokcLiVqjkpaWNDyrUQAnvx/HnT4kEhQlzcTuV2l YxCnnYKHJ6DBdxZjKi8N0LpLUnvewDJztzd9TkCjyMy3Jd5666O057fALpvCMuFq85HK YrMkxJqx9Bzg2epXhOgy2GOBm+vCZg/ojU/O2pI5IWAh2gTqeAaGD46FQeYpSNgyYRLD XVtyeNcrpKkwNABv3lW5VwamQrXE5fOevwaQroHZVGNRXz5AQTulj7p1KSguUYSCYSh/ 2Hug== X-Gm-Message-State: AOJu0YzpV8Cy41OAjfom/nN5u7QJXobVd2WkCp2WTyXhLdRz+A/87L1J uqjm6V7a47UTYYtP6SMRhu4mP6IdbQSmJ+A1U6Xn2t0cK32UKthtS0TqK12t5Zb3J1T7vpOCR3t Q0sl6f5eRhzBQHRBkHZcgBatIazqmrq1SDDvhuIRwVV17zBZjMGKrhoWa8gBIF7Dx+KoswPTaaV 6pMBD9TLe5SFkNHENxqEiMwjr54TkmCw== X-Gm-Gg: ASbGncv/Fu3ahAYmY9JKEL/U/g85Jb7i1q+DRPvKJj8/KliIPW2RnbV4yyXfo9LcpOF kMp7vmp8psjwjOJeqtbaNBsoJt9G9cstkDLovj1SRMvQJNkWijxrSzkZD66aZSSddGqmthSyZ20 uB61+nlTojbmK6py++qlFq4alDQQ7uxV7B1R/wyuzwQkxONpER0+EZWiq931xmBmNIN3GDYX8Qj J+9BiNLijJGx62U0guCJ7kz/3pXRuCS4nAPSK9y6rJ6ro2rUsh0EdmA7L1buaPcCu2pfTkjOQo2 fFE8cg== X-Received: by 2002:a05:600c:4f84:b0:439:a5e6:73ff with SMTP id 5b1f17b1804b1-439ae1f1592mr25822035e9.17.1740140596711; Fri, 21 Feb 2025 04:23:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGo9/AQqo1o07mTu78YKKF3QoTM2iQJnYI73eu657am8xueKpwPzz3H475IpZC1SdFg6W549g== X-Received: by 2002:a05:600c:4f84:b0:439:a5e6:73ff with SMTP id 5b1f17b1804b1-439ae1f1592mr25821745e9.17.1740140596297; Fri, 21 Feb 2025 04:23:16 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f259f771dsm23064139f8f.81.2025.02.21.04.23.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:15 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:11 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Marcel Apfelbaum Subject: [PULL 12/41] pcie_sriov: Remove num_vfs from PCIESriovPF Message-ID: <5e7dd17e43486f41d4f88dbefd7219f0524f424c.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Akihiko Odaki num_vfs is not migrated so use PCI_SRIOV_CTRL_VFE and PCI_SRIOV_NUM_VF instead. Signed-off-by: Akihiko Odaki Message-Id: <20250116-reuse-v20-10-7cb370606368@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/pci/pcie_sriov.h | 1 - hw/pci/pcie_sriov.c | 38 ++++++++++++++++++++++++++----------- hw/pci/trace-events | 2 +- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/include/hw/pci/pcie_sriov.h b/include/hw/pci/pcie_sriov.h index 70649236c1..5148c5b77d 100644 --- a/include/hw/pci/pcie_sriov.h +++ b/include/hw/pci/pcie_sriov.h @@ -16,7 +16,6 @@ #include "hw/pci/pci.h" typedef 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 */ } PCIESriovPF; diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index db087bb933..69609c112e 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -51,7 +51,6 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, pcie_add_capability(dev, PCI_EXT_CAP_ID_SRIOV, 1, offset, PCI_EXT_CAP_SRIOV_SIZEOF); dev->exp.sriov_cap = offset; - dev->exp.sriov_pf.num_vfs = 0; dev->exp.sriov_pf.vf = NULL; pci_set_word(cfg + PCI_SRIOV_VF_OFFSET, vf_offset); @@ -188,29 +187,28 @@ static void register_vfs(PCIDevice *dev) assert(sriov_cap > 0); num_vfs = pci_get_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF); - if (num_vfs > pci_get_word(dev->config + sriov_cap + PCI_SRIOV_TOTAL_VF)) { - return; - } trace_sriov_register_vfs(dev->name, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), num_vfs); for (i = 0; i < num_vfs; i++) { pci_set_enabled(dev->exp.sriov_pf.vf[i], true); } - dev->exp.sriov_pf.num_vfs = num_vfs; + + pci_set_word(dev->wmask + sriov_cap + PCI_SRIOV_NUM_VF, 0); } static void unregister_vfs(PCIDevice *dev) { - uint16_t num_vfs = dev->exp.sriov_pf.num_vfs; + uint8_t *cfg = dev->config + dev->exp.sriov_cap; uint16_t i; trace_sriov_unregister_vfs(dev->name, PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn), num_vfs); - for (i = 0; i < num_vfs; i++) { + PCI_FUNC(dev->devfn)); + for (i = 0; i < pci_get_word(cfg + PCI_SRIOV_TOTAL_VF); i++) { pci_set_enabled(dev->exp.sriov_pf.vf[i], false); } - dev->exp.sriov_pf.num_vfs = 0; + + pci_set_word(dev->wmask + dev->exp.sriov_cap + PCI_SRIOV_NUM_VF, 0xffff); } void pcie_sriov_config_write(PCIDevice *dev, uint32_t address, @@ -236,6 +234,17 @@ void pcie_sriov_config_write(PCIDevice *dev, uint32_t address, } else { unregister_vfs(dev); } + } else if (range_covers_byte(off, len, PCI_SRIOV_NUM_VF)) { + uint8_t *cfg = dev->config + sriov_cap; + uint8_t *wmask = dev->wmask + sriov_cap; + uint16_t num_vfs = pci_get_word(cfg + PCI_SRIOV_NUM_VF); + uint16_t wmask_val = PCI_SRIOV_CTRL_MSE | PCI_SRIOV_CTRL_ARI; + + if (num_vfs <= pci_get_word(cfg + PCI_SRIOV_TOTAL_VF)) { + wmask_val |= PCI_SRIOV_CTRL_VFE; + } + + pci_set_word(wmask + PCI_SRIOV_CTRL, wmask_val); } } @@ -252,6 +261,8 @@ void pcie_sriov_pf_reset(PCIDevice *dev) unregister_vfs(dev); pci_set_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF, 0); + pci_set_word(dev->wmask + sriov_cap + PCI_SRIOV_CTRL, + PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE | PCI_SRIOV_CTRL_ARI); /* * Default is to use 4K pages, software can modify it @@ -298,7 +309,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; @@ -306,5 +317,10 @@ PCIDevice *pcie_sriov_get_vf_at_index(PCIDevice *dev, int n) uint16_t pcie_sriov_num_vfs(PCIDevice *dev) { - return dev->exp.sriov_pf.num_vfs; + uint16_t sriov_cap = dev->exp.sriov_cap; + uint8_t *cfg = dev->config + sriov_cap; + + return sriov_cap && + (pci_get_word(cfg + PCI_SRIOV_CTRL) & PCI_SRIOV_CTRL_VFE) ? + pci_get_word(cfg + PCI_SRIOV_NUM_VF) : 0; } diff --git a/hw/pci/trace-events b/hw/pci/trace-events index 19643aa8c6..e98f575a9d 100644 --- a/hw/pci/trace-events +++ b/hw/pci/trace-events @@ -14,7 +14,7 @@ msix_write_config(char *name, bool enabled, bool masked) "dev %s enabled %d mask # hw/pci/pcie_sriov.c sriov_register_vfs(const char *name, int slot, int function, int num_vfs) "%s %02x:%x: creating %d vf devs" -sriov_unregister_vfs(const char *name, int slot, int function, int num_vfs) "%s %02x:%x: Unregistering %d vf devs" +sriov_unregister_vfs(const char *name, int slot, int function) "%s %02x:%x: Unregistering vf devs" sriov_config_write(const char *name, int slot, int fun, uint32_t offset, uint32_t val, uint32_t len) "%s %02x:%x: sriov offset 0x%x val 0x%x len %d" # pcie.c From patchwork Fri Feb 21 12:23:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985387 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 84B65C021B5 for ; Fri, 21 Feb 2025 12:32:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS5A-0000lG-DS; Fri, 21 Feb 2025 07:24:40 -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 1tlS53-0000Md-Ro for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS51-0007DV-SP for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140671; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=2JcyUMGxDlcrXYgVkAaUWu6KNUElDakyOBWHSKnyH28=; b=fMY/cdsLIJPUISzWySV4VJhgQxGC02hb6ZsHHP2MjeM+OHdBN9/rYur6LVA8i5xztxzlvC wsCOvptVZ4Vw/rvGt1JPDAYaZReXy+SStYQQBE6k/mRhLXH3FzA+/NBdhZX3Tp1OloKiGY hcRO5fdGMRIXXV6WZv6OFt8cmAiTrFY= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-601-6n3ak-6NPi-Kb_q0-Bmg-g-1; Fri, 21 Feb 2025 07:23:21 -0500 X-MC-Unique: 6n3ak-6NPi-Kb_q0-Bmg-g-1 X-Mimecast-MFC-AGG-ID: 6n3ak-6NPi-Kb_q0-Bmg-g_1740140600 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4399c5ba9e4so10937375e9.3 for ; Fri, 21 Feb 2025 04:23:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140599; x=1740745399; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2JcyUMGxDlcrXYgVkAaUWu6KNUElDakyOBWHSKnyH28=; b=XJddo16RdiBhjsOIEZ9HSiPAl9z8jMINYqTQW4v7pq4pHGy6mazzgsFl8kCHBaQc4t pnqq2BvHrjBdBj0UxzAJbLBgLzIecKm/WxTap5HtQWdjRZCvkmWghQl6FcGn2bK0qsfw b02E3QpUYzOohRtLa7Ewzs6qs5xFttcBTb+KMqFBoS98lZgD5O95demYUBd5hSLlZ0Mb Kc1/5UkK97xIzi5PXYrwqdZfOG0vhTo8XwyfbvuV0qzgGEy4BBJ7HyePELCC2O3XYf13 3tnUV/rQHOEWBkiOuQRHxOc3t7zgKnpETSeZYu+pWKug5jHTa/yWkKcE0KBJ6NOZWn2v RCnA== X-Gm-Message-State: AOJu0YwPvXuZXysUpWnMbA9ywXxAQmDTZlSc/aiLyngp5obB4unUGaOD pS3WsqSk5nOsGqpVcqhjB+j+Ov5Fj4BKsiWrbvfQ7NAKhSFcF8TuNGoSnjOykwelGvvVYNEN2UD t0LOSguTFBQMdLbqgMG8Wegv3wMiUJimA3h+m0PRtFTINHezd7Nhd6Bqm8Ke4YmsH8T2rnkPrzo vK30yy8H7HDs5Ngry9yqxPucoOeIxw0g== X-Gm-Gg: ASbGncshQZhnauSGeirIADUtRxxNeBiTXm+PI6/Hl/oGtUNPkuvSkyRtgVN38aQ+nAa cszs29RB3XgrK3qiuGzkSUckUxWpNpYa6AfRwrYIqICATBhJzo5G/mKSUWMX5iPetxpeOmQOlBb iactsKBGD6+D9LY2Yg+ZjDgxK16qCi6oWpmWcofTFSzqcDXOYpXlX3jusVKG0Hi8TENPfiWVvxa Lpbv+xQvPxcMv6IhAmJOistIyyu5LYP98fLaS/91z8ars5R7hnZdMDONbVzKqExsUY0WwEbkJ80 kdbzGQ== X-Received: by 2002:a05:600c:3d8c:b0:439:9496:17e9 with SMTP id 5b1f17b1804b1-439ae36d34bmr20372555e9.8.1740140599256; Fri, 21 Feb 2025 04:23:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IHu7XyLONuH1jkZt2HcsELssL6ffpIsFOwb9hXXYNdK1mOm+9HV1v6Q23UZmGZ4iQWGYha/LQ== X-Received: by 2002:a05:600c:3d8c:b0:439:9496:17e9 with SMTP id 5b1f17b1804b1-439ae36d34bmr20372365e9.8.1740140598919; Fri, 21 Feb 2025 04:23:18 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b0371db0sm15474995e9.37.2025.02.21.04.23.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:18 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:16 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Marcel Apfelbaum Subject: [PULL 13/41] pcie_sriov: Register VFs after migration Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Akihiko Odaki 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 Message-Id: <20250116-reuse-v20-11-7cb370606368@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- 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 5148c5b77d..c5d2d318d3 100644 --- a/include/hw/pci/pcie_sriov.h +++ b/include/hw/pci/pcie_sriov.h @@ -57,6 +57,8 @@ void pcie_sriov_pf_add_sup_pgsize(PCIDevice *dev, uint16_t opt_sup_pgsize); void pcie_sriov_config_write(PCIDevice *dev, uint32_t address, uint32_t val, int len); +void pcie_sriov_pf_post_load(PCIDevice *dev); + /* Reset SR/IOV */ void pcie_sriov_pf_reset(PCIDevice *dev); diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 3e29b30d55..69a1b8c298 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -803,10 +803,17 @@ static bool migrate_is_not_pcie(void *opaque, int version_id) return !pci_is_express((PCIDevice *)opaque); } +static int pci_post_load(void *opaque, int version_id) +{ + pcie_sriov_pf_post_load(opaque); + return 0; +} + const VMStateDescription vmstate_pci_device = { .name = "PCIDevice", .version_id = 2, .minimum_version_id = 1, + .post_load = pci_post_load, .fields = (const VMStateField[]) { VMSTATE_INT32_POSITIVE_LE(version_id, PCIDevice), VMSTATE_BUFFER_UNSAFE_INFO_TEST(config, PCIDevice, diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index 69609c112e..1eb4358256 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -248,6 +248,13 @@ void pcie_sriov_config_write(PCIDevice *dev, uint32_t address, } } +void pcie_sriov_pf_post_load(PCIDevice *dev) +{ + if (dev->exp.sriov_cap) { + register_vfs(dev); + } +} + /* Reset SR/IOV */ void pcie_sriov_pf_reset(PCIDevice *dev) From patchwork Fri Feb 21 12:23:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985366 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5D3FCC021AA for ; Fri, 21 Feb 2025 12:29:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS44-0005RF-Aj; Fri, 21 Feb 2025 07:23: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 1tlS41-0005MZ-Q8 for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS40-000751-6J for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140607; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vVk3p3HEep2LyPnlOovtQs5KCaYeb3tyVgIY2zzDrbw=; b=JbQkl58x0gOei1g+BTXdnn8T2sIuDY5FnTqx+E/VjIq1Hn3iBWR31isyZ9XYMDWl1DC+wb +33llT3Tf33bEN4YTqO3hGatdvBwt64yfgCiMM1YvKZEH3FKNExjkBgNNxUuIvahT8fonE 34uWcZt+jwLeAj9VmcxQ1Fz19CsPtC8= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-78-nGSEFI0FMl6MNVwitmIo1Q-1; Fri, 21 Feb 2025 07:23:26 -0500 X-MC-Unique: nGSEFI0FMl6MNVwitmIo1Q-1 X-Mimecast-MFC-AGG-ID: nGSEFI0FMl6MNVwitmIo1Q_1740140605 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43995bff469so22355325e9.2 for ; Fri, 21 Feb 2025 04:23:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140604; x=1740745404; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vVk3p3HEep2LyPnlOovtQs5KCaYeb3tyVgIY2zzDrbw=; b=RUWlVl3lLstytF9M78RMIfPkcMaJlVWJALBEWlgqgGxfEqUs7HEMy9t0HNUgY/Eybi 0POUPcnI9L5+Yp+Ply3KNsTBD6zV72180BZmwZCdZqvgw03syB2GiiK60+a99Lkqqq7v tGXnDJQ/PdNY7+i44r8sw0kebRWclQKmf2XTPsfPiHh/Xwul6bGyKFD/Pxgj5S9Own3V eoMIw0+I9vgenBYe5FACFOBw3VRYpec5cxiXq0tHuXyXJdMQVrwuMo3qkhIwY085o5ia LJ2EkuJi7zA8GN+txisv0p6NUd3YAxqqFgKvrs+n/Ni1UaaWpvXs9j2tuQw4uj5hP0ax GCvg== X-Gm-Message-State: AOJu0Yy8Iuzcda0DjWDqf/kEXMuR9+TpVs8TCyiCO85cDY0ewnhVJz7c xyREPKD+ejNYxi3NK4t5YE96b56wlsjCI7TZpz57mCl9nCN5I5Fq0gwzl2xu6NmtWwtvLykvcE4 UDxgKhdAq0cPiGUw33AZAGHn+9oSLoxuDJt7mxRyp6GDfmTrbnXARjqIT9zZs+TmcyT+k7Avlyg I6uADt9kYe4z1OhFzezYFXYpZjy2Lcjw== X-Gm-Gg: ASbGncuAE2R6fOt6YXM9XzmbRqeL23+nOEcdAZswyAOoEjX5P1RnQjtaIUUBtrqlW3E LaVkhica9OFEjPaFTxz5IR+ep9thTwIPYjvqFbPqtakAGVx/rFvw36P4PVxDvggdUup71IIVUl6 9Pxr4EoToaXS8mDMv7SKNH//cLlhIt2ThdbcCPpK6dK5XRqCGM5USxQgA0fbTo3vxjonr+gXUFM GO0j+GVTUCGiIchkgkT/LVGcZc0F1EfXAJW9juo6xYFtqzpqdfJLwZpWGZk3iScPiWOcV+hL1+d JE66kQ== X-Received: by 2002:a05:600c:358c:b0:439:84ba:5760 with SMTP id 5b1f17b1804b1-439aeae1c8bmr23195015e9.5.1740140604437; Fri, 21 Feb 2025 04:23:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IE7dZXy/S/F+QfB+XB0iaRszV02y5v1dVz9dhh8IXaoCTwnbIMIBkhRjQXTIxb1MVLGBGUMtA== X-Received: by 2002:a05:600c:358c:b0:439:84ba:5760 with SMTP id 5b1f17b1804b1-439aeae1c8bmr23194645e9.5.1740140603941; Fri, 21 Feb 2025 04:23:23 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce435sm16117715e9.3.2025.02.21.04.23.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:22 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:19 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Nicholas Piggin , Akihiko Odaki , Fabiano Rosas , Laurent Vivier , Paolo Bonzini Subject: [PULL 14/41] qtest/libqos/pci: Do not write to PBA memory Message-ID: <9e837c961a883392f8c4707a8d3d2e6c6aa793b6.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Nicholas Piggin The PCI Local Bus Specification says the result of writes to MSI-X PBA memory is undefined. QEMU implements them as no-ops, so remove the pointless write from qpci_msix_pending(). Signed-off-by: Nicholas Piggin Message-Id: <20250117172244.406206-2-npiggin@gmail.com> Reviewed-by: Akihiko Odaki Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/qtest/libqos/pci.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/qtest/libqos/pci.c b/tests/qtest/libqos/pci.c index b23d72346b..a59197b992 100644 --- a/tests/qtest/libqos/pci.c +++ b/tests/qtest/libqos/pci.c @@ -328,8 +328,6 @@ bool qpci_msix_pending(QPCIDevice *dev, uint16_t entry) g_assert(dev->msix_enabled); pba_entry = qpci_io_readl(dev, dev->msix_pba_bar, dev->msix_pba_off + off); - qpci_io_writel(dev, dev->msix_pba_bar, dev->msix_pba_off + off, - pba_entry & ~(1 << bit_n)); return (pba_entry & (1 << bit_n)) != 0; } From patchwork Fri Feb 21 12:23:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7528FC021AA for ; Fri, 21 Feb 2025 12:24:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS47-0005VU-S9; Fri, 21 Feb 2025 07:23:35 -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 1tlS44-0005RR-Bf for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS42-00075N-SQ for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aBBtVaw1c6M0PAlbeQ2HLOqmT0Z/NhHMcRyXtUTwOIA=; b=IhBhVpuxXhrMmCQHBRnaCcASLbg3dSlSuD8WxSK6gFloCKVftGvuG/lZMwMjwgb9pLA3RK 12KA2MD/xKcNj+bjSrSIgEcUGIhDRKA1QoH6B5JyH2h2eFr7OhIqIpFXiWPjXdLBF2E1aQ UJF2pUddzE+zrwZRmPInhLP7nTgxIPo= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-104-ARkWdfcHNcGqD0AgIxqPtA-1; Fri, 21 Feb 2025 07:23:29 -0500 X-MC-Unique: ARkWdfcHNcGqD0AgIxqPtA-1 X-Mimecast-MFC-AGG-ID: ARkWdfcHNcGqD0AgIxqPtA_1740140608 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-38f2c0aa6d6so1468654f8f.0 for ; Fri, 21 Feb 2025 04:23:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140607; x=1740745407; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aBBtVaw1c6M0PAlbeQ2HLOqmT0Z/NhHMcRyXtUTwOIA=; b=dWpU7szLcbRuu/fMCh16u59JofwOnDrGSGm5mUZg9rs88+KxhW/rwUvP5tbjewcxvI sB/9ut1GXh1aB7JxwyHiyL9T5BjAAu9vfQvRp9AnsjL4NFHA8XHdD6DKocW+muWztw0f +Er5O00gJKID+r8jx3YRDUadV7iDu4yDXNQDCKzG2FQw1q2ualytnUaNKRo8GH0W6QLd PgG5Fzx9zfTvUeA1vOWRW+8xeRECiRhx3Z2zcfEZHtsoMoPqW0cGS6hT4usfeLHmgdvZ pmUIBs0gEIqsjEpxWCPlqdwQmVDYYJyJsyNK/R0mpI5B+Psf3/GR2YkQwbyqrDHFz30v +hsw== X-Gm-Message-State: AOJu0Yxx+K8rWG2f7pd1Jzu4vScrzC+paPUymao0DnxD1TXuHeJh9PDD /HKEKhSMx3v7TB4W8IFzNn2xS1uyOpd1ojPg6dQSn4sPBFkiXsSJwNGahI+SzjrP5kbUt3ueO+4 wcap2roXvEo3Xqhin1uzHVZCP+ZmKYgIqi+ENXwi8G6eSvICGZrvLnGr0va2gvbr/c2w2BhfnG1 tBAOY1Ue1eOhFf8/6AT9MRJRvueowX/w== X-Gm-Gg: ASbGncurWV1LWOExyHt+4cNCA2cNtWu4YNaNG+hhgSWJ4tmlR0AVxXzQJqrl7ABiUBR rzoJHhFBRMTjRD1ImH+pwvMBsUxLe+9aWIh6PxyGyQpZddJb3tK2jIzffBVRgRErdD0Q80L02kh OC7F+NGQSsfGKo+EUsXXLfCeVVjQslP8ANow9YiKbiPOAM9U70SNpPJiOkDRO03JcAuEjq+a0ve xRPkluaMVKuTAyy9+4SzQYFM6+3qVZ+B8E9cY2TbWXGGmQ8+XxD7vZBI/lC4sEOOjR3RxfLl46G zT5jfw== X-Received: by 2002:a5d:47c3:0:b0:38d:d59c:c9d6 with SMTP id ffacd0b85a97d-38f61611400mr6413998f8f.21.1740140607484; Fri, 21 Feb 2025 04:23:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGAuxjCF3ZwRwvuDWVK/vDileVZBX1yVedjgRj6UPj+N98Yk4D2pum8pMv3NfyhVP6GacQS1g== X-Received: by 2002:a5d:47c3:0:b0:38d:d59c:c9d6 with SMTP id ffacd0b85a97d-38f61611400mr6413967f8f.21.1740140607019; Fri, 21 Feb 2025 04:23:27 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b0372124sm15539275e9.39.2025.02.21.04.23.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:26 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:24 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Nicholas Piggin , Marcel Apfelbaum , Dmitry Fleytman , Sriram Yagnaraman , Phil Dennis-Jordan , Philippe =?utf-8?q?Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Akihiko Odaki Subject: [PULL 15/41] hw/pci/msix: Warn on PBA writes Message-ID: <44ed44aefec571041fe3b3a8b6849613a74b520a.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Nicholas Piggin Of the MSI-X PBA pending bits, the PCI Local Bus Specification says: Software should never write, and should only read Pending Bits. If software writes to Pending Bits, the result is undefined. Log a GUEST_ERROR message if the PBA is written to by software. Cc: Marcel Apfelbaum Cc: Dmitry Fleytman Cc: Sriram Yagnaraman Signed-off-by: Nicholas Piggin Message-Id: <20250117172842.406338-2-npiggin@gmail.com> Reviewed-by: Phil Dennis-Jordan Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Akihiko Odaki Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/pci/msix.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/pci/msix.c b/hw/pci/msix.c index 57ec7084a4..66f27b9d71 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -15,6 +15,7 @@ */ #include "qemu/osdep.h" +#include "qemu/log.h" #include "hw/pci/msi.h" #include "hw/pci/msix.h" #include "hw/pci/pci.h" @@ -260,6 +261,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr, static void msix_pba_mmio_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) { + PCIDevice *dev = opaque; + + qemu_log_mask(LOG_GUEST_ERROR, + "PCI [%s:%02x:%02x.%x] attempt to write to MSI-X " + "PBA at 0x%" FMT_PCIBUS ", ignoring.\n", + pci_root_bus_path(dev), pci_dev_bus_num(dev), + PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), + addr); } static const MemoryRegionOps msix_pba_mmio_ops = { From patchwork Fri Feb 21 12:23:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985350 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E3B5EC021AA for ; Fri, 21 Feb 2025 12:24:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS4A-0005cW-Ra; Fri, 21 Feb 2025 07:23:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS48-0005WQ-Hp for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS46-00075r-SX for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140614; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=xnNXa72bifXcpK8QJLo0EWswUxugR/C5FGlEBsch7ws=; b=ELpyVVa88uPrINZnSAUOUOZJyCaNTP/oKTTI4ZlY0sfr6OwO0QrYq40KG3/vDjRem3pcEW rN7wyYbJwNrmGOh/xTcugYDrPuTVoCZcbd6H/zG43WNHlgZZHZxuPzEoRhmxHsk5ydKu59 O5oap2k0Acvap6IKeyQNiR1PwyGMmJM= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-t36RtbtlM1qoFTIKA6HkDA-1; Fri, 21 Feb 2025 07:23:33 -0500 X-MC-Unique: t36RtbtlM1qoFTIKA6HkDA-1 X-Mimecast-MFC-AGG-ID: t36RtbtlM1qoFTIKA6HkDA_1740140612 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-438da39bb69so14023785e9.0 for ; Fri, 21 Feb 2025 04:23:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140611; x=1740745411; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=xnNXa72bifXcpK8QJLo0EWswUxugR/C5FGlEBsch7ws=; b=dq4/xCF+fT6xBhKz5uGaPR7sdozwM4EPfdRqCMuFMQ42GbnSfkdRcx3YrNWs3jRiY6 I77ZCffq7MTZ0c/pHNcGEy6m9GbEpRdW13DqsqTd43HSXIl0NrTtiEZrRRPxCc96/F/X q8qsYgzI8hbGet6g+xhJPJTSEjRFrI2XJxhcV3jC5MK75tWRkdLQVSqDln9sVb926wHw +Ytm7R4ZVrHlhUCem10AfzqvBS5CsoRW3qiQo9+S+F19H3STY5zK9bOL6fWbzZh0i9+s GMnCRLWo/NFpqV89zzGbo4IkEi1wZUe+YUk09Wtchhn4Awh+nUEv5c1tsfZFbOg4K4xt a4SQ== X-Gm-Message-State: AOJu0YwKB/OqYj2t+buMcAy9NMboM7LcROUYZ7xFhTWxrMAjY4Yex4Ib 3x3CXjIAAGw0Vj2oz7LdCqFPQaMivDGEtq+3i+ziopxzYrvZvds8afy3Ay2G6RuGrP6u/J7vgFS qKThL2a6wJiWmWJEEHXAL7CoSxCLHt6izMX7SehOgDnmFNi1Of/tWwjY2+m6DgTD1EFDNg707xx W//+knnvpEvrqSZxnYuly9AZmkXD6gJg== X-Gm-Gg: ASbGncuXlpIhbumQ4zr+/giR+DN4cUpPOHXTMzwHbEeakaZWDDXyovIVWJyzagunTKp Ui1ENuqJTvDK3nzvdO7mfwCZTf6mAKAMaIpboEI+eaD3p7LLabS4wpkpfX3Rur8Q5dEszwluGFn l/bBIPMsLTmj5lXgm/ecrcPolKxnPuHTURSduDkBLrRvm/mt3Jp9rqhF0ulatBE64QDNjfJxjQj P5F1WunF8iLMUsuw2eRIafAXAID7MWNAKL4qFF6MsZec+mh73U6h+0zPQIXpdlf5NP5XdCySoub KaoM1Q== X-Received: by 2002:a05:600c:548b:b0:439:608b:c4ad with SMTP id 5b1f17b1804b1-439ae1d86f5mr25351455e9.3.1740140611442; Fri, 21 Feb 2025 04:23:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGDbq97x6aFlTWlSIbhg9SmwjTBWHz30pZ4y0G1zP18OVqZf0kp6NRu67BnsWJsLe8gKVrJcQ== X-Received: by 2002:a05:600c:548b:b0:439:608b:c4ad with SMTP id 5b1f17b1804b1-439ae1d86f5mr25351205e9.3.1740140611091; Fri, 21 Feb 2025 04:23:31 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f259d5923sm23451118f8f.74.2025.02.21.04.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:30 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:27 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Nicholas Piggin , Phil Dennis-Jordan , Akihiko Odaki , Marcel Apfelbaum Subject: [PULL 16/41] hw/pci: Assert a bar is not registered multiple times Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Nicholas Piggin Nothing should be doing this, but it doesn't get caught by pci_register_bar(). Add an assertion to prevent misuse. Signed-off-by: Nicholas Piggin Message-Id: <20250117172842.406338-3-npiggin@gmail.com> Reviewed-by: Phil Dennis-Jordan Signed-off-by: Nicholas Piggin Reviewed-by: Phil Dennis-Jordan Reviewed-by: Akihiko Odaki Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/pci/pci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 69a1b8c298..1d42847ef0 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1398,6 +1398,7 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num, assert(hdr_type != PCI_HEADER_TYPE_BRIDGE || region_num < 2); r = &pci_dev->io_regions[region_num]; + assert(!r->size); r->addr = PCI_BAR_UNMAPPED; r->size = size; r->type = type; From patchwork Fri Feb 21 12:23:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985358 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91EAFC021AA for ; Fri, 21 Feb 2025 12:26:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS4M-00063q-MO; Fri, 21 Feb 2025 07:23: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 1tlS4G-0005kn-1V for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4C-00076H-VH for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140619; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=2aojgtrZ6esJVqQc5qz1w/JX0CqBotUbbq3GahOTG6Q=; b=SkouCYVG3H3YWsXtxXRxkKZIhT5lCtgD4IeWYmscEJPopp5scBlu3/lfrNSYEoqBaS1ugk xlo54DGPCs2PzR+3UgfAQlET6aW/Gx4q7nuXVZ9Re+pca7whSJ7otpczicZddIeEB6QByJ Q9Q3aujo/Z0AlS0Dmj0RlYjZ/BjFzK0= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-258-ouY0Gy2cM9-ox3TMoLT5_Q-1; Fri, 21 Feb 2025 07:23:37 -0500 X-MC-Unique: ouY0Gy2cM9-ox3TMoLT5_Q-1 X-Mimecast-MFC-AGG-ID: ouY0Gy2cM9-ox3TMoLT5_Q_1740140615 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4399a5afc72so10245365e9.3 for ; Fri, 21 Feb 2025 04:23:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140615; x=1740745415; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2aojgtrZ6esJVqQc5qz1w/JX0CqBotUbbq3GahOTG6Q=; b=X2s4xShe60NytFAP/QfSHxANyvym18lvVvEQLZAqH7fmB+aRvyHvArL927oCmYDl7b stHnrIeX8OJMsV0zzDf8MtT9X9SIyaPxnQYI4ey9FBnSbGH4CG7h0NzNTS8i0VmxKcHI qy6piyWcEF5DeLxUH89KnX1xKniHnulE42rp1P4VXKt2HDo/4nYPIOehJVsyajQwEvdr DSw9UqsOQp91DJ4Mbvg28nwf1pWtanJenEKKiatB7CcEciA0ShNcLG16yD52BMUTn1Tf gi4FCS7BMWt/Bh04PJl2xJtMmtWutATXV1yx+VQZ2R5I1oH4hLMH+uXYb9np33k00MnN MCkA== X-Gm-Message-State: AOJu0YxZVXLu0PdeOqftd9aRrDi5e9sfNJ/9zZRGZCFBjmKrz3T85mbx FgCsdr53ZFNZCVATCLeh7mQbyQ+tHP4t+4Qf4ffiuo5QzWfVMS+nl4+bXEgri1nTWkfSFczfyAB vPQ7y6hY1M2rwjwABzSrKD6NolxorzEalTywDFX6R1YkCs8spdgHH91cKareellAs9knCWhQQKw jmCSdmdTbyCnRiuUJYTIoxKPsi6vZJ6Q== X-Gm-Gg: ASbGnctWstMWm7N98pK0IbmCAw04WnJbqDP1sNe6lZxsHWInfQOm2pqFwpp6ymiaROJ UhtASi+XRsk1v1RePUreswuTpHNtDlVuUdsgfE8AmBuPtVmRC2QbKlosybsTI6mQec0JGBKDIcT /8DQzSa4EmvbMyy1NF4IosvFsWxnYEjdGLCx9CVTt9Ee96W8I/v36b6zW82xbdeXPWqG5jjGgFx FjP0/zqoO1tl95s3fEa6a6BGev+qO4gDaQemAE3bNXwKT9lezIZyNVrXpeOF8CUHarV2/UiXMFg 31H4ng== X-Received: by 2002:a05:600c:4ece:b0:439:9274:8203 with SMTP id 5b1f17b1804b1-439aeae0543mr22381885e9.6.1740140614679; Fri, 21 Feb 2025 04:23:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfuQquOBWW5A7tkUGJ2yxc0B2Zlc5AbnX9fc0iisrFfMRf341iMJ09qib/W/y0hD1nrJrhMQ== X-Received: by 2002:a05:600c:4ece:b0:439:9274:8203 with SMTP id 5b1f17b1804b1-439aeae0543mr22381575e9.6.1740140614165; Fri, 21 Feb 2025 04:23:34 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce41dsm16307815e9.1.2025.02.21.04.23.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:33 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:31 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Thomas Huth , Akihiko Odaki , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PULL 17/41] hw/i386/pc: Fix crash that occurs when introspecting TYPE_PC_MACHINE machines Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Thomas Huth QEMU currently crashes when you try to inspect the machines based on TYPE_PC_MACHINE for their properties: $ echo '{ "execute": "qmp_capabilities" } { "execute": "qom-list-properties","arguments": { "typename": "pc-q35-10.0-machine"}}' \ | ./qemu-system-x86_64 -M pc -qmp stdio {"QMP": {"version": {"qemu": {"micro": 50, "minor": 2, "major": 9}, "package": "v9.2.0-1070-g87e115c122-dirty"}, "capabilities": ["oob"]}} {"return": {}} Segmentation fault (core dumped) This happens because TYPE_PC_MACHINE machines add a machine_init- done_notifier in their instance_init function - but instance_init of machines are not only called for machines that are realized, but also for machines that are introspected, so in this case the listener is added for a q35 machine that is never realized. But since there is already a running pc machine, the listener function is triggered immediately, causing a crash since it was not for the right machine it was meant for. Such listener functions must never be installed from an instance_init function. Let's do it from pc_basic_device_init() instead - this function is called from the MachineClass->init() function instead, i.e. guaranteed to be only called once in the lifetime of a QEMU process. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2779 Signed-off-by: Thomas Huth Message-Id: <20250117192106.471029-1-thuth@redhat.com> Reviewed-by: Akihiko Odaki Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/pc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index b46975c8a4..85b8a76455 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1241,6 +1241,9 @@ void pc_basic_device_init(struct PCMachineState *pcms, /* Super I/O */ pc_superio_init(isa_bus, create_fdctrl, pcms->i8042_enabled, pcms->vmport != ON_OFF_AUTO_ON, &error_fatal); + + pcms->machine_done.notify = pc_machine_done; + qemu_add_machine_init_done_notifier(&pcms->machine_done); } void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus) @@ -1714,9 +1717,6 @@ static void pc_machine_initfn(Object *obj) if (pcmc->pci_enabled) { cxl_machine_init(obj, &pcms->cxl_devices_state); } - - pcms->machine_done.notify = pc_machine_done; - qemu_add_machine_init_done_notifier(&pcms->machine_done); } static void pc_machine_reset(MachineState *machine, ResetType type) From patchwork Fri Feb 21 12:23:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985352 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AAFF8C021AA for ; Fri, 21 Feb 2025 12:24:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS4K-0005ue-Ge; Fri, 21 Feb 2025 07:23:48 -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 1tlS4G-0005km-0J for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4D-00076L-DZ for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140620; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BVlPptZNlm2Qp+Na4geuSvUcMsY7gT+KX61fq3waWVU=; b=iQN5dSsY9XkSHBOoIMX7DGS6rBIE96Fd87ZPn4O4nyjcWJTYyglT3i8jaCN8ciC+3zxoyD 9+PG0mbgNtTpT/7CRAgSxw/K9XJxSYO2licb7P5AdS9KNKryEI7B6m5u9fSiUzdb7ErVr9 ey56NnBC9JHi7HOv3bwMuxc5+0i4a5Q= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-418-soFATn_pPxKQDYVnr7IeQA-1; Fri, 21 Feb 2025 07:23:39 -0500 X-MC-Unique: soFATn_pPxKQDYVnr7IeQA-1 X-Mimecast-MFC-AGG-ID: soFATn_pPxKQDYVnr7IeQA_1740140618 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-38f4bf0d5faso1190909f8f.0 for ; Fri, 21 Feb 2025 04:23:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140618; x=1740745418; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=BVlPptZNlm2Qp+Na4geuSvUcMsY7gT+KX61fq3waWVU=; b=o2hSHjf02M7Cx5BS4ZuKoTKHEIu6GJWWomK2UySqSShJwp4Gpas/vTOszPfnak4c0R SntIafZODRFcXV87SvlIW1yiIojqt+s7a0v+VGNTqS93DiSTcMLqPXHuTVo/fbLSOZZU OejtLvGQNvOgUpQmRydccnxpRLxwRYrqRBdiLT3cJ+ABemQr8/rIFTj3+xwRI7yu9qQZ 4rLjvwDNMmmATT/5DPXx5os7FLeXlxSNkRn9buyK+PhLOpJI9xYkokIktnkGjzKuhgWF +wM0ZjkoJ0yzW9V+LvcMHgPplgrN2FWadMkP4BHPM7bYZcgQOaCbEkwaWDuhy9e77aNB dt1Q== X-Gm-Message-State: AOJu0YyqDLigGNzgVRJH2NTGjP3ptCOuNXJ4XkeIntNmTLO6nyjg6aGq PZC8qHiW2eKyt2FB+hOYTBSTSnAwXMMzfDzpd1nuQzOLegbqBD67By8tebQJicddGjcKMqnaRV9 2sOowz64/RsuG1mCDkP7rQ8xc9is4KhJRbMRbdG99yLHN1AmDGPcKRgwCNRjM/QqZrSTJfa+nxp E4HwDQaiZ7tK4BK/esFDMpqUUgfaxvjQ== X-Gm-Gg: ASbGncuX936TKGMJz3f+uxyALQ+33nNpdCziZXfLLw4EyfbL44Z6WFSjVvTe5eOZOUk HyFphORACrlui7Yp6gE/5rcf8KzYnYGkrUNf2mcQDbYIoUoefuwFA+2x8oB8fN35Vq3wsqZ/C1f RfiAGfa+FF9Wvz8R8sVbzXEYJqNpdCzEPdkzer4D/cYSWc73GGVTwULe1dSJDPyBBQHj4M+NqbL a+hKMv2YyUEJhq2Dh9vJKRMeQsdlxOn4XJqc9qB4ru7dMR78BOxRO58cm9NyFRMw4162j+6lDZi CtvZNw== X-Received: by 2002:a05:6000:1f8f:b0:38f:452f:9fa9 with SMTP id ffacd0b85a97d-38f6e753bbamr2421668f8f.2.1740140617776; Fri, 21 Feb 2025 04:23:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHdqyGBgHa+Vk9exghcMJlYeGh7AIcRbWUs1CO90fDwyzVXwO0REgi1xmkmoUlfO7mzg18jwQ== X-Received: by 2002:a05:6000:1f8f:b0:38f:452f:9fa9 with SMTP id ffacd0b85a97d-38f6e753bbamr2421643f8f.2.1740140617327; Fri, 21 Feb 2025 04:23:37 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f259d5e92sm23595672f8f.66.2025.02.21.04.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:36 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:34 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Thomas Huth , Sergio Lopez , Akihiko Odaki , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PULL 18/41] hw/i386/microvm: Fix crash that occurs when introspecting the microvm machine Message-ID: <38ef383073b8ee59d598643160f206a19a46237f.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Thomas Huth QEMU currently crashes when you try to inspect the properties of the microvm machine: $ echo '{ "execute": "qmp_capabilities" } { "execute": "qom-list-properties","arguments": { "typename": "microvm-machine"}}' | \ ./qemu-system-x86_64 -qmp stdio {"QMP": {"version": {"qemu": {"micro": 50, "minor": 2, "major": 9}, "package": "v9.2.0-1072-g60af367187-dirty"}, "capabilities": ["oob"]}} {"return": {}} qemu-system-x86_64: ../qemu/hw/i386/acpi-microvm.c:250: void acpi_setup_microvm(MicrovmMachineState *): Assertion `x86ms->fw_cfg' failed. Aborted (core dumped) This happens because the microvm machine adds a machine_done (and a powerdown_req) notifier in their instance_init function - however, the instance_init of machines are not only called for machines that are realized, but also for machines that are introspected, so in this case the listener is added for a microvm machine that is never realized. And since there is already a running machine, the listener function is triggered immediately, causing a crash since it was not for the right machine it was meant for. Such listener functions must never be installed from an instance_init function. Let's do it from microvm_machine_state_init() instead - this function is the MachineClass->init() function instead, i.e. guaranteed to be only called once in the lifetime of a QEMU process. Since the microvm_machine_done() and microvm_powerdown_req() were defined quite late in the microvm.c file, we have to move them now also earlier, so that we can get their function pointers from microvm_machine_state_init() without having to introduce a separate prototype for those functions earlier. Reviewed-by: Sergio Lopez Signed-off-by: Thomas Huth Message-Id: <20250123204708.1560305-1-thuth@redhat.com> Reviewed-by: Akihiko Odaki Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/microvm.c | 66 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c index a8d354aabe..d0a236c74f 100644 --- a/hw/i386/microvm.c +++ b/hw/i386/microvm.c @@ -451,11 +451,44 @@ static HotplugHandler *microvm_get_hotplug_handler(MachineState *machine, return NULL; } +static void microvm_machine_done(Notifier *notifier, void *data) +{ + MicrovmMachineState *mms = container_of(notifier, MicrovmMachineState, + machine_done); + X86MachineState *x86ms = X86_MACHINE(mms); + + acpi_setup_microvm(mms); + dt_setup_microvm(mms); + fw_cfg_add_e820(x86ms->fw_cfg); +} + +static void microvm_powerdown_req(Notifier *notifier, void *data) +{ + MicrovmMachineState *mms = container_of(notifier, MicrovmMachineState, + powerdown_req); + X86MachineState *x86ms = X86_MACHINE(mms); + + if (x86ms->acpi_dev) { + Object *obj = OBJECT(x86ms->acpi_dev); + AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj); + adevc->send_event(ACPI_DEVICE_IF(x86ms->acpi_dev), + ACPI_POWER_DOWN_STATUS); + } +} + static void microvm_machine_state_init(MachineState *machine) { MicrovmMachineState *mms = MICROVM_MACHINE(machine); X86MachineState *x86ms = X86_MACHINE(machine); + /* State */ + mms->kernel_cmdline_fixed = false; + + mms->machine_done.notify = microvm_machine_done; + qemu_add_machine_init_done_notifier(&mms->machine_done); + mms->powerdown_req.notify = microvm_powerdown_req; + qemu_register_powerdown_notifier(&mms->powerdown_req); + microvm_memory_init(mms); x86_cpus_init(x86ms, CPU_VERSION_LATEST); @@ -581,31 +614,6 @@ static void microvm_machine_set_auto_kernel_cmdline(Object *obj, bool value, mms->auto_kernel_cmdline = value; } -static void microvm_machine_done(Notifier *notifier, void *data) -{ - MicrovmMachineState *mms = container_of(notifier, MicrovmMachineState, - machine_done); - X86MachineState *x86ms = X86_MACHINE(mms); - - acpi_setup_microvm(mms); - dt_setup_microvm(mms); - fw_cfg_add_e820(x86ms->fw_cfg); -} - -static void microvm_powerdown_req(Notifier *notifier, void *data) -{ - MicrovmMachineState *mms = container_of(notifier, MicrovmMachineState, - powerdown_req); - X86MachineState *x86ms = X86_MACHINE(mms); - - if (x86ms->acpi_dev) { - Object *obj = OBJECT(x86ms->acpi_dev); - AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj); - adevc->send_event(ACPI_DEVICE_IF(x86ms->acpi_dev), - ACPI_POWER_DOWN_STATUS); - } -} - static void microvm_machine_initfn(Object *obj) { MicrovmMachineState *mms = MICROVM_MACHINE(obj); @@ -617,14 +625,6 @@ static void microvm_machine_initfn(Object *obj) mms->isa_serial = true; mms->option_roms = true; mms->auto_kernel_cmdline = true; - - /* State */ - mms->kernel_cmdline_fixed = false; - - mms->machine_done.notify = microvm_machine_done; - qemu_add_machine_init_done_notifier(&mms->machine_done); - mms->powerdown_req.notify = microvm_powerdown_req; - qemu_register_powerdown_notifier(&mms->powerdown_req); } GlobalProperty microvm_properties[] = { From patchwork Fri Feb 21 12:23:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985361 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6EF92C021B3 for ; Fri, 21 Feb 2025 12:28:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS4P-0006Is-8P; Fri, 21 Feb 2025 07:23: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 1tlS4J-0005ud-R2 for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4G-00076a-2J for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140623; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BmV9gn8eSSrkunnR1tfz+dt6M43eXodM12I1RMZXJ08=; b=VeCcMGUdiZJfh4pWADDbE+huoe15BxkQs3CGzhd8mE6f+AOVl8DoNKmASHwlbAS2LVtsnk VNft9rCCXEkFQ5szPAH19mZP9HAwmfAnUb/wk/cCb7Bnva28cTNCPdIDPHg/rL1am28WJ0 9JknAgFDPq5jLJiH3PUhmWNYFul30Bk= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-389-NkHcyx8dPXep6i9G9M482A-1; Fri, 21 Feb 2025 07:23:42 -0500 X-MC-Unique: NkHcyx8dPXep6i9G9M482A-1 X-Mimecast-MFC-AGG-ID: NkHcyx8dPXep6i9G9M482A_1740140621 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43995bff469so22357015e9.2 for ; Fri, 21 Feb 2025 04:23:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140621; x=1740745421; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=BmV9gn8eSSrkunnR1tfz+dt6M43eXodM12I1RMZXJ08=; b=ZU3UTSEydbN36/oLZJ/GiweaEjTEX5W+ADw08BpNm3meLwMicgwY2gcLWebE9cBf8D XVgGL0d1hjW9zW6DNYj3drvHHRzcm8WV0sJetu3o4SFHBNHqg8YiUq0nFirCozCNnqxz WZzSVZlMRvVRViz4tGoyKJ2QsAV1jPkqd6tjJQ6Jt6SPHtywSy6vbS95yOxST/H9F0vu lNJFgtjAMHI9d78cZXzhXJye8DLzhri4MbmUqNoNjEHTqA6c5/KU05/kkrEG/jYzCenP Mi8AKSGqSdgBm66uxLG1wfS4+mILkwWN2qbJzI/jfbaNBlTXCiiV0kAHIJqwTvye54ef yfUg== X-Gm-Message-State: AOJu0YxJwbmVT7I5VTOBc1ySnrX/UEXaLWm5xUZC1XQMCrHA6WZpQdnQ Zj0HEmenYO3f+0nBR3Es6PTXnDxXXnccxOuXUYcGIEiTkDAsVLfDnw1NJzjsGHCT333rWAYC+zI b4ZkveBHMSvOGoIjxi3lFQzn1Dg1Uwxnlm1towcDGxgGemt2hsFjUXemKpRhSWs1oT2ZpzV0ID7 srVRMuEj/HsFJ6sj6+S9OSLsftRiXcPw== X-Gm-Gg: ASbGncuFddbd0lhspw5QSvafZ2cGBVfQXRUQc7zV5b/lXuYrGtNFuQhip6q/+o/KvLm 6BjYutxsYkq+X7/Qzej/p3hopxZq2JVPI51ETrQCYGzkqLpEDejDTtJFpMASFZd5CiHiI+0nIgk HNAtsAm1FZLpJYEecJim08o8fpvDZGzhKWlK05Cf1nsGgiMtsI6PP/j/Crt1Fj0Fb3/1PvVLyTB WUtbUUz+neS1u7N0jo3PnHfMjSfMxN+JKCzeYYhq84rFRgfjwcdCJW1oUsVxRo8jBAqayB8ektG 6zZwqw== X-Received: by 2002:a05:600c:3149:b0:439:969e:d80f with SMTP id 5b1f17b1804b1-439aebe6b9bmr22320015e9.31.1740140620794; Fri, 21 Feb 2025 04:23:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IECyBszWZ+AKTWGIva+rALczMJpq1e0vnMnV+nYXnKg6amFBca/x+CsyF1OZcMfkdhkG1aLKg== X-Received: by 2002:a05:600c:3149:b0:439:969e:d80f with SMTP id 5b1f17b1804b1-439aebe6b9bmr22319755e9.31.1740140620405; Fri, 21 Feb 2025 04:23:40 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02d624bsm15703225e9.15.2025.02.21.04.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:39 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:37 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Thomas Huth , Fabiano Rosas , Stefano Garzarella , Laurent Vivier , Paolo Bonzini Subject: [PULL 19/41] tests/qtest/vhost-user-test: Use modern virtio for vhost-user tests Message-ID: <14998e50c3638b07946ebe5972a327cc26e9f03c.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Thomas Huth All other vhost-user tests here use modern virtio, too, so let's adjust the vhost-user-net test accordingly. Signed-off-by: Thomas Huth Message-Id: <20250203124346.169607-1-thuth@redhat.com> Reviewed-by: Fabiano Rosas Reviewed-by: Stefano Garzarella Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/qtest/vhost-user-test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index 76d142a158..bd977ef28d 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -1043,7 +1043,8 @@ static void test_multiqueue(void *obj, void *arg, QGuestAllocator *alloc) static uint64_t vu_net_get_features(TestServer *s) { - uint64_t features = 0x1ULL << VHOST_F_LOG_ALL | + uint64_t features = 0x1ULL << VIRTIO_F_VERSION_1 | + 0x1ULL << VHOST_F_LOG_ALL | 0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES; if (s->queues > 1) { From patchwork Fri Feb 21 12:23:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985354 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 27A48C021B5 for ; Fri, 21 Feb 2025 12:24:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS4R-0006RP-QR; Fri, 21 Feb 2025 07:23:55 -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 1tlS4N-0006A9-Jb for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4L-000775-1v for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140628; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/kmJLONp2OhkpfuMOLSYnuEY7cqZckWFV/n/C9H76MQ=; b=Upxms1YHOWG1HTX7YPWUx2MTcZGX8qcEK1fUFi+qU3usn/hiJi7D2L6cJ9Vp92vRaVY4v3 zYXr0vZJ1nIet28uXhRzPNFw6U2OqJtnxWJrT5eAm827ise80flb9OGM/eRBieDYSHR2Cd jI6OMGlk3vUhrVvkfTkR8SZZB24itTE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-554-x8ONGrvdNPWE5i3WXFvBGA-1; Fri, 21 Feb 2025 07:23:45 -0500 X-MC-Unique: x8ONGrvdNPWE5i3WXFvBGA-1 X-Mimecast-MFC-AGG-ID: x8ONGrvdNPWE5i3WXFvBGA_1740140624 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-38f2c0aa6d6so1468734f8f.0 for ; Fri, 21 Feb 2025 04:23:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140624; x=1740745424; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/kmJLONp2OhkpfuMOLSYnuEY7cqZckWFV/n/C9H76MQ=; b=r1x5dmhzirera+fKUDS2IZ9maeewJp1epaHKgQ2pG3zWyH2uFgMhQdNao4AwdxFZ43 cmRVXXZWZ5iR4eHd24SAyU9ti7wAsONLavFWilbaXyt4g0ZW99msJFXBzOmBch6Qv4Ul gIDqfrfOYYWWV74rDiSGuxy2nmptcKVrC4EIkgsDIqfcK6KraQ0XBJtpKMdqZNpHKC/r tx0hiN3Xh9LTfWbUzrVL8koyBklphZv9vj1mj+4wTK+OeSeLg8F53q1gs7UQSGFfVOr4 2hCe3PVc1056CUFbl0lf8LgUhXd9arZBkJ/Z1UOBSD2ovDbuHGQnIUjRNOPeRoT8SPaw bpxQ== X-Gm-Message-State: AOJu0YyqLepf9EWory3z+ZzLEfL09lj61juEV52sjC71xJkeA9WKi0wG eNRKSeymjrxbTUqumsZ9r+AjBX5FvKjiEgWHtmKrNeI8zp+tVMMFaxbx0nobwdpe6d/oMmlah7w /gcfuyTGEIVoQGWtXwxJB1cpWaiD9e+Qw86PQULioOkxNaW7xcOEWPUjBgIGchNBgIip8nGJkYj jBBBZSRjzuHW6/gtOn4YLg7f8yg9Jx1A== X-Gm-Gg: ASbGnctylFVvilgCN9q7jxq59CCoYsDpHf120TjbsWcMfHT4AgSt3CWLlEpAP7lZZI1 3nefuEN+6woB7FCfIR/9GNbK1yy7N9FINn8IokZQTKlTiDv9kjyqNF3VHdkLxwiYZAXAk8boPI2 InAHYTGQhFjMgO579en1luPezI6oz0QdhbPPtMLoI4IdE+tYyGVxhOE/o/qpwcb+227/yvTxqvk 4Oe8mfeYpcuabarCsq8JkiqHKxDJea3P0lGBL+5E3bhgzQGFlM1MgpBZFdOkKW+CRlIBSkNBEy7 B3o9HA== X-Received: by 2002:a5d:584a:0:b0:38d:e0a9:7e5e with SMTP id ffacd0b85a97d-38f614991f2mr6180249f8f.6.1740140623766; Fri, 21 Feb 2025 04:23:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IHFDL+zlxYKdIihf74iUeeE4fGEfxbyh9v74/Wv9N8hj3ncytNmdrEaDkcUWhVFnarzzBvS7g== X-Received: by 2002:a5d:584a:0:b0:38d:e0a9:7e5e with SMTP id ffacd0b85a97d-38f614991f2mr6180221f8f.6.1740140623274; Fri, 21 Feb 2025 04:23:43 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce435sm16127735e9.3.2025.02.21.04.23.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:42 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:40 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Li Zhijian , Jonathan Cameron , Fan Ni Subject: [PULL 20/41] hw/cxl: Introduce CXL_T3_MSIX_VECTOR enumeration Message-ID: <8f90a54cfafe8c93a71930a96a63ccbd074f4142.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Li Zhijian Introduce the `CXL_T3_MSIX_VECTOR` enumeration to specify MSIX vector assignments specific to the Type 3 (T3) CXL device. The primary goal of this change is to encapsulate the MSIX vector uses that are unique to the T3 device within an enumeration, improving code readability and maintenance by avoiding magic numbers. This organizational change allows for more explicit references to each vector’s role, thereby reducing the potential for misconfiguration. It also modified `mailbox_reg_init_common` to accept the `msi_n` parameter, reflecting the new MSIX vector setup. This pertains to the T3 device privately; other endpoints should refrain from using it, despite its public accessibility to all of them. Signed-off-by: Li Zhijian Signed-off-by: Jonathan Cameron Message-Id: <20250203161908.145406-2-Jonathan.Cameron@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/cxl/cxl_device.h | 4 ++-- hw/cxl/cxl-device-utils.c | 12 +++++------- hw/cxl/switch-mailbox-cci.c | 4 +++- hw/mem/cxl_type3.c | 20 ++++++++++++++------ 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index 561b375dc8..3a0ee7e8e7 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -264,8 +264,8 @@ void cxl_device_register_block_init(Object *obj, CXLDeviceState *dev, typedef struct CXLType3Dev CXLType3Dev; typedef struct CSWMBCCIDev CSWMBCCIDev; /* Set up default values for the register block */ -void cxl_device_register_init_t3(CXLType3Dev *ct3d); -void cxl_device_register_init_swcci(CSWMBCCIDev *sw); +void cxl_device_register_init_t3(CXLType3Dev *ct3d, int msi_n); +void cxl_device_register_init_swcci(CSWMBCCIDev *sw, int msi_n); /* * CXL r3.1 Section 8.2.8.1: CXL Device Capabilities Array Register diff --git a/hw/cxl/cxl-device-utils.c b/hw/cxl/cxl-device-utils.c index 035d034f6d..52ad1e4c3f 100644 --- a/hw/cxl/cxl-device-utils.c +++ b/hw/cxl/cxl-device-utils.c @@ -352,10 +352,8 @@ static void device_reg_init_common(CXLDeviceState *cxl_dstate) } } -static void mailbox_reg_init_common(CXLDeviceState *cxl_dstate) +static void mailbox_reg_init_common(CXLDeviceState *cxl_dstate, int msi_n) { - const uint8_t msi_n = 9; - /* 2048 payload size */ ARRAY_FIELD_DP32(cxl_dstate->mbox_reg_state32, CXL_DEV_MAILBOX_CAP, PAYLOAD_SIZE, CXL_MAILBOX_PAYLOAD_SHIFT); @@ -382,7 +380,7 @@ static void memdev_reg_init_common(CXLDeviceState *cxl_dstate) cxl_dstate->memdev_status = memdev_status_reg; } -void cxl_device_register_init_t3(CXLType3Dev *ct3d) +void cxl_device_register_init_t3(CXLType3Dev *ct3d, int msi_n) { CXLDeviceState *cxl_dstate = &ct3d->cxl_dstate; uint64_t *cap_h = cxl_dstate->caps_reg_state64; @@ -398,7 +396,7 @@ void cxl_device_register_init_t3(CXLType3Dev *ct3d) device_reg_init_common(cxl_dstate); cxl_device_cap_init(cxl_dstate, MAILBOX, 2, CXL_DEV_MAILBOX_VERSION); - mailbox_reg_init_common(cxl_dstate); + mailbox_reg_init_common(cxl_dstate, msi_n); cxl_device_cap_init(cxl_dstate, MEMORY_DEVICE, 0x4000, CXL_MEM_DEV_STATUS_VERSION); @@ -408,7 +406,7 @@ void cxl_device_register_init_t3(CXLType3Dev *ct3d) CXL_MAILBOX_MAX_PAYLOAD_SIZE); } -void cxl_device_register_init_swcci(CSWMBCCIDev *sw) +void cxl_device_register_init_swcci(CSWMBCCIDev *sw, int msi_n) { CXLDeviceState *cxl_dstate = &sw->cxl_dstate; uint64_t *cap_h = cxl_dstate->caps_reg_state64; @@ -423,7 +421,7 @@ void cxl_device_register_init_swcci(CSWMBCCIDev *sw) device_reg_init_common(cxl_dstate); cxl_device_cap_init(cxl_dstate, MAILBOX, 2, 1); - mailbox_reg_init_common(cxl_dstate); + mailbox_reg_init_common(cxl_dstate, msi_n); cxl_device_cap_init(cxl_dstate, MEMORY_DEVICE, 0x4000, 1); memdev_reg_init_common(cxl_dstate); diff --git a/hw/cxl/switch-mailbox-cci.c b/hw/cxl/switch-mailbox-cci.c index 65cdac6cc1..833b824619 100644 --- a/hw/cxl/switch-mailbox-cci.c +++ b/hw/cxl/switch-mailbox-cci.c @@ -17,10 +17,12 @@ #include "hw/qdev-properties.h" #include "hw/cxl/cxl.h" +#define CXL_SWCCI_MSIX_MBOX 3 + static void cswmbcci_reset(DeviceState *dev) { CSWMBCCIDev *cswmb = CXL_SWITCH_MAILBOX_CCI(dev); - cxl_device_register_init_swcci(cswmb); + cxl_device_register_init_swcci(cswmb, CXL_SWCCI_MSIX_MBOX); } static void cswbcci_realize(PCIDevice *pci_dev, Error **errp) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 0ae1704a34..ebc0ec536e 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -30,6 +30,14 @@ #include "hw/cxl/cxl.h" #include "hw/pci/msix.h" +/* type3 device private */ +enum CXL_T3_MSIX_VECTOR { + CXL_T3_MSIX_PCIE_DOE_TABLE_ACCESS = 0, + CXL_T3_MSIX_EVENT_START = 2, + CXL_T3_MSIX_MBOX = CXL_T3_MSIX_EVENT_START + CXL_EVENT_TYPE_MAX, + CXL_T3_MSIX_VECTOR_NR +}; + #define DWORD_BYTE 4 #define CXL_CAPACITY_MULTIPLIER (256 * MiB) @@ -843,7 +851,6 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp) ComponentRegisters *regs = &cxl_cstate->crb; MemoryRegion *mr = ®s->component_registers; uint8_t *pci_conf = pci_dev->config; - unsigned short msix_num = 10; int i, rc; uint16_t count; @@ -884,16 +891,17 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp) &ct3d->cxl_dstate.device_registers); /* MSI(-X) Initialization */ - rc = msix_init_exclusive_bar(pci_dev, msix_num, 4, NULL); + rc = msix_init_exclusive_bar(pci_dev, CXL_T3_MSIX_VECTOR_NR, 4, NULL); if (rc) { goto err_address_space_free; } - for (i = 0; i < msix_num; i++) { + for (i = 0; i < CXL_T3_MSIX_VECTOR_NR; i++) { msix_vector_use(pci_dev, i); } /* DOE Initialization */ - pcie_doe_init(pci_dev, &ct3d->doe_cdat, 0x190, doe_cdat_prot, true, 0); + pcie_doe_init(pci_dev, &ct3d->doe_cdat, 0x190, doe_cdat_prot, true, + CXL_T3_MSIX_PCIE_DOE_TABLE_ACCESS); cxl_cstate->cdat.build_cdat_table = ct3_build_cdat_table; cxl_cstate->cdat.free_cdat_table = ct3_free_cdat_table; @@ -908,7 +916,7 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp) if (rc) { goto err_release_cdat; } - cxl_event_init(&ct3d->cxl_dstate, 2); + cxl_event_init(&ct3d->cxl_dstate, CXL_T3_MSIX_EVENT_START); /* Set default value for patrol scrub attributes */ ct3d->patrol_scrub_attrs.scrub_cycle_cap = @@ -1202,7 +1210,7 @@ static void ct3d_reset(DeviceState *dev) pcie_cap_fill_link_ep_usp(PCI_DEVICE(dev), ct3d->width, ct3d->speed); cxl_component_register_init_common(reg_state, write_msk, CXL2_TYPE3_DEVICE); - cxl_device_register_init_t3(ct3d); + cxl_device_register_init_t3(ct3d, CXL_T3_MSIX_MBOX); /* * Bring up an endpoint to target with MCTP over VDM. From patchwork Fri Feb 21 12:23:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985384 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7F6DEC021AA for ; Fri, 21 Feb 2025 12:32:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS5d-0003Ty-Bl; Fri, 21 Feb 2025 07:25:10 -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 1tlS5Z-0003Gd-7F for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:25:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS5X-0007Gh-5Y for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:25:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140702; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=21MZvzcuowvqSXzQXl2K9YuO6KQY2fQmr4euw2anaeY=; b=PGfHx/39Br2NMlMKIG+sgtoVldWf7YSZRqdo9R8cv97PzesBmx8kVXv3ZS0oA/o1UTdBVP hNOnlbLVbSKm/YW8YU66+lPoqn93fnwXitiwq+T36NsWHM9sgoxxVkTQ+ycf3fO1cr+A5L 59SGnpFlpo0+t6FJaMNbHgu1QEo6y/c= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-352-PytxyZotMneRmvC2W6923Q-1; Fri, 21 Feb 2025 07:23:48 -0500 X-MC-Unique: PytxyZotMneRmvC2W6923Q-1 X-Mimecast-MFC-AGG-ID: PytxyZotMneRmvC2W6923Q_1740140627 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-38f32ac838cso1775796f8f.2 for ; Fri, 21 Feb 2025 04:23:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140626; x=1740745426; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=21MZvzcuowvqSXzQXl2K9YuO6KQY2fQmr4euw2anaeY=; b=EXf0dmXGq5d1RWBtPk3TqbCTJVTIsaJMZ0c5Fn7Cj0nAXtHFQ1EgjCfPF9qe2HDVOF PivIf8l9tF7fphsSz7KREnyNpAyTPa018m9jT8rjiOODGp1G/KKhzqr8D1iqoOmbO6RK QpTUI3x1qh8NpuVAsEwAYUEsyXkYjJOsHOqn1gSag0P5t5remXLDKm2s2BqW4CqMGJEM xfcVU8+fBFxpHevGLBlpVjbAMy6tmJzmA4O4HCtsULc+AD6GhHQ0Yewzp0K6IdGaOKks VkTkCzm49O+g/XpdghAuoaUKESEhKWIGeuiayIVaS5l/2N6bEyNlGr48/YQE6xa5zqbQ 8K7Q== X-Gm-Message-State: AOJu0YyYHqF9p/ZL8Y51Qhc12ntdowyapWDq/ztlVihfbp/sYM/KP4CV Gj7cpDiRBvBmXNnAhDA3L+PcNdqq16TQSuOKqerRbbe5gHEJQx/WxJ2uQou+okACFi2ZMaIIgLm nM+8m4kb6O+FSOdNZGzUnLHMWY9ucyil0zcp0PbEJvSvfZY4XTSErUPEmc7aTvxKCMPHj8Vv6h1 BCNJsymrWMEQQ9ghLQgaa58VHFwGgXqw== X-Gm-Gg: ASbGnct5OdTECNF64/1sJcw1VwZhHmQgDPJFIVSZngcNTJ0cDYKucYaff0GuRNrKIF1 +MzhQTIyjL3vPAi3BGrhXZpLf9lx6G6gesk+GgqOGQRDPccYzq2VkBeKtMWTIKZmjm+oq1JUNzN NcLqjVbhUH4JhkbvdL60aIVrc63E3R+pKEH6Q/WjeoNptAlWnyQxewUVzkzkfbq/YLbujMhk6MW dL1hDRR3Mk/iOkwkkpBE4PGsBUkwirBcx+tbd0mWhFXAx+NJpNt1bJREHsM5uCW85rSA8jCY8Rm cZClwQ== X-Received: by 2002:a05:6000:1f8f:b0:38d:d223:f8e6 with SMTP id ffacd0b85a97d-38f6e4c20damr2693644f8f.0.1740140626489; Fri, 21 Feb 2025 04:23:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IH2KGV9KW75NIzNkWG0SW6peFEkOFc/jU+KcSZPzdoAVv5xo2diToCCT3MD2+GZhM03uTHZcw== X-Received: by 2002:a05:6000:1f8f:b0:38d:d223:f8e6 with SMTP id ffacd0b85a97d-38f6e4c20damr2693617f8f.0.1740140626064; Fri, 21 Feb 2025 04:23:46 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f25915785sm23929271f8f.58.2025.02.21.04.23.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:45 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:43 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Li Zhijian , Jonathan Cameron , Fan Ni Subject: [PULL 21/41] hw/mem/cxl_type3: Add paired msix_uninit_exclusive_bar() call Message-ID: <0401c4328f4d18be540fd432c2bbacce4531d14f.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Li Zhijian msix_uninit_exclusive_bar() should be paired with msix_init_exclusive_bar() Ensure proper resource cleanup by adding the missing `msix_uninit_exclusive_bar()` call for the Type3 CXL device. Signed-off-by: Li Zhijian Signed-off-by: Jonathan Cameron Message-Id: <20250203161908.145406-3-Jonathan.Cameron@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/mem/cxl_type3.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index ebc0ec536e..4775aab0d6 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -944,6 +944,7 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp) err_release_cdat: cxl_doe_cdat_release(cxl_cstate); err_free_special_ops: + msix_uninit_exclusive_bar(pci_dev); g_free(regs->special_ops); err_address_space_free: if (ct3d->dc.host_dc) { @@ -967,6 +968,7 @@ static void ct3_exit(PCIDevice *pci_dev) pcie_aer_exit(pci_dev); cxl_doe_cdat_release(cxl_cstate); + msix_uninit_exclusive_bar(pci_dev); g_free(regs->special_ops); if (ct3d->dc.host_dc) { cxl_destroy_dc_regions(ct3d); From patchwork Fri Feb 21 12:23:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985364 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DB658C021B3 for ; Fri, 21 Feb 2025 12:28:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS4U-0006ay-6R; Fri, 21 Feb 2025 07:23:58 -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 1tlS4R-0006RO-52 for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4P-00077W-9C for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140632; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c79lvmIC7XDPg0zQTrgvrz5zU+cAN9dA2+2j0QFPSdk=; b=Flxpt4746WcjCc253L/Df3CT0ZV8OYmtNVm0auDyUfaN0i8B+ZTwNGTeD4s58pbDHFepld sVdQ+lqRV4CcPVl8/PC+wgBRMyEjq5lXrr50btJCV99NZjCZmySL0v4Xmc/A1nzww+WdZq HdROjyBIEzsn6IU7bOnyUNhN5SR6y8I= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-119-jA0_JEeyOIqs4NYyvnzHGw-1; Fri, 21 Feb 2025 07:23:51 -0500 X-MC-Unique: jA0_JEeyOIqs4NYyvnzHGw-1 X-Mimecast-MFC-AGG-ID: jA0_JEeyOIqs4NYyvnzHGw_1740140630 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-38f3bac2944so926905f8f.3 for ; Fri, 21 Feb 2025 04:23:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140629; x=1740745429; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=c79lvmIC7XDPg0zQTrgvrz5zU+cAN9dA2+2j0QFPSdk=; b=CfZISjmOHpKlfbXXYfN7/QU0u+YOa9dZ0c6ahqckC+iKqhEU1l7fIwNSoiaCMXQdm0 5sp6ogx50HjuD5HeKd6O5NKBb0C4uHD72Rw/mFEBcez0NhgSQCYahoOSej6WhcPHINUu zPAm+lm3XIkQ/1MBXWVMBwKM1hvhn3+nJs5WzSf60QlB/xRyQM7WMO6BjO1Ye6+ZTGdQ oG1ax/n+bjl8cji49BsCW8lpmBpg9qhTZDOIqxQbVELbLXfJjgJxSQSlbVJaGTqsB5Cs 4IAmybenlgqQ33eP7xTnM60vD/pgFyPeu3e/yLm1X2xYwGUNGMzljGSheLtcPbIERifd 3YVA== X-Gm-Message-State: AOJu0Yx85q+Gm0RwVcyrSi32uF1KZ0GqukBtVTC1d252ZFDOuQw+NZqk F/2DrM9dP3rN7LyebadZpKcjUXiel29hMbhtckq5MzDUjGsgtLPSjnRU7su2UvqgIMrIZSiglqw ROde0E8BsCdmcaLcbhO/frMETpCRd+uXZ12I20ksOTaR4elBTTJX1rRl0V1xInYGN9mOqbEqUVB F2T8b0bEjXiEafDEA8jOJSixqtYcxzvQ== X-Gm-Gg: ASbGncs/SKDdf5ijFWvYV8V5Asufju5hOg9DP9eP0WU8SJfGol7jmDfUFohOPP01tbn uXzuToxlEamrbGoBNKJUYF4mKG0arsYeqDKACIkv29B+jL7OK/e4/B8wVKKNEcAs7Y5H6fCI3/N b53DWhbrI9/Ft5ojk3S2kt38giiSmRQq0Ub2aC+MRwDhgC9wy594LS6CELhN3XUkV/ilYkHGxLJ 1gYz/k9FCCD8WCLXrDFF9yCQH8ENmM8MdexnaJrWN74HPdnr8Rr06sayrU90yJa5nolL6OQm26s YhAnBg== X-Received: by 2002:a5d:5f52:0:b0:38d:d387:166 with SMTP id ffacd0b85a97d-38f6f0b17e2mr2388945f8f.34.1740140629686; Fri, 21 Feb 2025 04:23:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IETYIuEHMaRoMdATYfo+tF0vwvnWwY+dv7D1Lu6nfQZJBD2wIWuRw/G0FlD/TkmWe8mw1DbCA== X-Received: by 2002:a5d:5f52:0:b0:38d:d387:166 with SMTP id ffacd0b85a97d-38f6f0b17e2mr2388922f8f.34.1740140629274; Fri, 21 Feb 2025 04:23:49 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f259d5ee2sm22963814f8f.80.2025.02.21.04.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:48 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:46 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Li Zhijian , Jonathan Cameron , Philippe =?utf-8?q?Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Fan Ni Subject: [PULL 22/41] hw/mem/cxl_type3: Fix special_ops memory leak on msix_init_exclusive_bar() failure Message-ID: <06953e7e5ea5e8fa0b7b704bdb66ab1e62f1f378.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Li Zhijian Address a memory leak issue by ensuring `regs->special_ops` is freed when `msix_init_exclusive_bar()` encounters an error during CXL Type3 device initialization. Additionally, this patch renames err_address_space_free to err_msix_uninit for better clarity and logical flow Signed-off-by: Li Zhijian Signed-off-by: Jonathan Cameron Message-Id: <20250203161908.145406-4-Jonathan.Cameron@huawei.com> Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/mem/cxl_type3.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 4775aab0d6..ff6861889b 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -893,7 +893,7 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp) /* MSI(-X) Initialization */ rc = msix_init_exclusive_bar(pci_dev, CXL_T3_MSIX_VECTOR_NR, 4, NULL); if (rc) { - goto err_address_space_free; + goto err_free_special_ops; } for (i = 0; i < CXL_T3_MSIX_VECTOR_NR; i++) { msix_vector_use(pci_dev, i); @@ -907,7 +907,7 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp) cxl_cstate->cdat.free_cdat_table = ct3_free_cdat_table; cxl_cstate->cdat.private = ct3d; if (!cxl_doe_cdat_init(cxl_cstate, errp)) { - goto err_free_special_ops; + goto err_msix_uninit; } pcie_cap_deverr_init(pci_dev); @@ -943,10 +943,10 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp) err_release_cdat: cxl_doe_cdat_release(cxl_cstate); -err_free_special_ops: +err_msix_uninit: msix_uninit_exclusive_bar(pci_dev); +err_free_special_ops: g_free(regs->special_ops); -err_address_space_free: if (ct3d->dc.host_dc) { cxl_destroy_dc_regions(ct3d); address_space_destroy(&ct3d->dc.host_dc_as); From patchwork Fri Feb 21 12:23:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985373 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DC5DDC021B5 for ; Fri, 21 Feb 2025 12:30:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS4X-0006tu-DU; Fri, 21 Feb 2025 07:24:01 -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 1tlS4V-0006lU-GQ for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4T-000783-QP for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:23:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140637; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cvBWmFUXdZkhnxIEnnyEww3jMhD10rJHEduWob1P8ko=; b=FeCZlR4ZTVhbT3x/wsXY4BB8NHwuqTn/HtX34BX2E3LtFNBxdzZU0lpmYKz0hugs6btrds GLfvZCwidl3d8p+a91g8DbxrWQ08sO6VaJgVYHDqOLDCyArTMO07g8hujcMpWTNiBu1n/z VXxH3DKrNi9n4aGYhKrQYELwlk//TOg= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-226-ZvWvn7_aOqmdbfvw94YhIA-1; Fri, 21 Feb 2025 07:23:54 -0500 X-MC-Unique: ZvWvn7_aOqmdbfvw94YhIA-1 X-Mimecast-MFC-AGG-ID: ZvWvn7_aOqmdbfvw94YhIA_1740140633 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4394b8bd4e1so10341555e9.0 for ; Fri, 21 Feb 2025 04:23:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140633; x=1740745433; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cvBWmFUXdZkhnxIEnnyEww3jMhD10rJHEduWob1P8ko=; b=udLBdeQk5dERLfZC3JQWfJRNIanG3t4eXaAAO+KZk57Cby2k+Wo93U2DjvCW4r6gtj 5WyNVQ/wTEWyjCcSW5DLeR+jHVyPpjuNl9dj2Z+rLqEzY8GUN642nEMSi1vpYqmL2KGC CAR0VuPVHTvCIvOJwM8PwkBO6mFjCxho87pNt/ilM36S0b3kS/KJG/rE9kr8OAmpS1DZ Z+Tx5ZydYJVctYyphDfeQtsMKrAWbCgu51PQ6BNIMZyY6hHrC1pNHkQGXRJsGtqATOAM b2w3XnPW8p3F+DHUtMxEKqoOEBJqvtBoSwAg0EDFzuoX16yF4ucQtYvQsfWMz3PPK3DN Blug== X-Gm-Message-State: AOJu0Ywmd2BeOeo/816nLErp4lm9YviuB6FlPttGAlZJmnfwWsgcntA9 We3ChJuAEmh/HJPwlY0RwBuseuP1/070BzOlkym4CVSNxafRBg+vvReJuP6xVitTT+4VqovguRn 9xHysDsRK0Vx9rsUmGTOWdjiczegGrzc4/gSPsLpM2vJErcPfNng2YDmtJ7YZepEBrCMiybEdnZ tmj8VivLQtj1BEaHVPyYclCguhjZ8acA== X-Gm-Gg: ASbGnctxYsT4DeURFeGTpYDLWiGwYXQHgGw71/3yjZPjgK0C6o85lZAaRDSfC+zGiYg KTXgv3rB8KtZeVD3q7qM5iOC9zlGZ1CMRmdx0lPBHIsi3RPPP57nqcrw6OPUeJulyXPK+HXpBQP maDRSH1xxWAcweMF4nRm2nVhx2cNKlbtAZTstz3pfgB/PYdFSdZnwUkxQPwcBE8/SwSJOpDlaSS jlSTLEuyrpYpk+cYEhMr5Zx6HDBAbPUS9sYVgvIWmwNWRjbRAwKxvf+dTkNR9WAi1eo+qyI+GHc A4AeSg== X-Received: by 2002:a05:600c:350a:b0:439:8e3e:b0d6 with SMTP id 5b1f17b1804b1-439aeb2ab04mr21261405e9.13.1740140632831; Fri, 21 Feb 2025 04:23:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXgxX+Us+Oq4NHZZ7PokBtBmgoOeq85WQiUNg/YON7wMRdu/OuvN5CwHTRnEPaU/P996S3+A== X-Received: by 2002:a05:600c:350a:b0:439:8e3e:b0d6 with SMTP id 5b1f17b1804b1-439aeb2ab04mr21261225e9.13.1740140632493; Fri, 21 Feb 2025 04:23:52 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02f24acsm15849555e9.21.2025.02.21.04.23.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:52 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:49 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Li Zhijian , Jonathan Cameron , Philippe =?utf-8?q?Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Fan Ni Subject: [PULL 23/41] hw/mem/cxl_type3: Ensure errp is set on realization failure Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Li Zhijian Simply pass the errp to its callee which will set errp if needed, to enhance error reporting for CXL Type 3 device initialization by setting the errp when realization functions fail. Previously, failing to set `errp` could result in errors being overlooked, causing the system to mistakenly treat failure scenarios as successful and potentially leading to redundant cleanup operations in ct3_exit(). Signed-off-by: Li Zhijian Signed-off-by: Jonathan Cameron Message-Id: <20250203161908.145406-5-Jonathan.Cameron@huawei.com> Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/mem/cxl_type3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index ff6861889b..d8b45f9bd1 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -891,7 +891,7 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp) &ct3d->cxl_dstate.device_registers); /* MSI(-X) Initialization */ - rc = msix_init_exclusive_bar(pci_dev, CXL_T3_MSIX_VECTOR_NR, 4, NULL); + rc = msix_init_exclusive_bar(pci_dev, CXL_T3_MSIX_VECTOR_NR, 4, errp); if (rc) { goto err_free_special_ops; } @@ -912,7 +912,7 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp) pcie_cap_deverr_init(pci_dev); /* Leave a bit of room for expansion */ - rc = pcie_aer_init(pci_dev, PCI_ERR_VER, 0x200, PCI_ERR_SIZEOF, NULL); + rc = pcie_aer_init(pci_dev, PCI_ERR_VER, 0x200, PCI_ERR_SIZEOF, errp); if (rc) { goto err_release_cdat; } From patchwork Fri Feb 21 12:23:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985372 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2F737C021AA for ; Fri, 21 Feb 2025 12:30:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS4c-00077d-Vm; Fri, 21 Feb 2025 07:24:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4Z-00072Z-LM for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4X-00078m-OB for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140641; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=htXrZRjJWy6jAGF8iFopXWg4nq3jbP1OW/HmNp/8W4o=; b=hZuCYZH6nCCNaIg3TRmGiJiuM34kNZUe6BUXK4z8ufcLRRuMOZOme9X/OeO9w7ywvvseJK mMbiKUJrlauJsj4X14c0ckgOXi2EfU1oO/ttigafnSZSCft9yt6M89xrORxpn03h5o/KbD BY9/1yO/n+gDOB3ULD62raRuFli6Oww= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-300-fEUT-AKfO3O5EDtbCDQ_Ng-1; Fri, 21 Feb 2025 07:23:59 -0500 X-MC-Unique: fEUT-AKfO3O5EDtbCDQ_Ng-1 X-Mimecast-MFC-AGG-ID: fEUT-AKfO3O5EDtbCDQ_Ng_1740140638 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-38f2c0aa6d6so1468820f8f.0 for ; Fri, 21 Feb 2025 04:23:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140637; x=1740745437; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=htXrZRjJWy6jAGF8iFopXWg4nq3jbP1OW/HmNp/8W4o=; b=JC/BwKszLyT03LEw6G4ZtRSERsJ3mCLKVnSkZvKud4vZQS47PMgBYrurpEx5Dd/mto bP/tIpD8LBKdZFOJte44374vSmmU6FV0G5IYaUF9NluytqIIVpSb5uSM5wjETaBtx12N uk9MWJ68IJKobQGEUeymnVRiPHq5sNk9C/3V9Kh92hRRpILPCD3Iq10Ao+XTUXWiDUII somNWKKh30opd20vBA5IiyJpEryOuh7dT6e9dvG94u3Y9GiU41Brqitt5K/MDTFJuby0 Mdzm6bPmNFiM321FPRpCkH9UhkbRwP8u6eQLAV2YzRU9CxT7iPU0yceVrXEdL343G+Y3 qDZA== X-Gm-Message-State: AOJu0YxWhDk2mVqkNcvvc1zWo1/iX2BYK8StxQ4aCSLw3hKH7h0MF/Ko Lz0AEsHUAohJSRknGLW0FsAj4tfequa28fRapGch2Kq1gsDMXWM35n9UZXzNYGcRKLqKIaTeLUJ jXC6KV2gV34/fEYkJGPqdBmuPJ3BcbQvrU2A2pNi6gV/TGJrJ/2nzhx2hM7YCbt1isynb7G+wFD UB/DvRsYiAFzzayeeeHRHDc8ilVVP8sg== X-Gm-Gg: ASbGncvfM4y9RZvx/15FE42bD/7klPSoEbA09Tg8HkD7pJZqep8vRTzM8bgpzIKJ722 h/W89lNxvje+L8g9+X8BDnO/sfc21e5N22lXxy73weHdaa3lzjTRZ7NY34lwCTAuxL6l2UQ5PN/ o6/LnAOHwl7VF0SLhofLSAvaJUpkRRLj/cm2OIQBFxHgQuWJ3sGeJwYdYF8qbVNPGtYpQqajPQU yqA9iI+zz+ozVA/P3H3IFeMGLe3OqB6lKi0CCSQN+kndJJAvOsaFugeSgY9+s0cxp5q07i4oToc 3zPHBw== X-Received: by 2002:a05:6000:18a9:b0:38d:e3fd:1a1c with SMTP id ffacd0b85a97d-38f6f515202mr2711229f8f.23.1740140637437; Fri, 21 Feb 2025 04:23:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IEk3MwthKuYt50N4X+gNJoPR6Bsnka87p4Sfpx0EuJrucprl8bLCQE5TlFazLFd1IIkjbKcrA== X-Received: by 2002:a05:6000:18a9:b0:38d:e3fd:1a1c with SMTP id ffacd0b85a97d-38f6f515202mr2711197f8f.23.1740140636971; Fri, 21 Feb 2025 04:23:56 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f25a0fe5esm23510599f8f.99.2025.02.21.04.23.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:56 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:52 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Yao Xingtao , Jonathan Cameron , Fan Ni Subject: [PULL 24/41] mem/cxl_type3: support 3, 6, 12 and 16 interleave ways Message-ID: <9ac2c42f43a536f53b3d4cad8a601ccb8640cbd8.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Yao Xingtao Since the kernel does not check the interleave capability, a 3-way, 6-way, 12-way or 16-way region can be create normally. Applications can access the memory of 16-way region normally because qemu can convert hpa to dpa correctly for the power of 2 interleave ways, after kernel implementing the check, this kind of region will not be created any more. For non power of 2 interleave ways, applications could not access the memory normally and may occur some unexpected behaviors, such as segmentation fault. So implements this feature is needed. Link: https://lore.kernel.org/linux-cxl/3e84b919-7631-d1db-3e1d-33000f3f3868@fujitsu.com/ Signed-off-by: Yao Xingtao Signed-off-by: Jonathan Cameron Message-Id: <20250203161908.145406-6-Jonathan.Cameron@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/cxl/cxl-component-utils.c | 9 +++++++-- hw/mem/cxl_type3.c | 15 +++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/hw/cxl/cxl-component-utils.c b/hw/cxl/cxl-component-utils.c index cd116c0401..473895948b 100644 --- a/hw/cxl/cxl-component-utils.c +++ b/hw/cxl/cxl-component-utils.c @@ -243,8 +243,13 @@ static void hdm_init_common(uint32_t *reg_state, uint32_t *write_msk, ARRAY_FIELD_DP32(reg_state, CXL_HDM_DECODER_CAPABILITY, INTERLEAVE_4K, 1); ARRAY_FIELD_DP32(reg_state, CXL_HDM_DECODER_CAPABILITY, POISON_ON_ERR_CAP, 0); - ARRAY_FIELD_DP32(reg_state, CXL_HDM_DECODER_CAPABILITY, 3_6_12_WAY, 0); - ARRAY_FIELD_DP32(reg_state, CXL_HDM_DECODER_CAPABILITY, 16_WAY, 0); + if (type == CXL2_TYPE3_DEVICE) { + ARRAY_FIELD_DP32(reg_state, CXL_HDM_DECODER_CAPABILITY, 3_6_12_WAY, 1); + ARRAY_FIELD_DP32(reg_state, CXL_HDM_DECODER_CAPABILITY, 16_WAY, 1); + } else { + ARRAY_FIELD_DP32(reg_state, CXL_HDM_DECODER_CAPABILITY, 3_6_12_WAY, 0); + ARRAY_FIELD_DP32(reg_state, CXL_HDM_DECODER_CAPABILITY, 16_WAY, 0); + } ARRAY_FIELD_DP32(reg_state, CXL_HDM_DECODER_CAPABILITY, UIO, 0); ARRAY_FIELD_DP32(reg_state, CXL_HDM_DECODER_CAPABILITY, UIO_DECODER_COUNT, 0); diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index d8b45f9bd1..6fffa21ead 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -1100,10 +1100,17 @@ static bool cxl_type3_dpa(CXLType3Dev *ct3d, hwaddr host_addr, uint64_t *dpa) continue; } - *dpa = dpa_base + - ((MAKE_64BIT_MASK(0, 8 + ig) & hpa_offset) | - ((MAKE_64BIT_MASK(8 + ig + iw, 64 - 8 - ig - iw) & hpa_offset) - >> iw)); + if (iw < 8) { + *dpa = dpa_base + + ((MAKE_64BIT_MASK(0, 8 + ig) & hpa_offset) | + ((MAKE_64BIT_MASK(8 + ig + iw, 64 - 8 - ig - iw) & hpa_offset) + >> iw)); + } else { + *dpa = dpa_base + + ((MAKE_64BIT_MASK(0, 8 + ig) & hpa_offset) | + ((((MAKE_64BIT_MASK(ig + iw, 64 - ig - iw) & hpa_offset) + >> (ig + iw)) / 3) << (ig + 8))); + } return true; } From patchwork Fri Feb 21 12:23:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985386 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1A615C021B3 for ; Fri, 21 Feb 2025 12:32:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS4o-0007XY-Nj; Fri, 21 Feb 2025 07:24:18 -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 1tlS4c-00077q-Tt for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4a-00079L-IO for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140643; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=efArqX3wxrFLzxI2BnYAIchHDFGDYnrZNrftosICqWI=; b=MpPgiqRaNsfloCCcj4Sl8kVaXns9Pt/CJ/NIuCN/wmBuoLAPeQGM9pPgw5V4+h4Z+0gMVp cfu1vXcpEcEa3+FiNslNjVkn2yovAZd7UpqvtFG0GCPFbsVwAopd5NsZ9qWWHiA7XcZrLc oens9hu89dczrGrIZT7uBJhvhtfy3T0= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-227-24l28EmYPciw52PTCe4LvA-1; Fri, 21 Feb 2025 07:24:02 -0500 X-MC-Unique: 24l28EmYPciw52PTCe4LvA-1 X-Mimecast-MFC-AGG-ID: 24l28EmYPciw52PTCe4LvA_1740140641 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-38f20b530dfso2862748f8f.3 for ; Fri, 21 Feb 2025 04:24:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140641; x=1740745441; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=efArqX3wxrFLzxI2BnYAIchHDFGDYnrZNrftosICqWI=; b=O+rvVp0Te7HXHyBYy9QJf/ewtGFp3bM4uVEl6DC+l4JkPIxhIH39pGtXqr485rLs32 SGJEiniZDO2zL/5lByjsl2E+JNPAIXO1mewi1Q7p8RdbzbFRKyRJO8QPf+h3i+fBxVHI 4jMVsXqnTEPAOL4EOeJfjyr5hGV9hImLr9lPCol/tY412Oa/GMEVGDh0CMKPQz2LkQ91 +A+GsLfUZ3sfTMW8zc6FLxtgVHEC9quL0CmksN0Zw2Hl0FDOhwIBYNQ7meoCctN4zxjY +fauyK6WE6GQKf2O0PPQ4u6qnfRsHuRFOxOi598Ujp8AGZwTLlAIkOPlnsqElgqWRqu+ vYkQ== X-Gm-Message-State: AOJu0YxTyCt8d3B9OmctVvP00oS0ybqi66yFtVLZX/fHkiGAqCBT0bb8 TId6zB4rEwBTs+ZGUcqoiMZxi+/YJpFoMGLmG+UQs6s+gk246ApaZvrT8Ij70axFKQeCfR18yZ1 fenv91t1H7jrME8r1/xWFaczPsrXn8sNWPQ27dwA311cwHGSsddleQ3K8g9NjzL45C/swXTKBYT 4A47PTXYujrH+smUmwkXF1+pJNqLu8lQ== X-Gm-Gg: ASbGnctS3So6Abt41bhsWwJjxFQxg5Kll/V+Df7p4V1BeVRWO3jd8tt03w77V9xqEe2 EqKt8pvu87PEk48p+/pSJBQL0ZlTgmkhLquy9au6T/zCv314h4gdGzL1wOxhonYtu6T1IXmhQz+ U5n1GNEcDuObt+xk2xGNO9GzR3lo1P+68fWwdLQ/PeO1kCpH/CxZ7JieAjthCwGRa+wd2vHFCeQ MaJP4o132JGQG46/Q1rRqBKRs06vPTudPnE2+GgvO+4zQIp61fDPfC5pOWXDJTATr/aX0fhu8pT i+Q33g== X-Received: by 2002:a5d:5985:0:b0:38d:d3e2:db32 with SMTP id ffacd0b85a97d-38f70783f03mr1630991f8f.7.1740140640579; Fri, 21 Feb 2025 04:24:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBcs0LLK9M/2eQd/v420ecawU/E6E9cWuNXscwVXqJLjISObGrjJp+2QPvcf0Jj6gPFCnmDQ== X-Received: by 2002:a5d:5985:0:b0:38d:d3e2:db32 with SMTP id ffacd0b85a97d-38f70783f03mr1630967f8f.7.1740140640110; Fri, 21 Feb 2025 04:24:00 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258dcc50sm23682854f8f.34.2025.02.21.04.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:23:59 -0800 (PST) Date: Fri, 21 Feb 2025 07:23:57 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Daniel =?utf-8?b?UC4gQmVycmFu?= =?utf-8?b?Z8Op?= , David Hildenbrand Subject: [PULL 25/41] hw/virtio: reset virtio balloon stats on machine reset Message-ID: <1456e90653c46aceb3dd83a7b9889a32aad7700d.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Daniel P. Berrangé When a machine is first booted, all virtio balloon stats are initialized to their default value -1 (18446744073709551615 when represented as unsigned). They remain that way while the firmware is loading, and early phase of guest OS boot, until the virtio-balloon driver is activated. Thereafter the reported stats reflect the guest OS activity. When a machine reset is performed, however, the virtio-balloon stats are left unchanged by QEMU, despite the guest OS no longer updating them, nor indeed even still existing. IOW, the mgmt app keeps getting stale stats until the guest OS starts once more and loads the virtio-balloon driver (if ever). At that point the app will see a discontinuity in the reported values as they sudden jump from the stale value to the new value. This jump is indigituishable from a valid data update. While there is an "last-updated" field to report on the freshness of the stats, that does not unambiguously tell the mgmt app whether the stats are still conceptually relevant to the current running workload. It is more conceptually useful to reset the stats to their default values on machine reset, given that the previous guest workload the stats reflect no longer exists. The mgmt app can now clearly identify that there are is no stats information available from the current executing workload. The 'last-updated' time is also reset back to 0. IOW, on every machine reset, the virtio stats are in the same clean state they were when the macine first powered on. A functional test is added to validate this behaviour with a real world guest OS. Signed-off-by: Daniel P. Berrangé Message-Id: <20250204094202.2183262-1-berrange@redhat.com> Acked-by: David Hildenbrand Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio-balloon.h | 4 + hw/virtio/virtio-balloon.c | 30 ++++- MAINTAINERS | 1 + tests/functional/meson.build | 2 + tests/functional/test_virtio_balloon.py | 161 ++++++++++++++++++++++++ 5 files changed, 197 insertions(+), 1 deletion(-) create mode 100755 tests/functional/test_virtio_balloon.py diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-balloon.h index b12c18a43b..0456c211c6 100644 --- a/include/hw/virtio/virtio-balloon.h +++ b/include/hw/virtio/virtio-balloon.h @@ -16,6 +16,7 @@ #define QEMU_VIRTIO_BALLOON_H #include "standard-headers/linux/virtio_balloon.h" +#include "hw/resettable.h" #include "hw/virtio/virtio.h" #include "system/iothread.h" #include "qom/object.h" @@ -71,6 +72,9 @@ struct VirtIOBalloon { bool qemu_4_0_config_size; uint32_t poison_val; + + /* State of the resettable container */ + ResettableState reset_state; }; #endif diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index ad05768ded..2eb5a14fa2 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -31,7 +31,7 @@ #include "trace.h" #include "qemu/error-report.h" #include "migration/misc.h" - +#include "system/reset.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" @@ -910,6 +910,8 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp) } reset_stats(s); + s->stats_last_update = 0; + qemu_register_resettable(OBJECT(dev)); } static void virtio_balloon_device_unrealize(DeviceState *dev) @@ -917,6 +919,7 @@ static void virtio_balloon_device_unrealize(DeviceState *dev) VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIOBalloon *s = VIRTIO_BALLOON(dev); + qemu_unregister_resettable(OBJECT(dev)); if (s->free_page_bh) { qemu_bh_delete(s->free_page_bh); object_unref(OBJECT(s->iothread)); @@ -987,6 +990,27 @@ static void virtio_balloon_set_status(VirtIODevice *vdev, uint8_t status) } } +static ResettableState *virtio_balloon_get_reset_state(Object *obj) +{ + VirtIOBalloon *s = VIRTIO_BALLOON(obj); + return &s->reset_state; +} + +static void virtio_balloon_reset_enter(Object *obj, ResetType type) +{ + VirtIOBalloon *s = VIRTIO_BALLOON(obj); + + /* + * When waking up from standby/suspend-to-ram, do not reset stats. + */ + if (type == RESET_TYPE_WAKEUP) { + return; + } + + reset_stats(s); + s->stats_last_update = 0; +} + static void virtio_balloon_instance_init(Object *obj) { VirtIOBalloon *s = VIRTIO_BALLOON(obj); @@ -1038,6 +1062,7 @@ static void virtio_balloon_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + ResettableClass *rc = RESETTABLE_CLASS(klass); device_class_set_props(dc, virtio_balloon_properties); dc->vmsd = &vmstate_virtio_balloon; @@ -1050,6 +1075,9 @@ static void virtio_balloon_class_init(ObjectClass *klass, void *data) vdc->get_features = virtio_balloon_get_features; vdc->set_status = virtio_balloon_set_status; vdc->vmsd = &vmstate_virtio_balloon_device; + + rc->get_state = virtio_balloon_get_reset_state; + rc->phases.enter = virtio_balloon_reset_enter; } static const TypeInfo virtio_balloon_info = { diff --git a/MAINTAINERS b/MAINTAINERS index a928ce3e41..013a57d5bf 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2246,6 +2246,7 @@ F: include/hw/virtio/virtio-balloon.h F: system/balloon.c F: include/system/balloon.h F: tests/qtest/virtio-balloon-test.c +F: tests/functional/test_virtio_balloon.py virtio-9p M: Greg Kurz diff --git a/tests/functional/meson.build b/tests/functional/meson.build index cf80924ddc..2d399cc464 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -44,6 +44,7 @@ test_timeouts = { 'riscv64_tuxrun' : 120, 's390x_ccw_virtio' : 420, 'sh4_tuxrun' : 240, + 'virtio_balloon': 120, } tests_generic_system = [ @@ -242,6 +243,7 @@ tests_x86_64_system_thorough = [ 'linux_initrd', 'multiprocess', 'netdev_ethtool', + 'virtio_balloon', 'virtio_gpu', 'x86_64_hotplug_cpu', 'x86_64_tuxrun', diff --git a/tests/functional/test_virtio_balloon.py b/tests/functional/test_virtio_balloon.py new file mode 100755 index 0000000000..67b48e1b4e --- /dev/null +++ b/tests/functional/test_virtio_balloon.py @@ -0,0 +1,161 @@ +#!/usr/bin/env python3 +# +# virtio-balloon tests +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +import time + +from qemu_test import QemuSystemTest, Asset +from qemu_test import wait_for_console_pattern +from qemu_test import exec_command_and_wait_for_pattern + +UNSET_STATS_VALUE = 18446744073709551615 + + +class VirtioBalloonx86(QemuSystemTest): + + ASSET_KERNEL = Asset( + ('https://archives.fedoraproject.org/pub/archive/fedora/linux/releases' + '/31/Server/x86_64/os/images/pxeboot/vmlinuz'), + 'd4738d03dbbe083ca610d0821d0a8f1488bebbdccef54ce33e3adb35fda00129') + + ASSET_INITRD = Asset( + ('https://archives.fedoraproject.org/pub/archive/fedora/linux/releases' + '/31/Server/x86_64/os/images/pxeboot/initrd.img'), + '277cd6c7adf77c7e63d73bbb2cded8ef9e2d3a2f100000e92ff1f8396513cd8b') + + ASSET_DISKIMAGE = Asset( + ('https://archives.fedoraproject.org/pub/archive/fedora/linux/releases' + '/31/Cloud/x86_64/images/Fedora-Cloud-Base-31-1.9.x86_64.qcow2'), + 'e3c1b309d9203604922d6e255c2c5d098a309c2d46215d8fc026954f3c5c27a0') + + DEFAULT_KERNEL_PARAMS = ('root=/dev/vda1 console=ttyS0 net.ifnames=0 ' + 'rd.rescue') + + def wait_for_console_pattern(self, success_message, vm=None): + wait_for_console_pattern( + self, + success_message, + failure_message="Kernel panic - not syncing", + vm=vm, + ) + + def mount_root(self): + self.wait_for_console_pattern('Entering emergency mode.') + prompt = '# ' + self.wait_for_console_pattern(prompt) + + exec_command_and_wait_for_pattern(self, 'mount /dev/vda1 /sysroot', + prompt) + exec_command_and_wait_for_pattern(self, 'chroot /sysroot', + prompt) + exec_command_and_wait_for_pattern(self, "modprobe virtio-balloon", + prompt) + + def assert_initial_stats(self): + ret = self.vm.qmp('qom-get', + {'path': '/machine/peripheral/balloon', + 'property': 'guest-stats'})['return'] + when = ret.get('last-update') + assert when == 0 + stats = ret.get('stats') + for name, val in stats.items(): + assert val == UNSET_STATS_VALUE + + def assert_running_stats(self, then): + ret = self.vm.qmp('qom-get', + {'path': '/machine/peripheral/balloon', + 'property': 'guest-stats'})['return'] + when = ret.get('last-update') + now = time.time() + + assert when > then and when < now + stats = ret.get('stats') + # Stat we expect this particular Kernel to have set + expectData = [ + "stat-available-memory", + "stat-disk-caches", + "stat-free-memory", + "stat-htlb-pgalloc", + "stat-htlb-pgfail", + "stat-major-faults", + "stat-minor-faults", + "stat-swap-in", + "stat-swap-out", + "stat-total-memory", + ] + for name, val in stats.items(): + if name in expectData: + assert val != UNSET_STATS_VALUE + else: + assert val == UNSET_STATS_VALUE + + def test_virtio_balloon_stats(self): + self.set_machine('q35') + kernel_path = self.ASSET_KERNEL.fetch() + initrd_path = self.ASSET_INITRD.fetch() + diskimage_path = self.ASSET_DISKIMAGE.fetch() + + self.vm.set_console() + self.vm.add_args("-S") + self.vm.add_args("-cpu", "max") + self.vm.add_args("-m", "2G") + # Slow down BIOS phase with boot menu, so that after a system + # reset, we can reliably catch the clean stats again in BIOS + # phase before the guest OS launches + self.vm.add_args("-boot", "menu=on") + self.vm.add_args("-machine", "q35,accel=kvm:tcg") + self.vm.add_args("-device", "virtio-balloon,id=balloon") + self.vm.add_args('-drive', + f'file={diskimage_path},if=none,id=drv0,snapshot=on') + self.vm.add_args('-device', 'virtio-blk-pci,bus=pcie.0,' + + 'drive=drv0,id=virtio-disk0,bootindex=1') + + self.vm.add_args( + "-kernel", + kernel_path, + "-initrd", + initrd_path, + "-append", + self.DEFAULT_KERNEL_PARAMS + ) + self.vm.launch() + + # Poll stats at 100ms + self.vm.qmp('qom-set', + {'path': '/machine/peripheral/balloon', + 'property': 'guest-stats-polling-interval', + 'value': 100 }) + + # We've not run any guest code yet, neither BIOS or guest, + # so stats should be all default values + self.assert_initial_stats() + + self.vm.qmp('cont') + + then = time.time() + self.mount_root() + self.assert_running_stats(then) + + # Race window between these two commands, where we + # rely on '-boot menu=on' to (hopefully) ensure we're + # still executing the BIOS when QEMU processes the + # 'stop', and thus have not loaded the virtio-balloon + # driver in the guest + self.vm.qmp('system_reset') + self.vm.qmp('stop') + + # If the above assumption held, we're in BIOS now and + # stats should be all back at their default values + self.assert_initial_stats() + self.vm.qmp('cont') + + then = time.time() + self.mount_root() + self.assert_running_stats(then) + + +if __name__ == '__main__': + QemuSystemTest.main() From patchwork Fri Feb 21 12:24:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985385 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1F9C0C021B5 for ; Fri, 21 Feb 2025 12:32:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS4o-0007Y5-Rs; Fri, 21 Feb 2025 07:24:18 -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 1tlS4f-0007El-M8 for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4e-00079v-5V for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140646; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CxbSAxlMP5lXdwMUAFqhrkgFZvw7oxzLClb5NrCtOYk=; b=EcmK2z/leP29xhHFABrNFIwQFV6lgX0mlPrzQtUsN3lj92dnf1rr7AE7hS4jjZLn9d4nna xENr13yabIo2+w/8JXM0To/CGNt8CNIPyVcCJTJEsk9mOdjGeHZW7tNepTrPvqOX+dK4Yr 0Zya013SZs1KcXGJKqwvyHeIPdfzoxQ= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-158-dsls1Pd9PJ6JwVsRxy50uQ-1; Fri, 21 Feb 2025 07:24:05 -0500 X-MC-Unique: dsls1Pd9PJ6JwVsRxy50uQ-1 X-Mimecast-MFC-AGG-ID: dsls1Pd9PJ6JwVsRxy50uQ_1740140644 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4399304b329so11188365e9.3 for ; Fri, 21 Feb 2025 04:24:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140644; x=1740745444; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=CxbSAxlMP5lXdwMUAFqhrkgFZvw7oxzLClb5NrCtOYk=; b=BWys0hF+ZFQT0u6hWGqBTMb0uDHhIW+0NNE9vBpt1xGHMTCuvKC6xKtDU/J5xyET8C 899CQZfMECimyXBwLi9PRc6cOD0mqeuVoYfU9YdLlZdEwtca9Urz5iLPs3LngrutrmWj RrAiLrMj31Ot93wap6omKcNVUYoCTIQ4DgXzrH9xfGPhWJUFwR7B20QD56Lat5niQw8w VspgjA4aSM1NsJDS8ELP8djguJgXJTPYWLj3TOYQRS36KdTRfjpbUBE1NII3ovLGyYiF 3mQ3kROc0FRNFzu3QRF8o2/cree5ePI3yL2fGHs7AIz6jRiyQ+72idPi8BtUuPQpfcNh f6gg== X-Gm-Message-State: AOJu0YxxlK7qvfWuvueBfqTGRrYCKsHjoglJQQC+wtONirzesCqXn/1E cziqFNSSO6FSI1BOeleQY1MobOpRYK3eKxdby4linf6hPpcHiqpwGMBmVKOLJpkmU4pA9HQqq6g l/MZbBftVr555LppshbduNtwBnC87tV1ICjJuu9hr5pcpb0nbqRFnmRz++0mQyOHobCBiiOEaa6 c4wP9h+gT1srHPYIbsbF1s92fmJJExGw== X-Gm-Gg: ASbGncvcAPqMQoAP47y+Yqi48lGeeB10HaAc4oMQ/utBnx3mXo127JAX3q1uUpB0KlY zXRakU0m8bhI+KK1PmQjyVqtSs5McV4vkEZaCQMjNOIJa58o+UgomEViS/09lFAR1/XqFHf0XGw KLMDhs1gQYyesHD+vt4ZPmYE30pLX9bgP4GK3FMC/STf0InNJ8fXd3AjOK+NcXvRa7AJ1343A06 k2qksoQgHB/uoGhy3t+od4IKRzHCOaehEWomIQvdT5fgLbnMFVXACY12SQLSsIsXdEk3UX+yMRi 2+5v8w== X-Received: by 2002:a05:600c:1991:b0:434:fb65:ebbb with SMTP id 5b1f17b1804b1-439ae1f15e5mr26765225e9.17.1740140643875; Fri, 21 Feb 2025 04:24:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHPAfdQzI9E5KCm0GX6LhCTTel3l5yQewSOkc69pQNDuhY1Gv70HxVjO0WnyxWH4qUdJMrhTA== X-Received: by 2002:a05:600c:1991:b0:434:fb65:ebbb with SMTP id 5b1f17b1804b1-439ae1f15e5mr26764905e9.17.1740140643412; Fri, 21 Feb 2025 04:24:03 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b030bdb4sm16054695e9.27.2025.02.21.04.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:24:02 -0800 (PST) Date: Fri, 21 Feb 2025 07:24:00 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Sairaj Kodilkar , Vasant Hegde , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PULL 26/41] amd_iommu: Use correct DTE field for interrupt passthrough Message-ID: <63dc0b8647391b372f3bb38ff1066f6b4a5e6ea1.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Sairaj Kodilkar Interrupt passthrough is determine by the bits 191,190,187-184. These bits are part of the 3rd quad word (i.e. index 2) in DTE. Hence replace dte[3] by dte[2]. Fixes: b44159fe0 ("x86_iommu/amd: Add interrupt remap support when VAPIC is not enabled") Signed-off-by: Sairaj Kodilkar Reviewed-by: Vasant Hegde Message-Id: <20250207045354.27329-2-sarunkod@amd.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/amd_iommu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 6b13ce894b..98f1209a38 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -1309,15 +1309,15 @@ static int amdvi_int_remap_msi(AMDVIState *iommu, ret = -AMDVI_IR_ERR; break; case AMDVI_IOAPIC_INT_TYPE_NMI: - pass = dte[3] & AMDVI_DEV_NMI_PASS_MASK; + pass = dte[2] & AMDVI_DEV_NMI_PASS_MASK; trace_amdvi_ir_delivery_mode("nmi"); break; case AMDVI_IOAPIC_INT_TYPE_INIT: - pass = dte[3] & AMDVI_DEV_INT_PASS_MASK; + pass = dte[2] & AMDVI_DEV_INT_PASS_MASK; trace_amdvi_ir_delivery_mode("init"); break; case AMDVI_IOAPIC_INT_TYPE_EINT: - pass = dte[3] & AMDVI_DEV_EINT_PASS_MASK; + pass = dte[2] & AMDVI_DEV_EINT_PASS_MASK; trace_amdvi_ir_delivery_mode("eint"); break; default: From patchwork Fri Feb 21 12:24:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985367 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9A4EAC021B3 for ; Fri, 21 Feb 2025 12:29:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS4z-0008Ae-B5; Fri, 21 Feb 2025 07:24:30 -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 1tlS4k-0007PL-GA for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4h-0007Ac-1a for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140650; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dxfWHzt9iN+96ZxAmV4fASWczS4ot0QMavailc7mYDI=; b=DJgxk7Bohn9m7qvVVDwvRSuS1ZwSQRGDaiXcB5uQPGvdYRTZFWkkm8mf1bW12N9aN1LHcF 3h7W0y6M49zBcJ0mm8oHLn90dxhxjdz+NXgxqbi4qsADzkVbXXaWU/GYhX40icGabwswym ixc/Xs2E9+VxFZ6fF0ohWB85cIsZ0mk= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-MJjZAXcVNqK-qcN41WAz9w-1; Fri, 21 Feb 2025 07:24:08 -0500 X-MC-Unique: MJjZAXcVNqK-qcN41WAz9w-1 X-Mimecast-MFC-AGG-ID: MJjZAXcVNqK-qcN41WAz9w_1740140647 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43947a0919aso18741485e9.0 for ; Fri, 21 Feb 2025 04:24:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140647; x=1740745447; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=dxfWHzt9iN+96ZxAmV4fASWczS4ot0QMavailc7mYDI=; b=cltvu6UTGQflsOQh0bVhMCq9UOv5BIUTidmUoZjv3WyEd3Cgh3sJpBnje9vdOTB1lT GywPCn72XlO032takYvzrFyeN7os7EQpTou+LhrY2QNUUORL8yw9ImtFnLjtk1S+yJr6 WQapSE4+0rzessnAkVune4ESoqu+TLA5ntrZFo/wE7PO5+tC1W+4oRtXj3aN/FGJJMI/ i2ezG50ObICwksc24/NBnjgiOa9hYC6SSIyh1E3l6/tAbXn4/BX8qYhp1e9S/KRRNtzq MWhCYcr1oUD01BtJJe0f78KH/RIL704p9Lw5dQlNksJy6Dg1qaKD7J/6CN84aiCdxIHT wdJA== X-Gm-Message-State: AOJu0YwEFnxQ6uxa5MXuKBZH0d0No8gfJvCQVhXU9OG4I6mSxNjWxzae 8ggGaM4/7iUT6FXwX6DHG19Gko6HKYlbmn+1Gy0qGd3GDC9IUU+NEwrY9P4MBTE8dLfa3r0gC8X 0zxtcTLC8sWYLe6r5a9LeELj9WOd5KaaHjxfw09Kf4SMFxyFSFST8ntaFJZh+6kb/qbZcTTl+0o eZWc++aOyJX1OPtJmfWoKGTle5iRRrdw== X-Gm-Gg: ASbGncsLxeiywvQNETO9jbEFlgJuSRXaRuZSfKQPcV2CQBqkRzwPWwyutBRGIKDl/UT LLa538taNATk58T00cqpg1NGw0MCnf6Ul6SnKMVjHDYBzsMVtQp6+wl1aoIsFkg5QZaby1w1LM6 YMlgcJSQ0rjs+ivZ80+M3RZFWLjv5dI3uXJFJwM+/gmi/rYjcYjm7V29+DEhcmA/KQFLrol+hBu Yk3KO33mM4J7MVxgZXXGTLTu+jWKHfxCm9urQRJz1JDwoe+1xX+IBFxTAdbB/FqKv9B4xgCUdhj bxbKoQ== X-Received: by 2002:a05:600c:45ca:b0:439:9a40:aa0b with SMTP id 5b1f17b1804b1-439ae21e36emr23933785e9.25.1740140646900; Fri, 21 Feb 2025 04:24:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IE++L12GzMimgissjFPBxz51sTR1njhnN+DcWPxHFC8BjJANAvKPaefWVIjCiSosjXHz8lRHg== X-Received: by 2002:a05:600c:45ca:b0:439:9a40:aa0b with SMTP id 5b1f17b1804b1-439ae21e36emr23933245e9.25.1740140646422; Fri, 21 Feb 2025 04:24:06 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm15860915e9.3.2025.02.21.04.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:24:05 -0800 (PST) Date: Fri, 21 Feb 2025 07:24:03 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Sairaj Kodilkar , Vasant Hegde , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PULL 27/41] amd_iommu: Use correct bitmask to set capability BAR Message-ID: <3684717b7407cc395dc9bf522e193dbc85293dee.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Sairaj Kodilkar AMD IOMMU provides the base address of control registers through IVRS table and PCI capability. Since this base address is of 64 bit, use 32 bits mask (instead of 16 bits) to set BAR low and high. Fixes: d29a09ca68 ("hw/i386: Introduce AMD IOMMU") Signed-off-by: Sairaj Kodilkar Reviewed-by: Vasant Hegde Message-Id: <20250207045354.27329-3-sarunkod@amd.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/amd_iommu.h | 2 +- hw/i386/amd_iommu.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/i386/amd_iommu.h b/hw/i386/amd_iommu.h index e0dac4d9a9..28125130c6 100644 --- a/hw/i386/amd_iommu.h +++ b/hw/i386/amd_iommu.h @@ -187,7 +187,7 @@ AMDVI_CAPAB_FLAG_HTTUNNEL | AMDVI_CAPAB_EFR_SUP) /* AMDVI default address */ -#define AMDVI_BASE_ADDR 0xfed80000 +#define AMDVI_BASE_ADDR 0xfed80000ULL /* page management constants */ #define AMDVI_PAGE_SHIFT 12 diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 98f1209a38..044fe43256 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -1593,9 +1593,9 @@ static void amdvi_pci_realize(PCIDevice *pdev, Error **errp) /* reset AMDVI specific capabilities, all r/o */ pci_set_long(pdev->config + s->capab_offset, AMDVI_CAPAB_FEATURES); pci_set_long(pdev->config + s->capab_offset + AMDVI_CAPAB_BAR_LOW, - AMDVI_BASE_ADDR & ~(0xffff0000)); + AMDVI_BASE_ADDR & MAKE_64BIT_MASK(14, 18)); pci_set_long(pdev->config + s->capab_offset + AMDVI_CAPAB_BAR_HIGH, - (AMDVI_BASE_ADDR & ~(0xffff)) >> 16); + AMDVI_BASE_ADDR >> 32); pci_set_long(pdev->config + s->capab_offset + AMDVI_CAPAB_RANGE, 0xff000000); pci_set_long(pdev->config + s->capab_offset + AMDVI_CAPAB_MISC, 0); From patchwork Fri Feb 21 12:24:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985376 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 72552C021AA for ; Fri, 21 Feb 2025 12:30:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS4x-0007tU-19; Fri, 21 Feb 2025 07:24:27 -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 1tlS4n-0007WU-5h for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4k-0007Ap-72 for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140653; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y55Lq3nnb4wo+Mep9PSIMyZizGYpu/mdV63SxawIIlg=; b=aabNhQw8IMcm7+llcpSMw0oJIgJtoJLuVURlvy4YEIsWNzwTlWB03VLPptg9g0IbMcjMJn b7WPd9eFW+LGm7qqOh1B7aEQ332xCT0Vl4yTaJLAtt+Qambnti4+/3nnh9ABxqbpbyfYud 1Ep9xcCrQgCaROWP4BeoVwSzbSJA1gg= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-358-sPgT0ernO1WXshOxFlWDRQ-1; Fri, 21 Feb 2025 07:24:12 -0500 X-MC-Unique: sPgT0ernO1WXshOxFlWDRQ-1 X-Mimecast-MFC-AGG-ID: sPgT0ernO1WXshOxFlWDRQ_1740140651 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43942e82719so13917555e9.2 for ; Fri, 21 Feb 2025 04:24:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140650; x=1740745450; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=y55Lq3nnb4wo+Mep9PSIMyZizGYpu/mdV63SxawIIlg=; b=oy60sa0a/0BJ6GIDu8Wbvz/4Q/qwReJBnJVEktaw4ILhjLZ792LCmOVJ3cSAXogZbj P/CcO+cjLKOndcpZw2a/L2x6dS7qXfSRkASlfchJMIqnH7ykW5LDly120hDCF5YlX8NU xd7W4ULy+/yvtOu3l5ggYIs4w+EB4fE3grZIYaHJx8kV/0ZNIp35rHvg0jU4HLNlwsPv ZVZS/nqK9YCcm/2DBFX0rJJWfN9S2my5Ab9zUC/5gHAux5ymcvLSfj4xRiC3AYMilsv1 ptViLcD6SC44UN2LkxtD5o4mLBDlvLm3I3OPBuhIAUXhCb4W8lxK33kLhggcepG1Q7JX A2ZA== X-Gm-Message-State: AOJu0Yy+PMFEJaK4ND7LmQX+4iVoJswogwnMllKdk/R3i16YOk0mria8 L0h3Mng0YRQspCHhJf5fmzf/2OD3uZ91ylr7aTI538UfTUof2QaY70vFTXr3BU3pjP4zrDtQWfe L0Vuuu3jXB0EqJkOqiLwCf5xp+dth7PU4mjBpgK5poNIyepO5QEXA7/Zr3WzTwvri7/ImjCzRui uus/TOXoBojxMYbus1quCaM/gxWDtz4g== X-Gm-Gg: ASbGnctwfSuOfDL0lRrzsBus8gIB26nyorCJiAOtkRVphYFkULsacapJPOHxwTIlZJJ UpZx/vwULeWxEMvHoCex6+9tqMPmoTaBSHR4K4eO26p17X3qJf9nV8yLw8ZjfgX6btgdEqxhOF9 4I32i/B7amWpA98SbGpZMyJsAA4ATWlSQL7pPRCWKNHoE+WinX39EISZkputJh4Ce3kdsSjbcEG zoysBKo8VWWgd6OCn1fIsmv499GTbq9ALM8lTtgOLqJ7XP3FVsZrYXvsLtZ/Yjr/5U6PQGe0QPz QotRUw== X-Received: by 2002:a5d:47a9:0:b0:38f:3888:33bc with SMTP id ffacd0b85a97d-38f6e755eebmr2956940f8f.10.1740140650247; Fri, 21 Feb 2025 04:24:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1jDVsRMsGdie1M/p/c7fTH9AvdNu2+7DPqbDnkNGxE7mSHJYD/rRv7K8qAaHKQGbg3i0uWw== X-Received: by 2002:a5d:47a9:0:b0:38f:3888:33bc with SMTP id ffacd0b85a97d-38f6e755eebmr2956895f8f.10.1740140649660; Fri, 21 Feb 2025 04:24:09 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258fc7ecsm22997792f8f.49.2025.02.21.04.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:24:09 -0800 (PST) Date: Fri, 21 Feb 2025 07:24:06 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Jonah Palmer , Eugenio =?utf-8?b?UMOpcmV6?= , Lei Yang , Stefano Garzarella , Jason Wang Subject: [PULL 28/41] vhost-iova-tree: Implement an IOVA-only tree Message-ID: <92cf61e70838c20adc82daa3170fdbb9d174b508.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Jonah Palmer Creates and supports an IOVA-only tree to support a SVQ IOVA->HVA and GPA->IOVA tree for host-only and guest-backed memory, respectively, in the next patch. The IOVA allocator still allocates an IOVA range but now adds this range to the IOVA-only tree as well as to the full IOVA->HVA tree. In the next patch, the full IOVA->HVA tree will be split into a partial SVQ IOVA->HVA tree and a GPA->IOVA tree. The motivation behind having an IOVA-only tree was to have a single tree that would keep track of all allocated IOVA ranges between the partial SVQ IOVA->HVA and GPA->IOVA trees. Signed-off-by: Jonah Palmer Acked-by: Eugenio Pérez Tested-by: Lei Yang Message-Id: <20250217144936.3589907-2-jonah.palmer@oracle.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-iova-tree.h | 3 ++- hw/virtio/vhost-iova-tree.c | 26 ++++++++++++++++++++------ hw/virtio/vhost-vdpa.c | 29 +++++++++++++++++++++-------- net/vhost-vdpa.c | 10 ++++++++-- 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/hw/virtio/vhost-iova-tree.h b/hw/virtio/vhost-iova-tree.h index 4adfd79ff0..525ce72b1d 100644 --- a/hw/virtio/vhost-iova-tree.h +++ b/hw/virtio/vhost-iova-tree.h @@ -21,7 +21,8 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostIOVATree, vhost_iova_tree_delete); const DMAMap *vhost_iova_tree_find_iova(const VhostIOVATree *iova_tree, const DMAMap *map); -int vhost_iova_tree_map_alloc(VhostIOVATree *iova_tree, DMAMap *map); +int vhost_iova_tree_map_alloc(VhostIOVATree *iova_tree, DMAMap *map, + hwaddr taddr); void vhost_iova_tree_remove(VhostIOVATree *iova_tree, DMAMap map); #endif diff --git a/hw/virtio/vhost-iova-tree.c b/hw/virtio/vhost-iova-tree.c index 3d03395a77..216885aa3c 100644 --- a/hw/virtio/vhost-iova-tree.c +++ b/hw/virtio/vhost-iova-tree.c @@ -28,6 +28,9 @@ struct VhostIOVATree { /* IOVA address to qemu memory maps. */ IOVATree *iova_taddr_map; + + /* Allocated IOVA addresses */ + IOVATree *iova_map; }; /** @@ -44,6 +47,7 @@ VhostIOVATree *vhost_iova_tree_new(hwaddr iova_first, hwaddr iova_last) tree->iova_last = iova_last; tree->iova_taddr_map = iova_tree_new(); + tree->iova_map = iova_tree_new(); return tree; } @@ -53,6 +57,7 @@ VhostIOVATree *vhost_iova_tree_new(hwaddr iova_first, hwaddr iova_last) void vhost_iova_tree_delete(VhostIOVATree *iova_tree) { iova_tree_destroy(iova_tree->iova_taddr_map); + iova_tree_destroy(iova_tree->iova_map); g_free(iova_tree); } @@ -75,6 +80,7 @@ const DMAMap *vhost_iova_tree_find_iova(const VhostIOVATree *tree, * * @tree: The iova tree * @map: The iova map + * @taddr: The translated address (HVA) * * Returns: * - IOVA_OK if the map fits in the container @@ -83,19 +89,26 @@ const DMAMap *vhost_iova_tree_find_iova(const VhostIOVATree *tree, * * It returns assignated iova in map->iova if return value is VHOST_DMA_MAP_OK. */ -int vhost_iova_tree_map_alloc(VhostIOVATree *tree, DMAMap *map) +int vhost_iova_tree_map_alloc(VhostIOVATree *tree, DMAMap *map, hwaddr taddr) { + int ret; + /* Some vhost devices do not like addr 0. Skip first page */ hwaddr iova_first = tree->iova_first ?: qemu_real_host_page_size(); - if (map->translated_addr + map->size < map->translated_addr || - map->perm == IOMMU_NONE) { + if (taddr + map->size < taddr || map->perm == IOMMU_NONE) { return IOVA_ERR_INVALID; } - /* Allocate a node in IOVA address */ - return iova_tree_alloc_map(tree->iova_taddr_map, map, iova_first, - tree->iova_last); + /* Allocate a node in the IOVA-only tree */ + ret = iova_tree_alloc_map(tree->iova_map, map, iova_first, tree->iova_last); + if (unlikely(ret != IOVA_OK)) { + return ret; + } + + /* Insert a node in the IOVA->HVA tree */ + map->translated_addr = taddr; + return iova_tree_insert(tree->iova_taddr_map, map); } /** @@ -107,4 +120,5 @@ int vhost_iova_tree_map_alloc(VhostIOVATree *tree, DMAMap *map) void vhost_iova_tree_remove(VhostIOVATree *iova_tree, DMAMap map) { iova_tree_remove(iova_tree->iova_taddr_map, map); + iova_tree_remove(iova_tree->iova_map, map); } diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 3cdaa12ed5..703dcfc929 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -360,14 +360,20 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, llsize = int128_sub(llend, int128_make64(iova)); if (s->shadow_data) { int r; + hwaddr hw_vaddr = (hwaddr)(uintptr_t)vaddr; - mem_region.translated_addr = (hwaddr)(uintptr_t)vaddr, mem_region.size = int128_get64(llsize) - 1, mem_region.perm = IOMMU_ACCESS_FLAG(true, section->readonly), - r = vhost_iova_tree_map_alloc(s->iova_tree, &mem_region); + r = vhost_iova_tree_map_alloc(s->iova_tree, &mem_region, hw_vaddr); if (unlikely(r != IOVA_OK)) { error_report("Can't allocate a mapping (%d)", r); + + if (mem_region.translated_addr == hw_vaddr) { + error_report("Insertion to IOVA->HVA tree failed"); + /* Remove the mapping from the IOVA-only tree */ + goto fail_map; + } goto fail; } @@ -1142,16 +1148,23 @@ static void vhost_vdpa_svq_unmap_rings(struct vhost_dev *dev, * * @v: Vhost-vdpa device * @needle: The area to search iova + * @taddr: The translated address (HVA) * @errorp: Error pointer */ static bool vhost_vdpa_svq_map_ring(struct vhost_vdpa *v, DMAMap *needle, - Error **errp) + hwaddr taddr, Error **errp) { int r; - r = vhost_iova_tree_map_alloc(v->shared->iova_tree, needle); + r = vhost_iova_tree_map_alloc(v->shared->iova_tree, needle, taddr); if (unlikely(r != IOVA_OK)) { error_setg(errp, "Cannot allocate iova (%d)", r); + + if (needle->translated_addr == taddr) { + error_append_hint(errp, "Insertion to IOVA->HVA tree failed"); + /* Remove the mapping from the IOVA-only tree */ + vhost_iova_tree_remove(v->shared->iova_tree, *needle); + } return false; } @@ -1192,11 +1205,11 @@ static bool vhost_vdpa_svq_map_rings(struct vhost_dev *dev, vhost_svq_get_vring_addr(svq, &svq_addr); driver_region = (DMAMap) { - .translated_addr = svq_addr.desc_user_addr, .size = driver_size - 1, .perm = IOMMU_RO, }; - ok = vhost_vdpa_svq_map_ring(v, &driver_region, errp); + ok = vhost_vdpa_svq_map_ring(v, &driver_region, svq_addr.desc_user_addr, + errp); if (unlikely(!ok)) { error_prepend(errp, "Cannot create vq driver region: "); return false; @@ -1206,11 +1219,11 @@ static bool vhost_vdpa_svq_map_rings(struct vhost_dev *dev, addr->avail_user_addr = driver_region.iova + avail_offset; device_region = (DMAMap) { - .translated_addr = svq_addr.used_user_addr, .size = device_size - 1, .perm = IOMMU_RW, }; - ok = vhost_vdpa_svq_map_ring(v, &device_region, errp); + ok = vhost_vdpa_svq_map_ring(v, &device_region, svq_addr.used_user_addr, + errp); if (unlikely(!ok)) { error_prepend(errp, "Cannot create vq device region: "); vhost_vdpa_svq_unmap_ring(v, driver_region.translated_addr); diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 231b45246c..5a3a57203d 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -510,14 +510,20 @@ static int vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v, void *buf, size_t size, bool write) { DMAMap map = {}; + hwaddr taddr = (hwaddr)(uintptr_t)buf; int r; - map.translated_addr = (hwaddr)(uintptr_t)buf; map.size = size - 1; map.perm = write ? IOMMU_RW : IOMMU_RO, - r = vhost_iova_tree_map_alloc(v->shared->iova_tree, &map); + r = vhost_iova_tree_map_alloc(v->shared->iova_tree, &map, taddr); if (unlikely(r != IOVA_OK)) { error_report("Cannot map injected element"); + + if (map.translated_addr == taddr) { + error_report("Insertion to IOVA->HVA tree failed"); + /* Remove the mapping from the IOVA-only tree */ + goto dma_map_err; + } return r; } From patchwork Fri Feb 21 12:24:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985382 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B3C3DC021B6 for ; Fri, 21 Feb 2025 12:31:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS51-0008RM-MV; Fri, 21 Feb 2025 07:24:31 -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 1tlS4q-0007m3-Qw for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4n-0007BE-GD for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wb9xbiaN7Bcp6mEKCB6c5bcDTebQhCRaR5TgWWaVjGM=; b=c8aJIi2ngk+9b/Dj9pFGxFevuwGYAWO1d6uyR2NhNoSCpuhUhBiNxwyj9qZzzw592c9w/n nzdkpjMtgd8OE9WHBqzfEW0A93paDcpyNRhCYDjH42+uNu4qDcms0KBoPJJ1fVXUhAHAn4 JfjgAFynwfAqeR4WiSEjGP8XcHevpwc= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-456-tUYzRR2KPFCg04f0emajDw-1; Fri, 21 Feb 2025 07:24:15 -0500 X-MC-Unique: tUYzRR2KPFCg04f0emajDw-1 X-Mimecast-MFC-AGG-ID: tUYzRR2KPFCg04f0emajDw_1740140654 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4399304b329so11188875e9.3 for ; Fri, 21 Feb 2025 04:24:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140653; x=1740745453; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Wb9xbiaN7Bcp6mEKCB6c5bcDTebQhCRaR5TgWWaVjGM=; b=gYnBidEMt5I4olY5khrnICajYlH4IsmEFMn6Rc7R49g1lFS+2NIf2CJwwKXArIklMi MD2Ripkt5R9+YPXvh3seSrzAhBR4tU2IyiYqLasIC6rFFXBpI+W/yvBIlQ0KPsEHgx/b v9tHdGkwR1twoFWMsGZLJezrOM7Fs9DoW/V9XIJIh+eto/+GDoM2zt1l6orNBcrDDySh lOADwoYfzHo7nv0M7Wyn08bVuX4ioZdWDEwoGQ2z5FXlsLvf5K7pS2hYHCSXpHEzZdge IQhFer1Lw/75bhHuP/S1YcHc4rTpNDkwhZqLMH9JY5aNDVYjBifrbn9rbhhGgLE/jsuR kFDA== X-Gm-Message-State: AOJu0YwKoS1WLH7iRJapXOEBHEaP3Mn9ir2KAiT+mqAc0Nv17UwAgKNo vY69Yxx8qazxPXGI+GdY9trvD+Jkd/NaZHHEcuRjYslIyIV/69jtKGBqIWPAMUV8TC/N/Fn0Eub C5OWnjRvZn3n4HQIAHJoMmfHXKXL0scdrAL8WAa6HuX9UWXqP3LeE7jwSmSmR7DzdaZUA4wpBKc a2E3bY5QoZOiKBX1Lm50fNbb/q3IIKJw== X-Gm-Gg: ASbGncvBCO5cvKXdnzQBWA/KW9i/jiT0X7O4j3zwsbhPs/v0xNgRv20tYeNytyB+9yl 6mH5GGEWKabqbQ6Ng4bZEnA7lBw8+39YVqyrrCfp1NpFRHbmye5LZn9VMJcbpPpjpbsGPLg+U1x mVOw8QOFK6s+gVrdmr0BoeupXvQt9Ag4+h8Zhgkmw25yI+OdvsgPape8X/Ub6adpzi9o3IvBhnj QplfPD43DKxJAihCtkUeacaGblSI7dtMe5ROIfo5Y/1CjuqdSm6SYUs74E8fnvZ/hgtjn+KTa/4 kkqY/w== X-Received: by 2002:a05:6000:144f:b0:38f:503a:d93f with SMTP id ffacd0b85a97d-38f6f0b2529mr3037055f8f.40.1740140653345; Fri, 21 Feb 2025 04:24:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHx50PM2eXkWeQnj7YGfYS410hlTByeZikBkrj+ZVrxLwKmExb0zlzHW1FcvtFEADRSS2qo7A== X-Received: by 2002:a05:6000:144f:b0:38f:503a:d93f with SMTP id ffacd0b85a97d-38f6f0b2529mr3037017f8f.40.1740140652707; Fri, 21 Feb 2025 04:24:12 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f259f7987sm22859401f8f.87.2025.02.21.04.24.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:24:12 -0800 (PST) Date: Fri, 21 Feb 2025 07:24:10 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Jonah Palmer , Eugenio =?utf-8?b?UMOpcmV6?= , Stefano Garzarella , Peter Xu , Jason Wang Subject: [PULL 29/41] vhost-iova-tree, svq: Implement GPA->IOVA & partial IOVA->HVA trees Message-ID: <05063f55841babae7216d36105440ed8ba632938.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Jonah Palmer Creates and supports a GPA->IOVA tree and a partial IOVA->HVA tree by splitting up guest-backed memory maps and host-only memory maps from the full IOVA->HVA tree. That is, any guest-backed memory maps are now stored in the GPA->IOVA tree and host-only memory maps stay in the IOVA->HVA tree. Also propagates the GPAs (in_addr/out_addr) of a VirtQueueElement to vhost_svq_translate_addr() to translate GPAs to IOVAs via the GPA->IOVA tree (when descriptors are backed by guest memory). For descriptors backed by host-only memory, the existing partial SVQ IOVA->HVA tree is used. GPAs are unique in the guest's address space, ensuring unambiguous IOVA translations. This avoids the issue where different GPAs map to the same HVA, causing the original HVA->IOVA translation to potentially return an IOVA associated with the wrong intended GPA. Signed-off-by: Jonah Palmer Acked-by: Eugenio Pérez Message-Id: <20250217144936.3589907-3-jonah.palmer@oracle.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-iova-tree.h | 5 +++ hw/virtio/vhost-shadow-virtqueue.h | 5 ++- include/qemu/iova-tree.h | 22 ++++++++++ hw/virtio/vhost-iova-tree.c | 67 ++++++++++++++++++++++++++++++ hw/virtio/vhost-shadow-virtqueue.c | 55 ++++++++++++++++-------- hw/virtio/vhost-vdpa.c | 19 ++++----- net/vhost-vdpa.c | 2 +- util/iova-tree.c | 46 ++++++++++++++++++++ 8 files changed, 190 insertions(+), 31 deletions(-) diff --git a/hw/virtio/vhost-iova-tree.h b/hw/virtio/vhost-iova-tree.h index 525ce72b1d..0c4ba5abd5 100644 --- a/hw/virtio/vhost-iova-tree.h +++ b/hw/virtio/vhost-iova-tree.h @@ -24,5 +24,10 @@ const DMAMap *vhost_iova_tree_find_iova(const VhostIOVATree *iova_tree, int vhost_iova_tree_map_alloc(VhostIOVATree *iova_tree, DMAMap *map, hwaddr taddr); void vhost_iova_tree_remove(VhostIOVATree *iova_tree, DMAMap map); +const DMAMap *vhost_iova_tree_find_gpa(const VhostIOVATree *iova_tree, + const DMAMap *map); +int vhost_iova_tree_map_alloc_gpa(VhostIOVATree *iova_tree, DMAMap *map, + hwaddr taddr); +void vhost_iova_tree_remove_gpa(VhostIOVATree *iova_tree, DMAMap map); #endif diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-virtqueue.h index 19c842a15b..9c273739d6 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -118,8 +118,9 @@ uint16_t vhost_svq_available_slots(const VhostShadowVirtqueue *svq); void vhost_svq_push_elem(VhostShadowVirtqueue *svq, const VirtQueueElement *elem, uint32_t len); int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg, - size_t out_num, const struct iovec *in_sg, size_t in_num, - VirtQueueElement *elem); + size_t out_num, const hwaddr *out_addr, + const struct iovec *in_sg, size_t in_num, + const hwaddr *in_addr, VirtQueueElement *elem); size_t vhost_svq_poll(VhostShadowVirtqueue *svq, size_t num); void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); diff --git a/include/qemu/iova-tree.h b/include/qemu/iova-tree.h index 44a45931d5..16d354a814 100644 --- a/include/qemu/iova-tree.h +++ b/include/qemu/iova-tree.h @@ -40,6 +40,28 @@ typedef struct DMAMap { } QEMU_PACKED DMAMap; typedef gboolean (*iova_tree_iterator)(DMAMap *map); +/** + * gpa_tree_new: + * + * Create a new GPA->IOVA tree. + * + * Returns: the tree point on success, or NULL otherwise. + */ +IOVATree *gpa_tree_new(void); + +/** + * gpa_tree_insert: + * + * @tree: The GPA->IOVA tree we're inserting the mapping to + * @map: The GPA->IOVA mapping to insert + * + * Inserts a GPA range to the GPA->IOVA tree. If there are overlapped + * ranges, IOVA_ERR_OVERLAP will be returned. + * + * Return: 0 if successful, < 0 otherwise. + */ +int gpa_tree_insert(IOVATree *tree, const DMAMap *map); + /** * iova_tree_new: * diff --git a/hw/virtio/vhost-iova-tree.c b/hw/virtio/vhost-iova-tree.c index 216885aa3c..9d2d6a7af2 100644 --- a/hw/virtio/vhost-iova-tree.c +++ b/hw/virtio/vhost-iova-tree.c @@ -31,6 +31,9 @@ struct VhostIOVATree { /* Allocated IOVA addresses */ IOVATree *iova_map; + + /* GPA->IOVA address memory maps */ + IOVATree *gpa_iova_map; }; /** @@ -48,6 +51,7 @@ VhostIOVATree *vhost_iova_tree_new(hwaddr iova_first, hwaddr iova_last) tree->iova_taddr_map = iova_tree_new(); tree->iova_map = iova_tree_new(); + tree->gpa_iova_map = gpa_tree_new(); return tree; } @@ -58,6 +62,7 @@ void vhost_iova_tree_delete(VhostIOVATree *iova_tree) { iova_tree_destroy(iova_tree->iova_taddr_map); iova_tree_destroy(iova_tree->iova_map); + iova_tree_destroy(iova_tree->gpa_iova_map); g_free(iova_tree); } @@ -122,3 +127,65 @@ void vhost_iova_tree_remove(VhostIOVATree *iova_tree, DMAMap map) iova_tree_remove(iova_tree->iova_taddr_map, map); iova_tree_remove(iova_tree->iova_map, map); } + +/** + * Find the IOVA address stored from a guest memory address (GPA) + * + * @tree: The VhostIOVATree + * @map: The map with the guest memory address + * + * Returns the stored GPA->IOVA mapping, or NULL if not found. + */ +const DMAMap *vhost_iova_tree_find_gpa(const VhostIOVATree *tree, + const DMAMap *map) +{ + return iova_tree_find_iova(tree->gpa_iova_map, map); +} + +/** + * Allocate a new IOVA range and add the mapping to the GPA->IOVA tree + * + * @tree: The VhostIOVATree + * @map: The IOVA mapping + * @taddr: The translated address (GPA) + * + * Returns: + * - IOVA_OK if the map fits both containers + * - IOVA_ERR_INVALID if the map does not make sense (like size overflow) + * - IOVA_ERR_NOMEM if the IOVA-only tree cannot allocate more space + * + * It returns an assigned IOVA in map->iova if the return value is IOVA_OK. + */ +int vhost_iova_tree_map_alloc_gpa(VhostIOVATree *tree, DMAMap *map, hwaddr taddr) +{ + int ret; + + /* Some vhost devices don't like addr 0. Skip first page */ + hwaddr iova_first = tree->iova_first ?: qemu_real_host_page_size(); + + if (taddr + map->size < taddr || map->perm == IOMMU_NONE) { + return IOVA_ERR_INVALID; + } + + /* Allocate a node in the IOVA-only tree */ + ret = iova_tree_alloc_map(tree->iova_map, map, iova_first, tree->iova_last); + if (unlikely(ret != IOVA_OK)) { + return ret; + } + + /* Insert a node in the GPA->IOVA tree */ + map->translated_addr = taddr; + return gpa_tree_insert(tree->gpa_iova_map, map); +} + +/** + * Remove existing mappings from the IOVA-only and GPA->IOVA trees + * + * @tree: The VhostIOVATree + * @map: The map to remove + */ +void vhost_iova_tree_remove_gpa(VhostIOVATree *iova_tree, DMAMap map) +{ + iova_tree_remove(iova_tree->gpa_iova_map, map); + iova_tree_remove(iova_tree->iova_map, map); +} diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c index 37aca8b431..30ba565f03 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -78,24 +78,39 @@ uint16_t vhost_svq_available_slots(const VhostShadowVirtqueue *svq) * @vaddr: Translated IOVA addresses * @iovec: Source qemu's VA addresses * @num: Length of iovec and minimum length of vaddr + * @gpas: Descriptors' GPAs, if backed by guest memory */ static bool vhost_svq_translate_addr(const VhostShadowVirtqueue *svq, hwaddr *addrs, const struct iovec *iovec, - size_t num) + size_t num, const hwaddr *gpas) { if (num == 0) { return true; } for (size_t i = 0; i < num; ++i) { - DMAMap needle = { - .translated_addr = (hwaddr)(uintptr_t)iovec[i].iov_base, - .size = iovec[i].iov_len, - }; Int128 needle_last, map_last; size_t off; + const DMAMap *map; + DMAMap needle; + + /* Check if the descriptor is backed by guest memory */ + if (gpas) { + /* Search the GPA->IOVA tree */ + needle = (DMAMap) { + .translated_addr = gpas[i], + .size = iovec[i].iov_len, + }; + map = vhost_iova_tree_find_gpa(svq->iova_tree, &needle); + } else { + /* Search the IOVA->HVA tree */ + needle = (DMAMap) { + .translated_addr = (hwaddr)(uintptr_t)iovec[i].iov_base, + .size = iovec[i].iov_len, + }; + map = vhost_iova_tree_find_iova(svq->iova_tree, &needle); + } - const DMAMap *map = vhost_iova_tree_find_iova(svq->iova_tree, &needle); /* * Map cannot be NULL since iova map contains all guest space and * qemu already has a physical address mapped @@ -130,6 +145,7 @@ static bool vhost_svq_translate_addr(const VhostShadowVirtqueue *svq, * @sg: Cache for hwaddr * @iovec: The iovec from the guest * @num: iovec length + * @addr: Descriptors' GPAs, if backed by guest memory * @more_descs: True if more descriptors come in the chain * @write: True if they are writeable descriptors * @@ -137,7 +153,8 @@ static bool vhost_svq_translate_addr(const VhostShadowVirtqueue *svq, */ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, const struct iovec *iovec, size_t num, - bool more_descs, bool write) + const hwaddr *addr, bool more_descs, + bool write) { uint16_t i = svq->free_head, last = svq->free_head; unsigned n; @@ -149,7 +166,7 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, return true; } - ok = vhost_svq_translate_addr(svq, sg, iovec, num); + ok = vhost_svq_translate_addr(svq, sg, iovec, num, addr); if (unlikely(!ok)) { return false; } @@ -174,8 +191,9 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, const struct iovec *out_sg, size_t out_num, + const hwaddr *out_addr, const struct iovec *in_sg, size_t in_num, - unsigned *head) + const hwaddr *in_addr, unsigned *head) { unsigned avail_idx; vring_avail_t *avail = svq->vring.avail; @@ -191,13 +209,14 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, return false; } - ok = vhost_svq_vring_write_descs(svq, sgs, out_sg, out_num, in_num > 0, - false); + ok = vhost_svq_vring_write_descs(svq, sgs, out_sg, out_num, out_addr, + in_num > 0, false); if (unlikely(!ok)) { return false; } - ok = vhost_svq_vring_write_descs(svq, sgs, in_sg, in_num, false, true); + ok = vhost_svq_vring_write_descs(svq, sgs, in_sg, in_num, in_addr, false, + true); if (unlikely(!ok)) { return false; } @@ -247,8 +266,9 @@ static void vhost_svq_kick(VhostShadowVirtqueue *svq) * Return -EINVAL if element is invalid, -ENOSPC if dev queue is full */ int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg, - size_t out_num, const struct iovec *in_sg, size_t in_num, - VirtQueueElement *elem) + size_t out_num, const hwaddr *out_addr, + const struct iovec *in_sg, size_t in_num, + const hwaddr *in_addr, VirtQueueElement *elem) { unsigned qemu_head; unsigned ndescs = in_num + out_num; @@ -258,7 +278,8 @@ int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg, return -ENOSPC; } - ok = vhost_svq_add_split(svq, out_sg, out_num, in_sg, in_num, &qemu_head); + ok = vhost_svq_add_split(svq, out_sg, out_num, out_addr, in_sg, in_num, + in_addr, &qemu_head); if (unlikely(!ok)) { return -EINVAL; } @@ -274,8 +295,8 @@ int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg, static int vhost_svq_add_element(VhostShadowVirtqueue *svq, VirtQueueElement *elem) { - return vhost_svq_add(svq, elem->out_sg, elem->out_num, elem->in_sg, - elem->in_num, elem); + return vhost_svq_add(svq, elem->out_sg, elem->out_num, elem->out_addr, + elem->in_sg, elem->in_num, elem->in_addr, elem); } /** diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 703dcfc929..7efbde3d4c 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -360,17 +360,17 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, llsize = int128_sub(llend, int128_make64(iova)); if (s->shadow_data) { int r; - hwaddr hw_vaddr = (hwaddr)(uintptr_t)vaddr; + hwaddr gpa = section->offset_within_address_space; mem_region.size = int128_get64(llsize) - 1, mem_region.perm = IOMMU_ACCESS_FLAG(true, section->readonly), - r = vhost_iova_tree_map_alloc(s->iova_tree, &mem_region, hw_vaddr); + r = vhost_iova_tree_map_alloc_gpa(s->iova_tree, &mem_region, gpa); if (unlikely(r != IOVA_OK)) { error_report("Can't allocate a mapping (%d)", r); - if (mem_region.translated_addr == hw_vaddr) { - error_report("Insertion to IOVA->HVA tree failed"); + if (mem_region.translated_addr == gpa) { + error_report("Insertion to GPA->IOVA tree failed"); /* Remove the mapping from the IOVA-only tree */ goto fail_map; } @@ -392,7 +392,7 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, fail_map: if (s->shadow_data) { - vhost_iova_tree_remove(s->iova_tree, mem_region); + vhost_iova_tree_remove_gpa(s->iova_tree, mem_region); } fail: @@ -446,21 +446,18 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener, if (s->shadow_data) { const DMAMap *result; - const void *vaddr = memory_region_get_ram_ptr(section->mr) + - section->offset_within_region + - (iova - section->offset_within_address_space); DMAMap mem_region = { - .translated_addr = (hwaddr)(uintptr_t)vaddr, + .translated_addr = section->offset_within_address_space, .size = int128_get64(llsize) - 1, }; - result = vhost_iova_tree_find_iova(s->iova_tree, &mem_region); + result = vhost_iova_tree_find_gpa(s->iova_tree, &mem_region); if (!result) { /* The memory listener map wasn't mapped */ return; } iova = result->iova; - vhost_iova_tree_remove(s->iova_tree, *result); + vhost_iova_tree_remove_gpa(s->iova_tree, *result); } vhost_vdpa_iotlb_batch_begin_once(s); /* diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 5a3a57203d..bd01866878 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -649,7 +649,7 @@ static ssize_t vhost_vdpa_net_cvq_add(VhostVDPAState *s, VhostShadowVirtqueue *svq = g_ptr_array_index(s->vhost_vdpa.shadow_vqs, 0); int r; - r = vhost_svq_add(svq, out_sg, out_num, in_sg, in_num, NULL); + r = vhost_svq_add(svq, out_sg, out_num, NULL, in_sg, in_num, NULL, NULL); if (unlikely(r != 0)) { if (unlikely(r == -ENOSPC)) { qemu_log_mask(LOG_GUEST_ERROR, "%s: No space on device queue\n", diff --git a/util/iova-tree.c b/util/iova-tree.c index 06295e2755..5b0c95ff15 100644 --- a/util/iova-tree.c +++ b/util/iova-tree.c @@ -257,3 +257,49 @@ void iova_tree_destroy(IOVATree *tree) g_tree_destroy(tree->tree); g_free(tree); } + +static int gpa_tree_compare(gconstpointer a, gconstpointer b, gpointer data) +{ + const DMAMap *m1 = a, *m2 = b; + + if (m1->translated_addr > m2->translated_addr + m2->size) { + return 1; + } + + if (m1->translated_addr + m1->size < m2->translated_addr) { + return -1; + } + + /* Overlapped */ + return 0; +} + +IOVATree *gpa_tree_new(void) +{ + IOVATree *gpa_tree = g_new0(IOVATree, 1); + + gpa_tree->tree = g_tree_new_full(gpa_tree_compare, NULL, g_free, NULL); + + return gpa_tree; +} + +int gpa_tree_insert(IOVATree *tree, const DMAMap *map) +{ + DMAMap *new; + + if (map->translated_addr + map->size < map->translated_addr || + map->perm == IOMMU_NONE) { + return IOVA_ERR_INVALID; + } + + /* We don't allow inserting ranges that overlap with existing ones */ + if (iova_tree_find(tree, map)) { + return IOVA_ERR_OVERLAP; + } + + new = g_new0(DMAMap, 1); + memcpy(new, map, sizeof(*new)); + iova_tree_insert_internal(tree->tree, new); + + return IOVA_OK; +} From patchwork Fri Feb 21 12:24:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EE379C021B3 for ; Fri, 21 Feb 2025 12:25:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS5B-0000ol-Ao; Fri, 21 Feb 2025 07:24: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 1tlS4s-0007uy-Ry for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4q-0007Bd-J4 for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140659; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A+vuP+wp5WYQIHMmPYDAfhQFy0pXwNh7ZSHKv4P/Gxg=; b=Au9qt93vd0/ViYWRvUkliPTdUhVvOAurWRknoq9bEQIqvGFeJ5JyfXjRSZG3rQzFjI1v1P z04unoQp7p74e5hQPXc/zaG5OiyjkBdIlGRD+9LBAQb+Wl7v/WBQ0tBz5rlHuaBM06c8BH CATE41kgOnRSy0o/IhQ2z4TajNTz1mQ= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-HD71-DUPOrC96YwfTrw_xg-1; Fri, 21 Feb 2025 07:24:17 -0500 X-MC-Unique: HD71-DUPOrC96YwfTrw_xg-1 X-Mimecast-MFC-AGG-ID: HD71-DUPOrC96YwfTrw_xg_1740140656 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43995bff469so22360695e9.2 for ; Fri, 21 Feb 2025 04:24:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140656; x=1740745456; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=A+vuP+wp5WYQIHMmPYDAfhQFy0pXwNh7ZSHKv4P/Gxg=; b=R8zd8YmHP0wjfkf8ksav15xfrCKTuwkMf2qDrEwu+qRMCvwJDjXowdRlJImhN7Orpu QGfcfTeYIT8GHcsLWPbD5dkjq3Tfe/b/EpauLvSP8IzzYy690hhO/o4sWQU63Pd0uQeh VA9Jp1ZGg5Pfc9fHZx0bScHwMGDMJC5n/9z1/bI9hjt6N8LM3JGAs+uXh/GyG6o/62nM Wi4mBNsU12JaS4+d7RZOKXoVLlT75CJly44TVjCvCeW3SMfm/6d4GQKy4S7dsmdel3Le WKPimp8/5ZsouthY313ceCxQ+OTG/v/V4D9LDsZyg6E+voEo1SsJ9CKPePgYNLMmjqAE yVnA== X-Gm-Message-State: AOJu0YwLLtI6+CtyqYo0lGtZ7iNJsiEzmsnmkbS/WnhZ0jyIlEUAGreG yGD0CzNFYmRLiG6QQRyDwYj074dF59klbl1aPYetMTRozREGxFBU+OI07Od+6kMnoqqJGEh3kwj KSqKlNkKtNgNme81xYXTofhldbRIq17f/Rq7ztmAy850h6nOVOEQQ5eSuhIpCrBUg0Li7TpvT7F yBBcLH/dxtm3orF6AAHjDgu866rzDGvw== X-Gm-Gg: ASbGncuM8toDDyR3bQPA074JjchNOVvjTnFIa7oNZJHoQtht7P+KKLd9DcAQMD0TmHg dyW/dHMvY9jMaGqtK8tnrKvfvHxBL4sNE8v3dCQ9npZsT2v41qFwq5+QwLT6UFV0w6Mwvxm3bRk YSFWLIMTRgw7V9d0/Lu0/QAL2eXyBO3ENFD51xcvVhc0JVVWVArqq13hfUcAeRjHpV6gakyYIWL VN9UJy9F1ESoVwGZ/0kreUYhwDvlCpibYPH7Sx5mn1Y3M9qGTb/2dYb01H+9/wshMEmizkW4nbn Qo/oyA== X-Received: by 2002:a5d:64a3:0:b0:38d:eb33:79c2 with SMTP id ffacd0b85a97d-38f707b0962mr1943488f8f.32.1740140656140; Fri, 21 Feb 2025 04:24:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOQdYe/jRCBs/h5WCxs8VZNxg4pjXo2WFNg3p1tnMmOnzsadTHHEqus1bu6mU2w5l500hkbQ== X-Received: by 2002:a5d:64a3:0:b0:38d:eb33:79c2 with SMTP id ffacd0b85a97d-38f707b0962mr1943465f8f.32.1740140655719; Fri, 21 Feb 2025 04:24:15 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f259d5923sm23452690f8f.74.2025.02.21.04.24.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:24:15 -0800 (PST) Date: Fri, 21 Feb 2025 07:24:13 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Jonah Palmer , Eugenio =?utf-8?b?UMOpcmV6?= , Lei Yang , Stefano Garzarella Subject: [PULL 30/41] vhost-iova-tree: Update documentation Message-ID: <332859dd597b78f7d1ebfaefd6195e3a2b3e5906.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Jonah Palmer Minor update to some of the documentation / comments in hw/virtio/vhost-iova-tree.c. Signed-off-by: Jonah Palmer Reviewed-by: Eugenio Pérez Tested-by: Lei Yang Message-Id: <20250217144936.3589907-4-jonah.palmer@oracle.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-iova-tree.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/hw/virtio/vhost-iova-tree.c b/hw/virtio/vhost-iova-tree.c index 9d2d6a7af2..fa4147b773 100644 --- a/hw/virtio/vhost-iova-tree.c +++ b/hw/virtio/vhost-iova-tree.c @@ -37,9 +37,9 @@ struct VhostIOVATree { }; /** - * Create a new IOVA tree + * Create a new VhostIOVATree * - * Returns the new IOVA tree + * Returns the new VhostIOVATree. */ VhostIOVATree *vhost_iova_tree_new(hwaddr iova_first, hwaddr iova_last) { @@ -56,7 +56,7 @@ VhostIOVATree *vhost_iova_tree_new(hwaddr iova_first, hwaddr iova_last) } /** - * Delete an iova tree + * Delete a VhostIOVATree */ void vhost_iova_tree_delete(VhostIOVATree *iova_tree) { @@ -69,10 +69,10 @@ void vhost_iova_tree_delete(VhostIOVATree *iova_tree) /** * Find the IOVA address stored from a memory address * - * @tree: The iova tree + * @tree: The VhostIOVATree * @map: The map with the memory address * - * Return the stored mapping, or NULL if not found. + * Returns the stored IOVA->HVA mapping, or NULL if not found. */ const DMAMap *vhost_iova_tree_find_iova(const VhostIOVATree *tree, const DMAMap *map) @@ -81,10 +81,10 @@ const DMAMap *vhost_iova_tree_find_iova(const VhostIOVATree *tree, } /** - * Allocate a new mapping + * Allocate a new IOVA range and add the mapping to the IOVA->HVA tree * - * @tree: The iova tree - * @map: The iova map + * @tree: The VhostIOVATree + * @map: The IOVA mapping * @taddr: The translated address (HVA) * * Returns: @@ -92,7 +92,7 @@ const DMAMap *vhost_iova_tree_find_iova(const VhostIOVATree *tree, * - IOVA_ERR_INVALID if the map does not make sense (like size overflow) * - IOVA_ERR_NOMEM if tree cannot allocate more space. * - * It returns assignated iova in map->iova if return value is VHOST_DMA_MAP_OK. + * It returns an assigned IOVA in map->iova if the return value is IOVA_OK. */ int vhost_iova_tree_map_alloc(VhostIOVATree *tree, DMAMap *map, hwaddr taddr) { @@ -117,9 +117,9 @@ int vhost_iova_tree_map_alloc(VhostIOVATree *tree, DMAMap *map, hwaddr taddr) } /** - * Remove existing mappings from iova tree + * Remove existing mappings from the IOVA-only and IOVA->HVA trees * - * @iova_tree: The vhost iova tree + * @iova_tree: The VhostIOVATree * @map: The map to remove */ void vhost_iova_tree_remove(VhostIOVATree *iova_tree, DMAMap map) From patchwork Fri Feb 21 12:24:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985369 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C520BC021AA for ; Fri, 21 Feb 2025 12:29:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS4y-00086W-Ai; Fri, 21 Feb 2025 07:24:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4w-0007x6-MF for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4t-0007C3-93 for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140662; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u27NKlvtYL4RNuhqQv/c+tDTZMnad0qlqsDe9OD9/Lo=; b=VxZcGYT37CZAgHl0dcjh6ClMgtDQvOq+i8ZOBhXMDsoFrOgDcEbvmQznRUvEp2yJyzHzDJ XgMekagWX8sN2p2yvqMPzLDFVqUx2iDOtTjcweo+tUm07zalRSrL0Cp7oj7E89Bgg6kikp N3ITkfKEO8zF8kK5nmXNGZ9USEzVUe8= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-484-sPKOyW18PGq8cIGO07cErQ-1; Fri, 21 Feb 2025 07:24:21 -0500 X-MC-Unique: sPKOyW18PGq8cIGO07cErQ-1 X-Mimecast-MFC-AGG-ID: sPKOyW18PGq8cIGO07cErQ_1740140660 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4393e8738b3so14979895e9.0 for ; Fri, 21 Feb 2025 04:24:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140659; x=1740745459; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=u27NKlvtYL4RNuhqQv/c+tDTZMnad0qlqsDe9OD9/Lo=; b=JheR72ecmfoE7+2vCaYV83Ap8Vu1QRc7EouQ0y9VPShobXwabi+TxfZ9NZCvERa6qj ENPiu30robJvJ4Zxb4xaTuKtsnTbtLVXbgRviZd3JniY3BA2K/qe7DRLWgs6rwparZzR bj/Gwb5kRyCmA+fjuEk487P/EqSZg5ORUpAKn9AgZDrljaLN+FY2hn3whSgTx7OyqRcN GLHXnPMdioPbzMytDti661JzIVIuKzW9qJPm9sS1ztS6EUKbxT/MXnaoAIM7Q35sRVRj EJFGp36yaBrNe8jt6Xw+7idbJxLCcVBgIxdpqhz/NThAeAwD0/35W9dLiimdbXh03FuW fIFA== X-Gm-Message-State: AOJu0YzpOU5JSo0FQHnTJfovrWdgsGvQ+dToidpsFc0SHQ24J9KF3dEk QG+xb9fyhh/h7Iw/D1c4Zt3xcvH0m4oCJcYxApHxOs1fJG9w7WAjcQVbDtJQyMOl+yYNazqVz6j ykHTQCwp28ql6BG+RECJCGuM2zFvo9K+Ja+BlYSCKWclXYAqBnI/tGupMkLZ96NDZuw5XLSuYHz dW8AlnTkgHSiQm2V8N8Mm3pzMKKp9lag== X-Gm-Gg: ASbGnctMQZB0ZiAvSCKZ8d3ldpLaw9eua4A+F8acOfyBu3SqSRRYTFJUowHyZ2KCRfM v7/5DQsJ+UvM9JC9WSIoE2ADqoRRpc2L5yHBo/mfEStXRWwh04j5iOEUwLUpAZ25c00qLCMNAsI KURRB3SetSvEHSvTuXYEMlcpKAzZQH+BGmSUOziHx65tiKLEj4D7E3nxcOnQLEKPgU1UADHJWP1 8M/zVLBDZHBkzHCm0xkfFDtRYdXmshZLB9ZaWAld1KRmyLw2e0LqAIZUw+fTRPVl0abLlDQ0Uaz 1tUpcw== X-Received: by 2002:a05:600c:5101:b0:439:65f0:c9ce with SMTP id 5b1f17b1804b1-439ae220a84mr21414935e9.25.1740140659478; Fri, 21 Feb 2025 04:24:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGkanAFun3kgOrIGed7mKCligMYCtqpxaZuvTDrHUsPKhnQURrgk8syYfc4clZ/xQe1ug+xSg== X-Received: by 2002:a05:600c:5101:b0:439:65f0:c9ce with SMTP id 5b1f17b1804b1-439ae220a84mr21414675e9.25.1740140659021; Fri, 21 Feb 2025 04:24:19 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm15866465e9.3.2025.02.21.04.24.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:24:18 -0800 (PST) Date: Fri, 21 Feb 2025 07:24:16 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Stefano Garzarella , qemu-stable@nongnu.org, myluo24@m.fudan.edu.cn, "Gonglei (Arei)" , Zhenwei Pi Subject: [PULL 31/41] cryptodev/vhost: allocate CryptoDevBackendVhost using g_mem0() Message-ID: <83cb18ac4500f3a14067b19408705068647cb0c5.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stefano Garzarella The function `vhost_dev_init()` expects the `struct vhost_dev` (passed as a parameter) to be fully initialized. This is important because some parts of the code check whether `vhost_dev->config_ops` is NULL to determine if it has been set (e.g. later via `vhost_dev_set_config_notifier`). To ensure this initialization, it’s better to allocate the entire `CryptoDevBackendVhost` structure (which includes `vhost_dev`) using `g_mem0()`, following the same approach used for other vhost devices, such as in `vhost_net_init()`. Fixes: 042cea274c ("cryptodev: add vhost-user as a new cryptodev backend") Cc: qemu-stable@nongnu.org Reported-by: myluo24@m.fudan.edu.cn Signed-off-by: Stefano Garzarella Message-Id: <20250211135523.101203-1-sgarzare@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- backends/cryptodev-vhost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index 8718c97326..943680a23a 100644 --- a/backends/cryptodev-vhost.c +++ b/backends/cryptodev-vhost.c @@ -53,7 +53,7 @@ cryptodev_vhost_init( CryptoDevBackendVhost *crypto; Error *local_err = NULL; - crypto = g_new(CryptoDevBackendVhost, 1); + crypto = g_new0(CryptoDevBackendVhost, 1); crypto->dev.max_queues = 1; crypto->dev.nvqs = 1; crypto->dev.vqs = crypto->vqs; From patchwork Fri Feb 21 12:24:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985375 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 110A5C021B5 for ; Fri, 21 Feb 2025 12:30:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS56-0000Uc-46; Fri, 21 Feb 2025 07:24: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 1tlS4y-0008A9-Ca for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4w-0007CO-FZ for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140665; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fb35RulI/+ttP697lcY0Hr/k4kUhvbmNTuRv5jMyS8s=; b=YVjggYvQByLww2fxQkfqwS22Sf0TjUyFwKglzf3nXAvbG50zeBglnJX/sfr79pWRxUsX0g 7i1ym/PLCQxItL2v162fzrqLmrmPImK1u/XpQEvjLgOA7K3bKCYf8xyrJ3PnRTevb0F8ef os/hzgN72ygO6nbCoz6PKJsLOrxUAUw= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-433-7ml3dXdWPbipH3ka4AJY0w-1; Fri, 21 Feb 2025 07:24:24 -0500 X-MC-Unique: 7ml3dXdWPbipH3ka4AJY0w-1 X-Mimecast-MFC-AGG-ID: 7ml3dXdWPbipH3ka4AJY0w_1740140663 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43998ec3733so10586265e9.2 for ; Fri, 21 Feb 2025 04:24:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140662; x=1740745462; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Fb35RulI/+ttP697lcY0Hr/k4kUhvbmNTuRv5jMyS8s=; b=i9/hKzv8v4hT0DvRG+b757jf5rOLmalH0O1oI7EhETVsxzsSjcvxqJaWN6DSNUVV2w uexAbXBmo5SzPJI+MqER6cNXGa103I1nblbfdI94Xn3VX6a5wdHS9IVXFalkOgR/IUeJ yp2gtaXtcY+YcaKF5mvdHio5PgvdNb0gGQ1+Hhs63GJlqW9G6GnXC71c2cfErr2a6Lc4 LQZSZ+Op1ZsYiZXM90qaYTWr6a+1YHFGUQbPPosZI6g581E+Pmz+mxGx2dZI/GnGdDOY zkyO7oylJvpiiGjPPC8fCjPfaSTt4Wjo9Ha2O6eCOZ0tS2P3rTivB/25zMM9AEemi1+C K7iQ== X-Gm-Message-State: AOJu0YxybnZZk9FEZW+1VUTLHxVCCVYgQriLhL0AMIc7mw1sT5718U2R 9bdYXKC7OPXCaV+ICsw1Jit2TKrF1JKLXdKJdHlCklgWbEMf+mt4EsXi3N6lZUvq7Jaobhksjjg +K5UutUchno+UZtOKTbCYJZkPeIU7ns3Ud28mgxsFjsGx73hk+nQPnwZJmo7TGWIKXmN/q96tnf 8G83nw6bHxCaagEwlio4W9P3ouVrCYkw== X-Gm-Gg: ASbGncuz6kE2PVBvJYUQUy2yiOEEAheNz6kfeG6o4s8yjgc6roAJadv04Ak2q9S1mhB RfdcRkM8cfi2dQY/stIZlwWeat+RGXPbgQz6V2A7nFMbrGGb/qhwzuOS0QTVywSnMkvCDPeAksR xIaA2HPznS3+j/DyDP+vY0OGUNV6ScgeiqGXUQ/TfanKZ6ghF+lpQbM7AZn8RyWN6XCyeALnBAd YLy50/Y7d3C1N79fzDf1FhVckK/55xx3jePrcryGEY1YXQ7qL+uq0n+QCeKHYPgmdxDrFWJBN8U 9zYyhw== X-Received: by 2002:a05:600c:4ecc:b0:439:84d3:f7ee with SMTP id 5b1f17b1804b1-439ae2189bemr19969465e9.24.1740140662672; Fri, 21 Feb 2025 04:24:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6C38cxMb9hzBe8yIVY1QmJ5KuG0NeV8RdsIxgctExImapK4BqB1nnxj/lrUWzL3/D0wEekQ== X-Received: by 2002:a05:600c:4ecc:b0:439:84d3:f7ee with SMTP id 5b1f17b1804b1-439ae2189bemr19969225e9.24.1740140662269; Fri, 21 Feb 2025 04:24:22 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02e4245sm15665135e9.18.2025.02.21.04.24.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:24:21 -0800 (PST) Date: Fri, 21 Feb 2025 07:24:19 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Stefano Garzarella , Philippe =?utf-8?q?Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Thomas Huth , Richard Henderson Subject: [PULL 32/41] MAINTAINERS: add more files to `vhost` Message-ID: <590de17b829d2ccd8067f19c71a53e31bec7bf00.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stefano Garzarella While sending a patch for backends/cryptodev-vhost.c I noticed that Michael wasn`t in CC so I took a look at the files listed under `vhost` and tried to fix it increasing the coverage by adding new files. Signed-off-by: Stefano Garzarella Message-Id: <20250211144259.117910-1-sgarzare@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- MAINTAINERS | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 013a57d5bf..2d07d72933 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2212,12 +2212,16 @@ M: Michael S. Tsirkin R: Stefano Garzarella S: Supported F: hw/*/*vhost* -F: docs/interop/vhost-user.json -F: docs/interop/vhost-user.rst +F: docs/interop/vhost-user* +F: docs/system/devices/vhost-user* F: contrib/vhost-user-*/ -F: backends/vhost-user.c +F: backends/*vhost* F: include/system/vhost-user-backend.h +F: include/hw/virtio/vhost* +F: include/*/vhost* F: subprojects/libvhost-user/ +F: block/export/vhost-user* +F: util/vhost-user-server.c vhost-shadow-virtqueue R: Eugenio Pérez From patchwork Fri Feb 21 12:24:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985356 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6D989C021B3 for ; Fri, 21 Feb 2025 12:25:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS5J-0001Q8-K2; Fri, 21 Feb 2025 07:24: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 1tlS51-0008QZ-FF for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS4z-0007D6-NS for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140669; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0LpIbNsQ+dt+JvKUY8+SWh8i4my2OzTIZC5O+PsCrUY=; b=YkZr5iUV9enX8mZmF2c7nDdYgxLiT1Y6/Q02TG2eZeObrI2fdUF1WnebWny+Oh98wY6dTC zQbmSk81wt8QQZBLh7HPw2RCplaBbk0Mso4iLSTnR82Suu5tbWQ8Vofjvf7jyHj+2r0h5G faUvdS0QiILyxFVoh/LmbVVocB2GjEc= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-620-UKnG_SJcMJiToIkYm2WLew-1; Fri, 21 Feb 2025 07:24:27 -0500 X-MC-Unique: UKnG_SJcMJiToIkYm2WLew-1 X-Mimecast-MFC-AGG-ID: UKnG_SJcMJiToIkYm2WLew_1740140667 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4393b6763a3so9536315e9.2 for ; Fri, 21 Feb 2025 04:24:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140666; x=1740745466; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0LpIbNsQ+dt+JvKUY8+SWh8i4my2OzTIZC5O+PsCrUY=; b=CRTWvbk5rWhACCEukoXKmQNZVWGLsg9/CATpVQg7AxANw1LWVBfdHrv184MunAHf2r yUhsb27QDKtnsE4vhlPyfjl9/ETErcoveB5ZLKmX/+guyGhGXN+aP90cs3DFG/YuqY79 iQ1e+Tjt7XGilKhCKDHlX8xb+ZfCj5sZ3FoE/1Cuk05jaTP+CJ0HB9QXNdS1t9B7ys/L DEulAet6nv0a1hAAn7p+OdroTZsknEyk8k8TsanU8lXDU7ise85Yf/jvadLAf9yHm7xh AvgGAeWsLaUYBKCobfs0WEbz28eyvd9GNpwvq8yGejPJ5Z5M7E9gf/kpBLUBn8IGYrjC YfRg== X-Gm-Message-State: AOJu0Yw3JWcd0Ces0xhIXTUIk+UvKRncJtLImqiMoC8cYKId4vKqRMVW DzOP0iQatlYHR6X4m/f8K3htZNSKqefJwJKSV71c9q757mRqdQuB+wl5rwNFFj5HsPjpMbta0ib B/e8CeKm4PLU7K+IpNmE+yzA9ZjD7Jj10EwjyvuD7CCpIz+f8kUdan2XI7IfRqsHuYEl090In/k Qxj6iGvA15kRQIuc8TMVnN3DN3uO8WMg== X-Gm-Gg: ASbGnctZzuveSBugLT/Go2asQ2M7Hnf0A55S5uVVyFhyXrpXBp1z014q5GkkNXhtc+F K9jODfgP/bogcMJFJZ5GYo9iAW1PXndaGT/Fnd9iIhMrLWRbrOShLZQyOH/Ls5AhCfvH+Sb/Dxk zCjwmYEyxKhCqhUEd297UsVBykzb4/6Q3uNJINaOgdo3EsKHJQ259ySTX3fqB6bWsabi7bM/MJE Vs0Dxocb6SkbHYIM5V6w5G+UL6o93rY65A2Qa1cf9Psi+fcfCb7iwHU6ZGMhe2/VdkFmNmf+7V9 Is/Wow== X-Received: by 2002:a05:600c:3c90:b0:439:a202:86dd with SMTP id 5b1f17b1804b1-439b155b048mr15027135e9.26.1740140666226; Fri, 21 Feb 2025 04:24:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IH3DqUfrNt+5E8efvA4ge4PEvPvxxIj1UbxOtGVHHSmIjAJzSbsPusm/w+FqHQbYdxCuImAzw== X-Received: by 2002:a05:600c:3c90:b0:439:a202:86dd with SMTP id 5b1f17b1804b1-439b155b048mr15026825e9.26.1740140665730; Fri, 21 Feb 2025 04:24:25 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4399bea8577sm64824915e9.0.2025.02.21.04.24.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:24:25 -0800 (PST) Date: Fri, 21 Feb 2025 07:24:22 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Konstantin Shkolnyy , Eugenio =?utf-8?b?UMOpcmV6?= , Lei Yang , Stefano Garzarella Subject: [PULL 33/41] vdpa: Fix endian bugs in shadow virtqueue Message-ID: <50e9754149066dc91f58405d3378b589098cb408.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Konstantin Shkolnyy VDPA didn't work on a big-endian machine due to missing/incorrect CPU<->LE data format conversions. Signed-off-by: Konstantin Shkolnyy Message-Id: <20250212164923.1971538-1-kshk@linux.ibm.com> Fixes: 10857ec0ad ("vhost: Add VhostShadowVirtqueue") Acked-by: Eugenio Pérez Tested-by: Lei Yang Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-shadow-virtqueue.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c index 30ba565f03..2481d49345 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -182,10 +182,10 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, descs[i].len = cpu_to_le32(iovec[n].iov_len); last = i; - i = cpu_to_le16(svq->desc_next[i]); + i = svq->desc_next[i]; } - svq->free_head = le16_to_cpu(svq->desc_next[last]); + svq->free_head = svq->desc_next[last]; return true; } @@ -247,10 +247,12 @@ static void vhost_svq_kick(VhostShadowVirtqueue *svq) smp_mb(); if (virtio_vdev_has_feature(svq->vdev, VIRTIO_RING_F_EVENT_IDX)) { - uint16_t avail_event = *(uint16_t *)(&svq->vring.used->ring[svq->vring.num]); + uint16_t avail_event = le16_to_cpu( + *(uint16_t *)(&svq->vring.used->ring[svq->vring.num])); needs_kick = vring_need_event(avail_event, svq->shadow_avail_idx, svq->shadow_avail_idx - 1); } else { - needs_kick = !(svq->vring.used->flags & VRING_USED_F_NO_NOTIFY); + needs_kick = + !(svq->vring.used->flags & cpu_to_le16(VRING_USED_F_NO_NOTIFY)); } if (!needs_kick) { @@ -386,7 +388,7 @@ static bool vhost_svq_more_used(VhostShadowVirtqueue *svq) return true; } - svq->shadow_used_idx = cpu_to_le16(*(volatile uint16_t *)used_idx); + svq->shadow_used_idx = le16_to_cpu(*(volatile uint16_t *)used_idx); return svq->last_used_idx != svq->shadow_used_idx; } @@ -404,7 +406,7 @@ static bool vhost_svq_enable_notification(VhostShadowVirtqueue *svq) { if (virtio_vdev_has_feature(svq->vdev, VIRTIO_RING_F_EVENT_IDX)) { uint16_t *used_event = (uint16_t *)&svq->vring.avail->ring[svq->vring.num]; - *used_event = svq->shadow_used_idx; + *used_event = cpu_to_le16(svq->shadow_used_idx); } else { svq->vring.avail->flags &= ~cpu_to_le16(VRING_AVAIL_F_NO_INTERRUPT); } @@ -429,7 +431,7 @@ static uint16_t vhost_svq_last_desc_of_chain(const VhostShadowVirtqueue *svq, uint16_t num, uint16_t i) { for (uint16_t j = 0; j < (num - 1); ++j) { - i = le16_to_cpu(svq->desc_next[i]); + i = svq->desc_next[i]; } return i; @@ -704,7 +706,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, svq->desc_state = g_new0(SVQDescState, svq->vring.num); svq->desc_next = g_new0(uint16_t, svq->vring.num); for (unsigned i = 0; i < svq->vring.num - 1; i++) { - svq->desc_next[i] = cpu_to_le16(i + 1); + svq->desc_next[i] = i + 1; } } From patchwork Fri Feb 21 12:24:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985370 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 17AB6C021AA for ; Fri, 21 Feb 2025 12:29:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS5C-0000vW-Rp; Fri, 21 Feb 2025 07:24:43 -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 1tlS55-0000YG-KO for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS53-0007Dr-SI for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EAxtLkE7W+XUghJ5VIYoz6FDtNlGyyTqDgvbSHIaIzI=; b=iJaV0ctVFdMOGKrqRVZJqZZ9T6YKyktx25/cuRBN2fM7ZQBe9eSJyYMSCNbbeq1c1ZEgNA kE8im+tpvMcmGfGWa7FtTruL/He57IoedRd3ok1jMlktmcI4afLSZm6lRJ6UfvKglY9EyA PgNUDiGWx4c67yr8XEPQnEIUdiGYS30= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-142-7Jdp2p50OAKdEnAO2KLyww-1; Fri, 21 Feb 2025 07:24:32 -0500 X-MC-Unique: 7Jdp2p50OAKdEnAO2KLyww-1 X-Mimecast-MFC-AGG-ID: 7Jdp2p50OAKdEnAO2KLyww_1740140671 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-38f628ff78eso1073988f8f.1 for ; Fri, 21 Feb 2025 04:24:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140670; x=1740745470; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EAxtLkE7W+XUghJ5VIYoz6FDtNlGyyTqDgvbSHIaIzI=; b=P441zPucIYbRWZb97lq9HZnYdW1AtFsRFvu/2Na3Ggz+VHWHLKbi98TRhtgPbOazWY 3eqizv5kjl0XS1QVqLDyPcll1QIcrfJ7ITiEnFIB80YOf+UHFkOJPUTINZE/LyZphuf2 wPsRdzOWktuAZD4NidX28ctAduFXoYzVBC2g3zNjN0BYxA9GEPaCKY4r816/SkmoNWG/ O+343F582MZaXLdAJ62v9HGsfcSInu7IM0DFNU9TKR99TrazlmhOO4d/+PtY+uxb2zZv 4ekcWfwvKq2k4A9y5quOB0AnfS7gU4BTMKPrjlbeedZa8PHNlymO5xklLD4xsXTvjLEP Kjww== X-Gm-Message-State: AOJu0YxDafJKURf/3xGWpTFHkYEtJ/gcGYmKzqNdpu1fUQqPYBenYTww 3+JCk+ythjviWveyFbSYQ7h3jDRVsK69w8441gtPvWXnjAg50pBplxqY4DFJd26nv9XHOvh1aJj f5hK15sgEa4sJ8QkUIG6WsUdWMhFdrVJ2nquUiHDJDPvg96KCzm0p4DaENtrXIc0/aOPcV/A6ct lQcZ/YpNnAArGvPfHy5j5QjWUQOM8Qdg== X-Gm-Gg: ASbGncv9WE6PAwPDR+RQhETIpj41gQfWRLN5H7QWjkELPxUIZYOiJKrepIAuI5yy2+M KdaRXqCzsjhdTZzlzFxIRl8g0Ya2QU0twrTU+Fr+kseXGROE9hjlPiaMvNA4VqkIME2zFlSyQeM ySqBBoPsvbitlrdEZHPIRb2O/QIJm2WuDYaq+2oGBj+yOPtVrqqXTF253yXnInC2qY5ymALEiWB R0676A0ieYmTaxYSXv130d1LOXNJINI9tsMPX/uUP5XRG7an5LFiT7Qswmj8EywUYVG6Gf0x4Ax Eq7xAg== X-Received: by 2002:a05:6000:1f84:b0:38b:d807:f3be with SMTP id ffacd0b85a97d-38f6f3c50bbmr2137651f8f.3.1740140670404; Fri, 21 Feb 2025 04:24:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IHozMNEJXCK2el7msXK/RalCAw14qKq6Aw2YgNN1y/9vaE7HcjvC0xf0w6Rf4dvcuifEp+uUQ== X-Received: by 2002:a05:6000:1f84:b0:38b:d807:f3be with SMTP id ffacd0b85a97d-38f6f3c50bbmr2137625f8f.3.1740140669998; Fri, 21 Feb 2025 04:24:29 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258cccdesm23255646f8f.26.2025.02.21.04.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:24:29 -0800 (PST) Date: Fri, 21 Feb 2025 07:24:25 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Alexander Graf , Vikrant Garg , Dorjoy Chowdhury , Philippe =?utf-8?q?Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PULL 34/41] hw/virtio/virtio-nsm: Respond with correct length Message-ID: <131fe64e63c88ec52c45a5946a478c0edeb31b78.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Alexander Graf When we return a response packet from NSM, we need to indicate its length according to the content of the response. Prior to this patch, we returned the length of the source buffer, which may confuse guest code that relies on the response size. Fix it by returning the response payload size instead. Fixes: bb154e3e0cc715 ("device/virtio-nsm: Support for Nitro Secure Module device") Reported-by: Vikrant Garg Signed-off-by: Alexander Graf Message-Id: <20250213114541.67515-1-graf@amazon.com> Reviewed-by: Dorjoy Chowdhury Fixes: bb154e3e0cc715 ("device/virtio-nsm: Support for Nitro Secure Module device")
Reported-by: Vikrant Garg Signed-off-by: Alexander Graf Reviewed-by: Philippe Mathieu-Daudé Tested-by: Vikrant Garg Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-nsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/virtio-nsm.c b/hw/virtio/virtio-nsm.c index 098e1aeac6..b22aa74e34 100644 --- a/hw/virtio/virtio-nsm.c +++ b/hw/virtio/virtio-nsm.c @@ -1596,7 +1596,7 @@ static void handle_input(VirtIODevice *vdev, VirtQueue *vq) g_free(req.iov_base); g_free(res.iov_base); virtqueue_push(vq, out_elem, 0); - virtqueue_push(vq, in_elem, in_elem->in_sg->iov_len); + virtqueue_push(vq, in_elem, sz); virtio_notify(vdev, vq); return; From patchwork Fri Feb 21 12:24:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985378 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 51E8AC021AA for ; Fri, 21 Feb 2025 12:31:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS5H-0001Bt-RM; Fri, 21 Feb 2025 07:24:48 -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 1tlS5A-0000ou-MP for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS58-0007ED-UJ for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140678; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=qUA67lnlZ1kgDiClFh7mIAizVWuXk4KUx2uXWAEi+j8=; b=gfkt10voKh1mUR+42iI5bR0vW8/4pzXdd81+nzRbFO9eAF3/o5xRRAsinetD/YipH+N2fN 22yL6CGLxcPe5nMq14HOEuEI0zGDurq0nOC6GqrCgmXKjUb2wH4EAxtzH0lA38grIJPKI+ UnC/sNKV37lxhjdBIOOPiGIH55dt370= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-315-yb7I_n_fPLK_PvltGKh_Yw-1; Fri, 21 Feb 2025 07:24:36 -0500 X-MC-Unique: yb7I_n_fPLK_PvltGKh_Yw-1 X-Mimecast-MFC-AGG-ID: yb7I_n_fPLK_PvltGKh_Yw_1740140676 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4399a5afc72so10250195e9.3 for ; Fri, 21 Feb 2025 04:24:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140675; x=1740745475; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qUA67lnlZ1kgDiClFh7mIAizVWuXk4KUx2uXWAEi+j8=; b=GROT38UovHmNCJYFHBWvcI5XLBnnZelpxyg3Li+cazqzz0w/Dht9xN5uIEX29ZV+zA Sr/7fEPhhm2dghdvtn8Q1SuaBufdDxP4X9C86oMAkXmZu4ORv8VaCPJLVNiumJ7Bh8FR nsLcscFj8DApiz30nRIdET3LAjnfXva+KGlEUNkuSTKH5fz9l88gFg7fqkOUqH+HhC4w shB/iy2qGnS5aSzY2+sb658XtpaFRT1Q9vTY25i4CaE51JpDfNY+l2HMqyXnRivDYj7J pmHu5V7j8as2NyKM9jW7ZsuNYLe6LUxeCo9NHzWD+/d7a5RzLOjK3vFJbCjm4EE1HkYz cc4w== X-Gm-Message-State: AOJu0Yx/L4FeMJx6CRDe4optSPjP+2j5ZiYqUEBj0+gfxHyUNPXEg3jw JrIwyjUtbZHc2lZTOlShWmI+zIOY6XnrjjRGx0JJqzxDpZk5+6uyLOu36qFnd1uxb9dJwa/EIX2 WwOoYT/Mlsc6RMR7hgOGOdEOMSNcFqUBodegxThIfdwAuVYiPrTaGVGwrKdZLhK0CrkC9i7En4V fG5Esf0eOClqODw5NnGScsnMJFEBUrtw== X-Gm-Gg: ASbGnctH2zKzz1fqhU1HxqTRAgEyKwjkvFgd9Lh8BdyTnrAgrkOKLnMS5Gmb7UyfSXP ScHcNPecwTdTsYzlU66EXUTfcLO4Y2XugRdOLEZfy1ljwWLpyknlYlcVo4TXIaxD4nH1uxm7S3m ijdqUjTT66MlHvwLcp9YWF6ndAAhXlosVTaXN4VkSefod0Q+m5OetkU9CyV3ZboijNSz4iew4WZ X5d6RmCZ6u8igK+TZxJK4cNVB/eQ7Jp48nj+BZ8gboZz0abkIl1+dC59CrfHoC7O5ien2Xv0eU7 uJmRTQ== X-Received: by 2002:a05:600c:500e:b0:439:8e46:ee73 with SMTP id 5b1f17b1804b1-439aeb2b5d6mr21742975e9.15.1740140675316; Fri, 21 Feb 2025 04:24:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFaeWRFRYfK0x7iyzRUjEsi1+KVod4N7DA9MqcsiQt7qtKUTUTdG4OFv4H8GnVPFQ1EiCCwVQ== X-Received: by 2002:a05:600c:500e:b0:439:8e46:ee73 with SMTP id 5b1f17b1804b1-439aeb2b5d6mr21742685e9.15.1740140674931; Fri, 21 Feb 2025 04:24:34 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258b4118sm23865508f8f.18.2025.02.21.04.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:24:34 -0800 (PST) Date: Fri, 21 Feb 2025 07:24:30 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Laurent Vivier , Stefano Brivio , Markus Armbruster , Jason Wang , Eric Blake Subject: [PULL 35/41] net: vhost-user: add QAPI events to report connection state Message-ID: <02fd9f8aeeb184276b283ae2f404bc3acf1e7b7a.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Laurent Vivier The netdev reports NETDEV_VHOST_USER_CONNECTED event when the chardev is connected, and NETDEV_VHOST_USER_DISCONNECTED when it is disconnected. The NETDEV_VHOST_USER_CONNECTED event includes the chardev id. This allows a system manager like libvirt to detect when the server fails. For instance with passt: { 'execute': 'qmp_capabilities' } { "return": { } } [killing passt here] { "timestamp": { "seconds": 1739538634, "microseconds": 920450 }, "event": "NETDEV_VHOST_USER_DISCONNECTED", "data": { "netdev-id": "netdev0" } } [automatic reconnection with reconnect-ms] { "timestamp": { "seconds": 1739538638, "microseconds": 354181 }, "event": "NETDEV_VHOST_USER_CONNECTED", "data": { "netdev-id": "netdev0", "chardev-id": "chr0" } } Tested-by: Stefano Brivio Signed-off-by: Laurent Vivier Message-Id: <20250217092550.1172055-1-lvivier@redhat.com> Acked-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- qapi/net.json | 40 ++++++++++++++++++++++++++++++++++++++++ net/vhost-user.c | 3 +++ 2 files changed, 43 insertions(+) diff --git a/qapi/net.json b/qapi/net.json index 2739a2f423..310cc4fd19 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -1031,3 +1031,43 @@ ## { 'event': 'NETDEV_STREAM_DISCONNECTED', 'data': { 'netdev-id': 'str' } } + +## +# @NETDEV_VHOST_USER_CONNECTED: +# +# Emitted when the vhost-user chardev is connected +# +# @netdev-id: QEMU netdev id that is connected +# +# @chardev-id: The character device id used by the QEMU netdev +# +# Since: 10.0 +# +# .. qmp-example:: +# +# <- { "timestamp": {"seconds": 1739538638, "microseconds": 354181 }, +# "event": "NETDEV_VHOST_USER_CONNECTED", +# "data": { "netdev-id": "netdev0", "chardev-id": "chr0" } } +# +## +{ 'event': 'NETDEV_VHOST_USER_CONNECTED', + 'data': { 'netdev-id': 'str', 'chardev-id': 'str' } } + +## +# @NETDEV_VHOST_USER_DISCONNECTED: +# +# Emitted when the vhost-user chardev is disconnected +# +# @netdev-id: QEMU netdev id that is disconnected +# +# Since: 10.0 +# +# .. qmp-example:: +# +# <- { "timestamp": { "seconds": 1739538634, "microseconds": 920450 }, +# "event": "NETDEV_VHOST_USER_DISCONNECTED", +# "data": { "netdev-id": "netdev0" } } +# +## +{ 'event': 'NETDEV_VHOST_USER_DISCONNECTED', + 'data': { 'netdev-id': 'str' } } diff --git a/net/vhost-user.c b/net/vhost-user.c index 12555518e8..0b235e50c6 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -16,6 +16,7 @@ #include "chardev/char-fe.h" #include "qapi/error.h" #include "qapi/qapi-commands-net.h" +#include "qapi/qapi-events-net.h" #include "qemu/config-file.h" #include "qemu/error-report.h" #include "qemu/option.h" @@ -271,6 +272,7 @@ static void chr_closed_bh(void *opaque) if (err) { error_report_err(err); } + qapi_event_send_netdev_vhost_user_disconnected(name); } static void net_vhost_user_event(void *opaque, QEMUChrEvent event) @@ -300,6 +302,7 @@ static void net_vhost_user_event(void *opaque, QEMUChrEvent event) net_vhost_user_watch, s); qmp_set_link(name, true, &err); s->started = true; + qapi_event_send_netdev_vhost_user_connected(name, chr->label); break; case CHR_EVENT_CLOSED: /* a close event may happen during a read/write, but vhost From patchwork Fri Feb 21 12:24:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985368 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BAB3FC021AA for ; Fri, 21 Feb 2025 12:29:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS5P-00028U-HE; Fri, 21 Feb 2025 07:24:55 -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 1tlS5F-0001F2-4W for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS5C-0007EU-Bj for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140681; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y+Y5g8wbgtarePqnIrjsvz5QinXPsEQErGBVpb/bDhs=; b=DaBHADIoPOLrGSjn5LmbojwpDnaw6sGtjRb6iH1edK0war9917uoImgYphiQFtwMBFg2U5 /7IY1WDKt0uzm1aa8p1oQVoNLw98joieGP3EoUVm75V5AnbcTK0oC5itVcChlBQhPFw4rz mQwnj85FvOsM7m+gdfRqe3sz4Gy9GJg= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-138-I-tzmKEfOlK_MT18FABBQQ-1; Fri, 21 Feb 2025 07:24:40 -0500 X-MC-Unique: I-tzmKEfOlK_MT18FABBQQ-1 X-Mimecast-MFC-AGG-ID: I-tzmKEfOlK_MT18FABBQQ_1740140679 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4399d2a1331so10852675e9.1 for ; Fri, 21 Feb 2025 04:24:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140679; x=1740745479; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=y+Y5g8wbgtarePqnIrjsvz5QinXPsEQErGBVpb/bDhs=; b=Q8IWcMzrk1OXKcXQSB67SFNdstZlFvjGYf7xjrB2jiJHlVaZ7Y90g/Ghocdo36x4Vd 74ZQvB9hNZYs9MJKp4HIbvK/rd8dSbHnqkE0O5lxeFAXIEzd+mY2us9jwqsFyfa31dVw LAfcYEyRIyKZKW0PMg9dlChvjhkswCQJdmcrxbORPcs7aRLbMtSbrzsAzStWbC5yY1K2 0osVsSyGmMbica1XxHszol71t3clfJPnSoAu6gJxuMC4tRnCeqL4QSyLU1B5vwNssk31 LnNFlKmUlvtninzmJ/MIobORMLs5OmZ6T/8vjJDIU9BjgEK0ptDv2E0vWThDaNTtAO3n CWcg== X-Gm-Message-State: AOJu0Yy3YUK6zZOF/VO1Rp7uQi4Lq7bNUUY9kLlYJAyxHWLOU0Nk2K0p JlwHFAmQRy8S23hnT3JGQFqlD0Vm9yshn4GXe3pfu3XxWiwbtpDi82MZK9PUuUYn6tAgzNvCk9K xCo7qYfcS/CEYo6xQu9juy1Rw1BmbjMxPWhuWltsXTab7XGaa8D0RlEpOUM0OuvBF4Wh0BYnRKo dUWreYaXGjtw3Esp/hBPHWhR4Z2df2Eg== X-Gm-Gg: ASbGnctmpgl/C9ZFvbFwx4djGFVY+hMibFfvridBJ42qshT77FOhjQ7YsEju7TaB5bB PPO7fqDzUOZ2brp9nbWW5j3+WSfe9gm6eFLbUTQEg/V+MXnB/H6OeZ51lPtiUC3JOI05AZNZVAC zUbET6rP6MQ3JithQA1kyDZ4mdG2qoZTe8Ew84hl+k68D+XE7B1OQp5MYFiUGgg2GQeYwGN8Mvc PA3lFFlYn1OUqbckbkzaeEn2TfOToXPV/tUc/hfWCr5NVkc3OtVpHo2y1FFNwUoInYDFcFPkHgC t0jcKA== X-Received: by 2002:a05:600c:6b66:b0:439:96a4:d2a8 with SMTP id 5b1f17b1804b1-439a2fb2c41mr56334785e9.5.1740140678858; Fri, 21 Feb 2025 04:24:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBIYq7g/aIhnFqWv6GdVkr3BQpXbN/J9tjIC8IdZtcPFONd6G8oGq4LP5nOL6C9aWpvPQl+A== X-Received: by 2002:a05:600c:6b66:b0:439:96a4:d2a8 with SMTP id 5b1f17b1804b1-439a2fb2c41mr56334425e9.5.1740140678405; Fri, 21 Feb 2025 04:24:38 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b6f8b1fesm1528215e9.32.2025.02.21.04.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:24:37 -0800 (PST) Date: Fri, 21 Feb 2025 07:24:35 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Matias Ezequiel Vara Larsen , Philippe =?utf-8?q?Mathi?= =?utf-8?q?eu-Daud=C3=A9?= , Stefano Garzarella , qemu-stable@nongnu.org, Dorinda Bassey , Alex =?utf-8?q?Benn=C3=A9e?= , Manos Pitsidianakis Subject: [PULL 36/41] vhost-user-snd: correct the calculation of config_size Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Matias Ezequiel Vara Larsen Use virtio_get_config_size() rather than sizeof(struct virtio_snd_config) for the config_size in the vhost-user-snd frontend. The frontend shall rely on device features for the size of the device configuration space. The presence of `controls` in the config space depends on VIRTIO_SND_F_CTLS according to the specification (v1.3): ` 5.14.4 Device Configuration Layout ... controls (driver-read-only) indicates a total number of all available control elements if VIRTIO_SND_F_CTLS has been negotiated. ` This fixes an issue introduced by commit ab0c7fb2 ("linux-headers: update to current kvm/next") in which the optional field `controls` is added to the virtio_snd_config structure. This breaks vhost-user-device backends that do not implement the `controls` field. Fixes: ab0c7fb22b ("linux-headers: update to current kvm/next") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2805 Reviewed-by: Philippe Mathieu-Daudé Suggested-by: Stefano Garzarella Signed-off-by: Matias Ezequiel Vara Larsen Message-Id: <20250217131255.829892-1-mvaralar@redhat.com> Cc: qemu-stable@nongnu.org Reviewed-by: Stefano Garzarella Reviewed-by: Dorinda Bassey Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-user-snd.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-user-snd.c b/hw/virtio/vhost-user-snd.c index 8610370af8..b414c75c06 100644 --- a/hw/virtio/vhost-user-snd.c +++ b/hw/virtio/vhost-user-snd.c @@ -16,6 +16,18 @@ #include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/virtio_snd.h" +static const VirtIOFeature feature_sizes[] = { + {.flags = 1ULL << VIRTIO_SND_F_CTLS, + .end = endof(struct virtio_snd_config, controls)}, + {} +}; + +static const VirtIOConfigSizeParams cfg_size_params = { + .min_size = endof(struct virtio_snd_config, chmaps), + .max_size = sizeof(struct virtio_snd_config), + .feature_sizes = feature_sizes +}; + static const VMStateDescription vu_snd_vmstate = { .name = "vhost-user-snd", .unmigratable = 1, @@ -23,16 +35,20 @@ static const VMStateDescription vu_snd_vmstate = { static const Property vsnd_properties[] = { DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), + DEFINE_PROP_BIT64("controls", VHostUserBase, + parent_obj.host_features, VIRTIO_SND_F_CTLS, false), }; static void vu_snd_base_realize(DeviceState *dev, Error **errp) { VHostUserBase *vub = VHOST_USER_BASE(dev); VHostUserBaseClass *vubs = VHOST_USER_BASE_GET_CLASS(dev); + VirtIODevice *vdev = &vub->parent_obj; vub->virtio_id = VIRTIO_ID_SOUND; vub->num_vqs = 4; - vub->config_size = sizeof(struct virtio_snd_config); + vub->config_size = virtio_get_config_size(&cfg_size_params, + vdev->host_features); vub->vq_size = 64; vubs->parent_realize(dev, errp); From patchwork Fri Feb 21 12:24:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985381 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 078F6C021AA for ; Fri, 21 Feb 2025 12:31:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS5N-0001qA-Bp; Fri, 21 Feb 2025 07:24: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 1tlS5K-0001ZV-7Q for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS5F-0007El-Ee for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140684; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4axH5wnLBbWmf0mZZ4eXxBRYfBLFNqsbFSXKtM6Ca1c=; b=YlvpTvdMAA9MYzvYwmW8GvXOHNR4mSwwg9Qz/XmmAHOhd2BiM/MXwPl33L1qK2+c6KiJY/ vLnZFujYeeC4TzEioo6UrGjktPngwUHatqi2BiT1clhD7Dac+EGMBlANdG6L8/uYBpQvbZ NYWTh1Rb3PeR8vUgm5/NRHmTDQlulHA= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-215-KD7lBZHgMmmDDH1L0mXhFQ-1; Fri, 21 Feb 2025 07:24:43 -0500 X-MC-Unique: KD7lBZHgMmmDDH1L0mXhFQ-1 X-Mimecast-MFC-AGG-ID: KD7lBZHgMmmDDH1L0mXhFQ_1740140682 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-38f4c0c1738so1762004f8f.1 for ; Fri, 21 Feb 2025 04:24:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140682; x=1740745482; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=4axH5wnLBbWmf0mZZ4eXxBRYfBLFNqsbFSXKtM6Ca1c=; b=uHSeeLz8c3eH7RO1YwXJb4kwtsI8bRNLCA1yoXPalCf8gih/yNEAFNyq6memIrw6HB uROpIO+vn18mHZmTlmH/kbqi4pQWcsMV3QJksu/7S7JM0tjc22Wqlv63+rQYi2rQofN7 KCgCm3GJ5o5j3lCuC9uCKqzoeD0UqM+vWCwpw51BpJUDNj+edx9IVRjDa/7lMhbSFPGk IAfaH3hkjC5dNcym3J6F/F+sGFKEkaD+Lu/sA94ivXExQK7t1ldd4L+GAAL7oLWidDGh KTErGwwLUk2/YkVWDBbyFZMpcTVbIxIhvYw3vY8LxUuZa2lAE0t+JOy0R4KIQHxDtDBG 0E2A== X-Gm-Message-State: AOJu0YynasEF/j0hDK4eoCrqsHg6p9u/S+O5naIZM6VmXCw+Pdk/o8BH +/OXZYoiPdGRziviJkUBIU455lnurw/xaNbiSt8fISeE+4Cv1Ab8TYyu+rNs74NK0iuUlM/YWkV DLhhDdONxvPBrkkWp+2ArmSnDaSDe6I4jt9xGFoBVGXeU9uRmmi9+97yDTPDpnYjKxvHIL+s6RX dBLkK3s/kaD1qZO0Z+82bKl9JiBWBTrA== X-Gm-Gg: ASbGncvcSh3b/Es5t8fgqmzVjPLXkm4LBnlgs4F6B2KePXd59ESSwXrOk8DV8jR3Thc rr7DFjhDfFFSDF3wInxnYewTeZ6uBCjaCnDsAyE4ZCjhkXYy7kMKu9cLBiJH66J0wq8N3nwlQfS bAdGLmDFZVIljXY1PcwKOv2B9+pamiqAyufpO5mVLpeCxRoK3mzCwbWWmUeiIWYiM66dRl901gA 3iwsJDop3axRKh1ZxkhQD8ZEJFkLMlsdFnHYt2+EwQgINBcs00/9lCifmH16vliKIdEm1Ro05Gc 2vANxQ== X-Received: by 2002:a05:6000:1fa5:b0:38f:2ddd:a1bb with SMTP id ffacd0b85a97d-38f6e7572a4mr2601437f8f.8.1740140681914; Fri, 21 Feb 2025 04:24:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgb2QoSwEnpVJ6E6eXVMY4HLbaa7xmHAySLJUcGX1p5ru24YWlfiZSBl/WBKtwdlr3HT49Jw== X-Received: by 2002:a05:6000:1fa5:b0:38f:2ddd:a1bb with SMTP id ffacd0b85a97d-38f6e7572a4mr2601407f8f.8.1740140681398; Fri, 21 Feb 2025 04:24:41 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f259f7b68sm22889517f8f.85.2025.02.21.04.24.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:24:40 -0800 (PST) Date: Fri, 21 Feb 2025 07:24:38 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Eric Auger , Zhenzhong Duan , Jason Wang , Peter Xu Subject: [PULL 37/41] hw/virtio/virtio-iommu: Migrate to 3-phase reset Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Eric Auger Currently the iommu may be reset before the devices it protects. For example this happens with virtio-net. Let's use 3-phase reset mechanism and reset the IOMMU on exit phase after all DMA capable devices have been reset during the 'enter' or 'hold' phase. Signed-off-by: Eric Auger Acked-by: Michael S. Tsirkin Reviewed-by: Zhenzhong Duan Acked-by: Jason Wang Message-Id: <20250218182737.76722-2-eric.auger@redhat.com> Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 14 ++++++++++---- hw/virtio/trace-events | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index f41104a952..b6e7e01ef7 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -1504,11 +1504,11 @@ static void virtio_iommu_device_unrealize(DeviceState *dev) virtio_cleanup(vdev); } -static void virtio_iommu_device_reset(VirtIODevice *vdev) +static void virtio_iommu_device_reset_exit(Object *obj, ResetType type) { - VirtIOIOMMU *s = VIRTIO_IOMMU(vdev); + VirtIOIOMMU *s = VIRTIO_IOMMU(obj); - trace_virtio_iommu_device_reset(); + trace_virtio_iommu_device_reset_exit(); if (s->domains) { g_tree_destroy(s->domains); @@ -1668,6 +1668,7 @@ static void virtio_iommu_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + ResettableClass *rc = RESETTABLE_CLASS(klass); device_class_set_props(dc, virtio_iommu_properties); dc->vmsd = &vmstate_virtio_iommu; @@ -1675,7 +1676,12 @@ static void virtio_iommu_class_init(ObjectClass *klass, void *data) set_bit(DEVICE_CATEGORY_MISC, dc->categories); vdc->realize = virtio_iommu_device_realize; vdc->unrealize = virtio_iommu_device_unrealize; - vdc->reset = virtio_iommu_device_reset; + + /* + * Use 'exit' reset phase to make sure all DMA requests + * have been quiesced during 'enter' or 'hold' phase + */ + rc->phases.exit = virtio_iommu_device_reset_exit; vdc->get_config = virtio_iommu_get_config; vdc->set_config = virtio_iommu_set_config; vdc->get_features = virtio_iommu_get_features; diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 04e36ae047..76f0d458b2 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -108,7 +108,7 @@ virtio_pci_notify_write(uint64_t addr, uint64_t val, unsigned int size) "0x%" PR virtio_pci_notify_write_pio(uint64_t addr, uint64_t val, unsigned int size) "0x%" PRIx64" = 0x%" PRIx64 " (%d)" # hw/virtio/virtio-iommu.c -virtio_iommu_device_reset(void) "reset!" +virtio_iommu_device_reset_exit(void) "reset!" virtio_iommu_system_reset(void) "system reset!" virtio_iommu_get_features(uint64_t features) "device supports features=0x%"PRIx64 virtio_iommu_device_status(uint8_t status) "driver status = %d" From patchwork Fri Feb 21 12:24:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985374 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D3816C021B3 for ; Fri, 21 Feb 2025 12:30:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS5P-00028l-IZ; Fri, 21 Feb 2025 07:24:55 -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 1tlS5L-0001b2-1p for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS5J-0007F5-7h for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140688; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=z4ygtfE//+SZN2f+zX5YmIK1yZQyKJU0PdMA77xslew=; b=GeaufGUJsZmDCwmKTa6NSiLIPtNPUCUbSVl8IIC3UZYTER2OjOpq1bNXdX2xE3AgIbJ6Dh fcfqx8Ew+4jVod4qlHcZ2WgusC1Uog9cizOzNBVDozdAl88qgsjkxCIMd/E64313l6s4wp 4OolDQW5h4LIsJdw18OFHr1gJ1pm0Uw= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-68-QEHEHu19N_a5fOLWoiijHw-1; Fri, 21 Feb 2025 07:24:47 -0500 X-MC-Unique: QEHEHu19N_a5fOLWoiijHw-1 X-Mimecast-MFC-AGG-ID: QEHEHu19N_a5fOLWoiijHw_1740140686 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-38f4e3e9c5bso941201f8f.1 for ; Fri, 21 Feb 2025 04:24:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140686; x=1740745486; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=z4ygtfE//+SZN2f+zX5YmIK1yZQyKJU0PdMA77xslew=; b=cbx+Qhp27ruGqlQnafU3Mdt+6hczPkbFmSzrdoMfd1Zk6ZHCK0fw7BV10S2OhaBnB8 jm7t86tGbk81s2MylKIkaovb7Z+1e6kYlnrcC5ROfvKWqwr5ImbJ/1yTZjF5nGnZ4LDy 2TUVIG2K3akIwbvadqXjzFAuOkKOB7E8fJR2eKQrWrf7SgpX5S+2nb9cdr7XvGyKwuGG DCob6wMnBViZiRBEqAmxZcX1HxKjyOpy9LedmSCLEX/zdzPqOXqwMf+WK15Pa/VS7P/9 B2v5rPPV7iFweI1n044yQkaG9ez7AWl0NwWIMDvWbKycTEz3WBrE1i+UvVs2TC1EWw4e zMog== X-Gm-Message-State: AOJu0Yw4KsQMEuLD4Ulwq7HoYhl9EorbWJmL0yRM6OG4/WVpgFn0Axs2 yWHk0/tnpeHKQ/V5F9DP68iYAAus/CHnxSyMm/WjygvdY00p/o/5h/EjRa/yqU7NqDH0cnM4dio TCSlHl7phmlreGmVeTOFG45/ALMIV1afbRbpYd/OxMOQTl6Ht6dBPvXEdX0JCnm7qy2ECey+wk0 nEntECpT+BdOHjh1QD8m5vXjZaoEF+zw== X-Gm-Gg: ASbGncvJ3BSbo/p5RNEzWngKnbGxGk/mzlkvcsl2UeQFZffeLXam7cMbgZpoOLm0zvb 0XTMo54LoK/AdHDnRUjjrDC5VnUkRCVtC3ipC38F22MSGMEXy4kRVWzLj6A68MqDfukgDYAfIr5 f+5szt1zBv0f66lObFOBUeZ9JhQe4JZZE1Kl5sOB/SrLxHXoaCgYuGu5Y7hsziua0wn67BR8qXi Wi5h1FJNM5u44Uoq7eoJLBjqX3q58bWWUt3utnvdv5rAGYQQ8Dk3FnRu5Muzh2cMFl5xPjI61ro UfZHnw== X-Received: by 2002:a5d:5848:0:b0:38f:2990:c074 with SMTP id ffacd0b85a97d-38f6e95e697mr3088099f8f.16.1740140685843; Fri, 21 Feb 2025 04:24:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFEAdCWQAFIFZ/v616ucdhekMHqtcZK/hSR9FKGYG/dGXHtJrunXzIBiWwyHzBiOLfsZ2Mf0g== X-Received: by 2002:a5d:5848:0:b0:38f:2990:c074 with SMTP id ffacd0b85a97d-38f6e95e697mr3088064f8f.16.1740140685378; Fri, 21 Feb 2025 04:24:45 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f259fe1efsm23442781f8f.97.2025.02.21.04.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:24:44 -0800 (PST) Date: Fri, 21 Feb 2025 07:24:41 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Eric Auger , Jason Wang , Peter Xu , Yi Liu , =?utf-8?q?Cl?= =?utf-8?q?=C3=A9ment?= Mathieu--Drif , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PULL 38/41] hw/i386/intel-iommu: Migrate to 3-phase reset Message-ID: <2aaf48bcf27d8b3da5b30af6c1ced464d3df30f7.1740140520.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Eric Auger Currently the IOMMU may be reset before the devices it protects. For example this happens with virtio devices but also with VFIO devices. In this latter case this produces spurious translation faults on host. Let's use 3-phase reset mechanism and reset the IOMMU on exit phase after all DMA capable devices have been reset on 'enter' or 'hold' phase. Signed-off-by: Eric Auger Acked-by: Michael S. Tsirkin Acked-by: Jason Wang Zhenzhong Duan Message-Id: <20250218182737.76722-3-eric.auger@redhat.com> Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/intel_iommu.c | 12 +++++++++--- hw/i386/trace-events | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index f366c223d0..a5cf2d0e81 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -4697,10 +4697,11 @@ static void vtd_init(IntelIOMMUState *s) /* Should not reset address_spaces when reset because devices will still use * the address space they got at first (won't ask the bus again). */ -static void vtd_reset(DeviceState *dev) +static void vtd_reset_exit(Object *obj, ResetType type) { - IntelIOMMUState *s = INTEL_IOMMU_DEVICE(dev); + IntelIOMMUState *s = INTEL_IOMMU_DEVICE(obj); + trace_vtd_reset_exit(); vtd_init(s); vtd_address_space_refresh_all(s); } @@ -4864,8 +4865,13 @@ static void vtd_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); X86IOMMUClass *x86_class = X86_IOMMU_DEVICE_CLASS(klass); + ResettableClass *rc = RESETTABLE_CLASS(klass); - device_class_set_legacy_reset(dc, vtd_reset); + /* + * Use 'exit' reset phase to make sure all DMA requests + * have been quiesced during 'enter' or 'hold' phase + */ + rc->phases.exit = vtd_reset_exit; dc->vmsd = &vtd_vmstate; device_class_set_props(dc, vtd_properties); dc->hotpluggable = false; diff --git a/hw/i386/trace-events b/hw/i386/trace-events index 53c02d7ac8..ac9e1a10aa 100644 --- a/hw/i386/trace-events +++ b/hw/i386/trace-events @@ -68,6 +68,7 @@ vtd_frr_new(int index, uint64_t hi, uint64_t lo) "index %d high 0x%"PRIx64" low vtd_warn_invalid_qi_tail(uint16_t tail) "tail 0x%"PRIx16 vtd_warn_ir_vector(uint16_t sid, int index, int vec, int target) "sid 0x%"PRIx16" index %d vec %d (should be: %d)" vtd_warn_ir_trigger(uint16_t sid, int index, int trig, int target) "sid 0x%"PRIx16" index %d trigger %d (should be: %d)" +vtd_reset_exit(void) "" # amd_iommu.c amdvi_evntlog_fail(uint64_t addr, uint32_t head) "error: fail to write at addr 0x%"PRIx64" + offset 0x%"PRIx32 From patchwork Fri Feb 21 12:24:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985371 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BCA38C021B3 for ; Fri, 21 Feb 2025 12:29:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS5T-0002XN-HM; Fri, 21 Feb 2025 07:24:59 -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 1tlS5O-000220-P3 for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS5M-0007Fd-QM for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140692; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=EBrAYudfN30eTDxsGlpkwQ5zRuzxrz1/bLUV220VFQI=; b=F2edohw3lZ3OM4n8gSLnfn1Dy8xsGniYwRIuLCUj+/H3dbqmdoxceCszA3P4jn1/AHk3zS kWShQea96gyHwO7hHgpX0n3A8S/CcsshLdcuLTH+PI3pMrkjm+oRMAtr2pyQUuLAS73NDv ZYZUcFkpg/K59C7B4N9Mm2/kgEEIkPE= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-9-DCDNizhyMLeCEixwv6WLRg-1; Fri, 21 Feb 2025 07:24:50 -0500 X-MC-Unique: DCDNizhyMLeCEixwv6WLRg-1 X-Mimecast-MFC-AGG-ID: DCDNizhyMLeCEixwv6WLRg_1740140690 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-38f36fcf4b3so1229556f8f.1 for ; Fri, 21 Feb 2025 04:24:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140689; x=1740745489; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=EBrAYudfN30eTDxsGlpkwQ5zRuzxrz1/bLUV220VFQI=; b=aT6WeTSA6b7ApHcSYFa8IGctDOMhrbxL1SuxvnNWcqIXbdz6Vbwe1p2nWgtAKABWqQ Mmi+Q/M+eEOl2YyOPo585PjBRPXSrxOozZBkiGs5iETHC3cWyMT/vKqKmcmWo7U9OyQt ASrrV4/GJLhL/CBLYzJQuACQkJPMzzmR7Ixu3ii6dyiv1qHBemgctaRasxQF7mYhE18j eodH52B1RuhKGPqVFqvNNz79wisMLbksKmBkUL2C0Qiu12vUU7dkb+9sa3Wt06ECFV0K 96RU+T2vUALtxXecuccVKUwpJgxUnW2XDCy+CO4ybD2ZWDYEsl+c+tnCrhjnDAGH2hLm thew== X-Gm-Message-State: AOJu0Yx69hy5yO94ieAuIDVq6Pi1JZKiN+t0M6NYpjujbXdCNy9/y0jg JPuQFVLZDrgdPacQ9dS4BsYzn1uKZRPZdOcxLyktQUU3+M3860Zrp+v60sHPVMlOTVsmf1tcJ4s CUU9gNE5DeRQLmCMSd2wzkyKu7Uyyil/tK0G3fdQ1Wu8R3CMvOhzMcub/7ZX+nofVjLDr2FITSA sJe1XujrmhjrG8ZGZUt8phJjvNqIu2aQ== X-Gm-Gg: ASbGncuzTs3/FD9ZiuPSH1kpy8Hc57jDs7bG1w6BRAMCsRsJwDvYD5Ny/8NXTXaBd/+ IJa0HyWCSafYNqd/ZTNgfeZsOTCNKK1g7XIwNxdoayA+sIW7ICjF4lLt05cuzFh3spKGz+/kcSF mXwONr/CIqO+5RLOW39rdsxbuJcRKlki+8Lm1OgXxneDXrczumRoIj5LKKsz0Yw4/4SbG6lA0V0 Q/3jklS7seNtRUfNK2xqIfrm+WnqKSCuY9AUe1Ci+INCfPuQBLYeli56Pr2T5Sr5eDmmsjTVf1V uRLtrw== X-Received: by 2002:a05:6000:178d:b0:38f:4263:9d62 with SMTP id ffacd0b85a97d-38f6e9791acmr2815549f8f.27.1740140689147; Fri, 21 Feb 2025 04:24:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFp32AULRbmy01GSTfnKC2IjEC3TBFgsu2vbO9S8ZHJwsJenQ6kGgbMF8w2rfBY0Cmk08V9sg== X-Received: by 2002:a05:6000:178d:b0:38f:4263:9d62 with SMTP id ffacd0b85a97d-38f6e9791acmr2815517f8f.27.1740140688648; Fri, 21 Feb 2025 04:24:48 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f259d65dfsm23693257f8f.64.2025.02.21.04.24.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:24:48 -0800 (PST) Date: Fri, 21 Feb 2025 07:24:45 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Eric Auger , Zhenzhong Duan , Peter Xu , qemu-arm@nongnu.org Subject: [PULL 39/41] hw/arm/smmuv3: Move reset to exit phase Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Eric Auger Currently the iommu may be reset before the devices it protects. For example this happens with virtio-scsi-pci. when system_reset is issued from qmp monitor: spurious "virtio: zero sized buffers are not allowed" warnings can be observed. This happens because outstanding DMA requests are still happening while the SMMU gets reset. This can also happen with VFIO devices. In that case spurious DMA translation faults can be observed on host. Make sure the SMMU is reset in the 'exit' phase after all DMA capable devices have been reset during the 'enter' or 'hold' phase. Signed-off-by: Eric Auger Reviewed-by: Zhenzhong Duan Message-Id: <20250218182737.76722-4-eric.auger@redhat.com> Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/arm/smmu-common.c | 9 +++++++-- hw/arm/smmuv3.c | 14 ++++++++++---- hw/arm/trace-events | 1 + 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index dd74c2e558..8c1b407b82 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -924,7 +924,12 @@ static void smmu_base_realize(DeviceState *dev, Error **errp) } } -static void smmu_base_reset_hold(Object *obj, ResetType type) +/* + * Make sure the IOMMU is reset in 'exit' phase after + * all outstanding DMA requests have been quiesced during + * the 'enter' or 'hold' reset phases + */ +static void smmu_base_reset_exit(Object *obj, ResetType type) { SMMUState *s = ARM_SMMU(obj); @@ -949,7 +954,7 @@ static void smmu_base_class_init(ObjectClass *klass, void *data) device_class_set_props(dc, smmu_dev_properties); device_class_set_parent_realize(dc, smmu_base_realize, &sbc->parent_realize); - rc->phases.hold = smmu_base_reset_hold; + rc->phases.exit = smmu_base_reset_exit; } static const TypeInfo smmu_base_info = { diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index c0cf5df0f6..b49a59b64c 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1870,13 +1870,19 @@ static void smmu_init_irq(SMMUv3State *s, SysBusDevice *dev) } } -static void smmu_reset_hold(Object *obj, ResetType type) +/* + * Make sure the IOMMU is reset in 'exit' phase after + * all outstanding DMA requests have been quiesced during + * the 'enter' or 'hold' reset phases + */ +static void smmu_reset_exit(Object *obj, ResetType type) { SMMUv3State *s = ARM_SMMUV3(obj); SMMUv3Class *c = ARM_SMMUV3_GET_CLASS(s); - if (c->parent_phases.hold) { - c->parent_phases.hold(obj, type); + trace_smmu_reset_exit(); + if (c->parent_phases.exit) { + c->parent_phases.exit(obj, type); } smmuv3_init_regs(s); @@ -1999,7 +2005,7 @@ static void smmuv3_class_init(ObjectClass *klass, void *data) SMMUv3Class *c = ARM_SMMUV3_CLASS(klass); dc->vmsd = &vmstate_smmuv3; - resettable_class_set_parent_phases(rc, NULL, smmu_reset_hold, NULL, + resettable_class_set_parent_phases(rc, NULL, NULL, smmu_reset_exit, &c->parent_phases); device_class_set_parent_realize(dc, smmu_realize, &c->parent_realize); diff --git a/hw/arm/trace-events b/hw/arm/trace-events index c64ad344bd..7790db780e 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -56,6 +56,7 @@ smmuv3_config_cache_inv(uint32_t sid) "Config cache INV for sid=0x%x" smmuv3_notify_flag_add(const char *iommu) "ADD SMMUNotifier node for iommu mr=%s" smmuv3_notify_flag_del(const char *iommu) "DEL SMMUNotifier node for iommu mr=%s" smmuv3_inv_notifiers_iova(const char *name, int asid, int vmid, uint64_t iova, uint8_t tg, uint64_t num_pages, int stage) "iommu mr=%s asid=%d vmid=%d iova=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64" stage=%d" +smmu_reset_exit(void) "" # strongarm.c strongarm_uart_update_parameters(const char *label, int speed, char parity, int data_bits, int stop_bits) "%s speed=%d parity=%c data=%d stop=%d" From patchwork Fri Feb 21 12:24:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985357 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8999BC021AA for ; Fri, 21 Feb 2025 12:25:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS5Y-000387-OI; Fri, 21 Feb 2025 07:25:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS5S-0002Ws-Kd for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS5Q-0007Fx-5T for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:24:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140695; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7AoCeBbkagUX8Kyv4XqGNujI5QUp6oIuMdoxn2XTqVk=; b=ecqmbU6RdVHtJQGMKB//SKxDrfkBceXR2+v/64BkWBs874m6YA6oAxF16WnZORvWEo2/SM ECy3EDPsGsUAK49dvIeH2ib0KZZS6pQE6O3jBMXRamkBup6GvYid5O8pTe5JEPRVZN6MRc 5sNLhbcHjwjq2xG0xrpMf2zB9XeqmUg= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-654-YnydFCNOOQSY8tgy7HAz9w-1; Fri, 21 Feb 2025 07:24:54 -0500 X-MC-Unique: YnydFCNOOQSY8tgy7HAz9w-1 X-Mimecast-MFC-AGG-ID: YnydFCNOOQSY8tgy7HAz9w_1740140693 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4399a5afc72so10251115e9.3 for ; Fri, 21 Feb 2025 04:24:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140692; x=1740745492; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7AoCeBbkagUX8Kyv4XqGNujI5QUp6oIuMdoxn2XTqVk=; b=GncP+wwrg4myeNus4i/D3VsOuZEsxn1HhuOcNP5c2iCbY0g6y6i7j8i6shrxAVcZRV 0Ka7IZ9Dl7zTYmSe8EH9Xz95PqLzCY9xa89VL7SAOri2Jo4PvBB7M7rqzANUfIJvRM/l cj/eoXV9mIT7tVc9Gh+bmROenElERpe8bjO4Djs6s1F7j8wrvP+AGaGqWYTreh7TgTzP xZdsk9qGwVIwJODQRjBZLBzHy3H1YhM940q/pMOAmCLfCu+KoZFpMotRoljW5vDmhZIt TrXuTi2WtCeSjVAu8vu9HzFUXAsk6nvlBzuFfYXK+dgS2S0EQ3rbqBtOCBl/eC2l4YDS ISfg== X-Gm-Message-State: AOJu0YwQ3zdSm7N+VjntN2xc7H8A2dVIoc+2PaIgivWRYB8eC3ndunNN nYeyRBU4jdA3W7nqRaAMSakJoky40c5XW8DTTbEqoLAiRnEFRravdjyyYhw/VnWnG3g3jCbz65S 7RB7RwsSlyIDPFQXEZLqbs7FPfz3mCRI670vr17dxtQdaR/D3HmsOaDuuBbIMzL9ELL0XQsl3/0 st+cX99O8ULuo3WeQXQLYZsqpkaOh6Hg== X-Gm-Gg: ASbGnctZ0OsKBpkDJY2lSHFp6Bw3JmsH8FtLJruWIbB1ud4LNCaoKmGCPDIsKBw1iyn p2ankuLciYJQddJYcAbaqhmao/QqOtvx5CBIYaeod0UZ4DlW63bVpLTXK/uzgQUi1XHAFVnzPRU Hb9Y77VyP+mQ7aObmojyK3JUchXKWS2FM7N9xXp5SIb9YmNwLtRC5FN0KZ2KVk9SQ03RCShVPxi KsNpgy0Msjrig+WLkFMbvd7egRwGwh1xixey0Xt5s/Ffe8DV4H+WWOwpke7RWYqBjsGFFo7Cbh4 j8nFhA== X-Received: by 2002:a05:600c:3548:b0:439:a138:1d with SMTP id 5b1f17b1804b1-439aebc2408mr18512765e9.22.1740140692570; Fri, 21 Feb 2025 04:24:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IEC1S3BVBIVp6Aq5M9p4iY9jtpnipohLmI5OfqtcZ9IuH+TJxJwTRR89FVJi6u+C4uJxcbysQ== X-Received: by 2002:a05:600c:3548:b0:439:a138:1d with SMTP id 5b1f17b1804b1-439aebc2408mr18512445e9.22.1740140692044; Fri, 21 Feb 2025 04:24:52 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02d8859sm15613625e9.16.2025.02.21.04.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:24:51 -0800 (PST) Date: Fri, 21 Feb 2025 07:24:48 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Eric Auger , =?utf-8?q?C=C3=A9dric?= Le Goater , Zhenzhong Duan , Peter Xu , Alex Williamson Subject: [PULL 40/41] hw/vfio/common: Add a trace point in vfio_reset_handler Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Eric Auger To ease the debug of reset sequence, let's add a trace point in vfio_reset_handler() Signed-off-by: Eric Auger Reviewed-by: Cédric Le Goater Acked-by: Michael S. Tsirkin Reviewed-by: Zhenzhong Duan Message-Id: <20250218182737.76722-5-eric.auger@redhat.com> Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/vfio/common.c | 1 + hw/vfio/trace-events | 1 + 2 files changed, 2 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index f7499a9b74..173fb3a997 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1386,6 +1386,7 @@ void vfio_reset_handler(void *opaque) { VFIODevice *vbasedev; + trace_vfio_reset_handler(); QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) { if (vbasedev->dev->realized) { vbasedev->ops->vfio_compute_needs_reset(vbasedev); diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index cab1cf1de0..c5385e1a4f 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -120,6 +120,7 @@ vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t subtype vfio_legacy_dma_unmap_overflow_workaround(void) "" vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64 vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64 +vfio_reset_handler(void) "" # platform.c vfio_platform_realize(char *name, char *compat) "vfio device %s, compat = %s" From patchwork Fri Feb 21 12:24:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13985360 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DBC5AC021AA for ; Fri, 21 Feb 2025 12:28:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlS5Z-0003Ag-HM; Fri, 21 Feb 2025 07:25:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS5V-0002vz-Km for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:25:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlS5T-0007GH-RJ for qemu-devel@nongnu.org; Fri, 21 Feb 2025 07:25:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740140699; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=I0OkFCZq8v0ezATiJzoCyWDoQl7Sr4+CP54xKEjqIMM=; b=Ar84hrt6rRC0c7/4PeGtgtXSOXsHZXB0wx8tz6wcVVUBQcQGQ4d0POfBxiirqJMvWtqZAq NCEPHkVbNc9n8ZaJSQH1XyZFrIECk8JxYEiSf1obEqMSZyjfKYS7k4sl/VD4+XkpJ3mHYi YJNjn+5tm6Hkqx07s91xXm/PNKGHhZo= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-600-RKQWpiuiP4eTqM_CqD4sLA-1; Fri, 21 Feb 2025 07:24:57 -0500 X-MC-Unique: RKQWpiuiP4eTqM_CqD4sLA-1 X-Mimecast-MFC-AGG-ID: RKQWpiuiP4eTqM_CqD4sLA_1740140697 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43943bd1409so14811695e9.3 for ; Fri, 21 Feb 2025 04:24:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740140696; x=1740745496; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=I0OkFCZq8v0ezATiJzoCyWDoQl7Sr4+CP54xKEjqIMM=; b=nE/oDWe/KWKW8kT3OIDw1U0Br8YEzV74+uE9N7/M8nZT0wiBBrJkTVDFc9TIjo8pP7 rbVV5TU/M4NlrlZrVkc5GHKryPi9n2KT9bh74MHCMKrEh5WqBIO1gfOr77ZzY1FUTfly 8KROW0rmrY9vYxztXPFRbO1l0r7GCJ+rJ5rk3U/9YARA+wHwILEf+bC2SIYy12h+ZtHt mwxVUxdil/lqO/hI4mDfyPP0qCfJnCLemz8P31UCtq6lG0z84HeIjiu7v2o8pTzkpOhk Qirjvq3CQGh6BpY7LSkkfz0GsASXNjBfaNIiwy3a3hxDMt2dnrNoQ4Gri5QS0qK29+QK 2ZUQ== X-Gm-Message-State: AOJu0YwKZ/jbutESI4O95hJ5kdxGLl7QotQ4Xht20v1HSLQWI3ga1+v6 C5WJ6aUHyF4eINgzVNGVloeH51iT9rKAaPoNyWJnbndoOlTvNjZmxHR/Jeuy64nbCgEV8Iuql4Z tyUCy7KjQsNzxm98ZyUH2CtaMMbSb/T0j+s+swdBsuyqyRWGwAM3lyA+5Jh6P0QWhVlY+jxnfI1 oZEywH2LsbHIsegq106kAfZ2Hv3spdPA== X-Gm-Gg: ASbGnctBLh0WpD0+6EaijCd92cgXWtE9OC39qS43w58vkOqyvlixkoPRjE31Q9LQMvM 7rsdiM24cFkUAv9BgGvCxK1Q7EC3aHuC2/DTu73QyoHYQtPvtdnmorgWj3V5Bt36CgR6E/EmQay XR2IWf8eX1PhGD4eipglTGSNoLXFIFEEj1fqld5HafYZX/Yv5DiNDG1eMaodAN/otwrZ/+eTUs1 Bi1WvRt9Gyei09S74Pk3s49R6aWgjaPoLOH5eIgkKttUwsYfV+I/KqBjNtDZy4ll0wbNsupC9aK wsSanA== X-Received: by 2002:a05:6000:1865:b0:38f:32ac:7e53 with SMTP id ffacd0b85a97d-38f6f0b189dmr2926310f8f.39.1740140695946; Fri, 21 Feb 2025 04:24:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1VdlP3nDv9m/QVmbN66yECgtSWRc76CHq+MPgAz5kk0JJkt5SGKyisEDedvAy6RtJeKfIHQ== X-Received: by 2002:a05:6000:1865:b0:38f:32ac:7e53 with SMTP id ffacd0b85a97d-38f6f0b189dmr2926280f8f.39.1740140695503; Fri, 21 Feb 2025 04:24:55 -0800 (PST) Received: from redhat.com ([31.187.78.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258ccd51sm23265433f8f.29.2025.02.21.04.24.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2025 04:24:55 -0800 (PST) Date: Fri, 21 Feb 2025 07:24:52 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Eric Auger , Zhenzhong Duan , Peter Xu , Richard Henderson , Philippe =?utf-8?q?Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Luc Michel Subject: [PULL 41/41] docs/devel/reset: Document reset expectations for DMA and IOMMU Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.424, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Eric Auger To avoid any translation faults, the IOMMUs are expected to be reset after the devices they protect. Document that we expect DMA requests to be stopped during the 'enter' or 'hold' phase while IOMMUs should be reset during the 'exit' phase. Signed-off-by: Eric Auger Reviewed-by: Zhenzhong Duan Message-Id: <20250218182737.76722-6-eric.auger@redhat.com> Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- docs/devel/reset.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/devel/reset.rst b/docs/devel/reset.rst index adefd59ef9..0b8b2fa5f4 100644 --- a/docs/devel/reset.rst +++ b/docs/devel/reset.rst @@ -143,6 +143,11 @@ The *exit* phase is executed only when the last reset operation ends. Therefore the object does not need to care how many of reset controllers it has and how many of them have started a reset. +DMA capable devices are expected to cancel all outstanding DMA operations +during either 'enter' or 'hold' phases. IOMMUs are expected to reset during +the 'exit' phase and this sequencing makes sure no outstanding DMA request +will fault. + Handling reset in a resettable object -------------------------------------