From nobody Thu Jan 26 22:11:35 2023 X-Original-To: dev-commits-src-branches@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 4P2w0R2LhKz3c7xn; Thu, 26 Jan 2023 22:11:35 +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 4P2w0R1p11z3tgs; Thu, 26 Jan 2023 22:11:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674771095; 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=d1T21tW/+UrcQXx+T5/8VkmhbH2K6B8U4M8NZnWiq+I=; b=pC3W5exzY2zJfYFqLC/lTlK/B9dxGL08qoR2XYA8kcVmo6OoYW3+s/+oJRAc5kO2mzWduJ oRGY0g1asLAAZUUjirQ34GK9eB/d9Re9gBBavjMJCEW5e50gyXUVzgqV03pA8mJYEgPyIw xCHdrFnVuXi+hoNEuPO0fKyGz7bYK4mhVAcaLaqdt/j5gEuQfEegPaVSpUjAxQaiHD/KnM XHDoUN99qzTyYHPskD9RNqnfNtEpBQIBtmZ3BovM69eAGg/JHqGEOpAvvghgcPl8fDQ6RY +zdff99y7z5W1TGiglXy/92YF21hsLUiYf5n1hj6d7UoINqxs+PP3JQHJdA/vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674771095; 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=d1T21tW/+UrcQXx+T5/8VkmhbH2K6B8U4M8NZnWiq+I=; b=vs8xCuHgYwfTc9IxW4FBH5fjPTwxlhiZD5yI9T73KfNIfZE5QhXlCZ5Wdzt5Jm0cF5FGiK ncUaz4TIfcqY1PBDUOdUJiHSy46Z5UShVUqQiKpQ056IFjNeVmWocVTan/i1fIUQcfAXLp Mi/+Mp9Yk1tJ/Ig1SECiUC7h3JNTb5FPFWHykRYnMEL3ZIPZn7egVl+7RYRpDg/3DiB6iD 7C7gh7yNU+VQIDa5JMpS54sab885kZ/Mk8ehTuSHEb1XfLjEiWsc0fSXyZKbXs/LQ6h+1C 06ffrXNWcrwoYK9HdmLhG16kYb6JT7+ucWsHA7b2uyw7MCgUY0oAkgkMT8sPTg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674771095; a=rsa-sha256; cv=none; b=QqPxXNBM9AYxkPku4O5j8xAeablHDqIcSvoBUuR+1T/MANq/8CyYODF6r6P0QxfzosqLd4 55fGlTvislWlBFE7GeU3rYPAzfjNY0zMApfYOeKv8wf6/GCYe3ae+MYsNdy/lpyl1x86eJ HBjeb7c0I4U4d1NFTbBJaE8XRPjD4PKE6r5fG+uJLkecIxPxsYY4o1VsYa+UVFotIQ+KUD WwxAFDNtKQjG/RYRZz7UHFg7qFJUDb29Q5cqd7JZ+mxwzjciHCqiEIFUrd7KM23SEno/8y wJ9suvFRybIg1WArNdzd4ka6CCKDGRaLiRokGehZd2fgdgpIs9iyRUPlX8HUuA== 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 4P2w0R0sFJzlX0; Thu, 26 Jan 2023 22:11:35 +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 30QMBZt2018451; Thu, 26 Jan 2023 22:11:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30QMBZp8018450; Thu, 26 Jan 2023 22:11:35 GMT (envelope-from git) Date: Thu, 26 Jan 2023 22:11:35 GMT Message-Id: <202301262211.30QMBZp8018450@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: a8ffb1a17ce3 - stable/13 - vmm: Simplify saving of absolute TSC values in snapshots. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: a8ffb1a17ce31c0ec60ec220f79e4eaeefe99aaa Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=a8ffb1a17ce31c0ec60ec220f79e4eaeefe99aaa commit a8ffb1a17ce31c0ec60ec220f79e4eaeefe99aaa Author: John Baldwin AuthorDate: 2022-11-18 17:57:29 +0000 Commit: John Baldwin CommitDate: 2023-01-26 21:43:22 +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 (cherry picked from commit a7db532e3a6f83067b342f569b56076d011f8a1e) --- 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 90edfbe7673c..3ec34a1f3336 100644 --- a/sys/amd64/vmm/vmm.c +++ b/sys/amd64/vmm/vmm.c @@ -2802,10 +2802,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]; @@ -2817,13 +2819,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: @@ -2834,33 +2838,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);