You won't generally get 4K over DVI ('but some things show specs for it' - find a monitor that isn't an IBM T220-clone that takes 4K/9MP over DVI and we can talk). Dual-link DVI KVMs are a bit esoteric, but I know Belkin makes a few (I have one of these and it works well:
https://www.belkin.com/us/p/P-F1DN104B-3/) - they can get really pricey though, and from browsing their website they do offer 'dual view' (two monitor) models as well:
https://www.belkin.com/us/p/P-F1DN104F-3/
For HDMI you're probably better off finding an 'HDMI matrix' that accepts HDMI 2.0, which will exist, but will also likely be pricey (some post-script web searching looks like around $100 US), and then adding a USB switch for the peripherals. (like this:
https://www.iogear.com/product/GUS402)
The other other option is if the monitors have >1 input (which is likely), use their on-board switching facility (which will also let you 'split' the monitors between two machines), and just get a USB switch for the peripherals.