From patchwork Thu Aug 22 03:35:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13772574 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4872C52D7C for ; Thu, 22 Aug 2024 03:35:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A29D6B0253; Wed, 21 Aug 2024 23:35:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 454D594000B; Wed, 21 Aug 2024 23:35:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 259CB6B0258; Wed, 21 Aug 2024 23:35:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id EA7BB6B0253 for ; Wed, 21 Aug 2024 23:35:40 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 921111404B8 for ; Thu, 22 Aug 2024 03:35:40 +0000 (UTC) X-FDA: 82478466840.08.F8044BE Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by imf02.hostedemail.com (Postfix) with ESMTP id B68AC80011 for ; Thu, 22 Aug 2024 03:35:38 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bNR1LNJJ; spf=pass (imf02.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724297658; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Oq1dmJmhMQ/ONS/9FcWt2dsBOZ/rQa7CJ2HEombNkGY=; b=uM2w/1bu1daBVGseTXpl/yZabRedvvX3eWrHq0wLZy8MOLinjtVQbkSLK2wpa+u0WWUr+/ FhdYN809nKxYB8N+bTiDYGeO76Smm4r/e2IF/bdYQ3E25WuLjDsdH6rzmQTnEUZ6Dzio1L +ammJljv/RqyejugtrFlMtkougJEgMQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724297658; a=rsa-sha256; cv=none; b=cb2A+jxljpQomF0HD6OcF79AOwgrt77DVpN91lCuw0BvA1I+rDBfaPtkyXojdki9mjfdTW +XuqSME/YWD7CMKSp55HlkqnCAm+OtWvp6mnLhRoAoWdvCoQ/5I02mOvBupDImv2FcDUd+ 8T+EAobpDtji363Ayp4toW2PSlQa228= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bNR1LNJJ; spf=pass (imf02.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-42816ca797fso1974625e9.2 for ; Wed, 21 Aug 2024 20:35:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724297737; x=1724902537; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Oq1dmJmhMQ/ONS/9FcWt2dsBOZ/rQa7CJ2HEombNkGY=; b=bNR1LNJJXG0gaqdVXFbOiJVBRz9MwOHA6+f2hcuhO0VId2jLT16be4Mex4nVdYCsT2 wjr2DMl5Q1QlMqs6RmO2vW+7aUubqDPh1ajOjBxywkK8Zb+90Bfu48AKN2qwg4bKoeYo GF0T7acGTQlBYQvOy1YZDQxgoVq2ToOAmwB99/yEiVyVSFgAQckpVwKNQUhZgLD0LYh8 cYm18FF08FC7KwjPu0cEvBF7PIy1YeF1C2lLftOfWy/rQgll3+ZXoS2Oz5B2vvfASh59 UWs3TslymR6axCPJJCBhQnw+UAL2YO85VAghgPXP1RQNnmNaGFThEAWu1jKVJt6Oxas2 B63A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724297737; x=1724902537; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Oq1dmJmhMQ/ONS/9FcWt2dsBOZ/rQa7CJ2HEombNkGY=; b=ZxmpOeQhNxbEZ9XP8Q9jAKFHwStd4hgluRGy9lCbJOWKucDTWNAezJHggRlEiQyKoc NAiqFoy01lDiVN9UgOkPeTc6/ZS5RSkYlz+mMRGauDenDHvm2jwCRaz2RAXg6QEnKT51 +PqTYa6U9iJCLrngTrzwCHYEC8VFBfXzXSORkZiPVN35a7c/r9GSmfgejyZW0tUnCSef 3IUbseGusnwzNFkfS8lLCI14zIUlNNp9kGKW83SkKYk5gxO2ld8SSIJqhyIeW+vllokb tgU8ksvEw9hx+8kAklLiJcrYOT8b0El8KaZvLYMDClKtJKrDVShvcz0nGWsaD4uNa34v 3y2g== X-Forwarded-Encrypted: i=1; AJvYcCWdHWZNZ1bBWHw3k3vulTtMzmtA/7fPYtQwMUt3igaq6xG2o4Y51WQmh3/5sAegQ8w9IuMB4za89A==@kvack.org X-Gm-Message-State: AOJu0YwA9ctQ4MpFdLVOpw8xD7gzBpNmziClwroS3x+3Zod8kU++Y3PB v7bTiwJnZkhaxL+MzZ1y74bH1aY4bei7UFEQPfdNRPhnkrcyg88Y X-Google-Smtp-Source: AGHT+IF1YE9cTCYPQ6lqJcA/bVj+/okCLizbljJ5bkv4iDV+o0PRhQhkc+Im1+k1WARHaBsjsN01GQ== X-Received: by 2002:a05:600c:5486:b0:429:e637:959e with SMTP id 5b1f17b1804b1-42abd2125d2mr33760875e9.10.1724297736489; Wed, 21 Aug 2024 20:35:36 -0700 (PDT) Received: from 127.0.0.1localhost ([148.252.128.6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42abefc626fsm45491995e9.31.2024.08.21.20.35.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 20:35:35 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Conrad Meyer , linux-block@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 1/7] io_uring/cmd: expose iowq to cmds Date: Thu, 22 Aug 2024 04:35:51 +0100 Message-ID: <55ce8b5b813a7ca40597457b9afc8fd17d4ff11b.1724297388.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B68AC80011 X-Stat-Signature: cmgeqmxz6ra4x6o3ambezztniiowu5cr X-HE-Tag: 1724297738-988223 X-HE-Meta: U2FsdGVkX1+1D5gaVycxucIs75z1YQvG383sM88sq2nIb+xIglg/WfqDDFg2V9j82UbXTrwavqPj5c039kZU2h3S8+Q+TDxDphdQ11lA7JAq2tXk7bZ2p3XfizncXBa3u41fb+J0R9yJzl2nX+PZMVtrHRqAdgVuWH65lY1op40kEF5uibKnpoTYGP/WVca6T35upCnGijqsOPV9lfzaf+ILjirpm6b9Im2MusMuhIRg0jMG0xj7TZJcrg2uUEbuyXXzCBv5hDOaNIks38bGbTGgEegILbne87yy8DMy/D1SxlAepuInzGVVRNPWlpV4b2/982F/WpHB67QrkuTxriyvHUzUL0pTg7HMUuVR0Gh055iZVhk5wXpqSpbfKPmsCPeBftPg4oQFnbuy417Asl9cocQSsaEQcRVc7H0Bo5sETGaGD3xjjHRo+mZFuZqKsWGXdRd2DUQy7nLtixwt8KGyI7xXeVIuDq/BB67Us8kJqJh3RnKifNAfre4ouLCLd+4mg63SsYVL1lB30BSxAVCAqWPv1nHZHSXxNY7mBQsRCAE1S0WUA6JqXC4TfIfxv4CqA7+W8Jd8feXLD5S5TKm8KEfo6LuP/HuC8Rx5TiEsHxBk+3OyUHS3cpo4t74mPm/5CCQdiPTimf+aaqLmgGCEp7tH/gdWodfFgcOSWMeu2JXv6HNET3tZsZpkJ1lXjaM+Kif47cjH3NIwTaHywcWn5YGpEnC4sgTvNefxhr4zRFPW8XfL/rykkpuYLP4vyKoN4KffFI2jwhXLgatJC/KjnHx3c4dNPIULDzq9bHwh/HkG/JoIDte4gdiobKeJ0enR58CzAKNcKpqA1EPb0OUrx9ts1PJpLqPER1jsmB8dDAV4/rGFaV5ZTf1JL48QUgPSANR7PUOpmlXZEJ8kTP0edqqVr58lvAJK/e9zDqnnK3ZCCvPQIinITW4cphaGB3iQlYW34fP2QyfIjGA sAMzzCCw PucyZAQKjHDayKjmtQjULvABvHakZWQsuYfrL2aQpnH9Af6uToELnpVmtRvi1o0Fd66htgC0aTVXQZqhUMmC/7OdZfVxh1ceyI/nffE9AIdkiSnA6ci+o9Ek/TeGHEUpSd975kuXPo6kIsfkpRciPjvH0QhgUice632Ucm5ujVDRqQkP/l9TGBrEkRir5vkIQrWMkrCVVCAHZ7rmSIlTu6oWgLdZ21c/0SFsbkf5OmWC3dFmP63gl3TlLW2Dze2z/Qu0HPxCLaGGGlSg8rWXyODJ1+hrZxzKPRzcvcq/XM18D0dErXVV4mPcyuUDlAzEBOSyMjX1KEFV7MyUAGwceBF0HG2GNYbtNF67/OhwQbA5rMLfbMqtMoC+BcIUYy2Dr8nNvDemseLvwJgbicCz1voAQiD/wNCqV6LSk2f2S+yjpa2/Lp+f8TymE5Ie3PmJa/VQgNX7Tbt/nvDnal1nNZKQVeu1HRBexX0wMXnCB7hodkJVd+XtYCx36lA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000078, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When an io_uring request needs blocking context we offload it to the io_uring's thread pool called io-wq. We can get there off ->uring_cmd by returning -EAGAIN, but there is no straightforward way of doing that from an asynchronous callback. Add a helper that would transfer a command to a blocking context. Note, we do an extra hop via task_work before io_queue_iowq(), that's a limitation of io_uring infra we have that can likely be lifted later if that would ever become a problem. Signed-off-by: Pavel Begunkov --- include/linux/io_uring/cmd.h | 6 ++++++ io_uring/io_uring.c | 11 +++++++++++ io_uring/io_uring.h | 1 + io_uring/uring_cmd.c | 7 +++++++ 4 files changed, 25 insertions(+) diff --git a/include/linux/io_uring/cmd.h b/include/linux/io_uring/cmd.h index 447fbfd32215..86ceb3383e49 100644 --- a/include/linux/io_uring/cmd.h +++ b/include/linux/io_uring/cmd.h @@ -48,6 +48,9 @@ void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd, void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd, unsigned int issue_flags); +/* Execute the request from a blocking context */ +void io_uring_cmd_issue_blocking(struct io_uring_cmd *ioucmd); + #else static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw, struct iov_iter *iter, void *ioucmd) @@ -67,6 +70,9 @@ static inline void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd, unsigned int issue_flags) { } +static inline void io_uring_cmd_issue_blocking(struct io_uring_cmd *ioucmd) +{ +} #endif /* diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index a53f2f25a80b..323cad8175e9 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -533,6 +533,17 @@ static void io_queue_iowq(struct io_kiocb *req) io_queue_linked_timeout(link); } +static void io_req_queue_iowq_tw(struct io_kiocb *req, struct io_tw_state *ts) +{ + io_queue_iowq(req); +} + +void io_req_queue_iowq(struct io_kiocb *req) +{ + req->io_task_work.func = io_req_queue_iowq_tw; + io_req_task_work_add(req); +} + static __cold void io_queue_deferred(struct io_ring_ctx *ctx) { while (!list_empty(&ctx->defer_list)) { diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h index 65078e641390..9d70b2cf7b1e 100644 --- a/io_uring/io_uring.h +++ b/io_uring/io_uring.h @@ -94,6 +94,7 @@ int io_uring_alloc_task_context(struct task_struct *task, int io_ring_add_registered_file(struct io_uring_task *tctx, struct file *file, int start, int end); +void io_req_queue_iowq(struct io_kiocb *req); int io_poll_issue(struct io_kiocb *req, struct io_tw_state *ts); int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr); diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c index 8391c7c7c1ec..39c3c816ec78 100644 --- a/io_uring/uring_cmd.c +++ b/io_uring/uring_cmd.c @@ -277,6 +277,13 @@ int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw, } EXPORT_SYMBOL_GPL(io_uring_cmd_import_fixed); +void io_uring_cmd_issue_blocking(struct io_uring_cmd *ioucmd) +{ + struct io_kiocb *req = cmd_to_io_kiocb(ioucmd); + + io_req_queue_iowq(req); +} + static inline int io_uring_cmd_getsockopt(struct socket *sock, struct io_uring_cmd *cmd, unsigned int issue_flags) From patchwork Thu Aug 22 03:35:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13772575 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9377C3DA4A for ; Thu, 22 Aug 2024 03:35:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C90BC6B0256; Wed, 21 Aug 2024 23:35:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C3FAF6B0258; Wed, 21 Aug 2024 23:35:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABB976B0295; Wed, 21 Aug 2024 23:35:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 85B896B0256 for ; Wed, 21 Aug 2024 23:35:41 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4152EC1224 for ; Thu, 22 Aug 2024 03:35:41 +0000 (UTC) X-FDA: 82478466882.13.947E3D7 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by imf06.hostedemail.com (Postfix) with ESMTP id 609D4180010 for ; Thu, 22 Aug 2024 03:35:39 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=grqfWCND; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.128.51 as permitted sender) smtp.mailfrom=asml.silence@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724297674; a=rsa-sha256; cv=none; b=B1nr2rs7XynGzrJU3xdDQ6/y4ogmjEd9fMMJ36TwmjwsC+RL9JTsFHE/R3nQCPN2KkaQHD 4eoGCuio7ySoKCH2I9y636Aab75uhTl/2WvRWTIjlYS9/y6HTgmGljmzlFrlJso9ojIQJV xh6eKYCeVBuC0hsRwgntGMyrQr74tjg= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=grqfWCND; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.128.51 as permitted sender) smtp.mailfrom=asml.silence@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724297674; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=yyZRXxiAI12SAMIbkwT8bn9l7S8e/TKEaLOeKBVDL1c=; b=ZDiwRdD8xHUYQFaa/cBKD1MsA/5zu5dNJqq/Z/tWori0YoX1KXxztyVJgN5eJEUf6N2pHk agpEgfFqqorGJy2+qHqRuHU8UH6GmOCmOyKe1MJ089G9GmdV4/pD0+Wj9LJfjNlb4/Hrd+ Bvrew29MiwAW0hzhyML26ubv8e6uw0k= Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-42808071810so2037335e9.1 for ; Wed, 21 Aug 2024 20:35:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724297738; x=1724902538; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yyZRXxiAI12SAMIbkwT8bn9l7S8e/TKEaLOeKBVDL1c=; b=grqfWCNDxrwhsX7h4zRbSHfwCWCwVdK3YzLgHe9s9VdijDy1+TGfqv3yqp/IKxi5jx R2sae20H/CkqOwAV/8u6QRGuowYggR1iVkLneitGz13n08XfVNXmYJHr7f3mPbJUW3YZ os7+pMKbSZXaWK0EeS/U15XlWfV4xVgJ73eXKjvgjAsq7APRYLrGoboS3szuIVlZu0CY sf7wnAtORY/6dASakxmxomIs6cPa9Jjn2ckyFQx/qkhnDgHKGNRSF3lw6pmOvf/h6qLv ePndzVVL9py4yNFlSrSPcWveXtTwTjwVqsxv1FEfmoX3dRTIOLNzKQbLInX+XaEPRG3Y 2G8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724297738; x=1724902538; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yyZRXxiAI12SAMIbkwT8bn9l7S8e/TKEaLOeKBVDL1c=; b=dHz/YtoyYPyE1F/cnu5pyqIt0ZDvnERldD2NU8oUAUlbSNPHc+oOgisKTOfJfZ1HEp ZNH7ydug+CiLyBXmeqgHBLzxf878gKZeaDgDhLLHreikylHJdtKE6Ma14R8++fDrA/n4 P3Tz9gIk1Vw2HUS8q3dQlxv8CFH4/hyn5ik4zYNt2/DzDeSbN+b/RzEuE2YPG9zr17Ud 2uj+Jr+YZI8lCCcig9XEiLIXQmTqW9QuG8NmQTP2SWkDdVbzL98de7mLvgSic1aBL6cL x9g8hqAfitFv59WEVsF9SCFWjgWwHeZpLCBXAkgknpLlJ/HXcCLktiDEn+lnC69LAIb4 1rdQ== X-Forwarded-Encrypted: i=1; AJvYcCXAyxDH4or6/X9rZG3zzgNn74FiHNUE8nDYSstrKwvVH3aRljMBdGk5fYrmLvwuOAEMP9mK/MSAcQ==@kvack.org X-Gm-Message-State: AOJu0YyzB/TSznBx96q5wxyyWt4QTeJNG/n8u8bnQkr78lZSi2iZDKes Lv9Bc1r97IaaQx2iElBFX8N0rLRjEYG9UPbzsFaVlSQEXu8zUt9QG+xyjA== X-Google-Smtp-Source: AGHT+IHDULdLquHnuYJwxgO4fQ1bzZiZlm+YOsZaNNDGdxrpbgmJfo4P3H5hO/VE8ik0Fzd4TfAAUQ== X-Received: by 2002:a05:600c:45cf:b0:428:fb7f:c831 with SMTP id 5b1f17b1804b1-42abd253e34mr32708315e9.32.1724297737617; Wed, 21 Aug 2024 20:35:37 -0700 (PDT) Received: from 127.0.0.1localhost ([148.252.128.6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42abefc626fsm45491995e9.31.2024.08.21.20.35.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 20:35:37 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Conrad Meyer , linux-block@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 2/7] io_uring/cmd: give inline space in request to cmds Date: Thu, 22 Aug 2024 04:35:52 +0100 Message-ID: <54b2273600884f077b1564d4353c77ce2d9b1051.1724297388.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 609D4180010 X-Stat-Signature: sjeckg5o3pc1a6aqdbxrdi84h65u7ch8 X-Rspam-User: X-HE-Tag: 1724297739-517423 X-HE-Meta: U2FsdGVkX1/YCKkxvsapXq8oUBnIcSXNEednuXrV8KJrPkY12AWdDn3/TzlqoNbh5EG4RlQAaAq3msh/IFmUqRuJYofRUU65BEF2GnxTN0NW4r0qQWltBpKkXhu45lvBgKoF2tNHpDnEGjnv1SmJvMPun/bbMOsPtSFsc7EiVswjrz7gDKjtiFV9yLXt3JrUst64GVLa5E/gX/mWWKi8tSdXTgIC37KHMKec4t13ier7eeePN1KOKOJwijuRgQnw5glMsE3iqGHjhj1qT+G1e5jIVV/h2gDKfYpaxCyrokzNAScZLWEVK/mH9CoubnHPnSuhPDxYoR++gGFolKgNaBZnrOdI0RfgHFwS3HQvoWz/OPHagu5Zj+1UpOwfXCJg4d8xsZbzRzhDkil83Ha7+npUx6DUDEn+VD8MTTSiK2QQNO2QbMTHuQfY6YyU54GZ70noeg//9mYtOqKzQg55PRwOFTpI91BpheiHzuGQ+BoovOc/1auBW7gYBGslwL4RA9S/00G6mIuQWsVW2jqm7e6Ud8mguvTJVikiF9e1PkC8UL+7YV5+v30B9p2UV6k+x2zpJ3OJ4sNr+QPKTpRWujEm3gabJTEA5BKDeGRascNyK1/fx+NE3sQHgxZWUcJ8H3ALT00mFN/zWwGHGfJfpl6GSLEqwcsYEVaeAfk0H4wlAbYtn7My4Fhv0Q/c5iv3VUMUiKEMue72KuutloeEx7QFOveyk0Fz2KPJohU2GBOnMPV+eHDX3A3XD6Pg0kxqXsk/GAqJM3B80QVLb6I5yjWz9HaT/hLAnNIhxfnerAl5mWMAl3z8cY8xSZ+p04Atrms1Ube5Cp+n0Vn5R2Pop97KWZ6SxTU8PdV5ETCmIxXUudmUyafuTHl0Wq2xCYXk65e2llnniGg7DkkfohOFGM6i4eLfbWNJJjiLxDeex0cDTShJwkHCEvUfST1VbrWq4zisq3GjVcAKlEwgliO DHFCWBqm 9SSTucsMipLtEt32RSup5K0HJiLJFg5fkIGqxtUtXyoBIx2uaA7/kEGX7BDw/lzMkAF0J7fl4RP5Xc3of/jff8TJdWBWDQ6p5+iycb/YMkyrJurhVYT/IhmJnxQdKRy9F+DYp13YUVcNesAHp+WjNVnirT/WAkVSOL9HVI4WIgCFZiceUYVzTU5uwjpdIiziJ6wWUORO3hUP7iCmfoQ5nh99IJKcIGTP7lqYaoDNWBT3m4zWt8rqIJXv0lNjtL6uSWYn/UK/GWM5oIOwESguFHKmIZkHNa3U/cktm/yVzUarn47smU7h1J+avXvCwToZeU3Usj2rbMciYYU+JrJZL0yaP0Fd0liNE87JS7XNnqnEyy4MG3Lv6M5UNfaAAJTFXs6y3cVgr7ndFfdZmNInvNBWu/EFnPPQy5NdMrt6AAAZCfgwWFEv6ws/Mhs3UEYfGBUMKvZzYmdnSzbnk79RDz6H4rrJKCs9b1uqRsW68AretuyVu4YlRfLmK4w== X-Bogosity: Ham, tests=bogofilter, spamicity=0.001298, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Some io_uring commands can use some inline space in io_kiocb. We have 32 bytes in struct io_uring_cmd, expose it. Signed-off-by: Pavel Begunkov --- include/linux/io_uring/cmd.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/linux/io_uring/cmd.h b/include/linux/io_uring/cmd.h index 86ceb3383e49..c189d36ad55e 100644 --- a/include/linux/io_uring/cmd.h +++ b/include/linux/io_uring/cmd.h @@ -23,6 +23,15 @@ static inline const void *io_uring_sqe_cmd(const struct io_uring_sqe *sqe) return sqe->cmd; } +static inline void io_uring_cmd_private_sz_check(size_t cmd_sz) +{ + BUILD_BUG_ON(cmd_sz > sizeof_field(struct io_uring_cmd, pdu)); +} +#define io_uring_cmd_to_pdu(cmd, pdu_type) ( \ + io_uring_cmd_private_sz_check(sizeof(pdu_type)), \ + ((pdu_type *)&(cmd)->pdu) \ +) + #if defined(CONFIG_IO_URING) int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw, struct iov_iter *iter, void *ioucmd); From patchwork Thu Aug 22 03:35:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13772576 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58EFCC3DA4A for ; Thu, 22 Aug 2024 03:35:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6EFB76B0295; Wed, 21 Aug 2024 23:35:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6743E6B0296; Wed, 21 Aug 2024 23:35:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EE476B0297; Wed, 21 Aug 2024 23:35:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 269056B0295 for ; Wed, 21 Aug 2024 23:35:43 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9EE9FA8152 for ; Thu, 22 Aug 2024 03:35:42 +0000 (UTC) X-FDA: 82478466924.19.916D72E Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by imf12.hostedemail.com (Postfix) with ESMTP id C40B640005 for ; Thu, 22 Aug 2024 03:35:40 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Cg62PaOw; spf=pass (imf12.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.221.47 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724297660; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=coYbv4PcaCiw3s7iKLGpr0JKeDXM/58rHgT2Op2hXlo=; b=rfIbKjcbkMJnNmz6TLmlLhda056eMQOlW5KwZMzAfBelomyNX5prgiIktiR11CiEmMbYJl m6j815KIORmNUF6Hkaj7KLO6AT60VbwxiJzHgkQDOKQ4JSE00qwpQ7AjlZrMRU45Mmh3RN FmyQYhUQCWu2U+MzPxsZkQLA1mox09o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724297660; a=rsa-sha256; cv=none; b=jVLOI4OKg331gv+34sXr+ZyckBMxF9Jou0hvnUMLTh+vfSbVvGExMx6P+/yawjNOP0kusr nXQnQHmR3mc+GwelRqTwtJAw7gk0F/X/dArrnpyHkJCY7kmUvAb0lN/ZpO5pAuX+iLVFI+ M8d4WIKBvtytVfNydXwHqjOTu92Rs+g= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Cg62PaOw; spf=pass (imf12.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.221.47 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-371893dd249so100848f8f.2 for ; Wed, 21 Aug 2024 20:35:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724297739; x=1724902539; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=coYbv4PcaCiw3s7iKLGpr0JKeDXM/58rHgT2Op2hXlo=; b=Cg62PaOwEYQ8D72DySoJ0VrL6AEgD7TqBCQNnPXVSaSvyY88Vmt1g0LNhZrJa/nPjB M1smnYuO4O6sxP0Xi6cQn5/3k/V7CQosbW/u4aeiq3yOE0BEsiW5o8TTJzKS8i/1mtPY sA2vhIIgpT/oWTjCF6zyjYZ4u47f0/TTowMaBE0fOAyzF0I+HVQSLTIhBYuF4uchAaOb HPB2b3Cl+07UA8jn/1HjCWFrE33fq2yQfTxKFvMil43e0ZhV6R6xrQS6+Nusy+azVARJ xA+C0QtZFhHz1GmfjezlzIOQMEL6RpCXISYSSWFZSn9I5Kdc0NeRBZOTZAQkZ5E/HopS PJjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724297739; x=1724902539; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=coYbv4PcaCiw3s7iKLGpr0JKeDXM/58rHgT2Op2hXlo=; b=TeYgiasdxikhEniU0cMfBH4GFE59n1mTNGTOXFIjghWi7J0OxvrbJdZEH0fmADMH1z Kwq1Hp+KOr9+W20lOAH/mMLXZWiX+Yo9DWp8kJgu/eX5nWcJzglULaLNTsejlmDUqWyH 8SQdD8B0qUeR3O23n+fxmHIjpg/ZY/XPGZKpBjBVdR/N38XF2Ebi4jgcwW54QQtDgx5r w3FEvuE58xZCMrDVt1wO90+fmEM+4mEv21QvAREtE/3F7m6GIrXqZ86/+7cxpbC8la8v 5jzR5wU0n/zJo3+wwZb8bdHVffQxOgwE/Szm9fI2KFv/CU1LnZtAbcKavJu+7J1GMLTS Q+qg== X-Forwarded-Encrypted: i=1; AJvYcCXjY92BoCzvZdOIm1HTpsV9rCMtKfK6cxLUMFhxzcEXydhMWVr94Gq2KTJe7kZAr2wFf06X4FMtTA==@kvack.org X-Gm-Message-State: AOJu0Yyj2uysNT5O77wMUtqMMC2EXdqPz9O4R1lduPeeBPm+iF92dmwc Ulvo0lKtD0nQH1BYS6nK7H491pS/Kbrd1ctUdi14QPaK4gOjK7rT X-Google-Smtp-Source: AGHT+IHP7tOkU4byOXFqX59kqg4UjLfQGE6iQhOnMRCrdta+ni4FkcLFL3OtNWEW+YJSDoGtQ2G8Gw== X-Received: by 2002:adf:ef0b:0:b0:371:8763:763c with SMTP id ffacd0b85a97d-372fd5a45d5mr2872795f8f.33.1724297738908; Wed, 21 Aug 2024 20:35:38 -0700 (PDT) Received: from 127.0.0.1localhost ([148.252.128.6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42abefc626fsm45491995e9.31.2024.08.21.20.35.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 20:35:38 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Conrad Meyer , linux-block@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 3/7] filemap: introduce filemap_invalidate_pages Date: Thu, 22 Aug 2024 04:35:53 +0100 Message-ID: <5bf2b0f08ec25fa649f04c0847722c6b028f660c.1724297388.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: p8ewqdasckafoqgd9o68xu45byzk7ugu X-Rspamd-Queue-Id: C40B640005 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1724297740-324141 X-HE-Meta: U2FsdGVkX19xs4OeGe3HrGetyb15vZgWswTIMD9E7lZ1o6LHXUaTZtL7cQBhmHQk/rBGzpIj9I1LBpOgayCBg4J9tJ/TcCikBtm1yy4y+UlP/CUbCDD5oGmgwSQv6bHlMvbvfqzM7xz7FDSAj/3vVDNR+J56Gc6B1d8cOLm/I6sl6YxoNIiUX+QZa9gKp7z332S9bKKTXn6Z92JgbK86J+QAJNTRzBPminCiBKDL4/twbNh9Mnu66+RzpVumbh0u1F1tQK6eZ7nzyphcaMyI5l+3e2aOI7+fHNxMhmi5/QH3qt/Oqsx+tCIq2br0DYWbpCRnYvxysA9RDb1KkOZuHPhc4yXwmOtQGkgbxO1goe8WU9u/Tszl+MBizDRvnH7K219eJbBZr28RPwSearT1x2MsFn3A2STs4+hVsz191mjSRBp8Vik4iaKvhItHi/k3pG0okbBiIJiQAHsZZC0XDrnXiOgP8w1y6SpJpHM5+5b7udlhsKXSFyvi+4Xo2ZWketD0Wsvk4vtksOtDqBoie/VRNPpUvc+UDlfCM6XU2BMhjVik/AmdFk4+AFTGVcCyTUfW4GvW1E8jOfI8vRbR7gxvEorC907CtJ2JdQDEBBzYHzG+flyC9uVIK0eJzcP7INAa1JeIq74f8f0fdUkS8QmOrCOWM5yituS5lUoyzfP3WHAlmK5Kl9oFlLMHY7/LbtHAnOi6G1Ra+CFRquvZ9UOTjaohTBem3h31Ksk80gijQToVhenao5JG4nLF5kfpLcFEZmX8f1bAKTvmgR/CyD8QLDTUC8ZBnUpV/FKnNvN5Lkc31xgFzGi8IE1t8OwMD9OJrmv0r1kqkehhbYTlKBDFaRtYvfetyDmIjkE7UpGF99MwnMi4SVyae4JQpa5LwTk+G0VGTq88SDZllIXlZ9Z9yo5KB4KIAWsQjtuJb1mlByeG2VJP1VqsrngHEpaVOuarL//FYiWt3MJhw8a r93T8tvD Ep/6GuKJy2ij7xaMpBQEfO6fJCHOVL09h+abLS12JJZJv/nxgyYafsBHIKppPaB4+DGqjVaHecGRArrEzfndDT5B0t9HYoEMvo6Lei/vuJRCAh+BzNfe5FKPDRoQx+FK+/fhPKyGbArvMrb+32lS8jooQ0ioJSdbhOOIt6107XIGBoLarOYdgCIv93v1xjse1twKzGQdvhT9slRRHjC+Zi844MpQre5ULasPxgEXqUBN5Gw0GwresMexUx2urCUIYwwQ5Z6ALRpE2mquV6DXvMgA93UXZCaL5+DEXtpk7Idw9M6ze0tv5QnwOw1ndSpp6Qk9VQe06o0/Nvi3ZI5FgbhWxZ6CHqTu1+g93zSj4xjAh6ujzAYL+OBD/ulWqvsWkVVym86T2HiUx/y1QeJSKTq0ZDGyfEFLfXWzCJn4G1zToRgoFYncnQOAYHJHFPlcMWfsRaXQatU8k5r6Sh1PR2ACAl70e5sOnxPGF2Hg5C9klLV6BN3ZTpYKkNw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000626, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: kiocb_invalidate_pages() is useful for the write path, however not everything is backed by kiocb and we want to reuse the function for bio based discard implementation. Extract and and reuse a new helper called filemap_invalidate_pages(), which takes a argument indicating whether it should be non-blocking and might return -EAGAIN. Signed-off-by: Pavel Begunkov --- include/linux/pagemap.h | 2 ++ mm/filemap.c | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index d9c7edb6422b..e39c3a7ce33c 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -32,6 +32,8 @@ int invalidate_inode_pages2_range(struct address_space *mapping, pgoff_t start, pgoff_t end); int kiocb_invalidate_pages(struct kiocb *iocb, size_t count); void kiocb_invalidate_post_direct_write(struct kiocb *iocb, size_t count); +int filemap_invalidate_pages(struct address_space *mapping, + loff_t pos, loff_t end, bool nowait); int write_inode_now(struct inode *, int sync); int filemap_fdatawrite(struct address_space *); diff --git a/mm/filemap.c b/mm/filemap.c index d62150418b91..74baec119239 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2712,14 +2712,12 @@ int kiocb_write_and_wait(struct kiocb *iocb, size_t count) } EXPORT_SYMBOL_GPL(kiocb_write_and_wait); -int kiocb_invalidate_pages(struct kiocb *iocb, size_t count) +int filemap_invalidate_pages(struct address_space *mapping, + loff_t pos, loff_t end, bool nowait) { - struct address_space *mapping = iocb->ki_filp->f_mapping; - loff_t pos = iocb->ki_pos; - loff_t end = pos + count - 1; int ret; - if (iocb->ki_flags & IOCB_NOWAIT) { + if (nowait) { /* we could block if there are any pages in the range */ if (filemap_range_has_page(mapping, pos, end)) return -EAGAIN; @@ -2738,6 +2736,16 @@ int kiocb_invalidate_pages(struct kiocb *iocb, size_t count) return invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT, end >> PAGE_SHIFT); } + +int kiocb_invalidate_pages(struct kiocb *iocb, size_t count) +{ + struct address_space *mapping = iocb->ki_filp->f_mapping; + loff_t pos = iocb->ki_pos; + loff_t end = pos + count - 1; + + return filemap_invalidate_pages(mapping, pos, end, + iocb->ki_flags & IOCB_NOWAIT); +} EXPORT_SYMBOL_GPL(kiocb_invalidate_pages); /** From patchwork Thu Aug 22 03:35:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13772577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 915D1C3DA4A for ; Thu, 22 Aug 2024 03:35:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73A536B0147; Wed, 21 Aug 2024 23:35:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EB4F6B0255; Wed, 21 Aug 2024 23:35:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53BF56B0257; Wed, 21 Aug 2024 23:35:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 33F236B0147 for ; Wed, 21 Aug 2024 23:35:44 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DE0EA160435 for ; Thu, 22 Aug 2024 03:35:43 +0000 (UTC) X-FDA: 82478466966.10.57D1BE2 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by imf09.hostedemail.com (Postfix) with ESMTP id 063B5140021 for ; Thu, 22 Aug 2024 03:35:41 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=azA4TXDm; spf=pass (imf09.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.221.42 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724297635; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=G7yUgVOy5MpRKfji6spWllEFui/I+HP/hnabDQ6U+Y0=; b=F2g1FWmlUSHdpjZ8bN5sxIfHPOc5cjW+y/D6biZVQdgRgNyEI31M8Vjr7QrnUpfk668bEd y3POZHYUGN6QcYpZQmsVctqjAg5U45GAAHuDwP/Q4LOTlnCY5aISwYVotRJrLFHmtEWnOK e8h4k98xsS89ozSQJk3ddpuUmDAGUsU= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=azA4TXDm; spf=pass (imf09.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.221.42 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724297635; a=rsa-sha256; cv=none; b=ho1qANuFMfUSRBp6wpkFqa6UUe8mU+YFaP6tHKdPCfvD71u0m5yrviZCcq5UpJv/9jym/o Jvy3oIie6FoMyCiONIiey4DipxssBZ/WElOgp1WKjePETN2gYTFRsRlUGCyv/84qNyHLhl /p92pt3Ht/36ZY6rSw92Un7sa4JeX6o= Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-371bb8322b2so137097f8f.0 for ; Wed, 21 Aug 2024 20:35:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724297740; x=1724902540; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G7yUgVOy5MpRKfji6spWllEFui/I+HP/hnabDQ6U+Y0=; b=azA4TXDmNUZk2Dikgs8i3q07xrrPWpsbTvfg70EkmccV7KBG+eihChSl3jGVyLMs+1 w5jFvNLhGzL8kpenzRnOcADF6Ez1yHBINunnYmkiaN4XbFc7vmeTXCHwHk8YUFRIc7mC mz5MhCbBy5fNtDSd951t50aaFzlFsX+twD8uEb18bf+u5WkpH0FKJakGCAyYzHNBME4u 2y1+e26XGMARJCjLbU9UONEqQDoZDByPVz3J9nCa0llQ7FC1afY4OcPX+XPqrPrMUXNO ofXjBzONemP3HWRyP9NESDZOHc/qFDuuKojR5Xg4S08leOBOSTwwH5rLhog/6JiYusA5 AmrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724297740; x=1724902540; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G7yUgVOy5MpRKfji6spWllEFui/I+HP/hnabDQ6U+Y0=; b=V5HHolbyz4rQyeoTGIQGOcPtwIhJd+t/HUBlJwf5E5thQjyrKiAlXskrius6Lply4u xGvqDOXogcA33ltKpPivNvJmnlg16mHPwwMu5fLfxeJK7GYckmridIBuU0oHmGRxt4Dh v4aPm6Quao2tG0zDSwvggbVkIB0b93RXdGcNpdG5U6f3jY4pdtS0mJWAJqWvAGwEElT+ A93l6q7l+42dF9oJfzpcBcFX1Z7SXFj6SBHyrYq5Q1MO6IhDl4d+VV6Aks54K+ky5uGC 0FtY4NM10J1JY8qZm7wS97hnjewFlRFogquJOsulBK7i96rxg3NPqfQpzPmT1se+F58M mo+A== X-Forwarded-Encrypted: i=1; AJvYcCWjQalw4A7HISMSYJPPw6rUIgtebs5iw7Lgmii1kIu/gvtADa8SX3ucRe7FuXj+LNctzojKBx/vOA==@kvack.org X-Gm-Message-State: AOJu0YzgPM9x4krLrfCCjpFKQvGn8MN7sxOanNlXXc5Npziw/UFb9lDX EWBfBrthvUDbGfnll9E+ByneKFvpBmUx1LgeTq2Fisj35FqML7N1 X-Google-Smtp-Source: AGHT+IFHlvWFFCxl8YjFlJaGHJvsG1W8kc3fcAPScv4ZmRwi4I8WRIgqdUzhutwlfp/55qdQx9eetw== X-Received: by 2002:a5d:4487:0:b0:365:aec0:e191 with SMTP id ffacd0b85a97d-373052b4b25mr815314f8f.21.1724297740108; Wed, 21 Aug 2024 20:35:40 -0700 (PDT) Received: from 127.0.0.1localhost ([148.252.128.6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42abefc626fsm45491995e9.31.2024.08.21.20.35.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 20:35:39 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Conrad Meyer , linux-block@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 4/7] block: introduce blk_validate_write() Date: Thu, 22 Aug 2024 04:35:54 +0100 Message-ID: <2ef85c782997ad40e923e7640039e0c7795e19da.1724297388.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 063B5140021 X-Stat-Signature: za15dizf9fc5tashiaa5m6k8a7rpexsr X-Rspam-User: X-HE-Tag: 1724297741-27151 X-HE-Meta: U2FsdGVkX1/rN3MF1cjCLIUxjADcKg7vDRzu26bUNSx642ntKe4iot0dOdw2sZzAVd9XHia7cOWfe9rYqMiMltCysNXQNSjBDms/+unQGGqF7mty216mC0Q+5StYv2dAygKZJoigA95nL9ySr115GjV5wqpWSjzS1mCPI+KUAUWo/EsvVp8lXSm41nehubM3clyWA3u3PIJicYzoG5VdClU4+cvKMCiZmE9YxDP/KeOmz9SgBHLstGLZFuXHmZAmxqPq1B4cpl6n8EGd9HZaTGk4yvH9/jN3vs98aGDtDCh9z9V2dS6L+xO3m7VbnPA80J/TTJRRFOpVxY1FxVEil7HC3pm45UrxXBnkkVwQWUGP0tVxtRIQoyF3xT/95GCV0qWMbTiEhg/yQCGSOAEJN0vA7gI18NzJCXfh8CoSbn5NPo0m4l6pwgM5yXplR1/dMKD8hQXVsRDAX/DgkVoeLltO4RBm5qsv0KfLO+QwJziAYuyBxRmmh2PqL7FXYvf544gIDiDaGIGR/DWx769+VXkdWIxbEftidsEbd/KNsNgUn/UG0QcrVTdhPa3L/oSaBenW/Tstfdt8vYwwdAMnuOTLTPET/zjAYbpov0MGgLjYuC9xEX2GyS+x73iKqtYPTdzxbWe+1rc0JQnr4HYYMq3eJEvE9PyfmMswbP+eVmYPgOFnp6AY3ucvK+DGRY0rcbzyNijs4fVfFz9NHR2mshfF/NQNnhCYIZP67uNxt1f11m97d9ROk8MwzX9IkVh/7CLMwrfCy/rV+eBVud5cIPE5Ip1r8LQK/5jLCYZbdsFZbC+O1OXsLbF0W/KcbPw5Khrp/0QMNG6RX1GfdWTIGkq3Kyw0L4aNYTnib10XaGjjyBIB7hXwHbj/+8Qss3eQTFnncRy+PwmaYqCWBlY97KvKRZxYTCKM13fE5EWf39WcXz1AcWDRW3EjAL8pJv4jNUoofJYEphTtX9ngITK JBaGzxdL 8Nfyq038ORt9ghkgs1Lg+kVDW42bEBQSOZvN8JhQL/c3XxTWhhRXHmnPFOh/HRmOsMxoDf+UOaMxJH20dq8AIfZ4R7nVlqy7RXu2qD3OcHMt4jC5RQYE2YZzmilpkTRb68+WBpXPwbUOpSwnoL/WH/ZMliZDwSye8ODIBYXSO4KGQi6kPLQbj7Eb0lCpZ8j2NCUVtTGEZR326WYpEJMzE5HS0KeBu4LJDeLEaFCD0BetBlUBK30MdENNdy5b8ISWJjp7n07yMmvDqpes0aZmZ9ZvPvxbsG65LrROGwFZFTXu0ZO62akUUL1yvEEbv47vj+doorbihzyApYAqOTs6XMhdK5ulXzkKUTWf69y04XfoTEpTpU1B+ZWc1kTYNzvhFNYbho/XDeA+6w265FlumNC+IM789W8sZnp9PmAj33Ta1pngsNjgj+/vxmxEkLvrq66NeZGXuQvFrSTL/ufN+4XWR32Qh1qBbAbl6p22z+qSogq086ajJ+TL+Hw== 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: List-Subscribe: List-Unsubscribe: In preparation to further changes extract a helper function out of blk_ioctl_discard() that validates if it's allowed to do a write-like operation for the given range. Signed-off-by: Pavel Begunkov --- block/ioctl.c | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/block/ioctl.c b/block/ioctl.c index e8e4a4190f18..8df0bc8002f5 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -92,38 +92,49 @@ static int compat_blkpg_ioctl(struct block_device *bdev, } #endif +static int blk_validate_write(struct block_device *bdev, blk_mode_t mode, + uint64_t start, uint64_t len) +{ + unsigned int bs_mask; + uint64_t end; + + if (!(mode & BLK_OPEN_WRITE)) + return -EBADF; + if (bdev_read_only(bdev)) + return -EPERM; + + bs_mask = bdev_logical_block_size(bdev) - 1; + if ((start | len) & bs_mask) + return -EINVAL; + if (!len) + return -EINVAL; + + if (check_add_overflow(start, len, &end) || end > bdev_nr_bytes(bdev)) + return -EINVAL; + + return 0; +} + static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode, unsigned long arg) { - unsigned int bs_mask = bdev_logical_block_size(bdev) - 1; - uint64_t range[2], start, len, end; + uint64_t range[2], start, len; struct bio *prev = NULL, *bio; sector_t sector, nr_sects; struct blk_plug plug; int err; - if (!(mode & BLK_OPEN_WRITE)) - return -EBADF; - - if (!bdev_max_discard_sectors(bdev)) - return -EOPNOTSUPP; - if (bdev_read_only(bdev)) - return -EPERM; - if (copy_from_user(range, (void __user *)arg, sizeof(range))) return -EFAULT; - start = range[0]; len = range[1]; - if (!len) - return -EINVAL; - if ((start | len) & bs_mask) - return -EINVAL; + if (!bdev_max_discard_sectors(bdev)) + return -EOPNOTSUPP; - if (check_add_overflow(start, len, &end) || - end > bdev_nr_bytes(bdev)) - return -EINVAL; + err = blk_validate_write(bdev, mode, start, len); + if (err) + return err; filemap_invalidate_lock(bdev->bd_mapping); err = truncate_bdev_range(bdev, mode, start, start + len - 1); From patchwork Thu Aug 22 03:35:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13772578 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD281C3DA4A for ; Thu, 22 Aug 2024 03:35:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5944D6B025B; Wed, 21 Aug 2024 23:35:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 53B246B0296; Wed, 21 Aug 2024 23:35:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B71E6B0297; Wed, 21 Aug 2024 23:35:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 197F16B025B for ; Wed, 21 Aug 2024 23:35:45 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C19BB4048D for ; Thu, 22 Aug 2024 03:35:44 +0000 (UTC) X-FDA: 82478467008.01.72244CD Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by imf25.hostedemail.com (Postfix) with ESMTP id CE5CEA0004 for ; Thu, 22 Aug 2024 03:35:42 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IYeKNGto; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.221.43 as permitted sender) smtp.mailfrom=asml.silence@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724297677; a=rsa-sha256; cv=none; b=oDZCmGo2qXzkF6RiR5x3R0oe2b8IovdqnECnagS81wxdPKyQiMxOZPwdJfye5AhcqoGFlk kZuqiaB3pM1pTlf1wQ3EzuHzhlEj6TQofr5NsaC9YigOtwR80pORJNHin5votYQ6jHmfGv 4/PkwChSIUfDSZIyqtYO8hH5i3H614I= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IYeKNGto; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.221.43 as permitted sender) smtp.mailfrom=asml.silence@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724297677; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qGj49BU9lgDQwY8mNGLmILE2ejA/5ZP33Z20PIIjLDo=; b=yMg9yy+/VyuYGo0zw9g4Az/kYOjkRWQg/9jHk6GTqYrRY7VBCsmIq5MgHWxGXF8NvMFxxQ eku+AkfgZRmIpmEw134tFsc4zELXv9JXN9iyXBCTZni97lnHJMgLCcjpNJwzY7LDM3YHXo hLSiNWzDq1lApc6vvSLpHUJC6yv2viQ= Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3718706cf8aso110251f8f.3 for ; Wed, 21 Aug 2024 20:35:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724297741; x=1724902541; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qGj49BU9lgDQwY8mNGLmILE2ejA/5ZP33Z20PIIjLDo=; b=IYeKNGtomNALHsb1s7Abxy7L9WaNLV5nGr4hFLeEGcs8nnfRhfYMvCxD7iVi/QFwJq zY+3MExniQTBiyB/mUSpHkqFWKqQZiN6I5Fn0PtKGjNE2FQX8o6oNR4Rw9oGXRUKXOcr y51I4LYP6k54l39E1QKDeYBCUzBsUiws+xLS66PjDokp51QFbE/wSLmf8c6x7nWp9HEz KpN2N6pqWN1n0ZvplbUUol86ei7o5dNrF5btwnKjI4qqYWJ4rLyGNdn9H6M4BaUSIEvr fhZYmBJDYg9af78x18KfeWWT44UCoem/UbCt6mcRQH8ZDnTrdv+RIwsgYfEhD3IM/fNQ QVWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724297741; x=1724902541; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qGj49BU9lgDQwY8mNGLmILE2ejA/5ZP33Z20PIIjLDo=; b=Iz7o5ZvwlJYACMw0wiIKeG4vTXACs11cstX6+SUv0N7HvMJOeDKtrj0Ava1sAf5kKx YTAYVrQNK1pVELQlcwrNFCVsu9KTay95cMWIPuK4Cz1sAZCSigGahZuDhqmDmyMuwop2 i8ZeiQmHO/1x2L3xZOeaKGJC2R1mLVtOlafSnkMz/cngcIx6Ig/okWPHR0uRe19Wmgav MMNHvGvnBP8/hU4y3cYIjKoP30lfrnZmffkBlb16H2pdzcewjURKdtmxga2qxCBmgtq0 LdCIOBC32GQwyxv+7js19OXuYNd0E/NpDPZ0qppaV8neXLST5t2CuyLicVwlGB3T9B/I n4YA== X-Forwarded-Encrypted: i=1; AJvYcCWu/IG+9zdSn6nlyOGXDCYNsjSnItjWLkfwUZ0XjVi0w9NQXtYYIlu5mgihkVxvOIJmnsNbrnz69A==@kvack.org X-Gm-Message-State: AOJu0Yw8CtTw3GPZm17kiWQRJwUOnWl7qotkJueKfOmmOa3YIVkxNFUO sUt6gzwjTSNQ/DM2hYanWe77y86blIZCvSEt4timfKD9VcUmjgNgnltBEA== X-Google-Smtp-Source: AGHT+IEgmvrrHLtdXgyQgbBcddGUU2deWM/qRpnDz7MB2b3ub/DdWnFYjjz5OkIhJ7k2yrrWHOHjOg== X-Received: by 2002:adf:cd8a:0:b0:368:310d:c383 with SMTP id ffacd0b85a97d-37308c08adcmr230595f8f.5.1724297741164; Wed, 21 Aug 2024 20:35:41 -0700 (PDT) Received: from 127.0.0.1localhost ([148.252.128.6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42abefc626fsm45491995e9.31.2024.08.21.20.35.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 20:35:40 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Conrad Meyer , linux-block@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 5/7] block: implement async discard as io_uring cmd Date: Thu, 22 Aug 2024 04:35:55 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: CE5CEA0004 X-Stat-Signature: kwg9jf55e4huoke8yefe7mumoo19dewo X-Rspam-User: X-HE-Tag: 1724297742-110963 X-HE-Meta: U2FsdGVkX1/QcAi7eljI/3iN3Yoh9juiXrFK9fWy9oncanShKuICH4KEsJyhPokRjJoGPtbC6pWtx6+1v04cY6l2dsZxgChB8Og2ZQstdrHG7dYK9MrcZmLTd36zpNpy0SLRt6z/j0Bf4PC4Y/BV0Hdi5WQto19anM5cj4adUMuM9otBp7e40dCkqz/lsmcJm4BdkkKJ53+U5XF/XUMd/2PJIgyREEogTzcb/XLsUqk8M8IpaS3WEBLUQf2eLm+aLqG1YProE/mDCO18ydZqv7HStCtpRrgWD0OqdMCJ1cu0zjCzKnlMPEpS5k5NBvKT2aqZNQ34ic3CWRXwc+nlplc4CBhCJcb9aYcZXAmEi13SMiWrTR50B23QNvGza1FfusaDAlbHXAyfaKYiR3ZFYnw+1KdKhlfeMhbD/nE2vA9cF3BMveGE0w5ru70Mh1Ad0EPL69Ul059ELtTpER8zFqGsLq4atorE8XVWIBJZnvgBvafpgc03LBnuN/skFEDGwFoNBfo7jOu5nzPQWCoH37Dr9Kt7Kd5e8RCrDmVS7XR4EDvJXeKwcHaf3LfX2Z6GYlLVavH+9+VIwOLIKlFv2Efxw3kOGmjeDpTyMEfQW9ExUQ7LJNJReI032bWvqEd0evkw1/zJoTULbIKMNJvU3nRxM2Wpbalod2mU/i5ELdr2RdCFvuSN5UjWx3M5vlKI83P9Aew8p5k/Vk5KAlmt/j/w79OYMs8/BfzmnmrG4T1H4RX7MLAfJpLgBOQGZE9eVc6MiuvaWI52o0U9KeGfrBf/lKLDyCFXW2y9Q+dlPxDzrv5Py182O4vQNzLEJHi5f+bBY5cW8Lb5cMGM7d7LPkE529SiZs+OlB0pqB4xrvSVlU1hUlJwJxt+3Iae5JO+eHkjpYvUuyj7z8xrxz0XacBL9zaw6XNqIchsn2yz9uHDMA3NlRzOXvGXe0unli1QmPoWqY/F7+QVQR3Bjgy ZuX4J+7V UI8f06U3VdYV1w2/DiE0b6OJjbp+5usyKuD6ExLO6nSRpO5NrVzWJ0N4tkqRMfKBNt2SJclXlDNL80vrCwWc6QBTb13N/mmFe5ELSj3xrEiWaRyJXov3ISisyy8I5ORNZru34Obvoa6hTD9JTizpL270M54BKv2rWZpZATWyNgAyPk3DS/5KO7TxR2ta/BRKQqLwMSsK2n1yeM7txkAM6XlmIvx9ddJdflLf4WFEoE/SJAUh49w/pwebSvZVBiWMj8JbMG3DD5P1kKTQ6/GLpYpE4eHUftyJCmLI5dxck2KSLbEnqsWTzShW2apH2iINukssza/OuerNpF3h5nOd6w1zZlD+JIyGjlyecpPN4XzBa8X+KycRLpKhrwZKEIdi4UwpqFY9DT55dyejLTaWjon+QsIvdl23CkYZ0fLNytIBA86+mwJsy6Dxn3FRz15m7sGLXU1tXg0s2yoVAROuCZxVg/gZsCTge+XanFHQkm40+c6Q66mHM2qJVcNUcmLAcBKVuJUjcqir6ckRE27+fZfmfxK9ZOuPS8iJo+9eL/FK6YxKcMbOi4OKbnw== 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: List-Subscribe: List-Unsubscribe: io_uring allows to implement custom file specific operations via fops->uring_cmd callback. Use it to wire up asynchronous discard commands. Normally, first it tries to do a non-blocking issue, and if fails we'd retry from a blocking context by returning -EAGAIN to core io_uring. Note, unlike ioctl(BLKDISCARD) with stronger guarantees against races, we only do a best effort attempt to invalidate page cache, and it can race with any writes and reads and leave page cache stale. It's the same kind of races we allow to direct writes. Suggested-by: Conrad Meyer Signed-off-by: Pavel Begunkov --- block/blk.h | 1 + block/fops.c | 2 + block/ioctl.c | 101 ++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/fs.h | 2 + 4 files changed, 106 insertions(+) diff --git a/block/blk.h b/block/blk.h index e180863f918b..5178c5ba6852 100644 --- a/block/blk.h +++ b/block/blk.h @@ -571,6 +571,7 @@ blk_mode_t file_to_blk_mode(struct file *file); int truncate_bdev_range(struct block_device *bdev, blk_mode_t mode, loff_t lstart, loff_t lend); long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg); +int blkdev_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags); long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg); extern const struct address_space_operations def_blk_aops; diff --git a/block/fops.c b/block/fops.c index 9825c1713a49..8154b10b5abf 100644 --- a/block/fops.c +++ b/block/fops.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "blk.h" static inline struct inode *bdev_file_inode(struct file *file) @@ -873,6 +874,7 @@ const struct file_operations def_blk_fops = { .splice_read = filemap_splice_read, .splice_write = iter_file_splice_write, .fallocate = blkdev_fallocate, + .uring_cmd = blkdev_uring_cmd, .fop_flags = FOP_BUFFER_RASYNC, }; diff --git a/block/ioctl.c b/block/ioctl.c index 8df0bc8002f5..a9aaa7cb7f73 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include "blk.h" static int blkpg_do_ioctl(struct block_device *bdev, @@ -745,3 +747,102 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) return ret; } #endif + +struct blk_cmd { + blk_status_t status; + bool nowait; +}; + +static void blk_cmd_complete(struct io_uring_cmd *cmd, unsigned int issue_flags) +{ + struct blk_cmd *bc = io_uring_cmd_to_pdu(cmd, struct blk_cmd); + int res = blk_status_to_errno(bc->status); + + if (res == -EAGAIN && bc->nowait) + io_uring_cmd_issue_blocking(cmd); + else + io_uring_cmd_done(cmd, res, 0, issue_flags); +} + +static void bio_cmd_end(struct bio *bio) +{ + struct io_uring_cmd *cmd = bio->bi_private; + struct blk_cmd *bc = io_uring_cmd_to_pdu(cmd, struct blk_cmd); + + if (unlikely(bio->bi_status) && !bc->status) + bc->status = bio->bi_status; + + io_uring_cmd_do_in_task_lazy(cmd, blk_cmd_complete); + bio_put(bio); +} + +static int blkdev_cmd_discard(struct io_uring_cmd *cmd, + struct block_device *bdev, + uint64_t start, uint64_t len, bool nowait) +{ + sector_t sector = start >> SECTOR_SHIFT; + sector_t nr_sects = len >> SECTOR_SHIFT; + struct bio *prev = NULL, *bio; + int err; + + if (!bdev_max_discard_sectors(bdev)) + return -EOPNOTSUPP; + + err = blk_validate_write(bdev, file_to_blk_mode(cmd->file), start, len); + if (err) + return err; + err = filemap_invalidate_pages(bdev->bd_mapping, start, + start + len - 1, nowait); + if (err) + return err; + + while ((bio = blk_alloc_discard_bio(bdev, §or, &nr_sects, + GFP_KERNEL))) { + if (nowait) { + /* + * Don't allow multi-bio non-blocking submissions as + * subsequent bios may fail but we won't get direct + * feedback about that. Normally, the caller should + * retry from a blocking context. + */ + if (unlikely(nr_sects)) { + bio_put(bio); + return -EAGAIN; + } + bio->bi_opf |= REQ_NOWAIT; + } + prev = bio_chain_and_submit(prev, bio); + } + if (!prev) + return -EFAULT; + + prev->bi_private = cmd; + prev->bi_end_io = bio_cmd_end; + submit_bio(prev); + return -EIOCBQUEUED; +} + +int blkdev_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags) +{ + struct block_device *bdev = I_BDEV(cmd->file->f_mapping->host); + struct blk_cmd *bc = io_uring_cmd_to_pdu(cmd, struct blk_cmd); + const struct io_uring_sqe *sqe = cmd->sqe; + u32 cmd_op = cmd->cmd_op; + uint64_t start, len; + + if (unlikely(sqe->ioprio || sqe->__pad1 || sqe->len || + sqe->rw_flags || sqe->file_index)) + return -EINVAL; + + bc->status = BLK_STS_OK; + bc->nowait = issue_flags & IO_URING_F_NONBLOCK; + + start = READ_ONCE(sqe->addr); + len = READ_ONCE(sqe->addr3); + + switch (cmd_op) { + case BLOCK_URING_CMD_DISCARD: + return blkdev_cmd_discard(cmd, bdev, start, len, bc->nowait); + } + return -EINVAL; +} diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 753971770733..0016e38ed33c 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -208,6 +208,8 @@ struct fsxattr { * (see uapi/linux/blkzoned.h) */ +#define BLOCK_URING_CMD_DISCARD 0 + #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ #define FIBMAP _IO(0x00,1) /* bmap access */ #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */ From patchwork Thu Aug 22 03:35:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13772579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2881AC3DA4A for ; Thu, 22 Aug 2024 03:35:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E8E566B0298; Wed, 21 Aug 2024 23:35:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E3F466B029A; Wed, 21 Aug 2024 23:35:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C423A6B029B; Wed, 21 Aug 2024 23:35:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A262B6B0298 for ; Wed, 21 Aug 2024 23:35:46 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5F1F2406A3 for ; Thu, 22 Aug 2024 03:35:46 +0000 (UTC) X-FDA: 82478467092.26.5A50CC5 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by imf09.hostedemail.com (Postfix) with ESMTP id 84464140017 for ; Thu, 22 Aug 2024 03:35:44 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="dEdh/28j"; spf=pass (imf09.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.128.44 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724297728; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PVhT9OqiSkRhkZBmbxRRu3VwPAT0F6C3XigyZkc8g4k=; b=Z2/FQ6Z/tLZhutWiReS6BqcK5QPnHElbhwQUUOaQ6UQQTFDfVloQxJpIRyccNa4PxJ9poe fSt7vnxuHenuEX9JHPAicfV6pd/yX7EWdRwW52aKJ7zpYugFZUa2pFaS3Rngx/hh5KcJP7 3xghrkju89PjdWPEXA73EDsr/VRhiIs= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="dEdh/28j"; spf=pass (imf09.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.128.44 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724297728; a=rsa-sha256; cv=none; b=51X48Nk7JLDjRwsjonwcvs7bnDoJPYN7erekkgTd6VH9bo75V9XoSl9NRaptezhL8m6zon 1Jk9lisLANDxusnO9OgKrqSPbMW7FiWhJ9cWvu6eFBIUjG35h9R2OAb44bj84WmxKAcsIN hLx6YCB6OAsznSaeJsN1cVuTzY+5TqE= Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-42816ca782dso1737395e9.2 for ; Wed, 21 Aug 2024 20:35:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724297743; x=1724902543; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PVhT9OqiSkRhkZBmbxRRu3VwPAT0F6C3XigyZkc8g4k=; b=dEdh/28jEeuPmlWp8R4w2Tj6LeB8ub9i3qg1hsy4PxPjUA7K4IMSAWWlXOiqQqeZmb ehcq9Xw/6SSX55KQb/yaKNOUUHzmVOANITzfN+2mgfr7o+M4GIEe8GDQ7IamP+Ppj/lJ 6BUsl8Go7KxeEBEcj+gIJDCW2a+iW2goADnC6/MkIJZRgx8qEo1+dZdiGbsCQssBGpK6 kbqvCsWTwpQYR+vtU7QlTcFCl3vXJv0Ocx0PjzP9tnzh4VguNEqdcXzHSEMj+hzmcsyl /L9GSnK4q81kCikfj85PhFfCmNQXWlpJm9iNjwpXWHvKcqNaVqKBRJiP8T0u/4oxnFEc ETTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724297743; x=1724902543; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PVhT9OqiSkRhkZBmbxRRu3VwPAT0F6C3XigyZkc8g4k=; b=MtOg8REYymDxWiXloFYYQUofsecRkuzbDEOj0vj7UWzrBRMfCcsdRRtB3J94PZD4k+ a6lsDUaLMZPiGul0t+R4hi81AOmn1Xjg4seLClKV9zdxDmfousgkpuC2a8qeO6by70cU B8jZweBjaL5Z9o1e9azpnuSedh3402cA4roSt2LLGvTC0oLoPv+kohRihIQlahGZOQH8 QZtQSm85Go3d8+3ht1dfO3KDyS+25vrJwQdza63Xky7CNWaE+foSU37BiQ9rMRwOpFeg Txw12X0XoMUiml4FixzljTqTmB5dOuAyWFCOfsU3jXyPhPnopJW+uiD7eMqFlfgr1M4R UMpw== X-Forwarded-Encrypted: i=1; AJvYcCVTNN5fxUa+/Xjeafy29ilW0fuDk4LxPHeE+D7V2ndpKN8TCaHhf8zBPSHpBijUn0b8e8IPwsyq5Q==@kvack.org X-Gm-Message-State: AOJu0YylA+Y1NY3Sqolza35JORNZoxQiSJuyowLxCsCHruRETGFVplHw +ddRXk+ULQFeFu4y2lZa7bS/wOuroC6Do3u3hWUeM1lTLAo8AB30 X-Google-Smtp-Source: AGHT+IHqvEt/onVyk5pfq2MvnE1mDsVk/iF7QUbNipDxcqrMgadYUmb8t6sc6QQq2b3aRAiZt2CaSw== X-Received: by 2002:a05:600c:4ed2:b0:426:5440:854a with SMTP id 5b1f17b1804b1-42abd21f727mr28548505e9.1.1724297742468; Wed, 21 Aug 2024 20:35:42 -0700 (PDT) Received: from 127.0.0.1localhost ([148.252.128.6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42abefc626fsm45491995e9.31.2024.08.21.20.35.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 20:35:41 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Conrad Meyer , linux-block@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 6/7] block: implement async wire write zeroes Date: Thu, 22 Aug 2024 04:35:56 +0100 Message-ID: <09c5ef75c04c17ee2fd551da50fc9aae3bfce50a.1724297388.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 8p6rte9twnb6jmxcopgri7meubit9bst X-Rspamd-Queue-Id: 84464140017 X-Rspamd-Server: rspam11 X-HE-Tag: 1724297744-6112 X-HE-Meta: U2FsdGVkX1+Hj1C2638BW5HHz5o544A61gthkzAAtc0eRbspORDMQbXDTMguGoh6/DRK8+PUAdoFQTB1a4CQnWD9PQPASt9P1801lvIBYBdZpyukXTcEp0i0hgGngBoPWog3eoBX7GRVIrYIP0SIpnlVlBlHUXCIXcyry/2KmJF+SYW92RBtqqWIGGUe76/AqcLZSSAwj9/Wai8tCn94JfTWM0D6NxTyyhOuS5H+vrRY81LW0NUIkATBCS7QyvRsvNXx3JqhcHjZJbuOv30PMSubGYVnCc9zvjTebm9L3Jlfb2zXI2J67wTvlgpvU6YS8jsutQhkgbt3J1XCdcTN0FtEdNJGypmfCnALh1NY+poXTqpiioFAnrwLJcEEvtAUeYcxTrf50hTBRQjj/AqZcKic3yiVDd6qUg5rOKxIjS5i44J/iHu5LP1gkzkdgrTG7hc0n5GIDUslKOv48i4oKLUGc7y2+KBaKJW8twq4l775lK29RnxymjqCwZWjkPoUM6VmUBEoMk+DFAcNMHUbtACVBvEAHZAlld3JqR4CLSy36FBzJeg3h5LiRuGCw9w/aGvWuhCVa7WKIXbXPfQvvcgg0ugOcIPTTYrR+2txY1xrIvOM5rMF7U3dwk8S0IHD7xWTKmlU5I4JA24rt/GX7MJQUejldD3DCTH9mxnWS5ph1ngvA/tAb76g1mkxFZialAmXR/mF3Vkxn6q9fIfTFiTXvjBaQPq7NbKQyQGfFGmGV5pdKwyssbeEWZxv/Jp4CuVJTUzpvxI8+SA8RjltTj+R5riIEU1pRcGoATKvSE+GKTSjOrH1/+UHCmcGedRWI2o605MiN+XKKFDHnta/9oYzXeqc3tF13pbPviF79M2clKkTsIyQSNlKzHnc8VhcjhX3tKxxxVeLA0gWepnPjZSTmzUyrqW47QIvN9bHkRPwCSEwbsPH5RqZruf70Mi5SeJ1E9En1Dhy9qE0Eof FbBNKY3o 3bN1uEh+CNJ+e8tRrms6/FewwmuHrJ1VVv2ZE0+xTPzaSMELShC0Cb//FgihGGud27RNukzjoC5+iej2LxG8oBCz5NUzqPv9YbPgR7/iSJZAYFzGjbplvd7T/TCszhIu1shLkzxYFbW3xIJU4SXC74MioEdSUPFR1CWAFkySEu2t1871xydeoqJutakD1eRU3asdLI6+7D7X2j73BrYF/8VwMnnNTHxkrkBf8wC15r3uyRm4NXCoCX0qPux47u58AATlcTT6TneUlXI/R0ykyyFa7wsfw7imN62Qsp1Jjt00wQKIJFyb2JL/ZReMa3suQq8mBu8mqIn1m4znyunqPF1PmvkZ4b7hHK8v3jMwtbjQv6YVaP62QfeW9yZ4GehG4IX7vKHQs4+zscpfPdHRdn4sWOaO9J1e2NLMipNzXAClqF35Au9DpX0icppPG++Ym5+x9sJqUqmPzlIKExAkwSiQONIXdzhLiE9Lj1bALwyl2mCvKil9ZtCrLM19yiZ1yM4u5 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: List-Subscribe: List-Unsubscribe: Add another io_uring cmd for block layer implementing asynchronous write zeroes. It reuses helpers we've added for async discards, and inherits the code structure as well as all considerations in regards to page cache races. Suggested-by: Conrad Meyer Signed-off-by: Pavel Begunkov --- block/ioctl.c | 68 +++++++++++++++++++++++++++++++++++++++++ include/linux/blkdev.h | 4 +++ include/uapi/linux/fs.h | 1 + 3 files changed, 73 insertions(+) diff --git a/block/ioctl.c b/block/ioctl.c index a9aaa7cb7f73..6f0676f21e7b 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -776,6 +776,71 @@ static void bio_cmd_end(struct bio *bio) bio_put(bio); } +static int blkdev_queue_cmd(struct io_uring_cmd *cmd, struct block_device *bdev, + uint64_t start, uint64_t len, sector_t limit, + blk_opf_t opf) +{ + sector_t bs_mask = (bdev_logical_block_size(bdev) >> SECTOR_SHIFT) - 1; + sector_t sector = start >> SECTOR_SHIFT; + sector_t nr_sects = len >> SECTOR_SHIFT; + struct bio *prev = NULL, *bio; + int err; + + if (!limit) + return -EOPNOTSUPP; + + err = blk_validate_write(bdev, file_to_blk_mode(cmd->file), start, len); + if (err) + return err; + + err = filemap_invalidate_pages(bdev->bd_mapping, start, + start + len - 1, opf & REQ_NOWAIT); + if (err) + return err; + + limit = min(limit, (UINT_MAX >> SECTOR_SHIFT) & ~bs_mask); + while (nr_sects) { + sector_t bio_sects = min(nr_sects, limit); + + /* + * Don't allow multi-bio non-blocking submissions as subsequent + * bios may fail but we won't get direct feedback about that. + * Normally, the caller should retry from a blocking context. + */ + if ((opf & REQ_NOWAIT) && bio_sects != nr_sects) + return -EAGAIN; + + bio = bio_alloc(bdev, 0, opf, GFP_KERNEL); + if (!bio) + break; + bio->bi_iter.bi_sector = sector; + bio->bi_iter.bi_size = bio_sects << SECTOR_SHIFT; + sector += bio_sects; + nr_sects -= bio_sects; + + prev = bio_chain_and_submit(prev, bio); + } + if (!prev) + return -EFAULT; + + prev->bi_private = cmd; + prev->bi_end_io = bio_cmd_end; + submit_bio(prev); + return -EIOCBQUEUED; +} + +static int blkdev_cmd_write_zeroes(struct io_uring_cmd *cmd, + struct block_device *bdev, + uint64_t start, uint64_t len, bool nowait) +{ + blk_opf_t opf = REQ_OP_WRITE_ZEROES | REQ_NOUNMAP; + + if (nowait) + opf |= REQ_NOWAIT; + return blkdev_queue_cmd(cmd, bdev, start, len, + bdev_write_zeroes_sectors(bdev), opf); +} + static int blkdev_cmd_discard(struct io_uring_cmd *cmd, struct block_device *bdev, uint64_t start, uint64_t len, bool nowait) @@ -843,6 +908,9 @@ int blkdev_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags) switch (cmd_op) { case BLOCK_URING_CMD_DISCARD: return blkdev_cmd_discard(cmd, bdev, start, len, bc->nowait); + case BLOCK_URING_CMD_WRITE_ZEROES: + return blkdev_cmd_write_zeroes(cmd, bdev, start, len, + bc->nowait); } return -EINVAL; } diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index e85ec73a07d5..82bbe1e3e278 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1095,6 +1095,10 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp); +struct bio *blk_alloc_write_zeroes_bio(struct block_device *bdev, + sector_t *sector, sector_t *nr_sects, + gfp_t gfp_mask); + #define BLKDEV_ZERO_NOUNMAP (1 << 0) /* do not free blocks */ #define BLKDEV_ZERO_NOFALLBACK (1 << 1) /* don't write explicit zeroes */ #define BLKDEV_ZERO_KILLABLE (1 << 2) /* interruptible by fatal signals */ diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 0016e38ed33c..b9e20ce57a28 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -209,6 +209,7 @@ struct fsxattr { */ #define BLOCK_URING_CMD_DISCARD 0 +#define BLOCK_URING_CMD_WRITE_ZEROES 1 #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ #define FIBMAP _IO(0x00,1) /* bmap access */ From patchwork Thu Aug 22 03:35:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13772580 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE854C3DA4A for ; Thu, 22 Aug 2024 03:35:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE31C6B029A; Wed, 21 Aug 2024 23:35:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A92BD6B029B; Wed, 21 Aug 2024 23:35:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 95C9F6B029C; Wed, 21 Aug 2024 23:35:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 65EE26B029A for ; Wed, 21 Aug 2024 23:35:47 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 31826A1255 for ; Thu, 22 Aug 2024 03:35:47 +0000 (UTC) X-FDA: 82478467134.19.D19D5CE Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by imf18.hostedemail.com (Postfix) with ESMTP id 53FB51C000F for ; Thu, 22 Aug 2024 03:35:45 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fllHs+yl; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.128.51 as permitted sender) smtp.mailfrom=asml.silence@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724297655; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lswIDLrIj7CXYuFfzAb9ZDGauPy9RK0EG0P/gPYjyms=; b=f179CtbX42JokCSbAdZeRUkd5OnxMjTeCIPgLHvEW0fdhaQpcme38S58xL/YUSpNIexi/p YOjMgu3KXVPCOH0CDakIrqy/oZ+ME3zr8uhR7Qc9MLLgu63BzARFcKUzEjGm+MIiWmtgQM ss6jzZsNwRgzxCAAgvi2QpzdAWS/T6g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724297655; a=rsa-sha256; cv=none; b=DEjuCvAhEaiX54nqIqvcQuLFEWePAWc8O0wOS/M3kt0iVrRUdxWOrVd/wSiBErVoEOqNMH fVgwmVA/qWOJhv5HcOY4MHdu5MAMP+iR4CgeSGYDnfCbotvGkoKiG3r6fdXEm+iUCN84z7 W6dgkoBI9AGwUOiWWh7IGAVClcu5GEs= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fllHs+yl; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.128.51 as permitted sender) smtp.mailfrom=asml.silence@gmail.com Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4280c55e488so1569695e9.0 for ; Wed, 21 Aug 2024 20:35:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724297744; x=1724902544; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lswIDLrIj7CXYuFfzAb9ZDGauPy9RK0EG0P/gPYjyms=; b=fllHs+ylFq3VUT9eK6seYOrZpZP27zf5lcgG0V0eHPmnwIEkLBjtgtNdJlwFQ+RMI5 U9VT6BO/SSn9DNei0hW/Js2gh0CJBxzfeT8ux+zgiEDZqKLQdjVFWhR8gzZOobLwyorH 1+Mk1QH7eQRf+o+VpaTX14OHSv6Gklz9XtoptE8hr7/OnREWsxqZIjq0GZbYNnLgSp7P vWLAOxJ7NbFnpKpGWw0xEuicwWSG+drMVJ+uf2+DIIMZTqpmQAIShcZvNXJauV61DJ6K KgNHMrg/+fIVKqB8eJnp68V/QF4yA8N7netd5Hq9AusAK2G/wgGClgYeKarGMvAy49DN JaFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724297744; x=1724902544; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lswIDLrIj7CXYuFfzAb9ZDGauPy9RK0EG0P/gPYjyms=; b=uqW5Gv4XB3++tx7zHhwV/4KxeiVQN64AHxz4q6u35I1hlyAVke7jXHaWrW2TuCOOPD xZ0qkLSb62QHX9ZZ2T/95V3/mY7eyD9Gvyrda0rvKiKmVF53hzg5OnfRIvZlQO8rjhHl ocnrM+7NVHpRu+/btC6zgh5sE87ULKdEjClHT8cpubEI2dHHBCFLP2V/iC5rLSoIneRn eL39VqCgAEvlQ6KuiKecASxSe91yut8Z24vy3GSW89AKbBCRO9xPKfz0Vudpxcn/bydU WS6lSLzqOHRSRPAEHeMBamjAsadxfGztvKluFcCNUtfMFOfYG7j5thCii6vqijdgzdB3 gCFg== X-Forwarded-Encrypted: i=1; AJvYcCUVTjG8w7lxMn+vass5NICMkqDaqz0A2UUipYtufK2kViM+T3FX/KwNFGzpuPy9s5864Rr7fnGMNQ==@kvack.org X-Gm-Message-State: AOJu0Yx42uHJwht4q/ro2Le7/rW58N7ly8r/Z2Kij82tJrObVCnmQNTt 9FyrL5SPPb9tEKOPwypaPkMoDSSha2NbNFw4R1yZXKwlGmoc18tf X-Google-Smtp-Source: AGHT+IG8hgkDMcLSSneo44THzR5IGgkExEMFh9iktxvoExcbZbFlYFw8o0WlWu1YjpgQLAsbGqHOpQ== X-Received: by 2002:a05:600c:3c9d:b0:428:6ac:426e with SMTP id 5b1f17b1804b1-42ac3899e82mr7892605e9.5.1724297743449; Wed, 21 Aug 2024 20:35:43 -0700 (PDT) Received: from 127.0.0.1localhost ([148.252.128.6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42abefc626fsm45491995e9.31.2024.08.21.20.35.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 20:35:43 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Conrad Meyer , linux-block@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 7/7] block: implement async secure erase Date: Thu, 22 Aug 2024 04:35:57 +0100 Message-ID: <5ee52b6cc60fb3d4ecc3d689a3b30eabf4359dba.1724297388.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 53FB51C000F X-Stat-Signature: trpkyntxwktgeeg1xy3pwjgoquws4kxb X-Rspam-User: X-HE-Tag: 1724297745-613489 X-HE-Meta: U2FsdGVkX19UjJmKP2RZD3IJIgdsq8qnydosKql7Eql01GMjhQjlr4sY0gOeW0zOxSgmQNP62zt5rIRtcVCCweURz5zqFkK0XY3oskPT9DBnDz0DqbkSCldl4RZSol/qdTeC1QAZGblBaTmHUNKhkKmTd/5U+qar0fGdeclt2wGTaeJFsrqQCQ7xcdFg0vCDn+nB+kvBI5GFVEt38E+TddGNHEZBdRn14a15KBS+B4gLCo8/W7O76x6g3MkptYnShmLqreUPiUITb3KmKJNIkLQk/99sFKudgPOj8CB43e5VSxUkxyG9PqS8523jpxWFigXNbih0e+w4yXlxrwIB5meGdQHtJ1Qm6IHOl3yDL4ytYrXXM5IwTgsJguIa85kYsKTBB3GJedrWTvu/F3W1U0eWSmRCRY3V3P2cyNlznxUiXl2Q0738NpAa725vRE9o49c+lfKIALHseZrV27zbnLSAMWvVZ6Q+7eO/f51oMqn21proKym2Fb/tbrcBgjnM2k97KP/x6Kwx/WiyKYxcy+McwEOY4fXlzZB1TVw84jVsG7xeKm3sP8kPNk5XHzuo7khrPvr7oMTiSkbogCOQjC7E1zuqZQwHZm22d6Xsv5gmv4wsEhT+ZNyu1XYFmdhAnLpx8J9gPncxk5rIrPvVmBuTvD9LYv2I5uDAcBDNnOMG5//CHnOl9scvZ2sivUaY3KnBMZl290Odpgz0o70zs4Un2dxBUQQUZFmaAynPbhArtm9dqVH6fgUO3HEH30HnleLtdV5edpQmvb1Aor30YMzqK04bpFH/CSc8Y2VYSdegc3sbu7qzYJCwPTdz2nGwIl1DIjW9vf3pirPMr3twCMPSkVp+UjiuCa/QHtA90r1PTMSiALOUSqXjHfLt8hx5wfEzCJjUfMu6vYeLFSipu41jKfdhCk1l9JTaMFc5mnJyPnT+a3Y5lUUUxCSQMwBGGhDa4NXBaEvPuFYWbBT b0puKDER w4lGI66SYC5kXPjjK5KsS2xiYb7HETYMVLvqtd3Pab/lk6jLVLE+XbwR8pLHpGz7vLlBzfxHBGUr9OWSsjpJXkJ9sTh/yQNjGE42ji+URUfiJShkRzuS4yHb4FrQNVsZYniudrNfYPigg49yy45CJg7BZRnpNKV/OuYM5+xn2x55FC203gBpnUnHH7YhEBa76kwkZuVU83y8XASfEFeEKmEydV3ZtbdAzU667ev8jjHVLRuVepwP8kGwETEgUgBatJ4QASlN679PgHzWzEdxg0RXhd3A9xgifTkvXhkF/vWJjxn+r6WjLWoQa9Q1hU8hNU2EqGTPGggfB5ST8j/eizxz36NfXWCEDutN+zYuCWWZoSiSwgFi3AGrEMRjjjZP2zBHPuyXFz1Mvr9Z5XuGBYgh53i+iiW26GsNoGxT0tnp2Jbhebqu+qRdS91djIttysyOwiJLAPnAASxa/Rurh/i6KDsDMtGzMpkussPZSQKZbIfOaYnO3p4gYKm2S20AyHFXF X-Bogosity: Ham, tests=bogofilter, spamicity=0.000009, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add yet another io_uring cmd implementing async secure erases. It has same page cache races as async discards and write zeroes and reuses the common paths in general. Suggested-by: Conrad Meyer Signed-off-by: Pavel Begunkov --- block/ioctl.c | 15 +++++++++++++++ include/uapi/linux/fs.h | 1 + 2 files changed, 16 insertions(+) diff --git a/block/ioctl.c b/block/ioctl.c index 6f0676f21e7b..ab8bab6ee806 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -841,6 +841,18 @@ static int blkdev_cmd_write_zeroes(struct io_uring_cmd *cmd, bdev_write_zeroes_sectors(bdev), opf); } +static int blkdev_cmd_secure_erase(struct io_uring_cmd *cmd, + struct block_device *bdev, + uint64_t start, uint64_t len, bool nowait) +{ + blk_opf_t opf = REQ_OP_SECURE_ERASE; + + if (nowait) + opf |= REQ_NOWAIT; + return blkdev_queue_cmd(cmd, bdev, start, len, + bdev_max_secure_erase_sectors(bdev), opf); +} + static int blkdev_cmd_discard(struct io_uring_cmd *cmd, struct block_device *bdev, uint64_t start, uint64_t len, bool nowait) @@ -911,6 +923,9 @@ int blkdev_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags) case BLOCK_URING_CMD_WRITE_ZEROES: return blkdev_cmd_write_zeroes(cmd, bdev, start, len, bc->nowait); + case BLOCK_URING_CMD_SECURE_ERASE: + return blkdev_cmd_secure_erase(cmd, bdev, start, len, + bc->nowait); } return -EINVAL; } diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index b9e20ce57a28..425957589bdf 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -210,6 +210,7 @@ struct fsxattr { #define BLOCK_URING_CMD_DISCARD 0 #define BLOCK_URING_CMD_WRITE_ZEROES 1 +#define BLOCK_URING_CMD_SECURE_ERASE 2 #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ #define FIBMAP _IO(0x00,1) /* bmap access */