From patchwork Mon Jun 13 20:13:54 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: 12880070 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 68183C433EF for ; Mon, 13 Jun 2022 20:15:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E5EF8D01C3; Mon, 13 Jun 2022 16:15:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 920568D01C0; Mon, 13 Jun 2022 16:15:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D23E8D01C4; Mon, 13 Jun 2022 16:15:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 51A318D01C3 for ; Mon, 13 Jun 2022 16:15:27 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 32A52FC0 for ; Mon, 13 Jun 2022 20:15:27 +0000 (UTC) X-FDA: 79574317494.07.A87A449 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by imf31.hostedemail.com (Postfix) with ESMTP id B2B63200A6 for ; Mon, 13 Jun 2022 20:15:26 +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=1655151325; 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=5YxZt8AJdg20zeg5mlaLc0cE80lCSk74fkwRwLQH28g=; b=vNtdLTu/n3uZXNxwSADnWXXhRvSCEmqvLH3FjLwQYNnr7TcYt1H3qoRfDAzhIfr++YtDwz DKhTZe2bKI12WI17MUbeLtNkumWSZskhDTHfG69P2kj/KpodD0zAj2B3BsQUqDUogXpISQ 4ac6Q6f0pE/XLiSdQl54Sxg/q37QO3s= 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 03/32] kasan: move is_kmalloc check out of save_alloc_info Date: Mon, 13 Jun 2022 22:13:54 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655151326; 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=5YxZt8AJdg20zeg5mlaLc0cE80lCSk74fkwRwLQH28g=; b=MZPjNnXiVpyi2Vt3pVGuZbVzDa6AMPjLG+0dXhgxB5TGj+lYn1uwpBkmnqAx/Fp8NZrD7/ 5Xv/bSKfeUHi9J1Z9LVMOI0R/xg0lcEopX0XAS+Squ77QUu1Yq5aBAzamk2FrwFkbGYrFB ZFMU5o9ucg/+pIwcE8XfCCtmyyRxDxo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655151326; a=rsa-sha256; cv=none; b=v2P0Eilbpuq+ogtMuzl0nSrMVZ/L5AydmQH5/I5+KNH0lgSlmiRNWGGFrzWWe4fcWvPOoA tpLNMAva91LGvZEQ5PdNprHFkTqcLx/g6A4KlKIUe/1zlmeWLizbGN6bYGihYeVqtxg+qu oPrMqUISNGInRb4lnp1Qn4Xk8yAWjKk= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="vNtdLTu/"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf31.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="vNtdLTu/"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf31.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: tcaycepn4ckpta8yrbnqwd84m6bwwg4u X-Rspamd-Queue-Id: B2B63200A6 X-HE-Tag: 1655151326-289639 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. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- 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 753775b894b6..a6107e8375e0 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;