1 From d17ab6e1289b1d705c75de8a2351218962fb7352 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali@kernel.org>
3 Date: Thu, 9 Dec 2021 11:06:39 +0100
4 Subject: [PATCH] nvme: Do not allocate 8kB buffer on stack
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 Calling 'nvme scan' followed by 'nvme detail' crashes U-Boot on Turris
10 Omnia with the following error:
13 pc : [<0a000000>] lr : [<7ff80bfc>]
14 reloc pc : [<8a8c0000>] lr : [<00840bfc>]
15 sp : 7fb2b908 ip : 0000002a fp : 02000000
16 r10: 04000000 r9 : 7fb2fed0 r8 : e1000000
17 r7 : 0c000000 r6 : 03000000 r5 : 06000000 r4 : 01000000
18 r3 : 7fb30928 r2 : 7fb30928 r1 : 00000000 r0 : 00000000
19 Flags: nZCv IRQs off FIQs off Mode SVC_32
20 Code: 0f0fb4f0 0f0fb4f0 0f0fb4f0 0f0fb4f0 (f0f04b0f)
23 This happens when nvme_print_info() tries to return to the caller. It
24 looks like this error is caused by trying to allocate 8 KiB of memory
25 on the stack by the two uses of ALLOC_CACHE_ALIGN_BUFFER().
27 Use malloc_cache_aligned() to allocate this memory dynamically instead.
29 This fixes 'nvme detail' on Turris Omnia.
31 Note that similar change was applied to file drivers/nvme/nvme.c in past by
32 commit 2f83481dff9c ("nvme: use page-aligned buffer for identify command").
34 Signed-off-by: Pali Rohár <pali@kernel.org>
35 Signed-off-by: Marek Behún <marek.behun@nic.cz>
37 drivers/nvme/nvme_show.c | 35 ++++++++++++++++++++++++++---------
38 1 file changed, 26 insertions(+), 9 deletions(-)
40 --- a/drivers/nvme/nvme_show.c
41 +++ b/drivers/nvme/nvme_show.c
42 @@ -106,24 +106,41 @@ int nvme_print_info(struct udevice *udev
44 struct nvme_ns *ns = dev_get_priv(udev);
45 struct nvme_dev *dev = ns->dev;
46 - ALLOC_CACHE_ALIGN_BUFFER(char, buf_ns, sizeof(struct nvme_id_ns));
47 - struct nvme_id_ns *id = (struct nvme_id_ns *)buf_ns;
48 - ALLOC_CACHE_ALIGN_BUFFER(char, buf_ctrl, sizeof(struct nvme_id_ctrl));
49 - struct nvme_id_ctrl *ctrl = (struct nvme_id_ctrl *)buf_ctrl;
50 + struct nvme_id_ctrl *ctrl;
51 + struct nvme_id_ns *id;
54 - if (nvme_identify(dev, 0, 1, (dma_addr_t)(long)ctrl))
56 + ctrl = memalign(dev->page_size, sizeof(struct nvme_id_ctrl));
60 + if (nvme_identify(dev, 0, 1, (dma_addr_t)(long)ctrl)) {
65 print_optional_admin_cmd(le16_to_cpu(ctrl->oacs), ns->devnum);
66 print_optional_nvm_cmd(le16_to_cpu(ctrl->oncs), ns->devnum);
67 print_format_nvme_attributes(ctrl->fna, ns->devnum);
69 - if (nvme_identify(dev, ns->ns_id, 0, (dma_addr_t)(long)id))
71 + id = memalign(dev->page_size, sizeof(struct nvme_id_ns));
77 + if (nvme_identify(dev, ns->ns_id, 0, (dma_addr_t)(long)id)) {
82 print_formats(id, ns);
83 print_data_protect_cap(id->dpc, ns->devnum);
84 print_metadata_cap(id->mc, ns->devnum);