@@ -526,21 +526,22 @@ static bool get_free_page_hints(VirtIOBalloon *dev)
526
526
ret = false;
527
527
goto out ;
528
528
}
529
- if (id == dev -> free_page_report_cmd_id ) {
530
- dev -> free_page_report_status = FREE_PAGE_REPORT_S_START ;
529
+ if (dev -> free_page_hint_status == FREE_PAGE_HINT_S_REQUESTED &&
530
+ id == dev -> free_page_hint_cmd_id ) {
531
+ dev -> free_page_hint_status = FREE_PAGE_HINT_S_START ;
531
532
} else {
532
533
/*
533
534
* Stop the optimization only when it has started. This
534
535
* avoids a stale stop sign for the previous command.
535
536
*/
536
- if (dev -> free_page_report_status == FREE_PAGE_REPORT_S_START ) {
537
- dev -> free_page_report_status = FREE_PAGE_REPORT_S_STOP ;
537
+ if (dev -> free_page_hint_status == FREE_PAGE_HINT_S_START ) {
538
+ dev -> free_page_hint_status = FREE_PAGE_HINT_S_STOP ;
538
539
}
539
540
}
540
541
}
541
542
542
543
if (elem -> in_num ) {
543
- if (dev -> free_page_report_status == FREE_PAGE_REPORT_S_START ) {
544
+ if (dev -> free_page_hint_status == FREE_PAGE_HINT_S_START ) {
544
545
qemu_guest_free_page_hint (elem -> in_sg [0 ].iov_base ,
545
546
elem -> in_sg [0 ].iov_len );
546
547
}
@@ -566,11 +567,11 @@ static void virtio_ballloon_get_free_page_hints(void *opaque)
566
567
qemu_mutex_unlock (& dev -> free_page_lock );
567
568
virtio_notify (vdev , vq );
568
569
/*
569
- * Start to poll the vq once the reporting started. Otherwise, continue
570
+ * Start to poll the vq once the hinting started. Otherwise, continue
570
571
* only when there are entries on the vq, which need to be given back.
571
572
*/
572
573
} while (continue_to_get_hints ||
573
- dev -> free_page_report_status == FREE_PAGE_REPORT_S_START );
574
+ dev -> free_page_hint_status == FREE_PAGE_HINT_S_START );
574
575
virtio_queue_set_notification (vq , 1 );
575
576
}
576
577
@@ -591,33 +592,37 @@ static void virtio_balloon_free_page_start(VirtIOBalloon *s)
591
592
return ;
592
593
}
593
594
594
- if (s -> free_page_report_cmd_id == UINT_MAX ) {
595
- s -> free_page_report_cmd_id =
596
- VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_MIN ;
595
+ qemu_mutex_lock (& s -> free_page_lock );
596
+
597
+ if (s -> free_page_hint_cmd_id == UINT_MAX ) {
598
+ s -> free_page_hint_cmd_id =
599
+ VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN ;
597
600
} else {
598
- s -> free_page_report_cmd_id ++ ;
601
+ s -> free_page_hint_cmd_id ++ ;
599
602
}
600
603
601
- s -> free_page_report_status = FREE_PAGE_REPORT_S_REQUESTED ;
604
+ s -> free_page_hint_status = FREE_PAGE_HINT_S_REQUESTED ;
605
+ qemu_mutex_unlock (& s -> free_page_lock );
606
+
602
607
virtio_notify_config (vdev );
603
608
}
604
609
605
610
static void virtio_balloon_free_page_stop (VirtIOBalloon * s )
606
611
{
607
612
VirtIODevice * vdev = VIRTIO_DEVICE (s );
608
613
609
- if (s -> free_page_report_status != FREE_PAGE_REPORT_S_STOP ) {
614
+ if (s -> free_page_hint_status != FREE_PAGE_HINT_S_STOP ) {
610
615
/*
611
616
* The lock also guarantees us that the
612
617
* virtio_ballloon_get_free_page_hints exits after the
613
- * free_page_report_status is set to S_STOP.
618
+ * free_page_hint_status is set to S_STOP.
614
619
*/
615
620
qemu_mutex_lock (& s -> free_page_lock );
616
621
/*
617
- * The guest hasn 't done the reporting , so host sends a notification
618
- * to the guest to actively stop the reporting .
622
+ * The guest isn 't done hinting , so send a notification
623
+ * to the guest to actively stop the hinting .
619
624
*/
620
- s -> free_page_report_status = FREE_PAGE_REPORT_S_STOP ;
625
+ s -> free_page_hint_status = FREE_PAGE_HINT_S_STOP ;
621
626
qemu_mutex_unlock (& s -> free_page_lock );
622
627
virtio_notify_config (vdev );
623
628
}
@@ -627,20 +632,20 @@ static void virtio_balloon_free_page_done(VirtIOBalloon *s)
627
632
{
628
633
VirtIODevice * vdev = VIRTIO_DEVICE (s );
629
634
630
- if (s -> free_page_report_status != FREE_PAGE_REPORT_S_DONE ) {
635
+ if (s -> free_page_hint_status != FREE_PAGE_HINT_S_DONE ) {
631
636
/* See virtio_balloon_free_page_stop() */
632
637
qemu_mutex_lock (& s -> free_page_lock );
633
- s -> free_page_report_status = FREE_PAGE_REPORT_S_DONE ;
638
+ s -> free_page_hint_status = FREE_PAGE_HINT_S_DONE ;
634
639
qemu_mutex_unlock (& s -> free_page_lock );
635
640
virtio_notify_config (vdev );
636
641
}
637
642
}
638
643
639
644
static int
640
- virtio_balloon_free_page_report_notify (NotifierWithReturn * n , void * data )
645
+ virtio_balloon_free_page_hint_notify (NotifierWithReturn * n , void * data )
641
646
{
642
647
VirtIOBalloon * dev = container_of (n , VirtIOBalloon ,
643
- free_page_report_notify );
648
+ free_page_hint_notify );
644
649
VirtIODevice * vdev = VIRTIO_DEVICE (dev );
645
650
PrecopyNotifyData * pnd = data ;
646
651
@@ -698,7 +703,7 @@ static size_t virtio_balloon_config_size(VirtIOBalloon *s)
698
703
if (virtio_has_feature (features , VIRTIO_BALLOON_F_FREE_PAGE_HINT )) {
699
704
return offsetof(struct virtio_balloon_config , poison_val );
700
705
}
701
- return offsetof(struct virtio_balloon_config , free_page_report_cmd_id );
706
+ return offsetof(struct virtio_balloon_config , free_page_hint_cmd_id );
702
707
}
703
708
704
709
static void virtio_balloon_get_config (VirtIODevice * vdev , uint8_t * config_data )
@@ -710,14 +715,14 @@ static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data)
710
715
config .actual = cpu_to_le32 (dev -> actual );
711
716
config .poison_val = cpu_to_le32 (dev -> poison_val );
712
717
713
- if (dev -> free_page_report_status == FREE_PAGE_REPORT_S_REQUESTED ) {
714
- config .free_page_report_cmd_id =
715
- cpu_to_le32 (dev -> free_page_report_cmd_id );
716
- } else if (dev -> free_page_report_status == FREE_PAGE_REPORT_S_STOP ) {
717
- config .free_page_report_cmd_id =
718
+ if (dev -> free_page_hint_status == FREE_PAGE_HINT_S_REQUESTED ) {
719
+ config .free_page_hint_cmd_id =
720
+ cpu_to_le32 (dev -> free_page_hint_cmd_id );
721
+ } else if (dev -> free_page_hint_status == FREE_PAGE_HINT_S_STOP ) {
722
+ config .free_page_hint_cmd_id =
718
723
cpu_to_le32 (VIRTIO_BALLOON_CMD_ID_STOP );
719
- } else if (dev -> free_page_report_status == FREE_PAGE_REPORT_S_DONE ) {
720
- config .free_page_report_cmd_id =
724
+ } else if (dev -> free_page_hint_status == FREE_PAGE_HINT_S_DONE ) {
725
+ config .free_page_hint_cmd_id =
721
726
cpu_to_le32 (VIRTIO_BALLOON_CMD_ID_DONE );
722
727
}
723
728
@@ -830,14 +835,14 @@ static int virtio_balloon_post_load_device(void *opaque, int version_id)
830
835
return 0 ;
831
836
}
832
837
833
- static const VMStateDescription vmstate_virtio_balloon_free_page_report = {
838
+ static const VMStateDescription vmstate_virtio_balloon_free_page_hint = {
834
839
.name = "virtio-balloon-device/free-page-report" ,
835
840
.version_id = 1 ,
836
841
.minimum_version_id = 1 ,
837
842
.needed = virtio_balloon_free_page_support ,
838
843
.fields = (VMStateField []) {
839
- VMSTATE_UINT32 (free_page_report_cmd_id , VirtIOBalloon ),
840
- VMSTATE_UINT32 (free_page_report_status , VirtIOBalloon ),
844
+ VMSTATE_UINT32 (free_page_hint_cmd_id , VirtIOBalloon ),
845
+ VMSTATE_UINT32 (free_page_hint_status , VirtIOBalloon ),
841
846
VMSTATE_END_OF_LIST ()
842
847
}
843
848
};
@@ -864,7 +869,7 @@ static const VMStateDescription vmstate_virtio_balloon_device = {
864
869
VMSTATE_END_OF_LIST ()
865
870
},
866
871
.subsections = (const VMStateDescription * []) {
867
- & vmstate_virtio_balloon_free_page_report ,
872
+ & vmstate_virtio_balloon_free_page_hint ,
868
873
& vmstate_virtio_balloon_page_poison ,
869
874
NULL
870
875
}
@@ -903,7 +908,7 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
903
908
VIRTIO_BALLOON_F_FREE_PAGE_HINT )) {
904
909
s -> free_page_vq = virtio_add_queue (vdev , VIRTQUEUE_MAX_SIZE ,
905
910
virtio_balloon_handle_free_page_vq );
906
- precopy_add_notifier (& s -> free_page_report_notify );
911
+ precopy_add_notifier (& s -> free_page_hint_notify );
907
912
908
913
object_ref (OBJECT (s -> iothread ));
909
914
s -> free_page_bh = aio_bh_new (iothread_get_aio_context (s -> iothread ),
@@ -927,7 +932,7 @@ static void virtio_balloon_device_unrealize(DeviceState *dev)
927
932
qemu_bh_delete (s -> free_page_bh );
928
933
object_unref (OBJECT (s -> iothread ));
929
934
virtio_balloon_free_page_stop (s );
930
- precopy_remove_notifier (& s -> free_page_report_notify );
935
+ precopy_remove_notifier (& s -> free_page_hint_notify );
931
936
}
932
937
balloon_stats_destroy_timer (s );
933
938
qemu_remove_balloon_handler (s );
@@ -999,8 +1004,8 @@ static void virtio_balloon_instance_init(Object *obj)
999
1004
1000
1005
qemu_mutex_init (& s -> free_page_lock );
1001
1006
qemu_cond_init (& s -> free_page_cond );
1002
- s -> free_page_report_cmd_id = VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_MIN ;
1003
- s -> free_page_report_notify .notify = virtio_balloon_free_page_report_notify ;
1007
+ s -> free_page_hint_cmd_id = VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN ;
1008
+ s -> free_page_hint_notify .notify = virtio_balloon_free_page_hint_notify ;
1004
1009
1005
1010
object_property_add (obj , "guest-stats" , "guest statistics" ,
1006
1011
balloon_stats_get_all , NULL , NULL , s );
0 commit comments