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 D474FEB64D9 for ; Sun, 2 Jul 2023 19:52:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=48LJnYKDosWc2DezMLIuMkaqAp59tWkpCv9qEHfIHkc=; b=qxOdFQg2aSVHmF ZzjS13OEdFuQYwGb4IfB+whJUJUccZ5GeoDy34NURH6nNWJsLWqcccjuXMIgdRDEz/POIJKItWP3L MWeejlNNTpB75yDv2tYkzUQvMs/CzIzdPMTXIjKy1wo/QQ00lB2iT2L8qgDXvWa5jKEIsxXpl5GI4 lb5KEP0ZrxKpWUCJoLGzY77vAV5xQxhWr4otdS6Tpl5myc91qTxwEnsvr4WgBKYrkNEayBklRNaN8 v9YEqPF5VfjN6/JMkbQ1lQkTF/e9dvwptcKXgnSioFQDcOYfH1jtcOYrmVm+ZBNOFzTrFmMxNCiOJ iXAFtcV52uee9qGsV0tw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qG37P-008WTo-0B; Sun, 02 Jul 2023 19:52:23 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qG37L-008WSA-35 for linux-arm-kernel@lists.infradead.org; Sun, 02 Jul 2023 19:52:21 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7194960CF7; Sun, 2 Jul 2023 19:52:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 239F6C433C7; Sun, 2 Jul 2023 19:52:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688327538; bh=uvw7GrQ1XDLvop8eHF6Yxz3fQb5epaLTvh23lQtRsdE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YLxOshtcbxvS2uvteV9Pv0JvgwdGNn2fLzdiSt9zx1IkSu2gZ2kBat0jb5TwOSvm3 rbpfvZTJs6U+bDF4vcAN8K+uTMY5zr9tPZSbs7sSt9xcHl3h2+eXfKoPTPULBbRT/9 zAi3YwzgoX9b9ODCazy6PXfhunDPIThv5BuDdt1dTvzLhtu8gjq0U9aIYKsRB+OG+g AbhqMQQ0BV6JBurgKbEBAZQKYajYbkeYwL0sjGOv+kv4IvhgKH5/uLZNKbwJTjwQK6 AFQ4vbmlBlUfRuyIDrwvF6tSIajXOhncjEwEJhvNH/XMqExyJagItc9c9cM6C+GTu5 +EGEOGbhYTOdQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mark Rutland , Russell King , Steve Capper , Will Deacon , Russell King , Catalin Marinas , Sasha Levin , anshuman.khandual@arm.com, wangkefeng.wang@huawei.com, quic_zhenhuah@quicinc.com, chenfeiyang@loongson.cn, bhe@redhat.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 6.1 7/9] arm64: mm: fix VA-range sanity check Date: Sun, 2 Jul 2023 15:51:54 -0400 Message-Id: <20230702195159.1788402-7-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230702195159.1788402-1-sashal@kernel.org> References: <20230702195159.1788402-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.37 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230702_125220_078315_D66A01B3 X-CRM114-Status: GOOD ( 20.85 ) 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: , 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 From: Mark Rutland [ Upstream commit ab9b4008092c86dc12497af155a0901cc1156999 ] Both create_mapping_noalloc() and update_mapping_prot() sanity-check their 'virt' parameter, but the check itself doesn't make much sense. The condition used today appears to be a historical accident. The sanity-check condition: if ((virt >= PAGE_END) && (virt < VMALLOC_START)) { [ ... warning here ... ] return; } ... can only be true for the KASAN shadow region or the module region, and there's no reason to exclude these specifically for creating and updateing mappings. When arm64 support was first upstreamed in commit: c1cc1552616d0f35 ("arm64: MMU initialisation") ... the condition was: if (virt < VMALLOC_START) { [ ... warning here ... ] return; } At the time, VMALLOC_START was the lowest kernel address, and this was checking whether 'virt' would be translated via TTBR1. Subsequently in commit: 14c127c957c1c607 ("arm64: mm: Flip kernel VA space") ... the condition was changed to: if ((virt >= VA_START) && (virt < VMALLOC_START)) { [ ... warning here ... ] return; } This appear to have been a thinko. The commit moved the linear map to the bottom of the kernel address space, with VMALLOC_START being at the halfway point. The old condition would warn for changes to the linear map below this, and at the time VA_START was the end of the linear map. Subsequently we cleaned up the naming of VA_START in commit: 77ad4ce69321abbe ("arm64: memory: rename VA_START to PAGE_END") ... keeping the erroneous condition as: if ((virt >= PAGE_END) && (virt < VMALLOC_START)) { [ ... warning here ... ] return; } Correct the condition to check against the start of the TTBR1 address space, which is currently PAGE_OFFSET. This simplifies the logic, and more clearly matches the "outside kernel range" message in the warning. Signed-off-by: Mark Rutland Cc: Russell King Cc: Steve Capper Cc: Will Deacon Reviewed-by: Russell King (Oracle) Link: https://lore.kernel.org/r/20230615102628.1052103-1-mark.rutland@arm.com Signed-off-by: Catalin Marinas Signed-off-by: Sasha Levin --- arch/arm64/mm/mmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 9a7c389651540..8c3a99c2bd1f2 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -449,7 +449,7 @@ static phys_addr_t pgd_pgtable_alloc(int shift) static void __init create_mapping_noalloc(phys_addr_t phys, unsigned long virt, phys_addr_t size, pgprot_t prot) { - if ((virt >= PAGE_END) && (virt < VMALLOC_START)) { + if (virt < PAGE_OFFSET) { pr_warn("BUG: not creating mapping for %pa at 0x%016lx - outside kernel range\n", &phys, virt); return; @@ -476,7 +476,7 @@ void __init create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys, static void update_mapping_prot(phys_addr_t phys, unsigned long virt, phys_addr_t size, pgprot_t prot) { - if ((virt >= PAGE_END) && (virt < VMALLOC_START)) { + if (virt < PAGE_OFFSET) { pr_warn("BUG: not updating mapping for %pa at 0x%016lx - outside kernel range\n", &phys, virt); return; -- 2.39.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel