From patchwork Wed Aug 21 08:18:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13770991 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 667B9C52D7C for ; Wed, 21 Aug 2024 08:20:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E5D3C6B00CD; Wed, 21 Aug 2024 04:20:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E0D476B00CE; Wed, 21 Aug 2024 04:20:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C85AA6B00CF; Wed, 21 Aug 2024 04:20:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A741D6B00CD for ; Wed, 21 Aug 2024 04:20:24 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 295C440A67 for ; Wed, 21 Aug 2024 08:20:24 +0000 (UTC) X-FDA: 82475555568.22.7889C8A Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf16.hostedemail.com (Postfix) with ESMTP id 4D09A180018 for ; Wed, 21 Aug 2024 08:20:22 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DIpIi3Km; spf=pass (imf16.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724228382; a=rsa-sha256; cv=none; b=AZkEcOwKv65mlExqO/5QBpJVdpFE+j5IXBjG3x90FqvcIkZ7bi+7SS26st9PPVTyj+f1lE 9oJjLItp4pm5blkkEF7t9lJXJQiiomdLW6dsgpvOSKtzMGcFOfO1wGfYOAdt2eNLZ5VVYW YuAU49j9R6I8ShurHM9Rcax3OagtFbY= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DIpIi3Km; spf=pass (imf16.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724228382; 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=Ib2peXsn8Xzv08d3et99PPledeQt2suHPjEB9mw45Nc=; b=gnPKYe7v113wCAJzruOF0EHhL7AwAwyzcWYpVALP8R2gKv2DiOg109nPx0M8W1sDXyHlLV /HLDy78mOkFsOjwPppP2fsMyb5OqJJkk6BExH65j3KmwICeZkfT9ubVgul/p2LC+JfCwQH C+JcxNFl6QwOocV+Tsnj24Ykk5AHITc= Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-7cd8afc9ff3so221234a12.0 for ; Wed, 21 Aug 2024 01:20:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1724228421; x=1724833221; 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=Ib2peXsn8Xzv08d3et99PPledeQt2suHPjEB9mw45Nc=; b=DIpIi3KmTTTvjlzxqPDbyah8JhGwEp3bwMN06POXmLMKTTNTQJYoqTwlltnuGWW4o9 472EfzF93R8xqjr/p2BSX3CkwXj1hTkE+EYKTayDpExAH4D9lnCfgK9TlWa+Ne+9CjuR wxXKiWFONPO5sEwBIhHLutr4bR+yRMeDXNFiIisp5LI+bgGyF7awEcGzCDAzbswwcVqE kFZ9VoD836R5vKvX7kFBUhmR6IU+brhUWKNR4TnaEDPBdoiQfX/2tWhoU5rsLXNeV5ZH 2mywZF0Zm6vs7a8hI5CDegQwixM2rsCDpTp2GBwwAktKrT8B/bQeMEk1fCpnKDqiLsTK CbjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724228421; x=1724833221; 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=Ib2peXsn8Xzv08d3et99PPledeQt2suHPjEB9mw45Nc=; b=hv+u1ZsXFCkRhIVpUFCWZdZQTEXXtp7WfaOkt7uk5R9yUYZ2vVei7n/fn0iDG8gebF SHNV7WvPW/sp7CKNOcibX6Wzjkn79iYM8RIEXDM1x/uJ2T0u4k+GlzcoCvOd3clVGtBM xAAuCjj1G5VdWdd1+YYX0lacDEkBD4YLvocer3CZARojOBxXwwj+Q0eYNlSlzLqY8N2/ Lbj0cMpsglbP6/3uy1C5Y9RjaIv8VGtPczbdTAwaR8PvYkE6qrREzqPH4pf0Mq1gOueh o0yEXiIt6oJuaMXAHJXIHh/X6atPPBFnDPMT2OJBgbkpA+YU/5a9Ybzt1wL/mSMnlCLW 9Cqw== X-Forwarded-Encrypted: i=1; AJvYcCW9PAJGV/uMrVRtW5H3MGpuoYs8i8CEp939Y/RTb+9s7o+gbel/CyT3nFQxjeOiITM5ZwBKivwrxA==@kvack.org X-Gm-Message-State: AOJu0YxBSu+M7KCuHl4bWBUIP6cAgEs9ACOElyrQB9t3a0+1CmPdSjLp jqmZMVmvIKAkhnxhIUEF412/fnj7Pv/JExjlXzmUVrdvB44+6E8pM9R0qkwKmhQ= X-Google-Smtp-Source: AGHT+IE93wrdhvj1jPWy5zvxTPwSbhlcdosDYnf+NOlDda6ytSjhdKrpXWKVADSrOUal4AF7Aqrd8g== X-Received: by 2002:a17:90b:350a:b0:2d3:c084:9d93 with SMTP id 98e67ed59e1d1-2d5e9a2f0damr2610948a91.14.1724228421082; Wed, 21 Aug 2024 01:20:21 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 01:20:20 -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 08/14] mm: copy_pte_range() use pte_offset_map_maywrite_nolock() Date: Wed, 21 Aug 2024 16:18:51 +0800 Message-Id: <05c311498fc8e7e9b2143c7b5fef6dc624cfc49f.1724226076.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-Stat-Signature: yg79zhxzxm57urh6jfbsxmyc6yw1dkin X-Rspamd-Queue-Id: 4D09A180018 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724228422-920983 X-HE-Meta: U2FsdGVkX1/cbYPqHmHQrlATHNKPNJH/6kpMHQSueAoKIEt6XDa+v2WuZvlirp1tiMOILDdzP44J83LbVSp30bmnf5bOuwDLncpAO6aT8VPzFI9BhPShHPtdcgm5BPO2hlB0RrCPdU0tqjAtMZcBA5fK8QH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g8iKSsfrrQuOIJU3XRO852DL32k1IrcynHQNwR5D1gF7BVdCet57a0Ty0pc71CcYEyU/A9B9y3PBZFi+HcilhLy680hzr+bOZtcXJckiR9r6FHmihlbZT96UCRh93i9gPI8e2oYbJzbPPjStF+nbRXFpU4/1vnC6N9R1Z25LK8vyrLdPgHLbAtaMZPlVuiXgGk0GmAa1wo/VW X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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 copy_pte_range(), we may modify the src_pte entry after holding the src_ptl, so convert it to using pte_offset_map_maywrite_nolock(). But since we already hold the write lock of mmap_lock, there is no need to get pmdval to do pmd_same() check, just pass NULL to pmdvalp parameter. Signed-off-by: Qi Zheng --- mm/memory.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index d3378e98faf13..3016b3bf0c3b0 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1083,6 +1083,7 @@ copy_pte_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, struct mm_struct *src_mm = src_vma->vm_mm; pte_t *orig_src_pte, *orig_dst_pte; pte_t *src_pte, *dst_pte; + pmd_t pmdval; pte_t ptent; spinlock_t *src_ptl, *dst_ptl; int progress, max_nr, ret = 0; @@ -1108,7 +1109,8 @@ copy_pte_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, ret = -ENOMEM; goto out; } - src_pte = pte_offset_map_nolock(src_mm, src_pmd, addr, &src_ptl); + src_pte = pte_offset_map_maywrite_nolock(src_mm, src_pmd, addr, NULL, + &src_ptl); if (!src_pte) { pte_unmap_unlock(dst_pte, dst_ptl); /* ret == 0 */