Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp4104081rdg; Wed, 18 Oct 2023 15:27:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEv9OVFyyJEYwceJUv9SUofdtmjbD5ma8dzTeQo8n+YUX8xi5yBMuYvEYOlyUv62uz3OqIU X-Received: by 2002:a17:90a:d3d8:b0:27d:348:94a8 with SMTP id d24-20020a17090ad3d800b0027d034894a8mr490375pjw.6.1697668038758; Wed, 18 Oct 2023 15:27:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697668038; cv=none; d=google.com; s=arc-20160816; b=NHq+s3iKKib1qDrxzivUHIdG9+lrLgxQr1JCEyUiMktEPLBvxlLb7TtzJl+LCfG1b3 XtzLDgx8TzLVPStxu2xni4LaJ7ZS/dWvCOA4UT3mdI/mo5IIwPT1Ojs3ok5WHPD8V0KF Wcw1cVegjtoxqTw7Xg6yzIFSRbC8zRDP/hLyqrZm11sfhjIpzi1NQo6WlwW2aQNfbud0 TObRM8TdqEXjxOsE4dhyVhQg5i3C1TjF7ayVF7zxa746qevcOYEYt05s+vjLQH3zn/7u 6aUqWx1+znD+eNkI7xtPzs6FB8D1SB1NFu/CwW+oRsm11BGnSW4XoAHV9r4EQnv4aPh2 Q9aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:organization:message-id:date :subject:cc:to:from:dkim-signature; bh=G8UuCHIixDR7Vf9lSi2UHqS5JARBRiXgrMtZL7P5rjA=; fh=JFaV5dk/a1c0Dx3dw+QO4GCXvzyM7Ra02iINZt8AFsw=; b=Kn3V5CYmh0+74DIsV7FVfsdtXzBUw0NUMvA8Waz1FZ3hp7q/uXNVEk70PdTv6Fnpe2 8p+PJEKnUGsvM385XlIBZoSqWEAh1Cp5xe7wNAI8ScngnankAToU/Ll3o4gUl4aG6JyM CKwvOe/WlC+TL2vfxKiENeOz/0iVnXQ3xIuJBz3qA0QhnSP994GakWyLPt4HcLwaihDA r7tNSYkCvaE3aZveTo9BDS9IKM9jLeFAUZcqRF5Qz2DuoZnRgUjJ7VYcEcEi7Bo1EyLz LnOczjpTvG0gbpMoMNr3ayMgHe8AuVjgHFznBp2yLM5mCI9TBxULIfIYXfr2Me5/LRuS iRbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Enh+iBuh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id v191-20020a6389c8000000b00563d74b6347si3087384pgd.863.2023.10.18.15.27.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 15:27:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Enh+iBuh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D9FF7820DA28; Wed, 18 Oct 2023 15:27:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231704AbjJRW1O (ORCPT + 99 others); Wed, 18 Oct 2023 18:27:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230051AbjJRW1M (ORCPT ); Wed, 18 Oct 2023 18:27:12 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDD02114 for ; Wed, 18 Oct 2023 15:27:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697668031; x=1729204031; h=from:to:cc:subject:date:message-id:mime-version; bh=75QujgEWINW/qGGyCr9s22g4nyJiNVG3a7cStBj1G6Y=; b=Enh+iBuh+LHMVKC7G0ph17YNABdMBiiB/qtBgmQZrI9DJydxHAlwCQdc otuWa/SGhER4rBjPbFOEHQAiNXQLz4vbYjQvCjAUQuq1Homc3riqk9xDv fzoQjkrNvedR1GeHwYYH075qhIOmFUZUFmOP2SbrYdBenEprtD6D1WtzX tutyKiVG8RHkLE/+lty3nMRFAqdQEwCJQwLOXocsT/cb3b5Zcetn58yta fS7YkeV57tK1eCwEmy9eAgBR/Wk1pfPpc4FNusVKmMAx90VQrDxgOVfiG 3xSqQz+QFpYXhuQ4PKOG+Hpcxi0wbfMPYVgDz3mE3XUw12GywbZKD9a3Y g==; X-IronPort-AV: E=McAfee;i="6600,9927,10867"; a="452598562" X-IronPort-AV: E=Sophos;i="6.03,236,1694761200"; d="scan'208";a="452598562" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2023 15:26:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10867"; a="750272751" X-IronPort-AV: E=Sophos;i="6.03,236,1694761200"; d="scan'208";a="750272751" Received: from minhjohn-mobl.amr.corp.intel.com (HELO jcompost-mobl.amr.corp.intel.com) ([10.212.43.53]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2023 15:26:48 -0700 From: "Compostella, Jeremy" To: Adam Dunlap Cc: Ingo Molnar , , "linux-kernel@vger.kernel.org" , "x86@kernel.org" , Felix Held Subject: Reserved bits and commit x86/sev-es: Set x86_virt_bits to the correct value straight away, instead of a two-phase approach Date: Wed, 18 Oct 2023 15:26:47 -0700 Message-ID: <87r0lry3bs.fsf@jcompost-mobl.amr.corp.intel.com> Organization: Intel Corporation - 2200 Mission College Blvd. Santa Clara, CA 95052. USA MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 18 Oct 2023 15:27:17 -0700 (PDT) --=-=-= Content-Type: text/plain Content-Disposition: inline Hi, On both AMD and Intel platform, when memory encryption is enabled (TME on Intel, SME or SVE on AMD), the number of physical address bits should be lowered. Both AMD code (arch/x86/kernel/cpu/amd.c) and Intel code (arch/x86/kernel/cpu/intel.c) support this. I recently noticed though that Intel code is not lowering the number of physical address bits as part of the early cpu initialization (c_early_init) and this is leading to MTRRs sanity check failure in generic_get_mtrr() with the following logs. mtrr: your BIOS has configured an incorrect mask, fixing it. mtrr: your BIOS has configured an incorrect mask, fixing it. [...] I have been working on fixing this following a similar approach to what AMD code does: lower the number of physical address bits at early initialization. - AMD: early_init_amd() -> detect_tme() -> c->x86_phys_bits -= [...] - Intel: early_init_intel() -> early_detect_mem_encrypt() -> c->x86_phys_bits -= [...] I posted the patch on the LKML (cf. ) It works just fine on v6.6-rc6. However, this morning Kirill brought up commit fbf6449f84bf ("x86/sev-es: Set x86_virt_bits to the correct value straight away, instead of a two-phase approach") on the tip branch to my attention and I believe it should break the AMD early flow and is breaking the patch I submitted on my local tests. This commit moves the get_cpu_address_sizes() call after the this_cpu->c_early_init() call. @@ -1601,7 +1607,6 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c) cpu_detect(c); get_cpu_vendor(c); get_cpu_cap(c); - get_cpu_address_sizes(c); setup_force_cpu_cap(X86_FEATURE_CPUID); cpu_parse_early_param(); @@ -1617,6 +1622,8 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c) setup_clear_cpu_cap(X86_FEATURE_CPUID); } + get_cpu_address_sizes(c); + setup_force_cpu_cap(X86_FEATURE_ALWAYS); cpu_set_bug_bits(c); In the light of commit fbf6449f84bf I am wondering what is the right approach to fix the regression for AMD and then fix the MTRR check for Intel. Should we introduce a new cpu_dev callback to read the number of reserved bits and take it into account in get_cpu_address_sizes() ? Regards, -- *Jeremy* /One Emacs to rule them all/ --=-=-=--