Received: by 10.223.185.116 with SMTP id b49csp825126wrg; Sat, 10 Feb 2018 21:17:07 -0800 (PST) X-Google-Smtp-Source: AH8x226nISgVJxLWM25p0oUM1Gy/ENcdmjbeYOKtqGD4QBopzpGh2Z2oCnFsSC5uTKAb3mUk2Mno X-Received: by 10.98.23.65 with SMTP id 62mr7751820pfx.43.1518326227533; Sat, 10 Feb 2018 21:17:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518326227; cv=none; d=google.com; s=arc-20160816; b=CIoWqj6ubreeF8iUGOi2NYNxnfjKUndga2MW6dG+OE8NoA8yKiO1lSP8sik4J+lI6s GXBuyPhEjpEIXh1e0f3DCP4B8C2uqCrzjkAADJPp/QRPSKSAtqrc5XM4ImTpIX85iKSE Lp5Ll+drYgcb0blMzXhYREvEXQdvh3bFrJRtJoY9a2NvdAsxdE0FuxB3iRcvOWtFXiAO aD/k3iN7kgKzSZ6iWB068G4QBYiUS7nA7JoCgUY/uIFwAoLJgTqY04KjOpDpnI4T4pWq VAa3phAQW9guqw2xEPXwNGVgYpZmWYORW5pAof7+1ZWpj1wmxeYxEba/pVC0uN74oTL2 yO+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=eYTjqpoLHhHoVugAzEpYWF7H15TcfuKFcNxxcOmM54Q=; b=l0FDHA7Iz6yL3OXfHWje0Y2yUfIeQJDQ+x5StFNuOKN6AfRFN7UUjPwicWtCBTlu+f HSYQwyZZNTiOorEvcXfobrzKrPJWVi4qWqsuIsMHuXcl+h0vfmKAtS3rMbaxfd3STPbl uXUEf/gEYA6VCXmnqrxhMIsyIVMXWUk0yt4GUAPysn+P8Z6t3WzaZaaupCzq74b2inyw vtWNTEZuYbiP+nrt8IGJmmPMpkrwdyDnqyVWQ6PLmBTdaEviyaW4QJ2US9IWm27IAPM2 VCqfVMXMjcoFAzkU5NzeMbwlAX3PKBpWPnDmldjpIrRsp3E9Bb6JWC4HxjuvtZ4PHL4y QHIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c18-v6si1730951plo.701.2018.02.10.21.16.53; Sat, 10 Feb 2018 21:17:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932128AbeBKFO3 (ORCPT + 99 others); Sun, 11 Feb 2018 00:14:29 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41373 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752589AbeBKEdl (ORCPT ); Sat, 10 Feb 2018 23:33:41 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ekjKd-0002hM-O3; Sun, 11 Feb 2018 04:33:39 +0000 Received: from ben by deadeye with local (Exim 4.90) (envelope-from ) id 1ekjKY-0004VD-8p; Sun, 11 Feb 2018 04:33:34 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Nick Sarnie" , "Paolo Bonzini" , "David Hildenbrand" , "Radim =?UTF-8?Q?Kr=C4=8Dm=C3=A1=C5=99?=" Date: Sun, 11 Feb 2018 04:20:06 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.2 47/79] KVM: SVM: obey guest PAT In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.2.99-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Paolo Bonzini commit 15038e14724799b8c205beb5f20f9e54896013c3 upstream. 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 Signed-off-by: Paolo Bonzini Reviewed-by: David Hildenbrand Tested-by: Nick Sarnie Signed-off-by: Radim Krčmář Signed-off-by: Ben Hutchings --- arch/x86/kvm/svm.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -3040,6 +3040,13 @@ static int svm_set_msr(struct kvm_vcpu * struct vcpu_svm *svm = to_svm(vcpu); 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, data); break;