Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6748590rwr; Tue, 2 May 2023 05:11:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6VXNprSrLvbZJyhbksz8aFngljgP1SGIjX5hYfj55vU8lOyGXVwc2m1GMEna4KTF53plr9 X-Received: by 2002:a17:90a:72cc:b0:24e:39c:f12e with SMTP id l12-20020a17090a72cc00b0024e039cf12emr6414497pjk.30.1683029478265; Tue, 02 May 2023 05:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683029478; cv=none; d=google.com; s=arc-20160816; b=QIGjT5pkwd/8ME236RMLuXZwwHF5zn/efpYtgExoa3y3iI12qTSSxVF9lwuO6i7z6j fkWLmP6g/nqcciavjGa5dEhwcOlAGKm4hdCMwHvohLeye6mu8AlBFv9v+dwjjkzeKUF6 qgk6r02uDlk43tSEAGcjmBXJ4BnuYvc9+plJla+S0VAuAW8G4Hzt21G+kOBxOyzwTRag RFprk4oOK7SwObXkTaNPEe6aRY7PWYHTArK6DmEYgVMuo+E1ioXD71fl+0Hu1UIlPqHb rr8QZGIZG2h6/1ZeH7LwHy+A9EP6zbOZR+f4xOkJRfJf6bBpONvQ8PyNtyeb6LZSPpq9 B0eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=5isj2N5NCBHlgNEX7kDR8L5F10upbDgKEvNgnzD7pjU=; b=RE0zrQ0wt+1+3oB8WaZvgVJMfY5OgNiPOvKXJnsPwK6WPazvLtCza9Il0V3Ut/Ece5 JTSoIpgvt9iQBD1Du7R94s54YSOYAWJ5rcezPDaa1/Lj4Y8gadc7J3Mlx6Px6NHkCvF4 nO49JKx0gq36hX0Tw0wndMxlMxUH8tqisfPAWFEJQxPWKNQoppLUX4Q1hISyksDo7qXy KjqqB317FQkG18ri0Q+amKwIdemYqSoceTw4mrCUhWaJhFJm48qOjKDHd/7mlCpRo8yH 7mJSPRjwYrPngUUahGokEL+simT0I1lQcMzDZpD7skDMVOeyuuUJuHkQFhN9g054t9Hy kvdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=lCdfsFMO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id az24-20020a17090b029800b0024b6a8879c3si27048838pjb.68.2023.05.02.05.11.06; Tue, 02 May 2023 05:11:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=lCdfsFMO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233905AbjEBMJw (ORCPT + 99 others); Tue, 2 May 2023 08:09:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233784AbjEBMJv (ORCPT ); Tue, 2 May 2023 08:09:51 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96EBA4EC8; Tue, 2 May 2023 05:09:43 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 23DE021A10; Tue, 2 May 2023 12:09:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1683029382; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=5isj2N5NCBHlgNEX7kDR8L5F10upbDgKEvNgnzD7pjU=; b=lCdfsFMOgUvQOOjznQ29dhIfCPfBATrhqs0ygxXq+WuLpchDR8rfeWRUqFg4gsVq1hAZso M6yRbkcUUeSN+OZpt0kdpNk+01NuOD3H4axIM8mN+INEgVDTKNBob6uRoIMwSVTHqsAyiH tXY30Kqoaqh0gDh5kUwQuvMJsIBgFwg= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9635D139C3; Tue, 2 May 2023 12:09:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id bPRFI4X9UGRmLwAAMHmgww (envelope-from ); Tue, 02 May 2023 12:09:41 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-hyperv@vger.kernel.org, linux-doc@vger.kernel.org Cc: mikelley@microsoft.com, Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Boris Ostrovsky , xen-devel@lists.xenproject.org, Jonathan Corbet , Andy Lutomirski , Peter Zijlstra Subject: [PATCH v6 00/16] x86/mtrr: fix handling with PAT but without MTRR Date: Tue, 2 May 2023 14:09:15 +0200 Message-Id: <20230502120931.20719-1-jgross@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This series tries to fix the rather special case of PAT being available without having MTRRs (either due to CONFIG_MTRR being not set, or because the feature has been disabled e.g. by a hypervisor). The main use cases are Xen PV guests and SEV-SNP guests running under Hyper-V. Instead of trying to work around all the issues by adding if statements here and there, just try to use the complete available infrastructure by setting up a read-only MTRR state when needed. In the Xen PV case the current MTRR MSR values can be read from the hypervisor, while for the SEV-SNP case all needed is to set the default caching mode to "WB". I have added more cleanup which has been discussed when looking into the most recent failures. Note that I couldn't test the Hyper-V related change (patch 3). Running on bare metal and with Xen didn't show any problems with the series applied. It should be noted that patches 9+10 are replacing today's way to lookup the MTRR cache type for a memory region from looking at the MTRR register values to building a memory map with the cache types. This should make the lookup much faster and much easier to understand. Changes in V2: - replaced former patches 1+2 with new patches 1-4, avoiding especially the rather hacky approach of V1, while making all the MTRR type conflict tests available for the Xen PV case - updated patch 6 (was patch 4 in V1) Changes in V3: - dropped patch 5 of V2, as already applied - split patch 1 of V2 into 2 patches - new patches 6-10 - addressed comments Changes in V4: - addressed comments Changes in V5 - addressed comments - some other small fixes - new patches 3, 8 and 15 Changes in V6: - patch 1 replaces patches 1+2 of V5 - new patches 8+12 - addressed comments Juergen Gross (16): x86/mtrr: remove physical address size calculation x86/mtrr: replace some constants with defines x86/mtrr: support setting MTRR state for software defined MTRRs x86/hyperv: set MTRR state when running as SEV-SNP Hyper-V guest x86/xen: set MTRR state when running as Xen PV initial domain x86/mtrr: replace vendor tests in MTRR code x86/mtrr: have only one set_mtrr() variant x86/mtrr: move 32-bit code from mtrr.c to legacy.c x86/mtrr: allocate mtrr_value array dynamically x86/mtrr: add get_effective_type() service function x86/mtrr: construct a memory map with cache modes x86/mtrr: add mtrr=debug command line option x86/mtrr: use new cache_map in mtrr_type_lookup() x86/mtrr: don't let mtrr_type_lookup() return MTRR_TYPE_INVALID x86/mm: only check uniform after calling mtrr_type_lookup() x86/mtrr: remove unused code .../admin-guide/kernel-parameters.txt | 4 + arch/x86/hyperv/ivm.c | 4 + arch/x86/include/asm/mtrr.h | 43 +- arch/x86/include/uapi/asm/mtrr.h | 6 +- arch/x86/kernel/cpu/mtrr/Makefile | 2 +- arch/x86/kernel/cpu/mtrr/amd.c | 2 +- arch/x86/kernel/cpu/mtrr/centaur.c | 11 +- arch/x86/kernel/cpu/mtrr/cleanup.c | 22 +- arch/x86/kernel/cpu/mtrr/cyrix.c | 2 +- arch/x86/kernel/cpu/mtrr/generic.c | 677 ++++++++++++------ arch/x86/kernel/cpu/mtrr/legacy.c | 90 +++ arch/x86/kernel/cpu/mtrr/mtrr.c | 195 ++--- arch/x86/kernel/cpu/mtrr/mtrr.h | 18 +- arch/x86/kernel/setup.c | 2 + arch/x86/mm/pgtable.c | 24 +- arch/x86/xen/enlighten_pv.c | 52 ++ 16 files changed, 721 insertions(+), 433 deletions(-) create mode 100644 arch/x86/kernel/cpu/mtrr/legacy.c -- 2.35.3