From patchwork Tue Sep 24 06:10:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13810133 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 BB1DFCF9C6B for ; Tue, 24 Sep 2024 06:11:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E0B76B00A1; Tue, 24 Sep 2024 02:11:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 467876B00A2; Tue, 24 Sep 2024 02:11:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E2446B00A3; Tue, 24 Sep 2024 02:11:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0E4A66B00A1 for ; Tue, 24 Sep 2024 02:11:40 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BE1D71C70EC for ; Tue, 24 Sep 2024 06:11:39 +0000 (UTC) X-FDA: 82598610318.18.8DFB158 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf22.hostedemail.com (Postfix) with ESMTP id DD7B7C0005 for ; Tue, 24 Sep 2024 06:11:37 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=UwTWWbpo; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf22.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727158210; a=rsa-sha256; cv=none; b=W+v4Z7EC3uWiae4dszsNssRj90CGlrtcSwhngYOks1nOs3HEQkr9nXQZnx3gGIR4Kkkvvn sqBR6tQHq0NPYc5Okr9Ce0JUNBXgODrMFdQ++BSUxp3+mEyKq8bzEQer8IIIRTuQXk1V/j qLFatYJUgGc+ahs5RXqqEUlUM0G9aNE= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=UwTWWbpo; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf22.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.173 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=1727158210; 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=RnMCKwBqnYl3LJbu0M9HQTu7wcymlNTkAYqiZlfWQ7I=; b=zXP/y0uMeTaxRjCjpoPlGoBBepizp9eT2p/oKgpkn2nZf8T0IDJO8hmBAmP9NaQsjL7EML 0PNwNQrvh4jvff4PILx1+QXXXsn9zSQqox33Y2m0ad/M9iLxaY+uY85Fyi12a+K6R6UYRA w9rH4zp04Fc8vkJkLkOXaqZPCFXGy6Y= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-206bd1c6ccdso48965525ad.3 for ; Mon, 23 Sep 2024 23:11:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727158297; x=1727763097; 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=RnMCKwBqnYl3LJbu0M9HQTu7wcymlNTkAYqiZlfWQ7I=; b=UwTWWbpopMQe/EV1ZvE5tJKFY1ttAZ4xR9sRufHnsHf8vYgHsD/bELErJbjnR2XpXx WwGaCur7L2RCA4JD+j/YEUa02sAEZ4udEHBxtjjSbDvJOD7ysDFz8tTUTjuYgI6w1d4w mshvs50EKNwD4IIXowPmRLJzpeWMxaC5Dhc7yp8wlRqnv5SIgIgHa4L6mHCe6xKJxfHR iCAZ5XQxvNeSVfdD9qS6L/x9tf0anXa9SaRY2iEzpjmigeZpp4aaidZmXhqfWYs3cVkv IZ2MJ6uEfEFJlY/Jkv7uxqoo7dn48TO9+rC0jKoxgqR6ucTDIslOd8QsbSMHPEAvG3od zL8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727158297; x=1727763097; 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=RnMCKwBqnYl3LJbu0M9HQTu7wcymlNTkAYqiZlfWQ7I=; b=Q35ZFyyj0m0f+a4B4txsaPmx9UI+29n+cm9MLjs1Ef4NG4Bf/KmB8HQnyT7fkMNa/T MxBeMes+cPa4hH3O3boPPD9q719JiPbxf9+1A6kSByJszvv2fZQcVBeZBroMiH9LpXce JwPepwiBsI4UexQSJ6z6zQ7ptR2inZaUnKcseidcRxLwJhFWmvTms9Q4SyBX+JTb+rf9 jJvWckNhXaAtbTAWByBkzydeRNrFCHJy1DiLioYoivyOKJkIR33mVSoPeCuACjbtP0TG XnzUYcv+oTDLlTarVrxsS66JTP07X9rrVytPYJjDAZNk/17skr1A7Kr/igJEXIh+KlBX 62Ww== X-Forwarded-Encrypted: i=1; AJvYcCXIN+xTNlXuLJVsKUSLrl9wYgR3Tt4zmqV9iv1iyBMttYOJ6kRa5/M4TqcEhM2HyNtbEbVjG8UZrQ==@kvack.org X-Gm-Message-State: AOJu0YwaDi6hQgEHX7gfHwCR4RTbkuRp+M+Ytf4Ap2QNoP4vncWIuarb oHEpghlGSRCONHfmLh9ZnSjlK0COaUlrPGEoDEbbMcMtb8v+40WSpCWzqw71CS4= X-Google-Smtp-Source: AGHT+IFBI5Ned/vbTuuRRzdnv79MFASKoi0/m2fLpf4am0H6y8GNq4qW/RgfzVT9no9zcYiBkg/Xzw== X-Received: by 2002:a17:902:ea07:b0:20a:f013:ddb5 with SMTP id d9443c01a7336-20af013e29dmr19152265ad.59.1727158296610; Mon, 23 Sep 2024 23:11:36 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([63.216.146.178]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20af17229c9sm4344885ad.85.2024.09.23.23.11.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2024 23:11:36 -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 v4 11/13] mm: userfaultfd: move_pages_pte() use pte_offset_map_rw_nolock() Date: Tue, 24 Sep 2024 14:10:03 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: DD7B7C0005 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: dobcoc5j9qrcxag8mp7akp68dcbydpz8 X-HE-Tag: 1727158297-490880 X-HE-Meta: U2FsdGVkX1+/MAW19ihirY4CRcW9po3rLNHGJihMUTFx+aaiJ+f5wBGDNePqASYAsBcR75c2+Ow/kvjldaWdSqI2ulZitSKq/2q9vvb0MFB4i2c219jC9UcuHaXPIrpCwdGOSyf7rB5+NXpj01BMB4yLFLuZaANSIHzs6xIoMkg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JjHZkkHxJ7GzIQOXsQOiO6i9GZXQq6D1VQsWQyOBI4n4rv/UkwVc5lrfwcLPl5gguXyNpzNMtpRmBErLNfHK3SGc7pBkPidVnW3nYm0Z3rFGSJDIDI7SlyUOyG6j0gUQEDKTLFD2HsE2gPE+RL+DlXHh/D8poY= 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_pages_pte(), we may modify the dst_pte and src_pte after acquiring the ptl, so convert it to using pte_offset_map_rw_nolock(). But since we will use pte_same() to detect the change of the pte entry, there is no need to get pmdval, so just pass a dummy variable to it. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- mm/userfaultfd.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index ce13c40626472..48b87c62fc3dd 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1135,7 +1135,7 @@ static int move_pages_pte(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, spinlock_t *src_ptl, *dst_ptl; pte_t *src_pte = NULL; pte_t *dst_pte = NULL; - + pmd_t dummy_pmdval; struct folio *src_folio = NULL; struct anon_vma *src_anon_vma = NULL; struct mmu_notifier_range range; @@ -1146,7 +1146,14 @@ static int move_pages_pte(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, src_addr, src_addr + PAGE_SIZE); mmu_notifier_invalidate_range_start(&range); retry: - dst_pte = pte_offset_map_nolock(mm, dst_pmd, dst_addr, &dst_ptl); + /* + * Use the maywrite version to indicate that dst_pte will be modified, + * but since we will use pte_same() to detect the change of the pte + * entry, there is no need to get pmdval, so just pass a dummy variable + * to it. + */ + dst_pte = pte_offset_map_rw_nolock(mm, dst_pmd, dst_addr, &dummy_pmdval, + &dst_ptl); /* Retry if a huge pmd materialized from under us */ if (unlikely(!dst_pte)) { @@ -1154,7 +1161,9 @@ static int move_pages_pte(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, goto out; } - src_pte = pte_offset_map_nolock(mm, src_pmd, src_addr, &src_ptl); + /* same as dst_pte */ + src_pte = pte_offset_map_rw_nolock(mm, src_pmd, src_addr, &dummy_pmdval, + &src_ptl); /* * We held the mmap_lock for reading so MADV_DONTNEED