From: Nicholas Piggin <npiggin@gmail.com>
To: Linux Kernel <linux-kernel@vger.kernel.org>,
linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
Santosh Sivaraj <santosh@fossix.org>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>,
Reza Arbab <arbab@linux.ibm.com>,
Balbir Singh <bsingharora@gmail.com>,
Chandan Rajendra <chandan@linux.ibm.com>,
christophe leroy <christophe.leroy@c-s.fr>,
Mahesh Salgaonkar <mahesh@linux.ibm.com>,
Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
stable@vger.kernel.org
Subject: Re: [PATCH v10 2/7] powerpc/mce: Fix MCE handling for huge pages
Date: Tue, 20 Aug 2019 00:22:35 +1000 [thread overview]
Message-ID: <1566223931.kpuwkor3n7.astroid@bobo.none> (raw)
In-Reply-To: <20190815003941.18655-3-santosh@fossix.org>
Santosh Sivaraj's on August 15, 2019 10:39 am:
> From: Balbir Singh <bsingharora@gmail.com>
>
> The current code would fail on huge pages addresses, since the shift would
> be incorrect. Use the correct page shift value returned by
> __find_linux_pte() to get the correct physical address. The code is more
> generic and can handle both regular and compound pages.
>
> Fixes: ba41e1e1ccb9 ("powerpc/mce: Hookup derror (load/store) UE errors")
> Signed-off-by: Balbir Singh <bsingharora@gmail.com>
> [arbab@linux.ibm.com: Fixup pseries_do_memory_failure()]
> Signed-off-by: Reza Arbab <arbab@linux.ibm.com>
> Co-developed-by: Santosh Sivaraj <santosh@fossix.org>
> Signed-off-by: Santosh Sivaraj <santosh@fossix.org>
> Tested-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
> Cc: stable@vger.kernel.org # v4.15+
> ---
> arch/powerpc/include/asm/mce.h | 2 +-
> arch/powerpc/kernel/mce_power.c | 55 ++++++++++++++--------------
> arch/powerpc/platforms/pseries/ras.c | 9 ++---
> 3 files changed, 32 insertions(+), 34 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/mce.h b/arch/powerpc/include/asm/mce.h
> index a4c6a74ad2fb..f3a6036b6bc0 100644
> --- a/arch/powerpc/include/asm/mce.h
> +++ b/arch/powerpc/include/asm/mce.h
> @@ -209,7 +209,7 @@ extern void release_mce_event(void);
> extern void machine_check_queue_event(void);
> extern void machine_check_print_event_info(struct machine_check_event *evt,
> bool user_mode, bool in_guest);
> -unsigned long addr_to_pfn(struct pt_regs *regs, unsigned long addr);
> +unsigned long addr_to_phys(struct pt_regs *regs, unsigned long addr);
> #ifdef CONFIG_PPC_BOOK3S_64
> void flush_and_reload_slb(void);
> #endif /* CONFIG_PPC_BOOK3S_64 */
> diff --git a/arch/powerpc/kernel/mce_power.c b/arch/powerpc/kernel/mce_power.c
> index a814d2dfb5b0..e74816f045f8 100644
> --- a/arch/powerpc/kernel/mce_power.c
> +++ b/arch/powerpc/kernel/mce_power.c
> @@ -20,13 +20,14 @@
> #include <asm/exception-64s.h>
>
> /*
> - * Convert an address related to an mm to a PFN. NOTE: we are in real
> - * mode, we could potentially race with page table updates.
> + * Convert an address related to an mm to a physical address.
> + * NOTE: we are in real mode, we could potentially race with page table updates.
> */
> -unsigned long addr_to_pfn(struct pt_regs *regs, unsigned long addr)
> +unsigned long addr_to_phys(struct pt_regs *regs, unsigned long addr)
> {
> - pte_t *ptep;
> - unsigned long flags;
> + pte_t *ptep, pte;
> + unsigned int shift;
> + unsigned long flags, phys_addr;
> struct mm_struct *mm;
>
> if (user_mode(regs))
> @@ -35,14 +36,21 @@ unsigned long addr_to_pfn(struct pt_regs *regs, unsigned long addr)
> mm = &init_mm;
>
> local_irq_save(flags);
> - if (mm == current->mm)
> - ptep = find_current_mm_pte(mm->pgd, addr, NULL, NULL);
> - else
> - ptep = find_init_mm_pte(addr, NULL);
> + ptep = __find_linux_pte(mm->pgd, addr, NULL, &shift);
> local_irq_restore(flags);
> +
> if (!ptep || pte_special(*ptep))
> return ULONG_MAX;
> - return pte_pfn(*ptep);
> +
> + pte = *ptep;
> + if (shift > PAGE_SHIFT) {
> + unsigned long rpnmask = (1ul << shift) - PAGE_SIZE;
> +
> + pte = __pte(pte_val(pte) | (addr & rpnmask));
> + }
> + phys_addr = pte_pfn(pte) << PAGE_SHIFT;
> +
> + return phys_addr;
> }
This should remain addr_to_pfn I think. None of the callers care what
size page the EA was mapped with. 'pfn' is referring to the Linux pfn,
which is the small page number.
if (shift > PAGE_SHIFT)
return (pte_pfn(*ptep) | ((addr & ((1UL << shift) - 1)) >> PAGE_SHIFT);
else
return pte_pfn(*ptep);
Something roughly like that, then you don't have to change any callers
or am I missing something?
Thanks,
Nick
next prev parent reply other threads:[~2019-08-19 14:22 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-15 0:39 [PATCH v10 0/7] powerpc: implement machine check safe memcpy Santosh Sivaraj
2019-08-15 0:39 ` [PATCH v10 1/7] powerpc/mce: Schedule work from irq_work Santosh Sivaraj
2019-08-19 14:08 ` Nicholas Piggin
2019-08-15 0:39 ` [PATCH v10 2/7] powerpc/mce: Fix MCE handling for huge pages Santosh Sivaraj
2019-08-19 14:22 ` Nicholas Piggin [this message]
2019-08-20 1:47 ` Santosh Sivaraj
2019-08-20 3:04 ` Nicholas Piggin
2019-08-15 0:39 ` [PATCH v10 3/7] powerpc/mce: Make machine_check_ue_event() static Santosh Sivaraj
2019-08-15 0:39 ` [PATCH v10 4/7] extable: Add function to search only kernel exception table Santosh Sivaraj
2019-08-15 0:39 ` [PATCH v10 5/7] powerpc/memcpy: Add memcpy_mcsafe for pmem Santosh Sivaraj
2019-08-15 0:39 ` [PATCH v10 6/7] powerpc/mce: Handle UE event for memcpy_mcsafe Santosh Sivaraj
2019-08-19 14:28 ` Nicholas Piggin
2019-08-15 0:39 ` [PATCH v10 7/7] powerpc: add machine check safe copy_to_user Santosh Sivaraj
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=1566223931.kpuwkor3n7.astroid@bobo.none \
--to=npiggin@gmail.com \
--cc=aneesh.kumar@linux.ibm.com \
--cc=arbab@linux.ibm.com \
--cc=bsingharora@gmail.com \
--cc=chandan@linux.ibm.com \
--cc=christophe.leroy@c-s.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mahesh@linux.ibm.com \
--cc=mahesh@linux.vnet.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=santosh@fossix.org \
--cc=stable@vger.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®