From patchwork Mon Sep 12 04:09:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivam Kumar X-Patchwork-Id: 12973236 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 A71A3ECAAA1 for ; Mon, 12 Sep 2022 04:32:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229575AbiILEcu (ORCPT ); Mon, 12 Sep 2022 00:32:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbiILEct (ORCPT ); Mon, 12 Sep 2022 00:32:49 -0400 Received: from mx0a-002c1b01.pphosted.com (mx0a-002c1b01.pphosted.com [148.163.151.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 289F323143 for ; Sun, 11 Sep 2022 21:32:45 -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 28B8COR8024335; Sun, 11 Sep 2022 21:10:48 -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=h2o/I5BfPfLUVYPl+IpVZ58ZRC+Pd/XhXm778JDjros=; b=M+eZtMLpb2D/t0B0cGHdoMUjaWy/5NQXEiTzqzoWftZ3X4mfHswMyQbkdbAk+n1cEZND j3WYVrmEtxJMt8YvFm4KSuDXuBu1OJmuqkEDep34Jtmr18frsDXEyjpEXuGVKvhqSoxl mOAr/AZ2QZAWGvL0xy1XHi18CGWkYvkYsWVD72RUl/5NxH0CHtzrLYndS2kU3iyXbiZF wvaL6TlEHm3QE2WLmP1b5nqzRFtcqpI671YWLtyKNbnh69u7mJ6C9xyLX4EOy43p58FP PBuYwsv3UWYIjcQHSx6YhL+/Zlc5VtHX62xrePtIC6Tj/ClDrQN0hFZlb3jE4GgbFEY3 Ww== Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2168.outbound.protection.outlook.com [104.47.56.168]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3jgpwtjwgw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Sep 2022 21:10:47 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a03++9WIRC0MGMxA4XwIJ0GlSapv34JH7NtX1cmwVBDwpso2oSClCTyaXzdsoFXT0NYQTuiBylcU1S8z17iP147LsIjMjyjNjBwL6x7/xMQXFXuD2ynkek+RPy9I/jgI++mH4cY5zg9UtTWnZahvRA+V12lHejq9TZSkUI42NRfS+g4xFdjcVsshJnonl5i4NtthYW6xx/IIlmpEMwsu9ADip3PCrpqQp1X3oB8BkIqjvUMrcDRZubtxnuBOoAttYO+Ezf3nODpdufkj2C5pdjbPTfS43q6J4d3hYuRBTBtuKwAr1+EfGoZA+GXviaNspONn7i6LXaaGfubOgZyzig== 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=h2o/I5BfPfLUVYPl+IpVZ58ZRC+Pd/XhXm778JDjros=; b=In4NU5xljb9CJdildL3OAzVbJdOIXc4aVjv8resMBoZIKhhJEj5tqtN3n6utzTtUNaMKulTYyywEuk7jTAE7xiRUZkzHCCn+yUhTx6p+iSyYlh5x71RTvZWzFjmB4eye83NHk9RIq1BouNpahjGY3B7CRt2ouXdN3aDuOukp5/v2chQG7AgHHYdG7xjEI0DizfxHS9u3lf6ZbR90GwPyIsr/8Xza46+LAi4elNmT7vaQYaD2vaJ9Pp5jXiqNA6J64bpYBZA7orxqci5efSLofSDlGgR2LrgExafUv6lylzzX3r/oCneIPllc2walNnJnuDpPU8idrFYsHYlqFGXDYw== 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 CH3PR02MB9116.namprd02.prod.outlook.com (2603:10b6:610:144::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.12; Mon, 12 Sep 2022 04:10:45 +0000 Received: from CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::bcdf:6d6f:e6e:b9cf]) by CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::bcdf:6d6f:e6e:b9cf%7]) with mapi id 15.20.5612.022; Mon, 12 Sep 2022 04:10:45 +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 v5 1/5] KVM: Implement dirty quota-based throttling of vcpus Date: Mon, 12 Sep 2022 04:09:24 +0000 Message-Id: <20220912040926.185481-2-shivam.kumar1@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220912040926.185481-1-shivam.kumar1@nutanix.com> References: <20220912040926.185481-1-shivam.kumar1@nutanix.com> X-ClientProxiedBy: BY5PR03CA0025.namprd03.prod.outlook.com (2603:10b6:a03:1e0::35) To CO6PR02MB7555.namprd02.prod.outlook.com (2603:10b6:303:b3::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO6PR02MB7555:EE_|CH3PR02MB9116:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c4577bb-aa5e-456d-c32e-08da9474c432 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: hz4lAvoHzGbWqUlCjQrm1Si6dIRs6FMNErUQh+8hxGvs2z1RwjCMMKRaHrq9VgkzE1qviq/+gM0078dfOoPqMuKgpU/qCErlhH8vH2NmyomHucpMkenZRBJNn6ikvszpjntWOPr1Cq1OJPsQLQl9dnFILG+ODkFPCVMSAUwpFAEEc8CkOoXigCdesbzA8bdS6pu4X5eiecwz27mCVB7Alr2NCigAt2JRfyKMy7yYlEuBlIs5DiSsFFVdEX47w4doAVmvzVaP1I+pKCPbO8N4q4VN2U6ZqFutUmaubbnXrfUBv51HlRECo97/gI26QJq7x0pNRAq/qUyxAcH66nZfOl03zPMLAvToTvGaKppHq+GSQ4oHJXTHnEd6e56SaZiURWhUJhd+1+kB0W1gbejMQOM33Vokf2ZBOtuem2lfPeBgO9B5ivDRPVIHI3Lqm44jICIAx4qFMxOu4ze2fxQITtjJusouVpLljUcyHyjciNY05snFY3xVnQ/ZBPZ5rXX6pTa9JxT/dL+CNlTAUQ6BsWpKC/pak9ceoytpXXjrKeYp60mxboWe0twOr4B1gjlqJR9A3Ntg9DB+wbYCukvN34xd+1rGcBUsAy8SUBVm9zGIPlL149CroSX6qrZGfxzfRcxoEF6DxuIVRCtwTIQkI1LfaQHtgt+3Nld6W/+AUPJPpXoc5wOOu3H2IS8VWtYioGbspDllxjS9OJa18gjAETM6tf/5uJH8iamJy1PSIlxrPb7wzX5QDGSVUSqhf/EJuxd21YDCdSSBOwXrcV9tm+rpLPoSMytL4cd1c/K6edMpQbKQWBpmWbqG4tbwzmzc 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:(13230016)(396003)(366004)(376002)(136003)(346002)(39850400004)(26005)(107886003)(6512007)(52116002)(41300700001)(54906003)(86362001)(6506007)(6666004)(478600001)(966005)(6486002)(2616005)(1076003)(186003)(38100700002)(83380400001)(2906002)(15650500001)(38350700002)(36756003)(5660300002)(8676002)(66946007)(4326008)(8936002)(66476007)(66556008)(316002)(14143004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jmTmEMzaiH+TB9m5OIITAyWnYwH1GBr2FL7VHzW2AQAbJDW6WxSL+uN52nqBd8vEF2B5X4R5IExG7gLYf9wT2AVcHRxH6P3oKaMlGiHC8AlIEWy4Q9HBzZTXEn4wTZtv1v7mz7Gwq5uqLjSfjMPa4bszguT3+Ln8xLG5BYyfPI2ui6wvEroM9+Hxg/wV7qdi0JhFUPmZytUDFNfbLH45P4qFJBOSrG1ik3Lcvon9b1aUa5DL+tynwf6ortuLZ+14eTPpDhHFrbNXuz+p8f/80Sx71w+UyNro4ehH1Ah52tkfU7zJAydXHzYMVV06UXgGgBDhA1MJ4Xxffp2F15gdXz6wEqaWKh8eG9A1jKHFfme3DId1vDOXC6eKDD7RXyTRXFuomcU4EoCv6xDeBOmmjOza3wky2KFwbjcKMvxdymESh8HAC/HSLr84bGgZ4uNJoA1JvoMNRI7GX+n86WCe+AAotO4Ic2ydodiIX7wd3O1it6fVYKhuhr9cLiHWe6l7M4NOrVIapf6Ky4tRFf9mqteo0+sMF+LorxdO/Js2L9uxpg1l/JMgByry26irf+vDK27BtDRmj5ZMfqyD2VRT+VK2fQRbkIqbnUlaEp7v8F4Henw2KawpqTr9y7VSO7gVPe1Bmw0Z4KFUel0fbN8xr0It0cNpnB/K5RW9QwCaA1x5nti83zbeLM0AGqimQU7RAKH4zqIvzJ90mrIvMjIf25RQKZxsErlBqOqyZCjnmskA+QtcsY23Ok1eeIgSvAZAs2H4hMcsua0Fkwv/N0U+Zr2lxrj3eEkrX2+F9RKi8COdQIenKbZdLUl2wSLiiRg0HyPfxCjmahJne1oeWBDCNKDMuDnpxOdqwZNRvVWH4BgMcFkEjMxj00LN3xw4mX2bNjdSYluqu2HTCQCuSUS6ZcnO15URDBcHPcj3eV3Z3E+cPvds0u61zlAEjxfqXrxwUKaJDC9Yjn0DTDwTGqNpZJZ9y3gB/iuQZRUfGTN3FzzJ77OHtbhJP6qMK4YP7n0yYRsC/+Mr0Q9WqsUnc2FgZ078SoRGF2Aumy714eff1T8Wp2UV2jeB/0Z5eAXsO/DmP61wH+qJJtEv5IsVhYBizYp1hDLsutS16dQRSJaT42PeZWHFtXlDp/uHJtbBCP5eTFdhhUJImqRJTXUFnFPdMw4pTSRIBzjPrkpc9ll5gbgWFZ6JRX8YXuN+ue4ixmpsY44xDwucO7I1ywqHgrK/pkvf8ia7bF1HFP/YOpxcgsl2LnMqVnJvEmLyklTCi+uHu6ye1TVx2fFwGgkqPwH0PXIEfH+RPQBfyWDtkpYjm7DAywbedf0Tw6kB8SrtE6+Bk1mLISDh+tI8+ZCpwUfHksCtNALE15FQ0/rW5fpj9UtJoEYug640y33BNzJ9rktFQX+7DUpn4E7NKdw2ypzNuOCgqcy41C86sysRHiVlWUDSj4O+jK81SzW0AGDqoET056RDVI+fusaETo8q2Tm4zA4NBUE2HnZJwvBZPxlvBZ9yxNeAC1zYx0AyDuKLOLt/DwAgvWb6bHI3cIEHhb1ja7/RGdZ97HwBVCySwr6xFL8UwhJvjzhXiCO+JMLVy9jyAGcCc8PJFwyT7VQe5Puh4w== X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5c4577bb-aa5e-456d-c32e-08da9474c432 X-MS-Exchange-CrossTenant-AuthSource: CO6PR02MB7555.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2022 04:10:45.6373 (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: /UZwVIJxX+Ir4vOnY6IjQncKY5d/jM/dXzbIfp/X/Wqxcvtv2kJwcRL4xuSrxNkNnZYzCcydKyWOEO7wIpLRPoHiU/4/cw7WSviluiIoVdM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR02MB9116 X-Proofpoint-ORIG-GUID: 4o1N-R8fjMErZsK--8eAQ0yGweOCaz_Z X-Proofpoint-GUID: 4o1N-R8fjMErZsK--8eAQ0yGweOCaz_Z X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-12_02,2022-09-09_01,2022-06-22_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 Reported-by: kernel test robot --- Documentation/virt/kvm/api.rst | 32 ++++++++++++++++++++++++++++++++ include/linux/kvm_host.h | 20 +++++++++++++++++++- include/linux/kvm_types.h | 1 + include/uapi/linux/kvm.h | 12 ++++++++++++ virt/kvm/kvm_main.c | 26 +++++++++++++++++++++++--- 5 files changed, 87 insertions(+), 4 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index abd7c32126ce..2d7f63aa6ef3 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -6614,6 +6614,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. + :: /* KVM_EXIT_NOTIFY */ @@ -6668,6 +6686,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/include/linux/kvm_host.h b/include/linux/kvm_host.h index f4519d3689e1..9acb28635d94 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -151,12 +151,13 @@ static inline bool is_error_page(struct page *page) #define KVM_REQUEST_NO_ACTION BIT(10) /* * Architecture-independent vcpu->requests bit members - * Bits 4-7 are reserved for more arch-independent bits. + * Bits 5-7 are reserved for more arch-independent bits. */ #define KVM_REQ_TLB_FLUSH (0 | KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP) #define KVM_REQ_VM_DEAD (1 | KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP) #define KVM_REQ_UNBLOCK 2 #define KVM_REQ_UNHALT 3 +#define KVM_REQ_DIRTY_QUOTA_EXIT 4 #define KVM_REQUEST_ARCH_BASE 8 /* @@ -380,6 +381,8 @@ struct kvm_vcpu { */ struct kvm_memory_slot *last_used_slot; u64 last_used_slot_gen; + + u64 dirty_quota; }; /* @@ -542,6 +545,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 3ca3db020e0e..263a588f3cd3 100644 --- a/include/linux/kvm_types.h +++ b/include/linux/kvm_types.h @@ -118,6 +118,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 eed0315a77a6..4c4a65b0f0a5 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -272,6 +272,7 @@ struct kvm_xen_exit { #define KVM_EXIT_RISCV_SBI 35 #define KVM_EXIT_RISCV_CSR 36 #define KVM_EXIT_NOTIFY 37 +#define KVM_EXIT_DIRTY_QUOTA_EXHAUSTED 38 /* For KVM_EXIT_INTERNAL_ERROR */ /* Emulate instruction failed. */ @@ -510,6 +511,11 @@ struct kvm_run { #define KVM_NOTIFY_CONTEXT_INVALID (1 << 0) __u32 flags; } notify; + /* KVM_EXIT_DIRTY_QUOTA_EXHAUSTED */ + struct { + __u64 count; + __u64 quota; + } dirty_quota_exit; /* Fix the size of the union. */ char padding[256]; }; @@ -531,6 +537,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 + * lifetime. 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 584a5bab3af3..f315af50037d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3298,18 +3298,36 @@ int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len) } EXPORT_SYMBOL_GPL(kvm_clear_guest); +static void kvm_vcpu_is_dirty_quota_exhausted(struct kvm_vcpu *vcpu) +{ + u64 dirty_quota = READ_ONCE(vcpu->run->dirty_quota); + + if (!dirty_quota || (vcpu->stat.generic.pages_dirtied < dirty_quota)) + return; + + /* + * Snapshot the quota to report it to userspace. The dirty count will be + * captured when the request is processed. + */ + vcpu->dirty_quota = dirty_quota; + kvm_make_request(KVM_REQ_DIRTY_QUOTA_EXIT, vcpu); +} + void mark_page_dirty_in_slot(struct kvm *kvm, const struct kvm_memory_slot *memslot, gfn_t gfn) { struct kvm_vcpu *vcpu = kvm_get_running_vcpu(); -#ifdef CONFIG_HAVE_KVM_DIRTY_RING if (WARN_ON_ONCE(!vcpu) || WARN_ON_ONCE(vcpu->kvm != kvm)) return; -#endif - if (memslot && kvm_slot_dirty_track_enabled(memslot)) { + if (!memslot) + return; + + WARN_ON_ONCE(!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; @@ -3318,6 +3336,8 @@ void mark_page_dirty_in_slot(struct kvm *kvm, slot, rel_gfn); else set_bit_le(rel_gfn, memslot->dirty_bitmap); + + kvm_vcpu_is_dirty_quota_exhausted(vcpu); } } EXPORT_SYMBOL_GPL(mark_page_dirty_in_slot); From patchwork Mon Sep 12 04:09:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivam Kumar X-Patchwork-Id: 12973235 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 135E6ECAAA1 for ; Mon, 12 Sep 2022 04:30:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229561AbiILEab (ORCPT ); Mon, 12 Sep 2022 00:30:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbiILEa2 (ORCPT ); Mon, 12 Sep 2022 00:30:28 -0400 Received: from mx0a-002c1b01.pphosted.com (mx0a-002c1b01.pphosted.com [148.163.151.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B2AF1263D for ; Sun, 11 Sep 2022 21:30:27 -0700 (PDT) Received: from pps.filterd (m0127837.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28BFl5x6019399; Sun, 11 Sep 2022 21:11:14 -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=SB6m/uVEdBBmQOg4jHUtj5dP/AoBax2FmBuxXyKcya8=; b=rwovNXd9Vs3F9lwEqgwEwNfMBpJO1rf8jWVWUQgZSrmyYZps2ZXTxNpFTc3UTpMemVGh +rL8iSCdZluRza9qS/vGIKHfXYfbO+eKbpMoDmppLPBFNvVmJ1HsMLVRjKKyNw85nvJ1 SvQ3UBUCs7tm0utoG06b4QcrS29/M5lKOvcZ6/jGvwve9favOcS/S24tuUVMchr+M3Iv x5KS63/qb1tOgteDatHHN/Elezhqrr256NdbeK0siHasoutB/98ysFzPmeZCdyr0+uqw /8iWT4hHDaFPNTAASySptJmDqeC6AWVYE+S52z2N+IqNfoaAFdqjNJBaJ4eoPyiAjBVU xA== Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2175.outbound.protection.outlook.com [104.47.56.175]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3jgpg8ay8u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Sep 2022 21:11:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WwiESbkvNxsRg2EPA41726+oDP2+URnrO1k6XLc7XTRp3oOXpUKD+5HMP546yF3Z8Ad9/2P6ZbUXKeh9/sovpshLKeqrNOEWxomjCOjJJgMiulAiL9RUNLbI8HoMSKJKrbaIHgjSafqfyPdZgDuE/FD9LU23AQa1ecAo7kzCtHBioUoxVpolnk06SFe5CL1o4XjfWBARiy50st5PFH+y0BtuXC9lLbbPH9LAKDvbA/vMkzjZqyxe0WZFxJNy6aERtHiF13AssCSU7HcQ/xzdeMbxjb7Wiv1sE+w7fFJVZpr2Azt1Xo7GM2C6zQmKpNe61vSduAfiCBlaCtUKVwAfoQ== 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=SB6m/uVEdBBmQOg4jHUtj5dP/AoBax2FmBuxXyKcya8=; b=BAsdQt7M4NFMmhcqVTJn4jcIPH2ThL4ldD2W4TLWNKPt0LWsZGbr/kZ0ceCZYghzwRm+BWS6eyZIrtl5u7luKCRvg5MoEJLO18TWgOGevMLiV4WczZmHqNCQxhKmtOvo2d8E4n2jdLMxCLGqjQEKSFhz/HEK0sn7eLS2jbPUmVUGNwPZdbbJRlw4x8k7mvn5CnwMSmQsPX6e4rn/VAl0OHXlFsupC9fElfSQp3rFUT7JNIw73K/+wtLeU6UXAS/+026q+OnhZhaXj7OZKwYaG6Ssn16d1ZjKu/nnL9d2gO3ESlbkXRf9cA+IJYNeOl2oaT0ZpLM9+5lO7yhi4+TJRQ== 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 CH3PR02MB9116.namprd02.prod.outlook.com (2603:10b6:610:144::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.12; Mon, 12 Sep 2022 04:11:12 +0000 Received: from CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::bcdf:6d6f:e6e:b9cf]) by CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::bcdf:6d6f:e6e:b9cf%7]) with mapi id 15.20.5612.022; Mon, 12 Sep 2022 04:11:12 +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 v5 2/5] KVM: x86: Dirty quota-based throttling of vcpus Date: Mon, 12 Sep 2022 04:09:26 +0000 Message-Id: <20220912040926.185481-3-shivam.kumar1@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220912040926.185481-1-shivam.kumar1@nutanix.com> References: <20220912040926.185481-1-shivam.kumar1@nutanix.com> X-ClientProxiedBy: BY5PR03CA0025.namprd03.prod.outlook.com (2603:10b6:a03:1e0::35) To CO6PR02MB7555.namprd02.prod.outlook.com (2603:10b6:303:b3::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO6PR02MB7555:EE_|CH3PR02MB9116:EE_ X-MS-Office365-Filtering-Correlation-Id: d64fac7c-8d7a-4d0c-113c-08da9474d460 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: Dcqp/nRzx+HHmy+EWZy5aqNod16weOBxkjIowI56VPoQCLlfX3WbTFa4+lYGRXVYrx6IvvC8Y+7f+F8SjXz3jpURkqp380m69+lKoC0B3bRJmnVVeUvmEjy7zLluWUYTaj3pcx4l3XdPKURao3ppz/X+hJ15fVg7wxeA0Hf5xryqk/qSTKgRGUYaT8xNo1Lhj9dZRRYA1/Dm3lp3mnVWug7Jw/YNNLmT5s3D9hHJEkAMh00DBBy4T5u+yvsGJklWESns+Xx21l7s2BTpF5CS1NtnjeXDxp6q5ZZuxA7dn/iu8Q+rGa3d/U0R8SECjavTwcq0VJG6zQfr3URDZNKteowQSG2tWi3o4aSyYnbobUP0rxI/lOd/aFxUnMO+ofjIv0J8/mtydhtY2wMzllGm4K0q4/tWZA7guYhRubhFBzFc+CFcT3A90wGC+UVsDWZ6pAGXeT/7hfADMl6nG0uyXYS8JcBmsZFj6yxTyz2GKDgl/+qasUseSMrubN4KN/+nl5ae9ZukMYUUFt67YexhDmpxnAZwOXCtrqoKfuPr24k39XolD5JO5vhvncvZaDpXMLKnvXkmzwm3BiUCGx5ZrzqmcT3/43+fm/FzeGzRL61cjC5dUO+i88FQQn6mVZRLrUjHvjA8Bgj4+JkVwwStY94K/dcXGVC9iKrfj5Ib+Q0MPUTJyyJw4J18nUT25UwNQ75IFbMsdKWaO9A7s/1IviETYbZY3U/BvfVNja5nQ0lKa+HBVumsnHbVECFc/1g6zduEyhOmA7uM3fSLIZTMrIuVEcqD5hfbT7vu8ScYwgc= 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:(13230016)(396003)(366004)(376002)(136003)(346002)(39850400004)(26005)(107886003)(6512007)(52116002)(41300700001)(54906003)(86362001)(6506007)(6666004)(478600001)(6486002)(2616005)(1076003)(186003)(38100700002)(83380400001)(2906002)(15650500001)(38350700002)(36756003)(5660300002)(8676002)(66946007)(4326008)(8936002)(66476007)(66556008)(316002)(14143004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: s0irz+HC5qr/NmrW2B46FudCNvVV0rvsSWBQjFdBdQJYneO9/blYC6SS0lMGDYwlpNgozOYI1CR3CLRcFBl5sG/3QszyT+/23hRd87E5wwkcPjqmPyXCvdgljqoCkZluWxxGx+QCTis6ls49zyfmPylXR3c1HRQxz9m/jn1SAMOb2cut+lkVQW4WiSrcj2Ekyb7w/089cqmwqtenCqr1RSfPXKwaaIMPZJ6zbk0GVicuZdjySLtu1vWt19yyengWZ2uC22sev8gbR8nO+RFopTz78y/yAV2i1Ah9+CMFG7/udqf5ySFWf2nFMuWqk0PseUBoKTJQnzW+VPteJtLeh9HoCHuExDZblQaedpb10JC/JG3W2Ju5I7mvLy4WOvec7YdHa/QMrGzA5Z0pK21jcZjav9QckpRqCYqViKLigeDyp8ThyogAKgPlPL5fnmoUVTjcqyU9of94+t9A/iyZKvOCNqo3N9q4GsE+VgpogW4Dg6RqhmZemUafAqxYAYSKKrai3mWv9YQ3eWWkHvsYbE04EHSLh39T476zCi+blpPwZD3b4I1tJCeTb7xKq5c93CWtmoSRnnr1DpgkdMpfh6NokiFRmARxaiYSjUTQgNt0fnwWsMmcoJIRERKRqrnm9qFAUTxGOVxuPAFyQ4rAxcMesyNoWyVAe4g0OLa33Np+o39RSdSniIwykyizenDXUPhXQZD94S3dAS0ATm8QmosJG0htzFqljC1m+YiW8AhVmNVKEKtmddtjgKCWR/rGPHtu5e+cn6NyBp5QmMl3Jqmqw1E5VmErYwkNPNpBeWRCj7Z9ooJ+n3dBqF91TdUwe0mLayQEsjxlG8FQG4nCFSOPgnjwfhzwKsmq4Pk8yM9V3p8gbseU7nXehdrls0ueBhFlcAtv7ysRNuSsGtiCa+qwcLLJtLFXJNZWwPSvnAqDQAbPJ8TLSLW246aiErZw8mxfm1yuwUxohu46bvZnaa4ph8mlNq+eqINr39h5qAXo64sLRnYt+F+jwahM04NHp0ssQw7BYRt3+VqVteFwS0pZ2HovwPmR8ICXhVmOXkVaC1vf2LjdfDOBmtj6c8mWjyDV36CJJowvtCb+Y0t1kMYtkCJXNAmDeB8SQ/62ZkIPeGP+vzhCi6ghXQOSjiKWvyAO/jnvb++idg9+LQa/v+7stGaxa+isJm3402oUZY6TaTAKX/flwnBmtBynm0afleCvMuvxsLwGSOO7FueHU3//SMU6DCXOMemyGj3w06vcqVyM/AEp0cU+W7lJ2p9fw8MXXvQd8ErFU4rxHDaQ/wDzNePCYCWGm5Gqj3m6FVupEA6RB4ZngD6jHaCljYIsPZcbXD5j5PzceMu8fMwjxoQ/RLcbbLdUfYATofda+GrcIcDcMHJymBQx/vwix0FXWwSL1nwTQBe8yqiKVAchnxAGGD6oX0bxGTQVxToeRkTEYlpy/x1kmcGMxVxU3AA5nyGiMS45+RCuhI+vjZwGEvwnA7/PUVAXLqx/fS3tATdJYU1YXJ6L4Ev/SZqof5/JP1dCVyKpJpLZoIVTeKlPLFCsLjMGULIDqVVxBTeI7Ajr64atobKRW7c7JjaeEQZOpIYd7Q6jlv3ily1Cssj3lw== X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: d64fac7c-8d7a-4d0c-113c-08da9474d460 X-MS-Exchange-CrossTenant-AuthSource: CO6PR02MB7555.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2022 04:11:12.8091 (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: Xj0Nam/epXHluIAbeehiOHDkQ5El5S7nDH/zbsuUT+cNp46DT3YvL+0LIN2wrpohEHEexznY0BuwdOazJuTADxa+S1BMLVpmxOJ75PLZjMw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR02MB9116 X-Proofpoint-ORIG-GUID: _Jaqj9wPGznULsABWjnFW7so5fr5oLte X-Proofpoint-GUID: _Jaqj9wPGznULsABWjnFW7so5fr5oLte X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-12_02,2022-09-09_01,2022-06-22_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/x86/kvm/mmu/spte.c | 4 ++-- arch/x86/kvm/vmx/vmx.c | 3 +++ arch/x86/kvm/x86.c | 9 +++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c index 2e08b2a45361..c0ed35abbf2d 100644 --- a/arch/x86/kvm/mmu/spte.c +++ b/arch/x86/kvm/mmu/spte.c @@ -228,9 +228,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 d7f8331d6f7e..9499c7566479 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5750,6 +5750,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 205ebdc2b11b..0b1243b598c9 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10362,6 +10362,15 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) r = 0; goto out; } + if (kvm_check_request(KVM_REQ_DIRTY_QUOTA_EXIT, vcpu)) { + struct kvm_run *run = vcpu->run; + + run->exit_reason = KVM_EXIT_DIRTY_QUOTA_EXHAUSTED; + run->dirty_quota_exit.count = vcpu->stat.generic.pages_dirtied; + run->dirty_quota_exit.quota = vcpu->dirty_quota; + r = 0; + goto out; + } /* * KVM_REQ_HV_STIMER has to be processed after From patchwork Mon Sep 12 04:09:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivam Kumar X-Patchwork-Id: 12973234 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 81126ECAAD5 for ; Mon, 12 Sep 2022 04:27:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229531AbiILE0V (ORCPT ); Mon, 12 Sep 2022 00:26:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiILE0U (ORCPT ); Mon, 12 Sep 2022 00:26:20 -0400 X-Greylist: delayed 627 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 11 Sep 2022 21:26:19 PDT Received: from mx0b-002c1b01.pphosted.com (mx0b-002c1b01.pphosted.com [148.163.155.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B007E1C908 for ; Sun, 11 Sep 2022 21:26:19 -0700 (PDT) Received: from pps.filterd (m0127844.ppops.net [127.0.0.1]) by mx0b-002c1b01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28BCIHA7020506; Sun, 11 Sep 2022 21:26:07 -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=39Ppz8D5yUE2kLAAbJqLn+DP2snZCikuOwcRuOeO2W8=; b=DfSwCHtQNex549YcamMpg19EmsNwXAUpYGaQEvStLcIWsAr0rz7wvHkFWekbQZoQQIoL LmkcBxBsVpbU9BY5GWPw3z7EWc5mZc+BahFLfDeHA1UISNkwak3GWKtomyIELsLAyIba hK7k0/cB3HcPMPqeKvifej/AYeBFT2ZlzxkT4/M01I7V6r/lxkw2/LtmMJGiRRu9qiA7 jQYOHjTm6t6QRD7CJMm12D4ryZcyT2ZtsrHaoIFkx6lNMsbNLUSUA+aVfJkRrcA4Mdm8 4zoPPhr4GO4eeWQgGGuRYT9Hn6dKPeYirN4SNuWgjmMq0277ZIsjdjph3oCI6eSzSQqF KQ== Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by mx0b-002c1b01.pphosted.com (PPS) with ESMTPS id 3jgt41ap0n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Sep 2022 21:26:07 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LiJ03uS1ZNJxEP4AvOaeaV9AXE1a9/kPE4mIe/6Wbmg9m1q7nY4F2XjTxLdKidZRIL+nd7dc49QJgnL42FSiBFZgQ+z0YtP3cD7pv75IKZH2cCr7frfUnrh0bZKp8L5pyt+49WnFuiWZT2qFC44WUz63px2TFa3bB/LfNRyCSQ811xB3mrfiNNJWO2FKW6YaqHyE+uEuEuzO7DZ5Bp6tx5G6PGrYHoLXDvv2JIGF2m8RvoRozFTVnM8gyny8ocYiNph4cXNBNtB/WRlghyQu4m8WvQP4fCQHCwKyzprgMvVIt5aEDqdaRpiERtgs8TQgjmYO6f/3jeDA6oFCxCAwlg== 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=39Ppz8D5yUE2kLAAbJqLn+DP2snZCikuOwcRuOeO2W8=; b=C45t8B8FEB5n1o+V21l7k1ROkm8OpLlOELIhFUKs2O9ZlqCyO0gcy0a9y7MqZX6eZwWeUst8dxd4IfRzFla5GtlC7/rXUxwCd+ODg1lUh2THW5QAsQ60vs2VESneWc5JZ1I4mOMtAKAzdPrrbfbHa/wY23bhwAgsAF2Pwbj+0rugjG0k4UZhveAox2hrn3HCQtA9AinysUIeAU3l5PdpB28S6oCQ2KMmJwKsw+j451BbVOV1GX/+2td1lTADdDZrHTOYDOlnLP6UlfDQ5fK3h4ZCloXAaRuJzceZsuvYlbDLbMvSWHLkMtakQKY+vyPbhL86D9BhFzFHCbsfRhbUpw== 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 CH3PR02MB9116.namprd02.prod.outlook.com (2603:10b6:610:144::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.12; Mon, 12 Sep 2022 04:11:35 +0000 Received: from CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::bcdf:6d6f:e6e:b9cf]) by CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::bcdf:6d6f:e6e:b9cf%7]) with mapi id 15.20.5612.022; Mon, 12 Sep 2022 04:11:35 +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 v5 3/5] KVM: arm64: Dirty quota-based throttling of vcpus Date: Mon, 12 Sep 2022 04:09:28 +0000 Message-Id: <20220912040926.185481-4-shivam.kumar1@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220912040926.185481-1-shivam.kumar1@nutanix.com> References: <20220912040926.185481-1-shivam.kumar1@nutanix.com> X-ClientProxiedBy: BY5PR03CA0025.namprd03.prod.outlook.com (2603:10b6:a03:1e0::35) To CO6PR02MB7555.namprd02.prod.outlook.com (2603:10b6:303:b3::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO6PR02MB7555:EE_|CH3PR02MB9116:EE_ X-MS-Office365-Filtering-Correlation-Id: af5a38bc-75f7-41d4-56bb-08da9474e1b6 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: zZVj/KkEA3swy212UdyU03yOF2jjqY/L/1QymaYjSwgf2oMX2PE0RKtUkzmyuxAXA3rV1+A0HMXebYZ/d9XFpLWhx3YI99HvX0oiYfKuIvx7urgwtQFh3a/gGJW924hze8++YTH5j6gd4M7ZPCnxaz/ZmbKZFx9XvZj7KPCSgBmZ5McIG7zq0GfhbGNoz/F4vr41JhCNtJvDHy81lmEWLY0T4fKHaJ8mVMUzvD37OUfLHrmY2aiH+G9kJb+H4wnNgYUHYQ4MetmoTssG2mk9qiVmvN1JPJPmPBQaTKykzvlpBdgRdgypWI/kS1MrBKyFNc8U3E7OJhupBTD4EM9qrRB86LThDzv+cJDUCjKiewpBT3Aj1KUG76A5dX91ZgfspgADOmlMKKe3R3vXf/TyxvKc1eHK4s35S4gnBhlxfCy7yGI5TeWcjxyMMQ2kjo9cHK+LiLmCjBJ6U0obb5J4Wbp9T5medyX5O+urMka+loP7MUxNf9a4XBE5cYV6uduhhXEp2+rWdrUvOGwvMY13KnF/28IRYop5pXKUpJ5q1u8mvi4k1VshlNabjAVHut0ikjBgHfI1+gc4LLntER5EJKouxgthpjmxKyOR4s5Q1lmf788E//JSYWVUF4Qo0TUfE3anWxOuo75cCbHwvnI1PUT9w+7OFOSkcdXJiB/80Fo2oWUwqdVXuUyg9u80VZs1PCtH3CKSBqfDNvfyibRX9vfInhRBRJ4d12Ow1PWyFW33h4T3YOwhWJUGNkrUvm7xR5U6vqbKHEEVPmen41eguY6t7RfqVmC0SDHVSsEGfeM= 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:(13230016)(396003)(366004)(376002)(136003)(346002)(39850400004)(26005)(107886003)(6512007)(52116002)(41300700001)(54906003)(86362001)(6506007)(6666004)(478600001)(6486002)(2616005)(1076003)(186003)(38100700002)(83380400001)(2906002)(15650500001)(38350700002)(36756003)(5660300002)(8676002)(66946007)(4326008)(8936002)(66476007)(66556008)(316002)(14143004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9wZwdKP6iNhK20p3sY8IYLyCJ3t2XB6gbPpwfncL46Kcd9Q8pMd37zBNhu8T+SOYIP4j7j/mEzTaQjmPjRV4gHl67rKMVIHaj5O+b/FcNgNirCDRi837ZGutCmQX5hrJdYTnCdAZtkADVxx7ZQ+Dh8JJG3mmAIpTv3DHHdte7yqFFhU0In/e+IbBeU70xR4cLXus4hVzNp0ot72WXMVcrWa5ZRgje7LNYnc07mkcNRDPA9S+hJD2E8ziIJE/wNs+esZh7yCphp7VrBRkIrTTZDA3uSiIsb3axvUudQj4BhWc6hUA6VcfZm1ipanzZd5XjgtNTGHVrSAtwxFGltQ31LYIMnSwXfVQpK+C6XtXaDFhKbxIGx+QefJpBay85rG3tT/bJ+mO85zIkYTeHcjsBiBndUuiuSUOWoYqhQdfCfh1IEbM8GFHVh1ZMvvSs1v7YteXOuJxNqKBN1T7edpwuz0sY/4Tp5hcoDsPfcGn0H/SB+VBDjKOvQKmNpDlbIuT0Ac8sncHKSBCd/QI89nZFtrRHRUn43h46er+tJnNcRqS/GVJdBmnXzJ02UBfeE61SFOyQhHRvjgTRiRZJHQ0nBauIwHLuDwneC5+6N6gL5/xWr3JRb1cITMaYCX6WQz5tG9q+wYQw9tOujJ3ynApVpHbjnLpCV59Sy6ZUmCNeATMdvliCB1VuqT6QWf3/LaZNTiv0nMAs7gjDXgNM1Ne75bEZz59XnaIS/iRKk557xtXgauYhAn+lFRanf4LIW2FSv9V4wetdZWr65Ei67W6u5O4W70bT/8wlDAAQLad5m73aySEUbJJWUefUjMnQWaEOt47Nsnx4f0rTbqN6YPOqTS94xU6joPYO37o2iprC3hRizR+T7fhg+0nERNSgWlDoC7Qh/XmPNc7zt2jQJqiFbj7OhQYg4yKGIQvSQPXq9ZN1KqaOG7hRCAUMIUjiEy3Nw6onmdehXAxlkr/uXVsO+btq6B0RINBL7pKpQzVQjHOSbHFM7J5s8vv+tZ6Ijf5GtSxHSGXf4Zim2Swdm8+v4mhNOk55tvw3s2d/loVTCcim4wbyQpbBgtkeswwTA8eM6RWnqxg36lrQWxHvPfSZjFISFadzh2iLbsm2UWlLNZ7tzxIm31ZBds1C5FRGMmSDdks4/uY7GNG1eBkgA3FBp97+MeXAmNzdi/vTV4hcCGrpkfviXwBwEK/DD/eID8v/SgXLDJfwfxl3vgAu6Cyfc9c6ic7zRzuDNhDy0ruG1Kf/pofHl4oFpor7kidRgZORVmi2aIltsZX/tj6UZJWCy0QzGxF7vqi4U59TxP9NIuCxWIxHm6bvmkkgPRSzjydXRGoRH+5KnF7MqpM4K1OnEsUd1mGWEs2k5hSn6bQkYQ8INMEX0KUffa4GNt2GEKoNC2wYZgnvO7z16lyv4YIjvQmPbJgJ1Df1I8aUa1D8sv3LJ1IgzzyXScZZku4gu1y7o7P730m5pe/nnNi9L4O1cOtZR13G0hco0vpzHt3xKsd2VZvuizMczMkxU1mqpzScEp2MZda93TKfgr9Cyfo9BLPLtVAEm9i1p0S5AxuTGjI6bo/gcKJrL0XvoyeaU9OpmkKmcACB+X+3y1PE8gy3g== X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: af5a38bc-75f7-41d4-56bb-08da9474e1b6 X-MS-Exchange-CrossTenant-AuthSource: CO6PR02MB7555.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2022 04:11:35.2161 (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: bh8l9T/vj+RgjsKhboTRbL0g7w5aI01EqWtlGfShw94FMH5FaPsGjkYFDMs1X06nNfgunDpbixAgml4F0KUDhhVd2AodE/GrCIsmXn4tyzw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR02MB9116 X-Proofpoint-GUID: DAdmWfm-yvtz_GTsG4Gc5G5BL6jISEVY X-Proofpoint-ORIG-GUID: DAdmWfm-yvtz_GTsG4Gc5G5BL6jISEVY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-12_02,2022-09-09_01,2022-06-22_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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 2ff0ef62abad..ff17d14aa5b0 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -747,6 +747,15 @@ static int check_vcpu_requests(struct kvm_vcpu *vcpu) if (kvm_check_request(KVM_REQ_SUSPEND, vcpu)) return kvm_vcpu_suspend(vcpu); + + if (kvm_check_request(KVM_REQ_DIRTY_QUOTA_EXIT, vcpu)) { + struct kvm_run *run = vcpu->run; + + run->exit_reason = KVM_EXIT_DIRTY_QUOTA_EXHAUSTED; + run->dirty_quota_exit.count = vcpu->stat.generic.pages_dirtied; + run->dirty_quota_exit.quota = vcpu->dirty_quota; + return 0; + } } return 1; From patchwork Mon Sep 12 04:09:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivam Kumar X-Patchwork-Id: 12973232 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 AB191ECAAA1 for ; Mon, 12 Sep 2022 04:12:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229463AbiILEMP (ORCPT ); Mon, 12 Sep 2022 00:12:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiILEMM (ORCPT ); Mon, 12 Sep 2022 00:12:12 -0400 X-Greylist: delayed 83 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 11 Sep 2022 21:12:10 PDT Received: from mx0a-002c1b01.pphosted.com (mx0a-002c1b01.pphosted.com [148.163.151.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC74E1707F for ; Sun, 11 Sep 2022 21:12:10 -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 28BFtwCR010580; Sun, 11 Sep 2022 21:11: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=YyfVSbyTRijCayA0e318Az45XK6QFnxj79/isEOk73k=; b=drxxjrjaQE8pQgCoogfxu6V+06npzP5we4hB3f6pMy5pJlA+CdJ0QpI6T4wVd4ijqNRF 2t641KtmrKuWaLVmw+dZrxK/a9W4ToAOidSLI10Vkb2vClgXO+dltHlQ/AmtlGjgllxh A7+lDXriqQFMCQlaPainNq+pAweGE63zVvRrXKiiBbPn1Jn9YnPoejFDhILYEQWYnpAQ bzWiya3hsj87NDScMKs4rHKZgwisZs+dLFq1gO0uWHu2neopHRxyDS5JKOlCptgl9OmN FUNSYQ/VPrX4JsNFeg4pI8x+u573h8B/IdVG/BX21o6Yq/Y7H/E0e1xvkWB+90E75/75 jw== Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2170.outbound.protection.outlook.com [104.47.56.170]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3jgpwtjwjk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Sep 2022 21:11:56 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ASqIOp1Hnpn4NcaRrWeSddptHaLoZGxtuI+FRAUaYo2zr9BoSv6Aw8CIiXCEB9T3DWBr1TbSogndbZGSmC/mbNN2of7j75QzkUzDy1diO0ohiMeUZgDRztQ5AgJp75Rvb2JoV6gca16Lj+wmOnI42PiMfBHDTDRUaBzRy2ppVJf5M84Mnu8XWfalhTjjXwYcFKQRdCGERMKHaSj9INOwQGShhkWoNUeBd/fNPHnLyEJdvvXJ3U2BZdrbZo1b2CmPXUCEChHxWuaJdxf/F7ekhhNkN7eR+zWY2NxTv6k+/EzDKX9uzzKRVf5qmdJt/nwxDqX7AMSNjSfMQxE0uFJQvg== 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=YyfVSbyTRijCayA0e318Az45XK6QFnxj79/isEOk73k=; b=eE8su5pk1mHorKu0BwkagwwF5bs8jwdt2+MRYoMt/XF3Pdz0CSYgN/0ywvgY+90NX+JKw7LOkkeKrkRwmlxVHqvnQcZm1KEFJfNKpp9hTC76z/8ggU5PNtXU8Mlm20kqF9lkOaMFnzIGlcO45H2bo4YJQBgchC8L4CV5I2NxhpU9no1fYoE7cIvsKFmjluNhTVK4Z96tXhXceZUo08YqNPwcXs+qaq66bwmc5Enbk0o7YCnoxopfhG7w6Nq2tMsEl3+srq0RRgdY8G926d8tnTzbWOpi80J5q/Kc94Rjv5QzEZRGZ8xrFKsKHw1SXc4oroVhPf0PvWOKZDYKCfARjA== 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 CH3PR02MB9116.namprd02.prod.outlook.com (2603:10b6:610:144::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.12; Mon, 12 Sep 2022 04:11:54 +0000 Received: from CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::bcdf:6d6f:e6e:b9cf]) by CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::bcdf:6d6f:e6e:b9cf%7]) with mapi id 15.20.5612.022; Mon, 12 Sep 2022 04:11:53 +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 v5 4/5] KVM: s390x: Dirty quota-based throttling of vcpus Date: Mon, 12 Sep 2022 04:09:30 +0000 Message-Id: <20220912040926.185481-5-shivam.kumar1@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220912040926.185481-1-shivam.kumar1@nutanix.com> References: <20220912040926.185481-1-shivam.kumar1@nutanix.com> X-ClientProxiedBy: BY5PR03CA0025.namprd03.prod.outlook.com (2603:10b6:a03:1e0::35) To CO6PR02MB7555.namprd02.prod.outlook.com (2603:10b6:303:b3::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO6PR02MB7555:EE_|CH3PR02MB9116:EE_ X-MS-Office365-Filtering-Correlation-Id: ddf8d74c-9585-4ae4-8b41-08da9474ecd3 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: yv206G8/exW4SGjcspFdOU3DDLbtNTnfV4ksfsNkzI1yAqRN0zBkhKXOgrZisUB5n2pJ4CeRFwvpgTClfJmSp1q51THh9/gnJdxnEG1ujg21CtCV9Am4y8d6hkboPz9S3mtXUro6kNhaGnQSeEkoKJPizjbg8BwZHr+S2s8IgMMbHLYnqqu5nqnVpavuW3EU/9zViqBegWNhOkRzQ8vczwZnKh/L/mWeJOiCwTrDDwMUPXWjjBIxNZJpCmiR6kN1ABmdP+theHzixEyfRhfNGFOojTUThF3ELESqJLUpQhKuY6D/3WPUlerLnFUr2HgVSRR5Xqq3FG1Ke1vkzMj2zixYsj8VBULsZefq3PBdJ/sc2o6jZuVnu3VWB+dBT7NyF6CJ706t9bItl+TU/vRGJndetgKQj5UgpuCPeHDNIrWrmg9luoxjPIZDukTkYNW2sfG0lbnatT/yAzcw4hWgGLNJYBC9vzptVaFMEqMyoL291+k1CdndvaLXdnWWbjwzBMs6BvTZm4z6astx16W8fCtIEHU2NbpqLDcuUqRsOegjXOShOKgZuNld1z2/hfd+injq3P1eGU1Rza7G+zZNOnCPiRyN1YqZPF42O7D+nx+6JssG58MqHyGEzCzeOM+yOZub5nHn7H1gwQdLhz+0ZnqIvBB8uKB4Z8WG/Bki+GOlk6dJHxrYntQOfmrXetLE5qQIBZFb0y973zsZ7XnWsB7qtYmu2NojSk/kn4KOCDplqRqgdUf+YZ8r3sp+MpkTSZBQZkYuO9p6c5GkUAtlb0NW7fFzqhSOPSWloefo1SM= 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:(13230016)(396003)(366004)(376002)(136003)(346002)(39850400004)(26005)(107886003)(6512007)(52116002)(41300700001)(54906003)(86362001)(6506007)(6666004)(478600001)(6486002)(2616005)(1076003)(186003)(38100700002)(83380400001)(2906002)(15650500001)(38350700002)(36756003)(5660300002)(8676002)(66946007)(4326008)(8936002)(66476007)(66556008)(316002)(14143004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: K58VUO6qY4BzWa4fybRh8PZFW1R5ZNMq9nQwlk56Ps6zwQ79rgGWT1Vys5KIVc+FNDbEvU3J+3TiyKZQWj0bQ/OaQ66SXMDstC293a6SxEalwjaXnylR7Q1YmCdw7WS302bbqn4hpWY0G3zgYmu3KoEtWpYuOnHMjesWOslz6avqUPaSe2KSoq4SHvckSDBR8Zr032eRRiL716lyqHE9cdl81TlYPKPpdAh/vDQu4Yj/4wzv43eLXFTvOqHsjS3O7xSpJpowW34T7jHZACGck7dakVKKmtvVby9t8H/yItTEKtQID0lXofe0S8tibye/lY3/ORw3VfSuGfa7xlR5lQXQIM9APADpNTXWcAIIXY2A6O61dGF3VEFYq/3qaZpUnOK1H3carf7THvIHl5DptBz80CQ1BxF7WJUl6k6A3F1y9tSVPF4G195ZQYA4qGIuTMibBRWSENo32gpkfoAYn+ygSqzHWMaqZB93aEQixYSiRPD7/7chIBwxWBV69d5RD1h7WGi7zvFXzmaDf+/QH9XiKcx1pxNia1K/1Xny4dRXSaO339wmrG0tAyDQY6j/lN/D6ZZ4Z2a61z50lgaWhz3c8BiqfXGsj5sWK36wMkz2/Iu7HKhJzWNFH5T7LP6pnxnJMQV4I0/L22+Y+FB6spnKXSafWUPCQu/5WlIyodNeq7rvo0Ex78CNpVDHOini2qr8OhyxhZzJ+GFX75gXLxM4qqPon9nA9goWd94AhcUtqBHAHb0DRiW+3q+quIhjO/U67sqx4jXhInxvxAdkw8RLXTEOQr089vJzfshC6/ugVSTowQvrO/ZGyHUw6q0FXZGgMcfv7CI0Lo12viNm+gYBkhNASGqE5JAWgz9glj7H0Lfi7Hq0wFUh/ZYei/WsHqxK1imM1o5hEw28pkdD9Cyv9aTiEAo/nKKU6CxZQ2q4zVRwl/Z5v2ABR5RbkEPL7iOJXNYRn1kVTWJQRn2eUV3QudN4At+Cwagtj8TX0hw3COSxdkJpTh96ASKeWWeezNHxsur1pMzXnqlPNaVSmghEI69zvKFx6KE4OJnXbAOlLT9kAlQvAy6kcRXzmneKh0a/pv0FJ05dXajup9RXt+S4R7ydZ7nC7Aq/Se2JBE5npYn9e56qWj3Vj9HYiCQZN8wJfmqsRVPeOwf7FZbzZ2kNRsHrr7sGNWkuBTueWHxB0SKfZ7qho4XsrYSoyiSzGuSeloNgZ0Vw92b6/t02ASYRoeFsKIcScehEHocEjnGGYwPFBmgClgtC0FukZEhMKwLBGhIP3j1Y/KZhqbG3CYe7SxQm4z9Mt1dkENmS0E6zmKCWLBFDh0SmMjHmR043aght3yf596I7g3W32MefswCXs5x2CDWkeSVwZrqjSQvsDJ4B9IR9U1Z+gMxDrWnQQ0/cTQExvamV59Tq33psPwatTUekaKK9BESn1SF0y4TxIlgyxtXtG5PNmEMC0W3d5xVoQlKxXe709kwpzThDPVK4BaQ3dSMiB2yi3tBXnyqYjzfPcFtezFAvmjYE8yNSxa/EZgtc1Kd4NnePZ69bVfoziCs07HAzCwkcBaD3kfespsT780sVXF3Ue4y0Ww10DOlBLugfCgZP8oTNiSwWxw== X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: ddf8d74c-9585-4ae4-8b41-08da9474ecd3 X-MS-Exchange-CrossTenant-AuthSource: CO6PR02MB7555.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2022 04:11:53.8625 (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: 2XzvBzRUNPgqa/Tl/4op3iBtrU44SaqSBbHpX5qoh1YD9MHi92xGQw5pXPzcoHvNWS1z6Ps0iKOmKPB992fFRWMTU5LDzjQrySOuS5YZcbs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR02MB9116 X-Proofpoint-ORIG-GUID: ZYMZ54Qj4rMpxcdAv9nkIgVEhLFvamtC X-Proofpoint-GUID: ZYMZ54Qj4rMpxcdAv9nkIgVEhLFvamtC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-12_02,2022-09-09_01,2022-06-22_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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index edfd4bbd0cba..2fe2933a7064 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -4343,6 +4343,15 @@ static int kvm_s390_handle_requests(struct kvm_vcpu *vcpu) goto retry; } + if (kvm_check_request(KVM_REQ_DIRTY_QUOTA_EXIT, vcpu)) { + struct kvm_run *run = vcpu->run; + + run->exit_reason = KVM_EXIT_DIRTY_QUOTA_EXHAUSTED; + run->dirty_quota_exit.count = vcpu->stat.generic.pages_dirtied; + run->dirty_quota_exit.quota = vcpu->dirty_quota; + return 1; + } + /* nothing to do, just clear the request */ kvm_clear_request(KVM_REQ_UNHALT, vcpu); /* we left the vsie handler, nothing to do, just clear the request */ From patchwork Mon Sep 12 04:09:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivam Kumar X-Patchwork-Id: 12973233 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 93051ECAAD5 for ; Mon, 12 Sep 2022 04:12:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229517AbiILEMb (ORCPT ); Mon, 12 Sep 2022 00:12:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbiILEM3 (ORCPT ); Mon, 12 Sep 2022 00:12:29 -0400 Received: from mx0a-002c1b01.pphosted.com (mx0a-002c1b01.pphosted.com [148.163.151.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 438CA17A96 for ; Sun, 11 Sep 2022 21:12:26 -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 28BFtwCS010580; Sun, 11 Sep 2022 21:12:13 -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=2ruFcqmhurpAOnfoBpr0QPVZrCJT/wNpd0j3CjSIO1k=; b=HqTJRUYpksA4IRycwDCdJplraZ2hTXMIhXMtIuWEhcWj7JzJ4RfAwACFhiMG/3W28Iet yKhAMOg4CJ0DtxolhNreuB+WIpPRS8PmUr6tCdGOxM2jUvoIcHVu60n42xKdLsIKrcru WaodV7EMc8bj9OJW0kppuTfKcq2Cfr7qwSv4moR1Wnvu0FRVaegQHqN5REzZi8PHku1p USP4YbCUmvkIxqA9FIEw//ws5d87EcXujBcIyD98gi4mNhpyiGYH77Q6fAzQMTDG2Dng g5hvmewbVwaMpAPpyXiVTZzJLcmtJL9k+2CKs4yNqtvvUra8ZwL7yMPYiDgXkK8ZkvIL PQ== Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2174.outbound.protection.outlook.com [104.47.56.174]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3jgpwtjwk6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Sep 2022 21:12:13 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z8IYb/5BF/bzrpq3gFbCFINwMdw/L1Eo+A3T08oUgf/N4hwnJdr7/K9OU7EJK2Ig+q6bZeDy3KT879wHdJf+PR3L0yBVEBWqbxk1WP9hN3bQGGg010+Y7fGqjzj0jcyLT5sfOPz7rGZMMF/9OuppkXYGfbXC4D7gIr+Z6ggpbYpIkrsx7XDdodYAVic1pWt3WH03eDElgmh1AWHodT1fG4aq3RcgrTHIeG2UfFaedFM7Zdrh0DkUbZGUcPLfKIeFUaKhL2fZWPQ+9+srEqTSNhcY4J+AUjimGsFvMPizy7l+CWpH9jhVlHH/ZY0cy7ulR1v8SqmUXQt4rekT9rMdtg== 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=2ruFcqmhurpAOnfoBpr0QPVZrCJT/wNpd0j3CjSIO1k=; b=K7O3pKFX2lI7iuHpM4K7lqGTg3s4oUu/0UGHFPLgPB3Y0e39anjqBEG4wFP1U7UxUK10oGsWGyW7w84WOPYKFOLQ0Gab4AfmpxYQFiKheXPPZF4UDB++8QxgoYWqRj7kDk0SGCVNP7RGDDj/WgCGvy9ZflFr6xpUjacwX15Po+33b5VB9+WgNQHVSffn2NeYW7rJzlc4zVFy+yDCg8kWkggEfGeg85ek2lASefeJnzj4EQQ8SciX8YA2YzxSWDLBdeJ61HMUgZ8zcQEW1gq5vM7G8qYBKbvGTirUHVu5+lybblltcLcfft+kaG6qGmyjm5jpM6ve5hzyuHc0Fhk1Xw== 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 CH3PR02MB9116.namprd02.prod.outlook.com (2603:10b6:610:144::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.12; Mon, 12 Sep 2022 04:12:11 +0000 Received: from CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::bcdf:6d6f:e6e:b9cf]) by CO6PR02MB7555.namprd02.prod.outlook.com ([fe80::bcdf:6d6f:e6e:b9cf%7]) with mapi id 15.20.5612.022; Mon, 12 Sep 2022 04:12:11 +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 v5 5/5] KVM: selftests: Add selftests for dirty quota throttling Date: Mon, 12 Sep 2022 04:09:32 +0000 Message-Id: <20220912040926.185481-6-shivam.kumar1@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220912040926.185481-1-shivam.kumar1@nutanix.com> References: <20220912040926.185481-1-shivam.kumar1@nutanix.com> X-ClientProxiedBy: BY5PR03CA0025.namprd03.prod.outlook.com (2603:10b6:a03:1e0::35) To CO6PR02MB7555.namprd02.prod.outlook.com (2603:10b6:303:b3::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO6PR02MB7555:EE_|CH3PR02MB9116:EE_ X-MS-Office365-Filtering-Correlation-Id: f9ff0ae6-bbef-429c-8771-08da9474f753 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: 56NK1rJI/+TpeWxhmZFpHhLYhB6tgqZBwZEzpXkT6CdlH8WBsDPV0SWNv5Nu3+zsnOxQwgVhQYZ098KXKRTJXX1DZDqxMcP+t7slNjLcSQ5PlQOlHQLuKg4bIYrKTtUBrPWIVGFlFJF4z0IkWMaksi4CxJn156dAIjuL4CpkmLLucQbm+eaJPTz2XfoybWRAsMQNqYa492OB/kDGcljr1A4uwWNAxGvLnOGjJwKBqQIJD3OcltdjfdY89lnDMwZlYl66woQ7/yUnxv4eEjbPQcoHcbMPfjATifY/U0EaGE9zJgb1pJbMk+oQhE5yOAQxjnth3Q1R1kwpNXJVbtcu3xK74rARmNiygwtL78b1qwMC3y9OBKyzPjLNNTfNjOKH98xE9qJmbW+ZRZSFxpbNJxmSBMC7cdXEUh1TtYgJkXMFI3sRrCvE4N+EKk8RUfVoGGoxMB4546GBgHeBOXZTrjtfCAcPHsT0NV/Lnlj4UtYqv8aQULQNN4Y7jITvnw7t/6Qoh9iKtBcmhx9g1wwWHdr1ILNttI4mVAfCOipccUXJ0tCX2+Mk+zkA0M3gk/08B/cb/RrbVlH6Zh8c4XfGWLijU341/jIYHepGgvn4uQbgr7NwUsYOW07qtPGUnoZEb6w+BfVDfpyRRHlZTQQ/VazlcN7tBlF6OQAYS315KYMv2SH0boBzDfT/VJ3PleYgw4sP4PlejtEHQEWLARmjViGtlXF4zHMjS34ydkiFTL6xF+eGFZ1pZbdKjuWp2Sap+HBWzhVZ1J0NA0liG2j83W++tW24q++c42sUE9nsIVU= 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:(13230016)(396003)(366004)(376002)(136003)(346002)(39850400004)(26005)(107886003)(6512007)(52116002)(41300700001)(45080400002)(54906003)(86362001)(6506007)(6666004)(478600001)(6486002)(2616005)(1076003)(186003)(38100700002)(83380400001)(2906002)(15650500001)(38350700002)(36756003)(5660300002)(8676002)(66946007)(4326008)(8936002)(66476007)(66556008)(316002)(14143004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +ZyeCGuDelBgqYycE8blLEKX5xKRa9eI9cHcDGrnsn0Rpa+05B2K4/UQ0UI7EdDqwvyDX4U6c4kXlhQmHTrA1Roajup0aDeDfZIFeECybryx7ExM4JoygwtMrxYtqNc/lh6J2/wyc4g5kaSloXpMIoiYW1Vnzi7TWa7lhn5Hash2i0OO9lB6h5wxgrcdvkSSCgdgFwFZdB+ofJGR0so0qwqdet1H5ydKMO7eJ1Jinjm/b7Iu/VJClrRStB+XK5ThgIxN3xKdYTwmoKpUtAzWdWnwwhd+hRNB8ns/5DEc4dngsMRyA68n3DYV6x9sBf4Q2cKF9lcZorTN4c2+yqxLnqnQ5pyFJkJaY33YpXXQRt2B1q7BDXTMImo1zfaM8hTFAV22OHy9M1HIOn4N2uyFYzkRNEY4dALxJvhxyeZX7TefmT41/GJxzwrZ4pMzhB4/WKD6Tz+N1tfIPCbBNmZX60fljrQS6EcRenNdCrfuQtTugVv+yUq0PCGqAeAx7zcYptlkugAPwx2pVUEFSOyugQGDbeyeMEA+O6ykABzbPfh3DwTJ8R8NeSb0IBrjGRhUEUuvZdBEBRM0zUzgx8v2HFdq3KtTWc+pOnk0j5nSNMZg0FK5qp8Vmh5rarquO/TUSM2HBxv/weQOWggr5IfaEagbxAStXh49TehyHbgJwIS2BPPftv9mUtQ+AoObFxDXNWu5h0uKhewrMTWee5l6dY14YISh/C4RvRE/biews/wRCodSZNlhpKQ/LCSJM1NlACqMYQLC93yOGiKLmjIHFmqCVF9djeCSi6v56ZF5n3a4dGre5nBs35q8vX0L30Up3kMly2hrX0VeC8jqZEYm4+3qSGdYG5XGV1hG+84QZ21irN58XqS8LZchAIKGKemD5iS8H1GQS9issXem3CPmCkqHGpXpRRUt1N6W6xb7p3j4VmKbGCtJ65slpQgc4rCCAzhd6N73OuJchlv2vdRwTnwcuAtKsy83WX5RZPCw0AAT+FkqEbiUd6CHqjjsifrPKtkAaFctONaFUCQkEYwKicuQoUOPQ3hw/a5S4rbxLD4Sf0Z8UmuRKgFp7eTD55HPAzDY/SiAe5ONa0XKgKzoJtHX4J04ZbxXhv4Hcwr0IEleBuN3hjIMAejGtnHCO44mjrgVziNkRViAEXDyHruuun6mqTg18B9zqWgtUAXYtY/OtVSXzeuYzD4IgHTMa09eQkRDQX7gYCNeh9ExNGbYCC2VtEgNa+/CWNvKNTOjVysMDI28hULhuLTkW8+ij3oW2nZCJ7NTylJXc5dA5mrewSmxfDKH8JWuhukmmGqzc8/uEV0e4B4285FavJnNAllPAbxNdZioiuLgAJ9pWNHXrWEi5IMHDAv0s8Wkeblq1n7xhaZEmYRynueJe/ms1CfAuABQ/YvBY63U7alBZnKAK1WGkS32Qhdv1QvKCbK4e9oYfStCI9AbPbopcDZOhLKfvRaP9kkp+McmAnuhT7Tac1KyKZWM+4s2BbNDb8x+rvUZyJ2+454/IfbOOXWnQMWjSLtJsO7ogn8R+Abe116aEpRwgqPGGH57Qz93xfOkvgfQQXilGTnshF2W3Myhh7NXx8Z925rhV0cTbO9Ci6g1Iw== X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: f9ff0ae6-bbef-429c-8771-08da9474f753 X-MS-Exchange-CrossTenant-AuthSource: CO6PR02MB7555.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2022 04:12:11.4159 (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: CPkKFO5E++TYPF4fqqq4uYbWj5Wq5HBsCApzPSuLVMzNLXHbEVjuN6JKELaNweZo6rbmfkfveIbzfI/+tloM/knewm+2nd49WKrrwEX3Ikk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR02MB9116 X-Proofpoint-ORIG-GUID: bwyTLpS3fizwa5N1klk81J71yf18Zsgf X-Proofpoint-GUID: bwyTLpS3fizwa5N1klk81J71yf18Zsgf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-12_02,2022-09-09_01,2022-06-22_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 | 33 +++++++++++++++-- .../selftests/kvm/include/kvm_util_base.h | 4 +++ tools/testing/selftests/kvm/lib/kvm_util.c | 36 +++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 9c883c94d478..81c46eff7e1d 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -63,6 +63,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 @@ -189,6 +191,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) { @@ -208,6 +211,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_has_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); @@ -255,7 +265,11 @@ static void default_after_vcpu_run(struct kvm_vcpu *vcpu, int ret, int err) TEST_ASSERT(ret == 0 || (ret == -1 && err == EINTR), "vcpu run failed: errno=%d", err); - TEST_ASSERT(get_ucall(vcpu, NULL) == UCALL_SYNC, + 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(vcpu, NULL) == UCALL_SYNC, "Invalid guest sync status: exit_reason=%s\n", exit_reason_str(run->exit_reason)); @@ -372,6 +386,9 @@ static void dirty_ring_after_vcpu_run(struct kvm_vcpu *vcpu, int ret, int err) if (get_ucall(vcpu, 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 */ @@ -762,6 +779,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); @@ -803,6 +824,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"), " @@ -824,6 +848,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", @@ -852,11 +878,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 24fde97f6121..68be66b9ac67 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -834,4 +834,8 @@ static inline int __vm_disable_nx_huge_pages(struct kvm_vm *vm) return __vm_enable_cap(vm, KVM_CAP_VM_DISABLE_NX_HUGE_PAGES, 0); } +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 9889fe0d8919..4c7bd9807d0b 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -18,6 +18,7 @@ #include #define KVM_UTIL_MIN_PFN 2 +#define PML_BUFFER_SIZE 512 static int vcpu_mmap_sz(void); @@ -1703,6 +1704,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 @@ -1979,3 +1981,37 @@ void __vm_get_stat(struct kvm_vm *vm, const char *stat_name, uint64_t *data, break; } } + +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; +}