Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2160216rwi; Thu, 3 Nov 2022 13:28:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM62A1WAJGC7kDVIXuDrQN4KBywHi5MTj/ZTCW8Tj6sNicNoV8eqM132bvLlB8hCm1Sg3lqj X-Received: by 2002:a05:6a00:1483:b0:56b:ab8e:f44a with SMTP id v3-20020a056a00148300b0056bab8ef44amr32143474pfu.85.1667507283820; Thu, 03 Nov 2022 13:28:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667507283; cv=none; d=google.com; s=arc-20160816; b=Adas+Zl/zVbu7MvuLiemeCVlBhg9cTIGyUmPV+TTLzx03ZY5D7xY5virnIskNF0e9n O6efrOKUkFF3JQp2j78XFtzuFkW3JwviPMf8iQ9Sfa+rC/mDBglQWphadZB+DRKNOIGK yJ2uTBChKn8uhypRekE/Nxx8FTR8cD/ZeR+qeXlelUw0xJ+cLv3+NZ1Tr+Ot065ZoII/ R80M9dtY7AOFMVs0AaymwC+2eawLkQUOjha7AIsWlQKbD+QlwB0Wyo8yLtX2gVxrcLnD SRnp0KQ5Nb2FZNzrL1bD3qVRyriatluOJHwomrK6InqIgu4zGH2+hMK+Xs+/SP/qjfjs Wh/w== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j2-20020a056a00174200b0056c6f255a7csi2209056pfc.170.2022.11.03.13.27.50; Thu, 03 Nov 2022 13:28:03 -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 + 97 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 Content-Transfer-Encoding: 8bit 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 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_ */ -- 2.25.1