  One of the major goals of future cosmic microwave background (CMB) $B$-mode
polarization experiments is the detection of primordial gravitational waves
through an unbiased measurement of the tensor-to-scalar ratio $r$. Robust
detection of this signal will require mitigating all possible contamination to
the $B$-mode polarization from astrophysical origins. One such extragalactic
contamination arises from the patchiness in the electron density during the
reionization epoch. Along with the signature on CMB polarization, the patchy
reionization can source secondary anisotropies on the CMB temperature through
the kinetic Sunyaev-Zeldovich (kSZ) effect. In order to study the impact of
this foreground for the upcoming CMB missions, we present a self-consistent
framework to compute the CMB anisotropies based on a physically motivated model
of reionization. We show that the value of $r$ can bias towards a higher value
if the secondary contribution from reionization is neglected. However,
combining small-scale kSZ signal, large-scale $E$-mode polarization, and
$B$-mode polarization measurements, we can put constraints on the patchiness in
electron density during reionization and can mitigate its impact on the value
of $r$. CMB missions such as CMB-S4 and PICO may experience a bias of
$>0.17\sigma$ which can go as high as $\sim 0.73\sigma$ for extreme
reionization models allowed by the Planck and SPT CMB measurements. As future
experiments target to measure $r$ at $5\sigma$, this is likely to affect the
measurement significance and hence possibly affect the claim of detection of
$r$, if not mitigated properly by using joint estimations of different
reionization observables.
