From nobody Wed Sep 17 10:51:38 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F9E2C4332F for ; Wed, 21 Dec 2022 06:18:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232779AbiLUGSH (ORCPT ); Wed, 21 Dec 2022 01:18:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231853AbiLUGRz (ORCPT ); Wed, 21 Dec 2022 01:17:55 -0500 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 279AA1EC70 for ; Tue, 20 Dec 2022 22:17:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671603428; 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=KJgJpF5xZkDorw1tYw0inGkzyUnI/sANbAPj2wEvpBo=; b=PjFa1XX3Cq0LY3yn+ODozah1fPKwB1lsgS4x7FENLAoG46fcaMSPC4Zt6fu+bSpV3344/j gfKltPm3/dece1XDvGNMNZXjaIa0joBM3rhvt5ixjFLOa2Lwun7ylM4Zl4fJPGbbBoUV1Z 4kkEAfImVlf418O7sUkNAt6j2iw1lMI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-134-K258nhXDPxuz3qsE6vOB7A-1; Wed, 21 Dec 2022 01:17:06 -0500 X-MC-Unique: K258nhXDPxuz3qsE6vOB7A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EDB33886462; Wed, 21 Dec 2022 06:17:05 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-236.pek2.redhat.com [10.72.13.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BB022166B26; Wed, 21 Dec 2022 06:17:03 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com Cc: sgarzare@redhat.com, eperezma@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] vdpasim: customize allocation size Date: Wed, 21 Dec 2022 14:16:50 +0800 Message-Id: <20221221061652.15202-3-jasowang@redhat.com> In-Reply-To: <20221221061652.15202-1-jasowang@redhat.com> References: <20221221061652.15202-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Allow individual simulator to customize the allocation size. Signed-off-by: Jason Wang Reviewed-by: Stefano Garzarella --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 8 ++++++-- drivers/vdpa/vdpa_sim/vdpa_sim.h | 1 + drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 1 + drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_= sim.c index 757afef86ba0..55aaa023a6e2 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -253,7 +253,10 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr= *dev_attr, struct vdpa_device *vdpa; struct vdpasim *vdpasim; struct device *dev; - int i, ret =3D -ENOMEM; + int i, ret =3D -EINVAL; + + if (!dev_attr->alloc_size) + goto err_alloc; =20 if (config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) { if (config->device_features & @@ -268,9 +271,10 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr= *dev_attr, else ops =3D &vdpasim_config_ops; =20 + ret =3D -ENOMEM; vdpa =3D __vdpa_alloc_device(NULL, ops, dev_attr->ngroups, dev_attr->nas, - sizeof(struct vdpasim), + dev_attr->alloc_size, dev_attr->name, false); if (IS_ERR(vdpa)) { ret =3D PTR_ERR(vdpa); diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_= sim.h index 0e78737dcc16..51c070a543f1 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h @@ -37,6 +37,7 @@ struct vdpasim_dev_attr { struct vdpa_mgmt_dev *mgmt_dev; const char *name; u64 supported_features; + size_t alloc_size; size_t config_size; size_t buffer_size; int nvqs; diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c b/drivers/vdpa/vdpa_sim/v= dpa_sim_blk.c index c6db1a1baf76..4f7c35f59aa5 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c @@ -378,6 +378,7 @@ static int vdpasim_blk_dev_add(struct vdpa_mgmt_dev *md= ev, const char *name, dev_attr.nvqs =3D VDPASIM_BLK_VQ_NUM; dev_attr.ngroups =3D VDPASIM_BLK_GROUP_NUM; dev_attr.nas =3D VDPASIM_BLK_AS_NUM; + dev_attr.alloc_size =3D sizeof(struct vdpasim); dev_attr.config_size =3D sizeof(struct virtio_blk_config); dev_attr.get_config =3D vdpasim_blk_get_config; dev_attr.work_fn =3D vdpasim_blk_work; diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/v= dpa_sim_net.c index c3cb225ea469..20cd5cdff919 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c @@ -249,6 +249,7 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *md= ev, const char *name, dev_attr.nvqs =3D VDPASIM_NET_VQ_NUM; dev_attr.ngroups =3D VDPASIM_NET_GROUP_NUM; dev_attr.nas =3D VDPASIM_NET_AS_NUM; + dev_attr.alloc_size =3D sizeof(struct vdpasim); dev_attr.config_size =3D sizeof(struct virtio_net_config); dev_attr.get_config =3D vdpasim_net_get_config; dev_attr.work_fn =3D vdpasim_net_work; --=20 2.25.1