From patchwork Tue Sep 13 19:54:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 12975311 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 673D8C6FA82 for ; Tue, 13 Sep 2022 19:58:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E6BBB6B007B; Tue, 13 Sep 2022 15:58:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E1BB08D0001; Tue, 13 Sep 2022 15:58:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE3166B007E; Tue, 13 Sep 2022 15:58:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BEBAD6B007B for ; Tue, 13 Sep 2022 15:58:06 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9867FA09EF for ; Tue, 13 Sep 2022 19:58:06 +0000 (UTC) X-FDA: 79908123372.25.2998B18 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) by imf01.hostedemail.com (Postfix) with ESMTP id 58A534009D for ; Tue, 13 Sep 2022 19:58:06 +0000 (UTC) Received: by mail-qv1-f44.google.com with SMTP id ml1so10115837qvb.1 for ; Tue, 13 Sep 2022 12:58:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=dgAC9wdSWdNnQd7c6lUo6ch6gbgfZ8Ik+m13B5omrFE=; b=pgU7qB1cfn3bbb6aqaPKVsP0QULztBXM6ZTdmlLajCShk8VBE78cxzG8Cv0iNse9pr raJ8GgLPcDyEkXzvMHViIvbgw2EPxCCCxmBWVydWXsbvHPXhV9LnTIQcxrhx+uvf4Xru 5WYEg1qQVSMXl/Ik2LXwDiiTB+uN5XnQ7jp32HYymQ2HZJZADmguB3tnteKHk9qIukRc jpn8LdBlaPcxTkVAmOKzkV+NLvIVifwROYLBZ5KLKak/eoCCJdA+KloOJgYdmZJeYMVG xPc5vPtISXEXXxdKiktdhoBVSWbwV6cguyuU1u/JwyBG7hVEPpa11URawNPjZH6cK9Db YImw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=dgAC9wdSWdNnQd7c6lUo6ch6gbgfZ8Ik+m13B5omrFE=; b=s9KXVGQ2dSZ7drNJhocvRMTzWZxqBhqEv2MB+jtk6c3er/6Mb9fKe2H6rfkgajvEt2 aqKUlW18op/LaramVBLNx9i7CyVewBIL0mU/j2SamJQ/0xgk9zdA6k5woWT5DJp1ifzU pXSWU6APSDuqzTbe80F3mowDb+rBElPFGROKRtbhJlXSCeXy+4umACYdPIT4mtIvEfYX msv5r3kSDGtU724m1ABkqO6Uzlf0tuh3ZpazdHRHmG6GYzCCXkUtmE+drRui42z++pN9 fCPYEVZYtI4UucHPJohg4pkc1dcO2CPHNFd3PJ9f5HYQYWtQP0vUTBF/rq+hKzqScAV1 dEdA== X-Gm-Message-State: ACgBeo1XRI8QCAmBJZqGouaUUMIv/qNHUkHfNnibDqzs483S/hnsg4Ml wBjiYR8IDCXBiaDfjLVQTJI= X-Google-Smtp-Source: AA6agR5N0IDxlcIGSy6m2BrDrpoJ44hk3cGJOE0+/g5noyEETZjDxRdlg2yegkHVtpvIIdmASzximw== X-Received: by 2002:a0c:a901:0:b0:4aa:a283:ef4a with SMTP id y1-20020a0ca901000000b004aaa283ef4amr28465376qva.53.1663099085481; Tue, 13 Sep 2022 12:58:05 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id s11-20020a05620a29cb00b006b8e049cf08sm276305qkp.2.2022.09.13.12.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 12:58:04 -0700 (PDT) From: Doug Berger To: Andrew Morton Cc: Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Frank Rowand , Mike Kravetz , Muchun Song , Mike Rapoport , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Borislav Petkov , "Paul E. McKenney" , Neeraj Upadhyay , Randy Dunlap , Damien Le Moal , Doug Berger , Florian Fainelli , David Hildenbrand , Zi Yan , Oscar Salvador , Hari Bathini , Kees Cook , - , KOSAKI Motohiro , Mel Gorman , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux.dev Subject: [PATCH 03/21] mm/hugetlb: correct demote page offset logic Date: Tue, 13 Sep 2022 12:54:50 -0700 Message-Id: <20220913195508.3511038-4-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220913195508.3511038-1-opendmb@gmail.com> References: <20220913195508.3511038-1-opendmb@gmail.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=pgU7qB1c; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of opendmb@gmail.com designates 209.85.219.44 as permitted sender) smtp.mailfrom=opendmb@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663099086; a=rsa-sha256; cv=none; b=LAT37yN9RDGn+7Y8f9Zx6SUCl7ynyDfeRdJ3aVOxeHRqNGtjWdo2oN1lRsVtghH4pOgEXI kqaM24vEi2Oe022RBk+GkEy+1VfRpkPV25FwgInyiI3gKmHnvmTAl+xo6S0A/NRaN42V1O qib5Zr4cYHH7VTcjBHWxCnJJ1K1CBoc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663099086; 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:in-reply-to:references:references:dkim-signature; bh=dgAC9wdSWdNnQd7c6lUo6ch6gbgfZ8Ik+m13B5omrFE=; b=t5UqZuoNjsMu7qF1ZO9msg6QPDhRN4KAj2OrhkqQip/RtNWiIy5TqLfnMmTlMkk1Vbhw/j ziIg4Cjx3BClb2HhekPdNiiajfyOf7zwIjQSeJhVZ/DI87DCcwNbtOLm76T90eZr+F7/yf jBS8Kn9AEpze97QJjrbESMP7dPpD2Ck= X-Rspam-User: Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=pgU7qB1c; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of opendmb@gmail.com designates 209.85.219.44 as permitted sender) smtp.mailfrom=opendmb@gmail.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 58A534009D X-Stat-Signature: xdese6toqen3qmr6ptit9hmb3xhn7y1f X-HE-Tag: 1663099086-482691 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 mem_map_offset function 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 Acked-by: Muchun Song --- mm/hugetlb.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 79949893ac12..a1d51a1f0404 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 = mem_map_offset(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);