The behavior of grain boundaries in polycrystalline halide perovskite solar cells remains poorly understood. Whereas theoretical studies indicate that grain boundaries are not active for electron-hole recombination, there have been observations of higher nonradiative recombination rates involving these extended defects. We find that iodine interstitial defects, which have been established as a recombination center in bulk crystals, tend to segregate at planar defects in CsPbI3. First-principles calculations show that enhanced structural relaxation of the defects at grain boundaries results in increased stability (higher concentration) and deeper trap states (faster recombination). We show how the grain boundary can be partly passivated by halide mixing or extrinsic doping, which replaces or suppresses the formation of trap states close to the grain boundaries.