Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp338386lqt; Thu, 18 Apr 2024 17:49:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXFVwyoat6NzjNvhTp/bOVO8dfm4Jv/Ga10ZArMwj1Fft8lPAnnkKKR3e5RrOlZudONQF9i6cy1Mt1z0UzireTxAl5FiWoG5xXdJxMxrw== X-Google-Smtp-Source: AGHT+IFSCevBWMN59iFdUg04a4C25tP5c6HnggSfD5Lx73qoe3ECQwLfdgweLXQ+7nlTNkAk1zo6 X-Received: by 2002:a05:6870:6112:b0:22e:8b02:fb6e with SMTP id s18-20020a056870611200b0022e8b02fb6emr904145oae.10.1713487742863; Thu, 18 Apr 2024 17:49:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713487742; cv=pass; d=google.com; s=arc-20160816; b=paS4Mp1cLOyUyvPH1wFv+JgECDF8BUjC1bFTPsPs+JB0O8kvBTu2ahJhkVMnOKw4FL qL/lSvZ05BNSOLTdavnRlURVNjisr9YaePcrLIhsByEqIYhxuF4QKBVGLf/gA2zN8laJ QYFNxiUqdRbva6O5ZNw584YbrS23eygmn4oV2zI9b2xlTpYpOIIyDuO+Yrli6gLFHtto I63Cz7g5F+M59scA1q0iMoD7CE+XJrIPFOLYBTLhHK5wTF4crH1JR683s+Tumbxhbmyi JmK4FbWYjDM5aCRbGh0Y5HTo2Eurp3qZCSi01j0xxvu++NR8uP8JWRZ6Knt3E+ZiJlbx C3Og== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=kv36pZL0GJVl/T7E7g5nXtrvReWvAqFk0qsaTXOCjTo=; fh=HIgqdCRNsdig6fFZo7mozWuYaG1np7wAWZ9DWXiF+dM=; b=V+EJEH0uZiOSJ57upsD1ttPOIW6I0P5fEuyQEYsIWnsXsSPUFfvK/L8AttM9pPXJUo uX3SUiJxy6YWqsDpU9rst9+3v+fYfPFutwwAD2oAkx14UPUV61+HXWwvfAVLP7TbFxf6 YEq7OxS/h/+sqHcgqZusd+OYiqTNrANatOgZ7DVKkRK67atHb6i+4eKyNuv6dFs7X7MI 80iDtioY/auK0iKzNNG1igFWL2WbCi6wCurC9agN7xXSnKWL8Quje81KZzfAqKjyR4bI ar2YHsB4Mga1PJHh6y46vF/v6uhGgOBoi4AMno/nhwinGVA+RxpR8mJJPXLrtnnBqx6Y 1eDw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LsKULCgS; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-150893-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150893-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id r33-20020a632061000000b005ee3cfc190asi2178582pgm.159.2024.04.18.17.49.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 17:49:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150893-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LsKULCgS; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-150893-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150893-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 291D6B21807 for ; Fri, 19 Apr 2024 00:49:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 617E51396; Fri, 19 Apr 2024 00:48:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LsKULCgS" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CF0910FF for ; Fri, 19 Apr 2024 00:48:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713487728; cv=none; b=UVXNSknqnC7+X83KI0eBzHRZg8KvP9WrjYsFGHxjHmia7/ynQRV4QWx6TIK6FNKs6unhJz+AxteFwR4BupdLfb02ofFOC/SxJhV2VwbecS6luYWInzZLcoVFl4DcXvpMBctKu1+T3lMzPwaEli91fa1x4BrgdQLpwOGLvYgm+WA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713487728; c=relaxed/simple; bh=z3dsRoIho2UFcOVtKxoPrRld9oI+JpMNMnSKgMc1MOk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NDujayytjPOHN1LdVXJgDk0i/vQmj/JUYiPuNRk6L1tSJSthccmISif/2xzXOlG12VqyzRyTi/GLQ3Z+YzKVCBv+VXHIoF8afiLpl3PdmpiMIqZgFEEkKtWxk3bxnybA7hctDWZAlFgH8DJG7atxrGH36EpApPUX3mOEsClF0cU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LsKULCgS; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7434DC113CE; Fri, 19 Apr 2024 00:48:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713487728; bh=z3dsRoIho2UFcOVtKxoPrRld9oI+JpMNMnSKgMc1MOk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LsKULCgSG7XE5q//CHVu+++9qUAwi+aKSRHANZgB6F2Y8YgdfILnwStBM9Yxr7yBi j+j3UmvOxYxg/vACBOvYGwbanu81YRwUM1ySGAFkI0qh2YjZd1W7A4U8uIvEm65nn+ xMupZEAr1JjwukeySn0tQ0YfF52zJutTYUoQFARclNVHCNfcklpB2cnIHzCH8l+7Oe HkB4N6EXaXQkbzYMu44BEJ6h3ydPc1aGylS3nNjCk9KGh1pwjbEVlY9ooAK/yce4SI 9xr3I/l6uIVI4vMwH891loIShfs9VoM69Iz2KauF70eI+zRwpfuaLrxMmKL+OJBrTn nASf+If5AfCxA== Date: Thu, 18 Apr 2024 17:48:45 -0700 From: Josh Poimboeuf To: Andrew Cooper Cc: Pawan Gupta , x86@kernel.org, linux-kernel@vger.kernel.org, Linus Torvalds , Daniel Sneddon , Thomas Gleixner , Alexandre Chartre , Konrad Rzeszutek Wilk , Peter Zijlstra , Greg Kroah-Hartman , Sean Christopherson , Dave Hansen , Nikolay Borisov , KP Singh , Waiman Long , Borislav Petkov , Ingo Molnar Subject: Re: [PATCH v3] x86/bugs: Only harden syscalls when needed Message-ID: <20240419004845.ker26cp3hslttslk@treble> References: <20240417164514.66hgypzxgqxt3ssk@desk> <20240417175723.r4si62d6oqirqadb@treble> <2a490bb4-fd00-46e7-b7c3-bb8ef962d8b9@citrix.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2a490bb4-fd00-46e7-b7c3-bb8ef962d8b9@citrix.com> On Wed, Apr 17, 2024 at 07:01:54PM +0100, Andrew Cooper wrote: > On 17/04/2024 6:57 pm, Josh Poimboeuf wrote: > > On Wed, Apr 17, 2024 at 09:45:14AM -0700, Pawan Gupta wrote: > >> On Wed, Apr 17, 2024 at 04:14:26PM +0100, Andrew Cooper wrote: > >>> On 17/04/2024 12:02 am, Josh Poimboeuf wrote: > >>>> diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c > >>>> index ca295b0c1eee..dcb97cc2758f 100644 > >>>> --- a/arch/x86/kernel/cpu/bugs.c > >>>> +++ b/arch/x86/kernel/cpu/bugs.c > >>>> @@ -1678,6 +1687,21 @@ static void __init spectre_v2_select_mitigation(void) > >>>> enum spectre_v2_mitigation_cmd cmd = spectre_v2_parse_cmdline(); > >>>> enum spectre_v2_mitigation mode = SPECTRE_V2_NONE; > >>>> > >>>> + /* > >>>> + * X86_FEATURE_INDIRECT_SAFE indicates whether indirect calls can be > >>>> + * considered safe. That means either: > >>>> + * > >>>> + * - the CPU isn't vulnerable to Spectre v2 or its variants; > >>>> + * > >>>> + * - a hardware mitigation is in place (e.g., IBRS, BHI_DIS_S); or > >>>> + * > >>>> + * - the user turned off mitigations altogether. > >>>> + * > >>>> + * Assume innocence until proven guilty: set the cap bit now, then > >>>> + * clear it later if/when needed. > >>>> + */ > >>>> + setup_force_cpu_cap(X86_FEATURE_INDIRECT_SAFE); > >>> Following on from the (re)discovery that X86_FEATURE_RETPOLINE is a poor > >>> name given what it *actually* does, can I recommend s/SAFE/OK/ here? > >> Or simply X86_FEATURE_USE_INDIRECT_BRANCH. > >> > >>> This flag really is "do I want indirect branches or not", which - as > >>> noted here - is more than just a judgement of whether indirect branches > >>> are "safe". > > X86_FEATURE_USE_INDIRECT_BRANCH sounds good. It's a bit long but does > > describe it better. > > Works for me.  Definitely an improvement over SAFE. USE_INDIRECT_BRANCH is now irking me: "use indirect branch for what? when? why?" At the moment I'm leaning towards Andrew's suggestion of X86_FEATURE_INDIRECT_OK as it at least says it's "ok" (safe or don't care) to use indirect branches when desired (typically performance raisins). I'll probably go with that (or maybe X86_FEATURE_INDIRECT_BRANCH_OK) unless anybody yells. -- Josh