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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AABAEC7115C for ; Wed, 25 Jun 2025 08:30:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50A3D6B00A5; Wed, 25 Jun 2025 04:30:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4BBAE6B00A8; Wed, 25 Jun 2025 04:30:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3AA786B00A9; Wed, 25 Jun 2025 04:30:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 281A06B00A5 for ; Wed, 25 Jun 2025 04:30:48 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D0EA11619CE for ; Wed, 25 Jun 2025 08:30:47 +0000 (UTC) X-FDA: 83593252134.02.685D929 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by imf11.hostedemail.com (Postfix) with ESMTP id CD86E40002 for ; Wed, 25 Jun 2025 08:30:45 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nLv4865c; spf=pass (imf11.hostedemail.com: domain of david.laight.linux@gmail.com designates 209.85.128.45 as permitted sender) smtp.mailfrom=david.laight.linux@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750840245; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HWZO9vBydLguvscfxtiLRMgmMbnzb9l8oTdYX/pGmn4=; b=nzazxrnP7hEzem0/syBE6ACVaPf/SE4gJercmLM1RJmSucez5O6WJ9ijbVUAR2m/ZYfmxs rZ4oa2winVw3XA+j6hgInyTvL45wagiKWfTGzp8/O3AKYKp2rW9BHEL1j2e0td6AjmA3AZ AYF8iWZVLsC084FFbY2izeCu0KSfpOE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750840245; a=rsa-sha256; cv=none; b=ldHZrUucNEhGkAnKY4HVk3FyWu8jiUtbK2X7ch4lXQft8HbMFxDIffDElzgM3Nkp4dCLy4 Jtw5udmFd4stPVC+3XerLXcWSWweUkHfybIsERECvDV7yhgfDf4lUOydOeEm5Vgd3RtuZH gU9nQLiH+1LWx6C6nbMXvOfAFosiGug= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nLv4865c; spf=pass (imf11.hostedemail.com: domain of david.laight.linux@gmail.com designates 209.85.128.45 as permitted sender) smtp.mailfrom=david.laight.linux@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-453749aef9eso5632275e9.3 for ; Wed, 25 Jun 2025 01:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750840244; x=1751445044; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=HWZO9vBydLguvscfxtiLRMgmMbnzb9l8oTdYX/pGmn4=; b=nLv4865cR9E9+QL7M0N8XpQP14ishi8WNbPwqyFijgT4my7qTvC2TKH6fznAndxC9B Cpfu5I1Kpma198LAxqFkQY6SZERT4z6DpCYyNjkeqIFUus/fgXUvCth2PTItFQSl/vli 75eggmAdoVPgPFToP0YjZ3kLD+EXvzvgefywimlA4gvQB45hJJMYRGuF5FF3in48fFaX OdfTLu3EJQkhngcoHmiM/2kC1jbTiPAK4lD08vcX5caJnXXD4yrXHRuOnl4sag/MiSoo yRO3eZEnzLY2cYCb7IpDhdcISEssEx6kpRpaXF9XXPdwhFpGfxhRBeybmb60tPIPsDcT gdmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750840244; x=1751445044; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HWZO9vBydLguvscfxtiLRMgmMbnzb9l8oTdYX/pGmn4=; b=OHBJo2jrLUYW8vpbBKxeGF9drzCesMrRUtEWatsi4H4mJAxWrkqSRwyftGlMIfiQP5 Vnd/aBJgvA7vEXTjc22XKkLSkWtM8jz+JDnj1mys/XyJRYbY8lXCn425YlV4BVm503hC nsCLgJmA6YP/kqVifWdjV1TiJNkJkvZ/4kLZnE7rBmTr8NKH6le2B0mwlf4Dxn8M4j9B /kZ3AfmliWGPgd9zV112V9SQgFOb6ZrFwtcIpI2HXk4GmFNOS8SthCEgvpXSyTtJwOWh 5RUmKBgO+gZ8KLEmer01LSQry6KHE9z8l+yFArlz7IbCSPOtqT7t0N/C/LRAi3PphxTh eDqA== X-Forwarded-Encrypted: i=1; AJvYcCVBtcRMVteBgUPxxTuGBBca/lJ2sWsMwmwLyWzy0dRbTeVeNj7dO9gaKszVOkhj6uXB9upTSg7x3g==@kvack.org X-Gm-Message-State: AOJu0Yw3UDvDwMEDS8XIUFKEZiIthxZejYKSugBWcHiR3A0BVloSO1IE 8J9SMTJAp/VQEBj6iaxNxZkzvKLVX5B5Uvu+txyCeRGecsiOJn99heqk X-Gm-Gg: ASbGncurFbLU8x0w8mRuYUS3rggB/JldSahen+OZtQ2nmy0Et1QeOtWEjnSbJnS4B5Y yuO1Kq7P0V93yydjXMZ+tDyymzCfOEDtU+G+U/mMIs8VRskg4XNBXu9fJDP1mcetdIBDTVVPFmk f7wymP41tiZJj98UKm9rKhe8AQB59fdXE28T2mhSHyy5m6a1v/CnhSdQT2C+ddV5WaC1fJcsQLH 9qVd3ElBailyM6KQOB//wBiRKq3xK4BTWDwiO3ZFFqySNTlqpxAZZ8copoUEFzW40JpxEVeOKqu tAOeVOqxm9DR4XPE9EGrnChZcNbDX1hYsZQghe8Ta6EGgXeBL9YP37PjZO3KnQgpuCNmmSNc5P1 MUAi6p16U6E6UYvgrdbyeCKAS X-Google-Smtp-Source: AGHT+IE9XkEDDWe5avnMKVyJiktIxY/anhzBr2iUjPbEYXho5HvfSLdB5xhpcwci6yKEnr3ElCb9VQ== X-Received: by 2002:a05:600c:4e02:b0:43c:f513:958a with SMTP id 5b1f17b1804b1-45381add658mr19874775e9.13.1750840244055; Wed, 25 Jun 2025 01:30:44 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4538327fed8sm4463545e9.1.2025.06.25.01.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 01:30:43 -0700 (PDT) Date: Wed, 25 Jun 2025 09:30:40 +0100 From: David Laight To: Segher Boessenkool Cc: Christophe Leroy , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan , Alexander Viro , Christian Brauner , Jan Kara , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Andre Almeida , Andrew Morton , Dave Hansen , Linus Torvalds , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 0/5] powerpc: Implement masked user access Message-ID: <20250625093040.7a7eaf3e@pumpkin> In-Reply-To: <20250624213712.GI17294@gate.crashing.org> References: <20250622172043.3fb0e54c@pumpkin> <20250624093258.4906c0e0@pumpkin> <20250624213712.GI17294@gate.crashing.org> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CD86E40002 X-Stat-Signature: ar6trgo7e7697ekjokytuu9f6gmbjcoc X-Rspam-User: X-HE-Tag: 1750840245-438246 X-HE-Meta: U2FsdGVkX19UzrxFnKfxQ6DdwkZo65ppYOntmUGuV+4g3Js9bsvgfTyPdfIB6s5K84TJjHrDSLqBj/1lKgHIU8DsI/5O+rs+HBsGXH/vxeEHdr6KnIRLOkOjsf6pWGWq7zkKR9t1JohFzOyIGRgGcZNqsIH0T44wgK4wM40AIjg398EQPq97rVVGlm4C3MNxAaeH+EMliIKVebSkl2kFksUAPhoNL1ZZcQ1T0P7CZyeaK7YPC4/ZWwtAsOa7LfJzFDUxwsfP2owhCP4iYBA8h0O3LRhgVjgDbQuRbvHK2aSSTFRE3Az6ihW8QodOXrsNo/Mgt+jqaxODsLBizaNM/bE9Wuko86fJvUU9jQYn5cEb33OZeCejNhmyDbXQr8Tgpg9SrR6ioN9Q2qPFubpfadNQNDlzNSjVMYqPYkXWZsN/jl88+nppCGLtGiXTrQAwrWUcvrhFUfgXyJfV14u9B3FJUS30pc+0ipKpCbqsrGh+4X7IdNCG3e5Ok8QtouzRXfaTywO4lson0ZBKrhnFEwRBHR48z4MEFpTTcabXxZGuwepr3C+jso3zxST9DwP0HMkSArlouXqB+Lagn9+8WMPoqz+Ug1cvmj1smBJu3PYR+kHgwFBFVtxIfSUGmJYVPnO9OxG8iuaTeE5gMnvmdQEm4pL8apTyDHYyV1bmPDBFLgVZhG649KD/3ODKHBP6jTHVLVrKyR9BAMdL7TDZz0KS7zh5+9+cE6YBsrXde43fL8BJwt5MBgh+p79q6wZRQRnhMpTFV0jN8rTsEwmstjyPYJoGscQTO53SzaxITI3v2oNiCm7O7lEIIQLAASlKuf79wHsojWk/UkF8bgRGf8yHxmPJEK7kSVcpcBqBwnJ61XOoMU6coRVyYgvWdXrYkch4Fuq0xlNyw4Mu+P2PY2eLPq4KNYEYDinugZGD5pAdWZXzgjDcBCxU5xwYA5au/YsNOlo7JZv5Rdc9Mtg vZ4d8Tkw c92DYQLhpJvED/PNdLjPEWp/wsDzmnZt+z/EvL3qZRvzqNJHPhnJfoCfP4TyIORLNX9yJWk9zFcHsZ0sen4OtvS8Y9aHbHRejjIvLivvAfgFAUDSTPbAtj5o9b0y0PfREPkt3aArVPBOde04qkXPSJKjJ9+WGc9q8uxmfNJxy9ErE452uOgIMSOiNM50bBh31+O3lxaBbgKLmqoKTJPum0qs+D0t62mnHmdJeVLWzJy4XL+bpm7XWPGadCAMOZGixJJOfcg8gXeueHmLaT6fVFj8SvC1NcCHCN5qT4dCR0hcjFwemVBgAd32YfBy/nr7AfLF5dW5NnfVMXYbi1+2SurTv3kn1x8zO6+XzXbieaXSKI0pevBXJiRl9swF6T6MME0haJs4Mehm/Z0Ux/ZxpYELyOW++cEPPVDbl+tBDsoULqdVuQbp3mHOYQDJCI3qnQsaFOnlpkvkW4zqm0hcWV3U3L7iIrMy5LR4qtNPeDldShh4= 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: List-Subscribe: List-Unsubscribe: On Tue, 24 Jun 2025 16:37:12 -0500 Segher Boessenkool wrote: > Hi! > > On Tue, Jun 24, 2025 at 09:32:58AM +0100, David Laight wrote: > > > So GCC uses the 'unlikely' variant of the branch instruction to force > > > the correct prediction, doesn't it ? > > > > Nope... > > Most architectures don't have likely/unlikely variants of branches. > > In GCC, "likely" means 80%. "Very likely" means 99.95%. Most things get > something more appropriate than such coarse things predicted. > > Most of the time GCC uses these predicted branch probabilities to lay > out code in such a way that the fall-through path is the expected one. That is fine provided the cpu doesn't predict the 'taken' path. If you write: if (unlikely(x)) continue; gcc is very likely to generate a backwards conditional branch that will get predicted taken (by a cpu without dynamic branch prediction). You need to but something (an asm comment will do) before the 'continue' to force gcc to generate a forwards (predicted not taken) branch to the backwards jump. > Target backends can do special things with it as well, but usually that > isn't necessary. > > There are many different predictors. GCC usually can predict things > not bad by just looking at the shape of the code, using various > heuristics. Things like profile-guided optimisation allow to use a > profile from an actual execution to optimise the code such that it will > work faster (assuming that future executions of the code will execute > similarly!) Without cpu instructions to force static prediction I don't see how that helps as much as you might think. Each time the code is loaded into the I-cache the branch predictor state is likely to have been destroyed by other code. So the branches get predicted by 'the other code' regardless of any layout. > > You also can use __builtin_expect() in the source code, to put coarse > static prediction in. That is what the kernel "{un,}likely" macros do. > > If the compiler knows some branch is not very predictable, it can > optimise the code knowing that. Like, it could use other strategies > than conditional branches. > > On old CPUs something like "this branch is taken 50% of the time" makes > it a totally unpredictable branch. But if say it branches exactly every > second time, it is 100% predicted correctly by more advanced predictors, > not just 50%. Only once you are in a code loop. Dynamic branch prediction is pretty hopeless for linear code. The first time you execute a branch it is likely to be predicted taken 50% of the time. (I guess a bit less than 50% - it will be percentage of branches that are taken.) > > To properly model modern branch predictors we need to record a "how > predictable is this branch" score as well for every branch, not just a > "how often does it branch instead of falling through" score. We're not > there yet. If you are going to adjust the source code you want to determine correct static prediction for most branches. That probably requires an 'every other' static prediction. I spent a lot of time optimising some code to minimise the worst case path, the first thing I had to do was disable the dynamic branch prediction logic. David > > > Segher