Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4323444imw; Tue, 12 Jul 2022 06:08:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tvgtzxCLxCLIRcMpXG/PAdIviN/A1H5AJQVFEJkEyO26kq1JThTJIlyuqgu9OJDDgTevLU X-Received: by 2002:a05:6402:2741:b0:434:fe8a:1f96 with SMTP id z1-20020a056402274100b00434fe8a1f96mr32480250edd.331.1657631332245; Tue, 12 Jul 2022 06:08:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657631332; cv=none; d=google.com; s=arc-20160816; b=v3xRyRToJI/DAYBvGxxrhJkPfnFTWXQTM9egn+++rnyYUmi6NNYm3j0aqUfhA9u+7D 1P20KgwBYBMizxdnOlvNojr3SRJhsvftL7nlDnZbailOP55iRtnL7yJcM0yUrRfKxrW/ kQl4vcoj+Sn9VKud36kYQAu2V5HJAPTMW8n/tzlP7obHIumfdxnGcX3z5F9T9FBUc8ZZ tzFjd8Ob6ZrZjSb4Qga92IeJCMU2fMnmMTRHEPJPjW7isacAISHtzBeKKCxexrezIQOL 03z9I1UFCJSRj+fF+Sj3Xldy/8yiBsy/BElAfC2Ka2dehMvkbkKNOyK74I5rhV1jLmmN WtxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=UaSHri8uX8QzRonJXk/9Ev1ksxotFizg9AxbyPG4jRk=; b=ndbJTWEytA4DQhnYkq4Tsj5vRTgNq5t9ajIZfQFOe24c2pqBE2wDNvePpx0a9G3uzk wmblMaIlq5pwz6u+eeGbdp+H53geJBYgcby6W8wkjpNkn3CuEHb3YsMX0X/DE8oDdvzu P2hyRWt+r/vIQuDBWU8CrlvXMtyEA98AI5fjJU+VVgjKifgBNQu6yyZebw32beF8GzCw klJlzhxBwh7lSLxJu8uNS5FFg9JtRcuZDz/CpVTGvVWV3vPF0LrcuTJcly/XTy9hVCM/ UrVRR7y16k5qMCa5eK28pH9NWc7wHq7pOAzBHrkwlFHVMPav2LxwXBetuVg3Ya9FiRgK 2DKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=AdA9qT8w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hc39-20020a17090716a700b00726e142a88esi14701384ejc.983.2022.07.12.06.08.23; Tue, 12 Jul 2022 06:08:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=AdA9qT8w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232503AbiGLMVZ (ORCPT + 99 others); Tue, 12 Jul 2022 08:21:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232278AbiGLMVW (ORCPT ); Tue, 12 Jul 2022 08:21:22 -0400 Received: from mail-yw1-x1130.google.com (mail-yw1-x1130.google.com [IPv6:2607:f8b0:4864:20::1130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70BEF6D549 for ; Tue, 12 Jul 2022 05:21:21 -0700 (PDT) Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-31d7db3e6e5so48327207b3.11 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=HkCqm5owuBKLUCAbb4kngmnvV4P9IiVXVGFkX1Br6d0Fqc8ORrEOk6LjfIn4AW2BFI DwS0F2phDx6fIMvwQIL1gRPI9pF984OnU5Bee8RWncZj9j9O+wDZVc3RB+/6sMQtOQsZ nURzFzvfBjcApf/NifrPioMcUL/VU01KHKMYx0KQ7Vjv8qc4zxeU/akQrAMBZGckmPba DdaJaGha1oqEWF3lSYgKYpmu/nvgltRotSsDeTiytpwM0UiMB1kDeef3o7eRYoOQvtam 7+aqXquqgyBCiwVvR3Hcvl1FIlUL60066W0X4T464K9kStFsabA7NhP6BrSSu39u6haG yMMQ== X-Gm-Message-State: AJIora/46TzrRTbIC6bE+BiyDqtPGwY86LJulYNypDGpp8vJnE6CMoHz ytvwUe+ClLedocRBQ+nQ+UwvK6Yf5M4BZJLSb+uwQg== 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" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > }