From patchwork Fri Jul 21 09:20:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 123702 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp85187vqg; Fri, 21 Jul 2023 02:42:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlH06f/EaZbKWx7Dys4q35qpTEfvGjBPL4Rx6h20pw8OzuOUmmwD+KFH7hiSw3Y/PBAj0Q0m X-Received: by 2002:a17:907:b13:b0:991:b292:695 with SMTP id h19-20020a1709070b1300b00991b2920695mr1230519ejl.55.1689932569062; Fri, 21 Jul 2023 02:42:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689932569; cv=none; d=google.com; s=arc-20160816; b=ml6ceB0IdVD59E8ZKIulmQnhiBW3mORxZqUqOSnAsT84TfptiaNBh9RXLII9qCpV8d tFERoCXaVrFImTymWfq/LENhSRT8kObNexLZ+fa7eM9QPlePv7PV4GfWrwAHI/BNUHy4 MGrFlPGKvs4ewInwcFOMTfGueR+1WRnninjPuIPc6vhQUAosPxA2mEOYsl8cgWErIRpE dfqb/h/FuKJ+0VJKPMb9FnsD0HVJtThdCPalbDKlAPT+CI22i1MMcNS6vQnzqe8IYoL0 KS1nCYrdrF54ecTKLS+krsCWF+Lq98HU8npTWhxrJhPBol1SkjgvHJ7kp6yAl7An9YHR R5qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=lnSn0ECivsr7eEcD2ltZgdffvBPmL6Z4J6rcVRb2slo=; fh=/oet1gSeaW9/3mGfKvkgVRBdVyooXlcic9qQ9Z0CO/8=; b=l80eb3IIzsBjDvms0NFWNoUBQa8KHA5SagiRN2CbPgVJ0hyUC0lP+mYZX/DLImilmN UeZHNkHE3jYcHGX6spIngll/wjbv/5ZPQpDvQCrQaM7FdjXjN3nz5SnjWqNYoPl+D04+ EbuOdqdDX7UIAqnMtF6jSYuTf3SMQEU3RtDD5KL18Fe6dFdnicg6InGtqH7PNkI7Wo8u 8Bp5yOB47JmDeBz+BmTzTWjXRrlGDOpziIe+a57zbhM/F7314K9Ao4vcoCgAcM6KWm4E sAf0tXr1GHNtpoQJcMn2kC5DQLiQXuO01kcBZ+rIRzGWAGjSXqG+f2N6eqkObmhSQjJP 3JRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qFa3Smpn; dkim=neutral (no key) header.i=@linutronix.de; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b19-20020a170906039300b0098ddf0dcf02si2303855eja.157.2023.07.21.02.42.23; Fri, 21 Jul 2023 02:42:49 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qFa3Smpn; dkim=neutral (no key) header.i=@linutronix.de; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229633AbjGUJVA (ORCPT + 99 others); Fri, 21 Jul 2023 05:21:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231653AbjGUJU7 (ORCPT ); Fri, 21 Jul 2023 05:20:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6BAD2D57; Fri, 21 Jul 2023 02:20:57 -0700 (PDT) Date: Fri, 21 Jul 2023 09:20:54 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1689931255; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lnSn0ECivsr7eEcD2ltZgdffvBPmL6Z4J6rcVRb2slo=; b=qFa3SmpnufMsfmk97ue4xwhxkkjwhLhWoBDYGFS50GhnIdz5i0OS/jFBdDyovnm5wzxDgq MSzVXMcL/RiIhg2jh5yeam/uXOX/NQ0pclZUbNWMC8m4yADjfBtlbbqRJZlQDNSjciIuNt 0g2QOtEF5Pk9YE/0p1lADltzh0SVDo1YNL95QeHiPMTDEgm6ggiVBxxTFCJttz1I7xW511 zdHjErwgwymDUQtb5osrw6R+72MyHfYUIAGCVSo6CiEeU4ImJhhWBymlgmtweCUlXn520d H+vH/tfJTNKmznTilyTWUf7RvJXeC0JfG5dfvVtZSOU/Jf0yRd/zyRrDeHsTHQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1689931255; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lnSn0ECivsr7eEcD2ltZgdffvBPmL6Z4J6rcVRb2slo=; b=jEsxa6cHpQgPde3U7UwP5rO4fNg9DuTc4UbcZJBARNeT49ovoMX4N0P9cOhAiBgXPGPHAo XVW9r0VY2oD5dwDg== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86: Fix kthread unwind Cc: Petr Mladek , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230719201538.GA3553016@hirez.programming.kicks-ass.net> References: <20230719201538.GA3553016@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Message-ID: <168993125450.28540.2663691700893492367.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails 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_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772022733257633103 X-GMAIL-MSGID: 1772022733257633103 The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 2e7e5bbb1c3c8d502edeb5c0670eac4995134b6f Gitweb: https://git.kernel.org/tip/2e7e5bbb1c3c8d502edeb5c0670eac4995134b6f Author: Peter Zijlstra AuthorDate: Wed, 19 Jul 2023 22:15:38 +02:00 Committer: Peter Zijlstra CommitterDate: Thu, 20 Jul 2023 23:03:50 +02:00 x86: Fix kthread unwind The rewrite of ret_from_form() misplaced an unwind hint which caused all kthread stack unwinds to be marked unreliable, breaking livepatching. Restore the annotation and add a comment to explain the how and why of things. Fixes: 3aec4ecb3d1f ("x86: Rewrite ret_from_fork() in C") Reported-by: Petr Mladek Signed-off-by: Peter Zijlstra (Intel) Tested-by: Petr Mladek Link: https://lkml.kernel.org/r/20230719201538.GA3553016@hirez.programming.kicks-ass.net --- arch/x86/entry/entry_64.S | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 91f6818..43606de 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -285,7 +285,15 @@ SYM_FUNC_END(__switch_to_asm) */ .pushsection .text, "ax" SYM_CODE_START(ret_from_fork_asm) - UNWIND_HINT_REGS + /* + * This is the start of the kernel stack; even through there's a + * register set at the top, the regset isn't necessarily coherent + * (consider kthreads) and one cannot unwind further. + * + * This ensures stack unwinds of kernel threads terminate in a known + * good state. + */ + UNWIND_HINT_END_OF_STACK ANNOTATE_NOENDBR // copy_thread CALL_DEPTH_ACCOUNT @@ -295,6 +303,12 @@ SYM_CODE_START(ret_from_fork_asm) movq %r12, %rcx /* fn_arg */ call ret_from_fork + /* + * Set the stack state to what is expected for the target function + * -- at this point the register set should be a valid user set + * and unwind should work normally. + */ + UNWIND_HINT_REGS jmp swapgs_restore_regs_and_return_to_usermode SYM_CODE_END(ret_from_fork_asm) .popsection