From patchwork Tue Sep 24 06:10:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13810134 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 C2B0ECF9C6B for ; Tue, 24 Sep 2024 06:11:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 505A26B00A3; Tue, 24 Sep 2024 02:11:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B4E26B00A4; Tue, 24 Sep 2024 02:11:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 32F296B00A5; Tue, 24 Sep 2024 02:11:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0FD956B00A3 for ; Tue, 24 Sep 2024 02:11:46 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BCD2D1617F5 for ; Tue, 24 Sep 2024 06:11:45 +0000 (UTC) X-FDA: 82598610570.07.E2AF191 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf15.hostedemail.com (Postfix) with ESMTP id E56A9A0002 for ; Tue, 24 Sep 2024 06:11:43 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=PwciraW2; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727158186; 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=fwq8DT6JeNdavhckGZI91GgKWXC+kbG6stmMQ1HgBAg=; b=ATnLsG4UduX28K4IIwjonWiuMauK1tdOwiSxyVUydpP0FLvmhwh70FpStg+FakwPGdPhst 91d4EY6IbFpa+5JH7MkQlXCyaTBbUUFB6nTWOF7UAxAzGBUk6qM3WqY615YeMUFxjbX+Zy XQi7k34Jrynflt2+B2agt2j42YhJngU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727158186; a=rsa-sha256; cv=none; b=5qOVqhAHGgf8Q5q1diHqfOWKbX9cnf6huIjz+Zqs/iSPx4HDgDe/Ok94v9h60tbuD0Cnq/ ecqUHhREk0XYhIYp1XSswEIKma1IivfyOIPusEE2CMDaJXA5WTQr0eYKQjPjrYVZ8X+ac7 ehNKl9TPbmq8w3BoLLOwC/1SE4+aRJ0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=PwciraW2; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2053525bd90so47137615ad.0 for ; Mon, 23 Sep 2024 23:11:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727158303; x=1727763103; 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=fwq8DT6JeNdavhckGZI91GgKWXC+kbG6stmMQ1HgBAg=; b=PwciraW2+m9PlVgbSMMkGVMZ2whfQGtHFlIp4YYqb8MUc0fDG+n7OEhDnGCYV5k/Bn jNP66u+tcn8lNmMWIv6MdEnywcCAi7gYSsNXDRfGrCc8CfCrDyoQy42xbVQrk8EIv7aP gDojxZ4qdm5NYjgF5STgSRdGqW8uK3gFTgnVbvW2bSsne9RM8mwxQBZCJ0eProfMxvkF DxLkbaUMkJJ0ry23bVHQIJddE3yiyJPf50k92YsTqP4orMMnzE19vxxa7VUzMMd/Qrwm xHIIlaHY8k8WKs59mnQV1dmCQ9hwKSaonKUb0RBe/5agMSjuOptQ6mnDbbrASEz8gegn tTHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727158303; x=1727763103; 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=fwq8DT6JeNdavhckGZI91GgKWXC+kbG6stmMQ1HgBAg=; b=q6mzgPVxKyxOQKjMAWokVJ48+nLqbxfwL1yNE9QJat66cMZVFoOeBIW6MoU5F0uOX8 01YmqKqq68e7ZNaF5NMa89kniqCtDqJYIAd1yOn71WQKwNGxwUjNz6BHx4yTBXrHhe+Q CNTgAxm4WGk1Q3X5SmeDvqQIHEgpqK5zyHdVmFiNTTQOn3EXtp7ykYQ3fsRXYoFWsldj lQLTWjenI62pgo2rSt+IZuedfvKInZVUPpVNL8qDPgPdbgqJQzvATgfgyLLaV2HIuc1Q nSMDwiBrq0VOktJwQXjBwAW+YUU3BKN3oyP1VEs+wrA/X0MqctG/hlUsM/W6Zf5l+nBu xqlA== X-Forwarded-Encrypted: i=1; AJvYcCU2AVkruaTITXAL6iGgcrwDJ1JdDy5nJFCHkx/C84Gh8xbTAinQfTn3nIa6K9ZpqEVxY0xiLLbHtg==@kvack.org X-Gm-Message-State: AOJu0YzLDsyTX2MGDLjkxYb6mHM/0ivlgsbhyoiE9eqPYJAAdzEkJ2YS ip/G2ro5w3IFD2Bp/fQ9/cMjdvDwtvpEhCEnSjS957zEhVbc7AC27txdRjMvo7g= X-Google-Smtp-Source: AGHT+IFl5AsK8a8BNnydzmhf2ct6wAj0Fi3O6gM7MY+2JS5/M4Off4jZQYnq6Yk2iDK5ETk+W1TbBw== X-Received: by 2002:a17:902:ec87:b0:206:b915:58e with SMTP id d9443c01a7336-208d83af7b0mr191498925ad.22.1727158302727; Mon, 23 Sep 2024 23:11:42 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([63.216.146.178]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20af17229c9sm4344885ad.85.2024.09.23.23.11.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2024 23:11:42 -0700 (PDT) From: Qi Zheng To: david@redhat.com, hughd@google.com, willy@infradead.org, muchun.song@linux.dev, vbabka@kernel.org, akpm@linux-foundation.org, rppt@kernel.org, vishal.moola@gmail.com, peterx@redhat.com, ryan.roberts@arm.com, christophe.leroy2@cs-soprasteria.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Qi Zheng Subject: [PATCH v4 12/13] mm: multi-gen LRU: walk_pte_range() use pte_offset_map_rw_nolock() Date: Tue, 24 Sep 2024 14:10:04 +0800 Message-Id: <6efef5316d7468d13ed5f344452a0b872481972b.1727148662.git.zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: E56A9A0002 X-Stat-Signature: tzs55r6msusbwhjw83d4wqthhgh3mz1r X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1727158303-67412 X-HE-Meta: U2FsdGVkX18LZ22qLLBUyt2u+Y75oSfdgGU1Oe/DYHC+8Zl9c1pGT0UrpjxvwICY6S4iX9MB1uOAH3c058nSZi8MHY+FXYpHpExgpl1OctOnv6lcdwoeOIJSbjy866uN+i9s3zF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ytFz1yHRsq3l8v9dmB1SW2/GQs6N8ndxZuVMOFESnI37d9sd4IW/8LAHojj/mSmmjabnuPzYAlfCl0Dc94+tRsQkH8SApOwR/2wSV+qmVrKR5JUZzCk0wVZ9r8rMn56uhEQd992wuOQPr8utp7noCUYP0ST7YEKLVeo9SsT/fFq/4VtSYxqCpoXeU3urWVuIzWJmCnAyisLV6QjVZCkAYQ== 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: In walk_pte_range(), we may modify the pte entry after holding the ptl, so convert it to using pte_offset_map_rw_nolock(). At this time, the pte_same() check is not performed after the ptl held, so we should get pmdval and do pmd_same() check to ensure the stability of pmd entry. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Acked-by: David Hildenbrand --- mm/vmscan.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 749cdc110c745..bdca94e663bc5 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3375,8 +3375,10 @@ static bool walk_pte_range(pmd_t *pmd, unsigned long start, unsigned long end, struct pglist_data *pgdat = lruvec_pgdat(walk->lruvec); DEFINE_MAX_SEQ(walk->lruvec); int old_gen, new_gen = lru_gen_from_seq(max_seq); + pmd_t pmdval; - pte = pte_offset_map_nolock(args->mm, pmd, start & PMD_MASK, &ptl); + pte = pte_offset_map_rw_nolock(args->mm, pmd, start & PMD_MASK, &pmdval, + &ptl); if (!pte) return false; if (!spin_trylock(ptl)) { @@ -3384,6 +3386,11 @@ static bool walk_pte_range(pmd_t *pmd, unsigned long start, unsigned long end, return false; } + if (unlikely(!pmd_same(pmdval, pmdp_get_lockless(pmd)))) { + pte_unmap_unlock(pte, ptl); + return false; + } + arch_enter_lazy_mmu_mode(); restart: for (i = pte_index(start), addr = start; addr != end; i++, addr += PAGE_SIZE) {