From patchwork Wed Aug 4 08:58:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12418181 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=-17.4 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, URIBL_BLOCKED,USER_AGENT_GIT 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 2804DC4338F for ; Wed, 4 Aug 2021 09:05:30 +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 E331C60E52 for ; Wed, 4 Aug 2021 09:05:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E331C60E52 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:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=i1MbHymrRhH+sEr0qwUSwGpd6EWk57QMidBkDGQLXAg=; b=2zeB7b376lCZE0eqI6GN/xWVi9 oZw8vtFbDgoWMx9o4FzsXD/9vq/FPxS3Vt2eJIFNqm5CorxSpeMJSTvTjFh1zulKmqdzQbQhFe0Mn Cn1DSqpjkrUEHMFKSmU6rKy6NX+wCHqFjvBJ+0AfoRib/IpUSj5hIQvm3jpWrlpP2In4vtl4uCVYa 8dwmYp82JtYLpiBO1wvA3BT8Hq/x8wJ2PneOd9WdjYrdLqkVeP/RZyqVIEPOlz/QlEgQ+miXoHx+x U6Pd/AmhCT1Et2HFTZ/R7xCPEwhjQetpIwmw+BNu6b3mM0IHmtpLA7G7VfN6RePsjFPeTZRYZYhp+ +Evcrmdw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mBCo5-005Hst-9W; Wed, 04 Aug 2021 09:03:22 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mBCjg-005FbV-Go for linux-arm-kernel@lists.infradead.org; Wed, 04 Aug 2021 08:58:49 +0000 Received: by mail-yb1-xb49.google.com with SMTP id w200-20020a25c7d10000b02905585436b530so2196888ybe.21 for ; Wed, 04 Aug 2021 01:58:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=35TVCGaSXP1YX+xl0ynmypPjFUwRXJIFcUTUP7y3OEA=; b=uZnF95SUd8tPNPh9UDFmW/BkibQwuIqjWxF/hBpRgMBadermRtPRVOXDB9dmgoECSE FKyGfmtyrLDrsggccC+Bh3D5G2gELbtHa3uN0XfY5JKG0ECY2NshKN8FbWDsmNi36LEb ctSbdLL+8gkNDC+TlCJ0gt0RNoAPIKSkADIlXB6qQ9GqhxXiuP9bYTOxBYCK/0CJbLyX OMo5Qd7rEVm7l+Vl0r9z9VADsMHVwgRinpxvMjgoANM3sIcdXewmA5o0ijE8KaMaarny i6gAvU3WwVGrOeGLvkW/NqGz11SdqskIEqbf4Vm2r99E0OmmNmyy0TLewqXP11d4sUzL O8HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=35TVCGaSXP1YX+xl0ynmypPjFUwRXJIFcUTUP7y3OEA=; b=WI5KY+ZF/K6KpozhqGFb+w45miKU+6pwKkEBv5nDJ3CpzmWA3aKc8YnZZy0i7jpvJl TynYLTPNUf7wJocShNzyFbl6tHem1prl1biLe9JoYLfsrsLGN0Gx9QGFGFjK7yeCqiNN ZgxOfvzFUIbRssJbKCYYELNmIp8Sly3egSQEnxV7kWiNeH1KnIBZSMnFpXraNp94IV+z ZVAzSo0c36EV9f9OLFv31GtdQwAVJUa041dbG7DqAKi2pM7CsCB2UNijog0dumKzVdGy SapTqkvHXcYPwZ5QXE7cKia+DTWQSfsgikIL6DBB3wN9nDESQOBs2bHm7SzngKaUYQnT juCA== X-Gm-Message-State: AOAM532whrG5buJ7bulpxyjcpkjNtLySE+T5oKLj978bzzRpzJbQfdtm gYcNWXmakSSM751P1xn4TIdFmimdil4= X-Google-Smtp-Source: ABdhPJwQw2VG+2wPW9YYVkLKNHJyZLMCee16q7ggjAFKp03Ugn+6tAxy0sKWEOCLAMhlJGHciviyBhrNI/s= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a25:8010:: with SMTP id m16mr34219421ybk.210.1628067526796; Wed, 04 Aug 2021 01:58:46 -0700 (PDT) Date: Wed, 4 Aug 2021 08:58:09 +0000 In-Reply-To: <20210804085819.846610-1-oupton@google.com> Message-Id: <20210804085819.846610-12-oupton@google.com> Mime-Version: 1.0 References: <20210804085819.846610-1-oupton@google.com> X-Mailer: git-send-email 2.32.0.605.g8dce9f2422-goog Subject: [PATCH v6 11/21] KVM: arm64: Refactor update_vtimer_cntvoff() From: Oliver Upton To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: Paolo Bonzini , Sean Christopherson , 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 , Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210804_015848_603920_C3E18B6B X-CRM114-Status: GOOD ( 12.78 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Make the implementation of update_vtimer_cntvoff() generic w.r.t. guest timer context and spin off into a new helper method for later use. Require callers of this new helper method to grab the kvm lock beforehand. No functional change intended. Signed-off-by: Oliver Upton Reviewed-by: Andrew Jones --- arch/arm64/kvm/arch_timer.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c index 3df67c127489..c0101db75ad4 100644 --- a/arch/arm64/kvm/arch_timer.c +++ b/arch/arm64/kvm/arch_timer.c @@ -747,22 +747,32 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu) return 0; } -/* Make the updates of cntvoff for all vtimer contexts atomic */ -static void update_vtimer_cntvoff(struct kvm_vcpu *vcpu, u64 cntvoff) +/* Make offset updates for all timer contexts atomic */ +static void update_timer_offset(struct kvm_vcpu *vcpu, + enum kvm_arch_timers timer, u64 offset) { int i; struct kvm *kvm = vcpu->kvm; struct kvm_vcpu *tmp; - mutex_lock(&kvm->lock); + lockdep_assert_held(&kvm->lock); + kvm_for_each_vcpu(i, tmp, kvm) - timer_set_offset(vcpu_vtimer(tmp), cntvoff); + timer_set_offset(vcpu_get_timer(tmp, timer), offset); /* * When called from the vcpu create path, the CPU being created is not * included in the loop above, so we just set it here as well. */ - timer_set_offset(vcpu_vtimer(vcpu), cntvoff); + timer_set_offset(vcpu_get_timer(vcpu, timer), offset); +} + +static void update_vtimer_cntvoff(struct kvm_vcpu *vcpu, u64 cntvoff) +{ + struct kvm *kvm = vcpu->kvm; + + mutex_lock(&kvm->lock); + update_timer_offset(vcpu, TIMER_VTIMER, cntvoff); mutex_unlock(&kvm->lock); }