Re: [PATCH v10 0/9] KVM: mm: fd-based approach for supporting KVM

2023-04-17 Thread Chao Peng
; On Sat, Jan 14, 2023 at 12:37:59AM +, > > > > Sean Christopherson wrote: > > > > > > > > > On Fri, Dec 02, 2022, Chao Peng wrote: > > > > > > This patch series implements KVM guest private memory for > > > > > > c

Re: [PATCH v10 9/9] KVM: Enable and expose KVM_MEM_PRIVATE

2023-03-28 Thread Chao Peng
On Fri, Mar 24, 2023 at 10:29:25AM +0800, Xiaoyao Li wrote: > On 3/24/2023 10:10 AM, Chao Peng wrote: > > On Wed, Mar 22, 2023 at 05:41:31PM -0700, Isaku Yamahata wrote: > > > On Wed, Mar 08, 2023 at 03:40:26PM +0800, > > > Chao Peng wrote: > > > > > &g

Re: [PATCH v10 0/9] KVM: mm: fd-based approach for supporting KVM

2023-03-24 Thread Chao Peng
On Wed, Mar 22, 2023 at 08:27:37PM -0500, Michael Roth wrote: > On Tue, Feb 21, 2023 at 08:11:35PM +0800, Chao Peng wrote: > > > Hi Sean, > > > > > > We've rebased the SEV+SNP support onto your updated UPM base support > > > tree and things seem to be

Re: [PATCH v10 9/9] KVM: Enable and expose KVM_MEM_PRIVATE

2023-03-23 Thread Chao Peng
On Wed, Mar 22, 2023 at 05:41:31PM -0700, Isaku Yamahata wrote: > On Wed, Mar 08, 2023 at 03:40:26PM +0800, > Chao Peng wrote: > > > On Wed, Mar 08, 2023 at 12:13:24AM +, Ackerley Tng wrote: > > > Chao Peng writes: > > > > > > > On Sat, Jan 14,

Re: [PATCH v10 9/9] KVM: Enable and expose KVM_MEM_PRIVATE

2023-03-07 Thread Chao Peng
On Wed, Mar 08, 2023 at 12:13:24AM +, Ackerley Tng wrote: > Chao Peng writes: > > > On Sat, Jan 14, 2023 at 12:01:01AM +, Sean Christopherson wrote: > > > On Fri, Dec 02, 2022, Chao Peng wrote: > > ... > > > Strongly prefer to use similar logic

Re: [PATCH v10 1/9] mm: Introduce memfd_restricted system call to create restricted user memory

2023-02-23 Thread Chao Peng
> > int restrictedmem_bind(struct file *file, pgoff_t start, pgoff_t end, > >struct restrictedmem_notifier *notifier, bool exclusive) > > { > > struct restrictedmem *rm = file->f_mapping->private_data; > > int ret = -EINVAL; > > > > down_write(>lock); > > > >

Re: [PATCH v10 0/9] KVM: mm: fd-based approach for supporting KVM

2023-02-21 Thread Chao Peng
> Hi Sean, > > We've rebased the SEV+SNP support onto your updated UPM base support > tree and things seem to be working okay, but we needed some fixups on > top of the base support get things working, along with 1 workaround > for an issue that hasn't been root-caused yet: > >

Re: [PATCH v10 9/9] KVM: Enable and expose KVM_MEM_PRIVATE

2023-01-28 Thread Chao Peng
On Sat, Jan 14, 2023 at 12:01:01AM +, Sean Christopherson wrote: > On Fri, Dec 02, 2022, Chao Peng wrote: ... > Strongly prefer to use similar logic to existing code that detects wraps: > > mem->restricted_offset + mem->memory_size < > mem->restrict

Re: [PATCH v10 7/9] KVM: Update lpage info when private/shared memory are mixed

2023-01-28 Thread Chao Peng
On Fri, Jan 13, 2023 at 11:16:27PM +, Sean Christopherson wrote: > On Fri, Dec 02, 2022, Chao Peng wrote: > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > index 9a07380f8d3c..5aefcff614d2 100644 > > --- a/arch/x86/kvm/x86.c > > +++ b/arch/x86/kvm/x86

Re: [PATCH v10 9/9] KVM: Enable and expose KVM_MEM_PRIVATE

2023-01-18 Thread Chao Peng
On Tue, Jan 17, 2023 at 07:35:58PM +, Sean Christopherson wrote: > On Tue, Jan 17, 2023, Chao Peng wrote: > > On Sat, Jan 14, 2023 at 12:01:01AM +, Sean Christopherson wrote: > > > On Fri, Dec 02, 2022, Chao Peng wrote: > > > > @@ -10357,6 +10364,12 @@ stat

Re: [PATCH v10 1/9] mm: Introduce memfd_restricted system call to create restricted user memory

2023-01-18 Thread Chao Peng
On Tue, Jan 17, 2023 at 04:34:15PM +, Sean Christopherson wrote: > On Tue, Jan 17, 2023, Chao Peng wrote: > > On Fri, Jan 13, 2023 at 09:54:41PM +, Sean Christopherson wrote: > > > > + list_for_each_entry(notifier, >notifiers, list) { > > >

Re: [PATCH v10 2/9] KVM: Introduce per-page memory attributes

2023-01-17 Thread Chao Peng
On Tue, Jan 17, 2023 at 11:21:10AM +0800, Binbin Wu wrote: > > On 12/2/2022 2:13 PM, Chao Peng wrote: > > In confidential computing usages, whether a page is private or shared is > > necessary information for KVM to perform operations like page fault > > ha

Re: [PATCH v10 0/9] KVM: mm: fd-based approach for supporting KVM

2023-01-17 Thread Chao Peng
On Sat, Jan 14, 2023 at 12:37:59AM +, Sean Christopherson wrote: > On Fri, Dec 02, 2022, Chao Peng wrote: > > This patch series implements KVM guest private memory for confidential > > computing scenarios like Intel TDX[1]. If a TDX host accesses > > TDX-protected guest

Re: [PATCH v10 9/9] KVM: Enable and expose KVM_MEM_PRIVATE

2023-01-17 Thread Chao Peng
On Sat, Jan 14, 2023 at 12:01:01AM +, Sean Christopherson wrote: > On Fri, Dec 02, 2022, Chao Peng wrote: > > @@ -10357,6 +10364,12 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) > > > > if (kvm_check_request(KVM_REQ_UPDATE_CP

Re: [PATCH v10 3/9] KVM: Extend the memslot to support fd-based private memory

2023-01-17 Thread Chao Peng
On Fri, Jan 13, 2023 at 10:37:39PM +, Sean Christopherson wrote: > On Tue, Jan 10, 2023, Chao Peng wrote: > > On Mon, Jan 09, 2023 at 07:32:05PM +, Sean Christopherson wrote: > > > On Fri, Jan 06, 2023, Chao Peng wrote: > > > > On Thu, Jan 05, 2023 at 11:

Re: [PATCH v10 1/9] mm: Introduce memfd_restricted system call to create restricted user memory

2023-01-17 Thread Chao Peng
On Fri, Jan 13, 2023 at 09:54:41PM +, Sean Christopherson wrote: > On Fri, Dec 02, 2022, Chao Peng wrote: > > The system call is currently wired up for x86 arch. > > Building on other architectures (except for arm64 for some reason) yields: > > CALL/.../scr

Re: [PATCH v10 3/9] KVM: Extend the memslot to support fd-based private memory

2023-01-10 Thread Chao Peng
On Mon, Jan 09, 2023 at 07:32:05PM +, Sean Christopherson wrote: > On Fri, Jan 06, 2023, Chao Peng wrote: > > On Thu, Jan 05, 2023 at 11:23:01AM +, Jarkko Sakkinen wrote: > > > On Fri, Dec 02, 2022 at 02:13:41PM +0800, Chao Peng wrote: > > > > To make futur

Re: [PATCH v10 3/9] KVM: Extend the memslot to support fd-based private memory

2023-01-06 Thread Chao Peng
On Thu, Jan 05, 2023 at 11:23:01AM +, Jarkko Sakkinen wrote: > On Fri, Dec 02, 2022 at 02:13:41PM +0800, Chao Peng wrote: > > In memory encryption usage, guest memory may be encrypted with special > > key and can be accessed only by the guest itself. We call such memory >

Re: [PATCH v10 9/9] KVM: Enable and expose KVM_MEM_PRIVATE

2023-01-05 Thread Chao Peng
On Thu, Jan 05, 2023 at 12:38:30PM -0800, Vishal Annapurve wrote: > On Thu, Dec 1, 2022 at 10:20 PM Chao Peng wrote: > > > > +#ifdef CONFIG_HAVE_KVM_RESTRICTED_MEM > > +static bool restrictedmem_range_is_valid(struct kvm_memory_slot *slot, > > +

Re: [PATCH v10 2/9] KVM: Introduce per-page memory attributes

2023-01-04 Thread Chao Peng
On Tue, Jan 03, 2023 at 11:06:37PM +, Sean Christopherson wrote: > On Tue, Jan 03, 2023, Wang, Wei W wrote: > > On Tuesday, January 3, 2023 9:40 AM, Chao Peng wrote: > > > > Because guest memory defaults to private, and now this patch stores &

Re: [PATCH v10 2/9] KVM: Introduce per-page memory attributes

2023-01-02 Thread Chao Peng
On Wed, Dec 28, 2022 at 04:28:01PM +0800, Chenyi Qiang wrote: ... > > +static int kvm_vm_ioctl_set_mem_attributes(struct kvm *kvm, > > + struct kvm_memory_attributes *attrs) > > +{ > > + gfn_t start, end; > > + unsigned long i; > > + void *entry; > > +

Re: [PATCH v10 1/9] mm: Introduce memfd_restricted system call to create restricted user memory

2022-12-23 Thread Chao Peng
On Thu, Dec 22, 2022 at 06:15:24PM +, Sean Christopherson wrote: > On Wed, Dec 21, 2022, Chao Peng wrote: > > On Tue, Dec 20, 2022 at 08:33:05AM +, Huang, Kai wrote: > > > On Tue, 2022-12-20 at 15:22 +0800, Chao Peng wrote: > > > > On Mon, Dec 19, 2022 at 08:4

Re: [PATCH v10 1/9] mm: Introduce memfd_restricted system call to create restricted user memory

2022-12-23 Thread Chao Peng
On Thu, Dec 22, 2022 at 12:37:19AM +, Huang, Kai wrote: > On Wed, 2022-12-21 at 21:39 +0800, Chao Peng wrote: > > > On Tue, Dec 20, 2022 at 08:33:05AM +, Huang, Kai wrote: > > > > > On Tue, 2022-12-20 at 15:22 +0800, Chao Peng wrote: > > > > > &g

Re: [PATCH v10 3/9] KVM: Extend the memslot to support fd-based private memory

2022-12-21 Thread Chao Peng
On Tue, Dec 20, 2022 at 10:55:44AM +0100, Borislav Petkov wrote: > On Tue, Dec 20, 2022 at 03:43:18PM +0800, Chao Peng wrote: > > RESTRICTEDMEM is needed by TDX_HOST, not TDX_GUEST. > > Which basically means that RESTRICTEDMEM should simply depend on KVM. > Because you can't kn

Re: [PATCH v10 1/9] mm: Introduce memfd_restricted system call to create restricted user memory

2022-12-21 Thread Chao Peng
On Tue, Dec 20, 2022 at 08:33:05AM +, Huang, Kai wrote: > On Tue, 2022-12-20 at 15:22 +0800, Chao Peng wrote: > > On Mon, Dec 19, 2022 at 08:48:10AM +, Huang, Kai wrote: > > > On Mon, 2022-12-19 at 15:53 +080

Re: [PATCH v10 3/9] KVM: Extend the memslot to support fd-based private memory

2022-12-19 Thread Chao Peng
On Mon, Dec 19, 2022 at 03:36:28PM +0100, Borislav Petkov wrote: > On Fri, Dec 02, 2022 at 02:13:41PM +0800, Chao Peng wrote: > > In memory encryption usage, guest memory may be encrypted with special > > key and can be accessed only by the guest itself. We call such memory >

Re: [PATCH v10 2/9] KVM: Introduce per-page memory attributes

2022-12-19 Thread Chao Peng
On Mon, Dec 19, 2022 at 11:17:22AM +0100, Borislav Petkov wrote: > On Mon, Dec 19, 2022 at 04:15:32PM +0800, Chao Peng wrote: > > Tamping down with error number a bit: > > > > if (attrs->flags) > > return -ENXIO; > > if (

Re: [PATCH v10 1/9] mm: Introduce memfd_restricted system call to create restricted user memory

2022-12-19 Thread Chao Peng
On Mon, Dec 19, 2022 at 08:48:10AM +, Huang, Kai wrote: > On Mon, 2022-12-19 at 15:53 +0800, Chao Peng wrote: > > > > > > [...] > > > > > > > + > > > > + /* > > > > +* These pages are currently unmovable so d

Re: [PATCH v10 2/9] KVM: Introduce per-page memory attributes

2022-12-19 Thread Chao Peng
On Fri, Dec 16, 2022 at 04:09:06PM +0100, Borislav Petkov wrote: > On Fri, Dec 02, 2022 at 02:13:40PM +0800, Chao Peng wrote: > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > > index 1782c4555d94..7f0f5e9f2406 100644 > > --- a/virt/kvm/kvm_main.c > >

Re: [PATCH v10 3/9] KVM: Extend the memslot to support fd-based private memory

2022-12-19 Thread Chao Peng
On Tue, Dec 13, 2022 at 08:04:14PM +0800, Xiaoyao Li wrote: > On 12/8/2022 7:30 PM, Chao Peng wrote: > > On Thu, Dec 08, 2022 at 04:37:03PM +0800, Xiaoyao Li wrote: > > > On 12/2/2022 2:13 PM, Chao Peng wrote: > > > > > > .. > > > &

Re: [PATCH v10 6/9] KVM: Unmap existing mappings when change the memory attributes

2022-12-18 Thread Chao Peng
On Tue, Dec 13, 2022 at 11:51:25PM +, Huang, Kai wrote: > On Fri, 2022-12-02 at 14:13 +0800, Chao Peng wrote: > >   > > - /* flags is currently not used. */ > > + /* 'flags' is currently not used. */ > >   if (attrs->flags) > >   return

Re: [PATCH v10 1/9] mm: Introduce memfd_restricted system call to create restricted user memory

2022-12-18 Thread Chao Peng
On Tue, Dec 13, 2022 at 11:49:13PM +, Huang, Kai wrote: > > > > memfd_restricted() itself is implemented as a shim layer on top of real > > memory file systems (currently tmpfs). Pages in restrictedmem are marked > > as unmovable and unevictable, this is required for current confidential > >

Re: [PATCH v10 8/9] KVM: Handle page fault for private memory

2022-12-11 Thread Chao Peng
On Fri, Dec 09, 2022 at 09:01:04AM +, Fuad Tabba wrote: > Hi, > > On Fri, Dec 2, 2022 at 6:19 AM Chao Peng wrote: > > > > A KVM_MEM_PRIVATE memslot can include both fd-based private memory and > > hva-based shared memory. Architecture code (like TDX code) can te

Re: [PATCH v10 6/9] KVM: Unmap existing mappings when change the memory attributes

2022-12-11 Thread Chao Peng
On Fri, Dec 09, 2022 at 08:57:31AM +, Fuad Tabba wrote: > Hi, > > On Thu, Dec 8, 2022 at 11:18 AM Chao Peng wrote: > > > > On Wed, Dec 07, 2022 at 05:16:34PM +, Fuad Tabba wrote: > > > Hi, > > > > > > On Fri, Dec 2, 2022 at 6:19 A

Re: [PATCH v10 5/9] KVM: Use gfn instead of hva for mmu_notifier_retry

2022-12-08 Thread Chao Peng
On Tue, Dec 06, 2022 at 03:48:50PM +, Fuad Tabba wrote: ... > > > > > > */ > > > > - if (unlikely(kvm->mmu_invalidate_in_progress) && > > > > - hva >= kvm->mmu_invalidate_range_start && > > > > - hva < kvm->mmu_invalidate_range_end) > > > > -

Re: [PATCH v10 3/9] KVM: Extend the memslot to support fd-based private memory

2022-12-08 Thread Chao Peng
On Thu, Dec 08, 2022 at 04:37:03PM +0800, Xiaoyao Li wrote: > On 12/2/2022 2:13 PM, Chao Peng wrote: > > .. > > > Together with the change, a new config HAVE_KVM_RESTRICTED_MEM is added > > and right now it is selected on X86_64 only. > > > > From the patc

Re: [PATCH v10 8/9] KVM: Handle page fault for private memory

2022-12-08 Thread Chao Peng
On Thu, Dec 08, 2022 at 10:29:18AM +0800, Yuan Yao wrote: > On Fri, Dec 02, 2022 at 02:13:46PM +0800, Chao Peng wrote: > > A KVM_MEM_PRIVATE memslot can include both fd-based private memory and > > hva-based shared memory. Architecture code (like TDX code) can tell > > wheth

Re: [PATCH v10 6/9] KVM: Unmap existing mappings when change the memory attributes

2022-12-08 Thread Chao Peng
On Wed, Dec 07, 2022 at 04:13:14PM +0800, Yuan Yao wrote: > On Fri, Dec 02, 2022 at 02:13:44PM +0800, Chao Peng wrote: > > Unmap the existing guest mappings when memory attribute is changed > > between shared and private. This is needed because shared pages and > > private pag

Re: [PATCH v10 7/9] KVM: Update lpage info when private/shared memory are mixed

2022-12-08 Thread Chao Peng
On Tue, Dec 06, 2022 at 10:42:24PM -0800, Isaku Yamahata wrote: > On Tue, Dec 06, 2022 at 08:02:24PM +0800, > Chao Peng wrote: > > > On Mon, Dec 05, 2022 at 02:49:59PM -0800, Isaku Yamahata wrote: > > > On Fri, Dec 02, 2022 at 02:13:45PM +0800, > > > Chao Peng w

Re: [PATCH v10 6/9] KVM: Unmap existing mappings when change the memory attributes

2022-12-08 Thread Chao Peng
On Wed, Dec 07, 2022 at 05:16:34PM +, Fuad Tabba wrote: > Hi, > > On Fri, Dec 2, 2022 at 6:19 AM Chao Peng wrote: > > > > Unmap the existing guest mappings when memory attribute is changed > > between shared and private. This is needed because shared pages and

Re: [PATCH v10 5/9] KVM: Use gfn instead of hva for mmu_notifier_retry

2022-12-07 Thread Chao Peng
On Tue, Dec 06, 2022 at 10:34:11PM -0800, Isaku Yamahata wrote: > On Tue, Dec 06, 2022 at 07:56:23PM +0800, > Chao Peng wrote: > > > > > - if (unlikely(kvm->mmu_invalidate_in_progress) && > > > > - hva >= kvm->mmu_inval

Re: [PATCH v10 4/9] KVM: Add KVM_EXIT_MEMORY_FAULT exit

2022-12-07 Thread Chao Peng
On Tue, Dec 06, 2022 at 03:47:20PM +, Fuad Tabba wrote: > Hi, > > On Fri, Dec 2, 2022 at 6:19 AM Chao Peng wrote: > > > > This new KVM exit allows userspace to handle memory-related errors. It > > indicates an error happens in KVM at guest memory range [gpa, gpa+si

Re: [PATCH v10 3/9] KVM: Extend the memslot to support fd-based private memory

2022-12-07 Thread Chao Peng
On Tue, Dec 06, 2022 at 12:39:18PM +, Fuad Tabba wrote: > Hi Chao, > > On Tue, Dec 6, 2022 at 11:58 AM Chao Peng wrote: > > > > On Mon, Dec 05, 2022 at 09:03:11AM +, Fuad Tabba wrote: > > > Hi Chao, > > > > > > On Fri

Re: [PATCH v10 2/9] KVM: Introduce per-page memory attributes

2022-12-07 Thread Chao Peng
On Tue, Dec 06, 2022 at 03:07:27PM +, Fuad Tabba wrote: > Hi, > > On Fri, Dec 2, 2022 at 6:18 AM Chao Peng wrote: > > > > In confidential computing usages, whether a page is private or shared is > > necessary information for KVM to perform operations like pa

Re: [PATCH v10 2/9] KVM: Introduce per-page memory attributes

2022-12-07 Thread Chao Peng
On Tue, Dec 06, 2022 at 10:34:32AM -0300, Fabiano Rosas wrote: > Chao Peng writes: > > > In confidential computing usages, whether a page is private or shared is > > necessary information for KVM to perform operations like page fault > > handling, page zapping etc. There

Re: [PATCH v10 1/9] mm: Introduce memfd_restricted system call to create restricted user memory

2022-12-07 Thread Chao Peng
On Tue, Dec 06, 2022 at 02:57:04PM +, Fuad Tabba wrote: > Hi, > > On Fri, Dec 2, 2022 at 6:18 AM Chao Peng wrote: > > > > From: "Kirill A. Shutemov" > > > > Introduce 'memfd_restricted' system call with the ability to create > > memory areas

Re: [PATCH v10 7/9] KVM: Update lpage info when private/shared memory are mixed

2022-12-06 Thread Chao Peng
On Mon, Dec 05, 2022 at 02:49:59PM -0800, Isaku Yamahata wrote: > On Fri, Dec 02, 2022 at 02:13:45PM +0800, > Chao Peng wrote: > > > A large page with mixed private/shared subpages can't be mapped as large > > page since its sub private/shared pages are from different memory

Re: [PATCH v10 5/9] KVM: Use gfn instead of hva for mmu_notifier_retry

2022-12-06 Thread Chao Peng
On Mon, Dec 05, 2022 at 09:23:49AM +, Fuad Tabba wrote: > Hi Chao, > > On Fri, Dec 2, 2022 at 6:19 AM Chao Peng wrote: > > > > Currently in mmu_notifier invalidate path, hva range is recorded and > > then checked against by mmu_notifier_retry_hva() in the p

Re: [PATCH v10 3/9] KVM: Extend the memslot to support fd-based private memory

2022-12-06 Thread Chao Peng
On Mon, Dec 05, 2022 at 09:03:11AM +, Fuad Tabba wrote: > Hi Chao, > > On Fri, Dec 2, 2022 at 6:18 AM Chao Peng wrote: > > > > In memory encryption usage, guest memory may be encrypted with special > > key and can be accessed only by the guest itself. We call suc

Re: [PATCH v9 1/8] mm: Introduce memfd_restricted system call to create restricted user memory

2022-12-01 Thread Chao Peng
On Thu, Dec 01, 2022 at 06:16:46PM -0800, Vishal Annapurve wrote: > On Tue, Oct 25, 2022 at 8:18 AM Chao Peng wrote: > > ... > > +} > > + > > +SYSCALL_DEFINE1(memfd_restricted, unsigned int, flags) > > +{ > > Looking at the underlying shmem implementatio

[PATCH v10 2/9] KVM: Introduce per-page memory attributes

2022-12-01 Thread Chao Peng
. - KVM_GET_SUPPORTED_MEMORY_ATTRIBUTES to return the KVM supported memory attributes. KVM internally uses xarray to store the per-page memory attributes. Suggested-by: Sean Christopherson Signed-off-by: Chao Peng Link: https://lore.kernel.org/all/y2wb48kd0j4vg...@google.com/ --- Documentation/virt/kvm/api.rst | 63

[PATCH v10 7/9] KVM: Update lpage info when private/shared memory are mixed

2022-12-01 Thread Chao Peng
subpages and update this 'mixed' bit whenever the memory attribute is changed between private and shared. Signed-off-by: Chao Peng --- arch/x86/include/asm/kvm_host.h | 8 ++ arch/x86/kvm/mmu/mmu.c | 134 +++- arch/x86/kvm/x86.c | 2

[PATCH v10 9/9] KVM: Enable and expose KVM_MEM_PRIVATE

2022-12-01 Thread Chao Peng
Signed-off-by: Yu Zhang Signed-off-by: Chao Peng Reviewed-by: Fuad Tabba --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/x86.c | 13 +++ include/linux/kvm_host.h| 3 + virt/kvm/kvm_main.c | 179 +++- 4 files changed, 191

[PATCH v10 6/9] KVM: Unmap existing mappings when change the memory attributes

2022-12-01 Thread Chao Peng
page state, invoke kvm_mmu_invalidate_* helpers to let the page fault handler retry during this time frame. Signed-off-by: Chao Peng --- include/linux/kvm_host.h | 7 +- virt/kvm/kvm_main.c | 168 ++- 2 files changed, 116 insertions(+), 59 deletions

[PATCH v10 3/9] KVM: Extend the memslot to support fd-based private memory

2022-12-01 Thread Chao Peng
the normal and the '_ext' variants. Co-developed-by: Yu Zhang Signed-off-by: Yu Zhang Signed-off-by: Chao Peng Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba --- Documentation/virt/kvm/api.rst | 40 ++- arch/x86/kvm/Kconfig | 2 ++ arch/x86/kvm/x86.c

[PATCH v10 8/9] KVM: Handle page fault for private memory

2022-12-01 Thread Chao Peng
Zhang Signed-off-by: Chao Peng --- arch/x86/kvm/mmu/mmu.c | 63 +++-- arch/x86/kvm/mmu/mmu_internal.h | 14 +++- arch/x86/kvm/mmu/mmutrace.h | 1 + arch/x86/kvm/mmu/tdp_mmu.c | 2 +- include/linux/kvm_host.h| 30 5 files

[PATCH v10 5/9] KVM: Use gfn instead of hva for mmu_notifier_retry

2022-12-01 Thread Chao Peng
-by: Sean Christopherson Signed-off-by: Chao Peng --- arch/x86/kvm/mmu/mmu.c | 8 +--- include/linux/kvm_host.h | 33 + virt/kvm/kvm_main.c | 32 +++- 3 files changed, 49 insertions(+), 24 deletions(-) diff --git a/arch/x86/kvm

[PATCH v10 4/9] KVM: Add KVM_EXIT_MEMORY_FAULT exit

2022-12-01 Thread Chao Peng
rspace for an implicit conversion when the page is in a different state than requested (private or shared). Suggested-by: Sean Christopherson Co-developed-by: Yu Zhang Signed-off-by: Yu Zhang Signed-off-by: Chao Peng Reviewed-by: Fuad Tabba --- Documentation/virt/kvm/api.rs

[PATCH v10 0/9] KVM: mm: fd-based approach for supporting KVM

2022-12-01 Thread Chao Peng
48.200037-1-sea...@google.com/ [4] Selftest: https://lore.kernel.org/all/2022014244.1714148-1-vannapu...@google.com/ Chao Peng (8): KVM: Introduce per-page memory attributes KVM: Extend the memslot to support fd-based private memory KVM: Add KVM_EXIT_MEMORY_FAULT exit KVM: Use gfn

[PATCH v10 1/9] mm: Introduce memfd_restricted system call to create restricted user memory

2022-12-01 Thread Chao Peng
restricted() prevents userspace read, write and mmap. By defining new bit in the 'flags', it can be extended to support other restricted semantics in the future. The system call is currently wired up for x86 arch. Signed-off-by: Kirill A. Shutemov Signed-off-by: Chao Peng --- arch/x86/entr

Re: [PATCH v9 1/8] mm: Introduce memfd_restricted system call to create restricted user memory

2022-11-30 Thread Chao Peng
On Tue, Nov 29, 2022 at 01:18:15PM -0600, Michael Roth wrote: > On Tue, Nov 29, 2022 at 01:06:58PM -0600, Michael Roth wrote: > > On Tue, Nov 29, 2022 at 10:06:15PM +0800, Chao Peng wrote: > > > On Mon, Nov 28, 2022 at 06:37:25PM -0600, Michael Roth wrote: > > > >

Re: [PATCH v9 1/8] mm: Introduce memfd_restricted system call to create restricted user memory

2022-11-29 Thread Chao Peng
On Mon, Nov 28, 2022 at 06:37:25PM -0600, Michael Roth wrote: > On Tue, Oct 25, 2022 at 11:13:37PM +0800, Chao Peng wrote: ... > > +static long restrictedmem_fallocate(struct file *file, int mode, > > + loff_t offset, loff_t len) > &

Re: [PATCH v9 1/8] mm: Introduce memfd_restricted system call to create restricted user memory

2022-11-29 Thread Chao Peng
On Tue, Nov 29, 2022 at 12:39:06PM +0100, David Hildenbrand wrote: > On 29.11.22 12:21, Kirill A. Shutemov wrote: > > On Mon, Nov 28, 2022 at 06:06:32PM -0600, Michael Roth wrote: > > > On Tue, Oct 25, 2022 at 11:13:37PM +0800, Chao Peng wrote: > > >

Re: [PATCH v9 1/8] mm: Introduce memfd_restricted system call to create restricted user memory

2022-11-29 Thread Chao Peng
On Tue, Nov 29, 2022 at 02:21:39PM +0300, Kirill A. Shutemov wrote: > On Mon, Nov 28, 2022 at 06:06:32PM -0600, Michael Roth wrote: > > On Tue, Oct 25, 2022 at 11:13:37PM +0800, Chao Peng wrote: > > > From: "Kirill A. Shutemov" > > > >

Re: [PATCH v9 3/8] KVM: Add KVM_EXIT_MEMORY_FAULT exit

2022-11-22 Thread Chao Peng
On Fri, Nov 18, 2022 at 03:59:12PM +, Sean Christopherson wrote: > On Fri, Nov 18, 2022, Alex Benn?e wrote: > > > > Chao Peng writes: > > > > > On Thu, Nov 17, 2022 at 03:08:17PM +, Alex Benn?e wrote: > > >> >> I think this shoul

Re: [PATCH v9 3/8] KVM: Add KVM_EXIT_MEMORY_FAULT exit

2022-11-17 Thread Chao Peng
On Thu, Nov 17, 2022 at 03:08:17PM +, Alex Bennée wrote: > > Chao Peng writes: > > > On Wed, Nov 16, 2022 at 07:03:49PM +, Alex Bennée wrote: > >> > >> Chao Peng writes: > >> > >> > On Tue, Nov 15, 2022 at 04:56:12PM +,

Re: [PATCH v9 0/8] KVM: mm: fd-based approach for supporting KVM

2022-11-17 Thread Chao Peng
On Wed, Nov 16, 2022 at 09:40:23AM +, Alex Bennée wrote: > > Chao Peng writes: > > > On Mon, Nov 14, 2022 at 11:43:37AM +, Alex Bennée wrote: > >> > >> Chao Peng writes: > >> > >> > >> > Introduction > >> >

Re: [PATCH v9 3/8] KVM: Add KVM_EXIT_MEMORY_FAULT exit

2022-11-17 Thread Chao Peng
On Wed, Nov 16, 2022 at 07:03:49PM +, Alex Bennée wrote: > > Chao Peng writes: > > > On Tue, Nov 15, 2022 at 04:56:12PM +, Alex Bennée wrote: > >> > >> Chao Peng writes: > >> > >> > This new KVM exit allows userspace to hand

Re: [PATCH v9 3/8] KVM: Add KVM_EXIT_MEMORY_FAULT exit

2022-11-17 Thread Chao Peng
On Wed, Nov 16, 2022 at 06:48:43PM +, Sean Christopherson wrote: > On Wed, Nov 16, 2022, Andy Lutomirski wrote: > > > > > > On Tue, Oct 25, 2022, at 8:13 AM, Chao Peng wrote: > > > diff --git a/Documentation/virt/kvm/api.rst > > > b/Documentation/vi

Re: [PATCH v9 7/8] KVM: Handle page fault for private memory

2022-11-17 Thread Chao Peng
On Wed, Nov 16, 2022 at 10:13:07PM +, Sean Christopherson wrote: > On Wed, Nov 16, 2022, Ackerley Tng wrote: > > >@@ -4173,6 +4203,22 @@ static int kvm_faultin_pfn(struct kvm_vcpu *vcpu, > > >struct kvm_page_fault *fault) > > > return RET_PF_EMULATE; > > > } > > > > > >+

Re: [PATCH v9 5/8] KVM: Register/unregister the guest private memory regions

2022-11-17 Thread Chao Peng
On Wed, Nov 16, 2022 at 10:24:11PM +, Sean Christopherson wrote: > On Tue, Oct 25, 2022, Chao Peng wrote: > > +static int kvm_vm_ioctl_set_mem_attr(struct kvm *kvm, gpa_t gpa, gpa_t > > size, > > +bool is_private) > >

Re: [PATCH v9 0/8] KVM: mm: fd-based approach for supporting KVM

2022-11-15 Thread Chao Peng
On Mon, Nov 14, 2022 at 11:43:37AM +, Alex Bennée wrote: > > Chao Peng writes: > > > > Introduction > > > > KVM userspace being able to crash the host is horrible. Under current > > KVM architecture, all guest memory is inherent

Re: [PATCH v9 3/8] KVM: Add KVM_EXIT_MEMORY_FAULT exit

2022-11-15 Thread Chao Peng
On Tue, Nov 15, 2022 at 04:56:12PM +, Alex Bennée wrote: > > Chao Peng writes: > > > This new KVM exit allows userspace to handle memory-related errors. It > > indicates an error happens in KVM at guest memory range [gpa, gpa+size). > > The flags incl

Re: [PATCH v9 1/8] mm: Introduce memfd_restricted system call to create restricted user memory

2022-11-15 Thread Chao Peng
v 01, 2022 at 07:37:29PM +0800, Chao Peng wrote: > > > >> > > > > >> > 1) restoring kernel directmap: > > > >> > > > > >> > Currently SNP (and I believe TDX) need to either split or > > >

Re: [PATCH v9 2/8] KVM: Extend the memslot to support fd-based private memory

2022-11-15 Thread Chao Peng
On Mon, Nov 14, 2022 at 04:04:59PM +, Alex Bennée wrote: > > Chao Peng writes: > > > In memory encryption usage, guest memory may be encrypted with special > > key and can be accessed only by the guest itself. We call such memory > > private memory. It's valuel

Re: [PATCH v9 4/8] KVM: Use gfn instead of hva for mmu_notifier_retry

2022-11-11 Thread Chao Peng
On Thu, Nov 10, 2022 at 08:06:33PM +, Sean Christopherson wrote: > On Tue, Oct 25, 2022, Chao Peng wrote: > > @@ -715,15 +715,9 @@ static void kvm_mmu_notifier_change_pte(struct > > mmu_notifier *mn, > > kvm_handle_hva_range(mn, address, address + 1,

Re: [PATCH v9 6/8] KVM: Update lpage info when private/shared memory are mixed

2022-11-08 Thread Chao Peng
On Tue, Nov 08, 2022 at 08:08:05PM +0800, Yuan Yao wrote: > On Tue, Oct 25, 2022 at 11:13:42PM +0800, Chao Peng wrote: > > When private/shared memory are mixed in a large page, the lpage_info may > > not be accurate and should be updated with this mixed info. A large page > >

Re: [PATCH v9 5/8] KVM: Register/unregister the guest private memory regions

2022-11-08 Thread Chao Peng
On Tue, Nov 08, 2022 at 09:35:06AM +0800, Yuan Yao wrote: > On Tue, Oct 25, 2022 at 11:13:41PM +0800, Chao Peng wrote: > > Introduce generic private memory register/unregister by reusing existing > > SEV ioctls KVM_MEMORY_ENCRYPT_{UN,}REG_REGION. It differs from SEV case > >

Re: [PATCH v9 5/8] KVM: Register/unregister the guest private memory regions

2022-11-08 Thread Chao Peng
On Fri, Nov 04, 2022 at 09:19:31PM +, Sean Christopherson wrote: > Paolo, any thoughts before I lead things further astray? > > On Fri, Nov 04, 2022, Chao Peng wrote: > > On Thu, Nov 03, 2022 at 11:04:53PM +, Sean Christopherson wrote: > > > On Tue, Oct 2

Re: [PATCH v9 4/8] KVM: Use gfn instead of hva for mmu_notifier_retry

2022-11-07 Thread Chao Peng
On Fri, Nov 04, 2022 at 10:29:48PM +, Sean Christopherson wrote: > On Fri, Nov 04, 2022, Chao Peng wrote: > > On Thu, Oct 27, 2022 at 11:29:14AM +0100, Fuad Tabba wrote: > > > Hi, > > > > > > On Tue, Oct 25, 2022 at 4:19 PM Chao Peng > > > wro

Re: [PATCH v9 5/8] KVM: Register/unregister the guest private memory regions

2022-11-04 Thread Chao Peng
On Thu, Nov 03, 2022 at 11:04:53PM +, Sean Christopherson wrote: > On Tue, Oct 25, 2022, Chao Peng wrote: > > @@ -4708,6 +4802,24 @@ static long kvm_vm_ioctl(struct file *filp, > > r = kvm_vm_ioctl_set_memory_region(kvm, ); > > break;

Re: [PATCH v9 4/8] KVM: Use gfn instead of hva for mmu_notifier_retry

2022-11-03 Thread Chao Peng
On Thu, Oct 27, 2022 at 11:29:14AM +0100, Fuad Tabba wrote: > Hi, > > On Tue, Oct 25, 2022 at 4:19 PM Chao Peng wrote: > > > > Currently in mmu_notifier validate path, hva range is recorded and then > > checked against in the mmu_notifier_retry_hva() of the p

Re: [PATCH v9 1/8] mm: Introduce memfd_restricted system call to create restricted user memory

2022-11-02 Thread Chao Peng
On Tue, Nov 01, 2022 at 02:30:58PM -0500, Michael Roth wrote: > On Tue, Nov 01, 2022 at 10:19:44AM -0500, Michael Roth wrote: > > On Tue, Nov 01, 2022 at 07:37:29PM +0800, Chao Peng wrote: > > > On Mon, Oct 31, 2022 at 12:47:38PM -0500, Michael Roth wrote: > > > >

Re: [PATCH v9 7/8] KVM: Handle page fault for private memory

2022-11-01 Thread Chao Peng
On Mon, Oct 31, 2022 at 05:02:50PM -0700, Isaku Yamahata wrote: > On Fri, Oct 28, 2022 at 02:55:45PM +0800, > Chao Peng wrote: > > > On Wed, Oct 26, 2022 at 02:54:25PM -0700, Isaku Yamahata wrote: > > > On Tue, Oct 25, 2022 at 11:13:43PM +0800, > > > Chao Peng

Re: [PATCH v9 1/8] mm: Introduce memfd_restricted system call to create restricted user memory

2022-11-01 Thread Chao Peng
On Mon, Oct 31, 2022 at 12:47:38PM -0500, Michael Roth wrote: > On Tue, Oct 25, 2022 at 11:13:37PM +0800, Chao Peng wrote: > > From: "Kirill A. Shutemov" > > > > Introduce 'memfd_restricted' system call with the ability to create > > memory areas that are res

Re: [PATCH v9 2/8] KVM: Extend the memslot to support fd-based private memory

2022-10-31 Thread Chao Peng
On Fri, Oct 28, 2022 at 03:04:27PM +0800, Xiaoyao Li wrote: > On 10/25/2022 11:13 PM, Chao Peng wrote: > > In memory encryption usage, guest memory may be encrypted with special > > key and can be accessed only by the guest itself. We call such memory > > private m

Re: [PATCH v9 1/8] mm: Introduce memfd_restricted system call to create restricted user memory

2022-10-28 Thread Chao Peng
On Wed, Oct 26, 2022 at 10:31:45AM -0700, Isaku Yamahata wrote: > On Tue, Oct 25, 2022 at 11:13:37PM +0800, > Chao Peng wrote: > > > +int restrictedmem_get_page(struct file *file, pgoff_t offset, > > + struct page **pagep, int *order) > > +{ > &

Re: [PATCH v9 7/8] KVM: Handle page fault for private memory

2022-10-28 Thread Chao Peng
On Wed, Oct 26, 2022 at 02:54:25PM -0700, Isaku Yamahata wrote: > On Tue, Oct 25, 2022 at 11:13:43PM +0800, > Chao Peng wrote: > > > A memslot with KVM_MEM_PRIVATE being set can include both fd-based > > private memory and hva-based shared memory. Architecture code (like T

Re: [PATCH v9 6/8] KVM: Update lpage info when private/shared memory are mixed

2022-10-28 Thread Chao Peng
On Wed, Oct 26, 2022 at 01:46:20PM -0700, Isaku Yamahata wrote: > On Tue, Oct 25, 2022 at 11:13:42PM +0800, > Chao Peng wrote: > > > When private/shared memory are mixed in a large page, the lpage_info may > > not be accurate and should be updated with this mixed info. A lar

Re: [PATCH v9 3/8] KVM: Add KVM_EXIT_MEMORY_FAULT exit

2022-10-28 Thread Chao Peng
On Thu, Oct 27, 2022 at 11:27:05AM +0100, Fuad Tabba wrote: > Hi, > > On Tue, Oct 25, 2022 at 4:19 PM Chao Peng wrote: > > > > This new KVM exit allows userspace to handle memory-related errors. It > > indicates an error happens in KVM at guest memory range [gp

[PATCH v9 1/8] mm: Introduce memfd_restricted system call to create restricted user memory

2022-10-25 Thread Chao Peng
Signed-off-by: Kirill A. Shutemov Signed-off-by: Chao Peng --- arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + include/linux/restrictedmem.h | 62 ++ include/linux/syscalls.h | 1 + include/uapi/asm-generic/unistd.h | 5 +

[PATCH v9 4/8] KVM: Use gfn instead of hva for mmu_notifier_retry

2022-10-25 Thread Chao Peng
fixes a bug in kvm_zap_gfn_range() which has already been using gfn when calling kvm_mmu_invalidate_begin/end() while these functions accept hva in current code. Signed-off-by: Chao Peng --- arch/x86/kvm/mmu/mmu.c | 2 +- include/linux/kvm_host.h | 18 +++- virt/kvm/kvm_main.c

[PATCH v9 0/8] KVM: mm: fd-based approach for supporting KVM

2022-10-25 Thread Chao Peng
.kernel.org/all/20220819174659.2427983-1-vannapu...@google.com/ Chao Peng (7): KVM: Extend the memslot to support fd-based private memory KVM: Add KVM_EXIT_MEMORY_FAULT exit KVM: Use gfn instead of hva for mmu_notifier_retry KVM: Register/unregister the guest private memory regions KVM: Update lpage in

[PATCH v9 7/8] KVM: Handle page fault for private memory

2022-10-25 Thread Chao Peng
-by: Yu Zhang Signed-off-by: Yu Zhang Signed-off-by: Chao Peng --- arch/x86/kvm/mmu/mmu.c | 56 +++-- arch/x86/kvm/mmu/mmu_internal.h | 14 - arch/x86/kvm/mmu/mmutrace.h | 1 + arch/x86/kvm/mmu/spte.h | 6 arch/x86/kvm/mmu/tdp_mmu.c

[PATCH v9 8/8] KVM: Enable and expose KVM_MEM_PRIVATE

2022-10-25 Thread Chao Peng
to do the zapping. Co-developed-by: Yu Zhang Signed-off-by: Yu Zhang Signed-off-by: Chao Peng --- include/linux/kvm_host.h | 3 +- virt/kvm/kvm_main.c | 174 +-- 2 files changed, 171 insertions(+), 6 deletions(-) diff --git a/include/linux/kvm_host.h b

[PATCH v9 5/8] KVM: Register/unregister the guest private memory regions

2022-10-25 Thread Chao Peng
which supports KVM_PRIVATE_MEM should override this function. KVM internally defaults all guest memory as private memory and maintain the shared memory in 'mem_attr_array'. The above ioctls operate on this field and unmap existing mappings if any. Signed-off-by: Chao Peng --- Documentation/virt

[PATCH v9 6/8] KVM: Update lpage info when private/shared memory are mixed

2022-10-25 Thread Chao Peng
private/share pages. Signed-off-by: Chao Peng --- arch/x86/include/asm/kvm_host.h | 8 +++ arch/x86/kvm/mmu/mmu.c | 112 +++- arch/x86/kvm/x86.c | 2 + include/linux/kvm_host.h| 19 ++ virt/kvm/kvm_main.c | 16 +++-- 5

[PATCH v9 2/8] KVM: Extend the memslot to support fd-based private memory

2022-10-25 Thread Chao Peng
a binary compatible alias struct kvm_user_mem_region to handle both the normal and the '_ext' variants. Co-developed-by: Yu Zhang Signed-off-by: Yu Zhang Signed-off-by: Chao Peng --- Documentation/virt/kvm/api.rst | 48 - arch/x86/kvm/Kconfig | 2 ++ arch/x86

[PATCH v9 3/8] KVM: Add KVM_EXIT_MEMORY_FAULT exit

2022-10-25 Thread Chao Peng
rspace for an implicit conversion when the page is in a different state than requested (private or shared). Suggested-by: Sean Christopherson Co-developed-by: Yu Zhang Signed-off-by: Yu Zhang Signed-off-by: Chao Peng --- Documentation/virt/kvm/api.rst | 23 +++ include/uapi

Re: [PATCH v8 1/8] mm/memfd: Introduce userspace inaccessible memfd

2022-10-21 Thread Chao Peng
> wrote: > > > > > > > > On Mon, Oct 17, 2022 at 06:39:06PM +0200, Gupta, Pankaj wrote: > > > > > On 10/17/2022 6:19 PM, Kirill A . Shutemov wrote: > > > > > > On Mon, Oct 17, 2022 at 03:00:21PM +0200, Vlastimil Babka wrot

  1   2   3   4   5   >