From patchwork Tue Jul 19 00:09:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 12921897 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5E94C43334 for ; Tue, 19 Jul 2022 00:10:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E53D26B0073; Mon, 18 Jul 2022 20:10:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DDC1E940007; Mon, 18 Jul 2022 20:10:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7D696B0074; Mon, 18 Jul 2022 20:10:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id AB70C940007 for ; Mon, 18 Jul 2022 20:10:22 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 876C7812F4 for ; Tue, 19 Jul 2022 00:10:22 +0000 (UTC) X-FDA: 79701917484.14.B24B200 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by imf18.hostedemail.com (Postfix) with ESMTP id 218F21C0017 for ; Tue, 19 Jul 2022 00:10:21 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1658189421; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GtkG5Wr6mLxaj0KDnAXzT5VwvOshmWOEVZwvcH5Zewg=; b=mN9bAq9GONsrVCTbjG80C24gOTIMa+xuIqPBtuKnd9t1EmZu9qiGd5NezacM1d9GvjRLK8 Gwe7MocFUFwRFZIXlCMnNgD+irIrHoko8uTkz6ClE3gAJYdZQGZizTArRoI4ljcXTyzo/6 slVf9IOinbUllaQpiZY1CbQC+FZddzs= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Peter Collingbourne , Evgenii Stepanov , Florian Mayer , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm v2 03/33] kasan: move is_kmalloc check out of save_alloc_info Date: Tue, 19 Jul 2022 02:09:43 +0200 Message-Id: <52c77b163f90a7d24a0a38f713b3849439387431.1658189199.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658189422; a=rsa-sha256; cv=none; b=v1U8f2sBs3mHG0nmo1KdBY9c+eHZkny1vwuycPcdP7DS/M01i658JFcQjqhcIF7AphpMlS dfx4GQObXp5aJCJ8WVMW44x5YDh97RJh1XCadrsED5fYFYs7O7DD8MEW5pBFTCic2B+6RO 9EPHsvP0hZLL27ik4Kt69y39e1Zs0iM= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=mN9bAq9G; spf=pass (imf18.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658189422; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GtkG5Wr6mLxaj0KDnAXzT5VwvOshmWOEVZwvcH5Zewg=; b=L/5bZuUjQd/0g6yE1gRuDFHxejzBOhiqCSBpFmykTGGQPdnTr7GJz8brqiu8eOOPNqOYh+ ae6YR2hk0Ewiw+3UBKhlkq32RzxbfZSxfeqVAv3+fEF8/ZlhxpKbg6ppqlK0D8a+pvGXcH 0eQB4oXH+zuF13rN51stiYqPbKtxVZw= X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 218F21C0017 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=mN9bAq9G; spf=pass (imf18.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Stat-Signature: 4ns3yhrj7437wj5jf49h7dqowyz97kpn X-HE-Tag: 1658189421-362381 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: From: Andrey Konovalov Move kasan_info.is_kmalloc check out of save_alloc_info(). This is a preparatory change that simplifies the following patches in this series. Reviewed-by: Marco Elver Signed-off-by: Andrey Konovalov --- mm/kasan/common.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 4b2bbb6063cb..a6fd597f73f5 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -423,15 +423,10 @@ void __kasan_slab_free_mempool(void *ptr, unsigned long ip) } } -static void save_alloc_info(struct kmem_cache *cache, void *object, - gfp_t flags, bool is_kmalloc) +static void save_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) { struct kasan_alloc_meta *alloc_meta; - /* Don't save alloc info for kmalloc caches in kasan_slab_alloc(). */ - if (cache->kasan_info.is_kmalloc && !is_kmalloc) - return; - alloc_meta = kasan_get_alloc_meta(cache, object); if (alloc_meta) kasan_set_track(&alloc_meta->alloc_track, flags); @@ -466,8 +461,8 @@ void * __must_check __kasan_slab_alloc(struct kmem_cache *cache, kasan_unpoison(tagged_object, cache->object_size, init); /* Save alloc info (if possible) for non-kmalloc() allocations. */ - if (kasan_stack_collection_enabled()) - save_alloc_info(cache, (void *)object, flags, false); + if (kasan_stack_collection_enabled() && !cache->kasan_info.is_kmalloc) + save_alloc_info(cache, (void *)object, flags); return tagged_object; } @@ -512,8 +507,8 @@ static inline void *____kasan_kmalloc(struct kmem_cache *cache, * Save alloc info (if possible) for kmalloc() allocations. * This also rewrites the alloc info when called from kasan_krealloc(). */ - if (kasan_stack_collection_enabled()) - save_alloc_info(cache, (void *)object, flags, true); + if (kasan_stack_collection_enabled() && cache->kasan_info.is_kmalloc) + save_alloc_info(cache, (void *)object, flags); /* Keep the tag that was set by kasan_slab_alloc(). */ return (void *)object;