Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp25289imw; Tue, 12 Jul 2022 13:55:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vsSmF9CP5UOPXk70xmNaGQlRso64vRac3xIAq0g3rP3sa/vAEZgBEF/8tZv3akTZGmQM1n X-Received: by 2002:a17:90b:17c1:b0:1f0:1fc9:bcc7 with SMTP id me1-20020a17090b17c100b001f01fc9bcc7mr6623549pjb.53.1657659351535; Tue, 12 Jul 2022 13:55:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657659351; cv=none; d=google.com; s=arc-20160816; b=ljkvuvrzrE6eQkZe6OOhzl+M4le0kw1J1JEasu9Mtf+zdF5IBT/fpSZtkuGC5tfQvC vR/gMaAIqfi+gFEIgwOvOnBw2pHGdkiTgnPmxN2WnWJTGjGfFHNvTFMIUx7Ok/4cwCj5 MsRYTcwET1TOlSOWUjpJ+aGdnzVfriTqHwWrzdKhv/fUumr4ju+5VLOseBQUe2n3YAF6 U6E+4Ff134F4w7asq9L132dW8X3sbiWgSHeAQdAKXziqaP+d+w5LvtdZ2CN48A3qnfFu b1seIFoeMYN9PSp5+upQuoWhvGnKsPmDJKsGaWjrg2kVXNHYQWuqHNrCET2ZWEH44e34 9/8g== 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=RKK1lXMjRWqUig8H8QqO7/11V6SW6sIg9G+thBNKNHw=; b=sVnQgA+f2PClzgzik6YS3RoQt80dxRv97bX4zny2bLiPw04Txe7AsnP3y7mYX67WAm 2vjl+6ED5B0gqX6frJtuEhfdVxqwyn5/TZtTVcLv5xTtGgirqnUIQQorWRgSkmAelhBj l+21kyxG+/KIQ6zqbqE3jop3ESSltFbVUpVpho3CwxA+Q+2L6l1/xPl80NzPcuCYVpX5 s4AFN4+NVj1mJfysWXt9t/plEY0KieoakYPWkM5V8nr0bXsr1i5jZNFAI1B91wSgK2g0 Pf8SsFelE2BmvuIM2jX1IDPQpW4Vn47Z6iMWsu5FCeIQgWK+DMC9e5F0rSlNiItkajAp qTeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DplmMXOr; 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 r73-20020a632b4c000000b0040d2fb963cdsi13193102pgr.423.2022.07.12.13.55.37; Tue, 12 Jul 2022 13:55:51 -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=DplmMXOr; 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 S235952AbiGLTPS (ORCPT + 99 others); Tue, 12 Jul 2022 15:15:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236048AbiGLTOV (ORCPT ); Tue, 12 Jul 2022 15:14:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D353C6364; Tue, 12 Jul 2022 11:54: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 dfw.source.kernel.org (Postfix) with ESMTPS id 5D1DC61123; Tue, 12 Jul 2022 18:54:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 579E1C3411C; Tue, 12 Jul 2022 18:54:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657652040; bh=AGltoFjHSKOvDf8pB/bmiaRkj18+FhxPuUtWptDeuFM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DplmMXOrlVjc/xX7TmQcdLndbBzTYD4JqFKNxd9PA2u+1beBnLmz9SnIgJ7rWtFHe c3NzaY73ICWWc1Jsb9/tDCdA+qXDiBsoZKwi71HhiUXIUfYnA/lXgBADjMaYAthoh+ zEtxLSy8zBhJGJjqyNmMPXN1dTeyEdYVnRKi2RjI= 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.18 61/61] x86/static_call: Serialize __static_call_fixup() properly Date: Tue, 12 Jul 2022 20:39:58 +0200 Message-Id: <20220712183239.312205699@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220712183236.931648980@linuxfoundation.org> References: <20220712183236.931648980@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); @@ -114,12 +115,12 @@ void arch_static_call_transform(void *si if (tramp) { __static_call_validate(tramp, true, 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, false); - __static_call_transform(site, __sc_insn(!func, tail), func); + __static_call_transform(site, __sc_insn(!func, tail), func, false); } mutex_unlock(&text_mutex); @@ -145,8 +146,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; }