From patchwork Thu Sep 26 06:46:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13812890 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 794A0CCFA07 for ; Thu, 26 Sep 2024 06:59:07 +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=3DwHdqVJkGu7HChE1YzlDZaDZvpQCVqvAB2HVgACkHs=; b=4MfFxI0zXps0ZxZ3EjyHMuNk/3 YwaHILPHri7s6LoqbZYK0QxQprQsHm+J2mS+sObAIFt902ZDykm3FNfQYsC56ShjUpUhqdq03vzB9 2xt4oY45Q5Upihqgqr8AOSHARXhH+8QehOa3L6pVjg5pZXJGjrznIIYaUPzwLDyekvOYm53LAR/Tt Xu2prVwiOseJQQWDVYG5sXSdT1ybJ5ygQFmjtbRcMRDhVrWLjp9Oid81I/W5Ko5wbL9BB7J6da/4m jOqyVpSJk9IJGZPeZjMFMTlEIbERAR7MNDSi3Mof35xyzXPzrzzuc80tA7gqLHt7cRfOLRIWswFBy TdxH5vPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stiSl-00000007QM2-18j8; Thu, 26 Sep 2024 06:58:55 +0000 Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stiI2-00000007NaF-1Bh6 for linux-arm-kernel@lists.infradead.org; Thu, 26 Sep 2024 06:47:52 +0000 Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-7a7f8b0b7d0so34240785a.2 for ; Wed, 25 Sep 2024 23:47:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727333269; x=1727938069; 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=3DwHdqVJkGu7HChE1YzlDZaDZvpQCVqvAB2HVgACkHs=; b=cpboEdH3rBEd4AkuinfKjCoIptNyB3usKxkIVM5vv6pOOdgGGre/npl4cZVqWL/aft O2+sw8H2ooaecGjt24/ttbtSZxtLoHVseuGaUliz3E1XFZIhJTJr66aNJAP6pHHEpOSr dyuJFtu0H30FyqogMkR5CgK2rQ5JSA5PswYk5c+KxR4G7xCFGOBncXZ02ds7y/s5/2b5 3aZ/eVW+6WrP5//OEycvttv3GYEYEDkAGWRaYWKHFKFk0pUiuC58TnOwgfxB1CfV6vlI Bswi3dP18wZLWJJXEncC6gXfBoqKsONQ96IUsAm7Lph4IQ3GXumvNjjT63qijtMc2aGu HJuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727333269; x=1727938069; 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=3DwHdqVJkGu7HChE1YzlDZaDZvpQCVqvAB2HVgACkHs=; b=oMaCw7sqeZMpNSuF+mpnLzjm5RNMm1nj03wgcajg4Y4k9nvVNrG83YFyZ2a8OhtYb/ /kORGUVKVkMqO0iUTbCLuR800n6B2NESP+wTxskOYJMLivFvUIiE3qGGu7DgKgEtVwN3 khULRYky91nA3JxV+AQ2m6aNw93j+quWXPBrYhYDWSP8+xmpGsPp54OD7g5gOmmuV0ml Blil4u/D4CMGyxnhorU8HU3fazxAbkOsYFVs4ZrUisRXr3Pz7liWSIZ0N3dQfwg7iZpB KtEoYFM05pg0CEvsmOFzh27fLBP5uJpjkaAJLCcYlBVWl+CspMh7yOawmsgDbsZuahOj CXqA== X-Forwarded-Encrypted: i=1; AJvYcCXVRNewBt751if9LPWQ0pWV5Q6SVfSV1dh6ANvKfrT0WYGglrTpM613VCeaBJuDoug8iZoUx+i9KpioxP1NYxK/@lists.infradead.org X-Gm-Message-State: AOJu0YwZQ/KFUQpk91AQkmWTqYy2pMP3nl5OlS6/gVf3KDchFpkkFeD2 UNLFMPuq6+cwOSMwUyYVod3p1rmpiAojLbE5RJ7J2k/NAqzInmMDIWHYLbDFSkI= X-Google-Smtp-Source: AGHT+IGf6yhFgM7V9dSkmNMD310kmtT4NpPr6tml7YSLsMbfjuBNhYOZWImI0+hdwHwJZd31DH/Ogg== X-Received: by 2002:a05:620a:4009:b0:7a7:f18a:e46f with SMTP id af79cd13be357-7ace744e486mr712325485a.43.1727333269291; Wed, 25 Sep 2024 23:47:49 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.150]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45b5257ff1esm23024611cf.38.2024.09.25.23.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 23:47:48 -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 v5 08/13] mm: copy_pte_range() use pte_offset_map_rw_nolock() Date: Thu, 26 Sep 2024 14:46:21 +0800 Message-Id: <9166f6fad806efbca72e318ab6f0f8af458056a9.1727332572.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-20240925_234750_499960_68F867F3 X-CRM114-Status: GOOD ( 12.24 ) 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_rw_nolock(). Since we already hold the exclusive mmap_lock, and the copy_pte_range() and retract_page_tables() are using vma->anon_vma to be exclusive, so the PTE page is stable, there is no need to get pmdval and do pmd_same() check. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- mm/memory.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 6432b636d1ba7..c19cf14e1c565 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1086,6 +1086,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 dummy_pmdval; pte_t ptent; spinlock_t *src_ptl, *dst_ptl; int progress, max_nr, ret = 0; @@ -1111,7 +1112,15 @@ 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); + + /* + * We already hold the exclusive mmap_lock, the copy_pte_range() and + * retract_page_tables() are using vma->anon_vma to be exclusive, so + * the PTE page is stable, and there is no need to get pmdval and do + * pmd_same() check. + */ + src_pte = pte_offset_map_rw_nolock(src_mm, src_pmd, addr, &dummy_pmdval, + &src_ptl); if (!src_pte) { pte_unmap_unlock(dst_pte, dst_ptl); /* ret == 0 */