Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp289873rwn; Wed, 14 Sep 2022 21:08:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR6bjXi8yjGFWfu7KvgVJoAsJ/4HLISCQ5HyW758pHZTZNFaiRZEad+gHyebjtV9xJIXncvD X-Received: by 2002:a17:907:a48:b0:77c:51b0:5aeb with SMTP id be8-20020a1709070a4800b0077c51b05aebmr14987509ejc.61.1663214924421; Wed, 14 Sep 2022 21:08:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663214924; cv=none; d=google.com; s=arc-20160816; b=UD2WZX+Z8pzjCbKupkce30D+wMK8OXH9xTLi9hPy3sT9P80so4sN4MHRORR8etPxuB uMLSvCjyQ7qVtBnba6kEixs2zdYM7k53wXH6HWBLmgBPxW4XTrQq+Zk9JX04/L2FL0pD kynYr4Sj1qYjaBK8ZOkJCiSgx8Xk0vAEnebJO37SCdilcvhSisQqAQUhaCQxRkWuaNhG hcym7AsTMxFw6XbwleQw+jdxNDD5zgT0Wnr2PZ43HA/rjj84GT51n+1JB0LpDXJWHuiq g2BU9AnJ4xI1nQaD+JXcqIKwewRHLyBnHWmLAwc22DVD4O1s+VDgZyUuGJg+DtHLlws2 D4BA== 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=dGenGNFixSUfvjBcMpAQ6R5uUlnwP9tMHtyYapDVSlA=; b=LsGvaQyi5yQCmG8+dhc5fhpoXFw2KNlenSL6ADBmtZtRvCiYW1qdMIw0lYIxnkbnTy jb2LouRIly+e1kuwwTNqX478/ww48L3i8R44bNYBmJlhfXC8Jdl9g+NQ5HJa6aPudUc7 Y/PRkzDxZwBDNUg65Y2AR5pM5cmMGX2qBB6tliJy0IO3JeeAP6gLwwbPXbirOvkoiu+g ttmOcgje21Q9/Dv6b2Xpq4/2OK5tin4RNHKfI+xyg1P9lCr3GKo9qpALjhjS4haQBClf jLxMas5X41E8gkm/jWsIjuHQCujkGZYSqFeUWDfUdWQ18U3aAN2rFUOwhIbNxor7dRNS iI6g== 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 b5-20020a056402084500b0044ee4ec8915si16432809edz.39.2022.09.14.21.08.18; Wed, 14 Sep 2022 21:08:44 -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 S229501AbiIOEEX (ORCPT + 99 others); Thu, 15 Sep 2022 00:04:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbiIOEEW (ORCPT ); Thu, 15 Sep 2022 00:04:22 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 422817969C; Wed, 14 Sep 2022 21:04:21 -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 17FC11682; Wed, 14 Sep 2022 21:04:27 -0700 (PDT) Received: from [10.162.43.6] (unknown [10.162.43.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 105FB3F71A; Wed, 14 Sep 2022 21:04:17 -0700 (PDT) Message-ID: Date: Thu, 15 Sep 2022 09:34:15 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] mm/hugetlb: correct demote page offset logic Content-Language: en-US To: Doug Berger , Mike Kravetz , Muchun Song Cc: Andrew Morton , Oscar Salvador , linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20220914190917.3517663-1-opendmb@gmail.com> From: Anshuman Khandual In-Reply-To: <20220914190917.3517663-1-opendmb@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,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 9/15/22 00:39, Doug Berger wrote: > With gigantic pages it may not be true that struct page structures > are contiguous across the entire gigantic page. The nth_page macro > is used here in place of direct pointer arithmetic to correct for > this. > > Fixes: 8531fc6f52f5 ("hugetlb: add hugetlb demote page support") > Signed-off-by: Doug Berger > Cc: Reviewed-by: Anshuman Khandual > --- > mm/hugetlb.c | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index e070b8593b37..0bdfc7e1c933 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -3420,6 +3420,7 @@ static int demote_free_huge_page(struct hstate *h, struct page *page) > { > int i, nid = page_to_nid(page); > struct hstate *target_hstate; > + struct page *subpage; > int rc = 0; > > target_hstate = size_to_hstate(PAGE_SIZE << h->demote_order); > @@ -3453,15 +3454,16 @@ static int demote_free_huge_page(struct hstate *h, struct page *page) > mutex_lock(&target_hstate->resize_lock); > for (i = 0; i < pages_per_huge_page(h); > i += pages_per_huge_page(target_hstate)) { > + subpage = nth_page(page, i); > if (hstate_is_gigantic(target_hstate)) > - prep_compound_gigantic_page_for_demote(page + i, > + prep_compound_gigantic_page_for_demote(subpage, > target_hstate->order); > else > - prep_compound_page(page + i, target_hstate->order); > - set_page_private(page + i, 0); > - set_page_refcounted(page + i); > - prep_new_huge_page(target_hstate, page + i, nid); > - put_page(page + i); > + prep_compound_page(subpage, target_hstate->order); > + set_page_private(subpage, 0); > + set_page_refcounted(subpage); > + prep_new_huge_page(target_hstate, subpage, nid); > + put_page(subpage); > } > mutex_unlock(&target_hstate->resize_lock); >