Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp17070imu; Thu, 8 Nov 2018 14:00:23 -0800 (PST) X-Google-Smtp-Source: AJdET5cvS01fzYeOkn1UDCZAvY/KpbUtWx/A42+bA+wGGR8ocELtaoPvLa/7X0YWIoXPWq0B96rX X-Received: by 2002:a62:8a0d:: with SMTP id y13-v6mr6316625pfd.142.1541714423847; Thu, 08 Nov 2018 14:00:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541714423; cv=none; d=google.com; s=arc-20160816; b=tRcIszMuw0a83sAaa6GN7SEuIbEuEQTRtgc3jk5RHqHS881X9FUkpxyZT2etk6LIc0 nn9P2pwBO3bJGWcCpHzWTa5rj/BVb+M11byLnL0tw5ndB24nU8NlR9MJ0Q8YPcYNdtFC 4VJjGDDR8dYc2sOyVt+MRTQjXrc2qQ8A6HgnJhygn/vnT4+pquEqZOtyP5sUE/UicgKP G70MkjFodOcdUAjU6PP6iECamRgLQn/9dXzHTQ6xruKluiO4yo1rqd5gW0ZKpFESieBL uByG68nf+JRZs7xipVNcQ1VkYUn5dpIBsEK3hsV7jgdGNnC2WrNLNH7fdpNdIgL2ZrUG a4zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4KWa5mShE2RYmt8bjRwpWtqLyHgP2/w3M6f4X4tWrws=; b=FBeLUQM+VdWbsKquNfCAJP1SqeoWWlZpkjOrVdOGCu811i6h6J3CHSMjeifiZZiqEu J/ddFo8WSMy1kY2Cz585OwzmWgjZ/CMFVZ2Hkn/UGA9asXsXBgjsQAdJ3wiLx9T6aXwP kzPIlmPc1iT8X7f/D0OnNMl1XeEZ3ljPjkxi80quSBbdcljMS7BsW2XmxIbL8c/Gi2ca Jn3iLEjVnWHCzaomwgDf8uRG3EFh9AuphcHE1iDXFBEAb2tAi7zl8SYMcwysYctIwuNs ynwObsUT9xxDAAPSNL6+TKBQh9QYg346ZnhgWuKMs/PQHL2WTgT0twMyz/ZgNTYssakv cujg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Kjs69boJ; 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 l68-v6si5991463pfl.56.2018.11.08.14.00.08; Thu, 08 Nov 2018 14:00:23 -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; dkim=pass header.i=@kernel.org header.s=default header.b=Kjs69boJ; 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 S1729899AbeKIHgb (ORCPT + 99 others); Fri, 9 Nov 2018 02:36:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:54046 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729261AbeKIHgb (ORCPT ); Fri, 9 Nov 2018 02:36:31 -0500 Received: from localhost (unknown [208.72.13.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5C4C820818; Thu, 8 Nov 2018 21:59:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714342; bh=UIf7AzYqLiq8H0MOc8czjaVvqWU/7o+lM8RoXQt9TBs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kjs69boJPvAJY/79s3OMMYYJwVKMbb2sXYJXFSrKLfZTbGKs9sWylP5HUkOrURdvT Jbhb95vJc4ngt/Hy8o39upiuFuEhAmR/fc20Sby62nvQe3G0l7IyFoSKU8jJ+WCUzY njNmzgref6Y/z3OENIUW4i/r+k7Hb6GK/0snKzxk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Waiman Long , Ard Biesheuvel , Borislav Petkov , Linus Torvalds , Theodore Tso , Arnd Bergmann , Scott J Norton , Douglas Hatch , Matt Fleming , Sasha Levin Subject: [PATCH 4.4 025/114] x86/mm/pat: Prevent hang during boot when mapping pages Date: Thu, 8 Nov 2018 13:50:40 -0800 Message-Id: <20181108215101.398014379@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215059.051093652@linuxfoundation.org> References: <20181108215059.051093652@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit e535ec0899d1fe52ec3a84c9bc03457ac67ad6f7 ] There's a mixture of signed 32-bit and unsigned 32-bit and 64-bit data types used for keeping track of how many pages have been mapped. This leads to hangs during boot when mapping large numbers of pages (multiple terabytes, as reported by Waiman) because those values are interpreted as being negative. commit 742563777e8d ("x86/mm/pat: Avoid truncation when converting cpa->numpages to address") fixed one of those bugs, but there is another lurking in __change_page_attr_set_clr(). Additionally, the return value type for the populate_*() functions can return negative values when a large number of pages have been mapped, triggering the error paths even though no error occurred. Consistently use 64-bit types on 64-bit platforms when counting pages. Even in the signed case this gives us room for regions 8PiB (pebibytes) in size whilst still allowing the usual negative value error checking idiom. Reported-by: Waiman Long Cc: Ard Biesheuvel Cc: Borislav Petkov Cc: Linus Torvalds CC: Theodore Ts'o Cc: Arnd Bergmann Cc: Greg Kroah-Hartman Cc: Scott J Norton Cc: Douglas Hatch Signed-off-by: Matt Fleming Signed-off-by: Sasha Levin --- arch/x86/mm/pageattr.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c index 0e1dd7d47f05..26598e08666c 100644 --- a/arch/x86/mm/pageattr.c +++ b/arch/x86/mm/pageattr.c @@ -955,11 +955,11 @@ static void populate_pte(struct cpa_data *cpa, } } -static int populate_pmd(struct cpa_data *cpa, - unsigned long start, unsigned long end, - unsigned num_pages, pud_t *pud, pgprot_t pgprot) +static long populate_pmd(struct cpa_data *cpa, + unsigned long start, unsigned long end, + unsigned num_pages, pud_t *pud, pgprot_t pgprot) { - unsigned int cur_pages = 0; + long cur_pages = 0; pmd_t *pmd; pgprot_t pmd_pgprot; @@ -1029,12 +1029,12 @@ static int populate_pmd(struct cpa_data *cpa, return num_pages; } -static int populate_pud(struct cpa_data *cpa, unsigned long start, pgd_t *pgd, - pgprot_t pgprot) +static long populate_pud(struct cpa_data *cpa, unsigned long start, pgd_t *pgd, + pgprot_t pgprot) { pud_t *pud; unsigned long end; - int cur_pages = 0; + long cur_pages = 0; pgprot_t pud_pgprot; end = start + (cpa->numpages << PAGE_SHIFT); @@ -1090,7 +1090,7 @@ static int populate_pud(struct cpa_data *cpa, unsigned long start, pgd_t *pgd, /* Map trailing leftover */ if (start < end) { - int tmp; + long tmp; pud = pud_offset(pgd, start); if (pud_none(*pud)) @@ -1116,7 +1116,7 @@ static int populate_pgd(struct cpa_data *cpa, unsigned long addr) pgprot_t pgprot = __pgprot(_KERNPG_TABLE); pud_t *pud = NULL; /* shut up gcc */ pgd_t *pgd_entry; - int ret; + long ret; pgd_entry = cpa->pgd + pgd_index(addr); @@ -1351,7 +1351,8 @@ static int cpa_process_alias(struct cpa_data *cpa) static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias) { - int ret, numpages = cpa->numpages; + unsigned long numpages = cpa->numpages; + int ret; while (numpages) { /* -- 2.17.1