Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp291279pxb; Wed, 27 Oct 2021 03:12:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3Q+o13jrIFvTs+G9OKJjYyQRczMU1TKjoU8DolRtdgFOgGbX/NkOg2ThMwvAqoyrabac1 X-Received: by 2002:a63:6d49:: with SMTP id i70mr23850375pgc.40.1635329531835; Wed, 27 Oct 2021 03:12:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635329531; cv=none; d=google.com; s=arc-20160816; b=mn1jcWLm2ydZqIiCM+jd41QSWL6+H1TKLIghN7OClCtKEVEhU2MHzsVtUJmoPWtHsa onjsgxoNwVCQuYN7Fel87QvqOpGnk1ih9EdQrHkdPVL5kbDt4y3YlgXUfxvhsFF/M4pU wNSaWD20KTVIDHpZQvnWK668cY1aagfszw4mNfztiwteVRdNVt7h5JDvpbe9WeCDujnz 972JjlCupXLz6G02I9lL0XPeB6OvzDUJT9Z0tXDmgsBjJCURH3/gsRWdykh4Weiyef9v FibIsEX7h03qmnfOdymk7KW/ack5wK0SpmeanwTDYREazTKuFKHxxymE7SMruFhRMVlg 0YXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=shc+/NvHg/NcqVmYgURHASgtGulIua8OVbhJZJMa/OY=; b=EOzN+eHpDFILRCuQpsOeD4JZ4QXJXSZurp3iLcnm8uVlCb0Lk2KPKS14VMVmCbmibc BhIyM0j2Rbobj9CfKGmhOEzKBo2oqGeNahPVzSpDB+uBGTKCVe+UmKtyvhd0KVOJhtoa u09mCvFlOv6S5Caqx1DoOlH4M+O5FKK/7nOj1JpfmC5aXcJTWQ1ZZx18Vy9tQ00wWhKw deZpZY5rfhp6URnVjuMkxXFB4SM6vYreAITGeLjh4UEymguiWi8oX6lJoZNdCN5sC3co TapIrpuksGUXxjI4MQV94VlB6ZE88ZAW4CxDKCirGeW11qni8UXwLH9YdXV6ACm6cwtA IxGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=h2scTVFQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q19si5014829pgl.462.2021.10.27.03.11.23; Wed, 27 Oct 2021 03:12:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=h2scTVFQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238958AbhJZTwz (ORCPT + 99 others); Tue, 26 Oct 2021 15:52:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233642AbhJZTwy (ORCPT ); Tue, 26 Oct 2021 15:52:54 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F503C061570; Tue, 26 Oct 2021 12:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=shc+/NvHg/NcqVmYgURHASgtGulIua8OVbhJZJMa/OY=; b=h2scTVFQCKTqaThnNi+sQi6FNf TYuSImBkJQK3rNZLy356ezVStEbL1f3qyQPUSE4tkSAPeMxKOyIKv4nFvePDmdmyEBut4m2vNTQTo EyHvTGyQaAFDe61wM8DoK+02q11vl3ypl3t6jJhFAwHb+YOdhal0Fh8bpRPRSD2QZjMyxDh1qNqli takQyvaijMoRQvZn/jVD6uy4uokCh4Oxo8yPhskgCJBbAnMZVBkST9zH03/QERLhu+Cy7/pOuQsFw hi+ZCTXpluw6yM9ekPYE68dI2gKYLwOlIGwzscTYfSy0TPkXaRRBt3cCG2lx2HQ+Nbp3Ymi3H5ywF ENeF1uXA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfSRP-00H7SC-Jc; Tue, 26 Oct 2021 19:49:21 +0000 Date: Tue, 26 Oct 2021 20:48:59 +0100 From: Matthew Wilcox To: Pasha Tatashin Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-m68k@lists.linux-m68k.org, anshuman.khandual@arm.com, akpm@linux-foundation.org, william.kucharski@oracle.com, mike.kravetz@oracle.com, vbabka@suse.cz, geert@linux-m68k.org, schmitzmic@gmail.com, rostedt@goodmis.org, mingo@redhat.com, hannes@cmpxchg.org, guro@fb.com, songmuchun@bytedance.com, weixugc@google.com, gthelen@google.com Subject: Re: [RFC 1/8] mm: add overflow and underflow checks for page->_refcount Message-ID: References: <20211026173822.502506-1-pasha.tatashin@soleen.com> <20211026173822.502506-2-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211026173822.502506-2-pasha.tatashin@soleen.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 26, 2021 at 05:38:15PM +0000, Pasha Tatashin wrote: > static inline void page_ref_add(struct page *page, int nr) > { > - atomic_add(nr, &page->_refcount); > + int ret; > + > + VM_BUG_ON(nr <= 0); > + ret = atomic_add_return(nr, &page->_refcount); > + VM_BUG_ON_PAGE(ret <= 0, page); This isn't right. _refcount is allowed to overflow into the negatives. See page_ref_zero_or_close_to_overflow() and the conversations that led to it being added.