Theory of the upper critical field of a magnetic superconductor