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: 13810180 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EF306CF9C6B for ; Tue, 24 Sep 2024 06:25:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=fwq8DT6JeNdavhckGZI91GgKWXC+kbG6stmMQ1HgBAg=; b=mfgzeaMpfH36a26m2Pai8gfJc3 bJZQT2tTwR+30IyOms6xC9O+3Va9I2nlmDqzJvQtxZAb3m9/2eqWWQLPShIcypr9i9zd/XdRko27S evjDMCh4c01pRgGDTDmZWaI74Y9ZnsSBGWz9rRQMarG95frny9khzZuYqowKs9SwNfh5+6+QDTdeW mJjUd2gMfxb2/oc33ZnqjuYHqQJGYFqjKgbCtMbQ3VyAqQ6FbxJOkP6Qizd96rI1u5DgwhTBpoTxv thScvue4/V9dlT8mCVnw/uJzyHiy0NUHgAk+2KPdRoTekS380wiifGmMVJirJDAH4DaSrKEjs2Vwv 5sq/LpMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1ssyzR-00000001FDq-3Jj5; Tue, 24 Sep 2024 06:25:37 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1ssylz-00000001CEm-1gd6 for linux-arm-kernel@lists.infradead.org; Tue, 24 Sep 2024 06:11:44 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-20551eeba95so44280205ad.2 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=lists.infradead.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=NzdtXg3tm6bkQPoBU6x/QDbp1fRv8xChyo0i5VElmAOU73lnyY/+4nBhzmfzMLzE7G pAN9MpaSVOVKXyrSEEjRNP+XjpNWuILggZjYRdroOhT0BPy6q2v8eZyZaB+EUaLXNMkb h8767MSNVkCDCtkrUBmm2/47tGS0Gr1WPi+QIgIUpnl0mRsu/Qb65GvyNEIO8vlL9FFv eSGodDkFAB8ZYyJhRc2+ZLHos3WiFI+rjcSA7cdLQplTKnZT1vzOCjS0GCLm5PEgn4QV LhGMeTL99ZXfwmQB7E3D20np/4OEApDukPg49i+RqPcdWPhmzXN8lPsA3rAtuwzEbzKA GH3A== 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=eVpPvnbD1FlSbG5C6cD56RbDKaPoiB8pxpm93M9jukS85tIX2vYUB2vHFo2v4QJGZX oiLjn9/3fHoP69xq5oSE0j4FnqOxK6FUIrtn6+tvPcqpiA8smBMmXJ+jW8EJoD0YQ0Ty XuogNq33yN2NmbQC6dK5yEatTh5625ahKjgHqUozsYHkejRGmJ+YvyqDLWAADVW5lrBU /HgayZBVRO7sQulWREzqqaPWlvvy+BErY5D8tFC3c2x/UJu4H5XUnejL7XDHRtlQ/4u9 O0ohMCT0qduH7eOjFIpxeB0VXCtG1VzWWHUKT6BZkloJvCFEAfI9hT8YpHm0HBGGDnvG H4bw== X-Forwarded-Encrypted: i=1; AJvYcCWi33MLd3R2AyMYe/lPgeDfYYyCRtWqWVtBWGmGa6fVK7BUK7qcm1CX9NqHpt494aSheXXLtp4XbTfvdYW8HqYj@lists.infradead.org X-Gm-Message-State: AOJu0YzyMMYwQkKWPEeK5KzTixz2JY4eK3H1lc0MjhSCjPj4Ie/78l/5 l1k4tZa/WNDscdAb9KZ2eN+VBIXdGjB3O6J0nDc81WvPKir1m//qBsirRf5JcAM= 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240923_231143_449850_11B912E3 X-CRM114-Status: GOOD ( 12.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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) {