From patchwork Wed Apr 2 18:17:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 14036354 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 704F1C36018 for ; Wed, 2 Apr 2025 18:17:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4068B280008; Wed, 2 Apr 2025 14:17:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3654C280006; Wed, 2 Apr 2025 14:17:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0FA73280009; Wed, 2 Apr 2025 14:17:17 -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 CD51F280006 for ; Wed, 2 Apr 2025 14:17:17 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 05E1016044C for ; Wed, 2 Apr 2025 18:17:18 +0000 (UTC) X-FDA: 83289910956.04.719C326 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf02.hostedemail.com (Postfix) with ESMTP id 023E18000D for ; Wed, 2 Apr 2025 18:17:15 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=awmYQ8yE; spf=none (imf02.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743617836; 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=qTiP2D3OrGMsSaRwxahGkUod//8qVelF/nv7EzuQ3uQ=; b=ZWy9RAgfbXRaoCc0lUVYkLg6G+C5zpRjCikQJRDJNwL8f3wUNq32Oc6aUwcFZz21cn40oP j+ToU91fv6f9H1CcXGrjwCegmLjsFt76z3OhbZ0kx0ZgxyXQJWirBWY7PMuiAcRRGtPZ0R G1otcjae23XDyzsUfh4GJUCIRTz5ruI= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=awmYQ8yE; spf=none (imf02.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743617836; a=rsa-sha256; cv=none; b=NXl2N1Ar2KvmXtoR09iuBfdZv7YnURTm0vTAVibjtGp0/9p3R57UdZV6RSf9Gd65KwkVTY oHYZPGJzTcbzuUplDi1iQbcGi9unSFmzALYEae8qA8eK3S6w+n9PKCZBz5T8UuU8WnnTu4 UyR1Jy7/yAU99Ld4r68Tl2BFbhOhSY0= 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=qTiP2D3OrGMsSaRwxahGkUod//8qVelF/nv7EzuQ3uQ=; b=awmYQ8yEmw1Xbw+DXL1UpX4cf4 7g2FBet0xAZTYuMgfxIQPDUKNDEnYG1OojGXMU8dzq8v0Dm3Xg3bIZxZ8jUMHjYuLKpJaXjCPWDNj +P50tTxGfQW8TlF4INZKosrHKKdTKnkDF68CNIfsChqxVOgk92zVkt8mqJGO8NGK/rUmK8+TUCIhb E75NdS4YZUF7WIpVdxcrszpVRkKB+DuwbeD1pFngn1Pvl8oYcCadm7nkua9ReUvkYbuR3kNolwx1W dj13ssBLhJrGdpSmvHqvjztT1dip9P2Iv/lTxyo8Evgs/vo05MpzggO07vRbTvtVJBZIVCnwoKpwm g8QuymMA==; Received: from willy by casper.infradead.org with local (Exim 4.98.1 #2 (Red Hat Linux)) id 1u02eF-0000000A0ig-2MTV; 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, David Hildenbrand Subject: [PATCH v2 07/11] mm: Add folio_mk_pte() Date: Wed, 2 Apr 2025 19:17:01 +0100 Message-ID: <20250402181709.2386022-8-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: 023E18000D X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: gsjcbbzuj39sm5koph3g5j7dhzonkssn X-HE-Tag: 1743617835-791264 X-HE-Meta: U2FsdGVkX19ZPwtjtqTxz89HWb3Vwf/3ki0E8pNndPwZK+wgIs2MvVgODZQS/dwxNCHXq++APEW9E/LHrlQt8CSdJVFp7NDDNRORkk0wI9OOMghmLP2wXRCMvbSxzdQw4zkI2y2dMgCJj9VRTFhQ/48u1XFPEg6ldYUKa8ccONP5ecBkFba1vudvWvMnlFEhGNwpBc++yIv9lCqDug9P+RVSbTJexePLcYj7YKpGa4u6Pxa86+PyinTt62XKKBFD5Eejsz0IbmtKfnMLPhVjZNdYSh/vu6PmZigIiEGTTRzS0i0kBnqPL0YTmEKh0p0q5uV2d6Hh1KNy2eL2xgv+U4qe0Pwx6+jlAKR96At2wpgS8KIAz7jbQypzkUi/YstlrWeqbZLgNCUOyHMoRmSrCaUUfPeFH/gVFAyyKU8hsAhICJSO7OkCGXn4m4/NQv9F2YrdwJ30meyiE2LOKas5/sRduZW3OU4EPF9KXDzY1W9Y/61UCRAeXbZyEmmC+dH0iBlwIOF2hYhg0kvtB00HUcuBSGfDMxRfn5ISCyxhiOxpoJiyk19FjfT+610gTvE6Uort2Ml+Ed14OBm6gcHj8nsUCLbNnybXGjuiZ7fYxD6iGCDnEkoZ4tmwuqsy7YRqMGCHMiWZtCYFzuBN+nZ+oUWAK1Qr4tz0dGLlsYFPWd4o55Oh9GrC22gST8AZEsAsjcLZx52JmrJ/fHFYQRhV5b6FynDUn2iofeo7KYRP/i/aVvCWlcsV+0kPx0k/vqBQ9wI9/0Ky5P4R/gC4yCu6j9e7jH0bNKbc6RGl3wcK0Xb3w3wSUphSUajCCTlRYmbxfcvu45SvXomDjZAKn/oeXyAhkx3ToDtMzIUji4Rw/KVwv2XtnZBnkOm3cIDPcfB1A8iAQBK+8xMKHWDvhuSnxrnOSH7/Fv4kqoBacJIOH0qTp8k4LRw2EI9KUPW95SfSC5QFQ5+tTRqEA3XDmyH SNxgmQV4 nNwT1Mc+ItYPHJaAmCSmvNep7TKmtolGSZ75fNB+OIldpfVEyv+jIqZJIzF4lgb87mukcgN4/wt6OYlMBIhz+VnGuswpCP6AkLpZKpQBbv+vbHkv4we2bagwvT5QlU/akhe1PPGt5zyrKLszah5JphmnJVU2W6ExpX4WZaUsXO/GuMEEiOuF0qc8xNpmBoLoI+X/f61qSwIjsm9OxnsCFjj0pKgRmVA5Q4cvZWK86liogo/nU3v2tNF8LagIyKk8ZK2oMJQjeI/1nZBbY+tdvIgZPlHTNB6Q4jSvTMHnePjpPERoydJjTAW3MoA== 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: Removes a cast from folio to page in four callers of mk_pte(). Signed-off-by: Matthew Wilcox (Oracle) Acked-by: David Hildenbrand --- include/linux/mm.h | 15 +++++++++++++++ mm/memory.c | 6 +++--- mm/userfaultfd.c | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 5dc097b5d646..d657815305f7 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1992,6 +1992,21 @@ static inline pte_t mk_pte(struct page *page, pgprot_t pgprot) { return pfn_pte(page_to_pfn(page), pgprot); } + +/** + * folio_mk_pte - Create a PTE for this folio + * @folio: The folio to create a PTE for + * @pgprot: The page protection bits to use + * + * Create a page table entry for the first page of this folio. + * This is suitable for passing to set_ptes(). + * + * Return: A page table entry suitable for mapping this folio. + */ +static inline pte_t folio_mk_pte(struct folio *folio, pgprot_t pgprot) +{ + return pfn_pte(folio_pfn(folio), pgprot); +} #endif static inline bool folio_has_pincount(const struct folio *folio) diff --git a/mm/memory.c b/mm/memory.c index 68bcf639a78c..fc4d8152a2e4 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -929,7 +929,7 @@ copy_present_page(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma rss[MM_ANONPAGES]++; /* All done, just insert the new page copy in the child */ - pte = mk_pte(&new_folio->page, dst_vma->vm_page_prot); + pte = folio_mk_pte(new_folio, dst_vma->vm_page_prot); pte = maybe_mkwrite(pte_mkdirty(pte), dst_vma); if (userfaultfd_pte_wp(dst_vma, ptep_get(src_pte))) /* Uffd-wp needs to be delivered to dest pte as well */ @@ -3523,7 +3523,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) inc_mm_counter(mm, MM_ANONPAGES); } flush_cache_page(vma, vmf->address, pte_pfn(vmf->orig_pte)); - entry = mk_pte(&new_folio->page, vma->vm_page_prot); + entry = folio_mk_pte(new_folio, vma->vm_page_prot); entry = pte_sw_mkyoung(entry); if (unlikely(unshare)) { if (pte_soft_dirty(vmf->orig_pte)) @@ -5013,7 +5013,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) */ __folio_mark_uptodate(folio); - entry = mk_pte(&folio->page, vma->vm_page_prot); + entry = folio_mk_pte(folio, vma->vm_page_prot); entry = pte_sw_mkyoung(entry); if (vma->vm_flags & VM_WRITE) entry = pte_mkwrite(pte_mkdirty(entry), vma); diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index fbf2cf62ab9f..3d77c8254228 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1063,7 +1063,7 @@ static int move_present_pte(struct mm_struct *mm, folio_move_anon_rmap(src_folio, dst_vma); src_folio->index = linear_page_index(dst_vma, dst_addr); - orig_dst_pte = mk_pte(&src_folio->page, dst_vma->vm_page_prot); + orig_dst_pte = folio_mk_pte(src_folio, dst_vma->vm_page_prot); /* Follow mremap() behavior and treat the entry dirty after the move */ orig_dst_pte = pte_mkwrite(pte_mkdirty(orig_dst_pte), dst_vma);