linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Pratik R. Sampat" <prsampat@amd.com>
To: Kiryl Shutsemau <kas@kernel.org>
Cc: linux-mm@kvack.org, linux-coco@lists.linux.dev, x86@kernel.org,
	linux-kernel@vger.kernel.org, tglx@linutronix.de,
	mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
	ardb@kernel.org, akpm@linux-foundation.org, david@kernel.org,
	osalvador@suse.de, thomas.lendacky@amd.com, michael.roth@amd.com
Subject: Re: [PATCH v3 1/2] mm/memory_hotplug: Add support to accept memory during hot-add
Date: Thu, 29 Jan 2026 11:32:02 -0600	[thread overview]
Message-ID: <1f588ff8-e3f5-488a-836d-5e33cfd37a51@amd.com> (raw)
In-Reply-To: <aXs09b7Q8wmHMFNQ@thinkstation>

Hi Kiryl,

On 1/29/26 4:35 AM, Kiryl Shutsemau wrote:
> On Wed, Jan 28, 2026 at 02:41:04PM -0600, Pratik R. Sampat wrote:
>> Confidential computing guests require memory to be accepted before use.
>> The unaccepted memory bitmap maintained by firmware does not track
>> most hotplugged memory ranges apart from system memory annotated to be
>> cold plugged at boot.
>>
>> Explicitly validate and transition the newly added memory to a private
>> state, making it usable by the guest.
>>
>> Signed-off-by: Pratik R. Sampat <prsampat@amd.com>
>> ---
>>  drivers/firmware/efi/unaccepted_memory.c | 18 ++++++++++++++++++
>>  include/linux/mm.h                       |  5 +++++
>>  mm/memory_hotplug.c                      |  2 ++
>>  3 files changed, 25 insertions(+)
>>
>> diff --git a/drivers/firmware/efi/unaccepted_memory.c b/drivers/firmware/efi/unaccepted_memory.c
>> index c2c067eff634..5a4c8b0f56c8 100644
>> --- a/drivers/firmware/efi/unaccepted_memory.c
>> +++ b/drivers/firmware/efi/unaccepted_memory.c
>> @@ -209,6 +209,24 @@ bool range_contains_unaccepted_memory(phys_addr_t start, unsigned long size)
>>  	return ret;
>>  }
>>  
>> +/*
>> + * Unaccepted memory bitmap only covers initial boot memory and not the
>> + * hotpluggable range that is part of SRAT parsing. However, some initial memory
>> + * with the attribute EFI_MEMORY_HOT_PLUGGABLE can indicate boot time memory
>> + * that can be hot-removed. Hence, handle acceptance in accordance with the
>> + * unaccepted bitmap. Otherwise, perform the state change for the memory range
>> + * up-front.
>> + */
>> +void accept_hotplug_memory(phys_addr_t start, unsigned long size)
>> +{
>> +	if (range_contains_unaccepted_memory(start, size)) {
>> +		accept_memory(start, size);
>> +		return;
>> +	}
> 
> No. This is buggy. The memory has to be accepted regardless of state in
> the bitmap. If the memory is ever unplugged the bitmap state is not
> relevant.
> 
> So, accept it unconditionally and mark the memory accepted in the
> bitmap.

I see. This makes sense for acceptance since device_del would always fully
unplug it.

I still might need to keep a version of bitmap handling in unaccept considering
the case where partially accepted (lazy) memory is removed.
For SNP, pvalidate is not an idempotent operation and we must only rescind
the state for the bits that were previously accepted.

Also, now that I stare at the unaccept_hotplug_memory implementation, I realize
calling range_contains_unaccepted_memory() is plain wrong. I should rather be
looking at the ranges and handling the bitmap + unacceptance.
I'll be sure to clean that up in the next iteration as well.

Thanks,
--Pratik

> 
>> +
>> +	arch_accept_memory(start, start + size);
>> +}
>> +
>>  #ifdef CONFIG_PROC_VMCORE
>>  static bool unaccepted_memory_vmcore_pfn_is_ram(struct vmcore_cb *cb,
>>  						unsigned long pfn)
>> diff --git a/include/linux/mm.h b/include/linux/mm.h
>> index 15076261d0c2..2d3c1ea40606 100644
>> --- a/include/linux/mm.h
>> +++ b/include/linux/mm.h
>> @@ -4504,6 +4504,7 @@ int set_anon_vma_name(unsigned long addr, unsigned long size,
>>  
>>  bool range_contains_unaccepted_memory(phys_addr_t start, unsigned long size);
>>  void accept_memory(phys_addr_t start, unsigned long size);
>> +void accept_hotplug_memory(phys_addr_t start, unsigned long size);
>>  
>>  #else
>>  
>> @@ -4517,6 +4518,10 @@ static inline void accept_memory(phys_addr_t start, unsigned long size)
>>  {
>>  }
>>  
>> +static inline void accept_hotplug_memory(phys_addr_t start, unsigned long size)
>> +{
>> +}
>> +
>>  #endif
>>  
>>  static inline bool pfn_is_unaccepted_memory(unsigned long pfn)
>> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
>> index a63ec679d861..549ccfd190ee 100644
>> --- a/mm/memory_hotplug.c
>> +++ b/mm/memory_hotplug.c
>> @@ -1567,6 +1567,8 @@ int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags)
>>  	if (!strcmp(res->name, "System RAM"))
>>  		firmware_map_add_hotplug(start, start + size, "System RAM");
>>  
>> +	accept_hotplug_memory(start, size);
>> +
>>  	/* device_online() will take the lock when calling online_pages() */
>>  	mem_hotplug_done();
>>  
>> -- 
>> 2.52.0
>>
> 



  reply	other threads:[~2026-01-29 17:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-28 20:41 [PATCH v3 0/2] SEV-SNP Unaccepted Memory Hotplug Pratik R. Sampat
2026-01-28 20:41 ` [PATCH v3 1/2] mm/memory_hotplug: Add support to accept memory during hot-add Pratik R. Sampat
2026-01-29 10:35   ` Kiryl Shutsemau
2026-01-29 17:32     ` Pratik R. Sampat [this message]
2026-01-28 20:41 ` [PATCH v3 2/2] x86/sev: Add support to unaccept memory after hot-remove Pratik R. Sampat
2026-01-28 21:08   ` Andrew Morton
2026-01-28 22:25     ` Pratik R. Sampat
2026-01-28 21:15   ` Dave Hansen
2026-01-29 10:40     ` Kiryl Shutsemau
2026-01-29 17:32       ` Pratik R. Sampat
2026-01-29 17:39         ` Dave Hansen
2026-01-29 19:32           ` Pratik R. Sampat

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=1f588ff8-e3f5-488a-836d-5e33cfd37a51@amd.com \
    --to=prsampat@amd.com \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@kernel.org \
    --cc=kas@kernel.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=michael.roth@amd.com \
    --cc=mingo@redhat.com \
    --cc=osalvador@suse.de \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --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