From patchwork Sat Dec 2 09:15:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 172761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1672980vqy; Sat, 2 Dec 2023 01:44:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IFbf9Iads7I1lTPFPwyNw0z7YJUrLP+8BTizhOs4ZC331AfKsfIIh7OSzOHpFO4Tq6S3ISZ X-Received: by 2002:a17:90b:17c8:b0:285:db2e:f6ec with SMTP id me8-20020a17090b17c800b00285db2ef6ecmr839106pjb.8.1701510286713; Sat, 02 Dec 2023 01:44:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701510286; cv=none; d=google.com; s=arc-20160816; b=BUI4cGkouF60/tbHMDLw+5siXHqjSoPgmEKlkxplO9DODYjQD0W9nE+QajFG6YO1rE UBwaha68+VHOZrQ5stqooT5ZG+XLDa1bv2QbMSG0Y6fXjxyNxwwMwFFNfCY09CLKLjX2 GUwI9wFXMIi8x8MRVZwp+Ti5BmG8PSsSx9JYE+V3GiFzyd44i8HOK3JZqBodf/6rCGIK 4XaUpAnGssvEJLoRqSHGBI88NCUsnX0qOE3ipeErCKG5nq+Zs2N2mrfjVuRJgvV4NVS1 endTNXYgZvjQZlf9sB7q9No0NfPmgy0hZKaQ1hILzCLLic2/gQdd31XcYjuMXyHzQoEc r4rw== 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=8RWm6h6NQEKA/hTmPc4g5ktvtEx9lVA8gcQZUkhtr9E=; fh=+WI4m5k3dRLR+dR3neThuZkNBTzIm/a8HgtddERL9fA=; b=AjS2FQJTGC/np4GIZQPeztN4MBYWAAjC5+9ufq3OUrQbXQkC5trnNadZbLaNCvAtIJ xuy53qTP669FcNJCIa7XKTn42ssvYw34LaryaK6XZhkHrhnRKpnGIrNGiLtFsjjvA8Bg I269W9/JhikVJbDMXkePxWRQACjSpMVeJT964HdRkERw9sPOqGpLmqphvG0CtRRO0ClT RqRqzdETxhZP5Nct/G3f1ODRfb/38ugW5a6ZcV+8coV52BJxNHzxKjV9Z+tLx4WEZ5RV TdNpuSG2mEku+oZMBJtK76icIE/Jz201vXP5yahQcNeIQkTn4serpK7x9f4NHaysamTL 0ACQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=doAyBkor; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id x20-20020a17090aca1400b0026b71fdd505si4755102pjt.177.2023.12.02.01.44.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 01:44:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=doAyBkor; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id D7DD5808A377; Sat, 2 Dec 2023 01:44:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232253AbjLBJoe (ORCPT + 99 others); Sat, 2 Dec 2023 04:44:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231849AbjLBJod (ORCPT ); Sat, 2 Dec 2023 04:44:33 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15A94181; Sat, 2 Dec 2023 01:44:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701510280; x=1733046280; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=3m2805xxDC9GupP7oswWsUnW1kwrOEt/HuavVpPlfek=; b=doAyBkorSKI5GQlTAY56Lfn9XRT5lkLs1Q3aGbjDVVfRCbYIeEfa/YIa ZKk4DXV7s7Z+duit9oKQO23iVrNAbqiA30lXJykin+KRE7r1Vz7wUzVa3 WBdHhCtTmP3dE0uNjw08lOXkF/TseFZua7aGD9RtmmOzC+InIaKMoY1Mu 2LBkb0zxtZlHaI4JhAUKKD0SmZ36+J6y/D69sc9bZM9dE/hyV5OGsiMI8 B22Xp7MDsDtsgLvhcseB/pFll9eATs377JfLnXbnGsqdr3vPHAixltJFx 2EnCyJSho3M47VdLdDYQ+axaqAdagy2fcOQIDXVZr00K1fTFP36e8jRgY A==; X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="390756406" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="390756406" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 01:44:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="860817503" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="860817503" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 01:44:36 -0800 From: Yan Zhao To: iommu@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: alex.williamson@redhat.com, jgg@nvidia.com, pbonzini@redhat.com, seanjc@google.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, kevin.tian@intel.com, baolu.lu@linux.intel.com, dwmw2@infradead.org, yi.l.liu@intel.com, Yan Zhao Subject: [RFC PATCH 03/42] KVM: Introduce VM ioctl KVM_CREATE_TDP_FD Date: Sat, 2 Dec 2023 17:15:41 +0800 Message-Id: <20231202091541.13568-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231202091211.13376-1-yan.y.zhao@intel.com> References: <20231202091211.13376-1-yan.y.zhao@intel.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sat, 02 Dec 2023 01:44:43 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784162850290695233 X-GMAIL-MSGID: 1784162850290695233 Introduce VM ioctl KVM_CREATE_TDP_FD to create KVM TDP FD object, which will act as an interface of KVM to export TDP page tables and communicate with external components of KVM. Signed-off-by: Yan Zhao --- include/uapi/linux/kvm.h | 19 +++++++++++++++++++ virt/kvm/kvm_main.c | 19 +++++++++++++++++++ virt/kvm/tdp_fd.h | 10 ++++++++++ 3 files changed, 48 insertions(+) create mode 100644 virt/kvm/tdp_fd.h diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 211b86de35ac5..f181883c60fed 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1582,6 +1582,9 @@ struct kvm_s390_ucas_mapping { #define KVM_GET_DEVICE_ATTR _IOW(KVMIO, 0xe2, struct kvm_device_attr) #define KVM_HAS_DEVICE_ATTR _IOW(KVMIO, 0xe3, struct kvm_device_attr) +/* ioctl for vm fd to create tdp fd */ +#define KVM_CREATE_TDP_FD _IOWR(KVMIO, 0xe4, struct kvm_create_tdp_fd) + /* * ioctls for vcpu fds */ @@ -2267,4 +2270,20 @@ struct kvm_s390_zpci_op { /* flags for kvm_s390_zpci_op->u.reg_aen.flags */ #define KVM_S390_ZPCIOP_REGAEN_HOST (1 << 0) +/** + * struct kvm_create_tdp_fd - VM ioctl(KVM_CREATE_TDP_FD) + * Create a TDP fd object for a TDP exported by KVM. + * + * @as_id: in: Address space ID for this TDP. + * @mode: in: Mode of this tdp. + * Reserved for future usage. Currently, this field must be 0. + * @fd: out: fd of TDP fd object for a TDP exported by KVM. + * @pad: in: Reserved as 0. + */ +struct kvm_create_tdp_fd { + __u32 as_id; + __u32 mode; + __u32 fd; + __u32 pad; +}; #endif /* __LINUX_KVM_H */ diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 486800a7024b3..494b6301a6065 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -61,6 +61,7 @@ #include "async_pf.h" #include "kvm_mm.h" #include "vfio.h" +#include "tdp_fd.h" #include @@ -4973,6 +4974,24 @@ static long kvm_vm_ioctl(struct file *filp, case KVM_GET_STATS_FD: r = kvm_vm_ioctl_get_stats_fd(kvm); break; + case KVM_CREATE_TDP_FD: { + struct kvm_create_tdp_fd ct; + + r = -EFAULT; + if (copy_from_user(&ct, argp, sizeof(ct))) + goto out; + + r = kvm_create_tdp_fd(kvm, &ct); + if (r) + goto out; + + r = -EFAULT; + if (copy_to_user(argp, &ct, sizeof(ct))) + goto out; + + r = 0; + break; + } default: r = kvm_arch_vm_ioctl(filp, ioctl, arg); } diff --git a/virt/kvm/tdp_fd.h b/virt/kvm/tdp_fd.h new file mode 100644 index 0000000000000..05c8a6d767469 --- /dev/null +++ b/virt/kvm/tdp_fd.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __TDP_FD_H +#define __TDP_FD_H + +static inline int kvm_create_tdp_fd(struct kvm *kvm, struct kvm_create_tdp_fd *ct) +{ + return -EOPNOTSUPP; +} + +#endif /* __TDP_FD_H */