Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp454457imn; Fri, 29 Jul 2022 12:07:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sWTHPEj9n3CEINSPR7tQDSlMLMdXcigV3OrpqPBzZVzweuHgSS402C8+8WyHLlfFbxGY+e X-Received: by 2002:a05:6402:430e:b0:43d:1cf6:61ec with SMTP id m14-20020a056402430e00b0043d1cf661ecmr4115640edc.194.1659121671575; Fri, 29 Jul 2022 12:07:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659121671; cv=none; d=google.com; s=arc-20160816; b=GDAqyswG+LeC906pI8sy+M67jijw3BW48neAD9K5o5qV/dw1oAG5PWZSHHP6X3y3JI go5Af2mvpEL6chOYpRktLCkl5WL6inVTHHtywrPJR6nTwe6HMz4eDqww172hPUlMEmx1 UEyVJBLGzp7DgfGHM2xZMt1t8vfkr6R44jimBcY2qTkAgJd2OURaQuEh52lKD5F+qrfS LBnpFUu/hn6rNzsErKkui6xi4etCsnh+MkPyrO9FGptOiRkdOxRBStpBh0juubMBAqE8 nASbLLEu3qlObAK14qCr6NeplGXMx1lPBdH8CGehFm0/QYsppKgmuvpvRBSPXtTln8o4 nroQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature:dkim-filter; bh=h9tSFFf+9NDh5w3UMA4ak85MvaSoM48KyykzPpV1Wwk=; b=eNhP8xPhPQ2ElQt2gdrOWecsKreb6r1eUl9/Z6C1OeTjMeLvsz8Dvg287n6aOQf9A/ QoI0QYsMQ1NA3f9ufD9ipZwZgF1ztTs45BcaZlJgpgMXuVl4n3Y9ONjdhWD75kcd2iGn HfJwjIVtFYZgQoEZBcemr/ib4c+GZRMCM+lHl0/K8B27t/R8LYRymFk1gPCNfs/MX0Tg pDXx7ecpUkR2VoIuApxuBloLbOITXRwNLh+BoQ69b7nkIA/YTb+HnziBnokgOCrvOhLS NSYAtdyHLHnH+ohWzbH2muy9AyeP89VpitVS/l3kFy8k1GQhHXhLzqKjm4vpAOlmxn8k Bq5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b="d/jbki2R"; 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 gn19-20020a1709070d1300b0070790bfa9a2si4977924ejc.154.2022.07.29.12.07.26; Fri, 29 Jul 2022 12:07:51 -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=default header.b="d/jbki2R"; 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 S238818AbiG2TEZ (ORCPT + 99 others); Fri, 29 Jul 2022 15:04:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238793AbiG2TDo (ORCPT ); Fri, 29 Jul 2022 15:03:44 -0400 Received: from mail.efficios.com (mail.efficios.com [167.114.26.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7EF18AB2B; Fri, 29 Jul 2022 12:03:04 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 2EB28318B71; Fri, 29 Jul 2022 15:03:02 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id p5u6UTBqgqEu; Fri, 29 Jul 2022 15:03:01 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 95D64318DEA; Fri, 29 Jul 2022 15:02:52 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 95D64318DEA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1659121372; bh=h9tSFFf+9NDh5w3UMA4ak85MvaSoM48KyykzPpV1Wwk=; h=From:To:Date:Message-Id; b=d/jbki2RQHZPrWpesTlzRrNNgMZBrKIzKpv2++G4PzMbs5lENwed1L8iUvlsxfcDG zlhrnUq+XKu1+nJyy+IDQA8wTYjRo4rPs47aJ4UZFoYbZmAINbeMNml0xvioLMjS+m Nx1p2MjpuIMyT24eLVKZnSQh4tIBnwr7o73gd5rtAcevi373DldB93aSipqHSuT4Gr QVyXILPF16HDY26/A5GtIMN3740asmcpBA/BkZfUE61kONCPEs24deuRQQ3h1L6sfc QPd/F0H+HPw/Ve+mdIScAMtK0kMuQLBER8BQQpVro0xKp2WIr4rz1bMA857Wz99zHP Kmeo0n+HSQ/Gg== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 4ViiKJQgwb0W; Fri, 29 Jul 2022 15:02:52 -0400 (EDT) Received: from localhost.localdomain (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by mail.efficios.com (Postfix) with ESMTPSA id 8A9B8318C74; Fri, 29 Jul 2022 15:02:48 -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 , Mathieu Desnoyers Subject: [PATCH v3 22/23] selftests/rseq: x86: Implement rseq_load_u32_u32 Date: Fri, 29 Jul 2022 15:02:24 -0400 Message-Id: <20220729190225.12726-23-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220729190225.12726-1-mathieu.desnoyers@efficios.com> References: <20220729190225.12726-1-mathieu.desnoyers@efficios.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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.17.1