Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3457939rdg; Tue, 17 Oct 2023 16:02:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJqLOHVFupPrhKDd1lWI98AhFjsEbRpL6wfikdFXGmvpwoC3S6t5c1kJapi4BVho8uiDrC X-Received: by 2002:a05:6359:5e02:b0:134:d806:69df with SMTP id pw2-20020a0563595e0200b00134d80669dfmr3138451rwb.18.1697583721083; Tue, 17 Oct 2023 16:02:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697583721; cv=none; d=google.com; s=arc-20160816; b=hNy0ECDQILQylxsvNp+leJ+pKtfMLbyzdFHczWERI+DPu8ahpMaIqlCGpumzEnFbqK usD6VJcoZRLPSUent7PVaqGUgb9fuSRKaWX+Kq2bxEPGOxqUz1ji6RhijPf0B4gMpSE+ lPduUut+dlp507J2uauN6X58Q3nUaOWeY6gep+AQdO7YufZPYuuB5QuKuH/lBfeMrr+0 4JSpRts7KiKzkwn0az54SyaE+mXaCYjoMD6lxcCldp0qpum2m5r0GN8+KNF92iYzMzF4 mOsuK1gFu6RCCmFnHdm1hXDd/dt0cW2uMMOJTz43lMDHPopmewr1IUws2I0e6zhlnRmK GCxA== 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=JOKJf+aFkcLqb+vIwiVLl6niteK0lFsixSF6GjMiBCE=; fh=/dNG7O5S6JIX0CZzJKQSLFTf7rgQ1Azl+D/Qxa/4VAY=; b=cJ0fw18Hr0aHrGSabDOZva8vW6t6y84t4CU51FJpHQxROctBFdf5C6czq6ZthG3/aQ 6QiPT/Vav1NS7MLnAdm2KoIFkXFT3ZwDgvI8JhULLKXET0zax2eSn9WyMG4S0hlmNbCN x1CAc9pDe7jOqECMU2WopMsO5KQr0cI/MREn86/kXUB49MXLE7d5Nt93uXNvsUgP0LFi iVQdHHzqfAgCYW6wF6kNZxqom119EXR1KdPMiwkjD29y0J45wkm6xvArsiCW0NEXamp9 UaHXM6cdzG7tBrBaNcm3qLJqkuJ6805PCpMcNZDmsydyFFxxcf0mDIl/YtZL2OqHQfie 7omQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XbDnJKqY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id t23-20020a656097000000b005ae39764b64si758429pgu.135.2023.10.17.16.02.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 16:02:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XbDnJKqY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 6BB558088562; Tue, 17 Oct 2023 16:01:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344122AbjJQXBX (ORCPT + 99 others); Tue, 17 Oct 2023 19:01:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230056AbjJQXBU (ORCPT ); Tue, 17 Oct 2023 19:01:20 -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 E1D3EA4 for ; Tue, 17 Oct 2023 16:01:18 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7aa161b2fso95697437b3.2 for ; Tue, 17 Oct 2023 16:01:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697583678; x=1698188478; 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=JOKJf+aFkcLqb+vIwiVLl6niteK0lFsixSF6GjMiBCE=; b=XbDnJKqYZ7SVFDowWbx/bTwJP8RuE/wzj3iAFiVeoBVOsh0JnRFzaSQfNOZ8jXtDlW 7r5Lrz/e/5SOIsQltFMS8Cf1LnxGI/yKUnO5WVSmmKKbogzTzDW3M4mfNustcE9WieUz Zs1+ApNFlYtQIQaF/nRIcuFHI6EE8zhhcBqYfskyuDllm/A4ShrcW72xxfBxj6KloEON Kw7L08SWmzOXt66Mq2uE8eWP0+hB958idEciAfX9AnnJIAQFAqrwKjbSv1wivrQn+fnf FDKD0HKty0u82itufiL19h6I/6sOdu75whJS17ENM8HpUUXlZoFfR6zzN7FYCiY0m2Fn MsFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697583678; x=1698188478; 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=JOKJf+aFkcLqb+vIwiVLl6niteK0lFsixSF6GjMiBCE=; b=rgmPe/enQvZOZQSV6Ghkbqr2dbsLLuPtsJz+UaQKgA1SIcolx299NOdxE1svGFDipR 8hXdyxI7G9g5AXTJxIhTYNemP3rMprIzok5DYHpsnzsoGMxyt8UjpMhsr7sjckFzuth7 YKPAzlvF0cic6DNVWExHXkkD9pqK4KmgB2wsuHzi23jv0XtfnQBQFPiXnvy0MPXY8ETN HDAodkhbKzxFmyyOMj0RUowJXlgAi+yQWzao8wg71BgJka5tzWkGLuQ3cc5lWUgii5w5 UcA9z8LBQiRvNJLB9q3hWKyQIYxKTMM7pVBDnv6uKOTwdCWbty7ZjNISI+UGy4/CXF5d X9jQ== X-Gm-Message-State: AOJu0YyvOWqc4MCUfZ3vkAeenjfJ3f45If1K8Ph759E2iaLB5KfGx+ms B93k0RU2+55Zfunmj+HpiIbQUqS4pZ3sLAzazQ3A X-Received: from axel.svl.corp.google.com ([2620:15c:2a3:200:cd04:35d6:a586:5c86]) (user=axelrasmussen job=sendgmr) by 2002:a0d:d848:0:b0:59b:ec33:ec6d with SMTP id a69-20020a0dd848000000b0059bec33ec6dmr90025ywe.5.1697583678192; Tue, 17 Oct 2023 16:01:18 -0700 (PDT) Date: Tue, 17 Oct 2023 16:01:08 -0700 In-Reply-To: <20231017230110.3170850-1-axelrasmussen@google.com> Mime-Version: 1.0 References: <20231017230110.3170850-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231017230110.3170850-2-axelrasmussen@google.com> Subject: [PATCH v3 1/3] ioctl_userfaultfd.2: clarify the state of the uffdio_api structure on error From: Axel Rasmussen To: Alejandro Colomar , Mike Rapoport , 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 pete.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 (pete.vger.email [0.0.0.0]); Tue, 17 Oct 2023 16:01:43 -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. Reviewed-by: Mike Rapoport (IBM) 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 e68085262..82aee667c 100644 --- a/man2/ioctl_userfaultfd.2 +++ b/man2/ioctl_userfaultfd.2 @@ -272,6 +272,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 @@ -305,14 +313,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.655.g421f12c284-goog