Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1160176pxb; Wed, 6 Apr 2022 10:07:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLC6fE2+tHZ6xJ3tAFBSdE6/s5zD83E6mvkvJYHPhDkpxgRuECA7sikPwSmX7/tVtbUoFi X-Received: by 2002:a17:903:183:b0:154:61ec:74a3 with SMTP id z3-20020a170903018300b0015461ec74a3mr9652740plg.69.1649264866020; Wed, 06 Apr 2022 10:07:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649264866; cv=none; d=google.com; s=arc-20160816; b=VxROTLnc9yX2Kgpy5zIs056vdVaCnqkyXIlDJ5/7Y6o3migDpaiGk+ZzywJ+ORkbZc TQ24xnHrGje2Vd1C8dihO0N6ox29LiMHfFldJRBEmFZJEP4ec6XuObBRA4XFRSpvwnMr BivuYSUWkX19qbH/W7H/EGZyZPUJn8HWfenueMG5pqjALzt74Vp4xgO1/xIlbm3qNidL T97mXMiKONC9dvNex/NbJcW5zzp71x3Fl7qCe6Dg33ixQQYC0PcyFpL3CQR+RQrls/wU Ifg9hdf/CXDyxzXaI/OHUb2zTpomSUnRAcbCB0mgKIlt8nMzgyMwqcbHWt13iv4jOJxF V5GQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Etuy+q50gTQE86tfzCHGdQx90BKADVyS9ZN4cKWmw/I=; b=SXt55O3XLx/gLqEq48x0JtTYVpkNpz1/x0pDhrJgc+Q5CZ8ACUhAJ+5ICzYPlsyssC fjtB7MrRUtACf75GpYbwXnLicbSbCx1e2zwJjnXEzS162dyTnG5HT4STt1uaFRItxLOz Lv5qpdcoW/N8Bl8rXO00JGcqMsEiHSxV2aDVwanxA4RSUyiGlCbG3THm8bThclv+qNFU t/83EVwwVR5SO+kHxd5wJvC28K/zBA585qNkIywNZpcwRiy58iQ+i5s9KeO2FnJ7ysUy gmnpotA03sD1sc2ozekFPlB2MWDXTO9agUwSd9HkhiRUXUzIllb5NwYpeFpYfqOOhoyD 7CXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ie+v5zV3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id mn7-20020a17090b188700b001c7e26d8fbesi4913798pjb.107.2022.04.06.10.07.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 10:07:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ie+v5zV3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 00928229C94; Wed, 6 Apr 2022 09:52:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238103AbiDFQyG (ORCPT + 99 others); Wed, 6 Apr 2022 12:54:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238133AbiDFQxF (ORCPT ); Wed, 6 Apr 2022 12:53:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 014DF21799B; Wed, 6 Apr 2022 07:17:07 -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 C3B44B82426; Wed, 6 Apr 2022 14:17:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE8C6C385A3; Wed, 6 Apr 2022 14:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649254625; bh=OMfx41/031A0MP+RHm+KFwlRg5XT4Op6fvW1GZ75ZuQ=; h=From:To:Cc:Subject:Date:From; b=ie+v5zV3XbfY5P59UHcq+VjkI8jYwX+M798YCErKW4mWwv0QnMTzYY0jffAZsFU3G NlvREmST3Mo+7tk9Vp8tFVLhFCiuSyJIkSpUxz6C4lQp7KkFTVq4pylTTO7CbyOB8b qQtOHKG+zvk0IRBtTWkeqALBoUjyzccmtfUr63v+sODqL7mIXCl97wfuhgbOegKmjx SrKL4NSIwcwdfxICNvyal+YIFKmN+GtAtnmrPXerskHsKWm1LUkZ7REub0s/5tBAkg paiu7LCYgtynayD8d832/BWLmBKdP9cKgoHq5Bdon9dXOufgzpTLpqeIsn36OZqjYH /rQKYtCcfkKVg== From: guoren@kernel.org To: guoren@kernel.org, arnd@arndb.de, palmer@dabbelt.com Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Guo Ren , Palmer Dabbelt , Masami Hiramatsu , stable@vger.kernel.org Subject: [PATCH V3] riscv: patch_text: Fixup last cpu should be master Date: Wed, 6 Apr 2022 22:16:49 +0800 Message-Id: <20220406141649.728971-1-guoren@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 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 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)); -- 2.25.1