Received: by 10.192.165.156 with SMTP id m28csp1474189imm; Wed, 18 Apr 2018 10:10:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/ZZi9572Q+Bw6UzI/m+UCXd2/NUWmdfx2U8ugR4BWOmilxhD0F85hw37NP5ey0/VKLLB7d X-Received: by 10.101.87.138 with SMTP id b10mr2361518pgr.241.1524071407998; Wed, 18 Apr 2018 10:10:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524071407; cv=none; d=google.com; s=arc-20160816; b=IMANNzqLF9cGMVcYJXYmtYODRJhmGytmhpMv63OHPodyGHjML8yTSUAYEqHzgtcbQx QdfZsmjh2z54WI1oHqxMGd/zVLR1Fo2EC/6RvGKDpEquW+d60re8a4aNblVlncVEoWhm qwYSijSHoUpuL/KCH6Od1gkhwrJL06R9jc3GWRTnBU5tlBSoqN5Koas/LIQdwKTmU/nP OEkvdv8OUl23N65tf50hqEb1+/mzKMUa+b2/dMRquRZUiDlsrURlLnk9aCgIbDMJDGTp 7AzGMg/VLM2zAql6BKT5qZXjzD9CxQNF3V8UKN0JOAXHPDes8PS8SiSkO+eXa9V67XM2 fzSA== 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 :arc-authentication-results; bh=L0CmRt2Q/6x+b3MBwp7RjVdQoYyRYoWFzN6MBGW1nao=; b=zdEWWsAi6h0PxYBRk2vadZa2B4Vpp1xje1H5kUkWyhE7KS1n5VbibzN2wLQ4FnaekM G85eP063XnzU7QkroAmJAzIoUKX4ZRUXxEdCCpJqLvzcRzEz+GqvFyfDUFLpxQXBf6My GoeBQpBb6Ge1AHP8PbrtWI//kgQ4AfdG5P9miDbs1WprFjbt2hj8BOQkgs0KQcqOblB4 gGa4ZChJl06vEb/67ewH5FzmgX9kAD6oc/J4DDgpRuaL9SX7MFliVS1bzLgXR2fifKLv QlyOLhl4TmVGN2W+AfllDfj6hzNMp2G/AXpaT0GrNtP0tBj6mKMzocSealJl3Vmyl/sZ IkJA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q12si1381240pgc.614.2018.04.18.10.09.53; Wed, 18 Apr 2018 10:10:07 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752340AbeDRRIm (ORCPT + 99 others); Wed, 18 Apr 2018 13:08:42 -0400 Received: from mail-ot0-f194.google.com ([74.125.82.194]:33413 "EHLO mail-ot0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751041AbeDRRIk (ORCPT ); Wed, 18 Apr 2018 13:08:40 -0400 Received: by mail-ot0-f194.google.com with SMTP id w2-v6so2751478otj.0 for ; Wed, 18 Apr 2018 10:08:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=L0CmRt2Q/6x+b3MBwp7RjVdQoYyRYoWFzN6MBGW1nao=; b=K6luVvIN/v8CVF0r4kJPFIPIwwHzAhWZc+0AYWNOP9/Uii4ca2WUTo8ypcbj584oz9 SXEEBGlUaOBtjD+eh7djEd2z2f6kRYd35BVCorujYPo9M9IEe1R7kqbV8s3GQfXZX3sy D2NVWgpJLnMseRuf1zSwsDogw6dkPp1WrF67jOwOtDFlhz00JESG2NCUb7hRsMAJn1gO Nje3Os2uoOGwQUHHyfWvbVrT1+PvpDKIo1LrGncMabNwF2HcvL0kfbd9LMWaLSMFhwfB XYiSdECr/+zu7Jsux7vGKUsw0YsydURG4ALNBBuKXwsRUblguG649uGFMS7TY6hF47UC LALQ== X-Gm-Message-State: ALQs6tD5WIrN0/mGbcYHVrnBY522R5GV49fppvGGUPE7h3Dc+zT7eFxL Dx6MGTiQoPCFchsQiGprqg17Eg== X-Received: by 2002:a9d:19a6:: with SMTP id k35-v6mr1873109otk.328.1524071320290; Wed, 18 Apr 2018 10:08:40 -0700 (PDT) Received: from labbott-redhat.redhat.com ([2601:602:9802:a8dc::ce63]) by smtp.gmail.com with ESMTPSA id h39-v6sm877659otb.16.2018.04.18.10.08.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Apr 2018 10:08:39 -0700 (PDT) From: Laura Abbott To: Boris Ostrovsky , Juergen Gross Cc: Laura Abbott , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Subject: [PATCHv2] x86/xen: Remove use of VLAs Date: Wed, 18 Apr 2018 10:08:32 -0700 Message-Id: <20180418170832.8798-1-labbott@redhat.com> X-Mailer: git-send-email 2.14.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There's an ongoing effort to remove VLAs[1] from the kernel to eventually turn on -Wvla. It turns out, the few VLAs in use in Xen produce only a single entry array that is always bounded by GDT_SIZE. Clean up the code to get rid of the VLA and the loop. [1] https://lkml.org/lkml/2018/3/7/621 Signed-off-by: Laura Abbott --- v2: Updated the code to reflect that we know size is always bounded by GDT_SIZE. This gets rid of the array and the loop. I can throw a few more comments in there if someone thinks they need to be updated. --- arch/x86/xen/enlighten_pv.c | 84 ++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 55 deletions(-) diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index c36d23aa6c35..1254f2fa3a89 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -421,45 +421,32 @@ static void xen_load_gdt(const struct desc_ptr *dtr) { unsigned long va = dtr->address; unsigned int size = dtr->size + 1; - unsigned pages = DIV_ROUND_UP(size, PAGE_SIZE); - unsigned long frames[pages]; - int f; - - /* - * A GDT can be up to 64k in size, which corresponds to 8192 - * 8-byte entries, or 16 4k pages.. - */ + unsigned long pfn, mfn; + int level; + pte_t *ptep; + void *virt; - BUG_ON(size > 65536); + BUG_ON(size > GDT_SIZE); BUG_ON(va & ~PAGE_MASK); - for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) { - int level; - pte_t *ptep; - unsigned long pfn, mfn; - void *virt; - - /* - * The GDT is per-cpu and is in the percpu data area. - * That can be virtually mapped, so we need to do a - * page-walk to get the underlying MFN for the - * hypercall. The page can also be in the kernel's - * linear range, so we need to RO that mapping too. - */ - ptep = lookup_address(va, &level); - BUG_ON(ptep == NULL); - - pfn = pte_pfn(*ptep); - mfn = pfn_to_mfn(pfn); - virt = __va(PFN_PHYS(pfn)); + /* + * The GDT is per-cpu and is in the percpu data area. + * That can be virtually mapped, so we need to do a + * page-walk to get the underlying MFN for the + * hypercall. The page can also be in the kernel's + * linear range, so we need to RO that mapping too. + */ + ptep = lookup_address(va, &level); + BUG_ON(ptep == NULL); - frames[f] = mfn; + pfn = pte_pfn(*ptep); + mfn = pfn_to_mfn(pfn); + virt = __va(PFN_PHYS(pfn)); - make_lowmem_page_readonly((void *)va); - make_lowmem_page_readonly(virt); - } + make_lowmem_page_readonly((void *)va); + make_lowmem_page_readonly(virt); - if (HYPERVISOR_set_gdt(frames, size / sizeof(struct desc_struct))) + if (HYPERVISOR_set_gdt(&mfn, size / sizeof(struct desc_struct))) BUG(); } @@ -470,34 +457,21 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr) { unsigned long va = dtr->address; unsigned int size = dtr->size + 1; - unsigned pages = DIV_ROUND_UP(size, PAGE_SIZE); - unsigned long frames[pages]; - int f; - - /* - * A GDT can be up to 64k in size, which corresponds to 8192 - * 8-byte entries, or 16 4k pages.. - */ + unsigned long pfn, mfn; + pte_t pte; - BUG_ON(size > 65536); + BUG_ON(size > GDT_SIZE); BUG_ON(va & ~PAGE_MASK); - for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) { - pte_t pte; - unsigned long pfn, mfn; + pfn = virt_to_pfn(va); + mfn = pfn_to_mfn(pfn); - pfn = virt_to_pfn(va); - mfn = pfn_to_mfn(pfn); + pte = pfn_pte(pfn, PAGE_KERNEL_RO); - pte = pfn_pte(pfn, PAGE_KERNEL_RO); - - if (HYPERVISOR_update_va_mapping((unsigned long)va, pte, 0)) - BUG(); - - frames[f] = mfn; - } + if (HYPERVISOR_update_va_mapping((unsigned long)va, pte, 0)) + BUG(); - if (HYPERVISOR_set_gdt(frames, size / sizeof(struct desc_struct))) + if (HYPERVISOR_set_gdt(&mfn, size / sizeof(struct desc_struct))) BUG(); } -- 2.14.3