From patchwork Tue Sep 10 23:43:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13799485 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 A96D3EE01F1 for ; Tue, 10 Sep 2024 23:45:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C7998D00D7; Tue, 10 Sep 2024 19:44:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0013E8D0002; Tue, 10 Sep 2024 19:44:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBB518D00D7; Tue, 10 Sep 2024 19:44:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B5E518D0002 for ; Tue, 10 Sep 2024 19:44:55 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 73BF0A91EA for ; Tue, 10 Sep 2024 23:44:55 +0000 (UTC) X-FDA: 82550461350.18.F83718D Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf05.hostedemail.com (Postfix) with ESMTP id A97CE10000F for ; Tue, 10 Sep 2024 23:44:53 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Gm0Y4QJt; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of 39NngZgsKCGkHJRLYSLfaUNNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--ackerleytng.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=39NngZgsKCGkHJRLYSLfaUNNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--ackerleytng.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726011809; a=rsa-sha256; cv=none; b=6hCQPr+iru2QW+iKrL1kXaDHT27GIusgqWrZvFMU0OMbUVqQVXsuRjxOPnaTbPlMANIjk5 ySHqYMP0DBHpKs1bKapQmTAPse7i9cDwUwJfmS/dwxqu0SqBLgEIaVKBYWsaVK06sWN6F6 oikqfQ+KnLkTNmAgewU6zqy4vaEjuhs= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Gm0Y4QJt; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of 39NngZgsKCGkHJRLYSLfaUNNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--ackerleytng.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=39NngZgsKCGkHJRLYSLfaUNNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--ackerleytng.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726011809; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gEfEne/GQ2Ka6MCKI1Fo0Z3xc55YqHsI9PC21Ep9Z3Y=; b=WELnJltJazBYG3uzVHNh/FAFXE5YvnjEWb3aLQt5GThWjch5MBMtXD0eWj0EvKiImyxAli iLbowYWrwAyhEpGoB+MNiRyUJLX7ftm/2wjReAZweo4ZAifXKXZeTzOs2bhpESBeHPpqW7 zIxnChMR2JqQBU3wkxygDMy6qUK2V0o= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e1a74f824f9so2807380276.1 for ; Tue, 10 Sep 2024 16:44:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726011893; x=1726616693; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gEfEne/GQ2Ka6MCKI1Fo0Z3xc55YqHsI9PC21Ep9Z3Y=; b=Gm0Y4QJtnjHPOuD9bg2mizdWUKePvjtIITzg6kvFNxjTC/SivgNJoi2P6F+ZyZWTFf kmqh+cORdys3FxKF5UEEuqvAv7tQ5sG9Z/VgOzZvncjkCobU/DgwcFr+7mMEOQUBnEra 0Hl5hGzgSsSbHA4255NIBYNHhfhwv+rqR26LVPqM9Pzg2XDW8cWji3nEuFQXpuhtEZLi W1IqAc8SlbhTgFXe3EvRZdv0BChBxvWl9DxNe4JI1CSWfvmwZbde+0iH1Ce8FfG/vWkn ak8qXtqlyZdr7LGGNyjtqeIdR7fEAXIUltsS3fz5nffiqwrNHEj7+X7pbybJhBGgF7M1 wWEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726011893; x=1726616693; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gEfEne/GQ2Ka6MCKI1Fo0Z3xc55YqHsI9PC21Ep9Z3Y=; b=oo/ptbI/wNy0Q8KtF87Z4D7n6go6cigJP1Z1nxGNsabQhXwFPgkE+Fdhb+fAe7BPRI P1aVnhIoSqEZDLV+JGk14/tycOx5R4IgpH9NqWnBnhy0G693tiaDjugTuDFm3YRBra5N yvho4X4j8yUIF/CMZRUPUmIqUn/ZM3Ri5Hf3za4xzRMm8zgaf3Si9NEidE0mE58LFLJn iv0OqAUzfUCO6HLNBPngUG1Av68ESDQ7Iyc7GDzQhDqg7uWeh04oY5ohcOZWq2GCBQ24 1kQwbCeHROMfb4CxDiDTSIFSOSGheb94h8zRvJpvGlZ0S+Dtcno+JcuiZL3YdTiF1kT5 Dbmw== X-Forwarded-Encrypted: i=1; AJvYcCV5ejeuYSNvvjbroEnaOjNCP8WSrp1Cxr1v4GeC4eaUYm8V86cUtfXmLlSDr5by8YjQhzE/wi7FwA==@kvack.org X-Gm-Message-State: AOJu0YxnFLlHfXvUcihmrPBgDPhyiZ+bnUHtSszbQz2FJqma6QskcY4K 8SobydjKC005j4ccrpoB4q0UUvjKZYc0cqG5cRCshR77LR17JEv6GUTsXENhqamWk4m3t8+Z+JF cF29+MsxrMoJu6RQHR1iKBQ== X-Google-Smtp-Source: AGHT+IF6ODlxEXjF8aJZSBZZ4I/iqFxheCqSbnSqwhL4p+xdg87aJqDyTNVQn4Ts0x37EKQBXrqF/+I4z5+HsrSwWw== X-Received: from ackerleytng-ctop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:13f8]) (user=ackerleytng job=sendgmr) by 2002:a25:698a:0:b0:e16:50d2:3d39 with SMTP id 3f1490d57ef6-e1d8c5610cbmr1470276.9.1726011892629; Tue, 10 Sep 2024 16:44:52 -0700 (PDT) Date: Tue, 10 Sep 2024 23:43:43 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <315ae41e7a53edab139c0323fa96892f2b647450.1726009989.git.ackerleytng@google.com> Subject: [RFC PATCH 12/39] mm: hugetlb: Move and expose hugetlb_zero_partial_page() From: Ackerley Tng To: tabba@google.com, quic_eberman@quicinc.com, roypat@amazon.co.uk, jgg@nvidia.com, peterx@redhat.com, david@redhat.com, rientjes@google.com, fvdl@google.com, jthoughton@google.com, seanjc@google.com, pbonzini@redhat.com, zhiquan1.li@intel.com, fan.du@intel.com, jun.miao@intel.com, isaku.yamahata@intel.com, muchun.song@linux.dev, mike.kravetz@oracle.com Cc: erdemaktas@google.com, vannapurve@google.com, ackerleytng@google.com, qperret@google.com, jhubbard@nvidia.com, willy@infradead.org, shuah@kernel.org, brauner@kernel.org, bfoster@redhat.com, kent.overstreet@linux.dev, pvorel@suse.cz, rppt@kernel.org, richard.weiyang@gmail.com, anup@brainfault.org, haibo1.xu@intel.com, ajones@ventanamicro.com, vkuznets@redhat.com, maciej.wieczor-retman@intel.com, pgonda@google.com, oliver.upton@linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-fsdevel@kvack.org X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A97CE10000F X-Stat-Signature: eauuapedrg5ha7eu5f4jkokkkxnjrnpn X-Rspam-User: X-HE-Tag: 1726011893-33060 X-HE-Meta: U2FsdGVkX1/WqjkMVkz2t4F/akcZALSTTw0URCzfeRxKB87tAtMOBAPMbWydZLJSRaKY31NJMyZjYw5ewWKhSGicGmqDP4/rPVSgElcesAlxYhbN4ahdUQ5w7J9BpzvSlUwXGKGW9vAoXdwYiUbpc7cquovK3/3p9pp8k9F4QTMZrsabtAmthLlMS9Wp1GepNQHskN60+OX6T+y4f5NcWjU4NCqUYwMdqCB7wLyGiZ5nkBfjCXWgd+XQx8Dxf9rlG9r7PjAhnJaR7HUnaVbmUmtVRHka1aLQKWAlecSCR8RDdE7tSGifcfffXTwaroJkna4Zc2RYIqs4HK9iBDEfSdzJTntiZpnt0nTGfnTIM4TA7CKRrHucMkrzi5xO1xX7AjMgKKkf8QE3chEQE6G2/I6mcNyAQy9KZNFoYAu5j1sMS7EFN4Fy4UMji3nq2U/NCJ/I4JPdcM4VKGNQzTprT2DQOlPwWC7PJVUjliJE9TlR6hUmFT7JnGripksAY0g3eJKcPW5QEJaf1EDWbFS57b3xP/YP28QC1VsDm/XeWcX6xjgca9GF7tCeZcaVz8NnwbfuwIMhDZ24kYjCCRNbS/cPsVEROlFWVShWfYfsdGOJO/KZIPNWV2YLtPMW6RIhbWS7PtGQdLTce0rSz9zfNaZOcc/Ysec8dxAfBrV1/lxaTBWwgSpN+JebcJh7eMmNp/JycEWYrx1slLeqmQA0eyD+ij97a+W71n353lOjAqVdeXgroyezRJlGw7+MeBnKTTh+52SYcb9fG9jTeNtgr1NT7Gmy6gYtwi+BpNjz2rMiRW519/M6ddyYz86Tg1rxMAlRBtmEtzKzkbOnhGp6uCRMUMxJepA1DNR06baYfL4q834fD5qWqpK7HK06OkJGTx4vOBobJ4IumOWw/j3BZCPigCkyQh3emwTUikNgUfgs3Q78H1tTCLYbn79/Lof+gEvdk9u3aFWX6cjbf7e bmVJlowG 5WIeBNWXs+KyTgPmA9NhYxd/bsng04hA/umTic4OGutrldx5h65AWguBxIhuPhnYTxcsiPpGOACQcynwO9CRWncBpZJ3Rk9uQZLSVlBkJU3KYi0cINbpe+2vy6bgouEbv4MmsAHgGUHjHXzLfNrqh3hHK5B2ccsGIxHnP4Q02oWq3C2W5SYJW9cNSNv3BJc4leo4/X23LoNtYPdgkh5yRmqVjKeSJwC5SattGAtYYVMbe0StSB28p/DOhDGPe6umFudM3FwoVYMctJ91/MrP36FnKXmkGsiU7toeC40kc2aM9ijpFo3QxxTeCHQmR9dECHOy8H5cUU0PrD4TPBYzSecsiu3j+KLktHIJ1FMpxKYOVDY1uJN3yML4k5BPrLGKAcB1YbkayMhh+ro4NYJIl8shRubXCgmaY0TAdVaDbpd3IUveeN1H57I9xZ6fOvHxKoRzMpw7qbIxOM6F4qWttmvlimoQ0VeIcvRcebIoL4JGYwlJBTttgU+Gin060N6PH9M5P2Tgm8obifrubjRY9FHXM8oxI4z4BKS8LC9ZDR3w8GBHxcGfhhFNn+mDw6kuJmfraW/ZdUUiSp3vaZTop4q9zfnwCDB4IVK0ode0Ur4eduEkkD5jdi3ERMYJCtzMQ7IOUwxAo+0SyA5X6NcOp0/BDPoYL5rDF642K4dCzrtTUXokUQySTQovABGjx6diBGmqR2Fhpohz1R3s= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This will used by guest_memfd in a later patch. Signed-off-by: Ackerley Tng --- fs/hugetlbfs/inode.c | 33 +++++---------------------------- include/linux/hugetlb.h | 3 +++ mm/hugetlb.c | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 300a6ef300c1..f76001418672 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -720,29 +720,6 @@ static void hugetlb_vmtruncate(struct inode *inode, loff_t offset) remove_inode_hugepages(inode, offset, LLONG_MAX); } -static void hugetlbfs_zero_partial_page(struct hstate *h, - struct address_space *mapping, - loff_t start, - loff_t end) -{ - pgoff_t idx = start >> huge_page_shift(h); - struct folio *folio; - - folio = filemap_lock_hugetlb_folio(h, mapping, idx); - if (IS_ERR(folio)) - return; - - start = start & ~huge_page_mask(h); - end = end & ~huge_page_mask(h); - if (!end) - end = huge_page_size(h); - - folio_zero_segment(folio, (size_t)start, (size_t)end); - - folio_unlock(folio); - folio_put(folio); -} - static long hugetlbfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) { struct hugetlbfs_inode_info *info = HUGETLBFS_I(inode); @@ -768,9 +745,10 @@ static long hugetlbfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) i_mmap_lock_write(mapping); /* If range starts before first full page, zero partial page. */ - if (offset < hole_start) - hugetlbfs_zero_partial_page(h, mapping, - offset, min(offset + len, hole_start)); + if (offset < hole_start) { + hugetlb_zero_partial_page(h, mapping, offset, + min(offset + len, hole_start)); + } /* Unmap users of full pages in the hole. */ if (hole_end > hole_start) { @@ -782,8 +760,7 @@ static long hugetlbfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) /* If range extends beyond last full page, zero partial page. */ if ((offset + len) > hole_end && (offset + len) > hole_start) - hugetlbfs_zero_partial_page(h, mapping, - hole_end, offset + len); + hugetlb_zero_partial_page(h, mapping, hole_end, offset + len); i_mmap_unlock_write(mapping); diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 4d47bf94c211..752062044b0b 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -124,6 +124,9 @@ long hugepage_subpool_put_pages(struct hugepage_subpool *spool, long delta); int hugetlb_acct_memory(struct hstate *h, long delta); +void hugetlb_zero_partial_page(struct hstate *h, struct address_space *mapping, + loff_t start, loff_t end); + void hugetlb_dup_vma_private(struct vm_area_struct *vma); void clear_vma_resv_huge_pages(struct vm_area_struct *vma); int move_hugetlb_page_tables(struct vm_area_struct *vma, diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 5a37b03e1361..372d8294fb2f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1989,6 +1989,27 @@ void free_huge_folio(struct folio *folio) } } +void hugetlb_zero_partial_page(struct hstate *h, struct address_space *mapping, + loff_t start, loff_t end) +{ + pgoff_t idx = start >> huge_page_shift(h); + struct folio *folio; + + folio = filemap_lock_hugetlb_folio(h, mapping, idx); + if (IS_ERR(folio)) + return; + + start = start & ~huge_page_mask(h); + end = end & ~huge_page_mask(h); + if (!end) + end = huge_page_size(h); + + folio_zero_segment(folio, (size_t)start, (size_t)end); + + folio_unlock(folio); + folio_put(folio); +} + /* * Must be called with the hugetlb lock held */