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 64920CDB465 for ; Thu, 19 Oct 2023 17:30:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A30E8800A5; Thu, 19 Oct 2023 13:30:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E03B8D001A; Thu, 19 Oct 2023 13:30:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8812A800A5; Thu, 19 Oct 2023 13:30:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7630C8D001A for ; Thu, 19 Oct 2023 13:30:09 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 30489C0530 for ; Thu, 19 Oct 2023 17:30:09 +0000 (UTC) X-FDA: 81362899338.02.00B1D91 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by imf26.hostedemail.com (Postfix) with ESMTP id 3DD31140020 for ; Thu, 19 Oct 2023 17:30:06 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=I+Axsl8y; spf=pass (imf26.hostedemail.com: domain of axelrasmussen@google.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=axelrasmussen@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697736607; 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=FAurVaDY4Y7iKpcdCWtd8DcvDhclHUigROPGt0DwP4I=; b=AleaLVQ7kePsAsnarPHSKxbUInui/L6ZTBDYYwpsXzX2rZj9kao2RuOxdolyHJwSSXOaqi IInXy88/AIhqyY2Vj0ObIE/Xz5txXlv2oNTqBJhjfHlKPcr7qyyrrup2JuDDovbmLbAfM5 dR4LglFUSA7e+B8YPrNrYU4QTSjhme4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697736607; a=rsa-sha256; cv=none; b=1l7LSsQRGfZKVot3JYV1+8hB0sw7jjPtAsNToQhRVipLT7QGYkgORk+KIvlrvM1STQybZB GI5ZcS7DTI8CMzc0wCeisw0357uiGrLepUCj/i53P+OUZSf8Uw1WgDc++gCJTmNURhug3x ddj6z6uJ9fpDTGwVJsIu4yc1wV7h/1E= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=I+Axsl8y; spf=pass (imf26.hostedemail.com: domain of axelrasmussen@google.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=axelrasmussen@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-99bdeae1d0aso1345132966b.1 for ; Thu, 19 Oct 2023 10:30:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697736605; x=1698341405; 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=FAurVaDY4Y7iKpcdCWtd8DcvDhclHUigROPGt0DwP4I=; b=I+Axsl8yundqVigQ+nXmFuBrxA4E/8WN5Y88VockRXwH3rSO12ogltPHWbQcJ+R2Ny Vf7j8t8QfWl5Dm6SSpaa0BA8/4zbIx1y217D5jNO/ppnJGns16lAZGa8PdbWp1NHC9/G H9VXNcx5pwkgyaBIn8ay5KPFwZaXsun/4tkna8udB2mj6WUFg37gaXcK+ZIV/TZHDoq3 VVb+6j7aYVLkALRgfOgYXBmjt/C+a6h3bz7BVsMVSDsX2gbd1Ern63GwiuEJQUnR/T4B pGgK8cf35wXC2+6rcurR0Y+8hHP45P5QXmTXM0rmh7bKab5bpWdNP4Z7wyyq8/kXZ/nK RrvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697736605; x=1698341405; 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=FAurVaDY4Y7iKpcdCWtd8DcvDhclHUigROPGt0DwP4I=; b=Kw5W+Hwv0Cq9lkSx6s3smOWb4t2P5tzPzlt2N+o4+qeCegy+X2mGuYOgMfNagoK4up XLIgmuDVjTu5XKku6AR6nwnnJr84ECzReuXqcSLinV6cAldpZLFrvjXnOfGbEFh8Pyrl Jwdv5Q8RpwXaKQMm7JBrjamwORhP2AJBmgiBwM+O5XlchmFTFteV/me6JRiiWz/X1Wlx oyTGcBjOHZiEv32Sc5CNhwwk7kYiofZsjBAiX+aD56JeKZj3ORhnddp5Zt2r+YxzhfAV /7j0rmeBat1gV46aYuIa4exnMIDV2Md3panyTGGgUjcs3IT8Iei+XYOkrSkr7VTjipug JBqA== X-Gm-Message-State: AOJu0YyhhBbjuzJNXJQFvq89whHNSuIOgGyn80rC39OvYi9I4DGew2FA m0rwAmQtEPMm26czTgMst4G6xyGgDHp9PtBUHLK58g== X-Google-Smtp-Source: AGHT+IHSZri8nXlKAjUkj+Rn1zxVvwP9rVjfWLt21urXdgubxJwwllu1ZEhXZeg6mDIzbPAa3WiOaM+FoK+uOXkcy60= X-Received: by 2002:a17:907:3687:b0:9ae:57b8:ad1b with SMTP id bi7-20020a170907368700b009ae57b8ad1bmr2090783ejc.21.1697736605364; Thu, 19 Oct 2023 10:30:05 -0700 (PDT) MIME-Version: 1.0 References: <20231009064230.2952396-1-surenb@google.com> <20231009064230.2952396-4-surenb@google.com> In-Reply-To: From: Axel Rasmussen Date: Thu, 19 Oct 2023 10:29:27 -0700 Message-ID: Subject: Re: [PATCH v3 3/3] selftests/mm: add UFFDIO_MOVE ioctl test To: Suren Baghdasaryan Cc: Peter Xu , akpm@linux-foundation.org, viro@zeniv.linux.org.uk, brauner@kernel.org, shuah@kernel.org, aarcange@redhat.com, lokeshgidra@google.com, david@redhat.com, hughd@google.com, mhocko@suse.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: 3DD31140020 X-Rspam-User: X-Stat-Signature: 1hrbdoy68ix7o4q1bipghj6xqieskk91 X-Rspamd-Server: rspam03 X-HE-Tag: 1697736606-406430 X-HE-Meta: U2FsdGVkX19PtwVsMIoXSfxnQC2PEeZlzQXlZpvpCIRCYIPSS6rC0BcbcvEJ9BXqEdG9KcPPqF9+YcwH2bMLdCsiyF4KJsUM3jotlKGodea7fvOO0kSlHvgQ/JLIumYu2PVu7fO+0EmWdZiVeugcB+QLcuxbsid4zEaB65hVBPuul/2TccAekra2D5Dzvfl8PVA9pOkqSSGKj63jz+1bvnW9zQLRwzg+W1NmIAVlwK4ECcsQ+lKpeW7baMNZv59HMq1zHhAykSNR4BicCIG3pnO2wTAUW+BaqmPcO6Ny9RM7RYmaRexeeG42nLZ+wm1WARhW1zAR3Ec1wW0TlLuYYwICJqiwX/LCDVLr/VQ28+0Tzz0vrwgdhyJ1qqTBYhiP+lp7VwZZVu4dxo2SrUltkf1J98YHmLNz7teJ2M2vojc7MfRx3RvUThBBA1S6D2v0QjA1eGcBUEopxA43gQobFUEsrMamXm8CZ8snATR7ycvDofFyHy5tkuaaRN/gjO53VTQjuS5g7K/O3+zbfrYm0a9FV5xMKWzBlE3QMN67xhnX03GB742rvVPcostDUqTw/TYFGvpuwO1yPeitnk74xHXbgr/Su4TWEpu1KDIKN44TNuO6ZLet+XiNdXCvZRqRdkkQWqZdWD3YneggmszOE9LnB9bp8t/M2zrLnxjyfYSGsHlzYDFAjSfJ3gCwzrr2CRvRHFrf6//Yftr0aB0osHsdwGCcGNMPySX6FY0dXQoeOghMZz4I1IgUz3rdDnGfy1KG93wM5rmnxqJYOCG407gYZK5P1w+fezMyIDmLK5HAV+V1RVriXLqSdkEQ5IR47t2iGh1s55QW7R7jhlFn+j3ppe+0Bkoi2zFhxz6kShECt85TKTL2krbrGi0jWu8oEvJSdWSeYt3LrxdCFNEF1YnC9yHGofS3G6ZajaXP2GEPbntLRer0caOtNbGTVW4dNi0VIHWUExDAovPuZo+ WhIUEbhh 1oxYUMxAS+NuCZnHOtmC7bjGMCGLRNCdhjk4SUm7Zj6RKcwX4pBoO1cQ7CVgf9qK8ZMUT4ixnFeTB2a0OnzcL10eeJ+BxldQmEEUsLPwAqXW9QMiowCQw476Nkt6GGLclcMDLchcBo/fyUiV2+uUxuMqb+4o1pEbCi+JjnJIvnlfgMXKPFe1PrG4zkQJ96fBC+gcy0J+Z4qk2ts6nWP3TcayBYqULPLq8+6vQVgKudS1AUKMIa40TWTmu4Im8AzTMSs85qPQPQcb+8YgyT/2VGXw3baKV3M8y0gp2CjGEBLsSszyDNi0pXb4Fs+w95FTTpapKPe5E9EG2GHjTZzo5Bq6YHljJ4LDBf811hi6W9m836k0bTOsSagd8lw== 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: On Thu, Oct 19, 2023 at 8:43=E2=80=AFAM Suren Baghdasaryan wrote: > > On Thu, Oct 12, 2023 at 3:29=E2=80=AFPM Peter Xu wrot= e: > > > > On Sun, Oct 08, 2023 at 11:42:28PM -0700, Suren Baghdasaryan wrote: > > > Add a test for new UFFDIO_MOVE ioctl which uses uffd to move source > > > into destination buffer while checking the contents of both after > > > remapping. After the operation the content of the destination buffer > > > should match the original source buffer's content while the source > > > buffer should be zeroed. > > > > > > Signed-off-by: Suren Baghdasaryan > > > --- > > > tools/testing/selftests/mm/uffd-common.c | 41 ++++++++++++- > > > tools/testing/selftests/mm/uffd-common.h | 1 + > > > tools/testing/selftests/mm/uffd-unit-tests.c | 62 ++++++++++++++++++= ++ > > > 3 files changed, 102 insertions(+), 2 deletions(-) > > > > > > diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing= /selftests/mm/uffd-common.c > > > index 02b89860e193..ecc1244f1c2b 100644 > > > --- a/tools/testing/selftests/mm/uffd-common.c > > > +++ b/tools/testing/selftests/mm/uffd-common.c > > > @@ -52,6 +52,13 @@ static int anon_allocate_area(void **alloc_area, b= ool is_src) > > > *alloc_area =3D NULL; > > > return -errno; > > > } > > > + > > > + /* Prevent source pages from collapsing into THPs */ > > > + if (madvise(*alloc_area, nr_pages * page_size, MADV_NOHUGEPAGE)= ) { > > > + *alloc_area =3D NULL; > > > + return -errno; > > > + } > > > > Can we move this to test specific code? > > Ack. I think that's doable. > > > > > > + > > > return 0; > > > } > > > > > > @@ -484,8 +491,14 @@ void uffd_handle_page_fault(struct uffd_msg *msg= , struct uffd_args *args) > > > offset =3D (char *)(unsigned long)msg->arg.pagefault.ad= dress - area_dst; > > > offset &=3D ~(page_size-1); > > > > > > - if (copy_page(uffd, offset, args->apply_wp)) > > > - args->missing_faults++; > > > + /* UFFD_MOVE is supported for anon non-shared mappings.= */ > > > + if (uffd_test_ops =3D=3D &anon_uffd_test_ops && !map_sh= ared) { > > > > IIUC this means move_page() will start to run on many other tests... as > > long as anonymous & private. Probably not wanted, because not all test= s > > may need this MOVE test, and it also means UFFDIO_COPY is never tested = on > > anonymous.. > > > > You can overwrite uffd_args.handle_fault(). Axel just added a hook whi= ch > > seems also usable here. See 99aa77215ad02. > > Yes, I was thinking about adding a completely new set of tests for > UFFDIO_MOVE but was not sure. With your confirmation I'll follow that > path so that UFFDIO_COPY tests stay the same. > > > > > > + if (move_page(uffd, offset)) > > > + args->missing_faults++; > > > + } else { > > > + if (copy_page(uffd, offset, args->apply_wp)) > > > + args->missing_faults++; > > > + } > > > } > > > } > > > > > > @@ -620,6 +633,30 @@ int copy_page(int ufd, unsigned long offset, boo= l wp) > > > return __copy_page(ufd, offset, false, wp); > > > } > > > > > > +int move_page(int ufd, unsigned long offset) > > > +{ > > > + struct uffdio_move uffdio_move; > > > + > > > + if (offset >=3D nr_pages * page_size) > > > + err("unexpected offset %lu\n", offset); > > > + uffdio_move.dst =3D (unsigned long) area_dst + offset; > > > + uffdio_move.src =3D (unsigned long) area_src + offset; > > > + uffdio_move.len =3D page_size; > > > + 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); > > > + wake_range(ufd, uffdio_move.dst, page_size); > > > + } else if (uffdio_move.move !=3D page_size) { > > > + err("UFFDIO_MOVE error: %"PRId64, (int64_t)uffdio_move.= move); > > > + } else > > > + return 1; > > > + return 0; > > > +} > > > + > > > int uffd_open_dev(unsigned int flags) > > > { > > > int fd, uffd; > > > diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing= /selftests/mm/uffd-common.h > > > index 7c4fa964c3b0..f4d79e169a3d 100644 > > > --- a/tools/testing/selftests/mm/uffd-common.h > > > +++ b/tools/testing/selftests/mm/uffd-common.h > > > @@ -111,6 +111,7 @@ void wp_range(int ufd, __u64 start, __u64 len, bo= ol wp); > > > void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_args *= args); > > > int __copy_page(int ufd, unsigned long offset, bool retry, bool wp); > > > int copy_page(int ufd, unsigned long offset, bool wp); > > > +int move_page(int ufd, unsigned long offset); > > > void *uffd_poll_thread(void *arg); > > > > > > int uffd_open_dev(unsigned int flags); > > > diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/tes= ting/selftests/mm/uffd-unit-tests.c > > > index 2709a34a39c5..f0ded3b34367 100644 > > > --- a/tools/testing/selftests/mm/uffd-unit-tests.c > > > +++ b/tools/testing/selftests/mm/uffd-unit-tests.c > > > @@ -824,6 +824,10 @@ static void uffd_events_test_common(bool wp) > > > char c; > > > struct uffd_args args =3D { 0 }; > > > > > > + /* Prevent source pages from being mapped more than once */ > > > + if (madvise(area_src, nr_pages * page_size, MADV_DONTFORK)) > > > + err("madvise(MADV_DONTFORK) failed"); > > > > Modifying events test is weird.. I assume you don't need this anymore a= fter > > you switch to the handle_fault() hook. > > I think so but let me try first and I'll get back on that. > > > > > > + > > > fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); > > > if (uffd_register(uffd, area_dst, nr_pages * page_size, > > > true, wp, false)) > > > @@ -1062,6 +1066,58 @@ static void uffd_poison_test(uffd_test_args_t = *targs) > > > uffd_test_pass(); > > > } > > > > > > +static void uffd_move_test(uffd_test_args_t *targs) > > > +{ > > > + unsigned long nr; > > > + pthread_t uffd_mon; > > > + char c; > > > + unsigned long long count; > > > + struct uffd_args args =3D { 0 }; > > > + > > > + if (uffd_register(uffd, area_dst, nr_pages * page_size, > > > + true, false, false)) > > > + err("register failure"); > > > + > > > + if (pthread_create(&uffd_mon, NULL, uffd_poll_thread, &args)) > > > + err("uffd_poll_thread create"); > > > + > > > + /* > > > + * Read each of the pages back using the UFFD-registered mappin= g. We > > > + * expect that the first time we touch a page, it will result i= n a missing > > > + * fault. uffd_poll_thread will resolve the fault by remapping = source > > > + * page to destination. > > > + */ > > > + for (nr =3D 0; nr < nr_pages; nr++) { > > > + /* Check area_src content */ > > > + count =3D *area_count(area_src, nr); > > > + if (count !=3D count_verify[nr]) > > > + err("nr %lu source memory invalid %llu %llu\n", > > > + nr, count, count_verify[nr]); > > > + > > > + /* Faulting into area_dst should remap the page */ > > > + count =3D *area_count(area_dst, nr); > > > + if (count !=3D count_verify[nr]) > > > + err("nr %lu memory corruption %llu %llu\n", > > > + nr, count, count_verify[nr]); > > > + > > > + /* Re-check area_src content which should be empty */ > > > + count =3D *area_count(area_src, nr); > > > + if (count !=3D 0) > > > + err("nr %lu move failed %llu %llu\n", > > > + nr, count, count_verify[nr]); > > > > All of above should see zeros, right? Because I don't think anyone boo= sted > > the counter at all.. > > > > Maybe set some non-zero values to it? Then the re-check can make more > > sense. > > I thought uffd_test_ctx_init() is initializing area_count(area_src, > nr), so the source pages should contain non-zero data before the move. > Am I missing something? You're correct, uffd_test_ctx_init() fills in some data in area_src. > > > > > If you want, I think we can also make uffd-stress.c test to cover MOVE = too, > > basically replacing all UFFDIO_COPY when e.g. user specified from cmdli= ne. > > Optional, and may need some touch ups here and there, though. > > That's a good idea. I'll add that in the next version. > Thanks, > Suren. > > > > > Thanks, > > > > > + } > > > + > > > + if (write(pipefd[1], &c, sizeof(c)) !=3D sizeof(c)) > > > + err("pipe write"); > > > + if (pthread_join(uffd_mon, NULL)) > > > + err("join() failed"); > > > + > > > + if (args.missing_faults !=3D nr_pages || args.minor_faults !=3D= 0) > > > + uffd_test_fail("stats check error"); > > > + else > > > + uffd_test_pass(); > > > +} > > > + > > > /* > > > * Test the returned uffdio_register.ioctls with different register = modes. > > > * Note that _UFFDIO_ZEROPAGE is tested separately in the zeropage t= est. > > > @@ -1139,6 +1195,12 @@ uffd_test_case_t uffd_tests[] =3D { > > > .mem_targets =3D MEM_ALL, > > > .uffd_feature_required =3D 0, > > > }, > > > + { > > > + .name =3D "move", > > > + .uffd_fn =3D uffd_move_test, > > > + .mem_targets =3D MEM_ANON, > > > + .uffd_feature_required =3D UFFD_FEATURE_MOVE, > > > + }, > > > { > > > .name =3D "wp-fork", > > > .uffd_fn =3D uffd_wp_fork_test, > > > -- > > > 2.42.0.609.gbb76f46606-goog > > > > > > > -- > > Peter Xu > > > > -- > > To unsubscribe from this group and stop receiving emails from it, send = an email to kernel-team+unsubscribe@android.com. > >