Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2474263pxa; Mon, 17 Aug 2020 10:27:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzj0Ph3G3RP7k7TyOpfPKWNQH0MqQlIZSGso8SutcG0FgNOATLiPv1Z2c5jJbBJUOvbdDE3 X-Received: by 2002:a17:906:ca8c:: with SMTP id js12mr16630230ejb.195.1597685255459; Mon, 17 Aug 2020 10:27:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597685255; cv=none; d=google.com; s=arc-20160816; b=gKYFVAHXHpSENXL+9GQixvHBSjKdgrr2c5/zmrohytt1KAcJYFYlG2QRTa965PlD8K dg7xt2ygPzOF42vsFytRs/zbxm61RbZUMSHiQxV6R3/enk9OER0n8AJY652ekdr02Jiw BMVHtpCQbI3KcYwvJOc5k5jiXFAP24pftTJWQ307OfqZ3vmz0TAVuSlB4BZOAx/a54Zf ioBjFjh5W3/5yiLUvQhwYeyyE1uocA6AVj7/Xww9LqysQ15DrdU3YJfjWuOXMLKEZCBV 8oltGToS1J7u7WvMoWVgQxjBQnfPh3CPb+gnKzin6v5kjgVgYnXGhKqJ6cGV1fx2NZw5 hN9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=2KOxcTzA4HjXLrbc8Kis3OZr0Jk9r2f94fOWh6B2JtI=; b=rZbXQ/dbt2PNO+/HyO5XmzdGYZHmq1rrov5jWgtQLkdrYvWRD5yFnaVk1m3H+vJGay K3NeYhC5/CHAeKCfVQXD+fwjomnNST5m3IF7KtLlB6GPwdIbAMc2u0JwB+BLmTs/L8WV C2vp1FvMZBwecvKaHYJruV7MAbQGPmy2FoYQK/JaHuCdjEprOxjOScx1OJ04YDltaJ5l shTbfoZRAUhOnWhDTh89OVShGgfx6jSQNXKjUmgVRsqjTvgKIMc2g9vDJ+ZViyiEquvy DpMgJRRK7+Xj9eDqTJT6fnWsbYsICRWuQb3iTEDP+hTTPstgIDoYoyaREpfa+IZDeAEb MpMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XBz6GJYE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n15si11511770ejk.642.2020.08.17.10.27.12; Mon, 17 Aug 2020 10:27:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XBz6GJYE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390024AbgHQRZ1 (ORCPT + 99 others); Mon, 17 Aug 2020 13:25:27 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:56759 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731459AbgHQRUp (ORCPT ); Mon, 17 Aug 2020 13:20:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597684844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=2KOxcTzA4HjXLrbc8Kis3OZr0Jk9r2f94fOWh6B2JtI=; b=XBz6GJYEGBFwPmHH9FcPApxgQWy607NhqWJ50zudkV1ZW2b/WPsK+2jZLbLmWVJrV0i49W 8FO62cvmZMJ9tYkxyX5utEcPgosJ68WGLMpAh5erkbnnf0PhQbFt86/p/JyD/RVowVZ5Gp 71ICP6jY2xG4l341S1wXKOE6FjTYnnI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-322-VJjp-ljEPnex_p-WPMyJ0g-1; Mon, 17 Aug 2020 13:20:39 -0400 X-MC-Unique: VJjp-ljEPnex_p-WPMyJ0g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 223CF81F001; Mon, 17 Aug 2020 17:20:38 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id B33FD5D9D2; Mon, 17 Aug 2020 17:20:34 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Sean Christopherson , peterx@redhat.com, Yang Weijiang , stable@vger.kernel.org Subject: [PATCH] selftests: kvm: Use a shorter encoding to clear RAX Date: Mon, 17 Aug 2020 13:20:34 -0400 Message-Id: <20200817172034.26673-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yang Weijiang If debug_regs.c is built with newer binutils, the resulting binary is "optimized" by the assembler: asm volatile("ss_start: " "xor %%rax,%%rax\n\t" "cpuid\n\t" "movl $0x1a0,%%ecx\n\t" "rdmsr\n\t" : : : "rax", "ecx"); is translated to : 000000000040194e : 40194e: 31 c0 xor %eax,%eax <----- rax->eax? 401950: 0f a2 cpuid 401952: b9 a0 01 00 00 mov $0x1a0,%ecx 401957: 0f 32 rdmsr As you can see rax is replaced with eax in target binary code. This causes a difference is the length of xor instruction (2 Byte vs 3 Byte), and makes the hard-coded instruction length check fail: /* Instruction lengths starting at ss_start */ int ss_size[4] = { 3, /* xor */ <-------- 2 or 3? 2, /* cpuid */ 5, /* mov */ 2, /* rdmsr */ }; Encode the shorter version directly and, while at it, fix the "clobbers" of the asm. Reported-by: Yang Weijiang Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini --- tools/testing/selftests/kvm/x86_64/debug_regs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/debug_regs.c b/tools/testing/selftests/kvm/x86_64/debug_regs.c index 8162c58a1234..b8d14f9db5f9 100644 --- a/tools/testing/selftests/kvm/x86_64/debug_regs.c +++ b/tools/testing/selftests/kvm/x86_64/debug_regs.c @@ -40,11 +40,11 @@ static void guest_code(void) /* Single step test, covers 2 basic instructions and 2 emulated */ asm volatile("ss_start: " - "xor %%rax,%%rax\n\t" + "xor %%eax,%%eax\n\t" "cpuid\n\t" "movl $0x1a0,%%ecx\n\t" "rdmsr\n\t" - : : : "rax", "ecx"); + : : : "eax", "ebx", "ecx", "edx"); /* DR6.BD test */ asm volatile("bd_start: mov %%dr0, %%rax" : : : "rax"); -- 2.26.2