Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp245259ybg; Thu, 17 Oct 2019 22:17:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqzuPqITs9UthczF2JOcfxZKConGTpmmfOFXKO4nsuFf+8zoq6ih/MeB8oXWFJI6hRzhUubm X-Received: by 2002:a17:907:3301:: with SMTP id ym1mr7097779ejb.106.1571375873098; Thu, 17 Oct 2019 22:17:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571375873; cv=none; d=google.com; s=arc-20160816; b=HoWc5q0s5l/pgjlWe/F9Mh83AeX0sKzOdUIxiriPifFPLrTh+s+a09QI+LKoUJeW0J 9u8RnEQzvkaJzi9URa6a3E1kmAzFnauuiJeOMS2IzLZnnTDe96TpP+JVutw52SAkLQ4y uzNHnYJVZ0uCBULytgQ+Pq8GB7IYNu4RaLb51JCzEAl0wMF9HDnkB0GyQg2S8KWCzAhO dEsvCU9IWWbC8G923klR//EbJyWX/xFkrCRZGVFWyOnvmbSaNx/SIPdgn8egFPy6Im6o yodNntJMPaVs0AoRw3/SIWroKtMx/qdkFJg2gqxb+cgYlKeivvqc4FpY/tVHZrB21CKx zFnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=jiJM3q00Cs3J+4iBdzrbz+3NBuTvctRmPGhTW89Z5+k=; b=ELiYbUvbbo138OhbcrfqrDQiJEn2IYQAv58Ae4zyw1zbGLxKaCh1+rhuQeq6L2RQRf frEFYUlXNAedZcrEeTbMFlpng4bvynwXn5r40qOD9d7lb8BZn5a0R1SGV9sx+xLABYbg sBe22Zh849UdsiqLHm8ZaoLSUN6UXeOEy+nZuH1d++SAncBW7UOWKQaDwM1JuuQDAT0V 8GQqNNfTrJhtwLzRWpTQYm5ygdH3GsTGpe8eMzTSZG42dlCGzRpLrrBuD/1WJ5KNyJDc PVBsgIYPNlQtSNKYbZ1NQSHdYYqxk5mZAgUogvzLkYTPp+UnGlPI+xz1alwuapVGH0/6 SX+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id kt5si2842912ejb.283.2019.10.17.22.17.29; Thu, 17 Oct 2019 22:17:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392962AbfJPXxA (ORCPT + 99 others); Wed, 16 Oct 2019 19:53:00 -0400 Received: from www9186uo.sakura.ne.jp ([153.121.56.200]:35496 "EHLO www9186uo.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728701AbfJPXxA (ORCPT ); Wed, 16 Oct 2019 19:53:00 -0400 X-Greylist: delayed 348 seconds by postgrey-1.27 at vger.kernel.org; Wed, 16 Oct 2019 19:52:58 EDT Received: by www9186uo.sakura.ne.jp (Postfix, from userid 500) id D74D01E3745; Thu, 17 Oct 2019 08:47:08 +0900 (JST) Date: Thu, 17 Oct 2019 08:47:08 +0900 From: Naoya Horiguchi To: David Hildenbrand Cc: Naoya Horiguchi , "linux-mm@kvack.org" , Michal Hocko , Oscar Salvador , "linux-kernel@vger.kernel.org" , Andrew Morton Subject: Re: [PATCH] mm, soft-offline: convert parameter to pfn Message-ID: <20191016234706.GA5493@www9186uo.sakura.ne.jp> References: <20191016070924.GA10178@hori.linux.bs1.fc.nec.co.jp> <20191016082735.GB13770@hori.linux.bs1.fc.nec.co.jp> <20191016085359.GD13770@hori.linux.bs1.fc.nec.co.jp> <997b5b51-db71-3e27-1f84-cbaa24fa66c7@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-2022-jp Content-Disposition: inline In-Reply-To: <997b5b51-db71-3e27-1f84-cbaa24fa66c7@redhat.com> User-Agent: Mutt/1.5.20 (2009-12-10) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 16, 2019 at 10:57:57AM +0200, David Hildenbrand wrote: > On 16.10.19 10:54, Naoya Horiguchi wrote: > >On Wed, Oct 16, 2019 at 10:34:52AM +0200, David Hildenbrand wrote: > >>On 16.10.19 10:27, Naoya Horiguchi wrote: > >>>On Wed, Oct 16, 2019 at 09:56:19AM +0200, David Hildenbrand wrote: > >>>>On 16.10.19 09:09, Naoya Horiguchi wrote: > >>>>>Hi, > >>>>> > >>>>>I wrote a simple cleanup for parameter of soft_offline_page(), > >>>>>based on thread https://lkml.org/lkml/2019/10/11/57. > >>>>> > >>>>>I know that we need more cleanup on hwpoison-inject, but I think > >>>>>that will be mentioned in re-write patchset Oscar is preparing now. > >>>>>So let me shared only this part as a separate one now. > >>>... > >>>> > >>>>I think you should rebase that patch on linux-next (where the > >>>>pfn_to_online_page() check is in place). I assume you'll want to move the > >>>>pfn_to_online_page() check into soft_offline_page() then as well? > >>> > >>>I rebased to next-20191016. And yes, we will move pfn_to_online_page() > >>>into soft offline code. It seems that we can also move pfn_valid(), > >>>but is simply moving like below good enough for you? > >> > >>At least I can't am the patch to current next/master (due to > >>pfn_to_online_page()). > > Could also be that my "git am" skills failed as the mail was not a > proper patch itself :) Sorry for the inconvenience, my company email system breaks original message by introducing quoted-printable format ('=20' or '=3D'). Most mail client usually handles it but git-am doesn't. I give up using it and send via smtp.gmail.com. > >@@ -1877,11 +1877,17 @@ static int soft_offline_free_page(struct page *page) > > * This is not a 100% solution for all memory, but tries to be > > * ``good enough'' for the majority of memory. > > */ > >-int soft_offline_page(struct page *page, int flags) > >+int soft_offline_page(unsigned long pfn, int flags) > > { > > int ret; > >- unsigned long pfn = page_to_pfn(page); > >+ struct page *page; > >+ if (!pfn_valid(pfn)) > >+ return -ENXIO; > >+ /* Only online pages can be soft-offlined (esp., not ZONE_DEVICE). */ > >+ page = pfn_to_online_page(pfn); > >+ if (!page) > >+ return -EIO; > > if (is_zone_device_page(page)) { > > -> this is now no longer possible! So you can drop the whole if > (is_zone_device....) case OK, thanks. I updated it. Thanks, Naoya Horiguchi --- From 5faf227839b578726fe7f5ff414a153abb3b3a31 Mon Sep 17 00:00:00 2001 From: Naoya Horiguchi Date: Thu, 17 Oct 2019 08:40:53 +0900 Subject: [PATCH] mm, soft-offline: convert parameter to pfn Currently soft_offline_page() receives struct page, and its sibling memory_failure() receives pfn. This discrepancy looks weird and makes precheck on pfn validity tricky. So let's align them. Signed-off-by: Naoya Horiguchi --- drivers/base/memory.c | 7 +------ include/linux/mm.h | 2 +- mm/madvise.c | 2 +- mm/memory-failure.c | 19 +++++++++---------- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 55907c27075b..a757d9ed88a7 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -538,12 +538,7 @@ static ssize_t soft_offline_page_store(struct device *dev, if (kstrtoull(buf, 0, &pfn) < 0) return -EINVAL; pfn >>= PAGE_SHIFT; - if (!pfn_valid(pfn)) - return -ENXIO; - /* Only online pages can be soft-offlined (esp., not ZONE_DEVICE). */ - if (!pfn_to_online_page(pfn)) - return -EIO; - ret = soft_offline_page(pfn_to_page(pfn), 0); + ret = soft_offline_page(pfn, 0); return ret == 0 ? count : ret; } diff --git a/include/linux/mm.h b/include/linux/mm.h index 44d058723db9..fd360d208346 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2794,7 +2794,7 @@ extern int sysctl_memory_failure_early_kill; extern int sysctl_memory_failure_recovery; extern void shake_page(struct page *p, int access); extern atomic_long_t num_poisoned_pages __read_mostly; -extern int soft_offline_page(struct page *page, int flags); +extern int soft_offline_page(unsigned long pfn, int flags); /* diff --git a/mm/madvise.c b/mm/madvise.c index 2be9f3fdb05e..99dd06fecfa9 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -887,7 +887,7 @@ static int madvise_inject_error(int behavior, pr_info("Soft offlining pfn %#lx at process virtual address %#lx\n", pfn, start); - ret = soft_offline_page(page, MF_COUNT_INCREASED); + ret = soft_offline_page(pfn, MF_COUNT_INCREASED); if (ret) return ret; continue; diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 05c8c6df25e6..af2712004a4d 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1476,7 +1476,7 @@ static void memory_failure_work_func(struct work_struct *work) if (!gotten) break; if (entry.flags & MF_SOFT_OFFLINE) - soft_offline_page(pfn_to_page(entry.pfn), entry.flags); + soft_offline_page(entry.pfn, entry.flags); else memory_failure(entry.pfn, entry.flags); } @@ -1857,7 +1857,7 @@ static int soft_offline_free_page(struct page *page) /** * soft_offline_page - Soft offline a page. - * @page: page to offline + * @pfn: pfn to soft-offline * @flags: flags. Same as memory_failure(). * * Returns 0 on success, otherwise negated errno. @@ -1877,18 +1877,17 @@ static int soft_offline_free_page(struct page *page) * This is not a 100% solution for all memory, but tries to be * ``good enough'' for the majority of memory. */ -int soft_offline_page(struct page *page, int flags) +int soft_offline_page(unsigned long pfn, int flags) { int ret; - unsigned long pfn = page_to_pfn(page); + struct page *page; - if (is_zone_device_page(page)) { - pr_debug_ratelimited("soft_offline: %#lx page is device page\n", - pfn); - if (flags & MF_COUNT_INCREASED) - put_page(page); + if (!pfn_valid(pfn)) + return -ENXIO; + /* Only online pages can be soft-offlined (esp., not ZONE_DEVICE). */ + page = pfn_to_online_page(pfn); + if (!page) return -EIO; - } if (PageHWPoison(page)) { pr_info("soft offline: %#lx page already poisoned\n", pfn); -- 2.17.1