Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5757264ioo; Wed, 1 Jun 2022 11:57:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDAJAF9Asce/ufSG7g/wtFWlcCjpCp8s6tDYpGvplzVj7AX3kW/wSlvvMdWLy2CYs+oJbM X-Received: by 2002:a05:6a00:1501:b0:510:7ab8:71c8 with SMTP id q1-20020a056a00150100b005107ab871c8mr67938584pfu.63.1654109820930; Wed, 01 Jun 2022 11:57:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654109820; cv=none; d=google.com; s=arc-20160816; b=IgHMKe1IhT28AMy8As0ebCZVek55UniEUs26r8TcgGTkjAQwaIR9fSAja+mt9PozRp k+U4mqArWIMSBxZ47cReHHhwtm9Qbx/q9W1MznpqEMupBfUQfzfc0UgxcCCHBCroeTMy ncRJSOOSwvVRAMbCpibIruYZl1QUnclS4UBcxMYB/wnHM1T0q5XoLuKVF+HcRDAybOA5 ZrZte53og15qRcL72GLN+Os3m4VMMI5uvzrsHM7oPT/Jcdf4ZWnB9+JR2MazX0qyF9Ph PmfOgKb7uzCpH0Xm8OqWMGuhpzgV8kXwC/04WZEAL4+VP3kd9cKL5L5FGzqzyiOF3dNY IcjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=RasPjcgW3MbjOYmk499B8lRQ6/y64Pgdc8ibAu0hQ94=; b=tGr28qLf9bGYKAFe/e67/64w4RDouu+T/VZeUkmcrzgnnHgrMg6ypr4hY/VyYUBZjP xNovjfmfXFLYfVGoEYEgKss/sMnrQULIcnep/qi3ySJYY+0Hes72RUbyYMSYK9gwMOaQ HfgAJrzuVySC4FoPx/pCijOVn+EgivEOC4zTHXizEaXJnbcxFrOgS2WsKY2d+2Zm15Md FxyT7Y0WXv6xaSz/AYnqGlAOjIF3L7K4fljSzE/4li40/fhb3OZFRxUyFynOBK5YAVO4 iYO8o81tcWQf4pdf2C/gCUV9/l2DfBj04/N0iUn0Ft4YKZBeF7B1SAMdIJpUoEc/BWst 1Q2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cybernetics.com header.s=mail header.b=Bt5vfluu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cybernetics.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q24-20020a635058000000b003fafafbb097si2759458pgl.615.2022.06.01.11.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 11:57:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@cybernetics.com header.s=mail header.b=Bt5vfluu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cybernetics.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E9D6E90CE1; Wed, 1 Jun 2022 11:44:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232777AbiEaSOc (ORCPT + 99 others); Tue, 31 May 2022 14:14:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346879AbiEaSO0 (ORCPT ); Tue, 31 May 2022 14:14:26 -0400 Received: from mail.cybernetics.com (mail.cybernetics.com [173.71.130.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B71FF8CCCE for ; Tue, 31 May 2022 11:14:25 -0700 (PDT) X-ASG-Debug-ID: 1654020863-1cf43917f334b000001-xx1T2L Received: from cybernetics.com ([10.10.4.126]) by mail.cybernetics.com with ESMTP id oOy2yfF6AsqWuHgq; Tue, 31 May 2022 14:14:23 -0400 (EDT) X-Barracuda-Envelope-From: tonyb@cybernetics.com X-ASG-Whitelist: Client DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cybernetics.com; s=mail; bh=RasPjcgW3MbjOYmk499B8lRQ6/y64Pgdc8ibAu0hQ94=; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:References:Cc:To:From: Content-Language:Subject:MIME-Version:Date:Message-ID; b=Bt5vfluu/fRwhcrHUI+Q RP31wdoXrw1Y6q/RDhu8jjMvd8Xv/prWojQ2sBb93UI9yWCDk8+z3hJRHrqRB9Kyl/P33NDljwTGT 6LP6dpwARPHNZ8W9RmxQn7ynBzURXdzx83Lam9kFm87wr8w+LJVJi4f0pmJ+NCuSFMASSmTsmw= Received: from [10.157.2.224] (HELO [192.168.200.1]) by cybernetics.com (CommuniGate Pro SMTP 7.1.1) with ESMTPS id 11829197; Tue, 31 May 2022 14:14:23 -0400 Message-ID: Date: Tue, 31 May 2022 14:14:23 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: [PATCH 03/10] dmapool: fix boundary comparison Content-Language: en-US X-ASG-Orig-Subj: [PATCH 03/10] dmapool: fix boundary comparison From: Tony Battersby To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: iommu@lists.linux-foundation.org, kernel-team@fb.com, Matthew Wilcox , Keith Busch , Andy Shevchenko , Robin Murphy , Tony Lindgren References: <9b08ab7c-b80b-527d-9adf-7716b0868fbc@cybernetics.com> In-Reply-To: <9b08ab7c-b80b-527d-9adf-7716b0868fbc@cybernetics.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Barracuda-Connect: UNKNOWN[10.10.4.126] X-Barracuda-Start-Time: 1654020863 X-Barracuda-URL: https://10.10.4.122:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at cybernetics.com X-Barracuda-Scan-Msg-Size: 1388 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fix the boundary comparison when constructing the list of free blocks for the case that 'size' is a power of two. Since 'boundary' is also a power of two, that would make 'boundary' a multiple of 'size', in which case a single block would never cross the boundary. This bug would cause some of the allocated memory to be wasted (but not leaked). Example: size = 512 boundary = 2048 allocation = 4096 Address range 0 - 511 512 - 1023 1024 - 1535 1536 - 2047 * 2048 - 2559 2560 - 3071 3072 - 3583 3584 - 4095 * Prior to this fix, the address ranges marked with "*" would not have been used even though they didn't cross the given boundary. Fixes: e34f44b3517f ("pool: Improve memory usage for devices which can't cross boundaries") Signed-off-by: Tony Battersby --- mm/dmapool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/dmapool.c b/mm/dmapool.c index d7b372248111..782143144a32 100644 --- a/mm/dmapool.c +++ b/mm/dmapool.c @@ -210,7 +210,7 @@ static void pool_initialise_page(struct dma_pool *pool, struct dma_page *page) do { unsigned int next = offset + pool->size; - if (unlikely((next + pool->size) >= next_boundary)) { + if (unlikely((next + pool->size) > next_boundary)) { next = next_boundary; next_boundary += pool->boundary; } -- 2.25.1