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 X-Spam-Level: X-Spam-Status: No, score=-7.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A615C4361B for ; Wed, 16 Dec 2020 13:11:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44A39233A2 for ; Wed, 16 Dec 2020 13:11:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726096AbgLPNLC (ORCPT ); Wed, 16 Dec 2020 08:11:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:34104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725837AbgLPNLC (ORCPT ); Wed, 16 Dec 2020 08:11:02 -0500 Date: Wed, 16 Dec 2020 14:10:16 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1608124221; bh=hik3VFwHxdYU3iZiPeJs/44UrawWI+LLVu5/SUjPF+w=; h=From:To:Cc:Subject:References:In-Reply-To:From; b=KKZqfF3TABbL8/rDivoVJcPSCg3WFlS0ByZUChn7ZWJSptIW+Xh/HJ1UIuRSn5E1v awMhYNzza+ecWj0djqWxSN5ucVD7fS1iMsOzk2n5KoHwD9J/xVL3BF+KsW7MzUSw6y ZVY7IsvdRGTEM4ND9gMUaIeuY4klFuhCvMbNPortxQJXFLlhcIKYAGCTv/uxkx+LEL mfSnEqpdSUrc+993ocmrsk4zApI54m2loZFAXlfBXoYACGTVkyRlumFeyn1J410hoT YeQkMH3l+vJceDtq9+ZKaY2ldu8UoXY/ywUSjj44Y3yYSu2W/V7JOiJXA4IkzSEGJE 6iz7y5jd37F6A== From: Jessica Yu To: Peter Zijlstra Cc: Dexuan Cui , Ingo Molnar , Daniel Bristot de Oliveira , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Josh Poimboeuf Subject: Re: static_branch_enable() does not work from a __init function? Message-ID: <20201216131016.GC13751@linux-8ccs> References: <20201216092649.GM3040@hirez.programming.kicks-ass.net> <20201216115524.GA13751@linux-8ccs> <20201216124708.GZ3021@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20201216124708.GZ3021@hirez.programming.kicks-ass.net> X-OS: Linux linux-8ccs 4.12.14-lp150.12.61-default x86_64 User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +++ Peter Zijlstra [16/12/20 13:47 +0100]: >On Wed, Dec 16, 2020 at 12:55:25PM +0100, Jessica Yu wrote: >> +++ Peter Zijlstra [16/12/20 10:26 +0100]: >> [snip] >> > > PS, I originally found: in arch/x86/kvm/vmx/vmx.c: vmx_init(), it looks >> > > like the line "static_branch_enable(&enable_evmcs);" does not take effect >> > > in a v5.4-based kernel, but does take effect in the v5.10 kernel in the >> > > same x86-64 virtual machine on Hyper-V, so I made the above test module >> > > to test static_branch_enable(), and found that static_branch_enable() in >> > > the test module does not work with both v5.10 and my v5.4 kernel, if the >> > > __init marker is used. >> >> Because the jump label code currently does not allow you to update if >> the entry resides in an init section. By marking the module init >> section __init you place it in the .init.text section. >> jump_label_add_module() detects this (by calling within_module_init()) >> and marks the entry by calling jump_entry_set_init(). Then you have >> the following sequence of calls (roughly): >> >> static_branch_enable >> static_key_enable >> static_key_enable_cpuslocked >> jump_label_update >> jump_label_can_update >> jump_entry_is_init returns true, so bail out >> >> Judging from the comment in jump_label_can_update(), this seems to be >> intentional behavior: >> >> static bool jump_label_can_update(struct jump_entry *entry, bool init) >> { >> /* >> * Cannot update code that was in an init text area. >> */ >> if (!init && jump_entry_is_init(entry)) >> return false; >> > >Only because we're having .init=false, incorrectly. See the other email. Ah yeah, you're right. I also misread the intention of the if conditional :/ If we're currently running an init function it's fine, but after that it will be unsafe. Btw, your patch seems to work for me, using the test module provided by Dexuan.