Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3314998imm; Tue, 29 May 2018 05:14:09 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLmvlwJgu4+XO+pBRL6N3WgfmJ6hGsg8hYe5mcl6VrpcLfDyuGn0La496E9GQkDqPIvPh0Z X-Received: by 2002:a17:902:7105:: with SMTP id a5-v6mr9222583pll.171.1527596049951; Tue, 29 May 2018 05:14:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527596049; cv=none; d=google.com; s=arc-20160816; b=KyAYwGViDw2hnVZYvKr8CXwU0lYg3PJZq3hFQfWLNzTKT8RS1xk8S4sXBupoRihluG 7wgDo2NxPyhPIOusok+bajorEKbTrWA6feQ/tt2aTIEzpP0hyweaqGxeKKKgEUiRxpd0 clXSt8j02LOpj/jEHIVS3VUOolHSFMEFaPB5sqF/EmxXHnrY9R1Wjr1jdnS4PcxgS1l9 GshA8j1gO25ZgjyIet2UIsMKbkfes6JYXrVQoefnNulkqjWaoVmMJplOga3KNNsuG81G o2I/kw/Dw/tY6lCEe02PmizY8lUQWgP3Zs3J6NSDAfD2i4diNsSmRK7oVLSxCCfI9q3e UKvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=VuN1gp0a5b48252tdsSCItcbK/vbgQ3I3oNzQQ0dbXI=; b=Mep5PLP0mN5LlhCs/bHMTgP4W+z4cZQYZAVE+anGbbKP749F+zgDvlBNaXp82cb4y+ GyrWnJKXfN54MdWPteCzopxFq3KJNGV/l9kXEF4IGR4nUdcmill+aFLvosoX4RmdzjaK 6ip+3IW6ThXE4T0gS4livXsME99PjvJ7ly6RXuF6zzRDuKheAtKR2DpSX+mnBwVXL6kB wz7n3EMFLxMWdzPRB9W11xH+nON00dRBuJN0/nwIRAYuJaFwMMSAXrKdde48SYXai/iW 67+Z4MgGVFS6k6csIlFwLnmJ2U4kAu+111nN7vYxV8iOYS78S4IxiHvk4NAqoYH7An94 WJtw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y17-v6si16222650plp.485.2018.05.29.05.13.55; Tue, 29 May 2018 05:14:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933882AbeE2MMO (ORCPT + 99 others); Tue, 29 May 2018 08:12:14 -0400 Received: from foss.arm.com ([217.140.101.70]:38658 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933793AbeE2MMJ (ORCPT ); Tue, 29 May 2018 08:12:09 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A5A6815B2; Tue, 29 May 2018 05:12:09 -0700 (PDT) Received: from approximate.cambridge.arm.com (approximate.cambridge.arm.com [10.1.206.75]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4F2603F53D; Tue, 29 May 2018 05:12:07 -0700 (PDT) From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: Will Deacon , Catalin Marinas , Thomas Gleixner , Andy Lutomirski , Kees Cook , Greg Kroah-Hartman , Christoffer Dall , Randy Dunlap , Dominik Brodowski , Julien Grall , Mark Rutland Subject: [PATCH v2 15/17] arm64: Add test_and_clear_flag and set_flag atomic assembler primitives Date: Tue, 29 May 2018 13:11:19 +0100 Message-Id: <20180529121121.24927-16-marc.zyngier@arm.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180529121121.24927-1-marc.zyngier@arm.com> References: <20180529121121.24927-1-marc.zyngier@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As we're about to need to atomically manipulate some thread flags from entry.S, let's introduce two atomic primitives (test_and_clear_flag and set_flag) for that purpose. We provide two implementations: one using the traditional LL/SC instructions, and one using the ARMv8.1 atomics. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/assembler.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 0bcc98dbba56..d3612ad8035e 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -701,4 +702,40 @@ USER(\label, ic ivau, \tmp2) // invalidate I line PoU .Lyield_out_\@ : .endm +/* + * test_and_clear_flag: + * + * res: register containing the result (0 or 1 << bitnum) + * addr: address of the word to be manipulated + * bitnum: number of the bit in that word + * wtmp: temporary register, must be a 32bit reg + */ + .macro test_and_clear_flag, res, addr, bitnum, wtmp +alt_lse " prfm pstl1strm, [\addr]", "nop" +alt_lse "8:ldxr \res, [\addr]", "ldr \res, [\addr]" + tbz \res, #\bitnum, 9f +alt_lse " bic \res, \res, #(1 << \bitnum)", "mov \res, #(1 << \bitnum)" +alt_lse " stlxr \wtmp, \res, [\addr]", "ldclral \res, \res, [\addr]" +alt_lse " cbnz \wtmp, 8b", "nop" +alt_lse " dmb ish", "nop" +alt_lse " orr \res, \res, #(1 << \bitnum)", "nop" +9: + .endm + +/* + * set_flag: + * + * addr: address of the word to be manipulated + * bitnum: number of the bit in that word + * tmp: temporary register + * wtmp: temporary register, must be a 32bit reg + */ + .macro set_flag, addr, bitnum, tmp, wtmp +alt_lse " prfm pstl1strm, [\addr]", "mov \tmp, #(1 << \bitnum)" +alt_lse "8:ldxr \tmp, [\addr]", "stset \tmp, [\addr]" +alt_lse " orr \tmp, \tmp, #(1 << \bitnum)", "nop" +alt_lse " stxr \wtmp, \tmp, [\addr]", "nop" +alt_lse " cbnz \wtmp, 8b", "nop" + .endm + #endif /* __ASM_ASSEMBLER_H */ -- 2.14.2