From patchwork Sat Feb 13 01:05:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12086475 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7274DC433E0 for ; Sat, 13 Feb 2021 01:06:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C3A464E05 for ; Sat, 13 Feb 2021 01:06:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232148AbhBMBGM (ORCPT ); Fri, 12 Feb 2021 20:06:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231743AbhBMBGK (ORCPT ); Fri, 12 Feb 2021 20:06:10 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8750CC0613D6 for ; Fri, 12 Feb 2021 17:05:30 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id r15so1033012qke.5 for ; Fri, 12 Feb 2021 17:05:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=OtznJizRN0hv7fVgLX6rnwrrxkCPL4lVRSWsCFjNnfE=; b=t56RiT1euE1E7CnLH3sOlDJSwYjYPxoxi/65GUwODU+vZGxsdYuG5+JudpeiQbYM/C ZFbuxsVlODgPdGNe/ORKCDGDUs6vPLRE4eEUhTNPQMTF/7ka0IiZrgOjzUUfSW1pCy8F yQexKIkRIlzOiBzSslW2f8bGyujBRRESZvdG1tDQJEuEA1sb+qmvq0d+f+dWDsOh887m rICHWD3PzXVRf37UTmBrWq6W5h+X1QzvK6HHtVDPG/lCd16qAg2vUCA4GEUP1MpAPHb1 2CwxXyh/k7TV8L3H8XmmhMcOgp4UegSpqOBvho3GdgNScCjqgwBzUv3s+SCQmCUIax6N ISVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=OtznJizRN0hv7fVgLX6rnwrrxkCPL4lVRSWsCFjNnfE=; b=lNQCG5H5G/r1JoQZ2vYT0QmI1jQMgklb/Ykk63clxY0fCn2+Xjrxh3+EEPUXfoFtH6 qWTp43cc8lV7saPIWXJhf3jQx8ZbiD5elr43QzIjkKRWeyYVmqZ+BtaH3ZBDq+Z3aF5w eOor/thkzZOHn1aRszHhNDHk5aX7+3Ok8ddhg4u2jDbwcgTiK7I85w3uFxfpfXbJO1eq Buf2Ym/Z0lAW4t6c6FZWVRjdyCHbVyAIgKp2hGhvDeYnqqkv7exfvzo43h6may6PaFXv fTC7XhtO4bOcnjGbgefM6oRiBAypDvnpmewvUTd609BGQ+8hiaUj16UoSolub0YJJz/9 nKtQ== X-Gm-Message-State: AOAM533hyQKEu9anRCYnebDMOw91LXX/wllOUib8e701lj6jMLUm9SJW P7BGbH5YH9aP6mzKvzqkk4r0FgICYug= X-Google-Smtp-Source: ABdhPJyHJCYOfqtyA0CEPVTw5ctoK1eVWrcbTWX8UBaNeZKIu8zioYMpaKyl/EHcdeGYZhRTW+srES5FTOQ= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:b407:1780:13d2:b27]) (user=seanjc job=sendgmr) by 2002:a05:6214:20a1:: with SMTP id 1mr5147613qvd.30.1613178329654; Fri, 12 Feb 2021 17:05:29 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 12 Feb 2021 17:05:10 -0800 In-Reply-To: <20210213010518.1682691-1-seanjc@google.com> Message-Id: <20210213010518.1682691-2-seanjc@google.com> Mime-Version: 1.0 References: <20210213010518.1682691-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 1/9] KVM: x86: Remove emulator's broken checks on CR0/CR3/CR4 loads From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Babu Moger , Joao Martins , David Woodhouse Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Remove the emulator's checks for illegal CR0, CR3, and CR4 values, as the checks are redundant, outdated, and in the case of SEV's C-bit, broken. The emulator manually calculates MAXPHYADDR from CPUID and neglects to mask off the C-bit. For all other checks, kvm_set_cr*() are a superset of the emulator checks, e.g. see CR4.LA57. Fixes: a780a3ea6282 ("KVM: X86: Fix reserved bits check for MOV to CR3") Cc: Babu Moger Signed-off-by: Sean Christopherson --- arch/x86/kvm/emulate.c | 68 +----------------------------------------- 1 file changed, 1 insertion(+), 67 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index f7970ba6219f..f4273b8e31fa 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -4230,75 +4230,9 @@ static int check_cr_read(struct x86_emulate_ctxt *ctxt) static int check_cr_write(struct x86_emulate_ctxt *ctxt) { - u64 new_val = ctxt->src.val64; - int cr = ctxt->modrm_reg; - u64 efer = 0; - - static u64 cr_reserved_bits[] = { - 0xffffffff00000000ULL, - 0, 0, 0, /* CR3 checked later */ - CR4_RESERVED_BITS, - 0, 0, 0, - CR8_RESERVED_BITS, - }; - - if (!valid_cr(cr)) + if (!valid_cr(ctxt->modrm_reg)) return emulate_ud(ctxt); - if (new_val & cr_reserved_bits[cr]) - return emulate_gp(ctxt, 0); - - switch (cr) { - case 0: { - u64 cr4; - if (((new_val & X86_CR0_PG) && !(new_val & X86_CR0_PE)) || - ((new_val & X86_CR0_NW) && !(new_val & X86_CR0_CD))) - return emulate_gp(ctxt, 0); - - cr4 = ctxt->ops->get_cr(ctxt, 4); - ctxt->ops->get_msr(ctxt, MSR_EFER, &efer); - - if ((new_val & X86_CR0_PG) && (efer & EFER_LME) && - !(cr4 & X86_CR4_PAE)) - return emulate_gp(ctxt, 0); - - break; - } - case 3: { - u64 rsvd = 0; - - ctxt->ops->get_msr(ctxt, MSR_EFER, &efer); - if (efer & EFER_LMA) { - u64 maxphyaddr; - u32 eax, ebx, ecx, edx; - - eax = 0x80000008; - ecx = 0; - if (ctxt->ops->get_cpuid(ctxt, &eax, &ebx, &ecx, - &edx, true)) - maxphyaddr = eax & 0xff; - else - maxphyaddr = 36; - rsvd = rsvd_bits(maxphyaddr, 63); - if (ctxt->ops->get_cr(ctxt, 4) & X86_CR4_PCIDE) - rsvd &= ~X86_CR3_PCID_NOFLUSH; - } - - if (new_val & rsvd) - return emulate_gp(ctxt, 0); - - break; - } - case 4: { - ctxt->ops->get_msr(ctxt, MSR_EFER, &efer); - - if ((efer & EFER_LMA) && !(new_val & X86_CR4_PAE)) - return emulate_gp(ctxt, 0); - - break; - } - } - return X86EMUL_CONTINUE; } From patchwork Sat Feb 13 01:05:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12086479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1A3AC433E0 for ; Sat, 13 Feb 2021 01:06:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8766064DE3 for ; Sat, 13 Feb 2021 01:06:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232218AbhBMBGU (ORCPT ); Fri, 12 Feb 2021 20:06:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232152AbhBMBGN (ORCPT ); Fri, 12 Feb 2021 20:06:13 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE9FEC061788 for ; Fri, 12 Feb 2021 17:05:32 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id j4so1537466ybt.23 for ; Fri, 12 Feb 2021 17:05:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=7xn8o/ghRMywDnWyKQGCThUSnsromvC8HnD8FrfD33c=; b=NaxGehxC6eKDL5N5xdIbYtGybwPPhOxUcFMlaZSmJKfznEczu8LIRrR0jsRAPhcFMl rueMQU4dp7BNgviiYYDXykntaOwGqotyzVt1qIDToSW3EpJrwvpa+G0aKPZzwOJQJoRO 8j5tsr8Kb8sa82rZ8s2DlAo+QDaI/ysvPtV/zR5mYVGUIYwA19PYdLqwGWxYIE70FxNk ptN2mvq+RVorh/qW8fTW2ZHt5PVnOsKcJrEV4kO/heFpV26wgi4OJ4AJRqS5PboxlMIQ +y44T0Q4UP/bpD8fw4v5jjMAVflpOQ+1A14Qs+KuLuvMSxTXR+a693PGr9LxY/qWyrk5 AAVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=7xn8o/ghRMywDnWyKQGCThUSnsromvC8HnD8FrfD33c=; b=uRoXVVKKwd6+uFWEv3nUnHnwH+hQbTcdh/BptSFNAq55MC2Ek/lk04XahBiz0ZnzAJ wfIGA7RZqwYIasOn3uZg3F0zeaM9sPZuoVp3TU2Ur6LgvoVPQPf768c2gf9FbOpvfWJx zSGR6YbVIXDrV42VNUSNjv1XlivD5H67fp3JKF7d/T9CYKcPrUzKutJExxnvYJtixDba YKGaKMfQjVhFHV7aX0VelcWSBhWcXcahH0nr8YsSmugTEQ36+Trh+GVCCFZA/BWYG3/c PkZcLVb300XLE2UthLvP+HDSKBc1pwj6Uv7iL1rXwrOQ4kxdQdp44z4DCZ2J10M9auQI 9jGQ== X-Gm-Message-State: AOAM530qaSTPr69duNayewEOZEPeup4QvCxFIUJfRN6e8wyr3AgZe+Wt 8hIdEI8xpBec2zDJ6FqBHGxxWAC8mYs= X-Google-Smtp-Source: ABdhPJw9DKV3wwTLHQatJSXRXGRXRz/fqBxe+ClysKcFHqFZMd63KZd0BaAnkNUg8z/cQhoe0q5RysY2az8= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:b407:1780:13d2:b27]) (user=seanjc job=sendgmr) by 2002:a25:4252:: with SMTP id p79mr7545032yba.492.1613178332046; Fri, 12 Feb 2021 17:05:32 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 12 Feb 2021 17:05:11 -0800 In-Reply-To: <20210213010518.1682691-1-seanjc@google.com> Message-Id: <20210213010518.1682691-3-seanjc@google.com> Mime-Version: 1.0 References: <20210213010518.1682691-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 2/9] KVM: x86: Check CR3 GPA for validity regardless of vCPU mode From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Babu Moger , Joao Martins , David Woodhouse Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Check CR3 for an invalid GPA even if the vCPU isn't in long mode. For bigger emulation flows, notably RSM, the vCPU mode may not be accurate if CR0/CR4 are loaded after CR3. For MOV CR3 and similar flows, the caller is responsible for truncating the value. Note, SMRAM.CR3 is read-only, so this is mostly a theoretical bug since KVM will not have stored an illegal CR3 into SMRAM during SMI emulation. Fixes: 660a5d517aaa ("KVM: x86: save/load state on SMM switch") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3fa140383f5d..72fd8d384df7 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1073,10 +1073,15 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) return 0; } - if (is_long_mode(vcpu) && kvm_vcpu_is_illegal_gpa(vcpu, cr3)) + /* + * Do not condition the GPA check on long mode, this helper is used to + * stuff CR3, e.g. for RSM emulation, and there is no guarantee that + * the current vCPU mode is accurate. + */ + if (kvm_vcpu_is_illegal_gpa(vcpu, cr3)) return 1; - else if (is_pae_paging(vcpu) && - !load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3)) + + if (is_pae_paging(vcpu) && !load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3)) return 1; kvm_mmu_new_pgd(vcpu, cr3, skip_tlb_flush, skip_tlb_flush); From patchwork Sat Feb 13 01:05:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12086489 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46F5BC433E0 for ; Sat, 13 Feb 2021 01:07:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DFC5B64DFF for ; Sat, 13 Feb 2021 01:07:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232287AbhBMBG4 (ORCPT ); Fri, 12 Feb 2021 20:06:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229708AbhBMBGv (ORCPT ); Fri, 12 Feb 2021 20:06:51 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CDF3C06178B for ; Fri, 12 Feb 2021 17:05:35 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id u1so1571849ybu.14 for ; Fri, 12 Feb 2021 17:05:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=73lpx2Ds4nvqlzfYC2U6+DFk/lea8weqXjZsX+2GDyw=; b=ZDEE5RwcuHsoiD9G5EqwUruq+RUMompkf0icwCSbTaWazBwSSHjqycoQCAQUig6JLX lHd3cdDCINo6JFi1t5kIOHGkAxPe6n8heWpOf0Ar6QcF8qMXBOL71MwmuetIXFBVFnxn SbiskeSOPJEnaOptYYoSvcU3z3gpCYudseikfY3B4PJKvwcHkoGMrSQGe+K1H1n7qfIB j49CpM/z76XiG1+XIeCmImVT0EiOlpattwYI8+xiYMLDbl7WGItmSNxSTQNUqdXn6OQK GTdd7T1xDhN/qy36dCXlrM92c6D1WIFlGM76b9o0y4UdT5g0bTdQXly9HvLrccpw14n+ EbfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=73lpx2Ds4nvqlzfYC2U6+DFk/lea8weqXjZsX+2GDyw=; b=WBrps1i6OxghbeTY3Wn+0nAD7fNdY4F2sDtUtgMOQ3EyI98FtNzRrnybXPUQlctEKu P0P5U9wWEuVCdLyKp/kLyfZZHaUd7Bpt8alfxEZ6vU4jnjkvQoWcc1F9EUQDRV2GPGmE x6YW2AYuAyUEByufD2e2VrZP3dLDQC5PUou8SrFjpQwg7Ir7Yij5faoSL6hVtCMwWrmR ji1dWCxf/Netvk1bHuFDt13c0JinORYBVcgaB4CIgrdSZ1t/Y95hFdIxSzo0QEHbglhV jK2k8ozN/R0DkLwHNjbIaS09+zqpqwlWNX7ORsGsurogJHbmGKXUFrZE8xK5Sv51KkIE Rjdw== X-Gm-Message-State: AOAM533Jtng0rkosxohLzJNT56yBvx6xa2FagFz+BLv296Uq1TcfKrMb Tq4oucP9pOztCaTgGp2y8ZslZxJPnqc= X-Google-Smtp-Source: ABdhPJx+0Cq+HxRVYT+4ftVIegCIMDnq/iMusdAIcSm4QHRvfpfrkJW7Brk6Ieo52y+3nWHY97ZniguMvIw= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:b407:1780:13d2:b27]) (user=seanjc job=sendgmr) by 2002:a25:da8d:: with SMTP id n135mr7603360ybf.13.1613178334460; Fri, 12 Feb 2021 17:05:34 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 12 Feb 2021 17:05:12 -0800 In-Reply-To: <20210213010518.1682691-1-seanjc@google.com> Message-Id: <20210213010518.1682691-4-seanjc@google.com> Mime-Version: 1.0 References: <20210213010518.1682691-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 3/9] KVM: SVM: Truncate GPR value for DR and CR accesses in !64-bit mode From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Babu Moger , Joao Martins , David Woodhouse Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Drop bits 63:32 on loads/stores to/from DRs and CRs when the vCPU is not in 64-bit mode. The APM states bits 63:32 are dropped for both DRs and CRs: In 64-bit mode, the operand size is fixed at 64 bits without the need for a REX prefix. In non-64-bit mode, the operand size is fixed at 32 bits and the upper 32 bits of the destination are forced to 0. Fixes: 7ff76d58a9dc ("KVM: SVM: enhance MOV CR intercept handler") Fixes: cae3797a4639 ("KVM: SVM: enhance mov DR intercept handler") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 42d4710074a6..d077584d45ec 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2526,7 +2526,7 @@ static int cr_interception(struct vcpu_svm *svm) err = 0; if (cr >= 16) { /* mov to cr */ cr -= 16; - val = kvm_register_read(&svm->vcpu, reg); + val = kvm_register_readl(&svm->vcpu, reg); trace_kvm_cr_write(cr, val); switch (cr) { case 0: @@ -2572,7 +2572,7 @@ static int cr_interception(struct vcpu_svm *svm) kvm_queue_exception(&svm->vcpu, UD_VECTOR); return 1; } - kvm_register_write(&svm->vcpu, reg, val); + kvm_register_writel(&svm->vcpu, reg, val); trace_kvm_cr_read(cr, val); } return kvm_complete_insn_gp(&svm->vcpu, err); @@ -2637,11 +2637,11 @@ static int dr_interception(struct vcpu_svm *svm) dr = svm->vmcb->control.exit_code - SVM_EXIT_READ_DR0; if (dr >= 16) { /* mov to DRn */ dr -= 16; - val = kvm_register_read(&svm->vcpu, reg); + val = kvm_register_readl(&svm->vcpu, reg); err = kvm_set_dr(&svm->vcpu, dr, val); } else { kvm_get_dr(&svm->vcpu, dr, &val); - kvm_register_write(&svm->vcpu, reg, val); + kvm_register_writel(&svm->vcpu, reg, val); } return kvm_complete_insn_gp(&svm->vcpu, err); From patchwork Sat Feb 13 01:05:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12086491 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FB2DC433DB for ; Sat, 13 Feb 2021 01:07:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1567B64E16 for ; Sat, 13 Feb 2021 01:07:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232299AbhBMBHC (ORCPT ); Fri, 12 Feb 2021 20:07:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229796AbhBMBGv (ORCPT ); Fri, 12 Feb 2021 20:06:51 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D25B9C061793 for ; Fri, 12 Feb 2021 17:05:37 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id f81so1591666yba.8 for ; Fri, 12 Feb 2021 17:05:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=K6GpRs9FR8BeiWVjAaubiS/GB9p5ADQHu9rZN6FFHVQ=; b=L5fSLUAHoVIcedkgWCwU3hPyKW4aU3nlVu1zHtinTYWv7ikUhlJ0+JGT7Ek5gD0zxO 26uS1yYQzOCiAQC7l0fELfn+rbjT+muiIraHQc7YLm8x/EkMFqHX822srIEB8B+gAzuH 8wWLa3VskNVfQAEVXmgkN4Ax0dt56CfD0uzKyOuKRU6a34hSYthHuPcBOYKXLMq/Y2Qd DSDkWLWrAeV3eV5EhkAH+n/PUNITw30XJ5V1eeGjHXFvwMmR/oUY4HQIxtgy3BEkQY+l 17hCtpujPDxZhb16gNcqJ7+3mEMSkqgcNSyTpKePvKvF3vXZDB0Bnx4LICRqSho3N1YF P0qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=K6GpRs9FR8BeiWVjAaubiS/GB9p5ADQHu9rZN6FFHVQ=; b=sWrOw9bnf534wi3E+gDKP53o9RwBucwPLJGPrpTeIdzNBm/b7YCTAzGNAN/sk6yC6U GcJjujkZWKAetPgJ3nkhstKjM5NURzs8zccofxAfZZBS6i0vRt50+o0hPbo/eYvdOIBB sQ5OHqBGDTk2lvv1BEXwPRGn/T+FiPCozIHnN5q9WF5tjQ18zgsiTRucKriuL43hLH8L gCiDkRolx9uDyedkl3bXVmh3HfS2tSfJnPONLLL5SEVkTFHFf+wCWsEk/983UUIf69Ib X+XNkrN6hEd3CCFzD0c0mtymSxhfBBJYmOOVlCsbhMf8GQ/E8/cxYMa/oFcZ6wZ+ENak LDKw== X-Gm-Message-State: AOAM530+RfBbwhqprIg2KEWfXg7A068HVqEFNiDokoiMD+j8JGovdOnX 2Jt1f4Z+QfZ5EUNMwKWzx4CZcSlt1Pw= X-Google-Smtp-Source: ABdhPJyqPwzyhV5/NL+RxD+oLqbn8FweVhzS2bV2tQiUSPPujPrp/n+aapmAsQ4H5GF50ExYUBZGWrS7EGs= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:b407:1780:13d2:b27]) (user=seanjc job=sendgmr) by 2002:a25:c943:: with SMTP id z64mr7637015ybf.367.1613178337159; Fri, 12 Feb 2021 17:05:37 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 12 Feb 2021 17:05:13 -0800 In-Reply-To: <20210213010518.1682691-1-seanjc@google.com> Message-Id: <20210213010518.1682691-5-seanjc@google.com> Mime-Version: 1.0 References: <20210213010518.1682691-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 4/9] KVM: VMX: Truncate GPR value for DR and CR reads in !64-bit mode From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Babu Moger , Joao Martins , David Woodhouse Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Drop bits 63:32 when storing a DR/CR to a GPR when the vCPU is not in 64-bit mode. Per the SDM: The operand size for these instructions is always 32 bits in non-64-bit modes, regardless of the operand-size attribute. CR8 technically isn't affected as CR8 isn't accessible outside of 64-bit mode, but fix it up for consistency and to allow for future cleanup. Fixes: 6aa8b732ca01 ("[PATCH] kvm: userspace interface") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index e0a3a9be654b..115826a020ff 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5067,12 +5067,12 @@ static int handle_cr(struct kvm_vcpu *vcpu) case 3: WARN_ON_ONCE(enable_unrestricted_guest); val = kvm_read_cr3(vcpu); - kvm_register_write(vcpu, reg, val); + kvm_register_writel(vcpu, reg, val); trace_kvm_cr_read(cr, val); return kvm_skip_emulated_instruction(vcpu); case 8: val = kvm_get_cr8(vcpu); - kvm_register_write(vcpu, reg, val); + kvm_register_writel(vcpu, reg, val); trace_kvm_cr_read(cr, val); return kvm_skip_emulated_instruction(vcpu); } @@ -5145,7 +5145,7 @@ static int handle_dr(struct kvm_vcpu *vcpu) unsigned long val; kvm_get_dr(vcpu, dr, &val); - kvm_register_write(vcpu, reg, val); + kvm_register_writel(vcpu, reg, val); err = 0; } else { err = kvm_set_dr(vcpu, dr, kvm_register_readl(vcpu, reg)); From patchwork Sat Feb 13 01:05:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12086495 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A49D3C433E9 for ; Sat, 13 Feb 2021 01:07:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67AF964E2A for ; Sat, 13 Feb 2021 01:07:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232313AbhBMBHG (ORCPT ); Fri, 12 Feb 2021 20:07:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232065AbhBMBGv (ORCPT ); Fri, 12 Feb 2021 20:06:51 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C13FC0617A7 for ; Fri, 12 Feb 2021 17:05:40 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 203so1616913ybz.2 for ; Fri, 12 Feb 2021 17:05:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=TBi9mzif932CxFGCWRDrn7WGDuvfCWuy0X2/DzVvU4g=; b=eAAy3T6Mg9MgvMRoSl1leu1/x7dc/YzSirva7kjTTqYDj3Z/JWsTk3rDtvr8fM0Ynx IneM1faKW1NfM4jLdO98lI+F1pZx4N/af028aMALOaJ6bXay+7Ig0rp+cujiJ+YdOvps UBKOb/miIzmhvD5if77dpaacD8dZfceUuRTnmYR2mXZGhPFH8VGjJ38idFteAPlX/Jd7 2+1egmV5AcuhLwwVmRJj1NR8dICdnsfiglCXyVdKUDEgN/dNOIWNnQilRSN/jGZwUkya X7oAtOM86mbPt0K8UKmM6FkGzbTKkYDC2QUdkIyaXgmu3d3cthyTMUhjK6Byw9X3cgSW eJxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=TBi9mzif932CxFGCWRDrn7WGDuvfCWuy0X2/DzVvU4g=; b=d5Bvn3ENRwVgpzL8Xzct3aGDv7Mv/48y8EkWwyNv+bHmjP9bzHHy21WyUtXd3NN9G0 D7e+CxZ4GyCvacZmY2bpdNDlNxSozfxwjQ8k31/EWDJsVukajg1T3cB+pOtXFiJbbPO3 HzXkeJh1PYsbLqsS3jAmmKwOn822tmrnAjdfIlomJAsm2vu0w6jwmNdeyH6AHOhgF6MX MlYGMgpE3GTnEE88gPRiCDToqim4LdSkK6I/tRSCOBxX/licqUWcEFhRtUn3KeT073L2 uV86VauPTTJRayjaQiUhTzXjpj+73CBADzp3AP6Y8PigExgDNBdxTuPPZUNg9R5+ito9 8bow== X-Gm-Message-State: AOAM531J8TcJoqczaMR9HzXTMDoUJrfePedMeSp+1mck/2uYG/zga1TS pZ2QAw+CiUq1Ebfh0Rs2YGKtUrjShiI= X-Google-Smtp-Source: ABdhPJwJ397Wb5KM3/64tZ40OxBWn1gDdaF1KvvfyK2w6iee5rf3z8RE1K3mgwbyc0Ifiwv6u/oV9Na9y78= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:b407:1780:13d2:b27]) (user=seanjc job=sendgmr) by 2002:a25:c401:: with SMTP id u1mr7304123ybf.340.1613178339470; Fri, 12 Feb 2021 17:05:39 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 12 Feb 2021 17:05:14 -0800 In-Reply-To: <20210213010518.1682691-1-seanjc@google.com> Message-Id: <20210213010518.1682691-6-seanjc@google.com> Mime-Version: 1.0 References: <20210213010518.1682691-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 5/9] KVM: nVMX: Truncate bits 63:32 of VMCS field on nested check in !64-bit From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Babu Moger , Joao Martins , David Woodhouse Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Drop bits 63:32 of the VMCS field encoding when checking for a nested VM-Exit on VMREAD/VMWRITE in !64-bit mode. VMREAD and VMWRITE always use 32-bit operands outside of 64-bit mode. The actual emulation of VMREAD/VMWRITE does the right thing, this bug is purely limited to incorrectly causing a nested VM-Exit if a GPR happens to have bits 63:32 set outside of 64-bit mode. Fixes: a7cde481b6e8 ("KVM: nVMX: Do not forward VMREAD/VMWRITE VMExits to L1 if required so by vmcs12 vmread/vmwrite bitmaps") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index b2f0b5e9cd63..d6c892ea551c 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -5717,7 +5717,7 @@ static bool nested_vmx_exit_handled_vmcs_access(struct kvm_vcpu *vcpu, /* Decode instruction info and find the field to access */ vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); - field = kvm_register_read(vcpu, (((vmx_instruction_info) >> 28) & 0xf)); + field = kvm_register_readl(vcpu, (((vmx_instruction_info) >> 28) & 0xf)); /* Out-of-range fields always cause a VM exit from L2 to L1 */ if (field >> 15) From patchwork Sat Feb 13 01:05:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12086493 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4E6AC43381 for ; Sat, 13 Feb 2021 01:07:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8744864DFF for ; Sat, 13 Feb 2021 01:07:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232338AbhBMBHI (ORCPT ); Fri, 12 Feb 2021 20:07:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232242AbhBMBGv (ORCPT ); Fri, 12 Feb 2021 20:06:51 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FC09C0617A9 for ; Fri, 12 Feb 2021 17:05:42 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 11so1566414ybl.21 for ; Fri, 12 Feb 2021 17:05:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=3xHEuJTQ8VLRaUFklswJjFu0PeXqCwd63ebUwadXbKc=; b=EVeU7iVBUs5OZCWOqhc8sKWFTxPAeC9DRuEOUGY1jV014ehcyPoLiTq8xzzfMtNFoA NATJifNRk4owfCjJHNWGHFygbK6Idcga74AzDNDVwyfiQp2B7Wu6BIZArhBUCeO9D4ct RDb0IopIymEdhJeUnEE8X5PlUVBwa7aQJwjzgGkgj5VwsDPQG9MXmlHkMnkqa+V54eP/ tUiVrPGiplFWiUYkFfvzMYG4kwsu6EIMqsQxU6xnoPIB6cg0ATlnpOfO+8WfeMfFr5bG ukNfDDv2zScXa+qnp2IiyTJK7DIZqYTInPyfsyIxqNxYYO4d+BP9LAnbC99DON6cOVGO ETxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=3xHEuJTQ8VLRaUFklswJjFu0PeXqCwd63ebUwadXbKc=; b=j2O0mJkFV9lg2sO924raNKwe8QX3dBULfRrm6KOaSgvZdz0ad1wuaqGckOcwSut6wR hGBe5xvarkXmhqaBr3oxqAMoqz5K1uaAsfB8XPQu3NfMOL9YpbEshZeKL3yxN8O568yp mEVmy1qsCKq4AjMRZFpR3EyReYxHuBTFUcsnT4yS0b2bWObG3uIWx+csAkIr535+4hGd 9TkKpGE2mTyxKjssd1skmIIKe4APyTg8mqiOf7vU9I2QDNjNClEpA0cUKsGtTwrXpMWL Nz62UrpM+ErPqX+t9ihk6m0QTEJ/VRX/IL9jivaSHpKxxAEwmFBM23BRW6yb/QoNAA+s xrRw== X-Gm-Message-State: AOAM531yTcnXNSYBiDHc3b1PjCGWe0S90K6IgJyA82bJgnWYifx/gDKT uK7vKrCAH0O/uVanb8LFC0knWMrh13g= X-Google-Smtp-Source: ABdhPJyy5TPJAO2Y7pIDCH20WbQR26WzIdg1RrpGoRQoBMnvsrTMuS9QUQNA7Uk6QdtC8C7Ja8FoF87zq4s= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:b407:1780:13d2:b27]) (user=seanjc job=sendgmr) by 2002:a05:6902:6af:: with SMTP id j15mr8196259ybt.229.1613178341828; Fri, 12 Feb 2021 17:05:41 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 12 Feb 2021 17:05:15 -0800 In-Reply-To: <20210213010518.1682691-1-seanjc@google.com> Message-Id: <20210213010518.1682691-7-seanjc@google.com> Mime-Version: 1.0 References: <20210213010518.1682691-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 6/9] KVM: nVMX: Truncate base/index GPR value on address calc in !64-bit From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Babu Moger , Joao Martins , David Woodhouse Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Drop bits 63:32 of the base and/or index GPRs when calculating the effective address of a VMX instruction memory operand. Outside of 64-bit mode, memory encodings are strictly limited to E*X and below. Fixes: 064aea774768 ("KVM: nVMX: Decoding memory operands of VMX instructions") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index d6c892ea551c..a02d8744ca66 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -4601,9 +4601,9 @@ int get_vmx_mem_address(struct kvm_vcpu *vcpu, unsigned long exit_qualification, else if (addr_size == 0) off = (gva_t)sign_extend64(off, 15); if (base_is_valid) - off += kvm_register_read(vcpu, base_reg); + off += kvm_register_readl(vcpu, base_reg); if (index_is_valid) - off += kvm_register_read(vcpu, index_reg) << scaling; + off += kvm_register_readl(vcpu, index_reg) << scaling; vmx_get_segment(vcpu, &s, seg_reg); /* From patchwork Sat Feb 13 01:05:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12086497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E39C4C433E6 for ; Sat, 13 Feb 2021 01:07:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 97B4F64E05 for ; Sat, 13 Feb 2021 01:07:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232391AbhBMBHT (ORCPT ); Fri, 12 Feb 2021 20:07:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232318AbhBMBHH (ORCPT ); Fri, 12 Feb 2021 20:07:07 -0500 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C88D3C061356 for ; Fri, 12 Feb 2021 17:05:44 -0800 (PST) Received: by mail-qk1-x74a.google.com with SMTP id n62so1022534qkn.7 for ; Fri, 12 Feb 2021 17:05:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=P+psZ8urjSB19xd68DRcw5VIbpFuXXaxHhSRR+LYyzM=; b=k6qkmAvojRBdZtQiL1P3/gZ3Ohf8rmwo3kI3u0nfcqM5xXx6p631Ajcjl7zcdiSRHw rSrO6ebqY02dZji0IdXk3bfJ5KOGfMWTqIEHeOxX/52Zirlye6uHVDxtE9b/IDBHvRMg em81wXDx2Jhw8H9RLPrAkYG/HGeB5hKozyuYvnjJPqLUrKf1n9QWMuJSFLigZ3fOum4j 2/ObS62FRkWpAfG/DsdH1nX+jFmy9f4dP1o81l/TVYOlbhERATidBSkyhF5QDQtg1pCE OKGBlkJBVpi6IWvji/drU8AyH4AyrGrPJRERqG/70KuSCMqWJXjR3VG/8KB+shu6U8F0 0eGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=P+psZ8urjSB19xd68DRcw5VIbpFuXXaxHhSRR+LYyzM=; b=AzQuBhNFZYRBshIQvNqdQdnl6fuPlDFIY/AlynMGC6As9kfidf12mXOfRmGTwutO1f ZaeXuIn2+n+2BVT2Yz1ij7KJXwEA81kfb1dbN/ugG/G9t56iVAh4meomoEkxdStE7Slf QMB9zoi3t24EvOzYHtYetUEAMYmi7FeYO+O/sRdnBm9tMn24J87CHJ22B0F+CYxDyeNZ ep0mQ72XMaafwpfk1yo1Tq7r8LHh1iuGwJjJ34KdRmm08umgmuFjH1w/Pc1MicqLjsl0 ahHbCoO2K3u0HpduyXtuYwBQITJU4bI8v6751u4iqZKZmn25Ln7mh4DZNq+w6000AfB0 OOTA== X-Gm-Message-State: AOAM530mjJNfVT0w31DzO+H/jAbyyedYoBS8E1NVOK6R5IafKjF2gIuI w5BMHqMGPNq0B2c6es3rGeCYjzH1zsY= X-Google-Smtp-Source: ABdhPJy0LFozKYfLKCDmm992FOaE4QAa6HOq5vsXSWWjOS4e2eIfXgPp1+BlwSSEBaBZnvdBtmc0SFrpE7w= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:b407:1780:13d2:b27]) (user=seanjc job=sendgmr) by 2002:a05:6214:94a:: with SMTP id dn10mr5178605qvb.28.1613178343985; Fri, 12 Feb 2021 17:05:43 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 12 Feb 2021 17:05:16 -0800 In-Reply-To: <20210213010518.1682691-1-seanjc@google.com> Message-Id: <20210213010518.1682691-8-seanjc@google.com> Mime-Version: 1.0 References: <20210213010518.1682691-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 7/9] KVM: x86/xen: Drop RAX[63:32] when processing hypercall From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Babu Moger , Joao Martins , David Woodhouse Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Truncate RAX to 32 bits, i.e. consume EAX, when retrieving the hypecall index for a Xen hypercall. Per Xen documentation[*], the index is EAX when the vCPU is not in 64-bit mode. [*] http://xenbits.xenproject.org/docs/sphinx-unstable/guest-guide/x86/hypercall-abi.html Fixes: 23200b7a30de ("KVM: x86/xen: intercept xen hypercalls if enabled") Cc: Joao Martins Cc: David Woodhouse Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/kvm/xen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index af8f6562fce4..5bfed72edd07 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -383,7 +383,7 @@ int kvm_xen_hypercall(struct kvm_vcpu *vcpu) bool longmode; u64 input, params[6]; - input = (u64)kvm_register_read(vcpu, VCPU_REGS_RAX); + input = (u64)kvm_register_readl(vcpu, VCPU_REGS_RAX); /* Hyper-V hypercalls get bit 31 set in EAX */ if ((input & 0x80000000) && From patchwork Sat Feb 13 01:05:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12086499 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 379D2C433E6 for ; Sat, 13 Feb 2021 01:08:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 056AE64E05 for ; Sat, 13 Feb 2021 01:08:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231317AbhBMBIA (ORCPT ); Fri, 12 Feb 2021 20:08:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232415AbhBMBHc (ORCPT ); Fri, 12 Feb 2021 20:07:32 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C52B6C06121C for ; Fri, 12 Feb 2021 17:05:46 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id u3so1577509ybj.13 for ; Fri, 12 Feb 2021 17:05:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=4l7lJ89dUN/mDifctyjmka3i9z9nrBYEG0xhjmdSUUo=; b=YuUYSqFaQ2X/0AytqcSo2UGtMt7JtxTw3r9Xzk7NzwzyffwnESubnEoE7LsExZarvt 8+srTOrLYWx8VNCnh+NMkLm8HBBYc1aW8jDYfjBjnNkbW2s58daTr3p+gHwV0OxNV4Sy hdMM2vEhrY+wf282MZxoJGM4ELVodFjb7XGiRYxSVFYFPhMv9IfdS1QpJBg37RLjdTaS Buc7LUfI+pockTKv0tdUNTVMnQEvhEy6Y6evVbg5LUTcpDwaFrNuNyICJdyXI3KOy5Dz HFreFKXVzbUi+HaSHgAEDNC4ycPviQrRrczVyEzojLuex32wF3Q5yVCFbp69zythHxiO pEhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=4l7lJ89dUN/mDifctyjmka3i9z9nrBYEG0xhjmdSUUo=; b=Y0cD6PO/b2Fl7Aj2VIDszzxufE1EEB3LlPCD7eBZc8ern4uqn8oy939AYD4rkc8ZEp 2dhrRHjJMBomz8bQucuriG6LEk1x8T49lHmmWMtPixStTkiUfWLZVWlin1CTxN66Jvip Bz9QG5DLr/OdnbQ6FMwZ8wqu6iGmBjoHBUyUPVzp/Jvac95TXUlDPgBMAQsTwqLqHTkq NM6FBu106ucypL0pZqPoV5LmAItGmyD/QYAC7RknEA0Pi3ZcuKDzJfVUSYl24c/h5CBZ 0OFnEbICM/j36xVcUSH4uvYqQP8K8PeyH2jKI6LYPwf2dLhgCO14TFpov9Mx6mASz8j/ SY5Q== X-Gm-Message-State: AOAM532E0yxYmIvpnlpC0b2DETggrT5N37Ul9OCzHTUrvjXW5AMgqzs6 XgIzY8tky47Gk/pFUMtf/FkWqFxy/W4= X-Google-Smtp-Source: ABdhPJwRv7XF/pVWzpewg9HbbCCXg2ivDZcIqXVajCZywXnqWbM7K4Of/uyX2s/OJKRsluXzj0diKX6QMO0= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:b407:1780:13d2:b27]) (user=seanjc job=sendgmr) by 2002:a25:b904:: with SMTP id x4mr7134861ybj.189.1613178346051; Fri, 12 Feb 2021 17:05:46 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 12 Feb 2021 17:05:17 -0800 In-Reply-To: <20210213010518.1682691-1-seanjc@google.com> Message-Id: <20210213010518.1682691-9-seanjc@google.com> Mime-Version: 1.0 References: <20210213010518.1682691-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 8/9] KVM: SVM: Use default rAX size for INVLPGA emulation From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Babu Moger , Joao Martins , David Woodhouse Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Drop bits 63:32 of RAX when grabbing the address for INVLPGA emulation outside of 64-bit mode to make KVM's emulation slightly less wrong. The address for INVLPGA is determined by the effective address size, i.e. it's not hardcoded to 64/32 bits for a given mode. Add a FIXME to call out that the emulation is wrong. Opportunistically tweak the ASID handling to make it clear that it's defined by ECX, not rCX. Per the APM: The portion of rAX used to form the address is determined by the effective address size (current execution mode and optional address size prefix). The ASID is taken from ECX. Fixes: ff092385e828 ("KVM: SVM: Implement INVLPGA") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index d077584d45ec..4dc64ebaa756 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2327,12 +2327,17 @@ static int clgi_interception(struct vcpu_svm *svm) static int invlpga_interception(struct vcpu_svm *svm) { struct kvm_vcpu *vcpu = &svm->vcpu; + gva_t gva = kvm_rax_read(vcpu); + u32 asid = kvm_rcx_read(vcpu); - trace_kvm_invlpga(svm->vmcb->save.rip, kvm_rcx_read(&svm->vcpu), - kvm_rax_read(&svm->vcpu)); + /* FIXME: Handle an address size prefix. */ + if (!is_long_mode(vcpu)) + gva = (u32)gva; + + trace_kvm_invlpga(svm->vmcb->save.rip, asid, gva); /* Let's treat INVLPGA the same as INVLPG (can be optimized!) */ - kvm_mmu_invlpg(vcpu, kvm_rax_read(&svm->vcpu)); + kvm_mmu_invlpg(vcpu, gva); return kvm_skip_emulated_instruction(&svm->vcpu); } From patchwork Sat Feb 13 01:05:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12086501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D94A7C433E6 for ; Sat, 13 Feb 2021 01:08:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E2B364DF2 for ; Sat, 13 Feb 2021 01:08:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232498AbhBMBIH (ORCPT ); Fri, 12 Feb 2021 20:08:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232425AbhBMBHd (ORCPT ); Fri, 12 Feb 2021 20:07:33 -0500 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B2CCC06121E for ; Fri, 12 Feb 2021 17:05:49 -0800 (PST) Received: by mail-qv1-xf49.google.com with SMTP id n1so894626qvi.4 for ; Fri, 12 Feb 2021 17:05:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=GxRBYEs4CWruEYRrtfSKHL2sbkupVmuIYWg19YRJTeE=; b=tAORAmccBwtfDWDhkawqa8cU8ojcedEsrhUixpTf5QdFmHVDSKBZyAeNrFo9/ztSlK 6lXXruk94Ka9i7EBZXRDZ3R3MH/PPzra+CEyyq5rpqxD9TVIfGVZK1nfXpTJkmCtr/X2 5JT1y4gSq6EjbERzpgy+kqs4qy2iLDG5GH3hCywBVKmWAMI6nxb6SC4ovu1wOrvtloMg APQxY7wUuIc9yaBgbsZjX3Dz0yxcECv3RSAXNnaV5l8vl+fDw/lU22HpNuK4Z1YSSRcf XZbpB+Fdm3go9bnDeQnxuhCcIotQ+rW4gxZZfzUWCVzXbvFduMrtiFR/bYjp1/NpiBLW QBbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=GxRBYEs4CWruEYRrtfSKHL2sbkupVmuIYWg19YRJTeE=; b=UYS9J/SQVBfAEbJUvnLEKeZaC87k6revYiGtQ0DeTIa/OPa2ORISYTTjo2/dv/0kXV giLStaRf/ehG7UxpT7MCilgfOdAsEgfhaqzSgILqBPstdKZx/ulJnRSDeIxt6eH70m3b R3VwgmqvKq3jG3++mCSM6l9OuDfnz80KzKbLzqHQmLSWWXJGQrZWPsCqjTiVKYu0nF1C L2L9we2wF7VpoIVEqjzVZmSTUtSAVWZN1HuV3J+/o9zSC/KlEk2VsBga0UwB0iL2GUxM 9w5mhL19U2X8gJInvsp4+HNMYPnTpjlOG1t6ATT85RTq8QEcDWIL4blKZKTaDu92os4u ddbA== X-Gm-Message-State: AOAM532o0SIfXBOIXvQpRkzLDgWwgCjgvbtnWe3I515/uGTGbclKog9d v1fl+OLaZx1AAtOKbJGYW+HnnEGrE/o= X-Google-Smtp-Source: ABdhPJyKLwZoEBRJ36RbXivN6C+aGywSGAgjsVtG0ymGdiyD/xd5LCqkYdu/GmD11UBmFe3spDJkjVoEOxk= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:b407:1780:13d2:b27]) (user=seanjc job=sendgmr) by 2002:a0c:e38c:: with SMTP id a12mr5121096qvl.38.1613178348349; Fri, 12 Feb 2021 17:05:48 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 12 Feb 2021 17:05:18 -0800 In-Reply-To: <20210213010518.1682691-1-seanjc@google.com> Message-Id: <20210213010518.1682691-10-seanjc@google.com> Mime-Version: 1.0 References: <20210213010518.1682691-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH 9/9] KVM: x86: Rename GPR accessors to make mode-aware variants the defaults From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Babu Moger , Joao Martins , David Woodhouse Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Append raw to the direct variants of kvm_register_read/write(), and drop the "l" from the mode-aware variants. I.e. make the mode-aware variants the default, and make the direct variants scary sounding so as to discourage use. Accessing the full 64-bit values irrespective of mode is rarely the desired behavior. Signed-off-by: Sean Christopherson --- arch/x86/kvm/kvm_cache_regs.h | 19 ++++++++++++------- arch/x86/kvm/svm/svm.c | 8 ++++---- arch/x86/kvm/vmx/nested.c | 20 ++++++++++---------- arch/x86/kvm/vmx/vmx.c | 12 ++++++------ arch/x86/kvm/x86.c | 8 ++++---- arch/x86/kvm/x86.h | 8 ++++---- arch/x86/kvm/xen.c | 2 +- 7 files changed, 41 insertions(+), 36 deletions(-) diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm/kvm_cache_regs.h index 2e11da2f5621..3db5c42c9ecd 100644 --- a/arch/x86/kvm/kvm_cache_regs.h +++ b/arch/x86/kvm/kvm_cache_regs.h @@ -62,7 +62,12 @@ static inline void kvm_register_mark_dirty(struct kvm_vcpu *vcpu, __set_bit(reg, (unsigned long *)&vcpu->arch.regs_dirty); } -static inline unsigned long kvm_register_read(struct kvm_vcpu *vcpu, int reg) +/* + * The "raw" register helpers are only for cases where the full 64 bits of a + * register are read/written irrespective of current vCPU mode. In other words, + * odds are good you shouldn't be using the raw variants. + */ +static inline unsigned long kvm_register_read_raw(struct kvm_vcpu *vcpu, int reg) { if (WARN_ON_ONCE((unsigned int)reg >= NR_VCPU_REGS)) return 0; @@ -73,8 +78,8 @@ static inline unsigned long kvm_register_read(struct kvm_vcpu *vcpu, int reg) return vcpu->arch.regs[reg]; } -static inline void kvm_register_write(struct kvm_vcpu *vcpu, int reg, - unsigned long val) +static inline void kvm_register_write_raw(struct kvm_vcpu *vcpu, int reg, + unsigned long val) { if (WARN_ON_ONCE((unsigned int)reg >= NR_VCPU_REGS)) return; @@ -85,22 +90,22 @@ static inline void kvm_register_write(struct kvm_vcpu *vcpu, int reg, static inline unsigned long kvm_rip_read(struct kvm_vcpu *vcpu) { - return kvm_register_read(vcpu, VCPU_REGS_RIP); + return kvm_register_read_raw(vcpu, VCPU_REGS_RIP); } static inline void kvm_rip_write(struct kvm_vcpu *vcpu, unsigned long val) { - kvm_register_write(vcpu, VCPU_REGS_RIP, val); + kvm_register_write_raw(vcpu, VCPU_REGS_RIP, val); } static inline unsigned long kvm_rsp_read(struct kvm_vcpu *vcpu) { - return kvm_register_read(vcpu, VCPU_REGS_RSP); + return kvm_register_read_raw(vcpu, VCPU_REGS_RSP); } static inline void kvm_rsp_write(struct kvm_vcpu *vcpu, unsigned long val) { - kvm_register_write(vcpu, VCPU_REGS_RSP, val); + kvm_register_write_raw(vcpu, VCPU_REGS_RSP, val); } static inline u64 kvm_pdptr_read(struct kvm_vcpu *vcpu, int index) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 4dc64ebaa756..55afe41b4102 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2531,7 +2531,7 @@ static int cr_interception(struct vcpu_svm *svm) err = 0; if (cr >= 16) { /* mov to cr */ cr -= 16; - val = kvm_register_readl(&svm->vcpu, reg); + val = kvm_register_read(&svm->vcpu, reg); trace_kvm_cr_write(cr, val); switch (cr) { case 0: @@ -2577,7 +2577,7 @@ static int cr_interception(struct vcpu_svm *svm) kvm_queue_exception(&svm->vcpu, UD_VECTOR); return 1; } - kvm_register_writel(&svm->vcpu, reg, val); + kvm_register_write(&svm->vcpu, reg, val); trace_kvm_cr_read(cr, val); } return kvm_complete_insn_gp(&svm->vcpu, err); @@ -2642,11 +2642,11 @@ static int dr_interception(struct vcpu_svm *svm) dr = svm->vmcb->control.exit_code - SVM_EXIT_READ_DR0; if (dr >= 16) { /* mov to DRn */ dr -= 16; - val = kvm_register_readl(&svm->vcpu, reg); + val = kvm_register_read(&svm->vcpu, reg); err = kvm_set_dr(&svm->vcpu, dr, val); } else { kvm_get_dr(&svm->vcpu, dr, &val); - kvm_register_writel(&svm->vcpu, reg, val); + kvm_register_write(&svm->vcpu, reg, val); } return kvm_complete_insn_gp(&svm->vcpu, err); diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index a02d8744ca66..358747586037 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -4601,9 +4601,9 @@ int get_vmx_mem_address(struct kvm_vcpu *vcpu, unsigned long exit_qualification, else if (addr_size == 0) off = (gva_t)sign_extend64(off, 15); if (base_is_valid) - off += kvm_register_readl(vcpu, base_reg); + off += kvm_register_read(vcpu, base_reg); if (index_is_valid) - off += kvm_register_readl(vcpu, index_reg) << scaling; + off += kvm_register_read(vcpu, index_reg) << scaling; vmx_get_segment(vcpu, &s, seg_reg); /* @@ -5005,7 +5005,7 @@ static int handle_vmread(struct kvm_vcpu *vcpu) return nested_vmx_failInvalid(vcpu); /* Decode instruction info and find the field to read */ - field = kvm_register_readl(vcpu, (((instr_info) >> 28) & 0xf)); + field = kvm_register_read(vcpu, (((instr_info) >> 28) & 0xf)); offset = vmcs_field_to_offset(field); if (offset < 0) @@ -5023,7 +5023,7 @@ static int handle_vmread(struct kvm_vcpu *vcpu) * on the guest's mode (32 or 64 bit), not on the given field's length. */ if (instr_info & BIT(10)) { - kvm_register_writel(vcpu, (((instr_info) >> 3) & 0xf), value); + kvm_register_write(vcpu, (((instr_info) >> 3) & 0xf), value); } else { len = is_64_bit_mode(vcpu) ? 8 : 4; if (get_vmx_mem_address(vcpu, exit_qualification, @@ -5097,7 +5097,7 @@ static int handle_vmwrite(struct kvm_vcpu *vcpu) return nested_vmx_failInvalid(vcpu); if (instr_info & BIT(10)) - value = kvm_register_readl(vcpu, (((instr_info) >> 3) & 0xf)); + value = kvm_register_read(vcpu, (((instr_info) >> 3) & 0xf)); else { len = is_64_bit_mode(vcpu) ? 8 : 4; if (get_vmx_mem_address(vcpu, exit_qualification, @@ -5108,7 +5108,7 @@ static int handle_vmwrite(struct kvm_vcpu *vcpu) return kvm_handle_memory_failure(vcpu, r, &e); } - field = kvm_register_readl(vcpu, (((instr_info) >> 28) & 0xf)); + field = kvm_register_read(vcpu, (((instr_info) >> 28) & 0xf)); offset = vmcs_field_to_offset(field); if (offset < 0) @@ -5305,7 +5305,7 @@ static int handle_invept(struct kvm_vcpu *vcpu) return 1; vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); - type = kvm_register_readl(vcpu, (vmx_instruction_info >> 28) & 0xf); + type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf); types = (vmx->nested.msrs.ept_caps >> VMX_EPT_EXTENT_SHIFT) & 6; @@ -5385,7 +5385,7 @@ static int handle_invvpid(struct kvm_vcpu *vcpu) return 1; vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); - type = kvm_register_readl(vcpu, (vmx_instruction_info >> 28) & 0xf); + type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf); types = (vmx->nested.msrs.vpid_caps & VMX_VPID_EXTENT_SUPPORTED_MASK) >> 8; @@ -5646,7 +5646,7 @@ static bool nested_vmx_exit_handled_cr(struct kvm_vcpu *vcpu, switch ((exit_qualification >> 4) & 3) { case 0: /* mov to cr */ reg = (exit_qualification >> 8) & 15; - val = kvm_register_readl(vcpu, reg); + val = kvm_register_read(vcpu, reg); switch (cr) { case 0: if (vmcs12->cr0_guest_host_mask & @@ -5717,7 +5717,7 @@ static bool nested_vmx_exit_handled_vmcs_access(struct kvm_vcpu *vcpu, /* Decode instruction info and find the field to access */ vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); - field = kvm_register_readl(vcpu, (((vmx_instruction_info) >> 28) & 0xf)); + field = kvm_register_read(vcpu, (((vmx_instruction_info) >> 28) & 0xf)); /* Out-of-range fields always cause a VM exit from L2 to L1 */ if (field >> 15) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 115826a020ff..03cc2b236d9a 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5025,7 +5025,7 @@ static int handle_cr(struct kvm_vcpu *vcpu) reg = (exit_qualification >> 8) & 15; switch ((exit_qualification >> 4) & 3) { case 0: /* mov to cr */ - val = kvm_register_readl(vcpu, reg); + val = kvm_register_read(vcpu, reg); trace_kvm_cr_write(cr, val); switch (cr) { case 0: @@ -5067,12 +5067,12 @@ static int handle_cr(struct kvm_vcpu *vcpu) case 3: WARN_ON_ONCE(enable_unrestricted_guest); val = kvm_read_cr3(vcpu); - kvm_register_writel(vcpu, reg, val); + kvm_register_write(vcpu, reg, val); trace_kvm_cr_read(cr, val); return kvm_skip_emulated_instruction(vcpu); case 8: val = kvm_get_cr8(vcpu); - kvm_register_writel(vcpu, reg, val); + kvm_register_write(vcpu, reg, val); trace_kvm_cr_read(cr, val); return kvm_skip_emulated_instruction(vcpu); } @@ -5145,10 +5145,10 @@ static int handle_dr(struct kvm_vcpu *vcpu) unsigned long val; kvm_get_dr(vcpu, dr, &val); - kvm_register_writel(vcpu, reg, val); + kvm_register_write(vcpu, reg, val); err = 0; } else { - err = kvm_set_dr(vcpu, dr, kvm_register_readl(vcpu, reg)); + err = kvm_set_dr(vcpu, dr, kvm_register_read(vcpu, reg)); } out: @@ -5565,7 +5565,7 @@ static int handle_invpcid(struct kvm_vcpu *vcpu) } vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); - type = kvm_register_readl(vcpu, (vmx_instruction_info >> 28) & 0xf); + type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf); if (type > 3) { kvm_inject_gp(vcpu, 0); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 72fd8d384df7..37ad41a63a33 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6873,12 +6873,12 @@ static bool emulator_guest_has_fxsr(struct x86_emulate_ctxt *ctxt) static ulong emulator_read_gpr(struct x86_emulate_ctxt *ctxt, unsigned reg) { - return kvm_register_read(emul_to_vcpu(ctxt), reg); + return kvm_register_read_raw(emul_to_vcpu(ctxt), reg); } static void emulator_write_gpr(struct x86_emulate_ctxt *ctxt, unsigned reg, ulong val) { - kvm_register_write(emul_to_vcpu(ctxt), reg, val); + kvm_register_write_raw(emul_to_vcpu(ctxt), reg, val); } static void emulator_set_nmi_mask(struct x86_emulate_ctxt *ctxt, bool masked) @@ -8524,7 +8524,7 @@ static void enter_smm_save_state_32(struct kvm_vcpu *vcpu, char *buf) put_smstate(u32, buf, 0x7ff0, kvm_rip_read(vcpu)); for (i = 0; i < 8; i++) - put_smstate(u32, buf, 0x7fd0 + i * 4, kvm_register_read(vcpu, i)); + put_smstate(u32, buf, 0x7fd0 + i * 4, kvm_register_read_raw(vcpu, i)); kvm_get_dr(vcpu, 6, &val); put_smstate(u32, buf, 0x7fcc, (u32)val); @@ -8570,7 +8570,7 @@ static void enter_smm_save_state_64(struct kvm_vcpu *vcpu, char *buf) int i; for (i = 0; i < 16; i++) - put_smstate(u64, buf, 0x7ff8 - i * 8, kvm_register_read(vcpu, i)); + put_smstate(u64, buf, 0x7ff8 - i * 8, kvm_register_read_raw(vcpu, i)); put_smstate(u64, buf, 0x7f78, kvm_rip_read(vcpu)); put_smstate(u32, buf, 0x7f70, kvm_get_rflags(vcpu)); diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 39eb04887141..ddf47a59054d 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -222,19 +222,19 @@ static inline bool vcpu_match_mmio_gpa(struct kvm_vcpu *vcpu, gpa_t gpa) return false; } -static inline unsigned long kvm_register_readl(struct kvm_vcpu *vcpu, int reg) +static inline unsigned long kvm_register_read(struct kvm_vcpu *vcpu, int reg) { - unsigned long val = kvm_register_read(vcpu, reg); + unsigned long val = kvm_register_read_raw(vcpu, reg); return is_64_bit_mode(vcpu) ? val : (u32)val; } -static inline void kvm_register_writel(struct kvm_vcpu *vcpu, +static inline void kvm_register_write(struct kvm_vcpu *vcpu, int reg, unsigned long val) { if (!is_64_bit_mode(vcpu)) val = (u32)val; - return kvm_register_write(vcpu, reg, val); + return kvm_register_write_raw(vcpu, reg, val); } static inline bool kvm_check_has_quirk(struct kvm *kvm, u64 quirk) diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 5bfed72edd07..af8f6562fce4 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -383,7 +383,7 @@ int kvm_xen_hypercall(struct kvm_vcpu *vcpu) bool longmode; u64 input, params[6]; - input = (u64)kvm_register_readl(vcpu, VCPU_REGS_RAX); + input = (u64)kvm_register_read(vcpu, VCPU_REGS_RAX); /* Hyper-V hypercalls get bit 31 set in EAX */ if ((input & 0x80000000) &&