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 X-Spam-Level: X-Spam-Status: No, score=-18.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77444C433E0 for ; Thu, 18 Feb 2021 19:40:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CF87764EAD for ; Thu, 18 Feb 2021 19:40:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CF87764EAD Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2C80C6B0006; Thu, 18 Feb 2021 14:40:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 24E896B006C; Thu, 18 Feb 2021 14:40:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C96F6B006E; Thu, 18 Feb 2021 14:40:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0091.hostedemail.com [216.40.44.91]) by kanga.kvack.org (Postfix) with ESMTP id E42036B0006 for ; Thu, 18 Feb 2021 14:40:55 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AFB2E45B4 for ; Thu, 18 Feb 2021 19:40:55 +0000 (UTC) X-FDA: 77832406470.12.9B351F4 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf23.hostedemail.com (Postfix) with ESMTP id 2AAF0A0009DC for ; Thu, 18 Feb 2021 19:40:54 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id c19so1962665pjq.3 for ; Thu, 18 Feb 2021 11:40:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Wz58CA+xdym2cUyo64XiGmMsVDmP1Ip6ib85/PA+8zo=; b=W4TbLg8qMWfsuB1AB1fMJ0DQTaFAcUQPoq+MCDUEp7V6Ciiq+emO4o0yMc0LUcQVGk S40PUiaXN2LyLfo1ylNkspdEEFpE0/hgXez5mBHFrPqWj49PStiPKrJWCNlddVIR4S4y JJAZA3udWx4+/ZhZg4XxsRnz+APo8EZEu+2ay55Dr1HLzkYwmnbeRNgFPUZiLLlDOayP fuYr65h6/T/GhF3hcPGcmyns/NTU7L6GS+bD1W4r5YYwUDff5ENC7jCx5iDLSLfEf8jm 6JWIu9r+O/an6lGfFBSinzW5B1JyjGz9cFZnSwPTT5dSUDpCNH3qYYubCax/srCVhYYO 7NUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Wz58CA+xdym2cUyo64XiGmMsVDmP1Ip6ib85/PA+8zo=; b=RMNUWFvug+Sblne4c160mnlkI3NLS54M+4al+CpVEvM+EXbZ7HAfLhqEcIAXPOWxbk B3FKcHvtVNtW007YAgZtpYbGKd6L1A5V6yjnDg2/1nYrHuV92PC56RakC33uHNu94PRU sYrGfxYhMQZOLDp28OZc/hcAOBwIG7gVwLMctJ7eKSvb0PGfvKfnQjU7/bvAnaTBRyn5 ybrEU4cBhHRKdf0Z69olUZmGi7BM8y+8Zssrwj8iX6gUNWGrTlbcNIMBeOo5XZ0fp6mA W1iNGYrnGpozwBZKzUSQ5V/DuU20EB7PHQKhQdCkuwiL2y6BilVyH5pNpiyaaOJKQ+j3 +ThA== X-Gm-Message-State: AOAM5333uE4RW1UFuGCmf/pQ5bySpaSoN9/LH1ur9TCYAv3NWWRogfYu YFAmdGgCU+e6slGvrndgXH46Zw5JJttux/NoZIgQ7w== X-Google-Smtp-Source: ABdhPJy9k7NKXFpkZ4tUscvI5SLYhmK/yqXevEwIsjaCtaGMW1qKDUD84zrMdLrxIty2E/geWLG9vutH6l1No/0DJBU= X-Received: by 2002:a17:90a:64cc:: with SMTP id i12mr6170pjm.41.1613677253685; Thu, 18 Feb 2021 11:40:53 -0800 (PST) MIME-Version: 1.0 References: <487751e1ccec8fcd32e25a06ce000617e96d7ae1.1613595269.git.andreyknvl@google.com> In-Reply-To: From: Andrey Konovalov Date: Thu, 18 Feb 2021 20:40:42 +0100 Message-ID: Subject: Re: [PATCH] mm, kasan: don't poison boot memory To: David Hildenbrand Cc: Andrew Morton , Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , George Kennedy , Konrad Rzeszutek Wilk , Will Deacon , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Peter Collingbourne , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , Christoph Hellwig , kasan-dev , Linux ARM , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2AAF0A0009DC X-Stat-Signature: x3tk7i9eqjd5u69pbmcfu37jqifdchx3 Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf23; identity=mailfrom; envelope-from=""; helo=mail-pj1-f44.google.com; client-ip=209.85.216.44 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1613677254-214841 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 Thu, Feb 18, 2021 at 9:55 AM David Hildenbrand wrote: > > On 17.02.21 21:56, Andrey Konovalov wrote: > > During boot, all non-reserved memblock memory is exposed to the buddy > > allocator. Poisoning all that memory with KASAN lengthens boot time, > > especially on systems with large amount of RAM. This patch makes > > page_alloc to not call kasan_free_pages() on all new memory. > > > > __free_pages_core() is used when exposing fresh memory during system > > boot and when onlining memory during hotplug. This patch adds a new > > FPI_SKIP_KASAN_POISON flag and passes it to __free_pages_ok() through > > free_pages_prepare() from __free_pages_core(). > > > > This has little impact on KASAN memory tracking. > > > > Assuming that there are no references to newly exposed pages before they > > are ever allocated, there won't be any intended (but buggy) accesses to > > that memory that KASAN would normally detect. > > > > However, with this patch, KASAN stops detecting wild and large > > out-of-bounds accesses that happen to land on a fresh memory page that > > was never allocated. This is taken as an acceptable trade-off. > > > > All memory allocated normally when the boot is over keeps getting > > poisoned as usual. > > > > Signed-off-by: Andrey Konovalov > > Change-Id: Iae6b1e4bb8216955ffc14af255a7eaaa6f35324d > > Not sure this is the right thing to do, see > > https://lkml.kernel.org/r/bcf8925d-0949-3fe1-baa8-cc536c529860@oracle.com > > Reversing the order in which memory gets allocated + used during boot > (in a patch by me) might have revealed an invalid memory access during boot. > > I suspect that that issue would no longer get detected with your patch, > as the invalid memory access would simply not get detected. Now, I > cannot prove that :) This looks like a good example. Ok, what we can do is: 1. For KASAN_GENERIC: leave everything as is to be able to detect these boot-time bugs. 2. For KASAN_SW_TAGS: remove boot-time poisoning via kasan_free_pages(), but use the "invalid" tag as the default shadow value. The end result should be the same: bad accesses will be detected. For unallocated memory as it has the default "invalid" tag, and for allocated memory as it's poisoned properly when allocated/freed. 3. For KASAN_HW_TAGS: just remove boot-time poisoning via kasan_free_pages(). As the memory tags have a random unspecified value, we'll still have a 15/16 chance to detect a memory corruption. This also makes sense from the performance perspective: KASAN_GENERIC isn't meant to be running in production, so having a larger perf impact is acceptable. The other two modes will be faster.