From patchwork Mon Apr 24 15:19:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 676571 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a41:0:0:0:0:0 with SMTP id v1csp2217814wrs; Mon, 24 Apr 2023 08:20:35 -0700 (PDT) X-Google-Smtp-Source: AKy350bneyyDfri+Uj/JeR9Bt2wdAnnhY/a9zsM3nlnVd5WLpoYXm+0+79f8NcmfXlhURrKaVkYm X-Received: by 2002:ad4:5966:0:b0:5ca:f6dd:f3b6 with SMTP id eq6-20020ad45966000000b005caf6ddf3b6mr18116593qvb.16.1682349634989; Mon, 24 Apr 2023 08:20:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682349634; cv=none; d=google.com; s=arc-20160816; b=P8fEjNvHDoOOzE4h1Laix3DamQpVIPUgcryPrtHO4Rl7Xq6EG9UkHc/M+kk5hYhCsE +5NUwMpqHknK6jVEM/GpzwA5eOqKvRZqV3R20FEDzbnb5q4ul4FewYhUjIyvPzqYVLbF CZUzXzByS1QvRNTp3yqD5c6B2StIIF7+Qv2iXSTvqDiUSXlolMSHW0NNwtjPK5j3Qxpu KVIHj7SEg4mKGpxHame6o2vJrJ8ll58XvmpcAbhHLh9Nt09Yq1lPop56Rwo9p+y6hVOk gW3+BycMXs63brkT57uURft+8hCZcDs04i3BtadRbcwapYcXAYcRBzx2PTsOrWQhr+2E HLPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=0ew3Q4Te16gnuQZBIdWPX9nVhsTHp7a/L7LDD7lrC64=; b=pMA+2KZWCwPwTs0Ji9iyKJHozoRrepQa4HxUTnap3mlxEmsOYZDkTJpO8u6xDKteuG wfMO4iEyCIpyEYEUuzMWK/cJhJEZQ/+Klo2vJmECXHzdO4mEeLD29F9iMqf58/MnkVL3 tbKnkIqdormtG4hueaeFUkkH9PUDfx/mAsKAAFKYu3wh1IlAH513MZOcPDM8RXp9FMqu A8d9MAbBzC/QFueVknLCkdvdMc/c4U3U4olnTfPAYQLcc649PrCNIAD56HJ7elZtiPTV ZwIWRn+BO1Uioohcvb4m75mO8beTZxhnwI66X3TT5chfDWXXvHoG7Y4MR7a7qNdW8BkI zyBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XGBdXVAu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id gg7-20020a056214252700b005ef64bd04ffsi5799590qvb.12.2023.04.24.08.20.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Apr 2023 08:20:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XGBdXVAu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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) static void emac_store_desc(MSF2EmacState *s, EmacDesc *d, hwaddr desc) { - /* Convert from host endianness into LE. */ - d->pktaddr = cpu_to_le32(d->pktaddr); - d->pktsize = cpu_to_le32(d->pktsize); - d->next = 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 = cpu_to_le32(d->pktaddr); + outd.pktsize = cpu_to_le32(d->pktsize); + outd.next = cpu_to_le32(d->next); - address_space_write(&s->dma_as, desc, MEMTXATTRS_UNSPECIFIED, d, sizeof *d); + address_space_write(&s->dma_as, desc, MEMTXATTRS_UNSPECIFIED, &outd, sizeof outd); } static void msf2_dma_tx(MSF2EmacState *s)