Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp7262800ybp; Wed, 16 Oct 2019 06:17:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsdm90OugMMF6WTpC+7GA4mk6fOyma2m49FFBsuS/o3qxTI5/KNY83kJDJPSAk9xsmGoem X-Received: by 2002:a50:e71a:: with SMTP id a26mr38878379edn.265.1571231876972; Wed, 16 Oct 2019 06:17:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571231876; cv=none; d=google.com; s=arc-20160816; b=wYpafMgeRNvHvZWXFpBYSjWlLEyxNbmLTc0qTSOAoFp5HH4ORY/z+1C0iOUiXG67sT Rv1i8VCTlFE7NU8PS9GlBYNCJAza/Nspndv2Ptr9zZgjD+Q7GxXBWQr7RYFpzRFmUxvR hU++qo+mzBdOM++OLjzeZwnC8LnZY7GYlAMO3syhRolmhpyZ22Wu+UM88q7GbcwWnWGA HO65KL6cPCh5eqMgyg/eHn50Xvfcf251HkkuuamQBzNo9xQmQ4FXipnexDI6Hs7BtJhw Ic5haegOZ/u7yDXyOUdsnblh6rWl4iaReiCURX/K3FZFVNH7bvzj+EoPO1rKP6Yi0lVa OpTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from; bh=FekQeA/41xssOb2DTdm500xNrcOhiMl6KbPpRaSJu4Q=; b=scIGVgRmHF0MFRkT4la5p7ts2SgdkwtYskWuAEf57VU3ZqDzIHtev2jRnQAVMrBZoE YCVybfP6/xTaGSSFfAlhJhTtDTnTQ3IRuZ94pJoW8Ln/vIeVcO3bGkmRsISzL3cWGwck Z/V9CFJxY2fWRkoj4s9FHIj5h3+P1nF23FXJ7FFqbbOQt3z0Zxy/7exg6l/1uo/+NO1g pMlq2nk5w16Z3nOQLhMl2PyZNHwsnnfJjR0rr5CUyFGnJwO4kx0iA+WfSwMRE49knU+J uCRZ3A6oRS/hPeCdnBnOQ4VxMI3OZ0Pnvy6ORi9anOat8YyC8zDwaFEf5nL8YKCfmeKw reZg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z55si17391831edb.41.2019.10.16.06.17.33; Wed, 16 Oct 2019 06:17:56 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391771AbfJPIyk convert rfc822-to-8bit (ORCPT + 99 others); Wed, 16 Oct 2019 04:54:40 -0400 Received: from tyo161.gate.nec.co.jp ([114.179.232.161]:38795 "EHLO tyo161.gate.nec.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732135AbfJPIyj (ORCPT ); Wed, 16 Oct 2019 04:54:39 -0400 Received: from mailgate02.nec.co.jp ([114.179.233.122]) by tyo161.gate.nec.co.jp (8.15.1/8.15.1) with ESMTPS id x9G8sMjn029051 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 16 Oct 2019 17:54:22 +0900 Received: from mailsv02.nec.co.jp (mailgate-v.nec.co.jp [10.204.236.94]) by mailgate02.nec.co.jp (8.15.1/8.15.1) with ESMTP id x9G8sMLv016072; Wed, 16 Oct 2019 17:54:22 +0900 Received: from mail02.kamome.nec.co.jp (mail02.kamome.nec.co.jp [10.25.43.5]) by mailsv02.nec.co.jp (8.15.1/8.15.1) with ESMTP id x9G8rWeo007892; Wed, 16 Oct 2019 17:54:22 +0900 Received: from bpxc99gp.gisp.nec.co.jp ([10.38.151.150] [10.38.151.150]) by mail02.kamome.nec.co.jp with ESMTP id BT-MMP-9557864; Wed, 16 Oct 2019 17:54:01 +0900 Received: from BPXM23GP.gisp.nec.co.jp ([10.38.151.215]) by BPXC22GP.gisp.nec.co.jp ([10.38.151.150]) with mapi id 14.03.0439.000; Wed, 16 Oct 2019 17:54:00 +0900 From: Naoya Horiguchi To: David Hildenbrand CC: "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 Thread-Topic: [PATCH] mm, soft-offline: convert parameter to pfn Thread-Index: AQHVg/CjSPbKnBteSU6QJtzEs3jIHKdcT6KAgAAIvQCAAAIIAIAABVeA Date: Wed, 16 Oct 2019 08:54:00 +0000 Message-ID: <20191016085359.GD13770@hori.linux.bs1.fc.nec.co.jp> References: <20191016070924.GA10178@hori.linux.bs1.fc.nec.co.jp> <20191016082735.GB13770@hori.linux.bs1.fc.nec.co.jp> In-Reply-To: Accept-Language: en-US, ja-JP Content-Language: ja-JP X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.34.125.150] Content-Type: text/plain; charset="iso-2022-jp" Content-ID: <91064F69C753194DB32F7FEE60BAE5C4@gisp.nec.co.jp> Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-TM-AS-MML: disable 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: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()). > > > > > @@ -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). */ > > + if (!pfn_to_online_page(pfn)) > > + return -EIO; > > + page = pfn_to_page(pfn); > > if (is_zone_device_page(page)) { > > pr_debug_ratelimited("soft_offline: %#lx page is device page\n", > > pfn); > > -- > > > > Or we might have an option to do as memory_failure() does like below: > > In contrast to soft offlining, memory failure can deal with devmem. So I > think the above makes sense. OK, so here's the revised one. Thanks, Naoya Horiguchi --- From: Naoya Horiguchi Date: Wed, 16 Oct 2019 17:00:33 +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 | 14 ++++++++++---- 4 files changed, 13 insertions(+), 12 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..bdf408d7f65c 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,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)) { pr_debug_ratelimited("soft_offline: %#lx page is device page\n", pfn); -- 2.17.1