Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2712267pxb; Thu, 3 Feb 2022 12:30:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJyivJXxns7Eh1U4LyebeRfVxTksveSzBK+3+bN9ft3eCVDrayE2vO/NH6RPyUyBLWJihJ45 X-Received: by 2002:a17:90b:3ece:: with SMTP id rm14mr11572623pjb.220.1643920256138; Thu, 03 Feb 2022 12:30:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643920256; cv=none; d=google.com; s=arc-20160816; b=ct9EBG532t4c/CowE3q7uty59JhzygY6oDR6E2QM/Ycneup+B9BBE8v4hykb5C7kHF ZJv5+2fVjFOt6Id4sMHNHddXRQUQhWVEK/eKS37Xja5Hw9R+mMMLOzFwG+7R/QHXsS5K dy4j3FNQPgLeliKMF6FWAdZjIUDHubCo5PmJC/hAFy2QzPp14xK4w4I+QLA+MNgCE1N0 Y8EcSLs4FhRvN01PCroEIwyS4GpPtV4IzTQ3wg2An/hwhDFEH4chD0SRL7iUUTGOWcfh 6fQLhWuL5tzEPoF80wKuwkKrNDn6YQPjuIBILzsGeUkD/vd1B/lpra3JQsCNhWVy+Tdb hX/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=0XQrcne1OeLwtG7c+SuRiiAs/iFwST52MfQyczNUq2M=; b=fo1DL6XREbf9+iQJXLoOZN81pQy4mZt/9k73Erupt++RwA11Zv0sIGYktFm9MdqATz h9X+I/1fpeFr+o4Fy0QlJhNjQTtW95c5iyK+U+bSSjaV1gaVuTIHmJPIqCGdDPnxFuN9 +QCmphvROeRG+rTPKz4GMqZRK3Es5AtI7bF7Vwx05x37UcysWs4E615y7ZMDTl2uNPjp rDFd1aVFEcqNOKTKHrlRxRqrJ17qnvJF3IQCqppEUGlVYpHGndbgi6Kv52Clhk0aHlsV twaQQj5LbDv/g/Zc8M08xt+hnxO3uHK2KU1ZY+TToqJX+BQafx8BGD0AjwaTrjG5OYVL Arpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=n4Qn8EYh; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h10si21448055pfn.110.2022.02.03.12.30.44; Thu, 03 Feb 2022 12:30:56 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=n4Qn8EYh; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353307AbiBCSP7 (ORCPT + 99 others); Thu, 3 Feb 2022 13:15:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353288AbiBCSP4 (ORCPT ); Thu, 3 Feb 2022 13:15:56 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34687C061714 for ; Thu, 3 Feb 2022 10:15:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E7020B83500 for ; Thu, 3 Feb 2022 18:15:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E280C340E8; Thu, 3 Feb 2022 18:15:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643912153; bh=BY3UZV02Xh9Phpvcf/vyWzWl1za0GoBYITY+12OY2kw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=n4Qn8EYhsbP3e7GPUom9sYrKL/AYoHQKeoy0sQRJojfA1+H/nlD/IwU0tOCQ3lDsS TjKhyYAgqHhWCQPc2B6bYKH61/FMgjSEWkEeyT88c3t4QTwkRVy7fFpgB3NvF9oe6/ vBa1aqhZmA6bgn1D4nGKqaralwRGnD7Rx5OZC+ae6HDTeO9pgSy/ZLdX3bOwyCS7fx S2rjWgc/cfKNCi4QkZMET2M0dORLomhvoUP27SawXqvXaUC3qq/eCSQoCGHl/mhk9z 3U9O2uAflljkuQw+bXLuSOTPLPVQ05ZpaDgUjmUXTSDBvHeIwbK+d+J9FRCG1uUFk9 a6puoTle2uGkw== Date: Thu, 3 Feb 2022 20:15:43 +0200 From: Mike Rapoport To: Anshuman Khandual Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, hch@infradead.org, akpm@linux-foundation.org, Michael Ellerman , Paul Mackerras , linuxppc-dev@lists.ozlabs.org Subject: Re: [RFC V1 04/31] powerpc/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT Message-ID: References: <1643029028-12710-1-git-send-email-anshuman.khandual@arm.com> <1643029028-12710-5-git-send-email-anshuman.khandual@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1643029028-12710-5-git-send-email-anshuman.khandual@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 24, 2022 at 06:26:41PM +0530, Anshuman Khandual wrote: > This defines and exports a platform specific custom vm_get_page_prot() via > subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX > macros can be dropped which are no longer needed. While here, this also > localizes arch_vm_get_page_prot() as powerpc_vm_get_page_prot(). > > Cc: Michael Ellerman > Cc: Paul Mackerras > Cc: linuxppc-dev@lists.ozlabs.org > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Anshuman Khandual > --- > arch/powerpc/Kconfig | 1 + > arch/powerpc/include/asm/mman.h | 3 +- > arch/powerpc/include/asm/pgtable.h | 19 ------------ > arch/powerpc/mm/mmap.c | 47 ++++++++++++++++++++++++++++++ > 4 files changed, 49 insertions(+), 21 deletions(-) > > diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig > index b779603978e1..ddb4a3687c05 100644 > --- a/arch/powerpc/Kconfig > +++ b/arch/powerpc/Kconfig > @@ -135,6 +135,7 @@ config PPC > select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST > select ARCH_HAS_UACCESS_FLUSHCACHE > select ARCH_HAS_UBSAN_SANITIZE_ALL > + select ARCH_HAS_VM_GET_PAGE_PROT > select ARCH_HAVE_NMI_SAFE_CMPXCHG > select ARCH_KEEP_MEMBLOCK > select ARCH_MIGHT_HAVE_PC_PARPORT > diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h > index 7cb6d18f5cd6..7b10c2031e82 100644 > --- a/arch/powerpc/include/asm/mman.h > +++ b/arch/powerpc/include/asm/mman.h > @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot, > } > #define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey) > > -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags) > +static inline pgprot_t powerpc_vm_get_page_prot(unsigned long vm_flags) > { > #ifdef CONFIG_PPC_MEM_KEYS > return (vm_flags & VM_SAO) ? > @@ -34,7 +34,6 @@ static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags) > return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0); > #endif > } > -#define arch_vm_get_page_prot(vm_flags) arch_vm_get_page_prot(vm_flags) > > static inline bool arch_validate_prot(unsigned long prot, unsigned long addr) > { > diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h > index d564d0ecd4cd..3cbb6de20f9d 100644 > --- a/arch/powerpc/include/asm/pgtable.h > +++ b/arch/powerpc/include/asm/pgtable.h > @@ -20,25 +20,6 @@ struct mm_struct; > #include > #endif /* !CONFIG_PPC_BOOK3S */ > > -/* Note due to the way vm flags are laid out, the bits are XWR */ > -#define __P000 PAGE_NONE > -#define __P001 PAGE_READONLY > -#define __P010 PAGE_COPY > -#define __P011 PAGE_COPY > -#define __P100 PAGE_READONLY_X > -#define __P101 PAGE_READONLY_X > -#define __P110 PAGE_COPY_X > -#define __P111 PAGE_COPY_X > - > -#define __S000 PAGE_NONE > -#define __S001 PAGE_READONLY > -#define __S010 PAGE_SHARED > -#define __S011 PAGE_SHARED > -#define __S100 PAGE_READONLY_X > -#define __S101 PAGE_READONLY_X > -#define __S110 PAGE_SHARED_X > -#define __S111 PAGE_SHARED_X > - > #ifndef __ASSEMBLY__ > > #ifndef MAX_PTRS_PER_PGD > diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c > index c475cf810aa8..7f05e7903bd2 100644 > --- a/arch/powerpc/mm/mmap.c > +++ b/arch/powerpc/mm/mmap.c > @@ -254,3 +254,50 @@ void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) > mm->get_unmapped_area = arch_get_unmapped_area_topdown; > } > } > + > +static inline pgprot_t __vm_get_page_prot(unsigned long vm_flags) > +{ > + switch (vm_flags & (VM_READ | VM_WRITE | VM_EXEC | VM_SHARED)) { > + case VM_NONE: > + return PAGE_NONE; > + case VM_READ: > + return PAGE_READONLY; > + case VM_WRITE: > + return PAGE_COPY; > + case VM_READ | VM_WRITE: > + return PAGE_COPY; > + case VM_EXEC: > + return PAGE_READONLY_X; > + case VM_EXEC | VM_READ: > + return PAGE_READONLY_X; > + case VM_EXEC | VM_WRITE: > + return PAGE_COPY_X; > + case VM_EXEC | VM_READ | VM_WRITE: > + return PAGE_COPY_X; > + case VM_SHARED: > + return PAGE_NONE; > + case VM_SHARED | VM_READ: > + return PAGE_READONLY; > + case VM_SHARED | VM_WRITE: > + return PAGE_SHARED; > + case VM_SHARED | VM_READ | VM_WRITE: > + return PAGE_SHARED; > + case VM_SHARED | VM_EXEC: > + return PAGE_READONLY_X; > + case VM_SHARED | VM_EXEC | VM_READ: > + return PAGE_READONLY_X; > + case VM_SHARED | VM_EXEC | VM_WRITE: > + return PAGE_SHARED_X; > + case VM_SHARED | VM_EXEC | VM_READ | VM_WRITE: > + return PAGE_SHARED_X; > + default: > + BUILD_BUG(); > + } > +} > + > +pgprot_t vm_get_page_prot(unsigned long vm_flags) > +{ > + return __pgprot(pgprot_val(__vm_get_page_prot(vm_flags)) | > + pgprot_val(powerpc_vm_get_page_prot(vm_flags))); Any reason to keep powerpc_vm_get_page_prot() rather than open code it here? This applies to other architectures that implement arch_vm_get_page_prot() and/or arch_filter_pgprot() as well. > +} > +EXPORT_SYMBOL(vm_get_page_prot); > -- > 2.25.1 > > -- Sincerely yours, Mike.