Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4353640pxb; Tue, 10 Nov 2020 14:24:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJw03zaVsn6HRFxxP+klnepZt462Yo34IevVI2NmY4DLHlfLixnUjOzTTakkiRaQM2duwc+3 X-Received: by 2002:a05:6402:88d:: with SMTP id e13mr24246723edy.366.1605047080526; Tue, 10 Nov 2020 14:24:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605047080; cv=none; d=google.com; s=arc-20160816; b=KP/tNC9HTmnMGyiXuITTa0AVdQ93NPLRdRQ2ECqAAGDEcCyoTouZgzpqKOG/nRNh22 6LooPl0+1NW0mOdr0hA4skd9A7dheLmkkzZOJaBb55u3A/4+6GOjdxiBNRQ6jqd6z5Fi hEJ8HstA69nV8Wp7UaBE3m6I/Qa1+C+KtVBs9spzf7WV7n+w0AqqhdF+k7WVhmjKeSUu wts4az8jI5RyXKn48lEh6bVrgVm6xre2pm42TJngq+DvliHBEuCpfuN7x/Nxt1qAy6YM thvDitHRqbudoYrhc5VREfLJYElGbhko8gTRsT1ijDUIhYLq+LHUr45y36vhFIoNigBT mqxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=WOMasW4WeK4i4aCbvBDhnou95P0GnHEsdPLivTBemP4=; b=hTJ/a6J8O/+bFRh9ELwShG82IqYmfsR0WDu7iV8M4goTBafDcV6ehMU6mZL7CAQ4m/ u15UQHJ9IaAQuxYzoO+84KelpPRWETF9EeJDQq+BnaLaIeB2dJ81P8Mn4xZjZQXzKtRR +yREyXYDS8OmzH4RwwZ0m0EnhZMffKe7S958R1ZtXX5rlflDHvwNhu31YUfeWowvYbOm OlpCrb6UM9IL/3JYoZOCVk/3RGdqgVl9digu6JBrKEeYKQnnS5VLOM2kJhuccSrPuRG4 /qI6TCy2tkU2dsvBvxIiSYmSuCbvBCR6jsQUlqzQY8q7uNwi+XxIez3yyYSyKOZLPQRu 75Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HbmemqL7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q25si47273edr.490.2020.11.10.14.24.17; Tue, 10 Nov 2020 14:24:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HbmemqL7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732281AbgKJWU4 (ORCPT + 99 others); Tue, 10 Nov 2020 17:20:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732374AbgKJWUv (ORCPT ); Tue, 10 Nov 2020 17:20:51 -0500 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 467D5C0613D1 for ; Tue, 10 Nov 2020 14:20:51 -0800 (PST) Received: by mail-qt1-x849.google.com with SMTP id j5so8487695qtj.11 for ; Tue, 10 Nov 2020 14:20:51 -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=p0OTVHLLkmaQUeF7aJW3te4IbE/8RGn3XmjyQ/VudvDANXtLu0ixPoOlyJmaZCcZy6 Q0q5vqPit3UEZ0msGUOvhe9sBx3kagehjWoQEEBV2zuOVNu1jsnBVGsB251Q+bCOK00c gXMgpOQwSyQb/fU8mKY1sStPsv1j2V2lHj9CD8aD1r6evbQJ7q/T04YbhC+45AKaifNT 4L7SQ0LBmrCo6ArUEcN1kQCyCWQq5lG0BABY0TguOezscEbgdB1eb/vMQ8m2ywr2G1EI 35JngAvKDwg0wCwTREgWKX3EwKZHqjORPGUcBD0HMbuXp/HjaSRds4zBcTkmDPFsX21R 4zSQ== X-Gm-Message-State: AOAM5325nEb7t3YR9ADgm+qG8Xrj2lX6pufbZi5qhME7ZM969XHBzOtz z0WxJoQB34+E67xmLoNTQobn0ECWNxze08do Sender: "andreyknvl via sendgmr" 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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. -- 2.29.2.222.g5d2a92d10f8-goog