From patchwork Thu Jun 20 00:30:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Clark X-Patchwork-Id: 11005601 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 32A1F76 for ; Thu, 20 Jun 2019 00:33:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20FB0288C7 for ; Thu, 20 Jun 2019 00:33:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 153A2288ED; Thu, 20 Jun 2019 00:33:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 67954288C7 for ; Thu, 20 Jun 2019 00:33:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hdkzC-0000Ew-RI; Thu, 20 Jun 2019 00:31:30 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hdkzB-0000Dk-1i for xen-devel@lists.xenproject.org; Thu, 20 Jun 2019 00:31:29 +0000 X-Inumbo-ID: bdc2d041-92f2-11e9-8980-bc764e045a96 Received: from mail-io1-xd41.google.com (unknown [2607:f8b0:4864:20::d41]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id bdc2d041-92f2-11e9-8980-bc764e045a96; Thu, 20 Jun 2019 00:31:27 +0000 (UTC) Received: by mail-io1-xd41.google.com with SMTP id j6so430842ioa.5 for ; Wed, 19 Jun 2019 17:31:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fiPymJBpqSFVjWizv6VMNdFvETPztYM6w/lb+Pe6n6k=; b=Dzk9J86rpv5oga6pUzNVUzIzV+O40GfSx4Ru7fd/aJncXBetfqLAKgz6hNEJJKvgTg bxVoJDl22L5ofABLmzYtstFuueHkP3FxFhnsI12gUHOJR5A4iKSSeqemOxBqebNua4OV /FghdXExvZJ4/sBbf7ESroXeTpkELXxm6kgJP/FfmrJipsvZoAOXRaXTOKJ5Kcc3TcQ9 bSQzWrw+uwrWyJK9IdGqLglBxUfYLVwYeVilcMeBpDdypTDE5XA1UZ/pASGK/N36/nGt oekBzXYRWYSorNUQG4dnFMjGdQpTIgk1zfE5fMHttycXI8sLUw9CWX8e2w8JGCYjsx0S gAqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fiPymJBpqSFVjWizv6VMNdFvETPztYM6w/lb+Pe6n6k=; b=tToNRdjDKxRycsRYRzSXuQo5nskKv6BiK+ZUwDZa3nlwhmYeE7FBZ0z0hjaC1xLHbH OBkn74Q34OSGIMEpG6WffwLAmLJqQw6ryXddcyuP1ejZKmSVLouRw4pj8F4haqNVMuD5 2xwoCHbQLLPB3gfiFzSS84GSP2hhfEOuA9Nbdx+nOz5Q3TdrX0AP5CurezyM+Pq+AInB deKsxHznB6FJgVrnGLCmisiHgR97ITRLxQOWJ3E4RTUwDxQlqxQo5smYDTlsCBjx2w+t CzxRikE1LfzdW3g34NUSMnzfcE1PmkAlt1nzsEwsrMKw8G+tDLtvke8iiPAnNyYlaexK AMXA== X-Gm-Message-State: APjAAAWVWCLcTLnfOgOoXhJL3eZiRfs6brKaO1bN7Ji1EMNEcJqJ1BCn 1E/xYk0/LXpucdb9AldS7X+AwZOTgg8= X-Google-Smtp-Source: APXvYqysln0sal/3G7K7k8lyB2Cal5oDdFg8nOjpOWZnCEi1wIkET7Ka11WdAtmdNwyi2cnGzbL4RQ== X-Received: by 2002:a05:6638:63a:: with SMTP id h26mr12641877jar.92.1560990686853; Wed, 19 Jun 2019 17:31:26 -0700 (PDT) Received: from desktop.ice.pyrology.org (static-50-53-74-115.bvtn.or.frontiernet.net. [50.53.74.115]) by smtp.gmail.com with ESMTPSA id e188sm22579016ioa.3.2019.06.19.17.31.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Jun 2019 17:31:25 -0700 (PDT) From: Christopher Clark To: xen-devel@lists.xenproject.org Date: Wed, 19 Jun 2019 17:30:50 -0700 Message-Id: <20190620003053.21993-7-christopher.w.clark@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190620003053.21993-1-christopher.w.clark@gmail.com> References: <20190620003053.21993-1-christopher.w.clark@gmail.com> Subject: [Xen-devel] [RFC 6/9] x86/nested, xsm: add nested_hvm_op hypercall X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Rich Persaud , Tim Deegan , Julien Grall , Jan Beulich , Daniel De Graaf , =?utf-8?q?Roger_Pau_Monn=C3=A9?= MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Provides proxying to the host hypervisor for HVMOP_get_param and HVMOP_set_param ops. Signed-off-by: Christopher Clark --- tools/flask/policy/modules/dom0.te | 1 + xen/arch/x86/guest/hypercall_page.S | 1 + xen/arch/x86/guest/xen-nested.c | 42 +++++++++++++++++++++++++++++ xen/arch/x86/hypercall.c | 1 + xen/arch/x86/pv/hypercall.c | 1 + xen/include/public/xen.h | 1 + xen/include/xen/hypercall.h | 4 +++ xen/include/xsm/dummy.h | 7 +++++ xen/include/xsm/xsm.h | 7 +++++ xen/xsm/dummy.c | 1 + xen/xsm/flask/hooks.c | 22 +++++++++++++++ 11 files changed, 88 insertions(+) diff --git a/tools/flask/policy/modules/dom0.te b/tools/flask/policy/modules/dom0.te index 1f564ff83b..7d0f29f082 100644 --- a/tools/flask/policy/modules/dom0.te +++ b/tools/flask/policy/modules/dom0.te @@ -46,6 +46,7 @@ allow dom0_t dom0_t:resource { add remove }; # Allow dom0 to communicate with a nested Xen hypervisor allow dom0_t nestedxen_t:version { xen_version xen_get_features }; allow dom0_t nestedxen_t:mmu physmap; +allow dom0_t nestedxen_t:hvm { setparam getparam }; # These permissions allow using the FLASK security server to compute access # checks locally, which could be used by a domain or service (such as xenstore) diff --git a/xen/arch/x86/guest/hypercall_page.S b/xen/arch/x86/guest/hypercall_page.S index 1a8dd0ea4f..adbb82f4ec 100644 --- a/xen/arch/x86/guest/hypercall_page.S +++ b/xen/arch/x86/guest/hypercall_page.S @@ -62,6 +62,7 @@ DECLARE_HYPERCALL(argo_op) DECLARE_HYPERCALL(xenpmu_op) DECLARE_HYPERCALL(nested_xen_version) DECLARE_HYPERCALL(nested_memory_op) +DECLARE_HYPERCALL(nested_hvm_op) DECLARE_HYPERCALL(arch_0) DECLARE_HYPERCALL(arch_1) diff --git a/xen/arch/x86/guest/xen-nested.c b/xen/arch/x86/guest/xen-nested.c index a76983cc2d..82bd6885e6 100644 --- a/xen/arch/x86/guest/xen-nested.c +++ b/xen/arch/x86/guest/xen-nested.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -160,3 +161,44 @@ int compat_nested_memory_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) return nested_add_to_physmap(*nat); } #endif + +long do_nested_hvm_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) +{ + struct xen_hvm_param a; + long ret; + + if ( !xen_nested ) + return -ENOSYS; + + ret = xsm_nested_hvm_op(XSM_PRIV, current->domain, cmd); + if ( ret ) + return ret; + + switch ( cmd ) + { + case HVMOP_set_param: + { + if ( copy_from_guest(&a, arg, 1) ) + return -EFAULT; + + return xen_hypercall_hvm_op(cmd, &a); + } + + case HVMOP_get_param: + { + if ( copy_from_guest(&a, arg, 1) ) + return -EFAULT; + + ret = xen_hypercall_hvm_op(cmd, &a); + + if ( !ret && __copy_to_guest(arg, &a, 1) ) + return -EFAULT; + + return ret; + } + + default: + gprintk(XENLOG_ERR, "Nested hvm op %d not implemented.\n", cmd); + return -EOPNOTSUPP; + } +} diff --git a/xen/arch/x86/hypercall.c b/xen/arch/x86/hypercall.c index 2aa8dc5ac6..268cc9450a 100644 --- a/xen/arch/x86/hypercall.c +++ b/xen/arch/x86/hypercall.c @@ -76,6 +76,7 @@ const hypercall_args_t hypercall_args_table[NR_hypercalls] = #ifdef CONFIG_XEN_NESTED ARGS(nested_xen_version, 2), COMP(nested_memory_op, 2, 2), + ARGS(nested_hvm_op, 2), #endif ARGS(mca, 1), ARGS(arch_1, 1), diff --git a/xen/arch/x86/pv/hypercall.c b/xen/arch/x86/pv/hypercall.c index 96198d3313..e88ecce222 100644 --- a/xen/arch/x86/pv/hypercall.c +++ b/xen/arch/x86/pv/hypercall.c @@ -87,6 +87,7 @@ const hypercall_table_t pv_hypercall_table[] = { #ifdef CONFIG_XEN_NESTED HYPERCALL(nested_xen_version), COMPAT_CALL(nested_memory_op), + HYPERCALL(nested_hvm_op), #endif HYPERCALL(mca), HYPERCALL(arch_1), diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h index e081f52fc4..1731409eb8 100644 --- a/xen/include/public/xen.h +++ b/xen/include/public/xen.h @@ -123,6 +123,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t); #define __HYPERVISOR_dm_op 41 #define __HYPERVISOR_nested_xen_version 42 #define __HYPERVISOR_nested_memory_op 43 +#define __HYPERVISOR_nested_hvm_op 44 /* Architecture-specific hypercall definitions. */ #define __HYPERVISOR_arch_0 48 diff --git a/xen/include/xen/hypercall.h b/xen/include/xen/hypercall.h index d373bd1763..b09070539e 100644 --- a/xen/include/xen/hypercall.h +++ b/xen/include/xen/hypercall.h @@ -158,6 +158,10 @@ extern long do_nested_xen_version( extern long do_nested_memory_op( int cmd, XEN_GUEST_HANDLE_PARAM(void) arg); + +extern long do_nested_hvm_op( + int cmd, + XEN_GUEST_HANDLE_PARAM(void) arg); #endif #ifdef CONFIG_COMPAT diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h index 17375f6b9f..238b425c49 100644 --- a/xen/include/xsm/dummy.h +++ b/xen/include/xsm/dummy.h @@ -754,6 +754,13 @@ static XSM_INLINE int xsm_nested_add_to_physmap(XSM_DEFAULT_ARG XSM_ASSERT_ACTION(XSM_PRIV); return xsm_default_action(action, d, NULL); } + +static XSM_INLINE int xsm_nested_hvm_op(XSM_DEFAULT_ARG const struct domain *d, + unsigned int cmd) +{ + XSM_ASSERT_ACTION(XSM_PRIV); + return xsm_default_action(action, d, NULL); +} #endif #include diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h index 920d2d9088..cc02bf18c7 100644 --- a/xen/include/xsm/xsm.h +++ b/xen/include/xsm/xsm.h @@ -190,6 +190,7 @@ struct xsm_operations { #ifdef CONFIG_XEN_NESTED int (*nested_xen_version) (const struct domain *d, unsigned int cmd); int (*nested_add_to_physmap) (const struct domain *d); + int (*nested_hvm_op) (const struct domain *d, unsigned int cmd); #endif }; @@ -741,6 +742,12 @@ static inline int xsm_nested_add_to_physmap(xsm_default_t def, return xsm_ops->nested_add_to_physmap(d); } +static inline int xsm_nested_hvm_op(xsm_default_t def, const struct domain *d, + unsigned int cmd) +{ + return xsm_ops->nested_hvm_op(d, cmd); +} + #endif /* CONFIG_XEN_NESTED */ #endif /* XSM_NO_WRAPPERS */ diff --git a/xen/xsm/dummy.c b/xen/xsm/dummy.c index 5ce29bcfe5..909d41a81b 100644 --- a/xen/xsm/dummy.c +++ b/xen/xsm/dummy.c @@ -160,5 +160,6 @@ void __init xsm_fixup_ops (struct xsm_operations *ops) #ifdef CONFIG_XEN_NESTED set_to_dummy_if_null(ops, nested_xen_version); set_to_dummy_if_null(ops, nested_add_to_physmap); + set_to_dummy_if_null(ops, nested_hvm_op); #endif } diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index 17a81b85f9..f8d247e28f 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -1768,6 +1768,27 @@ static int flask_nested_xen_version(const struct domain *d, unsigned int op) return domain_has_xen_version(d, SECINITSID_NESTEDXEN, op); } +static int flask_nested_hvm_op(const struct domain *d, unsigned int op) +{ + u32 perm; + + switch ( op ) + { + case HVMOP_set_param: + perm = HVM__SETPARAM; + break; + + case HVMOP_get_param: + perm = HVM__GETPARAM; + break; + + default: + perm = HVM__HVMCTL; + } + + return domain_has_nested_perm(d, SECCLASS_HVM, perm); +} + #endif long do_flask_op(XEN_GUEST_HANDLE_PARAM(xsm_op_t) u_flask_op); @@ -1912,6 +1933,7 @@ static struct xsm_operations flask_ops = { #ifdef CONFIG_XEN_NESTED .nested_xen_version = flask_nested_xen_version, .nested_add_to_physmap = flask_nested_add_to_physmap, + .nested_hvm_op = flask_nested_hvm_op, #endif };