From patchwork Wed Jun 26 13:05:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Audra Mitchell X-Patchwork-Id: 13712885 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 19514C27C4F for ; Wed, 26 Jun 2024 13:05:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C0166B0083; Wed, 26 Jun 2024 09:05:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 36DB56B0085; Wed, 26 Jun 2024 09:05:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20F4A6B0088; Wed, 26 Jun 2024 09:05:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 021776B0083 for ; Wed, 26 Jun 2024 09:05:31 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 43B0DC10B8 for ; Wed, 26 Jun 2024 13:05:31 +0000 (UTC) X-FDA: 82273061262.20.0ECFA22 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 614D88005E for ; Wed, 26 Jun 2024 13:05:24 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ArkhL1yB; spf=pass (imf30.hostedemail.com: domain of audra@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=audra@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719407112; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=Mr03uo/qNadzOQlFY//QZdUfSWytOj/GgGVXQ4GRB8Q=; b=FEWp4lyMdz7h0kcLZEquFqjAPBD94H185XrTOzkH9bG7ccauWzWUfK9u+Hyhl03laX74WI 4VXPjvtmKohB0D3DxzEXot5ystmI4QydvjxwDemHGJcGBKtuG+gOmou4YvU3zOwaG/GOUw /yUzAgpp91uMybBUNSgq+coLaF1iUvM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ArkhL1yB; spf=pass (imf30.hostedemail.com: domain of audra@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=audra@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719407112; a=rsa-sha256; cv=none; b=7AJmCPmZHnnw9XLQQA5FLMU/W3/n329Q0uG+Icm9OX2xkCyJMAX4UvSQgvS2b8ZdnxVidJ SH8YADkDXchljabCQbDbtSePPLIUrv+hd5XDzJ5NxYdVFobUlwR5yzqPcv+8pAaK/bgP2r ykyN3hd9deUae+Nuldzf4Wf8gvX+hpU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719407123; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Mr03uo/qNadzOQlFY//QZdUfSWytOj/GgGVXQ4GRB8Q=; b=ArkhL1yBOQAVYNUJIZeRp0cWjh4kwmKJtdwCCaSmnFGPk3cNNME2m93MOMpe60DskVbogO uKc9ZlKu2QXw6iLeRRt5DBa6jKBAyezTPk4a7BMHDyWzSNX8CW4CmptLD5LDVUQnCOsFFO PUOyk3EGHTjcFIGS94xQquj1ahVbO30= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-eCZDRI6TNFqZg1KfqIWAxA-1; Wed, 26 Jun 2024 09:05:21 -0400 X-MC-Unique: eCZDRI6TNFqZg1KfqIWAxA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A06B919560AD; Wed, 26 Jun 2024 13:05:19 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.34.168]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DABDE1956050; Wed, 26 Jun 2024 13:05:16 +0000 (UTC) From: Audra Mitchell To: viro@zeniv.linux.org.uk Cc: brauner@kernel.org, jack@suse.cz, aarcange@redhat.com, akpm@linux-foundation.org, rppt@linux.vnet.ibm.com, shli@fb.com, peterx@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, shuah@kernel.org, linux-kselftest@vger.kernel.org, raquini@redhat.com, linux-mm@kvack.org Subject: [PATCH v3 1/3] Fix userfaultfd_api to return EINVAL as expected Date: Wed, 26 Jun 2024 09:05:11 -0400 Message-ID: <20240626130513.120193-1-audra@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Stat-Signature: pnwn1ej73y1f45n9tcyn14khi7cuopeo X-Rspam-User: X-Rspamd-Queue-Id: 614D88005E X-Rspamd-Server: rspam02 X-HE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ROcvGt5A34Fya9xpCckkbVeGiNXeQHK96jiPSMmYoSkxGNTPHO+1opFAKCl5Molxo/RKi0qYp1EPLKTzs5WM+Z1htd9ZuQangm8T1eEBUNN7ZYTvi6sD7JZx4QuI6TrOCyoBsTYtQe3Lof7vJ9ozM9h/1aetsp/YDxTedkSak+nqhxBNgoc1Gwv4QLpLpWQ1N+O+BrT6OjS1wlNB0ADS2IvK5WYwxytD+cZJFlO5O4gjqjyRizmmL7iTlRlhQiHu7hkEm3MN/5A== 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: Currently if we request a feature that is not set in the Kernel config we fail silently and return all the available features. However, the man page indicates we should return an EINVAL. We need to fix this issue since we can end up with a Kernel warning should a program request the feature UFFD_FEATURE_WP_UNPOPULATED on a kernel with the config not set with this feature. [ 200.812896] WARNING: CPU: 91 PID: 13634 at mm/memory.c:1660 zap_pte_range+0x43d/0x660 [ 200.820738] Modules linked in: [ 200.869387] CPU: 91 PID: 13634 Comm: userfaultfd Kdump: loaded Not tainted 6.9.0-rc5+ #8 [ 200.877477] Hardware name: Dell Inc. PowerEdge R6525/0N7YGH, BIOS 2.7.3 03/30/2022 [ 200.885052] RIP: 0010:zap_pte_range+0x43d/0x660 Fixes: e06f1e1dd499 ("userfaultfd: wp: enabled write protection in userfaultfd API") Signed-off-by: Audra Mitchell --- fs/userfaultfd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index eee7320ab0b0..17e409ceaa33 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -2057,7 +2057,7 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx, goto out; features = uffdio_api.features; ret = -EINVAL; - if (uffdio_api.api != UFFD_API || (features & ~UFFD_API_FEATURES)) + if (uffdio_api.api != UFFD_API) goto err_out; ret = -EPERM; if ((features & UFFD_FEATURE_EVENT_FORK) && !capable(CAP_SYS_PTRACE)) @@ -2081,6 +2081,11 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx, uffdio_api.features &= ~UFFD_FEATURE_WP_UNPOPULATED; uffdio_api.features &= ~UFFD_FEATURE_WP_ASYNC; #endif + + ret = -EINVAL; + if (features & ~uffdio_api.features) + goto err_out; + uffdio_api.ioctls = UFFD_API_IOCTLS; ret = -EFAULT; if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api))) From patchwork Wed Jun 26 13:05:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Audra Mitchell X-Patchwork-Id: 13712886 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 A5D38C27C4F for ; Wed, 26 Jun 2024 13:05:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2AD246B0088; Wed, 26 Jun 2024 09:05:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 234D46B0089; Wed, 26 Jun 2024 09:05:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D5E86B008A; Wed, 26 Jun 2024 09:05:36 -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 E1E696B0088 for ; Wed, 26 Jun 2024 09:05:35 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A620D1C1D6E for ; Wed, 26 Jun 2024 13:05:33 +0000 (UTC) X-FDA: 82273061346.11.D455EB0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf21.hostedemail.com (Postfix) with ESMTP id B499D1C001D for ; Wed, 26 Jun 2024 13:05:31 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VBzKKOT4; spf=pass (imf21.hostedemail.com: domain of audra@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=audra@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719407123; a=rsa-sha256; cv=none; b=c1R9meRWJnHzmH6p6FPigErrYpEF0SO9QS50Dt1gWrH3D8BJtk3dtvrPc5swMWFga2cLOl ZR4aWUU3TN1r1ybEvRfekW7Ji6vDMJ5p7o3tN/R4sBxqzAhuikjl5ZGlqc6FvBfTPdQ7dA d2mkDXfHZ36TXyhbSvahUsWtP3PYkIE= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VBzKKOT4; spf=pass (imf21.hostedemail.com: domain of audra@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=audra@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719407123; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=udTceohd6Xr0o0t6E07fDA2ozt9gdMnkrdCtTzzon0Y=; b=6xQhpQhPCH63eK3MdpBzR0q0iIrAN5Uw7/CIvsIgZ6qtKneBt9/sj6FIWNFS5AsXOV0MIH vJoto4ZY0MVyY3MXD6kn+UaYr+ah6cxZZW/q6/GxSb/XVvSplMf3e49XqD3TMtxeb/Nt5g EaW9FXLPzOkTc7v23efNa4xJ8NEjtwE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719407131; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=udTceohd6Xr0o0t6E07fDA2ozt9gdMnkrdCtTzzon0Y=; b=VBzKKOT4tfFHqWTc0B/LexHWT5jvPhdiYITFldlXIO5MzajaWhS2HozSPnlo24hz8iWO7g 74ike2upjO324Q95gMIitXNapDNCAM/hFunevdEsitEuAUIs0TCSGBu+O6KJAVWmG1K77h EPgtb7voi1ABva07aOPhu9Ig2EdWhU8= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-539-JMed5K9SNQyAZYFHgEAV9Q-1; Wed, 26 Jun 2024 09:05:25 -0400 X-MC-Unique: JMed5K9SNQyAZYFHgEAV9Q-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 61C3819560AB; Wed, 26 Jun 2024 13:05:23 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.34.168]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2CF111956050; Wed, 26 Jun 2024 13:05:21 +0000 (UTC) From: Audra Mitchell To: viro@zeniv.linux.org.uk Cc: brauner@kernel.org, jack@suse.cz, aarcange@redhat.com, akpm@linux-foundation.org, rppt@linux.vnet.ibm.com, shli@fb.com, peterx@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, shuah@kernel.org, linux-kselftest@vger.kernel.org, raquini@redhat.com, linux-mm@kvack.org Subject: [PATCH v3 2/3] Update uffd-stress to handle EINVAL for unset config features Date: Wed, 26 Jun 2024 09:05:12 -0400 Message-ID: <20240626130513.120193-2-audra@redhat.com> In-Reply-To: <20240626130513.120193-1-audra@redhat.com> References: <20240626130513.120193-1-audra@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Stat-Signature: d89zpzzsdpi1rqaryfjq6fdmocc8qq1i X-Rspamd-Queue-Id: B499D1C001D X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1719407131-581765 X-HE-Meta: U2FsdGVkX1/mhftvO7SFRmGlTh+uFxT9eKXLeZf0O8p3TZYr0vW6qdFs/CaTv7YLsJwQLqInKTyrJ4JIRky4GU/aKN6ypt4Tg70smu1rC/nAXAKeXH0vd1Ig2PlmwAbfYWjaYs4SF8zTjcHCOCR55koB+5Bzc32qePbwalFP4EMVLfCY8lrkF/WJHjgNCUr9LrC36VpMkLifAS6LyXTu+5xFqIrdeuSjnZ8Mc0lHydEPVHtP27e4R/7Vkcxq0igge1ZLRiVQtyaRWObjaDAqMQGFkAt4j2PL2iPVqgPSC0eHYkMhjlB3r9+HvwrupHo8K7wgcX2QMso9n8aslSrJuDNMqopfm6WAqq5oOhbd/tlu0+HlkqWe5ELiUGJSlsEy1RNukz0/dyv7T9buYfof9a9MJIwgk/89KNcnNrSwzAm1FujM0kXuU89jn9sFw0oiCfc1X2t2U2H/I6gBoAAHJDsNwI7+5NLLK/kXXuXNwGBo0eFgUJstUpXzlmFiSMxMtDzXhCgvzCfrzy8OnGa6Yq1GMpC+x0KgBgHStnk83YdMgNo0UueUCfXQXdIPsLQ8cMd0S7WFxGmwrTodcRr+iQYori83ps8S+One02/EbCGMOXLSz7j3SOVJlM2vHIdQSvGMap+KfqOkQYSXpuXRdwcVOOlfVAvCH6XSWIvcbzE/zaOnGf4unNghfGwPAmawHgchVc6tcVf+QXgFGIQanX2Fo8IsgDWH15+7iFR1KrdinVDrLBd1y/A0IxYfxRW2aF30s78WE+mOD11Z6R3yrP7ts/I9TfgYvQidRDBdMzABJ7wDmk+TQIinjdwhjEsomCJZSkbRVxF3P1m2z3ohnitbQbLEhAV8lsqvjhmaCmZv+OHlMxQI30/Mc8Cx2PP5JMgOdQa2Ad7Xzt7G548l9epepeITZp+8dWr2naHKmNhCnnOrfZ7ggL3Qj62nqk7D/TfT+VGKasq5U0kJC3j I/AXxand 5JKQB2/Tb6oQisk7E1V/SSdy15iYAU3zoRgu1IeqRqc1C7e7kSWYkHj2ZugfmNpj90fKsKbUMWqLwWD451BHydEnimKuzm0Kz3BG6BHLkOrah1E/JmeYRCrEFCrutzzESPqEJSulPf25ix2trzAYkvggFynGL4Q6skuilmqWm20NBIOqn7/IUpxQlrOT2vWgCExrFlECvWPAmUF4EYgPNsUEAnyEedQgpyOnDsJj8wDvY/uTDOEsDO/UYmG1VK7zxxbH1f0Y8GS8lgF8EW7Yh8rtkF51Oc88EzLRMgAcK+2//Qfc= 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: Now that we have updated userfaultfd_api to correctly return EIVAL when a feature is requested but not available, let's fix the uffd-stress test to only set the UFFD_FEATURE_WP_UNPOPULATED feature when the config is set. In addition, still run the test if the CONFIG_PTE_MARKER_UFFD_WP is not set, just dont use the corresponding UFFD_FEATURE_WP_UNPOPULATED feature. Signed-off-by: Audra Mitchell --- tools/testing/selftests/mm/uffd-stress.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index f78bab0f3d45..b9b6d858eab8 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -38,6 +38,8 @@ #ifdef __NR_userfaultfd +uint64_t features; + #define BOUNCE_RANDOM (1<<0) #define BOUNCE_RACINGFAULTS (1<<1) #define BOUNCE_VERIFY (1<<2) @@ -247,10 +249,14 @@ static int userfaultfd_stress(void) unsigned long nr; struct uffd_args args[nr_cpus]; uint64_t mem_size = nr_pages * page_size; + int flags = 0; memset(args, 0, sizeof(struct uffd_args) * nr_cpus); - if (uffd_test_ctx_init(UFFD_FEATURE_WP_UNPOPULATED, NULL)) + if (features & UFFD_FEATURE_WP_UNPOPULATED && test_type == TEST_ANON) + flags = UFFD_FEATURE_WP_UNPOPULATED; + + if (uffd_test_ctx_init(flags, NULL)) err("context init failed"); if (posix_memalign(&area, page_size, page_size)) @@ -385,8 +391,6 @@ static void set_test_type(const char *type) static void parse_test_type_arg(const char *raw_type) { - uint64_t features = UFFD_API_FEATURES; - set_test_type(raw_type); if (!test_type) @@ -409,8 +413,8 @@ static void parse_test_type_arg(const char *raw_type) * feature. */ - if (userfaultfd_open(&features)) - err("Userfaultfd open failed"); + if (uffd_get_features(&features)) + err("failed to get available features"); test_uffdio_wp = test_uffdio_wp && (features & UFFD_FEATURE_PAGEFAULT_FLAG_WP); From patchwork Wed Jun 26 13:05:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Audra Mitchell X-Patchwork-Id: 13712887 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 28AD8C30659 for ; Wed, 26 Jun 2024 13:05:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5F916B0089; Wed, 26 Jun 2024 09:05:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B11516B008A; Wed, 26 Jun 2024 09:05:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93D326B0093; Wed, 26 Jun 2024 09:05:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 744C86B0089 for ; Wed, 26 Jun 2024 09:05:38 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DD77A160FE8 for ; Wed, 26 Jun 2024 13:05:37 +0000 (UTC) X-FDA: 82273061514.05.5B46AED Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 170394001D for ; Wed, 26 Jun 2024 13:05:35 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KdBdKsND; spf=pass (imf11.hostedemail.com: domain of audra@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=audra@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719407120; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JykDiXdqlJ6ciyv4C7jHD9UAaumemJj0MYtCVwinG38=; b=iXiKzxWk4836SUOju8E7ZkQdvbSc9jENlOyuYNECnlZFbM8IAGmchQe0oWHRruSdNcruKc BpUlAYRfMjlyY39jiZXRcUWrslS98sc18BN7cG86k8u4PcNqlEQ2ags5sGIUS+SygY+R3I m1yvyjg+bGJmnwb7rD0vd92tmLN1XNU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719407120; a=rsa-sha256; cv=none; b=OXBEA4FDl9sJmlJIp9Le+qk2rAzgDnlEBpsGqC+l75tUchZp1//czIO0549PFLUSPX5zLj 3lkfuqAHtaeEr758s321SqoDeOJO9xaTF3PkGc3j8Y73tT+uiv4mdUPSuXQOOhJqnZFr0p TmXnQ108yEJQKAgGKZRJxlWbvxIESwU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KdBdKsND; spf=pass (imf11.hostedemail.com: domain of audra@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=audra@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719407135; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JykDiXdqlJ6ciyv4C7jHD9UAaumemJj0MYtCVwinG38=; b=KdBdKsNDhj9uSs6MQ+Jg48EjDHpNfGGJFY1UniHziZGXLNT0Xob0dVbSeekbFVtr/JpyVS eQdFNNVy7wWwKIViNFa4B+DG49ntoGF8OZ8VjLLCdcya7xc7sthbxk6x+cBLhYfah/ozhB Hyt49QM6kpgUcpjsaouHNChnhn0PjwA= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-18-ITRtfxPeOlmGxIiufKwUFg-1; Wed, 26 Jun 2024 09:05:31 -0400 X-MC-Unique: ITRtfxPeOlmGxIiufKwUFg-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 04A4E19560A7; Wed, 26 Jun 2024 13:05:28 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.34.168]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 117261956050; Wed, 26 Jun 2024 13:05:24 +0000 (UTC) From: Audra Mitchell To: viro@zeniv.linux.org.uk Cc: brauner@kernel.org, jack@suse.cz, aarcange@redhat.com, akpm@linux-foundation.org, rppt@linux.vnet.ibm.com, shli@fb.com, peterx@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, shuah@kernel.org, linux-kselftest@vger.kernel.org, raquini@redhat.com, linux-mm@kvack.org Subject: [PATCH v3 3/3] Turn off test_uffdio_wp if CONFIG_PTE_MARKER_UFFD_WP is not configured. Date: Wed, 26 Jun 2024 09:05:13 -0400 Message-ID: <20240626130513.120193-3-audra@redhat.com> In-Reply-To: <20240626130513.120193-1-audra@redhat.com> References: <20240626130513.120193-1-audra@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Stat-Signature: rkag3begutdueqatx1e7ggnt5qpo419h X-Rspamd-Queue-Id: 170394001D X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1719407135-723457 X-HE-Meta: U2FsdGVkX19OdT7+2k+iuynUK4I3H9hq23LQQXYBvAYnTJ8JELIfwXzBDymlIlO/7HwPACZF8AWgVyyh41EUJiNxwP0+8a9kw+TcmFd/RT9rFBVnvin2IOq9eNdXbwa9icMY1iyPL44D0lwTS44hkYnR1ud9BxFfpD3ZaLr3IaQXTiTPOHL7EZ7Jo8Uj7OS8YWx8imf5Rw6HgpHJv3GAtKTmXfahyG+0LRRkACnb1hsX0RYr5rPI5vo5kQ/4nzCLHAQT1LTjNvc6QvDgQvUUNKU8cvR2zwfac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.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: If CONFIG_PTE_MARKER_UFFD_WP is disabled, then we turn off three features in userfaultfd_api (UFFD_FEATURE_WP_HUGETLBFS_SHMEM, UFFD_FEATURE_WP_UNPOPULATED, and UFFD_FEATURE_WP_ASYNC). Currently this test always will call uffdio_regsiter with the flag UFFDIO_REGISTER_MODE_WP. However, the kernel ensures in vma_can_userfault that if the feature UFFD_FEATURE_WP_HUGETLBFS_SHMEM is disabled, only allow the VM_UFFD_WP on anonymous vmas, meaning our call to uffdio_regsiter will fail. We still want to be able to run the test even if we have CONFIG_PTE_MARKER_UFFD_WP disabled, so check to see if the feature UFFD_FEATURE_WP_HUGETLBFS_SHMEM has been turned off in the test and if so, disable us from calling uffdio_regsiter with the flag UFFDIO_REGISTER_MODE_WP. Signed-off-by: Audra Mitchell Reviewed-by: Peter Xu --- tools/testing/selftests/mm/uffd-stress.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index b9b6d858eab8..3266ae885f75 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -419,6 +419,9 @@ static void parse_test_type_arg(const char *raw_type) test_uffdio_wp = test_uffdio_wp && (features & UFFD_FEATURE_PAGEFAULT_FLAG_WP); + if (test_type != TEST_ANON && !(features & UFFD_FEATURE_WP_HUGETLBFS_SHMEM)) + test_uffdio_wp = false; + close(uffd); uffd = -1; }