From patchwork Tue Feb 20 11:09:46 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: 13563880 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 204A1C48BC4 for ; Tue, 20 Feb 2024 11:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=w+Rx/5s5KavZq6DWK5aDu2cMQXVE2GfvKAPvxkJiHrA=; b=xkqKJRXfIeEUY1 dRR0Uv6JMbmJKkZifXwzL48YesuJy1SQuBkU8pEQjVhtViji3XaOOY47td7AgnqIv8yLm/HzbzZCm PsFpJiY8ABtwr0y6c6fUJK2/gsr7p8KvuUNYhr0iAsh/Wk6BWmWTTsEntHs5rpMgVgae3BzpUQ1+s aUfooH2SQTliZpuRrK6Epn263D4CVioEbBrrF+ZqiWYgJUJebt2pS9mH0LNl8gMRpAZ9YvjGgnzam pcla98yoaInZf0sVpyaPFoP1MyywLAAhT1oYuWyg3qtiuWBtXnbif+0Xbc/ihQ1pi6W9CZNXkrSil NYt8OCEnZZ6iUaVazPlg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rcO0i-0000000EO9K-04CP; Tue, 20 Feb 2024 11:10:04 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rcO0f-0000000EO8L-0BC5 for linux-riscv@lists.infradead.org; Tue, 20 Feb 2024 11:10:03 +0000 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-33d0a82685dso1004378f8f.1 for ; Tue, 20 Feb 2024 03:10:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708427399; x=1709032199; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=R+NE38xHg+iFcMOIUoO6dahKVI267XimNpzeYRqug0o=; b=PKzgL9bpT133l75LiOpMgkm01qEn2gQRE2SlvTSDjZQgQ99S4nd8pgKkEYPj0hIM9j 75uZmJh3X5jHv2EaN3zHLFiK+9srhnLygKbtYntUZjiSjv9fE7RE4FEmk81h4tWYph26 wYrYFOnV9eRd9ZSVKIXdB4wzqQgzqWlQBPZP0w/DqECDYiMSeXJrmsyn6+gNiWMmhT8o qUv1FQnDs82Zo5e5WCla6fY4cvTli9pgX7+hbfJ8cJre6OWKbnj29fTenbHiMH0FPaGu EvNO5rEBATU2u1yDeP9b0aiDTDjga/4VSZXgD8yqKwkuqrPlT3gYGGmugAVniamldqoC 2sZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708427399; x=1709032199; 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=R+NE38xHg+iFcMOIUoO6dahKVI267XimNpzeYRqug0o=; b=Mj/Qnuea4ZsHFGZO8pD/YTLZJPyH10Nk0ntQT686JPXAnTLoqcMK+ulhEA5NfGnnMN UpoUoDJMDXxkvp380tejS0UPkEAjmx7zVfrykw+HeQbGrd3ZG7r9jmJgmMBydmcNZeX5 ANCpJLey6TD5ZOCqLoIOJ7MZong/zD/jp+fL4TADN1rxrmQFciLbuBy6r68P649ZwyCh KngmnhW8rRLMR0LDlQ2zbMr81X8Em/54rhcMSEHp0Hk8+g0Yro8I7paALU3HWOQFPnwH Xty4lNpR+BEI84LPzr95NU74MJjTclOIpsrQUPWaRTwnJNnNUm8om8sifiKP/TjzzIE7 m4Iw== X-Forwarded-Encrypted: i=1; AJvYcCWVDMDLumbSFvAGKgDkCGAxsib3IEVaV1ULroj521yJLiOdsg++WuPzxdS5rY0EiVibxsmuLABcrhGrBX73YOTaOsErk+zwv3S35713hHwx X-Gm-Message-State: AOJu0Yxt09KUI+IdY1d8fx5Kh2xHb+19fPvd1ZaeP0BLSh8pQ8OPFkCx NVlpapEzK2pyDMDCdlpSpps6lf6UdDbDOvqVXxYNAnAE3AUk+NFeeMe+KOEbUKC/K60ooAnyNie f X-Google-Smtp-Source: AGHT+IFEeB57DA/UVYTFHFvFefw4+utIN4uHed+oWc9cOPONdvuPDUZUvkrfpHzHpS85/bYqCuA05g== X-Received: by 2002:a05:6000:79d:b0:33d:7221:97cf with SMTP id bu29-20020a056000079d00b0033d722197cfmr55643wrb.6.1708427399487; Tue, 20 Feb 2024 03:09:59 -0800 (PST) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:6202:c7ea:a0cd:ad4a]) by smtp.gmail.com with ESMTPSA id az19-20020adfe193000000b0033d6ff7f9edsm1092523wrb.95.2024.02.20.03.09.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 03:09:59 -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 v2] riscv: hwprobe: export largest userspace address Date: Tue, 20 Feb 2024 12:09:46 +0100 Message-ID: <20240220110950.871307-1-cleger@rivosinc.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240220_031001_293046_6DFCA81D X-CRM114-Status: GOOD ( 18.38 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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 used bits [1]. Since this reflect the raw MMU mode supported, it might differ from the logical one used internally. Exporting the maximum mmappable address through hwprobe will allow a more stable interface to be used. For that purpose, add a new hwprobe key named RISCV_HWPROBE_MAX_KEY which will export the maximum mmappable userspace 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: Stefan O'Rear --- 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/uapi/asm/hwprobe.h | 1 + arch/riscv/kernel/sys_hwprobe.c | 4 ++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Documentation/arch/riscv/hwprobe.rst b/Documentation/arch/riscv/hwprobe.rst index b2bcc9eed9aa..a626aa21ac74 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_MAX_USER_ADDRESS`: An unsigned long which + represent the maximum userspace mmappable address. 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/uapi/asm/hwprobe.h b/arch/riscv/include/uapi/asm/hwprobe.h index 9f2a8e3ff204..a6da434be9da 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_MAX_USER_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..19a47540b4a2 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_MAX_USER_ADDRESS: + pair->value = arch_get_mmap_end(ULONG_MAX, 0, 0); + break; /* * For forward compatibility, unknown keys don't fail the whole