Can BOTH instrument rated pilot under the hood and safety pilot log PIC time in IFR flight?
I believe the key to this scenario is in the FAA Counsel Office's interpretation to Speranza (2009) 

Quoting from the FAA's interpretation letter:


  The FAA has previously stated that there is a distinction between logging PIC time and acting as a PIC. See Herman Interpretation. To act as a PIC (i.e., the pilot who has final authority and responsibility for the operation and safety of the flight), a pilot must be properly rated in the aircraft and be properly rated and authorized to conduct the flight. In your example of an IFR flight, being properly rated and authorized would include having an instrument rating. Accordingly, only Pilot A may act as the PIC, and Pilot A has final authority and responsibility for the safety of the flight regardless of who is manipulating the controls. 


They also clarify the circumstances under which Pilot B may log PIC time for this flight, and what that means for Pilot B logging PIC time:


  Accordingly, Pilot B may log PIC time for the portion of the flight during which Pilot B was the sole manipulator of the controls.
  . . .
  However, Pilot A may not log PIC time for the portion of the flight during which Pilot B is the sole manipulator ofthe controls, and is logging PIC time, because there is no provision for this logging in §61.51(e). Section 61.51(e)(1)(iii) allows the pilot acting as PIC to log PIC time only if more than one pilot is required under the type certification of the aircraft or the regulations under which the flight is conducted, and only one pilot is required for the flight in your example. Although Pilot B properly may log PIC time for a portion of the flight as discussed previously, Pilot B could not act as PIC and was not a required flight crewmember for any portion of the flight under the aircraft's type certificate or the regulations under which the flight was conducted.


(Emphasis mine in both quotations.)



So, because the flight is conducted under instrument flight rules you must hold an instrument rating (be "properly rated and authorized" to conduct the flight) in order to act as PIC and log PIC time on that basis, regardless of the weather conditions (VMC/IMC) under which the flight is conducted.  

A key difference between your case and the one in the interpretation is that both of your pilots have instrument ratings. Since the safety pilot in your example holds an instrument rating they are rated for the aircraft and authorized to conduct a flight under Instrument Flight Rules, therefore they can act as PIC, and would be eligible to log PIC time for this flight (as a required crewmember under FAR 91.109).  

This would, as best I can tell, revert to the same logging situation as a safety pilot under VFR: For any portion of the flight in which the safety pilot is also manipulating the flight controls the pilot under the hood would be unable to log PIC time, and for any portion of the flight where "Pilot A" is not under the hood they safety pilot would (generally) be unable to log PIC time.