Skip to content

Commit dccc96a

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: core: Reduce memory required for SCSI logging
The data structure used for log messages is so large that it can cause a boot failure. Since allocations from that data structure can fail anyway, use kmalloc() / kfree() instead of that data structure. See also https://bugzilla.kernel.org/show_bug.cgi?id=204119. See also commit ded85c1 ("scsi: Implement per-cpu logging buffer") # v4.0. Reported-by: Jan Palus <jpalus@fastmail.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Hannes Reinecke <hare@suse.com> Cc: Johannes Thumshirn <jthumshirn@suse.de> Cc: Ming Lei <ming.lei@redhat.com> Cc: Jan Palus <jpalus@fastmail.com> Signed-off-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 94ef80a commit dccc96a

2 files changed

Lines changed: 3 additions & 47 deletions

File tree

‎drivers/scsi/scsi_logging.c‎

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,57 +15,15 @@
1515
#include <scsi/scsi_eh.h>
1616
#include <scsi/scsi_dbg.h>
1717

18-
#define SCSI_LOG_SPOOLSIZE 4096
19-
20-
#if (SCSI_LOG_SPOOLSIZE / SCSI_LOG_BUFSIZE) > BITS_PER_LONG
21-
#warning SCSI logging bitmask too large
22-
#endif
23-
24-
struct scsi_log_buf {
25-
char buffer[SCSI_LOG_SPOOLSIZE];
26-
unsigned long map;
27-
};
28-
29-
static DEFINE_PER_CPU(struct scsi_log_buf, scsi_format_log);
30-
3118
static char *scsi_log_reserve_buffer(size_t *len)
3219
{
33-
struct scsi_log_buf *buf;
34-
unsigned long map_bits = sizeof(buf->buffer) / SCSI_LOG_BUFSIZE;
35-
unsigned long idx = 0;
36-
37-
preempt_disable();
38-
buf = this_cpu_ptr(&scsi_format_log);
39-
idx = find_first_zero_bit(&buf->map, map_bits);
40-
if (likely(idx < map_bits)) {
41-
while (test_and_set_bit(idx, &buf->map)) {
42-
idx = find_next_zero_bit(&buf->map, map_bits, idx);
43-
if (idx >= map_bits)
44-
break;
45-
}
46-
}
47-
if (WARN_ON(idx >= map_bits)) {
48-
preempt_enable();
49-
return NULL;
50-
}
51-
*len = SCSI_LOG_BUFSIZE;
52-
return buf->buffer + idx * SCSI_LOG_BUFSIZE;
20+
*len = 128;
21+
return kmalloc(*len, GFP_ATOMIC);
5322
}
5423

5524
static void scsi_log_release_buffer(char *bufptr)
5625
{
57-
struct scsi_log_buf *buf;
58-
unsigned long idx;
59-
int ret;
60-
61-
buf = this_cpu_ptr(&scsi_format_log);
62-
if (bufptr >= buf->buffer &&
63-
bufptr < buf->buffer + SCSI_LOG_SPOOLSIZE) {
64-
idx = (bufptr - buf->buffer) / SCSI_LOG_BUFSIZE;
65-
ret = test_and_clear_bit(idx, &buf->map);
66-
WARN_ON(!ret);
67-
}
68-
preempt_enable();
26+
kfree(bufptr);
6927
}
7028

7129
static inline const char *scmd_name(const struct scsi_cmnd *scmd)

‎include/scsi/scsi_dbg.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ struct scsi_cmnd;
66
struct scsi_device;
77
struct scsi_sense_hdr;
88

9-
#define SCSI_LOG_BUFSIZE 128
10-
119
extern void scsi_print_command(struct scsi_cmnd *);
1210
extern size_t __scsi_format_command(char *, size_t,
1311
const unsigned char *, size_t);

0 commit comments

Comments
 (0)