Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1623469lqe; Mon, 8 Apr 2024 14:56:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX5V3uWhuiZSAFrLRzOcuInhsXMeJ3IH1+Tz0mTdIx0U4g84PfU+8ik4p1jQd0ejQVoeQ2JMCaAOhCu+NDU50a3kQBJ7OOgNqmweL4Ryw== X-Google-Smtp-Source: AGHT+IFUPwBdfmtEkhCnltv54ZT6Vima0w30Fat9jh4vHGm+lWwFrI1Vr2ItGv2U/XhUAklF2wJU X-Received: by 2002:a05:6402:e83:b0:56c:292f:84da with SMTP id h3-20020a0564020e8300b0056c292f84damr705776eda.17.1712613415348; Mon, 08 Apr 2024 14:56:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712613415; cv=pass; d=google.com; s=arc-20160816; b=IXAhQYOyk/8KfpwSTPH0wjjh8Ah2ZBWlaiu0TpmxAPTqlmJtINJpBF51X1pxmWF72c /rQYKOzZbBDa5ai8AfuzLNyxmKrSJf8V1UT5+8I8rh9ctDHCThYvsXXaXz726rnAtFWY QL2f3oIqYDuTVdoEYIK0JgmundeyLkbE9yYCFrFL0ojjCRerNzTQRvE7jr8H3Jf5hy0u hCOLQPByNu+8Vzut1TlBRfUUGPvTUOnOTCPVbprJvtEuvvKvQ8TRg6lmR9KmyPu/Uv/8 VSGifF718eTrnJu97hl/Ak7j89pLAzzcRuIVFAxF/qgV0UDpPLQz1uR1iUnMuasoG3GE B29g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=0+YtI06tP7BJVW9G+3zSEn/HDI9HVvJWqFii9XPCuXU=; fh=5JFhifUsyEQ+yk50ig/qxPZw8igyDPQjjaJlBNU+Cqs=; b=ljgIsYaCmYPj5arOlusXU/YWwVx4tL3JdCfpIqwNizOB8oZlDsTn5O2GSBnsffEPmw RiS3xnNjG7icSI+Y04BqnCuwvIzGnEBJvqw31/NlUREAxACGw47x9QR2evKdEmM82gVS dzShUOlyeyP8tD67SMP6sgtoWrUBde35pgshQVjMV70nocXIJ4l94FLzDmssA05G4qX4 v86cDTa3Jk6sjr/hhaYTTovNz3e8012tzyuy3vBMeGgbhq6c0qa6h48/EvNLm4WwPm+1 ZhchI66JZwRTy84w39tS//4ZeyFq8lK9rKzyh40ucnp+Qswfp01YaaYVHeCp4/aWtH7x Ln0g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KjlAgZE3; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-135958-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135958-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id fe6-20020a056402390600b0056c193c0659si4284517edb.75.2024.04.08.14.56.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 14:56:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135958-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KjlAgZE3; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-135958-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135958-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 am.mirrors.kernel.org (Postfix) with ESMTPS id DCD3C1F22910 for ; Mon, 8 Apr 2024 21:56:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE07E14A0AE; Mon, 8 Apr 2024 21:56:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KjlAgZE3" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1296F149DF4 for ; Mon, 8 Apr 2024 21:56:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712613393; cv=none; b=ZtYBRUdd/zOWLRWfz+FoNfLFjB4N1SRLJB9AoeF+eNwXhnpFAMvpq62RH8+FC0Xrv/92PescggVU4uJhiFt+GtbNM5A7t73IQkQcOf+cn9o0m+6gpWFLglK96e5gVz74SLFxapv6wHG01LtJ7UykrJX08ONudwG2zD2tC1MJnJc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712613393; c=relaxed/simple; bh=KMgMj5SuCHh7Ha85uQVvUmDrUucgoYhw/hHwBlpvQbY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jUx5vnVdkKvXKTqyCqEMCyYkN4PQv7NUszh4iqj0A4gOaXBdqelW11svbuYEspf13O18zhatlnUEoq8XFi+f8p14hlD/ytHv68Mo8lhhz1fN5VW1I+L59PqprD37QMKGaMe25TOOy32VE9fphdb4X6SHcPywhE9/ANiVIoixIwg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=KjlAgZE3; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcc4563611cso7315378276.3 for ; Mon, 08 Apr 2024 14:56:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712613391; x=1713218191; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=0+YtI06tP7BJVW9G+3zSEn/HDI9HVvJWqFii9XPCuXU=; b=KjlAgZE3nlz98x0q293PDPdRhk+5X5FEXRErDY3u7gM43ADQ/PrutCwp5eZioqhPWy h6k04WR84E+XdEpDKttS2IabfF6FqTWsZN9OU0uY0tSDUjv40UDMuVNi/0N0hZJf3ORt ag9HbWcuCI1ey5sl4jSrgcBusSM7snMLAZVLxYFimTmyAMJityePZwtdWOfGQ96MsymH X/3hykJ/yE89A2G7XGt5onu6nDtLkz13oraQPqUZ6KGSp5bGS6UztbLBrcQh5/e80pBc h7muRYDazcBlqdIFnBVppQad/bCTceGFJ08oCTSuJMicu/vWT2HNqC62Qnl626Yd+NEK nZ0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712613391; x=1713218191; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0+YtI06tP7BJVW9G+3zSEn/HDI9HVvJWqFii9XPCuXU=; b=VmjMr0Bze8nUwS8TTizOLyDTWbaPYYCOb0bT80l+EukfTbT2B8S0xWohi4UDngb0Q4 azDohd0m+/iau78sJdpz+5l+rCKjKaX8aDKSRLsB9RZTHYBs0mJlrzbbE3eZr5+7KKeO 866uNAI3j4GO0V6M6rzISFohJaDmDt808h+WEPbjFgdJkLFTQE5iFdWqsaCD9xStbpmM mkpNrcf+M1MzEs1phdV7SjmUu7PrDk2zmfv9KKF3hsIn7E/BfBCJjEXTM7MkDeO6EJ17 +IDCRw/vk3w7TA42jb+Chx18pVjV4gP2gC1vYS2+bIiCU67lboWSFsIVyFtXPSjOUbxd cbgg== X-Forwarded-Encrypted: i=1; AJvYcCUOVN8NDE2Z4+9GaycpZHM233yZD9OkpO1/rJ5E8XP2Yz5zFjX5lV8uYlCEZWm08l9u9CAXbFXGh7/ZIvsmOcRGw1Gm3fnVxtSHBMFS X-Gm-Message-State: AOJu0YyWoAZZBvM64FctowjU+tJaFFqCpp1iwzSABJcW3Ud+cpI8nQ+t Q7iq4RSkPXL/kSjxzoieKNANMVrYpdwAPHc6C+3hJVPbPMq5T7VNfL7M9UXCutKW4yf5nMKCGbs 5QQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:188e:b0:dc2:550b:a4f4 with SMTP id cj14-20020a056902188e00b00dc2550ba4f4mr3047423ybb.1.1712613391167; Mon, 08 Apr 2024 14:56:31 -0700 (PDT) Date: Mon, 8 Apr 2024 14:56:29 -0700 In-Reply-To: <44eb0d36-7454-41e7-9a16-ce92a88e568c@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240328171949.743211-1-leobras@redhat.com> <414eaf1e-ca22-43f3-8dfa-0a86f5b127f5@paulmck-laptop> <44eb0d36-7454-41e7-9a16-ce92a88e568c@paulmck-laptop> Message-ID: Subject: Re: [RFC PATCH v1 0/2] Avoid rcu_core() if CPU just left guest vcpu From: Sean Christopherson To: "Paul E. McKenney" Cc: Marcelo Tosatti , 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 Content-Type: text/plain; charset="us-ascii" On Mon, Apr 08, 2024, Paul E. McKenney wrote: > On Mon, Apr 08, 2024 at 01:06:00PM -0700, Sean Christopherson wrote: > > On Mon, Apr 08, 2024, Paul E. McKenney wrote: > > > > > > + if (vcpu->wants_to_run) > > > > > > + context_tracking_guest_start_run_loop(); > > > > > > > > > > At this point, if this is a nohz_full CPU, it will no longer report > > > > > quiescent states until the grace period is at least one second old. > > > > > > > > I don't think I follow the "will no longer report quiescent states" issue. Are > > > > you saying that this would prevent guest_context_enter_irqoff() from reporting > > > > that the CPU is entering a quiescent state? If so, that's an issue that would > > > > need to be resolved regardless of what heuristic we use to determine whether or > > > > not a CPU is likely to enter a KVM guest. > > > > > > Please allow me to start over. Are interrupts disabled at this point, > > > > Nope, IRQs are enabled. > > > > Oof, I'm glad you asked, because I was going to say that there's one exception, > > kvm_sched_in(), which is KVM's notifier for when a preempted task/vCPU is scheduled > > back in. But I forgot that kvm_sched_{in,out}() don't use vcpu_{load,put}(), > > i.e. would need explicit calls to context_tracking_guest_{stop,start}_run_loop(). > > > > > and, if so, will they remain disabled until the transfer of control to > > > the guest has become visible to RCU via the context-tracking code? > > > > > > Or has the context-tracking code already made the transfer of control > > > to the guest visible to RCU? > > > > Nope. The call to __ct_user_enter(CONTEXT_GUEST) or rcu_virt_note_context_switch() > > happens later, just before the actual VM-Enter. And that call does happen with > > IRQs disabled (and IRQs stay disabled until the CPU enters the guest). > > OK, then we can have difficulties with long-running interrupts hitting > this range of code. It is unfortunately not unheard-of for interrupts > plus trailing softirqs to run for tens of seconds, even minutes. Ah, and if that occurs, *and* KVM is slow to re-enter the guest, then there will be a massive lag before the CPU gets back into a quiescent state. > One counter-argument is that that softirq would take scheduling-clock > interrupts, and would eventually make rcu_core() run. Considering that this behavior would be unique to nohz_full CPUs, how much responsibility does RCU have to ensure a sane setup? E.g. if a softirq runs for multiple seconds on a nohz_full CPU whose primary role is to run a KVM vCPU, then whatever real-time workaround the vCPU is running is already doomed. > But does a rcu_sched_clock_irq() from a guest OS have its "user" > argument set? No, and it shouldn't, at least not on x86 (I assume other architectures are similar, but I don't actually no for sure). On x86, the IRQ that the kernel sees comes looks like it comes from host kernel code. And on AMD (SVM), the IRQ doesn't just "look" like it came from host kernel, the IRQ really does get vectored/handled in the host kernel. Intel CPUs have a performance optimization where the IRQ gets "eaten" as part of the VM-Exit, and so KVM synthesizes a stack frame and does a manual CALL to invoke the IRQ handler. And that's just for IRQs that actually arrive while the guest is running. IRQs arrive while KVM is active, e.g. running its large vcpu_run(), are "pure" host IRQs.