From mboxrd@z Thu Jan 1 00:00:00 1970 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=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, 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 5C3F1C33CA4 for ; Fri, 10 Jan 2020 15:47:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1276720838 for ; Fri, 10 Jan 2020 15:47:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="wVyxSKtH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1276720838 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 70B288E0007; Fri, 10 Jan 2020 10:47:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BD1D8E0001; Fri, 10 Jan 2020 10:47:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50DCF8E0007; Fri, 10 Jan 2020 10:47:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0234.hostedemail.com [216.40.44.234]) by kanga.kvack.org (Postfix) with ESMTP id 36E6D8E0001 for ; Fri, 10 Jan 2020 10:47:45 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id D02462C94 for ; Fri, 10 Jan 2020 15:47:44 +0000 (UTC) X-FDA: 76362154848.27.mask15_266ebe7d9763b X-HE-Tag: mask15_266ebe7d9763b X-Filterd-Recvd-Size: 6561 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Fri, 10 Jan 2020 15:47:43 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id 195so1308500pfw.11 for ; Fri, 10 Jan 2020 07:47:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ar4Hk7sTDhuxABHFPIAjYj6whvYMREbeGUKWQd9uQ3c=; b=wVyxSKtHotMq4EuLG6hUjb4yKyMqleMnTy2ia5IR32vG1YEhn+fWVw6nECakPk3eMo govAPdUvlSguVPs4krubKp53uQQ9zcK/nOpruq7xLFh9MhZ2aVLRMep1ijJtRsBbRH4k qEn76slmf01lSzxBJn1EzDED7udNX2854BZX79hMA06qXKI1lwm0uhuikWvkINRrF3r6 CaZIcsIEKXRJezA9MyOOURToYQ2i4oCtAWYFq7suJNrCZgzxls/hBecHUBdDUpl53n8i TiedOy91/RFnzrgw7ejTT0wHQMN0TQJmFUdbKmZFgnoDAeAWVoVmdDDOqJgnD38PMhQv uz4A== 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=ar4Hk7sTDhuxABHFPIAjYj6whvYMREbeGUKWQd9uQ3c=; b=VjoiOlj5JJJEBGaEshNrPCWwpVCBL3Mpb5PeM3b1zEBVS0uHRULDOjEdQfm+ZCVwRv 8o1XyHjbgJY11/q9ZJ7b+hXFIsNCDHBP/k43ghq+RNb5QiqCT3wFbWd3ak73Xy7qklDi XNy/LsOmUhoQ6CIrPWbWx7iddXRkrioOfvHCLwuvulLrqbwQQoW4ff9K+PhrAtFBgaQM tnhjLR+DEkTdKYwnfrf/v0vX4bQJ+qB4ClD7hmatiwIrH91m+DllgTPULLWIeyXeEtv3 y0WXgLMTxrGl+WWGm+xA7Bvn1trWoy7kdhqPIIkuStdm+Xaw58Z+0t9J6KU9zPRWs96T D8og== X-Gm-Message-State: APjAAAWlGUtd/SmDxpQ2S+q+ljHz7lc6IhMMai7/Gxi6hLxkmGBbxeCg MzSg0ic+F9TA0vnig8H73qBwLQ== X-Google-Smtp-Source: APXvYqy/eFWRQ7Wigbs9Lto08/bjCPlfrb6Cq9OM8UDwn5twRULysQal8kDhfv5vdBLeNtpjBnQ+LQ== X-Received: by 2002:a63:215f:: with SMTP id s31mr4979937pgm.27.1578671263157; Fri, 10 Jan 2020 07:47:43 -0800 (PST) Received: from x1.localdomain ([66.219.217.145]) by smtp.gmail.com with ESMTPSA id 3sm3489520pfi.13.2020.01.10.07.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2020 07:47:42 -0800 (PST) From: Jens Axboe To: io-uring@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Jens Axboe Subject: [PATCH 1/3] io_uring: add IORING_OP_FADVISE Date: Fri, 10 Jan 2020 08:47:37 -0700 Message-Id: <20200110154739.2119-2-axboe@kernel.dk> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200110154739.2119-1-axboe@kernel.dk> References: <20200110154739.2119-1-axboe@kernel.dk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: This adds support for doing fadvise through io_uring. We assume that WILLNEED doesn't block, but that DONTNEED may block. Signed-off-by: Jens Axboe --- fs/io_uring.c | 53 +++++++++++++++++++++++++++++++++++ include/uapi/linux/io_uring.h | 2 ++ 2 files changed, 55 insertions(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index 62459a79a61f..0b200a7d4ae0 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -72,6 +72,7 @@ #include #include #include +#include =20 #define CREATE_TRACE_POINTS #include @@ -400,6 +401,13 @@ struct io_files_update { u32 offset; }; =20 +struct io_fadvise { + struct file *file; + u64 offset; + u32 len; + u32 advice; +}; + struct io_async_connect { struct sockaddr_storage address; }; @@ -452,6 +460,7 @@ struct io_kiocb { struct io_open open; struct io_close close; struct io_files_update files_update; + struct io_fadvise fadvise; }; =20 struct io_async_ctx *io; @@ -669,6 +678,10 @@ static const struct io_op_def io_op_defs[] =3D { .needs_file =3D 1, .unbound_nonreg_file =3D 1, }, + { + /* IORING_OP_FADVISE */ + .needs_file =3D 1, + }, }; =20 static void io_wq_submit_work(struct io_wq_work **workptr); @@ -2435,6 +2448,35 @@ static int io_openat(struct io_kiocb *req, struct = io_kiocb **nxt, return 0; } =20 +static int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_s= qe *sqe) +{ + if (sqe->ioprio || sqe->buf_index || sqe->addr) + return -EINVAL; + + req->fadvise.offset =3D READ_ONCE(sqe->off); + req->fadvise.len =3D READ_ONCE(sqe->len); + req->fadvise.advice =3D READ_ONCE(sqe->fadvise_advice); + return 0; +} + +static int io_fadvise(struct io_kiocb *req, struct io_kiocb **nxt, + bool force_nonblock) +{ + struct io_fadvise *fa =3D &req->fadvise; + int ret; + + /* DONTNEED may block, others _should_ not */ + if (fa->advice =3D=3D POSIX_FADV_DONTNEED && force_nonblock) + return -EAGAIN; + + ret =3D vfs_fadvise(req->file, fa->offset, fa->len, fa->advice); + if (ret < 0) + req_set_fail_links(req); + io_cqring_add_event(req, ret); + io_put_req_find_next(req, nxt); + return 0; +} + static int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe= *sqe) { unsigned lookup_flags; @@ -3724,6 +3766,9 @@ static int io_req_defer_prep(struct io_kiocb *req, case IORING_OP_STATX: ret =3D io_statx_prep(req, sqe); break; + case IORING_OP_FADVISE: + ret =3D io_fadvise_prep(req, sqe); + break; default: printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n", req->opcode); @@ -3920,6 +3965,14 @@ static int io_issue_sqe(struct io_kiocb *req, cons= t struct io_uring_sqe *sqe, } ret =3D io_statx(req, nxt, force_nonblock); break; + case IORING_OP_FADVISE: + if (sqe) { + ret =3D io_fadvise_prep(req, sqe); + if (ret) + break; + } + ret =3D io_fadvise(req, nxt, force_nonblock); + break; default: ret =3D -EINVAL; break; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.= h index 80f892628e66..f87d8fb42916 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -36,6 +36,7 @@ struct io_uring_sqe { __u32 cancel_flags; __u32 open_flags; __u32 statx_flags; + __u32 fadvise_advice; }; __u64 user_data; /* data to be passed back at completion time */ union { @@ -86,6 +87,7 @@ enum { IORING_OP_STATX, IORING_OP_READ, IORING_OP_WRITE, + IORING_OP_FADVISE, =20 /* this goes last, obviously */ IORING_OP_LAST, --=20 2.24.1