From patchwork Fri Aug 26 15:08:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12956211 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 528DDECAAA3 for ; Fri, 26 Aug 2022 15:10:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0315940008; Fri, 26 Aug 2022 11:10:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D8AA8940007; Fri, 26 Aug 2022 11:10:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDD8B940008; Fri, 26 Aug 2022 11:10:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id AAD78940007 for ; Fri, 26 Aug 2022 11:10:01 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8EFD740CE7 for ; Fri, 26 Aug 2022 15:10:01 +0000 (UTC) X-FDA: 79842079002.07.B1D34B6 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) by imf21.hostedemail.com (Postfix) with ESMTP id 168FA1C001B for ; Fri, 26 Aug 2022 15:10:00 +0000 (UTC) Received: by mail-ej1-f74.google.com with SMTP id hb37-20020a170907162500b0073d7f7fbbbfso725843ejc.17 for ; Fri, 26 Aug 2022 08:10:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc; bh=G7zTeV7HivGGK7/AmFGwNvvgE+xYoTaOW1pCL0nph+s=; b=rllUU8td54J92uwD4gqMdf7quRrn9vs+RF/VGfmhTNifoonDDOGDzA+ehk2F0Nktis bzsb1L86DwkC+0Lwn7biXr7xSRRAyztcTTabYoOev0SalCjTFvsRPApNrtWrG92arrNL vYy30mjcDtboOMLaYF/EGB9Bb67OhSnqrd9929GMzB46msZdCnUGmupRwBiLOAMpOTu/ xgXxZRY8JK8LqcDPH4Z1qbgGAF+6QrIMppgLaa1fjdmq/jeISdUH5rHhnHGN0itBSODe GmUzrI95aXvhJ1Ss7JdEnAwqbHxBSkafgMVWr/h9flFgsjbzEK99uA8DU4lsh1XM5zFP k9rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc; bh=G7zTeV7HivGGK7/AmFGwNvvgE+xYoTaOW1pCL0nph+s=; b=qyxgby37daU0GmLoRVg2a2n9NqcUtQDX/3OsJJOfjF42OSjX2odb7rvdyPCqolPEzA 2oCoVBQeLqGONg4Xr8vOMuFN3lNDaQJ65oZprWNfQjP0hf6bjmR1e9BNOyFf0cyQa+Yo buv8Gic6YwA7psdWkSvZ93yNGxn7ETuqvy95E4e1eIJsAgDR3Wux3uSCoMVIS+Jpimrp HW8YCFIKuiwK/+RtlrVkcxRhsn1GrvzpxwfTeyAKdo2Ph4RR6NETHNkFge7NnSUvifSt P1zxR9E4vMmzjgPv/VPnIhNV2iIruRQdLljLZUyiTTb/NbLLLqTVftRY0kcWmqAAFB/E vpoA== X-Gm-Message-State: ACgBeo37QuaU3JZakJSMXUUOch/+i3Bp3Qlw5yH+IFeeGXnKDTAUMjAG 81Uxpk9i4j51EiYLPTVLM8YV1yf8FuM= X-Google-Smtp-Source: AA6agR6mygGnpoLM0Fz1GI/HNspwZBf2HxeWieGPgMrRMoJDYKMR11CPv0kXU0SX1XneClLqmTxEKKFSAKQ= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:5207:ac36:fdd3:502d]) (user=glider job=sendgmr) by 2002:a17:907:b17:b0:72a:edb8:7529 with SMTP id h23-20020a1709070b1700b0072aedb87529mr5717591ejl.749.1661526599889; Fri, 26 Aug 2022 08:09:59 -0700 (PDT) Date: Fri, 26 Aug 2022 17:08:01 +0200 In-Reply-To: <20220826150807.723137-1-glider@google.com> Mime-Version: 1.0 References: <20220826150807.723137-1-glider@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220826150807.723137-39-glider@google.com> Subject: [PATCH v5 38/44] x86: kasan: kmsan: support CONFIG_GENERIC_CSUM on x86, enable it for KASAN/KMSAN From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , Alexei Starovoitov , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Mark Rutland , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661526601; a=rsa-sha256; cv=none; b=P40Bc3mepvTXbjyswHQBhexC2iNKYWIpLG4kIoknA3ARQy4LGsJqpmjmYG2EQOM+fnzuBb pjI74Bu8TbwF/eNxwgaMjaqBn0a716aRu+6p/poJMG96E947iSl7jwK7OH9pLKrzkECvjQ 9nJRDhEBZ2ijQcENCYvDK3gww2fnwbU= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=rllUU8td; spf=pass (imf21.hostedemail.com: domain of 3R-IIYwYKCE4w1ytu7w44w1u.s421y3AD-220Bqs0.47w@flex--glider.bounces.google.com designates 209.85.218.74 as permitted sender) smtp.mailfrom=3R-IIYwYKCE4w1ytu7w44w1u.s421y3AD-220Bqs0.47w@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661526601; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=G7zTeV7HivGGK7/AmFGwNvvgE+xYoTaOW1pCL0nph+s=; b=aT9v7ille6HGf1p52lzK9PZao4srLNObHNdntVgN/rKH9ljfOGE0CJp8rJLwo+jUV7J0bB uSY0KKxjgzUWAlVlYqVyrkzlGhv2hICci1XsMfWT1KrmlwQWoTth7S3cIkm+oyxe6oO8ZE hk9BajjWZAwt2T32n5Fw9xih4RX2AiQ= X-Stat-Signature: gx55s37zzchgsmcx1p43egx3xtjj6xs6 X-Rspamd-Queue-Id: 168FA1C001B Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=rllUU8td; spf=pass (imf21.hostedemail.com: domain of 3R-IIYwYKCE4w1ytu7w44w1u.s421y3AD-220Bqs0.47w@flex--glider.bounces.google.com designates 209.85.218.74 as permitted sender) smtp.mailfrom=3R-IIYwYKCE4w1ytu7w44w1u.s421y3AD-220Bqs0.47w@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Rspamd-Server: rspam02 X-HE-Tag: 1661526600-191770 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This is needed to allow memory tools like KASAN and KMSAN see the memory accesses from the checksum code. Without CONFIG_GENERIC_CSUM the tools can't see memory accesses originating from handwritten assembly code. For KASAN it's a question of detecting more bugs, for KMSAN using the C implementation also helps avoid false positives originating from seemingly uninitialized checksum values. Signed-off-by: Alexander Potapenko --- Link: https://linux-review.googlesource.com/id/I3e95247be55b1112af59dbba07e8cbf34e50a581 --- arch/x86/Kconfig | 4 ++++ arch/x86/include/asm/checksum.h | 16 ++++++++++------ arch/x86/lib/Makefile | 2 ++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index f9920f1341c8d..33f4d4baba079 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -324,6 +324,10 @@ config GENERIC_ISA_DMA def_bool y depends on ISA_DMA_API +config GENERIC_CSUM + bool + default y if KMSAN || KASAN + config GENERIC_BUG def_bool y depends on BUG diff --git a/arch/x86/include/asm/checksum.h b/arch/x86/include/asm/checksum.h index bca625a60186c..6df6ece8a28ec 100644 --- a/arch/x86/include/asm/checksum.h +++ b/arch/x86/include/asm/checksum.h @@ -1,9 +1,13 @@ /* SPDX-License-Identifier: GPL-2.0 */ -#define _HAVE_ARCH_COPY_AND_CSUM_FROM_USER 1 -#define HAVE_CSUM_COPY_USER -#define _HAVE_ARCH_CSUM_AND_COPY -#ifdef CONFIG_X86_32 -# include +#ifdef CONFIG_GENERIC_CSUM +# include #else -# include +# define _HAVE_ARCH_COPY_AND_CSUM_FROM_USER 1 +# define HAVE_CSUM_COPY_USER +# define _HAVE_ARCH_CSUM_AND_COPY +# ifdef CONFIG_X86_32 +# include +# else +# include +# endif #endif diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile index f76747862bd2e..7ba5f61d72735 100644 --- a/arch/x86/lib/Makefile +++ b/arch/x86/lib/Makefile @@ -65,7 +65,9 @@ ifneq ($(CONFIG_X86_CMPXCHG64),y) endif else obj-y += iomap_copy_64.o +ifneq ($(CONFIG_GENERIC_CSUM),y) lib-y += csum-partial_64.o csum-copy_64.o csum-wrappers_64.o +endif lib-y += clear_page_64.o copy_page_64.o lib-y += memmove_64.o memset_64.o lib-y += copy_user_64.o