Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5697239pxb; Thu, 20 Jan 2022 02:43:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJyn8J3aophaPhTSTgEgra+jXm5KC21DuUH3li3XKQ1gHDQQcWGw2yJ+NAzomSYNx/+/0gyg X-Received: by 2002:a17:902:8a94:b0:14a:ef2e:60e5 with SMTP id p20-20020a1709028a9400b0014aef2e60e5mr9251520plo.42.1642675420220; Thu, 20 Jan 2022 02:43:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642675420; cv=none; d=google.com; s=arc-20160816; b=NIzOfFGJkE4COyHaAdxKkz8o0NcGRWQcjf5WDo/dJQkXZzl7PdUnh8A7hontCDNE4e Hi1e6ebBt9CCND97r/byT6lPjpiHd5bmaxeYYjhseA/4Ij6kW2AnJ5UMUpTkhecMbxJG xtcE1OGU/qyqPl2KmIOuiyCU+tyReOyuXmUz7aTl7sAjQpf8hY0V2vUsddQt0J0VUb73 RGJIMrdIaGHwe+J7Vjr7Uy7w5aeCR8TFS7dZ1WaGBQl7rO+iKgyqmJH5z3geIO+26lq+ 31whG8rhVpiKjIpcSgjmM5FSXLQRncDRnV6ufc42DbtzAVaXNgLP9S6d4Q6sSo497IFX wB2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=7AXaD+9j6Xo57ig72N3HPtEsn0CPbdRnWIBJ88gNjfk=; b=joY14Wl3MVphQMHZ+AsxQfO6RnRYtuZhPtj43ywCtG4ALmOjvwdK/mq7uRPv5IFVO9 TWYvlX+Vxm8ELFtHiN6GaShJC+YQFE7bCF1l5j6R083FdhNf7R3Oewb1c8OIEwzqRiMI yitwYwkgaJhDdzXOdc3kfBZKKIRzmJxJ5bTktbARYanq5dNKNqEpNJiiYFP2x8CU2za3 GbQLnx0lZ/hjlqvIgbpEluZ9hZYKetdZsM+Ztu5t19H7J3atGPbOk25SQEv+8v88iWHG p87m5qMewRYz2jxc9okJ45HCWYg9sIFLl39x/6M8fm1jL+NXbSE64Jg7TydZiK2alcOG opvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=B04TtwMI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f4si3408047pgm.226.2022.01.20.02.43.28; Thu, 20 Jan 2022 02:43:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=B04TtwMI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243131AbiARNXJ (ORCPT + 99 others); Tue, 18 Jan 2022 08:23:09 -0500 Received: from mga06.intel.com ([134.134.136.31]:48497 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243192AbiARNWt (ORCPT ); Tue, 18 Jan 2022 08:22:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642512169; x=1674048169; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=wc/HrL4JpEiPy0hOw1D7+yU1U6huBzVxxSt7KzpRO+o=; b=B04TtwMI8Z6Q0OSb5WaB8avjVN4KkBlKNKP8mKDlAZs/VIJNh2sM7HzA 3D53A5/bmI9KxAdg0mRf/kgVQ5lJhqjTcpDztbh4fSV8ag4T+r4PFGElC 1JWdamiGyqyQfLVIoWToGuZSyKF/BJred/xV655tgtt7xx3QON44ATjPo J2Jqx9oTpP31Xn58oLEqekiR9++9GQpkwlrXCDLEUWpqn07d3P4nCVQVy AU2WlkOCwOoJaoWP5wV2LH5MM9VlLMCHeWbKCGAp2hWLG/l25RVnQiivE kSMfrj6ktoxYUCCrnsu4Xe4TWqjQ/IpjPe5GZez88B4e3J+hrSEMBFgta w==; X-IronPort-AV: E=McAfee;i="6200,9189,10230"; a="305545836" X-IronPort-AV: E=Sophos;i="5.88,297,1635231600"; d="scan'208";a="305545836" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2022 05:22:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,297,1635231600"; d="scan'208";a="531791841" Received: from chaop.bj.intel.com ([10.240.192.101]) by orsmga008.jf.intel.com with ESMTP; 18 Jan 2022 05:22:42 -0800 From: Chao Peng To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, qemu-devel@nongnu.org Cc: Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Yu Zhang , Chao Peng , "Kirill A . Shutemov" , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com Subject: [PATCH v4 07/12] KVM: Add KVM_EXIT_MEMORY_ERROR exit Date: Tue, 18 Jan 2022 21:21:16 +0800 Message-Id: <20220118132121.31388-8-chao.p.peng@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220118132121.31388-1-chao.p.peng@linux.intel.com> References: <20220118132121.31388-1-chao.p.peng@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 includes additional information for userspace to handle the error. Currently bit 0 is defined as 'private memory' where '1' indicates error happens due to private memory access and '0' indicates error happens due to shared memory access. After private memory is enabled, this new exit will be used for KVM to exit to userspace for shared memory <-> private memory conversion in memory encryption usage. In such usage, typically there are two kind of memory conversions: - explicit conversion: happens when guest explicitly calls into KVM to map a range (as private or shared), KVM then exits to userspace to do the map/unmap operations. - implicit conversion: happens in KVM page fault handler. * if the fault is due to a private memory access then causes a userspace exit for a shared->private conversion request when the page has not been allocated in the private memory backend. * If the fault is due to a shared memory access then causes a userspace exit for a private->shared conversion request when the page has already been allocated in the private memory backend. Signed-off-by: Yu Zhang Signed-off-by: Chao Peng --- include/uapi/linux/kvm.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 5d6dceb1b93e..52d8938a4ba1 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -278,6 +278,7 @@ struct kvm_xen_exit { #define KVM_EXIT_X86_BUS_LOCK 33 #define KVM_EXIT_XEN 34 #define KVM_EXIT_RISCV_SBI 35 +#define KVM_EXIT_MEMORY_ERROR 36 /* For KVM_EXIT_INTERNAL_ERROR */ /* Emulate instruction failed. */ @@ -495,6 +496,14 @@ struct kvm_run { unsigned long args[6]; unsigned long ret[2]; } riscv_sbi; + /* KVM_EXIT_MEMORY_ERROR */ + struct { +#define KVM_MEMORY_EXIT_FLAG_PRIVATE (1 << 0) + __u32 flags; + __u32 padding; + __u64 gpa; + __u64 size; + } memory; /* Fix the size of the union. */ char padding[256]; }; -- 2.17.1