Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp882926pxb; Wed, 27 Oct 2021 14:24:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzU1oYjqt0Oqj6up+SuR7FKs0gSHUy3O6JWetnTSn4JHXeZpT4p75QkLYOn6QGNemQlgz7B X-Received: by 2002:a65:4008:: with SMTP id f8mr184228pgp.310.1635369892249; Wed, 27 Oct 2021 14:24:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635369892; cv=none; d=google.com; s=arc-20160816; b=H/lgUvTnN6A9RppSKCym37WZ5o6LpEmFCrASGqIcO32mnmbaEKhztu40Ly1tgVTzIp a9jXM/lNqgTdLIh80J4WcpLUYEVAZS4JfzPuzUM46wKX5F297ZS3YG8VduDW9lSRtekT 5bC/k8MMLhhHGwm0WQBJ3sFB7u652OX7lbXE0GZXolriWrGBql5BXTNbMMHxH191dF2R ltMKBKxbOpg6bsfEzrnhNHSYKysnIag28v2VZ3mPkiI4oWYtaMyl8p6fsMmvmXdHFlho QFdlBPqWNLTMbJkfwa4uDLZfVrqZ3x97DmvWODF7iG9Wm6e8xaG63ERCKPL1hFj5TaWT T/Og== 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=vsVX54iamSqF8EqMqhMff/1IYYGj1jxaET3s56qWpSM=; b=A5M1BcPZTpQ2HHieFgV9+ybHzlKrTPd0uShwgfjhxxYDejWDMxUaEG5X7828C6miBN fZYNLd3vFdqORWO5tO9mv2hhXdNa/Qr4WNt48j6kpYtBcwvTNAuKYprxE5s47BSi4GtC tEUathad+/eyWxiQ9PpUh3B0ssumIc1YB7OUuxvJjKSXNBZgR7KqT7kp5hBranMBlgK5 bgjmN7sIqldzeZv4u5homvnUQ/WrMytXLvZWyVfXVgI+Tr7NBpMLp4FSRLAkAJ/yLHPk C7I1k9h71xL1vmPZ75v5nriOJNwzsK/jCUJTTtNA3Av/vsy88N34LP4yGvFEOI0TWDTt nHiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=JetjZbaE; 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=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b10si1865479pgk.282.2021.10.27.14.24.37; Wed, 27 Oct 2021 14:24:52 -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=@alien8.de header.s=dkim header.b=JetjZbaE; 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=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241890AbhJ0MVy (ORCPT + 97 others); Wed, 27 Oct 2021 08:21:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241894AbhJ0MVk (ORCPT ); Wed, 27 Oct 2021 08:21:40 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51270C061243 for ; Wed, 27 Oct 2021 05:19:13 -0700 (PDT) Received: from zn.tnic (p200300ec2f161500de850afe3c1188c4.dip0.t-ipconnect.de [IPv6:2003:ec:2f16:1500:de85:afe:3c11:88c4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id CFAC91EC0602; Wed, 27 Oct 2021 14:19:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1635337151; 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: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=vsVX54iamSqF8EqMqhMff/1IYYGj1jxaET3s56qWpSM=; b=JetjZbaEOtDjwhfyfi8AbnoEMhCb/CVLigHWsv0vFUZ79EumhPjnUj1Tie7TBKnCzdjwhD DXqV3jezLY4mwCJe1ZqygneGbPPFIVgnlnpWJNlvkOatAT0kQYly7gHyMNm9Xc+2NlMYr0 0wqb+SCw8JM2h9xOxk/1CTrx4yxwpXs= Date: Wed, 27 Oct 2021 14:19:07 +0200 From: Borislav Petkov To: Lai Jiangshan Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Lai Jiangshan , Josh Poimboeuf , "Chang S . Bae" , Sasha Levin , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Dave Hansen , "H. Peter Anvin" Subject: Re: [PATCH V4 01/50] x86/entry: Add fence for kernel entry swapgs in paranoid_entry() Message-ID: References: <20211026141420.17138-1-jiangshanlai@gmail.com> <20211026141420.17138-2-jiangshanlai@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20211026141420.17138-2-jiangshanlai@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? This way you kill speculation for both cases and have a single fence. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette