Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3383997pxj; Tue, 1 Jun 2021 04:10:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycUXycXDn6taEdB8avxXn1Xwr3KVXPqRkyBi0Ye4Yw6R9SFqxDI1t7YUxJA/vksWpVsJim X-Received: by 2002:a05:6638:b84:: with SMTP id b4mr24315693jad.122.1622545853373; Tue, 01 Jun 2021 04:10:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622545853; cv=none; d=google.com; s=arc-20160816; b=R1FQaLIIQ2vO/+fIWIN94gIkpOeNXjpEAMnyYVq3XWod9ZP4Qkm5fFfw6xkigJHHl2 4TD+HeHcfHlh3UTSBA7FFltlcuiaJiiq/jPXvmF6jt+SIDYC1scyAXfUjmMRZMQe0a9L Okgtxyen6gxMZd9UCYUgWLNgNJj5Z61Ims4PY0PeGGEdInjo/1OEHjOIlXfkjFz0ucZ7 zrpjdtO3rO7DcPBPAg8PrzUso6KnjWpE0S3OKFUqmZdTaRe1CDUmGaurC8mg6Isjoxtw lBSju4cd4cb8qvypGoofPW+eDWEIIHu7stmnF6su4iyuLYEqlLYc3OhsVSU835U4Nri1 gBwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:to:cc:ironport-sdr:ironport-sdr; bh=aHXlp+I7V+fPyt/oAviqCcUeMWrW2KTgOJlahuj/eWE=; b=DwYcuAvygS/CqCi5zuMG+oQRSMgZJYG5fhIl0yX1/F1HlARci0Ds9tymtHcYFkUaXG b1RSQ9U5IA1q8xXe9tEHALjMyvkbyk0bxKcQobYnOuso8mnSBXIyODjlHxOxCeO3hSHE qstxwmMetvuIYuL9eZ2ksRHbbWZj6VsoO3DqGQyhfgg4c+uKSNLyj4kEbXkxZiNgMD34 5cKGLuiXF1JGGmH0pJRCW3krwFNhOm4bRhT+hsFZVpa8ImsGBObZ4yhIHrO+COMSNG35 P31fuNdIyyfBxE4Ke0TatZftD4NWGpqYdnX8WI0fUT2YmOMbKQu63BU3EQXX7AwO3S4Q o/8g== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m17si8904478jap.92.2021.06.01.04.10.40; Tue, 01 Jun 2021 04:10:53 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233703AbhFALLL (ORCPT + 99 others); Tue, 1 Jun 2021 07:11:11 -0400 Received: from mga17.intel.com ([192.55.52.151]:55270 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231219AbhFALLK (ORCPT ); Tue, 1 Jun 2021 07:11:10 -0400 IronPort-SDR: pkC2Q//r7MY75tw/5TDmjOxbO+z4PmHrn1GS5EnsMI4pRunlWQMJtfdhzOyf1uXXD2z6LP2Qlb TESWM8Hz9PJw== X-IronPort-AV: E=McAfee;i="6200,9189,10001"; a="183884743" X-IronPort-AV: E=Sophos;i="5.83,239,1616482800"; d="scan'208";a="183884743" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2021 04:09:28 -0700 IronPort-SDR: WZDegxNp3wP/q9jDqwvfXA6qZogcEqh5JoBYq/igauYkrmanJiiBAFQsG4FtYSwyipOd9u7o5j CsavuhDtdc4g== X-IronPort-AV: E=Sophos;i="5.83,239,1616482800"; d="scan'208";a="479239460" Received: from blu2-mobl3.ccr.corp.intel.com (HELO [10.254.213.9]) ([10.254.213.9]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2021 04:09:24 -0700 Cc: baolu.lu@linux.intel.com, LKML , Joerg Roedel , David Woodhouse , "iommu@lists.linux-foundation.org" , "kvm@vger.kernel.org" , "Alex Williamson (alex.williamson@redhat.com)" , Jason Wang , Eric Auger , Jonathan Corbet , "Raj, Ashok" , "Liu, Yi L" , "Wu, Hao" , "Jiang, Dave" , Jacob Pan , Jean-Philippe Brucker , David Gibson , Kirti Wankhede , Robin Murphy To: Jason Gunthorpe , "Tian, Kevin" References: <20210528233649.GB3816344@nvidia.com> From: Lu Baolu Subject: Re: [RFC] /dev/ioasid uAPI proposal Message-ID: <786295f7-b154-cf28-3f4c-434426e897d3@linux.intel.com> Date: Tue, 1 Jun 2021 19:09:21 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <20210528233649.GB3816344@nvidia.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jason, On 2021/5/29 7:36, Jason Gunthorpe wrote: >> /* >> * Bind an user-managed I/O page table with the IOMMU >> * >> * Because user page table is untrusted, IOASID nesting must be enabled >> * for this ioasid so the kernel can enforce its DMA isolation policy >> * through the parent ioasid. >> * >> * Pgtable binding protocol is different from DMA mapping. The latter >> * has the I/O page table constructed by the kernel and updated >> * according to user MAP/UNMAP commands. With pgtable binding the >> * whole page table is created and updated by userspace, thus different >> * set of commands are required (bind, iotlb invalidation, page fault, etc.). >> * >> * Because the page table is directly walked by the IOMMU, the user >> * must use a format compatible to the underlying hardware. It can >> * check the format information through IOASID_GET_INFO. >> * >> * The page table is bound to the IOMMU according to the routing >> * information of each attached device under the specified IOASID. The >> * routing information (RID and optional PASID) is registered when a >> * device is attached to this IOASID through VFIO uAPI. >> * >> * Input parameters: >> * - child_ioasid; >> * - address of the user page table; >> * - formats (vendor, address_width, etc.); >> * >> * Return: 0 on success, -errno on failure. >> */ >> #define IOASID_BIND_PGTABLE _IO(IOASID_TYPE, IOASID_BASE + 9) >> #define IOASID_UNBIND_PGTABLE _IO(IOASID_TYPE, IOASID_BASE + 10) > Also feels backwards, why wouldn't we specify this, and the required > page table format, during alloc time? > Thinking of the required page table format, perhaps we should shed more light on the page table of an IOASID. So far, an IOASID might represent one of the following page tables (might be more): 1) an IOMMU format page table (a.k.a. iommu_domain) 2) a user application CPU page table (SVA for example) 3) a KVM EPT (future option) 4) a VM guest managed page table (nesting mode) This version only covers 1) and 4). Do you think we need to support 2), 3) and beyond? If so, it seems that we need some in-kernel helpers and uAPIs to support pre-installing a page table to IOASID. From this point of view an IOASID is actually not just a variant of iommu_domain, but an I/O page table representation in a broader sense. Best regards, baolu