Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3210195iob; Mon, 16 May 2022 16:07:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyw35bxnhoOmz68LGqarPus86Vhisf2PuvLepV6gmePrIZ+jotVSPBNO1juYDVsE5hSr4Y0 X-Received: by 2002:a17:903:1c4:b0:15e:9f34:378c with SMTP id e4-20020a17090301c400b0015e9f34378cmr19738434plh.87.1652742434466; Mon, 16 May 2022 16:07:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652742434; cv=none; d=google.com; s=arc-20160816; b=GGo99YxMuqrV/0/352xShS0jB96siG0T5u0s76+cT3pRZ/KtSvWre0UXPPZiCk/kKZ Xki3DBpWJG0NLpokmYXtktslen8ZtlrFo2/hv8MmSwQzGvEIhmRutKIQzez0X9UpYVfR MPT98GxngTREaClEZ76WXzPWNAXClXZdZoISpL2iCnwvxu76AhWCg3Xg0UorsxAoLoiU 7DPI7SYZS2NPudDMurXzu0Ow7msqfqPi5KITEPBBTpF/T3XzkGNSOq/DsOBZ9gM12jML jEG4zfqM/3BccAVQw4sx9MWkENOOEQF0gEPkWfPR+j0wc8xhHC8mdDRenOiDDeGkdXQs XK5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=RAcicosbrzNtKq22oJlMdmRA4Z34sYOSW6vqrZPUyF0=; b=wyvXvt8GtqPysymHoghYf+oipvSCwzsPpo1KslYlvUoYLyEIBb7WIr2VsXVCWfal6p RD4HGq3uQVPwmJQBgvb/WAYG4HErtsC/C45suw01Atu0HIFSGpFWOuflfjmZEuOKFQ0V izJpSXOMaE/+TJTXkrINadmVJPHQodUSNVKBahQxMYrFd1FK8QHWQv7I3W1TAFQioowl wCgX+HNRI3ibSC5OYJh1hT6WdZarsjJpL9NGWFyDikWNgQSCLu07srpOQmeDMq6Akh+s hoQaIMB8X0q5jN2c+7aUK5sflr5ZgF/QuuO8YyttA4d3V84xdr0VUFQPgem29swzPXNB 0mwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=D2doh2R2; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s16-20020a056a00179000b0050a6c1711d7si15768129pfg.336.2022.05.16.16.07.03; Mon, 16 May 2022 16:07:14 -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=@redhat.com header.s=mimecast20190719 header.b=D2doh2R2; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345437AbiEPTbZ (ORCPT + 99 others); Mon, 16 May 2022 15:31:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345426AbiEPTbW (ORCPT ); Mon, 16 May 2022 15:31:22 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C18D51A394 for ; Mon, 16 May 2022 12:31:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652729471; 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: in-reply-to:in-reply-to; bh=RAcicosbrzNtKq22oJlMdmRA4Z34sYOSW6vqrZPUyF0=; b=D2doh2R20EbfNVDoMUyerpLzgZaEOmXMkkwuu/jX8nK8ndYHrfvAVLJoaLnf69jsh1gs1G O+HvvbkVfVuo9Ncobos5511FC32B+wlXmYbxsUbLrIg/haahNZAP/GGRzH5xKHCK7Hcp3p juQZgNb9eta8f2ovz9BRRJpsqXxNQDg= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-500-DCgS7vFaPTi9XkWYiP2xVw-1; Mon, 16 May 2022 15:31:09 -0400 X-MC-Unique: DCgS7vFaPTi9XkWYiP2xVw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DCE983C1E321; Mon, 16 May 2022 19:31:08 +0000 (UTC) Received: from localhost (unknown [10.39.192.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 714ED555087; Mon, 16 May 2022 19:31:08 +0000 (UTC) Date: Mon, 16 May 2022 20:29:25 +0100 From: Stefan Hajnoczi To: ming.lei@redhat.com Cc: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, Gabriel Krisman Bertazi , ZiyangZhang , Xiaoguang Wang , kwolf@redhat.com, sgarzare@redhat.com Subject: Re: [RFC PATCH] ubd: add io_uring based userspace block driver Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="6o93nD4/ZHY926/y" Content-Disposition: inline In-Reply-To: <20220509092312.254354-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, 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 --6o93nD4/ZHY926/y Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, This looks interesting! I have some questions: 1. What is the ubdsrv permission model? A big usability challenge for *-in-userspace interfaces is the balance between security and allowing unprivileged processes to use these features. - Does /dev/ubd-control need to be privileged? I guess the answer is yes since an evil ubdsrv can hang I/O and corrupt data in hopes of triggering file system bugs. - Can multiple processes that don't trust each other use UBD at the same time? I guess not since ubd_index_idr is global. - What about containers and namespaces? They currently have (write) access to the same global ubd_index_idr. - Maybe there should be a struct ubd_device "owner" (struct task_struct *) so only devices created by the current process can be modified? 2. io_uring_cmd design The rationale for the io_uring_cmd design is not explained in the cover letter. I think it's worth explaining the design. Here are my guesses: The same thing can be achieved with just file_operations and io_uring. ubdsrv could read I/O submissions with IORING_OP_READ and write I/O completions with IORING_OP_WRITE. That would require 2 sqes per roundtrip instead of 1, but the same number of io_uring_enter(2) calls since multiple sqes/cqes can be batched per syscall: - IORING_OP_READ, addr=(struct ubdsrv_io_desc*) (for submission) - IORING_OP_WRITE, addr=(struct ubdsrv_io_cmd*) (for completion) Both operations require a copy_to/from_user() to access the command metadata. The io_uring_cmd approach works differently. The IORING_OP_URING_CMD sqe carries a 40-byte payload so it's possible to embed struct ubdsrv_io_cmd inside it. The struct ubdsrv_io_desc mmap gets around the fact that io_uring cqes contain no payload. The driver therefore needs a side-channel to transfer the request submission details to ubdsrv. I don't see much of a difference between IORING_OP_READ and the mmap approach though. It's not obvious to me how much more efficient the io_uring_cmd approach is, but taking fewer trips around the io_uring submission/completion code path is likely to be faster. Something similar can be done with file_operations ->ioctl(), but I guess the point of using io_uring is that is composes. If ubdsrv itself wants to use io_uring for other I/O activity (e.g. networking, disk I/O, etc) then it can do so and won't be stuck in a blocking ioctl() syscall. It would be nice if you could write 2 or 3 paragraphs explaining why the io_uring_cmd design and the struct ubdsrv_io_desc mmap was chosen. 3. Miscellaneous stuff - There isn't much in the way of memory ordering in the code. I worry a little that changes to the struct ubdsrv_io_desc mmap may not be visible at the expected time with respect to the io_uring cq ring. Thanks, Stefan --6o93nD4/ZHY926/y Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAmKCphUACgkQnKSrs4Gr c8hrNAgAm3whe7oUQEB6dbQEsZj/jlnxPIiZq/Fr9/qmzrwAuaYZbQb7wxSij7gS agI4tPMiNTdweZSwBQgDzsfaKTZPVJ1Hg7e3a2a8KO2rXgIpuroUVG9D5UIU5cbv H1DysO+LRPe82xUkKTzeU6i4iUdIXar5R7hUCPUPZq/0+VMYHfbwwnXz3D37w/4i YPYKxaq6uPB75kcC95XiztGm69CXTsSu8Uy6VRE11WEqy0fI5T+mkCx0CecxpKQW fMpCO8VMcQKD4el7KiexTboeqA2kxbi1PxJninlh5S9zA8roQpUpLDS6LhwNlQeb 43+1hxRTFOsSai6oZzonuQaQdYi2Cg== =vNPr -----END PGP SIGNATURE----- --6o93nD4/ZHY926/y--