From patchwork Wed Feb 21 23:47:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 204498 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1364064dyc; Wed, 21 Feb 2024 15:51:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX21n43OoO5ssnUJhEHGUakF8MFRrpQeQ3iW2qJsDsPMYxRzulpj+6KVax3K01jRvTNLiwO2pXWgqZmr9g2Aqdz0s8ucg== X-Google-Smtp-Source: AGHT+IE9oeYKiBJtnYDOUObK+Pvbl6x3YZ5JAC6PeM25UgzxH5Y1FsmUydq8wrwuFq0L7W6U5P0A X-Received: by 2002:aa7:d996:0:b0:565:10cd:835 with SMTP id u22-20020aa7d996000000b0056510cd0835mr1611820eds.28.1708559482540; Wed, 21 Feb 2024 15:51:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708559482; cv=pass; d=google.com; s=arc-20160816; b=sdqcxF6Lj58kxKvQe3CYCKdsZYB/q6hHNECKIyRRdCA4qaH448ExgEcpKBEgbanI9D 3Nwb9LVzXHO0YCsBy5n9f9oDOvmlvNaw62vGwLapSc9hvilIjZxDesfOM4p/piWv4dhE JFhjU0KCm3fEFSPF4wA01H9smHIVT5DTthkMlT8OV2oo9BB402c/bbMCyhcuEe2QFsFu M/9X0Xwitg1qRr86qrmgVneqaLBZk0fDNxEJ/UcJVtPi9PMNHvsl7wDa3ThOEbKsd5pE ECrP70X/uO0ybZjIh7BT67Q3rHTsTOG8ZqnWyOt0wZa4bLsdwnaT5f5vvxvzICgok88M kUdw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Lre+UqQQHJdTu6yMn3GijLQ4gMqXOjZ+IEoJS056n7k=; fh=bYkyQ6TEkHmoVFeA4uBytIaOo1w6qWAI42GBNQ/IGOk=; b=MK7NkWp2nJDk8VLJdDZ93SDPstUV4HWizgRQOsKJx+boyZTPd6jMJvryHJ/2Si/nm0 OmfZYz1/eP3IzXyBDsiylqjngIyy2D/MnmBP+dNp3XoGH/mafM6Ap4lxgvjcR7pES2jo I8gO2qRNruU03Af5fTNdskAI+EQwjF5mNHK6qgqsap5csRNeVC7Le2J4F+c/5NZR42wn OhUpQ1PB4o7RWQls/2RlkWxN/RWeRGkePuCZcjbI1QUOuRaEuJbjK9uQCKy3H3OSMlYb qg1/M0n71eEH8HOwj5AvXpereKyj2nZMqcr9sbqXNGSq0WExNPv6dIcUboYqrT17EniK vIEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JUTXxe3V; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-75686-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75686-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v3-20020a50d583000000b00561d43bb5f2si4690504edi.387.2024.02.21.15.51.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 15:51:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75686-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JUTXxe3V; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-75686-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75686-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 2B3B91F24361 for ; Wed, 21 Feb 2024 23:51:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E32E132C23; Wed, 21 Feb 2024 23:50:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JUTXxe3V" Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D3B312DDBF for ; Wed, 21 Feb 2024 23:50:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708559405; cv=none; b=a7AHBgRohDWCC1qW8FUNUHX/gUCufbv+00au/UBkbRYYrD2TddZ+AZl0Di4hWpQeV+Uq0bc5KMfMUYAYKCP+41Ob4Wi6KgOCoeyQKS7Ej81AaOGu+8eC1pMei7EPYLCEy4dd2BOy7/TNB6k77le7rc9TXysjpgLF71D03XZ3BmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708559405; c=relaxed/simple; bh=XJuffzEnSNsKJ3424e4z6pRxfuv0ZSk9YKCo6w6QkXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aqrnIHChCIPdoZewYYyuPCDBckhOM4QxpAV6EZp08kUZlDpbP7d8oHZihUoVzw+twwl8s/NOMEsxwWBNeK2ZxJktGcOnHbShokILeZlz2+NXAv/11czhzVjd8DYs0Gvyfr8t2+NkdvLndAyBwlGeXLJbHM/wDraOjjgDymaH0YQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JUTXxe3V; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1d51ba18e1bso12930705ad.0 for ; Wed, 21 Feb 2024 15:50:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708559403; x=1709164203; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Lre+UqQQHJdTu6yMn3GijLQ4gMqXOjZ+IEoJS056n7k=; b=JUTXxe3V3B3NiQcRIjnkJ4afoy78xQD5DeWFZUsj8s51ZGtMTbZYeSSM7ozrNym+pf SI6NhHXgsFpexqtsOXM330c2qSB/fuA+xCZFihB4k4elUGsMhk1lChCgL7B+HfXam3Eb NuA5JKCRpYvAIcyif7rTsg+j2Vh+1Ao0v61iH0KPC5B8blcWdIG56PizsiEV5/aVB76C EkkvpH5ZmjIMw7kA7+HSSmkAa/V1zSumR1LZzzIHWgjINiD2C7DUB3cDLpn8iZBNnbGQ uF86omCfk7PrfP/b/DN7toJc2WvNDaHQYwjgUyTLTViuBYk7xTRoyT21RxYfZXqxHW6j cPsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708559403; x=1709164203; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Lre+UqQQHJdTu6yMn3GijLQ4gMqXOjZ+IEoJS056n7k=; b=Ic6uMtgJeoDfNifoT7kXI/UhBjRsoMhCbMhxt2piADf+DpH514S5Nv4Y9Padj6JXM1 uppeV5k/SPUIOSlLyvs9UPZRbpxDk0uQyLja5vCNoWYtoMVCNZaJg29VPFJCHd2+nyT5 VTjf2wDcHPDRgB82NrmoN8uflL3RqZjB9Pqyj6KwCwiO4nbD6RSQzJmVVuy5OY9gqWu6 jDnBxBEhelu5Oa1swgWIL+gI3tsELg33dQNO0c/WAWmVJOmCWDTz8cmuahoeOJZOMBVp Zix3bk0uZHp2z/G/478EkZc9+eHGXGfhhj1rL0u2WLCZI93Bq9g4lLv1avmTeQzMZXFJ 4pxA== X-Gm-Message-State: AOJu0YwTg62NCwMmzy+ybY0mBrgkbt1FBN/VundYkSO89Z8sqQyd1MbB RoWaiB0W5bZAwHR8VDdUUPChZQSvu1A1nlRvXvQpE4CrdhXvvXzkF0gs7Ua7 X-Received: by 2002:a17:902:ce82:b0:1db:f8ef:a9e2 with SMTP id f2-20020a170902ce8200b001dbf8efa9e2mr11700757plg.47.1708559403319; Wed, 21 Feb 2024 15:50:03 -0800 (PST) Received: from fedora.. (c-73-170-51-167.hsd1.ca.comcast.net. [73.170.51.167]) by smtp.googlemail.com with ESMTPSA id jx3-20020a170903138300b001d752c4f36asm8657794plb.78.2024.02.21.15.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 15:50:02 -0800 (PST) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, muchun.song@linux.dev, willy@infradead.org, "Vishal Moola (Oracle)" Subject: [PATCH v2 4/5] hugetlb: Use vmf_anon_prepare() instead of anon_vma_prepare() Date: Wed, 21 Feb 2024 15:47:31 -0800 Message-ID: <20240221234732.187629-5-vishal.moola@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240221234732.187629-1-vishal.moola@gmail.com> References: <20240221234732.187629-1-vishal.moola@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791554468154920589 X-GMAIL-MSGID: 1791554468154920589 hugetlb_no_page() and hugetlb_wp() call anon_vma_prepare(). In preparation for hugetlb to safely handle faults under the VMA lock, use vmf_anon_prepare() here instead. Additionally, passing hugetlb_wp() the vm_fault struct from hugetlb_fault() works toward cleaning up the hugetlb code and function stack. Signed-off-by: Vishal Moola (Oracle) Reviewed-by: Matthew Wilcox (Oracle) --- mm/hugetlb.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 70c5870e859e..ae8c8b3da981 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5826,7 +5826,8 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma, */ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long address, pte_t *ptep, unsigned int flags, - struct folio *pagecache_folio, spinlock_t *ptl) + struct folio *pagecache_folio, spinlock_t *ptl, + struct vm_fault *vmf) { const bool unshare = flags & FAULT_FLAG_UNSHARE; pte_t pte = huge_ptep_get(ptep); @@ -5960,10 +5961,9 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, * When the original hugepage is shared one, it does not have * anon_vma prepared. */ - if (unlikely(anon_vma_prepare(vma))) { - ret = VM_FAULT_OOM; + ret = vmf_anon_prepare(vmf); + if (unlikely(ret)) goto out_release_all; - } if (copy_user_large_folio(new_folio, old_folio, address, vma)) { ret = VM_FAULT_HWPOISON_LARGE; @@ -6203,10 +6203,10 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, new_pagecache_folio = true; } else { folio_lock(folio); - if (unlikely(anon_vma_prepare(vma))) { - ret = VM_FAULT_OOM; + + ret = vmf_anon_prepare(vmf); + if (unlikely(ret)) goto backout_unlocked; - } anon_rmap = 1; } } else { @@ -6273,7 +6273,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, hugetlb_count_add(pages_per_huge_page(h), mm); if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) { /* Optimization, do the COW without a second fault */ - ret = hugetlb_wp(mm, vma, address, ptep, flags, folio, ptl); + ret = hugetlb_wp(mm, vma, address, ptep, flags, folio, ptl, vmf); } spin_unlock(ptl); @@ -6496,7 +6496,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, if (flags & (FAULT_FLAG_WRITE|FAULT_FLAG_UNSHARE)) { if (!huge_pte_write(entry)) { ret = hugetlb_wp(mm, vma, address, ptep, flags, - pagecache_folio, ptl); + pagecache_folio, ptl, &vmf); goto out_put_page; } else if (likely(flags & FAULT_FLAG_WRITE)) { entry = huge_pte_mkdirty(entry);