Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp9120755ybl; Fri, 17 Jan 2020 06:41:42 -0800 (PST) X-Google-Smtp-Source: APXvYqx5/OVSg68gwkPC88+Xe+Qimi0NutO/De3XaCH4JrasPVaPcKzRT7e8gP2fVn3oS3ko4vhV X-Received: by 2002:aca:3cd7:: with SMTP id j206mr3723412oia.142.1579272101999; Fri, 17 Jan 2020 06:41:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579272101; cv=none; d=google.com; s=arc-20160816; b=sSrR0/oVOk5DPk2A7fsq4w+BYLGGU66MDFtH59EhhesXQGwVaN5rygmTNsMN/PCoIK 00q8c8OTLPBEBeOm2O2QGWiSdtTsjDXSl0XQQsDnGpr5kmMipSmKo3G2kB9qXcaJCAmm 7dJyFVKiFLAnqACiXE0EhWu1P3FPjDktOxpYmlyj7HBYudSJDfyd7rQOGoQnDNTwKvHQ wR7WuXx7J9H/BEyIcVtVdOnqpiiEDsIxag1GW1GMoeudBzawAjtjrr3K2DqOxkdoHsyh 1vNwV4yhsChWfT8OHI/Ixju7B2lMaPz1oI8iTmz8tkk1VOp3qeA5qFYbwpYxI4Wb7QkY o2sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=KudCoM842RaNlfNIDc8GILSto65qU3Yl67MFnAD9q7I=; b=dne+c03pqQa9ANe8QRoUr9sReecaEEBtP/xrMa8fR8ZnknfJeZAQtuPDtflKYE1vst 3hzhGoD/7M4vznouvaNu6J14jmFshrHyZoT1CQL7J3pajSJfHWJJ+mxHUMnLcJb8H9IM e3ILp+AVDzdwMo6/YopShx+g78A5unkkGcnpniTEMdJzYkfmd6iHUalwAR06ryqa9lrw 9LNPNQF0VnKqHzRn3BDHIUArdRApJ5CuaAsX3P+oyAgEyQGFC3Us/ucikoZgnusmkD5L 4rw7CzIqXIL3Rv/taXjvc6G0hBdTrl3h4rhVPL1x5Ccn8EUOd+gg8BUddXLIEMYW3DBJ m6mg== ARC-Authentication-Results: i=1; mx.google.com; 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 k21si14524771otr.1.2020.01.17.06.41.30; Fri, 17 Jan 2020 06:41:41 -0800 (PST) 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; 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 S1729279AbgAQOkB (ORCPT + 99 others); Fri, 17 Jan 2020 09:40:01 -0500 Received: from mx2.suse.de ([195.135.220.15]:58472 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728512AbgAQOkA (ORCPT ); Fri, 17 Jan 2020 09:40:00 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 59B93B17A; Fri, 17 Jan 2020 14:39:58 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Konrad Rzeszutek Wilk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Boris Ostrovsky , Stefano Stabellini , Jens Axboe Subject: [PATCH] xen/blkfront: limit allocated memory size to actual use case Date: Fri, 17 Jan 2020 15:39:55 +0100 Message-Id: <20200117143955.18892-1-jgross@suse.com> X-Mailer: git-send-email 2.16.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Today the Xen blkfront driver allocates memory for one struct blkfront_ring_info for each communication ring. This structure is statically sized for the maximum supported configuration resulting in a size of more than 90 kB. As the main size contributor is one array inside the struct, the memory allocation can easily be limited by moving this array to be the last structure element and to allocate only the memory for the actually needed array size. Signed-off-by: Juergen Gross --- drivers/block/xen-blkfront.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index c02be06c5299..61491167da19 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -151,9 +151,6 @@ MODULE_PARM_DESC(max_ring_page_order, "Maximum order of pages to be used for the #define BLK_RING_SIZE(info) \ __CONST_RING_SIZE(blkif, XEN_PAGE_SIZE * (info)->nr_ring_pages) -#define BLK_MAX_RING_SIZE \ - __CONST_RING_SIZE(blkif, XEN_PAGE_SIZE * XENBUS_MAX_RING_GRANTS) - /* * ring-ref%u i=(-1UL) would take 11 characters + 'ring-ref' is 8, so 19 * characters are enough. Define to 20 to keep consistent with backend. @@ -177,12 +174,12 @@ struct blkfront_ring_info { unsigned int evtchn, irq; struct work_struct work; struct gnttab_free_callback callback; - struct blk_shadow shadow[BLK_MAX_RING_SIZE]; struct list_head indirect_pages; struct list_head grants; unsigned int persistent_gnts_c; unsigned long shadow_free; struct blkfront_info *dev_info; + struct blk_shadow shadow[]; }; /* @@ -1915,7 +1912,8 @@ static int negotiate_mq(struct blkfront_info *info) info->nr_rings = 1; info->rinfo = kvcalloc(info->nr_rings, - sizeof(struct blkfront_ring_info), + struct_size(info->rinfo, shadow, + BLK_RING_SIZE(info)), GFP_KERNEL); if (!info->rinfo) { xenbus_dev_fatal(info->xbdev, -ENOMEM, "allocating ring_info structure"); -- 2.16.4