From patchwork Thu Mar 4 01:59:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12115329 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77F6CC433DB for ; Thu, 4 Mar 2021 02:00:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0CE23650DF for ; Thu, 4 Mar 2021 02:00:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0CE23650DF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 563F26B000A; Wed, 3 Mar 2021 21:00:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 53AB66B000C; Wed, 3 Mar 2021 21:00:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 390AD6B000D; Wed, 3 Mar 2021 21:00:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id 0D9676B000A for ; Wed, 3 Mar 2021 21:00:00 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B6F4D181D3039 for ; Thu, 4 Mar 2021 01:59:59 +0000 (UTC) X-FDA: 77880536118.22.74BDCE4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 9438BC0007C5 for ; Thu, 4 Mar 2021 01:59:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614823198; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DK7INWloX9H1AWnOZWZTogB23KAtqlPeswE1LI5JIvE=; b=WKCKlWs1aT8e4cMSptPC47DvLyChDJUCSd35Zgsw1nJ0C9vhXI0CWbUH5HilgN9fhSQVGP nE43w4c55s2Yp12P98c4mp9HyDmSS9Ehvu+w5y/JiTWyLIMGXUiXqda5uM8M81J1cgJd34 O+zVY006BrGsRfTwEm1yv/6M+OfhBd8= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-182-9UhqIMKBOKKFfXFeTOf03w-1; Wed, 03 Mar 2021 20:59:57 -0500 X-MC-Unique: 9UhqIMKBOKKFfXFeTOf03w-1 Received: by mail-qk1-f200.google.com with SMTP id h21so21783672qkl.12 for ; Wed, 03 Mar 2021 17:59:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DK7INWloX9H1AWnOZWZTogB23KAtqlPeswE1LI5JIvE=; b=r8l1dPm4kb3BabdJKgZqyps2o8JzhrdJLvlXV2igb0C4l7k8XfVDCuKaYU9IrLU4As cblzK5b5e7yqLtbj5Duz0Le9G0AIXR9Beo6f2MUdcTzMX8mTD89s2V1ifjYpXPYq2uhL qoim+4l/bCkYaZII9glMInbJg0PDyH2KbUUCxPVq/Hs85hF2FNyE7z6ir4MN9Z9nKvy1 wu0UaRqX7P2CP1ftN4F7EpkTw4uV1OXoLttOsLqD76pDTE/C9H4yCRJE6dBbJY03kqk4 A5uzLDiUDXp/eUWjcucFOzTnja56rmglSiAsLp8lGsDC/fXkzot/TCSgID3ERi+wwXcL 3ksA== X-Gm-Message-State: AOAM53268KGKsCZpbG8JshAcvCWARJABA6iNFv0knZ5WtnXLpaArKFiy /ScqDn/kVBKF8gfIZvK9oVtblcR7ET8yq6HHBhhQcciZ5SB3OPKXSlrNEbr+IR258+FGijrxXOM QsbWi4+yAttg= X-Received: by 2002:a0c:b617:: with SMTP id f23mr2163137qve.44.1614823196920; Wed, 03 Mar 2021 17:59:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwxeZ5a1mqjFCVuCtrVoLgbBF/ndMtcWPREu37qyYMGQmwQz48Q/q8ajeD2blfbJQfQ0Oti+w== X-Received: by 2002:a0c:b617:: with SMTP id f23mr2163126qve.44.1614823196691; Wed, 03 Mar 2021 17:59:56 -0800 (PST) Received: from xz-x1.redhat.com (bras-vprn-toroon474qw-lp130-25-174-95-95-253.dsl.bell.ca. [174.95.95.253]) by smtp.gmail.com with ESMTPSA id b7sm18610766qkj.115.2021.03.03.17.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Mar 2021 17:59:55 -0800 (PST) From: Peter Xu To: linux-man@vger.kernel.org Cc: Mike Rapoport , Nadav Amit , linux-kernel@vger.kernel.org, Linux MM Mailing List , peterx@redhat.com, Axel Rasmussen , Alejandro Colomar , Andrea Arcangeli , Andrew Morton , Michael Kerrisk Subject: [PATCH 4/4] ioctl_userfaultfd.2: Add write-protect mode docs Date: Wed, 3 Mar 2021 20:59:47 -0500 Message-Id: <20210304015947.517713-5-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210304015947.517713-1-peterx@redhat.com> References: <20210304015947.517713-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 9438BC0007C5 X-Stat-Signature: t1parjopnjcedum9hc8rp9szhpq5bfgt Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf06; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=63.128.21.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614823198-445945 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Userfaultfd write-protect mode is supported starting from Linux 5.7. Signed-off-by: Peter Xu --- man2/ioctl_userfaultfd.2 | 74 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-) diff --git a/man2/ioctl_userfaultfd.2 b/man2/ioctl_userfaultfd.2 index 1965d1932..3feb888a8 100644 --- a/man2/ioctl_userfaultfd.2 +++ b/man2/ioctl_userfaultfd.2 @@ -208,10 +208,11 @@ signal will be sent to the faulting process. Applications using this feature will not require the use of a userfaultfd monitor for processing memory accesses to the regions registered with userfaultfd. +.TP .BR UFFD_FEATURE_THREAD_ID " (since Linux 4.14)" If this feature bit is set, .I uffd_msg.pagefault.feat.ptid -Will be set +will be set to the faulted thread ID for each page fault message. .PP The returned .I ioctls @@ -233,6 +234,11 @@ operation is supported. The .B UFFDIO_UNREGISTER operation is supported. +.TP +.B 1 << _UFFDIO_WRITEPROTECT +The +.B UFFDIO_WRITEPROTECT +operation is supported. .PP This .BR ioctl (2) @@ -321,9 +327,6 @@ Track page faults on missing pages. .B UFFDIO_REGISTER_MODE_WP Track page faults on write-protected pages. .PP -Currently, the only supported mode is -.BR UFFDIO_REGISTER_MODE_MISSING . -.PP If the operation is successful, the kernel modifies the .I ioctls bit-mask field to indicate which @@ -653,6 +656,69 @@ field of the structure was not a multiple of the system page size; or .I len was zero; or the specified range was otherwise invalid. +.SS UFFDIO_WRITEPROTECT +(Since Linux 5.7) Do write-protect or write-unprotect for an userfaultfd +registered memory range with mode +.BR UFFDIO_REGISTER_MODE_WP . +.PP +The +.I argp +argument is a pointer to a +.I uffdio_range +structure as shown below: +.PP +.in +4n +.EX +struct uffdio_writeprotect { + struct uffdio_range range; /* Range to change write permission */ + __u64 mode; /* Mode to change write permission */ +}; +.EE +.in +There're two modes that are supported in this structure: +.TP +.B UFFDIO_WRITEPROTECT_MODE_WP +When this mode bit is set, the ioctl will be a write-protect operation upon the +memory range specified by +.IR range . +Otherwise it'll be a write-unprotect operation upon the specified range. +.TP +.B UFFDIO_WRITEPROTECT_MODE_DONTWAKE +Do not wake up the thread that waits for page-fault resolution after the +operation. This could only be specified if +.B UFFDIO_WRITEPROTECT_MODE_WP +is not specified (in a resolving stage, not protecting stage). +.PP +This +.BR ioctl (2) +operation returns 0 on success. +On error, \-1 is returned and +.I errno +is set to indicate the error. +Possible errors include: +.TP +.B EINVAL +The +.I start +or the +.I len +field of the +.I ufdio_range +structure was not a multiple of the system page size; or +.I len +was zero; or the specified range was otherwise invalid. +.TP +.B EAGAIN +The process was interrupted and need to retry. +.TP +.B ENOENT +The range specified in +.I range +is not valid. E.g., the virtual address does not exist, or not registered with +userfaultfd write-protect mode. +.TP +.B EFAULT +Encountered a generic fault during processing. .SH RETURN VALUE See descriptions of the individual operations, above. .SH ERRORS