From patchwork Fri Jun 21 18:12:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Audra Mitchell X-Patchwork-Id: 13707976 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE336156227 for ; Fri, 21 Jun 2024 18:12:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718993558; cv=none; b=ijku81m3KuPclHwjDjqps85K2G6RSyLboQJ8WsO2YOkiB1KhJm5ZIn4kiwWXT3UPR6rxLcNdXNX/GjmnyJEhgHcA/0wt+CkLLGlqcifd51HrefTjHkoNIa9/e3rXKlaIz51A9WKW1/uuM5ze5U4XWAQwPAPBiSLMvpY+GtYmTlA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718993558; c=relaxed/simple; bh=zn0J5hnyo6dVCxNaGHylzs/o0p86kxCsjWOV/SevYqw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Sacmyqp13bzouOd8ga1Xc9RvWfmhrMaWV4kPq4cCFuIs4i7VlIBxdLfPHni8p2nOQtIUsjD+YeQBYUHjPZkCq1HVQ0yq2gZ4ZEltU5CfsnmaDwf9c6WNHrFhxmpOL8rr4dnI9NaOmHv53gh88xeWNeoGdp2ivoFrRqk2WHVzgfo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=RQl5Q5CU; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RQl5Q5CU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718993555; 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=RQl5Q5CUGP+WN80rpAole8uPiINqK/u/SGTokYsDx97IdwXpbzynmaLwIRh5kfmWUJq3eb iGK/ARwXowPgXT+HedJ64M6c4r8KXdkKWvSrmztvQz2FIiVmzJMpqCojkqCo4fp39R1tV2 ZBq03tyfPyN7JfHHrqx2EcNRvhxuOWI= Received: from mx-prod-mc-04.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-333-RT0_tw-tOvOI7aOA-C_GCg-1; Fri, 21 Jun 2024 14:12:32 -0400 X-MC-Unique: RT0_tw-tOvOI7aOA-C_GCg-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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2923219560A2; Fri, 21 Jun 2024 18:12:30 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.33.154]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 73F821956048; Fri, 21 Jun 2024 18:12:27 +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 Subject: [PATCH v2 1/3] Fix userfaultfd_api to return EINVAL as expected Date: Fri, 21 Jun 2024 14:12:22 -0400 Message-ID: <20240621181224.3881179-1-audra@redhat.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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 Acked-by: Peter Xu --- 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 Fri Jun 21 18:12:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Audra Mitchell X-Patchwork-Id: 13707977 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C611017B40F for ; Fri, 21 Jun 2024 18:12:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718993564; cv=none; b=huBA+Quze6afKJ6MS4iuPrbz+HEkSb1XDU1LONN/J62aViCMEKD3b3de7N7CQmEUKYgJqT9TC66RioqoDA/KFzTredH2aPrX5D3GH9hIcfrpzQJjR4WhKVE8Udo7wrE4W85WLCIqkoj+bBJR12aWweBPG0aPWVKMI6immDIn4pw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718993564; c=relaxed/simple; bh=qkKdzACF1keOV6J4gFQTNFSJosbImY3UiiUaqJIsSvI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b5cAmNI9PrHo3kimwubGpHi2RN5Ys1kjoD/MkaLe44VV4M6nv5T62Dp06Tpoic6h2d2UYvRQKxhEKIL0hRbCuMnKFTP4W5eDN0Tsj7wNhe4OYLhkh47cluQH5WG66p94eO1MgxtKgYbt5cZHRY4j8bysoCNkEUEXc/4+dRUF2wM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=OsMUY6L+; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OsMUY6L+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718993561; 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=OsMUY6L+QEUy44HxbeyYpFohLSxmoVFX3WpU3UMYrstzrOLCvpK6ob3W9WOFLKdv/eDJ02 2OsFcbw7iUY2ZLfcBjzGtFFEXA63b6je8Dghr+w4i0gh2IGkUW2G1vlurvwSwfoBXuvDZj 4eN76bkKeqJRYAeIT1A9sCIlCBnPr/Y= Received: from mx-prod-mc-04.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-215-1EwU5UKBM66XOkdkmdarqQ-1; Fri, 21 Jun 2024 14:12:36 -0400 X-MC-Unique: 1EwU5UKBM66XOkdkmdarqQ-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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C4AB819560B8; Fri, 21 Jun 2024 18:12:34 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.33.154]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4F6AE1956056; Fri, 21 Jun 2024 18:12:31 +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 Subject: [PATCH v2 2/3] Update uffd-stress to handle EINVAL for unset config features Date: Fri, 21 Jun 2024 14:12:23 -0400 Message-ID: <20240621181224.3881179-2-audra@redhat.com> In-Reply-To: <20240621181224.3881179-1-audra@redhat.com> References: <20240621181224.3881179-1-audra@redhat.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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 Acked-by: Peter Xu --- 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 Fri Jun 21 18:12:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Audra Mitchell X-Patchwork-Id: 13707978 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3ABC117B40F for ; Fri, 21 Jun 2024 18:12:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718993569; cv=none; b=YecExotTFllz3heXtIlEZ+zdrIgSBGqnDGtyE2PRuhlUZJA/+SEnolCeUybTTT8kTJdzSZAYqplA2mItlfwunayLa+Jnjxbv3sVCIwQsgHHMIaspaCpmtNc5vR7Tig4Cj9gXTSqxFXwqmcMeCHuFXi3/FezH5A939JonSkxet/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718993569; c=relaxed/simple; bh=Y599k+zSybdg2JOvHy7OaMyrh1jyQwSGQbme1c7buBQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dxU1nVPH616AZJHgc+Ru7EL1Ocq9ie23ikANZUQqX1Dsrp/9SVtQ3H1qvX285I/qlo/3nRdL05Xgo59tma1WuAcUQXsAYDOvQIPQW3Iw/hsz0gkP4L9usAf/UWbckU0miGHdKkIp2MgWumcXABAfZ00KwrHy8WuKpi0rU89HNsg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XuMZzDKj; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XuMZzDKj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718993567; 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=Cr6dk5Gx+6xUDFsSwN421Zwok7Qnwc3SYB5JfAAmbas=; b=XuMZzDKjbo59/DB89FFGIKw8lrp5rD8D4/ujqz1WqmKa9Uxwtjw4uXok+JoLcmcGhTjpbR K9vPTsZtYCQVB1YC9gvbG5oF5l2HhlXpcO/+RcbFc32hVQktvH1jDqbIQulSzX9PeA/1x3 0E11PvSizs2JEmH2FqNRN58RCGu+Q8Y= 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-369-WM9VARPvNTWwGJjXM4GQRQ-1; Fri, 21 Jun 2024 14:12:41 -0400 X-MC-Unique: WM9VARPvNTWwGJjXM4GQRQ-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 C2E2219560A7; Fri, 21 Jun 2024 18:12:39 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.33.154]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4F5FF1956056; Fri, 21 Jun 2024 18:12:36 +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 Subject: [PATCH v2 3/3] Turn off test_uffdio_wp if CONFIG_PTE_MARKER_UFFD_WP is not configured. Date: Fri, 21 Jun 2024 14:12:24 -0400 Message-ID: <20240621181224.3881179-3-audra@redhat.com> In-Reply-To: <20240621181224.3881179-1-audra@redhat.com> References: <20240621181224.3881179-1-audra@redhat.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 If CONFIG_PTE_MARKER_UFFD_WP is disabled, then testing with test_uffdio_up enables calling uffdio_regsiter with the flag UFFDIO_REGISTER_MODE_WP. The kernel ensures in vma_can_userfault() that if CONFIG_PTE_MARKER_UFFD_WP is disabled, only allow the VM_UFFD_WP on anonymous vmas. Signed-off-by: Audra Mitchell --- 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..2601c9dfadd6 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_UNPOPULATED)) + test_uffdio_wp = false; + close(uffd); uffd = -1; }