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: 6xixrj3g7fifg5kk61yxuqifsi3zggw1 X-HE-Tag: 1706663226-588073 X-HE-Meta: U2FsdGVkX1+dK8C/eIM4ztVXj5zaoiCStt0z/XibWiXr5thIRkusSlTBdi56EJARVLr3I/VR/2WrT+3B7nE2oojJL3EM4OMV9fEjN47iSFVHzQvijaUFSoQv4QnqMMRgAxBOIN32F+HcV7cH1Cti95kxkEQ1cq2xoRjwnQ4syY9QoW14QErx6nuYX0ZrbdiiddhPbftAxYMY3JB+ykH/GHiFODUiWpNMNL6tPO5o4GEWnkCzmt2ot2f+gsUDASpYt9Ec14l1nwWnVpCvZ0HOkz8lw+8iJtbQHjkW72I5um+PXnwFZQEsn3VLm7Kl5n/pLbi+kz1x2I7OUBBkAW0FTQW4gPhXFmqqEYpDuJplcVk8qMHOqXVAJp8x+qz53I6XB59CvERJzJY/n7IOyqdML4FEN9/+Rb9XKV/u70yC5rGij/j7clMfcJ7AVP6VZOZkiXU0TXT1J/d+pviN0TXT8iE9l1ZFZjIKMb65HQQ/4lTV3L1erlgeGBar8YuZZZvfUs186EJK73mfOtraiL4oVw/yfi6oxIilS6XxHfRGDcZ3/GTRhLSkySKbfw9JH1FNYahx6tX0moCANHJ4JX6jw4fNZSfQqru30TZFP3uM8MelUwJzxobxmvAnlwGn2MsoyIr/yrjUyHDU+uh3pa8lOisNKGzjJt8HWcJtaxEAAYwYfzK+dxbaSqN/MdNaSEaw45diogsPEc39spZXzyUwfdWVkOwywm5vCa04ww2WvNOQEBYFj68xrw8WrgeMR5B36LG2YG/cDqL/KcJnGWDClMac4+uh50yLqvKmSvs6rkBXpMxWTk2bWXKzcit21Vp2yg3elPGgFvLijJ/mtddbUiUoRolkW3MfKcR4exZyhIknPv+dGdWJPDrkq3KrA6FwzI709xKePXDdal45GbONLmfjE4+LkPIwbzXVDCjZ2+fe6OnLucLl2zGMJ/wn3MU7e9Mf4cKZLX+RE54JMMn famYqXqB tFU0ecgqI7PCJViN2EXrkEZzMjnqGWRb+dFmfozJC1hXJyY4xvKO+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 From patchwork Wed Jan 31 01:07:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13538462 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 DDC5EC46CD2 for ; Wed, 31 Jan 2024 01:07:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B3EC6B007E; Tue, 30 Jan 2024 20:07:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 73DC46B0081; Tue, 30 Jan 2024 20:07:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B6086B0083; Tue, 30 Jan 2024 20:07:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 494126B007E for ; Tue, 30 Jan 2024 20:07:10 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DC9691C15B5 for ; Wed, 31 Jan 2024 01:07:09 +0000 (UTC) X-FDA: 81737817378.28.54313AA Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf02.hostedemail.com (Postfix) with ESMTP id E906880020 for ; Wed, 31 Jan 2024 01:07:07 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=J6nBGf0J; spf=pass (imf02.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.182 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=1706663228; 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=13+B6LdTKTjt05jiAPVkvvRHYs5geOTb+j5SNg+p/UA=; b=V0DwsqnlvABkonr6+eYJsNdxVOFM8/kxgyiT7WK26+XQ7nIbWb2XBCDv7P/Xj4uxNIIs+S YP/ucTQf0mn/zMGitV2xmyS9ODtMKQxR9BhitsuQG2IPqBc5zlaJxlr/Ut1U+Akuz3tbcJ PjYpibktQlarZvLo4/GGHTcUCl2NVJY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706663228; a=rsa-sha256; cv=none; b=Ija+yM4sJXyCbiXDiXtwBSrdtOlZ04r/BX7/miOuUwLMrcQlwhVlUYR1qq6mibmt1u+IjE +pUAwglz9z+loYI+8tkLjChNkHng4Tqo3NINo4YJu1zXpKIyOvVPKI3KMNv/8xLb33rReZ J4COQr3CqZ6FB6Z6SQJ01D4i0Jgf9Bc= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=J6nBGf0J; spf=pass (imf02.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1d74045c463so26374845ad.3 for ; Tue, 30 Jan 2024 17:07:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706663227; x=1707268027; 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=13+B6LdTKTjt05jiAPVkvvRHYs5geOTb+j5SNg+p/UA=; b=J6nBGf0JzyweyhUI4AvsyTRXq3nG+oTJTgPoDiP8yq6c4tYYeBIulE5NiR26W9OS15 fGIDAnTRCGMh1BPj+fry/YnFi6PGGEoAyzaZYxJ2qYDHyxk8Ab+Qmy6wgBnsXKVwQB4T ZYXkVjmZZGvpGCdWgOajR66q2Jkh5hX1bjkLzBnU/ncVh8Ymd5yKBlA2tW8EWyf6Ldan 5QZCkrcqJ3Jr7RFTWiFrNP/qbSZ3tlf7RLBHb83NTtYGA5uHqYYhVSM+2iO4qeq5tHCp pV8PXa+Cdm1d8Rv0f4VGYPQ8UU8kH8o0D3ebXfJ7OhKiqDClD0K5A9b9vjT+NM+U+fhK Xssw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706663227; x=1707268027; 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=13+B6LdTKTjt05jiAPVkvvRHYs5geOTb+j5SNg+p/UA=; b=KvQGlQ9v0DO55k4rYI/MezfTBc0Q9UZ6QczYXyrKd4i/UR7p3z07sbXzFunYaa0y3W L6fqUB/jCEGT0EerIoQr4bCswIKSbDNdJ2fKbvo8AlHnfy26K4Z5xO+tKPxzESwbRxED tG796weHGdQBGq7LW3JcoL7Zv1hRuqXgQgIXW6Y33uQitCEuINHBNIHjljohhttZ2dVi KPFCf5I/tNN/7JqHS9a4gOUnbrjtCtDGF8K7E+e71cwLXqh1G4z9E94ok5Uukf2LMFQV j59tVjIf56yx2NX4TKscQE1JDdvus5Tgbu6LaXY+ikcPdf+G2BCMi2k9ruQycrjRGDMN 0QVA== X-Gm-Message-State: AOJu0YzTmV8xLtVCHiS2aT4Cieq68intCmz9Sa3FiQgHc2xHDq4EkW1P zRlXIiEcW2uvdZ/36wq+Y8fwkL2DgWSZySZvK/uf0fNw35WwxMCR6UpB+ALpjI8= X-Google-Smtp-Source: AGHT+IGIqOEFmF8Mu/FASfF7P65RQWGZzm9qTCAxZvpsz+0vbkzTgvcUN2KnnNMoLEzcUjvmf/0/0A== X-Received: by 2002:a17:902:d4d2:b0:1d8:ebdf:182a with SMTP id o18-20020a170902d4d200b001d8ebdf182amr328261plg.44.1706663226858; Tue, 30 Jan 2024 17:07:06 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 17:07:06 -0800 (PST) From: Charlie Jenkins Date: Tue, 30 Jan 2024 17:07:01 -0800 Subject: [PATCH v3 2/3] selftests: riscv: Generalize mm selftests MIME-Version: 1.0 Message-Id: <20240130-use_mmap_hint_address-v3-2-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=8909; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=O8gOkv0E1+A6kkia3nAEslnYUt3oCjYhoTGBKmBpp+k=; b=WDJobdBUYFFYtVz4fM3mc2BW26h1VmQ6/aM6YFyqcKnkZdKdsSDlfHr/m8269BVavOJ6niR8o kbLZ7INj1slC1TxiJM+zGX+bV9o4qK/6r+wzMsvzUXhyAPr1DF8kVVD X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-Rspamd-Queue-Id: E906880020 X-Rspam-User: X-Stat-Signature: oksyg59sqyxcr148xjyfgz19uu6q597n X-Rspamd-Server: rspam03 X-HE-Tag: 1706663227-397669 X-HE-Meta: U2FsdGVkX1848xKksWdYVGhfUXLXy91qfICXhIGtX+xxHiGk40H/jUkx0UipZd2gIsixktqMK3FytYI0pKqU2s6r+dY0yqtEe+Ov7JA5ODlfgV5AI6keOaGBFlwUWQyRcEuTyieGLr8kEDdL6tCJX8kGYkEM9qtprIIfDeCN8p4EsCOQB635pHl25+dl8+2cRBtj4KnTGw92lVP+2ejW0kdO5v7D09wfofrjciBY9zvQIn/fg95OIbLUxImS8uJJOg18Jweb0G9iW1XdYss+YEmgNapECtAAvG+nddkBz47WEGKJPeP2n3R4+IJmO6FTApoXzWJGqBzI/qg5CNDxl2LikRzITamvat+AihBoRWfCLDW1KGlAZCCGU4nsfmMF0ZAnIKy6nUDXezuh9dBD583lF26Scjj57KmNHnl92d/D5CgTJhKF1kiq+Kz6rfY8JKPawEsvaX99tbUNGjp4ydsmeHHXRatafZbgALmMn9r59OS1f7ZKATmGlK7UsbTocJ99hXl2l5L/T4UPcdqrbh0A/BgRRHN92uqOsXAcDwhjtzzeEiwNrWwDY1WnyY6fP6RqlopH3XkDXxTLPIPlqyoG+lwyJogd//6T0LYYt2/QWmP6ZPvxIUEIaBQeRuiF9laaxGNk1ArZCipm1D+bYTQOlFedzF2yJz6WJQBh81+ZzXp4qZawcZNgQVSjU8aOoXlvtzRl3O0Wn9zzxsNH3qZgntdvRedteErkjXVtWOXzmBfuHmgVH/9RizAI36YWk0KOaRJFUwhTlDteHD1AqPc1vDAluCnSckRhYFmurVhfrD4sWobWApYq4HQJdeXQ3nMzrCGRbba4eq+nvlW63NuKIYWQRYKaAvH5u80y17REfjGm83G87lP7v6kD/vYZiApFekAxnXYFD06RkUgnUWGQQcxOJaYuZL6YBuTDJNUyMtkcj3ZF4tZwC8lBCDLu/tHr6gU/IZ5yrZy8ds5 CTu/HnHz TWWQVg3+CZQPR5yR8J+fwnJi0aocLHJDus8LT+EPW/I2XpEONMq41mVC88aObiajXgGPqfCephhJ/zaU5CXdjfmfwE+iaJOkbT8gqIkCmSQPojLfnZt9+hACFfd8O/6RbZ8Zt77AQUucvhY0gaRIruDdNBzXgNS18Ojw+HZytzQy116jxIQBs690x71zGFHkPbbrFRxLgQ4E+o7REqaKFOAXp+qxZTNj+MRn74/8S395kwDAcv/5kr72gOi6ByGjbuIpiMzBM1DlHu6JgEPitw7T6gBvJb3/K21ApX0PyT71c0SlEysLwq9G9m0jfGpCk+z13yO/t1f7f820PSMjuqWq8P3zgiDaxuSOQJ29foUN6ebH9EKYJREebaPXKBE4JWT2KMzOmWW/8Q4gbNlRqXd9ujXd+IBnIQjDKgtAyUbFxlPo7ZBBeX5pRv7uJAt+gNoTg2Uh+itbwG+o= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The behavior of mmap on riscv is defined to not provide an address that uses more bits than the hint address, if provided. Make the tests reflect that. Signed-off-by: Charlie Jenkins --- tools/testing/selftests/riscv/mm/mmap_bottomup.c | 23 +---- tools/testing/selftests/riscv/mm/mmap_default.c | 23 +---- tools/testing/selftests/riscv/mm/mmap_test.h | 107 ++++++++++++++--------- 3 files changed, 67 insertions(+), 86 deletions(-) diff --git a/tools/testing/selftests/riscv/mm/mmap_bottomup.c b/tools/testing/selftests/riscv/mm/mmap_bottomup.c index 1757d19ca89b..7f7d3eb8b9c9 100644 --- a/tools/testing/selftests/riscv/mm/mmap_bottomup.c +++ b/tools/testing/selftests/riscv/mm/mmap_bottomup.c @@ -6,30 +6,9 @@ TEST(infinite_rlimit) { -// Only works on 64 bit -#if __riscv_xlen == 64 - struct addresses mmap_addresses; - EXPECT_EQ(BOTTOM_UP, memory_layout()); - do_mmaps(&mmap_addresses); - - EXPECT_NE(MAP_FAILED, mmap_addresses.no_hint); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_37_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_38_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_46_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_47_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_55_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_56_addr); - - EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.no_hint); - EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_37_addr); - EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_38_addr); - EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_46_addr); - EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.on_47_addr); - EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.on_55_addr); - EXPECT_GT(1UL << 56, (unsigned long)mmap_addresses.on_56_addr); -#endif + TEST_MMAPS; } TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/riscv/mm/mmap_default.c b/tools/testing/selftests/riscv/mm/mmap_default.c index c63c60b9397e..2ba3ec990006 100644 --- a/tools/testing/selftests/riscv/mm/mmap_default.c +++ b/tools/testing/selftests/riscv/mm/mmap_default.c @@ -6,30 +6,9 @@ TEST(default_rlimit) { -// Only works on 64 bit -#if __riscv_xlen == 64 - struct addresses mmap_addresses; - EXPECT_EQ(TOP_DOWN, memory_layout()); - do_mmaps(&mmap_addresses); - - EXPECT_NE(MAP_FAILED, mmap_addresses.no_hint); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_37_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_38_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_46_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_47_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_55_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_56_addr); - - EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.no_hint); - EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_37_addr); - EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_38_addr); - EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_46_addr); - EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.on_47_addr); - EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.on_55_addr); - EXPECT_GT(1UL << 56, (unsigned long)mmap_addresses.on_56_addr); -#endif + TEST_MMAPS; } TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/riscv/mm/mmap_test.h b/tools/testing/selftests/riscv/mm/mmap_test.h index 9b8434f62f57..36e78d991d5e 100644 --- a/tools/testing/selftests/riscv/mm/mmap_test.h +++ b/tools/testing/selftests/riscv/mm/mmap_test.h @@ -4,60 +4,83 @@ #include #include #include +#include +#include "../../kselftest_harness.h" #define TOP_DOWN 0 #define BOTTOM_UP 1 -struct addresses { - int *no_hint; - int *on_37_addr; - int *on_38_addr; - int *on_46_addr; - int *on_47_addr; - int *on_55_addr; - int *on_56_addr; +#if __riscv_xlen == 64 +uint64_t random_addresses[] = { + 0x19764f0d73b3a9f0, 0x016049584cecef59, 0x3580bdd3562f4acd, + 0x1164219f20b17da0, 0x07d97fcb40ff2373, 0x76ec528921272ee7, + 0x4dd48c38a3de3f70, 0x2e11415055f6997d, 0x14b43334ac476c02, + 0x375a60795aff19f6, 0x47f3051725b8ee1a, 0x4e697cf240494a9f, + 0x456b59b5c2f9e9d1, 0x101724379d63cb96, 0x7fe9ad31619528c1, + 0x2f417247c495c2ea, 0x329a5a5b82943a5e, 0x06d7a9d6adcd3827, + 0x327b0b9ee37f62d5, 0x17c7b1851dfd9b76, 0x006ebb6456ec2cd9, + 0x00836cd14146a134, 0x00e5c4dcde7126db, 0x004c29feadf75753, + 0x00d8b20149ed930c, 0x00d71574c269387a, 0x0006ebe4a82acb7a, + 0x0016135df51f471b, 0x00758bdb55455160, 0x00d0bdd949b13b32, + 0x00ecea01e7c5f54b, 0x00e37b071b9948b1, 0x0011fdd00ff57ab3, + 0x00e407294b52f5ea, 0x00567748c200ed20, 0x000d073084651046, + 0x00ac896f4365463c, 0x00eb0d49a0b26216, 0x0066a2564a982a31, + 0x002e0d20237784ae, 0x0000554ff8a77a76, 0x00006ce07a54c012, + 0x000009570516d799, 0x00000954ca15b84d, 0x0000684f0d453379, + 0x00002ae5816302b5, 0x0000042403fb54bf, 0x00004bad7392bf30, + 0x00003e73bfa4b5e3, 0x00005442c29978e0, 0x00002803f11286b6, + 0x000073875d745fc6, 0x00007cede9cb8240, 0x000027df84cc6a4f, + 0x00006d7e0e74242a, 0x00004afd0b836e02, 0x000047d0e837cd82, + 0x00003b42405efeda, 0x00001531bafa4c95, 0x00007172cae34ac4, }; +#else +uint32_t random_addresses[] = { + 0x8dc302e0, 0x929ab1e0, 0xb47683ba, 0xea519c73, 0xa19f1c90, 0xc49ba213, + 0x8f57c625, 0xadfe5137, 0x874d4d95, 0xaa20f09d, 0xcf21ebfc, 0xda7737f1, + 0xcedf392a, 0x83026c14, 0xccedca52, 0xc6ccf826, 0xe0cd9415, 0x997472ca, + 0xa21a44c1, 0xe82196f5, 0xa23fd66b, 0xc28d5590, 0xd009cdce, 0xcf0be646, + 0x8fc8c7ff, 0xe2a85984, 0xa3d3236b, 0x89a0619d, 0xc03db924, 0xb5d4cc1b, + 0xb96ee04c, 0xd191da48, 0xb432a000, 0xaa2bebbc, 0xa2fcb289, 0xb0cca89b, + 0xb0c18d6a, 0x88f58deb, 0xa4d42d1c, 0xe4d74e86, 0x99902b09, 0x8f786d31, + 0xbec5e381, 0x9a727e65, 0xa9a65040, 0xa880d789, 0x8f1b335e, 0xfc821c1e, + 0x97e34be4, 0xbbef84ed, 0xf447d197, 0xfd7ceee2, 0xe632348d, 0xee4590f4, + 0x958992a5, 0xd57e05d6, 0xfd240970, 0xc5b0dcff, 0xd96da2c2, 0xa7ae041d, +}; +#endif -static inline void do_mmaps(struct addresses *mmap_addresses) -{ - /* - * Place all of the hint addresses on the boundaries of mmap - * sv39, sv48, sv57 - * User addresses end at 1<<38, 1<<47, 1<<56 respectively - */ - void *on_37_bits = (void *)(1UL << 37); - void *on_38_bits = (void *)(1UL << 38); - void *on_46_bits = (void *)(1UL << 46); - void *on_47_bits = (void *)(1UL << 47); - void *on_55_bits = (void *)(1UL << 55); - void *on_56_bits = (void *)(1UL << 56); +#define PROT (PROT_READ | PROT_WRITE) +#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS) - int prot = PROT_READ | PROT_WRITE; - int flags = MAP_PRIVATE | MAP_ANONYMOUS; +/* mmap must return a value that doesn't use more bits than the hint address. */ +static inline unsigned long get_max_value(unsigned long input) +{ + unsigned long max_bit = (1UL << (((sizeof(unsigned long) * 8) - 1 - + __builtin_clzl(input)))); - mmap_addresses->no_hint = - mmap(NULL, 5 * sizeof(int), prot, flags, 0, 0); - mmap_addresses->on_37_addr = - mmap(on_37_bits, 5 * sizeof(int), prot, flags, 0, 0); - mmap_addresses->on_38_addr = - mmap(on_38_bits, 5 * sizeof(int), prot, flags, 0, 0); - mmap_addresses->on_46_addr = - mmap(on_46_bits, 5 * sizeof(int), prot, flags, 0, 0); - mmap_addresses->on_47_addr = - mmap(on_47_bits, 5 * sizeof(int), prot, flags, 0, 0); - mmap_addresses->on_55_addr = - mmap(on_55_bits, 5 * sizeof(int), prot, flags, 0, 0); - mmap_addresses->on_56_addr = - mmap(on_56_bits, 5 * sizeof(int), prot, flags, 0, 0); + return max_bit + (max_bit - 1); } +#define TEST_MMAPS \ + ({ \ + void *mmap_addr; \ + for (int i = 0; i < ARRAY_SIZE(random_addresses); i++) { \ + mmap_addr = mmap((void *)random_addresses[i], \ + 5 * sizeof(int), PROT, FLAGS, 0, 0); \ + EXPECT_NE(MAP_FAILED, mmap_addr); \ + EXPECT_GE((void *)get_max_value(random_addresses[i]), \ + mmap_addr); \ + mmap_addr = mmap((void *)random_addresses[i], \ + 5 * sizeof(int), PROT, FLAGS, 0, 0); \ + EXPECT_NE(MAP_FAILED, mmap_addr); \ + EXPECT_GE((void *)get_max_value(random_addresses[i]), \ + mmap_addr); \ + } \ + }) + static inline int memory_layout(void) { - int prot = PROT_READ | PROT_WRITE; - int flags = MAP_PRIVATE | MAP_ANONYMOUS; - - void *value1 = mmap(NULL, sizeof(int), prot, flags, 0, 0); - void *value2 = mmap(NULL, sizeof(int), prot, flags, 0, 0); + void *value1 = mmap(NULL, sizeof(int), PROT, FLAGS, 0, 0); + void *value2 = mmap(NULL, sizeof(int), PROT, FLAGS, 0, 0); return value2 > value1; } From patchwork Wed Jan 31 01:07:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13538463 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 A9775C47DDF for ; Wed, 31 Jan 2024 01:07:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 801716B0081; Tue, 30 Jan 2024 20:07:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 78BA96B0083; Tue, 30 Jan 2024 20:07:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67B4E6B0085; Tue, 30 Jan 2024 20:07:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 56ABB6B0081 for ; Tue, 30 Jan 2024 20:07:11 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 381A81A0C38 for ; Wed, 31 Jan 2024 01:07:11 +0000 (UTC) X-FDA: 81737817462.12.C8EF65D Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf27.hostedemail.com (Postfix) with ESMTP id 4258040012 for ; Wed, 31 Jan 2024 01:07:09 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=CI5Z4vIL; spf=pass (imf27.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.175 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=1706663229; 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=GGh1y1t0UhB5LcXiFRn0m1YgEny22RmTe/CDN12WiLQ=; b=mxFNEKDsZ6Jlha2Weii7MSazXiM+5o1TK2TzTagwDIHtL8KsKNpiA6hoNa9EjIoqrgkN1W C67WSee47e63XSV87WNr+EHmmF8P49jR6p+yfnfMeiWDhCwkD4dgRP2/W8IHSbq7LPNm82 NJQlvvScST9o7kLRqr+G5EU6IvYSdjQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706663229; a=rsa-sha256; cv=none; b=qHPIiaFLX9H6U+xM7ud2vya5nk1aPOoi9ei37JDgQ7PsRxdKD+3kzSX76Pl2bgwiiPLvCS zaEnXkZcqqes2t1lTGHl+orycvNg0qoVnaYXMaei0EOLiw8UTqdV9yOE5V5CnGR+Jjtoie DdxQgzlKFElZw3T1HmjAhvB4ozj2mPA= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=CI5Z4vIL; spf=pass (imf27.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1d746ce7d13so38370095ad.0 for ; Tue, 30 Jan 2024 17:07:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706663228; x=1707268028; 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=GGh1y1t0UhB5LcXiFRn0m1YgEny22RmTe/CDN12WiLQ=; b=CI5Z4vILW/+g5KEt9eu2r1icAXOb2HwOcvjJIiVxkH21MHfgnfC/k6V8p9QH4dfDWD CtIIyrMQBQIMAAycf745tAAyzVk926ikskdLI/usOAxvx1UhM7Cs6a8WH6wZIZqj0Vg4 3eawIB2uYtpPywGhdZWBo6MvdMWz63BBzfcF07CZoI/MZALUzIyuUeOoc+cbvCmct7f6 8gL7fZxX7YylPD4oGvUqlDR9oozR3hQGv54hVxR4rM/1MllrV8/iqW8umrEP5+9LSsBX 8rhp0ODwHylVM54RcDWNoiLBGXeUYOZyQIo84KJoTiLIgThA8cMupKNto+jYDn92bN7D LbCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706663228; x=1707268028; 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=GGh1y1t0UhB5LcXiFRn0m1YgEny22RmTe/CDN12WiLQ=; b=M30LbC95W7PFS9/ssIXQTBwDyQ5YSepaa6kEYaEoaltrNSyM5sF/f9yvoWn5+gER34 xWF0EChJH3M8TfFAniOK518VsEnwifoOtG6V8+Zv0TCvJDuDPj7euF1ZZ8OUDV3Xl8+k G1AjG9kuL/KRxM8tPck3TQO8ERyLuirKZ+HE4QfirZygkc7LheI9GpMf4cp/wjp/yeox HhFs20GpdwPOtvp4P8GWsfDZMiHpVM5PFIeZC+2zKLBdkuNcd5NsOjV9JfseqYMegIWF 2yUDCsoyhL9YjfYmfBTN+lVEri48CkmsRm6HgVadHI5lPOgHYh5MZCkpg3hfzdZHhvIP 6Xgw== X-Gm-Message-State: AOJu0YxCgJlmq1ujDYxA3ubDccRcAjlB4ePe7LLQHE/HKsmkGLWeCBb9 X1vNPZHAcBMcq2AVWHrSde+OoNS/S+RkU38cH8SH4Bkqna0H9ara9dDBf/a+EFA= X-Google-Smtp-Source: AGHT+IEmbM/VilqQzN+bDSe1zgWZkRRaNPdWi6aSgLeBxKervvgWyww593Ha65RTd+Oj6JpwZn8mJA== X-Received: by 2002:a17:902:ed94:b0:1d7:310e:1e0d with SMTP id e20-20020a170902ed9400b001d7310e1e0dmr263865plj.32.1706663228198; Tue, 30 Jan 2024 17:07:08 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 17:07:07 -0800 (PST) From: Charlie Jenkins Date: Tue, 30 Jan 2024 17:07:02 -0800 Subject: [PATCH v3 3/3] docs: riscv: Define behavior of mmap MIME-Version: 1.0 Message-Id: <20240130-use_mmap_hint_address-v3-3-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=1848; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=2lxtSNzBMdkYqwC90W41TvLPqjzE8CkjIf8iMq/P7L4=; b=VULcNJMPaGSSibunnHmdY8O6pSGdUfVoHdHqVkSZ/6IDh4hPdQyOg/2Va726eHw2pMLSxc0cG 87Fixe/YDGPCXhl08WlTq3vxGBa82+KW2s0J79eiJ6OVp8GW8Fgr/ii X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-Rspamd-Queue-Id: 4258040012 X-Rspam-User: X-Stat-Signature: p6a8ux474fkpjcj57zi7amuy89jyhtjt X-Rspamd-Server: rspam03 X-HE-Tag: 1706663229-512288 X-HE-Meta: U2FsdGVkX1+jyWhHJtJzqDq4B+x/4DAsCtsvUWDtIYiMHyGZzX/WvIa/RPRIR/it3LdKZVx/Nh3EEB4mtGkp9HEVc5sLSP5MySYPf6KlG9hdEx2J7o5SQhSvAtZqKIVz8OgNbb3V1S5NNvyK5SESZUf3+S7+Z064WYbSgwt838MymLdw/58eTeuaEB5ECPdIki9umJFZU27bTIKw7+1TdGVG2MtzBli7e3600x3o3zBDc2uXt4q1lzIGtet1A+Bm8BUfYLlQMwycsKzSBV2bjTkSrcUDmy808lSFx5Pgg507psFxtwj6sOC9YSpB9RnokTfEr9io0uZldp9qjTc77m6e0hZSXIX/l0g56OEf+ZmpOh68zKuqsXakG4GLCzqeTgRBxThfIpbzvqeaHFgZIE1ONW3YhP1dju8qDQRNegRmRHg4pgg02QsuMM0Vb/iuHgHefqQNGoqEZw7dGr6PLWqFsStwrKLy2Eu/mQckJvSw7xtthXGDhQO1VC0BGDgRZk/W8w/5/yv9/ZUZ05cpPjADuSkzQq0irH7dQx0CS9j+5nZOPvpQbRwTdQLCKZ+a1oR4qd7QpTT33DIyYEi5Tav5HMhk+OeE04mTYw/lDEeGSK3J4APooeZ25EEBhNB1VkfKGHXn3opx3cb0Wc4KtMkksVlazoCUwiZ7EK9qK2HzSqh7TU8+QBQV+Ofl1kS0GacApA4f7t5ZaJQ0rVf169cgnf0SOyRNbbjN62ld4pLREA8UBVUqdg42YtalJ7gjiRuuLgpm6ojLJ0dHWNtuhrwzLNTcVuz2cTZwiAT3l5ZZJUOrcXKfjD+Dfdh6RbIgi/WvKrHi9aTpGYbv/T44ED8f/7tilLL0LXvaOIQmbOkWIys+AfwT5wATfEzYWwYMb84nZKlyMseJdG+QSFj9dx+UIlPUcrDNXuiNWyKbThf38FTeMhwDEzu2FnzH3sYmJLp1ZIQO1thYrVKBGXC i+Q/wcgI hiDGNLSvihqpXUYfoio/j53A2M37oie+ynJM8CfPN7mn1TE4b7GfrT0ztK1s2InLRabIvV/UNvRnZSMdRGlcMtAvNMDmOOoI5M0GHPV6tgFfNJkmgHLz9JqY44d19aCRLHICbfMTncH2rIVO8vlVRy+G0zfuRzp6ejVoxUQmD3iNdOaxKFVQtXrAi1ZyP+RQCK0wx933xUjY7/yuf7UoOEGTsa+A8wxb09e2rjN1Mof146tn2XbFghXn6nmu3kgPmPs3kMPpx26LJ1z34Q0bWMOc74E7Ig5BEVzsQzR//RRhrnlXXkMLpBCeV9heFpokYrYlEzKnh6XExCqilL94FcluMrriXKgmSL/MlE4sjNNJ1FjHVFSlGTt9u95WpnXItp6YOKKmkrN6mifcJiM7gwZ0SKg5Ov75rAqvYn8/tiTvz877R02IxopFXkIkYCcX6Fk6mNEL135EiiJycHLT1ec7hoA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.115465, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Define mmap on riscv to not provide an address that uses more bits than the hint address, if provided. Signed-off-by: Charlie Jenkins --- Documentation/arch/riscv/vm-layout.rst | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Documentation/arch/riscv/vm-layout.rst b/Documentation/arch/riscv/vm-layout.rst index 69ff6da1dbf8..e476b4386bd9 100644 --- a/Documentation/arch/riscv/vm-layout.rst +++ b/Documentation/arch/riscv/vm-layout.rst @@ -144,14 +144,8 @@ passing 0 into the hint address parameter of mmap. On CPUs with an address space smaller than sv48, the CPU maximum supported address space will be the default. Software can "opt-in" to receiving VAs from another VA space by providing -a hint address to mmap. A hint address passed to mmap will cause the largest -address space that fits entirely into the hint to be used, unless there is no -space left in the address space. If there is no space available in the requested -address space, an address in the next smallest available address space will be -returned. - -For example, in order to obtain 48-bit VA space, a hint address greater than -:code:`1 << 47` must be provided. Note that this is 47 due to sv48 userspace -ending at :code:`1 << 47` and the addresses beyond this are reserved for the -kernel. Similarly, to obtain 57-bit VA space addresses, a hint address greater -than or equal to :code:`1 << 56` must be provided. +a hint address to mmap. When a hint address is passed to mmap, the returned +address will never use more bits than the hint address. For example, if a hint +address of `1 << 40` is passed to mmap, a valid returned address will never use +bits 41 through 63. If no mappable addresses are available in that range, mmap +will return `MAP_FAILED`.