Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp459409imi; Fri, 22 Jul 2022 02:51:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s7tWwXoCfQ3wjCIQrdt6DTmSuferrSGYoLnlDBQxd/aqKIIdURpXKLNLfGj0+pS+bWVHG7 X-Received: by 2002:a17:90b:4b81:b0:1ef:cd2c:bf2e with SMTP id lr1-20020a17090b4b8100b001efcd2cbf2emr3160127pjb.137.1658483504894; Fri, 22 Jul 2022 02:51:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658483504; cv=none; d=google.com; s=arc-20160816; b=MKgCLr4Y+1yA+2ok3JEKGB4FFSjE13nvcPdAR5t+gNLQxuV0O/nm7A6L1feDv3b6Rv tA6mZTyw38TdxKkQd+ZuJqXIDP5uE2makDdNoAy1ZRBYDjFk24SaUnGwMJlQ8Ihg2JDt +SnngOa3aY5nmb04WlIhLY80p0uU3MxKABvF29N5UfxqEfeBM172wkonq+BDviFdPwQt NqiU7kHlhMmtOnfLTUcXNhejHep8COfkL7445XnQLAQ0xs8P1JOoQ9/v9kEQfpfEiSfg hhKWp7wPq4HuKH57VL5/S1IVv9oSF2sDh6ekPTliw+Z/XdtiY5ivU5+o0PHNPb+33vY/ nXVQ== 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=lDp5pxa1OXD2FHhMl89y04aYmuRwApZWdpQDMs7kBXGg0Sa+boxDaEyM47gfm/lz1M 5rv9MbP2II1wwKQgyL9w7BgWJeummkknD757uYLjmHzEr/B9YpN6mmbjLF0FPqY+W5Of Jrslz9Cc3UH0ON/tIQg6+hc6nvhJX3iX0TWrKsForRDqnaVinTkopnwbHrKqwfH6h/xy eMDuUpftbJlY9r9LhZWRiVSOHSDkIy4inmu0PGbBkN3XiLj6BP5EAqnEEC/fBVAHHnhA Xhh42oraRSqhcrPysJSU+evWVfwg45HwoddNytwO6OXTxF5e3HWz8+oE78FSBXPD/Rao zzWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fb6CSHrp; 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 n22-20020a056a0007d600b0052b93453af1si5115148pfu.92.2022.07.22.02.51.30; Fri, 22 Jul 2022 02:51:44 -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=fb6CSHrp; 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 S235704AbiGVJQK (ORCPT + 99 others); Fri, 22 Jul 2022 05:16:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235397AbiGVJPc (ORCPT ); Fri, 22 Jul 2022 05:15:32 -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 33DCAAFB4A; Fri, 22 Jul 2022 02:11:35 -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 BCE4261F8C; Fri, 22 Jul 2022 09:11:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B15D2C341D9; Fri, 22 Jul 2022 09:11:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658481094; bh=AGltoFjHSKOvDf8pB/bmiaRkj18+FhxPuUtWptDeuFM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fb6CSHrpwxRdyfDxqEHdcwKSTbUrBTbG9Y6XW66SSP/aOUebBOIIVPYIPwRNroxsn XH2zDydtWPWCh7X3b+aUGlMwJNtOcvWWcznegAw6uzMd3j0ZZSMQHgcoLfN4Sp20t4 v7NGILK9rJZqtfZNoVstsB63Y/Eas+/4/4KJLHkU= 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/70] x86/static_call: Serialize __static_call_fixup() properly Date: Fri, 22 Jul 2022 11:07:56 +0200 Message-Id: <20220722090654.261640411@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220722090650.665513668@linuxfoundation.org> References: <20220722090650.665513668@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.8 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 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; }