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: 13810175 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 7FB9FCF9C6B for ; Tue, 24 Sep 2024 06:24:42 +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=JYDx6olGBZytK5syFvtWNqesQWJmZ/VcuSiPjSyD9NM=; b=QjtSS3u6liLRGbE7wl/jMMUQ8p jPyQYZDWbfLaI3+74aXRMFOc1XycMwjWYnShew6CTY7DycJrPBZLyXsU4qQKzugGI1vJbTiKHbJmj Hkjkr/whvnugxi7onAaRqGH31cKkM1VHKc+dT3S9r5MZzNIft3Qznn45/YlrHvjnUUWzNJns+xsY2 aWJ0jHcxwaKkfIV0/174HBNb7qZd/cZGCei1VqDdOyAS/F4t7QA7rEXKop2bunx6tJbuPAjD3ICrJ HSepvVrVxmN93POaAm8HSwxc8hxHuCs4QFFuRqZ1DLdHjNdbUJ/taUlelIdKNz+i+5bRYNBD8prdf ufxerhjA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1ssyyM-00000001F3B-0ZS0; Tue, 24 Sep 2024 06:24:30 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1ssyly-00000001CDw-0fkd for linux-arm-kernel@bombadil.infradead.org; Tue, 24 Sep 2024 06:11:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=JYDx6olGBZytK5syFvtWNqesQWJmZ/VcuSiPjSyD9NM=; b=TvIwKpjUQb3oId1COm3OHRt2an iyDKzDNS0ZGepSZf0ItB8uh+WD8XGYGOWRopfc/4B+N8/brZfXHnnJ45EgB9Qx8IjW0irCwzULdfG V6iO59zk9DTdDjKSey9BUDeszVULz333JwDe1n9VvWwcDPigOJh59PGrPoIQSQcc9h8V42TkmqHJd 16RD8xchhNHKjIX/OdNS6gl8raGUU/wp8dU0f7mpAYJsD0PyEQBhFLdbGDJszawVMnA7icB4BKfuq 6AwRSDf94NvrQnH+gcD0rjsEirqCjk4mJFXkhUlI6Hb7iLozYXOUIEU9c31tG/VLhrBYri5NDvRsy zkqpcSiQ==; Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1ssyls-00000001jzC-3dxj for linux-arm-kernel@lists.infradead.org; Tue, 24 Sep 2024 06:11:40 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-2055136b612so61986395ad.0 for ; Mon, 23 Sep 2024 23:11:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727158284; x=1727763084; 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=JYDx6olGBZytK5syFvtWNqesQWJmZ/VcuSiPjSyD9NM=; b=VVZucuoDBhGUG03btOCA67Hce7XVdUS2X8gQLqKZ5E4mBW6PU/FrnRJgxfVfN5lzh1 4yme97FtDMIC6Efl4//x1XcJCBY/ENjUemdgK9wO0FHUqOUEn+l6KQWPlIt3PVAPglCq m0fW9dn+PMFMPXwIIPQppIw9zl7pMkdMuF5X+gB7S/BK/qD8GKK+9iWSWm1YeyqUA1OJ RY7HmXmctXqEJC8mYdkgbzTdTQZLccqsZNAMhTlJSl3anOi9ZTH31rEdXmCU4rj1MZbo tfOZ5qVBs67f5DiOSSaj7IHYizrGJXCZa7pAlsQh/8bOX+5yZs57kAAvdXnPlBXNYUqD 5Ltg== 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=HkVAfmRu6BSxkFUyNOR7PnhfCC+/eqRljBLSw8qJws2IZoCgjOe+cW3dSLllJAGPsP XnC/rm1AifkjT5B1LoZZ6qoRd2rBlHcYekpKkVNhaFOBLaUJqbxjR/6lSWFpVq+VC7Eq A1eMmTw6+5if0DOv2uHEAWhfDPBK3UvyxJ4AX4EBaCuYDZ8My04EBuuJcGjlg0tmM+vu GgMyIYL/8Cgwv9JxBT+5ONuz5Gug09/PZLyWMUYZ28dYjGrBi2dV+nNVOhuWaNdTm7NG ghDojLbcWTp+MJKRDSdwWwMogGun8izYLTww8tXwNFv8lxP+8E6viz9nbL5k1ApYzGHT KMyQ== X-Forwarded-Encrypted: i=1; AJvYcCU922SoyP8UgqFLViPNIaSFjrFxoOswhee1z3kxrkLn5ddTUQZ94Ujvl+vZL0GRqJwBV62F5H5XTL7zDKrHFrkd@lists.infradead.org X-Gm-Message-State: AOJu0YxQOcidNe6q144nUYOGCcR54/0+gRvidEfcO0injRWZm5s5qprK oL6gO2VSh8o673r0McmujEu4+Q2XuKBdXmKa3b6U3IkcYI7BM40P8C/iF22AwVU= 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240924_071137_894489_AC855B09 X-CRM114-Status: GOOD ( 12.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 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;