Received: by 10.223.176.5 with SMTP id f5csp3364235wra; Mon, 29 Jan 2018 12:12:14 -0800 (PST) X-Google-Smtp-Source: AH8x227Al7ZiSOjaw/Ac76cZi1+yLA/cT+mnR5lA3Gy5CCDAIZPmp8mHwh1YBdhcumm0kbzi7QH6 X-Received: by 2002:a17:902:8a89:: with SMTP id p9-v6mr22479478plo.397.1517256734233; Mon, 29 Jan 2018 12:12:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517256734; cv=none; d=google.com; s=arc-20160816; b=lmCAzX/8BORTVYYw+fhA+rIgaN77wUUscNw8jgHNAcNDZtj/N0/B2miIGgLcZ4i16h f8ZWBaiEqES4E3/jpjeflhR+3PkFQHNWNlpjXp/4lSaVwWcggEGB4/JZSH0eMdKk01ed 97eS/L1Ts0fcX6eo/vIK2X1TAB8I3R2k+DyexnWZw1eYxNXBUZZIUXlgntDu2sXGRCAX U+SXVY6zvi8vhB4zsxsGimNhRc9Ir9UHU//xer3Io38R+LskvzgwDhnsB3XxiQCR8SRS hQXzM8z9RV676IHIx9G3ZSRcZg31xeGNwzxqz0za3Hg5FaXnrq8BoSiTomgy/WCVYwfQ dQxQ== 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=St7vMDGpgRhGynI8AwLLN6Hub39LikG/CaWiukUku/c=; b=WVOYN0VykDLbhC7jzKGKf0Q6+IsumdcTebCSH+Ap6SSuSxP+qPWCBFD7MnzmNaFg5i rc6ydO4SEhA9plwgUo7Rz8fE2e0EOO3Yko7XyR3dACJa9bsc4s18aivU05EzCtCZMgP5 qMWWZNIr3y4qtrFhqMIS6HC8GtUOyo6BtIQOBUvhk7bpnl8NF0YEwqU5/VSXfIj66lz4 m9sxQfOEnzVVN9/vk2nbqjONkafZx1hrd01BXp6D4HQjU3bdYrjkvOxV32cd1WavwuX6 NaMmFKfMMPBXFiGxHm0q0LGGlHe8G8OuqoQYey1jECLQE7y1Fql9eNVmZzipsvByi4I3 5V2g== 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 o11si7954024pgn.796.2018.01.29.12.11.59; Mon, 29 Jan 2018 12:12:14 -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 S1753727AbeA2ULf (ORCPT + 99 others); Mon, 29 Jan 2018 15:11:35 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:60480 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753704AbeA2ULd (ORCPT ); Mon, 29 Jan 2018 15:11:33 -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 0050C2F63; Mon, 29 Jan 2018 13:04:37 +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.9 15/66] cma: fix calculation of aligned offset Date: Mon, 29 Jan 2018 13:56:39 +0100 Message-Id: <20180129123840.638706274@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123839.842860149@linuxfoundation.org> References: <20180129123839.842860149@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.9-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,