Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp39278lqb; Tue, 28 May 2024 08:16:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUJ6Bz9LRcET1pA2qi6YrQcUxZnShdfagVTfOKpRh940DMUqJcNBj7oeAJ/Nc7Zw2NQiVknPC51hV557PBVZBukUZrSBUYl6VLooCIc8Q== X-Google-Smtp-Source: AGHT+IFpV6H/WR+d8hvn+LySgvbEwE0MizB9HjcJwRu+riWsY5pdJ/zQSjtcQokbuys3PXdD3f+V X-Received: by 2002:a50:f60b:0:b0:578:610d:b889 with SMTP id 4fb4d7f45d1cf-578610db9f0mr7647467a12.24.1716909396471; Tue, 28 May 2024 08:16:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716909396; cv=pass; d=google.com; s=arc-20160816; b=iPU7bp9cxK2jQseEd8YSdMZN/Ba80eBtGwnlic7igSttnhScDdGQ1Te9yvkW8WVHma tRjp3l7abzUewKW4mqnhXRt/FulMkcfnJ03dVj4yHp5II+WYl8QoxFvuQIC5Z2J7GFJ4 M/2jcKWAn+BWKxmx12/vw/41ZqnugWDTK0lohUIb1d4CtJiIkF9ysFvau6ZtvgFf8W9i f0zox8AbbMbIOQlmIIvOtaFkkXkPHfOVDzLiUtdoAQu8mveLqiuU6wtopSEZdyZIFl/M mbuo6UWK24KraPimsi8ynRJFJdkKXOYNlFbADYsED6z5LTnpKEfpXRi0vN5noCuoGp8+ mNVw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=QJ9jfwQtVSCqEew5FGQUfrRX44QJ3TNBiU9EdF5jARo=; fh=VbnJ6VF2Xu8cjCM7wbW5ocCEWxgqUPpc3VQlLR+v4HU=; b=NubRvKab87k11NwC+NyMrtoiEvQxDmE5lrB3FvSVVCp8ZiRGfDGLzxxWk0pptJP3Jb nhTD3mudKRgsovIY6H6ErHFgmuWe9BXISbuGjRj0OGELzqVbefma4paBf0YTgVJUUBMh NhE19mUF3SvXMJxWz/dtWyUj8pJCy7njMfuh8dzgQs4vE5FLkDJ+ILdSci6Pn8kvxVaV 6pYX/Tw2rFhhuN8YBGcNgZBWjM2DskSijifSSGWewa4Au+p58ZK+UJp6PA4Bb+CAIbeM 5A7BVmcAZKQLTpWBdvDzXXzEQzCpDy+qDTy2MX9DYuJBdN1UstShfXKMMW+0RZXENdQ4 wJOQ==; 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=yntQABQd; 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-192643-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192643-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 4fb4d7f45d1cf-578524b4307si5258788a12.532.2024.05.28.08.16.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 08:16:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192643-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=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=yntQABQd; 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-192643-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192643-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 E44ED1F24401 for ; Tue, 28 May 2024 15:16:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CD4FA174EF3; Tue, 28 May 2024 15:15:03 +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="yntQABQd" Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.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 2527416FF5E for ; Tue, 28 May 2024 15:15:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716909302; cv=none; b=mpHmuxW/724QC3G/kpFkEOHW1XMVu2AHmMVmVTdJtOxm8iXbGfFNxcyC4dUbpZkwvZZMphmYKzsfeatL2k16aQgrwhGRddXL+PFEfL9Ep0Y0B3NX7c/qYcrsSHxlFgYUkxR7H+KTQEyCRqgwR78uHI0s4ShDQ396f8vpJx1K/+s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716909302; c=relaxed/simple; bh=byVCn7vyyoWVCExOcLktbP9jgpsI9hB8fTXW6dyI5l4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qbUfbkl9n6ls4n9qUtgEx0yrDC2sI0G6uM0tfC9nCrvPe1ypSXiMDE+lGhNyJ+WQJQeuuviL3tOQRDjNlcYhRL1ti2dcJhY+aVrdjYw8/qYrnD7CHAABW9HOK2e4LUpY5v82GmatxOELDYgNDUeY6V85HbG6C4NZaXnDpgUEe3E= 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=yntQABQd; arc=none smtp.client-ip=209.85.208.171 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-lj1-f171.google.com with SMTP id 38308e7fff4ca-2e964acff1aso9771961fa.0 for ; Tue, 28 May 2024 08:15:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1716909299; x=1717514099; darn=vger.kernel.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=QJ9jfwQtVSCqEew5FGQUfrRX44QJ3TNBiU9EdF5jARo=; b=yntQABQd2Un8Wr1ZeQtRfwEySXNs4PXXc/bgKeXzgUEt1lh/x8IbAJLtmuIRWveMrI dKQkyxJ3VIo2a0vAt5uDvuhz6zyhhA2RNlNP/eW+BWUVr5rT0Ww02jxkXbdFQR+Q8yx4 raDEp09sVL4gbBA1DccmNWhyl7gTdZXJvbzruYtfURxWL+hMZc6CcpOf09ku3qW6Cwtu aZoJ1pnA3C1kztX0H8fCuHbLIBtxvZv8Bw/w5xr378I3F4yLwuNSPJzcxSSHH5EMM2Xx IZKSVfSsogKL7bB73qRmhm7xTNzRnMgfVIPLjDylZX4XTRfQ8OesccCwwMZKIXZXlWZ8 93sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716909299; x=1717514099; 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=QJ9jfwQtVSCqEew5FGQUfrRX44QJ3TNBiU9EdF5jARo=; b=bfMwXo5Qx7/ap6l586OKNp4ymY3kARobk1ifYQLy49ferfzMPlIxy7t3PyvXEJmzwP DfYhFZE+oKifOhlQwsloJcQqWULbY0RAva1wTHDMWaoA/wYrwzg/VZtNzmN1kaeOxcLb FrF1yJQs9gvvV8XDEvyVGugF2HJcdqMcaVN1Tg28eIjNMmIFVyLT6gPTmUOMoyss/ytj aolXgt71ktMe4pVhKQcSBmBCW8ajwF7PrnBjZ50lWwZ3GF7mNErLM2HFif6FYlfTp1N9 LRte8izEmkpxQzDv82RWpVBBSihlbT3hWqAg3Ddi5SlZIKi82rMyWHuQ3mb90LpftdwP csNg== X-Forwarded-Encrypted: i=1; AJvYcCV3577zn4hT2anrOODMRnwROnvYEqY6BcFRLekK0wq68BUS92ac5naPz+wo41eoLZrSxnXDSYbH0beQ4L2S8be819N8bEHNtxs94PMf X-Gm-Message-State: AOJu0YzLHCChDx5zIY3YdRFzXoGL3XyqUu6eHk1ixYJ6VB34a/TiZuZK OzAdJsRWWFVcqxpqD6AAea8dnmGBljw96RE/MfGEnhueZ8upKb4ibwexetMUXzs= X-Received: by 2002:a2e:a7c3:0:b0:2e9:546c:544a with SMTP id 38308e7fff4ca-2e95b28ae5emr87639391fa.34.1716909299278; Tue, 28 May 2024 08:14:59 -0700 (PDT) Received: from alex-rivos.home (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-421089708f8sm143918715e9.20.2024.05.28.08.14.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 08:14:58 -0700 (PDT) From: Alexandre Ghiti To: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , Arnd Bergmann , Leonardo Bras , Guo Ren , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-arch@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH 4/7] riscv: Implement xchg8/16() using Zabha Date: Tue, 28 May 2024 17:10:49 +0200 Message-Id: <20240528151052.313031-5-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240528151052.313031-1-alexghiti@rivosinc.com> References: <20240528151052.313031-1-alexghiti@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This adds runtime support for Zabha in xchg8/16() operations. Signed-off-by: Alexandre Ghiti --- arch/riscv/include/asm/cmpxchg.h | 24 ++++++++++++++++++++++-- arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/kernel/cpufeature.c | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h index 0789fbe38b23..43696d9e13aa 100644 --- a/arch/riscv/include/asm/cmpxchg.h +++ b/arch/riscv/include/asm/cmpxchg.h @@ -11,8 +11,14 @@ #include #include -#define __arch_xchg_masked(prepend, append, r, p, n) \ +#define __arch_xchg_masked(swap_sfx, prepend, append, r, p, n) \ ({ \ + __label__ zabha, end; \ + \ + asm goto(ALTERNATIVE("nop", "j %[zabha]", 0, \ + RISCV_ISA_EXT_ZABHA, 1) \ + : : : : zabha); \ + \ u32 *__ptr32b = (u32 *)((ulong)(p) & ~0x3); \ ulong __s = ((ulong)(p) & (0x4 - sizeof(*p))) * BITS_PER_BYTE; \ ulong __mask = GENMASK(((sizeof(*p)) * BITS_PER_BYTE) - 1, 0) \ @@ -34,6 +40,17 @@ : "memory"); \ \ r = (__typeof__(*(p)))((__retx & __mask) >> __s); \ + goto end; \ + \ +zabha: \ + __asm__ __volatile__ ( \ + prepend \ + " amoswap" swap_sfx " %0, %z2, %1\n" \ + append \ + : "=&r" (r), "+A" (*(p)) \ + : "rJ" (n) \ + : "memory"); \ +end: \ }) #define __arch_xchg(sfx, prepend, append, r, p, n) \ @@ -55,8 +72,11 @@ \ switch (sizeof(*__ptr)) { \ case 1: \ + __arch_xchg_masked(".b" sfx, prepend, append, \ + __ret, __ptr, __new); \ + break; \ case 2: \ - __arch_xchg_masked(prepend, append, \ + __arch_xchg_masked(".h" sfx, prepend, append, \ __ret, __ptr, __new); \ break; \ case 4: \ diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index e17d0078a651..f71ddd2ca163 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -81,6 +81,7 @@ #define RISCV_ISA_EXT_ZTSO 72 #define RISCV_ISA_EXT_ZACAS 73 #define RISCV_ISA_EXT_XANDESPMU 74 +#define RISCV_ISA_EXT_ZABHA 75 #define RISCV_ISA_EXT_XLINUXENVCFG 127 diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 3ed2359eae35..8d0f56dd2f53 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -257,6 +257,7 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { __RISCV_ISA_EXT_DATA(zihintpause, RISCV_ISA_EXT_ZIHINTPAUSE), __RISCV_ISA_EXT_DATA(zihpm, RISCV_ISA_EXT_ZIHPM), __RISCV_ISA_EXT_DATA(zacas, RISCV_ISA_EXT_ZACAS), + __RISCV_ISA_EXT_DATA(zabha, RISCV_ISA_EXT_ZABHA), __RISCV_ISA_EXT_DATA(zfa, RISCV_ISA_EXT_ZFA), __RISCV_ISA_EXT_DATA(zfh, RISCV_ISA_EXT_ZFH), __RISCV_ISA_EXT_DATA(zfhmin, RISCV_ISA_EXT_ZFHMIN), -- 2.39.2