Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6826358rdb; Tue, 2 Jan 2024 15:16:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXsRhvog01K/BJUqcGThwANgMNIeWd6NJlfTTQO7EpMOPlRhQcJywnUhDEPe0XolAPysWm X-Received: by 2002:a05:6a00:130f:b0:6d9:b5cb:d773 with SMTP id j15-20020a056a00130f00b006d9b5cbd773mr238200pfu.22.1704237407327; Tue, 02 Jan 2024 15:16:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704237407; cv=none; d=google.com; s=arc-20160816; b=wgcuH0SYof3EPLl1uYbmGW23+xIu4YBCFG8tNkiuEIb5b0oEsQPeyEaTgRS0R8OnTP q6eHzvzdzF5brqRwmv9wSbF02PLZBU79Q6ytdpdyp3+xpB5rGPrXBDTnt9iSZM6Vk1yt PYwG27v0HYmcX/iSGg+S7JLHdiVyScXVCDnizku4FoxjIHgvs8F9sIbyL+tqDV+FycGR rcrlS7K3Urr4xyCTawvpzZNUsHYJMa7WNB4SdrsA2YAh4P/i6rM/4je9kTAV4AmaoLYI CautuU3OrsENa4qMqTwA+CfgpR4haUfO+S6Nur83Q1sxaZYZkK48u4lT/eUqzJvI9vld +YOA== 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=W9VsReBQkICOIEczr/aBz2S0AWm3omPhTa+sgYDFysE=; fh=FwWBjM+xWJi7arR2ekAOUWY0Uxliwfm0q+bxzjcmt3o=; b=FfhszKeXPNyQtIL5aRO5rRNCzuaLOSbMq+XqXaW6kjZsktUuV7BZlb0PSHNyy8xbu1 wrFqjTcMyX3jXEu5IMf7H8gl1HcHJrz3CAOOp9HrrWYhGNEAD9xZ6E5obccOeF56OnFQ NXgF/22YJsWZAwMnDu5rv5eJ1T5JI0frXTdlcQTWnrv5Jvo+8I4j0VW2sRfWxDEp1pW8 Qi2mqjHhTp1p8UykxXHcLviRVqfmqeOzHEOP6TA+yky5hiLiL55L7+K/lJU7LhKtHd/Y PhUjQtjpeZ+lp+mDykubN6KyxrmC/+GGqU4oAOrwW19QqPwtW/nvtaaBSqxoPWrpx/o3 8WyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=n7U12ke9; spf=pass (google.com: domain of linux-kernel+bounces-14967-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14967-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 c21-20020aa78815000000b00690f9e835d8si15346563pfo.132.2024.01.02.15.16.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 15:16:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14967-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=n7U12ke9; spf=pass (google.com: domain of linux-kernel+bounces-14967-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14967-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 7EC6C28490A for ; Tue, 2 Jan 2024 23:16:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 710D817751; Tue, 2 Jan 2024 23:16:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="n7U12ke9" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) (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 D45151773D for ; Tue, 2 Jan 2024 23:16:34 +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-yw1-f173.google.com with SMTP id 00721157ae682-5e784ce9bb8so74554387b3.0 for ; Tue, 02 Jan 2024 15:16:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704237394; x=1704842194; 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=W9VsReBQkICOIEczr/aBz2S0AWm3omPhTa+sgYDFysE=; b=n7U12ke9HUlf9h9JIl4Hr4vTl35sGXHRFMUgb0qxklXMMaAXtpchclYkN9V5/aUTEl Tr+qgAczELBPYnbHzYrM0+3gFdEDFDtoO4vEaRIUxgUQ1qF2AcB5wFnuhKA0ns+ZuYJY V6ZvLt2PtpBTCrbg+9RgWIms6P5JcQDd22XEI7HCgmpV+hjmECCUX2U+6ilocGPbSpzv jZc10ZpGudzYXnBg3WhZ2ITPdYtunH+Jt8XWEV4k444EEbqZ8gBgZxFEgLJLFEht3sA/ DyfYjkWmuVp9mjOQ/184BWYsOQdG/a9KSLWXv/ZUXjGxdK7X7brrHc060NlcRki7zmK8 vCrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704237394; x=1704842194; 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=W9VsReBQkICOIEczr/aBz2S0AWm3omPhTa+sgYDFysE=; b=LaihvGiPy2QKsoNNj2KJ6l6PKnunfetFABc+JZCP9Q30WX1bTRvlV7DaKinR/ciZfN ZctZVc+lUXNNjchVvUIqakooLEsbd26nil9if5KoHH/9MAEIX0kWOsWehbli5BIs5DKI OJ6Gqz56bA5O0bgKaXZOS/0T+lAuapZs72NPXWAgPHg26Sn2jMgXrdovcCc3ZBwvmaR1 TjVagB6v6MlkxGt3l/32+TOH9YTfjyitVGIVGd9NOpfDENUhWDn5oFbaau4tuyCd60iR L/+JE8WVui/aFadbFR2sMg54pJhBHcmEzBvqMmlEs7/uVKog8bC8A+UwZfVJ81ixkWbv ++fg== X-Gm-Message-State: AOJu0YzObujLMqX8SaK1Ik2TtLFHgrtZb5bOrGA2UZQFEgkM8eI4qCj5 ebytUBk37tXeuA6cU/DGuF5QGeEDK6Gk/edPPfCAoBVcQ+Ev X-Received: by 2002:a81:574d:0:b0:5d3:dacc:63bd with SMTP id l74-20020a81574d000000b005d3dacc63bdmr108135ywb.19.1704237393551; Tue, 02 Jan 2024 15:16:33 -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:16:20 -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 8:58=E2=80=AFAM Suren Baghdasaryan wrote: > > On Tue, Jan 2, 2024 at 1:00=E2=80=AFAM Peter Xu wrote= : > > > > 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 is = a > > thp, I think it means it's pte mapped here. Then after the split we may > > 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. Thanks for catching this, Peter! > > > > > -- > > Peter Xu > >