Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp775332ybj; Tue, 5 May 2020 07:23:17 -0700 (PDT) X-Google-Smtp-Source: APiQypK//vpNoG3i/xdHGD/QZqv2zyhLNDyLcsk3XeXE5BOE0+ph5ZxhETJK+GC26YhD+GJ7PEdR X-Received: by 2002:aa7:dac3:: with SMTP id x3mr2919146eds.379.1588688597652; Tue, 05 May 2020 07:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588688597; cv=none; d=google.com; s=arc-20160816; b=yNNmzskVOV/h6tGERQ8TGInkLE3q4gO2Nj+nHMq04KFL5I5PaL0e7cuSbmgRHi8AwL TxzyLdquM6x+aLasYEzvhxLIYJcsFuWrz1tyWeDQTe6ovultIt275xf3Xi+qJvwFWDUi 2kd6E6ZzHG52M8IpNyrf5J5RmVwp0TZVYSOvNM/RApIu7TO8yEY4GVjkF3FspxBhGOVi VbapFwFAPYCSJa6RaTLuOFZ1AVPA3NEsQ8wUPyXPC5zNuTJAEtFjF+ySYPL7rwcyt9EC wbw8qw4yFpFFMNk9mJwpRaLRav4BhXHU9zwyvbPbD8NP3Gnq3i9QlzgNDiH3XJYzGRJY tLTw== 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 :message-id:date:subject:cc:to:from; bh=2ewXQXE8DuvFn7NiX1bw6o75ZDONUAus6OOJvO2KDKE=; b=SqFGtAB9aV1T3+8Go8d0qlybPzEJjK8fKeqN4E69OjgfxYpYeUfdQ9qXrEiLCsCGjm F0bkOcG/Jkux3uCa+kFFo8gc1v/fqrAzdkqJ36CGHtVjMLeLwyZ1krE7wHMNuO9Sh2QK M3ehh80t+4pqJRPGK7f+iam8kRs4nuWk+TNiY27Sn263S/6ibwIH7ScApmydkmzn1+Ul qc55q3HQnzn+p7nsWF16b2KsBDFeLtiNJwvBD3Lkdo0D8GucPAJ6jyNsw3mliPFk2s/d vuth8FwYbma8VjDcU6660+BeREn//j8N0hCrRwkkVcQlQi/psXgBpDjZZW3skCms82x1 UOvg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce9si1289760ejb.154.2020.05.05.07.22.53; Tue, 05 May 2020 07:23:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730110AbgEEOUL (ORCPT + 99 others); Tue, 5 May 2020 10:20:11 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:45565 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729997AbgEEOQF (ORCPT ); Tue, 5 May 2020 10:16:05 -0400 Received: from localhost.localdomain ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.145]) with ESMTPA (Nemesis) id 1M9nEJ-1jSNK23B49-005rjT; Tue, 05 May 2020 16:15:47 +0200 From: Arnd Bergmann To: Boris Ostrovsky , Juergen Gross Cc: Arnd Bergmann , Stefano Stabellini , Yan Yankovskyi , Wei Liu , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: [PATCH] xenbus: avoid stack overflow warning Date: Tue, 5 May 2020 16:15:37 +0200 Message-Id: <20200505141546.824573-1-arnd@arndb.de> X-Mailer: git-send-email 2.26.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:A6tw1zrTOAQW5yW+MxCDJvOopLSS/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9P0oo9BzRoS655scEfNndInz 7spEwdABS87Ga/MwDfUpMag/fwUWsaGdnX00Lewh0xtIkUjZQc= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The __xenbus_map_ring() function has two large arrays, 'map' and 'unmap' on its stack. When clang decides to inline it into its caller, xenbus_map_ring_valloc_hvm(), the total stack usage exceeds the warning limit for stack size on 32-bit architectures. drivers/xen/xenbus/xenbus_client.c:592:12: error: stack frame size of 1104 bytes in function 'xenbus_map_ring_valloc_hvm' [-Werror,-Wframe-larger-than=] As far as I can tell, other compilers don't inline it here, so we get no warning, but the stack usage is actually the same. It is possible for both arrays to use the same location on the stack, but the compiler cannot prove that this is safe because they get passed to external functions that may end up using them until they go out of scope. Move the two arrays into separate basic blocks to limit the scope and force them to occupy less stack in total, regardless of the inlining decision. Signed-off-by: Arnd Bergmann --- drivers/xen/xenbus/xenbus_client.c | 74 +++++++++++++++++------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c index 040d2a43e8e3..23ca70378e36 100644 --- a/drivers/xen/xenbus/xenbus_client.c +++ b/drivers/xen/xenbus/xenbus_client.c @@ -470,54 +470,62 @@ static int __xenbus_map_ring(struct xenbus_device *dev, unsigned int flags, bool *leaked) { - struct gnttab_map_grant_ref map[XENBUS_MAX_RING_GRANTS]; - struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_GRANTS]; int i, j; int err = GNTST_okay; - if (nr_grefs > XENBUS_MAX_RING_GRANTS) - return -EINVAL; + { + struct gnttab_map_grant_ref map[XENBUS_MAX_RING_GRANTS]; - for (i = 0; i < nr_grefs; i++) { - memset(&map[i], 0, sizeof(map[i])); - gnttab_set_map_op(&map[i], addrs[i], flags, gnt_refs[i], - dev->otherend_id); - handles[i] = INVALID_GRANT_HANDLE; - } + if (nr_grefs > XENBUS_MAX_RING_GRANTS) + return -EINVAL; - gnttab_batch_map(map, i); + for (i = 0; i < nr_grefs; i++) { + memset(&map[i], 0, sizeof(map[i])); + gnttab_set_map_op(&map[i], addrs[i], flags, + gnt_refs[i], dev->otherend_id); + handles[i] = INVALID_GRANT_HANDLE; + } + + gnttab_batch_map(map, i); - for (i = 0; i < nr_grefs; i++) { - if (map[i].status != GNTST_okay) { - err = map[i].status; - xenbus_dev_fatal(dev, map[i].status, + for (i = 0; i < nr_grefs; i++) { + if (map[i].status != GNTST_okay) { + err = map[i].status; + xenbus_dev_fatal(dev, map[i].status, "mapping in shared page %d from domain %d", gnt_refs[i], dev->otherend_id); - goto fail; - } else - handles[i] = map[i].handle; + goto fail; + } else + handles[i] = map[i].handle; + } } - return GNTST_okay; fail: - for (i = j = 0; i < nr_grefs; i++) { - if (handles[i] != INVALID_GRANT_HANDLE) { - memset(&unmap[j], 0, sizeof(unmap[j])); - gnttab_set_unmap_op(&unmap[j], (phys_addr_t)addrs[i], - GNTMAP_host_map, handles[i]); - j++; + { + struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_GRANTS]; + + for (i = j = 0; i < nr_grefs; i++) { + if (handles[i] != INVALID_GRANT_HANDLE) { + memset(&unmap[j], 0, sizeof(unmap[j])); + gnttab_set_unmap_op(&unmap[j], + (phys_addr_t)addrs[i], + GNTMAP_host_map, + handles[i]); + j++; + } } - } - if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap, j)) - BUG(); + if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, + unmap, j)) + BUG(); - *leaked = false; - for (i = 0; i < j; i++) { - if (unmap[i].status != GNTST_okay) { - *leaked = true; - break; + *leaked = false; + for (i = 0; i < j; i++) { + if (unmap[i].status != GNTST_okay) { + *leaked = true; + break; + } } } -- 2.26.0