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 8E3B5C7115A for ; Sun, 22 Jun 2025 16:20:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCC076B0096; Sun, 22 Jun 2025 12:20:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA35B6B0099; Sun, 22 Jun 2025 12:20:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C919D6B009B; Sun, 22 Jun 2025 12:20:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B38DF6B0096 for ; Sun, 22 Jun 2025 12:20:51 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3D8D114082D for ; Sun, 22 Jun 2025 16:20:51 +0000 (UTC) X-FDA: 83583550302.07.0A4574B Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by imf20.hostedemail.com (Postfix) with ESMTP id 3BFD11C0006 for ; Sun, 22 Jun 2025 16:20:48 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LBb+t+ye; spf=pass (imf20.hostedemail.com: domain of david.laight.linux@gmail.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=david.laight.linux@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750609249; a=rsa-sha256; cv=none; b=x2/uu9dCxcWFYaU1HE4mWyF4WX1NQZXd0F/2wa35OSwse1qo0WMNHl6EAxKDx9e7AWSCO6 I0rEyEbrkoWQLVGvcPNhl+ccjO2QpFoaqorBlDDsY/nXocZUMsTvGgY7CiZ9QJhjb19Q4b V/VUdie4eng2kmHDnm9lJpbubWjSOkE= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LBb+t+ye; spf=pass (imf20.hostedemail.com: domain of david.laight.linux@gmail.com designates 209.85.128.48 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=1750609249; 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=h9UguERxuhFrRUQfvCGEwWcq0+7rxY/z2LNMvf2rwsc=; b=fqQjVlcRd7UKwnhSGPztEA8kEk0PoZQYhothC1g+eCqNgg9banUFeSihdgeB1d1cZPoNDk A+3bwtDf9SqzgrYpGVVN0OP0Ns6X4aljoTx0YzvfaHhnE5j5zEI483Gf2hGbW0ulo4q6Ty iVgHFITwlAgA8MzlguWKXFEmcNLpPJY= Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-450cf214200so30757635e9.1 for ; Sun, 22 Jun 2025 09:20:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750609247; x=1751214047; 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=h9UguERxuhFrRUQfvCGEwWcq0+7rxY/z2LNMvf2rwsc=; b=LBb+t+yeZsbmFseQprQTyJ0keelnQWTElmkc2v3aQuU0oaBiT6Ak64xeblBEaijK1N mJGpISPse8u8Zc3fuCTnAVMhd94fRH+g3zhk/SURSBjA8VTPRven2NfJ0ZXPJbk/5/kc UG/yfUpXfrAUE/NWn2LApG5GYhmj96nfrRbwwUDOQ1VcZtrBxUEsC23tVwtHOzPJEqrF 0QlRm+PvbVkRYHGMfwSepUmLMaiSpteb8XeskIDLTCFYNozN3QMabfRypvTSdPvkEBx7 /O01NBWJuZJkrFQ41FosFOGtzTl2/PWxsGeGeF5KyYGLtqXilpjlQI/XPkQpExTa3NcW jTbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750609247; x=1751214047; 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=h9UguERxuhFrRUQfvCGEwWcq0+7rxY/z2LNMvf2rwsc=; b=jaf5yY41rAXxjrNDrx2JOAXm7nkn+ZpoJC9A1XFwseP8UgzkDX8+TbIowi52qixTIw eU/Rn7yaUCBk7fvNnQlRQK5aphlXfxuDFyvW4PXFIxilz0BZfmYAMfS1MORFmgl4LkDf DGCJyq10pb5fo23J+riRcRS/pfYRV2GSZcrr4G7wBcuuF+32+E5PeTO53ecUs3Gb1Uof BNFQeMxDbQ5TJoim3uHdPKmYgOAs5Ql/m/3efQaX+KXMfAiTCOBi0dUsQ7rmcFpbTP47 52VswhwrcxMp0fb59ctty8SgFw5ofiPbCniedgQXXfyYRGyri2tujxOWAMWUFpd9HeEX 6jSw== X-Forwarded-Encrypted: i=1; AJvYcCXFwzySCgsF1pNU3LqJEC7nsCT6zHoUgiz+UK+xzsoDF2ZJfFuAGuxGeIBL0htifnKs4/Ruz3YmWg==@kvack.org X-Gm-Message-State: AOJu0YzfjQ5PdLfF88IjeI3nxRYa42AxWWq0zudfe3U6f7ZsGMAXqOHR YFjJhmUmj3/QHqVq7bamXopNVT9eXbKPBbE3ULktlOoN7+XvTRhMe+4l X-Gm-Gg: ASbGnct0TkP0YhFUr0yjEH6dQ748bOAy7a7/166IktJiJ48d2PP4kj+oR4vkT4wWiVK zNzlVPmeDQxnRs0UJ14bC4lPCHN+/W/UFpSLWaDsZidXMb4Z77wJCorgO4kUdTfeGBP6jFAwTNP uOUwAWE3nUpienDf7UDDBVxnRtumXTnhC88x+anDhFlKHEItcLC6iy/7Nv6UmxwblOwsBIe8QC7 NUHM57/RtV7wyuqX2rvHZ+B0mXkad9iwsi0jj2XDC34IAsh2/82Lvf/6ABvP77XKCMnx0zNU+RZ b172lLY2l6Fk5GloE9PGyVTg1paC8FJqCFkdf+4AX+yLlc7ATivvITU+v74MHBzdTbAlB/wMe5r W7x4nwDSLCdZI2kx33mu9C3YN X-Google-Smtp-Source: AGHT+IGm8Jkkiej/C+jG1pvkrtKONtBC9in64FwHFjGEl4tQBWrNcO7v48A3YibfheGLyTPhwgFPNg== X-Received: by 2002:a05:600c:45cb:b0:444:34c7:3ed9 with SMTP id 5b1f17b1804b1-453659f8288mr77140725e9.26.1750609247175; Sun, 22 Jun 2025 09:20:47 -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-453646cb57fsm85091375e9.1.2025.06.22.09.20.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 09:20:46 -0700 (PDT) Date: Sun, 22 Jun 2025 17:20:43 +0100 From: David Laight To: Christophe Leroy Cc: 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: <20250622172043.3fb0e54c@pumpkin> In-Reply-To: References: 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: rspam05 X-Rspamd-Queue-Id: 3BFD11C0006 X-Stat-Signature: ak8m85d1qnpsxdcwbc8oxd4mjxt63y3y X-Rspam-User: X-HE-Tag: 1750609248-820074 X-HE-Meta: U2FsdGVkX19p3dOLF29wOj4cVOku16lqXtDvTDOhAdW8k1wTMq9hpMakKPRLw/m+J2gcN1yoAZSSt4RP5qhaPuWsgtf0V4W2gO28iBxBG4iPTzYu48Jsqzgka91cn4t6UWYmbvdQ1avPM49bwqPD/Uwl4sN6LxL7vMPQAUxlZVcxQHkG7hTwFkk8+RLHjl1xtXd09Ov+sRTsKi1RG5I5MmX1G0+ZX0edHn/GUCBI7HgTWwhN0Xj1QNAXgN6u8PmDq47AFdYkqRXVzj13qwLjA31I7p0jSSBje/LVgYKr5VZP2H36lGRABuuS3fE3sz1iAt4+QhGDc0vDPrBq8tQCma8XF8UtzzYxRnVHDolAP3djBZ8qKpiVlsn6M/o6xOvTbQ0qyOGr9ujbmuiGI6QWK5HQqvMJtmhLP5SpiNCMMhvaRRwUAz04ja152Wci25X2RqoANZfz865PWA/p+bRxFn7ufMjcSPE5Gxt5RTu7Wm1RK3QVyby8j+HLfWLDS8Jd/C6OTsc32azM06tHMI2Tjxw1wduOLYKXdby7sW9b47VUkuK83+pY3S2mkIZg+YQ/qupe+kSuZuZi4e9VxNcu8ttPbHokoLsIHVQBLPkZw+M4jIS9gl19CIGs+RRRP5sb7TILKHaCMLhbpjfIYIv4KOP2gdSMP7GSnrV1KaD3leJV/Gl04YbXD2lpsa6Z/qWbZaCsEbE7OmEIsaVTsn0BB/BZ9vtF8p18GZ/pGcNaPk1acc2N4g5xl8O+WJVLFBeaVaIATccIYYS42lHzgN+LX3vpk2MjYiJ4b0EaRD2/CJ08vROiQU6xCO/OwjwwkzVkqXCg6hY+9l6140T3MzSBeQ1WZr2C297LXewGIR4eJQGbCdbMSSUp3oH/Jb9MBv+5y7R7h9PbyIuYsQsMzMmc1lOsJpD9aSDkNm+ODu3BDqQKb5ZPFcsl8syGtyQwMRL9il+pkpLcVGzOJiEYZru GR2UaLNB w5KjE6HQMeWOikwb9GTdRT5G0EFZT1/TOOrDbLECasNAgWN3xZBM6PxnB3LkcPbtGmUY9am4La74Ipsj9gOr8Q+2egsVM9A+JRUqgRN9/JlK5vgvr5En42tq4CIU3+yVvvCYuOXH7eWyn2FwpFg0H62ZGFIJJOH33lON340x7tHO8+RPLmbLDo6dqngZ+3CBKqM+/lEfMyaTBG+CObCcNaRrk8VVkClnZXqFR/y1j+LQadwwGe68tS2D9D1mcB5U1a5OGZCd7yCDRhbNhR2wjT5KOUXnP/EKaprNjir7Mb+i1qAJs9duAkuqLnvieiZVwPkeZdoueMWdz70m8lyd9Yw11a7EoG0guvSNiV3wS8b4bJ5CjmMq+333LB/iviING+F3QH+MjSM/YRqfHXkW/jtoNeeXZx3+7gYj0BRhOB6wPzQXnHY92ZYIr4EZEg3LjCDifk5pk68ex8YY= 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 Sun, 22 Jun 2025 11:52:38 +0200 Christophe Leroy wrote: > Masked user access avoids the address/size verification by access_ok(). > Allthough its main purpose is to skip the speculation in the > verification of user address and size hence avoid the need of spec > mitigation, it also has the advantage to reduce the amount of > instructions needed so it also benefits to platforms that don't > need speculation mitigation, especially when the size of the copy is > not know at build time. It also removes a conditional branch that is quite likely to be statically predicted 'the wrong way'. > Unlike x86_64 which masks the address to 'all bits set' when the > user address is invalid, here the address is set to an address in > the gap. It avoids relying on the zero page to catch offseted > accesses. On book3s/32 it makes sure the opening remains on user > segment. The overcost is a single instruction in the masking. That isn't true (any more). Linus changed the check to (approx): if (uaddr > TASK_SIZE) uaddr = TASK_SIZE; (Implemented with a conditional move) Replacing the original version that used cmp, sbb, or to get 'all bits set'. Quite likely the comments are wrong! I thought there was a second architecture that implemented it - and might still set ~0u? As you noted returning 'TASK_SIZE' (or, at least, the base of a page that is guaranteed to fault) means that the caller only has to do 'reasonably sequential' accesses, and not guarantee to read offset zero first. As a separate patch, provided there is a guard page between user and kernel, and user accesses are 'reasonably sequential' even access_ok() need not check the transfer length. Linus wasn't that brave :-) I think some of the 'API' is still based on the original 386 code where the page tables had to be checked by hand for CoW. David > > First patch adds masked_user_read_access_begin() and > masked_user_write_access_begin() to match with user_read_access_end() > and user_write_access_end(). > > Second patch adds speculation barrier to copy_from_user_iter() so that > the barrier in powerpc raw_copy_from_user() which is redundant with > the one in copy_from_user() can be removed. > > Third patch removes the redundant barrier_nospec() in > raw_copy_from_user(). > > Fourth patch removes the unused size parameter when enabling/disabling > user access. > > Last patch implements masked user access. > > Christophe Leroy (5): > uaccess: Add masked_user_{read/write}_access_begin > uaccess: Add speculation barrier to copy_from_user_iter() > powerpc: Remove unused size parametre to KUAP enabling/disabling > functions > powerpc: Move barrier_nospec() out of allow_read_{from/write}_user() > powerpc: Implement masked user access > > arch/powerpc/Kconfig | 2 +- > arch/powerpc/include/asm/book3s/32/kup.h | 2 +- > arch/powerpc/include/asm/book3s/64/kup.h | 4 +- > arch/powerpc/include/asm/kup.h | 24 ++-- > arch/powerpc/include/asm/nohash/32/kup-8xx.h | 2 +- > arch/powerpc/include/asm/nohash/kup-booke.h | 2 +- > arch/powerpc/include/asm/uaccess.h | 140 ++++++++++++++++--- > fs/select.c | 2 +- > include/linux/uaccess.h | 8 ++ > kernel/futex/futex.h | 4 +- > lib/iov_iter.c | 7 + > lib/strncpy_from_user.c | 2 +- > lib/strnlen_user.c | 2 +- > 13 files changed, 158 insertions(+), 43 deletions(-) >