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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A722C433F5 for ; Wed, 29 Sep 2021 08:51:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 59C7E61357 for ; Wed, 29 Sep 2021 08:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244883AbhI2Iwl (ORCPT ); Wed, 29 Sep 2021 04:52:41 -0400 Received: from foss.arm.com ([217.140.110.172]:51244 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244640AbhI2Iwi (ORCPT ); Wed, 29 Sep 2021 04:52:38 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B8B60101E; Wed, 29 Sep 2021 01:50:57 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [10.57.21.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 639C83F793; Wed, 29 Sep 2021 01:50:55 -0700 (PDT) Date: Wed, 29 Sep 2021 09:50:45 +0100 From: Mark Rutland To: Peter Zijlstra Cc: Josh Poimboeuf , Dmitry Vyukov , syzbot , Linux ARM , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, viro@zeniv.linux.org.uk, will@kernel.org, x86@kernel.org Subject: Re: [syzbot] upstream test error: KASAN: invalid-access Read in __entry_tramp_text_end Message-ID: <20210929085035.GA33284@C02TD0UTHF1T.local> References: <000000000000a3cf8605cb2a1ec0@google.com> <20210921165134.GE35846@C02TD0UTHF1T.local> <20210927170122.GA9201@C02TD0UTHF1T.local> <20210927171812.GB9201@C02TD0UTHF1T.local> <20210928103543.GF1924@C02TD0UTHF1T.local> <20210929013637.bcarm56e4mqo3ndt@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 29, 2021 at 09:39:47AM +0200, Peter Zijlstra wrote: > On Tue, Sep 28, 2021 at 06:36:37PM -0700, Josh Poimboeuf wrote: > > On Tue, Sep 28, 2021 at 11:35:43AM +0100, Mark Rutland wrote: > > > > In the other x86 thread Josh Poimboeuf suggested to use asm goto to a > > > > cold part of the function instead of .fixup: > > > > https://lore.kernel.org/lkml/20210927234543.6waods7rraxseind@treble/ > > > > This sounds like a more reliable solution that will cause less > > > > maintenance burden. Would it work for arm64 as well? > > > > > > Maybe we can use that when CC_HAS_ASM_GOTO_OUTPUT is avaiable, but in > > > general we can't rely on asm goto supporting output arguments (and IIRC > > > GCC doesn't support that at all), so we'd still have to support the > > > current fixup scheme. > > gcc-11 has it Neat. Worth looking at for future, then. > > Even without CC_HAS_ASM_GOTO_OUTPUT it should still be possible to hack > > something together if you split the original insn asm and the extable > > asm into separate statements, like: > > > > diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h > > index 6b52182e178a..8f62469f2027 100644 > > --- a/arch/x86/include/asm/msr.h > > +++ b/arch/x86/include/asm/msr.h > > @@ -137,20 +139,21 @@ static inline unsigned long long native_read_msr_safe(unsigned int msr, > > { > > DECLARE_ARGS(val, low, high); > > > > + *err = 0; > > + asm volatile("417: rdmsr\n" > > + : EAX_EDX_RET(val, low, high) > > + : "c" (msr)); > > + asm_volatile_goto(_ASM_EXTABLE(417b, %l[Efault]) :::: Efault); > > That's terrible :-) Could probably do with a comment, but might just > work.. The compiler is well within its rights to spill/restore/copy/shuffle registers or modify memory between the two asm blocks (which it's liable to do that when optimizing this after a few layers of inlining), and skipping that would cause all sorts of undefined behaviour. It's akin to trying to do an asm goto without the compiler supporting asm goto. This would probably happen to work in the common case, but it'd cause nightmarish bugs in others... Thanks, Mark. > > + > > +done: > > if (tracepoint_enabled(read_msr)) > > do_trace_read_msr(msr, EAX_EDX_VAL(val, low, high), *err); > > return EAX_EDX_VAL(val, low, high); > > + > > +Efault: > > + *err = -EIO; > > + ZERO_ARGS(val, low, high); > > + goto done; > > } > > > > /* Can be uninlined because referenced by paravirt */ > >