From patchwork Sun Jan 9 13:05:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiongwei Song X-Patchwork-Id: 12707770 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D734C433F5 for ; Sun, 9 Jan 2022 13:05:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 952896B0073; Sun, 9 Jan 2022 08:05:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D9F46B0074; Sun, 9 Jan 2022 08:05:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77AD06B0075; Sun, 9 Jan 2022 08:05:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0109.hostedemail.com [216.40.44.109]) by kanga.kvack.org (Postfix) with ESMTP id 66DD56B0073 for ; Sun, 9 Jan 2022 08:05:48 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 19A32181CAEF0 for ; Sun, 9 Jan 2022 13:05:48 +0000 (UTC) X-FDA: 79010770776.03.2F26404 Received: from pv50p00im-hyfv10011601.me.com (pv50p00im-hyfv10011601.me.com [17.58.6.43]) by imf05.hostedemail.com (Postfix) with ESMTP id 6229C100003 for ; Sun, 9 Jan 2022 13:05:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1641733546; bh=g6L+kqSc5f6G0SvO3Njd2vpwSi2vmrKCjGly4UmhZ9c=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=RMyeKdCSTClAxoIfpApVBBCKB9wmAQbdhhR0xOTC5ADL/bXfYg4JWD5U8l9f0k0Z4 gBSzZUgxRr0RIfL/QOQHWG9wrA8sD5As9lbzONjP/gDwjM7CmHkV5IXYFyb1Tjjxj3 hFvg1hNQ8U+3MwUk1i6HxZF1grjzFCWkGDmuM8h7wC2Xtz/Zb6AecWSojTBwD3ph3h OuFBRlPm4H5WYQdX6HgFgm+brakks0vby/hS3EtwuFxN2rqRrWjWB3Q0m0MbrS3jQI gzOxg0eodmL5rl+gZ9PEvagHab4LlWkQudY3bh0cbi5LodwcwMQA2QcmEM8S4obwB3 WYBH4fznkhbeg== Received: from xiongwei.. (unknown [120.245.2.119]) by pv50p00im-hyfv10011601.me.com (Postfix) with ESMTPSA id B282896022F; Sun, 9 Jan 2022 13:05:41 +0000 (UTC) From: sxwjean@me.com To: akpm@linux-foundation.org, david@redhat.com, mhocko@suse.com, dan.j.williams@intel.com, osalvador@suse.de, naoya.horiguchi@nec.com, thunder.leizhen@huawei.com Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Xiongwei Song Subject: [PATCH 1/2] mm/memremap.c: Add pfn_to_devmap_page() to get page in ZONE_DEVICE Date: Sun, 9 Jan 2022 21:05:14 +0800 Message-Id: <20220109130515.140092-2-sxwjean@me.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220109130515.140092-1-sxwjean@me.com> References: <20220109130515.140092-1-sxwjean@me.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.790 definitions=2022-01-09_04:2022-01-06,2022-01-09 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=785 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-2009150000 definitions=main-2201090096 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 6229C100003 X-Stat-Signature: u7y5bgqyuot9xdm583bh98e51kx3wnhx Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=me.com header.s=1a1hai header.b=RMyeKdCS; spf=pass (imf05.hostedemail.com: domain of sxwjean@me.com designates 17.58.6.43 as permitted sender) smtp.mailfrom=sxwjean@me.com; dmarc=pass (policy=quarantine) header.from=me.com X-HE-Tag: 1641733547-919097 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: From: Xiongwei Song when requesting page information by /proc/kpage*, the pages in ZONE_DEVICE were missed. We need a function to help on this. The pfn_to_devmap_page() function like pfn_to_online_page(), but only concerns the pages in ZONE_DEVICE. Signed-off-by: Xiongwei Song --- include/linux/memremap.h | 8 ++++++++ mm/memremap.c | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/include/linux/memremap.h b/include/linux/memremap.h index c0e9d35889e8..621723e9c4a5 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -137,6 +137,8 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap); void devm_memunmap_pages(struct device *dev, struct dev_pagemap *pgmap); struct dev_pagemap *get_dev_pagemap(unsigned long pfn, struct dev_pagemap *pgmap); +struct page *pfn_to_devmap_page(unsigned long pfn, + struct dev_pagemap **pgmap); bool pgmap_pfn_valid(struct dev_pagemap *pgmap, unsigned long pfn); unsigned long vmem_altmap_offset(struct vmem_altmap *altmap); @@ -166,6 +168,12 @@ static inline struct dev_pagemap *get_dev_pagemap(unsigned long pfn, return NULL; } +static inline struct page *pfn_to_devmap_page(unsigned long pfn, + struct dev_pagemap **pgmap) +{ + return NULL; +} + static inline bool pgmap_pfn_valid(struct dev_pagemap *pgmap, unsigned long pfn) { return false; diff --git a/mm/memremap.c b/mm/memremap.c index 5a66a71ab591..072dbe6ab81c 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -494,6 +494,48 @@ struct dev_pagemap *get_dev_pagemap(unsigned long pfn, } EXPORT_SYMBOL_GPL(get_dev_pagemap); +/** + * pfn_to_devmap_page - get page pointer which belongs to dev_pagemap by @pfn + * @pfn: page frame number to lookup page_map + * @pgmap: to save pgmap address which is for putting reference + * + * If @pgmap is non-NULL, then pfn is on ZONE_DEVICE and return page pointer. + */ +struct page *pfn_to_devmap_page(unsigned long pfn, struct dev_pagemap **pgmap) +{ + unsigned long nr = pfn_to_section_nr(pfn); + struct mem_section *ms; + struct page *page = NULL; + + if (nr >= NR_MEM_SECTIONS) + return NULL; + + if (IS_ENABLED(CONFIG_HAVE_ARCH_PFN_VALID) && !pfn_valid(pfn)) + return NULL; + + ms = __nr_to_section(nr); + if (!valid_section(ms)) + return NULL; + if (!pfn_section_valid(ms, pfn)) + return NULL; + + /* + * Two types of sections may include valid pfns: + * - The pfns of section belong to ZONE_DEVICE and ZONE_{NORMAL,MOVABLE} + * at the same time. + * - All pfns in one section are offline but valid. + */ + if (!online_device_section(ms) && online_section(ms)) + return NULL; + + *pgmap = get_dev_pagemap(pfn, NULL); + if (*pgmap) + page = pfn_to_page(pfn); + + return page; +} +EXPORT_SYMBOL_GPL(pfn_to_devmap_page); + #ifdef CONFIG_DEV_PAGEMAP_OPS void free_devmap_managed_page(struct page *page) { From patchwork Sun Jan 9 13:05:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiongwei Song X-Patchwork-Id: 12707771 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 794F9C433EF for ; Sun, 9 Jan 2022 13:05:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 112CF6B0074; Sun, 9 Jan 2022 08:05:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 09C406B0075; Sun, 9 Jan 2022 08:05:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E58696B0078; Sun, 9 Jan 2022 08:05:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0219.hostedemail.com [216.40.44.219]) by kanga.kvack.org (Postfix) with ESMTP id D55766B0074 for ; Sun, 9 Jan 2022 08:05:54 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 986FD978FC for ; Sun, 9 Jan 2022 13:05:54 +0000 (UTC) X-FDA: 79010771028.26.BD9AFA9 Received: from pv50p00im-hyfv10011601.me.com (pv50p00im-hyfv10011601.me.com [17.58.6.43]) by imf06.hostedemail.com (Postfix) with ESMTP id 200CB18000A for ; Sun, 9 Jan 2022 13:05:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1641733553; bh=9XqLQAg2WYNjySdUZ9g0g99XYS7qmt4n0TDjaRPnSgk=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=PUyV3NOZj+akieY/PAdt+rSI2U4GS49Lg2zTR292RohKAonX1oUma986j+2IY+9CC NancyU0X6guoMLp/6igw8BEHiLrdpC4PXMiWPm1r3SNwl/T5tV2JLltMuOpKOD7R4m cfXYhDnjXVAK/7xAcTCUrps5hsiGzBhTlqle+PJrYK/1mQqguJk4kbZ+Fi/hVFH9k0 DwOV+Z9yV6HbQkoLxxa62BwkYTi6XR94zaAkmEpVmEhBsuL3HZU5cvmvQI8UYBWA95 DDn6iV2j3dJYe3UQnXxq3WWruV5dU0gKpRuvFCKD1GXtMCKigoTKk6+WAE5qjh91NF c2nsQ11po2ubg== Received: from xiongwei.. (unknown [120.245.2.119]) by pv50p00im-hyfv10011601.me.com (Postfix) with ESMTPSA id 9219E960270; Sun, 9 Jan 2022 13:05:48 +0000 (UTC) From: sxwjean@me.com To: akpm@linux-foundation.org, david@redhat.com, mhocko@suse.com, dan.j.williams@intel.com, osalvador@suse.de, naoya.horiguchi@nec.com, thunder.leizhen@huawei.com Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Xiongwei Song Subject: [PATCH 2/2] proc: Add getting pages info of ZONE_DEVICE support Date: Sun, 9 Jan 2022 21:05:15 +0800 Message-Id: <20220109130515.140092-3-sxwjean@me.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220109130515.140092-1-sxwjean@me.com> References: <20220109130515.140092-1-sxwjean@me.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.790 definitions=2022-01-09_04:2022-01-06,2022-01-09 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=798 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-2009150000 definitions=main-2201090096 X-Stat-Signature: zze36rt37jgikrrr4jfnc3ga8ggw58ia X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 200CB18000A Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=me.com header.s=1a1hai header.b=PUyV3NOZ; spf=pass (imf06.hostedemail.com: domain of sxwjean@me.com designates 17.58.6.43 as permitted sender) smtp.mailfrom=sxwjean@me.com; dmarc=pass (policy=quarantine) header.from=me.com X-HE-Tag: 1641733553-317770 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: From: Xiongwei Song When requesting pages info by /proc/kpage*, the pages in ZONE_DEVICE were missed. The pfn_to_devmap_page() function can help to get page that belongs to ZONE_DEVICE. Signed-off-by: Xiongwei Song --- fs/proc/page.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/fs/proc/page.c b/fs/proc/page.c index 9f1077d94cde..2cdc2b315ff8 100644 --- a/fs/proc/page.c +++ b/fs/proc/page.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "internal.h" #define KPMSIZE sizeof(u64) @@ -46,6 +47,7 @@ static ssize_t kpagecount_read(struct file *file, char __user *buf, { const unsigned long max_dump_pfn = get_max_dump_pfn(); u64 __user *out = (u64 __user *)buf; + struct dev_pagemap *pgmap = NULL; struct page *ppage; unsigned long src = *ppos; unsigned long pfn; @@ -60,17 +62,18 @@ static ssize_t kpagecount_read(struct file *file, char __user *buf, count = min_t(unsigned long, count, (max_dump_pfn * KPMSIZE) - src); while (count > 0) { - /* - * TODO: ZONE_DEVICE support requires to identify - * memmaps that were actually initialized. - */ ppage = pfn_to_online_page(pfn); + if (!ppage) + ppage = pfn_to_devmap_page(pfn, &pgmap); if (!ppage || PageSlab(ppage) || page_has_type(ppage)) pcount = 0; else pcount = page_mapcount(ppage); + if (pgmap) + put_dev_pagemap(pgmap); + if (put_user(pcount, out)) { ret = -EFAULT; break; @@ -229,10 +232,12 @@ static ssize_t kpageflags_read(struct file *file, char __user *buf, { const unsigned long max_dump_pfn = get_max_dump_pfn(); u64 __user *out = (u64 __user *)buf; + struct dev_pagemap *pgmap = NULL; struct page *ppage; unsigned long src = *ppos; unsigned long pfn; ssize_t ret = 0; + u64 flags; pfn = src / KPMSIZE; if (src & KPMMASK || count & KPMMASK) @@ -242,13 +247,15 @@ static ssize_t kpageflags_read(struct file *file, char __user *buf, count = min_t(unsigned long, count, (max_dump_pfn * KPMSIZE) - src); while (count > 0) { - /* - * TODO: ZONE_DEVICE support requires to identify - * memmaps that were actually initialized. - */ ppage = pfn_to_online_page(pfn); + if (!ppage) + ppage = pfn_to_devmap_page(pfn, &pgmap); + + flags = stable_page_flags(ppage); + if (pgmap) + put_dev_pagemap(pgmap); - if (put_user(stable_page_flags(ppage), out)) { + if (put_user(flags, out)) { ret = -EFAULT; break; } @@ -277,6 +284,7 @@ static ssize_t kpagecgroup_read(struct file *file, char __user *buf, { const unsigned long max_dump_pfn = get_max_dump_pfn(); u64 __user *out = (u64 __user *)buf; + struct dev_pagemap *pgmap = NULL; struct page *ppage; unsigned long src = *ppos; unsigned long pfn; @@ -291,17 +299,18 @@ static ssize_t kpagecgroup_read(struct file *file, char __user *buf, count = min_t(unsigned long, count, (max_dump_pfn * KPMSIZE) - src); while (count > 0) { - /* - * TODO: ZONE_DEVICE support requires to identify - * memmaps that were actually initialized. - */ ppage = pfn_to_online_page(pfn); + if (!ppage) + ppage = pfn_to_devmap_page(pfn, &pgmap); if (ppage) ino = page_cgroup_ino(ppage); else ino = 0; + if (pgmap) + put_dev_pagemap(pgmap); + if (put_user(ino, out)) { ret = -EFAULT; break;