From patchwork Mon Jan 24 12:57:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 12722094 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 7B961C433F5 for ; Mon, 24 Jan 2022 12:59:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 117C06B00C8; Mon, 24 Jan 2022 07:59:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C79F6B00C9; Mon, 24 Jan 2022 07:59:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F204B6B00CA; Mon, 24 Jan 2022 07:59:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id E171A6B00C8 for ; Mon, 24 Jan 2022 07:59:13 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AFC3520B2C for ; Mon, 24 Jan 2022 12:59:13 +0000 (UTC) X-FDA: 79065186186.03.890D1DE Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf27.hostedemail.com (Postfix) with ESMTP id C702640002 for ; Mon, 24 Jan 2022 12:59:12 +0000 (UTC) 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 490841396; Mon, 24 Jan 2022 04:59:12 -0800 (PST) Received: from p8cg001049571a15.arm.com (unknown [10.163.43.190]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DCC033F774; Mon, 24 Jan 2022 04:59:09 -0800 (PST) From: Anshuman Khandual To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, hch@infradead.org, akpm@linux-foundation.org, Anshuman Khandual Subject: [RFC V1 31/31] mm/mmap: Define macros for vm_flags access permission combinations Date: Mon, 24 Jan 2022 18:27:08 +0530 Message-Id: <1643029028-12710-32-git-send-email-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1643029028-12710-1-git-send-email-anshuman.khandual@arm.com> References: <1643029028-12710-1-git-send-email-anshuman.khandual@arm.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C702640002 X-Stat-Signature: 9ceu5jtxf6y6fijjjr5f8zfjwxbz3co9 Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf27.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com X-HE-Tag: 1643029152-529254 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: These macros will be useful in cleaning up the all those switch statements in vm_get_page_prot() across all platforms. Cc: Andrew Morton Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- include/linux/mm.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 6c0844b99b3e..b3691eeec500 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2828,6 +2828,45 @@ static inline bool range_in_vma(struct vm_area_struct *vma, return (vma && vma->vm_start <= start && end <= vma->vm_end); } +/* + * Access permission related vm_flags combination is used to map into + * platform defined page protection flags. This enumeration helps in + * abstracting out possible indices after vm_flags is probed for all + * access permission i.e (VM_SHARED | VM_EXEC | VM_READ | VM_WRITE). + * + * VM_EXEC ---------------------| + * | + * VM_WRITE ---------------| | + * | | + * VM_READ -----------| | | + * | | | + * VM_SHARED ----| | | | + * | | | | + * v v v v + * VMFLAGS_IDX_(S|X)(R|X)(W|X)(E|X) + * + * X - Indicates that the access flag is absent + */ +enum vmflags_idx { + VMFLAGS_IDX_XXXX, /* (VM_NONE) */ + VMFLAGS_IDX_XRXX, /* (VM_READ) */ + VMFLAGS_IDX_XXWX, /* (VM_WRITE) */ + VMFLAGS_IDX_XRWX, /* (VM_READ | VM_WRITE) */ + VMFLAGS_IDX_XXXE, /* (VM_EXEC) */ + VMFLAGS_IDX_XRXE, /* (VM_EXEC | VM_READ) */ + VMFLAGS_IDX_XXWE, /* (VM_EXEC | VM_WRITE) */ + VMFLAGS_IDX_XRWE, /* (VM_EXEC | VM_READ | VM_WRITE) */ + VMFLAGS_IDX_SXXX, /* (VM_SHARED | VM_NONE) */ + VMFLAGS_IDX_SRXX, /* (VM_SHARED | VM_READ) */ + VMFLAGS_IDX_SXWX, /* (VM_SHARED | VM_WRITE) */ + VMFLAGS_IDX_SRWX, /* (VM_SHARED | VM_READ | VM_WRITE) */ + VMFLAGS_IDX_SXXE, /* (VM_SHARED | VM_EXEC) */ + VMFLAGS_IDX_SRXE, /* (VM_SHARED | VM_EXEC | VM_READ) */ + VMFLAGS_IDX_SXWE, /* (VM_SHARED | VM_EXEC | VM_WRITE) */ + VMFLAGS_IDX_SRWE, /* (VM_SHARED | VM_EXEC | VM_READ | VM_WRITE) */ + VMFLAGS_IDX_MAX +}; + #ifdef CONFIG_MMU pgprot_t vm_get_page_prot(unsigned long vm_flags); void vma_set_page_prot(struct vm_area_struct *vma);