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: 10710331 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 BBFE717D5 for ; Mon, 3 Dec 2018 18:33:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACC75288FA for ; Mon, 3 Dec 2018 18:33:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FB582AF9A; Mon, 3 Dec 2018 18:33:55 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3B668288FA for ; Mon, 3 Dec 2018 18:33:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=N2tXagjk2YXHIW2Z3+Aq95p6uUKdAlxq2sDuMwlr414=; b=fV1r6NGLQ1+/s1 Q/GASJiSSL89u4XGAQRafOKSSik4Ba5glUbNz/+dLJzzI4n/+4V93cuug0heByv/tIEg9+OivMhni JI8Heyx3RegCdAJjJOx2cb5la7WFlUJDQuvPsAk6zX3EkKJ3GvTknOxi8zkkEYwth36CNtk3oWEO8 dPoETkk9uXQecFoXqi+5BjO30Pzoj8Vk41LnpwzLuJH0sqWK/jBlmtZ2EP/QTZwUY8HU3M0nwdVeW Lq3BcoXTAIJwAbcSnlXZgnIDYscKVJ+84U8RklB8VZDtxHdMOKiF+/Lx21ou22Gor/B78ClClqNyX NHJROfPVuPQGNJUcf0VQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gTt2U-0005JP-Vv; Mon, 03 Dec 2018 18:33:50 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gTt0P-0003LE-5j for linux-arm-kernel@bombadil.infradead.org; Mon, 03 Dec 2018 18:31:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=kerOtvmOxxD7FTzicp7qWBnU/Qscugchq6UMLvEsTfY=; b=c9aaSm7Es8fOTdx0XYFzRcGeJs 6wlpj42TwRewLdjXKLTJK1EwGOFmiFeAoQM2uNkIJvObLmdDpooe15EbJS61cBbwefi62NV5qbMir 9pz0bywH8Y2ts06Wghgd+ECcY28Su3/3EIG9NbDxqQ2byevDGdlPfauF1ek08oee10coPc3dyGfVC 1NLokOu1zvFjFYeDRlLK2n0p2F8EWQLHsSoXQRYO+KNOtpdI56QTnNymKeaMKzxAwErohMv2m+dnn 3Qmp+r9f9YyqDmGIyhZq4aGH/obr9aTGUdIUVLhLsL2CdIBOgiVeFyc0U/AhwbStbknSn9hi9V7Ov 4SRkGpTA==; Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by merlin.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gTsdQ-0001f2-Eu for linux-arm-kernel@lists.infradead.org; Mon, 03 Dec 2018 18:07:57 +0000 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181203_130756_592722_D41B6A3E X-CRM114-Status: GOOD ( 16.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rafael Wysocki , Tony Luck , Fan Wu , Xie XiuQi , Marc Zyngier , Catalin Marinas , Will Deacon , Christoffer Dall , Dongjiu Geng , linux-mm@kvack.org, Borislav Petkov , James Morse , Naoya Horiguchi , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, Len Brown Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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;