From patchwork Thu Aug 22 07:13:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13772833 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 2D4DCC3DA4A for ; Thu, 22 Aug 2024 07:14:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CAED80011; Thu, 22 Aug 2024 03:14:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DF7580010; Thu, 22 Aug 2024 03:14:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4D6080011; Thu, 22 Aug 2024 03:14:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BDD6F80010 for ; Thu, 22 Aug 2024 03:14:42 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 52029804FA for ; Thu, 22 Aug 2024 07:14:42 +0000 (UTC) X-FDA: 82479018804.15.B70A9B7 Received: from mail-oa1-f43.google.com (mail-oa1-f43.google.com [209.85.160.43]) by imf15.hostedemail.com (Postfix) with ESMTP id 80D06A0023 for ; Thu, 22 Aug 2024 07:14:40 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=a48iCGNr; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.160.43 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=1724310801; 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=kCwbwV/YmKb9rcRCZPyi2vEyGZwxl6QKnoBllHH347k=; b=y0F2gssNENW4OinfjDw4+GfLOu0ArGQy/0hsdoB2+jx2w+hBDkbP8cgPacSvkOwjclOq1d +LJJEQrTp+DgWJPhDhnOHLFdSCS1wS5K/Iij34HcGaz+QAYcbZUyT9ziooNAHBOb1dv9Zz /YXEndT3WGEW9VkUIV8RY9B2NBFH8bw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724310801; a=rsa-sha256; cv=none; b=VX97/o1Dc8S2Pp3NovhtltXDlQjzGY7GrqsaaadEjjtjW2YrkG4gB1m6miesJbV4PPnBLi KaRLIox5lWiNwoUgGFb2ao+JAfE/jdn1iEuz7MoLoH4gNshlw93rLdDIB8TPYgY2ViYR+i Kq3L4wc/aNHvS4QVV9aq+PqboMmzXVM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=a48iCGNr; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.160.43 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-oa1-f43.google.com with SMTP id 586e51a60fabf-27012aa4a74so250299fac.0 for ; Thu, 22 Aug 2024 00:14:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1724310879; x=1724915679; 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=kCwbwV/YmKb9rcRCZPyi2vEyGZwxl6QKnoBllHH347k=; b=a48iCGNruWrskqiVZi6XSEg/8YppD8YWqO3YAtYG6guhUO/bbwo9/9ulMTvfjIo4Pr YBmJ06S4hzq3oArnA6q90geGipRoPCtkM9aEDzKDCZoJFERg6STaqdP+D0HMCbtfMYUz mB4ug8LFsgAX2glS4ilwyeZJnAQJlDT/EEVfhJR/xx4a7yZUUWmLty0JV3svJCQHzsPQ bHwE8Vmt0k5J3LrqDD6c6/MOhZSm00Ckk5Ri3um4jaKUZZMxiqE+cJ9DOERLgb+EGjCV VdZ0u7CugEgl4gjlieIBZc6tdNjRrcEiF1Vt/dWybMEKdsmvG/WPGJmeGdCOYKediTED ZUxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724310879; x=1724915679; 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=kCwbwV/YmKb9rcRCZPyi2vEyGZwxl6QKnoBllHH347k=; b=KZTlnUgwtAE++UYNhAdB0XucUPy3d2XIncHcaxkCcnf4S6rwdz03OhdJhHfEzbKpBQ 1ljrC/rXxteRoaLgkdrRzsOx1h9SLNNj0Zk4DUgEYZMC7e7EkaDJVOJturPpwe0HY1Pc gXO4B4JDPrligFX/V2PXDv+Gn+h1vNZy8hBW+8usVn77294FOo6h5tGB7MkXp7p54dXf SnCNcCcY569C1LeCWGgFXs51gpmKJlHuo+TdUHmDcKyOOctflYx2Nqjwt1hbaUto4JoT 1xlQHnawATx+KYoQbTGgJZkkXYWhbuqI+RfYCzEMhY/KnmYlaygJgVyD2cZdb1xhJfAe 8QCQ== X-Forwarded-Encrypted: i=1; AJvYcCXcLG8IChnhSnmfRRd6jkT9bdPpx85kOfhKXXaKMbQSX38XLP4+4036hEVok+2VxITGAaW5079vpQ==@kvack.org X-Gm-Message-State: AOJu0YzoQrEQRD2YhqxfBJg8F1ITs9w+98jdV+MT7e0EzIQF/u+oWq66 sDasrSA6ICNeQyBFrCFIp7m64TVtXsn2NA/hGKFYKWbD/a7+HfClqirYonfq3jw= X-Google-Smtp-Source: AGHT+IFsTn+Q5A1WOhbyPTAjHclYiOvt3nhLZV/Hi5KOu9NOtbxQa/3JykhMvHE3PrFxCVBhO2k7lw== X-Received: by 2002:a05:6871:149:b0:268:afc3:648e with SMTP id 586e51a60fabf-273cffcb557mr1073020fac.42.1724310879532; Thu, 22 Aug 2024 00:14:39 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 00:14:39 -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 09/14] mm: mremap: move_ptes() use pte_offset_map_rw_nolock() Date: Thu, 22 Aug 2024 15:13:24 +0800 Message-Id: <12097a187fee5f21860d4f87e7aa103f822e298e.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-Queue-Id: 80D06A0023 X-Stat-Signature: 3wo7wyi5f59pn1citimxnpah5xmho86c X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1724310880-652006 X-HE-Meta: U2FsdGVkX1+Mrea9BBYvbIieWTIPVvAC44TWdYFTiHGx1TSji0KRcC38anTWZ6Ye/sNLpamx8ezR0aTAvRruTC+p5NgJuaVcJIJwFptT4RqsEZ6XbDHqCh1jq9gn4J7pgfiwsvbpALyc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ixQKfIW0CHrzzTFZqPsn6bzV7HisTbsM2837D31B5nkqoDdevI1HRuy4CQfaOnY+Gb/+khcGWKjfR2919IUg0GXz5/yVWCSsEoTVaNNB5Bvi3uh9j3TOXVF7rH/nYSfJITNDBN5nDfSLuczc2QptNhdIK/kb0U/UJ7/lWM3Rn9sPa/jYNBKJsVm7ZKuPdDyavpbhMAlGtHqbPdLuLVM7nSnb6v2xj0yD4sCwGB/ZeizL4ec= 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 move_ptes(), we may modify the new_pte after acquiring the new_ptl, so convert it to using pte_offset_map_rw_nolock(). But since we already hold the exclusive 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 --- mm/mremap.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/mremap.c b/mm/mremap.c index 24712f8dbb6b5..f96b025c09079 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -143,6 +143,7 @@ static int move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd, spinlock_t *old_ptl, *new_ptl; bool force_flush = false; unsigned long len = old_end - old_addr; + pmd_t dummy_pmdval; int err = 0; /* @@ -175,7 +176,13 @@ static int move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd, err = -EAGAIN; goto out; } - new_pte = pte_offset_map_nolock(mm, new_pmd, new_addr, &new_ptl); + /* + * Use the maywrite version to indicate that new_pte will be modified, + * but since we hold the exclusive mmap_lock, there is no need to + * recheck pmd_same() after acquiring the new_ptl. + */ + new_pte = pte_offset_map_rw_nolock(mm, new_pmd, new_addr, &dummy_pmdval, + &new_ptl); if (!new_pte) { pte_unmap_unlock(old_pte, old_ptl); err = -EAGAIN;