Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp126109img; Wed, 27 Feb 2019 18:19:35 -0800 (PST) X-Google-Smtp-Source: AHgI3IYsDSWTra9Et3IyLPQPMRdWgv9IF3iZrxJDAjBM4MUJKYB907pfxrdLzyx4Vg7dJBYFdht1 X-Received: by 2002:a65:5c41:: with SMTP id v1mr5954600pgr.404.1551320375849; Wed, 27 Feb 2019 18:19:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551320375; cv=none; d=google.com; s=arc-20160816; b=b8qTaVuOl1haCCd18LBbv6ATSoqXzg/YXCjPqsbzqHli5+33ZQFyemrMqBFvTOKD1A 71Dvxix5by7e71do6uk35GGHD/gHL4buuhuzCk1fAtyQnD5g6WosAEbSott7PcR4CskZ SHafJyNizxYIrRuJOPInvKMgnm9Upi5h4Y5UPEuhGeQH9M3Oc/Am4l9QTz3W2QZxHay2 tXnfe1wFlnpTzF+9rdbhVkGcpjrXBoT/rDeVbHRy0Wm7cXtG2vafL5FWxn/Rs1Wt29Yc 8jHBh8vbgkBAu7grPsMmA9V0p42ER0ADRYzD7SIu2m1uWaw0EGC2DkAQNxQ/1SafwCzk Va2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=Vx2VZtOceXx/muNOFvOTUbvq8L4C1gUYQ/k1Qg6oF3M=; b=R+dXsNjjdS/xVyiQI6zIgnrN5BazU8iubK7zwxyL1Zo2ZsvSwMAn3EtmId10CkKFfI yEJu7yrVH4TNmqvEPxlaVBtyvF8slM6hkBdOAjiv7HrlgKUuJjQA+PsjNUg3P2MCRzJo CLe6Q8gxtkUkMhRdK5L3mID878Jp0WiUykYDfbCkT4pr8N38dEQzrqz7pqsDZxwuTcoV v2wPylTAWLR6FVoOoWl9w1yq8jOHGIuyx4C4C28Z51wvcQXAGwmBuKdpBZ4dtgXqgvYc GZlS/gUVawwqssAqhjAgvVB+DBfxDgy806Ka3KgLV6L+aRl9Cldw/WFb/t7pG1Am73U8 B1Bg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z3si17378432pgr.90.2019.02.27.18.19.20; Wed, 27 Feb 2019 18:19:35 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730730AbfB1CSx (ORCPT + 99 others); Wed, 27 Feb 2019 21:18:53 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:33400 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730650AbfB1CSr (ORCPT ); Wed, 27 Feb 2019 21:18:47 -0500 Received: by mail-qt1-f196.google.com with SMTP id z39so21859477qtz.0 for ; Wed, 27 Feb 2019 18:18:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Vx2VZtOceXx/muNOFvOTUbvq8L4C1gUYQ/k1Qg6oF3M=; b=OA5NtGaAi7smxl+1bCpRBD/mHts2jQtSFn86yvnDeeVfTAgwbbwf0MZSgWh1e9AY5L rxRllJ2cbPvqSOkTii1Kjju/O8IU26h8Dsn6NaIyLCC7ZE8z+rjAG0+lEQbRZE/ZzwgU fKrAGWCndHkHovgDmthAGlHKpqdDp6WZnYGThKnoXFP/+Va+bxNc47UdSu971HTyEU6E nKEVXo0kh1dNVF1/scSM44EC7sO9cgyJVN/jFYCZehn7ej3ZHrAvxsZFyTuiSKIZWxXJ UM6kkKEj8x6cA4yt9C2ifStNI97qxX71Xe/DhwsO8OBfiQnuU1sPDx6N4Gz6fZ4SbYpx 7ZJQ== X-Gm-Message-State: APjAAAUwK/QTZiSQGYWyAbj3sUUa8fS85HMBtOKO+yu4HjPcYfl1dwVa IZirbDWOOzLMUnx1hZRJEjab61Qx3tY= X-Received: by 2002:a0c:b311:: with SMTP id s17mr4441198qve.69.1551320326433; Wed, 27 Feb 2019 18:18:46 -0800 (PST) Received: from localhost.localdomain (cpe-98-13-254-243.nyc.res.rr.com. [98.13.254.243]) by smtp.gmail.com with ESMTPSA id y21sm12048357qth.90.2019.02.27.18.18.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 27 Feb 2019 18:18:45 -0800 (PST) From: Dennis Zhou To: Dennis Zhou , Tejun Heo , Christoph Lameter Cc: Vlad Buslov , kernel-team@fb.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/12] percpu: do not search past bitmap when allocating an area Date: Wed, 27 Feb 2019 21:18:29 -0500 Message-Id: <20190228021839.55779-3-dennis@kernel.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20190228021839.55779-1-dennis@kernel.org> References: <20190228021839.55779-1-dennis@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org pcpu_find_block_fit() guarantees that a fit is found within PCPU_BITMAP_BLOCK_BITS. Iteration is used to determine the first fit as it compares against the block's contig_hint. This can lead to incorrectly scanning past the end of the bitmap. The behavior was okay given the check after for bit_off >= end and the correctness of the hints from pcpu_find_block_fit(). This patch fixes this by bounding the end offset by the number of bits in a chunk. Signed-off-by: Dennis Zhou --- mm/percpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/percpu.c b/mm/percpu.c index 53bd79a617b1..69ca51d238b5 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -988,7 +988,8 @@ static int pcpu_alloc_area(struct pcpu_chunk *chunk, int alloc_bits, /* * Search to find a fit. */ - end = start + alloc_bits + PCPU_BITMAP_BLOCK_BITS; + end = min_t(int, start + alloc_bits + PCPU_BITMAP_BLOCK_BITS, + pcpu_chunk_map_bits(chunk)); bit_off = bitmap_find_next_zero_area(chunk->alloc_map, end, start, alloc_bits, align_mask); if (bit_off >= end) -- 2.17.1