[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <SN6PR12MB2767322F8C573EDFA1C20AD78E659@SN6PR12MB2767.namprd12.prod.outlook.com>
Date: Wed, 10 Aug 2022 03:59:34 +0000
From: "Kalra, Ashish" <Ashish.Kalra@....com>
To: Borislav Petkov <bp@...en8.de>
CC: "x86@...nel.org" <x86@...nel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"kvm@...r.kernel.org" <kvm@...r.kernel.org>,
"linux-coco@...ts.linux.dev" <linux-coco@...ts.linux.dev>,
"linux-mm@...ck.org" <linux-mm@...ck.org>,
"linux-crypto@...r.kernel.org" <linux-crypto@...r.kernel.org>,
"tglx@...utronix.de" <tglx@...utronix.de>,
"mingo@...hat.com" <mingo@...hat.com>,
"jroedel@...e.de" <jroedel@...e.de>,
"Lendacky, Thomas" <Thomas.Lendacky@....com>,
"hpa@...or.com" <hpa@...or.com>,
"ardb@...nel.org" <ardb@...nel.org>,
"pbonzini@...hat.com" <pbonzini@...hat.com>,
"seanjc@...gle.com" <seanjc@...gle.com>,
"vkuznets@...hat.com" <vkuznets@...hat.com>,
"jmattson@...gle.com" <jmattson@...gle.com>,
"luto@...nel.org" <luto@...nel.org>,
"dave.hansen@...ux.intel.com" <dave.hansen@...ux.intel.com>,
"slp@...hat.com" <slp@...hat.com>,
"pgonda@...gle.com" <pgonda@...gle.com>,
"peterz@...radead.org" <peterz@...radead.org>,
"srinivas.pandruvada@...ux.intel.com"
<srinivas.pandruvada@...ux.intel.com>,
"rientjes@...gle.com" <rientjes@...gle.com>,
"dovmurik@...ux.ibm.com" <dovmurik@...ux.ibm.com>,
"tobin@....com" <tobin@....com>,
"Roth, Michael" <Michael.Roth@....com>,
"vbabka@...e.cz" <vbabka@...e.cz>,
"kirill@...temov.name" <kirill@...temov.name>,
"ak@...ux.intel.com" <ak@...ux.intel.com>,
"tony.luck@...el.com" <tony.luck@...el.com>,
"marcorr@...gle.com" <marcorr@...gle.com>,
"sathyanarayanan.kuppuswamy@...ux.intel.com"
<sathyanarayanan.kuppuswamy@...ux.intel.com>,
"alpergun@...gle.com" <alpergun@...gle.com>,
"dgilbert@...hat.com" <dgilbert@...hat.com>,
"jarkko@...nel.org" <jarkko@...nel.org>
Subject: RE: [PATCH Part2 v6 09/49] x86/fault: Add support to handle the RMP
fault for user address
[AMD Official Use Only - General]
Hello Boris,
>> When SEV-SNP is enabled globally, a write from the host goes through
>> the
>globally?
>Can SNP be even enabled any other way?
>I see the APM talks about it being enabled globally, I guess this means the RMP represents *all* system memory?
Actually SNP feature can be enabled globally, but SNP is activated on a per VM basis.
>From the APM:
The term SNP-enabled indicates that SEV-SNP is globally enabled in the SYSCFG
MSR. The term SNP-active indicates that SEV-SNP is enabled for a specific VM in the
SEV_FEATURES field of its VMSA
>> +/*
>> + * Return 1 if the caller need to retry, 0 if it the address need to be split
>> + * in order to resolve the fault.
>> + */
>Magic numbers.
>Pls do instead:
>enum rmp_pf_ret {
> RMP_PF_SPLIT = 0,
> RMP_PF_RETRY = 1,
>};
>and use those instead.
Ok.
>> +static int handle_user_rmp_page_fault(struct pt_regs *regs, unsigned long error_code,
>> + unsigned long address)
>> +{
>> + int rmp_level, level;
>> + pte_t *pte;
>> + u64 pfn;
>> +
>> + pte = lookup_address_in_mm(current->mm, address, &level);
>> +
>> + /*
>> + * It can happen if there was a race between an unmap event and
>> + * the RMP fault delivery.
>> + */
>You need to elaborate more here: a RMP fault can happen and then the
>page can get unmapped? What is the exact scenario here?
Yes, if the page gets unmapped while the RMP fault was being handled,
will add more explanation here.
>> + if (!pte || !pte_present(*pte))
>> + return 1;
>> +
>> + pfn = pte_pfn(*pte);
>> +
>> + /* If its large page then calculte the fault pfn */
>> + if (level > PG_LEVEL_4K) {
>> + unsigned long mask;
>> +
>> + mask = pages_per_hpage(level) - pages_per_hpage(level - 1);
>> + pfn |= (address >> PAGE_SHIFT) & mask;
>Oh boy, this is unnecessarily complicated. Isn't this
> pfn |= pud_index(address);
>or
> pfn |= pmd_index(address);
>depending on the level?
Actually, the above computes an index into the RMP table. It is basically an index into
the 4K page within the hugepage mapped in the RMP table or in other words an index
into the RMP table entry for 4K page(s) corresponding to a hugepage.
So, pud_index()/pmd_index() can't be used for the same.
>I think it is but it needs more explaining.
>In any case, those are two static masks exactly and they don't need to
>be computed for each #PF.
>> diff --git a/mm/memory.c b/mm/memory.c
>> index 7274f2b52bca..c2187ffcbb8e 100644
>> --- a/mm/memory.c
>> +++ b/mm/memory.c
>> @@ -4945,6 +4945,15 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf)
>> return 0;
>> }
>>
>>. +static int handle_split_page_fault(struct vm_fault *vmf)
>> +{
> >+ if (!IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT))
>> + return VM_FAULT_SIGBUS;
>Yah, this looks weird: generic code implies that page splitting after a
>#PF makes sense only when SEV is present and none otherwise.
It is mainly a wrapper around__split_huge_pmd() for SNP use case
where the host hugepage is split to be in sync with the RMP table.
Thanks,
Ashish
Powered by blists - more mailing lists