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: 13790099 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 72215CA0ED3 for ; Wed, 4 Sep 2024 08:42:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0356D6B02E8; Wed, 4 Sep 2024 04:42:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EFFA06B02EA; Wed, 4 Sep 2024 04:41:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D53986B02EB; Wed, 4 Sep 2024 04:41:59 -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 B191E6B02E8 for ; Wed, 4 Sep 2024 04:41:59 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5A9F5160DA3 for ; Wed, 4 Sep 2024 08:41:59 +0000 (UTC) X-FDA: 82526413158.27.C2213FA Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf03.hostedemail.com (Postfix) with ESMTP id 7485220006 for ; Wed, 4 Sep 2024 08:41:57 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=R8W6gVyK; spf=pass (imf03.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.178 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=1725439221; 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=4PxEMdLIb7w0CeH690VB/ed9+hRnYGoSsqaGDg4GBd4=; b=VYsyGsWZPq3g04zeMccqe7+sfhtidBqb53X4Akjuy5mH9wVKDZt40GC3B3QtT1SKiJ+m3A 2BvjA3V4zP3TlGhAWOPQwSmEwri8sO8iwHEcdSFJ8V/pamwsgzxmLLXAorPcgXrZCAvfei ehZ5j1cFLves0NaTv1cqDxjhhaQsSw0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725439221; a=rsa-sha256; cv=none; b=fX1TTuW0WN31wrhhujWohcrDBEuL9cfuE5uNwIeVOPSWkJbTpXF8w5MNVz45gVX83eY5IE tfhHrvgR97DT4Ie+bbF5jPTfU58xvUz30kNqkRqtWp7CaijxZ/XukKExOS9yoCzJfVie9k pQUhkQpW2Ybj7TAoYEzpt1D19wy5fdE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=R8W6gVyK; spf=pass (imf03.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2053f6b8201so31856805ad.2 for ; Wed, 04 Sep 2024 01:41:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1725439316; x=1726044116; 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=4PxEMdLIb7w0CeH690VB/ed9+hRnYGoSsqaGDg4GBd4=; b=R8W6gVyKImpqSXqQfPAJxyIrcy3rdy5qd2v+DluMAvftwTozl1jgFNy78q1JmCE7tn reaUSrj3pyD9W/5mbgaXyeo+crmF3fi65qMpE3wCfjIckz3O1rrQw+ZG0qU9bYQm0Iyc z0oQpXvAcPx57LIR9M/OUag5mQ5w8lP0sw7hhtXAjQ7p4jRiv4+f8OMeCmzeVkeHXZl/ fLmVVUbpXHFbHFPwKw7bSLEh5a49cSD/PzUwprfJmlneHL6+ChGoyS300ytioXuZ/UIM LEMr35SPvtnuAQIlxLrnhqKXQe2ebiD9dzfvXb23apgJjDb9qJMrG5WAdtTN194uGj5x IaUA== 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=fxF0HysEnWynvZhYR6EtZ8h5Rr+M2XAmvqMTDQjn9lKw+cMWUlhy2v5zcGzCbd7dXp VsRaK6gG7vJifgBF8lyLDn2MJAbrbSbRx7/zsQyUHXwewdxE9emWYAuT0lpauBAoEoQz G1dtlr/COVZoJhxk9f9PQj6dgA049IjcDbhLfaVhC+2OnXmzTkAne9lb6et6tFuTgQkf de18wkWObkGnuF0H0kQJR52ot8Vl6df4Q7DiQy2D2++aJtQMclbAgKkbAitj1+D4w2wm 5C1pmjawU5uQU8swrsRDumXRfdfKOQnSlOHgVf/ZkzNsVN9DCYIWFSZiCVzKklYHVa66 pCTw== X-Forwarded-Encrypted: i=1; AJvYcCU9GuXhuceJGAF+sgb1Hnc5WUXDkp/SiBEN52FLT5PZWsQmaK9HDQr+A0kTPo75dmDr7CPwTger0Q==@kvack.org X-Gm-Message-State: AOJu0YxJLckkH5iEAfVyS1Pw6jNmbG2v091dxv/zrIniVbzOY9RPzi0N M/M7wb+2lPMbvH66cAqfIWCQrRlp0u6FlGeNRVOJOw7Gt5j2rA3ExIMysWSbHcQ= 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-Stat-Signature: kb5e54w3caqcz5f6jm8x5k9jshfm6bk8 X-Rspamd-Queue-Id: 7485220006 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1725439317-227487 X-HE-Meta: U2FsdGVkX18TLk+cMKtMJ7bwXl0T4M/jLxO1iDaJH2pSh64393br0knKgtfuyhEltJDJR5EJwyZhcyI/z30neuF4Y7IBHO4VOCgmzeZicRXHZMtd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70jUYlAmNhuR6Zd4AU/WAwQ78/JW9/6nh6aU+hjktOwvT30X6N31IsqhPuVNjzMhMP0PkSOKJU4tO2NypAUq8DWHtfAeaqOl4TQmGfnlykGz5DML2n0Q83W6tLWXJt+Du9sek0cnUhRvOyTee6PeZWHycLjrgtXjrClCSqghQcUU8IiLMfUULvva8JGXxLgiusu6oG3CunA2ekJz+s6/lkwuVEpqLV60lqfj5/+CKWK1dg2Q82lu1GQL6Q== 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 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