Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4698043imw; Tue, 12 Jul 2022 12:38:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tTfX3rRJ2aNQGhyRIWrDeCE8ceQ69rcEJiTeBTiESq5tpxgydugsYMaOn9pRk8aPWtCOG/ X-Received: by 2002:a17:902:e5d1:b0:16b:ece4:79e6 with SMTP id u17-20020a170902e5d100b0016bece479e6mr26114331plf.83.1657654729506; Tue, 12 Jul 2022 12:38:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657654729; cv=none; d=google.com; s=arc-20160816; b=QSeWUupjQJk3dme6BrV3RkP8uwQv2EsIyUAyJYgvARcPycUGzB5EYVCTjxosnaMFqS zaSIfnldJ4LMO872q8TASt4QiRbWZXzw0Nzx2rOuDJr8KBhFmOYP6YnxApkg3/iysc5x o6X8GRhZKl/SaET3zTmuedcOQopHUumTcAXM9kEoFxJ8w6V9X1VKHynMt9lbN5kW+okT HPb+uHw9tJMCLBWtFHEcptz7HHfdbtuokCx9w3btGnidnPeErgiiHypj1TotS7tYzNIH u0zjZKM+IhRndX4awTuWG1UkPCJZmTeGIgFBJzXd+5QBn+ajXKEF2LQy6B7G2pr3A8jF qKkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ON2GIzfA3v8RUExuFtuSp4SI08NLZaohZ/Q55gkhakw=; b=xrlNjc30FhDgthj3TS6T/I4BFeWXt/baHA36Odme0FQoaMC60QXAryNmpBHzEtFb59 9+1ma0L0kZf+M3/xI8jpP6azNmf0JR4gRzmgeGZcYCQQuI+034PmSXLTM5xmV22UghA4 uzGJh+v1JUXsUhsecE+LCyCrQJFQgkP0j9LLY4TJ5VC1LXOZHwFEmSXpHa70PtSEiZ90 AGD4XKCGkoWX+6aXFPYfnl41vxNWwVMdKt2u92ZxpLpKTxxL9iHeVNlghYeFIso4dG97 xmRGJbIh74xi56eau+NWUzg6vIS6ez8d9vYLnVUvoxbwf7/h0En0AALOBvAF1vKaM+Bo Q1og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="UMSBg/up"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id br7-20020a056a00440700b005255dd30819si13277621pfb.4.2022.07.12.12.38.37; Tue, 12 Jul 2022 12:38:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="UMSBg/up"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235630AbiGLTHw (ORCPT + 99 others); Tue, 12 Jul 2022 15:07:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235539AbiGLTHI (ORCPT ); Tue, 12 Jul 2022 15:07:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76985FB8F0; Tue, 12 Jul 2022 11:51:28 -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 dfw.source.kernel.org (Postfix) with ESMTPS id A2AD86149A; Tue, 12 Jul 2022 18:51:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEEA0C3411C; Tue, 12 Jul 2022 18:51:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657651871; bh=sO/NRT++o1GVJ2ZubOWRLCd5AukTe/ungHx3/aluXy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UMSBg/upjTUYNgowMTS3eRPly58zf3TxI//bKZNRxxOCMJCP55UIhVoUPBiv/lrK5 ihTPlGho9ZE55wPwMKBjy4w6F5ZG3R3+Q9UP+h6s+PpiHIF4kXubCFpfKdZvxLeg4m 60WqgiudDwrieQXvo3TJSRW+iDM7vLNbaX2BTAjo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Borislav Petkov Subject: [PATCH 5.15 78/78] x86/static_call: Serialize __static_call_fixup() properly Date: Tue, 12 Jul 2022 20:39:48 +0200 Message-Id: <20220712183242.085202699@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220712183238.844813653@linuxfoundation.org> References: <20220712183238.844813653@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner commit c27c753ea6fd1237f4f96abf8b623d7bab505513 upstream. __static_call_fixup() invokes __static_call_transform() without holding text_mutex, which causes lockdep to complain in text_poke_bp(). Adding the proper locking cures that, but as this is either used during early boot or during module finalizing, it's not required to use text_poke_bp(). Add an argument to __static_call_transform() which tells it to use text_poke_early() for it. Fixes: ee88d363d156 ("x86,static_call: Use alternative RET encoding") Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/static_call.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/arch/x86/kernel/static_call.c +++ b/arch/x86/kernel/static_call.c @@ -25,7 +25,8 @@ static const u8 xor5rax[] = { 0x2e, 0x2e static const u8 retinsn[] = { RET_INSN_OPCODE, 0xcc, 0xcc, 0xcc, 0xcc }; -static void __ref __static_call_transform(void *insn, enum insn_type type, void *func) +static void __ref __static_call_transform(void *insn, enum insn_type type, + void *func, bool modinit) { const void *emulate = NULL; int size = CALL_INSN_SIZE; @@ -60,7 +61,7 @@ static void __ref __static_call_transfor if (memcmp(insn, code, size) == 0) return; - if (unlikely(system_state == SYSTEM_BOOTING)) + if (system_state == SYSTEM_BOOTING || modinit) return text_poke_early(insn, code, size); text_poke_bp(insn, code, size, emulate); @@ -108,12 +109,12 @@ void arch_static_call_transform(void *si if (tramp) { __static_call_validate(tramp, true); - __static_call_transform(tramp, __sc_insn(!func, true), func); + __static_call_transform(tramp, __sc_insn(!func, true), func, false); } if (IS_ENABLED(CONFIG_HAVE_STATIC_CALL_INLINE) && site) { __static_call_validate(site, tail); - __static_call_transform(site, __sc_insn(!func, tail), func); + __static_call_transform(site, __sc_insn(!func, tail), func, false); } mutex_unlock(&text_mutex); @@ -139,8 +140,10 @@ bool __static_call_fixup(void *tramp, u8 return false; } + mutex_lock(&text_mutex); if (op == RET_INSN_OPCODE || dest == &__x86_return_thunk) - __static_call_transform(tramp, RET, NULL); + __static_call_transform(tramp, RET, NULL, true); + mutex_unlock(&text_mutex); return true; }