From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 342DEC433F5 for ; Thu, 17 Mar 2022 16:03:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236310AbiCQQEm (ORCPT ); Thu, 17 Mar 2022 12:04:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236300AbiCQQEi (ORCPT ); Thu, 17 Mar 2022 12:04:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14C217DAB5; Thu, 17 Mar 2022 09:03:21 -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 C66BCB80122; Thu, 17 Mar 2022 16:03:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89C3AC340F7; Thu, 17 Mar 2022 16:03:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647532998; bh=NGiQFPVnfDqZ1ROyWh9ETbUs7TxBnFHdgwPh/4n9jkA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=rh3zXpgLbT6SxqOATKmV9Yg1s5i3qEYz1c57woGTPEB9HVQOvoNJg27Eh+Vpr5bnB 9l5P2ZTbDZaUyjAkAuW69dtO6pyULM2UcfPOa/ltFPnPz77RHcuBH0PVA5FQJ12/RC Vk505u32UA7dKFDT0dy2VxMqKGqWACf/31xxW4OqezMnTHpxYCMn1KQiwkY/kCWZjl tez2KzHX0g5xYLn7LOcGj9kCZD3N5v3/Q8DWhareckpREHZplQyMPK0Lacqa+cRkYa +F+S5yDxaEib1+Rm48oukLIWleLtwPzHRjq6T+UmUWe4bisqNoOKNa4rHPwNTuLNGA 61hyjnnLNxwhA== Received: by mail-ua1-f49.google.com with SMTP id i26so2231972uap.6; Thu, 17 Mar 2022 09:03:18 -0700 (PDT) X-Gm-Message-State: AOAM531bLQ9j5G+gp/Lo/PFiis0JHUWfBPW46CD/bKg5JwkV1cVcXPng SjWhnrtPMTOZbCm2i6hJ3lON1f5MEG/g1xzQyf8= X-Google-Smtp-Source: ABdhPJx56mP1yBItNhpbrH5BO1aKkva0leBOvED1GBx+mkRa6thFGwJA/RpUKcskkXEWf9nO8JBbTl9WVNeKe2iBtLA= X-Received: by 2002:ab0:3785:0:b0:350:c22e:9908 with SMTP id d5-20020ab03785000000b00350c22e9908mr1907268uav.114.1647532997252; Thu, 17 Mar 2022 09:03:17 -0700 (PDT) MIME-Version: 1.0 References: <20220313012221.1755483-1-guoren@kernel.org> In-Reply-To: From: Guo Ren Date: Fri, 18 Mar 2022 00:03:06 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH V2] arch: patch_text: Fixup last cpu should be master To: Catalin Marinas Cc: Linux ARM , Linux Kernel Mailing List , linux-csky@vger.kernel.org, linux-riscv , "open list:TENSILICA XTENSA PORT (xtensa)" , Guo Ren , Max Filippov , Will Deacon , Palmer Dabbelt , Masami Hiramatsu , Chris Zankel , Arnd Bergmann Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 16, 2022 at 10:38 PM Catalin Marinas wrote: > > On Sun, Mar 13, 2022 at 09:22:21AM +0800, guoren@kernel.org wrote: > > 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. > > I couldn't find the original intent in the commit logs (at least not in > the arm64 logs). Maybe the intention was for the CPUs to wait for the > text patching to complete rather than the master CPU to wait for the > others to enter the cpu_relax() loop before patching. > > I think your patch makes sense anyway, the master CPU would wait for all > the others to enter the cpu_relax() loop before patching and releasing > them with another increment. You probably wouldn't see any issues in > practice unless you insert probes in the multi_stop_cpu() function (or > we could mark this function as __kprobes and get rid of the extra loops > entirely). That could depend on micro-arch, trigger other harts' IPI is not guaranteed by hw. > > > --- 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]); > > For arm64: > > Reviewed-by: Catalin Marinas Thx > > -- > Catalin -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/