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: 11327737 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 1510A921 for ; Fri, 10 Jan 2020 15:47:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C8C5E20721 for ; Fri, 10 Jan 2020 15:47:51 +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="YfbEpVdy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8C5E20721 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 C65008E0009; Fri, 10 Jan 2020 10:47:47 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C12FD8E0001; Fri, 10 Jan 2020 10:47:47 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B02C08E0009; Fri, 10 Jan 2020 10:47:47 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0242.hostedemail.com [216.40.44.242]) by kanga.kvack.org (Postfix) with ESMTP id 9A09C8E0001 for ; Fri, 10 Jan 2020 10:47:47 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 30F51181AC9C6 for ; Fri, 10 Jan 2020 15:47:47 +0000 (UTC) X-FDA: 76362154974.21.pear22_26cb45b883b0c X-Spam-Summary: 2,0,0,6be51b43f9be3e0c,d41d8cd98f00b204,axboe@kernel.dk,:io-uring@vger.kernel.org:linux-fsdevel@vger.kernel.org::axboe@kernel.dk,RULES_HIT:41:355:379:541:800:960:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1543:1711:1730:1747:1777:1792:2194:2198:2199:2200:2393:2559:2562:3138:3139:3140:3141:3142:3354:3865:3867:3868:3872:3874:4117:4321:4605:5007:6261:6653:8634:10004:11026:11473:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12683:12895:13894:14096:14110:14181:14394:14721:21080:21444:21451:21627:21740:21990:30054,0,RBL:209.85.216.65:@kernel.dk:.lbl8.mailshell.net-62.2.0.100 66.100.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:48,LUA_SUMMARY:none X-HE-Tag: pear22_26cb45b883b0c X-Filterd-Recvd-Size: 6126 Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Fri, 10 Jan 2020 15:47:46 +0000 (UTC) Received: by mail-pj1-f65.google.com with SMTP id a6so1128396pjh.2 for ; Fri, 10 Jan 2020 07:47:46 -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=QWceF/Ubr4D2pRBOuqF4RXO//H5vRaeFWCb4JBp7K4FGozc3PkdyxtFzxZ3fQHNbIa XPDvMIyrv15Faei37Q7gSWKDCIG2x0jVFcmKIQ654ZcUJhbPVcDXN7UgP0cI7ZYgisP3 /HhBtMwP3A6/pXay9Z9YplUJdo65EZD9Wa3NuHbbeDhbCKm112ycN1Sip4uPrJ2MSW6h SC81VSuXpySokuxYa5jgtfivMIW2QwQwmpAwlnbwEhBTBUF9+UphunMbhJrj9lvZow10 uq/gnpJuKckXnNhsDrwuxGpu1E7xNidNd500ti2oXbroW2W2NQWf7g405L8GLOtfXFHs t5qQ== X-Gm-Message-State: APjAAAXy52RYIjPVthi3K7Wg0EpfeFPZPn3QmH1beqq8B9bYsWAHlmD4 AhUzGexrejHyu7jorH5ggzcHsQ== 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 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 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,