From nobody Mon May 20 04:01:53 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1682349635; cv=none; d=zohomail.com; s=zohoarc; b=TobN/xOo4BucjpL3z/qIyLe5RKOD8Y1Y/nCQ0KKgEfgzl1wPR/Z9y9Db6E4xp/dQtcJVLFUwxm+eN9cP5SzWQNrNH7ftktlD+20zFzGZFiqv+Bq4uYeDIh2MRyx67E+Ja8fB0b6cNE2IyQ8jwQJmvR1nT6ULm+9sLUnbZyebFgw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682349635; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=0ew3Q4Te16gnuQZBIdWPX9nVhsTHp7a/L7LDD7lrC64=; b=V7tkYf20DVy/ad/ByTS4A1sshEmCgUFzfaBTNNyyxIaOYsTptiUWfUS1coF229m36SEf6wzKVKqh2Rvc3qJeswvHLwR8W5Oj5ZNISaxmhph8O9a/16p1CeVNE4+NnnpOGzwp6Tyt/uukmffURzBOLEQiJnrcTJM6NEr2jysCwPg= 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 1682349635555444.3933814269931; Mon, 24 Apr 2023 08:20:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pqxyS-000369-5Y; Mon, 24 Apr 2023 11:19:28 -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 1pqxyQ-00035Y-NK for qemu-devel@nongnu.org; Mon, 24 Apr 2023 11:19:26 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pqxyO-000556-1K for qemu-devel@nongnu.org; Mon, 24 Apr 2023 11:19:26 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f178da21b5so30804735e9.3 for ; Mon, 24 Apr 2023 08:19:23 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id c16-20020a05600c0ad000b003f198dfbbfcsm6740939wmr.19.2023.04.24.08.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 08:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1682349562; x=1684941562; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=0ew3Q4Te16gnuQZBIdWPX9nVhsTHp7a/L7LDD7lrC64=; b=XGBdXVAulx1pnsRt5YwIemP4xWGq8Vom4cLsvUMiC4YbLYQlokP8XjWsbeLwpxntru P4DSkkUZJo6aMPtAM9J8mWk4uM1KvOqtkduiU+xuthhFyxm5yv51vNWVE0t/yF78NJUe NUVpZ9ZvYaMf2r5D6ux1uBiDTSiR0hLbnozOOQBkXOort8zG2gRRpoYtoGCILKdxBLfb XPAlnpPyPgiH1EBGB4dijaFimDYBz/0+AJHZTh0kmT8310aGjyzjv8HRMg17j3C7YlUZ ho5qD3oFYKknYlW9pFGFGpx9XP4HKERuKAiAVtVBuQO5k3I+1qExR8gS4EHYQclrNme9 5FFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682349562; x=1684941562; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0ew3Q4Te16gnuQZBIdWPX9nVhsTHp7a/L7LDD7lrC64=; b=T2cVP5BIx+lm72uKqKM3Y6nBlUSrxvCxym0hvChs9SCEAo/OdVOD+weaHMwrk++wPS YnqfU4AmdZ/BLoEpdEKtoWRDLCWxJS4tkp5kKmpMi/XYoLiDlBfIjzwysRMhMA6vSN37 HlD86lIuQTw/9fy36kI+WCJxqS0JjcNwzgqdTNlFbAx4JUMpMqC0v2tv31RMCDOH+1NL v1i3HhX+H5ct01NwvueUonZJ6uYFz3Y4aJPMTNRaiwshtQGV6LJF5K053+2PRKfTbzKa HYx5c5g+iZYVflArLbs6SUew6D59QkTMDr/YB6EMCr5ql08Qlmb5x1EtjffLnnu/u1XQ Sh9A== X-Gm-Message-State: AAQBX9fxlDBBxi8aFhp6DBSia3PK+4JypIvtRW18iYwVG3ZO13kB+PsL Q3Ld/LBQX1xbVZh54XVJVqcU2A== X-Google-Smtp-Source: AKy350bicqVT/66vlx7lfxsYaQHiUTYju7s7vSriBwSWk690ZkDC6aUWEGM5aQH4k+ppGdrrD1mksg== X-Received: by 2002:a05:600c:b49:b0:3f1:72db:4554 with SMTP id k9-20020a05600c0b4900b003f172db4554mr7908798wmr.1.1682349562055; Mon, 24 Apr 2023 08:19:22 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Jason Wang , Subbaraya Sundeep Subject: [PATCH] hw/net/msf2-emac: Don't modify descriptor in-place in emac_store_desc() Date: Mon, 24 Apr 2023 16:19:19 +0100 Message-Id: <20230424151919.1333299-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 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::332; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x332.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1682349636900100001 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 --- This is one of a number of issues that prevent 'make check-avocado' working for arm targets on a big-endian host... hw/net/msf2-emac.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hw/net/msf2-emac.c b/hw/net/msf2-emac.c index 7ccd3e51427..34c1f768db0 100644 --- a/hw/net/msf2-emac.c +++ b/hw/net/msf2-emac.c @@ -120,12 +120,16 @@ static void emac_load_desc(MSF2EmacState *s, EmacDesc= *d, hwaddr desc) =20 static void emac_store_desc(MSF2EmacState *s, EmacDesc *d, hwaddr desc) { - /* 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