From nobody Mon Nov 25 08:01:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1717486819; cv=none; d=zohomail.com; s=zohoarc; b=QzhL5ZUw1ecaUerVkZHY2HRLVQW0DJWJhRj4xZ4iG8OC0/Ppmoa7VXlvJaE+1a4GYw0TL6HYlNKihmM7SbLWLoguigjP0mgs8kUXSsedHTTFNIh629vgOQqjpR45JHPxZVZNW2jfuXUC/Tsc8FGuDR0FkJNvqTTOBg0FULSJ76o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717486819; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=P6HHbjqk4XrFefVy6GQgM1+QvWuppZRcdnzLqF6vvXY=; b=jezNWXc568QRnNUkGIjhDPhCNAEUMQBYequYHmZoAM2dxPCBVWn1/uEjBnHd2QRYdqO6GtagfWA8+rW0oR7D6IVX70oYKIg3bnbW+5F5tWmNG4rNrFZjC1GWgQfuj7oUdwvblkrd6GiahjNx69U5LP5dXudKrYLG+kG/JgjaQ/g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17174868196751005.1069783105492; Tue, 4 Jun 2024 00:40:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEOks-0000TP-6p; Tue, 04 Jun 2024 03:38:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEOko-0000L9-81 for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:38:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEOkm-0006NZ-F5 for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:38:46 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-247-MBah7YaMODq9SRMnQyyS9w-1; Tue, 04 Jun 2024 03:38:42 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C14DA185B920; Tue, 4 Jun 2024 07:38:41 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9AAEC492BD6; Tue, 4 Jun 2024 07:38:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717486723; 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=P6HHbjqk4XrFefVy6GQgM1+QvWuppZRcdnzLqF6vvXY=; b=AaArSsmQ2z4pVt7KRUxxdbcGsPG5r+KTkCyOY4udNoKpMW0Kly4EZ5x0Q38M2xRo5mYEMw d81GVQD/wsD5ZADexJTZQJmgUHPLM5FjanxIGaPklEzZyNNCjjNFS+RwqZn5Wj5fcK9VeI bse9uCC0RCJB2G9BhWxoxS+VMLuqukg= X-MC-Unique: MBah7YaMODq9SRMnQyyS9w-1 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Cc: Akihiko Odaki , Jason Wang Subject: [PULL 14/20] virtio-net: Do not write hashes to peer buffer Date: Tue, 4 Jun 2024 15:37:49 +0800 Message-ID: <20240604073755.1859-15-jasowang@redhat.com> In-Reply-To: <20240604073755.1859-1-jasowang@redhat.com> References: <20240604073755.1859-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717486820318100001 Content-Type: text/plain; charset="utf-8" From: Akihiko Odaki The peer buffer is qualified with const and not meant to be modified. Signed-off-by: Akihiko Odaki Signed-off-by: Jason Wang --- hw/net/virtio-net.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index b423169a48..666a4e2a03 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1830,16 +1830,9 @@ static uint8_t virtio_net_get_hash_type(bool hasip4, return 0xff; } =20 -static void virtio_set_packet_hash(const uint8_t *buf, uint8_t report, - uint32_t hash) -{ - struct virtio_net_hdr_v1_hash *hdr =3D (void *)buf; - hdr->hash_value =3D hash; - hdr->hash_report =3D report; -} - static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf, - size_t size) + size_t size, + struct virtio_net_hdr_v1_hash *hdr) { VirtIONet *n =3D qemu_get_nic_opaque(nc); unsigned int index =3D nc->queue_index, new_index =3D index; @@ -1870,7 +1863,8 @@ static int virtio_net_process_rss(NetClientState *nc,= const uint8_t *buf, n->rss_data.hash_types); if (net_hash_type > NetPktRssIpV6UdpEx) { if (n->rss_data.populate_hash) { - virtio_set_packet_hash(buf, VIRTIO_NET_HASH_REPORT_NONE, 0); + hdr->hash_value =3D VIRTIO_NET_HASH_REPORT_NONE; + hdr->hash_report =3D 0; } return n->rss_data.redirect ? n->rss_data.default_queue : -1; } @@ -1878,7 +1872,8 @@ static int virtio_net_process_rss(NetClientState *nc,= const uint8_t *buf, hash =3D net_rx_pkt_calc_rss_hash(pkt, net_hash_type, n->rss_data.key); =20 if (n->rss_data.populate_hash) { - virtio_set_packet_hash(buf, reports[net_hash_type], hash); + hdr->hash_value =3D hash; + hdr->hash_report =3D reports[net_hash_type]; } =20 if (n->rss_data.redirect) { @@ -1898,7 +1893,7 @@ static ssize_t virtio_net_receive_rcu(NetClientState = *nc, const uint8_t *buf, VirtQueueElement *elems[VIRTQUEUE_MAX_SIZE]; size_t lens[VIRTQUEUE_MAX_SIZE]; struct iovec mhdr_sg[VIRTQUEUE_MAX_SIZE]; - struct virtio_net_hdr_mrg_rxbuf mhdr; + struct virtio_net_hdr_v1_hash extra_hdr; unsigned mhdr_cnt =3D 0; size_t offset, i, guest_offset, j; ssize_t err; @@ -1908,7 +1903,7 @@ static ssize_t virtio_net_receive_rcu(NetClientState = *nc, const uint8_t *buf, } =20 if (!no_rss && n->rss_data.enabled && n->rss_data.enabled_software_rss= ) { - int index =3D virtio_net_process_rss(nc, buf, size); + int index =3D virtio_net_process_rss(nc, buf, size, &extra_hdr); if (index >=3D 0) { NetClientState *nc2 =3D qemu_get_subqueue(n->nic, index); return virtio_net_receive_rcu(nc2, buf, size, true); @@ -1968,15 +1963,17 @@ static ssize_t virtio_net_receive_rcu(NetClientStat= e *nc, const uint8_t *buf, if (n->mergeable_rx_bufs) { mhdr_cnt =3D iov_copy(mhdr_sg, ARRAY_SIZE(mhdr_sg), sg, elem->in_num, - offsetof(typeof(mhdr), num_buffers), - sizeof(mhdr.num_buffers)); + offsetof(typeof(extra_hdr), hdr.num_bu= ffers), + sizeof(extra_hdr.hdr.num_buffers)); } =20 receive_header(n, sg, elem->in_num, buf, size); if (n->rss_data.populate_hash) { - offset =3D sizeof(mhdr); + offset =3D offsetof(typeof(extra_hdr), hash_value); iov_from_buf(sg, elem->in_num, offset, - buf + offset, n->host_hdr_len - sizeof(mhdr)); + (char *)&extra_hdr + offset, + sizeof(extra_hdr.hash_value) + + sizeof(extra_hdr.hash_report)); } offset =3D n->host_hdr_len; total +=3D n->guest_hdr_len; @@ -2006,10 +2003,11 @@ static ssize_t virtio_net_receive_rcu(NetClientStat= e *nc, const uint8_t *buf, } =20 if (mhdr_cnt) { - virtio_stw_p(vdev, &mhdr.num_buffers, i); + virtio_stw_p(vdev, &extra_hdr.hdr.num_buffers, i); iov_from_buf(mhdr_sg, mhdr_cnt, 0, - &mhdr.num_buffers, sizeof mhdr.num_buffers); + &extra_hdr.hdr.num_buffers, + sizeof extra_hdr.hdr.num_buffers); } =20 for (j =3D 0; j < i; j++) { --=20 2.42.0