From patchwork Tue Oct 17 15:51:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Saenz Julienne X-Patchwork-Id: 13425565 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 546A8CDB474 for ; Tue, 17 Oct 2023 15:53:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344180AbjJQPxa (ORCPT ); Tue, 17 Oct 2023 11:53:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235088AbjJQPx2 (ORCPT ); Tue, 17 Oct 2023 11:53:28 -0400 Received: from smtp-fw-9106.amazon.com (smtp-fw-9106.amazon.com [207.171.188.206]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD31DF5; Tue, 17 Oct 2023 08:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1697558008; x=1729094008; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=I7FWWa7aQS2aYUzbRv0vGUR8vIS4wtaPLaLNjNSlUB4=; b=EqJWlODhGEw+Ghs6lR6J1mf0xVlEnGI+7AUrJHUwwLN84c3EeDfiVNM+ S1jPzR2+UoyGaXDxXG4uA5UltcClUFmhoNYrUbABCsDcyh3j27KkuSr7F nCLuQwa3ZiaseWFZWYkGfyzs1mseTSMMoXlAY5smt6OqzRoQpW0DmOqwx k=; X-IronPort-AV: E=Sophos;i="6.03,232,1694736000"; d="scan'208";a="678249753" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-pdx-2b-m6i4x-a893d89c.us-west-2.amazon.com) ([10.25.36.210]) by smtp-border-fw-9106.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2023 15:53:21 +0000 Received: from smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan2.pdx.amazon.com [10.39.38.66]) by email-inbound-relay-pdx-2b-m6i4x-a893d89c.us-west-2.amazon.com (Postfix) with ESMTPS id 01F3040D73; Tue, 17 Oct 2023 15:53:19 +0000 (UTC) Received: from EX19MTAEUA002.ant.amazon.com [10.0.17.79:40649] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.17.120:2525] with esmtp (Farcaster) id 7d3a7ec6-0eb4-43ae-9e87-2bdb149c100e; Tue, 17 Oct 2023 15:53:18 +0000 (UTC) X-Farcaster-Flow-ID: 7d3a7ec6-0eb4-43ae-9e87-2bdb149c100e Received: from EX19D004EUC001.ant.amazon.com (10.252.51.190) by EX19MTAEUA002.ant.amazon.com (10.252.50.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.37; Tue, 17 Oct 2023 15:53:18 +0000 Received: from dev-dsk-nsaenz-1b-189b39ae.eu-west-1.amazon.com (10.13.235.138) by EX19D004EUC001.ant.amazon.com (10.252.51.190) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.37; Tue, 17 Oct 2023 15:53:13 +0000 From: Nicolas Saenz Julienne To: CC: , , , , , , , , , , , , , Nicolas Saenz Julienne , Subject: [PATCH v3] KVM: x86: hyper-v: Don't auto-enable stimer on write from user-space Date: Tue, 17 Oct 2023 15:51:02 +0000 Message-ID: <20231017155101.40677-1-nsaenz@amazon.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Originating-IP: [10.13.235.138] X-ClientProxiedBy: EX19D036UWB003.ant.amazon.com (10.13.139.172) To EX19D004EUC001.ant.amazon.com (10.252.51.190) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Don't apply the stimer's counter side effects when modifying its value from user-space, as this may trigger spurious interrupts. For example: - The stimer is configured in auto-enable mode. - The stimer's count is set and the timer enabled. - The stimer expires, an interrupt is injected. - The VM is live migrated. - The stimer config and count are deserialized, auto-enable is ON, the stimer is re-enabled. - The stimer expires right away, and injects an unwarranted interrupt. Cc: stable@vger.kernel.org Fixes: 1f4b34f825e8 ("kvm/x86: Hyper-V SynIC timers") Signed-off-by: Nicolas Saenz Julienne Reviewed-by: Vitaly Kuznetsov --- Changes since v2: - reword commit message/subject. Changes since v1: - Cover all 'stimer->config.enable' updates. arch/x86/kvm/hyperv.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 7c2dac6824e2..238afd7335e4 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -727,10 +727,12 @@ static int stimer_set_count(struct kvm_vcpu_hv_stimer *stimer, u64 count, stimer_cleanup(stimer); stimer->count = count; - if (stimer->count == 0) - stimer->config.enable = 0; - else if (stimer->config.auto_enable) - stimer->config.enable = 1; + if (!host) { + if (stimer->count == 0) + stimer->config.enable = 0; + else if (stimer->config.auto_enable) + stimer->config.enable = 1; + } if (stimer->config.enable) stimer_mark_pending(stimer, false);