Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp878346rdb; Wed, 6 Dec 2023 02:31:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFDBvni3DNLWPKN1VCQBrSfRgWEu4fv3AK631TufGOvmwY66sP8XJE9c6ujTdlAmdUdHguH X-Received: by 2002:a17:902:ab59:b0:1d0:6ffd:f226 with SMTP id ij25-20020a170902ab5900b001d06ffdf226mr347473plb.124.1701858692644; Wed, 06 Dec 2023 02:31:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701858692; cv=none; d=google.com; s=arc-20160816; b=BJMzkS+TKXCJtU8jN3nNIiRy7pHKFy5xZBfsFAjNi7pwO03r6QapCNgVSbwh7GWIHZ FDHEP+SjH1otFEhk/vKDdo02YPuoGWqyb/3iSO8bix1RMRtiBJzLwz5hoGLlXcT6iFbt Ao0im4DVjaHgmWbW69Pu9BcJujhxyYhTF+wuR6RN7J+UYw6V1kOwUz6tp7CrQa77X+SE Ge7pa10iR5qBE1S6/GyU4q14tkIxjip88YHhr0EORDFquRigv1YznCeBcoW/8hpCeOLc 6fcX6dm1TNymE/K3HDSLHSPOFAxYQnKlBeTKyyTxvbgXmSPgNh+FrwgPcuiNd+73SMpf x7qw== 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=oJAfBJe//jMp144Bh2ybimjx6ISuOne+BJIc9JPDue0=; fh=BonCDYkT2j1VY/AgyhOKqEQ33f4iRxSkOH4YtEHP3pE=; b=vujJepO27KuIVy3agdLZkooUO0Zl2Di8yjY6o6EeOuCokMoa1sVfiFT/J4nxgmbFmi 5/L1TLlmoQlKH10Cu7bM8sohYsenLEK7tns+eWfTEi9svq71uz5rSdvtlC1WdXdttuYQ qQbVRyrU/RMtodmTYecWGzFOMavs58JCNX19hcpecpEuS44orlxuSy1sRV+zEJhJ4ijR 3pe4uy/I1hrbJYpIedA6SFX+7M8Mq+lDkvR2a7UOgI7jFcGjVGpYSsIksTU3pk+gfyMk Z1ST4c84RvorpAc4qSEQofgWgfVb/1bkcxcgoJHS6JM5cc9qtsChapPzCJsEfy4+50ht 6EDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=s5NfzDY6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id jf19-20020a170903269300b001d0626761c5si8251340plb.217.2023.12.06.02.31.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 02:31:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=s5NfzDY6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 2D5CF80779A6; Wed, 6 Dec 2023 02:30:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377436AbjLFKai (ORCPT + 99 others); Wed, 6 Dec 2023 05:30:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377418AbjLFKag (ORCPT ); Wed, 6 Dec 2023 05:30:36 -0500 Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E597012F for ; Wed, 6 Dec 2023 02:30:41 -0800 (PST) Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-db549f869a3so5335509276.1 for ; Wed, 06 Dec 2023 02:30:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701858641; x=1702463441; 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=oJAfBJe//jMp144Bh2ybimjx6ISuOne+BJIc9JPDue0=; b=s5NfzDY6S0KcpnPU5ek/CTs7xvn0+fFhbf/dLr7qSR9E9uxw/sN5Ztfq9MmjD9ByvO Dcp9McBlxJLZhbBO1PMbBI8Y0GCxvzSkyaGgb5DbfV3wCpkvqJ6o05aCdJ39Um3CJWv3 1oGxoT0ric7Ezm5vcLv7pylzl5/FxcPSGn30BWNSjXcW9slLphriIG9ARdRjzGj8oiuB x3sqT6Z6Xrbv0swjaBFH7zkggGqkjUsdSWZTxoSpVsKxflb9+TKLo0xsmINhH7s6T0Lg wNJYeZpVfkidV3cpGt9eGfKepmuTHxslAlk3pNkK4ufuxwTsFwvLJfkpeli/pn7+fnvX AbWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701858641; x=1702463441; 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=oJAfBJe//jMp144Bh2ybimjx6ISuOne+BJIc9JPDue0=; b=huUccapOiu+kRQo4e12T6x79kwI+qZIV0Y+/p/ovMc1ss6D8uX8XgH+TIJnbB1X+q7 cNz+a2Hy03bT5MxFNo4Fsri4TU1UYaWu4mor4i432yGmzYGdtQ/3Qd/c9EO6PLuXuUBa Upg4wHjyLzbdKTP1bcbquuOkwfPzbML2Z0kyB05QhTvm4aePZhgf7wOIcO4W423n1dib Mjsy+LVetXH2uSQSh0WC1cSVgz/I07Vl5XgMtXkNOhWR5yNBJMtAhIKa94xaRdZYQkrn N4/LP7lvE+Sb9HjsKDsUYzikIc3epUrMzqwEPuZxhANytxkwDImwsz/FVuaBbjkpX+wN 1A7Q== X-Gm-Message-State: AOJu0YzyD5GXzQ7F6R4/yAbSTs3XksrUL4nhcdgj7KbFzgAdqM2SDxTr Bqs8CS4lRHx2ddUYcQZXi/zjEOfbLxVnl3cDoFZ7BQ== X-Received: by 2002:a25:c7cd:0:b0:db5:45f4:ec83 with SMTP id w196-20020a25c7cd000000b00db545f4ec83mr416954ybe.43.1701858640812; Wed, 06 Dec 2023 02:30:40 -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: <3ba0015b-b36e-449a-8445-0f6272694db5@redhat.com> From: Suren Baghdasaryan Date: Wed, 6 Dec 2023 02:30:28 -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=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 02:30:58 -0800 (PST) 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 s= ource > >>>>>>>>>>> into destination buffer while checking the contents of both a= fter > >>>>>>>>>>> the move. After the operation the content of the destination = buffer > >>>>>>>>>>> should match the original source buffer's content while the s= ource > >>>>>>>>>>> buffer should be zeroed. Separate tests are designed for PMD = aligned and > >>>>>>>>>>> unaligned cases because they utilize different code paths in = 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 off= set, bool wp) > >>>>>>>>>>> return __copy_page(ufd, offset, false, wp); > >>>>>>>>>>> } > >>>>>>>>>>> +int move_page(int ufd, unsigned long offset, unsigned l= ong 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 (err= no=3D16, > >>>>>>>>>> @uffd-common.c:648) > >>>>>>>>>> > >>>>>>>>>> I'm running in a VM on Apple M2 (arm64). I haven't debugged an= y 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 pag= e 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 virt= ual > >>>>>>> area we are testing with, and that we do seem to get more odd pat= terns > >>>>>>> on arm64. > >>>>>>> > >>>>>>> uffd_move_test_common() is a bit more elaborate, but if we aligne= d 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 t= he 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 an= d the > >>>>>>> actual ranges we are trying to move. Maybe something "obvious" ca= n 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 afte= r > >>>>>> 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 thi= s > >>>> 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 addres= s > >>>> 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= THP. > >> > >> 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. > > 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. > > -- > Cheers, > > David / dhildenb >