From patchwork Fri Aug 2 15:55:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13751720 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 5D21CC3DA4A for ; Fri, 2 Aug 2024 15:56:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F37F96B008C; Fri, 2 Aug 2024 11:56:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE88F6B0092; Fri, 2 Aug 2024 11:56:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D65C66B0093; Fri, 2 Aug 2024 11:56:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B78696B008C for ; Fri, 2 Aug 2024 11:56:02 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3A64BA7DA5 for ; Fri, 2 Aug 2024 15:56:02 +0000 (UTC) X-FDA: 82407756564.08.EE27BEE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 853B11A0015 for ; Fri, 2 Aug 2024 15:56:00 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iD1CoK8y; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722614131; a=rsa-sha256; cv=none; b=RUDfiGDgYBmntL1NfpJCMCPLP8pHaU13A4uR7NN/Z4IPhUdGeTt+MSN5RgJr8R784wtOEn 5Do3lT/A/vCR5omHU9g6ZbmlMuPSUy0yVH5jvDPy3vAQy9YSIKaI7i4dD+H0wxF6E3SN5k nxFYGs4Q+IWPjal61df+k6xuNkSwOY8= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iD1CoK8y; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722614131; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bw5wWvDZXB6NwMKpULq7b52Hk472J0+TTnpqg3dn/tg=; b=h4hgQtVmWEYl4leZiZyjXGqDQFEHLEifB7+r0ycrzKf1fJT4TVVaCG3uMnowhpCJc8+BoM L9ZS/ZRZk0GwAwC4C8dQLXmPknCaKgwl03JrlQYQcNYwdJFk5D8SiwMAA1lDXWFLRUnUGF fZhHWpzokV7O1Pkd2DD5FjdtweNX48I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722614159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bw5wWvDZXB6NwMKpULq7b52Hk472J0+TTnpqg3dn/tg=; b=iD1CoK8yND4V5mBrxk2QaHXqmMGZaVxG20SVfRJw24Yqr+DOmj3x5kRJ2SQdn4biaxJBQL XDWBS0tyAdDSaJdMs3lbHR0x0hZ7BnxLc8zYaHqdKEFVw1eN6x/7JFZ0i7j8m4LtIGrJDt Gp0XS5rQ5D1Od2CaZBlyiXoRwooVrAM= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-63-0uIxfBSuNxWDrKG_hH-lfg-1; Fri, 02 Aug 2024 11:55:55 -0400 X-MC-Unique: 0uIxfBSuNxWDrKG_hH-lfg-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2085618B669A; Fri, 2 Aug 2024 15:55:53 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.113]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A8A8F3000198; Fri, 2 Aug 2024 15:55:46 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Jonathan Corbet , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , Gerald Schaefer Subject: [PATCH v1 03/11] mm/migrate: convert do_pages_stat_array() from follow_page() to folio_walk Date: Fri, 2 Aug 2024 17:55:16 +0200 Message-ID: <20240802155524.517137-4-david@redhat.com> In-Reply-To: <20240802155524.517137-1-david@redhat.com> References: <20240802155524.517137-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Stat-Signature: w8cafgckycb1w7tck4bhxh8q6mpmdnca X-Rspamd-Queue-Id: 853B11A0015 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1722614160-230319 X-HE-Meta: U2FsdGVkX1+u1Ip5wwQY8C0XGQ31r0HUHbsRUCJJ/04xgJ4/yCV0cydIion9RWyZv8xTShjHsIKnNOtg5uEgybtiuzSco4MAjYxlK9mrt+6TmeqFo8IVrONzfwHBJpFrSBtYCezupCsy8kHviJrodqLNHrdrJIJ1E/ydjaWYIMkO8YOmcp5pM9uVdCaAn1fb5OacE+yRxmdDJp4b4ycIn2xuxILBgs4ZzaTbe4eQKF6fh2C1TwnWIqd6YFNLpzRp12d6/6djPNtnjmoTlEzg+3lwh9d8qyN0LlwBTjfBtCa0Rt2fwMbYMd9mWSCpI5NWB9YXXH5N29AyxYxkwBy2xuTHh5vhXB+fr0eAjbsSuUAiNR8I8cKPmnhNbYjiITQNflpQGnpcxUgs4FcML4uX7XQLuxmSDftxv27C7ixBzmc+SRnoiRpfqgwwTcEwR2qlVSNP7USTWCDfIcKpXBnndtz/uwCSt6NUCY8OjlI88HEdx5rPPHpN4utBmP5fVKf69THRI9jocABT8Tb7qBpZ+8v1qDR/8lVyiNQ8GvSy44Cl9jpPfNAOKVox+jJQI28Bq15Zt6nDAs5mHUhu3kMSnE2i4/toLth0PpKJrb7C2T0SrtKl5k6xLDd4h4aZYfuQs5JMuDNs9RqXJPxZIMrGkhcab+TtW/2Ie8A0bOHxUt2CeynbzEFhqohkZRhGjLQdIy+YiN+7xwAwVk1KrWKMXKBbl/AnRMM3DkDCNF61JhYdq4ylt/Hrr6svcfox48GC4atm11HtB806zENf3iH+jMiZNJyPjpeU+KMTeFIuxMQkjl93hmVQPwGI6m/fg4elkZrwIE9qQdL2vVy/T18gTwg61+sRJZULzbP3DtXQA3k+2T6Jdiya1Cl60MCGCAQkZEOBFH7afBBeymY9gTY2V0pldwFghwmdbRDWl+sCrJxl8hexVYet5KDmUf/RDfnMUyrTGE2LM5FUOC/sIG/ 6mzzhjS2 QEgLnGL3oBGBt6RRXx79BtI/13JUQsKdStQXu+TP1MVl25cR3/Os+KnuZYB10vHfj+VXIDDtZ9iE5ASIb0sou3jivl4BDVJ5Ywt6rwiFZliUy77JC35rySRGxylSCGbEd5Ft+5dStWN6lPF3gVae+R3nF6wd/T2W7Bm1y0LzBZSDgw5cteeGPOWouNvt3Gp2q6LI13KPDmEm8ru/TUMwzEt8eB+pUYmCLxMYTJB2oRWnhHbt6tciIHau39S86Arz2VXkmeJ7D6j1kOwSr/Zxx1P7odlWlJC7bZ7iAKAnfyt23+mFJ/6cwtPm2mGueqz76n79KVd/WoUNE1BIsJ9/61OoXnw== 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: List-Subscribe: List-Unsubscribe: Let's use folio_walk instead, so we can avoid taking a folio reference just to read the nid and get rid of another follow_page()/FOLL_DUMP user. Use FW_ZEROPAGE so we can return "-EFAULT" for it as documented. The possible return values for follow_page() were confusing, especially with FOLL_DUMP set. We'll handle it like documented in the man page: * -EFAULT: This is a zero page or the memory area is not mapped by the process. * -ENOENT: The page is not present. We'll keep setting -ENOENT for ZONE_DEVICE. Maybe not the right thing to do, but it likely doesn't really matter (just like for weird devmap, whereby we fake "not present"). Note that the other errors (-EACCESS, -EBUSY, -EIO, -EINVAL, -ENOMEM) so far only applied when actually moving pages, not when only querying stats. We'll effectively drop the "secretmem" check we had in follow_page(), but that shouldn't really matter here, we're not accessing folio/page content after all. Signed-off-by: David Hildenbrand --- mm/migrate.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index aa482c954cb0..b5365a434ba9 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -50,6 +50,7 @@ #include #include #include +#include #include @@ -2331,28 +2332,26 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages, for (i = 0; i < nr_pages; i++) { unsigned long addr = (unsigned long)(*pages); struct vm_area_struct *vma; - struct page *page; + struct folio_walk fw; + struct folio *folio; int err = -EFAULT; vma = vma_lookup(mm, addr); if (!vma) goto set_status; - /* FOLL_DUMP to ignore special (like zero) pages */ - page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP); - - err = PTR_ERR(page); - if (IS_ERR(page)) - goto set_status; - - err = -ENOENT; - if (!page) - goto set_status; - - if (!is_zone_device_page(page)) - err = page_to_nid(page); - - put_page(page); + folio = folio_walk_start(&fw, vma, addr, FW_ZEROPAGE); + if (folio) { + if (is_zero_folio(folio) || is_huge_zero_folio(folio)) + err = -EFAULT; + else if (folio_is_zone_device(folio)) + err = -ENOENT; + else + err = folio_nid(folio); + folio_walk_end(&fw, vma); + } else { + err = -ENOENT; + } set_status: *status = err;