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=-16.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS 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 68E6BC4338F for ; Fri, 20 Aug 2021 17:26:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 12F5260E90 for ; Fri, 20 Aug 2021 17:26:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 12F5260E90 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 9B5A86B0071; Fri, 20 Aug 2021 13:26:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9663C6B0072; Fri, 20 Aug 2021 13:26:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82EB86B0073; Fri, 20 Aug 2021 13:26:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0026.hostedemail.com [216.40.44.26]) by kanga.kvack.org (Postfix) with ESMTP id 657E36B0071 for ; Fri, 20 Aug 2021 13:26:14 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 17A591F04B for ; Fri, 20 Aug 2021 17:26:14 +0000 (UTC) X-FDA: 78496137468.01.C12328E Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf25.hostedemail.com (Postfix) with ESMTP id AB719B000187 for ; Fri, 20 Aug 2021 17:26:13 +0000 (UTC) Received: by mail-pf1-f172.google.com with SMTP id k19so9205765pfc.11 for ; Fri, 20 Aug 2021 10:26:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=D8sisJowkMm73SRcyloSHTS3YrdB++THv76Ik71IMKs=; b=PsGLm1nHLmD0olMes1ii+F35WB1QR3GTdzThohn2vNRHikczDvTAL7ub6u59oWmXOh yhGJ7GXmoYVqqa6Ujv/zD3nt0WUaghYfRdXL9FI9PNhxF3QA2yV5NJV0jGNRq4L6F3iz M5DBU12zh7G4AIT9vbvOjCjTmI+CmHnd7ti6c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=D8sisJowkMm73SRcyloSHTS3YrdB++THv76Ik71IMKs=; b=Di0hV5xOWZZmI5fJNe3MpFT3R3jakgipqwahpkB4IlqrOyJr+uW9aEHiaLmmBxJc1r fwT52xT1kiXcfN1SN+qIHb82PWcvmINvMa00Es7YbSU+XD3RhgNe5gGSpJCW7eApU+Bf IURrPYPBmh586FPwT2ZrdwroDjsZLohbiMp76Yq96GItGR+WSYGot2tqSfvB66RbybRa xnmuxuhBiUagTmXv7w0/TzPWyr0v2k1IVn2wuALF+8R6u9wMTX1naGPiS+YXBcqykJsT YGwWWdANWGkRPS39YF0P3RJOSinJ4YtYtt+z751GdueA85xpMgTpud7GDAmP4JlV2ZH9 aLGw== X-Gm-Message-State: AOAM533O4Vg77n99wpZS5VE037kZci8XkweVbZPt0YpB5oLnu9ggB4Om 0P/bahnfbTNKHV6AmwbcNg4CGw== X-Google-Smtp-Source: ABdhPJxP3ToehmaVHNs/nW/7VuNtAx+pgvsn+WFlB9EEoe2zs22r1Qot84tN6E5aN5x6mPGGRXYiBw== X-Received: by 2002:a05:6a00:168a:b0:3e2:789e:5fd0 with SMTP id k10-20020a056a00168a00b003e2789e5fd0mr20666872pfc.68.1629480372638; Fri, 20 Aug 2021 10:26:12 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id g26sm8760565pgb.45.2021.08.20.10.26.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Aug 2021 10:26:11 -0700 (PDT) Date: Fri, 20 Aug 2021 10:26:10 -0700 From: Kees Cook To: Peter Zijlstra Cc: Will Deacon , 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 Subject: Re: [PATCH] mm/rmap: Convert from atomic_t to refcount_t on anon_vma->refcount Message-ID: <202108201013.36752C28@keescook> References: <1626665029-49104-1-git-send-email-xiyuyang19@fudan.edu.cn> <20210720160127.ac5e76d1e03a374b46f25077@linux-foundation.org> <20210819132131.GA15779@willie-the-truck> <20210820082457.GA16784@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: AB719B000187 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=PsGLm1nH; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf25.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.172 as permitted sender) smtp.mailfrom=keescook@chromium.org X-Rspamd-Server: rspam04 X-Stat-Signature: n948cd54wy96wxhnedgx4487djubbon6 X-HE-Tag: 1629480373-692669 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 11:03:00AM +0200, Peter Zijlstra wrote: > On Fri, Aug 20, 2021 at 09:24:58AM +0100, Will Deacon wrote: > > > > 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 > > kernel/event/core.o-outofline-saturate-ud2: 96954 > kernel/event/core.o: 97248 > > > Is that with the saturation moved to the UD handler as well? > > Yep, that's the full function call replaced with an exception. > > > 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? > > That's simpler execption code too, we can abuse the existing WARN/UD2 > stuff. > > --- > arch/x86/include/asm/refcount.h | 31 +++++++++++++++++++++++++++++++ > include/asm-generic/bug.h | 4 ++++ > include/linux/refcount.h | 15 +++++++++++---- > lib/bug.c | 13 ++++++++++++- > lib/refcount.c | 7 ++----- > 5 files changed, 60 insertions(+), 10 deletions(-) > > diff --git a/arch/x86/include/asm/refcount.h b/arch/x86/include/asm/refcount.h > new file mode 100644 > index 000000000000..bed52b95d24c > --- /dev/null > +++ b/arch/x86/include/asm/refcount.h > @@ -0,0 +1,31 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_X86_REFCOUNT_H > +#define _ASM_X86_REFCOUNT_H > + > +#define refcount_warn_saturate refcount_warn_saturate > +static __always_inline void refcount_warn_saturate(refcount_t *r, const enum refcount_saturation_type t) > +{ > + refcount_set(r, REFCOUNT_SATURATED); > + __WARN_FLAGS(BUGFLAG_ONCE|BUGFLAG_REFCOUNT|BUGFLAG_REFCOUNT_TYPE(t)); > +} Instead of using up warn flags, what was done in the past was to use an explicit EXTABLE in a cold text section: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/include/asm/asm.h?h=v4.15#n80 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/mm/extable.c?h=v4.15#n45 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/include/asm/refcount.h?h=v4.15 > + > +#define refcount_dec_and_test refcount_dec_and_test > +static inline 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; > +} This looks basically the same as what we had before (i.e. the earlier REFCOUNT_CHECK_LE_ZERO within GEN_UNARY_SUFFIXED_RMWcc). -- Kees Cook