From patchwork Mon Apr 11 12:26:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12809073 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 1C7C0C433F5 for ; Mon, 11 Apr 2022 12:29:27 +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=k2nLvu5CjmiIVv3VBqXSv4Om+JYykQ4MHX8d9zZQoYA=; b=5GT6+VCLit88aL rmiAhlf/w0I+E0vucpQCvjMgoESJ+huXZqiwi/7vPotA6ypql4/ws/p2wfad/hadsKLpNf2qW/Y9W Ib3WDmf1MfqUvT58ATrYq1qHeu5flHyFaV2yankAp5qk5Ui/sq6qHQ4qsAH+Ufm8j0v30yJgxfWxL rRqTS53Eg7nS0cOj0ubQD+xnE5Wrje/3ITG6LZhV2Vov6vKRbw1y/vAd3zOd9TG5FUsY5i2Tqft1u muLlOzTnoavK7B0vaq277as2pQEOpCp0LYC2St8s1QxCE4fIvjb01myJS6zHncR7I1tD3VlyFlKdH LNe5MPnNA7LDjIfEMTBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndt9W-008ytZ-1T; Mon, 11 Apr 2022 12:28:18 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndt9S-008ys4-83 for linux-arm-kernel@lists.infradead.org; Mon, 11 Apr 2022 12:28:16 +0000 Received: by mail-pl1-x62b.google.com with SMTP id n18so13699988plg.5 for ; Mon, 11 Apr 2022 05:28:12 -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=QodfVSYvtajfZu5GfMihFlyPJS016l+/i2+aa3dvR/M=; b=48tVOWYpd8ZPY/3YXoKZl/BMYH7ui+Amk8t7+6bc6Y3MHSVGrA7nNaU4JNpefswj4O 3QIbwtZ5+BHBTZNgGUx6DrH3/naQop/ghumvjDr5b4gjrSw5xBXTR+9zH8IAaoLG5gv8 gD+ExHUS5TaUwjwlBih/bZxaVMFu2pAfBQK6etpOVvQnbXqO15kpDPu07EQ5Hns27pDy GdJdYuKQsFNBL/EYDP1UNsIuB8BOmBL5kmxp4DW+gbRcvB5rsPta4dYUENQVHVbbLWVR zP4WnsTReOaNJvd5FYJsk+SEB+0e5y8/aNOQ5n1BKxPeWkivTzYBGdVtTERal50mDJcC dgDQ== 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=QodfVSYvtajfZu5GfMihFlyPJS016l+/i2+aa3dvR/M=; b=jkUDSF6u2psI/Avo1rPoIGdsEzM/Bj2h5iZeE7VjugZUe1/GtHVrTnt7uZkM55tczA DN+bi/DujwlVLo5LUFt9hRPHo7C0sg1Y1L0+b+YaLlOSEPdbiBmjfcRk74vMkAWhth92 20MptJSPvo9F2L7RuQzXWEaSzrJDITTjq8ba+iGBnHXlxd6WE0S0RXzhDZBvYCGJb2sl s7TR73SJTDcR1ST3PNizwdz3w0XK9HJY2YDePot+RnIHa3dvIFjv9OrX70pGcpjAcYzc DZMwLXviQDC+dfMni/o8kemLVnpTuTdBEpe82my2ybmLvAURC9D9scCW0GBer1J0GQw3 k5+A== X-Gm-Message-State: AOAM530KdfXH5OgTB6rT3ARCFhmg9OKuoMNgzdgM5uaV0D4JhpNjf5zM b/zHbuwPAjSjcbLd99YzO2fAOA== X-Google-Smtp-Source: ABdhPJymaL28YkA+U0QTjSOpHtH19n1Ae0krubSKlT0fk5Q1jJNPCSnDRqn1pqEh0YKC/Ps/1r0OBw== X-Received: by 2002:a17:90a:600b:b0:1cb:8ba5:d3bc with SMTP id y11-20020a17090a600b00b001cb8ba5d3bcmr7319539pji.42.1649680091792; Mon, 11 Apr 2022 05:28:11 -0700 (PDT) Received: from FVFYT0MHHV2J.bytedance.net ([139.177.225.245]) by smtp.gmail.com with ESMTPSA id fa11-20020a17090af0cb00b001ca6e27a684sm20065699pjb.16.2022.04.11.05.28.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 05:28:11 -0700 (PDT) From: Muchun Song To: will@kernel.org, catalin.marinas@arm.com, akpm@linux-foundation.org, anshuman.khandual@arm.com, steven.price@arm.com, lengxujun2007@126.com, arnd@arndb.de, smuchun@gmail.com, duanxiongchun@bytedance.com, quic_qiancai@quicinc.com, aneesh.kumar@linux.ibm.com Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH v2] arm64: mm: fix pmd_leaf() Date: Mon, 11 Apr 2022 20:26:53 +0800 Message-Id: <20220411122653.40284-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-20220411_052814_320906_C66ED0F0 X-CRM114-Status: GOOD ( 10.43 ) 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. 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 --- v2: - Replace pmd_present() with pmd_val() since we expect pmd_leaf() works well on non-present pmd case. arch/arm64/include/asm/pgtable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index ad9b221963d4..00cdd2d895d3 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_val(pmd) && !(pmd_val(pmd) & PMD_TABLE_BIT)) #define pmd_bad(pmd) (!pmd_table(pmd)) #define pmd_leaf_size(pmd) (pmd_cont(pmd) ? CONT_PMD_SIZE : PMD_SIZE)