Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp671300rdd; Tue, 9 Jan 2024 16:41:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IHSDfa37EWodPPPvvisK+PUB82w2VtEF2MDCcChmOuFKkpJ+7887suCir9fH5csk93CpK3Y X-Received: by 2002:a05:620a:43a0:b0:783:2673:77fe with SMTP id a32-20020a05620a43a000b00783267377femr528481qkp.30.1704847277814; Tue, 09 Jan 2024 16:41:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704847277; cv=none; d=google.com; s=arc-20160816; b=XKpG30i5WEdV3meHJws8N2nno+G14rhPlJTuK4WKcrAbtwzXpbpFlRJMABi4IdfQUx 4jvYiVGU76XfqNYuPWO6PoO1/WUuLC9Z+RyVmbk4zp8Z3dLGIcqTb1/Xnw+LXWWvOh0t zQtQ8lTBx+8c9kmJGkNYqtieB3MBbk+0eyY0iV6hl8OuOmBzBNbsl6OG2M96X9o5k0qT rKv9QDwSyKdXi+xUgFXC3R9+E6Z/Xxdpin9ZG+ZLQb58mgr9R0LChFTTmCeIaz5NEBWG 1S6MD97YmhT69IhEly5VUFwGk6z1tLDk7m8+5/8dm8RKTxNkfcuKenWsf81Zf6rW74p7 chlQ== ARC-Message-Signature: i=1; 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 :reply-to:dkim-signature; bh=D4tvOVGYXZj07Mh3AbKScJlIRDF+gPUSkrxYwSocJBU=; fh=/j5JD0kNmt6w2ElaoSjWxIvbDK7Ar0LSE5o5EAaCtME=; b=r5SAwadNjLd3i5eqftwqHD04BTchtxXD7H4jG1kVUIjl159gQqHc2m+7/rvWlnKvyQ w9p2q1DcWsDTWOAbY+dhcvhyD9KA1cVxhuvNxSvmrd1OGRTqd3xa5ft3088kyviA4cN3 w0mz90WT8oUlVqd/XeRuRD6MivB2LLEMq7hOytcgfdc6ZQSkswNMx5027zsk5R0zynsk bS1JIS7xM38q/MmhleF/KMXEHOlgj9XMDF20tGaryMh4PmBHkUwEba6loAJ/14Ov1k3r UQrwQTabEQH+jctgmxv95L20D5j9+txlMcKMyylbu9bLavRVMHI429JQ+pRzfrqesKq6 74Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eKOR2f2l; spf=pass (google.com: domain of linux-kernel+bounces-21591-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21591-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f10-20020a05620a408a00b007831fd2dab1si3365384qko.600.2024.01.09.16.41.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 16:41:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21591-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=@google.com header.s=20230601 header.b=eKOR2f2l; spf=pass (google.com: domain of linux-kernel+bounces-21591-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21591-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 90C401C25284 for ; Wed, 10 Jan 2024 00:41:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC916DDDF; Wed, 10 Jan 2024 00:39:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eKOR2f2l" 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 5E4DE944F for ; Wed, 10 Jan 2024 00:39:49 +0000 (UTC) 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-dbedc37d66cso3176653276.3 for ; Tue, 09 Jan 2024 16:39:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704847188; x=1705451988; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=D4tvOVGYXZj07Mh3AbKScJlIRDF+gPUSkrxYwSocJBU=; b=eKOR2f2lty8vnakGYTNRzUplaVRRnXqedSIK3sreykitPI9o67BRVaBrxSgFLagtTX E7idXtH06VESju55/7pn2PyR9wabHnLKrg5hFMvFSPAUBTkBm0GI+QypdLjs+qCwUrkd Tr00OJcLOoRFHnPquwThbMR409+RjGDPa2clm160YkiOxvc3vjm8NNC0mPmNBFOulQpN pUunmH8MValLTymY4F4IUS2XDYXCzQ/GV6a4oGQ/P7ko0du8/zY5NfxmxWjypNQDV4Pf AxCYZDRc/nO9+8OaCOAOu+L839lOI1VXgGoH5etbh4FrviDVDQGYl4DsLckswoz7/7vG Y7hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704847188; x=1705451988; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=D4tvOVGYXZj07Mh3AbKScJlIRDF+gPUSkrxYwSocJBU=; b=X8oxZisewDyqgKX6YWgr160pa2FmWJjBUw+EgFPpvKJHnX/XuaQ5PZnVWBBp7dtO4F NUD7K3roSQibAlh/2Hn/sO/+xCaSYP+XTzyATCkG4do2TNDSZhSXYR4hK4GARZf4SLfg NfUHubyYduzrG+XlDS55Dd7eiAiE3hH9sE/9vwo7kCFobU3Z4/OS6ysrENOMs16ZwS0s SXN8wk+bfZqhRYhbF3sYY/YvFIduBa1o/xY6Jm2XJtURMAuaeWwYM+dNaGf4ZMniPRwf LZudMEQItmDKCSPSsCABSGfWR8eVdbqOvgFp8YJr0J0loU6csMvuzUQpk1bS70Pk9Xkm Oiwg== X-Gm-Message-State: AOJu0Yxbcxz/pLmLDbdGawDJ7rgRii8JUbbz5Aei/INgbRM/B5d6fYd1 hxsYA4WgGQ2B8v24Vd/xs5cOBk9SEp2G6eP7fw== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:8749:0:b0:dbe:d426:c456 with SMTP id e9-20020a258749000000b00dbed426c456mr6512ybn.4.1704847188423; Tue, 09 Jan 2024 16:39:48 -0800 (PST) Reply-To: Sean Christopherson Date: Tue, 9 Jan 2024 16:39:38 -0800 In-Reply-To: <20240110003938.490206-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240110003938.490206-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20240110003938.490206-5-seanjc@google.com> Subject: [PATCH 4/4] KVM: Add a comment explaining the directed yield pending interrupt logic From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Like Xu Content-Type: text/plain; charset="UTF-8" Add a comment to explain why KVM treats vCPUs with pending interrupts as in-kernel when a vCPU wants to yield to a vCPU that was preempted while running in kernel mode. Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 6326852bfb3d..4a9e7513c585 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -4089,6 +4089,13 @@ void kvm_vcpu_on_spin(struct kvm_vcpu *me, bool yield_to_kernel_mode) continue; if (kvm_vcpu_is_blocking(vcpu) && !vcpu_dy_runnable(vcpu)) continue; + + /* + * Treat the target vCPU as being in-kernel if it has a + * pending interrupt, as the vCPU trying to yield may + * be spinning waiting on IPI delivery, i.e. the target + * vCPU is in-kernel for the purposes of directed yield. + */ if (READ_ONCE(vcpu->preempted) && yield_to_kernel_mode && !kvm_arch_dy_has_pending_interrupt(vcpu) && !kvm_arch_vcpu_preempted_in_kernel(vcpu)) -- 2.43.0.472.g3155946c3a-goog