From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x226va1AMG25CIiFkAT9CM7wuYb/fcrjDeI4oSwZ47ke1W9+VLlCS1yGn/4pbz56qPgrLnwh1 ARC-Seal: i=1; a=rsa-sha256; t=1517256762; cv=none; d=google.com; s=arc-20160816; b=VbhC5EgVjo+S4gDVOWlAzmZc0BURDuVhhOPQu7kzrS4/TpBNpuZ1R9Jkd6HXm+Daa1 vwO4urRGE9VMoDEVyEjF53A8TUgifbNznrS96cnkag4Q9MBi3rFim8L3dYeVfyZ8eGt8 +z3uU9YFy+KPbOjOwXN6xCjfKt0bKBvFE0B4fggUxjQPrayAnohOncMpK0rfHA1hnvPE V4y28SKOJZNGuw54eEJE8RCT2yv9QiXsLVD9SnuKo33Sne/OEEV9ta7g6Tt2OXKCDlx2 gHBnSeVFRfhf1o02WaHvazysyEnc16jNvVrYp33hy0iAUasbBMb3AFHPTRuaEmaHfCgz Rpew== 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=mTuKlZ/l4LtJn8i87GtZene2zo6fXbRF2qjX8iJoyFM=; b=v/MjXze6OSaB3tv+ocuwRfWeJUu3Kzn2+Vd62VZX3xlFhOXbTsz6FJ9IZJH2iFFF/G LTHRpbkEyoh55jr3M3l2U3EcfE2mqBzB+QGq/w03ruI0FBkbFX9kWMivwyhmafWffU2+ ujX4B4JLwGCKMHSmsgA0tTk+37Gw6Tb7eEelMcPuPSKYNxnhEZypHufcTIDb3w+off3r AXJatuE5P4orCYAilxfLnKgQIveyC97UcwEU2JL5xYtzS3hGeipnMAhVS0yntZlQMFbS zV5KEu/y9238V2n6MQ1+wfP93jqR9b/zFcK+UThOHWC6Yo6X0QHZMk2+VvLcM5X2LDGj CRhw== 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.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 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?1590959026692694462?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 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,