From patchwork Wed Apr 6 14:02: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: 12803505 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 17E8CC433EF for ; Wed, 6 Apr 2022 14:04:14 +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: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:In-Reply-To:References: List-Owner; bh=8IolPwKXBX5McsRjeqtmEY0VDZwGXZa9zjgEr5wVFak=; b=ArDmA7BGiOr3s2 NEGhXQUkqMoxsT3+auHJEhsrLuTskyN0myuw7vNn6I1m93bi+h8/EWoPHNxr5A3ZTtvOaVwOV4zFk m8+naZKQHo2Gqr4lD4SxrPhjGewWWI7FuS1LuQ+XnErvgu5sQttJjxcSb5T+J9AAr2lMUKBTH0YSI +J9aXRB7L/B4o6c7LkQGGAV7n+zMEMyCNxlLwTuU/bzcg+Dlg+GFGh/r814ppX3EjmjSCxqKCKEWC NY/GQt+ylOLvZ7H3DrX6AIOpM3gFJkCu/BVFvPLyWV4dxWEc4sKhMV8tEwjaAAfdma1Rx92jdvufD D9dhHxPl3Q1jnjvBInaA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nc6FN-006Phy-7L; Wed, 06 Apr 2022 14:02:57 +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 1nc6FK-006Ph9-48 for linux-arm-kernel@lists.infradead.org; Wed, 06 Apr 2022 14:02:55 +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 AC0CD616E0; Wed, 6 Apr 2022 14:02:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66E13C385A6; Wed, 6 Apr 2022 14:02:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649253772; bh=EWVfkY7LZ4Dzf52FkYxnRsdOJExYj9Q5zThM/LqPWUM=; h=From:To:Cc:Subject:Date:From; b=jVZS4kFB1zE34Twugtd7xwaS7QwBjEMO5gFzNi6IAg3AyYMCsLS2hld8xVrCmgWf6 kzmAgDUWqIKOHhyY1FYC+SZsvbv/CrgNEe6o3eNwadCKZXtsYbFEQDIYYS8cCQjhep xepPxhsACdfpZ8a3CVO2xf5vk6a2RFW0OaB04hZQwXb3nYWmDsH6OcqZ5B6JnvdiRC GQopA77VDw11FwUuZKNSDlxNL3FmjJTJeGyYsppw38GP5ToILvGZez0jVMpE4UV4Ix Vix4u0Y3QVdt836tvPbUwCit4CipXnCTRiomViK6/s4eyrDCVKyE2J/hDAvdF4TTdY PQqDet16psZmQ== From: guoren@kernel.org To: guoren@kernel.org, arnd@arndb.de Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Guo Ren , Catalin Marinas , Max Filippov , Masami Hiramatsu , stable@vger.kernel.org Subject: [PATCH V3] arm64: patch_text: Fixup last cpu should be master Date: Wed, 6 Apr 2022 22:02:21 +0800 Message-Id: <20220406140221.727300-1-guoren@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220406_070254_239015_40ABFF6F X-CRM114-Status: GOOD ( 15.25 ) 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. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Catalin Marinas Reviewed-by: Max Filippov 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]);