From patchwork Tue Dec 14 16:20:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12676411 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 A95E7C433F5 for ; Tue, 14 Dec 2021 16:42:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B15646B00A7; Tue, 14 Dec 2021 11:23:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AC4BA6B00A8; Tue, 14 Dec 2021 11:23:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 965056B00A9; Tue, 14 Dec 2021 11:23:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0039.hostedemail.com [216.40.44.39]) by kanga.kvack.org (Postfix) with ESMTP id 840C16B00A7 for ; Tue, 14 Dec 2021 11:23:47 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 0EBD484773 for ; Tue, 14 Dec 2021 16:23:36 +0000 (UTC) X-FDA: 78916920432.22.76E1BB3 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) by imf26.hostedemail.com (Postfix) with ESMTP id 9C69C140006 for ; Tue, 14 Dec 2021 16:23:35 +0000 (UTC) Received: by mail-ed1-f73.google.com with SMTP id n11-20020aa7c68b000000b003e7d68e9874so17491142edq.8 for ; Tue, 14 Dec 2021 08:23:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=i4Z+HeLj0NbbaW9XsBkHpSzUhX9tYLnEL06CEMz9cxQ=; b=CtNztcjBEqraF6PWTnSXaJZwhKs4VOr8XcR8KBg/pBQ2Da/PejhZCJsQKJ2YjR7v2/ kbtjnRWYF6oHjIE1QUU9sNrJZ8oX1PRsaB0k0wwiGw3KahKYBs8kQxsYyIVySa1+C8gk 9CaiRdFR0QdNccdq18vSMjDF/91noPRWA/PSRMJ06eKAO4TKKxY6Xra42mzaC6fUiyvg daWq/hDnfRZaLNtnJTkxe1lSZQA8VJLyT1WDrfP17NsWbAfasFzl8yGpRlOTOKmlWzTu hifPioMqhyX4Qx2LkQcqzJfpAUnlpCQYhZJ4Vpv0aBceVSNFALwdReKnTErJKjqlvToM 3Abg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=i4Z+HeLj0NbbaW9XsBkHpSzUhX9tYLnEL06CEMz9cxQ=; b=ezdxtIy6bjt+GH3AS31MQEGvM8fFojgn29AdpJUvqlU27CPnrJK+BHw+VdGkpbIDx7 GicDnKzX3eO2r0J3SxzGnhez2VnCL7fZbXyyUd1ojAho2NPv3jJZOTyeeFCc9xW8+bf3 kxDnUZZZhjauHXHEyrSSb6Q/nH8xl5UrwGuIYUsAQ9bAp805rC6XXFBClz4wmurzgWUl wyoriET6D3G1R0BMjF1nmGm1GVguJ6Isht1Qhvmujwei3rJq4EqDi8L6PfPoywZo2BCn QR25etR1JdkmdbignaEJi3yWUojK3FACvqulZUdhujkG4agObs/9oWQXA1VtOkc0Liq9 wzQg== X-Gm-Message-State: AOAM532chmK/wke607Bg3xa1lmgY9aOtGu5vX6EvRyvsS1kADCKvkpCc 9nwiP2ScKlDRE7PezuiUrnTQxr+iK/8= X-Google-Smtp-Source: ABdhPJwqPu8nQr3pQusJoQrA+ALDwH/+qHW5RVV26eLzrA0etrVpkzgZzSUC2jzB1IRlcmv9IvT3/jPW864= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:357e:2b9d:5b13:a652]) (user=glider job=sendgmr) by 2002:a17:906:1913:: with SMTP id a19mr6790529eje.484.1639499014263; Tue, 14 Dec 2021 08:23:34 -0800 (PST) Date: Tue, 14 Dec 2021 17:20:44 +0100 In-Reply-To: <20211214162050.660953-1-glider@google.com> Message-Id: <20211214162050.660953-38-glider@google.com> Mime-Version: 1.0 References: <20211214162050.660953-1-glider@google.com> X-Mailer: git-send-email 2.34.1.173.g76aa8bc2d0-goog Subject: [PATCH 37/43] x86: kasan: kmsan: support CONFIG_GENERIC_CSUM on x86, enable it for KASAN/KMSAN From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Ard Biesheuvel , 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 , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=CtNztcjB; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 3BsW4YQYKCIcrwtop2rzzrwp.nzxwty58-xxv6lnv.z2r@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3BsW4YQYKCIcrwtop2rzzrwp.nzxwty58-xxv6lnv.z2r@flex--glider.bounces.google.com X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9C69C140006 X-Stat-Signature: hjdhhpau1oedpewy7i1zmasgh4ika71t X-HE-Tag: 1639499015-285494 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 5c2ccb85f2efb..760570ff3f3e4 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -310,6 +310,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 c6506c6a70922..81be8498353a6 100644 --- a/arch/x86/lib/Makefile +++ b/arch/x86/lib/Makefile @@ -66,7 +66,9 @@ endif lib-$(CONFIG_X86_USE_3DNOW) += mmx_32.o 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