Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5687071rwd; Mon, 12 Jun 2023 08:21:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4qJ4pC8xoAh+qtIqQyiOZ4czhpfvaMRp1NhnW2/N0jzKOMY1v8ehtuY59awRyojAC87PjK X-Received: by 2002:a05:6a00:248c:b0:663:29c9:7cc6 with SMTP id c12-20020a056a00248c00b0066329c97cc6mr10635578pfv.21.1686583296016; Mon, 12 Jun 2023 08:21:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686583296; cv=none; d=google.com; s=arc-20160816; b=VelSMx625hd7p08p8G+UueR34uNMh2CmjuXLTWkupKfl76G5UN1O5PYVWWY0BdeXTS QMpYYtPE3OYgmv/66QsMVSA1b8T6QZ5vlh3X/dUXbY2UeJhTbQ7dbdn0HHDZQ1rOI5To 01aArkaMED7MkIxBSE1fe3kz48t91BBt5qTuAW98meu2hQR15Mn4OHwICRB7aTm4vOv8 dWH2jbrjw6/BTujyNH/ktu6Pe9qMrd9sMwaZ7kv7Wr4kIS0ejlQpJreFIPYExTB/l/+e m/QDjZqTMj8U0ppLoTG0Tr2aBvRCAUCCziw3K0IdkU1m270CDwDX8dnCDZRFa0/ub1Bs ZsiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=OepVOVESBsHnklaeVzadff+wqnBaRR0RW98FlIFm8kc=; b=P+0aSdVq5Gd9pnJs0IBPWReyV6FTp2h1H4WDQfN1S1WJ1ndWye+E0vGQqnZzvNrGoO HRlNc/ieMXYSxRq+i+AlPrfOdpdaU/4xexbu+rnQyZbH9B+OsxQpPJ05fp961D3dDVba O2VzCM+CynQ4HuY8p3AJDTAZ2jMiTvSOP9QcLi0poGGt3NmcVNbbYjhGNK9Zl0tI9Z0I G0fNejMUp57KIo2i5Ru421a2S7LL62QqCOzFp5APl1RJaVhy1LOb75wGl23VWKLsi/eF LvfhXAY4Y499jo4nICQ6C/9hw+aJ/vhfBqgvAcDCffnjU6mse3za75nJNsepJBU3CmN0 /lXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HpbqCkok; 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=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x25-20020aa79579000000b0064d45bbba8csi6942712pfq.62.2023.06.12.08.21.24; Mon, 12 Jun 2023 08:21:35 -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=@intel.com header.s=Intel header.b=HpbqCkok; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236274AbjFLOft (ORCPT + 99 others); Mon, 12 Jun 2023 10:35:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235319AbjFLOfq (ORCPT ); Mon, 12 Jun 2023 10:35:46 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D920BAA; Mon, 12 Jun 2023 07:35:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686580536; x=1718116536; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=UV/2h6fqgbTSA+6nmz5EI6zXiJFLRye4hW68DS9EZqo=; b=HpbqCkok+pVDmwG7yB5/WvZDlqCwd/MyZibYrkmRhczsDhEde1vXxPHR fYmZbUmNAtQTJrBLZBbAqq/TrpOsa1iQewreRjw4mT05tLiaqHLJthAG5 blNWWMYn3YEqaVcQFtXaHz4NQMDz4/+sOb+mBeJ/nIvGMH8bCBDn672xs MjD9FEzpzPp9VE2NsQ4if40msT/AnWDz1sUnf6Kivys/RFRRIeyJ6jsx0 iudTq3t/aUDbdyzfO3aB5Jfdv2Ru1BNmUvfEKdFvURaqC6y6tSn7qJUDF Cw1Paqv2SWAoBzjcSGtP6pIdGWIliT3eWfH33+5LU3K62yBkyLHzqg+U1 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10739"; a="338419480" X-IronPort-AV: E=Sophos;i="6.00,236,1681196400"; d="scan'208";a="338419480" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2023 07:34:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10739"; a="711224041" X-IronPort-AV: E=Sophos;i="6.00,236,1681196400"; d="scan'208";a="711224041" Received: from smizr3x-mobl3.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.43.127]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2023 07:33:58 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 3E33710CE1A; Mon, 12 Jun 2023 17:33:55 +0300 (+03) Date: Mon, 12 Jun 2023 17:33:55 +0300 From: "kirill.shutemov@linux.intel.com" To: "Huang, Kai" Cc: "kvm@vger.kernel.org" , "Hansen, Dave" , "linux-kernel@vger.kernel.org" , "Luck, Tony" , "david@redhat.com" , "bagasdotme@gmail.com" , "ak@linux.intel.com" , "Wysocki, Rafael J" , "Chatre, Reinette" , "Christopherson,, Sean" , "pbonzini@redhat.com" , "tglx@linutronix.de" , "Yamahata, Isaku" , "linux-mm@kvack.org" , "Shahar, Sagi" , "peterz@infradead.org" , "imammedo@redhat.com" , "Gao, Chao" , "Brown, Len" , "sathyanarayanan.kuppuswamy@linux.intel.com" , "Huang, Ying" , "Williams, Dan J" Subject: Re: [PATCH v11 11/20] x86/virt/tdx: Fill out TDMRs to cover all TDX memory regions Message-ID: <20230612143355.sur7zc7byu7omxal@box.shutemov.name> References: <927ec9871721d2a50f1aba7d1cf7c3be50e4f49b.1685887183.git.kai.huang@intel.com> <0600959d-9e10-fb1f-b3a9-862a51b9d8e1@intel.com> <201af662-f700-9145-c113-563e378074ad@intel.com> <89c99e7360dc2acfe5fb56c2bbb40e074e1f94d5.camel@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <89c99e7360dc2acfe5fb56c2bbb40e074e1f94d5.camel@intel.com> X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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 On Mon, Jun 12, 2023 at 02:33:58AM +0000, Huang, Kai wrote: > > > > > Maybe not even a pr_warn(), but something that's a bit ominous and has a > > chance of getting users to act. > > Sorry I am not sure how to do. Could you give some suggestion? Maybe something like this would do? I'm struggle with the warning message. Any suggestion is welcome. diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 9cd4f6b58d4a..cc141025b249 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -627,6 +627,15 @@ static int fill_out_tdmrs(struct list_head *tmb_list, /* @tdmr_idx is always the index of last valid TDMR. */ tdmr_list->nr_consumed_tdmrs = tdmr_idx + 1; + /* + * Warn early that kernel is about to run out of TDMRs. + * + * This is indication that TDMR allocation has to be reworked to be + * smarter to not run into an issue. + */ + if (tdmr_list->max_tdmrs - tdmr_list->nr_consumed_tdmrs < TDMR_NR_WARN) + pr_warn("Low number of spare TDMRs\n"); + return 0; } diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h index 323ce744b853..17efe33847ae 100644 --- a/arch/x86/virt/vmx/tdx/tdx.h +++ b/arch/x86/virt/vmx/tdx/tdx.h @@ -98,6 +98,9 @@ struct tdx_memblock { int nid; }; +/* Warn if kernel has less than TDMR_NR_WARN TDMRs after allocation */ +#define TDMR_NR_WARN 4 + struct tdmr_info_list { void *tdmrs; /* Flexible array to hold 'tdmr_info's */ int nr_consumed_tdmrs; /* How many 'tdmr_info's are in use */ -- Kiryl Shutsemau / Kirill A. Shutemov