  We perform for the first time a dedicated analysis of cosmological
constraints on DFSZ QCD axion models. Such constructions are especially
interesting in light of the recent Xenon-1T excess and of hints from stellar
cooling. In DFSZ models, for $m_a\gtrsim 0.1$ eV, scatterings of pions and
muons can produce a sizable cosmic background of thermal axions, that behave
similarly to massive neutrinos. However, the pion coupling depends on the
alignment between the vevs of two Higgs doublets, and can be significantly
suppressed or enhanced with respect to the KSVZ scenario. Using the latest
Planck and BAO data, we find $m_a\leq 0.2~\text{eV}$ at $95\%$ C.L., when the
axion coupling to pions $c_{a\pi}$ is maximal. Constraints on $m_a$, instead,
can be significantly relaxed when $c_{a\pi}$ is small. In particular, we point
out that in the so-called DFSZ-II model, where the axion coupling to leptons
does not vanish simultaneously with $c_{a\pi}$, production via muons gives
$m_a\leq 0.6~\text{eV}$ at $95\%$ C.L., whereas in the DFSZ-I model bounds on
$m_a$ can be fully lifted. We then combine cosmological data with recent hints
of a DFSZ axion coupled to electrons from the Xenon-1T experiment, finding in
this case that the axion mass is constrained to be in the window $0.07
~\text{eV} \lesssim m_a \lesssim 1.8\, (0.3)~\text{eV}$ for the DFSZ-I
(DFSZ-II) model. A similar analysis with stellar cooling hints gives $3
~\text{meV} \lesssim m_a \lesssim 0.2 ~\text{eV}$ for DFSZ-II, while no
constraint arises in the DFSZ-I case. Forthcoming CMB Stage 4 experiments will
be able to further test such scenarios; for instance the Xenon-1T window should
be fully probed at $2\sigma$ for a DFSZ-I axion.
