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=-13.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 CA664C388F7 for ; Tue, 10 Nov 2020 18:06:57 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3C67A20797 for ; Tue, 10 Nov 2020 18:06:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="PMHCMAep"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="V79NEawH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C67A20797 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=pZPp7hh6WBQyAzmXgd58sjB3AEtefFCs/ImEaQk0LlU=; b=PMHCMAep5isUtUH6n61PfFhAV+ eYhMfCLIyVn2Eat1ILy42cs4Za+n1dbclsbh2JT4qwKs3Th9b41HM9pAGd8ooa2dwHUlTKUQ66YNK aDJRCukDjcZFzGUieH89rRkuDlbSvpSTVQXMvTnTw+NUGtPbkMydfRA/pBfYExEcQ0OHmbZUc7NhU Jiy76r3iGXDTqxI4lAEY6JVYeiO7QyPuMPAUIyLnAvV7r377ELacYxDj7dc94W5uFPTXiSpg/ghEf bvlaP8gbGa6YwXoLjbOw4BKXckNKP1yK/+4r4E2H8abQexRpX5yUprb/JljYpZebup1M67vUL3ZaQ hG3n9VpA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcY1F-0007wc-IE; Tue, 10 Nov 2020 18:05:25 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcY1D-0007w1-4v for linux-arm-kernel@lists.infradead.org; Tue, 10 Nov 2020 18:05:23 +0000 Received: from localhost.localdomain (82-64-249-211.subs.proxad.net [82.64.249.211]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 95C8120797; Tue, 10 Nov 2020 18:05:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605031522; bh=KZvVG95mFvLJFhyEnaSuwyYtRmUz2vvNomLldmZ/qh8=; h=From:To:Cc:Subject:Date:From; b=V79NEawHtYuZjVk0t/eQWBYKZCKdCzqp8Ums5kHOZMQQ35nzGhwDnp8fC3h7kICB0 MghvJ7HqfbapdR6txLM07mxiP93/6xJAIiqrovVaVUPlnqnYhDLUutjLgF8QAmXjuN GE7eUCz9TOvioMg7bQfkzZaMCGwYPmiw9xXPwfVE= From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] arm64: mm: don't assume struct page is always 64 bytes Date: Tue, 10 Nov 2020 19:05:11 +0100 Message-Id: <20201110180511.29083-1-ardb@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201110_130523_283310_CCA27672 X-CRM114-Status: GOOD ( 15.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: catalin.marinas@arm.com, will@kernel.org, Ard Biesheuvel , geert@linux-m68k.org, steve.capper@arm.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Commit 8c96400d6a39be7 simplified the page-to-virt and virt-to-page conversions, based on the assumption that struct page is always 64 bytes in size, in which case we can use a single signed shift to perform the conversion (provided that the vmemmap array is placed appropriately in the kernel VA space) Unfortunately, this assumption turns out not to hold, and so we need to revert part of this commit, and go back to an affine transformation. Given that all the quantities involved are compile time constants, this should not make any practical difference. Reported-by: Geert Uytterhoeven Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/memory.h | 8 +++++--- arch/arm64/mm/init.c | 2 -- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 03e9b112bd94..556cb2d62b5b 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -308,13 +308,15 @@ static inline void *phys_to_virt(phys_addr_t x) #else #define page_to_virt(x) ({ \ __typeof__(x) __page = x; \ - u64 __addr = (u64)__page << VMEMMAP_SHIFT; \ + u64 __idx = ((u64)__page - VMEMMAP_START) / sizeof(struct page);\ + u64 __addr = PAGE_OFFSET + (__idx * PAGE_SIZE); \ (void *)__tag_set((const void *)__addr, page_kasan_tag(__page));\ }) #define virt_to_page(x) ({ \ - u64 __addr = __tag_reset((u64)(x)) & PAGE_MASK; \ - (struct page *)((s64)__addr >> VMEMMAP_SHIFT); \ + u64 __idx = (__tag_reset((u64)x) - PAGE_OFFSET) / PAGE_SIZE; \ + u64 __addr = VMEMMAP_START + (__idx * sizeof(struct page)); \ + (struct page *)__addr; \ }) #endif /* !CONFIG_SPARSEMEM_VMEMMAP || CONFIG_DEBUG_VIRTUAL */ diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 3a5e9f9298e9..7e15d92836d8 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -502,8 +502,6 @@ static void __init free_unused_memmap(void) */ void __init mem_init(void) { - BUILD_BUG_ON(!is_power_of_2(sizeof(struct page))); - if (swiotlb_force == SWIOTLB_FORCE || max_pfn > PFN_DOWN(arm64_dma_phys_limit ? : arm64_dma32_phys_limit)) swiotlb_init(1); -- 2.20.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel