From patchwork Fri Mar 1 16:44:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 208950 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp15184dyc; Fri, 1 Mar 2024 09:04:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW2obOHZ9ADuCvKCnDmUTL4hTe94zZ9Jo08BWC5Ee+mEbX6Lq4xTn0VLM1moaB9TAZYrlmwJeH+g9OLfw2hyNiFFOAHLA== X-Google-Smtp-Source: AGHT+IFCoh2HnTRIabb29wUQLXVE2rVbnRKZlfjl9z2HDp41yLiod6532n/FQZiy1rGK8yqYfsAx X-Received: by 2002:a6b:7842:0:b0:7c8:274f:4ae2 with SMTP id h2-20020a6b7842000000b007c8274f4ae2mr1702765iop.5.1709312686055; Fri, 01 Mar 2024 09:04:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709312686; cv=pass; d=google.com; s=arc-20160816; b=upMD+4VRlYQUhtAMAuTwwlt4zm0+PyBYuBPfBvN5G/PVC/+PIFT5akhH1bpmw0bgXv EGiVlCQwpivaLEZfmkwO9yq0071nYc8Kv0AdSm2yyjCQC/0hQaB26cP3f/SmThsIHofU P9Dl/ZycBPA8eze3QZH46+awRnuKe/RhC9ujhGAP41BEkcButQshIpVAXEF5iTKz6NHu nhcmHiXtT6b5CFuku6KYQWgivGIc9CTXlgmvvk8MK2mCIR7kO+v/bUstz75pa+mVah7k VFBbvg2AieRxcYmG1bS0vfyrSeGt8dwEJTjAWuSfxoFF2Xa4XMT+eDSpcYBgCfOvH6or tjEw== 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=0fSMW0qhtBaxw1Ne7+Ji9afXRUSlXWtRAYNnO9M03wA=; fh=/u1aw1VI64Z9+A4AIJICqOvuc9BnUe/C9ZRmxYLXrCA=; b=YuYmunOHIO9nAHXvfdO81OVJjlRjq8/ewrGlh8OYGrqYSYzFoC7R+h53pceT+XUBy1 MM4u26jkpkyVTc44XUPwwFxWp2xtte1J5anfuQJ9qAnvkOrcjNdQN/YbOFlFbrVCbmCA 00tD4y5MH7IbtleDMgEk7VmLcpfkgmXoL1LKw9zsY0o6JaeroRUSyYF0DHzLB7chDer+ 8hVbiQF+39JnYOU+wEcDRuAcMqnkf81meLYGa02n2cvE0DTaDFCBc1TUUBI1FyshSYPv OUDb//D73UZbjFaMUrgsaJeJqPiW056tAlWwrOtXmCaUy8lW3fMLmp0zLoKrYtTMTkVN bjUg==; 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=SkGQcwHQ; 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-88755-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88755-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n9-20020a056638120900b004742da57cecsi1313270jas.90.2024.03.01.09.04.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 09:04:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88755-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=SkGQcwHQ; 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-88755-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88755-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 746DF28BC77 for ; Fri, 1 Mar 2024 16:51:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DEE153D39B; Fri, 1 Mar 2024 16:44:58 +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="SkGQcwHQ" Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 059F33C47C for ; Fri, 1 Mar 2024 16:44:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709311495; cv=none; b=VPo52RP2bbBkI5KSbCRKGfaPy8v6IsNpcWO396Z1+9t9GwKl3YPF+Q2JVU+vjz3zS3tgPxO+SzvTUpRA/UO/MqTQMi/63vcv7dQggopmEjbtuGUPSdVoj+jF4nss7EHkTGbzCxAON//pBQqfl2AZ7w7wQFa98uvLdchUo5r70aU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709311495; c=relaxed/simple; bh=eW/jBE9xiI7mzT0S7JbXnNi/2VZkkXPS3pieWKtDhWA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=fERnI5QANPCIQnSungH6j/CM6tv6AjowVxTJ+0A+VZNuZAOAUiUiDJPjsEhyc/vykgkdi6F9wi3pbx3N7mNb+L8lwDTY1tdeGRa1A19eT18No/eQWJAem4CzcGih7kF1L3UhPZgiQxug6K9fstNRQtWYT1xe5cHRqyyLQrmPXuY= 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=SkGQcwHQ; arc=none smtp.client-ip=209.85.167.46 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-lf1-f46.google.com with SMTP id 2adb3069b0e04-5132bd70e7dso576777e87.1 for ; Fri, 01 Mar 2024 08:44:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1709311490; x=1709916290; 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=0fSMW0qhtBaxw1Ne7+Ji9afXRUSlXWtRAYNnO9M03wA=; b=SkGQcwHQSQw2jvhMg1rtMW0GIpv5/fDSioHSxRxKHmEONt9ynYhKeVKBmc371UcJzf 3GIb/2VaJP2k9RMeL3qW794AB2QoLsRW7OjOvkTogEzx2Boz+8KDLq58QlmcTBvUZT41 M7W/ZMVIKvSEAZpsZncsJu7bcT3L/KtgJOxwVgTbKWKL420AJTU+9IG2k/nRDc2fF1BX RCMa64JFTQn/URDR2NpGeru0Q76fWHZuc3Sy31a9K8wXZdMmN8RnB4TNDGwVAfUsh0IE ZW6RFvUri4mlYP4ZCi0SfRNVNAemLXspnU1kIJAgeTK6mO5M0Kp2Goq4kKpDEfw1lAy/ 137w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709311490; x=1709916290; 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=0fSMW0qhtBaxw1Ne7+Ji9afXRUSlXWtRAYNnO9M03wA=; b=b+EYTPtS9JBWTh5OufpV5rc0LQwnG2DHZod+695FtGMvxeWs+kDWVSMpPUVN26VtVy WLXWPR5szqjRQDWBwViwq4i+XV3Pv9YbrPt8UOe88dhEluIWhPI5KqtLFW4/L4lx+ViT rW1ijr4piaf430p4ivCZlEzMRl3Xlsv6iRqxL84dVXjb5+DtbA3V9HcAYhYC38na+Nhp XAhHpjIXjbjl+YqIX5HrrnLBbJFTt3XDIYSMV9vXG/m3jt7/+qSN8kNK5sZ7mqqZ9ZdQ LVp2Ps5Ncvgik8MSi5cHuFfQnKTNED/82Tj4LBTgxN2lz0G+0H5kn/019duzVxWQu0Ox zLoA== X-Forwarded-Encrypted: i=1; AJvYcCUXOBtS4jiQJngzXAscMvaaHA90uj2huG6cJzUJRSq/TJgGhIWsyFnBgDiC+6ylVqF1wdwM1idivlbo8betU0vHEEgj4tUw6eiylVm6 X-Gm-Message-State: AOJu0YzMc5VQiQ+jOQX/6E1geebobPnEE7j2jdieIgEOzi8qSyqF/+ay E5tQOB/wJ2nlh/KxUe3FKf5ggza0Kl4yiWMSywXI/S3alsRlAmPA2S4lXzmWecg= X-Received: by 2002:a05:6512:39c5:b0:513:258f:5ef3 with SMTP id k5-20020a05651239c500b00513258f5ef3mr2453949lfu.1.1709311489974; Fri, 01 Mar 2024 08:44:49 -0800 (PST) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:1cac:c075:fa3d:e5e9]) by smtp.gmail.com with ESMTPSA id t1-20020a5d5341000000b0033e11acf84asm4456462wrv.15.2024.03.01.08.44.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 08:44:49 -0800 (PST) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= 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?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Robin Ehn , Charlie Jenkins , "Stefan O'Rear" , Jessica Clarke Subject: [PATCH] riscv: hwprobe: export highest virtual userspace address Date: Fri, 1 Mar 2024 17:44:06 +0100 Message-ID: <20240301164407.475957-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792344258986586238 X-GMAIL-MSGID: 1792344258986586238 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 --- 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..341863d4d989 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