Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp491744pxu; Tue, 5 Jan 2021 17:40:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzunL//iwcld707x8gJD9maplZcp/FNGX+qK8W+PNbNCy9uM0GyeZblblI3eWBg1uvisxCg X-Received: by 2002:a17:907:210b:: with SMTP id qn11mr1424333ejb.41.1609897204695; Tue, 05 Jan 2021 17:40:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609897204; cv=none; d=google.com; s=arc-20160816; b=abqBzSQGOSqsANVPpmAlgD+z3lUPwOsEndCTKiBxRP7mkO+HI7LeqEBzbbRqJcLvRE FikPVp+8OsZ0PJDOtsyHsRiX3/X675KtI5Wfn/xgm/XJ9T8ctWdX+5tD9IeCQhF3y9Rd 1N9fo2rZOVXYXUKl5n+qW99QVwDXMGjZLZtv7u6ZO6BsG1qVsNJDigJFOqj4D0z9wMgQ mCwXTqxFOO9WfuZuSF8lr6dC8UYxpi5DfB15AYcDSwQaFkEIS1rjfMZ0QFwrdpLHCQ85 J41YwRRpehu1soMt0MKy/VHcIuOHh+nd0Q3JsGz4VGA+MphH85OvAh1xOgHDGQfrV5I1 yL3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-signature; bh=hfo2Cvq3ATvx2T/cgdPX/GnBQ6IRxGdJrImGfK4T+dA=; b=XufMq+hRN5WtiNE0hyac5BNEsJd3TJcSXxTApwlmEaxJsBMyENw6v2QsMKCVGW5Vc0 Oqo40b6+LlPLjd5snq/cEEaPhE8nla4VKYoX5r53NR0xJohH0N7V5UVLR3DaYSGQmUAm E7ypYyfnPe+9Urd+ifvH6KbZn6BSwyKayM5ufEm0GXg7/NwO4seaaWb4K7MI4beH6h06 P4GV/14LjE4fuWej1C0yPMXUNv5F35LMqz2lYLEDqt9YVCPbNfusUGtaA/tYD5KtAYAB rRQvqq8is6SpNPINM6H90Quwf5jI2bnZ8IPbSSUCh/spJ1DtU16FsbRY1h5VYUM4j6PT CJcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SaYxcMoj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn3si345469edb.35.2021.01.05.17.39.41; Tue, 05 Jan 2021 17:40:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SaYxcMoj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726386AbhAFBg6 (ORCPT + 99 others); Tue, 5 Jan 2021 20:36:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29981 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726157AbhAFBg6 (ORCPT ); Tue, 5 Jan 2021 20:36:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609896931; 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=hfo2Cvq3ATvx2T/cgdPX/GnBQ6IRxGdJrImGfK4T+dA=; b=SaYxcMoj64K7e7Prv38M0ls5TYLH1jXb0xdy7gP7RDtZQKe+pBjpOQAuhoD7kjWMUzLClU 16KFv4GYvlT6PJjyC+6/Q2fWGV909vuuTtP4Z33qstK/EzDhNucf4ynguQckjGSSldX51Z CWG6ZRd051tUn5YT3/NqXeWFiGh4YAM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-253-S0RL1n1-Ng6rSVE22t9dEQ-1; Tue, 05 Jan 2021 20:35:29 -0500 X-MC-Unique: S0RL1n1-Ng6rSVE22t9dEQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A79FC180A089; Wed, 6 Jan 2021 01:35:28 +0000 (UTC) Received: from [10.10.112.14] (ovpn-112-14.rdu2.redhat.com [10.10.112.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BF1B860BE2; Wed, 6 Jan 2021 01:35:27 +0000 (UTC) Subject: Re: [PATCH] Revert "KVM: x86: Unconditionally enable irqs in guest context" To: Sean Christopherson Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, w90p710@gmail.com, pbonzini@redhat.com, vkuznets@redhat.com, Thomas Gleixner References: <20210105192844.296277-1-nitesh@redhat.com> From: Nitesh Narayan Lal Organization: Red Hat Inc, Message-ID: Date: Tue, 5 Jan 2021 20:35:26 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/5/21 7:47 PM, Sean Christopherson wrote: > +tglx > > On Tue, Jan 05, 2021, Nitesh Narayan Lal wrote: >> This reverts commit d7a08882a0a4b4e176691331ee3f492996579534. >> >> After the introduction of the patch: >> >> 87fa7f3e9: x86/kvm: Move context tracking where it belongs >> >> since we have moved guest_exit_irqoff closer to the VM-Exit, explicit >> enabling of irqs to process pending interrupts should not be required >> within vcpu_enter_guest anymore. > Ugh, except that commit completely broke tick-based accounting, on both Intel > and AMD. I did notice some discrepancies in the system time reported after the introduction of this patch but I wrongly concluded that the behavior is correct. I reported this yesterday [1] but I think I added your old email ID in that thread (sorry about that). > With guest_exit_irqoff() being called immediately after VM-Exit, any > tick that happens after IRQs are disabled will be accounted to the host. E.g. > on Intel, even an IRQ VM-Exit that has already been acked by the CPU isn't > processed until kvm_x86_ops.handle_exit_irqoff(), well after PF_VCPU has been > cleared. Right that also explains the higher system time reported by the cpuacct.stats. > > CONFIG_VIRT_CPU_ACCOUNTING_GEN=y should still work (I didn't bother to verify). For the cpuacct stats that I have shared in the other thread, this config was enabled. > > Thomas, any clever ideas? Handling IRQs in {vmx,svm}_vcpu_enter_exit() isn't an > option as KVM hasn't restored enough state to handle an IRQ, e.g. PKRU and XCR0 > are still guest values. Is it too heinous to fudge PF_VCPU across KVM's > "pending" IRQ handling? E.g. this god-awful hack fixes the accounting: > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 836912b42030..5a777fd35b4b 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -9028,6 +9028,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) > vcpu->mode = OUTSIDE_GUEST_MODE; > smp_wmb(); > > + current->flags |= PF_VCPU; > kvm_x86_ops.handle_exit_irqoff(vcpu); > > /* > @@ -9042,6 +9043,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) > ++vcpu->stat.exits; > local_irq_disable(); > kvm_after_interrupt(vcpu); > + current->flags &= ~PF_VCPU; > > if (lapic_in_kernel(vcpu)) { > s64 delta = vcpu->arch.apic->lapic_timer.advance_expire_delta; > I can give this a try. What is the right way to test this (via cpuacct stats maybe)? [1] https://lore.kernel.org/lkml/12a1b9d4-8534-e23a-6bbd-736474928e6b@redhat.com/ -- Thanks Nitesh