From patchwork Mon Mar 15 13:55:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 400461 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3461637jai; Mon, 15 Mar 2021 07:16:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrW2fQnSuzW48xrg4GNdd+mPWEudNOGayRztOwmVLZZy0alLIX7eiyg1BshHsbadeWVnBs X-Received: by 2002:a17:906:398a:: with SMTP id h10mr24161533eje.155.1615817770739; Mon, 15 Mar 2021 07:16:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615817770; cv=none; d=google.com; s=arc-20160816; b=I0hOSXzYoDhrTCTc6MkfXv8m4kHbhi08MPof4rUGupGAQLZ9NF6OM+SkYDK2L8DtQM VLGarfs5jWa5rEZA0C9I+IxtPjZynUm7bDp2RO00AQtESwOJ4DtYwAUmov2BtbBYpii6 LFCpcOoPELHGE0T8My8W1FbAEFycmIUXXrD+UgX+liXkeizvyV+rYR67OUKeXd4CUNqd DDiFG0NMxO4oTie8J9PHD+3etkFtTL/szQGjsWoduj6xO86dQORt2ZdyvozYT3pAds5D cAQjVxPA52bsmI+/C7oexyoRe7tnbDAGq63Gd4ve1Wbu4XrqL0Wc8VPAZjmPj+VLrvfU 2/Ew== 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=OZjhL7y53A3GwZ+Wz6gG7qGcDNdJg9J9+4oZ0n5FbK0=; b=CUnV5+8Ns2bF8XG5Bc0JklhroDxBhPHlN5YxGqVjjXUnUo7GkLci2BDUkXaR6v3rjz 9ei2UpdLvC9RQqlmJ5mMBq7jwvpbKAYDGsBf2iIQ35BrirB1KYfDhbVbS39yuwo9Daw8 xHb0VlwD3vACad5N6mkuHYiLLZ2jMnHc8/xB7C0HdblFpqtWlA8fS14HhUlX/KRfe33L 2wzILm4JV/WJ0542RqLZU9wcrEJjXUuMHmrUajIC2Mf1QIwDMXRnlxEz4BZSzo5pcXCe Qwj/7SEih7+y8dAtOsLTq6mrPtVMq0yqfAVPuXjsvsTIy32lVWj3GQ2RBBwN3s7lXRWJ e9qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TUGF32q5; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 h21si993553ede.37.2021.03.15.07.16.10; Mon, 15 Mar 2021 07:16:10 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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=TUGF32q5; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S230250AbhCOOJI (ORCPT + 12 others); Mon, 15 Mar 2021 10:09:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:49790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230408AbhCOOD2 (ORCPT ); Mon, 15 Mar 2021 10:03:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4604964EF3; Mon, 15 Mar 2021 14:03:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615817008; bh=3K2/gUiXGJ4t/u1MAqj4oCX1prLgPfHabLROMX+2Rjs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TUGF32q5lYjwSWbSSZVn2DnCRoJYZOQdO0TG04yNje3WD9LfpV3w5boFoP6rT5QDG usLrZiru0zgmoGSteBh6j68CExFUq/ArvJfxNjB/Ra9yp5/MUC5Z++8CTtKl/KF5qg MfhX6WmpAiN2kjOD1gdSj1QPVjEoe+yaiQlPap2s= 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.10 244/290] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory Date: Mon, 15 Mar 2021 14:55:37 +0100 Message-Id: <20210315135550.253891009@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@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(+) -- 2.30.1 diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index b913844ab740..916e0547fdcc 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -218,6 +218,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); }