From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x2268Nkh9vDGwsSpSZ1W6BkTG+bf3wrr64zQrI7/pGnDftkT2QW2csYXCKD5gOJtoLf1rzS3R ARC-Seal: i=1; a=rsa-sha256; t=1517256694; cv=none; d=google.com; s=arc-20160816; b=qaFFPk/f1Q8Jrx5gjnhXTTwrUdHe3u399rtnqI9HnfDGE/zgJ6vS1qEb4a2B5hYrc9 WTJhSecii9hQbeXcTe/CabrEsA8Nv76RmkWXrqjNcXL3JvWcYIG5nFAwheFTWovYqITV xaJaSkRsTcv9B6gG8xS+9qkhZmXLSvyBMEfMD514OzibQlg/U2b1j5Z1X9eClXcTxrl0 Stvi4MQChlU3ZPGxZ79aiUWeDZUn7EYKPpa3jHNjk91lZ2j6JWLY2BRbN+nsZKc6b4BG WqgrzxDEmigY8y7i5/W53YxpHnH3EGFGTsknRC+Am5x64/pz0Qxw8zy6aGlMcDG7JnaK YiUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=St7vMDGpgRhGynI8AwLLN6Hub39LikG/CaWiukUku/c=; b=dOnDS+Mw3NcEykr4M7lbkN7gCIazuhOMI96xUlCJFjxaCjV03TtdUbbryVGsGpn9/W aj6Dj6KmoAsc3sEiTaUu/lt23mgPzzHA86l8LoyN0yiVc0+m119M1T6dRUoMvia9AjZR E9MaGqMCbj00xnZQoszMC/GLqItMS/xh5OZ7CuRs5lp0HkkqB4ZeS1zIzJFxJD3HoBig KUd907q9+TdokQ8N40fiZQ88khi589lZ09M0UZ4fMBk02YHx40BNP3nbiEZp1h6SPFbA M28fnppYWZYQd/RrKdKE8QuEHSOEx4BRslhCgn8H2oiGaCPQWSP/jqjo8BXiV7C6UgZd NhaA== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-LABELS: =?utf-8?b?IlxcU2VudCI=?= X-GMAIL-THRID: =?utf-8?q?1590958954948429724?= X-GMAIL-MSGID: =?utf-8?q?1590958954948429724?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 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,