From patchwork Wed Dec 20 22:44:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13500621 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 14F63C3DA6E for ; Wed, 20 Dec 2023 22:45:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3E718D000A; Wed, 20 Dec 2023 17:45:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F0798D0002; Wed, 20 Dec 2023 17:45:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88FB28D000A; Wed, 20 Dec 2023 17:45:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 74F058D0002 for ; Wed, 20 Dec 2023 17:45:37 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4672716010B for ; Wed, 20 Dec 2023 22:45:37 +0000 (UTC) X-FDA: 81588679914.29.51AC44F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 980D410001D for ; Wed, 20 Dec 2023 22:45:35 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="dHZtPhJ/"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703112335; 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=/7RNQidug/EwvaArOE9sRzRSaxqKYQznxGvOG5hZ9FI=; b=pC+f7noyrGQSCxpYanIWO7sCdGOjDSdKGAnLgGR4f7XK58pmHx1Gmt6uQ5gTE8Unex376B XIUp7phjWeGEIrDwwWNxE/T6UDFlYP1TWkWfju8abHfuR/XlmxL4qKYaM9pR42iwoVwL0+ of7Z/oa7MjwIq5x/1QK8fBkKxl5IL5E= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="dHZtPhJ/"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703112335; a=rsa-sha256; cv=none; b=TbEDzhZF8uMI9WHzOW5Y6EJfizGK2dyIGaqZES9otRMhfUOocMIij5AiEI1Du4PjHcmjmN MX0m8Bi7zXmfaT+v2WAwE/5206wx4RPTliiVcmYO77WRqoiFW2XZgLX3c8w6kvY8J6JYM+ ZIdVucYC1cTrnIrB7kkEpeiKgM5rIkE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703112334; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/7RNQidug/EwvaArOE9sRzRSaxqKYQznxGvOG5hZ9FI=; b=dHZtPhJ/VlmSGWT5DKbZrqOnyDcWPI+bc9c5cGEGr9kiNtb8E7NAef4Cg+Z9eJC3xpHMyf Pk54gMBMmWMsDNIPm6a98e3vzZoG9tQcuclupuhkLBX9UWL8IokGuqEy776skIulsMbqtt jhv1e5zY0DU4ax0mKRMkQ7feIB1dDog= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-97-pT_9TgFiNeKKCpu7Ia4-ig-1; Wed, 20 Dec 2023 17:45:28 -0500 X-MC-Unique: pT_9TgFiNeKKCpu7Ia4-ig-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 11CCF1C41B24; Wed, 20 Dec 2023 22:45:28 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD23A40C6EB9; Wed, 20 Dec 2023 22:45:25 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Hugh Dickins , Ryan Roberts , Yin Fengwei , Mike Kravetz , Muchun Song , Peter Xu Subject: [PATCH v2 08/40] mm/memory: page_add_file_rmap() -> folio_add_file_rmap_[pte|pmd]() Date: Wed, 20 Dec 2023 23:44:32 +0100 Message-ID: <20231220224504.646757-9-david@redhat.com> In-Reply-To: <20231220224504.646757-1-david@redhat.com> References: <20231220224504.646757-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Queue-Id: 980D410001D X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 1i4yjwug4z8xh5a3b8gfaonu1hytqwzj X-HE-Tag: 1703112335-505158 X-HE-Meta: U2FsdGVkX185PGV7d4SzjL/7r9SGk/PIOcfMVQn8bG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+KxSPBgwgLGRFifjWW2fXZ70WhNw0qOdX0ke5UCx3MRnqDgK2dGqCnOspXiaiHmhwtwg9KCgy2cTp8cEzTZQHDcs5viCV9tm/kVGiGsf5h7els/VkR/PD8dy4XqPs3hFh7sjiGcu4njj6pkSn51ongylr+Ma36i+BY4f2D0843r/LIPEaPRhtkOE= 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: Let's convert insert_page_into_pte_locked() and do_set_pmd(). While at it, perform some folio conversion. Reviewed-by: Yin Fengwei Reviewed-by: Ryan Roberts Signed-off-by: David Hildenbrand --- mm/memory.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 7f957e5a84311..c77d3952d261f 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1859,12 +1859,14 @@ static int validate_page_before_insert(struct page *page) static int insert_page_into_pte_locked(struct vm_area_struct *vma, pte_t *pte, unsigned long addr, struct page *page, pgprot_t prot) { + struct folio *folio = page_folio(page); + if (!pte_none(ptep_get(pte))) return -EBUSY; /* Ok, finally just insert the thing.. */ - get_page(page); + folio_get(folio); inc_mm_counter(vma->vm_mm, mm_counter_file(page)); - page_add_file_rmap(page, vma, false); + folio_add_file_rmap_pte(folio, page, vma); set_pte_at(vma->vm_mm, addr, pte, mk_pte(page, prot)); return 0; } @@ -4409,6 +4411,7 @@ static void deposit_prealloc_pte(struct vm_fault *vmf) vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) { + struct folio *folio = page_folio(page); struct vm_area_struct *vma = vmf->vma; bool write = vmf->flags & FAULT_FLAG_WRITE; unsigned long haddr = vmf->address & HPAGE_PMD_MASK; @@ -4418,8 +4421,7 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) if (!thp_vma_suitable_order(vma, haddr, PMD_ORDER)) return ret; - page = compound_head(page); - if (compound_order(page) != HPAGE_PMD_ORDER) + if (page != &folio->page || folio_order(folio) != HPAGE_PMD_ORDER) return ret; /* @@ -4428,7 +4430,7 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) * check. This kind of THP just can be PTE mapped. Access to * the corrupted subpage should trigger SIGBUS as expected. */ - if (unlikely(PageHasHWPoisoned(page))) + if (unlikely(folio_test_has_hwpoisoned(folio))) return ret; /* @@ -4452,7 +4454,7 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma); add_mm_counter(vma->vm_mm, mm_counter_file(page), HPAGE_PMD_NR); - page_add_file_rmap(page, vma, true); + folio_add_file_rmap_pmd(folio, page, vma); /* * deposit and withdraw with pmd lock held