Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3377409ybp; Sun, 6 Oct 2019 10:35:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxALIuo3ai9tA49K4wTyyJRK2oFRYH7cwGqJGGzwA/9JZA75tVKxo/rmc2J0BEvCO76Bwy0 X-Received: by 2002:a50:b6a8:: with SMTP id d37mr25548141ede.63.1570383350439; Sun, 06 Oct 2019 10:35:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570383350; cv=none; d=google.com; s=arc-20160816; b=GA3hVVi36zBzu03xiTxhOdDAaKqKRuXIgcS72sn/bNgHLHNvdUYhWeDOX/ddTG5Go+ rOfkT33uvgl6IzW3B6CNQSKSykkCuW2G8027/uY+wCh6IaB352CNMZw24L94FO+XbiD7 HGmGBfs3y8c13VCSs2VwaoW121RmujhHAnlzJcSaem3AobtKqB6tvAjNUwludiEcJeGT kbr+UVnKGReHjyjfYgBo9S8FJ0kaZevLTla8jj1pz9iAsfhR7BofgytJLiaAzIwS0ZId admRwCW1hpetYHOj7PaCYOIx8IQuFokJsT9ZM4QCuOuJ5fs7rwVKtg3SO6VCXeMCLaN0 B8/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/hhNE6tGVOAThv1NBYIVBYFzu1XkHTstDpOTHmvbu3E=; b=pQi/p+nW6qjqFtoj8/RyEhikU6NrzHtu6Y9ftRH3E6BxxXkWS72ev0XeOdcgLVBJuN V99JfENkCzm9h9Um4T85d/FtIKelFj8ArZeLdaRKKSgjSRhce4A4PeeTDQnIj45ibjcx CYzwd051y0BBQ/sGD5lrgiUtUcqBXknFt0VBDUI4UHhkcXJTud9l3lromRvfwCUfDnkb FVSYQlpLz+/H6JHpOpOPA0x3Oxs/fZdA74hY3W2L9RrvwWDxM3MddaGBSOdj5EjjRX8+ ZlpR+kebIVFePa6mXyXTro25FBqTuMKG8TCM/7ZOm0zpKM2KI14SGxNFYZUJosJklimz dIVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dxxx0C1W; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id oc20si5767297ejb.260.2019.10.06.10.35.26; Sun, 06 Oct 2019 10:35:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dxxx0C1W; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729495AbfJFRbs (ORCPT + 99 others); Sun, 6 Oct 2019 13:31:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:58040 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729467AbfJFRbq (ORCPT ); Sun, 6 Oct 2019 13:31:46 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 295F82087E; Sun, 6 Oct 2019 17:31:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383105; bh=z73psTK34fbmksqrLT4/YfS8TjnQVVU5eQzrEgt7u9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dxxx0C1WFJD3p18l0UdZCbGGaCe21mG9rOXYkeqXTVwRcjMyA5TPRNWUwIog8/92z FrTs+rOidl/erwTizjKQCsmG0IUb9PQUCG3/d9KItHezGuxt1KnnQEe39UOJUgfa+c WEx1vk39smXX3MPcXY8ffiynejIyOvYHZPjtAf4g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Palus , Christoph Hellwig , Hannes Reinecke , Johannes Thumshirn , Ming Lei , Bart Van Assche , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.19 045/106] scsi: core: Reduce memory required for SCSI logging Date: Sun, 6 Oct 2019 19:20:51 +0200 Message-Id: <20191006171143.338610512@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171124.641144086@linuxfoundation.org> References: <20191006171124.641144086@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bart Van Assche [ Upstream commit dccc96abfb21dc19d69e707c38c8ba439bba7160 ] 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 ded85c193a39 ("scsi: Implement per-cpu logging buffer") # v4.0. Reported-by: Jan Palus Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Ming Lei Cc: Jan Palus Signed-off-by: Bart Van Assche Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/scsi_logging.c | 48 +++---------------------------------- include/scsi/scsi_dbg.h | 2 -- 2 files changed, 3 insertions(+), 47 deletions(-) diff --git a/drivers/scsi/scsi_logging.c b/drivers/scsi/scsi_logging.c index bd70339c1242e..03d9855a6afd7 100644 --- a/drivers/scsi/scsi_logging.c +++ b/drivers/scsi/scsi_logging.c @@ -16,57 +16,15 @@ #include #include -#define SCSI_LOG_SPOOLSIZE 4096 - -#if (SCSI_LOG_SPOOLSIZE / SCSI_LOG_BUFSIZE) > BITS_PER_LONG -#warning SCSI logging bitmask too large -#endif - -struct scsi_log_buf { - char buffer[SCSI_LOG_SPOOLSIZE]; - unsigned long map; -}; - -static DEFINE_PER_CPU(struct scsi_log_buf, scsi_format_log); - static char *scsi_log_reserve_buffer(size_t *len) { - struct scsi_log_buf *buf; - unsigned long map_bits = sizeof(buf->buffer) / SCSI_LOG_BUFSIZE; - unsigned long idx = 0; - - preempt_disable(); - buf = this_cpu_ptr(&scsi_format_log); - idx = find_first_zero_bit(&buf->map, map_bits); - if (likely(idx < map_bits)) { - while (test_and_set_bit(idx, &buf->map)) { - idx = find_next_zero_bit(&buf->map, map_bits, idx); - if (idx >= map_bits) - break; - } - } - if (WARN_ON(idx >= map_bits)) { - preempt_enable(); - return NULL; - } - *len = SCSI_LOG_BUFSIZE; - return buf->buffer + idx * SCSI_LOG_BUFSIZE; + *len = 128; + return kmalloc(*len, GFP_ATOMIC); } static void scsi_log_release_buffer(char *bufptr) { - struct scsi_log_buf *buf; - unsigned long idx; - int ret; - - buf = this_cpu_ptr(&scsi_format_log); - if (bufptr >= buf->buffer && - bufptr < buf->buffer + SCSI_LOG_SPOOLSIZE) { - idx = (bufptr - buf->buffer) / SCSI_LOG_BUFSIZE; - ret = test_and_clear_bit(idx, &buf->map); - WARN_ON(!ret); - } - preempt_enable(); + kfree(bufptr); } static inline const char *scmd_name(const struct scsi_cmnd *scmd) diff --git a/include/scsi/scsi_dbg.h b/include/scsi/scsi_dbg.h index e03bd9d41fa8f..7b196d2346264 100644 --- a/include/scsi/scsi_dbg.h +++ b/include/scsi/scsi_dbg.h @@ -6,8 +6,6 @@ struct scsi_cmnd; struct scsi_device; struct scsi_sense_hdr; -#define SCSI_LOG_BUFSIZE 128 - extern void scsi_print_command(struct scsi_cmnd *); extern size_t __scsi_format_command(char *, size_t, const unsigned char *, size_t); -- 2.20.1