Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp5375654pxv; Wed, 7 Jul 2021 02:11:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMhp7P4/0FZs4buawGEC16ZNQDzAdCcnRgFDH9X3AlhtEvZpIVLq62Wid6YT4Epgu0Q2MJ X-Received: by 2002:a05:6402:270e:: with SMTP id y14mr29260558edd.124.1625649094934; Wed, 07 Jul 2021 02:11:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625649094; cv=none; d=google.com; s=arc-20160816; b=aH8B8TpJF5xDJHF/10Ol6SB1sxNoubLgdTh3SURKoR2E15HuPGCuBa6E074oRkmc8R Mx10o9RNoL0JD6JYBT9GetwmLSp+dAWVHgdu6tprneabP4uU/APpQCMKXEGsdNQ2usHY 80dP3gF0arVfYUVX930wdCB8qfRMzmihcXOmhNiLCerVzAC/cgo17YVBU0TE4qwRs7LH yfNyqCYT+p4oUEdLZqA6qdeIJgKqyePlsScEKw5m0ZpqJTKs+/tIlOQPTfZmEnAQ/ai5 fwzvhwhsqL6h3c19vQepAv6fGf0egtvIsVitelNpcINcfZrZNx5ao71jhDTe4+vjk12y +44g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=FtdRj0uqhbWYJv1fXc78UI5Oym+NbdH9ODlpZg+9HZI=; b=k6HcCFyf/Ow+ITWCDtUsr6FCpk9j8+D5rbTpNmlLmQZMdNEcYwXoPo266q5FWDIVgu rt29VTg2+TV1GyTD21MDfy/aBQm5YwDYxfDJgGHgqlBNkghMNxVnjYo+yZSORUsk1+zy 8xQBV7S0ldsES9cT6WULJqDfxYUcWqKOjJtC+SiMw6rsAUhYggTsah49LOi48/IP7tdj /zHW7Z3PQYGQP8izwz3bnLy8F4LikSZKnNwARIXfzWh+gS1KhZ7/fE5UH1jVFkmwtr4F z3hqIqVTNw+12GJLc0k1KEXA/M2SXly0Bt4W+udSkXWUuMLRNItxB/T4OtsxrYT4DO3k ed6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=UP2gxo7E; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 3si16381991ejr.392.2021.07.07.02.11.11; Wed, 07 Jul 2021 02:11:34 -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=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=UP2gxo7E; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231480AbhGGJMH (ORCPT + 99 others); Wed, 7 Jul 2021 05:12:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231548AbhGGJMG (ORCPT ); Wed, 7 Jul 2021 05:12:06 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CA81C061760 for ; Wed, 7 Jul 2021 02:09:26 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id h2so2461514edt.3 for ; Wed, 07 Jul 2021 02:09:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=FtdRj0uqhbWYJv1fXc78UI5Oym+NbdH9ODlpZg+9HZI=; b=UP2gxo7E+OXts94W4XG8ov25acIgy16F7Xuv5WNUryBRLvnB1SUdOumUACfAPoJmFS 52RE8R7P3qzg1tarx6KjKAKEHb0Dj5puUCLSt4CliZJpugu/J1PeSwvG09Sv8SfFplGU DBap5eLBxTmFKW9K2PAgbKQ4UW5jIafViUeCgIHHk0GQV9Tv4AoOXsa2pQcvvdtk0UEk qzg8jcE6bFOHgPnYLfHRZZTw0XzS/1JMmDSF7Xh2WYY8wHkQJK4LhvVclPWJCWFgWaoK 6TQcVcEEhAqleM8ofZK+PMsZBBDsQDwSyML/MSyfSeinKDg97GhQwRNlPXflVJHElUst mqKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=FtdRj0uqhbWYJv1fXc78UI5Oym+NbdH9ODlpZg+9HZI=; b=ZCRyEkGavgkuMHs1Vb3VUvT5t5ieZyGtqO/uYn2shYof1NkdWOhQxiSXy3v+LXmKa5 6qzJrriHapOLx1tvp1qp50JOV8B7+WBBlIGGZGTEC/hj30ErgJghWjrYsJcpBFK8BVfE Hc8XbYdjckQ5v14+jZhOcPMhLvViU+mpLMXqYyVpPsnS5nuiIly/Br6gZOwiHUEFeqXj lfcp5cmXG2Go5/z1xHs/LpPAjSfyQD+F2MQIecmiDxklEfunSjAwKwXwBovLfw2bkB09 V8LE7JOqsfzGJV6iWEnixUxyGVQQtOmbHcV7V9XthS+PqJUjS8MDVDEM+bgOuYHyK/fS V2nQ== X-Gm-Message-State: AOAM531ukhfp95ufne1syKk4OrAnAFzH3uLssIDJcMorqelzGhvaT8Jj uSUoQXl6aEvlhFlUPCGalXAbNjGYLC0oTWVFd1p1 X-Received: by 2002:a05:6402:31ae:: with SMTP id dj14mr23195138edb.145.1625648964822; Wed, 07 Jul 2021 02:09:24 -0700 (PDT) MIME-Version: 1.0 References: <20210615141331.407-11-xieyongji@bytedance.com> <8320d26d-6637-85c6-8773-49553dfa502d@redhat.com> In-Reply-To: From: Yongji Xie Date: Wed, 7 Jul 2021 17:09:13 +0800 Message-ID: Subject: Re: [PATCH v8 10/10] Documentation: Add documentation for VDUSE To: Stefan Hajnoczi Cc: Jason Wang , "Michael S. Tsirkin" , Stefano Garzarella , Parav Pandit , Christoph Hellwig , Christian Brauner , Randy Dunlap , Matthew Wilcox , Al Viro , Jens Axboe , bcrl@kvack.org, Jonathan Corbet , =?UTF-8?Q?Mika_Penttil=C3=A4?= , Dan Carpenter , joro@8bytes.org, Greg KH , songmuchun@bytedance.com, virtualization , netdev@vger.kernel.org, kvm , linux-fsdevel@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 6, 2021 at 6:22 PM Stefan Hajnoczi wrote: > > On Tue, Jul 06, 2021 at 11:04:18AM +0800, Yongji Xie wrote: > > On Mon, Jul 5, 2021 at 8:50 PM Stefan Hajnoczi wr= ote: > > > > > > On Mon, Jul 05, 2021 at 11:36:15AM +0800, Jason Wang wrote: > > > > > > > > =E5=9C=A8 2021/7/4 =E4=B8=8B=E5=8D=885:49, Yongji Xie =E5=86=99=E9= =81=93: > > > > > > > OK, I get you now. Since the VIRTIO specification says "Devic= e > > > > > > > configuration space is generally used for rarely-changing or > > > > > > > initialization-time parameters". I assume the VDUSE_DEV_SET_C= ONFIG > > > > > > > ioctl should not be called frequently. > > > > > > The spec uses MUST and other terms to define the precise requir= ements. > > > > > > Here the language (especially the word "generally") is weaker a= nd means > > > > > > there may be exceptions. > > > > > > > > > > > > Another type of access that doesn't work with the VDUSE_DEV_SET= _CONFIG > > > > > > approach is reads that have side-effects. For example, imagine = a field > > > > > > containing an error code if the device encounters a problem unr= elated to > > > > > > a specific virtqueue request. Reading from this field resets th= e error > > > > > > code to 0, saving the driver an extra configuration space write= access > > > > > > and possibly race conditions. It isn't possible to implement th= ose > > > > > > semantics suing VDUSE_DEV_SET_CONFIG. It's another corner case,= but it > > > > > > makes me think that the interface does not allow full VIRTIO se= mantics. > > > > > > > > > > > > Note that though you're correct, my understanding is that config sp= ace is > > > > not suitable for this kind of error propagating. And it would be ve= ry hard > > > > to implement such kind of semantic in some transports. Virtqueue s= hould be > > > > much better. As Yong Ji quoted, the config space is used for > > > > "rarely-changing or intialization-time parameters". > > > > > > > > > > > > > Agreed. I will use VDUSE_DEV_GET_CONFIG in the next version. And = to > > > > > handle the message failure, I'm going to add a return value to > > > > > virtio_config_ops.get() and virtio_cread_* API so that the error = can > > > > > be propagated to the virtio device driver. Then the virtio-blk de= vice > > > > > driver can be modified to handle that. > > > > > > > > > > Jason and Stefan, what do you think of this way? > > > > > > Why does VDUSE_DEV_GET_CONFIG need to support an error return value? > > > > > > > We add a timeout and return error in case userspace never replies to > > the message. > > > > > The VIRTIO spec provides no way for the device to report errors from > > > config space accesses. > > > > > > The QEMU virtio-pci implementation returns -1 from invalid > > > virtio_config_read*() and silently discards virtio_config_write*() > > > accesses. > > > > > > VDUSE can take the same approach with > > > VDUSE_DEV_GET_CONFIG/VDUSE_DEV_SET_CONFIG. > > > > > > > I noticed that virtio_config_read*() only returns -1 when we access a > > invalid field. But in the VDUSE case, VDUSE_DEV_GET_CONFIG might fail > > when we access a valid field. Not sure if it's ok to silently ignore > > this kind of error. > > That's a good point but it's a general VIRTIO issue. Any device > implementation (QEMU userspace, hardware vDPA, etc) can fail, so the > VIRTIO specification needs to provide a way for the driver to detect > this. > > If userspace violates the contract then VDUSE needs to mark the device > broken. QEMU's device emulation does something similar with the > vdev->broken flag. > > The VIRTIO Device Status field DEVICE_NEEDS_RESET bit can be set by > vDPA/VDUSE to indicate that the device is not operational and must be > reset. > It might be a solution. But DEVICE_NEEDS_RESET is not implemented currently. So I'm thinking whether it's ok to add a check of DEVICE_NEEDS_RESET status bit in probe function of virtio device driver (e.g. virtio-blk driver). Then VDUSE can make use of it to fail device initailization when configuration space access failed. Thanks, Yongji