Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752665AbdLHRjc (ORCPT ); Fri, 8 Dec 2017 12:39:32 -0500 Received: from mail-ve1eur02hn0228.outbound.protection.outlook.com ([104.47.6.228]:63097 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752003AbdLHRj3 (ORCPT ); Fri, 8 Dec 2017 12:39:29 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Date: Fri, 8 Dec 2017 20:39:10 +0300 From: Roman Kagan To: Vitaly Kuznetsov Cc: kvm@vger.kernel.org, x86@kernel.org, Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "Michael Kelley (EOSG)" , Andy Lutomirski , Mohammed Gamal , Cathy Avery , linux-kernel@vger.kernel.org, devel@linuxdriverproject.org Subject: Re: [PATCH 6/6] x86/kvm: support Hyper-V reenlightenment Message-ID: <20171208173909.GA4777@rkaganb.sw.ru> Mail-Followup-To: Roman Kagan , Vitaly Kuznetsov , kvm@vger.kernel.org, x86@kernel.org, Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "Michael Kelley (EOSG)" , Andy Lutomirski , Mohammed Gamal , Cathy Avery , linux-kernel@vger.kernel.org, devel@linuxdriverproject.org References: <20171208105000.25116-1-vkuznets@redhat.com> <20171208105000.25116-7-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171208105000.25116-7-vkuznets@redhat.com> User-Agent: Mutt/1.9.1 (2017-09-22) X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR05CA0153.eurprd05.prod.outlook.com (2603:10a6:7:28::40) To HE1PR08MB0844.eurprd08.prod.outlook.com (2a01:111:e400:59b2::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 37cf5263-090a-4b8d-842d-08d53e6299d5 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(7168020)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307);SRVR:HE1PR08MB0844; X-Microsoft-Exchange-Diagnostics: 1;HE1PR08MB0844;3:ELMLGMj4H56wDn2DsQzBOkQOuy1ZcfDYZIFTEmXNpbVbWiYJ+cuVnmJs32Ie5bUnrjlqHU1SRVmCuRZwgLrmNviVfIKkcHTSlL2BZYidEGpj5RM50nDgprtBkw5kzVZycM0j5daaTbSI7b92lMi7jwADHhf2YtAyBouSNiNzXsb7R36r4uhYrv/HpzYPv9Y1iXF/vt+xdwB11miX2DjgQezU0HqAd6K/XLbMMzHo63G4D0HC+/OqFJGT9bl8YVtS;25:+XOn70XlWfY239WwN/KackNvX9AzFjddt+1q3VB1hl9HV3Z/RgqFibUPgUaStcwNcjEH7pYLgUcCnzacxEksxlXfRYNVoazhxAXCrGYW0+Ok26LQZdrc2yABI2J2eF2vvY+Pljijq3qIEhlU4PXO7orIn+HCL+WqWi8XdilD0f5ZVcOwn6MQCSCixE6kSY1GrYStuRF8ftM6XwGtPSz5OV0QX+ffQeT6XKlLO+id9PexB7CPpSvfFGSI6tRLcRs5+HG8nWhYn9Oy3ca/VaKt95+PaWJytgVo2QWbQ+nUDNldNHpjfdMconHCqy6cHLYyOXD727MMsMDEXvUcKcVeUQ==;31:5v1Ph3qjxRH1S9lFHoZ4Q9sTgQjuq5V7WgTNYZ9x7Kf0WaZFVDwDTr2ZWqVNqXaS7LG3CCBYIfpbb9UqwXS8VhHoT/hu4jyIRbm4yf+DCO3Q8BfKUbwMdfYcXRZw0rgWzgRF5Sc0CTgLTfMakEaejXCx7eyMKoeKyXNtYyv3iAuo6zM9PyGIw7NucIp97hGHC8qVMI/LEYj1CkVCMXBvU62NlPFQNFRVmNNMMocizcI= X-MS-TrafficTypeDiagnostic: HE1PR08MB0844:|HE1PR08MB0844: X-Microsoft-Exchange-Diagnostics: 1;HE1PR08MB0844;20:EI+VHlqOEM3ABuK4SoD/9nJIDW4Xn0UUACb3jqBeAayUwoXHn7OvByNkwiAnakypg2qXpaJQE3omriKFzaDFqh2SookTqK+Q53aV5g0PQh8KQisfKNx+91BY9rj06Qzh6omC4rXhzBPVwc/JlURsb08qiwtLbrtIreRe6Hujt0WtwYtDfiemPjwzEZ4NQcUASzMy62Okh2oybgsiocHZB3V6lZydLJG2sEVvGgr8FxcGiSa6Qte1r1+8OyRSTrShPixSkNaC1yrSBzjRXXTKqDlnHlszGvUNj0DPzN7521t6DJk12xiupbboEDrdssk6kNMk9FQUq030jSM8kISTuIPWISPQryiuUbFNRp+l1yx06bCwv6S7XZjZn6dnilUHE5jQtNhHKFgJJ+AwcnYM+9Jx2/F+Lu96zSHoO5fig04=;4:GMivbpozY9rWszNqLRAkm0JI6ZO+z9OW+Aa5u0SDir/egTo8b4AOuFs7Xun41nuWYYiP0WDN1JFepTWD2K6M5zsnDC/giN9xdaHg2jT86CXo/wo0gMLSt6/m9g2mqY9krBcFBOTWqGfh0aecA8eViDn174TxVLu1bfPBa4kzDO0M7af795KNOhCBSi/lzvyQjXjgjShqysCi+XURzJo16Wn4H3D4+f2TykCGF1AOo9tYJH2rnlBKtsSwLaSsOmhA35zS023EPOOIMlt09ofFXw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231022)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123555025)(20161123564025)(20161123562025)(20161123560025)(6072148)(201708071742011);SRVR:HE1PR08MB0844;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:HE1PR08MB0844; X-Forefront-PRVS: 0515208626 X-Forefront-Antispam-Report: SFV:SPM;SFS:(10019020)(346002)(376002)(366004)(24454002)(189003)(199004)(1076002)(36756003)(55236003)(23726003)(6116002)(3846002)(7416002)(53936002)(52116002)(7696005)(83506002)(106356001)(58126008)(81156014)(47776003)(316002)(81166006)(16526018)(16586007)(66066001)(7736002)(305945005)(8676002)(54906003)(97736004)(2906002)(105586002)(76176011)(33656002)(9686003)(6506006)(229853002)(8666007)(55016002)(2950100002)(6916009)(6666003)(5660300001)(69596002)(68736007)(6246003)(478600001)(575784001)(25786009)(8936002)(86362001)(4326008)(50466002)(53416004)(30126002);DIR:OUT;SFP:1501;SCL:5;SRVR:HE1PR08MB0844;H:rkaganb.sw.ru;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;HE1PR08MB0844;23:eyywnDUg+G/5BZV9ha63NqSAdXYC1zjQfExG+GTBQ?= =?us-ascii?Q?V8eQidEq9dP+YD2xBwAaD3I0Dk13pZ7LNsOvzyC8GkqlSB4J4P680AAXEScs?= =?us-ascii?Q?BXlqmzQNobrQnqDmQ0lp04Cr9hV2Ndia8vYY30a4krKt17gVbKRws7x3WIbt?= =?us-ascii?Q?2ScICdf2n3qpbC9f5o8o2T/Y60tmPU1H+nrEiUVbzN0yuM5avcbToGhAlta/?= =?us-ascii?Q?kPnBow+UFst7Qn08TJMD/s2sHOuKxZjUZk9tF8HX+z+bVy/+N4jL1L2Gd+qC?= =?us-ascii?Q?0FFwp7NjCQIoigzS+upf5IkiBJ3lOMlli5y5pDYWx+l7TQHn4aGhAzJZ1d98?= =?us-ascii?Q?6iCoGBACEXdcweffsitz+bKnOevmE4Ji/KofFMMv8zRqEkzJ7j+J2XGA11nm?= =?us-ascii?Q?vXY6pIUT84ZgI7J3h2mhYiDL3NGSmSLzlUaSExpdef8eYR2QQCs0BSXZL+QG?= =?us-ascii?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ixumpPiPj6JKWLDGc4vOF3XY2yiAyNGclJIbpAd5FWevA6XZC0iXGG7e3cKdAXGm5C8aEsDgbmOGVeeS6MiYJh64mWE4wPyEjHpS/10151my1dniqJxhtHs5QqPbA+OV4= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2017 17:39:14.5948 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 37cf5263-090a-4b8d-842d-08d53e6299d5 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR08MB0844 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2385 Lines: 75 On Fri, Dec 08, 2017 at 11:50:00AM +0100, Vitaly Kuznetsov wrote: > When we run nested KVM on Hyper-V guests we need to update masterclocks for > all guests when L1 migrates to a host with different TSC frequency. > Implement the procedure in the following way: > - Pause all guests. > - Tell our host (Hyper-V) to stop emulating TSC accesses. > - Update our gtod copy, recompute clocks. > - Unpause all guests. > > This is somewhat similar to cpufreq but we have two important differences: > we can only disable TSC emulation globally (on all CPUs) and we don't know > the new TSC frequency until we turn the emulation off so we can't > 'prepare' ourselves to the event. > > Signed-off-by: Vitaly Kuznetsov > --- > arch/x86/kvm/x86.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 45 insertions(+) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 96e04a0cb921..04d90712ffd2 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -68,6 +68,7 @@ > #include > #include > #include > +#include > > #define CREATE_TRACE_POINTS > #include "trace.h" > @@ -5946,6 +5947,43 @@ static void tsc_khz_changed(void *data) > __this_cpu_write(cpu_tsc_khz, khz); > } > > +void kvm_hyperv_tsc_notifier(void) > +{ > +#ifdef CONFIG_X86_64 > + struct kvm *kvm; > + struct kvm_vcpu *vcpu; > + int cpu; > + > + spin_lock(&kvm_lock); > + list_for_each_entry(kvm, &vm_list, vm_list) > + kvm_make_mclock_inprogress_request(kvm); > + > + hyperv_stop_tsc_emulation(); > + > + /* TSC frequency always matches when on Hyper-V */ > + for_each_present_cpu(cpu) > + per_cpu(cpu_tsc_khz, cpu) = tsc_khz; > + kvm_max_guest_tsc_khz = tsc_khz; > + > + list_for_each_entry(kvm, &vm_list, vm_list) { > + struct kvm_arch *ka = &kvm->arch; > + > + spin_lock(&ka->pvclock_gtod_sync_lock); > + > + pvclock_update_vm_gtod_copy(kvm); > + > + kvm_for_each_vcpu(cpu, vcpu, kvm) > + kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu); > + > + kvm_for_each_vcpu(cpu, vcpu, kvm) > + kvm_clear_request(KVM_REQ_MCLOCK_INPROGRESS, vcpu); > + > + spin_unlock(&ka->pvclock_gtod_sync_lock); > + } > + spin_unlock(&kvm_lock); Can't you skip all this if the tsc frequency hasn't changed (which should probably be the case when the CPU supports tsc frequency scaling)? Roman.