Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3914325pxv; Mon, 5 Jul 2021 08:44:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBbnH0V0ceDMhFhqyW4Lh9drozF4m9Bba9CUQyGbiTOnCoOpup/ckbnnVoyIkVu7qCdbva X-Received: by 2002:a05:6402:1711:: with SMTP id y17mr13974507edu.334.1625499865767; Mon, 05 Jul 2021 08:44:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625499865; cv=none; d=google.com; s=arc-20160816; b=hlpA5r0GLbV1EogUurLk7n6VOTsyQcf4nazsQ60Ez3HvIWZkKuwlgK1WsMP+ZCnjFi la5jBtg5GieuQj2XzoDyOIU3GcR1LgGQa3k3oFwPufFbY2OunatUjaqNkVo8DlU8mReY rdjh3llovhruSlPzspgUz7K3f1PcgtRhWDL2W7Rg3/U3QpDEcKAaPT36rPfM4OQ7pm9N iMCvpKzBjqenfsKi/HAjOfZBUMJblGrfHbZi0iUMPn3cWTfl4/v4BodGbnO7jnfPCzoF XXJCw9IkKrCNQ7c6Vfp80VGv83AIer2ox7JdYlMpFzmgMZig9e9j7EtK76874VCAbz5h c4gw== 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=bVNCdX7ndUUNICYWDY18b1RoxxOM6eGKkJqslO3pts0=; b=pUbJSprSRwIyg6cSeD93dYXbiOSg91L/aKHRcH36wGeExkUkVu6KLTP5T58pKLZDUR Se+eoJmXDj4Yp0ECcbbFenpngRn+N8WeZpsggvWxgftTdNShhHo7i7LivnceCl3bOSi3 6oAIBrHnaOVhNnVkYSJB2qNOwXJ8Csi1dSOEmE/ipX2oGecW9sK3sNiYZI/q882b8kUb 95bLPT0f5g8F5sosgyfXZ/OSg1sEQP65FwEPf9lqTtydmiryTZySPeRxOw82XvT6MW/3 G1l2Edx1dYlLDCjYd25HShNaIG87hdRw4bB3pCapyyuBJwiRdEx5RVsiT6/Li9GD18O0 B9Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QCNMDoMD; 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 dd27si5084431edb.441.2021.07.05.08.43.59; Mon, 05 Jul 2021 08:44: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=QCNMDoMD; 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 S232130AbhGEPpi (ORCPT + 99 others); Mon, 5 Jul 2021 11:45:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:39312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231899AbhGEPph (ORCPT ); Mon, 5 Jul 2021 11:45:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 885F9613C1; Mon, 5 Jul 2021 15:42:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625499780; bh=aD6J7wwTkd61kTD+YwKULBV5n12ddnDruf6BnlnuTWo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=QCNMDoMDhQ2wMpmN9RARXSdRUbarHsBSqXjBYzVz7WJMfPaB8IGGeX7UmgOF0mna2 b6OIgpWM9cYIYPRaPFVm0+kMLV8nhUfH4mpd9jedJ78esavfDRwug3o7cNM0PPKJIp WysteeLoGKNKK+zxsamgNhAbuK5qeGbDnJ83no3TGnyeMZYg95IysbtYErZZCaHOcw uYuQks9iveRmvZOP24S5ECMD9DjoX2xho/bzkcKGv9RoVFTtEGqbKq/E1AjFEc5tjY pS+0eFNY7ZkiMQ0ASrLTQIp91v9k90qposfQrRjPUDhOgM9gGqdYRdRhTlAq5E5oYc AORBYg4FHanEA== Date: Tue, 6 Jul 2021 00:42:57 +0900 From: Masami Hiramatsu To: Peter Zijlstra Cc: Steven Rostedt , Josh Poimboeuf , Ingo Molnar , X86 ML , Daniel Xu , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, kuba@kernel.org, mingo@redhat.com, ast@kernel.org, Thomas Gleixner , Borislav Petkov , kernel-team@fb.com, yhs@fb.com, linux-ia64@vger.kernel.org, Abhishek Sagar , Andrii Nakryiko Subject: Re: [PATCH -tip v8 11/13] x86/unwind: Recover kretprobe trampoline entry Message-Id: <20210706004257.9e282b98f447251a380f658f@kernel.org> In-Reply-To: References: <162399992186.506599.8457763707951687195.stgit@devnote2> <162400002631.506599.2413605639666466945.stgit@devnote2> 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 Mon, 5 Jul 2021 13:36:14 +0200 Peter Zijlstra wrote: > On Fri, Jun 18, 2021 at 04:07:06PM +0900, Masami Hiramatsu wrote: > > @@ -549,7 +548,15 @@ bool unwind_next_frame(struct unwind_state *state) > > (void *)orig_ip); > > goto err; > > } > > - > > + /* > > + * There is a small chance to interrupt at the entry of > > + * kretprobe_trampoline where the ORC info doesn't exist. > > + * That point is right after the RET to kretprobe_trampoline > > + * which was modified return address. So the @addr_p must > > + * be right before the regs->sp. > > + */ > > + state->ip = unwind_recover_kretprobe(state, state->ip, > > + (unsigned long *)(state->sp - sizeof(long))); > > state->regs = (struct pt_regs *)sp; > > state->prev_regs = NULL; > > state->full_regs = true; > > @@ -562,6 +569,9 @@ bool unwind_next_frame(struct unwind_state *state) > > (void *)orig_ip); > > goto err; > > } > > + /* See UNWIND_HINT_TYPE_REGS case comment. */ > > + state->ip = unwind_recover_kretprobe(state, state->ip, > > + (unsigned long *)(state->sp - sizeof(long))); > > > > if (state->full_regs) > > state->prev_regs = state->regs; > > Why doesn't the ftrace case have this? That is, why aren't both return > trampolines having the same general shape? Ah, this strongly depends what the trampoline code does. For the kretprobe case, the PUSHQ at the entry of the kretprobe_trampoline() does not covered by UNWIND_HINT_FUNC. Thus it needs to find 'correct_ret_addr' by the frame pointer (which is next to the sp). "kretprobe_trampoline:\n" #ifdef CONFIG_X86_64 /* Push fake return address to tell the unwinder it's a kretprobe */ " pushq $kretprobe_trampoline\n" UNWIND_HINT_FUNC But I'm not so sure how ftrace treat it. It seems that the return_to_handler() doesn't care such case. (anyway, return_to_handler() does not return but jump to the original call-site, in that case, the information will be lost.) Thank you, -- Masami Hiramatsu