From patchwork Tue Nov 10 22:20:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895655 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A411B138B for ; Tue, 10 Nov 2020 22:20:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4ED2D20674 for ; Tue, 10 Nov 2020 22:20:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="HbmemqL7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4ED2D20674 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 8F4E46B0095; Tue, 10 Nov 2020 17:20:52 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8A25C6B0096; Tue, 10 Nov 2020 17:20:52 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71D456B0098; Tue, 10 Nov 2020 17:20:52 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0170.hostedemail.com [216.40.44.170]) by kanga.kvack.org (Postfix) with ESMTP id 346E16B0095 for ; Tue, 10 Nov 2020 17:20:52 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id CFCD5180AD802 for ; Tue, 10 Nov 2020 22:20:51 +0000 (UTC) X-FDA: 77469929502.26.kite64_4e04738272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id A9E041804B647 for ; Tue, 10 Nov 2020 22:20:51 +0000 (UTC) X-Spam-Summary: 1,0,0,840e84f54e9dcf2f,d41d8cd98f00b204,3qhkrxwokcbcxa0e1l7ai83bb381.zb985ahk-997ixz7.be3@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:69:152:355:379:541:800:960:965:966:967:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:1981:2194:2196:2199:2200:2393:2525:2559:2563:2682:2685:2859:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3354:3867:3868:3870:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4117:4321:4385:4390:4395:4425:5007:6261:6653:6742:8603:8957:9025:9592:9969:10004:10400:11026:11473:11658:11914:12043:12291:12296:12297:12438:12555:12679:12895:12986:14096:14097:14181:14394:14659:14721:21080:21324:21365:21444:21451:21627:21939:21990:30003:30012:30054:30075,0,RBL:209.85.222.202:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yrtxhph15xkhx679skskd5dspryypt3ak41kkquxemcrwhrdxgzbkf57haqid.ntyxycc8racux9n9oabxr4xtti6fft9 57x6xwxd X-HE-Tag: kite64_4e04738272f8 X-Filterd-Recvd-Size: 6714 Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:20:51 +0000 (UTC) Received: by mail-qk1-f202.google.com with SMTP id w189so215391qkd.6 for ; Tue, 10 Nov 2020 14:20:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=WOMasW4WeK4i4aCbvBDhnou95P0GnHEsdPLivTBemP4=; b=HbmemqL7hGON1dZUtHAIO/Ny5Z5yXZ4JDxyVyJy817JkkYWiD/QtbND8oC8ab7jCnI 5Wbp10QDuzYLJu6lNMQ/cilMKfhcOQKdxLo2b2RlUEr9KAST0GqOKpk56Qy0CPfK5YuM QKo9+lLsoO9x4ILXIt3sKjhcJ8pdIqjOatB0zmydqRDWzWGHfAAw6YSENtb7o5FoF2si lv2RAbcm26eD/cbihEmRP5cwTzv9aHIH9H1rKOeKMG6R8p0oNMZ/gBRAvVBPI42BEMDc psc8VI/Zf64SE7/LFloA+ZdjypcKgOsrKstJM34+FhTA1A+KoSlI7qAqvqmoxKnZxc2h Df1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=WOMasW4WeK4i4aCbvBDhnou95P0GnHEsdPLivTBemP4=; b=XXjBeNMF74vYBFGUKmO7lOoHJUKhMf5f2syuycn7KII5blWMlY14TjJB/IQfTf1YHS JV49L84iZxt3MA3Yr7ko0G0TT/je929IdEHqlGeGnR2vgPvoRb0sbsyzAHpa1W0hKNuJ k9OKyzI+p7EZzX8JzAmGgp8sGmFCX4mc6k/9SvoTsBtz3lsttpI5K/EQF4SwXLdFX5O/ zBFdQbKzUSniAfZZHx3v6rqZiLN4IDPzmJi0rZPKFHG1PLyDNZEAm2jZG89YOE3Nvbky ez1ui9iCfiFJ6DnIUxbkVXlk8tNLyfowzZEnSV6e2CjOT+NJqp1cykAYoxxwOeIbsWd2 n2mQ== X-Gm-Message-State: AOAM5333xeFcWD3PbkeLZy358NyCoDnujumCDW+9XyNsq9ZHLaiecohZ GYzUm8Ko9kba5p6PkW/4ZlxLyjvukvBuBEMF X-Google-Smtp-Source: ABdhPJxV3RzH8+DI2bYMl115wXV/xV/YUfiel/zd2PCNwgEqHTxxwM0dmmBMZ8TRZ+cgt1xGGP23OM9y5Oi9AE76 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:9e2f:: with SMTP id p47mr14534879qve.11.1605046850374; Tue, 10 Nov 2020 14:20:50 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:13 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 09/20] kasan: inline kasan_poison_memory and check_invalid_free From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: Using kasan_poison_memory() or check_invalid_free() currently results in function calls. Move their definitions to mm/kasan/kasan.h and turn them into static inline functions for hardware tag-based mode to avoid unneeded function calls. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/Ia9d8191024a12d1374675b3d27197f10193f50bb Reviewed-by: Marco Elver --- mm/kasan/hw_tags.c | 15 --------------- mm/kasan/kasan.h | 28 ++++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 1476ac07666e..0303e49904b4 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -30,27 +30,12 @@ void kasan_init_hw_tags(void) pr_info("KernelAddressSanitizer initialized\n"); } -void kasan_poison_memory(const void *address, size_t size, u8 value) -{ - hw_set_mem_tag_range(kasan_reset_tag(address), - round_up(size, KASAN_GRANULE_SIZE), value); -} - void kasan_unpoison_memory(const void *address, size_t size) { hw_set_mem_tag_range(kasan_reset_tag(address), round_up(size, KASAN_GRANULE_SIZE), get_tag(address)); } -bool check_invalid_free(void *addr) -{ - u8 ptr_tag = get_tag(addr); - u8 mem_tag = hw_get_mem_tag(addr); - - return (mem_tag == KASAN_TAG_INVALID) || - (ptr_tag != KASAN_TAG_KERNEL && ptr_tag != mem_tag); -} - void kasan_set_free_info(struct kmem_cache *cache, void *object, u8 tag) { diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 7498839a15d3..ab7314418604 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -153,8 +153,6 @@ struct kasan_alloc_meta *kasan_get_alloc_meta(struct kmem_cache *cache, struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, const void *object); -void kasan_poison_memory(const void *address, size_t size, u8 value); - #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) static inline const void *kasan_shadow_to_mem(const void *shadow_addr) @@ -194,8 +192,6 @@ void print_tags(u8 addr_tag, const void *addr); 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); const char *get_bug_type(struct kasan_access_info *info); void metadata_fetch_row(char *buffer, void *row); @@ -279,6 +275,30 @@ static inline u8 random_tag(void) } #endif +#ifdef CONFIG_KASAN_HW_TAGS + +static inline void kasan_poison_memory(const void *address, size_t size, u8 value) +{ + hw_set_mem_tag_range(kasan_reset_tag(address), + round_up(size, KASAN_GRANULE_SIZE), value); +} + +static inline bool check_invalid_free(void *addr) +{ + u8 ptr_tag = get_tag(addr); + u8 mem_tag = hw_get_mem_tag(addr); + + return (mem_tag == KASAN_TAG_INVALID) || + (ptr_tag != KASAN_TAG_KERNEL && ptr_tag != mem_tag); +} + +#else /* CONFIG_KASAN_HW_TAGS */ + +void kasan_poison_memory(const void *address, size_t size, u8 value); +bool check_invalid_free(void *addr); + +#endif /* CONFIG_KASAN_HW_TAGS */ + /* * Exported functions for interfaces called from assembly or from generated * code. Declarations here to avoid warning about missing declarations.