From patchwork Thu Aug 22 07:13:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13772876 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 27ACAC531DF for ; Thu, 22 Aug 2024 07:23:32 +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=7wvuIpVK8M95P7HYfgMO/FZeMoPfoEIc6BtRbN48KOY=; b=uUWhYy/XoK8f+ovTT0FDa/Vu65 MRz2D34QB7sPndOgt9EGQpG217pJx/ve+bOqPX4Ui8z6eymzLBBkAJ7dmbwI9BDkw3/MZiPTIV/4c r+yWWGjcxtNRsYDIIFF1uLPuyLReEfDk5ESDsNzvYNXSC14C7T4OAKLtdWZKH1KudqGz/Owmqanlb M/3FntPjswo+Fnopf82sHufKuXrhvcMUdU+dbMyQsUyxCw103IHdV+vfrtx3lnJXblciVCWB68Z5L hS24AojQP2bBlgRVmfedW0GthiDQneszkloB8hDa4u0GyLXIx5nUtiY7CmKGM3PO+5/9DHR6YlE6a 4wlrGrFA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh2A6-0000000Bqhq-2g1y; Thu, 22 Aug 2024 07:23:14 +0000 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh21z-0000000BnNx-2QEI for linux-arm-kernel@lists.infradead.org; Thu, 22 Aug 2024 07:14:53 +0000 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-3db14930a1aso293534b6e.3 for ; Thu, 22 Aug 2024 00:14:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1724310891; x=1724915691; 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=7wvuIpVK8M95P7HYfgMO/FZeMoPfoEIc6BtRbN48KOY=; b=WRsCp2PxdE6BMAF5zsiFf3msfXt6ZJFf0QRpBZT4fBJnocbsK/JzLmbHBOFzn53URY 3LYuhUq1PjPhBNkHz0Wqu0sYD7i3z/oWOuWfwWH1eBcdIcdi4CfKvV5DrJ0oxCp+X7v0 TmCmwEJG6++tOHGMqpEIfctJwhnC5/2NUsJBHHxr8HQvZub44cVNRZ+gYU9kksIip+ZA 3iJh3rgCS8PR00R6pGiD7WT5+VY5pF0TJ3Zhf2vH5fcqSBqqy6jeiUSMSO5FlTzeEUy3 Ig+l30eu+Vx827bLPl5F4dLfsnbexyt1qfqiPWqnLdxtkozeWi5R+o9shzakfF/AV5xd lnPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724310891; x=1724915691; 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=7wvuIpVK8M95P7HYfgMO/FZeMoPfoEIc6BtRbN48KOY=; b=kVNHwcs5Ot/ttsyBKCAJkat/ezq3C+W+/r2eP7/1hdmv0iKjFDVU8eaobSf4IBh5HU 5d9ag2GrYUH0Gp6rCwVDdwuaau9I6Nyh0+IArISITuP/aOPzS1RJWmR6UIYOMiUVX/ZB JSvKuNVhC+6uqoRLuaOombt9OBcwL56fCxqRsISnjWfh9hM+477xRd/VQoHn8dcYNrnc 8uTaEJ+ln2rL1Xl3IAfdRWra8WYcBgc7n/nwONcJZuZJmQUefPYzpJc9lg5mmTL0TjBb Dox2WFtjOoYjQHKYRevo0gVLu7ZnAfsMnvoAziUMQbg67c04H2Z9ZfDuZ1tGF6gk3oGw Hxkw== X-Forwarded-Encrypted: i=1; AJvYcCWvI69CK/e4f7Di5W8VFeN9rdfoBuDIFQ5a3oxcHtjwsaBNMALX2SRvAS8gAPsL2oHpR1d2gV+SZtsQz+GkuLT/@lists.infradead.org X-Gm-Message-State: AOJu0YzYY2Xu6VurYB7B4XwUBMAVwi8F02yfA2MdHV7b+Q7WcTBmGAgy /0eOKlMfaZy9sB0sI3+5T8ULblFpDQTucmE34ltxdvd1SioZjpaLlW93OjmElHQ= X-Google-Smtp-Source: AGHT+IH3dTXEnimLAtKAfnTveP36n8fQueYjLUMvugh9RpWMjyLI+ldrjyQ+VF2Ub3qToXnGQhbMbg== X-Received: by 2002:a05:6808:3847:b0:3d6:2b12:7dc0 with SMTP id 5614622812f47-3de22ff6ae0mr1325714b6e.20.1724310890896; Thu, 22 Aug 2024 00:14:50 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([240e:473:c90:f96:d029:ea8a:4e6d:d272]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7cd9ac994a3sm695095a12.16.2024.08.22.00.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 00:14:50 -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 v2 11/14] mm: userfaultfd: move_pages_pte() use pte_offset_map_rw_nolock() Date: Thu, 22 Aug 2024 15:13:26 +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-20240822_001451_674746_D6AE47CD X-CRM114-Status: GOOD ( 12.81 ) 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_pages_pte(), we may modify the dst_pte and src_pte after acquiring the ptl, so convert it to using pte_offset_map_rw_nolock(). But since we already do the pte_same() check, there is no need to get pmdval to do pmd_same() check, just pass a dummy variable to it. Signed-off-by: Qi Zheng --- mm/userfaultfd.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 6ef42d9cd482e..414ee744257b7 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1135,7 +1135,7 @@ static int move_pages_pte(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, spinlock_t *src_ptl, *dst_ptl; pte_t *src_pte = NULL; pte_t *dst_pte = NULL; - + pmd_t dummy_pmdval; struct folio *src_folio = NULL; struct anon_vma *src_anon_vma = NULL; struct mmu_notifier_range range; @@ -1146,7 +1146,14 @@ static int move_pages_pte(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, src_addr, src_addr + PAGE_SIZE); mmu_notifier_invalidate_range_start(&range); retry: - dst_pte = pte_offset_map_nolock(mm, dst_pmd, dst_addr, &dst_ptl); + /* + * Use the maywrite version to indicate that dst_pte will be modified, + * but since we will use pte_same() to detect the change of the pte + * entry, there is no need to get pmdval, so just pass a dummy variable + * to it. + */ + dst_pte = pte_offset_map_rw_nolock(mm, dst_pmd, dst_addr, &dummy_pmdval, + &dst_ptl); /* Retry if a huge pmd materialized from under us */ if (unlikely(!dst_pte)) { @@ -1154,7 +1161,9 @@ static int move_pages_pte(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, goto out; } - src_pte = pte_offset_map_nolock(mm, src_pmd, src_addr, &src_ptl); + /* same as dst_pte */ + src_pte = pte_offset_map_rw_nolock(mm, src_pmd, src_addr, &dummy_pmdval, + &src_ptl); /* * We held the mmap_lock for reading so MADV_DONTNEED