From patchwork Wed Apr 2 18:17:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 14036358 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 0D328C36017 for ; Wed, 2 Apr 2025 18:17:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3C0E28000C; Wed, 2 Apr 2025 14:17:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 99D4A280006; Wed, 2 Apr 2025 14:17:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77A6528000C; Wed, 2 Apr 2025 14:17:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 49B09280006 for ; Wed, 2 Apr 2025 14:17:29 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 896971A063E for ; Wed, 2 Apr 2025 18:17:29 +0000 (UTC) X-FDA: 83289911418.20.2C9D4B0 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf08.hostedemail.com (Postfix) with ESMTP id 0170C160003 for ; Wed, 2 Apr 2025 18:17:27 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=KLXmh9XL; dmarc=none; spf=none (imf08.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743617848; a=rsa-sha256; cv=none; b=SqomqHlFR2MM3L5IAlKqs9vaOIGh83IQt2ZY0fW2If7znofWJCgxUUUFf9CGV3+w2nJNMH uTr5ltqktUifcmd9Sfv3jfch1KhELSluiZXrV3m21KdkDHQP0+RDin3/SsPW5/TFPMiUtD /+30ijB87g6VzmPwA8XeBiQu9won6M0= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=KLXmh9XL; dmarc=none; spf=none (imf08.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743617848; 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=YUZaMbW4I7OXHp12rW2s26jw5pZRBiflAQO7xH+epdQ=; b=LGHp1mzUZfGyJaMWRK4kNYNhkyCV1qzHAe4oKJ4Gsx3QkA4D4Im9w8Y6Kc6SuPpkdGfnyq 8H8imSpj4fhcTYFBKVauzgYeHC48/Ch4DdzPxVV6tXcNK24YtmdPE9mt5Z5z4Wwrd/z1g0 7V5XBngx7Uzh/KgPY8RLbDVB/qewQBU= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=YUZaMbW4I7OXHp12rW2s26jw5pZRBiflAQO7xH+epdQ=; b=KLXmh9XLowoSpHwZ9zM4XJydIz TqWk5i77jSlCFxWbMVP41th0m7mltbbAIhyscjEcZ2rqKCIEuoMRoD8m+tkh+GNG9gDl8rWlkOZkP fJKzIOFKoDy/lc/b2zPnyKxlgkgynJROldGu/GnUwxMQC1WFVqZaJlZssQ/5IhiixPJWsYVjXY6Lh iyp0jtqktkLNuxr/NRsw1lQda/qG6kWQ495VsU3nd+AJoAD5ypvjFgJm47HQeJFCQCKwnv0D/c3Mx DMSfkFCF4wKXPSKifK0Q0DRnMg3cMaeKkoAqLdt4f6wurG5VoJc5sbOu5ynI+5BSeypDTnkuW9GD+ Mt8qEIRg==; Received: from willy by casper.infradead.org with local (Exim 4.98.1 #2 (Red Hat Linux)) id 1u02eF-0000000A0ii-2im4; Wed, 02 Apr 2025 18:17:11 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-arch@vger.kernel.org Subject: [PATCH v2 08/11] hugetlb: Simplify make_huge_pte() Date: Wed, 2 Apr 2025 19:17:02 +0100 Message-ID: <20250402181709.2386022-9-willy@infradead.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402181709.2386022-1-willy@infradead.org> References: <20250402181709.2386022-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 0170C160003 X-Stat-Signature: shpe1eutrc6da4qeqjht7iemxhr4d9a7 X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1743617847-855534 X-HE-Meta: U2FsdGVkX18yVHof1rRdpbE6w0L+PUyiV5X86/Oo3h1AGuD/0oiGUith1YSQ+nqcuhMJniYWcGY1Vr92w0RyDb/+le3/TN+GjEF0DLqZIufuWcbka+ciXTSd+Fd1eXpxNRQg43vnACYxx3y66FDK8bersZx3opGPJr9BD/piEYcVaOQru7Rc1CCGbR14A+N7PJr9302LPMxXSevIxsnvDbouhdMbxR/Ux5OfuGRYBzyFUyRF2sntgbueC3syR98nhAV5LDoUNrNhOGyfTNZsvKQJjRAan8bj9TcqRq/7IngOFZgjPTo0s17gSEld0C2YKfu1fM2BjvOsH+IZTdnvmIYiT87CE48WZq4PGZi89wk7ILDeL17QW51Pf95xOPTgy6UnC8vRN6xItd8pbLY6Xpp0jDjWafgcILIcLscpSGKsmKnDHW7BFSXq4Jw3abMPxCdpKRVAqUiuKHVA3arRW2XEVJKRJCOGJrVb6Xn4ar2vYmIQGtoKptHg2eM6Soj/dok1YfFLtA8kLhEXK/Uvo5BTH8cx+1MQWCFQxp2gWd2nira0Qq2YkY7X+58PIZcnsv4ZSuUVSBAl00VUX9D83j6i7n1f5/n8oGge4WwgmGRFwHq13Cg87qoOsTdLdfRSBxSB8WJpPmw8JpBQ7Iw41dx4UJ8ccPG1SstjxZ99lXKePoL6aOFjGor6GH9us08/it9xLUG/VDbF3d5Y/fF/OXhfENjs655mQXqcs+ZhxiADMtFB1HL4MwHVyYV4vu1ARBVWLC0tbhKB/XHWstvGcoC9ya2i+mwe3/e2uk2rXghCBy+lu9sXMK9YLgZIldhFTqTwIW6SSXZHbdMRqKk8j/V2dzqupxOJPWDDGLsytw20Lez7WFpmXBMFsE6uaiY2ZkfuDSUKZPv2TVJ4P4zBfYhC11ndjSiVjS2Z7IZ8n/8hIFwc/iGd0QtYHp13CqjyWRae4XUvDpf7QD0LA0G hQ8El2R3 smjY/M/kvHAMWw2DbnhSnRg1XUMT+evHdebsq0jPCxAmrV980jVTIho6eX6sFD4agm0EbJutL+GrcMQD2aEdbANP+cKp0QIx6C02e1X75BzAf2v4oN1eIiqY0GsVCGQIrODWfOKi9dlx5MYt04ub8mAlIs7g/dTVo3gfwajrvLsh4yGx2IY4Ej27gATGG+9mpVZX8fqJxw45HtIwl2W9t0EnABBZMPz7d0z0AAtUtPTCRkJUGmuEmLH2EQFK3HY7kOQBG8AqwqDjdQBqjbJVBW6XQp4ASdIU1XsrC 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: List-Subscribe: List-Unsubscribe: mk_huge_pte() is a bad API. Despite its name, it creates a normal PTE which is later transformed into a huge PTE by arch_make_huge_pte(). So replace the page argument with a folio argument and call folio_mk_pte() instead. Then, because we now know this is a regular PTE rather than a huge one, use pte_mkdirty() instead of huge_pte_mkdirty() (and similar functions). Signed-off-by: Matthew Wilcox (Oracle) --- mm/hugetlb.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 6fccfe6d046c..df185f10bc9e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5441,18 +5441,16 @@ const struct vm_operations_struct hugetlb_vm_ops = { .pagesize = hugetlb_vm_op_pagesize, }; -static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page, +static pte_t make_huge_pte(struct vm_area_struct *vma, struct folio *folio, bool try_mkwrite) { - pte_t entry; + pte_t entry = folio_mk_pte(folio, vma->vm_page_prot); unsigned int shift = huge_page_shift(hstate_vma(vma)); if (try_mkwrite && (vma->vm_flags & VM_WRITE)) { - entry = huge_pte_mkwrite(huge_pte_mkdirty(mk_huge_pte(page, - vma->vm_page_prot))); + entry = pte_mkwrite_novma(pte_mkdirty(entry)); } else { - entry = huge_pte_wrprotect(mk_huge_pte(page, - vma->vm_page_prot)); + entry = pte_wrprotect(entry); } entry = pte_mkyoung(entry); entry = arch_make_huge_pte(entry, shift, vma->vm_flags); @@ -5507,7 +5505,7 @@ static void hugetlb_install_folio(struct vm_area_struct *vma, pte_t *ptep, unsigned long addr, struct folio *new_folio, pte_t old, unsigned long sz) { - pte_t newpte = make_huge_pte(vma, &new_folio->page, true); + pte_t newpte = make_huge_pte(vma, new_folio, true); __folio_mark_uptodate(new_folio); hugetlb_add_new_anon_rmap(new_folio, vma, addr); @@ -6257,7 +6255,7 @@ static vm_fault_t hugetlb_wp(struct folio *pagecache_folio, spin_lock(vmf->ptl); vmf->pte = hugetlb_walk(vma, vmf->address, huge_page_size(h)); if (likely(vmf->pte && pte_same(huge_ptep_get(mm, vmf->address, vmf->pte), pte))) { - pte_t newpte = make_huge_pte(vma, &new_folio->page, !unshare); + pte_t newpte = make_huge_pte(vma, new_folio, !unshare); /* Break COW or unshare */ huge_ptep_clear_flush(vma, vmf->address, vmf->pte); @@ -6537,7 +6535,7 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping, hugetlb_add_new_anon_rmap(folio, vma, vmf->address); else hugetlb_add_file_rmap(folio); - new_pte = make_huge_pte(vma, &folio->page, vma->vm_flags & VM_SHARED); + new_pte = make_huge_pte(vma, folio, vma->vm_flags & VM_SHARED); /* * If this pte was previously wr-protected, keep it wr-protected even * if populated. @@ -7022,7 +7020,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, * For either: (1) CONTINUE on a non-shared VMA, or (2) UFFDIO_COPY * with wp flag set, don't set pte write bit. */ - _dst_pte = make_huge_pte(dst_vma, &folio->page, + _dst_pte = make_huge_pte(dst_vma, folio, !wp_enabled && !(is_continue && !vm_shared)); /* * Always mark UFFDIO_COPY page dirty; note that this may not be