From patchwork Wed Feb 27 19:19:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 1049119 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 448lrC1303z9sDb; Thu, 28 Feb 2019 06:20:10 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1gz4kP-0005Pi-CS; Wed, 27 Feb 2019 19:20:05 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1gz4kN-0005OT-5N for kernel-team@lists.ubuntu.com; Wed, 27 Feb 2019 19:20:03 +0000 Received: from mail-qk1-f200.google.com ([209.85.222.200]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1gz4kM-0008K9-La for kernel-team@lists.ubuntu.com; Wed, 27 Feb 2019 19:20:02 +0000 Received: by mail-qk1-f200.google.com with SMTP id 207so14022815qkf.9 for ; Wed, 27 Feb 2019 11:20:02 -0800 (PST) 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=kDyBCSHSv/2j/fM/D7LU0xhz+UJNqtBfNo38r0WsRkg=; b=PRG8LSO31WNW9cBr7I5gv8Msg29q1cG5DhFJhehcPxs8OFbRjUFrblS2wRw2c1kIQZ hESre6S2kdhV73Cgcpo5KeqbfdNsXt02GRE+l3W7bH4Lz9pe+iDTT9XNJOte2lrGqvip MDY//XFWquMGmjgeE4b5woRhVCvLeJG7HqFRTupz1NiWJcq4jvDY6PaJdRxC5c5X8eeX hZJ1hlrii38YI4Kt5ml0lUrQ+Kv0pzRBvzE8oltDRPS+6Gi+aXcawpEPi0Fr0u6WfBEu NOtPOvqcd2sY1iS5bkPRcECHC84RPrQljDcSWW7GOj9fVLlAlDzjMuNNzyGb4eiBRwKE IvDw== X-Gm-Message-State: APjAAAXs1EHytyYsmK270NLePJG0y7UJmCC7l5i3dp+oDySpxzI12dW5 PJJ4BfJ/JJchdtmew0z+kwIviCGsJxvrr7YWGMMHvh8vL3B0EGYhpBu4utTEvUKC8L07Wa7plR7 E0jkEaj0ptDk8BQ2MDcJldq7Q58ibgVE7QTHugXxaIA== X-Received: by 2002:ac8:3718:: with SMTP id o24mr3055300qtb.2.1551295201364; Wed, 27 Feb 2019 11:20:01 -0800 (PST) X-Google-Smtp-Source: APXvYqxpOb1TmRxTNQXzr+b++v/t96bdjqeQE8KcXLiZiZk4ky4t3h+zgyq68Mx6oV2aY7FbOdFG5w== X-Received: by 2002:ac8:3718:: with SMTP id o24mr3055291qtb.2.1551295201229; Wed, 27 Feb 2019 11:20:01 -0800 (PST) Received: from localhost ([179.110.167.246]) by smtp.gmail.com with ESMTPSA id 24sm12617584qtu.17.2019.02.27.11.19.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Feb 2019 11:20:00 -0800 (PST) From: "Guilherme G. Piccoli" To: kernel-team@lists.ubuntu.com Subject: [SRU X] [PATCH 2/2] KVM: LAPIC: cap __delay at lapic_timer_advance_ns Date: Wed, 27 Feb 2019 16:19:50 -0300 Message-Id: <20190227191950.12074-3-gpiccoli@canonical.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190227191950.12074-1-gpiccoli@canonical.com> References: <20190227191950.12074-1-gpiccoli@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gpiccoli@canonical.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Marcelo Tosatti BugLink: https://bugs.launchpad.net/bugs/1817918 The host timer which emulates the guest LAPIC TSC deadline timer has its expiration diminished by lapic_timer_advance_ns nanoseconds. Therefore if, at wait_lapic_expire, a difference larger than lapic_timer_advance_ns is encountered, delay at most lapic_timer_advance_ns. This fixes a problem where the guest can cause the host to delay for large amounts of time. Reported-by: Alan Jenkins Signed-off-by: Marcelo Tosatti Signed-off-by: Paolo Bonzini (cherry picked from commit b606f189c7d5bf9b875bba168162fe05287880fe) Signed-off-by: Guilherme G. Piccoli --- arch/x86/kvm/lapic.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 76e8295517ed..e1edbf9c4033 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1265,7 +1265,8 @@ void wait_lapic_expire(struct kvm_vcpu *vcpu) /* __delay is delay_tsc whenever the hardware has TSC, thus always. */ if (guest_tsc < tsc_deadline) - __delay(tsc_deadline - guest_tsc); + __delay(min(tsc_deadline - guest_tsc, + nsec_to_cycles(vcpu, lapic_timer_advance_ns))); } static void start_apic_timer(struct kvm_lapic *apic)