Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2590715rwo; Sun, 23 Jul 2023 19:51:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlELElxPre+FwaAUzmFAmfDyRdTvVQdD6KLXM+6oo2iQgznEVXSyez06+h8Si6V+IqcQJXnb X-Received: by 2002:a05:6358:2495:b0:137:d0bb:6036 with SMTP id m21-20020a056358249500b00137d0bb6036mr3472192rwc.1.1690167112408; Sun, 23 Jul 2023 19:51:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690167112; cv=none; d=google.com; s=arc-20160816; b=Y93lwcaR5YnyAY2Div0yq1req1HJMwPYo3D9lS7V8VsJhNPPc0C0Bx4aatejXK8qNm NPQn894jshmdMMEmodlz7hg1kqjh3f8a4ul4DmYknIZcWspFwT+3BK6ruOw7UhKPMZdS /iUG/fu0hNlgmQvhPjo4+Id0ry7Wx0jGEQy3zvpkchg/0H0b2DIxr3ICAVwpbKLje9IG L+RZ7sA4Qga/N23hnmA2MnUHnuMDFtpxB7DWX2TL2ibAUEtwerFVLJF9NXvNBBvn6MpH 4WqqARFN1CAJyHW+/tLqODk//l+yNLifa0FZ3gHbLaw96st/KcBQKrcppAF7UeinDHFd +1OA== 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:to:content-language:subject:cc:user-agent:mime-version :date:message-id; bh=HHtaXeqmuogvH+Z+iEj1cganz7gMsWSt0aMeGEWByy4=; fh=vVKjys611c1MJ5jCS5LZG9OLjb6JpaUjqStU2+B/QHY=; b=AprrWCEq+o/U1gaiWilk6L8wmICna2DFL5JMur8Ie3yl7W0edqXSu2eVx9w8MbgUJL MIQQ5rMDnan8rgoUTx78kwIKqikFH0jtew2HzA9wRWr8HmmrE4G6YqCWHmWPkTjV+fPO pAw2i8NrrUUH3zmpwEkOuFvp1bVxQO4W4oB36wLnU8344Oas+0ISITp2QTszJ4XBeKM3 855OPuD5cf1//Mc42rFlfWQv9BjHjYAaj2Shr+igVzYlyAHJgUtc4ryvVZ0e+u5KkloH j1W49IF/ICcwgMYLFzDNOMGkTqzA3P4ivwsiFg5fsDIT3HARzklgGOj1Z89ezZgy8DJf BN/g== 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d4-20020a056a0010c400b006687af0b2efsi8318870pfu.27.2023.07.23.19.51.40; Sun, 23 Jul 2023 19:51:52 -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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230062AbjGXCYa (ORCPT + 99 others); Sun, 23 Jul 2023 22:24:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230289AbjGXCY0 (ORCPT ); Sun, 23 Jul 2023 22:24:26 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA380E53 for ; Sun, 23 Jul 2023 19:24:10 -0700 (PDT) Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4R8MpC3W0xztRZ0; Mon, 24 Jul 2023 09:22:11 +0800 (CST) Received: from [10.174.178.120] (10.174.178.120) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 24 Jul 2023 09:25:22 +0800 Message-ID: <35a0dad6-4f3b-f2c3-f835-b13c1e899f8d@huawei.com> Date: Mon, 24 Jul 2023 09:25:22 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird CC: , , , , , , , , , Subject: Re: [RFC PATCH] arm64: mm: Fix kernel page tables incorrectly deleted during memory removal Content-Language: en-US To: References: <20230717115150.1806954-1-mawupeng1@huawei.com> <20230721103628.GA12601@willie-the-truck> From: mawupeng In-Reply-To: <20230721103628.GA12601@willie-the-truck> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.178.120] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, 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 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, >> >> offline_and_remove_memory >> try_remove_memory >> arch_remove_memory >> __remove_pgd_mapping >> unmap_hotplug_range >> unmap_hotplug_p4d_range >> unmap_hotplug_pud_range >> if (pud_sect(pud)) >> pud_clear(pudp); > > Sorry, but I'm struggling to understand the problem here. If we're adding > and removing a 2G memory region, why _wouldn't_ we want to use large 1GiB > mappings? > Or are you saying that only a subset of the memory is removed, > but we then accidentally unmap the whole thing? Yes, umap a subset but the whole thing page table entry is removed. > >> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c >> index 95d360805f8a..44c724ce4f70 100644 >> --- a/arch/arm64/mm/mmu.c >> +++ b/arch/arm64/mm/mmu.c >> @@ -44,6 +44,7 @@ >> #define NO_BLOCK_MAPPINGS BIT(0) >> #define NO_CONT_MAPPINGS BIT(1) >> #define NO_EXEC_MAPPINGS BIT(2) /* assumes FEAT_HPDS is not used */ >> +#define NO_PUD_MAPPINGS BIT(3) >> >> int idmap_t0sz __ro_after_init; >> >> @@ -344,7 +345,7 @@ static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long end, >> */ >> if (pud_sect_supported() && >> ((addr | next | phys) & ~PUD_MASK) == 0 && >> - (flags & NO_BLOCK_MAPPINGS) == 0) { >> + (flags & (NO_BLOCK_MAPPINGS | NO_PUD_MAPPINGS)) == 0) { >> pud_set_huge(pudp, phys, prot); >> >> /* >> @@ -1305,7 +1306,7 @@ struct range arch_get_mappable_range(void) >> int arch_add_memory(int nid, u64 start, u64 size, >> struct mhp_params *params) >> { >> - int ret, flags = NO_EXEC_MAPPINGS; >> + int ret, flags = NO_EXEC_MAPPINGS | NO_PUD_MAPPINGS; > > I think we should allow large mappings here and instead prevent partial > removal of the block, if that's what is causing the issue. This could solve this problem. Or we can prevent partial removal? Or rebulid page table entry which is not removed? > > Will