From patchwork Mon Dec 3 18:06:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710287 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 075A815A6 for ; Mon, 3 Dec 2018 18:08:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F08092B47E for ; Mon, 3 Dec 2018 18:08:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E48EA2B495; Mon, 3 Dec 2018 18:08:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A5862B47E for ; Mon, 3 Dec 2018 18:08:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D1636B6A8D; Mon, 3 Dec 2018 13:07:53 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 883D96B6A8E; Mon, 3 Dec 2018 13:07:53 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 721AA6B6A8F; Mon, 3 Dec 2018 13:07:53 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by kanga.kvack.org (Postfix) with ESMTP id 416F36B6A8D for ; Mon, 3 Dec 2018 13:07:53 -0500 (EST) Received: by mail-ot1-f70.google.com with SMTP id s12so5859767otc.12 for ; Mon, 03 Dec 2018 10:07:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=kerOtvmOxxD7FTzicp7qWBnU/Qscugchq6UMLvEsTfY=; b=R2L+QTy/Ahs4Tqegqya/x0hoUbSLMTSd97G9yXJBwjqb3MlwCjtBqy1O6T8FOp+OXn s7+j+hZXdE4KmNeSABTRNhzlbJEhl9uhmhbzGWNv3Jj/YbyD4KC3WXb0BfvXkbwJVnqQ Fj+rujPw2pz7MTmQF+1+Fhu+vN7JroGHFhU1jIwvD6b4+kmNEbgxqOwLxg7zUMhzN4pW uYAKMY0mr1GAlWYGP5z3SJYkVPIzGiitk7/petyInPie0m1TKEVEXl44pveU9DaT0H0X 5/UM6MIrUOEbMKsS7Bnq6aP6AXiU4xLmQBSC5NxBR97zPxBir1NCrxSej+7IHUhfA3rq LSHg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWa58L/luivUD5tZmaJ/Lj/vPLHnVoGp3DnstVGa3wR5bTz/p4Yp VVUrjFkgZ/pcWmYQsgBt/682+zwBU6cfc4gJmukg86xUIVoWztKeIQc9MUfUE6SUsJRYaTrJ3XK So3o/J/n7F8vfdTUvmdPteEHVqv1mFzfeJTp8SAarzEMd4aHo7GAiBDkJsLVhIz2xnA== X-Received: by 2002:aca:5a88:: with SMTP id o130mr11060655oib.275.1543860473027; Mon, 03 Dec 2018 10:07:53 -0800 (PST) X-Google-Smtp-Source: AFSGD/VDDlwXgeGgCaMdYv6K+aSxyirMJBtBNcL3upWvmHKvZbFUk5KovP0GtVQeBTBF9uli1cGW X-Received: by 2002:aca:5a88:: with SMTP id o130mr11060628oib.275.1543860472327; Mon, 03 Dec 2018 10:07:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860472; cv=none; d=google.com; s=arc-20160816; b=XJHx/vNcwMrWPUBmt7+UB9VHA20f81/C8AjiFd85PA8gR99ZOWaZQ1ed2OncAI+R5A RaJZM5RldjLMQ4z0C48pyp2/PRO0fW+FR1AbgiBni97TnuY+f6dkLmv5hmhLYA3K0q8T 6m823ZckyMHH7GtQVovrW5u5y1kpBm6Hsy7dLJ2yvBIyjmtKpQJE1QKqEHQO78ttegmi jsRf6b3qoUBQCmUcPstZncHQrD6QN9zGXjznseE74+KlxuK2a9prz08SUDVziqWq0mBj z6Ik3t+EV8KL5VC2jgUS7vKBGVgMbEJhDtuooyez+BNDersRZoipPRvIgSV9pt9flz2f cNtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=kerOtvmOxxD7FTzicp7qWBnU/Qscugchq6UMLvEsTfY=; b=DhIyWSxlEBbeJPPoEjD/tEJag1X2hpGxO3SXVzL43z8Vd6De0p0BJtk/50mF5BZUEq wabLQT4dCVyZ8RWCqmk7ruX6SfSstUbkFLHEC9qaxmqCaICY1o6QMkZo/dTWPOsZ5/4e BfX2aOXXs8kyRIuPq5SDLpvZkGLrb/cLpuCQ8Kb9cTw++FTTqnI0KADhQCdYs6XpTB35 mRCKKuZoxFuxKYB8sexA4dKlWdUTKX8AQdcrJ1Ac6Qe1D2Zn/mhpd4MN1U2M022As6rm VvUDdmPrcrU16vvx3U9xh/wsG231aHg/tqP3pqBpC5HNxNNjQ7jgqJ7kp2TMmK3Inf6L agPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com Received: from foss.arm.com (usa-sjc-mx-foss1.foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id 108si7171623oti.277.2018.12.03.10.07.52 for ; Mon, 03 Dec 2018 10:07:52 -0800 (PST) Received-SPF: pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com 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 B8DDC1715; Mon, 3 Dec 2018 10:07:51 -0800 (PST) Received: from eglon.cambridge.arm.com (eglon.cambridge.arm.com [10.1.196.105]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E88C93F59C; Mon, 3 Dec 2018 10:07:48 -0800 (PST) From: James Morse To: linux-acpi@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Borislav Petkov , Marc Zyngier , Christoffer Dall , Will Deacon , Catalin Marinas , Naoya Horiguchi , Rafael Wysocki , Len Brown , Tony Luck , Dongjiu Geng , Xie XiuQi , Fan Wu , James Morse Subject: [PATCH v7 21/25] mm/memory-failure: Add memory_failure_queue_kick() Date: Mon, 3 Dec 2018 18:06:09 +0000 Message-Id: <20181203180613.228133-22-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The GHES code calls memory_failure_queue() from IRQ context to schedule work on the current CPU so that memory_failure() can sleep. For synchronous memory errors the arch code needs to know any signals that memory_failure() will trigger are pending before it returns to user-space, possibly when exiting from the IRQ. Add a helper to kick the memory failure queue, to ensure the scheduled work has happened. This has to be called from process context, so may have been migrated from the original cpu. Pass the cpu the work was queued on. Change memory_failure_work_func() to permit being called on the 'wrong' cpu. Signed-off-by: James Morse --- include/linux/mm.h | 1 + mm/memory-failure.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 5411de93a363..37b4884b2a1e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2692,6 +2692,7 @@ enum mf_flags { }; extern int memory_failure(unsigned long pfn, int flags); extern void memory_failure_queue(unsigned long pfn, int flags); +extern void memory_failure_queue_kick(int cpu); extern int unpoison_memory(unsigned long pfn); extern int get_hwpoison_page(struct page *page); #define put_hwpoison_page(page) put_page(page) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 0cd3de3550f0..ec05e1dfce37 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1480,7 +1480,7 @@ static void memory_failure_work_func(struct work_struct *work) unsigned long proc_flags; int gotten; - mf_cpu = this_cpu_ptr(&memory_failure_cpu); + mf_cpu = container_of(work, struct memory_failure_cpu, work); for (;;) { spin_lock_irqsave(&mf_cpu->lock, proc_flags); gotten = kfifo_get(&mf_cpu->fifo, &entry); @@ -1494,6 +1494,19 @@ static void memory_failure_work_func(struct work_struct *work) } } +/* + * Process memory_failure work queued on the specified CPU. + * Used to avoid return-to-userspace racing with the memory_failure workqueue. + */ +void memory_failure_queue_kick(int cpu) +{ + struct memory_failure_cpu *mf_cpu; + + mf_cpu = &per_cpu(memory_failure_cpu, cpu); + cancel_work_sync(&mf_cpu->work); + memory_failure_work_func(&mf_cpu->work); +} + static int __init memory_failure_init(void) { struct memory_failure_cpu *mf_cpu;