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: 13770994 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1D0BC52D7C for ; Wed, 21 Aug 2024 08:20:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55B596B00D3; Wed, 21 Aug 2024 04:20:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 50ED06B00D4; Wed, 21 Aug 2024 04:20:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 369AB6B00D5; Wed, 21 Aug 2024 04:20:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 14A246B00D3 for ; Wed, 21 Aug 2024 04:20:45 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BCBCE1C229F for ; Wed, 21 Aug 2024 08:20:44 +0000 (UTC) X-FDA: 82475556408.11.1E069FF Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf07.hostedemail.com (Postfix) with ESMTP id DFA0540004 for ; Wed, 21 Aug 2024 08:20:42 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=ghE5JOPV; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724228354; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jOO3xScatAPPPb8tw2FfV0S/NtjYDESd+MYV0EHgGGs=; b=P1eBtkWe/G/itYLAShGYn1CakAw52joJ2XpmC18uTsb3O3soZaTlUI8shSXvsKtimS67je 7Aegxdk5F/L9gr1//2eMmlRGPv0EaZ4/5n0tdjStXo1pYafs3iD2+1bAdsrUP0uafgAxeo TJtoHtVvr2NPGsmxQErY1RsxG33jacU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724228354; a=rsa-sha256; cv=none; b=J2KdnNn6CU5EwDPwsKSAu0kXcTGJA+KgUhv7vn2kDxrB64pfgLn/C1RvkhH4O/vklCUTG6 ihA6rfX11PDASqdpweMwXwHDTPLElpIDew5qSWYZUyKAWpV8Hm0KtT387wWGmGy1V9AiXs KnFccX7GWosHasBtHqexo1YEz5/amTY= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=ghE5JOPV; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-713f3b4c9f7so2304158b3a.2 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=kvack.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=ghE5JOPVfe51qYDOQ7yFdkh2hMuenpFStFrijxpc0LSGa+aGhTZkrBCSU5VJuOqjfP BgnTgofa9MXnbdbuTTFu3vUn6aInuQvgcgS5yxoFIhvoBakiVd5vAMNoJb0gZMZougUP gnM1JOSb4kyGDWsmDKuoYTKyVGdKWWe0FLbR1Mm6IvRhYUUZIewwPCFRoRq/QFzT9RQI 2UJGZyQC3NR7QUufODq6Z/VDARm8MuRoKcltziCRr7D4U4QpmfHnaFtYdVxRYuMaFOt4 bKALA+EauilScyWyiVVdGuMTKPMbBEPksNK5UGiLS+AeUyMKUgzwOZsvI5/zKbubLEU3 ZEQQ== 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=FH2WD6Tr2whDzlHjKIlFyBrdh4ulC3SK8eiOyWvgEd7dqqyx3fvP5+5JmYSGNiptvi RnHecirssObC8wGgMWQncxl5Oxsyg8/qqFF90WqfPu6cCr5VWYP/+UhAJnriDPB84RnP 4h2ThSJPTD9K0jqXZgprYhSbSahhLEHwB2z8ruthDnrJnajSAW1k2mbmNsRCbf7GA2vK 0AU31l+p/Vm1svQhbpvcD6NgpcYCy0F/Gt89ff+lD+0EhCTsG4vYBXmNaiW+lXfZKXxc Q4AO02pCd0FcHA5R/9lI6NvSFrLYOsGzrlxS9r4jgDQrEztd/0fgB1CFWXP18L5w+PvJ 0U3w== X-Forwarded-Encrypted: i=1; AJvYcCUCtWsUndAsY/lWjaPrqC9ZeXw8r8wvjmnloeYHt2ErbIza5cctRRlYcUe+D8Uj0JrCbtlvgV9YXA==@kvack.org X-Gm-Message-State: AOJu0YzDOLUDz7zct+0V60u6o5p0ULtRU1XHavTxflOo27IjA/eSPXzo M1AFCCweKyzSebBV3rZOtZ6jmAdCY2hhTgDsArFjcom+fDWwEh8PmerRqzNGUss= 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DFA0540004 X-Stat-Signature: wzn3t7q5p843837zhb54ockc1faorud4 X-Rspam-User: X-HE-Tag: 1724228442-391719 X-HE-Meta: U2FsdGVkX1+RtLuQCg+HYgFgidhSJOxbhV8wanNn1ag4GfMKaiAgDvHTPAuvl90MsIp190pb8G90MQlgT3zfE/FNnw3QSxxObd4JdjmIsF+FJZXrAKE6tZwONaxS6nKZ7p++XpwH+TYZcvmjEjqhZV0A55pTl2qfRoTlCIRFJwxIq4DC4MvUk83jGOxu9r0OtZON+oVsBOAWnmfeY8llzug0d3UfCa+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vjMPc63wL8bbI5xJGHDiqpAsyRLiiPbqsgyDpB8OFPh57zn0YtAugx9+Ai/GLWMWpuV+CJkeZ4GimRRljXYRGq6j9/JiA829KIreBIz62nY1D0+k02OHRG0VLkasuQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000015, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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