Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1457973ybl; Wed, 14 Aug 2019 17:45:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+Z9+665u/nLdzRl+ZL/uW9OWJkffsaPPrNO1mTtFrd/cv2wSNkM2ucdTUi8I6GWKHmtE7 X-Received: by 2002:a65:420c:: with SMTP id c12mr1582141pgq.442.1565829949099; Wed, 14 Aug 2019 17:45:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565829949; cv=none; d=google.com; s=arc-20160816; b=szbyOe+Jp9uQjlz0F0wWyMNo51OJrsJ5HhgBmeKiTk+m0TkWljpEqJts7eiCMQv4HC QE13MMJDlObLWZw80fnppZp13TCzKxiIIFN8HfSEF72Bfshclvn9AZd8R9TkrNGQbru4 AWJqW72jlH1vQjpx7CkMnlHktgT9hPNOAGYZ7WdE5wLABTG6GQZURZpST/cNZXaZvkrx ybdTaWepRLNikZs6s5ETYh0qynlFIs1CNpv3y11jGeyZYxW4DIRQWlNDHRM8xdPwRtxC mLxIj1OJ/EYFTUtRANfhyXExnL9zzj9YPX8vQ6YvHpttB7SnRaf2V6BE3/4yFqTyvH/w gtLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=D2tlN+71g8bWt9oQlVT6rxO2X/4rsSsVdmtXxR74abA=; b=M1po0dCsf6EwkGuCr2bIaya/dHoiUWHogOoMqw+cxmD2BYcM3BEHpC/SND6lNc//D2 yfkudM/FVwR9GSm1q4BmDSRQn1e1oq+6AUe2+mkQk55vhQE5kgCSQGiTABG/mWS8T5HH hJ5jcQ+pqRfAxX+1Pbk6zhrWW/g3XLCJwiCrDKR7vF+nCuSLwIzsXL7Ww9PZArdYZ6Le huOr8WlU9fdBb5mhxuVDAjpR8nJElvV9eep7w2e8NSG+FGOs1/fe2+OMNFmRI0lKgiLq G+Tq88UWfcHEiCrj5rzYVtB0mZ1f/S8S36vr9a16uQd/BDv0ZNZFCZnQbPHUyW7+KtOI IiYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fossix-org.20150623.gappssmtp.com header.s=20150623 header.b=kdCxrQJC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h16si883157plr.94.2019.08.14.17.45.32; Wed, 14 Aug 2019 17:45:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fossix-org.20150623.gappssmtp.com header.s=20150623 header.b=kdCxrQJC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729434AbfHOAkF (ORCPT + 99 others); Wed, 14 Aug 2019 20:40:05 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:41226 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726490AbfHOAkE (ORCPT ); Wed, 14 Aug 2019 20:40:04 -0400 Received: by mail-pf1-f193.google.com with SMTP id 196so390269pfz.8 for ; Wed, 14 Aug 2019 17:40: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=D2tlN+71g8bWt9oQlVT6rxO2X/4rsSsVdmtXxR74abA=; b=kdCxrQJCWt07ionWVmtYa9pkcvVdj6ejpK9Z/fzG1CU/wmax9uUyylyLS4k6l1zcxi QgWUUCA8BuF0rYGj8gE0NOZG7zmBkMtjJtOWifH157TJavy6ZGMLJpK3PdAKW3wzKPHn Z2Q8LYFUSrlQM1SVeg1j8ms2BzQI+yxK8jeH0NqDUiM7nirgUIoqpn83PPVs+KkGNKz4 eAwZAoMlt6R+OR276CGGB8RQ+nTrrhqq8pNlypPCuqOPdO7mR1JXwFp3cPWmQjztUr9o f5NwTS/flLhKTEbRdbwgg/tpTWQkX6l8f+Gf9i+6sMvZIFixeQyB/SaAb5mGF1aVB8az NMcA== 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=D2tlN+71g8bWt9oQlVT6rxO2X/4rsSsVdmtXxR74abA=; b=lYnZnmq2d5rHtIl45UtTdigSNNwLJM8dhRWvOkdKXgSUoakE6jC/kW4OT+hVbOKHYk R3rUuDdi2HX/ixlu99HqJ7OeI0zVoCdKEOUkhKvdpvpnx/hn4eyrnVdTkh8Ur3xEQDCy xK1RdwqvbcHf7IrOnzhqdpSb7IUZ1ACCT2I9yF66K9Jhy1C1HdXT4K+VtijQLNR5heFI ka3AvOQbd/oZGfIIYeVFoHPugyNj4C1V1KVprRbsvmLObuIUAxPdv5c9ixRPYZwbG6Vz 7wX+g6D1hCU3yHBjCWh1uYeF6RHlslSRd2Aqbobs1cKCVsCUEOPUKJ77Calb03Tc+FoY kfSg== X-Gm-Message-State: APjAAAUiMLVCkZNUAgERVbEQ/BldiKUl5H5ygbdacYVSsOoFowXjc6tL n26eK73OQT+dUDvPz9Dk+nnBWw== X-Received: by 2002:a17:90a:1110:: with SMTP id d16mr580444pja.29.1565829604197; Wed, 14 Aug 2019 17:40:04 -0700 (PDT) Received: from santosiv.in.ibm.com ([49.205.218.176]) by smtp.gmail.com with ESMTPSA id g8sm815917pgk.1.2019.08.14.17.40.00 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 14 Aug 2019 17:40:03 -0700 (PDT) From: Santosh Sivaraj To: linuxppc-dev , Linux Kernel Cc: "Aneesh Kumar K.V" , Mahesh Salgaonkar , Reza Arbab , Balbir Singh , Chandan Rajendra , Michael Ellerman , Nicholas Piggin , christophe leroy , Mahesh Salgaonkar , stable@vger.kernel.org Subject: [PATCH v10 2/7] powerpc/mce: Fix MCE handling for huge pages Date: Thu, 15 Aug 2019 06:09:36 +0530 Message-Id: <20190815003941.18655-3-santosh@fossix.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190815003941.18655-1-santosh@fossix.org> References: <20190815003941.18655-1-santosh@fossix.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Balbir Singh 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 [arbab@linux.ibm.com: Fixup pseries_do_memory_failure()] Signed-off-by: Reza Arbab Co-developed-by: Santosh Sivaraj Signed-off-by: Santosh Sivaraj Tested-by: Mahesh Salgaonkar 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 /* - * 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; } /* flush SLBs and reload */ @@ -344,7 +352,7 @@ static const struct mce_derror_table mce_p9_derror_table[] = { MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true }, { 0, false, 0, 0, 0, 0, 0 } }; -static int mce_find_instr_ea_and_pfn(struct pt_regs *regs, uint64_t *addr, +static int mce_find_instr_ea_and_phys(struct pt_regs *regs, uint64_t *addr, uint64_t *phys_addr) { /* @@ -354,18 +362,16 @@ static int mce_find_instr_ea_and_pfn(struct pt_regs *regs, uint64_t *addr, * faults */ int instr; - unsigned long pfn, instr_addr; + unsigned long instr_addr; struct instruction_op op; struct pt_regs tmp = *regs; - pfn = addr_to_pfn(regs, regs->nip); - if (pfn != ULONG_MAX) { - instr_addr = (pfn << PAGE_SHIFT) + (regs->nip & ~PAGE_MASK); + instr_addr = addr_to_phys(regs, regs->nip) + (regs->nip & ~PAGE_MASK); + if (instr_addr != ULONG_MAX) { instr = *(unsigned int *)(instr_addr); if (!analyse_instr(&op, &tmp, instr)) { - pfn = addr_to_pfn(regs, op.ea); *addr = op.ea; - *phys_addr = (pfn << PAGE_SHIFT); + *phys_addr = addr_to_phys(regs, op.ea); return 0; } /* @@ -440,15 +446,9 @@ static int mce_handle_ierror(struct pt_regs *regs, *addr = regs->nip; if (mce_err->sync_error && table[i].error_type == MCE_ERROR_TYPE_UE) { - unsigned long pfn; - - if (get_paca()->in_mce < MAX_MCE_DEPTH) { - pfn = addr_to_pfn(regs, regs->nip); - if (pfn != ULONG_MAX) { - *phys_addr = - (pfn << PAGE_SHIFT); - } - } + if (get_paca()->in_mce < MAX_MCE_DEPTH) + *phys_addr = addr_to_phys(regs, + regs->nip); } } return handled; @@ -541,7 +541,8 @@ static int mce_handle_derror(struct pt_regs *regs, * kernel/exception-64s.h */ if (get_paca()->in_mce < MAX_MCE_DEPTH) - mce_find_instr_ea_and_pfn(regs, addr, phys_addr); + mce_find_instr_ea_and_phys(regs, addr, + phys_addr); } found = 1; } diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c index f16fdd0f71f7..5743f6353638 100644 --- a/arch/powerpc/platforms/pseries/ras.c +++ b/arch/powerpc/platforms/pseries/ras.c @@ -739,13 +739,10 @@ static void pseries_do_memory_failure(struct pt_regs *regs, if (mce_log->sub_err_type & UE_LOGICAL_ADDR_PROVIDED) { paddr = be64_to_cpu(mce_log->logical_address); } else if (mce_log->sub_err_type & UE_EFFECTIVE_ADDR_PROVIDED) { - unsigned long pfn; - - pfn = addr_to_pfn(regs, - be64_to_cpu(mce_log->effective_address)); - if (pfn == ULONG_MAX) + paddr = addr_to_phys(regs, + be64_to_cpu(mce_log->effective_address)); + if (paddr == ULONG_MAX) return; - paddr = pfn << PAGE_SHIFT; } else { return; } -- 2.21.0