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: 13566621 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 6E4E6C48BF6 for ; Wed, 21 Feb 2024 23:50:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13D846B007E; Wed, 21 Feb 2024 18:50:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 09E856B0080; Wed, 21 Feb 2024 18:50:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE5FB6B0081; Wed, 21 Feb 2024 18:50:06 -0500 (EST) 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 BDA3C6B007E for ; Wed, 21 Feb 2024 18:50:06 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 88D781C0C7F for ; Wed, 21 Feb 2024 23:50:06 +0000 (UTC) X-FDA: 81817456812.10.AB8CF8F Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf03.hostedemail.com (Postfix) with ESMTP id BB27920019 for ; Wed, 21 Feb 2024 23:50:04 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="N15S/KaL"; spf=pass (imf03.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708559404; 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=Lre+UqQQHJdTu6yMn3GijLQ4gMqXOjZ+IEoJS056n7k=; b=iK/Gkk8KVDZct44rs7zb+FEP72hne/3CDYHixwf9zoh7RF3MH973THPFqh0BIUZbJh61lV wPd56OZma9fq3a1TiirmbMDIRyfSLbl9daLNI4QjA7ZpyhxY0+hfzxEAlrdRY40I6va4SE WeQotaiYm5pBRu6XGHE2FzC2s4if8ZE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708559404; a=rsa-sha256; cv=none; b=IbjpuSoVXUWL5W3/wERIn/ERloQbqjO7zThG8xkPMMiugs+ucimxm1DLUz3rfzLt+V8/GG mnmNlvhAsoiDdsvSiYI0gcVwDldGq9yUHWdYDpR63i3Bf5lUJlFbHoNR9slwuszM3BZDx7 vbBAic/V9M50xUBxC2VhORp1N7sKtmY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="N15S/KaL"; spf=pass (imf03.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1d94b222a3aso11479215ad.2 for ; Wed, 21 Feb 2024 15:50:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708559403; x=1709164203; darn=kvack.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=N15S/KaLFjxVQe2zJEqkxpLKqwOEP4oUGjAXYbUfDsXx4KT2sm/UrSy1R8ia1Tkgw1 orm9BYF+zfORWk5SM5BufTaW8zfhGb/bE0OSM4eLaHBUhWubgvRd6Aj24tzUSpwzXido PRaWpvMehDzulrXB2v/u1ko/HO7wG/HXNPopfI5WndDUaPexYSAj9+JPVsM0+yaat2Ft AFerCSr/WCHBP9rETb8ks5EmIMwVCapByhM8xbW4Mjq+dbbNQ5in7q+WLmy2gATf0w+U yK2ETrA3mRwk2aSbHV38rmv7KGzybwRRGXhWkmSOUQoVDXEslqIQDAH8pYn3tMEVlLZt znXg== 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=wb9aj1XCyaFPK63stuHrGiEKQOhH4Joklq4jA1kI8f+akovktShZ7Wlvufn7Mwx5cy 73MmSLT1AE0qEf2ikgQ4hD+sZlNlrfywCowzhBlFuQCZ/jiamx+uiU01t2CP2Iz8/sXZ 0H5+uUxqic+5TTQeSPac81Kqx7okfTZc0/NpFY8yBSbPL/fxkjK53oWVYDGtt7Dv4468 KwOjmm4wP4uLDroNuJYU+B+rARw0xL6R1tqOaKYqvEiFR1T7fKpaOdKbJU7nxOdtJZTx Zdl/koViG0Gl5NcF0iQt+KFH6tW3jNuq1RODnOLzzTupozn7EMBmim7/oK68GVM7/krF ivhQ== X-Gm-Message-State: AOJu0YwKk2d6s76uYGdbapMhoYF0AdvoXpf1uTQcb+QzEdNvafEMW4rS md9PHlxKbRLD5t6TYFQkkR5Lt/+M4UWH+lU0Pb+SqCMLJ0N3UzohGPuuwLee X-Google-Smtp-Source: AGHT+IHzBLxTwT83ejaeN5GYbEyyAPkmAr8zn2RrQRiLrYkA/4Vzbw5dz0rbMxD4XQ9QGsj2VVT/sw== 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> MIME-Version: 1.0 X-Rspamd-Queue-Id: BB27920019 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: w3eupjztks49nty75y778tb8s6yhf1wq X-HE-Tag: 1708559404-282855 X-HE-Meta: U2FsdGVkX1/9BJJFfthMEeEk8CbF9igB4uq4Uw1v663fC9PNawsKIYEn6i6g0PFcqcMcCT4RtWOMYQb7Uc/9wpCfijy/ZFcOUm2pLWYmcDr12pfAWbmMT6FLxfFnCCf9XDbChX0BojcY/yBJNs7tyAtFI3AJKpvs02fc4CM1klIILquzU5EPSoZ3/NU/oA4I2f+ERi6LBZT1g/tKX4IZTc3eXInvv6EvKt09u/drDV9G68qZMeWYb25MF7WBhj7kN265jRPi84yqpOtoLkfCVjL98E1I8IQH28NBnP0iPqfoEohrlHSD0XBa9J4D8DuPiaw+9lEBCqG/3SEkgtw0vj9pbsAfBdjQ+HYFOgzjYjxA7Mjb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gSps85Erpl9G0w4IAGzYxyiaHu5+2rwZo7DTccRFt+2+5rkoPP10HfSpbrDCljAkUdgoBvkS8bCYM/R99st1vIVlnEMZbMHcf4L9pJ4fQ6T55DqDjpobM/+CZj+LIfkzgjTDnHRwsliexcT45DB1H2pfBKWR/zMMGAQ== 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: 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);