From patchwork Wed Jul 3 17:42:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 809351 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp807912wru; Wed, 3 Jul 2024 10:43:55 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUmw5Oj1XUw156GJEMiVuN+ip0toZ3mRIaHYDksyu3GmIJePo20BKZIqk0AROZUQougFdvCkVcrh+ITcSzAw4XH X-Google-Smtp-Source: AGHT+IERxiJqJWsUX/HQe58EW2dJzmWuNxQ+QspmRIe2UDUg+U5dffaC5LG9XVx4jJNn7JaxgjXq X-Received: by 2002:a05:622a:1aa3:b0:446:61e2:c0c3 with SMTP id d75a77b69052e-44662e7124cmr125617681cf.59.1720028635014; Wed, 03 Jul 2024 10:43:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720028635; cv=none; d=google.com; s=arc-20160816; b=GvYqje31+eARhxABCMwd825BkdJSHCOZURmGMIA2GFL/6sx/yUz1Kev7UqwhCoqLaf +QSHIhmoN19Q8yiL/diXB9Dtc2aYNRWRSbNqtDZliRHQ4X97A527jr83HZUKXHUWVXLZ P7L3OkUqUAjVEXo35AjRmEnZMmg7Zrqu6OC5DTsEgRwC+fOGUSwrohRtos/UM+1J1Hn7 qAXXKDFR8cMm6Kily9HUGQRLdnKdntG4edslL5djX+N8DshX2zGQ3XC64IrHZqfL42Bp qLN7pJ00j2pKhsVWQz/x1Ut0kIwfIqwFzGE1QjRfDOypaiCUEZhbNu3ekrmyTUDDtVQ1 xKPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7R7OJJiu7/4ltitIhcOKEZN8yuDpc4Bx0+hw02RzbL8=; fh=Pt34uH2d6qd1+kMXHGmjTpArIG+IrIAL/tEkjT+KenA=; b=MnZRl2Dj/rcJUaY1JFy5U59YcB52W6nfYuE8+mpGZwYIpw8cGCQkIiCeWyEwqMO4n9 08WIyYTbn4+CSPA1NUerK/At/cHiNb9UdJzaybPT3a5oFc9hSokPT5Zl5WzHdyQZN62T TWjVBRt9Q+fpG0co8sdfay2iPi+HdOQn4tpVLDK2vVOq/6nZfDp8tnGVnBgd5nHqWJ2F 0UXWafkMOpYbhEllde/Z60J/yPdAqP93uMCr6VUsdeeQjFQwG7zN/sV1xV0mxkIW1kr+ 11wxIbSIIGdFiqXyqzhc785WDpLRP9SGjbvRcBPjqjUeMGAq1KtPV6gM6LDZjbdIDiAB VCwA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gpC6xX1t; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-446513c18b4si130824521cf.129.2024.07.03.10.43.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 Jul 2024 10:43:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gpC6xX1t; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sP40G-0003Kx-Rf; Wed, 03 Jul 2024 13:42:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sP40A-0003Iz-IM for qemu-devel@nongnu.org; Wed, 03 Jul 2024 13:42:42 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sP404-0005Lg-Ue for qemu-devel@nongnu.org; Wed, 03 Jul 2024 13:42:39 -0400 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-2c983d8bdc7so496366a91.0 for ; Wed, 03 Jul 2024 10:42:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720028554; x=1720633354; darn=nongnu.org; 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=7R7OJJiu7/4ltitIhcOKEZN8yuDpc4Bx0+hw02RzbL8=; b=gpC6xX1tTOi4L1sgLfED/zN96kolyJ6bY67FuzYRZPbhDC8tsDTQH9mOnemaJ0oDSY nX/1Zh00YB6BD7o+FK6qkiagA+QJC59x4CVMjjbFC/k/jtSUtsYOkOzFt+mYwCDuMAZi L6ULgRMGAMqdod8TGD1dzyHjcOVhYBbXfRjVPw+kdgTK0UTlgiCen+mi5giGzZNILApm yq/BdaYQmCJNPF0bah4ss/RM4YbKz8oWauNLaNH8eFgdqz/+kpQ1+MKGMam78c+sjnBE aUmMPy9R6kXaRKohlCqG8RvVb4IbotyHn0nZxRp1xEZgp3HzEEqXMvlXRsm1GOg7D3UE qNYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720028554; x=1720633354; 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=7R7OJJiu7/4ltitIhcOKEZN8yuDpc4Bx0+hw02RzbL8=; b=Flmu8GRMcGDPGcE7eLxPjf4hW7lyxMCfdwGpyOJapfve2cEZfUKiiP89wfV2n0SDNT MzsJqoenRzrf/qIPh+HgDHi6GJRVVCvyerIdB5ouah4pcOqqBHq0TGwXNB7ev7Pnd7OC goJL0p3gVBTzQmB7QZV5K8cKLmIDz0Fq6mZtoTLnwg0pjF2yAhX3fdoWDZ0az/ldrFgz w69XZjhVIbQO0wGl8DXY2ueJI/wQlGhRI9jja3VYSvcZFpwv0djoNEDXmBRkHrZG2f+G cOjoqRLSPklVEKitCtDcTMwREOc2rIMnc2OFZVmFFcCDswTj0kqrwC+tXU8m073nRqCi TXeA== X-Gm-Message-State: AOJu0YzvGxI8JbcaERcXg634qbs//qi2HR7ahiuBniPSH4zbC94haWHh 5NdNzDzYOuwktnY2NyEF0r4drXEak4awww5WgbmCZw4kAN/LgQhbn/UmK+m5kmC9zPvTJa/ll0g J X-Received: by 2002:a17:90a:9204:b0:2c9:6d07:18f4 with SMTP id 98e67ed59e1d1-2c96d071921mr3089793a91.35.1720028553579; Wed, 03 Jul 2024 10:42:33 -0700 (PDT) Received: from stoup.. (174-21-76-141.tukw.qwest.net. [174.21.76.141]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91d3e7d7bsm11070030a91.47.2024.07.03.10.42.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 10:42:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Alistair Francis , Daniel Henrique Barboza Subject: [PULL 6/7] util/cpuinfo-riscv: Use linux __riscv_hwprobe syscall Date: Wed, 3 Jul 2024 10:42:25 -0700 Message-Id: <20240703174226.2117169-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240703174226.2117169-1-richard.henderson@linaro.org> References: <20240703174226.2117169-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1034.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org With recent linux kernels, there is a syscall to probe for various ISA extensions. These bits were phased in over several kernel releases, so we still require checks for symbol availability. Acked-by: Alistair Francis Reviewed-by: Daniel Henrique Barboza Signed-off-by: Richard Henderson --- meson.build | 6 ++++++ util/cpuinfo-riscv.c | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/meson.build b/meson.build index 54e6b09f4f..2f981f936e 100644 --- a/meson.build +++ b/meson.build @@ -2862,6 +2862,12 @@ have_cpuid_h = cc.links(''' }''') config_host_data.set('CONFIG_CPUID_H', have_cpuid_h) +# Don't bother to advertise asm/hwprobe.h for old versions that do +# not contain RISCV_HWPROBE_EXT_ZBA. +config_host_data.set('CONFIG_ASM_HWPROBE_H', + cc.has_header_symbol('asm/hwprobe.h', + 'RISCV_HWPROBE_EXT_ZBA')) + config_host_data.set('CONFIG_AVX2_OPT', get_option('avx2') \ .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot enable AVX2') \ .require(cc.links(''' diff --git a/util/cpuinfo-riscv.c b/util/cpuinfo-riscv.c index 7dcfbee2ab..497ce12680 100644 --- a/util/cpuinfo-riscv.c +++ b/util/cpuinfo-riscv.c @@ -6,6 +6,11 @@ #include "qemu/osdep.h" #include "host/cpuinfo.h" +#ifdef CONFIG_ASM_HWPROBE_H +#include +#include +#endif + unsigned cpuinfo; static volatile sig_atomic_t got_sigill; @@ -47,6 +52,27 @@ unsigned __attribute__((constructor)) cpuinfo_init(void) #endif left &= ~info; +#ifdef CONFIG_ASM_HWPROBE_H + if (left) { + /* + * TODO: glibc 2.40 will introduce , which + * provides __riscv_hwprobe and __riscv_hwprobe_one, + * which is a slightly cleaner interface. + */ + struct riscv_hwprobe pair = { .key = RISCV_HWPROBE_KEY_IMA_EXT_0 }; + if (syscall(__NR_riscv_hwprobe, &pair, 1, 0, NULL, 0) == 0 + && pair.key >= 0) { + info |= pair.value & RISCV_HWPROBE_EXT_ZBA ? CPUINFO_ZBA : 0; + info |= pair.value & RISCV_HWPROBE_EXT_ZBB ? CPUINFO_ZBB : 0; + left &= ~(CPUINFO_ZBA | CPUINFO_ZBB); +#ifdef RISCV_HWPROBE_EXT_ZICOND + info |= pair.value & RISCV_HWPROBE_EXT_ZICOND ? CPUINFO_ZICOND : 0; + left &= ~CPUINFO_ZICOND; +#endif + } + } +#endif /* CONFIG_ASM_HWPROBE_H */ + if (left) { struct sigaction sa_old, sa_new;