Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6832681rdb; Tue, 2 Jan 2024 15:35:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IFMCFaUTTQ3tq1rPagQWsH75diZUf9LQhkkh2RMHkpyWWSdf/+4y4isjMIMokxkSP9ScEPs X-Received: by 2002:a05:6a20:6a21:b0:197:60cf:a838 with SMTP id p33-20020a056a206a2100b0019760cfa838mr232513pzk.1.1704238512317; Tue, 02 Jan 2024 15:35:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704238512; cv=none; d=google.com; s=arc-20160816; b=d+bssMcFRr6hPDuI4Meaz+BVQMF7ZB3bfKoceYyepzkiXpXD0SrwnqCH8EfW9BLgNp 39g5WGCFdQmdfRPl5M7ML8Ad7DBQJLakNRVCsD1+lpNdmolietxYUTfAGiFHzVBjW400 51WTYC+eRwqcpP1Wf21TI8MwiDP8vf4KTaeD3m7ZmKF4n0PRNiJjN6e1C1A1F/xtp3Wj dFmcr6RL9KRKg7eRMpfnMepRgsnTXmZ7KHmAER8mj9Z/EHPginY1J9ia91Jk3HdLbMdP K+LF4HKP6KwWwFMjC8GWv/BzfQUZDd8Xe3HONiJPmwQ6n6Ngdt7hwf4mUrHasm0HUYbT KpZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=fEeHN1tMa7cbdkZt1wLkdCjR844Pa9tAzIQcAD+DKkg=; fh=FwWBjM+xWJi7arR2ekAOUWY0Uxliwfm0q+bxzjcmt3o=; b=ZISdn+1d1GjVTQ1ABZzpyDpVRB5YlnE9ByclrjX6oZ6rWwo5yGc1VaMrouClYUnFBu nsOR9biw0Mfj9s+O6GBC1eD6RY0FG1sTTpUZBi6eTgDiV3STB06CUKh6QBk1FuA43C5n cawGcD2irY/p2ZEWidykrB+r3XnoN5qDKMyXrpyiLK3+CbwAE/D3pqa+EDkos702HSDt GB1Y45gDRgEbndi91OFL/fZi9pOg8PKyHgKNzupclfDhtJMQPMFYWV1AbgRZU+zTQLIR xgfZyN2s5OBPM7bYleOICW1gxi+P7zmEKq8v8LF4Y0PjNV2JDrjkr1fFqnk/zMWF9Det LptA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=TbOeiDBt; spf=pass (google.com: domain of linux-kernel+bounces-14976-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14976-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h33-20020a63f921000000b005cd8cb67fe9si21527843pgi.583.2024.01.02.15.35.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 15:35:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14976-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=TbOeiDBt; spf=pass (google.com: domain of linux-kernel+bounces-14976-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14976-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 94A54284447 for ; Tue, 2 Jan 2024 23:35:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C381817986; Tue, 2 Jan 2024 23:35:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TbOeiDBt" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA01E1774B for ; Tue, 2 Jan 2024 23:35:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-dbdb8e032f7so7548030276.1 for ; Tue, 02 Jan 2024 15:35:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704238499; x=1704843299; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=fEeHN1tMa7cbdkZt1wLkdCjR844Pa9tAzIQcAD+DKkg=; b=TbOeiDBtMM3VQzjCTx+vQzqEIsYMMdfafBnQb4OL9mNorkV5EVEzF/E6NRsVum344u FH/bSMVREJ8A5uDjwuyQ/bdSS9fP/umdMFtbn8uWhQfIshTaW2YnOlpM3pciFbN/CPv9 iFkwuyFKJbQoTfnTez2h7ICI1niZtRTCBExGwMLtqxOSEAkW2P0Ce9kEcLmjAnCrXxCj yc2w31Tg7r/gYkQBS8bIzdev1VnKLZS7Mlcvp3I79+7CSdCLwFTwlmXGXDM6hDrDBGlu rcGZVs2jQ6Lsa5urffJeSOnr1kFc2iMX9k0pUEwipPkTragdetDOcF8QIc4SnGOiFF+K l+Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704238499; x=1704843299; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fEeHN1tMa7cbdkZt1wLkdCjR844Pa9tAzIQcAD+DKkg=; b=jTFdeDGALkojQwqxFqZC2uEdn2aYyojbVqEN+58XOiQGKrpgbPovOuyrQvlSm9kXV4 ZSlqLm+BxDiRavmdff7JI1JatrQPtIl3reS6IxvBQzAOAaK/4Jf3sYrssMFcFhDiXr2L dmXvHqOca7LFysimW9qMb4FSa5IPEmgopLAuncjBBC+IHkpFgDNKVNpg1ygyYTNu826X SJX5aak4iep2UdfpaI+fpxNh8kiM543x0J2vytx1AYXYhn+ZzJeQedc9O+SAYqnVSHYh aLKgEWWbfTckWGfVt3lGiRdztLGOHYDmA+EHwVVKzqoLJ17RPk2CuKiAbyQib4sJ0iMu 26Kw== X-Gm-Message-State: AOJu0YzzhmjPqEmCDFZ13GSJXVhd9raXWhIt475JIY3nUkBBndWEsWYt +lFA7nMkD3IZ4fVTox0DfXMnPxsV8FybOiVOZY3AZfJZvxd4 X-Received: by 2002:a5b:7c3:0:b0:db5:4ec5:6f2f with SMTP id t3-20020a5b07c3000000b00db54ec56f2fmr129240ybq.20.1704238499402; Tue, 02 Jan 2024 15:34:59 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231230025607.2476912-1-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Tue, 2 Jan 2024 15:34:46 -0800 Message-ID: Subject: Re: [PATCH 1/1] userfaultfd: fix move_pages_pte() splitting folio under RCU read lock To: Peter Xu Cc: akpm@linux-foundation.org, viro@zeniv.linux.org.uk, brauner@kernel.org, shuah@kernel.org, aarcange@redhat.com, lokeshgidra@google.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, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jan 2, 2024 at 3:16=E2=80=AFPM Suren Baghdasaryan wrote: > > On Tue, Jan 2, 2024 at 8:58=E2=80=AFAM Suren Baghdasaryan wrote: > > > > On Tue, Jan 2, 2024 at 1:00=E2=80=AFAM Peter Xu wro= te: > > > > > > On Fri, Dec 29, 2023 at 06:56:07PM -0800, Suren Baghdasaryan wrote: > > > > @@ -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 =3D dst_pte =3D NULL; > > > > err =3D split_folio(src_folio); > > > > if (err) > > > > goto out; > > > > + goto retry; > > > > } > > > > > > Do we also need to clear src_folio and src_folio_pte? If the folio i= s a > > > thp, I think it means it's pte mapped here. Then after the split we m= ay > > > want to fetch the small folio after the split, not the head one? > > > > I think we need to re-fetch the src_folio only if the src_addr falls > > into a non-head page. Looking at the __split_huge_page(), the head > > page is skipped in the last loop, so I think it should stay valid. > > That said, maybe it's just an implementation detail of the > > __split_huge_page() and I should not rely on that and refetch anyway? > > I'll post a v2 with this fix and re-fetching the folio > unconditionally. We also don't need to reset src_folio_pte value > because it's used only if src_folio is not NULL. Posted at https://lore.kernel.org/all/20240102233256.1077959-1-surenb@googl= e.com/ > Thanks for catching this, Peter! > > > > > > > > > -- > > > Peter Xu > > >