Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3586062pxb; Sun, 26 Sep 2021 20:29:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJ7KeeLgFwBBDnwr5OeyCXmt+tSrIBPL5pEMUqY+jhbkhhqdNxWcxrYNEMxEmXv+C3JAxp X-Received: by 2002:a17:90a:11:: with SMTP id 17mr17082260pja.238.1632713341183; Sun, 26 Sep 2021 20:29:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632713341; cv=none; d=google.com; s=arc-20160816; b=MgY1zbdXMxWfqLSQfM2WUuyEkAb9iiEJ6Ai60+jX59MpUmW3pNYB9561XOTh+bsIT1 NL2JGOEqK+4Bev9/51EYGBf3bjxGxsf7/NacbEjAAkwYblhxnnn0buAJ4fMed2I0s9Gc h+BSVW1qGvizcwpcX4w2qfQ5d34HX+CLgh+JB7ximT8C/eZMlZ/BSXGiQEdaWwPDp05Q uY8fUbBBNDOHydjATMqQJxIqtRBXxWKYNRM0BoWrTERr+gq7eoDtqgkS83TwODMC/oDw FmIKKVrUDSRqyLfai3bgzWAELs1U6N22KLXXOl2GI87DNDTj25Ho0l9Af/8984JgKaLV S+CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject; bh=6DzTDsJcDV1FeYAsVbI6apePU+YWd5+6prJf5z8OkKY=; b=Ro0TDf0jaI4dGyC5ZbAnZj/69UdUXpHUG78suUgsw28rCxbD8CJPw4T/EIR8rDGgR/ SeuYPzNbiNeFeu1JlyYCiRluxBYcjFJNb6b3Qu1kUnCBIE55gFTqcqQI/ZfBjvsaXbrZ pki19wpLDv7sMDZzBlAciJ9xmYHW6ShLwHKFBaBqrafX+e2+yA0eImCZmJM/bswwaNmV pYWsmjNcQMdUeMoc/ObOHRfM7Cr0M5y1dGkNX8E8Hz+B2ozA7eLSs/w7GNkPPIvh+p/z t2Rcfe5jZvv0CQuW1zhYdO8dF9Vv4ASOOIQ9SAIOT8fdJp59n8zOhgAQie8n6aQ2zy7w bxeQ== 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 t190si14931235pgd.565.2021.09.26.20.28.47; Sun, 26 Sep 2021 20:29:01 -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 S232498AbhI0D3k (ORCPT + 99 others); Sun, 26 Sep 2021 23:29:40 -0400 Received: from out4436.biz.mail.alibaba.com ([47.88.44.36]:54604 "EHLO out4436.biz.mail.alibaba.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229572AbhI0D3j (ORCPT ); Sun, 26 Sep 2021 23:29:39 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04395;MF=laijs@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0UpgMq9c_1632713278; Received: from C02XQCBJJG5H.local(mailfrom:laijs@linux.alibaba.com fp:SMTPD_---0UpgMq9c_1632713278) by smtp.aliyun-inc.com(127.0.0.1); Mon, 27 Sep 2021 11:27:59 +0800 Subject: Re: [PATCH V2 01/41] x86/entry: Fix swapgs fence From: Lai Jiangshan To: Thomas Gleixner , Lai Jiangshan , linux-kernel@vger.kernel.org Cc: Josh Poimboeuf , "Chang S . Bae" , Sasha Levin , Andy Lutomirski , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" References: <20210926150838.197719-1-jiangshanlai@gmail.com> <20210926150838.197719-2-jiangshanlai@gmail.com> <87r1dbawzq.ffs@tglx> <9312a767-f1d3-d283-80a9-e6b3854252e1@linux.alibaba.com> Message-ID: <445de475-c223-be11-325f-fa6679e45cb0@linux.alibaba.com> Date: Mon, 27 Sep 2021 11:27:58 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <9312a767-f1d3-d283-80a9-e6b3854252e1@linux.alibaba.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/9/27 09:10, Lai Jiangshan wrote: >> >> This change is wrong. >> >> In the paranoid entry path even if user GS base is set then the entry >> does not necessarily come from user space so there is no guarantee that >> there was a CR3 write on PTI enabled systems before the SWAPGS. >> >> FENCE_SWAPGS_USER_ENTRY does not emit a LFENCE when PTI is enabled, so >> both the comment and FENCE_SWAPGS_KERNEL_ENTRY which emits LFENCE on >> affected CPUs unconditionaly are correct. Though the comment could do >> with some polishing to make this entirely clear. > > > I didn't notice FENCE_SWAPGS_USER_ENTRY depends on PTI. The commit c75890700455 ("x86/entry/64: Remove unneeded kernel CR3 switching") ( https://lore.kernel.org/all/20200419144049.1906-2-laijs@linux.alibaba.com/ ) also made it wrong. When the SWITCH_TO_KERNEL_CR3 in the path is removed, FENCE_SWAPGS_USER_ENTRY should also be changed to FENCE_SWAPGS_KERNEL_ENTRY. (Or just jmp to .Lerror_entry_done_lfence which has FENCE_SWAPGS_KERNEL_ENTRY already.) And FENCE_SWAPGS_USER_ENTRY could be documented with "it should be followed with serializing operations such as SWITCH_TO_KERNEL_CR3". Or we can add a SWAPGS_AND_SWITCH_TO_KERNEL_CR3 to combine them. I will fix it in v3. (Or should I do it separately before v3?) Sorry for my fault. Lai > > I will add FENCE_SWAPGS_KERNEL_ENTRY only on the kernel path. > > Thanks > Lai