Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4274837pxb; Tue, 2 Mar 2021 10:48:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJxd79TBdgj73sLZ+Iryewl8mssmIGNUY0JhX4Tdi11SHY0xr9zXqFzyal8p+MSkeEaIANND X-Received: by 2002:a17:906:8614:: with SMTP id o20mr21386226ejx.386.1614710889800; Tue, 02 Mar 2021 10:48:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614710889; cv=none; d=google.com; s=arc-20160816; b=1GEjHOooQsnq5w+VJyuU9W9L/YthjQigUkTTF69YKtAw/FnHA5NuP8yDP6RMcf1LUA TiUhVkAotzEGY0eUPwqfmMdI4oEFvmliT4OnGADGCktoku3QYUBswBYXHAC5MPP70clJ e9N/wC0lU66/dOlhbM9u7a19rHPaN7zbKV71+LMpewRz+shGxWrRIJ5ZvIXDU9V5/ix5 47vFY1Uk5Dgn1wBqJ/VABovuWLy8YDprB2VOk7SwtUVO8GxMR00jd470ZYVWpqF1KD/T vkNIDpF2D9Q021MNmFT3+jFhCGmZEy4LnOnuOyPA1WxBBWzsaSinlj88544P0VRzIkbF kDCA== 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=Lt0ZrrfvV73542xvDnq/D/d6Q2m80AcjPIABo7omNsU=; b=XhZ8KLcVSM0aK7ev799L0rzZNVdH2y+7CcupPZMIikfF7G3GFd6Hj16PBVWGvGs2jo Gdhk0/HK6vtCVYgDpqwmTGGH2DLnJ5dG+2Z3D7HssLYFeRbAZvTfGnZ0zWHI3BVtg3m2 bt8ycsc0WuwQKuNSqxLng6lz7ib//uBRATIUhwYNVSLmWV1z5Trg5mDYC/GpTUP1NO6c GH8dF0uP1WUXWW695o+/gi2na7qjJz8tQ+TDWAZ6vqCXp0+66Ia2/wUqnrIFR+cd0ooD ORpeJ8IfmNDaKLlYj/enTAmJ1AJE+noU0Hy/CZRiGFjqJgwdHvNIopQZyuDAzjMWDvT8 7waw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="LFinN9m/"; 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 i2si13846293eje.75.2021.03.02.10.47.45; Tue, 02 Mar 2021 10:48:09 -0800 (PST) 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="LFinN9m/"; 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 S1576674AbhCBEcB (ORCPT + 99 others); Mon, 1 Mar 2021 23:32:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:52396 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443711AbhCBCXL (ORCPT ); Mon, 1 Mar 2021 21:23:11 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6BFDD614A7; Tue, 2 Mar 2021 02:22:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614651750; bh=twucalpitITdHszx7+x7EMGhA3/YxluCVY+oR0edqW4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=LFinN9m/tx28kMdWUQbQb8VIklLB1k4t8oBFCQWx3cLQ/kN3j6SEjnM0roIDjMS5h PGtbAcXUayBAWIwpUcvcj1+UhtPEgmszxmpjJe/CVR3iZtsnl1MoF6nSheHaD6blH2 /FYY6D+DNyG0SbiBikm0pYVSzSRFOpeQrm8SxIidXKiWo+l78XE6HOCCBmyxJIvzvr 0wbgz3n1+2/GGhfTnYQb7jKMSrm8Vh7VSRxN4ixMAeYjpxyp41AUtt0WIcdUxxHLul xXyUOs932wF0bhN5pZCRHNRsw6jra/tjRD7mQPl+C62zvGAIsf5UbzOFmk0itiIDE8 kCo2exah6Xysw== Date: Tue, 2 Mar 2021 11:22:24 +0900 From: Masami Hiramatsu To: Oleg Nesterov Cc: Andy Lutomirski , Masami Hiramatsu , Peter Zijlstra , LKML , Anil S Keshavamurthy , "David S. Miller" , X86 ML , Andrew Cooper Subject: Re: Why do kprobes and uprobes singlestep? Message-Id: <20210302112224.6b3568434be490fbfbdec790@kernel.org> In-Reply-To: <20210301165130.GA5351@redhat.com> References: <20210301165130.GA5351@redhat.com> 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 Hi Oleg and Andy, On Mon, 1 Mar 2021 17:51:31 +0100 Oleg Nesterov wrote: > Hi Andy, > > sorry for delay. > > On 02/23, Andy Lutomirski wrote: > > > > A while back, I let myself be convinced that kprobes genuinely need to > > single-step the kernel on occasion, and I decided that this sucked but > > I could live with it. it would, however, be Really Really Nice (tm) > > if we could have a rule that anyone running x86 Linux who single-steps > > the kernel (e.g. kgdb and nothing else) gets to keep all the pieces > > when the system falls apart around them. Specifically, if we don't > > allow kernel single-stepping and if we suitably limit kernel > > instruction breakpoints (the latter isn't actually a major problem), > > then we don't really really need to use IRET to return to the kernel, > > and that means we can avoid some massive NMI nastiness. > > Not sure I understand you correctly, I know almost nothing about low-level > x86 magic. x86 has normal interrupt and NMI. When an NMI occurs the CPU masks NMI (the mask itself is hidden status) and IRET releases the mask. The problem is that if an INT3 is hit in the NMI handler and does a single-stepping, it has to use IRET for atomically setting TF and return. > > But I guess this has nothing to do with uprobes, they do not single-step > in kernel mode, right? Agreed, if the problematic case is IRET from NMI handler, uprobes doesn't hit because it only invoked from user-space. Andy, what would you think? > > Uprobes seem to single-step user code for no discernable reason. > > (They want to trap after executing an out of line instruction, AFAICT. > > Surely INT3 or even CALL after the out-of-line insn would work as well > > or better.) > > Uprobes use single-step from the very beginning, probably because this > is the most simple and "standard" way to implement xol. > > And please note that CALL/JMP/etc emulation was added much later to fix the > problems with non-canonical addresses, and this emulation it still incomplete. Yeah, I found another implementation of the emulation afterwards. Of cource since uprobes only treat user-space, it maybe need more care. Thank you, -- Masami Hiramatsu