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=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no 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 E1C0AC07548 for ; Thu, 10 Sep 2020 16:34:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9051F214F1 for ; Thu, 10 Sep 2020 16:34:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qio5Y/ng" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726947AbgIJQeH (ORCPT ); Thu, 10 Sep 2020 12:34:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726848AbgIJQUA (ORCPT ); Thu, 10 Sep 2020 12:20:00 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 032FFC061795 for ; Thu, 10 Sep 2020 09:19:25 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id z9so669825wmk.1 for ; Thu, 10 Sep 2020 09:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FMPZ+VzJ+cGDOwRKaJNQBA78kSsKgAl4Rh0tiwYlTzE=; b=qio5Y/ngq6hLvVhm2468rrq1KMTKqMD6reAUvBjeUZg28PU5pE4JmNKzEpw8Dq+ZXy +EBIltpVv7QGDdAn4nxre70MoBcYp+ZbE2Ys3VULwUK1yP0HL3DasnxQfvmF0gkR+Q2w XXXT1jlovgPhzmb2Azi56ku1TTdNZxdn+K+kr78m2GsuiuQXY9gX12qF88KkpZnemGhJ MJssQE/2khIJzxVKek0/2AchROZlEnhoQlFEPM6sUEfKgfy2CAq/Yh22tkigFm698koO mMAoFZxYY/mBcRNr6lIqxmYIA0Po3F0jG8at5Ra3VRYBbSP1Kv4QWYrVQtLIm0bvwx1e m4lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FMPZ+VzJ+cGDOwRKaJNQBA78kSsKgAl4Rh0tiwYlTzE=; b=J8VlbpFuAgQpqLDnTq7Ve+cLk+83A1ccvbIIIOZN5ONP2R9mN6WXiGHJFWR13QgKVs ytGwNjhh4ihH4AjEW8+2N9nbL7Eftc6uH19TVg7bl8z4JQB+a6fU4UDz3q5L2WOZbdJG DOinCkkpPdXn07cm4p2970raaQvZ208OVMqFKGJspj4WNgAe61QyEo8aH9Jt9LbYybr1 u5spc8RDwCRbvL6mp2mcOJxnVg1K9KZPk/8HjaVmiszbTqAUM8YHKSibbnVHiRLyvPsX 73IueBcYTaaDZz7FsXYkvSXWwwYEBV3JJoJ7Nz+ASPM7W6gzZs6oMxm/R+o4lWIVwZZi xEZA== X-Gm-Message-State: AOAM5323Py3v9oN9JpXuTcMeWMT/kEvY/8bGZqaBuYAvC9eUMHXWQ6nP p/u7SYAejaXggskb42Edu9hgujIS5pMRhrdfx7QvFA== X-Google-Smtp-Source: ABdhPJyoPsL8Lmtmn7sZD3Htvbk1/voqEAiS4Xrou0lgQ0ny/1SONHlnFGvvgkm/zl3krXuPxJMxMt2fP0vpplN7tBI= X-Received: by 2002:a7b:cd93:: with SMTP id y19mr760920wmj.112.1599754762218; Thu, 10 Sep 2020 09:19:22 -0700 (PDT) MIME-Version: 1.0 References: <20200907134055.2878499-1-elver@google.com> <20200907134055.2878499-2-elver@google.com> In-Reply-To: From: Alexander Potapenko Date: Thu, 10 Sep 2020 18:19:10 +0200 Message-ID: Subject: Re: [PATCH RFC 01/10] mm: add Kernel Electric-Fence infrastructure To: Dmitry Vyukov Cc: Marco Elver , Andrew Morton , Catalin Marinas , Christoph Lameter , David Rientjes , Joonsoo Kim , Mark Rutland , Pekka Enberg , "H. Peter Anvin" , "Paul E. McKenney" , Andrey Konovalov , Andrey Ryabinin , Andy Lutomirski , Borislav Petkov , Dave Hansen , Eric Dumazet , Greg Kroah-Hartman , Ingo Molnar , Jann Horn , Jonathan Corbet , Kees Cook , Peter Zijlstra , Qian Cai , Thomas Gleixner , Will Deacon , "the arch/x86 maintainers" , "open list:DOCUMENTATION" , LKML , kasan-dev , Linux ARM , Linux-MM Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 10, 2020 at 5:43 PM Dmitry Vyukov wrote: > > + /* Calculate address for this allocation. */ > > + if (right) > > + meta->addr += PAGE_SIZE - size; > > + meta->addr = ALIGN_DOWN(meta->addr, cache->align); > > I would move this ALIGN_DOWN under the (right) if. > Do I understand it correctly that it will work, but we expect it to do > nothing for !right? If cache align is >PAGE_SIZE, nothing good will > happen anyway, right? > The previous 2 lines look like part of the same calculation -- "figure > out the addr for the right case". Yes, makes sense. > > + > > + schedule_delayed_work(&kfence_timer, 0); > > + WRITE_ONCE(kfence_enabled, true); > > Can toggle_allocation_gate run before we set kfence_enabled? If yes, > it can break. If not, it's still somewhat confusing. Correct, it should go after we enable KFENCE. We'll fix that in v2. > > +void __kfence_free(void *addr) > > +{ > > + struct kfence_metadata *meta = addr_to_metadata((unsigned long)addr); > > + > > + if (unlikely(meta->cache->flags & SLAB_TYPESAFE_BY_RCU)) > > This may deserve a comment as to why we apply rcu on object level > whereas SLAB_TYPESAFE_BY_RCU means slab level only. Sorry, what do you mean by "slab level"? SLAB_TYPESAFE_BY_RCU means we have to wait for possible RCU accesses in flight before freeing objects from that slab - that's basically what we are doing here below: > > + call_rcu(&meta->rcu_head, rcu_guarded_free); > > + else > > + kfence_guarded_free(addr, meta); > > +} > > +void kfence_print_object(struct seq_file *seq, const struct kfence_metadata *meta) > > +{ > > + const int size = abs(meta->size); > > This negative encoding is somewhat confusing. We do lots of abs, but > do we even look at the sign anywhere? I can't find any use that is not > abs. I think initially there was a reason for this, but now we don't seem to use it anywhere. Nice catch! Alex 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=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no 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 089C3C433E2 for ; Thu, 10 Sep 2020 16:19:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 80A6A206A1 for ; Thu, 10 Sep 2020 16:19:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qio5Y/ng" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 80A6A206A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D7CC76B0085; Thu, 10 Sep 2020 12:19:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D52A86B0099; Thu, 10 Sep 2020 12:19:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C40586B009B; Thu, 10 Sep 2020 12:19:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0149.hostedemail.com [216.40.44.149]) by kanga.kvack.org (Postfix) with ESMTP id AB3586B0085 for ; Thu, 10 Sep 2020 12:19:24 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 74DCA180AD81A for ; Thu, 10 Sep 2020 16:19:24 +0000 (UTC) X-FDA: 77247661848.28.shape17_28169c9270e7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 4211C6C04 for ; Thu, 10 Sep 2020 16:19:24 +0000 (UTC) X-HE-Tag: shape17_28169c9270e7 X-Filterd-Recvd-Size: 5917 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Thu, 10 Sep 2020 16:19:23 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id k18so640989wmj.5 for ; Thu, 10 Sep 2020 09:19:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FMPZ+VzJ+cGDOwRKaJNQBA78kSsKgAl4Rh0tiwYlTzE=; b=qio5Y/ngq6hLvVhm2468rrq1KMTKqMD6reAUvBjeUZg28PU5pE4JmNKzEpw8Dq+ZXy +EBIltpVv7QGDdAn4nxre70MoBcYp+ZbE2Ys3VULwUK1yP0HL3DasnxQfvmF0gkR+Q2w XXXT1jlovgPhzmb2Azi56ku1TTdNZxdn+K+kr78m2GsuiuQXY9gX12qF88KkpZnemGhJ MJssQE/2khIJzxVKek0/2AchROZlEnhoQlFEPM6sUEfKgfy2CAq/Yh22tkigFm698koO mMAoFZxYY/mBcRNr6lIqxmYIA0Po3F0jG8at5Ra3VRYBbSP1Kv4QWYrVQtLIm0bvwx1e m4lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FMPZ+VzJ+cGDOwRKaJNQBA78kSsKgAl4Rh0tiwYlTzE=; b=q+vE1xPgZctO+/LGmDh3yYNefEo1zhZEQS6WO8jrevmn9vM18p5zX8ULAuRrPJYWyd 8j72iQHQs3/6v/rxCbFtv3nEpODAGhRts+del2aRda0wHGxPumKUQi+unmd6U42s4GKa IxBxSuECR9Hu7oURWUNeUqtFOhl7lKsTcajvWNNm2BM0m1p87uvHonadIVQYe/SVjumm 7yr+5cP0ogjtzuR6QXfimTyuoSOeiFN5DISI+AOCDjVPfYz3OXvKAUE8sx/7TPQPCYd8 kHuPEzJLcA1Sp6UhVOmpSPgx60XWYO3dLiS4y9h5QNPnsdmEhZGaRRrHdFzXHHcxF0yj tt6Q== X-Gm-Message-State: AOAM531Nx2uEbDINyihnF9o0hSGzYwbeacXpt4ZvGrc2MhZvY1X/OZWv Li+KKQiW9CXOF/80wD1fXhNxFyu5pQfgZvYDxK1LKQ== X-Google-Smtp-Source: ABdhPJyoPsL8Lmtmn7sZD3Htvbk1/voqEAiS4Xrou0lgQ0ny/1SONHlnFGvvgkm/zl3krXuPxJMxMt2fP0vpplN7tBI= X-Received: by 2002:a7b:cd93:: with SMTP id y19mr760920wmj.112.1599754762218; Thu, 10 Sep 2020 09:19:22 -0700 (PDT) MIME-Version: 1.0 References: <20200907134055.2878499-1-elver@google.com> <20200907134055.2878499-2-elver@google.com> In-Reply-To: From: Alexander Potapenko Date: Thu, 10 Sep 2020 18:19:10 +0200 Message-ID: Subject: Re: [PATCH RFC 01/10] mm: add Kernel Electric-Fence infrastructure To: Dmitry Vyukov Cc: Marco Elver , Andrew Morton , Catalin Marinas , Christoph Lameter , David Rientjes , Joonsoo Kim , Mark Rutland , Pekka Enberg , "H. Peter Anvin" , "Paul E. McKenney" , Andrey Konovalov , Andrey Ryabinin , Andy Lutomirski , Borislav Petkov , Dave Hansen , Eric Dumazet , Greg Kroah-Hartman , Ingo Molnar , Jann Horn , Jonathan Corbet , Kees Cook , Peter Zijlstra , Qian Cai , Thomas Gleixner , Will Deacon , "the arch/x86 maintainers" , "open list:DOCUMENTATION" , LKML , kasan-dev , Linux ARM , Linux-MM Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 4211C6C04 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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 Thu, Sep 10, 2020 at 5:43 PM Dmitry Vyukov wrote: > > + /* Calculate address for this allocation. */ > > + if (right) > > + meta->addr += PAGE_SIZE - size; > > + meta->addr = ALIGN_DOWN(meta->addr, cache->align); > > I would move this ALIGN_DOWN under the (right) if. > Do I understand it correctly that it will work, but we expect it to do > nothing for !right? If cache align is >PAGE_SIZE, nothing good will > happen anyway, right? > The previous 2 lines look like part of the same calculation -- "figure > out the addr for the right case". Yes, makes sense. > > + > > + schedule_delayed_work(&kfence_timer, 0); > > + WRITE_ONCE(kfence_enabled, true); > > Can toggle_allocation_gate run before we set kfence_enabled? If yes, > it can break. If not, it's still somewhat confusing. Correct, it should go after we enable KFENCE. We'll fix that in v2. > > +void __kfence_free(void *addr) > > +{ > > + struct kfence_metadata *meta = addr_to_metadata((unsigned long)addr); > > + > > + if (unlikely(meta->cache->flags & SLAB_TYPESAFE_BY_RCU)) > > This may deserve a comment as to why we apply rcu on object level > whereas SLAB_TYPESAFE_BY_RCU means slab level only. Sorry, what do you mean by "slab level"? SLAB_TYPESAFE_BY_RCU means we have to wait for possible RCU accesses in flight before freeing objects from that slab - that's basically what we are doing here below: > > + call_rcu(&meta->rcu_head, rcu_guarded_free); > > + else > > + kfence_guarded_free(addr, meta); > > +} > > +void kfence_print_object(struct seq_file *seq, const struct kfence_metadata *meta) > > +{ > > + const int size = abs(meta->size); > > This negative encoding is somewhat confusing. We do lots of abs, but > do we even look at the sign anywhere? I can't find any use that is not > abs. I think initially there was a reason for this, but now we don't seem to use it anywhere. Nice catch! Alex 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=-3.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 02838C43461 for ; Thu, 10 Sep 2020 16:20:52 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9B0712075A for ; Thu, 10 Sep 2020 16:20:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="2/R2qsqb"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="qio5Y/ng" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9B0712075A Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vN62JwkmBicuR/0ieojiSnjnMzY9Czp+ZWUT8HQ+YvY=; b=2/R2qsqbYVTalgF2GlsYeh38n lAo7yrzjd7F/2GZ2yj/vV7wqcuFWnQv6pKjre6ALIMvn6lhGY6dEv5YDu6pMNNMZGIETsh6UGyn9W Kq4IQky+zcezA4u7UOM6jySOdvZehwFF/Ls/5Wb7RBkSYEXdmi8M/RfdvaotiTv8rmDmSrodYVX0Z 00wwaNRigdMjeB+BcQxr5hX+lF2nZFg0WydAgdW889W79OySSwbpXj5KRFVb7gMqi+S2tMqg5MKhc tShPp5kv0S/OCHN214PQO5M5+tEHt8vjUMu8Q49DxjvpuDd3gLBcTZohYGbZQuD8vKNN7mEnoI2+i qjyQDMfMw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kGPII-0003eS-Pb; Thu, 10 Sep 2020 16:19:30 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kGPIE-0003bM-ED for linux-arm-kernel@lists.infradead.org; Thu, 10 Sep 2020 16:19:27 +0000 Received: by mail-wm1-x343.google.com with SMTP id l9so656187wme.3 for ; Thu, 10 Sep 2020 09:19:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FMPZ+VzJ+cGDOwRKaJNQBA78kSsKgAl4Rh0tiwYlTzE=; b=qio5Y/ngq6hLvVhm2468rrq1KMTKqMD6reAUvBjeUZg28PU5pE4JmNKzEpw8Dq+ZXy +EBIltpVv7QGDdAn4nxre70MoBcYp+ZbE2Ys3VULwUK1yP0HL3DasnxQfvmF0gkR+Q2w XXXT1jlovgPhzmb2Azi56ku1TTdNZxdn+K+kr78m2GsuiuQXY9gX12qF88KkpZnemGhJ MJssQE/2khIJzxVKek0/2AchROZlEnhoQlFEPM6sUEfKgfy2CAq/Yh22tkigFm698koO mMAoFZxYY/mBcRNr6lIqxmYIA0Po3F0jG8at5Ra3VRYBbSP1Kv4QWYrVQtLIm0bvwx1e m4lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FMPZ+VzJ+cGDOwRKaJNQBA78kSsKgAl4Rh0tiwYlTzE=; b=SgkVx4kU3CKZLRFpkUf2a/ml4cg7wXb9FgcHY4KIe3ZFqNXoyOaBafFHlX/fZXDiRi NFRvH7rOgdp6Kw2SpyFvi9lq5Ei78abQ+iU0CrVe72ArOvLX7ns7k8l/QXqLKY4Halzz +Yh+8ZCtMPwPIw8yuKNujwuKhKumfBlIN1bS6HJvXHiEciQCm6ONznAj3ndEV3vfSUOY o4RgcZ72+NV2wFwiCz6N/vXIdqLQonVsWRyw0XmZbxUFAVR4vqhJznmIys7uGjYoJ0Fw IWu2cdVgZq/mDclv5r0TeKhMxqu27glNLcSX+kc2DmVKoTIegLCX61Ge8u4iPSieRWsy WsLA== X-Gm-Message-State: AOAM533GD5LMrYnpMXzes1kjeTpByTFhIYHvZOqzTaf0gq8Jm2PiAjko uMAwQEhTPHXFGq3QZGPKpwM+WW6t/YSSohplTG9ERA== X-Google-Smtp-Source: ABdhPJyoPsL8Lmtmn7sZD3Htvbk1/voqEAiS4Xrou0lgQ0ny/1SONHlnFGvvgkm/zl3krXuPxJMxMt2fP0vpplN7tBI= X-Received: by 2002:a7b:cd93:: with SMTP id y19mr760920wmj.112.1599754762218; Thu, 10 Sep 2020 09:19:22 -0700 (PDT) MIME-Version: 1.0 References: <20200907134055.2878499-1-elver@google.com> <20200907134055.2878499-2-elver@google.com> In-Reply-To: From: Alexander Potapenko Date: Thu, 10 Sep 2020 18:19:10 +0200 Message-ID: Subject: Re: [PATCH RFC 01/10] mm: add Kernel Electric-Fence infrastructure To: Dmitry Vyukov X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200910_121926_533362_3FA0D421 X-CRM114-Status: GOOD ( 25.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , "open list:DOCUMENTATION" , Peter Zijlstra , Catalin Marinas , Dave Hansen , Linux-MM , Eric Dumazet , "H. Peter Anvin" , Christoph Lameter , Will Deacon , Jonathan Corbet , the arch/x86 maintainers , kasan-dev , Ingo Molnar , David Rientjes , Andrey Ryabinin , Marco Elver , Kees Cook , "Paul E. McKenney" , Jann Horn , Andrey Konovalov , Borislav Petkov , Andy Lutomirski , Thomas Gleixner , Andrew Morton , Linux ARM , Greg Kroah-Hartman , LKML , Pekka Enberg , Qian Cai , Joonsoo Kim Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Sep 10, 2020 at 5:43 PM Dmitry Vyukov wrote: > > + /* Calculate address for this allocation. */ > > + if (right) > > + meta->addr += PAGE_SIZE - size; > > + meta->addr = ALIGN_DOWN(meta->addr, cache->align); > > I would move this ALIGN_DOWN under the (right) if. > Do I understand it correctly that it will work, but we expect it to do > nothing for !right? If cache align is >PAGE_SIZE, nothing good will > happen anyway, right? > The previous 2 lines look like part of the same calculation -- "figure > out the addr for the right case". Yes, makes sense. > > + > > + schedule_delayed_work(&kfence_timer, 0); > > + WRITE_ONCE(kfence_enabled, true); > > Can toggle_allocation_gate run before we set kfence_enabled? If yes, > it can break. If not, it's still somewhat confusing. Correct, it should go after we enable KFENCE. We'll fix that in v2. > > +void __kfence_free(void *addr) > > +{ > > + struct kfence_metadata *meta = addr_to_metadata((unsigned long)addr); > > + > > + if (unlikely(meta->cache->flags & SLAB_TYPESAFE_BY_RCU)) > > This may deserve a comment as to why we apply rcu on object level > whereas SLAB_TYPESAFE_BY_RCU means slab level only. Sorry, what do you mean by "slab level"? SLAB_TYPESAFE_BY_RCU means we have to wait for possible RCU accesses in flight before freeing objects from that slab - that's basically what we are doing here below: > > + call_rcu(&meta->rcu_head, rcu_guarded_free); > > + else > > + kfence_guarded_free(addr, meta); > > +} > > +void kfence_print_object(struct seq_file *seq, const struct kfence_metadata *meta) > > +{ > > + const int size = abs(meta->size); > > This negative encoding is somewhat confusing. We do lots of abs, but > do we even look at the sign anywhere? I can't find any use that is not > abs. I think initially there was a reason for this, but now we don't seem to use it anywhere. Nice catch! Alex _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel