From patchwork Sat Dec 30 02:56:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13506778 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 2E2C3C46CD4 for ; Sat, 30 Dec 2023 02:56:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80C116B00E6; Fri, 29 Dec 2023 21:56:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 76EC16B00E7; Fri, 29 Dec 2023 21:56:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E7276B00E9; Fri, 29 Dec 2023 21:56:14 -0500 (EST) 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 481E66B00E6 for ; Fri, 29 Dec 2023 21:56:14 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1239616020C for ; Sat, 30 Dec 2023 02:56:14 +0000 (UTC) X-FDA: 81621970668.28.E7DEE61 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf12.hostedemail.com (Postfix) with ESMTP id 596664000E for ; Sat, 30 Dec 2023 02:56:12 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=dj0E0vRa; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 3y4aPZQYKCEo463qzns00sxq.o0yxuz69-yyw7mow.03s@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3y4aPZQYKCEo463qzns00sxq.o0yxuz69-yyw7mow.03s@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703904972; 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=rx3xKuaGL8HWrRRVUoZvzccCFnr0zto7mWLIM9ls3L0=; b=LhDIQQzhl2Za9IUl8gNt47QjuGT1ZwFBbnu2NQWlABdUVjeZakCjlmV3KvHKGi36gaN/W4 rXQYq4avsi6Yp77oT5F821ig9bekHYbkydkXU/KU/BERZZMkRqtcQA0UibzodcTLV6A8t0 m5H8/lmugpRoeAG8OBhz78UcNFseJeA= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=dj0E0vRa; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 3y4aPZQYKCEo463qzns00sxq.o0yxuz69-yyw7mow.03s@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3y4aPZQYKCEo463qzns00sxq.o0yxuz69-yyw7mow.03s@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703904972; a=rsa-sha256; cv=none; b=6HT1+5YpEtVYOzPW5tY6jON+CfOD2JapmFPiAhToesQIp3LDWp39ky4fNphZMMzt3/3RMz 7IZwvRMCgM34TxjVw8bjcjBr1LGmTF9EYME8FEryI5h6DWlCoT1d3SahIO9VNRE29UV81R sZoJ1XPbKAcjLFSrUg/jUhnyIXzHI8M= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5f0fd486b9aso1304247b3.2 for ; Fri, 29 Dec 2023 18:56:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1703904971; x=1704509771; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=rx3xKuaGL8HWrRRVUoZvzccCFnr0zto7mWLIM9ls3L0=; b=dj0E0vRa+fYKyYnWlJxgedkVo9d7u2vCbCmItxIyyyys8+mGkXJgrkwJIJ+Pi1yiKN Gwf3IR8YRpdTRKo1/hy7/nuJ3pdXUJiltjL5WvCBOeDFEy3jHSStvUcm1Ow/kmFN6sEH w0XGC1fIs6tYgT5euIFpqRwploFnJA1KgWf1/y4YRZcITFn04OwNQ2gaFpkLdjeomnTN hs54bYz41VoVFGZq8Pfe3huewaHBJkCMe3wu/I1tX4jVbXJDqPfT9TPxKQrO8LxdQSHQ EQZd2ZEUCbnryUIzdJ5afy8y7en7Rr93ZoxyRvV0/EKWtARPgY85Lcf9YVG3xrXICZVw 3mwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703904971; x=1704509771; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=rx3xKuaGL8HWrRRVUoZvzccCFnr0zto7mWLIM9ls3L0=; b=dd5zgW9KDwIKa+2BzsqJp8BfLB67bE8OI4/EG1dXhcE1Ah2sfJBxWvZxML6rNr68wm lN8m+c8cBDlfr6NDj1BGsWJ7xYLs4bQbnX4+24VhrrGIz5NEAT9tp5TTg1yfb0q5xyGT KreIcU/xEoo9gQePj+LE8KojyN3FTbK0eZWG0w9eK14Mg1m1WpjGvCaZ4jR+kr4WqUV8 GOW/FJVclyYmqPh3INqUmorFeB+NNgy8bFvUTijfOpx9HLLqq/pq0WNLv+C3i2QJWzi2 eJnCJUFMlR1tkYQgyE7U6Jjjdz9hevBhzzT6Hvqc+ibDI8kuxD/tpKppkmvF476IMjl+ TCQA== X-Gm-Message-State: AOJu0YyfezBjBmIZxw9G4tk+O61Prd0j1XvrxwpvBTH8lRHeXNdZ+rSn 3aSQuWV1PlZH1Q9ECpsWi+dofEO8J0FLa421mQ== X-Google-Smtp-Source: AGHT+IEa0V0G+LZdy2Xqpj9r4ydRhq229LLnwM8al0ZDxIMrbdtDuGldtaNSDvCbTs1jv2oUX2fZyzvUP58= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:aa12:a8e:81ce:b04d]) (user=surenb job=sendgmr) by 2002:a5b:8d2:0:b0:dbe:269d:13f4 with SMTP id w18-20020a5b08d2000000b00dbe269d13f4mr219681ybq.0.1703904971448; Fri, 29 Dec 2023 18:56:11 -0800 (PST) Date: Fri, 29 Dec 2023 18:56:07 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231230025607.2476912-1-surenb@google.com> Subject: [PATCH 1/1] userfaultfd: fix move_pages_pte() splitting folio under RCU read lock From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: viro@zeniv.linux.org.uk, brauner@kernel.org, shuah@kernel.org, aarcange@redhat.com, lokeshgidra@google.com, peterx@redhat.com, david@redhat.com, ryan.roberts@arm.com, hughd@google.com, mhocko@suse.com, axelrasmussen@google.com, rppt@kernel.org, willy@infradead.org, Liam.Howlett@oracle.com, jannh@google.com, zhangpeng362@huawei.com, bgeffon@google.com, kaleshsingh@google.com, ngeoffray@google.com, jdduke@google.com, surenb@google.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-team@android.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 596664000E X-Stat-Signature: qzi6smowz5mfgfs43gh6genxxq4zzesj X-HE-Tag: 1703904972-959491 X-HE-Meta: U2FsdGVkX1+NIHeTr8qTIgnMCidZwuGTv+2BM6Z4sEE2ZvrTUPu+HVj42If8r9G+H6Lh7CWjEgDrv8jh9OZIU8Iq65yQqhCFWhIVQ45LdU0DQQ6+ogKD6aqjkgjtOngSNW5zXTjaJ1qqbnc1+4qVfF63RKWHoBP4JkWAW1eGgwg9cdSulEF4cG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BYtLoEREAHDEaq/0Sc0OhaGnHgvqELSHj3KG2gUyczgJZojMJ9NkVQ1/MZRoM36wmWVc9LwRu4EH6EwuewaV+hdcA1rrFaf7dsykeVBj0uJW7i4RR8reg7zEYosWmqiFFC07anvgmc8yZzTar5ZyxME1b1rl2i2qvGxVAl01OaY3x6bvZfDAT/Di29F2Wza7DOhaBSwq45NSYx5tQFoJEDCEubMS/zQr1w4e+mDUy0EgpNbkJdHrjcLc0vQ5vHYJFETLizKI+35sKF3LcYWuWbN3ox/Oa7V/CFs54y+W6NKN/hhsQzyZb+005grM1Fbqutq9GWjTifE6vn2CLha8jrHqk5IYwPSbObTGPAIgnyUKaPCPhTBGei3vM1phl8TmfPdPIE2A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.002408, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: While testing the split PMD path with lockdep enabled I've got an "Invalid wait context" error caused by split_huge_page_to_list() trying to lock anon_vma->rwsem while inside RCU read section. The issues is due to move_pages_pte() calling split_folio() under RCU read lock. Fix this by unmapping the PTEs and exiting RCU read section before splitting the folio and then retrying. The same retry pattern is used when locking the folio or anon_vma in this function. Fixes: 94b01c885131 ("userfaultfd: UFFDIO_MOVE uABI") Signed-off-by: Suren Baghdasaryan --- Patch applies over mm-unstable. Please note that the SHA in Fixes tag is unstable. mm/userfaultfd.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 5e718014e671..71393410e028 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1078,9 +1078,14 @@ static int move_pages_pte(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, /* at this point we have src_folio locked */ if (folio_test_large(src_folio)) { + /* split_folio() can block */ + pte_unmap(&orig_src_pte); + pte_unmap(&orig_dst_pte); + src_pte = dst_pte = NULL; err = split_folio(src_folio); if (err) goto out; + goto retry; } if (!src_anon_vma) {