Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1923730rdb; Wed, 31 Jan 2024 13:24:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6bAKAnUTmp7aUTnMmQ/jNKSnXi0otUiH9uHFyQfOwoC0Z8TzyU1mRW63DX3WbkJ/LYMr6 X-Received: by 2002:a05:620a:49:b0:783:f51b:f887 with SMTP id t9-20020a05620a004900b00783f51bf887mr650632qkt.50.1706736266158; Wed, 31 Jan 2024 13:24:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706736266; cv=pass; d=google.com; s=arc-20160816; b=G2C+zqWGREXbesxQAFK3yJyrp2PQ7E9G08AXF0e1jNz6ezQ8bU879rnAlY2IA0UhXW w6+MYVTd9c4wezbsmJSneOHcUMq0hWXRdMRb6M3/V/ft2s75XJMfDPT3cjkzmW+Ga0T2 BWp41UnecZvxYraXz6LRnoYgcZJoX3hMi4abrLiGYBm6YzXq0hboHMJ9T5/dfmBKdWdN 3eI5M2zRGVbiNDKPA8V+dWbQ5BIkj/4wpt4B0Q1+WedWa011gW6HVDe/UwNc0p2xmTYN 6Tcaz8LbpCq1vcyJn1FDGXT2IiDTs81kMj0Am3tscA9IwXUvtt6+F0YuPS6i+Lws9ePr 7RuA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=DdJd8WMSLTfjw5bGewWyf8GBgviMl0SG1rvkGuz/zfc=; fh=7yJkEnjQlu76Ak76OE3O/ImJTVeIa60r71n04N5t0V0=; b=SLda2iYioFORNjbchaATO1U+4xrvICiabWCh0insrpxWy0M2DUdqFHbjYnvE2ZhmuU kHbq8aB8GdvnpJhlWfWi9yXu/APGWLbstZwW625NcIDDZvLrYRpgoTYzot6JWeSY6neX d7GfVg7g6vfxbeW1dXNP3htkwlTQtrAGx3QnnugbIFoyr89HQNOYm98lghBwobNqbCf9 yHpSSmbrZyqHOmLKErBhpM+7LeBsSL8QtmvYHe0AbkQK74VFVGsqKHuWenj5ulcJbqx9 fD3Kov2CdlS98yEFZz2pq4rFnn27onYDh8vqwWa+x9GJfQB6tiKigbWdqXsc4mC2yd+u ry3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-47152-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47152-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=1; AJvYcCU1ThnkvmCKCBSvngGt/kjDDxfXH/G7NOP/3xE+6r1MgtC+Zkla1OXNoJFrteS/IKBOtmSo2mJE0OPrCzIpAskdQLKk9nplckbGZktr9Q== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c19-20020a05620a165300b0077f4e80e131si5249035qko.692.2024.01.31.13.24.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 13:24:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47152-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-47152-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47152-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E5A461C23AF4 for ; Wed, 31 Jan 2024 21:24:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9A0E3B2A2; Wed, 31 Jan 2024 21:20:57 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA28D3B2A1 for ; Wed, 31 Jan 2024 21:20:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706736057; cv=none; b=V8ZpUYV2yIGMjhIriGa7YEJMbER/CX5ozEPXO1pLg7mTYBnGl70/YZy8H6RvlkLoXCNXVLOul9hxDhc7f1orV4cuYgv1IrDxHgwOG8Sg8yEVOZo3oJsYWPn1th/PGWmrn0qXyQmBenNfppqk38AnCKloAIDqNVH5uuggiFJIHjE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706736057; c=relaxed/simple; bh=e37xxEqCXgrSoXUtHNE3d3iD3PvqiDlJCMjxG5NFxRc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=W6webLTbUve/ny2VIst0S+37qjbMVsUam8Rmnv4rNFQD6EbzWPCLbjJ8cEzGe1OSDsMQzl9nZgnQnIqvlelbulZ01RGUBK3PBL75UJxIX653v72F3WgVZLmB2S2N1nv6SXrGhDyutoLRghqyCxU7HNVDY7aqZEBc3QhRc8WP+is= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E8AB6DA7; Wed, 31 Jan 2024 13:21:36 -0800 (PST) Received: from [10.57.90.248] (unknown [10.57.90.248]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3B21C3F738; Wed, 31 Jan 2024 13:20:51 -0800 (PST) Message-ID: Date: Wed, 31 Jan 2024 21:20:49 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] arm: flush: don't abuse pfn_valid() to check if pfn is in RAM Content-Language: en-GB To: "Russell King (Oracle)" Cc: Yongqiang Liu , linux-arm-kernel@lists.infradead.org, yanaijie@huawei.com, zhangxiaoxu5@huawei.com, wangkefeng.wang@huawei.com, sunnanyong@huawei.com, rppt@linux.ibm.com, linux-kernel@vger.kernel.org, keescook@chromium.org, arnd@arndb.de, m.szyprowski@samsung.com, willy@infradead.org References: <20240131125907.1006760-1-liuyongqiang13@huawei.com> <0da50102-3e87-49f7-b8f7-45cfcb4232d6@arm.com> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024-01-31 7:00 pm, Russell King (Oracle) wrote: > On Wed, Jan 31, 2024 at 06:39:31PM +0000, Robin Murphy wrote: >> On 31/01/2024 12:59 pm, Yongqiang Liu wrote: >>> @@ -292,7 +293,7 @@ void __sync_icache_dcache(pte_t pteval) >>> /* only flush non-aliasing VIPT caches for exec mappings */ >>> return; >>> pfn = pte_pfn(pteval); >>> - if (!pfn_valid(pfn)) >>> + if (!memblock_is_map_memory(PFN_PHYS(pfn))) >>> return; >>> folio = page_folio(pfn_to_page(pfn)); >> >> Hmm, it's a bit odd in context, since pfn_valid() obviously pairs with this >> pfn_to_page(), whereas it's not necessarily clear that >> memblock_is_map_memory() implies pfn_valid(). >> >> However, in this case we're starting from a PTE - rather than going off to >> do a slow scan of memblock to determine whether a round-trip through >> page_address() is going to give back a mapped VA, can we not trivially >> identify that from whether the PTE itself is valid? > > Depends what you mean by "valid". If you're referring to pte_valid() > and L_PTE_VALID then no. > > On 32-bit non-LPAE, the valid bit is the same as the present bit, and > needs to be set for the PTE to not fault. Any PTE that is mapping > something will be "valid" whether it is memory or not, whether it is > backed by a page or not. > > pfn_valid() should be telling us whether the PFN is suitable to be > passed to pfn_to_page(), and if we have a situation where pfn_valid() > returns true, but pfn_to_page() returns an invalid page, then that in > itself is a bug that needs to be fixed and probably has far reaching > implications for the stability of the kernel. Right, the problem here seems to be the opposite one, wherein we *do* often have a valid struct page for an address which is reserved and thus not mapped by the kernel, but seemingly we then take it down a path which assumes anything !PageHighmem() is lowmem and dereferences page_address() without looking. However I realise I should have looked closer at the caller, and my idea is futile since the PTE here is for a userspace mapping, not a kernel VA, and is already pte_valid_user() && !pte_special(). Plus the fact that the stack trace indicates an mmap() path suggests it most likely is a legitimate mapping of some no-map carveout or MMIO region. Oh well. My first point still stands, though - I think at least a comment to clarify that assumption would be warranted. Thanks, Robin.