From patchwork Sat Dec 2 09:18:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 172766 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1673856vqy; Sat, 2 Dec 2023 01:47:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGzCaRy7vNzGwKaen0eszIVxGE5vV56QQryc41Z3ccLC+Nef63tfvCGb1b3TfAUqGD5Fwf3 X-Received: by 2002:a17:902:ec92:b0:1cf:f353:6e5d with SMTP id x18-20020a170902ec9200b001cff3536e5dmr1111926plg.19.1701510478378; Sat, 02 Dec 2023 01:47:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701510478; cv=none; d=google.com; s=arc-20160816; b=bflPSmuAO38uVeOoPiU79rfVceESupuDmkifmYlBV+a9UDy92po0Geo/FZvlSsvc0E tpCpMhrVGwBTMfScDd90OvfSjAH2BLcctq7QCegUiRSbkv+F7Ap7MAFvayIx7hZsKzng Kup3MeMh8JVQFIlx6WumXk7DA7z7T0idMw8dILeuuHKvwtN661xM+IBIWC5zeu8QwtRL oy0ifeBBCwnK2FwB8naT8XCbW6jw0nj6+/IHEOjtdNNDYxA6pABr9b5GjYT+mobHN+Qy n7rBy2fc9eGZGVKm/lAZVMc/qu1Jk5XhwVo/T0oYsW7KjjVkfgOORWD/CnzpfFD9X6v+ trEQ== 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=KdoXpgHOBQK+/mr0tIR7CiaoCfhkem6xwhzesMzjk6E=; fh=+WI4m5k3dRLR+dR3neThuZkNBTzIm/a8HgtddERL9fA=; b=tnT8Aj9lxitKJTe9KYm8gcpUYZXn29DG/vslItamOVMagQfjUMB08MEjzQXsozFOw0 QXKOFkBfXh6mB4xTc42BR9TZ/3e0bh55fmn+jDirugzyCf0RsPWd7GGSC9GYJvuzAIT7 ZbJDj/rrHo7MXk3cNfjFF3GA+x/V6D2eRSLSQGf4HyCgiRi0WpHHEiHYaFvayANZVsE6 uKonLoUT6MyPryQG4yDPkE3j64ttZ2wlT4M0MjXdKtERSd4gRPO6MOmxenXOGHZY4wcN OlIweGfZaAiBB3q7De8jTWifq0RYePu4T/YX+VHZzv0984Q6MGwEo+5JRx3vLz+ARya6 G5jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=e4OnIPat; 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 l5-20020a170903120500b001d005527017si4707875plh.313.2023.12.02.01.47.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 01:47:58 -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=e4OnIPat; 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 2FF39808EE57; Sat, 2 Dec 2023 01:47:54 -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 S232330AbjLBJrp (ORCPT + 99 others); Sat, 2 Dec 2023 04:47:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231849AbjLBJro (ORCPT ); Sat, 2 Dec 2023 04:47:44 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A29E181; Sat, 2 Dec 2023 01:47:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701510471; x=1733046471; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=fHaCSLze+0JkRVgR65Mc5+ZZ7ruPmv2R2QFTSzLWrGg=; b=e4OnIPatRMyAfv2tmRqGQ1vaQsxcj35oTePJ234Poi9Vsfz2iDUfRCVk Ocn3KhYphXUxKxgyW5ULzwWMQacit7VNtOogJfO3dV2+N9JkD+tATbcu1 trr5o91Bwx4X0qfkxE+lWNfotXccWJr584lYnmXJIlIoVrEHpchqSaycA CuBMTz2Sjsdh73clU4KqY6eLPoBxaGLiNRDsKTcCNo5g/TyXAKa2lxFJ8 5k8ld7g8VEZ/tnhMeviV/ACW8iahZXgCGZmGFfg2JowxsQWfShYT32jY5 QuzoOYZxfQflqxNT4TzP6+ZbAc+06KWSla4kqwAh/A9oAVdCyhA+6GmjE w==; X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="6886424" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="6886424" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 01:47:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="746278898" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="746278898" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 01:47:47 -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 08/42] KVM: Add a helper to notify importers that KVM exported TDP is flushed Date: Sat, 2 Dec 2023 17:18:50 +0800 Message-Id: <20231202091850.13890-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:47:54 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784163051401754443 X-GMAIL-MSGID: 1784163051401754443 Introduce a helper in KVM TDP FD to notify importers that TDP page tables are invalidated. This helper will be called by arch code (e.g. VMX specific code). Currently, the helper will notify all importers of all KVM exported TDPs. Signed-off-by: Yan Zhao --- include/linux/kvm_host.h | 3 +++ virt/kvm/tdp_fd.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index b76919eec9b72..a8af95194767f 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2366,5 +2366,8 @@ static inline int kvm_arch_fault_exported_tdp(struct kvm_exported_tdp *tdp, } #endif /* __KVM_HAVE_ARCH_EXPORTED_TDP */ +void kvm_tdp_fd_flush_notify(struct kvm *kvm, unsigned long gfn, unsigned long npages); + #endif /* CONFIG_HAVE_KVM_EXPORTED_TDP */ + #endif diff --git a/virt/kvm/tdp_fd.c b/virt/kvm/tdp_fd.c index 02c9066391ebe..8c16af685a061 100644 --- a/virt/kvm/tdp_fd.c +++ b/virt/kvm/tdp_fd.c @@ -304,3 +304,41 @@ void kvm_tdp_fd_put(struct kvm_tdp_fd *tdp_fd) fput(tdp_fd->file); } EXPORT_SYMBOL_GPL(kvm_tdp_fd_put); + +static void kvm_tdp_fd_flush(struct kvm_exported_tdp *tdp, unsigned long gfn, + unsigned long npages) +{ +#define INVALID_NPAGES (-1UL) + bool all = (gfn == 0) && (npages == INVALID_NPAGES); + struct kvm_tdp_importer *importer; + unsigned long start, size; + + if (all) { + start = 0; + size = -1UL; + } else { + start = gfn << PAGE_SHIFT; + size = npages << PAGE_SHIFT; + } + + spin_lock(&tdp->importer_lock); + + list_for_each_entry(importer, &tdp->importers, node) { + if (!importer->ops->invalidate) + continue; + + importer->ops->invalidate(importer->data, start, size); + } + spin_unlock(&tdp->importer_lock); +} + +void kvm_tdp_fd_flush_notify(struct kvm *kvm, unsigned long gfn, unsigned long npages) +{ + struct kvm_exported_tdp *tdp; + + spin_lock(&kvm->exported_tdplist_lock); + list_for_each_entry(tdp, &kvm->exported_tdp_list, list_node) + kvm_tdp_fd_flush(tdp, gfn, npages); + spin_unlock(&kvm->exported_tdplist_lock); +} +EXPORT_SYMBOL_GPL(kvm_tdp_fd_flush_notify);