From nobody Wed Feb 11 07:07:39 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 6B4CE1E520 for ; Wed, 6 Mar 2024 10:42:25 +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=1709721746; cv=none; b=qQX3g7zOjTEYxhau62O5hF3DjCUfB+B+Z97JNkaax44zBZ9bssjg25HaUyoTbkLrPM2tcv0Kdxx3F66xLU/pOm5Q6kDXK1t/QEYGbrvnJA3Aj/IsW40r3lH1sgCNH9d8d8i+XBKuMXcYTjxPVFPxdbtYeVgJl1Pv5Jk4/Fv98hA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709721746; c=relaxed/simple; bh=CxV8MifY1lrwJx7GkesgEIYplTEI/H1POQkB3NsGQqU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CBQShobxuOWQ7NsREr/2nf2GZnz5huwhl7/9m2yUW6IDBWh48mhyc9Y9563WZ8cX2BEqfVGBiCh5CDIB4AZfPolyEvgKB/FYiCFROxWOgIpcc1g3wsxctmM0GfU++59eGuGe3DV6HI9PSSegm+nmXghv+NKyVO+HAh9BDo+IV/8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=XH/CyYsl; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="XH/CyYsl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709721744; 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=1JTq1zOoPcvZLzyDHIG6xTSG66u1JMVbpFEt5kpx07M=; b=XH/CyYslzUhUiwZa5q9LWSJSx1XaUejmTPGU6RHS3o+G2O+pG07eLCIjftNysD4GUQBgdL htrkhv23yOVQu6c22PxeESGPut1HEmtveHXmMQ0/iXt2afq51ICDlIqyHzM7Mw3zve3iyK lDf2hhhCkPrJ/ZTL6QWWfbMpAP4CTcM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-w92BStQdNuqU_EljwB5_jw-1; Wed, 06 Mar 2024 05:42:18 -0500 X-MC-Unique: w92BStQdNuqU_EljwB5_jw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6AC0E800267; Wed, 6 Mar 2024 10:42:17 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7360111E3F3; Wed, 6 Mar 2024 10:42:11 +0000 (UTC) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org, Andrew Morton , Muchun Song , Jason Gunthorpe , peterx@redhat.com, Matthew Wilcox , Mike Rapoport , Christophe Leroy , x86@kernel.org, sparclinux@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH RFC 03/13] mm/gup: Check p4d presence before going on Date: Wed, 6 Mar 2024 18:41:37 +0800 Message-ID: <20240306104147.193052-4-peterx@redhat.com> In-Reply-To: <20240306104147.193052-1-peterx@redhat.com> References: <20240306104147.193052-1-peterx@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.11.54.3 Content-Type: text/plain; charset="utf-8" From: Peter Xu Currently there should have no p4d swap entries so it may not matter much, however this may help us to rule out swap entries in pXd_huge() API, which will include p4d_huge(). The p4d_present() checks make it 100% clear that we won't rely on p4d_huge() for swap entries. Signed-off-by: Peter Xu --- mm/gup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 69a777f4fc5c..f87a7d90f2ae 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -776,7 +776,7 @@ static struct page *follow_p4d_mask(struct vm_area_stru= ct *vma, =20 p4dp =3D p4d_offset(pgdp, address); p4d =3D READ_ONCE(*p4dp); - if (p4d_none(p4d)) + if (p4d_none(p4d) || !p4d_present(p4d)) return no_page_table(vma, flags); BUILD_BUG_ON(p4d_huge(p4d)); if (unlikely(p4d_bad(p4d))) @@ -3069,7 +3069,7 @@ static int gup_p4d_range(pgd_t *pgdp, pgd_t pgd, unsi= gned long addr, unsigned lo p4d_t p4d =3D READ_ONCE(*p4dp); =20 next =3D p4d_addr_end(addr, end); - if (p4d_none(p4d)) + if (p4d_none(p4d) || !p4d_present(p4d)) return 0; BUILD_BUG_ON(p4d_huge(p4d)); if (unlikely(is_hugepd(__hugepd(p4d_val(p4d))))) { --=20 2.44.0