Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp416526lqp; Thu, 21 Mar 2024 05:31:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUEen7er5ds+qRe6s+Sr5FJ8tNkxxd8qqwMLEgP0VUkoSBLMc/2K7wnvKNOF/qPhTQjjfLcstQDoBhhVjk5KQ58VNkYec/1bJKXmB//rA== X-Google-Smtp-Source: AGHT+IHhbdnVMI4XyiHHCbVrWRV0MkWu7+Jk+aSd0jnTdJvsVTvUnKSx3wKwrV1E6WddE6gxP3AW X-Received: by 2002:a05:620a:3953:b0:78a:1611:1778 with SMTP id qs19-20020a05620a395300b0078a16111778mr9204102qkn.6.1711024287602; Thu, 21 Mar 2024 05:31:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711024287; cv=pass; d=google.com; s=arc-20160816; b=kPiF7WRibd2rawwaHxJyxcJqjGYg0Vp7DVpY9viJehWnmEyLZzKrI9EFyCGXgLsSLX Br5L+DfmzlTe+J1Yj8vvxu12txlPqRCiMu2lU8jwqMnrRlYWc2O10LuWPgMWqBs6QzLs evmwclC+o64r3zGxZL346B4+K3lVdh6fs/s7TEd/hUQnC8WQZo5Jxa3H0IE12D3299Po yZjIjPsfcUDzLzS68kIjPsMhjM1s/YgzNN/ShnPEu8JO5kB/sMDoa+eniuFUE+9jnwtb jLzMsR/NbZv9F1s2q2lTILdNRDJZe79sZf+Ay0LvRBdTFB3zH6Mrj6ZgHo+BeiRuPRvD shbQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=B4nWxDL2LITioaRby7yvh7M2SRX3O9JMXDxwR9Igm8M=; fh=1QxQOecrU1LMWCI0lfA3ZW1bHuF2iqCbS+m9tfWAPRY=; b=PPjdn1TD7dEJbFoIUFBWy80u3O8N6D6vr8b8hycDdTu13eKzLWxCI+jc60LtudxVRE Azf5XhoS3kwnPNrSinLcoRNqhCryiltG5t+kbQCItHzM5bhTpraazx6TmL8zrmvhSe+E MU+Gdzk0g6w/FUdDWit4DmtBoScMrD26NF7vVathpcQVejwvKCR2DtYd490sJarriINo tDeQbu/mG7E/bmgZx6Q49+grxHElOLBBjoSyqlCvADyOFatOyTxwgyBwePOWjx7UDBZp +5XV3Ey6fz2MQ/apPBqlNHzWuYIeifNq0Vkz8XqYmBbvDnkS+0DVcVXXZHtr7Ai2aC5W nEPw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QsVMEQhI; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-110033-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110033-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 20-20020a05620a04d400b007885a7c32bdsi16218305qks.201.2024.03.21.05.31.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 05:31:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110033-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QsVMEQhI; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-110033-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110033-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 14CD11C2203C for ; Thu, 21 Mar 2024 12:31:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 429AD7A15B; Thu, 21 Mar 2024 12:31:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QsVMEQhI" Received: from mail-vk1-f177.google.com (mail-vk1-f177.google.com [209.85.221.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C78757A156 for ; Thu, 21 Mar 2024 12:31:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711024281; cv=none; b=N7jnjHIMl1UJwkMfWY237goieStPA3ngSgJfk0CuFfRfPeCu3biROCqb+R4yqsgNXpVAZIzWDtf3qpaGxylxqLBperoBdSzFFc4a2wN1aFpDgsezGE7iTzQZDaQqxpPr9PpjTac95lkRiAqyudb2vwV0x4fsyzVkJwJA1r2m8fU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711024281; c=relaxed/simple; bh=BTg+EWmvJZoLYmT0vdJuRMK/JhaMzRSaXUqmDlG1W64=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Y9w6/rr/M8X2dTRkKwWp88ECfCYOv8fyGrcC8B4103giRav2XbLFjGyvzoAkpcNa5/qbkmXIyhgrsoUSVYSHxX97J+hcObl69rmPdr0AIobDqX/CQVUl3SQDabCp6rRabj5zsOmCIf+Y3USXjEE+Fh2EzGvEpzzGldGdjR5VyS8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QsVMEQhI; arc=none smtp.client-ip=209.85.221.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-vk1-f177.google.com with SMTP id 71dfb90a1353d-4d4404fbdf5so411241e0c.0 for ; Thu, 21 Mar 2024 05:31:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711024279; x=1711629079; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=B4nWxDL2LITioaRby7yvh7M2SRX3O9JMXDxwR9Igm8M=; b=QsVMEQhIMDqg+hqu3F7BBINDNHAvoP2nr4uGzi17WsB7q96S+C6xx5XqJOsUXGGQ8u a5bt7qUxWFvZzsOZzMSFbGeL+1/fMTdDIlFy/xZfw+snqQMyECQ34qbuKcmwRFiCZvP1 wBPkEy9AJnG7Moc4DTi3euuJ3pm2o9u3IC+yoO73fQZlxF/1DaqImjS1dyoPq0xmqgG0 viMgIK2VAzYgE4ZVdw3+K1jsNNAaM02phv+fWFG4aIrXGahLDW/SIci0bmxKHZVDUAYN yUwpioHoIRHf9dijVSYL3h6DJ2a/6q3zfXb8yv0CBhWjoblYvudy9HCpjbEJtLFXjXFL 6xpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711024279; x=1711629079; 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=B4nWxDL2LITioaRby7yvh7M2SRX3O9JMXDxwR9Igm8M=; b=Ysw0EwfEN+BiiYBi2BnG3+Z2hm3sb4qj1Bc2izqJYfe/CPYPbINcc67Ip/54xM1077 jqjtY7pTE5CqLN2UXGlrLQUfD6IDVktsUF7HPPqAghUoJQPgVZXYrhSDRvOPZU3+k1I1 mQCoinXCZ8FdjYrnXnzoYC3bVkDH53SVznPzdIPP6C3gVjgMcNJ59eIAfS8gOascTpVp P21jgXcJ40gzVMSoQ5ATugCEkHq5QoHXvcw1mLEVhItOjLxuuNMuLDBosKKRDgqjYUU2 887IORwIxMi+dkjksvJirsdirXVhnR/1ot2eeWzQinpj4sWi59TpvB2lCYsotGpRZFBt PQsQ== X-Forwarded-Encrypted: i=1; AJvYcCU1A7p3/Q/eYsdv3qoAaeSRoXVgeSkqIxLBzU70BIC40h+GQyGAPKcRjFwsSVjrXsQMibqKjL8x7bNqrn/RzthtXFKDIW7yyfVw99Yj X-Gm-Message-State: AOJu0YzeTby0JMu5OHwAg14xphY+OluA/Qa/YlIVNIE2ueDlvKj3D/6d Rjbik+GmGZcmsgp/Az8bHiGPVTxMmxGzu9BYDYpXp9tqIBisYJkg2PPmGQpgGTeBLa0sRcbGPVu EPH0rXfll7SUA6TW3GlhbU/FDhIxdp2s5GnTM X-Received: by 2002:a05:6122:c85:b0:4c9:f704:38c with SMTP id ba5-20020a0561220c8500b004c9f704038cmr19496827vkb.11.1711024278613; Thu, 21 Mar 2024 05:31:18 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240320101851.2589698-1-glider@google.com> <20240320101851.2589698-3-glider@google.com> In-Reply-To: <20240320101851.2589698-3-glider@google.com> From: Marco Elver Date: Thu, 21 Mar 2024 13:30:42 +0100 Message-ID: Subject: Re: [PATCH v2 3/3] x86: call instrumentation hooks from copy_mc.c To: Alexander Potapenko Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, tglx@linutronix.de, x86@kernel.org, Linus Torvalds , Dmitry Vyukov , Tetsuo Handa Content-Type: text/plain; charset="UTF-8" On Wed, 20 Mar 2024 at 11:19, Alexander Potapenko wrote: > > Memory accesses in copy_mc_to_kernel() and copy_mc_to_user() are performed > by assembly routines and are invisible to KASAN, KCSAN, and KMSAN. > Add hooks from instrumentation.h to tell the tools these functions have > memcpy/copy_from_user semantics. > > The call to copy_mc_fragile() in copy_mc_fragile_handle_tail() is left > intact, because the latter is only called from the assembly implementation > of copy_mc_fragile(), so the memory accesses in it are covered by the > instrumentation in copy_mc_to_kernel() and copy_mc_to_user(). > > Link: https://lore.kernel.org/all/3b7dbd88-0861-4638-b2d2-911c97a4cadf@I-love.SAKURA.ne.jp/ > Suggested-by: Linus Torvalds > Signed-off-by: Alexander Potapenko > Cc: Dmitry Vyukov > Cc: Marco Elver > Cc: Tetsuo Handa Reviewed-by: Marco Elver > --- > v2: > - as requested by Linus Torvalds, move the instrumentation outside the > uaccess section > --- > arch/x86/lib/copy_mc.c | 21 +++++++++++++++++---- > 1 file changed, 17 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/lib/copy_mc.c b/arch/x86/lib/copy_mc.c > index 6e8b7e600def5..97e88e58567bf 100644 > --- a/arch/x86/lib/copy_mc.c > +++ b/arch/x86/lib/copy_mc.c > @@ -4,6 +4,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -61,10 +62,20 @@ unsigned long copy_mc_enhanced_fast_string(void *dst, const void *src, unsigned > */ > unsigned long __must_check copy_mc_to_kernel(void *dst, const void *src, unsigned len) > { > - if (copy_mc_fragile_enabled) > - return copy_mc_fragile(dst, src, len); > - if (static_cpu_has(X86_FEATURE_ERMS)) > - return copy_mc_enhanced_fast_string(dst, src, len); > + unsigned long ret; > + > + if (copy_mc_fragile_enabled) { > + instrument_memcpy_before(dst, src, len); > + ret = copy_mc_fragile(dst, src, len); > + instrument_memcpy_after(dst, src, len, ret); > + return ret; > + } > + if (static_cpu_has(X86_FEATURE_ERMS)) { > + instrument_memcpy_before(dst, src, len); > + ret = copy_mc_enhanced_fast_string(dst, src, len); > + instrument_memcpy_after(dst, src, len, ret); > + return ret; > + } > memcpy(dst, src, len); > return 0; > } > @@ -75,6 +86,7 @@ unsigned long __must_check copy_mc_to_user(void __user *dst, const void *src, un > unsigned long ret; > > if (copy_mc_fragile_enabled) { > + instrument_copy_to_user(dst, src, len); > __uaccess_begin(); > ret = copy_mc_fragile((__force void *)dst, src, len); > __uaccess_end(); > @@ -82,6 +94,7 @@ unsigned long __must_check copy_mc_to_user(void __user *dst, const void *src, un > } > > if (static_cpu_has(X86_FEATURE_ERMS)) { > + instrument_copy_to_user(dst, src, len); > __uaccess_begin(); > ret = copy_mc_enhanced_fast_string((__force void *)dst, src, len); > __uaccess_end(); > -- > 2.44.0.291.gc1ea87d7ee-goog >