From patchwork Fri Jul 1 14:23:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12903395 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 B6D98C433EF for ; Fri, 1 Jul 2022 14:25:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 584EF6B0083; Fri, 1 Jul 2022 10:25:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 534696B0085; Fri, 1 Jul 2022 10:25:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3FC7D6B0088; Fri, 1 Jul 2022 10:25:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2E2726B0083 for ; Fri, 1 Jul 2022 10:25:04 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 003F530638 for ; Fri, 1 Jul 2022 14:25:03 +0000 (UTC) X-FDA: 79638752928.22.08A8F37 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) by imf05.hostedemail.com (Postfix) with ESMTP id 9EDB110004C for ; Fri, 1 Jul 2022 14:25:03 +0000 (UTC) Received: by mail-ej1-f73.google.com with SMTP id e20-20020a170906315400b007262bd0111eso843086eje.9 for ; Fri, 01 Jul 2022 07:25:03 -0700 (PDT) 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=7Mhpta8bleV/UMALfZOJOInTXQD6eorZ40ixMEZLH18=; b=SK4zuM/LqN9V22hVvhABvQyziEAxlHrFJzT62CJ+8Gr5z1csKhH0NIvPZy7HXwJZFS 0o2Dz9vScER5v/m3+Ov0b57zCiiCbrCApAZdn0z0ihUpL5uyP1/bXdMsnOidMKiSUJDa BkpEhnOP5g9I2ipIkJ/00hmAFD/og1SK1bdSIzNn7w1oXdItFTnvjA3O0QGS+joj1qPX vu0mr88M+r8S11fh0jNIUSEtNfYY0tXFLftByqdopzCcL3vRLSr276xum9GnJaDchFRq uhPrpu558FoA7vusBo7CKw0yXyOXaTlW7kFEpBeSn/VATqyQvBlleRzR7PZQtdIROe8G gmaQ== 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=7Mhpta8bleV/UMALfZOJOInTXQD6eorZ40ixMEZLH18=; b=O2ejW6coLAboV1Mv0xZb0TKqU2mjJ9m/6I0gMfZrwrCRQwt2/EN2vBbUwvwz9XpQa9 ZRxvy/cTrfAusigrNre4raoH28r56OD2hlHhZFFjY+OBULjjmu5LjqOLXP8xYikCm6v4 Ke/t/iIgnF5Aap1+jfq0TTr8KcSx5lCNMKAFH+kjoO050Oifw7L51AQyLHVV8AWO7zu4 DcVGZFD7GhULfxv9rvSJBmSd3MvXnA56Y0UeLDENeGOQLV8VjLB/CbejTaVo1E1HNH66 GBuzodMkZCf8fn7AEmFWfk5I9lY2j1i5kcRli1zbjNmGzH6gkvxIVDvSyZPfbfseSqQy BrLw== X-Gm-Message-State: AJIora8aliHMukefHMV72fhzmvwU9YLoaffA9SgWKx1nAtVw2QKh0MrB S5pF9BB/1A2uEg+mWy37oNcUJ6dZyxA= X-Google-Smtp-Source: AGRyM1ukHF/75hMCkE1ceqIKqAwme//w8kYLgX2Q1lXtK73q2uRxhmeeO4GeXUnmM9oAotsl2fJIw5hKglI= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:a6f5:f713:759c:abb6]) (user=glider job=sendgmr) by 2002:a05:6402:f29:b0:435:c108:58f2 with SMTP id i41-20020a0564020f2900b00435c10858f2mr19006559eda.401.1656685502496; Fri, 01 Jul 2022 07:25:02 -0700 (PDT) Date: Fri, 1 Jul 2022 16:23:03 +0200 In-Reply-To: <20220701142310.2188015-1-glider@google.com> Message-Id: <20220701142310.2188015-39-glider@google.com> Mime-Version: 1.0 References: <20220701142310.2188015-1-glider@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 38/45] 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=1656685503; a=rsa-sha256; cv=none; b=LqliZmjfZ20z/SGSPQlxre6GIfkB7bFv2Gi65fIDxxF+3PTI3QCrOUAVselz5FMwYxQvmt KjTgg0/+1VFpGhhouK2L4lMkmHrn51zG10BViefFVVA/ptKEZEZy/VwN9m5fjChMtkYV8k TI+JMbf+k8ROqbYCQ0b688e9XzdwQDs= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="SK4zuM/L"; spf=pass (imf05.hostedemail.com: domain of 3vgO_YgYKCN0FKHCDQFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--glider.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=3vgO_YgYKCN0FKHCDQFNNFKD.BNLKHMTW-LLJU9BJ.NQF@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=1656685503; 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=7Mhpta8bleV/UMALfZOJOInTXQD6eorZ40ixMEZLH18=; b=mQ5p6wqDS2W9T30ZXby/QQyQ8G2lZ1JVd8BNLvDM7VDBk8kaHGYPEP4acsrIPK8jjtKZlU /LfNkFj4lxoCDDMsZM3wE+lfnA5ZmaC2uI/x6pohs9i9lgYrLMBEhJaldaVN96kH9M+pfI 8tzBnbUxg9mcrp2J/NgVXxsnzBuOWwQ= X-Rspam-User: X-Rspamd-Server: rspam04 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="SK4zuM/L"; spf=pass (imf05.hostedemail.com: domain of 3vgO_YgYKCN0FKHCDQFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--glider.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=3vgO_YgYKCN0FKHCDQFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: ptuy16zy3s5ya511u8orcqd36yh1kosh X-Rspamd-Queue-Id: 9EDB110004C X-HE-Tag: 1656685503-1334 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 be0b95e51df66..4a5d0a0f54dea 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