Received: by 2002:a05:7412:e79e:b0:f3:1519:9f41 with SMTP id o30csp210080rdd; Wed, 22 Nov 2023 13:37:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IH72LJrlSjRJJCsU9Vl8Di+RekVO8larQdFIZYMbtoB0mCZ3V9kTO1iHbzz5y8UZsra79cm X-Received: by 2002:a17:90b:3891:b0:26d:2b86:dbe1 with SMTP id mu17-20020a17090b389100b0026d2b86dbe1mr4151383pjb.25.1700689033977; Wed, 22 Nov 2023 13:37:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700689033; cv=pass; d=google.com; s=arc-20160816; b=im0reN9W5loWJerTgjk6pj6JXUVlXU+BXuv7zAew4DK0DdCoFa7d+mne/31iWEC9bX FnKA7P4kvoPxJ94Lc8E6DsazbmZhaStVjrSRwTW1+4tkUSj4Y49QbvMOBGnP1u+kjT5B BMxbrILS2nxfLr21mNA+2nOGSecpIxEa966OdSOjAMOa+rXepLKYZVh0vkNFXeWUoRuJ +YXDotrN+vPdRR3Z+Ap5aLKvFKgTDP25r7OsLAmR3GVN5oHJsPA+M2DowLd+emgIwUO5 f56E8Ox+X5UgjMeSS9IQPwX1T0+t1Q8HbjwIX5e+R+CyZCOncOhSUzV9lfExHy8P/eTc kXAg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:subject:user-agent:date :message-id:dkim-signature; bh=OSqcW9CLX5X/DMZdqxALz09AR/LoG2nzJ0XH/yk6QwU=; fh=ZPR0T8cST3w7zq2qt1LodueNlO+CD3oD3KyLDysf0ds=; b=zdQ3bAypa6rq5UjS29h7ppxYyGf4w0A4Mn199pY2uxlRPFLNfV9Tp8qWys7ai/3jhk QKVhbjsJUyUyFrbdvmV2Nt7pOvllbVjKWfzU+Dw+o/nB97lDh5wNKkqwYtD85mc7dYbQ sBeSTT7G6ewwo+NusU+K9Ei80N1TONAshzrRs9cJmQiwYtsg9JC/5kQm0nZL1I9mBlj7 vQK70L6a/pH30gb05vKJvZUlad2rF8K45af6H/4FcV0rIIkWXyLloWTGa/A8AOVNdYoo R91n6HjQ0f9J+Ik+PZ4HN5IZ7cb3llklA3BKLiXtbQgoPVscyjAbMN8MFQgQudGZPKHY wOlQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=t4hJeKLH; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id f20-20020a17090ace1400b002802950ea02si375641pju.170.2023.11.22.13.37.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 13:37:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=t4hJeKLH; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 2D18A827A76F; Wed, 22 Nov 2023 13:36:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235176AbjKVVgS (ORCPT + 99 others); Wed, 22 Nov 2023 16:36:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235173AbjKVVgQ (ORCPT ); Wed, 22 Nov 2023 16:36:16 -0500 Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02olkn2065.outbound.protection.outlook.com [40.92.50.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E028D42 for ; Wed, 22 Nov 2023 13:36:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CMtbjaaU9gJXbHUlxBzoNrHU+4xL9zEMSW9HTzVcrTJLNvY6KZWmnP7M+gkjrZx64pC/ZoalkLIn69VwF5xvdGbcZwxiIlCQoqR0K6fSzuYFDAMWsYSRCA7plpiDby4cnVcIKMRuLgXxaD3RPgpxNXM3MRlgPGcIhfPx9N+ys/J1vy2mCbsnEvWKUoeVhFoEjYi8d+n6l+FxUvH1f6YriEEivir5CVrFDpOX7Sl4nuRDmoSFGm2pwpkW161wuWzY8ppaaEBjbScI+JbkV2cHTnmyOMkbVOizIRjRrW4t9gwbPNk743ZG23PWH1fcK2CB8JJrwocubGxugur2KofzmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OSqcW9CLX5X/DMZdqxALz09AR/LoG2nzJ0XH/yk6QwU=; b=eRsxFHV9oVsAy0GlJYXINc9HQgE4/L6m7SBuGePpeeqS9LQv1l3plISoenvF/efW58ZE6yRUFgNnvftCFIJtdw2VMkkCMAooyGVA+dOewimMoDmhxP94iXsNs9lFdww2JMnvqEa2A7R4Z3JKP9jkh/snsEhbEyUR8yUYJ7LSRPId3ANYPcbsa9PS4Fxycx8iuW35T2fDEmP3nQYrluL9fdSpYm6H+oXHo4I4v9+C1sKiWuKLKosgk4AC1/OyOQzSzlDe1m0GebKWosK4upSOewqJOGUFqiA6NC0l+GxouVi50ldpe7F+JYdwZTrxeWxW3h18BScrSuGhNJSl6PhUEg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OSqcW9CLX5X/DMZdqxALz09AR/LoG2nzJ0XH/yk6QwU=; b=t4hJeKLH87rahXjf8IQgV+sh+75EXG8a2rdKE/hvMZ4FeKS2IMWaH8RayOAlNLqigt3dt/wtF24k4ylPgY4+mitcwRwlaTVyU2djtmY/NX16dK/x8AHRzfy6zyyHkzAvKzjNzwEI0K0uP7jHi/FBmVjLncUKkHgj0HPwF8GQtyW+IYCueNDyaHf2xyxqP7vXqiwgQ1tVPbich4feZRMybruZENYEdapsnEPzHabEQ1KrEfgazCbWXUQDaNV8Nkr7A2XFRSOqJKhI9wJ4U3fSfwdB11mejixaX29CNImHWgcbPQ1v728s5u5k54UtUPKbLmQt2X3B6cgZr/6iyoEmfA== Received: from VI1P193MB0752.EURP193.PROD.OUTLOOK.COM (2603:10a6:800:32::19) by AM8P193MB1041.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:1ef::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.20; Wed, 22 Nov 2023 21:36:09 +0000 Received: from VI1P193MB0752.EURP193.PROD.OUTLOOK.COM ([fe80::fdd2:7dbf:e16c:f4a4]) by VI1P193MB0752.EURP193.PROD.OUTLOOK.COM ([fe80::fdd2:7dbf:e16c:f4a4%5]) with mapi id 15.20.7025.020; Wed, 22 Nov 2023 21:36:09 +0000 Message-ID: Date: Thu, 23 Nov 2023 05:36:08 +0800 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] kfence: Replace local_clock() with ktime_get_boot_fast_ns() To: Marco Elver Cc: glider@google.com, dvyukov@google.com, akpm@linux-foundation.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org References: From: Juntong Deng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TMN: [ARpD+7jaLWsVwXQ6CNIBsaM+1KFXvjcn] X-ClientProxiedBy: LO4P265CA0227.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:315::13) To VI1P193MB0752.EURP193.PROD.OUTLOOK.COM (2603:10a6:800:32::19) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1P193MB0752:EE_|AM8P193MB1041:EE_ X-MS-Office365-Filtering-Correlation-Id: 75cf1ad8-294e-48dd-42db-08dbeba30a65 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pSOu6HuNHaUdDZ78UidPyHkGa76MJPWXToqWn+ul60UQO3Foa4OJzLNUv6Ge6F03/J5enoKoXSvhh4XQfKZsTCWhxmU184lX4rUDKWaBaIH56yxwuZm+3BwHkym9XnxidS3KOUEETK1YNTKyt9JOuPPU4Orn+ZDdJSn9V4XNATDD8F70KWFxsZcXCB0goGl4KaPX+s+uYnwXoScw9VLze8YyojweqLC7drOV04u6w/8itmvevidayUljMA/AzNi0Mjh+igB/D2ID2v0utv6iyBMZ+CC1th+jTEsPFzpTK2wqp2KZ6tS5aW5GnoBGO8fnGPF62xxSnLLLpAxhkdcXaAYc2q2sbhiObG9WCvWwBYYgRITSGe1kG6tEIuACFG5lIuyLpF/0Yq2w1dEvKUulsZuHTKlBwcf5LXKGwCR7Zlx/FSbapfOGx9bKm4oXBM+n9YgfSDKzQFIfo4jYpJDQeSaxcg6cDKFaGMnDgzPTVKYRF59t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csL80oc=3D?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75cf1ad8-294e-48dd-42db-08dbeba30a65 X-MS-Exchange-CrossTenant-AuthSource: VI1P193MB0752.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2023 21:36:09.2508 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8P193MB1041 X-Spam-Status: No, score=1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FORGED_MUA_MOZILLA,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 22 Nov 2023 13:36:29 -0800 (PST) On 2023/11/23 4:35, Marco Elver wrote: > On Wed, 22 Nov 2023 at 21:01, Juntong Deng wrote: >> >> The time obtained by local_clock() is the local CPU time, which may >> drift between CPUs and is not suitable for comparison across CPUs. >> >> It is possible for allocation and free to occur on different CPUs, >> and using local_clock() to record timestamps may cause confusion. > > The same problem exists with printk logging. > >> ktime_get_boot_fast_ns() is based on clock sources and can be used >> reliably and accurately for comparison across CPUs. > > You may be right here, however, the choice of local_clock() was > deliberate: it's the same timestamp source that printk uses. > > Also, on systems where there is drift, the arch selects > CONFIG_HAVE_UNSTABLE_SCHED_CLOCK (like on x86) and the drift is > generally bounded. > >> Signed-off-by: Juntong Deng >> --- >> mm/kfence/core.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/mm/kfence/core.c b/mm/kfence/core.c >> index 3872528d0963..041c03394193 100644 >> --- a/mm/kfence/core.c >> +++ b/mm/kfence/core.c >> @@ -295,7 +295,7 @@ metadata_update_state(struct kfence_metadata *meta, enum kfence_object_state nex >> track->num_stack_entries = num_stack_entries; >> track->pid = task_pid_nr(current); >> track->cpu = raw_smp_processor_id(); >> - track->ts_nsec = local_clock(); /* Same source as printk timestamps. */ >> + track->ts_nsec = ktime_get_boot_fast_ns(); > > You have ignored the comment placed here - now it's no longer the same > source as printk timestamps. I think not being able to correlate > information from KFENCE reports with timestamps in lines from printk > is worse. > > For now, I have to Nack: Unless you can prove that > ktime_get_boot_fast_ns() can still be correlated with timestamps from > printk timestamps, I think this change only trades one problem for > another. > > Thanks, > -- Marco Honestly, the possibility of accurately matching a message in the printk log by the timestamp in the kfence report is very low, since allocation and free do not directly correspond to a certain event. Since time drifts across CPUs, timestamps may be different even if allocation and free can correspond to a certain event. If we really need to find the relevant printk logs by the timestamps in the kfence report, all we can do is to look for messages that are within a certain time range. If we are looking for messages in a certain time range, there is not much difference between local_clock() and ktime_get_boot_fast_ns(). Also, this patch is in preparation for my next patch. My next patch is to show the PID, CPU number, and timestamp when the error occurred, in this case time drift from different CPUs can cause confusion. For example, use-after-free caused by a subtle race condition, in which the time between the free and the error occur will be very close. Time drift from different CPUs may cause it to appear in the report that the error timestamp precedes the free timestamp.