Buck converter using P-MOSFET
The IRF9530 is rated for a maximum of 20V between Gate and Source. You are applying 24V, which will probably blow it up. However your circuit should work fine with one small addition - a resistor in series between Q1 Collector and R3.

This resistor forms a voltage divider with R3. If you make it the same value then voltage will be divided by 2 and the Gate will get 12V. The total resistance load on Q1 will then be 200&ohm;, so when turned on it will draw 24V/200&ohm; = 120mA. This is bit much for a 2N3904, so I would increase the resistances to 220&ohm; each.

You should also have a low ESR 'bulk' capacitor across the 24V supply. Otherwise inductance in the wires will cause voltage spikes that may damage the MOSFET.