Two-dimensional (2D) flows can be controlled efficiently using spanwise "waviness", i.e. a control (e.g. wall blowing/suction or wall deformation) that is periodic in the spanwise direction. This study tackles the global linear stability of 2D flows subject to small-amplitude 3D spanwise-periodic control. Building on previous work for parallel flows [1], an adjoint method is proposed for computing the second-order sensitivity of eigenvalues. Since such control has indeed a zero net first-order (linear) effect, the second-order (quadratic) effect prevails. The sensitivity operator allows one (i) to predict the effect of any control without actually computing the controlled flow, and (ii) to compute the optimal control (and an orthogonal set of sub-optimal controls) for stabilization/destabilization or frequency modification. The proposed method takes advantage of the very spanwise-periodic nature of the control to reduce computational complexity (from a fully 3D problem to a 2D problem). The approach is applied to the leading eigenvalue of the laminar flow around a circular cylinder, and two kinds of spanwise-harmonic control are explored: wall actuation via blowing/suction, and wall deformation. Decomposing the eigenvalue variation, it is found that the 3D contribution (from the spanwise-periodic first-order flow modification) is generally larger than the 2D contribution from the mean flow correction (spanwise-invariant second-order flow modification). Over a wide range of control spanwise wavenumber, the optimal control for flow stabilization is top-down symmetric, leading to varicose streaks in the cylinder wake. Analyzing the competition between amplification and stabilization shows that optimal varicose streaks are not significantly more amplified than sinuous streaks but have a stronger stabilizing effect. The optimal wall deformation induces a flow modification very similar to that induced by the optimal wall actuation. In general, spanwise and tangential actuation have a small contribution to the optimal control, so normal-only actuation is a good trade-off between simplicity and effectiveness. Our method opens the way to the systematic design of optimal spanwise-periodic control for a variety of control objectives other than linear stability properties.