mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>,
	linux-kernel@vger.kernel.org, x86@kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Michael Roth <michael.roth@amd.com>,
	Ashish Kalra <ashish.kalra@amd.com>
Subject: Re: [PATCH v3 7/8] x86/sev: Add full support for a segmented RMP table
Date: Fri, 18 Oct 2024 10:06:01 -0500	[thread overview]
Message-ID: <13538afd-e3cf-d030-e714-977ff8d5700a@amd.com> (raw)
In-Reply-To: <4c1198e7-00c8-449e-bbb9-7dcf15e11cfe@amd.com>

On 10/18/24 03:37, Neeraj Upadhyay wrote:
> 
> 
>>  
>> @@ -196,7 +203,42 @@ static void __init __snp_fixup_e820_tables(u64 pa)
>>  void __init snp_fixup_e820_tables(void)
>>  {
>>  	__snp_fixup_e820_tables(probed_rmp_base);
>> -	__snp_fixup_e820_tables(probed_rmp_base + probed_rmp_size);
>> +
>> +	if (RMP_IS_SEGMENTED(rmp_cfg)) {
>> +		unsigned long size;
>> +		unsigned int i;
>> +		u64 pa, *rst;
>> +
>> +		pa = probed_rmp_base;
>> +		pa += RMPTABLE_CPU_BOOKKEEPING_SZ;
>> +		pa += RMP_SEGMENT_TABLE_SIZE;
>> +		__snp_fixup_e820_tables(pa);
>> +
>> +		pa -= RMP_SEGMENT_TABLE_SIZE;
>> +		rst = early_memremap(pa, RMP_SEGMENT_TABLE_SIZE);
>> +		if (!rst)
>> +			return;
>> +
>> +		for (i = 0; i < rst_max_index; i++) {
>> +			pa = RST_ENTRY_SEGMENT_BASE(rst[i]);
>> +			size = RST_ENTRY_MAPPED_SIZE(rst[i]);
>> +			if (!size)
>> +				continue;
>> +
>> +			__snp_fixup_e820_tables(pa);
>> +
>> +			/* Mapped size in GB */
>> +			size *= (1UL << 30);
> 
> nit: size <<= 30 ?

Yeah, might be clearer.

> 
>> +			if (size > rmp_segment_coverage_size)
>> +				size = rmp_segment_coverage_size;
>> +
>> +			__snp_fixup_e820_tables(pa + size);
> 
> I might have understood this wrong, but is this call meant to fixup segmented
> rmp table end. So, is below is required?
> 
> size  = PHYS_PFN(size);
> size <<= 4;
> __snp_fixup_e820_tables(pa + size);

Good catch. Yes, it is supposed to be checking the end of the RMP segment
which should be the number of entries and not the mapped size.

> 
>> +		}
>> +
>> +		early_memunmap(rst, RMP_SEGMENT_TABLE_SIZE);
>> +	} else {
>> +		__snp_fixup_e820_tables(probed_rmp_base + probed_rmp_size);
>> +	}
>>  }
>>  
> 
> ...
> 
>> +static bool __init segmented_rmptable_setup(void)
>> +{
>> +	u64 rst_pa, *rst, pa, ram_pa_end, ram_pa_max;
>> +	unsigned int i, max_index;
>> +
>> +	if (!probed_rmp_base)
>> +		return false;
>> +
>> +	if (!alloc_rmp_segment_table())
>> +		return false;
>> +
>> +	/* Map the RMP Segment Table */
>> +	rst_pa = probed_rmp_base + RMPTABLE_CPU_BOOKKEEPING_SZ;
>> +	rst = memremap(rst_pa, RMP_SEGMENT_TABLE_SIZE, MEMREMAP_WB);
>> +	if (!rst) {
>> +		pr_err("Failed to map RMP segment table addr %#llx\n", rst_pa);
>> +		goto e_free;
>> +	}
>> +
>> +	/* Get the address for the end of system RAM */
>> +	ram_pa_max = max_pfn << PAGE_SHIFT;
>> +
>> +	/* Process each RMP segment */
>> +	max_index = 0;
>> +	ram_pa_end = 0;
>> +	for (i = 0; i < rst_max_index; i++) {
>> +		u64 rmp_segment, rmp_size, mapped_size;
>> +
>> +		mapped_size = RST_ENTRY_MAPPED_SIZE(rst[i]);
>> +		if (!mapped_size)
>> +			continue;
>> +
>> +		max_index = i;
>> +
>> +		/* Mapped size in GB */
>> +		mapped_size *= (1ULL << 30);
> 
> nit: mapped_size <<= 30 ?

Ditto.

> 
>> +		if (mapped_size > rmp_segment_coverage_size)
>> +			mapped_size = rmp_segment_coverage_size;
>> +
>> +		rmp_segment = RST_ENTRY_SEGMENT_BASE(rst[i]);
>> +
>> +		rmp_size = PHYS_PFN(mapped_size);
>> +		rmp_size <<= 4;
>> +
>> +		pa = (u64)i << rmp_segment_coverage_shift;
>> +
>> +		/* Some segments may be for MMIO mapped above system RAM */
>> +		if (pa < ram_pa_max)
>> +			ram_pa_end = pa + mapped_size;
>> +
>> +		if (!alloc_rmp_segment_desc(rmp_segment, rmp_size, pa))
>> +			goto e_unmap;
>> +
>> +		pr_info("RMP segment %u physical address [%#llx - %#llx] covering [%#llx - %#llx]\n",
>> +			i, rmp_segment, rmp_segment + rmp_size - 1, pa, pa + mapped_size - 1);
>> +	}
>> +
>> +	if (ram_pa_max > ram_pa_end) {
>> +		pr_err("Segmented RMP does not cover full system RAM (expected 0x%llx got 0x%llx)\n",
>> +		       ram_pa_max, ram_pa_end);
>> +		goto e_unmap;
>> +	}
>> +
>> +	/* Adjust the maximum index based on the found segments */
>> +	rst_max_index = max_index + 1;
>> +
>> +	memunmap(rst);
>> +
>> +	return true;
>> +
>> +e_unmap:
>> +	memunmap(rst);
>> +
>> +e_free:
>> +	free_rmp_segment_table();
>> +
>> +	return false;
>> +}
>> +
> 
> ...
> 
>>  
>> +static bool probe_segmented_rmptable_info(void)
>> +{
>> +	unsigned int eax, ebx, segment_shift, segment_shift_min, segment_shift_max;
>> +	u64 rmp_base, rmp_end;
>> +
>> +	rdmsrl(MSR_AMD64_RMP_BASE, rmp_base);
>> +	rdmsrl(MSR_AMD64_RMP_END, rmp_end);
>> +
>> +	if (!(rmp_base & RMP_ADDR_MASK)) {
>> +		pr_err("Memory for the RMP table has not been reserved by BIOS\n");
>> +		return false;
>> +	}
>> +
>> +	WARN_ONCE(rmp_end & RMP_ADDR_MASK,
>> +		  "Segmented RMP enabled but RMP_END MSR is non-zero\n");
>> +
>> +	/* Obtain the min and max supported RMP segment size */
>> +	eax = cpuid_eax(0x80000025);
>> +	segment_shift_min = eax & GENMASK(5, 0);
>> +	segment_shift_max = (eax & GENMASK(11, 6)) >> 6;
>> +
>> +	/* Verify the segment size is within the supported limits */
>> +	segment_shift = MSR_AMD64_RMP_SEGMENT_SHIFT(rmp_cfg);
>> +	if (segment_shift > segment_shift_max || segment_shift < segment_shift_min) {
>> +		pr_err("RMP segment size (%u) is not within advertised bounds (min=%u, max=%u)\n",
>> +		       segment_shift, segment_shift_min, segment_shift_max);
>> +		return false;
>> +	}
>> +
>> +	/* Override the max supported RST index if a hardware limit exists */
>> +	ebx = cpuid_ebx(0x80000025);
>> +	if (ebx & BIT(10))
>> +		rst_max_index = ebx & GENMASK(9, 0);
>> +
>> +	set_rmp_segment_info(segment_shift);
>> +
>> +	probed_rmp_base = rmp_base;
>> +	probed_rmp_size = 0;
>> +
>> +	pr_info("RMP segment table physical address [0x%016llx - 0x%016llx]\n",
>> +		rmp_base, rmp_base + RMPTABLE_CPU_BOOKKEEPING_SZ + RMP_SEGMENT_TABLE_SIZE);
>> +
> 
> rmp_base + RMPTABLE_CPU_BOOKKEEPING_SZ, rmp_base + RMPTABLE_CPU_BOOKKEEPING_SZ + RMP_SEGMENT_TABLE_SIZE);

I really want the full range printed, which includes the bookkeeping area.
So maybe the text could be clearer, let me think about that.

Thanks,
Tom

> 
> 
> - Neeraj
> 
>> +	return true;
>> +}
>> +

  reply	other threads:[~2024-10-18 15:06 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-30 15:22 [PATCH v3 0/8] Provide support for RMPREAD and a segmented RMP Tom Lendacky
2024-09-30 15:22 ` [PATCH v3 1/8] x86/sev: Prepare for using the RMPREAD instruction to access the RMP Tom Lendacky
2024-10-16  8:52   ` Nikunj A. Dadhania
2024-10-16 14:43     ` Tom Lendacky
2024-10-17  5:24       ` Nikunj A. Dadhania
2024-10-16 15:01   ` Neeraj Upadhyay
2024-09-30 15:22 ` [PATCH v3 2/8] x86/sev: Add support for the RMPREAD instruction Tom Lendacky
2024-10-16 10:46   ` Nikunj A. Dadhania
2024-10-17 15:26   ` Borislav Petkov
2024-10-17 16:24     ` Tom Lendacky
2024-10-18  4:21   ` Neeraj Upadhyay
2024-10-18 12:41   ` Borislav Petkov
2024-10-18 15:14     ` Tom Lendacky
2024-10-21 15:41       ` Borislav Petkov
2024-10-21 17:10         ` Tom Lendacky
2024-10-21 17:49           ` Borislav Petkov
2024-09-30 15:22 ` [PATCH v3 3/8] x86/sev: Require the RMPREAD instruction after Fam19h Tom Lendacky
2024-09-30 17:03   ` Dave Hansen
2024-09-30 18:59     ` Tom Lendacky
2024-10-18 13:06       ` Borislav Petkov
2024-10-18  4:26   ` Neeraj Upadhyay
2024-10-18 13:30     ` Tom Lendacky
2024-09-30 15:22 ` [PATCH v3 4/8] x86/sev: Move the SNP probe routine out of the way Tom Lendacky
2024-10-16 11:05   ` Nikunj A. Dadhania
2024-10-18  4:28   ` Neeraj Upadhyay
2024-09-30 15:22 ` [PATCH v3 5/8] x86/sev: Map only the RMP table entries instead of the full RMP range Tom Lendacky
2024-10-16 11:25   ` [sos-linux-ext-patches] " Nikunj A. Dadhania
2024-10-18  4:38   ` Neeraj Upadhyay
2024-10-18 13:32     ` Tom Lendacky
2024-09-30 15:22 ` [PATCH v3 6/8] x86/sev: Treat the contiguous RMP table as a single RMP segment Tom Lendacky
2024-10-17 11:05   ` Nikunj A. Dadhania
2024-10-18  5:59   ` Neeraj Upadhyay
2024-10-18 13:56     ` Tom Lendacky
2024-10-18 14:42       ` Tom Lendacky
2024-09-30 15:22 ` [PATCH v3 7/8] x86/sev: Add full support for a segmented RMP table Tom Lendacky
2024-10-18  6:32   ` Nikunj A. Dadhania
2024-10-18 14:41     ` Tom Lendacky
2024-10-18  8:37   ` Neeraj Upadhyay
2024-10-18 15:06     ` Tom Lendacky [this message]
2024-09-30 15:22 ` [PATCH v3 8/8] x86/sev/docs: Document the SNP Reverse Map Table (RMP) Tom Lendacky
2024-10-18  6:56   ` Nikunj A. Dadhania
2024-10-18 14:48     ` Tom Lendacky
2024-10-18 13:31   ` Neeraj Upadhyay

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=13538afd-e3cf-d030-e714-977ff8d5700a@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=Neeraj.Upadhyay@amd.com \
    --cc=ashish.kalra@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.roth@amd.com \
    --cc=mingo@redhat.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

all inboxes | Powered by JetHome®