From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 691BAC6FD1C for ; Fri, 24 Mar 2023 03:44:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229948AbjCXDoF (ORCPT ); Thu, 23 Mar 2023 23:44:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231308AbjCXDnV (ORCPT ); Thu, 23 Mar 2023 23:43:21 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09DD1CDC9 for ; Thu, 23 Mar 2023 20:43:18 -0700 (PDT) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4PjSdh38bJz17Nrg; Fri, 24 Mar 2023 11:40:08 +0800 (CST) Received: from [10.174.177.243] (10.174.177.243) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Fri, 24 Mar 2023 11:43:13 +0800 Message-ID: <15f4892c-e0dc-ff37-45a8-a1a025c2d929@huawei.com> Date: Fri, 24 Mar 2023 11:43:12 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH] mm: kfence: fix handling discontiguous page Content-Language: en-US To: Muchun Song , , , , , , , CC: , , References: <20230323025003.94447-1-songmuchun@bytedance.com> From: Kefeng Wang In-Reply-To: <20230323025003.94447-1-songmuchun@bytedance.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/3/23 10:50, Muchun Song wrote: > The struct pages could be discontiguous when the kfence pool is allocated > via alloc_contig_pages() with CONFIG_SPARSEMEM and !CONFIG_SPARSEMEM_VMEMMAP. > So, the iteration should use nth_page(). > Reviewed-by: Kefeng Wang > Fixes: 0ce20dd84089 ("mm: add Kernel Electric-Fence infrastructure") > Signed-off-by: Muchun Song > --- > mm/kfence/core.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/mm/kfence/core.c b/mm/kfence/core.c > index d66092dd187c..1065e0568d05 100644 > --- a/mm/kfence/core.c > +++ b/mm/kfence/core.c > @@ -556,7 +556,7 @@ static unsigned long kfence_init_pool(void) > * enters __slab_free() slow-path. > */ > for (i = 0; i < KFENCE_POOL_SIZE / PAGE_SIZE; i++) { > - struct slab *slab = page_slab(&pages[i]); > + struct slab *slab = page_slab(nth_page(pages, i)); > > if (!i || (i % 2)) > continue; > @@ -602,7 +602,7 @@ static unsigned long kfence_init_pool(void) > > reset_slab: > for (i = 0; i < KFENCE_POOL_SIZE / PAGE_SIZE; i++) { > - struct slab *slab = page_slab(&pages[i]); > + struct slab *slab = page_slab(nth_page(pages, i)); > > if (!i || (i % 2)) > continue;