From patchwork Thu Dec 21 18:35:38 2023 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: 182405 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp611614dyi; Thu, 21 Dec 2023 10:37:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGkAOGoN++d/Y7z6bnVcKO++eEymShL8XHOmT1wkhgPXHbo0VvqRnOEWIjp3Nzh5fd2SFZB X-Received: by 2002:a17:90a:784e:b0:28a:c616:ff1c with SMTP id y14-20020a17090a784e00b0028ac616ff1cmr141990pjl.97.1703183821734; Thu, 21 Dec 2023 10:37:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703183821; cv=none; d=google.com; s=arc-20160816; b=FXS+6Jk1YCtpNNCm5TkJ7AL3EI5salFnJgPpq+MS8xqnayz5XC0j57Sw8XSAH/uQvb y/YkGoZnZaLme48zmxPvkt7A0W4UCSpnLfgy73eloXOkVEhVqecHFuTdL0fFg6vDq1h9 XyOMj4YbpKJ8m1Dm202BfaeDF9Bqz08s+uE8DfC+F4R4tYLA1QSO7Dzc9V2ch8J/A7/y Nmn0EaUde9aFe4LQwurUdyg+1m2iyHZNdeL9Yw9cDG+Yr/FrfT3Y1YNghUTpDVycv+QT CVp8puW1D8BYxcfLF6Fb1P2C4ybYz36ZQWf9cJAFx4xXfbsw6WAG9+xKOgKQT1Zkr8xx df5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9xuoTXuQnTI+pN/bKZ3i8KybAohyAUoP+IGmtMicRak=; fh=E9W45FwZb6Id+g4Lg+hTR4TMK1PXvrXS/qWrVP2FBRY=; b=GL6IfK/MQaxkQ1oHBV9ew1sexO78MpfWXB7bcYaibnRM6mtlSD4QWOAEh2NOvx8HNA 5XF6KABFcOdovBTx9lc6ytJjTDKPQsI3OLqkjY3/rIou2Y0vnY6z7o3rY/DF/qB0hZ6z yqXUreIAqFu+QqleSFSlR4dkMEKjqaNc9NE7Je5J6msVAri/iXoej4XfN/TmZrqJV+Fx JDhZNu6JfrbHwJYkZJKu+PTsNwxLaFTwNUCgrugx47uZc4Gsh8NKuvl1DF+l6hceJsu+ oplsG1BlnPWTMbVRlMOuWPjx3c4KHSUZ8/n4LsIVUFFjg0inTTluyZCSYULpYgTKorKc GuZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=WarMWAg0; spf=pass (google.com: domain of linux-kernel+bounces-8936-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8936-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w7-20020a17090aad4700b0028b3dcfcf5dsi2071959pjv.0.2023.12.21.10.37.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 10:37:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8936-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=WarMWAg0; spf=pass (google.com: domain of linux-kernel+bounces-8936-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8936-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 728482863A4 for ; Thu, 21 Dec 2023 18:36:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08F1A745CD; Thu, 21 Dec 2023 18:35:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="WarMWAg0" X-Original-To: linux-kernel@vger.kernel.org Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B97F76280C for ; Thu, 21 Dec 2023 18:35:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev 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=1703183747; 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=9xuoTXuQnTI+pN/bKZ3i8KybAohyAUoP+IGmtMicRak=; b=WarMWAg0K7SHak78ygWtlpgqTMwt7mumTYTiIrRXvERxbmLV9b2mB09CJkEoY/kvKqecGT LJD1Iz9YrXuxQjpfGtqzVdMCmE1Di3rxLYHjeVLXbJ+cka5BV4sF8NvnLlPNSEtQ8xSxsE gYC+xeKuS4JVZvylLWKrrqmi4VV2GMA= From: andrey.konovalov@linux.dev To: Andrew Morton , Juntong Deng Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 2/4] kasan: reuse kasan_track in kasan_stack_ring_entry Date: Thu, 21 Dec 2023 19:35:38 +0100 Message-Id: <20231221183540.168428-2-andrey.konovalov@linux.dev> In-Reply-To: <20231221183540.168428-1-andrey.konovalov@linux.dev> References: <20231221183540.168428-1-andrey.konovalov@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785917679033489252 X-GMAIL-MSGID: 1785917679033489252 From: Andrey Konovalov Avoid duplicating fields of kasan_track in kasan_stack_ring_entry: reuse the structure. Fixes: 5d4c6ac94694 ("kasan: record and report more information") Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- mm/kasan/kasan.h | 7 +------ mm/kasan/report_tags.c | 12 ++++++------ mm/kasan/tags.c | 12 ++++++------ 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 5e298e3ac909..9072ce4c1263 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -279,13 +279,8 @@ struct kasan_free_meta { struct kasan_stack_ring_entry { void *ptr; size_t size; - u32 pid; - depot_stack_handle_t stack; + struct kasan_track track; bool is_free; -#ifdef CONFIG_KASAN_EXTRA_INFO - u64 cpu:20; - u64 timestamp:44; -#endif /* CONFIG_KASAN_EXTRA_INFO */ }; struct kasan_stack_ring { diff --git a/mm/kasan/report_tags.c b/mm/kasan/report_tags.c index 979f284c2497..688b9d70b04a 100644 --- a/mm/kasan/report_tags.c +++ b/mm/kasan/report_tags.c @@ -31,8 +31,8 @@ static const char *get_common_bug_type(struct kasan_report_info *info) static void kasan_complete_extra_report_info(struct kasan_track *track, struct kasan_stack_ring_entry *entry) { - track->cpu = entry->cpu; - track->timestamp = entry->timestamp; + track->cpu = entry->track.cpu; + track->timestamp = entry->track.timestamp; } #endif /* CONFIG_KASAN_EXTRA_INFO */ @@ -80,8 +80,8 @@ void kasan_complete_mode_report_info(struct kasan_report_info *info) if (free_found) break; - info->free_track.pid = entry->pid; - info->free_track.stack = entry->stack; + info->free_track.pid = entry->track.pid; + info->free_track.stack = entry->track.stack; #ifdef CONFIG_KASAN_EXTRA_INFO kasan_complete_extra_report_info(&info->free_track, entry); #endif /* CONFIG_KASAN_EXTRA_INFO */ @@ -98,8 +98,8 @@ void kasan_complete_mode_report_info(struct kasan_report_info *info) if (alloc_found) break; - info->alloc_track.pid = entry->pid; - info->alloc_track.stack = entry->stack; + info->alloc_track.pid = entry->track.pid; + info->alloc_track.stack = entry->track.stack; #ifdef CONFIG_KASAN_EXTRA_INFO kasan_complete_extra_report_info(&info->alloc_track, entry); #endif /* CONFIG_KASAN_EXTRA_INFO */ diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c index c13b198b8302..c4d14dbf27c0 100644 --- a/mm/kasan/tags.c +++ b/mm/kasan/tags.c @@ -100,8 +100,8 @@ static void save_extra_info(struct kasan_stack_ring_entry *entry) u32 cpu = raw_smp_processor_id(); u64 ts_nsec = local_clock(); - entry->cpu = cpu; - entry->timestamp = ts_nsec >> 3; + entry->track.cpu = cpu; + entry->track.timestamp = ts_nsec >> 3; } #endif /* CONFIG_KASAN_EXTRA_INFO */ @@ -134,15 +134,15 @@ static void save_stack_info(struct kmem_cache *cache, void *object, if (!try_cmpxchg(&entry->ptr, &old_ptr, STACK_RING_BUSY_PTR)) goto next; /* Busy slot. */ - old_stack = entry->stack; + old_stack = entry->track.stack; entry->size = cache->object_size; - entry->pid = current->pid; - entry->stack = stack; - entry->is_free = is_free; + entry->track.pid = current->pid; + entry->track.stack = stack; #ifdef CONFIG_KASAN_EXTRA_INFO save_extra_info(entry); #endif /* CONFIG_KASAN_EXTRA_INFO */ + entry->is_free = is_free; entry->ptr = object;