From patchwork Thu Sep 26 06:46: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: 13812867 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 99C0FCCF9E9 for ; Thu, 26 Sep 2024 06:48:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28F246B00B5; Thu, 26 Sep 2024 02:48:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 23F4F6B00B6; Thu, 26 Sep 2024 02:48:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DED76B00B7; Thu, 26 Sep 2024 02:48:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E3CC66B00B5 for ; Thu, 26 Sep 2024 02:48:14 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9FB5C12020D for ; Thu, 26 Sep 2024 06:48:14 +0000 (UTC) X-FDA: 82605960108.09.28E75DD Received: from mail-vs1-f50.google.com (mail-vs1-f50.google.com [209.85.217.50]) by imf09.hostedemail.com (Postfix) with ESMTP id CB6EA14000F for ; Thu, 26 Sep 2024 06:48:12 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="jE7cH/IL"; spf=pass (imf09.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.217.50 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=1727333256; 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=aXTwut+dzNyHtytsuWFcXJ2Z1C9apqorQFsSnetqX1dblv+93t/qlZ0Nc84LYrUQ1PpBUy gJdt9hYiBinZjn1Ffa6vXJeCwZ6WHHYlrMpKHjJRURdX1Lrpt9BrfXHrQzK43997/yYFie mmImM6q08VoBH60moUEriRmpQgQ6GSk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="jE7cH/IL"; spf=pass (imf09.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.217.50 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727333256; a=rsa-sha256; cv=none; b=6R7sD4cZvlhjPAdy9vNYiEH604ubXvKgm+PNgeKCS8dsMRX+AHsBE1NfSQzF4eDU948y9C AHrwKyNdSK63Z/X+O0BRp31Qpsdgr2jIVhhRsPBFOqlZvRnCt0xZkgbZTCY4mstgUpqHym 0OVkM+Xuxgl8uwTcXxH5RrC/C/kkTQk= Received: by mail-vs1-f50.google.com with SMTP id ada2fe7eead31-49bc44e52d0so278594137.1 for ; Wed, 25 Sep 2024 23:48:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727333292; x=1727938092; 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=jE7cH/ILLfiwyXsMSzDw5cKQkPnIVIQogcC99lhXoEhXUS3YrN3Y+9wTJK+RpEjNMc QYVIUJA4m5azeKrI6diky0WvqXPS7r4bmFmCi+HO9dLGF4S0tm3139RZfc/RAw8zL9h3 x8XTNdEOy5KbpV0z84Eph74dsPdZ0ImwyCecoItCCBievB0L5bHV8xjCIMVxyNVwr5Jd GU34ZL5jcwcNb2BhAjLFqVsy+y0yO8gfBMsZ557fIsuJrVh217JipoJ4R0PiBQUnDVEH X2D9eKLaFOl/mdty2PUxPWOxTAKBb+A4IgfPWWVmvkzFrAIqbTJxXona4MUwDmGSekaW rizQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727333292; x=1727938092; 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=sO603y8NLdWTDi9ba6s3anAek3DkXLoTktqDM6eFh51D7K8BFwR8/+TY8erfZSfKCV L1EJsqywrPBPd4lPiYXcs66CEMQZpZRo7Y+lQzzjr5f7JuyAFMy2bZ+WGlLotSoztIQS iZwdGmo0xifoHpEJrSYF3zjjyZv7lbebGfSL+k5LeFkGE0VV5uARQqT26Ija8rRTgMbD vDycYkMzsfTFRwFwk0g5ab/03EcXH7QXydIRt4pJoZRHk9Z7y4WlECMxXKZnarD35AtH M0ITunzL4sZyJsFo0pbn/dagcMM1bHzlxUSGTAQMkvxgFGz3YsMVpqTT6NPGlAxy4eTf 60dQ== X-Forwarded-Encrypted: i=1; AJvYcCX/l9qa0NZch+E/qrlNSCj73hH+bBhQ55E/rgql59bpt6cen+yBuuT1sU/F6x4rIlofff4qGTMZrA==@kvack.org X-Gm-Message-State: AOJu0Yx4y7kO752AZ9qRzFbha5kRl9SIlMgyZMQZTEcnlDTP9caE4SyZ iD7psFKT3AehmwaR6JSEnttV6Z6VxN41ctOprSQrk2boGUEzZeG+fMxKbsftDro= X-Google-Smtp-Source: AGHT+IEjiufoSG+9f7J9DudEHL9YuIq0UaJx7YZ52pOk+qHYx73DXmea6YZQnzcRnEEhuuY+i+vKHw== X-Received: by 2002:a05:6102:e06:b0:493:b055:bf56 with SMTP id ada2fe7eead31-4a15dc39965mr6802341137.2.1727333291940; Wed, 25 Sep 2024 23:48:11 -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.48.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 23:48:11 -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 11/13] mm: userfaultfd: move_pages_pte() use pte_offset_map_rw_nolock() Date: Thu, 26 Sep 2024 14:46:24 +0800 Message-Id: <1530e8fdbfc72eacf3b095babe139ce3d715600a.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-Rspam-User: X-Stat-Signature: ywz9jaf8okar1rksih4zripdnweqyeae X-Rspamd-Queue-Id: CB6EA14000F X-Rspamd-Server: rspam11 X-HE-Tag: 1727333292-62064 X-HE-Meta: U2FsdGVkX1+XqEraoeTVfl/PN68Qt9SWyBv1wXN4j5PNrKGoJi8GfRLRCiQGSWRY3tDJDrShUAUQvA1dQ6x6C1vv1ul6CKMPVJQ00hGLi2luGM47yo5GvyZU07bpKdCBbQGVq2EyRedaStynC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v/q+j7hVicoLFAWKuPgp1qP0rzLau4rJvLqhmAv0SiOPI0HSNwRCU7zlMT3Fcf938UgDJRSNkg6oStWevuLSzYWhOFpUzn1FqcGZP5oqBNUPZ5gPdrkbhg9Bf8YRMce/TIf/fU7KBWZzurKCeiZRF1pYmOoTdlE2unF67osqwZpyhXr96M/HHwZj+iWZo9rwQ= 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 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