Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2482137rdb; Sun, 3 Dec 2023 20:09:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEWcX3Tyh4phrhidiz1ueloNoryYoeXtkFk1UqXz3VccJhFVvoCgbBF3k64G/tXI8RH4GIx X-Received: by 2002:a05:6a00:2918:b0:6bd:3157:2dfe with SMTP id cg24-20020a056a00291800b006bd31572dfemr1324258pfb.7.1701662986900; Sun, 03 Dec 2023 20:09:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701662986; cv=none; d=google.com; s=arc-20160816; b=AtFSyBthXuzsT7Z5GwEqNgMkYQNh3bobIrn3ySBx6VttGCNm2bE9e6vJFT8arPUCsu b992PJLyHFrKI0bzzkrFvnSw5mGNR9A81oIQP4crMJrXXY4A2R1HSKETUz7OA9VsCHMr A6dix5wC7O5YAS3As00omxWGYhtvKP2jE4869h6aRZ0EFOAYAiBZjliraPWEJfnaZumO MwGZF9dbWdqQE7zo5BqcKNF9svsKsf4VCgPrBJDgd2ZbaSz88HIpNipAbPoOrCOwteQd KUp6R71WnGV4EjAR2qwJbMLJobpW+ozMLzkDKE5i0t1YReRbKEYApfipANcrXuQwxZH4 QThw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=GYEy8kccuU/d4RqwnKbLSWjVNxsFIN3X39pgAqk88hU=; fh=BonCDYkT2j1VY/AgyhOKqEQ33f4iRxSkOH4YtEHP3pE=; b=sC60C2JugEcC2sDKRQGpoRIePf66mdso8oS/xq35/WRKXesQyXi3tH9G86U6SGRJUD Ef/BC3C/3nJdtzDwnXduyPo4l2fiIitkyYRUSpr9qOsRUUw97yWcTjaUkoP2M1NFUyhV HuTR52cxO/9PJDiiqJlhK/StjH2Rr+zWAIgtrOTXjyEwc6TXhwRmZQT+ScSg3iVWqefr ThmbExMiqEn8oaaTIB7XLTey37JbxHsHAr5UHDrEVdXQiNvPMmLaw2x5p0cWLK6NpSO8 2CU1WOi5UR9+CHZ092x8KS4EXUbhRllDIOUUxBHY5R6ZOf7nV0SRuxXx9VPx2g3fFkr/ QdbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=hPQWM4gu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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. [23.128.96.36]) by mx.google.com with ESMTPS id h14-20020a056a00218e00b006cbee42fbb9si7171586pfi.119.2023.12.03.20.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 20:09:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=hPQWM4gu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 3A27C8047450; Sun, 3 Dec 2023 20:09:44 -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 S234378AbjLDEJU (ORCPT + 99 others); Sun, 3 Dec 2023 23:09:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbjLDEJT (ORCPT ); Sun, 3 Dec 2023 23:09:19 -0500 Received: from mail-yw1-x112d.google.com (mail-yw1-x112d.google.com [IPv6:2607:f8b0:4864:20::112d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70C26D7 for ; Sun, 3 Dec 2023 20:09:23 -0800 (PST) Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-5d4f71f7e9fso25417657b3.0 for ; Sun, 03 Dec 2023 20:09:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701662962; x=1702267762; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=GYEy8kccuU/d4RqwnKbLSWjVNxsFIN3X39pgAqk88hU=; b=hPQWM4guKMEQxD47inyd24oqA2s6SnJ5TgqtpCndXN0KR1dplAPskCO4ELfJVTd//j Km4lVjWDOpSeeIeLEyEP//+EnJX544L3wPrGdl/GeUOmEC1Bkor6vqaVnZPPFbUKUoxn isN+OZKTLV1A0AH/ufBb1VhLYSRgXdZJABX7CV8mWFvVvviTS8lnbXZkaBYBJJdM3NLy RPdVk33+LwHWUW/oJt5MWDcKmSNBNKabInSEwmcngBR40dwp2J7zCmFdRRiTt9j3EeUG KkIE6ZdOi17fE4iYEgt5KMQhQpWLZT3tE20yREeSS7MhF7xb/V/xUOFK2SPf9m4sM1r/ KUlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701662962; x=1702267762; h=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=GYEy8kccuU/d4RqwnKbLSWjVNxsFIN3X39pgAqk88hU=; b=bmi5pcl9qMtTz03XQ6drqAJWG91HUuCuTCplJuZ+xcmtpXdZDYb4HzfZK2cJEGLa2m +Bpj+O6Hn/Lcp43dX00MqGeuXfJ/SG9x4Pj2Yt5+o7+Ycbmtb/wPlczM0MDThziUwXeA CK7h+JUAVpa8xVFLMxkujAOtv70/E9htzkcXb2XIMGSZRrfa/PcyQHRdLyA3oobY5uJ6 rk0qERNW+ETb0LJczuML0kwZYgcuSUa7gpCIBocPmSVQCikTc8MljUDcGcM1rFZss96r z0IEmVeZoaTOC3bg+6YB3Djc/Y35nph2kRvc0BVuHGLsOc1aWC/swG5uDbLtanV+GGTI YEzg== X-Gm-Message-State: AOJu0YxHuIHm77hrE1AWfgCSYRrrKOxqxU/Fcv3Ln+7AiUX2fGwQJIX4 gbcpnH1TkrBIdk+SFBr5aSAwzix3HbxxySJxdczFBA== X-Received: by 2002:a05:690c:f85:b0:5d7:1940:dd62 with SMTP id df5-20020a05690c0f8500b005d71940dd62mr2260818ywb.56.1701662962373; Sun, 03 Dec 2023 20:09:22 -0800 (PST) MIME-Version: 1.0 References: <20231121171643.3719880-1-surenb@google.com> <20231121171643.3719880-6-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Sun, 3 Dec 2023 20:09:09 -0800 Message-ID: Subject: Re: [PATCH v5 5/5] selftests/mm: add UFFDIO_MOVE ioctl test To: David Hildenbrand Cc: Ryan Roberts , akpm@linux-foundation.org, 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: multipart/mixed; boundary="00000000000066ca67060ba74878" 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]); Sun, 03 Dec 2023 20:09:44 -0800 (PST) --00000000000066ca67060ba74878 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 destination buffer > >>>> should match the original source buffer's content while the source > >>>> buffer should be zeroed. Separate tests are designed for PMD aligned= and > >>>> unaligned cases because they utilize different code paths in the ker= nel. > >>>> > >>>> 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 offset, bo= ol 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", offset, 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 (errno=3D16= , > >>> @uffd-common.c:648) > >>> > >>> I'm running in a VM on Apple M2 (arm64). I haven't debugged any furth= er, 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 kernel; see ot= her email > > for full config. > > > >> > >> I can spot that uffd_move_pmd_test()/uffd_move_pmd_handle_fault() uses > >> default_huge_page_size(), which reads the default hugetlb size. > > > > My kernel command line is explicitly seting the default huge page 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 virtual > area we are testing with, and that we do seem to get more odd patterns > on arm64. > > uffd_move_test_common() is a bit more elaborate, but if we aligned the > src+start area up, surely "step_count" cannot be left unmodified? > > So assuming we get either an unaligned source or an unaligned dst from > mmap(), I am not convinced that we won't be moving areas that are 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 missing > 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 after replacing default_huge_page_size() with read_pmd_pagesize(), the move-pmd test started working for me. Ryan, could you please apply attached patches (over mm-unstable) and try the test again? Thanks, Suren. > > -- > Cheers, > > David / dhildenb > --00000000000066ca67060ba74878 Content-Type: text/x-patch; charset="US-ASCII"; name="0001-userfaultfd-split-large-pmd-mapped-folio.patch" Content-Disposition: attachment; filename="0001-userfaultfd-split-large-pmd-mapped-folio.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lpqe5cp81 RnJvbSBjYmQ0MzQ4NDg0OTg2MTkzYzQ1MjM1YmFiYmFlNmUzMDMxOGQ5ZTQ4IE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBTdXJlbiBCYWdoZGFzYXJ5YW4gPHN1cmVuYkBnb29nbGUuY29t PgpEYXRlOiBTdW4sIDMgRGVjIDIwMjMgMTk6NTM6NDUgLTA4MDAKU3ViamVjdDogW1BBVENIIDEv Ml0gdXNlcmZhdWx0ZmQ6IHNwbGl0IGxhcmdlIHBtZC1tYXBwZWQgZm9saW8KClNpZ25lZC1vZmYt Ynk6IFN1cmVuIEJhZ2hkYXNhcnlhbiA8c3VyZW5iQGdvb2dsZS5jb20+Ci0tLQogbW0vdXNlcmZh dWx0ZmQuYyB8IDE3ICsrKysrKysrKysrKysrKysrCiAxIGZpbGUgY2hhbmdlZCwgMTcgaW5zZXJ0 aW9ucygrKQoKZGlmZiAtLWdpdCBhL21tL3VzZXJmYXVsdGZkLmMgYi9tbS91c2VyZmF1bHRmZC5j CmluZGV4IDcxZDAyODFmMTE2Mi4uNmU2ZjY3MjA2N2ZlIDEwMDY0NAotLS0gYS9tbS91c2VyZmF1 bHRmZC5jCisrKyBiL21tL3VzZXJmYXVsdGZkLmMKQEAgLTEzODIsOCArMTM4MiwyNSBAQCBzc2l6 ZV90IG1vdmVfcGFnZXMoc3RydWN0IHVzZXJmYXVsdGZkX2N0eCAqY3R4LCBzdHJ1Y3QgbW1fc3Ry dWN0ICptbSwKIAkJCS8qIENoZWNrIGlmIHdlIGNhbiBtb3ZlIHRoZSBwbWQgd2l0aG91dCBzcGxp dHRpbmcgaXQuICovCiAJCQlpZiAobW92ZV9zcGxpdHNfaHVnZV9wbWQoZHN0X2FkZHIsIHNyY19h ZGRyLCBzcmNfc3RhcnQgKyBsZW4pIHx8CiAJCQkgICAgIXBtZF9ub25lKGRzdF9wbWR2YWwpKSB7 CisJCQkJc3RydWN0IGZvbGlvICpmb2xpbyA9IHBmbl9mb2xpbyhwbWRfcGZuKCpzcmNfcG1kKSk7 CisJCQkJaWYgKCFmb2xpbyB8fCAhUGFnZUFub25FeGNsdXNpdmUoJmZvbGlvLT5wYWdlKSkgewor CQkJCQlzcGluX3VubG9jayhwdGwpOworCQkJCQllcnIgPSAtRUJVU1k7CisJCQkJCWJyZWFrOwor CQkJCX0KKwkJCQlmb2xpb19nZXQoZm9saW8pOwogCQkJCXNwaW5fdW5sb2NrKHB0bCk7CiAJCQkJ c3BsaXRfaHVnZV9wbWQoc3JjX3ZtYSwgc3JjX3BtZCwgc3JjX2FkZHIpOworCQkJCWlmIChmb2xp b190ZXN0X2xhcmdlKGZvbGlvKSkgeworCQkJCQlmb2xpb19sb2NrKGZvbGlvKTsKKwkJCQkJZXJy ID0gc3BsaXRfZm9saW8oZm9saW8pOworCQkJCQlmb2xpb191bmxvY2soZm9saW8pOworCQkJCQlp ZiAoZXJyKSB7CisJCQkJCQlmb2xpb19wdXQoZm9saW8pOworCQkJCQkJYnJlYWs7CisJCQkJCX0K KwkJCQl9CisJCQkJZm9saW9fcHV0KGZvbGlvKTsKIAkJCQljb250aW51ZTsKIAkJCX0KIAotLSAK Mi40My4wLnJjMi40NTEuZzg2MzFiYzc0NzItZ29vZwoK --00000000000066ca67060ba74878 Content-Type: text/x-patch; charset="US-ASCII"; name="0002-selftests-mm-use-correct-function-to-obtain-huge-pag.patch" Content-Disposition: attachment; filename="0002-selftests-mm-use-correct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