From patchwork Sun Mar 6 22:08:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivam Kumar X-Patchwork-Id: 12770939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2951BC433F5 for ; Sun, 6 Mar 2022 22:15:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234338AbiCFWPw (ORCPT ); Sun, 6 Mar 2022 17:15:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbiCFWPv (ORCPT ); Sun, 6 Mar 2022 17:15:51 -0500 Received: from mx0a-002c1b01.pphosted.com (mx0a-002c1b01.pphosted.com [148.163.151.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 160DA3B570 for ; Sun, 6 Mar 2022 14:14:58 -0800 (PST) Received: from pps.filterd (m0127838.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 226KgSL8001313; Sun, 6 Mar 2022 14:09:41 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=proofpoint20171006; bh=if/hj+iTraekyQCiKkXtNZ566c2zsWNGmGkqJ8r+njw=; b=D5+wIvp3CHJLOktOK5XMl5G83TAp6aHiDnx2nGLrIYhbUAkfXO+S2BBQGgkt28WVjt9y 4UPs0cu0Dd8gyjjvd+S1+mju/1Eu6RsZAQ1AHNy70Wp9Niqsh+9ofLZBicM5IaXlpb1s IDb+rdI369rxTi0Mq3xYOYeczQNA6TIfOYJSeGn/MsloATP7ppNKRSZhXDhjpuqhg8yn q5dqpckLEwotRSK+0iuzwuAYN3NCMqHH7PC5EdkTB78iNC8cq3eA6lkG7gd17bCZc8tt vh0nMm0SCaQjn47ueXUZI6ZsvTBe6/aHe8Hc00GDh/BQxXRwHDfUZGKD3gFu+e9JNjb0 nw== Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2177.outbound.protection.outlook.com [104.47.55.177]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3em8a31w6y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 06 Mar 2022 14:09:41 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NOteJ8cGLc1DEfzH4UhvILH6Wv9q7qtQntCKg7isLqnysIvt3MH3S+PaxJ2sqMw9kgi+BRwb7Mw6Q8Bt7ynHorqnecXh79+t91BmrZbI9Jci/mMznRwWzBowKYp1PUIIou9gr0PBveExLQ5BQaTiM4arRRR2VJm1SXCNIPoDzueWWXpZaQtl7yLQ6dGLoUmheUfIr8iLqFFSo0H+/R9RwlERno7xlqbmowV+aKCBLHyeqGeyu1NH61kd1PMDLPj0aUBuqpixXG6e+DqocVnuCNepLOsZUOK4UjBjceMpUHZKBWGka/r6Y2lTMIK2UR0zuGOxaPH06dtTw1urVvKOOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=if/hj+iTraekyQCiKkXtNZ566c2zsWNGmGkqJ8r+njw=; b=iBFSAv92r5Wld08p7B5X7FWgTVObMpyJDz91JIkzbLmcaP8se+cQWKtCKM5k1SXfBJoOZLIIeTnnMVLB/z2ER9MnCNSE+VdCLeWo02XhVJtpawa7pdn0uvvvmXfYWWtHNrhhXZqli7GJ11IMnMJwwrnMxfH68JER+UvX1fCOV/DSua4rEqWBFON8ORLJC2IbTwNTtwXIT5K5oPwHba0BVex20eFL/2ZaS6dwLV0cWq0KSnQlI77GQ3gmGcoVYfC3ooEWdglk+3J4N+oQHVCpcL/DvzOD1bX+6eZcWXKTAc29S5DB2tw/WggMv3h1GUrjzirGD7wClI6nOWLkcoxJ/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none Received: from CO6PR02MB7555.namprd02.prod.outlook.com (2603:10b6:303:b3::20) by BN6PR02MB3234.namprd02.prod.outlook.com (2603:10b6:405:65::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.15; Sun, 6 Mar 2022 22:09:39 +0000 Received: from CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::88fa:f43f:f4c7:6862]) by CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::88fa:f43f:f4c7:6862%8]) with mapi id 15.20.5038.026; Sun, 6 Mar 2022 22:09:39 +0000 From: Shivam Kumar To: pbonzini@redhat.com, seanjc@google.com Cc: kvm@vger.kernel.org, Shivam Kumar , Shaju Abraham , Manish Mishra , Anurag Madnawat Subject: [PATCH v3 1/3] KVM: Implement dirty quota-based throttling of vcpus Date: Sun, 6 Mar 2022 22:08:48 +0000 Message-Id: <20220306220849.215358-2-shivam.kumar1@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220306220849.215358-1-shivam.kumar1@nutanix.com> References: <20220306220849.215358-1-shivam.kumar1@nutanix.com> X-ClientProxiedBy: SJ0PR05CA0155.namprd05.prod.outlook.com (2603:10b6:a03:339::10) To CO6PR02MB7555.namprd02.prod.outlook.com (2603:10b6:303:b3::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 399f5e3a-cef6-4c46-51f0-08d9ffbe01d0 X-MS-TrafficTypeDiagnostic: BN6PR02MB3234:EE_ X-Microsoft-Antispam-PRVS: x-proofpoint-crosstenant: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ULKw0rRkJQ7BamKsFZcIe4CAqkjNa3otV6kKV/LT5NJCIhTBu60M+EmsWoJAod/CUWE9v+JrDMj4LgRb5iCKg3K8vSc6TgvblbInj+ROm5B2OjcFzNZUQEIJFDlcZqInfMOh9Sy9LSp7FzaqTRNW7bwQLwyyTc3AYp+n6e3Ge+f2zcIhKSh9P0VSmmIfM8QyE0HrWhRNLAo/oe+EsTYT1yl7MoWDImOdb2GQu5C9belZx7WgNsdSyeo4YTAzrUAsI1thyI69GzZFhrpqYIqkqmPH3liUMNH3lXJba02MH94azVMHxEwqnhOwB5bGIzB/LnpctpL5g7bTHqQC0X5cfzC1nTE3K4ktbdkMVHo3/ejmqjNBZ5/QkqFtPUAXX27GQJjS1qGyJaRf3+d62LPWOrFrbybUscoDnTlQxUwVkfVpKex0AYrXs2hEVb/0UpB+A73/fLO0lrSa/8IKU8R7WuoSv7DMYuLIeNgYqOtuW3S4bP4s0elHnSoxlVE88aeL+czo171cjVMdmbAYN98J4FQJAvxzjbf71HD0bzCHZsDEfMC4yZZgAsT/BAEaofto7buCmTRG5f4Iwn79V+4Nl79IiWYwQaUSJvys8SCE3xppxrXcBV5t/lyF6NBFPVIRh1cLQahFtCRxmhQ/TD3m00hA+/xWHi/xjZRzLz+O+fTjAPgG9CNV/EXHplA7hOQMLXZA0a3iAVLhMMoSHd+QjMXqtAfT50Mg20WJRODJXmw= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO6PR02MB7555.namprd02.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(36756003)(2906002)(2616005)(38100700002)(1076003)(316002)(54906003)(8936002)(4326008)(66556008)(66476007)(66946007)(8676002)(508600001)(186003)(26005)(5660300002)(83380400001)(86362001)(6666004)(6506007)(52116002)(15650500001)(6512007)(6486002)(38350700002)(107886003)(14143004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zkwek6/Uqd05gMLGbJU+7Q6ZHV1jtfuob9qYAJXQw/5z110vZN+woxo3jruE++qsel6Mdp0S+d8EgH537JfqL86Mjj2yDtO21gh4DU9n6llVlaRk0k2LV3QslnAgg7Pe9+P0oJwA+c1dgQ3i8NRc17J5UdmBplqCIS1FowPYsoCEiuu9FjoOWCW8l+1D7yNy7N6RD9cLFzJTqdaxGEAGeU8se3kZ3T0VaikEizeZf5gI1ysTEXU0N5VWRCUxP0ArkXBXlhHqNf3txtpXNvYLqjWr8iH/e5awSyznxUx582A9eQ/96nRecOXf/NWeCQDyF6+hu296AgdIMpaxFubRUIq4QjKGRNvu27kSwdPRhJUyyIutVpRYAmrtRSix30QPz1V7G6ql36Kqr5Dwh+2lgdtNvNWuGAhCpUITE2TMFfhgg8FpQ5GfIk5GHyWV3T0iFmkUptRtYtDn58s5ITz++/6A0OK/+KzRX85K8FEj5g9El1UXLiniNXItoQhUJfh/JqBusaU6H1wPayFEMZOLF+FvjwXBTUlwia95b4KXQXhP84AQ6f1KnUFaWJqsl8YHPQTWjqE/4CNDXgNwqxzQhJiccVzwTAMYRIgRNCxC16lQLOvMGxkqD9rXhXEba1KDT2E0AEgJTOkEDjPcuEzCyUBYS7WqvwUZs0QveS/K/ho/Jj2dWtu0SmIYy+gkv+iawn0LWXpxHPIoeSwgUzSTCf0s4kWYYbZBACLT2/MMJKDXWA9iH5qy0VHIeobW25MhQXMAA+u/Eo/wPfcmrjtaw1zAGTmY5RzwtQHatHRJW0NhNHl1uxB1gG94xPszV3LePibZVXB9tsXhriMnFMvcA5vf9Tjn8Pqrw4EYcfbG4RSvKHcCfaNiCarUNRAc2IkPEB7JphwZImqcjx7SCWO3fbe9fNJKyaexKZFiO5q2mt0liV2wKqvCBzhFC1cCoL2r5xSsy2+azAph6StV7fUAnBFtTDGmbN7k2E8zcmaO20jVNBImqDLhpFyFDx7M89R16O65pz572tKxJkcf/QWcKkeHgorOBmziHn02e7a3kr4AvAFibwq1LLp9keZ9iiOU6wehEOVkvPvVSme6IAr1W4hFPDGCtG8MnpuTBBeM0/HC/ZRluI+WdA8DhVT4ohCcWUDuooBznT5Eeot539VVVpaE+0OgmGr4i0D/NOaIAYEOqt6u3Q201oMcryz25Jy5ai4itbmB4yG+a/tTr/m7mmQpDUGv83xQ5emvuGY6hX3RVTBSsm1FuPXQ0jBjKHbrbCdxwhcLkdiG2Vl7/G/pfTOKh+isPnd3maqz9JiC7NvRCE7d1qgCmUP1vKeoirx48YB5hhImdLkOS0Rt4L4+Bn+llpcZ0+PJXvrrdLl7fcr7MBzNq+ea8OexUsZIloBW0tEHdX73iOdzrULcDWPH8vBkccx6bWdaBzKN5C0dnG2esmhkxpQoL6343gioLHC2qGf+prJP4a4NZRDyTZaGleQXrXARu7EoG9+Z9D7LtOErsN3/+ONCO9Igshc75ReseYRpLO8u08tsnARd3ImC73YiRkerTNJhnbwMHCLu93oa2Tw8PAJgZE4VBS1VHc+6eI+rMy+rnTwnXVUc7tWAS5MvSoFK7ABswDwsbUR9MujB10aRtJ5l0aqhCiw2jKsqYk/VfnAsApUq3AIXkrDBgm+BFw1n0E34DTAW+eA7Nck= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 399f5e3a-cef6-4c46-51f0-08d9ffbe01d0 X-MS-Exchange-CrossTenant-AuthSource: CO6PR02MB7555.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2022 22:09:39.0184 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0KdHpFjV69b6QcDMNhZW8VjG80907dcq8F0VyGOLgKZnbWqje0pw0blmZBYJxap5aQS32wA3RbtQFvTZ0xbPl/8EAJzPdf1Xvkwpajuvxeo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR02MB3234 X-Proofpoint-ORIG-GUID: xcs6jnIv7YK4-AvSs04I0v-mRxs7PFpU X-Proofpoint-GUID: xcs6jnIv7YK4-AvSs04I0v-mRxs7PFpU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-06_08,2022-03-04_01,2022-02-23_01 X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Define variables to track and throttle memory dirtying for every vcpu. dirty_count: Number of pages the vcpu has dirtied since its creation, while dirty logging is enabled. dirty_quota: Number of pages the vcpu is allowed to dirty. To dirty more, it needs to request more quota by exiting to userspace. Implement the flow for throttling based on dirty quota. i) Increment dirty_count for the vcpu whenever it dirties a page. ii) Exit to userspace whenever the dirty quota is exhausted (i.e. dirty count equals/exceeds dirty quota) to request more dirty quota. Suggested-by: Shaju Abraham Suggested-by: Manish Mishra Co-developed-by: Anurag Madnawat Signed-off-by: Anurag Madnawat Signed-off-by: Shivam Kumar --- arch/arm64/kvm/arm.c | 3 +++ arch/s390/kvm/kvm-s390.c | 3 +++ arch/x86/kvm/x86.c | 4 ++++ include/linux/kvm_host.h | 15 +++++++++++++++ include/linux/kvm_types.h | 1 + include/uapi/linux/kvm.h | 12 ++++++++++++ virt/kvm/kvm_main.c | 7 ++++++- 7 files changed, 44 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index ecc5958e27fe..5b6a239b83a5 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -848,6 +848,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) ret = 1; run->exit_reason = KVM_EXIT_UNKNOWN; while (ret > 0) { + ret = kvm_vcpu_check_dirty_quota(vcpu); + if (!ret) + break; /* * Check conditions before entering the guest */ diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 2296b1ff1e02..9cc0e0583ef4 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -3994,6 +3994,9 @@ static bool kvm_arch_setup_async_pf(struct kvm_vcpu *vcpu) static int vcpu_pre_run(struct kvm_vcpu *vcpu) { int rc, cpuflags; + rc = kvm_vcpu_check_dirty_quota(vcpu); + if (!rc) + return -EREMOTE; /* * On s390 notifications for arriving pages will be delivered directly diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index eb4029660bd9..0b35b8cc0274 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10257,6 +10257,10 @@ static int vcpu_run(struct kvm_vcpu *vcpu) vcpu->arch.l1tf_flush_l1d = true; for (;;) { + r = kvm_vcpu_check_dirty_quota(vcpu); + if (!r) + break; + if (kvm_vcpu_running(vcpu)) { r = vcpu_enter_guest(vcpu); } else { diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index f11039944c08..b1c599c78c42 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -530,6 +530,21 @@ static inline int kvm_vcpu_exiting_guest_mode(struct kvm_vcpu *vcpu) return cmpxchg(&vcpu->mode, IN_GUEST_MODE, EXITING_GUEST_MODE); } +static inline int kvm_vcpu_check_dirty_quota(struct kvm_vcpu *vcpu) +{ + u64 dirty_quota = READ_ONCE(vcpu->run->dirty_quota); + u64 pages_dirtied = vcpu->stat.generic.pages_dirtied; + struct kvm_run *run = vcpu->run; + + if (!dirty_quota || (pages_dirtied < dirty_quota)) + return 1; + + run->exit_reason = KVM_EXIT_DIRTY_QUOTA_EXHAUSTED; + run->dirty_quota_exit.count = pages_dirtied; + run->dirty_quota_exit.quota = dirty_quota; + return 0; +} + /* * Some of the bitops functions do not support too long bitmaps. * This number must be determined not to exceed such limits. diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h index dceac12c1ce5..7f42486b0405 100644 --- a/include/linux/kvm_types.h +++ b/include/linux/kvm_types.h @@ -106,6 +106,7 @@ struct kvm_vcpu_stat_generic { u64 halt_poll_fail_hist[HALT_POLL_HIST_COUNT]; u64 halt_wait_hist[HALT_POLL_HIST_COUNT]; u64 blocking; + u64 pages_dirtied; }; #define KVM_STATS_NAME_SIZE 48 diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 507ee1f2aa96..1d9531efe1fb 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -270,6 +270,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_DIRTY_QUOTA_EXHAUSTED 36 /* For KVM_EXIT_INTERNAL_ERROR */ /* Emulate instruction failed. */ @@ -487,6 +488,11 @@ struct kvm_run { unsigned long args[6]; unsigned long ret[2]; } riscv_sbi; + /* KVM_EXIT_DIRTY_QUOTA_EXHAUSTED */ + struct { + __u64 count; + __u64 quota; + } dirty_quota_exit; /* Fix the size of the union. */ char padding[256]; }; @@ -508,6 +514,12 @@ struct kvm_run { struct kvm_sync_regs regs; char padding[SYNC_REGS_SIZE_BYTES]; } s; + /* + * Number of pages the vCPU is allowed to have dirtied over its entire + * liftime. KVM_RUN exits with KVM_EXIT_DIRTY_QUOTA_EXHAUSTED if the + * quota is reached/exceeded. + */ + __u64 dirty_quota; }; /* for KVM_REGISTER_COALESCED_MMIO / KVM_UNREGISTER_COALESCED_MMIO */ diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 0afc016cc54d..041ab464405d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3163,7 +3163,12 @@ void mark_page_dirty_in_slot(struct kvm *kvm, return; #endif - if (memslot && kvm_slot_dirty_track_enabled(memslot)) { + if (!memslot) + return; + + vcpu->stat.generic.pages_dirtied++; + + if (kvm_slot_dirty_track_enabled(memslot)) { unsigned long rel_gfn = gfn - memslot->base_gfn; u32 slot = (memslot->as_id << 16) | memslot->id; From patchwork Sun Mar 6 22:08:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivam Kumar X-Patchwork-Id: 12770940 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70CB8C433F5 for ; Sun, 6 Mar 2022 22:26:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234358AbiCFW1k (ORCPT ); Sun, 6 Mar 2022 17:27:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbiCFW1k (ORCPT ); Sun, 6 Mar 2022 17:27:40 -0500 Received: from mx0a-002c1b01.pphosted.com (mx0a-002c1b01.pphosted.com [148.163.151.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADEC222BEC for ; Sun, 6 Mar 2022 14:26:46 -0800 (PST) Received: from pps.filterd (m0127838.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 226KgSLd001313; Sun, 6 Mar 2022 14:26:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=proofpoint20171006; bh=g0zbLYBp2ImP7dhDo3S5jCO3iU9GcYtXYu0GdrBigv8=; b=JyN1Am0B2NWWL2w4zsCleg429gs+KpQNJx3bjUa6E1VgRPTq9wHkhirAKF636oxsvpCp tz8y266dvdSUuG9jVgkvuUvE7G3KhDE2Lt0H584UJ26OVRyOnpB+D1xUzXswjxFeFR14 oEI8Tf/Z8juWpAlF77eg+G+dpuJN3LIdEaTzmrBI8hHJuDi6B4uOSARqyZPMx13GolEK EvLBstIk8aJCK1hvGvSF3QeHF/6L7ehUsMXDmLA6pfZf7Wxd1j33QBSS7d4B+wp8awqR nYHGkiWUQEZjjDHNPDs+biSQFLVwygo91emZT2mWYwd3+4PdAK57kAqN+y338YeuGywo LA== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2172.outbound.protection.outlook.com [104.47.59.172]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3em8a31wmn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 06 Mar 2022 14:26:39 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KXuFneBU9nQSKNivJ64ud2x4eYNoxN73IUSPrKoion0RHL/5BTc+VLLcTlf93zmyxntWS0CuwSS1iDEJcjvw/5vNU7a1+z8e4snDV2ZGlr0bpdO5qC8ZyQ7LcMrAFCy9DqpVnZYSQUC+ZFRi02NcC1+4bItiBCVf8UEOmrDbVdDO0DP68NUO4boJTEWdXXbUYXtilkWiRFFE3OUp59ZUt1UlJgyClyjCVvdIvo9MIqVvdqt1zXQMa1+19vggiUoAtU2RwqFnNxTNw542hmrpjOvDkVNpdgO2NZgH0jT0gaX3cxUkcrq/6d9oWxe0EKZixIuB8oeGRGP/QfyYFvta+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=g0zbLYBp2ImP7dhDo3S5jCO3iU9GcYtXYu0GdrBigv8=; b=nv0wjjbUdb3xx3b3JNGqL6TGm9DJKCSaWJkyTjqmkEiQrNBEIBQCnvM1wCwPDXwnZ4aDUEF6O7K3qOQkFVag36t5tBI4cNHb8UBLSsUs52aD9Dw6qMjXDDgRvwtO7nQfIpjl0Nn/8IEd37/ODWPXoybMKC4GdjnI0Sj6LEVmd7IgRbHPQuzkd3qsOj6sd25n8OLXwyi1154JcI+XzhGZI/Amf2uIgjuleeVu+9c/D0pdDaExsy5d7kK3qeZ45OqGpp5HVGsnxhQyM/oGRzbDzQ/smaFG1uji6MTwGVEyx/t3WMdEedVleV3oPoK27vJIG19xx2D0meND9jB/nwpcOw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none Received: from CO6PR02MB7555.namprd02.prod.outlook.com (2603:10b6:303:b3::20) by BYAPR02MB5495.namprd02.prod.outlook.com (2603:10b6:a03:95::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Sun, 6 Mar 2022 22:10:35 +0000 Received: from CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::88fa:f43f:f4c7:6862]) by CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::88fa:f43f:f4c7:6862%8]) with mapi id 15.20.5038.026; Sun, 6 Mar 2022 22:10:34 +0000 From: Shivam Kumar To: pbonzini@redhat.com, seanjc@google.com Cc: kvm@vger.kernel.org, Shivam Kumar , Shaju Abraham , Manish Mishra , Anurag Madnawat Subject: [PATCH v3 2/3] KVM: Documentation: Update kvm_run structure for dirty quota Date: Sun, 6 Mar 2022 22:08:50 +0000 Message-Id: <20220306220849.215358-3-shivam.kumar1@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220306220849.215358-1-shivam.kumar1@nutanix.com> References: <20220306220849.215358-1-shivam.kumar1@nutanix.com> X-ClientProxiedBy: SJ0PR05CA0155.namprd05.prod.outlook.com (2603:10b6:a03:339::10) To CO6PR02MB7555.namprd02.prod.outlook.com (2603:10b6:303:b3::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2dd07f2d-31cc-4584-c217-08d9ffbe22f8 X-MS-TrafficTypeDiagnostic: BYAPR02MB5495:EE_ X-Microsoft-Antispam-PRVS: x-proofpoint-crosstenant: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: riwV37A3GH3mvZpXcxec940srT+NMVyy54QyYuvB6ZqPAZ6R6+SqInVIPsSzaPrJdOLTUvFrDFS2e9Gnp25+cgR83o15OUFP/0D80MaHY5DUbEL+/BOZbQQOkqH1cfg+NLsJPEM6U5Yk/CXGPKP4BNHTolSF418gpjEGxKBBSivKt+3VPC7qGcxkTwPr0i64x8rosTSYi3vz7BPRkCaq+Li8vdYFMjduQ9VcVrbNJfs5v9p/KKB9gns2Cvsa5t5VcSoxyza9Ew1u5NPxguxcXWZ43vkLQKBx0Fvx5lquu47g1S8/TVPFwHOS2iseju4Pps+YQyfIH2O9zw/Zu8jd9CO4xSO97Kq/5XEFUDFdiYa8R0Vhw2O0Y5/Ea/ZidmWcXtALPCabJt9bXtzkDcTAipcYhwZG8E5mFT2vb9IW/RH97I1BLS4v1ik3f2ryFK17fxwVgNDZAUY75wPaRM0enN1/f0toZCnm6h83i4EfQQcnXxoZTo6hScFJCLC5n7hhzQqshWJY0H9V4Gj93QzSWsOMGUyfibw8Eq+yrH3hQcxBJVjvRAgizwZA7anI+dI7TOjizkd/cu/G/h+HJCRYIJAhlDTk3MXmqfrHW6KdXzJ5dWGI6Vcj5xgzoTtZCYe1JIbgpbRwgZvbl5OZsljxC+9fzaaxF/QJMUrqx9GUBvAuPmZFFtV84+oRKfTHTl4opVP0hbnmBlPQAUTkT2HzovlgI77dN0e+NDwLUNiTc4ihmrFnNgPkVrpCl7uT5ADk9RIuKxY14gT/T42StNlabx3YEk3YMa76757kdnnc5jVXDpECALkiYa1Pid1K6IPF X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO6PR02MB7555.namprd02.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(5660300002)(15650500001)(86362001)(2906002)(508600001)(8676002)(66476007)(66556008)(4326008)(6512007)(6486002)(6666004)(8936002)(6506007)(966005)(66946007)(83380400001)(52116002)(107886003)(54906003)(38350700002)(1076003)(186003)(26005)(36756003)(2616005)(38100700002)(316002)(14143004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IQIL8bJ8tWhsw7aKTQsXTZFj2VMK+OCTh2mucUy5Wnw8pad8paOooZNIHc4iTOtCciZzHOl9JwmPzmTq2ECtUJVLWN0cqJ21mmuIgpKLQYSR3q2cBkJzoUqS+g3lZCE18icwKWrPgW5no8jJ4Twl3ejNVBcvf30FOxO/rZGp3aedeq7Q5n+9ovnkDbD6GocaToaTzCBYrmYlfXjU5BTHmNiY3nCn9CCr1E9CaE25XXLn3Q8crldMABxvlbgyB3rJv9sJwBORGbpEM7D/hEqtR48S5HCoI9yL0x04T2Ut6EtfNAIj4uhaEhWqavmUWULe0UPyJKZ1vJ1s/omxmfLOtyM+lEu+iW9tZicsOQmNgw2jdet4HeMr5MZKDyPOiKeTVGuPI5bjhSssjV35SUFP1EQbSCfPB60QzGcPVDmCjinWj5eoBZwm7HkUteNnolyMnGe8bndrrL2hj/MDyxSA0/FYYwu2+OiiWDNA7SjxPFYEOY92bC0IrDvlreJ7nWkEVmvlp4MPMj+eUQjO8NAgz4emaSmR9Oeqqiewayn0ewE1Cdc6hIcH7U5hWsp+C2t8zx8/7879uVhTnakWS54Fpt7k8eqczy/UP9oKUGfpuoy35x10wZRW49Y5tOHhiy/ahJJ5kZaqQG+n6pLS2dd3Z69OKV0z1RNaJyz1/SALrq/05ehG8rhmBNGQSlEW1BzMaYmp89iUwBbmhIhiTGCgR0Eb6u3dvWg9/eRd/kdsjL+C1Vx4d7o/OM3/F5sxcM2w5dAX7KAgh78MtJ8ys4nL+qI2ECkisBYGwIahwWJaCZVvElFKzLLqzmJWIlgBfV+v8csCFrdLrsvC9rkRRfxvjg6YJ0f2gh1Vl+JVmx0yLp4NUSbe9iHrCoA5XvpVterpGOxRm9nzZ5G0Xhf5Uihq9txTWGH+GQq3RpmNIDSFg0DhEqrnoms+TvTFEbRYTbMsX6weu7KBiVd0LFAtSJgh4uk6Hi1i6vZWP2AjWmW+c4enzBiSSZeYJ7jz33Z6QfptNw8ZV2cxCiTpNUo5okIqu4+mIZJ4aL+XQ0X00xfYnlqlTtHmWzYpsjLUcZ/Y+rDbm03JtcDfUcqn0DFVziyjpdvkaQMcEcIRV+0E+N1buJmTuJvpMXPok+6YbLzx5TvWnt7OLFlb5eV/FJjzMSG6z0d3dCA7OM8E3+MmLiRLdPNFvdPLtzvcgFY2RWeCxutb/WyftnHnhJQ/AROM+Di9UB7rqbh/wKZUR+8RY+SYzKHuyauJJiPKuPa5kBvj7Kappzzq9p4iSpIXBhJir4obbFfEBVaOVYdrr8QFuPT2DrNl66k0bNunrbl6hyp3Qo6PIj1XpcuFihXdJ/AqCjXVLW1q88Wc0nJsApBkTFDu/7AXUcbBvQp8onnOvMIDtGfXwiQIKgOqjP/Tpg8dTziz8o3FNiuhmsoP+tWKlXQKsWqFY8WMhkpswLa1WEgswqqv20Vr+ja0eNoahwHTnGbf732cWB2LG+Q0ktGiqrxfUUNk2Bh38DnjJFQyQCMRPRlV3gtI69tl6GHDnD4URrpRNAAf6A9YOPaLoeG3W2k0NwLSF8kcA9toVJlgqj6d9mipelOnjKgamqjWdIG6IHPD1YNKIzG5Rs+i3LyM4YimmUDUKt+wyngNxh4N5nq0E2LgCRdVB0j/aLBW8jWVObR3daZ6PoMLpk+s4qWzyxFacLs= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2dd07f2d-31cc-4584-c217-08d9ffbe22f8 X-MS-Exchange-CrossTenant-AuthSource: CO6PR02MB7555.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2022 22:10:34.6482 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tUx1lHLmBe7IgvawQUDm9tud5Q+JIzlAooISUsanT7pz6NNhlbWbEkPCIaJGhgnq3GtbZAzTcXvvGHbclwdaYoDjmhHLi6Cd4V1D4akFs20= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR02MB5495 X-Proofpoint-ORIG-GUID: vzQQoxGSb37aKNB6U8kyTLwcW-WYTYJT X-Proofpoint-GUID: vzQQoxGSb37aKNB6U8kyTLwcW-WYTYJT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-06_08,2022-03-04_01,2022-02-23_01 X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Update the kvm_run structure with a brief description of dirty quota members and how dirty quota throttling works. Suggested-by: Shaju Abraham Suggested-by: Manish Mishra Co-developed-by: Anurag Madnawat Signed-off-by: Anurag Madnawat Signed-off-by: Shivam Kumar --- Documentation/virt/kvm/api.rst | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 9f3172376ec3..50e001473b1f 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -6125,6 +6125,23 @@ array field represents return values. The userspace should update the return values of SBI call before resuming the VCPU. For more details on RISC-V SBI spec refer, https://github.com/riscv/riscv-sbi-doc. +:: + + /* KVM_EXIT_DIRTY_QUOTA_EXHAUSTED */ + struct { + __u64 count; + __u64 quota; + } dirty_quota_exit; +If exit reason is KVM_EXIT_DIRTY_QUOTA_EXHAUSTED, it indicates that the VCPU has +exhausted its dirty quota. The 'dirty_quota_exit' member of kvm_run structure +makes the following information available to the userspace: + 'count' field: the current count of pages dirtied by the VCPU, + 'quota' field: the observed dirty quota just before the exit to userspace. +The userspace can design a strategy to allocate the overall scope of dirtying +for the VM among the vcpus. Based on the strategy and the current state of dirty +quota throttling, the userspace can make a decision to either update (increase) +the quota or to put the VCPU to sleep for some time. + :: /* Fix the size of the union. */ @@ -6159,6 +6176,17 @@ values in kvm_run even if the corresponding bit in kvm_dirty_regs is not set. :: + /* + * Number of pages the vCPU is allowed to have dirtied over its entire + * lifetime. KVM_RUN exits with KVM_EXIT_DIRTY_QUOTA_EXHAUSTED if the quota + * is reached/exceeded. + */ + __u64 dirty_quota; +Please note that this quota cannot be strictly enforced if PML is enabled, and +the VCPU may end up dirtying pages more than its quota. The difference however +is bounded by the PML buffer size. + +:: }; From patchwork Sun Mar 6 22:08:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivam Kumar X-Patchwork-Id: 12770948 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95C6CC433F5 for ; Sun, 6 Mar 2022 22:43:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234392AbiCFWoE (ORCPT ); Sun, 6 Mar 2022 17:44:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231361AbiCFWoD (ORCPT ); Sun, 6 Mar 2022 17:44:03 -0500 X-Greylist: delayed 1914 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 06 Mar 2022 14:43:10 PST Received: from mx0b-002c1b01.pphosted.com (mx0b-002c1b01.pphosted.com [148.163.155.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CF83329B7 for ; Sun, 6 Mar 2022 14:43:10 -0800 (PST) Received: from pps.filterd (m0127844.ppops.net [127.0.0.1]) by mx0b-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 226KbxBp011928; Sun, 6 Mar 2022 14:11:13 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=proofpoint20171006; bh=2se+xk3aWAhcZZ2B2hIF5uaud4QQgZ/Fchj7rN7SAgA=; b=C8CBVF9ABdZHxkfSeA9rMAxNSDaCpXm4IhbAdWnft4eOGkhJ1TlBdKotWB/NA1KylJqH jGYGWbbSHsjOoY5JgMbdOqBPkbqucwXkwdQbrOU2cJlaCl77gJhNuKDQ6TZdZsU93YJC 7DlvBjL7ZYOUE+CnJ/KjL+d1qanUJg2Og/AlDCX5GkL6Il3+9/KX8nhmrmGMfcJ/MZVg bZT+PQZJPXH5RhPSNBeVCoSmJr7JS3G13EugwKE0ohNte7EHKGsqMv6M4FIBKCQ1d29M pv8tBXDzOdYTZCxkomMOvywRHIuMepfu0mqz0sWH7Q5Kfn6BtI+U6GvLHAKQyOHq6wL+ OA== Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2172.outbound.protection.outlook.com [104.47.57.172]) by mx0b-002c1b01.pphosted.com (PPS) with ESMTPS id 3em894hwhn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 06 Mar 2022 14:11:13 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YViYwp4PGZ7Hqz2pddvcFTcc9QJOLiGaF1TvNPoVU5A3z+T9HX32AWPP9M/ccgBQSDK3NHYwVDEC5/9CHUamxfLRUUUyEB99rBOuPNHq1ttoS91iAkXsY2Y8KWCHHj3y0+kNG63ajU8m0S6FER1zrLAYTjSwBYcMvd/W/e3yNZJwg6FJzLPcHbLIPE/9HRTc8o7zqA0b58bQi5PKNm+4QXJ2Zog78TtltN+yt/e0+eQ/F3dM7aZwvqHahT5rxDh66xhY7SJw36mPKyvWahkh3bDhYVdbAwTzyupVBdWjJaama2uu+6Ovqogl2Ew/0YDtMkiu8epP/BQN6IjFfgM86Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2se+xk3aWAhcZZ2B2hIF5uaud4QQgZ/Fchj7rN7SAgA=; b=f6F5z0y8J9EsDH/NmyY5wgBJcSC9jDUarJjUUyQqo5WiW/opYjXK4Df6aQNZOvupe5T9YDREvPi60S449XYU+tUTjk0GDYJzEX17wVP5kkoDhBX3BnNcZE6j+axIARCVY48eG9OSKYyaQ71OcVHFAOcO5vZ8pODL0z37dkMKwDmoexEttygCpI8IpbUb8vpTuKZrojnt4VdP++3Mg0B4JzKztQUdc1fCjxy/Zq/uhScxG7FeZGsHkpSecvqOBbQYbp2ziS3UsXiRCCrGFrvynj1gZLtFVIeFlyqvwWtbYKqaj42Bx1bWdex1BSNMGUUSkoqKp+I9RqGPSJ4/+k5l/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none Received: from CO6PR02MB7555.namprd02.prod.outlook.com (2603:10b6:303:b3::20) by BYAPR02MB5495.namprd02.prod.outlook.com (2603:10b6:a03:95::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Sun, 6 Mar 2022 22:11:11 +0000 Received: from CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::88fa:f43f:f4c7:6862]) by CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::88fa:f43f:f4c7:6862%8]) with mapi id 15.20.5038.026; Sun, 6 Mar 2022 22:11:11 +0000 From: Shivam Kumar To: pbonzini@redhat.com, seanjc@google.com Cc: kvm@vger.kernel.org, Shivam Kumar , Shaju Abraham , Manish Mishra , Anurag Madnawat Subject: [PATCH v3 3/3] KVM: selftests: Add selftests for dirty quota throttling Date: Sun, 6 Mar 2022 22:08:52 +0000 Message-Id: <20220306220849.215358-4-shivam.kumar1@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220306220849.215358-1-shivam.kumar1@nutanix.com> References: <20220306220849.215358-1-shivam.kumar1@nutanix.com> X-ClientProxiedBy: SJ0PR05CA0155.namprd05.prod.outlook.com (2603:10b6:a03:339::10) To CO6PR02MB7555.namprd02.prod.outlook.com (2603:10b6:303:b3::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7d64c25c-27ea-4acc-2209-08d9ffbe38d2 X-MS-TrafficTypeDiagnostic: BYAPR02MB5495:EE_ X-Microsoft-Antispam-PRVS: x-proofpoint-crosstenant: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3MFpcS0/+TOm5flceujpWuBivBtX/pVsWwv3eDacxFzGkv+iZz/ABO0S9OqpZ66/ZH9wEZQZyQ1kNilTAnKY86HxRGShPtMOislsJrycE98IfO0Zx7qSPqlfPsIjVmpqEI17LPr4nk/lTaNwMP+x6PRKy7E8zRM08Vtq/gr+m6j+KlMm4S9Ibdu5VXYaEdlh+uOj6+4Bd/BjcQMacdsztL5ZUvzwa73077pKGN9muNgpKyOEY8fKw6vfs8aH6D5ZReO9DBXoPNPx3YLFAdouPQCBmKKobFlExrkKAuOyGWa5bETjP1C704rY6drnpvjm4WPdzSIRoozCURxB8OXf+/tOW1UYdINybwBcg+plZKAkgjTI4mTjFkeTaDjQLmiIROmqpw0ae2fInlGGWCH2OazsXGXEmOZcuJUcUcNiPcfKLCgBCyFIEC28XihI+IRKGNQv2RPBfPoflLvRHQa6MXgijwwOIlkugEYfAscMSnFAJtQ13rj1B8PF5P4TI59BfaNyEzUAGufevegQIrFwMrvfK4JXBy1LS8LZNgmYUuGXGQ5ljc/BN51G52+hCVID16C1Qvg+L85WG9//TLYFM50HnlM1Ylcbk/anfpAB8Z9wi5T7WLQcJMewHPAc5be+y+O0VRCpAInXzsbS761J2xGb1d6/OFlUJ3aaE63VecT/ak+zFeqYTo9IVVw0Q7tQyUsj3fHmiqO4UCjXCd9xoG9ZIKMrIIv5dn5uoDj77FM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO6PR02MB7555.namprd02.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(5660300002)(45080400002)(15650500001)(86362001)(2906002)(508600001)(8676002)(66476007)(66556008)(4326008)(6512007)(6486002)(6666004)(8936002)(6506007)(66946007)(83380400001)(52116002)(107886003)(54906003)(38350700002)(1076003)(186003)(26005)(36756003)(2616005)(38100700002)(316002)(14143004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8JnxwxITW+ATFsHicuUC45nyzaQ78iCqYeuacKvjnSfOv2co6BJ3lRdGnVXtgorOLBdbX5yxWWtarIrX2y7KJLzSzi4yO7CMFLuT3C2mWgzHxkb1qBdKWHACMGPn42XcXR9s/OSu2xIl/8mULUqT/yCxXC2Jb1fsD5Y43SnVcSmvddFkvGPWersA/5mHW/3CN78d1gW4sIYz4JTz1JvIsS/y4CXS1Ljl66SEnkEoo41MMVlZwoWfOQpjqzgsnUi7D7VlBbE0HxoakL3FRFfoBDp+9mROYWh/YBoif2374Hei0bcR/l+tkClL9VFQ9QyZRmIcmZLmR0dSfY66fL8rbAjmcf6A7IFO95845c5m9HVXX367AgjmcNi+CGJpcP8rkUo5Hytju3gOgMah3hQ+7fRrAdrioSBrADrq08Sea8M76g4NdBtktl+OhFwDYg5vMpcMSwl+hpLN4jZEhF9gOGARtBbWNe+wTE+ee0AaC0dziDIY22gTzLfpdtyWgYfiP8UDrpyHNSLoBR3juDM57R4cCiFPptXkjISYE/Pitnzek4Tn6SbdsFITfgBuffSkcl0mL1HRcXd9+kNNsHXwJZ2sw4LNtKuc0GmkJJNa2XN0eMkbuUUCQJa7nD9BjYiwDFlAPxqKSLtZ4vzMY1byOj81mEK+xXApp3mMcpLDX5smeLSJ923wpq2xZrbQUVPqJmv7naon1R4iDV68b/DJ3RbkmZpKPjf0nS+C8cHNQm8heZSDgJw/VOnSxH/OyQtboISDn5w0Ulmbd1GvzbZ68q8HRBo9CXGq0fvtDjT4bmns3xGWI/cBGVdrfvEm8tmBsxb3IioAsmEEco0Dk9Yu4uWRGARnWUvXurknMXYZy4NFchGo+ROVYOhV0q3F0ZTE67b799uBPjvO3CLv2klTU5YXE4OUrZC1D7kCYBnkLl9uyFwAYOCgEldSxVWk5qO79rQPCRLgAU8O4mCxcrO+jlBMrQl7ZybWpb8V+8lY3evdBiUFwY4/5pnGfCyu1wIFpi2K5lufmVliR90PgOLMFhwQKtFhMYjDGK2Oc8U82o511yE8kYztQCeCueJxOg572fRmWCeXk+NQspWxUDK9YNILZjbOM0uFNxfP2nadfY2qgo5x6fH9rJINfdfgjoJvzBB4bQyyEbFukn5yt9Btwfu93PIEDmLtn1RZK2jCmJNA72VCWAZ0cbQS5XZvhD8muTIiV12dPUpYCWJ0AQFL+X8ioM+WRkv4mmGqm2Cm4esHtRKEFD/11QnnIcUXm09rxIVeNVgC+ewAUUOL65Tl4QprJ3/urZcTgIDLynsc1HaLLVgy+ncPs8PenuzCX22/FXFm7HAj3j7O6yT0ucdZjDFT53kbSrwHGa7vyBlWx5VXCOP0nltdZfXqkz1t+fYW91XynovUHOiUD4JR1WS2tB+3M4K4IN14hxPee6hfbflimDKKN4pk8qkX0+woYkaFkKEKBwfgLbxa4WGRqBSraOLVeq30Qb+RfjdzVwAzNVXTFFn3Nsw6ISa2IxLiOnfynMwyTQdYYSKJV3tuncfli/HyEfAwZyVKjB6sPf/kv34JJelDBVB8NRES+l+3zf/RR/MU7dJCsXOX3wXWcQqlXAkZwRPDIJI1CAHQOREumlzYmjydi30As6W5kg1spekTVb7wToZiZD0xRn4ZPQk7+HwbKXoDqaycubzYN0BKshU= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7d64c25c-27ea-4acc-2209-08d9ffbe38d2 X-MS-Exchange-CrossTenant-AuthSource: CO6PR02MB7555.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2022 22:11:11.2893 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /7e6VYAzviWyAst7GrkijCVtb6HfglPSPVQlYGO20u8WuvmmSKP9XewoUWZTmwlBE1dETYUSW8hE+y/dXqbXH0VF4e7UvbXt7+y6mAHxa5c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR02MB5495 X-Proofpoint-GUID: EV9UlTZfEI1VCYI9VkTdN-kdf4taSDL0 X-Proofpoint-ORIG-GUID: EV9UlTZfEI1VCYI9VkTdN-kdf4taSDL0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-06_08,2022-03-04_01,2022-02-23_01 X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add selftests for dirty quota throttling with an optional -d parameter to configure by what value dirty quota should be incremented after each dirty quota exit. With very small intervals, a smaller value of dirty quota can ensure that the dirty quota exit code is tested. A zero value disables dirty quota throttling and thus dirty logging, without dirty quota throttling, can be tested. Suggested-by: Shaju Abraham Suggested-by: Manish Mishra Co-developed-by: Anurag Madnawat Signed-off-by: Anurag Madnawat Signed-off-by: Shivam Kumar --- tools/testing/selftests/kvm/dirty_log_test.c | 37 +++++++++++++++++-- .../selftests/kvm/include/kvm_util_base.h | 4 ++ tools/testing/selftests/kvm/lib/kvm_util.c | 36 ++++++++++++++++++ 3 files changed, 73 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 3fcd89e195c7..e75d826e21fb 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -65,6 +65,8 @@ #define SIG_IPI SIGUSR1 +#define TEST_DIRTY_QUOTA_INCREMENT 8 + /* * Guest/Host shared variables. Ensure addr_gva2hva() and/or * sync_global_to/from_guest() are used when accessing from @@ -191,6 +193,7 @@ static enum log_mode_t host_log_mode_option = LOG_MODE_ALL; static enum log_mode_t host_log_mode; static pthread_t vcpu_thread; static uint32_t test_dirty_ring_count = TEST_DIRTY_RING_COUNT; +static uint64_t test_dirty_quota_increment = TEST_DIRTY_QUOTA_INCREMENT; static void vcpu_kick(void) { @@ -210,6 +213,13 @@ static void sem_wait_until(sem_t *sem) while (ret == -1 && errno == EINTR); } +static void set_dirty_quota(struct kvm_vm *vm, uint64_t dirty_quota) +{ + struct kvm_run *run = vcpu_state(vm, VCPU_ID); + + vcpu_set_dirty_quota(run, dirty_quota); +} + static bool clear_log_supported(void) { return kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); @@ -260,9 +270,13 @@ static void default_after_vcpu_run(struct kvm_vm *vm, int ret, int err) TEST_ASSERT(ret == 0 || (ret == -1 && err == EINTR), "vcpu run failed: errno=%d", err); - TEST_ASSERT(get_ucall(vm, VCPU_ID, NULL) == UCALL_SYNC, - "Invalid guest sync status: exit_reason=%s\n", - exit_reason_str(run->exit_reason)); + if (test_dirty_quota_increment && + run->exit_reason == KVM_EXIT_DIRTY_QUOTA_EXHAUSTED) + vcpu_handle_dirty_quota_exit(run, test_dirty_quota_increment); + else + TEST_ASSERT(get_ucall(vm, VCPU_ID, NULL) == UCALL_SYNC, + "Invalid guest sync status: exit_reason=%s\n", + exit_reason_str(run->exit_reason)); vcpu_handle_sync_stop(); } @@ -377,6 +391,9 @@ static void dirty_ring_after_vcpu_run(struct kvm_vm *vm, int ret, int err) if (get_ucall(vm, VCPU_ID, NULL) == UCALL_SYNC) { /* We should allow this to continue */ ; + } else if (test_dirty_quota_increment && + run->exit_reason == KVM_EXIT_DIRTY_QUOTA_EXHAUSTED) { + vcpu_handle_dirty_quota_exit(run, test_dirty_quota_increment); } else if (run->exit_reason == KVM_EXIT_DIRTY_RING_FULL || (ret == -1 && err == EINTR)) { /* Update the flag first before pause */ @@ -773,6 +790,10 @@ static void run_test(enum vm_guest_mode mode, void *arg) sync_global_to_guest(vm, guest_test_virt_mem); sync_global_to_guest(vm, guest_num_pages); + /* Initialise dirty quota */ + if (test_dirty_quota_increment) + set_dirty_quota(vm, test_dirty_quota_increment); + /* Start the iterations */ iteration = 1; sync_global_to_guest(vm, iteration); @@ -814,6 +835,9 @@ static void run_test(enum vm_guest_mode mode, void *arg) /* Tell the vcpu thread to quit */ host_quit = true; log_mode_before_vcpu_join(); + /* Terminate dirty quota throttling */ + if (test_dirty_quota_increment) + set_dirty_quota(vm, 0); pthread_join(vcpu_thread, NULL); pr_info("Total bits checked: dirty (%"PRIu64"), clear (%"PRIu64"), " @@ -835,6 +859,8 @@ static void help(char *name) printf(" -c: specify dirty ring size, in number of entries\n"); printf(" (only useful for dirty-ring test; default: %"PRIu32")\n", TEST_DIRTY_RING_COUNT); + printf(" -q: specify incemental dirty quota (default: %"PRIu32")\n", + TEST_DIRTY_QUOTA_INCREMENT); printf(" -i: specify iteration counts (default: %"PRIu64")\n", TEST_HOST_LOOP_N); printf(" -I: specify interval in ms (default: %"PRIu64" ms)\n", @@ -863,11 +889,14 @@ int main(int argc, char *argv[]) guest_modes_append_default(); - while ((opt = getopt(argc, argv, "c:hi:I:p:m:M:")) != -1) { + while ((opt = getopt(argc, argv, "c:q:hi:I:p:m:M:")) != -1) { switch (opt) { case 'c': test_dirty_ring_count = strtol(optarg, NULL, 10); break; + case 'q': + test_dirty_quota_increment = strtol(optarg, NULL, 10); + break; case 'i': p.iterations = strtol(optarg, NULL, 10); break; diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 4ed6aa049a91..b70732998329 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -395,4 +395,8 @@ int vcpu_get_stats_fd(struct kvm_vm *vm, uint32_t vcpuid); uint32_t guest_get_vcpuid(void); +void vcpu_set_dirty_quota(struct kvm_run *run, uint64_t dirty_quota); +void vcpu_handle_dirty_quota_exit(struct kvm_run *run, + uint64_t test_dirty_quota_increment); + #endif /* SELFTEST_KVM_UTIL_BASE_H */ diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index d8cf851ab119..fa77558d745e 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -19,6 +19,7 @@ #include #define KVM_UTIL_MIN_PFN 2 +#define PML_BUFFER_SIZE 512 static int vcpu_mmap_sz(void); @@ -2286,6 +2287,7 @@ static struct exit_reason { {KVM_EXIT_X86_RDMSR, "RDMSR"}, {KVM_EXIT_X86_WRMSR, "WRMSR"}, {KVM_EXIT_XEN, "XEN"}, + {KVM_EXIT_DIRTY_QUOTA_EXHAUSTED, "DIRTY_QUOTA_EXHAUSTED"}, #ifdef KVM_EXIT_MEMORY_NOT_PRESENT {KVM_EXIT_MEMORY_NOT_PRESENT, "MEMORY_NOT_PRESENT"}, #endif @@ -2517,3 +2519,37 @@ int vcpu_get_stats_fd(struct kvm_vm *vm, uint32_t vcpuid) return ioctl(vcpu->fd, KVM_GET_STATS_FD, NULL); } + +void vcpu_set_dirty_quota(struct kvm_run *run, uint64_t dirty_quota) +{ + run->dirty_quota = dirty_quota; + + if (dirty_quota) + pr_info("Dirty quota throttling enabled with initial quota %"PRIu64"\n", + dirty_quota); + else + pr_info("Dirty quota throttling disabled\n"); +} + +void vcpu_handle_dirty_quota_exit(struct kvm_run *run, + uint64_t test_dirty_quota_increment) +{ + uint64_t quota = run->dirty_quota_exit.quota; + uint64_t count = run->dirty_quota_exit.count; + + /* + * Due to PML, number of pages dirtied by the vcpu can exceed its dirty + * quota by PML buffer size. + */ + TEST_ASSERT(count <= quota + PML_BUFFER_SIZE, "Invalid number of pages + dirtied: count=%"PRIu64", quota=%"PRIu64"\n", count, quota); + + TEST_ASSERT(count >= quota, "Dirty quota exit happened with quota yet to + be exhausted: count=%"PRIu64", quota=%"PRIu64"\n", count, quota); + + if (count > quota) + pr_info("Dirty quota exit with unequal quota and count: + count=%"PRIu64", quota=%"PRIu64"\n", count, quota); + + run->dirty_quota = count + test_dirty_quota_increment; +}