Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp618104rwb; Thu, 22 Sep 2022 04:26:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5R1nirF0/KaaDoTD4VPm1jSln+oZ8gIVy7g2uzIFCnSmpuGGCHoHvxKw/Kt6zP3eLEQ5Dc X-Received: by 2002:a05:6402:5c9:b0:446:fb0:56bb with SMTP id n9-20020a05640205c900b004460fb056bbmr2868068edx.173.1663845983710; Thu, 22 Sep 2022 04:26:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663845983; cv=none; d=google.com; s=arc-20160816; b=vW2be/ADzb0ifWVI3eQlHrIBDRf8ESn4/ovhC6/vaXs33lRUFl7DLQtN2imJWON2cJ ZyaljHp0VhLwZaIcqhEZD9eNqrWaFZt3I0pltq7196xniubjXZL3vzoldZO1uNgqkj21 E/Q7zUt1ZF6urP9A8yA/DT8r8al8uBYLfTsH0sCaSkHqpIQvoLRBMIhutVlFVTcE8yXf YnpZ8PIbw9dG3olmog/rTkVTpZb67Qo4E+ABzocfpag/t2TDCm6Pn1UQ81bboBzNNKkE 76fddpKFCkpDUGtpUYZo1UBbpTkClizWn+tlp24jcrrBzUrH6duX/3QnxcAsxtRnXmFH afQQ== 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=DWa45MwT9HJbbWL1v8RkC8+86JKx1olov1VZ+m1F3UG62q5hQ/ICyiZh5HZWd9473F ep/DNCPeaZAtujlzZHrsMsNwsZlzqj0bj8DOGUdDeMBwMyMxJPrUvyGRlnjgcYx6vHqC zlewzq2xGF3jB3tjCKFTSoIsfoIQN7WNsid+BvBpDpGEkevZPF/dTMMny5ZYBkY8F7PI HFYU66MWJHllp+cScaxkFx21/KTlNd1K+mLdShXW717wsvvyyaEP2mxSkrrDl+JhLvok 1CSmGMG7ZrSLez7bufmu3+iCEGmsTy+4nGf+/yepJ0MzqpO7V6AqbqRXpK/lSTErO6fF XXFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=pTWXc0aH; 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 j8-20020aa7c408000000b0044ec439e9b0si4637204edq.346.2022.09.22.04.25.57; Thu, 22 Sep 2022 04:26:23 -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=pTWXc0aH; 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 S231319AbiIVLKv (ORCPT + 99 others); Thu, 22 Sep 2022 07:10:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229960AbiIVLKY (ORCPT ); Thu, 22 Sep 2022 07:10:24 -0400 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C116786FC4; Thu, 22 Sep 2022 04:10:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1663844390; bh=GiIwE9YHQOYSV1t9xMmzh55nme/2oo46Ec0cLTbVyBg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pTWXc0aH8nagv1sG4a/1BnYxtYlT7HgUJdIrz/5IehKnxao26LaFM/JbVxUphD0Sd CyAmyp2vj0l9GnpmxIctPlG4ybyzO8FyFvThOw7Ghu8Ek7c68k4yKSg0OFpioAQ+JD c94wjbf9MVWQR299ajNkKw5/wp+NI5DtPqq8i2mHeH5RrTTOZ7Htwz2ys7DLFUjBuh MOmQ1UvxzfN/vy3QhzI3N+PS5ZF/GC4nm7djsXncd4/qQYpsNvxm5rAr646XozLxbk Xr+pFUsMo3Mvx4cKEWpCsGCzbnDnZoNq42NwBSZ+cNL6g7g5fGr0FVBJbTHliqctSQ HYAxUamIIHkyA== Received: from localhost.localdomain (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4MYC3V11wDzNLB; Thu, 22 Sep 2022 06:59:50 -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 , Mathieu Desnoyers Subject: [PATCH v4 22/25] selftests/rseq: x86: Implement rseq_load_u32_u32 Date: Thu, 22 Sep 2022 06:59:37 -0400 Message-Id: <20220922105941.237830-23-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220922105941.237830-1-mathieu.desnoyers@efficios.com> References: <20220922105941.237830-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