If you are flying directly from another country, you can use the 144 TWOV. This is a transit without visa. You will receive this when you arrive at the airport. This is not valid if you fly into Beijing and have a connecting flight to Shanghai. Flight must be direct. When you arrive back to Shanghai from your cruise, you will also need to apply for another 144 TWOV. Essentially you are transiting through Shanghai to your destination. So you can stay in Shanghai visa free up to 144 hours. I have not personally used this for a cruise but I have used it in Guangzhou, flying in and out without a China visa. A friend has used it on a RCL cruise from Shanghai. You can look up the rules and details. Make sure you have all your travel documents on you. Immigration needs to see your connecting plane/cruise tickets.
https://www.china-briefing.com/news/china-resumes-144-hour-visa-free-transit-policy-for-foreigners-who-can-apply/#:~:text=Under the 144-hour visa,well as satisfy other requirements
https://en.m.wikipedia.org/wiki/Visa_policy_of_mainland_China#72-hour_stay_/_144-hour_stay