Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1416970pxb; Wed, 6 Apr 2022 18:19:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxh4Zda8gxfXqnzI1p83OxvM0udhAXk8KrpucuWsgZHdVyBO/YpTcPEcyqm8FYoarnTidUH X-Received: by 2002:a63:6b83:0:b0:380:102:8779 with SMTP id g125-20020a636b83000000b0038001028779mr9541086pgc.42.1649294391088; Wed, 06 Apr 2022 18:19:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649294391; cv=none; d=google.com; s=arc-20160816; b=TCiktq/Zbh5vhKf9zqHQd4glrLucnOwX/x41LQlX5TkEQZq26s40iJHAoc/RRV8WR/ qoyGuBHERr1SecsU1HM3gOTCX2+R9+v7gbW0kyBvEuBn9DSjR6w5aEyGOPkUfpTl+Zr7 B566hZgiN3IYsD9QY/zmN9ey0HsAwiiKpyZ/9CXENp32WCLHQ29fSNcIkX6sOw6pbS8e 6gnio9s6DJeOZorDBjshQCz7E3v3D4Nbae0XncJSYEDZmnWTWHhDQBcq03JegCrzxEaU 0SCNIAewykMEOfS9wbsjcVC4DKuSNSFWR/+kt26DsTcMxIwZMTCmNFU7wk5wOpMbli2L u2PQ== 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=msv3nOGjLIGTrH1A0ydlYoFmzBEnAkJ0hjTDqARjFZY=; b=nuUGoGcyp9U3DBhchLb1Nn0ITMoIJPNRIQe0+PbhGK5Y+GKjdGWt000emB0bXZ3pXX 8pcC3NW7lL3JaCz9Cokfuk0+/e5UxlBrsFvZOS41hXw/fxn330ULWP30IX0uy/5Y1eLa jkbvleWGBdnArs7ohmiLN580PGJV1WTvcgKa//OOlKENpFDlTTsp43u8TaRs1lfi851W utHPOZsPQn1yMyLROZ1p8bPZGh68cWsHCT6CQupeyualm82jOEZ50DcFAp+FcEzGod5X N+BzhijvC6GIgymzVd6RpmuKGEhVk+muTQO07h9SBkd+2rBGnTXoWZ/b0yDO2/aI9sHt uIog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail2 header.b=VO5Vhnal; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 b14-20020a170902e94e00b00153b2d16577si17075799pll.383.2022.04.06.18.19.36; Wed, 06 Apr 2022 18:19:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=VO5Vhnal; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S238094AbiDFXsK (ORCPT + 99 others); Wed, 6 Apr 2022 19:48:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231515AbiDFXsJ (ORCPT ); Wed, 6 Apr 2022 19:48:09 -0400 Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F49914DA2A for ; Wed, 6 Apr 2022 16:46:09 -0700 (PDT) Date: Wed, 06 Apr 2022 23:46:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1649288767; bh=msv3nOGjLIGTrH1A0ydlYoFmzBEnAkJ0hjTDqARjFZY=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID; b=VO5Vhnal3btdccM03/zjx2HXeh90LnPQtZxVlbYpXI/CIiB1agDAywbdGZh5hywcq ABZlR70nWy5Ow9CkEO/b7fi6iEkoZCzmSITCMiB7MjVivjekK659yX21GM2dNVOIRA mh59hg3iMWpa2Z+NfVHe3TPbA6B69hxMVJR5JzD8ZsZ1nW2u9MIUMZBgDT1MsW60lq A+aMAv9jOnBanleUgziFJ7IbNKttao6DHkEcfLY675fWBdkapXa3bm8kOBxcieAygi 9GJ9QNw4ZrZLFW2iSKAgXg0dG1qMEwHClLk4n7XC6K8HFN/eb1kQPE6jYtGllJ3H9d 6DkQR7EZW/BwQ== To: Arnd Bergmann From: Alexander Lobakin Cc: Bart Van Assche , Jens Axboe , Keith Busch , Chaitanya Kulkarni , "Martin K. Petersen" , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Lobakin Reply-To: Alexander Lobakin Subject: [PATCH] asm-generic: fix __get_unaligned_be48() on 32 bit platforms Message-ID: <20220406233909.529613-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,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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-kernel@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 --- 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.1