From patchwork Mon Oct 31 13:41:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Yudaken X-Patchwork-Id: 13025943 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D16FFA3745 for ; Mon, 31 Oct 2022 13:42:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231211AbiJaNmI (ORCPT ); Mon, 31 Oct 2022 09:42:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230288AbiJaNmH (ORCPT ); Mon, 31 Oct 2022 09:42:07 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D28F4101FD for ; Mon, 31 Oct 2022 06:42:06 -0700 (PDT) Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29VDFQsD007133 for ; Mon, 31 Oct 2022 06:42:06 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=s2048-2021-q4; bh=Yf3Oe7nNm4mTSc3Ipcgjg8uc6Rp9QEcyG6HSDoB+xZ4=; b=EKCOfaSaFDOw74Oktjbuvt+1B3GImoF+0Pfdv2cyjnPw429BZ+ClRwFoyWfRyOhCoLbk srwnnDHvwHwVxhzhSvXK2Z7WAKjhfn1wumR5w4AUJSIdrhbpVSlgB4tLouGw6xhuBiK6 VfZtnpKX9PvKcaPRVutZmpOQ7Hn7s8qgdKF5t2gopF6CiCyzarCq8aWMtOTwY+c3AFs/ Hkm8yuwghA5Nr5gRqkzFk8sMX4XECa/Hy6UyAF5RgyFsJ0/3U80IHQa1p58tbI+QYCCj Q6jaKBRXV78rgtnvmAH8N9UrMoT6Xxak2/zzS09Px7R97t4maN2Iro0SSSb+g0GioxdW 4Q== Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3kh1x1xcd2-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 31 Oct 2022 06:42:05 -0700 Received: from twshared23862.08.ash9.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c085:21d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 31 Oct 2022 06:42:04 -0700 Received: by devbig038.lla2.facebook.com (Postfix, from userid 572232) id 038E48A19664; Mon, 31 Oct 2022 06:41:36 -0700 (PDT) From: Dylan Yudaken To: Jens Axboe , Pavel Begunkov CC: , , Dylan Yudaken Subject: [PATCH for-next 12/12] io_uring: poll_add retarget_rsrc support Date: Mon, 31 Oct 2022 06:41:26 -0700 Message-ID: <20221031134126.82928-13-dylany@meta.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221031134126.82928-1-dylany@meta.com> References: <20221031134126.82928-1-dylany@meta.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: ZsbdbKjEvdcRSEIRfN8njtPqINm1f7AF X-Proofpoint-GUID: ZsbdbKjEvdcRSEIRfN8njtPqINm1f7AF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-31_15,2022-10-31_01,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Add can_retarget_rsrc handler for poll. Note that the copy of fd is stashed in the middle of the struct io_poll as there is a hole there, and this is the only way to ensure that the structure does not grow beyond the size of struct io_cmd_data. Signed-off-by: Dylan Yudaken --- io_uring/opdef.c | 1 + io_uring/poll.c | 12 ++++++++++++ io_uring/poll.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/io_uring/opdef.c b/io_uring/opdef.c index 5159b3abc2b2..952ea8ff5032 100644 --- a/io_uring/opdef.c +++ b/io_uring/opdef.c @@ -133,6 +133,7 @@ const struct io_op_def io_op_defs[] = { .name = "POLL_ADD", .prep = io_poll_add_prep, .issue = io_poll_add, + .can_retarget_rsrc = io_poll_can_retarget_rsrc, }, [IORING_OP_POLL_REMOVE] = { .audit_skip = 1, diff --git a/io_uring/poll.c b/io_uring/poll.c index 0d9f49c575e0..fde8060b9399 100644 --- a/io_uring/poll.c +++ b/io_uring/poll.c @@ -863,6 +863,7 @@ int io_poll_add_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) return -EINVAL; poll->events = io_poll_parse_events(sqe, flags); + poll->fd = req->cqe.fd; return 0; } @@ -963,3 +964,14 @@ void io_apoll_cache_free(struct io_cache_entry *entry) { kfree(container_of(entry, struct async_poll, cache)); } + +bool io_poll_can_retarget_rsrc(struct io_kiocb *req) +{ + struct io_poll *poll = io_kiocb_to_cmd(req, struct io_poll); + + if (req->flags & REQ_F_FIXED_FILE && + io_file_peek_fixed(req, poll->fd) != req->file) + return false; + + return true; +} diff --git a/io_uring/poll.h b/io_uring/poll.h index 5f3bae50fc81..dcc4b06bcea1 100644 --- a/io_uring/poll.h +++ b/io_uring/poll.h @@ -12,6 +12,7 @@ struct io_poll { struct file *file; struct wait_queue_head *head; __poll_t events; + int fd; /* only used by poll_add */ struct wait_queue_entry wait; }; @@ -37,3 +38,4 @@ bool io_poll_remove_all(struct io_ring_ctx *ctx, struct task_struct *tsk, bool cancel_all); void io_apoll_cache_free(struct io_cache_entry *entry); +bool io_poll_can_retarget_rsrc(struct io_kiocb *req);