If you have your 3.1.2 SHSH then you can restore to that, jb with blackra1in and then create a hacked 4.0 ipsw with pwnagetool.
If you don't have your 3.1.2 SHSH then you have to upgrade directly to 4.0.1 and yes your phone will be locked again. So if you are using a different carrier then go borrow a sim from a friend or pay someone at that carriers store a $20 to activate your phone. Then use jailbreakme.com