Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp191523lqj; Wed, 10 Apr 2024 07:53:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVN196L1DL0dkBwhvXZfFXyYwbGOnoXUYtyC10Nzt+7dmYikhNiluD4J0IbPRJ2e/kRTUQXIKQCohSJRrvWu+oDkvE7em7k3bH2lVQD3w== X-Google-Smtp-Source: AGHT+IFVxSM75MY4lkgTKqLVO1uvSZr1ipz+zhYKKQSZHi4dB7N9PPrH9wl6UYn07D5JVtaBw4ap X-Received: by 2002:a17:90a:eb14:b0:2a4:9222:a915 with SMTP id j20-20020a17090aeb1400b002a49222a915mr3315845pjz.0.1712760790447; Wed, 10 Apr 2024 07:53:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712760790; cv=pass; d=google.com; s=arc-20160816; b=zIFTsa9B8RgoG9nyZTKNBmuHCrJ8+BLwYPPvAx2tO8qiCVLoEiJct7PIsEB0bVKfLa o5SLmXeXp0fFeepr2gofehjd3JYuZJUA0XGFQiOkyDmuxxEIoO2gAlTSif9jAUS89P+P Z7rHDxXsG9xnMFKvbw9yC1Up7WGhRn4XGhpZlU+LK8Z3DIvVoa6viKvBTMkEmpUYU8Me sK60y45XGsZu6P+eQ56CdlNRJrbL+q1V2W2rU7qMF/lVhnEpIub7zaHh2tzz9uatxWr3 87Hkbv642E30upfGYs9f2LJtLXTKBMoP4EH+M3QYjQW9pu6bmHwLHxCS6LsvIWs6VKVZ ix9Q== 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=ckqATcdgxJCfEplA12RhN0CYzD0p8U1UjWm+/+bzbPs=; fh=8Wjm8mWAe2RDFiCd5jviYCkXnK+g2g4Fe9Zl0f2yofc=; b=c7wLLItAXMAwXkEA4rZBmhHgID7cW0Sn+eNc08JTqYU3Azd2URBh32Mqok0GC1Helj Sop9mtG8Qhw/wmqlaKz6F4ic0/rGB2Zqq+qLzzlkpwXOG3XEzpgJ/KrxWtMWM5A8cxjz NHJqte4CbU+J7/nNZeyDVGpl2z+qiEjVi9CNmUbRQARKezRDV84EIsm3FFl9tLPIPlEF 9GpW+gyQE80j5G6CbwjSJCpkcvVOazGUhQau0kw3QpPpJzSX0eEqq766kBRLi26jHOsz SRO+oPDlYGOkbgFYSm8fJJZPZRxgfT9GZCEAhiQQpoXSCWfKsuLweAWA6V9JtSP+I0Y1 gFlg==; 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=TJWmsgoq; 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-138803-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138803-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n15-20020a17090a4e0f00b002a545ed0b00si1657511pjh.166.2024.04.10.07.53.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 07:53:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-138803-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=TJWmsgoq; 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-138803-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138803-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 6C9AE28648F for ; Wed, 10 Apr 2024 14:52:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E2567173353; Wed, 10 Apr 2024 14:46:19 +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="TJWmsgoq" Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 5293B16C85A for ; Wed, 10 Apr 2024 14:46:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712760378; cv=none; b=k9cjvygGqAsObrUoc7eBm7DmdslLDqqllYwDa6BdnN1wmxF86d4MMNcwKNAWocijkSfenhDXB9AgyXLEqiw8soFLexLX7IGOYkMpXF3s5NJ/eL97tisgJ29UwfHTJ7VBU77Vd7q+ffr7oLCZvgNoJrdvkP95MAHQXMJo9Kt7GBs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712760378; c=relaxed/simple; bh=WgkrZgZQAl6ugPvfnsOWKCXijBgJrcY9jgRDbI6X6mI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=pAFgnz3HRyzLduo+IVnggJiKMhaBhe9Q12GNK04vnMeTUDHpstN/qrJzk1Lw2GhOWUBTQz2FhAMljm6ENdhJiAqS5EsOxlcOD6gS/OL7Fj682U3JQaq8l/fKWTMJLwq15rVqC+Vwe6VsQBWHtUX11kV/qN499FqiSUF6D2Xzn3c= 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=TJWmsgoq; arc=none smtp.client-ip=209.85.221.51 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-f51.google.com with SMTP id ffacd0b85a97d-346407b8c9aso660086f8f.0 for ; Wed, 10 Apr 2024 07:46:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712760373; x=1713365173; 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=ckqATcdgxJCfEplA12RhN0CYzD0p8U1UjWm+/+bzbPs=; b=TJWmsgoqHnI914w0dvG2pPHOr2C7PbsovQzT8vzlsBhS5n58mJZ0lSx0FBStYA72VQ qtCtUK/S6Z2WvkPAUZjSitjnza0jljsiA4gk++BxhRQKvwEuEs40vUUkVN+lhZjm6zrz eLkM9z4/ftg2D4y2Sy2XrmquG7PD2HKn67ABWvng5SN0x/JRlp2I73349Qb3DDkHnvwR 1lB36eVdsb7cYS2Gp/OIRP5mlnLMQJdOjvLOOe2tACaAbbOMKnRYW55PSsWVVW5rAwyJ beMc17SyAgny0RsMT7RX6/UmBY63H+HtKSMA1ZMLL7NfbBTaIDUZujnu9ukld4y6Pis/ VBpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712760373; x=1713365173; 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=ckqATcdgxJCfEplA12RhN0CYzD0p8U1UjWm+/+bzbPs=; b=oYEUV4hHnAxjc2iB1QsKIiBFJTce/f+plKMpjUFA5ysRgAIjO2QaO7J7FjYku70l1Y 0dr9JAJ+6ugnZt2exu98pCs2YyPzcFm3MF3N1yNa/vGFhYhfv5187FcozdZ0lqW2TEgH zSwNBbrOzcRt2vrTzfTmGhd91Ga1uIGsC+pZDHAXO4rZsZOqYZjcsbgIfdy2u9qRlSy1 e0BGOKZ3ityGeuTwe+Ax7BRjR3Jo2/1xUf84UJhtd1bAL46sbwx/6U1S1zKXLwMcTmK6 rA1gleDyaFbecEQeJ9UrMDNygkeizxXR6D8TnK0TN4UOtZBhMhmY366TBsMG0B5Lgfxs 5qJA== X-Forwarded-Encrypted: i=1; AJvYcCVMmi6RQWae57eqo0zO4oc85kNZcsAPxdyjCQpxrjalhTgDFtnZUGYeZhWbbqItr+LhX3g/uBcYAMiW4dyDG0Hr1hRM34HeHnFhar2b X-Gm-Message-State: AOJu0Yx1AQ2nykDlnsgZbkPZR2gH4UCb9iIWr1NH4eIBfT1+5z6kSata qI2Q9pCg2viIER0FZ87vphTbYklSshtAFsA0svGw3icmVoKIIoNr5BSrFBsK3ng= X-Received: by 2002:a5d:64e3:0:b0:343:ba58:1297 with SMTP id g3-20020a5d64e3000000b00343ba581297mr2344809wri.3.1712760373469; Wed, 10 Apr 2024 07:46:13 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:d4a6:5856:3e6c:3dff]) by smtp.gmail.com with ESMTPSA id c9-20020adffb09000000b00345c2f84d5asm7068715wrr.10.2024.04.10.07.46.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 07:46:13 -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 v5] riscv: hwprobe: export highest virtual userspace address Date: Wed, 10 Apr 2024 16:45:57 +0200 Message-ID: <20240410144558.1104006-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 --- Testing: This new hwprobe key can be tested using qemu and a simple hwprobe dump tool: https://github.com/clementleger/hwprobe_dump/tree/dev/cleger/highest_virt v5: - Rebased on master to fix merge conflicts - Link to v4: https://lore.kernel.org/lkml/20240313084554.31925-1-cleger@rivosinc.com/ 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 | 6 ++++++ arch/riscv/include/uapi/asm/hwprobe.h | 1 + arch/riscv/kernel/sys_hwprobe.c | 4 ++++ 5 files changed, 15 insertions(+), 1 deletion(-) 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 0faf5f161f1e..345d9a3e4b25 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -57,6 +57,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 8cae41a502dd..eddc0ffc47b4 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 @@ -215,6 +216,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