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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,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 75BF4C48BDF for ; Tue, 15 Jun 2021 10:09:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 059A361446 for ; Tue, 15 Jun 2021 10:09:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 059A361446 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 4ACDC6B0036; Tue, 15 Jun 2021 06:09:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45D786B006E; Tue, 15 Jun 2021 06:09:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FE406B0070; Tue, 15 Jun 2021 06:09:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id EF46F6B0036 for ; Tue, 15 Jun 2021 06:09:12 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8D5CFA77C for ; Tue, 15 Jun 2021 10:09:12 +0000 (UTC) X-FDA: 78255535344.09.7665213 Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) by imf14.hostedemail.com (Postfix) with ESMTP id C2283C00CBFF for ; Tue, 15 Jun 2021 10:09:02 +0000 (UTC) Received: by mail-ot1-f49.google.com with SMTP id o17-20020a9d76510000b02903eabfc221a9so13787976otl.0 for ; Tue, 15 Jun 2021 03:09:12 -0700 (PDT) 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=D/L9M46eaaH0QBqlJTDr9j5/a1oRGHp298rEoHobuSk=; b=W/lfR0zLReQdc7PHjJRVB6Z9hn6GJnOFkroA8pyiE5Y0liNQOgHCt87KS4/bkAX7eE ruHOuoF3srORlhSJjFmg2JbJjF5kGBzDUdqoQ0xbY3+7U7KDtUEKQoFIW1wmxShxQmod 7IyMraVpNr1qagN5T38H67gQWcRWPStkYlkY11tL5rOY+XXsGhRyP8nZUCYVpimFgaQE TDDfZ1AGYIcueALqYy5l63YjogRbXNbuef49nv3KDRdF0RjbjFT7pI243T186J46J90u GYwjsGeX4c5nDZ3pG35tX5Es3IqFrw8pDn67QjzsbdqHfe/JYmQpn0mp/7J6DK3wRnbU rLsQ== 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=D/L9M46eaaH0QBqlJTDr9j5/a1oRGHp298rEoHobuSk=; b=TwPYurT3IS042Qa/ricPt0ytRkT4dd5Txl+x0srNH3Lu19Q2CgrO5n29hghvyjZwcg hwbB1BZg/JyVjpcYAdKBVLkr6fr1QdiuxF7f/LD6rYVCUoku3oUh2M/YofvCsdtZO/nT h02PqtZwLJCso9HjTeljTEBTblvPYYLda+iBgSz6j7nEoshjafrhiwzEMyhMyg7rgV/4 ShKwNeTsqyjJoxV4rMMNEMjYSEgHVLmqzZoZnsG1mnStgkDYSHyIa8g8N8+YSidRkMrh SmjA5eS+OpqJVNL1kMrrHfvkBIM8/QAa52IVdDwE2eIltK8Fv8/8IxjD0VHvlSMNgxGf QjXg== X-Gm-Message-State: AOAM531kUGTERNfaxsHCfLVVlGEgA7NaMDeS4x9M0r99vJtMQpx53NrN FeOchQrSc2dZwC5d2wSaMEdiuKVxmpvVdG1uTqmyYA== X-Google-Smtp-Source: ABdhPJxoyp0dtnWruW4n6Mt2ds9c4qUeqUilzebp8wuisHioo9OHuACmSktOGVx8KTei3SgLqyvF0y6ZD0IXk1FVzz0= X-Received: by 2002:a05:6830:1c7b:: with SMTP id s27mr17651144otg.233.1623751751394; Tue, 15 Jun 2021 03:09:11 -0700 (PDT) MIME-Version: 1.0 References: <20210615014705.2234866-1-dja@axtens.net> <20210615014705.2234866-3-dja@axtens.net> In-Reply-To: <20210615014705.2234866-3-dja@axtens.net> From: Marco Elver Date: Tue, 15 Jun 2021 12:08:59 +0200 Message-ID: Subject: Re: [PATCH v12 2/6] kasan: allow architectures to provide an outline readiness check To: Daniel Axtens Cc: LKML , Linux Memory Management List , linuxppc-dev@lists.ozlabs.org, kasan-dev , Christophe Leroy , aneesh.kumar@linux.ibm.com, Balbir Singh , "Aneesh Kumar K . V" Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C2283C00CBFF Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b="W/lfR0zL"; spf=pass (imf14.hostedemail.com: domain of elver@google.com designates 209.85.210.49 as permitted sender) smtp.mailfrom=elver@google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: 8msom9eeckgffio1jxhskkj5mm8rkcjd X-HE-Tag: 1623751742-298881 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 Tue, 15 Jun 2021 at 03:47, Daniel Axtens wrote: > > Allow architectures to define a kasan_arch_is_ready() hook that bails > out of any function that's about to touch the shadow unless the arch > says that it is ready for the memory to be accessed. This is fairly > uninvasive and should have a negligible performance penalty. > > This will only work in outline mode, so an arch must specify > ARCH_DISABLE_KASAN_INLINE if it requires this. > > Cc: Balbir Singh > Cc: Aneesh Kumar K.V > Suggested-by: Christophe Leroy > Signed-off-by: Daniel Axtens > > -- > > I discuss the justfication for this later in the series. Also, > both previous RFCs for ppc64 - by 2 different people - have > needed this trick! See: > - https://lore.kernel.org/patchwork/patch/592820/ # ppc64 hash series > - https://patchwork.ozlabs.org/patch/795211/ # ppc radix series > --- > mm/kasan/common.c | 4 ++++ > mm/kasan/generic.c | 3 +++ > mm/kasan/kasan.h | 4 ++++ > mm/kasan/shadow.c | 4 ++++ > 4 files changed, 15 insertions(+) > > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > index 10177cc26d06..0ad615f3801d 100644 > --- a/mm/kasan/common.c > +++ b/mm/kasan/common.c > @@ -331,6 +331,10 @@ static inline bool ____kasan_slab_free(struct kmem_cache *cache, void *object, > u8 tag; > void *tagged_object; > > + /* Bail if the arch isn't ready */ > + if (!kasan_arch_is_ready()) > + return false; > + > tag = get_tag(object); > tagged_object = object; > object = kasan_reset_tag(object); > diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c > index 53cbf28859b5..c3f5ba7a294a 100644 > --- a/mm/kasan/generic.c > +++ b/mm/kasan/generic.c > @@ -163,6 +163,9 @@ static __always_inline bool check_region_inline(unsigned long addr, > size_t size, bool write, > unsigned long ret_ip) > { > + if (!kasan_arch_is_ready()) > + return true; > + > if (unlikely(size == 0)) > return true; > > diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h > index 8f450bc28045..19323a3d5975 100644 > --- a/mm/kasan/kasan.h > +++ b/mm/kasan/kasan.h > @@ -449,6 +449,10 @@ static inline void kasan_poison_last_granule(const void *address, size_t size) { > > #endif /* CONFIG_KASAN_GENERIC */ > > +#ifndef kasan_arch_is_ready > +static inline bool kasan_arch_is_ready(void) { return true; } > +#endif > + > /* > * Exported functions for interfaces called from assembly or from generated > * code. Declarations here to avoid warning about missing declarations. > diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c > index 082ee5b6d9a1..74134b657d7d 100644 > --- a/mm/kasan/shadow.c > +++ b/mm/kasan/shadow.c > @@ -73,6 +73,10 @@ void kasan_poison(const void *addr, size_t size, u8 value, bool init) > { > void *shadow_start, *shadow_end; > > + /* Don't touch the shadow memory if arch isn't ready */ > + if (!kasan_arch_is_ready()) > + return; > + What about kasan_poison_last_granule()? kasan_unpoison() currently seems to potentially trip on that.