Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1210747pxk; Thu, 10 Sep 2020 09:37:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaMIaOnN3+cCXCujO8dWG9RI/F8lgxCc2/YjDNc2gQjs3nGisQYbqWL58+HEnPMih9DGfa X-Received: by 2002:a17:906:fcc7:: with SMTP id qx7mr10330661ejb.254.1599755823514; Thu, 10 Sep 2020 09:37:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599755823; cv=none; d=google.com; s=arc-20160816; b=qD59HOP8niuEj7CQdo9RWIfdeisjCdYJcoOxg3KxrUwQosZ7u6NzH7AG5CBwELaIvV C8irPibuOYjZwyE60VnJH71WkqzbLHvyv/53UaAXA0G7QxHzCt6d+Lk0QmhYEN1QcFbm Tpm5mhKE0FtX6obM7mhTHtwpao/Vid8AqZ8ovEjficBogTwvkfgfF9OlKX6xuoN15V2J 6Tr9C0U3WGyDV1+n3Vvmwcw8VGpHJZBOhz2Wgw37H9dOTdHm5E5dCAvtbA+4VqtAYrBA v7lkuj68dxNOEwKMgftWtOVtJazTZ0JYXjV6uWHPKUHhz9d3LZZSIUH6Vvdy+ynHBytZ 2Scg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=FMPZ+VzJ+cGDOwRKaJNQBA78kSsKgAl4Rh0tiwYlTzE=; b=sg+HfdcJ6j6wA+LW3CpiWMzT96HYk0GH7/TwqGc8eNzee8Y1zHnPxW8ZpuamlYKelz uLBQyUXJtDYLdeVwrzNTKesTaZcIzy+mvsZLkqVPan78YId1BImIF8betruQrnDbfsmw IdFOyPDwCbgQyX4KHdeCB4f2LTNIWvoGz3XzE9QarwCUDTxOhEpgmftiMxckusZZWLGC uD+sPR6iYH2Je2H9cQcAoJkyVNI+wfP7pWG84LPNMnZJ9GY8jm0uaENoRR6F8HHphOOC 7HGhWCU+y8xuglHn11hK/cCuhcmjYJ6LW+DCwF9dDMk3so0eH9UgDtC3183vNgs5XXuR qj6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="qio5Y/ng"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y98si4286486ede.605.2020.09.10.09.36.40; Thu, 10 Sep 2020 09:37:03 -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=@google.com header.s=20161025 header.b="qio5Y/ng"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726868AbgIJQeF (ORCPT + 99 others); Thu, 10 Sep 2020 12:34:05 -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-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