From patchwork Wed Mar 27 15:23:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13606789 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 00EF7CD1280 for ; Wed, 27 Mar 2024 15:24:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E8B0A6B009F; Wed, 27 Mar 2024 11:23:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E35906B00A0; Wed, 27 Mar 2024 11:23:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C8A276B00A1; Wed, 27 Mar 2024 11:23:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A60D56B009F for ; Wed, 27 Mar 2024 11:23:59 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3B91B1A0DD4 for ; Wed, 27 Mar 2024 15:23:59 +0000 (UTC) X-FDA: 81943189398.24.2EEDA3B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 151A14001A for ; Wed, 27 Mar 2024 15:23:56 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OzgduuCE; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711553037; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iN7hVKxpU9yGNoa0FvV6QQfaV15Sbc5QZKf/pqr08oc=; b=Y81U8eHhLibXGIGvaeFo5LLoANECbqQSQCcu7gIE+XIfb0HiHdj3+WkGyeGis83gW53ymd 31Qea5fHUlN/T6/TGWKCoPr/j1MUNrSTq1lLFDnTno4RNqHpWM1wMK7Ea8q6G8GxJzVGoD YF55JRj5Gxf4dBRU8KAavTnL7SQn3e4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711553037; a=rsa-sha256; cv=none; b=XnXKEMq58uy7DzCUxEnQRtvPz7SvO7n0h7V6peusUmCuakqcx3z66ysT+r9J9Q4IGfrFHg 6wshETEa7R+TTCCVkROKTmdwWS5OA3y1JebnUqg1er0FF9KNvljE6gbqk1ubN+LdysX0Ra D6nTpAzfdAtpwxe6ge83SHdVUjM5l9Y= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OzgduuCE; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711553036; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iN7hVKxpU9yGNoa0FvV6QQfaV15Sbc5QZKf/pqr08oc=; b=OzgduuCE5ijan7+anPU0v3ATulf3xn3Bk7Gk3JYuhoBm3ZS1gIcqJVt2pAesMXzNJJDgWE rEKjZuM7hbLQjp1Z2MVlmx/cUWy3UY90lsp+S+50j6tqO3UmvYbfEs2+2Fphs2IepJQLmq tRbBPSVjZ4Xb1ZzQo+sSp3dXf0khzr0= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-611-lvZlrj4dMEenZ5lBG6ACHQ-1; Wed, 27 Mar 2024 11:23:45 -0400 X-MC-Unique: lvZlrj4dMEenZ5lBG6ACHQ-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-696a9c482a4so3595976d6.0 for ; Wed, 27 Mar 2024 08:23:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711553025; x=1712157825; 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=iN7hVKxpU9yGNoa0FvV6QQfaV15Sbc5QZKf/pqr08oc=; b=e1DTHvUMVEXj6wDelgDY9znswepFH/tZWBK6FG8bn8SiLBlN2XGTdBWcYk1+OnmLZq 4hSoxm2lLpX/J7eyOrAgFda5hPGur9PXHu9Xh8Jx7FRPEzNlf6VW06cLc5ww5+oujSeB LBgBdhMjiYWZ/nzjKrpHvqthuqyVfmbV4EpslSDPu5I7if5Vji+hlK1Jd5YZLjNoK3F0 OhQRZpr5/+oT7oD4h8++yi82mNIiZLWWAMFgNK08KOkdSJQlHk0oqZb8dunF1KlA8md8 U3oCBELKlPKYlEG8rMUIUovneLklXzKDX3maOnKd5RRJ61qTvaobC0E/OrELYH3uSd1b yLUA== X-Gm-Message-State: AOJu0YxEcoYoDxwyXrrJNKfIwWFtOUEzZlLIxXeNZiTSb8GfHNCfUsVV vvCEiF/9a8VMGjW+1jKrKgCduY1/gZOGDRUk+XK3u+7zM9wb4XBid7qB/ia7W1qWVPbQpPLdKnN +I0w+QlJbVCC+HUvHZuP3vfu37BPiqIlb6ITbxrI6IPdqCb01lHAv4ep1+I/cSx8YI2mCB85ESL ClkFHYAb2qYSUTaOXPqeCPmAdxggiYbw== X-Received: by 2002:a05:6214:4598:b0:696:7b32:cceb with SMTP id op24-20020a056214459800b006967b32ccebmr13869575qvb.6.1711553024769; Wed, 27 Mar 2024 08:23:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFS0Dr3UNRPnI4el/D5x8gcrtCXLMsQwIvd4dOzHJoXuoNg03xhCSCfsu9VpmJMAiYn3G+95A== X-Received: by 2002:a05:6214:4598:b0:696:7b32:cceb with SMTP id op24-20020a056214459800b006967b32ccebmr13869513qvb.6.1711553024070; Wed, 27 Mar 2024 08:23:44 -0700 (PDT) Received: from x1n.redhat.com ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id hu4-20020a056214234400b00690dd47a41csm6412639qvb.86.2024.03.27.08.23.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 08:23:43 -0700 (PDT) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Yang Shi , "Kirill A . Shutemov" , Mike Kravetz , John Hubbard , Michael Ellerman , peterx@redhat.com, Andrew Jones , Muchun Song , linux-riscv@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Christophe Leroy , Andrew Morton , Christoph Hellwig , Lorenzo Stoakes , Matthew Wilcox , Rik van Riel , linux-arm-kernel@lists.infradead.org, Andrea Arcangeli , David Hildenbrand , "Aneesh Kumar K . V" , Vlastimil Babka , James Houghton , Jason Gunthorpe , Mike Rapoport , Axel Rasmussen Subject: [PATCH v4 04/13] mm: Introduce vma_pgtable_walk_{begin|end}() Date: Wed, 27 Mar 2024 11:23:23 -0400 Message-ID: <20240327152332.950956-5-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240327152332.950956-1-peterx@redhat.com> References: <20240327152332.950956-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 151A14001A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: yfnhrdisatua895kc7mdkupt8tygzm4d X-HE-Tag: 1711553036-710980 X-HE-Meta: U2FsdGVkX1/ZVUkhOEulavnL4HKywEjbDgKrGtWpXp2LF9FHDqaIzflLM7TAbunDE6nnEUu2gBK3s7pVigHkQhebacAJIPougLLxZeBHWekrfJ0qsUZahf0x4Lt2PWADos9W+Uoxb/DBEeSnA93rAI2nhDN6c1CJ/KwIgGIMvSDLVJIWgXQC/9342YbNOou9kTIBp01FivjlFLSPvEJt6De7fefvwLAnAjqSSmBRres3TdbmL0HtLTKNU13xVPj6/9ai7eorS1rteBBHue5jnyfDhDddDVFYAd5tfoVTxPdxMve8CZQOs9nSOScspZfb+VNTOBi4Ra/HOT+QcYqZfBHiWboIOTmBxuuBYxpdENGPNRTK/WuH1tR3uRmXGqYHp/yLhuW8MVs7kvgwKLqRB2T2APx0aBAoHhfYC5khR7YBuACtOTmocW+jIriLzg1u4sxW0qtQZrbIE3gYdTPK28j7CO8d+ZYcueF6YYb0PzWEsTJWVctbYG15nDtIySeg6SRFhss1K3hlyV027BgIveZIqcs/mN6sM+vIIvtG+UuV5ejSurKY02L3NyvfkugILht9taII2/B22zNLlRCWvmp8dVBPBU1VTQc0HRtgMu5kXzgJhB3GsQB73plF5c9gLBJEKtrnOLDqOOC2cF7rlvJW8XtRby5KvoaLcHeuXKqBrmX4O8W3BKvIGngepkSug4fps6RVzCLC1MR7Ej5EDA0h4pcqXYX2C+ZF8n9uGpWqP/DtX8lYsUwBSfKhuZm4760oLclSmIG0y1kx3TdyiTOjOKObJ1m7dZwG6/U01rGmQk98JuZ456qo61D3rRHwom4IqU0yxB/q8E8Ygq5q9eKuJ23X39coepYRACbhMlDErSiRwRwzUIeRU9TSxKzFuRNzmjKc+MqJZT1icbTP3bZluPHlf8ZmKTc0voWbG7jEr/Rg9tcL1dK+1gnfgG/KE0cxYth4mITL6ZTHlft 8t817T/T 7MJ9MYuOLT6BGW/Athqe6OehcnhxQMgpmbv1VrzVkNRXpyxUhx/NY6osgNzjja90s76tiju0yekPLTXdogfDsocWnxzfBMF2fm4R/Xf6d7v5eCVbjWXKLZFHBoHukMtzu7a2VxWezUhQF4nFMQkF4z7MfrxGCYIQrfsAvffpCGr+oNXBLv+FLNJu1Z2dibn0BLh8QluM4Ojy6yc2wiD7TboVJkiEi6+orM/e11w/fzecr5Bu9DfixE71A150JreZmISzXtYQ0fkv0DRVciQt+3Cmb2pYklrxlxWsRgqNrrK/3A+pc4sG3pnGbslO7wNPQpGds9tZ3+30N9qCeXYm3MTcO3dPwhAx7IHmWNdUWxjBmBop7Rk89uRgT5z9ETgP/pLtP0Sfb01+qP1t7H2VxoKezwO3mKJfib+bAFu5nT3vfqz5ec6vwgK6qFvUEAv1U+NGHaG74AtCZQPBGvhwaOp33rPb+i1I6YV8JRjLvidahbds= 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: From: Peter Xu Introduce per-vma begin()/end() helpers for pgtable walks. This is a preparation work to merge hugetlb pgtable walkers with generic mm. The helpers need to be called before and after a pgtable walk, will start to be needed if the pgtable walker code supports hugetlb pages. It's a hook point for any type of VMA, but for now only hugetlb uses it to stablize the pgtable pages from getting away (due to possible pmd unsharing). Reviewed-by: Christoph Hellwig Reviewed-by: Muchun Song Signed-off-by: Peter Xu --- include/linux/mm.h | 3 +++ mm/memory.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index afe27ff3fa94..d8f78017d271 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -4233,4 +4233,7 @@ static inline bool pfn_is_unaccepted_memory(unsigned long pfn) return range_contains_unaccepted_memory(paddr, paddr + PAGE_SIZE); } +void vma_pgtable_walk_begin(struct vm_area_struct *vma); +void vma_pgtable_walk_end(struct vm_area_struct *vma); + #endif /* _LINUX_MM_H */ diff --git a/mm/memory.c b/mm/memory.c index 3d0c0cc33c57..27d173f9a521 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6438,3 +6438,15 @@ void ptlock_free(struct ptdesc *ptdesc) kmem_cache_free(page_ptl_cachep, ptdesc->ptl); } #endif + +void vma_pgtable_walk_begin(struct vm_area_struct *vma) +{ + if (is_vm_hugetlb_page(vma)) + hugetlb_vma_lock_read(vma); +} + +void vma_pgtable_walk_end(struct vm_area_struct *vma) +{ + if (is_vm_hugetlb_page(vma)) + hugetlb_vma_unlock_read(vma); +}