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: 26605 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5546660wrr; Mon, 28 Nov 2022 01:56:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf5CATY2EgwFuwBdkD+H17bcYRBJPZrtGW6iIZ2US1TweO64L/m5/2Ik+0i/PfBFTWxf3DoB X-Received: by 2002:a05:6402:71a:b0:46b:1231:5f77 with SMTP id w26-20020a056402071a00b0046b12315f77mr5740797edx.244.1669629396987; Mon, 28 Nov 2022 01:56:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669629396; cv=none; d=google.com; s=arc-20160816; b=inwKczJx9Rx2L6VZriGkv2yZ+cW32F583ifDV423OEvwlhlUZ+dEKSOQ35U4Oh87yo xvCASUejFd4DTXq4awHno0U6zzuUINXUsS+CWy8eibmurxUO7ACT44GFMnF7yFeInymd xhaAS0bb8D7ubCrM5leKAhThOdCITzV8oeZTkgXqSzNLQvAveTqyrovVFT+JIZgIb+1/ F/mqdrf3bRprdGPx3VRIdsS85omGzzL7e14MSOUyVnCwdo3NuH8M+dRTK14/4l8x2xgS d6zxAZNxV9u9ryzvEi5d1iNBDOKSNd9dqTpTrYDTwC/vhUwfDR996T79srX9wt11SBm/ DmYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=Cct04cXs5K6Oma9vXfMm60p6i+CfzdxpxLX+V58OiqQ=; b=b+DrDuDVsuptve74KGt8sHmVGdgmBnWB/SjiKKePs0uO1yB9eq72Qqi3DMYVW5fROm BEdyQpclEEnKmwM5F8ky/ox23XtYA5ibENGtKqdHuCmeN04krj/rrmJb+jH9vYL1pKbt DcaktdxzndE3FQ2QT97kmOQg71wSPe99bSgSWeEluuRC506Ah24dEebfpjI4SCUwjeIV NWoaz7Hf+Efy2pQLKqTqhppOPwX0mHfz+2pHh4zpJLaHdt5k8AeH+MtQey+P9mC4vNGX OAr/0TMIx5wip2Vet7K8MCDIrLU8lRp0vukTBFg9C+ie1sN4dk64v0NHJbn5HNcoh0XM /v/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=F8rWO4eE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w19-20020a05640234d300b004619867344csi11350573edc.0.2022.11.28.01.56.14; Mon, 28 Nov 2022 01:56:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=F8rWO4eE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230043AbiK1JvM (ORCPT + 99 others); Mon, 28 Nov 2022 04:51:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230035AbiK1JvE (ORCPT ); Mon, 28 Nov 2022 04:51:04 -0500 Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 657FE193C3 for ; Mon, 28 Nov 2022 01:51:02 -0800 (PST) Received: by mail-wm1-x349.google.com with SMTP id b47-20020a05600c4aaf00b003d031aeb1b6so8335761wmp.9 for ; Mon, 28 Nov 2022 01:51:02 -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=mGDmE/ZIzLmbxq/WzHItTaSBBn/U36ekDff7uWyEG96Nr1ha1AUzmy/p46yiVpxkic RtQDGqm3qYefO617r9Ge+TP6ltc2+Be81Kp2UINc3esTLFnisFfEUfLgla9YNGUqX4bE JUzuua/De4CoKe2wUct8riYzNm8nLNknxDlQYC5Eh5FDvxQEjGecU/hI2xKX7lJJn2I7 0CfIPDTpHWP0YKzKnof1W1uBIu9uF4peJc4Op+HLvN8hYBzvQoLT4zLDOxdtKKoHpAv2 YTAH7LQ1Wo78+RVQpOB1KIWXv4tAzpm9d5RNfyYVfGCQqyxpcKZ6IJju3m1fXiGtLIDz 8frA== X-Gm-Message-State: ANoB5plbZ0qfPQIbqS/xP4QsUvvm0+Fjd7aQYwZcJJO5LjwBFBqh9zPJ E4zLgbCUtq8fTimailr0RxkAJv+6b2M= 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750733314159456390?= X-GMAIL-MSGID: =?utf-8?q?1750733314159456390?= 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);