Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2344943ybz; Thu, 23 Apr 2020 16:25:51 -0700 (PDT) X-Google-Smtp-Source: APiQypKSw4FzNQkiiY0X4vY98uDvNzZEL5MmyEHmpyeyfIxSc8dLbTSV0xMZnwowQvBqZCLTKZXu X-Received: by 2002:a17:906:7383:: with SMTP id f3mr4610686ejl.197.1587684351128; Thu, 23 Apr 2020 16:25:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587684351; cv=none; d=google.com; s=arc-20160816; b=T9eL9uDXY1Vmp+UreJJPWBVGKMb7Q/HpyHp4IAtX+9a4zBEdjXM3ug425wyxvZ/MOU s4fqBmphGnWaGaAxhuMzhMeQHcUl3IcbrMMZ/dIRMmNblaE4QKOKo/zAqDuXAALWuTzb CCBht18joCpG/ByzL6sY0p2LSqn132p/1/AlRiizmpPy+hMJugNNSybA78ReMgFAblAk uZTQc5oVJQxngmghzd0JMQVK9gnNeV1FB/AvGh62r+u7SLQ4SFKyd1fxyn8+wp7WNthi DnNXNwai+tNZe2pvyaoF8o9+y2tQEXUJfvUMl97/ZvE4jj2gtAIwzg/H15lALyB+4tFt nrfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uXtd62uH46r8rE7o924VFaMsRPlPu1v34uBLoABFTYE=; b=PjTSVELbKlG1mjprT0p28H8GAn4GafoicYjoCYSab9Z5ut6uTJjyyW9PhOnvx9CEIZ MGX15aSULcQqNfBe/uBXyduESFZkLW2XKJFMzZeJYQR04VmhdyqeVxUBpZU5phsV0HUm QifBlSmtKQ81tJVgJob+Znhv3e3Vfs+i0okuSDXPAJhZYhhc4tVJWj0u4hleGxYaKTGm XIciWw7Wy0dIENmNRQ25dX/l9y6PiuwcAjn2FcKhKBBerPX2J8eh+KGWFYI57n/zBHUF FxwhGk0qwHkac69CCelVMj0kS4/Hff9Weq37prWcuGcLbAKMEKnfJPYcFFHPPFA62Bxm 72Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IPUWZAiv; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d1si1979764edr.360.2020.04.23.16.25.27; Thu, 23 Apr 2020 16:25:51 -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=@kernel.org header.s=default header.b=IPUWZAiv; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729890AbgDWXXK (ORCPT + 99 others); Thu, 23 Apr 2020 19:23:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:59030 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729046AbgDWXWX (ORCPT ); Thu, 23 Apr 2020 19:22:23 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 875892173E; Thu, 23 Apr 2020 23:22:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587684142; bh=Tz5CMnRcgkpz8IB+Wui6WEZE0CTms+oTNEix0tZQyJ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IPUWZAivfv9yKjnNJ2u73Rk396kd8ENGwXuoH6pEOonVOMb9CZrxwJtwBatPEz3Mf HpwdizD9NxT8fnGtxsZIJUMokTapcdH1A+R32swmRV/zRsaE+J71Xsw0bWuCUouwHF jNXEjV3OU0jYAAtrhlQPV94X5o55Na26aU23HxI0= From: Sasha Levin To: linux-kernel@vger.kernel.org, tglx@linutronix.de, bp@alien8.de, luto@kernel.org Cc: hpa@zytor.com, dave.hansen@intel.com, tony.luck@intel.com, ak@linux.intel.com, ravi.v.shankar@intel.com, chang.seok.bae@intel.com, Sasha Levin Subject: [PATCH v10 08/18] x86/entry/64: Document GSBASE handling in the paranoid path Date: Thu, 23 Apr 2020 19:21:57 -0400 Message-Id: <20200423232207.5797-9-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200423232207.5797-1-sashal@kernel.org> References: <20200423232207.5797-1-sashal@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Chang S. Bae" On FSGSBASE systems, the way to handle GS base in the paranoid path is different from the existing SWAPGS-based entry/exit path handling. Document the reason and what has to be done for FSGSBASE enabled systems. Signed-off-by: Chang S. Bae Reviewed-by: Tony Luck Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Dave Hansen Cc: Tony Luck Cc: Andi Kleen Signed-off-by: Sasha Levin --- Documentation/x86/entry_64.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Documentation/x86/entry_64.rst b/Documentation/x86/entry_64.rst index a48b3f6ebbe87..0499a40723af3 100644 --- a/Documentation/x86/entry_64.rst +++ b/Documentation/x86/entry_64.rst @@ -108,3 +108,12 @@ We try to only use IST entries and the paranoid entry code for vectors that absolutely need the more expensive check for the GS base - and we generate all 'normal' entry points with the regular (faster) paranoid=0 variant. + +On FSGSBASE systems, however, user space can set GS without kernel +interaction. It means the value of GS base itself does not imply anything, +whether a kernel value or a user space value. So, there is no longer a safe +way to check whether the exception is entering from user mode or kernel +mode in the paranoid entry code path. So the GS base value needs to be read +out, saved and the kernel GS base value written. On exit, the saved GS base +value needs to be restored unconditionally. The non-paranoid entry/exit +code still uses SWAPGS unconditionally as the state is known. -- 2.20.1