The extended trust region subproblem (ETRS) of minimizing a quadratic objective over the unit ball with additional linear constraints has attracted a lot of attention in the last few years because of its theoretical significance and wide spectra of applications. Several sufficient conditions to guarantee the exactness of its semidefinite programming (SDP) relaxation have been recently developed in the literature. In this paper, we consider a generalization of the extended trust region subproblem (GETRS), in which the unit ball constraint in the ETRS is replaced by a general, possibly nonconvex, quadratic constraint, and the linear constraints are replaced by a conic linear constraint. We derive sufficient conditions for guaranteeing the exactness of the SDP relaxation of the GETRS under mild assumptions. Our main tools are two classes of convex relaxations for the GETRS based on either a simultaneous diagonalization transformation of the quadratic forms or linear combinations of the quadratic forms. We also compare our results to the existing sufficient conditions in the literature. Finally, we extend our results to derive a new sufficient condition for the exactness of the SDP relaxation of general diagonal quadratically constrained quadratic programs, where each quadratic function is associated with a diagonal matrix. Funding: This work was supported by the National Natural Science Foundation of China [Grants 11801087, 12171100, 72161160340]; Hong Kong Research Grants Council [Grants 14213716 and 14202017]; and Natural Science Foundation of Shanghai [Grant 22ZR1405100].