Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1140571ybg; Fri, 18 Oct 2019 12:41:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkvg/Tqj50t6+e2JVc8jLYYP3RYnPjU3rVmxFISzxwWSMnWkkPzlXdhSmKQAQ+Yejtl7LW X-Received: by 2002:a50:ec91:: with SMTP id e17mr11320502edr.169.1571427700478; Fri, 18 Oct 2019 12:41:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571427700; cv=none; d=google.com; s=arc-20160816; b=yCwRJ527BpMaHeAWUjsTD//p6+J9FVlCIUzeT0Rsf1N0iaG8GZZvBoEEEc0ME9VLM+ ++RVozxbJwsh139c2CX4KqolLj9zD7KK19Ko5Pzz9Bt11KexYOjWdxqT5r+ppYwd1nSr h+YrR/BTjVf2gHC82nGHLOWhzxAUP8F+Xh03wj2VZhc80kbIa5QY7BLytmF0S67AbJVF vUgC7UOxxiOZxu+nqRm5MIXxNWxud/CLU8HiZzaap7AqPNFECv4A5TtG90/dOMOiumkW cDqNyZHYMX46Xh3mz5h74++CUDuv/U57VbNt6n4CAOeMs7ke3s7u15uqnB/o2Wl18PBK U6hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=MBg/HqHsz8wWc2Iqpf+I/pjhCC498grAkatHREwF8Nk=; b=RtKEZWl27yTcwEGcedaFIUVjzc+mM5cUjuHo3gJKP8CJNE919wkJU1WiGT6+4Y//ph /EmsV3eIjoazXhXRxsIiiUs8LHEi1YxrY+HiS8CJVBqjQoYmiCqpQaEEXsvXWTwGB2bq NeXADIMG5umfc2i9eN/nTqEMl7Tx98DQxbHt1u/0V28yV1I6y0E9a9NDhXienvOhnsSQ QJJHa6ZarBpRDumQ5fEF6ec33kn0P16OYc33mE+IeLU+NK/bzwJ/Me3S/hcy9KWRH5/Q E2lm/hX3r1l0/ueZm7IZOLUEmlUcb00M+q667/hf2p1QrSouckrS6Inpz+j8i5cKeQSU 350w== 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 26si4651738ejl.292.2019.10.18.12.41.17; Fri, 18 Oct 2019 12:41:40 -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 S2440153AbfJQOWA (ORCPT + 99 others); Thu, 17 Oct 2019 10:22:00 -0400 Received: from mx2.suse.de ([195.135.220.15]:40804 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2440097AbfJQOVk (ORCPT ); Thu, 17 Oct 2019 10:21:40 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9F88DB4C5; Thu, 17 Oct 2019 14:21:38 +0000 (UTC) From: Oscar Salvador To: n-horiguchi@ah.jp.nec.com Cc: mhocko@kernel.org, mike.kravetz@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [RFC PATCH v2 16/16] mm, soft-offline: convert parameter to pfn Date: Thu, 17 Oct 2019 16:21:23 +0200 Message-Id: <20191017142123.24245-17-osalvador@suse.de> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20191017142123.24245-1-osalvador@suse.de> References: <20191017142123.24245-1-osalvador@suse.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Naoya Horiguchi 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 Signed-off-by: Oscar Salvador --- drivers/base/memory.c | 7 +------ include/linux/mm.h | 2 +- mm/madvise.c | 2 +- mm/memory-failure.c | 17 +++++++++-------- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index b3cae2eb1c4f..b510b4d176c9 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)); + ret = soft_offline_page(pfn); return ret == 0 ? count : ret; } diff --git a/include/linux/mm.h b/include/linux/mm.h index 0f80a1ce4e86..40722854d357 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2791,7 +2791,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); +extern int soft_offline_page(unsigned long pfn); /* diff --git a/mm/madvise.c b/mm/madvise.c index 9ca48345ce45..f83b7d4c68c1 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -890,7 +890,7 @@ static int madvise_inject_error(int behavior, if (behavior == MADV_SOFT_OFFLINE) { pr_info("Soft offlining pfn %#lx at process virtual address %#lx\n", pfn, start); - ret = soft_offline_page(page); + ret = soft_offline_page(pfn); } else { pr_info("Injecting memory failure for pfn %#lx at process virtual address %#lx\n", pfn, start); diff --git a/mm/memory-failure.c b/mm/memory-failure.c index c038896bedf0..bfecb61fc064 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1521,7 +1521,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)); + soft_offline_page(entry.pfn); else memory_failure(entry.pfn, entry.flags); } @@ -1834,7 +1834,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 * * Returns 0 on success, otherwise negated errno. * @@ -1853,16 +1853,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 soft_offline_page(unsigned long pfn) { 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 (!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.12.3