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: 13772832 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 BFB95C3DA4A for ; Thu, 22 Aug 2024 07:14:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C511A80009; Thu, 22 Aug 2024 03:14:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDB3780010; Thu, 22 Aug 2024 03:14:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B8F080009; Thu, 22 Aug 2024 03:14:37 -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 77D406B00AA for ; Thu, 22 Aug 2024 03:14:37 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 27F63C1311 for ; Thu, 22 Aug 2024 07:14:37 +0000 (UTC) X-FDA: 82479018594.25.FBB51D4 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf08.hostedemail.com (Postfix) with ESMTP id 49BFF160008 for ; Thu, 22 Aug 2024 07:14:35 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=a+pDqIvP; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724310785; 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=lG9D96+xW+VlDYZHTIMi8bcfezh9NEOiBopQjA6w29o=; b=QMOSesPyWHuAZqwViBsOGUtOEVTbFQpwp75sz5vY+0j/gvgqBo0MabWsU1h4IRSgr3J5kO 8vHGhnhpah6c/3wfKJeLYenXz5MSmbJ8e9Amomdfu7nZCgR67Nq0zHHD4y1AEjm1/S0J83 p5iErjG5ZBcFaC1Kwf7xqquClsI9S3I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724310785; a=rsa-sha256; cv=none; b=kXfPMcbB4DwgFmUk7bTBfi8PN6EPTIRPOI6yPkLJZgk0IBLI6NlLNxUdNsILBMkGJ9c5af /b/j1bcoclHya4sd3WYSadlCaTkpXBo/xaXeRUIjSgdR898Ng4j/tKdgGk5E5K0kX6RMAF zr2ZxM1DV6WpyugbYK/1H12WKIrDbZo= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=a+pDqIvP; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-713edc53429so393938b3a.2 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=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=lG9D96+xW+VlDYZHTIMi8bcfezh9NEOiBopQjA6w29o=; b=a+pDqIvPCxsBqzCvWy5kti4DLMAAHWZl0x7Jziu/FVPA2PYkf2lflYG4//NLuW5G5I Y6/MDBgqGBUz2tttr08+SScWdHjZc8ZOagA+HChHPdWd4IMJbsk4zgX8WGir2iPtu3jF X+m7ANyr1CjFjH4BHHMWRq/f56oTly0Bm2eMwUXhXKu1L83n/S7XNjqSHYBQAM+//20K NuoDv6myrZPgH4nlWiBfNJqlDscIDt5xNnu7abbYpjC0SvSvyOx2jOa/JmLvfSuUd7jQ qPnOchx2HovPbfLDGq5fSdFj5SsaAjIu0fDsowz8jQpXQBFneNp2mbwFyr+Z7cllhOXI qcOg== 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=jupWh6J5+Uzeia+b6JW9kbfaA1M4NpAzY0ZoAAUJk3c877Yw/b5FxpOGmuh2UpZWcm DYs5s5IRlnS6X54kpd1I8E5736HU4Q9dgFZV4MFoHvCY+Kr4/wXY7eyZJS7hqWaqW+tI Xl6PV+ftTmOghjGeEbJTvfrgoJufEykUhF4CZUvIzCHrm/S4l7bUFPovjaX+KW8LR9Cf MQQa69R+sEW1oGCnWU+74p1TpChBWwV4dSh+208JitcBDq1hK1IkmrS6MUMcy7VuZRGw GNt/cMqzrcKx9XnVbt7b+/nVVLxWtldfyIFiXmt6wFbJ9n1MXKOmbeTQvTXoRCJ6i7Uk lJVQ== X-Forwarded-Encrypted: i=1; AJvYcCWl8oY3PCEaaGEBRz8SATg22GYT1u3Ok/7iP+vqaNgegG3l8gjeG+f43P/h1Llpu5I2Z40aOUrQaQ==@kvack.org X-Gm-Message-State: AOJu0YwahGbUSA+YjywyXmffqFf3WWpIUkCCbpc+UV8NuGYn0v9jmi0I zW2Nr9VNyEf6OR+l+7MtN7EhYZzIaqJsheD8bg9jL/Opz93sf8ytlHHX7DHiJU8= 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 49BFF160008 X-Stat-Signature: hr89kwa8eqc3i1nxnph36kab8nadyd8y X-Rspam-User: X-HE-Tag: 1724310875-380414 X-HE-Meta: U2FsdGVkX19iA0Gdgdrg65xitlGzJgNn3hM2ifJCQFX94LH7xPPztaU8mR4aFE8553pHpqy0xzK59rdCiz9mdZh2R9CxIyFKWsMr3KNLrikHj1tuJ2eIz50Bc295+aIFR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L1us0+BPNmpXoKmiG/5IvUgkvmirQQzZ7Jf7V/2DT8EYC6T2dG0XB7LZhQ+xZ4O4KYOy42OZc5bkZhrBG36jPuEdYomWVKgK0BGVLp1RQ19lJVbgkS+vUQnpWYhWpSj87W2M6Bq+seQ3JQN5H1e+qVFXEeqLaki52usCVPkeyBo8bVepE4RA+xzFssl4YeQLQunQRWoliWP9JuhKoMUhoUaPrcEoB2tXi X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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(). 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 */