From patchwork Wed Sep 14 19:09:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 12976521 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E25F5C6FA82 for ; Wed, 14 Sep 2022 19:10:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F4F18D0002; Wed, 14 Sep 2022 15:10:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A3EB8D0001; Wed, 14 Sep 2022 15:10:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06C0E8D0002; Wed, 14 Sep 2022 15:10:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E8F6A8D0001 for ; Wed, 14 Sep 2022 15:10:03 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C35A040BAA for ; Wed, 14 Sep 2022 19:10:03 +0000 (UTC) X-FDA: 79911631086.21.F44D578 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by imf02.hostedemail.com (Postfix) with ESMTP id 7C6D8800A9 for ; Wed, 14 Sep 2022 19:10:03 +0000 (UTC) Received: by mail-qk1-f181.google.com with SMTP id u28so8701594qku.2 for ; Wed, 14 Sep 2022 12:10:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=6mBQHGkTCxpZ0kR+Uol1DB+Rk5F3r94azBv7C4epuC0=; b=Dw+JcD8DgkClgEkMagfiLANjV0/pvsu8mhEfMYKS7oDGdcZfuKNeFhI/Aoq7gPfQLV e8Kwx4FZhkAXPB+vBkt9h4Jdvp+0RBQ4LU+E4Xgr9bdlw1/FqhFU29nRGFQ9zTfZw38Z p7Je6UJUAwa54gPy3e+9UPpKoky64QyvHprd5ErvXlrdCDEcyXN6yTB9GhUbzi0AK5LE HOEpB2MnXRM+djEY0AvyrOxocKyT8YTNfyTMFmxLDwH+i94Zyu1JIR6aGOIpi60vgvOb WfgRj9PkKGvrrMSBQK7ouYKhoPR+A3L2SeloAaG4l7KYZViqKsgcPirutkSJJpSAvfCY U9sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=6mBQHGkTCxpZ0kR+Uol1DB+Rk5F3r94azBv7C4epuC0=; b=WLJOoOIJrZPpReHf0grsL9INYHn+ZGsp5JkWpCdodarD9awtY3BQ9l9CitjE4Ahe60 G1SjbHo0UNbGCrQ/96+00P4G1AvRkhf06XrkWC1xU1CGID4gZHgQiCLgsSLPgJQVi7w7 P+LUWakOJQqyYmvaxN/BLDJL1fa5tPCQXTZ7bQejIprsUZ8Sx7UZhkwro3Uu/E6MGZwK EGONKn6MIqulJvCf6Skjz80rJHhi0IFR8MqR2rdnlBC//tXitgdvYEZto0GqAsTnep08 gJfgFKgO2I5UOamOWImlED4pPKdeKgbcKwzWVhVE6/+BShqnZ4IJVEZxyjuwKfMS6Jms D34w== X-Gm-Message-State: ACgBeo1/bIGef3j44uA4SSxQb/TKg7qXmpApFA+fF4paeSMt6X3mvBUi ENTz/12yO5zHKi4ib2FfwD8= X-Google-Smtp-Source: AA6agR6/cTAVNB2gJ6Q5yLayiUSp9J8axMaA2UvkltnAQknb0qPfdRdMCbKdsCS63D4nEi+1IcaxrQ== X-Received: by 2002:a05:620a:4447:b0:6c6:c438:1ced with SMTP id w7-20020a05620a444700b006c6c4381cedmr28568302qkp.658.1663182602724; Wed, 14 Sep 2022 12:10:02 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id p8-20020a05622a00c800b0035bb8168daesm2300105qtw.57.2022.09.14.12.09.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 12:10:01 -0700 (PDT) From: Doug Berger To: Mike Kravetz , Muchun Song Cc: Andrew Morton , Oscar Salvador , linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Doug Berger Subject: [PATCH] mm/hugetlb: correct demote page offset logic Date: Wed, 14 Sep 2022 12:09:17 -0700 Message-Id: <20220914190917.3517663-1-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663182603; a=rsa-sha256; cv=none; b=2Cgn4ae3C8SqxSIjtJh088t+tPEpmxmzH516BHarxAk4hBySNaUWImDyoj29gQK8UdE/Rq sdK0Jt8BnBr8eDwUXWygmLhUVWECTM/7TaMU11OUtxAp6wJcmSaHw1y1yVxICwkH+2oNQQ 9d9OwA2eMYpI6u8q1K5U1Yw0RZoHlA4= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Dw+JcD8D; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of opendmb@gmail.com designates 209.85.222.181 as permitted sender) smtp.mailfrom=opendmb@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663182603; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=6mBQHGkTCxpZ0kR+Uol1DB+Rk5F3r94azBv7C4epuC0=; b=tOQfX1V2eFoXU251knSHnu7pWLNkkNIZkhLcFOhHgq0Jmd8WHiH4fsPFn5g7SMTF9YvWmN BHCKmnExJXyB0f/qgoUmopvQhMC8UB5IaGC5v4HbA8FkJh9K6XrKlsx5H3B4cIpdebvzgy prskHm4ySZfwGVNTh8exQD8loiB4AjU= X-Rspam-User: X-Rspamd-Queue-Id: 7C6D8800A9 X-Rspamd-Server: rspam05 X-Stat-Signature: bjzniaajt8q6urhk4kkyhetjr1ra5e1u Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Dw+JcD8D; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of opendmb@gmail.com designates 209.85.222.181 as permitted sender) smtp.mailfrom=opendmb@gmail.com X-HE-Tag: 1663182603-939417 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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: Mike Kravetz Reviewed-by: Anshuman Khandual Reviewed-by: Oscar Salvador --- 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);