From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8A30C432BE for ; Wed, 11 Aug 2021 10:15:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C90F860D07 for ; Wed, 11 Aug 2021 10:15:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237062AbhHKKQS convert rfc822-to-8bit (ORCPT ); Wed, 11 Aug 2021 06:16:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:54374 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236960AbhHKKOv (ORCPT ); Wed, 11 Aug 2021 06:14:51 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CB58160D07; Wed, 11 Aug 2021 10:13:31 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mDlEn-004I9g-Oc; Wed, 11 Aug 2021 11:13:29 +0100 Date: Wed, 11 Aug 2021 11:13:29 +0100 Message-ID: <87sfzg9tme.wl-maz@kernel.org> From: Marc Zyngier To: Anshuman Khandual Cc: linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/5] KVM: arm64: Drop direct PAGE_[SHIFT|SIZE] usage as page size In-Reply-To: <4a4d320e-f09c-5198-d3cb-397d837190b1@arm.com> References: <1628578961-29097-1-git-send-email-anshuman.khandual@arm.com> <1628578961-29097-2-git-send-email-anshuman.khandual@arm.com> <25ee7799069492f2501003faec7f9732@kernel.org> <0b47c654-7e9b-a7ca-bdf4-f9607062200e@arm.com> <87zgto9z9i.wl-maz@kernel.org> <4a4d320e-f09c-5198-d3cb-397d837190b1@arm.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: anshuman.khandual@arm.com, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 11 Aug 2021 10:37:36 +0100, Anshuman Khandual wrote: > > > > On 8/11/21 1:41 PM, Marc Zyngier wrote: > > On Wed, 11 Aug 2021 06:34:46 +0100, > > Anshuman Khandual wrote: > >> > >> > >> > >> On 8/10/21 7:03 PM, Marc Zyngier wrote: > >>> On 2021-08-10 08:02, Anshuman Khandual wrote: > >>>> All instances here could just directly test against CONFIG_ARM64_XXK_PAGES > >>>> instead of evaluating via PAGE_SHIFT or PAGE_SIZE. With this change, there > >>>> will be no such usage left. > >>>> > >>>> Cc: Marc Zyngier > >>>> Cc: James Morse > >>>> Cc: Alexandru Elisei > >>>> Cc: Suzuki K Poulose > >>>> Cc: Catalin Marinas > >>>> Cc: Will Deacon > >>>> Cc: linux-arm-kernel@lists.infradead.org > >>>> Cc: kvmarm@lists.cs.columbia.edu > >>>> Cc: linux-kernel@vger.kernel.org > >>>> Signed-off-by: Anshuman Khandual > >>>> --- > >>>>  arch/arm64/kvm/hyp/pgtable.c | 6 +++--- > >>>>  arch/arm64/mm/mmu.c          | 2 +- > >>>>  2 files changed, 4 insertions(+), 4 deletions(-) > >>>> > >>>> diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > >>>> index 05321f4165e3..a6112b6d6ef6 100644 > >>>> --- a/arch/arm64/kvm/hyp/pgtable.c > >>>> +++ b/arch/arm64/kvm/hyp/pgtable.c > >>>> @@ -85,7 +85,7 @@ static bool kvm_level_supports_block_mapping(u32 level) > >>>>       * Reject invalid block mappings and don't bother with 4TB mappings for > >>>>       * 52-bit PAs. > >>>>       */ > >>>> -    return !(level == 0 || (PAGE_SIZE != SZ_4K && level == 1)); > >>>> +    return !(level == 0 || (!IS_ENABLED(CONFIG_ARM64_4K_PAGES) && level == 1)); > >>>>  } > >>>> > >>>>  static bool kvm_block_mapping_supported(u64 addr, u64 end, u64 phys, u32 level) > >>>> @@ -155,7 +155,7 @@ static u64 kvm_pte_to_phys(kvm_pte_t pte) > >>>>  { > >>>>      u64 pa = pte & KVM_PTE_ADDR_MASK; > >>>> > >>>> -    if (PAGE_SHIFT == 16) > >>>> +    if (IS_ENABLED(CONFIG_ARM64_64K_PAGES)) > >>>>          pa |= FIELD_GET(KVM_PTE_ADDR_51_48, pte) << 48; > >>>> > >>>>      return pa; > >>>> @@ -165,7 +165,7 @@ static kvm_pte_t kvm_phys_to_pte(u64 pa) > >>>>  { > >>>>      kvm_pte_t pte = pa & KVM_PTE_ADDR_MASK; > >>>> > >>>> -    if (PAGE_SHIFT == 16) > >>>> +    if (IS_ENABLED(CONFIG_ARM64_64K_PAGES)) > >>>>          pte |= FIELD_PREP(KVM_PTE_ADDR_51_48, pa >> 48); > >>>> > >>>>      return pte; > >>>> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > >>>> index 9ff0de1b2b93..8fdfca179815 100644 > >>>> --- a/arch/arm64/mm/mmu.c > >>>> +++ b/arch/arm64/mm/mmu.c > >>>> @@ -296,7 +296,7 @@ static void alloc_init_cont_pmd(pud_t *pudp, > >>>> unsigned long addr, > >>>>  static inline bool use_1G_block(unsigned long addr, unsigned long next, > >>>>              unsigned long phys) > >>>>  { > >>>> -    if (PAGE_SHIFT != 12) > >>>> +    if (!IS_ENABLED(CONFIG_ARM64_4K_PAGES)) > >>>>          return false; > >>>> > >>>>      if (((addr | next | phys) & ~PUD_MASK) != 0) > >>> > >>> I personally find it a lot less readable. > >>> > >>> Also, there is no evaluation whatsoever. All the code guarded > >>> by a PAGE_SIZE/PAGE_SHIFT that doesn't match the configuration > >>> is dropped at compile time. > >> > >> The primary idea here is to unify around IS_ENABLED(CONFIG_ARM64_XXK_PAGES) > >> usage in arm64, rather than having multiple methods to test page size when > >> ever required. > > > > I'm sorry, but I find the idiom extremely painful to parse. If you are > > Okay, it was not explained very well. My bad. > > > annoyed with the 'PAGE_SHIFT == 12/14/16', consider replacing it with > > 'PAGE_SIZE == SZ_4/16/64K' instead. > > Sure, understood. But the problem here is not with PAGE_SHIFT/PAGE_SIZE > based tests but rather having multiple ways of doing the same thing in > arm64 tree. Please find further explanation below. > > > > > IS_ENABLED(CONFIG_ARM64_XXK_PAGES) also gives the wrong impression > > that *multiple* page sizes can be selected at any given time. That's > > obviously not the case, which actually makes PAGE_SIZE a much better > > choice. > > PAGE_SHIFT and PAGE_SIZE are derived from CONFIG_ARM64_XXK_PAGES. Hence > why not just directly use the original user selected config option that > eventually decides PAGE_SHIFT and PAGE_SIZE. > > config ARM64_PAGE_SHIFT > int > default 16 if ARM64_64K_PAGES > default 14 if ARM64_16K_PAGES > default 12 > > arch/arm64/include/asm/page-def.h:#define PAGE_SHIFT CONFIG_ARM64_PAGE_SHIFT > arch/arm64/include/asm/page-def.h:#define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT) I'm sorry, but that's only a build system artefact. PAGE_SIZE/SHIFT is what we use in the kernel at large, not IS_ENABLED(BLAH). It is short, to the point, and it is guaranteed to be what it says on the tin. If by some miracle you were going to enable multiple *simultaneous* page sizes support in the arm64 kernel, I'd certainly look at things differently. Thankfully, this isn't the case. > Also there are already similar IS_ENABLED() instances which do not > create much confusion. The point here being, to have just a single > method that checks compiled page size support, instead of three > different ways of doing the same thing. > > - IS_ENABLED(CONFIG_ARM64_XXK_PAGES) > - if (PAGE_SHIFT == XX) > - if (PAGE_SIZE == XX) > > $git grep IS_ENABLED arch/arm64/ | grep PAGES > > arch/arm64/include/asm/vmalloc.h: return IS_ENABLED(CONFIG_ARM64_4K_PAGES) && > arch/arm64/mm/mmu.c: BUG_ON(!IS_ENABLED(CONFIG_ARM64_16K_PAGES)); > arch/arm64/mm/mmu.c: BUG_ON(!IS_ENABLED(CONFIG_ARM64_16K_PAGES)); 3 instances are hardly a convincing argument. maz@hot-poop:~/arm-platforms$ git grep -w PAGE_SIZE | grep '== SZ' arch/powerpc/include/asm/nohash/32/mmu-8xx.h: if (PAGE_SIZE == SZ_16K) fs/btrfs/disk-io.c: if ((PAGE_SIZE == SZ_4K && sectorsize != PAGE_SIZE) || fs/btrfs/disk-io.c: (PAGE_SIZE == SZ_64K && (sectorsize != SZ_4K && fs/btrfs/disk-io.c: if (PAGE_SIZE == SZ_64K && sectorsize == SZ_4K) { Look, I win! :-) > > > > As things stand, I don't plan to take such a patch. > > Sure, will drop it from the series if the above explanation and > the rationale for the patch still does not convince you. It really doesn't. This is only a bike-shedding exercise, which introduce pointless churn. Thanks, M. -- Without deviation from the norm, progress is not possible.