From patchwork Fri Jan 10 15:47:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11327725 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D778A921 for ; Fri, 10 Jan 2020 15:47:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B607820838 for ; Fri, 10 Jan 2020 15:47:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="wVyxSKtH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728393AbgAJPro (ORCPT ); Fri, 10 Jan 2020 10:47:44 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43381 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728385AbgAJPro (ORCPT ); Fri, 10 Jan 2020 10:47:44 -0500 Received: by mail-pf1-f194.google.com with SMTP id x6so1311418pfo.10 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=Y8iJWvFMMM/QCbpMj1GVjtZYCxOE8Ryumvg0niQIhGLX5f6pcQEmESg3rjt0cvS8ix D1JPk7MoVEZPOfjHEVeGLma9E8aAvJqw9F+z3YhvvXDuu9DSjmA7FUR8A0avSMyMCh8e 7udOxALUCmD5z3Ipoqn6cS3CpFT7dW+q3LB8+zPw++Ajgtl76NO+RZ07sBPAmHf5gg1G 2zjT7vwE2NsxQZDvtGkw1rGDtFOG0IivFRkfn4S3MPmytduxFrIyZ2JXHydTm4yAY9sG owC9EZIDT80KCdOL6WaL8DqQlBafVcGTs/QHJqi6pxImFUggGB7HHIwdy9/Ff73iLoy9 Ff6g== X-Gm-Message-State: APjAAAUhtdMWHHcJOH2gxhOyLkZtzVH0XQ2R3ngBjRwMapWlbxyJ36V/ HhZNSj7BTnWSR7zG7kIhHNhaLThvF2w= 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 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 #define CREATE_TRACE_POINTS #include @@ -400,6 +401,13 @@ struct io_files_update { u32 offset; }; +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; }; struct io_async_ctx *io; @@ -669,6 +678,10 @@ static const struct io_op_def io_op_defs[] = { .needs_file = 1, .unbound_nonreg_file = 1, }, + { + /* IORING_OP_FADVISE */ + .needs_file = 1, + }, }; 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; } +static int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) +{ + if (sqe->ioprio || sqe->buf_index || sqe->addr) + return -EINVAL; + + req->fadvise.offset = READ_ONCE(sqe->off); + req->fadvise.len = READ_ONCE(sqe->len); + req->fadvise.advice = 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 = &req->fadvise; + int ret; + + /* DONTNEED may block, others _should_ not */ + if (fa->advice == POSIX_FADV_DONTNEED && force_nonblock) + return -EAGAIN; + + ret = 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 = io_statx_prep(req, sqe); break; + case IORING_OP_FADVISE: + ret = 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, const struct io_uring_sqe *sqe, } ret = io_statx(req, nxt, force_nonblock); break; + case IORING_OP_FADVISE: + if (sqe) { + ret = io_fadvise_prep(req, sqe); + if (ret) + break; + } + ret = io_fadvise(req, nxt, force_nonblock); + break; default: ret = -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, /* this goes last, obviously */ IORING_OP_LAST, From patchwork Fri Jan 10 15:47:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11327729 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB8B6921 for ; Fri, 10 Jan 2020 15:47:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CA60620848 for ; Fri, 10 Jan 2020 15:47:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="qOl9QFBl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728407AbgAJPrp (ORCPT ); Fri, 10 Jan 2020 10:47:45 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:41280 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728389AbgAJPrp (ORCPT ); Fri, 10 Jan 2020 10:47:45 -0500 Received: by mail-pf1-f196.google.com with SMTP id w62so1320242pfw.8 for ; Fri, 10 Jan 2020 07:47:44 -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=KAg7QIm8jImHikUoSOMs5glP8O4K1H+Tjxl6C2b09Qs=; b=qOl9QFBlcZiHxiGK52h4/8M3/n2zocyp5aOgkMhgQcAOyq9f9KQsI+A7NOTym4c2SX uL7JxRaIckN5V3bACPRAFezd9Cl87tnT/gviSWBRkZpUa3NfnG/Cg8eAxuoeIZaqFzsQ YT626P69FUp1SeXP+fOrYiZI+YqREpnEyOkfdrRz27p6Hq5Y4Z801IQqDD4mY+yV4Vo1 UprGmZAf+XwvRsR61/J/GDr3cK+ezDYJ6O5FhvH2tE7N1HnGsYcRdzRlV9tvR6eE4zDG Qw1N9mz0P98CP0sx/UJfR5mYYNcfKssVkTwATm4bMeJfXMgwtEQmnoQO0ToQRZLt4QzS TGDQ== 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=KAg7QIm8jImHikUoSOMs5glP8O4K1H+Tjxl6C2b09Qs=; b=euPUq80A7/eJhDHxxK9b3rm6Yru8nZVqzQiH4J7WH7CnOkGKUdeK7pORLAU0lJXTz3 JjuJQaLVPFcnrN9RZSmH6zXuJACXp9o3BjsJaQjvvtKuYgJP+5VUsq0N2nbi08Ebe2V4 w+Ox3e/Gt4RlqlIPs+6Ol7yevjfJYBwKBqI7R5f2gtTcBODenFk0lJ0f+GHLNjCmItJs wYqx1YxOoCH2WastRZH4pokExUowboO0kDAujGQ5aPrMW0ZCUTlwwgURJpLEeeZyklnQ BqTbWTQJHCIEoGbcA7+DiZq0kQat38PWmEodOiHPFc0N0clSdOFac0mfGP9pG6MFWOgw 521g== X-Gm-Message-State: APjAAAWg29MXLOyavF1F6piyblRyUtMC4LRrE87kWGM4pKhZuwZAoaB7 JV3lebV6hVc0kLo7pG0JoWPnDTFP/2g= X-Google-Smtp-Source: APXvYqwoxEzA6d9ySBwwZb72IUvmAA51OESb6WnmFufqREvnNTQk2wRRkJwqjLvXMMAkB/+D11ZgOg== X-Received: by 2002:a63:5442:: with SMTP id e2mr5034197pgm.18.1578671264202; Fri, 10 Jan 2020 07:47:44 -0800 (PST) Received: from x1.localdomain ([66.219.217.145]) by smtp.gmail.com with ESMTPSA id 3sm3489520pfi.13.2020.01.10.07.47.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2020 07:47:43 -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 2/3] mm: make do_madvise() available internally Date: Fri, 10 Jan 2020 08:47:38 -0700 Message-Id: <20200110154739.2119-3-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 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This is in preparation for enabling this functionality through io_uring. Add a helper that is just exporting what sys_madvise() does, and have the system call use it. No functional changes in this patch. Signed-off-by: Jens Axboe --- include/linux/mm.h | 1 + mm/madvise.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 80a9162b406c..766cad8aaa60 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2328,6 +2328,7 @@ extern int __do_munmap(struct mm_struct *, unsigned long, size_t, struct list_head *uf, bool downgrade); extern int do_munmap(struct mm_struct *, unsigned long, size_t, struct list_head *uf); +extern int do_madvise(unsigned long start, size_t len_in, int behavior); static inline unsigned long do_mmap_pgoff(struct file *file, unsigned long addr, diff --git a/mm/madvise.c b/mm/madvise.c index bcdb6a042787..43b47d3fae02 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1044,7 +1044,7 @@ madvise_behavior_valid(int behavior) * -EBADF - map exists, but area maps something that isn't a file. * -EAGAIN - a kernel resource was temporarily unavailable. */ -SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) +int do_madvise(unsigned long start, size_t len_in, int behavior) { unsigned long end, tmp; struct vm_area_struct *vma, *prev; @@ -1141,3 +1141,8 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) return error; } + +SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) +{ + return do_madvise(start, len_in, behavior); +} From patchwork Fri Jan 10 15:47:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11327731 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 32C10921 for ; Fri, 10 Jan 2020 15:47:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 11D902087F for ; Fri, 10 Jan 2020 15:47:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="YfbEpVdy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728422AbgAJPrq (ORCPT ); Fri, 10 Jan 2020 10:47:46 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:38344 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728394AbgAJPrq (ORCPT ); Fri, 10 Jan 2020 10:47:46 -0500 Received: by mail-pl1-f196.google.com with SMTP id f20so1001082plj.5 for ; Fri, 10 Jan 2020 07:47:45 -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=k3hcL14cRfWpNhjA9GrayF/a85Yp0t4ZRzKs/aJScxA=; b=YfbEpVdyQ8r69dkfHiyx8pNVRgJyyyxs/BW7Sne8I0MWpE+ZH/3LI+IIhNcdvTbWhx KSMIHgttHCz96FPsAxgL/QbOtfsREZJayQvhPkoBZlEdA+nmSTZZfSk6eiNRi6Hp/PcE xQwJfmkN/jjA4W7kM6glJeeYxZ+LayDE5s6w593Lmjyp05+9qLL8ezVrwQd3PWnVDL6p osUO2qXIT0BxoLkwIuT3EREoLh3B7wMPjelMre6AgqLWyOtgL4hp7do3WmkLW1Dlaa4T VozdJbVkbLFpbiQX0NNexgmYxNFNe0YsTvIK1R8ylMZC15w9UIzkBEbpfKLHgPJl0d1i HC2g== 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=k3hcL14cRfWpNhjA9GrayF/a85Yp0t4ZRzKs/aJScxA=; b=nlD9Zx578VxIeLcx0SpAZ294y6910kzJAUYgmbuIuEhe4tgmht4W69qGD9Sf9uxkSe LAsAlTgROmADYRx4p3imVDbXkv3Edcj3uBtGC6T2V6XE4OrL5aZjM2VfvBHsYS9HjhA4 md18NDcgUrEB1h2Is0EcSOK55sYpipe6NUqMIVVsRe7L0Cw6wHZOVtxXoavVqqTn3hON CCgvmdgmWL052JmAdtS/d2BJ05dJxhEHceLduMpOeyVQHHUJ/7cAqPVlpLjBpuv14aID iAk//kvABzd+0JrTMIhckcncAehOmV+365tyEe6QxUmXn/VrVh4ltHhgKljrlB4+bI4V OyEA== X-Gm-Message-State: APjAAAV+WRy1Ua6vGS1FGzBMVWANEaMo+Cgg0xY7CbUCH4WHUATgMpYP EqMoFU7p9SF2ayvFybNm07l2oA== X-Google-Smtp-Source: APXvYqwtn2rd/HxYQ0miac7cSCHXh89mwRHywjJWx66WM1fjvHF+LOmqhvfTiq9mfW5y+k3hqxqXfQ== X-Received: by 2002:a17:902:c693:: with SMTP id r19mr5306318plx.25.1578671265337; Fri, 10 Jan 2020 07:47:45 -0800 (PST) Received: from x1.localdomain ([66.219.217.145]) by smtp.gmail.com with ESMTPSA id 3sm3489520pfi.13.2020.01.10.07.47.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2020 07:47:44 -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 3/3] io_uring: add IORING_OP_MADVISE Date: Fri, 10 Jan 2020 08:47:39 -0700 Message-Id: <20200110154739.2119-4-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 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This adds support for doing madvise(2) through io_uring. We assume that any operation can block, and hence punt everything async. This could be improved, but hard to make bullet proof. The async punt ensures it's safe. Signed-off-by: Jens Axboe Reviewed-by: Pavel Begunkov --- fs/io_uring.c | 56 ++++++++++++++++++++++++++++++++++- include/uapi/linux/io_uring.h | 1 + 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 0b200a7d4ae0..378f97cc2bf2 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -403,7 +403,10 @@ struct io_files_update { struct io_fadvise { struct file *file; - u64 offset; + union { + u64 offset; + u64 addr; + }; u32 len; u32 advice; }; @@ -682,6 +685,10 @@ static const struct io_op_def io_op_defs[] = { /* IORING_OP_FADVISE */ .needs_file = 1, }, + { + /* IORING_OP_MADVISE */ + .needs_mm = 1, + }, }; static void io_wq_submit_work(struct io_wq_work **workptr); @@ -2448,6 +2455,42 @@ static int io_openat(struct io_kiocb *req, struct io_kiocb **nxt, return 0; } +static int io_madvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) +{ +#if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU) + if (sqe->ioprio || sqe->buf_index || sqe->off) + return -EINVAL; + + req->fadvise.addr = READ_ONCE(sqe->addr); + req->fadvise.len = READ_ONCE(sqe->len); + req->fadvise.advice = READ_ONCE(sqe->fadvise_advice); + return 0; +#else + return -EOPNOTSUPP; +#endif +} + +static int io_madvise(struct io_kiocb *req, struct io_kiocb **nxt, + bool force_nonblock) +{ +#if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU) + struct io_fadvise *fa = &req->fadvise; + int ret; + + if (force_nonblock) + return -EAGAIN; + + ret = do_madvise(fa->addr, 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; +#else + return -EOPNOTSUPP; +#endif +} + static int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { if (sqe->ioprio || sqe->buf_index || sqe->addr) @@ -3769,6 +3812,9 @@ static int io_req_defer_prep(struct io_kiocb *req, case IORING_OP_FADVISE: ret = io_fadvise_prep(req, sqe); break; + case IORING_OP_MADVISE: + ret = io_madvise_prep(req, sqe); + break; default: printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n", req->opcode); @@ -3973,6 +4019,14 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe, } ret = io_fadvise(req, nxt, force_nonblock); break; + case IORING_OP_MADVISE: + if (sqe) { + ret = io_madvise_prep(req, sqe); + if (ret) + break; + } + ret = io_madvise(req, nxt, force_nonblock); + break; default: ret = -EINVAL; break; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index f87d8fb42916..7cb6fe0fccd7 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -88,6 +88,7 @@ enum { IORING_OP_READ, IORING_OP_WRITE, IORING_OP_FADVISE, + IORING_OP_MADVISE, /* this goes last, obviously */ IORING_OP_LAST,