From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 952C0C4332F for ; Tue, 31 Oct 2023 16:45:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346221AbjJaQpt (ORCPT ); Tue, 31 Oct 2023 12:45:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346284AbjJaQpZ (ORCPT ); Tue, 31 Oct 2023 12:45:25 -0400 Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8730B273D for ; Tue, 31 Oct 2023 09:36:04 -0700 (PDT) Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4SKbNw3bKHz1r1sM; Tue, 31 Oct 2023 17:36:00 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.68]) by mail.m-online.net (Postfix) with ESMTP id 4SKbNv719Xz1qqlW; Tue, 31 Oct 2023 17:35:59 +0100 (CET) X-Virus-Scanned: amavis at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.68]) (amavis, port 10024) with ESMTP id gPAjuvIpFzIo; Tue, 31 Oct 2023 17:35:58 +0100 (CET) X-Auth-Info: 7WVihqLGSDRZy2DvJB4lOgCCHp8jng0ZYt5id1i0l8Oow3unYQFAovJz6kwHdGof Received: from igel.home (aftr-62-216-205-72.dynamic.mnet-online.de [62.216.205.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Tue, 31 Oct 2023 17:35:58 +0100 (CET) Received: by igel.home (Postfix, from userid 1000) id 943A12C12E3; Tue, 31 Oct 2023 17:35:57 +0100 (CET) From: Andreas Schwab To: Emil Renner Berthing Cc: Charlie Jenkins , linux-riscv@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Eric Biederman , Kees Cook , Paul Walmsley , Palmer Dabbelt , Albert Ou , Samuel Holland , Nelson Chu , Emil Renner Berthing Subject: Re: [PATCH v7 1/3] riscv: Avoid unaligned access when relocating modules In-Reply-To: (Emil Renner Berthing's message of "Tue, 31 Oct 2023 06:11:47 -0700") References: <20231031-module_relocations-v7-0-6f4719b64bf7@rivosinc.com> <20231031-module_relocations-v7-1-6f4719b64bf7@rivosinc.com> X-Yow: Could I have a drug overdose? Date: Tue, 31 Oct 2023 17:35:57 +0100 Message-ID: <878r7iiwb6.fsf@igel.home> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Okt 31 2023, Emil Renner Berthing wrote: >> +static int riscv_insn_rmw(void *location, u32 keep, u32 set) >> +{ >> + u16 *parcel = location; >> + u32 insn = (u32)le16_to_cpu(parcel[0]) | (u32)le16_to_cpu(parcel[1]) << 16; >> + >> + insn &= keep; >> + insn |= set; >> + >> + parcel[0] = cpu_to_le32(insn); > > Why cpu_to_le32(insn)? Unless I've misunderstood something downcasting unsigned > to unsigned values in C (eg. from u32 to u16) is defined to always discard the > most signifcant bits, so cpu_to_le16(insn) should be fine. cpu_to_le32(insn) can't be right here anyway, since it also swaps the two u16 halves and would be the same as cpu_to_le16(insn >> 16) on big endian. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."