From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8054FC46499 for ; Fri, 5 Jul 2019 21:34:41 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F2927216E3 for ; Fri, 5 Jul 2019 21:34:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=fossix-org.20150623.gappssmtp.com header.i=@fossix-org.20150623.gappssmtp.com header.b="1muHSdZv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F2927216E3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=fossix.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 45gSmH1LS7zDqQ9 for ; Sat, 6 Jul 2019 07:34:39 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=fossix.org (client-ip=2607:f8b0:4864:20::443; helo=mail-pf1-x443.google.com; envelope-from=santosh@fossix.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=fossix.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=fossix-org.20150623.gappssmtp.com header.i=@fossix-org.20150623.gappssmtp.com header.b="1muHSdZv"; dkim-atps=neutral Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 45gSbX5y42zDqDD for ; Sat, 6 Jul 2019 07:27:04 +1000 (AEST) Received: by mail-pf1-x443.google.com with SMTP id p184so4788896pfp.7 for ; Fri, 05 Jul 2019 14:27:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fossix-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8FLyyUZijz/9yTl40JPivx76FPoflI2SBpNAwf5JCCQ=; b=1muHSdZvKofN4sVJKwvO5wlkz6uihjyfewo+FYSDw9wCHsTwpvwpG663oJgHIX5f5S p+9uF8NrxPZmYlW9vedszr5Qujrf72Tdm5jN7OxL6+Zmov1H1lDPg91JtFW2kC6DLxu8 To/i13Hn9ovWIDTOX/3nY/14kSDCFZmcGmCOxtuts2DyAW712fF8ds1TZrl+4RB9F1km R7R3WRhLjv6q5Qe7GsaTNLvHCfRLTtDzjGV2HC0uWliVOpaseMUDbX4yffT41kdO0IfI bJ2q0Uu8shCfBOQhUfOh67o2VaBzQnE/MO12WOZAoMS7mJvg/4fsgYpObjURwrOc/17/ WiLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8FLyyUZijz/9yTl40JPivx76FPoflI2SBpNAwf5JCCQ=; b=SBD5IDXIs8wqfLP2y7HrJknEK6TYetOWezsZVV16E+joZwxXX2MJic1+gJ4t4P4hCX Tr6hObhKFJPiGukR2qg8Ar9Kawgi23cFpOUT9hDh6laFfSB+JcSHUzWyfOFKE2Kb4g0e NgLhceNu5BU/bTh1haJuVvILS8m+LpkI7pDSsRVINjdDzxzcwTS+t8hUWOkh9rcqhii5 H/wCaUeex11Iarp6kC6AY9D5YVF3cLXiTqycgBQDpao/0SZgsyvclV7UsqNtTGrpYXHv u/5bwU3iGHbB7IyhscZw5vud+NKEgREW00eMUA9F2GBvKyTNKf1OJiXeRbZq0kImqhty N1hQ== X-Gm-Message-State: APjAAAWyApqGtI+22X8gGTILpX1xujhLslm8G7+DxT55pHNSRPtwTXn0 vEEb/bJceZ4quqnySPatnF32PrlDClFtNA== X-Google-Smtp-Source: APXvYqzlTs1/8u3ZzLhJcPPXlYEzJhKGzFusMDmdDLCnY3umjMbUAhzWmf597hezbp++Zt2yCe9MBQ== X-Received: by 2002:a17:90a:21cc:: with SMTP id q70mr8192721pjc.56.1562362022675; Fri, 05 Jul 2019 14:27:02 -0700 (PDT) Received: from santosiv.in.ibm.com ([49.205.217.222]) by smtp.gmail.com with ESMTPSA id o13sm9321389pje.28.2019.07.05.14.27.00 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 05 Jul 2019 14:27:02 -0700 (PDT) From: Santosh Sivaraj To: linuxppc-dev Subject: [v3 2/7] powerpc/mce: Bug fixes for MCE handling in kernel space Date: Sat, 6 Jul 2019 02:56:42 +0530 Message-Id: <20190705212647.21750-3-santosh@fossix.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190705212647.21750-1-santosh@fossix.org> References: <20190705212647.21750-1-santosh@fossix.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Aneesh Kumar K.V" , Mahesh Salgaonkar , Nicholas Piggin , Chandan Rajendra , Reza Arbab Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Balbir Singh The code currently assumes PAGE_SHIFT as the shift value of the pfn, this works correctly (mostly) for user space pages, but the correct thing to do is 1. Extract the shift value returned via the pte-walk API's 2. Use the shift value to access the instruction address. Note, the final physical address still use PAGE_SHIFT for computation. handle_ierror() is not modified and handle_derror() is modified just for extracting the correct instruction address. This is largely due to __find_linux_pte() returning pfn's shifted by pdshift. The code is much more generic and can handle shift values returned. Fixes: ba41e1e1ccb9 ("powerpc/mce: Hookup derror (load/store) UE errors") Signed-off-by: Balbir Singh [arbab@linux.ibm.com: Fixup pseries_do_memory_failure()] Signed-off-by: Reza Arbab Signed-off-by: Santosh Sivaraj --- arch/powerpc/include/asm/mce.h | 3 ++- arch/powerpc/kernel/mce_power.c | 26 ++++++++++++++++---------- arch/powerpc/platforms/pseries/ras.c | 6 ++++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/arch/powerpc/include/asm/mce.h b/arch/powerpc/include/asm/mce.h index a4c6a74ad2fb..94888a7025b3 100644 --- a/arch/powerpc/include/asm/mce.h +++ b/arch/powerpc/include/asm/mce.h @@ -209,7 +209,8 @@ 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_pfn(struct pt_regs *regs, unsigned long addr, + unsigned int *shift); #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 e39536aad30d..04666c0b40a8 100644 --- a/arch/powerpc/kernel/mce_power.c +++ b/arch/powerpc/kernel/mce_power.c @@ -23,7 +23,8 @@ * Convert an address related to an mm to a PFN. 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_pfn(struct pt_regs *regs, unsigned long addr, + unsigned int *shift) { pte_t *ptep; unsigned long flags; @@ -36,13 +37,15 @@ unsigned long addr_to_pfn(struct pt_regs *regs, unsigned long addr) local_irq_save(flags); if (mm == current->mm) - ptep = find_current_mm_pte(mm->pgd, addr, NULL, NULL); + ptep = find_current_mm_pte(mm->pgd, addr, NULL, shift); else - ptep = find_init_mm_pte(addr, NULL); + ptep = find_init_mm_pte(addr, shift); local_irq_restore(flags); if (!ptep || pte_special(*ptep)) return ULONG_MAX; - return pte_pfn(*ptep); + if (!*shift) + *shift = PAGE_SHIFT; + return (pte_val(*ptep) & PTE_RPN_MASK) >> *shift; } /* flush SLBs and reload */ @@ -358,15 +361,16 @@ static int mce_find_instr_ea_and_pfn(struct pt_regs *regs, uint64_t *addr, unsigned long pfn, instr_addr; struct instruction_op op; struct pt_regs tmp = *regs; + unsigned int shift; - pfn = addr_to_pfn(regs, regs->nip); + pfn = addr_to_pfn(regs, regs->nip, &shift); if (pfn != ULONG_MAX) { - instr_addr = (pfn << PAGE_SHIFT) + (regs->nip & ~PAGE_MASK); + instr_addr = (pfn << shift) + (regs->nip & ((1 << shift) - 1)); instr = *(unsigned int *)(instr_addr); if (!analyse_instr(&op, &tmp, instr)) { - pfn = addr_to_pfn(regs, op.ea); + pfn = addr_to_pfn(regs, op.ea, &shift); *addr = op.ea; - *phys_addr = (pfn << PAGE_SHIFT); + *phys_addr = (pfn << shift); return 0; } /* @@ -442,12 +446,14 @@ static int mce_handle_ierror(struct pt_regs *regs, if (mce_err->sync_error && table[i].error_type == MCE_ERROR_TYPE_UE) { unsigned long pfn; + unsigned int shift; if (get_paca()->in_mce < MAX_MCE_DEPTH) { - pfn = addr_to_pfn(regs, regs->nip); + pfn = addr_to_pfn(regs, regs->nip, + &shift); if (pfn != ULONG_MAX) { *phys_addr = - (pfn << PAGE_SHIFT); + (pfn << shift); } } } diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c index f16fdd0f71f7..5e43283d3300 100644 --- a/arch/powerpc/platforms/pseries/ras.c +++ b/arch/powerpc/platforms/pseries/ras.c @@ -740,12 +740,14 @@ static void pseries_do_memory_failure(struct pt_regs *regs, paddr = be64_to_cpu(mce_log->logical_address); } else if (mce_log->sub_err_type & UE_EFFECTIVE_ADDR_PROVIDED) { unsigned long pfn; + unsigned int shift; pfn = addr_to_pfn(regs, - be64_to_cpu(mce_log->effective_address)); + be64_to_cpu(mce_log->effective_address), + &shift); if (pfn == ULONG_MAX) return; - paddr = pfn << PAGE_SHIFT; + paddr = pfn << shift; } else { return; } -- 2.20.1