From patchwork Mon Jan 29 21:39:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13536442 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 5BA1EC47DA9 for ; Mon, 29 Jan 2024 21:39:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=oSB04HTLYV/jrjfQ3G35QT/1bvsgm1zEvfmhSKd+oA4=; b=vT3 xA9F97Orw2hwQRdKCC5mXDK3ldul+F7R/p/A4m/9A5ugKPJUFnvzl+4grQ7tSu8tPh5hkrC8PiBL+ DIjhMsX64ZCT63rw3p3tI4j8ZzvlbjT2NsMXItXQjBhkkAIH4YY+ss5DH+lsjK4X1YoVZjTy5HaW7 tqijFIk3WgW19sgCHViiUDSNLH8LLwILGIhCVPvDgYczEFL+FyjGchAp6Kvsq4tLJhbW0ldGQ3i1Y u2CxldYO8wcoXwFsGsNwvAT4ZOLA6uQI0EtISDJDG++eaA/ghaV9MJFw8uJpX3sfTDoIjbKItSnr1 T/fJnrgQofSyBk9GnI0tzyXTD+HZloA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rUZLt-0000000EO5F-0frX; Mon, 29 Jan 2024 21:39:37 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rUZLq-0000000EO4n-0oaI for linux-arm-kernel@lists.infradead.org; Mon, 29 Jan 2024 21:39:35 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-60297bb7d44so60726887b3.0 for ; Mon, 29 Jan 2024 13:39:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706564371; x=1707169171; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=B99eaBaQvufEj95SWhNrEVaGQs5nxLAIqm27nnip6fg=; b=vZMlRKYod2+D2VzuNkTivgKRyhMJ+9q0/nEF+ZEZvS7WgY1dth3fv3RmWa8QU1pdA0 YSaY1uAbDDxNi7vl+zVu9WVVuuVfu7+aGNbZh4ZMUIKPbmkUC3LyoVH5LNn48uSDC27W pa3ullX7THdRzst5CQCEVHSTA7ohL3ti3Wnhe5ywyZHFTbhWGns1QX3Tkf5b+cXvQbOY Bd9ullBxNdMB2Dyh3/el2bYm9pZBDqDfdjO7NElgdsju8aKyeDl0Yhsf0MwHtLg8YeFM KALqqvvL/JGfBabNGomIhrXLR+PS3NqHD0K5EBaLR+9uta7874eyoq61aJ94LSFbjsd5 w0YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706564371; x=1707169171; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=B99eaBaQvufEj95SWhNrEVaGQs5nxLAIqm27nnip6fg=; b=WxPiLRrY9NAU7jvBLOowyj7DiPexQ9DRsKjPVfRD+P5lLtepcCs+wckl9HNoN0LyUI tzjiOYJlTKKhkenoxxAXWMPMWmkCO14Nszc08x9j6VJLPwxKY2qz7DgB8Lc/Db4dXPCo DYDFOHw6MP+lwXZeHc+dPFMsLRigCPom1wQmxlkrfw4p6baCuF/ZmJmkwkPbh6meuTEG HViSLtZ7NPrHXHobQ52oOJ05yXl5T3lViAKwZtvaqiRisNcmXfWFQBfcdsIp1s92zL0w wsKPWnOYRNXejVvfTvA7FEhmx6EmG7pgu2LHOXvfP3EZq9BglmE0SQt88WWHCs2D9OMs Gp+A== X-Gm-Message-State: AOJu0YwbKO+ovWIRkrUHfZFIhFLxq4hBA7nsDzIws97lzHmwaGXQeujo l96qwtAaLY6q+8cPoMFHKhWYeBXxzyg9FiqrHVs3Fuld8HTSzdwdjDgrh8YWcMf9HyZUofXPz+E 2ron2I6TuWkAbDjb/CVfA+Q== X-Google-Smtp-Source: AGHT+IGygDA4Yqae/lvO9WyCp0eJko74aZVetrKCwp+siiLUcGXRBnWtoHzcunXD7W6Fuab5xM5aed9VfSPBn+KUWA== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:14ce]) (user=coltonlewis job=sendgmr) by 2002:a05:6902:2082:b0:dc2:5525:f6b with SMTP id di2-20020a056902208200b00dc255250f6bmr2459078ybb.7.1706564370856; Mon, 29 Jan 2024 13:39:30 -0800 (PST) Date: Mon, 29 Jan 2024 21:39:17 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240129213918.3124494-1-coltonlewis@google.com> Subject: [PATCH] KVM: arm64: Add capability for unconditional WFx passthrough From: Colton Lewis To: kvm@vger.kernel.org Cc: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Paolo Bonzini , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Colton Lewis X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240129_133934_255957_4108F05A X-CRM114-Status: GOOD ( 14.37 ) 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 Add KVM_CAP_ARM_WFX_PASSTHROUGH capability to always allow WFE/WFI instructions to run without trapping. Current behavior is to only allow this if the vcpu is the only task running. This commit keeps the old behavior when the capability is not set. This allows userspace to set deterministic behavior and increase efficiency for platforms with direct interrupt injection support. The implementation adds a new flag KVM_ARCH_FLAG_WFX_PASSTHROUGH_ENABLED to kvm.arch.flags. Signed-off-by: Colton Lewis --- arch/arm64/include/asm/kvm_host.h | 2 ++ arch/arm64/kvm/arm.c | 7 ++++++- include/uapi/linux/kvm.h | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) This patch is based on v6.8-rc1 -- 2.43.0.429.g432eaa2c6b-goog diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 21c57b812569..e0d5ec2983fa 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -274,6 +274,8 @@ struct kvm_arch { #define KVM_ARCH_FLAG_TIMER_PPIS_IMMUTABLE 6 /* Initial ID reg values loaded */ #define KVM_ARCH_FLAG_ID_REGS_INITIALIZED 7 + /* Never trap WFE/WFI instructions */ +#define KVM_ARCH_FLAG_WFX_PASSTHROUGH_ENABLED 8 unsigned long flags; /* VM-wide vCPU feature set */ diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index a25265aca432..6d993991bd7a 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -116,6 +116,10 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, } mutex_unlock(&kvm->slots_lock); break; + case KVM_CAP_ARM_WFX_PASSTHROUGH: + r = 0; + set_bit(KVM_ARCH_FLAG_WFX_PASSTHROUGH_ENABLED, &kvm->arch.flags); + break; default: r = -EINVAL; break; @@ -456,7 +460,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) if (kvm_arm_is_pvtime_enabled(&vcpu->arch)) kvm_make_request(KVM_REQ_RECORD_STEAL, vcpu); - if (single_task_running()) + if (single_task_running() || + test_bit(KVM_ARCH_FLAG_WFX_PASSTHROUGH_ENABLED, &vcpu->kvm->arch.flags)) vcpu_clear_wfx_traps(vcpu); else vcpu_set_wfx_traps(vcpu); diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index c3308536482b..7635b5cd2b3b 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1155,6 +1155,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_MEMORY_ATTRIBUTES 233 #define KVM_CAP_GUEST_MEMFD 234 #define KVM_CAP_VM_TYPES 235 +#define KVM_CAP_ARM_WFX_PASSTHROUGH 236 #ifdef KVM_CAP_IRQ_ROUTING