From patchwork Wed Jan 31 21:14:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 194944 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp31142dyc; Wed, 31 Jan 2024 13:20:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IGL0xlCPwTj5ERiy+B80c/11HRqQ/z+KMwvKX+kheoAtvLkyONFI7U60ZUlg0UlCciCUneQ X-Received: by 2002:a17:906:a85a:b0:a35:cb1c:bd69 with SMTP id dx26-20020a170906a85a00b00a35cb1cbd69mr389700ejb.6.1706736018710; Wed, 31 Jan 2024 13:20:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706736018; cv=pass; d=google.com; s=arc-20160816; b=Gk4H4PlENkvcehxJGCNOqCYmAy8HlJ+ryz4xKre0RvLeBkZaK6RWIm291hKroxu3O3 +vHIszA/GWMUYqSaIWsAibzLFVpc/04nwOgW23D3F9tFQtGdVJx4ETyMtgeF+UR9lYSB bz+30my9dgOz0QTATHR3NF66NBSbetNejpbctBx0ZZfK1Hacw3B522RiTbndhvInr2W/ cgKP7UV7CdxiiJS2n9Kr5SVk6ydglNsuzub0W7/1u4DBYPpDP1aIRO/BhvoE6YaK9qPa LxJ3ZDfoVZs51oNojvhLtu5NZRBUXJ4EMi66q34k4+ECL0jtcWcj0kEjcFBBBjavBCEJ D8+g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=Fkt8/v6brDioiH+ccpJMIFc54wdOcur1lkPXnHjo/as=; fh=J81Nefz63fQ7zZpe9XqiV2WCXF2NxKPcmu89VjIfp5A=; b=o84Zq5HyB7DAxCSi1O3OHr9XcMhjgGqGMHdxOEghTVgHHrfoqB5Q0AjuJBIXJy7yWb 6MkZYpEH/M/FlK6d944qM8kIjIdlg9x5H9cmLLeuwkVQiuL7lJ/woTti8GSyICOV/zmd czCvKm50BfLocXJOKf9DVXSg4CYsmBeiuEu9y4LGIQe4arxnQWXYTDmC0IlA9bwErVJ7 tRfKyd7mUhlYb8qi4hcqX8hhAq28w4NQhCSvvkrIPRIH8glqr/f4VJqjIi4IR57AEcab pn27RPAgoxXbCjd5BVJ6XHfzm/5BfZ5Y8O3/EmRcYu8eZfrpp0eWTzTGL6By1zYk6Rc7 RX4Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=lBiZIVKf; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-47134-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47134-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=1; AJvYcCUkVIFiV/sG8FE0GTru3U5vBQgX57UD5iQdSYRl0fBnRIA0Lg1DiZo6WJk0RIb74/3UrzBOeGGOHRYNWsy8OvIgOlPS2A== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id rn10-20020a170906d92a00b00a31897c47f4si5705618ejb.1023.2024.01.31.13.20.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 13:20:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47134-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=lBiZIVKf; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-47134-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47134-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 21B8D1F22BF2 for ; Wed, 31 Jan 2024 21:20:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5F1374176C; Wed, 31 Jan 2024 21:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="lBiZIVKf"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="4amRHlQQ" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB1843B290; Wed, 31 Jan 2024 21:14:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706735693; cv=none; b=WRHvUrGue6b9hOEZiG+CFb07hbe8pBVgtOGg92U3dLIEsXsT9IZaRv4DdBZolTVYMyGrfofw/5J1jwOpIw9GXwASw2XOndI3fxim9gzWa+kKOkyz/04D3xFBpZasUB+Y5PQyUWMXUtwItjusE9GOtU5FugQ51M8xYKHR7Qoy0FA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706735693; c=relaxed/simple; bh=cvq7V1ykTUX7C4s4O7SikD/1AEfkrbUY/8Ahx//l2q0=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=DVs1gphl5QyGoN97vjnvFZ+tecHrIMefyd8EOykHo7EVd5CgVITNcuQlOop/ISK4r6BDZNzHVKaOs9zN2rhj4VFl6wlTl8XWQ3u8NvDn7hQQ+GTttmqaReEFcJn8PZ9vfXSkaGSf9KpAEEbok1PdsG+dvMGzgo2h3Ef8Z8GxAlo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=lBiZIVKf; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=4amRHlQQ; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Wed, 31 Jan 2024 21:14:49 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706735690; h=from:from:sender:sender:reply-to: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fkt8/v6brDioiH+ccpJMIFc54wdOcur1lkPXnHjo/as=; b=lBiZIVKfNRjTED24uJsB9XsqiXyfTQiXPwVqOu5px06Lv551XP+gV7dGNMEw0gAyC0NCew RFIbQ27ZwX8ZNTcWFEdUOBOfr9wkD3rLH6ezhCu2uN8HsgEH482iolTKFmmm0W/8pADpKf qxWiG1awVnQQqtPSESMHvuIidBJhKI/qj3GDsnUw20XaDeuBV+d31i7a0ftVJVSIVm27Y6 zDRBnmL0piykYBuV1y21B+o6QnwD4PENjARZ5BR8PsCfBYZ/inPTXIZ8JT3hAoGbRDsQBJ M6KokbdP4x24KEzKN8JjKvXhv19H1xrfBZV+61u3KecGrjqkClASHYXSlH/Lhg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706735690; h=from:from:sender:sender:reply-to: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fkt8/v6brDioiH+ccpJMIFc54wdOcur1lkPXnHjo/as=; b=4amRHlQQgYmix+Tqwx4aqy3cPjKOmDCWufA5+ZDF2Ro/xZ1HWZPqx6zHwGCa5zSuTtYWg6 SyuG2Av+6YzWc1BA== From: "tip-bot2 for H. Peter Anvin (Intel)" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/fred] x86/fred: Disallow the swapgs instruction when FRED is enabled Cc: "H. Peter Anvin (Intel)" , Xin Li , Thomas Gleixner , "Borislav Petkov (AMD)" , Shan Kang , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231205105030.8698-19-xin3.li@intel.com> References: <20231205105030.8698-19-xin3.li@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170673568930.398.340341597805157045.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784440800557275242 X-GMAIL-MSGID: 1789642427372972894 The following commit has been merged into the x86/fred branch of tip: Commit-ID: 09794f68936a017e5632774c3e4450bebbcca2cb Gitweb: https://git.kernel.org/tip/09794f68936a017e5632774c3e4450bebbcca2cb Author: H. Peter Anvin (Intel) AuthorDate: Tue, 05 Dec 2023 02:50:07 -08:00 Committer: Borislav Petkov (AMD) CommitterDate: Wed, 31 Jan 2024 22:01:41 +01:00 x86/fred: Disallow the swapgs instruction when FRED is enabled SWAPGS is no longer needed thus NOT allowed with FRED because FRED transitions ensure that an operating system can _always_ operate with its own GS base address: - For events that occur in ring 3, FRED event delivery swaps the GS base address with the IA32_KERNEL_GS_BASE MSR. - ERETU (the FRED transition that returns to ring 3) also swaps the GS base address with the IA32_KERNEL_GS_BASE MSR. And the operating system can still setup the GS segment for a user thread without the need of loading a user thread GS with: - Using LKGS, available with FRED, to modify other attributes of the GS segment without compromising its ability always to operate with its own GS base address. - Accessing the GS segment base address for a user thread as before using RDMSR or WRMSR on the IA32_KERNEL_GS_BASE MSR. Note, LKGS loads the GS base address into the IA32_KERNEL_GS_BASE MSR instead of the GS segment's descriptor cache. As such, the operating system never changes its runtime GS base address. Signed-off-by: H. Peter Anvin (Intel) Signed-off-by: Xin Li Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov (AMD) Tested-by: Shan Kang Link: https://lore.kernel.org/r/20231205105030.8698-19-xin3.li@intel.com --- arch/x86/kernel/process_64.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 0f78b58..4f87f59 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -166,7 +166,29 @@ static noinstr unsigned long __rdgsbase_inactive(void) lockdep_assert_irqs_disabled(); - if (!cpu_feature_enabled(X86_FEATURE_XENPV)) { + /* + * SWAPGS is no longer needed thus NOT allowed with FRED because + * FRED transitions ensure that an operating system can _always_ + * operate with its own GS base address: + * - For events that occur in ring 3, FRED event delivery swaps + * the GS base address with the IA32_KERNEL_GS_BASE MSR. + * - ERETU (the FRED transition that returns to ring 3) also swaps + * the GS base address with the IA32_KERNEL_GS_BASE MSR. + * + * And the operating system can still setup the GS segment for a + * user thread without the need of loading a user thread GS with: + * - Using LKGS, available with FRED, to modify other attributes + * of the GS segment without compromising its ability always to + * operate with its own GS base address. + * - Accessing the GS segment base address for a user thread as + * before using RDMSR or WRMSR on the IA32_KERNEL_GS_BASE MSR. + * + * Note, LKGS loads the GS base address into the IA32_KERNEL_GS_BASE + * MSR instead of the GS segment’s descriptor cache. As such, the + * operating system never changes its runtime GS base address. + */ + if (!cpu_feature_enabled(X86_FEATURE_FRED) && + !cpu_feature_enabled(X86_FEATURE_XENPV)) { native_swapgs(); gsbase = rdgsbase(); native_swapgs(); @@ -191,7 +213,8 @@ static noinstr void __wrgsbase_inactive(unsigned long gsbase) { lockdep_assert_irqs_disabled(); - if (!cpu_feature_enabled(X86_FEATURE_XENPV)) { + if (!cpu_feature_enabled(X86_FEATURE_FRED) && + !cpu_feature_enabled(X86_FEATURE_XENPV)) { native_swapgs(); wrgsbase(gsbase); native_swapgs();