Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp551887pxk; Thu, 1 Oct 2020 08:43:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQyE9SUFZz3lP3dXbvNLlwBvSY2FFcCujUVyw9UrPe/X9ib0LLmUOXRgn2x6vokTYunDns X-Received: by 2002:a17:906:14db:: with SMTP id y27mr2679224ejc.148.1601566995794; Thu, 01 Oct 2020 08:43:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601566995; cv=none; d=google.com; s=arc-20160816; b=jjN8D9MZx5XJfTsXeEZH61blaw498HP5MyQFI9q0BmrJ4L5tKSxNgWmL7kH2JCuNIc MQHJq9rLvXK2Ozq+7IvqjMREz0gWqVV6HTJikpTbXjqejCE+xgdWcUM6t0xi4Zf/0Fcu A7gIn/dIpOtR8n4z2pRm/ZQCfNS1FCrsXhIpOGsD/Z3qb9hsGB7/R0UNoYrXttDnJ9FH UCcwgYeFHz2wZc5yO7++dIC+9Fi7UqkkHCJzqFXHG5uZZhXbHUIU3GN9gyyRnSQmiPlf 6jsilyRUzYVCtSi23l5aH0F9DlSI93gh119nxdul0LEU7outYKHfunRB7IravjFhy30/ J0Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=uFXzy5Lofx97mpwMssSqzQPbe7ED1iXWmhXzWnM2Ycc=; b=uO04TXqNsk60WQLpayBO4clnSEWEnTIPu+4sMGAUGgX+1g3Ny3xRzDPDqaZZ13nnO1 dTc4Gf5LdoDCJ5olNtr2Yec9O0LgYlGwa6HkMykCA7STlykA+SLboSoDeg/p3VW3yUHj TrOnJ16mG9kvXmT7oz8Rrtw58HjLM17aUYtH0Ma/97XscQqOuoHKRqq6/JZojaOiOOtL zMLLyOYMX5nq7FlN68OaDNf4SAOKLE1fbMB1goCwAe7XaYc+xBivxDitQExvE7w4JSG6 aJQayeKglXbGmI/78D/E6SibD6Hx0CSskoUngMy5RDzotsJMcccLbeWMX9LQGKbcuvz5 lF2A== 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 g15si3976547edp.40.2020.10.01.08.42.52; Thu, 01 Oct 2020 08:43:15 -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 S1732462AbgJAPjs (ORCPT + 99 others); Thu, 1 Oct 2020 11:39:48 -0400 Received: from smtprelay0107.hostedemail.com ([216.40.44.107]:46002 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731885AbgJAPjr (ORCPT ); Thu, 1 Oct 2020 11:39:47 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay05.hostedemail.com (Postfix) with ESMTP id 8956A1802912F; Thu, 1 Oct 2020 15:39:45 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,,RULES_HIT:41:152:355:379:599:973:981:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3870:3871:3872:4321:5007:8603:10004:10400:10848:11026:11232:11657:11658:11914:12043:12048:12296:12297:12438:12740:12895:13069:13311:13357:13894:14659:14721:21080:21627:21972:21990:30012:30054:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: flag54_230d6c72719c X-Filterd-Recvd-Size: 2832 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf14.hostedemail.com (Postfix) with ESMTPA; Thu, 1 Oct 2020 15:39:42 +0000 (UTC) Message-ID: Subject: Re: [PATCH v2][next] x86/uv/time: Replace one-element array and save heap space From: Joe Perches To: "Gustavo A. R. Silva" , Steve Wahl , Dimitri Sivanich , Russ Anderson , Darren Hart , Andy Shevchenko , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Cc: x86@kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , linux-hardening@vger.kernel.org Date: Thu, 01 Oct 2020 08:39:39 -0700 In-Reply-To: <20201001145608.GA10204@embeddedor> References: <20201001145608.GA10204@embeddedor> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.4-0ubuntu1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2020-10-01 at 09:56 -0500, Gustavo A. R. Silva wrote: > There is a regular need in the kernel to provide a way to declare having > a dynamically sized set of trailing elements in a structure. Kernel code > should always use “flexible array members”[1] for these cases. The older > style of one-element or zero-length arrays should no longer be used[2]. > > struct uv_rtc_timer_head contains a one-element array cpu[1]. > > Switch it to a flexible array and use the struct_size() helper to > calculate the allocation size. Also, save some heap space in the > process[3]. trivia: > diff --git a/arch/x86/platform/uv/uv_time.c b/arch/x86/platform/uv/uv_time.c [] > @@ -148,9 +148,8 @@ static __init int uv_rtc_allocate_timers(void) > struct uv_rtc_timer_head *head = blade_info[bid]; > > if (!head) { > - head = kmalloc_node(sizeof(struct uv_rtc_timer_head) + > - (uv_blade_nr_possible_cpus(bid) * > - 2 * sizeof(u64)), > + head = kmalloc_node(struct_size(head, cpu, > + uv_blade_nr_possible_cpus(bid)), > GFP_KERNEL, nid); > if (!head) { > uv_rtc_deallocate_timers(); Maybe save the value of uv_blade_nr_possible_cpus(bid) to reduce duplication and make the sizeof_struct more readable? if (!head) { int ncpus = uv_blade_nr_possible_cpus(bid); head = kmalloc_node(struct_size(head, cpu, ncpus), GFP_KERNEL, nid); if (!head) { uv_rtc_deallocate_timers(); return -ENOMEM; } spin_lock_init(&head->lock); head->ncpus = ncpus; head->next_cpu = -1; blade_info[bid] = head; }