Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1236635pxk; Thu, 10 Sep 2020 10:15:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZaT29byw5ZbuEYHKpxkSuFbKlXOAwTxc5qKoOxr1DL+SNu4ubkTUDf7C2p9M1HpgGQcHA X-Received: by 2002:aa7:d403:: with SMTP id z3mr10107944edq.310.1599758116359; Thu, 10 Sep 2020 10:15:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599758116; cv=none; d=google.com; s=arc-20160816; b=EhJIl/1XsdPv6aIc9QMSNJn16DslAWl9A0GEg+tHl0A/3SurV+TYMF0MoUedDFMPJH sVojxmdfD2/GxxvtVxSZQIG8A4rvaFuizSsCx9P8mGMXU+DE5V3LUgp/1tHtaTJLrb3k uR/pLtKbVg5gqnNkKfZxNcTkMVHV9paTYl9YTiZNjx3CJusbmsP4WD4i6qfscDW5qbV2 MkK4jWGDDJNz2jzSq7xjiyBEr6AVO02+Y4mM1rcx1gxkWEmkfy2sqBiORTXDmH+mkEHJ b54N57w5ixTXNOPgSu8WX0kcMswYMOB6AGV9af/vJIYeQ/E8ILlw4mFw28EiKa8//79t PZMA== 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=8vk1P98X5wFislYUCmYAXFRXimxyGQmLmxtAeRXAYBI=; b=KF+2A0hGU7DJfGJv0BiJ3OmsHOJGR2ve09N4nNqFjwTudF9JZGUvTiPmNYMYbbwono M/32i3cfYq+hblLu156Hx0TkWR397UpEAr+WOBCdDFYIlqrUkjqehEgpR/Vg0uRdPqTv xeFwXeMMIO2qSL7fjZXGkYvsbWTH6h8k5dKa9d0Z8RawHQAJ6SLYjihVSr6FN5PZ3Keu +bQCyiD82Lrju2vmC1mf9xIJhP7n1y+KWqM0C9b+mf8wl5qs0xlP74/J7FsMS9c2HO3G hMbcboZT7ygjU6iRv9YGJCQX5Snr/LCJ3g+djpuQQMpbkJYpsnCvwHR4MuDQJmCpFS83 XZLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dJ2eDS6O; 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 k14si4181083ejx.254.2020.09.10.10.14.53; Thu, 10 Sep 2020 10:15:16 -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=dJ2eDS6O; 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 S1726776AbgIJROM (ORCPT + 99 others); Thu, 10 Sep 2020 13:14:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726922AbgIJRMB (ORCPT ); Thu, 10 Sep 2020 13:12:01 -0400 Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9259FC061757 for ; Thu, 10 Sep 2020 10:11:53 -0700 (PDT) Received: by mail-qv1-xf44.google.com with SMTP id p15so3171592qvk.5 for ; Thu, 10 Sep 2020 10:11:53 -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=8vk1P98X5wFislYUCmYAXFRXimxyGQmLmxtAeRXAYBI=; b=dJ2eDS6OYx+Rr1FutsvSR3n0fKpYmBxf+wOjWwihbER0Mw3BpAiGD3a1kT4fo1a656 V80AfRGIV99omd5ddL5JXBPXJpatkmQWDKWjGcSi3nGAYjSpVDMG2pZu8Fkynp9EzdjX 2/ZYKWFE1At3yPuYVv1KopWAn5xo8pS001kqzr2rly3W3jrkKbttTPtkG2EYUKUj4EGt MHWogp+BNZlsUeqAcYg4Aoal6ThfyH5NVr26hIbvK3Mt8XY3Y5C7MiXhyp78D251+52b C8d5kNgjGwTl6Xk71d0Q0zyx2a8aj5SlpPUBsKpl7rd0oX916/kxRsgG0UC0xMBgkc6E U4WQ== 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=8vk1P98X5wFislYUCmYAXFRXimxyGQmLmxtAeRXAYBI=; b=KoDr1P79dr5EBEU7duK+WwR0DLzXAglOSO1lLgOK5wed0jWKf1Zlw6XuUunIhhX5nQ pLvNzauFQ9/y5cth/BkoKlZFEqTOSTEVGCoK8FNSGVE7FAgLsZBUuncKuC8OUNBhoJox 0/xP1ncT1IwkWfJvlspuTisU1dsCgOhQoLOCvRr0cBzNYbuNyHtLcM9J2b0/8Cy5yTmA xx4ralB6pn8H5sK+9w8ScYJ93phY3+n32BE+Nz3VTvfzJheANMvbtPwX0wg2zFzqUkWQ VjHQmbqza0MLm9wfj2ZFINnzfks6n2BU0FbPsDLJB0edVGiC0psnmJsrslJKvums0eMB 8iIQ== X-Gm-Message-State: AOAM532+kvRIEzHb64nwUXS5faXguminUWG4gDbfJAQYtVBn73ERcYv5 LOho1Lm+hW/jIWAUwdNPkiAJEaH2gPaVuj+6InivWg== X-Received: by 2002:a0c:f984:: with SMTP id t4mr9654083qvn.18.1599757912407; Thu, 10 Sep 2020 10:11:52 -0700 (PDT) MIME-Version: 1.0 References: <20200907134055.2878499-1-elver@google.com> <20200907134055.2878499-2-elver@google.com> In-Reply-To: From: Dmitry Vyukov Date: Thu, 10 Sep 2020 19:11:41 +0200 Message-ID: Subject: Re: [PATCH RFC 01/10] mm: add Kernel Electric-Fence infrastructure To: Alexander Potapenko 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 6:19 PM Alexander Potapenko wrote: > > 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: Exactly! You see it is confusing :) SLAB_TYPESAFE_BY_RCU does not mean that. rcu-freeing only applies to whole pages, that's what I mean by "slab level" (whole slabs are freed by rcu). > > > + call_rcu(&meta->rcu_head, rcu_guarded_free); > > > + else > > > + kfence_guarded_free(addr, meta); > > > +}