Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3354355pxf; Mon, 15 Mar 2021 07:50:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzw9qHwJTntM99kxfYDl5ByD4CKcwd0N3vwhcbha2W3eGaC6uT29N1iSLH4VdqJ0XuUN7Z+ X-Received: by 2002:a17:906:4d85:: with SMTP id s5mr22349329eju.43.1615819816624; Mon, 15 Mar 2021 07:50:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615819816; cv=none; d=google.com; s=arc-20160816; b=ZCYNuqRm1i+sWQ9XTQyKoRK5QgW+wgKuVIhU9/I0eF2Wb0dmpDbNTHwaz+EB+pDsXw 9L4C9b4il+A4HlZVhLcB8/Q+8w0VMbxm36X+RlwSvsHl7gIZ7W8pvjvuDo1rFSWQSI67 fBaX2+F3WMPDETqJWS01W8vizCaqus9rLPaeB70QGefVCJNlaEneh4H2VZhZ5JQNR4vU nr/UYu86EaR8TPTTgD9024DVWUMLCjjEYVasOsjf4yJrTAFHdCVcYuWd9rOdGhTXhhPB /Bp5CCJXd6qByMcstr9gJo/tIB/lZelbtlK+E51rxemQY0Ejlz9i7D7oxoxshb7nrcUg WiFA== 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=EiI0VfzfadUOuhv+lV8MTaZJNQVqJ2Uwx0z+GKOgdLY=; b=NicY2sNEBW9M77ZKshqCdsZP2vBRq8w3TVcZtH1/H+QWPQ6BbsUNXbAKGdyy6rJ1/K OOyfj0fDp66BPq7/AlE7CKf9bUHeR47nTcbJU4Vj3V9Wt5LkJO1tWaWiNderRKj7ib5C KBGu61pH563BGRWyO/ZDVf7J9n8qOZeMzMZGpRE3bT8gG/5NGIr8ht9i6dlSZ8wX5dQ9 8aqCMBji/foDgGFV0ujtOgHv5zjLF1qNaHACSj3pMF9Geajc532NRsvghlKd3ImJ1WOX gwf7749wgR78V804pW9yPZjzmsg8BVVdOH88n7pB8EO2lhMTf84IG0vUgK5mJj7V160Q nNHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EmqHMP3N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n7si11510965ejc.483.2021.03.15.07.49.53; Mon, 15 Mar 2021 07:50:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EmqHMP3N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S240903AbhCOOsM (ORCPT + 99 others); Mon, 15 Mar 2021 10:48:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:49494 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234220AbhCOODF (ORCPT ); Mon, 15 Mar 2021 10:03:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2F32464EF1; Mon, 15 Mar 2021 14:03:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816985; bh=yMcuxH9/NSD6zVo+lbmUfvAi3ZKHcoLQEMsqd003JX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EmqHMP3N3/Z7KziBkhLzJeEDfrQropMwm8+NBq/faUDk0wL41Eau/3F3wJD7sem/y xtezp4EiCkdPnE3X6xw5F21MgwrtAkUYABjG0+1VFkID4GP5Uhfnszt4eQSI9NVo6c K5OflLYdv4+j+Q9KAaNpFfKN/VK+mlv9QUwrvPP4= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Catalin Marinas , Will Deacon , Ard Biesheuvel , Robin Murphy , linux-arm-kernel@lists.infradead.org, David Hildenbrand , Anshuman Khandual , Sasha Levin Subject: [PATCH 5.11 244/306] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory Date: Mon, 15 Mar 2021 14:55:07 +0100 Message-Id: <20210315135515.886869493@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Anshuman Khandual [ Upstream commit eeb0753ba27b26f609e61f9950b14f1b934fe429 ] pfn_valid() validates a pfn but basically it checks for a valid struct page backing for that pfn. It should always return positive for memory ranges backed with struct page mapping. But currently pfn_valid() fails for all ZONE_DEVICE based memory types even though they have struct page mapping. pfn_valid() asserts that there is a memblock entry for a given pfn without MEMBLOCK_NOMAP flag being set. The problem with ZONE_DEVICE based memory is that they do not have memblock entries. Hence memblock_is_map_memory() will invariably fail via memblock_search() for a ZONE_DEVICE based address. This eventually fails pfn_valid() which is wrong. memblock_is_map_memory() needs to be skipped for such memory ranges. As ZONE_DEVICE memory gets hotplugged into the system via memremap_pages() called from a driver, their respective memory sections will not have SECTION_IS_EARLY set. Normal hotplug memory will never have MEMBLOCK_NOMAP set in their memblock regions. Because the flag MEMBLOCK_NOMAP was specifically designed and set for firmware reserved memory regions. memblock_is_map_memory() can just be skipped as its always going to be positive and that will be an optimization for the normal hotplug memory. Like ZONE_DEVICE based memory, all normal hotplugged memory too will not have SECTION_IS_EARLY set for their sections Skipping memblock_is_map_memory() for all non early memory sections would fix pfn_valid() problem for ZONE_DEVICE based memory and also improve its performance for normal hotplug memory as well. Cc: Catalin Marinas Cc: Will Deacon Cc: Ard Biesheuvel Cc: Robin Murphy Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Acked-by: David Hildenbrand Fixes: 73b20c84d42d ("arm64: mm: implement pte_devmap support") Signed-off-by: Anshuman Khandual Acked-by: Catalin Marinas Link: https://lore.kernel.org/r/1614921898-4099-2-git-send-email-anshuman.khandual@arm.com Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/mm/init.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 709d98fea90c..1141075e4d53 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -230,6 +230,18 @@ int pfn_valid(unsigned long pfn) if (!valid_section(__pfn_to_section(pfn))) return 0; + + /* + * ZONE_DEVICE memory does not have the memblock entries. + * memblock_is_map_memory() check for ZONE_DEVICE based + * addresses will always fail. Even the normal hotplugged + * memory will never have MEMBLOCK_NOMAP flag set in their + * memblock entries. Skip memblock search for all non early + * memory sections covering all of hotplug memory including + * both normal and ZONE_DEVICE based. + */ + if (!early_section(__pfn_to_section(pfn))) + return pfn_section_valid(__pfn_to_section(pfn), pfn); #endif return memblock_is_map_memory(addr); } -- 2.30.1