Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp41483pxb; Tue, 12 Apr 2022 16:13:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwapIl3SShJn0XZR+/EanhnjUs8lDStgAUk3MWHtEA7GxtjMwfHPVyfp8+WDk1ckoloCsdT X-Received: by 2002:a05:6a00:23d1:b0:505:bf44:84ee with SMTP id g17-20020a056a0023d100b00505bf4484eemr13051883pfc.75.1649805225664; Tue, 12 Apr 2022 16:13:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649805225; cv=none; d=google.com; s=arc-20160816; b=A/rSwR0o0SyxBomHLPvuAZtb0GoCp1l6ikQppJFkqIN53nxWDdH+iUIIzwrRAyw6hr o8XilSWNCkrc0wZl7RLRiNqD3VVgsH+tFj/yvHqvNOSIIUvipO+PT02d4Odjn3bPuHYM mZg4ResPCw3L3GwBRdNSd9UEdBJYhvq6LIoQOIMjR+l98536UOnHmdFqfB7MwxXTZhos L0xQyZnzocu5vnUErtF4/BKXQDXvBXahGBEIM6qZSdQAcdEiuyfmcsWeoEWUW71Ugjwk et5RW38mUBJwf9X8fVz1WDLFqVED8Px/Iewf+Aw8Uuaf9n2JSpGQqU2+mCvjGj9bQIsk HrFg== 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=f8gdN3TGhHde4X0lrzNByT1eSh3b1azuUSnhAhs282g=; b=MBWB4TqbNL/l5JGg0CVdl7w6RxKdT4hDQ8A8J9j16NDkFqIS9Lafw/D1Vtw/sl6tUR nbZiNC9WZWjHvvi5bQmlTfvRZGLoSIT9NnMI6xZTQssVq2zETgK6VPvHhNPY6zRjPPqx ed624RDafugrbTM8oy9STheBhIreNRTfK5uwD4/NW0a8KWHchxWYEQUy3a8zXJ5qOC+p x96UJ6+gXyxLVRBN+BVaRITEL7UQVYAy57Oht/0GTAOV1AKa5A1RTmYN+VUQP6izd3Dm vAo/0x3IgpK8XXVl9sM3dVsb9ByXK9mM8LKl/M3/DtEz4M3bcpBo07H0QwOgX/bkoKtg ldmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xMJqyyHS; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id a18-20020a63bd12000000b00387429c6255si3905137pgf.178.2022.04.12.16.13.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 16:13:45 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xMJqyyHS; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C64B921044C; Tue, 12 Apr 2022 14:57:05 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355993AbiDLHaN (ORCPT + 99 others); Tue, 12 Apr 2022 03:30:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351823AbiDLHM7 (ORCPT ); Tue, 12 Apr 2022 03:12:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39C4D17E0A; Mon, 11 Apr 2022 23:53:20 -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 E2C5EB81B46; Tue, 12 Apr 2022 06:53:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C501C385A1; Tue, 12 Apr 2022 06:53:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649746397; bh=3RUt2KxfRxSsYsWSSjP4U2KH/Rhc8qyzgbW8l/zg94U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xMJqyyHSVS+FGDqXAJt2FXwRN7a/hzhvWuKj+7aCbNO2VYS+vzUeuEgMBNrSogD8w /vZjibZ6VOazQNWGF8sMYqoudHw7l+xePeQYnYe6rrfkGX3n/reNqPhp5uDO1OnDYv g+IdDGnK3LbBKizSlTovq4HkzknvzK8KXW3u+rrY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guo Ren , Guo Ren , Catalin Marinas , Masami Hiramatsu , Will Deacon Subject: [PATCH 5.15 228/277] arm64: patch_text: Fixup last cpu should be master Date: Tue, 12 Apr 2022 08:30:31 +0200 Message-Id: <20220412062948.643072909@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220412062942.022903016@linuxfoundation.org> References: <20220412062942.022903016@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 31a099dbd91e69fcab55eef4be15ed7a8c984918 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. Fixes: ae16480785de ("arm64: introduce interfaces to hotpatch kernel and module code") Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Catalin Marinas Reviewed-by: Masami Hiramatsu Cc: Link: https://lore.kernel.org/r/20220407073323.743224-2-guoren@kernel.org Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- arch/arm64/kernel/patching.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/arch/arm64/kernel/patching.c +++ b/arch/arm64/kernel/patching.c @@ -117,8 +117,8 @@ static int __kprobes aarch64_insn_patch_ int i, ret = 0; struct aarch64_insn_patch *pp = arg; - /* The first CPU becomes master */ - if (atomic_inc_return(&pp->cpu_count) == 1) { + /* The last CPU becomes master */ + if (atomic_inc_return(&pp->cpu_count) == num_online_cpus()) { for (i = 0; ret == 0 && i < pp->insn_cnt; i++) ret = aarch64_insn_patch_text_nosync(pp->text_addrs[i], pp->new_insns[i]);