Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1039281pxa; Wed, 5 Aug 2020 20:30:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNgN3Z1lXrWWFlEcQn8UpD1r9wCUWFh+fc0VGwgZKX9VGUWGkl1+K7b22WZcITRkrJRUtp X-Received: by 2002:a50:8f44:: with SMTP id 62mr2262190edy.3.1596684610076; Wed, 05 Aug 2020 20:30:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596684610; cv=none; d=google.com; s=arc-20160816; b=ZUbBHRgJgh6EfqfAhZvmC2jW+VJfFVpgUv2Vn5B1PCjT94SxHrQR5fe5nE2N+fk+ml 6dEyQN6ZNXUK8MbaaLPVogEpDJ+hk+Pxa0Z+14kzoHBhMjMkloUUUlLr23u5hkxQvJ6r QJKdqmowNp7tT8a4DzxRHHZatSWvaLClpXC5u2Awwqc3GyvpQStJuXhTXwHCgR69CmwG 1ZIlSqrUWDZIys3eNEO9v+PkDh9ErGjaZPweMgFBjwMddXzbFRmbdcoscnrOjioVcpKa Mmc2a+OIlUXltzYguSelDDuZO581zyIY+0SWV3yy5wYRB20GRLVTtMD3aJG2nPE5hUUI v6Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=gqqusaMY5nwkPoft2J2o8MkWdw785dqs4rwmV+X8bIM=; b=WlBTAY23LMpo1nqmHyblRbdQ2hEpliIWOqM+5itoxvIEe0Alr0VPJcBjDU4KHd/PiV rMKGDcqhsd7WB0LHqiijIKIr2IXk6h9BoabH/8SMvpPbXpvgrGh724F+M5F1HBXSZtnQ PRtZ5jlLBVtsEFPp5tu3OJMGnY3J4+FQUisfDhStcbiyQhaxLjqG8gRlO10cgeCu/Cvd aFypvwas9lbGMn/5mt6M6sMoQb02OvsMYeOdh5OZjhrt8hEbkS038acuefhLj4bqJPeK fxkf4Er4ccB48T1qbDA1adcTlkbEZMx8YYPWbMk229UEcI5b37YBYDxt2C7hJYcTtbBs JWVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DaWaIBK0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oy1si1936553ejb.733.2020.08.05.20.29.47; Wed, 05 Aug 2020 20:30:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DaWaIBK0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730797AbgHFD3f (ORCPT + 99 others); Wed, 5 Aug 2020 23:29:35 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:24046 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730784AbgHFD3d (ORCPT ); Wed, 5 Aug 2020 23:29:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596684570; 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=gqqusaMY5nwkPoft2J2o8MkWdw785dqs4rwmV+X8bIM=; b=DaWaIBK0tzvHWThdfVm7QeobMmvyqephQ0+4hQWZO1B0f79YMi76oDQG3iJOo4NxjTuVTt r59GHVGToVhAV7OfUdH9O34omCL74/aQGTG6tMUB/7uljN5Y9McvNiYFwu/jgvw1fck8G6 yiqB6tpRczhTZY3VcIyKs5Aaa7QwodA= 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-248-Tki8dWVcPCurLaGHCQ6RVA-1; Wed, 05 Aug 2020 23:29:28 -0400 X-MC-Unique: Tki8dWVcPCurLaGHCQ6RVA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D514258; Thu, 6 Aug 2020 03:29:26 +0000 (UTC) Received: from [10.72.13.140] (ovpn-13-140.pek2.redhat.com [10.72.13.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id A097B19C71; Thu, 6 Aug 2020 03:29:18 +0000 (UTC) Subject: Re: [PATCH 4/4] vhost: vdpa: report iova range To: "Michael S. Tsirkin" Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, rob.miller@broadcom.com, lingshan.zhu@intel.com, eperezma@redhat.com, lulu@redhat.com, shahafs@mellanox.com, hanand@xilinx.com, mhabets@solarflare.com, gdawar@xilinx.com, saugatm@xilinx.com, vmireyno@marvell.com, zhangweining@ruijie.com.cn, eli@mellanox.com References: <20200617032947.6371-1-jasowang@redhat.com> <20200617032947.6371-5-jasowang@redhat.com> <20200805085635-mutt-send-email-mst@kernel.org> From: Jason Wang Message-ID: <357f681b-fdee-cc04-3cf3-04035c555893@redhat.com> Date: Thu, 6 Aug 2020 11:29:16 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200805085635-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/8/5 下午8:58, Michael S. Tsirkin wrote: > On Wed, Jun 17, 2020 at 11:29:47AM +0800, Jason Wang wrote: >> This patch introduces a new ioctl for vhost-vdpa device that can >> report the iova range by the device. For device that depends on >> platform IOMMU, we fetch the iova range via DOMAIN_ATTR_GEOMETRY. For >> devices that has its own DMA translation unit, we fetch it directly >> from vDPA bus operation. >> >> Signed-off-by: Jason Wang >> --- >> drivers/vhost/vdpa.c | 27 +++++++++++++++++++++++++++ >> include/uapi/linux/vhost.h | 4 ++++ >> include/uapi/linux/vhost_types.h | 5 +++++ >> 3 files changed, 36 insertions(+) >> >> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c >> index 77a0c9fb6cc3..ad23e66cbf57 100644 >> --- a/drivers/vhost/vdpa.c >> +++ b/drivers/vhost/vdpa.c >> @@ -332,6 +332,30 @@ static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp) >> >> return 0; >> } >> + >> +static long vhost_vdpa_get_iova_range(struct vhost_vdpa *v, u32 __user *argp) >> +{ >> + struct iommu_domain_geometry geo; >> + struct vdpa_device *vdpa = v->vdpa; >> + const struct vdpa_config_ops *ops = vdpa->config; >> + struct vhost_vdpa_iova_range range; >> + struct vdpa_iova_range vdpa_range; >> + >> + if (!ops->set_map && !ops->dma_map) { > Why not just check if (ops->get_iova_range) directly? Because set_map || dma_ops is a hint that the device has its own DMA translation logic. Device without get_iova_range does not necessarily meant it use IOMMU driver. Thanks > > > > >> + iommu_domain_get_attr(v->domain, >> + DOMAIN_ATTR_GEOMETRY, &geo); >> + range.start = geo.aperture_start; >> + range.end = geo.aperture_end; >> + } else { >> + vdpa_range = ops->get_iova_range(vdpa); >> + range.start = vdpa_range.start; >> + range.end = vdpa_range.end; >> + } >> + >> + return copy_to_user(argp, &range, sizeof(range)); >> + >> +} >> + >> static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, >> void __user *argp) >> { >> @@ -442,6 +466,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, >> case VHOST_VDPA_SET_CONFIG_CALL: >> r = vhost_vdpa_set_config_call(v, argp); >> break; >> + case VHOST_VDPA_GET_IOVA_RANGE: >> + r = vhost_vdpa_get_iova_range(v, argp); >> + break; >> default: >> r = vhost_dev_ioctl(&v->vdev, cmd, argp); >> if (r == -ENOIOCTLCMD) >> diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h >> index 0c2349612e77..850956980e27 100644 >> --- a/include/uapi/linux/vhost.h >> +++ b/include/uapi/linux/vhost.h >> @@ -144,4 +144,8 @@ >> >> /* Set event fd for config interrupt*/ >> #define VHOST_VDPA_SET_CONFIG_CALL _IOW(VHOST_VIRTIO, 0x77, int) >> + >> +/* Get the valid iova range */ >> +#define VHOST_VDPA_GET_IOVA_RANGE _IOW(VHOST_VIRTIO, 0x78, \ >> + struct vhost_vdpa_iova_range) >> #endif >> diff --git a/include/uapi/linux/vhost_types.h b/include/uapi/linux/vhost_types.h >> index 669457ce5c48..4025b5a36177 100644 >> --- a/include/uapi/linux/vhost_types.h >> +++ b/include/uapi/linux/vhost_types.h >> @@ -127,6 +127,11 @@ struct vhost_vdpa_config { >> __u8 buf[0]; >> }; >> >> +struct vhost_vdpa_iova_range { >> + __u64 start; >> + __u64 end; >> +}; >> + > > Pls document fields. And I think first/last is a better API ... > >> /* Feature bits */ >> /* Log all write descriptors. Can be changed while device is active. */ >> #define VHOST_F_LOG_ALL 26 >> -- >> 2.20.1