From patchwork Mon Dec 5 14:57: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: 13064602 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 9E553C4321E for ; Mon, 5 Dec 2022 14:57:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E7728E0002; Mon, 5 Dec 2022 09:57:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3974A8E0001; Mon, 5 Dec 2022 09:57:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2875E8E0002; Mon, 5 Dec 2022 09:57: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 1B8EB8E0001 for ; Mon, 5 Dec 2022 09:57:47 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9299E80445 for ; Mon, 5 Dec 2022 14:57:46 +0000 (UTC) X-FDA: 80208556932.04.2B54F3A Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf16.hostedemail.com (Postfix) with ESMTP id C1831180011 for ; Mon, 5 Dec 2022 14:57:45 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ql5DAtYv; spf=pass (imf16.hostedemail.com: domain of 36AaOYwYKCFEz41wxAz77z4x.v75416DG-553Etv3.7Az@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=36AaOYwYKCFEz41wxAz77z4x.v75416DG-553Etv3.7Az@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=1670252265; 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=YAXOrsESrx0CdS4Q6xjLBDZXEnUh9Z0PdR9s8BvDppo=; b=wfYrsju9foH9v/1pzx/mXwenOBGFXmz/ngT6Gb5YCr9LTj3+2jAKwov98P8pKzHw/dDNWI Uh7ZZm2WsZk38bYwLXxyaRrhHXlPzfS1NX/wHh1V4sbWi8NTXHog9LR78LcfequqogSDaC TQ6JzuuJqYasP0rbdZbMNdBGQMhdg9g= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ql5DAtYv; spf=pass (imf16.hostedemail.com: domain of 36AaOYwYKCFEz41wxAz77z4x.v75416DG-553Etv3.7Az@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=36AaOYwYKCFEz41wxAz77z4x.v75416DG-553Etv3.7Az@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670252265; a=rsa-sha256; cv=none; b=zjdnl2IzthN0QJO0s2jKAV5nZJaW1r1YX/ySUg0abL2i6uF1YKEKGE7sgZY1rJ0Oerxrp1 GMuFFYhmpWKJCS8weIqMTjEbkn+GaytDlAuocEHbrpj8NYbWOX3B6p3x77MWoSfQnSd1MZ f/4+lVhNRS9SXyAdo0zVjvZj5s1fobY= Received: by mail-ed1-f74.google.com with SMTP id i2-20020a05640242c200b0046c66305ebaso3019089edc.15 for ; Mon, 05 Dec 2022 06:57:45 -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=YAXOrsESrx0CdS4Q6xjLBDZXEnUh9Z0PdR9s8BvDppo=; b=ql5DAtYvnEvQAuv1Vg7O2uFk4TDOneX6PiWFdn5sm1InzCNwvuD+TNu80xbOhaLWHW Kvk1qtNKOg8fKGE3QXew2wXaYc8ycPvXrANWjCCd6ex5xA+DB3Y5q93zNpwpOls2gwld anNWOtm9lLhQZOroxXTd+g4keYF1LDsVuM7xDLI06sS0v/Y5oGzPWdxHKHKRCV2ChM9O uBPzDJ6wPAse5H7pHJZ7TKkYMa6hIxfPSxJE7VK9spAx121eufzZ7nwsvX6Y0rub+P4D S2z1c4BdZxeN14kHFjNYlDXY3fdCX+gD4ICa7gmRa1e/T3Uhg0Ooh64dOUMktMvGlqhD MD7g== 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=YAXOrsESrx0CdS4Q6xjLBDZXEnUh9Z0PdR9s8BvDppo=; b=prTwuGw/W2X35j+K89bdXAUcqbkTCHDGqBUPK3nd7oCyqD/cIjYpj85+khvs5GHVVT AJRPfPYYDXbqIkcY6xdD4dyC0et09J0wPTYPFqQlp97JU9jivRsao/qBHr/h2YAWT2F2 HF2A69MroaaEuRj2cEJnYZbEFdRzyM+1POSn1TvGXR8c4ad7hHeaotg5XjWF5w6u67Tv RkFEn1ME1ec5sFmokE3dIbj+DSWVVz6T7oQv9iKom7NbHhWmliUFH6sJ6X7jyCVM9SoJ Y/88c574U5Bm8S1UGTpIP8WsUgY/YRzpD4d5p5opjN04it+n9Weuk0q+KnFzpa6WjT7Y n1wg== X-Gm-Message-State: ANoB5plTc8GQVNwfWUOZ3T2agwTf0volhghhKElcQxLejW7+/XKHchNX /Norg020Rcz/nMn50SKs7qz1aURyREs= X-Google-Smtp-Source: AA0mqf7bLMTQFhWrdBJoIGa4xIjQbS5vJ9zm/mLC5/L9i1Mul32aXXmMdyPekGrKbIbgzqqPfdvdgJT7y9o= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:961a:360d:6816:d7ba]) (user=glider job=sendgmr) by 2002:a05:6402:2948:b0:463:bc31:2604 with SMTP id ed8-20020a056402294800b00463bc312604mr73708091edb.32.1670252264258; Mon, 05 Dec 2022 06:57:44 -0800 (PST) Date: Mon, 5 Dec 2022 15:57:40 +0100 In-Reply-To: <20221205132558.63484-1-glider@google.com> Mime-Version: 1.0 References: <20221205132558.63484-1-glider@google.com> X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog Message-ID: <20221205145740.694038-1-glider@google.com> Subject: [PATCH v2] kmsan: fix memcpy tests From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, elver@google.com, dvyukov@google.com, linux-mm@kvack.org X-Rspamd-Queue-Id: C1831180011 X-Stat-Signature: 5dcrp7ij43qowdbcnwzpch38baz8nbiw X-Rspam-User: X-Spamd-Result: default: False [-3.77 / 9.00]; BAYES_HAM(-4.67)[96.91%]; MID_CONTAINS_FROM(1.00)[]; DMARC_POLICY_ALLOW(-0.50)[google.com,reject]; MV_CASE(0.50)[]; FORGED_SENDER(0.30)[glider@google.com,36AaOYwYKCFEz41wxAz77z4x.v75416DG-553Etv3.7Az@flex--glider.bounces.google.com]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; R_DKIM_ALLOW(-0.20)[google.com:s=20210112]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; ARC_NA(0.00)[]; RCPT_COUNT_FIVE(0.00)[6]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_TRACE(0.00)[google.com:+]; PREVIOUSLY_DELIVERED(0.00)[linux-mm@kvack.org]; FROM_NEQ_ENVFROM(0.00)[glider@google.com,36AaOYwYKCFEz41wxAz77z4x.v75416DG-553Etv3.7Az@flex--glider.bounces.google.com]; TO_DN_NONE(0.00)[]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1] X-Rspamd-Server: rspam08 X-HE-Tag: 1670252265-549062 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: Recent Clang changes may cause it to delete calls of memcpy(), if the source is an uninitialized volatile local. This happens because passing a pointer to a volatile local into memcpy() discards the volatile qualifier, giving the compiler a free hand to optimize the memcpy() call away. Use OPTIMIZER_HIDE_VAR() to hide the uninitialized var from the too-smart compiler. Suggested-by: Marco Elver Signed-off-by: Alexander Potapenko Reviewed-by: Marco Elver --- mm/kmsan/kmsan_test.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c index 9a29ea2dbfb9b..eb44ef3c5f290 100644 --- a/mm/kmsan/kmsan_test.c +++ b/mm/kmsan/kmsan_test.c @@ -419,6 +419,7 @@ static void test_memcpy_aligned_to_aligned(struct kunit *test) kunit_info( test, "memcpy()ing aligned uninit src to aligned dst (UMR report)\n"); + OPTIMIZER_HIDE_VAR(uninit_src); memcpy((void *)&dst, (void *)&uninit_src, sizeof(uninit_src)); kmsan_check_memory((void *)&dst, sizeof(dst)); KUNIT_EXPECT_TRUE(test, report_matches(&expect)); @@ -441,6 +442,7 @@ static void test_memcpy_aligned_to_unaligned(struct kunit *test) kunit_info( test, "memcpy()ing aligned uninit src to unaligned dst (UMR report)\n"); + OPTIMIZER_HIDE_VAR(uninit_src); memcpy((void *)&dst[1], (void *)&uninit_src, sizeof(uninit_src)); kmsan_check_memory((void *)dst, 4); KUNIT_EXPECT_TRUE(test, report_matches(&expect)); @@ -464,6 +466,7 @@ static void test_memcpy_aligned_to_unaligned2(struct kunit *test) kunit_info( test, "memcpy()ing aligned uninit src to unaligned dst - part 2 (UMR report)\n"); + OPTIMIZER_HIDE_VAR(uninit_src); memcpy((void *)&dst[1], (void *)&uninit_src, sizeof(uninit_src)); kmsan_check_memory((void *)&dst[4], sizeof(uninit_src)); KUNIT_EXPECT_TRUE(test, report_matches(&expect));