Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1849893rwd; Thu, 18 May 2023 19:14:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7IATfJmaB52EoIexf3DlsdGo/LASBnc9MxhSIU6q7y4axGzZm8g4hj1sbKIROunC0E4C1l X-Received: by 2002:a05:6a20:8e05:b0:102:a593:a161 with SMTP id y5-20020a056a208e0500b00102a593a161mr463095pzj.57.1684462444247; Thu, 18 May 2023 19:14:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684462444; cv=none; d=google.com; s=arc-20160816; b=ABZZ+HfSO5O5nWKpQU0wbypuK4NPfjk0d9KEoPPjp2+dVV8kdKwJ/qNIKBiphzljCb 8PiVMyLpEhR5cdbw/C9qOucZHhhsrtGXQUzcXlKluOXowQY/Rnfy5yddRoIKMrK6vBDf AkRXxYQf2O/WLGSVhq3uBXs1mfqEJwIMFSJH4YUpfnwBlEOFiSZ9qmQmnLrNQwSIxh6t XYLSvFsHYcPoGS+NYSWPZJ6ojxJIlzRNUtJHBDuaOlVK3Gkx/DY2yhmt3EU9Dr4m2qBD OLy7C1yY3dMCYfbMGsNkhD4ijGwleI901V8FH0JS6RY01L0qSQ87hA0aIW5TktSvvmeF fd7g== 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=3LxIDwxX5oZ/H5qgJAleyIOOnzzqbniVCDVAXDLMI3E=; b=wvRxt/TCbwzUnPYo+j92hGLuV5rkB8LIM+vIGnKSZ81teZ+K04or0J+A4ErQSgx2M5 unHqv1dDQIVZWYDDTrvkqz7IumpNJPoTHKSeNR4gWaQ1ROsTDf1fr0QDKudsn5MJua0T UStzEuGzSJGpJuMWXZ8gSlrQ4/78N+dj0mmSksh/6VKuYtt7+EjZXVcq/4EwNp/cvhlK hFPc+MumG43xqC7wuvOBGlZ0SFgeyDlGar2AMoFBXc5g41/gxZO04eVPWVzxdVVkf3z0 5Q6v3ZRbz1+yV7miaPtQJvqEslHeC0v9JO7VY/WFUQ4P3YFj0FJDX9Fg4vltyoi2M7rM n/qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Cv7iYu6S; 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 d194-20020a6336cb000000b005348954e07asi632481pga.1.2023.05.18.19.13.52; Thu, 18 May 2023 19:14:04 -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=Cv7iYu6S; 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 S229683AbjESCDA (ORCPT + 99 others); Thu, 18 May 2023 22:03:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229807AbjESCC5 (ORCPT ); Thu, 18 May 2023 22:02:57 -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 ESMTPS id 92F8F192 for ; Thu, 18 May 2023 19:02:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684461730; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3LxIDwxX5oZ/H5qgJAleyIOOnzzqbniVCDVAXDLMI3E=; b=Cv7iYu6SVyp9e5//Tgd4aAWT1hqw+IfHCcSqqw30L1fcaGxRbYxbdPlBV+uaXR28RLVXTT CG+a1IE5qIK0javueS90sH0Qk8YEY0GTLkn/nDCLnrQ7QvU6NwIF0KtKKNzPZYqmvskXMr 9pjT19ftr4Sj4nlmuqcqE+58n/kvI7U= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-KvoNogk4OLKgDOxjwQKxiw-1; Thu, 18 May 2023 22:02:09 -0400 X-MC-Unique: KvoNogk4OLKgDOxjwQKxiw-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-4f3a7765189so749137e87.0 for ; Thu, 18 May 2023 19:02:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684461727; x=1687053727; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3LxIDwxX5oZ/H5qgJAleyIOOnzzqbniVCDVAXDLMI3E=; b=EnP1ZZIU7vpyAr0IQg68Dpc1AzTAI1SXRJzF512qSMHclc8sBYqa7V2F9v2BH7ugzB MTsoguCZsyITSUsHHfk1vAYluPCdTvJvJRnXm2hyd17HWRnq0kjcOifMZPe0GM+acKgi 9+MDLTG0yb1zO5aQ2bR9nhqRW1NU/UYvLbLfnCfCqHGJ3WWj7gWrhCh/qv+uy2kE24Fm N+SSqbu3mkH+UcTteGRTFjvNeLuN43MCVpj3oXijvPOz3f4CyCu+hNw+dTscIl+Y+Zg5 902Y11ge/93LdH4hm4YwEDyePrkn3u3V5JiZvUv6UUuR1N0c7IFpB1aBZqBLAMED5EOJ YGTg== X-Gm-Message-State: AC+VfDzKV9YIMaX8w+5DfQus51Ql7X+FK2xqWi34JmpsauGIoazgUj7j CT1x4yF43QNs8dRtb9fT8azeYmAoRN5ZRlyZAibPjNVzfST5QYQzyFJYqnKMpDrEvjj6Iix+J/D ZeU6ohmgTqEwMg9VjxXvfkuTI4utGfONecb2b607R X-Received: by 2002:ac2:5612:0:b0:4ed:c7cc:6f12 with SMTP id v18-20020ac25612000000b004edc7cc6f12mr210041lfd.34.1684461727672; Thu, 18 May 2023 19:02:07 -0700 (PDT) X-Received: by 2002:ac2:5612:0:b0:4ed:c7cc:6f12 with SMTP id v18-20020ac25612000000b004edc7cc6f12mr210035lfd.34.1684461727327; Thu, 18 May 2023 19:02:07 -0700 (PDT) MIME-Version: 1.0 References: <20230427104428.862643-1-mie@igel.co.jp> <20230427104428.862643-4-mie@igel.co.jp> In-Reply-To: From: Jason Wang Date: Fri, 19 May 2023 10:01:56 +0800 Message-ID: Subject: Re: [RFC PATCH v2 3/3] PCI: endpoint: Add EP function driver to provide virtio-console functionality To: Shunsuke Mie Cc: Lorenzo Pieralisi , =?UTF-8?Q?Krzysztof_Wilczy=C5=84ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Bjorn Helgaas , "Michael S. Tsirkin" , Frank Li , Jon Mason , Randy Dunlap , Ren Zhijie , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, virtualization@lists.linux-foundation.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=unavailable 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 On Thu, May 18, 2023 at 5:54=E2=80=AFPM Shunsuke Mie wrote= : > > Gentle ping ... > > > Thanks, > > Shunsuke. > > On 2023/05/10 12:17, Shunsuke Mie wrote: > > Hi Json, > > 2023=E5=B9=B45=E6=9C=888=E6=97=A5(=E6=9C=88) 13:03 Jason Wang : > >> On Thu, Apr 27, 2023 at 6:44=E2=80=AFPM Shunsuke Mie = wrote: > >>> Add a new PCIe endpoint function driver that works as a pci virtio-co= nsole > >>> device. The console connect to endpoint side console. It enables to > >>> communicate PCIe host and endpoint. > >>> > >>> Architecture is following: > >>> > >>> =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 =E2=94= =8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=AC=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=90 > >>> =E2=94=82virtioe =E2=94=82 =E2=94=82 = =E2=94=82virtio =E2=94=82 > >>> =E2=94=82console drv =E2=94=82 =E2=94=9C=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 =E2=94=82console d= rv =E2=94=82 > >>> =E2=94=9C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=A4 =E2=94= =82(virtio console=E2=94=82 =E2=94=9C=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=A4 > >>> =E2=94=82 virtio bus =E2=94=82 =E2=94=82 device) =E2= =94=82=E2=97=84=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=96=BA=E2=94=82 virti= o bus =E2=94=82 > >>> =E2=94=9C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=A4 =E2=94= =9C---------------=E2=94=A4 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=A4 > >>> =E2=94=82 =E2=94=82 =E2=94=82 pci ep virtio =E2= =94=82 =E2=94=82 > >>> =E2=94=82 pci bus =E2=94=82 =E2=94=82 console drv =E2= =94=82 =E2=94=82 > >>> =E2=94=82 =E2=94=82 pcie =E2=94=9C=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=A4 =E2= =94=82 > >>> =E2=94=82 =E2=94=82 =E2=97=84=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=96=BA =E2=94=82 pci ep Bus =E2=94=82 = =E2=94=82 > >>> =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 =E2=94= =94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=B4=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=98 > >>> PCIe Root PCIe Endpoint > >>> > >> I think it might only works for peer devices like: > >> > >> net, console or vsock. > > Could you tell me what "peer devices" means? I meant, for example we know in the case of virtio-net, TX can talk with RX belonging to another device directly. But this is not the case for other devices like virito-blk. > > > >> So there're many choices here, I'd like to know what's the reason for > >> you to implement a mediation. > >> > >> An alternative is to implement a dedicated net, console and vsock > >> driver for vringh (CAIF somehow works like this). This would have > >> better performance. > > Does it mean that the driver also functions as a network driver directl= y? I meant, e.g in the case of networking, you can have a dedicated driver with two vringh in the endpoint side. The benefit is the performance, no need for the (datapath) mediation. But if we don't care about the performance, this proposal seems to be fine. Thanks > >> > >>> This driver has two roles. The first is as a PCIe endpoint virtio con= sole > >>> function, which is implemented using the PCIe endpoint framework and = PCIe > >>> EP virtio helpers. The second is as a virtual virtio console device > >>> connected to the virtio bus on PCIe endpoint Linux. > >>> > >>> Communication between the two is achieved by copying the virtqueue da= ta > >>> between PCIe root and endpoint, respectively. > >>> > >>> This is a simple implementation and does not include features of > >>> virtio-console such as MULTIPORT, EMERG_WRITE, etc. As a result, each > >>> virtio console driver only displays /dev/hvc0. > >>> > >>> As an example of usage, by setting getty to /dev/hvc0, it is possible= to > >>> login to another host. > >>> > >>> Signed-off-by: Shunsuke Mie > >>> --- > >>> Changes from v2: > >>> - Change to use copy functions between kiovs of pci-epf-virtio. > >>> > >>> drivers/pci/endpoint/functions/Kconfig | 12 + > >>> drivers/pci/endpoint/functions/Makefile | 1 + > >>> drivers/pci/endpoint/functions/pci-epf-vcon.c | 596 +++++++++++++++= +++ > >>> 3 files changed, 609 insertions(+) > >>> create mode 100644 drivers/pci/endpoint/functions/pci-epf-vcon.c > >>> > >>> diff --git a/drivers/pci/endpoint/functions/Kconfig b/drivers/pci/end= point/functions/Kconfig > >>> index fa1a6a569a8f..9ce2698b67e1 100644 > >>> --- a/drivers/pci/endpoint/functions/Kconfig > >>> +++ b/drivers/pci/endpoint/functions/Kconfig > >>> @@ -44,3 +44,15 @@ config PCI_EPF_VIRTIO > >>> select VHOST_RING_IOMEM > >>> help > >>> Helpers to implement PCI virtio Endpoint function > >>> + > >>> +config PCI_EPF_VCON > >>> + tristate "PCI Endpoint virito-console driver" > >>> + depends on PCI_ENDPOINT > >>> + select VHOST_RING > >>> + select PCI_EPF_VIRTIO > >>> + help > >>> + PCIe Endpoint virtio-console function implementatino. This = module > >>> + enables to show the virtio-console as pci device to PCIe ho= st side, and > >>> + another virtual virtio-console device registers to endpoint= system. > >>> + Those devices are connected virtually and can communicate e= ach other. > >>> + > >>> diff --git a/drivers/pci/endpoint/functions/Makefile b/drivers/pci/en= dpoint/functions/Makefile > >>> index a96f127ce900..b4056689ce33 100644 > >>> --- a/drivers/pci/endpoint/functions/Makefile > >>> +++ b/drivers/pci/endpoint/functions/Makefile > >>> @@ -7,3 +7,4 @@ obj-$(CONFIG_PCI_EPF_TEST) +=3D pci-epf-= test.o > >>> obj-$(CONFIG_PCI_EPF_NTB) +=3D pci-epf-ntb.o > >>> obj-$(CONFIG_PCI_EPF_VNTB) +=3D pci-epf-vntb.o > >>> obj-$(CONFIG_PCI_EPF_VIRTIO) +=3D pci-epf-virtio.o > >>> +obj-$(CONFIG_PCI_EPF_VCON) +=3D pci-epf-vcon.o > >>> diff --git a/drivers/pci/endpoint/functions/pci-epf-vcon.c b/drivers/= pci/endpoint/functions/pci-epf-vcon.c > >>> new file mode 100644 > >>> index 000000000000..31f4247cd10f > >>> --- /dev/null > >>> +++ b/drivers/pci/endpoint/functions/pci-epf-vcon.c > >>> @@ -0,0 +1,596 @@ > >>> +// SPDX-License-Identifier: GPL-2.0 > >>> +/* > >>> + * PCI Endpoint function driver to impliment virtio-console device > >>> + * functionality. > >>> + */ > >>> +#include > >>> +#include > >>> +#include > >>> +#include > >>> +#include > >>> + > >>> +#include "pci-epf-virtio.h" > >>> + > >>> +static int virtio_queue_size =3D 0x100; > >>> +module_param(virtio_queue_size, int, 0444); > >>> +MODULE_PARM_DESC(virtio_queue_size, "A length of virtqueue"); > >>> + > >>> +struct epf_vcon { > >>> + /* To access virtqueues on remote host */ > >>> + struct epf_virtio evio; > >>> + struct vringh_kiov *rdev_iovs; > >>> + > >>> + /* To register a local virtio bus */ > >>> + struct virtio_device vdev; > >>> + > >>> + /* To access virtqueus of local host driver */ > >>> + struct vringh *vdev_vrhs; > >>> + struct vringh_kiov *vdev_iovs; > >>> + struct virtqueue **vdev_vqs; > >>> + > >>> + /* For transportation and notification */ > >>> + struct workqueue_struct *task_wq; > >>> + struct work_struct raise_irq_work, rx_work, tx_work; > >>> + > >>> + /* To retain virtio features. It is commonly used local and r= emote. */ > >>> + u64 features; > >>> + > >>> + /* To show a status whether this driver is ready and the remo= te is connected */ > >>> + bool connected; > >>> +}; > >>> + > >>> +enum { > >>> + VCON_VIRTQUEUE_RX, > >>> + VCON_VIRTQUEUE_TX, > >>> + // Should be end of enum > >>> + VCON_VIRTQUEUE_NUM > >>> +}; > >> It would be better if we can split the console specific thing out, > >> then it allows us to do ethernet and vsock in the future. > > I'm planning to implement each virtio device in a separate file. > > https://lwn.net/Articles/922124/ > > > > > > > >> Thanks > >> > > Best regards, > > Shunsuke >