From patchwork Fri May 10 03:50:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 13660857 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BEC1149C56 for ; Fri, 10 May 2024 03:50:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715313050; cv=none; b=joCfej5t7SAYtlZx6rdouxuwwpiZt4Hz7zEk3S6ZofdyNZBgvfk4LRyn35KEPsGtjmUbTR0S7HnDKr8YkJ/RgPEFZ+pyQPFIrnmrO+J+cZ/yXumaGs4NggzkaXj2KTmIl1RJfHAe020hlRPHATtfT+4kEq8+kK3noLLu5APA1gI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715313050; c=relaxed/simple; bh=IVCkJCiOABWzxjCH/t7/nMwNUwuLt4iI1yIP9Yui0Uk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tPsoSyEi5nnjn2qQJP5uaBI6nkRf+z1q9Ue2W7KDtef+o04+UA9ZqjBKQvUcMkfYBIJlIILgk0LNmz6ovOpEuABhIGwyIjoWKJWhr8oz2vtu3oxlDxE6bM1xJKzPley+ZV1uSg/i2GvDW7UDwHaoMHdxj7RKmBLKahHknQmJBPs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MFu0IJtW; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MFu0IJtW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715313047; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j8FluV5Q9vpqiSeY3lSHVZET6tI/O0uYgS5WdWWBERE=; b=MFu0IJtWPkv1jEWYTXZWB2J88y4UV0WZhlftCxhkeIQml4A19q7xggtEGtXbCP4jRlaM29 M8pl7S4YuvAdxQzbAyAWFC66npwyqcAXNwlXdKDlyIDGT1x80pZm4XmvNnviKZBN4UfTbM OQG0t96XU4e8QIHfGCC4fVbJSRUu3HU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-17-Jm57ilPRO9-76Ep_zByzSA-1; Thu, 09 May 2024 23:50:41 -0400 X-MC-Unique: Jm57ilPRO9-76Ep_zByzSA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8E5078009F8; Fri, 10 May 2024 03:50:41 +0000 (UTC) Received: from localhost (unknown [10.72.116.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E7192087D7B; Fri, 10 May 2024 03:50:40 +0000 (UTC) From: Ming Lei To: Jens Axboe , io-uring@vger.kernel.org Cc: Ming Lei , stable@vger.kernel.org Subject: [PATCH V2 1/2] io_uring: fail NOP if non-zero op flags is passed in Date: Fri, 10 May 2024 11:50:27 +0800 Message-ID: <20240510035031.78874-2-ming.lei@redhat.com> In-Reply-To: <20240510035031.78874-1-ming.lei@redhat.com> References: <20240510035031.78874-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 The NOP op flags should have been checked from beginning like any other opcode, otherwise NOP may not be extended with the op flags. Given both liburing and Rust io-uring crate always zeros SQE op flags, just ignore users which play raw NOP uring interface without zeroing SQE, because NOP is just for test purpose. Then we can save one NOP2 opcode. Suggested-by: Jens Axboe Fixes: 2b188cc1bb85 ("Add io_uring IO interface") Cc: stable@vger.kernel.org Signed-off-by: Ming Lei --- io_uring/nop.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/io_uring/nop.c b/io_uring/nop.c index d956599a3c1b..1a4e312dfe51 100644 --- a/io_uring/nop.c +++ b/io_uring/nop.c @@ -12,6 +12,8 @@ int io_nop_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { + if (READ_ONCE(sqe->rw_flags)) + return -EINVAL; return 0; } From patchwork Fri May 10 03:50:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 13660858 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C975149C51 for ; Fri, 10 May 2024 03:50:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715313052; cv=none; b=GvwQzf93UggUOqhYQJEhK3PrRxeMXrk9Zv/muXvrHNfqadTwVLZjB90sKQC/bOpWlFZNhHNL0LENUOwsms8X+lneRfXECaNou7V1kyE8lTh16eMwAeHtlzC7kJ6Nq2ArlOc8WqX7FHjEXNldpextb0c/+1pI4nZlzJrsZlvavi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715313052; c=relaxed/simple; bh=xHaS8RuSm+RAvHD7FiV0lv2QmdmMiqn2V4R9zlmW7Ak=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RSv+bgiuDuUaS2A0M4DgX1yiAABopq/KGk32bWRYOf1RU8Tc1jqpPCOPHzEARA6OU2K2F1dcoke/qv2AYVPuAYpHSEQR6j7SxsEdd9Y+mnctgtQY3QOnjj6+b0XqKirrCMTs7zuReeht4F1AXsaEfrXgUg9Qi4NlsYF5a0d1VDg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=OkDlceWl; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OkDlceWl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715313048; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BQxmNizpGxh8r0UMULNAz/Lp2TMmVrIxJyns9wH8C6U=; b=OkDlceWlsBSwTDJyy4OaNqKqe6W40PulkfkakZUpWD0cWvQLQSIbTmRwF5jTUIH90ErHx4 Jn2Li9J+hyI5T/gJ4jHw5WKprPCJLseQNwPrD/DX2lbcspYge3bZWzS3IiK8+AO9+dJJ1A M/8xZIR5I+SEjXh/N++NHoyue0WbFiY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-153-UwXz_FKoOYWzrVuDPvjwiA-1; Thu, 09 May 2024 23:50:45 -0400 X-MC-Unique: UwXz_FKoOYWzrVuDPvjwiA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E5D9B3C0BE3F; Fri, 10 May 2024 03:50:44 +0000 (UTC) Received: from localhost (unknown [10.72.116.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 003887464; Fri, 10 May 2024 03:50:43 +0000 (UTC) From: Ming Lei To: Jens Axboe , io-uring@vger.kernel.org Cc: Ming Lei Subject: [PATCH V2 2/2] io_uring: support to inject result for NOP Date: Fri, 10 May 2024 11:50:28 +0800 Message-ID: <20240510035031.78874-3-ming.lei@redhat.com> In-Reply-To: <20240510035031.78874-1-ming.lei@redhat.com> References: <20240510035031.78874-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Support to inject result for NOP so that we can inject failure from userspace. It is very helpful for covering failure handling code in io_uring core change. With nop flags, it becomes possible to add more test features on NOP in future. Suggested-by: Jens Axboe Signed-off-by: Ming Lei --- include/uapi/linux/io_uring.h | 8 ++++++++ io_uring/nop.c | 26 +++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 922f29b07ccc..21e9cd604068 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -72,6 +72,7 @@ struct io_uring_sqe { __u32 waitid_flags; __u32 futex_flags; __u32 install_fd_flags; + __u32 nop_flags; }; __u64 user_data; /* data to be passed back at completion time */ /* pack this to avoid bogus arm OABI complaints */ @@ -413,6 +414,13 @@ enum io_uring_msg_ring_flags { */ #define IORING_FIXED_FD_NO_CLOEXEC (1U << 0) +/* + * IORING_OP_NOP flags (sqe->nop_flags) + * + * IORING_NOP_INJECT_RESULT Inject result from sqe->result + */ +#define IORING_NOP_INJECT_RESULT (1U << 0) + /* * IO completion data structure (Completion Queue Entry) */ diff --git a/io_uring/nop.c b/io_uring/nop.c index 1a4e312dfe51..a5bcf3d6984f 100644 --- a/io_uring/nop.c +++ b/io_uring/nop.c @@ -10,18 +10,34 @@ #include "io_uring.h" #include "nop.h" +struct io_nop { + /* NOTE: kiocb has the file as the first member, so don't do it here */ + struct file *file; + int result; +}; + int io_nop_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { - if (READ_ONCE(sqe->rw_flags)) + unsigned int flags; + struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop); + + flags = READ_ONCE(sqe->nop_flags); + if (flags & ~IORING_NOP_INJECT_RESULT) return -EINVAL; + + if (flags & IORING_NOP_INJECT_RESULT) + nop->result = READ_ONCE(sqe->len); + else + nop->result = 0; return 0; } -/* - * IORING_OP_NOP just posts a completion event, nothing else. - */ int io_nop(struct io_kiocb *req, unsigned int issue_flags) { - io_req_set_res(req, 0, 0); + struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop); + + if (nop->result < 0) + req_set_fail(req); + io_req_set_res(req, nop->result, 0); return IOU_OK; }