From nobody Sun May 19 17:22:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1690297365; cv=none; d=zohomail.com; s=zohoarc; b=ZvGWMYgzMJnEPXw6dxTK+XLkCRZ0lWsTqJoeoSRFIF8+ntGEf+QjFuiv928ixyjhZVgRxZvo6+pR0x2gpjBDdfmX3+opP0q17hZgpvEeie/HKI80HgfZoRlOlmN3ps/vPj8R8T0BKaLuaLMoC7CMUvwytYgT8oO6ahCNDRWOn28= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690297365; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=iCfHIz0GBvq1V2AVmBH51dgFGGowWJt+HuwEuQVWETA=; b=fDWkbrva0jz4CVRkqbK8glav4Fyc5Tc1obKkFEfTuSfCJT7JKVH+Oye2hvsjPKZmpsjsawqr0tYIHYPJGNdVW7KJy6/diOAx5ubAe6kR2Evh0ks7j9CdGIjrtJEenh4uU5badIx7QiaPtlLORmg293Y9ymXf7BV1H6RScj+qd0c= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690297365357200.84279829550348; Tue, 25 Jul 2023 08:02:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOJY6-0001Xf-BA; Tue, 25 Jul 2023 11:02:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qOJXl-0001Rv-01; Tue, 25 Jul 2023 11:01:56 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qOJXd-0001xV-KL; Tue, 25 Jul 2023 11:01:40 -0400 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4R9Kr04P0Cz6GD6B; Tue, 25 Jul 2023 22:57:04 +0800 (CST) Received: from A2006125610.china.huawei.com (10.202.227.178) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 25 Jul 2023 16:01:19 +0100 To: , CC: , , , , Subject: [RFC PATCH] arm/kvm: Enable support for KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE Date: Tue, 25 Jul 2023 16:00:02 +0100 Message-ID: <20230725150002.621-1-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.202.227.178] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.176.79.56; envelope-from=shameerali.kolothum.thodi@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) AC_FROM_MANY_DOTS=2.999, BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Shameer Kolothum From: Shameer Kolothum via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1690297416715100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that we have Eager Page Split support added for ARM in the kernel[0], enable it in Qemu. This adds, -eager-split-size to Qemu options to set the eager page split chunk size. -enable KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE. The chunk size specifies how many pages to break at a time, using a single allocation. Bigger the chunk size, more pages need to be allocated ahead of time. Notes: - I am not sure whether we need to call kvm_vm_check_extension() for KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE or not as kernel seems to disable eager page size by default and it will return zero always. -ToDo: Update qemu-options.hx [0]: https://lore.kernel.org/all/168426111477.3193133.10748106199843780930.= b4-ty@linux.dev/ Signed-off-by: Shameer Kolothum --- include/sysemu/kvm_int.h | 1 + target/arm/kvm.c | 73 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index 511b42bde5..03a1660d40 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -116,6 +116,7 @@ struct KVMState uint64_t kvm_dirty_ring_bytes; /* Size of the per-vcpu dirty ring */ uint32_t kvm_dirty_ring_size; /* Number of dirty GFNs per ring */ bool kvm_dirty_ring_with_bitmap; + uint64_t kvm_eager_split_size; /* Eager Page Splitting chunk size */ struct KVMDirtyRingReaper reaper; NotifyVmexitOption notify_vmexit; uint32_t notify_window; diff --git a/target/arm/kvm.c b/target/arm/kvm.c index b4c7654f49..985d901062 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -30,6 +30,7 @@ #include "exec/address-spaces.h" #include "hw/boards.h" #include "hw/irq.h" +#include "qapi/visitor.h" #include "qemu/log.h" =20 const KVMCapabilityInfo kvm_arch_required_capabilities[] =3D { @@ -247,6 +248,23 @@ int kvm_arm_get_max_vm_ipa_size(MachineState *ms, bool= *fixed_ipa) return ret > 0 ? ret : 40; } =20 +static bool kvm_arm_eager_split_size_valid(uint64_t req_size, uint32_t siz= es) +{ + int i; + + for (i =3D 0; i < sizeof(uint32_t) * BITS_PER_BYTE; i++) { + if (!(sizes & (1 << i))) { + continue; + } + + if (req_size =3D=3D (1 << i)) { + return true; + } + } + + return false; +} + int kvm_arch_init(MachineState *ms, KVMState *s) { int ret =3D 0; @@ -280,6 +298,21 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } } =20 + if (s->kvm_eager_split_size) { + uint32_t sizes; + + sizes =3D kvm_vm_check_extension(s, KVM_CAP_ARM_SUPPORTED_BLOCK_SI= ZES); + if (!sizes) { + error_report("Eager Page Split not supported on host"); + } else if (!kvm_arm_eager_split_size_valid(s->kvm_eager_split_size, + sizes)) { + error_report("Eager Page Split requested chunk size not valid"= ); + } else if (kvm_vm_enable_cap(s, KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE= , 0, + s->kvm_eager_split_size)) { + error_report("Failed to set Eager Page Split chunk size"); + } + } + kvm_arm_init_debug(s); =20 return ret; @@ -1062,6 +1095,46 @@ bool kvm_arch_cpu_check_are_resettable(void) return true; } =20 +static void kvm_arch_get_eager_split_size(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + KVMState *s =3D KVM_STATE(obj); + uint64_t value =3D s->kvm_eager_split_size; + + visit_type_size(v, name, &value, errp); +} + +static void kvm_arch_set_eager_split_size(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + KVMState *s =3D KVM_STATE(obj); + uint64_t value; + + if (s->fd !=3D -1) { + error_setg(errp, "Cannot set properties after the accelerator has = been initialized"); + return; + } + + if (!visit_type_size(v, name, &value, errp)) { + return; + } + + if (value & (value - 1)) { + error_setg(errp, "early-split-size must be a power of two."); + return; + } + + s->kvm_eager_split_size =3D value; +} + void kvm_arch_accel_class_init(ObjectClass *oc) { + object_class_property_add(oc, "eager-split-size", "size", + kvm_arch_get_eager_split_size, + kvm_arch_set_eager_split_size, NULL, NULL); + + object_class_property_set_description(oc, "eager-split-size", + "Configure Eager Page Split chunk size for hugepages. (default: 0,= disabled)"); } --=20 2.34.1