Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp3087979lqo; Tue, 14 May 2024 21:46:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXpZ+Z5NBUm92xgsk1b4Z5B0LoleIaV7GHMWDkELJugSGAwFasmQUg/9sV2AYPckLkqhPYaySPjNj60W48QRqYYhz81aSlKMJM4zVY3SA== X-Google-Smtp-Source: AGHT+IGCaiCu/nUoVXYUi0kqiGLvk36mEvbdBjZz7OFamf/NsaNwkNexmQTpWXWePMvI46dPAlt4 X-Received: by 2002:a05:6214:5f0c:b0:6a0:cb30:aa4a with SMTP id 6a1803df08f44-6a1681441b0mr162813446d6.11.1715748367322; Tue, 14 May 2024 21:46:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715748367; cv=pass; d=google.com; s=arc-20160816; b=KPPt9SrsUaFRrC5phs/K1PkkePhdzfphhDZ8HWx5FTJMYotZCpSAs9NvQtmAlo0/T3 QkvIgaeZ9axQvn0QDrzEChO6Bq/tW/ifXy7cV8o949VlJsjo7zoJt1IsIzQ9kJnVLZl3 gfTKQPOxJWs5sYmICn9tDeuXbVe5qJitSZxMOH9krNUBKaFSpSLCcjPPJP5oznZY3Peb /3rWc+g0SudyE9eME1riwyihHHSGsGJuhXhnfn8xF+V/o/4FM4y5WK/dzI7CAdploQ/G DAp7Jtr2qatAIEXoHf86z3Au6lH3HZu65traztIjvtT/vERGZqqloQTFlbkZ6lQq+jPi 8Rhg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=HPDdnVnDLt4JFsPDNjCVl1qjYtj9SLA+tQ0OtYJYL+0=; fh=cAmeCvTyJ2E9ZKWsLOBZTtUm1+uEc8tx26/1+j9nI1Q=; b=H7KfaPxZbRVWGLjE/eht9ykjDExs2gMJWjMasWQ4oR2kRRFEygGrOe4E7/bIKDgi3R QLrb0ejq9VglhAchxs5u9ANzmMSycRq+iJT8BELLcQbbWCDHG9ExGpC0UzpMo/aTDNnX 8Th8g+7HgoAnVkgDJa5+gcdUBSwVq4/1679WE5H3lIBvhoz1Jno438gvxlIgItdJf01o HpRL+lqjkoGZ6I+RBNnLlEYnsPvQzGnl9leR7dX2RBFNpH7r2l/DlGETra0Fc5K2Yg9C vnugUXnTu1Ih3AtFxFFvOxo19suKeRC39XmbbxblNV9KZCDGnPjtRIToDcd5he+RAzfX moUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=faMxyunc; 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-179402-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179402-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 6a1803df08f44-6a15f2ef76csi144713086d6.450.2024.05.14.21.46.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 21:46:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179402-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=faMxyunc; 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-179402-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179402-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 E33F21C21545 for ; Wed, 15 May 2024 04:46:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DAB139855; Wed, 15 May 2024 04:46:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="faMxyunc" 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 74A191E4B1 for ; Wed, 15 May 2024 04:45:57 +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=1715748359; cv=none; b=F7kPr8Kh7/y5CBvuuxKd54irCDZKec7SB3/mCOf7/HoJTKMK0OIsStPIYvkEX/eNfnhah/KYj/hQ/ndgSJBaEBCMQmhlt4YYl4HRJMzqYoMaWQPVXtDyB8htxoKPYRnrTDu1BEURrXv0oNlYO9zkGr+E6RNFYavTuiJsdTIWXEs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715748359; c=relaxed/simple; bh=HEa6eZqnnTLKC7vECaVu6A1XoVWrmgsd1gOhdflAqDg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type:Content-Disposition; b=JWJ6P3qaSUVxcS1e0CV137ZPH80NBuaVcmIWHrAroccadbY8VAYK2sYQS+doSNE/X0/MDhM9ONOFS+3tmH/RAFnBbxFY4BTCHf2mMW16pgKu9EBy79MD5wI4/StEFrGk6nxGpEbfJc6Q7nRL5r/VddTSLJeIaaMjK2AoEa9sikA= 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=faMxyunc; 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=1715748356; 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=HPDdnVnDLt4JFsPDNjCVl1qjYtj9SLA+tQ0OtYJYL+0=; b=faMxyuncKA6fCxjc+jBx0KQPGuS4DMdt79yQj9fUVIWHqmXR+828VtVMcf0L14ZhIJcc0q 99hDaYvFYsWyUXxSMfmht6ulxFc17FPliuGXP9+SRcahCF8WRT7iCoK54HMgMVeE/d1suj yTTy+RfGKz/btqFrkwHhjlaJdKCkYxA= Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-662-3ZJJiKjUMvuOxD1VsTBQ7A-1; Wed, 15 May 2024 00:45:54 -0400 X-MC-Unique: 3ZJJiKjUMvuOxD1VsTBQ7A-1 Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-5c6245bc7caso5112374a12.3 for ; Tue, 14 May 2024 21:45:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715748353; x=1716353153; h=content-transfer-encoding:content-disposition:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HPDdnVnDLt4JFsPDNjCVl1qjYtj9SLA+tQ0OtYJYL+0=; b=EcPQrIaIHyReSsggHU1uDo8OyZeUrFbSGJ6j2IVd5vPoandIL5GvWe4BzVJSFqngwD k3gGnEuiJQrWUFAVv2Mh4hO3hVIfKWUyTHaoh1t5c1lziwUyR1bHHLAEjlB4Se2aE5Kj JX2EgBzZWY8G1pljHDEVWkptv9/4HRUUx317Anw7wc+wCHqEQ9B7mGmeuUuq3DWKML1j Kw6t8Q1Sa790nxg3InTNtTd9HyYoygds8ttEjd7grPHDqYgcKYJxWObgf1UvSkR28MOi UUWSxddS716ZpfhN0TX7Uc8xm2Qf5y+ucYqqKP43TnRsNLaZv1xipzFZ1GIOKu1v5yl4 +ohg== X-Forwarded-Encrypted: i=1; AJvYcCUIOCV5wrlAsYbhy5u0cMKTEsli54c+hEJrOiHOZA+H8rHIgTB+mEOx/+1yGawLcDacFpeVbgPK1KoiZY17+V7qtpmmQnDSTZ+DAHL0 X-Gm-Message-State: AOJu0YzYdXr41HdD9Z+HlGpZVd733h9Iaq8J8UcX0Rc6uFQdgoKBDeaA p6508/wlXzwwl3TsxOcBtGYzAQjffFtsp/FqvdtRWFNcAwP3bBzE9SN98ckjJNEtjsFcioVDHCU Yv53bPARvlrZoh1JnPoWSD939GU37w1YTtNo86iYG+W5O3IA4Z1+Sbgt/5sT5vg== X-Received: by 2002:a05:6a20:de91:b0:1af:cc9d:23af with SMTP id adf61e73a8af0-1afde1c5e0emr12058866637.57.1715748353626; Tue, 14 May 2024 21:45:53 -0700 (PDT) X-Received: by 2002:a05:6a20:de91:b0:1af:cc9d:23af with SMTP id adf61e73a8af0-1afde1c5e0emr12058849637.57.1715748353122; Tue, 14 May 2024 21:45:53 -0700 (PDT) Received: from localhost.localdomain ([2804:1b3:a800:a9e8:e01f:c640:3398:ffe5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b628ca5117sm12547700a91.40.2024.05.14.21.45.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 21:45:52 -0700 (PDT) From: Leonardo Bras To: "Paul E. McKenney" Cc: Leonardo Bras , Sean Christopherson , Frederic Weisbecker , Paolo Bonzini , Marcelo Tosatti , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [RFC PATCH 1/1] kvm: Note an RCU quiescent state on guest exit Date: Wed, 15 May 2024 01:45:33 -0300 Message-ID: X-Mailer: git-send-email 2.45.1 In-Reply-To: <68c39823-6b1d-4368-bd1e-a521ade8889b@paulmck-laptop> References: <20240511020557.1198200-1-leobras@redhat.com> <68c39823-6b1d-4368-bd1e-a521ade8889b@paulmck-laptop> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Tue, May 14, 2024 at 03:54:16PM -0700, Paul E. McKenney wrote: > On Mon, May 13, 2024 at 06:47:13PM -0300, Leonardo Bras Soares Passos wrote: > > On Mon, May 13, 2024 at 4:40 PM Sean Christopherson wrote: > > > > > > On Fri, May 10, 2024, Leonardo Bras wrote: > > > > As of today, KVM notes a quiescent state only in guest entry, which is good > > > > as it avoids the guest being interrupted for current RCU operations. > > > > > > > > While the guest vcpu runs, it can be interrupted by a timer IRQ that will > > > > check for any RCU operations waiting for this CPU. In case there are any of > > > > such, it invokes rcu_core() in order to sched-out the current thread and > > > > note a quiescent state. > > > > > > > > This occasional schedule work will introduce tens of microsseconds of > > > > latency, which is really bad for vcpus running latency-sensitive > > > > applications, such as real-time workloads. > > > > > > > > So, note a quiescent state in guest exit, so the interrupted guests is able > > > > to deal with any pending RCU operations before being required to invoke > > > > rcu_core(), and thus avoid the overhead of related scheduler work. > > > > > > Are there any downsides to this? E.g. extra latency or anything? KVM will note > > > a context switch on the next VM-Enter, so even if there is extra latency or > > > something, KVM will eventually take the hit in the common case no matter what. > > > But I know some setups are sensitive to handling select VM-Exits as soon as possible. > > > > > > I ask mainly because it seems like a no brainer to me to have both VM-Entry and > > > VM-Exit note the context switch, which begs the question of why KVM isn't already > > > doing that. I assume it was just oversight when commit 126a6a542446 ("kvm,rcu,nohz: > > > use RCU extended quiescent state when running KVM guest") handled the VM-Entry > > > case? > > > > I don't know, by the lore I see it happening in guest entry since the > > first time it was introduced at > > https://lore.kernel.org/all/1423167832-17609-5-git-send-email-riel@redhat.com/ > > > > Noting a quiescent state is cheap, but it may cost a few accesses to > > possibly non-local cachelines. (Not an expert in this, Paul please let > > me know if I got it wrong). > > Yes, it is cheap, especially if interrupts are already disabled. > (As in the scheduler asks RCU to do the same amount of work on its > context-switch fastpath.) Thanks! > > > I don't have a historic context on why it was just implemented on > > guest_entry, but it would make sense when we don't worry about latency > > to take the entry-only approach: > > - It saves the overhead of calling rcu_virt_note_context_switch() > > twice per guest entry in the loop > > - KVM will probably run guest entry soon after guest exit (in loop), > > so there is no need to run it twice > > - Eventually running rcu_core() may be cheaper than noting quiescent > > state every guest entry/exit cycle > > > > Upsides of the new strategy: > > - Noting a quiescent state in guest exit avoids calling rcu_core() if > > there was a grace period request while guest was running, and timer > > interrupt hits the cpu. > > - If the loop re-enter quickly there is a high chance that guest > > entry's rcu_virt_note_context_switch() will be fast (local cacheline) > > as there is low probability of a grace period request happening > > between exit & re-entry. > > - It allows us to use the rcu patience strategy to avoid rcu_core() > > running if any grace period request happens between guest exit and > > guest re-entry, which is very important for low latency workloads > > running on guests as it reduces maximum latency in long runs. > > > > What do you think? > > Try both on the workload of interest with appropriate tracing and > see what happens? The hardware's opinion overrides mine. ;-) That's a great approach! But in this case I think noting a quiescent state in guest exit is necessary to avoid a scenario in which a VM takes longer than RCU patience, and it ends up running rcuc in a nohz_full cpu, even if guest exit was quite brief. IIUC Sean's question is more on the tone of "Why KVM does not note a quiescent state in guest exit already, if it does in guest entry", and I just came with a few arguments to try finding a possible rationale, since I could find no discussion on that topic in the lore for the original commit. Since noting a quiescent state in guest exit is cheap enough, avoids rcuc schedules when grace period starts during guest execution, and enables a much more rational usage of RCU patience, it's a safe to assume it's a better way of dealing with RCU compared to current implementation. Sean, what do you think? Thanks! Leo > > Thanx, Paul >