Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1752834pxj; Wed, 19 May 2021 13:06:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwFSIDcxb7tmcsSebNGD8CELHwyD8yCrYoYVbcKV4Bq9Gd0VHF4FeUuOl851HN74VIww3I X-Received: by 2002:a17:906:18b2:: with SMTP id c18mr908253ejf.160.1621454798120; Wed, 19 May 2021 13:06:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621454798; cv=none; d=google.com; s=arc-20160816; b=GngPErcLSuMDMfNq2fg9wifcQcMDkLxTtDKXP3uYfYxSk7nsquSDWmzIkePjySn6ZY C0fNEIYBrpI1+lyQxZP3pVypCafzAQi9vn80m4VXmlI1aXS2BmFQarBt+1HoFOiKCihN iYgxV96FfZcM+yR1y+N+YX5Uvg+FGh1bFbYWvjdHVxAO+bwMdLU6FHIJaVrNIu85n5Ne mqSVjGygvOYq17gPHD2xZ/Jthyf4lbr6xZ/2G2OEILRYlpXAONaXfj8aPfDrHbZf2Hsa 7xfAMMBnQEoea7Cbs1aENFpNR8TThdVg1UrqYDpPxakYl433lnNNNod81zi3HQEGBU86 38Sw== 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=K6PlxR1Sd0Afhg7WgBhZnU12RDoSmxGULXPHeQgmUtQ=; b=bbEFfIjaHYhvwudrLf8vhSBfNb0G9q05DxHVNxAGombJ3bKpoNIXa81FnmH7+aloUc KxS6HPOU0dKdxD1G1srOQTN2x+/fxdBYbzri++kaT9w73KIQyObgv4dIV9gfrVllztpU x9vqzlrsIuutI+2PwLE4w2H7M93VQk+qF5P8pjaBwwIvICNASctf/8cGBX7sC55Tqqgx yZwcAM54PkwoaRf9Yno/OmmrysUtboARx3YZV2xrBH/SqfwDFihtaO6leQty5PAYnW9w vi5+HEaqbGgx+8yF5k1r+o606w5WKGngX0EkTlh3Gi7feva+TYkKagjO77blUvgnAIaA qjMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kZbVe1+Y; 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 r26si567978ejz.597.2021.05.19.13.06.14; Wed, 19 May 2021 13:06:38 -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=kZbVe1+Y; 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 S1354253AbhESOQf (ORCPT + 99 others); Wed, 19 May 2021 10:16:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353961AbhESOPb (ORCPT ); Wed, 19 May 2021 10:15:31 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 122DFC061344; Wed, 19 May 2021 07:14:05 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id y184-20020a1ce1c10000b02901769b409001so3432498wmg.3; Wed, 19 May 2021 07:14:05 -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=K6PlxR1Sd0Afhg7WgBhZnU12RDoSmxGULXPHeQgmUtQ=; b=kZbVe1+YAuC3A2cvHPLAJKF9rDZiNU07dbnjjQ+8rdlThDSiL2BHpe9buOIp2lCnOb p3agNsXrGjlkCZEwu66m04+44YK7oCtRZNnEXh1Jk/K2OIxIBgWZWolRExdfFEOJjOlS mPdeoONhtOPixZUtK+x8cgjkf/mjYv2PEWaRqwBULBq2RQpzKArXpTloDRDwaNRwi8vf PGKW212hS8Qw0IfewBVjzt4JhPJWzecTdZVChh55WZmRuOOUkNBonaVlVqLPKV7rTYD/ ZUSomRhOlpe+3LYWNVzKUjSu3vW8Eo/4+k/Vcuf6SifUESZqsqJjDEnhOFj60WFHTCXH 9QDw== 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=K6PlxR1Sd0Afhg7WgBhZnU12RDoSmxGULXPHeQgmUtQ=; b=RLLaCoWLczvlRqf2k8Kr5EgJqd/PLB4tZyJlAUQc3FWt4OBPx6R8QRn6xQJscLCG+8 CXGj2qmhM8B468UYZb2kxohgdvHPT+O6eFJQ4cyfegKWR4a+PSSlMT337VXhNtpGscCS b8NpoI5ziCBNtyPwKQaH5ZRk6kA8wXumE+UmvnNHS+3F2/tiJ7gL1NjbVQkczgbYQ6Ei L+p/LZfHakbsffEATAmz+ksZxxiROH4GksQDosVZARM/3SoKriTSHTuhS8uwAz/K517z N1ZjqQS8k8NChD5RieKoNKJu931QFw6W5F3lWZlKzCXGM+xgI33NaEYfdA00eY9lptcS PPXA== X-Gm-Message-State: AOAM530z34Zk79raN5a4du/n7c/ikhJg8k6OcN/tbm7Wm4v3aRqWRUi/ ekuJyPrx5sFXC2yttGhIvfObHnsZqqPpsWPv X-Received: by 2002:a7b:c041:: with SMTP id u1mr11549476wmc.95.1621433643523; Wed, 19 May 2021 07:14:03 -0700 (PDT) Received: from localhost.localdomain ([85.255.235.154]) by smtp.gmail.com with ESMTPSA id z3sm6233569wrq.42.2021.05.19.07.14.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 May 2021 07:14:03 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jens Axboe , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Horst Schirmeier , "Franz-B . Tuneke" , Christian Dietrich Subject: [PATCH 11/23] io_uring: enable mmap'ing additional CQs Date: Wed, 19 May 2021 15:13:22 +0100 Message-Id: <0b54c7e684a2a9c3cb1a3cddfe48790e79bfbb89.1621424513.git.asml.silence@gmail.com> 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 TODO: get rid of extra offset Signed-off-by: Pavel Begunkov --- fs/io_uring.c | 13 ++++++++++++- include/uapi/linux/io_uring.h | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 067cfb3a6e4a..1a4c9e513ac9 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -9207,6 +9207,7 @@ static void *io_uring_validate_mmap_request(struct file *file, struct io_ring_ctx *ctx = file->private_data; loff_t offset = pgoff << PAGE_SHIFT; struct page *page; + unsigned long cq_idx; void *ptr; switch (offset) { @@ -9218,7 +9219,15 @@ static void *io_uring_validate_mmap_request(struct file *file, ptr = ctx->sq_sqes; break; default: - return ERR_PTR(-EINVAL); + if (offset < IORING_OFF_CQ_RING_EXTRA) + return ERR_PTR(-EINVAL); + offset -= IORING_OFF_CQ_RING_EXTRA; + if (offset % IORING_STRIDE_CQ_RING) + return ERR_PTR(-EINVAL); + cq_idx = offset / IORING_STRIDE_CQ_RING; + if (cq_idx >= ctx->cq_nr) + return ERR_PTR(-EINVAL); + ptr = ctx->cqs[cq_idx].rings; } page = virt_to_head_page(ptr); @@ -9615,6 +9624,8 @@ static int io_allocate_scq_urings(struct io_ring_ctx *ctx, return 0; err: + while (ctx->cq_nr > 1) + io_mem_free(ctx->cqs[--ctx->cq_nr].rings); io_mem_free(ctx->rings); ctx->rings = NULL; return ret; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 92b61ca09ea5..67a97c793de7 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -203,6 +203,8 @@ enum { #define IORING_OFF_SQ_RING 0ULL #define IORING_OFF_CQ_RING 0x8000000ULL #define IORING_OFF_SQES 0x10000000ULL +#define IORING_OFF_CQ_RING_EXTRA 0x1200000ULL +#define IORING_STRIDE_CQ_RING 0x0100000ULL /* * Filled with the offset for mmap(2) -- 2.31.1