Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3019107rwb; Mon, 15 Aug 2022 16:15:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR6Rg3Dg/569VwlqRb5OFfP03BwxnbgRyP9lI5Q1vcItSGD/i77Ag9m3w/gyyLfjB8btyVM6 X-Received: by 2002:a17:906:ef8c:b0:730:e4e0:1f69 with SMTP id ze12-20020a170906ef8c00b00730e4e01f69mr11875688ejb.113.1660605357695; Mon, 15 Aug 2022 16:15:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605357; cv=none; d=google.com; s=arc-20160816; b=ursyCdqOAXNdK3GTGRNkhcCMIaSB6RQF9MSidj3OTOAAcj5aj4oZ1RmBEB0fnzSchz cac7GJulWse8V8djdslMokERDcH7uJcW3tD4zk3GeIu9IjJQVpC5QSvcvMU8sMykeIv8 1inn1HS8Zw7/n1/cdAro959b93axfQl1luYCVncr6bNehRHwC/BAX/owgsuswCtMWr2+ bwPBumZh52A02TcBcwgrIO2nmyxZzBaL9D8bSW30xNJtl+O6PRJEQ/Pjb55ofYlOr6yI FjCHI2PgkCih9fzG2eHAarZrIVDGwafgo5FMmKTB0h+JG5chbVCuUM6I/bdHV4qPSlJb LRWg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tI1x5XPajkXaXgWQfhPsJA1WAm6cuurGFGGfQizHX48=; b=Z+YEOyntoyNuMYNObMz5ChmjRiAiTI8nwvEvMfHbTvxDEwI6RnS9xZxSP4+GosB2NU xlImRRTmt0nGnTfk5l6R5osgycVwnHzODl1L9WGOllJyZFZHgDIbSBulaRftlhMF1iTc cHuL1ObwzkPn29Y7ydSih13UtNS4u86551otjHYE/dUXPksetdsdtiRjIATWl0ky8QNF qkz/qggQLu8+xoqH242QjliJ5D00X9R/HQn5Ks1MMYlCwS3v15tg8yT7kLAmrLLa7LBB uio+xgiUnbhLzDbB5/2KOiKwvGCu5UJV3tdQKdIc0rtiqXRo7yx8NWjgpBGfAGSHKWXa 687w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Tf9sFFkK; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v8-20020a170906338800b007306d40ae27si7596647eja.553.2022.08.15.16.15.32; Mon, 15 Aug 2022 16:15:57 -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=@linuxfoundation.org header.s=korg header.b=Tf9sFFkK; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351206AbiHOWnZ (ORCPT + 99 others); Mon, 15 Aug 2022 18:43:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351322AbiHOWh6 (ORCPT ); Mon, 15 Aug 2022 18:37:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77A9C1322FE; Mon, 15 Aug 2022 12:51:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4F7FA61206; Mon, 15 Aug 2022 19:51:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3039CC433C1; Mon, 15 Aug 2022 19:50:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593059; bh=f1yBoZdlxrrj+e56t5SpYyY3+I6Cwa8ohg4maem5XqM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tf9sFFkKdx/lqKJtIVQZj0n3FcnqYVfZ8fmSnhiy3CoqVK4YZfZ0nrweKZIKGJb7H L/WhkuV/v08g/u+VPKhAzlk+IJo48CjgLE2Vy6ALsalT9bWv5lZReTLOSvZDdf9tnU 0MGhtZr4NELe01nchIoUgfEtAcxZnhD/UzHMYWzU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Florian Fainelli , Serge Semin , Thomas Bogendoerfer , Sasha Levin Subject: [PATCH 5.18 0886/1095] MIPS: Fixed __debug_virt_addr_valid() Date: Mon, 15 Aug 2022 20:04:45 +0200 Message-Id: <20220815180505.990184416@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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: Florian Fainelli [ Upstream commit 8a2b456665d1e797123669581524cbb095fb003b ] It is permissible for kernel code to call virt_to_phys() against virtual addresses that are in KSEG0 or KSEG1 and we need to be dealing with both types. Rewrite the test condition to ensure that the kernel virtual addresses are above PAGE_OFFSET which they must be, and below KSEG2 where the non-linear mapping starts. For EVA, there is not much that we can do given the linear address range that is offered, so just return any virtual address as being valid. Finally, when HIGHMEM is not enabled, all virtual addresses are assumed to be valid as well. Fixes: dfad83cb7193 ("MIPS: Add support for CONFIG_DEBUG_VIRTUAL") Signed-off-by: Florian Fainelli Reviewed-by: Serge Semin Signed-off-by: Thomas Bogendoerfer Signed-off-by: Sasha Levin --- arch/mips/mm/physaddr.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/arch/mips/mm/physaddr.c b/arch/mips/mm/physaddr.c index a1ced5e44951..f9b8c85e9843 100644 --- a/arch/mips/mm/physaddr.c +++ b/arch/mips/mm/physaddr.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -12,15 +13,6 @@ static inline bool __debug_virt_addr_valid(unsigned long x) { - /* high_memory does not get immediately defined, and there - * are early callers of __pa() against PAGE_OFFSET - */ - if (!high_memory && x >= PAGE_OFFSET) - return true; - - if (high_memory && x >= PAGE_OFFSET && x < (unsigned long)high_memory) - return true; - /* * MAX_DMA_ADDRESS is a virtual address that may not correspond to an * actual physical address. Enough code relies on @@ -30,7 +22,9 @@ static inline bool __debug_virt_addr_valid(unsigned long x) if (x == MAX_DMA_ADDRESS) return true; - return false; + return x >= PAGE_OFFSET && (KSEGX(x) < KSEG2 || + IS_ENABLED(CONFIG_EVA) || + !IS_ENABLED(CONFIG_HIGHMEM)); } phys_addr_t __virt_to_phys(volatile const void *x) -- 2.35.1