From patchwork Thu Sep 26 06:46:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13812895 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 1A8E2CCF9E9 for ; Thu, 26 Sep 2024 07:00:17 +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=xHtLGGTaDvd+j7nlO+D4nlmKtDmH5wZnqdyAY1Z6B8s=; b=1DwRp1pP1KgPzL0pKS4ByEElAD aSi+7nx9oi/pb3TK6VTYdc4QBbdw4N58jKOHxMc6o7t4cIw7Xgmv+8A0nTxZXeK9tgXGvCgGS+BgC eZfHH4vCbnk7CgdmG3FJ69+BrdA51pZ9bIjVPIe6XURFzRmK7STcohFuKQFUa7Hct8KsicwHLxhvd W+T5tj5YeV5iaErq/G/+BH1FC9qdZ/KAh3RUn/59mm/PHDyb3xR7udkI+g4rvcYD1tmW1ILdPmX73 p+fNFBjbAWPkN+LDsWUv/XnLSFydOCki3pUXx0LRxHCT0ULi7LiAIXqC28snVIq1t8Po7sT78aFZC QAa+ceEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stiTt-00000007QaV-3CMb; Thu, 26 Sep 2024 07:00:05 +0000 Received: from mail-qk1-x734.google.com ([2607:f8b0:4864:20::734]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stiIA-00000007NdF-0EBv for linux-arm-kernel@lists.infradead.org; Thu, 26 Sep 2024 06:47:59 +0000 Received: by mail-qk1-x734.google.com with SMTP id af79cd13be357-7acb0499ffeso54904585a.1 for ; Wed, 25 Sep 2024 23:47:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727333277; x=1727938077; 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=xHtLGGTaDvd+j7nlO+D4nlmKtDmH5wZnqdyAY1Z6B8s=; b=BWOFC28jW4CxZFofIUxQI2fQoIS9qlXguFb+AoFYThdY7bITEeQGMZ2qXXmGQndt8F GuNeZyHGUyySm5OwZhj6RmMnMMd8UNPecY3YVq5UTIbhRHQq27Duxm9tuvz7FKAnDydm AaMbGc6mhLx8iu3czb4+VMg9mky7L85lhQVE66HNFOSmJC4nazOCUFoekRbANerIlIGT yOccRopLBMYbkEoLe/SrmDHwhf+YQf9NDvl20p0d1YtqtJZABcb/PyygB4Cmvun+o9q7 UW5pJ7LKzfnjDqD0EPNutlgSr3iISD4kfl2JLeYMSC6lx9ui1x6I5p0liflQJSE1d692 rDAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727333277; x=1727938077; 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=xHtLGGTaDvd+j7nlO+D4nlmKtDmH5wZnqdyAY1Z6B8s=; b=fkfnjv6B3yR2zxl+n50LqMqJZrRZsENU2V32TEXAipcBPu1vJ+qfJR5CegUmaUPR4I XcRLwhb7nKcSv1DIr0D0nteGEAJyo4dCi0qFDVL459jG1GCbPjVz/9gRPj6XOzHdgAEP txq7OXLlpJHlKDwOMlEIFDUGTX+gegGBVjS7z+JcG0P/2cGg/3UdvNYlpSlXzoW5/vGg K7rSvoci+Ref6Tbwshd5XgiUWSjeippPPN7ZK2fqQhpyfaFMRb1YX6IegfRum/J1Pfoc mTRQAP/4Q9Z0VqUXZxnuGfz1tdYJSl62D1RsnrdyWqe4Pk4E1CHOMRwc8GAllOQq3t8Q TmzA== X-Forwarded-Encrypted: i=1; AJvYcCWlopTqCcHgCGf55G2ePB3JaatXyCQRdy22wwCL21agCGxh8GTRtLZku3pI4qfD7QrDyUrYBb4u7SP1tiRWSLbo@lists.infradead.org X-Gm-Message-State: AOJu0Yx+0iCzcUpTyxdTlE8KQCC7GyTM+Dr/+qrvHQek134U5PVLgvza +tJDinhWr7nwDS2mVlf6T1Nyi1TXDSEW78rLkxiAgcxUCpZ2hPiTtTteRiZox0g= X-Google-Smtp-Source: AGHT+IGbo2MSjNAvLC3c2ApJAOpwKD09S+YUwBzMfKcY13i9YN/E+PXjNs0XRR1eOHqqnOUdrqUWyg== X-Received: by 2002:ac8:7d42:0:b0:458:2ce1:26f8 with SMTP id d75a77b69052e-45b5e045ea9mr77074431cf.60.1727333276776; Wed, 25 Sep 2024 23:47:56 -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.47.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 23:47:56 -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 09/13] mm: mremap: move_ptes() use pte_offset_map_rw_nolock() Date: Thu, 26 Sep 2024 14:46:22 +0800 Message-Id: <9d582a09dbcf12e562ac5fe0ba05e9248a58f5e0.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_234758_109394_5DB6CC9A X-CRM114-Status: GOOD ( 12.30 ) 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;