Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp8312335rwn; Wed, 14 Sep 2022 12:17:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4yf8zzTLcIilneH+nOD4u++cUdT7c7BcdGhkHOGYP2F11io5JHScIhBFsp1KrupM7kkYAa X-Received: by 2002:a17:90b:164d:b0:202:69b3:1002 with SMTP id il13-20020a17090b164d00b0020269b31002mr6230939pjb.86.1663183023079; Wed, 14 Sep 2022 12:17:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663183023; cv=none; d=google.com; s=arc-20160816; b=phg2B+VbVXsR5flPRjt7tDyVao7BuD85rY1XyOOhxzqji3I7iFUHB71nbUJM+oittC BhtYBEDSUFExVByFMbe//ckP/d6gJxiPeinZvEXpUOv9yRpZqfaY0fwHMTUy35J64aQ3 xX2VjkryFJjXCq0NVo4FsqODfiXGIVVaLLWPk/DXjteaSN9dkV25GsKKt1eLnlZQ5P4a 8K6TWh6v33g/3LsgXHZIrgTcAUprn5LUbdQq6KB+mNst0Sad7VGBa3Y7qQj4E/0d8QPn bQ6Rdi6voNKLczzjcYE/iTGNI0KNbHvjsFhMPaRtKTs57G9Ht9woSEIdZ/niKO7TSHXh XoDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=6mBQHGkTCxpZ0kR+Uol1DB+Rk5F3r94azBv7C4epuC0=; b=UgD1lpEPgOdoC+rCeyQ9z/IVNV5Q3YifDSJV6yhv36Pxpt348lfA8d02dZ0VRlYF9o GSNbumUuq+GE53VfEK7CJcDmDMy756RyTax3hIC3w+P4dFiomewZMlyRScMh/qp+cXda A+9F/GI4uvnkW1g8KXTaWFz81/hMo1Kyg54AhsuZfW4/hl3+7KBMPRO78caIbLk4iYmf vrdFtvqUCXB5ALxqtVivXrlnQVcAFQR1YPaYNXykFvPgyWLfXphdv5cgOFAIj4Q0dW1P emQz2tM5gWPTqphaJbJoeGn4J+p5FB7vUTlhljo5qNrBZJj7VLKfiOkruSCAEeRKYdrq QJaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Dw+JcD8D; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g32-20020a635220000000b0043486074814si15723652pgb.661.2022.09.14.12.16.50; Wed, 14 Sep 2022 12:17:03 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Dw+JcD8D; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229609AbiINTKH (ORCPT + 99 others); Wed, 14 Sep 2022 15:10:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229550AbiINTKE (ORCPT ); Wed, 14 Sep 2022 15:10:04 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A0DC2ED60; Wed, 14 Sep 2022 12:10:03 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id c19so9734995qkm.7; 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=EJ7MvtnmSGvBYcw+KukO66V4/Ny+fepM6cq+g10KHx6g8iFDoxP3ZLeF5RBeu7k0f/ lIYzLTfoWE4Jxyrui0HKG7JaT2Crx+sLLzMZgF1z26VR7fUCiFlVdPGZQs4TQunD1zRD TEsf+B8RQbM4uLCUp9S+QHKnlpI7bpSNcHQ/w0HoW/yi4gG0pvu5eEPzF1cnJM1OSfUL 8xNMsehjNVNkCbTS8JT/5YBMDDNAYTsvSa0mgJ6ptLS1HTVbvqt+TOlAONBctlfYsQ6D 28AEL7F5iO0MlVDLlT+2C+vn934INm0O3jufckVSIVYzRWt7AJnSjJdAkRKdGXidr3SN sfZQ== X-Gm-Message-State: ACgBeo32yXgEPcHJxECtcOQEWLk3kC0fh+l3JViXa05ZPPhXtSKl/Clw wfApYzsRk4dY5kTV2zpljapeODrRHYg= 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 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: --- 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); -- 2.25.1