From patchwork Wed Feb 21 23:47:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 20762 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1363758dyc; Wed, 21 Feb 2024 15:50:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWNnIrIuSfwjwpgmgi3KMYXM0JooeQjqtvWi/71NuZNjb8nncKerm1BFJe/cExfWuP/DBGZ/YchYyEgv5M5xvS84loP3g== X-Google-Smtp-Source: AGHT+IHNLGlqLLhRtoJfKKPoLCd0NbU7N6pbDv8BisQHSrG6Vbnz55cDUdUjEYB6BrU0f8tpGYY0 X-Received: by 2002:a05:6402:1353:b0:564:4ff0:ce5 with SMTP id y19-20020a056402135300b005644ff00ce5mr7062775edw.20.1708559424531; Wed, 21 Feb 2024 15:50:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708559424; cv=pass; d=google.com; s=arc-20160816; b=F/CDGHov4i3kq0aMBoDAU0EGIMbx2W7sTI1DBJqW/WHQZEim+OxZn124AUlX5Ha5Op u0coyDkanpBB0GpkvJiGHStXR+K6C/fwt26An36ay9FIcgwgmKF5Q1pjWcLf2qNSZjJL Kad3ESY7fAFQ78CNBlzJBgH0WsfnkJJnJCTgAqxAXP0bSRq0Scc3zgELb5EXl0JBh6mT eKqkbmxruDXDIw3XCQRZh4ytERBEQa+IACkr0o/Pz85wVEY2GHGmy9oEtSuU+GacJhxw AehEd0vvQZCfPHVbMvItruLAsIX5C8XRUl9KihDXcUXoQRRQao3KZxWJNM1YCETgWzEO cFUw== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=JvioobkCVW12CjzalX+EBXJJJID4JZxUgaUQxw/lRTs=; fh=bYkyQ6TEkHmoVFeA4uBytIaOo1w6qWAI42GBNQ/IGOk=; b=NlL5jGkuWFJonWa8OlIsZBefKSeqG0guRnovDa3s1o1otT5AnEtXR9JgFb0JfmMe3o 1YCPlkVHsocIcMUGfk7iOxDxMgOt77q7NZP3s7JsZXMxTLwr+RZWdOfwLxBkfNqtXawS 3tTBe68NuyPtTelv0XNTyDYbgrItp2dijPGFyc/SE26kBvnklAwW8L1haM/TyMUU73ik NRaTAg0GcoyC0F4aZjzGIACQXgbcDk/KsfYNcr151nhdgWzqFIzm56smfop3mGWofqUK ih7a3050k3D9s8J7msXtit7BRIdMYUycmfB7xQVMG2q7IHtHyRxZFdZUzBD8G4iMZTow GSzQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=AUy6hCnd; 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-75682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75682-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id i24-20020a508718000000b00564d9e59a3esi1603461edb.135.2024.02.21.15.50.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 15:50:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=AUy6hCnd; 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-75682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75682-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 29CAC1F242C4 for ; Wed, 21 Feb 2024 23:50:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0CF5E12DD8B; Wed, 21 Feb 2024 23:50:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AUy6hCnd" Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 1B9CF12AAE2 for ; Wed, 21 Feb 2024 23:49:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708559400; cv=none; b=ejOcyyq3GnuGxgT/f0smzcZYlvo8qj6AGc1zydpi15em1KaA/oM1Hl8fEvtadXuibRl444VdMEthdQcieeNfDg4q7Njc3uahQ2KMEs3+XfuCXbx8jVDAaZUKm9Fn3lcTgnQtn6feASXlkqE1J0XZjBCXal0WmCKeg6oU3BmLPh4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708559400; c=relaxed/simple; bh=8ssbREubAVv87aYETCRFT0C0nJ2IamnAxKYO3ULa64w=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=u3FAl87gc5Ai2EwD0SXneq49Ea270dX+5Z9lYVHE00mMWtnbrSEsP8lBAq63AuAglQt5da6+j/iE4h1K4uyTl0ucZbhB6dGzcM1hUkqambzxJavHbwLb6c1Df9jf4wuhsfk4Dti0oQSe88XdnbR9NfOUHmehe6azp4bTRejC0TY= 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=AUy6hCnd; arc=none smtp.client-ip=209.85.214.169 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-f169.google.com with SMTP id d9443c01a7336-1d934c8f8f7so68370505ad.2 for ; Wed, 21 Feb 2024 15:49:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708559398; x=1709164198; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JvioobkCVW12CjzalX+EBXJJJID4JZxUgaUQxw/lRTs=; b=AUy6hCndJ7coh3MQzNhOI7QTMSkXh+qJ6rDyYaRU5nwYwu+rw3ga6q2kH+OCSXB1Df +v1xFCfNUN9Lbn+C5u03A3etvPzvlDWYUw/L8lSlDENzQpxky8J/8LJvfss4pCAVztzC 6GFqpfbhPCYIeGvxWiMyI+GVFKi+TRTY95IxRUHKrdeWJSYW9+BiaIVMN1Qx/i1Au9n5 Px0pG6Y93gZo9i+Ign+RtBN6zf0ca/+DylG2NFRlB9jp4b0j3wCr/8VVhlSQ/b2tvN1f yZj0vrwoKnHg3cGF6vYXezgpJrRoknVJCJG4t+dXw8Tlr6LqHBvPEOIBc7Vm22Z09GLb OuYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708559398; x=1709164198; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JvioobkCVW12CjzalX+EBXJJJID4JZxUgaUQxw/lRTs=; b=gKfMClIlC/WHBXI8GyQhsqBO3mIdmcBxbUVy1eGLk12DL73GuALIwSgwEelnugHcu6 K5pxws6J/bFxUvcXevGi8aEYfMCvs8VGJ6SHkNmcudwl0aEfuTss1mQTlj3HmXE6JxFu 4nUOWgX+6hE3IRCOFfF16ROlSJ7yr2zLGA+7hlpcQsW9gJVygA8hYmvYoBBYIrL6EhDQ C9M7U7CRC+a0ptllap6gra1Ml1ApBFr3H/YMeRvT0E2qbkbDbe1/uha6RdPBHM23cl1O K3Tkhe0V4w2gqv9ClCEpFOrKhH3WPpGoR7K9vDEkhnLFiADiQ1V4p6Q2vG5eoI7s0+PU L44Q== X-Gm-Message-State: AOJu0Yyom3gLfwqJqQHvTnMb9ms8kFtq3dbrLmpL3GWLkLVy8cMt16jv mLvG0XfSTCP3gIZceGM0l2pUm1zL1p2Sum0i5eJ7+7IX4acJZU8k X-Received: by 2002:a17:902:ab94:b0:1db:d843:7246 with SMTP id f20-20020a170902ab9400b001dbd8437246mr10129008plr.51.1708559398243; Wed, 21 Feb 2024 15:49:58 -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.49.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 15:49:57 -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 0/5] Handle hugetlb faults under the VMA lock Date: Wed, 21 Feb 2024 15:47:27 -0800 Message-ID: <20240221234732.187629-1-vishal.moola@gmail.com> X-Mailer: git-send-email 2.43.0 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: 1791554407282382633 X-GMAIL-MSGID: 1791554407282382633 It is generally safe to handle hugetlb faults under the VMA lock. The only time this is unsafe is when no anon_vma has been allocated to this vma yet, so we can use vmf_anon_prepare() instead of anon_vma_prepare() to bailout if necessary. This should only happen for the first hugetlb page in the vma. Additionally, this patchset begins to use struct vm_fault within hugetlb_fault(). This works towards cleaning up hugetlb code, and should significantly reduce the number of arguments passed to functions. ----- The last patch in this series may cause ltp hugemmap10 to "fail". This is because vmf_anon_prepare() may bailout with no anon_vma under the VMA lock after allocating a folio for the hugepage. In free_huge_folio(), this folio is completely freed on bailout iff there is a surplus of hugetlb pages. This will remove a folio off the freelist and decrement the number of hugepages while ltp expects these counters to remain unchanged on failure. The rest of the ltp testcases pass. v2: - Removed unnecessary variables and indentations - Declare struct vm_fault in hugetlb_fault and pass it down as an argument instead of defining it in each called function. - Moved vmf_anon_prepare() declaration to mm/internal.h from include/linux/hugetlb.h Vishal Moola (Oracle) (5): mm/memory: Change vmf_anon_prepare() to be non-static hugetlb: Move vm_struct declaration to the top of hugetlb_fault() hugetlb: Pass struct vm_fault through to hugetlb_handle_userfault() hugetlb: Use vmf_anon_prepare() instead of anon_vma_prepare() hugetlb: Allow faults to be handled under the VMA lock mm/hugetlb.c | 88 ++++++++++++++++++++------------------------------- mm/internal.h | 1 + mm/memory.c | 2 +- 3 files changed, 36 insertions(+), 55 deletions(-)