Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp229345iof; Mon, 6 Jun 2022 02:09:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYMIZmwF+HMjvuw6+zB/kVocRdbrTP/eB0+sYmvgZr8yg39lQEdzSmOPsC0QKJSxg7Xakn X-Received: by 2002:a17:902:e847:b0:164:4201:1d1f with SMTP id t7-20020a170902e84700b0016442011d1fmr23327409plg.84.1654506553212; Mon, 06 Jun 2022 02:09:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654506553; cv=none; d=google.com; s=arc-20160816; b=aHSJiARYaLujynoiE0veMUQw89wGDLW2vu4lzBjF6IbdEvhZelFXt23/AiAi71M44A fO74qR573x3FO34cg9E4fe7qwQEgDOBbFOp9/TQVXTd3VNylTzhi0V0rlpFDDrLR8mZO pfhn+4HzFeCPery23s7G7cd9CNYKQV9Hnqe5rWlYCziljeewo98PQt44u8ETgPdlyqPy E+39quASVaXWlZG4w3b5khcKI1syPA5+t1hbJpUfi35G6kPby3KR4JgxsjCLe2pfwlTY OC8TGBLImA6N0gPnsJ4bnSmuihbjKQLvYousfhvlZgEzGhv1TNS+vRGb3mTPwaYhJnIY tOFQ== 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=hp82BU+I7MuWflxbH4EWx7W3vuzx9MsZrRsI8zYTBvY=; b=rrQgBBUaSgBELTHT9U/Wo3kMm37Db5tzqetaaqlZeIJ1ujGDd7zTMAd3o8HzEIV9p8 gfrAD5wz+X/cOifU/G2Tbiu2t7ZvDjLRk/8tU61l21FB6z0mfJqJLMaoKLZ3jJUkZ3zY rI3AaRjkITFAj42cyTZ8DppGqc4uhP5nl6wdwYnpQMDqEpntMbi5oupMPsJIEIdyd+Ay SUMzRdrP3kc4WUVm4zTWj0LCxB0TQed8b/itlPJ6Hkuk1FL6gQkca+3FVpLZ5lQS2t/p wk2sCBd9mbyyF9FgyhqWIQ1L5hqSUChaTm610zRv+QCsmzRbiqmpSImkXY9+Ch6Lzekj 7VjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WYw8xjKV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b16-20020a170902b61000b0016388cdd5c0si2518452pls.310.2022.06.06.02.09.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 02:09:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WYw8xjKV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 494AE14915E; Mon, 6 Jun 2022 01:42:37 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232445AbiFFIjw (ORCPT + 99 others); Mon, 6 Jun 2022 04:39:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232066AbiFFIiH (ORCPT ); Mon, 6 Jun 2022 04:38:07 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C9EF021E1F for ; Mon, 6 Jun 2022 01:37:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654504678; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hp82BU+I7MuWflxbH4EWx7W3vuzx9MsZrRsI8zYTBvY=; b=WYw8xjKV7Dzu4P8eQu3tFH5z/l3hwLcgC4Q5jBRVAv59G50p1LUO5sWwyI7JaB9kYu2ghD hNcavYiVnRzsUjtmIJ/M/bgAHquRf/fvYsdbhIPkACJP7iEYz/sbjE1mS6AGT65gfCW/4s xIxnVSaoM8rutl2mk2CV+0dv2Mr9/mU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-665-ElNrg5xgP3-yZxgFY3UPIg-1; Mon, 06 Jun 2022 04:37:55 -0400 X-MC-Unique: ElNrg5xgP3-yZxgFY3UPIg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BB8D73C19021; Mon, 6 Jun 2022 08:37:54 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.193.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id D45DF1121314; Mon, 6 Jun 2022 08:37:52 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Sean Christopherson , Wanpeng Li , Jim Mattson , Michael Kelley , Siddharth Chandrasekaran , Yuan Yao , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 24/38] KVM: selftests: Better XMM read/write helpers Date: Mon, 6 Jun 2022 10:36:41 +0200 Message-Id: <20220606083655.2014609-25-vkuznets@redhat.com> In-Reply-To: <20220606083655.2014609-1-vkuznets@redhat.com> References: <20220606083655.2014609-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 set_xmm()/get_xmm() helpers are fairly useless as they only read 64 bits from 128-bit registers. Moreover, these helpers are not used. Borrow _kvm_read_sse_reg()/_kvm_write_sse_reg() from KVM limiting them to XMM0-XMM8 for now. Reviewed-by: Maxim Levitsky Signed-off-by: Vitaly Kuznetsov --- .../selftests/kvm/include/x86_64/processor.h | 70 ++++++++++--------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index 4fd870f37b9e..9ac244fdce73 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -315,71 +315,73 @@ static inline void cpuid(uint32_t *eax, uint32_t *ebx, : "memory"); } -#define SET_XMM(__var, __xmm) \ - asm volatile("movq %0, %%"#__xmm : : "r"(__var) : #__xmm) +typedef u32 __attribute__((vector_size(16))) sse128_t; +#define __sse128_u union { sse128_t vec; u64 as_u64[2]; u32 as_u32[4]; } +#define sse128_lo(x) ({ __sse128_u t; t.vec = x; t.as_u64[0]; }) +#define sse128_hi(x) ({ __sse128_u t; t.vec = x; t.as_u64[1]; }) -static inline void set_xmm(int n, unsigned long val) +static inline void read_sse_reg(int reg, sse128_t *data) { - switch (n) { + switch (reg) { case 0: - SET_XMM(val, xmm0); + asm("movdqa %%xmm0, %0" : "=m"(*data)); break; case 1: - SET_XMM(val, xmm1); + asm("movdqa %%xmm1, %0" : "=m"(*data)); break; case 2: - SET_XMM(val, xmm2); + asm("movdqa %%xmm2, %0" : "=m"(*data)); break; case 3: - SET_XMM(val, xmm3); + asm("movdqa %%xmm3, %0" : "=m"(*data)); break; case 4: - SET_XMM(val, xmm4); + asm("movdqa %%xmm4, %0" : "=m"(*data)); break; case 5: - SET_XMM(val, xmm5); + asm("movdqa %%xmm5, %0" : "=m"(*data)); break; case 6: - SET_XMM(val, xmm6); + asm("movdqa %%xmm6, %0" : "=m"(*data)); break; case 7: - SET_XMM(val, xmm7); + asm("movdqa %%xmm7, %0" : "=m"(*data)); break; + default: + BUG(); } } -#define GET_XMM(__xmm) \ -({ \ - unsigned long __val; \ - asm volatile("movq %%"#__xmm", %0" : "=r"(__val)); \ - __val; \ -}) - -static inline unsigned long get_xmm(int n) +static inline void write_sse_reg(int reg, const sse128_t *data) { - assert(n >= 0 && n <= 7); - - switch (n) { + switch (reg) { case 0: - return GET_XMM(xmm0); + asm("movdqa %0, %%xmm0" : : "m"(*data)); + break; case 1: - return GET_XMM(xmm1); + asm("movdqa %0, %%xmm1" : : "m"(*data)); + break; case 2: - return GET_XMM(xmm2); + asm("movdqa %0, %%xmm2" : : "m"(*data)); + break; case 3: - return GET_XMM(xmm3); + asm("movdqa %0, %%xmm3" : : "m"(*data)); + break; case 4: - return GET_XMM(xmm4); + asm("movdqa %0, %%xmm4" : : "m"(*data)); + break; case 5: - return GET_XMM(xmm5); + asm("movdqa %0, %%xmm5" : : "m"(*data)); + break; case 6: - return GET_XMM(xmm6); + asm("movdqa %0, %%xmm6" : : "m"(*data)); + break; case 7: - return GET_XMM(xmm7); + asm("movdqa %0, %%xmm7" : : "m"(*data)); + break; + default: + BUG(); } - - /* never reached */ - return 0; } static inline void cpu_relax(void) -- 2.35.3