Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp4549126ioo; Tue, 31 May 2022 06:54:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4CY0Be1uAxrZ+l89yul1LED858f+20Q4pfwJuZ3d/ig8SACU02bEKRI2kXVo6ufxLpqTl X-Received: by 2002:a17:906:6a20:b0:6ff:47a3:803d with SMTP id qw32-20020a1709066a2000b006ff47a3803dmr16222222ejc.224.1654005280337; Tue, 31 May 2022 06:54:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654005280; cv=none; d=google.com; s=arc-20160816; b=MfKoINep7UvD5r0+zZysByLsNbdw77Mol69TRLEZ0h8NVHO/uXqas5BAmcBvvNNIKz u9sTq16/otn7Hc4/hjxHs0PAr0uwOk5p7hDD6LAIMzTrZWJ2QusxVVz0ZMJHZLHGKUZy 9aVg40JJs6JDI9kgy8UMxrioBHcxRsra4F1LnpiVw0Ysr6Df+/JrrI7ZeZQUwEjhrbYa ozqkxidhQCu2Qqx91vHHsLvjI+b5mYrTA+dg/6Ej4RwMcRX2EFPkVuqgqAqsyst1ypzU hjIRirJ+0sUIdOx1HUXnghH0X0/GmsDXwQyqiknmtrfFA3+ZzFQt04lJ9jOB6Kd5oaMf 5j7w== 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; bh=mqxGFZcVwPPwdiEiuZlCnpD8AoVrqbZpJvEqULLlTW8=; b=L4O1e5w0uq32p15MbLFiLlhjmkSIcOnw7vjD6/4zfItV4WH+3klagn66+0A7xUQDvb KmrAtzx0x69KseKHqSNJddXlTXkVaocdaP31pJ+K7l5nfsGZLGalKpNtBwzkMfag3Z1S KGMa/SIwZUBL/Rqxl8Zztjqcf1W58UOtga9GRubkijqKczqAFqnb0aOjYReELy3XGG3V 3z0NiuIxNvDZg7Xna7MqEpTGefaA4neI5/s/FdIDjavbS/mZJKo9g1pWBEUkqs3CzSzf zJC/k0WIFl+reKO4jaQ9NSGZnxaMS5MZHtnUD4m3WPHaIsiSW172DtVl/a14+RiR9nV2 x83Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cn4-20020a0564020ca400b0042dcaf306fesi7335670edb.230.2022.05.31.06.53.51; Tue, 31 May 2022 06:54:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344615AbiEaNMX (ORCPT + 99 others); Tue, 31 May 2022 09:12:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344605AbiEaNMU (ORCPT ); Tue, 31 May 2022 09:12:20 -0400 X-Greylist: delayed 1595 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 31 May 2022 06:12:19 PDT Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 449FB60045; Tue, 31 May 2022 06:12:17 -0700 (PDT) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nw1F3-0003Pr-Ez; Tue, 31 May 2022 12:44:57 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] helo=debian.cbg12.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nw1F3-0006Db-3n; Tue, 31 May 2022 12:44:57 +0000 From: Paul Durrant To: kvm@vger.kernel.org Cc: Paul Durrant , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org Subject: [PATCH] KVM: x86: PIT: Preserve state of speaker port data bit Date: Tue, 31 May 2022 13:44:21 +0100 Message-Id: <20220531124421.1427-1-pdurrant@amazon.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIM_ADSP_ALL, RCVD_IN_DNSWL_MED,SPF_FAIL,SPF_HELO_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently the state of the speaker port (0x61) data bit (bit 1) is not saved in the exported state (kvm_pit_state2) and hence is lost when re-constructing guest state. This patch removes the 'speaker_data_port' field from kvm_kpit_state and instead tracks the state using a new KVM_PIT_FLAGS_SPEAKER_DATA_ON flag defined in the API. Signed-off-by: Paul Durrant --- Documentation/virt/kvm/api.rst | 4 +++- arch/x86/include/uapi/asm/kvm.h | 3 ++- arch/x86/kvm/i8254.c | 10 +++++++--- arch/x86/kvm/i8254.h | 1 - 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 28b547a9d96a..8659dbfd3095 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -2998,7 +2998,9 @@ KVM_CREATE_PIT2. The state is returned in the following structure:: Valid flags are:: /* disable PIT in HPET legacy mode */ - #define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001 + #define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001 + /* speaker port data bit enabled */ + #define KVM_PIT_FLAGS_SPEAKER_DATA_ON 0x00000002 This IOCTL replaces the obsolete KVM_GET_PIT. diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h index 21614807a2cb..1b30c222d51c 100644 --- a/arch/x86/include/uapi/asm/kvm.h +++ b/arch/x86/include/uapi/asm/kvm.h @@ -306,7 +306,8 @@ struct kvm_pit_state { struct kvm_pit_channel_state channels[3]; }; -#define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001 +#define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001 +#define KVM_PIT_FLAGS_SPEAKER_DATA_ON 0x00000002 struct kvm_pit_state2 { struct kvm_pit_channel_state channels[3]; diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c index 1c83076091af..e0a7a0e7a73c 100644 --- a/arch/x86/kvm/i8254.c +++ b/arch/x86/kvm/i8254.c @@ -591,7 +591,10 @@ static int speaker_ioport_write(struct kvm_vcpu *vcpu, return -EOPNOTSUPP; mutex_lock(&pit_state->lock); - pit_state->speaker_data_on = (val >> 1) & 1; + if (val & (1 << 1)) + pit_state->flags |= KVM_PIT_FLAGS_SPEAKER_DATA_ON; + else + pit_state->flags &= ~KVM_PIT_FLAGS_SPEAKER_DATA_ON; pit_set_gate(pit, 2, val & 1); mutex_unlock(&pit_state->lock); return 0; @@ -612,8 +615,9 @@ static int speaker_ioport_read(struct kvm_vcpu *vcpu, refresh_clock = ((unsigned int)ktime_to_ns(ktime_get()) >> 14) & 1; mutex_lock(&pit_state->lock); - ret = ((pit_state->speaker_data_on << 1) | pit_get_gate(pit, 2) | - (pit_get_out(pit, 2) << 5) | (refresh_clock << 4)); + ret = (!!(pit_state->flags & KVM_PIT_FLAGS_SPEAKER_DATA_ON) << 1) | + pit_get_gate(pit, 2) | (pit_get_out(pit, 2) << 5) | + (refresh_clock << 4); if (len > sizeof(ret)) len = sizeof(ret); memcpy(data, (char *)&ret, len); diff --git a/arch/x86/kvm/i8254.h b/arch/x86/kvm/i8254.h index 394d9527da7e..a768212ba821 100644 --- a/arch/x86/kvm/i8254.h +++ b/arch/x86/kvm/i8254.h @@ -29,7 +29,6 @@ struct kvm_kpit_state { bool is_periodic; s64 period; /* unit: ns */ struct hrtimer timer; - u32 speaker_data_on; struct mutex lock; atomic_t reinject; -- 2.20.1