linux-coco.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Chao Gao <chao.gao@intel.com>
To: "Huang, Kai" <kai.huang@intel.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-coco@lists.linux.dev" <linux-coco@lists.linux.dev>,
	"x86@kernel.org" <x86@kernel.org>,
	"Shutemov, Kirill" <kirill.shutemov@intel.com>,
	"Dong, Eddie" <eddie.dong@intel.com>,
	"Hansen, Dave" <dave.hansen@intel.com>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	"Reshetova, Elena" <elena.reshetova@intel.com>,
	"kirill.shutemov@linux.intel.com"
	<kirill.shutemov@linux.intel.com>,
	"seanjc@google.com" <seanjc@google.com>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"Yamahata, Isaku" <isaku.yamahata@intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"Chen, Farrah" <farrah.chen@intel.com>,
	"Edgecombe, Rick P" <rick.p.edgecombe@intel.com>,
	"bp@alien8.de" <bp@alien8.de>,
	"Williams, Dan J" <dan.j.williams@intel.com>
Subject: Re: [RFC PATCH 04/20] x86/virt/tdx: Introduce a "tdx" subsystem and "tsm" device
Date: Thu, 5 Jun 2025 16:34:09 +0800	[thread overview]
Message-ID: <aEFWgV0a2kLI62Bf@intel.com> (raw)
In-Reply-To: <61fd680c4e4afd5eb4455ee0dbbb05c30f0e7a0d.camel@intel.com>

On Tue, Jun 03, 2025 at 07:44:08AM +0800, Huang, Kai wrote:
>
>>  static int init_tdx_module(void)
>>  {
>>  	int ret;
>> @@ -1136,6 +1209,8 @@ static int init_tdx_module(void)
>>  
>>  	pr_info("%lu KB allocated for PAMT\n", tdmrs_count_pamt_kb(&tdx_tdmr_list));
>>  
>> +	tdx_subsys_init();
>> +
>>  out_put_tdxmem:
>>  	/*
>>  	 * @tdx_memlist is written here and read at memory hotplug time.
>
>The error handling of init_module_module() is already very heavy.  Although
>tdx_subsys_init() doesn't return any error, I would prefer to putting
>tdx_subsys_init() to __tdx_enable() (the caller of init_tdx_module()) so that
>init_tdx_module() can just focus on initializing the TDX module.

Sounds good. Will do.

btw, I think we can use guard() to simplify the error-handling a bit, e.g.,

diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index a755cdef69d2..0b93064b9e0f 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -1218,11 +1218,11 @@ static int init_tdx_module(void)
	 * holding mem_hotplug_lock read-lock as the memory hotplug code
	 * path reads the @tdx_memlist to reject any new memory.
	 */
-	get_online_mems();
+	guard(online_mems)();
 
	ret = build_tdx_memlist(&tdx_memlist);
	if (ret)
-		goto out_put_tdxmem;
+		return ret;
 
	/* Allocate enough space for constructing TDMRs */
	ret = alloc_tdmr_list(&tdx_tdmr_list, &tdx_sysinfo.tdmr);
@@ -1253,13 +1253,7 @@ static int init_tdx_module(void)
 
	tdx_subsys_init();
 
-out_put_tdxmem:
-	/*
-	 * @tdx_memlist is written here and read at memory hotplug time.
-	 * Lock out memory hotplug code while building it.
-	 */
-	put_online_mems();
-	return ret;
+	return 0;
 
 err_reset_pamts:
	/*
@@ -1283,7 +1277,7 @@ static int init_tdx_module(void)
	free_tdmr_list(&tdx_tdmr_list);
 err_free_tdxmem:
	free_tdx_memlist(&tdx_memlist);
-	goto out_put_tdxmem;
+	return ret;
 }
 
 static int __tdx_enable(void)
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index eaac5ae8c05c..a0c0535a9122 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -2,6 +2,7 @@
 #ifndef __LINUX_MEMORY_HOTPLUG_H
 #define __LINUX_MEMORY_HOTPLUG_H
 
+#include <linux/cleanup.h>
 #include <linux/mmzone.h>
 #include <linux/spinlock.h>
 #include <linux/notifier.h>
@@ -172,6 +173,7 @@ int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
 
 void get_online_mems(void);
 void put_online_mems(void);
+DEFINE_LOCK_GUARD_0(online_mems, get_online_mems(), put_online_mems())
 
 void mem_hotplug_begin(void);
 void mem_hotplug_done(void);

  reply	other threads:[~2025-06-05  8:34 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-23  9:52 [RFC PATCH 00/20] TD-Preserving updates Chao Gao
2025-05-23  9:52 ` [RFC PATCH 01/20] x86/virt/tdx: Print SEAMCALL leaf numbers in decimal Chao Gao
2025-06-02 23:44   ` Huang, Kai
2025-05-23  9:52 ` [RFC PATCH 02/20] x86/virt/tdx: Prepare to support P-SEAMLDR SEAMCALLs Chao Gao
2025-06-04 12:22   ` Huang, Kai
2025-06-04 13:14     ` Chao Gao
2025-06-05  0:14       ` Huang, Kai
2025-05-23  9:52 ` [RFC PATCH 03/20] x86/virt/seamldr: Introduce a wrapper for " Chao Gao
2025-06-03 11:22   ` Nikolay Borisov
2025-06-09  7:53     ` Chao Gao
2025-06-09  8:02       ` Nikolay Borisov
2025-06-10  1:03         ` Chao Gao
2025-06-10  6:52           ` Nikolay Borisov
2025-06-10 15:02             ` Dave Hansen
2025-07-11 13:59   ` Sean Christopherson
2025-07-14  9:21     ` Chao Gao
2025-05-23  9:52 ` [RFC PATCH 04/20] x86/virt/tdx: Introduce a "tdx" subsystem and "tsm" device Chao Gao
2025-06-02 23:44   ` Huang, Kai
2025-06-05  8:34     ` Chao Gao [this message]
2025-07-31 20:17       ` dan.j.williams
2025-05-23  9:52 ` [RFC PATCH 05/20] x86/virt/tdx: Export tdx module attributes via sysfs Chao Gao
2025-06-02 23:49   ` Huang, Kai
2025-06-10  1:37     ` Chao Gao
2025-06-11  2:09       ` Huang, Kai
2025-06-11  7:45         ` Chao Gao
2025-05-23  9:52 ` [RFC PATCH 06/20] x86/virt/seamldr: Add a helper to read P-SEAMLDR information Chao Gao
2025-05-23  9:52 ` [RFC PATCH 07/20] x86/virt/tdx: Expose SEAMLDR information via sysfs Chao Gao
2025-07-29  4:55   ` Xu Yilun
2025-07-29 10:00     ` Chao Gao
2025-07-31 21:01     ` dan.j.williams
2025-08-01  2:07       ` Xu Yilun
2025-08-01 15:24         ` dan.j.williams
2025-08-04  7:00           ` Xu Yilun
2025-08-05  0:17             ` dan.j.williams
2025-08-05  0:47               ` Sean Christopherson
2025-08-05  4:02                 ` dan.j.williams
2025-08-05 13:49                   ` Sean Christopherson
2025-08-06 16:33                     ` dan.j.williams
2025-08-06  3:03                   ` Xu Yilun
2025-05-23  9:52 ` [RFC PATCH 08/20] x86/virt/seamldr: Implement FW_UPLOAD sysfs ABI for TD-Preserving Updates Chao Gao
2025-06-16 22:55   ` Sagi Shahar
2025-06-17  7:55     ` Chao Gao
2025-05-23  9:52 ` [RFC PATCH 09/20] x86/virt/seamldr: Allocate and populate a module update request Chao Gao
2025-05-23  9:52 ` [RFC PATCH 10/20] x86/virt/seamldr: Introduce skeleton for TD-Preserving updates Chao Gao
2025-05-23  9:52 ` [RFC PATCH 11/20] x86/virt/seamldr: Abort updates if errors occurred midway Chao Gao
2025-06-03 12:04   ` Nikolay Borisov
2025-06-09  2:37     ` Chao Gao
2025-05-23  9:52 ` [RFC PATCH 12/20] x86/virt/seamldr: Shut down the current TDX module Chao Gao
2025-06-03 12:36   ` Nikolay Borisov
2025-06-09  2:10     ` Chao Gao
2025-05-23  9:52 ` [RFC PATCH 13/20] x86/virt/tdx: Reset software states after TDX module shutdown Chao Gao
2025-05-23  9:52 ` [RFC PATCH 14/20] x86/virt/seamldr: Install a new TDX module Chao Gao
2025-05-23  9:52 ` [RFC PATCH 15/20] x86/virt/seamldr: Handle TD-Preserving update failures Chao Gao
2025-05-23  9:52 ` [RFC PATCH 16/20] x86/virt/seamldr: Do TDX cpu init after updates Chao Gao
2025-05-23  9:52 ` [RFC PATCH 17/20] x86/virt/tdx: Establish contexts for the new module Chao Gao
2025-05-23  9:52 ` [RFC PATCH 18/20] x86/virt/tdx: Update tdx_sysinfo and check features post-update Chao Gao
2025-05-23  9:52 ` [RFC PATCH 19/20] x86/virt/seamldr: Verify availability of slots for TD-Preserving updates Chao Gao
2025-05-23  9:52 ` [RFC PATCH 20/20] x86/virt/seamldr: Enable TD-Preserving Updates Chao Gao
2025-06-11 19:56 ` [RFC PATCH 00/20] TD-Preserving updates Sagi Shahar
2025-07-11  8:04 ` Chao Gao
2025-07-11 14:06   ` Sean Christopherson
2025-07-14 10:26     ` Chao Gao
2025-07-15  0:21   ` Paul E. McKenney
2025-07-16  7:30     ` Chao Gao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aEFWgV0a2kLI62Bf@intel.com \
    --to=chao.gao@intel.com \
    --cc=bp@alien8.de \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=eddie.dong@intel.com \
    --cc=elena.reshetova@intel.com \
    --cc=farrah.chen@intel.com \
    --cc=hpa@zytor.com \
    --cc=isaku.yamahata@intel.com \
    --cc=kai.huang@intel.com \
    --cc=kirill.shutemov@intel.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rick.p.edgecombe@intel.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).