From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2B44C433EF for ; Wed, 13 Jul 2022 15:41:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236746AbiGMPlL (ORCPT ); Wed, 13 Jul 2022 11:41:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229861AbiGMPlK (ORCPT ); Wed, 13 Jul 2022 11:41:10 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F018C33350 for ; Wed, 13 Jul 2022 08:41:08 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id 72so10848761pge.0 for ; Wed, 13 Jul 2022 08:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=UT9udr50GJyKecsX3LcPCWE8RWAbvRVT9oWgYzDIcoI=; b=N/vz09RBgdWROPujBdceXyeBj9//LIn7VgkL1kKVPjyw7AHYvpVidq1atlGd09WNGf GLogGH3KycLY6csUZJ1od98eTTmv6klSKuLEb5ZQMcEz/HpLm99idSsBrnPjwru5ncrj ODJNP029hxSgU8MF/bxgX4T5u3IQaw0XHtcPePOqAhPtFSEonJFwRfaiZ9N7P7fog/3m kIawcWMHNTT4gpMqdZcYaehLMp+1eVWobTXsl1prvqgm8O0bjfCC82rdrS6iMtybZ//q qqUKI/joS2+cRs2bdeBQCpocHIMG5EGLBXa7Agf1aE7L4bbsJA+lDS2N5iCA8B2AtpVk h7SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=UT9udr50GJyKecsX3LcPCWE8RWAbvRVT9oWgYzDIcoI=; b=u8ft2ezFUJvRX0NV1bQIFMhanhI7+hqp62b7X+O+cZH4S6Ztkl4Efn6jOBBtNgHEOJ EvxcBJKVXw7GoagY6B6qDhPzbz68LQEKnE+ljyzsuFzBROuAh8NqZ+nK5RBJi40AIYIl t41WN2snooA52q1EUHlkX4sT1om5ISrndc93wyibyczUjak5GJnIm3g30CpeiSC16shv t2tp/JbVKcuVO3MvT0stCi4ctj2eib7nEVp0mUCylFKvWkkl8Ms7gn5ZBwZILyC2qiW7 2JHBuphGH1/XVVQQZUI8xsgXgNM7M4OrgYe5rzP5J8oQ+k0e0u0cvQMD2gCHtiuOmsLW pEBQ== X-Gm-Message-State: AJIora+HwjulFTMu80d6IRXL0VMX79zqKw2WvZy2htM+Xv4RmoiTr6om ajE19M5vSz/kbxaHUkOzSftYZA== X-Google-Smtp-Source: AGRyM1tPCkg0z8Kca+zmBEg/o3uMJ/7f3MFzfn93JX1PyykFLy92b+ibQxZRHEFJ7WItU7DNR66iaw== X-Received: by 2002:a63:eb0f:0:b0:419:a843:aa29 with SMTP id t15-20020a63eb0f000000b00419a843aa29mr794459pgh.314.1657726868237; Wed, 13 Jul 2022 08:41:08 -0700 (PDT) Received: from google.com (123.65.230.35.bc.googleusercontent.com. [35.230.65.123]) by smtp.gmail.com with ESMTPSA id s4-20020a17090ad48400b001ec85441515sm1752965pju.24.2022.07.13.08.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 08:41:07 -0700 (PDT) Date: Wed, 13 Jul 2022 15:41:04 +0000 From: Sean Christopherson To: Vitaly Kuznetsov Cc: kvm@vger.kernel.org, Paolo Bonzini , Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] KVM: selftests: Fix wrmsr_safe() Message-ID: References: <20220713150532.1012466-1-vkuznets@redhat.com> <20220713150532.1012466-3-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220713150532.1012466-3-vkuznets@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 13, 2022, Vitaly Kuznetsov wrote: > It seems to be a misconception that "A" places an u64 operand to > EAX:EDX, at least with GCC11. It's not a misconception, it's just that the "A" trick only works for 32-bit binaries. For 64-bit, the 64-bit integer fits into "rax" without needing to spill into "rdx". I swear I had fixed this, but apparently I had only done that locally and never pushed/posted the changes :-/ > While writing a new test, I've noticed that wrmsr_safe() tries putting > garbage to the upper bits of the MSR, e.g.: > > kvm_exit: reason MSR_WRITE rip 0x402919 info 0 0 > kvm_msr: msr_write 40000118 = 0x60000000001 (#GP) > ... > when it was supposed to write '1'. Apparently, "A" works the same as > "a" and not as EAX/EDX. Here's the relevant disassembled part: > > With "A": > > 48 8b 43 08 mov 0x8(%rbx),%rax > 49 b9 ba da ca ba 0a movabs $0xabacadaba,%r9 > 00 00 00 > 4c 8d 15 07 00 00 00 lea 0x7(%rip),%r10 # 402f44 > 4c 8d 1d 06 00 00 00 lea 0x6(%rip),%r11 # 402f4a > 0f 30 wrmsr > > With "a"/"d": > > 48 8b 43 08 mov 0x8(%rbx),%rax > 48 89 c2 mov %rax,%rdx > 48 c1 ea 20 shr $0x20,%rdx > 49 b9 ba da ca ba 0a movabs $0xabacadaba,%r9 > 00 00 00 > 4c 8d 15 07 00 00 00 lea 0x7(%rip),%r10 # 402fc3 > 4c 8d 1d 06 00 00 00 lea 0x6(%rip),%r11 # 402fc9 > 0f 30 wrmsr > > I was only able to find one online reference that "A" gives "eax and > edx combined into a 64-bit integer", other places don't mention it at > all. > > Fixes: 3b23054cd3f5 ("KVM: selftests: Add x86-64 support for exception fixup") > Signed-off-by: Vitaly Kuznetsov > --- > tools/testing/selftests/kvm/include/x86_64/processor.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h > index 79dcf6be1b47..3d412c578e78 100644 > --- a/tools/testing/selftests/kvm/include/x86_64/processor.h > +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h > @@ -612,7 +612,7 @@ static inline uint8_t rdmsr_safe(uint32_t msr, uint64_t *val) > > static inline uint8_t wrmsr_safe(uint32_t msr, uint64_t val) > { > - return kvm_asm_safe("wrmsr", "A"(val), "c"(msr)); > + return kvm_asm_safe("wrmsr", "a"((u32)val), "d"(val >> 32), "c"(msr)); > } > > uint64_t vm_get_page_table_entry(struct kvm_vm *vm, struct kvm_vcpu *vcpu, > -- > 2.35.3 >