Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2786771lqp; Mon, 25 Mar 2024 09:10:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWvbC2pOVbzeIP/Br6DsU5Pg1q+oLjyeojKfPbgITQv95pOfwmNQqDDHYQ+hzjukKZt58TVN8NhAfLtaAKUd4JrECCwCWnCIL/KTwsDDw== X-Google-Smtp-Source: AGHT+IE/e15YY866b24NeIhQpPkkteamdiEJexENylyYXZqcQ+SSIEHTXqjrWhWBWTVuOloHWxxY X-Received: by 2002:a17:903:228b:b0:1e0:b5d4:9f61 with SMTP id b11-20020a170903228b00b001e0b5d49f61mr4224153plh.36.1711383048865; Mon, 25 Mar 2024 09:10:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711383048; cv=pass; d=google.com; s=arc-20160816; b=AG7d1AosgS78RseRDkxzU294tOtno4nneyomLS2/Kjy01jThmaM2i7o9jTLPnbNxzJ wIdeM+1kg0AHKlQclmkSDTkSxeDe4wDSYUh18KChEKedpxylscZKajEHvpaneDKtvWP4 AWQMTMtbvnjR7dL8n0Kp1+RWm2TyMy6iOCor9inGbqKLEV2Hp07Gkfi7FZUac75OMKUD mgDjbqhyg0sRRAtED9q8jgeLIMq9HWn7MXFbsdV3GIjJRb1oHs9/rBSFUHf/1MBUkVxL pw6nxEtk/VjfCkFeocpTys48AtxvL9NFmYUs7Xo5DcANbWb1TeZ7RovG05Q9ZZJRQZ5I J3qw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:cc:to:from:date:references:in-reply-to:message-id :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:feedback-id:dkim-signature:dkim-signature; bh=z4Kn3pYXpgiAUzuK6QDRYyQRhLD9Dn62eTCOSq5cUP0=; fh=wLCKoI1psCiB3/IVEIYsxImCFAW5l+mmf2YuiMG18sk=; b=qe8BOTLoJuLvTu4aArwLPdQ05j4Q3JwIjD3K5Wk/QN/YwvQ71rfHYPpdNjCTDP7Z7j Svc6FaJWAQ2hQhrWeGheMByOZn9BI2VoPTnltao45SetX+JRzs+ubmy8ZbyNu9mAn/Cl lKAkCc+OwW0VqJNaRarzReoz+tVkjJO+lPJTp7J24ZZdF/VnqnjFwQOrvdCHAVlADZhg T6/jn7zz3Q/gQm7os4MhJC0k+e7AIW1rs3lFRnUjDyRM2bEPrW0bFvHkN1z7wLiuRjWc LoaYdx5ybOvQvxHVu77tysuXcCIsJAC3YLvFhmjX6Ahx6Tbc5G/3VufX+UH3bosxh160 e4/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@arndb.de header.s=fm1 header.b="OK/isPdT"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=qv+awkv1; arc=pass (i=1 spf=pass spfdomain=arndb.de dkim=pass dkdomain=arndb.de dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=arndb.de); spf=pass (google.com: domain of linux-kernel+bounces-116924-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116924-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arndb.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b5-20020a170902650500b001dddcbe0aacsi5142957plk.188.2024.03.25.09.10.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 09:10:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116924-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@arndb.de header.s=fm1 header.b="OK/isPdT"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=qv+awkv1; arc=pass (i=1 spf=pass spfdomain=arndb.de dkim=pass dkdomain=arndb.de dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=arndb.de); spf=pass (google.com: domain of linux-kernel+bounces-116924-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116924-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arndb.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 25529C07AF3 for ; Mon, 25 Mar 2024 14:49:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5DC5B1BAA50; Mon, 25 Mar 2024 11:46:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=arndb.de header.i=@arndb.de header.b="OK/isPdT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qv+awkv1" Received: from wfhigh1-smtp.messagingengine.com (wfhigh1-smtp.messagingengine.com [64.147.123.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71FD21BB063 for ; Mon, 25 Mar 2024 11:15:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.152 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711365336; cv=none; b=DLXacpNsVvHB9hYRmrru0IrKdzwl6JKLC9e5HacpTtHXd83IKcgFXqLBrxM6rfwatsXWRL7r5BRc/SVVR9Je/oQAGQ8/NfVv+mJNA+OWi61Zyui/B64CekNkV8zf8L5FQqPlUYlw2I8orX4GGhtE268uggShGk1syNqeOt386hY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711365336; c=relaxed/simple; bh=opKIsZlMHtQnbJCvVr82tpAN2qU/VqAhSCB8KlJlM5M=; h=MIME-Version:Message-Id:In-Reply-To:References:Date:From:To:Cc: Subject:Content-Type; b=ImG1wXXcb5T/QaZJ3258vm8A1M+xmwZmssxQzea1xs15d2q6gbkFHwjbUcRigFXy66USx5XTop5h8db0fgFGjg6ft4zsGeuccTtzdlhHk6aCDVNRh1tF0Xg/iouYoGNSI5zSCRvVa5USDCEYCWHOQ4U/09rwyFAu4l327WlLO2Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arndb.de; spf=pass smtp.mailfrom=arndb.de; dkim=pass (2048-bit key) header.d=arndb.de header.i=@arndb.de header.b=OK/isPdT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qv+awkv1; arc=none smtp.client-ip=64.147.123.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arndb.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arndb.de Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.west.internal (Postfix) with ESMTP id 0646718000B9; Mon, 25 Mar 2024 07:15:31 -0400 (EDT) Received: from imap51 ([10.202.2.101]) by compute5.internal (MEProxy); Mon, 25 Mar 2024 07:15:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1711365331; x=1711451731; bh=z4Kn3pYXpg iAUzuK6QDRYyQRhLD9Dn62eTCOSq5cUP0=; b=OK/isPdTFrqQI/4cMYOrrqmGXY 50PVXN4faVpZIDcM+nQKPpcJsp8HKY6A9pBrXO25gQi+mYZ4l5Q4806IAHF61oe6 vYdvO37FtnvSCUNe5a/4Z1MNY7hoJeXyKtWc67mhdln7SQLItMMxArbqaU9LN4Kf BTeyDytZXE798uApFj79OBg/0EAduNeiSLTZkWADUBGZyjLKzJ1eTOSDvo761KeS iCJkRAEtxRB6m051iHakUQ5tVjstrcpLVuMHAVRuQQ7qPL6EPTmKGfFJ9x8dzq2w jI9k6qR7nfTjEml7e8cc4AjeEwpv2ffj//ESIkh7r2OALMAelwzZC0gC7dKA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1711365331; x=1711451731; bh=z4Kn3pYXpgiAUzuK6QDRYyQRhLD9 Dn62eTCOSq5cUP0=; b=qv+awkv1sbrET62JITAJj90ptP70MGbPz7R3Gjx4kMkc cl2bPh7jZ8YuPY3qLCzYTTX/TzqNJjKeAP+eEBHzGfomJd6PcC0dLfEUUlaxui8l gTK14QDH8bkmPJ7yk+LuZ8gRtpuX+8XnRBjI5AxvEJcIXJvrLvWfBVl1ZEUITyT5 /UmJ3BDZQHoNWi/WWcv9visDEDgFXxghMrfBH791hSWJlKGIFrEMci+d8/rNPb/P Td6RUt9NUsKD4sKU8ybS8GiKybSzzr2K0pMKfMnbQ1Z+alinCTYDcTA/3Hh8BEhN F4ruMTa6bkaZvYLcf+c7FIOkUb9gedPC+Buh2OTrVg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddutddgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedftehr nhguuceuvghrghhmrghnnhdfuceorghrnhgusegrrhhnuggsrdguvgeqnecuggftrfgrth htvghrnhepffehueegteeihfegtefhjefgtdeugfegjeelheejueethfefgeeghfektdek teffnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hrnhgusegrrhhnuggsrdguvg X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 8969FB6008D; Mon, 25 Mar 2024 07:15:30 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-332-gdeb4194079-fm-20240319.002-gdeb41940 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: In-Reply-To: <1883cf6b-7756-405b-a843-d8ae31e01d61@ghiti.fr> References: <20240313180010.295747-1-samuel.holland@sifive.com> <88de4a1a-047e-4be9-b5b0-3e53434dc022@sifive.com> <1883cf6b-7756-405b-a843-d8ae31e01d61@ghiti.fr> Date: Mon, 25 Mar 2024 12:15:10 +0100 From: "Arnd Bergmann" To: "Alexandre Ghiti" , "Samuel Holland" , "Alexandre Ghiti" Cc: "Palmer Dabbelt" , linux-riscv@lists.infradead.org, "Albert Ou" , "Andrew Morton" , "Charlie Jenkins" , guoren , "Jisheng Zhang" , "Kemeng Shi" , "Matthew Wilcox" , "Mike Rapoport" , "Paul Walmsley" , "Xiao W Wang" , "Yangyu Chen" , linux-kernel@vger.kernel.org Subject: Re: [PATCH] riscv: Define TASK_SIZE_MAX for __access_ok() Content-Type: text/plain On Mon, Mar 25, 2024, at 08:25, Alexandre Ghiti wrote: > On 24/03/2024 23:05, Arnd Bergmann wrote: >> On Tue, Mar 19, 2024, at 17:51, Alexandre Ghiti wrote: >>> >>> The use of alternatives allows to return right away if the buffer is >>> beyond the usable user address space, and it's not just "slightly >>> faster" for some cases (a very large buffer with only a few bytes being >>> beyond the limit or someone could fault-in all the user pages and fail >>> very late...etc). access_ok() is here to guarantee that such situations >>> don't happen, so actually it makes more sense to use an alternative to >>> avoid that. >> The access_ok() function really wants a compile-time constant >> value for TASK_SIZE_MAX so it can do constant folding for >> repeated calls inside of one function, so for configurations >> with a boot-time selected TASK_SIZE_64 it's already not ideal, >> with or without alternatives. >> >> If I read the current code correctly, riscv doesn't even >> have a way to build with a compile-time selected >> VA_BITS/PGDIR_SIZE, which is probably a better place to >> start optimizing, since this rarely needs to be selected >> dynamically. > > > Indeed, we do not support compile-time fixed VA_BITS! We could, but that > would only be used for custom kernels. I don't think distro kernels will > ever (?) propose 3 different kernels for sv39, sv48 and sv57 because the > cost of dynamically choosing the address space width is not big enough > to me (and the burden of maintaining 3 different kernels is). > > Let me know if I'm wrong, I'd be happy to work on that. My feeling is that in most cases, users are better off with a compile-time default, given that the addressable memory has a factor of 512 between each step. With sv39, I think you are limited to having all RAM in the first 128GB of physical address space, and each process is limited to 256GB virtual addressing, but this is already covers pretty much anything you want to do on small systems that run a custom kernel. On most desktop/server/cloud distros, hardwiring sv48 is probably sufficient if all general purpose machines support this, and it should be enough even for commercial databases that micro-optimize 100TB datasets through a permanent mmap(), as well as most NUMA systems with discontiguous memory. This adds a little cost over hardcoded sv39, but is still faster than a boot-time sv39/sv48 config that most users will not be aware of. Once enterprise distros certify systems beyond a few dozen TB of RAM, they probably need to enable the boot time detection, until then I think the few users with gigantic systems will probably be fine running a custom sv57 kernel. At that point, that distro can start shipping a kernel with boot-time detected page table sizes. Arnd