Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1261671rdg; Fri, 13 Oct 2023 16:03:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFh8swUfTC+87Foj8KgR1Vv4wcGSjaeh0VYIoAs1/dWMF8Jfs508RRs8krNx6y8uLLhDfrd X-Received: by 2002:a05:6a00:807:b0:68f:b7f6:f1df with SMTP id m7-20020a056a00080700b0068fb7f6f1dfmr29961279pfk.5.1697238194826; Fri, 13 Oct 2023 16:03:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697238194; cv=none; d=google.com; s=arc-20160816; b=PAZ1hTUbPhWIEWo12Qag24QgoKqLHv0PYpj6X+MzFuH1rsrQPEWd8L08LaBnfVw1TE 0F8j+HVUjnfKZaHKpNdOQYUAOK9SJXbDykAcTmQMCACrBE/IaNw8XdRZHxcWbe9Y4Zu0 hDCuxnogo+4AKjKbdCtY7PHWXAAFOZqYSfa6oKRaYLruZF4iqgfWheG5xt/8HfP7fYoU 1Dt3iVRP6Z6L0b9YBJGO11fwdvUn6AqGTqvu/by4J+/7BMG2wrPOfKvN3a4kVvn7o5ui BwyIQNiPpSeWjI6OolrkSwBq+OlfOw7hOAOp69xna1uNJtWTdViI0qc35bRhzswxijYj jZ0Q== 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 :references:subject:cc:to:from:dkim-signature; bh=952Vz9BWhJWjk+5ANpRwJvWkzWm9QkhBfU78JDvThTg=; fh=FPLmz1lqCyupV9hiR6t/zhpcZU1TDski5cNkXi87dgI=; b=LGdx1zd64TcC7/Qjax5ce+eXAUU5UVY+B+XAaF+/xAxuFbWEswxbfC5bTfU8PGST6u T6LzDu0j206mVTn1aNDGRaeTN/b5Xtvh9SIlMJvlrkI37KA/KdnyQf5jj7mGVjNBsQq5 TEiwjwKTClCSUSOiauDbfURE3ggYq/MyS0Vmdy2Q0JE5wOQxlPxt+MlmMDZFgxzNSBO6 Jb6z2QhAauzrmT7vHFGWZwslblcjDlGy2cvr78K7shqzF3ik9E8e3STlC3sKQWziNTnj tayboSQ+hdLUGXiycj8kfQLUv4iHdCpD4dQ0fizX1TSYyNFezF0iNzyADjZk69G4A4Ym h2ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZrpCuh+E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id h190-20020a6383c7000000b005ab74d58e04si2312196pge.58.2023.10.13.16.03.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 16:03:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZrpCuh+E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id B376D822B732; Fri, 13 Oct 2023 16:03:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232546AbjJMXDH (ORCPT + 99 others); Fri, 13 Oct 2023 19:03:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232384AbjJMXDG (ORCPT ); Fri, 13 Oct 2023 19:03:06 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EADCCB7 for ; Fri, 13 Oct 2023 16:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697238184; x=1728774184; h=from:to:cc:subject:references:date:message-id: mime-version; bh=4tg2hRkVnC558rPe0omEPqwmSytOElR8PBs/m6fdwIs=; b=ZrpCuh+E+cS+kc1pQyZKE2D80rlTrD4oc8UeCiQSvqInEUgxFYKGod4S ZDvIpI/ByizyUOqcnybqeRTMrpTgnNMYRNd0paOwBkxyjr3EwL7FiPknj 2Hra+3kPbT6d+OPU09MnhkhDY5olA3/dJrAvofTBb86n76SffifVrL5V3 0V/8kBa8XIe53++WPGh84KEFkqQoeKws3jsjDl3T7o4Jk6Zq6w2OWYxBS 9SATqCYcYrP3gOsHjnXwwWRqDrBvEVebiNEjsWSnn8sk1hdmTGFCwQiH0 yDM/TlJEwHZ/2MZtO3AtNHIGxO256XTXJQIEb5sCwgEUpo86Kf9I1aZ+n Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10862"; a="389142664" X-IronPort-AV: E=Sophos;i="6.03,223,1694761200"; d="scan'208";a="389142664" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2023 16:03:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10862"; a="704828913" X-IronPort-AV: E=Sophos;i="6.03,223,1694761200"; d="scan'208";a="704828913" Received: from sridharg-mobl2.amr.corp.intel.com (HELO jcompost-mobl.amr.corp.intel.com) ([10.212.73.167]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2023 16:03:03 -0700 From: "Compostella, Jeremy" To: kirill.shutemov@linux.intel.com, "Huang, Kai" Cc: "mingo@kernel.org" , "Li, Xin3" , "linux-kernel@vger.kernel.org" , "x86@kernel.org" , "bp@alien8.de" Subject: Re: [PATCH v3 1/2] x86/cpu/intel: Fix MTRR verification for TME enabled platforms References: <87a5t6ylpc.fsf@jcompost-mobl.amr.corp.intel.com> <00392c722e65c8d0da40384eecf8955be4875969.camel@intel.com> <20231002224752.33qa2lq7q2w4nqws@box> <65d26d679843e26fd5e6252a08391f87243a49c9.camel@intel.com> <20231003070659.hsjvnoc53agvms6c@box.shutemov.name> Date: Fri, 13 Oct 2023 16:03:02 -0700 Message-ID: <87edhyyvkp.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=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Fri, 13 Oct 2023 16:03:12 -0700 (PDT) --=-=-= Content-Type: text/plain Content-Disposition: inline "kirill.shutemov@linux.intel.com" writes: > On Tue, Oct 03, 2023 at 02:06:52AM +0000, Huang, Kai wrote: >> On Tue, 2023-10-03 at 01:47 +0300, kirill.shutemov@linux.intel.com wrote: >> > On Fri, Sep 29, 2023 at 09:14:00AM +0000, Huang, Kai wrote: >> > > On Thu, 2023-09-28 at 15:30 -0700, Compostella, Jeremy wrote: >> > > > On TME enabled platform, BIOS publishes MTRR taking into account Total >> > > > Memory Encryption (TME) reserved bits. >> > > > >> > > > generic_get_mtrr() performs a sanity check of the MTRRs relying on the >> > > > `phys_hi_rsvd' variable which is set using the cpuinfo_x86 structure >> > > > `x86_phys_bits' field. But at the time the generic_get_mtrr() >> > > > function is ran the `x86_phys_bits' has not been updated by >> > > > detect_tme() when TME is enabled. >> > > > >> > > > Since the x86_phys_bits does not reflect yet the real maximal physical >> > > > address size yet generic_get_mtrr() complains by logging the following >> > > > messages. >> > > > >> > > > mtrr: your BIOS has configured an incorrect mask, fixing it. >> > > > mtrr: your BIOS has configured an incorrect mask, fixing it. >> > > > [...] >> > > > >> > > > In such a situation, generic_get_mtrr() returns an incorrect size but >> > > > no side effect were observed during our testing. >> > > > >> > > > For `x86_phys_bits' to be updated before generic_get_mtrr() runs, >> > > > move the detect_tme() call from init_intel() to early_init_intel(). >> > > >> > > Hi, >> > > >> > > This move looks good to me, but +Kirill who is the author of detect_tme() for >> > > further comments. >> > > >> > > Also I am not sure whether it's worth to consider to move this to >> > > get_cpu_address_sizes(), which calculates the virtual/physical address sizes. >> > > Thus it seems anything that can impact physical address size could be put there. >> > >> > Actually, I am not sure how this patch works. AFAICS after the patch we >> > have the following callchain: >> > >> > early_identify_cpu() >> > this_cpu->c_early_init() (which is early_init_init()) >> > detect_tme() >> > c->x86_phys_bits -= keyid_bits; >> > get_cpu_address_sizes(c); >> > c->x86_phys_bits = eax & 0xff; >> > >> > Looks like get_cpu_address_sizes() would override what detect_tme() does. >> >> After this patch, early_identify_cpu() calls get_cpu_address_sizes() first and >> then calls c_early_init(), which calls detect_tme(). >> >> So looks no override. No? No override indeed as get_cpu_address_sizes() is always called before early_init_intel or init_intel(). - init/main.c::start_kernel() - arch/x86/kernel/setup.c::setup_arch() - arch/x86/kernel/cpu/common.c::early_cpu_init() - early_identify_cpu() - get_cpu_address_sizes(c) c->x86_phys_bits = eax & 0xff; - arch/x86/kernel/cpu/intel.c::early_init_intel() - detect_tme() c->x86_phys_bits -= keyid_bits; - arch/x86/kernel/cpu/common.c::arch_cpu_finalize_init() - identify_boot_cpu() - identify_cpu() - get_cpu_address_sizes(c) c->x86_phys_bits = eax & 0xff; - arch/x86/kernel/cpu/intel.c::init_intel() - early_init_intel() - detect_tme() c->x86_phys_bits -= keyid_bits; > We identify CPU twice: once via early_cpu_init() and the second time via > identify_boot_cpu()/identify_secondary_cpu(). I am talking about > early_cpu_init() codepath. > > It might not matter in practice as of now, because it will get straight > later, but CPU ident code is mess as it is. Let's not make it even worse. This change is not modifying the CPU indent code, this is just re-ordering detect_tme() call in the intel specifics hook so that the information is available earlier as it is needed by generic_get_mtrr(). This is similar to what is done in arch/x86/kernel/cpu/amd.c. --=-=-=--