From patchwork Fri Jul 7 03:53:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9829533 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C4902602CA for ; Fri, 7 Jul 2017 03:56:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAD3A25F3E for ; Fri, 7 Jul 2017 03:56:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D304283DA; Fri, 7 Jul 2017 03:56:34 +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=-4.2 required=2.0 tests=BAYES_00, 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 AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 33BD325F3E for ; Fri, 7 Jul 2017 03:56:34 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTKKu-0002BC-Ij; Fri, 07 Jul 2017 03:53:44 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTKKt-0002B0-4F for xen-devel@lists.xen.org; Fri, 07 Jul 2017 03:53:43 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id 8A/38-02181-5C50F595; Fri, 07 Jul 2017 03:53:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRWlGSWpSXmKPExsVywNykQvcoa3y kwc0XohZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8ahie0sBYulKt6tusHWwNgs3MXIxSEkMJ1R 4uXBzexdjJwcEgK8EkeWzWCFsP0lHs5vYYQo6mWUWP7sAyNIgk1AX2LF44NgRSIC0hLXPl8Gi zMLVEtMnD4HzBYW8JWYMH89C4jNIqAqcXtRP5jNK2ArMeniNiaIBfISu9ougs3hFLCTaL+4lR nEFgKqebBqLcsERt4FjAyrGNWLU4vKUot0jfSSijLTM0pyEzNzdA0NjPVyU4uLE9NTcxKTivW S83M3MQLDoZ6BgXEH46lm50OMkhxMSqK8Z27GRQrxJeWnVGYkFmfEF5XmpBYfYpTh4FCS4F3L Eh8pJFiUmp5akZaZAwxMmLQEB4+SCO8+kFbe4oLE3OLMdIjUKUZdjlcT/n9jEmLJy89LlRLnX QUyQwCkKKM0D24ELEouMcpKCfMyMjAwCPEUpBblZpagyr9iFOdgVBLm3QYyhSczrwRu0yugI5 iAjlBsjAE5oiQRISXVwLjN0HtRv3naehGfHZsSqqry8yyW3d85gfe753KVyJ7mebKZuw9sdK/ 7YH9+De/T9vCHntcCV3qGJO+UsRNuTln8bq2nBOPpCblBXK95RbkM/pxhF38f1XSn41OHYdRR TwUdM52bvHMvRM1LzGVZOCOtumViyV7ela4GTnutp194k7De8vDjs0osxRmJhlrMRcWJANF+O wONAgAA X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1499399618!104177186!1 X-Originating-IP: [192.55.52.120] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 54922 invoked from network); 7 Jul 2017 03:53:40 -0000 Received: from mga04.intel.com (HELO mga04.intel.com) (192.55.52.120) by server-14.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 7 Jul 2017 03:53:40 -0000 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jul 2017 20:53:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,320,1496127600"; d="scan'208";a="123632506" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga005.fm.intel.com with ESMTP; 06 Jul 2017 20:53:37 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Fri, 7 Jul 2017 11:53:08 +0800 Message-Id: <20170707035314.15659-2-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170707035314.15659-1-haozhong.zhang@intel.com> References: <20170707035314.15659-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Jan Beulich , Andrew Cooper Subject: [Xen-devel] [PATCH v7 1/7] x86/domctl: generalize the restore of vMCE parameters X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP vMCE parameters in struct xen_domctl_ext_vcpucontext were extended in the past, and is likely to be extended in the future. When migrating a PV domain from old Xen, XEN_DOMCTL_set_ext_vcpucontext should handle the differences. Instead of adding ad-hoc handling code at each extension, we introduce an array to record sizes of the current and all past versions of vMCE parameters, and search for the largest one that does not expire the size of passed-in parameters to determine vMCE parameters that will be restored. If vMCE parameters are extended in the future, we only need to adapt the array to reflect the extension. Signed-off-by: Haozhong Zhang --- Cc: Jan Beulich Cc: Andrew Cooper --- xen/arch/x86/domctl.c | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 7fa58b49af..5cd2af76bb 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -302,6 +302,39 @@ static int update_domain_cpuid_info(struct domain *d, return 0; } +static int vcpu_set_vmce(struct vcpu *v, + const struct xen_domctl_ext_vcpucontext *evc) +{ + /* + * Sizes of vMCE parameters used by the current and past versions + * of Xen in descending order. If vMCE parameters are extended, + * remember to add the old size in this array. + */ + static const unsigned int valid_vmce_size[] = { + sizeof(evc->vmce), + sizeof(evc->mcg_cap), + 0, + }; + struct hvm_vmce_vcpu vmce = { }; + unsigned int vmce_size = evc->size - offsetof(typeof(*evc), mcg_cap); + int i = 0; + + BUILD_BUG_ON(offsetof(struct xen_domctl_ext_vcpucontext, mcg_cap) != + offsetof(struct xen_domctl_ext_vcpucontext, vmce.caps)); + BUILD_BUG_ON(sizeof(evc->mcg_cap) != sizeof(evc->vmce.caps)); + + while ( i < ARRAY_SIZE(valid_vmce_size) - 1 && + vmce_size < valid_vmce_size[i] ) + ++i; + vmce_size = valid_vmce_size[i]; + + if ( !vmce_size ) + return 0; + + memcpy(&vmce, &evc->vmce, vmce_size); + return vmce_restore_vcpu(v, &vmce); +} + void arch_get_domain_info(const struct domain *d, struct xen_domctl_getdomaininfo *info) { @@ -912,23 +945,7 @@ long arch_do_domctl( else domain_pause(d); - BUILD_BUG_ON(offsetof(struct xen_domctl_ext_vcpucontext, - mcg_cap) != - offsetof(struct xen_domctl_ext_vcpucontext, - vmce.caps)); - BUILD_BUG_ON(sizeof(evc->mcg_cap) != sizeof(evc->vmce.caps)); - if ( evc->size >= offsetof(typeof(*evc), vmce) + - sizeof(evc->vmce) ) - ret = vmce_restore_vcpu(v, &evc->vmce); - else if ( evc->size >= offsetof(typeof(*evc), mcg_cap) + - sizeof(evc->mcg_cap) ) - { - struct hvm_vmce_vcpu vmce = { .caps = evc->mcg_cap }; - - ret = vmce_restore_vcpu(v, &vmce); - } - else - ret = 0; + ret = vcpu_set_vmce(v, evc); domain_unpause(d); }