Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1256941pxk; Thu, 10 Sep 2020 10:47:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQqTvOHVxcGyy3tr8YPynf5jsmQS0hniQEH22TAsrn5LgOmhSfkPlKz3spTh7RhA2cM+dL X-Received: by 2002:a17:906:a251:: with SMTP id bi17mr9821275ejb.526.1599760048708; Thu, 10 Sep 2020 10:47:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599760048; cv=none; d=google.com; s=arc-20160816; b=hJcP2DBuSuWNoKa7feLVaS88tZsa3FjBkGcp2qnIohzbl4+zHtoHgJV+kAg7PuQkLN dbTOcxCKpol5wHsWborXhYHZNpZVXgzuLD+6JYEXzjsoX5j53a67vuUdoP2ZxssFG9Ob aG7BtQEMuGtkwPMpII2MOS9EzvRwY5e6MzN5Gs5B6rico8gUk99X6hl7QpkWQ86Jwywk igkCySlAQyp1rf3KA2AeRordMdqRRgZDZ6HVyHHXY7kSfXbyC9dXnkNGpdb5GT21Xjst DHB3OYEGf+A+zq7itid9qujbmsxiLSdpPEBGV6dPxp/oRYd/Umvy7Nh+T4x9sqG4TPEU 3Jsw== 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=4ATdJdtrrGQs40AB3pAJaPiKELI+qIaGQiGwD413skg=; b=EV2ZaJqb3rftq8Ybaro+Ec7cl2oHsA0hdHNc23OUuJNEcZo0g+dCHULho3/O0nS2Fd fmWkQiOVa5AyM27qqMWMeY5UKk5z959tNk2xEPKUQr24e7U5/24aJY86Z54kW7RhLbH+ Y45g5ngU3ZItS6kAufxWqDW0Q2PXhTzqtUfApG/ZTVGJwhh5aGUwExQh54s//g7SZLzd kFjNGH1NGuscqKS9VW7uuBJLQ1F54oqf7IXPdyY1QMP3MZIWn2c+x4KR6P5NRgNWaBBg gKIjjI3x+ECMpdrum2bZlMR5bW6rrzUzVmXqiwO+3+xl04qFX75QVH99IjfpDjn32U71 vkQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=s1IboDV+; 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 d3si4319949edv.196.2020.09.10.10.47.05; Thu, 10 Sep 2020 10:47:28 -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=s1IboDV+; 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 S1727025AbgIJRma (ORCPT + 99 others); Thu, 10 Sep 2020 13:42:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726728AbgIJRl3 (ORCPT ); Thu, 10 Sep 2020 13:41:29 -0400 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFAACC061573 for ; Thu, 10 Sep 2020 10:41:17 -0700 (PDT) Received: by mail-oi1-x242.google.com with SMTP id t76so6705937oif.7 for ; Thu, 10 Sep 2020 10:41:17 -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=4ATdJdtrrGQs40AB3pAJaPiKELI+qIaGQiGwD413skg=; b=s1IboDV+5v/GRORnn7PeYV0l5Wu9lL1nSqTQFlmFaPKFJLXtecqcf/fF8tE8/TBzFO wwko5dfbZDLn4eQwiMdwMtaeAwbxcyMcNSrcmwcMOn3OhK75W+2R0JMdzJurCcZrbJkP Aj26foauya/lB6hvQxoJ9UV6SIiv7Wx7xQdQab6tQZiOH9gLwtyGWJ0sfxvcTvHLfm+n tsSey7Dl8WMXWipZQv8iolcq6jQBRRRGCvoNk4C55Q5vbgBS3P+t47LwGafvHf+8cbD9 tEYY2rXnyqBrxsujG5V89lCiwKjUHnQBSjuWeBKEtLaiZF0sc5GaRbmgOg3XZZyh/Aq0 b5bg== 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=4ATdJdtrrGQs40AB3pAJaPiKELI+qIaGQiGwD413skg=; b=X96dTxySnmCGdKnwLWAdZD7V/WaCfazVZWksTW1dBzdJdduInDhpQy9WA3BNtmca/h G2M7pf8/wgIQF94fv4jS19WyS1kTxjpZpGe9Ldu9KvETGI0moE1H7TdMetSB/gf7SZEb fW2o18ZVUn71JJCe2Iw+ych5jfLjJd2Hmz/liZvlTRxj7rBnfH98ANFHMh3+oOKOYlP3 IYvhej7rm7/F3gA6z9hfuMd65N7dOuxozyeJ33E8KkYl3UzhI646z/VeWrGbqMyf3aJM 2ZMupIk0Zf+c41OEJJVmo7KNzjNzxXltZzdgZBrfaIbRpquncaNW33o2eH/6yZoxMD7v i4VQ== X-Gm-Message-State: AOAM531sntyTSsZY5R2xIPUd9JDu4u2UlX8twwGEnqcGOonaL0H6JvHZ qhDc/WxHdXhB+WWFSbwnlORekUDiK/Yqst7XUl3ImQ== X-Received: by 2002:aca:5158:: with SMTP id f85mr709168oib.121.1599759676956; Thu, 10 Sep 2020 10:41:16 -0700 (PDT) MIME-Version: 1.0 References: <20200907134055.2878499-1-elver@google.com> <20200907134055.2878499-2-elver@google.com> In-Reply-To: From: Marco Elver Date: Thu, 10 Sep 2020 19:41:05 +0200 Message-ID: Subject: Re: [PATCH RFC 01/10] mm: add Kernel Electric-Fence infrastructure To: Dmitry Vyukov Cc: Alexander Potapenko , 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, 10 Sep 2020 at 19:11, Dmitry Vyukov wrote: > > 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). In the case here, we have to defer freeing the object, because unlike real SLAB_TYPESAFE_BY_RCU slabs, our page here may get recycled for other-typed objects. We can update the comment to be clearer.