Tony Stark is many things. Engineer, inventor, physicist. Among them is programmer. He knows about predicting outcomes, planning for accidents, having contingencies in place for every eventuality. It’s probably because of those skills that he’s still alive.
After Bruce walked in on Tony with his face buried in Loki’s crotch (which had been fine because Tony had had a ‘Bruce meets Loki and Hulks Out’ plan) Tony had written out his ‘is Loki my lover or my enemy today?’ flo-chart for his friend to see. It had questions like ‘has he tried to kill me within the last twenty-four hours’ and ‘has he tried to get access to the suit schematics recently’ on it, which even Tony acknowledges is a bit worrying. It’s worked so far though.
The Avengers’ reactions range from Thor’s unrestrained glee (he insists on seeing it as a sign that Loki is coming to his senses, despite the fact that he still attacks Tony at least once a month) to Natasha’s haughty disinterest (“If I find out you’ve passed on any classified information I will gut you like a pig”) to Steve’s bona-fide freak-out (which Tony freely admits is fully justified). Clint goes very quiet and then hits Tony as hard as he can in the face. When Tony comes round, Clint explains to him that he was checking for possession. Fury, when he eventually finds out, refuses to have anything to do with the Avengers, at least until Doom-bots attack the hellicarrier and he’s forced to ask for their help.
Pepper decides that it’s probably some kind of convoluted self-harm (it wouldn’t be the first time) and makes him see a psychiatrist. The poor woman runs out the room in tears after fifteen minutes, but once they’ve calmed her down and promised that neither Tony or Loki will be allowed anywhere near her, she admits that she doesn’t think Tony has any ulterior motives for his relationship, sub-conscious or otherwise.
Tony has a series of checks which he runs through when he meets Loki, designed to tell him if the god is more likely to kiss him or try and kill him. They’re constantly being updated and expanded, and they’re far from fool-proof, but on the rare occasions when he misjudges, Tony knows Loki well enough to be able to talk (or sometimes fuck) his way out of trouble, or at least keep himself alive until Thor and the others arrive to save him.
Tony has a table, hidden away in the very depths of JARVIS’ hard-drive, listing the pros and cons of his relationship with Loki. In the early days it was constantly being updated, ‘he’s homicidal’ being balanced against ‘he’s beautiful’, ‘he’s insane’ against ‘he’s brilliant’. But once ‘I love him’ had been added to the pro column, he’d decided it was stupid to keep updating it. Nothing was going to persuade him to give up what he had.
He’s been given some very unusual ‘hurt him and you die’ speeches (Hel and Freya are very different women, but equally formidable) and he suspects that Pepper has had words with Loki (thanks to Tony’s careful management, she’s never met Loki on a truly bad day, so she’s a lot less afraid of him than the rest of Tony’s friends). Fortunately Loki had been having a particularly good day and found the whole thing rather cute.
On those precious, rare, days when Loki is not only lucid, but aware of the terrible things he’s done, the lives he’s taken, he asks Tony why. Why he puts up with him, why he doesn’t run. And Tony kisses him and tells him that you can’t choose who you love. It’s not an ideal answer, but it’s the truth and Loki loves him all the more (on those days when he’s capable of feeling love) for not lying.