From patchwork Thu Sep 28 07:15: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: 145983 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3233495vqu; Thu, 28 Sep 2023 04:19:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/s1Trruh1q5mLx+rOKRYJkKu2gaQ+22epUR6cBPrMxVRir60H0/9IRtzCEW/Yaxm9FJG1 X-Received: by 2002:a17:90a:b015:b0:26d:61:3aad with SMTP id x21-20020a17090ab01500b0026d00613aadmr768320pjq.4.1695899990824; Thu, 28 Sep 2023 04:19:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695899990; cv=none; d=google.com; s=arc-20160816; b=t1z47FdOeLBf1yY2Ub3ZUYCNMYfguhnGU+mztGY7RaLmrvd0Fd9MTivJkiXn5L5ki7 D5J4zC4Z0mPCZGLlQgPivzfn7/biQnYWxqUF8W+e3cepwsMdkaIj5kSvfe51g+n35+fQ p7vJSaQP0/utMXsxYNbnBH18K9a5ddIRv8Rv8pb5FmEiOrC5wg0GAO0Kn7u8EqPqqAUB DNoCLhBf3W7IpGuQd2hWc5Xe5U1k6gEw3oPGY4myfRFm47s4RyYXKv+JuSNpiRw7YeEe LCGgcon/rEQwS+IQKbGwCcOLgv8zst5Tk8QhMHXrX4P/rMmuzTsaPusXWbkyyOIma8j9 /LIQ== 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=2y0+VNX1QXSRRDn0t918JCsJegvkzy8Q8HXWPeE4kI8=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=0IZdoZptmhaNua7dcF/CVwdz0obylBJRZP3rPDGhZOBmKpbsK06w8D9A8rW5dBG1nA g0r2Tga2ShuixyoI8KxGd2qeTSabZivuM9+6NMnHvoQYtMpoh0EVtC0wc9gxukXGke+w uPNcZl2fKz0nMdXwMLlkV2kLV2+MHQV+YhEq2KpCpjwRvUnC3eiAhLH/rV9dUuiEpXmZ bkrgRDF8XlRifZbhXfuiNn5uANUX7A7qWVXthXVR4pqPeBjeCSy9L6S9gLpoLDWsMzfT Ql4lvojpK8whfAG1NCys0WNpnmoYC1MSGChK2iki16/2t86k1zbiuuDs3HIWug/KVZzC Rt3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZMz6z7oY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id c4-20020a17090a674400b0026b51ae4574si7205874pjm.36.2023.09.28.04.19.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 04:19:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZMz6z7oY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 5E4D582C92F8; Thu, 28 Sep 2023 00:15:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231156AbjI1HPj (ORCPT + 20 others); Thu, 28 Sep 2023 03:15:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231276AbjI1HPe (ORCPT ); Thu, 28 Sep 2023 03:15:34 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2F901B5; Thu, 28 Sep 2023 00:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695885332; x=1727421332; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=19oLqUtwSE9KQwWhP3qN2eLoUKpEnDmNF77eh1iFefY=; b=ZMz6z7oYm22qq7jjCQEA7Pv5OKKQRvVGG97/dCMeT0usd82JAcTkFnKg TnUlHIgXv+R/9ozjsmdVHxv2oeUG8LjdouJ3trktr0QiYj39H5aQmRO8A MHDqDO7oEOUHwKPHzY7A4k5eTVyGtnnlLomfPzg+0G+TLylzzq2SUf59V W87YIzov6BpNTaKxHuu/DNzQdp0Za0C4pnCrPykfi/g0/7hteonB32YdO Vn08kXGO1VrFB20KPg2Eyksw7yyMrzbs9Izp1kg5y1TynL7t21KPN9QHM gvUrraGsgNdu+lILE2KDs+vJpCj3SM08LlxtLyUkOlb4ka+XQNSY/31W0 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="412914825" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="412914825" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2023 00:15:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="784601963" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="784601963" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga001.jf.intel.com with ESMTP; 28 Sep 2023 00:15:31 -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 v2 1/6] iommu: Add new iommu op to create domains owned by userspace Date: Thu, 28 Sep 2023 00:15:23 -0700 Message-Id: <20230928071528.26258-2-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230928071528.26258-1-yi.l.liu@intel.com> References: <20230928071528.26258-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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]); Thu, 28 Sep 2023 00:15:44 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778280028505777489 X-GMAIL-MSGID: 1778280028505777489 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 Reviewed-by: Kevin Tian --- include/linux/iommu.h | 11 ++++++++++- include/uapi/linux/iommufd.h | 12 +++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index c50a769d569a..3861d66b65c1 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -234,7 +234,15 @@ struct iommu_iotlb_gather { * op is allocated in the iommu driver and freed by the caller after * 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: allocate and return an iommu domain if success. Otherwise + * NULL is returned. The domain is not fully initialized until + * the caller iommu_domain_alloc() returns. + * @domain_alloc_user: Allocate an iommu domain corresponding to the input + * parameters as defined in include/uapi/linux/iommufd.h. + * Unlike @domain_alloc, it is called only by IOMMUFD and + * must fully initialize the new domain before return. + * 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 +275,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 Thu Sep 28 07:15:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 146246 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3503195vqu; Thu, 28 Sep 2023 11:08:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVjs1hsU121qEDeutDc9rocRMAfFRghzzM7reRoQ6mDYLj4V8ZoDASveBN6vEHF8egZDyZ X-Received: by 2002:a05:6870:1815:b0:1d6:65d1:7989 with SMTP id t21-20020a056870181500b001d665d17989mr2257325oaf.24.1695924519534; Thu, 28 Sep 2023 11:08:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695924519; cv=none; d=google.com; s=arc-20160816; b=wyAH1v+7pY0PcNAt/E4601gw/hyl7cnCNBkMwdzvbRGPvbw6uDlVuM51gAQcMykBSV C7eMMEKUMTXWrRhXzHkikhLSBGsuaAfcQrPonrHzOHp/EnUVLktsmt/l0KJP5YIp+0tK ovwRIdatnur7xOAxjuAItbQ5eY02THf3j5J294ZLiNieIpcok8uCLmlSDYQFjH58455k b4hil4zSuWbu0wW/VT/fPU20NIZQmp5+z3j1stDnKvl2gtMVIrn6OkZ2v+SY55kxPqfY 3KC0jsvZ2wR6qGXr0Cr71QcBu0VvgfEyvw0Ywr0fHjkh3uHI0kO/68QEjCTLGI52OT5Q ZHTg== 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=1C8MC5VZQA2hu1oaMgBguNv/m/esGQVWCeab4v6z2d3kN6LZJQZQbCv/DtOP5ksxeu G1ob+sHT/0D8Dv0clSDV0MeWcMuk9wafH/ta3N9ah54247/lYyiC82lK5HJBpVR7KVYc FWHdiqSIE9a1k5g7nGU2UQHJNEui6tJegBGO4V+22qt2YeZkdwfwEggME12ahui3NZhl vNbpFW1OPMTU8yR05RmmCu7i+Z+n0PB87aONCFxmO6wKlLwRK0heUEpG38xiNfP2ny/M kfC08kKxDn2634sF/Rq7CZlfxbDAIxo3z9KKcTIIphvGVzUccIE6CNEiVrSA2AzUF3zv inIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bRsbCqsj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id y184-20020a638ac1000000b00565660b78d3si18663316pgd.591.2023.09.28.11.08.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 11:08:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bRsbCqsj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 37C0D8115461; Thu, 28 Sep 2023 00:17:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231444AbjI1HPo (ORCPT + 20 others); Thu, 28 Sep 2023 03:15:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231271AbjI1HPe (ORCPT ); Thu, 28 Sep 2023 03:15:34 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53018CC1; Thu, 28 Sep 2023 00:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695885333; x=1727421333; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2u453SswpKakc0NOsEhGqMN9HDyZwW3XZ2U2N48J7YQ=; b=bRsbCqsjStpeOY40igeSQZ4spXGTYYTWuUKvdeoYZs62TCLPt1YULpgU LcKQPS7tc4INFyeVZhEMPsvc9BXZMNgqnIXKONItbL11a8Zh8T7345ynp 1wEE/kjYSNqRY5pRgi/8XYqgNVZ4m0zOiJr6L61mce8sZ3AtrgIWKqUkn HFo8kGxEZrZN3cxXWF3GWyQjgdknUCxvW+eUzduk7P1c7hC20amszj/P/ 5YwivSCByqLcL9lF6geeltn3HpV0G4vpXCzw9I8mT5e6jyjs6H0N9Nqwb dpf0iT+5ps/bGvNWsFuXOXIsikcYVroESs/YiFlbejQCvt8DD+aaZazs9 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="412914835" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="412914835" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2023 00:15:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="784601980" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="784601980" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga001.jf.intel.com with ESMTP; 28 Sep 2023 00:15:32 -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 v2 2/6] iommufd/hw_pagetable: Use domain_alloc_user op for domain allocation Date: Thu, 28 Sep 2023 00:15:24 -0700 Message-Id: <20230928071528.26258-3-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230928071528.26258-1-yi.l.liu@intel.com> References: <20230928071528.26258-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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 28 Sep 2023 00:17:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778305749013981478 X-GMAIL-MSGID: 1778305749013981478 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 Thu Sep 28 07:15:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 146101 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3290793vqu; Thu, 28 Sep 2023 05:59:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7QZjUyAX0xFOH9H3QyBF2uPk9NmtCO+YnuTeVvgOHqGGIzNaCL6lTiAWfvocJbJPGo3NI X-Received: by 2002:a05:6808:1495:b0:3ab:7f46:ecc5 with SMTP id e21-20020a056808149500b003ab7f46ecc5mr1336930oiw.35.1695905980197; Thu, 28 Sep 2023 05:59:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695905980; cv=none; d=google.com; s=arc-20160816; b=XrN+enS4VnxZv8gwQiJiuTdHorg/XjNxBm/KABNYEh1UXM3uTgZ3sSuSG5T8a4eLIl fRb4lVbmubf40Qg6u2VYZcL0qVuFlKVRQwYJWWnH9MP5nLHzx4Y6H88opQcxZW5GMaAI VjI/3ktbAeYnqlg8C35TeS6rbUK5CNqrl9PY34so7wzIll06Xxix2XzFyMY0SNiEhhnA sHzUDuWit/aupjGWbHyZ0yjPFlgS13fIbGGt34n/iVyPQPr8yjQYQQiLZGQNZivOIILK pZHVeXYytYdYqeFKFsT8h6F5YFLtVdrsEBToB5nBNJGSC4sIHZEAxqEB8tmEibvRRkrt Rv0Q== 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=rs2e1cOhZfU9JOGttBA4eLtZJQ6JMUANi0yRgxvF+jg=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=spenMR1kQgyxwX/RAgSsT1O8zPhzP+pJgbtnqyZKqVQRXOU1dpA/jc3sGXuGcRdS3L F4Cm/aj11yLm4CFgsMFAXFD2/iluQs+ThpBCFIMew8RJK+W26YbjF0vylS7GAkPHre49 NrVrmq6hHF2bznMgY25YATct68K9OuEnfXLFNPSNWqUEki+izxfOmLVOue6OIr7kHy5O wajvzFYDIVilnEJR+Az24wcSl65+hPHVifCFJyWUFA6ghRUfAJNkzrk7vGUXiyd67vGB J2is0Cc3IWnVyZbAQzPW/lo3yojmKj2ASpFSKiKWfsmn6wrCruEBvr3fqMnGTvwGblU5 nBZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gjdAgFkV; 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l73-20020a63914c000000b0055be9526b7fsi18550253pge.416.2023.09.28.05.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 05:59:40 -0700 (PDT) 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=gjdAgFkV; 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 A547E82CAC1F; Thu, 28 Sep 2023 00:16:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231156AbjI1HPy (ORCPT + 20 others); Thu, 28 Sep 2023 03:15:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230111AbjI1HPi (ORCPT ); Thu, 28 Sep 2023 03:15:38 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8C5CBE; Thu, 28 Sep 2023 00:15:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695885336; x=1727421336; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZbmgDv3TXndc8FlXP9Hwf4R9VBmB58wZHJMvSo5a+l0=; b=gjdAgFkVgRl0ElXuSJwdw/itOZoSd78eqpmQIjiCSOyZRmuojwyUbHpi 3MWY94UpS2Rtl9CGAjRcYPZpjFIx0duE3Xb8rdet4/tVnDTypiTgshs11 vbehTu7KaN+pFRwrb/Ch1ieYutZ717r8CGcCYf9pshrOoPTPj3Ktv7OEB u1+5hZvSfUGt+xyKQzeSw/wUva9vrDyO+wZN9A8IbOhmU2/X68yNdsMOf YkUyhxdk2qKcVuuX//+jd5bqUthy4V9erlq8pvc6ophwTzqtS3xT1QyGL JGOE6Jic13oKAOqRz+vXNEZ5g7jC7H4XPiWhX6S7mZPJtbAtYN0PP8DWs w==; X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="412914850" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="412914850" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2023 00:15:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="784602027" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="784602027" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga001.jf.intel.com with ESMTP; 28 Sep 2023 00:15:33 -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 v2 3/6] iommufd/hw_pagetable: Accepts user flags for domain allocation Date: Thu, 28 Sep 2023 00:15:25 -0700 Message-Id: <20230928071528.26258-4-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230928071528.26258-1-yi.l.liu@intel.com> References: <20230928071528.26258-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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]); Thu, 28 Sep 2023 00:16:00 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778286309190800762 X-GMAIL-MSGID: 1778286309190800762 This extends iommufd_hw_pagetable_alloc() to accepts user flags. Reviewed-by: Kevin Tian Signed-off-by: Yi Liu Reviewed-by: Lu Baolu --- 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 Thu Sep 28 07:15:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 146235 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3488942vqu; Thu, 28 Sep 2023 10:45:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTqB4i4bGdlnuMWuRNgRuB1DEGsmlRy1Ikl7YRgX8KgF0ZNuI93Gq5veDAsIhddMS6gstF X-Received: by 2002:a05:6a20:8e0a:b0:133:bbe0:312f with SMTP id y10-20020a056a208e0a00b00133bbe0312fmr2206335pzj.50.1695923144832; Thu, 28 Sep 2023 10:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695923144; cv=none; d=google.com; s=arc-20160816; b=nguSzGnm5C63N2HhKSLB4I8sitUV10HBV0g5KJFCdRlWCxb1nbWH0cOnotQiWdu90E BQDH2WvvOe8qdgYatBxFX6gOkAnzmQblp6pZF16SgI7obmk07Vwutl/zZWA0OTOV09Zw PvogtMutX8ZoOEG8m9iILOqbNR7apcvT8VFV2V5q1oWHplYLM8Jmm/W01CtcvLZBdk2s hBE8j4HDoms4e1PpZWBDq2CN7HaBcJacD6X7dDS4tv21EG+e+9z3hyik7LESIATahANB jVlqySJ4GkH7hkUvCjfBh8JxxRbfzcDOQQ5oQk3iXhvhjlchp7zwC2VpmGP1h4yRYrYO KfHg== 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=fMe+4r4h27YBWGP1Mh7yCshcsdgO6yvR9/I+ocLojQQ=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=FkGHUZnx1AS3yUHe1Zf+AADZxpeo4RteWeeCcFzrWXkVii7vGXGOmmvLSJrrqheRSh qnH2moEvyB6sX4+jAP1kgOY5MDQGQYFv2xn3Imsg6kHBWEt/WskXsNvSPQE5f+CsZzB7 4YIVp2EBvXvQO03G9sD/9WYFWG921EekMSL8ygPzlpLM666J7UNf25/WClWMfy17lb02 xTdpSPR5ivsujHZzx0mXfEzNHytTTtNzxdx/RbqnTApXMp+KMOxz5JAz8SId2zIYberj rC+v2BqNuYSMvnFgR5MV9hfIjNJh7J1fBRmDTAyT6iJ2gUR+8KpUezN6btv/JMXQ6BDY BAuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MUUMRgTT; 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id kn8-20020a170903078800b001c5cf1c30cfsi13139569plb.435.2023.09.28.10.45.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 10:45:44 -0700 (PDT) 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=MUUMRgTT; 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 E65D882CB51C; Thu, 28 Sep 2023 00:16:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231509AbjI1HQB (ORCPT + 20 others); Thu, 28 Sep 2023 03:16:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231367AbjI1HPn (ORCPT ); Thu, 28 Sep 2023 03:15:43 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6D35CC0; Thu, 28 Sep 2023 00:15:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695885341; x=1727421341; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=caYY16c3X4qJEs7vjlwRO/5AoAt3WHXwfSZCdiD2ZmE=; b=MUUMRgTThCSMlVV1j4ZAkDCiQnN9ahJ6PcuzU+TcvyVcHdmKXm8mQy/F g+aAp8eaWWt/Te+fZL3WWhBmn6nKxpYDZDEVMpnN8ProDarasVWjq+4c8 VkYWlZkfoHhL0Pd+5xO1+G2i+/Pc9m0Vp5TFJFlLkTABF/rXNwnpQFpvr 2CXqJYOih/iLUOE5kDpWrP6E5EH2Ry4iaPh6XPmwo1l/bTqxlHDB9ijOA yvddVyVhU3n9kD3aiazM2aqmWI40jlWP72/xnU9snwxIyt6pTv5KwNYbN +LqUS+2BpDfjQGXGz5fVOmtVooC9h75rOJ0zcTap1qW+Lp0oZcbn3ijS1 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="412914872" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="412914872" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2023 00:15:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="784602100" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="784602100" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga001.jf.intel.com with ESMTP; 28 Sep 2023 00:15: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 v2 4/6] iommufd/hw_pagetable: Support allocating nested parent domain Date: Thu, 28 Sep 2023 00:15:26 -0700 Message-Id: <20230928071528.26258-5-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230928071528.26258-1-yi.l.liu@intel.com> References: <20230928071528.26258-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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]); Thu, 28 Sep 2023 00:16:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778304307906676603 X-GMAIL-MSGID: 1778304307906676603 This extends IOMMU_HWPT_ALLOC to allocate domains used as parent (stage-2) in nested translation. Signed-off-by: Yi Liu Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian --- 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..8b3d2875d642 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 && !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 Thu Sep 28 07:15:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 146128 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3320521vqu; Thu, 28 Sep 2023 06:41:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZ4cH1YIuTpxECh9PkM7R5k4/Mi3V8jBrkAow0vemS0Cy6ypJH2Zcd9jeZLhjTE4cHtQ09 X-Received: by 2002:a17:903:44a:b0:1c6:2e2c:e6f4 with SMTP id iw10-20020a170903044a00b001c62e2ce6f4mr1078814plb.23.1695908511699; Thu, 28 Sep 2023 06:41:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695908511; cv=none; d=google.com; s=arc-20160816; b=SCRc+gzynVfMrUQ2WVxIb7Y7uWHwmSyzMndlMOGh4bNRRNbl4ctR9Nnqn9ytPzkEit nt/wvrOikJm4nz3u4Dl4uEh2Bx2eOsPArpVsm0nZrhbhw9OGXSdoRJexAfl7zUQF1Ojf 6XkIYn5jnscpOc8a0M9s6k//e+PD7RCUqIorFH0RlTR826fLKU93DwI0F2xbaV02QH+Q MBgwKekN+EphlrBaIjP/YcX+ynQJpOdTqpvJi5yz8KBgcI4xxf1Wv+oPLDIXfqoTT+jq wl/RhgJ748P/6MsCzcpEZ1N4HOlzNR6uKgU6V6MDXeNZG1N0xymT/MdtiaEodXxtWG7g r2DQ== 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=Ycy666blZbqlZD0DCRHQhyH9JA8zFAzJ8Z9EFRLaTV0=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=H/UoxTFHD7dAc+3sbNOcGqm6Pq9+hm0GZ9YBHYovn5pasjHpF05DU9MG0sOAnkZm6s nyNeQx1N+Bm3o0dtZrp6CYA+tb0TfzN/O+dHBPkwn067K+z755Eio4Pm3mLcCBiL/ziG Tb/v7XxLY122uqeHabnR3OckSJd0QZZJFCARbVLI3YfsMkcza/ltjiWzqWE0guQxxSHg a6ov/si0jkF1xA2gnieUVDHW4KvHGAv0GWFgR9a4WOsFivqxb989pYaiRDBGJURE4Nms aAAnc2NJJeXBigU+IgBWsj0wwN3uF4ZFJKY6qoJojdEvJZ+8grzT/JFr732UbP0hHvaf VtsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eogXUYzj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id a15-20020a170902710f00b001bb993caaedsi17384540pll.173.2023.09.28.06.41.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 06:41:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eogXUYzj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 B7FE582CB505; Thu, 28 Sep 2023 00:16:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231577AbjI1HP5 (ORCPT + 20 others); Thu, 28 Sep 2023 03:15:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231372AbjI1HPo (ORCPT ); Thu, 28 Sep 2023 03:15:44 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3016097; Thu, 28 Sep 2023 00:15:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695885342; x=1727421342; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aYVkD9R/amazwditpnyKsZ753FqDf92MQjTUubKUtOY=; b=eogXUYzjlnfM9gTDXJVk8g7DfVhGRALNtJ1d6Sn7MUrIIY9A08JC9fxF vRsocIkPPqa3SJH8owc1BfEZxpwbjs01iJ8lQYB+lBbANn0auVwvinFXT gTAdOKiIyoTNsKDDoEluadi3cAb5FgVg2mh7vFKzasifdCK093SP8agZ9 eMb7zRNa96hv3Ss2cY/upqhRAKj3vUycXFy4Dcc1kXsZybwH01NQpB/Se 2isain09Li4bG9WdpbzJgVsPN070xpkW8QHuYCLfDHd4dpswjEppNSZC4 ce38PhXJfXUlGi8Ob/Pa3EzRfqxVgfWpuz3zumPTtKNp46ufmo8fodpCU g==; X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="412914882" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="412914882" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2023 00:15:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="784602106" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="784602106" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga001.jf.intel.com with ESMTP; 28 Sep 2023 00:15:41 -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 v2 5/6] iommufd/selftest: Add domain_alloc_user() support in iommu mock Date: Thu, 28 Sep 2023 00:15:27 -0700 Message-Id: <20230928071528.26258-6-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230928071528.26258-1-yi.l.liu@intel.com> References: <20230928071528.26258-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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]); Thu, 28 Sep 2023 00:16:03 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778288963526659968 X-GMAIL-MSGID: 1778288963526659968 This adds mock_domain_alloc_user function and also new test case for the new flag IOMMU_HWPT_ALLOC_NEST_PARENT. Co-developed-by: Nicolin Chen Signed-off-by: Nicolin Chen Signed-off-by: Yi Liu Reviewed-by: Kevin Tian --- drivers/iommu/iommufd/selftest.c | 19 +++++++++++++++ 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, 48 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index 56506d5753f1..fe7e3c7d933a 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,26 @@ 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; + + if (flags & (~IOMMU_HWPT_ALLOC_NEST_PARENT)) + return ERR_PTR(-EOPNOTSUPP); + + 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 +325,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 Thu Sep 28 07:15:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 146300 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3593166vqu; Thu, 28 Sep 2023 13:55:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdXoQPIwHLNsdxsr5ry/E9JbWZu/wEavAPO6h3xeb4BUK15EEs2dOUuFJaK8I0VDFNFKK6 X-Received: by 2002:a05:6a20:430a:b0:153:40c3:aa71 with SMTP id h10-20020a056a20430a00b0015340c3aa71mr2701357pzk.43.1695934558360; Thu, 28 Sep 2023 13:55:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695934558; cv=none; d=google.com; s=arc-20160816; b=WjGIUph6boNU/gDdidcbGm5ZNkTQdfqUOiTuLvyd5U+ozJen/+OsNRUOIejueDwXfa o3evEBxBlbEQz6o30/tA2LMoypt1eNjgkc7cnHjjbDXGcVV6rTjM8S8qcvQ1v9J+oTYO 8PpIM87+aGG3GVwFhJzL3ubk8YBXWNU0NEPq/Gw5NWkmlgiSITZTcwpT20EYBhuB14FC abQnXpUmu61iCDgDKMQhPYxgYIfdeO+sEKQWavUKkLJhXyJ5vKwZ0MY1C+Pex40Rf9yN cmuWXm91lyIgZESxUXzj5ERuIOw8xlXL2AliooY2dxInsiOIuMpZHuk9X2HGgj5M5+30 kgKw== 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=JzUKFE/KvWUYjVSFlZ4behPSUQYZski/gyvV9fUSra4=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=rQfCg4/dAwZDFwlIhWMFot0emj+3BtzRchD/nx/iwuQovVXDRXgiISh/7H2sY28zJO X1AvvGxESuaUvX78sRh3nwok8OqEcWse0FDQ9A4d3kX7NpavU11bjt3/30nqAWg+0jEE mrp/23jeWcrT59SZkTQvDRdznIzRDp0vBKk/Zn+TGcBQfVhzwa+HirJ+AHofaO6HTgQ3 w0Es/MmL2AWBxE4VWPnqvM2Qm50P5sza5vxsavZOdCo25UUbJz33tEVaY2JTT9itEWLZ sggSx2AcI1uLKMTp80sdB5UIScnXmo1yyixEGOZ6ZXhbJqhlzeZnYrDjD+5rDyQGXWsr POzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NT6bCq7u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id b14-20020a170902650e00b001c61bd7cee0si10903933plk.211.2023.09.28.13.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 13:55:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NT6bCq7u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 9E9EC819D736; Thu, 28 Sep 2023 00:17:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231548AbjI1HQF (ORCPT + 20 others); Thu, 28 Sep 2023 03:16:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231322AbjI1HPs (ORCPT ); Thu, 28 Sep 2023 03:15:48 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28B0AF9; Thu, 28 Sep 2023 00:15:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695885343; x=1727421343; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WOT6Nvcwlk/4tcNAsxhrAgOjJcTJ1AZiQvr9aESlkuA=; b=NT6bCq7uT3UdwoUU/nXxlVQ0NsGn+pAVRZSPbOQHs2/rYfPRoPR/aNvm VB1AVpfEpap325ejnnT22+GPfyTQi3BWpGh5J7x2ET+qdU01u2YeTEHAC gYWGW0HyxxKXcNF3Hp4btvYI0wQJF4MR5z7t5HIxPqfdyezRxnupjt4ON SAGH1osCkKZadOpuDQAyfztkPhKsLsPVOgei6fFAnOBE7vrbCgnI6Sjjv nEUh7VHIZkMPDS7TdpkavQLOTL6uBNAHXogzbf7sNl/Ed9eoi4dcyr0Qd b2/VjQT/RrYGfbMjqUSkcuBalyrCHeWyhMkTAjiWu5BRyjoGy+Nbgm2NB g==; X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="412914902" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="412914902" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2023 00:15:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="784602111" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="784602111" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga001.jf.intel.com with ESMTP; 28 Sep 2023 00:15:41 -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 v2 6/6] iommu/vt-d: Add domain_alloc_user op Date: Thu, 28 Sep 2023 00:15:28 -0700 Message-Id: <20230928071528.26258-7-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230928071528.26258-1-yi.l.liu@intel.com> References: <20230928071528.26258-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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 28 Sep 2023 00:17:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778316275832170246 X-GMAIL-MSGID: 1778316275832170246 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 Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 5db283c17e0d..017aed5813d8 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4074,6 +4074,33 @@ 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; + + if (flags & (~IOMMU_HWPT_ALLOC_NEST_PARENT)) + return ERR_PTR(-EOPNOTSUPP); + + 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_alloc_user op needs to fully initialize a domain + * before return, so uses iommu_domain_alloc() here for + * simple. + */ + 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 +4834,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,