Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3557420pxj; Tue, 1 Jun 2021 08:01:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3W7qoh2l/Qzl+t/n78yH8ptE4n7HFxSC5v88utNaFP+KJcUWpRdykt/1qZd0Lgr4xNggl X-Received: by 2002:a17:906:15c2:: with SMTP id l2mr29341040ejd.348.1622559707686; Tue, 01 Jun 2021 08:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622559707; cv=none; d=google.com; s=arc-20160816; b=Lz452JlwfqqCnrFKeiXCX7GHTVnxomD1Dj9JzDLJyskx8XHI5xC1al9xtN5u8o6g8j HBbJh4mgdEXWNaM4rFsJ70zTGSxbtJSPYy1WZOmoOiUSS/rdWlA9c+UMZrzOgVxhH6fa ozC7hLr5yYjIt+NgWFm0FQqVWaQQF2/J4XKMxC08eEQIWf3ePkyLmZeX1rdERPU4NZL5 qFwPMwoNmc/LWYUxv4jh+bjWdELSj8gQdzDXdtTF+aL6igyDhmGYj1aZFh57LvCeJzCn CJpm06SLlLnWlohYSANaUgQcb3nuLDrNvQDKwH2h/vGTCtf4GvKkJMcB0+6HLamvHxQJ +z+Q== 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=r+ZDp2MX14n2P2eiCGRvIM1kDjuYaOV/V/d7u2BhKxU=; b=BcQFenc7OUHyW6/96+3I+Mf/Xni1DWpqlXbfRbj0lBFBC5dXW4YDUTIEP65QrUB9bj QLhYN40ZThdiVK1zN8fRsiX0wQbEThE067rfBiN2r+XXhxi/47LNW5Ak21rq9JG2R9Nw 9gz5+6aiYbC4H6ChaIfqjbwzeYepJCQcMkhV1BN9Mw0BreSMJgzPkY5oVBlGZoKgs90P ULUQOT0agK5XamC4TtdVhOa92f2U6BGFbGYvqVfrAOYiaNdcIOr3cflqDMOaKAAnOePK QJnlsRcmlthkh0iAXNUQeq8J358aVHjCC3vS9Fs9ixI2ZSHpAIIdWEaQxCU5qtAsCpuq TTzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=C9W+uhYu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w16si15866112ejv.665.2021.06.01.08.01.19; Tue, 01 Jun 2021 08:01:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=C9W+uhYu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234233AbhFAPA7 (ORCPT + 99 others); Tue, 1 Jun 2021 11:00:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234393AbhFAPAi (ORCPT ); Tue, 1 Jun 2021 11:00:38 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 756D6C061574; Tue, 1 Jun 2021 07:58:56 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id z8so9564495wrp.12; Tue, 01 Jun 2021 07:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r+ZDp2MX14n2P2eiCGRvIM1kDjuYaOV/V/d7u2BhKxU=; b=C9W+uhYumE184gHUe2A17WI1k6OUSKnUMSOlPxD9DzuqrJLhDNIQkGaKWUKIEiW4v1 mNeh2Y4YpZnQs1t27DpJQ3jjUuxr/OzZLDbmGOsx1aCDwyzOl2TGF8e9t6rFT04DPqV6 m4sPMX+LJfq3mrA4LQ97TpK6CI01oePa/rfDWPLfZoiYnxzpS+vMqpYR+epbx7JQ8K2K gXiReU9pjUIzNjq2u5fe6yghw+ZR7qJDdTEEYS9sKhUT7EOFMf4tAz0wCoEDsurME/vM Sc+Wophdi9+3KOlYQp4+xQNhUe0gnxqhbiWsuySYfv1/OrJiCv7dnEwfbEIOIA1vqZsz DAUw== 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=r+ZDp2MX14n2P2eiCGRvIM1kDjuYaOV/V/d7u2BhKxU=; b=j2opq+UQCnfmq6kvGiDfUXBZMFLXGM5TnlHCPbcU6qoabRV4FGouKk/RKdHdMU3SIK VLzo5FRnE3n0UxMsc0ja7tSxKyy9M13d9YZYC4ZP5Rgy6MaKZrvqwIaghIMlFIENLlE/ vo3N1D+4MEg2nII03kYkyzq5+SYYZhDFZwGuqjQbKpxKqTzPUlae4D8+9qPjhEqvfPLz NVandNtbYZK7fICmogHsxcv8EEqw98wt6KoaqEAajTCJp7R8s/p70xbBFoJnImu12xUO HMuQEa+CvuQMoA8ESHH5NdpdhhA07cE8Tm2dLllq7QyZSBbileada3yN3DwssU3i2FjK 21Qg== X-Gm-Message-State: AOAM530vwDPtmuvf8Pt2alWVut45yf5h0Zz03gI6j4Jf/w3DJRw3I7LW qXuZsHX2ToUKqV+RH80skTfMEObLDm/hHw== X-Received: by 2002:adf:eb86:: with SMTP id t6mr28618701wrn.253.1622559534854; Tue, 01 Jun 2021 07:58:54 -0700 (PDT) Received: from localhost.localdomain ([85.255.237.139]) by smtp.gmail.com with ESMTPSA id b4sm10697061wmj.42.2021.06.01.07.58.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jun 2021 07:58:54 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , Andres Freund , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , linux-kernel@vger.kernel.org Subject: [RFC 4/4] io_uring: implement futex wait Date: Tue, 1 Jun 2021 15:58:29 +0100 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add futex wait requests, those always go through io-wq for simplicity. Signed-off-by: Pavel Begunkov --- fs/io_uring.c | 38 ++++++++++++++++++++++++++++------- include/uapi/linux/io_uring.h | 2 +- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 99f4f8d9f685..9c3d075a6647 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -670,8 +670,15 @@ struct io_futex { struct file *file; unsigned int futex_op; - unsigned int nr_wake; - unsigned int wake_op_arg; + union { + /* wake */ + struct { + unsigned int nr_wake; + unsigned int wake_op_arg; + }; + /* wait */ + u32 val; + }; unsigned int flags; void __user *uaddr; }; @@ -5894,10 +5901,23 @@ static int io_futex_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) return -EINVAL; v = READ_ONCE(sqe->off); - f->nr_wake = (u32)v; - f->wake_op_arg = (u32)(v >> 32); - f->futex_op = READ_ONCE(sqe->futex_op); f->uaddr = u64_to_user_ptr(READ_ONCE(sqe->addr)); + f->futex_op = READ_ONCE(sqe->futex_op); + + switch (f->futex_op) { + case IORING_FUTEX_WAKE_OP: + f->nr_wake = (u32)v; + f->wake_op_arg = (u32)(v >> 32); + break; + case IORING_FUTEX_WAIT: + f->val = (u32)v; + if (unlikely(v >> 32)) + return -EINVAL; + break; + default: + return -EINVAL; + } + return 0; } @@ -5916,8 +5936,12 @@ static int io_futex(struct io_kiocb *req, unsigned int issue_flags) if (nonblock && ret == -EAGAIN) return -EAGAIN; break; - default: - ret = -EINVAL; + case IORING_FUTEX_WAIT: + if (nonblock) + return -EAGAIN; + ret = futex_wait(f->uaddr, f->flags, f->val, NULL, + FUTEX_BITSET_MATCH_ANY); + break; } if (ret < 0) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 6fa5a6e59934..7ab11ee2ce12 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -186,7 +186,7 @@ enum { enum { IORING_FUTEX_WAKE_OP = 0, - + IORING_FUTEX_WAIT, IORING_FUTEX_LAST, }; -- 2.31.1