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 0F571C4743C for ; Mon, 21 Jun 2021 17:43:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9541160FE9 for ; Mon, 21 Jun 2021 17:43:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9541160FE9 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 DB1636B0082; Mon, 21 Jun 2021 13:43:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D62186B0083; Mon, 21 Jun 2021 13:43:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDADB6B0085; Mon, 21 Jun 2021 13:43:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0066.hostedemail.com [216.40.44.66]) by kanga.kvack.org (Postfix) with ESMTP id 8B7766B0082 for ; Mon, 21 Jun 2021 13:43:03 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 298708249980 for ; Mon, 21 Jun 2021 17:43:03 +0000 (UTC) X-FDA: 78278451846.18.6AC1A89 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) by imf20.hostedemail.com (Postfix) with ESMTP id E366A141D for ; Mon, 21 Jun 2021 17:43:02 +0000 (UTC) Received: by mail-ot1-f45.google.com with SMTP id 102-20020a9d0eef0000b02903fccc5b733fso18526178otj.4 for ; Mon, 21 Jun 2021 10:43:02 -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=kWdKmgG81sJBpjzyn6TSXwSeeJGUkRqGGWlo4fqoDn8=; b=CiXJ6n5GdF+RiiNqGBO8F/j8UT/qhrN72JVb6QaRtPts6IKnis1CFRapxq7H+wy4y1 GWFo9rcHlHpgxkBuLl4FS+8nlfkbFdEK030ZBhpN6qPJyMdUafOT0hCU6NEZg+/cJrRf pfUzmq6g8hNiBVMMQmi5KfoIWhoTK5CYmbo4zeZ/tHEV5+AmXckA3wZ3WT3BZXuMYZhj NVF9LE5CuIVcXNVCX2rJkKM0UTagmKMDidAkcc234Ig0n0BY3qwZzxSC3tO838vQVzra HPm27NoxKSHr5adMk4M2O98++8T2eFSxAVl/o/Ma4PEiSFCcZeTUZXl2qx5wnX0IoVAk IjQw== 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=kWdKmgG81sJBpjzyn6TSXwSeeJGUkRqGGWlo4fqoDn8=; b=ifoj148nAw1DlcE+cbcp+ZOuW14ertDT2e0JCfu/Yw/+Hr22kCorbL0N5Lj1XDEdoH 4Qza7n0sa6nb1ulnDAV+4hBBT9b5YJLihbLFt4F8M8SvJZj2x0eFCq9ip8meH07gsRy0 NjmNfSLkxRZLIk2UApty3oUQ9hs2jyPcNGUXCSi8iL32ok/DZE7dsuZDjyP1wsx+3jfw C+PqRHfht8KZKGvbcR94XEPDUH5qlPGlWzmVGRDw2rk307piK5dAHo/KtGNI1ccXCE1q 8Jv+JMrU+4MOiQaSRCRarUp7JwbcKDJyMsmEUbO6uJISws3VnyxEG9jWGeCUrauS4JDq 96UQ== X-Gm-Message-State: AOAM533uNCZcCTiAkDvzdnDKQoqEukoBHvKZs4nZcSU7gtAaXEZHweoL 8ChYhocuVvliwjGQmie6TaCUO+r5m0yHH6VDs523jA== X-Google-Smtp-Source: ABdhPJzVuQD0App46op5EoLAsOExo04ZFgTkfdf4n29jaNNRdc+/25Vd8YBFUCL3ENliNFYA0wncLG3zEOaXjjN0y5I= X-Received: by 2002:a05:6830:93:: with SMTP id a19mr22053479oto.17.1624297381993; Mon, 21 Jun 2021 10:43:01 -0700 (PDT) MIME-Version: 1.0 References: <20210621154442.18463-1-yee.lee@mediatek.com> In-Reply-To: <20210621154442.18463-1-yee.lee@mediatek.com> From: Marco Elver Date: Mon, 21 Jun 2021 19:42:50 +0200 Message-ID: Subject: Re: [PATCH] kasan: unpoison use memset to init unaligned object size To: yee.lee@mediatek.com Cc: andreyknvl@gmail.com, wsd_upstream@mediatek.com, Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Andrew Morton , Matthias Brugger , "open list:KASAN" , "open list:MEMORY MANAGEMENT" , open list , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=CiXJ6n5G; spf=pass (imf20.hostedemail.com: domain of elver@google.com designates 209.85.210.45 as permitted sender) smtp.mailfrom=elver@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E366A141D X-Stat-Signature: pa97z4ac5j13rmxdcrbabp5mt3cxd9y4 X-HE-Tag: 1624297382-85233 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000009, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, 21 Jun 2021 at 17:45, wrote: > > From: Yee Lee > > This patch adds a memset to initialize object of unaligned size. s/This patch adds/Add/ > Duing to the MTE granulrity, the integrated initialization using s/Duing/Doing/ s/granulrity/granularity/ > hwtag instruction will force clearing out bytes in granular size, > which may cause undesired effect, such as overwriting to the redzone > of SLUB debug. In this patch, for the unaligned object size, function Did you encounter a crash due to this? Was it only SLUB debug that caused the problem? Do you have data on what the percentage of allocations are that would now be treated differently? E.g. what's the percentage of such odd-sized allocations during a normal boot with SLUB debug off? We need to know if this change would pessimize a non-debug kernel, and if so, we'd have to make the below behave differently. > uses memset to initailize context instead of the hwtag instruction. s/initailize/initialize/ > Signed-off-by: Yee Lee > --- > mm/kasan/kasan.h | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h > index 8f450bc28045..d8faa64614b7 100644 > --- a/mm/kasan/kasan.h > +++ b/mm/kasan/kasan.h > @@ -387,8 +387,11 @@ static inline void kasan_unpoison(const void *addr, size_t size, bool init) > > if (WARN_ON((unsigned long)addr & KASAN_GRANULE_MASK)) > return; > + if (init && ((unsigned long)size & KASAN_GRANULE_MASK)) { > + init = false; > + memset((void *)addr, 0, size); Should use memzero_explicit(). > + } > size = round_up(size, KASAN_GRANULE_SIZE); > - Remove whitespace change. > hw_set_mem_tag_range((void *)addr, size, tag, init); > } Thanks, -- Marco