From patchwork Thu Sep 26 06:46:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13812897 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 82CB0CCF9E9 for ; Thu, 26 Sep 2024 07:02:38 +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=RnMCKwBqnYl3LJbu0M9HQTu7wcymlNTkAYqiZlfWQ7I=; b=FXXjBipcGMo1ubnmEmrqRtJVUO STe2EsyDZj8olaznZXEDwApfaHOqJJFlDwtcKEg0cjFS49I+n6DeZ37kLSLCMwNQraSnyS3p8meVQ WbAwnL3bsfju26yLCHTV+uzXKHewA03bsRsY9JF2+YL7HHJCr5BBavSjVB+ml3Hvn+mF37kmuKptO zHE2JSSxwg3rNDyKGLheFlDnYKapO99phzHGpNzsl5zYa5d+oyr9zcCI3j8Ea5qxm7HruZdPYPRZr qlYWTCB0A2m08VQdG8tAxcvKsy+ZysAC3CchKJlRmBN/dRsujYm+EUscVa9ObhW8OpVax0AbCTYU3 rH/lQ8Jw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stiWA-00000007QuQ-1CF7; Thu, 26 Sep 2024 07:02:26 +0000 Received: from mail-vs1-xe34.google.com ([2607:f8b0:4864:20::e34]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stiIP-00000007NlO-2HI1 for linux-arm-kernel@lists.infradead.org; Thu, 26 Sep 2024 06:48:15 +0000 Received: by mail-vs1-xe34.google.com with SMTP id ada2fe7eead31-49bdc6e2e2cso272883137.0 for ; Wed, 25 Sep 2024 23:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727333292; x=1727938092; 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=RnMCKwBqnYl3LJbu0M9HQTu7wcymlNTkAYqiZlfWQ7I=; b=kLIPbwiuZj1SUrdccigASkz1JMiUy5JdSspYvAKzldnJ+SGSYwm16rPde1CDLfVtWp QEnTj6WvhlPrYbpZKBV9Ap71r4D7Q6HJ8RqGWr0ORRLiI7enjcfpNixuLbk3ALWPZQU+ QXUti00f5bs1eKe1j6LQXwSLuDIg8utfmzP/Bjvx5S8fp5UTMF1iLV2elUIleehiynKY olwddDxYtmj3vlbRkLuX37mXhsyL6dBZvLrBKOHMFd+HGnFaPoBh+an5HAnmAV1SoIML lbv0OsnqeXKXtxkJGdlXFmGK+z8YPETEWSeB+XC/3M6XOFfv9i51LQvrpdXQEwTA8hg/ Z21A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727333292; x=1727938092; 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=RnMCKwBqnYl3LJbu0M9HQTu7wcymlNTkAYqiZlfWQ7I=; b=J4Q6dAaEQ6XhBNhGFqQUfO67u3hByNh/4X73ag3lruSuW80WHPKRmmX2rSgcJljTV8 aKpTokrqomHucRhhesoH4rWWxbS3ZEDDxRG+Z3d3DsoEqg5AfXRFHHWYlZkDHKm+iCRL 4xD4s+t7/qgekh5j/TG834x+LzQ1wdDUwynOkXi+gvAr5oOWX9K6d13y6j3Ht8V/pztm KccSWW4PQKoLTqtAOhuLAJGO4aTQMEy/+GAIKxszWT5Sem5KOqC2nSaW18w6SPKenr0g KQmTcai7Sk26ixsUunFUxEC6I3r89qyVHa6jR5ax5nzAqSkJvTkyig+BQ+VcT3FpfmXr BzEw== X-Forwarded-Encrypted: i=1; AJvYcCV3s7SaQaM0kLp9wL39XP1kMAZxcLrvdvi5XfslKKFz01wSd2KucfHwlQP34g39qj/Q/7So/64ltBdaOocYRM5M@lists.infradead.org X-Gm-Message-State: AOJu0Yy+GwHIvrLKAlSqIJetWl6U/6Rvbo4wBnF0/GdregR3BeyTrla/ AvZvtQyixtsb+Tqk0va6E/gpwuxMD4DFYC6Vz3dMAK6/+43dqlF6kpJEfep8U3I= X-Google-Smtp-Source: AGHT+IEjiufoSG+9f7J9DudEHL9YuIq0UaJx7YZ52pOk+qHYx73DXmea6YZQnzcRnEEhuuY+i+vKHw== X-Received: by 2002:a05:6102:e06:b0:493:b055:bf56 with SMTP id ada2fe7eead31-4a15dc39965mr6802341137.2.1727333291940; Wed, 25 Sep 2024 23:48:11 -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.48.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 23:48:11 -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 11/13] mm: userfaultfd: move_pages_pte() use pte_offset_map_rw_nolock() Date: Thu, 26 Sep 2024 14:46:24 +0800 Message-Id: <1530e8fdbfc72eacf3b095babe139ce3d715600a.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_234813_606455_C860992B X-CRM114-Status: GOOD ( 12.26 ) 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 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. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- mm/userfaultfd.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index ce13c40626472..48b87c62fc3dd 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