Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp7373157yba; Thu, 2 May 2019 08:47:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKD/wgF2PqZvlLhEeBXySawatmYxvL79K2//jnAQkcjA3TyU/GzyYpySjeHKVqOOFNj1mv X-Received: by 2002:a62:d205:: with SMTP id c5mr4877307pfg.219.1556812023391; Thu, 02 May 2019 08:47:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556812023; cv=none; d=google.com; s=arc-20160816; b=tE+VUajtHaDK69FJVMpU903NG6ILo6WG5JsQbIeKbKo3z9j+J+jtUcyk6liBUH+DXr vkB+ob18d4KwTn1f+fGmPQWoUXRrtbLR5Gw3iPqWUa/mg7JLDebs8IopmAlo5aezBEjb aI/mAjpxCmJAnJpx5gpRyaSrl74f7Qz+Bd0D7JIk2Lw/qjRSiztoWonlPjZXt838QIa0 5UW8LGwefZZOkBGV+MJeX6ZHONcmCvuK7ctn3XBWWIVWl/hQKXtColR9hHNub40wmX20 IQKToSyBxsBeTKs7coDeHVIXdQhxIl+XKL9cV3KToDsJ4GgcJi2blJfWf91GAu2Rkfl2 YEeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=e6zo+nsftE9YKLvQ67bjeobJUWc5jr/GzIzg9mnY1do=; b=GEkrMBzH4qP2Vd6LYQBXECNJO1b2kB+ZqJYeA0041X4JgsO9hXjdeUcHmyWd81Aw2N /LsNMwjfcpvt/ApFkh7UxRWrrapt5smnjYO3tbM25zFL39GCF0ZCbbs1eCe1lBSDlHEV ID6LVwFs6vE91Z2tMvpczK0G/WApa3DOqyoINRJrOWY2+hwQSniNQaQsbZmgFBDHbFPa zOGTqFl8xUCPRGeDd+vSU95pAndHWTjVnjVfDVu/svZelwLbUFVgfu8jRrfKzvqufsJs +eLEyzxXQkyVFERtG2AxCqxIFRndis94CLispfZv5wofwhzu21XZJ0h078AO5lW49+Qt e7QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2Sn4QVa8; 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 m64si16114086pfm.188.2019.05.02.08.46.48; Thu, 02 May 2019 08:47:03 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=2Sn4QVa8; 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 S1727282AbfEBPpj (ORCPT + 99 others); Thu, 2 May 2019 11:45:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:42048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727580AbfEBPZi (ORCPT ); Thu, 2 May 2019 11:25:38 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B41FA214DA; Thu, 2 May 2019 15:25:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556810738; bh=oLrJ4LmSz7pDcdhOyRVpFHi65SBRmVoqaJ3TtCMVh28=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2Sn4QVa8lCPENn8qCkDUUSWxQvdV7rEh6PjVCduAiWngss3QismKG56pko5ZXiutm U5AJdES5fOIJmh15VbKqQDc6ontO6ecrd2Q5d06dEvH4jcasZCgHWj5D92I5NN753o XzuzVUYTC9zN6AqxteD2xOd1pWi3+zbqeWhY0QUU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matthew Wilcox , Jann Horn , stable@kernel.org, Linus Torvalds Subject: [PATCH 4.19 03/72] mm: make page ref count overflow check tighter and more explicit Date: Thu, 2 May 2019 17:20:25 +0200 Message-Id: <20190502143333.783252966@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190502143333.437607839@linuxfoundation.org> References: <20190502143333.437607839@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Linus Torvalds commit f958d7b528b1b40c44cfda5eabe2d82760d868c3 upstream. We have a VM_BUG_ON() to check that the page reference count doesn't underflow (or get close to overflow) by checking the sign of the count. That's all fine, but we actually want to allow people to use a "get page ref unless it's already very high" helper function, and we want that one to use the sign of the page ref (without triggering this VM_BUG_ON). Change the VM_BUG_ON to only check for small underflows (or _very_ close to overflowing), and ignore overflows which have strayed into negative territory. Acked-by: Matthew Wilcox Cc: Jann Horn Cc: stable@kernel.org Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- include/linux/mm.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -915,6 +915,10 @@ static inline bool is_device_public_page } #endif /* CONFIG_DEV_PAGEMAP_OPS */ +/* 127: arbitrary random number, small enough to assemble well */ +#define page_ref_zero_or_close_to_overflow(page) \ + ((unsigned int) page_ref_count(page) + 127u <= 127u) + static inline void get_page(struct page *page) { page = compound_head(page); @@ -922,7 +926,7 @@ static inline void get_page(struct page * Getting a normal page or the head of a compound page * requires to already have an elevated page->_refcount. */ - VM_BUG_ON_PAGE(page_ref_count(page) <= 0, page); + VM_BUG_ON_PAGE(page_ref_zero_or_close_to_overflow(page), page); page_ref_inc(page); }