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);