From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8464BC433F5 for ; Fri, 24 Sep 2021 09:28:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 691E860FDC for ; Fri, 24 Sep 2021 09:28:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244462AbhIXJaH (ORCPT ); Fri, 24 Sep 2021 05:30:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48978 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237056AbhIXJaG (ORCPT ); Fri, 24 Sep 2021 05:30:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632475712; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IoDPw1naO7tilFKWpbIB0mjp/4gXU+WPMdM7pLJKoHA=; b=MbRw5X8FSltWsEDRR4ZRCNO4lA+g7O/2b7wKNXGBygNFm0v6MOJNs3nTuVP5Wxo+mx2fhZ FGvosjusNakhoRf8/8xxRqm9CXAAAK49DBHWDozcDAVlJJHLreCRlBgBoxRBhBYDuq1BxM nourxBEZtnVYF9e1/YYqEj3EF1urGSg= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-567-SsZmmyQMMgezOYk-3i41DA-1; Fri, 24 Sep 2021 05:28:31 -0400 X-MC-Unique: SsZmmyQMMgezOYk-3i41DA-1 Received: by mail-ed1-f69.google.com with SMTP id h15-20020aa7de0f000000b003d02f9592d6so9578252edv.17 for ; Fri, 24 Sep 2021 02:28:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=IoDPw1naO7tilFKWpbIB0mjp/4gXU+WPMdM7pLJKoHA=; b=Ox7G89R+lASrC0pTXnhvsa9XgeI47GAiwD7MdxudQx09yqY2K1WLiBGpCWUb0SF5UI Up98SH5OCoXNxYN1CiTPXBUn7dsBhK1IDQk5FO8gzjrrG9hLMY8VHO+Ys/g/PB3p9J3n K61gjtDF4LdK0DVI98TItrF6MZfxt0X/r0YTGJ0XGdInQmw/PeVm98+PpdU/QuQA9Xhs 3TzlJ1ZUElZhfHV7OSc5iuWpAv/4bb3MO6EBDPRZG8pxHuyJypHElVdx/t9HQ1GpK8rD hzqP5LH7XpWs/4AGk2POPqSHFlErSsDGBGh6bQjYr5JKUFdJY6jKKMtFqY9RXDNluRy4 2T3g== X-Gm-Message-State: AOAM533/nhDcKZZeswXCFPp3M2LwN6Et8mWHBV3YwKmPkUtfmeOeM51O P00YDjPZ9Tl/zolUoQ9vHd+luiPiVo6hym6WpbLgvCXkVSGBvn3anFSG+XIJm2BCFTWc4ogZgsm 05/Oko8pgsQGH X-Received: by 2002:a05:6402:397:: with SMTP id o23mr3937689edv.59.1632475710477; Fri, 24 Sep 2021 02:28:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxh74xZ8KOA0BU0tWlr2IZ19X6YEnrfIAboOpOI5qSEDDf3VV5te0ekyXZWkyb0hkI6Io5dng== X-Received: by 2002:a05:6402:397:: with SMTP id o23mr3937667edv.59.1632475710253; Fri, 24 Sep 2021 02:28:30 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id b14sm5403970edy.56.2021.09.24.02.28.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Sep 2021 02:28:29 -0700 (PDT) Message-ID: Date: Fri, 24 Sep 2021 11:28:28 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [PATCH v7 5/6] KVM: x86: Refactor tsc synchronization code Content-Language: en-US To: Sean Christopherson , Oliver Upton Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Marc Zyngier , Peter Shier , Jim Mattson , David Matlack , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Andrew Jones , Will Deacon , Catalin Marinas References: <20210816001130.3059564-1-oupton@google.com> <20210816001130.3059564-6-oupton@google.com> From: Paolo Bonzini In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On 02/09/21 21:21, Sean Christopherson wrote: > >> + if (!matched) { >> + ... >> + spin_lock(&kvm->arch.pvclock_gtod_sync_lock); >> + kvm->arch.nr_vcpus_matched_tsc = 0; >> + } else if (!already_matched) { >> + spin_lock(&kvm->arch.pvclock_gtod_sync_lock); >> + kvm->arch.nr_vcpus_matched_tsc++; >> + } >> + >> + kvm_track_tsc_matching(vcpu); >> + spin_unlock(&kvm->arch.pvclock_gtod_sync_lock); > > This unlock is imbalanced if matched and already_matched are both true. It's not > immediately obvious that that_can't_ happen, and if it truly can't happen then > conditionally locking is pointless (because it's not actually conditional). This is IMO another reason to unify tsc_write_lock and pvclock_gtod_sync_lock. The chances of contention are pretty slim. As soon as I sort out the next -rc3 pull request I'll send out my version of Oliver's patches. Thanks, Paolo