Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp388516iog; Thu, 30 Jun 2022 02:49:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vU0zFNIvN4+yw910XWBFbGzZrH3DC8jMqCXi+eOPMWFRMX0ZLeLLqE/rrH0lJhSaulUtxK X-Received: by 2002:a63:591a:0:b0:40d:a82e:bc63 with SMTP id n26-20020a63591a000000b0040da82ebc63mr6800624pgb.61.1656582573615; Thu, 30 Jun 2022 02:49:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656582573; cv=none; d=google.com; s=arc-20160816; b=tCydcmb9RQIBxzDnWZBjf6dXzyb9jANWlxlMAHQZHDhQZwY9pbuFRQckq1AfHHiFza 4XaXwwqt83RBWVQlNAaFrzGfT9KIiUZfa5BL/YcQahR5snvTyvQjhbQ14f7t2ZP9AmgR z1AJ3wKNPWuCadp3GOgMKuS0gWjMeSwDJJVS8xObwsxdCxlb4JCSWWpZhbUHQWJTvY0f mT6HbVrNVZfm9rJiXpQlJo3WEQ9Wuy43Xgncyy9mi7NUoAqM8rCydjUGMqk3pxVqLsE+ /Qvx+fEDQ4ay3QfkZo26Lrbw3igd/i+b5s7iDR4jr+TiTv8sC+t1HkaEEuonsZSeJkyA OwUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tIhkPlWStBNk/+zkPkhwWVN8boBfp55d1HvcMzDGNpY=; b=nWqtgZybJ/c+TjbafAq4CzS9+3HZsUTU0HhOVpdPx7Ds5i4/V85pzivDcvdZgm/nF2 WOkRDRwHmAMtupYYlV6Cbwhl+pOfQQ9uCGhd+LJqNUM8XbBnA6DDoTTiBEzFlhxQoy7W 3gFngj1ZpX7014w6QB+siojFqD2oUx1YQljNkheshFRmHIiqOdtWeTVvqb2V8EivKFRP vmR1TvF8bow6pKFXPUCknm5Uo/wbuTT5KuXFjjn11zfRx8bpG64OeO94aiAyWBe+9wx3 O0thnK25qPA4uJfEzPo3qnDW8kBpFHrHtRBVaYIhK8OZiCJQmJn0NVH+9D/BFGUikD3d hy4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=oGcIHbH1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q197-20020a632ace000000b0040c6b32d48asi25703596pgq.871.2022.06.30.02.49.21; Thu, 30 Jun 2022 02:49:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=oGcIHbH1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234390AbiF3JTI (ORCPT + 99 others); Thu, 30 Jun 2022 05:19:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234070AbiF3JSW (ORCPT ); Thu, 30 Jun 2022 05:18:22 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7E1232051 for ; Thu, 30 Jun 2022 02:17:12 -0700 (PDT) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25U7UoFm027661 for ; Thu, 30 Jun 2022 02:17:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=tIhkPlWStBNk/+zkPkhwWVN8boBfp55d1HvcMzDGNpY=; b=oGcIHbH14Z8i/zpn5UX4exEbhjltNgXvXuU01I/lTGfMgsQexf3OeLgRBm5HfJtAFNwU K8rDzK7zTqd+KwJgwhKdt9MTPauQ7xVUJPYSA+Nn3z9kSsQkWpwfzDCZ0yXedELrKaED dNt69QTY2iHQ74Ly8P8oCw1bT1lmPe0NMao= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3h17fmgg3v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 30 Jun 2022 02:17:12 -0700 Received: from twshared17349.03.ash7.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c085:11d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 30 Jun 2022 02:17:11 -0700 Received: by devbig038.lla2.facebook.com (Postfix, from userid 572232) id C05E82599FDD; Thu, 30 Jun 2022 02:14:08 -0700 (PDT) From: Dylan Yudaken To: Jens Axboe , Pavel Begunkov , CC: , , Dylan Yudaken Subject: [PATCH v2 for-next 08/12] io_uring: fix multishot poll on overflow Date: Thu, 30 Jun 2022 02:12:27 -0700 Message-ID: <20220630091231.1456789-9-dylany@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220630091231.1456789-1-dylany@fb.com> References: <20220630091231.1456789-1-dylany@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: US7eKPPUKlT0m4NYf_N9mBrJT0qQk4eq X-Proofpoint-ORIG-GUID: US7eKPPUKlT0m4NYf_N9mBrJT0qQk4eq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-30_05,2022-06-28_01,2022-06-22_01 X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On overflow, multishot poll can still complete with the IORING_CQE_F_MORE flag set. If in the meantime the user clears a CQE and a the poll was cancelled the= n the poll will post a CQE without the IORING_CQE_F_MORE (and likely result -ECANCELED). However when processing the application will encounter the non-overflow CQE which indicates that there will be no more events posted. Typical userspace applications would free memory associated with the poll in this case. It will then subsequently receive the earlier CQE which has overflowed, which breaks the contract given by the IORING_CQE_F_MORE flag. Signed-off-by: Dylan Yudaken --- io_uring/poll.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/io_uring/poll.c b/io_uring/poll.c index e8f922a4f6d7..57747d92bba4 100644 --- a/io_uring/poll.c +++ b/io_uring/poll.c @@ -243,8 +243,10 @@ static int io_poll_check_events(struct io_kiocb *req= , bool *locked) req->apoll_events); =20 if (!io_post_aux_cqe(ctx, req->cqe.user_data, - mask, IORING_CQE_F_MORE, true)) - return -ECANCELED; + mask, IORING_CQE_F_MORE, false)) { + io_req_set_res(req, mask, 0); + return IOU_POLL_REMOVE_POLL_USE_RES; + } } else { ret =3D io_poll_issue(req, locked); if (ret =3D=3D IOU_STOP_MULTISHOT) --=20 2.30.2