From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5209C43331 for ; Mon, 30 Mar 2020 09:36:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7765420714 for ; Mon, 30 Mar 2020 09:36:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="evy2x4vE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728502AbgC3Jgz (ORCPT ); Mon, 30 Mar 2020 05:36:55 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:36123 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726127AbgC3Jgz (ORCPT ); Mon, 30 Mar 2020 05:36:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585561013; 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=GsQts7KdvM7OmuNRLhUrsthOkUg/qgVxfy93Ru1gfZY=; b=evy2x4vEuSEzfOEfMOBk7XF0LlGg9RwTvNCG35I6npTYRAPhPaZ6QfS7xiTu8M55RWmvbq vBQEFdfY5KPNoZiKFA0tpVgcqz4OHMXaKLms+LMZBThs+zYCl3YbTWQzK4CvkFUP8SabPF boQ5wulj/gkF+fAld2GXv73tuee+HbY= 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-493-H-Aylf-TMzeyq1sp7BqO4w-1; Mon, 30 Mar 2020 05:36:52 -0400 X-MC-Unique: H-Aylf-TMzeyq1sp7BqO4w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4A0A6E6BAC; Mon, 30 Mar 2020 09:36:43 +0000 (UTC) Received: from [10.36.112.58] (ovpn-112-58.ams2.redhat.com [10.36.112.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D17C9DA0FB; Mon, 30 Mar 2020 09:36:23 +0000 (UTC) Subject: Re: [PATCH v2 03/22] vfio: check VFIO_TYPE1_NESTING_IOMMU support To: Liu Yi L , qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Cc: pbonzini@redhat.com, mst@redhat.com, david@gibson.dropbear.id.au, kevin.tian@intel.com, jun.j.tian@intel.com, yi.y.sun@intel.com, kvm@vger.kernel.org, hao.wu@intel.com, jean-philippe@linaro.org, Jacob Pan , Yi Sun References: <1585542301-84087-1-git-send-email-yi.l.liu@intel.com> <1585542301-84087-4-git-send-email-yi.l.liu@intel.com> From: Auger Eric Message-ID: <2c65e531-1cc8-dc01-4b06-e7baff58addd@redhat.com> Date: Mon, 30 Mar 2020 11:36:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <1585542301-84087-4-git-send-email-yi.l.liu@intel.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Yi, On 3/30/20 6:24 AM, Liu Yi L wrote: > VFIO needs to check VFIO_TYPE1_NESTING_IOMMU support with Kernel before > further using it. e.g. requires to check IOMMU UAPI version. > > Cc: Kevin Tian > Cc: Jacob Pan > Cc: Peter Xu > Cc: Eric Auger > Cc: Yi Sun > Cc: David Gibson > Cc: Alex Williamson > Signed-off-by: Liu Yi L > Signed-off-by: Yi Sun > --- > hw/vfio/common.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/hw/vfio/common.c b/hw/vfio/common.c > index 0b3593b..c276732 100644 > --- a/hw/vfio/common.c > +++ b/hw/vfio/common.c > @@ -1157,12 +1157,21 @@ static void vfio_put_address_space(VFIOAddressSpace *space) > static int vfio_get_iommu_type(VFIOContainer *container, > Error **errp) > { > - int iommu_types[] = { VFIO_TYPE1v2_IOMMU, VFIO_TYPE1_IOMMU, > + int iommu_types[] = { VFIO_TYPE1_NESTING_IOMMU, > + VFIO_TYPE1v2_IOMMU, VFIO_TYPE1_IOMMU, > VFIO_SPAPR_TCE_v2_IOMMU, VFIO_SPAPR_TCE_IOMMU }; > - int i; > + int i, version; > > for (i = 0; i < ARRAY_SIZE(iommu_types); i++) { > if (ioctl(container->fd, VFIO_CHECK_EXTENSION, iommu_types[i])) { > + if (iommu_types[i] == VFIO_TYPE1_NESTING_IOMMU) { > + version = ioctl(container->fd, VFIO_CHECK_EXTENSION, > + VFIO_NESTING_IOMMU_UAPI); > + if (version < IOMMU_UAPI_VERSION) { > + info_report("IOMMU UAPI incompatible for nesting"); > + continue; > + } > + } This means that by default VFIO_TYPE1_NESTING_IOMMU wwould be chosen. I don't think this what we want. On ARM this would mean that for a standard VFIO assignment without vIOMMU, SL will be used instead of FL. This may not be harmless. For instance, in "[RFC v6 09/24] vfio: Force nested if iommu requires it", I use nested only if I detect we have a vSMMU. Otherwise I keep the legacy VFIO_TYPE1v2_IOMMU. Thanks Eric > return iommu_types[i]; > } > } > @@ -1278,6 +1287,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, > } > > switch (container->iommu_type) { > + case VFIO_TYPE1_NESTING_IOMMU: > case VFIO_TYPE1v2_IOMMU: > case VFIO_TYPE1_IOMMU: > { > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.1 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75B6AC43331 for ; Mon, 30 Mar 2020 09:37:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 407BE20714 for ; Mon, 30 Mar 2020 09:37:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="evy2x4vE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 407BE20714 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIqrQ-0006FQ-Cq for qemu-devel@archiver.kernel.org; Mon, 30 Mar 2020 05:37:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41562) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIqqm-0005q2-E8 for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:36:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIqqk-0006ff-Jm for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:36:55 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:60838) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jIqqk-0006fI-EA for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:36:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585561013; 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=GsQts7KdvM7OmuNRLhUrsthOkUg/qgVxfy93Ru1gfZY=; b=evy2x4vEuSEzfOEfMOBk7XF0LlGg9RwTvNCG35I6npTYRAPhPaZ6QfS7xiTu8M55RWmvbq vBQEFdfY5KPNoZiKFA0tpVgcqz4OHMXaKLms+LMZBThs+zYCl3YbTWQzK4CvkFUP8SabPF boQ5wulj/gkF+fAld2GXv73tuee+HbY= 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-493-H-Aylf-TMzeyq1sp7BqO4w-1; Mon, 30 Mar 2020 05:36:52 -0400 X-MC-Unique: H-Aylf-TMzeyq1sp7BqO4w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4A0A6E6BAC; Mon, 30 Mar 2020 09:36:43 +0000 (UTC) Received: from [10.36.112.58] (ovpn-112-58.ams2.redhat.com [10.36.112.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D17C9DA0FB; Mon, 30 Mar 2020 09:36:23 +0000 (UTC) Subject: Re: [PATCH v2 03/22] vfio: check VFIO_TYPE1_NESTING_IOMMU support To: Liu Yi L , qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com References: <1585542301-84087-1-git-send-email-yi.l.liu@intel.com> <1585542301-84087-4-git-send-email-yi.l.liu@intel.com> From: Auger Eric Message-ID: <2c65e531-1cc8-dc01-4b06-e7baff58addd@redhat.com> Date: Mon, 30 Mar 2020 11:36:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <1585542301-84087-4-git-send-email-yi.l.liu@intel.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 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: jean-philippe@linaro.org, kevin.tian@intel.com, Jacob Pan , Yi Sun , kvm@vger.kernel.org, mst@redhat.com, jun.j.tian@intel.com, yi.y.sun@intel.com, pbonzini@redhat.com, hao.wu@intel.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Yi, On 3/30/20 6:24 AM, Liu Yi L wrote: > VFIO needs to check VFIO_TYPE1_NESTING_IOMMU support with Kernel before > further using it. e.g. requires to check IOMMU UAPI version. > > Cc: Kevin Tian > Cc: Jacob Pan > Cc: Peter Xu > Cc: Eric Auger > Cc: Yi Sun > Cc: David Gibson > Cc: Alex Williamson > Signed-off-by: Liu Yi L > Signed-off-by: Yi Sun > --- > hw/vfio/common.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/hw/vfio/common.c b/hw/vfio/common.c > index 0b3593b..c276732 100644 > --- a/hw/vfio/common.c > +++ b/hw/vfio/common.c > @@ -1157,12 +1157,21 @@ static void vfio_put_address_space(VFIOAddressSpace *space) > static int vfio_get_iommu_type(VFIOContainer *container, > Error **errp) > { > - int iommu_types[] = { VFIO_TYPE1v2_IOMMU, VFIO_TYPE1_IOMMU, > + int iommu_types[] = { VFIO_TYPE1_NESTING_IOMMU, > + VFIO_TYPE1v2_IOMMU, VFIO_TYPE1_IOMMU, > VFIO_SPAPR_TCE_v2_IOMMU, VFIO_SPAPR_TCE_IOMMU }; > - int i; > + int i, version; > > for (i = 0; i < ARRAY_SIZE(iommu_types); i++) { > if (ioctl(container->fd, VFIO_CHECK_EXTENSION, iommu_types[i])) { > + if (iommu_types[i] == VFIO_TYPE1_NESTING_IOMMU) { > + version = ioctl(container->fd, VFIO_CHECK_EXTENSION, > + VFIO_NESTING_IOMMU_UAPI); > + if (version < IOMMU_UAPI_VERSION) { > + info_report("IOMMU UAPI incompatible for nesting"); > + continue; > + } > + } This means that by default VFIO_TYPE1_NESTING_IOMMU wwould be chosen. I don't think this what we want. On ARM this would mean that for a standard VFIO assignment without vIOMMU, SL will be used instead of FL. This may not be harmless. For instance, in "[RFC v6 09/24] vfio: Force nested if iommu requires it", I use nested only if I detect we have a vSMMU. Otherwise I keep the legacy VFIO_TYPE1v2_IOMMU. Thanks Eric > return iommu_types[i]; > } > } > @@ -1278,6 +1287,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, > } > > switch (container->iommu_type) { > + case VFIO_TYPE1_NESTING_IOMMU: > case VFIO_TYPE1v2_IOMMU: > case VFIO_TYPE1_IOMMU: > { >