From nobody Fri Nov 18 18:26:21 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NDQGP61Hyz4d7NJ; Fri, 18 Nov 2022 18:26:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NDQGP5W8zz4H1L; Fri, 18 Nov 2022 18:26:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668795981; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=HF/2SNMuzl1Wwfpgm1+JbUY/cPTJvyKiJ3QwabWiyXY=; b=RjWnM1CPtrPt3qOmH3Z4riQIQTuCeBV3ZnkTXBbjJ8XP2pg6H7EdfHC+IZaqrvAKBZswxH ZEHDoSpX5qz+WpWCFVSCKWohJxi6Z1sYwVyr8VscAj1kpxO24luTNVyFxK2monIahzo5Uy p0X47WlwQ+8azkc9LSUNWUW+Yp22NWwcJThmZ9axkz0M8Dx6If0zZxpGlz9IkQoXhyCS6c O3LHInM2/luKAnf+jkGT3lxHrtm80ZLeqq7MLm/K/lhNkdLylVzMqehsWJD2gC78/ubF21 5em7S18zMuf9XeSxmCv4p3L4Oq+2sCPHwsikbceCmGhzLbrCNcHOWMCgzWYl1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668795981; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=HF/2SNMuzl1Wwfpgm1+JbUY/cPTJvyKiJ3QwabWiyXY=; b=Aubjf5uQMPapU8p//5JdafG70862ZMj9KQbKO4uKxMGaBF87QvEUbnB8x8KlcCNb2k9tn5 XxtUKrDWsMo3jJP1W/A+4+DTUwj+Nfoam2f8MGXWZsMHm3PZndXy8/La+pVrO5y2PGHlHs et7wET8PSGJG+lq0ODGirTnx59d4er9V8OkZjp3xmoUt7HtKNl7tatsj/uEOFuFyJOgn+Z Gy9Zk/N1PMJFZ3YRAK2HcStbly+dCuflRiDOQHO1lsaC9Ex4IXECXiS2xRWm5v4f89mRLD mEQeY5SsmN7BAduefapnEF9M/hikMfa/gbEe6cJK7WmS6QZl282OaH1148D5vA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1668795981; a=rsa-sha256; cv=none; b=UdGvB71gLVSXxrIv4jhZQLFgperNN69DbE9hwEGSphVeZTQz2VM9FSukNOV0Pa8pSRVy0a zYA3FAKhRPfv45rYFQR6c2s9q/ljmwURLSLY5DP+6R0BHn2kCVgW4HERh+kLnP7YPZPH6J EEzbHoOrX3ollUk4SXbOptXopObTJjE8Pgv+NTK8ilCkMKH28ZNY1BV/ztO1kFueOg6YR3 RyIG/Iv7TW4PKYRjjO75Yppwen/4lOGfBA0G1VP+Logs74QHW12Nh8BoVgPwBxRoQJxe10 3r86n6EiCOwfIoiYcG6AbnM8nVJGaL9ykjlKGBO64HrVPqQJXVh59ui3xXdUTA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NDQGP4HPGzFVm; Fri, 18 Nov 2022 18:26:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2AIIQLVF029858; Fri, 18 Nov 2022 18:26:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AIIQLLi029857; Fri, 18 Nov 2022 18:26:21 GMT (envelope-from git) Date: Fri, 18 Nov 2022 18:26:21 GMT Message-Id: <202211181826.2AIIQLLi029857@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: a7db532e3a6f - main - vmm: Simplify saving of absolute TSC values in snapshots. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a7db532e3a6f83067b342f569b56076d011f8a1e Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=a7db532e3a6f83067b342f569b56076d011f8a1e commit a7db532e3a6f83067b342f569b56076d011f8a1e Author: John Baldwin AuthorDate: 2022-11-18 17:57:29 +0000 Commit: John Baldwin CommitDate: 2022-11-18 18:25:34 +0000 vmm: Simplify saving of absolute TSC values in snapshots. Read the current "now" TSC value and use it to compute absolute time saved value in vm_snapshot_vcpus rather than iterating over vCPUs multiple times in vm_snapshot_vm. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37146 --- sys/amd64/vmm/vmm.c | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c index dc6e03303b44..124fffec0d9e 100644 --- a/sys/amd64/vmm/vmm.c +++ b/sys/amd64/vmm/vmm.c @@ -2804,10 +2804,12 @@ VMM_STAT_FUNC(VMM_MEM_WIRED, "Wired memory", vm_get_wiredcnt); static int vm_snapshot_vcpus(struct vm *vm, struct vm_snapshot_meta *meta) { + uint64_t tsc, now; int ret; int i; struct vcpu *vcpu; + now = rdtsc(); for (i = 0; i < VM_MAXCPU; i++) { vcpu = &vm->vcpu[i]; @@ -2819,13 +2821,15 @@ vm_snapshot_vcpus(struct vm *vm, struct vm_snapshot_meta *meta) SNAPSHOT_VAR_OR_LEAVE(vcpu->guest_xcr0, meta, ret, done); SNAPSHOT_VAR_OR_LEAVE(vcpu->exitinfo, meta, ret, done); SNAPSHOT_VAR_OR_LEAVE(vcpu->nextrip, meta, ret, done); - /* XXX we're cheating here, since the value of tsc_offset as - * saved here is actually the value of the guest's TSC value. + + /* + * Save the absolute TSC value by adding now to tsc_offset. * * It will be turned turned back into an actual offset when the * TSC restore function is called */ - SNAPSHOT_VAR_OR_LEAVE(vcpu->tsc_offset, meta, ret, done); + tsc = now + vcpu->tsc_offset; + SNAPSHOT_VAR_OR_LEAVE(tsc, meta, ret, done); } done: @@ -2836,33 +2840,10 @@ static int vm_snapshot_vm(struct vm *vm, struct vm_snapshot_meta *meta) { int ret; - int i; - uint64_t now; - - ret = 0; - now = rdtsc(); - - if (meta->op == VM_SNAPSHOT_SAVE) { - /* XXX make tsc_offset take the value TSC proper as seen by the - * guest - */ - for (i = 0; i < VM_MAXCPU; i++) - vm->vcpu[i].tsc_offset += now; - } ret = vm_snapshot_vcpus(vm, meta); - if (ret != 0) { - printf("%s: failed to copy vm data to user buffer", __func__); + if (ret != 0) goto done; - } - - if (meta->op == VM_SNAPSHOT_SAVE) { - /* XXX turn tsc_offset back into an offset; actual value is only - * required for restore; using it otherwise would be wrong - */ - for (i = 0; i < VM_MAXCPU; i++) - vm->vcpu[i].tsc_offset -= now; - } done: return (ret);