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 45B05C77B7F for ; Wed, 25 Jun 2025 00:34:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C9136B00AC; Tue, 24 Jun 2025 20:34:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 979EB6B00AF; Tue, 24 Jun 2025 20:34:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 842316B00B0; Tue, 24 Jun 2025 20:34:50 -0400 (EDT) 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 6ABC16B00AC for ; Tue, 24 Jun 2025 20:34:50 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 183F914130D for ; Wed, 25 Jun 2025 00:34:50 +0000 (UTC) X-FDA: 83592052740.23.781ABDA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id D1BB380007 for ; Wed, 25 Jun 2025 00:34:47 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cw1K2kxf; spf=pass (imf02.hostedemail.com: domain of liwan@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=liwan@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750811688; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wa1S4P95Zir1w+zoKHeTJ8EFaOKtZfGjizlGSxcPX2A=; b=WDgawTFcrdr25v4sDZZeOZK+GnrXFDOoxWoBU+LnCCxS8oixX22D1kcOBmc/DRrsT9zqM3 4CqCdnAGj7O/DKUmLeQRq1HveYizt/68K13KopqmIy8IMT921z+j6iVHsUYrHgXgNT3FHs fFg99kmH6qjorREJE4S4xctVyPUOvXk= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cw1K2kxf; spf=pass (imf02.hostedemail.com: domain of liwan@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=liwan@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750811688; a=rsa-sha256; cv=none; b=GRrmjBP4v+BTeydnsTWQI6lqjzmEnhjrsbPVXjmRTgaIQrn+jwq6g1xM5Q6grOvSjZ7luA XvxQbN8NrlH1I4r0UjFEqAcQiZAWCUFSNxbOTOQcIOaoxVeyvNAmjbiGDiQPxXL4sP9DCX yUa6YJAmqs7cUZPbLMk7GuE2EWdC7Jw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1750811687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wa1S4P95Zir1w+zoKHeTJ8EFaOKtZfGjizlGSxcPX2A=; b=cw1K2kxf+U1pPV2Ri+bdpsFFd3E6hXykHzrBO2XB1fuyysVeBYf32kPsIiHK3+uQHkn+VW 96WhXpI9+zUvs4ccYG8xJF9UjqjbCe9uJnhbXOw3AzaX+ujhpuEguHHMLA2bROELQYBF+t Nc55YVguwG2DI+oQR/JH2z20PNzqZZg= Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-670-mMb7qDf-MQ2crh_0rWtXcQ-1; Tue, 24 Jun 2025 20:34:45 -0400 X-MC-Unique: mMb7qDf-MQ2crh_0rWtXcQ-1 X-Mimecast-MFC-AGG-ID: mMb7qDf-MQ2crh_0rWtXcQ_1750811685 Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-3141f9ce4e2so9359929a91.1 for ; Tue, 24 Jun 2025 17:34:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750811685; x=1751416485; 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=wa1S4P95Zir1w+zoKHeTJ8EFaOKtZfGjizlGSxcPX2A=; b=bk2vQaB/2xsJNA/lm+rIhmawoUr/l4owfk6TCaFmBjSxhnVXNo+6efGiQYg+c5Qrfl 2euqTT1J3PvOKi4sxIzrgVfhQdTdUrUmAdTJp+QoTYIaAlrpJzfPBiQRDawLsHaGcXLo IzBCJf/TuIrPrp/GlW+SgQDNLTx4lAInVbkPv9rpzyWYuINwC/51glNMJ09jWYe0E+K7 dhTxh5GvEqLpk0Pk5nBDCBxWkdCc8Cx7VLbip2/A/DjU1qYb/IOQ7XiiyrpNGtlc0jwL 5BNmkn/U6K/rPJS21N+gllK+fUBlc6MSQeCG8pydxrlX211HBSbFByvbtjCBjHjbZAJ8 zgsA== X-Forwarded-Encrypted: i=1; AJvYcCUcVPBcBZgCGqhG03GUERnQaeuUbw30NlQa7ArjPOd5rRdeaa0vXbXjtxx+z+c1wv0CQwVh50ApYQ==@kvack.org X-Gm-Message-State: AOJu0YzK+s5kBTC5gLZekwtDuO7rMkczegU+K8ilEeYiR7CAY8Ck2k9x Nu1+6es86e9hARQiU8l2yw2jzF6+0Pyj4+0E8oQQeveTFBcvt3scCDqaxX1qipuwSvXXi0SJ/xH W1c0IE1n7PjyV/+xI3bOzXmDzvxG/FjvQDyopyHPlfP9Y17wNfUCPfMBU94K7wGxaJGqTW9ho+C nuyw93xfUgaLS0mwq+akHSE0cOcHw= X-Gm-Gg: ASbGncvFXN6IrrzWN1FTVpxGMkOEmC0Qs9292DuwrenwhQDnxMh9xffkzLzta32ogjO EzoSWr6A0qBPBFigYJAwP11ThPwbrF7HFK8gnLCv8ley6DywES6NXCnkgoPqUp8LMdvnzg+WH8D z1bcXk X-Received: by 2002:a17:90b:3a05:b0:311:f684:d3cd with SMTP id 98e67ed59e1d1-315f2623c5amr1626524a91.12.1750811684666; Tue, 24 Jun 2025 17:34:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+4ozx4l6n3ZYmHch7GP4/FmjypFxv8DCTM6J5lisEsGhiigkreN6HaKrx5WbCssZPkt+0xma9WRwj2FROWU4= X-Received: by 2002:a17:90b:3a05:b0:311:f684:d3cd with SMTP id 98e67ed59e1d1-315f2623c5amr1626477a91.12.1750811684245; Tue, 24 Jun 2025 17:34:44 -0700 (PDT) MIME-Version: 1.0 References: <20250622081035.378164-1-liwang@redhat.com> <20250624042411.395285-1-liwang@redhat.com> <4bea7e61-b9d6-4855-bbdf-489020c9167a@redhat.com> In-Reply-To: <4bea7e61-b9d6-4855-bbdf-489020c9167a@redhat.com> From: Li Wang Date: Wed, 25 Jun 2025 08:34:32 +0800 X-Gm-Features: Ac12FXztJSBBYc5Ta8FNOZadelbqEIIbH12CYNqjK3ul3hTUZC0s2fYrNkCkuEA Message-ID: Subject: Re: [PATCH v2] selftests/mm: Fix UFFDIO_API usage with proper two-step feature negotiation To: David Hildenbrand Cc: akpm@linux-foundation.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Aruna Ramakrishna , Bagas Sanjaya , Catalin Marinas , Dave Hansen , Joey Gouly , Johannes Weiner , Keith Lucas , Ryan Roberts , Shuah Khan X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: OXYqMNvkH6D5-3wHGxG-729dzRylgbFo1LQrFjuxN5A_1750811685 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="000000000000822f9006385a9c32" X-Rspamd-Server: rspam11 X-Rspam-User: X-Rspamd-Queue-Id: D1BB380007 X-Stat-Signature: ymdo7tgnpbj37jbz7tfh3y71717sc95c X-HE-Tag: 1750811687-607891 X-HE-Meta: U2FsdGVkX1+Wl+ZaaKd6xEq+Tt46Pj8TMqYOO8UuXNmE5tDSlOrWMHa6T9maPiltoU3bzDn46h6i5O+z5leq5mc5F4R2qoqiXVhBLg9ZPu+OlkZ0Ysp5oOgxaUjyqvgnJrdBAWssCDS3eXRDCw+UovV+4exgjrAFFdiyS1FXjNjgq57UxdR5Dszz3t1AWVqHHv1CFYUm/whFU1DADS+RakFL83JpLUfZB0yWNG5DpNCI1qQLLBWd8uXrMHO4Ho6KB6doZTMrbmWiIDZy44ZPRdC/wxe0xJdwfw34tT0BG1aUcgpLRo5Woz8aB7uYMm/0UsJytraR8w+rOpvgcK/7oQ9lvdapgn4o3NldkFcZjXZdVmfLsTzoqDhUDxPtzXTCbIR7lcdOms7tQ/lfGDTLRwHIfkOcZcAxx5GMMzI/DVsIlWRGd/VV2doXTDSWB4zsAu5dPB7Mm5sADc8AmyQ3CLUMlIVTiyLYkqAHcUVanSz/Sufy3YljCvw23T4fn62TGgRRw7SGiMkdG0mGdR6AcL9YYiPMGYnrz9prLxF7FmH7kO20k8Kd5eLzjF2wJudlcRYHr3lPtX6P3UnvoKaV8SLkP6WDtjb0tCrTJVYuoDaI5XLVyxlSJMI1R0s/QG5RCKOnvr6wwrTF8EXq3Z5CMeC2fbFB0vRTiqviPscT2Uw6yT6nKTa/8EpQI8ZbKXCFTl9n898RJAuUgpwd2NpHP6hqSyo4hYaKWL+4QUagzso6FrVy7i6Mn8Ku3SCFCggY7XeMBfcfLn9kKp5SCBVrrU1L5vtDUBmT0YDBBM74rsnP9QW+/rEMDGcmX6DiMPH7V3+wWZAuAR5pw5KWhMNBa2vkOwIPkXLR8CubnNoHVOAFU06xatcb4e2LTmDbIFPIoNKcM/4Dp2Ty/vRG/LILkuPPVeWS062HQh7BtS2qCO5W2fPfxumfHFj82OZPSygFQxSfJ2rEwMFXrestGMI sWK64kFW MoC92i+cmdXSHdEvwdgoiIxBKK6kNOYsd9tUOTHSWjiA9OqniyyTomv29nCAoOnX8J30MnOEyCj74TE0tY2VUQ7q2+OERGOkbDmw8kMuICpzrnuoGUHtHhWzKX400kUQAawohDmWiYB2ZGscVkVZZZ6/0CKfFazXZR5gaH17CEwtF9q7NDnT8CtEZJ0a+yhsX5Nrz8c4Ylutha/iz6n3vA8wez/KWfHfx3NGcouuxf4CePG4r4qaLhBe3Ak6A/kiVbv9GppSCPcKi2EoHU8TV46v+aoylO6o6kWOUXLgIcU7j/6hFP09DvD5G8BeuHYEI7ewOGeZyKAdoKu+6yfciMsMZgW+a1/1V3mXkBhoSG4lHctK8zda9XgyJWQjqwPTPezoHyz3efLsP5Dlu1UJk4zAU266lZBVUvLKn/LDaq//VS1dzy15bZgQIae4Sv6o8bY5issiHrdvtO73ojLnM6NJv8A19EjtwIGBFB24P/th2CUcpIVsl0ql9vxf/ZST777rhestJPXR6r4sfZzorlEU2TK4BFoglYstj6VLkOeXo9lTARN1wTr8A8wKEO7uxxEydwfw8WfEWTKmqeIH2fpsxNoABcjS0Y3zlbQeVinNbES2N2O5w4yDp1AD8JWncD+ZtF22mruypr9Tf+Y+4cUzxMF6WStUMwl2/G2Awj3vz5nul/ZWsr2+R7iNLZON0+5bAeN+dYf1e7mqn3xZRt+tW3dHtDHozX0bhtbR6lB9GTpXJnW8KFj9J8iCBwl2bfpMIzohtBEoQ3/w= 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: --000000000000822f9006385a9c32 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jun 24, 2025 at 11:18=E2=80=AFPM David Hildenbrand wrote: > On 24.06.25 06:24, Li Wang wrote: > > The current implementation of test_unmerge_uffd_wp() explicitly sets > > `uffdio_api.features =3D UFFD_FEATURE_PAGEFAULT_FLAG_WP` before calling > > UFFDIO_API. This can cause the ioctl() call to fail with EINVAL on > kernels > > that do not support UFFD-WP, leading the test to fail unnecessarily: > > > > # ------------------------------ > > # running ./ksm_functional_tests > > # ------------------------------ > > # TAP version 13 > > # 1..9 > > # # [RUN] test_unmerge > > # ok 1 Pages were unmerged > > # # [RUN] test_unmerge_zero_pages > > # ok 2 KSM zero pages were unmerged > > # # [RUN] test_unmerge_discarded > > # ok 3 Pages were unmerged > > # # [RUN] test_unmerge_uffd_wp > > # not ok 4 UFFDIO_API failed <----- > > # # [RUN] test_prot_none > > # ok 5 Pages were unmerged > > # # [RUN] test_prctl > > # ok 6 Setting/clearing PR_SET_MEMORY_MERGE works > > # # [RUN] test_prctl_fork > > # # No pages got merged > > # # [RUN] test_prctl_fork_exec > > # ok 7 PR_SET_MEMORY_MERGE value is inherited > > # # [RUN] test_prctl_unmerge > > # ok 8 Pages were unmerged > > # Bail out! 1 out of 8 tests failed > > # # Planned tests !=3D run tests (9 !=3D 8) > > # # Totals: pass:7 fail:1 xfail:0 xpass:0 skip:0 error:0 > > # [FAIL] > > > > This patch improves compatibility and robustness of the UFFD-WP test > > (test_unmerge_uffd_wp) by correctly implementing the UFFDIO_API > > two-step handshake as recommended by the userfaultfd(2) man page. > > > > Key changes: > > > > 1. Use features=3D0 in the initial UFFDIO_API call to query supported > > feature bits, rather than immediately requesting WP support. > > > > 2. Skip the test gracefully if: > > - UFFDIO_API fails with EINVAL (e.g. unsupported API version), or > > - UFFD_FEATURE_PAGEFAULT_FLAG_WP is not advertised by the kernel. > > > > 3. Close the initial userfaultfd and create a new one before enabling > > the required feature, since UFFDIO_API can only be called once per > fd. > > > > 4. Improve diagnostics by distinguishing between expected and unexpecte= d > > failures, using strerror() to report errors. > > > > This ensures the test behaves correctly across a wider range of kernel > > versions and configurations, while preserving the intended behavior on > > kernels that support UFFD-WP. > > > > Suggestted-by: David Hildenbrand > > Signed-off-by: Li Wang > > Cc: Aruna Ramakrishna > > Cc: Bagas Sanjaya > > Cc: Catalin Marinas > > Cc: Dave Hansen > > Cc: Joey Gouly > > Cc: Johannes Weiner > > Cc: Keith Lucas > > Cc: Ryan Roberts > > Cc: Shuah Khan > > --- > > > > Notes: > > v1 --> v2: > > * Close the original userfaultfd and open a new one before > enabling features > > * Reworked UFFDIO_API negotiation to follow the official two-step > handshake > > > > .../selftests/mm/ksm_functional_tests.c | 28 +++++++++++++++++-= - > > 1 file changed, 26 insertions(+), 2 deletions(-) > > > > diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c > b/tools/testing/selftests/mm/ksm_functional_tests.c > > index b61803e36d1c..19e5b741893a 100644 > > --- a/tools/testing/selftests/mm/ksm_functional_tests.c > > +++ b/tools/testing/selftests/mm/ksm_functional_tests.c > > @@ -393,9 +393,13 @@ static void test_unmerge_uffd_wp(void) > > > > /* See if UFFD-WP is around. */ > > uffdio_api.api =3D UFFD_API; > > - uffdio_api.features =3D UFFD_FEATURE_PAGEFAULT_FLAG_WP; > > + uffdio_api.features =3D 0; > > if (ioctl(uffd, UFFDIO_API, &uffdio_api) < 0) { > > - ksft_test_result_fail("UFFDIO_API failed\n"); > > + if (errno =3D=3D EINVAL) > > + ksft_test_result_skip("The API version requested > is not supported\n"); > > + else > > + ksft_test_result_fail("UFFDIO_API failed: %s\n", > strerror(errno)); > > + > > goto close_uffd; > > } > > if (!(uffdio_api.features & UFFD_FEATURE_PAGEFAULT_FLAG_WP)) { > > @@ -403,6 +407,26 @@ static void test_unmerge_uffd_wp(void) > > goto close_uffd; > > } > > > > + /* > > + * UFFDIO_API must only be called once to enable features. > > + * So we close the old userfaultfd and create a new one to > > + * actually enable UFFD_FEATURE_PAGEFAULT_FLAG_WP. > > + */ > > + close(uffd); > > + uffd =3D syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK); > > + if (uffd < 0) { > > + ksft_test_result_skip("__NR_userfaultfd failed\n"); > > If it now suddenly fails (after it working above), this sure is a fail, > right? > Yes, you're right, here should ksft_test_result_fail(). > > Apart from that > > Acked-by: David Hildenbrand > Thanks for the review! --=20 Regards, Li Wang --000000000000822f9006385a9c32 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Tue, Jun 24, 2025 at 11:18= =E2=80=AFPM David Hildenbrand <david= @redhat.com> wrote:
On 24.06.25 06:24, Li Wang wrote:
> The current implementation of test_unmerge_uffd_wp() explicitly sets > `uffdio_api.features =3D UFFD_FEATURE_PAGEFAULT_FLAG_WP` before callin= g
> UFFDIO_API. This can cause the ioctl() call to fail with EINVAL on ker= nels
> that do not support UFFD-WP, leading the test to fail unnecessarily: >
>=C2=A0 =C2=A0 # ------------------------------
>=C2=A0 =C2=A0 # running ./ksm_functional_tests
>=C2=A0 =C2=A0 # ------------------------------
>=C2=A0 =C2=A0 # TAP version 13
>=C2=A0 =C2=A0 # 1..9
>=C2=A0 =C2=A0 # # [RUN] test_unmerge
>=C2=A0 =C2=A0 # ok 1 Pages were unmerged
>=C2=A0 =C2=A0 # # [RUN] test_unmerge_zero_pages
>=C2=A0 =C2=A0 # ok 2 KSM zero pages were unmerged
>=C2=A0 =C2=A0 # # [RUN] test_unmerge_discarded
>=C2=A0 =C2=A0 # ok 3 Pages were unmerged
>=C2=A0 =C2=A0 # # [RUN] test_unmerge_uffd_wp
>=C2=A0 =C2=A0 # not ok 4 UFFDIO_API failed=C2=A0 =C2=A0 =C2=A0<-----=
>=C2=A0 =C2=A0 # # [RUN] test_prot_none
>=C2=A0 =C2=A0 # ok 5 Pages were unmerged
>=C2=A0 =C2=A0 # # [RUN] test_prctl
>=C2=A0 =C2=A0 # ok 6 Setting/clearing PR_SET_MEMORY_MERGE works
>=C2=A0 =C2=A0 # # [RUN] test_prctl_fork
>=C2=A0 =C2=A0 # # No pages got merged
>=C2=A0 =C2=A0 # # [RUN] test_prctl_fork_exec
>=C2=A0 =C2=A0 # ok 7 PR_SET_MEMORY_MERGE value is inherited
>=C2=A0 =C2=A0 # # [RUN] test_prctl_unmerge
>=C2=A0 =C2=A0 # ok 8 Pages were unmerged
>=C2=A0 =C2=A0 # Bail out! 1 out of 8 tests failed
>=C2=A0 =C2=A0 # # Planned tests !=3D run tests (9 !=3D 8)
>=C2=A0 =C2=A0 # # Totals: pass:7 fail:1 xfail:0 xpass:0 skip:0 error:0<= br> >=C2=A0 =C2=A0 # [FAIL]
>
> This patch improves compatibility and robustness of the UFFD-WP test > (test_unmerge_uffd_wp) by correctly implementing the UFFDIO_API
> two-step handshake as recommended by the userfaultfd(2) man page.
>
> Key changes:
>
> 1. Use features=3D0 in the initial UFFDIO_API call to query supported<= br> >=C2=A0 =C2=A0 =C2=A0feature bits, rather than immediately requesting WP= support.
>
> 2. Skip the test gracefully if:
>=C2=A0 =C2=A0 =C2=A0- UFFDIO_API fails with EINVAL (e.g. unsupported AP= I version), or
>=C2=A0 =C2=A0 =C2=A0- UFFD_FEATURE_PAGEFAULT_FLAG_WP is not advertised = by the kernel.
>
> 3. Close the initial userfaultfd and create a new one before enabling<= br> >=C2=A0 =C2=A0 =C2=A0the required feature, since UFFDIO_API can only be = called once per fd.
>
> 4. Improve diagnostics by distinguishing between expected and unexpect= ed
>=C2=A0 =C2=A0 =C2=A0failures, using strerror() to report errors.
>
> This ensures the test behaves correctly across a wider range of kernel=
> versions and configurations, while preserving the intended behavior on=
> kernels that support UFFD-WP.
>
> Suggestted-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: Li Wang <liwang@redhat.com>
> Cc: Aruna Ramakrishna <aruna.ramakrishna@oracle.com>
> Cc: Bagas Sanjaya <bagasdotme@gmail.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: Joey Gouly <joey.gouly@arm.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Keith Lucas <keith.lucas@oracle.com>
> Cc: Ryan Roberts <ryan.roberts@arm.com>
> Cc: Shuah Khan <shuah@kernel.org>
> ---
>
> Notes:
>=C2=A0 =C2=A0 =C2=A0 v1 --> v2:
>=C2=A0 =C2=A0 =C2=A0 =C2=A0* Close the original userfaultfd and open a = new one before enabling features
>=C2=A0 =C2=A0 =C2=A0 =C2=A0* Reworked UFFDIO_API negotiation to follow = the official two-step handshake
>
>=C2=A0 =C2=A0.../selftests/mm/ksm_functional_tests.c=C2=A0 =C2=A0 =C2= =A0 =C2=A0| 28 +++++++++++++++++--
>=C2=A0 =C2=A01 file changed, 26 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools= /testing/selftests/mm/ksm_functional_tests.c
> index b61803e36d1c..19e5b741893a 100644
> --- a/tools/testing/selftests/mm/ksm_functional_tests.c
> +++ b/tools/testing/selftests/mm/ksm_functional_tests.c
> @@ -393,9 +393,13 @@ static void test_unmerge_uffd_wp(void)
>=C2=A0 =C2=A0
>=C2=A0 =C2=A0 =C2=A0 =C2=A0/* See if UFFD-WP is around. */
>=C2=A0 =C2=A0 =C2=A0 =C2=A0uffdio_api.api =3D UFFD_API;
> -=C2=A0 =C2=A0 =C2=A0uffdio_api.features =3D UFFD_FEATURE_PAGEFAULT_FL= AG_WP;
> +=C2=A0 =C2=A0 =C2=A0uffdio_api.features =3D 0;
>=C2=A0 =C2=A0 =C2=A0 =C2=A0if (ioctl(uffd, UFFDIO_API, &uffdio_api)= < 0) {
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_test_result_fail= ("UFFDIO_API failed\n");
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (errno =3D=3D EINV= AL)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0ksft_test_result_skip("The API version requested is not support= ed\n");
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0else
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0ksft_test_result_fail("UFFDIO_API failed: %s\n", strerror(= errno));
> +
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto close_uffd;=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0}
>=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!(uffdio_api.features & UFFD_FEATURE= _PAGEFAULT_FLAG_WP)) {
> @@ -403,6 +407,26 @@ static void test_unmerge_uffd_wp(void)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto close_uffd;=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0}
>=C2=A0 =C2=A0
> +=C2=A0 =C2=A0 =C2=A0/*
> +=C2=A0 =C2=A0 =C2=A0 * UFFDIO_API must only be called once to enable = features.
> +=C2=A0 =C2=A0 =C2=A0 * So we close the old userfaultfd and create a n= ew one to
> +=C2=A0 =C2=A0 =C2=A0 * actually enable UFFD_FEATURE_PAGEFAULT_FLAG_WP= .
> +=C2=A0 =C2=A0 =C2=A0 */
> +=C2=A0 =C2=A0 =C2=A0close(uffd);
> +=C2=A0 =C2=A0 =C2=A0uffd =3D syscall(__NR_userfaultfd, O_CLOEXEC | O_= NONBLOCK);
> +=C2=A0 =C2=A0 =C2=A0if (uffd < 0) {
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ksft_test_result_skip= ("__NR_userfaultfd failed\n");

If it now suddenly fails (after it working above), this sure is a fail, right?

Yes, you're right, here should ksft_test_result_= fail().

=C2=A0

Apart from that

Acked-by: David Hildenbrand <david@redhat.com>

Thanks for the review!=


--
Regards,
Li Wang
--000000000000822f9006385a9c32--