Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp62443rdb; Mon, 4 Dec 2023 20:48:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFAdlJdbyL5DD2NdiE0JQMw1Dk1VIeQSRMlYThkXi0J0B5h/YkMyV9StbHWRhvgPkku2S5J X-Received: by 2002:a92:dc10:0:b0:35d:5995:902e with SMTP id t16-20020a92dc10000000b0035d5995902emr3307257iln.33.1701751714433; Mon, 04 Dec 2023 20:48:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701751714; cv=none; d=google.com; s=arc-20160816; b=sG5gNf08H/PkFqi5HtBwtgkKYGYXhEsRw9K2K+zTRMVZZfvS9pp+rpmzoHkv7OjtlA MKlVL8YYskQhY7yNXagSH7diU4vXqe61txGan5E+F1RsIysTJAwbxxGAo9YQsHd1Be+j 8MDSAzPm+N0CMpwmM++5eSr9rtvmPzciWMxN2iNeCwOz5sYKAw9CctxR86YpZUnMKvHT y6Q+yX+gqZWLiIggfJKWj9WwUihfRoabmpH6ITqHN3EFZAi4GP7cBlfs3JkNQ3WzCg9c yoLVpbS7mqNDCVERmNr8CwTJ7Bxh0i4qQokEnBu22wKdF5tQ4G9iS/FcBa0j8yni2T2C m24Q== 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=PTwiqtihyMWEpX2uUmOeVlr01B75EdpPvzVSzPHU6u0=; fh=BonCDYkT2j1VY/AgyhOKqEQ33f4iRxSkOH4YtEHP3pE=; b=Q4k5JnQaz7klOxI3zp6KmoB6SvpQ7R6+1PSZw88bYYUqaN8eH5Y7QEum/ELkW73pxL jeEBiR6qKAWbFMpsO8d2wguz+e+ntjFKsLBEPzG4E8OJdGsKSTvc1gZ4gmi0dDcptjlS FZtoYJM4mWiRpPe7bPvAOFzmnsYI9TmD2DX2MYGwFYeY3dxRz0botDKou80CpTeKjIAG h56SZrFBI2A0SPqjNhtUSgklVVpGyzMqHniJMLsNvzJF6vZBw/ph0W4uE3xOC7KO1ICC uNqNSY9eMT1gwG476KlEv6GPTQsIorbGaA7fmxCJHFI6DjK+HKrNO3gy6XN5Ao92ToSV 82Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=EsROK7t2; 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 r7-20020a63d907000000b005c278464e08si5150767pgg.275.2023.12.04.20.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 20:48:34 -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=EsROK7t2; 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 70038807972C; Mon, 4 Dec 2023 20:48:31 -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 S231600AbjLEEqV (ORCPT + 99 others); Mon, 4 Dec 2023 23:46:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229611AbjLEEqU (ORCPT ); Mon, 4 Dec 2023 23:46:20 -0500 Received: from mail-yw1-x1135.google.com (mail-yw1-x1135.google.com [IPv6:2607:f8b0:4864:20::1135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1B46C0 for ; Mon, 4 Dec 2023 20:46:25 -0800 (PST) Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-5d7b1a8ec90so15994407b3.2 for ; Mon, 04 Dec 2023 20:46:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701751585; x=1702356385; 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=PTwiqtihyMWEpX2uUmOeVlr01B75EdpPvzVSzPHU6u0=; b=EsROK7t2fvj77E3v8lpYat9bTzWtHVYaJcPb52a5KrlqsVq3JW81QWSCBdLY/dl0/D C/7art0rHcG5IuKUkPCCGUCe1haQxMMNOwgLPnnFb3PtRK0gEujjXCd3AE7pnkT9UjeM 5poCjjwhoZGHum1E/4XJwFoD0Aeu5Wqx7p2NGF75Qom0a7y+t74kkxBZ7b3549VUBv8P sGevK4G7nvSRxShty3Z3I104eT/Qu/mczt/+EZElP7LIb7Dk/bBuFK8TD7C9KnU7Bn4w Rc6JUUS07y4PV5EzB+XpzCB4CeH7qB2shrpMoNoipHm3y0oUXBxmHGRyyKPP20EySsxr WjvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701751585; x=1702356385; 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=PTwiqtihyMWEpX2uUmOeVlr01B75EdpPvzVSzPHU6u0=; b=sHUmfcDeFb66dwU7q2ryh5HPk3u63+0tTFdsIw5VKNSWiB1D+7un2KkYU/vx/idWSl fKnTT54MvL8Rzpi/1guMiKKMe2B49PNCtp0k1HmS61dd4mjBcY80s2U/Tfy+8yHFICjo Th4lkzr4Wps0F2itl0fNWN6lVhl3ugrsEz5Hhkrd4cWykrLwctQ2NWmebfIKzlsGgETi Ervbxa02vAtOBcyM/OBgomJPZ9+4kpr6vtJQydM1CpTP/XFzmEbj0iwpgUrhCGeim3zp whEtor5SERfVO0BtQD4jpfTsfJUqZqCEkWZ4GTOvxiSvX9KX7gAxAIc5zNfa6NNGud6/ nYow== X-Gm-Message-State: AOJu0YyTw5t6wCDxihF9VNgKZO3TLkHKyeOMsBzt/q81MX7SSPreUEgy RsX4u3zBl17+wUIfIBlFjbT+xKZD1iIXdi56RyV7LQ== X-Received: by 2002:a05:690c:8:b0:5d8:2f65:cf71 with SMTP id bc8-20020a05690c000800b005d82f65cf71mr2583688ywb.86.1701751584910; Mon, 04 Dec 2023 20:46:24 -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> In-Reply-To: From: Suren Baghdasaryan Date: Mon, 4 Dec 2023 20:46:11 -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: 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]); Mon, 04 Dec 2023 20:48:31 -0800 (PST) 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 so= urce > > >>>>>>>> into destination buffer while checking the contents of both af= ter > > >>>>>>>> the move. After the operation the content of the destination b= uffer > > >>>>>>>> should match the original source buffer's content while the so= urce > > >>>>>>>> buffer should be zeroed. Separate tests are designed for PMD a= ligned and > > >>>>>>>> unaligned cases because they utilize different code paths in t= he 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 offs= et, bool wp) > > >>>>>>>> return __copy_page(ufd, offset, false, wp); > > >>>>>>>> } > > >>>>>>>> +int move_page(int ufd, unsigned long offset, unsigned lon= g 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 (errn= o=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 kernel; = see other 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 virtu= al > > >>>> area we are testing with, and that we do seem to get more odd patt= erns > > >>>> 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 th= e 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? > > >> > > >> 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 one > > > with it. > > > I'll also look into the reasons we need to split PMD on ARM64 in this > > > test. It's good that this happened and we were able to test the PMD > > > split path but I'm curious about the reason. It's possible my address > > > 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-mapped T= HP. > > Huh, good point. I might be able to move the folio splitting code into > 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 try to send it tomorrow. > > > > > -- > > Cheers, > > > > David / dhildenb > >