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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3862CE95A91 for ; Mon, 9 Oct 2023 09:14:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345623AbjJIJOA (ORCPT ); Mon, 9 Oct 2023 05:14:00 -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: Precedence: bulk List-ID: X-Mailing-List: linux-man@vger.kernel.org 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.