From patchwork Fri Oct 5 16:13:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 148221 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp640244lji; Fri, 5 Oct 2018 09:14:41 -0700 (PDT) X-Google-Smtp-Source: ACcGV63giUr/+SjxN13Hm/GTzXGL9Gbvdst3JAxTeqsSXP/aU7ddSOS26XjA0GKYiqgc+tsrukMs X-Received: by 2002:a17:902:6848:: with SMTP id f8-v6mr12489883pln.27.1538756081562; Fri, 05 Oct 2018 09:14:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538756081; cv=none; d=google.com; s=arc-20160816; b=a60F4mRiUAkRTG0doiQlSqrR4VcQW7TLg5XKd5jqYf0TPRzmvgnZ374og9JyN/9ROY CF3JMdkZCGp9aiMB4YVg0oqd5/BjF52zoNCJBQLSmL3CTOnMDDcsIBNp/PH/f0Bmo4wU pviTE89VigDWrNBbYHF9IS5+pEHE7M2ImnW+yibU2soJj3Dtlzw0GO+sAdjZvNWcj/CX qKgLbh1sq2Ey1howpgxcihLgWyfKPGXNiFvQ2pxWYS9rzLse636aXNOOuA55Z+lis+7O XH8DamTLxLAakX8v98ia4Cj4DC/AXXbmjUN4YCrhu1Zyby4/b/CwRA0vS4EuOYJcGkur /j4w== 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=Z8R806FbxYeTfkl/1x/Q3rvmypcueih3J3cy73B88tA=; b=SXhrlQolYpTZuI8FLIUan/qnmUcvRJ+r1I3lvTGrMpUmeT6N0sGh6iac7dYfisTcvl ibgEp0qj18tmd7jNQBYoDvUgR9agcyrsXhc+JhJNu2wi8YvdmaL8Wmad7P12N1fAnkji Rg6guZ6126kqfXHzzM91PHn51AS/0krnf4wPSPIMAw+Av7ADm7VR3HZp9Al8YPZU+tAr Rgh4Ru3ouLsYmG0LgAEIWZDosS/x3Lt74l/DSjN6nqm8ogtviZuDgo85d6lPenWOsdfp 89+qOsE+ZFoYzL9XCIL2AQ4QyRsQ0rk1r1h3hgU13+sCLjOy3HbgYlBmeP7jD0J0UFIB sV3w== 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 b8-v6si772450ple.411.2018.10.05.09.14.41; Fri, 05 Oct 2018 09:14:41 -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; 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 S1729193AbeJEXOC (ORCPT + 32 others); Fri, 5 Oct 2018 19:14:02 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:42863 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729138AbeJEXOB (ORCPT ); Fri, 5 Oct 2018 19:14:01 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.145]) with ESMTPA (Nemesis) id 1MfHxt-1fW6yQ0J1H-00gr4H; Fri, 05 Oct 2018 18:13:37 +0200 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.145]) with ESMTPA (Nemesis) id 1MfHxt-1fW6yQ0J1H-00gr4H; Fri, 05 Oct 2018 18:13:37 +0200 From: Arnd Bergmann To: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org Cc: Kees Cook , Arnd Bergmann , "H. Peter Anvin" , Toshi Kani , Andrew Morton , Joerg Roedel , linux-kernel@vger.kernel.org Subject: [PATCH] x86: avoid VLA in pgd_alloc() Date: Fri, 5 Oct 2018 18:13:16 +0200 Message-Id: <20181005161333.765973-1-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 X-Provags-ID: V03:K1:8zIErsJuioMiMQ2HAReOpNhMdFUd4Dv+Qsv/DG3fC8VXw2yO8zO 9qkXpbC5HpA9nrAyAUQrO/sJ9/3P6fXHn+6gL94XfnQ0ITk27OhT3MRYmftZmcZeYeI4+0M Iwht1EX0inm/WizYzPgjvCXFIXu/+dQbZyUNH/6Swc+Izcx+LT89F6cTrNSQx8K8ZZGtYZY EgmIXGRud/eMIMDHnAxtA== X-UI-Out-Filterresults: notjunk:1; V01:K0:GDBiROfLgoo=:yE2smityWbk/lrtX5zEPLx X7/oJ7IUW7CFC1ZIenrDtFTRixDVz/wIXmhzu9eXVapfiEswMFPj8eZ2f3DSshBVu05AZW2Hq BKru7GE3KvHUEZIkzJSPlNbeFkpyiP1S3WD32xbfsdTqzO9RRNW7jcTZ3dpKziqdr/Ro6525M bhCSWJIjzLmcLfEqRrGRLe+R3rekbBHPD7iOB5HBWKCyRNL0NCqtGySu5CVQ1b6MnO7t7ftWS ApTBbfHVa3fJJLkcqtEVkYE4LTEOFder84h4xzTnS9x8Ws421+LIxwNDtQGMpkaiP10trecKY J+bTLAjdDvpm90xtaMC6BM+PdJW74Svkxod4rItLjyrZqskeUjDlNRzyRVX6NBMEy2B1zIhyF quKhVOd6j3dSWyHoHqrS/HEPC2mdheWGrOTSU/GVtV+MU3/nTdqBAf4eh/IfKs38nuSJLIWLd w/6Kxq4VtvRO1weKtt5awDVP5Ka4YNPLOMq3naSGAtf39dCB2MwFt+N3Ow9lTtmJMgQ+2OoLt lAeLiLpuB+YJLKSr2K6Yjf5cYk8q8sGZDMo7PKrxjow8JEGv9o+PZdiZTbua6mzb/pplVuB78 IteleXsFyYY1VgfWI/47eBtOg8MIMNZXrKjFxt4CG+0MpDnBntSlTWG0TK3GDWT4p9NvGJoOY u+BnLnZzyLC02vbw3/zngYDYqlYIkYgnr8MYmWUBW4FeYCq3Op9SYDNXT3Hhx134D3Lc= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Turning on -Wvla found a new VLA usage: In file included from include/linux/kernel.h:15, from include/asm-generic/bug.h:18, from arch/x86/include/asm/bug.h:83, from include/linux/bug.h:5, from include/linux/mmdebug.h:5, from include/linux/mm.h:9, from arch/x86/mm/pgtable.c:2: arch/x86/mm/pgtable.c: In function 'pgd_alloc': include/linux/build_bug.h:29:45: error: ISO C90 forbids variable length array 'u_pmds' [-Werror=vla] arch/x86/mm/pgtable.c:190:34: note: in expansion of macro 'static_cpu_has' #define PREALLOCATED_USER_PMDS (static_cpu_has(X86_FEATURE_PTI) ? \ ^~~~~~~~~~~~~~ arch/x86/mm/pgtable.c:431:16: note: in expansion of macro 'PREALLOCATED_USER_PMDS' pmd_t *u_pmds[PREALLOCATED_USER_PMDS]; ^~~~~~~~~~~~~~~~~~~~~~ Use the actual size of the array that is used for X86_FEATURE_PTI instead of the variable size. Fixes: f59dbe9ca670 ("x86/pgtable/pae: Use separate kernel PMDs for user page-table") Fixes: 68664695ae57 ("Makefile: Globally enable VLA warning") Signed-off-by: Arnd Bergmann --- arch/x86/mm/pgtable.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) -- 2.18.0 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index 089e78c4effd..386b43e3e0ac 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -189,6 +189,7 @@ static void pgd_dtor(pgd_t *pgd) */ #define PREALLOCATED_USER_PMDS (static_cpu_has(X86_FEATURE_PTI) ? \ KERNEL_PGD_PTRS : 0) +#define MAX_PREALLOCATED_USER_PMDS KERNEL_PGD_PTRS void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd) { @@ -211,6 +212,7 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd) /* No need to prepopulate any pagetable entries in non-PAE modes. */ #define PREALLOCATED_PMDS 0 #define PREALLOCATED_USER_PMDS 0 +#define MAX_PREALLOCATED_USER_PMDS 0 #endif /* CONFIG_X86_PAE */ static void free_pmds(struct mm_struct *mm, pmd_t *pmds[], int count) @@ -428,8 +430,8 @@ static inline void _pgd_free(pgd_t *pgd) pgd_t *pgd_alloc(struct mm_struct *mm) { pgd_t *pgd; - pmd_t *u_pmds[PREALLOCATED_USER_PMDS]; - pmd_t *pmds[PREALLOCATED_PMDS]; + pmd_t *u_pmds[MAX_PREALLOCATED_USER_PMDS]; + pmd_t *pmds[MAX_PREALLOCATED_USER_PMDS]; pgd = _pgd_alloc();