From patchwork Thu Aug 22 07:13:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13772873 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 12C74C3DA4A for ; Thu, 22 Aug 2024 07:21: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=lG9D96+xW+VlDYZHTIMi8bcfezh9NEOiBopQjA6w29o=; b=F6kOPUmEePGMU/YOehRRkOOAMS Yd/x182lJnHAbxMhXkJ6XCTPlfn6c0ntpcHpuTo8IT49R9fyxayCv/nuNRotNI8un68xdYZDsvhI3 K4qvyM9gMV+WUAR1qCMn4rhIxgGANDTL6IiCKPKLuS+rlW5vIEGHQs7QfTnO3miBU8/qJGJcKRgNA mMYyLvy+dQVYQaSdS4t3n4nOYMowCpMZxo+bu66gqgJ+AOwLAR4NyfErqQr3TvlB5tJ9EtT8hLqp8 MAdgIEpM7xVkY6qBecs/CDQhmmUxaEGUhdTeUluul2pF6vXfOIWsl+fhHGftiLhzczHPPVG4M5Sk5 IVxNb45w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh27t-0000000Bpva-3mpR; Thu, 22 Aug 2024 07:20:57 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh21j-0000000BnBi-0QOR for linux-arm-kernel@lists.infradead.org; Thu, 22 Aug 2024 07:14:36 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-7143165f23fso391262b3a.1 for ; Thu, 22 Aug 2024 00:14:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1724310874; x=1724915674; 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=lG9D96+xW+VlDYZHTIMi8bcfezh9NEOiBopQjA6w29o=; b=J9ZGoyH3FDkynMdnMZSg2Ae8mLxPV5ZxcsvO6TnScqQaWnKfe9DaDsKKEZTu/6u4sI k0ta+02/lcRY/y5M4TnwfRQL9hnVrtEnk3x9hXImAiA6ftl1kv2CQBZlC8DFsxEunNbs OabP+Jq5kIjm2M2tARwuKpVdzxKQ2Gfg6vYuzTOIL/jASLlupdh/6EJyd6Y0Tnh3noer qncwDlusnTE0nKZeU/6knt9d0sUkwOJM5iic8MH7BsAT3KrxgR579rxReI8V5gyl+N/I egagFt+hn0TASStXWQ7Z5QfFoZuO1OwdEOnQafOT29R8YeumvUp18caUJx/7/LPjhoOj Qv8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724310874; x=1724915674; 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=lG9D96+xW+VlDYZHTIMi8bcfezh9NEOiBopQjA6w29o=; b=vMLnWHIwqom8a1makHHmi9GRdZnmPiJfrLKer/rkebR+tixT8I/oJGZyMtdrPPqGR/ vK3jXyYxyXb7/Rtf9ardERTtOV/2c7ZZwsvMQaXYbpoeoG1IZoXfYQrcZTyw8aAAT1lk e/4ci7lIvmU40Q/8fyJuyjGh9kZe8OQp54v0CHq3F5IvcAVXsoTZ8hkzDTwFUf15Htxe kZ7EADgGIrwj04BVJ41sRYKIQPICo2AKyfPyj0QuuzLtSV0VGaRoviJ8GgtHa4mny0zJ z4LQSkC24/dL96SC8vkFUYbUGm0drKOdGz0YGQPybP1qG3MhfB8fIBou/gccfyZFtYLZ 8L4w== X-Forwarded-Encrypted: i=1; AJvYcCUU/+xaGVFszQoTZ8AI/IE4zXus16VSr9yrHCoen4qO1/SX4ecdOuUKZFVXkw+pmU+RMsigeFyCWe8jg+TWvh4B@lists.infradead.org X-Gm-Message-State: AOJu0YxfgHvYbwUquo+6j6EXEpIOV4n0ja09/0seU/ILplqBMYen2CDd XUqMpomeI31KRPnCN5NVS3+xb4CN7E+cC9OXUZSSwspVeG9KyIpJw7I0B9k+mDk= X-Google-Smtp-Source: AGHT+IE1Azw7tBspdYFUO9+EydXCiNKc3KqrNzafyoF+69WNl4yC4JRDYA6cJOAAfX+V+yHVonAuzQ== X-Received: by 2002:a05:6a20:9d91:b0:1c4:f209:f1ea with SMTP id adf61e73a8af0-1cad80f657emr5853305637.31.1724310873985; Thu, 22 Aug 2024 00:14:33 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([240e:473:c90:f96:d029:ea8a:4e6d:d272]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7cd9ac994a3sm695095a12.16.2024.08.22.00.14.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 00:14:33 -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 v2 08/14] mm: copy_pte_range() use pte_offset_map_rw_nolock() Date: Thu, 22 Aug 2024 15:13:23 +0800 Message-Id: <71100c3867c4cf6f5f429ce9f2db8432066d0e99.1724310149.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-20240822_001435_159734_4F9E7502 X-CRM114-Status: GOOD ( 11.45 ) 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(). 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 a dummy variable to it. 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 7b6071a0e21e2..30d98025b2a40 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 dummy_pmdval; pte_t ptent; spinlock_t *src_ptl, *dst_ptl; int progress, max_nr, ret = 0; @@ -1108,7 +1109,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); + + /* + * Use the maywrite version to indicate that dst_pte will be modified, + * 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 a dummy variable + * to it. + */ + 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 */