Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1618118rdd; Thu, 11 Jan 2024 04:48:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZ7pzScyukwuhwTG/mxN62U4GHK/8h82Q5RilPckGL/hRY6Ehvmm7lVHroHaJH7DH4wkAk X-Received: by 2002:a17:902:e884:b0:1d4:4df7:22ab with SMTP id w4-20020a170902e88400b001d44df722abmr1084903plg.55.1704977285889; Thu, 11 Jan 2024 04:48:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704977285; cv=none; d=google.com; s=arc-20160816; b=raSu6KbiTj7CXu1frj8tbjLSD9B548Guvvs5ty99beNVZBDpPKseeVZOR64B4l6LLQ 4YVoW8UByCkhY/Cz0vpkf2n6aI6SAWOlIkmEc2XSKmJWTq1NbGP/l025M/j4rlxT6JBz bx5g+M0/74l2mFHuhSOhLeR2IafiPjUV0sxcNO81SctCvi5pvr84j3t528fBsWOHvyrO o/L8oOIMpUe+JnwREIXRzZxBpShtA1ghGn39mdvXl6QqUDxCjZ1xsDlM7AP0IoRiBShg 0+Ikbf6bGI0Z+ly+xUyp2Zjowo905t7Vcp5rAYmfHprrBVFAtKtiAFZTpxrbJZlwiiux HaGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent: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=Q7/S8vqkDSWxx7Uxlyc/1eZ/2ucSPvBu1sfKs/yXkYI=; fh=TdU2uh/YgCNbsUMQTg2WBgIlDkCy2MXSrlthNLdNUds=; b=LTtMCr2Vq/hg5TkmN6yCGnCs3Cz9Hmo4ICsWFZTiAEaoJQ+7jC6ooACvDXyUnm8z/3 1LVOeL6SlqJMhhlnhWgyGC8v3Uea6iBzXRiVlgL9H8rbdQRdPAWT31zWEkEQjSujzexf sTMkZCU9BwponUFPOBiyGAfFuaxJSzIJJ4hXTQcC2KFV0fBTjyt358jOXylL93OfTFkR k/hIPAFlOY53kDoU541DhGOWQc5wSRfGSDop2x83yJMR9sQmIlCVj6IkhUf9Mzaptn3P fT2PTBPkgxu6157gN7PQOMCxAW45eAA6l7Cp8ulK2ilrHFDp3Nmuba643f790S5RxO1S 37Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dBlwR6I2; spf=pass (google.com: domain of linux-kernel+bounces-23603-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23603-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s16-20020a170903321000b001b3d6c68bd1si973399plh.643.2024.01.11.04.48.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 04:48:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23603-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dBlwR6I2; spf=pass (google.com: domain of linux-kernel+bounces-23603-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23603-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8953C2825AF for ; Thu, 11 Jan 2024 12:48:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 678EA15E9B; Thu, 11 Jan 2024 12:47:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dBlwR6I2" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 BD1AF15E85; Thu, 11 Jan 2024 12:47:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1704977275; x=1736513275; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=cYs9Y/tzmUUmAlPWCC8CezHNT235rZZV4IJuzj8AYyE=; b=dBlwR6I2eGokefQ3FnJKpQePHadNesdC7BiJr8kCBh5MG+qOoAtwWmkZ G14GSsOGHX7oQz8aTs3ZfEMRVF9tBkF6bY8QAj+T/iEiSm/iPZwLgkvH5 WhWUX0p7wJnP0CENQquKv7x+At6f5oBvy9V+Qvl6VwMYH4/nGjZD/vWK4 8sUILGa0b8wteSQhgclMeOBJioAPLvHy0fg5h6zv4MBh51PBy6fIwEuKj pPIgBwlLh+CbMesXauGxux9mgfBN/XLpT0caR+YYZ8HV20l8Wxyae9j08 s2jb5z7/g1ate+Lzsm/RR+2xrPWagvygfWZ2/zFvaVxuA+xDS9zlFYLJN w==; X-IronPort-AV: E=McAfee;i="6600,9927,10949"; a="12190679" X-IronPort-AV: E=Sophos;i="6.04,186,1695711600"; d="scan'208";a="12190679" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2024 04:47:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10949"; a="873011676" X-IronPort-AV: E=Sophos;i="6.04,186,1695711600"; d="scan'208";a="873011676" Received: from yy-desk-7060.sh.intel.com (HELO localhost) ([10.239.159.76]) by FMSMGA003.fm.intel.com with ESMTP; 11 Jan 2024 04:47:27 -0800 Date: Thu, 11 Jan 2024 20:47:27 +0800 From: Yuan Yao To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Like Xu Subject: Re: [PATCH 2/4] KVM: x86: Rely solely on preempted_in_kernel flag for directed yield Message-ID: <20240111124727.wsnmjrh6jdtdbeuo@yy-desk-7060> References: <20240110003938.490206-1-seanjc@google.com> <20240110003938.490206-3-seanjc@google.com> <20240110075520.psahkt47hoqodqqf@yy-desk-7060> 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: User-Agent: NeoMutt/20171215 On Wed, Jan 10, 2024 at 09:13:28AM -0800, Sean Christopherson wrote: > On Wed, Jan 10, 2024, Yuan Yao wrote: > > On Tue, Jan 09, 2024 at 04:39:36PM -0800, Sean Christopherson wrote: > > > @@ -13093,7 +13092,7 @@ bool kvm_arch_dy_has_pending_interrupt(struct kvm_vcpu *vcpu) > > > > > > bool kvm_arch_vcpu_preempted_in_kernel(struct kvm_vcpu *vcpu) > > > { > > > - return kvm_arch_vcpu_in_kernel(vcpu); > > > + return vcpu->arch.preempted_in_kernel; > > > } > > > > > > bool kvm_arch_dy_runnable(struct kvm_vcpu *vcpu) > > > @@ -13116,9 +13115,6 @@ bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu) > > > if (vcpu->arch.guest_state_protected) > > > return true; > > > > > > - if (vcpu != kvm_get_running_vcpu()) > > > - return vcpu->arch.preempted_in_kernel; > > > - > > > > Now this function accepts vcpu parameter but can only get information from > > "current" vcpu loaded on hardware for VMX. I'm not sure whether need > > "WARN_ON(vcpu != kvm_get_running_vcpu())" here to guard it. i.e. > > kvm_guest_state() still uses this function (although it did chekcing before). > > Eh, I don't think it's worth adding a one-off kvm_get_running_vcpu() sanity check. > In the vast majority of cases, if VMREAD or VMWRITE is used improperly, the > instruction will fail at some point due to the pCPU not having any VMCS loaded. > It's really just cross-vCPU checks that could silently do the wrong thing, and > those flows are so few and far between that I'm comfortable taking a "just get > it right stance". > > If we want to add sanity checks, I think my vote would be to plumb @vcpu down > into vmcs_read{16,32,64,l} and add sanity checks there, probably with some sort > of guard so that the sanity checks can be enabled only for debug kernels. I got your point. Reviewed-by: Yuan Yao