From patchwork Fri Apr 22 06:00:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12822768 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5AFEEC4332F for ; Fri, 22 Apr 2022 06:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=uTWLC+lQzXTKsXCjPl0K8xWDKpJ54HVHU9zjDG7vgGM=; b=umLxfnYAcazMvj 3bAk3ZBPvnae5q341Bet7gmcwwsgmV4o6QP3dTMJgbp31NtqykFj/P90sAxBQH9FEcKGH7F5UteqR 8s196A+mK/+RFh0ejGpIQ7btLEfZC7VHpc7LzJLgeVSApTtrC8WKEv6QooejuftHLC2DmwxXcIlJE dMGaQHNtBnNSEl6M7XJWqLSWm+75tFo5CAbkMSKgpexXp1ZlF6QCiU7Yin36qZB/g8I+NsIP7o3xx EzV3TUSa5ELQtI282e0z5zfShQtpEONh968LHlKmaa/jxoVELGWiA8pPghg6KN36SudPFgYBvNNCC S93BgdMgpo2OOB6EUeKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nhmLs-00GKkk-Vy; Fri, 22 Apr 2022 06:01:09 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nhmLp-00GKfP-4q for linux-arm-kernel@lists.infradead.org; Fri, 22 Apr 2022 06:01:06 +0000 Received: by mail-pl1-x62f.google.com with SMTP id t12so8613723pll.7 for ; Thu, 21 Apr 2022 23:00:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sIHHWuXCFhgIuVLEw6qrEOnv9syAmIvNW41hiA3znas=; b=SOBh1fU+ek+mwjGri8dzq6pef9j78Zr2x/jT9SaI85A+HQkk8bA/T2JrdJj03jaz2/ fcNUQX4nKN+c2RYGvLoXSmG5HKZJOV6nxXnYYrWrG0E1AVaAJwD4k+jotH5A6UeMRhlY aVp4sP43Hqgc0cCmT8f+J1Z2BHzjW7467I9ce0l81Buuj2PSru0HCasQKsrM5mq9PXKX +uHpndlPMOycVEadM5NXsUqbzd8ROuMS3kixTlEw4Ir4JjvP/9AVvNU2yRsPYg4cUPwt 09qWlawywp74oZXGvT6TBnrCFpDTMTcTFyE2dZNFn9XmlL47RHvm8/heVC+99RyaYnB3 TRYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sIHHWuXCFhgIuVLEw6qrEOnv9syAmIvNW41hiA3znas=; b=Jddqp/tmdnnEMRvMAXgmSasU51UtusJp9bYiiji92tigy3PYwew9/l5RSxf/nCWd+e KvcNvsidQKUeES7m+uZO5EB2DqHLujJ46/msXJgNJQ21dCSc5kJzgtb81zy0yjxwxXZm 7apdlNB7tkeC1Wo64Q6upa6vSHXLcLlMHUMaD4NM/bc2AvOC6PFMW3Li9iWzwHm4Qnn7 LvnqQCG15ewYoasXDjeoyZOMS3YElBPBpCkcZsAFKoOi+OPlni6HbY0eGVwTCqlwrp3c fLpDeJ0mwdKuVyu5xeFDik3siocKWbUJjttcbjwU8GH4JEYgb6842S1Xz5iZMv57pSD3 YasA== X-Gm-Message-State: AOAM533a4cQS52sa1UmTcjnrD+3c0IhzmBOYCvzSgb7cU/qctDrsK6hd pGtVH+FxnrubjNxAzQf4ki+LAw== X-Google-Smtp-Source: ABdhPJxWgtwSeKPW/si2v9A21Ai8Ex0JgbDjAcJhrdIPLdEDJ5McfxSOMH64Ih+VY/b9HCxtO5ubSQ== X-Received: by 2002:a17:903:11d1:b0:151:9fb2:9858 with SMTP id q17-20020a17090311d100b001519fb29858mr2993208plh.136.1650607256188; Thu, 21 Apr 2022 23:00:56 -0700 (PDT) Received: from FVFYT0MHHV2J.bytedance.net ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id ck14-20020a056a00328e00b0050a3c5f415csm1029801pfb.23.2022.04.21.23.00.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Apr 2022 23:00:55 -0700 (PDT) From: Muchun Song To: will@kernel.org, steven.price@arm.com, catalin.marinas@arm.com, akpm@linux-foundation.org, anshuman.khandual@arm.com, lengxujun2007@126.com, arnd@arndb.de, quic_qiancai@quicinc.com, aneesh.kumar@linux.ibm.com Cc: smuchun@gmail.com, duanxiongchun@bytedance.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH v3] arm64: mm: fix p?d_leaf() Date: Fri, 22 Apr 2022 14:00:33 +0800 Message-Id: <20220422060033.48711-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220421_230105_217804_FA83CFB4 X-CRM114-Status: GOOD ( 10.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The pmd_leaf() is used to test a leaf mapped PMD, however, it misses the PROT_NONE mapped PMD on arm64. Fix it. A real world issue [1] caused by this was reported by Qian Cai. Also fix pud_leaf(). Link: https://patchwork.kernel.org/comment/24798260/ [1] Fixes: 8aa82df3c123 ("arm64: mm: add p?d_leaf() definitions") Reported-by: Qian Cai Signed-off-by: Muchun Song --- v3: - Fix pud_leaf() as well. - Rework pmd_leaf() as present && !table. arch/arm64/include/asm/pgtable.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 930077f7b572..9aae3773b6c4 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -551,7 +551,7 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, PMD_TYPE_TABLE) #define pmd_sect(pmd) ((pmd_val(pmd) & PMD_TYPE_MASK) == \ PMD_TYPE_SECT) -#define pmd_leaf(pmd) pmd_sect(pmd) +#define pmd_leaf(pmd) (pmd_present(pmd) && !pmd_table(pmd)) #define pmd_bad(pmd) (!pmd_table(pmd)) #define pmd_leaf_size(pmd) (pmd_cont(pmd) ? CONT_PMD_SIZE : PMD_SIZE) @@ -641,7 +641,7 @@ 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)) -#define pud_leaf(pud) pud_sect(pud) +#define pud_leaf(pud) (pud_present(pud) && !pud_table(pud)) #define pud_valid(pud) pte_valid(pud_pte(pud)) static inline void set_pud(pud_t *pudp, pud_t pud)