Syria gave the USSR and now Russia access to warm-water ports allowing them deploy in the Mediterranean and beyond. Russia also tends to demonstrate, to an extent, a commitment and loyalty to its partners that the US and UK probably don't. That's not a criticism or a compliment - US/UK foreign policy has been ruthlessly pragmatic for decades if not centuries. The Russians don't lack pragmatism but there is somewhat of a degree of loyalty in their psyche that perhaps informs their approach (I accept there's a generalisation there but I think it's rooted in truth).
And for better or worse, they chose to engage with Syria and that's their 'in' to the Middle East, which they undoubtedly feel they need as balance against US influence in Israel, Saudi and the Gulf states. There's another facet which has to be considered - rightly or wrongly, there is a narrative for a lot of Russians (which Putin undoubtedly knows to exploit) which is a fear of encirclement. The gradual drift of Eastern European nations into NATO, US military intervention in near Asia and its building relationships with former-USSR Central Asian states only feeds into that.
As for Iran, the prospect of the Syrian government falling and the country becoming another Sunni regime must be terrifying. I don't think enough credence is given to the sectarian differences that exist between the Sunni and Shia branches of Islam, but in Tehran the prospect of losing Syria would feel like an existential threat. Critically, maintaining an Iran-friendly Shia regime in Damascus gives Iran a geographical route to the Lebanese coast and provides a vital defensive balance, from their point of view, against Israel - the land corridor allows Iran to equip and resource Hezbollah and the Syrian militias far more easily and undoubtedly acts as a check and balance. Having said that I understand a recent Israeli air strike in Syria killed a number of Iranian Revolutionary Guards Corps soldiers who were acting as 'advisors'.
I read (or maybe heard on the radio) an interesting analysis recently, which likened the situation to the febrile state Europe was in, just prior to the outbreak of the First World War. Extreme tensions between different groups (we've not even started on the US-backed Kurdish militias which are anathema to Turkey), acting as proxies for middling powers and superpowers in a very fluid and dynamic environment. There's a fire already and it could easily become a conflagration.