As background, see this question for a general explanation of how safety pilots can log time. Also have a look at the Gebhart (2009) interpretation for the cross-country part (and see this question too).
Note that the two key things to keep in mind in these logging scenarios are:
- Acting as PIC and logging PIC time are two different things
- You have to be very clear about who is the acting PIC for the flight
With all that in mind (and referring to 14 CFR 61.51):
The primary pilot can log instrument time and cross country time, but not PIC time
The primary pilot can log all three. Whether they're the acting PIC or not, they can still log PIC time as the sole manipulator of the controls (61.51(e)(i)). They can also log instrument time while they're under the hood (61.51(g)) and cross country time.
The Safety Pilot can log PIC time, but not cross country time or instrument time
If the safety pilot is acting as PIC then that's correct. They can log PIC time because they're acting as PIC "of an aircraft for which more than one pilot is required under [...] the regulations under which the flight is conducted" (61.51(e)(iii)). If the safety pilot is not acting as PIC then they can log SIC time.
But either way, the safety pilot may not log cross country time (Gebhart). They also can't log instrument time because they were never operating "the aircraft solely by reference to instruments under actual or simulated instrument flight conditions" (61.51(g)).
If flying a high-performance and complex airplane, both the primary pilot and Safety Pilot must have a complex and high-performance rating
Only the acting PIC requires those endorsements (not ratings), per 61.31(e) and (f). So if only one of the two pilots on board has them, that's the only pilot who can act as PIC.
If only the primary pilot has the endorsements the flight can still go ahead because a safety pilot isn't required to have them. However, the safety pilot couldn't act as PIC and could only log SIC time.
If only the safety pilot has the endorsements the primary pilot can still log PIC time because you don't need the endorsements to log PIC time. But the safety pilot must act as PIC.
The symbiotic benefit of this system is that the primary pilot gets instrument time and the Safety Pilot gets PIC time, both at half price if they split the cost of flying
Essentially, yes. Typical practice is for the pilots to agree that the safety pilot will act as PIC, and they split the costs 50/50 (61.113(c)). That way they can both log PIC time - which is valuable for further ratings - while only paying 50% of the costs. This question has more information on cost-sharing.
And thanks to JScarry for pointing out that if the safety pilot has BasicMed rather than a regular medical, they must act as PIC. See this question for more details.
Whatever you do please be sure that both pilots do know and understand who is acting PIC for the flight. That person has the final responsibility if something goes wrong. Knowing who's acting PIC is important to prevent things like a safety pilot without a complex endorsement agreeing to act as PIC in a complex aircraft, because "I'm just a safety pilot". You might also have insurance or flying club rules on who can act as PIC.