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: 13771011 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 7ECB4C52D7C for ; Wed, 21 Aug 2024 08:26:54 +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=Ib2peXsn8Xzv08d3et99PPledeQt2suHPjEB9mw45Nc=; b=zAlRey9B5LdPZ9/z3IBGLSdr6k KdEyf9r8G4NT043bLFXZlyTpMl3OeWCl9zgERBzcNCgX964Bg4JvYupNcpskwlE2QAe0ZfhhU/lCc aDdzpf7cuubpWx98py+V/06aRbYNOcd/+6Xxvk242tFSSafBSM4+oj9C6b1z0vbS4zgLNI0UbI6Lt X46u7imwK0GkRV2AfjcFlTuDRB3K7sEBGpnP3y1smJSwJ23SHDAr/PWMDmO8CofC4AnkyN+n64LuR 324DZqqaNIrnmUrVEs3T36hYZ5OXrvMpDOTfkMRIqRvmo7C+SajRzdwXcC3mvTqOTw4mRwEjHg1Mn /nAuzCHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sggfx-000000083T1-0GkT; Wed, 21 Aug 2024 08:26:41 +0000 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sggZp-0000000822z-2ZV5 for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 08:20:23 +0000 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-7cd8afc9ff3so221235a12.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=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=Ib2peXsn8Xzv08d3et99PPledeQt2suHPjEB9mw45Nc=; b=fJKw0ZM7hi1YxIHUEFLe1oZ0iTA20XknAXxqQ9BxPk8/iQG5o0/s/NHLG2rWmj0T2U SrfVd3Qid/41PtwMQ5TWWlqaJbFTJtw+d+shMLEzafR/F1JnM3getDcnSAGrXGKdzAVH EAifPRgy19hQgMVk9BolrkKvYD1bipS/wqm7g/Fmn5ug3RYhmc2Rgo+fHHfv1CVKoc1F AEQbXpSIA+tQYsnRSSYHpxuURdqq84+QbsfO1MSHD4Ig6pSUbo7/UPYeheuPpI+1H8QI WyjlVzWgNbveGO0beRrpcYnfxrQCwJppMnogewMgkvxNAP+aY4EPe2Sfc0IY3m5tqFsg TxJw== 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=kw/nroaJogc2X86cDZaQTWwt553CqN5ngLREdQP0dGKSU8GDjibUezT1eSE+5Wn0mm Nz3u4cRAzLW6dFtBQZuRS1sKvH2P3lbN9nuDK2Uwu/MbglptY+bdJEGmeYCjZl+T0UVk kYezv4F8JZs7tYurERK2+CFsI6dg2Tuh00nqbZy8yRO42aQxqPKSXtzS3G4yFpwFM4d4 cCz4iMU90yF2hEAfjX0Q4c8eHLe40EqRcp7MDgkYor4EsykVUoJzZM/iXvWn86pxNxBr 6VCTguWP2I3qn9yVid2sZJE1lVSR4m0oevUDW9ReUsHqjF4KhaLyxyu23vvMovdfE1Cf wbFA== X-Forwarded-Encrypted: i=1; AJvYcCWXioDb+MLgNMQWr7iuhtsBR1FLhneK+6hR08Jhsb212w/6/4hXOyJy68C/IaJSVelnDGD9j+t2GZ88H+DuUCXI@lists.infradead.org X-Gm-Message-State: AOJu0Yz5bdGQME+Vz10J50iIP8viHOuVPiHjtB7YmgC0TWbVOtM18XRG BNmfazgdpsvsoHLqQsr0t2Y/Dj1VuccvJSq2Gt0A/BkZyPdnVrcn2k2bzbgweWQJpVD6Jf0CT+F I 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_012021_679741_12DC740B X-CRM114-Status: GOOD ( 11.22 ) 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 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 */