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=-5.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 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 68058C2D0A3 for ; Tue, 3 Nov 2020 09:25:33 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CF8F022384 for ; Tue, 3 Nov 2020 09:25:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="w2iNVyKP"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZwZFa29k" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CF8F022384 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=diwm6k19MhHqMu6iSAcFWYVRZEqAyvTkr3cc+kriciA=; b=w2iNVyKPitwfkVYzZpd8mxoCH 7I+8LuCnFJMZK03UF9N7BMjKirrG/ZNSjXCZ1zqAdFHzx5yqHCMgQXl6duirnrIQUGUcKeY55ppUo 4ebA/R4Pbq0M92ZfDm2Vj1Y28CZVvJQFrgv8nHyaGlPl9F2wNOStpKudtDNqx7VFXo9dksH3hHdhG kt+dXSXMPCoIHaYCXA4yujL73w2qnC88zp4WWq5lF5ZMuoufpVH2dZsCzeaynl24heVRJnU5jgBLy L32ONFmSpdGPrkBBpPBxa/eStcVqCwc+odWm1dMyY/E732tmpIwolvyRT0ZCYchKB2qeHE4QEMds2 Wul/doWEA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kZsXK-0005SY-0u; Tue, 03 Nov 2020 09:23:30 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kZsXB-0005Qx-8K for linux-arm-kernel@lists.infradead.org; Tue, 03 Nov 2020 09:23:23 +0000 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9DAAF22384; Tue, 3 Nov 2020 09:23:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604395400; bh=Pgv3DM0+DuAERlCNdzXMB7DUz3RYvCXuDk5nCVDv3pY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZwZFa29kVpGKbC2Fdoweg/wr9M7qR6xQmfk8lmOMdUEKsm5amVOwx9AmR+CJt1Hep iDaXYn2fF1RQO3uhzvrfcr9nXEO/WL2Q9ZR8kqWwYcmhSrNAKdLXWh6tuZIVBZqQhb J/FN/w9pcbImIdre/xgqq9fpQpqUbojs2z//qI1M= Date: Tue, 3 Nov 2020 09:23:16 +0000 From: Will Deacon To: Jean-Philippe Brucker Subject: Re: [PATCH] arm64: kprobes: Use BRK instead of single-step when executing instructions out-of-line Message-ID: <20201103092315.GC4403@willie-the-truck> References: <20201029173440.117174-1-jean-philippe@linaro.org> <20201102114152.GA3452@willie-the-truck> <20201102225255.fa991f3607c45bbbb161803c@kernel.org> <20201103091305.GA6723@myrica> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201103091305.GA6723@myrica> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201103_042322_049632_8044A15C X-CRM114-Status: GOOD ( 25.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: catalin.marinas@arm.com, Masami Hiramatsu , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Nov 03, 2020 at 10:13:05AM +0100, Jean-Philippe Brucker wrote: > On Mon, Nov 02, 2020 at 10:52:55PM +0900, Masami Hiramatsu wrote: > > > > - patch_text(p->addr, p->opcode); > > > > + patch_text(p->addr, p->opcode, 0); > > > > > > I don't think patch_text() is offering an awful lot to these callers. Why > > > don't we just call aarch64_insn_patch_text() directly, which I think will > > > make the code easier to read too? > > > > Agreed. I guess it's just because histrically used. > > Yes it's easy to remove, sending a v2 > > > > > > > void __kprobes arch_remove_kprobe(struct kprobe *p) > > > > @@ -163,20 +167,14 @@ static void __kprobes set_current_kprobe(struct kprobe *p) > > > > } > > > > > > > > /* > > > > - * Interrupts need to be disabled before single-step mode is set, and not > > > > - * reenabled until after single-step mode ends. > > > > - * Without disabling interrupt on local CPU, there is a chance of > > > > - * interrupt occurrence in the period of exception return and start of > > > > - * out-of-line single-step, that result in wrongly single stepping > > > > - * into the interrupt handler. > > > > + * Keep interrupts disabled while executing the instruction out-of-line. Since > > > > + * the kprobe state is per-CPU, we can't afford to be migrated. > > > > */ > > > > static void __kprobes kprobes_save_local_irqflag(struct kprobe_ctlblk *kcb, > > > > struct pt_regs *regs) > > > > { > > > > kcb->saved_irqflag = regs->pstate & DAIF_MASK; > > > > regs->pstate |= PSR_I_BIT; > > > > - /* Unmask PSTATE.D for enabling software step exceptions. */ > > > > - regs->pstate &= ~PSR_D_BIT; > > > > > > Can we set the D bit now? Would be one less thing to worry about. > > > > Hmm, I think we just ignore D bit above. If someone (kgdb?) is set D flag > > then there may be no reason to prohibit it on the trampoline. > > (Of course they must handle this case) > > Masking debug just for the trampoline would simplify reasoning about > nesting exceptions. Although it prevents from debugging kprobes using > KGDB, it seems reasonable to me because I don't think we can provide > guarantees that KGDB works reliably with kprobes. For example it doesn't > seem like a watchpoint would fire if the instruction performing the access > is simulated by kprobe. Yes, let's just set all of DAIF during the trampoline. Also, while I've got you, If you get a chance, I'd appreciate any feedback on my proposal for reworking our debug exception handling altogether: https://lore.kernel.org/r/20200626095551.GA9312@willie-the-truck Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel