From mboxrd@z Thu Jan 1 00:00:00 1970 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 15880C4321E for ; Mon, 5 Dec 2022 14:50:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 489458E0003; Mon, 5 Dec 2022 09:50:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 439FE8E0001; Mon, 5 Dec 2022 09:50:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 300B38E0003; Mon, 5 Dec 2022 09:50:16 -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 233A58E0001 for ; Mon, 5 Dec 2022 09:50:16 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E59D6801ED for ; Mon, 5 Dec 2022 14:50:15 +0000 (UTC) X-FDA: 80208537990.25.C6E3054 Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) by imf13.hostedemail.com (Postfix) with ESMTP id 7EF942000B for ; Mon, 5 Dec 2022 14:50:15 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="g/FT9zgI"; spf=pass (imf13.hostedemail.com: domain of glider@google.com designates 209.85.219.170 as permitted sender) smtp.mailfrom=glider@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670251815; a=rsa-sha256; cv=none; b=xbXFyyiMh3TzJx7o2eo0m1rlXh+cPQigUsgAunqRGwcVtRxL47T4QPkKwhKIVtxLPUYTRU 1Zt06toYS2700grmGTmimA1PXnNNI+zpNf2R5ZICky9biAKpUmLV7z9kvSkiS9m9yxNleA lxtLFlyKJGGnyYO2IoJm/QHWDfG1Iok= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="g/FT9zgI"; spf=pass (imf13.hostedemail.com: domain of glider@google.com designates 209.85.219.170 as permitted sender) smtp.mailfrom=glider@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=1670251815; 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=cHTpB0BnN7ZuHfG5zCDeCXEs2H7rEm1JWnyNEiOyTZQ=; b=VlWKyeeGl6QerokJ16POTjbFga0WCionNe5uXb7Ld3LPfBtmO0X6WkNmRQPj2QT6qgNOTs gMTSSYiaNKRPB3c9n5CKe01anIkIX1o60YkLe40L9YRIkpxxFppY22keyp9YYBfk4XAiEj gCopiV2bzxRnaGYSKgMPTh9zz5trSBM= Received: by mail-yb1-f170.google.com with SMTP id s11so214882ybe.2 for ; Mon, 05 Dec 2022 06:50:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=cHTpB0BnN7ZuHfG5zCDeCXEs2H7rEm1JWnyNEiOyTZQ=; b=g/FT9zgIfywPlpCBPQUqlmXCehbGXY4G649YoyoweLxkFfFIdSrJOCw7h5x3l4ErqD e3ojlUL60O5yr1B86bih6pEoiMgb/a3SzKzTjg839+vd8/rVkFj05rVjfHhJQM2vT2+b sOyiyr5BRG2rGBlaDQIdLYaW3V3f6gY393IK5v7C9PD6gjYwq+0DsKYA1UItR7OWgDGY gCItSoi+Su8tr+aeHU3EZHk0L/EfFSCYT++ALfFHXP2pxJgqHWr1+L0dtMLWk09ocJuL mdBWpaRiP67W2ZYK6YMSxo3RWnCraIC1YXE5W0tieqlyVXgTdTUXeGXbBRuxsHS0gp2u 1S8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=cHTpB0BnN7ZuHfG5zCDeCXEs2H7rEm1JWnyNEiOyTZQ=; b=kN7LW941irfo9Sp2tYstXctmPtSSqjXPEjgMqF7BpHJOd4MuD6VsaV7ep4+GeUi8fA wEN11nn5TFYeXElcMt8mCgXDqkblsjmsanVBtkqSt2vkqD9V3ILDxNBDFHpny6LyVo2L /ydePTZmLzaLkoHzuBuWGQddXMDVbiOdFvrFi/SaW4ammbDZzccmmBeKxV1tx/xw/9/U LBi9vuDTIkBYMb67F/8qPlENdmX/XqyR9ahMtRHv2Tv2VYYBvG/zPim48DcItS0lRc4z DksjkujQ38ty4dGpVHlocZLg5dh8rgXdy8O6UOKT6/DcHWLWYyDY1p281cmENA8CqBv6 6KIw== X-Gm-Message-State: ANoB5pk2x+RaofBLcfcH2V04L7rWSS8mXkZ5lniRnJqmbVB3z0v/B9AB CkqV+3tE5R5zx08maHy8v8rpwDZvwiMJSc8gBXN2rw== X-Google-Smtp-Source: AA0mqf7DCnqqoYPc7YOQu9LdRmvGPtKK2Wix1n/2wMB3G3QHBMzwlTzHU0J0/h1wunugl2V9aMNcJQzScpR6M9H4LC4= X-Received: by 2002:a25:d250:0:b0:6f4:f4d:c47a with SMTP id j77-20020a25d250000000b006f40f4dc47amr43332542ybg.398.1670251814484; Mon, 05 Dec 2022 06:50:14 -0800 (PST) MIME-Version: 1.0 References: <20221205132558.63484-1-glider@google.com> In-Reply-To: From: Alexander Potapenko Date: Mon, 5 Dec 2022 15:49:37 +0100 Message-ID: Subject: Re: [PATCH] kmsan: fix memcpy tests To: Marco Elver Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, dvyukov@google.com, linux-mm@kvack.org Content-Type: multipart/alternative; boundary="000000000000172bdb05ef15ceb7" X-Rspam-User: X-Spamd-Result: default: False [3.10 / 9.00]; SORBS_IRL_BL(3.00)[209.85.219.170:from]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; BAD_REP_POLICIES(0.10)[]; BAYES_HAM(-0.00)[35.54%]; R_DKIM_ALLOW(0.00)[google.com:s=20210112]; R_SPF_ALLOW(0.00)[+ip4:209.85.128.0/17]; DMARC_POLICY_ALLOW(0.00)[google.com,reject]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+,1:+,2:~]; TO_DN_SOME(0.00)[]; DKIM_TRACE(0.00)[google.com:+]; RCPT_COUNT_FIVE(0.00)[5]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[linux-mm@kvack.org]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; ARC_NA(0.00)[] X-Rspamd-Queue-Id: 7EF942000B X-Rspamd-Server: rspam01 X-Stat-Signature: uqai345utu6ccmzrdqnf9sgteugxzpau X-HE-Tag: 1670251815-301997 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: --000000000000172bdb05ef15ceb7 Content-Type: text/plain; charset="UTF-8" On Mon, Dec 5, 2022 at 3:12 PM Marco Elver wrote: > On Mon, 5 Dec 2022 at 14:26, Alexander Potapenko > wrote: > > > > 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. > > > > To outsmart the compiler, we call __msan_memcpy() instead of memcpy() > > in test_memcpy_aligned_to_aligned(), test_memcpy_aligned_to_unaligned() > > and test_memcpy_aligned_to_unaligned2(), because it's the behavior of > > __msan_memcpy() we are testing here anyway. > > > > Signed-off-by: Alexander Potapenko > > It might be nice to retain memcpy() calls somehow, as that tests > end-to-end that the compiler does the right thing here i.e. replacing > the memcpy() calls with instrumented versions. > > Does OPTIMIZER_HIDE_VAR() help? This should prevent the compiler from > seeing it's uninitialized. > > It indeed does, thanks! Let me send a v2. --000000000000172bdb05ef15ceb7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Mon, Dec 5, 2022 at 3:12 PM Marco = Elver <elver@google.com> wrot= e:
On Mon, 5 Dec= 2022 at 14:26, Alexander Potapenko <glider@google.com> wrote:
>
> Recent Clang changes may cause it to delete calls of memcpy(), if the<= br> > 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.
>
> To outsmart the compiler, we call __msan_memcpy() instead of memcpy()<= br> > in test_memcpy_aligned_to_aligned(), test_memcpy_aligned_to_unaligned(= )
> and test_memcpy_aligned_to_unaligned2(), because it's the behavior= of
> __msan_memcpy() we are testing here anyway.
>
> Signed-off-by: Alexander Potapenko <glider@google.com>

It might be nice to retain memcpy() calls somehow, as that tests
end-to-end that the compiler does the right thing here i.e. replacing
the memcpy() calls with instrumented versions.

Does OPTIMIZER_HIDE_VAR() help? This should prevent the compiler from
seeing it's uninitialized.

It indeed does, thanks!
Let me send a v2.
--000000000000172bdb05ef15ceb7--