Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4908943iog; Wed, 22 Jun 2022 08:07:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sDUMOed4zWbuHQFkXfbUVClWhjWii1QtuoFK1JEKsS1phpFKV15Ckfh9U1cn1LtbDuBCpX X-Received: by 2002:a17:902:c285:b0:16a:1631:afe3 with SMTP id i5-20020a170902c28500b0016a1631afe3mr20418678pld.93.1655910434506; Wed, 22 Jun 2022 08:07:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655910434; cv=none; d=google.com; s=arc-20160816; b=uHowVMBJDt4D5XmBYygbPxD0LKO9QCUXOBRHcZdXGksUfKDohgCfci7RmG1rs7DPk4 R4PuwC+7DHyd6M0Mj0mctiK9QvT9lSndENWQ1HeeDwtpxqfceGc2+LGzazgKO5FlsZUz F7/pEYk9ji/buoIOKPxIK9JiYQv73fKR2XD4rDUAyj16mm2Q2NZKcyxy2a1efqGJyUOO mSI5x0XghRwtpHNIr2HVxL9n2im/6YXPH2J5mG6O5XJE6MvqijIrSHoGF19gAO5zMGUA JqfyflBSqDFL+Eo3XWwn2zPGC6qEYPnFfI4lqILD2H5lt2aWqxS7UmcxkMO6AQeVW4WH KH8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=/2IQy+E40urhXFacB8Vj36ycB9yteHAjL3Hd6nT3fLI=; b=Rs4MOYrTQFws16bBIoL5ywsyDk1FvVJMK++1mSG74LCQ7lw128+on+wqCjzNwwLJqo lvvXshGVYOjtqGW/t5vWiaJj5tWKIekv15yC/If+VSYRAe8OA3Q1CO9zyP7zdFf3VoB5 gnP45z23I6vBuWhdJIotaQLG26TrwJtD9bQ+7SsFOr+8AOgLbeIL9+UovV0EHWOcu3Gp mTHxpm3bs/vKbdd3Xcq0CXh4hnDqw/3hrbQv0Fr87r1D+q/xTjm29wbhblSY4mEihr5T VnNkUPsCrrLmiWvMLAsuGDxOV2Prq7FR6/gQA6B8Z1xTKXTdo4oOZ9Uign3ZVMEtJJdL UAbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Vokv8DTI; 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 t9-20020a170902a5c900b00163dc4774b9si18567774plq.39.2022.06.22.08.07.01; Wed, 22 Jun 2022 08: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=Vokv8DTI; 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 S1358948AbiFVPFe (ORCPT + 99 others); Wed, 22 Jun 2022 11:05:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358467AbiFVPF2 (ORCPT ); Wed, 22 Jun 2022 11:05:28 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2D31832069 for ; Wed, 22 Jun 2022 08:05:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655910325; 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:references:references; bh=/2IQy+E40urhXFacB8Vj36ycB9yteHAjL3Hd6nT3fLI=; b=Vokv8DTIhrQmfSx6OwfyQua+cd1PXOhnU4LCW9Bvhbjud8gpV556PwzrAetBNSJ7LpKAgK 2REaD32yjarYF6sfX1y0DODUWTI4EpHZb4WG57a3DFRwmpk4hyFOPZu/SMbYNGH4a8fn5c fmuHsA+ehEskpVDaWIt0762dfj/8I9A= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-43-BEKo-trQPKym2Bj7SMQhyg-1; Wed, 22 Jun 2022 11:05:23 -0400 X-MC-Unique: BEKo-trQPKym2Bj7SMQhyg-1 Received: by mail-qk1-f197.google.com with SMTP id bi36-20020a05620a31a400b006a79f0706e5so20270529qkb.2 for ; Wed, 22 Jun 2022 08:05:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/2IQy+E40urhXFacB8Vj36ycB9yteHAjL3Hd6nT3fLI=; b=dO/fdvm1vi8bTXc79SbMPlwTiKli+kUAe/915SQgq/E/0xa933CYHl+mYg+MToN41l eemIQBIGqjjj4X9n5LA6YUCtp5prsdGJXfPD02+E3Fan4roTJlh92bo32YpL4yz+ojHC VgAJaIfrTvJrl+qwkBS55jV4WU01PItrbdqWnWTGMl1rqWUSq4ILHrv4qWPZHITCD/0b 4U55pSf0ijLngNiTbUfkdQA6mClWMwuF4S9lZf2Z8j1+g67VkXk4TIFuVEeFoMJsmlNF 4xNrJ05ePqKHgp2hwAtVodjglQe0yUupZqHilIfSj8qIpGqtPNUJzh/84ZqQIWvkXZXn m79w== X-Gm-Message-State: AJIora95VL8wOb4qAunVQ2U2UNtzemXslZ8iXVvK2S4pdEYQRF5XFZvf 9UNRitfoNeiGZLENn7hW83rcyIo4bhc/jpzojR/WyyqqWX7JzAm6S+uFRcad2r3qZY4JhsVj9sR gjqyY449BBjynNW/MTyqx81B3AhnituA0kz/UcKny X-Received: by 2002:a37:9e8d:0:b0:6ae:e97f:0 with SMTP id h135-20020a379e8d000000b006aee97f0000mr771683qke.255.1655910321124; Wed, 22 Jun 2022 08:05:21 -0700 (PDT) X-Received: by 2002:a37:9e8d:0:b0:6ae:e97f:0 with SMTP id h135-20020a379e8d000000b006aee97f0000mr771619qke.255.1655910320506; Wed, 22 Jun 2022 08:05:20 -0700 (PDT) MIME-Version: 1.0 References: <20220330180436.24644-1-gdawar@xilinx.com> <20220330180436.24644-20-gdawar@xilinx.com> In-Reply-To: From: Eugenio Perez Martin Date: Wed, 22 Jun 2022 17:04:44 +0200 Message-ID: Subject: Re: [PATCH v2 19/19] vdpasim: control virtqueue support To: Stefano Garzarella Cc: Gautam Dawar , Jason Wang , "Michael S. Tsirkin" , Xie Yongji , Gautam Dawar , Longpeng , Eli Cohen , Parav Pandit , Linux Virtualization , kernel list , kvm , netdev , Martin Petrus Hubertus Habets , Harpreet Singh Anand , Martin Porter , Pablo Cascon Katchadourian , Dinan Gunawardena , "Kamde, Tanuj" , habetsm.xilinx@gmail.com, ecree.xilinx@gmail.com, Wu Zongyong , Christophe JAILLET , Zhu Lingshan , Si-Wei Liu , Dan Carpenter , Zhang Min Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.4 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=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 Wed, Jun 22, 2022 at 12:21 PM Eugenio Perez Martin wrote: > > On Tue, Jun 21, 2022 at 5:20 PM Stefano Garzarella wrote: > > > > Hi Gautam, > > > > On Wed, Mar 30, 2022 at 8:21 PM Gautam Dawar wrote: > > > > > > This patch introduces the control virtqueue support for vDPA > > > simulator. This is a requirement for supporting advanced features like > > > multiqueue. > > > > > > A requirement for control virtqueue is to isolate its memory access > > > from the rx/tx virtqueues. This is because when using vDPA device > > > for VM, the control virqueue is not directly assigned to VM. Userspace > > > (Qemu) will present a shadow control virtqueue to control for > > > recording the device states. > > > > > > The isolation is done via the virtqueue groups and ASID support in > > > vDPA through vhost-vdpa. The simulator is extended to have: > > > > > > 1) three virtqueues: RXVQ, TXVQ and CVQ (control virtqueue) > > > 2) two virtqueue groups: group 0 contains RXVQ and TXVQ; group 1 > > > contains CVQ > > > 3) two address spaces and the simulator simply implements the address > > > spaces by mapping it 1:1 to IOTLB. > > > > > > For the VM use cases, userspace(Qemu) may set AS 0 to group 0 and AS 1 > > > to group 1. So we have: > > > > > > 1) The IOTLB for virtqueue group 0 contains the mappings of guest, so > > > RX and TX can be assigned to guest directly. > > > 2) The IOTLB for virtqueue group 1 contains the mappings of CVQ which > > > is the buffers that allocated and managed by VMM only. So CVQ of > > > vhost-vdpa is visible to VMM only. And Guest can not access the CVQ > > > of vhost-vdpa. > > > > > > For the other use cases, since AS 0 is associated to all virtqueue > > > groups by default. All virtqueues share the same mapping by default. > > > > > > To demonstrate the function, VIRITO_NET_F_CTRL_MACADDR is > > > implemented in the simulator for the driver to set mac address. > > > > > > Signed-off-by: Jason Wang > > > Signed-off-by: Gautam Dawar > > > --- > > > drivers/vdpa/vdpa_sim/vdpa_sim.c | 91 ++++++++++++++++++++++------ > > > drivers/vdpa/vdpa_sim/vdpa_sim.h | 2 + > > > drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 88 ++++++++++++++++++++++++++- > > > 3 files changed, 161 insertions(+), 20 deletions(-) > > > > > > diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c > > > index 659e2e2e4b0c..51bd0bafce06 100644 > > > --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c > > > +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c > > > @@ -96,11 +96,17 @@ static void vdpasim_do_reset(struct vdpasim *vdpasim) > > > { > > > int i; > > > > > > - for (i = 0; i < vdpasim->dev_attr.nvqs; i++) > > > + spin_lock(&vdpasim->iommu_lock); > > > + > > > + for (i = 0; i < vdpasim->dev_attr.nvqs; i++) { > > > vdpasim_vq_reset(vdpasim, &vdpasim->vqs[i]); > > > + vringh_set_iotlb(&vdpasim->vqs[i].vring, &vdpasim->iommu[0], > > > + &vdpasim->iommu_lock); > > > + } > > > + > > > + for (i = 0; i < vdpasim->dev_attr.nas; i++) > > > + vhost_iotlb_reset(&vdpasim->iommu[i]); > > > > > > - spin_lock(&vdpasim->iommu_lock); > > > - vhost_iotlb_reset(vdpasim->iommu); > > > spin_unlock(&vdpasim->iommu_lock); > > > > > > vdpasim->features = 0; > > > @@ -145,7 +151,7 @@ static dma_addr_t vdpasim_map_range(struct vdpasim *vdpasim, phys_addr_t paddr, > > > dma_addr = iova_dma_addr(&vdpasim->iova, iova); > > > > > > spin_lock(&vdpasim->iommu_lock); > > > - ret = vhost_iotlb_add_range(vdpasim->iommu, (u64)dma_addr, > > > + ret = vhost_iotlb_add_range(&vdpasim->iommu[0], (u64)dma_addr, > > > (u64)dma_addr + size - 1, (u64)paddr, perm); > > > spin_unlock(&vdpasim->iommu_lock); > > > > > > @@ -161,7 +167,7 @@ static void vdpasim_unmap_range(struct vdpasim *vdpasim, dma_addr_t dma_addr, > > > size_t size) > > > { > > > spin_lock(&vdpasim->iommu_lock); > > > - vhost_iotlb_del_range(vdpasim->iommu, (u64)dma_addr, > > > + vhost_iotlb_del_range(&vdpasim->iommu[0], (u64)dma_addr, > > > (u64)dma_addr + size - 1); > > > spin_unlock(&vdpasim->iommu_lock); > > > > > > @@ -250,8 +256,9 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr) > > > else > > > ops = &vdpasim_config_ops; > > > > > > - vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, 1, > > > - 1, dev_attr->name, false); > > > + vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, > > > + dev_attr->ngroups, dev_attr->nas, > > > + dev_attr->name, false); > > > if (IS_ERR(vdpasim)) { > > > ret = PTR_ERR(vdpasim); > > > goto err_alloc; > > > @@ -278,16 +285,20 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr) > > > if (!vdpasim->vqs) > > > goto err_iommu; > > > > > > - vdpasim->iommu = vhost_iotlb_alloc(max_iotlb_entries, 0); > > > + vdpasim->iommu = kmalloc_array(vdpasim->dev_attr.nas, > > > + sizeof(*vdpasim->iommu), GFP_KERNEL); > > > if (!vdpasim->iommu) > > > goto err_iommu; > > > > > > + for (i = 0; i < vdpasim->dev_attr.nas; i++) > > > + vhost_iotlb_init(&vdpasim->iommu[i], 0, 0); > > > + > > > vdpasim->buffer = kvmalloc(dev_attr->buffer_size, GFP_KERNEL); > > > if (!vdpasim->buffer) > > > goto err_iommu; > > > > > > for (i = 0; i < dev_attr->nvqs; i++) > > > - vringh_set_iotlb(&vdpasim->vqs[i].vring, vdpasim->iommu, > > > + vringh_set_iotlb(&vdpasim->vqs[i].vring, &vdpasim->iommu[0], > > > &vdpasim->iommu_lock); > > > > > > ret = iova_cache_get(); > > > @@ -401,7 +412,11 @@ static u32 vdpasim_get_vq_align(struct vdpa_device *vdpa) > > > > > > static u32 vdpasim_get_vq_group(struct vdpa_device *vdpa, u16 idx) > > > { > > > - return 0; > > > + /* RX and TX belongs to group 0, CVQ belongs to group 1 */ > > > + if (idx == 2) > > > + return 1; > > > + else > > > + return 0; > > > > This code only works for the vDPA-net simulator, since > > vdpasim_get_vq_group() is also shared with other simulators (e.g. > > vdpa_sim_blk), > > That's totally right. > > > should we move this net-specific code into > > vdpa_sim_net.c, maybe adding a callback implemented by the different > > simulators? > > > > At this moment, VDPASIM_BLK_VQ_NUM is fixed to 1, so maybe the right > thing to do for the -rc phase is to check if idx > vdpasim.attr.nvqs? > It's a more general fix. > Actually, that is already checked by vhost/vdpa.c. Taking that into account, is it worth introducing the change for 5.19? I'm totally ok with the change for 5.20. Thanks! > For the general case, yes, a callback should be issued to the actual > simulator so it's not a surprise when VDPASIM_BLK_VQ_NUM increases, > either dynamically or by anyone testing it. > > Thoughts? > > Thanks!