Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp8842808rwp; Wed, 19 Jul 2023 16:41:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlFYgnwW4BMcRzk0iEj1q7LNXj5c0Kp+CaIpTAdVMzZG/6pH1y+SUhC33Q8wKtBzw73hpuU8 X-Received: by 2002:a17:903:1248:b0:1b5:2b12:6f50 with SMTP id u8-20020a170903124800b001b52b126f50mr4448401plh.12.1689810117129; Wed, 19 Jul 2023 16:41:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689810117; cv=none; d=google.com; s=arc-20160816; b=INovYtiVuaQ8HBsTIC/6RKNRa+nX+8Wg/4qzSk4hb40bLrrozgZEM5wZZT6iaMht35 jaRQ6w1pGxCXTgGzka0RP/lFomGMH2PPL1V2LRNP1sfnqrAi/84Zuzb4ox2bdJRlkTq/ gUM0sXWGMKhztRqGVJhimqX9f6j8+fbAdWQDE1UugiFM29W+3emvDVKmxhakxnFPW0Zd C65cpAe/LLLyBgnrriFRk7CLUcouGEpf6OphiDbdshWvZvDsXttW2whORTL694NIVCKz +bR6QhhLazsGp+ASLETJKiyBx75fymVHXY6Tn5yJwjUp2WKELizNoXdAMAZ1t0wu/Knt 9Xsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=jTr98cbfIEn+KMnsZ9BHZQog4u8XIIFp9YPbC/+jfSc=; fh=/O8gMaZmPTW/PLKbzxWNSdpBBpj/h6cLHmMN60688Tk=; b=ySrDesBP//tjFFnov4hw6vxTWqfBSenkRAjpzpUAxrpV+b9xd1TpS5WTdNwKwyonSF n4V20N/Bv3WtWvT/lqC/NFvHusHgBCtXktPB4dqLxLgMwkoGW06K+6VeeMsyKQlwkMTr CEU502JF5/yRjRHFGDYdIypanyRutpen0eu8UUpqm0tJ5FPZ3PWN20G8dKyfPQ+4P78T inS2qrhlAmSqAw9hRUrNnqiGxYwKjgk3HPjeAXeoUx/kRbkxIb60v0AtsK7RKxaWh473 Mx/VOtZxZ24IG/TYE+NwUQpDDHEGQ+DYFZjicsxB3H/SuqyxHkaltWtfZOfr+pgM87ZC +PKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SvZp7drh; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p18-20020a170902c71200b001b8ae9058d3si4209271plp.516.2023.07.19.16.41.45; Wed, 19 Jul 2023 16:41:57 -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=@kernel.org header.s=k20201202 header.b=SvZp7drh; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229782AbjGSXbR (ORCPT + 99 others); Wed, 19 Jul 2023 19:31:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229512AbjGSXbQ (ORCPT ); Wed, 19 Jul 2023 19:31:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 595A19D; Wed, 19 Jul 2023 16:31:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CB95661877; Wed, 19 Jul 2023 23:31:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9984EC433C7; Wed, 19 Jul 2023 23:31:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689809474; bh=nIP5gyEY0YLO/0/+3zjFCWyJEEXhcI/AJRJ4WfpyQyA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SvZp7drhtHKzINff+lrYfxX2axIKzm3bwzgT3eAEmUOfnIUGiNN+HX7YbcckmXrBa Fffo7pFSS/EuDLW0c+fjXMiNVzwqY+ou7e4c7dWQuWHSFQZGqxGpOhvbiFl4R0ambe SZ0xEZzUn1L8b3PffGuT06szb7jJC9GRuhRqpegotCLBWaJh0MS+alUFvBBUT/UJol j4yMmlaMMMSDr4eX+nWRJfKmbJPIHRmJlNaSaZori8QO5em8YVZw5MCvEN9yWvksFb Y6P1L88WteQIrPgRz7dVTwshZsfWKrWArkv9b1+ApHrjPp2nfQsL9Wh54MeeEONmLA cK1vwYHagqwyA== Date: Wed, 19 Jul 2023 16:31:11 -0700 From: Josh Poimboeuf To: Peter Zijlstra Cc: Petr Mladek , Brian Gerst , linux-kernel@vger.kernel.org, x86@kernel.org, Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Sami Tolvanen , alyssa.milburn@linux.intel.com, keescook@chromium.org, joao@overdrivepizza.com, tim.c.chen@linux.intel.com, live-patching@vger.kernel.org Subject: Re: [PATCH v2 2/2] x86: Rewrite ret_from_fork() in C Message-ID: <20230719233111.kqafaqect4v2ehu6@treble> References: <20230623225529.34590-1-brgerst@gmail.com> <20230623225529.34590-3-brgerst@gmail.com> <20230719200222.GD3529734@hirez.programming.kicks-ass.net> <20230719201538.GA3553016@hirez.programming.kicks-ass.net> <20230719205050.GG3529734@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230719205050.GG3529734@hirez.programming.kicks-ass.net> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Wed, Jul 19, 2023 at 10:50:50PM +0200, Peter Zijlstra wrote: > > The below cures things; Josh, did I miss anything? > > > > --- > > arch/x86/entry/entry_64.S | 14 +++++++++++++- > > 1 file changed, 13 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S > > index 91f6818884fa..cfe7882ea9ae 100644 > > --- a/arch/x86/entry/entry_64.S > > +++ b/arch/x86/entry/entry_64.S > > @@ -285,7 +285,14 @@ 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 regs > > + * set at the top, there is no real exception frame and one cannot > > + * unwind further. This is the end. > > + * > > + * This ensures stack unwinds of kernel threads hit a known good state. > > + */ > > + UNWIND_HINT_END_OF_STACK The comments may be a bit superfluous (to me at least) but the patch looks fine. > So unwind_orc.c:unwind_next_frame() will terminate on this hint *or* on > user_mode(state->regs). > > AFAICT way things are set up in copy_thread(), user_mode() will not be > true -- after all there is no usermode, the kthread would first have to > exec() something to create a usermode. > > Yet I'm wondering if perhaps we should spoof the regs to make > user_mode() true and auto-terminate without this explicit hint. I'm not sure that would be worth the trouble / cleverness. The hint is straightforward IMO. > Josh, do you remember the rationale for all this? For what exactly :-) -- Josh