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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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 A65F2C433F5 for ; Thu, 2 Sep 2021 19:22:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 810A360F12 for ; Thu, 2 Sep 2021 19:22:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347367AbhIBTXo (ORCPT ); Thu, 2 Sep 2021 15:23:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243832AbhIBTXm (ORCPT ); Thu, 2 Sep 2021 15:23:42 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A7C9C061575 for ; Thu, 2 Sep 2021 12:22:44 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id n18so1832095plp.7 for ; Thu, 02 Sep 2021 12:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=uNPtW+6uA+IorMmx89tZvAje5LA6sRmLTggdZeiUpKQ=; b=DUPBVsET97fo8gZE+12RRIe3oBglmGvYRDpWjPC2p+hbEXLBsAYdQvDjInkq6gYd9W aD0keO3ba193KwUAVcMMcw+goFfB2DAN7bF6mvu7quwJ39X0u0GDdq6d0OOhIGbnCvNx jE0qJTjzRRm6E8cO1WHrwHdmnAAbN2EB+EIKY49b88wbvHWGVELVHCLjaPF8+CX3gjAG a4OToBU85qyLrfFq90ge6iKk8oVInT2Lj4C0lF3v/U7veqJLjRlG/5Jd9L1Rhtw1lTsU qi+PWSS7OrPNvrRmJQp/0Rnc2emt5+f/oh+VuZc/SgzPRcMJG/Qe1jrYCg1dxv07hOOU Ae6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=uNPtW+6uA+IorMmx89tZvAje5LA6sRmLTggdZeiUpKQ=; b=doVj9kbUa84L8/kPCw/R6GszXBriznuTiKnkK2jXvXo0WZRvp95Qm5xt7dX1HINkpB A9sEfFHFCNSam0Qa7rwOjP8YU1NSnh86rOhQz4PsoqH2kyUbJ7YuSZFL/csGUmBD7HG1 ccbAQOHdn/SB5sgQrFIcRh4EnM3Ck8hkVJsEXetNhkcO2mx0WPtXOKYPSRrqUJa+lGiD oJTfhDGWSEiqNnaKJUdmIvT6rsOV3NQVvEMXzVPP5d2YT4udzDlF+kq8aka24Q+FkIvA DCw86KxD4Qg4eQysS4sQqyiRwNlWlqSKr/0JwfRqK+HosSPn6yq8D4LAMfXRkTY8RAHr CWcA== X-Gm-Message-State: AOAM531hAXyDThUkT6sIjvlLWLkIHRuMnRRvUoYvhETAh1HGTm2ylDfv MOOvZUVW4tQV/wq8e3fQujV3BQ== X-Google-Smtp-Source: ABdhPJyA+Ul43RLuBvaJkLgS2mR6ljKmyKfNqIQzvT0/kC56lZBa3GlaBfo3GRItE1F4k7nstvQBhg== X-Received: by 2002:a17:90a:ad02:: with SMTP id r2mr5529728pjq.182.1630610563431; Thu, 02 Sep 2021 12:22:43 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id x75sm3674726pgx.43.2021.09.02.12.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 12:22:42 -0700 (PDT) Date: Thu, 2 Sep 2021 19:22:39 +0000 From: Sean Christopherson To: Oliver Upton Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Paolo Bonzini , 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 Subject: Re: [PATCH v7 4/6] KVM: x86: Take the pvclock sync lock behind the tsc_write_lock Message-ID: References: <20210816001130.3059564-1-oupton@google.com> <20210816001130.3059564-5-oupton@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210816001130.3059564-5-oupton@google.com> Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Mon, Aug 16, 2021, Oliver Upton wrote: > A later change requires that the pvclock sync lock be taken while > holding the tsc_write_lock. Change the locking in kvm_synchronize_tsc() > to align with the requirement to isolate the locking change to its own > commit. > > Cc: Sean Christopherson > Signed-off-by: Oliver Upton > --- > Documentation/virt/kvm/locking.rst | 11 +++++++++++ > arch/x86/kvm/x86.c | 2 +- > 2 files changed, 12 insertions(+), 1 deletion(-) > > diff --git a/Documentation/virt/kvm/locking.rst b/Documentation/virt/kvm/locking.rst > index 8138201efb09..0bf346adac2a 100644 > --- a/Documentation/virt/kvm/locking.rst > +++ b/Documentation/virt/kvm/locking.rst > @@ -36,6 +36,9 @@ On x86: > holding kvm->arch.mmu_lock (typically with ``read_lock``, otherwise > there's no need to take kvm->arch.tdp_mmu_pages_lock at all). > > +- kvm->arch.tsc_write_lock is taken outside > + kvm->arch.pvclock_gtod_sync_lock > + > Everything else is a leaf: no other lock is taken inside the critical > sections. > > @@ -222,6 +225,14 @@ time it will be set using the Dirty tracking mechanism described above. > :Comment: 'raw' because hardware enabling/disabling must be atomic /wrt > migration. > > +:Name: kvm_arch::pvclock_gtod_sync_lock > +:Type: raw_spinlock_t > +:Arch: x86 > +:Protects: kvm_arch::{cur_tsc_generation,cur_tsc_nsec,cur_tsc_write, > + cur_tsc_offset,nr_vcpus_matched_tsc} > +:Comment: 'raw' because updating the kvm master clock must not be > + preempted. > + > :Name: kvm_arch::tsc_write_lock > :Type: raw_spinlock > :Arch: x86 > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index b1e9a4885be6..f1434cd388b9 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -2533,7 +2533,6 @@ static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 data) > vcpu->arch.this_tsc_write = kvm->arch.cur_tsc_write; > > kvm_vcpu_write_tsc_offset(vcpu, offset); > - raw_spin_unlock_irqrestore(&kvm->arch.tsc_write_lock, flags); > > spin_lock_irqsave(&kvm->arch.pvclock_gtod_sync_lock, flags); > if (!matched) { > @@ -2544,6 +2543,7 @@ static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 data) > > kvm_track_tsc_matching(vcpu); > spin_unlock_irqrestore(&kvm->arch.pvclock_gtod_sync_lock, flags); Drop the irqsave/irqrestore in this patch instead of doing so while refactoring the code in the next patch. > + raw_spin_unlock_irqrestore(&kvm->arch.tsc_write_lock, flags); > } > > static inline void adjust_tsc_offset_guest(struct kvm_vcpu *vcpu, > -- > 2.33.0.rc1.237.g0d66db33f3-goog > 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=-14.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 DB572C433EF for ; Thu, 2 Sep 2021 19:25:41 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AC09B60F21 for ; Thu, 2 Sep 2021 19:25:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AC09B60F21 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Pfb1oJgm1GsplUldnHsNtwcEvyQ1p9aoEbuNHwx3/2E=; b=GHTifFcuEtOeeh Q1o/tuvxpuX+0mafJj27vtgv7FKvrWxtQ5Avd9UiydUs3r8xSTSNfV+5eFuqiwoO+jLp0WCLeqOwa hV0gVO8vHrZRXn0QxfNsb1H0FFZvPPcs+U+KtwIACzIVGI+M3km87XVGPRN/l3ka0I9zwf7eVNVc8 Gf6sG4sPJlmh5OL7vTHZA/D7UQ2Mm/w/ZmkEfDE/8oY+pgKH4qfaYOb5pr1UIcB71lsKhfh7WW6mz 7gMSpWjV9RIhEs1pn1yW9FiYaNMkWDoyw5sRo3x5PsXi++nObFdhSzYYL+8ooWaqxdfQnvUS+g2so UaMQOb0HyaPufAn1Cjaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mLsIS-00AMA5-QB; Thu, 02 Sep 2021 19:22:48 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mLsIO-00AM9E-PB for linux-arm-kernel@lists.infradead.org; Thu, 02 Sep 2021 19:22:46 +0000 Received: by mail-pl1-x62a.google.com with SMTP id m17so1830372plc.6 for ; Thu, 02 Sep 2021 12:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=uNPtW+6uA+IorMmx89tZvAje5LA6sRmLTggdZeiUpKQ=; b=DUPBVsET97fo8gZE+12RRIe3oBglmGvYRDpWjPC2p+hbEXLBsAYdQvDjInkq6gYd9W aD0keO3ba193KwUAVcMMcw+goFfB2DAN7bF6mvu7quwJ39X0u0GDdq6d0OOhIGbnCvNx jE0qJTjzRRm6E8cO1WHrwHdmnAAbN2EB+EIKY49b88wbvHWGVELVHCLjaPF8+CX3gjAG a4OToBU85qyLrfFq90ge6iKk8oVInT2Lj4C0lF3v/U7veqJLjRlG/5Jd9L1Rhtw1lTsU qi+PWSS7OrPNvrRmJQp/0Rnc2emt5+f/oh+VuZc/SgzPRcMJG/Qe1jrYCg1dxv07hOOU Ae6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=uNPtW+6uA+IorMmx89tZvAje5LA6sRmLTggdZeiUpKQ=; b=toRvswb8sjk1ueGhe1DlbTxV65mr/zmXtSN5Gh41W1y4OTOIM8wccY/iLf/rtKKJ+Q 8F3Fw4zMBF8rk/HkjoDjiCISuvlJJsxXBz3Mk2b0vL0lNxkID3AtJq55OSScWOb/svRm lcffsSo1ymjziiJBpgUt671eTX0xEX32NkWPfk6vXu9pyjFHEszZM02Lm3o2DupOPASl QbZw3VyS7+Wr9/SMEoyrIDV2Wj59xxNiy5DJBocWek1vZNM0SZi/3zcH6pJRM1T50Bg8 AE6TmGVIXKmussIjpWf/9CVxmqlwg8O4dQCDQOWZK1tcu20EPlZ8XyWGKeHNn2pcKtzT hVbw== X-Gm-Message-State: AOAM5307BPH1+yvUH19L4xvxEtnmK0Gm2N7uSF6b5vESg5MGkAH3NZnr xD71ka36AFQz9aceS9eOOQLy1A== X-Google-Smtp-Source: ABdhPJyA+Ul43RLuBvaJkLgS2mR6ljKmyKfNqIQzvT0/kC56lZBa3GlaBfo3GRItE1F4k7nstvQBhg== X-Received: by 2002:a17:90a:ad02:: with SMTP id r2mr5529728pjq.182.1630610563431; Thu, 02 Sep 2021 12:22:43 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id x75sm3674726pgx.43.2021.09.02.12.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 12:22:42 -0700 (PDT) Date: Thu, 2 Sep 2021 19:22:39 +0000 From: Sean Christopherson To: Oliver Upton Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Paolo Bonzini , 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 Subject: Re: [PATCH v7 4/6] KVM: x86: Take the pvclock sync lock behind the tsc_write_lock Message-ID: References: <20210816001130.3059564-1-oupton@google.com> <20210816001130.3059564-5-oupton@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210816001130.3059564-5-oupton@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210902_122244_870721_11E32476 X-CRM114-Status: GOOD ( 22.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Aug 16, 2021, Oliver Upton wrote: > A later change requires that the pvclock sync lock be taken while > holding the tsc_write_lock. Change the locking in kvm_synchronize_tsc() > to align with the requirement to isolate the locking change to its own > commit. > > Cc: Sean Christopherson > Signed-off-by: Oliver Upton > --- > Documentation/virt/kvm/locking.rst | 11 +++++++++++ > arch/x86/kvm/x86.c | 2 +- > 2 files changed, 12 insertions(+), 1 deletion(-) > > diff --git a/Documentation/virt/kvm/locking.rst b/Documentation/virt/kvm/locking.rst > index 8138201efb09..0bf346adac2a 100644 > --- a/Documentation/virt/kvm/locking.rst > +++ b/Documentation/virt/kvm/locking.rst > @@ -36,6 +36,9 @@ On x86: > holding kvm->arch.mmu_lock (typically with ``read_lock``, otherwise > there's no need to take kvm->arch.tdp_mmu_pages_lock at all). > > +- kvm->arch.tsc_write_lock is taken outside > + kvm->arch.pvclock_gtod_sync_lock > + > Everything else is a leaf: no other lock is taken inside the critical > sections. > > @@ -222,6 +225,14 @@ time it will be set using the Dirty tracking mechanism described above. > :Comment: 'raw' because hardware enabling/disabling must be atomic /wrt > migration. > > +:Name: kvm_arch::pvclock_gtod_sync_lock > +:Type: raw_spinlock_t > +:Arch: x86 > +:Protects: kvm_arch::{cur_tsc_generation,cur_tsc_nsec,cur_tsc_write, > + cur_tsc_offset,nr_vcpus_matched_tsc} > +:Comment: 'raw' because updating the kvm master clock must not be > + preempted. > + > :Name: kvm_arch::tsc_write_lock > :Type: raw_spinlock > :Arch: x86 > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index b1e9a4885be6..f1434cd388b9 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -2533,7 +2533,6 @@ static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 data) > vcpu->arch.this_tsc_write = kvm->arch.cur_tsc_write; > > kvm_vcpu_write_tsc_offset(vcpu, offset); > - raw_spin_unlock_irqrestore(&kvm->arch.tsc_write_lock, flags); > > spin_lock_irqsave(&kvm->arch.pvclock_gtod_sync_lock, flags); > if (!matched) { > @@ -2544,6 +2543,7 @@ static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 data) > > kvm_track_tsc_matching(vcpu); > spin_unlock_irqrestore(&kvm->arch.pvclock_gtod_sync_lock, flags); Drop the irqsave/irqrestore in this patch instead of doing so while refactoring the code in the next patch. > + raw_spin_unlock_irqrestore(&kvm->arch.tsc_write_lock, flags); > } > > static inline void adjust_tsc_offset_guest(struct kvm_vcpu *vcpu, > -- > 2.33.0.rc1.237.g0d66db33f3-goog > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 34292C4332F for ; Thu, 2 Sep 2021 21:01:23 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id D19A261074 for ; Thu, 2 Sep 2021 21:01:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D19A261074 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 730474B10B; Thu, 2 Sep 2021 17:01:22 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IJLRwAvCcDmK; Thu, 2 Sep 2021 17:01:21 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 1138A4B121; Thu, 2 Sep 2021 17:01:20 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 4BAE54B10A for ; Thu, 2 Sep 2021 15:22:46 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cnZkpUFxE2uX for ; Thu, 2 Sep 2021 15:22:44 -0400 (EDT) Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id B4B214A524 for ; Thu, 2 Sep 2021 15:22:44 -0400 (EDT) Received: by mail-pl1-f178.google.com with SMTP id q21so1841205plq.3 for ; Thu, 02 Sep 2021 12:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=uNPtW+6uA+IorMmx89tZvAje5LA6sRmLTggdZeiUpKQ=; b=DUPBVsET97fo8gZE+12RRIe3oBglmGvYRDpWjPC2p+hbEXLBsAYdQvDjInkq6gYd9W aD0keO3ba193KwUAVcMMcw+goFfB2DAN7bF6mvu7quwJ39X0u0GDdq6d0OOhIGbnCvNx jE0qJTjzRRm6E8cO1WHrwHdmnAAbN2EB+EIKY49b88wbvHWGVELVHCLjaPF8+CX3gjAG a4OToBU85qyLrfFq90ge6iKk8oVInT2Lj4C0lF3v/U7veqJLjRlG/5Jd9L1Rhtw1lTsU qi+PWSS7OrPNvrRmJQp/0Rnc2emt5+f/oh+VuZc/SgzPRcMJG/Qe1jrYCg1dxv07hOOU Ae6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=uNPtW+6uA+IorMmx89tZvAje5LA6sRmLTggdZeiUpKQ=; b=mvvF1TBIg63VekM9ONNp1talZ1g2Jzg26va9QpP9PapIf5G09p4nBopCe/2TTARBVW PnZheS3qhCjd2f/zy2gCBipseKfgfOo/D4sQkqjmZ7/AsCqPe5e2bRmTvxhsEVs4sj0R zO87Hs2h4k8+4coNmYM5bmKZqfG8b1Q2ezOBnIS+8DGvfRuakWTS2CZ2HYk96zLW9i8m 12qKybXx+JwmbOPgVzrokLivxm+xUwxyPnx9yblwLmYGgM7C/esq0B+CsMmLz45AgKwX jd2op2J4Sauzoo3Xbldi0ZPWVRksoIybqDBLTWI6ZAzY70+1w+1XFPOBFzICL8HyVA4E 7h4A== X-Gm-Message-State: AOAM530IdhFcdvEi/XWVFAJCh5c9gD17YV77vC4kVHQpAKe1EXq2jAKR RQlP4cb2AVFvfHkEtZQJW8JdGQ== X-Google-Smtp-Source: ABdhPJyA+Ul43RLuBvaJkLgS2mR6ljKmyKfNqIQzvT0/kC56lZBa3GlaBfo3GRItE1F4k7nstvQBhg== X-Received: by 2002:a17:90a:ad02:: with SMTP id r2mr5529728pjq.182.1630610563431; Thu, 02 Sep 2021 12:22:43 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id x75sm3674726pgx.43.2021.09.02.12.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 12:22:42 -0700 (PDT) Date: Thu, 2 Sep 2021 19:22:39 +0000 From: Sean Christopherson To: Oliver Upton Subject: Re: [PATCH v7 4/6] KVM: x86: Take the pvclock sync lock behind the tsc_write_lock Message-ID: References: <20210816001130.3059564-1-oupton@google.com> <20210816001130.3059564-5-oupton@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210816001130.3059564-5-oupton@google.com> X-Mailman-Approved-At: Thu, 02 Sep 2021 17:01:18 -0400 Cc: Catalin Marinas , kvm@vger.kernel.org, Will Deacon , Marc Zyngier , Peter Shier , David Matlack , Paolo Bonzini , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, Jim Mattson X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Mon, Aug 16, 2021, Oliver Upton wrote: > A later change requires that the pvclock sync lock be taken while > holding the tsc_write_lock. Change the locking in kvm_synchronize_tsc() > to align with the requirement to isolate the locking change to its own > commit. > > Cc: Sean Christopherson > Signed-off-by: Oliver Upton > --- > Documentation/virt/kvm/locking.rst | 11 +++++++++++ > arch/x86/kvm/x86.c | 2 +- > 2 files changed, 12 insertions(+), 1 deletion(-) > > diff --git a/Documentation/virt/kvm/locking.rst b/Documentation/virt/kvm/locking.rst > index 8138201efb09..0bf346adac2a 100644 > --- a/Documentation/virt/kvm/locking.rst > +++ b/Documentation/virt/kvm/locking.rst > @@ -36,6 +36,9 @@ On x86: > holding kvm->arch.mmu_lock (typically with ``read_lock``, otherwise > there's no need to take kvm->arch.tdp_mmu_pages_lock at all). > > +- kvm->arch.tsc_write_lock is taken outside > + kvm->arch.pvclock_gtod_sync_lock > + > Everything else is a leaf: no other lock is taken inside the critical > sections. > > @@ -222,6 +225,14 @@ time it will be set using the Dirty tracking mechanism described above. > :Comment: 'raw' because hardware enabling/disabling must be atomic /wrt > migration. > > +:Name: kvm_arch::pvclock_gtod_sync_lock > +:Type: raw_spinlock_t > +:Arch: x86 > +:Protects: kvm_arch::{cur_tsc_generation,cur_tsc_nsec,cur_tsc_write, > + cur_tsc_offset,nr_vcpus_matched_tsc} > +:Comment: 'raw' because updating the kvm master clock must not be > + preempted. > + > :Name: kvm_arch::tsc_write_lock > :Type: raw_spinlock > :Arch: x86 > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index b1e9a4885be6..f1434cd388b9 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -2533,7 +2533,6 @@ static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 data) > vcpu->arch.this_tsc_write = kvm->arch.cur_tsc_write; > > kvm_vcpu_write_tsc_offset(vcpu, offset); > - raw_spin_unlock_irqrestore(&kvm->arch.tsc_write_lock, flags); > > spin_lock_irqsave(&kvm->arch.pvclock_gtod_sync_lock, flags); > if (!matched) { > @@ -2544,6 +2543,7 @@ static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 data) > > kvm_track_tsc_matching(vcpu); > spin_unlock_irqrestore(&kvm->arch.pvclock_gtod_sync_lock, flags); Drop the irqsave/irqrestore in this patch instead of doing so while refactoring the code in the next patch. > + raw_spin_unlock_irqrestore(&kvm->arch.tsc_write_lock, flags); > } > > static inline void adjust_tsc_offset_guest(struct kvm_vcpu *vcpu, > -- > 2.33.0.rc1.237.g0d66db33f3-goog > _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm