From nobody Mon Feb 9 16:18:41 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599475809; cv=none; d=zohomail.com; s=zohoarc; b=KgC1WUbOuCExguPOC+Gc+Xv3sx0YGx9JPvQ6QN9iHTOynY7SjJg1ttF/0MEjPyYr47VsvN0yyfodbe2OPO1VXm8TtT9dB26YDRyjCDE+Vtd6BJzgSuml0d2bsQvxfV5m/MT92hrZagGX9t9W+CYxJ0+iaGnYVyhl4AdpjUXP7yA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599475809; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BvulEHqay9wA5dsX54rFHJ+xBQUVLlTyV6TCxPMHgz4=; b=Z4ZfoseSMs7Cjxa/z/couD46Pn57s404OjmRR7VjwVZGKrGs7Ci/GX9bUMte1fO+PsjbmXUaLD4Ob4P16+43NOK2egTztm7t5Nhyu1scDsuEZGvNwOvDcx0qiwUjPVOpcgvMUpj4bS1CDtFvKwQsHKXfZBe91Ea1aNSTwh2jcaA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1599475809407723.1610533690458; Mon, 7 Sep 2020 03:50:09 -0700 (PDT) Received: from localhost ([::1]:37840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kFEit-0001ub-Uz for importer@patchew.org; Mon, 07 Sep 2020 06:50:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54212) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFEiD-00014H-4A for qemu-devel@nongnu.org; Mon, 07 Sep 2020 06:49:25 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:57020 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kFEiB-0005Za-C5 for qemu-devel@nongnu.org; Mon, 07 Sep 2020 06:49:24 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-477-8tb6Vb7UO6imPWlqSq0zmQ-1; Mon, 07 Sep 2020 06:49:20 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CC9DA1007466; Mon, 7 Sep 2020 10:49:19 +0000 (UTC) Received: from jason-ThinkPad-X1-Carbon-6th.redhat.com (ovpn-12-108.pek2.redhat.com [10.72.12.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2CF910013C4; Mon, 7 Sep 2020 10:49:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599475762; 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=BvulEHqay9wA5dsX54rFHJ+xBQUVLlTyV6TCxPMHgz4=; b=Azqu/qlRCw7XcgKyPXHSPAOTCOCFNZK6Y9jnu8gU1Xt3im3/IkCFsopjVvDlEcrQtobHuq bgzhOkwwQrdiui3aiz64CFAR4HRS/hTMTSiWXWx/YK3QhF6O+XJ6h6Tvcq+HsrG35rjmcH hlpTaTgZQVnXb6JWGe6ufkEfX2ldYNg= X-MC-Unique: 8tb6Vb7UO6imPWlqSq0zmQ-1 From: Jason Wang To: mst@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 3/3] vhost-vdpa: batch updating IOTLB mappings Date: Mon, 7 Sep 2020 18:49:03 +0800 Message-Id: <20200907104903.31551-4-jasowang@redhat.com> In-Reply-To: <20200907104903.31551-1-jasowang@redhat.com> References: <20200907104903.31551-1-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.81; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/06 22:29:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elic@nvidia.com, Jason Wang , lulu@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" To speed up the memory mapping updating between vhost-vDPA and vDPA device driver, this patch passes the IOTLB batching flags via IOTLB API. Two new flags was introduced, VHOST_IOTLB_BATCH_BEGIN is a hint that a bathced IOTLB updating may be initiated from the userspace. VHOST_IOTLB_BATCH_END is a hint that userspace has finished the updating: VHOST_IOTLB_BATCH_BEGIN VHOST_IOTLB_UPDATE/VHOST_IOTLB_INVALIDATE ... VHOST_IOTLB_BATCH_END Vhost-vDPA can then know that all mappings has been set and can do optimization like passing all the mappings to the vDPA device driver. Signed-off-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 66 ++++++++++++++++++++++++++++++++++ include/hw/virtio/vhost-vdpa.h | 1 + 2 files changed, 67 insertions(+) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 4580f3efd8..ba1ae3ea44 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -78,6 +78,46 @@ static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hw= addr iova, return ret; } =20 +static void vhost_vdpa_listener_begin(MemoryListener *listener) +{ + struct vhost_vdpa *v =3D container_of(listener, struct vhost_vdpa, lis= tener); + struct vhost_dev *dev =3D v->dev; + struct vhost_msg_v2 msg; + int fd =3D v->device_fd; + + if (!(dev->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH))) { + return; + } + + msg.type =3D v->msg_type; + msg.iotlb.type =3D VHOST_IOTLB_BATCH_BEGIN; + + if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { + error_report("failed to write, fd=3D%d, errno=3D%d (%s)", + fd, errno, strerror(errno)); + } +} + +static void vhost_vdpa_listener_commit(MemoryListener *listener) +{ + struct vhost_vdpa *v =3D container_of(listener, struct vhost_vdpa, lis= tener); + struct vhost_dev *dev =3D v->dev; + struct vhost_msg_v2 msg; + int fd =3D v->device_fd; + + if (!(dev->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH))) { + return; + } + + msg.type =3D v->msg_type; + msg.iotlb.type =3D VHOST_IOTLB_BATCH_END; + + if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { + error_report("failed to write, fd=3D%d, errno=3D%d (%s)", + fd, errno, strerror(errno)); + } +} + static void vhost_vdpa_listener_region_add(MemoryListener *listener, MemoryRegionSection *section) { @@ -191,6 +231,8 @@ static void vhost_vdpa_listener_region_del(MemoryListen= er *listener, * depends on the addnop(). */ static const MemoryListener vhost_vdpa_memory_listener =3D { + .begin =3D vhost_vdpa_listener_begin, + .commit =3D vhost_vdpa_listener_commit, .region_add =3D vhost_vdpa_listener_region_add, .region_del =3D vhost_vdpa_listener_region_del, }; @@ -226,6 +268,7 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void = *opaque) assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); =20 v =3D opaque; + v->dev =3D dev; dev->opaque =3D opaque ; vhost_vdpa_call(dev, VHOST_GET_FEATURES, &features); dev->backend_features =3D features; @@ -280,6 +323,28 @@ static int vhost_vdpa_set_features(struct vhost_dev *d= ev, return !(status & VIRTIO_CONFIG_S_FEATURES_OK); } =20 +static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev) +{ + uint64_t features; + uint64_t f =3D 0x1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2 | + 0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH; + int r; + + if (vhost_vdpa_call(dev, VHOST_GET_BACKEND_FEATURES, &features)) { + return 0; + } + + features &=3D f; + r =3D vhost_vdpa_call(dev, VHOST_SET_BACKEND_FEATURES, &features); + if (r) { + return 0; + } + + dev->backend_cap =3D features; + + return 0; +} + int vhost_vdpa_get_device_id(struct vhost_dev *dev, uint32_t *device_id) { @@ -452,6 +517,7 @@ const VhostOps vdpa_ops =3D { .vhost_set_vring_kick =3D vhost_vdpa_set_vring_kick, .vhost_set_vring_call =3D vhost_vdpa_set_vring_call, .vhost_get_features =3D vhost_vdpa_get_features, + .vhost_set_backend_cap =3D vhost_vdpa_set_backend_cap, .vhost_set_owner =3D vhost_vdpa_set_owner, .vhost_set_vring_endian =3D NULL, .vhost_backend_memslots_limit =3D vhost_vdpa_memslots_limit, diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 6455663388..9b81a409da 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -18,6 +18,7 @@ typedef struct vhost_vdpa { int device_fd; uint32_t msg_type; MemoryListener listener; + struct vhost_dev *dev; } VhostVDPA; =20 extern AddressSpace address_space_memory; --=20 2.20.1