Message ID | 20230123205915.751729592@infradead.org |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1823439wrn; Mon, 23 Jan 2023 13:27:44 -0800 (PST) X-Google-Smtp-Source: AK7set87gB7PguG135UkZj/XV+vHCss0OVmGtKFgiYh+2eHN6PGLAVWXOE7m9zavd7DFK72kXSUk X-Received: by 2002:a17:90a:3:b0:22b:e872:4612 with SMTP id 3-20020a17090a000300b0022be8724612mr850087pja.42.1674509264088; Mon, 23 Jan 2023 13:27:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674509264; cv=none; d=google.com; s=arc-20160816; b=JXbewzL16GA2IEHUD953Bl/ids4GtU0My9GZnY3U4RfzMnav8QaWwteg69wH8oeKzP DUbQszK9hGTVaZs4ULXZZy8dGqtjK3+mveH7CUuRI3ZksfmcY15wFlnzoA/isP5r17Bq zHkcOgpJGqwY1xYseMkR6WPYjHzJSAHbuARwzkcspqB6HvTgehWWcRbJ/D5ZrbfLtVpU /eHCTfj/rAG0Onope5pZxeDmzXIza+K0+gd4oLkmB5jD/s6ALZdnZTM1VdANI+5hE9Fd ZMaU8RHfOZsVPdqdedSvnAhvHx/jOvbwuwNl+siZ/VsaMXfANYuPB8P3uyDoZW3dDyjc CQqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:user-agent:message-id :dkim-signature; bh=/FCuGsFHP8h1o3jLXAdPuiCn2YaK3Z2EA/HYKgflCd4=; b=R5SNH4L8QKaGM6wi01s3/PGBAUFymJxnT+WUSkwBsUH43ok8IC1dsP+Ji/zxHqWWx8 q7ZR41WQjp6pgXtCzX92RXUUdshCVYl5rDZcp5rUF7Tpzztit/U8VOg+n2kczsRT9J+o M5NbQ3cLl9oTn+DbCd8wO48ySQ6UGyDyB6oYE82NQkLIoJN9ARQTDUNXR89Fj4D/5wxu vUgRSYVIFiqbzI6LUo7EcEsSJvCtQy6xYKpUIFpKsNAMFt81WszILjVRMa4jizvVXgzX LrbxEU0Y1Uq0J2I2p8WJVOUz7Hm2l4CZoKuj7oGDhaxpigTZncuseLFhVksh6BPTe2fL Qp+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Scw69z18; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v19-20020a637a13000000b004b243c2b001si21364pgc.366.2023.01.23.13.27.31; Mon, 23 Jan 2023 13:27:44 -0800 (PST) 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; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Scw69z18; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232772AbjAWVHD (ORCPT <rfc822;rust.linux@gmail.com> + 99 others); Mon, 23 Jan 2023 16:07:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231130AbjAWVHC (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 23 Jan 2023 16:07:02 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BD7130EA2 for <linux-kernel@vger.kernel.org>; Mon, 23 Jan 2023 13:07:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Subject:Cc:To:From:Date:Message-ID: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To:References; bh=/FCuGsFHP8h1o3jLXAdPuiCn2YaK3Z2EA/HYKgflCd4=; b=Scw69z188z5U9ca/nvjFeycnxn Hcm1XgNaqDzaknTjChLGgjnv3eKib+iPl2n0cr3/x7H0ei94DMih94kJszIWT6DVLQM1mUuDNqsht IiVu+aUpTq0bm0ECXDJP1xrA6WPsSOmNBdUO/2uFs5igmY30u5ZqsIUACWcqUA4hcdo8maTZ81fBy VJfw072fSYjreryNDwR5YGJrQ/AgABViMyoOQFaa/rN+rh6WsZBJC5YsPk+9o0ck2eLJSqRn00uqN fkseM+RBUP49gaIjd65pKjL69MawmYvrPMqrbLbeLJvzfPycSveR1VYi/w0i7tlDDizg16MLxZPpq F5cwNM7w==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pK41f-004Wrb-BM; Mon, 23 Jan 2023 21:06:47 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 5FE3E3002BF; Mon, 23 Jan 2023 22:06:45 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 25A57201DD9B0; Mon, 23 Jan 2023 22:06:45 +0100 (CET) Message-ID: <20230123205915.751729592@infradead.org> User-Agent: quilt/0.66 Date: Mon, 23 Jan 2023 21:59:15 +0100 From: Peter Zijlstra <peterz@infradead.org> To: mingo@kernel.org Cc: tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, peterz@infradead.org, jpoimboe@kernel.org, jbaron@akamai.com, rostedt@goodmis.org, ardb@kernel.org, linux-kernel@vger.kernel.org, erhard_f@mailbox.org, ndesaulniers@google.com, mhiramat@kernel.org, sandipan.das@amd.com Subject: [PATCH 0/3] static_call/x86: Handle clang's conditional tail calls X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755850226107649800?= X-GMAIL-MSGID: =?utf-8?q?1755850226107649800?= |
Series |
static_call/x86: Handle clang's conditional tail calls
|
|
Message
Peter Zijlstra
Jan. 23, 2023, 8:59 p.m. UTC
Erhard reported boot fails on this AMD machine when using clang and bisected it to a commit introducing a few static_call()s. Turns out that when using clang with -Os it it very likely to generate conditional tail calls like: 0000000000000350 <amd_pmu_add_event>: 350: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 351: R_X86_64_NONE __fentry__-0x4 355: 48 83 bf 20 01 00 00 00 cmpq $0x0,0x120(%rdi) 35d: 0f 85 00 00 00 00 jne 363 <amd_pmu_add_event+0x13> 35f: R_X86_64_PLT32 __SCT__amd_pmu_branch_add-0x4 363: e9 00 00 00 00 jmp 368 <amd_pmu_add_event+0x18> 364: R_X86_64_PLT32 __x86_return_thunk-0x4 And our inline static_call() patching code can't deal with those and BUG happens -- really early. These patches borrow the kprobe Jcc emulation to implement text_poke_bp() Jcc support, which is then used to teach inline static_call() about this form. --- arch/x86/include/asm/text-patching.h | 31 ++++++++++++++++++ arch/x86/kernel/alternative.c | 62 +++++++++++++++++++++++++++--------- arch/x86/kernel/kprobes/core.c | 38 +++++----------------- arch/x86/kernel/static_call.c | 50 +++++++++++++++++++++++++++-- 4 files changed, 133 insertions(+), 48 deletions(-)
Comments
Hi Peter and Ingo, On Mon, Jan 23, 2023 at 09:59:15PM +0100, Peter Zijlstra wrote: > Erhard reported boot fails on this AMD machine when using clang and bisected it > to a commit introducing a few static_call()s. Turns out that when using clang > with -Os it it very likely to generate conditional tail calls like: > > 0000000000000350 <amd_pmu_add_event>: > 350: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 351: R_X86_64_NONE __fentry__-0x4 > 355: 48 83 bf 20 01 00 00 00 cmpq $0x0,0x120(%rdi) > 35d: 0f 85 00 00 00 00 jne 363 <amd_pmu_add_event+0x13> 35f: R_X86_64_PLT32 __SCT__amd_pmu_branch_add-0x4 > 363: e9 00 00 00 00 jmp 368 <amd_pmu_add_event+0x18> 364: R_X86_64_PLT32 __x86_return_thunk-0x4 > > And our inline static_call() patching code can't deal with those and BUG > happens -- really early. > > These patches borrow the kprobe Jcc emulation to implement text_poke_bp() Jcc > support, which is then used to teach inline static_call() about this form. > > --- > arch/x86/include/asm/text-patching.h | 31 ++++++++++++++++++ > arch/x86/kernel/alternative.c | 62 +++++++++++++++++++++++++++--------- > arch/x86/kernel/kprobes/core.c | 38 +++++----------------- > arch/x86/kernel/static_call.c | 50 +++++++++++++++++++++++++++-- > 4 files changed, 133 insertions(+), 48 deletions(-) I noticed this series was applied to x86/alternatives versus x86/urgent, even though this appears to be a regression since 6.1, as Erhard hit this issue in that tree. Additionally, a new change in LLVM main [1] causes conditional tail calls to be emitted even at -O2, so this breakage will become more noticeable over time. Is it possible to expedite this to mainline so that it can be backported to 6.1? If not, no worries, but I figured I would ask :) I have a backport of this series to 6.1 prepared already [2], where it appears to work for me but I will get wider testing before sending it after this is in Linus' tree (regardless of when that is). I figured it would not hurt to have other eyes on it ahead of time though. [1]: https://github.com/llvm/llvm-project/commit/ee5585ed09aff2e54cb540fad4c33f0c93626b1b [2]: https://git.kernel.org/nathan/l/cbl-1800-1774-6.1 Cheers, Nathan