From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 756B1C433E0 for ; Mon, 18 May 2020 19:58:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4AAA12081A for ; Mon, 18 May 2020 19:58:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589831910; bh=nxo2uyrHnJi5DnLmPJ4mv9Kr35HEpbx7CmvMdiP/OH4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=KITIBw8/YEP6wQFej/PrFOh9oxSBiyRCrIMA2KQE+Vy5Dm3qlBj5XGYe2X25lsrn+ CuhCRfpkPmsCOqE3shsjBXnI0R4ZSRSPkjdHXL+EZLvjo3+3pRrvvLZhNfuacLbp7G 3HMvjzyZ/gkIw+XffoUu3Jb0Ch1UYcWf4vdy1+ME= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728668AbgERT63 (ORCPT ); Mon, 18 May 2020 15:58:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:42302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726478AbgERT63 (ORCPT ); Mon, 18 May 2020 15:58:29 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8E7D920758; Mon, 18 May 2020 19:58:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589831909; bh=nxo2uyrHnJi5DnLmPJ4mv9Kr35HEpbx7CmvMdiP/OH4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=gtLLQynTEahJo7NSEd9NHZR7KvmuyM4/0lzVMvnb0+zt8LVUBHow/82N1pU3WpL9P 4bmTcYRRamBsfRU6+Bnh3o5MHVvMwPojnNIwrvXKv0GCleeS5OswE6zI1zvVftD+4a FOaEiwJ0K89WE617Heq5rB2zjU1P0qd/KRsz1bSs= Date: Mon, 18 May 2020 12:58:28 -0700 From: Andrew Morton To: "Rafael J. Wysocki" Cc: James Morse , linux-mm@kvack.org, linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Naoya Horiguchi , Len Brown , Tony Luck , Borislav Petkov , Catalin Marinas , Will Deacon , Mark Rutland , Tyler Baicar , Xie XiuQi Subject: Re: [PATCH v2 1/3] mm/memory-failure: Add memory_failure_queue_kick() Message-Id: <20200518125828.e4e3973c743556e976c5ee65@linux-foundation.org> In-Reply-To: <49686237.p6yG9EJavU@kreacher> References: <20200501164543.24423-1-james.morse@arm.com> <20200501164543.24423-2-james.morse@arm.com> <49686237.p6yG9EJavU@kreacher> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org On Mon, 18 May 2020 14:45:05 +0200 "Rafael J. Wysocki" wrote: > On Friday, May 1, 2020 6:45:41 PM CEST James Morse wrote: > > 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. > > > > --- a/include/linux/mm.h > > +++ b/include/linux/mm.h > > @@ -3012,6 +3012,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 a96364be8ab4..c4afb407bf0f 100644 > > --- a/mm/memory-failure.c > > +++ b/mm/memory-failure.c > > @@ -1493,7 +1493,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); > > @@ -1507,6 +1507,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; > > > > I could apply this provided an ACK from the mm people. > Naoya Horiguchi is the memory-failure.c person. A review would be appreciated please? I'm struggling with it a bit. memory_failure_queue_kick() should be called on the cpu which is identified by arg `cpu', yes? memory_failure_work_func() appears to assume this. If that's right then a) why bother passing in the `cpu' arg? and b) what keeps this thread pinned to that CPU? cancel_work_sync() can schedule. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 482B7C433DF for ; Mon, 18 May 2020 19:58:35 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 119EC20758 for ; Mon, 18 May 2020 19:58:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="BMfzb81V"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="gtLLQynT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 119EC20758 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=n0LTHGPGUrPegQpjoorvNakaAd8WgSAalKtldLLqN38=; b=BMfzb81VtOW3aA 443NWBKtkHqA3H72dH2Q8BnqvoFuK5FZNQeVoJN3Jhp54/IyKxkuo1cQN0kMcRL5KdxW+g8U7Jg4x e7LGFlUNET++HRHz2Lnn/CDioT1AmpRzoM4S5Cn00BBf2MOfdQIIN7on8KDVIsYRURve6J2eesI9k FTIBmwUpFJawYpqPxYYKDQU4T+XgL+Mu6NjgzWrRB533QgoiYUSAsXMBmVsvu7lzsKzdhY080Y25G ql2EZpnXtxeOdaXzBi6rMfOfugtHVSGiJ3HODVSCTuCxJEZsSEGEY6tPgRMH/5FL7CIbbXufy3q7r EifNLlvcYTVv1fmdsbJg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jaluD-0002DS-Kr; Mon, 18 May 2020 19:58:33 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jaluA-0002Cj-82 for linux-arm-kernel@lists.infradead.org; Mon, 18 May 2020 19:58:31 +0000 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8E7D920758; Mon, 18 May 2020 19:58:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589831909; bh=nxo2uyrHnJi5DnLmPJ4mv9Kr35HEpbx7CmvMdiP/OH4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=gtLLQynTEahJo7NSEd9NHZR7KvmuyM4/0lzVMvnb0+zt8LVUBHow/82N1pU3WpL9P 4bmTcYRRamBsfRU6+Bnh3o5MHVvMwPojnNIwrvXKv0GCleeS5OswE6zI1zvVftD+4a FOaEiwJ0K89WE617Heq5rB2zjU1P0qd/KRsz1bSs= Date: Mon, 18 May 2020 12:58:28 -0700 From: Andrew Morton To: "Rafael J. Wysocki" Subject: Re: [PATCH v2 1/3] mm/memory-failure: Add memory_failure_queue_kick() Message-Id: <20200518125828.e4e3973c743556e976c5ee65@linux-foundation.org> In-Reply-To: <49686237.p6yG9EJavU@kreacher> References: <20200501164543.24423-1-james.morse@arm.com> <20200501164543.24423-2-james.morse@arm.com> <49686237.p6yG9EJavU@kreacher> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200518_125830_323799_0B29CCA6 X-CRM114-Status: GOOD ( 20.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Tony Luck , linux-acpi@vger.kernel.org, Catalin Marinas , Xie XiuQi , linux-mm@kvack.org, Tyler Baicar , James Morse , Borislav Petkov , Naoya Horiguchi , Will Deacon , linux-arm-kernel@lists.infradead.org, Len Brown Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 18 May 2020 14:45:05 +0200 "Rafael J. Wysocki" wrote: > On Friday, May 1, 2020 6:45:41 PM CEST James Morse wrote: > > 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. > > > > --- a/include/linux/mm.h > > +++ b/include/linux/mm.h > > @@ -3012,6 +3012,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 a96364be8ab4..c4afb407bf0f 100644 > > --- a/mm/memory-failure.c > > +++ b/mm/memory-failure.c > > @@ -1493,7 +1493,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); > > @@ -1507,6 +1507,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; > > > > I could apply this provided an ACK from the mm people. > Naoya Horiguchi is the memory-failure.c person. A review would be appreciated please? I'm struggling with it a bit. memory_failure_queue_kick() should be called on the cpu which is identified by arg `cpu', yes? memory_failure_work_func() appears to assume this. If that's right then a) why bother passing in the `cpu' arg? and b) what keeps this thread pinned to that CPU? cancel_work_sync() can schedule. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel