From patchwork Mon Jun 10 12:02:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Yang X-Patchwork-Id: 13691945 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 614DCC27C5E for ; Mon, 10 Jun 2024 12:02:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C3E3D6B0095; Mon, 10 Jun 2024 08:02:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B768E6B0096; Mon, 10 Jun 2024 08:02:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A3CD6B0098; Mon, 10 Jun 2024 08:02:37 -0400 (EDT) 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 77CB36B0095 for ; Mon, 10 Jun 2024 08:02:37 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 38726C0FA3 for ; Mon, 10 Jun 2024 12:02:37 +0000 (UTC) X-FDA: 82214841954.06.66F43EB Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf05.hostedemail.com (Postfix) with ESMTP id 3E27C10000B for ; Mon, 10 Jun 2024 12:02:35 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SjQJNOzE; spf=pass (imf05.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=ioworker0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718020955; a=rsa-sha256; cv=none; b=Y6mxNowqnHBlHQ0kQPS+wP7j6khuWmOFf9pRxV3iBQ+wB0yALBIP5+ngQ+1zXafx8qvcZ1 6/9oAmib4mpBGYt7nmLdD0Uh1o9mx82wp42vVzws7vzwiJELbhy9M20ggeJZOoJJVdYQ3d 2tKcoGmo6vepRVW1MvCKqFv9n/3Vp9w= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SjQJNOzE; spf=pass (imf05.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=ioworker0@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=1718020955; 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=1Jta2NpH0Yo3jq0n3rdl7lcfRrUI+PWrFp0wIskmVQ4=; b=ZL/NI2IRUGBMw8cPZ0M7O+x3F5M2ojKuAx8HrJJPxIF4Ni7MpSsaFEhGMhD+n/UT6hGY2A Qzrko3IXwNM4cOjsrcen2h7B5HzJ0ZA+s1I2XjIVN5002gm3nvHdO4v0SE7+5uOY+4XNBA rreNlAp4rJjj0NVNqsZBWvKtylIs6R0= Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2c1def9b4b3so3376606a91.0 for ; Mon, 10 Jun 2024 05:02:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718020954; x=1718625754; 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=1Jta2NpH0Yo3jq0n3rdl7lcfRrUI+PWrFp0wIskmVQ4=; b=SjQJNOzEgi1LZKV5AA/ksvWVHDHmuDPa8uZQWVGAlbz03CRhmKg77MLTWkezXaFsTs cpts8lyDCWz6sb208TKB+/YqmgvgoCyXl7rvLF6rDfFSjNBiqvx87HyRnm5xB9Q17qB0 Y/iH54bXr0Kxf+gnnE1om16O9Y5XBT81MigyLJ3p0C6wGgqmE+y1sa76s6z+RtDNAOJu xrBlC4Es8RxOyiUuqZOKlW0A2ZVee/i1zLIP/ehEdUnE1XamT2pwnvrFI4cw73uEIo6u m0RWu0y65bLUxAqOoH7ePuwV5Ey5QgRYxRBZPFfHkZXrGg5WnA6T9ZEjmPOa3jQ2Z2FM 3Q4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718020954; x=1718625754; 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=1Jta2NpH0Yo3jq0n3rdl7lcfRrUI+PWrFp0wIskmVQ4=; b=RMgE9J6Zu/K7uxRxNmW0ERuUebY+wH5yVMQnPfC0I3M4HE9oQCnQx5iYXBDW3lAR2+ Ln51sb1ped9Hr4tBpRHhtUEGg/XGcmtb8Zxy89x+niztx88pFltGXDbcWSnytJFOIIcd jEUSmz+/NdtM1WkG5aYmuTJW2Oj9P22ATv32Lv6bME17ImvJt+fHL0H29Ly2x+doJPd+ c9N2w6SVtYHCUrNHQuq0FQntrd+Rfqmwhn33nkOpqo98tR+qh1ubV0bEurQ++rLES2Lj IGaSTPxd9mUkyBgEYbmdWSKGORyv4wYs5eVxIW6WcVsxtKBTUSgFQ1pssiFGNMK25dlC cZog== X-Forwarded-Encrypted: i=1; AJvYcCVpZnqtndnjeCccHIMrb/gnKiQwQAiMgIm7XzbXiSPjOt01pd6b9aUfyX/LkDOW/KmD67BCwoECIUkt/PSyd43hFeI= X-Gm-Message-State: AOJu0Yx2DTZ8pVw7jQqfXYCRGZ2k9lebBWotUzb6EA+7xqkMe3pZQpmZ Ux8sxERvpvZh4H7ZZ7ZQawP574lxtmm/SnYYGySupK8NMce1wEYR X-Google-Smtp-Source: AGHT+IHRNhyGYjU+bbHW3Rl/BwTn9HYeOw84bchXR2tVdnHVYoifBRotkcCaIuC++at7Grjg8V1JGQ== X-Received: by 2002:a17:90a:d581:b0:2c0:238c:4ee6 with SMTP id 98e67ed59e1d1-2c2bc9ba465mr8733353a91.2.1718020954042; Mon, 10 Jun 2024 05:02:34 -0700 (PDT) Received: from LancedeMBP.lan.lan ([2403:2c80:6::304c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c302f0ebdcsm2478478a91.23.2024.06.10.05.02.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 05:02:33 -0700 (PDT) From: Lance Yang To: akpm@linux-foundation.org Cc: willy@infradead.org, sj@kernel.org, baolin.wang@linux.alibaba.com, maskray@google.com, ziy@nvidia.com, ryan.roberts@arm.com, david@redhat.com, 21cnbao@gmail.com, mhocko@suse.com, fengwei.yin@intel.com, zokeefe@google.com, shy828301@gmail.com, xiehuan09@gmail.com, libang.li@antgroup.com, wangkefeng.wang@huawei.com, songmuchun@bytedance.com, peterx@redhat.com, minchan@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Lance Yang Subject: [PATCH v7 2/4] mm/rmap: add helper to restart pgtable walk on changes Date: Mon, 10 Jun 2024 20:02:07 +0800 Message-Id: <20240610120209.66311-3-ioworker0@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20240610120209.66311-1-ioworker0@gmail.com> References: <20240610120209.66311-1-ioworker0@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 3E27C10000B X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: 1seb5j9pokc4jnw9mpjjxzrdsa6z6c4i X-HE-Tag: 1718020955-650133 X-HE-Meta: U2FsdGVkX19Ur4NQ62y0wJmwuWXzkSxKOzjIurvLsdv/QYv3RFgOG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Nsupf9IgpJoh3YMK2MA51UiTpfI66oRi+Fxf0qiUQQLPs9x5frLqvAMG3pnvXqzW4VcpvvVF6Olg17CbKjXJG/VvwE8thLZq7h9hd1DUhpA7Nod36Kj88sx3PvuuEIoEBHHyc2QuxSmYeXTiRztNVN+aQorgLaiewT9f6hWLADaem9aTbd+nosUPHsLrdsQV6F9FSaF9gNY3tqm2ybGG4t/K4aTfAJqX2LuO4nD54SNn4lR2MwywDudr7lNG15zECF9e89f3Qk3fWSSuwc5OQUqf+kJgAnUeO1wacvXIt7+Ebfl6xALprJmfms4PWtFNLb8U 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: Introduce the page_vma_mapped_walk_restart() helper to handle scenarios where the page table walk needs to be restarted due to changes in the page table, such as when a PMD is split. It releases the PTL held during the previous walk and resets the state, allowing a new walk to start at the current address stored in pvmw->address. Suggested-by: David Hildenbrand Signed-off-by: Lance Yang --- include/linux/rmap.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 7229b9baf20d..5f18509610cc 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -710,6 +710,28 @@ static inline void page_vma_mapped_walk_done(struct page_vma_mapped_walk *pvmw) spin_unlock(pvmw->ptl); } +/** + * page_vma_mapped_walk_restart - Restart the page table walk. + * @pvmw: Pointer to struct page_vma_mapped_walk. + * + * It restarts the page table walk when changes occur in the page + * table, such as splitting a PMD. Ensures that the PTL held during + * the previous walk is released and resets the state to allow for + * a new walk starting at the current address stored in pvmw->address. + */ +static inline void +page_vma_mapped_walk_restart(struct page_vma_mapped_walk *pvmw) +{ + WARN_ON_ONCE(!pvmw->pmd); + WARN_ON_ONCE(!pvmw->ptl); + + if (pvmw->ptl) + spin_unlock(pvmw->ptl); + + pvmw->ptl = NULL; + pvmw->pmd = NULL; +} + bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw); /*