Message ID | 20231017155101.40677-1-nsaenz@amazon.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4230138vqb; Tue, 17 Oct 2023 08:53:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHSkqkvpeqyKa/1alepiwZxMLU5Tb0P24b+wIjBl4inuJ0Iob6RBZcwl7XkOI3b/Wvw48p4 X-Received: by 2002:a05:6a00:1d12:b0:6b2:51a0:e1c9 with SMTP id a18-20020a056a001d1200b006b251a0e1c9mr2733047pfx.1.1697558026043; Tue, 17 Oct 2023 08:53:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697558026; cv=none; d=google.com; s=arc-20160816; b=g94d2VOelot31tIE4ipDe+DEZFg3NbkKN3T/29Wn/kuJFyTB6TIA74o7yMaz5BOOrY 5T4neQ2dv9hTQL0wCF9kMeb8uO1gOeO9OuGHwhD33zoDDq4aQJd7lw2fhktSbix/VWW2 x4Chi1g6QpSHmgG2xtLkGRjMD6vW4ZLnYXOGO0PP/UBqYrYUVCMzqYcTLE+c0HlgIcaA /9jBPjXH+eakWIiLPU4DybUXvlsizxrt7sTh9JgryUHqq7/SC0Jpqt9DEiWcZI6MwyTb i/BkoF0nTiDaen9681HAzQ0cM4N3v8gvXfQ+Tv5xleq0eZtqw4rtE+T6lzyiy/QAaj8k 9PcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=I7FWWa7aQS2aYUzbRv0vGUR8vIS4wtaPLaLNjNSlUB4=; fh=BiBrsvioCliaE/AIk5OfVH/KI/ndwelJdw/6TJ9q9Z8=; b=MuH0g4HYAGZTMM/PpPL4nPg3rNou++Grr7sv3DYS+V09sOcJECn6E6aH0I0YgWx7L4 KlOvcrlF+ZO5H/S5LEGqg3CgXNzUbtQaOASI+oJOuCqoX7PNdY9L2OE8PA6VFTUT1hg8 9Bmfw7obS8tjcmFtsPQwxIF+1LpYSnfse9P09Fz8rcQB+kE9OMke/g1Fizbt6zfs7AB8 Q3ej+NjZDQg0pBl/biZdD2dJxpTW457PHiKLzIhEIw5MHx1F96hhU9fJ5WULryKGODyE HiWtV3KvOWzXPLcijDow30/EiAHKszVovnCFMFd9Y15d6VtBR1dF07L1g1EADGA4BjUY rzRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=EqJWlODh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id fa15-20020a056a002d0f00b006a15afe16c2si2004259pfb.296.2023.10.17.08.53.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 08:53:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=EqJWlODh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 930EC802542D; Tue, 17 Oct 2023 08:53:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344183AbjJQPxc (ORCPT <rfc822;hjfbswb@gmail.com> + 20 others); Tue, 17 Oct 2023 11:53:32 -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 <rfc822;linux-kernel@vger.kernel.org>); 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 <nsaenz@amazon.com> To: <kvm@vger.kernel.org> CC: <vkuznets@redhat.com>, <seanjc@google.com>, <pbonzini@redhat.com>, <tglx@linutronix.de>, <mingo@redhat.com>, <bp@alien8.de>, <dave.hansen@linux.intel.com>, <x86@kernel.org>, <hpa@zytor.com>, <graf@amazon.de>, <rkagan@amazon.de>, <linux-kernel@vger.kernel.org>, <anelkz@amazon.de>, Nicolas Saenz Julienne <nsaenz@amazon.com>, <stable@vger.kernel.org> 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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) X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 17 Oct 2023 08:53:43 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780018604755561737 X-GMAIL-MSGID: 1780018604755561737 |
Series |
[v3] KVM: x86: hyper-v: Don't auto-enable stimer on write from user-space
|
|
Commit Message
Nicolas Saenz Julienne
Oct. 17, 2023, 3:51 p.m. UTC
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 <nsaenz@amazon.com>
---
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(-)
Comments
Nicolas Saenz Julienne <nsaenz@amazon.com> writes: > 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 <nsaenz@amazon.com> > --- > > 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); LGTM, thanks! Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
On Tue, 17 Oct 2023 15:51:02 +0000, Nicolas Saenz Julienne wrote: > 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. > > [...] Applied to kvm-x86 misc, thanks! [1/1] KVM: x86: hyper-v: Don't auto-enable stimer on write from user-space https://github.com/kvm-x86/linux/commit/d6800af51c76 -- https://github.com/kvm-x86/linux/tree/next
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);