Received: by 10.213.65.68 with SMTP id h4csp471807imn; Tue, 13 Mar 2018 10:06:15 -0700 (PDT) X-Google-Smtp-Source: AG47ELvMS4AueP/iG14NlEUWRYMbyh2dRkozHel/0W1MWTADt5JrPSYxg7/X81pS9oEy/sJCdzkk X-Received: by 10.99.61.204 with SMTP id k195mr1072547pga.312.1520960775653; Tue, 13 Mar 2018 10:06:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520960775; cv=none; d=google.com; s=arc-20160816; b=ukFoHP40Vr1XMbHO0yy8fSNaxrt7+eGLMfNi26o22q1j4zhefkv+yB3pn1ysMLkY8q t3oSMp49U5FKkpOBK8/KVO/zsz8YJ6+ZVHtuRxgregWYGN9dZfUKZGDGPmbzBVYWQm6O gFal3Jpysew7+T2kwUENh3YQBuyGKyCdMr1s5TZEP14XL+EG8QTPJtU8zt5ib/vw4wMp avIiuCeipUchbEK+eR0/FrENCPe6lLjBhQSve4fRZ4kk/il6M6HbO8pFJWXFzM5/qI2y lgYdbSaJ6sjhS1Wy4RGbCvQyPduCDJFykjLABgSaisk9Tx2y51LGfL0pOKOFxdeI0xwn IQIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=uaaO+Itp56jp/NYLxSVLmhpJTJi4gIdHcWcpV2FA2yA=; b=YXEvwpkXUoR5tZVDwjoHINypSb7EvpUK3uo88Vh9Cv51se3VDFW7xE57sgBoND2h/9 6bPkq/dZx0FR10paiFYNWzzgCfhXuaSkHhbR2tGPOW33OEQHudJb+cvrghK4kLSk86r1 WiIEyqdJ/ryNnen41TJl3v6rxuriQL+F9tApROCXGOp9cHftDA2r0gpl4dYl3aF+agdH vlveNPOLChlCcsgXk3z7/OLAmAQYspAeVQp+6lpktEZOO/xUpW6wlHQ4Yj1TpWyGUOAR NIQ/ak/XhyEa3B/yH0NxbKRRLP3PrVDf+zJ1Dp0/y03x6+ACmQGR4Am/hbbqKsE+K557 BaAA== 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 i61-v6si385929plb.560.2018.03.13.10.06.00; Tue, 13 Mar 2018 10:06:15 -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 S933095AbeCMRD4 (ORCPT + 99 others); Tue, 13 Mar 2018 13:03:56 -0400 Received: from g9t5009.houston.hpe.com ([15.241.48.73]:54202 "EHLO g9t5009.houston.hpe.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933054AbeCMRDy (ORCPT ); Tue, 13 Mar 2018 13:03:54 -0400 Received: from g4t3433.houston.hpecorp.net (g4t3433.houston.hpecorp.net [16.208.49.245]) by g9t5009.houston.hpe.com (Postfix) with ESMTP id 6D48D63; Tue, 13 Mar 2018 17:03:53 +0000 (UTC) Received: from misato.americas.hpqcorp.net (misato.americas.hpqcorp.net [10.34.81.122]) by g4t3433.houston.hpecorp.net (Postfix) with ESMTP id DBD18376; Tue, 13 Mar 2018 17:03:52 +0000 (UTC) From: Toshi Kani To: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com Cc: bp@alien8.de, luto@kernel.org, gratian.crisan@ni.com, x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Toshi Kani Subject: [PATCH 2/2] x86/mm: remove pointless checks in vmalloc_fault Date: Tue, 13 Mar 2018 11:03:47 -0600 Message-Id: <20180313170347.3829-3-toshi.kani@hpe.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180313170347.3829-1-toshi.kani@hpe.com> References: <20180313170347.3829-1-toshi.kani@hpe.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org vmalloc_fault() sets user's pgd or p4d from the kernel page table. Once it's set, all tables underneath are identical. There is no point of following the same page table with two separate pointers and makes sure they see the same with BUG(). Remove the pointless checks in vmalloc_fault(). Also rename the kernel pgd/p4d pointers to pgd_k/p4d_k so that their names are consistent in the file. Suggested-by: Andy Lutomirski Signed-off-by: Toshi Kani Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Borislav Petkov Cc: Andy Lutomirski Cc: Gratian Crisan --- arch/x86/mm/fault.c | 56 +++++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 39 deletions(-) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 25a30b5d6582..e7bc79853538 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -417,11 +417,11 @@ void vmalloc_sync_all(void) */ static noinline int vmalloc_fault(unsigned long address) { - pgd_t *pgd, *pgd_ref; - p4d_t *p4d, *p4d_ref; - pud_t *pud, *pud_ref; - pmd_t *pmd, *pmd_ref; - pte_t *pte, *pte_ref; + pgd_t *pgd, *pgd_k; + p4d_t *p4d, *p4d_k; + pud_t *pud; + pmd_t *pmd; + pte_t *pte; /* Make sure we are in vmalloc area: */ if (!(address >= VMALLOC_START && address < VMALLOC_END)) @@ -435,73 +435,51 @@ static noinline int vmalloc_fault(unsigned long address) * case just flush: */ pgd = (pgd_t *)__va(read_cr3_pa()) + pgd_index(address); - pgd_ref = pgd_offset_k(address); - if (pgd_none(*pgd_ref)) + pgd_k = pgd_offset_k(address); + if (pgd_none(*pgd_k)) return -1; if (CONFIG_PGTABLE_LEVELS > 4) { if (pgd_none(*pgd)) { - set_pgd(pgd, *pgd_ref); + set_pgd(pgd, *pgd_k); arch_flush_lazy_mmu_mode(); } else { - BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref)); + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_k)); } } /* With 4-level paging, copying happens on the p4d level. */ p4d = p4d_offset(pgd, address); - p4d_ref = p4d_offset(pgd_ref, address); - if (p4d_none(*p4d_ref)) + p4d_k = p4d_offset(pgd_k, address); + if (p4d_none(*p4d_k)) return -1; if (p4d_none(*p4d) && CONFIG_PGTABLE_LEVELS == 4) { - set_p4d(p4d, *p4d_ref); + set_p4d(p4d, *p4d_k); arch_flush_lazy_mmu_mode(); } else { - BUG_ON(p4d_pfn(*p4d) != p4d_pfn(*p4d_ref)); + BUG_ON(p4d_pfn(*p4d) != p4d_pfn(*p4d_k)); } - /* - * Below here mismatches are bugs because these lower tables - * are shared: - */ BUILD_BUG_ON(CONFIG_PGTABLE_LEVELS < 4); pud = pud_offset(p4d, address); - pud_ref = pud_offset(p4d_ref, address); - if (pud_none(*pud_ref)) + if (pud_none(*pud)) return -1; - if (pud_none(*pud) || pud_pfn(*pud) != pud_pfn(*pud_ref)) - BUG(); - if (pud_large(*pud)) return 0; pmd = pmd_offset(pud, address); - pmd_ref = pmd_offset(pud_ref, address); - if (pmd_none(*pmd_ref)) + if (pmd_none(*pmd)) return -1; - if (pmd_none(*pmd) || pmd_pfn(*pmd) != pmd_pfn(*pmd_ref)) - BUG(); - if (pmd_large(*pmd)) return 0; - pte_ref = pte_offset_kernel(pmd_ref, address); - if (!pte_present(*pte_ref)) - return -1; - pte = pte_offset_kernel(pmd, address); - - /* - * Don't use pte_page here, because the mappings can point - * outside mem_map, and the NUMA hash lookup cannot handle - * that: - */ - if (!pte_present(*pte) || pte_pfn(*pte) != pte_pfn(*pte_ref)) - BUG(); + if (!pte_present(*pte)) + return -1; return 0; }