Received: by 2002:ab2:7988:0:b0:1f4:b336:87c4 with SMTP id g8csp92917lqj; Thu, 11 Apr 2024 10:41:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWe6RkSyeir1/9Gf+T+1vYbI/QbpgEYpX+AuyHkdPCToSxXM31SplWdNtZxAYFxK7RbCGjQUX6CWfrT8+k/DsRZGzXAjGPBLqAXL4zdqQ== X-Google-Smtp-Source: AGHT+IF1I5Dp9zEcaBej8j1w7xzkT+/G18XipDVR8InOJZjrZJGcf3+KoCg23iXkXA4tj6/vlwyX X-Received: by 2002:a05:620a:2909:b0:78e:c9b1:5623 with SMTP id m9-20020a05620a290900b0078ec9b15623mr351730qkp.8.1712857319049; Thu, 11 Apr 2024 10:41:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712857319; cv=pass; d=google.com; s=arc-20160816; b=l69YUO/2aFWIP8wFbrRkCKi7LeaYyzAhm8J+sQ4B3wE4xBTmQGNTH2G1+wEqNW9k3U DFrks2RhfgCOcc9OHBnLj9Hl3jAJ7lVafd7pePArQDihq7D5/CFcr9V2Jv7dvoUxJ6aA +U+TqSMbCjHg6I8UQYXey9KD7sbJiaDskCj41IS8graaOwwWAHTgyo9S7u2vHinUkRhr LHJ8VI3FHPuO6svB4+DyUzV6f54n6KcvC6jgaS+iMtF12Srxu3Wtt2Uoe5CR5O5VWvgU 5MbsNTmPUgDdEAL2GW/E3VR8dS/LeWQ51U8bSyYS+IyNQzo9crZ83k7C6Slh6RwxMLKw fMvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=WMYXluZdka6NWHeIT5ZbQJbQ6V8bbh3I4kjosa1hc3E=; fh=GDdg9PWL2nCiQO3Ze161jd6IuubKeGfjLOdpADw+o5k=; b=Ivogpg5EKqoiXIOTSENOlBL251xzE6dMLBzGzk22yAuGOpIPjNeNurlDVTdX8HIQqL 9tlFrIKcxmruw0QDftfS2PWKLDc+DpVQFq2KPn7VQyQAsLXnFlPi6P7ICl6FgTAEgIsw Kpk3+MSKT2wE4QtRPGJnUVow2CC9PS+AcseyZlF2rhv8EeciApOAdv4Q+LBDaftCTR7K OucrFcF6nFSnIOwV4xpcRmnuUHAlVOMILFooYBUCIJ/oYJLUYKwqLfzsu0YHD1WPiV5f ue/BpQMH4ILUKFCLQs+x37pP//ELEiAQuJv3DplseRL/3CmfGA1MMpEBzsbZHWloAhAs DYag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XKhyR30J; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-141293-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141293-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id wm6-20020a05620a580600b0078a6d5fdbd5si2000636qkn.740.2024.04.11.10.41.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 10:41:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141293-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XKhyR30J; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-141293-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141293-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A1DDB1C21A9D for ; Thu, 11 Apr 2024 17:41:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A9CE15B0E7; Thu, 11 Apr 2024 16:12:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XKhyR30J" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 3436F171B6 for ; Thu, 11 Apr 2024 16:12:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712851924; cv=none; b=SOlPJL3h9zPIZapyR8rRjtgdYK84lNWAAumj/jmf7bb049iVj1MIVB0xMwXKnb3ypJnh/wdEXyUh2hlbYi2m3/XqMbLtrC5ISMSgeNeMmb02spgF3gsdjCr8BOnYDNhwIQHQS+z5EMsXQvZ5LAQS3n/IVRY9FL1GT4acNdcf+Iw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712851924; c=relaxed/simple; bh=iZJ65E4jwpdPJWy55MJCZoVveyH46gJ2hl1C21236H4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JSdBfZUUZTL09Lqv6M645tFr8GK91VOdzkFNtNhtfGkAcL4Nc4HsBZXjW6b1jLSFiIkDPta7BIq464u2YUQ/1v8QylvL+Cz98iNREx/avvRU58Ed3EquTX0SIt8Y0ntNkjRlZOik9fLY/6Wti501t7nzJMF/qXTacL588Atm/J4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XKhyR30J; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712851922; 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: in-reply-to:in-reply-to:references:references; bh=WMYXluZdka6NWHeIT5ZbQJbQ6V8bbh3I4kjosa1hc3E=; b=XKhyR30J5aF+2fyV2VG8xOTn+MbR+q7eUFNdRzopaqyqarw66+t06o7Op4aX8VM0/WLn72 PAQZPn/o4pqKS6eyhXPkiz4kNTd1WA58XQQ4vMi7i6GHVee9M1DSkFAXhedemWUfis9kL3 Dv3J71mL+7j6fxX8rFWHOikngzUAQDY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-178-CUvC8KVAOeeiiVXbQ2VcNQ-1; Thu, 11 Apr 2024 12:11:56 -0400 X-MC-Unique: CUvC8KVAOeeiiVXbQ2VcNQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CE1C61887318; Thu, 11 Apr 2024 16:11:54 +0000 (UTC) Received: from tpad.localdomain (unknown [10.96.133.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E9657490E8; Thu, 11 Apr 2024 16:11:53 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 439A1400DCB1A; Tue, 9 Apr 2024 23:39:16 -0300 (-03) Date: Tue, 9 Apr 2024 23:39:16 -0300 From: Marcelo Tosatti To: Sean Christopherson Cc: "Paul E. McKenney" , Leonardo Bras , Paolo Bonzini , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, rcu@vger.kernel.org Subject: Re: [RFC PATCH v1 0/2] Avoid rcu_core() if CPU just left guest vcpu Message-ID: References: <20240328171949.743211-1-leobras@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 On Mon, Apr 08, 2024 at 10:16:24AM -0700, Sean Christopherson wrote: > On Fri, Apr 05, 2024, Paul E. McKenney wrote: > > On Fri, Apr 05, 2024 at 07:42:35AM -0700, Sean Christopherson wrote: > > > On Fri, Apr 05, 2024, Marcelo Tosatti wrote: > > > > rcuc wakes up (which might exceed the allowed latency threshold > > > > for certain realtime apps). > > > > > > Isn't that a false negative? (RCU doesn't detect that a CPU is about to (re)enter > > > a guest) I was trying to ask about the case where RCU thinks a CPU is about to > > > enter a guest, but the CPU never does (at least, not in the immediate future). > > > > > > Or am I just not understanding how RCU's kthreads work? > > > > It is quite possible that the current rcu_pending() code needs help, > > given the possibility of vCPU preemption. I have heard of people doing > > nested KVM virtualization -- or is that no longer a thing? > > Nested virtualization is still very much a thing, but I don't see how it is at > all unique with respect to RCU grace periods and quiescent states. More below. > > > But the help might well involve RCU telling the hypervisor that a given > > vCPU needs to run. Not sure how that would go over, though it has been > > prototyped a couple times in the context of RCU priority boosting. > > > > > > > > 3 - It checks if the guest exit happened over than 1 second ago. This 1 > > > > > > second value was copied from rcu_nohz_full_cpu() which checks if the > > > > > > grace period started over than a second ago. If this value is bad, > > > > > > I have no issue changing it. > > > > > > > > > > IMO, checking if a CPU "recently" ran a KVM vCPU is a suboptimal heuristic regardless > > > > > of what magic time threshold is used. > > > > > > > > Why? It works for this particular purpose. > > > > > > Because maintaining magic numbers is no fun, AFAICT the heurisitic doesn't guard > > > against edge cases, and I'm pretty sure we can do better with about the same amount > > > of effort/churn. > > > > Beyond a certain point, we have no choice. How long should RCU let > > a CPU run with preemption disabled before complaining? We choose 21 > > seconds in mainline and some distros choose 60 seconds. Android chooses > > 20 milliseconds for synchronize_rcu_expedited() grace periods. > > Issuing a warning based on an arbitrary time limit is wildly different than using > an arbitrary time window to make functional decisions. My objection to the "assume > the CPU will enter a quiescent state if it exited a KVM guest in the last second" > is that there are plenty of scenarios where that assumption falls apart, i.e. where > _that_ physical CPU will not re-enter the guest. > > Off the top of my head: > > - If the vCPU is migrated to a different physical CPU (pCPU), the *old* pCPU > will get false positives, and the *new* pCPU will get false negatives (though > the false negatives aren't all that problematic since the pCPU will enter a > quiescent state on the next VM-Enter. > > - If the vCPU halts, in which case KVM will schedule out the vCPU/task, i.e. > won't re-enter the guest. And so the pCPU will get false positives until the > vCPU gets a wake event or the 1 second window expires. > > - If the VM terminates, the pCPU will get false positives until the 1 second > window expires. > > The false positives are solvable problems, by hooking vcpu_put() to reset > kvm_last_guest_exit. And to help with the false negatives when a vCPU task is > scheduled in on a different pCPU, KVM would hook vcpu_load(). Sean, It seems that fixing the problems you pointed out above is a way to go.