From patchwork Thu Apr 7 07:33:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 12804561 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D5C06C433EF for ; Thu, 7 Apr 2022 07:35:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CjkP916AN62ZXRwAKvrosN9DnwqMMin1TIa5cGuNKmg=; b=4p1bsnAMAAK0Tf 66pC85Hcgrn4ulBSkQHGxeF0+2pLmhIncvcqAqoeJr720nKr5WGu+w7ILB8ljHTo0Vx9NnU3kMozy Vospq8kqKW0hzRhd0ZR4hKV4IkRZVnB1BquLwp2r2y/bovLBRKFSfZW4I3zjn++rtVvSb1u61RBO9 yFUiGjhSL02bITuRVaBtu0tGND4VHW8W8jrjF9416QLdOOGyPDZItL7k3Sq0aFN8Xbszdjobx61qj RmyYjjYiLj9skvdmObztfOwrOKHuDR+cVWPyJ/fOI397Vy8vRThZ3VU0TV0sukaWravx/2zW/e/1p UKkCzpk2IQ3K9i60w4Qw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncMeq-00A0Nk-Hl; Thu, 07 Apr 2022 07:34:20 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncMeV-00A0Er-Re; Thu, 07 Apr 2022 07:34:01 +0000 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 5B62561BE7; Thu, 7 Apr 2022 07:33:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43CB7C385A4; Thu, 7 Apr 2022 07:33:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649316838; bh=4wIhTQJZp3+FhQY+sjwWCoJ1fY2jda3dTtRoplMPuzA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qT2zXYE3CQHTLuX5QZZPQHikYbHh7VPe0bAHwwvmUvmMUnWQIyfU+k7F3AfDIvyRi DbQJ6qiQIryUX2TPGaCeCLRIsJKYDUtVi2eW9wk/oS4lUJw8TeMVaDawYhr+g7X8U3 BD/tIW0R3G5pA+cnnSBuTCL9yC6b2NqcdjvEtbeyIEFds6kbkFoaEJ60l1CqnYGp5C wuxNx22nM3sMr0zTrDhJ0Z36oEmgAqj8rk2NkpqWkUNRDlvhwyx3zToIQurA2FvotF fTUpZW/MoL2A1cwRv4njUeB8q1emqKBkULf3pSwP3zJi7/NivB+2LX/3X/WfQDDEH9 88qBx7bdrkZLg== From: guoren@kernel.org To: guoren@kernel.org, arnd@arndb.de, gregkh@linuxfoundation.org Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org, linux-xtensa@linux-xtensa.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Guo Ren , Catalin Marinas , Masami Hiramatsu , stable@vger.kernel.org Subject: [PATCH V4 1/4] arm64: patch_text: Fixup last cpu should be master Date: Thu, 7 Apr 2022 15:33:20 +0800 Message-Id: <20220407073323.743224-2-guoren@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220407073323.743224-1-guoren@kernel.org> References: <20220407073323.743224-1-guoren@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220407_003359_975629_39139766 X-CRM114-Status: GOOD ( 14.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Guo Ren 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: --- arch/arm64/kernel/patching.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/patching.c b/arch/arm64/kernel/patching.c index 771f543464e0..33e0fabc0b79 100644 --- a/arch/arm64/kernel/patching.c +++ b/arch/arm64/kernel/patching.c @@ -117,8 +117,8 @@ static int __kprobes aarch64_insn_patch_text_cb(void *arg) 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]); From patchwork Thu Apr 7 07:33:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 12804562 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 60017C433F5 for ; Thu, 7 Apr 2022 07:35:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YaAmNOsNMvDdrwkQSJ1jNCud9BAaTZ8Bw8a6JufkQjo=; b=xjdlTzV6mq4znG Knpt/0xbM+fmYP3I6thXqGq50loLtzYoil1ail9+ckNKpRhceYPvZjrHXSZIfYs/cVH/lBLidIANR X6DK8RqBdeotBRc8yCzIGJE0STBWxmCcRTlJdO2ANUrDqGjGZfo7wln3afBv/qJQFGZ9QtOIcAFFz N2hf/UPYC+4v8rAIfODz6b2VfiARmXO7lqOga9aKfKFGyNvnaZdwPO9CI41rvGaAT3GKTTc61c4vx f/xqwEPrcgo8zW4yLjjVCpUTquSsUL0CjYieuGVTicgRf2rBXwUJzzhPs7z2tVDQcsrdqnFydhwq3 WKz83ebN9ykOjLJMuxoQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncMf9-00A0VI-Iy; Thu, 07 Apr 2022 07:34:40 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncMed-00A0HG-HL; Thu, 07 Apr 2022 07:34:09 +0000 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 B6DAD61E07; Thu, 7 Apr 2022 07:34:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 393E2C385A9; Thu, 7 Apr 2022 07:33:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649316845; bh=Lq9EhyRijx1cfe4dEDp+AdieXvyyIhRaAjpvB7W8v1s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hMVhkWDgaKW7xR+gIWxFoU2fJjcz2m9cvJ8rHJeSJCXIE8aZFvMrAW/BStymn+T2e 0rQr1eouZWS72DT7IKe+1k5LDSIb14lGiB+icEK/brzv4tOvm8icRFHRL95VcKxtUL WKlxZBpH7tUCydPdcBBWDN6RxszZJ113iYYEws+rF9PPybUOBUyLvUzANlkMGkcX6J V+sqIB/OYIjO02NwbgMFGYlRo3P75PgRvJOHwQGjrpv/mhYTLklZFHQlBWW93nWPqX 2nkdfKPS73HXnFtJXT6u/bToYSDyfA66rkbKPTRPvu2a9yU44xYRjRQmhcb0/elX+b bV5un3MkOIEFw== From: guoren@kernel.org To: guoren@kernel.org, arnd@arndb.de, gregkh@linuxfoundation.org Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org, linux-xtensa@linux-xtensa.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Guo Ren , Masami Hiramatsu , stable@vger.kernel.org Subject: [PATCH V4 2/4] riscv: patch_text: Fixup last cpu should be master Date: Thu, 7 Apr 2022 15:33:21 +0800 Message-Id: <20220407073323.743224-3-guoren@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220407073323.743224-1-guoren@kernel.org> References: <20220407073323.743224-1-guoren@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220407_003407_676609_0C242641 X-CRM114-Status: GOOD ( 13.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Guo Ren 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: 043cb41a85de ("riscv: introduce interfaces to patch kernel code") Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Masami Hiramatsu Cc: --- arch/riscv/kernel/patch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c index 0b552873a577..765004b60513 100644 --- 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)); From patchwork Thu Apr 7 07:33:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 12804563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 94719C433FE for ; Thu, 7 Apr 2022 07:36:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0rwtt1RhhIyX2fo1HT/ocTtay2F8UbcagSsVCsdo9DU=; b=og7UkzYPUS2Nys InxwEBJvn0Y2vrdfv0Bux/0qfuHzxtGSNZShw4nEGL5BW0ZZE3fC4Sq9nwdwqL2dvCblpjvrVU3Fe zffoRdF2llXnHJrlyf0FiAkGwHUkUPzD+Y1ay2ucTdO43wcH1EKTTqEwXZzptmTwxQRRo+Q4hANLx 2B7jsjx/kJFuhP/BW/lhykXFXIltR4NnQpVpiuUL3sCJ3JEpkVg6tezhr8DQnW2b2zFcSiMYhGD8B WSoNLHgE+0hXdUzZ0vJeZtlByltY5/WC8f09N/n422nnHJTgL8IXQ6QukAJeKAqlTJeVAeC+czM1Y wJR+07DbueXwzii2vAaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncMfb-00A0jp-Fx; Thu, 07 Apr 2022 07:35:08 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncMem-00A0Lt-Ly; Thu, 07 Apr 2022 07:34:18 +0000 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 1B1AF61DC9; Thu, 7 Apr 2022 07:34:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A285C385A4; Thu, 7 Apr 2022 07:34:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649316855; bh=R2FPA9lWSXRgAzEvdehN22kFHU9pjAW3rQXXGDs7cDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OJlKMZ2aKAzw5+LeIolJB5pwRD23zC0v1DrROL+aQ2kRGcMIIsMaieRXUWJ7LPfML nyQDGC2U5D8LolVa+curnmQgS1G1eTqJU6hy8o/PK6TXWuqokCFmrNHffffMrLMcA6 eoih0F/3+r8HL51n2Y7mCAaPGw3hQ8FZazxhD6WzjaSFyku4Tu+I6JekSksdCexMLf 9i77RxagVWEuZ+JIeMVfyempj2xEj4HBmmTL0UVXgD1ZAMhk1YTlOJcfiQVibNXquT I877fj9qjzdWkWW46gJ59BkzmgKvL4eg2L9Nj5v0EgdHTWjw9L4HN2Dni12GE86edn Y8htB1f4ONb3Q== From: guoren@kernel.org To: guoren@kernel.org, arnd@arndb.de, gregkh@linuxfoundation.org Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org, linux-xtensa@linux-xtensa.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Guo Ren , Max Filippov , Masami Hiramatsu , stable@vger.kernel.org Subject: [PATCH V4 3/4] xtensa: patch_text: Fixup last cpu should be master Date: Thu, 7 Apr 2022 15:33:22 +0800 Message-Id: <20220407073323.743224-4-guoren@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220407073323.743224-1-guoren@kernel.org> References: <20220407073323.743224-1-guoren@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220407_003416_805263_814D53C4 X-CRM114-Status: GOOD ( 13.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Guo Ren 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: 64711f9a47d4 ("xtensa: implement jump_label support") Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Max Filippov Reviewed-by: Masami Hiramatsu Cc: --- arch/xtensa/kernel/jump_label.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/xtensa/kernel/jump_label.c b/arch/xtensa/kernel/jump_label.c index 0dde21e0d3de..ad1841cecdfb 100644 --- a/arch/xtensa/kernel/jump_label.c +++ b/arch/xtensa/kernel/jump_label.c @@ -40,7 +40,7 @@ static int patch_text_stop_machine(void *data) { struct patch *patch = data; - if (atomic_inc_return(&patch->cpu_count) == 1) { + if (atomic_inc_return(&patch->cpu_count) == num_online_cpus()) { local_patch_text(patch->addr, patch->data, patch->sz); atomic_inc(&patch->cpu_count); } else { From patchwork Thu Apr 7 07:33:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 12804564 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D8C30C433EF for ; Thu, 7 Apr 2022 07:36:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=y6jLx5a6srwsz1FbWatCV8kdgjhdzfveItARkKQQm8s=; b=c/p9YcUWvC4IVE FWbg40A4AUdU/wcScc2IuDOF5plqmtoHAMD1XEfvz+noh3V+CpwVfidPEvcQIYMVZsHVPg8gDsSbq LLEGHA/R9KaqucHVIrb1zKnqSj9JwnZdzRpML7PpExN3opBKOhvdc60tINYhJCWUORZrBSejSnJg0 MmOR3OuDOWuqyQjh2fJsPQZ1E7oTPot5wkmVh4atz0nHkSIaMgLpQm7nW7BO0lAx+w0epJAnugnB3 C/b4KJi/aXfW13m0iz0LcKL0PnmJexMNeJqk7/NT5Lxe0/+E+dHq4sstxBZu176cKWt51p4OSzqRU KRO+NSnss4Pj+AnzLnXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncMgC-00A14O-5K; Thu, 07 Apr 2022 07:35:44 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncMf4-00A0TG-Mi; Thu, 07 Apr 2022 07:34:36 +0000 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 2F6EF61E14; Thu, 7 Apr 2022 07:34:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1673CC385A4; Thu, 7 Apr 2022 07:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649316873; bh=1ucMhnW8irziJNfuECEH3MHXjDK0nSaVyUwaETtw+gM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KelGW/uTUVx5N9Sv2N8w8R9JRf21b8/HoKoyaUYPNOJgWfIKzQiF7OA1rp6QJv+BJ ytq/FiqmKFGSs0Sfa/N6mEuTZZcNJZCxF2cXvcwjhXcqSOTZQOSw+U0ZP4WPx9hrTG Igt3l6DJxAD6TkFv//g0cb7uzlxGM9LBCU/dDhX1u+m2/qq5O7bjJE8Kir697/BF/C gPykEqhRL5iAJtMqzxMZC1C51u9klzBs0AiIiqvKs+dxQdsK35GL29VVfT3QNbarg4 8fcYqEARmNuNjvOoZkd1vpBFpU1v2Bx7dFPjVeYLo38goAcOYyknOr6/WuWAhMceSM MC/wBEJ5daT5A== From: guoren@kernel.org To: guoren@kernel.org, arnd@arndb.de, gregkh@linuxfoundation.org Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org, linux-xtensa@linux-xtensa.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Guo Ren , Masami Hiramatsu , stable@vger.kernel.org Subject: [PATCH V4 4/4] csky: patch_text: Fixup last cpu should be master Date: Thu, 7 Apr 2022 15:33:23 +0800 Message-Id: <20220407073323.743224-5-guoren@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220407073323.743224-1-guoren@kernel.org> References: <20220407073323.743224-1-guoren@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220407_003434_813156_221FC5FD X-CRM114-Status: GOOD ( 13.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Guo Ren 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: 33e53ae1ce41 ("csky: Add kprobes supported") Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Masami Hiramatsu Cc: --- arch/csky/kernel/probes/kprobes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/csky/kernel/probes/kprobes.c b/arch/csky/kernel/probes/kprobes.c index 42920f25e73c..34ba684d5962 100644 --- a/arch/csky/kernel/probes/kprobes.c +++ b/arch/csky/kernel/probes/kprobes.c @@ -30,7 +30,7 @@ static int __kprobes patch_text_cb(void *priv) struct csky_insn_patch *param = priv; unsigned int addr = (unsigned int)param->addr; - if (atomic_inc_return(¶m->cpu_count) == 1) { + if (atomic_inc_return(¶m->cpu_count) == num_online_cpus()) { *(u16 *) addr = cpu_to_le16(param->opcode); dcache_wb_range(addr, addr + 2); atomic_inc(¶m->cpu_count);