Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2250879lqo; Mon, 13 May 2024 12:14:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUhYQvW4rOudQ8/Ayf9Ot7kmQt9TAVVnYTBmFl+rVwAcwHwYj0M6BUixCzWra6DxvsA4vOd1ZfMIqbsg0Wbr4f4WAKJ0q5cEzBMR/U9Pw== X-Google-Smtp-Source: AGHT+IHU+taiW2KN1c8+9WgexvbHSvfXu203/zu6CCXkp9m/6Db8WsKQPAP6mz9ucLOYMBfmE72j X-Received: by 2002:a4a:aa09:0:b0:5af:c4b3:7c6d with SMTP id 006d021491bc7-5b281966b7cmr9340449eaf.5.1715627671550; Mon, 13 May 2024 12:14:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715627671; cv=pass; d=google.com; s=arc-20160816; b=qgQEgq9knwsGqfZJotuMz2ikmw9KNsLoweVo/hcNPxvWtckOW2RqNyc1HvU1LjopCP 0UOhtYrflffa83gGAQnAI9vNvX87fo7iVgLKHCk7MpXLVEo39dOVxWLrOFTvUqljaWxS RgQm6h4snK2nlHbEfU5hTF4iizwPdbVmM3DU0KG20XDSZnIaHLLNOSyl35HD3dOdhmIv pvUvs1salhNLmT4k/11tstZecPypDdHmd24v8fYoc17I9ZF5/NhacjEAqCHVC9SzrkoZ jt76dcTq+jPeiyxJXFvf16DAmiPP0et78hLZVX7WE+gv6CYsVYYFAjKeOUYuNET2iEBe jENQ== 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=es+FVsqPWUNIRpUuG3Q0WLOBQbEEWGORQ4d1y6RL/uI=; fh=J0SyGZhxSksiCaYBVPmVfYa3lojwJpSmPhTHdUogUkY=; b=JSNLfzuklWkqD21NZrQWzhMzojR5I1wdw32gDrhHmoDdr+lkKvJRF8kSH9AfDK6Biq Suu91teDo6pXvuypNtiiidhoz6EViDNb6iZY9qtV5aE/APnZT2j74N2Zz3SYCFLJg+9O YdGH/4vxis0s+qC25bMdOaq1Buz6S1L7KZ9oSS6yNgxKTGB8W3Y9uk/0w60nzPWzbqK3 QUG2ioHsbvGVeWqhMFL1iaib5D5j8Lmk3owHZOpoKleiESA+cCKpZSzl2vWDIZ2Mdv7L qaiVTfm/qrn/OZqJ6zefOrTRkCsKBoA80HwVG40TQ1O/1F9HlWQimDde4vBNZBQZvHRq VmDA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SWAwARDs; 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-178011-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178011-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. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43df566ecd9si99384651cf.256.2024.05.13.12.14.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 12:14:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-178011-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SWAwARDs; 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-178011-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178011-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 45F9D1C20F23 for ; Mon, 13 May 2024 19:14:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7698848CCC; Mon, 13 May 2024 19:14:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SWAwARDs" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 CD8B341C69 for ; Mon, 13 May 2024 19:14:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715627665; cv=none; b=Htvbn2SOAKXPRhuVivU9gw+5inWm2ZetBrTik0DfJJc4G5b8W+qId2InNEEWCNA+6WdP9urrlAiFg9c3EW6FoHh/E//Kl9thzi2w1MUztzj1jWVH4EIcyyqflKR7PkP/dquVfcif1rImCopMwPjCpWOEa3bschHs1oEAMqhcNgA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715627665; c=relaxed/simple; bh=5N15qcryEo41N2/C4GG6RzQY4PJ2O8cJAktjHr+5acU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=p/3p+T8AmqlmdIu4UfIDNmK2x4vY4lcreFACkrV1h4Et7tIlM7cPpIpBDMAVZr33m/K/u9GFOI5gsa3kB1lgfrcglQCLNq69Z4YDLToWlXp5QdP2SgRCtLE3TrJh/F6E6ZFrxYxMaaXIWxoiuF0Ldg5iRzTblP54rcuaThjLfBI= 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=SWAwARDs; arc=none smtp.client-ip=170.10.129.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=1715627662; 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=es+FVsqPWUNIRpUuG3Q0WLOBQbEEWGORQ4d1y6RL/uI=; b=SWAwARDsuKVCnv+cs2/blRnpIfMjGpYTPJB+S7mUvYQKHhds3PBivMXyMlfwNcdlTbLfDK dwZPhvjHZD83Xf/5X0UFzI2zbWMggFEZjW+BleOCIX15FPKqcTiZb05vmbcRH0++OmLocv Nkd7NuuD6jIVhLOIv7PtIH9wquCXS9Y= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-691-IhuntFJkPiuuUjT2CZHgqA-1; Mon, 13 May 2024 15:14:21 -0400 X-MC-Unique: IhuntFJkPiuuUjT2CZHgqA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 92A5E380009A; Mon, 13 May 2024 19:14:20 +0000 (UTC) Received: from tpad.localdomain (unknown [10.96.133.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C255200B4D8; Mon, 13 May 2024 19:14:20 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 7C663400E4E82; Mon, 13 May 2024 16:14:03 -0300 (-03) Date: Mon, 13 May 2024 16:14:03 -0300 From: Marcelo Tosatti To: Leonardo Bras Cc: Frederic Weisbecker , "Paul E. McKenney" , Paolo Bonzini , Sean Christopherson , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [RFC PATCH 1/1] kvm: Note an RCU quiescent state on guest exit Message-ID: References: <20240511020557.1198200-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.6 On Mon, May 13, 2024 at 12:14:32AM -0300, Leonardo Bras wrote: > On Sun, May 12, 2024 at 06:44:23PM -0300, Marcelo Tosatti wrote: > > On Fri, May 10, 2024 at 11:05:56PM -0300, 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. > > > > This does not properly fix the current problem, as RCU work might be > > scheduled after the VM exit, followed by a timer interrupt. > > > > Correct? > > Correct, for this case, check the note below: > > > > > > > > > Signed-off-by: Leonardo Bras > > > --- > > > > > > ps: A patch fixing this same issue was discussed in this thread: > > > https://lore.kernel.org/all/20240328171949.743211-1-leobras@redhat.com/ > > > > > > Also, this can be paired with a new RCU option (rcutree.nocb_patience_delay) > > > to avoid having invoke_rcu() being called on grace-periods starting between > > > guest exit and the timer IRQ. This RCU option is being discussed in a > > > sub-thread of this message: > > > https://lore.kernel.org/all/5fd66909-1250-4a91-aa71-93cb36ed4ad5@paulmck-laptop/ > > ^ This one above. > The idea is to use this rcutree.nocb_patience_delay=N : > a new option we added on RCU that allow us to avoid invoking rcu_core() if > the grace_period < N miliseconds. This only works on nohz_full cpus. > > So with both the current patch and the one in above link, we have the same > effect as we previously had with last_guest_exit, with a cherry on top: we > can avoid rcu_core() getting called in situations where a grace period just > started after going into kernel code, and a timer interrupt happened before > it can report quiescent state again. > > For our nohz_full vcpu thread scenario, we have: > > - guest_exit note a quiescent state > - let's say we start a grace period in the next cycle > - If timer interrupts, it requires the grace period to be older than N > miliseconds > - If we configure a proper value for patience, it will never reach the > end of patience before going guest_entry, and thus noting a quiescent > state > > What do you think? I don't fully understand all of the RCU details, but since RCU quiescent state marking happens in IRQ disabled section, there is no chance for a timer interrupt to conflict with the marking of quiescent state. So seem to make sense to me.