Skip to content

Commit d2138ea

Browse files
easwarhmartinkpetersen
authored andcommitted
scsi: storvsc: Ratelimit warning logs to prevent VM denial of service
If there's a persistent error in the hypervisor, the SCSI warning for failed I/O can flood the kernel log and max out CPU utilization, preventing troubleshooting from the VM side. Ratelimit the warning so it doesn't DoS the VM. Closes: microsoft/WSL#9173 Signed-off-by: Easwar Hariharan <[email protected]> Link: https://lore.kernel.org/r/20250107-eahariha-ratelimit-storvsc-v1-1-7fc193d1f2b0@linux.microsoft.com Reviewed-by: Michael Kelley <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 37d061e commit d2138ea

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/scsi/storvsc_drv.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ do { \
171171
dev_warn(&(dev)->device, fmt, ##__VA_ARGS__); \
172172
} while (0)
173173

174+
#define storvsc_log_ratelimited(dev, level, fmt, ...) \
175+
do { \
176+
if (do_logging(level)) \
177+
dev_warn_ratelimited(&(dev)->device, fmt, ##__VA_ARGS__); \
178+
} while (0)
179+
174180
struct vmscsi_request {
175181
u16 length;
176182
u8 srb_status;
@@ -1176,7 +1182,7 @@ static void storvsc_on_io_completion(struct storvsc_device *stor_device,
11761182
int loglevel = (stor_pkt->vm_srb.cdb[0] == TEST_UNIT_READY) ?
11771183
STORVSC_LOGGING_WARN : STORVSC_LOGGING_ERROR;
11781184

1179-
storvsc_log(device, loglevel,
1185+
storvsc_log_ratelimited(device, loglevel,
11801186
"tag#%d cmd 0x%x status: scsi 0x%x srb 0x%x hv 0x%x\n",
11811187
scsi_cmd_to_rq(request->cmd)->tag,
11821188
stor_pkt->vm_srb.cdb[0],

0 commit comments

Comments
 (0)