From patchwork Wed Jan 31 01:07:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13538461 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 876DDC47DDB for ; Wed, 31 Jan 2024 01:07:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0ADFD6B0078; Tue, 30 Jan 2024 20:07:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 037FE6B007D; Tue, 30 Jan 2024 20:07:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF2486B007E; Tue, 30 Jan 2024 20:07:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D32126B0078 for ; Tue, 30 Jan 2024 20:07:08 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9C7F840592 for ; Wed, 31 Jan 2024 01:07:08 +0000 (UTC) X-FDA: 81737817336.13.2B36319 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf18.hostedemail.com (Postfix) with ESMTP id AFFAB1C001E for ; Wed, 31 Jan 2024 01:07:06 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=e953cy0e; spf=pass (imf18.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706663226; 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=ISQ44kMse6Lkn35EK9G7PdGD5a4TdSkkmzrVy/QiW8Y=; b=yL/9+e/qKUq7ff3bZ49iYBcCNDB9iVa77E0ZBQ/0DihkcAgHr8p9PMbhsZaV8C7XI5wiCS nqGqpXDX9stYLnC2uRHKmL56REHjIDpwD5x15kRXogRoTUPQUBxBFQXfJlu+kyL6zTpWM1 B8vgInZK9FwGV7PsuDcaIJKezYWI0Es= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706663226; a=rsa-sha256; cv=none; b=WAtHtbav9OVIwTs8kDImDQbh364DtY1pmdIjm/m/smpMPgFXtAGYp2QCP1x0WXzEkjvuqw /W9kYDDPYrj1WYCKbZnQnGNunKPagW0R6GFbM1OHLnHdCy9qpYmqzXoEy6fcjgwvZXCzfI 6pjYKZJPW+pWFvrUFhGpcL62MWWlVNU= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=e953cy0e; spf=pass (imf18.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1d8e1f0be53so17203945ad.1 for ; Tue, 30 Jan 2024 17:07:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706663225; x=1707268025; darn=kvack.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ISQ44kMse6Lkn35EK9G7PdGD5a4TdSkkmzrVy/QiW8Y=; b=e953cy0eHMP8v1YpAYCW6DHTyT0tucJE946ZuoLCfGmDii9y0U74kTAql+1YhLFtuh LCRPtfDdqaxvWRo/+xq21rXCtLXqUHF/ueuePdOmWuiST+TN09w4XyT6N8Ijr37+pmw9 mQWstfMmyQ+4j/WHLy8cO2D9/3LCfxoFNcR0hc4mymoqgJceihbFQgYvF4W7cOOn2I1g T1/GgJJIdTuQd5q+f5oz+YboYZzlHpx7nj6e10l5BdTQ/gIq2bfjuUqbqNdo1D7dlebk XpflnbGwlNF6og8Bdy9r+5M630j1+4on20V4pVGmmg9bI402wG+dA8WWhKtzQl3mndE/ 9F0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706663225; x=1707268025; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ISQ44kMse6Lkn35EK9G7PdGD5a4TdSkkmzrVy/QiW8Y=; b=fQrg9o017pUo2xx+1UmP1k59moNFxCnhfFD3PSWRe1W8hPDmUmgTAsSraKbuQUtQ7Q HebNopel8vycTKubf1ZYEHjosmbSMmUjH1asUbpLWMFTROtbhXNqYy31EixeQgw8ddYe AKefmG9GIna/gpfUDr++o08e6b2Mobq5dFBrbPjvn/nPS3DIVkGlEtyQAKrQ1WdDYAbs uw4kJQRzHnVT8ZV7qtDUwjTKncE75aFRXNdfmHBwzi8HQK7JNcRH4NRz3spOSEnCFYnS 4y/Kisg+QhPM02u9NiYLxrlmZSpY+BLCpNl1P2uZGhAMd+sXVA7KHiJ2A17s8HcpIQ2t mmxw== X-Gm-Message-State: AOJu0YwPMXggl/AWVQpZ/mX7ieMaZaGTF/NhlgNZdyjmUoIZh8bh+kaL MwhMZQEM+nHHLvtYOfXtKNYEUApxTYBBRWby6jNbpd5abovyEkYMl4ntxwFbbts= X-Google-Smtp-Source: AGHT+IF1fmnX78HPUX7rmBRccz3fIS+KOj7NE7osYGz6T48qtTIbzBRbCpuh11u5YSinOA7TvL7pUg== X-Received: by 2002:a17:902:d891:b0:1d5:36e8:9ac0 with SMTP id b17-20020a170902d89100b001d536e89ac0mr323253plz.50.1706663225597; Tue, 30 Jan 2024 17:07:05 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id r12-20020a170903410c00b001d8d3c276c4sm4970822pld.35.2024.01.30.17.07.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 17:07:05 -0800 (PST) From: Charlie Jenkins Date: Tue, 30 Jan 2024 17:07:00 -0800 Subject: [PATCH v3 1/3] riscv: mm: Use hint address in mmap if available MIME-Version: 1.0 Message-Id: <20240130-use_mmap_hint_address-v3-1-8a655cfa8bcb@rivosinc.com> References: <20240130-use_mmap_hint_address-v3-0-8a655cfa8bcb@rivosinc.com> In-Reply-To: <20240130-use_mmap_hint_address-v3-0-8a655cfa8bcb@rivosinc.com> To: Alexandre Ghiti , Paul Walmsley , Palmer Dabbelt , Albert Ou , Shuah Khan , Jonathan Corbet , Yangyu Chen Cc: linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706663222; l=3095; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=3agc++PZjt4adgBO71Cp8EyaaOma0q0miHLEwYoM4tM=; b=AIKMSezNvXcphAUCcNCg21BBdaXUpcacXo54uEbl2OdGKMHckPpGf4N0pTfpvOAZ+GZExeI6t yXu3KlulVP2CvsGt2kGidzgw5nA924NJE/B8ZORdKYgHBzunKKkQbuk X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-Rspamd-Queue-Id: AFFAB1C001E X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 6x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Y4xvKO+1QVbNnO4opm0xwGw6FfZlb0Z8t0fJUgUQjubzCyct8hMcKxpwuqH3AUbr9K9nbGMekOTgERMJboy1a0kJ89Yb7dRHFBDuEWlEfUHuzNEo3yHDzdo+K9e2YDPi77ngIeKOrfO1DzjYdv4yI1Th004xGfL4cGg6JJkRbrcOmARrME3qwqDl93yEqe4tS8JjOLA7uVDIJwN5tKuODl8R34C4VxrsCKjJ68NKNkpZWTfZIyONMgptZZgKLMLzccG5dU/6Dd2JESJOKIwF+wAE38IpQgQtZMWWUgkvjJkAci2vpZibkl8flPvsQVWhqh/OPKzKKCc+2AAP2yp33UtlhHdHr80QJnOetaSoIfCrHOFlCAliKTqYXQMTYf85o3LQLmMifLNt8ZY7kea9ojg7G1l6bX83C0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.003612, 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 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 | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index f19f861cda54..8ece7a8f0e18 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -14,22 +14,16 @@ #include -#ifdef CONFIG_64BIT -#define DEFAULT_MAP_WINDOW (UL(1) << (MMAP_VA_BITS - 1)) -#define STACK_TOP_MAX TASK_SIZE_64 - #define arch_get_mmap_end(addr, len, flags) \ ({ \ unsigned long mmap_end; \ typeof(addr) _addr = (addr); \ - 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_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; \ else \ - mmap_end = VA_USER_SV39; \ + mmap_end = (_addr + len); \ mmap_end; \ }) @@ -39,17 +33,18 @@ 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; \ mmap_base; \ }) +#ifdef CONFIG_64BIT +#define DEFAULT_MAP_WINDOW (UL(1) << (MMAP_VA_BITS - 1)) +#define STACK_TOP_MAX TASK_SIZE_64 #else #define DEFAULT_MAP_WINDOW TASK_SIZE #define STACK_TOP_MAX TASK_SIZE