From patchwork Sun Nov 29 00:45:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 11938891 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,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 3AB2CC63798 for ; Sun, 29 Nov 2020 00:50:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C528620731 for ; Sun, 29 Nov 2020 00:50:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lqD/tU0t" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C528620731 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8EE996B0072; Sat, 28 Nov 2020 19:50:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 87B386B0073; Sat, 28 Nov 2020 19:50:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CE3E6B0074; Sat, 28 Nov 2020 19:50:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0034.hostedemail.com [216.40.44.34]) by kanga.kvack.org (Postfix) with ESMTP id 493676B0072 for ; Sat, 28 Nov 2020 19:50:06 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 11D238249980 for ; Sun, 29 Nov 2020 00:50:06 +0000 (UTC) X-FDA: 77535624012.18.air83_561823327395 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id EE14E100ED3C7 for ; Sun, 29 Nov 2020 00:50:05 +0000 (UTC) X-HE-Tag: air83_561823327395 X-Filterd-Recvd-Size: 5515 Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Sun, 29 Nov 2020 00:50:05 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id k11so7394667pgq.2 for ; Sat, 28 Nov 2020 16:50:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m3T85bPGe5F+Y++Xanv5e+8tOU25N4OYONQwuoq/1Bg=; b=lqD/tU0tDTQCtA7PjLcc+V2DExVFb+xzSTUWJkOWg05/7ncV1krxldnwCAwNQbKtIr kX0ubA1jlwnfeL7wh0sqxAOpWkxq6I/TnUH6ydeF7C+k8P3OHNwR+eD/nKEpa4J7LeCL JWYXvxCkL2N/912drcMK3sw2tRkl5oG4zGYGl+BKn1JjigqIF4L0hzgTzZPkYJA8Ztij Tobt70TN3tvcPduGuqriyeun8JBv3Ug4E5Ly8fsoQJU5ucEGZ4aCTsRsZWsQVyuFQezp x5QPByemKbVvEKcYrYjn8Dds29j1cFTbc+13wyA1fSneWSwsfWrKOdioadcv+plh9kha 1gZg== 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=m3T85bPGe5F+Y++Xanv5e+8tOU25N4OYONQwuoq/1Bg=; b=ZUe1wHy4V7r+OBxOMiLXuApnG67wPbP0C32egZTjmN39Er6ZRBpjThIuzilcbwhhFD N0ecQhYsVnO1eXzzfAEDZZc+N6XcnkE77YDHEGuDRWEK+C6NTUzRR6ulTAWSCoA0PHgo KRUEcQYGW8dsHcwQ7nXTuTlVCxzLP9EkGPB/PXv+teJEB5sO50/uODPDoqNtFw3VKheX ZT9eMGeVGh2ne5vS61bpZWGS62292Y31AY023nphY13uylFQb3zOwREPh7ztqDInzA/J tDqsaqcjvN0OokL2XlAgnJKBFApcve+KYgkHRyWrX5GZE21MNTKDWVCxGZIRoHOjwlUj iV3Q== X-Gm-Message-State: AOAM530IAliD/C/i6EKsV+LWCg5l3Ut+X8iHMVZ2sFpubs9gxMEIyrb8 uOQLRKiV1LhNlGaxNRvGaqo= X-Google-Smtp-Source: ABdhPJwysR6pHHiIU7NpGqTX7WAlLbdiNThKHFXvrC9AzG3R2hvHHnbX1oMJ/YdkgURbzNUeOoVjCg== X-Received: by 2002:a17:90a:5b10:: with SMTP id o16mr18898825pji.142.1606611004639; Sat, 28 Nov 2020 16:50:04 -0800 (PST) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id gg19sm16444871pjb.21.2020.11.28.16.50.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2020 16:50:03 -0800 (PST) From: Nadav Amit X-Google-Original-From: Nadav Amit To: linux-fsdevel@vger.kernel.org Cc: Nadav Amit , Jens Axboe , Andrea Arcangeli , Peter Xu , Alexander Viro , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 07/13] fs/userfaultfd: support read_iter to use io_uring Date: Sat, 28 Nov 2020 16:45:42 -0800 Message-Id: <20201129004548.1619714-8-namit@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201129004548.1619714-1-namit@vmware.com> References: <20201129004548.1619714-1-namit@vmware.com> MIME-Version: 1.0 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: From: Nadav Amit iouring with userfaultfd cannot currently be used fixed buffers since userfaultfd does not provide read_iter(). This is required to allow asynchronous (queued) reads from userfaultfd. To support async-reads of userfaultfd provide read_iter() instead of read(). Cc: Jens Axboe Cc: Andrea Arcangeli Cc: Peter Xu Cc: Alexander Viro Cc: io-uring@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Signed-off-by: Nadav Amit --- fs/userfaultfd.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index b6a04e526025..6333b4632742 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1195,9 +1195,9 @@ static ssize_t userfaultfd_ctx_read(struct userfaultfd_ctx *ctx, int no_wait, return ret; } -static ssize_t userfaultfd_read(struct file *file, char __user *buf, - size_t count, loff_t *ppos) +static ssize_t userfaultfd_read_iter(struct kiocb *iocb, struct iov_iter *to) { + struct file *file = iocb->ki_filp; struct userfaultfd_ctx *ctx = file->private_data; ssize_t _ret, ret = 0; struct uffd_msg msg; @@ -1207,16 +1207,18 @@ static ssize_t userfaultfd_read(struct file *file, char __user *buf, return -EINVAL; for (;;) { - if (count < sizeof(msg)) + if (iov_iter_count(to) < sizeof(msg)) return ret ? ret : -EINVAL; _ret = userfaultfd_ctx_read(ctx, no_wait, &msg); if (_ret < 0) return ret ? ret : _ret; - if (copy_to_user((__u64 __user *) buf, &msg, sizeof(msg))) - return ret ? ret : -EFAULT; + + _ret = copy_to_iter(&msg, sizeof(msg), to); + if (_ret != sizeof(msg)) + return ret ? ret : -EINVAL; + ret += sizeof(msg); - buf += sizeof(msg); - count -= sizeof(msg); + /* * Allow to read more than one fault at time but only * block if waiting for the very first one. @@ -1980,7 +1982,7 @@ static const struct file_operations userfaultfd_fops = { #endif .release = userfaultfd_release, .poll = userfaultfd_poll, - .read = userfaultfd_read, + .read_iter = userfaultfd_read_iter, .unlocked_ioctl = userfaultfd_ioctl, .compat_ioctl = compat_ptr_ioctl, .llseek = noop_llseek,