Received: by 2002:ab2:5c0e:0:b0:1ef:a325:1205 with SMTP id i14csp13136lqk; Wed, 13 Mar 2024 14:49:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX1Lw11G4/pBKiicTvagxffeQ836j6TDeq3iICz6rBvW2UwTTHurQwFgSI75L/YH4/+aRlnJ7Uu9hAlc7VGC/FRp/sXrwZbbDHwb/rGwA== X-Google-Smtp-Source: AGHT+IEBfxVUf1U+/LQ+rmf8+YB6nk0375gBM0eJxLxwdCAw8q0lh3r3YaLfnzmfIqKG/1/M2uPB X-Received: by 2002:a17:906:695a:b0:a46:6510:a824 with SMTP id c26-20020a170906695a00b00a466510a824mr1686629ejs.19.1710366585524; Wed, 13 Mar 2024 14:49:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710366585; cv=pass; d=google.com; s=arc-20160816; b=Q177NAxHR8ZvSyQa/flVJYjyut1QzpqjdAQ5iDa2rQl+sSjgDLjFXbjSSEpUTnlX1K 82YzzB5xno7M1h1zKSsTdStNlzmQF8sEqUvQb4hM2MBORVF88f1JqR9lEBTqdUw+mm4q R9ytd8cGUYVqQqu0bpVIeV9A+yx1Zlpo/zu9T3j78A22yU/S+YQfsCfUJ3IBH5doCWsR aTj2yTwGnsgrowsvJyz73emdk4MTOnCKY8aRMZKXxb7PpUJXRK8CaKFp8yqRDfJcbOKz 4G1sBwYKtNLso2n4OnseRakKwQcEqbODmKRe19300DbchQBR2XgNjWWKYPGybTpGWxe7 FBPw== 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=xZurg04juSYF/uW9HtnhgkfMM1C/gArxmrpoVNEgvCQ=; fh=S17ZJIpzd3up8W/2mnfDLXI5SL/zTeoeytdAflVNIDs=; b=v95tUpTRm1MS0sRb9qGH1k0u9qI6FMmMWfl2hCC9m6rPJJQON02XpCyWAn64CgF5gz L6s6P/ZEg7+kvyd1XJIX3pBMclw2PNhjV9B+ykchuQnHtRasHR6WKkFZVL4SnutJO6a+ dCK1BnaBG5Y8vxyyH7ckICV4NE1cYowKqpWeH9rIdUSEelbjAbDN610o/WqJn3TEbYur IV8F7JVWbHHHwS5wfFoZyPf8X5b+hbx+GdORfh00ulDzgKjJdTOX3GYMXyz3gGK1Tdx7 Z9iIFSxq4BYrhuWFG5LrFo7F5wZSmel9YYHewXd/FX696ZDiDWKE2hu1LYtrEnb0BdCq ji7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SBeQCrtn; 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-102561-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102561-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 kh21-20020a170906f81500b00a4448562aa9si47619ejb.712.2024.03.13.14.49.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 14:49:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-102561-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=SBeQCrtn; 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-102561-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102561-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 1D27B1F241B4 for ; Wed, 13 Mar 2024 21:49:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 922355F477; Wed, 13 Mar 2024 21:47:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SBeQCrtn" 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 2310C5E068 for ; Wed, 13 Mar 2024 21:47:36 +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=1710366459; cv=none; b=Q2FhnJdBCi2y6LL4O2NIvkbW+72sDRD1zJk5z9Cxbf4Hj5kXBhW8QIoeMPIR4yd//TeyCEYiwAWopuX/SndOKHIYMe0MrATMZ+kA9XSDda3tBjdiKYqbtCkdQj/irGo1kIa/R13iHqzuD11MylhK2JklIFcn3LG0N6KR9cXDvTI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710366459; c=relaxed/simple; bh=t18R28ny76a7TFkmozYcxNFR6pN9FqPc0sZ3mbG+iGw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dKwH/wMohEczlrYwCuYHQObpr5kA18j6/FlwYyaDgKf8mstXf9QXGXsIEpDcJ6D3TiAS/AV8nT9jycR1tGN88/SlR5GZW8Jmz5Zqsm4/mQGlpZGShdlX0PgurMEF9/NHWbsTHo8+sAQCxDoZEX8//2etXSL1HHrQDOXgLvCB3+s= 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=SBeQCrtn; arc=none smtp.client-ip=170.10.129.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=1710366455; 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=xZurg04juSYF/uW9HtnhgkfMM1C/gArxmrpoVNEgvCQ=; b=SBeQCrtnqHalaF4ij/nFhZNiI+eARsbmV8yx4QsCtNna3JCa4lJ+8rGd3lRzXcXeM8wohm qJN9LS5pXgMNewiDDcDNW9aMhXgU8/VQEAs6HswGtID701FRuXbzkf5+PDDA/Ofw0x5+Qs AduHSVOOgpAUgK3iubymWDp1e+/DXG4= Received: from mail-vs1-f70.google.com (mail-vs1-f70.google.com [209.85.217.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-101-mkmmq4biNHyuLKqLTTzsZg-1; Wed, 13 Mar 2024 17:47:34 -0400 X-MC-Unique: mkmmq4biNHyuLKqLTTzsZg-1 Received: by mail-vs1-f70.google.com with SMTP id ada2fe7eead31-474c751e9baso10175137.0 for ; Wed, 13 Mar 2024 14:47:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710366454; x=1710971254; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xZurg04juSYF/uW9HtnhgkfMM1C/gArxmrpoVNEgvCQ=; b=jfXkqebEYSfhzwf59BYGzxdqFFU97K04XD0WogGGBLT9yTDbxQrCA1sT1CLZRBuvMt Wr1ucm435Rr8duNbDBbOsJ4vhN4WFsp69UiDYYGXnrEH8Cv5dTqPCmVgdS2e3pl6bc3V 7yl5XgI5W8ncHPRxx0gHtxEj4cNiYzP+Cl177S+nzrqJcbwv0lpCeNHvtwso0Y8IXmZT NDBW/yY/IGoJYNcCgZWja8OPJCRSi5I48HF7XK4tLB2nBx3HhHu+Tk/z5x5tdo5LVlyu /LOblzmuMYV0IU2OdJ/m4nt8oq+1oZaevmZ5vw3/4ZvWK2RaBj5KZcucf5/MUlImcR2n Ei7Q== X-Gm-Message-State: AOJu0YwgGgFYYqYZJa7xPcU0eN16sW6ePMpH0C433ZcOmozIROf89yjt cCrSYo0H8olesYHgmLpdswnMuBEfwzC369gasn8okT8rU0bjvUYGm1Oyu7AOAl9QF3QPBGoSD1K KE+YEhXhgyd7vMIBF9L204vLvyFYthm5DZV/1pgafPv48B/X9DJToQhGD+9IaWdbVsremFPCswr jfPiFn4/lnpU5joWfaCwS6NzPk+LWZExWdSKCd1P8nFbQ= X-Received: by 2002:a05:6102:5492:b0:474:d28c:2ac5 with SMTP id bk18-20020a056102549200b00474d28c2ac5mr243720vsb.0.1710366453744; Wed, 13 Mar 2024 14:47:33 -0700 (PDT) X-Received: by 2002:a05:6102:5492:b0:474:d28c:2ac5 with SMTP id bk18-20020a056102549200b00474d28c2ac5mr243694vsb.0.1710366453272; Wed, 13 Mar 2024 14:47:33 -0700 (PDT) Received: from x1n.redhat.com ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id dv10-20020ad44eea000000b0069111c5cdd4sm60114qvb.100.2024.03.13.14.47.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 14:47:32 -0700 (PDT) From: peterx@redhat.com To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: linux-arm-kernel@lists.infradead.org, Matthew Wilcox , linuxppc-dev@lists.ozlabs.org, Christophe Leroy , Andrew Morton , x86@kernel.org, peterx@redhat.com, Mike Rapoport , Muchun Song , sparclinux@vger.kernel.org, Jason Gunthorpe , Mark Salter , Catalin Marinas , Will Deacon Subject: [PATCH 08/13] mm/arm64: Merge pXd_huge() and pXd_leaf() definitions Date: Wed, 13 Mar 2024 17:47:14 -0400 Message-ID: <20240313214719.253873-9-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240313214719.253873-1-peterx@redhat.com> References: <20240313214719.253873-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 From: Peter Xu Unlike most archs, aarch64 defines pXd_huge() and pXd_leaf() slightly differently. Redefine the pXd_huge() with pXd_leaf(). There used to be two traps for old aarch64 definitions over these APIs that I found when reading the code around, they're: (1) 4797ec2dc83a ("arm64: fix pud_huge() for 2-level pagetables") (2) 23bc8f69f0ec ("arm64: mm: fix p?d_leaf()") Define pXd_huge() with the current pXd_leaf() will make sure (2) isn't a problem (on PROT_NONE checks). To make sure it also works for (1), we move over the __PAGETABLE_PMD_FOLDED check to pud_leaf(), allowing it to constantly returning "false" for 2-level pgtables, which looks even safer to cover both now. Cc: Muchun Song Cc: Mark Salter Cc: Catalin Marinas Cc: Will Deacon Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Peter Xu --- arch/arm64/include/asm/pgtable.h | 4 ++++ arch/arm64/mm/hugetlbpage.c | 8 ++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 401087e8a43d..14d24c357c7a 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -704,7 +704,11 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd) #define pud_none(pud) (!pud_val(pud)) #define pud_bad(pud) (!pud_table(pud)) #define pud_present(pud) pte_present(pud_pte(pud)) +#ifndef __PAGETABLE_PMD_FOLDED #define pud_leaf(pud) (pud_present(pud) && !pud_table(pud)) +#else +#define pud_leaf(pud) false +#endif #define pud_valid(pud) pte_valid(pud_pte(pud)) #define pud_user(pud) pte_user(pud_pte(pud)) #define pud_user_exec(pud) pte_user_exec(pud_pte(pud)) diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index 0f0e10bb0a95..1234bbaef5bf 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -81,16 +81,12 @@ bool arch_hugetlb_migration_supported(struct hstate *h) int pmd_huge(pmd_t pmd) { - return pmd_val(pmd) && !(pmd_val(pmd) & PMD_TABLE_BIT); + return pmd_leaf(pmd); } int pud_huge(pud_t pud) { -#ifndef __PAGETABLE_PMD_FOLDED - return pud_val(pud) && !(pud_val(pud) & PUD_TABLE_BIT); -#else - return 0; -#endif + return pud_leaf(pud); } static int find_num_contig(struct mm_struct *mm, unsigned long addr, -- 2.44.0