Received: by 2002:ac8:3b51:0:b0:3f3:9eb6:4eb6 with SMTP id r17csp11480063qtf; Sun, 2 Jul 2023 13:00:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlEyYKbxgMSU/j8/FQZ9fttKQ6Bu2Vce/oK5AMXSoxZ2Hq6Fi1JtEI7PRqpH4vMYBRu323HI X-Received: by 2002:a05:6a21:3298:b0:125:687a:1c5d with SMTP id yt24-20020a056a21329800b00125687a1c5dmr10942671pzb.60.1688328035597; Sun, 02 Jul 2023 13:00:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688328035; cv=none; d=google.com; s=arc-20160816; b=fLzk5tpB3oxIqxVtFOiBOSYmnOaR0SoLpW40fZO2YeYDFc5Kk3C5AsOZIXBzn8XB7f 5ybtSY/GZiyYRnk9uP5oK8mLYkzGPtKIobSnzlZMEAxutkus6zuowMA9F7EhKxy2b7us YfoJrcesgmCfDRD+n0nF/2w+NYJb02Jo8yUSJdAls/C5eJk3tUTHE/O56e8WkDtKNlTC hgvQ+Cd8jeOg+G3fev29LgQ3HkEpVwN/jIRVxpWo0DrJLXogpf/PJnQfc1/2703D66+s A1hPCq0LOwGldokgcgV7EfzTWeCjQ4V0ZtwvyHU7H0oeoSEfcfeKRYbBSmjJM/OWFHR2 Fs+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mE8BguOiR6GV3wMWGxntFzX5Z+6dQ4/Ekj28PZqZ28c=; fh=MPYoGDVLAVmXN6YXLND93u5ZKCr/5yQ5VYA+9X8WiJg=; b=nRRWRGGuPPqFdCmUOKeR7ZoUBgxZtfFusSvULDhgITNQX+oKshfVAl4270JZocluho PVqfk65txERWX63v6saS5h8SJu1ssq+nU6AFP7vNWiuhXzEtjvZp6C7D8v5EjyQCYhq8 fX4NaynhGr2Kdx2+bgmgE5HxS9TPrCwRgHnWVv7llrQlBiHX7Gn5byEE1Sgdkcr4o+nY AG/woYhVd2RR64sr9Cc8VWRFK/baBQIxU9U8BxsONRWUSLwum/ZsrnA95X3DdOauaUel GFZprafDjIi+tdAAF5XkVRzbnzdfQl1fjUMhVT6X6fGdA0MO/GcY5tTtsOm0+sOD25is RSbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fgOcmC3X; 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 a6-20020a634d06000000b005576ebe803fsi17021199pgb.318.2023.07.02.13.00.23; Sun, 02 Jul 2023 13:00:35 -0700 (PDT) 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=fgOcmC3X; 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 S232995AbjGBTz4 (ORCPT + 99 others); Sun, 2 Jul 2023 15:55:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233000AbjGBTzo (ORCPT ); Sun, 2 Jul 2023 15:55:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ACB010C0; Sun, 2 Jul 2023 12:53:34 -0700 (PDT) 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 8298560C8E; Sun, 2 Jul 2023 19:51:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 850ACC433C8; Sun, 2 Jul 2023 19:51:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688327484; bh=Y2NWTI9uJftjAgHQHVZxvuguhSzJNoNp4tot3HJ6cJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fgOcmC3X1MjQ+UzIJBnK10shVJ3xCg3pimgU/zByAKO17yoyrHxOIASmpX6Sslkry 5KBFRaMMMWKhvLIrTL99e923GwH1Il9+45jMn+8IuZmLm2eTJjQQZB0betpBBjIuJM AzD+gxbOkxFSJwfJ0IRc7ooCb6MCCTNXWzqb2wXKjDGVY1B6jKqjStTC0IfS9RZpKX WOv6QmZn4xr4VF2Z+Fbv2MldSVgYjpJskND5wEEkwH0R5ymyhRefF7OgoE2x7UDlC6 VdtY7dzMjleYp1UgfRo6HVOUn7nNLByn4oRcTD8YE2IxokshVsUdyjLKR53PPUtIOp U1+GP1mVU85uQ== 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.4 10/12] arm64: mm: fix VA-range sanity check Date: Sun, 2 Jul 2023 15:50:55 -0400 Message-Id: <20230702195057.1787686-10-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230702195057.1787686-1-sashal@kernel.org> References: <20230702195057.1787686-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.4.1 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 af6bc8403ee46..72b3c21820b96 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -451,7 +451,7 @@ static phys_addr_t pgd_pgtable_alloc(int shift) 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; @@ -478,7 +478,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