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=-4.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 131B5C433E0 for ; Tue, 19 May 2020 17:54:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E11E420674 for ; Tue, 19 May 2020 17:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589910849; bh=KQ09qmJntw1c9q5pRGAJny+H3aXXXYJ/5NQQVbuBJ6I=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=eeeyPZjdrxHKWiJTONjDKi37xrYiEDEkAIEB1jEfv6+REx5Evr+EvA+aJWU3FsDP2 IWShS67+1xonVJCu0H+N5+2xX5ZnNhZaI04FYISlbb/QsyoN2RJJwwB5XEVTePokmj g6lRDN4DxhveFD+tQMqbRpXWEvOLFPW/AbhhRkGU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727814AbgESRyJ convert rfc822-to-8bit (ORCPT ); Tue, 19 May 2020 13:54:09 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:39216 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726059AbgESRyJ (ORCPT ); Tue, 19 May 2020 13:54:09 -0400 Received: by mail-oi1-f196.google.com with SMTP id s198so515183oie.6 for ; Tue, 19 May 2020 10:54:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=oLkdDiI5HFWL8C7O6W36h9N6UH3412FNuY/4J1ySuKI=; b=BIxbhrzNLd98yodnnR2h8w+FvaTDdJtBN9sB6cQamRDo5XKWqvledas++CSeLvGdlp pGeHjBoydD6emDPG65uTfOQfZg557Q5ySQpbYY3MSG8PdTTLA1yPxKx9ReATDfF9JdiF 2qbKpLWwqPw+m1rfth3yMWpbMQ2wRcTAs58HPPVXiWyJoamq5WOOeksf82H94raRSa+R Z4FUouzbFGK+N2tqs/j5rPkPAfVc/kTMe0Qo99HxdW/0Y6IupJn9yaNCtT/77MALseM3 djxfNio0+VtgD7RVAGZjsx75f2vVbuvM3+gLyfTwIXaHTci10ajVp6sfrdYpsWu1avoH zFUw== X-Gm-Message-State: AOAM533sGt0CI3Tcham02cYsBubz4v4Tvv6PL+htT1zXuau2Z0e29pf5 CViZMZaq3Dpzd6wMZdAlVcmSed6Nt0M++PBhcHM= X-Google-Smtp-Source: ABdhPJyQZS1Xr8gnb53yM7SiKuoBHfAVWDm0sXFCpKkYsNKzAITxSaP4lvBa4TN4o5V50bKrrF/ZMaRIevhXPrGZPZs= X-Received: by 2002:aca:4254:: with SMTP id p81mr454025oia.68.1589910847813; Tue, 19 May 2020 10:54:07 -0700 (PDT) MIME-Version: 1.0 References: <20200501164543.24423-1-james.morse@arm.com> <20200501164543.24423-2-james.morse@arm.com> <49686237.p6yG9EJavU@kreacher> <20200518125828.e4e3973c743556e976c5ee65@linux-foundation.org> <20200519031511.GA31023@hori.linux.bs1.fc.nec.co.jp> In-Reply-To: <20200519031511.GA31023@hori.linux.bs1.fc.nec.co.jp> From: "Rafael J. Wysocki" Date: Tue, 19 May 2020 19:53:56 +0200 Message-ID: Subject: Re: [PATCH v2 1/3] mm/memory-failure: Add memory_failure_queue_kick() To: =?UTF-8?B?SE9SSUdVQ0hJIE5BT1lBKOWggOWPoyDnm7TkuZ8p?= , James Morse Cc: Andrew Morton , "Rafael J. Wysocki" , "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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org On Tue, May 19, 2020 at 5:15 AM HORIGUCHI NAOYA(堀口 直也) wrote: > > On Mon, May 18, 2020 at 12:58:28PM -0700, Andrew Morton wrote: > > 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. > > If I read correctly, memory_failure work is queue on the CPU on which the > user process ran when it touched the corrupted memory, and the process can > be scheduled on another CPU when the kernel returned back to userspace after > handling the GHES event. So we need to remember where the memory_failure > event is queued to flush proper work queue. So I feel that this properly > implements it. > > Considering the effect to the other caller, currently memory_failure_queue() > has 2 callers, ghes_handle_memory_failure() and cec_add_elem(). The former > is what we try to change now. And the latter is to execute soft offline > (which is related to corrected non-fatal errors), so that's not affected by > the reported issue. So I don't think that this change breaks the other > caller. > > So I'm fine with the suggested change. > > Acked-by: Naoya Horiguchi OK, thanks! So because patch [1/3] has been ACKed already, I'm applying this series as 5.8 material. Thanks everyone!