From patchwork Thu Feb 6 13:24:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11368439 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 2BDAD92A for ; Thu, 6 Feb 2020 13:26:28 +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 07C6520661 for ; Thu, 6 Feb 2020 13:26:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="Pgxnk2Ir" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 07C6520661 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1izh9N-0002d7-TV; Thu, 06 Feb 2020 13:24:57 +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.89) (envelope-from ) id 1izh9M-0002d1-Id for xen-devel@lists.xenproject.org; Thu, 06 Feb 2020 13:24:56 +0000 X-Inumbo-ID: 104f0be0-48e4-11ea-af84-12813bfff9fa Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 104f0be0-48e4-11ea-af84-12813bfff9fa; Thu, 06 Feb 2020 13:24:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1580995495; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=SUR2Zch0NanS6XPGioB/JRHlNkzk34eiNHO6q5hOpDA=; b=Pgxnk2Ir250+E+fzEft8BkX0FV2VMz/B2qfNGpRm4nSkVKw9IGikAHLE O0z8LFFZxnqaiZyu8C/oh48pD4u5ZEUA2gWaWpIVt7qO9pTjtR9WprJnB vwVcfEkyZNCIpeATyCcBRBGv8kl66g7jHZdjk+L68bFTIhQvTbt5eqdd/ c=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: vaTvcHxxAOMneLmIx6goDm19Dsy2EktZ2AY/wpSu3Abucy+dMWhnpOASN0sSOkIBrEOaUCpWiB WVTDDhPfg1BZ6KoDXRRIR9fKZavnj+85DS6ha1Cy6r58X8h6GEKo1+2RIb6bRC5GgOfDY1xL7z TnDFYe5N749/Aw+jzzPoWBTkrn13L4CUBkQd21qAkE7n4Zc264JbCXrMwpR9Enezsd+FgEsYvq yPOrPBCL1BX94buwJpku5rhiMpnNMyzVVLrworzcZikfkOacwNfCjAsH/aTX7lJR9LxFVH7TMM /r4= X-SBRS: 2.7 X-MesageID: 12414507 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,409,1574139600"; d="scan'208";a="12414507" From: Andrew Cooper To: Xen-devel Date: Thu, 6 Feb 2020 13:24:52 +0000 Message-ID: <20200206132452.11802-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] xen/hvm: Fix handling of obsolete HVM_PARAMs 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: Tamas K Lengyel , Wei Liu , Razvan Cojocaru , Andrew Cooper , Jan Beulich , Ian Jackson , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The local xc_hvm_param_deprecated_check() in libxc tries to guess Xen's behaviour for the MEMORY_EVENT params, but is wrong for the get side, where Xen would return 0 (which is also a bug). Delete the helper. In Xen, perform the checks in hvm_allow_set_param(), rather than hvm_set_param(), and actually implement checks on the get side so the hypercall doesn't return successfully with 0 as an answer. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Acked-by: Wei Liu --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné CC: Ian Jackson CC: Razvan Cojocaru CC: Tamas K Lengyel Tamas: You introduced xc_hvm_param_deprecated_check() in 0a246b41ca while introducing XEN_DOMCTL_monitor_op. Do you recall why? --- tools/libxc/xc_domain.c | 28 ++-------------------------- xen/arch/x86/hvm/hvm.c | 25 ++++++++++++++----------- xen/include/public/hvm/params.h | 18 ++++++++---------- 3 files changed, 24 insertions(+), 47 deletions(-) diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index e544218d2e..71829c2bce 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -1441,31 +1441,10 @@ int xc_domain_send_trigger(xc_interface *xch, return do_domctl(xch, &domctl); } -static inline int xc_hvm_param_deprecated_check(uint32_t param) -{ - switch ( param ) - { - case HVM_PARAM_MEMORY_EVENT_CR0: - case HVM_PARAM_MEMORY_EVENT_CR3: - case HVM_PARAM_MEMORY_EVENT_CR4: - case HVM_PARAM_MEMORY_EVENT_INT3: - case HVM_PARAM_MEMORY_EVENT_SINGLE_STEP: - case HVM_PARAM_MEMORY_EVENT_MSR: - return -EOPNOTSUPP; - default: - break; - }; - - return 0; -} - int xc_hvm_param_set(xc_interface *handle, uint32_t dom, uint32_t param, uint64_t value) { DECLARE_HYPERCALL_BUFFER(xen_hvm_param_t, arg); - int rc = xc_hvm_param_deprecated_check(param); - - if ( rc ) - return rc; + int rc; arg = xc_hypercall_buffer_alloc(handle, arg, sizeof(*arg)); if ( arg == NULL ) @@ -1484,10 +1463,7 @@ int xc_hvm_param_set(xc_interface *handle, uint32_t dom, uint32_t param, uint64_ int xc_hvm_param_get(xc_interface *handle, uint32_t dom, uint32_t param, uint64_t *value) { DECLARE_HYPERCALL_BUFFER(xen_hvm_param_t, arg); - int rc = xc_hvm_param_deprecated_check(param); - - if ( rc ) - return rc; + int rc; arg = xc_hypercall_buffer_alloc(handle, arg, sizeof(*arg)); if ( arg == NULL ) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 00a9e70b7c..93795dab92 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4105,8 +4105,14 @@ static int hvm_allow_set_param(struct domain *d, break; /* The following parameters are deprecated. */ case HVM_PARAM_DM_DOMAIN: + case HVM_PARAM_MEMORY_EVENT_CR0: + case HVM_PARAM_MEMORY_EVENT_CR3: + case HVM_PARAM_MEMORY_EVENT_CR4: + case HVM_PARAM_MEMORY_EVENT_INT3: + case HVM_PARAM_MEMORY_EVENT_SINGLE_STEP: case HVM_PARAM_BUFIOREQ_EVTCHN: - rc = -EPERM; + case HVM_PARAM_MEMORY_EVENT_MSR: + rc = -EINVAL; break; /* * The following parameters must not be set by the guest @@ -4221,15 +4227,6 @@ static int hvm_set_param(struct domain *d, uint32_t index, uint64_t value) case HVM_PARAM_ACPI_IOPORTS_LOCATION: rc = pmtimer_change_ioport(d, value); break; - case HVM_PARAM_MEMORY_EVENT_CR0: - case HVM_PARAM_MEMORY_EVENT_CR3: - case HVM_PARAM_MEMORY_EVENT_CR4: - case HVM_PARAM_MEMORY_EVENT_INT3: - case HVM_PARAM_MEMORY_EVENT_SINGLE_STEP: - case HVM_PARAM_MEMORY_EVENT_MSR: - /* Deprecated */ - rc = -EOPNOTSUPP; - break; case HVM_PARAM_NESTEDHVM: rc = xsm_hvm_param_nested(XSM_PRIV, d); if ( rc ) @@ -4411,8 +4408,14 @@ static int hvm_allow_get_param(struct domain *d, break; /* The following parameters are deprecated. */ case HVM_PARAM_DM_DOMAIN: + case HVM_PARAM_MEMORY_EVENT_CR0: + case HVM_PARAM_MEMORY_EVENT_CR3: + case HVM_PARAM_MEMORY_EVENT_CR4: + case HVM_PARAM_MEMORY_EVENT_INT3: + case HVM_PARAM_MEMORY_EVENT_SINGLE_STEP: case HVM_PARAM_BUFIOREQ_EVTCHN: - rc = -ENODATA; + case HVM_PARAM_MEMORY_EVENT_MSR: + rc = -EINVAL; break; /* The remaining parameters should not be read by the guest. */ default: diff --git a/xen/include/public/hvm/params.h b/xen/include/public/hvm/params.h index 36832e4b94..68293e314e 100644 --- a/xen/include/public/hvm/params.h +++ b/xen/include/public/hvm/params.h @@ -28,8 +28,14 @@ /* These parameters are deprecated and their meaning is undefined. */ #if defined(__XEN__) || defined(__XEN_TOOLS__) -#define HVM_PARAM_DM_DOMAIN 13 -#define HVM_PARAM_BUFIOREQ_EVTCHN 26 +#define HVM_PARAM_DM_DOMAIN 13 +#define HVM_PARAM_MEMORY_EVENT_CR0 20 +#define HVM_PARAM_MEMORY_EVENT_CR3 21 +#define HVM_PARAM_MEMORY_EVENT_CR4 22 +#define HVM_PARAM_MEMORY_EVENT_INT3 23 +#define HVM_PARAM_MEMORY_EVENT_SINGLE_STEP 25 +#define HVM_PARAM_BUFIOREQ_EVTCHN 26 +#define HVM_PARAM_MEMORY_EVENT_MSR 30 #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ @@ -227,14 +233,6 @@ */ #define HVM_PARAM_ACPI_IOPORTS_LOCATION 19 -/* Deprecated */ -#define HVM_PARAM_MEMORY_EVENT_CR0 20 -#define HVM_PARAM_MEMORY_EVENT_CR3 21 -#define HVM_PARAM_MEMORY_EVENT_CR4 22 -#define HVM_PARAM_MEMORY_EVENT_INT3 23 -#define HVM_PARAM_MEMORY_EVENT_SINGLE_STEP 25 -#define HVM_PARAM_MEMORY_EVENT_MSR 30 - /* Boolean: Enable nestedhvm (hvm only) */ #define HVM_PARAM_NESTEDHVM 24