Backport few upstream changes included between v5.15 and v6.1. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> (cherry picked from commit 418aadaec9dd9c67b2a4fffb51dfa1fb5fdf5098)