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=unavailable 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 BFBB1C4338F for ; Fri, 20 Aug 2021 08:25:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A6F76610CB for ; Fri, 20 Aug 2021 08:25:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232199AbhHTIZq (ORCPT ); Fri, 20 Aug 2021 04:25:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:40312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230077AbhHTIZl (ORCPT ); Fri, 20 Aug 2021 04:25:41 -0400 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) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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