Message ID | 20230220183847.59159-20-michael.roth@amd.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add AMD Secure Nested Paging (SEV-SNP) Hypervisor Support | expand |
On Mon, 20 Feb 2023 12:38:10 -0600 Michael Roth <michael.roth@amd.com> wrote: > From: Ashish Kalra <ashish.kalra@amd.com> > > Return pfn from dump_pagetable() to do SEV-specific > fault handling. Used for handling SNP RMP page fault. > It would be better to merge this patch with PATCH 13. > Signed-off-by: Ashish Kalra <ashish.kalra@amd.com> > Signed-off-by: Michael Roth <michael.roth@amd.com> > --- > arch/x86/mm/fault.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c > index afd4cde17001..f2b16dcfbd9a 100644 > --- a/arch/x86/mm/fault.c > +++ b/arch/x86/mm/fault.c > @@ -311,7 +311,7 @@ static bool low_pfn(unsigned long pfn) > return pfn < max_low_pfn; > } > > -static void dump_pagetable(unsigned long address) > +static unsigned long dump_pagetable(unsigned long address) > { > pgd_t *base = __va(read_cr3_pa()); > pgd_t *pgd = &base[pgd_index(address)]; > @@ -345,8 +345,10 @@ static void dump_pagetable(unsigned long address) > > pte = pte_offset_kernel(pmd, address); > pr_cont("*pte = %0*Lx ", sizeof(*pte) * 2, (u64)pte_val(*pte)); > + return 0; > out: > pr_cont("\n"); > + return 0; > } > > #else /* CONFIG_X86_64: */ > @@ -367,10 +369,11 @@ static int bad_address(void *p) > return get_kernel_nofault(dummy, (unsigned long *)p); > } > > -static void dump_pagetable(unsigned long address) > +static unsigned long dump_pagetable(unsigned long address) > { > pgd_t *base = __va(read_cr3_pa()); > pgd_t *pgd = base + pgd_index(address); > + unsigned long pfn; > p4d_t *p4d; > pud_t *pud; > pmd_t *pmd; > @@ -388,6 +391,7 @@ static void dump_pagetable(unsigned long address) > if (bad_address(p4d)) > goto bad; > > + pfn = p4d_pfn(*p4d); > pr_cont("P4D %lx ", p4d_val(*p4d)); > if (!p4d_present(*p4d) || p4d_large(*p4d)) > goto out; > @@ -396,6 +400,7 @@ static void dump_pagetable(unsigned long address) > if (bad_address(pud)) > goto bad; > > + pfn = pud_pfn(*pud); > pr_cont("PUD %lx ", pud_val(*pud)); > if (!pud_present(*pud) || pud_large(*pud)) > goto out; > @@ -404,6 +409,7 @@ static void dump_pagetable(unsigned long address) > if (bad_address(pmd)) > goto bad; > > + pfn = pmd_pfn(*pmd); > pr_cont("PMD %lx ", pmd_val(*pmd)); > if (!pmd_present(*pmd) || pmd_large(*pmd)) > goto out; > @@ -412,13 +418,14 @@ static void dump_pagetable(unsigned long address) > if (bad_address(pte)) > goto bad; > > + pfn = pte_pfn(*pte); > pr_cont("PTE %lx", pte_val(*pte)); > out: > pr_cont("\n"); > - > - return; > + return pfn; > bad: > pr_info("BAD\n"); > + return -1; > } > > #endif /* CONFIG_X86_64 */
On Mon, Feb 20, 2023 at 12:38:10PM -0600, Michael Roth wrote: > From: Ashish Kalra <ashish.kalra@amd.com> > > Return pfn from dump_pagetable() to do SEV-specific > fault handling. Used for handling SNP RMP page fault. > > Signed-off-by: Ashish Kalra <ashish.kalra@amd.com> > Signed-off-by: Michael Roth <michael.roth@amd.com> > --- > arch/x86/mm/fault.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c > index afd4cde17001..f2b16dcfbd9a 100644 > --- a/arch/x86/mm/fault.c > +++ b/arch/x86/mm/fault.c > @@ -311,7 +311,7 @@ static bool low_pfn(unsigned long pfn) > return pfn < max_low_pfn; > } > > -static void dump_pagetable(unsigned long address) > +static unsigned long dump_pagetable(unsigned long address) > { > pgd_t *base = __va(read_cr3_pa()); > pgd_t *pgd = &base[pgd_index(address)]; > @@ -345,8 +345,10 @@ static void dump_pagetable(unsigned long address) > > pte = pte_offset_kernel(pmd, address); > pr_cont("*pte = %0*Lx ", sizeof(*pte) * 2, (u64)pte_val(*pte)); > + return 0; > out: > pr_cont("\n"); > + return 0; > } > > #else /* CONFIG_X86_64: */ > @@ -367,10 +369,11 @@ static int bad_address(void *p) > return get_kernel_nofault(dummy, (unsigned long *)p); > } > > -static void dump_pagetable(unsigned long address) > +static unsigned long dump_pagetable(unsigned long address) > { > pgd_t *base = __va(read_cr3_pa()); > pgd_t *pgd = base + pgd_index(address); > + unsigned long pfn; pfn should be initialized otherwise this function may return an uninitialized value. > p4d_t *p4d; > pud_t *pud; > pmd_t *pmd; > @@ -388,6 +391,7 @@ static void dump_pagetable(unsigned long address) > if (bad_address(p4d)) > goto bad; > > + pfn = p4d_pfn(*p4d); > pr_cont("P4D %lx ", p4d_val(*p4d)); > if (!p4d_present(*p4d) || p4d_large(*p4d)) > goto out; > @@ -396,6 +400,7 @@ static void dump_pagetable(unsigned long address) > if (bad_address(pud)) > goto bad; > > + pfn = pud_pfn(*pud); > pr_cont("PUD %lx ", pud_val(*pud)); > if (!pud_present(*pud) || pud_large(*pud)) > goto out; > @@ -404,6 +409,7 @@ static void dump_pagetable(unsigned long address) > if (bad_address(pmd)) > goto bad; > > + pfn = pmd_pfn(*pmd); > pr_cont("PMD %lx ", pmd_val(*pmd)); > if (!pmd_present(*pmd) || pmd_large(*pmd)) > goto out; > @@ -412,13 +418,14 @@ static void dump_pagetable(unsigned long address) > if (bad_address(pte)) > goto bad; > > + pfn = pte_pfn(*pte); > pr_cont("PTE %lx", pte_val(*pte)); > out: > pr_cont("\n"); > - > - return; > + return pfn; > bad: > pr_info("BAD\n"); > + return -1; > } > > #endif /* CONFIG_X86_64 */ > -- > 2.25.1 > > > >
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index afd4cde17001..f2b16dcfbd9a 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -311,7 +311,7 @@ static bool low_pfn(unsigned long pfn) return pfn < max_low_pfn; } -static void dump_pagetable(unsigned long address) +static unsigned long dump_pagetable(unsigned long address) { pgd_t *base = __va(read_cr3_pa()); pgd_t *pgd = &base[pgd_index(address)]; @@ -345,8 +345,10 @@ static void dump_pagetable(unsigned long address) pte = pte_offset_kernel(pmd, address); pr_cont("*pte = %0*Lx ", sizeof(*pte) * 2, (u64)pte_val(*pte)); + return 0; out: pr_cont("\n"); + return 0; } #else /* CONFIG_X86_64: */ @@ -367,10 +369,11 @@ static int bad_address(void *p) return get_kernel_nofault(dummy, (unsigned long *)p); } -static void dump_pagetable(unsigned long address) +static unsigned long dump_pagetable(unsigned long address) { pgd_t *base = __va(read_cr3_pa()); pgd_t *pgd = base + pgd_index(address); + unsigned long pfn; p4d_t *p4d; pud_t *pud; pmd_t *pmd; @@ -388,6 +391,7 @@ static void dump_pagetable(unsigned long address) if (bad_address(p4d)) goto bad; + pfn = p4d_pfn(*p4d); pr_cont("P4D %lx ", p4d_val(*p4d)); if (!p4d_present(*p4d) || p4d_large(*p4d)) goto out; @@ -396,6 +400,7 @@ static void dump_pagetable(unsigned long address) if (bad_address(pud)) goto bad; + pfn = pud_pfn(*pud); pr_cont("PUD %lx ", pud_val(*pud)); if (!pud_present(*pud) || pud_large(*pud)) goto out; @@ -404,6 +409,7 @@ static void dump_pagetable(unsigned long address) if (bad_address(pmd)) goto bad; + pfn = pmd_pfn(*pmd); pr_cont("PMD %lx ", pmd_val(*pmd)); if (!pmd_present(*pmd) || pmd_large(*pmd)) goto out; @@ -412,13 +418,14 @@ static void dump_pagetable(unsigned long address) if (bad_address(pte)) goto bad; + pfn = pte_pfn(*pte); pr_cont("PTE %lx", pte_val(*pte)); out: pr_cont("\n"); - - return; + return pfn; bad: pr_info("BAD\n"); + return -1; } #endif /* CONFIG_X86_64 */