Received: by 10.223.176.5 with SMTP id f5csp3366413wra; Mon, 29 Jan 2018 12:13:29 -0800 (PST) X-Google-Smtp-Source: AH8x22573Wqv/JMHs36jBHj+RjYNLy+KUfGH+m2FwSxIa2T8Nau57Ke78QlTWpGEIuBCl4Uko8ET X-Received: by 10.98.34.206 with SMTP id p75mr28065762pfj.235.1517256809039; Mon, 29 Jan 2018 12:13:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517256809; cv=none; d=google.com; s=arc-20160816; b=KE6vuZ43YMtreiSCp0tAIWqCQJenuc7O0f125MiCYL/upHkhgSHTKWNO3pomzWuMe5 P9MTPX8YZ3IdiHrtXSO9wxfXfJoq72xwTJOeSgIHsi7SN+EkomdulZo1UzevLdD0gtw4 ySOxko7BwOB2oMQaiXKmUZTLRWiVxX/br1oToi+0VqZ54NDhnWvHrBeApuSElUatbfQ7 UEnjjuXRy9yiKzXLihCkSKnSnBeqyY9aiDWMlwc/tCRuHS1yLklcg5+tLbGvQLAG7P9c Iim/3joegDcMjgPsSokDHny/tVYjldLx6foyCVGO1SadepXm58zWHDBaL+TL7Ljmdj7w bJjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=mTuKlZ/l4LtJn8i87GtZene2zo6fXbRF2qjX8iJoyFM=; b=lr/BTKvLH+c9UNaLRulcNerPtQbT1CAo15kvI0IjWHKtavaw3oPqqBLhTEJkUkICOi igz8ckXqyvKV6SUKS5Vhl/MLm4aUKlTaxCO972kXfRtSjgaZoa087wHhZucsIMxpVrrJ YLGxHMqJ6qOAmRXqXo1qOsRNQxCS1+BJhGRElOG/2EU4OkV6OjGM2v8AIwvoIO8GxSCl tX64Y9qclQrtBVBqaiKhL2NgR4bGADUPwge+t3MLFeLWZgsZLPsV1SHvkGRp/Bp8ghuu sNDfrAfRqZjtQa0cINyk3x9vExwUSlx7KrPTQCDj6/7oNyzXxxuO47Bihp8+8ljAMb1R b3IQ== 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 g12-v6si224772pln.6.2018.01.29.12.13.14; Mon, 29 Jan 2018 12:13:29 -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; 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 S1753982AbeA2UMo (ORCPT + 99 others); Mon, 29 Jan 2018 15:12:44 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:35644 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753297AbeA2UMl (ORCPT ); Mon, 29 Jan 2018 15:12:41 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 174FE2EF2; Mon, 29 Jan 2018 13:01:21 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Angus Clark , Doug Berger , Gregory Fong , Laura Abbott , Vlastimil Babka , Lucas Stach , Catalin Marinas , Shiraz Hashim , Jaewon Kim , Andrew Morton , Linus Torvalds Subject: [PATCH 4.4 23/74] cma: fix calculation of aligned offset Date: Mon, 29 Jan 2018 13:56:28 +0100 Message-Id: <20180129123848.672828074@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123847.507563674@linuxfoundation.org> References: <20180129123847.507563674@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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. ------------------ From: Doug Berger commit e048cb32f69038aa1c8f11e5c1b331be4181659d upstream. The align_offset parameter is used by bitmap_find_next_zero_area_off() to represent the offset of map's base from the previous alignment boundary; the function ensures that the returned index, plus the align_offset, honors the specified align_mask. The logic introduced by commit b5be83e308f7 ("mm: cma: align to physical address, not CMA region position") has the cma driver calculate the offset to the *next* alignment boundary. In most cases, the base alignment is greater than that specified when making allocations, resulting in a zero offset whether we align up or down. In the example given with the commit, the base alignment (8MB) was half the requested alignment (16MB) so the math also happened to work since the offset is 8MB in both directions. However, when requesting allocations with an alignment greater than twice that of the base, the returned index would not be correctly aligned. Also, the align_order arguments of cma_bitmap_aligned_mask() and cma_bitmap_aligned_offset() should not be negative so the argument type was made unsigned. Fixes: b5be83e308f7 ("mm: cma: align to physical address, not CMA region position") Link: http://lkml.kernel.org/r/20170628170742.2895-1-opendmb@gmail.com Signed-off-by: Angus Clark Signed-off-by: Doug Berger Acked-by: Gregory Fong Cc: Doug Berger Cc: Angus Clark Cc: Laura Abbott Cc: Vlastimil Babka Cc: Greg Kroah-Hartman Cc: Lucas Stach Cc: Catalin Marinas Cc: Shiraz Hashim Cc: Jaewon Kim Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Vlastimil Babka Signed-off-by: Greg Kroah-Hartman --- mm/cma.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) --- a/mm/cma.c +++ b/mm/cma.c @@ -54,7 +54,7 @@ unsigned long cma_get_size(const struct } static unsigned long cma_bitmap_aligned_mask(const struct cma *cma, - int align_order) + unsigned int align_order) { if (align_order <= cma->order_per_bit) return 0; @@ -62,17 +62,14 @@ static unsigned long cma_bitmap_aligned_ } /* - * Find a PFN aligned to the specified order and return an offset represented in - * order_per_bits. + * Find the offset of the base PFN from the specified align_order. + * The value returned is represented in order_per_bits. */ static unsigned long cma_bitmap_aligned_offset(const struct cma *cma, - int align_order) + unsigned int align_order) { - if (align_order <= cma->order_per_bit) - return 0; - - return (ALIGN(cma->base_pfn, (1UL << align_order)) - - cma->base_pfn) >> cma->order_per_bit; + return (cma->base_pfn & ((1UL << align_order) - 1)) + >> cma->order_per_bit; } static unsigned long cma_bitmap_pages_to_bits(const struct cma *cma,