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: 29705 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2301246wrr; Mon, 5 Dec 2022 06:58:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf6FqRLxAVq0CafnqeipPguj6i1wPF+ZlxJUa7INhSlAkp3q+V71cZS4JTF/jWWLtBm+JA1t X-Received: by 2002:a17:906:f84d:b0:7b9:631b:7dfb with SMTP id ks13-20020a170906f84d00b007b9631b7dfbmr51895109ejb.32.1670252337485; Mon, 05 Dec 2022 06:58:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670252337; cv=none; d=google.com; s=arc-20160816; b=uXkn+ZuqMXKkB9rxE0iUE/VVfou/inN+S2CIzGCCyUUU5TzrHWaC980joQsfT8eNKt jpZFt+A+IsQN7/VakCf8nnlqyP061R1jYqVyRzlA1rcHx1uKktpvzFcSekUewGFZ217n ZgHWa8mjfoeEOQWx/6h0tHxELzMyQQUk0WcMboXWTtgg1w8XUQhk3Qr099Btg90txyXs pAdZVD0azeLg5V/YXGy31I0Qw0+hxIVCDaZ7eDqLYIz0wg1PpQsK+S0vj3FrZYdTigwV 4CVBD7x/TTk7wXgmb+S/HUqe3UNx8AV08jih3QGXKJeLdONxZ+EERujjVvcfd5j0N1AV yodg== 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=YAXOrsESrx0CdS4Q6xjLBDZXEnUh9Z0PdR9s8BvDppo=; b=qwVX+Y2SfgmHKMjS9KHyhR618sf9VJiqO5u9KU6SQHE8pN670p7ivijRuJyHhIselq ZCKjHU5G8h3JSrX2KuwgG53QedFnhk5HaQBQ3N2eBKX7R8DmoMirJpBj03VQOTNZD5iX ZZsFFl/Y9cQqFKa//tc3Dq0lN9gw/oHzzU57BjgVTxKRfiRXHgX0O8V+bg9DKSm+gabY nLcf1D7mag9uQdLqeyb8LITuSuk8BHDThWHRLoXPuBuxrNnSWX3CF70B03Ay5SY2DR/M m2ErnTI1xRpb90iobH1kOuhwHlM9wZ7W8Yy3SHN6upMKSDNfBf5vCcwOKKOMnqABmCuu XIhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ql5DAtYv; 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 v15-20020aa7d80f000000b0046c641a3108si4912640edq.148.2022.12.05.06.58.33; Mon, 05 Dec 2022 06:58:57 -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=ql5DAtYv; 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 S231355AbiLEO5u (ORCPT + 99 others); Mon, 5 Dec 2022 09:57:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230000AbiLEO5r (ORCPT ); Mon, 5 Dec 2022 09:57:47 -0500 Received: from mail-ej1-x64a.google.com (mail-ej1-x64a.google.com [IPv6:2a00:1450:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC1AA5F87 for ; Mon, 5 Dec 2022 06:57:45 -0800 (PST) Received: by mail-ej1-x64a.google.com with SMTP id nc4-20020a1709071c0400b0078a5ceb571bso7551980ejc.4 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=QqcGKrxJBqxzOnQBbUQXUW8if+ZAC6YZNn1oU5pK+LKTm+nkzsXOY6qUug5HVM7nEe +QEPDDssfX1bGruCQokwHx3Lobt7H5hA0SpTscjnnaHeEjTHoONyeRSN2PDrsgZb78RB jQhhoSf5yu7f6udYlDmMr8dCR2M9BL6R92rtKxhRljN3ACti+Q2LyBEYUDNI6206/eOV v4Z+1TkgOg77dDSb09lLVc7EMJa2HS3GdJFm8xb0sMcieyJvLmIae8PJ7m7u6v0ODzTw 0DczeoKu8fVKAuUvYi3XCfjHbFWMTRJ9etEkNP/UkTsJA6fbC2kifh40I2pNgg1+x11E nvHQ== X-Gm-Message-State: ANoB5plHoy97eaMGMJnBeewhYfx9a8fX7bVt3A+HvaWhfWUap/sOjB3D +gPuaN6B93z7I2nJpJyYHdgUsIzyDd4= 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-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?1751380972588053512?= X-GMAIL-MSGID: =?utf-8?q?1751386514971163441?= 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));