From mboxrd@z Thu Jan 1 00:00:00 1970 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 00B12CCA47A for ; Thu, 16 Jun 2022 13:13:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376839AbiFPNNh (ORCPT ); Thu, 16 Jun 2022 09:13:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376939AbiFPNNf (ORCPT ); Thu, 16 Jun 2022 09:13:35 -0400 Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83EFA2ED69 for ; Thu, 16 Jun 2022 06:13:33 -0700 (PDT) Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1655385211; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kC+K3WypVrYjxRT8nx/1mi96gi3ZYp6Ks5/ETviOqCc=; b=ALmY2nvH8hkZYqzFmbfMRNw/TxWYCWwBvFSGm5iR9HZ2Fv9Shs2aJmNfAtXQ1A7eN78Z2f iuZyDPg9WbBLuY656GIX8bO3e5o92leDej0pvnvno2h37TTBWoLAa2/6eBekDpoUJPDY1+ EWJnoNeRP1Hk1TqCNTaEmTLdd2q09Kk= Date: Thu, 16 Jun 2022 21:13:25 +0800 MIME-Version: 1.0 Subject: Re: [PATCH v2] io_uring: commit non-pollable provided mapped buffers upfront Content-Language: en-US To: Jens Axboe , io-uring Cc: Pavel Begunkov References: <43b88754-a171-e871-5418-1ce53055c715@kernel.dk> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Hao Xu In-Reply-To: <43b88754-a171-e871-5418-1ce53055c715@kernel.dk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org On 6/16/22 20:34, Jens Axboe wrote: > For recv/recvmsg, IO either completes immediately or gets queued for a > retry. This isn't the case for read/readv, if eg a normal file or a block > device is used. Here, an operation can get queued with the block layer. > If this happens, ring mapped buffers must get committed immediately to > avoid that the next read can consume the same buffer. > > Check if we're dealing with pollable file, when getting a new ring mapped > provided buffer. If it's not, commit it immediately rather than wait post > issue. If we don't wait, we can race with completions coming in, or just > plain buffer reuse by committing after a retry where others could have > grabbed the same buffer. > > Fixes: c7fb19428d67 ("io_uring: add support for ring mapped supplied buffers") > Signed-off-by: Jens Axboe > > --- > > diff --git a/fs/io_uring.c b/fs/io_uring.c > index 5d479428d8e5..b6e75f69c6b1 100644 > --- a/fs/io_uring.c > +++ b/fs/io_uring.c > @@ -3836,7 +3836,7 @@ static void __user *io_ring_buffer_select(struct io_kiocb *req, size_t *len, > req->buf_list = bl; > req->buf_index = buf->bid; > > - if (issue_flags & IO_URING_F_UNLOCKED) { > + if (issue_flags & IO_URING_F_UNLOCKED || !file_can_poll(req->file)) { > /* > * If we came in unlocked, we have no choice but to consume the > * buffer here. This does mean it'll be pinned until the IO > Looks good, Reviewed-by: Hao Xu