Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1576118ybk; Sun, 10 May 2020 21:58:10 -0700 (PDT) X-Google-Smtp-Source: APiQypL9gcAhaNsF4qbsdawnnN5l+wGv5GqfPIxECSXT/Oo0XENOdg1wOzNAy0uyXvW4lUK/na8m X-Received: by 2002:a17:906:bce6:: with SMTP id op6mr9049628ejb.337.1589173089959; Sun, 10 May 2020 21:58:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589173089; cv=none; d=google.com; s=arc-20160816; b=nwEAFVg3U+UVP4fqRKtspSf1VDZtVRqq2EtDWAI8S2ZKRctLjELMePnn4SRQpZcq8D BL3vp/rbEuh8OvOXTD0GlxHJ1IXlK+mU7AdwLZmXFqVSNpgKXJqBJXGl00p7IfAYPloE jYiWUL7dUEGjFtr5sTYbsIZUG8Usv5BC8Ktnctx7bCOKhLPO9p6RjNnJ0wwfasOYumfl S64+Ir39/cpx4Ai+MRE3rtSE0XKAID5INRIvitLmU6UvZb6BpBWNVU9chMavuJx5jcY8 4TScf7YnFlIGMo88ElgCuO2BQyn0GtVc/kakz8QHdr8KF5yngd13jn775U/3kcdqJqyP VCmQ== 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=IYzAshfb4mKBIceD12h0YkSzQJ3BaisLrTWlFivAkhQ=; b=G+F+ALAp5XGliRX+Mz/XzTqqjOHNPn/ou+eswRiNjep8938L2PjmV9oJcioR8AO6FJ fQp13odhYaKqDd3thRHsrnp8CPAaNJbMo44QqOQyCArjv/q1HcRdMQd23rCsgfqo/3p3 F2i6W4ioAih8HvDTSECNi2cYg0IHjsZJj+bzspahsOc9oVpV1jklOR7zecw2AHayBmkA in09m8/s+p7NZ4veAKm7uspEycLmFLPTcMidghF9I0KQmqdqBV3NLPCFhBdMNPdZgUpP foSy7nmQkfdPipsQYs7xlB6s1q2HHr3LbiYSwNsS3zQHc8SM3qIXqQ7kt5mCRK44ANC5 A1iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lcnkvbbv; 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 q19si3062755ejb.348.2020.05.10.21.57.40; Sun, 10 May 2020 21:58:09 -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=lcnkvbbv; 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 S1729283AbgEKEyQ (ORCPT + 99 others); Mon, 11 May 2020 00:54:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:37572 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728491AbgEKExi (ORCPT ); Mon, 11 May 2020 00:53:38 -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 D982724960; Mon, 11 May 2020 04:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589172817; bh=lCmbhHyFSvR8ipmtonVqDpN7IU+xGXfjR90A+02sw4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lcnkvbbvmimP90k20AkfM6+WQoifYcdWP7ymtu+SwY5iNWkL/AVpv/qx/J/nOiaIs YHI2yJeKfijew/c3BxGwRoS6i/ULw2sjATqquKgNqF9kEjkei0yNxyUrxG3s8FRkk6 JUiMS7L8bdLQ1/DYxc4CrQkS+TCWviCTydUt6M+c= 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 v12 08/18] x86/entry/64: Document GSBASE handling in the paranoid path Date: Mon, 11 May 2020 00:53:01 -0400 Message-Id: <20200511045311.4785-9-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200511045311.4785-1-sashal@kernel.org> References: <20200511045311.4785-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 Signed-off-by: Sasha Levin 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 --- 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