From patchwork Tue Sep 19 09:25:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 141864 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3349590vqi; Tue, 19 Sep 2023 05:35:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE53EDUCshjRRY3HMUsMwjZLspHvOvfL9p/gg7RrWnUObPokYBoMDfSPnc7TtpHDtT6VMY/ X-Received: by 2002:a05:6358:52d4:b0:134:e964:134c with SMTP id z20-20020a05635852d400b00134e964134cmr14236845rwz.11.1695126941742; Tue, 19 Sep 2023 05:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695126941; cv=none; d=google.com; s=arc-20160816; b=AuUv5Ds+8YwKVJ3rW/K+OQdFvOl3DbkiVgUI49DXLcmF0rzs/E4SjTP7QkylrMLEGI EvMUARuNjjg1ZChGfcKyqU2RJ+6j97YXg2STmrv5+8WzBpP/kSctknviqOsZhfRXWdaM H2KdUNfjRdo71cXDjGob74nfSj9Du0klXFI86cF2p9GJBbHX9yl45maYYUesZDolsb5S OcuFs2bKaHUTB/5VI8B1QtjVFjloo9E6iy2egUExD6X5OXE6fd+BvWtdTOYh+PyCvAzP S9d2cDjEnPz/Oom44y5/mXoVvTUdbdGqNDwZDzOQrh0Wmc/MjG1HcLCPpY2oTLMHiPGc zvWw== 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:date:subject:cc:to:from :dkim-signature; bh=z8EeTcSjHvooAnPAD/ewFN4qX5ZjnganMlD2Wn7F0mQ=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=uGjxSOjjGum74dQCFSSom59UuJbpKgv+TKe5fhIoQvrUvjPGY93OV20fzFhFhtc1rq G2G4LJjZvbR/DhrwLfu68+CRQJV3PgmdcSXgYITSpXD6jlwtTUjJwFEz2Bv54d2I6JGg ESWo5dRsv1XHZkoaN0WAgBKIP/LeJExuUbKsMCNteQ809toKA6gRib1gh8dK5S/MJLTI Mgj4cNPJRyfDfmpO8E6J+IPy0xBhuwEMVJO0ZudboCtE/s7ZbY7mSeKz7t1baLJp1eU0 aBJMG4l1LJKbr7OL0ZsJX4MlYGhl0qhB5r79rACj7rlsWH3nbQpuqk/VQrw6yAr8Cwah dJ4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dm8WE+HW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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. [23.128.96.35]) by mx.google.com with ESMTPS id x5-20020a654145000000b0056c4d97e152si5256525pgp.68.2023.09.19.05.35.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 05:35:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dm8WE+HW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 95CE2801BF49; Tue, 19 Sep 2023 02:25:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231273AbjISJZk (ORCPT + 26 others); Tue, 19 Sep 2023 05:25:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231210AbjISJZh (ORCPT ); Tue, 19 Sep 2023 05:25:37 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E169DA; Tue, 19 Sep 2023 02:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695115528; x=1726651528; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HRgwNmKwP4O6YStwVfMY8tcYduf05Yuqqfm8fE3FZmw=; b=dm8WE+HWTfa4zpVAgaEeOb3ivBghr8EbvEJKrV1cA5Hjo/p7taSrYEt0 03gI87KhbSRpLbNpzF/UsvJlpY1flOPTcPWVSBNPYAATyQGyiiMMHN/2I Z7ozXFCnhfELckP0TaQKfJ8TRolH3DWDPtQsm8QGseN32rFjtz1/UHr6p wfmvuuTxGVE7D8OzN6tizaY75RU7ngfCC6KazCVKXMStc+qBKutBJ6Ju+ ZjfE285TjfsYUwWdUzJhPg6CIucILEEFc2HjMqJfwkKD1HSmHfYP/oUXq RjBKoEG2GHuqBDaeVObEjhvIQLI4ikjBxSJDlPlIszIg8J5oaIzoqLpVz A==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="446368827" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="446368827" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 02:25:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="722804619" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="722804619" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga006.jf.intel.com with ESMTP; 19 Sep 2023 02:25:25 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [PATCH 1/6] iommu: Add new iommu op to create domains owned by userspace Date: Tue, 19 Sep 2023 02:25:18 -0700 Message-Id: <20230919092523.39286-2-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230919092523.39286-1-yi.l.liu@intel.com> References: <20230919092523.39286-1-yi.l.liu@intel.com> MIME-Version: 1.0 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 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]); Tue, 19 Sep 2023 02:25:52 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777469428448010255 X-GMAIL-MSGID: 1777469428448010255 Introduce a new iommu_domain op to create domains owned by userspace, e.g. through IOMMUFD. These domains have a few different properties compares to kernel owned domains: - They may be UNMANAGED domains, but created with special parameters. For instance aperture size changes/number of levels, different IOPTE formats, or other things necessary to make a vIOMMU work - We have to track all the memory allocations with GFP_KERNEL_ACCOUNT to make the cgroup sandbox stronger - Device-specialty domains, such as NESTED domains can be created by IOMMUFD. The new op clearly says the domain is being created by IOMMUFD, that the domain is intended for userspace use, and it provides a way to pass user flags or a driver specific uAPI structure to customize the created domain to exactly what the vIOMMU userspace driver requires. iommu drivers that cannot support VFIO/IOMMUFD should not support this op. This includes any driver that cannot provide a fully functional UNMANAGED domain. 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(). Suggested-by: Jason Gunthorpe Signed-off-by: Lu Baolu Co-developed-by: Nicolin Chen Signed-off-by: Nicolin Chen Signed-off-by: Yi Liu --- include/linux/iommu.h | 8 ++++++++ include/uapi/linux/iommufd.h | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index c50a769d569a..660dc1931dc9 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -235,6 +235,13 @@ struct iommu_iotlb_gather { * use. The information type is one of enum iommu_hw_info_type defined * in include/uapi/linux/iommufd.h. * @domain_alloc: allocate iommu domain + * @domain_alloc_user: Allocate an iommu domain corresponding to the input + * parameters like flags defined as enum iommufd_ioas_map_flags + * in include/uapi/linux/iommufd.h. Different from the + * domain_alloc op, it requires iommu driver to fully + * initialize a new domain including the generic iommu_domain + * struct. Upon success, a domain is returned. Upon failure, + * ERR_PTR must be 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 @@ -267,6 +274,7 @@ struct iommu_ops { /* Domain allocation and freeing by the iommu driver */ struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type); + struct iommu_domain *(*domain_alloc_user)(struct device *dev, u32 flags); struct iommu_device *(*probe_device)(struct device *dev); void (*release_device)(struct device *dev); diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index b4ba0c0cbab6..4a7c5c8fdbb4 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -347,10 +347,20 @@ struct iommu_vfio_ioas { }; #define IOMMU_VFIO_IOAS _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VFIO_IOAS) +/** + * enum iommufd_hwpt_alloc_flags - Flags for HWPT allocation + * @IOMMU_HWPT_ALLOC_NEST_PARENT: If set, allocate a domain which can serve + * as the parent domain in the nesting + * configuration. + */ +enum iommufd_hwpt_alloc_flags { + IOMMU_HWPT_ALLOC_NEST_PARENT = 1 << 0, +}; + /** * struct iommu_hwpt_alloc - ioctl(IOMMU_HWPT_ALLOC) * @size: sizeof(struct iommu_hwpt_alloc) - * @flags: Must be 0 + * @flags: Combination of enum iommufd_hwpt_alloc_flags * @dev_id: The device to allocate this HWPT for * @pt_id: The IOAS to connect this HWPT to * @out_hwpt_id: The ID of the new HWPT From patchwork Tue Sep 19 09:25:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 142003 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3548383vqi; Tue, 19 Sep 2023 10:13:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGAkX2WNeNQJc9BSuIpgjCKv6Ahhok9f2IRyXmm9AyFyVQb7ycK25Mu0CUs028dZmm2t6K/ X-Received: by 2002:a05:6a00:a1b:b0:68f:dfda:1814 with SMTP id p27-20020a056a000a1b00b0068fdfda1814mr399790pfh.18.1695143597257; Tue, 19 Sep 2023 10:13:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695143597; cv=none; d=google.com; s=arc-20160816; b=vxfn7WaMk+OlvNi3TJw6nvMsdELmzZvDCmD+bXFX5vKBmTm4gJNPlddKFkxrKlKVud ND/EgHtv9BEEgzxbkxDJBot7AACXg+MrP/6anFrbJHtF70ZiZ7ebvBEOEBN+LemuX3dH d9FMPimzSiIOKyyTI+fUSQg+5qmSVep4nvi6NVDrEHUHxexCPAYGFBRv37ljZZwd1gRj s9DGSQ4ZCIao4qk+VIFQockzuS9lqQCGnyLuFPK77/XvUz7NuZoT+3ZZpmBNsUjw7WFP ugY+a96QN18Rg1idkCd7losP7/UbN0Gp5+Fau3SsvbqrEEzay+Jh+FplC+zFqrmMw33z Zqmw== 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:date:subject:cc:to:from :dkim-signature; bh=5k8vQcR9Y700jDibsL6fBlemuEInlV0ExgbA4ifN46M=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=mmvqRE3FRXDJl+iVqgEHb0i6t8nAJLu9duyozE6nch3oxjQ7VofEGfLZryYuP7IY8R M6CHxn5xcxq3cWEuz87BJqbIHy/gkTJCVfSfD4LYYR7DJerQjQSAke2rUGYWfpnDNAD6 dpPizPNCdQjtzQ20trLz3UmNqYFbT09IsEbcDzCNLO3l7S0csM1SrkNABEh0CL8HbaWv zsevv4jmxePC8TpIdY/Aa+YEDp1VzkXIv0BquALkBZiDF16QWyttW/xYiOTSvUD0k6kQ l1pEiPrvBzGjr0yzPwYghTlQUgt8w2s9aNeBg9s47cu/WNGI6AyqeUuuh8xp+F9R/nbA 7r6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cEJ5ZlqR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id t9-20020a63d249000000b00565ecee8793si9951642pgi.875.2023.09.19.10.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 10:13:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cEJ5ZlqR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 6F7DF80A1496; Tue, 19 Sep 2023 02:26:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229921AbjISJ0N (ORCPT + 26 others); Tue, 19 Sep 2023 05:26:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231176AbjISJ0J (ORCPT ); Tue, 19 Sep 2023 05:26:09 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7325612E; Tue, 19 Sep 2023 02:25:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695115559; x=1726651559; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2u453SswpKakc0NOsEhGqMN9HDyZwW3XZ2U2N48J7YQ=; b=cEJ5ZlqRGQodnm+BbID6byANhSAcQS0D/pdTLSCsmafieJX3UnXg/Lh1 3/Awx24gTmqkRMF1nSsvUUKM0v7r75Ev/Wbz0DrTYIDUVmPmR5vPFgX/i 9AST63r2Kk6jz7/VWCDR9lH0r01wjAqjLLfKdwveMNcTUdb2j20YtMj9t IGqP1Epkys4WmqWgBme9FekHltzrLoaeCa1I2RXYVNjZ5tqLuOJCgN8/W 3JPL8tNXiLntg1+JLmJOUKdYcq/h/S2oPdTIVQ/DTeSi8rQxgbu4A3nZ8 iYrxhtb8BulAT9NpxXW0cuYeKKY8RR8HmMBVBiQ9AfU3G+ptrFn0tMp3I A==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="446368918" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="446368918" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 02:25:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="722804768" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="722804768" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga006.jf.intel.com with ESMTP; 19 Sep 2023 02:25:26 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [PATCH 2/6] iommufd/hw_pagetable: Use domain_alloc_user op for domain allocation Date: Tue, 19 Sep 2023 02:25:19 -0700 Message-Id: <20230919092523.39286-3-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230919092523.39286-1-yi.l.liu@intel.com> References: <20230919092523.39286-1-yi.l.liu@intel.com> MIME-Version: 1.0 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Tue, 19 Sep 2023 02:26:41 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777486892807019483 X-GMAIL-MSGID: 1777486892807019483 This makes IOMMUFD to use iommu_domain_alloc_user() for iommu_domain creation as IOMMUFD needs to support iommu_domain allocation with parameters from userspace in nested support. If the iommu driver doesn't provide domain_alloc_user callback then IOMMUFD falls back to use iommu_domain_alloc(). Suggested-by: Jason Gunthorpe Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian Co-developed-by: Nicolin Chen Signed-off-by: Nicolin Chen Signed-off-by: Yi Liu --- drivers/iommu/iommufd/hw_pagetable.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index cf2c1504e20d..48874f896521 100644 --- a/drivers/iommu/iommufd/hw_pagetable.c +++ b/drivers/iommu/iommufd/hw_pagetable.c @@ -5,6 +5,7 @@ #include #include +#include "../iommu-priv.h" #include "iommufd_private.h" void iommufd_hw_pagetable_destroy(struct iommufd_object *obj) @@ -74,6 +75,7 @@ struct iommufd_hw_pagetable * iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, struct iommufd_device *idev, bool immediate_attach) { + const struct iommu_ops *ops = dev_iommu_ops(idev->dev); struct iommufd_hw_pagetable *hwpt; int rc; @@ -88,10 +90,19 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, refcount_inc(&ioas->obj.users); hwpt->ioas = ioas; - hwpt->domain = iommu_domain_alloc(idev->dev->bus); - if (!hwpt->domain) { - rc = -ENOMEM; - goto out_abort; + if (ops->domain_alloc_user) { + hwpt->domain = ops->domain_alloc_user(idev->dev, 0); + if (IS_ERR(hwpt->domain)) { + rc = PTR_ERR(hwpt->domain); + hwpt->domain = NULL; + goto out_abort; + } + } else { + hwpt->domain = iommu_domain_alloc(idev->dev->bus); + if (!hwpt->domain) { + rc = -ENOMEM; + goto out_abort; + } } /* From patchwork Tue Sep 19 09:25:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 141985 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3507317vqi; Tue, 19 Sep 2023 09:13:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHW1xcU1eveLguWgvvszb+2ndrylkabBV46r2aI2W5rGm8LkxXhwJqKzpQ/fMZmcONZqWW/ X-Received: by 2002:a17:902:b710:b0:1c4:1b27:1cd6 with SMTP id d16-20020a170902b71000b001c41b271cd6mr9463809pls.26.1695139999881; Tue, 19 Sep 2023 09:13:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695139999; cv=none; d=google.com; s=arc-20160816; b=n/LIlSj73XJtUhVK64DFhr6NrkPneXV70SINlEdFo5Or1ccyJ4xx/4/ot5w0Dio6vY OnewEp0UCWD4qCCyQBqp6by8ilJIuAG7+ng16rmwPCT4npfssN5tXz8Bd7cknnmcwYQJ mPOJaCaOEa5r4ZInq/QLKy252596wGPbkgt4ovfitlpVmfHLkRIy1UFqM+nxPKeu+xzs NwDIwnicfLcwsJSC9LYg9p9FTJNELtMxjCBszQXfIVbLCxrhi4JVm+AqqyWeB7SOVbc9 MUNVGOwG/fXRSg91hEFP2g2UAYpXUC0FY7EFUUmP/jSI2EiEjbEfVKzDZV/OcCdJLf0m LnUQ== 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:date:subject:cc:to:from :dkim-signature; bh=rzLj9kamT4uCoY7kVVGpAReBPcRjfnhREDiGVpsrvGo=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=t2XKu8JqoiRnuZTIGiK7JJwC7ulrDYfraYUTDcPDmoDH2nhg4IUjMnTTIYL9w/qPUK padtuMpPgQA4DKFqu8eI36csBj0UPpcOEnkrNU6oDDUiCxDZwsiufFS8viegfhO96UR6 K40EIprUzkXt3g3cC4uyYuokab74Q3I//DE4PT3zYUnlTxDhTfydFwc8HnvBEYKrMXZW juv56Bro7xux0ky7BVYnNhEnLTBia6Z4il1QCw1yFVk/RG1BgalL7OG9CxkzPiO969nX vYPXTXMmRHm78l00utgkaoJ7AB8/HfMrcEovbNUDJrtNsWfKrw7xrNSUuOiGMbS0bfOa JokQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OkOXU2b6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id a7-20020a170902900700b001c3e500e6d4si9827527plp.344.2023.09.19.09.13.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 09:13:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OkOXU2b6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 65CEA8096A49; Tue, 19 Sep 2023 02:27:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231285AbjISJ0k (ORCPT + 26 others); Tue, 19 Sep 2023 05:26:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231388AbjISJ0V (ORCPT ); Tue, 19 Sep 2023 05:26:21 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 939E1102; Tue, 19 Sep 2023 02:26:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695115576; x=1726651576; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nqhafFsOTCXMpS7yBdxvrhkU6NiVVIo1xDbd9DzqNGI=; b=OkOXU2b60WA0DZ/h0Vh/3RZIuya4J47xG8j+efDmw9TUbxA9od6KmzCt fAndSzsyLlVcUyj1lVvrz+D+RqVI3Ax54STXAODerUFTM6+1dgObR9pXF qKKOASkMZIVvwsn9HWqO6OqcCoxawy/if/lxs2XHg6lgVSVwcP69y/lUG thxyv+0DxR87hVD0At4jbLbHKk9B1XUoKrIBK1LBmW76Sx+wB/0d6SjJk 8ur8Qijwhsu3nQuaINp29sVKeroVhPUyA22Ec0vkyOjg9eHxnwH6JQ8Ny efZWnEdx1EZZDwX6qK8+NR3DD02AddO/0yLt2tAoecW3cM8u1t3+qHlCY A==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="446368958" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="446368958" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 02:25:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="722804771" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="722804771" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga006.jf.intel.com with ESMTP; 19 Sep 2023 02:25:34 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [PATCH 3/6] iommufd/hw_pagetable: Accepts user flags for domain allocation Date: Tue, 19 Sep 2023 02:25:20 -0700 Message-Id: <20230919092523.39286-4-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230919092523.39286-1-yi.l.liu@intel.com> References: <20230919092523.39286-1-yi.l.liu@intel.com> MIME-Version: 1.0 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Tue, 19 Sep 2023 02:27:09 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777483120790746214 X-GMAIL-MSGID: 1777483120790746214 This extends iommufd_hw_pagetable_alloc() to accepts user flags. Signed-off-by: Yi Liu Reviewed-by: Kevin Tian --- drivers/iommu/iommufd/device.c | 2 +- drivers/iommu/iommufd/hw_pagetable.c | 9 ++++++--- drivers/iommu/iommufd/iommufd_private.h | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index ce78c3671539..e88fa73a45e6 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -540,7 +540,7 @@ iommufd_device_auto_get_domain(struct iommufd_device *idev, } hwpt = iommufd_hw_pagetable_alloc(idev->ictx, ioas, idev, - immediate_attach); + 0, immediate_attach); if (IS_ERR(hwpt)) { destroy_hwpt = ERR_CAST(hwpt); goto out_unlock; diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index 48874f896521..5be7a31cbd9c 100644 --- a/drivers/iommu/iommufd/hw_pagetable.c +++ b/drivers/iommu/iommufd/hw_pagetable.c @@ -61,6 +61,7 @@ int iommufd_hw_pagetable_enforce_cc(struct iommufd_hw_pagetable *hwpt) * @ictx: iommufd context * @ioas: IOAS to associate the domain with * @idev: Device to get an iommu_domain for + * @flags: Flags from userspace * @immediate_attach: True if idev should be attached to the hwpt * * Allocate a new iommu_domain and return it as a hw_pagetable. The HWPT @@ -73,7 +74,8 @@ int iommufd_hw_pagetable_enforce_cc(struct iommufd_hw_pagetable *hwpt) */ struct iommufd_hw_pagetable * iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, - struct iommufd_device *idev, bool immediate_attach) + struct iommufd_device *idev, u32 flags, + bool immediate_attach) { const struct iommu_ops *ops = dev_iommu_ops(idev->dev); struct iommufd_hw_pagetable *hwpt; @@ -91,7 +93,7 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, hwpt->ioas = ioas; if (ops->domain_alloc_user) { - hwpt->domain = ops->domain_alloc_user(idev->dev, 0); + hwpt->domain = ops->domain_alloc_user(idev->dev, flags); if (IS_ERR(hwpt->domain)) { rc = PTR_ERR(hwpt->domain); hwpt->domain = NULL; @@ -166,7 +168,8 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd) } mutex_lock(&ioas->mutex); - hwpt = iommufd_hw_pagetable_alloc(ucmd->ictx, ioas, idev, false); + hwpt = iommufd_hw_pagetable_alloc(ucmd->ictx, ioas, + idev, cmd->flags, false); if (IS_ERR(hwpt)) { rc = PTR_ERR(hwpt); goto out_unlock; diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 2c58670011fe..3064997a0181 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -242,7 +242,8 @@ struct iommufd_hw_pagetable { struct iommufd_hw_pagetable * iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, - struct iommufd_device *idev, bool immediate_attach); + struct iommufd_device *idev, u32 flags, + bool immediate_attach); int iommufd_hw_pagetable_enforce_cc(struct iommufd_hw_pagetable *hwpt); int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt, struct iommufd_device *idev); From patchwork Tue Sep 19 09:25:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 141781 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3244776vqi; Tue, 19 Sep 2023 02:32:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDvnbHhcH68mjooX32Y7wumeIt+KjalfoYusOamXrewcxC/S6CyddDaVL4Q2n7nvMOsGAA X-Received: by 2002:a05:6870:7027:b0:1d2:4b4c:eb11 with SMTP id u39-20020a056870702700b001d24b4ceb11mr14567072oae.32.1695115927836; Tue, 19 Sep 2023 02:32:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695115927; cv=none; d=google.com; s=arc-20160816; b=AQZhJssuRkzGu810uGwRsbt15zsZIJ5/kzmZ9yeMYDH8oCfZlfSBI3CPB3VvqVuwvv Ws1gLkfXA1uMxRAnoEoPEv+Y8SKysKAezBfPYkyZaxqSHJ+JG0TEplNJZVQ7q8G1nXoU DspUJbnyQsKKdMT2HR/8ORyxV4sGLHNrtxlYv78qv4tQrV1u2R6O7ZYLzrFC7Apo4+h3 lflp8n1oNfdZiFdCs1EhI5q1hErRTnNOGlcDLL5kqsooRoAcixf1QQIcBdZuPZzQLUzE GxQpDk8XeeROuWGkmJdSqx72QO0ABibxXXvIC56FWXWFABPEo2BzACT9F813ou9V7jCn 3HTQ== 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:date:subject:cc:to:from :dkim-signature; bh=Za4EkxBilisrWScE5f7iblx6T9qB1xELBkJ/ylhGX2A=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=uIxhPpUlKd5criBEfUmJKVhj/LRbuFFu0qQaFreVI6SCBqlh6fILza3JdaDtdKVIWp By2WmujMsCXeCyX1ZXFqaOyc3yu67tRIx5GnoA2y9vv2bMw0V3O16cdePfBEk9qFGVTJ Rph7jcNUBKW4PrTgHP0KPiWRUIuDYZcMkexWzSeo1+GCo+4MiPnZ2o8ZQiy7XLyhfAOL CUaDVjlK7osfpyvMPlBUpVpvci18dqveCOnZnr5Vu8bWKa5UaXveYgq/yhDC3vrWeIo3 5PoCmn47zZSUZ42Y0BD9wIZe3YWjiN4jwnK9aXsOw4M99FN8SfyiyyzSViRpQNGepSbY t8Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SxEwXDz+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id r15-20020a638f4f000000b005775613e206si9416038pgn.507.2023.09.19.02.32.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 02:32:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SxEwXDz+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 2606C8182EE1; Tue, 19 Sep 2023 02:26:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231414AbjISJ0Z (ORCPT + 26 others); Tue, 19 Sep 2023 05:26:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231261AbjISJ0U (ORCPT ); Tue, 19 Sep 2023 05:26:20 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59984134; Tue, 19 Sep 2023 02:26:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695115573; x=1726651573; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q66OHCFRu99evLMCHuExKGxiNMAzbw1601UJQaxYYqQ=; b=SxEwXDz+jalvWe/dutrmWsSyZEo1t4MwJCSVo4ZcJjd7SiGvrivuok03 mWCpZ0VUbJWyub9fzTdF2CfCHOZgWGK02iDOiFLkniNnnNmadyVMXZJE7 UrtC7VXOBRud+FkfLTLdPBOnhLaHsLebLHju2Y3XTPbIZvkZXKTAd6FFP rggKnkWOXzI/SXx9dGlE458WzuGfhNRodh1hpsakeYG61u2EwBbXj1G0e uksDIwQRNylTtHUVx+8/9fjFzYhacLrz1BaxnHdQzZjYnhvQp5WImiTkj 6v1DamzK7dyvl0SaAYTxDuW+P5X1PnR6g99Bu2io0DTRTcNjbzg2uF0lk g==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="446368928" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="446368928" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 02:25:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="722804772" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="722804772" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga006.jf.intel.com with ESMTP; 19 Sep 2023 02:25:34 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [PATCH 4/6] iommufd/hw_pagetable: Support allocating nested parent domain Date: Tue, 19 Sep 2023 02:25:21 -0700 Message-Id: <20230919092523.39286-5-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230919092523.39286-1-yi.l.liu@intel.com> References: <20230919092523.39286-1-yi.l.liu@intel.com> MIME-Version: 1.0 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Tue, 19 Sep 2023 02:26:54 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777457879029452292 X-GMAIL-MSGID: 1777457879029452292 This extends IOMMU_HWPT_ALLOC to allocate domains used as parent (stage-2) in nested translation. Signed-off-by: Yi Liu --- drivers/iommu/iommufd/hw_pagetable.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index 5be7a31cbd9c..26a8a818ffa3 100644 --- a/drivers/iommu/iommufd/hw_pagetable.c +++ b/drivers/iommu/iommufd/hw_pagetable.c @@ -83,6 +83,9 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, lockdep_assert_held(&ioas->mutex); + if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ops->domain_alloc_user) + return ERR_PTR(-EOPNOTSUPP); + hwpt = iommufd_object_alloc(ictx, hwpt, IOMMUFD_OBJ_HW_PAGETABLE); if (IS_ERR(hwpt)) return hwpt; @@ -154,7 +157,7 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd) struct iommufd_ioas *ioas; int rc; - if (cmd->flags || cmd->__reserved) + if (cmd->flags & ~IOMMU_HWPT_ALLOC_NEST_PARENT || cmd->__reserved) return -EOPNOTSUPP; idev = iommufd_get_device(ucmd, cmd->dev_id); From patchwork Tue Sep 19 09:25:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 141863 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3348532vqi; Tue, 19 Sep 2023 05:33:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9NPGGkiZPI7aKaTt4D8x1L4ixY4t0txEJgoU4L8uCskAV11dhtvzEK5MwmKqIglHx/HQf X-Received: by 2002:a05:6a21:4849:b0:14d:396e:6e1c with SMTP id au9-20020a056a21484900b0014d396e6e1cmr9163352pzc.28.1695126816372; Tue, 19 Sep 2023 05:33:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695126816; cv=none; d=google.com; s=arc-20160816; b=v1VZEawW7kuYye95dqjabbWEMZJ+r1p0dT30Otm7TvQrp9Xrn2l/PjEBqsnZ+xxMiT +Uk6n1pG06Z9uluzJLkq2vCnmYPpQYM7nO7Fxt7aJMFCs1FLR65+c+nhkwp/hTHB5bi8 L6gvCqbwzjGGzeHxuKFLzxZMWS0IWNNRiIS5Db/zyZLWgb5ZE/+rnA2G8Kxye2WDJaUG 2w5ti+5pP7TX7MyR4ORIuDtKp6Lo6okjFkO1sFp5ZPacDCFfNIaJPoee7PqFeuh8rpFq OXekBvrLpnPFen9OuVFpXpvNO0/rRxh0ykGJCeYTf5IQh1j0C1KhEJdX4PfpEQ9i0lCl RHsg== 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:date:subject:cc:to:from :dkim-signature; bh=VUEpYQFWk0U+oIDO9ZSEBO3wIvZaz6zBmOYDmVqm9cQ=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=z2UHGl4zaUwgGQ31R3f6E1i9Ih6GjtUQNIz4FHbDJKTfMu1SFI/Q/IjDJyenIOwWsP PGwPKBe7piNmdpMh2oZMrVpXBJ8Jf8ZcZgIPV5Rfj8LlTGF+H3q7/kgV8W5JxErIMyly UQSv3YJJdV8yyl/7if84OcLxHsAWLQJXRMa4oSV9LsM0RbMmRBh+y5zNEjsPyUXdSGm9 13ZmAusOAjcGnJ06TCqSij7UbDcTkWsS8TPRoyCQWagivlitVkuD3ZtdSUmutaV2xQ+h 1gBKfmMohEzLLeNy7lyoWt8Z68oG6uwrBusfNExDuzxrR37MUBB1LLT6ime9rQuBe3xH clmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GhTLeuqv; 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 i6-20020a639d06000000b0057772079a9bsi9633940pgd.662.2023.09.19.05.33.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 05:33:36 -0700 (PDT) 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=GhTLeuqv; 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 351178086520; Tue, 19 Sep 2023 02:27:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231531AbjISJ03 (ORCPT + 26 others); Tue, 19 Sep 2023 05:26:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231464AbjISJ0U (ORCPT ); Tue, 19 Sep 2023 05:26:20 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F68B12E; Tue, 19 Sep 2023 02:26:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695115573; x=1726651573; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MWn2F4rKZbZokQaf2eQ2te2+YDIyfqcOhEHVKn5AcUI=; b=GhTLeuqvsH7Vh8XFvt3MyP8BV2hjCIqZDNgLwSDo05mqSoLtOU87qpBx i7RU876nkUzCJmSoOOgsep2JWoUS+9Yue4407Ci52paqeOvI2sXtbhewS /N5jLDwP1wovTc4EXu5Ma6frldeyQNNF8cM/R4YK0w3wsb/DVReqLlbrj ewUSSd5uQAKkiKthlRb5MXKYUC4mEhWgPbA76WvbBjyFS2T7eoVlWh5V6 wBjGU2cITyke2nYqa0wGy2HFsYbPlARI/2/FyamVur3w7SQiRK7BKSVvM IB5ILVt8+IzVGNzKtIGXVmmVuwaJsBcQzyiwW+lnzopWzFsDbgXyNjKta g==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="446368946" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="446368946" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 02:25:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="722804774" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="722804774" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga006.jf.intel.com with ESMTP; 19 Sep 2023 02:25:35 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [PATCH 5/6] iommufd/selftest: Add domain_alloc_user() support in iommu mock Date: Tue, 19 Sep 2023 02:25:22 -0700 Message-Id: <20230919092523.39286-6-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230919092523.39286-1-yi.l.liu@intel.com> References: <20230919092523.39286-1-yi.l.liu@intel.com> MIME-Version: 1.0 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 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]); Tue, 19 Sep 2023 02:27:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777469296783051448 X-GMAIL-MSGID: 1777469296783051448 This adds mock_domain_alloc_user function and also new test case for the new flag IOMMU_HWPT_ALLOC_NEST_PARENT. Signed-off-by: Yi Liu --- drivers/iommu/iommufd/selftest.c | 16 +++++++++++++ tools/testing/selftests/iommu/iommufd.c | 24 +++++++++++++++---- .../selftests/iommu/iommufd_fail_nth.c | 2 +- tools/testing/selftests/iommu/iommufd_utils.h | 11 ++++++--- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index 56506d5753f1..b54cbfb1862b 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -146,6 +146,8 @@ static void *mock_domain_hw_info(struct device *dev, u32 *length, u32 *type) return info; } +static const struct iommu_ops mock_ops; + static struct iommu_domain *mock_domain_alloc(unsigned int iommu_domain_type) { struct mock_iommu_domain *mock; @@ -162,10 +164,23 @@ static struct iommu_domain *mock_domain_alloc(unsigned int iommu_domain_type) mock->domain.geometry.aperture_start = MOCK_APERTURE_START; mock->domain.geometry.aperture_end = MOCK_APERTURE_LAST; mock->domain.pgsize_bitmap = MOCK_IO_PAGE_SIZE; + mock->domain.ops = mock_ops.default_domain_ops; + mock->domain.type = iommu_domain_type; xa_init(&mock->pfns); return &mock->domain; } +static struct iommu_domain * +mock_domain_alloc_user(struct device *dev, u32 flags) +{ + struct iommu_domain *domain; + + domain = mock_domain_alloc(IOMMU_DOMAIN_UNMANAGED); + if (!domain) + domain = ERR_PTR(-ENOMEM); + return domain; +} + static void mock_domain_free(struct iommu_domain *domain) { struct mock_iommu_domain *mock = @@ -307,6 +322,7 @@ static const struct iommu_ops mock_ops = { .pgsize_bitmap = MOCK_IO_PAGE_SIZE, .hw_info = mock_domain_hw_info, .domain_alloc = mock_domain_alloc, + .domain_alloc_user = mock_domain_alloc_user, .capable = mock_domain_capable, .set_platform_dma_ops = mock_domain_set_plaform_dma_ops, .device_group = generic_device_group, diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index 9f705c1ea30f..9c129e63d7c7 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -114,6 +114,7 @@ TEST_F(iommufd, cmd_length) TEST_LENGTH(iommu_destroy, IOMMU_DESTROY); TEST_LENGTH(iommu_hw_info, IOMMU_GET_HW_INFO); + TEST_LENGTH(iommu_hwpt_alloc, IOMMU_HWPT_ALLOC); TEST_LENGTH(iommu_ioas_alloc, IOMMU_IOAS_ALLOC); TEST_LENGTH(iommu_ioas_iova_ranges, IOMMU_IOAS_IOVA_RANGES); TEST_LENGTH(iommu_ioas_allow_iovas, IOMMU_IOAS_ALLOW_IOVAS); @@ -1404,13 +1405,28 @@ TEST_F(iommufd_mock_domain, alloc_hwpt) int i; for (i = 0; i != variant->mock_domains; i++) { + uint32_t hwpt_id[2]; uint32_t stddev_id; - uint32_t hwpt_id; - test_cmd_hwpt_alloc(self->idev_ids[i], self->ioas_id, &hwpt_id); - test_cmd_mock_domain(hwpt_id, &stddev_id, NULL, NULL); + test_err_hwpt_alloc(EOPNOTSUPP, + self->idev_ids[i], self->ioas_id, + ~IOMMU_HWPT_ALLOC_NEST_PARENT, &hwpt_id[0]); + test_cmd_hwpt_alloc(self->idev_ids[i], self->ioas_id, + 0, &hwpt_id[0]); + test_cmd_hwpt_alloc(self->idev_ids[i], self->ioas_id, + IOMMU_HWPT_ALLOC_NEST_PARENT, &hwpt_id[1]); + + /* Do a hw_pagetable rotation test */ + test_cmd_mock_domain_replace(self->stdev_ids[i], hwpt_id[0]); + EXPECT_ERRNO(EBUSY, _test_ioctl_destroy(self->fd, hwpt_id[0])); + test_cmd_mock_domain_replace(self->stdev_ids[i], hwpt_id[1]); + EXPECT_ERRNO(EBUSY, _test_ioctl_destroy(self->fd, hwpt_id[1])); + test_cmd_mock_domain_replace(self->stdev_ids[i], self->ioas_id); + test_ioctl_destroy(hwpt_id[1]); + + test_cmd_mock_domain(hwpt_id[0], &stddev_id, NULL, NULL); test_ioctl_destroy(stddev_id); - test_ioctl_destroy(hwpt_id); + test_ioctl_destroy(hwpt_id[0]); } } diff --git a/tools/testing/selftests/iommu/iommufd_fail_nth.c b/tools/testing/selftests/iommu/iommufd_fail_nth.c index a220ca2a689d..3d7838506bfe 100644 --- a/tools/testing/selftests/iommu/iommufd_fail_nth.c +++ b/tools/testing/selftests/iommu/iommufd_fail_nth.c @@ -615,7 +615,7 @@ TEST_FAIL_NTH(basic_fail_nth, device) if (_test_cmd_get_hw_info(self->fd, idev_id, &info, sizeof(info))) return -1; - if (_test_cmd_hwpt_alloc(self->fd, idev_id, ioas_id, &hwpt_id)) + if (_test_cmd_hwpt_alloc(self->fd, idev_id, ioas_id, 0, &hwpt_id)) return -1; if (_test_cmd_mock_domain_replace(self->fd, stdev_id, ioas_id2, NULL)) diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index e0753d03ecaa..be4970a84977 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -103,10 +103,11 @@ static int _test_cmd_mock_domain_replace(int fd, __u32 stdev_id, __u32 pt_id, pt_id, NULL)) static int _test_cmd_hwpt_alloc(int fd, __u32 device_id, __u32 pt_id, - __u32 *hwpt_id) + __u32 flags, __u32 *hwpt_id) { struct iommu_hwpt_alloc cmd = { .size = sizeof(cmd), + .flags = flags, .dev_id = device_id, .pt_id = pt_id, }; @@ -120,8 +121,12 @@ static int _test_cmd_hwpt_alloc(int fd, __u32 device_id, __u32 pt_id, return 0; } -#define test_cmd_hwpt_alloc(device_id, pt_id, hwpt_id) \ - ASSERT_EQ(0, _test_cmd_hwpt_alloc(self->fd, device_id, pt_id, hwpt_id)) +#define test_cmd_hwpt_alloc(device_id, pt_id, flags, hwpt_id) \ + ASSERT_EQ(0, _test_cmd_hwpt_alloc(self->fd, device_id, \ + pt_id, flags, hwpt_id)) +#define test_err_hwpt_alloc(_errno, device_id, pt_id, flags, hwpt_id) \ + EXPECT_ERRNO(_errno, _test_cmd_hwpt_alloc(self->fd, device_id, \ + pt_id, flags, hwpt_id)) static int _test_cmd_access_replace_ioas(int fd, __u32 access_id, unsigned int ioas_id) From patchwork Tue Sep 19 09:25:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 141778 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3242930vqi; Tue, 19 Sep 2023 02:27:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFO1QraCWsoeZqzJCSHemfMSiBH9fwgN4aek64H7cMqb+QbnbJ6+Ul9UXvzmb5zwIJ169aX X-Received: by 2002:a05:6871:4584:b0:1d6:7449:e0dc with SMTP id nl4-20020a056871458400b001d67449e0dcmr8732038oab.20.1695115677778; Tue, 19 Sep 2023 02:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695115677; cv=none; d=google.com; s=arc-20160816; b=VBSPizspkBZtADFaihoycow/bHDyaOs8Zf1Tzfzb/qndVuekO9qJe/MEuZLuNw+kll Dqz36VIGM/XLV8CT3Y1qmYdqMI/OUhp/Qa63zmFIdwWuICQnqntE0CGrAqwZfComN70L Kxz7ZaFWLomzNgzOQZmuhrCi1HP6/sP878l9Y0rIFzI8TaiFHBsBFDNUBBYLlMKxWIGu Omg/krUtUkNjOwpJhfldxvzo1whACdpg7BRpKPiZVyWdvF68wc2mM7nh1ItDxqmcGmn1 iMenVI9OWEH9hc7HSxLwFCCbih9rnCRyDzaAwQMQ3EG+sVGurRw6tAueE9ivIPKM8My0 ulgg== 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:date:subject:cc:to:from :dkim-signature; bh=qkK7YV873sVdW51UZUIcTDcFfYXiu8MriT05qvT7mbc=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=Zp9VK7Wt18xEEN9ayMpQtMnYPkUCode7k09gISyz/DdoHmHZa/RihcR198YBGvHtET Rgqpdx54f2g9dC8VDtVbKCdJBh/sH8G0RZMSocKKkRQqiLEMTC3cjKnifZQmqu068yPh dyvGvtnU9Z1y/iPyX2Pr1N6y5izPEzok5MeMDb6QSCdoJ85CHDKpvD+T7/4eMpyUmqmi waeM7By07lYv/Beem9rk9P0hfp+f5mSVnrMwtAmW1/uAkw9UYcP787erzbdiNwVtg81F blR549ASl2+xL9lmvrVRQlbrXi8SVpxU8kNzcJNYZZbXyydrcnRclfYX2P8Dall025GB rrlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CHAn9QRK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id t23-20020a656097000000b0056569ee3ae6si9098383pgu.798.2023.09.19.02.27.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 02:27:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CHAn9QRK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 6E31680A138A; Tue, 19 Sep 2023 02:26:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229674AbjISJ0f (ORCPT + 26 others); Tue, 19 Sep 2023 05:26:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231436AbjISJ0W (ORCPT ); Tue, 19 Sep 2023 05:26:22 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52CA9F2; Tue, 19 Sep 2023 02:26:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695115576; x=1726651576; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W3riUZjJN8lKSKgwdYFNtz+cVKj5BdWi3nncFILY6lA=; b=CHAn9QRKv3H3tDCiTWgLAvQCce/ncVyy1qkQ1UoZ+ThsxQWzC+w1kfXb SFwRzv3OBav2+J3ai7Ayn9IjzF+TNRR1G0zM3dqPPqW9XsAme7XgnSGlm shn8TPCMJB7GHzWBSkGw7F++rW13hhE6VTFGcyEElqrAsG3j0tTfhrVon jQkL7u2kACsx/huk51IJWALf/d4if/4CwUr2jpmLSADaTD2aljTvlX72M nAUdIyPJauSCzg6ra/zXhK+mFMiBI2n/Xhf60G64XVbegVr0gkF8H5E/l 0HksFpgr9vXCaMdJl6pfCkgTy2AKFaX7S94eTSko2j1Rh3STA8aoz8vvE w==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="446368969" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="446368969" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 02:25:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="722804776" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="722804776" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga006.jf.intel.com with ESMTP; 19 Sep 2023 02:25:36 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [PATCH 6/6] iommu/vt-d: Add domain_alloc_user op Date: Tue, 19 Sep 2023 02:25:23 -0700 Message-Id: <20230919092523.39286-7-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230919092523.39286-1-yi.l.liu@intel.com> References: <20230919092523.39286-1-yi.l.liu@intel.com> MIME-Version: 1.0 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Tue, 19 Sep 2023 02:26:43 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777457616960079769 X-GMAIL-MSGID: 1777457616960079769 This adds the domain_alloc_user op implementation. It supports allocating domains to be used as parent under nested translation. Signed-off-by: Yi Liu --- drivers/iommu/intel/iommu.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 5db283c17e0d..491bcde1ff96 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4074,6 +4074,25 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) return NULL; } +static struct iommu_domain * +intel_iommu_domain_alloc_user(struct device *dev, u32 flags) +{ + struct iommu_domain *domain; + struct intel_iommu *iommu; + + iommu = device_to_iommu(dev, NULL, NULL); + if (!iommu) + return ERR_PTR(-ENODEV); + + if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ecap_nest(iommu->ecap)) + return ERR_PTR(-EOPNOTSUPP); + + domain = iommu_domain_alloc(dev->bus); + if (!domain) + domain = ERR_PTR(-ENOMEM); + return domain; +} + static void intel_iommu_domain_free(struct iommu_domain *domain) { if (domain != &si_domain->domain && domain != &blocking_domain) @@ -4807,6 +4826,7 @@ const struct iommu_ops intel_iommu_ops = { .capable = intel_iommu_capable, .hw_info = intel_iommu_hw_info, .domain_alloc = intel_iommu_domain_alloc, + .domain_alloc_user = intel_iommu_domain_alloc_user, .probe_device = intel_iommu_probe_device, .probe_finalize = intel_iommu_probe_finalize, .release_device = intel_iommu_release_device,