Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3519501pxb; Mon, 24 Jan 2022 11:15:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJw2qiIpFxUcGdgHNisV8QzCEQ6EhJeNpCdtOT1T6UG3njJM9eabbhKKSB+f9N1xa4kJX9xf X-Received: by 2002:a17:902:bcc8:b0:14b:14c8:e82c with SMTP id o8-20020a170902bcc800b0014b14c8e82cmr15115232pls.24.1643051756611; Mon, 24 Jan 2022 11:15:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643051756; cv=none; d=google.com; s=arc-20160816; b=lg4gxUqjsdAhjghFL/y9Xyj5M7rRkW31B6kF7HXZvmfHO9OrhsX+xR5WxQeYubwN/p VMNVm2A0VCoqNwj0KagcJwlWxOGelxF79Ch2hNPaPgpIr2qhyvsC9QhEe+fRS/spTyAE yB2tuTbbwfBVaRwOnPf9GC/Bjd4Z33DVnCUbjohmhV7ZBugy5tZcUA39UGC9uZyzwXyv qvQrViHuz9SS3XXdSvcoEu6eTWjxcRuha2xnq6HOheR/OHYnl3FEHHBgrKfoXZYTppMQ lvZt7y/3cYHhGBUKA8KGV7wG5bcn+3oVokyM5yPgb+Jv+DFIyklZ6qDLa/jr/QgfFlQy LP3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=RkewCVdlSZ7VI7OwBmc1MbBjH/Vm4dCxO/GLpoPLJ/A=; b=d/MB569i3pOYL8cpHPBgyNXXyYFb7J0bFwCxvSHlIIeKvVMKg4aOeJDhG/6XD0srxJ ORG6AXgYoEZwe54pI6ZSF6TtKE4B1ox5C38oGK4ttFNswGPxENWdygl+6NdKGkR0f6Za +6PP8Zdb/bl/frXmRWQs2EQ8/WLiKxAxoGjsnURz5yqMA6SqlkLzIlfpM7+WqNjmDBct 6YXetkh76cmxaloGHLlhpE4cQ+b1ayDBZ1HW9GeKjo+sqqfXKP80ZndeTeXkX30WcG0x Ar/t6stzb3mMfxay7GW/K8/VNJBonl46dMhrNuO+FATtOfo1HhG2QDJ6pgOfwe/9005L 5Oyg== 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=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c136si12401063pfc.67.2022.01.24.11.15.42; Mon, 24 Jan 2022 11:15:56 -0800 (PST) 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=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242925AbiAXM7h (ORCPT + 99 others); Mon, 24 Jan 2022 07:59:37 -0500 Received: from foss.arm.com ([217.140.110.172]:33302 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242971AbiAXM7M (ORCPT ); Mon, 24 Jan 2022 07:59:12 -0500 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.25.1