From patchwork Mon May 16 10:39:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 572976 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1590:0:0:0:0 with SMTP id w16csp996173map; Mon, 16 May 2022 05:02:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9KgND2XWXGa5ccSeV+sKqY49sabz2KoN+6Sto6F84yaQzwuL/r7YWP0r8VpWCa6WyA3Y/ X-Received: by 2002:a9f:3592:0:b0:365:ef07:68c9 with SMTP id t18-20020a9f3592000000b00365ef0768c9mr5742753uad.60.1652702577003; Mon, 16 May 2022 05:02:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652702576; cv=none; d=google.com; s=arc-20160816; b=a6xRf2tVuPyHQdedAMyMKN/2YMRygNm6WzreowwETxrqvcUclMEHLzwnaGwUyHWsLZ NBDCrJXzBCfvSd9V+hYZlIx/m1Wa8zYsqlZUjgah5YjbODvomRxRL8uPZQQosry3Y0q+ 5zaRFQcY4bEwq0w6dH7t/DVqDaID/FSOobS1X9+YBr7Gj4yeDXn+y6Ew51bv69kag8yK blApbAtd7eIc8HAw0azTR3Z/NtuZseuQ3H+rtbCVIvY9ReKB6+9hS3i/lgPLwh84LGrV gFrcIkdfxCtnoYUbtYz806tXpF7p1vl93igsgD+nqvHeQOHPW9Z4JjoeD4eJpYwGvB8T d3lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=8fsb11g7Z/r9felQ/mYfcCmnlXTX8/HfVlLGPmxAWLE=; b=zMgvRM8u/+o5DqNq6FJ1uTHjNZxDGHv80NUAhvPbEcF+p8nw5j+G02CgGqifRQapRS /f+mk+lvJh4wsZ4/WfgXR1YytZGy7EWLVrscWwmbvTtrmG6OvS4omX2DzUAaKR2izWzR Cx+gOSebE2EHnhPDcPEAhEp8JRmUSoZfeOVb4l9Tn7Zt6qHbx3jq1yUrHD4yIRa6FTOr du0foCwlvqIMBny1n1sfnL4tUJpbCn3ywE8I34zcO2gREZOWkoACiEcAxdunUgGH2XkP qWHwZQwNke4898QW+Ow2JaE9UIdqAH9cg2wwpCLnW6/t0CEFb/o4P+jYijrduPBVP8zS Nwew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bGr9sCMs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b139-20020a1f1b91000000b00344d2e38cc2si1363451vkb.177.2022.05.16.05.02.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 May 2022 05:02:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bGr9sCMs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:37342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nqZRA-0007Ga-GW for patch@linaro.org; Mon, 16 May 2022 08:02:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqY8b-0001Rr-4X for qemu-devel@nongnu.org; Mon, 16 May 2022 06:39:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:53239) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqY8Z-0005ev-AF for qemu-devel@nongnu.org; Mon, 16 May 2022 06:39:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652697578; 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=8fsb11g7Z/r9felQ/mYfcCmnlXTX8/HfVlLGPmxAWLE=; b=bGr9sCMsurGKrcM/sTkwwnlPaNhSrTRizaj+IcMVNoVWkP7Dmn40rfF1pw6awUliiSbZWQ ZzTBsg99hT8TJBZs0TSKCv63/hreuA+TtHlkJlWNNaAB/P0Zn+A+kPBkK6hBnbnDKNXaHs lHB16kv8GGpXnPo5XTJt2wqGRorFDVQ= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-581-xnaEZzODPZ6X7ps8samlGA-1; Mon, 16 May 2022 06:39:37 -0400 X-MC-Unique: xnaEZzODPZ6X7ps8samlGA-1 Received: by mail-wr1-f69.google.com with SMTP id u11-20020a056000038b00b0020c9ea8b64fso3787258wrf.2 for ; Mon, 16 May 2022 03:39:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=8fsb11g7Z/r9felQ/mYfcCmnlXTX8/HfVlLGPmxAWLE=; b=3rhvpRZKHzGu6b8lPdTMDko6yaOM9pjPWQLadrIOz93Q9PFAQqxVvccMGEP5twjm+8 5LE4WrifHEElk53bRAagK8Y3BuDhXap7Hl5uXx/qkCWjoonfr2i/s9GOdr5pDDI6wh6v EVNoN+btJuEoeFRrZg1YsBdtvJ+k8IjV5qN45Cw9ScaI/DCmG5/SdIXtvKpCuCOZgJh0 lveqSyUxIS8ZwdpwIlssFjvZ5IFftkDJ7/W9VjIqA1VFCkbe5CjLDFauh55+WrZfgRf9 SSQYL77bDEr73pD5N0QYaHSQVYv2SV/m/Vir74SDyhSh3sUuYXloxhvw6JbbNfZI3h5U 8pCg== X-Gm-Message-State: AOAM533ut6y5R3O69/r+Qq5kiRe7H4cDoGiow8kWpVGIihmT9cIf+buQ yyZBF/15yZYBqcEpsOWtlnwzg0pFUE5cyLcXkOUg92N0nHMP3eEEM/YduxvxvAlzI6G2MnXz6M1 aNHxtLAnakx8yL1JQsImmYGFjAvTj2jDFk7TeAlDyeh3ElnbzLnOECn6hdT3c X-Received: by 2002:a5d:64a5:0:b0:20d:af2:ed9f with SMTP id m5-20020a5d64a5000000b0020d0af2ed9fmr2524670wrp.271.1652697576186; Mon, 16 May 2022 03:39:36 -0700 (PDT) X-Received: by 2002:a5d:64a5:0:b0:20d:af2:ed9f with SMTP id m5-20020a5d64a5000000b0020d0af2ed9fmr2524642wrp.271.1652697575856; Mon, 16 May 2022 03:39:35 -0700 (PDT) Received: from redhat.com ([2.55.141.66]) by smtp.gmail.com with ESMTPSA id j10-20020adfc68a000000b0020c635ca28bsm9225755wrg.87.2022.05.16.03.39.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 03:39:35 -0700 (PDT) Date: Mon, 16 May 2022 06:39:33 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Alex =?utf-8?q?Benn=C3=A9e?= , Maxime Coquelin , Stefan Hajnoczi , Raphael Norwitz , Paolo Bonzini , Fam Zheng Subject: [PULL 68/91] hw/virtio/vhost-user: don't suppress F_CONFIG when supported Message-ID: <20220516095448.507876-69-mst@redhat.com> References: <20220516095448.507876-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220516095448.507876-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée Previously we would silently suppress VHOST_USER_PROTOCOL_F_CONFIG during the protocol negotiation if the QEMU stub hadn't implemented the vhost_dev_config_notifier. However this isn't the only way we can handle config messages, the existing vdc->get/set_config can do this as well. Lightly re-factor the code to check for both potential methods and instead of silently squashing the feature error out. It is unlikely that a vhost-user backend expecting to handle CONFIG messages will behave correctly if they never get sent. Fixes: 1c3e5a2617 ("vhost-user: back SET/GET_CONFIG requests with a protocol feature") Cc: Maxime Coquelin Cc: Michael S. Tsirkin Cc: Stefan Hajnoczi Signed-off-by: Alex Bennée Message-Id: <20220321153037.3622127-13-alex.bennee@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost-user.h | 1 + hw/scsi/vhost-user-scsi.c | 1 + hw/virtio/vhost-user.c | 44 ++++++++++++++++++++++++---------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h index e44a41bb70..6e0e8a71a3 100644 --- a/include/hw/virtio/vhost-user.h +++ b/include/hw/virtio/vhost-user.h @@ -22,6 +22,7 @@ typedef struct VhostUserState { CharBackend *chr; VhostUserHostNotifier notifier[VIRTIO_QUEUE_MAX]; int memory_slots; + bool supports_config; } VhostUserState; bool vhost_user_init(VhostUserState *user, CharBackend *chr, Error **errp); diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index 1b2f7eed98..9be21d07ee 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -121,6 +121,7 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp) vsc->dev.backend_features = 0; vqs = vsc->dev.vqs; + s->vhost_user.supports_config = true; ret = vhost_dev_init(&vsc->dev, &s->vhost_user, VHOST_BACKEND_TYPE_USER, 0, errp); if (ret < 0) { diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 6c8f722262..b0d417651d 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1949,14 +1949,15 @@ static int vhost_user_postcopy_notifier(NotifierWithReturn *notifier, static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque, Error **errp) { - uint64_t features, protocol_features, ram_slots; + uint64_t features, ram_slots; struct vhost_user *u; + VhostUserState *vus = (VhostUserState *) opaque; int err; assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER); u = g_new0(struct vhost_user, 1); - u->user = opaque; + u->user = vus; u->dev = dev; dev->opaque = u; @@ -1967,6 +1968,10 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque, } if (virtio_has_feature(features, VHOST_USER_F_PROTOCOL_FEATURES)) { + bool supports_f_config = vus->supports_config || + (dev->config_ops && dev->config_ops->vhost_dev_config_notifier); + uint64_t protocol_features; + dev->backend_features |= 1ULL << VHOST_USER_F_PROTOCOL_FEATURES; err = vhost_user_get_u64(dev, VHOST_USER_GET_PROTOCOL_FEATURES, @@ -1976,19 +1981,34 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque, return -EPROTO; } - dev->protocol_features = - protocol_features & VHOST_USER_PROTOCOL_FEATURE_MASK; + /* + * We will use all the protocol features we support - although + * we suppress F_CONFIG if we know QEMUs internal code can not support + * it. + */ + protocol_features &= VHOST_USER_PROTOCOL_FEATURE_MASK; - if (!dev->config_ops || !dev->config_ops->vhost_dev_config_notifier) { - /* Don't acknowledge CONFIG feature if device doesn't support it */ - dev->protocol_features &= ~(1ULL << VHOST_USER_PROTOCOL_F_CONFIG); - } else if (!(protocol_features & - (1ULL << VHOST_USER_PROTOCOL_F_CONFIG))) { - error_setg(errp, "Device expects VHOST_USER_PROTOCOL_F_CONFIG " - "but backend does not support it."); - return -EINVAL; + if (supports_f_config) { + if (!virtio_has_feature(protocol_features, + VHOST_USER_PROTOCOL_F_CONFIG)) { + error_setg(errp, "vhost-user device %s expecting " + "VHOST_USER_PROTOCOL_F_CONFIG but the vhost-user backend does " + "not support it.", dev->vdev->name); + return -EPROTO; + } + } else { + if (virtio_has_feature(protocol_features, + VHOST_USER_PROTOCOL_F_CONFIG)) { + warn_reportf_err(*errp, "vhost-user backend supports " + "VHOST_USER_PROTOCOL_F_CONFIG for " + "device %s but QEMU does not.", + dev->vdev->name); + protocol_features &= ~(1ULL << VHOST_USER_PROTOCOL_F_CONFIG); + } } + /* final set of protocol features */ + dev->protocol_features = protocol_features; err = vhost_user_set_protocol_features(dev, dev->protocol_features); if (err < 0) { error_setg_errno(errp, EPROTO, "vhost_backend_init failed");