A creature can voluntarily lower its spell resistance. Doing so is a standard action that does not provoke an attack of opportunity. Once a creature lowers its resistance, it remains down until the creature's next turn. At the beginning of the creature's next turn, the creature's spell resistance automatically returns unless the creature intentionally keeps it down (also a standard action that does not provoke an attack of opportunity).
So, unless the casting time of the spell goes beyond the start of the creature's next turn, its spell resistance stays down while the spell is being cast.
This answer by @ShadowKras shows that by readying its standard action to drop SR when it detects a benign spell being cast, a creature can reduce its risk. Its SR is then down until that initiative count on the following round, however. So it's a trade-off, though since SR isn't easily detectable, it's generally moderately safe to do.