Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3517556pxb; Mon, 4 Apr 2022 19:36:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx64tJ0DdvB9tDBizj69A4ZA7dYc8NPcSEv80qNsWgyVjPkz00wnjZYtCpszZFmDF/9iubk X-Received: by 2002:a63:a0d:0:b0:399:460c:ffb9 with SMTP id 13-20020a630a0d000000b00399460cffb9mr986698pgk.43.1649126191123; Mon, 04 Apr 2022 19:36:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649126191; cv=none; d=google.com; s=arc-20160816; b=Em9xI1cFf8G3CbWpbyfGOjDYJ/IcEly4B5sLV8wb3N4115IsUvRdjGJG2MpYnbxWCV CMzl4XpEIQF7Y6w8MsaT+33X1/eGbMcXRWj44I8tNeNLLwo0CWrbDxqCBo4mwOoicqil x1/oOnJ2whjJYTl9m0mkd4g9kLvB9nscVW3qJUMavrBdm7wb2S8qRy5C+3jcoxyODYpK wNBiyYKnlduSLcFWl35dw4BxdEEKEQg+jkc+UAWQjK+0DmFoGv91s+nnQQp2YOjkvbFL cF1+pGMbCMTPg0zQcBJcdYRDPB66G8SfyMdaC8Qw5d/jpyBeX+AUEgDU+oEhxxQwAPXC Ds6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=XCF3ta+yLboptu0AL+z01WuMeNrQr7DLRI8vR9k6QYk=; b=ve9fpZGN3Js6PBIoxA16DuwCaVp9Oxw5Jz+qT9mdbTR2F58GRZZsyvlytvxDdz67Vb eGnK0O5qQOsH2XtN+izQMA0Fyx9gwpZb0MD6r0dja63Rz3uwCw/CxrrQ/YG1myRQRC2w eB5qS6nm1hKiWYPNvvMn0t50a6KHOF1XJuQ1wzQS5/1VyHiijhU7lSsFn64tHVWVGJGS 1pH8b3MD0EPf676IEdsz1t0eiDOpjHigScICK1+FyPSGaWnf3Uh8OrKHCZ3OyLTWjzHV 4DWr+zn1xV2suLJ5UCq3JGb+YzgOdtbxXOuZGUbSgEhxnBhWKsbgvKXWsXFliXXa2Kfa G3CA== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u9-20020a170902e80900b00153b2d1640bsi12672453plg.19.2022.04.04.19.36.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 19:36:31 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0C97D32573F; Mon, 4 Apr 2022 18:00:08 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358388AbiDDKxV (ORCPT + 99 others); Mon, 4 Apr 2022 06:53:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245571AbiDDKxM (ORCPT ); Mon, 4 Apr 2022 06:53:12 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CB5993CFDD for ; Mon, 4 Apr 2022 03:51:16 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8D93B1FB; Mon, 4 Apr 2022 03:51:16 -0700 (PDT) Received: from [10.57.41.120] (unknown [10.57.41.120]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BAF1F3F718; Mon, 4 Apr 2022 03:51:14 -0700 (PDT) Message-ID: <14d1bb4c-f58b-12d6-1034-c851263acafd@arm.com> Date: Mon, 4 Apr 2022 11:51:13 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH] arm64: mm: fix pmd_leaf() Content-Language: en-GB To: Will Deacon , Muchun Song Cc: catalin.marinas@arm.com, akpm@linux-foundation.org, anshuman.khandual@arm.com, aneesh.kumar@linux.ibm.com, lengxujun2007@126.com, arnd@arndb.de, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, smuchun@gmail.com, duanxiongchun@bytedance.com, Qian Cai References: <20220403024928.4125-1-songmuchun@bytedance.com> <20220404091957.GA22790@willie-the-truck> From: Steven Price In-Reply-To: <20220404091957.GA22790@willie-the-truck> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/04/2022 10:19, Will Deacon wrote: > On Sun, Apr 03, 2022 at 10:49:28AM +0800, Muchun Song wrote: >> 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 >> --- >> 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 94e147e5456c..09eaae46a19b 100644 >> --- a/arch/arm64/include/asm/pgtable.h >> +++ b/arch/arm64/include/asm/pgtable.h >> @@ -535,7 +535,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_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) > > A bunch of the users of pmd_leaf() already check pmd_present() -- is it > documented that we need to handle this check inside the macro? afaict x86 > doesn't do this either. The documentation is with the fallback implementations that always return 0: > /* > * p?d_leaf() - true if this entry is a final mapping to a physical address. > * This differs from p?d_huge() by the fact that they are always available (if > * the architecture supports large pages at the appropriate level) even > * if CONFIG_HUGETLB_PAGE is not defined. > * Only meaningful when called on a valid entry. > */ I guess the term "valid entry" is a bit vague but my intention was that meant p?d_present(). I have to admit I hadn't considered PROT_NONE mappings before. Steve