Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1468537lqp; Fri, 22 Mar 2024 16:40:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWtDJWU+AjiOYZC/yT6yXZO9XFt11giCEX1QFTadsCuwjYAhjcNUcrv+YDFa5evqs9PangsNf0P0PmvEXiPx2+uOQqs9Bb/CZoEgAkOJw== X-Google-Smtp-Source: AGHT+IECWG7EcYAcnpzlLWE8B6HsweiPvRXPkIRjlxeDozOsLmg9nt52hQh93EcME6AQRXOuI/Em X-Received: by 2002:a19:5e1e:0:b0:515:95cd:6802 with SMTP id s30-20020a195e1e000000b0051595cd6802mr498678lfb.64.1711150809717; Fri, 22 Mar 2024 16:40:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711150809; cv=pass; d=google.com; s=arc-20160816; b=iSDO8x9E72f+DzRobfIb6Q30vNlL4oYh9ykcJJtjRU42B7AF6aeYt7XxsjiXIQB14t ehxYfJz9I6WZrWim4JTJDsfw5PW6YBhTdY7fZOslV2d7lmlLSSgDq+NjMgCe+++3EDwh Y8ObERl8V2ae8TBrzgcI9pSAGGsxXeCdKivevZm5E2Vybl3PRUp2n3CDOWFbe+uo5tPD fStoS0mA1u/PXu84Ajs+bKx0ycULNL90xX1spoy7oXtiq28GKF5sZ4L15uTaUI8j10Qi NTD0zvfRWJ+wMwwdzs21hQfNRObAuvrJXDhdZOIfF4zf0Bw6gCPY32OlMc6+XKOW84te mvUA== 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:feedback-id:dkim-signature; bh=/F96a8YELf+Ur72xFbmW7ZJSVd3YYBPROndGsfciYiA=; fh=PDSqKCT1h6xJ9zvDZw5PP5PtjgxsGM4Xu7MARVC6MJo=; b=oYvCjxYxg1J1TcV8FdqHnrJpYwl08w6fLQcMsgDylCel8yppQh9ErH8dGDIAfZ7nca JtVuKMoKBBlYnyzsKbSZX3LIHR3lKAtSXPV6LLvVLC9mq5HtlZ/7AFqsBkBtADE95A0F WaV/Aj4DS/P8WnrKxnLSK7GZk/XrLnWTYwAskPTJDWBlwKhDxwW3VQ1zTWZtNNYOiYnR aK4wuKQFacW6ei32LkCwE0XuZ7zdBDjGfKjMTep3L2+3Bmx5OCf9rbuOBf5raFr02QuJ G49CUsnCdCiYG9k2Lrfh3N3n71ezn2jQ0KRmtMNSe+vBevYL61DdCervSSQFpcQNJLgZ DCGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CfeeYC1l; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112106-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112106-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z9-20020a1709060f0900b00a472e032d75si288296eji.991.2024.03.22.16.40.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 16:40:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112106-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CfeeYC1l; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112106-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112106-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 6FC9C1F23835 for ; Fri, 22 Mar 2024 23:40:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E2A483CD2; Fri, 22 Mar 2024 23:39:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CfeeYC1l" Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (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 7621082D87; Fri, 22 Mar 2024 23:39:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711150754; cv=none; b=utdqi50FSCY7+zWwLQjpshNnJQgnS/t8DqYz0zSuAHP+Lrd8QYbEG4QElSMtWIa58/go6IqOVD08nrrRS9+oDn2W66y38IBkFmFlYs8Ef7GMkAbIAtCtrXKZOapePeNR8jg1zTHacSEw4V6IUdQGJVpLuNSz0MjMHZ7S38jML6A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711150754; c=relaxed/simple; bh=/NBZoIhK1CtetohxAcHUpmJsAGut/+ZBo1KxCgXiFn0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aRH2mBmkL/SD6/q9w4zT4zTatNm7gc8SVrxuWv2k9uCGBo45QgZVtG4w8cBTyNXjuYLjlQbM2Az+uUd40tYMu1hXJOSFMpwNtxiAD8thoioJBN/4NwB+Kw1q1vPBTBzvve3xRogUEZquF5rj4VJKChpdLHST2C3WfaFZZMxDSxc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CfeeYC1l; arc=none smtp.client-ip=209.85.222.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-789e2bf854dso165694885a.3; Fri, 22 Mar 2024 16:39:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711150751; x=1711755551; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=/F96a8YELf+Ur72xFbmW7ZJSVd3YYBPROndGsfciYiA=; b=CfeeYC1ldfisFBhiiBFKBGYcJQ0/SaYb52QkB5VrW3FFBNoe5ZQKWpb+cgVuN9SMpq cbqBCAjNBoI3FwtE6l6YPqS5kn8J8ZoZvIFw5/GyH9Y1H11FmYRrFn1+6buzBOk4/pQO Cn87gJU4kQo3hszZ50B7kkZLp808EJNTXXCCzSbc28WAW7Oz+vq6YodsbAHOifrKftR/ 7OteAVDnIvwrK2iQqflVbZD8y91HU07d0zXX6VkEgTQ9lOl3KVJ87bCt7+kqkIRpu7zg +3bkdFf2ioFf05ycKsn18QLeV4FJJxVEsm/gSFa3JTKeHZxSMcqH+pAVb9kEd7468y/K M41Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711150751; x=1711755551; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=/F96a8YELf+Ur72xFbmW7ZJSVd3YYBPROndGsfciYiA=; b=xQIXwRH73q9uOKtNjh5MU5TzOwaqQiMmeez4E81KeQoVger+sZqxPhiv0ONKC5IiIV wEPzntEalC0Q5vcs6+v5UgUVKPZgEt667h1Kvo8XO2aJRCQMtdSK1eF1WC233GGVOVCI XSHVHA6w1RCVsXE7sfmPX+UvzMf2sccP10aCOs58jxuZBcE0wUiYnRikRsDfV1fGx1nq wf0m4lGXCbI9MQ/sMgDtAMpYZFoiUo0ZsPBEyby+A90j9ox5ZR3eLeZvJgL5LMo2XO2M Bijcbm2a01rcErPgRVPjSwDzd/0DEOOZLLF+lW+GJHn/mdlN/e321nqZfFzavSrFEbCy vs/w== X-Forwarded-Encrypted: i=1; AJvYcCUXnS+JIkTfNrC1askxqs+HFDSs2CKGjQlwhIH51ZGce+/H2syh248ZQFb/MAX+ZSfqnT92RrV955bMuREgIeEVOtDIcHUnOZOPszezCDeYozYYzTZ/23UZEVU+BB48AqaexZzLweJZLKpLFbTQjKKLmDC8KOwbDEOKlpSnVqN5tB9xvF1vvIE= X-Gm-Message-State: AOJu0YwIKj9aRGPO0bHrUjb3dU2TlOcLNYDSOCoxL4VL59knndzBqO5k 2eOPyPucOUx3FadPEHKlJwYY0c9jl1OaIn9BtZpwJWAABNw4UwHl X-Received: by 2002:a05:620a:40d3:b0:78a:3fb1:bade with SMTP id g19-20020a05620a40d300b0078a3fb1bademr1295433qko.1.1711150751298; Fri, 22 Mar 2024 16:39:11 -0700 (PDT) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id cz52-20020a05620a36f400b0078a43996ab7sm267608qkb.1.2024.03.22.16.39.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 16:39:10 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailauth.nyi.internal (Postfix) with ESMTP id E694E27C005B; Fri, 22 Mar 2024 19:39:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 22 Mar 2024 19:39:09 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddtfedgudegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeegleejiedthedvheeggfejveefjeejkefgveffieeujefhueeigfegueeh geeggfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdei gedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfih igmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 22 Mar 2024 19:39:08 -0400 (EDT) From: Boqun Feng To: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Alan Stern , Andrea Parri , Will Deacon , Peter Zijlstra , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Lustig , Joel Fernandes , Nathan Chancellor , Nick Desaulniers , kent.overstreet@gmail.com, Greg Kroah-Hartman , elver@google.com, Mark Rutland , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Catalin Marinas , torvalds@linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org Subject: [WIP 2/3] rust: atomic: Add ARM64 fetch_add_relaxed() Date: Fri, 22 Mar 2024 16:38:37 -0700 Message-ID: <20240322233838.868874-3-boqun.feng@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322233838.868874-1-boqun.feng@gmail.com> References: <20240322233838.868874-1-boqun.feng@gmail.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 Signed-off-by: Boqun Feng --- rust/kernel/sync/atomic/arch.rs | 6 ++++++ rust/kernel/sync/atomic/arch/arm64.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 rust/kernel/sync/atomic/arch/arm64.rs diff --git a/rust/kernel/sync/atomic/arch.rs b/rust/kernel/sync/atomic/arch.rs index 3eb5a103a69a..fc280f229237 100644 --- a/rust/kernel/sync/atomic/arch.rs +++ b/rust/kernel/sync/atomic/arch.rs @@ -5,5 +5,11 @@ #[cfg(CONFIG_X86)] pub(crate) use x86::*; +#[cfg(CONFIG_ARM64)] +pub(crate) use arm64::*; + #[cfg(CONFIG_X86)] pub(crate) mod x86; + +#[cfg(CONFIG_ARM64)] +pub(crate) mod arm64; diff --git a/rust/kernel/sync/atomic/arch/arm64.rs b/rust/kernel/sync/atomic/arch/arm64.rs new file mode 100644 index 000000000000..438f37cf7df6 --- /dev/null +++ b/rust/kernel/sync/atomic/arch/arm64.rs @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! ARM64 implementation for atomic and barrier primitives. + +use core::arch::asm; +use core::cell::UnsafeCell; + +pub(crate) fn i32_fetch_add_relaxed(v: &UnsafeCell, i: i32) -> i32 { + let mut result; + unsafe { + asm!( + "prfm pstl1strm, [{v}]", + "1: ldxr {result:w}, [{v}]", + "add {val:w}, {result:w}, {i:w}", + "stxr {tmp:w}, {val:w}, [{v}]", + "cbnz {tmp:w}, 1b", + result = out(reg) result, + tmp = out(reg) _, + val = out(reg) _, + v = in(reg) v.get(), + i = in(reg) i, + ) + } + + result +} -- 2.44.0