Received: by 10.223.185.116 with SMTP id b49csp2333782wrg; Thu, 15 Feb 2018 10:00:26 -0800 (PST) X-Google-Smtp-Source: AH8x2240KDxFrHaa4D10LtO7MBtDLGMK181OyvKhohiYBDRQWQopvfSoSGHODK2vJ+1MLK8sLvBt X-Received: by 10.99.126.75 with SMTP id o11mr2863914pgn.97.1518717626122; Thu, 15 Feb 2018 10:00:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518717626; cv=none; d=google.com; s=arc-20160816; b=HF5k6GBho1mI8qlF0S75PzeQpbMgmsUqUy72MWhf1gmsVKDBe/GedjDioPygBw+e29 oUlQwKDnvjvbqTOvJK9ZgEAi0hWtMZCFTEuhDCJAh+pO6PN2M0Mw7+swPSnm4Qu8dOXf 9JcGCahCITxFhn1S/U9V6xEMy7PCO/QTp9n/t5t6cWYjoQqwn4UXwbI8FBYLipECqrsC vZSSjmA2jzk8Laju0VqPfz+TekdRlrwiUqWhgPdcwh6ZUAQMnmhpc2itvwjwQ9aeMmXX Dnf87Cbt/8eLzSJZIlOGxzlERi0w758sFVCNdtI1elULW++SnjkZ7OaMBUhfPQP8kXIe 62Ow== 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:in-reply-to :references:subject:cc:to:mime-version:user-agent:from:date :message-id:arc-authentication-results; bh=iH9fZnaoWKYJz7gKRFRUKLifuTZ7LZ7N+zzvYbktG4w=; b=d49P9PjWb8HCXd2rlTA3POYU9BvK7c9LeEtsAPaj7UFU5PJuTClK3cxx9vVU0GuWpF M7WX0jT9r3Nfjlvm2QPMQZkRUwxwVu5IvYCAI/32NJnpTlw+fDi2LN3SK59z0BwWl4J5 f4+HKoLFyjCasf72JmerATmss1QDIx4sy2EpoPcXyASBAsu2p0Kfb60Ai+kF7zlZDj2v 7epQB9naCunWLDKtBoA0jdQBISfgkuLiQXCJfjtuuwGpSTSQsu5iwJW8a212Okqu7RLb JqZAMZSoNHxD6NrgZr5YCW7XNapIWvQ9utyC1ucKVjwRWjxVmEqf6S5nsM4ne+mFd/fF 67KA== ARC-Authentication-Results: i=1; mx.google.com; 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 a72si76501pfj.343.2018.02.15.10.00.09; Thu, 15 Feb 2018 10:00:26 -0800 (PST) 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; 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 S1034093AbeBOR65 (ORCPT + 99 others); Thu, 15 Feb 2018 12:58:57 -0500 Received: from foss.arm.com ([217.140.101.70]:58874 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033969AbeBOR6z (ORCPT ); Thu, 15 Feb 2018 12:58:55 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9EE1D15AD; Thu, 15 Feb 2018 09:58:54 -0800 (PST) Received: from [10.1.207.55] (melchizedek.cambridge.arm.com [10.1.207.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 58ED63F487; Thu, 15 Feb 2018 09:58:50 -0800 (PST) Message-ID: <5A85C9C7.9060701@arm.com> Date: Thu, 15 Feb 2018 17:56:23 +0000 From: James Morse User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.6.0 MIME-Version: 1.0 To: Xie XiuQi CC: catalin.marinas@arm.com, will.deacon@arm.com, mingo@redhat.com, mark.rutland@arm.com, ard.biesheuvel@linaro.org, Dave.Martin@arm.com, takahiro.akashi@linaro.org, tbaicar@codeaurora.org, stephen.boyd@linaro.org, bp@suse.de, julien.thierry@arm.com, shiju.jose@huawei.com, zjzhang@codeaurora.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, wangxiongfeng2@huawei.com, zhengqiang10@huawei.com, gengdongjiu@huawei.com, huawei.libin@huawei.com, wangkefeng.wang@huawei.com, lijinyue@huawei.com, guohanjun@huawei.com, hanjun.guo@linaro.org, cj.chengjian@huawei.com Subject: Re: [PATCH v5 1/3] arm64/ras: support sea error recovery References: <1516969885-150532-1-git-send-email-xiexiuqi@huawei.com> <1516969885-150532-2-git-send-email-xiexiuqi@huawei.com> <5A70C536.7040208@arm.com> <5A7B4D87.9020207@arm.com> <7dacf375-4645-ba34-62d1-96d9f67dbcc2@huawei.com> In-Reply-To: <7dacf375-4645-ba34-62d1-96d9f67dbcc2@huawei.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Xie XiuQi, On 08/02/18 08:35, Xie XiuQi wrote: > I am very glad that you are trying to solve the problem, which is very helpful. > I agree with your proposal, and I'll test it on by box latter. > > Indeed, we're in precess context when we are in sea handler. I was thought we > can't call schedule() in the exception handler before. While testing this I've come to the conclusion that the memory_failure_queue_kick() approach I suggested makes arm64 behave slightly differently with APEI, and would need re-inventing if we support kernel-first too. The same race exists with memory-failure notifications signalled by SDEI, and to a lesser extent IRQ. So by fixing this in arch-code, we actually making our lives harder. Instead, I have the patch below. This is smaller, and not arch specific. It also saves the arch code secretly knowing that APEI calls memory_failure_queue(). I will post this as part of that series shortly... Thanks, James ---------------%<--------------- [PATCH] mm/memory-failure: increase queued recovery work's priority arm64 can take an NMI-like error notification when user-space steps in some corrupt memory. APEI's GHES code will call memory_failure_queue() to schedule the recovery work. We then return to user-space, possibly taking the fault again. Currently the arch code unconditionally signals user-space from this path, so we don't get stuck in this loop, but the affected process never benefits from memory_failure()s recovery work. To fix this we need to know the recovery work will run before we get back to user-space. Increase the priority of the recovery work by scheduling it on the system_highpri_wq, then try to bump the current task off this CPU so that the recover work starts immediately. Reported-by: Xie XiuQi Signed-off-by: James Morse CC: Xie XiuQi CC: gengdongjiu --- mm/memory-failure.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 4b80ccee4535..14f44d841e8b 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include "internal.h" @@ -1319,6 +1320,7 @@ static DEFINE_PER_CPU(struct memory_failure_cpu, memory_failure_cpu); */ void memory_failure_queue(unsigned long pfn, int flags) { + int cpu = smp_processor_id(); struct memory_failure_cpu *mf_cpu; unsigned long proc_flags; struct memory_failure_entry entry = { @@ -1328,11 +1330,14 @@ void memory_failure_queue(unsigned long pfn, int flags) mf_cpu = &get_cpu_var(memory_failure_cpu); spin_lock_irqsave(&mf_cpu->lock, proc_flags); - if (kfifo_put(&mf_cpu->fifo, entry)) - schedule_work_on(smp_processor_id(), &mf_cpu->work); - else + if (kfifo_put(&mf_cpu->fifo, entry)) { + queue_work_on(cpu, system_highpri_wq, &mf_cpu->work); + set_tsk_need_resched(current); + preempt_set_need_resched(); + } else { pr_err("Memory failure: buffer overflow when queuing memory failure at %#lx\n", pfn); + } spin_unlock_irqrestore(&mf_cpu->lock, proc_flags); put_cpu_var(memory_failure_cpu); } ---------------%<---------------