From patchwork Wed Aug 21 08:18:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13771014 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 A488CC52D7C for ; Wed, 21 Aug 2024 08:28:57 +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=jOO3xScatAPPPb8tw2FfV0S/NtjYDESd+MYV0EHgGGs=; b=KM6vjAMobddi2mhnhTIC86CzFq wilGPfLdC6BlMbDxkDuzA2EI9fhX3zkP6Q06rYHi7IUdJiuDRz/vJOGNSlpFU9mb5180MgG5z+R3Q XN5djqqx2dql2bvjR5RzZrM4x2Mwd2fbaLIHB1HuO7nYXTNPOIATJwnDMTuCQQL9NsaoIwl8/r2Yy NJTU2brCxhfg6UE4vAGjx7/rcuE40Fd+hCSu4mE7HJE/sobqYoxUasKES1P1jPLlCTUOiSqYpMS3+ lNvWvYJ8aTzAjMD6N1PYF/lNoVkwEGQUb1qw8XoX8EB8ySV6Ce6fvF1Af9rVQJCb1XdN4PAtiUqu/ Xkebk3kg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgghx-0000000842I-0Ujh; Wed, 21 Aug 2024 08:28:45 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sggaA-000000082C4-1R2E for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 08:20:43 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-70cec4aa1e4so4316350b3a.1 for ; Wed, 21 Aug 2024 01:20:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1724228442; x=1724833242; 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=jOO3xScatAPPPb8tw2FfV0S/NtjYDESd+MYV0EHgGGs=; b=Av0sGT8CHOhksuiSoFM+NWmvLSK3gUfi8Dq4bnHqoieXJdb5Y2IPcGTOWcpp8DyC3e CLQP3GenDs0WTRy0APqOYZdpeZ/Kc995CIB716KbeG4SaDvTl3xaJXjB+fG7inupE7Y5 J8GAd1iaLGX16iCKIWCklETYFM7r1wkYxIY2ZyLLYT+yIkCtjr1x02QRgHVj8TWOnjyh 0BwSN3WrUPRs9e5lhb4ReVS0GbfEYR7v9E3vB/hRchwfWPYtA5kMWDhDr1xFA4ZJZKhR FxTBT7FBlICHuxEAd/WJDAYnISmJ3v8PXPp4N5AYwmU4V/HRpjXNau7D08UruZ/N0L57 vweQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724228442; x=1724833242; 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=jOO3xScatAPPPb8tw2FfV0S/NtjYDESd+MYV0EHgGGs=; b=OsldEmlljlxuISOFtFbGenGCaIjFoWeWloziIZTeL6Gn7y8m0yHMu8WVkgRj4WUv/C CtqlFhM0Z2M6o2HsgY/MEMUhI5grKHu8jR23i2CQlbnei/Z6Hi8k6XBSARYtV6gERFQu 1jw2J5RwgNVhPg0NLN1CBInTVbtEhPYT5C1LZtLaVE8Md+jsW2w8Y5liZIlkrDe+iqlT PvK3jUIGjB6fZZ/Q6MVQaR2yLGsggPEs0uJXDs4k4Juk295gYsNA5GIRb4C0wxczI/83 wlm1dpSZ5ra5eA2vNm3y6MWnffsvQ1Y9M9FS+ntd4vyL4P/IVIj3X1e2SXs1MZBabmiP JePg== X-Forwarded-Encrypted: i=1; AJvYcCUkrvFxsix/LRZAk354QGuwoXbPHhzYy1ZZqmOajy0IKP3YnVunqzF/lenusp93+ayEGH/C0FvxFx0fCRdEHzJg@lists.infradead.org X-Gm-Message-State: AOJu0Yx8n+tEA/W1DVBFLz/VPivvDL9N6t55Aa8ZM5r4/AH4z33K+wig 2BZ5cxIWA+0Q/1Lr6SuIwIX4OK9b44USbccjRTafs4QaxI4ARc4rZt3pgVrTOTU= X-Google-Smtp-Source: AGHT+IFM+x1tDjPFZswDxs94u/u9nyN6BfWsdj/MLtJd+fBRDvg5mEN2O6omshjTkNyUCHM1AQzwKQ== X-Received: by 2002:a05:6a20:e605:b0:1c3:ce0f:bfb7 with SMTP id adf61e73a8af0-1cada055937mr1798278637.21.1724228441599; Wed, 21 Aug 2024 01:20:41 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.150]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d5eb9049b0sm1091453a91.17.2024.08.21.01.20.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 01:20:41 -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 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 11/14] mm: userfaultfd: move_pages_pte() use pte_offset_map_maywrite_nolock() Date: Wed, 21 Aug 2024 16:18:54 +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-20240821_012042_403168_ECFDD383 X-CRM114-Status: GOOD ( 12.31 ) 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_maywrite_nolock(). But since we already do the pte_same() check, there is no need to get pmdval to do pmd_same() check, just pass NULL to pmdvalp parameter. Signed-off-by: Qi Zheng --- mm/userfaultfd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 6ef42d9cd482e..310289fad2b32 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1146,7 +1146,13 @@ 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. + */ + dst_pte = pte_offset_map_maywrite_nolock(mm, dst_pmd, dst_addr, NULL, + &dst_ptl); /* Retry if a huge pmd materialized from under us */ if (unlikely(!dst_pte)) { @@ -1154,7 +1160,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_maywrite_nolock(mm, src_pmd, src_addr, NULL, + &src_ptl); /* * We held the mmap_lock for reading so MADV_DONTNEED