From patchwork Fri Dec 20 17:23:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11306053 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E7AA14F6 for ; Fri, 20 Dec 2019 17:24:46 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3A76E206A5 for ; Fri, 20 Dec 2019 17:24:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="K4sk9hfU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3A76E206A5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iiLzo-0007Ra-BR; Fri, 20 Dec 2019 17:23:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iiLzm-0007RV-Od for xen-devel@lists.xenproject.org; Fri, 20 Dec 2019 17:23:22 +0000 X-Inumbo-ID: 66be5a88-234d-11ea-a914-bc764e2007e4 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 66be5a88-234d-11ea-a914-bc764e2007e4; Fri, 20 Dec 2019 17:23:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1576862593; h=from:to:cc:subject:date:message-id:mime-version; bh=zvfvGbXGGcwjti2zy4M0c7LJxvvS4NUWyuGNRYX5tG0=; b=K4sk9hfUFcxQWChvASLekqP+HBwZkSxYoiXuqE1hhsrVd/mVkEkvj/Aj Vtouk78BokyiWm48YqadF3VrkFTuf21xALgtwhh9NML/dkxXR8FHYGSck OyDCxCrRt3zvSCNJW/UY1rKGoHSWzqBrTR48QGuYHtAFJrjeDZ6VfKp9l c=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: rywsNXeStD6SgdS2Ybb8ZQyE6xZ99Cm/+A7QQ6PYYjWT50w/muMA2HpSLvo9WppueySL32ghok mZk9Ax6iMiFkqkh8DsUShGIGTJeFte7m/kqm3ZHvOzQhZSrS8dKafc4gPIvw+L0soLLMra5RYk JB6jUXt0mi2Nfq+YWaEmJDZ5OAX+tsFjKWK46IY3ymZWn/WkoFRwuBj3535/ewe8DF2/n4v6RY tKsv3J6m5yf4ERCpispcfKDMt18BnSxlz+WDmNPjYQm2/hoP2yickabLgbPBYi7oqKgvjrgL3N vHA= X-SBRS: 2.7 X-MesageID: 10368290 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,336,1571716800"; d="scan'208";a="10368290" From: Andrew Cooper To: Xen-devel Date: Fri, 20 Dec 2019 17:23:10 +0000 Message-ID: <20191220172310.27231-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] libxc/restore: Don't duplicate state in process_vcpu_basic() 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 , Wei Liu , Ian Jackson Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" vcpu_guest_context_any_t is currently allocated on the stack, and copied from a mutable buffer which is freed immediately after its use here. Mutate the buffer in place instead of duplicating it. Signed-off-by: Andrew Cooper Acked-by: Ian Jackson --- CC: Ian Jackson CC: Wei Liu --- tools/libxc/xc_sr_restore_x86_pv.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/tools/libxc/xc_sr_restore_x86_pv.c b/tools/libxc/xc_sr_restore_x86_pv.c index 0a5b0016b4..70b8d2ad95 100644 --- a/tools/libxc/xc_sr_restore_x86_pv.c +++ b/tools/libxc/xc_sr_restore_x86_pv.c @@ -236,28 +236,25 @@ static int process_vcpu_basic(struct xc_sr_context *ctx, unsigned int vcpuid) { xc_interface *xch = ctx->xch; - vcpu_guest_context_any_t vcpu; + vcpu_guest_context_any_t *vcpu = ctx->x86_pv.restore.vcpus[vcpuid].basic; xen_pfn_t pfn, mfn; unsigned i, gdt_count; int rc = -1; - memcpy(&vcpu, ctx->x86_pv.restore.vcpus[vcpuid].basic, - ctx->x86_pv.restore.vcpus[vcpuid].basicsz); - /* Vcpu 0 is special: Convert the suspend record to an mfn. */ if ( vcpuid == 0 ) { - rc = process_start_info(ctx, &vcpu); + rc = process_start_info(ctx, vcpu); if ( rc ) return rc; rc = -1; } - SET_FIELD(&vcpu, flags, - GET_FIELD(&vcpu, flags, ctx->x86_pv.width) | VGCF_online, + SET_FIELD(vcpu, flags, + GET_FIELD(vcpu, flags, ctx->x86_pv.width) | VGCF_online, ctx->x86_pv.width); - gdt_count = GET_FIELD(&vcpu, gdt_ents, ctx->x86_pv.width); + gdt_count = GET_FIELD(vcpu, gdt_ents, ctx->x86_pv.width); if ( gdt_count > FIRST_RESERVED_GDT_ENTRY ) { ERROR("GDT entry count (%u) out of range (max %u)", @@ -270,7 +267,7 @@ static int process_vcpu_basic(struct xc_sr_context *ctx, /* Convert GDT frames to mfns. */ for ( i = 0; i < gdt_count; ++i ) { - pfn = GET_FIELD(&vcpu, gdt_frames[i], ctx->x86_pv.width); + pfn = GET_FIELD(vcpu, gdt_frames[i], ctx->x86_pv.width); if ( pfn > ctx->x86_pv.max_pfn ) { ERROR("GDT frame %u (pfn %#lx) out of range", i, pfn); @@ -293,11 +290,11 @@ static int process_vcpu_basic(struct xc_sr_context *ctx, goto err; } - SET_FIELD(&vcpu, gdt_frames[i], mfn, ctx->x86_pv.width); + SET_FIELD(vcpu, gdt_frames[i], mfn, ctx->x86_pv.width); } /* Convert CR3 to an mfn. */ - pfn = cr3_to_mfn(ctx, GET_FIELD(&vcpu, ctrlreg[3], ctx->x86_pv.width)); + pfn = cr3_to_mfn(ctx, GET_FIELD(vcpu, ctrlreg[3], ctx->x86_pv.width)); if ( pfn > ctx->x86_pv.max_pfn ) { ERROR("cr3 (pfn %#lx) out of range", pfn); @@ -323,12 +320,12 @@ static int process_vcpu_basic(struct xc_sr_context *ctx, goto err; } - SET_FIELD(&vcpu, ctrlreg[3], mfn_to_cr3(ctx, mfn), ctx->x86_pv.width); + SET_FIELD(vcpu, ctrlreg[3], mfn_to_cr3(ctx, mfn), ctx->x86_pv.width); /* 64bit guests: Convert CR1 (guest pagetables) to mfn. */ - if ( ctx->x86_pv.levels == 4 && (vcpu.x64.ctrlreg[1] & 1) ) + if ( ctx->x86_pv.levels == 4 && (vcpu->x64.ctrlreg[1] & 1) ) { - pfn = vcpu.x64.ctrlreg[1] >> PAGE_SHIFT; + pfn = vcpu->x64.ctrlreg[1] >> PAGE_SHIFT; if ( pfn > ctx->x86_pv.max_pfn ) { @@ -355,10 +352,10 @@ static int process_vcpu_basic(struct xc_sr_context *ctx, goto err; } - vcpu.x64.ctrlreg[1] = (uint64_t)mfn << PAGE_SHIFT; + vcpu->x64.ctrlreg[1] = (uint64_t)mfn << PAGE_SHIFT; } - if ( xc_vcpu_setcontext(xch, ctx->domid, vcpuid, &vcpu) ) + if ( xc_vcpu_setcontext(xch, ctx->domid, vcpuid, vcpu) ) { PERROR("Failed to set vcpu%u's basic info", vcpuid); goto err;