From patchwork Wed Mar 6 10:41:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13583875 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 B667DC54E41 for ; Wed, 6 Mar 2024 10:42:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 507196B009E; Wed, 6 Mar 2024 05:42:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B7AC6B009F; Wed, 6 Mar 2024 05:42:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 359336B00A0; Wed, 6 Mar 2024 05:42:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 20C9B6B009E for ; Wed, 6 Mar 2024 05:42:27 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CD307A0B8C for ; Wed, 6 Mar 2024 10:42:26 +0000 (UTC) X-FDA: 81866275092.06.0C3D110 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 205CB40006 for ; Wed, 6 Mar 2024 10:42:24 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="XH/CyYsl"; spf=pass (imf01.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1709721745; 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=1JTq1zOoPcvZLzyDHIG6xTSG66u1JMVbpFEt5kpx07M=; b=7xIF4ySfHLQAAI3qd2YGXFGTosKIN9wVgiUIAWUihhWP50Qw5r2uS+yoEcY5nwWTnPdqh4 bw0AJTPq/2wuMgTaalVYpQ9v6hCcSPsUZvuEHQNRJy8rCh9p7GfJvaVdenEv7H4ywGrQqk QcnrBAMY6dQgChTv15t7nPuN/Vgwv+c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709721745; a=rsa-sha256; cv=none; b=boRfWm2CyCLWLvdeeV7UR/PHUuIEfFX1YajMQslAzcIpgsdRQLSVzGHoPKzmDctdK161en 6k7kdS3X+wYcUFiYZlGgGCR4XJ0GlvBoarWeTItiCBsxTasRSq5v4dITnjgNIlLcrHrMiM ANdRavzMRpAO7CTSbEeu9cUI4y52iiU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="XH/CyYsl"; spf=pass (imf01.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com 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> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Rspamd-Queue-Id: 205CB40006 X-Rspam-User: X-Stat-Signature: 16twokg5141sdniwrzi5ipkert4dxuq5 X-Rspamd-Server: rspam03 X-HE-Tag: 1709721744-523378 X-HE-Meta: U2FsdGVkX1+ra/05keMhN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2SWV46zTZs1XjuWEpoPeuZWyVT9Bb99Uw/2C544jdhIlcZEtoXNiCySFQ21KiWqxGY/ykeaqYdEE= 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: 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_struct *vma, p4dp = p4d_offset(pgdp, address); p4d = 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, unsigned long addr, unsigned lo p4d_t p4d = READ_ONCE(*p4dp); next = 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))))) {