Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4378650ybl; Mon, 9 Dec 2019 09:49:41 -0800 (PST) X-Google-Smtp-Source: APXvYqzYB6HRqQXk1V0+4uzpR/x1rI0BDf5jsPidzK21n0CvCzmqKNzSRyj6I/9FivaGY0463Am4 X-Received: by 2002:a9d:75da:: with SMTP id c26mr22729471otl.40.1575913781316; Mon, 09 Dec 2019 09:49:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575913781; cv=none; d=google.com; s=arc-20160816; b=jZZrlVIyBFHasuRVSJSDFg79Nf999mTeko2jBV/m9DmMiK5GIQeWNhcbPEOKhRCyI/ kokrNW/UWc+ZycqJeAHtUYgIzsnIGzNoxAj2dx8z31yL36LVS3M9XeNYVQYJ5KXU6WYn QTPqDxVd9Tqvz6W+NTDvhb1Td7SWdE5ZRORTF7olp0TPb4v88C4KFvkiNOBf7WhGoHcN HLMmBXIhFuBaEVeJV83wzfH7n0o6GPQSC9BqoaESEOEXWI6FCrmlTWlarjCrDwOthIP4 Wio5IQCbN0U/6OCn7iGdVhfqWA/S0qFtuuygviaz6KVfphXiLV28d6R/Vb3gRGbllbKF WS/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Lt4hpqX7ZVZhkeNrxUdXUCr9dF2T52+7cfTs1UM8LG0=; b=EijkVj5izD7fm+F32f09gC7KkwPODT2cu9VmmQzG52uvhbD75AAa6LehiNQ3pr3aay MdNYCsRP+HHcrT1iFV0i4GH5paz2nk9BWC7dAAdwtWveNgOXtq+imaHWz7+R8Fr/+Pjv VTdxqcKv9xP97c55JvJr5UEOBpe0oUE3zayz9ezPtRwJT2jFb7B/PbHdR8rg4TLyNlm8 Z5gzwTVksPVh31DM9MzlRQJGSNGVojK7kUKAuFvUpqX5HiWyVUWQCNnuqVZDnEwsns21 TKRyswcwlsGq8aBmAJcKG1XgYSes1pzGrETL8IbwIb2vM9o5NLjHLS0exNwaBcgHxTeM Q7Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="WGX/N+4n"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y11si265690oiy.210.2019.12.09.09.49.30; Mon, 09 Dec 2019 09:49:41 -0800 (PST) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="WGX/N+4n"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726884AbfLIRs6 (ORCPT + 99 others); Mon, 9 Dec 2019 12:48:58 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:43475 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726509AbfLIRsw (ORCPT ); Mon, 9 Dec 2019 12:48:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575913731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lt4hpqX7ZVZhkeNrxUdXUCr9dF2T52+7cfTs1UM8LG0=; b=WGX/N+4n8AGH6z+HJ3Z9lJFTBviXiE8dpGYDU5/cp2LCJyalzpTKQFk7khfJAHlxkMloG+ Ub4CJeKSOJCcwM0PXhKvGPVwgh67AENExJ6BpefrcemTRZlab28GJmtWZWZHveX/eEKSVe ipn3gUhZOEJDIUnSyZQxtG5hfZdtC94= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-127-WurNm-wkPmmW_qXyqjEgnA-1; Mon, 09 Dec 2019 12:48:49 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 08BAB107ACC9; Mon, 9 Dec 2019 17:48:48 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-214.ams2.redhat.com [10.36.116.214]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD7121001B03; Mon, 9 Dec 2019 17:48:45 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Alexey Dobriyan , Andrew Morton , Oscar Salvador , Michal Hocko , Stephen Rothwell , linux-fsdevel@vger.kernel.org Subject: [PATCH v1 2/3] fs/proc/page.c: allow inspection of last section and fix end detection Date: Mon, 9 Dec 2019 18:48:35 +0100 Message-Id: <20191209174836.11063-3-david@redhat.com> In-Reply-To: <20191209174836.11063-1-david@redhat.com> References: <20191209174836.11063-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: WurNm-wkPmmW_qXyqjEgnA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If max_pfn does not fall onto a section boundary, it is possible to inspect PFNs up to max_pfn, and PFNs above max_pfn, however, max_pfn itself can't be inspected. We can have a valid (and online) memmap at and above max_pfn if max_pfn is not aligned to a section boundary. The whole early section has a memmap and is marked online. Being able to inspect the state of these PFNs is valuable for debugging, especially because max_pfn can change on memory hotplug and expose these memmaps. Also, querying page flags via "./page-types -r -a 0x144001," (tools/vm/page-types.c) inside a x86-64 guest with 4160MB under QEMU results in an (almost) endless loop in user space, because the end is not detected properly when starting after max_pfn. Instead, let's allow to inspect all pages in the highest section and return 0 directly if we try to access pages above that section. While at it, check the count before adjusting it, to avoid masking user errors. Cc: Alexey Dobriyan Cc: Andrew Morton Cc: Oscar Salvador Cc: Michal Hocko Cc: Stephen Rothwell Cc: linux-fsdevel@vger.kernel.org Signed-off-by: David Hildenbrand --- fs/proc/page.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fs/proc/page.c b/fs/proc/page.c index e40dbfe1168e..da01d3d9999a 100644 --- a/fs/proc/page.c +++ b/fs/proc/page.c @@ -29,6 +29,7 @@ static ssize_t kpagecount_read(struct file *file, char __user *buf, =09=09=09 size_t count, loff_t *ppos) { +=09const unsigned long max_dump_pfn =3D round_up(max_pfn, PAGES_PER_SECTIO= N); =09u64 __user *out =3D (u64 __user *)buf; =09struct page *ppage; =09unsigned long src =3D *ppos; @@ -37,9 +38,11 @@ static ssize_t kpagecount_read(struct file *file, char _= _user *buf, =09u64 pcount; =20 =09pfn =3D src / KPMSIZE; -=09count =3D min_t(size_t, count, (max_pfn * KPMSIZE) - src); =09if (src & KPMMASK || count & KPMMASK) =09=09return -EINVAL; +=09if (src >=3D max_dump_pfn * KPMSIZE) +=09=09return 0; +=09count =3D min_t(unsigned long, count, (max_dump_pfn * KPMSIZE) - src); =20 =09while (count > 0) { =09=09/* @@ -208,6 +211,7 @@ u64 stable_page_flags(struct page *page) static ssize_t kpageflags_read(struct file *file, char __user *buf, =09=09=09 size_t count, loff_t *ppos) { +=09const unsigned long max_dump_pfn =3D round_up(max_pfn, PAGES_PER_SECTIO= N); =09u64 __user *out =3D (u64 __user *)buf; =09struct page *ppage; =09unsigned long src =3D *ppos; @@ -215,9 +219,11 @@ static ssize_t kpageflags_read(struct file *file, char= __user *buf, =09ssize_t ret =3D 0; =20 =09pfn =3D src / KPMSIZE; -=09count =3D min_t(unsigned long, count, (max_pfn * KPMSIZE) - src); =09if (src & KPMMASK || count & KPMMASK) =09=09return -EINVAL; +=09if (src >=3D max_dump_pfn * KPMSIZE) +=09=09return 0; +=09count =3D min_t(unsigned long, count, (max_dump_pfn * KPMSIZE) - src); =20 =09while (count > 0) { =09=09/* @@ -253,6 +259,7 @@ static const struct file_operations proc_kpageflags_ope= rations =3D { static ssize_t kpagecgroup_read(struct file *file, char __user *buf, =09=09=09=09size_t count, loff_t *ppos) { +=09const unsigned long max_dump_pfn =3D round_up(max_pfn, PAGES_PER_SECTIO= N); =09u64 __user *out =3D (u64 __user *)buf; =09struct page *ppage; =09unsigned long src =3D *ppos; @@ -261,9 +268,11 @@ static ssize_t kpagecgroup_read(struct file *file, cha= r __user *buf, =09u64 ino; =20 =09pfn =3D src / KPMSIZE; -=09count =3D min_t(unsigned long, count, (max_pfn * KPMSIZE) - src); =09if (src & KPMMASK || count & KPMMASK) =09=09return -EINVAL; +=09if (src >=3D max_dump_pfn * KPMSIZE) +=09=09return 0; +=09count =3D min_t(unsigned long, count, (max_dump_pfn * KPMSIZE) - src); =20 =09while (count > 0) { =09=09/* --=20 2.21.0