From patchwork Wed Sep 4 08:40:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13790204 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 A6003CA0ED3 for ; Wed, 4 Sep 2024 09:17:38 +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=Y4jsyz9eZnVjuIeNrv9jm5llMD04VewCinfUm/XXhZs=; b=NgsRsOqm0OJj+hzinsWZL/7KBv TKpnsPeufrrlKNt6KVRdn1ZntXXoFr+tspUtNtLlTdg6KAI5rgnsOKFuL3IZ6xNJhq9DlcXM64aIH UDgqwcMRRbk1bjHRPtdxI/Eg7DOVpqrpMb3KZtHfyHHzXW7RV+DPqe/NeVrmZ4jILXA2BB3roq4N3 GsNzn8HT7g83JQ2FkF43/VIpYVX6d4beMxDlq/OxN+CnBVaLhowUF6A7QazDgHNmPJ6AsVUSY6vBl AE7VsqoBA7uNhCA/pGS4oQ4k19GbQtJ29hg2U3hetr1jJe+1M5eZYJ4dgk4pnfObXqLX0RbyHp0q9 tytaYoyg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slm8m-00000003dMc-1iSd; Wed, 04 Sep 2024 09:17:28 +0000 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sllaW-00000003Teq-0FtS for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2024 08:42:05 +0000 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-7cf5e179b68so344694a12.1 for ; Wed, 04 Sep 2024 01:42:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1725439323; x=1726044123; 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=Y4jsyz9eZnVjuIeNrv9jm5llMD04VewCinfUm/XXhZs=; b=alc82p1Dm0Gzx50K96eMxuHQcrZncugzu/o4jGHKMEZkHsULfVj8pEdR9jsCW3GVh7 SrYUB5JsEDRD9xsuj6th+2woHyOGIjTCb5VcYzneX4N9UpTdhE/JvKFSuoSCdPND7K6Q lldcdlCWEwWRxVMe/rGfO/WDJg9fHnM3Lu6zqh4AUjcya/Xgd3YPS9+1Vu7dsNRxUwAr Ytx1gDMurXySvir6M7IRcuAR3fpfJKZRzEngGUevYMmLqtkm27qLZZk/0kGr4aVYTv8p bvR4+6IEqp+pMi3H/VGfEbHYd6EFaXWaAMns1Z572+ybG51BeG8tIYHv7v6cnA6/Scyk eHgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725439323; x=1726044123; 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=Y4jsyz9eZnVjuIeNrv9jm5llMD04VewCinfUm/XXhZs=; b=Z1mZUXowW1subpXURVMwqtX8Vr80FdxsERzCmTF33n/PDIj+omIu2p9cWZ9D6gVlNq Rc71XKRC8VOsbjU0GKsCbv7b5gmQjB3/zkpXbdwrYtR1zbdnNsWPb78Spn3JQmFxTjF4 ZDEpDGQORf4BdwVZpOIXqHcAeBcp8pP+OszEOfXfUfKAgLZaceP4uPhTTCDjA3ZZM5DA jIVEPF/w9areEnd+bSihJcbVPcYKy5v8PhIigHzf7ifc+Y9b0cBWrk+/agLatmRpadBb MtiCX/jJ5yAMm0rwueFhqENHAXXgnuEz5ACCs1G/sVs4hrT6MdgO2Jn6xkjdxO+hjyIF 40ug== X-Forwarded-Encrypted: i=1; AJvYcCU9auNFSfh4L44MpDhHQSOPoX4AS2XBiRZY+qGmF+0K3dGlM6S5Ak+1xTV+54uAkh2JBoeGPC6jdiIdxPShTXHu@lists.infradead.org X-Gm-Message-State: AOJu0YxTv2biyWA5Kzawz4zrae8vT0kTO6BB6ALP2pcTzN7Pkt8RDrYt FSvonNwVQq8PVCThyiYXpvlrDF/W0RA4/xd9UB/doySFy68B9CD02VGVABI7ejc= X-Google-Smtp-Source: AGHT+IGXU/qy5PPe2L4ehUmGkYFpO+LVdbh/09mdfTo5RpVJKjaH3T6TEVRYBI0feUcEJkjAodGgeA== X-Received: by 2002:a17:902:e545:b0:1fd:6ca4:f987 with SMTP id d9443c01a7336-206b8341fdfmr24676655ad.15.1725439323059; Wed, 04 Sep 2024 01:42:03 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.242]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae95a51csm9414045ad.117.2024.09.04.01.41.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 01:42:02 -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 v3 12/14] mm: multi-gen LRU: walk_pte_range() use pte_offset_map_rw_nolock() Date: Wed, 4 Sep 2024 16:40:20 +0800 Message-Id: <20240904084022.32728-13-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20240904084022.32728-1-zhengqi.arch@bytedance.com> References: <20240904084022.32728-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_014204_190909_B9347F65 X-CRM114-Status: GOOD ( 12.50 ) 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 --- mm/vmscan.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index a9b6a8196f958..36b84e46cd7b5 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) {