From patchwork Mon Nov 28 09:45:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 13057206 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78225C43217 for ; Mon, 28 Nov 2022 09:45:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E07F96B0072; Mon, 28 Nov 2022 04:45:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DB7FD6B0073; Mon, 28 Nov 2022 04:45:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA7506B0074; Mon, 28 Nov 2022 04:45:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id BB3E26B0072 for ; Mon, 28 Nov 2022 04:45:47 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 85179C0CB4 for ; Mon, 28 Nov 2022 09:45:47 +0000 (UTC) X-FDA: 80182369134.23.89178D4 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) by imf22.hostedemail.com (Postfix) with ESMTP id 06164C0008 for ; Mon, 28 Nov 2022 09:45:46 +0000 (UTC) Received: by mail-ed1-f73.google.com with SMTP id f17-20020a056402355100b00466481256f6so6276960edd.19 for ; Mon, 28 Nov 2022 01:45:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=rXoOet1Rb1vO+RV0XEBtCtgaydxMI/engJANIwuECRQ=; b=s6w1xbIf2vlYUmSknr7oRraUB85nf4lYbLpqHtE7R/uCCqK/YnX+XJ9uS2gmJ6EfSy WC3rIcgYxlJav7Y0J/sxRNoZa4e7zOpW5Pab30yV6YSdxovSZhHEQa+NVRLP8hkETK4O 6xWCrhsjeg4dEgQ2Uyr/UbXf2G5Ql3Tvr+GtnFm8cARQJPnSKqhRpB68cZ0zzU6hYpMI TDcudtbdB+cg27Z0lGhN4n88RSV9kqLIMMgDW5leYNMZG4GEDv1J/ZlQuk/hm3AAZjfE UYGRAKSaGz2kKfqLvXtVQaNO+vPQS76GptQqpktijCNM6SDr2GTU81PuaYL3NZ69Igxe O1iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=rXoOet1Rb1vO+RV0XEBtCtgaydxMI/engJANIwuECRQ=; b=O8Oa5VHLOjxhd9BkgVN9X5V77sXiJ5eWY8bgdJj3liPsSz/DVhwKKp6EBj44JJ4WHx b97GHI9Q/T0dOuUr8IcznPr02zGBVwn5cdu+gCp76xWNEqVU2yOfBWwE+AylGn5jjKxs ZuwvKgYHDEfuR8/2sbon/syz+FMBl6zxfFoe8kcxKmunZZDoEEcnngIWW8zz640UANtf g6hSxb2VFW5cNXvfccN+ZF6oiCHZ4upBsV4/gbIn4F4XL1EbPegDlsFlWZUR/EGgCF/l QPellr9MyVm8U7AtwASVBAuWy6ypThXAVPV4Ef8gowI1xfp/gSOaSQLAtatcBvMvoFGz XzEw== X-Gm-Message-State: ANoB5pld9DpbdTp/gPn831GoEcsVpQe1eOgHJ33ARobCSjBPD9rV6GXG UX8bPdAmfzwQPIqHBzP8uvMFLZf/To0= X-Google-Smtp-Source: AA0mqf5JjgMUAXNrjyuEcpH5yC8Dqz2bfrGhmUj8weFzLuPbv1iNyji1PfDPUp5njvuDbzAg0khDIxsb0Ro= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:dc07:26e3:1eb7:b279]) (user=glider job=sendgmr) by 2002:aa7:de08:0:b0:46a:e4e0:8407 with SMTP id h8-20020aa7de08000000b0046ae4e08407mr10060697edv.36.1669628745543; Mon, 28 Nov 2022 01:45:45 -0800 (PST) Date: Mon, 28 Nov 2022 10:45:40 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221128094541.2645890-1-glider@google.com> Subject: [PATCH 1/2] lockdep: allow instrumenting lockdep.c with KMSAN From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, peterz@infradead.org, mingo@redhat.com, will@kernel.org, elver@google.com, dvyukov@google.com, linux-mm@kvack.org, kasan-dev@googlegroups.com, Eric Biggers ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=s6w1xbIf; spf=pass (imf22.hostedemail.com: domain of 3SYOEYwYKCIQotqlmzowwotm.kwutqv25-uus3iks.wzo@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3SYOEYwYKCIQotqlmzowwotm.kwutqv25-uus3iks.wzo@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669628747; a=rsa-sha256; cv=none; b=iTyhdL47saLJbt6McB9ukTDkFdUaAAjUxHt03uOJLFMnaTfj7rhu5k8YTbtYP9DI9QSah/ xtnwvkk0mfIj/sXHgJzH6/eXTdo1zaa8xQU1QJrCRLuTl3SxXHNhsCinWzj0tVVTq5JBis lmxossrgH7OMPDUFtDK2x+uPhElEmCQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669628747; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=rXoOet1Rb1vO+RV0XEBtCtgaydxMI/engJANIwuECRQ=; b=q9CnORG+lj/TmyEyTd/AOliULbNYR+r6zlKWurJBRbY/qHiovZfjjlgluDx/VT781zFjKw 1rJgdQfr2oLOHd1G40VYuxePdwXsaCHgKXiLjqzrn56UfSF6jUM1ZrJ54yQmdjPci3rDVn BukFheJovQGMq+1mwEkUYYcvBx984K0= X-Rspamd-Queue-Id: 06164C0008 X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=s6w1xbIf; spf=pass (imf22.hostedemail.com: domain of 3SYOEYwYKCIQotqlmzowwotm.kwutqv25-uus3iks.wzo@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3SYOEYwYKCIQotqlmzowwotm.kwutqv25-uus3iks.wzo@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam02 X-Stat-Signature: ffrb5faii59zn3bjjuqmcrnxz436axb5 X-HE-Tag: 1669628746-97548 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Lockdep and KMSAN used to play badly together, causing deadlocks when KMSAN instrumentation of lockdep.c called lockdep functions recursively. Looks like this is no more the case, and a kernel can run (yet slower) with both KMSAN and lockdep enabled. This patch should fix false positives on wq_head->lock->dep_map, which KMSAN used to consider uninitialized because of lockdep.c not being instrumented. Link: https://lore.kernel.org/lkml/Y3b9AAEKp2Vr3e6O@sol.localdomain/ Reported-by: Eric Biggers Signed-off-by: Alexander Potapenko --- kernel/locking/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/locking/Makefile b/kernel/locking/Makefile index ea925731fa40f..0db4093d17b8a 100644 --- a/kernel/locking/Makefile +++ b/kernel/locking/Makefile @@ -7,7 +7,6 @@ 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 ifdef CONFIG_FUNCTION_TRACER CFLAGS_REMOVE_lockdep.o = $(CC_FLAGS_FTRACE) From patchwork Mon Nov 28 09:45:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 13057207 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 860DEC433FE for ; Mon, 28 Nov 2022 09:51:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 245596B0072; Mon, 28 Nov 2022 04:51:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 21B7F6B0073; Mon, 28 Nov 2022 04:51:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E6666B0074; Mon, 28 Nov 2022 04:51:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E870F6B0072 for ; Mon, 28 Nov 2022 04:51:02 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BBFD0A0C1C for ; Mon, 28 Nov 2022 09:51:02 +0000 (UTC) X-FDA: 80182382364.04.56379F8 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf23.hostedemail.com (Postfix) with ESMTP id 4D14514000C for ; Mon, 28 Nov 2022 09:51:01 +0000 (UTC) Received: by mail-wm1-f73.google.com with SMTP id z18-20020a05600c221200b003cf7fcc286aso3549281wml.1 for ; Mon, 28 Nov 2022 01:51:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Cct04cXs5K6Oma9vXfMm60p6i+CfzdxpxLX+V58OiqQ=; b=F8rWO4eEUv81PuSKtmYCtH6WPMr3pJLLQVDBUG+mf3OIy/GgnIfAfRBTjQOuF0NZgI rQCvXESuwjsM+T6ALxE15HiEcWvtzdF69PXuMMgl9Gp8SOqnwRANXg4WM8IESG8AGx+s edceQgh2LwiydLOf165rabsPFjFB86SOAH4c/BT53evJVpZn4lRm6K5ImDhjrnhFx4Of XIQSsEb6/zUJG5A4gX+KMJ0FUtrijmXIqWZFaH/WZmcDXYjJU491FhbK5snqi54h7p/V 37ylxNxeU1MNJLXAM5OGWTPcUV0xqWEL7LQAoqOZ4ol27gM4g+vEdJinXsOfbPbuXFPD MJEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Cct04cXs5K6Oma9vXfMm60p6i+CfzdxpxLX+V58OiqQ=; b=c6m6UFkY7CA5GpnIrXDPsPay7qxMxa/jxnUra+D+4yxkW31fA8l8C0qJwB9PiVTiJe OmtCSRFuJ27uDnT09CiFhh4hEdztKTrjh24MSsJ3rn8x1SAL3bscq1/Bkm9aDjufzfEN +2+XLSkmYaZeiE5fLQyV0ZAk/w9n1IhKflJ4ympLUF2pTlrG9jtG+gOz9azK6+KUt44D erAeaW33XYf/9W0m/zELiLVfgidDcjtig+IjWjCR0Ze/ifJfYQJavVsqqIQ562EyD3nC 5pRPePpHsOuFme7hXdU5GEIL17juzK2KikkxHAVx3+xDpXVqZ4jwZ+k7JX1anwiqLGGF h+uw== X-Gm-Message-State: ANoB5pnN4sN8htycxYxR5Xw/F4sxg2bA8E7crtLncz2z3XUqt60Xj8Zg rM/dP5fF1slfld79E7YzAfMGuq3kc5Y= X-Google-Smtp-Source: AA0mqf47reGLvqtfhUicf3SwZLCRiQSU8ElrY3uGc5tGFXHC/qU5NVNZWlAkGfegPCyHFwdpnlPxg1K7kmE= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:dc07:26e3:1eb7:b279]) (user=glider job=sendgmr) by 2002:a5d:6dcf:0:b0:236:78b7:87c9 with SMTP id d15-20020a5d6dcf000000b0023678b787c9mr30120679wrz.556.1669629060947; Mon, 28 Nov 2022 01:51:00 -0800 (PST) Date: Mon, 28 Nov 2022 10:45:41 +0100 In-Reply-To: <20221128094541.2645890-1-glider@google.com> Mime-Version: 1.0 References: <20221128094541.2645890-1-glider@google.com> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221128094541.2645890-2-glider@google.com> Subject: [PATCH 2/2] kmsan: allow using __msan_instrument_asm_store() inside runtime From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, peterz@infradead.org, mingo@redhat.com, will@kernel.org, elver@google.com, dvyukov@google.com, linux-mm@kvack.org, kasan-dev@googlegroups.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669629062; a=rsa-sha256; cv=none; b=gsrRbQQcoeSHr/cX+JvBvwfII6zwnihIQLm9RJe02Z356Fnf8IkBDWlFz8VoknuyWsZjwp tJCv/kIoQ6/NA4/jq28koNEauhzrJuHj41IMHGlqNhRcqPPCG1TEbnmQThMnCmmkFrDrvC a5h/MD7GuvtxWX387DekPY/OReWGoog= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=F8rWO4eE; spf=pass (imf23.hostedemail.com: domain of 3hISEYwYKCMEnspklynvvnsl.jvtspu14-ttr2hjr.vyn@flex--glider.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3hISEYwYKCMEnspklynvvnsl.jvtspu14-ttr2hjr.vyn@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669629062; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Cct04cXs5K6Oma9vXfMm60p6i+CfzdxpxLX+V58OiqQ=; b=1CSANFJa+eKCaR/7hmpFqCROEClEqk+BDsG5An0k0GfQ7LgWUTHYrMW9Oyca1feeQAoXVB dfiJRyfOlm6A+TfYTkzsRrjbuj8eNb9zcD6Yx25Beu0QUj3KOjxhwf128TbxE/BiK9tVI0 Td4iyyjkyuV6g+zq/MpIXWCAb6/4zSw= X-Stat-Signature: aagdm7qsdgd1yi5w7z39b598zqki3r3f X-Rspamd-Queue-Id: 4D14514000C X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=F8rWO4eE; spf=pass (imf23.hostedemail.com: domain of 3hISEYwYKCMEnspklynvvnsl.jvtspu14-ttr2hjr.vyn@flex--glider.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3hISEYwYKCMEnspklynvvnsl.jvtspu14-ttr2hjr.vyn@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam10 X-HE-Tag: 1669629061-886477 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In certain cases (e.g. when handling a softirq) __msan_instrument_asm_store(&var, sizeof(var)) may be called with from within KMSAN runtime, but later the value of @var is used with !kmsan_in_runtime(), leading to false positives. Because kmsan_internal_unpoison_memory() doesn't take locks, it should be fine to call it without kmsan_in_runtime() checks, which fixes the mentioned false positives. Signed-off-by: Alexander Potapenko --- mm/kmsan/instrumentation.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/kmsan/instrumentation.c b/mm/kmsan/instrumentation.c index 271f135f97a16..770fe02904f36 100644 --- a/mm/kmsan/instrumentation.c +++ b/mm/kmsan/instrumentation.c @@ -81,12 +81,16 @@ DECLARE_METADATA_PTR_GETTER(8); * Handle a memory store performed by inline assembly. KMSAN conservatively * attempts to unpoison the outputs of asm() directives to prevent false * positives caused by missed stores. + * + * __msan_instrument_asm_store() may be called for inline assembly code when + * entering or leaving IRQ. We omit the check for kmsan_in_runtime() to ensure + * the memory written to in these cases is also marked as initialized. */ void __msan_instrument_asm_store(void *addr, uintptr_t size) { unsigned long ua_flags; - if (!kmsan_enabled || kmsan_in_runtime()) + if (!kmsan_enabled) return; ua_flags = user_access_save(); @@ -103,10 +107,8 @@ void __msan_instrument_asm_store(void *addr, uintptr_t size) user_access_restore(ua_flags); return; } - kmsan_enter_runtime(); /* Unpoisoning the memory on best effort. */ kmsan_internal_unpoison_memory(addr, size, /*checked*/ false); - kmsan_leave_runtime(); user_access_restore(ua_flags); } EXPORT_SYMBOL(__msan_instrument_asm_store);