]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
scsi: storvsc: Ratelimit warning logs to prevent VM denial of service
authorEaswar Hariharan <eahariha@linux.microsoft.com>
Tue, 7 Jan 2025 17:28:40 +0000 (17:28 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 1 Feb 2025 17:24:01 +0000 (18:24 +0100)
commit d2138eab8cde61e0e6f62d0713e45202e8457d6d upstream.

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: https://github.com/microsoft/WSL/issues/9173
Signed-off-by: Easwar Hariharan <eahariha@linux.microsoft.com>
Link: https://lore.kernel.org/r/20250107-eahariha-ratelimit-storvsc-v1-1-7fc193d1f2b0@linux.microsoft.com
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/scsi/storvsc_drv.c

index ff1735e3127d023a048ffc1b1e7848944f2704d7..6a628a6b5a6d2e9b44c0ee9d086ae7a132ab9f2c 100644 (file)
@@ -189,6 +189,12 @@ struct vmscsi_win8_extension {
        u32 queue_sort_ey;
 } __packed;
 
+#define storvsc_log_ratelimited(dev, level, fmt, ...)                          \
+do {                                                                           \
+       if (do_logging(level))                                                  \
+               dev_warn_ratelimited(&(dev)->device, fmt, ##__VA_ARGS__);       \
+} while (0)
+
 struct vmscsi_request {
        u16 length;
        u8 srb_status;
@@ -1231,7 +1237,7 @@ static void storvsc_on_io_completion(struct storvsc_device *stor_device,
                int loglevel = (stor_pkt->vm_srb.cdb[0] == TEST_UNIT_READY) ?
                        STORVSC_LOGGING_WARN : STORVSC_LOGGING_ERROR;
 
-               storvsc_log(device, loglevel,
+               storvsc_log_ratelimited(device, loglevel,
                        "tag#%d cmd 0x%x status: scsi 0x%x srb 0x%x hv 0x%x\n",
                        scsi_cmd_to_rq(request->cmd)->tag,
                        stor_pkt->vm_srb.cdb[0],