From patchwork Thu Mar 4 16:31:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12116577 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 1C33FC433E0 for ; Thu, 4 Mar 2021 16:32:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B183664F43 for ; Thu, 4 Mar 2021 16:32:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B183664F43 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 53CB56B0023; Thu, 4 Mar 2021 11:32:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 513C96B0024; Thu, 4 Mar 2021 11:32:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B5B76B0025; Thu, 4 Mar 2021 11:32:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0004.hostedemail.com [216.40.44.4]) by kanga.kvack.org (Postfix) with ESMTP id 204956B0023 for ; Thu, 4 Mar 2021 11:32:00 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id CF5FB8249980 for ; Thu, 4 Mar 2021 16:31:59 +0000 (UTC) X-FDA: 77882733558.02.1C501FE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf13.hostedemail.com (Postfix) with ESMTP id C9523E005F17 for ; Thu, 4 Mar 2021 16:31:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614875513; 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=0tDcn9g219xehBx47za8NiyX09EPm0l6AhkPUkOSCPU=; b=Ylgu4VSfqCpr8/VuimqIltld2XYfO8JF0rfnXdSPh+ewTOfFyJ8PKYHAnnn/sGZjv7fJk7 2NXMotTpwIJoKGhL7DeNNKjCStp7VzWg9hInHMr5K+Qocdb6tKv4BWthIHoBb/euAD5MXA VG4zT5ulfNAq3bJlJcluIwqlTljJKVY= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-324-Yv_1h-G8P9OYBJK9Td6WWg-1; Thu, 04 Mar 2021 11:31:51 -0500 X-MC-Unique: Yv_1h-G8P9OYBJK9Td6WWg-1 Received: by mail-qv1-f72.google.com with SMTP id u8so20958089qvm.5 for ; Thu, 04 Mar 2021 08:31:51 -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=0tDcn9g219xehBx47za8NiyX09EPm0l6AhkPUkOSCPU=; b=Zdw7YmqgIu+meV2dSHJK5RLcFzJ9m1MzmiL8mWG8v3A7V7cNd4UkIQv74H1xvPoR9d J1vjp/j72BS7eo5g3ZdYUyBYkfzNDAemMcMZdD5EpjM0wMI3HNR8Oi2P9b+0uLccip01 9zNs0LspV9MhVRZA8mcJoXfCybG4CgVXvIqUY4UqeOmZBtfE16GraaF+6cp02HsMyNIw xAO86m9OM/L4VV3lrcUEBVyntNZJlhfHgS2YYzy1Cky4OO5s8hqehqdpuBPaYR7J6ln+ vnz2Vwfe/Oz53vnLL0HmZQUiqgqD1nHnBJj9yxX8bGBIkks1oA4JyXXG7TRoB2K6/M+a 6YGg== X-Gm-Message-State: AOAM532XbexVm9WJ2H/qFE9EzNR4VBulE0j5Zo+Sb38G6q+pJquZg7KU +FgxkXpRxCg/Rf8RZFu5+d9zekDGbqtzSgLxnmAGUUbZ+ubKfHEIr/bGr9J3YW6f3xoguWU+n6I eLfcudskNexQ= X-Received: by 2002:a05:620a:41:: with SMTP id t1mr4784535qkt.322.1614875510981; Thu, 04 Mar 2021 08:31:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJylcR7zmiWNLEc9g5jLwnpRiC+4J5ac8vg6ZjMtKy4mC8DnZ8ugihiQl52PJ+chfQRujlICyQ== X-Received: by 2002:a05:620a:41:: with SMTP id t1mr4784503qkt.322.1614875510658; Thu, 04 Mar 2021 08:31:50 -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 r2sm51753qti.4.2021.03.04.08.31.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 08:31:49 -0800 (PST) From: Peter Xu To: linux-man@vger.kernel.org Cc: Alejandro Colomar , Nadav Amit , Andrea Arcangeli , linux-kernel@vger.kernel.org, Michael Kerrisk , Mike Rapoport , Axel Rasmussen , Andrew Morton , Linux MM Mailing List , peterx@redhat.com Subject: [PATCH v2 4/4] ioctl_userfaultfd.2: Add write-protect mode docs Date: Thu, 4 Mar 2021 11:31:40 -0500 Message-Id: <20210304163140.543171-5-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210304163140.543171-1-peterx@redhat.com> References: <20210304163140.543171-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-Stat-Signature: q935hzfrs8dg498ujk3z6earmoae96b6 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C9523E005F17 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf13; 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: 1614875512-152385 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 | 76 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/man2/ioctl_userfaultfd.2 b/man2/ioctl_userfaultfd.2 index b58983fe7..7497e63c4 100644 --- a/man2/ioctl_userfaultfd.2 +++ b/man2/ioctl_userfaultfd.2 @@ -234,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) @@ -322,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 @@ -443,6 +445,11 @@ operation: .TP .B UFFDIO_COPY_MODE_DONTWAKE Do not wake up the thread that waits for page-fault resolution +.TP +.B UFFDIO_COPY_MODE_WP +Do not set write permission when copying the page. The next write to the page +will trigger a write fault. This can be used in conjunction with write-protect +mode so that there will be another message generated when the page is written again. .PP The .I copy @@ -654,6 +661,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