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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1042FC6FA82 for ; Wed, 14 Sep 2022 14:41:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229718AbiINOlP (ORCPT ); Wed, 14 Sep 2022 10:41:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229706AbiINOlN (ORCPT ); Wed, 14 Sep 2022 10:41:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ED265EDD2; Wed, 14 Sep 2022 07:41:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1D8CDB81BB7; Wed, 14 Sep 2022 14:41:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBD45C433C1; Wed, 14 Sep 2022 14:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663166459; bh=TWVD90t16Cl0movMc47E4a7VMRO0iib3j6mMZIPWEy4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hv6Q78z6Q2nIk33ayTd0SENgiMZAkQbK+662pi7q6PYJ8VAdnvxiPBuQJoLPM4vza PeabpbDqHjj23HH1SgLFUMgqpcPH6+1c2CQHFEQJ2rk96xaOpYUNxMp8quRBL8XB4V fEf2eJIcDr8S6vR8S0uXlQhnGzn4dEqgbMAPuDlxD80r0j46KnPmQ1XtCvKfvhu5vZ wnZBTD4gUhr5lCrWbEEwMb6gLgc/X2BTRQlnQmp1RKxJ9Go7eIhtSbqLWxmZLOyPEQ hV239TE/NRjWX7ttnxwkcO0pd7nbgPDdQMRoSqKXunH8gPzs99xgsywPRP6TSNFimC /vWGTtutWNVHA== Date: Wed, 14 Sep 2022 07:40:57 -0700 From: Nathan Chancellor To: Peter Zijlstra Cc: Nick Desaulniers , Bill Wendling , Kees Cook , Juergen Gross , "Srivatsa S. Bhat (VMware)" , Alexey Makhalov , VMware PV-Drivers Reviewers , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , virtualization@lists.linux-foundation.org, LKML , clang-built-linux , linux-hardening@vger.kernel.org Subject: Re: [PATCH 2/2] x86/paravirt: add extra clobbers with ZERO_CALL_USED_REGS enabled Message-ID: References: <20220902213750.1124421-1-morbo@google.com> <20220902213750.1124421-3-morbo@google.com> <202209022251.B14BD50B29@keescook> 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-hardening@vger.kernel.org On Wed, Sep 07, 2022 at 10:50:03AM +0200, Peter Zijlstra wrote: > On Tue, Sep 06, 2022 at 11:00:07PM -0700, Nick Desaulniers wrote: > > On Sun, Sep 4, 2022 at 11:02 PM Bill Wendling wrote: > > > > > > On Sat, Sep 3, 2022 at 12:18 AM Kees Cook wrote: > > > > > > > > On Fri, Sep 02, 2022 at 09:37:50PM +0000, Bill Wendling wrote: > > > > > [...] > > > > > callq *pv_ops+536(%rip) > > > > > > > > Do you know which pv_ops function is this? I can't figure out where > > > > pte_offset_kernel() gets converted into a pv_ops call.... > > > > > > > This one is _paravirt_ident_64, I believe. I think that the original > > > issue Nathan was seeing was with another seemingly innocuous function. > > > > _paravirt_ident_64 is marked noinstr, which makes me suspect that it > > really needs to not be touched at all by the compiler for > > these...special features. > > My source tree sayeth: > > u64 notrace _paravirt_ident_64(u64 x) > > And that function is only ever called at boot, after alternatives runs > it's patched with: > > mov %_ASM_ARG1, %_ASM_AX > > Anyway, if you want to take it away from the compiler, something like > so should do. This appears to work fine for me in QEMU, as I can still boot with CONFIG_ZERO_CALL_USED_REGS and spawn a nested guest without any issues. > diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c > index 7ca2d46c08cc..8922e2887779 100644 > --- a/arch/x86/kernel/paravirt.c > +++ b/arch/x86/kernel/paravirt.c > @@ -80,11 +80,16 @@ static unsigned paravirt_patch_call(void *insn_buff, const void *target, > } > > #ifdef CONFIG_PARAVIRT_XXL > -/* identity function, which can be inlined */ > -u64 notrace _paravirt_ident_64(u64 x) > -{ > - return x; > -} > +extern u64 _paravirt_ident_64(u64 x); > +asm (".pushsection .entry.text, \"ax\"\n" > + ".global _paravirt_ident_64\n" > + "_paravirt_ident_64:\n\t" > + ASM_ENDBR > + "mov %" _ASM_ARG1 ", %" _ASM_AX "\n\t" > + ASM_RET > + ".size _paravirt_ident_64, . - _paravirt_ident_64\n\t" > + ".type _paravirt_ident_64, @function\n\t" > + ".popsection"); > #endif > > DEFINE_STATIC_KEY_TRUE(virt_spin_lock_key); >