From nobody Wed Apr 16 00:19:35 2025 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1683030278; cv=none; d=zohomail.com; s=zohoarc; b=mEC1dItIpP57rCN45wHDnJa1Xet4F1QNBOuLc19NthNraiRbXJdeRhPuJ7o/paSDpoBAXHnC7HpepyCYRc2yeAxP21wmhfII+bHQN+EguQqNHm/T/VCKnLzW3MePjPqToRX8c2ws64dwRyiXekxLK+OBsI4pUWhe7aml8O93Tlk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683030278; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OBdth3iwW/4zz8A4f8Bu3URSn8HTxb6Inx0wWl85wL0=; b=elCKqsNaPNYnece+8iJYlYLhsl7WRTEVtH2KdW2FNf/jaLzQWD0bBHrJRS+WKexK9CkHrUjGwU5yacSPBpRZJzADQGhJ6a7FYm/CfcB0Q2mcO/lBJcQCzIuM3astpupo+gX9xbiuwY0K68vfelTc4756SnxptZJcgQlLa8bFozU= 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 1683030278254960.1744939194132; Tue, 2 May 2023 05:24:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ptovM-0004Mn-Vq; Tue, 02 May 2023 08:16:05 -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 1ptoui-0003oU-Tk for qemu-devel@nongnu.org; Tue, 02 May 2023 08:15:36 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ptouY-0003E7-JP for qemu-devel@nongnu.org; Tue, 02 May 2023 08:15:22 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f19ab994ccso38260995e9.2 for ; Tue, 02 May 2023 05:15:14 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id g10-20020a7bc4ca000000b003f171234a08sm35040330wmk.20.2023.05.02.05.15.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 05:15:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683029713; x=1685621713; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=OBdth3iwW/4zz8A4f8Bu3URSn8HTxb6Inx0wWl85wL0=; b=o1Cvpr88A2SPITpOrLiVWGDuXarn93RlflkUxEWxQyHNUL2sK9r3SznG4kolvmSjon J0y1TZUB2YnWAqwlk8tlxCE8ZTSP3xapk84hJQGifkSKcWwbY3ngD68MfLPLtHbOVQ9H qiDZDInlncb9MhAfxy/P3AJU0nbsmUDbFFCqLIH9tI0VNFqZe+7URYFm3SWfmZ5bWLnB XvqycdT7pn7AX8dtdWIsyJg93kMipxc5+QY4KmK9b10og66/nr4f6NNxEzPArJQx7V8G dulZQnbW1Psdk7r9pZNRufnz33Dzig5jen85Gn0Ahw+X/cZ7XQSZuSBaDGoKIsvcHHil NK1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683029713; x=1685621713; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OBdth3iwW/4zz8A4f8Bu3URSn8HTxb6Inx0wWl85wL0=; b=VqzHNVQhK6oWsllNyKOPzP7x+qv6+IJMjFdcQlcHiN9Dp/HwZcbcpGRghfeuk4KBVe c1jQS2ha6DBhNjJehygWrRuYK5Sa8cYysmc2ohecTzmooPDXFCBQTN3uPrgoYJRU/sR1 ReiJe4yFbweHGa6ENlT6EAG1GLYT4Y6PjY5261OchOLUrfpyEgiAwWb538zEgPmmuefE GyvLPEn3CjWS8YMFa+tH4PSkHS8Ay7ZFvRebRkRsKhK6pVEJymkam63kqmVqRk9/F3mS 6gd0JYdfvyB1ZC6SNOhjskgldlYSOg+ba/8IPtjdld1fHRmdp7g/fZikbHPPp1TWxCGD uDeg== X-Gm-Message-State: AC+VfDxidlF7BvnbDApNt9Dnd964IJvd4WSeFS0EFBxZBL3dMFal0tRj 5HTUzXh2U5Nocxr+GRNzeZsePNm8lfcC9S2G9U8= X-Google-Smtp-Source: ACHHUZ7U+awM2wx3C+MpS7nV1uR3567qm3eVN7b+KuzeJKamlogEivDZ/ii4anFSKnwsmQsSlCIthw== X-Received: by 2002:a1c:f217:0:b0:3f2:5641:1477 with SMTP id s23-20020a1cf217000000b003f256411477mr12099387wmc.2.1683029713222; Tue, 02 May 2023 05:15:13 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 27/35] hw/net/msf2-emac: Don't modify descriptor in-place in emac_store_desc() Date: Tue, 2 May 2023 13:14:51 +0100 Message-Id: <20230502121459.2422303-28-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230502121459.2422303-1-peter.maydell@linaro.org> References: <20230502121459.2422303-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::336; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x336.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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 @linaro.org) X-ZM-MESSAGEID: 1683030279593100001 Content-Type: text/plain; charset="utf-8" The msf2-emac ethernet controller has functions emac_load_desc() and emac_store_desc() which read and write the in-memory descriptor blocks and handle conversion between guest and host endianness. As currently written, emac_store_desc() does the endianness conversion in-place; this means that it effectively consumes the input EmacDesc struct, because on a big-endian host the fields will be overwritten with the little-endian versions of their values. Unfortunately, in all the callsites the code continues to access fields in the EmacDesc struct after it has called emac_store_desc() -- specifically, it looks at the d.next field. The effect of this is that on a big-endian host networking doesn't work because the address of the next descriptor is corrupted. We could fix this by making the callsite avoid using the struct; but it's more robust to have emac_store_desc() leave its input alone. (emac_load_desc() also does an in-place conversion, but here this is fine, because the function is supposed to be initializing the struct.) Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell Reviewed-by: Thomas Huth Message-id: 20230424151919.1333299-1-peter.maydell@linaro.org --- hw/net/msf2-emac.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/net/msf2-emac.c b/hw/net/msf2-emac.c index 7ccd3e51427..db3a04deb19 100644 --- a/hw/net/msf2-emac.c +++ b/hw/net/msf2-emac.c @@ -118,14 +118,18 @@ static void emac_load_desc(MSF2EmacState *s, EmacDesc= *d, hwaddr desc) d->next =3D le32_to_cpu(d->next); } =20 -static void emac_store_desc(MSF2EmacState *s, EmacDesc *d, hwaddr desc) +static void emac_store_desc(MSF2EmacState *s, const EmacDesc *d, hwaddr de= sc) { - /* Convert from host endianness into LE. */ - d->pktaddr =3D cpu_to_le32(d->pktaddr); - d->pktsize =3D cpu_to_le32(d->pktsize); - d->next =3D cpu_to_le32(d->next); + EmacDesc outd; + /* + * Convert from host endianness into LE. We use a local struct because + * calling code may still want to look at the fields afterwards. + */ + outd.pktaddr =3D cpu_to_le32(d->pktaddr); + outd.pktsize =3D cpu_to_le32(d->pktsize); + outd.next =3D cpu_to_le32(d->next); =20 - address_space_write(&s->dma_as, desc, MEMTXATTRS_UNSPECIFIED, d, sizeo= f *d); + address_space_write(&s->dma_as, desc, MEMTXATTRS_UNSPECIFIED, &outd, s= izeof outd); } =20 static void msf2_dma_tx(MSF2EmacState *s) --=20 2.34.1