From patchwork Thu Nov 3 20:03:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 15173 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp743711wru; Thu, 3 Nov 2022 13:09:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Jwi+abiDgEhCpA4Z+/6hwpCF1j4XzaMUbErvN4os080zXTsCoPc7X40BkE/ZkzfJ2erBR X-Received: by 2002:a17:902:7294:b0:187:146c:316f with SMTP id d20-20020a170902729400b00187146c316fmr26000239pll.149.1667506160115; Thu, 03 Nov 2022 13:09:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667506160; cv=none; d=google.com; s=arc-20160816; b=alCnFpSy1+FSP6rgYeJlIzO0Ss2NU6kfCsbDAdxmJmJOYnxSFSxBGYyVM/VN4eS4Vb YDhK2HKXMyA2+c4/bqOD7zU6unI4baPVDtuatm3lCpLZlXj+gm0pHIXKn7mODWKs/QBK 7hFnUVbd1HzlKRJMcH3BaXH4XBfbN6UnP6fQvhD5oTEfw6/w9m+1j4tpDb1Vd8lwG5Kb N3LOXB7LAsxTQ2tyuCKOwc6kXbLCP7WyZfFkUvFFm6vecZzuuuM4WSBFK/0u+saHA7q8 z5z4HJl0a4nKv/DJOho0kAcBZtYI93NMSO/Y/rSp+8SaJJt31PTN0aT27D6CizKtVICe vRqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZUWYc0SeyEl0gJpMClGi3IC0omiL1tibq738j2w64ZY=; b=sKMVMGPm4I4AKlK/6JqYH4eRWLDy5Uh8jLfnAriAsAKNz/KCLbj6wm4tBt9CxpauSC gxG1TsfuogsAMo4A7Q/Mftqz4icolP3VBwFFzEk+I0xovDczuFTNBD2+wUprarkLzdFz +7PEnIWP6eDu7H7vf0o/tN9pHLdQqM4RJIdwF6QFJLgOzmA96X+qE8UA9/r4QAjVfeeY ghU0SwP8fm0bvKiBnoBxYTgAuz0FOxRoY+wiegroWrYfOuu8EB4Hgwf1fGwQYP8nj/zT DJ6FU1R9JYWn9sO78F+E4KLAboNd4PGFG4W7F2gaYI4Dq7YllVcGvgdolETAU9CMCgxI gfDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=jK9MetJu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a170902e54600b00182c51058ffsi2091246plf.201.2022.11.03.13.09.02; Thu, 03 Nov 2022 13:09:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=jK9MetJu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231749AbiKCUG0 (ORCPT + 99 others); Thu, 3 Nov 2022 16:06:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231390AbiKCUFQ (ORCPT ); Thu, 3 Nov 2022 16:05:16 -0400 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EC2A205DA; Thu, 3 Nov 2022 13:05:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1667505903; bh=GiIwE9YHQOYSV1t9xMmzh55nme/2oo46Ec0cLTbVyBg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jK9MetJuTwG0Fg0JVJbVkhIanpaS8JS+zHzx0juAZx54apDnZdlReSL/2AjtLTpWB /g9QKkZ1/x1w12aZthGzNc8gYFxw6ikdIgkRseBO/C3yiUB3Hpss/zMt2uHJL8kO7+ vZUaTRkhhxHFgU2j+BpXhOL1BIp9Tb2sKk2PY2z7js+wEx50a9l3PfdkhoIhLR8ab2 yj4nvqt0vKQHaTpRJy0evCeKIEdXaAjNhnaZAUacAlaO2r38bqEerlAizHib1s1Q6z 4VA2qzkjKcpjU4HkFOROw9QppXEjwRvEgSp+EE4UG6JbzhR6vcB8UjIhdp9aM03Ado HyDuK28UsvZsg== Received: from localhost.localdomain (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4N3F9C2hGvzg2n; Thu, 3 Nov 2022 16:05:03 -0400 (EDT) From: Mathieu Desnoyers To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , "Paul E . McKenney" , Boqun Feng , "H . Peter Anvin" , Paul Turner , linux-api@vger.kernel.org, Christian Brauner , Florian Weimer , David.Laight@ACULAB.COM, carlos@redhat.com, Peter Oskolkov , Alexander Mikhalitsyn , Chris Kennelly , Mathieu Desnoyers Subject: [PATCH v5 21/24] selftests/rseq: x86: Implement rseq_load_u32_u32 Date: Thu, 3 Nov 2022 16:03:56 -0400 Message-Id: <20221103200359.328736-22-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221103200359.328736-1-mathieu.desnoyers@efficios.com> References: <20221103200359.328736-1-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748506939223421593?= X-GMAIL-MSGID: =?utf-8?q?1748506939223421593?= Allow loading a pair of u32 within a rseq critical section. It can be used in situations where both rseq_abi()->vm_vcpu_id and rseq_abi()->node_id need to be sampled atomically with respect to preemption, signal delivery and migration. Signed-off-by: Mathieu Desnoyers --- tools/testing/selftests/rseq/rseq-x86-bits.h | 43 ++++++++++++++++++++ tools/testing/selftests/rseq/rseq.h | 14 +++++++ 2 files changed, 57 insertions(+) diff --git a/tools/testing/selftests/rseq/rseq-x86-bits.h b/tools/testing/selftests/rseq/rseq-x86-bits.h index 28ca77cc876c..ef961ab012e5 100644 --- a/tools/testing/selftests/rseq/rseq-x86-bits.h +++ b/tools/testing/selftests/rseq/rseq-x86-bits.h @@ -990,4 +990,47 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t #endif +#if defined(RSEQ_TEMPLATE_CPU_ID_NONE) && defined(RSEQ_TEMPLATE_MO_RELAXED) + +#define RSEQ_ARCH_HAS_LOAD_U32_U32 + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER(rseq_load_u32_u32)(uint32_t *dst1, uint32_t *src1, + uint32_t *dst2, uint32_t *src2) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + /* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) + RSEQ_INJECT_ASM(3) + "movl %[src1], %%eax\n\t" + "movl %%eax, %[dst1]\n\t" + "movl %[src2], %%eax\n\t" + "movl %%eax, %[dst2]\n\t" + "2:\n\t" + RSEQ_INJECT_ASM(4) + RSEQ_ASM_DEFINE_ABORT(4, "", abort) + : /* gcc asm goto does not allow outputs */ + : [rseq_offset] "r" (rseq_offset), + /* final store input */ + [dst1] "m" (*dst1), + [src1] "m" (*src1), + [dst2] "m" (*dst2), + [src2] "m" (*src2) + : "memory", "cc", "rax" + RSEQ_INJECT_CLOBBER + : abort + ); + rseq_after_asm_goto(); + return 0; +abort: + rseq_after_asm_goto(); + RSEQ_INJECT_FAILED + return -1; +} + +#endif /* defined(RSEQ_TEMPLATE_CPU_ID_NONE) && defined(RSEQ_TEMPLATE_MO_RELAXED) */ + #include "rseq-bits-reset.h" diff --git a/tools/testing/selftests/rseq/rseq.h b/tools/testing/selftests/rseq/rseq.h index 95a76a1c3b27..30fa8bfd874e 100644 --- a/tools/testing/selftests/rseq/rseq.h +++ b/tools/testing/selftests/rseq/rseq.h @@ -381,4 +381,18 @@ int rseq_cmpeqv_trymemcpy_storev(enum rseq_mo rseq_mo, enum rseq_percpu_mode per } } +#ifdef RSEQ_ARCH_HAS_LOAD_U32_U32 + +static inline __attribute__((always_inline)) +int rseq_load_u32_u32(enum rseq_mo rseq_mo, + uint32_t *dst1, uint32_t *src1, + uint32_t *dst2, uint32_t *src2) +{ + if (rseq_mo != RSEQ_MO_RELAXED) + return -1; + return rseq_load_u32_u32_relaxed(dst1, src1, dst2, src2); +} + +#endif + #endif /* RSEQ_H_ */