From nobody Sat Feb 7 18:21:17 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBFB023C9 for ; Mon, 7 Apr 2025 03:03:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743995022; cv=none; b=DJo5o58A1LHieUt57/leoFK23IkwnuAm6L2Xsxn2NYoYat8ODaKLdt1PQuCKScXque0sQjRRPG7s3/e/LWlK2xyzKaJkngpwnAzh8B6Xik45Obk992KfVQfc/PBsa1KN1Rc0yeEjvY/0LYY/U3r0s0MyrxXfvW1Yy0bhtZ/oUP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743995022; c=relaxed/simple; bh=anoOtA7y6qgnrIh5JPM+glc+gVVqyk36QYkbNJhTtw4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=Ax+DmsbRpEDx5QzUOkg8jxuzZ4M1O7aEfasOxccFOKjMHFha+YDnhCY1zTwwd6GGKJto38J+QonJdA3aRFRnsWXaCfx9UskPMjzFBCf69/8/2M6fhE2Qi+Q1MT5T1vlSRlb9W5zTVULFU/z5ed3ZIHMqJndFSyuA8iXERVitETo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=byuPrl9e; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="byuPrl9e" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1743995019; 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=WfJMyqNy/t97b+P9yQjERuT06PZQ+0TGu1JM+vWKq/A=; b=byuPrl9ej57u6zLBLJG+pQMTXCNTQB/cstSWhkhAWT9j0QBTAmeYqH4+YwdvRqGfYlsodP 7tT+Q2BykVG4k3D6XYJ/yis1uJlRHRUHAt2D6EDzNXPDNZkA86k/EpyQrVKhOZGECbOaLh 07+zjJ+sGOCetPXYuCmAOoOETxs3x6c= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-464-7xi461BqNpmUQhAB1YDcFg-1; Sun, 06 Apr 2025 23:03:36 -0400 X-MC-Unique: 7xi461BqNpmUQhAB1YDcFg-1 X-Mimecast-MFC-AGG-ID: 7xi461BqNpmUQhAB1YDcFg_1743995015 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C6BB1180AF56; Mon, 7 Apr 2025 03:03:34 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.15]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3ECF51801752; Mon, 7 Apr 2025 03:03:28 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, osalvador@suse.de, david@redhat.com, mingo@kernel.org, yanjun.zhu@linux.dev, linux-kernel@vger.kernel.org, Baoquan He Subject: [PATCH v3 1/3] mm/gup: fix wrongly calculated returned value in fault_in_safe_writeable() Date: Mon, 7 Apr 2025 11:03:04 +0800 Message-ID: <20250407030306.411977-2-bhe@redhat.com> In-Reply-To: <20250407030306.411977-1-bhe@redhat.com> References: <20250407030306.411977-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Type: text/plain; charset="utf-8" Not like fault_in_readable() or fault_in_writeable(), in fault_in_safe_writeable() local variable 'start' is increased page by page to loop till the whole address range is handled. However, it mistakenly calcalates the size of handled range with 'uaddr - start'. Here fix the code bug in fault_in_safe_writeable(), and also adjusting the codes in fault_in_readable() and fault_in_writeable() to use local variable 'start' to loop so that codes in these three functions are consistent. Signed-off-by: Baoquan He --- mm/gup.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 92351e2fa876..67a7de9e4f80 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2114,7 +2114,7 @@ static long __get_user_pages_locked(struct mm_struct = *mm, unsigned long start, */ size_t fault_in_writeable(char __user *uaddr, size_t size) { - char __user *start =3D uaddr, *end; + unsigned long start =3D (unsigned long)uaddr, end; =20 if (unlikely(size =3D=3D 0)) return 0; @@ -2122,20 +2122,20 @@ size_t fault_in_writeable(char __user *uaddr, size_= t size) return size; if (!PAGE_ALIGNED(uaddr)) { unsafe_put_user(0, uaddr, out); - uaddr =3D (char __user *)PAGE_ALIGN((unsigned long)uaddr); + start =3D PAGE_ALIGN((unsigned long)uaddr); } - end =3D (char __user *)PAGE_ALIGN((unsigned long)start + size); + end =3D PAGE_ALIGN(start + size); if (unlikely(end < start)) - end =3D NULL; - while (uaddr !=3D end) { - unsafe_put_user(0, uaddr, out); - uaddr +=3D PAGE_SIZE; + end =3D 0; + while (start !=3D end) { + unsafe_put_user(0, (char __user *)start, out); + start +=3D PAGE_SIZE; } =20 out: user_write_access_end(); - if (size > uaddr - start) - return size - (uaddr - start); + if (size > start - (unsigned long)uaddr) + return size - (start - (unsigned long)uaddr); return 0; } EXPORT_SYMBOL(fault_in_writeable); @@ -2207,8 +2207,8 @@ size_t fault_in_safe_writeable(const char __user *uad= dr, size_t size) } while (start !=3D end); mmap_read_unlock(mm); =20 - if (size > (unsigned long)uaddr - start) - return size - ((unsigned long)uaddr - start); + if (size > start - (unsigned long)uaddr) + return size - (start - (unsigned long)uaddr); return 0; } EXPORT_SYMBOL(fault_in_safe_writeable); @@ -2223,7 +2223,7 @@ EXPORT_SYMBOL(fault_in_safe_writeable); */ size_t fault_in_readable(const char __user *uaddr, size_t size) { - const char __user *start =3D uaddr, *end; + unsigned long start =3D (unsigned long)uaddr, end; volatile char c; =20 if (unlikely(size =3D=3D 0)) @@ -2232,21 +2232,21 @@ size_t fault_in_readable(const char __user *uaddr, = size_t size) return size; if (!PAGE_ALIGNED(uaddr)) { unsafe_get_user(c, uaddr, out); - uaddr =3D (const char __user *)PAGE_ALIGN((unsigned long)uaddr); + start =3D PAGE_ALIGN((unsigned long)uaddr); } - end =3D (const char __user *)PAGE_ALIGN((unsigned long)start + size); + end =3D PAGE_ALIGN(start + size); if (unlikely(end < start)) - end =3D NULL; - while (uaddr !=3D end) { - unsafe_get_user(c, uaddr, out); - uaddr +=3D PAGE_SIZE; + end =3D 0; + while (start !=3D end) { + unsafe_get_user(c, (const char __user *)start, out); + start +=3D PAGE_SIZE; } =20 out: user_read_access_end(); (void)c; - if (size > uaddr - start) - return size - (uaddr - start); + if (size > start - (unsigned long)uaddr) + return size - (start - (unsigned long)uaddr); return 0; } EXPORT_SYMBOL(fault_in_readable); --=20 2.41.0 From nobody Sat Feb 7 18:21:17 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD3C5212F8A for ; Mon, 7 Apr 2025 03:03:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743995031; cv=none; b=Hg5f/xaxtEVSLFbSBMTAUAH/Ysq6PLTmeWF4s7xxE4D918CVw+JeZDM1C5+iaWOBENYNu9TJn9/d+mnFTU6kfHghjMo/iubndXYVbM+7m6o+F8FziGO1A/LnmbRYCqV14IvuLdbI8vSs5b/VVbPcW/sWSiNvC675df6X87ctC2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743995031; c=relaxed/simple; bh=2iHESdN5CAJpKUIN9UWdXRao4XpqXuVxxqv0vjsjzdc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=ky0UjjbDNN5W5geuIkCn1Sgs361lhI4D85eyFUI0fSHC0chavLNlFJdb8XQavkm6/p+d937Q/Cw+PituIRBlx+jiwXRS+EMY8L79jMnPkJv4Yt2Ogin39RszUMjqljoqR5Gkdyv7w2cdTytKKR2QmuCYasAM9u6aVRveTcfZBWI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CcMz63xH; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CcMz63xH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1743995028; 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=bJ2k0hP9st8IhgiofWedxfuUo0Bg6ypk1SRHkg21egg=; b=CcMz63xHmh5qaX3/t7MpGbeG8RqjXCRNXvofBrjokFaxw7jjgSlUd/5ULciNd4Hu0aA4SU V9ZLby2gkIo17dx0DWiITxFOIohuJJr1piED6jY2tGRPtVum6f5h/3ta4X7AdTC7QhpUk1 +tQJTVsTJoCd/RkLjOBCKX+FtXDtwGo= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-269-oMN4FsPAPlG8CptC09g51A-1; Sun, 06 Apr 2025 23:03:43 -0400 X-MC-Unique: oMN4FsPAPlG8CptC09g51A-1 X-Mimecast-MFC-AGG-ID: oMN4FsPAPlG8CptC09g51A_1743995022 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C9B701800257; Mon, 7 Apr 2025 03:03:41 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.15]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D41EF1801752; Mon, 7 Apr 2025 03:03:35 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, osalvador@suse.de, david@redhat.com, mingo@kernel.org, yanjun.zhu@linux.dev, linux-kernel@vger.kernel.org, Baoquan He Subject: [PATCH v3 2/3] mm/gup: remove unneeded checking in follow_page_pte() Date: Mon, 7 Apr 2025 11:03:05 +0800 Message-ID: <20250407030306.411977-3-bhe@redhat.com> In-Reply-To: <20250407030306.411977-1-bhe@redhat.com> References: <20250407030306.411977-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Type: text/plain; charset="utf-8" In __get_user_pages(), it will traverse page table and take a reference to the page the given user address corresponds to if GUP_GET or GUP_PIN is set. However, it's not supported both GUP_GET and GUP_PIN are set. Even though this check need be done, it should be done earlier, but not doing it till entering into follow_page_pte() and failed. Furthermore, this checking has been done in is_valid_gup_args() and all external users of __get_user_pages() will call is_valid_gup_args() to catch the illegal setting. We don't need to worry about internal users of __get_user_pages() because the gup_flags are set by MM code correctly. Here remove the checking in follow_page_pte(), and add VM_WARN_ON_ONCE() to catch the possible exceptional setting just in case. And also change the VM_BUG_ON to VM_WARN_ON_ONCE() for checking (!!pages !=3D !!(gup_flags & (FOLL_GET | FOLL_PIN))) because the checking has been done in is_valid_gup_args() for external users of __get_user_pages= (). Signed-off-by: Baoquan He Acked-by: David Hildenbrand Reviewed-by: Oscar Salvador --- mm/gup.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 67a7de9e4f80..5b3ac5a867a3 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -844,11 +844,6 @@ static struct page *follow_page_pte(struct vm_area_str= uct *vma, pte_t *ptep, pte; int ret; =20 - /* FOLL_GET and FOLL_PIN are mutually exclusive. */ - if (WARN_ON_ONCE((flags & (FOLL_PIN | FOLL_GET)) =3D=3D - (FOLL_PIN | FOLL_GET))) - return ERR_PTR(-EINVAL); - ptep =3D pte_offset_map_lock(mm, pmd, address, &ptl); if (!ptep) return no_page_table(vma, flags, address); @@ -1432,7 +1427,11 @@ static long __get_user_pages(struct mm_struct *mm, =20 start =3D untagged_addr_remote(mm, start); =20 - VM_BUG_ON(!!pages !=3D !!(gup_flags & (FOLL_GET | FOLL_PIN))); + VM_WARN_ON_ONCE(!!pages !=3D !!(gup_flags & (FOLL_GET | FOLL_PIN))); + + /* FOLL_GET and FOLL_PIN are mutually exclusive. */ + VM_WARN_ON_ONCE((gup_flags & (FOLL_PIN | FOLL_GET)) =3D=3D + (FOLL_PIN | FOLL_GET)); =20 do { struct page *page; --=20 2.41.0 From nobody Sat Feb 7 18:21:17 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B7DF2135C1 for ; Mon, 7 Apr 2025 03:03:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743995035; cv=none; b=i3Bjh5waXUzHnbU+/9s/DNdj20Yc8qDu6yKZKZyiUD5cyTrw95t6zSr/cBfM/cnP9+3LNwS/p8oSbvEXhxUpLvRRkNOdgALKCvrOYGzhCRSuQHs/CMwjW2xxYHVSiCyu8tWhVdNc7vXxc6X3hBTC/45fTWxQWqeMXPN3AfhqmAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743995035; c=relaxed/simple; bh=W4d6eMuOsoigxHaayWrDjD0luwkLz5SkUS2Jq1yPQek=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=Sy//cY2ySX84mpeWUjZhnJjsk6ZUOqXuLcqr4WFcp1RUtbh1t81CN0sDM8n+4uD9E74w45c37haVYdwJ7XYghBieQ4kY25sl+GOVPCDE/mhEbCJPV4691Y279pGrGFWZqsi8axCo5MjVRnoOr4FlitxAEtFne/dXQQv7mV282qo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=A/tnNizp; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="A/tnNizp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1743995032; 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=AQ/UrRbnj3b02IVX/znAR8Dzkmamadv/LnZeVQ24gFU=; b=A/tnNizpVacWzJ78IOw/HUXUO1yR16CY9VhExiRgprRgZrNVSaQeETnVJr1n97YPmbS/2P K9P+8y+EPbGDX9Vzm1nm+OZrjxaHqgouPMTO+NSwPrxNesrzp0rjCO+4JD0L1B6FvaFwXb b/g03lgtfVuoUnQKEVUd4PEj7Vi4hZc= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-402-_D5q2rZONMCapjucfqhvkg-1; Sun, 06 Apr 2025 23:03:49 -0400 X-MC-Unique: _D5q2rZONMCapjucfqhvkg-1 X-Mimecast-MFC-AGG-ID: _D5q2rZONMCapjucfqhvkg_1743995028 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1AA4B1800361; Mon, 7 Apr 2025 03:03:48 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.15]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CB5CC1801A6D; Mon, 7 Apr 2025 03:03:42 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, osalvador@suse.de, david@redhat.com, mingo@kernel.org, yanjun.zhu@linux.dev, linux-kernel@vger.kernel.org, Baoquan He Subject: [PATCH v3 3/3] mm/gup: remove gup_fast_pgd_leaf() and clean up the relevant codes Date: Mon, 7 Apr 2025 11:03:06 +0800 Message-ID: <20250407030306.411977-4-bhe@redhat.com> In-Reply-To: <20250407030306.411977-1-bhe@redhat.com> References: <20250407030306.411977-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Type: text/plain; charset="utf-8" In the current kernel, only pud huge page is supported in some architectures. P4d and pgd huge pages haven't been supported yet. And in mm/gup.c, there's no pgd huge page handling in the follow_page_mask() code path. Hence it doesn't make sense to only have gup_fast_pgd_leaf() in gup_fast code path. Here remove gup_fast_pgd_leaf() and clean up the relevant codes. Signed-off-by: Baoquan He Reviewed-by: Oscar Salvador Acked-by: David Hildenbrand --- mm/gup.c | 49 +++---------------------------------------------- 1 file changed, 3 insertions(+), 46 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 5b3ac5a867a3..c9237db3cdb3 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3172,46 +3172,6 @@ static int gup_fast_pud_leaf(pud_t orig, pud_t *pudp= , unsigned long addr, return 1; } =20 -static int gup_fast_pgd_leaf(pgd_t orig, pgd_t *pgdp, unsigned long addr, - unsigned long end, unsigned int flags, struct page **pages, - int *nr) -{ - int refs; - struct page *page; - struct folio *folio; - - if (!pgd_access_permitted(orig, flags & FOLL_WRITE)) - return 0; - - BUILD_BUG_ON(pgd_devmap(orig)); - - page =3D pgd_page(orig); - refs =3D record_subpages(page, PGDIR_SIZE, addr, end, pages + *nr); - - folio =3D try_grab_folio_fast(page, refs, flags); - if (!folio) - return 0; - - if (unlikely(pgd_val(orig) !=3D pgd_val(*pgdp))) { - gup_put_folio(folio, refs, flags); - return 0; - } - - if (!pgd_write(orig) && gup_must_unshare(NULL, flags, &folio->page)) { - gup_put_folio(folio, refs, flags); - return 0; - } - - if (!gup_fast_folio_allowed(folio, flags)) { - gup_put_folio(folio, refs, flags); - return 0; - } - - *nr +=3D refs; - folio_set_referenced(folio); - return 1; -} - static int gup_fast_pmd_range(pud_t *pudp, pud_t pud, unsigned long addr, unsigned long end, unsigned int flags, struct page **pages, int *nr) @@ -3306,12 +3266,9 @@ static void gup_fast_pgd_range(unsigned long addr, u= nsigned long end, next =3D pgd_addr_end(addr, end); if (pgd_none(pgd)) return; - if (unlikely(pgd_leaf(pgd))) { - if (!gup_fast_pgd_leaf(pgd, pgdp, addr, next, flags, - pages, nr)) - return; - } else if (!gup_fast_p4d_range(pgdp, pgd, addr, next, flags, - pages, nr)) + BUILD_BUG_ON(pgd_leaf(pgd)); + if (!gup_fast_p4d_range(pgdp, pgd, addr, next, flags, + pages, nr)) return; } while (pgdp++, addr =3D next, addr !=3D end); } --=20 2.41.0