Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1770204rdb; Mon, 9 Oct 2023 02:14:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJMYrkifR95Yg21wcf1PEC2AotsYu9rB0clFJLflRQnH7ZLQoIO+ZCpivYtFWse0Hx9zkN X-Received: by 2002:a17:902:6b04:b0:1b7:e86f:7631 with SMTP id o4-20020a1709026b0400b001b7e86f7631mr11790770plk.19.1696842859434; Mon, 09 Oct 2023 02:14:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696842859; cv=none; d=google.com; s=arc-20160816; b=yY9tAod/7w3pWZ9z9EJn5p3eqTPO9UitRrTfKn31qHJY97KedThATwQisY25LtUln6 bJ6hZ0bx/RYx2Ojd3QZZ7CsFGtB1vc4dVw/5EO4avcrckE/8SnDbydVLzEaYaigIzmt7 PdTJul4H/th86mtnYe3yUE959FbNq7hZy6WV2NNON6cjJQeTC3qk14JvD8jJU/y45ab5 /7P414m1yodI6B5T7kVgNCPn7JaZwNxnzCczV5LzFkVldSq3YdHFD2ZD0f0zQ1Pa89rk LDjGXfDXromySIR2ix7m+7nbLzI0dwEKm16Klxac3dTs4wYuW/qyjcVfpBVT2MnIdpOx UqGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/bNBfzadQWIHGQ2DOV+RDjrnYF1gyxXlPVcMan1/Zz8=; fh=BWbWfT91ZoObkyv/CUh2YcKncoGd0AN7/sDhs+nlN4I=; b=QlrHNtZxgnTn/hrc5vyu+FJtFp5xVqStf4KerqOGidSGatkfQO/n2k8Ayuh1NBU4pt qsJQR0N+8YLFdxJzGVagj9XiAka0sOvHMWI5dNK9iMp1rjLszwwTU/k/L1lqcS1jtGjj TBy1ZLPruTkTToahyQRYFJ4xyHkHeI7vwPQIPx1/sPqzFp0NGUHkvPPuIbDQCN9dLBd7 8t1MsSiXbVNleMwViaAQNQBVykzQykH2RvW74ohHmORaqME7T5uFr6jQk9eesLljwVq/ nUlfYDOCtCRFijoLKu3X2UD2/IXMuBDpN3yRYQIqv37eoTUcOYL1UO8cpKCx/gWZDkWC CTGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="XoVD/LVv"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id kh8-20020a170903064800b001c42d60b9e6si8866979plb.112.2023.10.09.02.14.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 02:14:19 -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=@kernel.org header.s=k20201202 header.b="XoVD/LVv"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id CF0FF804C216; Mon, 9 Oct 2023 02:14:16 -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 S1345698AbjJIJOB (ORCPT + 99 others); Mon, 9 Oct 2023 05:14:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345651AbjJIJNx (ORCPT ); Mon, 9 Oct 2023 05:13:53 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7B25B6; Mon, 9 Oct 2023 02:13:50 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D231C433C7; Mon, 9 Oct 2023 09:13:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696842830; bh=jhipQjsWiEs+Ekubf342gQBtzevOfGi2BJ5QvrVCXa8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XoVD/LVv8aVw/fiyc7REZB4iBGjkQiMDiIXjJ1NUvGS912djNzCzSccBrjVnA+B8p QuINxv9JhjARUPo061A4lil0hWTiXPcrh+ZqqouR3fDxSnMnSajcFWBvPm9d1WPLe4 PuSmHoiF9ObcPxlL4eujAkAUsCkEMj7YZzWL8VuvPqtwuWm0mVpu3Xt8eQji7zPR81 sgg9LhNcKSushKV2A2D1/k+twz+uWzbWBdJdkiYqcVT8K38J6uUy0T0SrCfYddWkBu YiS+jP7rYMqxhA3i9wjwmIAtIgC+zMWjw1BsCeQescVFaEsFNdRaPIrYH0nZnzX28w IVrbomr9ZLrRA== Date: Mon, 9 Oct 2023 12:12:56 +0300 From: Mike Rapoport To: Alejandro Colomar Cc: Axel Rasmussen , Peter Xu , linux-man@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 3/5] ioctl_userfaultfd.2: clarify the state of the uffdio_api structure on error Message-ID: <20231009091256.GN3303@kernel.org> References: <20231003194547.2237424-1-axelrasmussen@google.com> <20231003194547.2237424-4-axelrasmussen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no 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]); Mon, 09 Oct 2023 02:14:17 -0700 (PDT) X-Spam-Level: ** On Sun, Oct 08, 2023 at 11:52:56PM +0200, Alejandro Colomar wrote: > Hi Axel, > > On Tue, Oct 03, 2023 at 12:45:45PM -0700, Axel Rasmussen wrote: > > 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. > > -.\" > > I've added Mike to the thread in case he wants to comment. Thanks, Alex! It looks like I reviewed v1 of the patchset though :) > Thanks, > Alex > > > .SS UFFDIO_REGISTER > > (Since Linux 4.3.) > > Register a memory address range with the userfaultfd object. > > -- > > 2.42.0.609.gbb76f46606-goog > > > > -- > -- Sincerely yours, Mike.