From patchwork Wed Jul 26 16:45:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13328362 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 21615C001DF for ; Wed, 26 Jul 2023 16:46:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD19B6B007D; Wed, 26 Jul 2023 12:46:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 995B76B007E; Wed, 26 Jul 2023 12:46:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8363F6B0080; Wed, 26 Jul 2023 12:46:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7362A6B007D for ; Wed, 26 Jul 2023 12:46:35 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id AEF761CA0A1 for ; Wed, 26 Jul 2023 16:46:34 +0000 (UTC) X-FDA: 81054341508.11.271805A Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf13.hostedemail.com (Postfix) with ESMTP id 1E93F20035 for ; Wed, 26 Jul 2023 16:46:31 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=2Jz16VlH; spf=pass (imf13.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690389992; a=rsa-sha256; cv=none; b=urv0qBoQfcK4T5QntiZlYfpSw12ZAzaZBW9l26EBrMlqpz3PSiw1DIbDzm6HXl0gTfKuUS WVOY1G9fVvaP9UEIdR1G/ruYTSToS/O/H3D0j8yPltHMnYeRr7xEawF/m/Pac32+VKMnuh /LCZP4MLaaT3SrsdqzMqYM3t/IsYHUY= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=2Jz16VlH; spf=pass (imf13.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.177 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=1690389992; 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=9I72PoBRKXLvHktmcrje1n02ixRw/D4fAolrg/chvlw=; b=2ruqMfjJP7z93nsEiSQbpZJzqGFHXwU+h4GXd8TmVOBIt2l/0btVmBDa25g+v5QYUtWvDw 9s8ibLlKb8vPUiaPqIx7WOhnAHzVrxQxp+zvH127dwqsfUwTRjkyiP9AKkQ6sZWouWmuU8 XFP2Dgt5lgiP4Q+YbJ6dp6iYkBUfPZE= Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1b8b4748fe4so41056005ad.1 for ; Wed, 26 Jul 2023 09:46:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690389991; x=1690994791; 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=9I72PoBRKXLvHktmcrje1n02ixRw/D4fAolrg/chvlw=; b=2Jz16VlHfoEFfZ3AFSLSXY8u2g8fiZbPZUwm9PJbLRY7gk6jqF0t0jiYlXi7TSGAYF 3zubxHuOcq7inKRub1IH2maTkPsOZAxyx6PORG91v3QJLBcTa/dZMQOYbMdbNUouInY2 7xzKDWuWhLszpWjh3LQHwMz6C55JKbegov2VqNbT1ZtA9nhipvVWBFdoo8sQqQIN350e D0wMU5CYHIqplbYqQ9tt0g/RjLzgREP1Ls4ss+Rt/p1Xz9F2SIvJNR5F90mAfc/fCnKK cIeKdrmuE9jvExtAHXgaqbGU9cdsmnL7Rerg9I1/qayP5aEnKEIwJ3CwtCTUbx2Qm+FI ugLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690389991; x=1690994791; 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=9I72PoBRKXLvHktmcrje1n02ixRw/D4fAolrg/chvlw=; b=B617GiA521G6/2KwNEdLc6f70kjkvtbhfMrUk8L+URIeNfDnsFb4i6gRzwm1YL2Hgf +BAj4hXwmv5alyghY3Jy8Z9ykrpKmNAZwJoidnj9ra5IiYxLMEllt1WmKkqFrNVKYo0o TDu7zFwWrf65vrFmTTzKmSUl2ekc0POoKifTftDLuCk+2coaQIW7zJvelaRL09Hy34en Xc+ZhmllwUjnl4sEdTCmcI6L7XaFAG0flCqZOYs9/k17fygSXEXUVqVdEHR/ehx8m66r f2yctwpfHCJSa3CohJpOQRsOSJeIBfj1FdJUfVAupOc/2ElexkSYkgGB5jPS3HqDjICh MF4Q== X-Gm-Message-State: ABy/qLYj4iWBWUL93BIAUsmB1fjReg9+I6zWFI2qdQmLW8L8KXnAxTWN k2/L9Ey0PNKems/+fVfTJEWp9A== X-Google-Smtp-Source: APBJJlGp1GY/W4RE/89gp/16eB2AGE/qHe+6+KWmHQWy/wMthtq4d82Q6nwr43YclX/zAw9dQWmddw== X-Received: by 2002:a17:902:d501:b0:1b6:9551:e297 with SMTP id b1-20020a170902d50100b001b69551e297mr2620057plg.44.1690389990886; Wed, 26 Jul 2023 09:46:30 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id h5-20020a170902f54500b001bb6c5ff4edsm11628870plf.173.2023.07.26.09.46.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 09:46:30 -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 v7 1/4] RISC-V: mm: Restrict address space for sv39,sv48,sv57 Date: Wed, 26 Jul 2023 09:45:55 -0700 Message-ID: <20230726164620.717288-2-charlie@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230726164620.717288-1-charlie@rivosinc.com> References: <20230726164620.717288-1-charlie@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 1E93F20035 X-Stat-Signature: 1kim9yzbfrmdweedo3pg3yhj576b6rbx X-Rspam-User: X-HE-Tag: 1690389991-886884 X-HE-Meta: U2FsdGVkX1+qKnfF5FwN5l/8e2gPJLsWYVA0xZ+/ELr7pqLpiWimfBUQXE0Q934cuupe1NlytetCnR2D+tKi0hasb8E4K+k0PSpFI/9J/XM8m9DpDpdNPjk6nmCIFKMSV6GX0CKawpWr32VLMO63ZacIU97Do1O5kO36j4o9MNfcJjZUCy0Ok3LIPh4Mh8NtQWGgyhtpUJe4mpcaEFtHQ3vxnZUhouAaGGcuuyEHtHDfORK8LLODJr0PF3wGWnsBIv6Xe715rNx5SlY5MS1SL006PEl4H+AVXu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nQBGnNIfbTmCbs56UNlrbo5g2Qc3CM8BwHBYiQGMgttNKEh+3MHIkYDFprJMFAf 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 | 13 ++++++++- arch/riscv/include/asm/processor.h | 47 +++++++++++++++++++++++++----- 3 files changed, 53 insertions(+), 9 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..530f6a171a2b 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -63,12 +63,23 @@ * 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)) #else #define VA_BITS 32 #endif +#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) + #define VMEMMAP_SHIFT \ (VA_BITS - PAGE_SHIFT - 1 + STRUCT_PAGE_MAX_SHIFT) #define VMEMMAP_SIZE BIT(VMEMMAP_SHIFT) diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index c950a8d9edef..050e27577419 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -13,20 +13,53 @@ #include -/* - * 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 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; \ + if ((addr) == 0) \ + 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; \ + unsigned long rnd_gap = (base) - DEFAULT_MAP_WINDOW; \ + if ((addr) == 0) \ + 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(MMAP_MIN_VA_BITS / 3) + #ifndef __ASSEMBLY__ struct task_struct; From patchwork Wed Jul 26 16:45:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13328364 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 E5A1DC04E69 for ; Wed, 26 Jul 2023 16:46:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7284B6B007E; Wed, 26 Jul 2023 12:46:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 613B76B0080; Wed, 26 Jul 2023 12:46:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48C638D0001; Wed, 26 Jul 2023 12:46:36 -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 3628B6B007E for ; Wed, 26 Jul 2023 12:46:36 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E5A4F80257 for ; Wed, 26 Jul 2023 16:46:35 +0000 (UTC) X-FDA: 81054341550.27.CF9429A Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf16.hostedemail.com (Postfix) with ESMTP id 8D3D118001E for ; Wed, 26 Jul 2023 16:46:33 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=fdbBRvRa; dmarc=none; spf=pass (imf16.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.176 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=1690389993; 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=4TaJQQDloS1fyLLLn7tLUDRDe19af+HfLSY4Q5iSlbqbsj+1J3gthWjvrEEcoH//oqZr9v Gb2ylDH7qXj2oEYbyPjNscRWkP6WxSsayyCcZyMNPQ78w0JHxjlfbn7oUzsE99yXUzXpm6 6w2FYYed4a5nwqQOjmRbXisSAZPhQXo= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=fdbBRvRa; dmarc=none; spf=pass (imf16.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690389993; a=rsa-sha256; cv=none; b=jOTNgxnkcoBadz5hYFBeZd9Yt7Z+NS3l/yri1Bi/exiMbIAnCRIluhVd9QApZ++JwhvkY8 5kQzL8YSs41sx/lF2bNql13aSnUovQWx8VFNMANYfcxah2lWGdDhCddocFPf82OYudZ75S VrS2pNZfeA0eA63QdpgIAp1Cxc7+YAE= Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1b8ad9eede0so55359605ad.1 for ; Wed, 26 Jul 2023 09:46:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690389992; x=1690994792; 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=fdbBRvRaTPSTT/HDfPIbS9t4jUSvkqd9rwoffU4CEGJqpWakQrGzOn2d+MzZih+cqP H767XPhHSrBW3BeoSgfzIfRjrkfDyRJoKjV8Cx5+WH2mdaus68oMtOGLqnA1Egrps0aY UGVOdKevwFc2JLs79ppgVZF3kq/Y7By0r4UXgVZpy1jcocZGI6y7zusvNByUOPECbAAb J8IgmWx2x5VIzKf7DUYjxeN+pMfmmrubFIAJSJNdujJ0wgInXBmwAkoPd4SHr55ekp76 9z4P7034lD4LzQQvpQ/YlNKQj5UqbBkQlHH+uXKe3A+KyXOPA0PH4wjdhQwbVNUwQiaR HwUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690389992; x=1690994792; 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=G3qpsVBeQRhUjua1+rdTdH2ZvSeCnTGD3mB4igUUafj6YR+XuACrsgLRxabSgWhFPr CKYkYqKxeh0pwJsuFCmpnFfA4CIW85dWSfcq32Jlc5VT0Sj0YVZlENxzPpwdA+v9OYZv olOx07z1CzSDhATF3KcwfOKRZx+Yh+OUCRtUl6Db2eAUxjfjAy+9tksTbPFNSnY2Z9vD zhS9gHnHFAHSMdSmzCf8ih3q/xIJJtgpYaYHCaEUoESJuJrKhtwf2iXXccMwJwV6FFQA OyMItq4lNGR1k38bbKiNvSzsl2pUGip1XbdTMnbh9Z0IUktx616uyHBYHvxcUpPOJnlv RO7g== X-Gm-Message-State: ABy/qLZsYz7FHcTlHDFzQiRaPN7ZK4vfn919v5i+0w/7/j9LY1I+hsOi 9FhNpTdhwFakqvKcvOtPz6Upng== X-Google-Smtp-Source: APBJJlGLB5XByQ88xcFR6FgoNnxQhRllDYe6TeGWQKSGsk2dH1XpSUdEUxZg+KMHQL4aF625aD6H5Q== X-Received: by 2002:a17:903:2287:b0:1bb:9f07:5e0 with SMTP id b7-20020a170903228700b001bb9f0705e0mr3346604plh.60.1690389992311; Wed, 26 Jul 2023 09:46:32 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id h5-20020a170902f54500b001bb6c5ff4edsm11628870plf.173.2023.07.26.09.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 09:46:31 -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 v7 2/4] RISC-V: mm: Add tests for RISC-V mm Date: Wed, 26 Jul 2023 09:45:56 -0700 Message-ID: <20230726164620.717288-3-charlie@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230726164620.717288-1-charlie@rivosinc.com> References: <20230726164620.717288-1-charlie@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8D3D118001E X-Rspam-User: X-Rspamd-Server: rsp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JPH799E8CZ7kiDRWVaORaCexSP7LsWj7ntoOms+gaVuwvnzDWcXpqU4s+UgB1+GNLwCLeaZJAQ4ZHBbv8WrHztuzuhaVBrzdFnKbCjXrhnKmr+MHZ3n2so/9DnAQExh8e9a7dEVk2l1VhZCU1bR9hx4J/GpPjUwFFA6PFm3MwXSko06UqpvCoZFDAm3h52ZlyfIVbc7WGXVt/SDjTo9zKrBsNblFOdz+LIyWm+nQoXGYydoCOIvcL1QE+gpqAVIPZPmrvYFocAMPPtNX0PPA+iecphwKSwQcB0IE1vRqxgX2BHJdk08c2xX88bCJFHvoIGpkbVs4G/un0pzgwYmQbWYFvQJI0foETSIyFRr0vUOfJff2z2sIpEtAODtjBvdUTKwtJzOWTfWo7FiC6sIXeRzd76/7UBLlvpSvirRN5weiRIZ8x X-Bogosity: Ham, tests=bogofilter, spamicity=0.005458, 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 Wed Jul 26 16:45:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13328366 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 7DF2EC001DC for ; Wed, 26 Jul 2023 16:46:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E5156B0081; Wed, 26 Jul 2023 12:46:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 023986B0082; Wed, 26 Jul 2023 12:46:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBCBE6B0085; Wed, 26 Jul 2023 12:46:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A17A46B0081 for ; Wed, 26 Jul 2023 12:46:38 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C58291202E6 for ; Wed, 26 Jul 2023 16:46:37 +0000 (UTC) X-FDA: 81054341634.28.AB1E3E9 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf29.hostedemail.com (Postfix) with ESMTP id DA3B8120024 for ; Wed, 26 Jul 2023 16:46:34 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=uGj1t6oL; dmarc=none; spf=pass (imf29.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.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=1690389994; 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=nxXmOdIWe/bZgFmovuliVgy5AL4XQqsEakBY4VilH/8=; b=T6ZCd5KLMOLf5rvQDFOuKPMWZvAGWsmgmYUoSxqVNVDEPUHfXWD/jGQ3UxHuEu1NSm5sdc vjIumL67MA50aZkrecVjL8WqSle37ZUkxV9xWYaocOW6Idtb6dAvnXq1pIhCOgUZkirTol tS/qapQKqESdpDthuknfRRNvfB7HMtk= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=uGj1t6oL; dmarc=none; spf=pass (imf29.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690389994; a=rsa-sha256; cv=none; b=yD+ytAIDwSDOPNMa9ELqbOUjXhOQTrRGW0HtosIUxURLSKsv605zD6toSY+X8kQShBwyGO OeLddiqHWjWRTP8By94WbHtexUgKrgQ+C14Jxn+StzGp9abfVeJyRVLg2aLHcavUKnKEhb cXbgZGR+DvkHRAqJfMYzrWf5jiXvVyU= Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1bbd2761f1bso4629065ad.2 for ; Wed, 26 Jul 2023 09:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690389993; x=1690994793; 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=nxXmOdIWe/bZgFmovuliVgy5AL4XQqsEakBY4VilH/8=; b=uGj1t6oL4u1fl4y0bUjyIo+gEG6FvyX76N3UvGsKUanjjrHB6wnIUkhEejMij86pkP EVcq1qYhmhAsWKH/bTv86zK02/LQZMQq7g4GucihnDv97RSd4YvXnrbgbDWPGh57Gm43 otyrPfQG7tSPmnn1LK0ZKv6nS+RjBkhyBwtgizouPL3Kq5x8fU1JxqHm8ESNdJya0Equ u60fTChXgviIE+TR2UEeszDN/H3aPv73hS0hvyNcKuH0qJi9wFqWw0PjC0ks4SU85S2Z 5glfdqvmMevya7khD8CyeEfxUGRd305Yi1lCbXYzBjv2vJ/zFMEBiJB9hvll+QMy0/cX T8VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690389993; x=1690994793; 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=nxXmOdIWe/bZgFmovuliVgy5AL4XQqsEakBY4VilH/8=; b=W0oAVFgT5HCVUR5C98ZQYjosHCzT6SqQodDTQSl9knxLNrc90FwMtCzSZ4Mg2jFOBz 9+Tn/T5RDkKepI2mQUfhx503mE769MEYl5g9epyroPwhoQTl0Co8zqN6AmLHaIfJ1NHz J31KtVntwv/icZHohQlR0Woo+fBggv0ABnwEtE1daNJyhV4bVsX4qf+JP9sILn5dCNyl Agzm+9ojZh389685Z1O2HIogdKmX+ZBQ8ul8qsuNmSEH9ibWrPyIi8sKW1r0dhXwpVCF djAJbiAMLDP/oMVbToe2r0F8Ci4IbYnAB5jZ3CZ7gA52xbLgqaEPeLox+jnWPyj75Xcu 7L6Q== X-Gm-Message-State: ABy/qLaMhZPLR4SWNShGwAfI88uK8kvKUnEEMJlXnPDvHrL1YL+X1FP2 KH2PAQF822rlUEhheIaCW5Igkg== X-Google-Smtp-Source: APBJJlHd8ZanXubRsLvs8LnpqdeDXtlGfjvqC1HSJQRHauQPQgT6PVzi7mdT5yfnVwFo9B2eoHwlEA== X-Received: by 2002:a17:902:c205:b0:1b5:219a:cbbd with SMTP id 5-20020a170902c20500b001b5219acbbdmr2429756pll.3.1690389993609; Wed, 26 Jul 2023 09:46:33 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id h5-20020a170902f54500b001bb6c5ff4edsm11628870plf.173.2023.07.26.09.46.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 09:46:33 -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 v7 3/4] RISC-V: mm: Update pgtable comment documentation Date: Wed, 26 Jul 2023 09:45:57 -0700 Message-ID: <20230726164620.717288-4-charlie@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230726164620.717288-1-charlie@rivosinc.com> References: <20230726164620.717288-1-charlie@rivosinc.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 86diy1fco7pi6fc4ofnkqrz1tuuze95a X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DA3B8120024 X-HE-Tag: 1690389994-55882 X-HE-Meta: U2FsdGVkX1/8PX493DgLCWXwmGa4FG9X2m659XqZeuQSe3ZnXVKnv0javtV86lGggbmgebcLnkzdx1ig/DlLDnstVhe7+hjg8Q3DEw1cLd1QxrQIEbPr6oleJppgxKUpsLXP3gpuu3IDrZsVm7KaR8bwZYdwHB04oIAKCJwGGlmBD2E1MHaEaKC9ka0mXrujFsQSwMz9WuIaUA1oMOdSgTw0XPxZXu3ZOUb040FPnKbSsrVtCH34Z0w9YniCam3LqpfWjVPq7dI/JAtGe4c06QWMXy80JMI8b8UZoiEfcFhrE56qH2SB69Ao/DLvZAEa0BO7DyX5tbKkSawzJKdhYMAuj9YtvpUWD87Y8xLDLCAwxT7FU+biJUyZ6QdWUB0JDrt+5+0uuOiXFspZYL8n9I2SYas45NNyz94kgzeHwDe8/qHB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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 530f6a171a2b..cd09ccd876b9 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -841,14 +841,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 Wed Jul 26 16:45:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13328365 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 BEB6AC04FE0 for ; Wed, 26 Jul 2023 16:46:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEDB36B0080; Wed, 26 Jul 2023 12:46:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD58D6B0083; Wed, 26 Jul 2023 12:46:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85DBD6B0082; Wed, 26 Jul 2023 12:46:38 -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 7784C6B0080 for ; Wed, 26 Jul 2023 12:46:38 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3B3C5C0351 for ; Wed, 26 Jul 2023 16:46:38 +0000 (UTC) X-FDA: 81054341676.19.D0FA769 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf23.hostedemail.com (Postfix) with ESMTP id 3B14D14001C for ; Wed, 26 Jul 2023 16:46:35 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=ctlEmW7D; dmarc=none; spf=pass (imf23.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.169 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=1690389996; 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=RhqFg57BvKl6fNbzr/B0XywyPma+HGuRk3UQYXqf+YX8MJg8nJj+0/E1Vl37tTzHQ1ktzJ oTML+hUiGye2Rhyw2dauqmaHOTtoqeiFHm9CvGIYMXyjYoNRzKU/ycd936XSh2jEcwqQ+W K9lJ2YU4fVIJfEnDgo1MCiTq5agUhNA= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=ctlEmW7D; dmarc=none; spf=pass (imf23.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690389996; a=rsa-sha256; cv=none; b=vDew09F0L7cE4esMOdF+6g7YhSyqB+QH+vpY+CrXswrHeKH2a58J2SvDwYHX58dVbgEDzj qJp1VZ/HyxASE68Anz+Oj70caIFgSb/5l+gRDlCSNiCXv0ZbJse9dplOc8iM2a4/OnEhZ1 jAl87Q5/KvnHbAUnEOgFFWxt9jrSmYw= Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1bbc06f830aso8629015ad.0 for ; Wed, 26 Jul 2023 09:46:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690389995; x=1690994795; 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=ctlEmW7DMTMNY+Sp7acXqqDtGLdfH554pjXRJaq8fLvxFb/RtQTWgjya5aX8frZUG+ kWLLX3V5bkPJ8D9sRUV/MwHTEJpB9RCwH6/ndhkksdQtRuU+HRr0zUfscDgxiFSHZA9+ yIU0ZD4Tam8mQ2WS+5pLZ/c5X4RhjfmHJo3MwLkOOIWTzwMnMBP8Q0wn+W52egZzi2xU AAyOixs1odiPKZLEKGezwwzYUkbE2yPosL+ri5v70wHRzK4oQvk1fggscCcK6icuFnGe uL29fxGA2FdvaKyJUxHyjHp+jMTQA1xrvEzeIai5Rjkq71aK2LAAFsldGh/eFZfk8xRM s+hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690389995; x=1690994795; 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=fsYaY3huSa/xAr1RfOXebLxGetD4aOUCGeGVzX7DXVGQqb14hSRKXu4YxLpqEuroVZ os6qorNTdHpi3ONYaPvE3aIVBKoYX3r0edaOmkswb1DvTGFOScASQB1+3o66KTz2GVtL gF+QUcoiQygvuxjvIYXxTxnY9As4UTX6QpJlUT1AYNWB/wTFw+gIdYigBEGwvUGRPGkd orcH1hDF9HKptcVsfCNK+PtwfnlRwSvb5K+BI0gRJvCHd05XxFa+cQ+mAXzfYO2JmQAz KS+f0CzNZriteeC8v/YkTmoQK9R8iNfHnNgc0/YU3OELNiVyGBCXv4bi4bUhM1a4qlpS BhEA== X-Gm-Message-State: ABy/qLam6gUKHeSNMb99PdOldTz2nkNQX/3m0pSVc7+M4rT9odFBAJLh pFKJG/uP4doe0tGk24FOBPJSOw== X-Google-Smtp-Source: APBJJlHYD5X46sfJHvjFJ8cY7MrqSJBPdDrgEnmRM7T9AiO1YpDySEyimp6MxA9+6dubMdyjQlpBgQ== X-Received: by 2002:a17:902:c943:b0:1b2:676d:1143 with SMTP id i3-20020a170902c94300b001b2676d1143mr38193pla.15.1690389994874; Wed, 26 Jul 2023 09:46:34 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id h5-20020a170902f54500b001bb6c5ff4edsm11628870plf.173.2023.07.26.09.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 09:46:34 -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 v7 4/4] RISC-V: mm: Document mmap changes Date: Wed, 26 Jul 2023 09:45:58 -0700 Message-ID: <20230726164620.717288-5-charlie@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230726164620.717288-1-charlie@rivosinc.com> References: <20230726164620.717288-1-charlie@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 3B14D14001C X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: mo15mqcstsatshwriu8oyws46nriuhnc X-HE-Tag: 1690389995-972502 X-HE-Meta: U2FsdGVkX19LjMZHRY6Bs7cuyAO0WZaiHpMTgXSbZv7e+1M80fD248KyfJD040ui0xeyyhPCvGdPF8Bp7MExj7xf8hJdBG1V0fkUe1G5LvOPb+xLlIOJwbsiKZlYFAsNm7Jx5sbT921EWyrEJNrm4t4xqRwfjnpTxbdIZ0T4M/7gwRat4m8JhMRB/6d+do/zzktIqigMOrOELPktBKmog7VIOFo8snRibHBKqzb+Wt7xI1kSNnCp/tdlFdWGorKFKT4Tpzvu9REKR3ycHzfKbtX/ROSXscYIo6Mfb2A0HbUp/J8bYX6F3TKcXP6AKXabovY27p643DopKK99W2CiJI5lB/+Z9wAa9tbKw109trSb1e3IXVpDLncATrPWOP8Psl+tMC+9Vb5Sz3nKQ2jb9GvNLECt6z2CFsnEXVMyJzO4qm7aPCSnyMBVgvd2yrHdVywIff01+SXhgrXVe6zJh5KFbeJDi9yNsdIWedK6s5twD5jU3toh4S+jqnlMv3L+xXnN3pIlLxJpadp596DD7kOtbZMQ7vXCUXPv9MkpYEPYT4n3LsA5SRhm9ZxvOqVIY6dTXZpHNGMVpCkBrzVca+SNeRsqh5UVvUpPY72dGouVkooXbCzJKWtavjGUcxbtDM3NntXwyUfyBQO0kcfk7zdrVJPp2qPbBlqskFxFwUmFuGUkD6p7/kSt0u6lDE7CjuwF6R7GOLIRdfs+Wrl/4w5ZPL2Hh3H2YuLz/0rEclEwTwybIWtAbid4YC7a7WICpd92bYwbmc7SgaRBKW5ppSPI5iOeAwwXg5cE4N+SGUCuwIC8pFVEtb9VXyIFjSiYp4Q8SJmud2+sq5I16rPgVhCWPq4tPag/QscQ3R/x2P1QcVX2h06wrHckGebiKw9f6l/aCHQyIs4XtpYQvOCe+SyV/rhVSTUwUF9Sv1JPhkhpoBup7aI9DY0u1884Jpy/VwvrW5SUyl9dxyZG9u2 3Rn68/ir oXyrNSpnd3PAeaqBiwvCf4WrUR4XLaKLGaWNAfCVAEuOIbBzHIZqZjddfGpBRL1U9nM70m22SRT0onpKqbkMLBbt1poB6MZLO7MeUYtAO/NdfcpdqB+LjpYNKrVctYrVyNljVypDyR+qagwkPaBzYO1owrLS3voeDiMdRDFQRLUAiYHE94QXY8CwwLsOMk4TLZuDD70Ogw6an40MKUc6XOrTDwE9dCVCwi1kz6O69G6EBuCx6izDNJFeQn2uFDd9667dEgPSBiZt7cGn+xbY5Z9MeDUunBYJUrD0FFm9WtJaajaiPi/YFhusZSZxlY86LAfnkvKDiP0gK2iN0qCMwVR8d5I+ex4BrXB95VqKpV1+G6e1Tjzq6KwzHVR45l0uE+2ORASuJ8yIP1fXeFuMLjLqjaMyNEJ+E2vOmOZXuawW7658eqQFqgHQ14oM/m5ojioSM X-Bogosity: Ham, tests=bogofilter, spamicity=0.001265, 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 --- 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.