From patchwork Tue Sep 29 09:17:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingyi Wang X-Patchwork-Id: 11805427 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6561D6CB for ; Tue, 29 Sep 2020 09:19:24 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2319420848 for ; Tue, 29 Sep 2020 09:19:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="u5oK4R/V" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2319420848 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6IiVwL5FT6h7ufGeOdNdfipEvBzUcL7ekr2IPYaHLOg=; b=u5oK4R/V7IL65KpAo8vLcdef4 a1q9kmt0cAo7ZHhXPMM7DyL4GQ/GpWpN29ouwulXVFrXOfoQ8eDUjTLfcmNEf0jK0lKaQWUTAZk6A KgZk1d6bVXm+ONmU/hmopHXyAOk9xneOicZUyDXGhLWiQ4mnS9cNZRqdmou6ypzkVelrn5TXbqqqt TRu4/IJEufLFJPzqTMZpAjU+11Jci9RDtiWJOEk7ehAO00JXaSacuBEf6RsnJUsPDK7Z44g0pUfcA 9/qxkHT29RbZZvnEw7/qNXZ1tbu45LB6ByAXtyLEkHa4vAjizjN68WvOyeiKf0OYGPNNnlbQBsOgd Ytdsz8FTw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNBmh-0003qE-VU; Tue, 29 Sep 2020 09:18:56 +0000 Received: from szxga05-in.huawei.com ([45.249.212.191] helo=huawei.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNBm3-0003Wm-Bq for linux-arm-kernel@lists.infradead.org; Tue, 29 Sep 2020 09:18:44 +0000 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 7CC37386EB632C20326B; Tue, 29 Sep 2020 17:18:02 +0800 (CST) Received: from DESKTOP-FPN2511.china.huawei.com (10.174.187.69) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Tue, 29 Sep 2020 17:17:56 +0800 From: Jingyi Wang To: , , Subject: [RFC PATCH 1/4] arm64: cpufeature: TWED support detection Date: Tue, 29 Sep 2020 17:17:24 +0800 Message-ID: <20200929091727.8692-2-wangjingyi11@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200929091727.8692-1-wangjingyi11@huawei.com> References: <20200929091727.8692-1-wangjingyi11@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.69] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200929_051815_698359_51FC51FF X-CRM114-Status: GOOD ( 12.25 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [45.249.212.191 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [45.249.212.191 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, catalin.marinas@arm.com, wangjingyi11@huawei.com, shameerali.kolothum.thodi@huawei.com, yezengruan@huawei.com, fanhenglong@huawei.com, james.morse@arm.com, prime.zeng@hisilicon.com, maz@kernel.org, wanghaibin.wang@huawei.com, will@kernel.org, julien.thierry.kdev@gmail.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Zengruan Ye TWE Delay is an optional feature in ARMv8.6 Extentions. This patch detect this feature. Signed-off-by: Zengruan Ye Signed-off-by: Jingyi Wang --- arch/arm64/Kconfig | 10 ++++++++++ arch/arm64/include/asm/cpucaps.h | 3 ++- arch/arm64/kernel/cpufeature.c | 12 ++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 6d232837cbee..fe66f4fc5f49 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1666,6 +1666,16 @@ config ARCH_RANDOM endmenu +menu "ARMv8.6 architectural features" + +config ARM64_TWED + bool "Enable suppot for delayed trapping of WFE" + default y + help + Delayed Trapping of WFE (part of the ARMv8.6 Extensions) + +endmenu + config ARM64_SVE bool "ARM Scalable Vector Extension support" default y diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cpucaps.h index 07b643a70710..7b8f018d142b 100644 --- a/arch/arm64/include/asm/cpucaps.h +++ b/arch/arm64/include/asm/cpucaps.h @@ -64,7 +64,8 @@ #define ARM64_BTI 54 #define ARM64_HAS_ARMv8_4_TTL 55 #define ARM64_HAS_TLB_RANGE 56 +#define ARM64_HAS_TWED 57 -#define ARM64_NCAPS 57 +#define ARM64_NCAPS 58 #endif /* __ASM_CPUCAPS_H */ diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 6424584be01e..d042d32a1144 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -2120,6 +2120,18 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .min_field_value = ID_AA64PFR1_BT_BTI, .sign = FTR_UNSIGNED, }, +#endif +#ifdef CONFIG_ARM64_TWED + { + .desc = "Delayed Trapping of WFE", + .capability = ARM64_HAS_TWED, + .type = ARM64_CPUCAP_SYSTEM_FEATURE, + .matches = has_cpuid_feature, + .sys_reg = SYS_ID_AA64MMFR1_EL1, + .field_pos = ID_AA64MMFR1_TWED_SHIFT, + .sign = FTR_UNSIGNED, + .min_field_value = 1, + }, #endif {}, }; From patchwork Tue Sep 29 09:17:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingyi Wang X-Patchwork-Id: 11805471 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CDD0E6CB for ; Tue, 29 Sep 2020 09:40:37 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E03420757 for ; Tue, 29 Sep 2020 09:40:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="wTM9nimw"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="glx4UC4P" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E03420757 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=NIiZehGSuldy1a8i9bGK/uhfoOPLa2AsdkcbZScPkoI=; b=wTM9nimwP6dIKbTmMDKAejiI6 fMpa3Ldx5+jb9xaxhcZ2z5aeETbYnVy/AunSm1Ff+p4J3D0W7BCji/lylyBysSH0/G87sXAQpO4Ed aB5GyEE9kNvHpNeP4FvM6xOF7Bx8NUYTsBMOJq53dtWEcFJ+lKDd46bIcV+gkdvKwt7wCo/ra+jzD vveoYs1CeWBid4sMgc4kbHdJHJq9vfD81wtgUKHH5PwpSW6tIDfaB+aqvuBNCcm0V3fo2y7d/Zf7Y kPTrFxYD0OfR1lrjYmS19OZEpPKh80Bgv7MNj7ZXNfp0PWqRF77W1sUs56RkeuFu7TxjyVyLhdKLO H65wdR7QQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNC7T-0000z2-DB; Tue, 29 Sep 2020 09:40:23 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNC7N-0000vN-7L for linux-arm-kernel@merlin.infradead.org; Tue, 29 Sep 2020 09:40:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=tNMArxxLJm7EtVb24dZeLL8/NXoN+ZpYunEwW1AXakc=; b=glx4UC4Pmu1myuB70dlX7Ia6WR kUYTGTGHAIesDLB0K38DWrb5BpgCDAU+5Qco7qNmqmZv5IgRBX+aaghe6FfZJqXrqidqi4VvjTGAQ 63XI601hCH9fLbLTA+BOqoOnfUHIiL+uer/yXnKeWSw2zmbxh+E+mwtr/h/YVo0zmGeYFoIKZqGuG FalNo2dI5RQmjQ9eGi0eJKx4wvDoI1ayu8U1PuZsg5XqoPmm2IrnVBr38+NrYZtx3Fn11tVCpCuD0 2lT4oEKVVbRvqKZWcudcYA3J+VzDtyPVBt6d0e9srIfDTHcEMLzLVWjdvIkyARDazICiJZwKtnyDM RzdqJgCg==; Received: from szxga05-in.huawei.com ([45.249.212.191] helo=huawei.com) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNBm2-00062Z-QP for linux-arm-kernel@lists.infradead.org; Tue, 29 Sep 2020 09:18:21 +0000 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 9D8AAFE6DE539D3107D0; Tue, 29 Sep 2020 17:18:07 +0800 (CST) Received: from DESKTOP-FPN2511.china.huawei.com (10.174.187.69) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Tue, 29 Sep 2020 17:17:57 +0800 From: Jingyi Wang To: , , Subject: [RFC PATCH 2/4] KVM: arm64: Make use of TWED feature Date: Tue, 29 Sep 2020 17:17:25 +0800 Message-ID: <20200929091727.8692-3-wangjingyi11@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200929091727.8692-1-wangjingyi11@huawei.com> References: <20200929091727.8692-1-wangjingyi11@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.69] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200929_101815_732940_7826EC1B X-CRM114-Status: GOOD ( 14.99 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.4.4 on casper.infradead.org summary: Content analysis details: (-4.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [45.249.212.191 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [45.249.212.191 listed in wl.mailspike.net] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, catalin.marinas@arm.com, wangjingyi11@huawei.com, shameerali.kolothum.thodi@huawei.com, yezengruan@huawei.com, fanhenglong@huawei.com, james.morse@arm.com, prime.zeng@hisilicon.com, maz@kernel.org, wanghaibin.wang@huawei.com, will@kernel.org, julien.thierry.kdev@gmail.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org For HCR_EL2, TWEDEn(bit[59]) decides whether TWED is enabled, and when the configurable delay is enabled, TWEDEL (bits[63:60]) encodes the minimum delay in taking a trap of WFE caused by the TWE bit in this register as 2^(TWEDEL + 8) cycles. We use two kernel parameters "twed_enable" and "twed" to configure the register. Signed-off-by: Zengruan Ye Signed-off-by: Jingyi Wang --- arch/arm64/include/asm/kvm_arm.h | 5 +++++ arch/arm64/include/asm/kvm_emulate.h | 32 ++++++++++++++++++++++++++++ arch/arm64/include/asm/kvm_host.h | 13 +++++++++++ arch/arm64/include/asm/virt.h | 8 +++++++ arch/arm64/kvm/arm.c | 22 +++++++++++++++++++ 5 files changed, 80 insertions(+) diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h index 1da8e3dc4455..03afb2921f1c 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -12,6 +12,11 @@ #include /* Hyp Configuration Register (HCR) bits */ +#define HCR_TWEDEL_SHIFT 60 +#define HCR_TWEDEL_MAX (UL(0xf)) +#define HCR_TWEDEL_MASK (HCR_TWEDEL_MAX << HCR_TWEDEL_SHIFT) +#define HCR_TWEDEL (UL(1) << HCR_TWEDEL_SHIFT) +#define HCR_TWEDEN (UL(1) << 59) #define HCR_FWB (UL(1) << 46) #define HCR_API (UL(1) << 41) #define HCR_APK (UL(1) << 40) diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index 1cc5f5f72d0b..1a9cce836170 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -102,6 +102,38 @@ static inline void vcpu_set_wfx_traps(struct kvm_vcpu *vcpu) vcpu->arch.hcr_el2 |= HCR_TWI; } +#ifdef CONFIG_ARM64_TWED +static inline void vcpu_twed_enable(struct kvm_vcpu *vcpu) +{ + vcpu->arch.hcr_el2 |= HCR_TWEDEN; +} + +static inline void vcpu_twed_disable(struct kvm_vcpu *vcpu) +{ + vcpu->arch.hcr_el2 &= ~HCR_TWEDEN; +} + +static inline void vcpu_twed_init(struct kvm_vcpu *vcpu) +{ + vcpu->arch.twed = (u64)twed; +} + +static inline void vcpu_set_twed(struct kvm_vcpu *vcpu) +{ + u64 delay = vcpu->arch.twed; + if (delay > HCR_TWEDEL_MAX) + delay = HCR_TWEDEL_MAX; + + vcpu->arch.hcr_el2 &= ~HCR_TWEDEL_MASK; + vcpu->arch.hcr_el2 |= (delay << HCR_TWEDEL_SHIFT); +} +#else +static inline void vcpu_twed_enable(struct kvm_vcpu *vcpu) {}; +static inline void vcpu_twed_disable(struct kvm_vcpu *vcpu) {}; +static inline void vcpu_twed_init(struct kvm_vcpu *vcpu) {}; +static inline void vcpu_set_twed(struct kvm_vcpu *vcpu) {}; +#endif + static inline void vcpu_ptrauth_enable(struct kvm_vcpu *vcpu) { vcpu->arch.hcr_el2 |= (HCR_API | HCR_APK); diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 905c2b87e05a..380cd9c8ad0f 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -371,6 +371,11 @@ struct kvm_vcpu_arch { u64 last_steal; gpa_t base; } steal; + +#ifdef CONFIG_ARM64_TWED + /* WFE trap delay */ + u64 twed; +#endif }; /* Pointer to the vcpu's SVE FFR for sve_{save,load}_state() */ @@ -688,4 +693,12 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu); #define kvm_arm_vcpu_sve_finalized(vcpu) \ ((vcpu)->arch.flags & KVM_ARM64_VCPU_SVE_FINALIZED) +#ifdef CONFIG_ARM64_TWED +#define use_twed() (has_twed() && twed_enable) +extern bool twed_enable; +extern unsigned int twed; +#else +#define use_twed() false +#endif + #endif /* __ARM64_KVM_HOST_H__ */ diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h index 09977acc007d..1a9e437e5bf6 100644 --- a/arch/arm64/include/asm/virt.h +++ b/arch/arm64/include/asm/virt.h @@ -98,6 +98,14 @@ static __always_inline bool has_vhe(void) return cpus_have_final_cap(ARM64_HAS_VIRT_HOST_EXTN); } +static __always_inline bool has_twed(void) +{ + if (cpus_have_const_cap(ARM64_HAS_TWED)) + return true; + + return false; +} + #endif /* __ASSEMBLY__ */ #endif /* ! __ASM__VIRT_H */ diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index b588c3b5c2f0..5b5e8b14dcd5 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -59,6 +59,14 @@ static bool vgic_present; static DEFINE_PER_CPU(unsigned char, kvm_arm_hardware_enabled); DEFINE_STATIC_KEY_FALSE(userspace_irqchip_in_use); +#ifdef CONFIG_ARM64_TWED +bool twed_enable = false; +module_param(twed_enable, bool, S_IRUGO | S_IWUSR); + +unsigned int twed = 0; +module_param(twed, uint, S_IRUGO | S_IWUSR); +#endif + int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu) { return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE; @@ -270,6 +278,13 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) vcpu->arch.hw_mmu = &vcpu->kvm->arch.mmu; + if (use_twed()) { + vcpu_twed_enable(vcpu); + vcpu_twed_init(vcpu); + } else { + vcpu_twed_disable(vcpu); + } + err = kvm_vgic_vcpu_init(vcpu); if (err) return err; @@ -736,6 +751,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) kvm_arm_setup_debug(vcpu); + if (use_twed()) { + vcpu_twed_enable(vcpu); + vcpu_set_twed(vcpu); + } else { + vcpu_twed_disable(vcpu); + } + /************************************************************** * Enter the guest */ From patchwork Tue Sep 29 09:17:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingyi Wang X-Patchwork-Id: 11805473 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EBDE51580 for ; Tue, 29 Sep 2020 09:40:37 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A593F20773 for ; Tue, 29 Sep 2020 09:40:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="F7fUuVEx"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="rDDnEBl8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A593F20773 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1PYyqd3Pe5m2GttOLnQWbhIn/4oecJRdSCDb2SPUTJI=; b=F7fUuVExSiWKdwice7NJ7UU+n pXUqcwBbKQv0B8M5t4okYF58o/EpU9DrK3OUjDWt0PNUTcdOyFyuJVFEoRy2sGP1JgWhCVZMrYQMt GfwO/v3ZbTHL1C9AGmHu0fMbdLafJZvK6DVZMgxcQYHxwbfHk+VxgYNQ/RyI+3dy3Zr3wZKZP4zHD 0t0V4McmFYpEl7HFg90Q3ebX2iMt51UQ5/mCd45zNDgUegOrz+CPb+SsctwFsINez6zPxINkGxcdK nUdlLh/Oxn/TZBwZ815NMYCp3Vz4WrvKhSxqkQEKPEHQP2/LmrvCIg8C7c11/SuQ2RSZKRSpJRbRS eF0QX6aig==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNC7N-0000xg-2t; Tue, 29 Sep 2020 09:40:17 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNC7L-0000vN-4e for linux-arm-kernel@merlin.infradead.org; Tue, 29 Sep 2020 09:40:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=jYGqDxXgrvHhfr8kUdik0WSscujBEyuUkSITSC/wv04=; b=rDDnEBl8ogE+NAMX4zC18ua5l3 admBMpWRy2WTvdrpGqcJ1Z8I7SrJHMFdyu1DMb960hA8XoQCvOAPHXNVpGLB8nBmI00wu5NUwG6jk dg4Q8q2IO4nfem1tUAm3xuQy2yPYjtkihlIbjnYNgk6AeTOx4lxmSvIGL7Di9rKphpC00duUswvGh nuYYjyfpk56SJtCqYszPDuTQw5j/CzM7hIPVtPkOy+8SpphTjkSbgKa+L0UVcibrzO3MgRDsbGTFS dtYAUOAlzVFmc5wOVOagwe/0Dq1s9AY0sr08Xa1oYcWB5WU0n53m3s0o3gwUdoPm4g1gcPEfOjh3N czDbDlvA==; Received: from szxga05-in.huawei.com ([45.249.212.191] helo=huawei.com) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNBmE-000658-Br for linux-arm-kernel@lists.infradead.org; Tue, 29 Sep 2020 09:18:29 +0000 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id B1E9BF27A1E5B154B283; Tue, 29 Sep 2020 17:18:07 +0800 (CST) Received: from DESKTOP-FPN2511.china.huawei.com (10.174.187.69) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Tue, 29 Sep 2020 17:17:58 +0800 From: Jingyi Wang To: , , Subject: [RFC PATCH 3/4] KVM: arm64: Use dynamic TWE Delay value Date: Tue, 29 Sep 2020 17:17:26 +0800 Message-ID: <20200929091727.8692-4-wangjingyi11@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200929091727.8692-1-wangjingyi11@huawei.com> References: <20200929091727.8692-1-wangjingyi11@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.69] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200929_101826_825191_D9015FCB X-CRM114-Status: GOOD ( 15.34 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.4.4 on casper.infradead.org summary: Content analysis details: (-4.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [45.249.212.191 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [45.249.212.191 listed in wl.mailspike.net] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, catalin.marinas@arm.com, wangjingyi11@huawei.com, shameerali.kolothum.thodi@huawei.com, yezengruan@huawei.com, fanhenglong@huawei.com, james.morse@arm.com, prime.zeng@hisilicon.com, maz@kernel.org, wanghaibin.wang@huawei.com, will@kernel.org, julien.thierry.kdev@gmail.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org We implement two new kernel parameters for changing the delay adaptively: twed_grow and twed_shrink twed_grow affects the delay on WFE trap and twed_shrink does it on sched_in; depending on their value, the delay is modifier like this: twed_shrink/ | twed_grow | WFE trap exit | sched_in --------------+---------------+------------ < 1 | = twed | = twed otherwise | = twed + 1 | = twed - 1 Signed-off-by: Zengruan Ye Signed-off-by: Jingyi Wang --- arch/arm64/include/asm/kvm_emulate.h | 6 ++++++ arch/arm64/include/asm/kvm_host.h | 6 +++++- arch/arm64/kvm/arm.c | 32 ++++++++++++++++++++++++++++ arch/arm64/kvm/handle_exit.c | 2 ++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index 1a9cce836170..546d10b3b534 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -116,16 +116,22 @@ static inline void vcpu_twed_disable(struct kvm_vcpu *vcpu) static inline void vcpu_twed_init(struct kvm_vcpu *vcpu) { vcpu->arch.twed = (u64)twed; + vcpu->arch.twed_dirty = true; } static inline void vcpu_set_twed(struct kvm_vcpu *vcpu) { u64 delay = vcpu->arch.twed; + + if (!vcpu->arch.twed_dirty) + return; + if (delay > HCR_TWEDEL_MAX) delay = HCR_TWEDEL_MAX; vcpu->arch.hcr_el2 &= ~HCR_TWEDEL_MASK; vcpu->arch.hcr_el2 |= (delay << HCR_TWEDEL_SHIFT); + vcpu->arch.twed_dirty = false; } #else static inline void vcpu_twed_enable(struct kvm_vcpu *vcpu) {}; diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 380cd9c8ad0f..35d1953d9d35 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -375,6 +375,7 @@ struct kvm_vcpu_arch { #ifdef CONFIG_ARM64_TWED /* WFE trap delay */ u64 twed; + bool twed_dirty; #endif }; @@ -595,7 +596,6 @@ void kvm_arm_vcpu_ptrauth_trap(struct kvm_vcpu *vcpu); static inline void kvm_arch_hardware_unsetup(void) {} static inline void kvm_arch_sync_events(struct kvm *kvm) {} -static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} static inline void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu) {} void kvm_arm_init_debug(void); @@ -697,8 +697,12 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu); #define use_twed() (has_twed() && twed_enable) extern bool twed_enable; extern unsigned int twed; +void grow_twed(struct kvm_vcpu *vcpu); +void shrink_twed(struct kvm_vcpu *vcpu); #else #define use_twed() false +static inline void grow_twed(struct kvm_vcpu *vcpu) {}; +static inline void shrink_twed(struct kvm_vcpu *vcpu) {}; #endif #endif /* __ARM64_KVM_HOST_H__ */ diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 5b5e8b14dcd5..989bffdcb3e9 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -65,6 +65,32 @@ module_param(twed_enable, bool, S_IRUGO | S_IWUSR); unsigned int twed = 0; module_param(twed, uint, S_IRUGO | S_IWUSR); + +static unsigned int twed_grow = 0; +module_param(twed_grow, uint, S_IRUGO | S_IWUSR); + +static unsigned int twed_shrink = 0; +module_param(twed_shrink, uint, S_IRUGO | S_IWUSR); + +void grow_twed(struct kvm_vcpu *vcpu) +{ + u64 old = vcpu->arch.twed; + + if (old < HCR_TWEDEL_MAX && twed_grow) { + vcpu->arch.twed += 1; + vcpu->arch.twed_dirty = true; + } +} + +void shrink_twed(struct kvm_vcpu *vcpu) +{ + u64 old = vcpu->arch.twed; + + if (old > 0 && twed_shrink) { + vcpu->arch.twed -= 1; + vcpu->arch.twed_dirty = true; + } +} #endif int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu) @@ -108,6 +134,12 @@ static int kvm_arm_default_max_vcpus(void) return vgic_present ? kvm_vgic_get_max_vcpus() : KVM_MAX_VCPUS; } +void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) +{ + if (use_twed()) + shrink_twed(vcpu); +} + /** * kvm_arch_init_vm - initializes a VM data structure * @kvm: pointer to the KVM struct diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index 5d690d60ccad..2ad72defa3c9 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -91,6 +91,8 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu) { if (kvm_vcpu_get_esr(vcpu) & ESR_ELx_WFx_ISS_WFE) { trace_kvm_wfx_arm64(*vcpu_pc(vcpu), true); + if (use_twed()) + grow_twed(vcpu); vcpu->stat.wfe_exit_stat++; kvm_vcpu_on_spin(vcpu, vcpu_mode_priv(vcpu)); } else { From patchwork Tue Sep 29 09:17:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingyi Wang X-Patchwork-Id: 11805477 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E76FB618 for ; Tue, 29 Sep 2020 09:41:58 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A0D3620848 for ; Tue, 29 Sep 2020 09:41:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Q+TX+p/C"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="wL62J/pW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A0D3620848 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qxEBtz/KoAl/LPRztw9XT6zQIvMaBqhjdAqvLuP9VEs=; b=Q+TX+p/CcLXQApNA58O2B6qng yXLH8JZeU6W6kJXgb9Pn8HPayqt75DRiwNhQd6JRNGuGd8fK5kVctet0Uzo9hcfADcNXd+WU0f6M8 n/lr0WCtnzDotodm9oDnjNOsI7oWff+TmX2KGCnFO/im4RCOeIiV5iAcVVDPVF1nw176W7JCSnbOM /76qVvqYPz1H1ZNSuPJn8gMTDwE5EHm8eHZBUci2n8LmYCKikyopc3mKJX2NBIEncIOXO7Uj1ib/A EVGrXn7ddWr5vrMkIVW0+SDNgvW5IQD1DeAB11hgiUu18eCuivd0qEVGktIUzuGVZ0QxrHrQfqcEp f+S+5UHuA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNC7V-0000zU-Ql; Tue, 29 Sep 2020 09:40:25 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNC7O-0000vN-5P for linux-arm-kernel@merlin.infradead.org; Tue, 29 Sep 2020 09:40:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=XWrJh789QsYep8Qo5Nfx+qvyXRykT18V6hLkLBWuupg=; b=wL62J/pWzlvygWdbklJhlXwn02 35rejyYCGgP8ARM6urG7ohV8/p7viAnQJYtIFjcNYc5HSUaYyUXrBMAtZFZF7rnidPfR9DtVAjc6Q mNm/Do5VNYuRXAGBVQWMGwNvT7NKL4LCwVPj+5u/xNLquikkG73LaY9BVl9jYYN1zHbZLUSRe1IbV zbAh2B0Th+1j8h7Yw34RcQg0MP+HDaAczo3kTLvSERZzjhWFjwRH3VTBa5/PG7KBEtjdYRSCVieaL pu0wTZLIiN8NnOYSaajWk6X9HtPNt2w94j0qSefCo9IRLSr9b6zhXtU/nMmMVDjLNWFk4/r9yue1/ T1/figcw==; Received: from szxga05-in.huawei.com ([45.249.212.191] helo=huawei.com) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNBm3-00062a-48 for linux-arm-kernel@lists.infradead.org; Tue, 29 Sep 2020 09:18:20 +0000 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id A7ECDD523EC78719281F; Tue, 29 Sep 2020 17:18:07 +0800 (CST) Received: from DESKTOP-FPN2511.china.huawei.com (10.174.187.69) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Tue, 29 Sep 2020 17:17:58 +0800 From: Jingyi Wang To: , , Subject: [RFC PATCH 4/4] KVM: arm64: Add trace for TWED update Date: Tue, 29 Sep 2020 17:17:27 +0800 Message-ID: <20200929091727.8692-5-wangjingyi11@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200929091727.8692-1-wangjingyi11@huawei.com> References: <20200929091727.8692-1-wangjingyi11@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.69] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200929_101816_094048_3996B941 X-CRM114-Status: UNSURE ( 9.26 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.4.4 on casper.infradead.org summary: Content analysis details: (-4.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [45.249.212.191 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [45.249.212.191 listed in wl.mailspike.net] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, catalin.marinas@arm.com, wangjingyi11@huawei.com, shameerali.kolothum.thodi@huawei.com, yezengruan@huawei.com, fanhenglong@huawei.com, james.morse@arm.com, prime.zeng@hisilicon.com, maz@kernel.org, wanghaibin.wang@huawei.com, will@kernel.org, julien.thierry.kdev@gmail.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Zengruan Ye Add tracepoints for TWE delay value update Signed-off-by: Zengruan Ye Signed-off-by: Jingyi Wang --- arch/arm64/kvm/arm.c | 4 ++++ arch/arm64/kvm/trace_arm.h | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 989bffdcb3e9..c3d7a326bf1b 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -80,6 +80,8 @@ void grow_twed(struct kvm_vcpu *vcpu) vcpu->arch.twed += 1; vcpu->arch.twed_dirty = true; } + + trace_kvm_twed_update(vcpu->vcpu_id, vcpu->arch.twed, old); } void shrink_twed(struct kvm_vcpu *vcpu) @@ -90,6 +92,8 @@ void shrink_twed(struct kvm_vcpu *vcpu) vcpu->arch.twed -= 1; vcpu->arch.twed_dirty = true; } + + trace_kvm_twed_update(vcpu->vcpu_id, vcpu->arch.twed, old); } #endif diff --git a/arch/arm64/kvm/trace_arm.h b/arch/arm64/kvm/trace_arm.h index ff0444352bba..5081266399e8 100644 --- a/arch/arm64/kvm/trace_arm.h +++ b/arch/arm64/kvm/trace_arm.h @@ -367,6 +367,27 @@ TRACE_EVENT(kvm_timer_emulate, __entry->timer_idx, __entry->should_fire) ); +TRACE_EVENT(kvm_twed_update, + TP_PROTO(unsigned int vcpu_id, unsigned int new, unsigned int old), + TP_ARGS(vcpu_id, new, old), + + TP_STRUCT__entry( + __field( unsigned int, vcpu_id ) + __field( unsigned int, new ) + __field( unsigned int, old ) + ), + + TP_fast_assign( + __entry->vcpu_id = vcpu_id; + __entry->new = new; + __entry->old = old; + ), + + TP_printk("vcpu %u old %u new %u (%s)", + __entry->vcpu_id, __entry->old, __entry->new, + __entry->old < __entry->new ? "growed" : "shrinked") +); + #endif /* _TRACE_ARM_ARM64_KVM_H */ #undef TRACE_INCLUDE_PATH