From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DCD6C433E6 for ; Thu, 18 Mar 2021 03:33:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2BD564F10 for ; Thu, 18 Mar 2021 03:33:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230192AbhCRDdC (ORCPT ); Wed, 17 Mar 2021 23:33:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28384 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229880AbhCRDcZ (ORCPT ); Wed, 17 Mar 2021 23:32:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616038344; 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=jLTPt0xOZQl9IIcVBTaP1P5SgdeBnCH6KEmvNhfyD0k=; b=AEgF7MEhf4DplFSfJ8eT+AI25s1ztyeJ534JLSgNSs+oEOI0K3HXd+sIPg0HKg5Cm7hzeo 7yZ5u1fszkvA0VGWQbI+YodlRkwVUPufyDskjjVsCamwoz5WpPi5d39dtFjPcI6ctmE6ti lIDCEWtGWDzOOZBUIhEiUcFCtglfVWM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-211-e1GUImQ-P96rYKksfeWs3g-1; Wed, 17 Mar 2021 23:32:22 -0400 X-MC-Unique: e1GUImQ-P96rYKksfeWs3g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 846D31084C83; Thu, 18 Mar 2021 03:32:20 +0000 (UTC) Received: from wangxiaodeMacBook-Air.local (ovpn-13-131.pek2.redhat.com [10.72.13.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 923922B431; Thu, 18 Mar 2021 03:31:58 +0000 (UTC) Subject: Re: [PATCH v4 14/14] vdpa_sim_blk: add support for vdpa management tool To: Stefano Garzarella , virtualization@lists.linux-foundation.org Cc: netdev@vger.kernel.org, Xie Yongji , Laurent Vivier , Stefan Hajnoczi , linux-kernel@vger.kernel.org, Max Gurtovoy , Parav Pandit , "Michael S. Tsirkin" , kvm@vger.kernel.org References: <20210315163450.254396-1-sgarzare@redhat.com> <20210315163450.254396-15-sgarzare@redhat.com> From: Jason Wang Message-ID: <94bb9e5a-a1b9-2e0d-d5ec-c6a3eaebea88@redhat.com> Date: Thu, 18 Mar 2021 11:31:54 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210315163450.254396-15-sgarzare@redhat.com> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ÔÚ 2021/3/16 ÉÏÎç12:34, Stefano Garzarella дµÀ: > Enable the user to create vDPA block simulator devices using the > vdpa management tool: > > # Show vDPA supported devices > $ vdpa mgmtdev show > vdpasim_blk: > supported_classes block > > # Create a vDPA block device named as 'blk0' from the management > # device vdpasim: > $ vdpa dev add mgmtdev vdpasim_blk name blk0 > > # Show the info of the 'blk0' device just created > $ vdpa dev show blk0 -jp > { > "dev": { > "blk0": { > "type": "block", > "mgmtdev": "vdpasim_blk", > "vendor_id": 0, > "max_vqs": 1, > "max_vq_size": 256 > } > } > } > > # Delete the vDPA device after its use > $ vdpa dev del blk0 > > Signed-off-by: Stefano Garzarella Acked-by: Jason Wang > --- > drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 76 +++++++++++++++++++++++----- > 1 file changed, 63 insertions(+), 13 deletions(-) > > diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > index 643ae3bc62c0..5bfe1c281645 100644 > --- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > @@ -37,7 +37,6 @@ > #define VDPASIM_BLK_SEG_MAX 32 > #define VDPASIM_BLK_VQ_NUM 1 > > -static struct vdpasim *vdpasim_blk_dev; > static char vdpasim_blk_id[VIRTIO_BLK_ID_BYTES] = "vdpa_blk_sim"; > > static bool vdpasim_blk_check_range(u64 start_sector, size_t range_size) > @@ -241,11 +240,23 @@ static void vdpasim_blk_get_config(struct vdpasim *vdpasim, void *config) > blk_config->blk_size = cpu_to_vdpasim32(vdpasim, SECTOR_SIZE); > } > > -static int __init vdpasim_blk_init(void) > +static void vdpasim_blk_mgmtdev_release(struct device *dev) > +{ > +} > + > +static struct device vdpasim_blk_mgmtdev = { > + .init_name = "vdpasim_blk", > + .release = vdpasim_blk_mgmtdev_release, > +}; > + > +static int vdpasim_blk_dev_add(struct vdpa_mgmt_dev *mdev, const char *name) > { > struct vdpasim_dev_attr dev_attr = {}; > + struct vdpasim *simdev; > int ret; > > + dev_attr.mgmt_dev = mdev; > + dev_attr.name = name; > dev_attr.id = VIRTIO_ID_BLOCK; > dev_attr.supported_features = VDPASIM_BLK_FEATURES; > dev_attr.nvqs = VDPASIM_BLK_VQ_NUM; > @@ -254,29 +265,68 @@ static int __init vdpasim_blk_init(void) > dev_attr.work_fn = vdpasim_blk_work; > dev_attr.buffer_size = VDPASIM_BLK_CAPACITY << SECTOR_SHIFT; > > - vdpasim_blk_dev = vdpasim_create(&dev_attr); > - if (IS_ERR(vdpasim_blk_dev)) { > - ret = PTR_ERR(vdpasim_blk_dev); > - goto out; > - } > + simdev = vdpasim_create(&dev_attr); > + if (IS_ERR(simdev)) > + return PTR_ERR(simdev); > > - ret = vdpa_register_device(&vdpasim_blk_dev->vdpa, VDPASIM_BLK_VQ_NUM); > + ret = _vdpa_register_device(&simdev->vdpa, VDPASIM_BLK_VQ_NUM); > if (ret) > goto put_dev; > > return 0; > > put_dev: > - put_device(&vdpasim_blk_dev->vdpa.dev); > -out: > + put_device(&simdev->vdpa.dev); > return ret; > } > > -static void __exit vdpasim_blk_exit(void) > +static void vdpasim_blk_dev_del(struct vdpa_mgmt_dev *mdev, > + struct vdpa_device *dev) > { > - struct vdpa_device *vdpa = &vdpasim_blk_dev->vdpa; > + struct vdpasim *simdev = container_of(dev, struct vdpasim, vdpa); > + > + _vdpa_unregister_device(&simdev->vdpa); > +} > + > +static const struct vdpa_mgmtdev_ops vdpasim_blk_mgmtdev_ops = { > + .dev_add = vdpasim_blk_dev_add, > + .dev_del = vdpasim_blk_dev_del > +}; > > - vdpa_unregister_device(vdpa); > +static struct virtio_device_id id_table[] = { > + { VIRTIO_ID_BLOCK, VIRTIO_DEV_ANY_ID }, > + { 0 }, > +}; > + > +static struct vdpa_mgmt_dev mgmt_dev = { > + .device = &vdpasim_blk_mgmtdev, > + .id_table = id_table, > + .ops = &vdpasim_blk_mgmtdev_ops, > +}; > + > +static int __init vdpasim_blk_init(void) > +{ > + int ret; > + > + ret = device_register(&vdpasim_blk_mgmtdev); > + if (ret) > + return ret; > + > + ret = vdpa_mgmtdev_register(&mgmt_dev); > + if (ret) > + goto parent_err; > + > + return 0; > + > +parent_err: > + device_unregister(&vdpasim_blk_mgmtdev); > + return ret; > +} > + > +static void __exit vdpasim_blk_exit(void) > +{ > + vdpa_mgmtdev_unregister(&mgmt_dev); > + device_unregister(&vdpasim_blk_mgmtdev); > } > > module_init(vdpasim_blk_init)