Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp97561pxy; Fri, 30 Apr 2021 00:57:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxa6dmmkX4iXOQxxslUuIYoHyoj67Fj6fay85g1aEWe1Y7z73TEIvK0mXHnRDd9JEWO0E6N X-Received: by 2002:a17:902:6a88:b029:eb:3ea5:58c3 with SMTP id n8-20020a1709026a88b02900eb3ea558c3mr4036399plk.55.1619769446788; Fri, 30 Apr 2021 00:57:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619769446; cv=none; d=google.com; s=arc-20160816; b=iZiecCpq9j44eU66zzibSRbJ0k5dat5efZrB33WACuyR9SPggmrdzB8r12RHylDICY +TQJVvlFbfbM7PICkJ/mfeJSstqIT1Non+gz6owrgNb9RSRNeB/aAcm5iFckB7qdgsvQ jDsKWy8IRlZwaB//VilniULzk9Ybo2ITDEG1giPZ9FCrDY0iMpiadYl2JzrI+kNpQOwf uW7kAyypbAsvtgjQ9S2LJQDuTg+AwgnZjB3MtfAfVYWwjit+Y4P1O9tVqqNw4DUCP9nm /rftYJL8HOJ+h10nYP8+nwuguuGuTBGpnUePJz0x4qaMVIb4qsVEQ1NQHMSmaR/XaIOm Bb0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=7TcDEyEghrbLOC7VkfUHCG8yZRKPkg0/jAVkGpahXkU=; b=v+FP+WfZplo5OSexmI32eeAaAldEL/AESBGCBSBj6rasznppzsOPrYK961Ap3kSIGh yAB/Wd1o8FeZ+77oC4w7xqq512+6JuVoEuF25l9iklXS4jAMXaWYGu+OsiMgQph1UHcx B0G3txl5NinPAiLZM8GbyosVS9XLelblObp79Z63+5XF9PJTLYdTUh+aJme/Rd9/vA6d o03aTL5rcJ+D918CU7RsI39Ip5Xj6PNIW/vPYrxI37FThPb39aXQChhF+GVHM3cSKzcv mQYvBypmTSjN2+SibaIiGHG0N0KylBtfeXgfWU7cz+gVbRD0CMCEw2Bh+GYtVhqPd7Al rhSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x4si2756217pll.61.2021.04.30.00.57.14; Fri, 30 Apr 2021 00:57:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231195AbhD3H53 (ORCPT + 99 others); Fri, 30 Apr 2021 03:57:29 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:17829 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230433AbhD3H5V (ORCPT ); Fri, 30 Apr 2021 03:57:21 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FWl4T0sKbzBtKK; Fri, 30 Apr 2021 15:54:01 +0800 (CST) Received: from huawei.com (10.175.113.32) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Fri, 30 Apr 2021 15:56:21 +0800 From: Nanyong Sun To: , , CC: , , , , , Subject: [PATCH -next 1/4] riscv: mm: add _PAGE_LEAF macro Date: Fri, 30 Apr 2021 16:28:47 +0800 Message-ID: <20210430082850.462609-2-sunnanyong@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210430082850.462609-1-sunnanyong@huawei.com> References: <20210430082850.462609-1-sunnanyong@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.32] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In riscv, a page table entry is leaf when any bit of read, write, or execute bit is set. So add a macro:_PAGE_LEAF instead of (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC), which is frequently used to determine if it is a leaf page. This make code easier to read, without any functional change. Signed-off-by: Nanyong Sun --- arch/riscv/include/asm/pgtable-64.h | 3 +-- arch/riscv/include/asm/pgtable-bits.h | 5 +++++ arch/riscv/include/asm/pgtable.h | 6 ++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h index f3b0da64c..e3b7c5dd6 100644 --- a/arch/riscv/include/asm/pgtable-64.h +++ b/arch/riscv/include/asm/pgtable-64.h @@ -46,8 +46,7 @@ static inline int pud_bad(pud_t pud) #define pud_leaf pud_leaf static inline int pud_leaf(pud_t pud) { - return pud_present(pud) && - (pud_val(pud) & (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC)); + return pud_present(pud) && (pud_val(pud) & _PAGE_LEAF); } static inline void set_pud(pud_t *pudp, pud_t pud) diff --git a/arch/riscv/include/asm/pgtable-bits.h b/arch/riscv/include/asm/pgtable-bits.h index bbaeb5d35..2ee413912 100644 --- a/arch/riscv/include/asm/pgtable-bits.h +++ b/arch/riscv/include/asm/pgtable-bits.h @@ -39,5 +39,10 @@ #define _PAGE_CHG_MASK (~(unsigned long)(_PAGE_PRESENT | _PAGE_READ | \ _PAGE_WRITE | _PAGE_EXEC | \ _PAGE_USER | _PAGE_GLOBAL)) +/* + * when all of R/W/X are zero, the PTE is a pointer to the next level + * of the page table; otherwise, it is a leaf PTE. + */ +#define _PAGE_LEAF (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC) #endif /* _ASM_RISCV_PGTABLE_BITS_H */ diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 80e63a93e..f489e412f 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -166,8 +166,7 @@ static inline int pmd_bad(pmd_t pmd) #define pmd_leaf pmd_leaf static inline int pmd_leaf(pmd_t pmd) { - return pmd_present(pmd) && - (pmd_val(pmd) & (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC)); + return pmd_present(pmd) && (pmd_val(pmd) & _PAGE_LEAF); } static inline void set_pmd(pmd_t *pmdp, pmd_t pmd) @@ -243,8 +242,7 @@ static inline int pte_exec(pte_t pte) static inline int pte_huge(pte_t pte) { - return pte_present(pte) - && (pte_val(pte) & (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC)); + return pte_present(pte) && (pte_val(pte) & _PAGE_LEAF); } static inline int pte_dirty(pte_t pte) -- 2.25.1