Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp26091imm; Tue, 5 Jun 2018 14:21:31 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKWaOQcXDFjJgGVj5i3XChZTMY1eFYwYDzbgwYgWlTC29uwUHgwna+0y4NXpg8Dd1SUQI3F X-Received: by 2002:a17:902:aa01:: with SMTP id be1-v6mr284231plb.296.1528233691776; Tue, 05 Jun 2018 14:21:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528233691; cv=none; d=google.com; s=arc-20160816; b=xtALpe6eMB/75aDzhB1O9EqcLDukg3H6chOy0FHCmRrGPcKY5LhmAkFI5bhW8hdz0o YgcpmuLvXelCbRyoWPCxnfXXY3f9kiKAPGi69l1FW3W9jAoHzF04nbGHrtiT37jDuHQ6 CZ75Z2vcrFSxS6iQB3heqAHzonrrX+vd340qF7/rLFo+Kn9p5sKjU2bmBEJ1zbopONBE 8i4X7Xt0xAaD1MRvKxXKgN9f/nJtjkg3SLRg9W78FjfKnfLq5j+N0W2tmtPKwZi0QZdR ZXm5NV8lGtMU5v61EYWvjj8A8CVciMyGAfbfRpF9m35ajJtSVSQ4QnnD+t4vfzUdO5Ca r9kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=rkXrBvPYoE5uY9oMXeD6FTxUnX2UBxelFlroIdD9SPc=; b=jjI59v2PV572R9YkmebDoF0lJAHtunf2OqyblkBj4Eb0/VCY1QFrhFX5b/8zhNHSmm TPml7UFjDyEOSQxhUFX8S14eDW1e7mJZAXD+Yd7YJVUH/0jcqI8dOw0jU4+3319Y+dRR GNFds0oeSNPm9ZoFhKkPmTsAzaye+T+Y6PzucrP0XbFP4rnrtlg/wwRI0BYc4Ul8tC16 iKC1dFeZ9J25SYmFQPAm7Nox5sItMrXyhlpT//uGbbJUa/PGMX8aoFE4Q6FD8jrX5H42 QaErAoOp6GeLxvXbxQjS5aKc6sd10hFmwdCgR8Crt82emk3GsB+TATEUi/EZQMl52nOw Nl3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CmVnIpfD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 89-v6si11042596pfi.362.2018.06.05.14.21.17; Tue, 05 Jun 2018 14:21:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CmVnIpfD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752166AbeFEVTy (ORCPT + 99 others); Tue, 5 Jun 2018 17:19:54 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:35063 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751635AbeFEVTx (ORCPT ); Tue, 5 Jun 2018 17:19:53 -0400 Received: by mail-it0-f68.google.com with SMTP id a3-v6so5312934itd.0 for ; Tue, 05 Jun 2018 14:19:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rkXrBvPYoE5uY9oMXeD6FTxUnX2UBxelFlroIdD9SPc=; b=CmVnIpfD8z/JAocdi4MV369DnjrGCkmxzX1S4PA7F12B8Am9dRAeYeG80VbXU2UMN6 /qpzZH/P4VNQ1IIJLoU8hhcrPzPdusMJWKBt3adKmNGW5EJiKRIRFxteb++1ZvfdKmDP QD00KeDQjsOhKEewgi7TrleIEIQWxJUjKU6kdZfNWke2+Tjjc34b59nYaM6xhj+zy416 hHnSmULxguRcnT5tn+wiWUf/6zO0PDW3OnbzOhKoMFwIgyS2jg4ZyY6KRkiLQ7SBcyMi CMVCKZtymT3EY++s8BbZKLKmoBEWDBxjE2GSDiUVzbWWHLgGAuQMBMrp7EaKdZ754zex F7Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rkXrBvPYoE5uY9oMXeD6FTxUnX2UBxelFlroIdD9SPc=; b=ZhZRKLE1icxZDAO/O8UetolbLxQZeRK1X4WV264P1Df6/p2rgudQq3lNkK+0A8G7GL EYSCS5Gzm47iDL4Zhq9aPPVK706cH/7qbEgU2sPPlKH3yLUmJ0IHxaCfXODDkFMMxurb mrnSVhp8Pe000p1bXTSiY4lc70RRASxxnNlttAb6m90uSEjViHpQfJ938CM7PWpOcaLS sfaLJ6xkmRHsp5gmRNPbT42bWFFig2ja1rETRXK17+r4xVJyAioi5+zEkzVHSoJIeRFk HS9J4b6u7keWjgdT3jEA1cpBSU2RES/l/mFWm8TZTmU/kcB2qZSll80jiloCAJzbn++o /EKw== X-Gm-Message-State: APt69E19sDRq78lmAJdFpLiNn5BUh1qsx1+6XsFAmP9y5g/xdiEiruud R4VuF0kUleJo6CK6QsAKqwCif42bgUiUUZo4IpQKig== X-Received: by 2002:a24:5594:: with SMTP id e142-v6mr963306itb.46.1528233592257; Tue, 05 Jun 2018 14:19:52 -0700 (PDT) MIME-Version: 1.0 References: <20180529221625.33541-1-thgarnie@google.com> <20180529221625.33541-22-thgarnie@google.com> <20180604161612.6d48d8d2@gandalf.local.home> <20180604174431.4aabfbf1@gandalf.local.home> In-Reply-To: From: Thomas Garnier Date: Tue, 5 Jun 2018 14:19:40 -0700 Message-ID: Subject: Re: [PATCH v4 21/27] x86/ftrace: Adapt function tracing for PIE support To: Steven Rostedt Cc: Kernel Hardening , Ingo Molnar , Thomas Gleixner , "H . Peter Anvin" , "the arch/x86 maintainers" , Francis Deslauriers , Greg KH , Andrew Morton , Peter Zijlstra , Guenter Roeck , nixiaoming , James Hogan , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 5, 2018 at 9:56 AM Thomas Garnier wrote: > > On Mon, Jun 4, 2018 at 2:44 PM Steven Rostedt wrote: > > > > On Mon, 4 Jun 2018 14:06:03 -0700 > > Thomas Garnier wrote: > > > > > On Mon, Jun 4, 2018 at 1:16 PM Steven Rostedt wrote: > > > > > > > > On Tue, 29 May 2018 15:15:22 -0700 > > > > Thomas Garnier wrote: > > > > > > > > > When using -fPIE/PIC with function tracing, the compiler generates a > > > > > call through the GOT (call *__fentry__@GOTPCREL). This instruction > > > > > takes 6 bytes instead of 5 on the usual relative call. > > > > > > > > > > If PIE is enabled, replace the 6th byte of the GOT call by a 1-byte nop > > > > > so ftrace can handle the previous 5-bytes as before. > > > > > > > > > > Position Independent Executable (PIE) support will allow to extend the > > > > > KASLR randomization range 0xffffffff80000000. > > > > > > > > I thought you were going to write a update to recordmcount.c to handle > > > > this at compile time? > > > > > > I can correctly calculate the start of the call instruction with > > > recordmcount (no need for addr-1) but I still need to handle the > > > different size of the instructions. I don't think I can completely > > > replace the GOT call with a relative call. Maybe I am missing > > > something on the way recordmcount is used? Should it replace all > > > mcount locations with a nop slide? Why is it done at runtime too then? > > > > Because we need to figure out the "ideal nop" thus we need to change it > > regardless. > > I see what you mean looking at the different ideal_nops based on configurations. > > > > > We could have recordmcount.c replace everything with the default nop > > (I've thought of that before), and then we could update with the ideal > > nop at run time, if that helps with this. > > I don't think that's necessary. In proposed implementation of PIE, > kernel modules would not use a GOT call. In the current implementation > the __fentry__ call is always GOT based (6-bytes). I will simplify the > runtime implementation in the next patch set to just swap the expected > size and ideal_nop when PIE is enabled. Actually moving the logic from 5-bytes to 6-bytes is much more complicated, that's why I went with this approach before. I don't think it can be improved much more beyond creating a nop slide in mrecordcount but that's a different approach. I will clean-up the code a bit for the next iteration but that's about it. Let me know what you think. > > > > > -- Steve > > > > -- > Thomas -- Thomas