Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1134490lqj; Mon, 3 Jun 2024 11:06:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVozzH6GgWqGfOJzSSAXhNdKxx7ZubmZGeehj54Yp868GzwyAxU0Nc3CXQa5iAxBFLLWz63Aq5G7V6csOgis6bba5EaWCW9McXCd6yV8A== X-Google-Smtp-Source: AGHT+IEpsHPtY8J/0h2ATapL/1rBJM2eEohZxlMTh9hDJmhUmad6kWAXSggJetoGclGLj+XZGjkD X-Received: by 2002:a17:906:6089:b0:a67:7649:3c3b with SMTP id a640c23a62f3a-a681fb5fa1emr664221866b.5.1717437961529; Mon, 03 Jun 2024 11:06:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717437961; cv=pass; d=google.com; s=arc-20160816; b=a8GfqQ8GgHDDyWMY59GifWl7kJYdId5rjAiGr8aUYa2YQCmTp+tF3hMI+ZxITCs76p wP+/gB6FmyxbisoWLrf5QYim6wRYdsNRGtC6w0NJEGG/Z3I1vNqCf3tM44Cd2Pdsa+tM mCGdQBEiZXjEyiwpeSlcUxpbysSw8YaWz5ZTXj8YlkOK5wPLsjDik5HdvQeNl5Kjvrrp 384I1B3z66BCu+Qfge1yc+7aqj1hdUbVSLTHsllSn6xg7DIIdkS/d9cbvh0DHlPhx4Um T3E2fRgz+yC9fdmoo2783Kjn6Jdlp/lMTBSKaSvDD2PmFYJ53ZaNlb1V7nC93kDwmxBc bzWA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:message-id:to :from:cc:in-reply-to:subject:date:dkim-signature; bh=3jcvQIjFY4g0Y2/xyHIexxJ5t7wWhmDVa3Fa+B/xds4=; fh=KZaYlIsGDcvnqwkKC33ECGjPJ2TAK2BmF7XPy0Q1nI0=; b=YAmlaTDzrdBSyxZTGCAF7pBdiSb3z0oUqSuChMLfbkdG06OQxQRHabrWMOpVWmSBls JVtyr7VROcLtO5yJN1KcDuoo3FOmo4LR8GIy96FSfSgHG1EWQ/Hu2yk5sT4NA3Jplwr3 7gAOi3BC41nKIadSVoUgGa+b9612E4lcw+gKd8u1Xro3rp64ZFG7uG+2Q732d8kn0B0V 7qS0/4sNEXRf8VgNK++Ev9+4rCU2NmdVJSkY8SI1w4yNhLwd/tA2hbAAsB4lHU41sNO3 0cV2jAdNSKzDHsX2QUSG4mrbFB7EfkzjemebSo0y4SRgaSW1m6ggbOgdXj8Fg0AjTsbK rsGQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@dabbelt-com.20230601.gappssmtp.com header.s=20230601 header.b=gKk3BG8Z; arc=pass (i=1 spf=pass spfdomain=dabbelt.com dkim=pass dkdomain=dabbelt-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-199546-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199546-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 a640c23a62f3a-a68fe33c634si159604766b.386.2024.06.03.11.06.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 11:06:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199546-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=@dabbelt-com.20230601.gappssmtp.com header.s=20230601 header.b=gKk3BG8Z; arc=pass (i=1 spf=pass spfdomain=dabbelt.com dkim=pass dkdomain=dabbelt-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-199546-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199546-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 19F3C1F23C37 for ; Mon, 3 Jun 2024 18:06:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 49F6F137C37; Mon, 3 Jun 2024 18:05:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dabbelt-com.20230601.gappssmtp.com header.i=@dabbelt-com.20230601.gappssmtp.com header.b="gKk3BG8Z" Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 574FA136E1D for ; Mon, 3 Jun 2024 18:05:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717437953; cv=none; b=KlyO5sb7ehkqFCa5YhMknEd/UTZMrZjRa6yBwsJY4ZvCne+u0AFFfEJsuTppmwqxMMNgY1E52L8JrMRvfc+PfsmKml+icUlMesMGZY+602zQZf66gtrFTZHeJ2RsqQuClB/G2YjClPy0Bec5M71yrkwKCWrPjyi7K189L2p1eNQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717437953; c=relaxed/simple; bh=UYSnHjuXzxeSHt5cSAE1g0Y2V5QexSEt9S9IHF3Ofys=; h=Date:Subject:In-Reply-To:CC:From:To:Message-ID; b=Av9kZfg5PE1WkHFSP5qp9sCF5L5SORqaAarNijzv8JgMpws1epIR0UTZ+XQvOyzw0ZbJk2AIJB9vZS1I7XtEfUVbzy/Atu6KlXpE24Ccayn0E0aRo5E967CTtuMONrjXnNqVcAa+wzyl7cfnaSr+baalcnl8wl1lq0szVLnxbIs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dabbelt.com; spf=pass smtp.mailfrom=dabbelt.com; dkim=pass (2048-bit key) header.d=dabbelt-com.20230601.gappssmtp.com header.i=@dabbelt-com.20230601.gappssmtp.com header.b=gKk3BG8Z; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dabbelt.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dabbelt.com Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1f44b45d6abso2208645ad.0 for ; Mon, 03 Jun 2024 11:05:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20230601.gappssmtp.com; s=20230601; t=1717437950; x=1718042750; darn=vger.kernel.org; h=message-id:to:from:cc:in-reply-to:subject:date:from:to:cc:subject :date:message-id:reply-to; bh=3jcvQIjFY4g0Y2/xyHIexxJ5t7wWhmDVa3Fa+B/xds4=; b=gKk3BG8ZVMVE/Qpkzjg2LUpp1yBLrBQnOSDQXoOWtxmhpIJV5V7zJdOsj325fXaXcm QSgXvgIKAv+iScx4NKxuQLBczBcUFpbZ32WzC3d8tW918vpjEfCzXg9gtyu+rBGua+/G +ZGEOEo5pcabCwQZWE7iPp5VpVxgLXh5KGuOFcqQ5WRvMdffL/Q2mHv8EYbu3f4j7flc d1Ea5aUkvNHyyijyTWKIsGGEMj+qWi6BPbtlxKSfyRhIUYIHjsy2oMbWRgUQRgdkhTHz YZh2dEi/T6ciJbB7JzKq5i/Cn6+jFTIGseWT0hotQRqKBCEn0cyzG3LNyrPLmj3Zobt9 3Jew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717437950; x=1718042750; h=message-id:to:from:cc:in-reply-to:subject:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=3jcvQIjFY4g0Y2/xyHIexxJ5t7wWhmDVa3Fa+B/xds4=; b=hySAbtZZ5Q8syMRHNraLEjcVSjxwZHXUwBpWTZWmf9VrSG+DtbiKjnMd/lGOI7BlZP xEFdge7FKtEh2czkzv3IUzfScx4YNqZS/Pe+Darf6UVeEQHw622+b77hMVKT4PPWIAgb X1dOTnrN31xZ86kccpBzCll95stlILD8u1g23YCoRQWceEP0FiBqN94L0pMJ7Y2wRcb5 t/zURniW2cgnuGVMOJo0L0RSImJFULUTntQUmJ8hPNkD6FCOqifFc1T7VkseIB0cZYDM rF8eZttqW0SEm6P8RF331IZyBNOBAa1zBz+KxXhyghs6jjmPtb5REOvVp5NEYio9/Rc2 I6sw== X-Forwarded-Encrypted: i=1; AJvYcCVxmtYarrgX1s3ND04FQ2pFJwgT/pki3/UsVgDiGUtG+88sE+l0W9UvO/CrhXuUkWoc9c+W/vw/5BBw7Ce3yW+zx36970XwrDXD0HCA X-Gm-Message-State: AOJu0YybSMTWmiEIWBUb6ouHRIsp/EzTsK7i0h5kKszcj6m7mRRB75iW gibGCtlzQcuvmx8IEOcSB0paOySvVWo7sr3ZwFKBH+jPkofhvOluSB/t7zijyzw= X-Received: by 2002:a17:903:22cf:b0:1f6:7cc9:fb2c with SMTP id d9443c01a7336-1f67cc9fd61mr37287145ad.49.1717437949140; Mon, 03 Jun 2024 11:05:49 -0700 (PDT) Received: from localhost ([192.184.165.199]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323e3c33sm67722815ad.176.2024.06.03.11.05.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 11:05:47 -0700 (PDT) Date: Mon, 03 Jun 2024 11:05:47 -0700 (PDT) X-Google-Original-Date: Mon, 03 Jun 2024 11:05:41 PDT (-0700) Subject: Re: [PATCH] RISC-V: hwprobe: Add MISALIGNED_PERF key In-Reply-To: CC: cyy@cyyself.name, Evan Green , aou@eecs.berkeley.edu, ajones@ventanamicro.com, andy.chiu@sifive.com, cleger@rivosinc.com, Conor Dooley , costa.shul@redhat.com, corbet@lwn.net, Paul Walmsley , samitolvanen@google.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org From: Palmer Dabbelt To: jesse@rivosinc.com Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: On Mon, 03 Jun 2024 10:57:21 PDT (-0700), Palmer Dabbelt wrote: > On Wed, 29 May 2024 20:36:45 PDT (-0700), cyy@cyyself.name wrote: >> On 2024/5/30 02:26, Evan Green wrote: >>> RISCV_HWPROBE_KEY_CPUPERF_0 was mistakenly flagged as a bitmask in >>> hwprobe_key_is_bitmask(), when in reality it was an enum value. This >>> causes problems when used in conjunction with RISCV_HWPROBE_WHICH_CPUS, >>> since SLOW, FAST, and EMULATED have values whose bits overlap with >>> each other. If the caller asked for the set of CPUs that was SLOW or >>> EMULATED, the returned set would also include CPUs that were FAST. >>> >>> Introduce a new hwprobe key, RISCV_HWPROBE_KEY_MISALIGNED_PERF, which >>> returns the same values in response to a direct query (with no flags), >>> but is properly handled as an enumerated value. As a result, SLOW, >>> FAST, and EMULATED are all correctly treated as distinct values under >>> the new key when queried with the WHICH_CPUS flag. >>> >>> Leave the old key in place to avoid disturbing applications which may >>> have already come to rely on the broken behavior. >>> >>> Fixes: e178bf146e4b ("RISC-V: hwprobe: Introduce which-cpus flag") >>> Signed-off-by: Evan Green >>> >>> --- >>> >>> >>> Note: Yangyu also has a fix out for this issue at [1]. That fix is much >>> tidier, but comes with the slight risk that some very broken userspace >>> application may break now that FAST cpus are not included for the query >>> of which cpus are SLOW or EMULATED. >> >> Indeed. Since the value of FAST is 0b11, the SLOW and EMULATED are 0b10 and >> 0b01 respectively. >> >> When this key is treated as a bitmask and query with >> RISCV_HWPROBE_WHICH_CPUS if a CPU has a superset bitmask of the requested >> value on the requested key, it will remain in the CPU mask. Otherwise, the >> CPU will be clear in the CPU mask. But when a key is treated as a value, we >> will just do a comparison. if it is not equal, then the CPU will be clear >> in the CPU. That's why FAST cpus are included when querying with SLOW or >> EMULATED with RISCV_HWPROBE_KEY_CPUPERF_0 key now. >> >> For me, deprecating the original hwprobe key and introducing a new key >> would be a better solution than changing the behavior as my patch did. > > OK. I don't have a strong feeling either way: if someone has code that > tries to read this as a btimask then it'd be broken, but it would > technically be following the docs. > > That said, we're relying on this as a pretty core userspace portability > construct. So maybe the right answer here is to just be really strict > about compatibility and eat the pain when we make a mistake, just to > make sure we set the right example about not breaking stuff. > > So unless anyone's opposed, I'll pick this up for 6.11. Though a few of us were talking and it looks like it's probably best to just make this extensible and put the vector stuff in here too. So something like diff --git a/Documentation/arch/riscv/hwprobe.rst b/Documentation/arch/riscv/hwprobe.rst index df5045103e73..e74727e1b7c0 100644 --- a/Documentation/arch/riscv/hwprobe.rst +++ b/Documentation/arch/riscv/hwprobe.rst @@ -211,25 +211,30 @@ The following keys are defined: :c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_PERF`, but the key was mistakenly classified as a bitmask rather than a value. -* :c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_PERF`: An enum value describing the - performance of misaligned scalar accesses on the selected set of processors. +* :c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_PERF`: An set of enum values describing the + performance of misaligned accesses on the selected set of processors. - * :c:macro:`RISCV_HWPROBE_MISALIGNED_UNKNOWN`: The performance of misaligned + * :c:macro: `RISCV_HWPROBE_SCALAR_MISALIGNED_MASK`: Describes the performance + of scalar misaligned accesses. + + * :c:macro:`RISCV_HWPROBE_SCALAR_MISALIGNED_UNKNOWN`: The performance of misaligned accesses is unknown. - * :c:macro:`RISCV_HWPROBE_MISALIGNED_EMULATED`: Misaligned accesses are + * :c:macro:`RISCV_HWPROBE_SCALAR_MISALIGNED_EMULATED`: Misaligned accesses are emulated via software, either in or below the kernel. These accesses are always extremely slow. - * :c:macro:`RISCV_HWPROBE_MISALIGNED_SLOW`: Misaligned accesses are slower + * :c:macro:`RISCV_HWPROBE_SCALAR_MISALIGNED_SLOW`: Misaligned accesses are slower than equivalent byte accesses. Misaligned accesses may be supported directly in hardware, or trapped and emulated by software. - * :c:macro:`RISCV_HWPROBE_MISALIGNED_FAST`: Misaligned accesses are faster + * :c:macro:`RISCV_HWPROBE_SCALAR_MISALIGNED_FAST`: Misaligned accesses are faster than equivalent byte accesses. - * :c:macro:`RISCV_HWPROBE_MISALIGNED_UNSUPPORTED`: Misaligned accesses are + * :c:macro:`RISCV_HWPROBE_SCALAR_MISALIGNED_UNSUPPORTED`: Misaligned accesses are not supported at all and will generate a misaligned address fault. + * :c:macro: `RISCV_HWPROBE_VECTOR_MISALIGNED_MASK`: ... vector ... + * :c:macro:`RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE`: An unsigned int which represents the size of the Zicboz block in bytes. Jesse is looking at the vector misaligned stuff that's showing up on the hardware, so I'll just hold off on this for a bit -- that way we can get the vector stuff sorted out at the same time. > >>> I wanted to get this fix out so that >>> we have both as options, and can discuss. These fixes are mutually >>> exclusive, don't take both. >> >> It's better to note this strange behavior on >> Documentation/arch/riscv/hwprobe.rst so users can quickly understand the >> differences on the behavior of these two keys. >> >> The C code part looks good to me. >> >>> >>> [1] https://lore.kernel.org/linux-riscv/tencent_01F8E0050FB4B11CC170C3639E43F41A1709@qq.com/ >>> >>> --- >>> Documentation/arch/riscv/hwprobe.rst | 8 ++++++-- >>> arch/riscv/include/asm/hwprobe.h | 2 +- >>> arch/riscv/include/uapi/asm/hwprobe.h | 1 + >>> arch/riscv/kernel/sys_hwprobe.c | 1 + >>> 4 files changed, 9 insertions(+), 3 deletions(-) >>> >>> diff --git a/Documentation/arch/riscv/hwprobe.rst b/Documentation/arch/riscv/hwprobe.rst >>> index 204cd4433af5..616ee372adaf 100644 >>> --- a/Documentation/arch/riscv/hwprobe.rst >>> +++ b/Documentation/arch/riscv/hwprobe.rst >>> @@ -192,8 +192,12 @@ The following keys are defined: >>> supported as defined in the RISC-V ISA manual starting from commit >>> d8ab5c78c207 ("Zihintpause is ratified"). >>> >>> -* :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: A bitmask that contains performance >>> - information about the selected set of processors. >>> +* :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: Deprecated. Returns similar values to >>> + :c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_PERF`, but the key was mistakenly >>> + classified as a bitmask rather than a value. >>> + >>> +* :c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_PERF`: An enum value describing the >>> + performance of misaligned scalar accesses on the selected set of processors. >>> >>> * :c:macro:`RISCV_HWPROBE_MISALIGNED_UNKNOWN`: The performance of misaligned >>> accesses is unknown. >>> 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 dda76a05420b..bc34e33fef23 100644 >>> --- a/arch/riscv/include/uapi/asm/hwprobe.h >>> +++ b/arch/riscv/include/uapi/asm/hwprobe.h >>> @@ -68,6 +68,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_MISALIGNED_PERF 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 969ef3d59dbe..c8b7d57eb55e 100644 >>> --- a/arch/riscv/kernel/sys_hwprobe.c >>> +++ b/arch/riscv/kernel/sys_hwprobe.c >>> @@ -208,6 +208,7 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair, >>> break; >>> >>> case RISCV_HWPROBE_KEY_CPUPERF_0: >>> + case RISCV_HWPROBE_KEY_MISALIGNED_PERF: >>> pair->value = hwprobe_misaligned(cpus); >>> break; >>>