Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp211091imm; Fri, 13 Jul 2018 22:02:34 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcm7YgYPwm5H+mCYbnJ5ivc/uc47+tXj6e1IFl+Muol8nQVpTApxdpGsF9GczaPPWD/0LVf X-Received: by 2002:a63:6986:: with SMTP id e128-v6mr8316952pgc.294.1531544554425; Fri, 13 Jul 2018 22:02:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531544554; cv=none; d=google.com; s=arc-20160816; b=iVTsKJLmcQdXsWHatdpP/PG8z/YgCUsE9oqfHJQghWelxORTrZBE8JAOwo87sigkfs gffbH7+SS3U+apmRHVCez+z2pHL/3gtmm9ipq6zr+Uow3LdVfzAHT15lnyQsOPwveLJj lq3cZgBTikKyL/HdoVAzfWjX4Epqt33E5PtpUWJZzIjB7YTITKSSCKA9qWiEMz9suP2P re2HARSiXmdB3YFz0kC6nb5eVPASintnSZs/8LI5vokgGKxFB/MU1Ivm7JIWFW8c4zhk ChhuCPHQolNCEfZ7QIeOUJL+yDA0WY/5BFm2QLC4a7SRP1DppVMfI7bZwLnwlE4r6ckp t1IA== 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 :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:arc-authentication-results; bh=EfAer62Bati1zZO1rb23M4O8rpSEN1q7ordD74+O5RU=; b=oLW2/TpM8WliI0j3vqqhRJEDgjk689AptSkPB9RvkiMhNE+S34rgZ//YDDCZxslHDQ XZpCDSi2ZLzMutAerh1D+ECLXpkU2ETWPtPNhpNuYPpqr7D8LwS1IvlFDlU+szazJDw1 0lLGJ8OrEp3q2stXHCmW9J5iM/9Ld8Df4K8b3T/Me33KwgmXRE0VAXDqh4eKFRe27O7g +b6n/sH5YA9u6klnfUF/TIqD08L+5qpDWGKv7KsBVT9S3wxAQYYhbg53S0D9sxl5/5rI vm78fMTu7xmDC4DjMlduO368DKF4/Hoaf5CR4r+gJSozBecctaQqes/e+4jfKgCNkVCJ Fg2Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c4-v6si4600506plr.405.2018.07.13.22.02.19; Fri, 13 Jul 2018 22:02:34 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730161AbeGNFSZ (ORCPT + 99 others); Sat, 14 Jul 2018 01:18:25 -0400 Received: from mga05.intel.com ([192.55.52.43]:36407 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725880AbeGNFSZ (ORCPT ); Sat, 14 Jul 2018 01:18:25 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Jul 2018 22:00:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,350,1526367600"; d="scan'208";a="66866182" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga003.jf.intel.com with ESMTP; 13 Jul 2018 22:00:09 -0700 Subject: [PATCH v6 08/13] mm, memory_failure: Collect mapping size in collect_procs() From: Dan Williams To: linux-nvdimm@lists.01.org Cc: Naoya Horiguchi , hch@lst.de, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Fri, 13 Jul 2018 21:50:11 -0700 Message-ID: <153154381163.34503.9922261445330906942.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <153154376846.34503.15480221419473501643.stgit@dwillia2-desk3.amr.corp.intel.com> References: <153154376846.34503.15480221419473501643.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for supporting memory_failure() for dax mappings, teach collect_procs() to also determine the mapping size. Unlike typical mappings the dax mapping size is determined by walking page-table entries rather than using the compound-page accounting for THP pages. Acked-by: Naoya Horiguchi Signed-off-by: Dan Williams --- mm/memory-failure.c | 81 +++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 988f977db3d2..8a81680d00dd 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -174,22 +174,51 @@ int hwpoison_filter(struct page *p) EXPORT_SYMBOL_GPL(hwpoison_filter); /* + * Kill all processes that have a poisoned page mapped and then isolate + * the page. + * + * General strategy: + * Find all processes having the page mapped and kill them. + * But we keep a page reference around so that the page is not + * actually freed yet. + * Then stash the page away + * + * There's no convenient way to get back to mapped processes + * from the VMAs. So do a brute-force search over all + * running processes. + * + * Remember that machine checks are not common (or rather + * if they are common you have other problems), so this shouldn't + * be a performance issue. + * + * Also there are some races possible while we get from the + * error detection to actually handle it. + */ + +struct to_kill { + struct list_head nd; + struct task_struct *tsk; + unsigned long addr; + short size_shift; + char addr_valid; +}; + +/* * Send all the processes who have the page mapped a signal. * ``action optional'' if they are not immediately affected by the error * ``action required'' if error happened in current execution context */ -static int kill_proc(struct task_struct *t, unsigned long addr, - unsigned long pfn, struct page *page, int flags) +static int kill_proc(struct to_kill *tk, unsigned long pfn, int flags) { - short addr_lsb; + struct task_struct *t = tk->tsk; + short addr_lsb = tk->size_shift; int ret; pr_err("Memory failure: %#lx: Killing %s:%d due to hardware memory corruption\n", pfn, t->comm, t->pid); - addr_lsb = compound_order(compound_head(page)) + PAGE_SHIFT; if ((flags & MF_ACTION_REQUIRED) && t->mm == current->mm) { - ret = force_sig_mceerr(BUS_MCEERR_AR, (void __user *)addr, + ret = force_sig_mceerr(BUS_MCEERR_AR, (void __user *)tk->addr, addr_lsb, current); } else { /* @@ -198,7 +227,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, * This could cause a loop when the user sets SIGBUS * to SIG_IGN, but hopefully no one will do that? */ - ret = send_sig_mceerr(BUS_MCEERR_AO, (void __user *)addr, + ret = send_sig_mceerr(BUS_MCEERR_AO, (void __user *)tk->addr, addr_lsb, t); /* synchronous? */ } if (ret < 0) @@ -235,35 +264,6 @@ void shake_page(struct page *p, int access) EXPORT_SYMBOL_GPL(shake_page); /* - * Kill all processes that have a poisoned page mapped and then isolate - * the page. - * - * General strategy: - * Find all processes having the page mapped and kill them. - * But we keep a page reference around so that the page is not - * actually freed yet. - * Then stash the page away - * - * There's no convenient way to get back to mapped processes - * from the VMAs. So do a brute-force search over all - * running processes. - * - * Remember that machine checks are not common (or rather - * if they are common you have other problems), so this shouldn't - * be a performance issue. - * - * Also there are some races possible while we get from the - * error detection to actually handle it. - */ - -struct to_kill { - struct list_head nd; - struct task_struct *tsk; - unsigned long addr; - char addr_valid; -}; - -/* * Failure handling: if we can't find or can't kill a process there's * not much we can do. We just print a message and ignore otherwise. */ @@ -292,6 +292,7 @@ static void add_to_kill(struct task_struct *tsk, struct page *p, } tk->addr = page_address_in_vma(p, vma); tk->addr_valid = 1; + tk->size_shift = compound_order(compound_head(p)) + PAGE_SHIFT; /* * In theory we don't have to kill when the page was @@ -317,9 +318,8 @@ static void add_to_kill(struct task_struct *tsk, struct page *p, * Also when FAIL is set do a force kill because something went * wrong earlier. */ -static void kill_procs(struct list_head *to_kill, int forcekill, - bool fail, struct page *page, unsigned long pfn, - int flags) +static void kill_procs(struct list_head *to_kill, int forcekill, bool fail, + unsigned long pfn, int flags) { struct to_kill *tk, *next; @@ -342,8 +342,7 @@ static void kill_procs(struct list_head *to_kill, int forcekill, * check for that, but we need to tell the * process anyways. */ - else if (kill_proc(tk->tsk, tk->addr, - pfn, page, flags) < 0) + else if (kill_proc(tk, pfn, flags) < 0) pr_err("Memory failure: %#lx: Cannot send advisory machine check signal to %s:%d\n", pfn, tk->tsk->comm, tk->tsk->pid); } @@ -1012,7 +1011,7 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn, * any accesses to the poisoned memory. */ forcekill = PageDirty(hpage) || (flags & MF_MUST_KILL); - kill_procs(&tokill, forcekill, !unmap_success, p, pfn, flags); + kill_procs(&tokill, forcekill, !unmap_success, pfn, flags); return unmap_success; }