From patchwork Wed Feb 24 16:35:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 12102135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5657CC433DB for ; Wed, 24 Feb 2021 16:39:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0C2E664EBA for ; Wed, 24 Feb 2021 16:39:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235390AbhBXQjI (ORCPT ); Wed, 24 Feb 2021 11:39:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:28910 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235406AbhBXQhV (ORCPT ); Wed, 24 Feb 2021 11:37:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614184555; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ul0Yt6zeiwAM8weYOyOSJ2OiEPiScZ2rMxR8/x//HFM=; b=GWJwJX4fvOpXLogQ5jfA0OnxicsIOGhgROOC2qozo7lolTq3HrxdaE+JaSETOqzPlMl9B8 vvhMTKcJm7nm6cm5yNiFulMtuIypya5ypQxeVdOHpAxIoy15lSUA1KX/h1O4yIDTkimI69 bqdEYpaE7X6nzZfHsRNsfR5Jgl/bGpY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-330-wGC310LYMCSX2952f1eVjw-1; Wed, 24 Feb 2021 11:35:52 -0500 X-MC-Unique: wGC310LYMCSX2952f1eVjw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2D497BBEF3 for ; Wed, 24 Feb 2021 16:35:51 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 265D419C71; Wed, 24 Feb 2021 16:35:49 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Subject: [PATCH kvm-unit-tests v2 1/4] x86: hyperv_stimer: keep SINT number parameter in 'struct stimer' Date: Wed, 24 Feb 2021 17:35:44 +0100 Message-Id: <20210224163547.197100-2-vkuznets@redhat.com> In-Reply-To: <20210224163547.197100-1-vkuznets@redhat.com> References: <20210224163547.197100-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org As a preparation to enabling direct synthetic timers support stop passing SINT number to stimer_start. Signed-off-by: Vitaly Kuznetsov --- x86/hyperv_stimer.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/x86/hyperv_stimer.c b/x86/hyperv_stimer.c index 75a69a127b4d..fa00dac4d66a 100644 --- a/x86/hyperv_stimer.c +++ b/x86/hyperv_stimer.c @@ -161,11 +161,10 @@ static void stimer_isr_auto_eoi(isr_regs_t *regs) static void stimer_start(struct stimer *timer, bool auto_enable, bool periodic, - u64 tick_100ns, int sint) + u64 tick_100ns) { u64 config, count; - timer->sint = sint; atomic_set(&timer->fire_count, 0); config = 0; @@ -173,7 +172,7 @@ static void stimer_start(struct stimer *timer, config |= HV_STIMER_PERIODIC; } - config |= ((u8)(sint & 0xFF)) << 16; + config |= ((u8)(timer->sint & 0xFF)) << 16; config |= HV_STIMER_ENABLE; if (auto_enable) { config |= HV_STIMER_AUTOENABLE; @@ -218,18 +217,29 @@ static void synic_disable(void) static void stimer_test_prepare(void *ctx) { + int vcpu = smp_id(); + struct svcpu *svcpu = &g_synic_vcpu[vcpu]; + struct stimer *timer1, *timer2; + write_cr3((ulong)ctx); synic_enable(); + synic_sint_create(SINT1_NUM, SINT1_VEC, false); synic_sint_create(SINT2_NUM, SINT2_VEC, true); + + timer1 = &svcpu->timer[0]; + timer2 = &svcpu->timer[1]; + + timer1->sint = SINT1_NUM; + timer2->sint = SINT2_NUM; } static void stimer_test_periodic(int vcpu, struct stimer *timer1, struct stimer *timer2) { /* Check periodic timers */ - stimer_start(timer1, false, true, ONE_MS_IN_100NS, SINT1_NUM); - stimer_start(timer2, false, true, ONE_MS_IN_100NS, SINT2_NUM); + stimer_start(timer1, false, true, ONE_MS_IN_100NS); + stimer_start(timer2, false, true, ONE_MS_IN_100NS); while ((atomic_read(&timer1->fire_count) < 1000) || (atomic_read(&timer2->fire_count) < 1000)) { pause(); @@ -242,7 +252,7 @@ static void stimer_test_periodic(int vcpu, struct stimer *timer1, static void stimer_test_one_shot(int vcpu, struct stimer *timer) { /* Check one-shot timer */ - stimer_start(timer, false, false, ONE_MS_IN_100NS, SINT1_NUM); + stimer_start(timer, false, false, ONE_MS_IN_100NS); while (atomic_read(&timer->fire_count) < 1) { pause(); } @@ -253,7 +263,7 @@ static void stimer_test_one_shot(int vcpu, struct stimer *timer) static void stimer_test_auto_enable_one_shot(int vcpu, struct stimer *timer) { /* Check auto-enable one-shot timer */ - stimer_start(timer, true, false, ONE_MS_IN_100NS, SINT1_NUM); + stimer_start(timer, true, false, ONE_MS_IN_100NS); while (atomic_read(&timer->fire_count) < 1) { pause(); } @@ -265,7 +275,7 @@ static void stimer_test_auto_enable_one_shot(int vcpu, struct stimer *timer) static void stimer_test_auto_enable_periodic(int vcpu, struct stimer *timer) { /* Check auto-enable periodic timer */ - stimer_start(timer, true, true, ONE_MS_IN_100NS, SINT1_NUM); + stimer_start(timer, true, true, ONE_MS_IN_100NS); while (atomic_read(&timer->fire_count) < 1000) { pause(); } @@ -282,7 +292,7 @@ static void stimer_test_one_shot_busy(int vcpu, struct stimer *timer) msg->header.message_type = HVMSG_TIMER_EXPIRED; wmb(); - stimer_start(timer, false, false, ONE_MS_IN_100NS, SINT1_NUM); + stimer_start(timer, false, false, ONE_MS_IN_100NS); do rmb(); From patchwork Wed Feb 24 16:35:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 12102139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30E70C433E0 for ; Wed, 24 Feb 2021 16:39:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D71B064EF1 for ; Wed, 24 Feb 2021 16:39:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234748AbhBXQjQ (ORCPT ); Wed, 24 Feb 2021 11:39:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43579 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235410AbhBXQhW (ORCPT ); Wed, 24 Feb 2021 11:37:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614184555; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5oZ0gBbOu96k/6wK9MgGNZa/Ac7X58KCvMjW+JEN0KE=; b=L5gH8zM63ZL102Id4ogNAGi4aoaIALsJZ1jhEZcXdyZJw2plfR5P6qzDjK1qXcXekdsReP ow2bcOjFrGXgP2dsyIx8IL/TFRB9sLjOaAqNsBAJieAnIYi6MLweiviRfcZljHwZV5a69L ajpEXmQ2KRmNdwhuxKqezlmfjJA7yrE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-283-gnQqpUl7OvecR-6HBP-yyg-1; Wed, 24 Feb 2021 11:35:53 -0500 X-MC-Unique: gnQqpUl7OvecR-6HBP-yyg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9691384E240 for ; Wed, 24 Feb 2021 16:35:52 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 885FA19C46; Wed, 24 Feb 2021 16:35:51 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Subject: [PATCH kvm-unit-tests v2 2/4] x86: hyperv_stimer: define union hv_stimer_config Date: Wed, 24 Feb 2021 17:35:45 +0100 Message-Id: <20210224163547.197100-3-vkuznets@redhat.com> In-Reply-To: <20210224163547.197100-1-vkuznets@redhat.com> References: <20210224163547.197100-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org As a preparation to enabling direct synthetic timers properly define hv_stimer_config. Signed-off-by: Vitaly Kuznetsov --- x86/hyperv.h | 22 +++++++++++++++++----- x86/hyperv_stimer.c | 21 ++++++++------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/x86/hyperv.h b/x86/hyperv.h index e135221fa28a..9a83da483467 100644 --- a/x86/hyperv.h +++ b/x86/hyperv.h @@ -60,11 +60,23 @@ #define HV_SYNIC_SINT_VECTOR_MASK (0xFF) #define HV_SYNIC_SINT_COUNT 16 -#define HV_STIMER_ENABLE (1ULL << 0) -#define HV_STIMER_PERIODIC (1ULL << 1) -#define HV_STIMER_LAZY (1ULL << 2) -#define HV_STIMER_AUTOENABLE (1ULL << 3) -#define HV_STIMER_SINT(config) (__u8)(((config) >> 16) & 0x0F) +/* + * Synthetic timer configuration. + */ +union hv_stimer_config { + u64 as_uint64; + struct { + u64 enable:1; + u64 periodic:1; + u64 lazy:1; + u64 auto_enable:1; + u64 apic_vector:8; + u64 direct_mode:1; + u64 reserved_z0:3; + u64 sintx:4; + u64 reserved_z1:44; + }; +}; #define HV_SYNIC_STIMER_COUNT (4) diff --git a/x86/hyperv_stimer.c b/x86/hyperv_stimer.c index fa00dac4d66a..1e4eff270406 100644 --- a/x86/hyperv_stimer.c +++ b/x86/hyperv_stimer.c @@ -163,20 +163,15 @@ static void stimer_start(struct stimer *timer, bool auto_enable, bool periodic, u64 tick_100ns) { - u64 config, count; + u64 count; + union hv_stimer_config config = {.as_uint64 = 0}; atomic_set(&timer->fire_count, 0); - config = 0; - if (periodic) { - config |= HV_STIMER_PERIODIC; - } - - config |= ((u8)(timer->sint & 0xFF)) << 16; - config |= HV_STIMER_ENABLE; - if (auto_enable) { - config |= HV_STIMER_AUTOENABLE; - } + config.periodic = periodic; + config.enable = 1; + config.auto_enable = auto_enable; + config.sintx = timer->sint; if (periodic) { count = tick_100ns; @@ -186,9 +181,9 @@ static void stimer_start(struct stimer *timer, if (!auto_enable) { wrmsr(HV_X64_MSR_STIMER0_COUNT + timer->index*2, count); - wrmsr(HV_X64_MSR_STIMER0_CONFIG + timer->index*2, config); + wrmsr(HV_X64_MSR_STIMER0_CONFIG + timer->index*2, config.as_uint64); } else { - wrmsr(HV_X64_MSR_STIMER0_CONFIG + timer->index*2, config); + wrmsr(HV_X64_MSR_STIMER0_CONFIG + timer->index*2, config.as_uint64); wrmsr(HV_X64_MSR_STIMER0_COUNT + timer->index*2, count); } } From patchwork Wed Feb 24 16:35:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 12102137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B9E9C43381 for ; Wed, 24 Feb 2021 16:39:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0AF6064EF5 for ; Wed, 24 Feb 2021 16:39:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235517AbhBXQj1 (ORCPT ); Wed, 24 Feb 2021 11:39:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:47599 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235413AbhBXQhX (ORCPT ); Wed, 24 Feb 2021 11:37:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614184557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BqZRAPirmJd947ZkT/vhl+S217xyAEtnFK5UWHoVomY=; b=JwUF94hp8/4pSUIWFGjiVWYu+c21PcPlUaYwdLCk6toaredmYcqJ0R078fb3LTFvYMh8Tw SJrR1zBHaa99M8b1tLpMLlKkLD4bvjvLDzhn5SvhTcufv8jNmuTZquar1oC1Et7Bjna3Tc oBX77mBpiXIFYH21TcH/KkbpVpnf+oA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-476-nRvDkyCnONW6lOuAscryGg-1; Wed, 24 Feb 2021 11:35:55 -0500 X-MC-Unique: nRvDkyCnONW6lOuAscryGg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 126F7107ACE6 for ; Wed, 24 Feb 2021 16:35:54 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 069ED19C46; Wed, 24 Feb 2021 16:35:52 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Subject: [PATCH kvm-unit-tests v2 3/4] x86: hyperv_stimer: don't require hyperv-testdev Date: Wed, 24 Feb 2021 17:35:46 +0100 Message-Id: <20210224163547.197100-4-vkuznets@redhat.com> In-Reply-To: <20210224163547.197100-1-vkuznets@redhat.com> References: <20210224163547.197100-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 'hyperv-testdev' is completely superfluous for stimer tests. Signed-off-by: Vitaly Kuznetsov --- x86/unittests.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x86/unittests.cfg b/x86/unittests.cfg index 0698d157276c..176f9e80b013 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -361,7 +361,7 @@ groups = hyperv [hyperv_stimer] file = hyperv_stimer.flat smp = 2 -extra_params = -cpu kvm64,hv_vpindex,hv_time,hv_synic,hv_stimer -device hyperv-testdev +extra_params = -cpu kvm64,hv_vpindex,hv_time,hv_synic,hv_stimer groups = hyperv [hyperv_clock] From patchwork Wed Feb 24 16:35:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 12102141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75549C433E6 for ; Wed, 24 Feb 2021 16:40:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3800464F02 for ; Wed, 24 Feb 2021 16:40:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234768AbhBXQjq (ORCPT ); Wed, 24 Feb 2021 11:39:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22270 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234487AbhBXQhZ (ORCPT ); Wed, 24 Feb 2021 11:37:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614184558; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/cykzK4/txSh+VMc+LR/WwUPtiOJKuKhe+NHf4sQ6mk=; b=DcGv4EcN8v21478WHcmGqeaiGc/AD1Qf8XTR0c8QSGKbf3Wiq5cC7ac0Lg+i18PUr2g2+R UKJ2Vz1/zUGNLCqQBtUDoTu4D7cjQ2V8hVuGyTfBF2oR0q2vxuKUMo7eo/f2obPJGvjNQR rZVEnXyGqop3CDRAGtopnFkF+DJ9SO8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-87-dwAwwuxwPcmtwv_gL3sQ2A-1; Wed, 24 Feb 2021 11:35:56 -0500 X-MC-Unique: dwAwwuxwPcmtwv_gL3sQ2A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 79EF2195D561 for ; Wed, 24 Feb 2021 16:35:55 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7015E19C46; Wed, 24 Feb 2021 16:35:54 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Subject: [PATCH kvm-unit-tests v2 4/4] x86: hyperv_stimer: add direct mode tests Date: Wed, 24 Feb 2021 17:35:47 +0100 Message-Id: <20210224163547.197100-5-vkuznets@redhat.com> In-Reply-To: <20210224163547.197100-1-vkuznets@redhat.com> References: <20210224163547.197100-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org All tests but stimer_test_one_shot_busy() are applicable, make them run in both 'message' and 'direct' modes. Signed-off-by: Vitaly Kuznetsov --- x86/hyperv.h | 7 +++ x86/hyperv_stimer.c | 116 ++++++++++++++++++++++++++++++++++++++------ x86/unittests.cfg | 6 +++ 3 files changed, 115 insertions(+), 14 deletions(-) diff --git a/x86/hyperv.h b/x86/hyperv.h index 9a83da483467..718744c4d179 100644 --- a/x86/hyperv.h +++ b/x86/hyperv.h @@ -10,6 +10,8 @@ #define HV_X64_MSR_SYNIC_AVAILABLE (1 << 2) #define HV_X64_MSR_SYNTIMER_AVAILABLE (1 << 3) +#define HV_STIMER_DIRECT_MODE_AVAILABLE (1 << 19) + #define HV_X64_MSR_GUEST_OS_ID 0x40000000 #define HV_X64_MSR_HYPERCALL 0x40000001 @@ -205,6 +207,11 @@ static inline bool stimer_supported(void) return cpuid(HYPERV_CPUID_FEATURES).a & HV_X64_MSR_SYNIC_AVAILABLE; } +static inline bool stimer_direct_supported(void) +{ + return cpuid(HYPERV_CPUID_FEATURES).d & HV_STIMER_DIRECT_MODE_AVAILABLE; +} + static inline bool hv_time_ref_counter_supported(void) { return cpuid(HYPERV_CPUID_FEATURES).a & HV_X64_MSR_TIME_REF_COUNT_AVAILABLE; diff --git a/x86/hyperv_stimer.c b/x86/hyperv_stimer.c index 1e4eff270406..231a1e3bc06e 100644 --- a/x86/hyperv_stimer.c +++ b/x86/hyperv_stimer.c @@ -16,6 +16,9 @@ #define SINT1_VEC 0xF1 #define SINT2_VEC 0xF2 +#define APIC_VEC1 0xF3 +#define APIC_VEC2 0xF4 + #define SINT1_NUM 2 #define SINT2_NUM 3 #define ONE_MS_IN_100NS 10000 @@ -25,6 +28,8 @@ static struct spinlock g_synic_alloc_lock; struct stimer { int sint; int index; + bool direct; + int apic_vec; atomic_t fire_count; }; @@ -81,8 +86,7 @@ static void stimer_shutdown(struct stimer *timer) wrmsr(HV_X64_MSR_STIMER0_CONFIG + 2*timer->index, 0); } -static void process_stimer_expired(struct svcpu *svcpu, struct stimer *timer, - u64 expiration_time, u64 delivery_time) +static void process_stimer_expired(struct stimer *timer) { atomic_inc(&timer->fire_count); } @@ -119,8 +123,14 @@ static void process_stimer_msg(struct svcpu *svcpu, abort(); } timer = &svcpu->timer[payload->timer_index]; - process_stimer_expired(svcpu, timer, payload->expiration_time, - payload->delivery_time); + + if (timer->direct) { + report(false, "VMBus message in direct mode received"); + report_summary(); + abort(); + } + + process_stimer_expired(timer); msg->header.message_type = HVMSG_NONE; mb(); @@ -159,6 +169,32 @@ static void stimer_isr_auto_eoi(isr_regs_t *regs) __stimer_isr(vcpu); } +static void __stimer_isr_direct(int vcpu, int timer_index) +{ + struct svcpu *svcpu = &g_synic_vcpu[vcpu]; + struct stimer *timer = &svcpu->timer[timer_index]; + + process_stimer_expired(timer); +} + +static void stimer_isr_direct1(isr_regs_t *regs) +{ + int vcpu = smp_id(); + + __stimer_isr_direct(vcpu, 0); + + eoi(); +} + +static void stimer_isr_direct2(isr_regs_t *regs) +{ + int vcpu = smp_id(); + + __stimer_isr_direct(vcpu, 1); + + eoi(); +} + static void stimer_start(struct stimer *timer, bool auto_enable, bool periodic, u64 tick_100ns) @@ -171,7 +207,12 @@ static void stimer_start(struct stimer *timer, config.periodic = periodic; config.enable = 1; config.auto_enable = auto_enable; - config.sintx = timer->sint; + if (!timer->direct) { + config.sintx = timer->sint; + } else { + config.direct_mode = 1; + config.apic_vector = timer->apic_vec; + } if (periodic) { count = tick_100ns; @@ -229,6 +270,28 @@ static void stimer_test_prepare(void *ctx) timer2->sint = SINT2_NUM; } +static void stimer_test_prepare_direct(void *ctx) +{ + int vcpu = smp_id(); + struct svcpu *svcpu = &g_synic_vcpu[vcpu]; + struct stimer *timer1, *timer2; + + write_cr3((ulong)ctx); + + timer1 = &svcpu->timer[0]; + timer2 = &svcpu->timer[1]; + + stimer_init(timer1, 0); + stimer_init(timer2, 1); + + timer1->apic_vec = APIC_VEC1; + timer2->apic_vec = APIC_VEC2; + + timer1->direct = true; + timer2->direct = true; +} + + static void stimer_test_periodic(int vcpu, struct stimer *timer1, struct stimer *timer2) { @@ -281,8 +344,15 @@ static void stimer_test_auto_enable_periodic(int vcpu, struct stimer *timer) static void stimer_test_one_shot_busy(int vcpu, struct stimer *timer) { - struct hv_message_page *msg_page = g_synic_vcpu[vcpu].msg_page; - struct hv_message *msg = &msg_page->sint_message[timer->sint]; + struct hv_message_page *msg_page; + struct hv_message *msg; + + /* Skipping msg slot busy test in direct mode */ + if (timer->direct) + return; + + msg_page = g_synic_vcpu[vcpu].msg_page; + msg = &msg_page->sint_message[timer->sint]; msg->header.message_type = HVMSG_TIMER_EXPIRED; wmb(); @@ -336,7 +406,12 @@ static void stimer_test_cleanup(void *ctx) synic_disable(); } -static void stimer_test_all(void) +static void stimer_test_cleanup_direct(void *ctx) +{ + stimers_shutdown(); +} + +static void stimer_test_all(bool direct) { int ncpus; @@ -348,12 +423,25 @@ static void stimer_test_all(void) report_abort("number cpus exceeds %d", MAX_CPUS); printf("cpus = %d\n", ncpus); - handle_irq(SINT1_VEC, stimer_isr); - handle_irq(SINT2_VEC, stimer_isr_auto_eoi); + if (!direct) { + printf("Starting Hyper-V SynIC timers tests: message mode\n"); - on_cpus(stimer_test_prepare, (void *)read_cr3()); - on_cpus(stimer_test, NULL); - on_cpus(stimer_test_cleanup, NULL); + handle_irq(SINT1_VEC, stimer_isr); + handle_irq(SINT2_VEC, stimer_isr_auto_eoi); + + on_cpus(stimer_test_prepare, (void *)read_cr3()); + on_cpus(stimer_test, NULL); + on_cpus(stimer_test_cleanup, NULL); + } else { + printf("Starting Hyper-V SynIC timers tests: direct mode\n"); + + handle_irq(APIC_VEC1, stimer_isr_direct1); + handle_irq(APIC_VEC2, stimer_isr_direct2); + + on_cpus(stimer_test_prepare_direct, (void *)read_cr3()); + on_cpus(stimer_test, NULL); + on_cpus(stimer_test_cleanup_direct, NULL); + } } int main(int ac, char **av) @@ -374,7 +462,7 @@ int main(int ac, char **av) goto done; } - stimer_test_all(); + stimer_test_all(stimer_direct_supported()); done: return report_summary(); } diff --git a/x86/unittests.cfg b/x86/unittests.cfg index 176f9e80b013..ad9afcec92ab 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -364,6 +364,12 @@ smp = 2 extra_params = -cpu kvm64,hv_vpindex,hv_time,hv_synic,hv_stimer groups = hyperv +[hyperv_stimer_direct] +file = hyperv_stimer.flat +smp = 2 +extra_params = -cpu kvm64,hv_vpindex,hv_time,hv_synic,hv_stimer,hv_stimer_direct +groups = hyperv + [hyperv_clock] file = hyperv_clock.flat smp = 2