From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB1B7C4338F for ; Fri, 20 Aug 2021 08:25:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7B739610D2 for ; Fri, 20 Aug 2021 08:25:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7B739610D2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 1171E6B0071; Fri, 20 Aug 2021 04:25:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A03C6B0072; Fri, 20 Aug 2021 04:25:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA9628D0001; Fri, 20 Aug 2021 04:25:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0065.hostedemail.com [216.40.44.65]) by kanga.kvack.org (Postfix) with ESMTP id CD07E6B0071 for ; Fri, 20 Aug 2021 04:25:05 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 72BBD1802BE1B for ; Fri, 20 Aug 2021 08:25:05 +0000 (UTC) X-FDA: 78494773770.09.189077D Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf27.hostedemail.com (Postfix) with ESMTP id 1C185700009B for ; Fri, 20 Aug 2021 08:25:05 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 7A112610A3; Fri, 20 Aug 2021 08:25:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629447904; bh=4zuMd4m7p1eR8VRfwtyd8SamPC6YHM7BjTVw1hV8o74=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Eg7LkK5l4UtJTA97Lw2VDJbt56j5SiiDvAZqCGMDbaWHkEO/kEUQQrEg7GSbT2RVJ QWNdqk+kK2mmFFe8hGO1hFcIWoJMGwNJKtQPeUqKw60/c4pDITEmoVmP4tpKv37fhK +sRU8TbrsHWSjKLTzsaWyRDHX9KhH3qjio56ARaRxOHGBU8QLd+YVwU6/PkY/vgKSq GLTQKbpuGuUXPoD0oHibx4AeBr/XogQOlWkRyUAB6FipROU4FYibQjliClTUDbHjmy NUMMVeqAv3HAd9LTGqnlcx9aF1DTUbPtw1QdrVnFbRQ+qaGDBoYpisA1QsOIsIVc+c TmONRcZZVw3hg== Date: Fri, 20 Aug 2021 09:24:58 +0100 From: Will Deacon To: Peter Zijlstra Cc: Linus Torvalds , Andrew Morton , Borislav Petkov , Xiyu Yang , Alistair Popple , Yang Shi , Shakeel Butt , Hugh Dickins , Miaohe Lin , Linux Kernel Mailing List , Linux-MM , yuanxzhang@fudan.edu.cn, Xin Tan , Will Deacon , David Howells , keescook@chromium.org Subject: Re: [PATCH] mm/rmap: Convert from atomic_t to refcount_t on anon_vma->refcount Message-ID: <20210820082457.GA16784@willie-the-truck> References: <1626665029-49104-1-git-send-email-xiyuyang19@fudan.edu.cn> <20210720160127.ac5e76d1e03a374b46f25077@linux-foundation.org> <20210819132131.GA15779@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Queue-Id: 1C185700009B Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Eg7LkK5l; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf27.hostedemail.com: domain of will@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=will@kernel.org X-Rspamd-Server: rspam04 X-Stat-Signature: iegy8i4wt1x675mt46nm89r4egw1j3qs X-HE-Tag: 1629447905-824270 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Aug 20, 2021 at 10:16:18AM +0200, Peter Zijlstra wrote: > On Fri, Aug 20, 2021 at 08:43:40AM +0200, Peter Zijlstra wrote: > > > Fine with me; although the immediate complaint from Andrew was about > > size, hence my UD1 hackery. > > > > > So if we do this, I think it should be something like > > > > > > static inline __must_check bool refcount_dec_and_test(refcount_t *r) > > > { > > > asm_volatile_goto (LOCK_PREFIX "decl %[var]\n\t" > > > "jz %l[cc_zero]\n\t" > > > "jl %l[cc_error]" > > > : : [var] "m" (r->refs.counter) > > > : "memory" : cc_zero, cc_error); > > > > > > return false; > > > > > > cc_zero: > > > return true; > > > cc_error: > > > refcount_warn_saturate(r, REFCOUNT_SUB_UAF); > > > return false; > > > } > > > > > > and we can discuss whether we could improve on the > > > refcount_warn_saturate() separately. > > > > I can do the refcount_warn_saturate() change separately. > > > > Let me go check how small I can get it... > > gcc-10.2.1, x86_64-defconfig > > kernel/event/core.o-inline-ud1: 96454 > kernel/event/core.o-outofline-ud1: 96604 > kernel/event/core.o-outofline-call: 97072 > > (42 refcount_warn_saturate/ud1 instances in that file, > 10 of which are refcount_dec_and_test) Is that with the saturation moved to the UD handler as well? I think it would be good to keep that as close to the point at which we detect the problem as we can, so perhaps we can inline that part and leave the diagnostics to the exception handler? Will