Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp647409rdb; Mon, 29 Jan 2024 13:39:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IFo5U8WT0M1Ise1uMFRShR9AUx4KThSkRScwDyQKPVd0BDvC+53qpyD0Yw8wn0YDyajZWgI X-Received: by 2002:a05:622a:138d:b0:42a:a6ed:5b7b with SMTP id o13-20020a05622a138d00b0042aa6ed5b7bmr2955744qtk.12.1706564382487; Mon, 29 Jan 2024 13:39:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706564382; cv=pass; d=google.com; s=arc-20160816; b=p1oYgevqsw2+DkGyk8+J7lWwjWth4+PHoY45eMHPjdClCAGNR4NL4QqxSbBw8O6Wlq moahYGJ4CUBn/9KXU2iD2ktzBH3ANb+ia5aBhThturPWSOXq0rT6ZaBDaNO4KSAlgwdl yV5QpmLaEI5CJOo1lLabib6yn0mV3crQUJ19RyDY+NUPxB2/LgwaCQEvWJXKhZ41LEZY UC4zJakBNGDk+baxdYDZson45I+x2CZP5oPv49IuMcb7UmLpij3/+Sgc06eA0uoY+0JD t+TASlMT6ixoxRkC9pVrJM0Ysgfl7baFyfL1VT41N5xLddem86I+LaJMcUhjF0Sl3s5i qfnA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=B99eaBaQvufEj95SWhNrEVaGQs5nxLAIqm27nnip6fg=; fh=+XovCp65kk2d2HyRn3SbQjumgqcLT1OcAd0O4ekipq4=; b=dBSVW8FdtuN9zoI6vSmlvwhXCxpgrrnOY+6ItfA3t2BMSoKyxG4eR2BptBtimgk6Bv lHKl4ccZ1Qy9l75ktaanLWRO6AJDoRQ1s1eU/tPAVZQIMWe7i/gZZxI7QMKj7uefOQBD pzYaaW3etwksHxo3B8W7ci0QrRWh2Vh0GIC5/3ttr7kWOQsKo77smN0UNfyl7EYKhGCi fcKQjPUE92ObcL2z9dZpWFZI9r58rnZyMmMys+T4juA3jOCNvGK5xgXfOBtH5tFe2ezk 3hwGj4ixgK5gpGcoXhaVwpdU/VEBRgLhot8kEkpy3TaKr0d6ZxyxepdB3A8lwPcv5ke7 ROHA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZumjhOHj; arc=pass (i=1 spf=pass spfdomain=flex--coltonlewis.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-43530-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43530-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g11-20020ac87f4b000000b0042a87e2b8a6si7173109qtk.770.2024.01.29.13.39.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 13:39:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-43530-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZumjhOHj; arc=pass (i=1 spf=pass spfdomain=flex--coltonlewis.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-43530-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43530-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 3E16F1C22569 for ; Mon, 29 Jan 2024 21:39:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 34C57158D99; Mon, 29 Jan 2024 21:39:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZumjhOHj" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 C7C721586CE for ; Mon, 29 Jan 2024 21:39:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706564373; cv=none; b=rLOKs61EqxnFVLX0aQ2KInvNQ9iolMDm8xKTVjwdZOwJIscobkfRue0AoD58JXTN+3sOaKughIEWKCYtwdjsfPevhXkHokkEULQ1iwnQG7I3lgeHnJVbogaSZrtod2IgtnakBqTUPSSou88j/a2wuUGcKrHUwFnN+fcAHvGVi00= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706564373; c=relaxed/simple; bh=7Nu5d56ZeDA6l5eLrmk49xSbFqNKeDMhhp/l9C/XfqI=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=LMF9UOUX77/aOsJI4LHHqd6OKJyC6RV5/DAy+gdXlNfKefRAucU3BWuw2EwhVjV2cDT292gsQrix+zEQTz/JHKhU8PlX7C55mQBZ+cNspzSftzDNBJdnGevO43lLcx2A7Wy88iu5rrvJ0Q8m/OITuVRaJin+uzTmZs33fWazZus= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ZumjhOHj; arc=none smtp.client-ip=209.85.219.202 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--coltonlewis.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc221fad8c7so5076965276.3 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=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=B99eaBaQvufEj95SWhNrEVaGQs5nxLAIqm27nnip6fg=; b=ZumjhOHjWvebavKmoiTpwKV2HZOWh2JrXNMNeai7+UQ+vz7+V3W+f/UYt9XTAVlNzf iqtFgi60YpN800Qku2RlBwzTwYOu7pM1KXzDdtIu1aV6KHygnHcCMYLlbbRKvggcHKIT GzklPzp+2CHjdnQVUhbyvvYBSrTrj/DP9S9tkNK7HESw5NsQIzYH4y95cbfa9o3pjH3n uCTL2DuDLbKAXicEt6/nHykZkihWKp/DZqyIGeIWxs08jzWl1k76NhYeA8dByvIGox9n uNLQUwnGNQIymH/eHYbvO4tq26vKxYZwq+Td+ohxPvSTzWDkh3H7MAklRCH+l9//61b/ c37Q== 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=FjkPsLsZAAfsO0Ha6ur8XGEbrGx7tK9r9p7WJYOH4+gywU4EpbHCfvvj7XXny1vmQc pZHIs5v1w/lk4x8Tyi2wiNkdBnxrdhlW+LtyT3qA9onco8M0K3U1+oeStttMJYBhkg1n 7T8JzT2mbZCKzVxuvLwXM+S/yBkNlBaYaTadJR2qEr9CKghr4QJyaV6mCjiStmMUiIZy QsJayn9kcGKc7ILKZw8Y5d/BUC6KWRF9okfKxpOlHw0TZGTMd5ndribJTzZJpnUJyivf ZriMQyP+ATbTj/euSg3FASXsSCauc8coJW7+WVwauyNfK7KxgsgDNpYKWC6ep2EUNbNL uf1w== X-Gm-Message-State: AOJu0YxzKGZYZvijKU3KLkJnvEE+PhFTnDpGuX/Vv7AlccTD9mLhy+9B 04O3XcwjYqecSxfV+A8IXldlaVWUo/ZZ9GVWG/aIBQtP+gNZv00iwZ06vuniz2/Gr8EhrgXEIkU M2Xr4KMoJHnZC8ycKBf2BbQ== 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 Content-Type: text/plain; charset="UTF-8" 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 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 -- 2.43.0.429.g432eaa2c6b-goog