From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [RFC][PATCH] KVM: SVM: Sync g_pat with guest-written PAT value Date: Tue, 21 Apr 2015 14:11:02 +0200 Message-ID: <55363E56.1020100@redhat.com> References: <552B5128.4010909@siemens.com> <552B6923.3020602@siemens.com> <20150420161401.GB26491@potion.brq.redhat.com> <20150420171635.GC26491@potion.brq.redhat.com> <553535B1.3050901@siemens.com> <20150420173345.GB26478@potion.brq.redhat.com> <55353957.6010907@siemens.com> <55353B3A.6060907@siemens.com> <20150420183303.GF26491@potion.brq.redhat.com> <55354871.5030208@siemens.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Cc: kvm , Joel Schopp To: Jan Kiszka , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= Return-path: Received: from mail-wi0-f172.google.com ([209.85.212.172]:38460 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750960AbbDUMLG (ORCPT ); Tue, 21 Apr 2015 08:11:06 -0400 Received: by wiun10 with SMTP id n10so18996309wiu.1 for ; Tue, 21 Apr 2015 05:11:05 -0700 (PDT) In-Reply-To: <55354871.5030208@siemens.com> Sender: kvm-owner@vger.kernel.org List-ID: On 20/04/2015 20:41, Jan Kiszka wrote: > If the guest pushes data for DMA into RAM, it may assume that it lands > there directly, without the need for explicit flushes, because it has > caching disabled - no? Yes, but Intel IOMMUs can have snooping control and in this case you can just set memory to WB. On Intel, KVM trusts the guest's PAT if the IOMMU is in use, and you do not have an Intel IOMMU with snooping control. In this case kvm_arch_has_noncoherent_dma(vcpu->kvm) returns true. The same should work for AMD, so you can set the gPAT: - to the guest's value if kvm_arch_has_noncoherent_dma(vcpu->kvm), and then you return cachemode2protval(kvm_get_guest_memory_type(...)) from svm_get_mt_mask to layer the guest MTRRs on top of the guest PAT. - otherwise, to all WB (0x0606060606060606), and then you can return either 0 or _PAGE_NOCACHE from svm_get_mt_mask to achieve either UC (for MMIO regions) or WB (for everything else). To sum up you have: IOMMU? no IOMMU? guest PAT obeyed ignored (all WB) guest MTRR obeyed (svm_get_mt_mask) ignored (UC if MMIO, else WB) host PAT always ignored always ignored host MTRR always obeyed always obeyed I think that kvm_arch_has_noncoherent_dma() can be resampled, and gPAT updated, in wbinvd_interception. Paolo