From patchwork Wed Feb 21 23:47:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13566619 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 3C41FC48BF6 for ; Wed, 21 Feb 2024 23:50:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 77E046B0078; Wed, 21 Feb 2024 18:50:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 705B46B007B; Wed, 21 Feb 2024 18:50:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 531F26B007E; Wed, 21 Feb 2024 18:50:04 -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 353F16B007B for ; Wed, 21 Feb 2024 18:50:04 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 074E7120C3E for ; Wed, 21 Feb 2024 23:50:03 +0000 (UTC) X-FDA: 81817456728.20.39D4D51 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf01.hostedemail.com (Postfix) with ESMTP id 051FF40011 for ; Wed, 21 Feb 2024 23:50:01 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Thma0WNF; spf=pass (imf01.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=1708559402; 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=+yscKp0AJANlReZg8MRza2RJbrRIz7yBwKbuUCOLUH8=; b=N8s0cVh4DiSm8NJ4UJFj8RWFjyOPqKhjyw2ESjY6gomn4XcU9bCmc+By1em32EYRwKYMrm 7Fef8xj7P8c9Tq5cgY6TYRP79ezz6XQLDoPga+bdBSyjVmKluPXcD0UcQWjRm0tZ0YQHdz EKmn+JNNqFT7cZz2fO64QQIze+vLE+k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708559402; a=rsa-sha256; cv=none; b=qLLIqnNY8d/dH2Y4ATYgYwV2L6AMRsTOPIZNb5XgXycVR0eu8S1OMu4ByPP8ICWvM/N+md iLERe4s/ZgxYg4oRr378IFfjSE6BrYA2NSvhnRA0bv9ohEDblQzc/86rls/W49HdzYxhcz Hz0j9z8a2P+LOwE+MThXYjR93JYdKPk= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Thma0WNF; spf=pass (imf01.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-1dc29f1956cso9383825ad.0 for ; Wed, 21 Feb 2024 15:50:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708559400; x=1709164200; 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=+yscKp0AJANlReZg8MRza2RJbrRIz7yBwKbuUCOLUH8=; b=Thma0WNFfmPKu1KXa3AWBQdQ6nhfd3AoqnDA1oH8fWhaz80VVj/jGw+igollwHOyzW PRpcPaVbtwqzJgZSRW3Jx9EMOzLXwMW61Zl3A80ug0BlPqNVM6huWRbZmc5jQ6wrPgOL oqoXz+Fsh2ilNxcm+DzRPgs/fQULJHSOS8lQfb1U8Q2Ub3dk+gYTYJ+vqWJWK1aQSL+o rVMGFwEDyYPgXKGE7SI1mCGwjW79SFAPjLW8pHj36zXa5Y8iFbF4ovTJ/gba6Q55uM33 DCdAqeaIquMGtciJrBos9jX4n+nqB5exheYF32OvwSpWTurAOaOPhkAtSvwlx56DK7IW uYJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708559400; x=1709164200; 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=+yscKp0AJANlReZg8MRza2RJbrRIz7yBwKbuUCOLUH8=; b=NKFf2RI7tGQTLKP0oJ9GeKrlRmZVE7SvNOMVxwhrk9DsS3wRIaJFtxcgs6s0X3Elvz VzXv2+WKb8gLE8fOVOlFXcX8BY+LLTqhMUb4//KtsN5CdniazfSNnTjzO4jpw9Md7X0X fEFOBmE5mq4uZ+5yczBFgy5pQSpLLaLnU+nFk0g5AfzE3oTYOBPI08pon1Lk/LaRnICM Uf7HT+jJYZp0vLvFcE9N+o6PUTyka8oAJvQPx/HrQycAFXWUIbpYR5ifvZUgZTXZyG79 7rt2msEPNWhNP3nRU0ujQESz376/re1nYKPY/qftLv0NO3Lpc8wjGyStTGVJMRx630Rg 0Tjg== X-Gm-Message-State: AOJu0Yx9g2e91ruXJiwVdmq3JHj+h9bXqnRc4zioTU/eVhfcEVnKA5HB 5G3YDxgTLsUxWzK70XVePOrklB0ldw4kbrfQ9iXHB/IsnuwlbiQ2diCc5SLL X-Google-Smtp-Source: AGHT+IFZIf1O6PqXeRikv0kae6U3RFR5jVDKRbX/kRqX+aBw6Rf505v5O+I9/n7itMhFi0AnJq7rXQ== X-Received: by 2002:a17:902:db09:b0:1dc:139:8488 with SMTP id m9-20020a170902db0900b001dc01398488mr10763038plx.5.1708559400552; Wed, 21 Feb 2024 15:50:00 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 15:49:59 -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 2/5] hugetlb: Move vm_struct declaration to the top of hugetlb_fault() Date: Wed, 21 Feb 2024 15:47:29 -0800 Message-ID: <20240221234732.187629-3-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: 051FF40011 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: unpcztowoi4ci9oh1xo3j9si9psym7ps X-HE-Tag: 1708559401-996607 X-HE-Meta: U2FsdGVkX1+iQRPxoBGy0Nd8z26oSmVuox15QmByLJBDvTdYPo58rykR0o9R4ZNPDUBCEVM1LyQqHQ/0Sxmt29mQeVEQ7Ee5Z9HevQm1syPwy06+zFIBaUaWAOvJ2F0VxPgvtR2CnmDNaDBa3dA8bNw1xkQTnPRu6GfEEDHpZfSgKn2h1ZsvYLa//Ao5JGhKJH11LWWacuOIRq4Dbj9TzguDU8gvJUHs+XKPWUY/M2iqBVN0gkRmDP3QrJx0PlTFe/HJjZz8sSGnLM0DpvLwdqTElzhIS0/4H7++1eJYd4PwC8HV4nq5Km3/74UWYOfnjycXr0Ke2uR2bLyK4KV7vC22IVSEr5AoeBsuPyOfj4W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z56zao0ckH4961cci0RwYDlKBVSQOCx43qocwn54iskwyLxUqVuHMmyLgHrM2AXKFgui1qCYStylCkWe1GFSkRjE8HIHxl9eM4c67ynCiVlRDYcpzEcQZxVAbi7/Wo484J6zgyG88dyM440pVd+XcA== 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_fault() currently defines a vm_struct to pass to the generic handle_userfault() function. We can move this definition to the top of hugetlb_fault() so that it can be used throughout the rest of the hugetlb fault path. This will help cleanup a number of excess variables and function arguments throughout the stack. Also, since vm_fault already has space to store the page offset, use that instead and get rid of idx. Signed-off-by: Vishal Moola (Oracle) Reviewed-by: Matthew Wilcox (Oracle) --- mm/hugetlb.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ed1581b670d4..d792d60ea16c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6353,13 +6353,25 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, spinlock_t *ptl; vm_fault_t ret; u32 hash; - pgoff_t idx; struct folio *folio = NULL; struct folio *pagecache_folio = NULL; struct hstate *h = hstate_vma(vma); struct address_space *mapping; int need_wait_lock = 0; unsigned long haddr = address & huge_page_mask(h); + struct vm_fault vmf = { + .vma = vma, + .address = haddr, + .real_address = address, + .flags = flags, + .pgoff = vma_hugecache_offset(h, vma, haddr), + /* TODO: Track hugetlb faults using vm_fault */ + + /* + * Some fields may not be initialized, be careful as it may + * be hard to debug if called functions make assumptions + */ + }; /* TODO: Handle faults under the VMA lock */ if (flags & FAULT_FLAG_VMA_LOCK) { @@ -6373,8 +6385,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, * the same page in the page cache. */ mapping = vma->vm_file->f_mapping; - idx = vma_hugecache_offset(h, vma, haddr); - hash = hugetlb_fault_mutex_hash(mapping, idx); + hash = hugetlb_fault_mutex_hash(mapping, vmf.pgoff); mutex_lock(&hugetlb_fault_mutex_table[hash]); /* @@ -6408,8 +6419,9 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, * hugetlb_no_page will drop vma lock and hugetlb fault * mutex internally, which make us return immediately. */ - return hugetlb_no_page(mm, vma, mapping, idx, address, ptep, - entry, flags); + + return hugetlb_no_page(mm, vma, mapping, vmf.pgoff, address, + ptep, entry, flags); } ret = 0; @@ -6455,7 +6467,8 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, /* Just decrements count, does not deallocate */ vma_end_reservation(h, vma, haddr); - pagecache_folio = filemap_lock_hugetlb_folio(h, mapping, idx); + pagecache_folio = filemap_lock_hugetlb_folio(h, mapping, + vmf.pgoff); if (IS_ERR(pagecache_folio)) pagecache_folio = NULL; } @@ -6470,13 +6483,6 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, if (userfaultfd_wp(vma) && huge_pte_uffd_wp(huge_ptep_get(ptep)) && (flags & FAULT_FLAG_WRITE) && !huge_pte_write(entry)) { if (!userfaultfd_wp_async(vma)) { - struct vm_fault vmf = { - .vma = vma, - .address = haddr, - .real_address = address, - .flags = flags, - }; - spin_unlock(ptl); if (pagecache_folio) { folio_unlock(pagecache_folio);