@@ -50,6 +50,24 @@ static void kvmppc_xive_native_cleanup_queue(struct kvm_vcpu *vcpu, int prio)
5050 }
5151}
5252
53+ static int kvmppc_xive_native_configure_queue (u32 vp_id , struct xive_q * q ,
54+ u8 prio , __be32 * qpage ,
55+ u32 order , bool can_escalate )
56+ {
57+ int rc ;
58+ __be32 * qpage_prev = q -> qpage ;
59+
60+ rc = xive_native_configure_queue (vp_id , q , prio , qpage , order ,
61+ can_escalate );
62+ if (rc )
63+ return rc ;
64+
65+ if (qpage_prev )
66+ put_page (virt_to_page (qpage_prev ));
67+
68+ return rc ;
69+ }
70+
5371void kvmppc_xive_native_cleanup_vcpu (struct kvm_vcpu * vcpu )
5472{
5573 struct kvmppc_xive_vcpu * xc = vcpu -> arch .xive_vcpu ;
@@ -575,19 +593,14 @@ static int kvmppc_xive_native_set_queue_config(struct kvmppc_xive *xive,
575593 q -> guest_qaddr = 0 ;
576594 q -> guest_qshift = 0 ;
577595
578- rc = xive_native_configure_queue (xc -> vp_id , q , priority ,
579- NULL , 0 , true);
596+ rc = kvmppc_xive_native_configure_queue (xc -> vp_id , q , priority ,
597+ NULL , 0 , true);
580598 if (rc ) {
581599 pr_err ("Failed to reset queue %d for VCPU %d: %d\n" ,
582600 priority , xc -> server_num , rc );
583601 return rc ;
584602 }
585603
586- if (q -> qpage ) {
587- put_page (virt_to_page (q -> qpage ));
588- q -> qpage = NULL ;
589- }
590-
591604 return 0 ;
592605 }
593606
@@ -617,12 +630,6 @@ static int kvmppc_xive_native_set_queue_config(struct kvmppc_xive *xive,
617630
618631 srcu_idx = srcu_read_lock (& kvm -> srcu );
619632 gfn = gpa_to_gfn (kvm_eq .qaddr );
620- page = gfn_to_page (kvm , gfn );
621- if (is_error_page (page )) {
622- srcu_read_unlock (& kvm -> srcu , srcu_idx );
623- pr_err ("Couldn't get queue page %llx!\n" , kvm_eq .qaddr );
624- return - EINVAL ;
625- }
626633
627634 page_size = kvm_host_page_size (kvm , gfn );
628635 if (1ull << kvm_eq .qshift > page_size ) {
@@ -631,6 +638,13 @@ static int kvmppc_xive_native_set_queue_config(struct kvmppc_xive *xive,
631638 return - EINVAL ;
632639 }
633640
641+ page = gfn_to_page (kvm , gfn );
642+ if (is_error_page (page )) {
643+ srcu_read_unlock (& kvm -> srcu , srcu_idx );
644+ pr_err ("Couldn't get queue page %llx!\n" , kvm_eq .qaddr );
645+ return - EINVAL ;
646+ }
647+
634648 qaddr = page_to_virt (page ) + (kvm_eq .qaddr & ~PAGE_MASK );
635649 srcu_read_unlock (& kvm -> srcu , srcu_idx );
636650
@@ -646,8 +660,8 @@ static int kvmppc_xive_native_set_queue_config(struct kvmppc_xive *xive,
646660 * OPAL level because the use of END ESBs is not supported by
647661 * Linux.
648662 */
649- rc = xive_native_configure_queue (xc -> vp_id , q , priority ,
650- (__be32 * ) qaddr , kvm_eq .qshift , true);
663+ rc = kvmppc_xive_native_configure_queue (xc -> vp_id , q , priority ,
664+ (__be32 * ) qaddr , kvm_eq .qshift , true);
651665 if (rc ) {
652666 pr_err ("Failed to configure queue %d for VCPU %d: %d\n" ,
653667 priority , xc -> server_num , rc );
0 commit comments