From patchwork Tue Feb 20 13:53:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 203612 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp420372dyc; Tue, 20 Feb 2024 06:05:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWbECyXkKGLWJLRBiDPn2IEJNqqF5N7bMRU1V/wyulhGjY22jPuL5vixZ1FuriqnjC7JrRz9Gp1sM1FH6oobV21efm3gw== X-Google-Smtp-Source: AGHT+IF7v7vo4ktMbK5XufYLTOBtH/+hzuXmdB06Bm2eN3wtHrmqdDvPfRdUM8/MDlZnb4VgdSTZ X-Received: by 2002:a17:902:aa91:b0:1d8:eb2b:7b26 with SMTP id d17-20020a170902aa9100b001d8eb2b7b26mr12401868plr.49.1708437921447; Tue, 20 Feb 2024 06:05:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708437921; cv=pass; d=google.com; s=arc-20160816; b=x4BhbakkQXjIAm/HmwRmX+2Im3vI2N7QjB8YjcQ8bq9gUIRO49Ua68Y2P9FEJ6O0fw cOVYzTXu0zYA/3Sy2r479i13+wNuTzKzKcXWJU+UPt2ov726zP8Kf7UocxmM7UbDi4Uc 3wHw49AnXuxAfoWwAIPYPDelQ9htSGik8GyVDtIFHZcKkelWZMBrzfMOk84+reeAObEk dzovXPQnDYFMRpu1ZUL9xFpnCpCslyssdyFHBHND+EVqkc+hRGPSkhWuwvHMBT/p2s0P iU7wkB3ozIAlq1viuRgwn/61xgxlDvT+rOQOZmnYwfvrcNrDfkcgfU9aybnOQIWqYg7B VwIQ== 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=dX0qwnAkMiUZDtYX3kWdxqu2YK+FS1rZpMye7v8OPU0=; fh=nBDBFJR+HvwjxGEXqgRVhcMPj8ZT95I+nHaEdPXSB9k=; b=GuT5OgdosvKUafJTDtohxi5DZmT045YsEFdlEG4xb7Y+aJzEVOjakASrSyTAAV/jdj X0FdvafYDjGumf8voixWv49XbiSoCic/oKzYXK4hYBI/i0pXCQhjPbqwEiSfJKAVQDdY AEA9TMKvLWSNsD0/EuXkZ+Xi+vl4S3DJwktIwkaZsbFrzISk5gjgKZ3J81yETGKKOcMG kV4HqnTbPzx0nVYho8efkf7vG01Oek8dYjfKKBK+58IFE5CuCcxg6IVFY7ykeBFWRK4v AKmp9Qc4paWKYccFJ4X2Z39+iGx6Ri4ZUGezx8YheGZIluyOlNPUO5U5R+8rKHXco5wE 8R4Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aOznktuE; 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-73113-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73113-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q11-20020a170902a3cb00b001db637ab9ccsi6072328plb.43.2024.02.20.06.05.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 06:05:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73113-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aOznktuE; 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-73113-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73113-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4CB94B218DE for ; Tue, 20 Feb 2024 13:54:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D65FE6D1CC; Tue, 20 Feb 2024 13:53:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="aOznktuE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="a1bQgqf9" 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 8B6B16BB2D; Tue, 20 Feb 2024 13:53:20 +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=1708437202; cv=none; b=gDYGpCwg4hfz+8KPlesjXXChOIimKkAu1AVd2AEpoD/LECqrfTNY03hNpLFGAvnzaowZPdDHzL4G5PEf01mcI2DgPFBFg+42jSapSG+iOznR4hWfh+GCYnQ0ETfroNzNFgWxDiNVhQoO6XHELMWU/PpmlMopTsP1lWCgYMUQlrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708437202; c=relaxed/simple; bh=F10nFbGUTPjXFdSlvkWXG5Crt8d0YCOIJtrTLvjfk30=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=QDBvBVU8uc0ALvydVX8KlIs2P0hGZhfmi3BCSpkZUKFJmdp6A/3QztOP7+zv2n59xn1KRRFK5kGGHHFdyt8yapV+TTZV/Nzi6TA/KemzKOOb5BFF07qwPjh69jrH8WNH4L5egYBkaEbdFrsKCahwaMAtIi9qeVJNF+cLSKFMkgI= 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=aOznktuE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=a1bQgqf9; 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: Tue, 20 Feb 2024 13:53:17 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708437198; 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=dX0qwnAkMiUZDtYX3kWdxqu2YK+FS1rZpMye7v8OPU0=; b=aOznktuEu1IKcWrjPohRsN40ufcs3rWAJjYG0PEyETNUuPzFT7wqv5AaN8GVVaTU5O1c56 AuzPLQaqh0bQPE2q77Ltn9+ESmZ3Ygc90VHgRtzhaL2XwWjrmpVWT9A9WWKStwZtB7AC3q Xe6IAUH5ZQMX+sBhg9cvgP826GDEbTzsZEt65BgnsVzhl6J7Noyu6v+grvSewdrKPKWDcs 9TEFitBqNcpAfzmCPP8y25fKug4w2mNqqa4QKcRTE5TKfYt3r977+3eAmbFl9lLVPm1w7R C7JbUO03u82v38b49r8p9viOun1+aRqRo6FJaU7GFu5HdkoMVXn7dO0c6rgs6A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708437198; 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=dX0qwnAkMiUZDtYX3kWdxqu2YK+FS1rZpMye7v8OPU0=; b=a1bQgqf9rp6XLVtKbRf3BSsVHaveFHAXsFsH8uETq0skuEZ6n9ehx0sAMfYO7ThUYCHRqe EyHQxHBz3AZ4SACQ== From: "tip-bot2 for Kirill A. Shutemov" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/mtrr] x86/pat: Simplify the PAT programming protocol Cc: "Kirill A. Shutemov" , "Borislav Petkov (AMD)" , Juergen Gross , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240124130650.496056-1-kirill.shutemov@linux.intel.com> References: <20240124130650.496056-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170843719768.398.8004359782631430331.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: 1791427002193474529 X-GMAIL-MSGID: 1791427002193474529 The following commit has been merged into the x86/mtrr branch of tip: Commit-ID: ffc92cf3db62443c626469ef160f9276f296f6c6 Gitweb: https://git.kernel.org/tip/ffc92cf3db62443c626469ef160f9276f296f6c6 Author: Kirill A. Shutemov AuthorDate: Wed, 24 Jan 2024 15:06:50 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Tue, 20 Feb 2024 14:40:51 +01:00 x86/pat: Simplify the PAT programming protocol The programming protocol for the PAT MSR follows the MTRR programming protocol. However, this protocol is cumbersome and requires disabling caching (CR0.CD=1), which is not possible on some platforms. Specifically, a TDX guest is not allowed to set CR0.CD. It triggers a #VE exception. It turns out that the requirement to follow the MTRR programming protocol for PAT programming is unnecessarily strict. The new Intel Software Developer Manual (http://www.intel.com/sdm) (December 2023) relaxes this requirement, please refer to the section titled "Programming the PAT" for more information. In short, this section provides an alternative PAT update sequence which doesn't need to disable caches around the PAT update but only to flush those caches and TLBs. The AMD documentation does not link PAT programming to MTRR and is there fore, fine too. The kernel only needs to flush the TLB after updating the PAT MSR. The set_memory code already takes care of flushing the TLB and cache when changing the memory type of a page. [ bp: Expand commit message. ] Signed-off-by: Kirill A. Shutemov Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Juergen Gross Link: https://lore.kernel.org/r/20240124130650.496056-1-kirill.shutemov@linux.intel.com --- arch/x86/kernel/cpu/cacheinfo.c | 7 ++++--- arch/x86/mm/pat/memtype.c | 9 +++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c index c131c41..78afad5 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -1118,15 +1118,16 @@ static void cache_cpu_init(void) unsigned long flags; local_irq_save(flags); - cache_disable(); - if (memory_caching_control & CACHE_MTRR) + if (memory_caching_control & CACHE_MTRR) { + cache_disable(); mtrr_generic_set_state(); + cache_enable(); + } if (memory_caching_control & CACHE_PAT) pat_cpu_init(); - cache_enable(); local_irq_restore(flags); } diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index 0904d7e..0d72183 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -240,6 +240,8 @@ void pat_cpu_init(void) } wrmsrl(MSR_IA32_CR_PAT, pat_msr_val); + + __flush_tlb_all(); } /** @@ -296,13 +298,8 @@ void __init pat_bp_init(void) /* * Xen PV doesn't allow to set PAT MSR, but all cache modes are * supported. - * When running as TDX guest setting the PAT MSR won't work either - * due to the requirement to set CR0.CD when doing so. Rely on - * firmware to have set the PAT MSR correctly. */ - if (pat_disabled || - cpu_feature_enabled(X86_FEATURE_XENPV) || - cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) { + if (pat_disabled || cpu_feature_enabled(X86_FEATURE_XENPV)) { init_cache_modes(pat_msr_val); return; }