From patchwork Mon Mar 15 09:14:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453118 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KC8QVRcC; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzW3h1qnfz9sVm for ; Mon, 15 Mar 2021 20:15:28 +1100 (AEDT) Received: from localhost ([::1]:52996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjJu-0007LH-81 for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:15:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjJH-0007KC-Rb for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:14:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:34442) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjJG-0007Vi-6T for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:14:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799685; 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=5zEzMfg/wj4Rhh5BSpxXPJCT+SYE/L9MbBTqBoF1i98=; b=KC8QVRcClqsMUhILpVP884MNNY6QRsI84xcSoi2KMU3gNf4e7ecn/pszyrDVkYpXwRZ0P+ Jcq4Yr9EulQ8E9VF8Jq6tR5gDc14WKnJg2knUD61KQNEFGXQCbYKubkDrGuvGm45NIwFL7 3OH+E1gQWy25bCYMxrpDRy8KdbxvvyE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-598-x-0IsAqJOIyb-4lYW7zG5A-1; Mon, 15 Mar 2021 05:14:44 -0400 X-MC-Unique: x-0IsAqJOIyb-4lYW7zG5A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 108D2107ACCD; Mon, 15 Mar 2021 09:14:43 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5346100164C; Mon, 15 Mar 2021 09:14:41 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 01/20] virtio-net: calculating proper msix vectors on init Date: Mon, 15 Mar 2021 17:14:14 +0800 Message-Id: <1615799673-31549-2-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Currently, the default msix vectors for virtio-net-pci is 3 which is obvious not suitable for multiqueue guest, so we depends on the user or management tools to pass a correct vectors parameter. In fact, we can simplifying this by calculating the number of vectors on realize. Consider we have N queues, the number of vectors needed is 2*N + 2 (#queue pairs + plus one config interrupt and control vq). We didn't check whether or not host support control vq because it was added unconditionally by qemu to avoid breaking legacy guests such as Minix. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Stefan Hajnoczi Signed-off-by: Jason Wang --- hw/core/machine.c | 1 + hw/virtio/virtio-net-pci.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 4386f57..979133f 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -39,6 +39,7 @@ GlobalProperty hw_compat_5_2[] = { { "ICH9-LPC", "smm-compat", "on"}, { "PIIX4_PM", "smm-compat", "on"}, + { "virtio-net-pci", "vectors", "3"}, }; const size_t hw_compat_5_2_len = G_N_ELEMENTS(hw_compat_5_2); diff --git a/hw/virtio/virtio-net-pci.c b/hw/virtio/virtio-net-pci.c index 292d13d..aa0b3ca 100644 --- a/hw/virtio/virtio-net-pci.c +++ b/hw/virtio/virtio-net-pci.c @@ -41,7 +41,8 @@ struct VirtIONetPCI { static Property virtio_net_properties[] = { DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), - DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3), + DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, + DEV_NVECTORS_UNSPECIFIED), DEFINE_PROP_END_OF_LIST(), }; @@ -50,6 +51,13 @@ static void virtio_net_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) DeviceState *qdev = DEVICE(vpci_dev); VirtIONetPCI *dev = VIRTIO_NET_PCI(vpci_dev); DeviceState *vdev = DEVICE(&dev->vdev); + VirtIONet *net = VIRTIO_NET(vdev); + + if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { + vpci_dev->nvectors = 2 * MAX(net->nic_conf.peers.queues, 1) + + 1 /* Config interrupt */ + + 1 /* Control vq */; + } virtio_net_set_netclient_name(&dev->vdev, qdev->id, object_get_typename(OBJECT(qdev))); From patchwork Mon Mar 15 09:14:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453120 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=V7xDcPqF; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzW3s6Xnkz9sWF for ; Mon, 15 Mar 2021 20:15:37 +1100 (AEDT) Received: from localhost ([::1]:53332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjK3-0007UO-Rg for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:15:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35128) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjJN-0007T2-Ef for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:14:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41562) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjJL-0007ad-SH for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:14:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799691; 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=UCs6u+KmEIKuSlel5gDgsoyTIyhIq4RLDUa5JAb9Xts=; b=V7xDcPqFGT4d7w/Ug0QKwBWORjqbp8/tCDpd5QF8DIDMJi8NaUS+eVUu1GZlcv5oS5vXxd lUPh9IS2NqnnOSS/7NbuG2FzSLkMCz2DDL3YEoFO5eM14gix7T69cszoW61HxbtX9KQxp7 D8qusB8AW5ssrKKyHSzGgDR6OOJRfEo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-495-nddpN3dGOkKLgRCl_hDmYg-1; Mon, 15 Mar 2021 05:14:49 -0400 X-MC-Unique: nddpN3dGOkKLgRCl_hDmYg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CDDF8100C621; Mon, 15 Mar 2021 09:14:47 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91750100164C; Mon, 15 Mar 2021 09:14:43 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 02/20] net: Fix build error when DEBUG_NET is on Date: Mon, 15 Mar 2021 17:14:15 +0800 Message-Id: <1615799673-31549-3-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Bin Meng , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Bin Meng "qemu-common.h" should be included to provide the forward declaration of qemu_hexdump() when DEBUG_NET is on. Signed-off-by: Bin Meng Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Jason Wang --- net/net.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/net.c b/net/net.c index 9a2a4c9..16a87cc 100644 --- a/net/net.c +++ b/net/net.c @@ -23,6 +23,7 @@ */ #include "qemu/osdep.h" +#include "qemu-common.h" #include "net/net.h" #include "clients.h" From patchwork Mon Mar 15 09:14:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453123 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dmSsSHHj; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzW7M4HN0z9sVm for ; Mon, 15 Mar 2021 20:18:39 +1100 (AEDT) Received: from localhost ([::1]:32792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjMz-0002TG-IJ for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:18:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35140) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjJS-0007e4-Ea for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:14:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:37778) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjJQ-0007eH-Pg for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:14:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799696; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type:in-reply-to:in-reply-to: references:references; bh=e9UQYhxlWEU9Mu20iWeA4OMqZZIO/1zzU2SifCrGhZU=; b=dmSsSHHj+qSMCD8UbJkLUqt+ret0ioTNYjITRBAlb9pL4LZnYBxC1T1BRE4xUQs0L5gb6q 3BWltCotylG5jkvWAYBJrLun05yAft+oGo92GX2gmHCGR56b2xsJNaR5/kTTnPbAodIHkF kxPbfhEWmmAavak6pfhi5JVRi7C8S7Q= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-302-JBnhB3fGPiCUimRKKutAhw-1; Mon, 15 Mar 2021 05:14:53 -0400 X-MC-Unique: JBnhB3fGPiCUimRKKutAhw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E230A805727; Mon, 15 Mar 2021 09:14:52 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DC17100164C; Mon, 15 Mar 2021 09:14:48 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 03/20] net: validate that ids are well formed Date: Mon, 15 Mar 2021 17:14:16 +0800 Message-Id: <1615799673-31549-4-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Jason Wang , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Paolo Bonzini When a network or network device is created from the command line or HMP, QemuOpts ensures that the id passes the id_wellformed check. However, QMP skips this: $ qemu-system-x86_64 -qmp stdio -S -nic user,id=123/456 qemu-system-x86_64: -nic user,id=123/456: Parameter id expects an identifier Identifiers consist of letters, digits, -, ., _, starting with a letter. $ qemu-system-x86_64 -qmp stdio -S {"execute":"qmp_capabilities"} {"return": {}} {"execute":"netdev_add", "arguments": {"type": "user", "id": "123/456"}} {"return": {}} After: $ qemu-system-x86_64 -qmp stdio -S {"execute":"qmp_capabilities"} {"return": {}} {"execute":"netdev_add", "arguments": {"type": "user", "id": "123/456"}} {"error": {"class": "GenericError", "desc": "Parameter "id" expects an identifier"}} Validity checks should be performed always at the bottom of the call chain, because QMP skips all the steps above. At the same time we know that every call chain should go through either QMP or (for legacy) through QemuOpts. Because the id for -net and -nic is automatically generated and not well-formed by design, just add the check to QMP. Cc: Jason Wang Signed-off-by: Paolo Bonzini Signed-off-by: Jason Wang --- net/net.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/net.c b/net/net.c index 16a87cc..77b35ea 100644 --- a/net/net.c +++ b/net/net.c @@ -1134,6 +1134,11 @@ void netdev_add(QemuOpts *opts, Error **errp) void qmp_netdev_add(Netdev *netdev, Error **errp) { + if (!id_wellformed(netdev->id)) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id", "an identifier"); + return; + } + net_client_init1(netdev, true, errp); } From patchwork Mon Mar 15 09:14:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453124 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=cxN/nn4/; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzW7Q5YsRz9sVm for ; Mon, 15 Mar 2021 20:18:42 +1100 (AEDT) Received: from localhost ([::1]:33150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjN2-0002cF-Oq for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:18:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjJV-0007jr-5g for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22030) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjJS-0007gQ-Ql for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799697; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type:in-reply-to:in-reply-to: references:references; bh=cHDylX3VDgnAxGpHNhSOXdMfRX+mhcDAqVY6r7JPZHo=; b=cxN/nn4/cYBkhee9YsQrI2ebtrEYZwAqYQbLWg6Rev03MNy3GA7MD6djoNu4he8dMn6wBo K9fRcg2/vjjxRYhhnZbovWIdhBb0wvcLdESVAuOoTzG5/N/73VSBBTiSnGEdXbHsKsDRMQ LynaxmX2RebAPEwluIMJnVhOF2uMfhI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-64-ghufpY7_NhOCyiAc1_uDjg-1; Mon, 15 Mar 2021 05:14:56 -0400 X-MC-Unique: ghufpY7_NhOCyiAc1_uDjg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5E37C8042BE; Mon, 15 Mar 2021 09:14:55 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F70C1007625; Mon, 15 Mar 2021 09:14:53 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 04/20] e1000: fail early for evil descriptor Date: Mon, 15 Mar 2021 17:14:17 +0800 Message-Id: <1615799673-31549-5-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" During procss_tx_desc(), driver can try to chain data descriptor with legacy descriptor, when will lead underflow for the following calculation in process_tx_desc() for bytes: if (tp->size + bytes > msh) bytes = msh - tp->size; This will lead a infinite loop. So check and fail early if tp->size if greater or equal to msh. Reported-by: Alexander Bulekov Reported-by: Cheolwoo Myung Reported-by: Ruhr-University Bochum Cc: Prasad J Pandit Cc: qemu-stable@nongnu.org Signed-off-by: Jason Wang --- hw/net/e1000.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index d8da2f6..4345d86 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -670,6 +670,9 @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp) msh = tp->tso_props.hdr_len + tp->tso_props.mss; do { bytes = split_size; + if (tp->size >= msh) { + goto eop; + } if (tp->size + bytes > msh) bytes = msh - tp->size; @@ -695,6 +698,7 @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp) tp->size += split_size; } +eop: if (!(txd_lower & E1000_TXD_CMD_EOP)) return; if (!(tp->cptse && tp->size < tp->tso_props.hdr_len)) { From patchwork Mon Mar 15 09:14:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453122 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Ut/mXP4D; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzW7K4LHkz9sVm for ; Mon, 15 Mar 2021 20:18:36 +1100 (AEDT) Received: from localhost ([::1]:60630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjMw-0002J9-0z for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:18:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjJX-0007od-Ro for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:35517) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjJV-0007iT-Dy for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799700; 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=wztnDkp2Vgs1w2guSSyW35cz9bp2eArQYIOdjsh3M24=; b=Ut/mXP4DN0zON3g1OmRPQPDJjiLvuk9GC3vuIHTJWej3+zPyctL+rWcjXNJamv2+T9qWSM C/YZWv4bNwNgmQ4e+vfZJFDRCFv6NIydFeCQ/gFZtDtMwAHLLFeg2Vr+ClWzyFhXoRtU2C kM3u6e5o5yRYSVCvBrSH8KBXyuT873A= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-446-qshcxG8OPUOEdcMw0d8jrw-1; Mon, 15 Mar 2021 05:14:58 -0400 X-MC-Unique: qshcxG8OPUOEdcMw0d8jrw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CFDBD107465E; Mon, 15 Mar 2021 09:14:57 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id E06671007625; Mon, 15 Mar 2021 09:14:55 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 05/20] net: introduce qemu_receive_packet() Date: Mon, 15 Mar 2021 17:14:18 +0800 Message-Id: <1615799673-31549-6-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Some NIC supports loopback mode and this is done by calling nc->info->receive() directly which in fact suppresses the effort of reentrancy check that is done in qemu_net_queue_send(). Unfortunately we can't use qemu_net_queue_send() here since for loopback there's no sender as peer, so this patch introduce a qemu_receive_packet() which is used for implementing loopback mode for a NIC with this check. NIC that supports loopback mode will be converted to this helper. This is intended to address CVE-2021-3416. Cc: Prasad J Pandit Reviewed-by: Philippe Mathieu-Daudé Cc: qemu-stable@nongnu.org Signed-off-by: Jason Wang --- include/net/net.h | 5 +++++ include/net/queue.h | 8 ++++++++ net/net.c | 38 +++++++++++++++++++++++++++++++------- net/queue.c | 22 ++++++++++++++++++++++ 4 files changed, 66 insertions(+), 7 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 919faca..4f56cae 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -144,12 +144,17 @@ void *qemu_get_nic_opaque(NetClientState *nc); void qemu_del_net_client(NetClientState *nc); typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque); void qemu_foreach_nic(qemu_nic_foreach func, void *opaque); +int qemu_can_receive_packet(NetClientState *nc); int qemu_can_send_packet(NetClientState *nc); ssize_t qemu_sendv_packet(NetClientState *nc, const struct iovec *iov, int iovcnt); ssize_t qemu_sendv_packet_async(NetClientState *nc, const struct iovec *iov, int iovcnt, NetPacketSent *sent_cb); ssize_t qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size); +ssize_t qemu_receive_packet(NetClientState *nc, const uint8_t *buf, int size); +ssize_t qemu_receive_packet_iov(NetClientState *nc, + const struct iovec *iov, + int iovcnt); ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size); ssize_t qemu_send_packet_async(NetClientState *nc, const uint8_t *buf, int size, NetPacketSent *sent_cb); diff --git a/include/net/queue.h b/include/net/queue.h index c0269bb..9f2f289 100644 --- a/include/net/queue.h +++ b/include/net/queue.h @@ -55,6 +55,14 @@ void qemu_net_queue_append_iov(NetQueue *queue, void qemu_del_net_queue(NetQueue *queue); +ssize_t qemu_net_queue_receive(NetQueue *queue, + const uint8_t *data, + size_t size); + +ssize_t qemu_net_queue_receive_iov(NetQueue *queue, + const struct iovec *iov, + int iovcnt); + ssize_t qemu_net_queue_send(NetQueue *queue, NetClientState *sender, unsigned flags, diff --git a/net/net.c b/net/net.c index 77b35ea..edf9b95 100644 --- a/net/net.c +++ b/net/net.c @@ -529,6 +529,17 @@ int qemu_set_vnet_be(NetClientState *nc, bool is_be) #endif } +int qemu_can_receive_packet(NetClientState *nc) +{ + if (nc->receive_disabled) { + return 0; + } else if (nc->info->can_receive && + !nc->info->can_receive(nc)) { + return 0; + } + return 1; +} + int qemu_can_send_packet(NetClientState *sender) { int vm_running = runstate_is_running(); @@ -541,13 +552,7 @@ int qemu_can_send_packet(NetClientState *sender) return 1; } - if (sender->peer->receive_disabled) { - return 0; - } else if (sender->peer->info->can_receive && - !sender->peer->info->can_receive(sender->peer)) { - return 0; - } - return 1; + return qemu_can_receive_packet(sender->peer); } static ssize_t filter_receive_iov(NetClientState *nc, @@ -680,6 +685,25 @@ ssize_t qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size) return qemu_send_packet_async(nc, buf, size, NULL); } +ssize_t qemu_receive_packet(NetClientState *nc, const uint8_t *buf, int size) +{ + if (!qemu_can_receive_packet(nc)) { + return 0; + } + + return qemu_net_queue_receive(nc->incoming_queue, buf, size); +} + +ssize_t qemu_receive_packet_iov(NetClientState *nc, const struct iovec *iov, + int iovcnt) +{ + if (!qemu_can_receive_packet(nc)) { + return 0; + } + + return qemu_net_queue_receive_iov(nc->incoming_queue, iov, iovcnt); +} + ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size) { return qemu_send_packet_async_with_flags(nc, QEMU_NET_PACKET_FLAG_RAW, diff --git a/net/queue.c b/net/queue.c index 19e32c8..c872d51 100644 --- a/net/queue.c +++ b/net/queue.c @@ -182,6 +182,28 @@ static ssize_t qemu_net_queue_deliver_iov(NetQueue *queue, return ret; } +ssize_t qemu_net_queue_receive(NetQueue *queue, + const uint8_t *data, + size_t size) +{ + if (queue->delivering) { + return 0; + } + + return qemu_net_queue_deliver(queue, NULL, 0, data, size); +} + +ssize_t qemu_net_queue_receive_iov(NetQueue *queue, + const struct iovec *iov, + int iovcnt) +{ + if (queue->delivering) { + return 0; + } + + return qemu_net_queue_deliver_iov(queue, NULL, 0, iov, iovcnt); +} + ssize_t qemu_net_queue_send(NetQueue *queue, NetClientState *sender, unsigned flags, From patchwork Mon Mar 15 09:14:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453127 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SXlDL+Wz; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzWBg38sFz9sVm for ; Mon, 15 Mar 2021 20:21:31 +1100 (AEDT) Received: from localhost ([::1]:42178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjPl-0006JC-F3 for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:21:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35292) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjJf-0007sy-6A for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31057) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjJY-0007ku-2n for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799703; 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=77lYuJueY3ZZ0H0iB015D9A2tcUPOFqLouZQaLMS7fI=; b=SXlDL+Wz8taGwooYmJ8KrOFfa1rxfNlt91JfpDbdmIAVIC/dILx8auZ8F2CR2nwTlzZ/sJ 7vjEB7PqEtJXUSkYn1Ee0RtODmBpD7qb76GKgVnfMi+1K4ma/Eb/CjpN3wfUbG4X64srjS IHVUHGeQf21Qh7EpO+M/C/PLc2uMC2Q= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-369-fOXzAT1bPySsZv4ayOpOzQ-1; Mon, 15 Mar 2021 05:15:01 -0400 X-MC-Unique: fOXzAT1bPySsZv4ayOpOzQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 76BD518460E1; Mon, 15 Mar 2021 09:15:00 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59EC81007625; Mon, 15 Mar 2021 09:14:58 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 06/20] e1000: switch to use qemu_receive_packet() for loopback Date: Mon, 15 Mar 2021 17:14:19 +0800 Message-Id: <1615799673-31549-7-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch switches to use qemu_receive_packet() which can detect reentrancy and return early. This is intended to address CVE-2021-3416. Cc: Prasad J Pandit Cc: qemu-stable@nongnu.org Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Jason Wang --- hw/net/e1000.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 4345d86..4f75b44 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -546,7 +546,7 @@ e1000_send_packet(E1000State *s, const uint8_t *buf, int size) NetClientState *nc = qemu_get_queue(s->nic); if (s->phy_reg[PHY_CTRL] & MII_CR_LOOPBACK) { - nc->info->receive(nc, buf, size); + qemu_receive_packet(nc, buf, size); } else { qemu_send_packet(nc, buf, size); } From patchwork Mon Mar 15 09:14:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453129 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Bu3LxIY6; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzWD74mB7z9sVm for ; Mon, 15 Mar 2021 20:22:47 +1100 (AEDT) Received: from localhost ([::1]:44094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjQz-0007DS-LU for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:22:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjJf-0007tB-9J for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59171) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjJb-0007mU-4u for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799705; 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=qKE7TWyoGxDr+8pHmWsEJIClKHQdRsabnkAaiD6An8s=; b=Bu3LxIY6LmDcCk5quz75MQYrVSjqhRO9MbrFF76AOb8x/JALHRg9F56JqW8CPMO9PliiSx 3f8E6PabgjrH/tB3TFfry19UHeutfZayEVTeZiZn2VJ9yH9cgJR1JwlsdTcZaCH2eDW9a4 MwJ4cM5BMHulkbuhOmf2eHka0ADGMAo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-199--FOSbTI7NQur5kwFM3P3NQ-1; Mon, 15 Mar 2021 05:15:04 -0400 X-MC-Unique: -FOSbTI7NQur5kwFM3P3NQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E68F1760C1; Mon, 15 Mar 2021 09:15:02 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 035C81007625; Mon, 15 Mar 2021 09:15:00 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 07/20] dp8393x: switch to use qemu_receive_packet() for loopback packet Date: Mon, 15 Mar 2021 17:14:20 +0800 Message-Id: <1615799673-31549-8-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch switches to use qemu_receive_packet() which can detect reentrancy and return early. This is intended to address CVE-2021-3416. Cc: Prasad J Pandit Cc: qemu-stable@nongnu.org Reviewed-by: Philippe Mathieu-Daudé --- hw/net/dp8393x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 205c0de..533a830 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -506,7 +506,7 @@ static void dp8393x_do_transmit_packets(dp8393xState *s) s->regs[SONIC_TCR] |= SONIC_TCR_CRSL; if (nc->info->can_receive(nc)) { s->loopback_packet = 1; - nc->info->receive(nc, s->tx_buffer, tx_len); + qemu_receive_packet(nc, s->tx_buffer, tx_len); } } else { /* Transmit packet */ From patchwork Mon Mar 15 09:14:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453126 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=YTbmsC9W; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzWBS0Nd5z9sVm for ; Mon, 15 Mar 2021 20:21:20 +1100 (AEDT) Received: from localhost ([::1]:41442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjPZ-00060G-De for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:21:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjJl-0007wS-2v for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25551) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjJi-0007oy-UG for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799712; 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=RyNIINoBz1Hi6Rbx/YwEruYvIrkhCW2bFy+35okkCBk=; b=YTbmsC9WU2kf3Xgdx8UX87kKN6NRNSqolk6y+kaByBmy5uT0R8WJODqm6CHh+j6Cz3kU0b wDkq92LloDWDn8zLScOcTxWq/hQgY6tfOx5nmnU0eDYkGBM4BYk2R5yHK+ffbj602l3Tqu zxb/xhoKnrKqlXhxilr4wl1eXNHc3O4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-130-u2_QYXjCP-CJuwgKosWmAg-1; Mon, 15 Mar 2021 05:15:10 -0400 X-MC-Unique: u2_QYXjCP-CJuwgKosWmAg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3FFC5100C624; Mon, 15 Mar 2021 09:15:09 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 731DA101E24F; Mon, 15 Mar 2021 09:15:03 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 08/20] msf2-mac: switch to use qemu_receive_packet() for loopback Date: Mon, 15 Mar 2021 17:14:21 +0800 Message-Id: <1615799673-31549-9-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch switches to use qemu_receive_packet() which can detect reentrancy and return early. This is intended to address CVE-2021-3416. Cc: Prasad J Pandit Cc: qemu-stable@nongnu.org Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Jason Wang --- hw/net/msf2-emac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/net/msf2-emac.c b/hw/net/msf2-emac.c index 32ba9e8..3e62060 100644 --- a/hw/net/msf2-emac.c +++ b/hw/net/msf2-emac.c @@ -158,7 +158,7 @@ static void msf2_dma_tx(MSF2EmacState *s) * R_CFG1 bit 0 is set. */ if (s->regs[R_CFG1] & R_CFG1_LB_EN_MASK) { - nc->info->receive(nc, buf, size); + qemu_receive_packet(nc, buf, size); } else { qemu_send_packet(nc, buf, size); } From patchwork Mon Mar 15 09:14:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453130 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=S8CQOVlt; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzWGD6nJkz9sRf for ; Mon, 15 Mar 2021 20:24:36 +1100 (AEDT) Received: from localhost ([::1]:49892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjSj-0001Fn-JU for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:24:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjJp-0007yW-6G for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33523) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjJm-0007rF-OT for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799716; 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=RdcJWZ6DHPuuQFJeMiOmCH7fjRe4vlISaTRE6TS3Riw=; b=S8CQOVltdi77+n7uom7QEZzYM5pC/nynwizVkmr5FdiwP2Mc3Mu36VZs52aZ2zEWkBfE5y 1wTgRXe5b/KdqWIGT87zwQ1i5EfEK42jBRF9Zy0yp5NmZEsUfiH6D2tOjcFyIZzd+hkaFo 9267FQM7kSmAuGuf4+3sX7nESMOw0zY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-104-_SIWSbGkN2aRJ7rn-UjGlA-1; Mon, 15 Mar 2021 05:15:14 -0400 X-MC-Unique: _SIWSbGkN2aRJ7rn-UjGlA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B621E107ACCD; Mon, 15 Mar 2021 09:15:13 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id C10C61007625; Mon, 15 Mar 2021 09:15:09 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 09/20] sungem: switch to use qemu_receive_packet() for loopback Date: Mon, 15 Mar 2021 17:14:22 +0800 Message-Id: <1615799673-31549-10-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch switches to use qemu_receive_packet() which can detect reentrancy and return early. This is intended to address CVE-2021-3416. Cc: Prasad J Pandit Cc: qemu-stable@nongnu.org Reviewed-by: Mark Cave-Ayland Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis Signed-off-by: Jason Wang --- hw/net/sungem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/net/sungem.c b/hw/net/sungem.c index 33c3722..3684a4d 100644 --- a/hw/net/sungem.c +++ b/hw/net/sungem.c @@ -306,7 +306,7 @@ static void sungem_send_packet(SunGEMState *s, const uint8_t *buf, NetClientState *nc = qemu_get_queue(s->nic); if (s->macregs[MAC_XIFCFG >> 2] & MAC_XIFCFG_LBCK) { - nc->info->receive(nc, buf, size); + qemu_receive_packet(nc, buf, size); } else { qemu_send_packet(nc, buf, size); } From patchwork Mon Mar 15 09:14:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453121 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dv5oFgLG; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzW4q1Q7mz9sVm for ; Mon, 15 Mar 2021 20:16:27 +1100 (AEDT) Received: from localhost ([::1]:54710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjKr-000886-51 for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:16:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjJu-00085g-5T for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59873) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjJs-0007xR-Hs for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799723; 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=6bJKthAT4Mc9pCJJjfRZzZpHScIqv7jLZTPGXL8J8zk=; b=dv5oFgLGDfijCmgpPcfrGzMf6Uiqoc9tms+xhpSGtRh3bZwep2KMa4jp52EZzDMsBL1XxB B2WI7+zGDKD/cde542H/oqMg0GH1SJpsPUSwWBaBEmb6GzfZKPKSN+ADWXoJgXRF0rNlXl +8EyGPOl0gnIaw1eV3Los+H3ktXl8u8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-187-iXzACB29MgqNXQVCWgYgxA-1; Mon, 15 Mar 2021 05:15:22 -0400 X-MC-Unique: iXzACB29MgqNXQVCWgYgxA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1EA8418460E2; Mon, 15 Mar 2021 09:15:21 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 410EB1007625; Mon, 15 Mar 2021 09:15:13 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 10/20] tx_pkt: switch to use qemu_receive_packet_iov() for loopback Date: Mon, 15 Mar 2021 17:14:23 +0800 Message-Id: <1615799673-31549-11-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch switches to use qemu_receive_receive_iov() which can detect reentrancy and return early. This is intended to address CVE-2021-3416. Cc: Prasad J Pandit Cc: qemu-stable@nongnu.org Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Jason Wang --- hw/net/net_tx_pkt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/net/net_tx_pkt.c b/hw/net/net_tx_pkt.c index da262ed..1f9aa59 100644 --- a/hw/net/net_tx_pkt.c +++ b/hw/net/net_tx_pkt.c @@ -553,7 +553,7 @@ static inline void net_tx_pkt_sendv(struct NetTxPkt *pkt, NetClientState *nc, const struct iovec *iov, int iov_cnt) { if (pkt->is_loopback) { - nc->info->receive_iov(nc, iov, iov_cnt); + qemu_receive_packet_iov(nc, iov, iov_cnt); } else { qemu_sendv_packet(nc, iov, iov_cnt); } From patchwork Mon Mar 15 09:14:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453131 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GT06fyQW; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzWGc1Wp4z9sRf for ; Mon, 15 Mar 2021 20:24:56 +1100 (AEDT) Received: from localhost ([::1]:51640 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjT4-0001xW-4W for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:24:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35570) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjK5-0008Rn-Vv for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54061) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjK2-00085f-Tl for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799734; 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=/ENnQUGZLLVogXHtCtzqE57XhBQnjWTcfqvtIxe9h40=; b=GT06fyQWuoFRRubeHjLZyajFFoNrPLPm1SIADeFihfnD5p+e1CuNHg7u0Zyqb+xGUSHqSk j0xOrWsYXzDyM+CqixIqZBvoTqDMZo5I4UVXWXYLkYO5uSLNZrjxnOvKHT9IEFVGm4VgAk d81VrK6+yhh2ud9uBR0xrIVpkHnUMjA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-442-FSsVAzYYOZSCs39UdwehDQ-1; Mon, 15 Mar 2021 05:15:29 -0400 X-MC-Unique: FSsVAzYYOZSCs39UdwehDQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D79011846117; Mon, 15 Mar 2021 09:15:27 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F3A31007625; Mon, 15 Mar 2021 09:15:21 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 11/20] rtl8139: switch to use qemu_receive_packet() for loopback Date: Mon, 15 Mar 2021 17:14:24 +0800 Message-Id: <1615799673-31549-12-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Alexander Bulekov , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alexander Bulekov This patch switches to use qemu_receive_packet() which can detect reentrancy and return early. This is intended to address CVE-2021-3416. Cc: Prasad J Pandit Cc: qemu-stable@nongnu.org Buglink: https://bugs.launchpad.net/qemu/+bug/1910826 Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Jason Wang --- hw/net/rtl8139.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c index 4675ac8..90b4fc6 100644 --- a/hw/net/rtl8139.c +++ b/hw/net/rtl8139.c @@ -1795,7 +1795,7 @@ static void rtl8139_transfer_frame(RTL8139State *s, uint8_t *buf, int size, } DPRINTF("+++ transmit loopback mode\n"); - rtl8139_do_receive(qemu_get_queue(s->nic), buf, size, do_interrupt); + qemu_receive_packet(qemu_get_queue(s->nic), buf, size); if (iov) { g_free(buf2); From patchwork Mon Mar 15 09:14:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453125 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=elnO3x/c; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzW7s5nppz9sWF for ; Mon, 15 Mar 2021 20:19:05 +1100 (AEDT) Received: from localhost ([::1]:34868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjNP-0003KI-QF for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:19:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjK8-00006b-SY for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:41549) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjK4-00086W-Fz for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799735; 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=ew/5txxMQKVoLsaPrRnRTg8UBay6ZQd+g3eeE8dHLCA=; b=elnO3x/cuwp1UUfDD+8mcpXjadqk9ztZ8DEIe6dnHSSrlUaJjeUdfVxDISbMSVbxusqsyf ZxyC7odWUQwANzDARgsVfe0zr4VinKY9Yla4qBPKz6jkQwYgx2rXXvyZdEw7Eo6lhGdj6F p6neFr3OzZ9WzMQRuiHMa1zyvVkePGs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-242-dmgPnscaOVWS2zRmlIBQkA-1; Mon, 15 Mar 2021 05:15:31 -0400 X-MC-Unique: dmgPnscaOVWS2zRmlIBQkA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 84A43760C0; Mon, 15 Mar 2021 09:15:30 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 552661045E83; Mon, 15 Mar 2021 09:15:28 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 12/20] pcnet: switch to use qemu_receive_packet() for loopback Date: Mon, 15 Mar 2021 17:14:25 +0800 Message-Id: <1615799673-31549-13-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Alexander Bulekov , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alexander Bulekov This patch switches to use qemu_receive_packet() which can detect reentrancy and return early. This is intended to address CVE-2021-3416. Cc: Prasad J Pandit Cc: qemu-stable@nongnu.org Buglink: https://bugs.launchpad.net/qemu/+bug/1917085 Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Jason Wang --- hw/net/pcnet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/net/pcnet.c b/hw/net/pcnet.c index f3f18d8..dcd3fc4 100644 --- a/hw/net/pcnet.c +++ b/hw/net/pcnet.c @@ -1250,7 +1250,7 @@ txagain: if (BCR_SWSTYLE(s) == 1) add_crc = !GET_FIELD(tmd.status, TMDS, NOFCS); s->looptest = add_crc ? PCNET_LOOPTEST_CRC : PCNET_LOOPTEST_NOCRC; - pcnet_receive(qemu_get_queue(s->nic), s->buffer, s->xmit_pos); + qemu_receive_packet(qemu_get_queue(s->nic), s->buffer, s->xmit_pos); s->looptest = 0; } else { if (s->nic) { From patchwork Mon Mar 15 09:14:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453133 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SuV+fMAw; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzWKs0Zwpz9sRf for ; Mon, 15 Mar 2021 20:27:45 +1100 (AEDT) Received: from localhost ([::1]:32920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjVn-0005vZ-3L for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:27:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35604) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjK7-0008WK-Sy for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44746) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjK5-00087c-Lj for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799736; 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=bbGpWHYX8p5RfriyfsnYp7IJPRDfebqyZu6HAJFvgYA=; b=SuV+fMAwffU+SWnvU/yPDx2gtlvecOkPCEbpCC4LKRGELwlPpmNzzH/aclRexGKvffMb3J rC7iddY8LUckVYUSeQN5UZz1FSo7BmGX8TuTUHyuy9LXBT0SRh3Ae/zF7Z2YpW0QLddXn3 rPMrZoyHELp+n4cwHce9uffZb6Lu4Es= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-489-grscoyrrNTieU-l-PjZpwA-1; Mon, 15 Mar 2021 05:15:34 -0400 X-MC-Unique: grscoyrrNTieU-l-PjZpwA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 432FE107ACCA; Mon, 15 Mar 2021 09:15:33 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1211010190A7; Mon, 15 Mar 2021 09:15:30 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 13/20] cadence_gem: switch to use qemu_receive_packet() for loopback Date: Mon, 15 Mar 2021 17:14:26 +0800 Message-Id: <1615799673-31549-14-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Alexander Bulekov , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alexander Bulekov This patch switches to use qemu_receive_packet() which can detect reentrancy and return early. This is intended to address CVE-2021-3416. Cc: Prasad J Pandit Cc: qemu-stable@nongnu.org Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Alexander Bulekov Signed-off-by: Jason Wang --- hw/net/cadence_gem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c index 9a4474a..24b3a0f 100644 --- a/hw/net/cadence_gem.c +++ b/hw/net/cadence_gem.c @@ -1275,8 +1275,8 @@ static void gem_transmit(CadenceGEMState *s) /* Send the packet somewhere */ if (s->phy_loop || (s->regs[GEM_NWCTRL] & GEM_NWCTRL_LOCALLOOP)) { - gem_receive(qemu_get_queue(s->nic), s->tx_packet, - total_bytes); + qemu_receive_packet(qemu_get_queue(s->nic), s->tx_packet, + total_bytes); } else { qemu_send_packet(qemu_get_queue(s->nic), s->tx_packet, total_bytes); From patchwork Mon Mar 15 09:14:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453137 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=N4w59xmb; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzWND6TyCz9sVb for ; Mon, 15 Mar 2021 20:29:48 +1100 (AEDT) Received: from localhost ([::1]:39784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjXl-0000ME-T7 for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:29:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35646) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjKC-0000C7-Bd for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:27387) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjK9-0008AO-QZ for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799741; 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=Da8utT56JvLvicbWmGO2VftTBd8X0cgM9z+/I38HVq4=; b=N4w59xmbpazFF6Hr9vqkEbu0KgnLijST+WIzzvv9WnLbwOya7Pk6hOdLg7g0f4WdWCopCT 3kT7CQBsFaGLwx4QnwXPxMqCHv7+pSUv70yKg8UReiBD433zfbCcjOGIJJZWPlmLJabfPS gN1iv0O+NVRYrM6KYsrKEXaGk51JPVU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-384-d_5Mvi-tOXurYTVzPPfleQ-1; Mon, 15 Mar 2021 05:15:37 -0400 X-MC-Unique: d_5Mvi-tOXurYTVzPPfleQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 01D4580006E; Mon, 15 Mar 2021 09:15:36 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id C4AE9100164C; Mon, 15 Mar 2021 09:15:33 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 14/20] lan9118: switch to use qemu_receive_packet() for loopback Date: Mon, 15 Mar 2021 17:14:27 +0800 Message-Id: <1615799673-31549-15-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Alexander Bulekov , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alexander Bulekov This patch switches to use qemu_receive_packet() which can detect reentrancy and return early. This is intended to address CVE-2021-3416. Cc: Prasad J Pandit Cc: qemu-stable@nongnu.org Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Jason Wang --- hw/net/lan9118.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/net/lan9118.c b/hw/net/lan9118.c index abc7962..6aff424 100644 --- a/hw/net/lan9118.c +++ b/hw/net/lan9118.c @@ -680,7 +680,7 @@ static void do_tx_packet(lan9118_state *s) /* FIXME: Honor TX disable, and allow queueing of packets. */ if (s->phy_control & 0x4000) { /* This assumes the receive routine doesn't touch the VLANClient. */ - lan9118_receive(qemu_get_queue(s->nic), s->txp->data, s->txp->len); + qemu_receive_packet(qemu_get_queue(s->nic), s->txp->data, s->txp->len); } else { qemu_send_packet(qemu_get_queue(s->nic), s->txp->data, s->txp->len); } From patchwork Mon Mar 15 09:14:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453139 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SHlHedr/; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzWRN2bZHz9sWF for ; Mon, 15 Mar 2021 20:32:32 +1100 (AEDT) Received: from localhost ([::1]:46908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjaQ-0003Si-ER for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:32:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35670) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjKE-0000G7-6g for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:51107) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjKB-0008Ac-HD for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type:in-reply-to:in-reply-to: references:references; bh=jz7rXc9MSNcMN+9Z+ch6NrMClneZPv4Jj5Qe+VK/CQs=; b=SHlHedr/OjbpFmElZBel95iLeZiADR9ahoE46MDHOLxmRR6b4hmkenEMip4ifPMSRY2/Ij xAA61HqWEnTBELnFYEocbdwPROeS9EN4JrTZ/pv9NqulLYH386tL8ILM4wrH7RCDuJUSyy C84G6/11ag2NvDosmOm9JRexRgfKew8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-486-8qhzuMosOfaF1j7A1rZerA-1; Mon, 15 Mar 2021 05:15:39 -0400 X-MC-Unique: 8qhzuMosOfaF1j7A1rZerA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3460E1858F2C; Mon, 15 Mar 2021 09:15:38 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84AC1100F49F; Mon, 15 Mar 2021 09:15:36 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 15/20] pvrdma: wean code off pvrdma_ring.h kernel header Date: Mon, 15 Mar 2021 17:14:28 +0800 Message-Id: <1615799673-31549-16-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Cornelia Huck , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Cornelia Huck The pvrdma code relies on the pvrdma_ring.h kernel header for some basic ring buffer handling. The content of that header isn't very exciting, but contains some (q)atomic_*() invocations that (a) cause manual massaging when doing a headers update, and (b) are an indication that we probably should not be importing that header at all. Let's reimplement the ring buffer handling directly in the pvrdma code instead. This arguably also improves readability of the code. Importing the header can now be dropped. Signed-off-by: Cornelia Huck Reviewed-by: Paolo Bonzini Reviewed-by: Yuval Shaia Tested-by: Yuval Shaia Signed-off-by: Jason Wang --- hw/rdma/vmw/pvrdma.h | 5 +- hw/rdma/vmw/pvrdma_cmd.c | 6 +- hw/rdma/vmw/pvrdma_dev_ring.c | 41 ++++---- hw/rdma/vmw/pvrdma_dev_ring.h | 9 +- hw/rdma/vmw/pvrdma_main.c | 4 +- .../drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h | 114 --------------------- scripts/update-linux-headers.sh | 3 +- 7 files changed, 38 insertions(+), 144 deletions(-) delete mode 100644 include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h diff --git a/hw/rdma/vmw/pvrdma.h b/hw/rdma/vmw/pvrdma.h index 1d36a76..d08965d 100644 --- a/hw/rdma/vmw/pvrdma.h +++ b/hw/rdma/vmw/pvrdma.h @@ -26,7 +26,6 @@ #include "../rdma_backend_defs.h" #include "../rdma_rm_defs.h" -#include "standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h" #include "standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_dev_api.h" #include "pvrdma_dev_ring.h" #include "qom/object.h" @@ -64,10 +63,10 @@ typedef struct DSRInfo { union pvrdma_cmd_req *req; union pvrdma_cmd_resp *rsp; - struct pvrdma_ring *async_ring_state; + PvrdmaRingState *async_ring_state; PvrdmaRing async; - struct pvrdma_ring *cq_ring_state; + PvrdmaRingState *cq_ring_state; PvrdmaRing cq; } DSRInfo; diff --git a/hw/rdma/vmw/pvrdma_cmd.c b/hw/rdma/vmw/pvrdma_cmd.c index 692125a..f59879e 100644 --- a/hw/rdma/vmw/pvrdma_cmd.c +++ b/hw/rdma/vmw/pvrdma_cmd.c @@ -262,7 +262,7 @@ static int create_cq_ring(PCIDevice *pci_dev , PvrdmaRing **ring, r = g_malloc(sizeof(*r)); *ring = r; - r->ring_state = (struct pvrdma_ring *) + r->ring_state = (PvrdmaRingState *) rdma_pci_dma_map(pci_dev, tbl[0], TARGET_PAGE_SIZE); if (!r->ring_state) { @@ -398,7 +398,7 @@ static int create_qp_rings(PCIDevice *pci_dev, uint64_t pdir_dma, *rings = sr; /* Create send ring */ - sr->ring_state = (struct pvrdma_ring *) + sr->ring_state = (PvrdmaRingState *) rdma_pci_dma_map(pci_dev, tbl[0], TARGET_PAGE_SIZE); if (!sr->ring_state) { rdma_error_report("Failed to map to QP ring state"); @@ -639,7 +639,7 @@ static int create_srq_ring(PCIDevice *pci_dev, PvrdmaRing **ring, r = g_malloc(sizeof(*r)); *ring = r; - r->ring_state = (struct pvrdma_ring *) + r->ring_state = (PvrdmaRingState *) rdma_pci_dma_map(pci_dev, tbl[0], TARGET_PAGE_SIZE); if (!r->ring_state) { rdma_error_report("Failed to map tp SRQ ring state"); diff --git a/hw/rdma/vmw/pvrdma_dev_ring.c b/hw/rdma/vmw/pvrdma_dev_ring.c index f0bcde7..074ac59 100644 --- a/hw/rdma/vmw/pvrdma_dev_ring.c +++ b/hw/rdma/vmw/pvrdma_dev_ring.c @@ -22,11 +22,10 @@ #include "trace.h" #include "../rdma_utils.h" -#include "standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h" #include "pvrdma_dev_ring.h" int pvrdma_ring_init(PvrdmaRing *ring, const char *name, PCIDevice *dev, - struct pvrdma_ring *ring_state, uint32_t max_elems, + PvrdmaRingState *ring_state, uint32_t max_elems, size_t elem_sz, dma_addr_t *tbl, uint32_t npages) { int i; @@ -73,48 +72,54 @@ out: void *pvrdma_ring_next_elem_read(PvrdmaRing *ring) { - int e; - unsigned int idx = 0, offset; + unsigned int idx, offset; + const uint32_t tail = qatomic_read(&ring->ring_state->prod_tail); + const uint32_t head = qatomic_read(&ring->ring_state->cons_head); - e = pvrdma_idx_ring_has_data(ring->ring_state, ring->max_elems, &idx); - if (e <= 0) { + if (tail & ~((ring->max_elems << 1) - 1) || + head & ~((ring->max_elems << 1) - 1) || + tail == head) { trace_pvrdma_ring_next_elem_read_no_data(ring->name); return NULL; } + idx = head & (ring->max_elems - 1); offset = idx * ring->elem_sz; return ring->pages[offset / TARGET_PAGE_SIZE] + (offset % TARGET_PAGE_SIZE); } void pvrdma_ring_read_inc(PvrdmaRing *ring) { - pvrdma_idx_ring_inc(&ring->ring_state->cons_head, ring->max_elems); + uint32_t idx = qatomic_read(&ring->ring_state->cons_head); + + idx = (idx + 1) & ((ring->max_elems << 1) - 1); + qatomic_set(&ring->ring_state->cons_head, idx); } void *pvrdma_ring_next_elem_write(PvrdmaRing *ring) { - int idx; - unsigned int offset, tail; + unsigned int idx, offset; + const uint32_t tail = qatomic_read(&ring->ring_state->prod_tail); + const uint32_t head = qatomic_read(&ring->ring_state->cons_head); - idx = pvrdma_idx_ring_has_space(ring->ring_state, ring->max_elems, &tail); - if (idx <= 0) { + if (tail & ~((ring->max_elems << 1) - 1) || + head & ~((ring->max_elems << 1) - 1) || + tail == (head ^ ring->max_elems)) { rdma_error_report("CQ is full"); return NULL; } - idx = pvrdma_idx(&ring->ring_state->prod_tail, ring->max_elems); - if (idx < 0 || tail != idx) { - rdma_error_report("Invalid idx %d", idx); - return NULL; - } - + idx = tail & (ring->max_elems - 1); offset = idx * ring->elem_sz; return ring->pages[offset / TARGET_PAGE_SIZE] + (offset % TARGET_PAGE_SIZE); } void pvrdma_ring_write_inc(PvrdmaRing *ring) { - pvrdma_idx_ring_inc(&ring->ring_state->prod_tail, ring->max_elems); + uint32_t idx = qatomic_read(&ring->ring_state->prod_tail); + + idx = (idx + 1) & ((ring->max_elems << 1) - 1); + qatomic_set(&ring->ring_state->prod_tail, idx); } void pvrdma_ring_free(PvrdmaRing *ring) diff --git a/hw/rdma/vmw/pvrdma_dev_ring.h b/hw/rdma/vmw/pvrdma_dev_ring.h index 5f2a0cf..d231588 100644 --- a/hw/rdma/vmw/pvrdma_dev_ring.h +++ b/hw/rdma/vmw/pvrdma_dev_ring.h @@ -19,18 +19,23 @@ #define MAX_RING_NAME_SZ 32 +typedef struct PvrdmaRingState { + int prod_tail; /* producer tail */ + int cons_head; /* consumer head */ +} PvrdmaRingState; + typedef struct PvrdmaRing { char name[MAX_RING_NAME_SZ]; PCIDevice *dev; uint32_t max_elems; size_t elem_sz; - struct pvrdma_ring *ring_state; /* used only for unmap */ + PvrdmaRingState *ring_state; /* used only for unmap */ int npages; void **pages; } PvrdmaRing; int pvrdma_ring_init(PvrdmaRing *ring, const char *name, PCIDevice *dev, - struct pvrdma_ring *ring_state, uint32_t max_elems, + PvrdmaRingState *ring_state, uint32_t max_elems, size_t elem_sz, dma_addr_t *tbl, uint32_t npages); void *pvrdma_ring_next_elem_read(PvrdmaRing *ring); void pvrdma_ring_read_inc(PvrdmaRing *ring); diff --git a/hw/rdma/vmw/pvrdma_main.c b/hw/rdma/vmw/pvrdma_main.c index 8593570..84ae802 100644 --- a/hw/rdma/vmw/pvrdma_main.c +++ b/hw/rdma/vmw/pvrdma_main.c @@ -85,7 +85,7 @@ static void free_dev_ring(PCIDevice *pci_dev, PvrdmaRing *ring, rdma_pci_dma_unmap(pci_dev, ring_state, TARGET_PAGE_SIZE); } -static int init_dev_ring(PvrdmaRing *ring, struct pvrdma_ring **ring_state, +static int init_dev_ring(PvrdmaRing *ring, PvrdmaRingState **ring_state, const char *name, PCIDevice *pci_dev, dma_addr_t dir_addr, uint32_t num_pages) { @@ -114,7 +114,7 @@ static int init_dev_ring(PvrdmaRing *ring, struct pvrdma_ring **ring_state, /* RX ring is the second */ (*ring_state)++; rc = pvrdma_ring_init(ring, name, pci_dev, - (struct pvrdma_ring *)*ring_state, + (PvrdmaRingState *)*ring_state, (num_pages - 1) * TARGET_PAGE_SIZE / sizeof(struct pvrdma_cqne), sizeof(struct pvrdma_cqne), diff --git a/include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h b/include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h deleted file mode 100644 index 7b4062a..0000000 --- a/include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2012-2016 VMware, Inc. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of EITHER the GNU General Public License - * version 2 as published by the Free Software Foundation or the BSD - * 2-Clause License. This program is distributed in the hope that it - * will be useful, but WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License version 2 for more details at - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html. - * - * You should have received a copy of the GNU General Public License - * along with this program available in the file COPYING in the main - * directory of this source tree. - * - * The BSD 2-Clause License - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __PVRDMA_RING_H__ -#define __PVRDMA_RING_H__ - -#include "standard-headers/linux/types.h" - -#define PVRDMA_INVALID_IDX -1 /* Invalid index. */ - -struct pvrdma_ring { - int prod_tail; /* Producer tail. */ - int cons_head; /* Consumer head. */ -}; - -struct pvrdma_ring_state { - struct pvrdma_ring tx; /* Tx ring. */ - struct pvrdma_ring rx; /* Rx ring. */ -}; - -static inline int pvrdma_idx_valid(uint32_t idx, uint32_t max_elems) -{ - /* Generates fewer instructions than a less-than. */ - return (idx & ~((max_elems << 1) - 1)) == 0; -} - -static inline int32_t pvrdma_idx(int *var, uint32_t max_elems) -{ - const unsigned int idx = qatomic_read(var); - - if (pvrdma_idx_valid(idx, max_elems)) - return idx & (max_elems - 1); - return PVRDMA_INVALID_IDX; -} - -static inline void pvrdma_idx_ring_inc(int *var, uint32_t max_elems) -{ - uint32_t idx = qatomic_read(var) + 1; /* Increment. */ - - idx &= (max_elems << 1) - 1; /* Modulo size, flip gen. */ - qatomic_set(var, idx); -} - -static inline int32_t pvrdma_idx_ring_has_space(const struct pvrdma_ring *r, - uint32_t max_elems, uint32_t *out_tail) -{ - const uint32_t tail = qatomic_read(&r->prod_tail); - const uint32_t head = qatomic_read(&r->cons_head); - - if (pvrdma_idx_valid(tail, max_elems) && - pvrdma_idx_valid(head, max_elems)) { - *out_tail = tail & (max_elems - 1); - return tail != (head ^ max_elems); - } - return PVRDMA_INVALID_IDX; -} - -static inline int32_t pvrdma_idx_ring_has_data(const struct pvrdma_ring *r, - uint32_t max_elems, uint32_t *out_head) -{ - const uint32_t tail = qatomic_read(&r->prod_tail); - const uint32_t head = qatomic_read(&r->cons_head); - - if (pvrdma_idx_valid(tail, max_elems) && - pvrdma_idx_valid(head, max_elems)) { - *out_head = head & (max_elems - 1); - return tail != head; - } - return PVRDMA_INVALID_IDX; -} - -#endif /* __PVRDMA_RING_H__ */ diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh index fa6f2b6..1050e36 100755 --- a/scripts/update-linux-headers.sh +++ b/scripts/update-linux-headers.sh @@ -215,8 +215,7 @@ sed -e '1h;2,$H;$!d;g' -e 's/[^};]*pvrdma[^(| ]*([^)]*);//g' \ "$linux/drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.h" > \ "$tmp_pvrdma_verbs"; -for i in "$linux/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h" \ - "$linux/drivers/infiniband/hw/vmw_pvrdma/pvrdma_dev_api.h" \ +for i in "$linux/drivers/infiniband/hw/vmw_pvrdma/pvrdma_dev_api.h" \ "$tmp_pvrdma_verbs"; do \ cp_portable "$i" \ "$output/include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/" From patchwork Mon Mar 15 09:14:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453132 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DLxQTAFW; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzWJV4Lthz9sRf for ; Mon, 15 Mar 2021 20:26:34 +1100 (AEDT) Received: from localhost ([::1]:56734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjUe-00042V-It for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:26:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjKH-0000Ig-It for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49322) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjKD-0008C0-Jo for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799744; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type:in-reply-to:in-reply-to: references:references; bh=HrClwnfx8I9ssnhe0q9H5fROi+DpFcnPBEVOnaDBar4=; b=DLxQTAFWGdngty7yfWUYJ72ZYzarPF9jzFOmwf93WvyNgYOg88evfAp11PkPaXIZNIZfZR dC+tXM+G6Qqj/V+nohWD2tP/GEzHGvM7BJoRNIyj8NlWk+5inPYmB0H55mgfCylhiKP3jq 3ex8bYFq5EkWOfCEuRF/LRogUJivn5E= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-167-N0bdQvwKOACp_qvjKvrx-Q-1; Mon, 15 Mar 2021 05:15:42 -0400 X-MC-Unique: N0bdQvwKOACp_qvjKvrx-Q-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D274F92524; Mon, 15 Mar 2021 09:15:40 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id B70E2100164C; Mon, 15 Mar 2021 09:15:38 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 16/20] qapi: net: Add query-netdev command Date: Mon, 15 Mar 2021 17:14:29 +0800 Message-Id: <1615799673-31549-17-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kirillov , Jason Wang , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alexey Kirillov The query-netdev command is used to get the configuration of the current network device backends (netdevs). This is the QMP analog of the HMP command "info network" but only for netdevs (i.e. excluding NIC and hubports). The query-netdev command returns an array of objects of the NetdevInfo type, which are an extension of Netdev type. It means that response can be used for netdev-add after small modification. This can be useful for recreate the same netdev configuration. Information about the network device is filled in when it is created or modified and is available through the NetClientState->stored_config. Signed-off-by: Alexey Kirillov Acked-by: Markus Armbruster Signed-off-by: Jason Wang --- include/net/net.h | 3 ++ net/l2tpv3.c | 7 ++++ net/net.c | 30 +++++++++++++- net/netmap.c | 7 ++++ net/slirp.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/socket.c | 71 +++++++++++++++++++++++++++++++ net/tap-win32.c | 9 ++++ net/tap.c | 103 ++++++++++++++++++++++++++++++++++++++++++--- net/vde.c | 22 ++++++++++ net/vhost-user.c | 18 ++++++-- net/vhost-vdpa.c | 14 +++++++ qapi/net.json | 80 +++++++++++++++++++++++++++++++++++ 12 files changed, 477 insertions(+), 9 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 4f56cae..dc3679f 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -5,6 +5,8 @@ #include "qapi/qapi-types-net.h" #include "net/queue.h" #include "hw/qdev-properties-system.h" +#include "qapi/clone-visitor.h" +#include "qapi/qapi-visit-net.h" #define MAC_FMT "%02X:%02X:%02X:%02X:%02X:%02X" #define MAC_ARG(x) ((uint8_t *)(x))[0], ((uint8_t *)(x))[1], \ @@ -93,6 +95,7 @@ struct NetClientState { char *model; char *name; char info_str[256]; + NetdevInfo *stored_config; unsigned receive_disabled : 1; NetClientDestructor *destructor; unsigned int queue_index; diff --git a/net/l2tpv3.c b/net/l2tpv3.c index e4d4218..8aa0a3e 100644 --- a/net/l2tpv3.c +++ b/net/l2tpv3.c @@ -723,6 +723,13 @@ int net_init_l2tpv3(const Netdev *netdev, l2tpv3_read_poll(s, true); + /* Store startup parameters */ + nc->stored_config = g_new0(NetdevInfo, 1); + nc->stored_config->type = NET_BACKEND_L2TPV3; + + QAPI_CLONE_MEMBERS(NetdevL2TPv3Options, + &nc->stored_config->u.l2tpv3, l2tpv3); + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "l2tpv3: connected"); return 0; diff --git a/net/net.c b/net/net.c index edf9b95..9a2a6ab 100644 --- a/net/net.c +++ b/net/net.c @@ -36,7 +36,6 @@ #include "monitor/monitor.h" #include "qemu/help_option.h" #include "qapi/qapi-commands-net.h" -#include "qapi/qapi-visit-net.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "qemu/error-report.h" @@ -353,6 +352,7 @@ static void qemu_free_net_client(NetClientState *nc) } g_free(nc->name); g_free(nc->model); + qapi_free_NetdevInfo(nc->stored_config); if (nc->destructor) { nc->destructor(nc); } @@ -1289,6 +1289,34 @@ RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name, return filter_list; } +NetdevInfoList *qmp_query_netdev(Error **errp) +{ + NetdevInfoList *list = NULL; + NetClientState *nc; + + QTAILQ_FOREACH(nc, &net_clients, next) { + /* + * Only look at netdevs (backend network devices), not for each queue + * or NIC / hubport + */ + if (nc->stored_config) { + NetdevInfo *element = QAPI_CLONE(NetdevInfo, nc->stored_config); + + g_free(element->id); /* Need to dealloc empty id after clone */ + element->id = g_strdup(nc->name); + + element->has_peer_id = nc->peer != NULL; + if (element->has_peer_id) { + element->peer_id = g_strdup(nc->peer->name); + } + + QAPI_LIST_PREPEND(list, element); + } + } + + return list; +} + void hmp_info_network(Monitor *mon, const QDict *qdict) { NetClientState *nc, *peer; diff --git a/net/netmap.c b/net/netmap.c index 350f097..ad59d4a 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -427,6 +427,13 @@ int net_init_netmap(const Netdev *netdev, pstrcpy(s->ifname, sizeof(s->ifname), netmap_opts->ifname); netmap_read_poll(s, true); /* Initially only poll for reads. */ + /* Store startup parameters */ + nc->stored_config = g_new0(NetdevInfo, 1); + nc->stored_config->type = NET_BACKEND_NETMAP; + + QAPI_CLONE_MEMBERS(NetdevNetmapOptions, + &nc->stored_config->u.netmap, netmap_opts); + return 0; } diff --git a/net/slirp.c b/net/slirp.c index be914c0..6ab348b 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -377,6 +377,9 @@ static int net_slirp_init(NetClientState *peer, const char *model, int shift; char *end; struct slirp_config_str *config; + NetdevUserOptions *stored; + StringList **stored_hostfwd; + StringList **stored_guestfwd; if (!ipv4 && (vnetwork || vhost || vnameserver)) { error_setg(errp, "IPv4 disabled but netmask/host/dns provided"); @@ -552,6 +555,115 @@ static int net_slirp_init(NetClientState *peer, const char *model, nc = qemu_new_net_client(&net_slirp_info, peer, model, name); + /* Store startup parameters */ + nc->stored_config = g_new0(NetdevInfo, 1); + nc->stored_config->type = NET_BACKEND_USER; + stored = &nc->stored_config->u.user; + + if (vhostname) { + stored->has_hostname = true; + stored->hostname = g_strdup(vhostname); + } + + stored->has_q_restrict = true; + stored->q_restrict = restricted; + + stored->has_ipv4 = true; + stored->ipv4 = ipv4; + + stored->has_ipv6 = true; + stored->ipv6 = ipv6; + + if (ipv4) { + uint8_t *net_bytes = (uint8_t *)&net; + uint8_t *mask_bytes = (uint8_t *)&mask; + + stored->has_net = true; + stored->net = g_strdup_printf("%d.%d.%d.%d/%d.%d.%d.%d", + net_bytes[0], net_bytes[1], + net_bytes[2], net_bytes[3], + mask_bytes[0], mask_bytes[1], + mask_bytes[2], mask_bytes[3]); + + stored->has_host = true; + stored->host = g_strdup(inet_ntoa(host)); + } + + if (tftp_export) { + stored->has_tftp = true; + stored->tftp = g_strdup(tftp_export); + } + + if (bootfile) { + stored->has_bootfile = true; + stored->bootfile = g_strdup(bootfile); + } + + if (vdhcp_start) { + stored->has_dhcpstart = true; + stored->dhcpstart = g_strdup(vdhcp_start); + } + + if (ipv4) { + stored->has_dns = true; + stored->dns = g_strdup(inet_ntoa(dns)); + } + + if (dnssearch) { + stored->has_dnssearch = true; + StringList **stored_list = &stored->dnssearch; + + for (int i = 0; dnssearch[i]; i++) { + String *element = g_new0(String, 1); + + element->str = g_strdup(dnssearch[i]); + QAPI_LIST_APPEND(stored_list, element); + } + } + + if (vdomainname) { + stored->has_domainname = true; + stored->domainname = g_strdup(vdomainname); + } + + if (ipv6) { + char addrstr[INET6_ADDRSTRLEN]; + const char *res; + + stored->has_ipv6_prefix = true; + stored->ipv6_prefix = g_strdup(vprefix6); + + stored->has_ipv6_prefixlen = true; + stored->ipv6_prefixlen = vprefix6_len; + + res = inet_ntop(AF_INET6, &ip6_host, + addrstr, sizeof(addrstr)); + + stored->has_ipv6_host = true; + stored->ipv6_host = g_strdup(res); + + res = inet_ntop(AF_INET6, &ip6_dns, + addrstr, sizeof(addrstr)); + + stored->has_ipv6_dns = true; + stored->ipv6_dns = g_strdup(res); + } + + if (smb_export) { + stored->has_smb = true; + stored->smb = g_strdup(smb_export); + } + + if (vsmbserver) { + stored->has_smbserver = true; + stored->smbserver = g_strdup(vsmbserver); + } + + if (tftp_server_name) { + stored->has_tftp_server_name = true; + stored->tftp_server_name = g_strdup(tftp_server_name); + } + snprintf(nc->info_str, sizeof(nc->info_str), "net=%s,restrict=%s", inet_ntoa(net), restricted ? "on" : "off"); @@ -581,15 +693,25 @@ static int net_slirp_init(NetClientState *peer, const char *model, s->poll_notifier.notify = net_slirp_poll_notify; main_loop_poll_add_notifier(&s->poll_notifier); + stored_hostfwd = &stored->hostfwd; + stored_guestfwd = &stored->guestfwd; + for (config = slirp_configs; config; config = config->next) { + String *element = g_new0(String, 1); + + element->str = g_strdup(config->str); if (config->flags & SLIRP_CFG_HOSTFWD) { if (slirp_hostfwd(s, config->str, errp) < 0) { goto error; } + stored->has_hostfwd = true; + QAPI_LIST_APPEND(stored_hostfwd, element); } else { if (slirp_guestfwd(s, config->str, errp) < 0) { goto error; } + stored->has_guestfwd = true; + QAPI_LIST_APPEND(stored_guestfwd, element); } } #ifndef _WIN32 diff --git a/net/socket.c b/net/socket.c index 15b410e..1614523 100644 --- a/net/socket.c +++ b/net/socket.c @@ -342,6 +342,7 @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, NetSocketState *s; SocketAddress *sa; SocketAddressType sa_type; + NetdevSocketOptions *stored; sa = socket_local_address(fd, errp); if (!sa) { @@ -385,8 +386,19 @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); net_socket_read_poll(s, true); + /* Store startup parameters */ + nc->stored_config = g_new0(NetdevInfo, 1); + nc->stored_config->type = NET_BACKEND_SOCKET; + stored = &nc->stored_config->u.socket; + + stored->has_fd = true; + stored->fd = g_strdup_printf("%d", fd); + /* mcast: save bound address as dst */ if (is_connected && mcast != NULL) { + stored->has_mcast = true; + stored->mcast = g_strdup(mcast); + s->dgram_dst = saddr; snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d (cloned mcast=%s:%d)", @@ -428,6 +440,7 @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer, { NetClientState *nc; NetSocketState *s; + NetdevSocketOptions *stored; nc = qemu_new_net_client(&net_socket_info, peer, model, name); @@ -447,6 +460,15 @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer, } else { qemu_set_fd_handler(s->fd, NULL, net_socket_connect, s); } + + /* Store startup parameters */ + nc->stored_config = g_new0(NetdevInfo, 1); + nc->stored_config->type = NET_BACKEND_SOCKET; + stored = &nc->stored_config->u.socket; + + stored->has_fd = true; + stored->fd = g_strdup_printf("%d", fd); + return s; } @@ -483,6 +505,7 @@ static void net_socket_accept(void *opaque) struct sockaddr_in saddr; socklen_t len; int fd; + NetdevSocketOptions *stored; for(;;) { len = sizeof(saddr); @@ -498,6 +521,13 @@ static void net_socket_accept(void *opaque) s->fd = fd; s->nc.link_down = false; net_socket_connect(s); + + /* Store additional startup parameters (extend net_socket_listen_init) */ + stored = &s->nc.stored_config->u.socket; + + stored->has_fd = true; + stored->fd = g_strdup_printf("%d", fd); + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "socket: connection from %s:%d", inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); @@ -513,6 +543,7 @@ static int net_socket_listen_init(NetClientState *peer, NetSocketState *s; struct sockaddr_in saddr; int fd, ret; + NetdevSocketOptions *stored; if (parse_host_port(&saddr, host_str, errp) < 0) { return -1; @@ -549,6 +580,15 @@ static int net_socket_listen_init(NetClientState *peer, net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s); + + /* Store startup parameters */ + nc->stored_config = g_new0(NetdevInfo, 1); + nc->stored_config->type = NET_BACKEND_SOCKET; + stored = &nc->stored_config->u.socket; + + stored->has_listen = true; + stored->listen = g_strdup(host_str); + return 0; } @@ -561,6 +601,7 @@ static int net_socket_connect_init(NetClientState *peer, NetSocketState *s; int fd, connected, ret; struct sockaddr_in saddr; + NetdevSocketOptions *stored; if (parse_host_port(&saddr, host_str, errp) < 0) { return -1; @@ -598,6 +639,12 @@ static int net_socket_connect_init(NetClientState *peer, return -1; } + /* Store additional startup parameters (extend net_socket_fd_init) */ + stored = &s->nc.stored_config->u.socket; + + stored->has_connect = true; + stored->connect = g_strdup(host_str); + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "socket: connect to %s:%d", inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); @@ -615,6 +662,7 @@ static int net_socket_mcast_init(NetClientState *peer, int fd; struct sockaddr_in saddr; struct in_addr localaddr, *param_localaddr; + NetdevSocketOptions *stored; if (parse_host_port(&saddr, host_str, errp) < 0) { return -1; @@ -643,6 +691,19 @@ static int net_socket_mcast_init(NetClientState *peer, s->dgram_dst = saddr; + /* Store additional startup parameters (extend net_socket_fd_init) */ + stored = &s->nc.stored_config->u.socket; + + if (!stored->has_mcast) { + stored->has_mcast = true; + stored->mcast = g_strdup(host_str); + } + + if (localaddr_str) { + stored->has_localaddr = true; + stored->localaddr = g_strdup(localaddr_str); + } + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "socket: mcast=%s:%d", inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); @@ -660,6 +721,7 @@ static int net_socket_udp_init(NetClientState *peer, NetSocketState *s; int fd, ret; struct sockaddr_in laddr, raddr; + NetdevSocketOptions *stored; if (parse_host_port(&laddr, lhost, errp) < 0) { return -1; @@ -698,6 +760,15 @@ static int net_socket_udp_init(NetClientState *peer, s->dgram_dst = raddr; + /* Store additional startup parameters (extend net_socket_fd_init) */ + stored = &s->nc.stored_config->u.socket; + + stored->has_localaddr = true; + stored->localaddr = g_strdup(lhost); + + stored->has_udp = true; + stored->udp = g_strdup(rhost); + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "socket: udp=%s:%d", inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port)); diff --git a/net/tap-win32.c b/net/tap-win32.c index 2b5dcda..b60933b 100644 --- a/net/tap-win32.c +++ b/net/tap-win32.c @@ -768,6 +768,7 @@ static int tap_win32_init(NetClientState *peer, const char *model, NetClientState *nc; TAPState *s; tap_win32_overlapped_t *handle; + NetdevTapOptions *stored; if (tap_win32_open(&handle, ifname) < 0) { printf("tap: Could not open '%s'\n", ifname); @@ -778,6 +779,14 @@ static int tap_win32_init(NetClientState *peer, const char *model, s = DO_UPCAST(TAPState, nc, nc); + /* Store startup parameters */ + nc->stored_config = g_new0(NetdevInfo, 1); + nc->stored_config->type = NET_BACKEND_TAP; + stored = &nc->stored_config->u.tap; + + stored->has_ifname = true; + stored->ifname = g_strdup(ifname); + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "tap: ifname=%s", ifname); diff --git a/net/tap.c b/net/tap.c index b751285..8041245 100644 --- a/net/tap.c +++ b/net/tap.c @@ -590,6 +590,7 @@ int net_init_bridge(const Netdev *netdev, const char *name, const char *helper, *br; TAPState *s; int fd, vnet_hdr; + NetdevBridgeOptions *stored; assert(netdev->type == NET_CLIENT_DRIVER_BRIDGE); bridge = &netdev->u.bridge; @@ -609,6 +610,21 @@ int net_init_bridge(const Netdev *netdev, const char *name, } s = net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr); + /* Store startup parameters */ + s->nc.stored_config = g_new0(NetdevInfo, 1); + s->nc.stored_config->type = NET_BACKEND_BRIDGE; + stored = &s->nc.stored_config->u.bridge; + + if (br) { + stored->has_br = true; + stored->br = g_strdup(br); + } + + if (helper) { + stored->has_helper = true; + stored->helper = g_strdup(helper); + } + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s,br=%s", helper, br); @@ -656,11 +672,13 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, const char *model, const char *name, const char *ifname, const char *script, const char *downscript, const char *vhostfdname, - int vnet_hdr, int fd, Error **errp) + int vnet_hdr, int fd, NetdevInfo **common_stored, + Error **errp) { Error *err = NULL; TAPState *s = net_tap_fd_init(peer, model, name, fd, vnet_hdr); int vhostfd; + NetdevTapOptions *stored; tap_set_sndbuf(s->fd, tap, &err); if (err) { @@ -668,12 +686,65 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, return; } + /* Store startup parameters */ + if (!*common_stored) { + *common_stored = g_new0(NetdevInfo, 1); + (*common_stored)->type = NET_BACKEND_TAP; + s->nc.stored_config = *common_stored; + } + stored = &(*common_stored)->u.tap; + + if (tap->has_sndbuf && !stored->has_sndbuf) { + stored->has_sndbuf = true; + stored->sndbuf = tap->sndbuf; + } + + if (vnet_hdr && !stored->has_vnet_hdr) { + stored->has_vnet_hdr = true; + stored->vnet_hdr = true; + } + if (tap->has_fd || tap->has_fds) { + if (!stored->has_fds) { + stored->has_fds = true; + stored->fds = g_strdup_printf("%d", fd); + } else { + char *tmp_s = stored->fds; + stored->fds = g_strdup_printf("%s:%d", stored->fds, fd); + g_free(tmp_s); + } + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd); } else if (tap->has_helper) { + if (!stored->has_helper) { + stored->has_helper = true; + stored->helper = g_strdup(tap->helper); + } + + if (!stored->has_br) { + stored->has_br = true; + stored->br = tap->has_br ? g_strdup(tap->br) : + g_strdup(DEFAULT_BRIDGE_INTERFACE); + } + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s", tap->helper); } else { + if (ifname && !stored->has_ifname) { + stored->has_ifname = true; + stored->ifname = g_strdup(ifname); + } + + if (script && !stored->has_script) { + stored->has_script = true; + stored->script = g_strdup(script); + } + + if (downscript && !stored->has_downscript) { + stored->has_downscript = true; + stored->downscript = g_strdup(downscript); + } + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "ifname=%s,script=%s,downscript=%s", ifname, script, downscript); @@ -689,9 +760,20 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { VhostNetOptions options; + stored->has_vhost = true; + stored->vhost = true; + + if (tap->has_vhostforce && tap->vhostforce) { + stored->has_vhostforce = true; + stored->vhostforce = true; + } + options.backend_type = VHOST_BACKEND_TYPE_KERNEL; options.net_backend = &s->nc; if (tap->has_poll_us) { + stored->has_poll_us = true; + stored->poll_us = tap->poll_us; + options.busyloop_timeout = tap->poll_us; } else { options.busyloop_timeout = 0; @@ -731,6 +813,15 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, } options.opaque = (void *)(uintptr_t)vhostfd; + if (!stored->has_vhostfds) { + stored->has_vhostfds = true; + stored->vhostfds = g_strdup_printf("%d", vhostfd); + } else { + char *tmp_s = stored->vhostfds; + stored->vhostfds = g_strdup_printf("%s:%d", stored->fds, vhostfd); + g_free(tmp_s); + } + s->vhost_net = vhost_net_init(&options); if (!s->vhost_net) { if (tap->has_vhostforce && tap->vhostforce) { @@ -783,6 +874,7 @@ int net_init_tap(const Netdev *netdev, const char *name, const char *vhostfdname; char ifname[128]; int ret = 0; + NetdevInfo *common_stored = NULL; /* will store configuration */ assert(netdev->type == NET_CLIENT_DRIVER_TAP); tap = &netdev->u.tap; @@ -829,7 +921,7 @@ int net_init_tap(const Netdev *netdev, const char *name, net_init_tap_one(tap, peer, "tap", name, NULL, script, downscript, - vhostfdname, vnet_hdr, fd, &err); + vhostfdname, vnet_hdr, fd, &common_stored, &err); if (err) { error_propagate(errp, err); close(fd); @@ -892,7 +984,7 @@ int net_init_tap(const Netdev *netdev, const char *name, net_init_tap_one(tap, peer, "tap", name, ifname, script, downscript, tap->has_vhostfds ? vhost_fds[i] : NULL, - vnet_hdr, fd, &err); + vnet_hdr, fd, &common_stored, &err); if (err) { error_propagate(errp, err); ret = -1; @@ -935,7 +1027,7 @@ free_fail: net_init_tap_one(tap, peer, "bridge", name, ifname, script, downscript, vhostfdname, - vnet_hdr, fd, &err); + vnet_hdr, fd, &common_stored, &err); if (err) { error_propagate(errp, err); close(fd); @@ -981,7 +1073,8 @@ free_fail: net_init_tap_one(tap, peer, "tap", name, ifname, i >= 1 ? "no" : script, i >= 1 ? "no" : downscript, - vhostfdname, vnet_hdr, fd, &err); + vhostfdname, vnet_hdr, fd, + &common_stored, &err); if (err) { error_propagate(errp, err); close(fd); diff --git a/net/vde.c b/net/vde.c index 99189cc..b0b8800 100644 --- a/net/vde.c +++ b/net/vde.c @@ -84,6 +84,7 @@ static int net_vde_init(NetClientState *peer, const char *model, VDECONN *vde; char *init_group = (char *)group; char *init_sock = (char *)sock; + NetdevVdeOptions *stored; struct vde_open_args args = { .port = port, @@ -108,6 +109,27 @@ static int net_vde_init(NetClientState *peer, const char *model, qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s); + /* Store startup parameters */ + nc->stored_config = g_new0(NetdevInfo, 1); + nc->stored_config->type = NET_BACKEND_VDE; + stored = &nc->stored_config->u.vde; + + if (sock) { + stored->has_sock = true; + stored->sock = g_strdup(sock); + } + + stored->has_port = true; + stored->port = port; + + if (group) { + stored->has_group = true; + stored->group = g_strdup(group); + } + + stored->has_mode = true; + stored->mode = mode; + return 0; } diff --git a/net/vhost-user.c b/net/vhost-user.c index ffbd94d..5b7056b 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -311,14 +311,15 @@ static void net_vhost_user_event(void *opaque, QEMUChrEvent event) } static int net_vhost_user_init(NetClientState *peer, const char *device, - const char *name, Chardev *chr, - int queues) + const char *name, const char *chardev, + Chardev *chr, int queues) { Error *err = NULL; NetClientState *nc, *nc0 = NULL; NetVhostUserState *s = NULL; VhostUserState *user; int i; + NetdevVhostUserOptions *stored; assert(name); assert(queues > 0); @@ -355,6 +356,16 @@ static int net_vhost_user_init(NetClientState *peer, const char *device, assert(s->vhost_net); + /* Store startup parameters */ + nc0->stored_config = g_new0(NetdevInfo, 1); + nc0->stored_config->type = NET_BACKEND_VHOST_USER; + stored = &nc0->stored_config->u.vhost_user; + + stored->chardev = g_strdup(chardev); + + stored->has_queues = true; + stored->queues = queues; + return 0; err: @@ -446,5 +457,6 @@ int net_init_vhost_user(const Netdev *netdev, const char *name, return -1; } - return net_vhost_user_init(peer, "vhost_user", name, chr, queues); + return net_vhost_user_init(peer, "vhost_user", name, + vhost_user_opts->chardev, chr, queues); } diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index fe659ec..8c27ea0 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -184,8 +184,22 @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device, VhostVDPAState *s; int vdpa_device_fd = -1; int ret = 0; + NetdevVhostVDPAOptions *stored; + assert(name); nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device, name); + + /* Store startup parameters */ + nc->stored_config = g_new0(NetdevInfo, 1); + nc->stored_config->type = NET_BACKEND_VHOST_VDPA; + stored = &nc->stored_config->u.vhost_vdpa; + + stored->has_vhostdev = true; + stored->vhostdev = g_strdup(vhostdev); + + stored->has_queues = true; + stored->queues = 1; /* TODO: change when support multiqueue */ + snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA); nc->queue_index = 0; s = DO_UPCAST(VhostVDPAState, nc, nc); diff --git a/qapi/net.json b/qapi/net.json index c31748c8..87361eb 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -714,3 +714,83 @@ ## { 'event': 'FAILOVER_NEGOTIATED', 'data': {'device-id': 'str'} } + +## +# @NetBackend: +# +# Available netdev backend drivers. +# +# Since: 6.0 +## +{ 'enum': 'NetBackend', + 'data': [ 'bridge', 'l2tpv3', 'netmap', 'socket', 'tap', 'user', 'vde', + 'vhost-user', 'vhost-vdpa' ] } + +## +# @NetdevInfo: +# +# Configuration of a network backend device (netdev). +# +# @id: Device identifier. +# +# @type: Specify the driver used for interpreting remaining arguments. +# +# @peer-id: The connected frontend network device name (absent if no frontend +# is connected). +# +# Since: 6.0 +## +{ 'union': 'NetdevInfo', + 'base': { 'id': 'str', + 'type': 'NetBackend', + '*peer-id': 'str' }, + 'discriminator': 'type', + 'data': { + 'bridge': 'NetdevBridgeOptions', + 'l2tpv3': 'NetdevL2TPv3Options', + 'netmap': 'NetdevNetmapOptions', + 'socket': 'NetdevSocketOptions', + 'tap': 'NetdevTapOptions', + 'user': 'NetdevUserOptions', + 'vde': 'NetdevVdeOptions', + 'vhost-user': 'NetdevVhostUserOptions', + 'vhost-vdpa': 'NetdevVhostVDPAOptions' } } + +## +# @query-netdev: +# +# Get a list of @NetdevInfo for all virtual network backend devices (netdevs). +# +# Returns: a list of @NetdevInfo describing each netdev. +# +# Since: 6.0 +# +# Example: +# +# -> { "execute": "query-netdev" } +# <- { "return": [ +# { +# "ipv6": true, +# "ipv4": true, +# "host": "10.0.2.2", +# "ipv6-dns": "fec0::3", +# "ipv6-prefix": "fec0::", +# "net": "10.0.2.0/255.255.255.0", +# "ipv6-host": "fec0::2", +# "type": "user", +# "peer-id": "net0", +# "dns": "10.0.2.3", +# "hostfwd": [ +# { +# "str": "tcp::20004-:22" +# } +# ], +# "ipv6-prefixlen": 64, +# "id": "netdev0", +# "restrict": false +# } +# ] +# } +# +## +{ 'command': 'query-netdev', 'returns': ['NetdevInfo'] } From patchwork Mon Mar 15 09:14:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453140 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hDUsBNsj; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzWT22CKMz9sVb for ; Mon, 15 Mar 2021 20:33:57 +1100 (AEDT) Received: from localhost ([::1]:51166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjbm-0005FA-Ug for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:33:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjKN-0000ML-DQ for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:16:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29419) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjKH-0008EA-CH for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799748; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type:in-reply-to:in-reply-to: references:references; bh=t1OUm1oD5Ay0Sxc++QAFRQuHsc8HWxPRWVar+Ykg7K8=; b=hDUsBNsjthcZ0JNpicl9IynxiJtX4AnBsOH8hZ+Hp9TA0yhN+vT6Uxo+DWDjkh5YufDuJ2 MNXbl6JTv1vhp7MycP2WDxp4mapL+oE0mi2IEJ7VHQIQyWF8n/H5HzKbzguLhGs7VxWZ8I MT5p8jqphcbYS7pbBFXWxgYqQ7ejsMg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-533-nPrigXOJNGWXTVGXoMQrBw-1; Mon, 15 Mar 2021 05:15:44 -0400 X-MC-Unique: nPrigXOJNGWXTVGXoMQrBw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1877C100C662; Mon, 15 Mar 2021 09:15:43 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60AFF100164C; Mon, 15 Mar 2021 09:15:41 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 17/20] tests: Add tests for query-netdev command Date: Mon, 15 Mar 2021 17:14:30 +0800 Message-Id: <1615799673-31549-18-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kirillov , Jason Wang , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alexey Kirillov A simply qtest that checks for correct number of netdevs in the response of the query-netdev. Signed-off-by: Alexey Kirillov Acked-by: Thomas Huth Signed-off-by: Jason Wang --- tests/qtest/meson.build | 3 + tests/qtest/test-query-netdev.c | 120 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 tests/qtest/test-query-netdev.c diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 2688e1b..66ee9fb 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -30,6 +30,9 @@ qtests_generic = [ if config_host.has_key('CONFIG_MODULES') qtests_generic += [ 'modules-test' ] endif +if slirp.found() + qtests_generic += [ 'test-query-netdev' ] +endif qtests_pci = \ (config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : []) + \ diff --git a/tests/qtest/test-query-netdev.c b/tests/qtest/test-query-netdev.c new file mode 100644 index 0000000..1118537 --- /dev/null +++ b/tests/qtest/test-query-netdev.c @@ -0,0 +1,120 @@ +/* + * QTest testcase for the query-netdev + * + * Copyright Yandex N.V., 2019 + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" + +#include "libqos/libqtest.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qlist.h" + +/* + * Events can get in the way of responses we are actually waiting for. + */ +GCC_FMT_ATTR(2, 3) +static QObject *wait_command(QTestState *who, const char *command, ...) +{ + va_list ap; + QDict *response; + QObject *result; + + va_start(ap, command); + qtest_qmp_vsend(who, command, ap); + va_end(ap); + + response = qtest_qmp_receive(who); + + result = qdict_get(response, "return"); + g_assert(result); + qobject_ref(result); + qobject_unref(response); + + return result; +} + +static void qmp_query_netdev_no_error(QTestState *qts, size_t netdevs_count) +{ + QObject *resp; + QList *netdevs; + + resp = wait_command(qts, "{'execute': 'query-netdev'}"); + + netdevs = qobject_to(QList, resp); + g_assert(netdevs); + g_assert(qlist_size(netdevs) == netdevs_count); + + qobject_unref(resp); +} + +static void test_query_netdev(void) +{ + const char *arch = qtest_get_arch(); + QObject *resp; + QTestState *state; + + /* Choosing machine for platforms without default one */ + if (g_str_equal(arch, "arm") || + g_str_equal(arch, "aarch64")) { + state = qtest_init( + "-nodefaults " + "-M virt " + "-netdev user,id=slirp0"); + } else if (g_str_equal(arch, "tricore")) { + state = qtest_init( + "-nodefaults " + "-M tricore_testboard " + "-netdev user,id=slirp0"); + } else if (g_str_equal(arch, "avr")) { + state = qtest_init( + "-nodefaults " + "-M mega2560 " + "-netdev user,id=slirp0"); + } else if (g_str_equal(arch, "rx")) { + state = qtest_init( + "-nodefaults " + "-M gdbsim-r5f562n8 " + "-netdev user,id=slirp0"); + } else { + state = qtest_init( + "-nodefaults " + "-netdev user,id=slirp0"); + } + g_assert(state); + + qmp_query_netdev_no_error(state, 1); + + resp = wait_command(state, + "{'execute': 'netdev_add', 'arguments': {" + " 'id': 'slirp1'," + " 'type': 'user'}}"); + qobject_unref(resp); + + qmp_query_netdev_no_error(state, 2); + + resp = wait_command(state, + "{'execute': 'netdev_del', 'arguments': {" + " 'id': 'slirp1'}}"); + qobject_unref(resp); + + qmp_query_netdev_no_error(state, 1); + + qtest_quit(state); +} + +int main(int argc, char **argv) +{ + int ret = 0; + g_test_init(&argc, &argv, NULL); + + qtest_add_func("/net/qapi/query_netdev", test_query_netdev); + + ret = g_test_run(); + + return ret; +} From patchwork Mon Mar 15 09:14:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453128 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DCq8zmDT; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzWCb2HWLz9sVm for ; Mon, 15 Mar 2021 20:22:19 +1100 (AEDT) Received: from localhost ([::1]:43326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjQX-0006sc-7j for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:22:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35792) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjKP-0000MQ-BK for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:16:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46746) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjKL-0008Ey-6l for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:15:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799749; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type:in-reply-to:in-reply-to: references:references; bh=h9pbZ/pkRIZW6HwU94ypg8INGZvCwgcj/xaTLOcNEGc=; b=DCq8zmDTpdETTUO1HCEgfK1IGVqZ9SA68yJwO9WgzAtaX2C4NSHLTWQToKMYHXNz8/ChJo dnCZHxiPCPRzD1bVHyNCemfehed6GVR12GqEyMR/kOK/pk3SKSdBgv7kFpxfLR6KXjCGIW /Divsl5/P7Spy0fB3VZ+uvOUL5J8hRg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-359-FM9_f7mCPoaApIjqLsJBDA-1; Mon, 15 Mar 2021 05:15:46 -0400 X-MC-Unique: FM9_f7mCPoaApIjqLsJBDA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 480B89251D; Mon, 15 Mar 2021 09:15:45 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98D75100164C; Mon, 15 Mar 2021 09:15:43 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 18/20] net: Move NetClientState.info_str to dynamic allocations Date: Mon, 15 Mar 2021 17:14:31 +0800 Message-Id: <1615799673-31549-19-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kirillov , Jason Wang , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alexey Kirillov The info_str field of the NetClientState structure is static and has a size of 256 bytes. This amount is often unclaimed, and the field itself is used exclusively for HMP "info network". The patch translates info_str to dynamic memory allocation. This action is also allows us to painlessly discard usage of this field for backend devices. Signed-off-by: Alexey Kirillov Signed-off-by: Jason Wang --- hw/net/xen_nic.c | 5 ++--- include/net/net.h | 2 +- net/l2tpv3.c | 3 +-- net/net.c | 14 ++++++++------ net/slirp.c | 5 ++--- net/socket.c | 43 ++++++++++++++++++++++++------------------- net/tap-win32.c | 3 +-- net/tap.c | 13 +++++-------- net/vde.c | 3 +-- net/vhost-user.c | 3 +-- net/vhost-vdpa.c | 2 +- 11 files changed, 47 insertions(+), 49 deletions(-) diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index 5c815b4..8431808 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -296,9 +296,8 @@ static int net_init(struct XenLegacyDevice *xendev) netdev->nic = qemu_new_nic(&net_xen_info, &netdev->conf, "xen", NULL, netdev); - snprintf(qemu_get_queue(netdev->nic)->info_str, - sizeof(qemu_get_queue(netdev->nic)->info_str), - "nic: xenbus vif macaddr=%s", netdev->mac); + qemu_get_queue(netdev->nic)->info_str = g_strdup_printf( + "nic: xenbus vif macaddr=%s", netdev->mac); /* fill info */ xenstore_write_be_int(&netdev->xendev, "feature-rx-copy", 1); diff --git a/include/net/net.h b/include/net/net.h index dc3679f..a02949f 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -94,7 +94,7 @@ struct NetClientState { NetQueue *incoming_queue; char *model; char *name; - char info_str[256]; + char *info_str; NetdevInfo *stored_config; unsigned receive_disabled : 1; NetClientDestructor *destructor; diff --git a/net/l2tpv3.c b/net/l2tpv3.c index 8aa0a3e..96611cb 100644 --- a/net/l2tpv3.c +++ b/net/l2tpv3.c @@ -730,8 +730,7 @@ int net_init_l2tpv3(const Netdev *netdev, QAPI_CLONE_MEMBERS(NetdevL2TPv3Options, &nc->stored_config->u.l2tpv3, l2tpv3); - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "l2tpv3: connected"); + s->nc.info_str = g_strdup_printf("l2tpv3: connected"); return 0; outerr: qemu_del_net_client(nc); diff --git a/net/net.c b/net/net.c index 9a2a6ab..277da71 100644 --- a/net/net.c +++ b/net/net.c @@ -129,11 +129,12 @@ char *qemu_mac_strdup_printf(const uint8_t *macaddr) void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]) { - snprintf(nc->info_str, sizeof(nc->info_str), - "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x", - nc->model, - macaddr[0], macaddr[1], macaddr[2], - macaddr[3], macaddr[4], macaddr[5]); + g_free(nc->info_str); + nc->info_str = g_strdup_printf( + "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x", + nc->model, + macaddr[0], macaddr[1], macaddr[2], + macaddr[3], macaddr[4], macaddr[5]); } static int mac_table[256] = {0}; @@ -352,6 +353,7 @@ static void qemu_free_net_client(NetClientState *nc) } g_free(nc->name); g_free(nc->model); + g_free(nc->info_str); qapi_free_NetdevInfo(nc->stored_config); if (nc->destructor) { nc->destructor(nc); @@ -1226,7 +1228,7 @@ void print_net_client(Monitor *mon, NetClientState *nc) monitor_printf(mon, "%s: index=%d,type=%s,%s\n", nc->name, nc->queue_index, NetClientDriver_str(nc->info->type), - nc->info_str); + nc->info_str ? nc->info_str : ""); if (!QTAILQ_EMPTY(&nc->filters)) { monitor_printf(mon, "filters:\n"); } diff --git a/net/slirp.c b/net/slirp.c index 6ab348b..bfa07e3 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -664,9 +664,8 @@ static int net_slirp_init(NetClientState *peer, const char *model, stored->tftp_server_name = g_strdup(tftp_server_name); } - snprintf(nc->info_str, sizeof(nc->info_str), - "net=%s,restrict=%s", inet_ntoa(net), - restricted ? "on" : "off"); + nc->info_str = g_strdup_printf("net=%s,restrict=%s", inet_ntoa(net), + restricted ? "on" : "off"); s = DO_UPCAST(SlirpState, nc, nc); diff --git a/net/socket.c b/net/socket.c index 1614523..9817234 100644 --- a/net/socket.c +++ b/net/socket.c @@ -180,7 +180,8 @@ static void net_socket_send(void *opaque) s->fd = -1; net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); s->nc.link_down = true; - memset(s->nc.info_str, 0, sizeof(s->nc.info_str)); + g_free(s->nc.info_str); + s->nc.info_str = g_new0(char, 1); return; } @@ -400,16 +401,16 @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, stored->mcast = g_strdup(mcast); s->dgram_dst = saddr; - snprintf(nc->info_str, sizeof(nc->info_str), - "socket: fd=%d (cloned mcast=%s:%d)", - fd, inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); + nc->info_str = g_strdup_printf("socket: fd=%d (cloned mcast=%s:%d)", + fd, inet_ntoa(saddr.sin_addr), + ntohs(saddr.sin_port)); } else { if (sa_type == SOCKET_ADDRESS_TYPE_UNIX) { s->dgram_dst.sin_family = AF_UNIX; } - snprintf(nc->info_str, sizeof(nc->info_str), - "socket: fd=%d %s", fd, SocketAddressType_str(sa_type)); + nc->info_str = g_strdup_printf("socket: fd=%d %s", + fd, SocketAddressType_str(sa_type)); } return s; @@ -444,7 +445,7 @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer, nc = qemu_new_net_client(&net_socket_info, peer, model, name); - snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d", fd); + nc->info_str = g_strdup_printf("socket: fd=%d", fd); s = DO_UPCAST(NetSocketState, nc, nc); @@ -528,9 +529,10 @@ static void net_socket_accept(void *opaque) stored->has_fd = true; stored->fd = g_strdup_printf("%d", fd); - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "socket: connection from %s:%d", - inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); + g_free(s->nc.info_str); + s->nc.info_str = g_strdup_printf("socket: connection from %s:%d", + inet_ntoa(saddr.sin_addr), + ntohs(saddr.sin_port)); } static int net_socket_listen_init(NetClientState *peer, @@ -645,9 +647,10 @@ static int net_socket_connect_init(NetClientState *peer, stored->has_connect = true; stored->connect = g_strdup(host_str); - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "socket: connect to %s:%d", - inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); + g_free(s->nc.info_str); + s->nc.info_str = g_strdup_printf("socket: connect to %s:%d", + inet_ntoa(saddr.sin_addr), + ntohs(saddr.sin_port)); return 0; } @@ -704,9 +707,10 @@ static int net_socket_mcast_init(NetClientState *peer, stored->localaddr = g_strdup(localaddr_str); } - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "socket: mcast=%s:%d", - inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); + g_free(s->nc.info_str); + s->nc.info_str = g_strdup_printf("socket: mcast=%s:%d", + inet_ntoa(saddr.sin_addr), + ntohs(saddr.sin_port)); return 0; } @@ -769,9 +773,10 @@ static int net_socket_udp_init(NetClientState *peer, stored->has_udp = true; stored->udp = g_strdup(rhost); - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "socket: udp=%s:%d", - inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port)); + g_free(s->nc.info_str); + s->nc.info_str = g_strdup_printf("socket: udp=%s:%d", + inet_ntoa(raddr.sin_addr), + ntohs(raddr.sin_port)); return 0; } diff --git a/net/tap-win32.c b/net/tap-win32.c index b60933b..0888db8 100644 --- a/net/tap-win32.c +++ b/net/tap-win32.c @@ -787,8 +787,7 @@ static int tap_win32_init(NetClientState *peer, const char *model, stored->has_ifname = true; stored->ifname = g_strdup(ifname); - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "tap: ifname=%s", ifname); + s->nc.info_str = g_strdup_printf("tap: ifname=%s", ifname); s->handle = handle; diff --git a/net/tap.c b/net/tap.c index 8041245..f864f43 100644 --- a/net/tap.c +++ b/net/tap.c @@ -625,8 +625,7 @@ int net_init_bridge(const Netdev *netdev, const char *name, stored->helper = g_strdup(helper); } - snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s,br=%s", helper, - br); + s->nc.info_str = g_strdup_printf("helper=%s,br=%s", helper, br); return 0; } @@ -714,7 +713,7 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, g_free(tmp_s); } - snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd); + s->nc.info_str = g_strdup_printf("fd=%d", fd); } else if (tap->has_helper) { if (!stored->has_helper) { stored->has_helper = true; @@ -727,8 +726,7 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, g_strdup(DEFAULT_BRIDGE_INTERFACE); } - snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s", - tap->helper); + s->nc.info_str = g_strdup_printf("helper=%s", tap->helper); } else { if (ifname && !stored->has_ifname) { stored->has_ifname = true; @@ -745,9 +743,8 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, stored->downscript = g_strdup(downscript); } - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "ifname=%s,script=%s,downscript=%s", ifname, script, - downscript); + s->nc.info_str = g_strdup_printf("ifname=%s,script=%s,downscript=%s", + ifname, script, downscript); if (strcmp(downscript, "no") != 0) { snprintf(s->down_script, sizeof(s->down_script), "%s", downscript); diff --git a/net/vde.c b/net/vde.c index b0b8800..67de6eb 100644 --- a/net/vde.c +++ b/net/vde.c @@ -100,8 +100,7 @@ static int net_vde_init(NetClientState *peer, const char *model, nc = qemu_new_net_client(&net_vde_info, peer, model, name); - snprintf(nc->info_str, sizeof(nc->info_str), "sock=%s,fd=%d", - sock, vde_datafd(vde)); + nc->info_str = g_strdup_printf("sock=%s,fd=%d", sock, vde_datafd(vde)); s = DO_UPCAST(VDEState, nc, nc); diff --git a/net/vhost-user.c b/net/vhost-user.c index 5b7056b..49c9a74 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -327,8 +327,7 @@ static int net_vhost_user_init(NetClientState *peer, const char *device, user = g_new0(struct VhostUserState, 1); for (i = 0; i < queues; i++) { nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name); - snprintf(nc->info_str, sizeof(nc->info_str), "vhost-user%d to %s", - i, chr->label); + nc->info_str = g_strdup_printf("vhost-user%d to %s", i, chr->label); nc->queue_index = i; if (!nc0) { nc0 = nc; diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 8c27ea0..423d717 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -200,7 +200,7 @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device, stored->has_queues = true; stored->queues = 1; /* TODO: change when support multiqueue */ - snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA); + nc->info_str = g_strdup_printf(TYPE_VHOST_VDPA); nc->queue_index = 0; s = DO_UPCAST(VhostVDPAState, nc, nc); vdpa_device_fd = qemu_open_old(vhostdev, O_RDWR); From patchwork Mon Mar 15 09:14:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453134 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=IDtqgZzU; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzWLs42r4z9sWF for ; Mon, 15 Mar 2021 20:28:37 +1100 (AEDT) Received: from localhost ([::1]:36138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjWd-0007HD-2k for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:28:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35826) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjKX-0000RF-PY for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:16:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:37152) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjKN-0008FI-1X for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:16:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799753; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type:in-reply-to:in-reply-to: references:references; bh=isyNSp/2RhFSGA6oQpYTNiKMxxPA5chCpwunFVG4v/U=; b=IDtqgZzU3ymOYAVXFQBvpVjKanGkZAu9NbhPk/yiG45P506Wdw71M8wmugsSFcgzvLEjrc KKcdzZWP9HdmrWRQQmud4PQ5vLLc0oMvP+MgsNPXkNT4VX6vqEJISOvX3c38RFP+xg51gk 324VJTuYhr58kKbf/5VFUJmMbPSy4pw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-570-B2UWKAcFPGuCkrYgyj6epQ-1; Mon, 15 Mar 2021 05:15:48 -0400 X-MC-Unique: B2UWKAcFPGuCkrYgyj6epQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A0C0D801817; Mon, 15 Mar 2021 09:15:47 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB33C1007625; Mon, 15 Mar 2021 09:15:45 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 19/20] hmp: Use QAPI NetdevInfo in hmp_info_network Date: Mon, 15 Mar 2021 17:14:32 +0800 Message-Id: <1615799673-31549-20-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kirillov , Jason Wang , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alexey Kirillov Replace usage of legacy field info_str of NetClientState for backend network devices with QAPI NetdevInfo stored_config that already used in QMP query-netdev. This change increases the detail of the "info network" output and takes a more general approach to composing the output. NIC and hubports still use legacy info_str field. Signed-off-by: Alexey Kirillov Signed-off-by: Jason Wang --- include/qapi/hmp-output-visitor.h | 30 ++++++ net/net.c | 31 +++++- qapi/hmp-output-visitor.c | 193 ++++++++++++++++++++++++++++++++++++++ qapi/meson.build | 1 + 4 files changed, 254 insertions(+), 1 deletion(-) create mode 100644 include/qapi/hmp-output-visitor.h create mode 100644 qapi/hmp-output-visitor.c diff --git a/include/qapi/hmp-output-visitor.h b/include/qapi/hmp-output-visitor.h new file mode 100644 index 0000000..541e400 --- /dev/null +++ b/include/qapi/hmp-output-visitor.h @@ -0,0 +1,30 @@ +/* + * HMP string output Visitor + * + * Copyright Yandex N.V., 2021 + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef HMP_OUTPUT_VISITOR_H +#define HMP_OUTPUT_VISITOR_H + +#include "qapi/visitor.h" + +typedef struct HMPOutputVisitor HMPOutputVisitor; + +/** + * Create a HMP string output visitor for @obj + * + * Flattens dicts/structures, only shows arrays borders. + * + * Errors are not expected to happen. + * + * The caller is responsible for freeing the visitor with + * visit_free(). + */ +Visitor *hmp_output_visitor_new(char **result); + +#endif diff --git a/net/net.c b/net/net.c index 277da71..725a4e1 100644 --- a/net/net.c +++ b/net/net.c @@ -55,6 +55,7 @@ #include "sysemu/sysemu.h" #include "net/filter.h" #include "qapi/string-output-visitor.h" +#include "qapi/hmp-output-visitor.h" /* Net bridge is currently not supported for W32. */ #if !defined(_WIN32) @@ -1221,14 +1222,42 @@ static void netfilter_print_info(Monitor *mon, NetFilterState *nf) monitor_printf(mon, "\n"); } +static char *generate_info_str(NetClientState *nc) +{ + NetdevInfo *ni = nc->stored_config; + char *ret_out = NULL; + Visitor *v; + + /* Use legacy field info_str for NIC and hubports */ + if ((nc->info->type == NET_CLIENT_DRIVER_NIC) || + (nc->info->type == NET_CLIENT_DRIVER_HUBPORT)) { + return g_strdup(nc->info_str ? nc->info_str : ""); + } + + if (!ni) { + return g_malloc0(1); + } + + v = hmp_output_visitor_new(&ret_out); + if (visit_type_NetdevInfo(v, "", &ni, NULL)) { + visit_complete(v, &ret_out); + } + visit_free(v); + + return ret_out; +} + void print_net_client(Monitor *mon, NetClientState *nc) { NetFilterState *nf; + char *info_str = generate_info_str(nc); monitor_printf(mon, "%s: index=%d,type=%s,%s\n", nc->name, nc->queue_index, NetClientDriver_str(nc->info->type), - nc->info_str ? nc->info_str : ""); + info_str); + g_free(info_str); + if (!QTAILQ_EMPTY(&nc->filters)) { monitor_printf(mon, "filters:\n"); } diff --git a/qapi/hmp-output-visitor.c b/qapi/hmp-output-visitor.c new file mode 100644 index 0000000..8036605 --- /dev/null +++ b/qapi/hmp-output-visitor.c @@ -0,0 +1,193 @@ +/* + * HMP string output Visitor + * + * Copyright Yandex N.V., 2021 + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu/cutils.h" +#include "qapi/hmp-output-visitor.h" +#include "qapi/visitor-impl.h" + +struct HMPOutputVisitor { + Visitor visitor; + char **result; + GString *buffer; + bool is_continue; +}; + +static HMPOutputVisitor *to_hov(Visitor *v) +{ + return container_of(v, HMPOutputVisitor, visitor); +} + +static void hmp_output_append_formatted(Visitor *v, const char *fmt, ...) +{ + HMPOutputVisitor *ov = to_hov(v); + va_list args; + + if (ov->is_continue) { + g_string_append(ov->buffer, ","); + } else { + ov->is_continue = true; + } + + va_start(args, fmt); + g_string_append_vprintf(ov->buffer, fmt, args); + va_end(args); +} + +static void hmp_output_skip_comma(Visitor *v) +{ + HMPOutputVisitor *ov = to_hov(v); + + ov->is_continue = false; +} + +static bool hmp_output_start_struct(Visitor *v, const char *name, + void **obj, size_t unused, Error **errp) +{ + return true; +} + +static void hmp_output_end_struct(Visitor *v, void **obj) {} + +static bool hmp_output_start_list(Visitor *v, const char *name, + GenericList **listp, size_t size, + Error **errp) +{ + hmp_output_append_formatted(v, "%s=[", name); + /* First element in array without comma before it */ + hmp_output_skip_comma(v); + + return true; +} + +static GenericList *hmp_output_next_list(Visitor *v, GenericList *tail, + size_t size) +{ + return tail->next; +} + +static void hmp_output_end_list(Visitor *v, void **obj) +{ + /* Don't need comma after last array element */ + hmp_output_skip_comma(v); + hmp_output_append_formatted(v, "]"); +} + +static bool hmp_output_type_int64(Visitor *v, const char *name, + int64_t *obj, Error **errp) +{ + hmp_output_append_formatted(v, "%s=%" PRId64, name, *obj); + + return true; +} + +static bool hmp_output_type_uint64(Visitor *v, const char *name, + uint64_t *obj, Error **errp) +{ + hmp_output_append_formatted(v, "%s=%" PRIu64, name, *obj); + + return true; +} + +static bool hmp_output_type_bool(Visitor *v, const char *name, bool *obj, + Error **errp) +{ + hmp_output_append_formatted(v, "%s=%s", name, *obj ? "true" : "false"); + + return true; +} + +static bool hmp_output_type_str(Visitor *v, const char *name, char **obj, + Error **errp) +{ + /* Skip already printed or unused fields */ + if (!*obj || g_str_equal(name, "id") || g_str_equal(name, "type")) { + return true; + } + + /* Do not print stub name for StringList elements */ + if (g_str_equal(name, "str")) { + hmp_output_append_formatted(v, "%s", *obj); + } else { + hmp_output_append_formatted(v, "%s=%s", name, *obj); + } + + return true; +} + +static bool hmp_output_type_number(Visitor *v, const char *name, + double *obj, Error **errp) +{ + hmp_output_append_formatted(v, "%s=%.17g", name, *obj); + + return true; +} + +/* TODO: remove this function? */ +static bool hmp_output_type_any(Visitor *v, const char *name, + QObject **obj, Error **errp) +{ + return true; +} + +static bool hmp_output_type_null(Visitor *v, const char *name, + QNull **obj, Error **errp) +{ + hmp_output_append_formatted(v, "%s=NULL", name); + + return true; +} + +static void hmp_output_complete(Visitor *v, void *opaque) +{ + HMPOutputVisitor *ov = to_hov(v); + + *ov->result = g_string_free(ov->buffer, false); + ov->buffer = NULL; +} + +static void hmp_output_free(Visitor *v) +{ + HMPOutputVisitor *ov = to_hov(v); + + if (ov->buffer) { + g_string_free(ov->buffer, true); + } + g_free(v); +} + +Visitor *hmp_output_visitor_new(char **result) +{ + HMPOutputVisitor *v; + + v = g_malloc0(sizeof(*v)); + + v->visitor.type = VISITOR_OUTPUT; + v->visitor.start_struct = hmp_output_start_struct; + v->visitor.end_struct = hmp_output_end_struct; + v->visitor.start_list = hmp_output_start_list; + v->visitor.next_list = hmp_output_next_list; + v->visitor.end_list = hmp_output_end_list; + v->visitor.type_int64 = hmp_output_type_int64; + v->visitor.type_uint64 = hmp_output_type_uint64; + v->visitor.type_bool = hmp_output_type_bool; + v->visitor.type_str = hmp_output_type_str; + v->visitor.type_number = hmp_output_type_number; + v->visitor.type_any = hmp_output_type_any; + v->visitor.type_null = hmp_output_type_null; + v->visitor.complete = hmp_output_complete; + v->visitor.free = hmp_output_free; + + v->result = result; + v->buffer = g_string_new(""); + v->is_continue = false; + + return &v->visitor; +} diff --git a/qapi/meson.build b/qapi/meson.build index fcb15a7..d4424ae 100644 --- a/qapi/meson.build +++ b/qapi/meson.build @@ -8,6 +8,7 @@ util_ss.add(files( 'qobject-output-visitor.c', 'string-input-visitor.c', 'string-output-visitor.c', + 'hmp-output-visitor.c', )) if have_system or have_tools util_ss.add(files( From patchwork Mon Mar 15 09:14:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1453138 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=B9HL72+f; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DzWQ04KGCz9sVb for ; Mon, 15 Mar 2021 20:31:20 +1100 (AEDT) Received: from localhost ([::1]:44236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLjZG-0002JV-H9 for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2021 05:31:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLjKa-0000Rx-0U for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:16:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51159) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lLjKN-0008F7-1F for qemu-devel@nongnu.org; Mon, 15 Mar 2021 05:16:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615799753; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type:in-reply-to:in-reply-to: references:references; bh=E+VgJlvCIJSqdxoF3v8V8EV1mu/+683LeE+XvfdyiPg=; b=B9HL72+feZoDh+P5Kqj8A+K9LVWApFI4KjSFM1Ds4Fnt+PUW7GYlXQEMT6ou5+h/+Mdemg SiAUyexYNT8Fcuk3lyhXOC/4ANKuCedVLsOR3eRB/P0fiQKtLozFcZE5XroKmIzx6gqPF/ QSEd7VTEckX1IqYoE9czAqjtL5iV3qk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-585-NZRAedaHNkyNCdVrTpwRAw-1; Mon, 15 Mar 2021 05:15:51 -0400 X-MC-Unique: NZRAedaHNkyNCdVrTpwRAw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CCDFE80006E; Mon, 15 Mar 2021 09:15:49 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-13-105.pek2.redhat.com [10.72.13.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D3FF100164C; Mon, 15 Mar 2021 09:15:47 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org Subject: [PULL V2 20/20] net: Do not fill legacy info_str for backends Date: Mon, 15 Mar 2021 17:14:33 +0800 Message-Id: <1615799673-31549-21-git-send-email-jasowang@redhat.com> In-Reply-To: <1615799673-31549-1-git-send-email-jasowang@redhat.com> References: <1615799673-31549-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kirillov , Jason Wang , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alexey Kirillov As we use QAPI NetClientState->stored_config to store and get information about backend network devices, we can drop fill of legacy field info_str for them. We still use info_str field for NIC and hubports, so we can not completely remove it. Signed-off-by: Alexey Kirillov Signed-off-by: Jason Wang --- net/l2tpv3.c | 2 -- net/slirp.c | 3 --- net/socket.c | 28 ---------------------------- net/tap-win32.c | 2 -- net/tap.c | 9 --------- net/vde.c | 2 -- net/vhost-user.c | 1 - net/vhost-vdpa.c | 1 - 8 files changed, 48 deletions(-) diff --git a/net/l2tpv3.c b/net/l2tpv3.c index 96611cb..b7e1d84 100644 --- a/net/l2tpv3.c +++ b/net/l2tpv3.c @@ -729,8 +729,6 @@ int net_init_l2tpv3(const Netdev *netdev, QAPI_CLONE_MEMBERS(NetdevL2TPv3Options, &nc->stored_config->u.l2tpv3, l2tpv3); - - s->nc.info_str = g_strdup_printf("l2tpv3: connected"); return 0; outerr: qemu_del_net_client(nc); diff --git a/net/slirp.c b/net/slirp.c index bfa07e3..9454a67 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -664,9 +664,6 @@ static int net_slirp_init(NetClientState *peer, const char *model, stored->tftp_server_name = g_strdup(tftp_server_name); } - nc->info_str = g_strdup_printf("net=%s,restrict=%s", inet_ntoa(net), - restricted ? "on" : "off"); - s = DO_UPCAST(SlirpState, nc, nc); s->slirp = slirp_init(restricted, ipv4, net, mask, host, diff --git a/net/socket.c b/net/socket.c index 9817234..c0de10c 100644 --- a/net/socket.c +++ b/net/socket.c @@ -180,8 +180,6 @@ static void net_socket_send(void *opaque) s->fd = -1; net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); s->nc.link_down = true; - g_free(s->nc.info_str); - s->nc.info_str = g_new0(char, 1); return; } @@ -401,16 +399,10 @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, stored->mcast = g_strdup(mcast); s->dgram_dst = saddr; - nc->info_str = g_strdup_printf("socket: fd=%d (cloned mcast=%s:%d)", - fd, inet_ntoa(saddr.sin_addr), - ntohs(saddr.sin_port)); } else { if (sa_type == SOCKET_ADDRESS_TYPE_UNIX) { s->dgram_dst.sin_family = AF_UNIX; } - - nc->info_str = g_strdup_printf("socket: fd=%d %s", - fd, SocketAddressType_str(sa_type)); } return s; @@ -445,8 +437,6 @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer, nc = qemu_new_net_client(&net_socket_info, peer, model, name); - nc->info_str = g_strdup_printf("socket: fd=%d", fd); - s = DO_UPCAST(NetSocketState, nc, nc); s->fd = fd; @@ -528,11 +518,6 @@ static void net_socket_accept(void *opaque) stored->has_fd = true; stored->fd = g_strdup_printf("%d", fd); - - g_free(s->nc.info_str); - s->nc.info_str = g_strdup_printf("socket: connection from %s:%d", - inet_ntoa(saddr.sin_addr), - ntohs(saddr.sin_port)); } static int net_socket_listen_init(NetClientState *peer, @@ -647,10 +632,6 @@ static int net_socket_connect_init(NetClientState *peer, stored->has_connect = true; stored->connect = g_strdup(host_str); - g_free(s->nc.info_str); - s->nc.info_str = g_strdup_printf("socket: connect to %s:%d", - inet_ntoa(saddr.sin_addr), - ntohs(saddr.sin_port)); return 0; } @@ -707,12 +688,7 @@ static int net_socket_mcast_init(NetClientState *peer, stored->localaddr = g_strdup(localaddr_str); } - g_free(s->nc.info_str); - s->nc.info_str = g_strdup_printf("socket: mcast=%s:%d", - inet_ntoa(saddr.sin_addr), - ntohs(saddr.sin_port)); return 0; - } static int net_socket_udp_init(NetClientState *peer, @@ -773,10 +749,6 @@ static int net_socket_udp_init(NetClientState *peer, stored->has_udp = true; stored->udp = g_strdup(rhost); - g_free(s->nc.info_str); - s->nc.info_str = g_strdup_printf("socket: udp=%s:%d", - inet_ntoa(raddr.sin_addr), - ntohs(raddr.sin_port)); return 0; } diff --git a/net/tap-win32.c b/net/tap-win32.c index 0888db8..21e4511 100644 --- a/net/tap-win32.c +++ b/net/tap-win32.c @@ -787,8 +787,6 @@ static int tap_win32_init(NetClientState *peer, const char *model, stored->has_ifname = true; stored->ifname = g_strdup(ifname); - s->nc.info_str = g_strdup_printf("tap: ifname=%s", ifname); - s->handle = handle; qemu_add_wait_object(s->handle->tap_semaphore, tap_win32_send, s); diff --git a/net/tap.c b/net/tap.c index f864f43..12a08d5 100644 --- a/net/tap.c +++ b/net/tap.c @@ -625,8 +625,6 @@ int net_init_bridge(const Netdev *netdev, const char *name, stored->helper = g_strdup(helper); } - s->nc.info_str = g_strdup_printf("helper=%s,br=%s", helper, br); - return 0; } @@ -712,8 +710,6 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, stored->fds = g_strdup_printf("%s:%d", stored->fds, fd); g_free(tmp_s); } - - s->nc.info_str = g_strdup_printf("fd=%d", fd); } else if (tap->has_helper) { if (!stored->has_helper) { stored->has_helper = true; @@ -725,8 +721,6 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, stored->br = tap->has_br ? g_strdup(tap->br) : g_strdup(DEFAULT_BRIDGE_INTERFACE); } - - s->nc.info_str = g_strdup_printf("helper=%s", tap->helper); } else { if (ifname && !stored->has_ifname) { stored->has_ifname = true; @@ -743,9 +737,6 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, stored->downscript = g_strdup(downscript); } - s->nc.info_str = g_strdup_printf("ifname=%s,script=%s,downscript=%s", - ifname, script, downscript); - if (strcmp(downscript, "no") != 0) { snprintf(s->down_script, sizeof(s->down_script), "%s", downscript); snprintf(s->down_script_arg, sizeof(s->down_script_arg), diff --git a/net/vde.c b/net/vde.c index 67de6eb..64bdb93 100644 --- a/net/vde.c +++ b/net/vde.c @@ -100,8 +100,6 @@ static int net_vde_init(NetClientState *peer, const char *model, nc = qemu_new_net_client(&net_vde_info, peer, model, name); - nc->info_str = g_strdup_printf("sock=%s,fd=%d", sock, vde_datafd(vde)); - s = DO_UPCAST(VDEState, nc, nc); s->vde = vde; diff --git a/net/vhost-user.c b/net/vhost-user.c index 49c9a74..e443c4b 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -327,7 +327,6 @@ static int net_vhost_user_init(NetClientState *peer, const char *device, user = g_new0(struct VhostUserState, 1); for (i = 0; i < queues; i++) { nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name); - nc->info_str = g_strdup_printf("vhost-user%d to %s", i, chr->label); nc->queue_index = i; if (!nc0) { nc0 = nc; diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 423d717..5a28bbc 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -200,7 +200,6 @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device, stored->has_queues = true; stored->queues = 1; /* TODO: change when support multiqueue */ - nc->info_str = g_strdup_printf(TYPE_VHOST_VDPA); nc->queue_index = 0; s = DO_UPCAST(VhostVDPAState, nc, nc); vdpa_device_fd = qemu_open_old(vhostdev, O_RDWR);