Skip to content

Commit b172862

Browse files
Paul Durrantbonzini
authored andcommitted
KVM: x86: PIT: Preserve state of speaker port data bit
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 <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 3dbec44 commit b172862

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

Documentation/virt/kvm/api.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3006,7 +3006,9 @@ KVM_CREATE_PIT2. The state is returned in the following structure::
30063006
Valid flags are::
30073007

30083008
/* disable PIT in HPET legacy mode */
3009-
#define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
3009+
#define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
3010+
/* speaker port data bit enabled */
3011+
#define KVM_PIT_FLAGS_SPEAKER_DATA_ON 0x00000002
30103012

30113013
This IOCTL replaces the obsolete KVM_GET_PIT.
30123014

arch/x86/include/uapi/asm/kvm.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ struct kvm_pit_state {
306306
struct kvm_pit_channel_state channels[3];
307307
};
308308

309-
#define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
309+
#define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
310+
#define KVM_PIT_FLAGS_SPEAKER_DATA_ON 0x00000002
310311

311312
struct kvm_pit_state2 {
312313
struct kvm_pit_channel_state channels[3];

arch/x86/kvm/i8254.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,10 @@ static int speaker_ioport_write(struct kvm_vcpu *vcpu,
591591
return -EOPNOTSUPP;
592592

593593
mutex_lock(&pit_state->lock);
594-
pit_state->speaker_data_on = (val >> 1) & 1;
594+
if (val & (1 << 1))
595+
pit_state->flags |= KVM_PIT_FLAGS_SPEAKER_DATA_ON;
596+
else
597+
pit_state->flags &= ~KVM_PIT_FLAGS_SPEAKER_DATA_ON;
595598
pit_set_gate(pit, 2, val & 1);
596599
mutex_unlock(&pit_state->lock);
597600
return 0;
@@ -612,8 +615,9 @@ static int speaker_ioport_read(struct kvm_vcpu *vcpu,
612615
refresh_clock = ((unsigned int)ktime_to_ns(ktime_get()) >> 14) & 1;
613616

614617
mutex_lock(&pit_state->lock);
615-
ret = ((pit_state->speaker_data_on << 1) | pit_get_gate(pit, 2) |
616-
(pit_get_out(pit, 2) << 5) | (refresh_clock << 4));
618+
ret = (!!(pit_state->flags & KVM_PIT_FLAGS_SPEAKER_DATA_ON) << 1) |
619+
pit_get_gate(pit, 2) | (pit_get_out(pit, 2) << 5) |
620+
(refresh_clock << 4);
617621
if (len > sizeof(ret))
618622
len = sizeof(ret);
619623
memcpy(data, (char *)&ret, len);

arch/x86/kvm/i8254.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ struct kvm_kpit_state {
2929
bool is_periodic;
3030
s64 period; /* unit: ns */
3131
struct hrtimer timer;
32-
u32 speaker_data_on;
3332

3433
struct mutex lock;
3534
atomic_t reinject;

0 commit comments

Comments
 (0)