From patchwork Thu Oct 26 07:13:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 10027525 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5DC4D60375 for ; Thu, 26 Oct 2017 07:13:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D9C128CCD for ; Thu, 26 Oct 2017 07:13:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 426AB28D42; Thu, 26 Oct 2017 07:13:50 +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=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B44DE28CCD for ; Thu, 26 Oct 2017 07:13:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751548AbdJZHNe (ORCPT ); Thu, 26 Oct 2017 03:13:34 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:44227 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750997AbdJZHNc (ORCPT ); Thu, 26 Oct 2017 03:13:32 -0400 Received: by mail-wm0-f67.google.com with SMTP id 196so18243704wma.1; Thu, 26 Oct 2017 00:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=3fC/sc5ZcOVq32UlWWqGDQB40sZhHhwPgz9SpIl9T60=; b=RZOVyqyZn9gTCZwYwd+pStSKElrDy96qaQ1XA8bgW4aW9NlyP4K92QSUiaMtP1r2sE NaA6xEZOd+MsjHtRMTX3938LVSm8H6JLw3emsThPExEguZrMTrhTJmHo/KeLDRYUclXf tbZ6E/UuYknTt2dGytQvN53gvGIOPVPYAE7L0mm/m7bNcLxB7NYZ32CnvfT7lXRh84Fj G1MNbjyFOILtw8coipIFJZmIbN4mQV/ePCpGRqJbKRo4ckGP2B0N3HTriHlkI8Z8j1ei qomEdIXJrNvkLNh0MX4dDgxTNTS5tc7nozfiuX3KZ1ifsH5OvHuhpL6xXs+tRfzlh0uh Vjrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=3fC/sc5ZcOVq32UlWWqGDQB40sZhHhwPgz9SpIl9T60=; b=m5WBQj5Sr4RFyMPt8Ekc2Aiatmd5tKb/91s3EjLXkkx9zacPwy0Xb7cjjJzJ9yXBYp rQHxXx2EDLnShEiceiJMFMVRj0sqszYjPKFMtHZnUAiCr6GCyQFElYiqea1XeUFtzMyw fcvfdLUkAzAApX9WfH+fYZJYaTmuYA4lpsB9R1GgayaKP6JgxXLkazi9nkDmGGXo77yB 1AIlKKzSJOJnuclmyBnNJvWZfcPHWqQenEhJLkikJUZ24Z3pvnGRaoYNk+ZQG9QLB8Sj 2N53ucZxj2qF/l8xVNQeWNRgN5Xk6ZI2rDZZRxhrytMcViOQwAo0/o8abxjwwjdq9XlG SYZQ== X-Gm-Message-State: AMCzsaX2SRNcd3AuxYzxnGT365ju9A5AAEgzWZnuvwXRsxYv1zLORA3r FWdb9kX1s4eiVpu8i5lklhSW9/JU X-Google-Smtp-Source: ABhQp+QVcuV16C7RUI3ho+JiOKL8q/zuCiVid7JGnZsJzdKphDUOzwi9EL8Vv54uAELQIzuBgMRaUg== X-Received: by 10.28.5.148 with SMTP id 142mr683404wmf.142.1509002010725; Thu, 26 Oct 2017 00:13:30 -0700 (PDT) Received: from localhost.localdomain ([62.168.35.108]) by smtp.gmail.com with ESMTPSA id l7sm3904136wrg.69.2017.10.26.00.13.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Oct 2017 00:13:29 -0700 (PDT) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH] KVM: SVM: obey guest PAT Date: Thu, 26 Oct 2017 09:13:27 +0200 Message-Id: <20171026071327.15427-1-pbonzini@redhat.com> X-Mailer: git-send-email 2.14.2 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For many years some users of assigned devices have reported worse performance on AMD processors with NPT than on AMD without NPT, Intel or bare metal. The reason turned out to be that SVM is discarding the guest PAT setting and uses the default (PA0=PA4=WB, PA1=PA5=WT, PA2=PA6=UC-, PA3=UC). The guest might be using a different setting, and especially might want write combining but isn't getting it (instead getting slow UC or UC- accesses). Thanks a lot to geoff@hostfission.com for noticing the relation to the g_pat setting. The patch has been tested also by a bunch of people on VFIO users forums. Fixes: 709ddebf81cb40e3c36c6109a7892e8b93a09464 Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=196409 Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Reviewed-by: David Hildenbrand Tested-by: Nick Sarnie --- arch/x86/kvm/svm.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index af256b786a70..af09baa3d736 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -3626,6 +3626,13 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) u32 ecx = msr->index; u64 data = msr->data; switch (ecx) { + case MSR_IA32_CR_PAT: + if (!kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, data)) + return 1; + vcpu->arch.pat = data; + svm->vmcb->save.g_pat = data; + mark_dirty(svm->vmcb, VMCB_NPT); + break; case MSR_IA32_TSC: kvm_write_tsc(vcpu, msr); break;