Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1589665rdb; Sat, 2 Dec 2023 01:49:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6KbSBe3GjPFv43bQXNXya82mHBh8z6a/Ru6zDIy5aLQIULcJmwaGhw5RAeaUgRnnDh/o8 X-Received: by 2002:a17:90a:e394:b0:286:544c:3af2 with SMTP id b20-20020a17090ae39400b00286544c3af2mr1065884pjz.20.1701510552099; Sat, 02 Dec 2023 01:49:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701510552; cv=none; d=google.com; s=arc-20160816; b=M/bG9yikTlzTbZQvjYo5xWt6R1FnyOsGJWJEnllgQEs1ktrWtAWQhVep73fBL6EEKY UavZ8U4t9miofLdHs7nJC8Iik7Mm1VjQu2bB41dojxS31++dGgoC99V9AHElY5AXsvHD 4amVmojBqXI7lsnpBVqZd5IVvLoXbmMYzA1Rk7LnQfJB05mzf76UR9WZkh+Tg5Z/pU6w mywyRmBvn8/PghrWSU4S5zvjn39AVj0jJ5ft6PNcgwdwtcGR+mu9E/yttgKO5zlZDYQo fKsA34uTOdIPWDHxlRxBZYdAuUNe4pDmQC/81YMq3WcfdSM7xygDlj+wV5VZzoHDEWIr aVPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=i262PTqJKfEj5lD7aLrMBMZvMKc/31qLf3Xyk6MAiwM=; fh=+WI4m5k3dRLR+dR3neThuZkNBTzIm/a8HgtddERL9fA=; b=FvZ3X9lUi96e59HoxwUcJYCrW+C9H7HUrBkK/rUl1B4Msl8Avoef2U/+Lk1lMzRJPn eqzQMEdR1kVrVBY2SsMK9mRYiC+XxJ22pMdsrH1849q7+bDegEPsLvj+CXSYzrf2XWzk 9XT9w3WmHfyC3CJtm7r0wpdbmSSastvXZtfwUHU7i7TdGtiGdBOIQ35Rf4XWOniH8qEB gerNEA9wswiN9LmwDJyuJKxWXHxLhyr2v0jbqpKE23OLblT00KgToDfnndVuAllPJfGV gPw5vNFO6412y/LTdK3W0kkspqc9dpRmHObTS6r0VPSmpYcZRYHX6CIgbHtj4Dw74luD vhZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UH2Q45X6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id o18-20020a17090aac1200b002861cc51114si4907708pjq.164.2023.12.02.01.49.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 01:49:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UH2Q45X6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id EFD8E8069D88; Sat, 2 Dec 2023 01:49:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232326AbjLBJtA (ORCPT + 99 others); Sat, 2 Dec 2023 04:49:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232253AbjLBJs7 (ORCPT ); Sat, 2 Dec 2023 04:48:59 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAC4C181; Sat, 2 Dec 2023 01:49:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701510545; x=1733046545; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=hOSJlPe1dfesUGDszntE2ySqLMhZ74ABDSSs+Yf065E=; b=UH2Q45X6iGIkbfzmkiFKTDoRJ3efHQne4QGlODGJghZe/cMifXJu7CEF 4VkcJnLoPg/rSDMkEG9e6bYogWkfZjlwfaBMnnPPd7bT23iocz+lyp0Vu CHG0loxZq0CfmJyjH+MInDs6M+0H5BIv9sk9Ey4+poykFickaTuguNDLe vNX8k1KG9QPnLRjQW7jjSVahPrWmwI4zHhMYQYGr5cL4H1eOpiYuTtpBm LxFCLOmrCOEkSeix+EuBD3+YKcTfT97bGM1U+37mPEIuZilIAS5o4ya/d aBne3Jyhz7ObNjt5pdv1OxYxqeMl+KISILmVz4+hDrtKqwjXuC+VztpAP A==; X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="373774703" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="373774703" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 01:49:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="1017293275" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="1017293275" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 01:49:02 -0800 From: Yan Zhao To: iommu@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: alex.williamson@redhat.com, jgg@nvidia.com, pbonzini@redhat.com, seanjc@google.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, kevin.tian@intel.com, baolu.lu@linux.intel.com, dwmw2@infradead.org, yi.l.liu@intel.com, Yan Zhao Subject: [RFC PATCH 10/42] iommu: Add new iommu op to create domains managed by KVM Date: Sat, 2 Dec 2023 17:20:07 +0800 Message-Id: <20231202092007.14026-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231202091211.13376-1-yan.y.zhao@intel.com> References: <20231202091211.13376-1-yan.y.zhao@intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 02 Dec 2023 01:49:11 -0800 (PST) Introduce a new iommu_domain op to create domains managed by KVM through IOMMUFD. These domains have a few different properties compares to kernel owned domains and user owned domains: - They must not be PAGING domains. Page mapping/unmapping is controlled by KVM. - They must be stage 2 mappings translating GPA to HPA. - Paging structure allocation/free is not managed by IOMMU driver, but by KVM. - TLBs flushes are notified by KVM. The new op clearly says the domain is being created by IOMMUFD. A driver specific structure to the meta data of paging structures from KVM is passed in via the op param "data". IOMMU drivers that cannot support VFIO/IOMMUFD should not support this op. This new op for now is only supposed to be used by IOMMUFD, hence no wrapper for it. IOMMUFD would call the callback directly. As for domain free, IOMMUFD would use iommu_domain_free(). Signed-off-by: Yan Zhao --- include/linux/iommu.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 9ecee72e2d6c4..0ce23ee399d35 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -522,6 +522,13 @@ __iommu_copy_struct_from_user_array(void *dst_data, * @domain_alloc_paging: Allocate an iommu_domain that can be used for * UNMANAGED, DMA, and DMA_FQ domain types. * @domain_alloc_sva: Allocate an iommu_domain for Shared Virtual Addressing. + * @domain_alloc_kvm: Allocate an iommu domain with type IOMMU_DOMAIN_KVM. + * It's called by IOMMUFD and must fully initialize the new + * domain before return. + * The @data is of type "const void *" whose format is defined + * in kvm arch specific header "asm/kvm_exported_tdp.h". + * Unpon success, domain of type IOMMU_DOMAIN_KVM is returned. + * Upon failure, ERR_PTR is returned. * @probe_device: Add device to iommu driver handling * @release_device: Remove device from iommu driver handling * @probe_finalize: Do final setup work after the device is added to an IOMMU @@ -564,6 +571,8 @@ struct iommu_ops { struct iommu_domain *(*domain_alloc_paging)(struct device *dev); struct iommu_domain *(*domain_alloc_sva)(struct device *dev, struct mm_struct *mm); + struct iommu_domain *(*domain_alloc_kvm)(struct device *dev, u32 flags, + const void *data); struct iommu_device *(*probe_device)(struct device *dev); void (*release_device)(struct device *dev); -- 2.17.1