From patchwork Sat Dec 2 09:19:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 172767 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1674009vqy; Sat, 2 Dec 2023 01:48:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjZQT4irrXMr9sr9J6gPPesPHjcrU0e6zZ/PV+a7dGyeW0jQriZNXFeWmQ129oktkU7in0 X-Received: by 2002:a17:902:d490:b0:1cf:ad33:61b with SMTP id c16-20020a170902d49000b001cfad33061bmr880582plg.39.1701510514829; Sat, 02 Dec 2023 01:48:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701510514; cv=none; d=google.com; s=arc-20160816; b=zu04+sJgpfZpxRyCqyhetWZ7IqY7KpbfE0RSXaeqeac9JKjH0Q15lElaomZWn4pqYZ RQYOP1rrkMq/sCcVH3nebpzpsEF4bhcCnQn3TbUBw+Qca1RnSOxUcBhRZCUF8q1SvOnf w98XUXYKkzpouJQHyGgsIvxPwjm2BoTTsI24Jf28bgOzoA6o3dDUD0VykFmYrRO8xqOp Ez6ZLkjvvrOjGkuwEeSPsfKzp5u/ywDndAn+PEUVWKdp4jqiVTxihskjE/NLh2v+epyS O4/UXUal5vOWvx1mVdhhgCYf227+x06jrKONxSBm7W8/I0Gnytt2y7zxShgLqT/jqTt8 XNYg== 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=nSCeOw2TedLJGCFSQ6v3nKv/0ND9/N4ALoOO35nJEyY=; fh=+WI4m5k3dRLR+dR3neThuZkNBTzIm/a8HgtddERL9fA=; b=nxvxQE8YGXDEwASir7mO5/PvBbQAQ1f3qtBqpc0FyKgzSw/me7/qjpFfq4XREDusGN dFwM2HJWvJ3IkNnSpWzt/crubofKHesYNNHlV85RFvaaVmeDwMabHWc4loWrdl6GMLuU 6Uxuan/GGKHpcPKe6YudLeK+a4rT4ZvvjHv2CH+fZ0065Wqwkpez6c+pfUoipFgHbw4p yvGu3XCAh/UP55T/zaT+DrrhEsJ5nrJxFvf8mTtoZ2XRrN0nDvvgaihJlmcVszL3lphs rAldTPhyUM9bJt4e83FGu9mcdgSiVxME3qSjxILgmIiSG07kbYXcmkCdVOchd3ApFtdk FjTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QSQzl9EO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id lt12-20020a17090b354c00b00283a148d836si4908177pjb.27.2023.12.02.01.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 01:48:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QSQzl9EO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 99E858032200; Sat, 2 Dec 2023 01:48:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232310AbjLBJsW (ORCPT + 99 others); Sat, 2 Dec 2023 04:48:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232373AbjLBJsV (ORCPT ); Sat, 2 Dec 2023 04:48:21 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B44B172A; Sat, 2 Dec 2023 01:48:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701510502; x=1733046502; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=VQNKqC4SiqPXJcfo/UghgDuOyfAhw8F6DULvr3iToMM=; b=QSQzl9EOyKhF+DQmNkW6v8gzChahCX1uo71w3nP8Xu6J3l25mC/LDsYI ct2r1JO5D5R4AhBjF4TfO4c1azhHMTzA6XCmiWFLHZ2EvXyQIy2IGI/cN MJ/JwdhktWJE8RfFCjXgsocv0I6BF7e7RdR0otX/HNQ0iZwbohS8FFqYh ZKel5jg873KEGJjFoe3tLJVhtN4RPcZ5SFReBl9+r/njaaqDQ1UGiCrOV mBNliID0ZSrswl9G2/am8snq9Kfsch3brJ8ittK0n1qPGhG22pg8mm6ge s2bPnYIGFwF9VKI7e/UWnQAlwxei2ihJIU7J9ZVS1jJMFdXNpUsSZL72o Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="390756693" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="390756693" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 01:48:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="860818540" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="860818540" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 01:48:18 -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 09/42] iommu: Add IOMMU_DOMAIN_KVM Date: Sat, 2 Dec 2023 17:19:24 +0800 Message-Id: <20231202091924.13947-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=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Sat, 02 Dec 2023 01:48:31 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784163089854744283 X-GMAIL-MSGID: 1784163089854744283 Introduce a new domain type to share stage 2 mappings from KVM. Paging strcture allocation/free of this new domain are managed by KVM. IOMMU side just gets page table root address from KVM via parsing vendor specific data passed in from KVM through IOMMUFD and sets it to the IOMMU hardware. This new domain can be allocated by domain_alloc_kvm op, and attached to a device through the existing iommu_attach_device/group() interfaces. Page mapping/unmapping are managed by KVM too, therefore map/unmap ops are not implemented. Signed-off-by: Yan Zhao --- include/linux/iommu.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index c79378833c758..9ecee72e2d6c4 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -171,6 +171,8 @@ struct iommu_domain_geometry { #define __IOMMU_DOMAIN_NESTED (1U << 6) /* User-managed address space nested on a stage-2 translation */ +#define __IOMMU_DOMAIN_KVM (1U << 7) /* KVM-managed stage-2 translation */ + #define IOMMU_DOMAIN_ALLOC_FLAGS ~__IOMMU_DOMAIN_DMA_FQ /* * This are the possible domain-types @@ -187,6 +189,7 @@ struct iommu_domain_geometry { * invalidation. * IOMMU_DOMAIN_SVA - DMA addresses are shared process addresses * represented by mm_struct's. + * IOMMU_DOMAIN_KVM - DMA mappings on stage 2, managed by KVM. * IOMMU_DOMAIN_PLATFORM - Legacy domain for drivers that do their own * dma_api stuff. Do not use in new drivers. */ @@ -201,6 +204,7 @@ struct iommu_domain_geometry { #define IOMMU_DOMAIN_SVA (__IOMMU_DOMAIN_SVA) #define IOMMU_DOMAIN_PLATFORM (__IOMMU_DOMAIN_PLATFORM) #define IOMMU_DOMAIN_NESTED (__IOMMU_DOMAIN_NESTED) +#define IOMMU_DOMAIN_KVM (__IOMMU_DOMAIN_KVM) struct iommu_domain { unsigned type;