Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1477514ybb; Sat, 4 Apr 2020 05:14:38 -0700 (PDT) X-Google-Smtp-Source: APiQypLQk68TXByfzKvoS6+qosgCLs2LljFxD7bLvpSXk87g4jE9BJOEJpPWP+kSJ9RebtEzHdOQ X-Received: by 2002:aca:da8b:: with SMTP id r133mr6592439oig.81.1586002478347; Sat, 04 Apr 2020 05:14:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586002478; cv=none; d=google.com; s=arc-20160816; b=bDx4r3nJULk5l2k2V0P0omh8RWdW6ztT1dhoGc7uzPc5opZNgGTURL+DbKCtU0xsj9 4YS5rcA+61dTZh2l+zT5ArPv6CzBA7jJeFQ37bVOUnqWInJJHZmwtIVkTlz02Pp607Yh HRnX3XMiKrNvKbUwAOU92GKIl8g5xB6WQ0PnlxLUBoVpvLAMHMPXHPUfLgu1sK4J7YKP LVhtocEklEQdXMZlvk4+iiSle6f0ovlODfrPrUyz6MqiOiIfCTgL8P1cPKdjbR1fz0UB EsTl5T95tP5N7xTxmgqDSTgHqx80CxNBNugRzQ1iczRLvmGYjaKb7KfM28DtYW1oNWpV iRVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=jKltLIjkeugNXvKZ/WNOjs3yWnJYwRe4Lc/bVmXm/3E=; b=IRjClruosaCo1tpx4Lj4PRMmdN4iJHVKAlKbRcV1O1bHtVgtjjv0fVQlpZKNUYXKE1 hlaueCOT1LPwyGSMX03STZH33a+2dqex5/9buo39Grd5fUqxs6D5Bp7OaiVum5eISrPt sBaSWbRlD5TxGQgpRK/St8lkJF0ZAQY7SV0h2WOMOMuLSlTNOWEe5ghs+d4TQw9+ul0L 8NHjpEdAUVrcKQaQthAijXPG4/jNlKlbGhXZAaDwjhshBDrQY/Ug6/r2aMOn0m9PvHTn CVzDukucRvbjbU8xDM3R7GyzQs81g/mbxkvRbEBFAIyW7RaFr3eAv5Y75wJqSBwhO7EV QJOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=RgVJg0wg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j26si5221869otk.98.2020.04.04.05.14.24; Sat, 04 Apr 2020 05:14:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=RgVJg0wg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726269AbgDDMMf (ORCPT + 99 others); Sat, 4 Apr 2020 08:12:35 -0400 Received: from mail-oi1-f194.google.com ([209.85.167.194]:39393 "EHLO mail-oi1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725943AbgDDMMf (ORCPT ); Sat, 4 Apr 2020 08:12:35 -0400 Received: by mail-oi1-f194.google.com with SMTP id d63so8697532oig.6 for ; Sat, 04 Apr 2020 05:12:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jKltLIjkeugNXvKZ/WNOjs3yWnJYwRe4Lc/bVmXm/3E=; b=RgVJg0wgr143G4gyzDbbfm84LsLH3MP4SN7MaIkYorAoVDOBWyb/mqeqd/llZlUALK pLOIJVHAXJ7+DwM8KcJEYnfUrevmL8hDEkZ/97Bp0ubUMgkETckeKob2oHdooiBOjPr3 rriSFYQXyrtdLZ63XdkfzTqKQnT0ak5J596o7hBoouU6OSZJZHm9fjqZkFJTSTYEbQS7 7jpm0dVmQsP6BVViUdq/XOgAkGrqCq705tOsDII+pSJ/6Xp2C22g2JIm5HujNedbTOk/ u2M1MideUCCoOEGi150OaW2iKtBiCAQTEXiz4tcpxZLbeOK+BimEdjw0BjbuYQ9r/WUl XMBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jKltLIjkeugNXvKZ/WNOjs3yWnJYwRe4Lc/bVmXm/3E=; b=nRr2MGSRY1uuIJzblkj0PxUFgh/5KhccqFHJzLR5NRS4J5+rvye/By3Hf9IZAzSQ/x 3zJTGovs1NbW9+mpAsgowoAxnA5sG68f2jP1YCoXRDmMUAJMt9LqQ8kDtB+yV+CLJqO3 ExeBj6Bo48H+G3oUiZoK2oUckxXaucxUFHzYpj7HqhWrmtQmjUrlFr7ApsS6BXh26EMW fn46lH3vFVjKp3zx5+FQ/Q+prsFz7HEzvg5aqU4/5pW/aTCc4LrIMTmuVeMAyYIV5m08 y8IKznIEJpQOr2Yw3xdXT2m+vNeXdgDSmdKPsourNibUgCQohuvPl9hOlIuzmpbF7BI2 KwnQ== X-Gm-Message-State: AGi0PuZdkXdMEht6L6e5kw8kAkS2Vnyn3Zp3JcyxRQVGMf5nRSJPVsiK tmuY9muj1mF/W49T7SQHVs04F+Z+c2M6Ixmv+4v8EA== X-Received: by 2002:a05:6808:56:: with SMTP id v22mr6104012oic.116.1586002354371; Sat, 04 Apr 2020 05:12:34 -0700 (PDT) MIME-Version: 1.0 References: <20200401003233.17fe4b6f7075e5b8f0ed5114@kernel.org> <20200402101733.1ef240faeaeada6e4d38ae80@kernel.org> <20200404121428.596911ba5653f8b18a80eab2@kernel.org> In-Reply-To: <20200404121428.596911ba5653f8b18a80eab2@kernel.org> From: Zong Li Date: Sat, 4 Apr 2020 20:12:24 +0800 Message-ID: Subject: Re: [PATCH v3 8/9] riscv: introduce interfaces to patch kernel code To: Masami Hiramatsu Cc: Palmer Dabbelt , Paul Walmsley , Albert Ou , linux-riscv , "linux-kernel@vger.kernel.org List" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 4, 2020 at 11:14 AM Masami Hiramatsu wrote: > > Hi Zong, > > On Fri, 3 Apr 2020 17:04:51 +0800 > Zong Li wrote: > > > > > > > +{ > > > > > > + void *waddr = addr; > > > > > > + bool across_pages = (((uintptr_t) addr & ~PAGE_MASK) + len) > PAGE_SIZE; > > > > > > + unsigned long flags = 0; > > > > > > + int ret; > > > > > > + > > > > > > + raw_spin_lock_irqsave(&patch_lock, flags); > > > > > > > > > > This looks a bit odd since stop_machine() is protected by its own mutex, > > > > > and also the irq is already disabled here. > > > > > > > > We need it because we don't always enter the riscv_patch_text_nosync() > > > > through stop_machine mechanism. If we call the > > > > riscv_patch_text_nosync() directly, we need a lock to protect the > > > > page. > > > > > > Oh, OK, but it leads another question. Is that safe to patch the > > > text without sync? Would you use it for UP system? > > > I think it is better to clarify "in what case user can call _nosync()" > > > and add a comment on it. > > > > The ftrace is one of the cases, as documentation of ftrace said, when > > dynamic ftrace is initialized, it calls kstop_machine to make the > > machine act like a uniprocessor so that it can freely modify code > > without worrying about other processors executing that same code. So > > the ftrace called the _nosync interface here directly. > > Hmm, even though, since it already running under kstop_machine(), no > other thread will run. > Could you consider to use text_mutex instead of that? The text_mutex > is already widely used in x86 and kernel/kprobes.c etc. > > (Hmm, it seems except for x86, alternative code don't care about > racing...) > Yes, text_mutex seems to be great. I'll change to use text_mutex in the next version if it works fine after testing. Thanks. > Thank you, > -- > Masami Hiramatsu