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 X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A78FC433B4 for ; Thu, 8 Apr 2021 22:39:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 687366115C for ; Thu, 8 Apr 2021 22:39:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232701AbhDHWjP (ORCPT ); Thu, 8 Apr 2021 18:39:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:48026 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232265AbhDHWjO (ORCPT ); Thu, 8 Apr 2021 18:39:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E83F961106; Thu, 8 Apr 2021 22:39:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617921542; bh=T9Xmxojax6GIvmigkpUkfCNwyL8m2lnVcs8esdkHluU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ZoU0pR6FdJu6NdPGeoNs5yO5cYoxyUs5bEwLhoirKPbQrjPHpWtA+GzKhw29LGl5r +sTOldiQ0OL/ST5SCFI0jkDveSexpBw0H8n/gorKyEk80ZGWY39TlpDhicZEMtfueJ RK7rLjeY7NEl9hyAZpceiuMOO+eZtYj0DrDiRLpUkqMBL40n1r/5caoi1xibNPVGlF TdInRWzsqMAGGrEP9lxyyxTGXVRLEd1RV3uaStHZmgwLGQo+AlCh87v4jeNa8iW8oz qeOstpHj1ppXnpMBid3KuC+uYJLqjF6y5MupJiorqVbC6iB3kkQE5V+f1WzFQTWpch O2C2IEeYapqDg== Date: Fri, 9 Apr 2021 07:38:58 +0900 From: Masami Hiramatsu To: Jisheng Zhang Cc: "Maciej W. Rozycki" , Masami Hiramatsu , Jisheng Zhang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Guo Ren , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] riscv: keep interrupts disabled for BREAKPOINT exception Message-Id: <20210409073858.e7b439e99e9e506f4f3847e2@kernel.org> In-Reply-To: <20210408192348.1d50c588@xhacker.debian> References: <20210330021624.2b776386@xhacker> <20210330183316.942215efe8e6e8455ad14113@kernel.org> <20210331222244.45a5807c@xhacker> <20210401093036.037f2abbce7ed5d1e68466b7@kernel.org> <20210408192348.1d50c588@xhacker.debian> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 8 Apr 2021 19:23:48 +0800 Jisheng Zhang wrote: > On Sat, 3 Apr 2021 20:30:53 +0200 (CEST) > "Maciej W. Rozycki" wrote: > > > CAUTION: Email originated externally, do not click links or open attachments unless you recognize the sender and know the content is safe. > > > > > > On Thu, 1 Apr 2021, Masami Hiramatsu wrote: > > > > > > > > Current riscv's kprobe handlers are run with both preemption and > > > > > > interrupt enabled, this violates kprobe requirements. Fix this issue > > > > > > by keeping interrupts disabled for BREAKPOINT exception. > > > > > > > > > > Not only while the breakpoint exception but also until the end of > > > > > the single step (maybe you are using __BUG_INSN_32 ??) need to be > > > > > disable interrupts. Can this do that? > > > > > > > > > > > > > interrupt is disabled during "single step" by kprobes_save_local_irqflag() > > > > and kprobes_restore_local_irqflag(). The code flow looks like: > > > > > > > > do_trap_break() // for bp > > > > kprobe_breakpoint_handler() > > > > setup_singlestep() > > > > kprobes_restore_local_irqflag() > > > > > > > > do_trap_break() // for ss > > > > kprobe_single_step_handler() > > > > kprobes_restore_local_irqflag() > > > > > > OK, thanks for the confirmation! > > > > Is this approach guaranteed to keep interrupt handling latency low enough > > for the system not to be negatively affected, e.g. for the purpose of NTP > > timekeeping? > > IMHO, interrupt latency can't be ensured if kprobes is triggered. Indeed. The latency depends on what the kprobe user handler does. Of course it must be as minimal as possible... On x86, it is less than a few microseconds. Thus it may be a jitter on hard realtime system, but not a big issue on usual system like NTP timekeeping. Thank you, -- Masami Hiramatsu