The mechanism of controlling supersonic cavity oscillations using upstream mass injection is investigated by implicit large-eddy simulations of a turbulent flow (M∞ = 2.0, ReD = 105) past a rectangular cavity with a length-to-depth ratio of 2. The mass injection is simulated by specifying a vertical velocity profile of a jet ejecting steadily through a slot placed at the upstream of the cavity leading edge. The results show that the steady upstream mass injection produces significant attenuation of the cavity oscillations, and two primary mechanisms are demonstrated to be directly responsible for the noise suppression: lifting up of the cavity shear layer, and damping of the shear-layer instability. It is found that the case of low mass flow injection investigated is more effective in stabilizing the cavity shear layer than the high mass flow injection. A transition stage might exist between two well-developed oscillating modes, but "mode-switching" is not observed.