From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5B483C27C6E for ; Fri, 14 Jun 2024 19:09:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gkzyBBXAwCY3OzPK+SBz7H8Gt8fdJVI1ukS9jG1P/vI=; b=xYb9fdAGFP9U8TyBmHF/NfExM9 eSNNVgz7744wfAGJ5MfJZT4ttVKzEC0S7nDmKIcXfxnU72iI9nYZyrOLlLp86U3jzrcoHasrqxYch gA1qi7KqPylSyC7AV1oCuRyyybLqxD50N4JapbHBUlJIuka1bJPlezUSMzBzq1FjgVlzkg/7MVsk6 /iTky8DYuFU96P4ZSn6IjoLTsy7AqBWNHyKsBqm6VrHPdYtYYJR4GgVDD4yduMRtT+H2fK63gA+tp KI2bl2RDlPkv+8PikifkFq9aW3Wu5Q1QO1DJnNHF9fnrGrQL06iuA5xtb0euFwjqrthwR2lPBeQT9 CHreYm5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sICIn-00000003rI6-2qB9; Fri, 14 Jun 2024 19:09:33 +0000 Received: from out-171.mta0.migadu.com ([91.218.175.171]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sICIk-00000003rHX-3N5P for linux-arm-kernel@lists.infradead.org; Fri, 14 Jun 2024 19:09:32 +0000 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> 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240614_120931_161123_46ACBF61 X-CRM114-Status: GOOD ( 18.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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