From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698131; cv=none; d=zohomail.com; s=zohoarc; b=n742HYSHL0E5twgmmLaQIHGJqBNw8Cht5rnJjrG8SC2/qf+MgXkp2nNEa+tLueAnyjiiKo0L77MgsOG7Zw/bkrE4aPohnX8c80LegnSEMLqpNQ7cHE1tVZZgaipAxAN0ggtFhUyHBuOlCxXoxb8RdcfEy28X6ki5Lha2EzY0C14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698131; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Mtzb0qY4MDbMr9h4Pryiu7sOu/RkyG3LEJdslfymoTw=; b=WNILbR7+qrndvi3HAe8Eig0gSLnLHhv5+DAN8GG1ge0jXjeKE4LYOBN4mtw32ndukpjH3uLaKBPLiHyIVTuJcVnlMYJB3VVse+VfV6ehnbiFfBxFojlehbiVfT/qkzmgMrz4dw1phtbjEbq6ezuiKsHTuj/3OULj3Aq0LhURjEE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698131495352.75447794458876; Wed, 18 Dec 2019 11:42:11 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCB-0007bE-O8; Wed, 18 Dec 2019 19:41:19 +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 1ihfCA-0007b4-6o for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:41:18 +0000 Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 584235b8-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:12 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:10 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:09 -0800 X-Inumbo-ID: 584235b8-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196272" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:38 -0800 Message-Id: <0987641ced136706961cf419eb5ed83d1302357b.1576697796.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 01/20] x86: make hvm_{get/set}_param accessible 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: Andrew Cooper , Tamas K Lengyel , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Currently the hvm parameters are only accessible via the HVMOP hypercalls. = By exposing hvm_{get/set}_param it will be possible for VM forking to copy the parameters directly into the clone domain. Signed-off-by: Tamas K Lengyel --- xen/arch/x86/hvm/hvm.c | 169 ++++++++++++++++++++-------------- xen/include/asm-x86/hvm/hvm.h | 4 + 2 files changed, 106 insertions(+), 67 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 614ed60fe4..5a3a962fbb 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4072,16 +4072,17 @@ static int hvmop_set_evtchn_upcall_vector( } =20 static int hvm_allow_set_param(struct domain *d, - const struct xen_hvm_param *a) + uint32_t index, + uint64_t new_value) { - uint64_t value =3D d->arch.hvm.params[a->index]; + uint64_t value =3D d->arch.hvm.params[index]; int rc; =20 rc =3D xsm_hvm_param(XSM_TARGET, d, HVMOP_set_param); if ( rc ) return rc; =20 - switch ( a->index ) + switch ( index ) { /* The following parameters can be set by the guest. */ case HVM_PARAM_CALLBACK_IRQ: @@ -4114,7 +4115,7 @@ static int hvm_allow_set_param(struct domain *d, if ( rc ) return rc; =20 - switch ( a->index ) + switch ( index ) { /* The following parameters should only be changed once. */ case HVM_PARAM_VIRIDIAN: @@ -4124,7 +4125,7 @@ static int hvm_allow_set_param(struct domain *d, case HVM_PARAM_NR_IOREQ_SERVER_PAGES: case HVM_PARAM_ALTP2M: case HVM_PARAM_MCA_CAP: - if ( value !=3D 0 && a->value !=3D value ) + if ( value !=3D 0 && new_value !=3D value ) rc =3D -EEXIST; break; default: @@ -4134,13 +4135,11 @@ static int hvm_allow_set_param(struct domain *d, return rc; } =20 -static int hvmop_set_param( +int hvmop_set_param( XEN_GUEST_HANDLE_PARAM(xen_hvm_param_t) arg) { - struct domain *curr_d =3D current->domain; struct xen_hvm_param a; struct domain *d; - struct vcpu *v; int rc; =20 if ( copy_from_guest(&a, arg, 1) ) @@ -4160,23 +4159,42 @@ static int hvmop_set_param( if ( !is_hvm_domain(d) ) goto out; =20 - rc =3D hvm_allow_set_param(d, &a); + rc =3D hvm_set_param(d, a.index, a.value); + + out: + rcu_unlock_domain(d); + return rc; +} + +int hvm_set_param( + struct domain *d, + uint32_t index, + uint64_t value) +{ + struct domain *curr_d =3D current->domain; + int rc; + struct vcpu *v; + + if ( index >=3D HVM_NR_PARAMS ) + return -EINVAL; + + rc =3D hvm_allow_set_param(d, index, value); if ( rc ) goto out; =20 - switch ( a.index ) + switch ( index ) { case HVM_PARAM_CALLBACK_IRQ: - hvm_set_callback_via(d, a.value); + hvm_set_callback_via(d, value); hvm_latch_shinfo_size(d); break; case HVM_PARAM_TIMER_MODE: - if ( a.value > HVMPTM_one_missed_tick_pending ) + if ( value > HVMPTM_one_missed_tick_pending ) rc =3D -EINVAL; break; case HVM_PARAM_VIRIDIAN: - if ( (a.value & ~HVMPV_feature_mask) || - !(a.value & HVMPV_base_freq) ) + if ( (value & ~HVMPV_feature_mask) || + !(value & HVMPV_base_freq) ) rc =3D -EINVAL; break; case HVM_PARAM_IDENT_PT: @@ -4186,7 +4204,7 @@ static int hvmop_set_param( */ if ( !paging_mode_hap(d) || !cpu_has_vmx ) { - d->arch.hvm.params[a.index] =3D a.value; + d->arch.hvm.params[index] =3D value; break; } =20 @@ -4201,7 +4219,7 @@ static int hvmop_set_param( =20 rc =3D 0; domain_pause(d); - d->arch.hvm.params[a.index] =3D a.value; + d->arch.hvm.params[index] =3D value; for_each_vcpu ( d, v ) paging_update_cr3(v, false); domain_unpause(d); @@ -4210,23 +4228,23 @@ static int hvmop_set_param( break; case HVM_PARAM_DM_DOMAIN: /* The only value this should ever be set to is DOMID_SELF */ - if ( a.value !=3D DOMID_SELF ) + if ( value !=3D DOMID_SELF ) rc =3D -EINVAL; =20 - a.value =3D curr_d->domain_id; + value =3D curr_d->domain_id; break; case HVM_PARAM_ACPI_S_STATE: rc =3D 0; - if ( a.value =3D=3D 3 ) + if ( value =3D=3D 3 ) hvm_s3_suspend(d); - else if ( a.value =3D=3D 0 ) + else if ( value =3D=3D 0 ) hvm_s3_resume(d); else rc =3D -EINVAL; =20 break; case HVM_PARAM_ACPI_IOPORTS_LOCATION: - rc =3D pmtimer_change_ioport(d, a.value); + rc =3D pmtimer_change_ioport(d, value); break; case HVM_PARAM_MEMORY_EVENT_CR0: case HVM_PARAM_MEMORY_EVENT_CR3: @@ -4241,24 +4259,24 @@ static int hvmop_set_param( rc =3D xsm_hvm_param_nested(XSM_PRIV, d); if ( rc ) break; - if ( a.value > 1 ) + if ( value > 1 ) rc =3D -EINVAL; /* * Remove the check below once we have * shadow-on-shadow. */ - if ( !paging_mode_hap(d) && a.value ) + if ( !paging_mode_hap(d) && value ) rc =3D -EINVAL; - if ( a.value && + if ( value && d->arch.hvm.params[HVM_PARAM_ALTP2M] ) rc =3D -EINVAL; /* Set up NHVM state for any vcpus that are already up. */ - if ( a.value && + if ( value && !d->arch.hvm.params[HVM_PARAM_NESTEDHVM] ) for_each_vcpu(d, v) if ( rc =3D=3D 0 ) rc =3D nestedhvm_vcpu_initialise(v); - if ( !a.value || rc ) + if ( !value || rc ) for_each_vcpu(d, v) nestedhvm_vcpu_destroy(v); break; @@ -4266,30 +4284,30 @@ static int hvmop_set_param( rc =3D xsm_hvm_param_altp2mhvm(XSM_PRIV, d); if ( rc ) break; - if ( a.value > XEN_ALTP2M_limited ) + if ( value > XEN_ALTP2M_limited ) rc =3D -EINVAL; - if ( a.value && + if ( value && d->arch.hvm.params[HVM_PARAM_NESTEDHVM] ) rc =3D -EINVAL; break; case HVM_PARAM_TRIPLE_FAULT_REASON: - if ( a.value > SHUTDOWN_MAX ) + if ( value > SHUTDOWN_MAX ) rc =3D -EINVAL; break; case HVM_PARAM_IOREQ_SERVER_PFN: - d->arch.hvm.ioreq_gfn.base =3D a.value; + d->arch.hvm.ioreq_gfn.base =3D value; break; case HVM_PARAM_NR_IOREQ_SERVER_PAGES: { unsigned int i; =20 - if ( a.value =3D=3D 0 || - a.value > sizeof(d->arch.hvm.ioreq_gfn.mask) * 8 ) + if ( value =3D=3D 0 || + value > sizeof(d->arch.hvm.ioreq_gfn.mask) * 8 ) { rc =3D -EINVAL; break; } - for ( i =3D 0; i < a.value; i++ ) + for ( i =3D 0; i < value; i++ ) set_bit(i, &d->arch.hvm.ioreq_gfn.mask); =20 break; @@ -4301,35 +4319,35 @@ static int hvmop_set_param( sizeof(d->arch.hvm.ioreq_gfn.legacy_mask) * 8); BUILD_BUG_ON(HVM_PARAM_BUFIOREQ_PFN > sizeof(d->arch.hvm.ioreq_gfn.legacy_mask) * 8); - if ( a.value ) - set_bit(a.index, &d->arch.hvm.ioreq_gfn.legacy_mask); + if ( value ) + set_bit(index, &d->arch.hvm.ioreq_gfn.legacy_mask); break; =20 case HVM_PARAM_X87_FIP_WIDTH: - if ( a.value !=3D 0 && a.value !=3D 4 && a.value !=3D 8 ) + if ( value !=3D 0 && value !=3D 4 && value !=3D 8 ) { rc =3D -EINVAL; break; } - d->arch.x87_fip_width =3D a.value; + d->arch.x87_fip_width =3D value; break; =20 case HVM_PARAM_VM86_TSS: /* Hardware would silently truncate high bits. */ - if ( a.value !=3D (uint32_t)a.value ) + if ( value !=3D (uint32_t)value ) { if ( d =3D=3D curr_d ) domain_crash(d); rc =3D -EINVAL; } /* Old hvmloader binaries hardcode the size to 128 bytes. */ - if ( a.value ) - a.value |=3D (128ULL << 32) | VM86_TSS_UPDATED; - a.index =3D HVM_PARAM_VM86_TSS_SIZED; + if ( value ) + value |=3D (128ULL << 32) | VM86_TSS_UPDATED; + index =3D HVM_PARAM_VM86_TSS_SIZED; break; =20 case HVM_PARAM_VM86_TSS_SIZED: - if ( (a.value >> 32) < sizeof(struct tss32) ) + if ( (value >> 32) < sizeof(struct tss32) ) { if ( d =3D=3D curr_d ) domain_crash(d); @@ -4340,34 +4358,33 @@ static int hvmop_set_param( * 256 bits interrupt redirection bitmap + 64k bits I/O bitmap * plus one padding byte). */ - if ( (a.value >> 32) > sizeof(struct tss32) + + if ( (value >> 32) > sizeof(struct tss32) + (0x100 / 8) + (0x10000 / 8) + 1 ) - a.value =3D (uint32_t)a.value | + value =3D (uint32_t)value | ((sizeof(struct tss32) + (0x100 / 8) + (0x10000 / 8) + 1) << 32); - a.value |=3D VM86_TSS_UPDATED; + value |=3D VM86_TSS_UPDATED; break; =20 case HVM_PARAM_MCA_CAP: - rc =3D vmce_enable_mca_cap(d, a.value); + rc =3D vmce_enable_mca_cap(d, value); break; } =20 if ( rc !=3D 0 ) goto out; =20 - d->arch.hvm.params[a.index] =3D a.value; + d->arch.hvm.params[index] =3D value; =20 HVM_DBG_LOG(DBG_LEVEL_HCALL, "set param %u =3D %"PRIx64, - a.index, a.value); + index, value); =20 out: - rcu_unlock_domain(d); return rc; } =20 static int hvm_allow_get_param(struct domain *d, - const struct xen_hvm_param *a) + uint32_t index) { int rc; =20 @@ -4375,7 +4392,7 @@ static int hvm_allow_get_param(struct domain *d, if ( rc ) return rc; =20 - switch ( a->index ) + switch ( index ) { /* The following parameters can be read by the guest. */ case HVM_PARAM_CALLBACK_IRQ: @@ -4429,42 +4446,60 @@ static int hvmop_get_param( if ( !is_hvm_domain(d) ) goto out; =20 - rc =3D hvm_allow_get_param(d, &a); + rc =3D hvm_get_param(d, a.index, &a.value); if ( rc ) goto out; =20 - switch ( a.index ) + rc =3D __copy_to_guest(arg, &a, 1) ? -EFAULT : 0; + + HVM_DBG_LOG(DBG_LEVEL_HCALL, "get param %u =3D %"PRIx64, + a.index, a.value); + + out: + rcu_unlock_domain(d); + return rc; +} + +int hvm_get_param( + struct domain *d, + uint32_t index, + uint64_t *value) +{ + int rc; + + if ( index >=3D HVM_NR_PARAMS || !value ) + return -EINVAL; + + rc =3D hvm_allow_get_param(d, index); + if ( rc ) + return rc; + + switch ( index ) { case HVM_PARAM_ACPI_S_STATE: - a.value =3D d->arch.hvm.is_s3_suspended ? 3 : 0; + *value =3D d->arch.hvm.is_s3_suspended ? 3 : 0; break; =20 case HVM_PARAM_VM86_TSS: - a.value =3D (uint32_t)d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED]; + *value =3D (uint32_t)d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED]; break; =20 case HVM_PARAM_VM86_TSS_SIZED: - a.value =3D d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED] & - ~VM86_TSS_UPDATED; + *value =3D d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED] & + ~VM86_TSS_UPDATED; break; =20 case HVM_PARAM_X87_FIP_WIDTH: - a.value =3D d->arch.x87_fip_width; + *value =3D d->arch.x87_fip_width; break; default: - a.value =3D d->arch.hvm.params[a.index]; + *value =3D d->arch.hvm.params[index]; break; } =20 - rc =3D __copy_to_guest(arg, &a, 1) ? -EFAULT : 0; - - HVM_DBG_LOG(DBG_LEVEL_HCALL, "get param %u =3D %"PRIx64, - a.index, a.value); + return 0; +}; =20 - out: - rcu_unlock_domain(d); - return rc; -} =20 /* * altp2m operations are envisioned as being used in several different diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h index 1d7b66f927..a6f4ae76a1 100644 --- a/xen/include/asm-x86/hvm/hvm.h +++ b/xen/include/asm-x86/hvm/hvm.h @@ -335,6 +335,10 @@ unsigned long hvm_cr4_guest_valid_bits(const struct do= main *d, bool restore); bool hvm_flush_vcpu_tlb(bool (*flush_vcpu)(void *ctxt, struct vcpu *v), void *ctxt); =20 +/* Caller must hold domain locks */ +int hvm_get_param(struct domain *d, uint32_t index, uint64_t *value); +int hvm_set_param(struct domain *d, uint32_t index, uint64_t value); + #ifdef CONFIG_HVM =20 #define hvm_get_guest_tsc(v) hvm_get_guest_tsc_fixed(v, 0) --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698126; cv=none; d=zohomail.com; s=zohoarc; b=l6ZarlqRdM+ALjqwvppfDb7GcIIX/2Dm1Ed8FVURaEV17fOIb5VsGGHKNHzsLB4RbmznFIiMxPQR8kgb3aGlbyfNWBayWs9obk/dl6rKZuglzQTxf8q5RcV5fFzkqhPzI3Rt/VxA5ydIR00KVxnUSyaF8Kgsf+3s6xIGEc6UTtA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698126; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cdXc1HacIbsEMRFURCCF1fTrq6QHN2PNgDPv8d4ggh0=; b=iwBQLWdoBYtj8bGG6OgpvrC74mbrRKDLxQXPNwGgQEvuiL4vQB+TwDEMhJP2Az1dJc9XxMMdPweIh1yFoRYh4u44gXvr+X+aAacQRjYgqx3N79pRIaIBE0WCdgGnQCBdr46AGrT2iU7VGBuFE/9cPaGGqu8kdZxCvoc3vNdOZYY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698126034773.6244613487725; Wed, 18 Dec 2019 11:42:06 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCL-0007fG-OT; Wed, 18 Dec 2019 19:41:29 +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 1ihfCK-0007ee-6g for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:41:28 +0000 Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 59282406-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:13 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:11 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:10 -0800 X-Inumbo-ID: 59282406-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196279" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:39 -0800 Message-Id: <3b07eeab8b384b4abf5277f26ebb8178e9434427.1576697796.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 02/20] xen/x86: Make hap_get_allocation accessible 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 , George Dunlap , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" During VM forking we'll copy the parent domain's parameters to the client, including the HAP shadow memory setting that is used for storing the domain= 's EPT. We'll copy this in the hypervisor instead doing it during toolstack la= unch to allow the domain to start executing and unsharing memory before (or even completely without) the toolstack. Signed-off-by: Tamas K Lengyel Acked-by: Andrew Cooper --- xen/arch/x86/mm/hap/hap.c | 3 +-- xen/include/asm-x86/hap.h | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c index 3d93f3451c..c7c7ff6e99 100644 --- a/xen/arch/x86/mm/hap/hap.c +++ b/xen/arch/x86/mm/hap/hap.c @@ -321,8 +321,7 @@ static void hap_free_p2m_page(struct domain *d, struct = page_info *pg) } =20 /* Return the size of the pool, rounded up to the nearest MB */ -static unsigned int -hap_get_allocation(struct domain *d) +unsigned int hap_get_allocation(struct domain *d) { unsigned int pg =3D d->arch.paging.hap.total_pages + d->arch.paging.hap.p2m_pages; diff --git a/xen/include/asm-x86/hap.h b/xen/include/asm-x86/hap.h index b94bfb4ed0..1bf07e49fe 100644 --- a/xen/include/asm-x86/hap.h +++ b/xen/include/asm-x86/hap.h @@ -45,6 +45,7 @@ int hap_track_dirty_vram(struct domain *d, =20 extern const struct paging_mode *hap_paging_get_mode(struct vcpu *); int hap_set_allocation(struct domain *d, unsigned int pages, bool *preempt= ed); +unsigned int hap_get_allocation(struct domain *d); =20 #endif /* XEN_HAP_H */ =20 --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698126; cv=none; d=zohomail.com; s=zohoarc; b=U0amEcBYPF4rYWuUaYhJkdGcwJAvXisKtoLuZhD835wl4sb+r15Py+s99IF+DTAFy5e/fbRgZRFrPOcGXljPNeeY0knB9aid3RfwK7wJDJGuWUQx/sgu5NUPQwzUjQmrxCemJbTtas6OzlBPYI0iladL0aPF9h7lze8NsU1HX0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698126; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=r5KLvGgfUEDEeilGXwJnw5AEvt+vs84SRsUaK+UFJBg=; b=nIwy6HHgivwIU1dO0idfP5ZhPfLv+q2cvDGoTnfYnf/f6WcvhTGizid18v/8dKAYCPPl/tbx/rjnzdAfYxJ3lFIEhPQs2enRTUU4x9VBZa3VBHEVXYm6eWbt/+YDhopNZRIdhAXN5Y02yjYOK1xLfD6hsdJ+lF5CXagfTRETcUw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698126290470.29332207779737; Wed, 18 Dec 2019 11:42:06 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCG-0007co-Eh; Wed, 18 Dec 2019 19:41:24 +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 1ihfCF-0007cP-6s for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:41:23 +0000 Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 58b04db5-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:13 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:12 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:11 -0800 X-Inumbo-ID: 58b04db5-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196285" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:40 -0800 Message-Id: <01275f564385bb6b2f69158b004ef671ab890719.1576697796.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 03/20] tools/libxc: clean up memory sharing files 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: Ian Jackson , Tamas K Lengyel , Wei Liu Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" No functional changes. Signed-off-by: Tamas K Lengyel Acked-by: Wei Liu --- tools/libxc/include/xenctrl.h | 24 ++++++++++++------------ tools/libxc/xc_memshr.c | 12 ++++++------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index f4431687b3..b5ffa53d55 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2060,7 +2060,7 @@ int xc_monitor_emulate_each_rep(xc_interface *xch, ui= nt32_t domain_id, * * Sharing is supported only on the x86 architecture in 64 bit mode, with * Hardware-Assisted Paging (i.e. Intel EPT, AMD NPT). Moreover, AMD NPT - * support is considered experimental.=20 + * support is considered experimental. =20 * Calls below return ENOSYS if not in the x86_64 architecture. * Calls below return ENODEV if the domain does not support HAP. @@ -2107,13 +2107,13 @@ int xc_memshr_control(xc_interface *xch, * EINVAL or EACCESS if the request is denied by the security policy */ =20 -int xc_memshr_ring_enable(xc_interface *xch,=20 +int xc_memshr_ring_enable(xc_interface *xch, uint32_t domid, uint32_t *port); /* Disable the ring for ENOMEM communication. * May fail with EINVAL if the ring was not enabled in the first place. */ -int xc_memshr_ring_disable(xc_interface *xch,=20 +int xc_memshr_ring_disable(xc_interface *xch, uint32_t domid); =20 /* @@ -2126,7 +2126,7 @@ int xc_memshr_ring_disable(xc_interface *xch, int xc_memshr_domain_resume(xc_interface *xch, uint32_t domid); =20 -/* Select a page for sharing.=20 +/* Select a page for sharing. * * A 64 bit opaque handle will be stored in handle. The hypervisor ensures * that if the page is modified, the handle will be invalidated, and future @@ -2155,7 +2155,7 @@ int xc_memshr_nominate_gref(xc_interface *xch, =20 /* The three calls below may fail with * 10 (or -XENMEM_SHARING_OP_S_HANDLE_INVALID) if the handle passed as sou= rce - * is invalid. =20 + * is invalid. * 9 (or -XENMEM_SHARING_OP_C_HANDLE_INVALID) if the handle passed as clie= nt is * invalid. */ @@ -2168,7 +2168,7 @@ int xc_memshr_nominate_gref(xc_interface *xch, * * After successful sharing, the client handle becomes invalid. Both tuples point to the same mfn with the same handle, the one specifi= ed as - * source. Either 3-tuple can be specified later for further re-sharing.=20 + * source. Either 3-tuple can be specified later for further re-sharing. */ int xc_memshr_share_gfns(xc_interface *xch, uint32_t source_domain, @@ -2193,7 +2193,7 @@ int xc_memshr_share_grefs(xc_interface *xch, /* Allows to add to the guest physmap of the client domain a shared frame * directly. * - * May additionally fail with=20 + * May additionally fail with * 9 (-XENMEM_SHARING_OP_C_HANDLE_INVALID) if the physmap entry for the g= fn is * not suitable. * ENOMEM if internal data structures cannot be allocated. @@ -2222,7 +2222,7 @@ int xc_memshr_range_share(xc_interface *xch, uint64_t last_gfn); =20 /* Debug calls: return the number of pages referencing the shared frame ba= cking - * the input argument. Should be one or greater.=20 + * the input argument. Should be one or greater. * * May fail with EINVAL if there is no backing shared frame for the input * argument. @@ -2235,9 +2235,9 @@ int xc_memshr_debug_gref(xc_interface *xch, uint32_t domid, grant_ref_t gref); =20 -/* Audits the share subsystem.=20 - *=20 - * Returns ENOSYS if not supported (may not be compiled into the hyperviso= r).=20 +/* Audits the share subsystem. + * + * Returns ENOSYS if not supported (may not be compiled into the hyperviso= r). * * Returns the number of errors found during auditing otherwise. May be (s= hould * be!) zero. @@ -2273,7 +2273,7 @@ long xc_sharing_freed_pages(xc_interface *xch); * should return 1. (And dominfo(d) for each of the two domains should ret= urn 1 * as well). * - * Note that some of these sharing_used_frames may be referenced by=20 + * Note that some of these sharing_used_frames may be referenced by * a single domain page, and thus not realize any savings. The same * applies to some of the pages counted in dominfo(d)->shr_pages. */ diff --git a/tools/libxc/xc_memshr.c b/tools/libxc/xc_memshr.c index d5e135e0d9..5ef56a6933 100644 --- a/tools/libxc/xc_memshr.c +++ b/tools/libxc/xc_memshr.c @@ -41,7 +41,7 @@ int xc_memshr_control(xc_interface *xch, return do_domctl(xch, &domctl); } =20 -int xc_memshr_ring_enable(xc_interface *xch,=20 +int xc_memshr_ring_enable(xc_interface *xch, uint32_t domid, uint32_t *port) { @@ -57,7 +57,7 @@ int xc_memshr_ring_enable(xc_interface *xch, port); } =20 -int xc_memshr_ring_disable(xc_interface *xch,=20 +int xc_memshr_ring_disable(xc_interface *xch, uint32_t domid) { return xc_vm_event_control(xch, domid, @@ -85,11 +85,11 @@ int xc_memshr_nominate_gfn(xc_interface *xch, memset(&mso, 0, sizeof(mso)); =20 mso.op =3D XENMEM_sharing_op_nominate_gfn; - mso.u.nominate.u.gfn =3D gfn;=20 + mso.u.nominate.u.gfn =3D gfn; =20 rc =3D xc_memshr_memop(xch, domid, &mso); =20 - if (!rc) *handle =3D mso.u.nominate.handle;=20 + if (!rc) *handle =3D mso.u.nominate.handle; =20 return rc; } @@ -105,11 +105,11 @@ int xc_memshr_nominate_gref(xc_interface *xch, memset(&mso, 0, sizeof(mso)); =20 mso.op =3D XENMEM_sharing_op_nominate_gref; - mso.u.nominate.u.grant_ref =3D gref;=20 + mso.u.nominate.u.grant_ref =3D gref; =20 rc =3D xc_memshr_memop(xch, domid, &mso); =20 - if (!rc) *handle =3D mso.u.nominate.handle;=20 + if (!rc) *handle =3D mso.u.nominate.handle; =20 return rc; } --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698137; cv=none; d=zohomail.com; s=zohoarc; b=OqwGqkdMGVsgVQk4QVDXLc4lF24p6YMBUU7pp8yWmVgLDysP7ls7YcSVwnHH1nqMvHVTJZ3AXCkpJHSyf3ccjMbF047gaRPjL4tege5ufI8Zq0KL14/CcPgLsG2Py144PoThlK2rr9MlQa8DGs0OT8FQ1my3epADQSZqyWTAmwU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698137; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fC7sca6V1MOeGQm2Rtg0sgSWaNv1UXPMAGUYTjo9B20=; b=S6dS88tvvbWTmPcC7G6MbnDeMYEDdniCRXAlYaOgt6em5GrN/ACnVhCBe5SAk9NL8lU3otgC0qdpzE1cvBJH/e+owxzy6Gl5nDbQaQxUm0748Qak2Rzkv5W9v5YmshJGqXzRGTHu36vdKrT0Dmnfbn8UEAUSVyVp+eqdAx+lQSI= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698137080442.15883878864804; Wed, 18 Dec 2019 11:42:17 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCR-0007hH-3t; Wed, 18 Dec 2019 19:41:35 +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 1ihfCP-0007gW-7J for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:41:33 +0000 Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 592a0794-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:13 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:12 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:12 -0800 X-Inumbo-ID: 592a0794-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196291" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:41 -0800 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 04/20] x86/mem_sharing: cleanup code and comments in various locations 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 , Tamas K Lengyel , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" No functional changes. Signed-off-by: Tamas K Lengyel --- xen/arch/x86/hvm/hvm.c | 11 +- xen/arch/x86/mm/mem_sharing.c | 342 +++++++++++++++++------------- xen/arch/x86/mm/p2m.c | 17 +- xen/include/asm-x86/mem_sharing.h | 51 +++-- 4 files changed, 236 insertions(+), 185 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 5a3a962fbb..1e888b403b 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1902,12 +1902,11 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned= long gla, if ( npfec.write_access && (p2mt =3D=3D p2m_ram_shared) ) { ASSERT(p2m_is_hostp2m(p2m)); - sharing_enomem =3D=20 - (mem_sharing_unshare_page(currd, gfn, 0) < 0); + sharing_enomem =3D mem_sharing_unshare_page(currd, gfn, 0); rc =3D 1; goto out_put_gfn; } -=20 + /* Spurious fault? PoD and log-dirty also take this path. */ if ( p2m_is_ram(p2mt) ) { @@ -1953,9 +1952,11 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned = long gla, __put_gfn(p2m, gfn); __put_gfn(hostp2m, gfn); out: - /* All of these are delayed until we exit, since we might=20 + /* + * All of these are delayed until we exit, since we might * sleep on event ring wait queues, and we must not hold - * locks in such circumstance */ + * locks in such circumstance. + */ if ( paged ) p2m_mem_paging_populate(currd, gfn); if ( sharing_enomem ) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index efb8821768..319aaf3074 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -59,8 +59,10 @@ static DEFINE_PER_CPU(pg_lock_data_t, __pld); #define RMAP_USES_HASHTAB(page) \ ((page)->sharing->hash_table.flag =3D=3D NULL) #define RMAP_HEAVY_SHARED_PAGE RMAP_HASHTAB_SIZE -/* A bit of hysteresis. We don't want to be mutating between list and hash - * table constantly. */ +/* + * A bit of hysteresis. We don't want to be mutating between list and hash + * table constantly. + */ #define RMAP_LIGHT_SHARED_PAGE (RMAP_HEAVY_SHARED_PAGE >> 2) =20 #if MEM_SHARING_AUDIT @@ -88,7 +90,7 @@ static inline void page_sharing_dispose(struct page_info = *page) { /* Unlikely given our thresholds, but we should be careful. */ if ( unlikely(RMAP_USES_HASHTAB(page)) ) - free_xenheap_pages(page->sharing->hash_table.bucket,=20 + free_xenheap_pages(page->sharing->hash_table.bucket, RMAP_HASHTAB_ORDER); =20 spin_lock(&shr_audit_lock); @@ -105,7 +107,7 @@ static inline void page_sharing_dispose(struct page_inf= o *page) { /* Unlikely given our thresholds, but we should be careful. */ if ( unlikely(RMAP_USES_HASHTAB(page)) ) - free_xenheap_pages(page->sharing->hash_table.bucket,=20 + free_xenheap_pages(page->sharing->hash_table.bucket, RMAP_HASHTAB_ORDER); xfree(page->sharing); } @@ -122,8 +124,8 @@ static inline void page_sharing_dispose(struct page_inf= o *page) * Nesting may happen when sharing (and locking) two pages. * Deadlock is avoided by locking pages in increasing order. * All memory sharing code paths take the p2m lock of the affected gfn bef= ore - * taking the lock for the underlying page. We enforce ordering between pa= ge_lock - * and p2m_lock using an mm-locks.h construct. + * taking the lock for the underlying page. We enforce ordering between + * page_lock and p2m_lock using an mm-locks.h construct. * * TODO: Investigate if PGT_validated is necessary. */ @@ -168,7 +170,7 @@ static inline bool mem_sharing_page_lock(struct page_in= fo *pg) if ( rc ) { preempt_disable(); - page_sharing_mm_post_lock(&pld->mm_unlock_level,=20 + page_sharing_mm_post_lock(&pld->mm_unlock_level, &pld->recurse_count); } return rc; @@ -178,7 +180,7 @@ static inline void mem_sharing_page_unlock(struct page_= info *pg) { pg_lock_data_t *pld =3D &(this_cpu(__pld)); =20 - page_sharing_mm_unlock(pld->mm_unlock_level,=20 + page_sharing_mm_unlock(pld->mm_unlock_level, &pld->recurse_count); preempt_enable(); _page_unlock(pg); @@ -186,7 +188,7 @@ static inline void mem_sharing_page_unlock(struct page_= info *pg) =20 static inline shr_handle_t get_next_handle(void) { - /* Get the next handle get_page style */=20 + /* Get the next handle get_page style */ uint64_t x, y =3D next_handle; do { x =3D y; @@ -198,24 +200,26 @@ static inline shr_handle_t get_next_handle(void) #define mem_sharing_enabled(d) \ (is_hvm_domain(d) && (d)->arch.hvm.mem_sharing_enabled) =20 -static atomic_t nr_saved_mfns =3D ATOMIC_INIT(0);=20 +static atomic_t nr_saved_mfns =3D ATOMIC_INIT(0); static atomic_t nr_shared_mfns =3D ATOMIC_INIT(0); =20 -/** Reverse map **/ -/* Every shared frame keeps a reverse map (rmap) of tuples t= hat +/* + * Reverse map + * + * Every shared frame keeps a reverse map (rmap) of tuples t= hat * this shared frame backs. For pages with a low degree of sharing, a O(n) * search linked list is good enough. For pages with higher degree of shar= ing, - * we use a hash table instead. */ + * we use a hash table instead. + */ =20 typedef struct gfn_info { unsigned long gfn; - domid_t domain;=20 + domid_t domain; struct list_head list; } gfn_info_t; =20 -static inline void -rmap_init(struct page_info *page) +static inline void rmap_init(struct page_info *page) { /* We always start off as a doubly linked list. */ INIT_LIST_HEAD(&page->sharing->gfns); @@ -225,10 +229,11 @@ rmap_init(struct page_info *page) #define HASH(domain, gfn) \ (((gfn) + (domain)) % RMAP_HASHTAB_SIZE) =20 -/* Conversions. Tuned by the thresholds. Should only happen twice=20 - * (once each) during the lifetime of a shared page */ -static inline int -rmap_list_to_hash_table(struct page_info *page) +/* + * Conversions. Tuned by the thresholds. Should only happen twice + * (once each) during the lifetime of a shared page. + */ +static inline int rmap_list_to_hash_table(struct page_info *page) { unsigned int i; struct list_head *pos, *tmp, *b =3D @@ -254,8 +259,7 @@ rmap_list_to_hash_table(struct page_info *page) return 0; } =20 -static inline void -rmap_hash_table_to_list(struct page_info *page) +static inline void rmap_hash_table_to_list(struct page_info *page) { unsigned int i; struct list_head *bucket =3D page->sharing->hash_table.bucket; @@ -276,8 +280,7 @@ rmap_hash_table_to_list(struct page_info *page) } =20 /* Generic accessors to the rmap */ -static inline unsigned long -rmap_count(struct page_info *pg) +static inline unsigned long rmap_count(struct page_info *pg) { unsigned long count; unsigned long t =3D read_atomic(&pg->u.inuse.type_info); @@ -287,11 +290,13 @@ rmap_count(struct page_info *pg) return count; } =20 -/* The page type count is always decreased after removing from the rmap. - * Use a convert flag to avoid mutating the rmap if in the middle of an=20 - * iterator, or if the page will be soon destroyed anyways. */ -static inline void -rmap_del(gfn_info_t *gfn_info, struct page_info *page, int convert) +/* + * The page type count is always decreased after removing from the rmap. + * Use a convert flag to avoid mutating the rmap if in the middle of an + * iterator, or if the page will be soon destroyed anyways. + */ +static inline +void rmap_del(gfn_info_t *gfn_info, struct page_info *page, int convert) { if ( RMAP_USES_HASHTAB(page) && convert && (rmap_count(page) <=3D RMAP_LIGHT_SHARED_PAGE) ) @@ -302,8 +307,7 @@ rmap_del(gfn_info_t *gfn_info, struct page_info *page, = int convert) } =20 /* The page type count is always increased before adding to the rmap. */ -static inline void -rmap_add(gfn_info_t *gfn_info, struct page_info *page) +static inline void rmap_add(gfn_info_t *gfn_info, struct page_info *page) { struct list_head *head; =20 @@ -314,7 +318,7 @@ rmap_add(gfn_info_t *gfn_info, struct page_info *page) (void)rmap_list_to_hash_table(page); =20 head =3D (RMAP_USES_HASHTAB(page)) ? - page->sharing->hash_table.bucket +=20 + page->sharing->hash_table.bucket + HASH(gfn_info->domain, gfn_info->gfn) : &page->sharing->gfns; =20 @@ -322,9 +326,9 @@ rmap_add(gfn_info_t *gfn_info, struct page_info *page) list_add(&gfn_info->list, head); } =20 -static inline gfn_info_t * -rmap_retrieve(uint16_t domain_id, unsigned long gfn,=20 - struct page_info *page) +static inline +gfn_info_t *rmap_retrieve(uint16_t domain_id, unsigned long gfn, + struct page_info *page) { gfn_info_t *gfn_info; struct list_head *le, *head; @@ -364,18 +368,18 @@ struct rmap_iterator { unsigned int bucket; }; =20 -static inline void -rmap_seed_iterator(struct page_info *page, struct rmap_iterator *ri) +static inline +void rmap_seed_iterator(struct page_info *page, struct rmap_iterator *ri) { ri->curr =3D (RMAP_USES_HASHTAB(page)) ? page->sharing->hash_table.bucket : &page->sharing->gfns; - ri->next =3D ri->curr->next;=20 + ri->next =3D ri->curr->next; ri->bucket =3D 0; } =20 -static inline gfn_info_t * -rmap_iterate(struct page_info *page, struct rmap_iterator *ri) +static inline +gfn_info_t *rmap_iterate(struct page_info *page, struct rmap_iterator *ri) { struct list_head *head =3D (RMAP_USES_HASHTAB(page)) ? page->sharing->hash_table.bucket + ri->bucket : @@ -405,14 +409,14 @@ retry: return list_entry(ri->curr, gfn_info_t, list); } =20 -static inline gfn_info_t *mem_sharing_gfn_alloc(struct page_info *page, - struct domain *d, - unsigned long gfn) +static inline +gfn_info_t *mem_sharing_gfn_alloc(struct page_info *page, struct domain *d, + unsigned long gfn) { gfn_info_t *gfn_info =3D xmalloc(gfn_info_t); =20 if ( gfn_info =3D=3D NULL ) - return NULL;=20 + return NULL; =20 gfn_info->gfn =3D gfn; gfn_info->domain =3D d->domain_id; @@ -425,9 +429,9 @@ static inline gfn_info_t *mem_sharing_gfn_alloc(struct = page_info *page, return gfn_info; } =20 -static inline void mem_sharing_gfn_destroy(struct page_info *page, - struct domain *d, - gfn_info_t *gfn_info) +static inline +void mem_sharing_gfn_destroy(struct page_info *page, struct domain *d, + gfn_info_t *gfn_info) { /* Decrement the number of pages. */ atomic_dec(&d->shr_pages); @@ -437,25 +441,29 @@ static inline void mem_sharing_gfn_destroy(struct pag= e_info *page, xfree(gfn_info); } =20 -static struct page_info* mem_sharing_lookup(unsigned long mfn) +static inline struct page_info* mem_sharing_lookup(unsigned long mfn) { - if ( mfn_valid(_mfn(mfn)) ) - { - struct page_info* page =3D mfn_to_page(_mfn(mfn)); - if ( page_get_owner(page) =3D=3D dom_cow ) - { - /* Count has to be at least two, because we're called - * with the mfn locked (1) and this is supposed to be=20 - * a shared page (1). */ - unsigned long t =3D read_atomic(&page->u.inuse.type_info); - ASSERT((t & PGT_type_mask) =3D=3D PGT_shared_page); - ASSERT((t & PGT_count_mask) >=3D 2); - ASSERT(SHARED_M2P(get_gpfn_from_mfn(mfn))); - return page; - } - } + struct page_info* page; + unsigned long t; =20 - return NULL; + if ( !mfn_valid(_mfn(mfn)) ) + return NULL; + + page =3D mfn_to_page(_mfn(mfn)); + if ( page_get_owner(page) !=3D dom_cow ) + return NULL; + + /* + * Count has to be at least two, because we're called + * with the mfn locked (1) and this is supposed to be + * a shared page (1). + */ + t =3D read_atomic(&page->u.inuse.type_info); + ASSERT((t & PGT_type_mask) =3D=3D PGT_shared_page); + ASSERT((t & PGT_count_mask) >=3D 2); + ASSERT(SHARED_M2P(get_gpfn_from_mfn(mfn))); + + return page; } =20 static int audit(void) @@ -492,7 +500,7 @@ static int audit(void) continue; } =20 - /* Check if the MFN has correct type, owner and handle. */=20 + /* Check if the MFN has correct type, owner and handle. */ if ( (pg->u.inuse.type_info & PGT_type_mask) !=3D PGT_shared_page ) { MEM_SHARING_DEBUG("mfn %lx in audit list, but not PGT_shared_pa= ge (%lx)!\n", @@ -545,7 +553,7 @@ static int audit(void) errors++; continue; } - o_mfn =3D get_gfn_query_unlocked(d, g->gfn, &t);=20 + o_mfn =3D get_gfn_query_unlocked(d, g->gfn, &t); if ( !mfn_eq(o_mfn, mfn) ) { MEM_SHARING_DEBUG("Incorrect P2M for d=3D%hu, PFN=3D%lx." @@ -568,7 +576,7 @@ static int audit(void) { MEM_SHARING_DEBUG("Mismatched counts for MFN=3D%lx." "nr_gfns in list %lu, in type_info %lx\n", - mfn_x(mfn), nr_gfns,=20 + mfn_x(mfn), nr_gfns, (pg->u.inuse.type_info & PGT_count_mask)); errors++; } @@ -603,7 +611,7 @@ int mem_sharing_notify_enomem(struct domain *d, unsigne= d long gfn, .u.mem_sharing.p2mt =3D p2m_ram_shared }; =20 - if ( (rc =3D __vm_event_claim_slot(d,=20 + if ( (rc =3D __vm_event_claim_slot(d, d->vm_event_share, allow_sleep)) < 0 ) return rc; =20 @@ -629,9 +637,9 @@ unsigned int mem_sharing_get_nr_shared_mfns(void) } =20 /* Functions that change a page's type and ownership */ -static int page_make_sharable(struct domain *d,=20 - struct page_info *page,=20 - int expected_refcnt) +static int page_make_sharable(struct domain *d, + struct page_info *page, + int expected_refcnt) { bool_t drop_dom_ref; =20 @@ -658,8 +666,10 @@ static int page_make_sharable(struct domain *d, return -EEXIST; } =20 - /* Check if the ref count is 2. The first from PGC_allocated, and - * the second from get_page_and_type at the top of this function */ + /* + * Check if the ref count is 2. The first from PGC_allocated, and + * the second from get_page_and_type at the top of this function. + */ if ( page->count_info !=3D (PGC_allocated | (2 + expected_refcnt)) ) { spin_unlock(&d->page_alloc_lock); @@ -675,6 +685,7 @@ static int page_make_sharable(struct domain *d, =20 if ( drop_dom_ref ) put_domain(d); + return 0; } =20 @@ -684,7 +695,7 @@ static int page_make_private(struct domain *d, struct p= age_info *page) =20 if ( !get_page(page, dom_cow) ) return -EINVAL; - =20 + spin_lock(&d->page_alloc_lock); =20 if ( d->is_dying ) @@ -727,10 +738,13 @@ static inline struct page_info *__grab_shared_page(mf= n_t mfn) =20 if ( !mfn_valid(mfn) ) return NULL; + pg =3D mfn_to_page(mfn); =20 - /* If the page is not validated we can't lock it, and if it's =20 - * not validated it's obviously not shared. */ + /* + * If the page is not validated we can't lock it, and if it's + * not validated it's obviously not shared. + */ if ( !mem_sharing_page_lock(pg) ) return NULL; =20 @@ -754,10 +768,10 @@ static int debug_mfn(mfn_t mfn) return -EINVAL; } =20 - MEM_SHARING_DEBUG(=20 + MEM_SHARING_DEBUG( "Debug page: MFN=3D%lx is ci=3D%lx, ti=3D%lx, owner_id=3D%d\n", - mfn_x(page_to_mfn(page)),=20 - page->count_info,=20 + mfn_x(page_to_mfn(page)), + page->count_info, page->u.inuse.type_info, page_get_owner(page)->domain_id); =20 @@ -775,7 +789,7 @@ static int debug_gfn(struct domain *d, gfn_t gfn) =20 mfn =3D get_gfn_query(d, gfn_x(gfn), &p2mt); =20 - MEM_SHARING_DEBUG("Debug for dom%d, gfn=3D%" PRI_gfn "\n",=20 + MEM_SHARING_DEBUG("Debug for dom%d, gfn=3D%" PRI_gfn "\n", d->domain_id, gfn_x(gfn)); num_refs =3D debug_mfn(mfn); put_gfn(d, gfn_x(gfn)); @@ -796,9 +810,9 @@ static int debug_gref(struct domain *d, grant_ref_t ref) d->domain_id, ref, rc); return rc; } - =20 + MEM_SHARING_DEBUG( - "=3D=3D> Grant [dom=3D%d,ref=3D%d], status=3D%x. ",=20 + "=3D=3D> Grant [dom=3D%d,ref=3D%d], status=3D%x. ", d->domain_id, ref, status); =20 return debug_gfn(d, gfn); @@ -824,15 +838,12 @@ static int nominate_page(struct domain *d, gfn_t gfn, goto out; =20 /* Return the handle if the page is already shared */ - if ( p2m_is_shared(p2mt) ) { + if ( p2m_is_shared(p2mt) ) + { struct page_info *pg =3D __grab_shared_page(mfn); if ( !pg ) - { - gprintk(XENLOG_ERR, - "Shared p2m entry gfn %" PRI_gfn ", but could not grab= mfn %" PRI_mfn " dom%d\n", - gfn_x(gfn), mfn_x(mfn), d->domain_id); BUG(); - } + *phandle =3D pg->sharing->handle; ret =3D 0; mem_sharing_page_unlock(pg); @@ -843,7 +854,6 @@ static int nominate_page(struct domain *d, gfn_t gfn, if ( !p2m_is_sharable(p2mt) ) goto out; =20 -#ifdef CONFIG_HVM /* Check if there are mem_access/remapped altp2m entries for this page= */ if ( altp2m_active(d) ) { @@ -872,42 +882,42 @@ static int nominate_page(struct domain *d, gfn_t gfn, =20 altp2m_list_unlock(d); } -#endif =20 /* Try to convert the mfn to the sharable type */ page =3D mfn_to_page(mfn); - ret =3D page_make_sharable(d, page, expected_refcnt);=20 - if ( ret )=20 + ret =3D page_make_sharable(d, page, expected_refcnt); + if ( ret ) goto out; =20 - /* Now that the page is validated, we can lock it. There is no=20 - * race because we're holding the p2m entry, so no one else=20 - * could be nominating this gfn */ + /* + * Now that the page is validated, we can lock it. There is no + * race because we're holding the p2m entry, so no one else + * could be nominating this gfn. + */ ret =3D -ENOENT; if ( !mem_sharing_page_lock(page) ) goto out; =20 /* Initialize the shared state */ ret =3D -ENOMEM; - if ( (page->sharing =3D=20 - xmalloc(struct page_sharing_info)) =3D=3D NULL ) + if ( !(page->sharing =3D xmalloc(struct page_sharing_info)) ) { /* Making a page private atomically unlocks it */ - BUG_ON(page_make_private(d, page) !=3D 0); + BUG_ON(page_make_private(d, page)); goto out; } page->sharing->pg =3D page; rmap_init(page); =20 /* Create the handle */ - page->sharing->handle =3D get_next_handle(); =20 + page->sharing->handle =3D get_next_handle(); =20 /* Create the local gfn info */ - if ( mem_sharing_gfn_alloc(page, d, gfn_x(gfn)) =3D=3D NULL ) + if ( !mem_sharing_gfn_alloc(page, d, gfn_x(gfn)) ) { xfree(page->sharing); page->sharing =3D NULL; - BUG_ON(page_make_private(d, page) !=3D 0); + BUG_ON(page_make_private(d, page)); goto out; } =20 @@ -946,15 +956,19 @@ static int share_pages(struct domain *sd, gfn_t sgfn,= shr_handle_t sh, get_two_gfns(sd, sgfn, &smfn_type, NULL, &smfn, cd, cgfn, &cmfn_type, NULL, &cmfn, 0, &tg); =20 - /* This tricky business is to avoid two callers deadlocking if=20 - * grabbing pages in opposite client/source order */ + /* + * This tricky business is to avoid two callers deadlocking if + * grabbing pages in opposite client/source order. + */ if ( mfn_eq(smfn, cmfn) ) { - /* The pages are already the same. We could return some + /* + * The pages are already the same. We could return some * kind of error here, but no matter how you look at it, * the pages are already 'shared'. It possibly represents * a big problem somewhere else, but as far as sharing is - * concerned: great success! */ + * concerned: great success! + */ ret =3D 0; goto err_out; } @@ -1010,11 +1024,15 @@ static int share_pages(struct domain *sd, gfn_t sgf= n, shr_handle_t sh, rmap_seed_iterator(cpage, &ri); while ( (gfn =3D rmap_iterate(cpage, &ri)) !=3D NULL) { - /* Get the source page and type, this should never fail:=20 - * we are under shr lock, and got a successful lookup */ + /* + * Get the source page and type, this should never fail: + * we are under shr lock, and got a successful lookup. + */ BUG_ON(!get_page_and_type(spage, dom_cow, PGT_shared_page)); - /* Move the gfn_info from client list to source list. - * Don't change the type of rmap for the client page. */ + /* + * Move the gfn_info from client list to source list. + * Don't change the type of rmap for the client page. + */ rmap_del(gfn, cpage, 0); rmap_add(gfn, spage); put_count++; @@ -1043,14 +1061,14 @@ static int share_pages(struct domain *sd, gfn_t sgf= n, shr_handle_t sh, atomic_dec(&nr_shared_mfns); atomic_inc(&nr_saved_mfns); ret =3D 0; - =20 + err_out: put_two_gfns(&tg); return ret; } =20 int mem_sharing_add_to_physmap(struct domain *sd, unsigned long sgfn, shr_= handle_t sh, - struct domain *cd, unsigned long cgfn)=20 + struct domain *cd, unsigned long cgfn) { struct page_info *spage; int ret =3D -EINVAL; @@ -1069,15 +1087,18 @@ int mem_sharing_add_to_physmap(struct domain *sd, u= nsigned long sgfn, shr_handle spage =3D __grab_shared_page(smfn); if ( spage =3D=3D NULL ) goto err_out; + ASSERT(smfn_type =3D=3D p2m_ram_shared); =20 /* Check that the handles match */ if ( spage->sharing->handle !=3D sh ) goto err_unlock; =20 - /* Make sure the target page is a hole in the physmap. These are typic= ally + /* + * Make sure the target page is a hole in the physmap. These are typic= ally * p2m_mmio_dm, but also accept p2m_invalid and paged out pages. See t= he - * definition of p2m_is_hole in p2m.h. */ + * definition of p2m_is_hole in p2m.h. + */ if ( !p2m_is_hole(cmfn_type) ) { ret =3D XENMEM_SHARING_OP_C_HANDLE_INVALID; @@ -1086,7 +1107,7 @@ int mem_sharing_add_to_physmap(struct domain *sd, uns= igned long sgfn, shr_handle =20 /* This is simpler than regular sharing */ BUG_ON(!get_page_and_type(spage, dom_cow, PGT_shared_page)); - if ( (gfn_info =3D mem_sharing_gfn_alloc(spage, cd, cgfn)) =3D=3D NULL= ) + if ( !(gfn_info =3D mem_sharing_gfn_alloc(spage, cd, cgfn)) ) { put_page_and_type(spage); ret =3D -ENOMEM; @@ -1102,11 +1123,17 @@ int mem_sharing_add_to_physmap(struct domain *sd, u= nsigned long sgfn, shr_handle mem_sharing_gfn_destroy(spage, cd, gfn_info); put_page_and_type(spage); } else { - /* There is a chance we're plugging a hole where a paged out page = was */ + /* + * There is a chance we're plugging a hole where a paged out + * page was. + */ if ( p2m_is_paging(cmfn_type) && (cmfn_type !=3D p2m_ram_paging_ou= t) ) { atomic_dec(&cd->paged_pages); - /* Further, there is a chance this was a valid page. Don't lea= k it. */ + /* + * Further, there is a chance this was a valid page. + * Don't leak it. + */ if ( mfn_valid(cmfn) ) { struct page_info *cpage =3D mfn_to_page(cmfn); @@ -1133,13 +1160,14 @@ err_out: } =20 =20 -/* A note on the rationale for unshare error handling: +/* + * A note on the rationale for unshare error handling: * 1. Unshare can only fail with ENOMEM. Any other error conditions BUG_O= N()'s * 2. We notify a potential dom0 helper through a vm_event ring. But we - * allow the notification to not go to sleep. If the event ring is ful= l=20 + * allow the notification to not go to sleep. If the event ring is full * of ENOMEM warnings, then it's on the ball. * 3. We cannot go to sleep until the unshare is resolved, because we mig= ht - * be buried deep into locks (e.g. something -> copy_to_user -> __hvm_= copy)=20 + * be buried deep into locks (e.g. something -> copy_to_user -> __hvm_= copy) * 4. So, we make sure we: * 4.1. return an error * 4.2. do not corrupt shared memory @@ -1147,19 +1175,20 @@ err_out: * 4.4. let the guest deal with it if the error propagation will reach= it */ int __mem_sharing_unshare_page(struct domain *d, - unsigned long gfn,=20 - uint16_t flags) + unsigned long gfn, + uint16_t flags) { p2m_type_t p2mt; mfn_t mfn; struct page_info *page, *old_page; int last_gfn; gfn_info_t *gfn_info =3D NULL; - =20 + mfn =3D get_gfn(d, gfn, &p2mt); - =20 + /* Has someone already unshared it? */ - if ( !p2m_is_shared(p2mt) ) { + if ( !p2m_is_shared(p2mt) ) + { put_gfn(d, gfn); return 0; } @@ -1167,26 +1196,30 @@ int __mem_sharing_unshare_page(struct domain *d, page =3D __grab_shared_page(mfn); if ( page =3D=3D NULL ) { - gdprintk(XENLOG_ERR, "Domain p2m is shared, but page is not: " - "%lx\n", gfn); + gdprintk(XENLOG_ERR, "Domain p2m is shared, but page is not: %lx\n= ", + gfn); BUG(); } =20 gfn_info =3D rmap_retrieve(d->domain_id, gfn, page); if ( unlikely(gfn_info =3D=3D NULL) ) { - gdprintk(XENLOG_ERR, "Could not find gfn_info for shared gfn: " - "%lx\n", gfn); + gdprintk(XENLOG_ERR, "Could not find gfn_info for shared gfn: %lx\= n", + gfn); BUG(); } =20 - /* Do the accounting first. If anything fails below, we have bigger - * bigger fish to fry. First, remove the gfn from the list. */=20 + /* + * Do the accounting first. If anything fails below, we have bigger + * bigger fish to fry. First, remove the gfn from the list. + */ last_gfn =3D rmap_has_one_entry(page); if ( last_gfn ) { - /* Clean up shared state. Get rid of the tuple - * before destroying the rmap. */ + /* + * Clean up shared state. Get rid of the tuple + * before destroying the rmap. + */ mem_sharing_gfn_destroy(page, d, gfn_info); page_sharing_dispose(page); page->sharing =3D NULL; @@ -1195,8 +1228,10 @@ int __mem_sharing_unshare_page(struct domain *d, else atomic_dec(&nr_saved_mfns); =20 - /* If the GFN is getting destroyed drop the references to MFN=20 - * (possibly freeing the page), and exit early */ + /* + * If the GFN is getting destroyed drop the references to MFN + * (possibly freeing the page), and exit early. + */ if ( flags & MEM_SHARING_DESTROY_GFN ) { if ( !last_gfn ) @@ -1212,7 +1247,7 @@ int __mem_sharing_unshare_page(struct domain *d, =20 return 0; } -=20 + if ( last_gfn ) { /* Making a page private atomically unlocks it */ @@ -1222,14 +1257,16 @@ int __mem_sharing_unshare_page(struct domain *d, =20 old_page =3D page; page =3D alloc_domheap_page(d, 0); - if ( !page )=20 + if ( !page ) { /* Undo dec of nr_saved_mfns, as the retry will decrease again. */ atomic_inc(&nr_saved_mfns); mem_sharing_page_unlock(old_page); put_gfn(d, gfn); - /* Caller is responsible for placing an event - * in the ring */ + /* + * Caller is responsible for placing an event + * in the ring. + */ return -ENOMEM; } =20 @@ -1240,11 +1277,11 @@ int __mem_sharing_unshare_page(struct domain *d, mem_sharing_page_unlock(old_page); put_page_and_type(old_page); =20 -private_page_found: =20 + private_page_found: if ( p2m_change_type_one(d, gfn, p2m_ram_shared, p2m_ram_rw) ) { - gdprintk(XENLOG_ERR, "Could not change p2m type d %hu gfn %lx.\n",=20 - d->domain_id, gfn); + gdprintk(XENLOG_ERR, "Could not change p2m type d %hu gfn %lx.\n", + d->domain_id, gfn); BUG(); } =20 @@ -1277,20 +1314,23 @@ int relinquish_shared_pages(struct domain *d) mfn_t mfn; int set_rc; =20 - if ( atomic_read(&d->shr_pages) =3D=3D 0 ) + if ( !atomic_read(&d->shr_pages) ) break; + mfn =3D p2m->get_entry(p2m, _gfn(gfn), &t, &a, 0, NULL, NULL); - if ( mfn_valid(mfn) && (t =3D=3D p2m_ram_shared) ) + if ( mfn_valid(mfn) && t =3D=3D p2m_ram_shared ) { /* Does not fail with ENOMEM given the DESTROY flag */ - BUG_ON(__mem_sharing_unshare_page(d, gfn,=20 - MEM_SHARING_DESTROY_GFN)); - /* Clear out the p2m entry so no one else may try to + BUG_ON(__mem_sharing_unshare_page(d, gfn, + MEM_SHARING_DESTROY_GFN)); + /* + * Clear out the p2m entry so no one else may try to * unshare. Must succeed: we just read the old entry and - * we hold the p2m lock. */ + * we hold the p2m lock. + */ set_rc =3D p2m->set_entry(p2m, _gfn(gfn), _mfn(0), PAGE_ORDER_= 4K, p2m_invalid, p2m_access_rwx, -1); - ASSERT(set_rc =3D=3D 0); + ASSERT(!set_rc); count +=3D 0x10; } else @@ -1454,7 +1494,7 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) =20 if ( XENMEM_SHARING_OP_FIELD_IS_GREF(mso.u.share.source_gfn) ) { - grant_ref_t gref =3D (grant_ref_t)=20 + grant_ref_t gref =3D (grant_ref_t) (XENMEM_SHARING_OP_FIELD_GET_GREF( mso.u.share.source_gfn)); rc =3D mem_sharing_gref_to_gfn(d->grant_table, gref, &sgfn, @@ -1470,7 +1510,7 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) =20 if ( XENMEM_SHARING_OP_FIELD_IS_GREF(mso.u.share.client_gfn) ) { - grant_ref_t gref =3D (grant_ref_t)=20 + grant_ref_t gref =3D (grant_ref_t) (XENMEM_SHARING_OP_FIELD_GET_GREF( mso.u.share.client_gfn)); rc =3D mem_sharing_gref_to_gfn(cd->grant_table, gref, &cgf= n, @@ -1534,7 +1574,7 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) sh =3D mso.u.share.source_handle; cgfn =3D mso.u.share.client_gfn; =20 - rc =3D mem_sharing_add_to_physmap(d, sgfn, sh, cd, cgfn);=20 + rc =3D mem_sharing_add_to_physmap(d, sgfn, sh, cd, cgfn); =20 rcu_unlock_domain(cd); } diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index ba126f790a..3119269073 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -511,8 +511,10 @@ mfn_t __get_gfn_type_access(struct p2m_domain *p2m, un= signed long gfn_l, if ( (q & P2M_UNSHARE) && p2m_is_shared(*t) ) { ASSERT(p2m_is_hostp2m(p2m)); - /* Try to unshare. If we fail, communicate ENOMEM without - * sleeping. */ + /* + * Try to unshare. If we fail, communicate ENOMEM without + * sleeping. + */ if ( mem_sharing_unshare_page(p2m->domain, gfn_l, 0) < 0 ) mem_sharing_notify_enomem(p2m->domain, gfn_l, false); mfn =3D p2m->get_entry(p2m, gfn, t, a, q, page_order, NULL); @@ -892,15 +894,15 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, = mfn_t mfn, &a, 0, NULL, NULL); if ( p2m_is_shared(ot) ) { - /* Do an unshare to cleanly take care of all corner=20 - * cases. */ + /* Do an unshare to cleanly take care of all corner cases. */ int rc; rc =3D mem_sharing_unshare_page(p2m->domain, gfn_x(gfn_add(gfn, i)), 0); if ( rc ) { p2m_unlock(p2m); - /* NOTE: Should a guest domain bring this upon itself, + /* + * NOTE: Should a guest domain bring this upon itself, * there is not a whole lot we can do. We are buried * deep in locks from most code paths by now. So, fail * the call and don't try to sleep on a wait queue @@ -909,8 +911,9 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mf= n_t mfn, * However, all current (changeset 3432abcf9380) code * paths avoid this unsavoury situation. For now. * - * Foreign domains are okay to place an event as they=20 - * won't go to sleep. */ + * Foreign domains are okay to place an event as they + * won't go to sleep. + */ (void)mem_sharing_notify_enomem(p2m->domain, gfn_x(gfn_add(gfn, i)), fa= lse); return rc; diff --git a/xen/include/asm-x86/mem_sharing.h b/xen/include/asm-x86/mem_sh= aring.h index db22468744..7d40e38563 100644 --- a/xen/include/asm-x86/mem_sharing.h +++ b/xen/include/asm-x86/mem_sharing.h @@ -33,12 +33,14 @@ #define MEM_SHARING_AUDIT 0 #endif =20 -typedef uint64_t shr_handle_t;=20 +typedef uint64_t shr_handle_t; =20 typedef struct rmap_hashtab { struct list_head *bucket; - /* Overlaps with prev pointer of list_head in union below. - * Unlike the prev pointer, this can be NULL. */ + /* + * Overlaps with prev pointer of list_head in union below. + * Unlike the prev pointer, this can be NULL. + */ void *flag; } rmap_hashtab_t; =20 @@ -57,34 +59,34 @@ struct page_sharing_info }; }; =20 -#define sharing_supported(_d) \ - (is_hvm_domain(_d) && paging_mode_hap(_d))=20 - unsigned int mem_sharing_get_nr_saved_mfns(void); unsigned int mem_sharing_get_nr_shared_mfns(void); =20 #define MEM_SHARING_DESTROY_GFN (1<<1) /* Only fails with -ENOMEM. Enforce it with a BUG_ON wrapper. */ int __mem_sharing_unshare_page(struct domain *d, - unsigned long gfn,=20 - uint16_t flags); -static inline int mem_sharing_unshare_page(struct domain *d, - unsigned long gfn, - uint16_t flags) + unsigned long gfn, + uint16_t flags); + +static inline +int mem_sharing_unshare_page(struct domain *d, + unsigned long gfn, + uint16_t flags) { int rc =3D __mem_sharing_unshare_page(d, gfn, flags); - BUG_ON( rc && (rc !=3D -ENOMEM) ); + BUG_ON(rc && (rc !=3D -ENOMEM)); return rc; } =20 -/* If called by a foreign domain, possible errors are +/* + * If called by a foreign domain, possible errors are * -EBUSY -> ring full * -ENOSYS -> no ring to begin with * and the foreign mapper is responsible for retrying. * - * If called by the guest vcpu itself and allow_sleep is set, may=20 - * sleep on a wait queue, so the caller is responsible for not=20 - * holding locks on entry. It may only fail with ENOSYS=20 + * If called by the guest vcpu itself and allow_sleep is set, may + * sleep on a wait queue, so the caller is responsible for not + * holding locks on entry. It may only fail with ENOSYS * * If called by the guest vcpu itself and allow_sleep is not set, * then it's the same as a foreign domain. @@ -92,10 +94,11 @@ static inline int mem_sharing_unshare_page(struct domai= n *d, int mem_sharing_notify_enomem(struct domain *d, unsigned long gfn, bool allow_sleep); int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg); -int mem_sharing_domctl(struct domain *d,=20 +int mem_sharing_domctl(struct domain *d, struct xen_domctl_mem_sharing_op *mec); =20 -/* Scans the p2m and relinquishes any shared pages, destroying=20 +/* + * Scans the p2m and relinquishes any shared pages, destroying * those for which this domain holds the final reference. * Preemptible. */ @@ -107,18 +110,22 @@ static inline unsigned int mem_sharing_get_nr_saved_m= fns(void) { return 0; } + static inline unsigned int mem_sharing_get_nr_shared_mfns(void) { return 0; } -static inline int mem_sharing_unshare_page(struct domain *d, - unsigned long gfn, - uint16_t flags) + +static inline +int mem_sharing_unshare_page(struct domain *d, unsigned long gfn, + uint16_t flags) { ASSERT_UNREACHABLE(); return -EOPNOTSUPP; } -static inline int mem_sharing_notify_enomem(struct domain *d, unsigned lon= g gfn, + +static inline +int mem_sharing_notify_enomem(struct domain *d, unsigned long gfn, bool allow_sleep) { ASSERT_UNREACHABLE(); --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698132; cv=none; d=zohomail.com; s=zohoarc; b=KRooJ3WK7KAfv5pWk/hJw7dlTH0gpmKACl1oPkR3BdeG14xaXWmFgLxKkmeWAH96TPChdRpsfS708lFZO9wTRJVnS+txuxhEK2ZsFl+mQMfGC6L2D3bVNt+t7iCWIM5/NqgCN1ZcsaMh7UYBizvjuwX0GaFp3FN9/SLaf/hf328= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698132; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YtY8YWmi/kabZfj/f4NIQp9qeZ6w95HWIVQHJB1P3lw=; b=Y1qI6u75OyrCJavrl872LFASOqUizjH0fjxLlQOsREeQ5BMh7z2oJWm58SBFcmr0aX/8TrTm9l2qsV6/NfWEqNY3yRJca4uJNungXxfJQbCRMH4kk05h1RbJTmF8IWbxzVSFgKS2MEgCCvldcZXePjYw7d/abahoLmff82/LciY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 15766981322372.545607084086896; Wed, 18 Dec 2019 11:42:12 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCV-0007kA-LS; Wed, 18 Dec 2019 19:41:39 +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 1ihfCU-0007jL-7W for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:41:38 +0000 Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 592a0795-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:15 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:13 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:12 -0800 X-Inumbo-ID: 592a0795-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196297" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:42 -0800 Message-Id: <136e2a2aab7d7e9b40d83429dba1cf7d70650111.1576697796.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 05/20] x86/mem_sharing: make get_two_gfns take locks conditionally 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 , Tamas K Lengyel , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" During VM forking the client lock will already be taken. Signed-off-by: Tamas K Lengyel Acked-by: Andrew Cooper --- xen/arch/x86/mm/mem_sharing.c | 11 ++++++----- xen/include/asm-x86/p2m.h | 10 +++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index 319aaf3074..c0e305ad71 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -954,7 +954,7 @@ static int share_pages(struct domain *sd, gfn_t sgfn, s= hr_handle_t sh, unsigned long put_count =3D 0; =20 get_two_gfns(sd, sgfn, &smfn_type, NULL, &smfn, - cd, cgfn, &cmfn_type, NULL, &cmfn, 0, &tg); + cd, cgfn, &cmfn_type, NULL, &cmfn, 0, &tg, true); =20 /* * This tricky business is to avoid two callers deadlocking if @@ -1068,7 +1068,7 @@ err_out: } =20 int mem_sharing_add_to_physmap(struct domain *sd, unsigned long sgfn, shr_= handle_t sh, - struct domain *cd, unsigned long cgfn) + struct domain *cd, unsigned long cgfn, bool= lock) { struct page_info *spage; int ret =3D -EINVAL; @@ -1080,7 +1080,7 @@ int mem_sharing_add_to_physmap(struct domain *sd, uns= igned long sgfn, shr_handle struct two_gfns tg; =20 get_two_gfns(sd, _gfn(sgfn), &smfn_type, NULL, &smfn, - cd, _gfn(cgfn), &cmfn_type, &a, &cmfn, 0, &tg); + cd, _gfn(cgfn), &cmfn_type, &a, &cmfn, 0, &tg, lock); =20 /* Get the source shared page, check and lock */ ret =3D XENMEM_SHARING_OP_S_HANDLE_INVALID; @@ -1155,7 +1155,8 @@ int mem_sharing_add_to_physmap(struct domain *sd, uns= igned long sgfn, shr_handle err_unlock: mem_sharing_page_unlock(spage); err_out: - put_two_gfns(&tg); + if ( lock ) + put_two_gfns(&tg); return ret; } =20 @@ -1574,7 +1575,7 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) sh =3D mso.u.share.source_handle; cgfn =3D mso.u.share.client_gfn; =20 - rc =3D mem_sharing_add_to_physmap(d, sgfn, sh, cd, cgfn); + rc =3D mem_sharing_add_to_physmap(d, sgfn, sh, cd, cgfn, true); =20 rcu_unlock_domain(cd); } diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 94285db1b4..7399c4a897 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -539,7 +539,7 @@ struct two_gfns { static inline void get_two_gfns(struct domain *rd, gfn_t rgfn, p2m_type_t *rt, p2m_access_t *ra, mfn_t *rmfn, struct domain *ld, gfn_t lgfn, p2m_type_t *lt, p2m_access_t *la, mfn_t *lmfn, - p2m_query_t q, struct two_gfns *rval) + p2m_query_t q, struct two_gfns *rval, bool lock) { mfn_t *first_mfn, *second_mfn, scratch_mfn; p2m_access_t *first_a, *second_a, scratch_a; @@ -569,10 +569,10 @@ do { = \ #undef assign_pointers =20 /* Now do the gets */ - *first_mfn =3D get_gfn_type_access(p2m_get_hostp2m(rval->first_domain= ), - gfn_x(rval->first_gfn), first_t, fir= st_a, q, NULL); - *second_mfn =3D get_gfn_type_access(p2m_get_hostp2m(rval->second_domai= n), - gfn_x(rval->second_gfn), second_t, s= econd_a, q, NULL); + *first_mfn =3D __get_gfn_type_access(p2m_get_hostp2m(rval->first_doma= in), + gfn_x(rval->first_gfn), first_t, f= irst_a, q, NULL, lock); + *second_mfn =3D __get_gfn_type_access(p2m_get_hostp2m(rval->second_dom= ain), + gfn_x(rval->second_gfn), second_t,= second_a, q, NULL, lock); } =20 static inline void put_two_gfns(struct two_gfns *arg) --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698136; cv=none; d=zohomail.com; s=zohoarc; b=Tm9UQ7vJKunq2FkvF5mFTB3PqIMhJAJFBvN9CnYnX/teCkJjFrjmciOkNTYqbuUD+IKWSBokq6jl87+vwWYqyVrgeNaA5udJMfdHPfggqwwii0vt7dAwqoNZ7YP90BN+UhEwMwHkaSYPkZllFgu7UDG2Lpsd4MLXg1Rlsrtb0Rk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698136; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DU/H2JdWFnubXy+Wp39tCit0Js/zP4o1PRK/HBvZ+oo=; b=cSXi7FuxNcJuBXCUkKqrChaRdpKyvVYb3OCFE91rKouzZaanYa9O0ec3jzu5KXr5PCyxseWG6WDm4HotzjYBGKbPn2CA7xXQmt7tmp6AMOL1tnXtkrs9rW+TQ+eKeGYdqfM9us1XcDhpiXjdmAZgtuBkY4YRKyymE4RBJyC90IE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698136047695.4570734069615; Wed, 18 Dec 2019 11:42:16 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCa-0007ng-9s; Wed, 18 Dec 2019 19:41:44 +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 1ihfCZ-0007my-7O for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:41:43 +0000 Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5a2671aa-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:15 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:14 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:13 -0800 X-Inumbo-ID: 5a2671aa-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196304" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:43 -0800 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 06/20] x86/mem_sharing: drop flags from mem_sharing_unshare_page 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 , George Dunlap , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" All callers pass 0 in. Signed-off-by: Tamas K Lengyel Reviewed-by: Wei Liu --- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/mm/p2m.c | 5 ++--- xen/include/asm-x86/mem_sharing.h | 8 +++----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 1e888b403b..e055114922 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1902,7 +1902,7 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned l= ong gla, if ( npfec.write_access && (p2mt =3D=3D p2m_ram_shared) ) { ASSERT(p2m_is_hostp2m(p2m)); - sharing_enomem =3D mem_sharing_unshare_page(currd, gfn, 0); + sharing_enomem =3D mem_sharing_unshare_page(currd, gfn); rc =3D 1; goto out_put_gfn; } diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 3119269073..baea632acc 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -515,7 +515,7 @@ mfn_t __get_gfn_type_access(struct p2m_domain *p2m, uns= igned long gfn_l, * Try to unshare. If we fail, communicate ENOMEM without * sleeping. */ - if ( mem_sharing_unshare_page(p2m->domain, gfn_l, 0) < 0 ) + if ( mem_sharing_unshare_page(p2m->domain, gfn_l) < 0 ) mem_sharing_notify_enomem(p2m->domain, gfn_l, false); mfn =3D p2m->get_entry(p2m, gfn, t, a, q, page_order, NULL); } @@ -896,8 +896,7 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mf= n_t mfn, { /* Do an unshare to cleanly take care of all corner cases. */ int rc; - rc =3D mem_sharing_unshare_page(p2m->domain, - gfn_x(gfn_add(gfn, i)), 0); + rc =3D mem_sharing_unshare_page(p2m->domain, gfn_x(gfn_add(gfn= , i))); if ( rc ) { p2m_unlock(p2m); diff --git a/xen/include/asm-x86/mem_sharing.h b/xen/include/asm-x86/mem_sh= aring.h index 7d40e38563..0a9192d0e2 100644 --- a/xen/include/asm-x86/mem_sharing.h +++ b/xen/include/asm-x86/mem_sharing.h @@ -70,10 +70,9 @@ int __mem_sharing_unshare_page(struct domain *d, =20 static inline int mem_sharing_unshare_page(struct domain *d, - unsigned long gfn, - uint16_t flags) + unsigned long gfn) { - int rc =3D __mem_sharing_unshare_page(d, gfn, flags); + int rc =3D __mem_sharing_unshare_page(d, gfn, 0); BUG_ON(rc && (rc !=3D -ENOMEM)); return rc; } @@ -117,8 +116,7 @@ static inline unsigned int mem_sharing_get_nr_shared_mf= ns(void) } =20 static inline -int mem_sharing_unshare_page(struct domain *d, unsigned long gfn, - uint16_t flags) +int mem_sharing_unshare_page(struct domain *d, unsigned long gfn) { ASSERT_UNREACHABLE(); return -EOPNOTSUPP; --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698138; cv=none; d=zohomail.com; s=zohoarc; b=moxnLuYu0NTUZb6DbQ7/CypFziFU58Df8xjVA2ATJnuaWxuxyd+h7Fk92dXAoLZg3ePNc7uKkC1xvBE3vEvsoCd9DdJD18JyoSX8HX6F0LVWO5IWna3nlK8XQFJu9AZExIIdoSipYuBn8+vEj17pTG06umYFfU8EFLkoefPgMD0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698138; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=n66OgZ7AtttSsThoG6XF98X86i5KPn+2w6ttmSNx3vw=; b=TB2fDaXMovn27Pun0Yqc2QbRVN12IfZoWhKIGT1ONeTwdkfA+UIGMIVMvB6xZvl0w6I/e4L7DW191nVcdh2OByRw/GKgt12VJ5zZYmwZ2vseK3LZnR9KO/tAZuKYawCXG8n1tq9pZ4m6vMV3Kvm5a1jIkArja+XpqY8LCDg89xM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698138730150.03864862064654; Wed, 18 Dec 2019 11:42:18 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCf-0007sk-0y; Wed, 18 Dec 2019 19:41:49 +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 1ihfCe-0007s2-7q for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:41:48 +0000 Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5a9f4897-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:15 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:15 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:14 -0800 X-Inumbo-ID: 5a9f4897-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196315" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:44 -0800 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 07/20] x86/mem_sharing: don't try to unshare twice during page fault 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: Andrew Cooper , Tamas K Lengyel , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The page was already tried to be unshared in get_gfn_type_access. If that didn't work, then trying again is pointless. Don't try to send vm_event aga= in either, simply check if there is a ring or not. Signed-off-by: Tamas K Lengyel --- xen/arch/x86/hvm/hvm.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index e055114922..8f90841813 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -1706,11 +1707,14 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned= long gla, struct domain *currd =3D curr->domain; struct p2m_domain *p2m, *hostp2m; int rc, fall_through =3D 0, paged =3D 0; - int sharing_enomem =3D 0; vm_event_request_t *req_ptr =3D NULL; bool sync =3D false; unsigned int page_order; =20 +#ifdef CONFIG_MEM_SHARING + bool sharing_enomem =3D false; +#endif + /* On Nested Virtualization, walk the guest page table. * If this succeeds, all is fine. * If this fails, inject a nested page fault into the guest. @@ -1898,14 +1902,16 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned= long gla, if ( p2m_is_paged(p2mt) || (p2mt =3D=3D p2m_ram_paging_out) ) paged =3D 1; =20 - /* Mem sharing: unshare the page and try again */ - if ( npfec.write_access && (p2mt =3D=3D p2m_ram_shared) ) +#ifdef CONFIG_MEM_SHARING + /* Mem sharing: if still shared on write access then its enomem */ + if ( npfec.write_access && p2m_is_shared(p2mt) ) { ASSERT(p2m_is_hostp2m(p2m)); - sharing_enomem =3D mem_sharing_unshare_page(currd, gfn); + sharing_enomem =3D true; rc =3D 1; goto out_put_gfn; } +#endif =20 /* Spurious fault? PoD and log-dirty also take this path. */ if ( p2m_is_ram(p2mt) ) @@ -1959,19 +1965,21 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned= long gla, */ if ( paged ) p2m_mem_paging_populate(currd, gfn); + +#ifdef CONFIG_MEM_SHARING if ( sharing_enomem ) { - int rv; - - if ( (rv =3D mem_sharing_notify_enomem(currd, gfn, true)) < 0 ) + if ( !vm_event_check_ring(currd->vm_event_share) ) { gdprintk(XENLOG_ERR, "Domain %hu attempt to unshare " - "gfn %lx, ENOMEM and no helper (rc %d)\n", - currd->domain_id, gfn, rv); + "gfn %lx, ENOMEM and no helper\n", + currd->domain_id, gfn); /* Crash the domain */ rc =3D 0; } } +#endif + if ( req_ptr ) { if ( monitor_traps(curr, sync, req_ptr) < 0 ) --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698146; cv=none; d=zohomail.com; s=zohoarc; b=SCExZ2xSCdnqAjGhZ8fRjg6E0ajYeY5clEDSf92eP15RbcKpGEvlknP1vC+XkT/165YE2Eu5RasNHe7Wzdx0NRJdUezDjlMGYh2i6seqTKopn5LCPT03UzJ7hmVB/0a3cAH+kUSAbEdZ/7MVlT52ViW6wZSjQHP6bJEfNZHJ+80= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698146; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GDQeWfOioFf963kHqcZEQUoX3YIGnsrTh4DvPe66fpY=; b=LdZz3FgTT4Gdq3ws0o/+rirjLtQhwQK2nAUkXxvXgVBVGzU0RwPiWTYQXpyPG1M5PhXLfiCCBUAMUUqjB/CV7qV+9RMtZSBuOZfh5cNjwbhxAa/9UZWUQM96+eApGn+u8GOB53+MCob4RLYmlFgx4P6K9AT961hPZYj8ouj70WM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698146793375.03121183287476; Wed, 18 Dec 2019 11:42:26 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCk-0007yk-Lt; Wed, 18 Dec 2019 19:41:54 +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 1ihfCj-0007xS-87 for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:41:53 +0000 Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5b028b0e-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:16 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:16 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:15 -0800 X-Inumbo-ID: 5b028b0e-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196329" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:45 -0800 Message-Id: <11fd562f28132f950f4ed60e7a896b07da78f520.1576697796.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 08/20] x86/mem_sharing: define mem_sharing_domain to hold some scattered variables 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 , Tamas K Lengyel , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Create struct mem_sharing_domain under hvm_domain and move mem sharing variables into it from p2m_domain and hvm_domain. Expose the mem_sharing_enabled macro to be used consistently across Xen. Remove some duplicate calls to mem_sharing_enabled in mem_sharing.c Signed-off-by: Tamas K Lengyel --- xen/arch/x86/mm/mem_sharing.c | 30 +++++------------------------- xen/drivers/passthrough/pci.c | 3 +-- xen/include/asm-x86/hvm/domain.h | 6 +++++- xen/include/asm-x86/mem_sharing.h | 16 ++++++++++++++++ xen/include/asm-x86/p2m.h | 4 ---- 5 files changed, 27 insertions(+), 32 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index c0e305ad71..5d81730315 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -197,9 +197,6 @@ static inline shr_handle_t get_next_handle(void) return x + 1; } =20 -#define mem_sharing_enabled(d) \ - (is_hvm_domain(d) && (d)->arch.hvm.mem_sharing_enabled) - static atomic_t nr_saved_mfns =3D ATOMIC_INIT(0); static atomic_t nr_shared_mfns =3D ATOMIC_INIT(0); =20 @@ -1300,6 +1297,7 @@ int __mem_sharing_unshare_page(struct domain *d, int relinquish_shared_pages(struct domain *d) { int rc =3D 0; + struct mem_sharing_domain *msd =3D &d->arch.hvm.mem_sharing; struct p2m_domain *p2m =3D p2m_get_hostp2m(d); unsigned long gfn, count =3D 0; =20 @@ -1307,7 +1305,7 @@ int relinquish_shared_pages(struct domain *d) return 0; =20 p2m_lock(p2m); - for ( gfn =3D p2m->next_shared_gfn_to_relinquish; + for ( gfn =3D msd->next_shared_gfn_to_relinquish; gfn <=3D p2m->max_mapped_pfn; gfn++ ) { p2m_access_t a; @@ -1342,7 +1340,7 @@ int relinquish_shared_pages(struct domain *d) { if ( hypercall_preempt_check() ) { - p2m->next_shared_gfn_to_relinquish =3D gfn + 1; + msd->next_shared_gfn_to_relinquish =3D gfn + 1; rc =3D -ERESTART; break; } @@ -1428,7 +1426,7 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) =20 /* Only HAP is supported */ rc =3D -ENODEV; - if ( !hap_enabled(d) || !d->arch.hvm.mem_sharing_enabled ) + if ( !mem_sharing_enabled(d) ) goto out; =20 switch ( mso.op ) @@ -1437,10 +1435,6 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem= _sharing_op_t) arg) { shr_handle_t handle; =20 - rc =3D -EINVAL; - if ( !mem_sharing_enabled(d) ) - goto out; - rc =3D nominate_page(d, _gfn(mso.u.nominate.u.gfn), 0, &handle= ); mso.u.nominate.handle =3D handle; } @@ -1452,9 +1446,6 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) gfn_t gfn; shr_handle_t handle; =20 - rc =3D -EINVAL; - if ( !mem_sharing_enabled(d) ) - goto out; rc =3D mem_sharing_gref_to_gfn(d->grant_table, gref, &gfn, NUL= L); if ( rc < 0 ) goto out; @@ -1470,10 +1461,6 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem= _sharing_op_t) arg) struct domain *cd; shr_handle_t sh, ch; =20 - rc =3D -EINVAL; - if ( !mem_sharing_enabled(d) ) - goto out; - rc =3D rcu_lock_live_remote_domain_by_id(mso.u.share.client_do= main, &cd); if ( rc ) @@ -1540,10 +1527,6 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem= _sharing_op_t) arg) struct domain *cd; shr_handle_t sh; =20 - rc =3D -EINVAL; - if ( !mem_sharing_enabled(d) ) - goto out; - rc =3D rcu_lock_live_remote_domain_by_id(mso.u.share.client_do= main, &cd); if ( rc ) @@ -1602,9 +1585,6 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) mso.u.range.opaque > mso.u.range.last_gfn) ) goto out; =20 - if ( !mem_sharing_enabled(d) ) - goto out; - rc =3D rcu_lock_live_remote_domain_by_id(mso.u.range.client_do= main, &cd); if ( rc ) @@ -1708,7 +1688,7 @@ int mem_sharing_domctl(struct domain *d, struct xen_d= omctl_mem_sharing_op *mec) if ( unlikely(is_iommu_enabled(d) && mec->u.enable) ) rc =3D -EXDEV; else - d->arch.hvm.mem_sharing_enabled =3D mec->u.enable; + d->arch.hvm.mem_sharing.enabled =3D mec->u.enable; } break; =20 diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index c07a63981a..65d1d457ff 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1498,8 +1498,7 @@ static int assign_device(struct domain *d, u16 seg, u= 8 bus, u8 devfn, u32 flag) /* Prevent device assign if mem paging or mem sharing have been=20 * enabled for this domain */ if ( d !=3D dom_io && - unlikely((is_hvm_domain(d) && - d->arch.hvm.mem_sharing_enabled) || + unlikely(mem_sharing_enabled(d) || vm_event_check_ring(d->vm_event_paging) || p2m_get_hostp2m(d)->global_logdirty) ) return -EXDEV; diff --git a/xen/include/asm-x86/hvm/domain.h b/xen/include/asm-x86/hvm/dom= ain.h index bcc5621797..8f70ba2b1a 100644 --- a/xen/include/asm-x86/hvm/domain.h +++ b/xen/include/asm-x86/hvm/domain.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -156,7 +157,6 @@ struct hvm_domain { =20 struct viridian_domain *viridian; =20 - bool_t mem_sharing_enabled; bool_t qemu_mapcache_invalidate; bool_t is_s3_suspended; =20 @@ -192,6 +192,10 @@ struct hvm_domain { struct vmx_domain vmx; struct svm_domain svm; }; + +#ifdef CONFIG_MEM_SHARING + struct mem_sharing_domain mem_sharing; +#endif }; =20 #endif /* __ASM_X86_HVM_DOMAIN_H__ */ diff --git a/xen/include/asm-x86/mem_sharing.h b/xen/include/asm-x86/mem_sh= aring.h index 0a9192d0e2..89cdaccea0 100644 --- a/xen/include/asm-x86/mem_sharing.h +++ b/xen/include/asm-x86/mem_sharing.h @@ -26,6 +26,20 @@ =20 #ifdef CONFIG_MEM_SHARING =20 +struct mem_sharing_domain +{ + bool enabled; + + /* + * When releasing shared gfn's in a preemptible manner, recall where + * to resume the search. + */ + unsigned long next_shared_gfn_to_relinquish; +}; + +#define mem_sharing_enabled(d) \ + (hap_enabled(d) && (d)->arch.hvm.mem_sharing.enabled) + /* Auditing of memory sharing code? */ #ifndef NDEBUG #define MEM_SHARING_AUDIT 1 @@ -105,6 +119,8 @@ int relinquish_shared_pages(struct domain *d); =20 #else =20 +#define mem_sharing_enabled(d) false + static inline unsigned int mem_sharing_get_nr_saved_mfns(void) { return 0; diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 7399c4a897..8defa90306 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -305,10 +305,6 @@ struct p2m_domain { unsigned long min_remapped_gfn; unsigned long max_remapped_gfn; =20 - /* When releasing shared gfn's in a preemptible manner, recall where - * to resume the search */ - unsigned long next_shared_gfn_to_relinquish; - #ifdef CONFIG_HVM /* Populate-on-demand variables * All variables are protected with the pod lock. We cannot rely on --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698150; cv=none; d=zohomail.com; s=zohoarc; b=UE6fKUNXydNOhW1bJbhpKbnETgnEkhxYyYkeKJZ04hByJDyCtEbohF3Pg2Rs9n4QbU4pdawT43sOaaayGTDrYTEaZ/8GAH73tLaQGxB2yy+U7vBG3SsjDr4uJbTavq4qyNt5A7Jg3cd0dHElPEaO90ntQGNUM9O6YcJ33qiYrQU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698150; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=On8IfqpVeF61fsFd8w98JVasEx5XNhn14e0yYjy7PxQ=; b=V9jRLf0mYwCbAhmWWQVY+T1Y04Ab8XuBoiyWYUoYL5Ec1y8Z1R+L4HR/BzUTHbRv6pCCRN6pkS4+HipMAAztnhDsbsHFtbdY4rEEicUD3F+uVH12SCvSNk9sG5QSRA2Zt7Qr6dTjS39RmFflpf0QW9SMDdb0xU5jKMm7yUUetSk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698150244120.00834932150917; Wed, 18 Dec 2019 11:42:30 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCp-00083S-0w; Wed, 18 Dec 2019 19:41:59 +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 1ihfCo-00082V-7x for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:41:58 +0000 Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5b7ec746-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:17 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:16 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:16 -0800 X-Inumbo-ID: 5b7ec746-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196338" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:46 -0800 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 09/20] x86/mem_sharing: Use INVALID_MFN and p2m_is_shared in relinquish_shared_pages 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 , Tamas K Lengyel , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" While using _mfn(0) is of no consequence during teardown, INVALID_MFN is the correct value that should be used. Signed-off-by: Tamas K Lengyel --- xen/arch/x86/mm/mem_sharing.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index 5d81730315..1b7b520ccf 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1317,7 +1317,7 @@ int relinquish_shared_pages(struct domain *d) break; =20 mfn =3D p2m->get_entry(p2m, _gfn(gfn), &t, &a, 0, NULL, NULL); - if ( mfn_valid(mfn) && t =3D=3D p2m_ram_shared ) + if ( mfn_valid(mfn) && p2m_is_shared(t) ) { /* Does not fail with ENOMEM given the DESTROY flag */ BUG_ON(__mem_sharing_unshare_page(d, gfn, @@ -1327,7 +1327,7 @@ int relinquish_shared_pages(struct domain *d) * unshare. Must succeed: we just read the old entry and * we hold the p2m lock. */ - set_rc =3D p2m->set_entry(p2m, _gfn(gfn), _mfn(0), PAGE_ORDER_= 4K, + set_rc =3D p2m->set_entry(p2m, _gfn(gfn), INVALID_MFN, PAGE_OR= DER_4K, p2m_invalid, p2m_access_rwx, -1); ASSERT(!set_rc); count +=3D 0x10; --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698121; cv=none; d=zohomail.com; s=zohoarc; b=NRgrTL3SWZWGuZNkno90h+rumpO3xGK+aDExXADyvHIBQeYvKh5AjR96zqltjqelgKHKLCAvdzdvCpY1fz4yqdk2MTKNwwwNeX6v3LlBvx+qsKTi0rveS+YupHw5YiYRtxL08jkBGnGqacuTUL3rmZGuEvtQKvMsnl+NkZaS2N0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698121; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=p1yd2YBlmfXRd2etAGB55ZQcbzo2LMJWhVj26Z8MS68=; b=I00TSoeBEzVHJVUD3MH0hDM07uNbDPD8z7E652WcBGmGfMfkgAglZhf3qD218ske7k6d3gp7Fi5+RMSB04tt+9VYI6qmKNu9BapRNDvhCrzuQAjijjVvy1m/4svEV3t0aO38H3mz9HsIU6p0QRJVhqcG2PKlpx8u/MtHy4TiL9s= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698121835972.8696817088999; Wed, 18 Dec 2019 11:42:01 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCD-0007bu-56; Wed, 18 Dec 2019 19:41:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCC-0007bW-8C for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:41:20 +0000 Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5b82fe42-21ce-11ea-a1e1-bc764e2007e4; Wed, 18 Dec 2019 19:41:17 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:17 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:16 -0800 X-Inumbo-ID: 5b82fe42-21ce-11ea-a1e1-bc764e2007e4 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196344" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:47 -0800 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 10/20] x86/mem_sharing: Make add_to_physmap static and shorten name 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 , Tamas K Lengyel , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" It's not being called from outside mem_sharing.c Signed-off-by: Tamas K Lengyel --- xen/arch/x86/mm/mem_sharing.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index 1b7b520ccf..fc1d8be1eb 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1064,8 +1064,9 @@ err_out: return ret; } =20 -int mem_sharing_add_to_physmap(struct domain *sd, unsigned long sgfn, shr_= handle_t sh, - struct domain *cd, unsigned long cgfn, bool= lock) +static +int add_to_physmap(struct domain *sd, unsigned long sgfn, shr_handle_t sh, + struct domain *cd, unsigned long cgfn, bool lock) { struct page_info *spage; int ret =3D -EINVAL; @@ -1558,7 +1559,7 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) sh =3D mso.u.share.source_handle; cgfn =3D mso.u.share.client_gfn; =20 - rc =3D mem_sharing_add_to_physmap(d, sgfn, sh, cd, cgfn, true); + rc =3D add_to_physmap(d, sgfn, sh, cd, cgfn, true); =20 rcu_unlock_domain(cd); } --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698161; cv=none; d=zohomail.com; s=zohoarc; b=Q+qu6dgHra1b2yYVtYQ2JB1iBsOSlJ88IhTrT/+23/2dtDeKMLjsoPBllmLbegDsooBST9tHSXwCCb1nM7W/75cDxYB8osPu41h5MqrTo3KW/Dkz1UPF3+PJ+9cXOKOlnx+ppfuAkIxJU4Nb6G5KhkeIPkJ/SyTTcTpns1Rkevw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698161; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KIK3w/MOo7q7JVmLoDfx6ptOufhVgXH1VauA5PHdTnU=; b=IFpSUk2XLce1JpcG+rSuBR05+Gy83UrMI+HtETKkdg2KHdUR9avJPItdgnUz99KeNgmk79MmmpiuKeuGZs/GLguVefxQDlrSCax94R15zaZx4KQ/fayYJaoqVD/JeoSNp7RsgytKG2wu8J0VFJu7N9gag4XzTv+x7P1b76KXqPM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698161191425.20173425742803; Wed, 18 Dec 2019 11:42:41 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCu-00088r-BY; Wed, 18 Dec 2019 19:42:04 +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 1ihfCt-00087w-8p for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:42:03 +0000 Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5b7ec747-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:18 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:18 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:17 -0800 X-Inumbo-ID: 5b7ec747-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196349" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:48 -0800 Message-Id: <88408b9bf706a28d8879edef61606f39a9df68b2.1576697796.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 11/20] x86/mem_sharing: Convert MEM_SHARING_DESTROY_GFN to a bool 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 , Tamas K Lengyel , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Stefano Stabellini , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" MEM_SHARING_DESTROY_GFN is used on the 'flags' bitfield during unsharing. However, the bitfield is not used for anything else, so just convert it to a bool instead. Signed-off-by: Tamas K Lengyel --- xen/arch/x86/mm/mem_sharing.c | 7 +++---- xen/arch/x86/mm/p2m.c | 1 + xen/common/memory.c | 2 +- xen/include/asm-x86/mem_sharing.h | 5 ++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index fc1d8be1eb..6e81e1a895 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1175,7 +1175,7 @@ err_out: */ int __mem_sharing_unshare_page(struct domain *d, unsigned long gfn, - uint16_t flags) + bool destroy) { p2m_type_t p2mt; mfn_t mfn; @@ -1231,7 +1231,7 @@ int __mem_sharing_unshare_page(struct domain *d, * If the GFN is getting destroyed drop the references to MFN * (possibly freeing the page), and exit early. */ - if ( flags & MEM_SHARING_DESTROY_GFN ) + if ( destroy ) { if ( !last_gfn ) mem_sharing_gfn_destroy(page, d, gfn_info); @@ -1321,8 +1321,7 @@ int relinquish_shared_pages(struct domain *d) if ( mfn_valid(mfn) && p2m_is_shared(t) ) { /* Does not fail with ENOMEM given the DESTROY flag */ - BUG_ON(__mem_sharing_unshare_page(d, gfn, - MEM_SHARING_DESTROY_GFN)); + BUG_ON(__mem_sharing_unshare_page(d, gfn, true)); /* * Clear out the p2m entry so no one else may try to * unshare. Must succeed: we just read the old entry and diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index baea632acc..53ea44fe3c 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -517,6 +517,7 @@ mfn_t __get_gfn_type_access(struct p2m_domain *p2m, uns= igned long gfn_l, */ if ( mem_sharing_unshare_page(p2m->domain, gfn_l) < 0 ) mem_sharing_notify_enomem(p2m->domain, gfn_l, false); + mfn =3D p2m->get_entry(p2m, gfn, t, a, q, page_order, NULL); } =20 diff --git a/xen/common/memory.c b/xen/common/memory.c index 309e872edf..c7d2bac452 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -352,7 +352,7 @@ int guest_remove_page(struct domain *d, unsigned long g= mfn) * might be the only one using this shared page, and we need to * trigger proper cleanup. Once done, this is like any other page. */ - rc =3D mem_sharing_unshare_page(d, gmfn, 0); + rc =3D mem_sharing_unshare_page(d, gmfn); if ( rc ) { mem_sharing_notify_enomem(d, gmfn, false); diff --git a/xen/include/asm-x86/mem_sharing.h b/xen/include/asm-x86/mem_sh= aring.h index 89cdaccea0..4b982a4803 100644 --- a/xen/include/asm-x86/mem_sharing.h +++ b/xen/include/asm-x86/mem_sharing.h @@ -76,17 +76,16 @@ struct page_sharing_info unsigned int mem_sharing_get_nr_saved_mfns(void); unsigned int mem_sharing_get_nr_shared_mfns(void); =20 -#define MEM_SHARING_DESTROY_GFN (1<<1) /* Only fails with -ENOMEM. Enforce it with a BUG_ON wrapper. */ int __mem_sharing_unshare_page(struct domain *d, unsigned long gfn, - uint16_t flags); + bool destroy); =20 static inline int mem_sharing_unshare_page(struct domain *d, unsigned long gfn) { - int rc =3D __mem_sharing_unshare_page(d, gfn, 0); + int rc =3D __mem_sharing_unshare_page(d, gfn, false); BUG_ON(rc && (rc !=3D -ENOMEM)); return rc; } --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698154; cv=none; d=zohomail.com; s=zohoarc; b=mP+3vFoTHakdr+twLsYILAO6hWchwWYbrbLePZWS5gesD7ra8yN0souFWNGskv23qQlL9SynCCE6O9PZQhSk7ELyrZK6ClI1u90LGMJpC4iI+dITPyKCtIyjNl8FS0IGQ+Omu9scAYs95yi0KQ+lICRm9uw6mfgonOG4iemWfyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698154; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+dDkia/i76+3BTWQgyXPswss5Hni0OccKwgCNPGig7k=; b=VrOoVkq+DONQwWm5wK5lA5Fw/BSchGbMpEfF5joJ8RLb+tyWHiHO1SXFxiMuLjCL6jbLv3azW/HIc8SctGDbcuAsZoUTXaNrKLJf/REldIX/mnZHjrceEGDnIY73i+XekVV4i0O7QWJZsAi3QJAmOJ4rp2L3gKFeMLi5ZQVzq/I= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698154474242.213271396629; Wed, 18 Dec 2019 11:42:34 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCz-0008DL-P1; Wed, 18 Dec 2019 19:42:09 +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 1ihfCy-0008C9-8c for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:42:08 +0000 Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5d0e22a0-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:19 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:19 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:18 -0800 X-Inumbo-ID: 5d0e22a0-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196354" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:49 -0800 Message-Id: <54a89539673507106ae6fcde866f813bd5e95d5f.1576697796.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 12/20] x86/mem_sharing: Replace MEM_SHARING_DEBUG with gdprintk 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 , Tamas K Lengyel , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Using XENLOG_ERR level since this is only used in debug paths (ie. it's expected the user already has loglvl=3Dall set). Signed-off-by: Tamas K Lengyel --- xen/arch/x86/mm/mem_sharing.c | 81 ++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index 6e81e1a895..90b6371e2f 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -49,9 +49,6 @@ typedef struct pg_lock_data { =20 static DEFINE_PER_CPU(pg_lock_data_t, __pld); =20 -#define MEM_SHARING_DEBUG(_f, _a...) \ - debugtrace_printk("mem_sharing_debug: %s(): " _f, __func__, ##_a) - /* Reverse map defines */ #define RMAP_HASHTAB_ORDER 0 #define RMAP_HASHTAB_SIZE \ @@ -491,8 +488,9 @@ static int audit(void) /* If we can't lock it, it's definitely not a shared page */ if ( !mem_sharing_page_lock(pg) ) { - MEM_SHARING_DEBUG("mfn %lx in audit list, but cannot be locked = (%lx)!\n", - mfn_x(mfn), pg->u.inuse.type_info); + gdprintk(XENLOG_ERR, + "mfn %lx in audit list, but cannot be locked (%lx)!\n", + mfn_x(mfn), pg->u.inuse.type_info); errors++; continue; } @@ -500,8 +498,9 @@ static int audit(void) /* Check if the MFN has correct type, owner and handle. */ if ( (pg->u.inuse.type_info & PGT_type_mask) !=3D PGT_shared_page ) { - MEM_SHARING_DEBUG("mfn %lx in audit list, but not PGT_shared_pa= ge (%lx)!\n", - mfn_x(mfn), pg->u.inuse.type_info & PGT_type= _mask); + gdprintk(XENLOG_ERR, + "mfn %lx in audit list, but not PGT_shared_page (%lx)!= \n", + mfn_x(mfn), pg->u.inuse.type_info & PGT_type_mask); errors++; continue; } @@ -509,24 +508,24 @@ static int audit(void) /* Check the page owner. */ if ( page_get_owner(pg) !=3D dom_cow ) { - MEM_SHARING_DEBUG("mfn %lx shared, but wrong owner (%hu)!\n", - mfn_x(mfn), page_get_owner(pg)->domain_id); + gdprintk(XENLOG_ERR, "mfn %lx shared, but wrong owner (%hu)!\n", + mfn_x(mfn), page_get_owner(pg)->domain_id); errors++; } =20 /* Check the m2p entry */ if ( !SHARED_M2P(get_gpfn_from_mfn(mfn_x(mfn))) ) { - MEM_SHARING_DEBUG("mfn %lx shared, but wrong m2p entry (%lx)!\n= ", - mfn_x(mfn), get_gpfn_from_mfn(mfn_x(mfn))); + gdprintk(XENLOG_ERR, "mfn %lx shared, but wrong m2p entry (%lx)= !\n", + mfn_x(mfn), get_gpfn_from_mfn(mfn_x(mfn))); errors++; } =20 /* Check we have a list */ if ( (!pg->sharing) || !rmap_has_entries(pg) ) { - MEM_SHARING_DEBUG("mfn %lx shared, but empty gfn list!\n", - mfn_x(mfn)); + gdprintk(XENLOG_ERR, "mfn %lx shared, but empty gfn list!\n", + mfn_x(mfn)); errors++; continue; } @@ -545,24 +544,26 @@ static int audit(void) d =3D get_domain_by_id(g->domain); if ( d =3D=3D NULL ) { - MEM_SHARING_DEBUG("Unknown dom: %hu, for PFN=3D%lx, MFN=3D= %lx\n", - g->domain, g->gfn, mfn_x(mfn)); + gdprintk(XENLOG_ERR, + "Unknown dom: %hu, for PFN=3D%lx, MFN=3D%lx\n", + g->domain, g->gfn, mfn_x(mfn)); errors++; continue; } o_mfn =3D get_gfn_query_unlocked(d, g->gfn, &t); if ( !mfn_eq(o_mfn, mfn) ) { - MEM_SHARING_DEBUG("Incorrect P2M for d=3D%hu, PFN=3D%lx." - "Expecting MFN=3D%lx, got %lx\n", - g->domain, g->gfn, mfn_x(mfn), mfn_x(o_m= fn)); + gdprintk(XENLOG_ERR, "Incorrect P2M for d=3D%hu, PFN=3D%lx= ." + "Expecting MFN=3D%lx, got %lx\n", + g->domain, g->gfn, mfn_x(mfn), mfn_x(o_mfn)); errors++; } if ( t !=3D p2m_ram_shared ) { - MEM_SHARING_DEBUG("Incorrect P2M type for d=3D%hu, PFN=3D%= lx MFN=3D%lx." - "Expecting t=3D%d, got %d\n", - g->domain, g->gfn, mfn_x(mfn), p2m_ram_s= hared, t); + gdprintk(XENLOG_ERR, + "Incorrect P2M type for d=3D%hu, PFN=3D%lx MFN=3D= %lx." + "Expecting t=3D%d, got %d\n", + g->domain, g->gfn, mfn_x(mfn), p2m_ram_shared, t); errors++; } put_domain(d); @@ -571,10 +572,10 @@ static int audit(void) /* The type count has an extra ref because we have locked the page= */ if ( (nr_gfns + 1) !=3D (pg->u.inuse.type_info & PGT_count_mask) ) { - MEM_SHARING_DEBUG("Mismatched counts for MFN=3D%lx." - "nr_gfns in list %lu, in type_info %lx\n", - mfn_x(mfn), nr_gfns, - (pg->u.inuse.type_info & PGT_count_mask)); + gdprintk(XENLOG_ERR, "Mismatched counts for MFN=3D%lx." + "nr_gfns in list %lu, in type_info %lx\n", + mfn_x(mfn), nr_gfns, + (pg->u.inuse.type_info & PGT_count_mask)); errors++; } =20 @@ -585,8 +586,8 @@ static int audit(void) =20 if ( count_found !=3D count_expected ) { - MEM_SHARING_DEBUG("Expected %ld shared mfns, found %ld.", - count_expected, count_found); + gdprintk(XENLOG_ERR, "Expected %ld shared mfns, found %ld.", + count_expected, count_found); errors++; } =20 @@ -765,12 +766,12 @@ static int debug_mfn(mfn_t mfn) return -EINVAL; } =20 - MEM_SHARING_DEBUG( - "Debug page: MFN=3D%lx is ci=3D%lx, ti=3D%lx, owner_id=3D%d\n", - mfn_x(page_to_mfn(page)), - page->count_info, - page->u.inuse.type_info, - page_get_owner(page)->domain_id); + gdprintk(XENLOG_ERR, + "Debug page: MFN=3D%lx is ci=3D%lx, ti=3D%lx, owner_id=3D%d\n= ", + mfn_x(page_to_mfn(page)), + page->count_info, + page->u.inuse.type_info, + page_get_owner(page)->domain_id); =20 /* -1 because the page is locked and that's an additional type ref */ num_refs =3D ((int) (page->u.inuse.type_info & PGT_count_mask)) - 1; @@ -786,8 +787,9 @@ static int debug_gfn(struct domain *d, gfn_t gfn) =20 mfn =3D get_gfn_query(d, gfn_x(gfn), &p2mt); =20 - MEM_SHARING_DEBUG("Debug for dom%d, gfn=3D%" PRI_gfn "\n", - d->domain_id, gfn_x(gfn)); + gdprintk(XENLOG_ERR, "Debug for dom%d, gfn=3D%" PRI_gfn "\n", + d->domain_id, gfn_x(gfn)); + num_refs =3D debug_mfn(mfn); put_gfn(d, gfn_x(gfn)); =20 @@ -803,14 +805,13 @@ static int debug_gref(struct domain *d, grant_ref_t r= ef) rc =3D mem_sharing_gref_to_gfn(d->grant_table, ref, &gfn, &status); if ( rc ) { - MEM_SHARING_DEBUG("Asked to debug [dom=3D%d,gref=3D%u]: error %d.\= n", - d->domain_id, ref, rc); + gdprintk(XENLOG_ERR, "Asked to debug [dom=3D%d,gref=3D%u]: error %= d.\n", + d->domain_id, ref, rc); return rc; } =20 - MEM_SHARING_DEBUG( - "=3D=3D> Grant [dom=3D%d,ref=3D%d], status=3D%x. ", - d->domain_id, ref, status); + gdprintk(XENLOG_ERR, " =3D=3D> Grant [dom=3D%d,ref=3D%d], status=3D%x.= ", + d->domain_id, ref, status); =20 return debug_gfn(d, gfn); } --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698163; cv=none; d=zohomail.com; s=zohoarc; b=BcEdbX9aOXILa7gaQxfDoQBm6tpcj6L7yLqTgFDN6jSIM5YIQcbfNgXRINb5h4z6+T/lGaQH4AsDXSEB0izHYaPSjjxyXr+qkyvP/QWP5UhiznuheT34X0UiVvGofrn3nNfvIWkbL3d2HfoZEnlzePTl2S+fBh3ymu+MBxygNrA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698163; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4FkgkO39NPPpvcM1vF2K0VnQL7/kG3HjcIg078JMhpk=; b=XiEYMvs8KENzf1ZRrWC7/Vbku4U/Flsx0ZNl5+XCAk96VA8sRnIO8HuYd3OIEh5KlQGK69Keobv3oDNP/ghdiGEnzOKByBboCdPOdEfuBdER100D67GMNeYTuzxP9B3M0iDYg2fANTfUZF5nXo9wA5BwNBjVptKfzRgZHSwz/nM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698163221703.8623446342165; Wed, 18 Dec 2019 11:42:43 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfD4-0008IN-BE; Wed, 18 Dec 2019 19:42:14 +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 1ihfD3-0008HI-8Y for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:42:13 +0000 Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5d0e22a1-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:20 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:20 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:19 -0800 X-Inumbo-ID: 5d0e22a1-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196365" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:50 -0800 Message-Id: <8c8e88a464770b9eceab3d70340c7390ff5bd0b3.1576697796.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 13/20] x86/mem_sharing: ASSERT that p2m_set_entry succeeds 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 , Tamas K Lengyel , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Signed-off-by: Tamas K Lengyel --- xen/arch/x86/mm/mem_sharing.c | 46 +++++++++++++++++------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index 90b6371e2f..e5c1424f9b 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1113,39 +1113,37 @@ int add_to_physmap(struct domain *sd, unsigned long= sgfn, shr_handle_t sh, goto err_unlock; } =20 + /* + * Must succeed, we just read the entry and hold the p2m lock + * via get_two_gfns. + */ ret =3D p2m_set_entry(p2m, _gfn(cgfn), smfn, PAGE_ORDER_4K, p2m_ram_shared, a); + ASSERT(!ret); =20 - /* Tempted to turn this into an assert */ - if ( ret ) + /* + * There is a chance we're plugging a hole where a paged out + * page was. + */ + if ( p2m_is_paging(cmfn_type) && (cmfn_type !=3D p2m_ram_paging_out) ) { - mem_sharing_gfn_destroy(spage, cd, gfn_info); - put_page_and_type(spage); - } else { + atomic_dec(&cd->paged_pages); /* - * There is a chance we're plugging a hole where a paged out - * page was. + * Further, there is a chance this was a valid page. + * Don't leak it. */ - if ( p2m_is_paging(cmfn_type) && (cmfn_type !=3D p2m_ram_paging_ou= t) ) + if ( mfn_valid(cmfn) ) { - atomic_dec(&cd->paged_pages); - /* - * Further, there is a chance this was a valid page. - * Don't leak it. - */ - if ( mfn_valid(cmfn) ) - { - struct page_info *cpage =3D mfn_to_page(cmfn); + struct page_info *cpage =3D mfn_to_page(cmfn); =20 - if ( !get_page(cpage, cd) ) - { - domain_crash(cd); - ret =3D -EOVERFLOW; - goto err_unlock; - } - put_page_alloc_ref(cpage); - put_page(cpage); + if ( !get_page(cpage, cd) ) + { + domain_crash(cd); + ret =3D -EOVERFLOW; + goto err_unlock; } + put_page_alloc_ref(cpage); + put_page(cpage); } } =20 --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698159; cv=none; d=zohomail.com; s=zohoarc; b=WdU84rC3Pb0kGp043a5Vz/gf3J5SvACtektA5AnyCNwXW51MUBzi5BMnfMoP3kdyPKeg6PrbY2QFHLfFX1C4KLg2nfqACDhVDP9Bl1dYm/4gAzsFknjhuYwbDRdatxI5yN9OkVh7HeufRHaz7s0xHUlc5HtUFlxegYR4rh/msvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698159; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qhW5BamtF2O43fN5YkdpQIIjjOW4tLZPms8tiSABy64=; b=NZij/eA3ggrfslid97sdT3++tbiP0Cndt5IGEU5oDMSDDFeLP+sv5rajU8PGaE2Bi1GN+YEiibDz1uIIE6AvjJ2MfPIEx6NIsgnKUnrtAiVBWjxCTK+n5wKQSbstyl7h0anslxMZ9d5Hk5upEpgJj6Wo4ja8h2jrwsK1Z+Zu4CE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698159893455.2239247797986; Wed, 18 Dec 2019 11:42:39 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfD9-0008NX-NK; Wed, 18 Dec 2019 19:42:19 +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 1ihfD8-0008MH-8a for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:42:18 +0000 Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5dec2f46-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:21 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:21 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:20 -0800 X-Inumbo-ID: 5dec2f46-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196369" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:51 -0800 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 14/20] x86/mem_sharing: Enable mem_sharing on first memop 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 , Tamas K Lengyel , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" It is wasteful to require separate hypercalls to enable sharing on both the parent and the client domain during VM forking. To speed things up we enable sharing on the first memop in case it wasn't already enabled. Signed-off-by: Tamas K Lengyel --- xen/arch/x86/mm/mem_sharing.c | 39 +++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index e5c1424f9b..48809a5349 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1402,6 +1402,24 @@ static int range_share(struct domain *d, struct doma= in *cd, return rc; } =20 +static inline int mem_sharing_control(struct domain *d, bool enable) +{ + if ( enable ) + { + if ( unlikely(!is_hvm_domain(d)) ) + return -ENOSYS; + + if ( unlikely(!hap_enabled(d)) ) + return -ENODEV; + + if ( unlikely(is_iommu_enabled(d)) ) + return -EXDEV; + } + + d->arch.hvm.mem_sharing.enabled =3D enable; + return 0; +} + int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) { int rc; @@ -1423,10 +1441,8 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem= _sharing_op_t) arg) if ( rc ) goto out; =20 - /* Only HAP is supported */ - rc =3D -ENODEV; - if ( !mem_sharing_enabled(d) ) - goto out; + if ( !mem_sharing_enabled(d) && (rc =3D mem_sharing_control(d, true)) ) + return rc; =20 switch ( mso.op ) { @@ -1675,24 +1691,15 @@ int mem_sharing_domctl(struct domain *d, struct xen= _domctl_mem_sharing_op *mec) { int rc; =20 - /* Only HAP is supported */ - if ( !hap_enabled(d) ) - return -ENODEV; - switch(mec->op) { case XEN_DOMCTL_MEM_SHARING_CONTROL: - { - rc =3D 0; - if ( unlikely(is_iommu_enabled(d) && mec->u.enable) ) - rc =3D -EXDEV; - else - d->arch.hvm.mem_sharing.enabled =3D mec->u.enable; - } - break; + rc =3D mem_sharing_control(d, mec->u.enable); + break; =20 default: rc =3D -ENOSYS; + break; } =20 return rc; --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698163; cv=none; d=zohomail.com; s=zohoarc; b=PPxipct9yLQ0j1RF8HmBjzaQqCzKS3g7rDUj+JEWyEhzEs/MuXjVcWVg6lXUrNDUkKttkpl4zq+jSB/GhVQDKiBJQxVPBw0Z7vEnHJ8BEP6xkFM1MxgVyfHUQcWZuL0YmBtgSJ/79/El8eb6N1a5ZmoB+tefH5vPq8S/2PoYiKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698163; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lQ4MxvdQEJu2vtBfid9kvo3aIis7h5Hab1VXbXT5cyc=; b=a8sV9eDmax+wHRi4VwYm82xQvEHd5lf1yJXbH6ODWXPwwBCy1ZtSGS71+acshihJc2zy/F5sEnyV45tzqzm+GOcIvSotJgDS9U2fm33/IquhxA08IYbtQ1k6aSGXYV98yjyQT14QLhw9UTdtM3Qq8DtIH1F+W4tkDX/zjWz6LQk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698163606170.68846599169945; Wed, 18 Dec 2019 11:42:43 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfDE-0008Sa-5G; Wed, 18 Dec 2019 19:42:24 +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 1ihfDD-0008RX-8W for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:42:23 +0000 Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5dec2f47-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:22 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:22 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:21 -0800 X-Inumbo-ID: 5dec2f47-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196377" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:52 -0800 Message-Id: <8c87a638cf6da36b7f419b2054c29f6e1e251470.1576697796.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 15/20] x86/mem_sharing: Skip xen heap pages in memshr nominate 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 , Tamas K Lengyel , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Trying to share these would fail anyway, better to skip them early. Signed-off-by: Tamas K Lengyel --- xen/arch/x86/mm/mem_sharing.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index 48809a5349..b3607b1bce 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -852,6 +852,11 @@ static int nominate_page(struct domain *d, gfn_t gfn, if ( !p2m_is_sharable(p2mt) ) goto out; =20 + /* Skip xen heap pages */ + page =3D mfn_to_page(mfn); + if ( !page || is_xen_heap_page(page) ) + goto out; + /* Check if there are mem_access/remapped altp2m entries for this page= */ if ( altp2m_active(d) ) { @@ -882,7 +887,6 @@ static int nominate_page(struct domain *d, gfn_t gfn, } =20 /* Try to convert the mfn to the sharable type */ - page =3D mfn_to_page(mfn); ret =3D page_make_sharable(d, page, expected_refcnt); if ( ret ) goto out; --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698131; cv=none; d=zohomail.com; s=zohoarc; b=Di81pzsduhLpKHmbLcGSrhXHyy34R9iFIOCzx2JoNuHeclO21Yj8Hya/uR10HOSk9sArpDxtXtd2bf4i/kkydNQOyPPYsSNUKVFsTKZYFaBqtlSWJFmlQkb46+PkaLLWCuqtWdjmcb8PFBabLjNlFYDF4oG10FVr9LjVujKntRw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698131; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jYJpvHtI4l1esvCbi74MVNoERqbYamHQ3FVAcogeeLo=; b=XdCG0N8oGMU7Eliz7kLJvXjr0iBADAeZ3clyZE73cvhsm+G/JkHzKAOIXhbbj4UVq5XufJl1rjqHH+dgWfZcTcLtCISAAF6lhN7ikW8mcp9+HJZNBje6BJtMmI7SCriJAlNnQhCrukrVPSzKTDhGxifs8XM/XPwjP9O0687HnaM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698130721240.27217778696365; Wed, 18 Dec 2019 11:42:10 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCV-0007kP-WF; Wed, 18 Dec 2019 19:41:39 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCU-0007jU-Gu for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:41:38 +0000 Received: from mga04.intel.com (unknown [192.55.52.120]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6245ac20-21ce-11ea-b6f1-bc764e2007e4; Wed, 18 Dec 2019 19:41:28 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:27 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:22 -0800 X-Inumbo-ID: 6245ac20-21ce-11ea-b6f1-bc764e2007e4 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196399" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:53 -0800 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 16/20] x86/mem_sharing: check page type count earlier 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 , Tamas K Lengyel , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Signed-off-by: Tamas K Lengyel --- xen/arch/x86/mm/mem_sharing.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index b3607b1bce..c44e7f2299 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -649,19 +649,18 @@ static int page_make_sharable(struct domain *d, return -EBUSY; } =20 - /* Change page type and count atomically */ - if ( !get_page_and_type(page, d, PGT_shared_page) ) + /* Check if page is already typed and bail early if it is */ + if ( (page->u.inuse.type_info & PGT_count_mask) !=3D 1 ) { spin_unlock(&d->page_alloc_lock); - return -EINVAL; + return -EEXIST; } =20 - /* Check it wasn't already sharable and undo if it was */ - if ( (page->u.inuse.type_info & PGT_count_mask) !=3D 1 ) + /* Change page type and count atomically */ + if ( !get_page_and_type(page, d, PGT_shared_page) ) { spin_unlock(&d->page_alloc_lock); - put_page_and_type(page); - return -EEXIST; + return -EINVAL; } =20 /* --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698136; cv=none; d=zohomail.com; s=zohoarc; b=hfjfLTVquJikgSGuGHW4f71iyyg8qkIeem0D+V2yrHLFSxyiMPEQLyNWlHXWHkrFs9c9t9UcMRi4kRiOGqBvVR4HOAfXhTzJW4ooS720GGe8PdNaCmpR5wQJhzPa9XzzpG/7xuPwZwZKw62lDhjDCvgruuLoIJzlODVn7hlO4HE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698136; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IxitH+KbPLKo0ihSarCW8AurIjOTbPESPN708D9bANw=; b=ExOexM5yJYpaszv6ndDZmT87ZA5XDQ07+YzU6MG2L1J5j+kjZQ0sBqmnpE0wsSFZ8sOvX4RoaHqu9YIUgWPd+CIVFpVXQJf4HAu0TOsx9BqvCUar5cT+mYbVZXHEScmXvWzHONmxtubMC5I6/FF2i9sdYbA2SVFsdMHiofzcl90= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698136362619.2912689245593; Wed, 18 Dec 2019 11:42:16 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCa-0007oC-LP; Wed, 18 Dec 2019 19:41:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCZ-0007nC-HJ for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:41:43 +0000 Received: from mga04.intel.com (unknown [192.55.52.120]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 62df30ca-21ce-11ea-b6f1-bc764e2007e4; Wed, 18 Dec 2019 19:41:29 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:29 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:27 -0800 X-Inumbo-ID: 62df30ca-21ce-11ea-b6f1-bc764e2007e4 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196408" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:54 -0800 Message-Id: <62ea55ed1aff2cea6e31c1da4ecd92981aff28d2.1576697796.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 17/20] xen/mem_sharing: VM forking 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: Stefano Stabellini , Tamas K Lengyel , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tamas K Lengyel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" VM forking is the process of creating a domain with an empty memory space a= nd a parent domain specified from which to populate the memory when necessary. F= or the new domain to be functional the VM state is copied over as part of the = fork operation (HVM params, hap allocation, etc). Signed-off-by: Tamas K Lengyel --- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/mm/mem_sharing.c | 228 ++++++++++++++++++++++++++++++ xen/arch/x86/mm/p2m.c | 11 +- xen/include/asm-x86/mem_sharing.h | 20 ++- xen/include/public/memory.h | 5 + xen/include/xen/sched.h | 1 + 6 files changed, 263 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 8f90841813..cafd07c67d 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1913,7 +1913,7 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned l= ong gla, } #endif =20 - /* Spurious fault? PoD and log-dirty also take this path. */ + /* Spurious fault? PoD, log-dirty and VM forking also take this path. = */ if ( p2m_is_ram(p2mt) ) { rc =3D 1; diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index c44e7f2299..e93ad2ec5a 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -22,11 +22,13 @@ =20 #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -36,6 +38,9 @@ #include #include #include +#include +#include +#include #include =20 #include "mm-locks.h" @@ -1423,6 +1428,200 @@ static inline int mem_sharing_control(struct domain= *d, bool enable) return 0; } =20 +/* + * Forking a page only gets called when the VM faults due to no entry being + * in the EPT for the access. Depending on the type of access we either + * populate the physmap with a shared entry for read-only access or + * fork the page if its a write access. + * + * The client p2m is already locked so we only need to lock + * the parent's here. + */ +int mem_sharing_fork_page(struct domain *d, gfn_t gfn, bool unsharing) +{ + int rc =3D -ENOENT; + shr_handle_t handle; + struct domain *parent; + struct p2m_domain *p2m; + unsigned long gfn_l =3D gfn_x(gfn); + mfn_t mfn, new_mfn; + p2m_type_t p2mt; + struct page_info *page; + + if ( !mem_sharing_is_fork(d) ) + return -ENOENT; + + parent =3D d->parent; + + if ( !unsharing ) + { + /* For read-only accesses we just add a shared entry to the physma= p */ + while ( parent ) + { + if ( !(rc =3D nominate_page(parent, gfn, 0, &handle)) ) + break; + + parent =3D parent->parent; + } + + if ( !rc ) + { + /* The client's p2m is already locked */ + struct p2m_domain *pp2m =3D p2m_get_hostp2m(parent); + + p2m_lock(pp2m); + rc =3D add_to_physmap(parent, gfn_l, handle, d, gfn_l, false); + p2m_unlock(pp2m); + + if ( !rc ) + return 0; + } + } + + /* + * If it's a write access (ie. unsharing) or if adding a shared entry = to + * the physmap failed we'll fork the page directly. + */ + p2m =3D p2m_get_hostp2m(d); + parent =3D d->parent; + + while ( parent ) + { + mfn =3D get_gfn_query(parent, gfn_l, &p2mt); + + if ( mfn_valid(mfn) && p2m_is_any_ram(p2mt) ) + break; + + put_gfn(parent, gfn_l); + parent =3D parent->parent; + } + + if ( !parent ) + return -ENOENT; + + if ( !(page =3D alloc_domheap_page(d, 0)) ) + { + put_gfn(parent, gfn_l); + return -ENOMEM; + } + + new_mfn =3D page_to_mfn(page); + copy_domain_page(new_mfn, mfn); + set_gpfn_from_mfn(mfn_x(new_mfn), gfn_l); + + put_gfn(parent, gfn_l); + + return p2m->set_entry(p2m, gfn, new_mfn, PAGE_ORDER_4K, p2m_ram_rw, + p2m->default_access, -1); +} + +static int bring_up_vcpus(struct domain *cd, struct cpupool *cpupool) +{ + int ret; + unsigned int i; + + if ( (ret =3D cpupool_move_domain(cd, cpupool)) ) + return ret; + + for ( i =3D 0; i < cd->max_vcpus; i++ ) + { + if ( cd->vcpu[i] ) + continue; + + if ( !vcpu_create(cd, i) ) + return -EINVAL; + } + + domain_update_node_affinity(cd); + return 0; +} + +static int fork_hap_allocation(struct domain *d, struct domain *cd) +{ + int rc; + bool preempted; + unsigned long mb =3D hap_get_allocation(d); + + if ( mb =3D=3D hap_get_allocation(cd) ) + return 0; + + paging_lock(cd); + rc =3D hap_set_allocation(cd, mb << (20 - PAGE_SHIFT), &preempted); + paging_unlock(cd); + + if ( rc ) + return rc; + + if ( preempted ) + return -ERESTART; + + return 0; +} + +static int fork_hvm(struct domain *d, struct domain *cd) +{ + int rc, i; + struct hvm_domain_context c =3D { 0 }; + uint32_t tsc_mode; + uint32_t gtsc_khz; + uint32_t incarnation; + uint64_t elapsed_nsec; + + c.size =3D hvm_save_size(d); + if ( (c.data =3D xmalloc_bytes(c.size)) =3D=3D NULL ) + return -ENOMEM; + + for ( i =3D 0; i < HVM_NR_PARAMS; i++ ) + { + uint64_t value =3D 0; + + if ( hvm_get_param(d, i, &value) || !value ) + continue; + + if ( (rc =3D hvm_set_param(cd, i, value)) ) + goto out; + } + + tsc_get_info(d, &tsc_mode, &elapsed_nsec, >sc_khz, &incarnation); + tsc_set_info(cd, tsc_mode, elapsed_nsec, gtsc_khz, incarnation); + + if ( (rc =3D hvm_save(d, &c)) ) + goto out; + + c.cur =3D 0; + rc =3D hvm_load(cd, &c); + +out: + xfree(c.data); + return rc; +} + +static int mem_sharing_fork(struct domain *d, struct domain *cd) +{ + int rc; + + if ( !d->controller_pause_count && + (rc =3D domain_pause_by_systemcontroller(d)) ) + return rc; + + cd->max_pages =3D d->max_pages; + cd->max_vcpus =3D d->max_vcpus; + + /* this is preemptible so it's the first to get done */ + if ( (rc =3D fork_hap_allocation(d, cd)) ) + return rc; + + if ( (rc =3D bring_up_vcpus(cd, d->cpupool)) ) + return rc; + + if ( (rc =3D fork_hvm(d, cd)) ) + return rc; + + cd->parent =3D d; + + return 0; +} + int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) { int rc; @@ -1677,6 +1876,35 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem= _sharing_op_t) arg) rc =3D debug_gref(d, mso.u.debug.u.gref); break; =20 + case XENMEM_sharing_op_fork: + { + struct domain *pd; + + rc =3D -EINVAL; + if ( mso.u.fork._pad[0] || mso.u.fork._pad[1] || + mso.u.fork._pad[2] ) + goto out; + + rc =3D rcu_lock_live_remote_domain_by_id(mso.u.fork.parent_dom= ain, + &pd); + if ( rc ) + goto out; + + if ( !mem_sharing_enabled(pd) ) + { + if ( (rc =3D mem_sharing_control(pd, true)) ) + goto out; + } + + rc =3D mem_sharing_fork(pd, d); + + if ( rc =3D=3D -ERESTART ) + rc =3D hypercall_create_continuation(__HYPERVISOR_memory_o= p, + "lh", XENMEM_sharing_op, + arg); + rcu_unlock_domain(pd); + break; + } default: rc =3D -ENOSYS; break; diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 53ea44fe3c..55c260731e 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -508,6 +508,14 @@ mfn_t __get_gfn_type_access(struct p2m_domain *p2m, un= signed long gfn_l, =20 mfn =3D p2m->get_entry(p2m, gfn, t, a, q, page_order, NULL); =20 + /* Check if we need to fork the page */ + if ( (q & P2M_ALLOC) && p2m_is_hole(*t) && + !mem_sharing_fork_page(p2m->domain, gfn, !!(q & P2M_UNSHARE)) ) + { + mfn =3D p2m->get_entry(p2m, gfn, t, a, q, page_order, NULL); + } + + /* Check if we need to unshare the page */ if ( (q & P2M_UNSHARE) && p2m_is_shared(*t) ) { ASSERT(p2m_is_hostp2m(p2m)); @@ -586,7 +594,8 @@ struct page_info *p2m_get_page_from_gfn( return page; =20 /* Error path: not a suitable GFN at all */ - if ( !p2m_is_ram(*t) && !p2m_is_paging(*t) && !p2m_is_pod(*t) ) + if ( !p2m_is_ram(*t) && !p2m_is_paging(*t) && !p2m_is_pod(*t) && + !mem_sharing_is_fork(p2m->domain) ) return NULL; } =20 diff --git a/xen/include/asm-x86/mem_sharing.h b/xen/include/asm-x86/mem_sh= aring.h index 4b982a4803..f80d3acdeb 100644 --- a/xen/include/asm-x86/mem_sharing.h +++ b/xen/include/asm-x86/mem_sharing.h @@ -26,8 +26,7 @@ =20 #ifdef CONFIG_MEM_SHARING =20 -struct mem_sharing_domain -{ +struct mem_sharing_domain { bool enabled; =20 /* @@ -40,6 +39,9 @@ struct mem_sharing_domain #define mem_sharing_enabled(d) \ (hap_enabled(d) && (d)->arch.hvm.mem_sharing.enabled) =20 +#define mem_sharing_is_fork(d) \ + (mem_sharing_enabled(d) && !!((d)->parent)) + /* Auditing of memory sharing code? */ #ifndef NDEBUG #define MEM_SHARING_AUDIT 1 @@ -90,6 +92,9 @@ int mem_sharing_unshare_page(struct domain *d, return rc; } =20 +int mem_sharing_fork_page(struct domain *d, gfn_t gfn, + bool unsharing); + /* * If called by a foreign domain, possible errors are * -EBUSY -> ring full @@ -119,6 +124,7 @@ int relinquish_shared_pages(struct domain *d); #else =20 #define mem_sharing_enabled(d) false +#define mem_sharing_is_fork(p2m) false =20 static inline unsigned int mem_sharing_get_nr_saved_mfns(void) { @@ -145,6 +151,16 @@ int mem_sharing_notify_enomem(struct domain *d, unsign= ed long gfn, return -EOPNOTSUPP; } =20 +static inline int mem_sharing_fork(struct domain *d, struct domain *cd, bo= ol vcpu) +{ + return -EOPNOTSUPP; +} + +static inline int mem_sharing_fork_page(struct domain *d, gfn_t gfn, bool = lock) +{ + return -EOPNOTSUPP; +} + #endif =20 #endif /* __MEM_SHARING_H__ */ diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index cfdda6e2a8..90a3f4498e 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -482,6 +482,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_mem_access_op_t); #define XENMEM_sharing_op_add_physmap 6 #define XENMEM_sharing_op_audit 7 #define XENMEM_sharing_op_range_share 8 +#define XENMEM_sharing_op_fork 9 =20 #define XENMEM_SHARING_OP_S_HANDLE_INVALID (-10) #define XENMEM_SHARING_OP_C_HANDLE_INVALID (-9) @@ -532,6 +533,10 @@ struct xen_mem_sharing_op { uint32_t gref; /* IN: gref to debug */ } u; } debug; + struct mem_sharing_op_fork { + domid_t parent_domain; + uint16_t _pad[3]; /* Must be set to 0 */ + } fork; } u; }; typedef struct xen_mem_sharing_op xen_mem_sharing_op_t; diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 9f7bc69293..fcad948962 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -501,6 +501,7 @@ struct domain /* Memory sharing support */ #ifdef CONFIG_MEM_SHARING struct vm_event_domain *vm_event_share; + struct domain *parent; /* VM fork parent */ #endif /* Memory paging support */ #ifdef CONFIG_HAS_MEM_PAGING --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698231; cv=none; d=zohomail.com; s=zohoarc; b=P4NmP7qk4WANHsFCLP/Ioy1pwEJM29UuBNyj7sVbZ5L66OVLJbTB+nGzndez5AaEjpTc6WVSuojDpctaRrIqpQ49ywoOT0nbUCvYOEjJF0GE7lz1LXKGatR27+EafImvP0GgLhaZdhgM3shTjDDF9nyrWZv/Iuwd7b3cy77sW5A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698231; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zDUUYFZB1bkPMbiv3VlBuQxbhGlj+hxBxScQ7TPgBRk=; b=lANyqdTn2+RPNgehc5+7I53mh84ThArTDkXO3bNvXyNEBsZ3TC6RRk/cjacygYal/I6VsI1URDtcFRh5aQKV1jvumP02lZAJzWaugXF39kpVOuDhiljXWRkElY1q/RPOiMoO0doUxA0tHc1PC6+CTxCqs4EEB5sALexSVTeK/s0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698231269229.50678218246992; Wed, 18 Dec 2019 11:43:51 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfDJ-00007L-GW; Wed, 18 Dec 2019 19:42:29 +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 1ihfDI-000053-8l for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:42:28 +0000 Received: from mga04.intel.com (unknown [192.55.52.120]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 634a6d2d-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:32 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:30 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:29 -0800 X-Inumbo-ID: 634a6d2d-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196415" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:55 -0800 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 18/20] xen/mem_access: Use __get_gfn_type_access in set_mem_access 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: Petre Pircalabu , Tamas K Lengyel , Tamas K Lengyel , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , Alexandru Isaila , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Use __get_gfn_type_access instead of p2m->get_entry to trigger page-forking when the mem_access permission is being set on a page that has not yet been copied over from the parent. Signed-off-by: Tamas K Lengyel --- xen/arch/x86/mm/mem_access.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c index 320b9fe621..9caf08a5b2 100644 --- a/xen/arch/x86/mm/mem_access.c +++ b/xen/arch/x86/mm/mem_access.c @@ -303,11 +303,10 @@ static int set_mem_access(struct domain *d, struct p2= m_domain *p2m, ASSERT(!ap2m); #endif { - mfn_t mfn; p2m_access_t _a; p2m_type_t t; - - mfn =3D p2m->get_entry(p2m, gfn, &t, &_a, 0, NULL, NULL); + mfn_t mfn =3D __get_gfn_type_access(p2m, gfn_x(gfn), &t, &_a, + P2M_ALLOC, NULL, false); rc =3D p2m->set_entry(p2m, gfn, mfn, PAGE_ORDER_4K, t, a, -1); } =20 --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698185; cv=none; d=zohomail.com; s=zohoarc; b=W3Er6nzrEYWGdUxMVr+NMxVwNTz2mpjf1jsKh6yjmDTfUnp3CUzLvAPn7OaPwvs9S2WnQNfrzIPDojofUpSJNoHu7FOHBvOqphgK5aorXuzjNBqPFlrHERRI82wCO8hinfiNZJroc1lUPRls3FfiiSgyOisj+5Zr8hHA2fJsFlE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698185; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=X1q4YxyaeGgkRls0QJEk9n2Z/FFjFqUWLf+ZbKsG7Nw=; b=CFFWj45QCe/YIrsEXMJAoV6uRySUMd+dVRl08MeThv7KoTn5wY/p9SWzTq59E8kees88LtE+RZzSlokrPfALJhsNgEJS3x6FCL0aRQqEb7wnizoxSqgviBLEnJwl0mNgDWXj1Q8DQCD+Il2BbBgdBeMfmLrEfwVLF7hdlgH4BuQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698185375950.7761460201916; Wed, 18 Dec 2019 11:43:05 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfDO-0000DB-TD; Wed, 18 Dec 2019 19:42:34 +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 1ihfDN-0000BI-8p for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:42:33 +0000 Received: from mga04.intel.com (unknown [192.55.52.120]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 651b6b6a-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:33 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:31 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:30 -0800 X-Inumbo-ID: 651b6b6a-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196426" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:56 -0800 Message-Id: <22a6cb7bd5593ed38cf6f66c26c4734a04718e1a.1576697796.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 19/20] x86/mem_sharing: reset a fork 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 , Tamas K Lengyel , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Stefano Stabellini , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Implement hypercall that allows a fork to shed all memory that got allocated for it during its execution and re-load its vCPU context from the parent VM. This allows the forked VM to reset into the same state the parent VM is in a faster way then creating a new fork would be. Measurements show about a 2x speedup during normal fuzzing operations. Performance may vary depending how much memory got allocated for the forked VM. If it has been completely deduplicated from the parent VM then creating a new fork would likely be mo= re performant. Signed-off-by: Tamas K Lengyel --- xen/arch/x86/mm/mem_sharing.c | 105 ++++++++++++++++++++++++++++++++++ xen/include/public/memory.h | 1 + 2 files changed, 106 insertions(+) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index e93ad2ec5a..4735a334b9 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1622,6 +1622,87 @@ static int mem_sharing_fork(struct domain *d, struct= domain *cd) return 0; } =20 +struct gfn_free; +struct gfn_free { + struct gfn_free *next; + struct page_info *page; + gfn_t gfn; +}; + +static int mem_sharing_fork_reset(struct domain *d, struct domain *cd) +{ + int rc; + + struct p2m_domain* p2m =3D p2m_get_hostp2m(cd); + struct gfn_free *list =3D NULL; + struct page_info *page; + + page_list_for_each(page, &cd->page_list) + { + mfn_t mfn =3D page_to_mfn(page); + if ( mfn_valid(mfn) ) + { + p2m_type_t p2mt; + p2m_access_t p2ma; + gfn_t gfn =3D mfn_to_gfn(cd, mfn); + mfn =3D __get_gfn_type_access(p2m, gfn_x(gfn), &p2mt, &p2ma, + 0, NULL, false); + if ( p2m_is_ram(p2mt) ) + { + struct gfn_free *gfn_free; + if ( !get_page(page, cd) ) + goto err_reset; + + /* + * We can't free the page while iterating over the page_li= st + * so we build a separate list to loop over. + * + * We want to iterate over the page_list instead of checki= ng + * gfn from 0 to max_gfn because this is ~10x faster. + */ + gfn_free =3D xmalloc(struct gfn_free); + if ( !gfn_free ) + goto err_reset; + + gfn_free->gfn =3D gfn; + gfn_free->page =3D page; + gfn_free->next =3D list; + list =3D gfn_free; + } + } + } + + while ( list ) + { + struct gfn_free *next =3D list->next; + + rc =3D p2m->set_entry(p2m, list->gfn, INVALID_MFN, PAGE_ORDER_4K, + p2m_invalid, p2m_access_rwx, -1); + put_page_alloc_ref(list->page); + put_page(list->page); + + xfree(list); + list =3D next; + + ASSERT(!rc); + } + + if ( (rc =3D fork_hvm(d, cd)) ) + return rc; + + err_reset: + while ( list ) + { + struct gfn_free *next =3D list->next; + + put_page(list->page); + xfree(list); + list =3D next; + } + + return 0; +} + int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) { int rc; @@ -1905,6 +1986,30 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem= _sharing_op_t) arg) rcu_unlock_domain(pd); break; } + + case XENMEM_sharing_op_fork_reset: + { + struct domain *pd; + + rc =3D -EINVAL; + if ( mso.u.fork._pad[0] || mso.u.fork._pad[1] || + mso.u.fork._pad[2] ) + goto out; + + rc =3D -ENOSYS; + if ( !d->parent ) + goto out; + + rc =3D rcu_lock_live_remote_domain_by_id(d->parent->domain_id,= &pd); + if ( rc ) + goto out; + + rc =3D mem_sharing_fork_reset(pd, d); + + rcu_unlock_domain(pd); + break; + } + default: rc =3D -ENOSYS; break; diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index 90a3f4498e..e3d063e22e 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -483,6 +483,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_mem_access_op_t); #define XENMEM_sharing_op_audit 7 #define XENMEM_sharing_op_range_share 8 #define XENMEM_sharing_op_fork 9 +#define XENMEM_sharing_op_fork_reset 10 =20 #define XENMEM_SHARING_OP_S_HANDLE_INVALID (-10) #define XENMEM_SHARING_OP_C_HANDLE_INVALID (-9) --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 01:36:40 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698199; cv=none; d=zohomail.com; s=zohoarc; b=lCfQS47y2DK+uq1uglIFbyDIgB+5l37cWgals1vOYbGs92EHG67f4UFVO/pMBLCMPUhL6TUDbXvZNuNR5HH9vV+R54WU34M0zImgDRuiCbrJfgKf6z5ZSMFkAh+yqn8lJuiMzDsHIXscNqb2rpJ7cdLgAObdgT79pM4PreKiaCI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698199; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=O4c/u16+ckRiX+VWrIi4sgp7cEi81P2bmaPHqTXVJ+k=; b=oH+jBe6tKXKh2jkyOxvLq5feafe8BXYV12VmZRC6hAZeY4S+31LEzJVrnEG8WCu4VroFJNUOj5KCxU0tGEqX0NJyr+vkNgaukLEiUYnAgp8SOpRL3Mdm/WiJ+zxYSwBdsOABSO4H3gklrxVH0PcxDRZRakH+sedBkdDQowQkV2I= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698199371287.0266396947186; Wed, 18 Dec 2019 11:43:19 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfDU-0000IC-84; Wed, 18 Dec 2019 19:42:40 +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 1ihfDS-0000Ge-8u for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:42:38 +0000 Received: from mga04.intel.com (unknown [192.55.52.120]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 651b6b6b-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:34 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:33 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:31 -0800 X-Inumbo-ID: 651b6b6b-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196437" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:57 -0800 Message-Id: <122128bd25e184d310a0a8af0f3c1e1c272d2fe1.1576697796.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 20/20] xen/tools: VM forking toolstack side 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: Anthony PERARD , Ian Jackson , Tamas K Lengyel , Wei Liu Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Add necessary bits to implement "xl fork-vm", "xl fork-launch-dm" and "xl fork-reset" commands. The process is split in two to allow tools needing access to the new VM as fast as possible after it was forked. It is expected that under certain use-cases the second command that launches QEMU will be skipped entirely. Signed-off-by: Tamas K Lengyel --- tools/libxc/include/xenctrl.h | 6 + tools/libxc/xc_memshr.c | 22 ++++ tools/libxl/libxl.h | 7 + tools/libxl/libxl_create.c | 237 +++++++++++++++++++++++----------- tools/libxl/libxl_dm.c | 2 +- tools/libxl/libxl_dom.c | 83 ++++++++---- tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_types.idl | 1 + tools/xl/xl.h | 5 + tools/xl/xl_cmdtable.c | 22 ++++ tools/xl/xl_saverestore.c | 96 ++++++++++++++ tools/xl/xl_vmcontrol.c | 8 ++ 12 files changed, 386 insertions(+), 104 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index b5ffa53d55..39afdb9b33 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2221,6 +2221,12 @@ int xc_memshr_range_share(xc_interface *xch, uint64_t first_gfn, uint64_t last_gfn); =20 +int xc_memshr_fork(xc_interface *xch, + uint32_t source_domain, + uint32_t client_domain); + +int xc_memshr_fork_reset(xc_interface *xch, uint32_t forked_domain); + /* Debug calls: return the number of pages referencing the shared frame ba= cking * the input argument. Should be one or greater. * diff --git a/tools/libxc/xc_memshr.c b/tools/libxc/xc_memshr.c index 5ef56a6933..ef5a5ee6a4 100644 --- a/tools/libxc/xc_memshr.c +++ b/tools/libxc/xc_memshr.c @@ -237,6 +237,28 @@ int xc_memshr_debug_gref(xc_interface *xch, return xc_memshr_memop(xch, domid, &mso); } =20 +int xc_memshr_fork(xc_interface *xch, uint32_t pdomid, uint32_t domid) +{ + xen_mem_sharing_op_t mso; + + memset(&mso, 0, sizeof(mso)); + + mso.op =3D XENMEM_sharing_op_fork; + mso.u.fork.parent_domain =3D pdomid; + + return xc_memshr_memop(xch, domid, &mso); +} + +int xc_memshr_fork_reset(xc_interface *xch, uint32_t domid) +{ + xen_mem_sharing_op_t mso; + + memset(&mso, 0, sizeof(mso)); + mso.op =3D XENMEM_sharing_op_fork_reset; + + return xc_memshr_memop(xch, domid, &mso); +} + int xc_memshr_audit(xc_interface *xch) { xen_mem_sharing_op_t mso; diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 54abb9db1f..75cb070587 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1536,6 +1536,13 @@ int libxl_domain_create_new(libxl_ctx *ctx, libxl_do= main_config *d_config, const libxl_asyncop_how *ao_how, const libxl_asyncprogress_how *aop_console_how) LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_domain_fork_vm(libxl_ctx *ctx, uint32_t pdomid, uint32_t *domid) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_domain_fork_launch_dm(libxl_ctx *ctx, libxl_domain_config *d_con= fig, + uint32_t domid, + const libxl_asyncprogress_how *aop_console= _how) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_domain_fork_reset(libxl_ctx *ctx, uint32_t domid); int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_con= fig, uint32_t *domid, int restore_fd, int send_back_fd, diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 32d45dcef0..e0d219596c 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -536,12 +536,12 @@ out: return ret; } =20 -int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, - libxl__domain_build_state *state, - uint32_t *domid) +static int libxl__domain_make_xs_entries(libxl__gc *gc, libxl_domain_confi= g *d_config, + libxl__domain_build_state *state, + uint32_t domid) { libxl_ctx *ctx =3D libxl__gc_owner(gc); - int ret, rc, nb_vm; + int rc, nb_vm; const char *dom_type; char *uuid_string; char *dom_path, *vm_path, *libxl_path; @@ -553,7 +553,6 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_conf= ig *d_config, =20 /* convenience aliases */ libxl_domain_create_info *info =3D &d_config->c_info; - libxl_domain_build_info *b_info =3D &d_config->b_info; =20 uuid_string =3D libxl__uuid2string(gc, info->uuid); if (!uuid_string) { @@ -561,64 +560,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_con= fig *d_config, goto out; } =20 - /* Valid domid here means we're soft resetting. */ - if (!libxl_domid_valid_guest(*domid)) { - struct xen_domctl_createdomain create =3D { - .ssidref =3D info->ssidref, - .max_vcpus =3D b_info->max_vcpus, - .max_evtchn_port =3D b_info->event_channels, - .max_grant_frames =3D b_info->max_grant_frames, - .max_maptrack_frames =3D b_info->max_maptrack_frames, - }; - - if (info->type !=3D LIBXL_DOMAIN_TYPE_PV) { - create.flags |=3D XEN_DOMCTL_CDF_hvm; - create.flags |=3D - libxl_defbool_val(info->hap) ? XEN_DOMCTL_CDF_hap : 0; - create.flags |=3D - libxl_defbool_val(info->oos) ? 0 : XEN_DOMCTL_CDF_oos_off; - } - - assert(info->passthrough !=3D LIBXL_PASSTHROUGH_DEFAULT); - LOG(DETAIL, "passthrough: %s", - libxl_passthrough_to_string(info->passthrough)); - - if (info->passthrough !=3D LIBXL_PASSTHROUGH_DISABLED) - create.flags |=3D XEN_DOMCTL_CDF_iommu; - - if (info->passthrough =3D=3D LIBXL_PASSTHROUGH_SYNC_PT) - create.iommu_opts |=3D XEN_DOMCTL_IOMMU_no_sharept; - - /* Ultimately, handle is an array of 16 uint8_t, same as uuid */ - libxl_uuid_copy(ctx, (libxl_uuid *)&create.handle, &info->uuid); - - ret =3D libxl__arch_domain_prepare_config(gc, d_config, &create); - if (ret < 0) { - LOGED(ERROR, *domid, "fail to get domain config"); - rc =3D ERROR_FAIL; - goto out; - } - - ret =3D xc_domain_create(ctx->xch, domid, &create); - if (ret < 0) { - LOGED(ERROR, *domid, "domain creation fail"); - rc =3D ERROR_FAIL; - goto out; - } - - rc =3D libxl__arch_domain_save_config(gc, d_config, state, &create= ); - if (rc < 0) - goto out; - } - - ret =3D xc_cpupool_movedomain(ctx->xch, info->poolid, *domid); - if (ret < 0) { - LOGED(ERROR, *domid, "domain move fail"); - rc =3D ERROR_FAIL; - goto out; - } - - dom_path =3D libxl__xs_get_dompath(gc, *domid); + dom_path =3D libxl__xs_get_dompath(gc, domid); if (!dom_path) { rc =3D ERROR_FAIL; goto out; @@ -626,12 +568,12 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_co= nfig *d_config, =20 vm_path =3D GCSPRINTF("/vm/%s", uuid_string); if (!vm_path) { - LOGD(ERROR, *domid, "cannot allocate create paths"); + LOGD(ERROR, domid, "cannot allocate create paths"); rc =3D ERROR_FAIL; goto out; } =20 - libxl_path =3D libxl__xs_libxl_path(gc, *domid); + libxl_path =3D libxl__xs_libxl_path(gc, domid); if (!libxl_path) { rc =3D ERROR_FAIL; goto out; @@ -642,10 +584,10 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_co= nfig *d_config, =20 roperm[0].id =3D 0; roperm[0].perms =3D XS_PERM_NONE; - roperm[1].id =3D *domid; + roperm[1].id =3D domid; roperm[1].perms =3D XS_PERM_READ; =20 - rwperm[0].id =3D *domid; + rwperm[0].id =3D domid; rwperm[0].perms =3D XS_PERM_NONE; =20 retry_transaction: @@ -663,7 +605,7 @@ retry_transaction: noperm, ARRAY_SIZE(noperm)); =20 xs_write(ctx->xsh, t, GCSPRINTF("%s/vm", dom_path), vm_path, strlen(vm= _path)); - rc =3D libxl__domain_rename(gc, *domid, 0, info->name, t); + rc =3D libxl__domain_rename(gc, domid, 0, info->name, t); if (rc) goto out; =20 @@ -740,7 +682,7 @@ retry_transaction: =20 vm_list =3D libxl_list_vm(ctx, &nb_vm); if (!vm_list) { - LOGD(ERROR, *domid, "cannot get number of running guests"); + LOGD(ERROR, domid, "cannot get number of running guests"); rc =3D ERROR_FAIL; goto out; } @@ -764,7 +706,7 @@ retry_transaction: t =3D 0; goto retry_transaction; } - LOGED(ERROR, *domid, "domain creation ""xenstore transaction commi= t failed"); + LOGED(ERROR, domid, "domain creation ""xenstore transaction commit= failed"); rc =3D ERROR_FAIL; goto out; } @@ -776,6 +718,80 @@ retry_transaction: return rc; } =20 +int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, + libxl__domain_build_state *state, + uint32_t *domid) +{ + libxl_ctx *ctx =3D libxl__gc_owner(gc); + int ret, rc; + + /* convenience aliases */ + libxl_domain_create_info *info =3D &d_config->c_info; + libxl_domain_build_info *b_info =3D &d_config->b_info; + + /* Valid domid here means we're soft resetting. */ + if (!libxl_domid_valid_guest(*domid)) { + struct xen_domctl_createdomain create =3D { + .ssidref =3D info->ssidref, + .max_vcpus =3D b_info->max_vcpus, + .max_evtchn_port =3D b_info->event_channels, + .max_grant_frames =3D b_info->max_grant_frames, + .max_maptrack_frames =3D b_info->max_maptrack_frames, + }; + + if (info->type !=3D LIBXL_DOMAIN_TYPE_PV) { + create.flags |=3D XEN_DOMCTL_CDF_hvm; + create.flags |=3D + libxl_defbool_val(info->hap) ? XEN_DOMCTL_CDF_hap : 0; + create.flags |=3D + libxl_defbool_val(info->oos) ? 0 : XEN_DOMCTL_CDF_oos_off; + } + + assert(info->passthrough !=3D LIBXL_PASSTHROUGH_DEFAULT); + LOG(DETAIL, "passthrough: %s", + libxl_passthrough_to_string(info->passthrough)); + + if (info->passthrough !=3D LIBXL_PASSTHROUGH_DISABLED) + create.flags |=3D XEN_DOMCTL_CDF_iommu; + + if (info->passthrough =3D=3D LIBXL_PASSTHROUGH_SYNC_PT) + create.iommu_opts |=3D XEN_DOMCTL_IOMMU_no_sharept; + + /* Ultimately, handle is an array of 16 uint8_t, same as uuid */ + libxl_uuid_copy(ctx, (libxl_uuid *)&create.handle, &info->uuid); + + ret =3D libxl__arch_domain_prepare_config(gc, d_config, &create); + if (ret < 0) { + LOGED(ERROR, *domid, "fail to get domain config"); + rc =3D ERROR_FAIL; + goto out; + } + + ret =3D xc_domain_create(ctx->xch, domid, &create); + if (ret < 0) { + LOGED(ERROR, *domid, "domain creation fail"); + rc =3D ERROR_FAIL; + goto out; + } + + rc =3D libxl__arch_domain_save_config(gc, d_config, state, &create= ); + if (rc < 0) + goto out; + } + + ret =3D xc_cpupool_movedomain(ctx->xch, info->poolid, *domid); + if (ret < 0) { + LOGED(ERROR, *domid, "domain move fail"); + rc =3D ERROR_FAIL; + goto out; + } + + rc =3D libxl__domain_make_xs_entries(gc, d_config, state, *domid); + +out: + return rc; +} + static int store_libxl_entry(libxl__gc *gc, uint32_t domid, libxl_domain_build_info *b_info) { @@ -1097,15 +1113,31 @@ static void initiate_domain_create(libxl__egc *egc, ret =3D libxl__domain_config_setdefault(gc,d_config,domid); if (ret) goto error_out; =20 - ret =3D libxl__domain_make(gc, d_config, &dcs->build_state, &domid); - if (ret) { - LOGD(ERROR, domid, "cannot make domain: %d", ret); + if ( !d_config->dm_restore_file ) + { + ret =3D libxl__domain_make(gc, d_config, &dcs->build_state, &domid= ); dcs->guest_domid =3D domid; + + if (ret) { + LOGD(ERROR, domid, "cannot make domain: %d", ret); + ret =3D ERROR_FAIL; + goto error_out; + } + } else if ( dcs->guest_domid !=3D INVALID_DOMID ) { + domid =3D dcs->guest_domid; + + ret =3D libxl__domain_make_xs_entries(gc, d_config, &dcs->build_st= ate, domid); + if (ret) { + LOGD(ERROR, domid, "cannot make domain: %d", ret); + ret =3D ERROR_FAIL; + goto error_out; + } + } else { + LOGD(ERROR, domid, "cannot make domain"); ret =3D ERROR_FAIL; goto error_out; } =20 - dcs->guest_domid =3D domid; dcs->sdss.dm.guest_domid =3D 0; /* means we haven't spawned */ =20 /* post-4.13 todo: move these next bits of defaulting to @@ -1141,7 +1173,7 @@ static void initiate_domain_create(libxl__egc *egc, if (ret) goto error_out; =20 - if (restore_fd >=3D 0 || dcs->domid_soft_reset !=3D INVALID_DOMID) { + if (restore_fd >=3D 0 || dcs->domid_soft_reset !=3D INVALID_DOMID || d= _config->dm_restore_file) { LOGD(DEBUG, domid, "restoring, not running bootloader"); domcreate_bootloader_done(egc, &dcs->bl, 0); } else { @@ -1217,7 +1249,16 @@ static void domcreate_bootloader_done(libxl__egc *eg= c, dcs->sdss.dm.callback =3D domcreate_devmodel_started; dcs->sdss.callback =3D domcreate_devmodel_started; =20 - if (restore_fd < 0 && dcs->domid_soft_reset =3D=3D INVALID_DOMID) { + if (restore_fd < 0 && dcs->domid_soft_reset =3D=3D INVALID_DOMID && !d= _config->dm_restore_file) { + rc =3D libxl__domain_build(gc, d_config, domid, state); + domcreate_rebuild_done(egc, dcs, rc); + return; + } + + if ( d_config->dm_restore_file ) { + dcs->srs.dcs =3D dcs; + dcs->srs.ao =3D ao; + state->forked_vm =3D true; rc =3D libxl__domain_build(gc, d_config, domid, state); domcreate_rebuild_done(egc, dcs, rc); return; @@ -1415,6 +1456,7 @@ static void domcreate_rebuild_done(libxl__egc *egc, /* convenience aliases */ const uint32_t domid =3D dcs->guest_domid; libxl_domain_config *const d_config =3D dcs->guest_config; + libxl__domain_build_state *const state =3D &dcs->build_state; =20 if (ret) { LOGD(ERROR, domid, "cannot (re-)build domain: %d", ret); @@ -1422,6 +1464,9 @@ static void domcreate_rebuild_done(libxl__egc *egc, goto error_out; } =20 + if ( d_config->dm_restore_file ) + state->saved_state =3D GCSPRINTF("%s", d_config->dm_restore_file); + store_libxl_entry(gc, domid, &d_config->b_info); =20 libxl__multidev_begin(ao, &dcs->multidev); @@ -1823,10 +1868,13 @@ static int do_domain_create(libxl_ctx *ctx, libxl_d= omain_config *d_config, GCNEW(cdcs); cdcs->dcs.ao =3D ao; cdcs->dcs.guest_config =3D d_config; + cdcs->dcs.guest_domid =3D *domid; + libxl_domain_config_init(&cdcs->dcs.guest_config_saved); libxl_domain_config_copy(ctx, &cdcs->dcs.guest_config_saved, d_config); cdcs->dcs.restore_fd =3D cdcs->dcs.libxc_fd =3D restore_fd; cdcs->dcs.send_back_fd =3D send_back_fd; + if (restore_fd > -1) { cdcs->dcs.restore_params =3D *params; rc =3D libxl__fd_flags_modify_save(gc, cdcs->dcs.restore_fd, @@ -2069,6 +2117,43 @@ int libxl_domain_create_new(libxl_ctx *ctx, libxl_do= main_config *d_config, ao_how, aop_console_how); } =20 +int libxl_domain_fork_vm(libxl_ctx *ctx, uint32_t pdomid, uint32_t *domid) +{ + int rc; + struct xen_domctl_createdomain create =3D {0}; + create.flags |=3D XEN_DOMCTL_CDF_hvm; + create.flags |=3D XEN_DOMCTL_CDF_hap; + create.flags |=3D XEN_DOMCTL_CDF_oos_off; + create.arch.emulation_flags =3D (XEN_X86_EMU_ALL & ~XEN_X86_EMU_VPCI); + + create.ssidref =3D SECINITSID_DOMU; + create.max_vcpus =3D 1; // placeholder, will be cloned from pdomid + create.max_evtchn_port =3D 1023; + create.max_grant_frames =3D LIBXL_MAX_GRANT_FRAMES_DEFAULT; + create.max_maptrack_frames =3D LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT; + + if ( (rc =3D xc_domain_create(ctx->xch, domid, &create)) ) + return rc; + + if ( (rc =3D xc_memshr_fork(ctx->xch, pdomid, *domid)) ) + xc_domain_destroy(ctx->xch, *domid); + + return rc; +} + +int libxl_domain_fork_launch_dm(libxl_ctx *ctx, libxl_domain_config *d_con= fig, + uint32_t domid, + const libxl_asyncprogress_how *aop_console= _how) +{ + unset_disk_colo_restore(d_config); + return do_domain_create(ctx, d_config, &domid, -1, -1, 0, 0, aop_conso= le_how); +} + +int libxl_domain_fork_reset(libxl_ctx *ctx, uint32_t domid) +{ + return xc_memshr_fork_reset(ctx->xch, domid); +} + int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_con= fig, uint32_t *domid, int restore_fd, int send_back_fd, diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index dac1b8ddb8..a119e789a7 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -2784,7 +2784,7 @@ static void device_model_spawn_outcome(libxl__egc *eg= c, =20 libxl__domain_build_state *state =3D dmss->build_state; =20 - if (state->saved_state) { + if (state->saved_state && !state->forked_vm) { ret2 =3D unlink(state->saved_state); if (ret2) { LOGED(ERROR, dmss->guest_domid, "%s: failed to remove device-m= odel state %s", diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index cdb294ab8d..95e6ecc9d3 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -392,9 +392,12 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid, libxl_domain_build_info *const info =3D &d_config->b_info; libxl_ctx *ctx =3D libxl__gc_owner(gc); char *xs_domid, *con_domid; - int rc; + int rc =3D 0; uint64_t size; =20 + if ( state->forked_vm ) + goto skip_fork; + if (xc_domain_max_vcpus(ctx->xch, domid, info->max_vcpus) !=3D 0) { LOG(ERROR, "Couldn't set max vcpu count"); return ERROR_FAIL; @@ -499,29 +502,6 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid, } } =20 - - rc =3D libxl__arch_extra_memory(gc, info, &size); - if (rc < 0) { - LOGE(ERROR, "Couldn't get arch extra constant memory size"); - return ERROR_FAIL; - } - - if (xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb + size) < = 0) { - LOGE(ERROR, "Couldn't set max memory"); - return ERROR_FAIL; - } - - xs_domid =3D xs_read(ctx->xsh, XBT_NULL, "/tool/xenstored/domid", NULL= ); - state->store_domid =3D xs_domid ? atoi(xs_domid) : 0; - free(xs_domid); - - con_domid =3D xs_read(ctx->xsh, XBT_NULL, "/tool/xenconsoled/domid", N= ULL); - state->console_domid =3D con_domid ? atoi(con_domid) : 0; - free(con_domid); - - state->store_port =3D xc_evtchn_alloc_unbound(ctx->xch, domid, state->= store_domid); - state->console_port =3D xc_evtchn_alloc_unbound(ctx->xch, domid, state= ->console_domid); - if (info->type !=3D LIBXL_DOMAIN_TYPE_PV) hvm_set_conf_params(ctx->xch, domid, info); =20 @@ -556,8 +536,34 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid, info->altp2m); } =20 + rc =3D libxl__arch_extra_memory(gc, info, &size); + if (rc < 0) { + LOGE(ERROR, "Couldn't get arch extra constant memory size"); + return ERROR_FAIL; + } + + if (xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb + size) < = 0) { + LOGE(ERROR, "Couldn't set max memory"); + return ERROR_FAIL; + } + rc =3D libxl__arch_domain_create(gc, d_config, domid); + if ( rc ) + goto out; =20 +skip_fork: + xs_domid =3D xs_read(ctx->xsh, XBT_NULL, "/tool/xenstored/domid", NULL= ); + state->store_domid =3D xs_domid ? atoi(xs_domid) : 0; + free(xs_domid); + + con_domid =3D xs_read(ctx->xsh, XBT_NULL, "/tool/xenconsoled/domid", N= ULL); + state->console_domid =3D con_domid ? atoi(con_domid) : 0; + free(con_domid); + + state->store_port =3D xc_evtchn_alloc_unbound(ctx->xch, domid, state->= store_domid); + state->console_port =3D xc_evtchn_alloc_unbound(ctx->xch, domid, state= ->console_domid); + +out: return rc; } =20 @@ -615,6 +621,9 @@ int libxl__build_post(libxl__gc *gc, uint32_t domid, char **ents; int i, rc; =20 + if ( state->forked_vm ) + goto skip_fork; + if (info->num_vnuma_nodes && !info->num_vcpu_soft_affinity) { rc =3D set_vnuma_affinity(gc, domid, info); if (rc) @@ -639,6 +648,7 @@ int libxl__build_post(libxl__gc *gc, uint32_t domid, } } =20 +skip_fork: ents =3D libxl__calloc(gc, 12 + (info->max_vcpus * 2) + 2, sizeof(char= *)); ents[0] =3D "memory/static-max"; ents[1] =3D GCSPRINTF("%"PRId64, info->max_memkb); @@ -901,14 +911,16 @@ static int hvm_build_set_params(xc_interface *handle,= uint32_t domid, libxl_domain_build_info *info, int store_evtchn, unsigned long *store_mfn, int console_evtchn, unsigned long *console= _mfn, - domid_t store_domid, domid_t console_domid) + domid_t store_domid, domid_t console_domid, + bool forked_vm) { struct hvm_info_table *va_hvm; uint8_t *va_map, sum; uint64_t str_mfn, cons_mfn; int i; =20 - if (info->type =3D=3D LIBXL_DOMAIN_TYPE_HVM) { + if ( info->type =3D=3D LIBXL_DOMAIN_TYPE_HVM && !forked_vm ) + { va_map =3D xc_map_foreign_range(handle, domid, XC_PAGE_SIZE, PROT_READ | PROT_WRITE, HVM_INFO_PFN); @@ -1224,6 +1236,23 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid, struct xc_dom_image *dom =3D NULL; bool device_model =3D info->type =3D=3D LIBXL_DOMAIN_TYPE_HVM ? true := false; =20 + if ( state->forked_vm ) + { + rc =3D hvm_build_set_params(ctx->xch, domid, info, state->store_po= rt, + &state->store_mfn, state->console_port, + &state->console_mfn, state->store_domid, + state->console_domid, state->forked_vm); + + if ( rc ) + return rc; + + return xc_dom_gnttab_seed(ctx->xch, domid, true, + state->console_mfn, + state->store_mfn, + state->console_domid, + state->store_domid); + } + xc_dom_loginit(ctx->xch); =20 /* @@ -1348,7 +1377,7 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid, rc =3D hvm_build_set_params(ctx->xch, domid, info, state->store_port, &state->store_mfn, state->console_port, &state->console_mfn, state->store_domid, - state->console_domid); + state->console_domid, false); if (rc !=3D 0) { LOG(ERROR, "hvm build set params failed"); goto out; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index b5adbfe4b7..ea6fe133a5 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1360,6 +1360,7 @@ typedef struct { =20 char *saved_state; int dm_monitor_fd; + bool forked_vm; =20 libxl__file_reference pv_kernel; libxl__file_reference pv_ramdisk; diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index 7921950f6a..7c4c4057a9 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -956,6 +956,7 @@ libxl_domain_config =3D Struct("domain_config", [ ("on_watchdog", libxl_action_on_shutdown), ("on_crash", libxl_action_on_shutdown), ("on_soft_reset", libxl_action_on_shutdown), + ("dm_restore_file", string, {'const': True}), ], dir=3DDIR_IN) =20 libxl_diskinfo =3D Struct("diskinfo", [ diff --git a/tools/xl/xl.h b/tools/xl/xl.h index 60bdad8ffb..9bdad6526e 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -31,6 +31,7 @@ struct cmd_spec { }; =20 struct domain_create { + uint32_t ddomid; /* fork launch dm for this domid */ int debug; int daemonize; int monitor; /* handle guest reboots etc */ @@ -45,6 +46,7 @@ struct domain_create { const char *config_file; char *extra_config; /* extra config string */ const char *restore_file; + const char *dm_restore_file; char *colo_proxy_script; bool userspace_colo_proxy; int migrate_fd; /* -1 means none */ @@ -127,6 +129,9 @@ int main_pciassignable_remove(int argc, char **argv); int main_pciassignable_list(int argc, char **argv); #ifndef LIBXL_HAVE_NO_SUSPEND_RESUME int main_restore(int argc, char **argv); +int main_fork_vm(int argc, char **argv); +int main_fork_launch_dm(int argc, char **argv); +int main_fork_reset(int argc, char **argv); int main_migrate_receive(int argc, char **argv); int main_save(int argc, char **argv); int main_migrate(int argc, char **argv); diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 5baa6023aa..94217e4ed4 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -180,6 +180,28 @@ struct cmd_spec cmd_table[] =3D { "-V, --vncviewer Connect to the VNC display after the domai= n is created.\n" "-A, --vncviewer-autopass Pass VNC password to viewer via stdin." }, + { "fork-vm", + &main_fork_vm, 0, 1, + "Fork a domain from the running parent domid", + "[options] ", + "-h Print this help.\n" + "-d Enable debug messages.\n" + }, + { "fork-launch-dm", + &main_fork_launch_dm, 0, 1, + "Launch the device model for a forked VM", + "[options] ", + "-h Print this help.\n" + "-p Do not unpause domain after restoring it.\= n" + "-d Enable debug messages.\n" + }, + { "fork-reset", + &main_fork_reset, 0, 1, + "Launch the device model for a forked VM", + "[options] ", + "-h Print this help.\n" + "-d Enable debug messages.\n" + }, { "migrate-receive", &main_migrate_receive, 0, 1, "Restore a domain from a saved state", diff --git a/tools/xl/xl_saverestore.c b/tools/xl/xl_saverestore.c index 9be033fe65..c1dd74f33e 100644 --- a/tools/xl/xl_saverestore.c +++ b/tools/xl/xl_saverestore.c @@ -229,6 +229,102 @@ int main_restore(int argc, char **argv) return EXIT_SUCCESS; } =20 +int main_fork_vm(int argc, char **argv) +{ + int debug =3D 0; + uint32_t pdomid =3D 0, domid =3D INVALID_DOMID; + int opt; + + SWITCH_FOREACH_OPT(opt, "d", NULL, "fork-vm", 1) { + case 'd': + debug =3D 1; + break; + } + + if (argc-optind =3D=3D 1) { + pdomid =3D atoi(argv[optind]); + } else { + help("fork-vm"); + return EXIT_FAILURE; + } + + if (libxl_domain_fork_vm(ctx, pdomid, &domid) || domid =3D=3D INVALID_= DOMID) + return EXIT_FAILURE; + + fprintf(stderr, "VM fork created with domid: %u\n", domid); + return EXIT_SUCCESS; +} + +int main_fork_launch_dm(int argc, char **argv) +{ + const char *config_file =3D NULL; + const char *dm_restore_file =3D NULL; + struct domain_create dom_info; + int paused =3D 0, debug =3D 0; + uint32_t ddomid =3D 0; + int opt, rc; + + SWITCH_FOREACH_OPT(opt, "pd", NULL, "fork-launch-dm", 1) { + case 'p': + paused =3D 1; + break; + case 'd': + debug =3D 1; + break; + } + + if (argc-optind =3D=3D 3) { + config_file =3D argv[optind]; + dm_restore_file =3D argv[optind + 1]; + ddomid =3D atoi(argv[optind + 2]); + } else { + help("fork-launch-dm"); + return EXIT_FAILURE; + } + + memset(&dom_info, 0, sizeof(dom_info)); + dom_info.ddomid =3D ddomid; + dom_info.dm_restore_file =3D dm_restore_file; + dom_info.debug =3D debug; + dom_info.paused =3D paused; + dom_info.config_file =3D config_file; + dom_info.migrate_fd =3D -1; + dom_info.send_back_fd =3D -1; + + rc =3D create_domain(&dom_info); + if (rc < 0) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +int main_fork_reset(int argc, char **argv) +{ + int debug =3D 0; + uint32_t domid =3D 0; + int opt, rc; + + SWITCH_FOREACH_OPT(opt, "d", NULL, "fork-reset", 1) + { + case 'd': + debug =3D 1; + break; + } + + if (argc-optind =3D=3D 1) { + domid =3D atoi(argv[optind]); + } else { + help("fork-reset"); + return EXIT_FAILURE; + } + + rc =3D libxl_domain_fork_reset(ctx, domid); + if (rc < 0) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + int main_save(int argc, char **argv) { uint32_t domid; diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index e520b1da79..d9cb19c599 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -645,6 +645,7 @@ int create_domain(struct domain_create *dom_info) =20 libxl_domain_config d_config; =20 + uint32_t ddomid =3D dom_info->ddomid; // launch dm for this domain iff= set int debug =3D dom_info->debug; int daemonize =3D dom_info->daemonize; int monitor =3D dom_info->monitor; @@ -655,6 +656,7 @@ int create_domain(struct domain_create *dom_info) const char *restore_file =3D dom_info->restore_file; const char *config_source =3D NULL; const char *restore_source =3D NULL; + const char *dm_restore_file =3D dom_info->dm_restore_file; int migrate_fd =3D dom_info->migrate_fd; bool config_in_json; =20 @@ -923,6 +925,12 @@ start: * restore/migrate-receive it again. */ restoring =3D 0; + } else if ( ddomid ) { + d_config.dm_restore_file =3D dm_restore_file; + ret =3D libxl_domain_fork_launch_dm(ctx, &d_config, ddomid, + autoconnect_console_how); + domid =3D ddomid; + ddomid =3D INVALID_DOMID; } else if (domid_soft_reset !=3D INVALID_DOMID) { /* Do soft reset. */ ret =3D libxl_domain_soft_reset(ctx, &d_config, domid_soft_reset, --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel