From mboxrd@z Thu Jan 1 00:00:00 1970 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 B95A0C433EF for ; Tue, 12 Jul 2022 12:21:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24F41940065; Tue, 12 Jul 2022 08:21:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FF4F940063; Tue, 12 Jul 2022 08:21:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C80B940065; Tue, 12 Jul 2022 08:21:22 -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 00701940063 for ; Tue, 12 Jul 2022 08:21:21 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C87CB20DFD for ; Tue, 12 Jul 2022 12:21:21 +0000 (UTC) X-FDA: 79678357962.06.5B1F156 Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) by imf25.hostedemail.com (Postfix) with ESMTP id 6D679A0071 for ; Tue, 12 Jul 2022 12:21:21 +0000 (UTC) Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-31c8bb90d09so78870047b3.8 for ; Tue, 12 Jul 2022 05:21:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UaSHri8uX8QzRonJXk/9Ev1ksxotFizg9AxbyPG4jRk=; b=AdA9qT8whnij0+KR+xYBYzsjojFQe6acCMTqkTici9ybil/uXKlgNpGU4ccpVCEIhz 9lstl2oAgiyy3zfDj8omvZMXE2HfC9BztuasX9rV3FAtelrWEST4nMElNJrEIUbHg6xz vLBb8YSGSfV6wwGP//JqkXtQWBzWnS6IQnt0H/AhukwKmCy+De2sO+LsQj6CPfc47DEP GPy1Qc9iOVk/8rq20s4g9LqjTdYELDMJmbd3WnYzVj9FTIda6MtL0VuZXtIj4K0Lxzhq mXgFDNw0qg6K2V5/KOq8itfFBvS3GWdiVr7JMEdKlZRGv/i9f+m7rMBo/pDfaPsFN5yP NkQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UaSHri8uX8QzRonJXk/9Ev1ksxotFizg9AxbyPG4jRk=; b=5QeMAMBtvdMy8PX/Jd+iPOZa4CrdALbAcvlGsmHX4U9CeYOYZNLqkwDgfABflMLAyX iZNd9CsfuoAaJoe/dSEUTvnfgdpm0TFeS394IGo5j8wM3oi0FIv31pSs8xl+r/+fCrgg m1rvKM6cr/0/WUzHgj/AGyRVbQs94KC1Gm5j+7Uf++csCDo/XdR7b1dBr3LdyZsmI6uO YajjrKBbbxSDrQxGOZuYToq9hRDLfQMP7xbq3HqD7C3ohGDqDwShtzzV0OtmbCtaSx/6 XkbOLy8wJUoPYxBurIuI4X/aPyd+MXc7rUtF62Y8Tx0oIDA8fvMWwiaJx86Z2vRGEEdw qcqw== X-Gm-Message-State: AJIora/0vAenxj2fduL05Rf6NdMAprGZbFZbX85qG6cIqWs2ZKYrwBRn rhUuDeuQliE34v90VL3nUe5vjBi9I0EyTL/F9eFpBQ== X-Google-Smtp-Source: AGRyM1tNTqqD1WJS4VX6QxCOJmIA4NZigO0ohBTbUAMEjXFjLnHlS2MHRgJF6cAyN0c2yj/38K4PnLL3yJAEs4Jhs+g= X-Received: by 2002:a81:1492:0:b0:31c:a1ff:9ec with SMTP id 140-20020a811492000000b0031ca1ff09ecmr23857082ywu.327.1657628480468; Tue, 12 Jul 2022 05:21:20 -0700 (PDT) MIME-Version: 1.0 References: <20220701142310.2188015-1-glider@google.com> <20220701142310.2188015-15-glider@google.com> In-Reply-To: <20220701142310.2188015-15-glider@google.com> From: Marco Elver Date: Tue, 12 Jul 2022 14:20:44 +0200 Message-ID: Subject: Re: [PATCH v4 14/45] mm: kmsan: maintain KMSAN metadata for page operations To: Alexander Potapenko 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 , 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 Content-Type: text/plain; charset="UTF-8" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657628481; 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=UaSHri8uX8QzRonJXk/9Ev1ksxotFizg9AxbyPG4jRk=; b=SIRk0QFcHjKz+EGkQrHbdtGR2ZfQCNXa2tz8D6sdWeJvkrvW5RXaVi0Glapx63RUVCiqUy Atzecs54f/gIe0SD6Xt+PkolSuNBV+1eu3zc9GZ0IvM6/K2jQvuvSvkmFIXUPIHXjt+h74 dpV46Tn5MzlO2PyeOLqijD6kowPfMvE= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=AdA9qT8w; spf=pass (imf25.hostedemail.com: domain of elver@google.com designates 209.85.128.174 as permitted sender) smtp.mailfrom=elver@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657628481; a=rsa-sha256; cv=none; b=C84WmODAQgEoYrRTiErUcqHBUN3FkLB7uBuuXFxEnHCmxO5b9LCWsDKlUrznrz+VIGIt2v sedue9iof+T9+cGu2dsYYXY/KuWL1I+EDOVDYdl9kg7WEP6UOTR8ig2lF3TpOXZmcXBApb a9FIS2xw7HHfsRDaRPUt5F9vE8Z0Y6g= X-Rspamd-Server: rspam02 X-Stat-Signature: btsw4fr9b3wct54wbxm434cnc71mykzz X-Rspamd-Queue-Id: 6D679A0071 X-Rspam-User: Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=AdA9qT8w; spf=pass (imf25.hostedemail.com: domain of elver@google.com designates 209.85.128.174 as permitted sender) smtp.mailfrom=elver@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1657628481-381076 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: On Fri, 1 Jul 2022 at 16:23, Alexander Potapenko wrote: > > Insert KMSAN hooks that make the necessary bookkeeping changes: > - poison page shadow and origins in alloc_pages()/free_page(); > - clear page shadow and origins in clear_page(), copy_user_highpage(); > - copy page metadata in copy_highpage(), wp_page_copy(); > - handle vmap()/vunmap()/iounmap(); > > Signed-off-by: Alexander Potapenko > --- > v2: > -- move page metadata hooks implementation here > -- remove call to kmsan_memblock_free_pages() > > v3: > -- use PAGE_SHIFT in kmsan_ioremap_page_range() > > v4: > -- change sizeof(type) to sizeof(*ptr) > -- replace occurrences of |var| with @var > -- swap mm: and kmsan: in the subject > -- drop __no_sanitize_memory from clear_page() > > Link: https://linux-review.googlesource.com/id/I6d4f53a0e7eab46fa29f0348f3095d9f2e326850 > --- > arch/x86/include/asm/page_64.h | 12 ++++ > arch/x86/mm/ioremap.c | 3 + > include/linux/highmem.h | 3 + > include/linux/kmsan.h | 123 +++++++++++++++++++++++++++++++++ > mm/internal.h | 6 ++ > mm/kmsan/hooks.c | 87 +++++++++++++++++++++++ > mm/kmsan/shadow.c | 114 ++++++++++++++++++++++++++++++ > mm/memory.c | 2 + > mm/page_alloc.c | 11 +++ > mm/vmalloc.c | 20 +++++- > 10 files changed, 379 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h > index baa70451b8df5..227dd33eb4efb 100644 > --- a/arch/x86/include/asm/page_64.h > +++ b/arch/x86/include/asm/page_64.h > @@ -45,14 +45,26 @@ void clear_page_orig(void *page); > void clear_page_rep(void *page); > void clear_page_erms(void *page); > > +/* This is an assembly header, avoid including too much of kmsan.h */ All of this code is under an "#ifndef __ASSEMBLY__" guard, does it matter? > +#ifdef CONFIG_KMSAN > +void kmsan_unpoison_memory(const void *addr, size_t size); > +#endif > static inline void clear_page(void *page) > { > +#ifdef CONFIG_KMSAN > + /* alternative_call_2() changes @page. */ > + void *page_copy = page; > +#endif > alternative_call_2(clear_page_orig, > clear_page_rep, X86_FEATURE_REP_GOOD, > clear_page_erms, X86_FEATURE_ERMS, > "=D" (page), > "0" (page) > : "cc", "memory", "rax", "rcx"); > +#ifdef CONFIG_KMSAN > + /* Clear KMSAN shadow for the pages that have it. */ > + kmsan_unpoison_memory(page_copy, PAGE_SIZE); What happens if this is called before the alternative-call? Could this (in the interest of simplicity) be moved above it? And if you used the kmsan-checks.h header, it also doesn't need any "ifdef CONFIG_KMSAN" anymore. > +#endif > }