Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: "Kalra, Ashish" <ashish.kalra@amd.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: tglx@linutronix.de, mingo@redhat.com,
	dave.hansen@linux.intel.com, x86@kernel.org, bp@alien8.de,
	thomas.lendacky@amd.com, hpa@zytor.com, michael.roth@amd.com,
	nikunj@amd.com, seanjc@google.com, ardb@kernel.org,
	stable@vger.kernel.org, linux-kernel@vger.kernel.org,
	kexec@lists.infradead.org, linux-coco@lists.linux.dev
Subject: Re: [PATCH v4] x86/sev: Fix making shared pages private during kdump
Date: Mon, 5 May 2025 16:49:26 -0500	[thread overview]
Message-ID: <d980dc29-9a75-459b-a194-cb225b3fae7b@amd.com> (raw)
In-Reply-To: <aBcxjsdC4tsIgIf2@gmail.com>


On 5/4/2025 4:21 AM, Ingo Molnar wrote:
> 
> * Ashish Kalra <Ashish.Kalra@amd.com> wrote:
> 
>>  
>> -			if (addr <= ghcb && ghcb <= addr + size) {
>> +			/* Handle the case of a huge page containing the GHCB page */
>> +			if (addr <= ghcb && ghcb < addr + size) {
>>  				skipped_addr = true;
>>  				break;
>>  			}
>> @@ -1131,9 +1132,8 @@ static void shutdown_all_aps(void)
>>  void snp_kexec_finish(void)
>>  {
>>  	struct sev_es_runtime_data *data;
>> +	unsigned long size, mask, ghcb;
>>  	unsigned int level, cpu;
>> -	unsigned long size;
>> -	struct ghcb *ghcb;
> 
> So this patch just morphs the type of 'ghcb' from a typed pointer to 
> unsigned long, while most 'ghcb' uses in coco/ are typed pointers?
> 
> That's just sloppy and fragile. Please just keep 'ghcb' a typed 
> pointer, and introduce *another* variable for the virtual address to 
> the hugepage.
> 
>>  	pte_t *pte;
>>  
>>  	if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP))
>> @@ -1157,11 +1157,14 @@ void snp_kexec_finish(void)
>>  
>>  	for_each_possible_cpu(cpu) {
>>  		data = per_cpu(runtime_data, cpu);
>> -		ghcb = &data->ghcb_page;
>> -		pte = lookup_address((unsigned long)ghcb, &level);
>> +		ghcb = (unsigned long)&data->ghcb_page;
> 
> If 'ghcb' has the proper type then this ugly forced type-cast goes 
> away.
> 
>> +		pte = lookup_address(ghcb, &level);
>>  		size = page_level_size(level);
>> +		mask = page_level_mask(level);
>> +		/* Handle the case of a huge page containing the GHCB page */
>> +		ghcb &= mask;
> 
> This too calls for using a separate variable for this, because after 
> this masking 'ghcb' is very much *not* the location of a GHCB page 
> anymore...
>

Sure, i will use a separate variable for this and keep ghcb as a typed pointer.
 
>>  		set_pte_enc(pte, level, (void *)ghcb);
>> -		snp_set_memory_private((unsigned long)ghcb, (size / PAGE_SIZE));
>> +		snp_set_memory_private(ghcb, (size / PAGE_SIZE));
> 
> Do we know whether this is safe? Could the huge page around the GHCB 
> page contain anything else? What is the structure of this memory area, 
> is it all dedicated to the GHCB, or could it contain random other data?
> 

There will be an issue if the huge page containing the GHCB 
has both private and shared memory contents in it.

When we skip a huge page containing the ghcb in unshare_all_memory()
then that huge page should have been containing all shared memory,
because if it had other private memory contents then there would be a
mismatch between NPT entry and RMP entry (as RMP would have 4K sub-entries
for private and shared mappings and then there would have been size type
mismatch between NPT and RMP tables) causing an RMP fault and then correspondingly
NPT would have been smashed/split into 4K private and shared mappings.

So at end of snp_kexec_finish(), when will be revisiting this huge page
again which contains the ghcb, it should be containing other shared memory
along with the ghcb as this whole range was skipped earlier and now
we should be able to convert this huge page back to private.

Thanks,
Ashish

> Thanks,
> 
> 	Ingo


      reply	other threads:[~2025-05-05 21:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-02 21:21 [PATCH v4] x86/sev: Fix making shared pages private during kdump Ashish Kalra
2025-05-04  9:21 ` Ingo Molnar
2025-05-05 21:49   ` Kalra, Ashish [this message]

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=d980dc29-9a75-459b-a194-cb225b3fae7b@amd.com \
    --to=ashish.kalra@amd.com \
    --cc=ardb@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.roth@amd.com \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=nikunj@amd.com \
    --cc=seanjc@google.com \
    --cc=stable@vger.kernel.org \
    --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