Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4694002imw; Tue, 12 Jul 2022 12:34:16 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sMy4drWAVHvfB+QPPQG5m7i8F1WLTGaJycqQjJU+VamNSApvwAQsUwelpKxPkl8QrjQMmP X-Received: by 2002:a17:907:2814:b0:72a:3758:e948 with SMTP id eb20-20020a170907281400b0072a3758e948mr25980740ejc.8.1657654456420; Tue, 12 Jul 2022 12:34:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657654456; cv=none; d=google.com; s=arc-20160816; b=FGIGbb/+cfhfCQPhAE3W91LaFakh/QkvyPhP+sMLQJUQDSgDjLKtzFEio73SGIAMdP c8kfIQFwIHoaAVHS2WYX3jXBGD+UFGyafKvW9y27euT/LWxmnELGFzdVEglE9ILfJOH0 DDWWzV7xBLA5xu157QTIpSBNZZOV0bwougDrgL0FGLEp5fUbhH3EAgSQttwKdzQKFIL7 UiQgtq2mak32WuDvQ6Pgb1KW5yXcgo98HXa0JQfZnruHqLMUXHLznBUelOY6gxQLCUm+ HBoMQYpBBLnTwwWMFuCyl6KhufHQCbQrat/ydtiiYHD0ZDmLFdJ5rfYb4CCq/295UbxJ n80A== 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=p7Ke+EDc/Ixl4wRr7BQXkozs79XvaW7mI7sT/TFnvLc=; b=ZrRTH8d79nce6ld2Cr5MIHn/rY4NnrCZiLv3nmChMHOeCktA03Mq7EAhaXRExQXIvG dG00a14Or0O94nVXLiAOdK0lFd5WHV8tlxC390ocrpxpbcqmVzJYBJG1OkEwjDl/tmFc 0BVg7nvKM84qqUn13KASDF4W4LtX7j8Laf/KlO+quuCFubDKMMazJ6AFbb3Vbxn5OqXE ooDXZeiSbXpoljI/EFrd8KZ+DHup10FgeAAUO8EOO3eC7EMkLDVrkoV9qw00Y1cuLb5K W71OxfPpzMhkfKbv/YTcIF76l169Sh2SKC3la0IYXhv48xEE2jCAzXtVxSpmbROFX2Ex 3S3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xQXYEA82; 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 n18-20020aa7c692000000b0043769e9d1bdsi12231650edq.467.2022.07.12.12.33.50; Tue, 12 Jul 2022 12:34:16 -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=xQXYEA82; 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 S234301AbiGLS5R (ORCPT + 99 others); Tue, 12 Jul 2022 14:57:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234950AbiGLS4m (ORCPT ); Tue, 12 Jul 2022 14:56:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09599ED15E; Tue, 12 Jul 2022 11:46:54 -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 56DC9B81B95; Tue, 12 Jul 2022 18:46:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEB99C3411C; Tue, 12 Jul 2022 18:46:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657651611; bh=UJnJ0k+B5Cwy8yaML0Wp60Wf0/bRoEx/BajCYGRGqcU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xQXYEA82zDb4sf0Llr1WxIVFZGPnw/hKJ7PJzpYjM4clYRDJ+C2qolRbGCZUwRAsv xM+rLGQVvLz88+AW5wNUS8FzxbbDCkr9I5p3mteClTNgNR4RG+piGsJWMMuYLS5la7 NpIrzZX36GUszB+oy2fi8bax42tfOvT20iFR9l6c= 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.10 130/130] x86/static_call: Serialize __static_call_fixup() properly Date: Tue, 12 Jul 2022 20:39:36 +0200 Message-Id: <20220712183252.461272960@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220712183246.394947160@linuxfoundation.org> References: <20220712183246.394947160@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 @@ -20,7 +20,8 @@ static const u8 tramp_ud[] = { 0x0f, 0xb 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) { int size = CALL_INSN_SIZE; const void *code; @@ -49,7 +50,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, NULL); @@ -96,12 +97,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); @@ -127,8 +128,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; }