Global regularity and stability of solutions to obstacle problems with nonstandard growth