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=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 3153BC4741F for ; Fri, 30 Oct 2020 16:07:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 86C89206CB for ; Fri, 30 Oct 2020 16:07:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GrPpfjH1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 86C89206CB 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 B3B3B6B007B; Fri, 30 Oct 2020 12:07:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AEB2A6B007D; Fri, 30 Oct 2020 12:07:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A02866B007E; Fri, 30 Oct 2020 12:07:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0092.hostedemail.com [216.40.44.92]) by kanga.kvack.org (Postfix) with ESMTP id 750206B007B for ; Fri, 30 Oct 2020 12:07:28 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1958F180AD815 for ; Fri, 30 Oct 2020 16:07:28 +0000 (UTC) X-FDA: 77429071776.02.view39_000cd6f27297 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id DF1B210097AA2 for ; Fri, 30 Oct 2020 16:07:27 +0000 (UTC) X-HE-Tag: view39_000cd6f27297 X-Filterd-Recvd-Size: 7342 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Fri, 30 Oct 2020 16:07:27 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id b19so3182179pld.0 for ; Fri, 30 Oct 2020 09:07:26 -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=65NdEmArmPn2nuNEZO88L62AlLpra/5W/MBvA6ISo6c=; b=GrPpfjH1Ts0r2xcMdjmbjed7OUayfMuc4WOdlv0ZhFob64TnL4hD5hOk7Now2nQ8yu fOXSQ648lTFpOXPIhsi1WZHKxnFPnXinXXCZXTH9mlJFC/e3MWaWyDWTLMXWaLIPRfCM 8dZ8KLfY/EtY0e0A/QpFpHNMkm3Z/+tbzTpyR+fz5y9RXVAxlbHux2PVwMeEkvlPFVgf DPlIpeWxYE1F6Pna/9vDxLRMxT51ye0bSNL2+L5DVGolhL7HMNqKn8Qxn+HUgo4+b+pa D6Oc5V8RLnBBL3KPx8XbpMS89rdSwKVDtSU7eCr3enXvqiq5Ljtc2TQd6xSvSRbiJDch 4TwQ== 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=65NdEmArmPn2nuNEZO88L62AlLpra/5W/MBvA6ISo6c=; b=Xh3DnI/IDPFWN3BLEv+dfuTo4THAyKEUV4WBrf1LohoJupSYTSHZVjrGyNOcpIdJay SeOaB0EHIauO5YzOdjhHPZGmREngbq8/sHZLLdU0R/fnAekJ8XyoLcSwcQ5jx3mly+SE p21RBZ+OYOk67ZThBLCkIgcsLzRf35czsLmAgH5EqDCpBBrTr+MyJSmZL0LuuK5Pfk53 k9dARaILewfosi6uE6yESsb9OU6K8niL+OME7k79FGR7W6wT9pMg/k0PCrZLbwtRsL8C s7mwqNEgsAfCdg3mgx/G6uZxGRAXmVb71HYxw/8WaQhHR3yfumaTcPE086LMHW1V5Tqa WYFA== X-Gm-Message-State: AOAM530aG5NPFdcWNNZ/14PBttQKOhqWcPisYQXQG/a58dwYXXzQw8Xc 7KxVStOfC81FM+Q0AX/qXMX8xUg36AkCECA5fepMmw== X-Google-Smtp-Source: ABdhPJwlIp8b6tHuhS2gJe93mWv2avcRLDWoNoXAS1I+eryy8zoqP3XyCYL4BSaptouForfDCOtkN5t50ZACn32fcPo= X-Received: by 2002:a17:902:d888:b029:d0:cb2d:f274 with SMTP id b8-20020a170902d888b02900d0cb2df274mr9313310plz.13.1604074045822; Fri, 30 Oct 2020 09:07:25 -0700 (PDT) MIME-Version: 1.0 References: <56b19be34ee958103481bdfc501978556a168b42.1603372719.git.andreyknvl@google.com> In-Reply-To: From: Andrey Konovalov Date: Fri, 30 Oct 2020 17:07:14 +0100 Message-ID: Subject: Re: [PATCH RFC v2 10/21] kasan: inline random_tag for HW_TAGS To: Dmitry Vyukov Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Kostya Serebryany , Peter Collingbourne , Serban Constantinescu , Andrey Ryabinin , Elena Petrova , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev , Linux ARM , Linux-MM , LKML Content-Type: text/plain; charset="UTF-8" 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 Fri, Oct 30, 2020 at 4:48 PM Andrey Konovalov wrote: > > On Wed, Oct 28, 2020 at 12:08 PM Dmitry Vyukov wrote: > > > > On Thu, Oct 22, 2020 at 3:19 PM Andrey Konovalov wrote: > > > > > > Using random_tag() currently results in a function call. Move its > > > definition to mm/kasan/kasan.h and turn it into a static inline function > > > for hardware tag-based mode to avoid uneeded function call. > > > > > > Signed-off-by: Andrey Konovalov > > > Link: https://linux-review.googlesource.com/id/Iac5b2faf9a912900e16cca6834d621f5d4abf427 > > > --- > > > mm/kasan/hw_tags.c | 5 ----- > > > mm/kasan/kasan.h | 37 ++++++++++++++++++++----------------- > > > 2 files changed, 20 insertions(+), 22 deletions(-) > > > > > > diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c > > > index c3a0e83b5e7a..4c24bfcfeff9 100644 > > > --- a/mm/kasan/hw_tags.c > > > +++ b/mm/kasan/hw_tags.c > > > @@ -36,11 +36,6 @@ void kasan_unpoison_memory(const void *address, size_t size) > > > round_up(size, KASAN_GRANULE_SIZE), get_tag(address)); > > > } > > > > > > -u8 random_tag(void) > > > -{ > > > - return get_random_tag(); > > > -} > > > - > > > bool check_invalid_free(void *addr) > > > { > > > u8 ptr_tag = get_tag(addr); > > > diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h > > > index 0ccbb3c4c519..94ba15c2f860 100644 > > > --- a/mm/kasan/kasan.h > > > +++ b/mm/kasan/kasan.h > > > @@ -188,6 +188,12 @@ static inline bool addr_has_metadata(const void *addr) > > > > > > #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ > > > > > > +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) > > > +void print_tags(u8 addr_tag, const void *addr); > > > +#else > > > +static inline void print_tags(u8 addr_tag, const void *addr) { } > > > +#endif > > > + > > > bool check_invalid_free(void *addr); > > > > > > void *find_first_bad_addr(void *addr, size_t size); > > > @@ -223,23 +229,6 @@ static inline void quarantine_reduce(void) { } > > > static inline void quarantine_remove_cache(struct kmem_cache *cache) { } > > > #endif > > > > > > -#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) > > > - > > > -void print_tags(u8 addr_tag, const void *addr); > > > - > > > -u8 random_tag(void); > > > - > > > -#else > > > - > > > -static inline void print_tags(u8 addr_tag, const void *addr) { } > > > - > > > -static inline u8 random_tag(void) > > > -{ > > > - return 0; > > > -} > > > - > > > -#endif > > > - > > > #ifndef arch_kasan_set_tag > > > static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) > > > { > > > @@ -273,6 +262,20 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) > > > #define get_mem_tag(addr) arch_get_mem_tag(addr) > > > #define set_mem_tag_range(addr, size, tag) arch_set_mem_tag_range((addr), (size), (tag)) > > > > > > +#ifdef CONFIG_KASAN_SW_TAGS > > > +u8 random_tag(void); > > > +#elif defined(CONFIG_KASAN_HW_TAGS) > > > +static inline u8 random_tag(void) > > > +{ > > > + return get_random_tag(); > > > > What's the difference between random_tag() and get_random_tag()? Do we > > need both? > > Not really. Will simplify this in the next version and give cleaner names. Actually I think I'll keep both for the next version, but rename get_random_tag() into hw_get_random_tag() along with other hw-specific calls. The idea is to have hw_*() calls for things that are implemented by the hardware for HW_TAGS, and then define random_tag() based on that for HW_TAGS and based on a software implementation for SW_TAGS.