Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2183995iob; Thu, 5 May 2022 18:17:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQWKsE40wMfS7bFjoqtWI9btX6i1HASfLbU+R8A4pOdP3mVqx9lu1yjgv4kDB/lJjsqxGb X-Received: by 2002:aa7:d407:0:b0:425:f57e:7ae5 with SMTP id z7-20020aa7d407000000b00425f57e7ae5mr964382edq.393.1651799879129; Thu, 05 May 2022 18:17:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651799879; cv=none; d=google.com; s=arc-20160816; b=LYeO7sMk/LITqVWdts8BTPxUBcGD2WBbdaj8DGkGz6l7NSZwQl0dAc7cSeQGWok5RL a5q3nusq74vrfDF5XgwlX29ySDREZM2QGCGe34AgrcBWlfCoBNR2MnN7SzcM4yNpYh/6 cLWzCSK+BB1AMiq+gZ//PNxDpPsRJjorTBS49KtEffgDx+o3nCFGGfTH+seAk0I8V7jo IXPMHJdJ9iRUNwCQFjU8zkOnbh1m6pVZtTZrdFH7EuZWRzHZS/8IHGNqoQvy0DrxRkqB TKGnQI2+WDIHR8TLebOJuNZXSYRcHNMBuGFZKu79JW5MnnoFKWZ0tlgJZmRgBVlr461Y WvfA== 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=usb885nJpU6h8UXigQxw216gCN0Ie7dmk1YgCBFV/fg=; b=cVLAmrxHXRe3fuxeZUQd0z0P7iAjgGI38LMVu3AQeyNT7GdITURyTz6DOludwoJe2O T37+L6Fv1zRkPPy+Ww4tG8m7i96Lnr5lg/T8rXAqOpn9eE+01IUfbA7QZBiWq3E8DF4l bCW88e1lIsVySHAA2+GVndIcdMeTrWrgHGrW2N6LNaB3NyFZ447hE3Ku5Bes3WoQSb06 20AkzdsRlGL1Leh4T/zrxJoHYP5sovM5bs53JhOeN+Edj1AATfTv2iS1q6awYAeRR0hA a9jIT80EK05YP53cMcqmzxsEa6STMqAWTuzWE66pDTwd/nGGtLR6dawhK/TB1g5rONHW RA9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ha7h/MMh"; 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 x93-20020a50bae6000000b00423e3538ee2si2862709ede.335.2022.05.05.18.17.36; Thu, 05 May 2022 18:17:59 -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="ha7h/MMh"; 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 S1357370AbiEDRYG (ORCPT + 99 others); Wed, 4 May 2022 13:24:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355598AbiEDREb (ORCPT ); Wed, 4 May 2022 13:04:31 -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 E31A84EF52; Wed, 4 May 2022 09:53:10 -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 659AE61899; Wed, 4 May 2022 16:53:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B658AC385A4; Wed, 4 May 2022 16:53:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683188; bh=NEBsSG0/XWJf6FprfNFMo2p3cGJLwBZ8OJmNqMRtIGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ha7h/MMhWT/k7W9LcRI1xrrIvH6XeIepiF6lTTmnCGeoBGsvT3HKYkTYm8uhzJwoi Iyafm///AApkf3nnLr62/pCEt/OV1ZqnTXg5owavHZ8FH1v1jhLzE5c6LEA5i2ESDm Rjn/SXBXvnGBvCIZci1ANq2XGPQ48JG3toIaD7cE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guo Ren , Guo Ren , Palmer Dabbelt , Masami Hiramatsu Subject: [PATCH 5.15 041/177] riscv: patch_text: Fixup last cpu should be master Date: Wed, 4 May 2022 18:43:54 +0200 Message-Id: <20220504153056.592587620@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153053.873100034@linuxfoundation.org> References: <20220504153053.873100034@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: Guo Ren commit 8ec1442953c66a1d8462cccd8c20b7ba561f5915 upstream. These patch_text implementations are using stop_machine_cpuslocked infrastructure with atomic cpu_count. The original idea: When the master CPU patch_text, the others should wait for it. But current implementation is using the first CPU as master, which couldn't guarantee the remaining CPUs are waiting. This patch changes the last CPU as the master to solve the potential risk. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Acked-by: Palmer Dabbelt Reviewed-by: Masami Hiramatsu Fixes: 043cb41a85de ("riscv: introduce interfaces to patch kernel code") Cc: stable@vger.kernel.org Signed-off-by: Palmer Dabbelt Signed-off-by: Greg Kroah-Hartman --- arch/riscv/kernel/patch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/riscv/kernel/patch.c +++ b/arch/riscv/kernel/patch.c @@ -104,7 +104,7 @@ static int patch_text_cb(void *data) struct patch_insn *patch = data; int ret = 0; - if (atomic_inc_return(&patch->cpu_count) == 1) { + if (atomic_inc_return(&patch->cpu_count) == num_online_cpus()) { ret = patch_text_nosync(patch->addr, &patch->insn, GET_INSN_LENGTH(patch->insn));