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.0 required=3.0 tests=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 C2FBBC433E2 for ; Tue, 19 May 2020 17:54:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9BB0220758 for ; Tue, 19 May 2020 17:54:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9BB0220758 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6272080007; Tue, 19 May 2020 13:54:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 605F1900002; Tue, 19 May 2020 13:54:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53A4680007; Tue, 19 May 2020 13:54:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0223.hostedemail.com [216.40.44.223]) by kanga.kvack.org (Postfix) with ESMTP id 3BE97900002 for ; Tue, 19 May 2020 13:54:09 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 03A608245571 for ; Tue, 19 May 2020 17:54:09 +0000 (UTC) X-FDA: 76834217418.08.shock77_7b7fd6a6a9439 X-HE-Tag: shock77_7b7fd6a6a9439 X-Filterd-Recvd-Size: 7417 Received: from mail-oi1-f196.google.com (mail-oi1-f196.google.com [209.85.167.196]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Tue, 19 May 2020 17:54:08 +0000 (UTC) Received: by mail-oi1-f196.google.com with SMTP id v128so505195oia.7 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=YlqYtkx2h1wgZxiUUX/VSpVkgI5NKieXXJ+XA/Q70z210W6yXUi//Bg4AlErgEJg3N Vjgc2PenLqBxhZIqQ4Liw/jrG1qHs2T6WXgJmOqmjNgHg4icdHrpFSTlL5UziuWsv5dV 2OPP1G+wCSCki3Od+lj7d8aI7zwLiMY/j8Bjemhg6+zx5YIhlyfI+2uIZSqIlgRu5c6T X6HlaTDySKdnDl4eXgSly7Sghij6g/VFXXuWXYo3RDO6jO5I+9YPsbSZVehmr2rM2VsF F+UPlQpcAxK+4EVLSFB1An/IGsHb3cEgUM4COIWLUSOzhfVh9kIRf4Ns4C9rQghgujGu RX2w== X-Gm-Message-State: AOAM5313n7o0WT7/Pi+tj5K3PzjPa6c9F3JmfZgpSFLEjHwP3ZNmTOoc PmHF/JgmzwXQ77LRKvRVBUnSOhFbXILNBm9mKII= 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: quoted-printable 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: On Tue, May 19, 2020 at 5:15 AM HORIGUCHI NAOYA(=E5=A0=80=E5=8F=A3=E3=80=80= =E7=9B=B4=E4=B9=9F) 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 sche= dule > > > > work on the current CPU so that memory_failure() can sleep. > > > > > > > > For synchronous memory errors the arch code needs to know any signa= ls > > > > 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 schedu= led > > > > work has happened. This has to be called from process context, so m= ay > > > > 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 'wr= ong' > > > > 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 w= ork_struct *work) > > > > unsigned long proc_flags; > > > > int gotten; > > > > > > > > - mf_cpu =3D this_cpu_ptr(&memory_failure_cpu); > > > > + mf_cpu =3D container_of(work, struct memory_failure_cpu, work); > > > > for (;;) { > > > > spin_lock_irqsave(&mf_cpu->lock, proc_flags); > > > > gotten =3D 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_failur= e workqueue. > > > > + */ > > > > +void memory_failure_queue_kick(int cpu) > > > > +{ > > > > + struct memory_failure_cpu *mf_cpu; > > > > + > > > > + mf_cpu =3D &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 ca= n > be scheduled on another CPU when the kernel returned back to userspace af= ter > 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_queu= e() > has 2 callers, ghes_handle_memory_failure() and cec_add_elem(). The forme= r > 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!