Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp176665ybt; Tue, 16 Jun 2020 20:34:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzczip3251ikdNG+h5et+YI+8MXPEcxir07ZhXvrlTujILAs4CxfXXfIBprEw/1fHASnqfg X-Received: by 2002:a17:906:d963:: with SMTP id rp3mr5883434ejb.326.1592364858966; Tue, 16 Jun 2020 20:34:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592364858; cv=none; d=google.com; s=arc-20160816; b=NDUVLwtFH9CNULFzR8+EQbZlbyb1cr9WZv+J0+5/lBkIcmo4SnS/GnY//2XH0DwVZ1 vAMKojhS0bJdUSbin8z+ufIHEggjqvnTtQbQSrusUvR+903izRoOleU+EtxLK8yEY9iU sXf9FW5gMm6sCt4djxIRbGkeZIaib7DIGYSkr46SlWPYazY/Wnhudu3wrDA59UNdwCAV KGrRojhQLx70Md/dSdXfBMCz3U13X4vlZiJyuVWjWOQVEll8W+YJ0ayT/dKYoWXuNjIB 0lTpW8X1gxIRaG3uDC4BW9WDacCdBkgwFk8JIpt9mE3CG8ZxF570+zy8ql7PSGnAlspl GspQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bkpquXk+lGQPHfSO+mPqa9rV9+97W808ddm79vGuDUE=; b=N754AvWYJ3ZS+N/eKG6EVbYC3CGsm32/GsmV5NvRjp+XaivoSbq0ZTeeYzMS1OkYub CigxKOadsHlF7BMpCnw2yYJZ17HJPAIBf8M/ltljzqPygbMzRFfSYDwzA73SShzrI6Cr QpCTPwD+jc0eINVxRUlRr4PZi9XnMUTl1zalVwEEbJIFLrfy6SxEaVw/ud03fzFs8It5 vAutkfcSae6nOhjKeVZJMVTdy31qotQFrWavD8lsuZ6Q0hnbyvSk+2+D+qHSN4hsPWdR W4nYR6o4C1Gx7xHt+fdvvtUx5FL93MRFpQwg9ZhK7HvNpfRughrk7C7PVniS9zzgZ7Zu jnoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SvsvEzcl; 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 t21si11819282edy.548.2020.06.16.20.33.56; Tue, 16 Jun 2020 20:34:18 -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=SvsvEzcl; 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 S1726802AbgFQDaj (ORCPT + 99 others); Tue, 16 Jun 2020 23:30:39 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:42197 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726703AbgFQDah (ORCPT ); Tue, 16 Jun 2020 23:30:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592364635; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bkpquXk+lGQPHfSO+mPqa9rV9+97W808ddm79vGuDUE=; b=SvsvEzcltwg1bFDntxdO5nMF2foMzKcbwhODdg8aMHDO8XgaiQGRDMGsoY6oavisvietaI V6n0zvBmnSxf5r6w03eSfn4UEYSmLFM8QsFS8bJ+Zs7yt5LZOs50WNiS5AA2QF2Zccz5Q/ 2yUQpvU1i7JU+hm7M3S21+bo2eaKoJc= 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-34-xHmwE7_lO6eRSOz8Om5cVQ-1; Tue, 16 Jun 2020 23:30:33 -0400 X-MC-Unique: xHmwE7_lO6eRSOz8Om5cVQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8535C10059A7; Wed, 17 Jun 2020 03:30:31 +0000 (UTC) Received: from jason-ThinkPad-X1-Carbon-6th.redhat.com (ovpn-13-217.pek2.redhat.com [10.72.13.217]) by smtp.corp.redhat.com (Postfix) with ESMTP id C17615C1BD; Wed, 17 Jun 2020 03:30:25 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: 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 Subject: [PATCH 4/4] vhost: vdpa: report iova range Date: Wed, 17 Jun 2020 11:29:47 +0800 Message-Id: <20200617032947.6371-5-jasowang@redhat.com> In-Reply-To: <20200617032947.6371-1-jasowang@redhat.com> References: <20200617032947.6371-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) { + 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; +}; + /* Feature bits */ /* Log all write descriptors. Can be changed while device is active. */ #define VHOST_F_LOG_ALL 26 -- 2.20.1