Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3637998rdg; Wed, 18 Oct 2023 01:07:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUL5sQ3o6cs5DWgL+QJ8Per/BbeePMIIb2NOmdrf0z9qZmnLvnBC3sVEYOogr8mCBIf5BE X-Received: by 2002:a17:90b:a50:b0:27d:492e:137a with SMTP id gw16-20020a17090b0a5000b0027d492e137amr4390714pjb.45.1697616426530; Wed, 18 Oct 2023 01:07:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697616426; cv=none; d=google.com; s=arc-20160816; b=xZ0G8KvQEaC9T3fgE96/VEOkev3Zwl/uq6dBPc8Tl76Vw7oueAMFUOFRuDDHnhL0oG 5tYL1265Wbm0yKKkUwgGEX36GK9Y4UKlM3fpXa4frrab2904vYUSUgDy6lbVAUbiSieM gP4/UdWieKi+2hFeJ6MJ72SPAVM6Sya64oaXogWRCMo/QLuWkHCnxwUq6JnBP64OPIxi sGm4jpYzH6jiTeBXyC9vIkGJN6jMR4q8LieoqzKBVhrw0YkAz5UO6Wjeo5pk6u8oXZEc lfQqq0cI3o2G1TMcGGHmHmQI77HRANaPK1JZWnTf1TrwldeINONRR4Cr3poelXBdBwbU Jvqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=oo2WWDvelf9ZpXmn8Aak1z8e708XX+d9Qhv4aD4RB10=; fh=nZr8jwE7mvRQHW1IgZyedhww570Sw5JPrhq+XqmzccI=; b=bLqPOtYHhQVb3HFdiXfvw71w0NfO+a63rYkbHyWTdOjuASBrM+aoxAGRl0auq+YAC8 o35U7DUKWqY7XKt7HKNX2Qy/2w0IcJLyZGI45CSGJ/LXmRTDS6HqV/poQEboF+m/CWR4 E5wQFmoydPPUQQVfvwZRWb69/OiB8IGSmQYA04A4n2pFwiwt3zkOCXVksQndHfYV/57L ZGB485CdfFL3i1B9ZPIdptFGjG1entSY1muf9SrvIy764SQtNDGqw2/U535GEEsPY/Om EziqJ//47sp5YCz71d3/mUVBNEIsy8S0QWPRDGS7jflU21UzlFjP06z5KGIq2qWQeWTS qRmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ip0Vsnil; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id oj4-20020a17090b4d8400b0026b043c8bbesi1072724pjb.136.2023.10.18.01.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 01:07:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ip0Vsnil; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id DDB958096FF8; Wed, 18 Oct 2023 01:06:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235118AbjJRIFx (ORCPT + 99 others); Wed, 18 Oct 2023 04:05:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235109AbjJRIFu (ORCPT ); Wed, 18 Oct 2023 04:05:50 -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 ESMTPS id F24CCBC for ; Wed, 18 Oct 2023 01:05:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697616310; 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: in-reply-to:in-reply-to:references:references; bh=oo2WWDvelf9ZpXmn8Aak1z8e708XX+d9Qhv4aD4RB10=; b=Ip0VsnilP6S92U+DK05kGSdvVAf5bPIYvD2dY6GlmS5aw1OyJa1b+uquieK3mCB27cEdrq qsL1AeP8nksIip4E0XlYJkmoaYxKxqDHMbu52TAvERVf98b2Vf2mZJcP5OAUDwIMWQ20rM 32331CfCtmVekuFP5TnYtTGE0Xfrmpk= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-8p7-bxkFOL6ZOxEsUNaOxQ-1; Wed, 18 Oct 2023 04:05:08 -0400 X-MC-Unique: 8p7-bxkFOL6ZOxEsUNaOxQ-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-53da5262466so5028872a12.0 for ; Wed, 18 Oct 2023 01:05:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697616307; x=1698221107; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=oo2WWDvelf9ZpXmn8Aak1z8e708XX+d9Qhv4aD4RB10=; b=tUNzXkSWEzUa3a6ZqRFr1Bh/S4gMNIMrUrN2qJ+3xwlTtfaiac2P7ddOs2GkwhMXZj 7W2IuBOGsZQ9tn6b42BhffACKGCfEhaLAsxVz5sOUTr67Sej4s48599e3IOLzkpY3xSx yqhXO1mOlPoomx8rLCwTCVz5QP5UNjzhdcWk7Ng/VVZIeFxAxVzPsx3tEKFnEtzzQJeD N5xS+4hWFI/laF4mjBTCyHnwSrzk3aEys/ImP1Rnu3jFXUkUWknN63Je6CFtlYh/TKxk T2fbWY0likyYQxyb2POKtvi9pxkkJe9EFHmTIlSWz7WX1IoztNZVKLC9UO/fwZ3dtoL2 u1iQ== X-Gm-Message-State: AOJu0Yxysom9W1/yWvsthI7Dqv/eieTdnySr57lbW1qmDZ/6gxIuctyO li3XkQU9B5396d83zPlFA4HeFbuV0D0VjrWDX2JWK+ydXx4Igb9Cm3m5nwdtElLKpUoyjrXcDTm ynnf9aTLB9hzNU1Vk05/y62RN X-Received: by 2002:a50:8e58:0:b0:53e:72be:2b31 with SMTP id 24-20020a508e58000000b0053e72be2b31mr2999942edx.42.1697616307573; Wed, 18 Oct 2023 01:05:07 -0700 (PDT) X-Received: by 2002:a50:8e58:0:b0:53e:72be:2b31 with SMTP id 24-20020a508e58000000b0053e72be2b31mr2999928edx.42.1697616307174; Wed, 18 Oct 2023 01:05:07 -0700 (PDT) Received: from sgarzare-redhat (host-87-12-185-56.business.telecomitalia.it. [87.12.185.56]) by smtp.gmail.com with ESMTPSA id f19-20020a50d553000000b0053f0e4e0411sm2449088edj.76.2023.10.18.01.05.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 01:05:06 -0700 (PDT) Date: Wed, 18 Oct 2023 10:05:02 +0200 From: Stefano Garzarella To: Si-Wei Liu Cc: jasowang@redhat.com, mst@redhat.com, eperezma@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [RFC v2 PATCH] vdpa_sim: implement .reset_map support Message-ID: References: <1697605893-30313-1-git-send-email-si-wei.liu@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <1697605893-30313-1-git-send-email-si-wei.liu@oracle.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 18 Oct 2023 01:06:05 -0700 (PDT) On Tue, Oct 17, 2023 at 10:11:33PM -0700, Si-Wei Liu wrote: >RFC only. Not tested on vdpa-sim-blk with user virtual address. >Works fine with vdpa-sim-net which uses physical address to map. > >This patch is based on top of [1]. > >[1] https://lore.kernel.org/virtualization/1696928580-7520-1-git-send-email-si-wei.liu@oracle.com/ > >Signed-off-by: Si-Wei Liu > >--- >RFC v2: > - initialize iotlb to passthrough mode in device add I tested this version and I didn't see any issue ;-) Tested-by: Stefano Garzarella >--- > drivers/vdpa/vdpa_sim/vdpa_sim.c | 34 ++++++++++++++++++++++++-------- > 1 file changed, 26 insertions(+), 8 deletions(-) > >diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c >index 76d41058add9..2a0a6042d61d 100644 >--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c >+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c >@@ -151,13 +151,6 @@ static void vdpasim_do_reset(struct vdpasim *vdpasim) > &vdpasim->iommu_lock); > } > >- for (i = 0; i < vdpasim->dev_attr.nas; i++) { >- vhost_iotlb_reset(&vdpasim->iommu[i]); >- vhost_iotlb_add_range(&vdpasim->iommu[i], 0, ULONG_MAX, >- 0, VHOST_MAP_RW); >- vdpasim->iommu_pt[i] = true; >- } >- > vdpasim->running = true; > spin_unlock(&vdpasim->iommu_lock); > >@@ -259,8 +252,12 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr, > if (!vdpasim->iommu_pt) > goto err_iommu; > >- for (i = 0; i < vdpasim->dev_attr.nas; i++) >+ for (i = 0; i < vdpasim->dev_attr.nas; i++) { > vhost_iotlb_init(&vdpasim->iommu[i], max_iotlb_entries, 0); >+ vhost_iotlb_add_range(&vdpasim->iommu[i], 0, ULONG_MAX, 0, >+ VHOST_MAP_RW); >+ vdpasim->iommu_pt[i] = true; >+ } > > for (i = 0; i < dev_attr->nvqs; i++) > vringh_set_iotlb(&vdpasim->vqs[i].vring, &vdpasim->iommu[0], >@@ -637,6 +634,25 @@ static int vdpasim_set_map(struct vdpa_device *vdpa, unsigned int asid, > return ret; > } > >+static int vdpasim_reset_map(struct vdpa_device *vdpa, unsigned int asid) >+{ >+ struct vdpasim *vdpasim = vdpa_to_sim(vdpa); >+ >+ if (asid >= vdpasim->dev_attr.nas) >+ return -EINVAL; >+ >+ spin_lock(&vdpasim->iommu_lock); >+ if (vdpasim->iommu_pt[asid]) >+ goto out; >+ vhost_iotlb_reset(&vdpasim->iommu[asid]); >+ vhost_iotlb_add_range(&vdpasim->iommu[asid], 0, ULONG_MAX, >+ 0, VHOST_MAP_RW); >+ vdpasim->iommu_pt[asid] = true; >+out: >+ spin_unlock(&vdpasim->iommu_lock); >+ return 0; >+} >+ > static int vdpasim_bind_mm(struct vdpa_device *vdpa, struct mm_struct *mm) > { > struct vdpasim *vdpasim = vdpa_to_sim(vdpa); >@@ -759,6 +775,7 @@ static const struct vdpa_config_ops vdpasim_config_ops = { > .set_group_asid = vdpasim_set_group_asid, > .dma_map = vdpasim_dma_map, > .dma_unmap = vdpasim_dma_unmap, >+ .reset_map = vdpasim_reset_map, > .bind_mm = vdpasim_bind_mm, > .unbind_mm = vdpasim_unbind_mm, > .free = vdpasim_free, >@@ -796,6 +813,7 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = { > .get_iova_range = vdpasim_get_iova_range, > .set_group_asid = vdpasim_set_group_asid, > .set_map = vdpasim_set_map, >+ .reset_map = vdpasim_reset_map, > .bind_mm = vdpasim_bind_mm, > .unbind_mm = vdpasim_unbind_mm, > .free = vdpasim_free, >-- >2.39.3 >