Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp882057rdb; Wed, 6 Dec 2023 02:40:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMD1cnJsxJZpa+lBJChNGbyF4DMbtfu6l/m9WRLVcS2uhsg2BnNjAx/504yA9Rl67ljzf/ X-Received: by 2002:a05:6a20:7484:b0:18f:97c:615d with SMTP id p4-20020a056a20748400b0018f097c615dmr797749pzd.90.1701859213895; Wed, 06 Dec 2023 02:40:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701859213; cv=none; d=google.com; s=arc-20160816; b=p7BZcoCRcmyvQZOgOiUFJ7UjdVNuebFU6rC168yHAPe6WjbMMJxqlWWCLgIJ9hGmgB GTKz9zX3wYO+EkwhUdepdeSoSv4pPYCUIH0tIHyeppRyxVOwttpxhXKVGjgIKiuTD7/+ nYiGbSUU1WRZ1TRrtQuK5wRW28EkhW/RUWPbDNyf1buYWPqRMmYDmNhHmuOv7upPfCQK r2c31UfyPCUu4+7YoAVm2t+LXG4vuGRQrDudohGN4NJTCn6tbBg6JrIjePYqsbWd9QJa G4bwYIxvsTa+SNstgU2a5SpRgrk6ZqEVoOLcEG/MXJPvjP/kJ6SgU0+xLe+36LjYmEP4 ZR0Q== 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=iQdifr2abX3HSlYGNn9HZ0F9hnYIWmyEvcln+QnyZu0=; fh=xCuToMpXzU6CtgaOGRLq6lsUv2FaJhgAb3MSDjExFvc=; b=JLEVgUm5/sapl2g+CzcRKR73bNTs1Znk5PV5TpnDUIDzIibmOtmiw274o2/1EBLcKw gZTQ0aNDdTMgtdfutuMcDFp74XdADu+rEU1HetqJtGmX459mFU3qobThG5yrVRFigg7s PQZhVlWWp9HbVP8ucK+5LSobytNm1jfq9PycvJeqG53L7YE/ixrcVjFxfVJRY7wOq5YF Ta61HRLtYb13bQV4Y1+M4FxLo5xXVku5L4yppQ2mYa+XlEzUZ8JgGXV9mlnlp0flq9AL MkJzFMKmj6dEi2k9IyrI5bgBYxC6cfzFVmTwqXi6rq/RKI2SBWfXCRJ/RQe9gvrgKmC1 NuYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZA0JY6sY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id dn17-20020a056a00499100b006ce36ffa532si6834780pfb.380.2023.12.06.02.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 02:40:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZA0JY6sY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 805B581A73C7; Wed, 6 Dec 2023 02:40:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377494AbjLFKjs (ORCPT + 99 others); Wed, 6 Dec 2023 05:39:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377470AbjLFKjq (ORCPT ); Wed, 6 Dec 2023 05:39:46 -0500 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19282D46 for ; Wed, 6 Dec 2023 02:39:52 -0800 (PST) Received: by mail-yb1-xb2e.google.com with SMTP id 3f1490d57ef6-db979bbae81so2680577276.0 for ; Wed, 06 Dec 2023 02:39:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701859191; x=1702463991; 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=iQdifr2abX3HSlYGNn9HZ0F9hnYIWmyEvcln+QnyZu0=; b=ZA0JY6sYzQ/jma2tyO02AcQA7bVyW6bB2WA00xr1dxomv8CTzVw9lCIAJu3BEWSiHt 4B7ZHctwldguKE6PEK9VfadO8oZ2KrQsSMzEEHSN7EgMIpJjgqaMdzMtGyZq7+ZKW2hs G2m+o1q241/t1Q9Rq9KG5dq6VQwU4DkV9HuQnLMzh+Y177kuxgwTmoocyNK/qtn0m1+F t92gf18JDNn3eUisFoH/WYKPXll7WXeg2qtd4PmMgTfDMv9+cwwqw7ITtwdCO8NDwx9y 3GXJYEedk056RgRkY1cLYo3qiAg6sZF1Nlb6o2TK0phsa1ld6jg8/6JjNZayj9qtD50x 61Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701859191; x=1702463991; 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=iQdifr2abX3HSlYGNn9HZ0F9hnYIWmyEvcln+QnyZu0=; b=l40r+V0FG7z1jjWXGAfSa4iksy3pu9u0NM7zCfUkMYt/U1Mw3cRvnb2CywJyFrl1ve PCy9BAXgbJNsliqTr3reK5ROiQzMknzVULnbKZZ0r6S5CARP9pcQVPcqrJf78Nvewc8h JTteIm5m0i6VrppNVPTtHao2TJu/tj/8F6flZ3Q+avOZZl9hLhkleFQS82dSgTDXvME6 XYjb4pqa96eW4+Nx5+e5L+NH6AqPpTF63K3dBQq0luIiap1JF/cpd2EsPQ3qvPw79xIi +nG9XmUFmb1TuRjX14ws0ea6RhrtEftrHYrPY3dUcqY7FgfBUDvy9JQa4iSQ7v/x+B2M ZDMQ== X-Gm-Message-State: AOJu0YzN3yqf8qS+kG8jkLcH1Xv7mqwmZpXjO9Ug6qNkNJVmfUO2UYEi FXu3PTPc8zJw3E5RIVPYVMjTKUMqqmnQigRpJ9YFRw== X-Received: by 2002:a25:1c2:0:b0:db7:dacf:4d65 with SMTP id 185-20020a2501c2000000b00db7dacf4d65mr262941ybb.97.1701859190881; Wed, 06 Dec 2023 02:39:50 -0800 (PST) MIME-Version: 1.0 References: <20231121171643.3719880-1-surenb@google.com> <20231121171643.3719880-6-surenb@google.com> <744be4e0-48e0-4c77-825c-711386dd205f@arm.com> <3ba0015b-b36e-449a-8445-0f6272694db5@redhat.com> In-Reply-To: From: Suren Baghdasaryan Date: Wed, 6 Dec 2023 02:39:39 -0800 Message-ID: Subject: Re: [PATCH v5 5/5] selftests/mm: add UFFDIO_MOVE ioctl test To: akpm@linux-foundation.org Cc: David Hildenbrand , Ryan Roberts , viro@zeniv.linux.org.uk, brauner@kernel.org, shuah@kernel.org, aarcange@redhat.com, lokeshgidra@google.com, peterx@redhat.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 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,T_SCC_BODY_TEXT_LINE, 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 pete.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 (pete.vger.email [0.0.0.0]); Wed, 06 Dec 2023 02:40:10 -0800 (PST) On Wed, Dec 6, 2023 at 2:30=E2=80=AFAM Suren Baghdasaryan wrote: > > On Wed, Dec 6, 2023 at 1:21=E2=80=AFAM David Hildenbrand wrote: > > > > On 05.12.23 05:46, Suren Baghdasaryan wrote: > > > On Mon, Dec 4, 2023 at 10:44=E2=80=AFAM Suren Baghdasaryan wrote: > > >> > > >> On Mon, Dec 4, 2023 at 10:27=E2=80=AFAM David Hildenbrand wrote: > > >>> > > >>> On 04.12.23 17:35, Suren Baghdasaryan wrote: > > >>>> On Mon, Dec 4, 2023 at 1:27=E2=80=AFAM Ryan Roberts wrote: > > >>>>> > > >>>>> On 04/12/2023 04:09, Suren Baghdasaryan wrote: > > >>>>>> On Sat, Dec 2, 2023 at 2:11=E2=80=AFAM David Hildenbrand wrote: > > >>>>>>> > > >>>>>>> On 02.12.23 09:04, Ryan Roberts wrote: > > >>>>>>>> On 01/12/2023 20:47, David Hildenbrand wrote: > > >>>>>>>>> On 01.12.23 10:29, Ryan Roberts wrote: > > >>>>>>>>>> On 21/11/2023 17:16, Suren Baghdasaryan wrote: > > >>>>>>>>>>> Add tests for new UFFDIO_MOVE ioctl which uses uffd to move= source > > >>>>>>>>>>> into destination buffer while checking the contents of both= after > > >>>>>>>>>>> the move. After the operation the content of the destinatio= n buffer > > >>>>>>>>>>> should match the original source buffer's content while the= source > > >>>>>>>>>>> buffer should be zeroed. Separate tests are designed for PM= D aligned and > > >>>>>>>>>>> unaligned cases because they utilize different code paths i= n the kernel. > > >>>>>>>>>>> > > >>>>>>>>>>> Signed-off-by: Suren Baghdasaryan > > >>>>>>>>>>> --- > > >>>>>>>>>>> tools/testing/selftests/mm/uffd-common.c | 24 +++ > > >>>>>>>>>>> tools/testing/selftests/mm/uffd-common.h | 1 + > > >>>>>>>>>>> tools/testing/selftests/mm/uffd-unit-tests.c | 189 +++= ++++++++++++++++ > > >>>>>>>>>>> 3 files changed, 214 insertions(+) > > >>>>>>>>>>> > > >>>>>>>>>>> diff --git a/tools/testing/selftests/mm/uffd-common.c > > >>>>>>>>>>> b/tools/testing/selftests/mm/uffd-common.c > > >>>>>>>>>>> index fb3bbc77fd00..b0ac0ec2356d 100644 > > >>>>>>>>>>> --- a/tools/testing/selftests/mm/uffd-common.c > > >>>>>>>>>>> +++ b/tools/testing/selftests/mm/uffd-common.c > > >>>>>>>>>>> @@ -631,6 +631,30 @@ int copy_page(int ufd, unsigned long o= ffset, bool wp) > > >>>>>>>>>>> return __copy_page(ufd, offset, false, wp); > > >>>>>>>>>>> } > > >>>>>>>>>>> +int move_page(int ufd, unsigned long offset, unsigned= long len) > > >>>>>>>>>>> +{ > > >>>>>>>>>>> + struct uffdio_move uffdio_move; > > >>>>>>>>>>> + > > >>>>>>>>>>> + if (offset + len > nr_pages * page_size) > > >>>>>>>>>>> + err("unexpected offset %lu and length %lu\n", offs= et, len); > > >>>>>>>>>>> + uffdio_move.dst =3D (unsigned long) area_dst + offset; > > >>>>>>>>>>> + uffdio_move.src =3D (unsigned long) area_src + offset; > > >>>>>>>>>>> + uffdio_move.len =3D len; > > >>>>>>>>>>> + uffdio_move.mode =3D UFFDIO_MOVE_MODE_ALLOW_SRC_HOLES; > > >>>>>>>>>>> + uffdio_move.move =3D 0; > > >>>>>>>>>>> + if (ioctl(ufd, UFFDIO_MOVE, &uffdio_move)) { > > >>>>>>>>>>> + /* real retval in uffdio_move.move */ > > >>>>>>>>>>> + if (uffdio_move.move !=3D -EEXIST) > > >>>>>>>>>>> + err("UFFDIO_MOVE error: %"PRId64, > > >>>>>>>>>>> + (int64_t)uffdio_move.move); > > >>>>>>>>>> > > >>>>>>>>>> Hi Suren, > > >>>>>>>>>> > > >>>>>>>>>> FYI this error is triggering in mm-unstable (715b67adf4c8): > > >>>>>>>>>> > > >>>>>>>>>> Testing move-pmd on anon... ERROR: UFFDIO_MOVE error: -16 (e= rrno=3D16, > > >>>>>>>>>> @uffd-common.c:648) > > >>>>>>>>>> > > >>>>>>>>>> I'm running in a VM on Apple M2 (arm64). I haven't debugged = any further, but > > >>>>>>>>>> happy to go deeper if you can direct. > > >>>>>>>>> > > >>>>>>>>> Does it trigger reliably? Which pagesize is that kernel using= ? > > >>>>>>>> > > >>>>>>>> Yep, although very occasionally it fails with EAGAIN. 4K kerne= l; see other email > > >>>>>>>> for full config. > > >>>>>>>> > > >>>>>>>>> > > >>>>>>>>> I can spot that uffd_move_pmd_test()/uffd_move_pmd_handle_fau= lt() uses > > >>>>>>>>> default_huge_page_size(), which reads the default hugetlb siz= e. > > >>>>>>>> > > >>>>>>>> My kernel command line is explicitly seting the default huge p= age size to 2M. > > >>>>>>>> > > >>>>>>> > > >>>>>>> Okay, so that likely won't affect it. > > >>>>>>> > > >>>>>>> I can only guess that it has to do with the alignment of the vi= rtual > > >>>>>>> area we are testing with, and that we do seem to get more odd p= atterns > > >>>>>>> on arm64. > > >>>>>>> > > >>>>>>> uffd_move_test_common() is a bit more elaborate, but if we alig= ned the > > >>>>>>> src+start area up, surely "step_count" cannot be left unmodifie= d? > > >>>>>>> > > >>>>>>> So assuming we get either an unaligned source or an unaligned d= st from > > >>>>>>> mmap(), I am not convinced that we won't be moving areas that a= re not > > >>>>>>> necessarily fully backed by PMDs and maybe don't even fall into= the VMA > > >>>>>>> of interest? > > >>>>>>> > > >>>>>>> Not sure if that could trigger the THP splitting issue, though. > > >>>>>>> > > >>>>>>> But I just quickly scanned that test setup, could be I am missi= ng > > >>>>>>> something. It might make sense to just print the mmap'ed range = and the > > >>>>>>> actual ranges we are trying to move. Maybe something "obvious" = can be > > >>>>>>> observed. > > >>>>>> > > >>>>>> I was able to reproduce the issue on an Android device and after > > >>>>>> implementing David's suggestions to split the large folio and af= ter > > >>>>>> replacing default_huge_page_size() with read_pmd_pagesize(), the > > >>>>>> move-pmd test started working for me. Ryan, could you please app= ly > > >>>>>> attached patches (over mm-unstable) and try the test again? > > >>>>> > > >>>>> Yep, all fixed with those patches! > > >>>> > > >>>> Great! Thanks for testing and confirming. I'll post an updated > > >>>> patchset later today and will ask Andrew to replace the current on= e > > >>>> with it. > > >>>> I'll also look into the reasons we need to split PMD on ARM64 in t= his > > >>>> test. It's good that this happened and we were able to test the PM= D > > >>>> split path but I'm curious about the reason. It's possible my addr= ess > > >>>> alignment calculations are somehow incorrect. > > >>> > > >>> I only skimmed the diff briefly, but likely you also want to try > > >>> splitting in move_pages_pte(), if you encounter an already-pte-mapp= ed THP. > > >> > > >> Huh, good point. I might be able to move the folio splitting code in= to > > >> pte-mapped case and do a retry after splitting. That should minimize > > >> the additional code required. Will do and post a new set shortly. > > >> Thanks! > > > > > > Was planning to post an update today but need some more time. Will tr= y > > > to send it tomorrow. > > > > It would be great to have tests that cover these cases (having to > > PTE-map a PMD-mapped THP, and stumbling over an already-PTE-mapped one)= . > > Agree. Let me post the new version so that mm-unstable does not > produce these failures and will start working on covering additional > cases in the tests. The new patchset is almost ready, just finishing > final tests. Posted v6 at https://lore.kernel.org/all/20231206103702.3873743-1-surenb@go= ogle.com/. Changes are listed in the cover letter. Andrew, could you please replace the current v5 version in mm-unstable with this new one? Thanks, Suren. > > > > > -- > > Cheers, > > > > David / dhildenb > >