From patchwork Thu Sep 26 06:46:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13812898 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 2B4B6CCF9E9 for ; Thu, 26 Sep 2024 07:03:50 +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=wKWf8ZYo9tlbP3964sEqp7HhdDy32FNbDdGL8iSt+Ok=; b=zc0Lcu90PxMsGh+69POAZg+Yzv DADMmNHMGLteqGfD/v63ny34CJGxBF1eR0XU7lOISYVVekh0alpb/1TP556W/wNwVsRJ5z0QCcXfy F/VLPHvGU+thl8rmDpawXYDbQrlJ+UFwFMPxu61Qzwc49F7bKcxuoNTjI/NzHnvmc12HtiNeleQVo nr0q/L4zk3ODycRnFRb1TJjRx8HwXB6Wf1i0p409XKqPVsAK1ofZ4YcspWryt8BKQqSqam1KXxMeG 87IzHimXPVZAiId0XhC9ux5IXQV282hN1n7vkxkFh+ous9ZJ7I9LIXVYLcUPak1w0sDcxw6IxJW5t nomq3pkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stiXI-00000007R1A-2xsK; Thu, 26 Sep 2024 07:03:36 +0000 Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stiIX-00000007NpG-0CQ7 for linux-arm-kernel@lists.infradead.org; Thu, 26 Sep 2024 06:48:22 +0000 Received: by mail-qt1-x831.google.com with SMTP id d75a77b69052e-458362e898aso4398991cf.0 for ; Wed, 25 Sep 2024 23:48:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727333300; x=1727938100; 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=wKWf8ZYo9tlbP3964sEqp7HhdDy32FNbDdGL8iSt+Ok=; b=jMGDMYS/1X8lIOjF1pjE41c5QO8x0m1YVGgoKq3lEE+zGi9ulQoaC0MlEOHSKmTfBW SB5IAlSYJLwBAmD/2D1vfep0HkhbpIl7j5BPXa5oRDBPU0mp0TQslA0sNlbcxDazHdTY ot9hAzZqngdVboh41EgMDgvmHeia8zL8lQlsMfkvXTJVz+JrqzBwwsphEy8Q0avVjqpp QN5JAUXs78hXkuwLKQNtOXtD0tVdR1PDkFApxXoHLuJTfj20o1PRp4MHv84+p14MsceE htMsp+LbQ5mgerLospNUFgsbAoYK69r4luln5GeU135gerCofNTIXLr7RA6K9TS6W8pG wMpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727333300; x=1727938100; 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=wKWf8ZYo9tlbP3964sEqp7HhdDy32FNbDdGL8iSt+Ok=; b=GNcdl1Zf3J3ZQIxeG4WSz+Cg1bkSsvPmfQh/i1ltwr+56vAAVupox6NoszaSKlBuB9 xUNYpr/LxkdEYhURPsywbwuLROyOeabP5bmbFox+/bMx7KdLcZ2+Wmdw194zn3+RXTR1 0D8JbY+O+yJtrumVBJz0DELRKL/xqtOcqlLXMp6yi37Ew8jyc6av6JKIhcfgAmy2d8Vz RRkhObjepSV5g4uioUkMzPqKme0ejjreh2RrLeeGyI34LxflzS/dhC875DbYixcvJAq/ bf6aNRoao+fFM8OY4pbSDHHnjB81J0rHBKwHt5e1hexLEvZmIHcha6xGGn/XUWiVDXSZ oriA== X-Forwarded-Encrypted: i=1; AJvYcCX0oVTZaScGLHD1wGBnf0w5QQV+q17Mz3aoFAv+96SXSGMuWZ5heSkDLk+jEnCcHgoQ1Ik9umxh/8aGxKAu8htE@lists.infradead.org X-Gm-Message-State: AOJu0YyKa4xfrQFJaJx3PtN0yBpSndPAxhrHPCcWinZr3TVVLkYzWAZy dNM1M/4NxOrz6s7xxupAtShCbuseNiFUCZ3DoMyvLnPh5abBgvRGvq8ZjxFc59Y= X-Google-Smtp-Source: AGHT+IH0PykjARYOlhRdYD8Ei00ntSXkZvlp+w/DvL/wK29HFMzX/PK1qWz6iq3HMQhndU3PBLr5iA== X-Received: by 2002:a05:622a:51:b0:458:3e20:65d3 with SMTP id d75a77b69052e-45b5e06627amr81705351cf.60.1727333299714; Wed, 25 Sep 2024 23:48:19 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.150]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45b5257ff1esm23024611cf.38.2024.09.25.23.48.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 23:48:19 -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 v5 12/13] mm: multi-gen LRU: walk_pte_range() use pte_offset_map_rw_nolock() Date: Thu, 26 Sep 2024 14:46:25 +0800 Message-Id: <7e9c194a5efacc9609cfd31abb9c7df88b53b530.1727332572.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-20240925_234821_168784_4924DBE4 X-CRM114-Status: GOOD ( 11.85 ) 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) {