From patchwork Tue Sep 24 06:10:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13810131 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 63026CF9C71 for ; Tue, 24 Sep 2024 06:11:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E52EB6B009D; Tue, 24 Sep 2024 02:11:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E03EE6B009E; Tue, 24 Sep 2024 02:11:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA3C16B009F; Tue, 24 Sep 2024 02:11:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A74C46B009D for ; Tue, 24 Sep 2024 02:11:27 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6D862C180B for ; Tue, 24 Sep 2024 06:11:27 +0000 (UTC) X-FDA: 82598609814.07.4082674 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf21.hostedemail.com (Postfix) with ESMTP id 947981C0008 for ; Tue, 24 Sep 2024 06:11:25 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=NC7k5pQz; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.170 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=1727158225; a=rsa-sha256; cv=none; b=n44eAn1MlgIkARuSdMUaOXqn6YNOexZpoRU0bWUW+QwygYOo2mliE8Fc6y4IO7xOUycX65 xAjO2FxDnokRzpLQ84ILlExSnR3ybdcorDmqOMZKmTs9SxItJ9v78VmZRlLBPpjkgIVHpe Q/HBBrkEtx65sFTrmigZzeF6AxhC/dw= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=NC7k5pQz; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.170 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=1727158225; 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=JYDx6olGBZytK5syFvtWNqesQWJmZ/VcuSiPjSyD9NM=; b=cDmHejFIpTq6Fo2AL364ymjWHRzCOyO37jDCsNEdNTxTzr+OKFrs8Ofe4hqj/N8y6GvCwe rX9gIMT6UScdvMtBFFvuGqta6utgkf4qoW49BX4n+I4+hdIRnv5S19kDZ8skaEQm4EylM8 OwK4mtp5vBPN6X9/GTU5Tn1vovfl+Mc= Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2055136b612so61986375ad.0 for ; Mon, 23 Sep 2024 23:11:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727158284; x=1727763084; 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=JYDx6olGBZytK5syFvtWNqesQWJmZ/VcuSiPjSyD9NM=; b=NC7k5pQzcVeOJFo880WXhgW7hAJmJEWmpY7tlJelbfEuSuon5lmzica30E1oB8YNTC LLYKSc076cjO9F+W0U1WaDc1yghm1nKa7k7FNb0KZR7QJHEwQiJZiIkFS5JZN3tBTki5 Dbjcd3iqPSkfbkqdBB4SmpJzVqBCuy/5BpnWfYeAb9onjLbAii9C8+n+j08YqJ5MCP8y p94jIMP8tqdDkRvMVxJYuLyppNG7edIcfAk1/19GDP6+kJECe8uaWvL1HkLmGpTIcaTv 0TBBttZ5KcrHPNQQusTu1GwuHpYtuA/XuwDT0BPZzyHxsj6+sp/zmEQkPw0rYfx5sgPZ JGtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727158284; x=1727763084; 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=JYDx6olGBZytK5syFvtWNqesQWJmZ/VcuSiPjSyD9NM=; b=SItsLHeAgFq5fKmGFsS+O1wHEPyROTApFVehjNpQm6ixybN2SWYOwX4WCZjRY71uam d3ACW41Su1UAYtwH8o6LLrfcFT9kuqKorQBT3IAmrKv3DxJ8h8A6kvvyHGca+CYcueUq XH7C9YZXPrN3FEmbsXO6VEjLedhyC5kPsvSUtuNLCJq6+Ro8LaHLGX9fr1CPoE0JfBsr X5U7XvS8ZWKR+XrHsXg2Hh2oKTC7C8Octc373CMFDU5vjWb/TaXVsvAB01018BAipOnv cwTSrEYmdo7Z/rLH3HYP604qo2pRMwrOBIEaTIXUHHLdWPJ+CcqqaHm7m4XVHfvpSzuC i7IQ== X-Forwarded-Encrypted: i=1; AJvYcCX90u0MWWZbcXv+SaUCpVZierE0KmjP3r5lAMs2l2fq3+KyWzKzV115V7cRH/uy876FtPiwwq4Qvg==@kvack.org X-Gm-Message-State: AOJu0YxYuQhdJKHu01ncqEa6vUF49EPRnNAXnz4deL4ojE98UKIdE1xA iUjEgFfES2ytuSWy31lNEU0nA580Tz1g95sieSDOycgzWmbwqI5XIFzJRNYoCgU= X-Google-Smtp-Source: AGHT+IEhn+iGj1vkzgTAalYoZbG5psMaFd6djM60OU+3J7JbD8pdYTlvGGhg/wgUQ8cNcQFEVSSWnw== X-Received: by 2002:a17:902:d483:b0:206:aac4:b844 with SMTP id d9443c01a7336-208d97e3f78mr215574535ad.6.1727158284398; Mon, 23 Sep 2024 23:11:24 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2024 23:11:24 -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 09/13] mm: mremap: move_ptes() use pte_offset_map_rw_nolock() Date: Tue, 24 Sep 2024 14:10:01 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: pzyj5tz7sdb373rwgegfyt6wxt6rgwc8 X-Rspamd-Queue-Id: 947981C0008 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1727158285-495822 X-HE-Meta: U2FsdGVkX18XCG835c2/Tx6MGvx5G61n/DVsZwbV4KIybZKsgVjlgPF9JICNB3PzKA99UxVmc4UhPKcsGnJcxR+bSKU9xRtAyY4zb9dR9pQr3v8VlTLNkdY4wBiAjcZTMHJNAuVSiL+MRMmdtEU1I7W2ojVNUIQeEN8JLeDocGD20LUnQJXyEjgrFKGB3plo6YgEBl8x/rgkWeag5pkR67PDx1kQN61How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U5OeB/j3Xv/CrGM+Rn4/IVrNADrkzNlE18ov/3uFFSn3tKJ/o9Kq3AES+pCmk+5HocR/plkhj480cGjg82c2p1fv2PYOT4PZGJ1iDj6w9XoDsGgiyr66O1vBQw= 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 move_ptes(), we may modify the new_pte after acquiring the new_ptl, so convert it to using pte_offset_map_rw_nolock(). Now new_pte is none, so hpage_collapse_scan_file() path can not find this by traversing file->f_mapping, so there is no concurrency with retract_page_tables(). In addition, we already hold the exclusive mmap_lock, so this new_pte page is stable, so there is no need to get pmdval and do pmd_same() check. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- mm/mremap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/mremap.c b/mm/mremap.c index 24712f8dbb6b5..9dffd4a5b4d18 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -143,6 +143,7 @@ static int move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd, spinlock_t *old_ptl, *new_ptl; bool force_flush = false; unsigned long len = old_end - old_addr; + pmd_t dummy_pmdval; int err = 0; /* @@ -175,7 +176,15 @@ static int move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd, err = -EAGAIN; goto out; } - new_pte = pte_offset_map_nolock(mm, new_pmd, new_addr, &new_ptl); + /* + * Now new_pte is none, so hpage_collapse_scan_file() path can not find + * this by traversing file->f_mapping, so there is no concurrency with + * retract_page_tables(). In addition, we already hold the exclusive + * mmap_lock, so this new_pte page is stable, so there is no need to get + * pmdval and do pmd_same() check. + */ + new_pte = pte_offset_map_rw_nolock(mm, new_pmd, new_addr, &dummy_pmdval, + &new_ptl); if (!new_pte) { pte_unmap_unlock(old_pte, old_ptl); err = -EAGAIN;