Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp763723iob; Thu, 12 May 2022 04:16:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxA2OK7kLeJqvp3Kc/QdZBY2t7qS9pfqNun/6z2j7A1PBqWJtVAA/qUHUQWY2qTUXxbj+DL X-Received: by 2002:a17:90a:488c:b0:1c7:b62e:8e8c with SMTP id b12-20020a17090a488c00b001c7b62e8e8cmr10291242pjh.157.1652354198454; Thu, 12 May 2022 04:16:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652354198; cv=none; d=google.com; s=arc-20160816; b=nnCJ7JvYjCw7J6IXZxif1O4g/A9UdOUDaiCvfKbHQQqlE5/EDe76BHoijLcxAvj2kV x3VPdCX4p+z7+TOZ0zrfHievLKaacYg0qUiAa8kcDddkTh8nPixKTvSML9RlllZ3FyC1 QNPcF/V/o1QT2zEIN1dI7nQcy9XuvruvH2ndVN+GpzrRJH1BhKkq+3l8/kbR1kBAY+qd ugZf5rowsn5075jA90PlhkvF4nO0w8bJKTrSejue2wvqL/JDVF7sLThqEUgUa0XRiw0z pkKxSFH1L+YIMh9rrwAnS+ytIEO4MZvuaRUxbubFhddK0O9tUL5vxk90jKqbxKFNekyp ReVg== 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 :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=vzmKp6FemolAIrrL9HTlk0UTLaJcbzB/FCWqS422ox0=; b=n9C/0e7Wg9N4ZF2BdTx+Lqv9kg4tRy2aUJJx0UFNTHec1hD9QYaGc5W0fMe3bte0Md hdeRcrtPtgsNfYNmj2C4VmQc+TER+IXhSB7Ppif+kS7o/U3E9N3wUNTelMZpo4FR8fvL Wt0Z7oYsjmXuMzY5+HVPrjEEKQjbXGnpm5rYeskUoQ1iyc+Rh6G57raiXGjR3FSjO10o jXZg07QE2ooTsSREtdNCyJmKhdhERMlnH3GkacIeqvlkLGeQXuNCcsHUSD1cC6FLjX3U 1szLw1RcuQ2dd6yPajZx2oPCgQ5PiG0ktmby2f1QHrTPUclJ3FBKmcWIRFRjOqP2tx/p lFwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AWsf0Ztk; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s200-20020a632cd1000000b003aa563d774dsi3239105pgs.36.2022.05.12.04.16.25; Thu, 12 May 2022 04:16:38 -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=@redhat.com header.s=mimecast20190719 header.b=AWsf0Ztk; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235371AbiEKLed (ORCPT + 99 others); Wed, 11 May 2022 07:34:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235703AbiEKLea (ORCPT ); Wed, 11 May 2022 07:34:30 -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 7C9A841320 for ; Wed, 11 May 2022 04:34:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652268867; 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=vzmKp6FemolAIrrL9HTlk0UTLaJcbzB/FCWqS422ox0=; b=AWsf0ZtkjzeIr080ae2G4WXEfK8TQXZ2DMZhk0zMSTIEFiXz+UDq4lcQOwt7BBfpF2nPmS CjGjVMucoGuFJMnH1s1r1ZK1C7fR12CZfYAEQC9M5iUEY1zjYDY7YxkiIRwrXLviwH/C9h Wp2c7t1Q/Q305WvRExw5QShr5DCTxEA= 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-413-2-tgISkLMwWnnNTrM-Fnvg-1; Wed, 11 May 2022 07:34:23 -0400 X-MC-Unique: 2-tgISkLMwWnnNTrM-Fnvg-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 D70333C138CA; Wed, 11 May 2022 11:34:22 +0000 (UTC) Received: from starship (unknown [10.40.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93A411121314; Wed, 11 May 2022 11:34:20 +0000 (UTC) Message-ID: Subject: Re: [PATCH v3 23/34] KVM: selftests: Better XMM read/write helpers From: Maxim Levitsky To: Vitaly Kuznetsov , kvm@vger.kernel.org, Paolo Bonzini Cc: Sean Christopherson , Wanpeng Li , Jim Mattson , Michael Kelley , Siddharth Chandrasekaran , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 11 May 2022 14:34:19 +0300 In-Reply-To: <20220414132013.1588929-24-vkuznets@redhat.com> References: <20220414132013.1588929-1-vkuznets@redhat.com> <20220414132013.1588929-24-vkuznets@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_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 On Thu, 2022-04-14 at 15:20 +0200, Vitaly Kuznetsov wrote: > 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. > > 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 37db341d4cc5..9ad7602a257b 100644 > --- a/tools/testing/selftests/kvm/include/x86_64/processor.h > +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h > @@ -296,71 +296,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) Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky