Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp980839lqs; Wed, 6 Mar 2024 02:42:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXixam5doyLe7pPKwAlaH9OVryg5RidY4OM+y0CeK5bpczoIIEBHOYA1FQFAmCBYxXizy2PKjS5wxiZq3JOYQfWNkVzgSzzVs+vYGX6WA== X-Google-Smtp-Source: AGHT+IG3iaXhkyeYxpRBQdd0dXLumM429fs4TUPoPC63+rkOFzJIBNrfZ7bNBAcHD8lFM38ZAu5u X-Received: by 2002:a50:cbc8:0:b0:563:ccd1:26bd with SMTP id l8-20020a50cbc8000000b00563ccd126bdmr10333938edi.2.1709721777390; Wed, 06 Mar 2024 02:42:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709721777; cv=pass; d=google.com; s=arc-20160816; b=cmbAiXY0gOLDhlFHJz+TAjTOZM8yaF50+gChTM212RLdg9fFOv0mZb3lL0h2I1YdJR H1zb7bgxlIXCBY4OhQWV1W4RVT26Zm4m749nxlXcZqCZRu6Ct+/LNN8kj/8uM76Rcnkf MHuw+HZGx0Hd4oMw6rnD6WRhjDvMFFf8cRbrlSrgwLgNz672qH5PYh8rXyugn6Co9iq2 GulObmT85WHYtEBlpUReklHs2mANaIW0mci5ZGRLjBjjcdj5BdaSkDGfD7N1YkjP0kec T2MjXIGaT+pZ442aS+ewSQL2pUwapwckXI+8R6W3I8AF1bmP747mAzfTjUdhaYz371si YKOA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=1JTq1zOoPcvZLzyDHIG6xTSG66u1JMVbpFEt5kpx07M=; fh=ZLWzwF9fAa+WzR8A8FaiEy/vTVg+lTkrbqyNLBqH+k0=; b=tCbZ+ut9/8dSbVL81m/Ph1XlprVVju5qv63dUnoWqnog7ltmPy2gNljUe4WCk0fzLe ziiJJEqbw4rFW6DWriZ/1cpQufrIUdeNmzk4G8pc/kiU4uLWz1hxJ1MaSZIJs9DSr5K8 AkNPH8fidrPhnlswCwT0Moe+epVb6LyXJ1EBH29+9X0N4ZNeJu501N/EwqItVT5++IWL 9eNwPlq96vEuu0rieCD+hfOkFS19F1AAr/0wY5rZDvXAJkAbcyz1X5O8McRGGTH34M20 Iyilsn0BCAaHEh6r7/lkSvHIBmq1fz6dWgmV8i8ckG+HXnvtsITfsDCa1yt1eaW8sbv/ uaxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="XH/CyYsl"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-93788-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93788-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l26-20020aa7d95a000000b00567f631000csi227666eds.167.2024.03.06.02.42.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 02:42:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-93788-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="XH/CyYsl"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-93788-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93788-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 241761F214BC for ; Wed, 6 Mar 2024 10:42:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA366605BC; Wed, 6 Mar 2024 10:42:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XH/CyYsl" 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 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: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 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))))) { -- 2.44.0