Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp2521437pxy; Mon, 3 May 2021 01:50:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjme7U0Ysq7RfiXxGJwqOgZFEtL2205ZXcqxDxMQogWNDkarPuNMVG43VCMcKJMaSLwLb+ X-Received: by 2002:a05:6402:280d:: with SMTP id h13mr19123612ede.105.1620031830671; Mon, 03 May 2021 01:50:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620031830; cv=none; d=google.com; s=arc-20160816; b=bmP/P/I1A8a1fx6TaANxzrYZzCsfysVVsEnONgBoaqQVibvnz8iOHDsGx6CnZMWzby E79Mgjea36bFRZT7DI90cdGTFH5RZphb9K69Fqs0uykEE+DJ5gc1WxIWkiqSBNTlUJAI RANNgZM5/uiT9M8f6s4XaKeP9whsLaTbGhlztS91Oy+vQaejJsi/+iQ5ky4TZMO8R9tp gL7V0RaDBi9h1VoAPC7IpyxxJumRUfs2Z9y2RSqm0Xsz7JIjNyDeDsFErAcu2oQvZs2m bJfpbljxzAmUKgRfQ2L1kMLaDvSnRCeQ/ASbNKkalMbulBfqvtYisaD/UnRtjkoPvpPU C9uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=IeWjvR+4fYFphBgV6kVzXcbgtodKzRO1JVhft24e7tk=; b=ILmnDkkz85SnAeEQw+Bn2GUjytUrDNrZS9WY+aBhEiVbzD7kf6GFmo5MzSAU7Lf9dr 3kA4XI9dz4Df8Rj5kAvTF6tRkDtnnWuuXB8J/WIKWsYfXQ9mxL8lPcxsmzaEaM91r7ud HtTzD77muXiuaDPWTxfcu4NUInvWbUdUDllRwMwF0HO5K9NvJhpiLzwXgdq801/qRtOo W1d6ZNWupNDTlLPIorSBkjMnM1gGicQIMkvkM79ZOJdDHapeEhGvPbjtfBdIdcYdXpx6 8Y2sWKq7KzfPL9yqw7ux5ZBKdaAJRjlmTrRKFNFjDIMTi0lFuEqGpKWsWzcbNGXfM+xd WO1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=iFzbwZ26; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y20si7890186edw.173.2021.05.03.01.50.07; Mon, 03 May 2021 01:50:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=iFzbwZ26; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S233030AbhECItS (ORCPT + 99 others); Mon, 3 May 2021 04:49:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233014AbhECItR (ORCPT ); Mon, 3 May 2021 04:49:17 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24628C06174A for ; Mon, 3 May 2021 01:48:25 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1620031702; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=IeWjvR+4fYFphBgV6kVzXcbgtodKzRO1JVhft24e7tk=; b=iFzbwZ26b0nAA7RhyhQg9VFODsf3YnhqgM/+OHG/c+7lOD3TcoZqHrLNn0B6Zk92uMJypq EMfQGlbmMPPfgMNACYlFzro6h/vl31R+EH3yXfSI/+eBurwB9wnVUMCDr+PHYuTYtbR2U7 qs7xpEaDuEK+ndRLUf79Z6h3fxdi9oTFEl/PiQDppjLxVXW48bykIeiKLwkh2Cto5s37IM LU7wqMOyYZioPrORQbQHWpyD9MPGPkF5MvhBSRakPHd9FkIKpXGmH85DaKrmTQjij8ZLzI DsLgO6e9JouJy9BzoyghhBnh1nKX2xzXO2NdxW8hi3Zp4Zz6cClDUv2v/mUUDg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1620031702; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=IeWjvR+4fYFphBgV6kVzXcbgtodKzRO1JVhft24e7tk=; b=PI/NN62S0I/FLzpIf3OhvuA3TTN/BQ7iGjzrtqwnXQe0FQ/H5h9PF7/t6wC4kFUR1zDqim 2tG8UxtR0lMuiXDQ== To: Anand K Mistry , x86@kernel.org Cc: joelaf@google.com, asteinhauser@google.com, bp@alien8.de, Anand K Mistry , Andy Lutomirski , Ben Segall , Catalin Marinas , "Chang S. Bae" , Daniel Bristot de Oliveira , Dave Hansen , Dietmar Eggemann , Fenghua Yu , Gabriel Krisman Bertazi , "H. Peter Anvin" , Ingo Molnar , Jay Lang , Jens Axboe , Juri Lelli , Kees Cook , Lai Jiangshan , Mel Gorman , Mike Rapoport , Oleg Nesterov , Peter Collingbourne , Peter Zijlstra , Steven Rostedt , Tony Luck , Vincent Guittot , linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH v2 1/2] x86/speculation: Allow per-process control of when to issue IBPB In-Reply-To: <20210429184101.RFC.v2.1.Iadd904c1764f3bfe260db30fe41bdb9b8f98533d@changeid> References: <20210429084410.783998-1-amistry@google.com> <20210429184101.RFC.v2.1.Iadd904c1764f3bfe260db30fe41bdb9b8f98533d@changeid> Date: Mon, 03 May 2021 10:48:21 +0200 Message-ID: <878s4wdwyy.ffs@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Anand, On Thu, Apr 29 2021 at 18:44, Anand K. Mistry wrote: > > -static inline unsigned long mm_mangle_tif_spec_ib(struct task_struct *next) > +static inline unsigned long mm_mangle_tif_spec_ib_on_leave( > + struct task_struct *next) > { > unsigned long next_tif = task_thread_info(next)->flags; > - unsigned long ibpb = (next_tif >> TIF_SPEC_IB) & LAST_USER_MM_IBPB; > + unsigned long spec_disabled = > + (next_tif >> TIF_SPEC_IB) & ~(next_tif >> TIF_NO_IBPB_LEAVE); > + unsigned long ibpb = spec_disabled & LAST_USER_MM_IBPB; > > return (unsigned long)next->mm | ibpb; > } > > +static inline bool ibpb_on_entry(struct task_struct *next) > +{ > + unsigned long next_tif = task_thread_info(next)->flags; > + unsigned long spec_disabled = > + (next_tif >> TIF_SPEC_IB) & ~(next_tif >> TIF_NO_IBPB_ENTRY); > + return spec_disabled & 1; > +} Why exactly do we need _three_ TIF bits and this non-intuitive inverted logic? The existing mode is: Issue IBPB when scheduling in and when scheduling out. Ergo the obvious approach for making it more finegrained is to split the existing TIF_SPEC_IB into TIF_SPEC_IB_IN and TIF_SPEC_IB_OUT and have the existing mode both bits set. Thanks, tglx