Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1142581rbb; Sun, 25 Feb 2024 23:03:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWmlZs8Fx0je30AmNGfUbWPgGGrFRMWCU9Tc61uJ7vFQpgqh7TW94MTPEj4I5KPYS93hKWAUM1n0RQEVCV3p+c859z6sdWdMc8/PU8iIQ== X-Google-Smtp-Source: AGHT+IEDkllf9q6FpCVABt/bV+gAtG5K76qleRJCf+I/O4ylgbG8hEMQ/NABWlikFdgbfkcK9EEv X-Received: by 2002:a05:620a:f88:b0:787:a9af:d6b8 with SMTP id b8-20020a05620a0f8800b00787a9afd6b8mr10156605qkn.8.1708930997975; Sun, 25 Feb 2024 23:03:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708930997; cv=pass; d=google.com; s=arc-20160816; b=I9lg/GqB/OW7MEvIYEHADMtrOHqGofnXGLSBENdYd5bmrhNtAXELktT0SabjeWEyKe DyZZ5k5KyrsJun6JHmsS8UE4OX+GLa6lkvUcEkeuM6iPFoUJeuoWnzAjkXUE6kIomDjY l7vI6rtj0URE4Yll1nwLOLH3FrNduVam9pNHgVthcrZnhRAqwDU6MUbLQR63BuXoFGL8 aJRmJ7r9ISOaQwirk/uAOa0hkpV75svOgQcP9sfY2uY6FJmV7r/x9bRbK0wrPPxiOlIR KW64LPwDZ/adTXcMc11Qaj5amwJ7yqdxi+3FFH57hQNpyVRQSV/k5J6THWvdCwblX2AR xUAg== 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:reply-to:subject :references:cc:to:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=l0aRkq99zbvImqGezi2O4f7LEP70T1pt+wuXlgU6khQ=; fh=Lflx/59weC61INwyVeI91IS++lzcpDl5hR3G1lG1qe8=; b=q+1fHK5oJoZyhBB6LtJHVNxFbk/4VVkiwA5a3vn0D/mu22CZs4LD/OO3/xlOyFMHRE 5TAk9EVh7+XA6o7HBiQySdFf4Lgfci2uneAQ1RsNPqINohOd5bPmGDF16IfXCsMuxB+H Vbz7ACoos0InTuIZrST3PIkxF1cJUiCUWga/jQJ8cPMC+Mn/5+dD3at92a8AmL8Ovt4i 253d/0BfLDFbzoSo9jKsaQYQB79JY9SxbcjId5EXis24FHvzYbRe2UWb4MEDe9ElfG4k vk4GDohYnyw5urvujjZfb/rTuX0f2Th+uYRsPN5HGcOKBFMIQKI7fXVbASdjfdgK5WZg dIgQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-80614-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80614-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c23-20020ae9e217000000b00787c1cf0d60si4462339qkc.571.2024.02.25.23.03.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 23:03:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80614-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=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-80614-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80614-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.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 B8C511C215F4 for ; Mon, 26 Feb 2024 07:03:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD86D1BDD8; Mon, 26 Feb 2024 07:03:12 +0000 (UTC) Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 284981BDCE for ; Mon, 26 Feb 2024 07:03:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708930992; cv=none; b=aohT2w9CrdrpaizIgV51Vt99yknj3jQRJGl2nVd4u6WFHywrf9BJkL6PDJUZlvqYTdGQctdDva2EvHYnRvA3JVygZI/P1r02uG5/0MH0QnYIwucsw5vZ0QcPyNbjc+Tg2pyQ2SFjYlXl3dHmApU2PfIDn2CzIXOjJGpe0C+G0S0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708930992; c=relaxed/simple; bh=1DtOKBCxpfL5fIkR2Rryk2XB5jCDrHQvAcOgOxHdaUE=; h=Message-ID:Date:MIME-Version:To:CC:References:Subject:From: In-Reply-To:Content-Type; b=A5qCHTGbPcn5jo/7wEodECwC3WgyjEMNMIwF49kpAIHe6y3vWT1Fwt5SPOalggbPPB+B++n7zQESiUkmXAxhh5FND3qKy+k0Pu1IvgxeF2G3Bbw6uQ0R+AymdOKYOC/klnPPxV8uuUIAz+EgqGMfwZrQqaAIrhMkytzoeh0WqfU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4Tjs4k0Y49zqjgw; Mon, 26 Feb 2024 15:02:30 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id 569081400F4; Mon, 26 Feb 2024 15:03:06 +0800 (CST) Received: from [10.174.179.13] (10.174.179.13) by dggpeml500011.china.huawei.com (7.185.36.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 26 Feb 2024 15:03:05 +0800 Message-ID: <5a1d28b7-1e6e-da39-9b34-f86470163bb1@huawei.com> Date: Mon, 26 Feb 2024 15:03:05 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 To: CC: , , , , , , , , , , , References: <20240223063608.2605736-1-liuyongqiang13@huawei.com> Subject: Re: [PATCH v2] arm: flush: check if the folio is reserved for no-mapping addresses Reply-To: <20240223063608.2605736-1-liuyongqiang13@huawei.com> From: Jinjiang Tu In-Reply-To: <20240223063608.2605736-1-liuyongqiang13@huawei.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500011.china.huawei.com (7.185.36.84) Since some abuses of pfn_valid() have been reported, I check all the use of pfn_valid(), and find some suspicious cases. phys_mem_access_prot() defined in arch/arm/mm/mmu.c returns pgprot_noncached() when pfn_valid() returns false. I think it’s purpose is to return pgprot_noncached() when the pfn is not in RAM, and the use of pfn_valid() is incorrect. Notably, phys_mem_access_prot() defined in arm64 uses pfn_is_map_memory() instead of pfn_valid() since commit 873ba463914c (arm64: decouple check whether pfn is in linear map from pfn_valid()). Similarly, virt_addr_valid() defined in arm64 uses pfn_is_map_memory() instead of pfn_valid() since commit 873ba463914c (arm64: decouple check whether pfn is in linear map from pfn_valid()), But virt_addr_valid() still uses pfn_valid(). Besides, the implementation of x86 also uses pfn_valid(). update_mmu_cache_range() defined in arch/arm/mm/fault-armv.c checks pfn_valid() and then calls __flush_dcache_folio(). This case is similar to the case reported by Yongqiang Liu, the pfn may not be a RAM pfn, and the system will crash in __flush_dcache_folio() due to the kernel linear mapping is not established. virt_addr_valid() is used to check whether a vrtual address is valid linear mapping. Are these uses of pfn_valid() incorrect? pfn_modify_allowed() defined in arch/x86/mm/mmap.c checks pfn_valid(), and the comment says it is intended to check whether the pfn is in real memory. So the use of pfn_valid() should be incorrent. This case is only involved when the cpu is affected by X86_BUG_L1TF. try_ram_remap() defined in kernel/iomem.c returns the linear address when three checks are passed. One of the checks is pfn_valid(). The only caller memremap() guarantees the pfn passed to try_ram_remap() is in RAM, but the pfn may be in NOMAP memory regions and is not mapped in linear mapping. commit 260364d112bc (arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map) solves it by checking in arch_memremap_can_ram_remap(), However, if other architectures involve this issue? Do these suspicious case abuse pfn_valid() really? Thanks