Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1033853pxb; Wed, 27 Oct 2021 17:53:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIpb/Xxo4sdBEJob52PrTUVozMmuzkQ+2VR5vPWSA8/M/bm0xBCggDDV/pP7gBcrzW0yew X-Received: by 2002:a17:90a:1a0c:: with SMTP id 12mr9416603pjk.2.1635382395238; Wed, 27 Oct 2021 17:53:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635382395; cv=none; d=google.com; s=arc-20160816; b=0hBY6BmpSPvDKBpe2x9HwI0vKfBOZ+kWhpC/37jcXVRUmciBZ2vit74TJnWCeY+YMC gXuxoth1DznkiaX/nCgIQoStxWlCnX2dA+nt5ybYwWQ2cptvH/S/VxiMeRymZNSg+VH4 nlZwJvBxGRsH0uu1spLymJE0NYtwgHlaGcRsB9s12tT4MQ1jyF/8n0g9O6X0MDLRq4qJ 8qR+EaIbWi4RaBMd5QN4CWB3LaaxvFzoLNCdYsM90Le8H2PjD8LD8xUSBoyifHZ69tb0 MVKyWkzqtphikdR5CuWS/vrlFNVIbdZCSbxz0OOvWKDmJZ66O0mCHOLpmgXQkfbeUN4Z +BXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=e2m2zoHMDDL861IlELq3f4bmv7hb+hrXfQW2KC+n2VY=; b=BcCRHzEIAsjuC7WhlrdbogkQ3/UR+6S52wPigfLFb5amV0tNL0B2n3/0W34AGbrhEN ix9liSJduqNMbdws0dWrF6AD0haknw4X1azk2dmsSycOWL56eUMtBaWewRSKdVrP9OgI iIl20dkQkn15cb2ybc5BxLDQFSvOVY8FJrgF9TuCwc7p8pobge/fPT4syJR1OQg8sheu eDbdnnQe/A6iGDTNoVujuV1ro6gsRxCng5MpQxOEbddXVp3SHH3L3mttDI4QOa+1EyUF jRGMvIMaWfGKkVqNntn4k2JFf6XILlL9XWNeZO7U3yfb9vOyOeNz3fckbO2uzaULYA1X 4tNQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r11si2078624pgm.193.2021.10.27.17.53.02; Wed, 27 Oct 2021 17:53:15 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229515AbhJ1Aya (ORCPT + 99 others); Wed, 27 Oct 2021 20:54:30 -0400 Received: from out30-56.freemail.mail.aliyun.com ([115.124.30.56]:52377 "EHLO out30-56.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbhJ1Ay3 (ORCPT ); Wed, 27 Oct 2021 20:54:29 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04357;MF=laijs@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0UtwmmjM_1635382319; Received: from 192.168.2.97(mailfrom:laijs@linux.alibaba.com fp:SMTPD_---0UtwmmjM_1635382319) by smtp.aliyun-inc.com(127.0.0.1); Thu, 28 Oct 2021 08:52:00 +0800 Message-ID: Date: Thu, 28 Oct 2021 08:51:59 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: Re: [PATCH V4 01/50] x86/entry: Add fence for kernel entry swapgs in paranoid_entry() Content-Language: en-US To: Borislav Petkov , Lai Jiangshan Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Josh Poimboeuf , "Chang S . Bae" , Sasha Levin , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Dave Hansen , "H. Peter Anvin" References: <20211026141420.17138-1-jiangshanlai@gmail.com> <20211026141420.17138-2-jiangshanlai@gmail.com> From: Lai Jiangshan In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/10/27 20:19, Borislav Petkov wrote: > On Tue, Oct 26, 2021 at 10:13:31PM +0800, Lai Jiangshan wrote: >> From: Lai Jiangshan >> >> Commit 18ec54fdd6d18 ("x86/speculation: Prepare entry code for Spectre >> v1 swapgs mitigations") adds FENCE_SWAPGS_{KERNEL|USER}_ENTRY >> for conditional swapgs. And in paranoid_entry(), it uses only >> FENCE_SWAPGS_KERNEL_ENTRY for both branches. It is because the fence >> is required for both cases since the CR3 write is conditinal even PTI >> is enabled. >> >> But commit 96b2371413e8f ("x86/entry/64: Switch CR3 before SWAPGS in >> paranoid entry") switches the code order and changes the branches. >> And it misses the needed FENCE_SWAPGS_KERNEL_ENTRY for user gsbase case. >> >> Add it back. >> >> Fixes: Commit 96b2371413e8f ("x86/entry/64: Switch CR3 before SWAPGS in paranoid entry") >> Cc: Josh Poimboeuf >> Cc: Chang S. Bae >> Cc: Sasha Levin >> Signed-off-by: Lai Jiangshan >> --- >> arch/x86/entry/entry_64.S | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S >> index e38a4cf795d9..1f98188e83ef 100644 >> --- a/arch/x86/entry/entry_64.S >> +++ b/arch/x86/entry/entry_64.S >> @@ -898,6 +898,7 @@ SYM_CODE_START_LOCAL(paranoid_entry) >> rdmsr >> testl %edx, %edx >> jns .Lparanoid_entry_swapgs >> + FENCE_SWAPGS_KERNEL_ENTRY > > Wouldn't it be cleaner to simply move the FENCE up from under the swapgs > to before the jns instruction? Sure, I will move it just before the testl instruction. > > This way you kill speculation for both cases and have a single fence. >