From patchwork Mon Apr 15 02:08:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13629390 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 6E606C4345F for ; Mon, 15 Apr 2024 02:08:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 07F346B0088; Sun, 14 Apr 2024 22:08:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0080F6B0089; Sun, 14 Apr 2024 22:08:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DEB0C6B008A; Sun, 14 Apr 2024 22:08:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BDFF06B0088 for ; Sun, 14 Apr 2024 22:08:27 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 508061A0318 for ; Mon, 15 Apr 2024 02:08:27 +0000 (UTC) X-FDA: 82010131854.05.5B40AE0 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf01.hostedemail.com (Postfix) with ESMTP id A332140002 for ; Mon, 15 Apr 2024 02:08:25 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=cZUEtEhV; spf=pass (imf01.hostedemail.com: domain of 3GIwcZgYKCNkNPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3GIwcZgYKCNkNPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713146905; a=rsa-sha256; cv=none; b=UbP/2wWy6hnhCQYl+3QzlbbUCfOmzNBECK/teptvNwrsdTfM1+6HfE09pYeR4veu0ik+II rWgGNU9fPNeJfyc67gvSHkdDUNEIiH5xjNnyJAoDYLrs5MYMc0DKhrK9vFdZAcoGkfyk3b s/AgfzMAYQBfy9qtE9g8uzm7RcXuozU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=cZUEtEhV; spf=pass (imf01.hostedemail.com: domain of 3GIwcZgYKCNkNPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3GIwcZgYKCNkNPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713146905; 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-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=/98u94op72EVu1rwcZBeQqBXmPZ1FBtvrZp8yXfae4Q=; b=Uz0oagzQQFnMmIqWUrDcPUjeSKoPZqy3E4lxjcz45du2QvMIuNPhuaHJvpWrGrk9Lc/0pi aq8HxUlUfXV77L83y0gEpmxMrWSYeICjBUvkre+o47nJAwmNi/mfbmUPnPvh7I0dr/YLLl /FMWOsd0svLdBGHKL7LIXBH/+/3yvjM= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6ceade361so5113471276.0 for ; Sun, 14 Apr 2024 19:08:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713146905; x=1713751705; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=/98u94op72EVu1rwcZBeQqBXmPZ1FBtvrZp8yXfae4Q=; b=cZUEtEhV1a7Y314BvINXJItkxf+KaAE3FwaX0qXiWaTs9BeqTDabtGMEDWRfr+tmTu xO9OeRPgINIs/xt9tt0EAX3/pcVCEGvPnJCizXfMqgR14qN3qqcVz265IPY2j7/vKJsX dRmms5iwfJQWXJu0ah5/iyVIGKF/vM+ag7hUxx/pgcluJFnH96NuDpxzXNIruLlKtC+F LpkHd8v4krydBGpI3YML/x8nyHUExyIs4kTGJ8Mk8n0f7vwd+/ZqmAT/Ben8f0h6MG6C lIbMQSsucFr3YXekmr0OT1lqzMJoXhco3SAsId+oWF19C0cyhywIVq/MTLeBwHnLs0eC bvTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713146905; x=1713751705; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=/98u94op72EVu1rwcZBeQqBXmPZ1FBtvrZp8yXfae4Q=; b=xBIhkPvv7G6v1ic6S2wv+tJQSoerpBv5FVNbbxI+K3OULLbq5JgKlxRzEYWL86+/35 gCqJ30KHBwlzPXzOtaVAj8M1FkJdnZdUWgelh5GFUtC0m3ow1zJMz6RL/t/vALZJoqHZ w5haEJe9+Ge/3hKBs1AhTtbl1WMKH0N50sHOv5EXvJOBsdsGMErYjYTmZNu/pLh2c0cO oh+JArJ6IYnGer1upfRsSn8bMtbDIhBcx7zXeQHdybD2EqMtMcdxIEJezY8MC+zBvIeX PlVpc8mOKk2xSXm8SxB5XDP4nAHn5RnTDyarER+FYbykbYoNZN+R+Xw7nz96UYIQpvWn gBXg== X-Forwarded-Encrypted: i=1; AJvYcCXala//m6WuTk/LtvkmKcm54QmZDwd8FwlK+SlTJvoIK0zObG0x9CUHiddqkaJuj1jX3vecDJvehtOSbmw1Rh2ZMhc= X-Gm-Message-State: AOJu0Yz3i/W5maUKvKL6Mkwe6WK/tjpK0V2ZR6u8b33HRyD9CVcHjIiA 7SGiY6Vo4VDJ49nurydG0srA/oCYFfKRAt2Bzru5rQtR6pxwjYnnKtWxnmRaTRjxCQANevbjTpN r/g== X-Google-Smtp-Source: AGHT+IGZchVsO41d1crlhOYsiW9odtp2PFbpIfFEraBCHTjkLJTY2phNg19cKjJ2oBAtjRoIf3A1jhKhsms= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:4faf:b746:8f4e:5d6]) (user=surenb job=sendgmr) by 2002:a05:6902:20c7:b0:dda:c57c:b69b with SMTP id dj7-20020a05690220c700b00ddac57cb69bmr2849394ybb.0.1713146904810; Sun, 14 Apr 2024 19:08:24 -0700 (PDT) Date: Sun, 14 Apr 2024 19:08:21 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240415020821.1152951-1-surenb@google.com> Subject: [PATCH 1/1] userfaultfd: remove WRITE_ONCE when setting folio->index during UFFDIO_MOVE From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: willy@infradead.org, david@redhat.com, peterx@redhat.com, lokeshgidra@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, surenb@google.com X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: A332140002 X-Stat-Signature: jdu6ae5cyczzaykpysw1nmy1xdesmuur X-Rspam-User: X-HE-Tag: 1713146905-264345 X-HE-Meta: U2FsdGVkX192KheJcf1oiQVRb4oESRCei1bXadiSkHnDRjtfw9fGrjSUqFdsaqN5Burt8sAsZnPOj7kau6YpFxCFAMY91fzcz9YmT/fn+BOGFh0f4oafrueMZVE4QMXtxZt53Uk4BUyNtNK8wZY+sH73FHwIixTDxZ/I+BidKfWuwW7r/w88KfIyfEz4rVjJGP1ciyMo7fB1Sbj3Cuo+9v6DSqsjM+SpqANFqgCXaLlI6cMpSAYNtNd4L2y1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MtZtFatW7wsAzTsu2Ha7WJmNSkLowix9WaVY9J/vfQiN2EkmNArrXFl9S+eKYdoaQMsHI+GhV79eAU5G5+ot9RQJrLcZGJNsduxghe8wwHkPFwVaURngJWGnNOnmOoFxQxi+FL9XE1ODMf6N+naZjUDvJUuXzA35v/o42NrT9crWpA4W6Jrh0OlADAGcJNQPnjYuskeJ9tH7HCzCGnr6rUCBd80AUBPFdPbbjAqZRJzstD2KR1fEJeAiJHq61pXdfbzTv9rWAHhW0Qft06Q2gHzUCYqoF5ziX6B8lgZjY9fJRgE4o4zc6SYgzwpnBwkRyU4ObsT+RsJi4AQ/+YEnwrt4ke/UQ3cCwd9aq8IyBGEUx0Kg2+vS3Uk5hDNKx4k5IWt6+WsR9t4IEtBEEB7EcsM= 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: When folio is moved with UFFDIO_MOVE it gets locked before the rmap and index are modified. Due to the folio lock being already held, WRITE_ONCE() is not needed when setting the folio index. Remove it. Reported-by: Matthew Wilcox Signed-off-by: Suren Baghdasaryan Cc: David Hildenbrand Cc: Peter Xu Cc: Lokesh Gidra Reviewed-by: David Hildenbrand Reviewed-by: Peter Xu --- mm/huge_memory.c | 2 +- mm/userfaultfd.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) base-commit: 3aec6b2b34e219898883d1e9ea7e911b4d3762a9 diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 58f2c4745d80..ee12726291f1 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2200,7 +2200,7 @@ int move_pages_huge_pmd(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, pm } folio_move_anon_rmap(src_folio, dst_vma); - WRITE_ONCE(src_folio->index, linear_page_index(dst_vma, dst_addr)); + src_folio->index = linear_page_index(dst_vma, dst_addr); _dst_pmd = mk_huge_pmd(&src_folio->page, dst_vma->vm_page_prot); /* Follow mremap() behavior and treat the entry dirty after the move */ diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index b70618e8dcd2..575ccf90325a 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1026,7 +1026,7 @@ static int move_present_pte(struct mm_struct *mm, } folio_move_anon_rmap(src_folio, dst_vma); - WRITE_ONCE(src_folio->index, linear_page_index(dst_vma, dst_addr)); + src_folio->index = linear_page_index(dst_vma, dst_addr); orig_dst_pte = mk_pte(&src_folio->page, dst_vma->vm_page_prot); /* Follow mremap() behavior and treat the entry dirty after the move */