From patchwork Mon Dec 11 15:56:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13487441 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 761B4C4167B for ; Mon, 11 Dec 2023 15:57:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C95BF6B0106; Mon, 11 Dec 2023 10:57:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BD23F6B0108; Mon, 11 Dec 2023 10:57:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A75F86B0109; Mon, 11 Dec 2023 10:57:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 91DA06B0106 for ; Mon, 11 Dec 2023 10:57:23 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 68F2812078D for ; Mon, 11 Dec 2023 15:57:23 +0000 (UTC) X-FDA: 81554991966.09.C4F12E0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id B92BB20022 for ; Mon, 11 Dec 2023 15:57:21 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gfo2UJjd; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.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=1702310241; 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=6j0c9ENvnxisPX95qRO4NJave2eFRdDuqpK0xgwx6DM=; b=EU1Su9Ji3Qbz8Ds7/khi3nInSZZIcAzpyUh7oGFT7V1JHz0FRuMYVtxRcgdQcj2gVLTyLy L7SZ3lOtUcPVfXGvDH7L7O0pz8Ctk6c0s6iQ2KwK+9p4DkeJBG+DvKlIZb5zltI2/OGFJm wfhqGtNbMPHRzI7h2+kFL+Cse+81oQs= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gfo2UJjd; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.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=1702310241; a=rsa-sha256; cv=none; b=hBhvkxO/CoJe3z5F84MmbNzey3dlKyn/HbFy8po4eobU2yaZtf8SwqkqsyslkstnYesr4l aYVdijq8fy68K1HnwwXGWcsAjTi8mLNy6eurNv+ZAi2+n5ezro+iqZ/SetnzCUuXMRrdlJ j0ph454zff3+gQHYO/zaSTKfqVFruxg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702310241; 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=6j0c9ENvnxisPX95qRO4NJave2eFRdDuqpK0xgwx6DM=; b=gfo2UJjdIc6+LWee59VC4khwpGS9QyOHXkCFtmc2JnP9nF4SwvEDWPUD+KO0oPB9g6pNgx ArhybpxztyvyzmSkgxkc3BuEcNO+gmluH+T6zWT0MeD4ffzPHZuZYNh+UiDOS+Wd1VEVhS IA0GUk/6UP62EkfvLoXJ3wfGTcVvG+g= 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-453-i-re_ooQPI6Z0iay6LlX8A-1; Mon, 11 Dec 2023 10:57:17 -0500 X-MC-Unique: i-re_ooQPI6Z0iay6LlX8A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 321B73C2865F; Mon, 11 Dec 2023 15:57:17 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D4961121306; Mon, 11 Dec 2023 15:57:15 +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 v1 08/39] mm/memory: page_add_file_rmap() -> folio_add_file_rmap_[pte|pmd]() Date: Mon, 11 Dec 2023 16:56:21 +0100 Message-ID: <20231211155652.131054-9-david@redhat.com> In-Reply-To: <20231211155652.131054-1-david@redhat.com> References: <20231211155652.131054-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B92BB20022 X-Stat-Signature: j599157o3aiipuoaoz1gyqz7wg84omdn X-Rspam-User: X-HE-Tag: 1702310241-839083 X-HE-Meta: U2FsdGVkX1+vaqVQERXQApcYm5p0b/ISaRzQMWdbCdFYyDUoHqLAp1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VOQK9YEeG4CwTG4MgOlUqoEkbk0Mj1hsSsnTRIPVCdEu8fqGhhtxzkc/42HVykEF/HnU49g+vNiGrEHtt505UQS035P5NsqKbz2ENo9rg/cBuvCPxjymSc35r7SMDgw== 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 Signed-off-by: David Hildenbrand Reviewed-by: Ryan Roberts --- mm/memory.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 6a5540ba3c65..70754fd65788 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