From patchwork Mon Mar 18 20:03:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13595766 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 29A97C54E58 for ; Mon, 18 Mar 2024 20:04:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 96EE76B0093; Mon, 18 Mar 2024 16:04:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FB5D6B0095; Mon, 18 Mar 2024 16:04:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74AAF6B0096; Mon, 18 Mar 2024 16:04:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5E4036B0093 for ; Mon, 18 Mar 2024 16:04:24 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2A17C14068F for ; Mon, 18 Mar 2024 20:04:24 +0000 (UTC) X-FDA: 81911236848.13.3AE5DD9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 001D6C0020 for ; Mon, 18 Mar 2024 20:04:21 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=O3WmJ+n7; spf=pass (imf22.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=1710792262; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xZurg04juSYF/uW9HtnhgkfMM1C/gArxmrpoVNEgvCQ=; b=K+MDgz2cx34t2kArbIZKuqd3RjW2n58jF/5Gfed+zzW3nt/YrIkLV074/ZId9FbsyZi/sW 33yYhfRvxYDcadC2Fgvd9rAf0VmWGP2BDJggfFJz5x+L9w4yOYDSltltU4FZV0Jt/HOjXd fTSAnzMdiBNtfXlZmJRl2WwAh4tgFMI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710792262; a=rsa-sha256; cv=none; b=uNav+fPtE0V7A+UIvF/bPBChlYtO4rMTqtOceFBzuuQptD4bJZ+c8Py6EOAIgSbHMC9HSW ee/IMFJqUbzZDJyJO2F5kpKrdYz0gywerZDDVNKD4zuK7enlC3hlX5xDDTkxVmMqZFtGyY 3iN7sZ9gzGd/ItOVE/nTV4W9BD3Jk2g= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=O3WmJ+n7; spf=pass (imf22.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=1710792261; 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=xZurg04juSYF/uW9HtnhgkfMM1C/gArxmrpoVNEgvCQ=; b=O3WmJ+n7XNNnxgnQ25kBqfo+fbeEk/1Y1UiHc/I+r1s+Jnm+U+jSTPJ08K6OeOSQz9nJQ2 FWBtcUPwIt5fVkYDpa+8pXRHJkFZDyV+JIRXsdW+4lR6GGV4VMdIwY6LuJNVvNUKn3eYrP RpTRI2839yVkqxy7+KfOsholIY7pkxg= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-rDlcGFdKOOaHCVeu3v0YUw-1; Mon, 18 Mar 2024 16:04:20 -0400 X-MC-Unique: rDlcGFdKOOaHCVeu3v0YUw-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-690c19ee50bso14534016d6.0 for ; Mon, 18 Mar 2024 13:04:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710792258; x=1711397058; 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=N861VHLtcctv+PP0JzztCTSOaa4zBdwW8ukkpEVyumy1moYs7YSwLoABc/aMx1mRFO XRlofHevJZPM5eHhaNPRqJI2/VmpQvER9TdYUObIxL6aoRrw3hoqtXKRI0exDZrAifaf kd52Ub6IRL7D7jnnPlMB7i0GtWtUpDM/csazZtr03C3iX9boagMy8W7rmkmCgZkce/ch iyTo463m9ePM+W5gaPtR9gsnI2YoMu+jpyJzBuLBl+3eYteGzxPuu8ixeXHsqbExozlJ qAW0Zsvwyi8HAL8448aVPw/QLxx72S3bQSqP7sztvpMu+r19eZ/rXdG+d89SpH0dVkFf 0dlA== X-Forwarded-Encrypted: i=1; AJvYcCVpRfRRBUl4EFM8Sg06fttr+6cYuVaQu3uYUBXbRoJDe1Yl2vXQpAY8aI4bZgjkDG4Xv9pcGrNYEK7K9ueuMppqzwM= X-Gm-Message-State: AOJu0Yx0Ri9EsbL23JSUzYNoiovp0mGvSUMA2kUzq76WvdRw8I2waATv GnTbtOfd/cH5qyyuuG+X8ZXtYGboRVpErqEQQpP0se2OxRZTjlY5DME6sLczLOW2+G1ccNo6um5 ubupBDVe9ue3xAYFE6h47bGnqmvU3/G3KC6e1jJWERdwuLFbd X-Received: by 2002:a05:6214:3f85:b0:690:9db6:f410 with SMTP id ow5-20020a0562143f8500b006909db6f410mr462674qvb.3.1710792258412; Mon, 18 Mar 2024 13:04:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGPMjFRvOQnrQWtPInqAdggXMmLflMtETkazIbCBO67t5p2Mbipn5U9tbb0PWyioZzi1AzvbQ== X-Received: by 2002:a05:6214:3f85:b0:690:9db6:f410 with SMTP id ow5-20020a0562143f8500b006909db6f410mr462644qvb.3.1710792258055; Mon, 18 Mar 2024 13:04:18 -0700 (PDT) Received: from x1n.. ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id hj10-20020a05622a620a00b0042ebbc1196fsm3484491qtb.87.2024.03.18.13.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 13:04:17 -0700 (PDT) From: peterx@redhat.com To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , x86@kernel.org, Muchun Song , Mike Rapoport , Matthew Wilcox , sparclinux@vger.kernel.org, Jason Gunthorpe , linuxppc-dev@lists.ozlabs.org, Christophe Leroy , linux-arm-kernel@lists.infradead.org, peterx@redhat.com, Mark Salter , Catalin Marinas , Will Deacon Subject: [PATCH v2 08/14] mm/arm64: Merge pXd_huge() and pXd_leaf() definitions Date: Mon, 18 Mar 2024 16:03:58 -0400 Message-ID: <20240318200404.448346-9-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240318200404.448346-1-peterx@redhat.com> References: <20240318200404.448346-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 001D6C0020 X-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h jDO8QJ79Snl9+2iWcaD9AEmZ7whi7V+/3GcdbCOadJIYyQd4HrKGwjWNdoRfdWVe4NtvgZCyCuYGPzoeKGw24cMWdqqtiwK3TSkEfVwk/kP1/T+KRw9+VAhBImx8GTpDt+vY4bGcCLamdpSFXDciLCqyakYHlvgt27pl6rd9naxdYsd3QpVhSpBBzIxHxK8dwAndznAwvJ7QNt/Syh+G9MCN948S1ZSPrjiyn66LjEXUdas9BJT8lDeDDSSjgaPIDexfWvzNt6LGrx/xrCfk8V1ns7BzY8dgfspN7WXcIRo1UkS7AuZIyouYkQn7FAl1DppmhtbO13ibw1YWCDSY0HcMCzIrfDBsow6fjhg2mAyp/dEyZMpo5gSLma8uzIHQk6yHvsAhM9Qhz+fLR+NjQZJFK8kS+nfaMhn3ak38l8X3925sxYwzSfouxBQ4NuzaiPff4UPJHDzsMI6YPUZQmEVQI66GNMMYB+ZmxNT/be/eeB6FJF4/6zshwnUis7yPCh9Fkm6K14IgfS4lgMOS0ahutCkDIzI5Phh79G4icxICcIYF+W/96P5DsaOmr8B+PdZo1R70yg3cPzRRt5FP9VkQMpFzPLllh31xh78A8EdTUvPY= 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 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,