Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp384859rwr; Thu, 4 May 2023 21:31:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6RgvbNWXs3yVcB8bOmeTfmZajfbek4PNvMRIlbnxnBX6OHyQQ0KcHMHuNnuJKXwx7RM6wP X-Received: by 2002:a17:902:c40b:b0:1aa:fd48:f5e2 with SMTP id k11-20020a170902c40b00b001aafd48f5e2mr116745plk.32.1683261109481; Thu, 04 May 2023 21:31:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683261109; cv=none; d=google.com; s=arc-20160816; b=ir7ggD6DHgNqm4dHHR1u9IsYzgDZeXxwXewje5C3EPjAUrIJmesGkKO1tsKRogVUMP LHVGB71JJ1cICbLsfWyEz5KltqLL6SA8gZG0KsPADOw5KhSRusZ+CmYbV8dW5UDy2U2O ACpg2g2xHPhGSFyivJFvNrSoYv0qZpDZp6kjkPl9wSuZ8rcrp/hEA87NxkLqKSnsgLMV ldcHnMHbPVtoNZt7zPLDpk3F8ah7mppLaQw+GIKTEWT5lOvFzfxE5EnW/T5E2CRfK873 4pRMd2E2E5ebskOlfQkhmBvtO5cOHu4btURq2pJsKj97g/2iFeobw8876mbwCAFFWB0J XtTA== 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:date:subject:cc:to:from:dkim-signature; bh=mVhP5af+O4pwjB4DNxiBtegJzD+t5vqxTNie3cd58II=; b=nTiNRDrnOH9Yc7KfslYsES2QyNOmiTuDHDV6Q+hOqC7brdDDgDuNkGtXpodZP3k22Z AuLP/XE17kvPxQrowf30iYCUeJL9VZWoPyiI8MFWVN8r2RALi8+opA7JW7fHN/tKPE/7 IXRfrFMLRX1IwpefhMkHdmgdW0cmjVtyOb4afrtNTQ0pY2tUy6xsd2p29z1iSLnEjrWz R+6R5/G99aKwyZ7yAmUsqmTEUfic6loQFUR1l8w6jO4vHOWktIGxeZBfvLEM47tmYjof HPYmuDsPS8RkPTxagU8GxjEHYRUAYyZxQfvNHJTeB0FosJ7VvNxL4VH9qd7Dy4gml3XX 24YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b="YGAKJi/h"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jf21-20020a170903269500b001aafaf1a917si689590plb.472.2023.05.04.21.31.33; Thu, 04 May 2023 21:31:49 -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=@ellerman.id.au header.s=201909 header.b="YGAKJi/h"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230169AbjEEDwC (ORCPT + 99 others); Thu, 4 May 2023 23:52:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229502AbjEEDwB (ORCPT ); Thu, 4 May 2023 23:52:01 -0400 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A371A11562 for ; Thu, 4 May 2023 20:51:58 -0700 (PDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4QCGvr1fKVz4x3g; Fri, 5 May 2023 13:51:52 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1683258712; bh=mVhP5af+O4pwjB4DNxiBtegJzD+t5vqxTNie3cd58II=; h=From:To:Cc:Subject:Date:From; b=YGAKJi/haN+xysLJd5BAil8L/L/+hwaBEmRB9E8upgP9LF0JoWDnkPvsu8h2VRrPE XnBegrFs6ewtA32QyJVeomyJvhhp9Ob8K3vFyil5OLtRNydWprDwoglTClkI/soP/w Bmppa8JvSFoqn05S04yL487C7wqFfFXN/NgLd1OKZQErGhk8IeUIoKHit5ZzcB0EB3 NrRMnLlI23zd77LEisLdrRgnePMZd9j9q72bteCPqXESFDlkNk0ertVWfis6wgTk1r S0Hk8dHXLfc8LPhSyJOaJ2uHhr92Y/rSETFn+dr36EgrSPn2Dgi3nlS0utee6kHm74 Nrxjn2rmFcaUg== From: Michael Ellerman To: glider@google.com, elver@google.com, , zhangpeng.00@bytedance.com Cc: , , Subject: [PATCH] mm: kfence: Fix false positives on big endian Date: Fri, 5 May 2023 13:51:27 +1000 Message-Id: <20230505035127.195387-1-mpe@ellerman.id.au> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 Since commit 1ba3cbf3ec3b ("mm: kfence: improve the performance of __kfence_alloc() and __kfence_free()"), kfence reports failures in random places at boot on big endian machines. The problem is that the new KFENCE_CANARY_PATTERN_U64 encodes the address of each byte in its value, so it needs to be byte swapped on big endian machines. The compiler is smart enough to do the le64_to_cpu() at compile time, so there is no runtime overhead. Fixes: 1ba3cbf3ec3b ("mm: kfence: improve the performance of __kfence_alloc() and __kfence_free()") Signed-off-by: Michael Ellerman --- mm/kfence/kfence.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/kfence/kfence.h b/mm/kfence/kfence.h index 2aafc46a4aaf..392fb273e7bd 100644 --- a/mm/kfence/kfence.h +++ b/mm/kfence/kfence.h @@ -29,7 +29,7 @@ * canary of every 8 bytes is the same. 64-bit memory can be filled and checked * at a time instead of byte by byte to improve performance. */ -#define KFENCE_CANARY_PATTERN_U64 ((u64)0xaaaaaaaaaaaaaaaa ^ (u64)(0x0706050403020100)) +#define KFENCE_CANARY_PATTERN_U64 ((u64)0xaaaaaaaaaaaaaaaa ^ (u64)(le64_to_cpu(0x0706050403020100))) /* Maximum stack depth for reports. */ #define KFENCE_STACK_DEPTH 64 -- 2.40.1