From nobody Sat May 4 23:40:26 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=1604682832; cv=none; d=zohomail.com; s=zohoarc; b=hlcHjYNnKPISPfMsMVhkgAFJ7uJdrb+StJVVwHR6rnbImnnbh+9Vme5unWrgb7wf+yWLza5DfieMMUWdYvsApNAwNqWiUOcZVAsHSkSNj8dIVFONS70bU+W3Q7BZfzzrx3o3UKvyROVo8qmT7+Dv3Vb52t64Zx3EPZHHxa/VFOg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604682832; h=Content-Transfer-Encoding:Cc: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=c5vzAfZVeD2fj+XSE443hBvvKPlw3OYEaKcDPAg0K5A=; b=MlcY2cpUVeF9ybR4N+IwWTZ9Q3MdHo/n7LsNCXTQtSrLSwv9kSXCUX8fYimZsKurVZeWnXsAIcYXtDl/XGQdQF/F5z3sKQJteZJLt34m4iGcT/rmj3jygz9BkKoE3sxIMwSRu7Zv6EeXE9vW343BUKFNFuEpO+h2uN0KMw7upto= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604682832487601.6290053519851; Fri, 6 Nov 2020 09:13:52 -0800 (PST) Received: from localhost ([::1]:40356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kb5J9-0002uq-9x for importer@patchew.org; Fri, 06 Nov 2020 12:13:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34662) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb5HM-0001D2-N7 for qemu-devel@nongnu.org; Fri, 06 Nov 2020 12:12:00 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:36791) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kb5HK-0003Mm-TX for qemu-devel@nongnu.org; Fri, 06 Nov 2020 12:12:00 -0500 Received: by mail-wm1-x342.google.com with SMTP id a65so2015649wme.1 for ; Fri, 06 Nov 2020 09:11:58 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id l1sm3162649wrb.1.2020.11.06.09.11.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2020 09:11:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=c5vzAfZVeD2fj+XSE443hBvvKPlw3OYEaKcDPAg0K5A=; b=dIleZsap3o6+gXkOpa4XvxrVEYJ996ZN0OD9RRKGSTVcfC88Oy44hK7YibbrOwON0K ZJOfVd4VrlGwyqvGaqnINa4uofv0mw64XDU7yvbMCBGgW/VVjfTXe/fHUY+piAAweZI8 aqNkmLicRvZBwxA7HnxQb/7kWtq4eV4EUuYMEQ/wOmycK1hfU06RLPBGdjD7i+A0L90G 15fwFJyw4rzOcx/w7/ofjlk+Vo6T71UzIVgcnwqvYKl5PTbwG7Fup8EeCKyxQ0CHL5Ak ZYxBcfjoXPoPsAhobPej6IlOrGuaz7EIAUANKsC6lvL6S+e39wH5CQu4fqDR8c9QMNgF orAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=c5vzAfZVeD2fj+XSE443hBvvKPlw3OYEaKcDPAg0K5A=; b=OKodl3ZqyjS8P2FWI6Dl3NWO7SVF2eRZPDtqyLATKriz9oxRav6qu4QFcBAgTzoKFg yQDfNQSqJcBk3nUJgjxvgTB/jyvQoCI04H8lqCe14Sx/NO8JWc+BGTqf0vM8BT3S1vAj miVQ+4381pf83TpnuEmp5ZvZtPalsF7yk2x8jNkMvBjUlWF9zT29G8t83yEZ7HzJubxB iIQE68U2NqqlKeb0cShoJyqC6STw+ClfuTnd6l6jjearW8iDbo7EDGj4phfCEDcgYQ4z h/KohBLlFnOQ9vevdX+lgJ+4S86IAD2QwS3EhzzkjRP2Yo+Uh9j13mUlyBncuraD0UyA A3KQ== X-Gm-Message-State: AOAM531/n3jpdjrS+Zu+7HB9O3kzPl48lVEgDb2joz41jr8nvn6dgQgm jN4LFq5yFbPCTLOBME438wBwu63ScYwtwA== X-Google-Smtp-Source: ABdhPJztB/QX6nwJKFN+J6RQb+WN+lfvuF7XxFQL8Ijbu/8AR61GfVhaWtoMDjj6qqE/uyEiZ8CC2g== X-Received: by 2002:a05:600c:2282:: with SMTP id 2mr653714wmf.154.1604682716930; Fri, 06 Nov 2020 09:11:56 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH for-5.2 1/4] hw/net/can/ctucan: Don't allow guest to write off end of tx_buffer Date: Fri, 6 Nov 2020 17:11:50 +0000 Message-Id: <20201106171153.32673-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201106171153.32673-1-peter.maydell@linaro.org> References: <20201106171153.32673-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::342; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x342.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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 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 , Vikram Garhwal , Pavel Pisa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" The ctucan device has 4 CAN bus cores, each of which has a set of 20 32-bit registers for writing the transmitted data. The registers are however not contiguous; each core's buffers is 0x100 bytes after the last. We got the checks on the address wrong in the ctucan_mem_write() function: * the first "is addr in range at all" check allowed addr =3D=3D CTUCAN_CORE_MEM_SIZE, which is actually the first byte off the end of the range * the decode of addresses into core-number plus offset in the tx buffer for that core failed to check that the offset was in range, so the guest could write off the end of the tx_buffer[] array * the decode had an explicit check for whether the core-number was out of range, which is actually impossible given the CTUCAN_CORE_MEM_SIZE check and the number of cores. Fix the top level check, check the offset, and turn the check on the core-number into an assertion. Fixes: Coverity CID 1432874 Signed-off-by: Peter Maydell Acked-by: Pavel Pisa --- hw/net/can/ctucan_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/net/can/ctucan_core.c b/hw/net/can/ctucan_core.c index d20835cd7e9..ea09bf71a0c 100644 --- a/hw/net/can/ctucan_core.c +++ b/hw/net/can/ctucan_core.c @@ -303,7 +303,7 @@ void ctucan_mem_write(CtuCanCoreState *s, hwaddr addr, = uint64_t val, DPRINTF("write 0x%02llx addr 0x%02x\n", (unsigned long long)val, (unsigned int)addr); =20 - if (addr > CTUCAN_CORE_MEM_SIZE) { + if (addr >=3D CTUCAN_CORE_MEM_SIZE) { return; } =20 @@ -312,7 +312,8 @@ void ctucan_mem_write(CtuCanCoreState *s, hwaddr addr, = uint64_t val, addr -=3D CTU_CAN_FD_TXTB1_DATA_1; buff_num =3D addr / CTUCAN_CORE_TXBUFF_SPAN; addr %=3D CTUCAN_CORE_TXBUFF_SPAN; - if (buff_num < CTUCAN_CORE_TXBUF_NUM) { + assert(buff_num < CTUCAN_CORE_TXBUF_NUM); + if (addr < sizeof(s->tx_buffer[buff_num].data)) { uint32_t *bufp =3D (uint32_t *)(s->tx_buffer[buff_num].data + = addr); *bufp =3D cpu_to_le32(val); } --=20 2.20.1 From nobody Sat May 4 23:40:26 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=1604682886; cv=none; d=zohomail.com; s=zohoarc; b=NYuj5qxmulzR+8JCoKcWB2v+lkQbITdi4cbrRtY/Pw9yoX3lC87vqMvO7SmnnMzzQqpiH3FMMrSCZ7q1cievgzuaCsW9rdO7UD4sHOauvIQGkYVHHdesq5wdDvb7+PqVtUnCV8A0iHX8BRyi+j6LIBXFv5WQWCyz1LuFCHyEcac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604682886; h=Content-Transfer-Encoding:Cc: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=QhdTsNE656tCSH0NDovdU3as+214FeSLljyeY/SGz5M=; b=ETfbailk+RJj1K3DMMBlWl4GRMdKjpjziYp9rT3CuE1mJXrc6fXGvkjw2zyC7ohTU2FNksRbr+6YGqt3n9ePE49/GdeOhz+/A4zqN8SbKdiHiO9j+LE14FmIBM44wKRAb1u73iK9FUZK/2hnT37EicZ6vyPJ6uwDgjPYFLiGuh0= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604682886595429.25985262565223; Fri, 6 Nov 2020 09:14:46 -0800 (PST) Received: from localhost ([::1]:45946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kb5K1-0005FK-Cr for importer@patchew.org; Fri, 06 Nov 2020 12:14:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34730) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb5HR-0001Gs-9N for qemu-devel@nongnu.org; Fri, 06 Nov 2020 12:12:06 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:56185) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kb5HM-0003Mr-7Z for qemu-devel@nongnu.org; Fri, 06 Nov 2020 12:12:04 -0500 Received: by mail-wm1-x341.google.com with SMTP id c9so2157211wml.5 for ; Fri, 06 Nov 2020 09:11:59 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id l1sm3162649wrb.1.2020.11.06.09.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2020 09:11:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QhdTsNE656tCSH0NDovdU3as+214FeSLljyeY/SGz5M=; b=X5nO/VDOGnJSTvMSrC9dJNpaAAh5GvemOQF6NG2wwUF6rcGcXDaY33lp+Lsnta0HI9 ttoDZnr4m/W0O9U8CiPmMTSW3OtzrJXiNRZiMhvOthGWoz6g9SMrIXuXaamg6hhCCB+F OBwIIPaqefmxEGwJHXPTrO9gQIQuo1/9PzdQtQku+uEWOG9dd5vel3mXj/AuqDKBG7aY nkRS+e9Hq8VT7TK1l/xPU7CybaylTFoIZvYM9+mGbiAhydlTbHGGy+ixMbb85sovPh+d H2Yt1eTKRmcc1iu5pGdiXpnUjKlLQ1z9CEhtrjqtUYp6jjpvJBnV+Hl1bwjIV8wZO14B P33g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QhdTsNE656tCSH0NDovdU3as+214FeSLljyeY/SGz5M=; b=b94fZei8BtwB7vcg10LA6gAJNWIYqEjU4v5fKUvsbicgFEPD7CSrnwOUiyVBmiGK1U U/ScRN9+84rlCksrSJD2NlRgL1zJTGyaEO1hibb1+/5vS+5KcmOBxpLLnhckafR/X4tV bUTN4Q8ihSzDRCEzRq/75TLzHt1LUbWXQurpTKzsXW6pSOlBJ19rmkJvnG8OqbExqG50 zKcP8biDwLFpJGWIHV8Llv6BOtLNdw5+nG+op/qpHaxbwCjEyuiWj4lwja9hyzqjd7E7 FbYei9F2ZmAIWRomHkBxE5TakTLd506HCTGxYQ1yoxeyINa0IeqstJTw3fUy5k7oT9g7 E7Ng== X-Gm-Message-State: AOAM532/gjHPV7Xz8y4/69iMboggzZDjxTI9eNwKbeEAQDmNOWbPNSpX xHo6BnjdZNHpNs56XnWHqXIs3jA61BmUvg== X-Google-Smtp-Source: ABdhPJx6W0XmIxaopniDiBl5L3OD0tuUdW0BkeGt71ef2/tXefEfZ6kLSdIsKVacBRYfonC24ufROA== X-Received: by 2002:a05:600c:2048:: with SMTP id p8mr574200wmg.165.1604682718310; Fri, 06 Nov 2020 09:11:58 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH for-5.2 2/4] hw/net/can/ctucan: Avoid unused value in ctucan_send_ready_buffers() Date: Fri, 6 Nov 2020 17:11:51 +0000 Message-Id: <20201106171153.32673-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201106171153.32673-1-peter.maydell@linaro.org> References: <20201106171153.32673-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::341; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x341.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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 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 , Vikram Garhwal , Pavel Pisa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" Coverity points out that in ctucan_send_ready_buffers() we set buff_st_mask =3D 0xf << (i * 4) inside the loop, but then we never use it before overwriting it later. The only thing we use the mask for is as part of the code that is inserting the new buff_st field into tx_status. That is more comprehensibly written using deposit32(), so do that and drop the mask variable entirely. We also update the buff_st local variable at multiple points during this function, but nothing can ever see these intermediate values, so just drop those, write the final TXT_TOK as a fixed constant value, and collapse the only remaining set/use of buff_st down into an extract32(). Fixes: Coverity CID 1432869 Signed-off-by: Peter Maydell --- hw/net/can/ctucan_core.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/hw/net/can/ctucan_core.c b/hw/net/can/ctucan_core.c index ea09bf71a0c..f2ce978e5ec 100644 --- a/hw/net/can/ctucan_core.c +++ b/hw/net/can/ctucan_core.c @@ -240,8 +240,6 @@ static void ctucan_send_ready_buffers(CtuCanCoreState *= s) uint8_t *pf; int buff2tx_idx; uint32_t tx_prio_max; - unsigned int buff_st; - uint32_t buff_st_mask; =20 if (!s->mode_settings.s.ena) { return; @@ -256,10 +254,7 @@ static void ctucan_send_ready_buffers(CtuCanCoreState = *s) for (i =3D 0; i < CTUCAN_CORE_TXBUF_NUM; i++) { uint32_t prio; =20 - buff_st_mask =3D 0xf << (i * 4); - buff_st =3D (s->tx_status.u32 >> (i * 4)) & 0xf; - - if (buff_st !=3D TXT_RDY) { + if (extract32(s->tx_status.u32, i * 4, 4) !=3D TXT_RDY) { continue; } prio =3D (s->tx_priority.u32 >> (i * 4)) & 0x7; @@ -271,10 +266,7 @@ static void ctucan_send_ready_buffers(CtuCanCoreState = *s) if (buff2tx_idx =3D=3D -1) { break; } - buff_st_mask =3D 0xf << (buff2tx_idx * 4); - buff_st =3D (s->tx_status.u32 >> (buff2tx_idx * 4)) & 0xf; int_stat.u32 =3D 0; - buff_st =3D TXT_RDY; pf =3D s->tx_buffer[buff2tx_idx].data; ctucan_buff2frame(pf, &frame); s->status.s.idle =3D 0; @@ -283,12 +275,11 @@ static void ctucan_send_ready_buffers(CtuCanCoreState= *s) s->status.s.idle =3D 1; s->status.s.txs =3D 0; s->tx_fr_ctr.s.tx_fr_ctr_val++; - buff_st =3D TXT_TOK; int_stat.s.txi =3D 1; int_stat.s.txbhci =3D 1; s->int_stat.u32 |=3D int_stat.u32 & ~s->int_mask.u32; - s->tx_status.u32 =3D (s->tx_status.u32 & ~buff_st_mask) | - (buff_st << (buff2tx_idx * 4)); + s->tx_status.u32 =3D deposit32(s->tx_status.u32, + buff2tx_idx * 4, 4, TXT_TOK); } while (1); } =20 --=20 2.20.1 From nobody Sat May 4 23:40:26 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=1604682997; cv=none; d=zohomail.com; s=zohoarc; b=fwLYRcotKVGPUewM3Ew+j3PXVSdFzcpwWIXfOlPK3lOy/pQ1HFzUDu+BC+cm0UgBrrtjmIGYKF3wiAqdt8Y5h9VfdqH5Cq8jMQUBTfvoqHv9yCkPw1uCM7O1wFrL7zizg+HlqfMpNiofQIJeHL7kq8SjbCIWU6OrCZlGl0ivf58= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604682997; h=Content-Transfer-Encoding:Cc: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=Ycwc9PI+oFTz4llRPLtPfpoPPiAd/CZwBx3qyq0lMqg=; b=m0yWgx87rm/i8rRsG8B9aeJwxmfODG4uzyzXqqqSFiveQpkrnL7BgLR8cw/78orNfItbDmd2jMXj2tB7ZrM7pPEsQm/XCQ08K1auOlt1QE515ArPb6OBsFU3a1sGlO+z7J3qv3vbM5sQNG3pu9vTVlFWXss2S5wEW13wE14WSCU= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604682997356924.0500046184309; Fri, 6 Nov 2020 09:16:37 -0800 (PST) Received: from localhost ([::1]:52512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kb5Lo-00084G-A4 for importer@patchew.org; Fri, 06 Nov 2020 12:16:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb5HT-0001Hx-DF for qemu-devel@nongnu.org; Fri, 06 Nov 2020 12:12:10 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:56188) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kb5HR-0003NV-4z for qemu-devel@nongnu.org; Fri, 06 Nov 2020 12:12:07 -0500 Received: by mail-wm1-x343.google.com with SMTP id c9so2157468wml.5 for ; Fri, 06 Nov 2020 09:12:04 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id l1sm3162649wrb.1.2020.11.06.09.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2020 09:11:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ycwc9PI+oFTz4llRPLtPfpoPPiAd/CZwBx3qyq0lMqg=; b=hRAvDh/GWZopBlkU8gG+DllAmis69LSZDLJkjLgrQNgCGDD8nFlgz1po7h2zPk7tMT a6hyWqZ7OMJTDRNIM5kJHaEP0AEZgm3M7/HWlk4XYYiL52gkQ8kfK7zEwS02K4e3cfzm P1lKXcfK/kvN8FmELI22gWWc5cfDu1XMoi725Iqz7Aj09MWwYoVwjSwTeXmiBQ3cMoUj mN0RrFTKyL5XtR9kCIs3K3GSgRTyQYbNrtCfqCqav0e5SFI9kijG7cc3JAI7E02KaMFp ibTziG9Q627Vy5IFh0v6H/9ROjYtpEqofUmZoAxMtRD/PHP9pIBhH89BgdQyRpqK1JsZ ldbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ycwc9PI+oFTz4llRPLtPfpoPPiAd/CZwBx3qyq0lMqg=; b=c2ze53xPwm78BiCIUCxafLpoDLa+bDDJemOrLxkgEx4w3fm9MCw7Ydr6JnfrdUHaJX wkf5SvP6G51Y1oZU3KRanVPHV6eF9xmfTCyjOyAJclzuFBc4P5xBTViKxG1kdEvtAebg z/qluomhfnvYmTK/LwiHfJZTAm94SQILopRboeeC8MoEnxM8NNnSsgsL2t1nbURBzuC5 myze+BJX3RoXkVw6wXj6ZluXj8rs5j62RQwgrDOUhr/ollsCpDeIKXzGg5LvMeiSuphU bHi9ZKXa1afmwr/LDpUjoc3g+Cw40tB/EbWYDr1KEh6StzjVxIcjvs4vUDNSKmAVYosv mRPQ== X-Gm-Message-State: AOAM530A+8S4hsP8QXAOg45I/lJjAKO8/VO/6+7BYzo+EDfK1X1pngRo fck4s/PT+ShLdlHygjD1CDbkrNBuByMYtA== X-Google-Smtp-Source: ABdhPJw7lcV4n5Abiz/tgeyJiu4G3mp3rgJlKQLD3s4Fd/MwpTRv1M6uhgo96sZa96c97MMj2Hqjtg== X-Received: by 2002:a1c:4ca:: with SMTP id 193mr588932wme.137.1604682720400; Fri, 06 Nov 2020 09:12:00 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH for-5.2 3/4] hw/net/can/ctucan_core: Handle big-endian hosts Date: Fri, 6 Nov 2020 17:11:52 +0000 Message-Id: <20201106171153.32673-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201106171153.32673-1-peter.maydell@linaro.org> References: <20201106171153.32673-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::343; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x343.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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 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 , Vikram Garhwal , Pavel Pisa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" The ctucan driver defines types for its registers which are a union of a uint32_t with a struct with bitfields for the individual fields within that register. This is a bad idea, because bitfields aren't portable. The ctu_can_fd_regs.h header works around the most glaring of the portability issues by defining the fields in two different orders depending on the setting of the __LITTLE_ENDIAN_BITFIELD define. However, in ctucan_core.h this is unconditionally set to 1, which is wrong for big-endian hosts. Set it only if HOST_WORDS_BIGENDIAN is not set. There is no need for a "have we defined it already" guard, because the only place that should set it is ctucan_core.h, which has the usual double-inclusion guard. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- Ideally all that bitfield-using code would be rewritten to use extract32 and deposit32 instead, IMHO. --- hw/net/can/ctucan_core.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/net/can/ctucan_core.h b/hw/net/can/ctucan_core.h index f21cb1c5ec3..bbc09ae0678 100644 --- a/hw/net/can/ctucan_core.h +++ b/hw/net/can/ctucan_core.h @@ -31,8 +31,7 @@ #include "exec/hwaddr.h" #include "net/can_emu.h" =20 - -#ifndef __LITTLE_ENDIAN_BITFIELD +#ifndef HOST_WORDS_BIGENDIAN #define __LITTLE_ENDIAN_BITFIELD 1 #endif =20 --=20 2.20.1 From nobody Sat May 4 23:40:26 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=1604682836; cv=none; d=zohomail.com; s=zohoarc; b=SqW4kiZx4jVNqWmckAfSSDzHuxM8Y2bzrRFPfCyRqXfBpz+heMbRbWhsbFkNVvvpeUz3AocJxSZXo3RavLf/eU8k1GUew/oA7Crm252Um76R0ArmncWDfLXkYmPnU6GHXTR9bZa1GHkx36EGL3VOKhc1BhphJ0hcq+Okzn8Tr4Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604682836; h=Content-Transfer-Encoding:Cc: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=nE1i2hAAqaIuOFEo+8UFV1Ok6/fO1ASvmRXI23HSnQQ=; b=S8CopOFZS0yuM1tMnOh+1tXgCBMdqLRFY0+APy2H3oKPRm5wFPxc4/0sWrDRNXp0uFB3dEVV28iXRpf19FPq4Rxxy5utVQX9DQSftFA5JGNvVQzIwW6Kf8KkKa5Z8YyQrivV5dEXlZAlAj0c1dFt8eo2DWFUnobsHaebZd9YuLg= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604682836353781.9999864580822; Fri, 6 Nov 2020 09:13:56 -0800 (PST) Received: from localhost ([::1]:40692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kb5JC-000358-8M for importer@patchew.org; Fri, 06 Nov 2020 12:13:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb5HV-0001I6-Fe for qemu-devel@nongnu.org; Fri, 06 Nov 2020 12:12:10 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:40736) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kb5HP-0003NF-2a for qemu-devel@nongnu.org; Fri, 06 Nov 2020 12:12:09 -0500 Received: by mail-wm1-x341.google.com with SMTP id k18so1998151wmj.5 for ; Fri, 06 Nov 2020 09:12:02 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id l1sm3162649wrb.1.2020.11.06.09.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2020 09:12:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nE1i2hAAqaIuOFEo+8UFV1Ok6/fO1ASvmRXI23HSnQQ=; b=qgo/+5ERyCclTWErEzcmtlr813OxzasDLZPv3kGPFB+AWSaQI//UjJxi5Q7MMI05dp HJAcF4xqKYnOmIW5WiuFpEAU6xFrKiwGglz2u2NhxnyxqwdNYKSbaPDyfo5BGBY5iF/J LVsPAni/KdliaS8UL36MOl0GpiMTydgz34e/UUjzhDs0gaYGYMrdLzMYUoxFAp6For31 zbzjnlD7wjBH9JWOZ4794W34ZFs66XRdAAI76fUfhMKdIGFGmxeSHa9GvkZjJPdn/ZmO Dp5qX84GQcCMM54qMk8tkOZe3i7dpPnZPmL7lA9YVsOgwc5fZxqYNSMNMOWrJuyPQNzv dj4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nE1i2hAAqaIuOFEo+8UFV1Ok6/fO1ASvmRXI23HSnQQ=; b=NhwX4bfbqWm/nNRLU+Eswx5a+TvVaQco9RNyHibRvCGQKZWO9UL1RD2tpGwHRxkEkE eEv3y4SVWdAWbxyBjSdCoYiNdRJ1GApArv2Tx65HePq6/lWGGzU0uR90T9SIjr4Xi3w9 ZVxgZra+NMKsaKDkmP41DvSh9oErmeKB619/cENcS8e4dzHHTvQNS1cM+mhftF22ZkM9 oPYZhEG7odpQAzEtrvbwq/WZH7JvKjmAJ1XjmnN9ivyYkSuI7ghijHGmI0gGtQ91ZKZA u/XAFvO1dC8tVmx+9WUgZAEH+w4d0dvudYdUAanGlHFPTRctw2av59t9qsw1TRWtzgn7 ODgg== X-Gm-Message-State: AOAM531/vXqiKZMQoFxC1HXZiFmiPbkM2n7I3/YWNNR2xtmEs8m/9Hg5 +miSCtTiLyAebb/meoB/FNZk8seo4J43AA== X-Google-Smtp-Source: ABdhPJwE7UbCW3ZL5xhezAlpe5z3+Kb5RRqpkxzitOCO1y9e4AdNpt71q2wKpSDOCsbMItbxEHAexA== X-Received: by 2002:a1c:b487:: with SMTP id d129mr672541wmf.38.1604682721478; Fri, 06 Nov 2020 09:12:01 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH for-5.2 4/4] hw/net/ctucan_core: Use stl_le_p to write to tx_buffers Date: Fri, 6 Nov 2020 17:11:53 +0000 Message-Id: <20201106171153.32673-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201106171153.32673-1-peter.maydell@linaro.org> References: <20201106171153.32673-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::341; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x341.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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 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 , Vikram Garhwal , Pavel Pisa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" Instead of casting an address within a uint8_t array to a uint32_t*, use stl_le_p(). This handles possibly misaligned addresses which would otherwise crash on some hosts. Signed-off-by: Peter Maydell Acked-by: Pavel Pisa Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/net/can/ctucan_core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/net/can/ctucan_core.c b/hw/net/can/ctucan_core.c index f2ce978e5ec..e66526efa83 100644 --- a/hw/net/can/ctucan_core.c +++ b/hw/net/can/ctucan_core.c @@ -305,8 +305,7 @@ void ctucan_mem_write(CtuCanCoreState *s, hwaddr addr, = uint64_t val, addr %=3D CTUCAN_CORE_TXBUFF_SPAN; assert(buff_num < CTUCAN_CORE_TXBUF_NUM); if (addr < sizeof(s->tx_buffer[buff_num].data)) { - uint32_t *bufp =3D (uint32_t *)(s->tx_buffer[buff_num].data + = addr); - *bufp =3D cpu_to_le32(val); + stl_le_p(s->tx_buffer[buff_num].data + addr, val); } } else { switch (addr & ~3) { --=20 2.20.1