Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3690447rdh; Thu, 28 Sep 2023 22:13:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFiFa0g1PXGw3ZTWeNkgoe4VkFdzS6n/pFu/eDaEHFqKFBIKqBlk6ESdK17eFtLCx3mzOPm X-Received: by 2002:a05:6a20:1387:b0:14d:c05c:6620 with SMTP id hn7-20020a056a20138700b0014dc05c6620mr2789201pzc.31.1695964406173; Thu, 28 Sep 2023 22:13:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695964406; cv=none; d=google.com; s=arc-20160816; b=Wf5FefWeyKILSSgRpclWbg7x4JSUUXNGCN/tJd0bdN5ksIDi/gZvY66wPQzwP/E04D XuukLO/96cYy1AE73Wf6oil+17BQpw3T7tD8iXJNB0Z5yNOgm7YVCKgokl/PP22oi9xr I+N60yJU4hvhYFWGw2DgwczTOWa/SpMZvnhG5P/YEg7ALfHEOSNHwhXX4fCp8PvYwap2 Lfv2as7WgAUx5Mi9QeDIJbWIaH6fiK1iDjo8zTAZocBzz0iaLMTLLYHUcCsckPFyZ0wh iJ2EKQ+OKwfkX+4dd2fv+RyhWc3Q8Bx1kdhE9g6d+8wgTgUDbE+h+U/jmtshgKelhhGO FPfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=6e7z54uATHSSGDjwccq5t2JrfgU8sx45IO2zPYWKTu4=; fh=CSuDgYekrq/8xohxdhTcSkjlTNz4+09bzaOInK8h7Vw=; b=wzTkY7V3liLbus+XUZUtfm5tYzV0MVCOQOTiUb6hOmqUqo2cPg0kW0TnMaILuWCZcW ZMJTkcIGxc+EqD1lDW/1YLCGe+zK7Mnr7htpLoxs4yQK9RplCRnzuIx+ZwI+Kql3n0ZC kWNeWEUHJ01hXYjZ3NGdNRHdhUr/Ot3ed6GnM3Ii2loNkDXaC89hgA1iekvdGmxnyqhi /YbdEnevsw8IR7qxqxfRi1BWCdWUeM3tzxvC0bC8DL1OKx/sagnU+r92vBHuA2i06/tX wlzMsapxlqTuMp1PaXaIPGwyhX3dghyRQU4lKd2qKsUZx43TkR3MwsnwG4CBjWP0tg/s J5dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=y8sNghs5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id f10-20020a65550a000000b00573fe48c908si19426877pgr.128.2023.09.28.22.13.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 22:13:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=y8sNghs5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id AEB5E82A54E4; Thu, 28 Sep 2023 08:36:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231847AbjI1Pgq (ORCPT + 99 others); Thu, 28 Sep 2023 11:36:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231722AbjI1Pgp (ORCPT ); Thu, 28 Sep 2023 11:36:45 -0400 Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45D32C0 for ; Thu, 28 Sep 2023 08:36:43 -0700 (PDT) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-59bc956b029so160779437b3.2 for ; Thu, 28 Sep 2023 08:36:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695915402; x=1696520202; 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=6e7z54uATHSSGDjwccq5t2JrfgU8sx45IO2zPYWKTu4=; b=y8sNghs5WMsnE7q6gtrMdqawiQAkTO1W5wa6oeNCXaAnuO5coljUYTKHQIIfk2EMz2 O25kuKl7THw2USeCRD4TNJVsZHVtZ1giiId7FZ0JqmdU8ZVSd9+kN47fAiKLStgbEb5e usE/N6m4Y0cwIdXKW/u6KHbCvCTczaAfx6pF2X0UF37Pq1+fMjvdpI14KJbH1zDBDIl/ juh4k3DFjFMvD9wNeCDGpfw5WWXogmG6cItwx4IfXa2Cfau+P2POuvxTuixFc80Nthod UaUhXr0/TzzolcftVars+LAO0gPugAto8XVIVPAGnG+4SWS5OlQWIBrONT8wGIJMwPGd Q6Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695915402; x=1696520202; 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=6e7z54uATHSSGDjwccq5t2JrfgU8sx45IO2zPYWKTu4=; b=CTp5JQDQKbap8SIWJqwov6sbTqk+CT8pVzBBoeLjxfw6+H2WjzjenFM+sYBdAZdDwm 8FqXP2tz6jftGbKqjzpSLuDsTBUkgcmnGlTdbaTRvru2X8BG4GQudvXMmYZHDmVTYfH8 jsMie8qxS/bbkCYOSjiu5nqewX87QmdOX7Q0wajo0A6q3TEXZ95ae3BRnlbKPKA10twZ 1svD32oi4ad0FeSAPip8af14WSWgtHQCUEqz43Zg+OZBf7lK/hUPn9hCFWzs890hit4Z 6g2sHbq52C070ya6FZH9NQ7aLMdmLGBylvlR1fpMVhR886yqQGpdbhz7SSBhIHoZhD7Y M2Dg== X-Gm-Message-State: AOJu0YxE/75PeSteUUN6warCIgaTIMvhtIP9rAjmU5ieiFm0KLNTROr0 0djXWeCHWgF2eeZQKXCyS0D8tqCdseniX9+SN8pNJw== X-Received: by 2002:a81:4e85:0:b0:569:479f:6d7f with SMTP id c127-20020a814e85000000b00569479f6d7fmr1392570ywb.43.1695915402166; Thu, 28 Sep 2023 08:36:42 -0700 (PDT) MIME-Version: 1.0 References: <20230923013148.1390521-1-surenb@google.com> <20230923013148.1390521-3-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 28 Sep 2023 08:36:31 -0700 Message-ID: Subject: Re: [PATCH v2 2/3] userfaultfd: UFFDIO_REMAP uABI To: Jann Horn Cc: akpm@linux-foundation.org, viro@zeniv.linux.org.uk, brauner@kernel.org, shuah@kernel.org, aarcange@redhat.com, lokeshgidra@google.com, peterx@redhat.com, david@redhat.com, hughd@google.com, mhocko@suse.com, axelrasmussen@google.com, rppt@kernel.org, willy@infradead.org, Liam.Howlett@oracle.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 X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 28 Sep 2023 08:36:56 -0700 (PDT) On Wed, Sep 27, 2023 at 3:49=E2=80=AFPM Jann Horn wrote: > > On Wed, Sep 27, 2023 at 11:08=E2=80=AFPM Suren Baghdasaryan wrote: > > On Wed, Sep 27, 2023 at 1:42=E2=80=AFPM Suren Baghdasaryan wrote: > > > > > > On Wed, Sep 27, 2023 at 1:04=E2=80=AFPM Jann Horn = wrote: > > > > > > > > On Wed, Sep 27, 2023 at 8:08=E2=80=AFPM Suren Baghdasaryan wrote: > > > > > On Wed, Sep 27, 2023 at 5:47=E2=80=AFAM Jann Horn wrote: > > > > > > On Sat, Sep 23, 2023 at 3:31=E2=80=AFAM Suren Baghdasaryan wrote: > > > > > > > + dst_pmdval =3D pmdp_get_lockless(dst_pmd); > > > > > > > + /* > > > > > > > + * If the dst_pmd is mapped as THP don't over= ride it and just > > > > > > > + * be strict. If dst_pmd changes into TPH aft= er this check, the > > > > > > > + * remap_pages_huge_pmd() will detect the cha= nge and retry > > > > > > > + * while remap_pages_pte() will detect the ch= ange and fail. > > > > > > > + */ > > > > > > > + if (unlikely(pmd_trans_huge(dst_pmdval))) { > > > > > > > + err =3D -EEXIST; > > > > > > > + break; > > > > > > > + } > > > > > > > + > > > > > > > + ptl =3D pmd_trans_huge_lock(src_pmd, src_vma)= ; > > > > > > > + if (ptl && !pmd_trans_huge(*src_pmd)) { > > > > > > > + spin_unlock(ptl); > > > > > > > + ptl =3D NULL; > > > > > > > + } > > > > > > > > > > > > This still looks wrong - we do still have to split_huge_pmd() > > > > > > somewhere so that remap_pages_pte() works. > > > > > > > > > > Hmm, I guess this extra check is not even needed... > > > > > > > > Hm, and instead we'd bail at the pte_offset_map_nolock() in > > > > remap_pages_pte()? I guess that's unusual but works... > > > > > > Yes, that's what I was thinking but I agree, that seems fragile. Mayb= e > > > just bail out early if (ptl && !pmd_trans_huge())? > > > > No, actually we can still handle is_swap_pmd() case by splitting it > > and remapping the individual ptes. So, I can bail out only in case of > > pmd_devmap(). > > FWIW I only learned today that "real" swap PMDs don't actually exist - > only migration entries, which are encoded as swap PMDs, exist. You can > see that when you look through the cases that something like > __split_huge_pmd() or zap_pmd_range() actually handles. Ah, good point. > > So I think if you wanted to handle all the PMD types properly here > without splitting, you could do that without _too_ much extra code. > But idk if it's worth it. Yeah, I guess I can call pmd_migration_entry_wait() and retry by returning EAGAIN, similar to how remap_pages_pte() handles PTE migration. Looks simple enough. Thanks for all the pointers! I'll start cooking the next version.