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 245D0C433EF for ; Wed, 27 Apr 2022 13:32:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B2D416B0072; Wed, 27 Apr 2022 09:32:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADEE06B0073; Wed, 27 Apr 2022 09:32:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 97E196B0075; Wed, 27 Apr 2022 09:32:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 8A4EA6B0072 for ; Wed, 27 Apr 2022 09:32:26 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6173F21215 for ; Wed, 27 Apr 2022 13:32:26 +0000 (UTC) X-FDA: 79402748292.30.EC2A9C5 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf20.hostedemail.com (Postfix) with ESMTP id 66D831C006C for ; Wed, 27 Apr 2022 13:32:22 +0000 (UTC) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1651066344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=X7MGqKhcR2rK4bHhpyakvKk80PXfTvRpOEHw1CHocKs=; b=ohn+hC646sn2jflwe2+UxebhGiwPyBV84sJRxiAvyqE37QW7aGwEfptKKOcUr3GZ10ZGJO OK5sYNE/5x1GOtersnl4dBFpoxCEkYLpcHbf6zuIs/HjJsUQuhbYWTRIsF2BLKeE7EPZUT h+qiVebu5bZsClGL1aLHWFs9tBrvecF74Qxr29uhbym2tYsLjtJbiw7fhzfHj+2+unjHXy dVr2VwG+u3k3PQ0XxUQgqmFy6FCIBp95Hh3k7a0U6gcS13RuTKUADQ8fRSQ68kmWkShqAx U/Odt/SoCJYK6j45Dny0vD2N7WOyZ2n5EsUXkEohvuxsvRSwmyMwsH6cgyXa5Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1651066344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=X7MGqKhcR2rK4bHhpyakvKk80PXfTvRpOEHw1CHocKs=; b=bCDiX4Fi9GAN0Y217Gcsro/3hVbm6FpepZEqlCHPe0fNNCAHEf2xbGEkJ8g5sLfVYuqOV2 ZiOzp4zTqL7wE2BQ== To: Alexander Potapenko , glider@google.com Cc: Alexander Viro , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Mark Rutland , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 28/46] kmsan: entry: handle register passing from uninstrumented code In-Reply-To: <20220426164315.625149-29-glider@google.com> References: <20220426164315.625149-1-glider@google.com> <20220426164315.625149-29-glider@google.com> Date: Wed, 27 Apr 2022 15:32:23 +0200 Message-ID: <87a6c6y7mg.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Stat-Signature: skw4yq5f5r514ohkm5kj9dbxrarzmi34 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 66D831C006C X-Rspam-User: Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=ohn+hC64; dkim=pass header.d=linutronix.de header.s=2020e header.b=bCDiX4Fi; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf20.hostedemail.com: domain of tglx@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=tglx@linutronix.de X-HE-Tag: 1651066342-967275 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: On Tue, Apr 26 2022 at 18:42, Alexander Potapenko wrote: Can you please use 'entry:' as prefix. Slapping kmsan in front of everything does not really make sense. > Replace instrumentation_begin() with instrumentation_begin_with_regs() > to let KMSAN handle the non-instrumented code and unpoison pt_regs > passed from the instrumented part. That should be: from the non-instrumented part or passed to the instrumented part right? > --- a/kernel/entry/common.c > +++ b/kernel/entry/common.c > @@ -23,7 +23,7 @@ static __always_inline void __enter_from_user_mode(struct pt_regs *regs) > CT_WARN_ON(ct_state() != CONTEXT_USER); > user_exit_irqoff(); > > - instrumentation_begin(); > + instrumentation_begin_with_regs(regs); I can see what you are trying to do, but this will end up doing the same thing over and over. Let's just look at a syscall. __visible noinstr void do_syscall_64(struct pt_regs *regs, int nr) { ... nr = syscall_enter_from_user_mode(regs, nr) __enter_from_user_mode(regs) ..... instrumentation_begin_with_regs(regs); .... instrumentation_begin_with_regs(regs); .... instrumentation_begin_with_regs(regs); if (!do_syscall_x64(regs, nr) && !do_syscall_x32(regs, nr) && nr != -1) { /* Invalid system call, but still a system call. */ regs->ax = __x64_sys_ni_syscall(regs); } instrumentation_end(); syscall_exit_to_user_mode(regs); instrumentation_begin_with_regs(regs); __syscall_exit_to_user_mode_work(regs); instrumentation_end(); __exit_to_user_mode(); That means you memset state four times and unpoison regs four times. I'm not sure whether that's desired. instrumentation_begin()/end() are not really suitable IMO. They were added to allow objtool to validate that nothing escapes into instrumentable code unless annotated accordingly. Thanks, tglx