From patchwork Tue Oct 3 19:45:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 148046 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp2312980vqb; Tue, 3 Oct 2023 12:46:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWjcBLFs9blrArsaGS1qWyhFUqrnpZWqpwC2k7GIKpfwAd5KdyzvQwk5RdncRmXV4WTqMw X-Received: by 2002:a05:6358:6f08:b0:132:f294:77fe with SMTP id r8-20020a0563586f0800b00132f29477femr435373rwn.2.1696362374928; Tue, 03 Oct 2023 12:46:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696362374; cv=none; d=google.com; s=arc-20160816; b=O047eMXIlEr4CEAr4asnOj6T70yfaKMhNwBgZwwjIhhDwu+Ij2bsqWk12zT5z/syGs 9DGBfPOoZGi+oL5jgjYF3IeQESOzsYa2OHrKclU6n2rUlWHaCh2iCwmm9Nge2Zqw6IWU liT25y9Jwg078fyDj0Dky5A9F5mMws61Qy8aKZhu7584tsg7usitIllaq+2cGcIcRFMZ Z2o0Y4DK+LvyDoFTZO7jFbDP81+mU7LfIKmLRCNJtzred0I95KM5sN+xuQSl4fbUK6NU qQQg6wubE2qFlL9UUP5ecBznUF7J9zy7Ok0U4zsJ63zVcGh8AOz/SfgvssRlX4HCE75h X05w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=LZEL2BMjxz1i5idDbV1660WVS0O86XmSCyt1X5bcmDM=; fh=SqwPTGdhTS3wVH9FltNQ4n/lDM1p3ApEDnroT8zra0U=; b=sy04jfQ16OnyXdwYxt5mpM3aF+WNhe/+t7hD3axX/P3zkkwyUgLUV5nS6bB4FkOadI /Px8vCGLgg6oQEZqRHUoCXFIw/fqyG1Ybd1GSWuieZc5ZD4+CWMY3XFN5y6ZExpv2Mhh o9LP4NN3gGWsq66alHjIV/zu60mOB5aQZjG0WU/0Sy5T5hld02D8IwQZZDfvDe4IX4Qj a9HhhHbac541MGnLQlIPrsH/SC59khlSyk9NBeZEIKyYXVKifL+v/i1QHbNy2oSLtMem 1jL3z5lBJFPOXZU1upYxVUNa6OyG1fYxyLdhvH0uBJMTU3Ut+ybXhRf8Iz+oZYnhcIxA HGdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Mq+RXsAd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id k10-20020aa788ca000000b0068e47f319d9si2262356pff.280.2023.10.03.12.46.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:46:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Mq+RXsAd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id B458C818CCB9; Tue, 3 Oct 2023 12:46:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240966AbjJCTqB (ORCPT + 17 others); Tue, 3 Oct 2023 15:46:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230502AbjJCTqA (ORCPT ); Tue, 3 Oct 2023 15:46:00 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE990A1 for ; Tue, 3 Oct 2023 12:45:56 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d81ff714678so1611925276.2 for ; Tue, 03 Oct 2023 12:45:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696362356; x=1696967156; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=LZEL2BMjxz1i5idDbV1660WVS0O86XmSCyt1X5bcmDM=; b=Mq+RXsAdEu8Agt8QFclfS9ZJWQeyPjWgzORyR7dQ5ZrZPp2vHmiXbJ8Hq0EpBo7Bjm DYaSmQPC1pDTdIxAGyi+usEAYI7R/RqxhbshCoE/FO/i6WfTuEF/WukwvjRfHVN85UrN v4fae/nl9HnRZZnb5Mi3EijH5EH3/ntBGOSXkDECrLT7KvigehvgWLyP5bvP78N889rC OGsVX1N6VIlUQF5Y7NU1C5vUlAhG4YW77ueRx0S2I1zYYj5Qcv5vKOsDRiglJTFK7Z8p sfnQH9Tj3M8uHD3OHsapFSGsUwwvZeyCSw1l+DN30ac1rAIHut9N5EwZb3pL9nZWitjx A2gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696362356; x=1696967156; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LZEL2BMjxz1i5idDbV1660WVS0O86XmSCyt1X5bcmDM=; b=YtdPZ5mg32s/covbxD7CDZewpebcO6SfcJZDiNswGVTR6I1So7/yCMbDWGhpeROF4A +s+kBGjjt95SGJxOoavZpp5HrX09SsUcWtHeU4b8rlIYLy99lTrU70VE/KRcEnxtDOjB qom/1779XDaEjRNOiCCt+HOMIY09lcfKOOoECx3fLRneSd4k6zxtCqhxwiz9DjvERfzE UVFLEI7+dK74E/0ZfEf7aKW/WenFw117vIRKzfO2ct/O6g6iyCZFTs4XYdS6uqs8ezNK 4Hpp0Qx11AHy8fhsClC2niDF5GowVOx9bY2ZN8Oqnor13aYYnVgAUJ6dqu8KPrIRfib5 mP4Q== X-Gm-Message-State: AOJu0YwLQsBwSx820dSwZ5HANJpLkx9J+JYhOOyy+fv1NTUftODLfUhJ XLbmXBy3UREngV9Ur+cSJjGKJsElrIioLsP/rSAL X-Received: from axel.svl.corp.google.com ([2620:15c:2a3:200:6577:b8c1:dd2d:1c93]) (user=axelrasmussen job=sendgmr) by 2002:a25:d816:0:b0:d7b:9fad:6b9e with SMTP id p22-20020a25d816000000b00d7b9fad6b9emr3353ybg.1.1696362356219; Tue, 03 Oct 2023 12:45:56 -0700 (PDT) Date: Tue, 3 Oct 2023 12:45:43 -0700 In-Reply-To: <20231003194547.2237424-1-axelrasmussen@google.com> Mime-Version: 1.0 References: <20231003194547.2237424-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog Message-ID: <20231003194547.2237424-2-axelrasmussen@google.com> Subject: [PATCH v2 1/5] ioctl_userfaultfd.2: describe two-step feature handshake From: Axel Rasmussen To: Alejandro Colomar , Peter Xu Cc: linux-man@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Axel Rasmussen X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 03 Oct 2023 12:46:09 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778764873678422766 X-GMAIL-MSGID: 1778764873678422766 Fully describe how UFFDIO_API can be used to perform a two-step feature handshake, and also note the case where this isn't necessary (programs which don't depend on any extra features). This lets us clean up an old FIXME asking for this to be described. Signed-off-by: Axel Rasmussen --- man2/ioctl_userfaultfd.2 | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/man2/ioctl_userfaultfd.2 b/man2/ioctl_userfaultfd.2 index b5281ec4c..ef352a69d 100644 --- a/man2/ioctl_userfaultfd.2 +++ b/man2/ioctl_userfaultfd.2 @@ -82,7 +82,6 @@ struct uffdio_api { The .I api field denotes the API version requested by the application. -.PP The kernel verifies that it can support the requested API version, and sets the .I features @@ -92,6 +91,25 @@ fields to bit masks representing all the available features and the generic .BR ioctl (2) operations available. .PP +Since Linux 4.11, +applications should use the +.I features +field to perform a two-step handshake. +First, +.BR UFFDIO_API +is called with the +.I features +field set to zero. +The kernel responsds by setting all supported feature bits. +.PP +Applications which do not require any specific features +can begin using the userfaultfd immediately. +Applications which do need specific features +should call +.BR UFFDIO_API +again with a subset of the reported feature bits set +to enable those features. +.PP Before Linux 4.11, the .I features field must be initialized to zero before the call to @@ -101,24 +119,11 @@ and zero (i.e., no feature bits) is placed in the field by the kernel upon return from .BR ioctl (2). .PP -Starting from Linux 4.11, the -.I features -field can be used to ask whether particular features are supported -and explicitly enable userfaultfd features that are disabled by default. -The kernel always reports all the available features in the -.I features -field. -.PP -To enable userfaultfd features the application should set -a bit corresponding to each feature it wants to enable in the -.I features -field. -If the kernel supports all the requested features it will enable them. -Otherwise it will zero out the returned +If the application sets unsupported feature bits, +the kernel will zero out the returned .I uffdio_api structure and return .BR EINVAL . -.\" FIXME add more details about feature negotiation and enablement .PP The following feature bits may be set: .TP From patchwork Tue Oct 3 19:45:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 148047 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp2313143vqb; Tue, 3 Oct 2023 12:46:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEai4UuZrYVxXKWkdb/dvFthTZb/pRqQEUNtqcpAcme8hzQlYUQEjzfUPUDzFIw069ghdsF X-Received: by 2002:a92:50f:0:b0:351:5aed:c13c with SMTP id q15-20020a92050f000000b003515aedc13cmr421879ile.14.1696362398819; Tue, 03 Oct 2023 12:46:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696362398; cv=none; d=google.com; s=arc-20160816; b=LXRMLIS2BIG/ybwJwC1p07/Hhp1IEzAA7OqBFpNaoldEqzJVHOyAQsI+vmNGMy49jX xDw02S6zsjvettRMiaE2ZCgXg9OOgCZcVgGI9Az59mQ0Ya+FK2jFXDaZPsqyyHJHq3Cd aJ+HLURkTAuORFgitZ+eljZ7FgC1Wtbpu7erInrqdD+RRTzrDT+YDa1lyRL5SepL1rKP DpMGy01vlWvfIVBXkm2+t0A9pXGeTTDZ739sjqye/W4YAWXQFc3iqmwT38Y95kcNxf+q KxTDzpSdJfUYDbFcgZ1pbl0M2p8bCCdmSdLcwmtdw1WMRi3eSbp/stvZDf1+4sbthK7H xciA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=saHgOnMA67n4gZwlJ4PpFPUXnm1EsnwqlouJFj0QSrA=; fh=SqwPTGdhTS3wVH9FltNQ4n/lDM1p3ApEDnroT8zra0U=; b=IOUTvlm2JpB9j4C+NP9oPTBiLHj4UFA9iSIKRWNmI2RW8cDaBfKdh6+8ui8WkgifN/ ZfUyfJyi3k6z+wI6mgAANz8xXibAqM+MXRdcqmjhy04HHj9b8O5Xxkt/NMakAIHIjpfH Z4C0ul7w+9Mz401Gw5pBGU/Fp4FccdskOTyOIXvahup5uxFoSJ9aglzsrjNUf6ySxmR7 qRKCqdv+Zzzz39zWUIYy0KL86AOC1amuZpwaP4+V96efpO0TKysllsMuUfKRYQygfE/I ommUlMDDTNrZ4nJYiO8QnfrW+wvkE/NM4A7/apkqIDnydVPWIrZ8XVqsu3F1iawoeSJU 1lHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=2Mxpn5k5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id g2-20020a636b02000000b005777b0c8f59si2053902pgc.478.2023.10.03.12.46.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:46:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=2Mxpn5k5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id A75CD80FC0BC; Tue, 3 Oct 2023 12:46:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240993AbjJCTqH (ORCPT + 17 others); Tue, 3 Oct 2023 15:46:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240967AbjJCTqC (ORCPT ); Tue, 3 Oct 2023 15:46:02 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DA059E for ; Tue, 3 Oct 2023 12:45:59 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d81646fcf3eso1613905276.0 for ; Tue, 03 Oct 2023 12:45:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696362358; x=1696967158; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=saHgOnMA67n4gZwlJ4PpFPUXnm1EsnwqlouJFj0QSrA=; b=2Mxpn5k5pKx/6mMwNwor3T/y8bR0e5D7o9nKAVYj3jc/eY2Zwrf/2WlnlAdV3+m24Y KfQG1it401Xtr1wqDi3Z/7y1w+lgksxQ7+IbLpKZ/XiXbkx3iFQb2+7iS9LyN1He4G0o gWYIpdiqnMkmV/V9GLTHjIUgQzBTlIyEd0qJjaegRBNFHnqSsI7II3E55RhcLjBtjvOd 4Dakj7TpO3cXJW0BGNt7vGiFbo4s6C9Ua7p6JWbn1TMTmH2QolMXMW2M47YOLiZa00S5 +iZXFtouXU29NOLS1y1LXAmftdNKDsWKUm6wWSBwMrwnFpaGsLDyx1iz7AWVefvxWacl 5jmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696362358; x=1696967158; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=saHgOnMA67n4gZwlJ4PpFPUXnm1EsnwqlouJFj0QSrA=; b=fQjgkt108bqgnp0Dnun4zEIrRtkvblb7chOiToHUkSt8caddnaqkLHAPRDp3obBg/T fOR9W0ApQmbbLI67m2qLhQeUGHV7eLYgFz0cYFvGs5kd9XAC73qjMegVy+XXOdwNd8pQ FR2MZgbeuWDzvB7aB6vB8xPDX6bupdr6GyoSOUxP+rGZIkP/h8qcl7oTWxUoth00BejZ 2hiJi2/Vgejn3lr4ZSP5Z8gUKAv6alHr5VFBokOBgKzYYViwJGpteoE8eBKd6/gqDWDL wjbb1TqqsuJqVmZnHwYjZPOdcc9kAazW1wZ1Z0PExc4SB6ywefn7+fw2/bKICSAtA+6O r5mw== X-Gm-Message-State: AOJu0Yy2cmjgqSxZ4ALalPTiemrmBZhYe2tOtwzvCEV13omHulzC0vLG z9Dy7T7iAqGkvV822Q62IfFViQHYu7zufZ8EYWns X-Received: from axel.svl.corp.google.com ([2620:15c:2a3:200:6577:b8c1:dd2d:1c93]) (user=axelrasmussen job=sendgmr) by 2002:a25:770f:0:b0:d35:bf85:5aa0 with SMTP id s15-20020a25770f000000b00d35bf855aa0mr4058ybc.4.1696362358605; Tue, 03 Oct 2023 12:45:58 -0700 (PDT) Date: Tue, 3 Oct 2023 12:45:44 -0700 In-Reply-To: <20231003194547.2237424-1-axelrasmussen@google.com> Mime-Version: 1.0 References: <20231003194547.2237424-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog Message-ID: <20231003194547.2237424-3-axelrasmussen@google.com> Subject: [PATCH v2 2/5] ioctl_userfaultfd.2: correct and update UFFDIO_API ioctl error codes From: Axel Rasmussen To: Alejandro Colomar , Peter Xu Cc: linux-man@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Axel Rasmussen X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 03 Oct 2023 12:46:10 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778764898821937435 X-GMAIL-MSGID: 1778764898821937435 First, it is not correct that repeated UFFDIO_API calls result in EINVAL. This is true *if both calls enable features*, but in the case where we're doing a two-step feature detection handshake, the kernel explicitly expects 2 calls (one with no features set). So, correct this description. Then, some new error cases have been added to the kernel recently, and the man page wasn't updated to note these. So, add in descriptions of these new error cases. Signed-off-by: Axel Rasmussen --- man2/ioctl_userfaultfd.2 | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/man2/ioctl_userfaultfd.2 b/man2/ioctl_userfaultfd.2 index ef352a69d..28dd2fcdd 100644 --- a/man2/ioctl_userfaultfd.2 +++ b/man2/ioctl_userfaultfd.2 @@ -256,17 +256,31 @@ refers to an address that is outside the calling process's accessible address space. .TP .B EINVAL -The userfaultfd has already been enabled by a previous -.B UFFDIO_API -operation. -.TP -.B EINVAL The API version requested in the .I api field is not supported by this kernel, or the .I features field passed to the kernel includes feature bits that are not supported by the current kernel version. +.TP +.B EINVAL +A previous +.B UFFDIO_API +call already enabled one or more features for this userfaultfd. +Calling +.B UFFDIO_API +twice, +the first time with no features set, +is explicitly allowed +as per the two-step feature detection handshake. +.TP +.B EPERM +The +.B UFFD_FEATURE_EVENT_FORK +feature was enabled, +but the calling process doesn't have the +.B CAP_SYS_PTRACE +capability. .\" FIXME In the above error case, the returned 'uffdio_api' structure is .\" zeroed out. Why is this done? This should be explained in the manual page. .\" From patchwork Tue Oct 3 19:45:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 148050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp2313240vqb; Tue, 3 Oct 2023 12:46:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGsb/atUlJO7HEOLCofjAv0IslrpFKCIPO2a+41cYyxiTKZmLkHbR85TYoXM9/+fDnzG2QZ X-Received: by 2002:a17:902:c94e:b0:1c7:245a:7fea with SMTP id i14-20020a170902c94e00b001c7245a7feamr680245pla.58.1696362412158; Tue, 03 Oct 2023 12:46:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696362412; cv=none; d=google.com; s=arc-20160816; b=UsYB3XmmRnQWqeqWolp0g4Qrqt08NXQ929osNGNWIdSu7OQ+Ue6rG3xRkFSHz0BG00 FMG8Y77PzvDKb6Gsbd1BE9iZGBrNQP3g5iI9UfMeMZOoi9E1VnJ5mm5Ta2bcGw38pAym teqzKnUVVN+pfYxt6giXEjQ7LojQYseozXhpBlYopY6GVyu82cjUhsknD2w7Yw+NPg2G hjRM+e75IoFhQQgwYs8sE8sRZTv+xOuXfqEdI2hhkK1wus2GOMkU3iVEFr2KnYGAP6wF u7GM9oMDSmIw/CfHDdqAV2fU5bVZLpk1jJw2ds1LaJXgwHa3SFFcadmgzZ47KqjevWbb m7Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=nSwsPxGjU1Rb9Mh5qgmhu8siiN6wKhSBap+YrmkGvmo=; fh=SqwPTGdhTS3wVH9FltNQ4n/lDM1p3ApEDnroT8zra0U=; b=dMr0+9rzsAO5OfxRTP52jYxpLoeXzv9lqwXwAVyMr75ESg2ToAayEtsJaOyLRnZaYD VfKRN0g47VlRR+klA8i6DdDRcQuI72wlKXKHQP3JFSBdhMHwq+dV80zMF27d1jWBlskQ VUTtFX4+GYxkIvGivZ/e/pXcngoZIIlTpVDm/z+Vu94vJz60qnGNHSQp4QRmUxKCrhll L+q5qhwckF6tzu/GvClhBn40PNrMXxbBJeSQQsasO2EpGL5+5vaBTCioi/PXtdyPb9zj ypBVhAkqbYLEwspV91iGuF7MAcvr5stavh6oCo8kSeuoH/rUPr7WNXjLWBlnXIk6JMNU zsQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Pd9SK3SC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id s8-20020a170902ea0800b001c7615a8e09si2321666plg.593.2023.10.03.12.46.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:46:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Pd9SK3SC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id EFE118120474; Tue, 3 Oct 2023 12:46:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231868AbjJCTqJ (ORCPT + 17 others); Tue, 3 Oct 2023 15:46:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240985AbjJCTqE (ORCPT ); Tue, 3 Oct 2023 15:46:04 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 640249E for ; Tue, 3 Oct 2023 12:46:01 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-59f8040b2ffso19700877b3.3 for ; Tue, 03 Oct 2023 12:46:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696362360; x=1696967160; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nSwsPxGjU1Rb9Mh5qgmhu8siiN6wKhSBap+YrmkGvmo=; b=Pd9SK3SCC8XYtdvCkW9OWI3b/vojrwi3PAWRiKO3zZhpTS8aEFKNymTz+mUdWvW9Ua r3frU1La3/2MjnYK3/E7NCxEbv+gf6utCPmir5kKSFOb0AdvxWLviV1yBg0EdqeFZYyy V5LWYJ2FjpmdQghLZxeFlNIxIzan/BIJxg7kFcOTZKNiFlPvvS4YPi/ho65NEtLjV87i 84GZygbITCqJcyiwIYxOODwu7ijuFGOEVwC09T1sn38VSk3wriZkQRqDyBXTLCEjeph8 fQHNeY8b6nTwk9VvRXhg2++Z6xaJjAd470hbYnvgrr6EXpa7M5cBkhWPFYo3/s7cbfXW QtMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696362360; x=1696967160; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nSwsPxGjU1Rb9Mh5qgmhu8siiN6wKhSBap+YrmkGvmo=; b=ibbp/fNFOgOpnnSGflOZGzt10kJO5yCk88oXaDsPeaLym5ShFBSzUGqjDui2RJXYnT 3t1yBUj6yeqfmhL0NEtpMRZUg+VxwPYYhlV4I8QbTVvnAgNuCgzJR2ggh+Xb68/38W78 mB+5/mD1ZwrNoKlKIs1ZR/fM5SNlnzRrWBjaM4qdA7PCLt4FPPgGf7FdnmeOEqbWqv/q RMnxwUS++B78LruiN4xC0uwPOhbRTq/koe/zezsuMv3HIYrTD5W3sDPvtjpyfNKOUK45 6kxPYS90Fzk4mX1zC34x7XDnf8A8xI7w9B4QVzbfn6cqbEbO2M9/nGjtURpAxvNScuDZ V3bA== X-Gm-Message-State: AOJu0YywtWypXqlBhbVAE/IxevgKOisRTVxOrGQhwd0O+5vLy01QyoXO iwUr1niNZ6Nb+Ls+cfBUlIw8YtMVqNGZ+e0OEaLP X-Received: from axel.svl.corp.google.com ([2620:15c:2a3:200:6577:b8c1:dd2d:1c93]) (user=axelrasmussen job=sendgmr) by 2002:a81:ae53:0:b0:59b:f138:c843 with SMTP id g19-20020a81ae53000000b0059bf138c843mr9811ywk.3.1696362360670; Tue, 03 Oct 2023 12:46:00 -0700 (PDT) Date: Tue, 3 Oct 2023 12:45:45 -0700 In-Reply-To: <20231003194547.2237424-1-axelrasmussen@google.com> Mime-Version: 1.0 References: <20231003194547.2237424-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog Message-ID: <20231003194547.2237424-4-axelrasmussen@google.com> Subject: [PATCH v2 3/5] ioctl_userfaultfd.2: clarify the state of the uffdio_api structure on error From: Axel Rasmussen To: Alejandro Colomar , Peter Xu Cc: linux-man@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Axel Rasmussen X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 03 Oct 2023 12:46:50 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778764913052324249 X-GMAIL-MSGID: 1778764913052324249 The old FIXME noted that the zeroing was done to differentiate the two EINVAL cases. It's possible something like this was true historically, but in current Linux we zero it in *both* EINVAL cases, so this is at least no longer true. After reading the code, I can't determine any clear reason why we zero it in some cases but not in others. So, some simple advice we can give userspace is: if an error occurs, treat the contents of the structure as unspecified. Just re-initialize it before retrying UFFDIO_API again. Signed-off-by: Axel Rasmussen --- man2/ioctl_userfaultfd.2 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/man2/ioctl_userfaultfd.2 b/man2/ioctl_userfaultfd.2 index 28dd2fcdd..2ee6a0532 100644 --- a/man2/ioctl_userfaultfd.2 +++ b/man2/ioctl_userfaultfd.2 @@ -248,6 +248,14 @@ operation returns 0 on success. On error, \-1 is returned and .I errno is set to indicate the error. +If an error occurs, +the kernel may zero the provided +.I uffdio_api +structure. +The caller should treat its contents as unspecified, +and reinitialize it before re-attempting another +.B UFFDIO_API +call. Possible errors include: .TP .B EFAULT @@ -281,14 +289,6 @@ feature was enabled, but the calling process doesn't have the .B CAP_SYS_PTRACE capability. -.\" FIXME In the above error case, the returned 'uffdio_api' structure is -.\" zeroed out. Why is this done? This should be explained in the manual page. -.\" -.\" Mike Rapoport: -.\" In my understanding the uffdio_api -.\" structure is zeroed to allow the caller -.\" to distinguish the reasons for -EINVAL. -.\" .SS UFFDIO_REGISTER (Since Linux 4.3.) Register a memory address range with the userfaultfd object. From patchwork Tue Oct 3 19:45:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 148049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp2313156vqb; Tue, 3 Oct 2023 12:46:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IElvndjK0mQ6hzy4fRu8fHi3PlJ9TQ3kV5ExwzS4KIn1lTzJFdXRh6RC0gYUuqhfxP7k1WD X-Received: by 2002:a05:6a00:399f:b0:692:780a:de90 with SMTP id fi31-20020a056a00399f00b00692780ade90mr514303pfb.30.1696362400801; Tue, 03 Oct 2023 12:46:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696362400; cv=none; d=google.com; s=arc-20160816; b=W0hHowfhYlr+uh17UxmVanlbUL805c5bs18xaac6HRAVwrPyHdpiGIFvwD87wspprS CwJ8F2NPzpcFXTIKCOWCnnJvZDM6dpMQp5C/6ZjInKfbn9LKY9AvxlYhzuAML31YXJPN x2oeUvM8/Ls8zv/65DKkNP6Lbc1Gx91HE9ld8W5XS5pDPfg7tZRHwn+h5ZmLJGVhvVG+ zgq5wgfQ/iqQIOtBNVhWBrXbxc4g4UJ3PwrNS/rPAVXZUNeoY1E0k4VGiNuP1/iOA/Cx RLt0Z9F2W0yrxQ5nTcS2u37emzQz2gCyBtCFaJwXyMcjg3uB+eojhUwIcx4TXZ5LyNF5 pLbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=KHojRgQcvHJlG3tNkbT5JYy4vaQ9RVgTVjOSA6AH+sQ=; fh=SqwPTGdhTS3wVH9FltNQ4n/lDM1p3ApEDnroT8zra0U=; b=MhHHv9MANzePqmuOvfj0qPgQX5NTZPqU5M4rrbZr/Q5Hem51JRl8Iswv6sFwqnWIiy dNIsDxVJ+H/H2HoUR9sdGZLnhqghy8R1gt8ew/i6qpdwmyy4hiM7+4TYrFOoabNPZPvn d2DhU0KNESJn7Rw5UQfiejQvhDK/h2gIAO1E9ICdzdVYj/D8wNjdvSsDGjUPU1SEts56 eacB+VLrlJCBjpwyRHTTzIMYCNQC0XxyAiFtjN9uiBIsBT+IHRgkm23N03BCnH65/jsr Jpvv3u8m4yuuT4RkFX2u3QP9p/p6bYZ8/mTSK9yAaPtPy6qZp88Mn9Mz6jd20VdCq/yP jcSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XiqKhHZP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id br10-20020a056a00440a00b006910e8e46e0si2121183pfb.371.2023.10.03.12.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:46:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XiqKhHZP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 469E5812047A; Tue, 3 Oct 2023 12:46:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241019AbjJCTqM (ORCPT + 17 others); Tue, 3 Oct 2023 15:46:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241001AbjJCTqH (ORCPT ); Tue, 3 Oct 2023 15:46:07 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8968ABF for ; Tue, 3 Oct 2023 12:46:03 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d865f1447a2so1687926276.2 for ; Tue, 03 Oct 2023 12:46:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696362363; x=1696967163; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=KHojRgQcvHJlG3tNkbT5JYy4vaQ9RVgTVjOSA6AH+sQ=; b=XiqKhHZPLH4u07w/7Cv0397UGeq3riVtQ+6IopmmJTx1IBU7ENDtd36FIaIzzriX1l TRm4vEBzWPhJiMhlKZCS5fPNxbIwFPk36izfGFF8VsrnWr8CiTMLpiO1CkXo9T8C7JzS YopAEjxgCBeokfCuu3mE/nERXoSs67zRnWtwx5xqgSOhWXE07OW5BT6us0Hp7VFT8S4V qrQBpym+hI9XtEMnN4pgQmOINSxTQioD1xzrzsqODAuQa2vakzXLZPWIY7MHC5+Y8drV UYC52RHymY2pjv65CMfVikh8SYrTxNWNyAl08YDJdsLyL28b/bv9mQAjpRDRbyPz3dAe 13vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696362363; x=1696967163; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KHojRgQcvHJlG3tNkbT5JYy4vaQ9RVgTVjOSA6AH+sQ=; b=eoBpoMgSZVjbxnY7ZeH1HiBDjH6nXGE2qOtqyoBWraK+K7w3Z7/dJ4tiirsb7AunuF 6MItxV9u30XmL9CVEozEPRw9GC/MNJF8VWhtG73ckLU1z4N6yASy1tctQYTOXBA3Clth MRuC3Val3xfb2UpZIcUwxyYMIomDZGyj0Mk4+B3knFd3JsVae0Coss29JAvCS3/PFhq4 /GO+RR6APf6lVEqQbwwN0kD1sH76OiJqrdizHFtxz1PvXI0arVYJ27tfcfB0No/eldoH 3mcML7nQt/5qgHoepTd8T4hp/4dMnCEkZzNWNIQN40RvLW00e1AWXlC/C70M8G3MvTqz Pk/g== X-Gm-Message-State: AOJu0Yx938LzaAgWtMOnikOEtDoth0cWo1/sK3uimRsVHv2RGRSlDYVF 5EEK0PQB05Wg55tHBrYDVdJT5Doy8aiPe29HADXl X-Received: from axel.svl.corp.google.com ([2620:15c:2a3:200:6577:b8c1:dd2d:1c93]) (user=axelrasmussen job=sendgmr) by 2002:a05:6902:212:b0:d89:b072:d06f with SMTP id j18-20020a056902021200b00d89b072d06fmr3912ybs.7.1696362362806; Tue, 03 Oct 2023 12:46:02 -0700 (PDT) Date: Tue, 3 Oct 2023 12:45:46 -0700 In-Reply-To: <20231003194547.2237424-1-axelrasmussen@google.com> Mime-Version: 1.0 References: <20231003194547.2237424-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog Message-ID: <20231003194547.2237424-5-axelrasmussen@google.com> Subject: [PATCH v2 4/5] ioctl_userfaultfd.2: fix / update UFFDIO_REGISTER error code list From: Axel Rasmussen To: Alejandro Colomar , Peter Xu Cc: linux-man@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Axel Rasmussen X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 03 Oct 2023 12:46:35 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778764901097510469 X-GMAIL-MSGID: 1778764901097510469 The list of error codes in the man page was out of date with respect to the current state of the kernel. Some errors were partially / incorrectly described. Update the error code listing, so it matches the current state of the kernel, and correctly describes all the errors. Signed-off-by: Axel Rasmussen --- man2/ioctl_userfaultfd.2 | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/man2/ioctl_userfaultfd.2 b/man2/ioctl_userfaultfd.2 index 2ee6a0532..95d69f773 100644 --- a/man2/ioctl_userfaultfd.2 +++ b/man2/ioctl_userfaultfd.2 @@ -388,12 +388,6 @@ On error, \-1 is returned and .I errno is set to indicate the error. Possible errors include: -.\" FIXME Is the following error list correct? -.\" -.TP -.B EBUSY -A mapping in the specified range is registered with another -userfaultfd object. .TP .B EFAULT .I argp @@ -408,21 +402,32 @@ field; or the field was zero. .TP .B EINVAL -There is no mapping in the specified address range. -.TP -.B EINVAL +The specified address range was invalid. +More specifically, +no mapping exists in the given range, +or the mapping that exists there is invalid +(e.g. unsupported type of memory), +or the range values ( .I range.start or .I range.len -is not a multiple of the system page size; or, +) are not multiples of the relevant page size, +or .I range.len -is zero; or these fields are otherwise invalid. +is zero. .TP -.B EINVAL -There as an incompatible mapping in the specified address range. -.\" Mike Rapoport: -.\" ENOMEM if the process is exiting and the -.\" mm_struct has gone by the time userfault grabs it. +.B ENOMEM +The process is exiting, +and its address space has already been torn down +when userfaultfd attempts to reference it. +.TP +.B EPERM +The userfaultfd would allow writing to a file backing the mapping, +but the calling process lacks such write permissions. +.TP +.B EBUSY +A mapping in the specified range is registered with another +userfaultfd object. .SS UFFDIO_UNREGISTER (Since Linux 4.3.) Unregister a memory address range from userfaultfd. From patchwork Tue Oct 3 19:45:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 148048 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp2313145vqb; Tue, 3 Oct 2023 12:46:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGhx9R7lBhrvhPKlg34t3o7W64DRohqjU3x+97ZTbJVyByDTuivFV91S6AT2GGeBfdBCqIq X-Received: by 2002:a17:902:cec3:b0:1bd:a22a:d409 with SMTP id d3-20020a170902cec300b001bda22ad409mr593527plg.40.1696362399013; Tue, 03 Oct 2023 12:46:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696362399; cv=none; d=google.com; s=arc-20160816; b=Fx6Kw/Dsv05cDBt6KhJBr2RV4M12Ur5Wi4ihyujNWNl+34rw7oizwYzOUDstrw33DI tguoRFe1E0lxgelLAzT0bgvcMWZ87brdAGY1qMjAEuW26vQ205o/RE47gzsW3Kxhirkb 0leF0QXtZAz2rmrveO+8osVkH/SJJf6D08XbZgl/rg8KiE9kuCZfmmtIYQmeZlJ/hW9e yn6SthD7X0SlKEBY+wyVNGqG3zVzHHcDgHGIbJ8B2LdJADw59lATWdFiyHF76SiqvHPM aVfrShOwAUWfhwgluLoKzlxrNw8Udc6MpvsxBBuQ8iKzUNd7uSZapV/8v4RwGOROREp1 KHnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=ocOKNhdUvGY6/aq7ieB9QOD0OYSMZQy4WsHc5CUE0HE=; fh=SqwPTGdhTS3wVH9FltNQ4n/lDM1p3ApEDnroT8zra0U=; b=R3/2cdmtUcFQrvav53fSnGHC7EOzEKyoRUA0fR03rycXIJRsVJ7C+qSNmw4BRbcvQA 05GqngzkjQvzuGeM/Nwd8+vWlYxSIytG9dz2TgoT5Q6erZmHZj5nYq9p7NP8/F71WE+D WE615XTsBI1gEl0VMzF9mhpOINApFKToT1ukYSVWuK2E73yxGATyRqPyA3yHSb+ue/hX aD3tDKpnIsKlORRORD2Cgag3kPQAhIk+zRGUSPjsJWlf0DTNe7v22WcdMfpwNJEnkTRK vtuBZtL/GMinJkzyGnKFlAdCOhdptWZqbj+0CDEbUWmfI741UVuumUg1Sm1jsMoqV9sM Sq3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ehJl6aaL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id u10-20020a170902e80a00b001c56edc4b7asi2308600plg.278.2023.10.03.12.46.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:46:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ehJl6aaL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id C632880FC0B9; Tue, 3 Oct 2023 12:46:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241027AbjJCTqO (ORCPT + 17 others); Tue, 3 Oct 2023 15:46:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241010AbjJCTqJ (ORCPT ); Tue, 3 Oct 2023 15:46:09 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BC9CE8 for ; Tue, 3 Oct 2023 12:46:05 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-59b5a586da6so1465157b3.1 for ; Tue, 03 Oct 2023 12:46:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696362364; x=1696967164; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ocOKNhdUvGY6/aq7ieB9QOD0OYSMZQy4WsHc5CUE0HE=; b=ehJl6aaLJNGOhOrfjjGtgCtiYEfY2LHntsLdKU/FBYgJCiFvaNLYgNbJOOFqVDKxI5 0tlEFynHceZNL3fSBFgNHZ/kLvifj37uiXSwhIL1YooLzMKPkYDmRSFbfbPOqtYD8Mvs Ps87tCr2bZMUZO9Zivitv9PsxX4MH8W3ZctJd3WnSDp3CQH2uBgMmFZ9jZPGD4xAy01M CEJUgtwAs2Rehgmozo13+bOtV85KtDo2c6aN5lwTq+DI5TBPGYCmJpjro1XfOD/QuDCJ 11hqB3Ls9BYhUN9zXKZU0dMLFKJjf0senhpOQGX5id9jawbC/CKbhBUIvihVc6GXfU7d jH9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696362364; x=1696967164; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ocOKNhdUvGY6/aq7ieB9QOD0OYSMZQy4WsHc5CUE0HE=; b=k1Jtj+OwT4XDCxOWj+6k7p8mn7PrsquAw9YUg5+9aJNk1G6ApznTwSYHejHPrEEuOQ J5pqp2FGvLI94oREHvbVf+CTWvimLDwZqjGlNGTsoXkIYpkp7gIkcThBv+tKtpKgyZjL saEXAqJ6x88VyXLsWbIDiK1YxnL3Ju7sNcR6EguwOsBkJ8rixioksDl6ACZVz9jQD+rQ kTI2PwDRAWlB+M2Ht6e4Qfal2YJyKwB1NdZGEHxGdt1Ll7EqGdp+ANeNlleESs2k1QJF X81IFqaP6LqPLA12uL8RbF0CdsYO5rCRylPcBerAV9fhSSTrDTbLmDramULT5AE6ndcp iVDg== X-Gm-Message-State: AOJu0Yy2GHHI6MmxxqRoNe69T0Mhm+OpgpPNNYvJKH+YFHlNNbhNqmBg E8/HaOBCEHyXKx/vgW3KKXw0Hp9TFPWaho3k4u5x X-Received: from axel.svl.corp.google.com ([2620:15c:2a3:200:6577:b8c1:dd2d:1c93]) (user=axelrasmussen job=sendgmr) by 2002:a81:d106:0:b0:595:8166:7be with SMTP id w6-20020a81d106000000b00595816607bemr6831ywi.0.1696362364727; Tue, 03 Oct 2023 12:46:04 -0700 (PDT) Date: Tue, 3 Oct 2023 12:45:47 -0700 In-Reply-To: <20231003194547.2237424-1-axelrasmussen@google.com> Mime-Version: 1.0 References: <20231003194547.2237424-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog Message-ID: <20231003194547.2237424-6-axelrasmussen@google.com> Subject: [PATCH v2 5/5] ioctl_userfaultfd.2: document new UFFDIO_POISON ioctl From: Axel Rasmussen To: Alejandro Colomar , Peter Xu Cc: linux-man@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Axel Rasmussen X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 03 Oct 2023 12:46:17 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778764898772850673 X-GMAIL-MSGID: 1778764898772850673 This is a new feature recently added to the kernel. So, document the new ioctl the same way we do other UFFDIO_* ioctls. Also note the corresponding new ioctl flag we can return in reponse to a UFFDIO_REGISTER call. Signed-off-by: Axel Rasmussen --- man2/ioctl_userfaultfd.2 | 112 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/man2/ioctl_userfaultfd.2 b/man2/ioctl_userfaultfd.2 index 95d69f773..6b6980d4a 100644 --- a/man2/ioctl_userfaultfd.2 +++ b/man2/ioctl_userfaultfd.2 @@ -380,6 +380,11 @@ operation is supported. The .B UFFDIO_CONTINUE operation is supported. +.TP +.B 1 << _UFFDIO_POISON +The +.B UFFDIO_POISON +operation is supported. .PP This .BR ioctl (2) @@ -890,6 +895,113 @@ The faulting process has exited at the time of a .B UFFDIO_CONTINUE operation. .\" +.SS UFFDIO_POISON +(Since Linux 6.6.) +Mark an address range as "poisoned". +Future accesses to these addresses will raise a +.B SIGBUS +signal. +Unlike +.B MADV_HWPOISON +this works by installing page table entries, +rather than "really" poisoning the underlying physical pages. +This means it only affects this particular address space. +.PP +The +.I argp +argument is a pointer to a +.I uffdio_continue +structure as shown below: +.PP +.in +4n +.EX +struct uffdio_poison { + struct uffdio_range range; + /* Range to install poison PTE markers in */ + __u64 mode; /* Flags controlling the behavior of poison */ + __s64 updated; /* Number of bytes poisoned, or negated error */ +}; +.EE +.in +.PP +The following value may be bitwise ORed in +.I mode +to change the behavior of the +.B UFFDIO_POISON +operation: +.TP +.B UFFDIO_POISON_MODE_DONTWAKE +Do not wake up the thread that waits for page-fault resolution. +.PP +The +.I updated +field is used by the kernel +to return the number of bytes that were actually poisoned, +or an error in the same manner as +.BR UFFDIO_COPY . +If the value returned in the +.I updated +field doesn't match the value that was specified in +.IR range.len , +the operation fails with the error +.BR EAGAIN . +The +.I updated +field is output-only; +it is not read by the +.B UFFDIO_POISON +operation. +.PP +This +.BR ioctl (2) +operation returns 0 on success. +In this case, +the entire area was poisoned. +On error, \-1 is returned and +.I errno +is set to indicate the error. +Possible errors include: +.TP +.B EAGAIN +The number of bytes mapped +(i.e., the value returned in the +.I updated +field) +does not equal the value that was specified in the +.I range.len +field. +.TP +.B EINVAL +Either +.I range.start +or +.I range.len +was not a multiple of the system page size; or +.I range.len +was zero; or the range specified was invalid. +.TP +.B EINVAL +An invalid bit was specified in the +.I mode +field. +.TP +.B EEXIST +One or more pages were already mapped in the given range. +.TP +.B ENOENT +The faulting process has changed its virtual memory layout simultaneously with +an outstanding +.B UFFDIO_POISON +operation. +.TP +.B ENOMEM +Allocating memory for page table entries failed. +.TP +.B ESRCH +The faulting process has exited at the time of a +.B UFFDIO_POISON +operation. +.\" .SH RETURN VALUE See descriptions of the individual operations, above. .SH ERRORS