Retirement tax questions

Ok, that covers what to do if there is a loss - you can't deduct the loss from your capital gains for that tax year. Did not know that, thank you. But it didn't answer whether the "earnings attributable to the excess contribution" are the earnings for the whole portfolio, or just the assets purchased with the excess contribution.