All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chia-I Wu <olvaffe@gmail.com>
To: kvm@vger.kernel.org
Cc: wanpengli@tencent.com, joro@8bytes.org,
	dri-devel@lists.freedesktop.org, gurchetansingh@chromium.org,
	kraxel@redhat.com, pbonzini@redhat.com, vkuznets@redhat.com,
	jmattson@google.com
Subject: [RFC PATCH 3/3] RFC: KVM: x86: support KVM_CAP_DMA_MEM
Date: Thu, 13 Feb 2020 13:30:36 -0800	[thread overview]
Message-ID: <20200213213036.207625-4-olvaffe@gmail.com> (raw)
In-Reply-To: <20200213213036.207625-1-olvaffe@gmail.com>

When a memslot has KVM_MEM_DMA set, we want VMX_EPT_IPAT_BIT cleared
for the memslot.  Before that is possible, simply call
kvm_arch_register_noncoherent_dma for the memslot.

SVM does not have the ignore-pat bit.  Guest PAT is always honored.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Cc: Gurchetan Singh <gurchetansingh@chromium.org>
Cc: Gerd Hoffmann <kraxel@redhat.com>
---
 arch/x86/include/uapi/asm/kvm.h | 1 +
 arch/x86/kvm/x86.c              | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h
index 503d3f42da16..578b686e3880 100644
--- a/arch/x86/include/uapi/asm/kvm.h
+++ b/arch/x86/include/uapi/asm/kvm.h
@@ -48,6 +48,7 @@
 #define __KVM_HAVE_XSAVE
 #define __KVM_HAVE_XCRS
 #define __KVM_HAVE_READONLY_MEM
+#define __KVM_HAVE_DMA_MEM
 
 /* Architectural interrupt line count. */
 #define KVM_NR_INTERRUPTS 256
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index fb5d64ebc35d..c89a4647fef6 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3331,6 +3331,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	case KVM_CAP_GET_TSC_KHZ:
 	case KVM_CAP_KVMCLOCK_CTRL:
 	case KVM_CAP_READONLY_MEM:
+	case KVM_CAP_DMA_MEM:
 	case KVM_CAP_HYPERV_TIME:
 	case KVM_CAP_IOAPIC_POLARITY_IGNORED:
 	case KVM_CAP_TSC_DEADLINE_TIMER:
@@ -10045,6 +10046,11 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
 	 */
 	if (change != KVM_MR_DELETE)
 		kvm_mmu_slot_apply_flags(kvm, (struct kvm_memory_slot *) new);
+
+	if (change == KVM_MR_CREATE && new->flags & KVM_MEM_DMA)
+		kvm_arch_register_noncoherent_dma(kvm);
+	else if (change == KVM_MR_DELETE && old->flags & KVM_MEM_DMA)
+		kvm_arch_unregister_noncoherent_dma(kvm);
 }
 
 void kvm_arch_flush_shadow_all(struct kvm *kvm)
-- 
2.25.0.265.gbab2e86ba0-goog

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

WARNING: multiple messages have this Message-ID (diff)
From: Chia-I Wu <olvaffe@gmail.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com,
	jmattson@google.com, joro@8bytes.org,
	gurchetansingh@chromium.org, kraxel@redhat.com,
	dri-devel@lists.freedesktop.org
Subject: [RFC PATCH 3/3] RFC: KVM: x86: support KVM_CAP_DMA_MEM
Date: Thu, 13 Feb 2020 13:30:36 -0800	[thread overview]
Message-ID: <20200213213036.207625-4-olvaffe@gmail.com> (raw)
In-Reply-To: <20200213213036.207625-1-olvaffe@gmail.com>

When a memslot has KVM_MEM_DMA set, we want VMX_EPT_IPAT_BIT cleared
for the memslot.  Before that is possible, simply call
kvm_arch_register_noncoherent_dma for the memslot.

SVM does not have the ignore-pat bit.  Guest PAT is always honored.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Cc: Gurchetan Singh <gurchetansingh@chromium.org>
Cc: Gerd Hoffmann <kraxel@redhat.com>
---
 arch/x86/include/uapi/asm/kvm.h | 1 +
 arch/x86/kvm/x86.c              | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h
index 503d3f42da16..578b686e3880 100644
--- a/arch/x86/include/uapi/asm/kvm.h
+++ b/arch/x86/include/uapi/asm/kvm.h
@@ -48,6 +48,7 @@
 #define __KVM_HAVE_XSAVE
 #define __KVM_HAVE_XCRS
 #define __KVM_HAVE_READONLY_MEM
+#define __KVM_HAVE_DMA_MEM
 
 /* Architectural interrupt line count. */
 #define KVM_NR_INTERRUPTS 256
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index fb5d64ebc35d..c89a4647fef6 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3331,6 +3331,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	case KVM_CAP_GET_TSC_KHZ:
 	case KVM_CAP_KVMCLOCK_CTRL:
 	case KVM_CAP_READONLY_MEM:
+	case KVM_CAP_DMA_MEM:
 	case KVM_CAP_HYPERV_TIME:
 	case KVM_CAP_IOAPIC_POLARITY_IGNORED:
 	case KVM_CAP_TSC_DEADLINE_TIMER:
@@ -10045,6 +10046,11 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
 	 */
 	if (change != KVM_MR_DELETE)
 		kvm_mmu_slot_apply_flags(kvm, (struct kvm_memory_slot *) new);
+
+	if (change == KVM_MR_CREATE && new->flags & KVM_MEM_DMA)
+		kvm_arch_register_noncoherent_dma(kvm);
+	else if (change == KVM_MR_DELETE && old->flags & KVM_MEM_DMA)
+		kvm_arch_unregister_noncoherent_dma(kvm);
 }
 
 void kvm_arch_flush_shadow_all(struct kvm *kvm)
-- 
2.25.0.265.gbab2e86ba0-goog


  parent reply	other threads:[~2020-02-13 21:30 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-13 21:30 [RFC PATCH 0/3] KVM: x86: honor guest memory type Chia-I Wu
2020-02-13 21:30 ` Chia-I Wu
2020-02-13 21:30 ` [RFC PATCH 1/3] KVM: vmx: rewrite the comment in vmx_get_mt_mask Chia-I Wu
2020-02-13 21:30   ` Chia-I Wu
2020-02-14  9:36   ` Paolo Bonzini
2020-02-14  9:36     ` Paolo Bonzini
2020-02-13 21:30 ` [RFC PATCH 2/3] RFC: KVM: add KVM_MEM_DMA Chia-I Wu
2020-02-13 21:30   ` Chia-I Wu
2020-02-13 21:30 ` Chia-I Wu [this message]
2020-02-13 21:30   ` [RFC PATCH 3/3] RFC: KVM: x86: support KVM_CAP_DMA_MEM Chia-I Wu
2020-02-13 21:41 ` [RFC PATCH 0/3] KVM: x86: honor guest memory type Paolo Bonzini
2020-02-13 21:41   ` Paolo Bonzini
2020-02-13 22:18   ` Chia-I Wu
2020-02-13 22:18     ` Chia-I Wu
2020-02-14 10:26     ` Paolo Bonzini
2020-02-14 10:26       ` Paolo Bonzini
2020-02-14 19:52       ` Sean Christopherson
2020-02-14 19:52         ` Sean Christopherson
2020-02-14 21:47         ` Chia-I Wu
2020-02-14 21:47           ` Chia-I Wu
2020-02-14 21:56           ` Jim Mattson
2020-02-14 21:56             ` Jim Mattson
2020-02-14 22:03             ` Sean Christopherson
2020-02-14 22:03               ` Sean Christopherson
2020-02-18 16:28               ` Paolo Bonzini
2020-02-18 16:28                 ` Paolo Bonzini
2020-02-18 22:58                 ` Sean Christopherson
2020-02-18 22:58                   ` Sean Christopherson
2020-02-19  9:52                 ` Tian, Kevin
2020-02-19  9:52                   ` Tian, Kevin
2020-02-19 19:36                   ` Chia-I Wu
2020-02-19 19:36                     ` Chia-I Wu
2020-02-20  2:04                     ` Tian, Kevin
2020-02-20  2:04                       ` Tian, Kevin
2020-02-20  2:38                       ` Tian, Kevin
2020-02-20  2:38                         ` Tian, Kevin
2020-02-20 22:23                         ` Chia-I Wu
2020-02-20 22:23                           ` Chia-I Wu
2020-02-21  0:23                           ` Tian, Kevin
2020-02-21  0:23                             ` Tian, Kevin
2020-02-21  4:45                             ` Chia-I Wu
2020-02-21  4:51                               ` Chia-I Wu
2020-02-21  4:51                                 ` Chia-I Wu
2020-02-21  5:39                                 ` Tian, Kevin
2020-02-21  5:39                                   ` Tian, Kevin
2020-02-21 15:59                                   ` Sean Christopherson
2020-02-21 15:59                                     ` Sean Christopherson
2020-02-21 18:21                                     ` Chia-I Wu
2020-02-21 18:21                                       ` Chia-I Wu
2020-02-25  1:29                                       ` Tian, Kevin
2020-02-25  1:29                                         ` Tian, Kevin
2020-02-14 21:15       ` Chia-I Wu
2020-02-14 21:15         ` Chia-I Wu
2020-02-19 10:00         ` Tian, Kevin
2020-02-19 10:00           ` Tian, Kevin
2020-02-19 19:18           ` Chia-I Wu
2020-02-19 19:18             ` Chia-I Wu
2020-02-20  2:13             ` Tian, Kevin
2020-02-20  2:13               ` Tian, Kevin
2020-02-20 23:02               ` Chia-I Wu
2020-02-20 23:02                 ` Chia-I Wu
2020-02-24 10:57               ` Gerd Hoffmann
2020-02-24 10:57                 ` Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200213213036.207625-4-olvaffe@gmail.com \
    --to=olvaffe@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gurchetansingh@chromium.org \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kraxel@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.