Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp1024085lqs; Fri, 14 Jun 2024 12:18:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVwroh13F4bH8HjwR0u18d37b7OJGUtvV2HkhLEyo6kvEUz7xX8IwWcVQuJCqwCEILPQxhhnBEDXQQGR/8Ax+NrQ/jzu6Kxb+02awlPyg== X-Google-Smtp-Source: AGHT+IGCUJreCFxVq6jJG8Iuq3LUux7F0cKME+EoT7GkC7ZaZjFNn6t+RruXKooTXPBjYGlWRh54 X-Received: by 2002:a05:651c:22b:b0:2ec:18c7:169f with SMTP id 38308e7fff4ca-2ec18c7193dmr18007281fa.0.1718392695809; Fri, 14 Jun 2024 12:18:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718392695; cv=pass; d=google.com; s=arc-20160816; b=R7avE6NzamrcIvYPXCdjVAVV65JQZnwyc0bmAMs9yEu72Ore38KDuqhem5dZWd0O3/ dm2EKjgywxIe4z7BUl7BNpkyDBYqHteiVc1C2oP4I+fuBb4d3d4r/8pN8fEKYfiGTo5P KQXgr3jYjPRH51Tw5q/mA3CAjrAGH9643lc3Fg9IQrRrMk872W211rd6HRMJp8xRUUZ9 I4K7F6ZgvlHLKNBBbcBEhpgYLjjRolfSJBnuKN32S/irJVRWguguPAsMFc19sOmegEd5 wu24X42OBluFaGolCj46l8AXaRiGuKDHgAw9lNRHuIGVZQ2sYD/Weq7JAtdqNUsKeZHQ qR+Q== 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=gkzyBBXAwCY3OzPK+SBz7H8Gt8fdJVI1ukS9jG1P/vI=; fh=kcQPmHMu6KYPjGszyQOGlsP61H/Kp0/TqfddCTEgnZE=; b=A/jHqNF9kh4C3ZexAxBqpmgErKXsmJkNobnVAtbmGknnK/5NbaFfeKKIPiLPSJ5qjz jgAaUMikh1uz7P2saY9FsmoWzm2Wzv472KbpTN6OurMNheKRImFYB2JKOLgUFLRL2eLd kqoEmlZnfaIsPDaeLkMRKrIn09xxDF1h2TiBd20lS97SAIFVHtPuRoLEeCb93EbLA5/W W+oybHxNx83kgNiFpGnzcaqnfU4Klfufk7s9Sibu1IwY1Wr9rFPUckanYA+c2w15/CSV fZuDkB1xu6O5kvCwp62uZaY1eQ/7CamvAvARGCMRRk4ciLfjc6r64hvlgCDW+bRFpEIu IKzg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="Uk/GR843"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-215446-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215446-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57cb7462700si2085579a12.619.2024.06.14.12.18.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 12:18:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215446-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="Uk/GR843"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-215446-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215446-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 B04571F258D5 for ; Fri, 14 Jun 2024 19:09:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BCA931A2FDC; Fri, 14 Jun 2024 19:09:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Uk/GR843" Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 B40BE1A2FAE for ; Fri, 14 Jun 2024 19:09:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718392171; cv=none; b=f4glhIOwkKSpEUVbGGvuX51ue0Jy424Oq9WHAZjW7TnH3j3V+bUe0c+S82V8u3qAJvIs1ejq6iCzltoHm09I7aZI+Ytarxk538KpiqanC9laNbOxOQ4r6caDvnQUFjR6CopetZS/4D8YhhilVW6uYJJOB1J1oYNPHBJCmOjrobw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718392171; c=relaxed/simple; bh=Wizhiytn4Lj3Shj2nqRLymOMjV8PCb5TMVol1RzlXWI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SvYLW+BTyPrHvDeP2n3SRWtkaGa3FV2XThvrlM7r14k2I2lWZ+AXPW8YgyNFhiVnHKupcM70mMv2yPxEEDC2CyYdXIe6blprPyEtQk2VJOsUKX0cOkWmA3HubvXSmg8XFNu73qOY79SanZtpUPSkUESeufTLpfFBYFnRFBkdJGM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Uk/GR843; arc=none smtp.client-ip=91.218.175.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: coltonlewis@google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1718392167; 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=gkzyBBXAwCY3OzPK+SBz7H8Gt8fdJVI1ukS9jG1P/vI=; b=Uk/GR843p9Box6vvqsaHG5/Rl57kIPIH+lAwURbqN6EOIWpimaV5f9KvkM310qiACy/fNc PF75FHaijo3O9EY3HAqFx+oCi4Runo9dXFhJd2kbkY4muHk/tGFsh2SMz1XfHfJtfRDOzQ h/aEl6tewTosCcf3fTQYa/N0oN1Zs5k= X-Envelope-To: kvm@vger.kernel.org X-Envelope-To: corbet@lwn.net X-Envelope-To: maz@kernel.org X-Envelope-To: james.morse@arm.com X-Envelope-To: suzuki.poulose@arm.com X-Envelope-To: yuzenghui@huawei.com X-Envelope-To: catalin.marinas@arm.com X-Envelope-To: will@kernel.org X-Envelope-To: linux-doc@vger.kernel.org X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: linux-arm-kernel@lists.infradead.org X-Envelope-To: kvmarm@lists.linux.dev Date: Fri, 14 Jun 2024 19:09:21 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Colton Lewis Cc: kvm@vger.kernel.org, Jonathan Corbet , Marc Zyngier , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Subject: Re: [PATCH v6] KVM: arm64: Add early_param to control WFx trapping Message-ID: References: <20240523174056.1565133-1-coltonlewis@google.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: <20240523174056.1565133-1-coltonlewis@google.com> X-Migadu-Flow: FLOW_OUT On Thu, May 23, 2024 at 05:40:55PM +0000, Colton Lewis wrote: > Add an early_params to control WFI and WFE trapping. This is to > control the degree guests can wait for interrupts on their own without > being trapped by KVM. Options for each param are trap and notrap. trap > enables the trap. notrap disables the trap. Note that when enabled, > traps are allowed but not guaranteed by the CPU architecture. Absent > an explicitly set policy, default to current behavior: disabling the > trap if only a single task is running and enabling otherwise. > > Signed-off-by: Colton Lewis > --- > v6: > * Rebase to v6.9.1 As in from the stable tree? Please base your patches on an -rc tag, and especially one from this release cycle. > +static bool kvm_vcpu_should_clear_twi(struct kvm_vcpu *vcpu) > +{ > + if (likely(kvm_wfi_trap_policy == KVM_WFX_NOTRAP_SINGLE_TASK)) > + return single_task_running() && > + (atomic_read(&vcpu->arch.vgic_cpu.vgic_v3.its_vpe.vlpi_count) || > + vcpu->kvm->arch.vgic.nassgireq); > + > + return kvm_wfi_trap_policy == KVM_WFX_NOTRAP; > +} Generally, it is more readable to organize your code in such a way that multiline statements are unnested as much as possible. So if you were to invert the if condition it'd become a bit cleaner. Here is what I plan on squashing into this patch, kvm_vcpu_should_clear_twe() got the same treatment for the sake of consistency. diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 9cddd1096b0a..53e23528d2cf 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -557,20 +557,20 @@ static void vcpu_set_pauth_traps(struct kvm_vcpu *vcpu) static bool kvm_vcpu_should_clear_twi(struct kvm_vcpu *vcpu) { - if (likely(kvm_wfi_trap_policy == KVM_WFX_NOTRAP_SINGLE_TASK)) - return single_task_running() && - (atomic_read(&vcpu->arch.vgic_cpu.vgic_v3.its_vpe.vlpi_count) || - vcpu->kvm->arch.vgic.nassgireq); + if (unlikely(kvm_wfi_trap_policy != KVM_WFX_NOTRAP_SINGLE_TASK)) + return kvm_wfi_trap_policy == KVM_WFX_NOTRAP; - return kvm_wfi_trap_policy == KVM_WFX_NOTRAP; + return single_task_running() && + (atomic_read(&vcpu->arch.vgic_cpu.vgic_v3.its_vpe.vlpi_count) || + vcpu->kvm->arch.vgic.nassgireq); } static bool kvm_vcpu_should_clear_twe(struct kvm_vcpu *vcpu) { - if (likely(kvm_wfe_trap_policy == KVM_WFX_NOTRAP_SINGLE_TASK)) - return single_task_running(); + if (unlikely(kvm_wfe_trap_policy != KVM_WFX_NOTRAP_SINGLE_TASK)) + return kvm_wfe_trap_policy == KVM_WFX_NOTRAP; - return kvm_wfe_trap_policy == KVM_WFX_NOTRAP; + return single_task_running(); } void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) -- Thanks, Oliver