Tal Afar is located in northern Iraq , near the city of Mosul .