Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp357015lql; Mon, 11 Mar 2024 05:07:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUMwt1zabXYK7Ell8vqaLPV3BpJ2gSIRYZ8DBjoSDk3xALKUKcdAuvOL2Cpxdw4wXdgZ7JirqxiRWG21eFlF1m39tFKQA1jXcI4gyCZ0w== X-Google-Smtp-Source: AGHT+IHp8iQ/2aCj1C4KbfT/FnxKZPXBxp29eOn4Ny+mPFHxWfQ6s5wK6JjpH/0xOXOJzhzioeu0 X-Received: by 2002:a6b:fb19:0:b0:7c8:60a6:5bda with SMTP id h25-20020a6bfb19000000b007c860a65bdamr6965914iog.17.1710158838197; Mon, 11 Mar 2024 05:07:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710158838; cv=pass; d=google.com; s=arc-20160816; b=f29l8ecEtWA1DC6eMaMyT9ULhDq/d+T/e2iO1ReJu048Qa8nBgvnYdkBmPV5Y29/h2 asSle6fVGXVB7XNyHwIRWGrxoKZ+D7MzHq8OUT1EoGB/KPesV60+sc6wrEM5AMqUsdUc 4eS40K6ASwJLJnByXaUUkLfPo0VRMw7vDFPHK9/keSFM1CXW3YdHOdjUCULlyIrPG7b3 CtSW1kLwXdBwamdpWKAgsx/Wc/31+gYZ+xIWiaRWIjVJ4J8Ind3TcH+D23rnhFksnxZM rEwFBzI107SroJ16hwaghOaoft0KT5/eug+Q3tbZExPZNwk0qJwRhucocxf8Sdlt4P74 SfgQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=t+uehrKRpiH38VA174uD5qYjpsJHrPQAuUj7YG5ipCE=; fh=nyRikoTzNy8VPjvlG2UwB5Xu+O+PdwODPYw0IW1inkc=; b=NsAYRderHMGqSywy5yju3+Lu819jhzmZ1o6I00TrUxoida+GfG+EfxoYIN/B4IECvc 1sUMzMHnF5tt6z1+CyKbM9ffnoF1PZWrMp56DqjcJ5I5Mw4wRDJDLu+VsH/Li+NwR6Hi 6eYs96mEDr1M8H4q5m1gRryR0mcJzJM+d6fnEh0knLFzNVL8yt/w+jJnTyak3sa4HMtz nIrAOTjTZlnVvaDs6ueHZJ77lKXyUyy06XhMtVTfdARSdIUN9Z2RixFL6rxJbu/cDSJy wfMSEOT8Kanh7ysk/8sctKBMU38abf5jtIn2N60hKb88f5PsbUH9b1uJXRAVnZHrnIcf /7hQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-98800-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98800-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m66-20020a632645000000b005dc351748d1si4910002pgm.660.2024.03.11.05.07.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 05:07:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-98800-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-98800-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98800-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com 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 B8237283952 for ; Mon, 11 Mar 2024 12:07:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8CF583BBFD; Mon, 11 Mar 2024 12:07:12 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 6648B3B78E for ; Mon, 11 Mar 2024 12:07:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710158832; cv=none; b=pkhl1Lbz5k6DVRiDalzU7qsMuH3LsFaw+8LE0Q5Nm0gF3bcyESYwbsSfRF2aZGkx4DN31sV+fyLmx96WAHnr3YLsvR1zS4tTxRDzmjVaTJ9ujTuZFNkaS3bsTXR55tI1RCBc3CiLRmJOkq5pjEatmEKDejLATOAHhZdwhmdDMow= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710158832; c=relaxed/simple; bh=B+m2Bjcxx1YSgN6LpD3F3IefXoQbz8pZeaCQuEGQC7o=; h=Date:From:To:CC:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XlYQwZ2S6UvDnvlXonAQ/msLmzAmmnp7ntymTdiZFOSnfklg7dKbUeI44lMZs2cDbd0kc2Di0iY/CHWE49vYposKasgPg2pIGFqVh4zVnakPQTdtkiYYW++qvdMbeWQfEOM7C0sqeR1v1yH60YON2M/6fJlh/bsgbBqIdK0eias= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Ttb7K0DgjzsXKF; Mon, 11 Mar 2024 20:05:01 +0800 (CST) Received: from kwepemd100011.china.huawei.com (unknown [7.221.188.204]) by mail.maildlp.com (Postfix) with ESMTPS id 808DA1400F4; Mon, 11 Mar 2024 20:07:05 +0800 (CST) Received: from M910t (10.110.54.157) by kwepemd100011.china.huawei.com (7.221.188.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 11 Mar 2024 20:07:03 +0800 Date: Mon, 11 Mar 2024 20:06:59 +0800 From: Changbin Du To: Mark Rutland CC: Changbin Du , Ingo Molnar , Andrew Morton , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , , , Alexander Potapenko , , Marco Elver Subject: Re: [PATCH] mm: kmsan: fix instrumentation recursion on preempt_count Message-ID: <20240311120659.2la4s5vwms5jebut@M910t> References: <20240311112330.372158-1-changbin.du@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100011.china.huawei.com (7.221.188.204) On Mon, Mar 11, 2024 at 11:42:29AM +0000, Mark Rutland wrote: > On Mon, Mar 11, 2024 at 07:23:30PM +0800, Changbin Du wrote: > > This disables msan check for preempt_count_{add,sub} to fix a > > instrumentation recursion issue on preempt_count: > > > > __msan_metadata_ptr_for_load_4() -> kmsan_virt_addr_valid() -> > > preempt_disable() -> __msan_metadata_ptr_for_load_4() > > > > With this fix, I was able to run kmsan kernel with: > > o CONFIG_DEBUG_KMEMLEAK=n > > o CONFIG_KFENCE=n > > o CONFIG_LOCKDEP=n > > > > KMEMLEAK and KFENCE generate too many false positives in unwinding code. > > LOCKDEP still introduces instrumenting recursions issue. But these are > > other issues expected to be fixed. > > > > Cc: Marco Elver > > Signed-off-by: Changbin Du > > --- > > kernel/sched/core.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > > index 9116bcc90346..5b63bb98e60a 100644 > > --- a/kernel/sched/core.c > > +++ b/kernel/sched/core.c > > @@ -5848,7 +5848,7 @@ static inline void preempt_latency_start(int val) > > } > > } > > > > -void preempt_count_add(int val) > > +void __no_kmsan_checks preempt_count_add(int val) > > { > > #ifdef CONFIG_DEBUG_PREEMPT > > /* > > @@ -5880,7 +5880,7 @@ static inline void preempt_latency_stop(int val) > > trace_preempt_on(CALLER_ADDR0, get_lock_parent_ip()); > > } > > What prevents a larger loop via one of the calles of preempt_count_{add,sub}() > > For example, via preempt_latency_{start,stop}() ? > > ... or via some *other* instrumentation that might be placed in those? > > I suspect we should be using noinstr or __always_inline in a bunch of places to > clean this up properly. > In my local build, these two are not that small for inlining. (I has preempt_off tracer enabled). $ readelf -s vmlinux | grep -sw -E 'preempt_count_add|preempt_count_sub' 157043: ffffffff81174de0 186 FUNC GLOBAL DEFAULT 1 preempt_count_add 157045: ffffffff81174eb0 216 FUNC GLOBAL DEFAULT 1 preempt_count_sub The noinstr adds __no_sanitize_memory to the tagged functions so we might see many false positives. > Mark. -- Cheers, Changbin Du