Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2924961lqp; Mon, 25 Mar 2024 13:15:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW+ho2UvoxyPQOdZEPxe0UpN3XEjr/krtzOGwnpP2gOAxOQxYiydwOTz9ViBpxK/bdsPCbrDu/Gpu7QswbxPxzV+xjPxch7t7XSad70BA== X-Google-Smtp-Source: AGHT+IGewjKIgkhGj3hfdDgejucjqvGTwd6X5RZsBdT7U4XnQwXkvpKOV/OSGNIR4NzNdCUvdiJR X-Received: by 2002:a50:a416:0:b0:568:d5e7:37a1 with SMTP id u22-20020a50a416000000b00568d5e737a1mr5289338edb.36.1711397746274; Mon, 25 Mar 2024 13:15:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711397746; cv=pass; d=google.com; s=arc-20160816; b=SlbsZFiICE+Gk3ngaRILFbHO+oQkbLjeTMBE6OKwBiUNCK8F0iHmKoksFEOkq1v9Ms KlQUgIUZ+PNXVR8khNN73avmiyd2Wi5LNSVPwzTKsSwbpuGwUK8Dfpxs6bxgM7tTbZKK oqsMoIAsivR2SJSTD5L5QeJA1rgVGN+FeDNHjJF35rZJNpPeqEnhtdUI0xe6iMXJqHMv i1qGWZ9lO0xGDe1/OUb/PmiqQgFKlvF54nVyuvHG6Fk3oS9l9z1jO41ro15LwuokVGY2 A37lBSQiV0xaNaIquV7pYLpUxOAlzxNpibaysL6eIl1uN93sC3CnSR6RMe4R7BDcT7eY J9Ew== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=3HcEpT6RPN2boK1vEqI0xsJDwfVbrJP1MEkldGtIvYI=; fh=DNH1EZVcDydTSSo5BVxLcmXRixbCTWcczSNAfXdC7Mc=; b=t2GpNVZf2UqxXtYGlXJMXCNy0MS/fT+uNJFWBPVMH/KqXS3ZCZBdvBjAXu66JpcFXU 4nG4NXmHWe15ZUt+Dw4HlA3Ycqt84C3UiNkUUfOMa1ms0qICcOLQ+SSdOlxv96F2zF8I 2cErKKg82lu299UR3fYxJPxPHo2fHTT131/nOzCHmcRH5KlZKnio5Xm/d5pMoAapww45 UuWivAHST5mNxGRFhlONDphHoV/+zs7lpBEVgWW7Q9Dx9ZbSBUhsNdo3lmpeQMZ15aIo yxzDfUxyZX0Silqoe+AffgEfPlK8VCNRAlLflXZEN9vo4p6wS/lhno9tEvk90DaeKMik o8Ug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=ghiti.fr); spf=pass (google.com: domain of linux-kernel+bounces-117904-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117904-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ev19-20020a056402541300b0056c16c9cafesi887259edb.446.2024.03.25.13.15.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:15:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117904-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=ghiti.fr); spf=pass (google.com: domain of linux-kernel+bounces-117904-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117904-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id D1EB01FA5B15 for ; Mon, 25 Mar 2024 20:15:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D0AAA5DF0E; Mon, 25 Mar 2024 20:13:06 +0000 (UTC) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) (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 0EAF1FC01 for ; Mon, 25 Mar 2024 20:13:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.193 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711397586; cv=none; b=VeLefgMsy5PFtEMPoLCXvsDAplKmdXb9t99reYSIrry1T7TGuX1TJ//paHK3SH2vZTSNdWr43E4UIehGMyy4vPJrg1CBOFnuqwvl49jghN7uAevEchZtGdlXRqA5P12KYdMVuNPruNxuE5sLMlVXL7XZ9NBXccJMiDolpYZxt1E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711397586; c=relaxed/simple; bh=SfZG6A8b7DawFMujLgpCe+RcXvJsAKzCUr+HoUNG97o=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=j+q2sMgHEV13iSe/RDLRIAd+eGMOJAlJ5tTlmzI0IXztxhnf3Qnm+qG7yNZKlSbaSURkZIBz87LF8F9wpGgylp00Sgj5kWVKzMUuGWKxb5ujuz6jUCQnD7LskSF1SNzSPyvYPR12BH0+u1I3kOl/XvMvnxU1iKtJ/+96mbAzBcA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr; spf=pass smtp.mailfrom=ghiti.fr; arc=none smtp.client-ip=217.70.183.193 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ghiti.fr Received: by mail.gandi.net (Postfix) with ESMTPSA id 7D366240003; Mon, 25 Mar 2024 20:12:55 +0000 (UTC) Message-ID: <5bf9b76a-8f1a-4a53-b550-f4f2ad775cd8@ghiti.fr> Date: Mon, 25 Mar 2024 21:12:54 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] riscv: Define TASK_SIZE_MAX for __access_ok() Content-Language: en-US To: Mark Rutland , David Laight Cc: Samuel Holland , Alexandre Ghiti , Palmer Dabbelt , "linux-riscv@lists.infradead.org" , Albert Ou , Andrew Morton , Charlie Jenkins , Guo Ren , Jisheng Zhang , Kemeng Shi , "Matthew Wilcox (Oracle)" , "Mike Rapoport (IBM)" , Paul Walmsley , Xiao Wang , Yangyu Chen , "linux-kernel@vger.kernel.org" References: <20240313180010.295747-1-samuel.holland@sifive.com> <88de4a1a-047e-4be9-b5b0-3e53434dc022@sifive.com> From: Alexandre Ghiti In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-GND-Sasl: alex@ghiti.fr Hi David, Mark, On 25/03/2024 17:39, Mark Rutland wrote: > On Mon, Mar 25, 2024 at 08:30:37AM +0100, Alexandre Ghiti wrote: >> Hi David, >> >> On 24/03/2024 20:42, David Laight 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. >>> Is it really worth doing ANY optimisations for the -EFAULT path? >>> They really don't happen. >>> >>> The only fault path that matters is the one that has to page in >>> data from somewhere. >> Which is completely avoided with a strict definition of access_ok(). I see >> access_ok() as an already existing optimization of fault paths by avoiding >> them entirely when they are bound to happen. > I think the point that David is making is that address+size pairs that'd fail > access_ok() *should* be rare, and hence it's a better trade-off to occasionally > handle faults for those if it makes the common case of successful access_ok() > smaller or faster. For any well-behaved userspace applications, access_ok() > should practically never fail, since userspace should be passing good > address+size pairs as arguments to syscalls. > > Using a compile-time constant TASK_SIZE_MAX allows the compiler to generate > much better code for access_ok(), and on arm64 we use a compile-time constant > even when our page table depth can change at runtime (and when native/compat > task sizes differ). The only abosolute boundary that needs to be maintained is > that access_ok() fails for kernel addresses. Hmm indeed I had completely misunderstood David's point, but actually not really since I disagreed with what he actually meant :) But I had not realized access_ok() was so performance-sensitive and also missed the point that it was to protect the kernel more than making sure the userspace address is correct, so I guess we are good to go with Samuel's patch. Thanks David and Mark, Alex > > Mark. > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv