Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1286697rdb; Tue, 30 Jan 2024 13:52:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IFMgHTPuH+4FZ+5OBON36sy07UhtZCFnvK+950/k6y1a4T/JbNXTDYRr3caIOUdBGi7narI X-Received: by 2002:a17:906:13da:b0:a29:11dc:8181 with SMTP id g26-20020a17090613da00b00a2911dc8181mr6461181ejc.50.1706651560968; Tue, 30 Jan 2024 13:52:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706651560; cv=pass; d=google.com; s=arc-20160816; b=bk1HZYvdL2rLJoqkT7tlMHSUD4VMfdnuKa7HFKMkkMbJf2kLI04fw4Co/kYeRTua/d aUYrKt+CKlhwT8NQzTYFStc5NuYlvPbSvinYbyYd1FT5yhSZt0nV040dPpDNeIJi2evX rSPa4SD6KajlBHbnMTuX1+SycKe7+YVHKLcnl+W9FSc7bCTXEkm7YjRIqNSvaWBnMS+C kpbIcDFoLcujjFyYTFWjvjDmhTqvzDBp3OMC458jqwuhlx/z1Vt1DCMd6QMaEeaJmTcW wJcPxVCab/qCQoeaGQ4KKOCEHHEizwbdTlywDe0iFEjj3yV9JIkfIgFtG7K+kriKXlm9 h+bw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Np9jYGYfYb8N8NYn/XtRXhSjDUyxZMfM0XTBuDl+Ozs=; fh=x3elxNEw2yGODuDgI5toUkEZ6zihXTY4FEnv3haTUdo=; b=zNbahJNowk/70g4JCJ0lfoig8hzvm25dqXI6kUIush9pQ6hgiwDfUXaQgl1KMCV1oj 1RWtG4EV2JJF+UhYvLkz8uH7QYt6fhh2P8QXxq3V05n5rFNd9HY5WnqNcDEXuaVXNHVr 3alShSmhhFfHCuKVjt51V0VHW+cMQ9vXixLywHRV8bWaQk6BcwX597HBB1r0kFvw6bQf KgcogpWjQUQVlSGgJV22ckLZDiY8PO7UD536boMFMpCcOJPrCGa+XR4Xahq70Mych+L0 1Hf244/F2fzIPVFFe2QgCWkwOGdSqpRuZgdabKMKps5e8p6oq6cJ9/8QSSnMMia/5Fi3 FoAg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="uwQqg/dH"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-45350-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45350-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 i26-20020a170906265a00b00a36006d5c56si1336871ejc.224.2024.01.30.13.52.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 13:52:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45350-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; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="uwQqg/dH"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-45350-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45350-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 8E1611F25E91 for ; Tue, 30 Jan 2024 21:52:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A3167D415; Tue, 30 Jan 2024 21:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="uwQqg/dH" Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83F087D40D for ; Tue, 30 Jan 2024 21:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706651493; cv=none; b=mNYb1sWajzFqLo6XyQNQvGb+1SIRkJktuwg3z+xqS3BnCeSbqLwfbFeUgoDoQN+pZbv90Xhu1raTSfEjlZY3McDK3CjWm/OtJtNlKDHnjIV3D1P39eErOTUFKaiTolN++6zMxJAbQq83UmLJx823dWNymOpvjjvNQnnhM6rR4+8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706651493; c=relaxed/simple; bh=rR8SVv800/kqryt7JwIAYqxwWBoFBi/ay/0m7ds4vus=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SaHYFQJORcjQh8YlM6SX8CooMvixIGu7btx0HaAPpYbE73TWR6T2uueLBJIO/YLCOFcu8CfeGEsasoKaOhG3Z8ZyhFQMN2OEqGX7pKYeE10W56oYtMMYE3jJcnic/9pRGb7pxYyvtZRZ1EtWwuRAak5EOkiWDQ4d5HteO8wfC50= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=uwQqg/dH; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2906bcae4feso2074233a91.3 for ; Tue, 30 Jan 2024 13:51:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706651490; x=1707256290; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=Np9jYGYfYb8N8NYn/XtRXhSjDUyxZMfM0XTBuDl+Ozs=; b=uwQqg/dHdGjr6VWkl+6Jgp6oEXjBon0K1PHQ+N8W89+pZ+QFOVgR04fKC62QKjr3Ek V3uWMjHFNEmuOeLoHD9iITvbYaYQsV7GYXe1F2k2IK14Ixh34wOlcJgTQl7Yn9ZSmQr2 6ud7FGJu8UibFqQvYHVeeWGQas7L86ZqIYA3LlVFIIJ5LQLCpA0f1oIzdz3bVDH7VBXJ gXEwu5KvETqkZaHp9DTqtfTwcPI/DhtPb37HVdlZaN2aGLSojkdb5NmDnBKB482C+k41 /7zfm79zjeY4uJ4V0LkfLpASH3C+3f3TwrVm93gbisnMRxVDsPexyECrcDTCreQ0mthc RwdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706651490; x=1707256290; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Np9jYGYfYb8N8NYn/XtRXhSjDUyxZMfM0XTBuDl+Ozs=; b=Y82hjCTbJ1twlAj1uI1oSagFkXVUFDYCchOr1Td+6AIOgnyE4Lml/atQXP7DPwpTsY cnCuvy2ePIDUiSpQMA+Jmp6xUf77skfM7zOd+NWz3oQ6F2HiHqV/VGiEzdLWT2yXrDCR Xpdg4I8WbVB5z2XHODHHhbJde7fLOfXVambOJ/9vcT8WGtYgnzZhypIgaD0PeYFw5l5E NKVZVINu590Aju3JBRberijYqjZ7AGwcuhHH2fyJhjPnkMS7Nvnz77xK7Qit6k5MJ7Fo H2W/U7fWPcDn9rFGbcS4v8Zxx8Z3GKHQWqL0p5ZR4j4Igo3G2IiqHtPd1D22ZWbvrwWu HipQ== X-Gm-Message-State: AOJu0Yx6exLh/VuandAJLKjUxqfG8OH+YjAATr2GaUYbudMaXiT/YWyW 8RRMAlTmgi85q3w5zdDiL0eluJeZQprLj5A9pZBEbMywolZzfFmJcPKCaB+egQY= X-Received: by 2002:a17:90a:17a2:b0:28f:f1c0:3d21 with SMTP id q31-20020a17090a17a200b0028ff1c03d21mr5388368pja.41.1706651490637; Tue, 30 Jan 2024 13:51:30 -0800 (PST) Received: from ghost ([12.44.203.122]) by smtp.gmail.com with ESMTPSA id nb5-20020a17090b35c500b0029464b5fcdbsm8657589pjb.42.2024.01.30.13.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 13:51:30 -0800 (PST) Date: Tue, 30 Jan 2024 13:51:28 -0800 From: Charlie Jenkins To: Yangyu Chen Cc: Alexandre Ghiti , Paul Walmsley , Palmer Dabbelt , Albert Ou , Shuah Khan , Jonathan Corbet , linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org Subject: Re: [PATCH v2 1/3] riscv: mm: Use hint address in mmap if available Message-ID: References: <20240130-use_mmap_hint_address-v2-0-f34ebfd33053@rivosinc.com> <20240130-use_mmap_hint_address-v2-1-f34ebfd33053@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Jan 31, 2024 at 03:15:16AM +0800, Yangyu Chen wrote: > On Tue, 2024-01-30 at 11:04 -0800, Charlie Jenkins wrote: > > On riscv it is guaranteed that the address returned by mmap is less > > than > > the hint address. Allow mmap to return an address all the way up to > > addr, if provided, rather than just up to the lower address space. > > > > This provides a performance benefit as well, allowing mmap to exit > > after > > checking that the address is in range rather than searching for a > > valid > > address. > > > > It is possible to provide an address that uses at most the same > > number > > of bits, however it is significantly more computationally expensive > > to > > provide that number rather than setting the max to be the hint > > address. > > There is the instruction clz/clzw in Zbb that returns the highest set > > bit > > which could be used to performantly implement this, but it would > > still > > be slower than the current implementation. At worst case, half of the > > address would not be able to be allocated when a hint address is > > provided. > > > > Signed-off-by: Charlie Jenkins > > --- > > ?arch/riscv/include/asm/processor.h | 22 +++++++++------------- > > ?1 file changed, 9 insertions(+), 13 deletions(-) > > > > diff --git a/arch/riscv/include/asm/processor.h > > b/arch/riscv/include/asm/processor.h > > index f19f861cda54..5d966ae81a58 100644 > > --- a/arch/riscv/include/asm/processor.h > > +++ b/arch/riscv/include/asm/processor.h > > @@ -22,14 +22,12 @@ > > ?({ \ > > ? unsigned long > > mmap_end; \ > > ? typeof(addr) _addr = (addr); \ > > - if ((_addr) == 0 || (IS_ENABLED(CONFIG_COMPAT) && > > is_compat_task())) \ > > - mmap_end = STACK_TOP_MAX; \ > > - else if ((_addr) >= VA_USER_SV57) \ > > - mmap_end = STACK_TOP_MAX; \ > > - else if ((((_addr) >= VA_USER_SV48)) && (VA_BITS >= > > VA_BITS_SV48)) \ > > - mmap_end = VA_USER_SV48; \ > > + if ((_addr) == 0 || \ > > + ??? (IS_ENABLED(CONFIG_COMPAT) && is_compat_task()) || \ > > + ??? ((_addr + len) > BIT(VA_BITS - > > 1))) \ > > + mmap_end = STACK_TOP_MAX \ > > ? else \ > > - mmap_end = VA_USER_SV39; \ > > + mmap_end = (_addr + len); \ > > ? mmap_end; \ > > ?}) > > ? > > @@ -39,14 +37,12 @@ > > ? typeof(addr) _addr = (addr); \ > > ? typeof(base) _base = (base); \ > > ? unsigned long rnd_gap = DEFAULT_MAP_WINDOW - (_base); \ > > - if ((_addr) == 0 || (IS_ENABLED(CONFIG_COMPAT) && > > is_compat_task())) \ > > + if ((_addr) == 0 || \ > > + ??? (IS_ENABLED(CONFIG_COMPAT) && is_compat_task()) || \ > > + ??? ((_addr + len) > BIT(VA_BITS - > > 1))) \ > > ? mmap_base = (_base); \ > > - else if (((_addr) >= VA_USER_SV57) && (VA_BITS >= > > VA_BITS_SV57)) \ > > - mmap_base = VA_USER_SV57 - rnd_gap; \ > > - else if ((((_addr) >= VA_USER_SV48)) && (VA_BITS >= > > VA_BITS_SV48)) \ > > - mmap_base = VA_USER_SV48 - rnd_gap; \ > > ? else \ > > - mmap_base = VA_USER_SV39 - rnd_gap; \ > > + mmap_base = (_addr + len) - rnd_gap; \ > > Please mind that rnd_gap can be non-zero, in this case, the map will > fail. It will be better to let mmap_base = min((_addr + len), (base) + > TASK_SIZE - DEFAULT_MAP_WINDOW) . Why would an rnd_gap that is non-zero cause mmap to fail? mmap will fail if rnd_gap is greater than (_addr + len). That is expected and should be interpreted as no address was available in the requested address space. mmap_base is used if the hint address is not available. I do see that I fumbled the test cases in this patch so I will fix that in a v3. - Charlie > > > ? mmap_base; \ > > ?}) > > ? > > >