From nobody Thu May 16 11:19:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 ARC-Seal: i=1; a=rsa-sha256; t=1605045558; cv=none; d=zohomail.com; s=zohoarc; b=e3BBvIQ18SF8+HmWGtZs1xvIRfu4gZ4eI3+Wsptv9dzxjs4nRjIFOTWPn//IcmFRpZ4o/arNXFvhBjxXe3U2XCKZJpV6vsvsIhIImR/OBZ9Pxm2UIeEdslk2eNbw+YFrXydjR8aQ8LXaGvdfw6j5gPC63dMFU+pz3wFICSLygB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605045558; 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=aED4sVBi+/AhSfzRw8X3kV2Pb3OlPTZ8fzgg3AYmxJ0=; b=kYBENmMSOJtMKXbz04BswhqBec70bPJpQp397TVrAWnSbIkoBahEaU1OQAjAJ7FYwof3WfwQvS1hx3gn+NfGBtD4QwjESNK6mgVAlmzr5clk/WSPW4+n5zPVn2V+kMlHnjMqNcAy5Ue5LHrgeqzCwCn5j1RiTu1CaMiHQ4U8/cE= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1605045558492768.0698758917312; Tue, 10 Nov 2020 13:59:18 -0800 (PST) Received: from localhost ([::1]:60558 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcbfZ-0000ri-BI for importer@patchew.org; Tue, 10 Nov 2020 16:59:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcbb6-0007bj-Pe for qemu-devel@nongnu.org; Tue, 10 Nov 2020 16:54:40 -0500 Received: from relay.felk.cvut.cz ([2001:718:2:1611:0:1:0:70]:14116) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcbb5-0002cS-1L for qemu-devel@nongnu.org; Tue, 10 Nov 2020 16:54:40 -0500 Received: from cmp.felk.cvut.cz (haar.felk.cvut.cz [147.32.84.19]) by relay.felk.cvut.cz (8.15.2/8.15.2) with ESMTP id 0AALrZM2095294; Tue, 10 Nov 2020 22:53:35 +0100 (CET) (envelope-from pisa@cmp.felk.cvut.cz) Received: from haar.felk.cvut.cz (localhost [127.0.0.1]) by cmp.felk.cvut.cz (8.14.0/8.12.3/SuSE Linux 0.6) with ESMTP id 0AALrYqA028054; Tue, 10 Nov 2020 22:53:34 +0100 Received: (from pisa@localhost) by haar.felk.cvut.cz (8.14.0/8.13.7/Submit) id 0AALrYHZ028053; Tue, 10 Nov 2020 22:53:34 +0100 From: Pavel Pisa To: qemu-devel@nongnu.org, Peter Maydell Subject: [PATCH for-5.2 v3 1/4] hw/net/can/ctucan: Don't allow guest to write off end of tx_buffer Date: Tue, 10 Nov 2020 22:52:47 +0100 Message-Id: <94d4236dee6973978398e6e2a3a321b65a7d35be.1605044619.git.pisa@cmp.felk.cvut.cz> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FELK-MailScanner-Information: X-MailScanner-ID: 0AALrZM2095294 X-FELK-MailScanner: Found to be clean X-FELK-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-0.099, required 6, BAYES_00 -0.50, KHOP_HELO_FCRDNS 0.40, SPF_HELO_NONE 0.00, SPF_NONE 0.00) X-FELK-MailScanner-From: pisa@cmp.felk.cvut.cz X-FELK-MailScanner-Watermark: 1605650019.03741@U0Ja59RiVa3UlzW+OwSn8Q 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: none client-ip=2001:718:2:1611:0:1:0:70; envelope-from=pisa@cmp.felk.cvut.cz; helo=relay.felk.cvut.cz X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/10 16:54:16 X-ACL-Warn: Detected OS = ??? X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_NONE=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: Pavel Pisa , Jason Wang , Vikram Garhwal , Ondrej Ille , =?UTF-8?q?Jan=20Charv=C3=A1t?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Peter Maydell 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 NB: currently the values of CTUCAN_CORE_MEM_SIZE, CTUCAN_CORE_TXBUF_NUM, etc, make "buff_num >=3D CTUCAN_CORE_TXBUF_NUM" impossible, but we retain this as a runtime check rather than an assertion to permit those values to be changed in future (in hardware they are configurable synthesis parameters). Fix the top level check, and check the offset is within the buffer. Fixes: Coverity CID 1432874 Signed-off-by: Peter Maydell Signed-off-by: Pavel Pisa Tested-by: Pavel Pisa --- hw/net/can/ctucan_core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/net/can/ctucan_core.c b/hw/net/can/ctucan_core.c index d20835cd7e..8486f429d7 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,9 @@ 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) { + addr &=3D ~3; + if ((buff_num < CTUCAN_CORE_TXBUF_NUM) && + (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 Thu May 16 11:19:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 ARC-Seal: i=1; a=rsa-sha256; t=1605045565; cv=none; d=zohomail.com; s=zohoarc; b=Z3eXe+inZULmvN082ORrNDQ3RGmTsTSOgcdfDzPtoshG/WRwcDm9xAHRObYidy7fMhLcTNWsktYdArmhPgUrpS0nS/4KlvqlEh/2GyLm+6ouGTqs4xGs8RSppFAyIvYsb2vLBTPyEARd3DxWmtKp+MYFA/rO+qgnJlfW+/1kGdI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605045565; 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=Idr2nK2RVq6MdGHXHJTt1bPBmEmi7zAbi4pKIQ/C3CE=; b=TE7cstXY7qPWXehfAQXKEKG74XFFNbxdCQO50rTprweH0pTkugtkeQ96Wo8AfIK3NK5pIniGUnmVAaEQD+lrER8hj2ULI6tDIFzg1y1p6mEl0yJvaSzslaZk5ZpMF9nxelVdku2eAbsWraorKOM5o44IGNE446p63C7rrqF9RX8= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1605045565416348.0296487296172; Tue, 10 Nov 2020 13:59:25 -0800 (PST) Received: from localhost ([::1]:60872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcbfg-00010S-6z for importer@patchew.org; Tue, 10 Nov 2020 16:59:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34534) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcbbG-0007im-9u for qemu-devel@nongnu.org; Tue, 10 Nov 2020 16:54:50 -0500 Received: from relay.felk.cvut.cz ([2001:718:2:1611:0:1:0:70]:14116) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcbbB-0002cS-7N for qemu-devel@nongnu.org; Tue, 10 Nov 2020 16:54:50 -0500 Received: from cmp.felk.cvut.cz (haar.felk.cvut.cz [147.32.84.19]) by relay.felk.cvut.cz (8.15.2/8.15.2) with ESMTP id 0AALrblo095295; Tue, 10 Nov 2020 22:53:37 +0100 (CET) (envelope-from pisa@cmp.felk.cvut.cz) Received: from haar.felk.cvut.cz (localhost [127.0.0.1]) by cmp.felk.cvut.cz (8.14.0/8.12.3/SuSE Linux 0.6) with ESMTP id 0AALrbxs028066; Tue, 10 Nov 2020 22:53:37 +0100 Received: (from pisa@localhost) by haar.felk.cvut.cz (8.14.0/8.13.7/Submit) id 0AALraeB028065; Tue, 10 Nov 2020 22:53:36 +0100 From: Pavel Pisa To: qemu-devel@nongnu.org, Peter Maydell Subject: [PATCH for-5.2 v3 2/4] hw/net/can/ctucan: Avoid unused value in ctucan_send_ready_buffers() Date: Tue, 10 Nov 2020 22:52:48 +0100 Message-Id: <96562ba01919479f7f311050e914419ed3c2f194.1605044619.git.pisa@cmp.felk.cvut.cz> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FELK-MailScanner-Information: X-MailScanner-ID: 0AALrblo095295 X-FELK-MailScanner: Found to be clean X-FELK-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-0.099, required 6, BAYES_00 -0.50, KHOP_HELO_FCRDNS 0.40, SPF_HELO_NONE 0.00, SPF_NONE 0.00) X-FELK-MailScanner-From: pisa@cmp.felk.cvut.cz X-FELK-MailScanner-Watermark: 1605650019.10731@7y1gp9Ofs2U+1lucnbn/Qg 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: none client-ip=2001:718:2:1611:0:1:0:70; envelope-from=pisa@cmp.felk.cvut.cz; helo=relay.felk.cvut.cz X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/10 16:54:16 X-ACL-Warn: Detected OS = ??? X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_NONE=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: Pavel Pisa , Jason Wang , Vikram Garhwal , Ondrej Ille , =?UTF-8?q?Jan=20Charv=C3=A1t?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Peter Maydell 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 Acked-by: Pavel Pisa Tested-by: Pavel Pisa --- 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 8486f429d7..f49c76261c 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 Thu May 16 11:19:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 ARC-Seal: i=1; a=rsa-sha256; t=1605046027; cv=none; d=zohomail.com; s=zohoarc; b=e9o8kiYA5wuKp0yjdiBCQ6nsHBNQ8DcRh9qVZvcMc4gUGzfbyZfTQECaWSshDdXN+2wakSxbPodj1q7bjVOGZzhXLAWrG60s9hy/af+Z/8hspu/MeVnl1iW/glyIuR9yQr/2lcfGUJTG7CzOqrc0Gy/sDqaORjxN03MAdDhxL0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605046027; h=Content-Type: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=t7CFjQ2WNsxy4YsJ/b8Uun9h9CHZO0BrwTSz66Z+Jt4=; b=SmovS9h2IBiHY9vPqDmkdRWX2Ua42ek9ZTBb9ViXGTE9wogguzkQ2j0aALwLT44e+cqsUiO+SBRJSuiW1DISiybPUolEKUBcp2DPFD0h0NUHNCFph40lCzhKxnIpmFjFHMbASgxaAeMyK2qs8pLd1LerPSFM/MpR6/d+kJ/rdAg= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1605046027073153.59885467574907; Tue, 10 Nov 2020 14:07:07 -0800 (PST) Received: from localhost ([::1]:40606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcbn8-0004gr-0D for importer@patchew.org; Tue, 10 Nov 2020 17:07:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcbbO-0007rs-5y for qemu-devel@nongnu.org; Tue, 10 Nov 2020 16:54:58 -0500 Received: from relay.felk.cvut.cz ([2001:718:2:1611:0:1:0:70]:13424) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcbbM-0002ce-Fl for qemu-devel@nongnu.org; Tue, 10 Nov 2020 16:54:57 -0500 Received: from cmp.felk.cvut.cz (haar.felk.cvut.cz [147.32.84.19]) by relay.felk.cvut.cz (8.15.2/8.15.2) with ESMTP id 0AALrejj095303; Tue, 10 Nov 2020 22:53:40 +0100 (CET) (envelope-from pisa@cmp.felk.cvut.cz) Received: from haar.felk.cvut.cz (localhost [127.0.0.1]) by cmp.felk.cvut.cz (8.14.0/8.12.3/SuSE Linux 0.6) with ESMTP id 0AALreW1028082; Tue, 10 Nov 2020 22:53:40 +0100 Received: (from pisa@localhost) by haar.felk.cvut.cz (8.14.0/8.13.7/Submit) id 0AALret1028081; Tue, 10 Nov 2020 22:53:40 +0100 From: Pavel Pisa To: qemu-devel@nongnu.org, Peter Maydell Subject: [PATCH for-5.2 v3 3/4] hw/net/can/ctucan_core: Handle big-endian hosts Date: Tue, 10 Nov 2020 22:52:49 +0100 Message-Id: <61096a9130b50e74e03914fcbfbb7bc759f5b6b5.1605044619.git.pisa@cmp.felk.cvut.cz> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-FELK-MailScanner-Information: X-MailScanner-ID: 0AALrejj095303 X-FELK-MailScanner: Found to be clean X-FELK-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-0.099, required 6, BAYES_00 -0.50, KHOP_HELO_FCRDNS 0.40, SPF_HELO_NONE 0.00, SPF_NONE 0.00) X-FELK-MailScanner-From: pisa@cmp.felk.cvut.cz X-FELK-MailScanner-Watermark: 1605650023.95102@awhc3FVjGoDauf5+3cGHtg 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: none client-ip=2001:718:2:1611:0:1:0:70; envelope-from=pisa@cmp.felk.cvut.cz; helo=relay.felk.cvut.cz X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/10 16:54:16 X-ACL-Warn: Detected OS = ??? X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_NONE=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: Vikram Garhwal , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Ondrej Ille , =?UTF-8?q?Jan=20Charv=C3=A1t?= , Pavel Pisa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell 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 Acked-by: Pavel Pisa Tested-by: Pavel Pisa --- 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 f21cb1c5ec..bbc09ae067 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 Thu May 16 11:19:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 ARC-Seal: i=1; a=rsa-sha256; t=1605046023; cv=none; d=zohomail.com; s=zohoarc; b=ah9M0oXbUYiEu/weC7ZRCs1+sI/ZHonwbk6Yo7Tb2Ahd3+rT784465MS8LYwga6uJCxT9NGACMJDY1o++D+NiLiDR7PjDrQrwuRSF64YgpJKH2u96pyL4ZqjhuC83GDPsbxFqa9RQi1VbpShR+kvTJlbTvy0vHmF8DyFPFlCTtQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605046023; h=Content-Type: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=RzupqbRAp9xZXyU0pb3Y8asV8zVRgn9GaQopBXem0ZY=; b=fVEJaQILwDkB9Z9QP4tDIFSC9GCEdi2GGF/LBIys61Sjb2uUsZrq3cP+vUfrtWJVPOPYKgD3n+dzT20cdpgh9Ln2fbTXLz650dgSMWLhD4WZzJmpR/E+D/OSmVulZkB4+fUZFn1c3JGuUadGzR7qBMaP74bua1W4/7GsOGK5+E0= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1605046023504966.7033371905993; Tue, 10 Nov 2020 14:07:03 -0800 (PST) Received: from localhost ([::1]:40394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcbn3-0004bg-N3 for importer@patchew.org; Tue, 10 Nov 2020 17:07:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcbbH-0007jS-0S for qemu-devel@nongnu.org; Tue, 10 Nov 2020 16:54:51 -0500 Received: from relay.felk.cvut.cz ([2001:718:2:1611:0:1:0:70]:13424) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcbbB-0002ce-8c for qemu-devel@nongnu.org; Tue, 10 Nov 2020 16:54:50 -0500 Received: from cmp.felk.cvut.cz (haar.felk.cvut.cz [147.32.84.19]) by relay.felk.cvut.cz (8.15.2/8.15.2) with ESMTP id 0AALrgwF095304; Tue, 10 Nov 2020 22:53:42 +0100 (CET) (envelope-from pisa@cmp.felk.cvut.cz) Received: from haar.felk.cvut.cz (localhost [127.0.0.1]) by cmp.felk.cvut.cz (8.14.0/8.12.3/SuSE Linux 0.6) with ESMTP id 0AALrgeh028093; Tue, 10 Nov 2020 22:53:42 +0100 Received: (from pisa@localhost) by haar.felk.cvut.cz (8.14.0/8.13.7/Submit) id 0AALrgb7028092; Tue, 10 Nov 2020 22:53:42 +0100 From: Pavel Pisa To: qemu-devel@nongnu.org, Peter Maydell Subject: [PATCH for-5.2 v3 4/4] hw/net/can/ctucan_core: Use stl_le_p to write to tx_buffers Date: Tue, 10 Nov 2020 22:52:50 +0100 Message-Id: <7951c8ad9a0ad6b5faf7ec7569f255fa45259590.1605044619.git.pisa@cmp.felk.cvut.cz> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-FELK-MailScanner-Information: X-MailScanner-ID: 0AALrgwF095304 X-FELK-MailScanner: Found to be clean X-FELK-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-0.099, required 6, BAYES_00 -0.50, KHOP_HELO_FCRDNS 0.40, SPF_HELO_NONE 0.00, SPF_NONE 0.00) X-FELK-MailScanner-From: pisa@cmp.felk.cvut.cz X-FELK-MailScanner-Watermark: 1605650023.99277@snFSPGKgF+gWI/ke73RDgg 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: none client-ip=2001:718:2:1611:0:1:0:70; envelope-from=pisa@cmp.felk.cvut.cz; helo=relay.felk.cvut.cz X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/10 16:54:16 X-ACL-Warn: Detected OS = ??? X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_NONE=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: Vikram Garhwal , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Ondrej Ille , =?UTF-8?q?Jan=20Charv=C3=A1t?= , Pavel Pisa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Pavel Pisa Tested-by: Pavel Pisa --- hw/net/can/ctucan_core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hw/net/can/ctucan_core.c b/hw/net/can/ctucan_core.c index f49c76261c..d171c372e0 100644 --- a/hw/net/can/ctucan_core.c +++ b/hw/net/can/ctucan_core.c @@ -303,11 +303,9 @@ 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; - addr &=3D ~3; if ((buff_num < CTUCAN_CORE_TXBUF_NUM) && - (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); + ((addr + size) <=3D sizeof(s->tx_buffer[buff_num].data))) { + stn_le_p(s->tx_buffer[buff_num].data + addr, size, val); } } else { switch (addr & ~3) { --=20 2.20.1