Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp716930rwb; Thu, 27 Jul 2023 21:24:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlFkmtXVQYtQSoVJa4fzatxmg62nlcSO6QDSzBI6mGQDjhWeF69PPNRgM3bpWP+snx1veAUy X-Received: by 2002:a05:6a20:3944:b0:132:965d:5323 with SMTP id r4-20020a056a20394400b00132965d5323mr723951pzg.33.1690518265079; Thu, 27 Jul 2023 21:24:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690518265; cv=none; d=google.com; s=arc-20160816; b=VMD2SXi+vYwkTKL2FjgsjZentoxn7MgMqbZwFi4cS0y7heA2FrodCfKJafeF359tiR h7C/6vlEC7ffEn5bm+bGIf946Rtp6FBuXz4+M8ILp+2rQzNpl2Y/C1uZfDMEcE5Tt5Mm MxoP3lG5x0kXBLn/R7rdiaeIvSopUsKLXJwY7ltiwlMajIvzTONX3CA8dde086A0te6A kaqCqINRg2bd19/ybN0jDApm2SVaPNFQz673YXvCc6OaoCmAOpwfT39AIs1/TIuklqhs /ltLfpa7qzt7CBIvOhXsiZwO+2ECYtrpo+A011je6fW8E/8IHTuU6zRF6vDT8e8R+p9v AtOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=gh0LO9oN4HNnAJ1jLFZFXyfBLdUoxcxyjjJx25XdPZg=; fh=TU0fIxcTzL6tzVu5V7cDXI4OcyOAw9jkGZFAnqLd6cY=; b=iwEBmW86SP4XJl0ExfGtI2aM0fKbtKMciO2SAOgAjasYfBEMz3DN8dh338j11SukKL SkSIUmpKDpHO3uq1ngstYR/LajNm3AYFx1yDI69cUESq9KbEX4Eg43Gi0QBjzgedxelM 0ucytD3WRjuKPEmz0kJd3to21AVCRU151X//i8xaKTZZeXQ5ro0J7NEbg59HvXaTQ3Oc nyaODpDYAfRTsF7oBsGw5fAJlpcA0ymTR8j6ENmgAYkUwov5ZIC2VbP6nlFdllYqyh3/ Raw0Kj4+95Z6Zy85HIYuppiX4L+IInCwgFMAJTuI3PEF+zHofMAqI5gYbUufKr3S4v70 xUMA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d5-20020a170902654500b001bb9d6794d3si2398868pln.72.2023.07.27.21.24.12; Thu, 27 Jul 2023 21:24:25 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230132AbjG1EBX (ORCPT + 99 others); Fri, 28 Jul 2023 00:01:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230009AbjG1EBU (ORCPT ); Fri, 28 Jul 2023 00:01:20 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3FAE02D64 for ; Thu, 27 Jul 2023 21:01:19 -0700 (PDT) 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 D1AF72F4; Thu, 27 Jul 2023 21:02:01 -0700 (PDT) Received: from [10.163.51.135] (unknown [10.163.51.135]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EB4483F6C4; Thu, 27 Jul 2023 21:01:14 -0700 (PDT) Message-ID: <306b2bc5-9637-0743-b8bb-7a60aa1ad65d@arm.com> Date: Fri, 28 Jul 2023 09:31:11 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [RFC PATCH] arm64: mm: Fix kernel page tables incorrectly deleted during memory removal Content-Language: en-US To: David Hildenbrand , mawupeng , will@kernel.org Cc: catalin.marinas@arm.com, akpm@linux-foundation.org, sudaraja@codeaurora.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, mark.rutland@arm.com References: <20230717115150.1806954-1-mawupeng1@huawei.com> <20230721103628.GA12601@willie-the-truck> <35a0dad6-4f3b-f2c3-f835-b13c1e899f8d@huawei.com> <732e0db0-eb41-6c58-85b7-46257b4ba0b7@redhat.com> <3149f5f8-7878-dfe1-5745-870fddcc1108@huawei.com> From: Anshuman Khandual In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,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 On 7/26/23 13:20, David Hildenbrand wrote: > On 26.07.23 08:20, mawupeng wrote: >> >> >> On 2023/7/24 14:11, David Hildenbrand wrote: >>> On 24.07.23 07:54, Anshuman Khandual wrote: >>>> >>>> >>>> On 7/24/23 06:55, mawupeng wrote: >>>>> >>>>> On 2023/7/21 18:36, Will Deacon wrote: >>>>>> On Mon, Jul 17, 2023 at 07:51:50PM +0800, Wupeng Ma wrote: >>>>>>> From: Ma Wupeng >>>>>>> >>>>>>> During our test, we found that kernel page table may be unexpectedly >>>>>>> cleared with rodata off. The root cause is that the kernel page is >>>>>>> initialized with pud size(1G block mapping) while offline is memory >>>>>>> block size(MIN_MEMORY_BLOCK_SIZE 128M), eg, if 2G memory is hot-added, >>>>>>> when offline a memory block, the call trace is shown below, >>> >>> Is someone adding memory in 2 GiB granularity and then removing parts of it in 128 MiB granularity? That would be against what we support using the add_memory() / offline_and_remove_memory() API and that driver should be fixed instead. >> >> Yes, this kind of situation. >> >> The problem occurs in the following scenarios: >> 1. use mem=xxG to reserve memory. >> 2. add_momory to online memory. >> 3. offline part of the memroy via offline_and_remove_memory. >> >> During my research, ACPI memory removal use memory_subsys_offline to offline memory section and >> this will not delete page table entry which do not trigger this kind of problem. >> >> So I understand what you are talking about. >> 1. 3rd-party driver shouldn't use add_memory/offline_and_remove_memory to online/offline memory. >>     If it have to use, this can be achieved by driver. >> 2. memory_subsys_offline is perfered to do such thing. > > No, my point is that > > 1) If you use add_memory() and offline_and_remove_memory() in the *same >    granularity* it has to be working, otherwise it has to be fixed. > > 2) If you use add_memory() and offline_and_remove_memory() in different >    granularity (especially, add_memory() in bigger granularity) , then >    change your code to do add_memory() in the same granularity. > > > If you run into 1), then we populated a PUD for boot memory that also covers yet unpopulated physical memory ranges that are later populated by add_memory(). If that's the case, then we can either fix it by Is that case possible ? __create_pgd_mapping() is called to create the mapping both in hotplug and boot memory cases. alloc_init_pud() ensures [1], that both virtual and physical address ranges are PUD_MASK aligned, before creating a huge or block page entry. (addr | next | phys) & ~PUD_MASK) == 0 > > a) Not doing that. Use PMD tables instead for that piece of memory. > > b) Detecting that that PUD still covers memory and refusing to remove >    that PUD. > > c) Rejecting to hotadd memory in this situation at that location. We >    have mhp_get_pluggable_range() -> arch_get_mappable_range() to kind- >    of handle something like that. >