Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1572532lql; Wed, 13 Mar 2024 01:46:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXgVBBB5crpt3A9FXZDEqbIKJ9vHSEZ4WAEiKCSXaFLjpOiB7AOGrkK6hag+/SNsvTjxqB96h2jupeKOj/UZTuOVY9qzY9IolNCWmc0GA== X-Google-Smtp-Source: AGHT+IHveB2erEbSLf3AVQrSvWuhEhdR4AmawXwCxP7TaiwvXkZcehbj5aSi7/KBcws3d6GAaWcn X-Received: by 2002:a50:cd03:0:b0:568:335d:a95d with SMTP id z3-20020a50cd03000000b00568335da95dmr7505048edi.18.1710319579487; Wed, 13 Mar 2024 01:46:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710319579; cv=pass; d=google.com; s=arc-20160816; b=oBRIqAwegTeejpSf01Yxq8myaYz9Y9/i9/lwMwnWRCh6dys5JQH02MjM8UH+9xIprd MEN5Nj53vl7tUXuixD3CiRgt4/NMHYMVt8mBFwQVKLJjZYhXJwO6K8VmduItG8LQkTs/ Wn/1ui6OiuWa/CiesC+v93/+Y2PMEF+ILBkX3t+1KHqKOmI5uDsUKRyaN71OFPLcQe64 zJLjJY7EDxX+OojRIzcwk9/68Y+DgL1VzJL2n0wVxUjfchPDvgG7iXwisVRJWqItM64v LRYv0pTOMVnxuKlNhhjxFv0gbmjRFQTesghnbru/NXEWzVnkMOquZI95ygujkIxUrv9O aAMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=xl9/EZGLKxGGHgqxXQrNVV9/fXW9fCPtZn84F/TZCWo=; fh=6A/2yPb/JsZKOetfvdRkM9MNhxc56+xnaL4+d/oTNFg=; b=sYFX9+6ldEqJvO5fRM0LRbCckczriTUkl6XmEwjRJccWoub78TFIElncAXQM+qeri3 s5wyrwWOWx8/OSe2FrBtpZeD2vs/cvssRQNcfdVGY+WJox/AVWSXJ9F0dMtCoTlHCVLI rDyY5sHST7oWJ9h+LVwFZTVhWKjY6amDS/4PF5+Ja8eUwpj7VU1ffn/4gtEHGS62ECkE dNeSgBdyamBVzm4iuyI4FvYr+OgJ17olnagXdu0sQMESeO4ErGUBK9hEMXyl1F9GV+I/ woO+7pwbDgpD+qei6Ash7mnz0rrfnQAlJDivRHuu9yyjhh99FQZNwLeCEasUA9TFjv/m YbRg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="W8/ALJ1g"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-101222-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101222-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id es7-20020a056402380700b005684f7bb829si3345536edb.420.2024.03.13.01.46.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 01:46:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101222-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="W8/ALJ1g"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-101222-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101222-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 057481F22384 for ; Wed, 13 Mar 2024 08:46:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D080F1A708; Wed, 13 Mar 2024 08:46:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="W8/ALJ1g" Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B729DAD5C for ; Wed, 13 Mar 2024 08:46:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710319571; cv=none; b=BFOMxhXfP9CReeYxMyzGchtFzl+6ttlJamvM9EX5yqWKNqBawcqdfCdCdy8NIC/ANRegACjs8PffNUguk2Lel8yZIU1mq6Q0YAvEtCMVPz6w0AuHoEO3JIZKhdSQTQIgO3emPzmgNrnM1RP0X8L6DW0g9p7kPDp+0NjOvRQnEX4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710319571; c=relaxed/simple; bh=s4ggDJ32IPV9w0ooiGFbvbPijBhiI1+2/3F1cv/jT2E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=QWZKCH/w0cd+oTJ10H38PRxVONUMe+GiCH9gYo2FUAKGsOi3wvjm6hAxjv5f5H5ALM0wNAnH27Rr2zD0JExzIVzVwe4XrHHX2lIN7Rgc3xDxv8gJaUklQMrmL6FlOzeTixLdtb1/9N2KMNCzZWk5JiSclQs/nkD8ZcaTc2+Nc98= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=W8/ALJ1g; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-33e9115d501so1163404f8f.0 for ; Wed, 13 Mar 2024 01:46:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1710319567; x=1710924367; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xl9/EZGLKxGGHgqxXQrNVV9/fXW9fCPtZn84F/TZCWo=; b=W8/ALJ1g66CtGj/wWBHMKx1Jyl10qHMjkI+dYDdCSBoWhiFg+BReIGM9/NLCEsBV7x rlLswpw9hM9BOh+XtCPvz4YiDn9SV1pBHjP1yPuF7RmFSyNu74YnTh1KeC+0OQCRCukG Anv5LP25INrlgLzZ+WtaMSh0ZX0hCgW+5whzzO+sqzftvM2bWDecXvaBuJ5+mt8wPqNd +kdQ6lyoefBcG1npO95QAlph9oZNKvA9sTOwceZhws4QIcZEisP/OZjrzUdhpJZDM4xJ cuSYHuCMFHD5inAYzREqoePgYK4nNMmwufJznq0jElIQcgP9A6+DsIZVkzLeEOg3pELn tWFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710319567; x=1710924367; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xl9/EZGLKxGGHgqxXQrNVV9/fXW9fCPtZn84F/TZCWo=; b=vsEl67g5dYK7OJbXbZev9vjAOo3u4H+yRJ5JFgpf9et88X4MrltkmEInWTS0BFVG0J bh14t3UixLteMUIAMdQ7/1A9ayuvB3NOSTcBYeWlo3ZWxwqOm+Fe8dvS3HfAMrXLgGNu ozM36pTFyyf/ig7+/RQ44mvJjooPVg6sxSS4epFvHiXniJxdyvHCJ8CYfuY6z17xeGjs 1ZMGBNbeDQCZb/sU905CgSVJLb4l/0WRNqbuEYsC/LdHeiE59GurOHWNmJKHV6slNK0F HxtWpOnwaJO1lf1wcL2VR7n/sc+GfkvhFQIxVbBbZkB3u/e1ahtjfyW7DEAxJmdybQeQ aE9Q== X-Forwarded-Encrypted: i=1; AJvYcCWjaN/qoRUd40kmqjQVcd1gQYUSu5d1XmFqYG3Q4e3DVKEi4CnYI5aOpKm5FdPRDP5JQhhEI3sjOmKFajZhJ9M+TcsbL+3+TGfmAfjK X-Gm-Message-State: AOJu0YwdsivOZYLiq26bfNZ9YAUcqKzuzvIh8pFZaRz6/hW0ZcGpNJBh ww1cCdWovs2X+caRcztr1nbbbG4aYGD2QtR6YEgrJI4vyOb8Hndcyi93+xNIxxs= X-Received: by 2002:a05:600c:1c84:b0:413:4299:ecd7 with SMTP id k4-20020a05600c1c8400b004134299ecd7mr2825793wms.0.1710319566968; Wed, 13 Mar 2024 01:46:06 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:1a26:f18f:eb07:b76a]) by smtp.gmail.com with ESMTPSA id w9-20020a05600c474900b00412706c3ddasm1612743wmo.18.2024.03.13.01.46.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 01:46:06 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Robin Ehn , Charlie Jenkins , "Stefan O'Rear" , Jessica Clarke Subject: [PATCH v4] riscv: hwprobe: export highest virtual userspace address Date: Wed, 13 Mar 2024 09:45:33 +0100 Message-ID: <20240313084554.31925-1-cleger@rivosinc.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some userspace applications (OpenJDK for instance) uses the free MSBs in pointers to insert additional information for their own logic and need to get this information from somewhere. Currently they rely on parsing /proc/cpuinfo "mmu=svxx" string to obtain the current value of virtual address usable bits [1]. Since this reflect the raw supported MMU mode, it might differ from the logical one used internally which is why arch_get_mmap_end() is used. Exporting the highest mmapable address through hwprobe will allow a more stable interface to be used. For that purpose, add a new hwprobe key named RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS which will export the highest userspace virtual address. Link: https://github.com/openjdk/jdk/blob/master/src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp#L171 [1] Signed-off-by: Clément Léger Reviewed-by: Charlie Jenkins --- v4: - Added Charlie Reviewed-by - Replace a tab instead of a space - Resend with actual V4 tag in front of message which was missing - Link to v3: https://lore.kernel.org/lkml/20240301164407.475957-1-cleger@rivosinc.com/ v3: - Note: I did not added Stefan Reviewed-by since I did more modifications than just a simple respin. - Handle CONFIG_MMU=n as well and rename the key to RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS - Add a user_max_virt_addr() macro to handle !MMU config - Link to v2: https://lore.kernel.org/lkml/20240220110950.871307-1-cleger@rivosinc.com/ v2: - Note: tried sysconf to export it but this is not backed by syscall and thus does not allow exporting such information easily. - Use arch_get_mmap_end() instead of VA_BITS since it reflects the maximum logical address used by the riscv port - Change hwprobe key name from RISCV_HWPROBE_KEY_VA_BITS to RISCV_HWPROBE_KEY_MAX_ADDRESS - Link to v1: https://lore.kernel.org/lkml/20240201140319.360088-1-cleger@rivosinc.com/ --- Documentation/arch/riscv/hwprobe.rst | 3 +++ arch/riscv/include/asm/hwprobe.h | 2 +- arch/riscv/include/asm/processor.h | 8 +++++++- arch/riscv/include/uapi/asm/hwprobe.h | 1 + arch/riscv/kernel/sys_hwprobe.c | 4 ++++ 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Documentation/arch/riscv/hwprobe.rst b/Documentation/arch/riscv/hwprobe.rst index b2bcc9eed9aa..875d3122bd66 100644 --- a/Documentation/arch/riscv/hwprobe.rst +++ b/Documentation/arch/riscv/hwprobe.rst @@ -210,3 +210,6 @@ The following keys are defined: * :c:macro:`RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE`: An unsigned int which represents the size of the Zicboz block in bytes. + +* :c:macro:`RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS`: An unsigned long which + represent the highest userspace virtual address usable. diff --git a/arch/riscv/include/asm/hwprobe.h b/arch/riscv/include/asm/hwprobe.h index 630507dff5ea..150a9877b0af 100644 --- a/arch/riscv/include/asm/hwprobe.h +++ b/arch/riscv/include/asm/hwprobe.h @@ -8,7 +8,7 @@ #include -#define RISCV_HWPROBE_MAX_KEY 6 +#define RISCV_HWPROBE_MAX_KEY 7 static inline bool riscv_hwprobe_key_is_valid(__s64 key) { diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index a8509cc31ab2..8af1182f5180 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -14,7 +14,7 @@ #include -#ifdef CONFIG_64BIT +#if defined(CONFIG_64BIT) && defined(CONFIG_MMU) #define DEFAULT_MAP_WINDOW (UL(1) << (MMAP_VA_BITS - 1)) #define STACK_TOP_MAX TASK_SIZE @@ -58,6 +58,12 @@ #define STACK_TOP DEFAULT_MAP_WINDOW +#ifdef CONFIG_MMU +#define user_max_virt_addr() arch_get_mmap_end(ULONG_MAX, 0, 0) +#else +#define user_max_virt_addr() 0 +#endif /* CONFIG_MMU */ + /* * This decides where the kernel will search for a free chunk of vm * space during mmap's. diff --git a/arch/riscv/include/uapi/asm/hwprobe.h b/arch/riscv/include/uapi/asm/hwprobe.h index 9f2a8e3ff204..3630e3f30354 100644 --- a/arch/riscv/include/uapi/asm/hwprobe.h +++ b/arch/riscv/include/uapi/asm/hwprobe.h @@ -67,6 +67,7 @@ struct riscv_hwprobe { #define RISCV_HWPROBE_MISALIGNED_UNSUPPORTED (4 << 0) #define RISCV_HWPROBE_MISALIGNED_MASK (7 << 0) #define RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE 6 +#define RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS 7 /* Increase RISCV_HWPROBE_MAX_KEY when adding items. */ /* Flags */ diff --git a/arch/riscv/kernel/sys_hwprobe.c b/arch/riscv/kernel/sys_hwprobe.c index a7c56b41efd2..560ea41a716d 100644 --- a/arch/riscv/kernel/sys_hwprobe.c +++ b/arch/riscv/kernel/sys_hwprobe.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -202,6 +203,9 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair, if (hwprobe_ext0_has(cpus, RISCV_HWPROBE_EXT_ZICBOZ)) pair->value = riscv_cboz_block_size; break; + case RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS: + pair->value = user_max_virt_addr(); + break; /* * For forward compatibility, unknown keys don't fail the whole -- 2.43.0