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, URIBL_BLOCKED,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 D26B9C2B9F4 for ; Tue, 22 Jun 2021 10:59:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5436661352 for ; Tue, 22 Jun 2021 10:59:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5436661352 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 9BECF6B0036; Tue, 22 Jun 2021 06:59:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 96EE66B0062; Tue, 22 Jun 2021 06:59:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80F576B006C; Tue, 22 Jun 2021 06:59:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 52BDF6B0036 for ; Tue, 22 Jun 2021 06:59:37 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id DB963180AD838 for ; Tue, 22 Jun 2021 10:59:36 +0000 (UTC) X-FDA: 78281063952.05.F4F949A Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) by imf11.hostedemail.com (Postfix) with ESMTP id 8A9BF2001093 for ; Tue, 22 Jun 2021 10:59:36 +0000 (UTC) Received: by mail-ot1-f42.google.com with SMTP id i12-20020a05683033ecb02903346fa0f74dso20775319otu.10 for ; Tue, 22 Jun 2021 03:59:36 -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=ST43GppbGqjxXxYbgPLZB6WISUmWZ5bTKVdHwZJ0LK0=; b=Nj20QEq+KxkLWAiRbPMmd9mJB90uKVMEJjEvf0yYVodg05DYpqSc/pXCThJAUiFWWl iNKgJcJ7DNn2WKIsPkHdudD+TvaWQFYuF2utzM/0BiSNl/bRqb4V/j6c+SppGNmH7N/m SJK8N2DsxlWNrBwtx4EhulxxN/48KFv1mHi3Q4jI1oF0WpsMWn9vLog4SIbJAH8a0T+0 k7XMG81iMUlbL9TnQ1ybXmXmFvN3qgKx+4Qsh0jggwve3xTJ1Ok1CCJOtWLJIOyYJ5iK 9WTN/RGCZZi5C7hQpYFPSEy41Jz0UqtXRSt9nAsvVe4HMhV/4wUnZgEPrWItlRzJHJeI jaHA== 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=ST43GppbGqjxXxYbgPLZB6WISUmWZ5bTKVdHwZJ0LK0=; b=hXVE0Orl7ckroCwz2Giuf2NGeEI3VSgcPzahRZ8P8L/mIasgoX/57k47jEffig3sMZ h+rscTd3t8i3phtNXGM1OiFVfYCw88+GO0xp0Z47+PX+itq1ZtjURcJ5sa/t/EC1cGxo ykXhKXgVDz6xB80Z3XTx1Gt6qgIVkob/uu9qO9uyEP7DVPCypiK8PeONrmnFwZCHQlnk 6eGrX5lE6E0yvR+jx3oDNMlDYkU+SVhSSvLVwuc79pYRr/mwPzYr60HCvyFPJuaWwmL3 vL4BhuysFWPB5nPCb10BG6KMYh02f7drcA6bOrJN0/8FnO6ED58SMjxi7Cbz6WYc6nF+ RaqQ== X-Gm-Message-State: AOAM532aB0JpVF/CcyYjAQ6TReEIa7LTlULipbTIc+MEw/TJT3V5anye XJF1FGWT3Kd7lAAE70mBg8EwMxHs0JObz1U+1EapfA== X-Google-Smtp-Source: ABdhPJyFj9ZXB0FBR0cxOcfQPd3wwOJR8y/fh4HikV7DTsq/slH7YOgsNfWAae+cwaRu5GpXy8mGpPmB6Ualf8IS/kQ= X-Received: by 2002:a05:6830:93:: with SMTP id a19mr2616280oto.17.1624359575598; Tue, 22 Jun 2021 03:59:35 -0700 (PDT) MIME-Version: 1.0 References: <20210622084723.27637-1-yee.lee@mediatek.com> <46b1468146206e6cef0c33ecbfd86e02ea819db4.camel@mediatek.com> In-Reply-To: <46b1468146206e6cef0c33ecbfd86e02ea819db4.camel@mediatek.com> From: Marco Elver Date: Tue, 22 Jun 2021 12:59:24 +0200 Message-ID: Subject: Re: [PATCH] kasan: [v2]unpoison use memzero to init unaligned object To: Yee Lee 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" X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 8A9BF2001093 X-Stat-Signature: p9xn4dhuw4su3merroxg653bk6c75ezd Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=Nj20QEq+; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of elver@google.com designates 209.85.210.42 as permitted sender) smtp.mailfrom=elver@google.com X-HE-Tag: 1624359576-577184 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, 22 Jun 2021 at 12:48, Yee Lee wrote: > > On Tue, 2021-06-22 at 11:01 +0200, Marco Elver wrote: > > On Tue, 22 Jun 2021 at 10:48, wrote: > > > > > > From: Yee Lee > > > > > > Follows the discussion: > > > https://patchwork.kernel.org/project/linux-mediatek/list/?series=504439 > > > > The info about the percentage of how frequent this is could have been > > provided as a simple reply to the discussion. > > > > > This patch Add memzero_explict to initialize unaligned object. > > > > This patch does not apply to anything (I see it depends on the > > previous patch). > > > > What you need to do is modify the original patch, and then send a > > [PATCH v2] (git helps with that by passing --reroll-count or -v) that > > applies cleanly to your base kernel tree. > > > > The commit message will usually end with '---' and then briefly > > denote > > what changed since the last version. > > > Got it. > > > > https://www.kernel.org/doc/html/latest/process/submitting-patches.html#the-canonical-patch-format > > > > > Based on the integrateion of initialization in kasan_unpoison(). > > > The hwtag instructions, constrained with its granularity, has to > > > overwrite the data btyes in unaligned objects. This would cause > > > issue when it works with SLUB debug redzoning. > > > > > > In this patch, an additional initalizaing path is added for the > > > unaligned objects. It contains memzero_explict() to clear out the > > > data and disables its init flag for the following hwtag actions. > > > > > > In lab test, this path is executed about 1.1%(941/80854) within the > > > overall kasan_unpoison during a non-debug booting process. > > > > Nice, thanks for the data. If it is somehow doable, however, I'd > > still > > recommend to additionally guard the new code path by a check if > > debug-support was requested. Ideally with an IS_ENABLED() config > > check > > so that if it's a production kernel the branch is simply optimized > > out > > by the compiler. > > Does it mean the memzero code path would be applied only at > CONFIG_DEBUG_SLUB enabled? It expects no other potential overwriting > in non-debug kernel. Yes, if the problem only occurs with slub debugging enabled. > By the way, based on de-coupling principle, adding a specific > conditional statement(is_enable slub_debug) in a primitive > funciton(kasan_unpoison) is not neat. It may be more proper that the > conditional statement be added in other procedures of slub alloc. What do you have in mind? Well, there is kmem_cache_debug_flags(). Perhaps there's a better place to add the check? > Thanks, > > BR, > Yee > > > > > > Lab test: QEMU5.2 (+mte) / linux kernel 5.13-rc7 > > > > > > Signed-off-by: Yee Lee > > > --- > > > mm/kasan/kasan.h | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h > > > index d8faa64614b7..edc11bcc3ff3 100644 > > > --- a/mm/kasan/kasan.h > > > +++ b/mm/kasan/kasan.h > > > @@ -389,7 +389,7 @@ static inline void kasan_unpoison(const void > > > *addr, size_t size, bool init) > > > return; > > > if (init && ((unsigned long)size & KASAN_GRANULE_MASK)) { > > > init = false; > > > - memset((void *)addr, 0, size); > > > + memzero_explicit((void *)addr, size); > > > } > > > size = round_up(size, KASAN_GRANULE_SIZE); > > > hw_set_mem_tag_range((void *)addr, size, tag, init); > > > 2.18.0 > > > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "kasan-dev" group. > > > To unsubscribe from this group and stop receiving emails from it, > > > send an email to kasan-dev+unsubscribe@googlegroups.com. > > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/kasan-dev/20210622084723.27637-1-yee.lee%40mediatek.com > > > . > > -- > You received this message because you are subscribed to the Google Groups "kasan-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/46b1468146206e6cef0c33ecbfd86e02ea819db4.camel%40mediatek.com.