From nobody Fri May 3 08:29:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1576862665; cv=none; d=zohomail.com; s=zohoarc; b=mlwiM7JGr8uZnEyPg47AsQGTS17QqvkL2NcTnnLENY5cYhmLLbSN2jAAbxJh2eqH0KJBVDbBt18PIJ/zp9V9vRs4AwvpSGC8M/wmASEhRwMkmuI88KquYf5S6kkgFdoFL8+Imr/CB+f/3HCcaAoeNxdcHgZSI9x3TFyI9py1qNA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576862665; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=6ED3RBpEJufKxLsqIV0kyRmmGvpEapCdp+ZWJEQjC+8=; b=S/mmUpV64CBXrA+26NGV63AVVBr9UiCbkrvLAVECSErpbpB8AQtxPqkWZpSG2EzU1dO+rnqE4HwCol7OLrVPKO1LUdcmkd2uDDL7hQLFFEOGbbGSfGr6eAk54gYCHy2Rjlq1KVL9mKgKgH/uwcgTGEZuLVxd86CWr73MG9MI7V4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1576862665298592.4604123285573; Fri, 20 Dec 2019 09:24:25 -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 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 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) X-Inumbo-ID: 66be5a88-234d-11ea-a914-bc764e2007e4 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 (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; 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) vcpu_guest_context_any_t is currently allocated on the stack, and copied fr= om 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 *c= tx, unsigned int vcpuid) { xc_interface *xch =3D ctx->xch; - vcpu_guest_context_any_t vcpu; + vcpu_guest_context_any_t *vcpu =3D ctx->x86_pv.restore.vcpus[vcpuid].b= asic; xen_pfn_t pfn, mfn; unsigned i, gdt_count; int rc =3D -1; =20 - 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 =3D=3D 0 ) { - rc =3D process_start_info(ctx, &vcpu); + rc =3D process_start_info(ctx, vcpu); if ( rc ) return rc; rc =3D -1; } =20 - 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); =20 - gdt_count =3D GET_FIELD(&vcpu, gdt_ents, ctx->x86_pv.width); + gdt_count =3D 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 =3D 0; i < gdt_count; ++i ) { - pfn =3D GET_FIELD(&vcpu, gdt_frames[i], ctx->x86_pv.width); + pfn =3D 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 *c= tx, goto err; } =20 - SET_FIELD(&vcpu, gdt_frames[i], mfn, ctx->x86_pv.width); + SET_FIELD(vcpu, gdt_frames[i], mfn, ctx->x86_pv.width); } =20 /* Convert CR3 to an mfn. */ - pfn =3D cr3_to_mfn(ctx, GET_FIELD(&vcpu, ctrlreg[3], ctx->x86_pv.width= )); + pfn =3D 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 *c= tx, goto err; } =20 - 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); =20 /* 64bit guests: Convert CR1 (guest pagetables) to mfn. */ - if ( ctx->x86_pv.levels =3D=3D 4 && (vcpu.x64.ctrlreg[1] & 1) ) + if ( ctx->x86_pv.levels =3D=3D 4 && (vcpu->x64.ctrlreg[1] & 1) ) { - pfn =3D vcpu.x64.ctrlreg[1] >> PAGE_SHIFT; + pfn =3D vcpu->x64.ctrlreg[1] >> PAGE_SHIFT; =20 if ( pfn > ctx->x86_pv.max_pfn ) { @@ -355,10 +352,10 @@ static int process_vcpu_basic(struct xc_sr_context *c= tx, goto err; } =20 - vcpu.x64.ctrlreg[1] =3D (uint64_t)mfn << PAGE_SHIFT; + vcpu->x64.ctrlreg[1] =3D (uint64_t)mfn << PAGE_SHIFT; } =20 - 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; --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel