Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2180438rdb; Tue, 3 Oct 2023 12:46:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERoVUTHeUqjrK7CsSRb4ZrE5gIrZrTXfW7xtrX/9DQ6olBFE5f2XpeZhS4k7wpTVsoevCT X-Received: by 2002:a05:6a20:440a:b0:153:40c3:aa71 with SMTP id ce10-20020a056a20440a00b0015340c3aa71mr543205pzb.43.1696362401592; Tue, 03 Oct 2023 12:46:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696362401; cv=none; d=google.com; s=arc-20160816; b=sJmzQ2aS+1evBhBGey/Sb4Ulex4Jd0vI3dquqT29p8Hh4xTEsmx/sO2RJEAdpQoeuD /VnYQb/CemZVsnkg+h54TXmGdx148TLj9dN5wr7VyFAFj5o1MPenl9kc08RK+yAkvADL Ra0yjoUjJd7iDIUpmMWlR2R8mjMuhWIHveTkoHFEruYD0ignvVqpsB5gdtFwASRKmDzP oIMbkHfA6CAKLyMeR25/VgclBgYlB71j9YWA0d2bg0y5hjOfNdDAggm9EK9iFFmz5g0a i+WafLgJCAmBeSZpfIzcwNEPCDWrNlRdKXrMiid3CXdXHG2WMRD5CX7YZ6eB0lM5j1c7 mQhA== 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 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id l18-20020a170902e2d200b001c72d694ec7si1886659plc.328.2023.10.03.12.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:46:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; 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 23.128.96.35 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 D80398120479; Tue, 3 Oct 2023 12:46:34 -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 S240967AbjJCTqJ (ORCPT + 99 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 Content-Type: text/plain; charset="UTF-8" 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) 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. -- 2.42.0.609.gbb76f46606-goog