Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3201653pxv; Mon, 12 Jul 2021 11:43:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6RNawv+3Vw1P3BEFpQKkFT00f7b5kayZe1ecA26R2IzXVmBgo5HZ0ok6Kh2ZKOPmxNuOk X-Received: by 2002:a17:907:7708:: with SMTP id kw8mr531044ejc.111.1626115425968; Mon, 12 Jul 2021 11:43:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626115425; cv=none; d=google.com; s=arc-20160816; b=a/1bFooD5JtG/MgHM2gjzK4w8Kw1zcXILzAFLdWN79iHEBJ5R3aXInLGf5cIn38lvk oInPeDjG1aipfoPNsoqhJWJOTX+/yVf5GE/hM7LcWvQOcMVOCo/XJcyANgY4PVruBb7F XhvxjTDJII5ucE9agn1nSOXeRCocRhhCs6Ocy30vqrmTaI4+WmlUs9jy6anI1XyhwNJI IP8oLdZzHromNWw2PCuQLaKZ0n/Cpy2cFGOCl+wd3gnpXmUId2iXTOV+ep5Ycv2omP8N ffc0NDY2eVrZD66sKgFWs4VVIVaulinUNtU7NWg1XI4gJG9CJD98maXszi+nZIIQw2fr hx1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Rz8zwYlKIBwilT7nuaKV92zNGRhD3wv0rHn55OLUrN8=; b=lW8N7ItjYuipFCfTEt0tmaEecZN4ZP8U9O6Mn6jqGxYPHSAuIbfLbnEE/sIKJHlj+N GOPhd0hUcL2P54gu3PWDb3I3lIQzcNbCDJFWq0fn6eVh89TssEgfJ2CmEZ/Xfyiz4cOg NsW1hWJQgxemUY6bwrP8d2HgT8veTSoQxLG9j3wW4LIDKoGZrJAwXesqpLHbpZZaxjxP KGjgHLFdjq0ppThVSQB7BG6fMv6GXMvlRJr+l6CO2Kv2dfkR78H3cv8miBn7GWwwAf+b jhwz7PRYXZLQBFFz3/kopR4mbhHGIev73WEPBBU+xAbzwog/BmlPycXoYBc/ksBJvlXm Hi0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HBRCvuJo; 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 y62si18985989ede.555.2021.07.12.11.43.23; Mon, 12 Jul 2021 11:43:45 -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=HBRCvuJo; 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 S235922AbhGLSoo (ORCPT + 99 others); Mon, 12 Jul 2021 14:44:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59368 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233973AbhGLSon (ORCPT ); Mon, 12 Jul 2021 14:44:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626115314; 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=Rz8zwYlKIBwilT7nuaKV92zNGRhD3wv0rHn55OLUrN8=; b=HBRCvuJoYtCL3w+DDft5SuLL8CK1BpQqw059rFkTTjej9hUenF51hLFivjlM6vAZqid4G0 +hwxburtBZts3N5nTjAIYZdyEIa7XqYUxvHN1FElJHmB1Ci/QMC6JU09oZAsyp9/IfVTRI OqvrfXQ9hkykn4AzCo0R7u4EpvlaIBw= Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-11-ZBNbG0CWMSyS-0RUqn_jJw-1; Mon, 12 Jul 2021 14:41:53 -0400 X-MC-Unique: ZBNbG0CWMSyS-0RUqn_jJw-1 Received: by mail-ot1-f72.google.com with SMTP id a60-20020a9d26420000b0290448d2be15e6so13800060otb.23 for ; Mon, 12 Jul 2021 11:41:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rz8zwYlKIBwilT7nuaKV92zNGRhD3wv0rHn55OLUrN8=; b=TU8bSC4XTGfOdVKXFK7PbR2UsewaRn5EmYx0QJt9y5HCeok9Lx5gyPgXGh7csUZDtM jU3egK4chwHuggWVVILuTYzkFtbh3Oc80knWLZ0aCS45kH41EWhHK6amVQTsGWvOCXdP ythY3YvNfHPTVDTcrnjv2AI6suxtmOzChhHmd5PZ/N7zMWY0a4G7WcRxn46RCEVfpPEA wEbC5sfZcNoDs6F5/e7t7Qo3Pd9unReCYAiiwUnO2aP8a6LAK6NEXd07hyjFhmP4SPIc wkZrpgCxiKn4ckyLaUYhFmbo+ehkkuY6e1sktlBnBYPS+xPxboZr+aavfH88jfnjk/8/ HO/w== X-Gm-Message-State: AOAM530+rusR5urFkLVoe83HhsIUvgekjgNo+ZWBzh6ZeVEH6JrYFDJH SuJ3pcfJ/qP2ySchp3CiENbTbz7Xu8vDxzerbuGt+qxB/e5PIPxmvBe16SjxHi++yms1ZdQXLKb Bi+DiX7iYG0LdXaK7hDT4jHVD X-Received: by 2002:aca:59c3:: with SMTP id n186mr158956oib.98.1626115312781; Mon, 12 Jul 2021 11:41:52 -0700 (PDT) X-Received: by 2002:aca:59c3:: with SMTP id n186mr158927oib.98.1626115312574; Mon, 12 Jul 2021 11:41:52 -0700 (PDT) Received: from redhat.com ([198.99.80.109]) by smtp.gmail.com with ESMTPSA id o9sm1221754oiw.49.2021.07.12.11.41.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 11:41:52 -0700 (PDT) Date: Mon, 12 Jul 2021 12:41:50 -0600 From: Alex Williamson To: "Tian, Kevin" Cc: Jason Gunthorpe , Jean-Philippe Brucker , David Gibson , Jason Wang , "parav@mellanox.com" , "Enrico Weigelt, metux IT consult" , Paolo Bonzini , Shenming Lu , Joerg Roedel , Eric Auger , "Jonathan Corbet" , "Raj, Ashok" , "Liu, Yi L" , "Wu, Hao" , "Jiang, Dave" , Jacob Pan , "Kirti Wankhede" , Robin Murphy , "kvm@vger.kernel.org" , "iommu@lists.linux-foundation.org" , "David Woodhouse" , LKML , "Lu Baolu" Subject: Re: [RFC v2] /dev/iommu uAPI proposal Message-ID: <20210712124150.2bf421d1.alex.williamson@redhat.com> In-Reply-To: References: <20210709155052.2881f561.alex.williamson@redhat.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 12 Jul 2021 01:22:11 +0000 "Tian, Kevin" wrote: > > From: Alex Williamson > > Sent: Saturday, July 10, 2021 5:51 AM > > On Fri, 9 Jul 2021 07:48:44 +0000 > > "Tian, Kevin" wrote: > > > For mdev the struct device should be the pointer to the parent device. > > > > I don't get how iommu_register_device() differentiates an mdev from a > > pdev in this case. > > via device cookie. Let me re-add this section for more context: > 3. Sample structures and helper functions > -------------------------------------------------------- > > Three helper functions are provided to support VFIO_BIND_IOMMU_FD: > > struct iommu_ctx *iommu_ctx_fdget(int fd); > struct iommu_dev *iommu_register_device(struct iommu_ctx *ctx, > struct device *device, u64 cookie); > int iommu_unregister_device(struct iommu_dev *dev); > > An iommu_ctx is created for each fd: > > struct iommu_ctx { > // a list of allocated IOASID data's > struct xarray ioasid_xa; > > // a list of registered devices > struct xarray dev_xa; > }; > > Later some group-tracking fields will be also introduced to support > multi-devices group. > > Each registered device is represented by iommu_dev: > > struct iommu_dev { > struct iommu_ctx *ctx; > // always be the physical device > struct device *device; > u64 cookie; > struct kref kref; > }; > > A successful binding establishes a security context for the bound > device and returns struct iommu_dev pointer to the caller. After this > point, the user is allowed to query device capabilities via IOMMU_ > DEVICE_GET_INFO. > > For mdev the struct device should be the pointer to the parent device. So we'll have a VFIO_DEVICE_BIND_IOMMU_FD ioctl where the user provides the iommu_fd and a cookie. vfio will use iommu_ctx_fdget() to get an iommu_ctx* for that iommu_fd, then we'll call iommu_register_device() using that iommu_ctx* we got from the iommu_fd, the cookie provided by the user, and for an mdev, the parent of the device the user owns (the device_fd on which this ioctl is called)... How does an arbitrary user provided cookie let you differentiate that the request is actually for an mdev versus the parent device itself? For instance, how can the IOMMU layer distinguish GVT-g (mdev) vs GVT-d (direct assignment) when both use the same struct device* and cookie is just a user provided value? Still confused. Thanks, Alex