From nobody Sun Apr 26 10:52:55 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E0A2CCA479 for ; Mon, 4 Jul 2022 17:17:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233384AbiGDRRN (ORCPT ); Mon, 4 Jul 2022 13:17:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230264AbiGDRRL (ORCPT ); Mon, 4 Jul 2022 13:17:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1C3F91114A for ; Mon, 4 Jul 2022 10:17:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656955030; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N/ASHfBlGwx6CPom7xa9MrPgEDXvopeeCGbYV8xojNw=; b=cjU8wuQ4NDW5GShDIBDWY5xbCgKIGczF9Rt9/bwoGqb5zr+W6Lr08PB5r7XUwJgX2Njij1 aMESe2VAqSW34vDa/RcmjES4ptFgJ0KA5a6aTYEP223tYuxri7oLfECi2ElspmK9lFJWho HSWLqtELk88+VTELCdeqnGuGn6aCRKo= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-207-i211Smq5ODeL1Xny1W4XEA-1; Mon, 04 Jul 2022 13:17:08 -0400 X-MC-Unique: i211Smq5ODeL1Xny1W4XEA-1 Received: by mail-qk1-f198.google.com with SMTP id z9-20020a376509000000b006af1048e0caso9224026qkb.17 for ; Mon, 04 Jul 2022 10:17:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N/ASHfBlGwx6CPom7xa9MrPgEDXvopeeCGbYV8xojNw=; b=32JtieuJOb989G1EcOC1nI8kKrmCNwRzXP/RYZRaMbaArUM/2jo8Qu+zT4b/tpT8HJ 288mEjoasRTHBvYimPtKE5O0r1GDLG348CEskojnORiZ/oLpgi6WQtOD5rW3v37ge3Jo gImMRpKZYmPEBF1nPkdQmzrWeNp8NegBBd2a+5wrO8TnetdOGawtklDKJBqnXvLT55Lq ERyiQKnE6DjjMX2tIyWz6n/pu736IqFheTbSs7pi3s/RJYKz78Fk+ITjWcBB/HfIzlCb WU6Q+uby3ZbL0velU/SieT0sCi8ZmqE2H65d+jRq5u2FdLQHaSaB6k/TIVd3nD3RYCiT WCHQ== X-Gm-Message-State: AJIora+p85r19UQyRPNRnnexCSiHhjujuaEJtFdK0eRd5oqi3kFHDh3n nIK+87bvEgJ7X+LNiCQDP9sR3fh5TP0GquPZaQCv/T/tLVarCsWbUNiG1zsd2WKQlKgXbwGSeoA 4OtuEvucfUr1SE9ufEFy9AMCH X-Received: by 2002:a05:620a:469e:b0:6b0:e66a:6bd with SMTP id bq30-20020a05620a469e00b006b0e66a06bdmr19691308qkb.285.1656955028388; Mon, 04 Jul 2022 10:17:08 -0700 (PDT) X-Google-Smtp-Source: AGRyM1um6olL36YJnCCSnK21iQMhdkBq5wN6w2T59beszRdcjnFkROIHM2UBY5D60rK6HejU80TvYQ== X-Received: by 2002:a05:620a:469e:b0:6b0:e66a:6bd with SMTP id bq30-20020a05620a469e00b006b0e66a06bdmr19691298qkb.285.1656955028170; Mon, 04 Jul 2022 10:17:08 -0700 (PDT) Received: from step1.redhat.com (host-79-46-200-206.retail.telecomitalia.it. [79.46.200.206]) by smtp.gmail.com with ESMTPSA id o16-20020a05620a2a1000b006a68fdc2d18sm21656078qkp.130.2022.07.04.10.17.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 10:17:07 -0700 (PDT) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Jason Wang , "Michael S. Tsirkin" , linux-kernel@vger.kernel.org, =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Stefano Garzarella Subject: [RFC PATCH 1/6] tools/virtio: fix build Date: Mon, 4 Jul 2022 19:16:56 +0200 Message-Id: <20220704171701.127665-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220704171701.127665-1-sgarzare@redhat.com> References: <20220704171701.127665-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Fix the build caused by the following changes: - phys_addr_t is now defined in tools/include/linux/types.h - dev_warn_once() is used in drivers/virtio/virtio_ring.c - linux/uio.h included by vringh.h use INT_MAX defined in limits.h Signed-off-by: Stefano Garzarella --- tools/virtio/linux/kernel.h | 2 +- tools/virtio/linux/vringh.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/virtio/linux/kernel.h b/tools/virtio/linux/kernel.h index 0b493542e61a..21593bf97755 100644 --- a/tools/virtio/linux/kernel.h +++ b/tools/virtio/linux/kernel.h @@ -29,7 +29,6 @@ #define READ 0 #define WRITE 1 =20 -typedef unsigned long long phys_addr_t; typedef unsigned long long dma_addr_t; typedef size_t __kernel_size_t; typedef unsigned int __wsum; @@ -136,6 +135,7 @@ static inline void *krealloc_array(void *p, size_t new_= n, size_t new_size, gfp_t #endif #define dev_err(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__) #define dev_warn(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__) +#define dev_warn_once(dev, format, ...) fprintf (stderr, format, ## __VA_A= RGS__) =20 #define min(x, y) ({ \ typeof(x) _min1 =3D (x); \ diff --git a/tools/virtio/linux/vringh.h b/tools/virtio/linux/vringh.h index 9348957be56e..e11c6aece734 100644 --- a/tools/virtio/linux/vringh.h +++ b/tools/virtio/linux/vringh.h @@ -1 +1,2 @@ +#include #include "../../../include/linux/vringh.h" --=20 2.36.1 From nobody Sun Apr 26 10:52:55 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D6B7C43334 for ; Mon, 4 Jul 2022 17:17:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233675AbiGDRRV (ORCPT ); Mon, 4 Jul 2022 13:17:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233493AbiGDRRP (ORCPT ); Mon, 4 Jul 2022 13:17:15 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A6C3F11C0E for ; Mon, 4 Jul 2022 10:17:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656955032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tKnKGcPQx2M8z8doipgVBVXWw9daoK1UODE6Y0G/spw=; b=APwHpzRLemvWDKpjK3QENGhFkSDSyuWH9h/A4Teak2K3oPQYcX+wCUUZVS4nWAues81fyt 6bxxJ2q3RrRecJmqzZI7WGInkLEjtoL+W9XJmS0VBOgJrWNbRrnSfhVvVPpN37yCJPMblr RyJibm8/hCklc/JKyEc69yWuiCndU9g= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-167-G7f2sKYtOY2hUEkfeCU9DQ-1; Mon, 04 Jul 2022 13:17:11 -0400 X-MC-Unique: G7f2sKYtOY2hUEkfeCU9DQ-1 Received: by mail-qt1-f198.google.com with SMTP id e8-20020ac84148000000b00319f55b2657so7307755qtm.15 for ; Mon, 04 Jul 2022 10:17:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tKnKGcPQx2M8z8doipgVBVXWw9daoK1UODE6Y0G/spw=; b=j2lJRjSTWdOhCa3aO4D9TW7dO93DpM8wgVD7xjsOVs81HgnC/N9lAghB/yz6TiJYoG CS1DlqV/MB/Ls4FLxKVkC9MMO3ELbDkkapbtEjHPYXI9XLgNYgGetZCVgCal+bRgsIPL 5nucYoilfxw/NjJKMAVJ8LRGxijew/r2RiHoQdFQ7NchFu5iwRpREpcvNhDJ0pGGioOG mm3W1/xTGkGvjuYTzTD+k6jqlmHzsNSJ15XDiJrk9kxIsVuGWf3Dn7xIoGe6XL3CNBRp D1hV7U5Pjd8bBvhTVTW04W4bzkXk/j2LaPJUwG2lYt36LB2mDy2vR5ZNuIEOKAb5vbgt HLsw== X-Gm-Message-State: AJIora+YQ0I0crgtVGwIkDMj2OXW112W+WSxr269gnLfD/ivISPTSebQ Oq736/7uen/4hMw6SQ9leMmyF7qCdLnSE8d/t1Q/CkD5hpKnyTak/U45Xo7dmSpES9IWOz2+C5s 5IwpuOO/hsgtQGozWn2O3DEKf X-Received: by 2002:a05:620a:f89:b0:6ae:d418:f478 with SMTP id b9-20020a05620a0f8900b006aed418f478mr20154053qkn.344.1656955031102; Mon, 04 Jul 2022 10:17:11 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v5kru0aGtinN6uCz+3PHhaYe1+jzHnVC9+Cwzy5758LJyRQ9emh0kO9BDMsxacR8UMuY7ZQw== X-Received: by 2002:a05:620a:f89:b0:6ae:d418:f478 with SMTP id b9-20020a05620a0f8900b006aed418f478mr20154038qkn.344.1656955030805; Mon, 04 Jul 2022 10:17:10 -0700 (PDT) Received: from step1.redhat.com (host-79-46-200-206.retail.telecomitalia.it. [79.46.200.206]) by smtp.gmail.com with ESMTPSA id o16-20020a05620a2a1000b006a68fdc2d18sm21656078qkp.130.2022.07.04.10.17.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 10:17:10 -0700 (PDT) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Jason Wang , "Michael S. Tsirkin" , linux-kernel@vger.kernel.org, =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Stefano Garzarella Subject: [RFC PATCH 2/6] vhost_test: add $(srctree) on the included path Date: Mon, 4 Jul 2022 19:16:57 +0200 Message-Id: <20220704171701.127665-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220704171701.127665-1-sgarzare@redhat.com> References: <20220704171701.127665-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Adding $(srctree) on the included path we can build vhost_test also when the kernel is not built in the source tree (make O=3D...). Use of EXTRA_CFLAGS is deprecated, so let's use ccflags-y. Signed-off-by: Stefano Garzarella --- tools/virtio/vhost_test/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/virtio/vhost_test/Makefile b/tools/virtio/vhost_test/Mak= efile index 94d3aff987dc..df5ad39e2520 100644 --- a/tools/virtio/vhost_test/Makefile +++ b/tools/virtio/vhost_test/Makefile @@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only obj-m +=3D vhost_test.o -EXTRA_CFLAGS +=3D -Idrivers/vhost +ccflags-y +=3D -I$(srctree)/drivers/vhost --=20 2.36.1 From nobody Sun Apr 26 10:52:55 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E10F8C43334 for ; Mon, 4 Jul 2022 17:17:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233410AbiGDRRX (ORCPT ); Mon, 4 Jul 2022 13:17:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233278AbiGDRRR (ORCPT ); Mon, 4 Jul 2022 13:17:17 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EAD7F120AF for ; Mon, 4 Jul 2022 10:17:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656955036; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eVND3GM+OEtAkbTKlrFfIkv0IqFoHwP40bUkEd6doGs=; b=h6azpLayAiVFW90SHmYl37Xb/e5kPRPpqgoOaJYjsNr6kETP517q5j4CJOQKQ596WPStWW 7EdB6reQY5iBS6FH1t1E1s9NWLzdhlwK8IcuLY/P8tPzGKLnGsfhrTK1RobWTkOYeKEt8H N/0DCJgfp+ZUNnw06Nj4qYTmSKn9CRg= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-315-iy3fFZtXN-mJ4vJUCm58iQ-1; Mon, 04 Jul 2022 13:17:14 -0400 X-MC-Unique: iy3fFZtXN-mJ4vJUCm58iQ-1 Received: by mail-qt1-f197.google.com with SMTP id ck12-20020a05622a230c00b00304ee787b02so6199255qtb.11 for ; Mon, 04 Jul 2022 10:17:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eVND3GM+OEtAkbTKlrFfIkv0IqFoHwP40bUkEd6doGs=; b=FFzIFp1Y16atBUYAmOEcAPFLL32LJWWNXeBfJRPEITjpEfjTf/hyhUiRa+/MJ1lJ9e KKqBZDLh5x0O5yXfiBvNhhzaQEeNNHdu+Oaz+8hx8nGi4njGq+kc3Yo7BvxPFVWPJn08 NJa4RLwsRuJjgW2XBXnJvFl9SfEweLc8uBXsm26xtIzKNriScveFVLF9OH84Rmw6gu1K wsCE88Nt0NYaH/bzEgisT7+vsWUg43hp6MBn64YX7rqFPYF1qxK9ZoBelNOlHpdQS6ZL yFRhUYAT81utJJoUq5R+Eia7zdY9GMSG0TjwYwoX7xrKAe3Jqrh9PWq9IEsN11Smsaty K6yg== X-Gm-Message-State: AJIora+3cXE0PuzuTlki9vIapqvvbx2l2jmL6EbOl4aCdyFVp29WqIRj bhEG+WE1fRenphxrDVWo8f8IzAtEiuoh8XK5InGWKbVvHzmVcUGAcr2vpIomUwk3lZvHm1OOSxh JPs1y/sDmmPEXmVo35rWl8aoU X-Received: by 2002:ac8:5b44:0:b0:318:291d:8f59 with SMTP id n4-20020ac85b44000000b00318291d8f59mr24361550qtw.22.1656955033389; Mon, 04 Jul 2022 10:17:13 -0700 (PDT) X-Google-Smtp-Source: AGRyM1srxXAHH5r1Kdxl8lINLquxuasM0BWZ/em5yNCcgZULj5nIl3JWsRbNRPyI0zQuAgROZCfdxw== X-Received: by 2002:ac8:5b44:0:b0:318:291d:8f59 with SMTP id n4-20020ac85b44000000b00318291d8f59mr24361526qtw.22.1656955033118; Mon, 04 Jul 2022 10:17:13 -0700 (PDT) Received: from step1.redhat.com (host-79-46-200-206.retail.telecomitalia.it. [79.46.200.206]) by smtp.gmail.com with ESMTPSA id o16-20020a05620a2a1000b006a68fdc2d18sm21656078qkp.130.2022.07.04.10.17.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 10:17:12 -0700 (PDT) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Jason Wang , "Michael S. Tsirkin" , linux-kernel@vger.kernel.org, =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Stefano Garzarella Subject: [RFC PATCH 3/6] virtio_test: call __virtio_unbreak_device Date: Mon, 4 Jul 2022 19:16:58 +0200 Message-Id: <20220704171701.127665-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220704171701.127665-1-sgarzare@redhat.com> References: <20220704171701.127665-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Commit 8b4ec69d7e09 ("virtio: harden vring IRQ") initialize vq->broken to true, so we need to call __virtio_unbreak_device() before starting to use it. Signed-off-by: Stefano Garzarella --- tools/virtio/linux/virtio.h | 2 ++ tools/virtio/virtio_test.c | 1 + 2 files changed, 3 insertions(+) diff --git a/tools/virtio/linux/virtio.h b/tools/virtio/linux/virtio.h index 363b98228301..feb720d4304f 100644 --- a/tools/virtio/linux/virtio.h +++ b/tools/virtio/linux/virtio.h @@ -66,4 +66,6 @@ struct virtqueue *vring_new_virtqueue(unsigned int index, const char *name); void vring_del_virtqueue(struct virtqueue *vq); =20 +void __virtio_unbreak_device(struct virtio_device *dev); + #endif diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c index 23f142af544a..765e64895dab 100644 --- a/tools/virtio/virtio_test.c +++ b/tools/virtio/virtio_test.c @@ -177,6 +177,7 @@ static void run_test(struct vdev_info *dev, struct vq_i= nfo *vq, long long spurious =3D 0; const bool random_batch =3D batch =3D=3D RANDOM_BATCH; =20 + __virtio_unbreak_device(&dev->vdev); r =3D ioctl(dev->control, VHOST_TEST_RUN, &test); assert(r >=3D 0); if (!reset_n) { --=20 2.36.1 From nobody Sun Apr 26 10:52:55 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38018C43334 for ; Mon, 4 Jul 2022 17:17:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233985AbiGDRRy (ORCPT ); Mon, 4 Jul 2022 13:17:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234278AbiGDRRo (ORCPT ); Mon, 4 Jul 2022 13:17:44 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C1C5412779 for ; Mon, 4 Jul 2022 10:17:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656955059; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tSo0TPjRmSn1V/oaklydrMSZvzy1inQBu0gNIodOnPc=; b=i8aJiXoiZVgoqqdZffZAuGmnUphRKLHERKbsuf0YTC9HAqNxMBrw4BreW2ARR8vsE0lvEA 2J4E1NsFslyvZ3ToyKEELG5bYXgpQveYcqkJs82yu3Qxrt4vs4dXrBVu3UcVAkaZirnlN2 SES9JA0JgPJJeNAozRC0ji6NPPomfN4= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-458-6hB6NocWNQeZfV2rXRfsfQ-1; Mon, 04 Jul 2022 13:17:38 -0400 X-MC-Unique: 6hB6NocWNQeZfV2rXRfsfQ-1 Received: by mail-qt1-f200.google.com with SMTP id m6-20020ac866c6000000b002f52f9fb4edso7303558qtp.19 for ; Mon, 04 Jul 2022 10:17:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tSo0TPjRmSn1V/oaklydrMSZvzy1inQBu0gNIodOnPc=; b=xlPgPtzP4xNGtQiO0ye7TS9T+SW7FQH48nUtvOvgx1k1W9G/dEwsIJepT6qrgiZSxk HshCKbzKOh2KeHkyQu7eGRcCD0mbpUkEWRjQVfXl/EBdoc21WYcK5K3I4tMgMJZnwFfI iJJJYNKT8Ops9ZnPD9sJr7++MPiK65iLKo0kPoAqcRYug+UhevLKut933AeITv0ANUjg S3y9MoHLx8A/+b/OoDCfU++FIAS6mYhIFSlx9jgF+1ojydeBe+5YmVrWUSXCxmV1vEo0 j8nFtNl3RoNc5/RWyuedzmF0fd8WMt8U1CnAIUb5/iaJr4mpd1Yfh2oYKPeAo9ndrDsl nisA== X-Gm-Message-State: AJIora9DZNxzJQhr5qTAqNX1c0C9HlOjqc76SWNoLplLQBQwGGDBsGc8 7Ca1CSC30a6VtS8GkzReWbumi3lAwDqIVqckjBu8EUl6WDe9naL0NyZu8IZeNbZctyZbtY+3BKk 6i6Z6v6otc141DU9ExbX8JDTN X-Received: by 2002:a05:620a:2697:b0:699:cca7:f8b2 with SMTP id c23-20020a05620a269700b00699cca7f8b2mr20820466qkp.738.1656955058185; Mon, 04 Jul 2022 10:17:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uc6e9t+TDjozVIHS20Xkm/89T4WuJyrekSiGRvrPx9nG54HgL0oXw8KiDuQ3MmSutE1rHC3Q== X-Received: by 2002:a05:620a:2697:b0:699:cca7:f8b2 with SMTP id c23-20020a05620a269700b00699cca7f8b2mr20820452qkp.738.1656955057917; Mon, 04 Jul 2022 10:17:37 -0700 (PDT) Received: from step1.redhat.com (host-79-46-200-206.retail.telecomitalia.it. [79.46.200.206]) by smtp.gmail.com with ESMTPSA id y7-20020a37f607000000b006a75e8d920bsm10788838qkj.88.2022.07.04.10.17.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 10:17:37 -0700 (PDT) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Jason Wang , "Michael S. Tsirkin" , linux-kernel@vger.kernel.org, =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Stefano Garzarella Subject: [RFC PATCH 4/6] tools/virtio: move feature negotiation in vdev_info_init() Date: Mon, 4 Jul 2022 19:16:59 +0200 Message-Id: <20220704171701.127665-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220704171701.127665-1-sgarzare@redhat.com> References: <20220704171701.127665-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The feature negotiation are per device, so it' s better to move them earlier in vdev_info_init() since vhost_vq_setup() contains the code to initialize virtqueue. Signed-off-by: Stefano Garzarella --- tools/virtio/virtio_test.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c index 765e64895dab..2d8a3e881637 100644 --- a/tools/virtio/virtio_test.c +++ b/tools/virtio/virtio_test.c @@ -69,7 +69,6 @@ void vhost_vq_setup(struct vdev_info *dev, struct vq_info= *info) { struct vhost_vring_state state =3D { .index =3D info->idx }; struct vhost_vring_file file =3D { .index =3D info->idx }; - unsigned long long features =3D dev->vdev.features; struct vhost_vring_addr addr =3D { .index =3D info->idx, .desc_user_addr =3D (uint64_t)(unsigned long)info->vring.desc, @@ -77,8 +76,6 @@ void vhost_vq_setup(struct vdev_info *dev, struct vq_info= *info) .used_user_addr =3D (uint64_t)(unsigned long)info->vring.used, }; int r; - r =3D ioctl(dev->control, VHOST_SET_FEATURES, &features); - assert(r >=3D 0); state.num =3D info->vring.num; r =3D ioctl(dev->control, VHOST_SET_VRING_NUM, &state); assert(r >=3D 0); @@ -149,6 +146,8 @@ static void vdev_info_init(struct vdev_info* dev, unsig= ned long long features) dev->mem->regions[0].memory_size =3D dev->buf_size; r =3D ioctl(dev->control, VHOST_SET_MEM_TABLE, dev->mem); assert(r >=3D 0); + r =3D ioctl(dev->control, VHOST_SET_FEATURES, &features); + assert(r >=3D 0); } =20 /* TODO: this is pretty bad: we get a cache line bounce --=20 2.36.1 From nobody Sun Apr 26 10:52:55 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 700D6C43334 for ; Mon, 4 Jul 2022 17:18:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233570AbiGDRSB (ORCPT ); Mon, 4 Jul 2022 13:18:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234338AbiGDRRp (ORCPT ); Mon, 4 Jul 2022 13:17:45 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ADB0E12A9D for ; Mon, 4 Jul 2022 10:17:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656955062; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YiY/8owB8tnVxNDq00B9edDJ5cOHJxj+7Raw9snQ9Fg=; b=XeSB6M4Fg0msAUjk+F3IulOyWbBM4uBisAXlYcZjIgZWgFcTxWeNxPvCt55UDA5d+64SYD s6eZJMMTsxY/YIXwBY8SeIIQGelPHammbwGhk0it/qCrh3Da3RMHNPSm/xMQiL993qMZsU kzxvyv5p3U17wOCi002kBp2PpAiu5PI= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-447-OpF5weAeM5OiXLx2lnVJPQ-1; Mon, 04 Jul 2022 13:17:41 -0400 X-MC-Unique: OpF5weAeM5OiXLx2lnVJPQ-1 Received: by mail-qt1-f200.google.com with SMTP id k16-20020ac84790000000b0031d446a2d1eso4832880qtq.6 for ; Mon, 04 Jul 2022 10:17:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YiY/8owB8tnVxNDq00B9edDJ5cOHJxj+7Raw9snQ9Fg=; b=iaRmvJGsvN9qKwRYn5T9DcPd6HcIcN74z2Jm8aUVAOuIqzV2SnF4VTSQRlSxYFUibX mL68Er7n/pWxZ4ETIptiOj/sIyCr0SsB61+lGnctm60te3cHOQv31kyJzHoRbGBOWn6c XsJ2+jgRlKXTYik9P33lZgd4S5cy5yinRAh6jRsXLWndWLn3mP/Y6d8Mk2RB19tCm894 T8exzGvwsoU9IizCoR0SEJbi2JwfIRYRAx+pFeLzZrJlxgh/lRRxrOOdofDUCk/Ih+xj TJaTGYTVopWFgoK2xPaZB/cWYJGdPWqn5tpYNoKJkVnf80cJLU9ihbMIqkV6pwAuRA9d MsWg== X-Gm-Message-State: AJIora+4NSCyYvEV1QsKv53+IWxYe6PdCvPIsZqBXLu9zNZzuTCh3NfA Ww9bGgXVmlx8t8QOJRZjNbpsvqf2S6UBLEWLFlAk1x2e5uBuFVe8NsC1IjxAFqR8PP82EmIAoIE qjeW5y37T9xz8KJyp9f9LwYHo X-Received: by 2002:a05:620a:4048:b0:6af:ce0:cda8 with SMTP id i8-20020a05620a404800b006af0ce0cda8mr20623409qko.698.1656955060958; Mon, 04 Jul 2022 10:17:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tWJ/kP40tu6aNymBNyHUdElVqOxdIB+Q8MDadYWSEvofTZlOr7etlNSmUr6/ZU13avClULAw== X-Received: by 2002:a05:620a:4048:b0:6af:ce0:cda8 with SMTP id i8-20020a05620a404800b006af0ce0cda8mr20623398qko.698.1656955060705; Mon, 04 Jul 2022 10:17:40 -0700 (PDT) Received: from step1.redhat.com (host-79-46-200-206.retail.telecomitalia.it. [79.46.200.206]) by smtp.gmail.com with ESMTPSA id y7-20020a37f607000000b006a75e8d920bsm10788838qkj.88.2022.07.04.10.17.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 10:17:39 -0700 (PDT) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Jason Wang , "Michael S. Tsirkin" , linux-kernel@vger.kernel.org, =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Stefano Garzarella Subject: [RFC PATCH 5/6] virtio_test: support vhost-vdpa device Date: Mon, 4 Jul 2022 19:17:00 +0200 Message-Id: <20220704171701.127665-6-sgarzare@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220704171701.127665-1-sgarzare@redhat.com> References: <20220704171701.127665-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The new --vdpa parameter can be used to run virtio_test with the new vdpa_sim_test.ko that implements the device. The main differences with vhost_test are: - control of status register - dma map messages - VHOST_SET_MEM_TABLE not supported by vhost-vdpa - VHOST_TEST_RUN not supported by vhost-vdpa The --reset option is not supported for now when using vhost-vdpa. Signed-off-by: Stefano Garzarella --- tools/virtio/virtio_test.c | 127 +++++++++++++++++++++++++++++++------ 1 file changed, 109 insertions(+), 18 deletions(-) diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c index 2d8a3e881637..91f983266d86 100644 --- a/tools/virtio/virtio_test.c +++ b/tools/virtio/virtio_test.c @@ -44,6 +44,8 @@ struct vdev_info { void *buf; size_t buf_size; struct vhost_memory *mem; + bool vdpa; + uint64_t backend_features; }; =20 static const struct vhost_vring_file no_backend =3D { .fd =3D -1 }, @@ -64,6 +66,36 @@ void vq_callback(struct virtqueue *vq) { } =20 +static void vdpa_add_status(struct vdev_info *dev, uint8_t status) +{ + uint8_t current_status; + int r; + + r =3D ioctl(dev->control, VHOST_VDPA_GET_STATUS, ¤t_status); + assert(r >=3D 0); + current_status |=3D status; + r =3D ioctl(dev->control, VHOST_VDPA_SET_STATUS, ¤t_status); + assert(r >=3D 0); + r =3D ioctl(dev->control, VHOST_VDPA_GET_STATUS, ¤t_status); + assert(r >=3D 0); + assert((current_status & status) =3D=3D status); +} + +static void vdpa_dma_map(struct vdev_info *dev, uint64_t iova, uint64_t si= ze, + uint64_t uaddr, uint8_t perm) +{ + struct vhost_msg_v2 msg =3D {}; + int r; + + msg.type =3D VHOST_IOTLB_MSG_V2; + msg.iotlb.iova =3D iova; + msg.iotlb.size =3D size; + msg.iotlb.uaddr =3D uaddr; + msg.iotlb.perm =3D perm; + msg.iotlb.type =3D VHOST_IOTLB_UPDATE; + r =3D write(dev->control, &msg, sizeof(msg)); + assert(r =3D=3D sizeof(msg)); +} =20 void vhost_vq_setup(struct vdev_info *dev, struct vq_info *info) { @@ -76,6 +108,12 @@ void vhost_vq_setup(struct vdev_info *dev, struct vq_in= fo *info) .used_user_addr =3D (uint64_t)(unsigned long)info->vring.used, }; int r; + if (dev->vdpa) { + vdpa_dma_map(dev, (uint64_t)(unsigned long)info->ring, + vring_size(info->vring.num, 4096), + (uint64_t)(unsigned long)info->ring, + VHOST_ACCESS_RW); + } state.num =3D info->vring.num; r =3D ioctl(dev->control, VHOST_SET_VRING_NUM, &state); assert(r >=3D 0); @@ -90,6 +128,11 @@ void vhost_vq_setup(struct vdev_info *dev, struct vq_in= fo *info) file.fd =3D info->call; r =3D ioctl(dev->control, VHOST_SET_VRING_CALL, &file); assert(r >=3D 0); + if (dev->vdpa) { + state.num =3D 1; + r =3D ioctl(dev->control, VHOST_VDPA_SET_VRING_ENABLE, &state); + assert(r >=3D 0); + } } =20 static void vq_reset(struct vq_info *info, int num, struct virtio_device *= vdev) @@ -121,33 +164,61 @@ static void vq_info_add(struct vdev_info *dev, int nu= m) dev->nvqs++; } =20 -static void vdev_info_init(struct vdev_info* dev, unsigned long long featu= res) +static void vdev_info_init(struct vdev_info *dev, unsigned long long featu= res, + char *vdpa_dev) { + char *vhost_dev =3D "/dev/vhost-test"; int r; memset(dev, 0, sizeof *dev); dev->vdev.features =3D features; + if (vdpa_dev) { + dev->vdpa =3D true; + vhost_dev =3D vdpa_dev; + } INIT_LIST_HEAD(&dev->vdev.vqs); spin_lock_init(&dev->vdev.vqs_list_lock); dev->buf_size =3D 1024; dev->buf =3D malloc(dev->buf_size); assert(dev->buf); - dev->control =3D open("/dev/vhost-test", O_RDWR); + dev->control =3D open(vhost_dev, O_RDWR); assert(dev->control >=3D 0); r =3D ioctl(dev->control, VHOST_SET_OWNER, NULL); assert(r >=3D 0); - dev->mem =3D malloc(offsetof(struct vhost_memory, regions) + - sizeof dev->mem->regions[0]); - assert(dev->mem); - memset(dev->mem, 0, offsetof(struct vhost_memory, regions) + - sizeof dev->mem->regions[0]); - dev->mem->nregions =3D 1; - dev->mem->regions[0].guest_phys_addr =3D (long)dev->buf; - dev->mem->regions[0].userspace_addr =3D (long)dev->buf; - dev->mem->regions[0].memory_size =3D dev->buf_size; - r =3D ioctl(dev->control, VHOST_SET_MEM_TABLE, dev->mem); - assert(r >=3D 0); + if (!dev->vdpa) { + dev->mem =3D malloc(offsetof(struct vhost_memory, regions) + + sizeof(dev->mem->regions[0])); + assert(dev->mem); + memset(dev->mem, 0, offsetof(struct vhost_memory, regions) + + sizeof(dev->mem->regions[0])); + dev->mem->nregions =3D 1; + dev->mem->regions[0].guest_phys_addr =3D (long)dev->buf; + dev->mem->regions[0].userspace_addr =3D (long)dev->buf; + dev->mem->regions[0].memory_size =3D dev->buf_size; + r =3D ioctl(dev->control, VHOST_SET_MEM_TABLE, dev->mem); + assert(r >=3D 0); + } else { + uint8_t status =3D 0; + + r =3D ioctl(dev->control, VHOST_GET_BACKEND_FEATURES, + &dev->backend_features); + assert(r >=3D 0); + dev->backend_features &=3D 0x1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2; + assert(dev->backend_features); + r =3D ioctl(dev->control, VHOST_SET_BACKEND_FEATURES, + &dev->backend_features); + assert(r >=3D 0); + r =3D ioctl(dev->control, VHOST_VDPA_SET_STATUS, &status); + assert(r >=3D 0); + vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | + VIRTIO_CONFIG_S_DRIVER); + vdpa_dma_map(dev, (uint64_t)(unsigned long)dev->buf, + dev->buf_size, (uint64_t)(unsigned long)dev->buf, + VHOST_ACCESS_RW); + } r =3D ioctl(dev->control, VHOST_SET_FEATURES, &features); assert(r >=3D 0); + if (dev->vdpa) + vdpa_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); } =20 /* TODO: this is pretty bad: we get a cache line bounce @@ -177,8 +248,13 @@ static void run_test(struct vdev_info *dev, struct vq_= info *vq, const bool random_batch =3D batch =3D=3D RANDOM_BATCH; =20 __virtio_unbreak_device(&dev->vdev); - r =3D ioctl(dev->control, VHOST_TEST_RUN, &test); - assert(r >=3D 0); + + if (!dev->vdpa) { + r =3D ioctl(dev->control, VHOST_TEST_RUN, &test); + assert(r >=3D 0); + } else { + vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); + } if (!reset_n) { next_reset =3D INT_MAX; } @@ -268,8 +344,10 @@ static void run_test(struct vdev_info *dev, struct vq_= info *vq, } } test =3D 0; - r =3D ioctl(dev->control, VHOST_TEST_RUN, &test); - assert(r >=3D 0); + if (!dev->vdpa) { + r =3D ioctl(dev->control, VHOST_TEST_RUN, &test); + assert(r >=3D 0); + } fprintf(stderr, "spurious wakeups: 0x%llx started=3D0x%lx completed=3D0x%lx\n", spurious, started, completed); @@ -323,6 +401,11 @@ const struct option longopts[] =3D { .val =3D 'r', .has_arg =3D optional_argument, }, + { + .name =3D "vdpa", + .val =3D 'V', + .has_arg =3D required_argument, + }, { } }; @@ -336,6 +419,7 @@ static void help(void) " [--delayed-interrupt]" " [--batch=3Drandom/N]" " [--reset=3DN]" + " [--vdpa=3D/dev/vhost-vdpa-N]" "\n"); } =20 @@ -347,6 +431,7 @@ int main(int argc, char **argv) long batch =3D 1, reset =3D 0; int o; bool delayed =3D false; + char *vdpa_dev =3D NULL; =20 for (;;) { o =3D getopt_long(argc, argv, optstring, longopts, NULL); @@ -389,6 +474,10 @@ int main(int argc, char **argv) assert(reset < (long)INT_MAX + 1); } break; + case 'V': + vdpa_dev =3D optarg; + features |=3D 1ULL << VIRTIO_F_ACCESS_PLATFORM; + break; default: assert(0); break; @@ -396,7 +485,9 @@ int main(int argc, char **argv) } =20 done: - vdev_info_init(&dev, features); + //TODO: support reset for vdpa + assert(vdpa_dev && !reset); + vdev_info_init(&dev, features, vdpa_dev); vq_info_add(&dev, 256); run_test(&dev, &dev.vqs[0], delayed, batch, reset, 0x100000); return 0; --=20 2.36.1 From nobody Sun Apr 26 10:52:55 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B2F0C43334 for ; Mon, 4 Jul 2022 17:17:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233752AbiGDRR5 (ORCPT ); Mon, 4 Jul 2022 13:17:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232511AbiGDRRr (ORCPT ); Mon, 4 Jul 2022 13:17:47 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 29B90E030 for ; Mon, 4 Jul 2022 10:17:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656955065; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3nCsnklBQ1UFm+gqm+qDZbbdiHHfrXIDqEIncE//uIk=; b=iJ2S7DijcJo0hLMndwCkOtavKYM4mWlhFJPlvfjftmO8y8uUpznD57JEHZ/jdaPi2aFiuk 3/vF7BX1ZbxY2UeA2dED6Z/OBsffQmSAW7UISk4oagla4UOgUYRyuvx4UjBXOInkvXjeYT YVDa6oC3SYuF2FKBQqgK5Eqssv10I+s= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-617-IoNL84AAPmehhhwEzGuCKg-1; Mon, 04 Jul 2022 13:17:44 -0400 X-MC-Unique: IoNL84AAPmehhhwEzGuCKg-1 Received: by mail-qt1-f199.google.com with SMTP id cf8-20020a05622a400800b0031e80dcf14cso784437qtb.3 for ; Mon, 04 Jul 2022 10:17:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3nCsnklBQ1UFm+gqm+qDZbbdiHHfrXIDqEIncE//uIk=; b=Aysg++84MUQk82LBn0yuLtWTXC2LyqopmyN48h1NlEOeqogrAN3C1ORUCCsDIZwFPD Khev+E0y41zjomgLIzquqRX0RMBUhCFrVNcdVJ0qekoBMKshr+9EYgcdA9CB7qLRl3h1 NAEubU3Mpm1qKz820VYNhAXBtchANb/RUyXEt2I7PhB0FmnmoZkexqfqZP4/ReNBnIct 0B0q1qLpbwuv5OpTbo9sZra/LBQ3Bxb4+K0apaLUrWX8TvN3rYQqo+Ez0XCF+md0TFSr c7b6ioj7le4MFkKig9nbdULcWdAiaz7CWoF/Bn5ZrWfPlgsRnEeZGcUfRZjoPVcESQd/ rU5Q== X-Gm-Message-State: AJIora8ra/qAwfF0zPgYJ+4ZApGiqlyZ7vhGujwwvqpkA5rna+ci4cgR zYrR5qTxvEruRVvg0yP8MqGuXG2YnAAwV9hOvPmbbJgEWl8ms+jaNKLqP8kKJkTPLF6AllHb3iC rkwsZv/mVCq1XYvx9zxE6/4iz X-Received: by 2002:ad4:5ba8:0:b0:470:b3e3:c26c with SMTP id 8-20020ad45ba8000000b00470b3e3c26cmr28170977qvq.100.1656955063483; Mon, 04 Jul 2022 10:17:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vxa67c+kgQJXWIOpjBNWGDvw6ASPjM/9BByyML3sl34yEuM27wxzml2seWDnyfhSMzT5UPKQ== X-Received: by 2002:ad4:5ba8:0:b0:470:b3e3:c26c with SMTP id 8-20020ad45ba8000000b00470b3e3c26cmr28170958qvq.100.1656955063179; Mon, 04 Jul 2022 10:17:43 -0700 (PDT) Received: from step1.redhat.com (host-79-46-200-206.retail.telecomitalia.it. [79.46.200.206]) by smtp.gmail.com with ESMTPSA id y7-20020a37f607000000b006a75e8d920bsm10788838qkj.88.2022.07.04.10.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 10:17:42 -0700 (PDT) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Jason Wang , "Michael S. Tsirkin" , linux-kernel@vger.kernel.org, =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Stefano Garzarella Subject: [RFC PATCH 6/6] vdpasim: add vdpa_sim_test module Date: Mon, 4 Jul 2022 19:17:01 +0200 Message-Id: <20220704171701.127665-7-sgarzare@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220704171701.127665-1-sgarzare@redhat.com> References: <20220704171701.127665-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This adds a test module for vhost-vdpa infrastructure to be used with virtio_test. Intentionally not tied to kbuild to prevent people from installing and loading it accidentally. Signed-off-by: Stefano Garzarella --- drivers/vdpa/vdpa_sim/vdpa_sim_test.c | 203 ++++++++++++++++++++++++++ tools/virtio/vdpa_test/vdpa_test.c | 1 + tools/virtio/Makefile | 32 +++- tools/virtio/vdpa_test/Makefile | 3 + 4 files changed, 234 insertions(+), 5 deletions(-) create mode 100644 drivers/vdpa/vdpa_sim/vdpa_sim_test.c create mode 100644 tools/virtio/vdpa_test/vdpa_test.c create mode 100644 tools/virtio/vdpa_test/Makefile diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_test.c b/drivers/vdpa/vdpa_sim/= vdpa_sim_test.c new file mode 100644 index 000000000000..17628b1a1cdd --- /dev/null +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_test.c @@ -0,0 +1,203 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * VDPA simulator for virtio-test. + * + * Copyright (c) 2022, Red Hat Inc. All rights reserved. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "vdpa_sim.h" + +#define DRV_VERSION "0.1" +#define DRV_AUTHOR "Stefano Garzarella " +#define DRV_DESC "vDPA Device Simulator for virtio-test device" +#define DRV_LICENSE "GPL v2" + +#define VDPASIM_TEST_FEATURES (VDPASIM_FEATURES) +#define VDPASIM_TEST_VIRTIO_ID 0 + +/* 1 virtqueues, 1 address spaces, 1 virtqueue groups */ +#define VDPASIM_TEST_VQ_NUM 1 +#define VDPASIM_TEST_AS_NUM 1 +#define VDPASIM_TEST_GROUP_NUM 1 + +static bool vdpasim_test_handle_req(struct vdpasim *vdpasim, + struct vdpasim_virtqueue *vq) +{ + int ret; + + ret =3D vringh_getdesc_iotlb(&vq->vring, &vq->out_iov, &vq->in_iov, + &vq->head, GFP_ATOMIC); + if (ret !=3D 1) + return false; + + if (vq->out_iov.used =3D=3D 0 || vq->in_iov.used > 0) { + dev_dbg(&vdpasim->vdpa.dev, "Unexpected descriptor format - out_iov: %u = in_iov %u\n", + vq->out_iov.used, vq->in_iov.used); + return false; + } + + if (vringh_kiov_length(&vq->out_iov) =3D=3D 0) { + dev_dbg(&vdpasim->vdpa.dev, "Unexpected 0 len for out buffer\n"); + return false; + } + + vringh_complete_iotlb(&vq->vring, vq->head, 0); + + return true; +} + +static void vdpasim_test_work(struct work_struct *work) +{ + struct vdpasim *vdpasim =3D container_of(work, struct vdpasim, work); + bool reschedule =3D false; + int i; + + spin_lock(&vdpasim->lock); + + if (!(vdpasim->status & VIRTIO_CONFIG_S_DRIVER_OK)) + goto out; + + for (i =3D 0; i < VDPASIM_TEST_VQ_NUM; i++) { + struct vdpasim_virtqueue *vq =3D &vdpasim->vqs[i]; + int reqs =3D 0; + + if (!vq->ready) + continue; + + while (vdpasim_test_handle_req(vdpasim, vq)) { + /* Make sure used is visible before rasing the interrupt. */ + smp_wmb(); + + local_bh_disable(); + if (vringh_need_notify_iotlb(&vq->vring) > 0) + vringh_notify(&vq->vring); + local_bh_enable(); + + if (++reqs > 4) { + reschedule =3D true; + break; + } + } + } +out: + spin_unlock(&vdpasim->lock); + + if (reschedule) + schedule_work(&vdpasim->work); +} + +static void vdpasim_test_get_config(struct vdpasim *vdpasim, void *config) +{ + u64 *test_config =3D config; + + *test_config =3D cpu_to_vdpasim64(vdpasim, 42); +} + +static void vdpasim_test_mgmtdev_release(struct device *dev) +{ +} + +static struct device vdpasim_test_mgmtdev =3D { + .init_name =3D "vdpasim_test", + .release =3D vdpasim_test_mgmtdev_release, +}; + +static int vdpasim_test_dev_add(struct vdpa_mgmt_dev *mdev, const char *na= me, + const struct vdpa_dev_set_config *config) +{ + struct vdpasim_dev_attr dev_attr =3D {}; + struct vdpasim *simdev; + int ret; + + dev_attr.mgmt_dev =3D mdev; + dev_attr.name =3D name; + dev_attr.id =3D VDPASIM_TEST_VIRTIO_ID; + dev_attr.supported_features =3D VDPASIM_TEST_FEATURES; + dev_attr.nvqs =3D VDPASIM_TEST_VQ_NUM; + dev_attr.ngroups =3D VDPASIM_TEST_GROUP_NUM; + dev_attr.nas =3D VDPASIM_TEST_AS_NUM; + dev_attr.config_size =3D sizeof(uint64_t); + dev_attr.get_config =3D vdpasim_test_get_config; + dev_attr.work_fn =3D vdpasim_test_work; + dev_attr.buffer_size =3D 0; + + simdev =3D vdpasim_create(&dev_attr); + if (IS_ERR(simdev)) + return PTR_ERR(simdev); + + ret =3D _vdpa_register_device(&simdev->vdpa, VDPASIM_TEST_VQ_NUM); + if (ret) + goto put_dev; + + return 0; + +put_dev: + put_device(&simdev->vdpa.dev); + return ret; +} + +static void vdpasim_test_dev_del(struct vdpa_mgmt_dev *mdev, + struct vdpa_device *dev) +{ + struct vdpasim *simdev =3D container_of(dev, struct vdpasim, vdpa); + + _vdpa_unregister_device(&simdev->vdpa); +} + +static const struct vdpa_mgmtdev_ops vdpasim_test_mgmtdev_ops =3D { + .dev_add =3D vdpasim_test_dev_add, + .dev_del =3D vdpasim_test_dev_del +}; + +static struct virtio_device_id id_table[] =3D { + { VDPASIM_TEST_VIRTIO_ID, VIRTIO_DEV_ANY_ID }, + { 0 }, +}; + +static struct vdpa_mgmt_dev mgmt_dev =3D { + .device =3D &vdpasim_test_mgmtdev, + .id_table =3D id_table, + .ops =3D &vdpasim_test_mgmtdev_ops, +}; + +static int __init vdpasim_test_init(void) +{ + int ret; + + ret =3D device_register(&vdpasim_test_mgmtdev); + if (ret) + return ret; + + ret =3D vdpa_mgmtdev_register(&mgmt_dev); + if (ret) + goto parent_err; + + return 0; + +parent_err: + device_unregister(&vdpasim_test_mgmtdev); + return ret; +} + +static void __exit vdpasim_test_exit(void) +{ + vdpa_mgmtdev_unregister(&mgmt_dev); + device_unregister(&vdpasim_test_mgmtdev); +} + +module_init(vdpasim_test_init) +module_exit(vdpasim_test_exit) + +MODULE_VERSION(DRV_VERSION); +MODULE_LICENSE(DRV_LICENSE); +MODULE_AUTHOR(DRV_AUTHOR); +MODULE_DESCRIPTION(DRV_DESC); diff --git a/tools/virtio/vdpa_test/vdpa_test.c b/tools/virtio/vdpa_test/vd= pa_test.c new file mode 100644 index 000000000000..779d2be2c9e5 --- /dev/null +++ b/tools/virtio/vdpa_test/vdpa_test.c @@ -0,0 +1 @@ +#include "vdpa_sim/vdpa_sim_test.c" diff --git a/tools/virtio/Makefile b/tools/virtio/Makefile index 1b25cc7c64bb..74a3e8d649a3 100644 --- a/tools/virtio/Makefile +++ b/tools/virtio/Makefile @@ -10,6 +10,7 @@ LDFLAGS +=3D -pthread vpath %.c ../../drivers/virtio ../../drivers/vhost mod: ${MAKE} -C `pwd`/../.. M=3D`pwd`/vhost_test V=3D${V} + ${MAKE} -C `pwd`/../.. M=3D`pwd`/vdpa_test V=3D${V} =20 #oot: build vhost as an out of tree module for a distro kernel #no effort is taken to make it actually build or work, but tends to mostly= work @@ -18,26 +19,47 @@ mod: #resulting modules in production! OOT_KSRC=3D/lib/modules/$$(uname -r)/build OOT_VHOST=3D`pwd`/../../drivers/vhost +OOT_VDPA=3D`pwd`/../../drivers/vdpa #Everyone depends on vhost #Tweak the below to enable more modules OOT_CONFIGS=3D\ CONFIG_VHOST=3Dm \ + CONFIG_VHOST_VDPA=3Dm \ CONFIG_VHOST_NET=3Dn \ CONFIG_VHOST_SCSI=3Dn \ CONFIG_VHOST_VSOCK=3Dn \ CONFIG_VHOST_RING=3Dn -OOT_BUILD=3DKCFLAGS=3D"-I "${OOT_VHOST} ${MAKE} -C ${OOT_KSRC} V=3D${V} +OOT_VDPA_CONFIGS=3D\ + CONFIG_VDPA=3Dm \ + CONFIG_VDPA_SIM=3Dm \ + CONFIG_VDPA_SIM_NET=3Dn \ + CONFIG_VDPA_SIM_BLOCK=3Dn \ + CONFIG_VDPA_USER=3Dn \ + CONFIG_MLX5_VDPA=3Dn \ + CONFIG_MLX5_VDPA_NET=3Dn \ + CONFIG_IFCVF=3Dn \ + CONFIG_VP_VDPA=3Dn \ + CONFIG_ALIBABA_ENI_VDPA=3Dn +OOT_BUILD=3DKCFLAGS=3D"-I "${OOT_VHOST}" -I "${OOT_VDPA} ${MAKE} -C ${OOT= _KSRC} V=3D${V} oot-build: echo "UNSUPPORTED! Don't use the resulting modules in production!" ${OOT_BUILD} M=3D`pwd`/vhost_test ${OOT_BUILD} M=3D${OOT_VHOST} ${OOT_CONFIGS} =20 -oot-clean: oot-build -oot: oot-build +oot-vdpa-build: oot-build + echo "UNSUPPORTED! Don't use the resulting modules in production!" + ${OOT_BUILD} M=3D`pwd`/vdpa_test + ${OOT_BUILD} M=3D${OOT_VDPA} ${OOT_VDPA_CONFIGS} + +oot-clean: oot +oot: oot-build oot-vdpa-build oot-clean: OOT_BUILD+=3Dclean =20 -.PHONY: all test mod clean vhost oot oot-clean oot-build -clean: +.PHONY: all test mod clean vhost oot oot-clean oot-build oot-vdpa-build cl= ean-vdpa +clean-vdpa: + ${RM} vdpa_test/*.o vdpa_test/.*.cmd vdpa_test/Module.symvers \ + vdpa_test/modules.order +clean: clean-vdpa ${RM} *.o vringh_test virtio_test vhost_test/*.o vhost_test/.*.cmd \ vhost_test/Module.symvers vhost_test/modules.order *.d -include *.d diff --git a/tools/virtio/vdpa_test/Makefile b/tools/virtio/vdpa_test/Makef= ile new file mode 100644 index 000000000000..fce9f344d88f --- /dev/null +++ b/tools/virtio/vdpa_test/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-m +=3D vdpa_test.o +ccflags-y +=3D -I$(srctree)/drivers/vdpa/ --=20 2.36.1