Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2669495lqp; Mon, 25 Mar 2024 06:14:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXltZG2pbGZzbDTedWXf4x+RWmjtUiAc3LsU0CdJ1RvbLnnrXiyVATCmKcUnO6jcca5bJO0AJHuWqtFGH3uBArMVrJS/wS27YgsarxnhA== X-Google-Smtp-Source: AGHT+IFEuB3M4T9Aaexa9pDiyo+6rrgcXE4hhyiAaofhpyCKMqEofeZIgaU+DwY7VaHMVyxa1srC X-Received: by 2002:a17:907:1184:b0:a49:fa33:a413 with SMTP id uz4-20020a170907118400b00a49fa33a413mr2326371ejb.69.1711372476057; Mon, 25 Mar 2024 06:14:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711372476; cv=pass; d=google.com; s=arc-20160816; b=wt5AAKKMpvMm6BzDqD3ylieocT/nSIT8pMuPYenuG3Y/KNIhGJsVufB3zFIw2pbQO3 QDmutZvIs0p+Mu4/1kRuLsLyHysYXjXOROhGCtFvPgYKFV4XwBJQlBkADhWGSqxqzb/m uPWsPn1Smvfi/vmwHw4oxz9fEehtWpu/vubKWbpHqgtBAH4EVqPb7N8lbJ5OfaS1hVzI 70AeyDf0KpbWavcehR4lhLuQkt9/QlQJ1fq5s4ISdiCfmpPXI4C8sHmAH3/UMg6DXrC4 MRCr47/QKn26bqozNiftvFAdMKAcTkziAZbG+UWKKiukj3Vv7XTYgHZDRSks2PuIFUGi O7zg== 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=pwLFi4clIuC4hmalPlGWzv+JYIp5Fk+IfdC6vj11chw=; fh=CBd/3/xBhU0WZ2rYhl/aKRHgYJa7ha0ZMCNcTt7bRYs=; b=e61dATz1X6bSuy13dT/fSou8fywJ2z5m4w3uYF6+wzTDOT24PUQlgKPHwneblD6+DO Q1FVVIL7xorsc3SeaPguIw0pRmxMkvpJYFuravrl1gRxSoWXBW55yIkoOqL4HO5W7GdG CjcFNwVeoSSMKIanFsxHhwLOlrHF7tlAwkGHGOM80L7uMWqNSZCe86M2Uv+Dt3EwikMr GadQ9XBGo2sOAWT8iHdjgJRInQy8xs7ujGGa6NP2h3IRajq5GlACGG30Q3t8JyeM2Fax DXZXIuK9s/UTuvdPjD09n8qkzJfbLA9RT8I7nUYylf+evQoalfIMzTDMVbLY07dJYsuI VBWg==; 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-116619-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116619-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id o12-20020a170906600c00b00a474884c967si1772781ejj.472.2024.03.25.06.14.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 06:14:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116619-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=ghiti.fr); spf=pass (google.com: domain of linux-kernel+bounces-116619-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116619-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 BDD351F3A890 for ; Mon, 25 Mar 2024 13:14:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EBFAB5CDD0; Mon, 25 Mar 2024 09:11:02 +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 DB6AF55798 for ; Mon, 25 Mar 2024 07:25:41 +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=1711351544; cv=none; b=E1niBaoiqP6KGIVbzEr0UpAPNgly14ek2Y4e0hJo3b0QyDVOwRFs2b4ynaEmzErOeQRtqOgEIfpJkvb7kvHM3NGfYFyKqKbp8wIp5z3eixddSeKFvp+YQsFtIQarWrPQvhlMWANBvY44qdy5aEXJim9B+xVPeDndNTrqtQ1R4js= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711351544; c=relaxed/simple; bh=6Ex/aBChk/0aJOCZhha4d9sYX6YbFHzLZTQVJK1TS4I=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=RUMKbclGpktypdpPDmtlYpQ0cOfc8d5I8+nSXzrAGx+8Kc57hbJZnXQdsnA5cpIqckWkLkg5KrtnBMl5prSjxqUAPAZIZzFFged+umTpdbFnelv6MsGToSgi87mOF2FBGZjqMfZ3ZHCz2HUIH7RHIo+pgb2GPBhCxPsMMMmZ+g8= 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 56277240002; Mon, 25 Mar 2024 07:25:29 +0000 (UTC) Message-ID: <1883cf6b-7756-405b-a843-d8ae31e01d61@ghiti.fr> Date: Mon, 25 Mar 2024 08:25:28 +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: Arnd Bergmann , 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 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: 8bit X-GND-Sasl: alex@ghiti.fr Hi Arnd, On 24/03/2024 23:05, Arnd Bergmann wrote: > On Tue, Mar 19, 2024, at 17:51, Alexandre Ghiti wrote: >> On 18/03/2024 22:29, Samuel Holland wrote: >>> On 2024-03-18 3:50 PM, Alexandre Ghiti wrote: >>>> On Wed, Mar 13, 2024 at 7:00 PM Samuel Holland >>> It looks like the call to fixup_exception() [added >>> in 416721ff05fd ("riscv, mm: Perform BPF exhandler fixup on page fault")] is >>> only intended to catch null pointer dereferences. So making the change wouldn't >>> have any functional impact, but it would still be a valid optimization. >>> >>>> Or I was wondering if it would not be better to do like x86 and use an >>>> alternative, it would be more correct (even though I believe your >>>> solution works) >>>> https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/page_64.h#L82. >>> What would be the benefit of using an alternative? Any access to an address >>> between TASK_SIZE and TASK_SIZE_MAX is guaranteed to generate a page fault, so >>> the only benefit I see is returning -EFAULT slightly faster at the cost of >>> applying a few hundred alternatives at boot. But it's possible I'm missing >>> something. >> >> 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. Thanks, Alex > > Arnd