diff mbox

[2/2,v2] ARM: KVM: user_mem_abort: support stage 2 MMIO page mapping

Message ID 20140625194551.a6443252bf913023159d25fd@freescale.com
State Accepted
Commit b88657674d39fc2127d62d0de9ca142e166443c8
Headers show

Commit Message

Kim Phillips June 26, 2014, 12:45 a.m. UTC
From: Kim Phillips <kim.phillips@linaro.org>

A userspace process can map device MMIO memory via VFIO or /dev/mem,
e.g., for platform device passthrough support in QEMU.

During early development, we found the PAGE_S2 memory type being used
for MMIO mappings.  This patch corrects that by using the more strongly
ordered memory type for device MMIO mappings: PAGE_S2_DEVICE.

Signed-off-by: Kim Phillips <kim.phillips@linaro.org>
Acked-by: Christoffer Dall <christoffer.dall@linaro.org>
---
Hi, here's a v2, upon request:

- rebased onto today's mainline ToT
- mmu.o-build tested only (ToT build doesn't complete)
- made commit text less terse
- added Christoffer's ack

Cheers,

Kim

 arch/arm/kvm/mmu.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Will Deacon June 26, 2014, 8:46 a.m. UTC | #1
On Thu, Jun 26, 2014 at 01:45:51AM +0100, Kim Phillips wrote:
> From: Kim Phillips <kim.phillips@linaro.org>
> 
> A userspace process can map device MMIO memory via VFIO or /dev/mem,
> e.g., for platform device passthrough support in QEMU.
> 
> During early development, we found the PAGE_S2 memory type being used
> for MMIO mappings.  This patch corrects that by using the more strongly
> ordered memory type for device MMIO mappings: PAGE_S2_DEVICE.
> 
> Signed-off-by: Kim Phillips <kim.phillips@linaro.org>
> Acked-by: Christoffer Dall <christoffer.dall@linaro.org>
> ---
> Hi, here's a v2, upon request:
> 
> - rebased onto today's mainline ToT
> - mmu.o-build tested only (ToT build doesn't complete)
> - made commit text less terse
> - added Christoffer's ack

Thanks for reposting this so quickly!

  Acked-by: Will Deacon <will.deacon@arm.com>

Will
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Christoffer Dall June 30, 2014, 9:08 a.m. UTC | #2
On Thu, Jun 26, 2014 at 09:46:26AM +0100, Will Deacon wrote:
> On Thu, Jun 26, 2014 at 01:45:51AM +0100, Kim Phillips wrote:
> > From: Kim Phillips <kim.phillips@linaro.org>
> > 
> > A userspace process can map device MMIO memory via VFIO or /dev/mem,
> > e.g., for platform device passthrough support in QEMU.
> > 
> > During early development, we found the PAGE_S2 memory type being used
> > for MMIO mappings.  This patch corrects that by using the more strongly
> > ordered memory type for device MMIO mappings: PAGE_S2_DEVICE.
> > 
> > Signed-off-by: Kim Phillips <kim.phillips@linaro.org>
> > Acked-by: Christoffer Dall <christoffer.dall@linaro.org>
> > ---
> > Hi, here's a v2, upon request:
> > 
> > - rebased onto today's mainline ToT
> > - mmu.o-build tested only (ToT build doesn't complete)
> > - made commit text less terse
> > - added Christoffer's ack
> 
> Thanks for reposting this so quickly!
> 
>   Acked-by: Will Deacon <will.deacon@arm.com>
> 
Thanks,

Marc, will you apply this one to kvmarm/queue [and kvmarm/next]?

-Christoffer
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Marc Zyngier June 30, 2014, 9:14 a.m. UTC | #3
On 30/06/14 10:08, Christoffer Dall wrote:
> On Thu, Jun 26, 2014 at 09:46:26AM +0100, Will Deacon wrote:
>> On Thu, Jun 26, 2014 at 01:45:51AM +0100, Kim Phillips wrote:
>>> From: Kim Phillips <kim.phillips@linaro.org>
>>>
>>> A userspace process can map device MMIO memory via VFIO or /dev/mem,
>>> e.g., for platform device passthrough support in QEMU.
>>>
>>> During early development, we found the PAGE_S2 memory type being used
>>> for MMIO mappings.  This patch corrects that by using the more strongly
>>> ordered memory type for device MMIO mappings: PAGE_S2_DEVICE.
>>>
>>> Signed-off-by: Kim Phillips <kim.phillips@linaro.org>
>>> Acked-by: Christoffer Dall <christoffer.dall@linaro.org>
>>> ---
>>> Hi, here's a v2, upon request:
>>>
>>> - rebased onto today's mainline ToT
>>> - mmu.o-build tested only (ToT build doesn't complete)
>>> - made commit text less terse
>>> - added Christoffer's ack
>>
>> Thanks for reposting this so quickly!
>>
>>   Acked-by: Will Deacon <will.deacon@arm.com>
>>
> Thanks,
> 
> Marc, will you apply this one to kvmarm/queue [and kvmarm/next]?

Yup, adding it.

	M.
diff mbox

Patch

diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index 16f8049..69af021 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -748,6 +748,7 @@  static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 	struct kvm_mmu_memory_cache *memcache = &vcpu->arch.mmu_page_cache;
 	struct vm_area_struct *vma;
 	pfn_t pfn;
+	pgprot_t mem_type = PAGE_S2;
 
 	write_fault = kvm_is_write_fault(kvm_vcpu_get_hsr(vcpu));
 	if (fault_status == FSC_PERM && !write_fault) {
@@ -798,6 +799,9 @@  static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 	if (is_error_pfn(pfn))
 		return -EFAULT;
 
+	if (kvm_is_mmio_pfn(pfn))
+		mem_type = PAGE_S2_DEVICE;
+
 	spin_lock(&kvm->mmu_lock);
 	if (mmu_notifier_retry(kvm, mmu_seq))
 		goto out_unlock;
@@ -805,7 +809,7 @@  static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 		hugetlb = transparent_hugepage_adjust(&pfn, &fault_ipa);
 
 	if (hugetlb) {
-		pmd_t new_pmd = pfn_pmd(pfn, PAGE_S2);
+		pmd_t new_pmd = pfn_pmd(pfn, mem_type);
 		new_pmd = pmd_mkhuge(new_pmd);
 		if (writable) {
 			kvm_set_s2pmd_writable(&new_pmd);
@@ -814,13 +818,14 @@  static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 		coherent_cache_guest_page(vcpu, hva & PMD_MASK, PMD_SIZE);
 		ret = stage2_set_pmd_huge(kvm, memcache, fault_ipa, &new_pmd);
 	} else {
-		pte_t new_pte = pfn_pte(pfn, PAGE_S2);
+		pte_t new_pte = pfn_pte(pfn, mem_type);
 		if (writable) {
 			kvm_set_s2pte_writable(&new_pte);
 			kvm_set_pfn_dirty(pfn);
 		}
 		coherent_cache_guest_page(vcpu, hva, PAGE_SIZE);
-		ret = stage2_set_pte(kvm, memcache, fault_ipa, &new_pte, false);
+		ret = stage2_set_pte(kvm, memcache, fault_ipa, &new_pte,
+				     mem_type == PAGE_S2_DEVICE);
 	}