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: 13790100 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 6A846CD4847 for ; Wed, 4 Sep 2024 08:42:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D7BB38D023D; Wed, 4 Sep 2024 04:42:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D04088D0239; Wed, 4 Sep 2024 04:42:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7E5D8D023D; Wed, 4 Sep 2024 04:42:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 943758D0239 for ; Wed, 4 Sep 2024 04:42:06 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 37CF81A0E91 for ; Wed, 4 Sep 2024 08:42:06 +0000 (UTC) X-FDA: 82526413452.30.5BEA6B2 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf10.hostedemail.com (Postfix) with ESMTP id 56D6EC0007 for ; Wed, 4 Sep 2024 08:42:04 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VYLAj4a9; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.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=1725439276; 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=Y4jsyz9eZnVjuIeNrv9jm5llMD04VewCinfUm/XXhZs=; b=gYVHJ2zswk2RH9iLBjB2XP/0gxSMuzTbBTAQ6JAZnlVmKBsfWesCnkPMP6Yi3TR3Jp7ksz 8GJKuCAtAmWFy1Im8UKTywKcNd4AZ6GE5IvY3FdIsu5jlkwIrydPTAYq3/sTjYZUwadzQc M2TK1FLkAEvZGWYkZOwASpmMUAIgbEk= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VYLAj4a9; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725439276; a=rsa-sha256; cv=none; b=CynTriYgRSUxoXOKFQZRkdA0rKl5CyZLjg/pbxv3fVPDho+5op1DzbcGAZ3YPlsbMhwwkV 23RxbY2IZrNNoDPYMJOQjgHE7uFVQpWHbRNoh5svVuxvl86WzeZ+v0EmTA07Grh9+xeLVW 7bfQdL476yYat95W9v+lWRFogRyFvrg= Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-7cf5e179b68so344693a12.1 for ; Wed, 04 Sep 2024 01:42:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1725439323; x=1726044123; 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=Y4jsyz9eZnVjuIeNrv9jm5llMD04VewCinfUm/XXhZs=; b=VYLAj4a9tTguWAynEJHqFDDCt53iqUFsBS4D+5LaOOagpYhtbETbUnYUf0fYjQv1hu K30RqWC312v167gqji6y1pNKDfXjbZFPbFtpWcSJr9vyvDtfq0ufAEmL3meHCzkx28Ww xL4Yo5+A+IqZIiAd9Wqhypn0Y2zOi9Ky9psWYi7YtKPnJjy/uQpx9vrUKQ+mlwRgmhFL D+2UodjBeq1SA4WBEDJoht+1w6yXjNnSxyPknOQuF+AcnbzPsny0IW/tf4iwp3HwIlNF 9tEi0lOycxq3kHbzAqKgu8hXU9qKkIG0/lXZNWm8Vz1LDmkz6TfA86bvVsAwf2A8/LfH K01A== 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=E53u7GMIqyI0pSvAvxs82nlGCPIwFI8uArbxUqtu6fVRtD4Uu9r327FmNDOhw+0dqK LQjGJOVKmDzYlMjEFNgurerAT+r037JW/7EIzZy68IibdwNZ0sUdQCGkoE/eVFbW10TQ d/Czb3M0RfBSdsqccIjhTYzJvZqNXEDcOTruPJzVjjtUvsSYHcpwW/4+Qonqa01Kb4n0 HyLg1KMwhoinVeQ8E+ObT2nlDocXMMeoyIWsdW1KH0nPEoF/7VT44MzKQGMSDE/8Qb5I vGKWb8kKa3c/QfIT7taOsBzxRRvmyR45m5chRgU3piKJ4fXLcLPg+0uW4bULhmcNa4gJ Kt3w== X-Forwarded-Encrypted: i=1; AJvYcCWb5izhyXzc4jfRcYfa/3ZbGdjs1hC5dMBeQahWjytz/j5JoJfMQ8vcc35FyIZJ/iyRW26yFeTO4g==@kvack.org X-Gm-Message-State: AOJu0Yxd8Y7ps/P8C7PdxiUTOH7b9LZ0wXskRyM5AP+WNGHrBV8D0NBv aitKLWKB2zMZKb65NqNHPpSULkEjJVPnV57h6kbHUOZL5tR32DEeDC8LOAHD2Jw= 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-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 56D6EC0007 X-Stat-Signature: i3wyqkth8n9gimffg8gfbw5kqbwbio9x X-HE-Tag: 1725439324-503328 X-HE-Meta: U2FsdGVkX19nx5Vyy+cZc+bgmVQK42FAojCJItt9fF5fdGbAfroPmxgTCmDR8poT0cQaYcanbNi6ZJhlc6/MqSTeMzss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zyhq4u44Elq6QZSLsR9JZObE3S0GSVARwgPGnQVn7ARSMA6SG03uZq6dkM8oSOdbQxKTkAKC1y+EP/yie5f5S0ty4yL79DjFYWN32mSLutNqe5hi2sze+EZTwwqLdr/ceKwTPNdMrplUAS90bUaJmT8MtykM3O7nhWBZkw3BowJyuRNZd5rd7DQJTYMkItN7VD/yuWiBSWa2WNfS7hdUY1nTFMVu0fLhlhx4GMyGxLeeL8l1Yfdw7P12vugg== 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 --- 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) {