From patchwork Mon Jul 10 15:35:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701023 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5243169wrs; Mon, 10 Jul 2023 08:36:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlFXOp8W7TeZnMwq7gm3djjVhUgX7q7RccPCEkSQlnIUWH92n+MuM/nArNdS9fAVGSbNowAO X-Received: by 2002:a05:622a:507:b0:403:a9cb:dd58 with SMTP id l7-20020a05622a050700b00403a9cbdd58mr5703117qtx.51.1689003408726; Mon, 10 Jul 2023 08:36:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003408; cv=none; d=google.com; s=arc-20160816; b=zgDoqRyQeQQvZ4KBmls7fiw70K+eMqRephp0utNLrr/d8RdmNv5ltTBwGS6Uj5vWfh /lkEgL5JIyhIZuRJypam5nauoAz3cqwiP7yRnrPsb6Dsx5Z9PgnWpjK40RHN9ZZQRbrX KatyyH0TiV3buwZ/p7zQs1IDsw7KhSZxn8/KameBhluZGQ2gVn/ECoX6rCLN+NpPIhz8 8m0XwgyAd/qAXWNtrW4qNJGy0u27BdxzfX2YsfaXrusTWpMDYIRpAgmysQD+E877b3MU kGMHf6Fi5PX0KUC3DZhDkb5k3a9fXZu6Uo2RagUM+Yg/65OzosOzFNWNTnBif5XrpADB aMuA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2VTCVQrd6KCn5j7u4ggdRsXsalHDUZEasAWYhlhI0Zk=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=I5ZeXLk9VaZhkIZxeyAixpp0vRbxYhCWYQX3Rh4jbvWw22IKa1S5gCB+Rt6gybyZjS 4ShmCXmvgMtUwZouc8waHTZtqD9FmrvUIZ4a6jgkxeIJre1DBQlBo4ZJyUV1K5My1h0t o2K4tQoCbgDBExXP0xQ5OW0G0yBsC4xKy6jRrPSHdxWGxJHdA+d90z7tXZxKx8XR50vn NzbAcaqjZ2IGDvOgW2dt3Dmy+YmeGUm9dykBO8am6xFuoTGk6hgRC1HwrSwFtsHygamk mF/sX0aFA+dH+xbJT1QkIfc3PUaXR91bYZMAa5jEjaZ0/gGEblq5mpz2rxlc80AEAwwF TRJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j+WDoZ1i; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s14-20020a05622a018e00b004039eb0c4fdsi10335qtw.597.2023.07.10.08.36.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:36:48 -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=@linaro.org header.s=google header.b=j+WDoZ1i; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIsvJ-0005cN-1a; Mon, 10 Jul 2023 11:35:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIsvB-0005Yn-9s for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:29 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIsv8-0004hm-7X for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:29 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3fbc5d5742bso51841975e9.2 for ; Mon, 10 Jul 2023 08:35:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003324; x=1691595324; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2VTCVQrd6KCn5j7u4ggdRsXsalHDUZEasAWYhlhI0Zk=; b=j+WDoZ1iK16umdVplpNjyby+C0HXEitODI37kGwJGXP8HLOVKe7rt/a/fw7jXjba2v zs1wAHlxk/Q0gaA1/EiJk1gIej/DaDqErNIuRsyn+V1aYx2zPQYHF82wztebpRwOgDdR wDqaRu8ZbrT7AmcnqHRt5hh/t3t9ctn/KE0KuSYJ1MRNrZYGPsAaBSC6EWxhxA/ELSah ssLutXIIMBRxXlihjutw4bgwVOv+fE2at4V0BKhYv7N3unwblarbHdJ1Zs11Q/JzVm2K nGkk3S7WpCKhBVvOhtq0iL4/XKlTn9C4IYBO7y1oNaY9ibZp27R/VNPsJVXR0gDmkWip wm2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003324; x=1691595324; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2VTCVQrd6KCn5j7u4ggdRsXsalHDUZEasAWYhlhI0Zk=; b=AQD3k3NJI4QZDDSXZWhBxuBdCOMOFg1uIOjfFmtT6iFhCMeCbi/ZqmKZ8I7ZoYu0uF zA0jGhy8ZF/aQ0B0C2CN9y+s6gl9MK74/Hsi09RB5W0Z2gA5bCJjih9+Iyurx1ouhaRk 8ZTvbLij1sq9H0iAmYNqzsHJD5RatWQuERiV2Oi3IjB95e8GXcqUsYWJ3VGXJjv7/U7D I5XCetaNfmxxmXNTu/ScdXIQG0TGLoH/p6XZ1nh27zsMbBt9EVJuxJ08To5NYEypXTn7 XNmIdoPVeS+DUhsoU+vPK7SpHXexSizg31mzIRmJ0vCseKtgyBSR8BcZOdMeDrRC8BmH O/Aw== X-Gm-Message-State: ABy/qLZOQFYa9ahz9KR5bvVLJgl+V798ywzjpl/rdKvHorpgX6Y5OLir lVvekAP0LwC6i+honSiuL6VBEw== X-Received: by 2002:a1c:7502:0:b0:3f8:fc96:6bfd with SMTP id o2-20020a1c7502000000b003f8fc966bfdmr11967928wmc.17.1689003324449; Mon, 10 Jul 2023 08:35:24 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id f19-20020a7bcc13000000b003fa973e6612sm10709182wmh.44.2023.07.10.08.35.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:35:23 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 503791FFBC; Mon, 10 Jul 2023 16:35:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [PATCH v3 01/20] include: attempt to document device_class_set_props Date: Mon, 10 Jul 2023 16:35:03 +0100 Message-Id: <20230710153522.3469097-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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-bounces+patch=linaro.org@nongnu.org I'm still not sure how I achieve by use case of the parent class defining the following properties: static Property vud_properties[] = { DEFINE_PROP_CHR("chardev", VHostUserDevice, chardev), DEFINE_PROP_UINT16("id", VHostUserDevice, id, 0), DEFINE_PROP_UINT32("num_vqs", VHostUserDevice, num_vqs, 1), DEFINE_PROP_END_OF_LIST(), }; But for the specialisation of the class I want the id to default to the actual device id, e.g.: static Property vu_rng_properties[] = { DEFINE_PROP_UINT16("id", VHostUserDevice, id, VIRTIO_ID_RNG), DEFINE_PROP_UINT32("num_vqs", VHostUserDevice, num_vqs, 1), DEFINE_PROP_END_OF_LIST(), }; And so far the API for doing that isn't super clear. Signed-off-by: Alex Bennée --- include/hw/qdev-core.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 06cadfc492..196ebf6d91 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -926,6 +926,15 @@ BusState *sysbus_get_default(void); char *qdev_get_fw_dev_path(DeviceState *dev); char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev); +/** + * device_class_set_props(): add a set of properties to an device + * @dc: the parent DeviceClass all devices inherit + * @props: an array of properties, terminate by DEFINE_PROP_END_OF_LIST() + * + * This will add a set of properties to the object. It will fault if + * you attempt to add an existing property defined by a parent class. + * To modify an inherited property you need to use???? + */ void device_class_set_props(DeviceClass *dc, Property *props); /** From patchwork Mon Jul 10 15:35:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701026 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5243325wrs; Mon, 10 Jul 2023 08:37:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlE1KeQb+k1d7h7uIcAHajgfxXylVxvRH3GSvhKU78way8ozlwB6xsuTZdbC+vodCa8BjfmC X-Received: by 2002:ac8:5b52:0:b0:403:a308:3cfc with SMTP id n18-20020ac85b52000000b00403a3083cfcmr9178582qtw.25.1689003429462; Mon, 10 Jul 2023 08:37:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003429; cv=none; d=google.com; s=arc-20160816; b=x2nemI/JvelFukedr0yoOlWDznBpU3Ju67pvxEgQfsUGnQovKOJkS1gmfB6lMW2bQt fPuI0zZi46giVes4kTyPpSzzrjMlrKYdeIF8Lebp464agtPwuwrI5UpkXcRf8DjuVQ5V J4gJ8DO62kDQUywZiUeE6ujs77iBMFODlTv8l/fGTCNd77eOjGgRhKl9JlWLB+qaJkIn YitrwfJQipW2f508VQcV/4zWgZXoZxiPOuiU+QBiL8bECnprVFA5eDqPvUsQxPukN3tB 0GZT+oq5AbHyG2jInEXVdqNulUItZ6fR+Ww4tPl2E1+jJPzUlLCjeN+z1PrUrZNS5BQa /Xqw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=A5nrdE1EbWfnKTXnpPgJZ0uBCr/0VA1ZCTtf34qEAwI=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=CDx6BoFzU5BtUszKIaRqsAAJhQBRBBo5V+GSWjU7r65KR+4CFQCCxAbCk+1yyoYfn4 s/eWkIDdcN53uS2q13GcnabFJY11IocSjc2ihhQC0mj8B1cMJ6idmDyZnmohO8tGZEWR b5imXqScBBPBQnNI7C8P3OIDIEdPaP7dz4WyIo8Wd+oeGPsRkStEHEvGC7jGY6WXo6h0 CzFber+U/VS2dyyIOxyHTzH8sH68ZOp7SZDV1LxqJVsGP+K3wUMdhbU7TilRX474+neg q+5HdZAdOQYtFdqnSgXQiFh8lpllF21AsvyKJ/lKgYmY6kJs/lU5Ra95gAn7LWHBqf/s U62g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OrGn7Nwj; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o20-20020ac85a54000000b00403b25523bbsi11798qta.537.2023.07.10.08.37.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:37:09 -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=@linaro.org header.s=google header.b=OrGn7Nwj; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIsvc-0005t9-6y; Mon, 10 Jul 2023 11:35:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIsvQ-0005lo-Vd for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:45 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIsvB-0004jr-JF for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:44 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3fbea14706eso47804215e9.2 for ; Mon, 10 Jul 2023 08:35:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003328; x=1691595328; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=A5nrdE1EbWfnKTXnpPgJZ0uBCr/0VA1ZCTtf34qEAwI=; b=OrGn7Nwjm+XbE+PNmSMJuXVthHH3ULc6N4kPsnLW92+NTRe49XPenOJcvcj+rac9Pt nVKbFaUa4sjJBQ5JMRiOtgrIVvCNWGvOPL1tNcAW4f4tOH/emMZuKxg7rRXyDxt7iER4 EVh843PUSJyRGBg3xZ2xsIqDnW8rBcSrOAnhBIdapzKLBQsvkCG7acr4Oq+d69200Srw WAsJ6ZdhbU8XMqnISdOThSNRm8ngNvfiGC5+pbMHzTRiBD+XPPnMyUiJhMWsDe9+zFNk fdGqiHCURsd4iiM3nGDx0bqt3xGWg0iHSBm2E2YXRApK8AGI5dMq9qV0vcb1IsF4Oe5i GRWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003328; x=1691595328; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A5nrdE1EbWfnKTXnpPgJZ0uBCr/0VA1ZCTtf34qEAwI=; b=Vkt/evEk+WlNCeWHtndPovCzdkEDQ7jeOmtOoU3RJPql67qFm00fhaiYfs5Seyme45 FxGsUkKJubGZeO+yNcevQgrVw6NTooU/empc1fT1LNnXI4riWbo0NHrPFesNC1jR2nPR myJ5HT1saXyhV5LNCYyYXgH66/ezGn4f+28tDWwphg3/8b5ZgLdchqrEGExg+gg2/dU0 fm/NWisgnM4iudMaX+8zTo1V+UdbX0R5SJ7odTmlwzCXHJdbavd32Qg2EstWzz60D6vI +JA08hCEHEVJ+rQvUNe3SvLL7FdoeSLk/coGIWYGH8OWXGxsE7NF3f8kp+x5O9azJyBE QJ1A== X-Gm-Message-State: ABy/qLbVKBwRsXAqrU5Tg+8YeXEMGSAz2u/bsa4mSLxEcyTv2WWp1gjY /OToef6myA0EA3iln8YpjGnQ4g== X-Received: by 2002:a05:600c:378b:b0:3fb:ffa8:6d78 with SMTP id o11-20020a05600c378b00b003fbffa86d78mr8100846wmr.36.1689003327693; Mon, 10 Jul 2023 08:35:27 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id e14-20020a05600c218e00b003fa96fe2bd9sm10643485wme.22.2023.07.10.08.35.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:35:23 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 68AF61FFBD; Mon, 10 Jul 2023 16:35:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [PATCH v3 02/20] include/hw: document the device_class_set_parent_* fns Date: Mon, 10 Jul 2023 16:35:04 +0100 Message-Id: <20230710153522.3469097-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x335.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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-bounces+patch=linaro.org@nongnu.org These are useful functions for when you want proper inheritance of functionality across realize/unrealize calls. Signed-off-by: Alex Bennée --- include/hw/qdev-core.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 196ebf6d91..884c726a87 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -952,9 +952,36 @@ void device_class_set_props(DeviceClass *dc, Property *props); void device_class_set_parent_reset(DeviceClass *dc, DeviceReset dev_reset, DeviceReset *parent_reset); + +/** + * device_class_set_parent_realize() - set up for chaining realize fns + * @dc: The device class + * @dev_realize: the device realize function + * @parent_realize: somewhere to save the parents realize function + * + * This is intended to be used when the new realize function will + * eventually call its parent realization function during creation. + * This requires storing the function call somewhere (usually in the + * instance structure) so you can eventually call + * dc->parent_realize(dev, errp) + */ void device_class_set_parent_realize(DeviceClass *dc, DeviceRealize dev_realize, DeviceRealize *parent_realize); + + +/** + * device_class_set_parent_unrealize() - set up for chaining unrealize fns + * @dc: The device class + * @dev_unrealize: the device realize function + * @parent_unrealize: somewhere to save the parents unrealize function + * + * This is intended to be used when the new unrealize function will + * eventually call its parent unrealization function during the + * unrealize phase. This requires storing the function call somewhere + * (usually in the instance structure) so you can eventually call + * dc->parent_unrealize(dev); + */ void device_class_set_parent_unrealize(DeviceClass *dc, DeviceUnrealize dev_unrealize, DeviceUnrealize *parent_unrealize); From patchwork Mon Jul 10 15:35:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701028 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5243430wrs; Mon, 10 Jul 2023 08:37:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlHMAUOO7KSx3OVOw/W0az+jVN+40W3LqYtmwqxLkxQ747lGmz804gdQQSs+HY0mTZt7w+EU X-Received: by 2002:a05:622a:493:b0:403:a80d:29e5 with SMTP id p19-20020a05622a049300b00403a80d29e5mr8089747qtx.31.1689003443693; Mon, 10 Jul 2023 08:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003443; cv=none; d=google.com; s=arc-20160816; b=ptXdHbbEvY+cbTyXK0Cd1/6g3jj0ZwgC6Gowt6l7mYPcH0krkTQsHcS4ofkG68X1/8 GVsf7mJjWAUH/l2eRaUXOljrD69ABi638cOTgv9KTRc52oQvHFaLoOtlK96ookMlHzyq SQCJ3lfbCcP3klYlyG9N6qswWWZwOgElUSxRDEDXb0zgnzcUwwhtnkOflR8/+s0F9Twk B+3bPc8Y9H5eCOMuwR8d02TuxegweRorT3lO+m5SXu/M7ejIl/e9WmF9+jjie6s9cWlW Ro3Qm3Sl+vHFk82aLx0gzmwebklaS3fT3F0/eHxckXhXJ8WgM1H668RhhYDJaqqxKTIW Himw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/3hOIZ7v+pYUizQmXUU1SDOsTbcl3kinhTlpzgj57Mc=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=jrwsmO/A6Kiph05PKjfmHAKcmn8x+rU88GYSyPd11fn9fS+Sli5EiE/bPaJv2YMvjA 0VcfZyQYF53rWZdw4xZq/uAFtElikwScB3l2TbEU18bUNcD/V4MQKZO47ON2wh9BYuLa l9kyLzMWuKFIzylQg9voCl+rYWPJAWkssW+rrHCD9e83ERx+6zBjSkOD+rdBOuFOAWUc cpw6GbhBIJK2JP0qfIgBbzY1v8py0A9Jk0DT4z3KTPIkXBHONZlrt3VHnMQNEvy4M0fh iRkhA/IOnu99M+gzu3khYDowGOjSt+DsmfR6QSpYzBxR3050g1rz1zszRCy2CBp8ldBz DaGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="znvx9h/v"; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w12-20020a05622a134c00b003e4f04bdc48si14219qtk.455.2023.07.10.08.37.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:37:23 -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=@linaro.org header.s=google header.b="znvx9h/v"; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIsvK-0005eh-BG; Mon, 10 Jul 2023 11:35:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIsvI-0005d7-3S for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:36 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIsvG-0004lc-3i for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:35 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3fbf7fbe722so53890345e9.3 for ; Mon, 10 Jul 2023 08:35:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003330; x=1691595330; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/3hOIZ7v+pYUizQmXUU1SDOsTbcl3kinhTlpzgj57Mc=; b=znvx9h/vOjwJwXqi5ZGmg8C5katjfqPtJ83ohhrloNdrhE7ddvfl6XAtl99kL6vihU POgZtencQUmRsz4Jr7073y0c9aKzNxj/6BKpMchtG/+J3oNbqRUjwfFM0QZNsl/Lp60x VEscevGaApVBQqCe2/TeqbhBVh/CWTOq6OFUIcWjSOoSUlvX0WPpKlDoOk5RAgkCBR7V boc0viIgcc9k+Ad3rNKZAkI5njDNjrQ4e3Eowjsax4XdhxoBXwGwpTTn8wQfc1ahvU+h H+f48PNqABorALgtpOXu8LHDcf/VHrTWWdqkka8uiOCn1n3f9wuMtJq7eE04LB6GbG0F u4/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003330; x=1691595330; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/3hOIZ7v+pYUizQmXUU1SDOsTbcl3kinhTlpzgj57Mc=; b=eDCVt9HcXjswXLjnyYOYoX3Y5rpz5txlf161yFkU/QwwJoImQN6/w/D14O76p9D68n 09CKEHTiqhJFRNToTW2CUQM2tAXquQqeYuBERpjNgP1ycxYnbW6D2PGEhSf/z2M6+4Lj 6LYbZ8476288fIWxI36naYOhoKJJxRNBDj+tUtlSirVOe9OGyVxsJYsAPYt1/AeDw6gx /chrm1rBus7LKl+O22B/CnoyCKNtLJiY4NGVRDxVMEf1RrF7yk4oCYH6CsQdDKK9Du/K iQwDtl40eKoWpJbj4wIitTMbYIAXkeJQP3J1L3mNF3dK9PUBINawqSVVCkFhvA3HfIQq 7kVg== X-Gm-Message-State: ABy/qLbB3zldLoicnvWi9G54RBT5fnKxeygOQsv6pKt2qgs2ryHYNg45 2XAPwdYM/bqvs1/DG/RKRla/Pw== X-Received: by 2002:a7b:c390:0:b0:3fb:d1db:5444 with SMTP id s16-20020a7bc390000000b003fbd1db5444mr12350095wmj.19.1689003329863; Mon, 10 Jul 2023 08:35:29 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id c5-20020a7bc005000000b003fbdbd0a7desm10597836wmb.27.2023.07.10.08.35.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:35:23 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8E1561FFBE; Mon, 10 Jul 2023 16:35:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [PATCH v3 03/20] hw/virtio: fix typo in VIRTIO_CONFIG_IRQ_IDX comments Date: Mon, 10 Jul 2023 16:35:05 +0100 Message-Id: <20230710153522.3469097-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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-bounces+patch=linaro.org@nongnu.org Fixes: 544f0278af (virtio: introduce macro VIRTIO_CONFIG_IRQ_IDX) Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- hw/display/vhost-user-gpu.c | 4 ++-- hw/net/virtio-net.c | 4 ++-- hw/virtio/vhost-user-fs.c | 4 ++-- hw/virtio/vhost-user-gpio.c | 2 +- hw/virtio/vhost-vsock-common.c | 4 ++-- hw/virtio/virtio-crypto.c | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 15f9d99d09..1791797bd7 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -489,7 +489,7 @@ vhost_user_gpu_guest_notifier_pending(VirtIODevice *vdev, int idx) /* * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1 - * as the Marco of configure interrupt's IDX, If this driver does not + * as the macro of configure interrupt's IDX, If this driver does not * support, the function will return */ @@ -506,7 +506,7 @@ vhost_user_gpu_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask) /* * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1 - * as the Marco of configure interrupt's IDX, If this driver does not + * as the macro of configure interrupt's IDX, If this driver does not * support, the function will return */ diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 04783f5b94..493afdd96b 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3362,7 +3362,7 @@ static bool virtio_net_guest_notifier_pending(VirtIODevice *vdev, int idx) } /* * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1 - * as the Marco of configure interrupt's IDX, If this driver does not + * as the macro of configure interrupt's IDX, If this driver does not * support, the function will return false */ @@ -3394,7 +3394,7 @@ static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx, } /* *Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1 - * as the Marco of configure interrupt's IDX, If this driver does not + * as the macro of configure interrupt's IDX, If this driver does not * support, the function will return */ diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 83fc20e49e..49d699ffc2 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -161,7 +161,7 @@ static void vuf_guest_notifier_mask(VirtIODevice *vdev, int idx, /* * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1 - * as the Marco of configure interrupt's IDX, If this driver does not + * as the macro of configure interrupt's IDX, If this driver does not * support, the function will return */ @@ -177,7 +177,7 @@ static bool vuf_guest_notifier_pending(VirtIODevice *vdev, int idx) /* * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1 - * as the Marco of configure interrupt's IDX, If this driver does not + * as the macro of configure interrupt's IDX, If this driver does not * support, the function will return */ diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index d6927b610a..3b013f2d0f 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -194,7 +194,7 @@ static void vu_gpio_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask) /* * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1 - * as the Marco of configure interrupt's IDX, If this driver does not + * as the macro of configure interrupt's IDX, If this driver does not * support, the function will return */ diff --git a/hw/virtio/vhost-vsock-common.c b/hw/virtio/vhost-vsock-common.c index 321262f6b3..12ea87d7a7 100644 --- a/hw/virtio/vhost-vsock-common.c +++ b/hw/virtio/vhost-vsock-common.c @@ -129,7 +129,7 @@ static void vhost_vsock_common_guest_notifier_mask(VirtIODevice *vdev, int idx, /* * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1 - * as the Marco of configure interrupt's IDX, If this driver does not + * as the macro of configure interrupt's IDX, If this driver does not * support, the function will return */ @@ -146,7 +146,7 @@ static bool vhost_vsock_common_guest_notifier_pending(VirtIODevice *vdev, /* * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1 - * as the Marco of configure interrupt's IDX, If this driver does not + * as the macro of configure interrupt's IDX, If this driver does not * support, the function will return */ diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index a6d7e1e8ec..44faf5a522 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -1210,7 +1210,7 @@ static void virtio_crypto_guest_notifier_mask(VirtIODevice *vdev, int idx, /* * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1 - * as the Marco of configure interrupt's IDX, If this driver does not + * as the macro of configure interrupt's IDX, If this driver does not * support, the function will return */ @@ -1229,7 +1229,7 @@ static bool virtio_crypto_guest_notifier_pending(VirtIODevice *vdev, int idx) /* * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1 - * as the Marco of configure interrupt's IDX, If this driver does not + * as the macro of configure interrupt's IDX, If this driver does not * support, the function will return */ From patchwork Mon Jul 10 15:35:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701020 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5242991wrs; Mon, 10 Jul 2023 08:36:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlHL5eJam7fP8khuQewz4inEvlqWzGk4f+EzWL4Qz/6DFf62oIa6GeaW5DNsSaA75tPBPhp9 X-Received: by 2002:a05:620a:2889:b0:767:dc9f:5141 with SMTP id j9-20020a05620a288900b00767dc9f5141mr829966qkp.19.1689003384945; Mon, 10 Jul 2023 08:36:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003384; cv=none; d=google.com; s=arc-20160816; b=W4l2cKqEyUfzEo90FwlOMy6gSS2heuHwnz7zhP8cRrWEAKIUZCY/mW0cuA3XglRze1 PiEBNAE99q/vKVmshPny+7jxna3aEKL+kYVSv7hmnzp/eGRo92eOP/WqZTleZoPIZLtM V3pyQWdauRyt3sGQpEWkfw0Ca3Ezx1OswikpLnxI4sya9jb8enGGvjL4f4E1W67VOgz3 x3NIrJ3ixnvnWDwktsF3TCz5wYSa0Kf7mzFpDHBC2eT80oCMApMuWnW1In0CCH0p5P99 1hEW0kuSvk+/K99kphDVM89BamDIjYhKfX4S62IrpvqyB/bPG3Gxg91wScguIfGpMBuB JWlw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=y4Dz/cKQcjk2Q/25bTqazNT9L0/TcrBA5Nkd7fUVra8=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=0TTCW0JpjpSS6GcNm8paz10rlapmmbKi7tffMNxYoI9cqVX5rpIo8rHWYZ4tLLUs1f WfJFYt6UmrJA5UBpzbX+VtI40H7uJ8ztpZVj6FW9Fa/JZDosNyQ6bKqU023w5GbxdwqQ bQSAfSMEFa/TT0AI/1wTF+J5kE/tC1v0cG5l7t6ulrfKHFiTsecH4Eq3FkquYDWpG9fx NX7xUBMeifETXRJ5DHG9I15f1SGcfTsUqeryagvpYFxH6LeiJViosvY+1jDzVJl2n8sK EBxxftVS3RyLR+zqqov3tCL66rPTVnACp/0E1/L4cBW16XCs4eZz7weW4GYf7S5WHGzT bH4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IQ6KxQRu; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m26-20020ae9e01a000000b007606fd3b7f8si5909510qkk.139.2023.07.10.08.36.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:36:24 -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=@linaro.org header.s=google header.b=IQ6KxQRu; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIsvR-0005lp-3y; Mon, 10 Jul 2023 11:35:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIsvP-0005l2-IP for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:43 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIsvG-0004lT-5h for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:43 -0400 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3143b72c5ffso5484246f8f.3 for ; Mon, 10 Jul 2023 08:35:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003329; x=1691595329; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y4Dz/cKQcjk2Q/25bTqazNT9L0/TcrBA5Nkd7fUVra8=; b=IQ6KxQRuWoZTFUkZL8wqDIz4YT5YYYlpRTK64s4+asCrYQkq5sXvq0jbS4LgRX+juo FtY4+9d3ucFJRqycocNYzmkhe4UgUBGlsz3IrUIOp0FByx1E9dRL0/zMBv+TcbnnJReW tQjCnWQqFqJR2PF0iIBVAb7oWo9T8iWebaIaek0j3O3PolB/hK7o0uSDLJk5cX1Hd9Ui wjUTkyz46AX11puBd1fk3BeKwLDm8YLQLeSp7imUg4gwcmcCan+Ke0NUqy19t5G1D/7Q TG73nLUjtZpcj4x+O2BS3mK1qixN6ydz9YwDwJ8lWw9nC7Bp8SUjREKhknKybzAN/DNp 9uMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003329; x=1691595329; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y4Dz/cKQcjk2Q/25bTqazNT9L0/TcrBA5Nkd7fUVra8=; b=bDjlhL02SVRa9lKQVLWpwvGy2u0Yctr5DvvhusPe8WUmIrjAmt9XVXZBLiYCk+jP3B szAwLePCIlNDciYIHe6K1fM92a/9lCMyw87HIF9/vHZyMqNpXSQwJ9u+BQmFp/iJO0lV yWJSRT4wDx443iK2v0GmBnd/Napyo5r1E8icA8PR8njIkRpAwcyalkusevuGEo/PxSsm o0ZTXO/TMlXq2fqOAsdW5qdMHzoLqIaXfPwzdU3T0MAfy/TB3K8LmjIm+CSA1X3sSwKJ /adk/Lxi57OqSm4kLr9iokZfWfPCtTcPAmyj2Yaw44O/4MMngJzBv7ydUnjdGqn3T05x ialQ== X-Gm-Message-State: ABy/qLZaLlV5DACgtIglXll+z/3g0c0R2zYF1klWrnQuJ7wAW4CgE/0H epsDeuKGeawImIs0VJjOiq+0Zg== X-Received: by 2002:a5d:6d4f:0:b0:314:3c8f:d267 with SMTP id k15-20020a5d6d4f000000b003143c8fd267mr14974373wri.45.1689003328955; Mon, 10 Jul 2023 08:35:28 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id k6-20020adfd846000000b00314315071bbsm12040337wrl.38.2023.07.10.08.35.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:35:23 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id A5DE91FFBF; Mon, 10 Jul 2023 16:35:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [PATCH v3 04/20] include/hw/virtio: document virtio_notify_config Date: Mon, 10 Jul 2023 16:35:06 +0100 Message-Id: <20230710153522.3469097-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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-bounces+patch=linaro.org@nongnu.org Signed-off-by: Alex Bennée --- include/hw/virtio/virtio.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 0492d26900..0671989383 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -276,6 +276,13 @@ extern const VMStateInfo virtio_vmstate_info; int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id); +/** + * virtio_notify_config() - signal a change to device config + * @vdev: the virtio device + * + * Assuming the virtio device is up (VIRTIO_CONFIG_S_DRIVER_OK) this + * will trigger a guest interrupt and update the config version. + */ void virtio_notify_config(VirtIODevice *vdev); bool virtio_queue_get_notification(VirtQueue *vq); From patchwork Mon Jul 10 15:35:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701030 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5243519wrs; Mon, 10 Jul 2023 08:37:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlFsONvu2qHQDRc/opSQHzLkT5Ic1cC+FpLDGxJpO3z4yHvoyBsMNtl+rRcVM1zGTOLK3BKO X-Received: by 2002:a05:620a:2a63:b0:767:47f2:dff4 with SMTP id q35-20020a05620a2a6300b0076747f2dff4mr15176438qkp.33.1689003453536; Mon, 10 Jul 2023 08:37:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003453; cv=none; d=google.com; s=arc-20160816; b=B5Vpy6S8QyYXE9HnmCj53///0xZ7iUYhBpvJ1SeXn4TY/BiCTyyyZnhKO2nLVrPxy/ 3nYQk7bys9LrX/iLxFlOi6R31C34UiRZlE4HMv3OB73HPxAndVgNy5zMGImxwD1a4fzF NdvAh+sHctvmZL33vOI8RiJnhJLkJB96EgRbDMjlak8TAAT3reixWKfNRw48gjr31g4k l+LDFYXMJUq5CeCDXcGbVrqZ+Miq5XnH9Euewexfl83oZLFlp15jWEHJ4JboQNXzAKhX vLseStLqvH4/elXD35v6qn72EiXQWOItt6U1cbU4x+VJNBJHO9Oj/3+g1Npso14TZpPb 0Qfg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VMtJa+hYr6z5Kv+bBMUl2RqQsO6glkaKRsQk48984cQ=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=iLqcirfrvBJRgtioSxi19FT6tihp/oMpp0HXQkRn919J39u9RvjKrPqFHdDsS2SivP SriJTLpeFlp5ZSiigGk02+4ZyxAVwzUdVUWasPffv6cbVB9bxfWMnZlWQiRcc82qTcrh GaztXvkETcR/z0fxkwzkOCiZZ6tYwO+2M5k0xuUHYoO+qUcxvdCTp0cvd42xg16C18t6 00TBobheXIKDLPxPDQPRKxxpJ7RrAqR+KBBpc+1X3y1pWSoxDHdg8LLUAnKhwqOuqJkI uKh729g0nVcbWwWoWcg5YJ+MI26vOLzlg+GvE3WVHkhujHj9mxMi+bu24nm4mC6ehoS0 wiBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sDe6ctuB; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bm38-20020a05620a19a600b00767cc37dc22si1871880qkb.209.2023.07.10.08.37.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:37:33 -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=@linaro.org header.s=google header.b=sDe6ctuB; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIsvN-0005ip-W7; Mon, 10 Jul 2023 11:35:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIsvM-0005ha-AD for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:40 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIsvG-0004lk-3A for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:40 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3fbdfda88f4so47533885e9.1 for ; Mon, 10 Jul 2023 08:35:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003330; x=1691595330; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VMtJa+hYr6z5Kv+bBMUl2RqQsO6glkaKRsQk48984cQ=; b=sDe6ctuBgcDWCsfWevwenPhgSZyso/28vlWvRb4lgnBGZcnReLxEHyKxPSy9Fs3Dh7 Qens4omJTbJYj+JQmE2PTQtoVeyNwLE9b1zmowPRdkvFFvYbWFWzqnNLmWjGHpaXG1h9 ocp5v4d0fhG4yOEKpQ5ykvguh+x47rohxhTiJTeadNdnieVAcnEq40hbPeYOVrpZpjj1 mHPzyHS1sefKNd/2WMc9FY6zsTCouFTXOhoxmfNM8oBU4Gk59bbZLXO3cQTratn3DuOL UUViAmtCLvNlxeSZPV+0dH1Hh6Bj6AfsbCVKo/6YxcmBNpzhVyvouB8zpCELK7N6uhFD Hllg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003330; x=1691595330; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VMtJa+hYr6z5Kv+bBMUl2RqQsO6glkaKRsQk48984cQ=; b=O0D+eAiV15BsoAmMNFpar7xADG/Js7x2O9P597+pXAIlhuk1tNUP1l1J0fxvLSeYY+ OuATjt4cGOxpybnaQQ+Nv93DSpC7utPUcoUX0amFcx9ivQjMTE8GhG0QS/6cfLfz5WuP Om2fYoWalu1IXdN+4AR4xk1cvUkx4tnQ0YlfqvJGH0W+TwikT0ysby5wUpyKJVPUW8+b WTqfywNM4rMobj1eRhQo9NBQvA9wOoos7KQHruVmNN797nHqMZRQ9p9x3ZceGeILv6Ok WpUaiKZfgLNuX+nl5S+Hr3vxuuiRmHDPysnHi2T2pBy7lVI4SpC8lSe8skyh2YUbPVsX 2FlQ== X-Gm-Message-State: ABy/qLYpATz5nZMFphuHBmT4ZLS6us9XWBsEGlraq439B2LZrOvmGyqq s3TZ1fCAVWhz57qMRqkQQWB1cw== X-Received: by 2002:a7b:cb97:0:b0:3fa:93b0:a69c with SMTP id m23-20020a7bcb97000000b003fa93b0a69cmr10757760wmi.24.1689003330640; Mon, 10 Jul 2023 08:35:30 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id q21-20020a7bce95000000b003fc06169abdsm211102wmj.2.2023.07.10.08.35.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:35:29 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id BF5B61FFC0; Mon, 10 Jul 2023 16:35:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [PATCH v3 05/20] include/hw/virtio: add kerneldoc for virtio_init Date: Mon, 10 Jul 2023 16:35:07 +0100 Message-Id: <20230710153522.3469097-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x335.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=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-bounces+patch=linaro.org@nongnu.org Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- include/hw/virtio/virtio.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 0671989383..631490bda4 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -219,6 +219,12 @@ struct VirtioDeviceClass { void virtio_instance_init_common(Object *proxy_obj, void *data, size_t vdev_size, const char *vdev_name); +/** + * virtio_init() - initialise the common VirtIODevice structure + * @vdev: pointer to VirtIODevice + * @device_id: the VirtIO device ID (see virtio_ids.h) + * @config_size: size of the config space + */ void virtio_init(VirtIODevice *vdev, uint16_t device_id, size_t config_size); void virtio_cleanup(VirtIODevice *vdev); From patchwork Mon Jul 10 15:35:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701031 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5243598wrs; Mon, 10 Jul 2023 08:37:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlHqcbk67SudU1zjixtKacr02V6qSHOP5rgZZVGpcLzPhzFdd5H+wit56qS+ugnHFkr2Y6YW X-Received: by 2002:a05:620a:4781:b0:765:66b4:9da7 with SMTP id dt1-20020a05620a478100b0076566b49da7mr12338140qkb.3.1689003463096; Mon, 10 Jul 2023 08:37:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003463; cv=none; d=google.com; s=arc-20160816; b=X4aMD+EAuSAn8grxzw00iKcOs04gQqZWvHWhzOFciWmMM2AYYzRlxHqyTSFU3eaiEl +Sh5n/6yuHYTRJa/swfvSPvbHuTMJzK3I+KqaMqOHT0MymZ/QIfZd9gLKMdzq1rHtUbL xaGyi/r79FYR7KjIdjitJHneo/+LS3aH/n4n6R+clzFm92hsESEwV7lRLwqMaA6rfH0z RFJi5w6MObh0SH+SWPgYZmd9TiDxVMbtt3CIBC/JU6Rwp3CQBLwgGC9h1viqfabGRucs MgbPsG/ehrIasCsqpbJGNLox6QN+NB5aPHG/d9r1yMomWr1HqJqfs3PgI9vS9fb9lw6l sEHA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ydjjuLF1zit1BjbAeuBjGkyFl+6yYLQdGkw5bViFdwU=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=F7KOlTRDhGR2MlOR1UD68NGSPq//H+i0mO7yDh/pD8Y36ArVBgYrn0yJn94ZfISoTC SutSpiNxMXZ6qMRR1s7iActQkXsW4XQAAz+hRmsRBdvtnq1Rd8OWkdskcPYPqFBJErlw nZXWEnKZMhwnhu20jCYSbAbRHlLGTl7FJ1jaT8gG0KiDKCsXgQZ5DxmRhOl3DOJ5TDMH lnAVgfnB3+IYrwJAAI/llYgqJlBuUBHCiVfAWsvtvZCvt/IKWqA7tGPCDgtur3TgZljZ HRI5uHsdIoFzZtGrpmG+b5PjF9munLVoW8uV7gpZfpuuE2qNUmZaCSEkyrBJVw6WgFTJ GmwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fD0hnaXh; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id pi47-20020a05620a37af00b007655a985a7dsi5713182qkn.380.2023.07.10.08.37.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:37:43 -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=@linaro.org header.s=google header.b=fD0hnaXh; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIsvi-0005we-4r; Mon, 10 Jul 2023 11:36:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIsvW-0005ph-KC for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:50 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIsvG-0004ls-48 for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:50 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3fba8e2aa52so52003305e9.1 for ; Mon, 10 Jul 2023 08:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003331; x=1691595331; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ydjjuLF1zit1BjbAeuBjGkyFl+6yYLQdGkw5bViFdwU=; b=fD0hnaXh2COPn2kr6AnQqYWkXVUFSuh5n6nxeoNsaXYX+hOoU9LitbfcgVIhd20Fpr hGcMAFPRVTanGVKk0H/qTyoF2t2PoJDd2XGF1g4+sAh6JuHwerlgUUBbE1SrdJ8WbQs2 uzZ2vQnEGqunCqdU6kB+hO4BX7jO/yrAqYVjocx7f4/qe8IntB6u961WWPyV04yeYxQn zxfVbMy7pe98kS0khKQG+To8Rmgh1TgTEIL9/3AttAR6SbvHRRNRgpooYEeYBNu7IF8P i5qlFhZn5koF2m+YDecMsuQgQS08KDFc9By0nJ1A7dIOKA5uqEfXjRBrN2pwH5ohFyqv ehAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003331; x=1691595331; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ydjjuLF1zit1BjbAeuBjGkyFl+6yYLQdGkw5bViFdwU=; b=CllGdhFsUcxdUoVp4KzA2rR7VrpaRx6DwcoHep15hAKf8fZDPV/Gdb6P+EaYotjAvx 4+QKRoU392wvDZrpz4/lwR3LN7ssR9TsaX3/SbCkZhQtJFOvMX/y4ZDKO4GdW9q/2tKO MAadHuBRDDgskwW8GD3CiLiuDs8OfFbdkab9ntSB5lq5IwFGHRcqkDl+xL6AhlXH+nca EO5kERQPLiy737VjChPVbVFTXPY5c0odPuI38alI4SA5Bvw+OTlp4zTEDqt+DeupHYEA vzlrWqEzjI/U7p52IG2h/j++dquRE+YCNsTKfo127+rsKgfTJb4jIK76rxMYlzQsw0tv KLYQ== X-Gm-Message-State: ABy/qLYPyUWFXHnFXHPTQwFeGpk6UFcEeh4RV4ms61F3MBU89/2W1maw GLqqeKToclb0IaniiMrvnbQmIQ== X-Received: by 2002:adf:ebc6:0:b0:313:f54a:a842 with SMTP id v6-20020adfebc6000000b00313f54aa842mr11805915wrn.63.1689003330902; Mon, 10 Jul 2023 08:35:30 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id z8-20020adfdf88000000b003143bb5ecd5sm12010850wrl.69.2023.07.10.08.35.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:35:29 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D78C41FFC1; Mon, 10 Jul 2023 16:35:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [PATCH v3 06/20] include/hw/virtio: document some more usage of notifiers Date: Mon, 10 Jul 2023 16:35:08 +0100 Message-Id: <20230710153522.3469097-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=unavailable 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-bounces+patch=linaro.org@nongnu.org Lets document some more of the core VirtIODevice structure. Signed-off-by: Alex Bennée --- include/hw/virtio/virtio.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 631490bda4..c8f72850bc 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -150,10 +150,18 @@ struct VirtIODevice VMChangeStateEntry *vmstate; char *bus_name; uint8_t device_endian; + /** + * @user_guest_notifier_mask: gate usage of ->guest_notifier_mask() callback. + * This is used to suppress the masking of guest updates for + * vhost-user devices which are asynchronous by design. + */ bool use_guest_notifier_mask; AddressSpace *dma_as; QLIST_HEAD(, VirtQueue) *vector_queues; QTAILQ_ENTRY(VirtIODevice) next; + /** + * @config_notifier: the event notifier that handles config events + */ EventNotifier config_notifier; bool device_iotlb_enabled; }; From patchwork Mon Jul 10 15:35:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701024 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5243205wrs; Mon, 10 Jul 2023 08:36:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlEr+j1ZM9MbIJ7jstxqNcErlYbw2lfO8hHFaPLdFEgmD6EP4LYom5Ca79Vauye/Q+OQx+GH X-Received: by 2002:ac8:7c4d:0:b0:3fd:e9f5:7f6d with SMTP id o13-20020ac87c4d000000b003fde9f57f6dmr14160922qtv.19.1689003413375; Mon, 10 Jul 2023 08:36:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003413; cv=none; d=google.com; s=arc-20160816; b=gsfEbkKoMpUQ0kJS/KmdbZtOH6TIi6IS6Q7WdznoIW1DK4qRYMYsTTdJG3z9vE5xJP IBn7XKLJSh1LTHUpY6bCZk68G/tPW3m2h5kf/xkGjSj2GyWSBKH/+IKE6KBD7s32EaB/ ArYdvoz1yvg/eo0XwG2mbtecwmoRzZU3wEszVBU84wyJwQhZktmrV4wi30gXs6FO3h+N 6n8qn0lC3uBn2sSw79I3Ksi4UcExOlxEtFzs1wZjwocvqGihOXZ4RMyjmnEllnDMcWiE IBpKdFOqV3QBeP4WoybUqv48jQcC4/FdQJoAfPoP3Engkjp7mbTfFTlR4LF2oJ+KlrzU YNJA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kRIoDdd0p00qTB3TzSNz7mfmNIx5ZZ+GLtrFSZRsJqY=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=Vh9Qkdfc+Ixu39oWbXpxLM/aidNh5i16pKQH9K1T1+IUrEOq3/mS3IXcWXvukqh1Q4 nohP6UcO6QuTI95GpH7XK4o3HhYsGUoGH7IC8nchucrsR8IdNcdMtutfFakapzRwNFKl oG03A1quSv/kx5EfS2bG+l0xAIxysic8G0hwgGGNf6tBzeR/q6AVfvOOvebvK2kqi4eL Y6NPGmCs3L+Njd3AcmFqIIcZ6IYmxxNtAOG1bUwDh60gU1zW1j4BbMv+CTwlOZaAAA4j eq+RJJ/DrYeoB3cJprJkxm7MJbTk1cnIUow+Iv2ASp/h63+MBjbZcpci3KprV+dR8GC+ 0WTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O3VTuUFM; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i15-20020ac85c0f000000b00403a91d5759si16867qti.378.2023.07.10.08.36.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:36:53 -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=@linaro.org header.s=google header.b=O3VTuUFM; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIsvY-0005pj-O5; Mon, 10 Jul 2023 11:35:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIsvP-0005lA-PH for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:43 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIsvG-0004lu-5u for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:43 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3fba8e2aa52so52003395e9.1 for ; Mon, 10 Jul 2023 08:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003331; x=1691595331; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kRIoDdd0p00qTB3TzSNz7mfmNIx5ZZ+GLtrFSZRsJqY=; b=O3VTuUFMnfLjPnQpb53j5d0/kpCeJ9CbjO/9oPjJpRb9vm5cVbo0rCgAhWC4AUTFSS pMU2//4xRY7IrXsrruKU5D4VnTO0yQPAFQFOxHXTNsTCoLSxnxnPKvgchOnlEG6M9PO8 sT+IlKO3XNPQrvhLf8eoB6sb2YltSyVvpBKc+OXmpQ/akEqBOZ1EnbccVQ6+HyjgfxOk tmkFNh8u+5nQZmvWP8VF4kINDOCzd0j7WghbVaNth/lP/uAd6wstmOWb0xH5ZnZT6cg1 PcJVWB8UvNwGgLLuMmNzMt1EnwxqbBHN7l9C8qz8dfLFT+QBhuYI8bz224978+P2xPvH 8JHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003331; x=1691595331; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kRIoDdd0p00qTB3TzSNz7mfmNIx5ZZ+GLtrFSZRsJqY=; b=MUWDNraCO62Z28mkaKv4bvlf7C008h2oko5eMZr3253WUfLA68/PXD3XOrgl3fd+/y gpp4Ouhm31zaLxpdDbRFC6tVQIZ5wEH8ubHIKPcSQlk2jkQ9ufkka3v0PqPhRy0zgL8j fa0OMzzR+oYEAufkfQLJ3tgp0PYET1ig9Ez1Nf2bx8jcstQFufjWxc5ASXEMnuCzlGen fsHYd3cXsk+NpdDJ/0sibmeqMraDWdc8GCrBLqgf5KryYaQqqKc/9FmdPAC7Du15NKTb rKAm0IfDST0aktcF/KdlM5qMjcnZcV77QsNLkEO4pmZsrB+yXq7chW8FhU7qdZWHF1wx rT5g== X-Gm-Message-State: ABy/qLZyci54GZNe5iFLJvmfHlsU2sKdi+kVu+fJgDHSadJPbdnFSNej lWOSS6nam17eas9y0i4OAKGMBA== X-Received: by 2002:a7b:c39a:0:b0:3fb:ef86:e2e with SMTP id s26-20020a7bc39a000000b003fbef860e2emr13254161wmj.19.1689003331099; Mon, 10 Jul 2023 08:35:31 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id u10-20020a7bcb0a000000b003fb739d27aesm10538415wmj.35.2023.07.10.08.35.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:35:29 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 035211FFC2; Mon, 10 Jul 2023 16:35:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [PATCH v3 07/20] virtio: add vhost-user-base and a generic vhost-user-device Date: Mon, 10 Jul 2023 16:35:09 +0100 Message-Id: <20230710153522.3469097-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x330.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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-bounces+patch=linaro.org@nongnu.org In theory we shouldn't need to repeat so much boilerplate to support vhost-user backends. This provides a generic vhost-user-base QOM object and a derived vhost-user-device for which the user needs to provide the few bits of information that aren't currently provided by the vhost-user protocol. This should provide a baseline implementation from which the other vhost-user stub can specialise. Signed-off-by: Alex Bennée Signed-off-by: Michael S. Tsirkin --- v2 - split into vub and vud --- include/hw/virtio/vhost-user-device.h | 45 ++++ hw/virtio/vhost-user-device.c | 324 ++++++++++++++++++++++++++ hw/virtio/meson.build | 2 + 3 files changed, 371 insertions(+) create mode 100644 include/hw/virtio/vhost-user-device.h create mode 100644 hw/virtio/vhost-user-device.c diff --git a/include/hw/virtio/vhost-user-device.h b/include/hw/virtio/vhost-user-device.h new file mode 100644 index 0000000000..9105011e25 --- /dev/null +++ b/include/hw/virtio/vhost-user-device.h @@ -0,0 +1,45 @@ +/* + * Vhost-user generic virtio device + * + * Copyright (c) 2023 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef QEMU_VHOST_USER_DEVICE_H +#define QEMU_VHOST_USER_DEVICE_H + +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" + +#define TYPE_VHOST_USER_BASE "vhost-user-base" + +OBJECT_DECLARE_TYPE(VHostUserBase, VHostUserBaseClass, VHOST_USER_BASE) + +struct VHostUserBase { + VirtIODevice parent; + /* Properties */ + CharBackend chardev; + uint16_t virtio_id; + uint32_t num_vqs; + /* State tracking */ + VhostUserState vhost_user; + struct vhost_virtqueue *vhost_vq; + struct vhost_dev vhost_dev; + GPtrArray *vqs; + bool connected; +}; + + /* needed so we can use the base realize after specialisation + tweaks */ +struct VHostUserBaseClass { + /*< private >*/ + VirtioDeviceClass parent_class; + /*< public >*/ + DeviceRealize parent_realize; +}; + +/* shared for the benefit of the derived pci class */ +#define TYPE_VHOST_USER_DEVICE "vhost-user-device" + +#endif /* QEMU_VHOST_USER_DEVICE_H */ diff --git a/hw/virtio/vhost-user-device.c b/hw/virtio/vhost-user-device.c new file mode 100644 index 0000000000..b0239fa033 --- /dev/null +++ b/hw/virtio/vhost-user-device.c @@ -0,0 +1,324 @@ +/* + * Generic vhost-user stub. This can be used to connect to any + * vhost-user backend. All configuration details must be handled by + * the vhost-user daemon itself + * + * Copyright (c) 2023 Linaro Ltd + * Author: Alex Bennée + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/virtio-bus.h" +#include "hw/virtio/vhost-user-device.h" +#include "qemu/error-report.h" + +static void vub_start(VirtIODevice *vdev) +{ + BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); + VHostUserBase *vub = VHOST_USER_BASE(vdev); + int ret, i; + + if (!k->set_guest_notifiers) { + error_report("binding does not support guest notifiers"); + return; + } + + ret = vhost_dev_enable_notifiers(&vub->vhost_dev, vdev); + if (ret < 0) { + error_report("Error enabling host notifiers: %d", -ret); + return; + } + + ret = k->set_guest_notifiers(qbus->parent, vub->vhost_dev.nvqs, true); + if (ret < 0) { + error_report("Error binding guest notifier: %d", -ret); + goto err_host_notifiers; + } + + vub->vhost_dev.acked_features = vdev->guest_features; + + ret = vhost_dev_start(&vub->vhost_dev, vdev, true); + if (ret < 0) { + error_report("Error starting vhost-user-device: %d", -ret); + goto err_guest_notifiers; + } + + /* + * guest_notifier_mask/pending not used yet, so just unmask + * everything here. virtio-pci will do the right thing by + * enabling/disabling irqfd. + */ + for (i = 0; i < vub->vhost_dev.nvqs; i++) { + vhost_virtqueue_mask(&vub->vhost_dev, vdev, i, false); + } + + return; + +err_guest_notifiers: + k->set_guest_notifiers(qbus->parent, vub->vhost_dev.nvqs, false); +err_host_notifiers: + vhost_dev_disable_notifiers(&vub->vhost_dev, vdev); +} + +static void vub_stop(VirtIODevice *vdev) +{ + VHostUserBase *vub = VHOST_USER_BASE(vdev); + BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); + int ret; + + if (!k->set_guest_notifiers) { + return; + } + + vhost_dev_stop(&vub->vhost_dev, vdev, true); + + ret = k->set_guest_notifiers(qbus->parent, vub->vhost_dev.nvqs, false); + if (ret < 0) { + error_report("vhost guest notifier cleanup failed: %d", ret); + return; + } + + vhost_dev_disable_notifiers(&vub->vhost_dev, vdev); +} + +static void vub_set_status(VirtIODevice *vdev, uint8_t status) +{ + VHostUserBase *vub = VHOST_USER_BASE(vdev); + bool should_start = virtio_device_should_start(vdev, status); + + if (vhost_dev_is_started(&vub->vhost_dev) == should_start) { + return; + } + + if (should_start) { + vub_start(vdev); + } else { + vub_stop(vdev); + } +} + +/* + * For an implementation where everything is delegated to the backend + * we don't do anything other than return the full feature set offered + * by the daemon (module the reserved feature bit). + */ +static uint64_t vub_get_features(VirtIODevice *vdev, + uint64_t requested_features, Error **errp) +{ + VHostUserBase *vub = VHOST_USER_BASE(vdev); + /* This should be set when the vhost connection initialises */ + g_assert(vub->vhost_dev.features); + return vub->vhost_dev.features & ~(1ULL << VHOST_USER_F_PROTOCOL_FEATURES); +} + +static void vub_handle_output(VirtIODevice *vdev, VirtQueue *vq) +{ + /* + * Not normally called; it's the daemon that handles the queue; + * however virtio's cleanup path can call this. + */ +} + +static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserBase *vub) +{ + vhost_user_cleanup(&vub->vhost_user); + + for (int i = 0; i < vub->num_vqs; i++) { + VirtQueue *vq = g_ptr_array_index(vub->vqs, i); + virtio_delete_queue(vq); + } + + virtio_cleanup(vdev); +} + +static int vub_connect(DeviceState *dev) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VHostUserBase *vub = VHOST_USER_BASE(vdev); + + if (vub->connected) { + return 0; + } + vub->connected = true; + + /* restore vhost state */ + if (virtio_device_started(vdev, vdev->status)) { + vub_start(vdev); + } + + return 0; +} + +static void vub_disconnect(DeviceState *dev) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VHostUserBase *vub = VHOST_USER_BASE(vdev); + + if (!vub->connected) { + return; + } + vub->connected = false; + + if (vhost_dev_is_started(&vub->vhost_dev)) { + vub_stop(vdev); + } +} + +static void vub_event(void *opaque, QEMUChrEvent event) +{ + DeviceState *dev = opaque; + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VHostUserBase *vub = VHOST_USER_BASE(vdev); + + switch (event) { + case CHR_EVENT_OPENED: + if (vub_connect(dev) < 0) { + qemu_chr_fe_disconnect(&vub->chardev); + return; + } + break; + case CHR_EVENT_CLOSED: + vub_disconnect(dev); + break; + case CHR_EVENT_BREAK: + case CHR_EVENT_MUX_IN: + case CHR_EVENT_MUX_OUT: + /* Ignore */ + break; + } +} + +static void vub_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VHostUserBase *vub = VHOST_USER_BASE(dev); + int ret; + + if (!vub->chardev.chr) { + error_setg(errp, "vhost-user-device: missing chardev"); + return; + } + + if (!vub->virtio_id) { + error_setg(errp, "vhost-user-device: need to define device id"); + return; + } + + if (!vub->num_vqs) { + vub->num_vqs = 1; /* reasonable default? */ + } + + if (!vhost_user_init(&vub->vhost_user, &vub->chardev, errp)) { + return; + } + + virtio_init(vdev, vub->virtio_id, 0); + + /* + * Disable guest notifiers, by default all notifications will be via the + * asynchronous vhost-user socket. + */ + vdev->use_guest_notifier_mask = false; + + /* Allocate queues */ + vub->vqs = g_ptr_array_sized_new(vub->num_vqs); + for (int i = 0; i < vub->num_vqs; i++) { + g_ptr_array_add(vub->vqs, + virtio_add_queue(vdev, 4, vub_handle_output)); + } + + vub->vhost_dev.nvqs = vub->num_vqs; + vub->vhost_dev.vqs = g_new0(struct vhost_virtqueue, vub->vhost_dev.nvqs); + + /* connect to backend */ + ret = vhost_dev_init(&vub->vhost_dev, &vub->vhost_user, + VHOST_BACKEND_TYPE_USER, 0, errp); + + if (ret < 0) { + do_vhost_user_cleanup(vdev, vub); + } + + qemu_chr_fe_set_handlers(&vub->chardev, NULL, NULL, vub_event, NULL, + dev, NULL, true); +} + +static void vub_device_unrealize(DeviceState *dev) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VHostUserBase *vub = VHOST_USER_BASE(dev); + struct vhost_virtqueue *vhost_vqs = vub->vhost_dev.vqs; + + /* This will stop vhost backend if appropriate. */ + vub_set_status(vdev, 0); + vhost_dev_cleanup(&vub->vhost_dev); + g_free(vhost_vqs); + do_vhost_user_cleanup(vdev, vub); +} + +static void vub_class_init(ObjectClass *klass, void *data) +{ + VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + + vdc->realize = vub_device_realize; + vdc->unrealize = vub_device_unrealize; + vdc->get_features = vub_get_features; + vdc->set_status = vub_set_status; +} + +static const TypeInfo vub_info = { + .name = TYPE_VHOST_USER_BASE, + .parent = TYPE_VIRTIO_DEVICE, + .instance_size = sizeof(VHostUserBase), + .class_init = vub_class_init, + .class_size = sizeof(VHostUserBaseClass), + .abstract = true +}; + + +/* + * The following is a concrete implementation of the base class which + * allows the user to define the key parameters via the command line. + */ + +static const VMStateDescription vud_vmstate = { + .name = "vhost-user-device", + .unmigratable = 1, +}; + +static Property vud_properties[] = { + DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), + DEFINE_PROP_UINT16("virtio-id", VHostUserBase, virtio_id, 0), + DEFINE_PROP_UINT32("num_vqs", VHostUserBase, num_vqs, 1), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vud_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + device_class_set_props(dc, vud_properties); + dc->vmsd = &vud_vmstate; + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); +} + +static const TypeInfo vud_info = { + .name = TYPE_VHOST_USER_DEVICE, + .parent = TYPE_VHOST_USER_BASE, + .instance_size = sizeof(VHostUserBase), + .class_init = vud_class_init, + .class_size = sizeof(VHostUserBaseClass), +}; + +static void vu_register_types(void) +{ + type_register_static(&vub_info); + type_register_static(&vud_info); +} + +type_init(vu_register_types) diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index f32b22f61b..b87c5523e7 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -15,7 +15,9 @@ if have_vhost softmmu_virtio_ss.add(files('vhost.c')) specific_virtio_ss.add(files('vhost-backend.c', 'vhost-iova-tree.c')) if have_vhost_user + # fixme - this really should be generic specific_virtio_ss.add(files('vhost-user.c')) + softmmu_virtio_ss.add(files('vhost-user-device.c')) endif if have_vhost_vdpa specific_virtio_ss.add(files('vhost-vdpa.c', 'vhost-shadow-virtqueue.c')) From patchwork Mon Jul 10 15:35:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701029 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5243441wrs; Mon, 10 Jul 2023 08:37:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlFpkHvvh/1Z5sg8aVob6LWWOmbU6rsRxNE3Tump1R70UfWn9JWD9M2n6k18EgI7Gd3dwbY6 X-Received: by 2002:a05:620a:2809:b0:765:4878:9d20 with SMTP id f9-20020a05620a280900b0076548789d20mr12544293qkp.61.1689003444353; Mon, 10 Jul 2023 08:37:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003444; cv=none; d=google.com; s=arc-20160816; b=BHjRo6jCPpv6DsNUkPyUQVeZEwCQ60x5wlrjlNnt4kWCivLmN7kahWPyRO5Mw/BRU5 CA2KcAyylBo8zxtDgchtnNZF64hQxQFDY6P06CED5FrIX7U7vDkbc9Y2TQ3YVMBXon7M QeZ5oz9BD3zYfMRt98F0VYDrz8OQXkV7J1v3EUqzBbdk3pqRYtrNTV/4zxCN0XmlUQhY s2fU5ts6Rx/2H2lJpV6L5n3Nsc8qMmOQHwcREEy1NiTMnEcoGjt+Qm2D4zf8I41poOYC 5gsU4cw3j0PZY1EMAi6aCLVIXPW3VxNK/So20brCr3JNwD4v1hUEvH18fWJYixmF1Ple i/mA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9tMjRjVxXlcAyveN1BbPQH3Nll2IHvq76/Eq339lGng=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=QSingfxsHAgNuYCOUiPFRh40sueoG57CcrR1p0aGm3cghu7mm2lptZsvnojagRBoZw EKlxtHcejeLDtpW5NnH4hIqVWS6ou6dMzBeWl6PVP4R6Hv4tkhiGw4Bwj5oMkuIPJTmM eBBf50Mm+hZEPQrz4FSFdajkIWlW55mlxn498m/JBZOUXT6XC1PRIv1QK7nd+Zjdw08m elpvG/0p8TxekVtnI/Rw2pBMB8PnBMU0hZ9Ryhp4egVn8EUdJgFupuraSRrnx7uyutCg opccB52nzvQJ/CBmMK3xyspZWnXH6/FU1M2+5TZO8H2o4N5frKe3ySU3RDKAhSQB4wLH D/bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cFywZH65; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c21-20020a05620a11b500b007608c82b593si5742270qkk.215.2023.07.10.08.37.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:37:24 -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=@linaro.org header.s=google header.b=cFywZH65; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIsvi-0005xa-Ma; Mon, 10 Jul 2023 11:36:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIsvX-0005py-PQ for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:52 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIsvG-0004mA-3w for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:50 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fbf1b82de7so34220695e9.1 for ; Mon, 10 Jul 2023 08:35:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003332; x=1691595332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9tMjRjVxXlcAyveN1BbPQH3Nll2IHvq76/Eq339lGng=; b=cFywZH65UhJ2Zn1R3CgaqM6BYfFdCW0Yj3VxquSqETsDyfA+KJZjJRIW6OUhvcqPQd zJi0/bHT+9HdYfAeOTLHZOk6L3fAllmPYDtD20KsYbPyROgJs1sFrXsfzlRW40R5vxv+ MBy/RS9K/WxjFg9LaSzuqki7fzXzXhia0PhE2TUpg6TQqoBYOMFE6TmVcu4PvnSYBZ6s iZbNQ+6vR6bOf9Q5fX+BpDpwxDWLIIvuwSohm5Fc1hxjT59NFa3yQLfZfc/t0vAKIKel TQ5fORkMHNia2Cec4y07yxltaaPPAUOtkifD3qm0Vm3gvGox45kwbH2OoyOH29nlAkUl 7k6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003332; x=1691595332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9tMjRjVxXlcAyveN1BbPQH3Nll2IHvq76/Eq339lGng=; b=e+K2Lwq2s5aCEsB5DXVq3E752VRsk59Wvzx1u+tAYek1qlBrJlJ2yPzUefu3oZLGu4 G6bJmdzb7PYSoJZDY/PZMfFyQ5v+xC5TiBtzSzy2PL2b4HTbM4v/yBPVUAaj2cTwgrcP 7xAU+B0Z1zWb1F9uQdbdN5hrGPvfBnDAR99kFqksRELqJm0DG4pR4z+aeyJBAwEiM7t8 3iL1cS9J/SrofnqEGKACwbRTQlBiyrvCkxlHPZHz4R+8gXdhm2kAOf5hiGbzk/sIUwEa yMGspSs7qKKzyYo+P3WRtl7j1xtoikGiFpa/+gzTB6OcOIRzXIeVc6P7LERDozlT8vc7 kZwQ== X-Gm-Message-State: ABy/qLbNIOyN110TvEjWswRvnOEdGGKJW8dMchLvCxjgdfKprN+a1wlW VgkTt6TmsFynry8q7sF5eIYNUw== X-Received: by 2002:a05:600c:35c3:b0:3fa:125c:8d65 with SMTP id r3-20020a05600c35c300b003fa125c8d65mr14771442wmq.3.1689003332066; Mon, 10 Jul 2023 08:35:32 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id s21-20020a7bc395000000b003fbc89af035sm183251wmj.17.2023.07.10.08.35.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:35:29 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 1D95A1FFC3; Mon, 10 Jul 2023 16:35:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [PATCH v3 08/20] virtio: add PCI stub for vhost-user-device Date: Mon, 10 Jul 2023 16:35:10 +0100 Message-Id: <20230710153522.3469097-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=unavailable 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-bounces+patch=linaro.org@nongnu.org This is all pretty much boilerplate. Signed-off-by: Alex Bennée Tested-by: Erik Schilling --- hw/virtio/vhost-user-device-pci.c | 71 +++++++++++++++++++++++++++++++ hw/virtio/meson.build | 1 + 2 files changed, 72 insertions(+) create mode 100644 hw/virtio/vhost-user-device-pci.c diff --git a/hw/virtio/vhost-user-device-pci.c b/hw/virtio/vhost-user-device-pci.c new file mode 100644 index 0000000000..41f9b7905b --- /dev/null +++ b/hw/virtio/vhost-user-device-pci.c @@ -0,0 +1,71 @@ +/* + * Vhost-user generic virtio device PCI glue + * + * Copyright (c) 2023 Linaro Ltd + * Author: Alex Bennée + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/vhost-user-device.h" +#include "hw/virtio/virtio-pci.h" + +struct VHostUserDevicePCI { + VirtIOPCIProxy parent_obj; + VHostUserBase vub; +}; + +typedef struct VHostUserDevicePCI VHostUserDevicePCI; + +#define TYPE_VHOST_USER_DEVICE_PCI "vhost-user-device-pci-base" + +DECLARE_INSTANCE_CHECKER(VHostUserDevicePCI, + VHOST_USER_DEVICE_PCI, + TYPE_VHOST_USER_DEVICE_PCI) + +static void vhost_user_device_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) +{ + VHostUserDevicePCI *dev = VHOST_USER_DEVICE_PCI(vpci_dev); + DeviceState *vdev = DEVICE(&dev->vub); + + vpci_dev->nvectors = 1; + qdev_realize(vdev, BUS(&vpci_dev->bus), errp); +} + +static void vhost_user_device_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); + k->realize = vhost_user_device_pci_realize; + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id = 0; /* Set by virtio-pci based on virtio id */ + pcidev_k->revision = 0x00; + pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER; +} + +static void vhost_user_device_pci_instance_init(Object *obj) +{ + VHostUserDevicePCI *dev = VHOST_USER_DEVICE_PCI(obj); + + virtio_instance_init_common(obj, &dev->vub, sizeof(dev->vub), + TYPE_VHOST_USER_DEVICE); +} + +static const VirtioPCIDeviceTypeInfo vhost_user_device_pci_info = { + .base_name = TYPE_VHOST_USER_DEVICE_PCI, + .non_transitional_name = "vhost-user-device-pci", + .instance_size = sizeof(VHostUserDevicePCI), + .instance_init = vhost_user_device_pci_instance_init, + .class_init = vhost_user_device_pci_class_init, +}; + +static void vhost_user_device_pci_register(void) +{ + virtio_pci_types_register(&vhost_user_device_pci_info); +} + +type_init(vhost_user_device_pci_register); diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index b87c5523e7..1e1df77783 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -18,6 +18,7 @@ if have_vhost # fixme - this really should be generic specific_virtio_ss.add(files('vhost-user.c')) softmmu_virtio_ss.add(files('vhost-user-device.c')) + softmmu_virtio_ss.add(when: 'CONFIG_VIRTIO_PCI', if_true: files('vhost-user-device-pci.c')) endif if have_vhost_vdpa specific_virtio_ss.add(files('vhost-vdpa.c', 'vhost-shadow-virtqueue.c')) From patchwork Mon Jul 10 15:35:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701027 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5243353wrs; Mon, 10 Jul 2023 08:37:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlEoWt8QpmduRNiEvVx27R7vXDSYJtbWoSKIIBRTsiktRbChgkU69Ja0K1C4TRqKb+v3MJ8N X-Received: by 2002:a37:ab0e:0:b0:765:a57a:16fe with SMTP id u14-20020a37ab0e000000b00765a57a16femr11749384qke.76.1689003431753; Mon, 10 Jul 2023 08:37:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003431; cv=none; d=google.com; s=arc-20160816; b=MpP0sZItMG4Qp3zzMIrx+iifcl2OVLDLZfrsnSWqo+Du//CRmIy2uTKpY9zzdH5uuI rSuCL4+o7YW/rfA0n2Jo4BNQcWuxe3NoFQK5udI/LLUeudEMNQ0y+rrk2u1SXNsxSBvh eQktFt+bdw7DtxWPcmrEN+V59nfnmUQ1+u3n4k73ycon2QrV2BNqBlBNUoN+g9SD3qcU IZHyXYIFwBVXO152UHIFgZBWBdT3e7oQOGE8BOzTZaNlMYz3aaOWrvAJKaSJZTdJw13Y t4q4IVh/g1VIYYlNPP6qmGiXnNPGq9Zi/++UT3qzVVIOa1HrwhuLk8fiKV9vGL0TNUob 4V3Q== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rdFHUc4Eq3wKAipF4SX95dDFFt52izFZ/2dyPXmKfbE=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=Xf1NtsAm90KUYvez/0WKlC7jVUZG9HLb8PFJ/rpEZNSG7l4vbhRb+dRgmkdCytomgk ddrKXkhWj65lknfqF1avC6Xrx4tk+9pI+6CTbxpO5ced7vkLCzdgiFBhYRmTAJ407paD aYFar/hKk6+bms/3jmLUkpBYW9ki8lzDCwfm5EwmgX8FQYj/weN4X179Rp+20Y97CYa5 I6gWDW2odzmz5sq+vwR7vomGNft0SHaFj/a19pviyhNiBWiLj2PgeWRosiciA3goYlnH 0uiCDNG+vtqIUe5Zz1yld9RWmZF7KCU0V2284fDQPtHz/fvuA5SFN1cDrcn1Q8InH+O8 62tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eFiMLsUr; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bi38-20020a05620a31a600b00767b74227b6si3755378qkb.444.2023.07.10.08.37.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:37:11 -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=@linaro.org header.s=google header.b=eFiMLsUr; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIsvc-0005t8-6p; Mon, 10 Jul 2023 11:35:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIsvR-0005mL-MM for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:49 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIsvG-0004mC-IJ for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:45 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-314172bb818so5028784f8f.1 for ; Mon, 10 Jul 2023 08:35:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003332; x=1691595332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rdFHUc4Eq3wKAipF4SX95dDFFt52izFZ/2dyPXmKfbE=; b=eFiMLsUru/VV8kVPFm0Y5Qa2d46683ycpaGaVlW+H3v3Wrf43hyvQ74S/BlNtqE97s xqls8Nj5LzpThId8Mh1nppn2ZMbGCwSip24xGyR07blIOu2ZUlOeCtikgev+rHgYuu2p MP+LGeLeBVIMSvvvA5eIHPa0nOhoLZ462rhujz7WAX3067pEus2NBYDwa4RU2ld419qw PfQe6eTG8vsQO2O2/3O0ocpruYpvLwYoEpCSM7ukVpYDEAzL4pX9rtHBU9mdC/TMJdJy s5yGuMiFvl49+GUQ9Tcf93ZugJ6ACylvKL3jJbSLDuTUK8YNpZ5esHTuGw6ba4UK0hpa WKwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003332; x=1691595332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rdFHUc4Eq3wKAipF4SX95dDFFt52izFZ/2dyPXmKfbE=; b=W4miakR/whDQwALIUyDKnuhxrIz+Zvpn5SAiSHT4aus2Gn61S7E5f3u88kFLUkxA0/ Usgb18SlRphUQZ3nXkjhLgHwOSiH4cDYzzYehbggUYcCqPbnETK/RicYofjjiZdwLNTG iATub72Rw+YGU37Ni9ZRQmhtb5nnjoAK57XaCVrbsbfxCJCD9MSptZAjGncE+R1yK1FO DL+19OMvcL/HN3SMs97FOVKlYBcZg5ncU7hnZ+66UWy0CMqXMXDVRyEeIQqWWX7ZZdbb iYfXDock4g2ZHW2C0HDBbYJ2fugCCQIom71qVGzb6QYlnx4gRN/9+0nwlQvv0SvAmCwF 235w== X-Gm-Message-State: ABy/qLalnddnhWMIF/CXJCgUln10/fL45jC3i8FmvBHATSujbN9MNv1m It59bEVEQYI+ZM/8NZjg0wcUuA== X-Received: by 2002:adf:ea86:0:b0:313:fe1b:f441 with SMTP id s6-20020adfea86000000b00313fe1bf441mr13591505wrm.29.1689003332348; Mon, 10 Jul 2023 08:35:32 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id l8-20020a5d5608000000b003142c85fbcdsm12080035wrv.11.2023.07.10.08.35.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:35:30 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 3CBAC1FFC4; Mon, 10 Jul 2023 16:35:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [PATCH v3 09/20] hw/virtio: derive vhost-user-rng from vhost-user-device Date: Mon, 10 Jul 2023 16:35:11 +0100 Message-Id: <20230710153522.3469097-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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-bounces+patch=linaro.org@nongnu.org Now we can take advantage of our new base class and make vhost-user-rng a much simpler boilerplate wrapper. Also as this doesn't require any target specific hacks we only need to build the stubs once. Signed-off-by: Alex Bennée --- v2 - new derivation layout - move directly to softmmu_virtio_ss --- include/hw/virtio/vhost-user-rng.h | 11 +- hw/virtio/vhost-user-rng.c | 277 +++-------------------------- hw/virtio/meson.build | 7 +- 3 files changed, 28 insertions(+), 267 deletions(-) diff --git a/include/hw/virtio/vhost-user-rng.h b/include/hw/virtio/vhost-user-rng.h index ddd9f01eea..13139c0d9d 100644 --- a/include/hw/virtio/vhost-user-rng.h +++ b/include/hw/virtio/vhost-user-rng.h @@ -12,21 +12,14 @@ #include "hw/virtio/virtio.h" #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-user.h" -#include "chardev/char-fe.h" +#include "hw/virtio/vhost-user-device.h" #define TYPE_VHOST_USER_RNG "vhost-user-rng" OBJECT_DECLARE_SIMPLE_TYPE(VHostUserRNG, VHOST_USER_RNG) struct VHostUserRNG { /*< private >*/ - VirtIODevice parent; - CharBackend chardev; - struct vhost_virtqueue *vhost_vq; - struct vhost_dev vhost_dev; - VhostUserState vhost_user; - VirtQueue *req_vq; - bool connected; - + VHostUserBase parent; /*< public >*/ }; diff --git a/hw/virtio/vhost-user-rng.c b/hw/virtio/vhost-user-rng.c index efc54cd3fb..71d3991f93 100644 --- a/hw/virtio/vhost-user-rng.c +++ b/hw/virtio/vhost-user-rng.c @@ -3,7 +3,7 @@ * * Copyright (c) 2021 Mathieu Poirier * - * Implementation seriously tailored on vhost-user-i2c.c + * Simple wrapper of the generic vhost-user-device. * * SPDX-License-Identifier: GPL-2.0-or-later */ @@ -13,281 +13,46 @@ #include "hw/qdev-properties.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/vhost-user-rng.h" -#include "qemu/error-report.h" #include "standard-headers/linux/virtio_ids.h" -static const int feature_bits[] = { - VIRTIO_F_RING_RESET, - VHOST_INVALID_FEATURE_BIT -}; - -static void vu_rng_start(VirtIODevice *vdev) -{ - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); - int ret; - int i; - - if (!k->set_guest_notifiers) { - error_report("binding does not support guest notifiers"); - return; - } - - ret = vhost_dev_enable_notifiers(&rng->vhost_dev, vdev); - if (ret < 0) { - error_report("Error enabling host notifiers: %d", -ret); - return; - } - - ret = k->set_guest_notifiers(qbus->parent, rng->vhost_dev.nvqs, true); - if (ret < 0) { - error_report("Error binding guest notifier: %d", -ret); - goto err_host_notifiers; - } - - rng->vhost_dev.acked_features = vdev->guest_features; - ret = vhost_dev_start(&rng->vhost_dev, vdev, true); - if (ret < 0) { - error_report("Error starting vhost-user-rng: %d", -ret); - goto err_guest_notifiers; - } - - /* - * guest_notifier_mask/pending not used yet, so just unmask - * everything here. virtio-pci will do the right thing by - * enabling/disabling irqfd. - */ - for (i = 0; i < rng->vhost_dev.nvqs; i++) { - vhost_virtqueue_mask(&rng->vhost_dev, vdev, i, false); - } - - return; - -err_guest_notifiers: - k->set_guest_notifiers(qbus->parent, rng->vhost_dev.nvqs, false); -err_host_notifiers: - vhost_dev_disable_notifiers(&rng->vhost_dev, vdev); -} - -static void vu_rng_stop(VirtIODevice *vdev) -{ - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); - int ret; - - if (!k->set_guest_notifiers) { - return; - } - - vhost_dev_stop(&rng->vhost_dev, vdev, true); - - ret = k->set_guest_notifiers(qbus->parent, rng->vhost_dev.nvqs, false); - if (ret < 0) { - error_report("vhost guest notifier cleanup failed: %d", ret); - return; - } - - vhost_dev_disable_notifiers(&rng->vhost_dev, vdev); -} - -static void vu_rng_set_status(VirtIODevice *vdev, uint8_t status) -{ - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - bool should_start = virtio_device_should_start(vdev, status); - - if (vhost_dev_is_started(&rng->vhost_dev) == should_start) { - return; - } - - if (should_start) { - vu_rng_start(vdev); - } else { - vu_rng_stop(vdev); - } -} - -static uint64_t vu_rng_get_features(VirtIODevice *vdev, - uint64_t requested_features, Error **errp) -{ - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - - return vhost_get_features(&rng->vhost_dev, feature_bits, - requested_features); -} - -static void vu_rng_handle_output(VirtIODevice *vdev, VirtQueue *vq) -{ - /* - * Not normally called; it's the daemon that handles the queue; - * however virtio's cleanup path can call this. - */ -} - -static void vu_rng_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask) -{ - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - - vhost_virtqueue_mask(&rng->vhost_dev, vdev, idx, mask); -} - -static bool vu_rng_guest_notifier_pending(VirtIODevice *vdev, int idx) -{ - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - - return vhost_virtqueue_pending(&rng->vhost_dev, idx); -} - -static void vu_rng_connect(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - - if (rng->connected) { - return; - } - - rng->connected = true; - - /* restore vhost state */ - if (virtio_device_started(vdev, vdev->status)) { - vu_rng_start(vdev); - } -} - -static void vu_rng_disconnect(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - - if (!rng->connected) { - return; - } - - rng->connected = false; - - if (vhost_dev_is_started(&rng->vhost_dev)) { - vu_rng_stop(vdev); - } -} - -static void vu_rng_event(void *opaque, QEMUChrEvent event) -{ - DeviceState *dev = opaque; - - switch (event) { - case CHR_EVENT_OPENED: - vu_rng_connect(dev); - break; - case CHR_EVENT_CLOSED: - vu_rng_disconnect(dev); - break; - case CHR_EVENT_BREAK: - case CHR_EVENT_MUX_IN: - case CHR_EVENT_MUX_OUT: - /* Ignore */ - break; - } -} - -static void vu_rng_device_realize(DeviceState *dev, Error **errp) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserRNG *rng = VHOST_USER_RNG(dev); - int ret; - - if (!rng->chardev.chr) { - error_setg(errp, "missing chardev"); - return; - } - - if (!vhost_user_init(&rng->vhost_user, &rng->chardev, errp)) { - return; - } - - virtio_init(vdev, VIRTIO_ID_RNG, 0); - - rng->req_vq = virtio_add_queue(vdev, 4, vu_rng_handle_output); - if (!rng->req_vq) { - error_setg_errno(errp, -1, "virtio_add_queue() failed"); - goto virtio_add_queue_failed; - } - - rng->vhost_dev.nvqs = 1; - rng->vhost_dev.vqs = g_new0(struct vhost_virtqueue, rng->vhost_dev.nvqs); - ret = vhost_dev_init(&rng->vhost_dev, &rng->vhost_user, - VHOST_BACKEND_TYPE_USER, 0, errp); - if (ret < 0) { - error_setg_errno(errp, -ret, "vhost_dev_init() failed"); - goto vhost_dev_init_failed; - } - - qemu_chr_fe_set_handlers(&rng->chardev, NULL, NULL, vu_rng_event, NULL, - dev, NULL, true); - - return; - -vhost_dev_init_failed: - g_free(rng->vhost_dev.vqs); - virtio_delete_queue(rng->req_vq); -virtio_add_queue_failed: - virtio_cleanup(vdev); - vhost_user_cleanup(&rng->vhost_user); -} - -static void vu_rng_device_unrealize(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserRNG *rng = VHOST_USER_RNG(dev); - struct vhost_virtqueue *vhost_vqs = rng->vhost_dev.vqs; - - vu_rng_set_status(vdev, 0); - - vhost_dev_cleanup(&rng->vhost_dev); - g_free(vhost_vqs); - virtio_delete_queue(rng->req_vq); - virtio_cleanup(vdev); - vhost_user_cleanup(&rng->vhost_user); -} - -static struct vhost_dev *vu_rng_get_vhost(VirtIODevice *vdev) -{ - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - return &rng->vhost_dev; -} - static const VMStateDescription vu_rng_vmstate = { .name = "vhost-user-rng", .unmigratable = 1, }; -static Property vu_rng_properties[] = { - DEFINE_PROP_CHR("chardev", VHostUserRNG, chardev), +static Property vrng_properties[] = { + DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), DEFINE_PROP_END_OF_LIST(), }; +static void vu_rng_base_realize(DeviceState *dev, Error **errp) +{ + VHostUserBase *vub = VHOST_USER_BASE(dev); + VHostUserBaseClass *vubs = VHOST_USER_BASE_GET_CLASS(dev); + + /* Fixed for RNG */ + vub->virtio_id = VIRTIO_ID_RNG; + vub->num_vqs = 1; + + vubs->parent_realize(dev, errp); +} + static void vu_rng_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass); - device_class_set_props(dc, vu_rng_properties); dc->vmsd = &vu_rng_vmstate; - set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + device_class_set_props(dc, vrng_properties); + device_class_set_parent_realize(dc, vu_rng_base_realize, + &vubc->parent_realize); - vdc->realize = vu_rng_device_realize; - vdc->unrealize = vu_rng_device_unrealize; - vdc->get_features = vu_rng_get_features; - vdc->set_status = vu_rng_set_status; - vdc->guest_notifier_mask = vu_rng_guest_notifier_mask; - vdc->guest_notifier_pending = vu_rng_guest_notifier_pending; - vdc->get_vhost = vu_rng_get_vhost; + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); } static const TypeInfo vu_rng_info = { .name = TYPE_VHOST_USER_RNG, - .parent = TYPE_VIRTIO_DEVICE, + .parent = TYPE_VHOST_USER_BASE, .instance_size = sizeof(VHostUserRNG), .class_init = vu_rng_class_init, }; diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 1e1df77783..fb80587d5b 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -7,6 +7,11 @@ softmmu_virtio_ss.add(when: 'CONFIG_VHOST_VSOCK_COMMON', if_true: files('vhost-v softmmu_virtio_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu.c')) softmmu_virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev.c')) +# VirtIO stubs which don't need building per-guest +softmmu_virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c')) +softmmu_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_RNG'], + if_true: files('vhost-user-rng-pci.c')) + specific_virtio_ss = ss.source_set() specific_virtio_ss.add(files('virtio.c')) specific_virtio_ss.add(files('virtio-config-io.c', 'virtio-qmp.c')) @@ -35,7 +40,6 @@ specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-us specific_virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng.c')) specific_virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c')) -specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vhost-user-gpio.c')) specific_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_GPIO'], if_true: files('vhost-user-gpio-pci.c')) @@ -45,7 +49,6 @@ virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-user-vs virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-blk-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_INPUT', if_true: files('vhost-user-input-pci.c')) -virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_SCSI', if_true: files('vhost-user-scsi-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('vhost-scsi-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs-pci.c')) From patchwork Mon Jul 10 15:35:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701034 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5243773wrs; Mon, 10 Jul 2023 08:38:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlFsCYTe5P9814wt8elqRqq+XFqOOo4FAA2wSpy8fwbQRyT3d5W58Y9NsFzjrSt0QI1jjW9L X-Received: by 2002:a25:ab85:0:b0:c6c:dda4:f449 with SMTP id v5-20020a25ab85000000b00c6cdda4f449mr9789929ybi.41.1689003488369; Mon, 10 Jul 2023 08:38:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003488; cv=none; d=google.com; s=arc-20160816; b=rUU64U2NMueeK+7NtSG+RiT8n2TujZyByDN7jPU5aAxnNVuQUHmWxu9jivdtqutxKt KrhYNCJHq4CMD+PSZoa2rd1DdNNkiTpczBHgO+Afs8u9igOGkDZrgbfalHl2P2vxOHHk W57fVlw7a8W8UzK8w967kU9Kxxce8HHz6y/LTxr6o1NrchCzz/8KXU2gmBWgepO3RYNh X/18F3bLJODaygpZ2KHLrBmRLsT464xwcXYHHV2lcO7oeK19P4uLYF38FyVl1oJ8Yort PeHA6kUYxpxKaRXORFaAXdxQeC8CEj6wSC+VRHC9kg8lDHsxunXm9YfSGlAEpf+LxUVG bKXQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uTkEU0oqDGeWEiEFn49DE5kPkeQF20sGslhQri+i2Js=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=RQhM9PWXMEDgOiQi3sL1okA85OlLg9PryKNJneasF7uYg1O03Ku9XF+89rU8cXYvZQ BCxYWFmdx7MqVOKuoAR4P8Kxr/tVWh50GA8cJm8Ol1dewVcwQO3nWJ9BJZ/AHyKWHUfl CydloVrYDIdKrHxhRt1M0cZ2ibEnN2M2F87mMh6FnmVCu6H1wd2yW2r82yh4j4AXSy5q AIZk9Z4IsSyNNbOWxQbEVUQLz9dEwM9whFH93T/QZMa6ugdXF6SbI3G83YEYcQ3rgE4T KImN8mu75xEVul8CS5xhOGb/svam+tQYSlOcT9BJ0TPqYLwysakdNWVXtidKJ1kQ8/jc AWUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Gb60r5gh; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p20-20020a05622a00d400b00403acaaaeb3si31095qtw.36.2023.07.10.08.38.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:38:08 -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=@linaro.org header.s=google header.b=Gb60r5gh; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIsvj-0005yF-KD; Mon, 10 Jul 2023 11:36:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIsvW-0005po-LR for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:50 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIsvJ-0004mn-2U for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:50 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fbc5d5742eso51880085e9.3 for ; Mon, 10 Jul 2023 08:35:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003333; x=1691595333; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uTkEU0oqDGeWEiEFn49DE5kPkeQF20sGslhQri+i2Js=; b=Gb60r5ghyLsbjsw/emm/XNOO5XDsv73JGPkCO6Jg/NLliM9W8ko2COzk5S4LrX+Ks7 uRjWlcAAdWqpuUU6s1HF939iHae0Bsz3OBGc1L0EKpfhoBUNGe7kWsBb+KirTKMG+KqB Yr7OYYc9dp6hwzvGDNaNC7QRrpLxF2ER6fY/Svzx2iGoGdwlg7jXy/qxLmevPi8FXmCo igvyoe3d2e3HXe1wH6VYcU+GS3SPvR3VF2nccn/o7xKBeF87Xe16sD2JGtexBbAB1DNp ooYiJxLqf/abGLFpdQfS+Al20i/IFZwaDuNlATC8CGIgB4CpLsSu6y/qjrQNbd/G9pEV XGFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003333; x=1691595333; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uTkEU0oqDGeWEiEFn49DE5kPkeQF20sGslhQri+i2Js=; b=eO9IIsRb/tQqdoU1Yr5yj98e41MqF1WWjNciDLB3+7ga2taplA1rI6N10o3VDomYeE eUzhZFEVDu3r2WyLN5D3SUZyHODZLVjtlvi9JINqYASOnYcxzQnmOCG88ZRLfpLnoAgD 19ufd3Ws+D2Iuw24PYOcRcj0/r/gkUDF6lhy9wlM6C09p3zOpuY2cQ3I94pOerP6HXOn cX7bteBa5rayu152+r+BxTu58gcNimV67VQZpOTiM0sy4oRb65juXTDJkWmRnpVzt4de jGne22KRNT1QwmqxPymfOAkbBAbEdnrVG5ctX8oLWjt+H0YJSfkErtZpX+fLo1UW+Qmw SMLA== X-Gm-Message-State: ABy/qLaFGqrhvJR2Jcn5QxJVj3tbdt67ilEtHifTdXDTzzR6xYGne/Rd LADfacwlQ3jmj8hgaN9Px4884A== X-Received: by 2002:a05:600c:c8:b0:3fb:ce46:c0b3 with SMTP id u8-20020a05600c00c800b003fbce46c0b3mr14257914wmm.35.1689003333598; Mon, 10 Jul 2023 08:35:33 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id z21-20020a7bc7d5000000b003fbd04ecdc6sm10810580wmk.5.2023.07.10.08.35.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:35:30 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 584DD1FFC5; Mon, 10 Jul 2023 16:35:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [PATCH v3 10/20] hw/virtio: add config support to vhost-user-device Date: Mon, 10 Jul 2023 16:35:12 +0100 Message-Id: <20230710153522.3469097-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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-bounces+patch=linaro.org@nongnu.org To use the generic device the user will need to provide the config region size via the command line. We also add a notifier so the guest can be pinged if the remote daemon updates the config. With these changes: -device vhost-user-device-pci,virtio-id=41,num_vqs=2,config_size=8 is equivalent to: -device vhost-user-gpio-pci Signed-off-by: Alex Bennée --- include/hw/virtio/vhost-user-device.h | 1 + hw/virtio/vhost-user-device.c | 58 ++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/include/hw/virtio/vhost-user-device.h b/include/hw/virtio/vhost-user-device.h index 9105011e25..3ddf88a146 100644 --- a/include/hw/virtio/vhost-user-device.h +++ b/include/hw/virtio/vhost-user-device.h @@ -22,6 +22,7 @@ struct VHostUserBase { CharBackend chardev; uint16_t virtio_id; uint32_t num_vqs; + uint32_t config_size; /* State tracking */ VhostUserState vhost_user; struct vhost_virtqueue *vhost_vq; diff --git a/hw/virtio/vhost-user-device.c b/hw/virtio/vhost-user-device.c index b0239fa033..2b028cae08 100644 --- a/hw/virtio/vhost-user-device.c +++ b/hw/virtio/vhost-user-device.c @@ -117,6 +117,42 @@ static uint64_t vub_get_features(VirtIODevice *vdev, return vub->vhost_dev.features & ~(1ULL << VHOST_USER_F_PROTOCOL_FEATURES); } +/* + * To handle VirtIO config we need to know the size of the config + * space. We don't cache the config but re-fetch it from the guest + * every time in case something has changed. + */ +static void vub_get_config(VirtIODevice *vdev, uint8_t *config) +{ + VHostUserBase *vub = VHOST_USER_BASE(vdev); + Error *local_err = NULL; + + /* + * There will have been a warning during vhost_dev_init, but lets + * assert here as nothing will go right now. + */ + g_assert(vub->config_size && vub->vhost_user.supports_config == true); + + if (vhost_dev_get_config(&vub->vhost_dev, config, + vub->config_size, &local_err)) { + error_report_err(local_err); + } +} + +/* + * When the daemon signals an update to the config we just need to + * signal the guest as we re-read the config on demand above. + */ +static int vub_config_notifier(struct vhost_dev *dev) +{ + virtio_notify_config(dev->vdev); + return 0; +} + +const VhostDevConfigOps vub_config_ops = { + .vhost_dev_config_notifier = vub_config_notifier, +}; + static void vub_handle_output(VirtIODevice *vdev, VirtQueue *vq) { /* @@ -141,12 +177,21 @@ static int vub_connect(DeviceState *dev) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); VHostUserBase *vub = VHOST_USER_BASE(vdev); + struct vhost_dev *vhost_dev = &vub->vhost_dev; if (vub->connected) { return 0; } vub->connected = true; + /* + * If we support VHOST_USER_GET_CONFIG we must enable the notifier + * so we can ping the guest when it updates. + */ + if (vub->vhost_user.supports_config) { + vhost_dev_set_config_notifier(vhost_dev, &vub_config_ops); + } + /* restore vhost state */ if (virtio_device_started(vdev, vdev->status)) { vub_start(vdev); @@ -214,11 +259,20 @@ static void vub_device_realize(DeviceState *dev, Error **errp) vub->num_vqs = 1; /* reasonable default? */ } + /* + * We can't handle config requests unless we know the size of the + * config region, specialisations of the vhost-user-device will be + * able to set this. + */ + if (vub->config_size) { + vub->vhost_user.supports_config = true; + } + if (!vhost_user_init(&vub->vhost_user, &vub->chardev, errp)) { return; } - virtio_init(vdev, vub->virtio_id, 0); + virtio_init(vdev, vub->virtio_id, vub->config_size); /* * Disable guest notifiers, by default all notifications will be via the @@ -268,6 +322,7 @@ static void vub_class_init(ObjectClass *klass, void *data) vdc->realize = vub_device_realize; vdc->unrealize = vub_device_unrealize; vdc->get_features = vub_get_features; + vdc->get_config = vub_get_config; vdc->set_status = vub_set_status; } @@ -295,6 +350,7 @@ static Property vud_properties[] = { DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), DEFINE_PROP_UINT16("virtio-id", VHostUserBase, virtio_id, 0), DEFINE_PROP_UINT32("num_vqs", VHostUserBase, num_vqs, 1), + DEFINE_PROP_UINT32("config_size", VHostUserBase, config_size, 0), DEFINE_PROP_END_OF_LIST(), }; From patchwork Mon Jul 10 15:35:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701022 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5243128wrs; Mon, 10 Jul 2023 08:36:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlECHcGaZZX5xo7mDFGWU7c7Nlyc7GSHf0sCke2KaoeJRMtbgI4wB7gzFw//ynyKKa16FHiI X-Received: by 2002:a37:f60c:0:b0:767:1db2:c32f with SMTP id y12-20020a37f60c000000b007671db2c32fmr11712091qkj.33.1689003402714; Mon, 10 Jul 2023 08:36:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003402; cv=none; d=google.com; s=arc-20160816; b=NcHM0GO4V/fRYxxFsgbz6cYUd3ar+etBx0dcwPvmobITb5Jfigp9M8WOCXBHQpENvh P85b5QiGUW3A21eVg9VMZ1oTYP8T9lE82iQ0ZY3vPVRDxwmEBDXE/MSsxlHzL4v6+D5Y XrXLjFI6K8dot8NYuzSJpZci6DPuJxBCVxOY0lnKCgtUbdH7YvzCYidLyURimVvFMyJ4 ODo3aFNVPGZhMQgjK0pvkFOWm080NWFs1xw1/mi/Zr5jRkDWP1ogQpZ8GvZ0fyLxszac pU+Nf9M8v1V4xH+wh/X4JIS3RCcK9wgF8BPUE5SIoS6ynKw5lfbUIKGB6JYwgg7obBC9 uNMw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ziduahlWFntmX4fsnibN0OPtf6Q844vE4n15aXZaaSA=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=wP+XC1CzNFQ94E0Lgyjor2a6TVOtdw4mXn2+7cB+ZxU/6d+E6q5f/M7ckjkFfsWLtb yDO0IveerRkeliQhI7UtHrT78NQSbxWpzWncB0ED4FeImVpFcGjGn9xx/u9jgeZqPZ5O bpUMsrQAjGzZNwNJN02kh4oqX12Atjlv9V80cVfbCP6SpHbgrJKLBdHmqyrVcDCAt6a4 nEPslTRIkKenb8LXHJtvo+dFEwU9QNIwt3n3CrLFptK13DvWjTUtdzdtmaldV8kqTz5C Ndod2Avrg2OQQJHN/k7mTggx0LVQbQkpyV7/LL8BV1oKjCk4yr/wSwlJOJn7Zb75TGhA h8uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QfgjvVwJ; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b1-20020ac85bc1000000b003e39654640bsi15069qtb.446.2023.07.10.08.36.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:36:42 -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=@linaro.org header.s=google header.b=QfgjvVwJ; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIsvd-0005to-1l; Mon, 10 Jul 2023 11:35:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIsvR-0005mK-Lf for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:49 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIsvG-0004mJ-63 for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:45 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3fbc5d5742eso51879805e9.3 for ; Mon, 10 Jul 2023 08:35:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003332; x=1691595332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ziduahlWFntmX4fsnibN0OPtf6Q844vE4n15aXZaaSA=; b=QfgjvVwJ55Og2EMgHR3FsoO7zYgZw5aIIFQCGnjBDkUuP37sBFKXiP1TTJxVm8bb3b nk2lg6k1Q0cFupMYBLmrNgfcuk6THlpUSxnZGyCzVhlzxcQWxleVLlLEgV6FjvRorGQs AM3n6dagtj2ZOkBqkQAI6+fCoXw1J17fZgnbUpP0V9ywZCPfDbaOKlfdoYZgXc2SeCqM l1vrgmJfTsdNfO81v8wUzXAmsM42bBEl/gi9YkRQzOoYuQARBN7tcykDKGkrLOFyyp7U FJODCTfETa/9fiXuBZPDhaBuXlOfC1NyYur9G2zr8yidQSdjqYemyMK8C/QMSyNMzv59 rw1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003332; x=1691595332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ziduahlWFntmX4fsnibN0OPtf6Q844vE4n15aXZaaSA=; b=PFst4tx2yBDDxBwjGJX3A3Iiz1wxM+O8Il1hy8BiSbABTzNaMjCuN4tSS4sQAWonnW quNd3nfBmaMLYA72lJE3oFSb+qWVA6olzHxxD+ijLYXM5jcWqxFyy4jPn290dvo3eaQi GBSrm1cH9iLzHj0ae2QCdivzHcjfW/lAuK2jZtMsmWmMf8l8Cfaa7RTU4f4UdyaG7kgb C0pnp/U+EbqFFQryWdoVCQf1TSAIqC6+MfW5xljNN3QaqsYXuaMBLrMl51vfxOslac9/ ZBACtVOMhT6/zLHOF4mhJbo7/cs0x/roaMjmMjFFHpM8GMStrl0KAg6jwGm6mbfPBWy4 DIxw== X-Gm-Message-State: ABy/qLYZvDo4Hfyaq+/ssEHr9iOUFi+udAoabf+kh3aY4yYx1oLLnDgl yh6u+Cgg8dcdkjaDigGS4oij/w== X-Received: by 2002:a7b:cc84:0:b0:3fc:a5:2c3a with SMTP id p4-20020a7bcc84000000b003fc00a52c3amr8699893wma.41.1689003332567; Mon, 10 Jul 2023 08:35:32 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id x24-20020a1c7c18000000b003fc00892c13sm153989wmc.35.2023.07.10.08.35.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:35:30 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 784DD1FFC6; Mon, 10 Jul 2023 16:35:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [PATCH v3 11/20] hw/virtio: derive vhost-user-gpio from vhost-user-device Date: Mon, 10 Jul 2023 16:35:13 +0100 Message-Id: <20230710153522.3469097-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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-bounces+patch=linaro.org@nongnu.org Now the new base class supports config handling we can take advantage and make vhost-user-gpio a much simpler boilerplate wrapper. Also as this doesn't require any target specific hacks we only need to build the stubs once. Signed-off-by: Alex Bennée --- v2 - use new vhost-user-base - move build to common code v3 - fix inadvertent double link --- include/hw/virtio/vhost-user-gpio.h | 23 +- hw/virtio/vhost-user-gpio.c | 400 ++-------------------------- hw/virtio/meson.build | 5 +- 3 files changed, 22 insertions(+), 406 deletions(-) diff --git a/include/hw/virtio/vhost-user-gpio.h b/include/hw/virtio/vhost-user-gpio.h index a9d3f9b049..0948654dec 100644 --- a/include/hw/virtio/vhost-user-gpio.h +++ b/include/hw/virtio/vhost-user-gpio.h @@ -12,33 +12,14 @@ #include "hw/virtio/virtio.h" #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-user.h" -#include "standard-headers/linux/virtio_gpio.h" -#include "chardev/char-fe.h" +#include "hw/virtio/vhost-user-device.h" #define TYPE_VHOST_USER_GPIO "vhost-user-gpio-device" OBJECT_DECLARE_SIMPLE_TYPE(VHostUserGPIO, VHOST_USER_GPIO); struct VHostUserGPIO { /*< private >*/ - VirtIODevice parent_obj; - CharBackend chardev; - struct virtio_gpio_config config; - struct vhost_virtqueue *vhost_vqs; - struct vhost_dev vhost_dev; - VhostUserState vhost_user; - VirtQueue *command_vq; - VirtQueue *interrupt_vq; - /** - * There are at least two steps of initialization of the - * vhost-user device. The first is a "connect" step and - * second is a "start" step. Make a separation between - * those initialization phases by using two fields. - * - * @connected: see vu_gpio_connect()/vu_gpio_disconnect() - * @started_vu: see vu_gpio_start()/vu_gpio_stop() - */ - bool connected; - bool started_vu; + VHostUserBase parent; /*< public >*/ }; diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index 3b013f2d0f..9f37c25415 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -11,382 +11,25 @@ #include "hw/qdev-properties.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/vhost-user-gpio.h" -#include "qemu/error-report.h" #include "standard-headers/linux/virtio_ids.h" -#include "trace.h" +#include "standard-headers/linux/virtio_gpio.h" -#define REALIZE_CONNECTION_RETRIES 3 -#define VHOST_NVQS 2 - -/* Features required from VirtIO */ -static const int feature_bits[] = { - VIRTIO_F_VERSION_1, - VIRTIO_F_NOTIFY_ON_EMPTY, - VIRTIO_RING_F_INDIRECT_DESC, - VIRTIO_RING_F_EVENT_IDX, - VIRTIO_GPIO_F_IRQ, - VIRTIO_F_RING_RESET, - VHOST_INVALID_FEATURE_BIT -}; - -static void vu_gpio_get_config(VirtIODevice *vdev, uint8_t *config) -{ - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - - memcpy(config, &gpio->config, sizeof(gpio->config)); -} - -static int vu_gpio_config_notifier(struct vhost_dev *dev) -{ - VHostUserGPIO *gpio = VHOST_USER_GPIO(dev->vdev); - - memcpy(dev->vdev->config, &gpio->config, sizeof(gpio->config)); - virtio_notify_config(dev->vdev); - - return 0; -} - -const VhostDevConfigOps gpio_ops = { - .vhost_dev_config_notifier = vu_gpio_config_notifier, +static Property vgpio_properties[] = { + DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), + DEFINE_PROP_END_OF_LIST(), }; -static int vu_gpio_start(VirtIODevice *vdev) +static void vgpio_realize(DeviceState *dev, Error **errp) { - BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - struct vhost_dev *vhost_dev = &gpio->vhost_dev; - int ret, i; + VHostUserBase *vub = VHOST_USER_BASE(dev); + VHostUserBaseClass *vubc = VHOST_USER_BASE_GET_CLASS(dev); - if (!k->set_guest_notifiers) { - error_report("binding does not support guest notifiers"); - return -ENOSYS; - } + /* Fixed for GPIO */ + vub->virtio_id = VIRTIO_ID_GPIO; + vub->num_vqs = 2; + vub->config_size = sizeof(struct virtio_gpio_config); - ret = vhost_dev_enable_notifiers(vhost_dev, vdev); - if (ret < 0) { - error_report("Error enabling host notifiers: %d", ret); - return ret; - } - - ret = k->set_guest_notifiers(qbus->parent, vhost_dev->nvqs, true); - if (ret < 0) { - error_report("Error binding guest notifier: %d", ret); - goto err_host_notifiers; - } - - /* - * Before we start up we need to ensure we have the final feature - * set needed for the vhost configuration. The backend may also - * apply backend_features when the feature set is sent. - */ - vhost_ack_features(&gpio->vhost_dev, feature_bits, vdev->guest_features); - - ret = vhost_dev_start(&gpio->vhost_dev, vdev, false); - if (ret < 0) { - error_report("Error starting vhost-user-gpio: %d", ret); - goto err_guest_notifiers; - } - gpio->started_vu = true; - - /* - * guest_notifier_mask/pending not used yet, so just unmask - * everything here. virtio-pci will do the right thing by - * enabling/disabling irqfd. - */ - for (i = 0; i < gpio->vhost_dev.nvqs; i++) { - vhost_virtqueue_mask(&gpio->vhost_dev, vdev, i, false); - } - - /* - * As we must have VHOST_USER_F_PROTOCOL_FEATURES (because - * VHOST_USER_GET_CONFIG requires it) we need to explicitly enable - * the vrings. - */ - g_assert(vhost_dev->vhost_ops && - vhost_dev->vhost_ops->vhost_set_vring_enable); - ret = vhost_dev->vhost_ops->vhost_set_vring_enable(vhost_dev, true); - if (ret == 0) { - return 0; - } - - error_report("Failed to start vrings for vhost-user-gpio: %d", ret); - -err_guest_notifiers: - k->set_guest_notifiers(qbus->parent, gpio->vhost_dev.nvqs, false); -err_host_notifiers: - vhost_dev_disable_notifiers(&gpio->vhost_dev, vdev); - - return ret; -} - -static void vu_gpio_stop(VirtIODevice *vdev) -{ - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); - struct vhost_dev *vhost_dev = &gpio->vhost_dev; - int ret; - - if (!gpio->started_vu) { - return; - } - gpio->started_vu = false; - - if (!k->set_guest_notifiers) { - return; - } - - vhost_dev_stop(vhost_dev, vdev, false); - - ret = k->set_guest_notifiers(qbus->parent, vhost_dev->nvqs, false); - if (ret < 0) { - error_report("vhost guest notifier cleanup failed: %d", ret); - return; - } - - vhost_dev_disable_notifiers(vhost_dev, vdev); -} - -static void vu_gpio_set_status(VirtIODevice *vdev, uint8_t status) -{ - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - bool should_start = virtio_device_should_start(vdev, status); - - trace_virtio_gpio_set_status(status); - - if (!gpio->connected) { - return; - } - - if (vhost_dev_is_started(&gpio->vhost_dev) == should_start) { - return; - } - - if (should_start) { - if (vu_gpio_start(vdev)) { - qemu_chr_fe_disconnect(&gpio->chardev); - } - } else { - vu_gpio_stop(vdev); - } -} - -static uint64_t vu_gpio_get_features(VirtIODevice *vdev, uint64_t features, - Error **errp) -{ - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - - return vhost_get_features(&gpio->vhost_dev, feature_bits, features); -} - -static void vu_gpio_handle_output(VirtIODevice *vdev, VirtQueue *vq) -{ - /* - * Not normally called; it's the daemon that handles the queue; - * however virtio's cleanup path can call this. - */ -} - -static void vu_gpio_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask) -{ - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - - /* - * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1 - * as the macro of configure interrupt's IDX, If this driver does not - * support, the function will return - */ - - if (idx == VIRTIO_CONFIG_IRQ_IDX) { - return; - } - - vhost_virtqueue_mask(&gpio->vhost_dev, vdev, idx, mask); -} - -static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserGPIO *gpio) -{ - virtio_delete_queue(gpio->command_vq); - virtio_delete_queue(gpio->interrupt_vq); - g_free(gpio->vhost_vqs); - virtio_cleanup(vdev); - vhost_user_cleanup(&gpio->vhost_user); -} - -static int vu_gpio_connect(DeviceState *dev, Error **errp) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - struct vhost_dev *vhost_dev = &gpio->vhost_dev; - int ret; - - if (gpio->connected) { - return 0; - } - gpio->connected = true; - - vhost_dev_set_config_notifier(vhost_dev, &gpio_ops); - gpio->vhost_user.supports_config = true; - - gpio->vhost_dev.nvqs = VHOST_NVQS; - gpio->vhost_dev.vqs = gpio->vhost_vqs; - - ret = vhost_dev_init(vhost_dev, &gpio->vhost_user, - VHOST_BACKEND_TYPE_USER, 0, errp); - if (ret < 0) { - return ret; - } - - /* restore vhost state */ - if (virtio_device_started(vdev, vdev->status)) { - vu_gpio_start(vdev); - } - - return 0; -} - -static void vu_gpio_event(void *opaque, QEMUChrEvent event); - -static void vu_gpio_disconnect(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - - if (!gpio->connected) { - return; - } - gpio->connected = false; - - vu_gpio_stop(vdev); - vhost_dev_cleanup(&gpio->vhost_dev); - - /* Re-instate the event handler for new connections */ - qemu_chr_fe_set_handlers(&gpio->chardev, - NULL, NULL, vu_gpio_event, - NULL, dev, NULL, true); -} - -static void vu_gpio_event(void *opaque, QEMUChrEvent event) -{ - DeviceState *dev = opaque; - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - Error *local_err = NULL; - - switch (event) { - case CHR_EVENT_OPENED: - if (vu_gpio_connect(dev, &local_err) < 0) { - qemu_chr_fe_disconnect(&gpio->chardev); - return; - } - break; - case CHR_EVENT_CLOSED: - /* defer close until later to avoid circular close */ - vhost_user_async_close(dev, &gpio->chardev, &gpio->vhost_dev, - vu_gpio_disconnect); - break; - case CHR_EVENT_BREAK: - case CHR_EVENT_MUX_IN: - case CHR_EVENT_MUX_OUT: - /* Ignore */ - break; - } -} - -static int vu_gpio_realize_connect(VHostUserGPIO *gpio, Error **errp) -{ - VirtIODevice *vdev = &gpio->parent_obj; - DeviceState *dev = &vdev->parent_obj; - struct vhost_dev *vhost_dev = &gpio->vhost_dev; - int ret; - - ret = qemu_chr_fe_wait_connected(&gpio->chardev, errp); - if (ret < 0) { - return ret; - } - - /* - * vu_gpio_connect() may have already connected (via the event - * callback) in which case it will just report success. - */ - ret = vu_gpio_connect(dev, errp); - if (ret < 0) { - qemu_chr_fe_disconnect(&gpio->chardev); - return ret; - } - g_assert(gpio->connected); - - ret = vhost_dev_get_config(vhost_dev, (uint8_t *)&gpio->config, - sizeof(gpio->config), errp); - - if (ret < 0) { - error_report("vhost-user-gpio: get config failed"); - - qemu_chr_fe_disconnect(&gpio->chardev); - vhost_dev_cleanup(vhost_dev); - return ret; - } - - return 0; -} - -static void vu_gpio_device_realize(DeviceState *dev, Error **errp) -{ - ERRP_GUARD(); - - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserGPIO *gpio = VHOST_USER_GPIO(dev); - int retries, ret; - - if (!gpio->chardev.chr) { - error_setg(errp, "vhost-user-gpio: chardev is mandatory"); - return; - } - - if (!vhost_user_init(&gpio->vhost_user, &gpio->chardev, errp)) { - return; - } - - virtio_init(vdev, VIRTIO_ID_GPIO, sizeof(gpio->config)); - - gpio->command_vq = virtio_add_queue(vdev, 256, vu_gpio_handle_output); - gpio->interrupt_vq = virtio_add_queue(vdev, 256, vu_gpio_handle_output); - gpio->vhost_vqs = g_new0(struct vhost_virtqueue, VHOST_NVQS); - - gpio->connected = false; - - qemu_chr_fe_set_handlers(&gpio->chardev, NULL, NULL, vu_gpio_event, NULL, - dev, NULL, true); - - retries = REALIZE_CONNECTION_RETRIES; - g_assert(!*errp); - do { - if (*errp) { - error_prepend(errp, "Reconnecting after error: "); - error_report_err(*errp); - *errp = NULL; - } - ret = vu_gpio_realize_connect(gpio, errp); - } while (ret < 0 && retries--); - - if (ret < 0) { - do_vhost_user_cleanup(vdev, gpio); - } - - return; -} - -static void vu_gpio_device_unrealize(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserGPIO *gpio = VHOST_USER_GPIO(dev); - - vu_gpio_set_status(vdev, 0); - qemu_chr_fe_set_handlers(&gpio->chardev, NULL, NULL, NULL, NULL, NULL, NULL, - false); - vhost_dev_cleanup(&gpio->vhost_dev); - do_vhost_user_cleanup(vdev, gpio); + vubc->parent_realize(dev, errp); } static const VMStateDescription vu_gpio_vmstate = { @@ -394,30 +37,21 @@ static const VMStateDescription vu_gpio_vmstate = { .unmigratable = 1, }; -static Property vu_gpio_properties[] = { - DEFINE_PROP_CHR("chardev", VHostUserGPIO, chardev), - DEFINE_PROP_END_OF_LIST(), -}; - static void vu_gpio_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass); - device_class_set_props(dc, vu_gpio_properties); dc->vmsd = &vu_gpio_vmstate; + device_class_set_props(dc, vgpio_properties); + device_class_set_parent_realize(dc, vgpio_realize, + &vubc->parent_realize); set_bit(DEVICE_CATEGORY_INPUT, dc->categories); - vdc->realize = vu_gpio_device_realize; - vdc->unrealize = vu_gpio_device_unrealize; - vdc->get_features = vu_gpio_get_features; - vdc->get_config = vu_gpio_get_config; - vdc->set_status = vu_gpio_set_status; - vdc->guest_notifier_mask = vu_gpio_guest_notifier_mask; } static const TypeInfo vu_gpio_info = { .name = TYPE_VHOST_USER_GPIO, - .parent = TYPE_VIRTIO_DEVICE, + .parent = TYPE_VHOST_USER_BASE, .instance_size = sizeof(VHostUserGPIO), .class_init = vu_gpio_class_init, }; diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index fb80587d5b..62ab2d82e0 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -11,6 +11,9 @@ softmmu_virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev.c' softmmu_virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c')) softmmu_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_RNG'], if_true: files('vhost-user-rng-pci.c')) +softmmu_virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vhost-user-gpio.c')) +softmmu_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_GPIO'], + if_true: files('vhost-user-gpio-pci.c')) specific_virtio_ss = ss.source_set() specific_virtio_ss.add(files('virtio.c')) @@ -40,8 +43,6 @@ specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-us specific_virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng.c')) specific_virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c')) -specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vhost-user-gpio.c')) -specific_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_GPIO'], if_true: files('vhost-user-gpio-pci.c')) virtio_pci_ss = ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c')) From patchwork Mon Jul 10 15:35:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701037 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5246417wrs; Mon, 10 Jul 2023 08:44:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlF+EF+1meyJupmdgQ8osOWgNDbCTqFn5PVq8kc9LdafYoHYN+0Ez4lhoj/ruAhTjCLWBlRb X-Received: by 2002:a0c:ca06:0:b0:630:1bc8:9c7 with SMTP id c6-20020a0cca06000000b006301bc809c7mr10385307qvk.2.1689003860431; Mon, 10 Jul 2023 08:44:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003860; cv=none; d=google.com; s=arc-20160816; b=QzJ4f0IP1JyMeG3cvgDsPcZe2zn2PsizcrJurZf73YSNGf7ZptVNjSSrqQmi2pAo2w cu5EzWjO4dC0XBZxaLT5yFGAUMbFalclUayEfzqxfdykDU0vqHS33EES33V7oWVqVGAR JSuPxjo5qixwu0e9NebRYrCj+G+tQGrWj2BLg1dqRYqCmfzvrWEd26X5dGL/DyLFe6fR 61yXmIfYB3UHERszBSzC5j/MqRwR/Bkagx8vLei6LyC7GvOKejL4VWMX5ajyAngnfOu/ xoJlEQ/vkJCDIV/nKS6+mE5F0JvrzoLLiQmoAnaEBOr45WhS+OrTIOUq8/gWu9jE/YUR PY8w== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BNSYY0aQSTUHXzFTnzMxA99hIZ3LEiMZlUH/7FQpKls=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=P5cLstECtW6Z45ItQN/pU6ze30EQuzbj2bJ0OoaDAT6Xz0v1WWV5DvdeSQ9gocRlLh yxN7Zh9MWC/uZvdRnteEzZpQ+vG8z/RmJjhtorXNdyC4jgv7PfDCSfdyGIE1Zzk7v9EY lU2KR/l4CuE5vvm85j4yAiLBiefFB0T6KJWJD9/7pGcC7va7iPFzSiQ6sUQE944Xk1oK OXhm63zQfu6LfeWNSwWU8ZkDfnI/LSaPk0eyJGr4+4eZNoakRlUqqCFqgnqjYQV3gwvq WQdeNe4/pzyO6suSp/l+b5iUucojPMVJ2MsOt5DoU/td6amdTFFI03bkUVA0V+TXDP/u cS4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YH15xvho; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z20-20020a0cda94000000b005eda1d1d9aasi5607431qvj.598.2023.07.10.08.44.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:44:20 -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=@linaro.org header.s=google header.b=YH15xvho; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIt39-0002bB-UT; Mon, 10 Jul 2023 11:43:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIt31-0002ZS-MZ for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:43:36 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIt2p-0006Lt-HS for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:43:35 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fbc244d307so54230945e9.1 for ; Mon, 10 Jul 2023 08:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003802; x=1691595802; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BNSYY0aQSTUHXzFTnzMxA99hIZ3LEiMZlUH/7FQpKls=; b=YH15xvhobY8NKTSC57QZAz6v9BkK2sney38Tz5C1DwmvpAH9ZuHGtEZHtG0sdzIOnz ChjGwrmQskZnDfU4iAE7CmtmW/aCdNc3/yFW+NMcPENbRVxwIRs2oxszMXenA6Koa7q8 ONCPss2T5r0ROt9ewnCsbNXpOxHnQeEzaWxXIl70mvvhxet0GJHWwOYyiAXJ5eE+4wk+ euB8K/msMSgqhWm4SBcPlyqdfl+VSQYsBw2+C0lLPsqj63Na8vZ9HAOm9iu+oVIBXW/t ZWhBvhNdq0FDfmnVYy2dPuyobWtRgj5ovMndveTNrvTNAhn+t60IsHYk2I1RG8kOJOYa 60Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003802; x=1691595802; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BNSYY0aQSTUHXzFTnzMxA99hIZ3LEiMZlUH/7FQpKls=; b=bpQ3T75DNCOqoy3EbIsT7ISaYK8o0GOKRyyU3VVsskIL/UNoZF+J0p4lmjcjnyoxKD rzu0NhY92njmidwMrKt92V+H16iKKYNTLx25dKFx+29bE2xPkfB6EJ7NI4sPjPT1cNTT kbB63P9pPZ9jzXOTvXxIIcgg31YaLqyBu3jiYdtLjSb9bOlSNTAyqFGfOybIof3fy6BC soB2ZuX38TrviTDFhLZWAcJfOOEUNTdKyAsnjhPiWuYmJFLXZu3hVb/x6USqLY+4kcba XbrMK+9tSMcxDOV4hsN0LVPbflsYM2QWZsBYoyf3GBlZfJrc03FvjtRnEyng2rqf940s fN3Q== X-Gm-Message-State: ABy/qLbzs/4Ac4DN4KGKiIwwrpeOxl3n881P0UKowQP1AQOCggLHNlwQ +gPxld/SZmKzKQot7g0mQAgDPQ== X-Received: by 2002:a05:6000:370:b0:313:f9a0:c530 with SMTP id f16-20020a056000037000b00313f9a0c530mr14344815wrf.52.1689003801867; Mon, 10 Jul 2023 08:43:21 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id g7-20020adff3c7000000b00313e59cb371sm12014708wrp.12.2023.07.10.08.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:43:21 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 97F141FFC7; Mon, 10 Jul 2023 16:35:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [PATCH v3 12/20] hw/virtio: derive vhost-user-i2c from vhost-user-base Date: Mon, 10 Jul 2023 16:35:14 +0100 Message-Id: <20230710153522.3469097-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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-bounces+patch=linaro.org@nongnu.org Now we can take advantage of the new base class and make vhost-user-i2c a much simpler boilerplate wrapper. Also as this doesn't require any target specific hacks we only need to build the stubs once. Signed-off-by: Alex Bennée --- v2 - update to new inheritance scheme - move build to common code v3 - fix merge conflict in meson --- include/hw/virtio/vhost-user-i2c.h | 18 +- hw/virtio/vhost-user-i2c.c | 271 ++--------------------------- hw/virtio/meson.build | 5 +- 3 files changed, 26 insertions(+), 268 deletions(-) diff --git a/include/hw/virtio/vhost-user-i2c.h b/include/hw/virtio/vhost-user-i2c.h index 0f7acd40e3..47153782d1 100644 --- a/include/hw/virtio/vhost-user-i2c.h +++ b/include/hw/virtio/vhost-user-i2c.h @@ -12,20 +12,18 @@ #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-user.h" +#include "hw/virtio/virtio.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" +#include "hw/virtio/vhost-user-device.h" + #define TYPE_VHOST_USER_I2C "vhost-user-i2c-device" OBJECT_DECLARE_SIMPLE_TYPE(VHostUserI2C, VHOST_USER_I2C) struct VHostUserI2C { - VirtIODevice parent; - CharBackend chardev; - struct vhost_virtqueue *vhost_vq; - struct vhost_dev vhost_dev; - VhostUserState vhost_user; - VirtQueue *vq; - bool connected; + /*< private >*/ + VHostUserBase parent; + /*< public >*/ }; -/* Virtio Feature bits */ -#define VIRTIO_I2C_F_ZERO_LENGTH_REQUEST 0 - #endif /* QEMU_VHOST_USER_I2C_H */ diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c index 4eef3f0633..4a1f644a87 100644 --- a/hw/virtio/vhost-user-i2c.c +++ b/hw/virtio/vhost-user-i2c.c @@ -14,253 +14,21 @@ #include "qemu/error-report.h" #include "standard-headers/linux/virtio_ids.h" -static const int feature_bits[] = { - VIRTIO_I2C_F_ZERO_LENGTH_REQUEST, - VIRTIO_F_RING_RESET, - VHOST_INVALID_FEATURE_BIT +static Property vi2c_properties[] = { + DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), + DEFINE_PROP_END_OF_LIST(), }; -static void vu_i2c_start(VirtIODevice *vdev) -{ - BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - int ret, i; - - if (!k->set_guest_notifiers) { - error_report("binding does not support guest notifiers"); - return; - } - - ret = vhost_dev_enable_notifiers(&i2c->vhost_dev, vdev); - if (ret < 0) { - error_report("Error enabling host notifiers: %d", -ret); - return; - } - - ret = k->set_guest_notifiers(qbus->parent, i2c->vhost_dev.nvqs, true); - if (ret < 0) { - error_report("Error binding guest notifier: %d", -ret); - goto err_host_notifiers; - } - - i2c->vhost_dev.acked_features = vdev->guest_features; - - ret = vhost_dev_start(&i2c->vhost_dev, vdev, true); - if (ret < 0) { - error_report("Error starting vhost-user-i2c: %d", -ret); - goto err_guest_notifiers; - } - - /* - * guest_notifier_mask/pending not used yet, so just unmask - * everything here. virtio-pci will do the right thing by - * enabling/disabling irqfd. - */ - for (i = 0; i < i2c->vhost_dev.nvqs; i++) { - vhost_virtqueue_mask(&i2c->vhost_dev, vdev, i, false); - } - - return; - -err_guest_notifiers: - k->set_guest_notifiers(qbus->parent, i2c->vhost_dev.nvqs, false); -err_host_notifiers: - vhost_dev_disable_notifiers(&i2c->vhost_dev, vdev); -} - -static void vu_i2c_stop(VirtIODevice *vdev) -{ - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); - int ret; - - if (!k->set_guest_notifiers) { - return; - } - - vhost_dev_stop(&i2c->vhost_dev, vdev, true); - - ret = k->set_guest_notifiers(qbus->parent, i2c->vhost_dev.nvqs, false); - if (ret < 0) { - error_report("vhost guest notifier cleanup failed: %d", ret); - return; - } - - vhost_dev_disable_notifiers(&i2c->vhost_dev, vdev); -} - -static void vu_i2c_set_status(VirtIODevice *vdev, uint8_t status) -{ - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - bool should_start = virtio_device_should_start(vdev, status); - - if (vhost_dev_is_started(&i2c->vhost_dev) == should_start) { - return; - } - - if (should_start) { - vu_i2c_start(vdev); - } else { - vu_i2c_stop(vdev); - } -} - -static uint64_t vu_i2c_get_features(VirtIODevice *vdev, - uint64_t requested_features, Error **errp) -{ - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - - virtio_add_feature(&requested_features, VIRTIO_I2C_F_ZERO_LENGTH_REQUEST); - return vhost_get_features(&i2c->vhost_dev, feature_bits, requested_features); -} - -static void vu_i2c_handle_output(VirtIODevice *vdev, VirtQueue *vq) -{ - /* - * Not normally called; it's the daemon that handles the queue; - * however virtio's cleanup path can call this. - */ -} - -static void vu_i2c_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask) -{ - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - - /* - * We don't support interrupts, return early if index is set to - * VIRTIO_CONFIG_IRQ_IDX. - */ - if (idx == VIRTIO_CONFIG_IRQ_IDX) { - return; - } - - vhost_virtqueue_mask(&i2c->vhost_dev, vdev, idx, mask); -} - -static bool vu_i2c_guest_notifier_pending(VirtIODevice *vdev, int idx) -{ - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - - /* - * We don't support interrupts, return early if index is set to - * VIRTIO_CONFIG_IRQ_IDX. - */ - if (idx == VIRTIO_CONFIG_IRQ_IDX) { - return false; - } - - return vhost_virtqueue_pending(&i2c->vhost_dev, idx); -} - -static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserI2C *i2c) -{ - vhost_user_cleanup(&i2c->vhost_user); - virtio_delete_queue(i2c->vq); - virtio_cleanup(vdev); -} - -static int vu_i2c_connect(DeviceState *dev) +static void vi2c_realize(DeviceState *dev, Error **errp) { - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); + VHostUserBase *vub = VHOST_USER_BASE(dev); + VHostUserBaseClass *vubc = VHOST_USER_BASE_GET_CLASS(dev); - if (i2c->connected) { - return 0; - } - i2c->connected = true; + /* Fixed for I2C */ + vub->virtio_id = VIRTIO_ID_I2C_ADAPTER; + vub->num_vqs = 1; - /* restore vhost state */ - if (virtio_device_started(vdev, vdev->status)) { - vu_i2c_start(vdev); - } - - return 0; -} - -static void vu_i2c_disconnect(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - - if (!i2c->connected) { - return; - } - i2c->connected = false; - - if (vhost_dev_is_started(&i2c->vhost_dev)) { - vu_i2c_stop(vdev); - } -} - -static void vu_i2c_event(void *opaque, QEMUChrEvent event) -{ - DeviceState *dev = opaque; - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - - switch (event) { - case CHR_EVENT_OPENED: - if (vu_i2c_connect(dev) < 0) { - qemu_chr_fe_disconnect(&i2c->chardev); - return; - } - break; - case CHR_EVENT_CLOSED: - vu_i2c_disconnect(dev); - break; - case CHR_EVENT_BREAK: - case CHR_EVENT_MUX_IN: - case CHR_EVENT_MUX_OUT: - /* Ignore */ - break; - } -} - -static void vu_i2c_device_realize(DeviceState *dev, Error **errp) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserI2C *i2c = VHOST_USER_I2C(dev); - int ret; - - if (!i2c->chardev.chr) { - error_setg(errp, "vhost-user-i2c: missing chardev"); - return; - } - - if (!vhost_user_init(&i2c->vhost_user, &i2c->chardev, errp)) { - return; - } - - virtio_init(vdev, VIRTIO_ID_I2C_ADAPTER, 0); - - i2c->vhost_dev.nvqs = 1; - i2c->vq = virtio_add_queue(vdev, 4, vu_i2c_handle_output); - i2c->vhost_dev.vqs = g_new0(struct vhost_virtqueue, i2c->vhost_dev.nvqs); - - ret = vhost_dev_init(&i2c->vhost_dev, &i2c->vhost_user, - VHOST_BACKEND_TYPE_USER, 0, errp); - if (ret < 0) { - g_free(i2c->vhost_dev.vqs); - do_vhost_user_cleanup(vdev, i2c); - } - - qemu_chr_fe_set_handlers(&i2c->chardev, NULL, NULL, vu_i2c_event, NULL, - dev, NULL, true); -} - -static void vu_i2c_device_unrealize(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserI2C *i2c = VHOST_USER_I2C(dev); - struct vhost_virtqueue *vhost_vqs = i2c->vhost_dev.vqs; - - /* This will stop vhost backend if appropriate. */ - vu_i2c_set_status(vdev, 0); - vhost_dev_cleanup(&i2c->vhost_dev); - g_free(vhost_vqs); - do_vhost_user_cleanup(vdev, i2c); + vubc->parent_realize(dev, errp); } static const VMStateDescription vu_i2c_vmstate = { @@ -268,30 +36,21 @@ static const VMStateDescription vu_i2c_vmstate = { .unmigratable = 1, }; -static Property vu_i2c_properties[] = { - DEFINE_PROP_CHR("chardev", VHostUserI2C, chardev), - DEFINE_PROP_END_OF_LIST(), -}; - static void vu_i2c_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass); - device_class_set_props(dc, vu_i2c_properties); dc->vmsd = &vu_i2c_vmstate; + device_class_set_props(dc, vi2c_properties); + device_class_set_parent_realize(dc, vi2c_realize, + &vubc->parent_realize); set_bit(DEVICE_CATEGORY_INPUT, dc->categories); - vdc->realize = vu_i2c_device_realize; - vdc->unrealize = vu_i2c_device_unrealize; - vdc->get_features = vu_i2c_get_features; - vdc->set_status = vu_i2c_set_status; - vdc->guest_notifier_mask = vu_i2c_guest_notifier_mask; - vdc->guest_notifier_pending = vu_i2c_guest_notifier_pending; } static const TypeInfo vu_i2c_info = { .name = TYPE_VHOST_USER_I2C, - .parent = TYPE_VIRTIO_DEVICE, + .parent = TYPE_VHOST_USER_BASE, .instance_size = sizeof(VHostUserI2C), .class_init = vu_i2c_class_init, }; diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 62ab2d82e0..d1d6892068 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -14,6 +14,9 @@ softmmu_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_RNG'], softmmu_virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vhost-user-gpio.c')) softmmu_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_GPIO'], if_true: files('vhost-user-gpio-pci.c')) +softmmu_virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c')) +softmmu_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_I2C'], + if_true: files('vhost-user-i2c-pci.c')) specific_virtio_ss = ss.source_set() specific_virtio_ss.add(files('virtio.c')) @@ -42,13 +45,11 @@ specific_virtio_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock.c specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-user-vsock.c')) specific_virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng.c')) specific_virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) -specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c')) virtio_pci_ss = ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-user-vsock-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-blk-pci.c')) -virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_INPUT', if_true: files('vhost-user-input-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_SCSI', if_true: files('vhost-user-scsi-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('vhost-scsi-pci.c')) From patchwork Mon Jul 10 15:35:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701040 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5246531wrs; Mon, 10 Jul 2023 08:44:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlH32YJkQ7onBw95RX8F9PXUEiU2hxdRBTZZouUHq+oqyW5aYaU3yPUXXNLWpH6OE4rQfGm4 X-Received: by 2002:a67:ead2:0:b0:443:4f72:fd35 with SMTP id s18-20020a67ead2000000b004434f72fd35mr6273963vso.1.1689003875681; Mon, 10 Jul 2023 08:44:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003875; cv=none; d=google.com; s=arc-20160816; b=fe99hMIqlvstiOk9hBg0Tk0Wp2E5z2IL5Oar4/wEs7ZxXdGzIv2q5PqjujtahD5RzS GMnKYss67ZJtueHAWkW07Xt2zdvqbrFKY3cODXxibvb00rZcQjZDSU2vtLfbDjbfaqJ1 OBPrYHke/9ClkzMokK1mYGopI/dT8AnkxzXTsgqMPG5wpQ97weZiui+HyPpSEpoDs4i2 Tkx68nrR3QcOMp9WlJ431mQ/Paro4ThIQMSHiTwcg15u+LrtuYPxlKruPZzBSk8vTwp8 jYL2PDrzRgoDCETywfzRKQB/iTFBf0SkNb2vGfy/TZnXBWehMm2Ued361rk4tcoQNf6+ A9Rw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AJso+7/SyOzlPSfGsjFdKvvog0Z+6+yUR2hdcAwaBfc=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=EclKfq16N5ohEv6OvTkxcDNe1gWo0Jf5yIcV/m072mPBlzAa0DCvBPUXPXAV776opC DjGaE7BDHrwWWwog8PcKPbnzQF9dLbM3JRew8ahsLuZlHxKiHmpRP0HuFbGEVYvelOO5 Djf5r5q/3RfYJQGh1Shw5qwkj6gxom+5bHDjecuwnmCZ1KQWPJFrzCGnYm1aUE4GiCN7 rBwv2DplgDhEOlclv6r4zWYbZXeR/X+sJf9fwY9R5CxykXr0bdRNq1W5XHZ5i47wCwYv lA1T/Mv1VdZyzG9ann2fph9S6szvh4tJT6FBKTBukX/0zDorm+r/GFdt4CVVDkOyPy3i UU/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MutJX7em; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x3-20020a0ce243000000b00626291257a6si5569109qvl.305.2023.07.10.08.44.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:44:35 -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=@linaro.org header.s=google header.b=MutJX7em; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIt2v-0002XX-4w; Mon, 10 Jul 2023 11:43:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIt2t-0002WU-Bk for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:43:27 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIt2q-0006Lv-M9 for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:43:27 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-31438512cafso5037494f8f.2 for ; Mon, 10 Jul 2023 08:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003802; x=1691595802; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AJso+7/SyOzlPSfGsjFdKvvog0Z+6+yUR2hdcAwaBfc=; b=MutJX7emGU8QPyPA59RtM1I5kKlSSAidzSGGfKrRgsv11216aNl7PXId0QQU0m6W9J kHL4Eb2rXMOQqQTZgcLmLeTksnZRcvY1ErYZBDeBOySKM/ww0rU2Rr3smYl1FhJN0Ty7 QJrFU9oocvL+vmc/Bx7Z/KJ3CTzdoDFaCBgcwvTnFEegXYES6XbkJEQLXgiUnNMq1Ysc 1AZF9EOnlU1Uvz/M5uFTWDDzYjRveuU/vJzNhFy/huSrObmQQQepk3UYUs9f63mxO86E MJovmWlhQQ8kwXuW9WuhWTxkIH+8r9xN8D+8Ug2UJy7MexKFU8FutQUpxEEreiFj7qNs AeZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003802; x=1691595802; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AJso+7/SyOzlPSfGsjFdKvvog0Z+6+yUR2hdcAwaBfc=; b=GnPSr3VXDRxk03FIZGlJJdKLpNoflqj5edJ0tMJFipAXJ1zMNnHLurDVcC+YQ1obZU z49zYUseTbvA2gEfm4GaXu2b3ZzgyABKM31D4VlYJ9woLSN0Fuw5bDH0fs9whHt/17d+ J4+FSpNoB2X6NkaHyTC3PLtAx/RruD3B/xYqcrDypdPNfbWSI827+p60jT5mbuq3fAym O9JiZ//NNArMHspVmCDQAfli6EpwfhF98nJ7yYOGvrq065ZniGEMR1G0JWnMHv/MXJw3 jAUCsGxgd8X6t1kAIPnpP/HBxS2O+pPgv0rcJhj32HiQzc//QNJYAlwQRQ1KDNfyZQtm APzw== X-Gm-Message-State: ABy/qLbHY73PGlDpiHWemYUDH5vBVPytHummZKEZwBwViqGFPl2/vfBq oQQ4LM1+RXZhXS5SqB4htQicDQ== X-Received: by 2002:a5d:5749:0:b0:313:e741:1caa with SMTP id q9-20020a5d5749000000b00313e7411caamr14204318wrw.25.1689003802026; Mon, 10 Jul 2023 08:43:22 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 24-20020a05600c22d800b003fbaade072dsm191143wmg.23.2023.07.10.08.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:43:21 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B26E01FFC8; Mon, 10 Jul 2023 16:35:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [RFC PATCH v3 13/20] docs/system: add a basic enumeration of vhost-user devices Date: Mon, 10 Jul 2023 16:35:15 +0100 Message-Id: <20230710153522.3469097-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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-bounces+patch=linaro.org@nongnu.org Make it clear the vhost-user-device is intended for expert use only. Signed-off-by: Alex Bennée --- v2 - make clear vhost-user-device for expert use --- docs/system/devices/vhost-user-rng.rst | 2 ++ docs/system/devices/vhost-user.rst | 41 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/docs/system/devices/vhost-user-rng.rst b/docs/system/devices/vhost-user-rng.rst index a145d4105c..ead1405326 100644 --- a/docs/system/devices/vhost-user-rng.rst +++ b/docs/system/devices/vhost-user-rng.rst @@ -1,3 +1,5 @@ +.. _vhost_user_rng: + QEMU vhost-user-rng - RNG emulation =================================== diff --git a/docs/system/devices/vhost-user.rst b/docs/system/devices/vhost-user.rst index a80e95a48a..0f9eec3f00 100644 --- a/docs/system/devices/vhost-user.rst +++ b/docs/system/devices/vhost-user.rst @@ -15,6 +15,47 @@ to the guest. The code is mostly boilerplate although each device has a ``chardev`` option which specifies the ID of the ``--chardev`` device that connects via a socket to the vhost-user *daemon*. +Each device will have an virtio-mmio and virtio-pci variant. See your +platform details for what sort of virtio bus to use. + +.. list-table:: vhost-user devices + :widths: 20 20 60 + :header-rows: 1 + + * - Device + - Type + - Notes + * - vhost-user-device + - Generic Development Device + - You must manually specify ``virtio-id`` and the correct ``num_vqs``. Intended for expert use. + * - vhost-user-blk + - Block storage + - + * - vhost-user-fs + - File based storage driver + - See https://gitlab.com/virtio-fs/virtiofsd + * - vhost-user-scsi + - SCSI based storage + - See contrib/vhost-user/scsi + * - vhost-user-gpio + - Proxy gpio pins to host + - See https://github.com/rust-vmm/vhost-device + * - vhost-user-i2c + - Proxy i2c devices to host + - See https://github.com/rust-vmm/vhost-device + * - vhost-user-input + - Generic input driver + - See contrib/vhost-user-input + * - vhost-user-rng + - Entropy driver + - :ref:`vhost_user_rng` + * - vhost-user-gpu + - GPU driver + - + * - vhost-user-vsock + - Socket based communication + - See https://github.com/rust-vmm/vhost-device + vhost-user daemon ================= From patchwork Mon Jul 10 15:35:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701038 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5246424wrs; Mon, 10 Jul 2023 08:44:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlHk3R/nH/TYzBZj9UYA/UKD22Pq9wFPfwTZ4DjgKzphEgurYjk4nig8ihPhvwrS51A254qm X-Received: by 2002:a05:622a:1711:b0:403:2e4c:28ad with SMTP id h17-20020a05622a171100b004032e4c28admr17224840qtk.18.1689003861669; Mon, 10 Jul 2023 08:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003861; cv=none; d=google.com; s=arc-20160816; b=nS/XIMBj1YR1QVG+GbteLCcab06TgDbjGqvMIAW682Tm0JHPGl1USIZoEfBJ+lnVPN GXZxhxxlkP/+9QmacnRoQl3b2e/JabtPBtfDjm0Ya3cc9JdAFclXttzQ5RCQEt+/26Nb 5wme/eyKYX8PreU6lNElMgrG+tO+0B2J0sr2hs4OWLh4p21TCjYhU7owcD2rvLKjdCmH j3yLZz0ZCAly8Y5kD9tdEOn5WpIKN7H4MlSpxJGvjTgx3UXLEe7m/D3CiFcE9evgC0s1 FQdOR7269TR6QQncqEwLD9JqSuU2WKzDB+3uW0n8J/C4tJfs3tjX4eCGJkugZaTh90Vr VwLg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PmygjvZg8uFQsUpexNqFXIftg/uxTgYWjvmcSaLAlsA=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=MnVCnzOJLbJWi13rmHDNQBIlUC13oWFV+LKFsrExDkQrKxFUueaSNjAccfb2Vs9qU5 Yb0mkbuzG+drSM99+bhhQmxRlWRCy9hXA73oTWd6KNmvfcytVn7oSDlZcYw25C9RU65l ltknubrWLY2xlAnrT77B3nWYK0EcOJAoNO+d++Poh/A4UVDdEDv/BuLRnGRdu1bkVVZ+ EQGd614b4Ba65XmId4E6LMSuGXhjE5UHk6bgrzMM7/JKetICpnXggmOMooshVtGr4aNR a8KcRTrBgBnGPgGMH2PPoPg68p9XzyvxBWF9/Y300RVrE0/OW9JojLvb7eWU6bqiPe63 1fpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="K+2L5/KZ"; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u20-20020a05622a011400b00403aac7f7besi33499qtw.105.2023.07.10.08.44.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:44:21 -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=@linaro.org header.s=google header.b="K+2L5/KZ"; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIt2v-0002XW-2F; Mon, 10 Jul 2023 11:43:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIt2s-0002WL-BW for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:43:26 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIt2p-0006Lz-Tq for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:43:25 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3fbef8ad9bbso52131215e9.0 for ; Mon, 10 Jul 2023 08:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003802; x=1691595802; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PmygjvZg8uFQsUpexNqFXIftg/uxTgYWjvmcSaLAlsA=; b=K+2L5/KZsyNq2tWxX1t3NkN+Tas0iUV8sqmJbF8Bc1mBDsis9QGrtaPM6uWbU0O6EJ 3bSL27/+49AgEl/1zUOzqznhTS7uptifshnsILnPb8Ysxny83UMqJv7qrX1EJSfNbaLE Y6hUgGF/ljtDn+1/g/obYmnkGelgzkpeSwAlR7o/l9tfJZXMmJbqw40/Ik1pt8LL+oxC ubbYAkTFnF+GkjSTpMQRpy9dJnk2lai7+GH5xVRt7EgWpiQV0uEUefvA0EbkXHwLurp7 /uobhuxqpzB4FGOZ9bLsboHb9Ig+4QMo4/9GYqxDGdUgazYs4cRI6JoT7A14GzQYDILz 8d7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003802; x=1691595802; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PmygjvZg8uFQsUpexNqFXIftg/uxTgYWjvmcSaLAlsA=; b=gQs6o+Q+LX1A7reEThDa9jr0No4XRA9TKkDIhzLM5Cvk8Wp+zNsh+xfnHg5xJ2JzS3 D+1i0oEaa8jFNU9ZviLgNinjWSLAGpvFdk8LoxmjIwf2Txqk4nHPz9/bG4491CsM9sSp SkhcsB6aiPaKHyKF2IIVrgfpd6YqaSLISpsFGbemL4g40w1R1nOs18po9mFomfQr1YkM wJ4afu0nK6ciRZ+5HOzcSV5s1IlLUkgTyZnp83sn1ru/CStmWCz5IRWkvEs1U4qTBCq5 AUn9R2OQRaHqBn68LN/eVDDBgNsIY6h50MfRj6TTvLLDnzhDuQD0Rf4ABf+LNeVuOcK9 e8pg== X-Gm-Message-State: ABy/qLbAFeZWM1rbdyKUiB3jhO4sXx/KSr/SmynX780R1GS0LRN4fReX vNoUfRa2+FD0zMnh7Jgo2N7qEQ== X-Received: by 2002:a05:600c:3785:b0:3fb:a0fc:1ba1 with SMTP id o5-20020a05600c378500b003fba0fc1ba1mr15154065wmr.35.1689003802252; Mon, 10 Jul 2023 08:43:22 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id u13-20020a7bcb0d000000b003fbc9b9699dsm155911wmj.45.2023.07.10.08.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:43:22 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id CEAE71FFC9; Mon, 10 Jul 2023 16:35:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [RFC PATCH v3 14/20] docs/interop: define STANDALONE protocol feature for vhost-user Date: Mon, 10 Jul 2023 16:35:16 +0100 Message-Id: <20230710153522.3469097-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x333.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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-bounces+patch=linaro.org@nongnu.org Currently QEMU has to know some details about the back-end to be able to setup the guest. While various parts of the setup can be delegated to the backend (for example config handling) this is a very piecemeal approach. This patch suggests a new feature flag (VHOST_USER_PROTOCOL_F_STANDALONE) which the back-end can advertise which allows a probe message to be sent to get all the details QEMU needs to know in one message. Signed-off-by: Alex Bennée --- Initial RFC for discussion. I intend to prototype this work with QEMU and one of the rust-vmm vhost-user daemons. --- docs/interop/vhost-user.rst | 39 +++++++++++++++++++++++++++++++++++++ hw/virtio/vhost-user.c | 8 ++++++++ 2 files changed, 47 insertions(+) diff --git a/docs/interop/vhost-user.rst b/docs/interop/vhost-user.rst index 5a070adbc1..a2080f56f3 100644 --- a/docs/interop/vhost-user.rst +++ b/docs/interop/vhost-user.rst @@ -275,6 +275,21 @@ Inflight description :queue size: a 16-bit size of virtqueues +Backend specifications +^^^^^^^^^^^^^^^^^^^^^^ + ++-----------+-------------+------------+------------+ +| device id | config size | min_vqs | max_vqs | ++-----------+-------------+------------+------------+ + +:device id: a 32-bit value holding the VirtIO device ID + +:config size: a 32-bit value holding the config size (see ``VHOST_USER_GET_CONFIG``) + +:min_vqs: a 32-bit value holding the minimum number of vqs supported + +:max_vqs: a 32-bit value holding the maximum number of vqs supported, must be >= min_vqs + C structure ----------- @@ -296,6 +311,7 @@ In QEMU the vhost-user message is implemented with the following struct: VhostUserConfig config; VhostUserVringArea area; VhostUserInflight inflight; + VhostUserBackendSpecs specs; }; } QEMU_PACKED VhostUserMsg; @@ -316,6 +332,7 @@ replies. Here is a list of the ones that do: * ``VHOST_USER_GET_VRING_BASE`` * ``VHOST_USER_SET_LOG_BASE`` (if ``VHOST_USER_PROTOCOL_F_LOG_SHMFD``) * ``VHOST_USER_GET_INFLIGHT_FD`` (if ``VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD``) +* ``VHOST_USER_GET_BACKEND_SPECS`` (if ``VHOST_USER_PROTOCOL_F_STANDALONE``) .. seealso:: @@ -885,6 +902,15 @@ Protocol features #define VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS 15 #define VHOST_USER_PROTOCOL_F_STATUS 16 #define VHOST_USER_PROTOCOL_F_XEN_MMAP 17 + #define VHOST_USER_PROTOCOL_F_STANDALONE 18 + +Some features depend on others to be supported: + +* ``VHOST_USER_PROTOCOL_F_STANDALONE`` depends on: + + * ``VHOST_USER_PROTOCOL_F_STATUS`` + * ``VHOST_USER_PROTOCOL_F_CONFIG`` (if there is a config space) + Front-end message types ----------------------- @@ -1440,6 +1466,19 @@ Front-end message types query the back-end for its device status as defined in the Virtio specification. +``VHOST_USER_GET_BACKEND_SPECS`` + :id: 41 + :request payload: N/A + :reply payload: ``Backend specifications`` + + When the ``VHOST_USER_PROTOCOL_F_STANDALONE`` protocol feature has been + successfully negotiated, this message is submitted by the front-end to + query the back-end for its capabilities. This is intended to remove + the need for the front-end to know ahead of time what the VirtIO + device the backend emulates is. + + The reply contains the device id, size of the config space and the + range of VirtQueues the backend supports. Back-end message types ---------------------- diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index c4e0cbd702..28b021d5d3 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -202,6 +202,13 @@ typedef struct VhostUserInflight { uint16_t queue_size; } VhostUserInflight; +typedef struct VhostUserBackendSpecs { + uint32_t device_id; + uint32_t config_size; + uint32_t min_vqs; + uint32_t max_vqs; +} VhostUserBackendSpecs; + typedef struct { VhostUserRequest request; @@ -226,6 +233,7 @@ typedef union { VhostUserCryptoSession session; VhostUserVringArea area; VhostUserInflight inflight; + VhostUserBackendSpecs specs; } VhostUserPayload; typedef struct VhostUserMsg { From patchwork Mon Jul 10 15:35:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701025 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5243248wrs; Mon, 10 Jul 2023 08:36:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlEpgrJ3B/Bs333NlhJ8EKAfJ6W8sbMmNVsuFf9ur4N0Q5N8q4OMeP3saQca5G24WA7KQy9G X-Received: by 2002:a05:620a:3186:b0:765:3e81:e74c with SMTP id bi6-20020a05620a318600b007653e81e74cmr14295980qkb.21.1689003419233; Mon, 10 Jul 2023 08:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003419; cv=none; d=google.com; s=arc-20160816; b=KZSURAAQaYMwtPCNhhzZYcj6EUhjedN1jzk3CoxwxZJoWxjQ8KeV72v53EdU0vO2It uyVrhJa/dD4qCiDyIwa25E9DPhFaoy7N3t7tzvG9a+EiPzLPhNUr7WQh+Ujq7diZHkoo x9lv2KtP3VIik4A8xLXNQ/x1b3v0SlKAu8XHSMUtLBuulG9hrBoLERbAmbnDB9m8BVNb d1S1WfFf3W4ehgzEpeNqA9lOkUl/KzDTZCPgefkRn6OIs9olaL+ph67JxGcJ3DhAIUZl whFkNvcCdF4TeXjrdZGbV6+fScuZZoYCeyU993DPV5ag73UPcvli1v6MHhfijU8ZBC39 W9Hw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JKWNeoNsx/2Bubdm0GX5BfFMkN3cqqCetF/HK2T9c0w=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=qu8CIjOXlkj1RerhV7/mZqsJpU7M2JNMQc70v2nQ7hbictoEuJS+c1ekgmHdpOtIES g+Z7GVN37BDTb5FvEw6UePGuxQ22B3MlHVtY6t7EV2z/jwdhpzYcNQcPOxDsaxedmCTn Dsb4FMK28m3uvEemDIemMf4u/hD7AjOj6QynF9YmMFQaaj4o0u3tNYCMP1pziX6Y7vUq rv4OJ2XlR0S7EiNuT6ZqpiiHhRaps75uof2IuXlLgSexj/ZI4qYaorx39TrFP3BAnWaw uATD3503qz8K1wNKEB/zVnz9+tQm05LZQ+VchbwzBYf+gi05j+ziWqMZ4iLQoz3SD4lC ikrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rqCoGiZp; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i8-20020ac85c08000000b00403b0e78f19si18887qti.307.2023.07.10.08.36.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:36:59 -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=@linaro.org header.s=google header.b=rqCoGiZp; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIsvh-0005uj-Mg; Mon, 10 Jul 2023 11:36:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIsvV-0005nm-Ao for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:49 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIsvI-0004nD-54 for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:48 -0400 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-314417861b9so4699180f8f.0 for ; Mon, 10 Jul 2023 08:35:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003334; x=1691595334; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JKWNeoNsx/2Bubdm0GX5BfFMkN3cqqCetF/HK2T9c0w=; b=rqCoGiZpI4oisj7FdN/P6Pm6psogPLWGKfNE+QfmXGA6uns8bkHBwl9nUUc7Slpoux REs3/Y/tHGGUIV+GKSrXZygLL22svBBmvZkICCzTUBMDW7ay24vp4zi2zSHT6gYaUtAl SlzIMHB5KsNOvlOohboHl7kwRCJIGofIdkMuGWnXw5tR735M3U9hDfYXGsA5UvsOf9/y HDkatK5aMg0f/ZRqh6y5/4DV0rQtdCDbIgq/MB4M5h/skqpFWG/+3Bu1c0OFDwVyaKR9 YQP1UG8GnC5dtKmAch3dCV8FVxsfMYlgTM2qCA69dNIyF2SYYLTZnTkIbPjOC0zbFt6q yGaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003334; x=1691595334; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JKWNeoNsx/2Bubdm0GX5BfFMkN3cqqCetF/HK2T9c0w=; b=HMM+rS7hb2g+zcbahWiYFqocA36qp+779Rkx27dc/L1I+0u5d/ocr1HuhymMu3JmAl rhPzRrpCzSMfEAlru+9WYsGBH/cSqd68WCV4pfk8rcUM1VRXOEccChp/d5AVb4z5HFYQ ZdJ59HuByRFxzv7K6ZQyUTz5uggOCZkHJAvAp/uK6Tsk8qUywCw+uv7A6iOkQCPvTBlz njf25NnNsMFOXSfLXToFHqSTiMvjOFc9UHKI3xPlynRBKqWNbZ1OVMMqxizYuS8gngdS RpTmy+b8JdYQd+3ISYjDcEpuyTgIHKOFm6LVuXHiuR0mP0KYjCSDrypQll5LhDxHSrRz sakw== X-Gm-Message-State: ABy/qLbjVz+zE3VzWB2QvMuwmhJtP77vm5V2rxkWJ6WNM7dLekqXXVcb Vy8379lEU3BA/DOQW+GHU0t0Mw== X-Received: by 2002:a5d:674b:0:b0:312:8e63:71c with SMTP id l11-20020a5d674b000000b003128e63071cmr12803306wrw.32.1689003334661; Mon, 10 Jul 2023 08:35:34 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id q24-20020a056000137800b00314172ba213sm11948883wrz.108.2023.07.10.08.35.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:35:32 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id E7A201FFBB; Mon, 10 Jul 2023 16:35:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [RFC PATCH v3 15/20] hw/virtio: move vhost_user_init earlier Date: Mon, 10 Jul 2023 16:35:17 +0100 Message-Id: <20230710153522.3469097-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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-bounces+patch=linaro.org@nongnu.org In preparation for getting the details of the VirtIO device directly from the vhost-user daemon we should connect once we have validated the chardev. We will actually move the connection in the next patch to keep the changes small and bisectable. Signed-off-by: Alex Bennée --- hw/virtio/vhost-user-device.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/virtio/vhost-user-device.c b/hw/virtio/vhost-user-device.c index 2b028cae08..d787f52364 100644 --- a/hw/virtio/vhost-user-device.c +++ b/hw/virtio/vhost-user-device.c @@ -250,6 +250,10 @@ static void vub_device_realize(DeviceState *dev, Error **errp) return; } + if (!vhost_user_init(&vub->vhost_user, &vub->chardev, errp)) { + return; + } + if (!vub->virtio_id) { error_setg(errp, "vhost-user-device: need to define device id"); return; @@ -268,10 +272,6 @@ static void vub_device_realize(DeviceState *dev, Error **errp) vub->vhost_user.supports_config = true; } - if (!vhost_user_init(&vub->vhost_user, &vub->chardev, errp)) { - return; - } - virtio_init(vdev, vub->virtio_id, vub->config_size); /* From patchwork Mon Jul 10 15:35:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701036 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5246367wrs; Mon, 10 Jul 2023 08:44:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlE3bxk2luZ9dfZyJz/xX6twAIeOgpaPrUDe9DW5FVZ0HjsaE1wlaj0hvq0S8/K7Na/gM2B7 X-Received: by 2002:a0c:b453:0:b0:635:e56e:ccf1 with SMTP id e19-20020a0cb453000000b00635e56eccf1mr10881406qvf.46.1689003851940; Mon, 10 Jul 2023 08:44:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003851; cv=none; d=google.com; s=arc-20160816; b=nekagDFCIJ7e7GeOyMljR69bFuQMHvqQm/fd30Arq9wkxlm8F0Cov+1kBLeFUQLAhO TStbHZBnJVDF5GBJw7uMT7mGRbD9fhGkTkFKFTAHLoaMZY66XYSP8/+9ZtJ1RLbU0n2A vvySQqpZiVoc1zrxZTJpLgmNlM0Y2NZ25KcWmZYh9vgOI3DwbQiVN1kBOT1xAvTUZFQW MBmIPQM1BRe7llf9lIXJm/A7/F+wi5MR48sI5oTE+d/tc48QYLrP4ahkT3V1ZWNjlyGY HMgxEuayTwDuU1bIXO1gXPqhf3ygx2i13MiMdUeBVNog9mhzYV1MrQa4qgfKh6pqFqtI V9+A== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=b0ilIKM9UzrdIh1IGF/Dd3LVm1ZupBEQeVXkMJAA6OY=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=RUIJoSx7ShpZV3a31CggdPvpjSE7rqOB3mp173h/LohJp6DZBVy0bEB8APr6YUWBJC 7lJiIVeTKCfV6xwII6gdv/WecI1SdzEvboKwR6mcjychXMU5ZuAUP4TLRSl1LPte8013 imgLdMrknFgep5O75Eq4JAhAt7Aqm0WRtBAovblTaBXbLzenuPpelLfRWZxZEwJ2MlzS mzjd9NUdMphkkn5z/GXbVcah8uX+pCKLzQLN79bFjcNhxnFp/iT5pGA9eVOC1T6/NsW/ Rx9qwaPyCsiMPALxw9Nw0jL6zDbIaZDUMsmcvJV8xMOTVIIk2uHjjIfAoMIR9o4ocjPk OqEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jxGO4ib/"; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g15-20020a0caacf000000b0057104cd4825si5548312qvb.68.2023.07.10.08.44.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:44:11 -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=@linaro.org header.s=google header.b="jxGO4ib/"; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIt2y-0002Ym-Ku; Mon, 10 Jul 2023 11:43:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIt2u-0002XG-Fj for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:43:28 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIt2r-0006ML-Lh for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:43:28 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3fbc12181b6so52052015e9.2 for ; Mon, 10 Jul 2023 08:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003803; x=1691595803; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=b0ilIKM9UzrdIh1IGF/Dd3LVm1ZupBEQeVXkMJAA6OY=; b=jxGO4ib/7xl0KK29LlO6eT9Q5mPWTQSH5ZA7JO+oBfOkMqUt48G2424F2Bggu4Y1K3 eS2gJn5s4IsmfRA6Kc/PilOY0eGLJw4sNZeWsuLAixtkcOazolJEBW7CL/YrIHY8FHJj 3c+NEJI2MRqwC777n7sf2C9xufCHv0AZAB5dhUfiAkk0XXpqIkTAQ7lR+Z7RWmAsBAJr lPTXknQqVPkLZV4RoInWpXcqE/7b7zFU273iwgIKba0oT2gNA8d+ouUl7WzxoWIICMuU i+dVpkZfIJq03Kc2NV3o702IJl6f4MErKzukJkkniZ61uOcqlaspvsIWuX4mB8RqtOhn UlqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003803; x=1691595803; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b0ilIKM9UzrdIh1IGF/Dd3LVm1ZupBEQeVXkMJAA6OY=; b=JMhdxkTmx3jp61XWutaHyi+WjCXNPJcRRKUdXlkj0F1+YjXsO7Gbw06Y7PhU0Cr3Hv T1rod3W8KluLrbOpggaer5f/RMcB54pO7pTeHhUXYyVrT/aMgEG3a1Guwh5QCZlYqqR7 H0bU1kbgPAeCLLg8ySXJpVgBp3/POlRi0lsBmFoU9C/wuWOiDaUYv61NPosJepyPSGku byPBo6bbicXRLWxcQqfSF4weJD2fFIm1dysmJTIDIGcHN2/HMw/Fbqju6Y4v9ILI77L+ OPWI9Z0N6kXmW8VVwIel6rKPR5xteN1LcM3NuTLJm2NQllhBt2Gt9ObcF15deV/1gmjA Jw0g== X-Gm-Message-State: ABy/qLZrFdkZ9cJMAR289xadAu9HNKemZ3H9B0k+knRcCGvRefcVFRwa XLS0C9L5c+e6yKzunwW8HchREw== X-Received: by 2002:a05:600c:378d:b0:3fc:e1:24b5 with SMTP id o13-20020a05600c378d00b003fc00e124b5mr8012473wmr.23.1689003803192; Mon, 10 Jul 2023 08:43:23 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id z22-20020a7bc7d6000000b003fbcdba1a63sm206655wmk.12.2023.07.10.08.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:43:22 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 0C1731FFCA; Mon, 10 Jul 2023 16:35:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [RFC PATCH v3 16/20] hw/virtio: move virtq initialisation into internal helper Date: Mon, 10 Jul 2023 16:35:18 +0100 Message-Id: <20230710153522.3469097-17-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x330.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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-bounces+patch=linaro.org@nongnu.org This will be useful if we end up having to consider initialising the virtqs at a seperate time. Signed-off-by: Alex Bennée --- hw/virtio/vhost.c | 60 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 82394331bf..971df8ccc5 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1382,12 +1382,47 @@ static void vhost_virtqueue_cleanup(struct vhost_virtqueue *vq) } } +/* + * Initialise the virtqs. This can happen soon after the initial + * connection if we have all the details we need or be deferred until + * later. + */ +static bool vhost_init_virtqs(struct vhost_dev *hdev, uint32_t busyloop_timeout, + Error **errp) +{ + int i, r, n_initialized_vqs = 0; + + for (i = 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { + r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i); + if (r < 0) { + error_setg_errno(errp, -r, "Failed to initialize virtqueue %d", i); + /* not sure what the point of this is if we have failed... */ + hdev->nvqs = n_initialized_vqs; + return false; + } + } + + if (busyloop_timeout) { + for (i = 0; i < hdev->nvqs; ++i) { + r = vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i, + busyloop_timeout); + if (r < 0) { + error_setg_errno(errp, -r, "Failed to set busyloop timeout"); + return false; + } + } + } + + g_assert(hdev->nvqs == n_initialized_vqs); + return true; +} + int vhost_dev_init(struct vhost_dev *hdev, void *opaque, VhostBackendType backend_type, uint32_t busyloop_timeout, Error **errp) { uint64_t features; - int i, r, n_initialized_vqs = 0; + int i, r; hdev->vdev = NULL; hdev->migration_blocker = NULL; @@ -1412,22 +1447,10 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, goto fail; } - for (i = 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { - r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i); - if (r < 0) { - error_setg_errno(errp, -r, "Failed to initialize virtqueue %d", i); - goto fail; - } - } - - if (busyloop_timeout) { - for (i = 0; i < hdev->nvqs; ++i) { - r = vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i, - busyloop_timeout); - if (r < 0) { - error_setg_errno(errp, -r, "Failed to set busyloop timeout"); - goto fail_busyloop; - } + /* Skip if we don't yet have number of vqs */ + if (hdev->vqs && hdev->nvqs) { + if (!vhost_init_virtqs(hdev, busyloop_timeout, errp)) { + goto fail_busyloop; } } @@ -1492,12 +1515,11 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, fail_busyloop: if (busyloop_timeout) { - while (--i >= 0) { + for (i = 0; i < hdev->nvqs; ++i) { vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i, 0); } } fail: - hdev->nvqs = n_initialized_vqs; vhost_dev_cleanup(hdev); return r; } From patchwork Mon Jul 10 15:35:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701033 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5243759wrs; Mon, 10 Jul 2023 08:38:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlH8Noo7eumerSgl1lKqQA1Ajo4Xx4GEtWXmxE1ZM/vTjo+F5KpKIuIQitnpDkf2Bhlf3AYz X-Received: by 2002:a05:622a:1492:b0:400:9666:4349 with SMTP id t18-20020a05622a149200b0040096664349mr16776245qtx.46.1689003486284; Mon, 10 Jul 2023 08:38:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003486; cv=none; d=google.com; s=arc-20160816; b=r55IhMCWApiDve+15XVrkvK6Wa1O6uL3MZc8qLc4RuCzE01WMxDykDJRxY9WXaXh+0 OoDICv/DP0EO38z9xlA4OlamWcnSU5Y2AeMZLhkMXkO6917uRxom9++5WrlweyPTGUof fEdjVgrQwV1rGcaCD4t30hVCZy3Tvw0htwB2cPBVpIEJcTRZSaTvGehZgpOfbqX9sJp/ q60Hyqfxti4dB1fRRHnm/FB7xIv1vwbXOp0asymEMc4W3uvUwTrsVdmQAumFFj2kIpP1 68VRlDgyBIm/+A6CYk4e+08m14FTyKOhlb1tn1bSBl7rrrDr2sk1rIA6JrxToifVCJLs a4nw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xDZmGNDNyuhkll410B4VoGo9VxH/iR/CeowwBsfUY1w=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=0qMuJm2SyBEy/mRcWkNYXwi4n8Gtog33cUlT7H07IPSL9ZbMIZEqutIcfDXT+kx/Zl mCvX5gYMTLoIl0lnAhzzBD0J86e7z0UVZMNS1iQtqxKQoYsiNThgaSAwrUB1dNLTafiu sxB5SuqH2jj878zmnZ4sx2iyerpfKBPn6K96WukbcgEXJ+PD3r6UfcXATqEnMyqN4fhC 8NL2f/nv4npdfoq3gRq2oht8QhqgmSPnrWyvJAD8K83HI1HUizhTBHCPS/7qIiJIVr95 MU25rxRJqefbngmj/jZWK/tWAbPzx2YFWar6Op3EwGhR0Ry074745HvPTsFiebtKDME/ EmJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QkYx+xUl; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o9-20020ac85a49000000b00403a8e58423si15900qta.448.2023.07.10.08.38.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:38:06 -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=@linaro.org header.s=google header.b=QkYx+xUl; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIsvl-0005yQ-Az; Mon, 10 Jul 2023 11:36:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIsvb-0005sx-Cc for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:55 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIsvK-0004ni-4G for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:55 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fbea14700bso47473095e9.3 for ; Mon, 10 Jul 2023 08:35:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003335; x=1691595335; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xDZmGNDNyuhkll410B4VoGo9VxH/iR/CeowwBsfUY1w=; b=QkYx+xUlO1OnM+U7cOlueYmTRxa1bcRe22n9kzYln3nevXTCPjNWcEniLPfkYm79vZ KvtBm3Ga+uZMT4h04nx/RzrT14Fs73vn/z2T6iOpPIC+cReZXRCJtA2axuOWG7QJun7r LBoNiyVR+X1c6ekBtUwVKWRKzFSVuKBc//NR7hOgPP19FwNL13KdaCue90FQv1L4CAbn dp/kGb85v2XetvnDznRnrY0ZbeOTbtlpbVzZMzvDLm6u2dJU4DGQzmKAkhb/H05xi//i 45XXZeFzfF3HxTykWRtgan9FWT8Gs+3FqtDujK4CE2Zsqo9v1mINrEnhHSPDzPDUf+yv 13Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003335; x=1691595335; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xDZmGNDNyuhkll410B4VoGo9VxH/iR/CeowwBsfUY1w=; b=Q2+RlGRjQhHepR0bwfk/MxQD+oVgiVyM+dzpgoFxHV0IUVa3D9udUIvJkPUXncEKTa ck3f//3YWKNLW9FHw//w/Ld2bMw8htf7Bp+26v5oLwY7rE8Hewpdsq+4zew6iozlNVyL ZcMNK3orAQtuTAxb5K0/p9CfUks2pzTGYaO+I5u/EUKh9wfFHDNAeWmh0tRj+Eo3+kWi ayRY7TN6aTbsjLEy3jH9PA+w+dvf4UBVoMJZcWANegNv/GXrrP/Mg/hWTUQ72PKMmtMF bemsbKu8Kqb1MbabUY4FlIKVteZ1extqYvkPDi5aj2A26Slyh3384AOhJW2NOhB7ThwL Hyjg== X-Gm-Message-State: ABy/qLbnGPX5bMbxTGCc/PKpML72cwHUOACx9awU+DVSYCX83RSt8tMy PoU/E4ooKfgiSYewIzRq4u01aQ== X-Received: by 2002:a1c:ed0d:0:b0:3fa:934c:8350 with SMTP id l13-20020a1ced0d000000b003fa934c8350mr11463432wmh.27.1689003335577; Mon, 10 Jul 2023 08:35:35 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id z22-20020a7bc7d6000000b003fbcdba1a63sm189157wmk.12.2023.07.10.08.35.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:35:33 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 3BCE21FFCB; Mon, 10 Jul 2023 16:35:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [RFC PATCH v3 17/20] hw/virtio: push down allocation responsibility for vhost_dev->vqs Date: Mon, 10 Jul 2023 16:35:19 +0100 Message-Id: <20230710153522.3469097-18-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x331.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=unavailable 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-bounces+patch=linaro.org@nongnu.org All the allocations are a function the number of vqs we are allocating so let the vhost code deal with it directly. This allows to eliminate some complexity of the clean-up code (because vhost_dev_init cleanups after itself if it fails). We can also places where we store copies of @vqs in child objects. Signed-off-by: Alex Bennée --- include/hw/virtio/vhost-user-blk.h | 1 - include/hw/virtio/vhost.h | 9 +++++++++ backends/vhost-user.c | 1 - hw/block/vhost-user-blk.c | 7 +------ hw/scsi/vhost-scsi.c | 2 -- hw/scsi/vhost-user-scsi.c | 6 ------ hw/virtio/vdpa-dev.c | 9 ++------- hw/virtio/vhost-user-device.c | 3 --- hw/virtio/vhost-user-fs.c | 1 - hw/virtio/vhost.c | 10 ++++++++-- 10 files changed, 20 insertions(+), 29 deletions(-) diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-user-blk.h index ea085ee1ed..479fcc2a82 100644 --- a/include/hw/virtio/vhost-user-blk.h +++ b/include/hw/virtio/vhost-user-blk.h @@ -37,7 +37,6 @@ struct VHostUserBlk { struct vhost_dev dev; struct vhost_inflight *inflight; VhostUserState vhost_user; - struct vhost_virtqueue *vhost_vqs; VirtQueue **virtqs; /* diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index f7f10c8fb7..912706668a 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -82,6 +82,10 @@ struct vhost_dev { MemoryRegionSection *mem_sections; int n_tmp_sections; MemoryRegionSection *tmp_sections; + /** + * @vqs - internal to vhost_dev, allocated based on @nvqs + * @nvqs - number of @vqs to allocate. + */ struct vhost_virtqueue *vqs; unsigned int nvqs; /* the first virtqueue which would be used by this vhost dev */ @@ -156,6 +160,9 @@ struct vhost_net { * negotiation of backend interface. Configuration of the VirtIO * itself won't happen until the interface is started. * + * If the initialisation fails it will call vhost_dev_cleanup() to + * tear down the interface and free memory. + * * Return: 0 on success, non-zero on error while setting errp. */ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, @@ -165,6 +172,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, /** * vhost_dev_cleanup() - tear down and cleanup vhost interface * @hdev: the common vhost_dev structure + * + * This includes freeing internals such as @vqs */ void vhost_dev_cleanup(struct vhost_dev *hdev); diff --git a/backends/vhost-user.c b/backends/vhost-user.c index 94c6a82d52..05a3cf77d0 100644 --- a/backends/vhost-user.c +++ b/backends/vhost-user.c @@ -34,7 +34,6 @@ vhost_user_backend_dev_init(VhostUserBackend *b, VirtIODevice *vdev, b->vdev = vdev; b->dev.nvqs = nvqs; - b->dev.vqs = g_new0(struct vhost_virtqueue, nvqs); ret = vhost_dev_init(&b->dev, &b->vhost_user, VHOST_BACKEND_TYPE_USER, 0, errp); diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index eecf3f7a81..9221f159ec 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -332,7 +332,6 @@ static int vhost_user_blk_connect(DeviceState *dev, Error **errp) s->dev.num_queues = s->num_queues; s->dev.nvqs = s->num_queues; - s->dev.vqs = s->vhost_vqs; s->dev.vq_index = 0; s->dev.backend_features = 0; @@ -480,7 +479,6 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) } s->inflight = g_new0(struct vhost_inflight, 1); - s->vhost_vqs = g_new0(struct vhost_virtqueue, s->num_queues); retries = REALIZE_CONNECTION_RETRIES; assert(!*errp); @@ -504,8 +502,7 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) return; virtio_err: - g_free(s->vhost_vqs); - s->vhost_vqs = NULL; + vhost_dev_cleanup(&s->dev); g_free(s->inflight); s->inflight = NULL; for (i = 0; i < s->num_queues; i++) { @@ -527,8 +524,6 @@ static void vhost_user_blk_device_unrealize(DeviceState *dev) NULL, NULL, NULL, false); vhost_dev_cleanup(&s->dev); vhost_dev_free_inflight(s->inflight); - g_free(s->vhost_vqs); - s->vhost_vqs = NULL; g_free(s->inflight); s->inflight = NULL; diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index 443f67daa4..aa25cdfcdc 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -214,8 +214,6 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp) } vsc->dev.nvqs = VHOST_SCSI_VQ_NUM_FIXED + vs->conf.num_queues; - vqs = g_new0(struct vhost_virtqueue, vsc->dev.nvqs); - vsc->dev.vqs = vqs; vsc->dev.vq_index = 0; vsc->dev.backend_features = 0; diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index ee99b19e7a..7e4c20ba42 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -94,7 +94,6 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp) VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev); VHostUserSCSI *s = VHOST_USER_SCSI(dev); VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s); - struct vhost_virtqueue *vqs = NULL; Error *err = NULL; int ret; @@ -116,10 +115,8 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp) } vsc->dev.nvqs = VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues; - vsc->dev.vqs = g_new0(struct vhost_virtqueue, vsc->dev.nvqs); vsc->dev.vq_index = 0; vsc->dev.backend_features = 0; - vqs = vsc->dev.vqs; ret = vhost_dev_init(&vsc->dev, &s->vhost_user, VHOST_BACKEND_TYPE_USER, 0, errp); @@ -136,7 +133,6 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp) free_vhost: vhost_user_cleanup(&s->vhost_user); - g_free(vqs); free_virtio: virtio_scsi_common_unrealize(dev); } @@ -146,13 +142,11 @@ static void vhost_user_scsi_unrealize(DeviceState *dev) VirtIODevice *vdev = VIRTIO_DEVICE(dev); VHostUserSCSI *s = VHOST_USER_SCSI(dev); VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s); - struct vhost_virtqueue *vqs = vsc->dev.vqs; /* This will stop the vhost backend. */ vhost_user_scsi_set_status(vdev, 0); vhost_dev_cleanup(&vsc->dev); - g_free(vqs); virtio_scsi_common_unrealize(dev); vhost_user_cleanup(&s->vhost_user); diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c index 363b625243..c537c0d5f5 100644 --- a/hw/virtio/vdpa-dev.c +++ b/hw/virtio/vdpa-dev.c @@ -54,7 +54,6 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp) VhostVdpaDevice *v = VHOST_VDPA_DEVICE(vdev); struct vhost_vdpa_iova_range iova_range; uint16_t max_queue_size; - struct vhost_virtqueue *vqs; int i, ret; if (!v->vhostdev) { @@ -101,8 +100,6 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp) } v->dev.nvqs = v->num_queues; - vqs = g_new0(struct vhost_virtqueue, v->dev.nvqs); - v->dev.vqs = vqs; v->dev.vq_index = 0; v->dev.vq_index_end = v->dev.nvqs; v->dev.backend_features = 0; @@ -112,7 +109,7 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp) if (ret < 0) { error_setg(errp, "vhost-vdpa-device: get iova range failed: %s", strerror(-ret)); - goto free_vqs; + goto out; } v->vdpa.iova_range = iova_range; @@ -120,7 +117,7 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp) if (ret < 0) { error_setg(errp, "vhost-vdpa-device: vhost initialization failed: %s", strerror(-ret)); - goto free_vqs; + goto out; } v->config_size = vhost_vdpa_device_get_u32(v->vhostfd, @@ -160,8 +157,6 @@ free_config: g_free(v->config); vhost_cleanup: vhost_dev_cleanup(&v->dev); -free_vqs: - g_free(vqs); out: qemu_close(v->vhostfd); v->vhostfd = -1; diff --git a/hw/virtio/vhost-user-device.c b/hw/virtio/vhost-user-device.c index d787f52364..0109d4829d 100644 --- a/hw/virtio/vhost-user-device.c +++ b/hw/virtio/vhost-user-device.c @@ -288,7 +288,6 @@ static void vub_device_realize(DeviceState *dev, Error **errp) } vub->vhost_dev.nvqs = vub->num_vqs; - vub->vhost_dev.vqs = g_new0(struct vhost_virtqueue, vub->vhost_dev.nvqs); /* connect to backend */ ret = vhost_dev_init(&vub->vhost_dev, &vub->vhost_user, @@ -306,12 +305,10 @@ static void vub_device_unrealize(DeviceState *dev) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); VHostUserBase *vub = VHOST_USER_BASE(dev); - struct vhost_virtqueue *vhost_vqs = vub->vhost_dev.vqs; /* This will stop vhost backend if appropriate. */ vub_set_status(vdev, 0); vhost_dev_cleanup(&vub->vhost_dev); - g_free(vhost_vqs); do_vhost_user_cleanup(vdev, vub); } diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 49d699ffc2..b6667f08b0 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -248,7 +248,6 @@ static void vuf_device_realize(DeviceState *dev, Error **errp) /* 1 high prio queue, plus the number configured */ fs->vhost_dev.nvqs = 1 + fs->conf.num_request_queues; - fs->vhost_dev.vqs = g_new0(struct vhost_virtqueue, fs->vhost_dev.nvqs); ret = vhost_dev_init(&fs->vhost_dev, &fs->vhost_user, VHOST_BACKEND_TYPE_USER, 0, errp); if (ret < 0) { diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 971df8ccc5..4c73ced3b7 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1392,6 +1392,8 @@ static bool vhost_init_virtqs(struct vhost_dev *hdev, uint32_t busyloop_timeout, { int i, r, n_initialized_vqs = 0; + hdev->vqs = g_new0(struct vhost_virtqueue, hdev->nvqs); + for (i = 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i); if (r < 0) { @@ -1530,9 +1532,13 @@ void vhost_dev_cleanup(struct vhost_dev *hdev) trace_vhost_dev_cleanup(hdev); - for (i = 0; i < hdev->nvqs; ++i) { - vhost_virtqueue_cleanup(hdev->vqs + i); + if (hdev->vqs) { + for (i = 0; i < hdev->nvqs; ++i) { + vhost_virtqueue_cleanup(hdev->vqs + i); + } + g_free(hdev->vqs); } + if (hdev->mem) { /* those are only safe after successful init */ memory_listener_unregister(&hdev->memory_listener); From patchwork Mon Jul 10 15:35:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701032 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5243662wrs; Mon, 10 Jul 2023 08:37:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlEicc11pUHYBUCP7XJqNu0i/Oj/ZJnL68RXPr5MqiKTt7k5vYiNALCfMekpagZO6TGrcy8A X-Received: by 2002:a67:eb93:0:b0:444:bf88:c6d5 with SMTP id e19-20020a67eb93000000b00444bf88c6d5mr5886316vso.1.1689003473083; Mon, 10 Jul 2023 08:37:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003473; cv=none; d=google.com; s=arc-20160816; b=beBU9ifrbuh0KiyJjVHGAvKHTCWz69mb6jBA617yR5AmXT+EIOEZCNh4yu5V1ZXQw1 8sFdNoE68GRHb3HCNCZlA++/CECwZI6sqQnzWxnKVfPHz+1keIH8urcpFVYah8NpGqHS eZVnjmkQQB5/l8zqqNJ5vriDp7KkLiGSMsXJhwLs3FaBdvvLc5wkmWXdWMPjywid+v0E TQVqjbWTH0tkyTKxPBcheDKAhaSgFHPB0AdnO8RiNSBlLL/SKpcTuwsy7PQgEjc9wqi6 Zawt4Mg/A8Egbx9JQ8+Fr+PVrUOeUdck0C6x7vOYMpvFTdbcA86DbqZphHM7V8gOtGXA s1ww== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+hje6WZSjT0couLKOVg8pz8KNazy1XWWPGcIUxlVXlw=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=yGgNNmmYs41NNGUCE8alq1WijDSB7TeanvDCLpTv+ywfQLcRg/W+oGoeujKSQFPi0g YbbPjQw4t0MKMgNrs+b2hdZ4ovZbP2Od2U7fUjzg6F/O4WdGPaSAtH9BSNqR2rGjGuyq 8niui3M9KOl2Vh761obyBHNNvFVVT8i4lZ2fX3ZQuy9wOxRE87+nrWfpzfCM8c+vTQmU k8ZHB66LMTY0TazQGhy299HFy/KRbyqgUekcEQHDaw4IL5GoNEmtCh/9nLG4OmJXsaFD v3rmS2/CJq4mv/m+eVFIHUtqC/3dF+xz0uHG5Kj+4QgxT1o3BGHKfsGXW1hRN5+AKRCw ypLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dScf+GYE; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p5-20020a0c8c85000000b0062b6cdfa0a8si5506763qvb.56.2023.07.10.08.37.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:37:53 -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=@linaro.org header.s=google header.b=dScf+GYE; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIsvi-0005xh-TA; Mon, 10 Jul 2023 11:36:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIsvX-0005qS-E5 for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:52 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIsvJ-0004np-Gx for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:51 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-31434226a2eso5489673f8f.1 for ; Mon, 10 Jul 2023 08:35:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003336; x=1691595336; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+hje6WZSjT0couLKOVg8pz8KNazy1XWWPGcIUxlVXlw=; b=dScf+GYEj3ctwO9WuCXFy0yxJ3B0LV0V0i8bC1r6JpbiaAldVwo/K8eKPwhd/jg/pI 2jLPNATky/tXkRu2pPN8+ioJ97SQUzIlDpQLrxDSlvwfVfWbThhbQrbNBYSEtrCnRtL5 D7roIwllb2KQ2lhMVeuxvMyeE2bCgCOyJkHj3vWjkJEK1eQXm1PDbsr1y9RPsbHqxK3g g4i9CY2MWPTZZ7n5c5jqdl6l5dtXGUHtrMNgwnkAFio/uKQe5zWfwF+Y7TdFKDOJDEbr Vwxa/MDPutQf07jM78ZWbk5VhP2xZwFAsmcLSL7K34PP8WESfI9RNkae8oYxfTJ0FcqJ n/bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003336; x=1691595336; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+hje6WZSjT0couLKOVg8pz8KNazy1XWWPGcIUxlVXlw=; b=juLsGsN2GYm+88d9Xng2f5LLd/5xLMWRSE9ycmgrsOsOcq93SjcKOn/3D4hvWut0VJ S32kp7t1tkhXR3TnLmNLydqiUZq9uqpdLMlmPZM9xdYM5zZD7CX2X6uLmjpnb28XW23R 88l0VxB+M8il4OagXimRbzyqJX8V7LP2lj1V1LpfGBN624M9sy82YFz5WAlGy+WMX6b8 7AM9YqPIx430jkQQb9/AuK01HhwkOHTeHtRsURPS2WL3gxSKx9OzYI8tcbpAmdMxX9rW WjLlQCjj6q4KayW18Jl6CIweR+0qMXOV+uGksh4yI+Eff5jhmyvPNupJA8smoa7vMpO/ hySw== X-Gm-Message-State: ABy/qLZMuG9sA+dmPUgWXZuoRA8smlmz9+SHaYyhMdF4RPv44yf7xbmM xnT6dJnBvUzlIt1FLYpnOcweqg== X-Received: by 2002:a5d:52cc:0:b0:314:f7e:8755 with SMTP id r12-20020a5d52cc000000b003140f7e8755mr14618439wrv.55.1689003335788; Mon, 10 Jul 2023 08:35:35 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id k6-20020adfd846000000b00314315071bbsm12040583wrl.38.2023.07.10.08.35.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:35:33 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 553FF1FFCC; Mon, 10 Jul 2023 16:35:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [RFC PATCH v3 18/20] hw/virtio: validate F_STANDALONE also supports other protocol features Date: Mon, 10 Jul 2023 16:35:20 +0100 Message-Id: <20230710153522.3469097-19-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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-bounces+patch=linaro.org@nongnu.org If the backend advertises F_STANDALONE validate that it supports the other mandatory features or error out. Signed-off-by: Alex Bennée --- hw/virtio/vhost-user.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 28b021d5d3..3116b3e46a 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -74,6 +74,8 @@ enum VhostUserProtocolFeature { /* Feature 14 reserved for VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS. */ VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS = 15, VHOST_USER_PROTOCOL_F_STATUS = 16, + VHOST_USER_PROTOCOL_F_XEN_MMAP = 17, + VHOST_USER_PROTOCOL_F_STANDALONE = 18, VHOST_USER_PROTOCOL_F_MAX }; @@ -2048,6 +2050,21 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque, } } + /* + * If the backend supports F_STANDALONE we should validate it + * supports the other features we expect. We can't check for + * F_CONFIG support until we know if there is a config space + * to manage. + */ + if (virtio_has_feature(protocol_features, + VHOST_USER_PROTOCOL_F_STANDALONE)) { + if (!virtio_has_feature(protocol_features, VHOST_USER_PROTOCOL_F_STATUS)) { + error_setg(errp, "vhost-user device expecting F_STANDALONE device to also " + "support F_STATUS but it does not."); + return -EPROTO; + } + } + /* final set of protocol features */ dev->protocol_features = protocol_features; err = vhost_user_set_protocol_features(dev, dev->protocol_features); From patchwork Mon Jul 10 15:35:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701035 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5243893wrs; Mon, 10 Jul 2023 08:38:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlGodnyHr02AWDvIqJIbrcTugqjrwzttiiShwrFZgiXxmD5ShwYyG0URL1jv9q4fTq7bSdXG X-Received: by 2002:a05:620a:1a85:b0:767:156e:ddaa with SMTP id bl5-20020a05620a1a8500b00767156eddaamr15204408qkb.35.1689003504784; Mon, 10 Jul 2023 08:38:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003504; cv=none; d=google.com; s=arc-20160816; b=mtYVfEKrsj8YTmYBXREUckw/nS0Aa++94O/i+8fgzOHpOKpxqFGYWD+kKeOlHiGnLQ Y5Hi0p7DTfh5ia+qz88ZXkZJR0nzGdjKu4mRdGKhaFKzSMHAnAA0JNtnglg4o2Mxd8Uq nbBNutIN1BBF9hlSipXm1xPkZbh+DJyX98h64uxiuIKkk49izqJey6AuuFVZv2/u//1v ViQKSpdUCk87BYAB/NzFnRiK747NrOwTSQXODVGqVDLhjCZbBt+ME4eNqNKiDXG93Lqd rdX1sz/g+YTCpKQCRsa+mNPlhgPcD7yRZ9iXZDwwmv0IdV5tCy7W6v01T9P5TGnv3dWX fsdA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iuW0jAfNN8A5+sR2hBxbLj3ogPv3jO9gBXIeFboC3qM=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=UIo2E+ikxC3DiC7DzH9UdtsBHmu6gvtJVw7hCVLosum/OIRoNTLnMsOqgcFcmMe2pw 9rHbat6WY75ftpqzrkDguLb5fLf/4qIstzOJpq2ZAGUSqy2GziLBEjlW4JcbTtWZByEm m96WGTOjusRtmZPp/nTC0L3Unh9McrMOlKMQNH/v0Xx0jAZ97BUMEZv+jyY6reyvjxtx BZf5YnM+v+Nb+tKJhi42plr0Ab/2lOl88IAbFMKy+0ruz8SNsG7QzUzFr9bAWcQYRNBV r5nTGKqRfLa4OGG0u+kyHEF53k8Fkug0Nx6bCzodJIIf6wlg6FnddQ9qjTzg3wPS1PNn /1mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uyAiHWBK; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g15-20020ae9e10f000000b0075c978bf036si5871083qkm.137.2023.07.10.08.38.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:38:24 -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=@linaro.org header.s=google header.b=uyAiHWBK; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIsvd-0005u0-4V; Mon, 10 Jul 2023 11:35:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIsvW-0005of-4A for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:50 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIsvH-0004n6-Rf for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:35:49 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fbf1b82dc7so48285895e9.2 for ; Mon, 10 Jul 2023 08:35:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003334; x=1691595334; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iuW0jAfNN8A5+sR2hBxbLj3ogPv3jO9gBXIeFboC3qM=; b=uyAiHWBKNrwXEov3SUlRfOs5mb5vduz8KJDIwGc22Efvyl+2qKo9Zs9VaFUSexdvqN 7o/qHbdGLuwVwwmC12VVfHJYOiN3pK3bggm76Njrj68DbNckyQjiQ7TrINZUeNV4kaYW X/V1oNbZ5ksSD4VWDC63Cpa89U6JiHy/KqNr4NGx0cvXUBRR+tuwxkudV6IONi8OISNw kXHcahtWyWFtthYN8r62h2Y+sXERXJwT+AoqvVKAsTEB3p1WFHdKRf0Pg6Vzc7UvzXEG +HfS5dsd9B231biK+6+Me2kgX7JGxMHzvyWshCgNDK7ncdA/R+d5ZUEY7SS/3L8Pi4XB gEmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003334; x=1691595334; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iuW0jAfNN8A5+sR2hBxbLj3ogPv3jO9gBXIeFboC3qM=; b=Wuh37o52yhyg7fun8BIyxSv5by4rK/7nk2lPswCFjA+Nyq3RvxNRAoLB0Nn2wB+u/3 tdOziHfS57cvzgc1C6X89ExcfnEdgYogmxicYWXAUZQ30sqy2CY+vcdy9DQF9Ztw8imD sQnLIl7mRlJGHpjR0/WJq548jCCiiMvxSabSjJYmCEM3ZLGLBvCU1b73b+igitrMMJ/r rbRgQNhalEQzLwYc1o4AxU8Ty4OcmrS4CJmIb/EyRqr9xJTDCCv+55qk914PV4/13ngP cLAjI3JJy3CEOXmuMH6h0RX+z12zlPjym9x6MLuoqwsISKYXZG1JrO7BSlimCrZyQ0oM kd4Q== X-Gm-Message-State: ABy/qLbXSbBiuQm93uuCuOlFIse0Q3yyQQ25l483F8cZrMpfsy+I6xAO 3Afhhb6HlEBPmMdiY4l5shXjcg== X-Received: by 2002:a7b:c397:0:b0:3fc:6b:15d4 with SMTP id s23-20020a7bc397000000b003fc006b15d4mr9587411wmj.27.1689003334448; Mon, 10 Jul 2023 08:35:34 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id z13-20020a5d4d0d000000b002fb60c7995esm12056258wrt.8.2023.07.10.08.35.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:35:33 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 7249E1FFCD; Mon, 10 Jul 2023 16:35:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [RFC PATCH v3 19/20] hw/virtio: probe backend for specs if it supports it Date: Mon, 10 Jul 2023 16:35:21 +0100 Message-Id: <20230710153522.3469097-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x334.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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-bounces+patch=linaro.org@nongnu.org Now we have detected and validated the protocol support lets do the probe. The empty state indicates no probe took place. Signed-off-by: Alex Bennée --- include/hw/virtio/vhost.h | 12 +++++++ hw/virtio/vhost-user.c | 73 +++++++++++++++++++++++++++++++++++---- hw/virtio/vhost.c | 2 +- 3 files changed, 79 insertions(+), 8 deletions(-) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 912706668a..1d8de1c558 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -68,6 +68,13 @@ typedef struct VhostDevConfigOps { struct vhost_memory; +typedef struct VhostUserBackendSpecs { + uint32_t device_id; + uint32_t config_size; + uint32_t min_vqs; + uint32_t max_vqs; +} VhostUserBackendSpecs; + /** * struct vhost_dev - common vhost_dev structure * @vhost_ops: backend specific ops @@ -107,11 +114,15 @@ struct vhost_dev { * VHOST_USER_SET_FEATURES or VHOST_NET_F_VIRTIO_NET_HDR. Its * future use should be discouraged and the variable retired as * its easy to confuse with the VirtIO backend_features. + * + * @specs: the results of a GET_BACKEND_SPECS probe. */ uint64_t features; uint64_t acked_features; uint64_t backend_features; + VhostUserBackendSpecs specs; + /** * @protocol_features: is the vhost-user only feature set by * VHOST_USER_SET_PROTOCOL_FEATURES. Protocol features are only @@ -134,6 +145,7 @@ struct vhost_dev { QLIST_HEAD(, vhost_iommu) iommu_list; IOMMUNotifier n; const VhostDevConfigOps *config_ops; + }; extern const VhostOps kernel_ops; diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 3116b3e46a..36aa4ec2d5 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -123,6 +123,7 @@ typedef enum VhostUserRequest { VHOST_USER_REM_MEM_REG = 38, VHOST_USER_SET_STATUS = 39, VHOST_USER_GET_STATUS = 40, + VHOST_USER_GET_BACKEND_SPECS = 41, VHOST_USER_MAX } VhostUserRequest; @@ -204,13 +205,6 @@ typedef struct VhostUserInflight { uint16_t queue_size; } VhostUserInflight; -typedef struct VhostUserBackendSpecs { - uint32_t device_id; - uint32_t config_size; - uint32_t min_vqs; - uint32_t max_vqs; -} VhostUserBackendSpecs; - typedef struct { VhostUserRequest request; @@ -1991,6 +1985,56 @@ static int vhost_user_postcopy_notifier(NotifierWithReturn *notifier, return 0; } +static bool vhost_user_get_backend_specs(struct vhost_dev *dev, Error **errp) +{ + int ret; + VhostUserMsg msg = { + .hdr.request = VHOST_USER_GET_BACKEND_SPECS, + .hdr.flags = VHOST_USER_VERSION, + .hdr.size = VHOST_USER_HDR_SIZE, + }; + + if (!virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_STANDALONE)) { + error_setg(errp, "VHOST_USER_PROTOCOL_F_STANDALONE not supported"); + return -EINVAL; + } + + ret = vhost_user_write(dev, &msg, NULL, 0); + if (ret < 0) { + error_setg_errno(errp, -ret, "vhost_get_backend send failed"); + return ret; + } + + ret = vhost_user_read(dev, &msg); + if (ret < 0) { + error_setg_errno(errp, -ret, "vhost_get_backend recv failed"); + return ret; + } + + if (msg.hdr.request != VHOST_USER_GET_BACKEND_SPECS) { + error_setg(errp, + "Received unexpected msg type. Expected %d received %d", + VHOST_USER_GET_BACKEND_SPECS, msg.hdr.request); + return -EPROTO; + } + + if (msg.hdr.size != sizeof(msg.payload.specs)) { + error_setg(errp, "Received bad msg size."); + return -EPROTO; + } + + if (msg.payload.specs.config_size && !virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_CONFIG)) { + error_setg(errp, "VHOST_USER_PROTOCOL_F_CONFIG not supported"); + return -EPROTO; + } + + dev->specs = msg.payload.specs; + + return 0; +} + static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque, Error **errp) { @@ -2073,6 +2117,21 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque, return -EPROTO; } + if (dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_STANDALONE)) { + err = vhost_user_get_backend_specs(dev, errp); + if (err < 0) { + error_setg_errno(errp, EPROTO, "vhost_get_backend_specs failed"); + return -EPROTO; + } + /* + * If this was never set by the user we can now fill it in + * so we can continue the initialisation + */ + if (!dev->nvqs) { + dev->nvqs = dev->specs.min_vqs; + } + } + /* query the max queues we support if backend supports Multiple Queue */ if (dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MQ)) { err = vhost_user_get_u64(dev, VHOST_USER_GET_QUEUE_NUM, diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 4c73ced3b7..d14467aa1c 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1450,7 +1450,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, } /* Skip if we don't yet have number of vqs */ - if (hdev->vqs && hdev->nvqs) { + if (hdev->nvqs) { if (!vhost_init_virtqs(hdev, busyloop_timeout, errp)) { goto fail_busyloop; } From patchwork Mon Jul 10 15:35:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701039 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5246478wrs; Mon, 10 Jul 2023 08:44:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlFEQafFTZI/EjqzJvsw1ytWVtnSfdv58tG2sYsWHfwNqMWnrH9NF2HjhL0AUGxXYCFcRirf X-Received: by 2002:a05:620a:448b:b0:767:dc58:f256 with SMTP id x11-20020a05620a448b00b00767dc58f256mr1033519qkp.70.1689003867095; Mon, 10 Jul 2023 08:44:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003867; cv=none; d=google.com; s=arc-20160816; b=g+o/uhF3fP+v16FMjsj+wW5orouv4HLv0JTvLhyClcvwSYa7UXO6NMieUK/lm9Ygdn vtRUiGsVNJr3kuAprEvYPbvJJsQp+vWpofUsRIFCBrfLzhkiIrZV0IuctoXplDBz26pa xDqnWsBLgCFmU7wVas++bu8OZPaJuK5cy7+iwdzzoDuNx80I0e9wQtPN++U0oP9SM4PZ oJN+hGwGsWrSgyNlNbco+pO/KR0r2+F2HjCxHxvwbGH+CvQx8N+RUaDWWeXKrEYZD6pz WSGOCI7RrMngGFl1y15Td86lppimg1SCeXY59rxIo3igBiUfn96NXgonrdHCQt/8Czze KsrQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IVoZ+61FKCrNdklMoUuKRwdzJcWCiwu+9oFevqFhgNQ=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=JwJBGLsCNbiOqRjztWAaH0mc5Hu3d8v1IJJj2Lfq+b2Id8Bxs/x5wUohLqX+3K7zDO Z1fTIpeLxvfE0l8VqGzh8DtQT2h9KGAqSYHw87S29iT8uo9VpRVQ2tViTOGCIkGncnFG FzVnm5cFKwWUoUWGcr4U6dmn5i6UppYo5v7sC5nNFo0Amc+wnmL/tdYbLRoQfdpw7EzM yTcB26iJJ1ZpUTfh+dSY2Nr13lJYDpYfdWGte5ZUwAfMN0OkcKRSf/wvFliaHUkWKcqV NEv9ZICKUxdR/DinqD5Pjv9FmCcoaD60Cu5tW/FQlOYX9GB1wNz2vJsvAQe2t6MVzHxd 6ntA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vr0iX5PB; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id do46-20020a05620a2b2e00b00767d0ec9a2bsi1226994qkb.303.2023.07.10.08.44.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:44:27 -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=@linaro.org header.s=google header.b=Vr0iX5PB; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIt30-0002ZO-A4; Mon, 10 Jul 2023 11:43:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIt2v-0002Xa-3s for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:43:29 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIt2q-0006MN-Mn for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:43:27 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3fbc5d5742eso51989205e9.3 for ; Mon, 10 Jul 2023 08:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003803; x=1691595803; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IVoZ+61FKCrNdklMoUuKRwdzJcWCiwu+9oFevqFhgNQ=; b=Vr0iX5PBlhO1Adj/4b7VlrHQkVn7GTOo5wyPKAYyOoIZEHmtrmf2CnnHEjUWaj3r5E gN1/wrYb3QfFv9cJ7Q+onYHROjTQ7g4Zk2+NvhwEx5lQUiRVDTA3Vspem0wuleZKlBTw HxZ5kfqcc4mZ5OGvHc4DKl1bxmJcccfgaf1hFufn/FOtw3wsH314q4Bjfx9ltnd83Dbg RvbJfwf39Lt2h6ddlusjcgwbBsceZCUeizDw6Aj5TX5ZaGT/rwtKPWaPWC5SFUqnexVj cNOLUD3riwHeX40BdeiIYBWMhiTu09Cv6qL4s4sfSUpe+/RCFyr7dZl0XKiMfrbRFWG9 2mtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003803; x=1691595803; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IVoZ+61FKCrNdklMoUuKRwdzJcWCiwu+9oFevqFhgNQ=; b=M4XFUAq8ZIhWit1Fq4cxgw1uzJngQ5eqtvj8fV5RIkHub6nxswGFJmBPufglyYpwXu wv2VUDT6F+gEN78AavQsACpbBul0z7uQ9PWT0wZlnfn09HCblKuQFYj+dpTNaEHlO/zU IFN4aIBbhfr+u5fMVaKHMqHuvnivlUqLCsbbwAb2Bme+cs+P1gHsMR+hmSSVopLjUK3g FgVY4KBAukLkzSIseBH5AzaHy0aOFfn/9amhdRDwvDv7BededZ7lvprq70DcHGbrn/X6 P3rRFbH0+1nQKl8ngonVjhh0B8vpwwi1rHL0IsLAn+6BBXl5dFZoN1K1XoslKrN0tEEX oRSw== X-Gm-Message-State: ABy/qLbyv23JxHEHlR0OFn35V/J8x9RfUP+UIsaPdcUsN6x562Q3f2yc 2+6nf1jKEQq/DzcsA8zbdtT1oA== X-Received: by 2002:a7b:c5d6:0:b0:3f7:3991:e12e with SMTP id n22-20020a7bc5d6000000b003f73991e12emr12593197wmk.1.1689003803383; Mon, 10 Jul 2023 08:43:23 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id h5-20020adffd45000000b00313f07ccca4sm12027136wrs.117.2023.07.10.08.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:43:22 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8AFD81FFBC; Mon, 10 Jul 2023 16:35:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [RFC PATCH v3 20/20] hw/virtio: allow vhost-user-device to be driven by backend Date: Mon, 10 Jul 2023 16:35:22 +0100 Message-Id: <20230710153522.3469097-21-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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-bounces+patch=linaro.org@nongnu.org Instead of requiring all the information up front allow the vhost_dev_init to complete and then see what information we have from the backend. This does change the order around somewhat. Signed-off-by: Alex Bennée --- hw/virtio/vhost-user-device.c | 45 +++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/hw/virtio/vhost-user-device.c b/hw/virtio/vhost-user-device.c index 0109d4829d..b30b6265fb 100644 --- a/hw/virtio/vhost-user-device.c +++ b/hw/virtio/vhost-user-device.c @@ -243,7 +243,6 @@ static void vub_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); VHostUserBase *vub = VHOST_USER_BASE(dev); - int ret; if (!vub->chardev.chr) { error_setg(errp, "vhost-user-device: missing chardev"); @@ -254,13 +253,43 @@ static void vub_device_realize(DeviceState *dev, Error **errp) return; } + if (vhost_dev_init(&vub->vhost_dev, &vub->vhost_user, + VHOST_BACKEND_TYPE_USER, 0, errp)!=0) { + error_setg(errp, "vhost-user-device: unable to start connection"); + return; + } + + if (vub->vhost_dev.specs.device_id) { + if (vub->virtio_id && vub->virtio_id != vub->vhost_dev.specs.device_id) { + error_setg(errp, "vhost-user-device: backend id %d doesn't match cli %d", + vub->vhost_dev.specs.device_id, vub->virtio_id); + return; + } + vub->virtio_id = vub->vhost_dev.specs.device_id; + } + if (!vub->virtio_id) { - error_setg(errp, "vhost-user-device: need to define device id"); + error_setg(errp, "vhost-user-device: need to define or be told device id"); return; } + if (vub->vhost_dev.specs.min_vqs) { + if (vub->num_vqs) { + if (vub->num_vqs < vub->vhost_dev.specs.min_vqs || + vub->num_vqs > vub->vhost_dev.specs.max_vqs) { + error_setg(errp, + "vhost-user-device: selected nvqs (%d) out of bounds (%d->%d)", + vub->num_vqs, + vub->vhost_dev.specs.min_vqs, vub->vhost_dev.specs.max_vqs); + return; + } + } else { + vub->num_vqs = vub->vhost_dev.specs.min_vqs; + } + } + if (!vub->num_vqs) { - vub->num_vqs = 1; /* reasonable default? */ + error_setg(errp, "vhost-user-device: need to define number of vqs"); } /* @@ -287,16 +316,6 @@ static void vub_device_realize(DeviceState *dev, Error **errp) virtio_add_queue(vdev, 4, vub_handle_output)); } - vub->vhost_dev.nvqs = vub->num_vqs; - - /* connect to backend */ - ret = vhost_dev_init(&vub->vhost_dev, &vub->vhost_user, - VHOST_BACKEND_TYPE_USER, 0, errp); - - if (ret < 0) { - do_vhost_user_cleanup(vdev, vub); - } - qemu_chr_fe_set_handlers(&vub->chardev, NULL, NULL, vub_event, NULL, dev, NULL, true); }