From patchwork Mon Jul 1 11:27:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11025683 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0DB071510 for ; Mon, 1 Jul 2019 11:29:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F40F4205FD for ; Mon, 1 Jul 2019 11:29:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8887284E8; Mon, 1 Jul 2019 11:29:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2DD5B205FD for ; Mon, 1 Jul 2019 11:29:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hhuTC-0002gF-MS; Mon, 01 Jul 2019 11:27:38 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hhuTC-0002g6-2q for xen-devel@lists.xenproject.org; Mon, 01 Jul 2019 11:27:38 +0000 X-Inumbo-ID: 39d7d17d-9bf3-11e9-8980-bc764e045a96 Received: from m4a0041g.houston.softwaregrp.com (unknown [15.124.2.87]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 39d7d17d-9bf3-11e9-8980-bc764e045a96; Mon, 01 Jul 2019 11:27:36 +0000 (UTC) Received: FROM m4a0041g.houston.softwaregrp.com (15.120.17.146) BY m4a0041g.houston.softwaregrp.com WITH ESMTP; Mon, 1 Jul 2019 11:27:30 +0000 Received: from M4W0335.microfocus.com (2002:f78:1193::f78:1193) by M4W0334.microfocus.com (2002:f78:1192::f78:1192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Mon, 1 Jul 2019 11:27:10 +0000 Received: from NAM04-BN3-obe.outbound.protection.outlook.com (15.124.8.10) by M4W0335.microfocus.com (15.120.17.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10 via Frontend Transport; Mon, 1 Jul 2019 11:27:10 +0000 Received: from BY5PR18MB3394.namprd18.prod.outlook.com (10.255.139.95) by BY5PR18MB3299.namprd18.prod.outlook.com (10.255.138.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2032.18; Mon, 1 Jul 2019 11:27:08 +0000 Received: from BY5PR18MB3394.namprd18.prod.outlook.com ([fe80::2005:4b02:1d60:d1bc]) by BY5PR18MB3394.namprd18.prod.outlook.com ([fe80::2005:4b02:1d60:d1bc%3]) with mapi id 15.20.2008.020; Mon, 1 Jul 2019 11:27:08 +0000 From: Jan Beulich To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v9 21/23] x86emul: add an AES/VAES test case to the harness Thread-Index: AQHVL//rjvi+w/B0mEG52cKePO+Mhg== Date: Mon, 1 Jul 2019 11:27:08 +0000 Message-ID: <8425cefe-adc1-b879-89e6-79d0554d07c8@suse.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0455.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:e::35) To BY5PR18MB3394.namprd18.prod.outlook.com (2603:10b6:a03:194::31) authentication-results: spf=none (sender IP is ) smtp.mailfrom=JBeulich@suse.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [87.234.252.170] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 656285d4-2905-46bf-065e-08d6fe170d8d x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:BY5PR18MB3299; x-ms-traffictypediagnostic: BY5PR18MB3299: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:854; x-forefront-prvs: 00851CA28B x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(346002)(136003)(396003)(366004)(376002)(39860400002)(189003)(199004)(6916009)(478600001)(5660300002)(256004)(76176011)(486006)(7736002)(80792005)(8676002)(4326008)(2501003)(66556008)(64756008)(66946007)(2906002)(66476007)(71190400001)(8936002)(71200400001)(66446008)(25786009)(73956011)(3846002)(446003)(68736007)(36756003)(81166006)(81156014)(66066001)(14454004)(6116002)(31686004)(11346002)(99286004)(305945005)(86362001)(31696002)(6436002)(386003)(6506007)(53936002)(102836004)(2616005)(54906003)(52116002)(6512007)(72206003)(316002)(476003)(186003)(6486002)(5640700003)(26005)(2351001); DIR:OUT; SFP:1102; SCL:1; SRVR:BY5PR18MB3299; H:BY5PR18MB3394.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: suse.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 7r94KkrC7wsV9mIXvf9TQbKiTXrfFJwbNk6BcqpUCauRIG1nrQJVQHR8WuXtrbjbOueUOgYdQDBtoPjLEkCvBYbU1h+LM9/ojX7zQnPXtVRABnTW3U+gCg6cWvMSUQZuGpmloS7TJ32VPAMksdt1zW5LhFJnqdBaZchMPTi++SgzBIhT5tvJLpHraoj6ylecWz/u9n2GIYAbnH85mLgd4lNwZ0JHGoVli/g61u7+RVy/05qVYxp0VkWemSMmE7r2NEX/Pge953CdeBJgtuX9mK+vvmUmGzGvON0yi2poNQdLse6OQATK1CpZMIcsAg1T4xUZ7V39+CxtbvDplsPgosSsBxE9tS1kuMjhy5O8aR+O9jm7zfIVVtwxCk1hpbdDwnFwdhN26yF3a0Ph2gu+X3IUMTSFmnVbsAp71L0g9Sg= Content-ID: MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 656285d4-2905-46bf-065e-08d6fe170d8d X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Jul 2019 11:27:08.6731 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 856b813c-16e5-49a5-85ec-6f081e13b527 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: JBeulich@suse.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR18MB3299 X-OriginatorOrg: suse.com Subject: [Xen-devel] [PATCH v9 21/23] x86emul: add an AES/VAES test case to the harness X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , RogerPau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- v8: New. --- a/tools/tests/x86_emulator/Makefile +++ b/tools/tests/x86_emulator/Makefile @@ -19,8 +19,9 @@ CFLAGS += $(CFLAGS_xeninclude) SIMD := 3dnow sse sse2 sse4 avx avx2 xop avx512f avx512bw avx512dq avx512er avx512vbmi FMA := fma4 fma SG := avx2-sg avx512f-sg avx512vl-sg +AES := ssse3-aes avx-aes avx2-vaes avx512bw-vaes GF := sse2-gf avx2-gf avx512bw-gf -TESTCASES := blowfish $(SIMD) $(FMA) $(SG) $(GF) +TESTCASES := blowfish $(SIMD) $(FMA) $(SG) $(AES) $(GF) OPMASK := avx512f avx512dq avx512bw @@ -143,6 +144,10 @@ $(1)-cflags := \ $(foreach flt,$($(1)-flts), \ "-D_$(vec)x$(idx)f$(flt) -m$(1:-sg=) $(call non-sse,$(1)) -Os -DVEC_MAX=$(vec) -DIDX_SIZE=$(idx) -DFLOAT_SIZE=$(flt)"))) endef +define simd-aes-defs +$(1)-cflags := $(foreach vec,$($(patsubst %-aes,sse,$(1))-vecs) $($(patsubst %-vaes,%,$(1))-vecs), \ + "-D_$(vec) -maes $(addprefix -m,$(subst -,$(space),$(1))) $(call non-sse,$(1)) -Os -DVEC_SIZE=$(vec)") +endef define simd-gf-defs $(1)-cflags := $(foreach vec,$($(1:-gf=)-vecs), \ "-D_$(vec) -mgfni -m$(1:-gf=) $(call non-sse,$(1)) -Os -DVEC_SIZE=$(vec)") @@ -153,6 +158,7 @@ endef $(foreach flavor,$(SIMD) $(FMA),$(eval $(call simd-defs,$(flavor)))) $(foreach flavor,$(SG),$(eval $(call simd-sg-defs,$(flavor)))) +$(foreach flavor,$(AES),$(eval $(call simd-aes-defs,$(flavor)))) $(foreach flavor,$(GF),$(eval $(call simd-gf-defs,$(flavor)))) $(foreach flavor,$(OPMASK),$(eval $(call opmask-defs,$(flavor)))) @@ -203,10 +209,13 @@ $(addsuffix .c,$(FMA)): $(addsuffix .c,$(SG)): ln -sf simd-sg.c $@ +$(addsuffix .c,$(AES)): + ln -sf simd-aes.c $@ + $(addsuffix .c,$(GF)): ln -sf simd-gf.c $@ -$(addsuffix .h,$(SIMD) $(FMA) $(SG) $(GF)): simd.h +$(addsuffix .h,$(SIMD) $(FMA) $(SG) $(AES) $(GF)): simd.h xop.h avx512f.h: simd-fma.c --- /dev/null +++ b/tools/tests/x86_emulator/simd-aes.c @@ -0,0 +1,102 @@ +#define UINT_SIZE 1 + +#include "simd.h" +ENTRY(aes_test); + +#if VEC_SIZE == 16 +# define AES(op, a...) __builtin_ia32_vaes ## op ## _v16qi(a) +# define imc(x) ((vec_t)__builtin_ia32_aesimc128((vdi_t)(x))) +#elif VEC_SIZE == 32 +# define AES(op, a...) __builtin_ia32_vaes ## op ## _v32qi(a) +# define imc(x) ({ \ + vec_t r_; \ + unsigned char __attribute__((vector_size(16))) t_; \ + asm ( "vaesimc (%3), %x0\n\t" \ + "vaesimc 16(%3), %1\n\t" \ + "vinserti128 $1, %1, %0, %0" \ + : "=&v" (r_), "=&v" (t_) \ + : "m" (x), "r" (&(x)) ); \ + r_; \ +}) +#elif VEC_SIZE == 64 +# define AES(op, a...) __builtin_ia32_vaes ## op ## _v64qi(a) +# define imc(x) ({ \ + vec_t r_; \ + unsigned char __attribute__((vector_size(16))) t_; \ + asm ( "vaesimc (%3), %x0\n\t" \ + "vaesimc 1*16(%3), %1\n\t" \ + "vinserti32x4 $1, %1, %0, %0\n\t" \ + "vaesimc 2*16(%3), %1\n\t" \ + "vinserti32x4 $2, %1, %0, %0\n\t" \ + "vaesimc 3*16(%3), %1\n\t" \ + "vinserti32x4 $3, %1, %0, %0" \ + : "=&v" (r_), "=&v" (t_) \ + : "m" (x), "r" (&(x)) ); \ + r_; \ +}) +#endif + +#ifdef __AVX512BW__ +# define ALL_TRUE (~0ULL >> (64 - ELEM_COUNT)) +# define eq(x, y) (B(pcmpeqb, _mask, (vqi_t)(x), (vqi_t)(y), -1) == ALL_TRUE) +# define aes(op, x, y) ((vec_t)AES(op, (vqi_t)(x), (vqi_t)(y))) +#else +# if defined(__AVX2__) && VEC_SIZE == 32 +# define to_bool(cmp) B(ptestc, , cmp, (vdi_t){} == 0) +# define aes(op, x, y) ((vec_t)AES(op, (vqi_t)(x), (vqi_t)(y))) +# else +# define to_bool(cmp) (__builtin_ia32_pmovmskb128(cmp) == 0xffff) +# define aes(op, x, y) ((vec_t)__builtin_ia32_aes ## op ## 128((vdi_t)(x), (vdi_t)(y))) +# endif +# define eq(x, y) to_bool((x) == (y)) +#endif + +int aes_test(void) +{ + unsigned int i; + vec_t src, zero = {}; + + for ( i = 0; i < ELEM_COUNT; ++i ) + src[i] = i; + + do { + vec_t x, y; + + touch(src); + x = imc(src); + touch(src); + + touch(zero); + y = aes(enclast, src, zero); + touch(zero); + y = aes(dec, y, zero); + + if ( !eq(x, y) ) return __LINE__; + + touch(zero); + x = aes(declast, src, zero); + touch(zero); + y = aes(enc, x, zero); + touch(y); + x = imc(y); + + if ( !eq(x, src) ) return __LINE__; + +#if VEC_SIZE == 16 + touch(src); + x = (vec_t)__builtin_ia32_aeskeygenassist128((vdi_t)src, 0); + touch(src); + y = (vec_t)__builtin_ia32_pshufb128((vqi_t)x, + (vqi_t){ 7, 4, 5, 6, + 1, 2, 3, 0, + 15, 12, 13, 14, + 9, 10, 11, 8 }); + if ( !eq(x, y) ) return __LINE__; +#endif + + src += ELEM_COUNT; + i += ELEM_COUNT; + } while ( i <= 256 ); + + return 0; +} --- a/tools/tests/x86_emulator/simd.h +++ b/tools/tests/x86_emulator/simd.h @@ -340,6 +340,10 @@ REN(pandn, , d); REN(por, , d); REN(pxor, , d); # endif +OVR(aesdec); +OVR(aesdeclast); +OVR(aesenc); +OVR(aesenclast); OVR(cvtpd2dqx); OVR(cvtpd2dqy); OVR(cvtpd2psx); --- a/tools/tests/x86_emulator/test_x86_emulator.c +++ b/tools/tests/x86_emulator/test_x86_emulator.c @@ -12,12 +12,15 @@ asm ( ".pushsection .test, \"ax\", @prog #include "sse.h" #include "sse2.h" #include "sse2-gf.h" +#include "ssse3-aes.h" #include "sse4.h" #include "avx.h" +#include "avx-aes.h" #include "fma4.h" #include "fma.h" #include "avx2.h" #include "avx2-sg.h" +#include "avx2-vaes.h" #include "avx2-gf.h" #include "xop.h" #include "avx512f-opmask.h" @@ -27,6 +30,7 @@ asm ( ".pushsection .test, \"ax\", @prog #include "avx512f-sg.h" #include "avx512vl-sg.h" #include "avx512bw.h" +#include "avx512bw-vaes.h" #include "avx512bw-gf.h" #include "avx512dq.h" #include "avx512er.h" @@ -91,6 +95,16 @@ static bool simd_check_xop(void) return cpu_has_xop; } +static bool simd_check_ssse3_aes(void) +{ + return cpu_has_aesni && cpu_has_ssse3; +} + +static bool simd_check_avx_aes(void) +{ + return cpu_has_aesni && cpu_has_avx; +} + static bool simd_check_avx512f(void) { return cpu_has_avx512f; @@ -141,6 +155,22 @@ static bool simd_check_avx512vbmi_vl(voi return cpu_has_avx512_vbmi && cpu_has_avx512vl; } +static bool simd_check_avx2_vaes(void) +{ + return cpu_has_aesni && cpu_has_vaes && cpu_has_avx2; +} + +static bool simd_check_avx512bw_vaes(void) +{ + return cpu_has_aesni && cpu_has_vaes && cpu_has_avx512bw; +} + +static bool simd_check_avx512bw_vaes_vl(void) +{ + return cpu_has_aesni && cpu_has_vaes && + cpu_has_avx512bw && cpu_has_avx512vl; +} + static bool simd_check_sse2_gf(void) { return cpu_has_gfni && cpu_has_sse2; @@ -319,6 +349,8 @@ static const struct { SIMD(XOP i16x16, xop, 32i2), SIMD(XOP i32x8, xop, 32i4), SIMD(XOP i64x4, xop, 32i8), + SIMD(AES (legacy), ssse3_aes, 16), + SIMD(AES (VEX/x16), avx_aes, 16), SIMD(OPMASK/w, avx512f_opmask, 2), SIMD(OPMASK+DQ/b, avx512dq_opmask, 1), SIMD(OPMASK+DQ/w, avx512dq_opmask, 2), @@ -418,6 +450,10 @@ static const struct { AVX512VL(_VBMI+VL u16x8, avx512vbmi, 16u2), AVX512VL(_VBMI+VL s16x16, avx512vbmi, 32i2), AVX512VL(_VBMI+VL u16x16, avx512vbmi, 32u2), + SIMD(VAES (VEX/x32), avx2_vaes, 32), + SIMD(VAES (EVEX/x64), avx512bw_vaes, 64), + AVX512VL(VL+VAES (x16), avx512bw_vaes, 16), + AVX512VL(VL+VAES (x32), avx512bw_vaes, 32), SIMD(GFNI (legacy), sse2_gf, 16), SIMD(GFNI (VEX/x16), avx2_gf, 16), SIMD(GFNI (VEX/x32), avx2_gf, 32), --- a/tools/tests/x86_emulator/x86-emulate.h +++ b/tools/tests/x86_emulator/x86-emulate.h @@ -125,10 +125,12 @@ static inline bool xcr0_mask(uint64_t ma #define cpu_has_sse cp.basic.sse #define cpu_has_sse2 cp.basic.sse2 #define cpu_has_sse3 cp.basic.sse3 +#define cpu_has_ssse3 cp.basic.ssse3 #define cpu_has_fma (cp.basic.fma && xcr0_mask(6)) #define cpu_has_sse4_1 cp.basic.sse4_1 #define cpu_has_sse4_2 cp.basic.sse4_2 #define cpu_has_popcnt cp.basic.popcnt +#define cpu_has_aesni cp.basic.aesni #define cpu_has_avx (cp.basic.avx && xcr0_mask(6)) #define cpu_has_f16c (cp.basic.f16c && xcr0_mask(6))