Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp42329lfv; Tue, 12 Apr 2022 16:29:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw668rEg+6mhOGpkDROj/cD5aNz3bnJ59A8lkYDdsO/DZVvWG4RVtlIWKgMTD3tSVC2Kj2i X-Received: by 2002:a17:90b:4b42:b0:1cb:a213:65d9 with SMTP id mi2-20020a17090b4b4200b001cba21365d9mr7682171pjb.138.1649806198278; Tue, 12 Apr 2022 16:29:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649806198; cv=none; d=google.com; s=arc-20160816; b=n0wrH6xwgpfw5ovC8LSE6EWZwUD33rlhcvU3NeT8MP3Uahsd2CGYtHLVOwjrIP0L0S /UliNVziH9kjY2jowjj1IxC4fqaO1r7R9GsltX+LWmgypGi6kN+fdEP+dwA9Kr+9h5Dl QRsRqJCCRBHj6edACTLNS4Xcr6/zRcMk43D39qkNcioj8WOlj7eUCFlbY1wfgmX7enaw 4WPOmIeb4cY8JtJHhyMx8DbUJKvrRGu1VssT4stD9VtR4NTXf0FKV4x/yA5EEBBMK5SS yYVEySCqIjZuXpEvkZnJsmODh/FniQ/UiKWg/t5oYwPds3gmJuZZfpFKVIqtd8xj2Bc4 kCtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:subject:reply-to:cc:from:to:dkim-signature:date; bh=JJtIRzBfNpDrJ/fFtvW6vi1j9+8vDctIDP1NHWiTvOk=; b=rLSYS9jYp5Xp8cjvcm8aAyMk39v5eWiWmy6Fxj7LLHL5A+FhVh/ZElwPEtpl86/MYO iaF+Kh4OAA40svGQ03n6HBO3PZTmDsYpBz8XEbml81tHbbqQ6rnhErmGpSh4ykNYHsfg sbG2r6ICS/gUFw+gbwVOO2mg7uPCBVjQrwLDAgyGtHz3AHlYJekWD5zAb5J6ihb7tt1V YKSNfrhCTam4be3ArFiJcumSeQ9awxBc8TkRT5S57SAyafKybNbYE/X23C00gmxek7ja b5C9prVnW3B+4cqS4ps5BIpTLsATmCR/BwlmPjiVFgWnMFq8t0p8QOmzr9pjr0g+tgzp TFqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail2 header.b=M2J2L0iK; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c12-20020a056a000acc00b004fa3a8e0035si14045009pfl.236.2022.04.12.16.29.41; Tue, 12 Apr 2022 16:29:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail2 header.b=M2J2L0iK; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230338AbiDLXba (ORCPT + 99 others); Tue, 12 Apr 2022 19:31:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230400AbiDLXbX (ORCPT ); Tue, 12 Apr 2022 19:31:23 -0400 X-Greylist: delayed 600 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 12 Apr 2022 15:16:17 PDT Received: from mail-4321.protonmail.ch (mail-4321.protonmail.ch [185.70.43.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07C4F219 for ; Tue, 12 Apr 2022 15:16:17 -0700 (PDT) Date: Tue, 12 Apr 2022 21:59:16 +0000 Authentication-Results: mail-4321.protonmail.ch; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b="M2J2L0iK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1649800761; bh=JJtIRzBfNpDrJ/fFtvW6vi1j9+8vDctIDP1NHWiTvOk=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID; b=M2J2L0iK2Kc/JQTIjkwhDUkVqWiZJr3O/27pjBoOkV0WQ7k3QLKoWiEY4P8AO2cMT OApMkeZx7jZ147jSo5zdtUJ4MYUQI3LZGgFLt5lQy2IbjAyfDr3JdfIat6WFFXrrpK w6L6qXuzVppbmyai1QnXQf3zVPlwQmukLWSYtXStunKKc6w2+Je+8XmI1/jRXcuKZM ugzbjMCdqaBj+SICra5VB2NALMPCUFd/dOxLuvqDVK4p7PmM55sl91uTxRYp3lYwIP Wplktu5ck2NSYZL+AmRdzhMhpS9KKb3ZVDMPNH0oQPlAk2NVHCT0SYTlSBPdbNDOXO jnYDIIyAsO8UQ== To: linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-crypto@vger.kernel.org From: Alexander Lobakin Cc: Arnd Bergmann , Bart Van Assche , Jens Axboe , Keith Busch , Chaitanya Kulkarni , "Martin K. Petersen" , Christoph Hellwig , Andrew Morton , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Lobakin Reply-To: Alexander Lobakin Subject: [PATCH RESEND] asm-generic: fix __get_unaligned_be48() on 32 bit platforms Message-ID: <20220412215220.75677-1-alobakin@pm.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org While testing the new macros for working with 48 bit containers, I faced a weird problem: 32 + 16: 0x2ef6e8da 0x79e60000 48: 0xffffe8da + 0x79e60000 All the bits starting from the 32nd were getting 1d in 9/10 cases. The debug showed: p[0]: 0x00002e0000000000 p[1]: 0x00002ef600000000 p[2]: 0xffffffffe8000000 p[3]: 0xffffffffe8da0000 p[4]: 0xffffffffe8da7900 p[5]: 0xffffffffe8da79e6 that the value becomes a garbage after the third OR, i.e. on `p[2] << 24`. When the 31st bit is 1 and there's no explicit cast to an unsigned, it's being considered as a signed int and getting sign-extended on OR, so `e8000000` becomes `ffffffffe8000000` and messes up the result. Cast the @p[2] to u64 as well to avoid this. Now: 32 + 16: 0x7ef6a490 0xddc10000 48: 0x7ef6a490 + 0xddc10000 p[0]: 0x00007e0000000000 p[1]: 0x00007ef600000000 p[2]: 0x00007ef6a4000000 p[3]: 0x00007ef6a4900000 p[4]: 0x00007ef6a490dd00 p[5]: 0x00007ef6a490ddc1 Fixes: c2ea5fcf53d5 ("asm-generic: introduce be48 unaligned accessors") Signed-off-by: Alexander Lobakin --- Resend: target linux-block, expand Ccs a bit include/asm-generic/unaligned.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/asm-generic/unaligned.h b/include/asm-generic/unaligne= d.h index 8fc637379899..df30f11b4a46 100644 --- a/include/asm-generic/unaligned.h +++ b/include/asm-generic/unaligned.h @@ -143,7 +143,7 @@ static inline void put_unaligned_be48(const u64 val, vo= id *p) static inline u64 __get_unaligned_be48(const u8 *p) { -=09return (u64)p[0] << 40 | (u64)p[1] << 32 | p[2] << 24 | +=09return (u64)p[0] << 40 | (u64)p[1] << 32 | (u64)p[2] << 24 | =09=09p[3] << 16 | p[4] << 8 | p[5]; } -- 2.35.2