From patchwork Wed Sep 4 08:40:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13790203 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 1900CCA0ED3 for ; Wed, 4 Sep 2024 09:16:43 +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=4PxEMdLIb7w0CeH690VB/ed9+hRnYGoSsqaGDg4GBd4=; b=kPSL0GblNksUxTj3iCc99aLowx W2B/Im0ZkFVyf0KHWUppBtuePURaYEr4vRg6H7bpmSMglw/eMhK1HQvVh4PgUuBR4PnosIMD+3vCs omn5MMnyr0sN/TD76PTXTc5TTvR37kSVEDyCoORqNRx4HZpjgygFSEJsvqs9vAhaaRfBmZ6CGupHl cgeiwTmNnmfNJmpT5dUdAIyYqH2pJClyLvAwcqIoKuO1AmUepqcp0aPkUaSxLV/eGFbyaQH7UCRKg As6JqvOylvPN1wcqCIyh2ELXcZ1RlHyU1v/6Dk32Z4eFUYQi91LulHTm3pO81zMkAWOXrpI5GlKwA GX1oKmqQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slm7r-00000003dAB-2PJs; Wed, 04 Sep 2024 09:16:31 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sllaO-00000003Tav-3Kau for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2024 08:41:58 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-206aee4073cso6775615ad.1 for ; Wed, 04 Sep 2024 01:41:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1725439316; x=1726044116; 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=4PxEMdLIb7w0CeH690VB/ed9+hRnYGoSsqaGDg4GBd4=; b=bIHL2YlbPA3LTXS69CWY1EVqyv/2XxTO7VXqbv4BpAI6Xvtmfonh820fXTv/N4ARX2 6PDH5bL3xcQSM+wtx4SpLncX7k6kPFqPWXMPN3hRJFX+1yXPBJLv8fUMSO/RVt7aXkuL cSdDTzkHVpoPW1m25TjPHE69zzzytzlkXbSexUi7bXX+RrMgzxy/sqY1ZsfUHBo8WrWk ZptpumULWuho/eMgZeaGKB2Cs3UBmXGZgyhmKh/fjJZ6s5Yy06ZA7JISYyVqwvK7wPma mE4mU7n06D9Z3YO2CPV6c3ssPrwH+mfiJRsOBhFM4/ZwWVD0Mz+R6FS5fy2NA5ZsTifm jM2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725439316; x=1726044116; 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=4PxEMdLIb7w0CeH690VB/ed9+hRnYGoSsqaGDg4GBd4=; b=aj9WKprkmWOZOgUyy1u+G+QD/xvg0eCwf45/fRUn+zk9NQ+XJv54y5JurGj/FTYBTq 9oiX/TlAyr4iNGAu51JU5vQlm17FykhnY4UPbMQhEFSSuVIsta8NnjZc+JYF4LnnnQv+ 2iHBeu4qG2EgRsCD80GEY5PuwmS6Eh8LfWj1wzciktbyU8xgNEgRtrthGzTET4l9w3Ig X+i6co3FkJyAIJE0sF3HfJJX7RJ95YlJesnxScq8+8Ut5ObehjSGu3aoEELCcNNUiti0 6xPguHb0xjk5TkyxJhP3MlsGWcIjMeSeNNo5rmaGwTQaHGw64rq9wFTYMkRVwPNZpfbk iMQQ== X-Forwarded-Encrypted: i=1; AJvYcCUKO24y9ivr0i9yoUH9AndLcmaK3InDoJX8eUK5YBeRDewL/x6U4nQeZj20EJZJCQ/CMdNYyD0tmDd/VO+TfBHS@lists.infradead.org X-Gm-Message-State: AOJu0YzNbdgs5BlKTo8o5WiyNKsQGq2s7VYjoMG7qXrL3ajFtezjdDt5 yv/l+OBa9uK0WatieMoXn+gIHIxnaNbqokRJAlaQ000v0CWDI/pLLmfGiUC/+Ao= X-Google-Smtp-Source: AGHT+IHUb0AH81Bf+t9sl3x8o3nWMR3fxDcIYnthyKOt2Ee/pQCOOrlcmsn4X1RsHo/HQ+Mvmo6mhg== X-Received: by 2002:a17:902:f94c:b0:205:4273:7d65 with SMTP id d9443c01a7336-20546131866mr119665875ad.21.1725439316150; Wed, 04 Sep 2024 01:41:56 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.242]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae95a51csm9414045ad.117.2024.09.04.01.41.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 01:41:55 -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 v3 11/14] mm: userfaultfd: move_pages_pte() use pte_offset_map_rw_nolock() Date: Wed, 4 Sep 2024 16:40:19 +0800 Message-Id: <20240904084022.32728-12-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20240904084022.32728-1-zhengqi.arch@bytedance.com> References: <20240904084022.32728-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_014156_897624_9DF50E38 X-CRM114-Status: GOOD ( 12.97 ) 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 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 already do the pte_same() check, 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/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