Excess IRA contribution with a loss

I contributed to my traditional IRA in 2021 and was not eligible. I pulled it back out this year. My initial investment was $7000. It turns out I have a loss after selling it and the distribution after pulling it back out was about 6700. How do I fix this on my 2021 tax return? Is gross distribution $6,700? What about box 2a? Would it be a negative number or zero? Do I use code 8 alone or do I need to use code J also?