Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3318131pxb; Fri, 4 Feb 2022 06:13:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJz6kaWYFpdOS58vsKFeIysFeT2AJODdKRUDiHkJRvemM4m2bLzqQgX6WRX6wftWTaJP8Zh3 X-Received: by 2002:a17:90a:de10:: with SMTP id m16mr3267069pjv.157.1643983985839; Fri, 04 Feb 2022 06:13:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643983985; cv=none; d=google.com; s=arc-20160816; b=v5LlVn9poxb3E8puEoUqBKGofg9VTpwKjLlvv8Ti2aASnB2Tb14rjsTO0XhNv13h+3 2O/sXCblziOJhmH1M/sQ1ya0xwffSHxavz5mGOoQMJ8Knyxno3s5FFdoU2SZQhHyVRaa DSiR/DKxmv+/3BIpj0MHkclLYLUwcMx01rgtdyW26PPn/8Hg3JQECZ+ml2r1zHNjyB06 12XCPIaCt27CP1LEWAa7Ohik7CDQVTuubU49G2WM1TXqI7lpJsUdG90EhqV85CSeSnml kikQ4aiaDY+tofoRVa7u/MSjtSK8gLSX1boYuwFzuEqXDE2PstSjm2xj96HGsd7V+SCt kGLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=LXt7F4SY9mUaI4My+l7zyPUtIO4tjdFdHq6AbcaRwiU=; b=wxSQeSGncXMPPz8d6Wr9PJHbV6KrmOqbPY+hNtZhOmeTxH9KaByCTKz7H+vGy7qBvk NNdJ9RWDZJerOsS+YUuB4HSURBHk4K3OHVswEPr04atDIaF9U082ZBvHsLCc4QXSDcDt lMmNhPkiJrYvInjYe3Bexf5WxkcXAxJ7ismn0QO+DSFsnnV11r3on72+rsu6Z+GI63qa GufkNeyqd18TYylUOLmXOENnVN88iWZ/NzZf/Bq8XHLhxbUL22r2Earkdh18UrP/tLY3 OXCBt7rS26KTB8K7Kcki/7n0VHneVgNBOtjGBDf9vZLxAjD84f1jKLFIfFnzuCFeye89 qiqA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y70si1981701pgd.810.2022.02.04.06.12.49; Fri, 04 Feb 2022 06:13:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235230AbiBCFYW (ORCPT + 99 others); Thu, 3 Feb 2022 00:24:22 -0500 Received: from foss.arm.com ([217.140.110.172]:50426 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229872AbiBCFYT (ORCPT ); Thu, 3 Feb 2022 00:24:19 -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 24D841FB; Wed, 2 Feb 2022 21:24:19 -0800 (PST) Received: from [10.163.44.35] (unknown [10.163.44.35]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CAF003F774; Wed, 2 Feb 2022 21:24:17 -0800 (PST) Subject: Re: [RFC V1 31/31] mm/mmap: Define macros for vm_flags access permission combinations To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, hch@infradead.org, akpm@linux-foundation.org References: <1643029028-12710-1-git-send-email-anshuman.khandual@arm.com> <1643029028-12710-32-git-send-email-anshuman.khandual@arm.com> From: Anshuman Khandual Message-ID: <53026c47-4bfa-44fe-1cba-f9c78d901a02@arm.com> Date: Thu, 3 Feb 2022 10:54:14 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <1643029028-12710-32-git-send-email-anshuman.khandual@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/24/22 6:27 PM, Anshuman Khandual wrote: > 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 > +}; Defining platform specific vm_get_page_prot() involves a switch statement with various vm_flags access combinations as cases. Hence I am wondering, will it help to use these above macros, instead of existing combinations separated with '|' flags. I can move this patch earlier in the series and change all platform switch cases. Please do suggest. Thank you. - Anshuman