Having pushed out an iOS4 redsn0w updated yesterday for the iPhone 3G, the iPhone Dev Team are back today with a new version of their PwnageTool 4.01 for the iPhone 3GS, 3G and second-gen iPod touch. The new software works with the new iOS4 releases Apple pushed out earlier in the week, together with an updated version of the ultrasn0w baseband unlocking tool that severs the carrier lock.
The actual process you'll have to follow depends entirely on what you've previously done to your handset; if it's in stock, out-of-the-box condition then you can usually just use PwnageTool 4.01 and be done, downloading ultrasn0w from the Cydia app store once your device is jailbroken. However, if you've unlocked and/or jailbroken it before, such as with Spirit, then you may have to do a few other things first; more instructions here.
If you have a first-gen iPhone, first-gen iPod touch or third-gen iPod touch then you shouldn't try to use PwnageTool 4.01, as they're not currently supported; the Dev Team are apparently working on amending that. Similarly, if you've been using developer iOS4 ROMs on your handset you shouldn't use this tool; it's only for the official, general builds that were released on June 21st.