From patchwork Mon Oct 5 09:49:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11816419 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E38D113B2 for ; Mon, 5 Oct 2020 09:50:52 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B0DE620776 for ; Mon, 5 Oct 2020 09:50:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="DI9ymTP2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B0DE620776 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.2949.8460 (Exim 4.92) (envelope-from ) id 1kPN7U-0000ld-JA; Mon, 05 Oct 2020 09:49:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 2949.8460; Mon, 05 Oct 2020 09:49:24 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kPN7U-0000lS-Fn; Mon, 05 Oct 2020 09:49:24 +0000 Received: by outflank-mailman (input) for mailman id 2949; Mon, 05 Oct 2020 09:49:23 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kPN7T-0000a7-9N for xen-devel@lists.xenproject.org; Mon, 05 Oct 2020 09:49:23 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 66d5992c-4a93-4e63-a402-3dcd90abad74; Mon, 05 Oct 2020 09:49:14 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kPN7I-00018e-Ki; Mon, 05 Oct 2020 09:49:12 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kPN7I-0007gW-C8; Mon, 05 Oct 2020 09:49:12 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kPN7T-0000a7-9N for xen-devel@lists.xenproject.org; Mon, 05 Oct 2020 09:49:23 +0000 X-Inumbo-ID: 66d5992c-4a93-4e63-a402-3dcd90abad74 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 66d5992c-4a93-4e63-a402-3dcd90abad74; Mon, 05 Oct 2020 09:49:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=/aaR7886EUtZE6QjtNx8lerjhqgir9MSpy1XgMZF4CQ=; b=DI9ymTP2D65+vmiOYBjbM//YKo UEJWIwtLaTCuNuH8oEgzyJs2GxIops+nzfjC+uJUuZMZXYdP6tlLXMss/APAlfHH5UukDZkx9Odyt W7aLmasRZAfakrHvBpaHu1lwvzZGq3x3qRe+XIPgerBnpJ1KZ5BJSRExOy7wiq6r4Hqw=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kPN7I-00018e-Ki; Mon, 05 Oct 2020 09:49:12 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kPN7I-0007gW-C8; Mon, 05 Oct 2020 09:49:12 +0000 From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Anthony PERARD , Volodymyr Babchuk , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= Subject: [PATCH 3/5] libxl / iommu / domctl: introduce XEN_DOMCTL_IOMMU_SET_ALLOCATION... Date: Mon, 5 Oct 2020 10:49:03 +0100 Message-Id: <20201005094905.2929-4-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201005094905.2929-1-paul@xen.org> References: <20201005094905.2929-1-paul@xen.org> MIME-Version: 1.0 From: Paul Durrant ... sub-operation of XEN_DOMCTL_iommu_ctl. This patch adds a new sub-operation into the domctl. The code in iommu_ctl() is extended to call a new arch-specific iommu_set_allocation() function which will be called with the IOMMU page-table overhead (in 4k pages) in response to libxl issuing a new domctl via the xc_iommu_set_allocation() helper function. The helper function is only called in the x86 implementation of libxl__arch_domain_create() when the calculated 'iommu_memkb' value is non-zero. Hence the ARM implementation of iommu_set_allocation() simply returns -EOPNOTSUPP. NOTE: The implementation of the IOMMU page-table memory pool will be added in a subsequent patch and so the x86 implementation of iommu_set_allocation() currently does nothing other than return 0 (to indicate success) thereby ensuring that the new call in libxl__arch_domain_create() always succeeds. Signed-off-by: Paul Durrant --- Cc: Ian Jackson Cc: Wei Liu Cc: Andrew Cooper Cc: George Dunlap Cc: Jan Beulich Cc: Julien Grall Cc: Stefano Stabellini Cc: Anthony PERARD Cc: Volodymyr Babchuk Cc: "Roger Pau Monné" --- tools/libs/ctrl/include/xenctrl.h | 5 +++++ tools/libs/ctrl/xc_domain.c | 16 ++++++++++++++++ tools/libs/light/libxl_x86.c | 10 ++++++++++ xen/drivers/passthrough/iommu.c | 8 ++++++++ xen/drivers/passthrough/x86/iommu.c | 5 +++++ xen/include/asm-arm/iommu.h | 6 ++++++ xen/include/asm-x86/iommu.h | 2 ++ xen/include/public/domctl.h | 8 ++++++++ 8 files changed, 60 insertions(+) diff --git a/tools/libs/ctrl/include/xenctrl.h b/tools/libs/ctrl/include/xenctrl.h index 3796425e1e..4d6c9d44bc 100644 --- a/tools/libs/ctrl/include/xenctrl.h +++ b/tools/libs/ctrl/include/xenctrl.h @@ -2650,6 +2650,11 @@ int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout, uint32 int xc_domain_cacheflush(xc_interface *xch, uint32_t domid, xen_pfn_t start_pfn, xen_pfn_t nr_pfns); +/* IOMMU control operations */ + +int xc_iommu_set_allocation(xc_interface *xch, uint32_t domid, + unsigned int nr_pages); + /* Compat shims */ #include "xenctrl_compat.h" diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c index e7cea4a17d..0b20a8f2ee 100644 --- a/tools/libs/ctrl/xc_domain.c +++ b/tools/libs/ctrl/xc_domain.c @@ -2185,6 +2185,22 @@ int xc_domain_soft_reset(xc_interface *xch, domctl.domain = domid; return do_domctl(xch, &domctl); } + +int xc_iommu_set_allocation(xc_interface *xch, uint32_t domid, + unsigned int nr_pages) +{ + DECLARE_DOMCTL; + + memset(&domctl, 0, sizeof(domctl)); + + domctl.cmd = XEN_DOMCTL_iommu_ctl; + domctl.domain = domid; + domctl.u.iommu_ctl.op = XEN_DOMCTL_IOMMU_SET_ALLOCATION; + domctl.u.iommu_ctl.u.set_allocation.nr_pages = nr_pages; + + return do_domctl(xch, &domctl); +} + /* * Local variables: * mode: C diff --git a/tools/libs/light/libxl_x86.c b/tools/libs/light/libxl_x86.c index 6ec6c27c83..9631974dd6 100644 --- a/tools/libs/light/libxl_x86.c +++ b/tools/libs/light/libxl_x86.c @@ -520,6 +520,16 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, NULL, 0, &shadow, 0, NULL); } + if (d_config->b_info.iommu_memkb) { + unsigned int nr_pages = DIV_ROUNDUP(d_config->b_info.iommu_memkb, 4); + + ret = xc_iommu_set_allocation(ctx->xch, domid, nr_pages); + if (ret) { + LOGED(ERROR, domid, "Failed to set IOMMU allocation"); + goto out; + } + } + if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_PV && libxl_defbool_val(d_config->b_info.u.pv.e820_host)) { ret = libxl__e820_alloc(gc, domid, d_config); diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index bef0405984..642d5c8331 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -515,6 +515,14 @@ static int iommu_ctl( switch ( ctl->op ) { + case XEN_DOMCTL_IOMMU_SET_ALLOCATION: + { + struct xen_domctl_iommu_set_allocation *set_allocation = + &ctl->u.set_allocation; + + rc = iommu_set_allocation(d, set_allocation->nr_pages); + break; + } default: rc = -EOPNOTSUPP; break; diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/x86/iommu.c index f17b1820f4..b168073f10 100644 --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -134,6 +134,11 @@ void __hwdom_init arch_iommu_check_autotranslated_hwdom(struct domain *d) panic("PVH hardware domain iommu must be set in 'strict' mode\n"); } +int iommu_set_allocation(struct domain *d, unsigned nr_pages) +{ + return 0; +} + int arch_iommu_domain_init(struct domain *d) { struct domain_iommu *hd = dom_iommu(d); diff --git a/xen/include/asm-arm/iommu.h b/xen/include/asm-arm/iommu.h index 937edc8373..2e4735bace 100644 --- a/xen/include/asm-arm/iommu.h +++ b/xen/include/asm-arm/iommu.h @@ -33,6 +33,12 @@ int __must_check arm_iommu_map_page(struct domain *d, dfn_t dfn, mfn_t mfn, int __must_check arm_iommu_unmap_page(struct domain *d, dfn_t dfn, unsigned int *flush_flags); +static inline int iommu_set_allocation(struct domain *d, + unsigned int nr_pages) +{ + return -EOPNOTSUPP; +} + #endif /* __ARCH_ARM_IOMMU_H__ */ /* diff --git a/xen/include/asm-x86/iommu.h b/xen/include/asm-x86/iommu.h index 970eb06ffa..d086f564af 100644 --- a/xen/include/asm-x86/iommu.h +++ b/xen/include/asm-x86/iommu.h @@ -138,6 +138,8 @@ int pi_update_irte(const struct pi_desc *pi_desc, const struct pirq *pirq, int __must_check iommu_free_pgtables(struct domain *d); struct page_info *__must_check iommu_alloc_pgtable(struct domain *d); +int __must_check iommu_set_allocation(struct domain *d, unsigned int nr_pages); + #endif /* !__ARCH_X86_IOMMU_H__ */ /* * Local variables: diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 75e855625a..6402678838 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1138,8 +1138,16 @@ struct xen_domctl_vuart_op { #define XEN_DOMCTL_IOMMU_INVALID 0 +#define XEN_DOMCTL_IOMMU_SET_ALLOCATION 1 +struct xen_domctl_iommu_set_allocation { + uint32_t nr_pages; +}; + struct xen_domctl_iommu_ctl { uint32_t op; /* XEN_DOMCTL_IOMMU_* */ + union { + struct xen_domctl_iommu_set_allocation set_allocation; + } u; }; struct xen_domctl {