Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2967928rwr; Fri, 28 Apr 2023 20:53:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5vDvOHAtS/ZbQgbvWJKDM3ZIHZHJEq0pfCKhWVVAZ65Uwphtpq/aQoCSIh6zY/ITAEhwcv X-Received: by 2002:a05:6a20:4321:b0:f6:7bb8:c8e5 with SMTP id h33-20020a056a20432100b000f67bb8c8e5mr10145306pzk.6.1682740407526; Fri, 28 Apr 2023 20:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682740407; cv=none; d=google.com; s=arc-20160816; b=rutEHaONbWjYjh44O2Ijluvdu6l8oKGCUNHPR94M87LUKvVPDiJPtC9Q+asqlcnh2R GqKwWkERkA5kz0uYNeRyGJsM1ijsqXQWtpFwVhRzRHpeAeyZQS2F466cQqK0FLvSQGfL Vmx3GFVvlLW33xOIxQNzZhUDKAoFJs1WavbN3ul+cIky6kyVXXl9EdHmsugtU2Sp7VLu VYqjqZNBEAyQ23oziXbkPjzfZ0xCCkvkJhnW3Vgmnb9Zz8tMLkzJ2CbBDKtvyb/H3P6T 8xV4Ok5aTZsm0E8SEvrN+KMYiGA51TY4jtZpegg//wcoNYLjg0RKR/T2/dA8TeCF1wT+ xPhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=7hEykoL+DtEVvM5AQ/oXB71vM8bBBliUOGpvgOLSN34=; b=mAmC6hukM/qeQU/9Hl0Yie2GNz9iCu0bzdD5wb3K1PKaoEmmqTMwNW0hEwcr/fwAfK IMcftBBHR+d1SyuDPUsq7+oRqeyjxQtEG/4FTSCpWRLtLqeQS62Km/ETJQqGS7Y1Ggam kZf0rNY0aCWxOWPVk41MrHarqINMSTanRzuBpc7Yd4GTF435qc5RLKJp8rN1UM2Hktzx 3RO8dGwfP4WZ+WfXTT7dvIJq1UgCMq/DkmurfiKIMWz25C617HWJ5Pz2eDsoNBzUw+13 B3YdblO7aOo51wpp3/U19F6g1XRO21dQL8q5CuOF3rpnWjWhaXB3Dcbkd0pm946VmJqt MQmg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v63-20020a638942000000b00518c9f4263fsi24444553pgd.468.2023.04.28.20.53.08; Fri, 28 Apr 2023 20:53:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230317AbjD2Dii (ORCPT + 99 others); Fri, 28 Apr 2023 23:38:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229598AbjD2Dif (ORCPT ); Fri, 28 Apr 2023 23:38:35 -0400 Received: from out0-205.mail.aliyun.com (out0-205.mail.aliyun.com [140.205.0.205]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0E1C26A6; Fri, 28 Apr 2023 20:38:32 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047198;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---.STlDLfd_1682739506; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.STlDLfd_1682739506) by smtp.aliyun-inc.com; Sat, 29 Apr 2023 11:38:27 +0800 Date: Sat, 29 Apr 2023 11:38:26 +0800 From: "Hou Wenlong" To: Steven Rostedt Cc: , "Thomas Garnier" , "Lai Jiangshan" , "Kees Cook" , "Masami Hiramatsu" , "Mark Rutland" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , , "H. Peter Anvin" , "Huacai Chen" , "Qing Zhang" , Subject: Re: [PATCH RFC 22/43] x86/ftrace: Adapt ftrace nop patching for PIE support Message-ID: <20230429033826.GA91541@k08j02272.eu95sqa> References: <38a5029cd2590e04209117740f8912db36eff58f.1682673543.git.houwenlong.hwl@antgroup.com> <20230428094454.0f2f5049@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230428094454.0f2f5049@gandalf.local.home> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 28, 2023 at 09:44:54PM +0800, Steven Rostedt wrote: > On Fri, 28 Apr 2023 17:51:02 +0800 > "Hou Wenlong" wrote: > > > From: Thomas Garnier > > > > From: Thomas Garnier > > > > When using PIE with function tracing, the compiler generates a > > call through the GOT (call *__fentry__@GOTPCREL). This instruction > > takes 6-bytes instead of 5-bytes with a relative call. And -mnop-mcount > > option is not implemented for -fPIE now. > > > > 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. > > Wait! This won't work! > > You can't just append another nop to fill in the blanks here. We must > either have a single 6 byte nop, or we need to refactor the entire logic to > something that other archs have. > > The two nops means that the CPU can take it as two separate commands. > There's nothing stopping the computer from preempting a task between the > two. If that happens, and you modify the 1byte nop and 5byte nop with a > single 6 byte command, when the task get's rescheduled, it will execute the > last 5 bytes of that 6 byte command and take a general protection fault, and > likely crash the machine. > > NACK on this. It needs a better solution. > > -- Steve > > Hi Steve, Sorry for not providing the original patch link: https://lore.kernel.org/all/20190131192533.34130-22-thgarnie@chromium.org/ I drop the Reviewed-by tag due to the change described in commit message. This nop patching is only used for the first time (addr = MCOUNT) before SMP or executing code in module. And ftrace_make_call() is not modified, then we would use 5 byte direct call to replace the first 5 byte nop when tracepoint is enabled like before, it's still one instruction. So, the logic is same like before, patch the first 5 byte when tracepoint is enabled or disabled during running. > > > > [Hou Wenlong: Adapt code change and fix wrong offset calculation in > > make_nop_x86()] > >