From mboxrd@z Thu Jan 1 00:00:00 1970 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