Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp264824pxf; Thu, 11 Mar 2021 03:25:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzaOTnBqYgtT4nq+b3lpLOh9AeBrynv3rNoS5I/JS7c8JVTPotHy17m1ov8E/GgPHGh0vU1 X-Received: by 2002:a17:907:94cc:: with SMTP id dn12mr2574521ejc.177.1615461957417; Thu, 11 Mar 2021 03:25:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615461957; cv=none; d=google.com; s=arc-20160816; b=Z26nS3Px4g1JAT0TZoMhGR27deSX6tsc0AGnG3sOEEO7gJtsLYqAHysOb2w157QBAS cZBfK77yKpzx5cB6/fEYHtEcRXDdZhHQWkqIQHNe8ISNt/SEeohUw/KIQlKhlcltfFmK WOaoBCZe/TEi8ptSF/Yc6xum5h73TxsGCAzHegrjHlD/Hhv3pOGgXScVxl0Bc1Bjo5sw UrNoNW3WY63K3qNHc1esyVlNH2QrsUFGfO1xwmQr89snQPFfDhlIw/HUAFuUOZrSFa74 2sS78cA2pbFC+U4eutmg9yTqhHEhofwXhKvP3gzB21gSXCO17MvxfiQIRBuwTTJlmmGt nsHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=tiajUIE6K1R+lwMsLQ1UqBsqgKA7WM6eL6BaEd0od9c=; b=Qycp7ekuChgxQH9lQrPBQGkS+BE+HICj43Svxd9XjoVunXXvFbQKQYo1GLv5q060Jj GKoX2nbk88rBoawAFOCs5cKoHLSSQqB77jOvD1xa9JGr0fDGw4tPkiG1031KAn8ZDT+5 OnfJO3D68TFWOpzWBw3nyDvdXOk0OabfTIyVwultXCtvPUoyLNQElRwfWn1PINUNtBQ5 ma6mXY5YBIdmPCMIN55y3WeS+4dsxMt9abHAEfwVb27i7Hl6k47RFMv34NT88E3P0687 Jl/cHlLBL6UrpWJhexTYOnwxotCCvuBjWZKvz/i83B5zVqmVenibyIrgrAKgVB0A+Qev WWvg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r27si1489310edw.299.2021.03.11.03.25.34; Thu, 11 Mar 2021 03:25:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232532AbhCKLYT convert rfc822-to-8bit (ORCPT + 99 others); Thu, 11 Mar 2021 06:24:19 -0500 Received: from mail.kingsoft.com ([114.255.44.145]:14549 "EHLO mail.kingsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232433AbhCKLYD (ORCPT ); Thu, 11 Mar 2021 06:24:03 -0500 X-AuditID: 0a580157-47bff70000021a79-b6-6049f721b84a Received: from mail.kingsoft.com (localhost [10.88.1.32]) (using TLS with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.kingsoft.com (SMG-1-NODE-87) with SMTP id E4.5D.06777.127F9406; Thu, 11 Mar 2021 18:55:29 +0800 (HKT) Received: from alex-virtual-machine (172.16.253.254) by KSBJMAIL2.kingsoft.cn (10.88.1.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 11 Mar 2021 19:23:58 +0800 Date: Thu, 11 Mar 2021 19:23:58 +0800 From: Aili Yao To: "HORIGUCHI =?UTF-8?B?TkFPWUE=?=(=?UTF-8?B?5aCA5Y+j44CA55u05Lmf?=)" CC: "Luck, Tony" , Oscar Salvador , "david@redhat.com" , "akpm@linux-foundation.org" , "bp@alien8.de" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "x86@kernel.org" , "linux-edac@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "yangfeng1@kingsoft.com" , , Subject: Re: [PATCH] mm,hwpoison: return -EBUSY when page already poisoned Message-ID: <20210311192358.62915aa7@alex-virtual-machine> In-Reply-To: <20210311085529.GA22268@hori.linux.bs1.fc.nec.co.jp> References: <20210303115710.2e9f8e23@alex-virtual-machine> <20210303163912.3d508e0f@alex-virtual-machine> <1a78e9abdc134e35a5efcbf6b2fd2263@intel.com> <20210304101653.546a9da1@alex-virtual-machine> <20210304121941.667047c3@alex-virtual-machine> <20210304144524.795872d7@alex-virtual-machine> <20210304235720.GA215567@agluck-desk2.amr.corp.intel.com> <20210305093016.40c87375@alex-virtual-machine> <20210310141042.4db9ea29@alex-virtual-machine> <20210311085529.GA22268@hori.linux.bs1.fc.nec.co.jp> Organization: kingsoft X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Originating-IP: [172.16.253.254] X-ClientProxiedBy: KSBJMAIL1.kingsoft.cn (10.88.1.31) To KSBJMAIL2.kingsoft.cn (10.88.1.32) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprFIsWRmVeSWpSXmKPExsXCFcGooKv43TPBYNcNQ4s569ewWXze8I/N 4uv6X8wW0zaKW1w41cBkcXnXHDaLe2v+s1pcOrCAyeJi4wFGizPTiiw2b5rKbPHmwj0Wix8b HrM68Hp8b+1j8Vi85yWTx6ZVnWwemz5NYvd4d+4cu8eJGb9ZPF5c3cji8X7fVTaPzaerPT5v kvM40fKFNYA7issmJTUnsyy1SN8ugStj78lvLAXbzCueHV3O1MDYpdXFyMkhIWAisfjWYuYu Ri4OIYHpTBKnHpxigXBeMUq07t/G1MXIwcEioCpxqU0SpIENyNx1bxYriC0ikCSxePZXJpB6 ZoHvLBKtx2+xgSSEBbwkvtxfywjSyytgJXF+RRSIySngKLFnvgbE+I0sEifunAGbwy8gJtF7 5T8TxEH2Em1bFjGC2LwCghInZz5hAbGZBTQlWrf/ZoewtSWWLXzNDGILCShKHF7yix2iV0ni SPcMNgg7VmLZvFesExiFZyEZNQvJqFlIRi1gZF7FyFKcm264iRESfeE7GOc1fdQ7xMjEwXiI UYKDWUmE1++4W4IQb0piZVVqUX58UWlOavEhRmkOFiVx3ssVnglCAumJJanZqakFqUUwWSYO TqkGpqTt89Jajz37vFJ3T9+7m6JVchxX3s5PvN2wiL/5fvWlX7d7LbkCTtS1OG/mypRc9PD8 Ast9WxTXyt5d97fLQm2rh80W54kFbFu4EvKup9Y8lTyV/fJB4LUwE1UVoT0XyiK8q7cHX+i5 d/nrz3N/2p7fXyKz9ZAKX6ikt3CT/V3rV8b7fvDu337CfUaeSW7s27ksTg737L+JvAvcaG01 Vf1M6av9Mg11Em5dc7TbtzDPnur/zM3h2+LmnhuZbOl6DcwPF/w/EVqxN+z+KfUdH/huVcmZ /1y+82dI1nHm96ahjtOfnWlhiP6z4dIEffPtSdGr1G3nlc/Qvam8yfwk2/8F8+YZeb57Y916 Z9eW+FQlluKMREMt5qLiRAAhjk/mLQMAAA== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 11 Mar 2021 08:55:30 +0000 HORIGUCHI NAOYA(堀口 直也) wrote: > On Wed, Mar 10, 2021 at 02:10:42PM +0800, Aili Yao wrote: > > On Fri, 5 Mar 2021 15:55:25 +0000 > > "Luck, Tony" wrote: > > > > > > From the walk, it seems we have got the virtual address, can we just send a SIGBUS with it? > > > > > > If the walk wins the race and the pte for the poisoned page is still valid, then yes. > > > > > > But we could have: > > > > > > CPU1 CPU2 > > > memory_failure sets poison > > > bit for struct page > > > > > > > > > rmap finds page in task > > > on CPU2 and sets PTE > > > to not-valid-poison > > > > > > memory_failure returns > > > early because struct page > > > already marked as poison > > > > > > walk page tables looking > > > for mapping - don't find it > > > > > > -Tony > > > > While I don't think there is a race condition, and if you really think the pfn with SIGBUS is not > > proper, I think following patch maybe one way. > > I copy your abandon code, and make a little modification, and just now it pass > > my simple test. > > > > And also this is a RFC version, only valid if you think the pfn with SIGBUS is not right. > > > > Thanks! > > > > From a522ab8856e3a332a2318d57bb19f3c59594d462 Mon Sep 17 00:00:00 2001 > > From: Aili Yao > > Date: Wed, 10 Mar 2021 13:59:18 +0800 > > Subject: [PATCH] x86/mce: fix invalid SIGBUS address > > > > walk the current process pte and compare with the pfn; > > 1. only test for normal page and 2M hugetlb page; > > 2. 1G hugetlb and transparentHuge is not support currently; > > 3. May other fails is not recognized, This is a RFC version. > > > > --- > > arch/x86/kernel/cpu/mce/core.c | 83 ++++++++++++++++++++++++++++++++++++++++-- > > 1 file changed, 80 insertions(+), 3 deletions(-) > > > > diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c > > index db4afc5..65d7ef7 100644 > > --- a/arch/x86/kernel/cpu/mce/core.c > > +++ b/arch/x86/kernel/cpu/mce/core.c > > @@ -28,8 +28,12 @@ > > #include > > #include > > #include > > +#include > > +#include > > +#include > > #include > > #include > > +#include > > #include > > #include > > #include > > Maybe requiring many dependencies like this implies that you might be better > to do below in mm/memory-failure.c instead of in this file. Yes, agree, I will change this, Thanks! > > @@ -1235,6 +1239,81 @@ static void __mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *fin > > /* mce_clear_state will clear *final, save locally for use later */ > > *m = *final; > > } > > +static int mc_pte_entry(pte_t *pte, unsigned long addr, unsigned long next, struct mm_walk *walk) > > +{ > > + u64 *buff = (u64 *)walk->private; > > + u64 pfn = buff[0]; > > + > > + if (!pte_present(*pte) && is_hwpoison_entry(pte_to_swp_entry(*pte))) > > + goto find; > > + else if (pte_pfn(*pte) == pfn) > > + goto find; > > + > > + return 0; > > +find: > > + buff[0] = addr; > > + buff[1] = PAGE_SHIFT; > > + return true; > > Returning true means you stop walking when you find the first entry pointing > to a given pfn. But there could be multiple such entries, so if MCE SRAR is > triggered by memory access to the larger address in hwpoisoned entries, the > returned virtual address might be wrong. Yes, We need to consider multiple posion page entries, I will fix this. Thanks for you sugguestion! > > +} > > + > > +extern bool is_hugetlb_entry_hwpoisoned(pte_t pte); > > + > > +static int mc_hugetlb_range(pte_t *ptep, unsigned long hmask, > > + unsigned long addr, unsigned long end, > > + struct mm_walk *walk) > > +{ > > + u64 *buff = (u64 *)walk->private; > > + u64 pfn = buff[0]; > > + int shift = PMD_SHIFT; > > + pte_t pte = huge_ptep_get(ptep); > > + > > + if (unlikely(is_hugetlb_entry_hwpoisoned(pte))) > > + goto find; > > + > > + if (pte_pfn(*ptep) == pfn) > > + goto find; > > + > > + return 0; > > +find: > > + buff[0] = addr; > > + buff[1] = shift; > > + return true; > > +} > > + > > +static struct mm_walk_ops walk = { > > + .pte_entry = mc_pte_entry, > > + .hugetlb_entry = mc_hugetlb_range > > +}; > > + > > +void mc_memory_failure_error(struct task_struct *p, unsigned long pfn) > > +{ > > + u64 buff[2] = {pfn, 0}; > > + struct page *page; > > + int ret = -1; > > + > > + page = pfn_to_page(pfn); > > + if (!page) > > + goto force_sigbus; > > + > > + if (is_zone_device_page(page)) > > + goto force_sigbus; > > + > > + mmap_read_lock(p->mm); > > + ret = walk_page_range(p->mm, 0, TASK_SIZE_MAX, &walk, (void *)buff); > > + mmap_read_unlock(p->mm); > > + > > + if (ret && buff[0]) { > > + pr_err("Memory error may not recovered: %#llx: Sending SIGBUS to %s:%d due to hardware memory corruption\n", > > + buff[0], p->comm, p->pid); > > + force_sig_mceerr(BUS_MCEERR_AR, (void __user *)buff[0], buff[1]); > > + } else { > > +force_sigbus: > > + pr_err("Memory error may not recovered, pfn: %#lx: Sending SIGBUS to %s:%d due to hardware memory corruption\n", > > + pfn, p->comm, p->pid); > > + force_sig_mceerr(BUS_MCEERR_AR, (void __user *)pfn, PAGE_SHIFT); > > + } > > + > > +} > > > > static void kill_me_now(struct callback_head *ch) > > { > > @@ -1259,9 +1338,7 @@ static void kill_me_maybe(struct callback_head *cb) > > } > > > > if (p->mce_vaddr != (void __user *)-1l) { > > - pr_err("Memory error may not recovered: %#lx: Sending SIGBUS to %s:%d due to hardware memory corruption\n", > > - p->mce_addr >> PAGE_SHIFT, p->comm, p->pid); > > - force_sig_mceerr(BUS_MCEERR_AR, p->mce_vaddr, PAGE_SHIFT); > > + mc_memory_failure_error(current, p->mce_addr >> PAGE_SHIFT); > > I guess that p->mce_vaddr stores the virtual address of the error here. > If so, sending SIGBUS with the address looks enough as we do now, so why > do you walk page table to find the error virtual address? I check the code again, yes, I should have placed mc_memory_failure_error in else branch, but it seems p->mce_vaddr is not correctly initialized and for my test, it has a zero value then code goes into if (p->mce_vaddr != (void __user *)-1l) branch; It seems this is another issue needing to fix; And from the p->mce_vaddr, possibly there is a better way to get vaddr, i will dig more about this. -- Thanks! Aili Yao