Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp373782rdb; Tue, 31 Oct 2023 09:46:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEmXPGzIqSPtA1bwPmDHqdEqP8NL+oi3WwhRgi28/oIasRTULVcrvGAW1jBPLf6RfuRW0T+ X-Received: by 2002:a17:902:ab81:b0:1ca:7f91:aa5d with SMTP id f1-20020a170902ab8100b001ca7f91aa5dmr12129088plr.16.1698770780429; Tue, 31 Oct 2023 09:46:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698770780; cv=none; d=google.com; s=arc-20160816; b=labXflcxXft92pTpvmvA1J9f7DbXfxZRtziEwGonvBpaEKbsUoe0jP5UrixQbDfFvh ZzGAAaWYEHVCLVCy1jwrsSSqjMnPpOnhq117kAAqOM2qfnpMyx7zmD9PP/0Ijbq5vYzJ yPZl8Q3WezK+F60G1kBUfKhJMjET8eEDSGVwB94/KTEtNzoIPHwE2NXhIo3iKesUuAxj fTNmnZl7IGaB+yXRKxGCtMNt2/G3TLHKyBSPOO6LI2E4d/+hEOcoZ9bnfHfGXrcpwzBG xL004ugFSrkQt8uqCELWNQgabew0q+4IQWie1+PQsNbxWus6hvhjBHmZVDSofjbYuuhK wChg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from; bh=ja0q3lqllAChw4GshvBvuNwL8c6PSBMo+zldYxCb/NI=; fh=zaYDrZ6UkOh2l3a/WDvJZTUDSuu85VM5L1M7PopzYmU=; b=rupOsEOryr2LUeT51E14rw1xdS62w4dt6pb1Cd2uqGoPKxE8F8/FRrTHOVnAW1rOMC KH4n975mwINVix9WfpvHXPVL2q76kHZRFXvkM9KG5vUJpMQvoEcuLtQlwSZey8QGXrkh 6mK8SeeSn2YGPaZrXOzpwQ6hDIV3EODq+RPMxkcXKUkQV9q3Xf7EuKy71Cu/S26IrshO QPVeiX8AooELJeFKefr9ucrPY/wu2S5PRxgR27adD/V/ZjRqbnxVxtKDd2uQsFCbburW q/WI478GiNMRKf2jGMAB+ITvNHZtiHCT81YW7mnliM/apYZZaud1Z5EMjb9Sph9fd4FL g2NA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id q7-20020a170902dac700b001b8921fbd87si1259102plx.490.2023.10.31.09.46.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 09:46:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id B4224802D3F6; Tue, 31 Oct 2023 09:46:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236496AbjJaQpr (ORCPT + 99 others); Tue, 31 Oct 2023 12:45:47 -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 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 31 Oct 2023 09:46:16 -0700 (PDT) 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."