Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1905480rdb; Tue, 20 Feb 2024 10:20:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVdoq9vSDTfzUo32GZkRWIK3UbPChgufWJNVLtMe2p9LMTAj2nRvAsIz5VIQrnoG5VhtBGW119PMKwSfn6C/pBT/7TXntv1jsQOU7AL5w== X-Google-Smtp-Source: AGHT+IFuIOD9Hqy08IlvgWP/do3cYFW79JnYk+TpWQsbB8X3yBli5cKJgJYb1QZGSF9XjSRS4ESd X-Received: by 2002:a05:6a00:1395:b0:6e4:6630:8155 with SMTP id t21-20020a056a00139500b006e466308155mr6838644pfg.20.1708453216382; Tue, 20 Feb 2024 10:20:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708453216; cv=pass; d=google.com; s=arc-20160816; b=OvYye0PQlxccK/sUAxg2KXwLcFg5IowodsbM/NDLZqX/gJOhC35rwk57EZWU1Hd/Ix 5vfXQCQQA8c4XMRwbnJ1RT2cHTb3MM6Y0CxVPItmll6cISQKiO+JqVskCCiP8q5HMOnS yOKoFpMN0qHEnGW0EfkK8Ed0ipd2Md5RzJaxGFN4W8Pq5r+P7CWcYOSZ2lFSmWAgFUlH kISfBGiXpUtOSPFaMjSQJbLH3kyCQ5VEy2sCmPy2HsyhmkMpv9e5uohsKl24Lej6jr5u pZvKx/KpeU9rPVnPIoiPluNzzc6bAsY+jXXW3TVSBlQ9CLXgKypa+DB9atpu17WISqMD 6HhA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:references:to:from:cc:message-id:date :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:subject:dkim-signature; bh=baf//OFtaBmveFrh1T1pIXdXH6SodC8p/NjJvSUchbw=; fh=if8LqwCahHB89ZYDC3FcinAaQQ+Rk908BTcreDXflNc=; b=nHmBQ1exaEPqChpirgob3Lqr+ny6U13EczVLz1K8+NSIc9j3HlySDEv5uSSt79r/aA pA26VK4Lwo5iS94FwB8Ds+7m6Ju/BGa9K0WVdwCkptD9M31Yw/WVSc4tDujWxN7pnDoa oEeSttcEukLNQ/2Geucwl9wIDqX/1f1K8KZR/dRBPDdLW3dDWNzWHKaxhSEEGpfgIt/F LIqygvXuL/BLuBH3zZpBOdvr58C1H7BE2IGasSUOlarnL+aIVleQ1jvmMgMFQDhUu5GJ DNHDXH/OLLj0NHlFLU4tbxddovSQeiBxI/hpzrPmnySfMuqxZ0IBNi2vwV3pkFhJ29M2 AaMw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=HaHts8d1; arc=pass (i=1 spf=pass spfdomain=amazon.es dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-73501-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73501-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ay36-20020a056a00302400b006e46a21d3a3si2937886pfb.393.2024.02.20.10.20.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 10:20:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73501-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=HaHts8d1; arc=pass (i=1 spf=pass spfdomain=amazon.es dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-73501-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73501-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1AE0C2816AD for ; Tue, 20 Feb 2024 18:20:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8BE7377F1B; Tue, 20 Feb 2024 18:20:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="HaHts8d1" Received: from smtp-fw-52002.amazon.com (smtp-fw-52002.amazon.com [52.119.213.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA61578B51; Tue, 20 Feb 2024 18:20:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.150 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708453202; cv=none; b=jEDiegGrxRfDjnqJsXleSqVgIHsxAFCrVHUsKAApP0I6istKSdEzVe/RaGbITZ25Tl82oCI4oPF9CwIS7+TOoh2ufDs+JH04GPogxbNXMtoJDX8FW27ehWaSSyCA/44BiizuXjvRnZYQ4Lr2+JAFnxlHNkKRrDQdBowWNbD8Hkc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708453202; c=relaxed/simple; bh=E8K+6Wm53lwrPr2IqIINIugq49kJsMNCH84DE/g7vVY=; h=Subject:MIME-Version:Content-Type:Date:Message-ID:CC:From:To: References:In-Reply-To; b=M+Ypc6nT9A3W/tJQuZ9pWu25O60l4BtOVVbcyt4ZLOM/jVajEfexuxiPLW/RI65sxjLduJS32BJxKe/YXwdkWLaWrr9/lteTk+LesjYHUVWoRmdKGxyxdq6YZ9nhAvwsynnIvV2pkK9G2g2FNhjmQgYja4HXgwS8/dB6SBag0Lo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.es; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=HaHts8d1; arc=none smtp.client-ip=52.119.213.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.es DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1708453201; x=1739989201; h=mime-version:content-transfer-encoding:date:message-id: cc:from:to:references:in-reply-to:subject; bh=baf//OFtaBmveFrh1T1pIXdXH6SodC8p/NjJvSUchbw=; b=HaHts8d1/bqJCwNjlrnR+lDGRzpg7oiVtdU9eWt42BSj05XjCIyYzCEz bLM3JxcbOY802jhcZVK9I7FyJ5BA+jG7UxjWMjGJlF17XOQszVYkyXzfl 5wcmTJgbK6Ccl7y4tshrFrMZbGsDLsXRtUroYsxhsTKk9rRq0L48iYcdc s=; X-IronPort-AV: E=Sophos;i="6.06,174,1705363200"; d="scan'208";a="614314737" Subject: Re: [RFC] cputime: Introduce option to force full dynticks accounting on NOHZ & NOHZ_IDLE CPUs Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-52002.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 18:19:54 +0000 Received: from EX19MTAEUA002.ant.amazon.com [10.0.43.254:20536] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.31.182:2525] with esmtp (Farcaster) id c706beb8-aa81-4dca-8c2b-451948cd7111; Tue, 20 Feb 2024 18:19:52 +0000 (UTC) X-Farcaster-Flow-ID: c706beb8-aa81-4dca-8c2b-451948cd7111 Received: from EX19D004EUC001.ant.amazon.com (10.252.51.190) by EX19MTAEUA002.ant.amazon.com (10.252.50.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 20 Feb 2024 18:19:52 +0000 Received: from localhost (10.13.235.138) by EX19D004EUC001.ant.amazon.com (10.252.51.190) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 20 Feb 2024 18:19:48 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" Date: Tue, 20 Feb 2024 18:19:44 +0000 Message-ID: CC: , , , , , , , , , , , , From: Nicolas Saenz Julienne To: Sean Christopherson X-Mailer: aerc 0.16.0-127-gec0f4a50cf77 References: <20240219175735.33171-1-nsaenz@amazon.com> In-Reply-To: X-ClientProxiedBy: EX19D042UWA003.ant.amazon.com (10.13.139.44) To EX19D004EUC001.ant.amazon.com (10.252.51.190) Hi Sean, On Tue Feb 20, 2024 at 4:18 PM UTC, Sean Christopherson wrote: > On Mon, Feb 19, 2024, Nicolas Saenz Julienne wrote: > > Under certain extreme conditions, the tick-based cputime accounting may > > produce inaccurate data. For instance, guest CPU usage is sensitive to > > interrupts firing right before the tick's expiration. This forces the > > guest into kernel context, and has that time slice wrongly accounted as > > system time. This issue is exacerbated if the interrupt source is in > > sync with the tick, significantly skewing usage metrics towards system > > time. > > ... > > > NOTE: This wasn't tested in depth, and it's mostly intended to highligh= t > > the issue we're trying to solve. Also ccing KVM folks, since it's > > relevant to guest CPU usage accounting. > > How bad is the synchronization issue on upstream kernels? We tried to ad= dress > that in commit 160457140187 ("KVM: x86: Defer vtime accounting 'til after= IRQ handling"). > > I don't expect it to be foolproof, but it'd be good to know if there's a = blatant > flaw and/or easily closed hole. The issue is not really about the interrupts themselves, but their side effects. For instance, let's say the guest sets up an Hyper-V stimer that consistently fires 1 us before the preemption tick. The preemption tick will expire while the vCPU thread is running with !PF_VCPU (maybe inside kvm_hv_process_stimers() for ex.). As long as they both keep in sync, you'll get a 100% system usage. I was able to reproduce this one through kvm-unit-tests, but the race window is too small to keep the interrupts in sync for long periods of time, yet still capable of producing random system usage bursts (which unacceptable for some use-cases). Other use-cases have bigger race windows and managed to maintain high system CPU usage over long periods of time. For example, with user-space HPET emulation, or KVM+Xen (don't know the fine details on these, but VIRT_CPU_ACCOUNTING_GEN fixes the mis-accounting). It all comes down to the same situation. Something triggers an exit, and the vCPU thread goes past 'vtime_account_guest_exit()' just in time for the tick interrupt to show up. Note that we're running with 160457140187 ("KVM: x86: Defer vtime accounting 'til after IRQ handling"), on the kernel that reproduced these issues. The RFC fix was tested against an upstream kernel by tracing cputime accounting and making sure the right code-paths were exercised. Nicolas