From patchwork Fri May 5 03:51:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 13232114 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB9FBC77B75 for ; Fri, 5 May 2023 03:51:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C42A6B0075; Thu, 4 May 2023 23:51:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4727B6B0078; Thu, 4 May 2023 23:51:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 388D96B007B; Thu, 4 May 2023 23:51:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by kanga.kvack.org (Postfix) with ESMTP id EB58F6B0075 for ; Thu, 4 May 2023 23:51:53 -0400 (EDT) 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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.006381, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: Alexander Potapenko Reviewed-by: Marco Elver --- 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