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: 13812864 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 1A771CCFA07 for ; Thu, 26 Sep 2024 06:47:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACD146B00AC; Thu, 26 Sep 2024 02:47:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A7A876B00AD; Thu, 26 Sep 2024 02:47:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91C366B00AE; Thu, 26 Sep 2024 02:47:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6A86C6B00AC for ; Thu, 26 Sep 2024 02:47:52 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 208431A0681 for ; Thu, 26 Sep 2024 06:47:52 +0000 (UTC) X-FDA: 82605959184.16.10EF040 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) by imf06.hostedemail.com (Postfix) with ESMTP id 42B41180004 for ; Thu, 26 Sep 2024 06:47:50 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="HTA/+byd"; spf=pass (imf06.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.222.173 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=1727333150; 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=3DwHdqVJkGu7HChE1YzlDZaDZvpQCVqvAB2HVgACkHs=; b=6s/moLFSzAW9OC8pfrnd9xYX3p9TCJc4xdY5T1nwafQVVahlVle0UThVqohaAPVuPrS+FQ t/v29Z8ZWcyLm92f6tw5igkrkvGQpjjH6eXn6ZhWzvGN0wKGxss8fRJopcb6q1zDzH1KPH CKdBc7awZBDcs36pVJqa8QEaRe2moe8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727333150; a=rsa-sha256; cv=none; b=ozXAJZyhXhFe95MNq0MdKjEkncDv9XNcY0UKUD8apnTWC1ASjl+mwoZIfET13PZZOTSzow yD6x9oMoD3n6V4UBRLmNgDRFMBV3ix1JPr3vlZ9LlMpw9ze1Ne20j7UytMAUglZ7VR1toX xvBH3WJagvXlRv5GUEhYQSD6IGTyctI= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="HTA/+byd"; spf=pass (imf06.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.222.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-7a99de9beb2so44969385a.3 for ; Wed, 25 Sep 2024 23:47:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727333269; x=1727938069; 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=3DwHdqVJkGu7HChE1YzlDZaDZvpQCVqvAB2HVgACkHs=; b=HTA/+byd4aT4hP4ivk+aM5+GkOiGlu9K4Y+qfn1SEW6SDjh79qNnaaRdCalgsxYQZb GzzoHiiBddUGHrLDTyLT01OboU0B/QmyR3k8taWiUZocNO1JVVRkmabR1Mb7GDJytAC+ gggzMYT+ouaVcQuufEBprHfED2sXFW7ew6jh0Q9NkzlI8/Acw0cy6KE3k6nD4i11g1Ez tIJiL8hVEooiZ8PpkMbRJt+l0aqMSwfm/x4736cToc8VGz4JB5G9EKOB2SeOwMwnnd2v xq5RGyPQoL/k0auZizZcyKiqp8h97WbR0F51GCSAoMMiCjNhIaLSHNtiUCKVB/nqW1LX I/bg== 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=sCJA5S9XqNfvsTmvZ7dDkWQ50gCqWrA+lLdFOnO/Yoj1KA/v003MQ960yoAwkSsIMI GTo1HRAh3AugIqC1Sn9JU7dfZzro456qAlhDLWGzYZdzJA2yx/UeNbGjUiXkXsVBtgRL 0KgUdS0jP+kAWP+PxFNKIHlflReVfBIfJ7POJEglXkiUVm8NjTqsAs3HWmyPKBUH2Yke 38zO4HvpqL4GTQAAuRI7eIclUhF8MpdyTy+NtQuYemWjUf9C5FiwRtUiLr288LJHqyep IG4Z+3ueBF9s+HN93S4ZFmmZlRl1JZMkxQikMHJ6kVbEDKWWEn2gGgMS8/b0Tw1w9/4A vd4Q== X-Forwarded-Encrypted: i=1; AJvYcCWW2nbtyVdmkLLzYx015zzIFGPTaaoYdVeTNrBYJXLt8gajz6rwhCuZOHy3/f846QITYV1n+1aakg==@kvack.org X-Gm-Message-State: AOJu0YzIsW+v97Oh+c43KeHJwd3Q5Sn0PbRAIuZ9oSioW6dOClXj6LBl 9Y3BAQOZY7hLYs0+OH6ItPBEEqwpSUqlqUC280YqU8YYp+y8B4bgdtQ0ii7y0uE= 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-Rspamd-Queue-Id: 42B41180004 X-Stat-Signature: 1jkbktpfzn483q7ryd7xcroq7jusbttb X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1727333270-619511 X-HE-Meta: U2FsdGVkX19+184xlCAdQZGxZjN0G3RZo/wgaQ/lGgYSSV+lOAesv/Pz6D4VHmMZB4GRV95HzgCa4+zqx6KGCs0rZ+brUIYNFvjIODf4u+8/AViLXvFiJtaOzp/GIwY11kgxzYJcKfKxy1pVBS8ehiXZacB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MbsrzUON6R3J6WjosdQpZJx0uqP75pJ7QqSW8qoVo64PUxYuo10H6ICpQOqJjmdx9vEQUXQ+RhsXbqCRkNiiD0ziJtTztZjuIvnGKIT4XcMIv9K0bIkIu+xXn/c+PSVQn2Yip5FrWAWPWi42z97Z3up1yRKj34WBQRpz4TGFtF7Ipa1TNwAas2mOAWajJbWwVJRA== 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_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 */