Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1031227pxb; Thu, 23 Sep 2021 16:29:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5tXYBV6OS62pA7nGZPAeJGyerUoy3jb0Qn54ve8fxVCFmKPmId1fKcTVWw2ThDm1gjTRg X-Received: by 2002:a02:cf83:: with SMTP id w3mr6492504jar.38.1632439767572; Thu, 23 Sep 2021 16:29:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632439767; cv=none; d=google.com; s=arc-20160816; b=csW5aSsfW7m4LQZl8PQLq948OGsxADQOxUPsQkucFeI+aluXaVsuTvJ+M/i/jDhAkP UZczxjwRU65XlOA9dpQPAXQ6/u24LE5/ENzwPaR2eOLERT61bLQn5TgHnzw2Egeqx0io T96HkY/Et1uN8U9Ps9t7hkGy3h+PQr027pnIEWyBaTEV3TcvekrjyMwrvHzLfnP9WLx+ hGOET9Mj6XLKjD1CBUZ2Tme9PoVBtMkmH8C4OzhHaAFzA8sWyy++/pH/rDgTg52gGjm/ X46NAzn+15uG4s09UIrDUvp8r8wqdjsrr309LR3a0MpZCRTnR6dquOBUnOigLTRfVTqB iWWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=UoYtoTmstwML8ZYwPoyxeKRDOk9ZLn4Jb/LikJefzXM=; b=RWuDoWUcALCnBKcr2uzpavL7LIr5YPV8FbEpdrz8l3oSr4WaUX5aMvGtbZq6D9nwgk QHVg/BrX9E6+cQetennGD/9XzzeH1XaJvynY+rWt6aXO6fKFgXfc+MntUtGipbYygXiC qgwS4XEHD12ViL+WbCBjck+BELpniYKr6onis7jGI8UgD2l632yjobAKp4OqjlqSMcVe hHRRXIbMln0qCfBW/gwomR4ze4BUcSSa8V7JdmyPJNUYX8yAXBm68YMihPn6NeCg+Hei JfnCURCoNsRofTqnxAoXTXeVNQVhKBZLwfm+Crq4XSDYYzL4HFAgI7qEu8WkPFSO/yX9 +V1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=QoqOFG2q; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si8315030ilb.43.2021.09.23.16.29.14; Thu, 23 Sep 2021 16:29:27 -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=@linux-foundation.org header.s=korg header.b=QoqOFG2q; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243400AbhIWX3p (ORCPT + 99 others); Thu, 23 Sep 2021 19:29:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:46778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235628AbhIWX3o (ORCPT ); Thu, 23 Sep 2021 19:29:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 60AC760F43; Thu, 23 Sep 2021 23:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1632439692; bh=1MbzwBSkc1BV2l0Q1eJRZ5r/+IJZfOlfncEyBxNFNc4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=QoqOFG2qw3bM46IOzMY71mwInBqJkHG8+OaD0tKjys3CTuJIyHgxVXlvJAYMas12F F2HEy8YxLuWFAhnHc31JAym5Ugkr3ZCQlFde6FPJ8lsV9Yc0HpPGIYxBYHz/UUrYoH TvCWm5q1iXTxSPSnTlHJezXskmBuR96UAL4grWhE= Date: Thu, 23 Sep 2021 16:28:11 -0700 From: Andrew Morton To: Marco Elver Cc: Alexander Potapenko , Dmitry Vyukov , Jann Horn , Aleksandr Nogikh , Taras Madan , LKML , Linux Memory Management List , kasan-dev Subject: Re: [PATCH v3 4/5] kfence: limit currently covered allocations when pool nearly full Message-Id: <20210923162811.3cc8188d6a30d9eed2375468@linux-foundation.org> In-Reply-To: References: <20210923104803.2620285-1-elver@google.com> <20210923104803.2620285-4-elver@google.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 23 Sep 2021 15:44:10 +0200 Marco Elver wrote: > > > > + * time, the below parameters provide a probablity of 0.02-0.33 for false > > > > + * positive hits respectively: > > > > + * > > > > + * P(alloc_traces) = (1 - e^(-HNUM * (alloc_traces / SIZE)) ^ HNUM > > > > + */ > > > > +#define ALLOC_COVERED_HNUM 2 > > > > +#define ALLOC_COVERED_SIZE (1 << (const_ilog2(CONFIG_KFENCE_NUM_OBJECTS) + 2)) > > > > +#define ALLOC_COVERED_HNEXT(h) (1664525 * (h) + 1013904223) > > > > Unless we are planning to change these primes, can you use > > next_pseudo_random32() instead? > > I'm worried about next_pseudo_random32() changing their implementation > to longer be deterministic or change in other ways that break our > usecase. In this case we want pseudorandomness, but we're not > implementing a PRNG. > > Open-coding the constants (given they are from "Numerical Recipes") is > more reliable and doesn't introduce unwanted reliance on > next_pseudo_random32()'s behaviour. Perhaps we could summarize this in an additional comment? Also, this: +static u32 get_alloc_stack_hash(unsigned long *stack_entries, size_t num_entries) +{ + /* Some randomness across reboots / different machines. */ + u32 seed = (u32)((unsigned long)__kfence_pool >> (BITS_PER_LONG - 32)); seems a bit weak. Would it be better to seed this at boot time with a randomish number?