From patchwork Tue Nov 10 22:20:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895653 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 3C744138B for ; Tue, 10 Nov 2020 22:20:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F111B20870 for ; Tue, 10 Nov 2020 22:20:51 +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="X/G1FHBp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F111B20870 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 9DD306B008C; Tue, 10 Nov 2020 17:20:50 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 93DC76B0092; Tue, 10 Nov 2020 17:20:50 -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 790A26B0093; Tue, 10 Nov 2020 17:20:50 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0171.hostedemail.com [216.40.44.171]) by kanga.kvack.org (Postfix) with ESMTP id 3CC666B008C for ; Tue, 10 Nov 2020 17:20:50 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id DFB01362C for ; Tue, 10 Nov 2020 22:20:49 +0000 (UTC) X-FDA: 77469929418.20.pot18_2d0ce2e272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id C1E05180C07AF for ; Tue, 10 Nov 2020 22:20:49 +0000 (UTC) X-Spam-Summary: 1,0,0,5377d9cd9daa20d3,d41d8cd98f00b204,3qbkrxwokcbuv8yczj58g619916z.x97638fi-775gvx5.9c1@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:69:152:355:379:541:800:960:966:967:968:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1542: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:3353:3867:3868:3870:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4385:4425:5007:6261:6653:6742:8603:8660:9025:9592:9969:10004:10400:11026:11473:11658:11914:12043:12296:12297:12438:12555:12679:12683:12895:12986:13148:13230:14096:14097:14181:14394:14659:14721:21080:21324:21365:21444:21451:21627:21939:21990:30003:30012:30054,0,RBL:209.85.221.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yfebobxjhh9nii8xos5oo75cdddypxn5y4riykzjxwb8p81857khnkt7oqfcb.j69n9doj4t46kun7sahek7jfsymrdsez1fxm nomqp3ua X-HE-Tag: pot18_2d0ce2e272f8 X-Filterd-Recvd-Size: 5960 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:20:49 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id r16so6159524wrw.22 for ; Tue, 10 Nov 2020 14:20:49 -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=/rSFl10DA/GX54GBDw6zGUYBErxFDPI5QaAJ7Zds8ak=; b=X/G1FHBpaTNPbceckVWXnlaQTlozNeiCpeU7tMmREOJimTXkmCTjt6rRjgNPSeQ0pw q73UVtucfzggJP2pLLg0d8XHXT0ngy/FLNTkV+unC3tseUSKbxmMqR1RfIvjsfMbA2Eq fniu1B6bL+1GI15kaPYNzXCk/yeIk98ad1Jm+d8i/5KDIlsK5BgcmP/efX5QPF1s8Si/ 6NXEIxz4MDViC1Q1XgbEBgCSkG1swl6ak5j3v5axkuBmgM9UBfbh1fuNYORk8kWZXP9Q iGwaOfp4qXX5szQspMdAW9gYIF9nebgteHML8xT3tOJCbTT3oOXCOGM54M/KBM4bacSy YBMQ== 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=/rSFl10DA/GX54GBDw6zGUYBErxFDPI5QaAJ7Zds8ak=; b=uXUkV0+BkvZ/s36lvn6LVcthoPnNc0wgvMe4qvSJwDdlLrSLdN9OK9MVZ6w5yCfCwN WV4vYCHlWHmyLalkfBKpLF6m6kHCS69yGlycwPC0FFJDeB5HMM32CcncxF28qmaab6wQ uKoorBntiCAfUBhi5D3Xel+7RUSXHKT/hRlYCv2jteMHg6CINhx3w/Sn8VKsuMIBRDHc vPeTDBlmufuAldgKA0Mv+zS7pI3rEz3VVKxAvo1Eo+mD0AhHtN9xtSDVBLtdpUCQs+Qx OIMGqp+HTzZtuEDthVbhYn1gfXulHvw1Xcyhw73Ox6Zrc99zqVY4wmGmWdcpyF1JnNz2 3v7Q== X-Gm-Message-State: AOAM53289XOypyvOx7MUkCiDQ+wGNHMHNU5VYfTxd6giH/L+4aWCXt6m ayMV83TqnKBPEPhcXd2eIhDWRvsJSc39Y+Jq X-Google-Smtp-Source: ABdhPJyY/bBCadcyM/PRgjtzpu0TT6SQ1RzDsL0gjh3vrXFFiPqpWwP79w3xbEXBJdKIjt2rfzmw9gOcpXSqt2FT X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a5d:6692:: with SMTP id l18mr14959782wru.44.1605046848070; Tue, 10 Nov 2020 14:20:48 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:12 +0100 In-Reply-To: Message-Id: <73399d4c0644266d61ad81eb391f5ee10c09e098.1605046662.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 08/20] kasan: inline random_tag for HW_TAGS 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 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 calls. Signed-off-by: Andrey Konovalov Link: https://linux-review.googlesource.com/id/Iac5b2faf9a912900e16cca6834d621f5d4abf427 Reviewed-by: Marco Elver --- mm/kasan/hw_tags.c | 5 ----- mm/kasan/kasan.h | 34 +++++++++++++++++----------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 49ea5f5c5643..1476ac07666e 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -42,11 +42,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 hw_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 8a5501ef2339..7498839a15d3 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) { @@ -279,6 +268,17 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) #endif /* CONFIG_KASAN_HW_TAGS */ +#ifdef CONFIG_KASAN_SW_TAGS +u8 random_tag(void); +#elif defined(CONFIG_KASAN_HW_TAGS) +#define random_tag() hw_get_random_tag() +#else +static inline u8 random_tag(void) +{ + return 0; +} +#endif + /* * Exported functions for interfaces called from assembly or from generated * code. Declarations here to avoid warning about missing declarations.