From patchwork Thu Jul 27 21:26:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13330781 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 700ECC00528 for ; Thu, 27 Jul 2023 21:26:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EED9D6B007D; Thu, 27 Jul 2023 17:26:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E517B6B007B; Thu, 27 Jul 2023 17:26:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C543B6B007D; Thu, 27 Jul 2023 17:26:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B2DC46B0078 for ; Thu, 27 Jul 2023 17:26:55 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8853EA059B for ; Thu, 27 Jul 2023 21:26:55 +0000 (UTC) X-FDA: 81058676790.10.9169097 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf10.hostedemail.com (Postfix) with ESMTP id ACE3AC000D for ; Thu, 27 Jul 2023 21:26:53 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=WUyJwKJP; dmarc=none; spf=pass (imf10.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690493213; a=rsa-sha256; cv=none; b=IJ0s1bPuifKYlooLGY9Hzls1yjQT+vi6uD0c9PeCxGiRa3WBrtiTXIrQ0xwdQ3RUX6xGao /rfpBarRqzRIf4YZHSbIWzgIUYMUHAXrfpoYHXzLS8+DLdYqbiV/V8nYnpqXYntmBpDi6Z 7q2SwXPxiA4+rDsUOI2FEpHhK5UPcOs= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=WUyJwKJP; dmarc=none; spf=pass (imf10.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690493213; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=L3MSUXAZDlHxvJw5XBpFpvl/fyG6WFk9gov0cKUKQOU=; b=75k157xiodySovQOIRIz3V+uBtcnGLW/rU0stVCrS2a16bh5Xh3phjrLTVQRyVYFFjJQck 82vvpb5dtKdJp9+ZAhWR3IH+7WUORnVkWb8qTypQSLVN7Z0/ARlUHSeW3FLAcbBUrmYTGB yPjkyMGR5u9pUgrZHOsNeZdcZHYw0As= Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-686c06b806cso1131258b3a.2 for ; Thu, 27 Jul 2023 14:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690493212; x=1691098012; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=L3MSUXAZDlHxvJw5XBpFpvl/fyG6WFk9gov0cKUKQOU=; b=WUyJwKJPX1jLH0ROd0fzWsfMZAkoQJ/zQofoMYk2lYdpobktAenlvABnk4JZwHpjY5 WvDq42U+gPL5MSTDxgvDRE6dXZTLh2FU/It8UyINzwEmymclonR4Y0AOvW5Z9Q/HA+hP UlAqHQbkeq1NLlVumQpfaDTbUcBjZ9pc/asdJ/p2EJm3zv0/rShcn1MU94GGVB8bsh+p rAkAcX9PQ06tbc6DdqNHbIa9qN4MoDe9IOgqU293iqT+rn1hHXDprtEdFDmsD5goGQnb KHFXw3D3dfM3/81YOre3JxqvqQjO5sIPW33VQ3yHsa9UPrEKTcSMpZBUp1PjeVpohIQh IUuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690493212; x=1691098012; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=L3MSUXAZDlHxvJw5XBpFpvl/fyG6WFk9gov0cKUKQOU=; b=fdauH4fMHbwyK1YMl88JFvxZVaKsz5nUzUhAqQ4hVYmAR8XzJU4tdjKh896m4GCzXb OgpkWmhZIQfb843/kOEg3Gvultg6RQhy/LzfALlNsoDLRzR4hVOK3vZdv6Z5X7oixf08 GAUH2MkfFpeqGKZxWzCjLlb/5EQ3tZy0wWS1DZ1UA0HMagEJHAavXAtW/lsdI00Lfeum F8wOrIIhTQOGP3RXTocT6NJJDhiLjgZVdCAe1E0eDJdY2vx9qvsJXmInbzzs+4lxNMXU jUi6LAohybMjXaIWZZAoCNj3n7AeWpTYuROL/vVFQCo6ZtkqkL039hC21NXekoLm+36t s81Q== X-Gm-Message-State: ABy/qLYE93pdfW12PiEvsyv97v8PTxDFtn3gmfwjuMJS3jEHmvi0CI5Y 9cTnaRh0EXl2iaQxcefgmkSRKg== X-Google-Smtp-Source: APBJJlGaUoECRIux0BUm3diAsqoj6PNZLuLLwkdpIzX5n1LpY2mGSBcBTtHRABOlgGcWfWQnA6vSiQ== X-Received: by 2002:a05:6a21:6d87:b0:137:68c3:c86f with SMTP id wl7-20020a056a216d8700b0013768c3c86fmr324290pzb.55.1690493212471; Thu, 27 Jul 2023 14:26:52 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b00682562b1549sm1912312pfd.24.2023.07.27.14.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 14:26:52 -0700 (PDT) From: Charlie Jenkins To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: charlie@rivosinc.com, conor@kernel.org, paul.walmsley@sifive.com, palmer@rivosinc.com, aou@eecs.berkeley.edu, anup@brainfault.org, konstantin@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, mick@ics.forth.gr, jrtc27@jrtc27.com, rdunlap@infradead.org, alexghiti@rivosinc.com Subject: [PATCH v8 1/4] RISC-V: mm: Restrict address space for sv39,sv48,sv57 Date: Thu, 27 Jul 2023 14:26:26 -0700 Message-ID: <20230727212647.4182407-2-charlie@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230727212647.4182407-1-charlie@rivosinc.com> References: <20230727212647.4182407-1-charlie@rivosinc.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: ACE3AC000D X-Stat-Signature: rwn496hnx856si6wqssfows73rr9pg67 X-HE-Tag: 1690493213-815851 X-HE-Meta: U2FsdGVkX1/mW/887vmy2PGjPbgzLnRCVpWvmAZxaQ8I/oo+VJ0JE+uXcDSbjXFHiAelZzQXZP6wsm9ZSQkjz5mJdWFrrCqoIoHtEc/lamc41tqO3VTlw7uttDoi7UajPXO3ipucPPZ9zq8h010z/t81BJDzM3inVblb5rffVVh9hhDZbffjW57lnmyd4H/GEz8U2pBvsTozh2CWXNOf0Dnrh4QWA3ejpP1otKHZnsKsZcdYtxm2lU5c2HsP37vYseFbdBQFh8/hoSboRGp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N/AwBWR0sfsE4SzPb+Rfbhji81CWB/Jf+Dh/W19nXa8GIhn3T5I5DRsdIf9WLcezE5cu9nDC7WB6+JpC6oOsU47UCND X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Make sv48 the default address space for mmap as some applications currently depend on this assumption. A hint address passed to mmap will cause the largest address space that fits entirely into the hint to be used. If the hint is less than or equal to 1<<38, an sv39 address will be used. An exception is that if the hint address is 0, then a sv48 address will be used. After an address space is completely full, the next smallest address space will be used. Signed-off-by: Charlie Jenkins --- arch/riscv/include/asm/elf.h | 2 +- arch/riscv/include/asm/pgtable.h | 20 +++++++++++- arch/riscv/include/asm/processor.h | 52 ++++++++++++++++++++++++++---- 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h index c24280774caf..5d3368d5585c 100644 --- a/arch/riscv/include/asm/elf.h +++ b/arch/riscv/include/asm/elf.h @@ -49,7 +49,7 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr); * the loader. We need to make sure that it is out of the way of the program * that it will "exec", and that there is sufficient room for the brk. */ -#define ELF_ET_DYN_BASE ((TASK_SIZE / 3) * 2) +#define ELF_ET_DYN_BASE ((DEFAULT_MAP_WINDOW / 3) * 2) #ifdef CONFIG_64BIT #ifdef CONFIG_COMPAT diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 75970ee2bda2..c76a1ef094a4 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -63,8 +63,26 @@ * position vmemmap directly below the VMALLOC region. */ #ifdef CONFIG_64BIT +#define VA_BITS_SV39 39 +#define VA_BITS_SV48 48 +#define VA_BITS_SV57 57 + +#define VA_USER_SV39 (UL(1) << (VA_BITS_SV39 - 1)) +#define VA_USER_SV48 (UL(1) << (VA_BITS_SV48 - 1)) +#define VA_USER_SV57 (UL(1) << (VA_BITS_SV57 - 1)) + #define VA_BITS (pgtable_l5_enabled ? \ - 57 : (pgtable_l4_enabled ? 48 : 39)) + VA_BITS_SV57 : (pgtable_l4_enabled ? VA_BITS_SV48 : VA_BITS_SV39)) + +#ifdef CONFIG_COMPAT +#define MMAP_VA_BITS_64 ((VA_BITS >= VA_BITS_SV48) ? VA_BITS_SV48 : VA_BITS) +#define MMAP_MIN_VA_BITS_64 ((VA_BITS >= VA_BITS_SV39) ? VA_BITS_SV39 : VA_BITS) +#define MMAP_VA_BITS (test_thread_flag(TIF_32BIT) ? 32 : MMAP_VA_BITS_64) +#define MMAP_MIN_VA_BITS (test_thread_flag(TIF_32BIT) ? 32 : MMAP_MIN_VA_BITS_64) +#else +#define MMAP_VA_BITS ((VA_BITS >= VA_BITS_SV48) ? VA_BITS_SV48 : VA_BITS) +#define MMAP_MIN_VA_BITS ((VA_BITS >= VA_BITS_SV39) ? VA_BITS_SV39 : VA_BITS) +#endif #else #define VA_BITS 32 #endif diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index c950a8d9edef..e810244ea951 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -13,19 +13,59 @@ #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) && test_thread_flag(TIF_32BIT))) \ + mmap_end = DEFAULT_MAP_WINDOW; \ + 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; \ +}) + +#define arch_get_mmap_base(addr, base) \ +({ \ + unsigned long mmap_base; \ + typeof(addr) _addr = (addr); \ + typeof(base) _base = (base); \ + unsigned long rnd_gap = (_base) - DEFAULT_MAP_WINDOW; \ + if ((_addr) == 0 || (IS_ENABLED(CONFIG_COMPAT) && test_thread_flag(TIF_32BIT))) \ + 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; \ +}) + +#else +#define DEFAULT_MAP_WINDOW TASK_SIZE +#define STACK_TOP_MAX TASK_SIZE +#endif +#define STACK_ALIGN 16 + +#define STACK_TOP DEFAULT_MAP_WINDOW + /* * This decides where the kernel will search for a free chunk of vm * space during mmap's. */ -#define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) - -#define STACK_TOP TASK_SIZE #ifdef CONFIG_64BIT -#define STACK_TOP_MAX TASK_SIZE_64 +#define TASK_UNMAPPED_BASE PAGE_ALIGN((UL(1) << MMAP_MIN_VA_BITS) / 3) #else -#define STACK_TOP_MAX TASK_SIZE +#define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) #endif -#define STACK_ALIGN 16 #ifndef __ASSEMBLY__ From patchwork Thu Jul 27 21:26:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13330782 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 4623CC001DC for ; Thu, 27 Jul 2023 21:26:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 74E136B0078; Thu, 27 Jul 2023 17:26:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D6206B007B; Thu, 27 Jul 2023 17:26:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 528B96B007E; Thu, 27 Jul 2023 17:26:57 -0400 (EDT) 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 441F36B0078 for ; Thu, 27 Jul 2023 17:26:57 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0677E1A05AC for ; Thu, 27 Jul 2023 21:26:57 +0000 (UTC) X-FDA: 81058676874.28.9716BA6 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf24.hostedemail.com (Postfix) with ESMTP id 0F81918000C for ; Thu, 27 Jul 2023 21:26:54 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=Sg1Dwaa2; dmarc=none; spf=pass (imf24.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690493215; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uTyjwJ6/AkKvsr8TkfjD+hMv/+AP+4ITK7UKxmmUnHc=; b=xyjehjrOT1E6lS0JmP2ddkaEes28LNK0+BDvqU5Jzoc6Bj6oqRrnIU6c1swxE6iuGykvn6 jqTWowDAcB4vn3aqiExs1w23cB2nrmsGD0E+x1zcg/G7J8a85XVIYFsGZJk9E/S9r9YxIW 1YN4eG8Dg5nloudr1jK/kOdbpcnDCUE= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=Sg1Dwaa2; dmarc=none; spf=pass (imf24.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690493215; a=rsa-sha256; cv=none; b=VcvtggXuzJ8kcVg5E0gfBE+MQYUM3mINqDU0Mu7cEKg3wtldcpDoPQwhT39YN9GNAudJoq r4gFTIl7h3VdRpDhAAtJ9I0KfCzpw1dr/SaYCxHqiUzGnZwsrikYQM/7M/5oMwFMFbdbm/ yw6TdinHhnv2lHIwefeVi5TY7W0UNnU= Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-686efa1804eso1134881b3a.3 for ; Thu, 27 Jul 2023 14:26:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690493214; x=1691098014; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uTyjwJ6/AkKvsr8TkfjD+hMv/+AP+4ITK7UKxmmUnHc=; b=Sg1Dwaa2hhNk+ptzUWDlhDziLQ7BYdhCwNr7XG+A7ALHhZ6cxngoMChZZks5hfTrMs MphNFVoom+/MTDIlLL3A0DgafopRx4dG9XeqhwbGAxXetU1et0fbhYOxFtD5wZX4Un9f MxohIFvJ3Bx15Dy3QaN+juClp/XtolsHoBP7WewspMul+5TyY3LFsvYFsa+p+F7dASAs 8KzKQ7sAuXE9YTKFSYoI2gSyDYJbuSzFCX3R0xBHM0kWH/4hzGeWQQwKjUtC3LPWQUqZ hvRPDa8Gi9VIS6DsUtg8Guw7ADzJjJpxUC95YnIXmy9ctQprbV7s12dIRS4wmTWwrHqA LhZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690493214; x=1691098014; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uTyjwJ6/AkKvsr8TkfjD+hMv/+AP+4ITK7UKxmmUnHc=; b=bRlDOhiqbfADARyBqwYRVSZ65oN0c/xeBPLdIXBhB4QUtnh61txrp2kUEYxFDt2VTP USmYtxn/EBTblfMifsukB9UWjpOCf1be9S3WfTKOnUn8hH/VeoXfRxMjQxrkn1UKx7ZA /rcHMGPJgnv4/YhFjB9JuEYk4fYB4AVaiN8XtscqI6JYYvi6nZwPzg1NMuRwLcCRz+cy nelY0aGc3IFAOcUuDqTyK+Yqq8ZGzUxfptTqWvWx3WApZkrcuetSsWJT63yUoTSTg7Ur vRjgrbwLi2ao0Yv68oQXBCpyJLsU3VpLrQdHuDi9prWVQWI+ofiP6L5qy5l4RXHdC+9S bIJQ== X-Gm-Message-State: ABy/qLZFe0rIeIgZG38MqDNmWG76P2pLyTcPVyur38Nv3KWuS/UZ3wKM CXfZKjJhkpmpIXIPtfjQVhTqfA== X-Google-Smtp-Source: APBJJlFFWYLTEbKLA8egXy5s3u+cXeAgzBIdat1e55NXRuoAca70SNRbD9GZigSou7wX9EmZTVDckA== X-Received: by 2002:a05:6a20:3d21:b0:134:f040:e967 with SMTP id y33-20020a056a203d2100b00134f040e967mr255099pzi.61.1690493213881; Thu, 27 Jul 2023 14:26:53 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b00682562b1549sm1912312pfd.24.2023.07.27.14.26.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 14:26:53 -0700 (PDT) From: Charlie Jenkins To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: charlie@rivosinc.com, conor@kernel.org, paul.walmsley@sifive.com, palmer@rivosinc.com, aou@eecs.berkeley.edu, anup@brainfault.org, konstantin@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, mick@ics.forth.gr, jrtc27@jrtc27.com, rdunlap@infradead.org, alexghiti@rivosinc.com Subject: [PATCH v8 2/4] RISC-V: mm: Add tests for RISC-V mm Date: Thu, 27 Jul 2023 14:26:27 -0700 Message-ID: <20230727212647.4182407-3-charlie@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230727212647.4182407-1-charlie@rivosinc.com> References: <20230727212647.4182407-1-charlie@rivosinc.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: sthjxosorij7ioezr51xmautyxwj9937 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0F81918000C X-HE-Tag: 1690493214-422653 X-HE-Meta: U2FsdGVkX18cOGkT0aape5s25eZEPrKzkyfxrIzG7Vwe0OJmo0CD//aKpDe/IyeevbVZL62BX3qXoXTk5pBazvqGqYj4W4SK4ISxtk7j14Opo+C44r/C2Mqp1oD+e8IWJ/845dqXWpM/4Un3Y7m5SOlDxYIkBsp+jJxb6zAqOuos6iFCpeZcwgG++5VZPCQ7JkTUmuohQY3pXHsxMEZM6fbHPprnkTRuUYQ2i8KZ58/tPaL4gA4SfT/wCuy3FXwXxHnKdPhLbArCTSZaDwzY7ydxv8TmOu+xYf+4Xm9EupMf+8eb+UN+G/ln0OJqebF0OkmwfWSTxlTaya+u+rhkKWWhdHW9XtdMIthEvL+NwPJm1dL8X5Bja0KS/vGkLnjjX+B6oztKgsYqf3/MgZuJwAiL3Vgaj2FIgW/cal623ZkfilfGIQyBkUuLk+Tctxa09yq0TJoLHfqGuy3cu5+XtTPk52mu4eIwSrD0bmYW7aXDQvvmaQ4tzN2RtBuHuWSfZe0yKD5vjGzWDXldbWn/qJK3USnxCHbaxVEuy58Xd8OX11bDhYcwqwGqjFDYTSBJR6YLZShFKkmVhTRk16CHELa2v8qUOZMcxZ5+r2ez9RVPzK5PXO8HqqWLjEmbBiLvfFCi4BLrIsqnxq9z5+AucHULoaRTqf3fuYCAn1R0WHsMeA2DQ6So+EKZHciYa59C7DcBQMujZ1OddnobH92A+rytlp81fSOMxfV4OKsh71aIEcHjaL1brG1oqLP6rxXKEw5GrjNrDmPK94cym8ZV3c2hHcAGHTRgok5S2rh4nFheMWacBj8Wnk3OUaSQNKh4E68ZvybDea9t2EGOr98GudIBuVebOLI4uP1L2xfubmiOwiHLcHbiePrNiUXrJuSN8ifh3egptltDYZsIUNfgV1/qTUEVqLKiw6bRhtilOByx0YFy9Fb8kCxBGri2TiTEKdnWq488ia3j/kKQA88 WwsOL60P Jrrd20g24LHIx28Pr85tXsbSv6gxpZ4JJGiSJm/b0J/IiFBUA3m5AbKfN6UPEx35E0ikcY8xu6FWfLWSn+aSQuWH+eOeDRJcWH15RT34J2LaeWJKE0hKiRe/HM6hgVBTqkuKXIUEffHS3Ou6GGWytvVjy32iZHj/VbfD8tldMqo2xCpZAPpPQb5R7zfv7gXZEzXQhdmkwQFMJNwrvs6sts8kmWVC6K/KChD0mZtSc17oapQqqOOnVNSUTInrmm7SWSZFnIPTWZsLI3I7tIQ1LywVZhOZuT/dNyr1zkcSEiaXwFdlO6lrHJh1Wta/SpEikUhnIC1tgJuWJMpQv6226z+WoU5iypVCnL//nRBS3LInn0KfLDd4Mn95x6pe0ReYxWAD2kIkN3KUFbw18BakKVcRr8DC0yz4PsgMLemVbfWsyYVcovw/hFlcBf26SGN8TQu/r X-Bogosity: Ham, tests=bogofilter, spamicity=0.026175, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add tests that enforce mmap hint address behavior. mmap should default to sv48. mmap will provide an address at the highest address space that can fit into the hint address, unless the hint address is less than sv39 and not 0, then it will return a sv39 address. These tests are split into two files: mmap_default.c and mmap_bottomup.c because a new process must be exec'd in order to change the mmap layout. The run_mmap.sh script sets the stack to be unlimited for the mmap_bottomup.c test which triggers a bottomup layout. Signed-off-by: Charlie Jenkins --- tools/testing/selftests/riscv/Makefile | 2 +- tools/testing/selftests/riscv/mm/.gitignore | 2 + tools/testing/selftests/riscv/mm/Makefile | 15 +++++ .../riscv/mm/testcases/mmap_bottomup.c | 35 ++++++++++ .../riscv/mm/testcases/mmap_default.c | 35 ++++++++++ .../selftests/riscv/mm/testcases/mmap_test.h | 64 +++++++++++++++++++ .../selftests/riscv/mm/testcases/run_mmap.sh | 12 ++++ 7 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/riscv/mm/.gitignore create mode 100644 tools/testing/selftests/riscv/mm/Makefile create mode 100644 tools/testing/selftests/riscv/mm/testcases/mmap_bottomup.c create mode 100644 tools/testing/selftests/riscv/mm/testcases/mmap_default.c create mode 100644 tools/testing/selftests/riscv/mm/testcases/mmap_test.h create mode 100755 tools/testing/selftests/riscv/mm/testcases/run_mmap.sh diff --git a/tools/testing/selftests/riscv/Makefile b/tools/testing/selftests/riscv/Makefile index f4b3d5c9af5b..4a9ff515a3a0 100644 --- a/tools/testing/selftests/riscv/Makefile +++ b/tools/testing/selftests/riscv/Makefile @@ -5,7 +5,7 @@ ARCH ?= $(shell uname -m 2>/dev/null || echo not) ifneq (,$(filter $(ARCH),riscv)) -RISCV_SUBTARGETS ?= hwprobe vector +RISCV_SUBTARGETS ?= hwprobe vector mm else RISCV_SUBTARGETS := endif diff --git a/tools/testing/selftests/riscv/mm/.gitignore b/tools/testing/selftests/riscv/mm/.gitignore new file mode 100644 index 000000000000..5c2c57cb950c --- /dev/null +++ b/tools/testing/selftests/riscv/mm/.gitignore @@ -0,0 +1,2 @@ +mmap_bottomup +mmap_default diff --git a/tools/testing/selftests/riscv/mm/Makefile b/tools/testing/selftests/riscv/mm/Makefile new file mode 100644 index 000000000000..11e0f0568923 --- /dev/null +++ b/tools/testing/selftests/riscv/mm/Makefile @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2021 ARM Limited +# Originally tools/testing/arm64/abi/Makefile + +# Additional include paths needed by kselftest.h and local headers +CFLAGS += -D_GNU_SOURCE -std=gnu99 -I. + +TEST_GEN_FILES := testcases/mmap_default testcases/mmap_bottomup + +TEST_PROGS := testcases/run_mmap.sh + +include ../../lib.mk + +$(OUTPUT)/mm: testcases/mmap_default.c testcases/mmap_bottomup.c testcases/mmap_tests.h + $(CC) -o$@ $(CFLAGS) $(LDFLAGS) $^ diff --git a/tools/testing/selftests/riscv/mm/testcases/mmap_bottomup.c b/tools/testing/selftests/riscv/mm/testcases/mmap_bottomup.c new file mode 100644 index 000000000000..b29379f7e478 --- /dev/null +++ b/tools/testing/selftests/riscv/mm/testcases/mmap_bottomup.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include + +#include "../../kselftest_harness.h" + +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_HARNESS_MAIN diff --git a/tools/testing/selftests/riscv/mm/testcases/mmap_default.c b/tools/testing/selftests/riscv/mm/testcases/mmap_default.c new file mode 100644 index 000000000000..d1accb91b726 --- /dev/null +++ b/tools/testing/selftests/riscv/mm/testcases/mmap_default.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include + +#include "../../kselftest_harness.h" + +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_HARNESS_MAIN diff --git a/tools/testing/selftests/riscv/mm/testcases/mmap_test.h b/tools/testing/selftests/riscv/mm/testcases/mmap_test.h new file mode 100644 index 000000000000..98a892de5d19 --- /dev/null +++ b/tools/testing/selftests/riscv/mm/testcases/mmap_test.h @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _TESTCASES_MMAP_TEST_H +#define _TESTCASES_MMAP_TEST_H +#include +#include +#include + +#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; +}; + +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); + + int prot = PROT_READ | PROT_WRITE; + int flags = MAP_PRIVATE | MAP_ANONYMOUS; + + 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); +} + +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); + + return value2 > value1; +} +#endif /* _TESTCASES_MMAP_TEST_H */ diff --git a/tools/testing/selftests/riscv/mm/testcases/run_mmap.sh b/tools/testing/selftests/riscv/mm/testcases/run_mmap.sh new file mode 100755 index 000000000000..ca5ad7c48bad --- /dev/null +++ b/tools/testing/selftests/riscv/mm/testcases/run_mmap.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +original_stack_limit=$(ulimit -s) + +./mmap_default + +# Force mmap_bottomup to be ran with bottomup memory due to +# the unlimited stack +ulimit -s unlimited +./mmap_bottomup +ulimit -s $original_stack_limit From patchwork Thu Jul 27 21:26:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13330783 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 2E34EC00528 for ; Thu, 27 Jul 2023 21:27:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB9F66B007B; Thu, 27 Jul 2023 17:26:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B6B056B007E; Thu, 27 Jul 2023 17:26:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A31C26B0080; Thu, 27 Jul 2023 17:26:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8C5AA6B007B for ; Thu, 27 Jul 2023 17:26:58 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6AF10B255F for ; Thu, 27 Jul 2023 21:26:58 +0000 (UTC) X-FDA: 81058676916.13.383CC73 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf08.hostedemail.com (Postfix) with ESMTP id 6625D160017 for ; Thu, 27 Jul 2023 21:26:56 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=HH7TEI0F; spf=pass (imf08.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.178 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=1690493216; 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=nxIryN+/nGnN7q5/mJrC1dQ+rinWckKL0IS2jYwlkeI=; b=N3E+LYjCWYBrWMnf0bWMlm7JsUVtMg1yc0le+kmQQSmYKdDOXiSbe/YAXANa21fDg+zP8x NsiwE9IjtAFm7Ld/KmphS4orgGYSh86bq5VOI4/T9zrHfUrbU/kr0vk+A+onWjM6nNB9S1 LrymDZ/++6qth8s2T2b48coP00KpBI8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690493216; a=rsa-sha256; cv=none; b=w2v7PX0frN9aGq/u35EBSR+zr8h23DJ7aq0qCfyjXNG2IiBYcnpNeHEvBVaSlbIXirjMDf siOcO6WA06uD63kwC4Jq6KVfGZs+g6Zbqr2W81GHZHumJGk97eBbXxKinxvAqAHy7asr71 d5si1zvHW8zD6jxMH3ejLLHxSRkv01Y= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=HH7TEI0F; spf=pass (imf08.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-686efb9ee3cso1370323b3a.3 for ; Thu, 27 Jul 2023 14:26:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690493215; x=1691098015; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nxIryN+/nGnN7q5/mJrC1dQ+rinWckKL0IS2jYwlkeI=; b=HH7TEI0FKqELKzYIXsjAzNMOv7EmEk19k49xsmg5JJ2iJpQjJBUsJBektepS7kbqjA Vt/YOabaV+5seRyrTS+nQFfXRu/Rmc0qF/Cmuzi6vbvzfQQ7hYiZSyJOGxFRzI1tA3px fkP0ufFuAla153rOmkqGNp0bHyeGAvpUM3evTA9mfbdGVkW+96ufuS/f54M74SC3GCRo WqzWIVc8ARWe8/mWjw/9xYezMnJhgSJlmpSTw5U4/6ICvlMwjc3VVGpkITduwPQnE0vT zFsh4Tq4pcASeCN6YVhHilpdFEEvWGuxwZ4SH0AQAfZfQIb9FQNxijHErK3RcGa3TLoV 6PHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690493215; x=1691098015; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nxIryN+/nGnN7q5/mJrC1dQ+rinWckKL0IS2jYwlkeI=; b=llbhEdcrsnLuHxfPcThjskMlAgnqxwUFKrE3hc2p5DHMBBH3/0JU6faZDAt3JZLVCv w4EjbQ1wc1zsPlnRA4BbT4BbHF3jJiC7ilqBDdnjVUaTTLkSyYmKUy9wJ68kcli3qOVM akirTIh+PSyiXeAJ6gCfiUgH3F0tulr7Ifer8yg40O0zH5SX67MOJ23/DpWmKl24xJYm C5qfP7ubcfHrGpaooHJtnmyJcJD4uGF0s1S2v6/xdlP1UP2jQcCC1dgPHgMg/tvzHBhh k2Q07sV1nPtBm++yEgqKweI328GOl8A4/akIsp/AvHSWF63/kkUU/PE3CjlUQmckmXyr mlDA== X-Gm-Message-State: ABy/qLbTsYJaTaRZkGBB+8Ly9GjXpWDCTFEAyHuaB5AjDWEWteptbNio XZVNGSE5/BUq3pkn6qjJ+JEZAA== X-Google-Smtp-Source: APBJJlH69UlfwIWPYbCOxQtQ76ua+pdw1/ixsjQRFRBQgUh0yQ7pLCSXX0UzINbZgQLjLL4GlXZWZw== X-Received: by 2002:a05:6a00:2316:b0:668:82fe:16f1 with SMTP id h22-20020a056a00231600b0066882fe16f1mr369674pfh.1.1690493215262; Thu, 27 Jul 2023 14:26:55 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b00682562b1549sm1912312pfd.24.2023.07.27.14.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 14:26:54 -0700 (PDT) From: Charlie Jenkins To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: charlie@rivosinc.com, conor@kernel.org, paul.walmsley@sifive.com, palmer@rivosinc.com, aou@eecs.berkeley.edu, anup@brainfault.org, konstantin@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, mick@ics.forth.gr, jrtc27@jrtc27.com, rdunlap@infradead.org, alexghiti@rivosinc.com Subject: [PATCH v8 3/4] RISC-V: mm: Update pgtable comment documentation Date: Thu, 27 Jul 2023 14:26:28 -0700 Message-ID: <20230727212647.4182407-4-charlie@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230727212647.4182407-1-charlie@rivosinc.com> References: <20230727212647.4182407-1-charlie@rivosinc.com> MIME-Version: 1.0 X-Stat-Signature: n5n1sfccqfjrmdrg9icxwpup7zhytruf X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 6625D160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Hs3IXle40Cu5Js2AbyVPs/1uFPsVf+ocLU5szVpAneu+SUMCzErR03un1IN+eyB2KrPb5aYJJv2FEcmQQMdvVBJuLvMaeiuZcnbZ9Ul/vW++jGDUZjqNrFdzaWA06tCeJWEbc0W6XJGImfw9pVXcaR9Bn2ogoAp6xdl8gtRn+FoXMBTd++N+yvtMszwYjo/7yl8IgcoKbQNc8+/yHIQZKTsedkenTP1ck7u1JHsQfzvx629NFNDOYC7jeRga/GXak8onT80zdhgkchJ6Yed1K3pJTDgk7uDSdX9x9ZF2an30a/3+5VZG6xvC2sb3mekg0AgShZ/PBcnD0gJlkblwLr0lIWJOGxsj/twp8AQQ0gfP5VBb5R0t2sk/gA4kRQKcHjCXAV6UprM2AiJU5o= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000587, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: sv57 is supported in the kernel so pgtable.h should reflect that. Signed-off-by: Charlie Jenkins Reviewed-by: Alexandre Ghiti --- arch/riscv/include/asm/pgtable.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index c76a1ef094a4..b551467a1dd8 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -848,14 +848,16 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) * Task size is 0x4000000000 for RV64 or 0x9fc00000 for RV32. * Note that PGDIR_SIZE must evenly divide TASK_SIZE. * Task size is: - * - 0x9fc00000 (~2.5GB) for RV32. - * - 0x4000000000 ( 256GB) for RV64 using SV39 mmu - * - 0x800000000000 ( 128TB) for RV64 using SV48 mmu + * - 0x9fc00000 (~2.5GB) for RV32. + * - 0x4000000000 ( 256GB) for RV64 using SV39 mmu + * - 0x800000000000 ( 128TB) for RV64 using SV48 mmu + * - 0x100000000000000 ( 64PB) for RV64 using SV57 mmu * * Note that PGDIR_SIZE must evenly divide TASK_SIZE since "RISC-V * Instruction Set Manual Volume II: Privileged Architecture" states that * "load and store effective addresses, which are 64bits, must have bits * 63–48 all equal to bit 47, or else a page-fault exception will occur." + * Similarly for SV57, bits 63–57 must be equal to bit 56. */ #ifdef CONFIG_64BIT #define TASK_SIZE_64 (PGDIR_SIZE * PTRS_PER_PGD / 2) From patchwork Thu Jul 27 21:26:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13330784 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 56DB4C04FE1 for ; Thu, 27 Jul 2023 21:27:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D41AE6B007E; Thu, 27 Jul 2023 17:26:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C2D4D6B0080; Thu, 27 Jul 2023 17:26:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ACDDC6B0081; Thu, 27 Jul 2023 17:26:59 -0400 (EDT) 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 9A4416B007E for ; Thu, 27 Jul 2023 17:26:59 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 61CF812066A for ; Thu, 27 Jul 2023 21:26:59 +0000 (UTC) X-FDA: 81058676958.10.EDDFAA4 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf24.hostedemail.com (Postfix) with ESMTP id 89047180016 for ; Thu, 27 Jul 2023 21:26:57 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=O0RhQf8K; dmarc=none; spf=pass (imf24.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690493217; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gcvGxWKs0ioHSwaNFVtuDJQ1B/8SpZlsoy8QXz36r7I=; b=DXAOVzvPiMHlrkPTPLwWoO0vf1RIlFt1AIxIYwrBtQOmP2FgHZFARt5IwFqnEdPupo9unV GClPAK4xOmpQJBNVmlcOkJy6oHFsV/n1Eyh3XTNvvKs0KGjPunbxiC1rGKO2aXmEo+GjbW mlE+wSCGlbPiNb5V/q7b67ta5FHoOnY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=O0RhQf8K; dmarc=none; spf=pass (imf24.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690493217; a=rsa-sha256; cv=none; b=QyRBRLp1iB8PkwmxZBv/nmhNWigm/yihq2xGmDpSvp7grl8HO80rV5x8JC2lIocur9+hjK bYRoccTMh1DKVd/wWIgwCOpZ/B9tLJKFSJiWBwZP5tKv+xqZ38o9yBs3NYJ/no8ntI7M6n eOQcnSHPColpAkeHn3zqpc1r94OVFyU= Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-686ba29ccb1so899418b3a.1 for ; Thu, 27 Jul 2023 14:26:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690493216; x=1691098016; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gcvGxWKs0ioHSwaNFVtuDJQ1B/8SpZlsoy8QXz36r7I=; b=O0RhQf8KfE7AkPva40tWc9J+su1HI1UE2kEfdz7pkwxir6Zk97X4vA7+YDbYbExjNZ 4RyRTkXeeZg8c5H4DsdkNwy5z0Oc/dOtYSntC5cuj+IHiZcJVOOl/pSPl7D3Ihdgfc6g IPIa1TkeHGbit0ypGybX6xXCaiyifj2oUvQhzSw14P8D1lwo9LkNq8obIlWu0dEXqnfq NOq9monYfeRcCg+StWnRJrEbiF6xrTEIpjpHi2DRzaZs15+pTwpPDnYlfAInaRS4UyKP klrItNmQI+SFf7u8/3WOJRIz/cZ031FyXJArV/48cx9URntu/5ar9hUBmNCWWhDXMrQw OqJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690493216; x=1691098016; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gcvGxWKs0ioHSwaNFVtuDJQ1B/8SpZlsoy8QXz36r7I=; b=hHfQxm05FPai5q4mGNzzrqv5rkuhiJ2ktbwIXBHJh9KGb0/HCJA1rO4s9U/2YnjA/r TU775m7uLLMttaEN/ISDtgzdLy4pRDHpRF4JiOAB1klG/84Jb7tADahDhJuHUKY+YVQD roAAaPz6kBGNuKHTIQz19SmZTpSpG1TdwOmgBpibFKvfgHaVH6iW3TARtMPvs8Oghxe4 p/EO5Erw7Wclfss3t5L4MmcKaVPlJv/7ugzK5ug0ibrORKORDjfwjSnX7MlOq90JFsMS N4b7mmgTaWbLoMjp9gKe+XPSGDTDGK7+PnRuYtsBOexzwnM6eAAho81yimWHwznfmy2Y ACCA== X-Gm-Message-State: ABy/qLYfUKBSJkLnjLaYLAlPMlsBEt855gAscsVKNTwhNV2sxOTHRJxF /kT/fDTekWnMWhS+4tbLNcRlDA== X-Google-Smtp-Source: APBJJlFlY+9HLXpB5MOpoEilud+PtI86fX/t6QctT4gfhpPOy7817Igg+eQtg4O7iE22xtMxf1LQKw== X-Received: by 2002:a05:6a21:3984:b0:12f:d350:8a12 with SMTP id ad4-20020a056a21398400b0012fd3508a12mr467624pzc.21.1690493216617; Thu, 27 Jul 2023 14:26:56 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b00682562b1549sm1912312pfd.24.2023.07.27.14.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 14:26:56 -0700 (PDT) From: Charlie Jenkins To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: charlie@rivosinc.com, conor@kernel.org, paul.walmsley@sifive.com, palmer@rivosinc.com, aou@eecs.berkeley.edu, anup@brainfault.org, konstantin@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, mick@ics.forth.gr, jrtc27@jrtc27.com, rdunlap@infradead.org, alexghiti@rivosinc.com Subject: [PATCH v8 4/4] RISC-V: mm: Document mmap changes Date: Thu, 27 Jul 2023 14:26:29 -0700 Message-ID: <20230727212647.4182407-5-charlie@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230727212647.4182407-1-charlie@rivosinc.com> References: <20230727212647.4182407-1-charlie@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 89047180016 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 35f5oehzaaf1pqdw9r9csmt5uaw99ffo X-HE-Tag: 1690493217-192763 X-HE-Meta: U2FsdGVkX19L8AhrT7Zlpf9pfC2X9giPxRcgp9V52A8/SKNPwpFY2YVTtCvAf/eLSVIQRc/dEYGf8S2JggKq57q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W93kpeGKLcBDjp+tlT2PV05/9lMGySclwWi+bc8xsWiABB5RpecxWGYrX8IcJ3J3fWZp1efaVjJPFMTh5bEFT0Cp84nQFB+D8lweu7MmISNNZlTpgOdD3kWF18Nq/BduHJLKhqJfXxvcuqztycfntHuB1GKjvvZQ91KylQNZQtiYHnkPcR8hFJoJ8l6LXzSPiBIc5BPY6LN+MrexmK7LGFfgkvxbdM0sZAEdzooSB8N+PuU/SQrzPz8M7NYTLiWbetPvAm+DKhbFTk4Kcp X-Bogosity: Ham, tests=bogofilter, spamicity=0.007638, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The behavior of mmap is modified with this patch series, so explain the changes to the mmap hint address behavior. Signed-off-by: Charlie Jenkins Reviewed-by: Alexandre Ghiti --- Documentation/riscv/vm-layout.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Documentation/riscv/vm-layout.rst b/Documentation/riscv/vm-layout.rst index 5462c84f4723..69ff6da1dbf8 100644 --- a/Documentation/riscv/vm-layout.rst +++ b/Documentation/riscv/vm-layout.rst @@ -133,3 +133,25 @@ RISC-V Linux Kernel SV57 ffffffff00000000 | -4 GB | ffffffff7fffffff | 2 GB | modules, BPF ffffffff80000000 | -2 GB | ffffffffffffffff | 2 GB | kernel __________________|____________|__________________|_________|____________________________________________________________ + + +Userspace VAs +-------------------- +To maintain compatibility with software that relies on the VA space with a +maximum of 48 bits the kernel will, by default, return virtual addresses to +userspace from a 48-bit range (sv48). This default behavior is achieved by +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.