From patchwork Tue Sep 24 06:10:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13810174 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 150E1CF9C6B for ; Tue, 24 Sep 2024 06:23:35 +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=OfC1RlAMiynS5u2L74+wFKTmuv 63I6GJVprKkVsKqXqRTBlWid1L5EGEk8TeNqWznKbFOxAu15Rj7Oh4ct7q0u25mFx5GzuELoNDix5 1RDKeZeEC63Xqm2cvbM0o1f/BeDygRptXa+Wpq9IO8eUB/eM1MIdBtsFhoEo3yFAMMX27B2UWiX8M z4jJ17JaYM7t2k04si1TUL3VWn+lPfWqDXyCAl9UHmzKa3Z9e+0meP6NImQeh2EjKdfxZjLUZb3Ma ynUl/E3+qea9yIt2706RRBy1R1HszIp5bR0jA78dpHiw/Mc4ewtlsqirgqUA9mP8QOeqy0CjYNHDs inWpajfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1ssyxG-00000001Esb-2O8x; Tue, 24 Sep 2024 06:23:22 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1ssylt-00000001CBR-1Bff for linux-arm-kernel@lists.infradead.org; Tue, 24 Sep 2024 06:11:38 +0000 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-20551eeba95so44279735ad.2 for ; Mon, 23 Sep 2024 23:11:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727158297; x=1727763097; 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=CzPGHGmRFqEGbK8h0wANbgJs5PRtl4UvTcG/TlXfG4R+Auh0gmtZl2TG761OpF3RO5 7uI8TwvEPxUmnJaA66GtncrmLM345QV1lZWuXIDUyJaDgsew1IXixt+E2Mn1KskooLiX jttVQJBUc7klIB7+GBWL0ERd0UzcBAycH5Tj9bBVA4zvjgZhoRlYvCU8AmGZE3nhscCs dAB1nMGwPDC7WC4VPjNWbenX7TBRH74wqQg632Ff4yXfwNGm05i1TxuQYkHqI8xvFEOa pWWUGl9kO3xpmOELpllxFG0ROCWeYeHpsoSiDW2BduxM+bWTWZ4EYUMG2507aQo96e1+ aZJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727158297; x=1727763097; 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=TOlKDUDbqCC/YlTf2haksyLlLoFuJbBvKMd7Vz+Dv09B5jHTubQ1mlfuu0nTfikZaT i8Va/yVmEb41HmPswDacZfRThpc3CgrRfIfrSLhPNb05MCaU16DiTXkQP+tUM2XedU3k JeJ0K1A5+4/nuaQHX6KoxkI6QNB062Akn2CSRlc1BcTKOwvitbCOAti50YewkAdvX4Bt VlbnFMJ/hhN5mmkocD90Yxy94aMJJzqZTRNOD6gQFr3O/+TrpsLrSjdpLEdrMvS6baqq FOVswtPd6Yu0Jgo1RqUY/BowckNEw8DkjlGfQYoiVufgN64ekcuZdIVhL0Idaj2tU9OX fbmA== X-Forwarded-Encrypted: i=1; AJvYcCVV4R2IGKTtE0b3vrmQP5u1L0OQ/ma/w8ExW36kUl+HeLftrHBp4inBxvOu6Ijjcm/FN6GNY6RHW+SOEgARgffJ@lists.infradead.org X-Gm-Message-State: AOJu0Yy6CXTR3k1Pbd2YTn2W+Y3/DGi1VlZSqpsCCh3sGbMYwyNlZuCS eQEXZsaV2v9um9uLyZI+SeV0yRVCQlcrV9vuDsSnFQ2dpfp5pAMCqaahFPJoJ3E= X-Google-Smtp-Source: AGHT+IFBI5Ned/vbTuuRRzdnv79MFASKoi0/m2fLpf4am0H6y8GNq4qW/RgfzVT9no9zcYiBkg/Xzw== X-Received: by 2002:a17:902:ea07:b0:20a:f013:ddb5 with SMTP id d9443c01a7336-20af013e29dmr19152265ad.59.1727158296610; Mon, 23 Sep 2024 23:11:36 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2024 23:11:36 -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 11/13] mm: userfaultfd: move_pages_pte() use pte_offset_map_rw_nolock() Date: Tue, 24 Sep 2024 14:10:03 +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-20240923_231137_345480_57BD93A0 X-CRM114-Status: GOOD ( 12.76 ) 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