From patchwork Mon Oct 14 10:58:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13834924 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2A619D16256 for ; Mon, 14 Oct 2024 12:31:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1Pv7dW4G5U3czwTGJgTczogiNPWDVKQoCd/L9alqD4s=; b=cTpnYKdt7sU4/q3+W/MfO8vuVg 1hF7vO5NdhLf/MMt5T2Yo/Jp4YJDB4XqAyOIswesQdw5b/DKUfgCmgij5SwiBkLmk8bCnslOqMJhD QodT3QJcJxguEpaZdY5eRQnuA5J9rqboBiS/8jCoWMBAYn3sFB9nLhYP9n7oIH2l6+ofQcjD268Lh WvsclfBNrBh4DvB7Ra42aZkV9xpGJBHRJSMfcHBQ+U3hxZqqUvm0CNFN0EMjHTV+9cgQ7jhJEHFsm qxJdxRTwQEXd36fftWdFAXT97cREu4coVkgVMYdvH2UySj8IwoUdpk3IkPCmpz4Ye8Ixuxfzo3fTa FhKKmolQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t0KEX-000000055ao-2ux6; Mon, 14 Oct 2024 12:31:33 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t0Ipm-00000004oc2-1eFQ for linux-arm-kernel@lists.infradead.org; Mon, 14 Oct 2024 11:01:55 +0000 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 A0064176C; Mon, 14 Oct 2024 04:02:23 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 62FEC3F51B; Mon, 14 Oct 2024 04:01:51 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Catalin Marinas , David Hildenbrand , Greg Marsden , Ivan Ivanov , Kalesh Singh , Marc Zyngier , Mark Rutland , Matthias Brugger , Miroslav Benes , Oliver Upton , Will Deacon Cc: Ryan Roberts , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v1 48/57] arm64: Convert switch to if for non-const comparison values Date: Mon, 14 Oct 2024 11:58:55 +0100 Message-ID: <20241014105912.3207374-48-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241014105912.3207374-1-ryan.roberts@arm.com> References: <20241014105514.3206191-1-ryan.roberts@arm.com> <20241014105912.3207374-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241014_040154_580194_A8BF12C6 X-CRM114-Status: GOOD ( 12.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When we enable boot-time page size, some macros are no longer compile-time constants. Where these macros are used as cases in switch statements, the switch statements no longer compile. Let's convert these to if/else blocks, which can handle the runtime values. Signed-off-by: Ryan Roberts --- ***NOTE*** Any confused maintainers may want to read the cover note here for context: https://lore.kernel.org/all/20241014105514.3206191-1-ryan.roberts@arm.com/ arch/arm64/kvm/mmu.c | 32 +++++++++++++++----------------- arch/arm64/mm/hugetlbpage.c | 34 +++++++++++----------------------- 2 files changed, 26 insertions(+), 40 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index a509b63bd4dd5..248a2d7ad6dbb 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1487,29 +1487,27 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, vma_shift = get_vma_page_shift(vma, hva); } - switch (vma_shift) { #ifndef __PAGETABLE_PMD_FOLDED - case PUD_SHIFT: - if (fault_supports_stage2_huge_mapping(memslot, hva, PUD_SIZE)) - break; - fallthrough; + if (vma_shift == PUD_SHIFT) { + if (!fault_supports_stage2_huge_mapping(memslot, hva, PUD_SIZE)) + vma_shift = PMD_SHIFT; + } #endif - case CONT_PMD_SHIFT: + if (vma_shift == CONT_PMD_SHIFT) { vma_shift = PMD_SHIFT; - fallthrough; - case PMD_SHIFT: - if (fault_supports_stage2_huge_mapping(memslot, hva, PMD_SIZE)) - break; - fallthrough; - case CONT_PTE_SHIFT: + } + if (vma_shift == PMD_SHIFT) { + if (!fault_supports_stage2_huge_mapping(memslot, hva, PMD_SIZE)) + vma_shift = PAGE_SHIFT; + } + if (vma_shift == CONT_PTE_SHIFT) { vma_shift = PAGE_SHIFT; force_pte = true; - fallthrough; - case PAGE_SHIFT: - break; - default: - WARN_ONCE(1, "Unknown vma_shift %d", vma_shift); } + if (vma_shift != PUD_SHIFT && + vma_shift != PMD_SHIFT && + vma_shift != PAGE_SHIFT) + WARN_ONCE(1, "Unknown vma_shift %d", vma_shift); vma_pagesize = 1UL << vma_shift; diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index 5f1e2103888b7..bc98c20655bba 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -51,16 +51,12 @@ void __init arm64_hugetlb_cma_reserve(void) static bool __hugetlb_valid_size(unsigned long size) { - switch (size) { #ifndef __PAGETABLE_PMD_FOLDED - case PUD_SIZE: + if (size == PUD_SIZE) return pud_sect_supported(); #endif - case CONT_PMD_SIZE: - case PMD_SIZE: - case CONT_PTE_SIZE: + if (size == CONT_PMD_SIZE || size == PMD_SIZE || size == CONT_PTE_SIZE) return true; - } return false; } @@ -104,24 +100,20 @@ static inline int num_contig_ptes(unsigned long size, size_t *pgsize) *pgsize = size; - switch (size) { #ifndef __PAGETABLE_PMD_FOLDED - case PUD_SIZE: + if (size == PUD_SIZE) { if (pud_sect_supported()) contig_ptes = 1; - break; + } else #endif - case PMD_SIZE: + if (size == PMD_SIZE) { contig_ptes = 1; - break; - case CONT_PMD_SIZE: + } else if (size == CONT_PMD_SIZE) { *pgsize = PMD_SIZE; contig_ptes = CONT_PMDS; - break; - case CONT_PTE_SIZE: + } else if (size == CONT_PTE_SIZE) { *pgsize = PAGE_SIZE; contig_ptes = CONT_PTES; - break; } return contig_ptes; @@ -339,20 +331,16 @@ unsigned long hugetlb_mask_last_page(struct hstate *h) { unsigned long hp_size = huge_page_size(h); - switch (hp_size) { #ifndef __PAGETABLE_PMD_FOLDED - case PUD_SIZE: + if (hp_size == PUD_SIZE) return PGDIR_SIZE - PUD_SIZE; #endif - case CONT_PMD_SIZE: + if (hp_size == CONT_PMD_SIZE) return PUD_SIZE - CONT_PMD_SIZE; - case PMD_SIZE: + if (hp_size == PMD_SIZE) return PUD_SIZE - PMD_SIZE; - case CONT_PTE_SIZE: + if (hp_size == CONT_PTE_SIZE) return PMD_SIZE - CONT_PTE_SIZE; - default: - break; - } return 0UL; }