From nobody Wed Apr 24 08:59:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1633700217; cv=none; d=zohomail.com; s=zohoarc; b=mGPW8Cz5Vitp/zqceVw7RjosMRpkwpqfrx++QVTACEWQH78joBECVhFTIFopa47CwPLkObHGMwdjq2F0xcc/iiq38hEhVfstGM4skSg4i5+Hhp8bdeXICnHn85hgwWBGRg+O14Eg/plZ7mDzn1SLYiSJbWPVSskbe1r8RXV9W8I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633700217; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aOjODVqE3mI7ZA3cSCIXOVZGgsm9P5SR8aFH2fWUDkU=; b=JBhAfSUE5DuD9xrCOjUglYyxoAXvJ5+70X5wAKbLkDrhOv6evEzu2ophlGtvecpsxL9XMFKmY8+ziVCNyeIIr20XkiQ6BiHZ03RCOK1GWrwhWZMysZ7COxpgayGaay4r+dMys8CbSbUDOk3wIQUtVuiid1cc9hj8KqN0w+qVygs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1633700217397602.1421671863591; Fri, 8 Oct 2021 06:36:57 -0700 (PDT) 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-38-ed2rPjXlPRulfNpq1QNBIg-1; Fri, 08 Oct 2021 09:36:49 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F2E8319067EC; Fri, 8 Oct 2021 13:35:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D1B7A60C05; Fri, 8 Oct 2021 13:35:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 896C11801241; Fri, 8 Oct 2021 13:35:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 198DZCc0026063 for ; Fri, 8 Oct 2021 09:35:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id DB3C619741; Fri, 8 Oct 2021 13:35:11 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.204]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1D0A19729; Fri, 8 Oct 2021 13:35:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633700216; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=aOjODVqE3mI7ZA3cSCIXOVZGgsm9P5SR8aFH2fWUDkU=; b=L74VZH/KKjyFJMSAh6VvuSNreqIWe2mMYZWITxMcktTdMShWX9PwB0rK/lmXqrnZvbTZ2H sKVezHYRPVdnpKyxbcaMJ5c5fBKR1BwjaTF5M9TN3ytJtdPMlLAK5cG02VNZcLM448LM53 7KlASo+1G88cZ8ePz3Nyfr66Z2ZY6+c= X-MC-Unique: ed2rPjXlPRulfNpq1QNBIg-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH v2 03/15] net/vhost-vdpa: Fix device compatibility check Date: Fri, 8 Oct 2021 15:34:30 +0200 Message-Id: <20211008133442.141332-4-kwolf@redhat.com> In-Reply-To: <20211008133442.141332-1-kwolf@redhat.com> References: <20211008133442.141332-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, damien.hedde@greensocs.com, pkrempa@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, mst@redhat.com, libvir-list@redhat.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, vsementsov@virtuozzo.com, lvivier@redhat.com, its@irrelevant.dk, pbonzini@redhat.com, eblake@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1633700220304100002 Content-Type: text/plain; charset="utf-8" vhost-vdpa works only with specific devices. At startup, it second guesses what the command line option handling will do and error out if it thinks a non-virtio device will attach to them. This second guessing is not only ugly, it can lead to wrong error messages ('-device floppy,netdev=3Dfoo' should complain about an unknown property, not about the wrong kind of network device being attached) and completely ignores hotplugging. Drop the old checks and implement .check_peer_type() instead to fix this. As a nice side effect, it also removes one more dependency on the legacy QemuOpts infrastructure and even reduces the code size. Signed-off-by: Kevin Wolf Acked-by: Jason Wang Reviewed-by: Damien Hedde --- net/vhost-vdpa.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 912686457c..6dc68d8677 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -147,12 +147,26 @@ static bool vhost_vdpa_has_ufo(NetClientState *nc) =20 } =20 +static bool vhost_vdpa_check_peer_type(NetClientState *nc, ObjectClass *oc, + Error **errp) +{ + const char *driver =3D object_class_get_name(oc); + + if (!g_str_has_prefix(driver, "virtio-net-")) { + error_setg(errp, "vhost-vdpa requires frontend driver virtio-net-*= "); + return false; + } + + return true; +} + static NetClientInfo net_vhost_vdpa_info =3D { .type =3D NET_CLIENT_DRIVER_VHOST_VDPA, .size =3D sizeof(VhostVDPAState), .cleanup =3D vhost_vdpa_cleanup, .has_vnet_hdr =3D vhost_vdpa_has_vnet_hdr, .has_ufo =3D vhost_vdpa_has_ufo, + .check_peer_type =3D vhost_vdpa_check_peer_type, }; =20 static int net_vhost_vdpa_init(NetClientState *peer, const char *device, @@ -179,24 +193,6 @@ static int net_vhost_vdpa_init(NetClientState *peer, c= onst char *device, return ret; } =20 -static int net_vhost_check_net(void *opaque, QemuOpts *opts, Error **errp) -{ - const char *name =3D opaque; - const char *driver, *netdev; - - driver =3D qemu_opt_get(opts, "driver"); - netdev =3D qemu_opt_get(opts, "netdev"); - if (!driver || !netdev) { - return 0; - } - if (strcmp(netdev, name) =3D=3D 0 && - !g_str_has_prefix(driver, "virtio-net-")) { - error_setg(errp, "vhost-vdpa requires frontend driver virtio-net-*= "); - return -1; - } - return 0; -} - int net_init_vhost_vdpa(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { @@ -204,10 +200,5 @@ int net_init_vhost_vdpa(const Netdev *netdev, const ch= ar *name, =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); opts =3D &netdev->u.vhost_vdpa; - /* verify net frontend */ - if (qemu_opts_foreach(qemu_find_opts("device"), net_vhost_check_net, - (char *)name, errp)) { - return -1; - } return net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, opts->vhostdev= ); } --=20 2.31.1