From patchwork Sat May 21 20:29:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivam Kumar X-Patchwork-Id: 12858009 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 F0EEBC433EF for ; Sat, 21 May 2022 20:31:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345356AbiEUUbK (ORCPT ); Sat, 21 May 2022 16:31:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345777AbiEUUbA (ORCPT ); Sat, 21 May 2022 16:31:00 -0400 Received: from mx0a-002c1b01.pphosted.com (mx0a-002c1b01.pphosted.com [148.163.151.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10A6BE01D for ; Sat, 21 May 2022 13:30:54 -0700 (PDT) Received: from pps.filterd (m0127839.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24LBP5tQ019024; Sat, 21 May 2022 13:30:37 -0700 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=zFeKGVAiz/bAbgKGBfPzVyn68FWsyXaNHNJZULGfkLg=; b=Bb2N+1Klkmpi+GGAEBLvurxPQ6UrcPMWu5yzKH08XP+6NXYyjp/Mm7Uqsj5CBtNbWf4b 0ruZjFdFmGjfuPvsudNrUYyV8AqcWAYR60rgGYKs8tUhX2tQjYRVs8hJqa0V7ZToj2Ar ER772l12SgE42Kq6HE6K/rtNnnUNTKGwImExP0qyt17u3HIZK+9RwJxqTkIvxegF0Cm8 MAHOd1SvmBjE/pxHCyIHfP/eaRkOFX93eLU9ddbTGqbxwAUO5dwjmgBlm/u4NqJmmf7M AO5Zil9uJG62XbQltiIOGzEP04+Dm0e0BSx1jgTIEJy05cVmnrvvgADw45H/GQgurp8q ug== Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3g6y5e8gpn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 21 May 2022 13:30:36 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kSyn9HQj0lFx5NKqhrg7nX20HiuttD1o9l/gjarjJUhT3RYk1lgVt6sCzwVEHj/ADX3Xjy6Da73zntHmTeokRJfPbAdrQdd6kRkb3/jLquQRO5J5+596wEGSlMktszV7A773O+ovLh3jU7azUvcAODJs4FZLkhqzDh8ftk2tQxys6LTQRQaaYcPH18LeMFBBSApNuBzEnsaOXHr0d1wLwlYwrXPDpcZHiiF/9HdJQP11VvKLwVjNZEe47usnfCMvFAKsyEmlNqq3M+y/P7kMYs5ih1KA7DJ8mfZT2+AGymaVoWApIp84mmNwNzLW351xZ34pn5D0+8oOfpwwm6HZyw== 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=zFeKGVAiz/bAbgKGBfPzVyn68FWsyXaNHNJZULGfkLg=; b=J34BX+izasNA9/6TPdLX6ffMbi1wP34Mi8Um/i/wcY3Y21brXa7IaP4Gd+OakYOrtyT9MPhMbKdvMGFVJEdjwI+vH0zC95fQvraDJis/kO2SP168q4tDPX8CRB6s5e5MrLJPJX6V/MHuIQTEKAUtwFIucocbdubsR1NZbBR3rs8HjtEDaOcMizTA1Ucsos+2SfJbl0M4lGL8SJjB71rYNBfboTiHTzXY25kmVqUAR2PHldih7xzogrEMAXDezbOceNwrSKCh5DXRDXIxqEW9XW0XSD5W0I3Vnl79/DkCD345f+tI0LPG5jAVcaiYz9nU18H3QlMWMIX2fUl2eM/ekA== 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 SN6PR02MB4319.namprd02.prod.outlook.com (2603:10b6:805:ac::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.19; Sat, 21 May 2022 20:30:34 +0000 Received: from CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::6819:797c:706f:9a01]) by CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::6819:797c:706f:9a01%6]) with mapi id 15.20.5273.021; Sat, 21 May 2022 20:30:34 +0000 From: Shivam Kumar To: pbonzini@redhat.com, seanjc@google.com, maz@kernel.org, james.morse@arm.com, borntraeger@linux.ibm.com, david@redhat.com Cc: kvm@vger.kernel.org, Shivam Kumar , Shaju Abraham , Manish Mishra , Anurag Madnawat Subject: [PATCH v4 1/4] KVM: Implement dirty quota-based throttling of vcpus Date: Sat, 21 May 2022 20:29:36 +0000 Message-Id: <20220521202937.184189-2-shivam.kumar1@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220521202937.184189-1-shivam.kumar1@nutanix.com> References: <20220521202937.184189-1-shivam.kumar1@nutanix.com> X-ClientProxiedBy: SJ0PR05CA0064.namprd05.prod.outlook.com (2603:10b6:a03:332::9) 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: 10c4c8b0-d38f-4359-022d-08da3b68c1f0 X-MS-TrafficTypeDiagnostic: SN6PR02MB4319: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: t/ZSkaJeDJiU85gMteRqtF+W4Q9qZB7anQRonfrhaxgkpn0J9VsPM+ss3Mn9B8Iz7Wur3P50ODbv2yib7y2gSifOZweJRY+MhLk9l0IHCUhnDcKWghemwe24+I3pFaEifaOAXTUe0EvR055jW8+YVMsBMYdcvssC6NrIF5CtQLDWk6Lv8cvwj0x8qFhAPJmcakECwG4faXNpzByqAmgDQ+6v7VRphoKx2bSYteEIA1ozSlRV6cfGttmlEXSmGWcLiljioUoRMFWwPYJ/3L0+2ufiH6qYJrCMr+6tQNGQUuw1b/5JmgUDWRuU0qxaD0+7rJ9iapuPleQ4aLbQqjM/cD/YmUeYx+cKqkiYfax1s4HommBd6HKPCkUQ3BIBabZyjZlfrUNwK/hcy6XgZhuKe8j+x5xCb+CWiMi9Inm4p+14ExQmnkzc4oHRRk88zohYOyc/0NjdvyplVAsr/cV5cF2Be+Zue82bzWKBlxwOJUOFq6Wm4VHXiNhEF4KDjKyoI4xmYtRm97CsDTNuxbOA4PksEdtL+YhBvCsxyT5/WHklPjy5NQ2ImiMPBHuknXxJ70GOp0atxscX323M6zdMv5uNnpyXYuzwyN48jVaDOJ/MhPsDV9ftXhrXzvRZ7HighdAXY/mCzEehUyY7ZvnXk9h+e0cQdv7EjsLPlgKA2oxpSW4TeG8PtxK9XRijBvTrL/yA1l+FATaeQZOK7ZgCYvf6F/00fycp+07KOjWIs05pjkTrs0jgTPtCUmKs0cBYPLjSiUcDZngXpn3r1dWb1IfujOjEyE7pNL51PgVuyms= 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)(15650500001)(52116002)(66476007)(66946007)(66556008)(2906002)(8936002)(5660300002)(508600001)(4326008)(966005)(6486002)(36756003)(86362001)(8676002)(6506007)(6512007)(316002)(54906003)(1076003)(83380400001)(107886003)(186003)(38100700002)(38350700002)(26005)(2616005)(14143004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LkEklDZVDb/57Va7MyIbhaKT8BjAN1fTpbJim+um9GlCvYF9hltXWV/WH3In1hWRAejiDAT6oVs5/mH9K8G3WrvLUNxj3fJF9/oPennPDIHMdzVQkhTjqj7K2x/k7C1USXawhtkV5oaHlLyPc9mEsJAYeN+pzNnoK5MqKqKBxk3//CHBHWcwfzH5v7Xi43LTaA6FT3XRUteKAfzOQKB7N9at8EcfSo+3KG4swXEQYhaG3DfoBxf088q4o68zTK/47e82X3AvNWCb5orXbT3BcSd1plN1+i6drH5hWaRVo59z7AfOh3Xe9CJyCW+AUmgTUdWbJ7goHZdhHne9tsOs5/coxQCgz0m91zuE/r9KqTf9+Sr6r/Pll7mPzpzBJlyNI94faaaqIJcCzvPqWM22WBZiOjC99yMUSOfVSMK8SZQ+FcrtsDjOeYspkoQohF00lYKnNbNlzkvaewXJjRPLm4Qwj1MEojIivDPpCLPezR7HCox00hddm8cJtchiWt8nd06lR6W8ZME2DXncK1vENTy3paLtgk54U5+5DyXISQotn9wecpxaTuCTLzgECPsvvmmuzyTMwjlWsCPpDdLSDApMU1RO8MiNMPSKhfOFPK6GTDplUfgqZ5SO58Vzutsw/zqn1gIqFILf5dpj6nQKlDzftKCxQr46XnxM6WN3SqPiPxq/iGsbpavsmA9TWohTYtNdi2gt7hzV3/HeUjLz2CtwX1z4gHC2rBTtfc+92kXa6dP4aa+RG9604cWZYhi5pecpo6uiFNXNES5945zPYh2yoJxDXwaojYTvi446wY6rTJQKq8bzdAWi28B8/N4DvcwiKheklyC68RWtZTOU+5/U19fpBCg33fb2OX96AFvm5pi3I1kWuYXbNsLAxmT3gjLyEwzbffb2tZ1l3tG7lIShwJRmxPfgdMeCzWhQOqjJF1IrgkRdpWTtrwKyxAs4K2ZjZjTcVXzMtuREdVHYjustosUNzP62GH1jlzn84xFC7S3ZK+0SES2QVZDXSHMKlWLzqruLzAXP7euALxlssvACRSloTIbHOWoN8NITJZGdDpwIie+VV5xbgk0j6vwQ5qUQe/jd/TfXKv4sswlxzv0Jf3/1/AtdMcIoqPoXEvyJzC2Qe2WYBHviDw0XA7Jh8kz8Stx6D7p+oXBxTTT7mcKjC71Sc1gUdQ32UUKfquc3XLX5U8glKUDHcOSFxvSXJavgZXoV7x/WWWvvfAaqutXGo6WamLtygoA+2/+GlncEWhRP7Gf3p/phPhEia2CYer9BtZ0/w6iM/r7aUNtAd3vvXCPZV7Cfcg6EdFVGaJyNTLI3h00rONSCKR5lPk2cLDOfIjDlh7tEaM9glVTA1lW65pBPx1RCFKdV5RsRga3LcshZOXi+/dZydXxgSz7z+wiX/GB8GNHPuc6dwu4aFZAYb4y7q1ULqlrEEKNydn4Xqm+0mI6rqLrqcu767EYT0Ynsba+6jY/A9LP7y0n7N50hGoXREYENvSobJTIE6wRKEimqT+gn+R1bL1UoeIHPnC2yNVUnHaDn7XDWjPD2wOAVAI60cmjABo02dfbJ5g+WSszTF7S8+G8mgoz0wrtDvHEmks/XA75+zA5mMQQ94c8TmiTAtQHpzsq8OGjHB54ZrwWqgAgiQ916sv9s6EFbxSwn7+VVD240TO3fOKFjfdCn0sQnORVaAXRAdZTF2PDseuM6teQlwwRUAKoDq9c2YfQYe59pSr27Iz1xZvrZwc3gEQh7ljjt7WZNyE++2l4= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 10c4c8b0-d38f-4359-022d-08da3b68c1f0 X-MS-Exchange-CrossTenant-AuthSource: CO6PR02MB7555.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2022 20:30:34.4434 (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: iyvzDchcnSTaJiODdDMBWydsE5zgDkFEnVAaeQcbCVp2fUtCUrbxCtDYDcll+Gm2SjflYJtaCEcLBu5Ipjsro/jjiCiiTktcDJmQBG1S0ak= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR02MB4319 X-Proofpoint-GUID: Tnmr7fB66SFzuSeesQYnmIN8gM7b6kU2 X-Proofpoint-ORIG-GUID: Tnmr7fB66SFzuSeesQYnmIN8gM7b6kU2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-21_06,2022-05-20_02,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 --- Documentation/virt/kvm/api.rst | 32 ++++++++++++++++++++++++++++++++ arch/x86/kvm/mmu/spte.c | 4 ++-- arch/x86/kvm/vmx/vmx.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 ++++++- 8 files changed, 75 insertions(+), 3 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 9f3172376ec3..a9317ed31d06 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -6125,6 +6125,24 @@ 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, can be + skewed based on the size of the pages accessed by each 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 +6177,20 @@ 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 enforcing the quota is best effort, as the guest may dirty +multiple pages before KVM can recheck the quota. However, unless KVM is using +a hardware-based dirty ring buffer, e.g. Intel's Page Modification Logging, +KVM will detect quota exhaustion within a handful of dirtied page. If a +hardware ring buffer is used, the overrun is bounded by the size of the buffer +(512 entries for PML). + +:: }; diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c index 73cfe62fdad1..01f0d2a04796 100644 --- a/arch/x86/kvm/mmu/spte.c +++ b/arch/x86/kvm/mmu/spte.c @@ -182,9 +182,9 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, "spte = 0x%llx, level = %d, rsvd bits = 0x%llx", spte, level, get_rsvd_bits(&vcpu->arch.mmu->shadow_zero_check, spte, level)); - if ((spte & PT_WRITABLE_MASK) && kvm_slot_dirty_track_enabled(slot)) { + if (spte & PT_WRITABLE_MASK) { /* Enforced by kvm_mmu_hugepage_adjust. */ - WARN_ON(level > PG_LEVEL_4K); + WARN_ON(level > PG_LEVEL_4K && kvm_slot_dirty_track_enabled(slot)); mark_page_dirty_in_slot(vcpu->kvm, slot, gfn); } diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index b730d799c26e..5cbe4992692a 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5507,6 +5507,9 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu) */ if (__xfer_to_guest_mode_work_pending()) return 1; + + if (!kvm_vcpu_check_dirty_quota(vcpu)) + return 0; } return 1; 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..ca1ac970a6cf 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) +{ + struct kvm_run *run = vcpu->run; + u64 dirty_quota = READ_ONCE(run->dirty_quota); + u64 pages_dirtied = vcpu->stat.generic.pages_dirtied; + + 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 Sat May 21 20:29:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivam Kumar X-Patchwork-Id: 12858010 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 CB366C433F5 for ; Sat, 21 May 2022 20:31:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345473AbiEUUbN (ORCPT ); Sat, 21 May 2022 16:31:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345230AbiEUUbK (ORCPT ); Sat, 21 May 2022 16:31:10 -0400 Received: from mx0a-002c1b01.pphosted.com (mx0a-002c1b01.pphosted.com [148.163.151.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AA3C1033 for ; Sat, 21 May 2022 13:31:08 -0700 (PDT) Received: from pps.filterd (m0127838.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24LIpc7e020493; Sat, 21 May 2022 13:30:57 -0700 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=FXkTc2ZVZXKC0E5sIcch8sHuG+fu4OGb9mag3uHKaKQ=; b=f9et2/Q16WRw40BElCMet3baFIrwA2rDKcfecUelzs5TvWoGvDVta9FuLtXoWC1tJmv8 Yz0LkvZSqEbD6GbVRTWnbEWET9TxWmxs1XMKqNI3Z8r1r2SOM8a4dH4refPUxgH+05Uv XHmwVd3xat3Sxfkz4tfmg9GMkEQCVkgWdrTQPLrgzozJMUZLpMkSCp8FPAbdIA8aHmSK YNK1eno7TGcXbYfImiR/ziY0lyq7ulnS+FGyy5TGpp4OZz9sO1IOg/n+MeqSGOyps4ms A/YmdC2Ahd9axv6rQyZtZolQSzgeQSuMrTyWa75TqpGCmYFSwric8OE1ntok+59wEXII fg== Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3g6ymx0fxh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 21 May 2022 13:30:57 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ls++s6D+2hvuQy7OlOisGv5VKbbyyFZ73xAePw2crwudJg1pCXzbNs7GRxxovkGeuC20xaEVzHdAVFGHjJZBRQcNbzRQ+tahfEmJ99Vkr3ZVzN0iAM7+V0KxHuhY/uDlWZkyo3JRFx+DPrGvLSkvrPcovl96D2N0zWin6NCHb+kXUyOxbwMjdoNkGKrx9AoP5hxUxe1HTS4fbiYNEGGc6tpObmhvYDrlDtRSFkfrkjyWa+XJzHZdq/xKO13osLV/x0s4vgJXzE/XPrV+IL+Ii/iAY36FyX0NHNfT2dobx2p2oADJIys69AhA6L83m+c3uVHqHvcYR28pCfKGow8LkA== 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=FXkTc2ZVZXKC0E5sIcch8sHuG+fu4OGb9mag3uHKaKQ=; b=PHELYl7YcPjOQ1eG41ZXCymbtqX4Kki8DU+1bUqwynhl25j5ZQUCf+mhxVk+KZPrvB8yeVR5+Qfkn4lv8gOYIjkMiZ4JmcD0fE705rZ2cPu6BNk3Gq163hx2CkNt2BSTJM6xdX3tSnBBs6WXGdEtFYXLqgBkonlLW5sVu9zO9XDFObTX/R8VAy9olzsVcXdamC2UR0fglhWVFKWs6SnONCBAtOYhE8sWtwOkfY0doNUJtxxKyq4dkHYPHp/nkScLWJZzpdbSVqQIF2sW8VAeuHlPkR286NC+ud1A763XHdRBA/BJXp9scIugih6GBYxwPpPfXgAbD9INqu4DFSIoTw== 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 SN6PR02MB4319.namprd02.prod.outlook.com (2603:10b6:805:ac::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.19; Sat, 21 May 2022 20:30:55 +0000 Received: from CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::6819:797c:706f:9a01]) by CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::6819:797c:706f:9a01%6]) with mapi id 15.20.5273.021; Sat, 21 May 2022 20:30:55 +0000 From: Shivam Kumar To: pbonzini@redhat.com, seanjc@google.com, maz@kernel.org, james.morse@arm.com, borntraeger@linux.ibm.com, david@redhat.com Cc: kvm@vger.kernel.org, Shivam Kumar , Shaju Abraham , Manish Mishra , Anurag Madnawat Subject: [PATCH v4 2/4] KVM: arm64: Dirty quota-based throttling of vcpus Date: Sat, 21 May 2022 20:29:38 +0000 Message-Id: <20220521202937.184189-3-shivam.kumar1@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220521202937.184189-1-shivam.kumar1@nutanix.com> References: <20220521202937.184189-1-shivam.kumar1@nutanix.com> X-ClientProxiedBy: SJ0PR05CA0064.namprd05.prod.outlook.com (2603:10b6:a03:332::9) 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: f738b79e-ee81-46e2-3007-08da3b68ce61 X-MS-TrafficTypeDiagnostic: SN6PR02MB4319: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: DOY8Cx7D7UawYZkqVD2lpAvBet6Pu6IYDyXRujA56dZSwwCuDmKJSMWdI2tWjmxrVmB43URBYioAp8KyqtwoN4Ukk5mAGQxgOJXvuRAXCclviGBhBnNJHpH0++wvW2S8/3BdoD0xgGKIso2AADY4OCyzNFbzTwgC5sFMNjyVuag/M3VN9DuCow5ExXAt+m3IB0W+IZ0EBZnZraiCINdZQVNId0inVolj55o0ymkA9sTtR6mBh6jzVTkBJ2ORu5mU1/ZeZCPNg+xGEWOsppVYUsch14h4RKPm09yICwY3VXVjHAmO22xS3xHaBZoqJApi4wh6pQQX0L7Eb6Wkk4Xzf97XG0NxvI+iSsHVCQSHAIDPs6qiTrxcS8nnTGlWgNOziu2juNv2uzsGC4+5JTV00jn+CSgn6Mvs+e1YxCc+Y6kwcq9pZhLBxAPpL9T1QQc4vug+Mt8g9bc+lXV33SoDKj6b4SJR3QIwMiNGlb8gfpq3SKMyscMSTQXpsTAjFzh5a8XtJv4JZ34ZBNn5dUMhkrE9nQpMsRj0fSBHDU9Y0wS5FjRe5EXiOj7SfarZUsCnBQLrh1hL+mzovu/J59/rB5Ut8Y3bqMfANHMF3g6J5an1O0qfbSeSe03YwZ5AQqt8/cF4BmUfcsroLN6XRIDFvzqo3NLf9LHc1/aYZfEsWT0sgu2DQBxHJH7qGKGueCqAL60Thrn/OO6vhmkIXi6z23LTPQeaqt+GpKL0OdsbqcI= 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)(15650500001)(52116002)(6666004)(66476007)(66946007)(66556008)(2906002)(8936002)(5660300002)(4744005)(508600001)(4326008)(6486002)(36756003)(86362001)(8676002)(6506007)(6512007)(316002)(54906003)(1076003)(83380400001)(107886003)(186003)(38100700002)(38350700002)(26005)(2616005)(14143004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tmAT03sp5RMbfkqBDJTGFc+HIlBMF2Mg8xsbE9WJVi7YyJXaNPtXMVxCgNCG1iR6dQ0/4hSNS0KUEBHi3KaSixGlY264iSrH4uQthtU5Orz6auuvP3LkUgir6ad45iVoELCTbqRAvyVchxqNMdfJIhgyh0YgLxTo670f7+yFIvqqD5vvO5hJ7sn8xYbl5kkJinMrVJCJUt7BtXHEfD9QJO28pp/UeDSqEYGpLj7FftMZdMnujEKTqz/Vkd6C3I3U4Me7haWXQIM69gpeb37o/o07dS2Za3whQBuootZDrSF1uZSygBTkO2EtmwNCB5CTOS/VgPe75cqoEk1ciZMBGE4nUlJ7SDdK3uMlm5wltCJFfwocj2NLSY6N7gTSeYEJmYf6ewQu+LVPi71ENKXWar8l1Pm0ti2vEHUWAg0qR2mQ/X6gu6PuJBnZYU+Ra/gEFdMlDuJYx3a+NQWzWLToPvrFCDTcVTs9Hd+8MJ6XbFCevKVhyCVkVDH2Z39LuAaRUyq8mmVcdpuTQwVQdgFZH31mT12D2P9Oh2+1RHyW3mTO5ljcwG8Xypz2bHbLARG92xf22/4HXvvjVUhIJRkBk3Xnluk9fA0LyndBhvQC5o44Z7jPAExl2IGSWj3hToJcwqaLplRKPhPsesYVMGiPSf3MLgeB37E5V02tQnVnhB+rWjRAOvAlFxWdqn+YDBbAUKfNyYqD2V69Zwq0Zf0r0Bp8zmbe483KCr8Pqp2eC1OL115Z8+XSrAl8ojV+1wwYyd6P5GbKfIrrNH3Al40I6WCmWzGBWpDdiX3XKmZByADjbMNrpN9y4logsgd9NXHDFRpSro5Keq4SijcdjNCNbDx2wB7DBD+u+r0pyFMkReuRYr2JyFvaooU+KJ5BB42jrCsZ1b0zAHbMB8TcyAS8Eaz+hBp+mbH4gy0dh0q0ucFProXH61PB/RQ6nOl+t93z5YcAwizWMekzRcrVJXkAkTEuVwQtXYHW7y/Q1GXNF7M5IrfkRKnnzNwhpV4zWhfUfzqdVcv+HF7MT/Apmfg/URvuHpMWJS47wzc10yS++quxXnTUPiKLpSKU1n1SxARsTviUIhhtJDd02FT/VUFO9NNEg1gvnXOVhVUz5YNHNngMDQmPHsJRgEK1V7Cf5XifnpI1l2+HrQGbWa4kKZZD7sx8s48JREhvc4j9WdQ5ve9bzX3/OWMjtObm1N8o/4eoRDaWkwmxd4uUOH0V1uLIKC9SHewsQJRvKnwa9Hlat4uyVpICbM5rytyKQ2LijkFgfIivvcIeNOKe6TBGVHv1u+yBMOG/Q4Pns04dZSsXqyI2UiD7v8yENtj2eC9y3dkJSRrRPlK6eDOoROj+xvWv1BslQxm3lduBJgbMom3EVR05XXPqHQ5FP+a0Ff5wMuO9JTzWNv77aqtsseGTDuTgdea4IM8DxJ1JmffLdumK3dH8GnkPXZj2+E/RZaif/+9q3OZbKUhrZG0NGPgBsqgoYPwyaMGjQzgzyiYAi4z007oo9bUWtEc70OJpZ934bB/04yqfC6hi/Yi3cgx4kA7X+ZP/uBv/OmUVMKlsq4q3LEH4dYxbp2r0/GM7/mC+wTX8xZHsWtPo4yZQwqVIo4frTRX6mKZx97DQPxrqmi6lTxHUK9Z1WUoLcybHqTlLFF/xO8c1S/ipiVmFUH8eUj4YTMnelNFsJGhQRu5MvUq5c0DbZWrmJce9PU+57BBuaK2dfl3o5awzKLl3O8YawV7L5T2qvw9mO1L6dogB/ZwoxKI= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: f738b79e-ee81-46e2-3007-08da3b68ce61 X-MS-Exchange-CrossTenant-AuthSource: CO6PR02MB7555.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2022 20:30:55.3490 (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: NB2VZNyi4z2+VOkegt3ubV7qKkvh23aPQ5d9czsvBqDIBjksQRktiK33rtC1G3zLY+VCJZOlD75CrDTgrYM0lCwO99LlEGx4b45BeEsn2i8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR02MB4319 X-Proofpoint-ORIG-GUID: A-p2WJUHMNZoiPwyVXUq-PRPjdqeATFG X-Proofpoint-GUID: A-p2WJUHMNZoiPwyVXUq-PRPjdqeATFG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-21_06,2022-05-20_02,2022-02-23_01 X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 +++ 1 file changed, 3 insertions(+) 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 */ From patchwork Sat May 21 20:29:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivam Kumar X-Patchwork-Id: 12858011 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 7B03CC433F5 for ; Sat, 21 May 2022 20:31:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344488AbiEUUbh (ORCPT ); Sat, 21 May 2022 16:31:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345945AbiEUUbZ (ORCPT ); Sat, 21 May 2022 16:31:25 -0400 Received: from mx0a-002c1b01.pphosted.com (mx0a-002c1b01.pphosted.com [148.163.151.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 709D32BE for ; Sat, 21 May 2022 13:31:23 -0700 (PDT) Received: from pps.filterd (m0127840.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24L8FnNp030493; Sat, 21 May 2022 13:31:12 -0700 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=YsQbK54wLZFiJJr1Civ5ve9nBaNC1DfaSfWmV7WdPSA=; b=lFx47AZO6/uXKguZusYuYhhNBQ1YiG8EfvoEdyTk8+nEdkfw52bYmFUTCzqa5q3PkINf xHTebSNe2kFVbCC3LInEk/zU78w/SqT4nxspqCc5D6bzkWCfrWMunk7A4x1yrfaTuFmw 7/p1oer9rHKKNw4nCbk00ly3BEylIS3YubgyaH3zzetCu7cxXPGP2C0MM+kaB8XXOEt2 xFWiOVm/8weiM3jT4Vz+fWzGb9ADqkz+9+uuA268/wB3TFjoGXZGcUAM9cFoOywq7Z1t TEVbqsU58pmEwnTipHUY/xva23jTt/vQEFpZxMs5To8YeOfjcmZhbm+CKqTxgleenBBV jQ== Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2173.outbound.protection.outlook.com [104.47.58.173]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3g6vdrgpd3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 21 May 2022 13:31:12 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TM9vyG/riNPmHVi5jkDmMxnzMzN66Cr9FReTeFxTZdRKI40XJbKDd1ndPUfwu5TPw/tRg8E5MAoT/y8ZVFKpd94YpdJSJ49GClU9+xOCiDutocn2fCs1HbHMHVBEjcrF/UyK8n44Rm1q4EDaDoj/0jCSzJYwAGDMVM7UQPSKvtobTi9ggdH3J1EaQ5RXhr/P6DW7PrKaNV+kuXxmklt00GMul9rsfo5jF86HDzpuos0ZXoR8BKohammPz4xI52z8rCmBNB+PJqOV/aWWeOOTkPnmysyr6F+tOEYeXbiVo1v6IiajJn4oZKyprpw5GLh6jkVvfQPkszTktqGBbUpxAQ== 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=YsQbK54wLZFiJJr1Civ5ve9nBaNC1DfaSfWmV7WdPSA=; b=RIQTSpJ9CB7dl8h+VCLLRKAZls7zGDshQaPS+pr2Ol5rvMJdayp7FON2KwDG+8My7ArHlY4gDnJUDLMmpSceIARvt6VB0NXz5ZvF7bAQEURKUM4EWlh0PqalfPkx0OolA9pVeBRhr0Vx/6wvi+Sp668m/pIsVTQYftLwIhA+UHiKnDDbwPs3zfdJ8aFAXzAnSzFig5JPXYZ69xsMkrt/QfXgo07Mq8t5VTt4enkRJsdh2SvLz5dGiYBXbMj7Ai1ZhnV6zVdg/6d1/Ej3xzc0rByoGsTgKOFMNdLHKkkBdS+uhJcBs+nOVu3/p+qFUUK6u0xGAY+7GmQNVz0c2cDHNQ== 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 SN6PR02MB4319.namprd02.prod.outlook.com (2603:10b6:805:ac::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.19; Sat, 21 May 2022 20:31:10 +0000 Received: from CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::6819:797c:706f:9a01]) by CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::6819:797c:706f:9a01%6]) with mapi id 15.20.5273.021; Sat, 21 May 2022 20:31:10 +0000 From: Shivam Kumar To: pbonzini@redhat.com, seanjc@google.com, maz@kernel.org, james.morse@arm.com, borntraeger@linux.ibm.com, david@redhat.com Cc: kvm@vger.kernel.org, Shivam Kumar , Shaju Abraham , Manish Mishra , Anurag Madnawat Subject: [PATCH v4 3/4] KVM: s390x: Dirty quota-based throttling of vcpus Date: Sat, 21 May 2022 20:29:40 +0000 Message-Id: <20220521202937.184189-4-shivam.kumar1@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220521202937.184189-1-shivam.kumar1@nutanix.com> References: <20220521202937.184189-1-shivam.kumar1@nutanix.com> X-ClientProxiedBy: SJ0PR05CA0064.namprd05.prod.outlook.com (2603:10b6:a03:332::9) 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: e6fa8ff8-bea6-475a-47f0-08da3b68d749 X-MS-TrafficTypeDiagnostic: SN6PR02MB4319: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: d74NFZICKevUmtLbkKIWkU1KBLSsn1ODVIwiAsQzIP2es9e7ewApE8WhjMq0kazGtEKVu9f6MvbCRJTrcwIVA6hgNXfhtAA3pXTlS1mysxoVMTLumpKQM2OANosGJqX6UKeFWqyVJjrAtDjjtRY6MJUZT/UBXAAKTTfvUIq8GMJwADVPN7zFnAbeMEb7vFMlRMQ3YPGqwuODfbhjQrvOyw3PG2Uf8NaPy1GcEey120iVZhpC0/5uHpEWiXuVJelr62xuf/1IsA+JSNTgCuw+bd/bgQK/UCRwSuJOjTxTcA/EgoTzNj8RXilOP+tWL6U3K7Oj0EbnFe2Gf1sv3qls/+VqGpeCwaG8FfZxJxrdDV/MmZ0rB4ZA+L57Rzyk0XeKyaG057JoD5kxucX/cXH//De5f3PGe/I8705aUCLK5t09L6L5OaYZDaF3ZNRcmY8R3uqHranFZItoh7hUipcYBGqXZib9RVWKObswI/o/XlKLgXzE5mAwJzTgnkq+0y8nG/JugjVm11cY3XT0cogZR9vHD5wMLMz+a4s0mMEBSqGvaEkq4xBe0yNlMcAmqnw56PgpM7qeC2SaOeBpsHGnOFntrvIk4v2mo4er4zEH7nwiDs0J1I2rqiI7zwMzyL3Ujopjqa8RQ8Wbbf90FdRc7EraL1dCk6h4IJrCfwBRswqlCjCWV79d8E3BH4UQ1kmHqjNLvAxGx8L/ZUS26vX15SIXL2zKxpHozyI6xdn0CEM= 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)(15650500001)(52116002)(6666004)(66476007)(66946007)(66556008)(2906002)(8936002)(5660300002)(4744005)(508600001)(4326008)(6486002)(36756003)(86362001)(8676002)(6506007)(6512007)(316002)(54906003)(1076003)(83380400001)(107886003)(186003)(38100700002)(38350700002)(26005)(2616005)(14143004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uICS8DbKO6Z0SsaYwXniZTYBVW88yRcxv3FTe56Vr2WPQK1dGsv3HKiAVzz6lZZ5NyuGxJlzjsc06YxcPZ739YBUyh21iIekhA9wADL41D3Vu7/J2cftnkrq3L1Am+xzX9QNIU8BUH6cVK5kcb7+MfX2SzA28pAmLnoulE9XLYofnrPZAwBShGh4HxAuSq2t4+0D/tj9EI6u94k9jAvwz1UpLOVhhK4guw9nIygNbJhukIDu4Su1CgGGpjX4IGr5ZCQyAHnTM/FWq2uELLVSTU07AQNmoyLKuda5PuSG9oHFbn1RZWISOdqlmjJqmSzwzPwiQJ5TcQANgKmKaZ+SaExkxlEs9d4flWtqE7DLlnyo0wz903HJRpIijOolGNs9MAYHwd/m9K0EKQ8MrFjZSA6+LN7dMQXERZFKE9IKxP6mVMOUFMjxwDPdNtMnidsMNgZdKuIR6VRbmtbI+wYUzMg06bVOMyN5lUitAs2z5w5Qs1UPvJA0ZYEaMfjYKsWeHR+36D7iMT3s0d9OaIyWHMcwjONsKIvBJ7KZBK5sulwUy0xmfU1VngfInf/djz9Lf9mqvwlCX8oeGQa2ADdAIsVtf1R/mGEsxeaGOmr/iDpNOt5/fyWCkpFNIyxWKbMVdMwPeCglONF0RIYhb+jIw0tLFcoJFuwhcsMFez311mRb/9lU2H97RCSsnWXhTSNpfRyMxOVqbEjML+dcttAyu7x04nSgs17VxjBkg8x7vyO+FbQq+XXyMdwDVaqecH6HUvEJQrpWhndLj6B3+B1F5RrNapNeQGce2BPes/C07514g+DKMFarQq13FMXH6pvX5tWQXvNCugOFdzArHcfYccM+yKTGIkgkQ4R1J8mVxbhoqGFsuJePy/pDFE9Z869hpUOPZyELl7kaPUT7KkPp/oPa1p1/f73Sy5gZfs+ci5xePyHwQ4wkTxho/A2m6K63338xWQGAaWpAtLBbHRbvVWWZGD59sEPcaCIM4uxlKBI/Z+WnZWr+VTdIBVGyFF8S/pSZTaIID/y0VkstF7pyaqLZ/2GjRC4zkYiqxHQq9CQw7iYkV63BkMZkiWHHJBx9AtEX0rjh8q631mF/btOncERKQRNbZ7wX2Oy/Q6WcQLiJHLPqW6kO7XaqarZtA2VB/KKHGM8K2s/k1eLesVCkgBRVSpEWlReo1XyJ6LG64aBgfu/kCpj+37JX3gFS0Zv0NY1K+98K48T8ADuVO5BsxOPl1sNapyOngDv36cTGW0n1Zccy+QhGRRp8r3moTc9ZQjqRvCzDTOpeaw9Pmd4SncMyKIDxAAtssmNle578FDHPqblaLgSHFK/LAQlPIKNRxkDkh3k4ZJ2reSIpxzdt8GC6fw1eVsdXmKZqOS5f++UBgRZjOybfgjbG0A8em8IKyA7CjY7GUGN3yCv1sICQulafid/zONXYpGxp7ASwkNMMm3JZD+I6hFMToGLsiTyZwXokM8Y+k/9zA9y1lndiWvpnsiowBBYwRzR+yCKfAb4CxMLvMpO7ogU3WU3XQv9PP2F31DkM3rIN56htILoAuItkilALK4CQW0aO91az0DpO7E8rGtn1ctdSiqaIpf0bxvwanisRbIXcwUipVX2x0nZ1V3Z1NJYuincBlg/wT/EC4q74cjWvR0BpD7jpTlA6s8gpZMUJCBvbM654Ini6+95/h4Nlrq8ycCYy8MJzdvKOo7K0g14HgEKsaiA+z9l70dn0mPX7BBgnQ0TI92Sn/I0JmelaIdxgMDtJ9Rwiu3Y= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: e6fa8ff8-bea6-475a-47f0-08da3b68d749 X-MS-Exchange-CrossTenant-AuthSource: CO6PR02MB7555.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2022 20:31:10.2918 (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: +izceogRmafFS/OdThoRAkht5DUkWXRmXbCzxzSMlj0DQVQ6Vps21JSEgXKz6P6KESVpayz80+tCLRMZHbL+1PBk9sKdUyo1UMBtkhPlqkQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR02MB4319 X-Proofpoint-ORIG-GUID: RvCFuyj2QsehRjmGUiWNyFMeyruvz8-s X-Proofpoint-GUID: RvCFuyj2QsehRjmGUiWNyFMeyruvz8-s X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-21_06,2022-05-20_02,2022-02-23_01 X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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/s390/kvm/kvm-s390.c | 3 +++ 1 file changed, 3 insertions(+) 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 From patchwork Sat May 21 20:29:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivam Kumar X-Patchwork-Id: 12858012 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 3CE69C433FE for ; Sat, 21 May 2022 20:31:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345647AbiEUUbs (ORCPT ); Sat, 21 May 2022 16:31:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345413AbiEUUbq (ORCPT ); Sat, 21 May 2022 16:31:46 -0400 Received: from mx0b-002c1b01.pphosted.com (mx0b-002c1b01.pphosted.com [148.163.155.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 146A1248FE for ; Sat, 21 May 2022 13:31:45 -0700 (PDT) Received: from pps.filterd (m0127843.ppops.net [127.0.0.1]) by mx0b-002c1b01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24LHUFdN002715; Sat, 21 May 2022 13:31:35 -0700 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=MzhJAPRznR4BIFwcVWKv4IfRzNLX1j/kg0pXRnodaMk=; b=SdS8tgJBzshue2rOc2z1kCNY4FpQCdwp8KcdB/91A2BrgD5/7/SE0nWucDCdhzKWdwGh Z5BdfVOGsNXisuty7HT0PGFSfekAcdCnSQphPvQeiDTNS/4RUiXAWr7q1OLTmic9cWDm ApiWq8OVYVg15S6oM8xYxOo3Cp3EWZLWWtgUbNe/2vlHwvWa7fXEnI+4mn1vQEoV0HI1 Z6K6I1/heeRytF61cmnKdO+Xs3ocTMJhZbJ+W70iYk2/6xQABylGx5MQNVv18+ztCSAD BCMrbhyMBPMr3iYvBCvHmwy0DPw58azui9GCHh57CxuWHkdz2n/9+HzvxSwlzAJrHNCo vg== Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2176.outbound.protection.outlook.com [104.47.58.176]) by mx0b-002c1b01.pphosted.com (PPS) with ESMTPS id 3g6x6h0jh5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 21 May 2022 13:31:35 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZKpWoy1g2H8SXO3o4c3mbXdMNQiwXwF39cAcUvpxfy56rqvfZZs2Mrt0X9mCcZZcx4QHn+hif6G0jlIyPtgdDMVETzYsFTNyM7dFUSC0ghD9KnpMT1SUKaLS8lx6el5B6EF0LbYYZ/TGUQ/0LlK5A1feRf3XpwHWPgByPett7hjNVq6iS85rqGpF0IDJDxlvdfn3J0mz9Qr3+skp9AbO23gmp3myiioAZUDqxqUJQ/GbaBMUrkV7W9io+R1/DW/UE/QcdS6QJUIHlpNNwE90e2jddxwP93LuGl1a1RugUvHqMmMde95AwrEhOEIuD36CKXdz6mmRip8dhGkxehiMXA== 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=MzhJAPRznR4BIFwcVWKv4IfRzNLX1j/kg0pXRnodaMk=; b=LHUBDxOU0X7ynpAj13r/EOMDyUlifqNiCWHJVjtIfw33d6wdtnV5In8eZNd33a6KDQ1sVWM+/2IaLAALKsvAH0K6se4VYgLF/K79eX2SAMVYSWNGIEkwHWPCTiMa4zbDY7DCUyzgOOPhO/0wAejNAr/R+PVICFKz7aUwcvGqAUmG5IlyoalL9wEd8zWg/ayXbtmiPXDsnL31/3Osebtlsd3nDvvLi2ZyKlyqTa9LjjSJNibXX8NdPXuv1teLdrHEMmjjnrLCSHvNDI/e3Lq2EZWPkjr/S/3sz3mwXWP9j99FsrGCYkPmlLfke90o+woPr5/7F++03KwmjVzcr7YNAg== 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 SN6PR02MB4319.namprd02.prod.outlook.com (2603:10b6:805:ac::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.19; Sat, 21 May 2022 20:31:34 +0000 Received: from CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::6819:797c:706f:9a01]) by CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::6819:797c:706f:9a01%6]) with mapi id 15.20.5273.021; Sat, 21 May 2022 20:31:34 +0000 From: Shivam Kumar To: pbonzini@redhat.com, seanjc@google.com, maz@kernel.org, james.morse@arm.com, borntraeger@linux.ibm.com, david@redhat.com Cc: kvm@vger.kernel.org, Shivam Kumar , Shaju Abraham , Manish Mishra , Anurag Madnawat Subject: [PATCH v4 4/4] KVM: selftests: Add selftests for dirty quota throttling Date: Sat, 21 May 2022 20:29:42 +0000 Message-Id: <20220521202937.184189-5-shivam.kumar1@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220521202937.184189-1-shivam.kumar1@nutanix.com> References: <20220521202937.184189-1-shivam.kumar1@nutanix.com> X-ClientProxiedBy: SJ0PR05CA0064.namprd05.prod.outlook.com (2603:10b6:a03:332::9) 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: 78a86594-852b-458a-b910-08da3b68e56b X-MS-TrafficTypeDiagnostic: SN6PR02MB4319: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: FmHH4YsPrwBKEZYZ4326W/wpJn5nxTyQkLHkdsYWClUY5G6OvoBcD9GRoXvOduicu+MSknfodgT0MZ+ENAmIdGZLBFZ8r2y1WYstkCRH2Cuh+djqfD6iwe4/RsPe4cqff96MorbBJmcmxnelVKidx3gPVhnYqm1wBISktmrH1VdK2AkEs360LC7StYI1vq50vd+yevklHqypGV6Clt9iGF4+eBrqoouYvoWOszc1wcJlkWSWWxZKOnz/dpwtEIiAnEeh4kancnipokncLz4XdQhc0shhc0CkjG0bQHHYWESlBkzkkvXwSdokuE5PO1C8D9oaW/bsrk/pDlKKyEc9m6jCSgPg8fvJNEtnad9qVMgrx5jCRU8pHP5JgTmOr7IpKLymLXlOyX564iwBm7p1WPFopwoFN2cEQhA3rTQ3jiL0trw2ZDZ2cql3W6C/MU7KuELxtqOjfIbWzjyTk5FseJO5vIM9iIaelQn9PIR40ngCw4cYAdghx0RgqoyN1ywis2odd3BlCTb07SwbhN8wuYJ1NhvD3AdQiV+LLu//DxPMYfukyjmP2uO6UplGPTB6+TvLU6Utg/haQXkUAvTNPxsQ0OxJoA5zRPsgHHTLJNId8JG6NhcvRn1iK0qKLVue9b8KC0pRqp/0p5MnS0RglJLDNA+acDNvA4bKnye0HC0l4G6PQTSgWstedRnFttjRJQ/t6RyCxCfxZ1eXpSyi/EVUB2E1fnv5S8+/Hh3ht94= 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)(15650500001)(45080400002)(52116002)(6666004)(66476007)(66946007)(66556008)(2906002)(8936002)(5660300002)(508600001)(4326008)(6486002)(36756003)(86362001)(8676002)(6506007)(6512007)(316002)(54906003)(1076003)(83380400001)(107886003)(186003)(38100700002)(38350700002)(26005)(2616005)(14143004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Y1rj9uHqw+a5zA4Wa3hVtkEtPFhzcohItsludW8nEZVsgjVdRf9TBcD2me/RLi/PpzNNa2yCH0aOQ8goY4DBdtR5Cf8lT+WecXcZRWv3CbCYsB1zOsDd+qAcC+URjNEaRjPmgTow2eyIWwi8vhy9uRXrytOyKN4G/4eTmN3XBH+YTEzeZQywmkTq0VTIKblIZiXD21E167OhZD2dyuiODJLHQbp3kv1hcLg+/3GnKuvZ+hJtdsyMCk8Ehnnt25HN+Iua0jXk/hp9FlT/xrwPAQGqqFjkvqZmRujs83Adi3Y0tpJqIFk8cOXPOCgwwC2Y4BLewmAPN2t9etfzzAnOAbN9AXwRm7zkp31+ztWR7p+ScLEXyh8keiBc96j8h/W8VSP0nLCiLalpsM61PXhwkvsc1yAA62W5UH5fwaoJ83gjN8xRuf3d3kZsakVif2zm8Da/hQSczWP0DbvK55gMylvFDuszuOOVBhfioi5w+xRN3IDWMPBpiRh6O8vuh21bkLgLGcnaVoEKlu2grZD5VNUMT/mquo7rh6W1FEtjoEnwoStzHtSykSDMeGvMz3wC/xjpn8LCUrAFSgvXM+Z9HelFzDbAz4Yy4CtdXko6BvZ0O94kGFab4I5IJaom6DPKS0JzDS1MYVfaBsCsmAMvLRTFe0qPC8ZYC2Fn8Eeuh0M8Kt2drJ9OnAugRSHpJbgR2TSruOAC/y8vbZpdd15FVQzr9t+dwr7j3dEyWUqEe4rR9yY3Y20JICRfUDcMxGhjiYt+ZBpWZuDlmn8OQvnCbMK/u/dzxqn2bbxIfLXpNtqSrjk1+J8f0ULpfwH77fWIgDx23Gp8lzIgajgBCCpKmWNDcITZlktRt6P4MXjXuqPaaHAcBvmncw7okwgTSINpyAX8ejeN+zx+22pLtvxawi1GnMf6TWwp1Dp/fBYTZsjBEJ3LN+R3d5tOM1zmqeKapWqkykHHyA3TZDslb6CdkxRKSxYCd0b5NiVpL9hPuCyN7Bbnr1jViIUrPV4lFp6UlwbC6i5E8nODPtFChcF/T92ZM8cmSCWVK8t2ChO3xTuWaqMHhoXOCMSVF/J2+IhNHR0rm6rw97L+kMUvOXB8xBK8K/ss7lWHkDhmF/VQ193dSbmtLLFM4c1fSGhb9iRT8SCxU+dGTHT55u620sB04viDIC8ZjHjmAFAIyCD04VhmY/d2mlpZD6UOXFfEpV61Gq609OzO4fTNMGbz9RVY+tsFJNqRFz/DxBzu0gRuwdEmovDZdfj0vXDYZRmBPaZMw0ftcBl4WmQW/3qfvTt5VBV7aU7Vu4ciLhQMbHgiGyozOQPZzfRDoRSkWTSZE6uoT2fPrjPwBW913XvvhLPPuTQFiHitys/OZnWb5ilE5mrYTZxIKLMEfbSYLmBysU0VCHqt0Y94WhxuNmS6/pfUxst2asCBJMf1D4+zs4iiS56lSD4c4DJ78wn+9XM4J21AiVv9j4RBmuI6CNvv/9jRx0Qmdt3jD5kvR3lTKZE3Y4eAI5chDscpbPBh2k/Ypv5jxRNYxda9GgiN3m7o0raBsgW72sZTezItjXAYNszhuCyH5z/esei9N/gC1ZKGzxskwcTAoEs2++7CWqQWV5X3KTPuR4zI6mSXBkoevtIPPKbk8kkxNm0pVepDxUJayjPznIKIvp3+JAiH5Eav6HP4zycx21UCfGS2L81wsI+J0/z/dVbBypCRajdkRv2USBywZ005aZRsqttcPKXFRhvkkuFLZyyn+VxcY3Ka91fGUUI= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 78a86594-852b-458a-b910-08da3b68e56b X-MS-Exchange-CrossTenant-AuthSource: CO6PR02MB7555.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2022 20:31:33.9744 (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: ACxoHa9ZtRua6E+YqXRB/Q7nkBjbjPts1zUzWZ2qMlIalSy/2f5FLOA+NgT3mzT/MlCH2WeTp8Mo48FtOwMwHvQoOytsnLb0Om5k4cqfwHQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR02MB4319 X-Proofpoint-ORIG-GUID: emPQALzkLRYByjWfTLSVjO5LICMvFFXZ X-Proofpoint-GUID: emPQALzkLRYByjWfTLSVjO5LICMvFFXZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-21_06,2022-05-20_02,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..74a354dea8a7 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 Intel's Page Modification Logging, 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; +}