Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp435251lqc; Fri, 8 Mar 2024 01:40:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUDEc0x8Ooh7kAPVfYpIxW3GxfOoBS4oFeAH4cJDmcUmtpp9iTyaYCY9W3Pl9kT1A5G1yCfNSYhzWPgBCAaT6x9vhe+xYNTQ1YXDZuAzg== X-Google-Smtp-Source: AGHT+IH7yuo87LO9XCaxkumLNa6yH0LPVdFgILzKQWCiAX5t9xRnw9kPP3/weGEl6Ve+ZI+8kXP4 X-Received: by 2002:a17:906:4148:b0:a44:f89:a04e with SMTP id l8-20020a170906414800b00a440f89a04emr15336871ejk.35.1709890804392; Fri, 08 Mar 2024 01:40:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709890804; cv=pass; d=google.com; s=arc-20160816; b=tZdJ5mpiMNVlgaq1YJb9lp8sk4nfKfF6R5CN94quw963fAqLqZphvgX4aS+lK0fchV MBLDzAcF3lPaGL8Z0if5v4hy+6npkHFtKqgeZp1y6g9LBl7aqgj2zLNF8LALKGJJ+8fW 2WX814E8EvoqKjNg/BJPpCY9DG7KqBGrfB0fHr+VRgmVHcc1s8JQdwa4CYEjCdubP4Mo kb/1qbUCrI7dWexT0l0sXfoEombV7XYLLHy7sUxljSTxvRdJZPnUY+cAd6fDuy/RmNil nnCVIPCXZaMqfY288zDkh9G+0L5Bq3zuJx/cFMjkCecqrE61b++Ph41J4E3U/omqy8vz 3Lpg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=Mkn/lM2x4sb3JsolgYFeL1UFRJfnKJyId5+RqBqRGmc=; fh=JZcW3paej+71BF2U88joOmRLyw7HYhUXVTtlAGjdHDw=; b=mtg8UV/9t+5swAydVjyN9JoY4bAD9o5lnY47oIju/BXQ3iJwGHV92asN9qunen0mEb sv5a9shFn3LH/gwiiabMurY7QBTuQBg8LeWkVgkCe6DMdTh42pRYqB4sVQstKMrmNgC6 yyzU9noPpwLtw/JdQchr1QB/GwOBc6ds96WoN9hhIxAzYBDkvtHsa2Wvohkry2ViXJsU 9dK+nJhAN5BONO3fEEmWb7K50NyqQMemG1o8JnpwZntCZ0CV+k0FNEwGMINWbwz2h5aW JyhCizonNCmzJgmhOM3gUGxvWIhq+9XYoQ/V+n3wWriz0OUzOdTIOFco4WwjirJVpHYY U1Hw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0hcmLJXI; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-96756-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96756-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l25-20020a170906a41900b00a4550ea10a2si4427047ejz.704.2024.03.08.01.40.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 01:40:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96756-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0hcmLJXI; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-96756-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96756-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 am.mirrors.kernel.org (Postfix) with ESMTPS id E72C81F243B1 for ; Fri, 8 Mar 2024 09:40:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 443F8535B8; Fri, 8 Mar 2024 09:39:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0hcmLJXI" Received: from mail-ua1-f54.google.com (mail-ua1-f54.google.com [209.85.222.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBBAE22F0F for ; Fri, 8 Mar 2024 09:39:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709890796; cv=none; b=WCQlYt2zC4iNDehonT1fqo/1xsW4I8tYNKV4PFN/BTGQRf2PAdf9fwirU3dLIG44IjfOS7Q10c4fpyFv/ogzWs1JT/tsRPdJw2CloBtp9rALILGZs6MRQTWEOPDxAHWgki8SyVh9Cq7rmFCE+5F8G/F4mk3t3MvA970eKbfB+Bk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709890796; c=relaxed/simple; bh=vtX7LPhamSxcbWntEzmJsAiMyPj5+b2SPq2jCfp7lnc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=raJoy8WKFM9yR8dmcrz5xkP0GZV19k5/XaDmyHr25FierkWNjaddyegHOMmOA5vihCkzeK0PJ06+WRjVqX1PrCGcl8pua3zNEoG4rhwQZ2rPeP89lWJwFspnuwGPm9SKxq7MnWStWl3SMfYPPk3llNsxsOzTA6yWXmLUa8YDnm8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=0hcmLJXI; arc=none smtp.client-ip=209.85.222.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ua1-f54.google.com with SMTP id a1e0cc1a2514c-7db26980225so296935241.0 for ; Fri, 08 Mar 2024 01:39:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709890793; x=1710495593; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Mkn/lM2x4sb3JsolgYFeL1UFRJfnKJyId5+RqBqRGmc=; b=0hcmLJXIrfoPhbKyXlsTI0eKqMuBgCZQ58F621PJn+4o5EOwrTdFpCE2wdzvk3fbW1 PdEMenEhfEB97f9FBcd+ng0K/ip3zKTIb1wTWCl4/WH9EdBosnyiLXGLLvXQdLWCM7uD ll2vCKKV3J0QicFdWmjkVD0oLr41k4wR1+NSOprdRpCOfnVgjcAE5GjNprwcfumpNXwJ rCz+YRH8AsR6nk342CyN13r2DMeX3SwJjMU6b6r6IaQPiBmlUMw3yPuaOXAVd7MTWh7I IOMOwcQEmSd3xIfXEjBZd4XvUAFzeo1ljhLSBSlsYGdzzwpjhM23X996zmwYGq/3IIl+ R/Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709890793; x=1710495593; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Mkn/lM2x4sb3JsolgYFeL1UFRJfnKJyId5+RqBqRGmc=; b=C8pOV4qu6iib4xs+nhL3Hzk1eU5fgeNhUflb69gQyANCdZRuBfZq8OOTG7j7s2Jhkr tN2FxAPYxGWqAFmaPt1X0QhjSr6NcDwiETZ8GVFkbM8ZdRSxQSYi9cMXEcungtEZ4ZK7 3ZPghyUTDtlIMYFYOBlqGZvvRbW9MURAtp1lXd7Y85X+52QMungqR7IwMAz25zEdipC/ uegmsfNoRu4PuCPS4SD9UmSUr+qIVNDaiDKV+4U8AU2rKCWgD6IHaTTIRIQH246p6fMg f8FmoVfkhh8kymfaHDcIgSH8MVWhgJnr8noKVWpBl+wzvz1mlHI+oaxaLXwaYsfqH/Sz oiFA== X-Forwarded-Encrypted: i=1; AJvYcCUkHSvFwd3DYh8RrB0zdJbenjHZ5FWkTl1KQqRjjYsIMi4rafhh57EiASS30IcrtkCr+Xb9a/0B95pW3ziZTecfk6flWIiBGtZrROiS X-Gm-Message-State: AOJu0YyRiJxThCwTV2UHLLdGgGjO3u6b5N/jwSJExp6zIh/rwMt79EDx 7uOJvJSeMFwz4c/sCZfrj44a6s67Uwllg3sBaArIm2UMdZOS7ysOKdzLI853N54ZMSYPKPN+SZX N9g8Ac2M7ZOlkRndaDz/qd5K372EF5m6e/zfv X-Received: by 2002:a05:6122:2703:b0:4d1:34a1:c892 with SMTP id ej3-20020a056122270300b004d134a1c892mr11242267vkb.13.1709890793488; Fri, 08 Mar 2024 01:39:53 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240308043448.masllzeqwht45d4j@M910t> In-Reply-To: <20240308043448.masllzeqwht45d4j@M910t> From: Marco Elver Date: Fri, 8 Mar 2024 10:39:15 +0100 Message-ID: Subject: Re: [BUG] kmsan: instrumentation recursion problems To: Changbin Du Cc: Alexander Potapenko , Andrew Morton , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" On Fri, 8 Mar 2024 at 05:36, 'Changbin Du' via kasan-dev wrote: > > Hey, folks, > I found two instrumentation recursion issues on mainline kernel. > > 1. recur on preempt count. > __msan_metadata_ptr_for_load_4() -> kmsan_virt_addr_valid() -> preempt_disable() -> __msan_metadata_ptr_for_load_4() > > 2. recur in lockdep and rcu > __msan_metadata_ptr_for_load_4() -> kmsan_virt_addr_valid() -> pfn_valid() -> rcu_read_lock_sched() -> lock_acquire() -> rcu_is_watching() -> __msan_metadata_ptr_for_load_8() > > > Here is an unofficial fix, I don't know if it will generate false reports. > > $ git show > commit 7f0120b621c1cbb667822b0f7eb89f3c25868509 (HEAD -> master) > Author: Changbin Du > Date: Fri Mar 8 20:21:48 2024 +0800 > > kmsan: fix instrumentation recursions > > Signed-off-by: Changbin Du > > diff --git a/kernel/locking/Makefile b/kernel/locking/Makefile > index 0db4093d17b8..ea925731fa40 100644 > --- a/kernel/locking/Makefile > +++ b/kernel/locking/Makefile > @@ -7,6 +7,7 @@ obj-y += mutex.o semaphore.o rwsem.o percpu-rwsem.o > > # Avoid recursion lockdep -> sanitizer -> ... -> lockdep. > KCSAN_SANITIZE_lockdep.o := n > +KMSAN_SANITIZE_lockdep.o := n This does not result in false positives? Does KMSAN_ENABLE_CHECKS_lockdep.o := n work as well? If it does, that is preferred because it makes sure there are no false positives if the lockdep code unpoisons data that is passed and used outside lockdep. lockdep has a serious impact on performance, and not sanitizing it with KMSAN is probably a reasonable performance trade-off. > ifdef CONFIG_FUNCTION_TRACER > CFLAGS_REMOVE_lockdep.o = $(CC_FLAGS_FTRACE) > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > index b2bccfd37c38..8935cc866e2d 100644 > --- a/kernel/rcu/tree.c > +++ b/kernel/rcu/tree.c > @@ -692,7 +692,7 @@ static void rcu_disable_urgency_upon_qs(struct rcu_data *rdp) > * Make notrace because it can be called by the internal functions of > * ftrace, and making this notrace removes unnecessary recursion calls. > */ > -notrace bool rcu_is_watching(void) > +notrace __no_sanitize_memory bool rcu_is_watching(void) For all of these, does __no_kmsan_checks instead of __no_sanitize_memory work? Again, __no_kmsan_checks (function-only counterpart to KMSAN_ENABLE_CHECKS_.... := n) is preferred if it works as it avoids any potential false positives that would be introduced by not instrumenting. > { > bool ret; > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 9116bcc90346..33aa4df8fd82 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_sanitize_memory 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()); > } > > -void preempt_count_sub(int val) > +void __no_sanitize_memory preempt_count_sub(int val) > { > #ifdef CONFIG_DEBUG_PREEMPT > > > -- > Cheers, > Changbin Du