Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp892955pxf; Thu, 8 Apr 2021 15:41:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgwXm3mK7OvNq1szy/QBl9TsSwxqHVIPDShO+m1AoamXseaOsuLzSFjp/rcF7bHn6F2c9w X-Received: by 2002:a50:bb05:: with SMTP id y5mr12208858ede.384.1617921685108; Thu, 08 Apr 2021 15:41:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617921685; cv=none; d=google.com; s=arc-20160816; b=zkuEPSkP3yZdsocDuwwOCRplADyuVVcL9NZKpJ84mCrQILz0+iZ1mLA5baxKB5uFcl 6KYoMHN/82vF9Biv6cSmENagwIr9R/P6CDYsFXUZkaeyTs1FEvAYBEU2AinVQP/p1Bev nYm0B6WFSyaAQBKczt0PIgso2aEnw1KkPa+Tu1H427JAC/ZNJida1hmzA8Q8IUOHiN1V ORyYl00FrSIu/0sQFW1ItePfw26U3PDXOPUOlboid84QJWrsOEBiLpZl7CifyaV499A1 CURzGCXKC0Lhq52sB7HRBy0JMM/1sQ385J6z8YF1nU2g2wioKaWkogMakZq4+stdOmAZ HWRw== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=sCeoKWDdPs845LYEe/FHOruHaO8YZndwUuQ15GqE8Yg=; b=OLlVRaPT6dgNpQ04i+eVPZITJ4IzfuwRQKdkR0kDL+jepuAUaQaofMy/F9CdsUUnpk EP6/hqgZAlZYlHkxtqBQjVUdE1YiAjAoPo/8JRpTbYXKLPg3BWiMASgFJu1H16INVt1V gthFna4g6F/N6dhJa3pIEuhzeZLkmhoq7gfvX1/8O6pteLhEAsdhe33Kd4NAwavXaWeo M9ldbX2ehz9Gpwmyak9/zANG7p9EBJtFg+Vd0x7yVS+TMTmWxmvnG3+7usp0lU1vDp7G 6Nn69pbw8vbTelkQmGD8YN1KtbbaHZceaFblEXEAMHHpZht1ECwvoWLRvIVBWEvQAWSn D7SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZoU0pR6F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b11si828328edz.197.2021.04.08.15.41.02; Thu, 08 Apr 2021 15:41:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZoU0pR6F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232643AbhDHWjO (ORCPT + 99 others); Thu, 8 Apr 2021 18:39:14 -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