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=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 BDAA0C10F29 for ; Wed, 18 Mar 2020 17:36:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6461C20724 for ; Wed, 18 Mar 2020 17:36:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=intel-com.20150623.gappssmtp.com header.i=@intel-com.20150623.gappssmtp.com header.b="rY4QT/QB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6461C20724 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BC1916B0007; Wed, 18 Mar 2020 13:36:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B72CC6B000C; Wed, 18 Mar 2020 13:36:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A87C36B000E; Wed, 18 Mar 2020 13:36:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0112.hostedemail.com [216.40.44.112]) by kanga.kvack.org (Postfix) with ESMTP id 8E7FA6B0007 for ; Wed, 18 Mar 2020 13:36:24 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 451D4181AEF10 for ; Wed, 18 Mar 2020 17:36:24 +0000 (UTC) X-FDA: 76609187088.13.eyes78_8f2bcae546641 X-HE-Tag: eyes78_8f2bcae546641 X-Filterd-Recvd-Size: 4531 Received: from mail-ot1-f66.google.com (mail-ot1-f66.google.com [209.85.210.66]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Wed, 18 Mar 2020 17:36:23 +0000 (UTC) Received: by mail-ot1-f66.google.com with SMTP id a49so23622918otc.11 for ; Wed, 18 Mar 2020 10:36:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=u0zkD3tZw1FM3vDbuJZBQPF9ITCV3BomRMsux+hpiws=; b=rY4QT/QBwB3hVhCNuKmfTfryb+wI7pQJMIZ+2cQsv7APw5irIgZEgc8KjTUsppIw8R 7t8IOEvJNaNe0/hdCOtizwatecq2CJveBzTuf9nOM2Tz7DMaaQHEhzhxRLPD5V3vKxHY KfnxdvY0JtjzbBKPc6T0neET7rc6ryAZIxtP84K/Ob3g2nNwe3pMzXFQsjMAV26Z7+Qk Hf7CFWe5IYl5yccvF0PgqAXf6T1oZ9MfDy2GPLoUOyjkcBAK/26jgZZ8/RmiLUH6WRGY fMDzqlDheFanepT9k5Ru97tuNMSksV7rKPz+GHzlxovtd7Vckvd1mJt4e6Oj+gJ++1Bw RWNQ== 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=u0zkD3tZw1FM3vDbuJZBQPF9ITCV3BomRMsux+hpiws=; b=Nc4y8GXWjkVGUVQo9Cc3dun/CKxrsXSPvYLrLMmyWWJYhJYcyEbIe4lPWQs6eSGWVY Iqnbck2ovYcpGZANI/2zTjy9Z/pOM9h9vEWNg8Iecrd8GsFsiuhleBGxxRf/W3d3rLRV Iv5FXd7mJHCz5CZ1hxs56wDiH4dqtHPQkt295F+epbW5CBHSJAQKLHbqeTuZzSRW7bRU n6t9bStPlAkdNrYoiesbQuf3894k4V3I7pQyu1zQ/Z6o583T8L+E7N7j7IQFf5pWLQTH 4heewRxXnn5Rj5fZz0jIYG30qt/V40DzvJ7SfsEtwW5gFHxyANm5tNKzvp7ZlTh37Zo3 tCpQ== X-Gm-Message-State: ANhLgQ2ZqDA/n3XifR1aSl3zYou4GIO3QMqPTnf27WzDujUDcjR/8dfc 51b3pPC/B2Dy8NVRnsIhVz+YI7wDBCk8AQ6NAlSlhg== X-Google-Smtp-Source: ADFU+vsexsUFNttN5rv6/8nvNx4lkcuuPI8wlLD11qIID+xeB+QWuzqYD5qUo6Pp3hpXCjiTgGtu8LfKngMYI9mor6E= X-Received: by 2002:a9d:6f07:: with SMTP id n7mr4604116otq.247.1584552981775; Wed, 18 Mar 2020 10:36:21 -0700 (PDT) MIME-Version: 1.0 References: <20200317135035.GA19442@SDF.ORG> <202003171435.41F7F0DF9@keescook> <20200317230612.GB19442@SDF.ORG> <202003171619.23210A7E0@keescook> <20200318014410.GA2281@SDF.ORG> <20200318082035.GB2281@SDF.ORG> In-Reply-To: <20200318082035.GB2281@SDF.ORG> From: Dan Williams Date: Wed, 18 Mar 2020 10:36:10 -0700 Message-ID: Subject: Re: [PATCH v2] mm/shuffle.c: Fix races in add_to_free_area_random() To: George Spelvin Cc: Kees Cook , Linux MM , Andrew Morton Content-Type: text/plain; charset="UTF-8" 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 Wed, Mar 18, 2020 at 1:20 AM George Spelvin wrote: > > On Tue, Mar 17, 2020 at 08:53:55PM -0700, Dan Williams wrote: > > On Tue, Mar 17, 2020 at 6:44 PM George Spelvin wrote: > >> - if (rand_bits == 0) { > >> - rand_bits = 64; > >> - rand = get_random_u64(); > >> + if (unlikely(rshift == 0)) { > > > > I had the impression that unless unlikely is "mostly never" then it > > can do more harm than good. Is a branch guaranteed to be taken every > > BITS_PER_LONG'th occurrence really a candidate for unlikely() > > annotation? > > I had to look this up. GCC manual: > > For the purposes of branch prediction optimizations, the probability > that a '__builtin_expect' expression is 'true' is controlled by GCC's > 'builtin-expect-probability' parameter, which defaults to 90%. You can > also use '__builtin_expect_with_probability' to explicitly assign a > probability value to individual expressions. > > So I think that <= 10% is good enough, which is true in this case. > > I was tring to encourage the compiler to: > * Place this code path out of line, and > * Not do the stack manipulations (build a frame, spill registers) > needed for a non-leaf function if this path isn't taken. Understood, I think it's ok in this case because the shuffling only happens for order-10 page free events by default so it will be difficult to measure the perf impact either way. But in other kernel contexts I think unlikely() annotation should come with numbers, 90% not taken is not sufficient in and of itself. You can add: Acked-by: Dan Williams