From patchwork Thu Oct 5 13:55:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 9987225 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9B11C6029B for ; Thu, 5 Oct 2017 13:56:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B72628C90 for ; Thu, 5 Oct 2017 13:56:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D2FC28C94; Thu, 5 Oct 2017 13:56:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E4F028C90 for ; Thu, 5 Oct 2017 13:56:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751498AbdJENzu (ORCPT ); Thu, 5 Oct 2017 09:55:50 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:34656 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751452AbdJENzp (ORCPT ); Thu, 5 Oct 2017 09:55:45 -0400 Received: by mail-pg0-f66.google.com with SMTP id u27so15661045pgn.1; Thu, 05 Oct 2017 06:55:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nBbwiRKPuJUIg0XG6WQDU7ILy9EG5zgo2nc+jEfCBjg=; b=oW7ZZGbUXYy8DEy+IP2w9RL4pPPVbxIsKM8W8fjkDw7/SiCGS1mhvKHIlrSgVxyGUh qoPKiIiROY4LbuoPjP+c/yJaRb3oGZ1GYl/lGWhZBD1YYc0tbp4lFUD8trTlvCS9XPu5 Zy/VGWZLiwRPvQN5lPqpqqKr0LLFhWavsZeDXshHCLNNVUnQGVMUk5EA5g6qqtG3H30n KIN/eP8MYHvZxwW7uDzEgUIlh01i8PGBGojQoZGl6u9o3quoXbf11bMpFUq5X9ojn9AO CF4kU0et80yrXdPh+XAJO0TP6yEdiqJEf8s09XBcw8U/TZiTKZN+QjTINd7M4wOqUweN 79xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nBbwiRKPuJUIg0XG6WQDU7ILy9EG5zgo2nc+jEfCBjg=; b=njlO4LwH2ibpSK2C+v5BQ+2AFW13W77KxRAE2qtk/lDObPvyUAxjnm06z+/DW8HMg4 JcFcDreaziz4G3rWFlUsd7XLVbFR6tg6815bRTvX8E02qVRfxkMcvKqOXxp8vjL/wvMT yngjUNri/y+2o5/N1PiP8qPvUmSx0Yybd5+WJh2xewFWfKLY97U97gVvefeIni6mXFwP DupS2O5pq7bmyYmY3v8STnTHK8jrygUxc7cqmyWe4aJGVhjoDgRtV5mdA2yGkxwzsWVE 6rJo1SikT/iuFQ1YYXhK2kpFfq7pNKqGQCXnWygQsif0UkGS2eqqf0Y9rOw05evaFpHA IKwA== X-Gm-Message-State: AMCzsaVkVNNTamntvTjnj+gHf0t9EecXESHxmN8vx9UB0HbXFfPcAB5l r7a5gtH5/EWfEwinNJ9kmr9Gfw== X-Google-Smtp-Source: AOwi7QBU8O94v6jqO7Lj7JPM8ZfuT5zhWBzeumqHjlslo3ZoRWVv/1pAMGJNzhwk/8RXSRQ/GuAdAw== X-Received: by 10.98.149.71 with SMTP id p68mr6366331pfd.311.1507211745046; Thu, 05 Oct 2017 06:55:45 -0700 (PDT) Received: from localhost ([223.72.82.149]) by smtp.gmail.com with ESMTPSA id m10sm28768463pgs.77.2017.10.05.06.55.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Oct 2017 06:55:44 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Wanpeng Li Subject: [PATCH v4 2/3] KVM: LAPIC: Keep timer running when switching between one-shot and periodic mode Date: Thu, 5 Oct 2017 06:55:32 -0700 Message-Id: <1507211733-22604-3-git-send-email-wanpeng.li@hotmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507211733-22604-1-git-send-email-wanpeng.li@hotmail.com> References: <1507211733-22604-1-git-send-email-wanpeng.li@hotmail.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wanpeng Li If we take TSC-deadline mode timer out of the picture, the Intel SDM does not say that the timer is disable when the timer mode is change, either from one-shot to periodic or vice versa. After this patch, the timer is no longer disarmed on change of mode, so the counter (TMCCT) keeps counting down. So what does a write to LVTT changes ? On baremetal, the change of mode is probably taken into account only when the counter reach 0. When this happen, LVTT is use to figure out if the counter should restard counting down from TMICT (so periodic mode) or stop counting (if one-shot mode). This patch is based on observation of the behavior of the APIC timer on baremetal as well as check that they does not go against the description written in the Intel SDM. Cc: Paolo Bonzini Cc: Radim Krčmář Signed-off-by: Wanpeng Li --- arch/x86/kvm/lapic.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 6723e2c..6b366c1 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1308,10 +1308,11 @@ static void apic_update_lvtt(struct kvm_lapic *apic) if (apic->lapic_timer.timer_mode != timer_mode) { if (apic_lvtt_tscdeadline(apic) != (timer_mode == - APIC_LVT_TIMER_TSCDEADLINE)) + APIC_LVT_TIMER_TSCDEADLINE)) { kvm_lapic_set_reg(apic, APIC_TMICT, 0); + hrtimer_cancel(&apic->lapic_timer.timer); + } apic->lapic_timer.timer_mode = timer_mode; - hrtimer_cancel(&apic->lapic_timer.timer); } }