Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp7376011yba; Thu, 2 May 2019 08:49:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqxUlxlenR/+uJpnXdRYhkcebB94CTvR4Ri///hRr8T6s43tapD/sbS8+ZwnJ81Pr+Nm7Xag X-Received: by 2002:a63:1b11:: with SMTP id b17mr4710630pgb.207.1556812198494; Thu, 02 May 2019 08:49:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556812198; cv=none; d=google.com; s=arc-20160816; b=UiWcJsYcY3L652oOexjL/yeIBCzHtwH3g9i2NoXgAyZVv0+gjcPlp6wj09b8UYpgq7 LpK7UM5Ao2hoIY2EwxS0OV8dD1NHdPvfsft8Ffh2BzIc07DOcpppZLyehDv2L+i+w4YQ h/Fph/xBiu9cqnsVyuFLnhBIKj/guhptsz2aVk6NeCI2xDNSeCRe5whe1JBlajvQzufn P86eQD0RVc8RQ1Y5iz5GWcoIRt3CuEyNMrgJJ4yS34DINb2mVvgQ/TpMm39mghcptDbt qrRm+YbMIoUbpg4/9JU+WH5tne6tLrqs7YmdD9fLmOm2UyFH/vzgbDomw0fIboga4D2C bKZg== 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=Tbw6i3rQ9w6Wo6GqhY/Ah9WkD08Fo2Jxm5BBUhas/Vk=; b=WRLOXQ0PjFBVow/kTe2qLZmnMRStgSxbwjDkP8J4ESUdeysiaViUXFNZ+wSPS2FILK wmvfNnB3bvyBtK17mocgVmyvhYWvmFAJUKo7tUXvES1y/SgBQ47V9Kkp9K+pY1JmOOJM HzZYcg2tD2wxbr/OBn5TFCvbm+dcpG4WaxFGgUi7rKtY+8CkiLASLIc84vTd01PY+Wt3 vVlCowQx672H/ERI5YfcpkV0+CdmZ2S+INZMDNLl0G+5OocnKGYkgXBg9BMNveQiG1ba 9NqNML1uJkHaay7W+1tjrpKKN6Hzu5zxku+3npvP0xMd6+5FeD6G0NipK30XAjtltq1U MbfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tQBa2vpc; 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 y16si30486719pga.34.2019.05.02.08.49.42; Thu, 02 May 2019 08:49:58 -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=tQBa2vpc; 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 S1727261AbfEBPYU (ORCPT + 99 others); Thu, 2 May 2019 11:24:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:40168 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726614AbfEBPYS (ORCPT ); Thu, 2 May 2019 11:24:18 -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 D5A26217D7; Thu, 2 May 2019 15:24:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556810657; bh=9VusDEM0Dk+CvbhfFruOjQti9yM7gvFuK8A5wTVuoSg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tQBa2vpcyfeWTXFfuR9sOX7t1M3e/moZIEeZ748V0KHo+5E5qs4rzz7wFB+TTF1vs 3LUOn3iIA8JYcIEyzMHU4Fc5hp6JSB4ZIuHSN5AmdOvo464G2QJDctHxFm43GQOjUV BXZ2YPjPTIWV4oK26jIBYkJxSMF2Uu6qnjxRYBP4= 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.14 04/49] mm: make page ref count overflow check tighter and more explicit Date: Thu, 2 May 2019 17:20:41 +0200 Message-Id: <20190502143324.526640348@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190502143323.397051088@linuxfoundation.org> References: <20190502143323.397051088@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 @@ -824,6 +824,10 @@ static inline bool is_device_public_page #endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */ +/* 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); @@ -831,7 +835,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); }