From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8224C4167B for ; Mon, 4 Dec 2023 16:35:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 680DD6B0176; Mon, 4 Dec 2023 11:35:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 60A156B0178; Mon, 4 Dec 2023 11:35:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A90B6B0177; Mon, 4 Dec 2023 11:35:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 369756B0172 for ; Mon, 4 Dec 2023 11:35:43 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0E734A0997 for ; Mon, 4 Dec 2023 16:35:43 +0000 (UTC) X-FDA: 81529686966.06.0B5F5EA Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) by imf21.hostedemail.com (Postfix) with ESMTP id 13BB31C0016 for ; Mon, 4 Dec 2023 16:35:40 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=wtemTIh2; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of surenb@google.com designates 209.85.128.182 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701707741; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jABw2zbx7ijea0rhPxJuqEg+N1RDQxgva2LQbaOAzns=; b=lmBorv2/toR6ZYI61zipFC5meLGiJoUao2E7GnHDOYwrt9uxqIOnPDZMdko8x8NsQwF7mf 29opV8BoiFG4sINsS14nBMV5zzQY5xOp0R4nmmMbf+GwDBe6W4axGY/iHMNAU91BW9vIKK oyurKgSfkSUnuf6KZ35PfB/WDnazixQ= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=wtemTIh2; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of surenb@google.com designates 209.85.128.182 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701707741; a=rsa-sha256; cv=none; b=Tj8URK2SrAmrMLO1QXhz+75/Ly91wiezZvfksJ/BlVmWdzkhaWufRVUToEBW7cgxs7jmEV gdeVQe1P7HhUgvehtJfsnU02aOnlLctf5ZC1SC3clJZyyfq9B7FHf+q0feYOeaGtjNS3nP MvVWCTxFIku4TbGJOTivsCOWPt5WfRw= Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-5d852ac9bb2so13546697b3.2 for ; Mon, 04 Dec 2023 08:35:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701707740; x=1702312540; darn=kvack.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=jABw2zbx7ijea0rhPxJuqEg+N1RDQxgva2LQbaOAzns=; b=wtemTIh27KrLY84SAHxlGjTJcewm+qoan9NPQflidse/nLDD0Z8LEW8dsnvWTP8VoU boLM5DMYqET8hX1RXT09zhXVyYwz84i/MTKxrXpG2p29QH9Q1aCPt2WQfrUxLBvFvt7H VpChEaP/7FswtATnUPEab7idGPLgA3r7CVSqh8cQGj7L3Zs/Opt6iF8wFAL+OdYOyEu/ QAsqxuZWMoyjNA3dLusaj99prjsLwyQ5yBdkHQudjizzQgIm52SdWEsIVGNwd7a+4zUe MlxT4WDw7mYHlbwxK2MzShFloDM9xbrZ46TwLCiCu9VuN3xLTswP8+eyIAAQZgdXpW1r /uaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701707740; x=1702312540; 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=jABw2zbx7ijea0rhPxJuqEg+N1RDQxgva2LQbaOAzns=; b=ZT0ObHfKnm+vnWLMghboXcm4XbYfTm8AJpJFJfLpUXfS/KCBPAK7Ov/uW4JUDPBJD8 /8MUmVfTBspAmue8DWk9ekOUVmMnWuCPn6bUiHTOV1xX6EAQVWYalqc137TXS/tXi/PB u43yzpIvxF82KQ4kTqxg4XIdNHyRbUzdVgqUMCOC+reghRAWBuJFDEWuVxuQxe5VqmRu UX4IJ1UNSL/3Q/Qkigx4I1mw5wjjM36fqtPuRmkSz1fVh9nBeQwRCp1DhQJFSqQbVL1y I2lm3lsR/axKXRenXHeypNdz4f0SsdrDoSUKQkjXHvUzvCJRBGNppLq61daaXb01bbQE V22w== X-Gm-Message-State: AOJu0YwWVkZP4Hvq0QUgtYClukDjAIKhNt/iCmFNiVhFw/AsJDz+/7xd XP6lCWXoXQoy/f6Irw8eZ7dqtS4Veah3vFSHiXWYnQ== X-Google-Smtp-Source: AGHT+IEPIvS2v9x5/LGkP67CUghbCwHnkkFfGaI/Rzd47JgebT80lAaPaT/OgP4FMUPPtIDXwaqelTsXTcjSOD2IRY4= X-Received: by 2002:a05:690c:a06:b0:5d7:1940:53c2 with SMTP id cg6-20020a05690c0a0600b005d7194053c2mr3349401ywb.58.1701707739801; Mon, 04 Dec 2023 08:35:39 -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: <744be4e0-48e0-4c77-825c-711386dd205f@arm.com> From: Suren Baghdasaryan Date: Mon, 4 Dec 2023 08:35:27 -0800 Message-ID: Subject: Re: [PATCH v5 5/5] selftests/mm: add UFFDIO_MOVE ioctl test To: Ryan Roberts Cc: David Hildenbrand , 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-Rspamd-Queue-Id: 13BB31C0016 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 4q5kx5khsu6pyby6fj6bpu5zf79hwexu X-HE-Tag: 1701707740-6585 X-HE-Meta: U2FsdGVkX1+nJfMb+96JosCUOGEzloGSsuJSyCMXJCmDJUXsiAV7XYdy+4oHpneYtcGlaw5tKZuxkOsE+z+zrXM6xamIN85pCQepj2fuHPE2Zz6HZc3HWkiNSt/GHCl3BEAgQEGQ/F4v9qcFngMSQyOpcSSsO1zB0SDKYEpXEj6W0cRELdKnlVND6og1mDz+Nts3Onx/RjgGIQoD5sFGKJAQcV47TpWVizvRjaz6TAKDcqPX9olWB+NQX+aSKlZXrqDzCv2aXSaIMBIvsGIk/1Lo/TcpcMx+nIWRnEYN1zoG9vTVrzlrI8birGa4tn7s28oa8xCXGDe68swC0Wzv7NCThsUEMl7RqMq3hDZbS8Sw+Unvds4R/j5//DRwDeKtVfwF41VtKSnaHJHlqCGx9SPM1UtqqmsZ0yN7BinP33nB+d8ZVwbLijcqS16yCM17JwITJdqT5VUTi1caSGZq7mHDZ8XYHf7x9k3J6bmgxZapJIsR+sa9TP3N1czSMmphg6amxv+FOZYwE8vlxPxJmwmJF/2ZUxdoOqrsmUa3F752Sx8LWRjNGCxtn0ELOlB+i2VTLSPtvyU6rZHJKyyqyWc5HPxd3eG8pIV7on0LWoXLkz9W1I1RY4RatjlWWSi1zjmsICLryXICLzeVRwEE422mIlPDo2+scFVRx5QNkbwsmlrK4EwmT7PNh5cyOf1aB42PxedYyi3yXPxaI+HFEhieIwqvE0/mhJptO2v4QoL+R9n8qR2htkIl4PKvW+jsWoq4BzF7t/3GvA/c9A65O9qXtcYAdIUqGLI32jnlxfo+lXqfDDQYgUmsq5PwPNPpw6YYoMZpKv+PlGVNPW4EGCWrF67e16sRWX765aO59iTjUtRQji0p/mcmcqWLVs1E9jAf+T5DtdiHASYOdxvvo66UKl2kPvWHn6hx7aTGwSOVOrrObLw/2ZAoPnt8HS8tKYD1m1oI7vfeHZ1zO/G 4aSyvQbz zzMPvsX3wBHfVIAHf8Tws8l+Fef3Eql87U6juTyzGyldZoU8ipdD0V4557jYkNOucH8wV8m3HxjTQQAKASOn5BsH919VkkAaV3MGOeZrSTysg35PPyzWg8dSm6Winwjh/tD7omrMZboKwTcXyOIlUs6XnFuIgrFsKbML4lF4/XY0M4hd6VI2CutDncBemZl7jHZALbBBRzeFvcBOuJUPX60BvuZI4jPeqIRBE6XCTDFs5AcraZL3c8xi1OY2488HcdQJuZZRT49Q11DPzI8qVoCv5yPvEtB8tKdjhVYWgV5h6JDr3LLJPNSch/G1CMAxDKgW4KdVcEEuUQZedV85AknaePwLri3jXSY1dW8mQ5zcQxp1mIvUpFAgLXKi9jXztYg/C X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 destination buffe= r > >>>>>> should match the original source buffer's content while the source > >>>>>> buffer should be zeroed. Separate tests are designed for PMD align= ed and > >>>>>> unaligned cases because they utilize different code paths in the k= ernel. > >>>>>> > >>>>>> 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, = 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", 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=3D= 16, > >>>>> @uffd-common.c:648) > >>>>> > >>>>> I'm running in a VM on Apple M2 (arm64). I haven't debugged any fur= ther, 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() us= es > >>>> default_huge_page_size(), which reads the default hugetlb size. > >>> > >>> My kernel command line is explicitly seting the default huge page siz= e 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 VM= A > >> 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. Thanks, Suren. > > > > Thanks, > > Suren. > > > >> > >> -- > >> Cheers, > >> > >> David / dhildenb > >> >