Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2678283pxp; Mon, 14 Mar 2022 02:28:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzN8qGnCiHZ1PcyIoX3rYb5QAKAaH3Xk2eaS+aqfgtK70ydndlBh0AgQnBjIXfvSKg4/wpY X-Received: by 2002:a17:907:3d86:b0:6db:9d9e:e470 with SMTP id he6-20020a1709073d8600b006db9d9ee470mr12842982ejc.373.1647250122282; Mon, 14 Mar 2022 02:28:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647250122; cv=none; d=google.com; s=arc-20160816; b=iAUKW+OWwVM8hQe386E8V/p+4Iz0Jefief7e0SsaS94fy2uxpIolJUI4irPl+SmbvL rAi2dn0IUTCMHFut44Pn1bNCfdEv6JD0dIlKM0kg3oBbKwd/SvWZIsfLKzr3+k0xhcCY 0MdO84T+1O82lPg9tGZCEoOHtmsR32QMgsWrVVeT00x/mRdioe4LAr8phgj6SPLKIT3p sgTjzrUth5QtEQUk51q0+FDjzmnFCKpSOqswf3UCrOvtQS3kO3V0fGeavOv8p/bJbdrt 1gHWa7mDF/HFUkAy/kPFwKfB6l2AFGr+KNauJt24o+NgCQkq1VcZiVr1IRitKkijgs9k j1sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=MHzA6f0O3UXfB/kOk5VVrrZ4oBWtPnkGe12GuOJG4uE=; b=lIJv4S24ql2MkJQtD1RPc7I5ot5HU8d1eZujt8PeNunCJm+9u1wkzDiXqNwFjKyovw 9PwlvQMo5IrkBVIHIPUC3cXCWIvk/swUgv1rpKbGzZdN15eXHzMJzml7xXEbY/598Y/W XiTt08OkM6JaQYBcuVX1W9ZdmxG/Q4fxyrdKRTufO4VOdN5GP7/oxh9DtG+gGZA26UKZ qwLuYpnj5EY4xRNsk34WrlvRMAJLshS2iDHhEmC0iG77q6lAsfH1HQAbyu//g/QlKJNS FPj3MWpTkDo1E5tt57z5dD82A2VIoYree13uQrsiIwR/kiE8tSEGsgu8StMWF3FJ9SQd arCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PAxk8eNd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fj9-20020a1709069c8900b006dbab289ef7si4335078ejc.1004.2022.03.14.02.28.17; Mon, 14 Mar 2022 02:28:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PAxk8eNd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233081AbiCLX6M (ORCPT + 99 others); Sat, 12 Mar 2022 18:58:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231253AbiCLX6J (ORCPT ); Sat, 12 Mar 2022 18:58:09 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEBEC1C7C28; Sat, 12 Mar 2022 15:57:01 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id d10so26604556eje.10; Sat, 12 Mar 2022 15:57:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MHzA6f0O3UXfB/kOk5VVrrZ4oBWtPnkGe12GuOJG4uE=; b=PAxk8eNdgllxX72uRW+A9etKTYEJxmo2qZ2uYPJSlslts+7q5lOrDfAu0MBdqQb6qa +RG9Zq2msE8ROSwnk02pqIxjI3sm2VmMSo6csSgF4BwMK9LRJ8t9nVORGd8uOUFt+oF6 tlPBa7gD3svCrLSPZWV9mBim/PNXNtn6tbCSBFcgJiTqeAEmjHVFvkpZkOYgEWtVdmKp prb9tzUvOuhhIDONOUd6BCOu1wMLmJ/tnbTTisFQD5k3qn3eLQafSgu/Mm+1FxbBWIvG JZRhM8mY/3+XZgh3SUNoRuwdrDIkvgdXAEYFFwTlAg7NbCeaOrJmznNXwf3dOxj4oIUr EJWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MHzA6f0O3UXfB/kOk5VVrrZ4oBWtPnkGe12GuOJG4uE=; b=2UW/8f/LqZc+4EUidwOG9pq5nSZomafS3tcoHqBrjnVS+ZecwryDnrwc91k7hAFsP6 S2825CZ0xDsYPX5ES6J8CFccJXsFOEtsColdZDUR4fIpdtNssNX92Lckp3Lp1z87Bh67 P0t0VRt17t4BOx+6i8/kXTU/PmZchfaAiIQT9SOb4fli/elmypf/sdJJGo4kjbLFIxux zSEP1wkHyaQYV2P6WVtgF9SyBkQcyJ/Uz5f/vPJP2rrQnw1R4iP+g1y+fgW8acbXNWbG DT1skUeUFkBs+XM0T/HrtKtZtrhLzxI1h4W+YFF6qP+km4rL/60iKLanFR1qtoAxNu2+ qYEA== X-Gm-Message-State: AOAM5321PH3so5vqACTJnoSjW3FaG4l8aZMQAwnlM04XE0k3PLEwNxF2 1gTYuaCCGI2InRkHyXA+z3GGX1g9bOjAHHLZHTQ= X-Received: by 2002:a17:907:72d0:b0:6db:4788:66a9 with SMTP id du16-20020a17090772d000b006db478866a9mr14229254ejc.516.1647129420213; Sat, 12 Mar 2022 15:57:00 -0800 (PST) MIME-Version: 1.0 References: <20220312155603.1752193-1-guoren@kernel.org> In-Reply-To: <20220312155603.1752193-1-guoren@kernel.org> From: Max Filippov Date: Sat, 12 Mar 2022 15:56:48 -0800 Message-ID: Subject: Re: [RFC PATCH] arch: patch_text: Fixup last cpu should be master To: Guo Ren Cc: linux-arm-kernel@lists.infradead.org, LKML , linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org, "open list:TENSILICA XTENSA PORT (xtensa)" , Guo Ren , Will Deacon , Catalin Marinas , Palmer Dabbelt , Masami Hiramatsu , Chris Zankel , Arnd Bergmann Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, FROM_LOCAL_NOVOWEL,HK_RANDOM_ENVFROM,HK_RANDOM_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,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 On Sat, Mar 12, 2022 at 7:56 AM wrote: > > From: Guo Ren > > These patch_text implementations are using stop_machine_cpuslocked > infrastructure with atomic cpu_count. The origin idea is that when > the master CPU patch_text, others should wait for it. But current > implementation is using the first CPU as master, which couldn't > guarantee continue CPUs are waiting. This patch changes the last > CPU as the master to solve the potaintial risk. > > Signed-off-by: Guo Ren > Signed-off-by: Guo Ren > Cc: Will Deacon > Cc: Catalin Marinas > Cc: Palmer Dabbelt > Cc: Peter Zijlstra Cc: Masami Hiramatsu > Cc: Chris Zankel > Cc: Max Filippov > Cc: Arnd Bergmann > --- > arch/arm64/kernel/patching.c | 4 ++-- > arch/csky/kernel/probes/kprobes.c | 2 +- > arch/riscv/kernel/patch.c | 2 +- > arch/xtensa/kernel/jump_label.c | 2 +- > 4 files changed, 5 insertions(+), 5 deletions(-) > > diff --git a/arch/arm64/kernel/patching.c b/arch/arm64/kernel/patching.c > index 771f543464e0..6cfea9650e65 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() - 1)) { atomic_inc_return returns the incremented value, so the last CPU gets num_online_cpus(), not (num_online_cpus() - 1). > for (i = 0; ret == 0 && i < pp->insn_cnt; i++) > ret = aarch64_insn_patch_text_nosync(pp->text_addrs[i], > pp->new_insns[i]); > diff --git a/arch/csky/kernel/probes/kprobes.c b/arch/csky/kernel/probes/kprobes.c > index 42920f25e73c..19821a06a991 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() - 1)) { Ditto. > *(u16 *) addr = cpu_to_le16(param->opcode); > dcache_wb_range(addr, addr + 2); > atomic_inc(¶m->cpu_count); > diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c > index 0b552873a577..cca72a9388e3 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() - 1)) { Ditto. > ret = > patch_text_nosync(patch->addr, &patch->insn, > GET_INSN_LENGTH(patch->insn)); > diff --git a/arch/xtensa/kernel/jump_label.c b/arch/xtensa/kernel/jump_label.c > index 61cf6497a646..7e1d3f952eb3 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() - 1)) { Ditto. > local_patch_text(patch->addr, patch->data, patch->sz); > atomic_inc(&patch->cpu_count); > } else { > -- > 2.25.1 > -- Thanks. -- Max