From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E59181BEF98; Mon, 13 Jan 2025 06:49:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=192.198.163.11 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736750944; cv=fail; b=ukVoSzuvBYAwAx0XlBDqpV8DA07Ew4K+MkBNWfgldn7lbvFayz5gCFMSsryawCvapeODUoWW+rL/0FJDWQ2WM/NBK9s4gmAFIimE8rxH86Ue2u6rbqi3oYFq6MJDdk1/SEOiuI9dHnD30Omb1M1MyIIOcejyAgg5AWCS+X2k4jM= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736750944; c=relaxed/simple; bh=J8suXr1qDWsDLx0jPwZV46PLJzVEdvkofxgQXOtcNIY=; h=Date:From:To:CC:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=nFJaGsIhtyXr5Xtqk8r+zhC18kxFUgQ0WMPCWOkKopma6Wi7M5xF6Ls5fpMzYJuHK/lY7dLcBk+OUs1yRX9rGBOplAxq3sf/mpGddVK6S+y+LS7HEnDz3YzWTgjYXwu0lEObZTk2Cj4AcLYWyCB5sKL82en5Up1XqkjhjRUhgao= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=M+KEK/Ar; arc=fail smtp.client-ip=192.198.163.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="M+KEK/Ar" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1736750943; x=1768286943; h=date:from:to:cc:subject:message-id:reply-to:references: in-reply-to:mime-version; bh=J8suXr1qDWsDLx0jPwZV46PLJzVEdvkofxgQXOtcNIY=; b=M+KEK/ArTqTpU3cj75eE65SyyJ3rI6D54G47eYFvE7YUM77AfcudO5eO HmRyI8L28SN5e4MPe5oymEr9FMK4MX+WLZGZYYJ/BRHgesUWkmoyem7uK clNHqM04sb/v3VvPaYzQyn6zFuMjMv54ebmneJC56jBEN/L9Rjo1VD+q5 wylCBsHzlelvuI4yaDvCU/pXpX+/8IYKGOHPJkrQw/HXCcLvMS63o6Usa RgPAlVMHT1/pN3bUnRzns7GWlpiCiNIM6ANAfWcD18y3EziQkPW5HmuWg ZNBtByJ0rwWo+J5vXcHAwVW1nG0A1xiuS/hyNR3niAGI6ugNCIk3mk6b/ A==; X-CSE-ConnectionGUID: 98v4vZ00RfiP7nujDawcBg== X-CSE-MsgGUID: d+A8+wcfQ3O3Dups7R/SBw== X-IronPort-AV: E=McAfee;i="6700,10204,11313"; a="47570388" X-IronPort-AV: E=Sophos;i="6.12,310,1728975600"; d="scan'208";a="47570388" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2025 22:49:02 -0800 X-CSE-ConnectionGUID: SY6uagtUS3WmJpnLYTDr1A== X-CSE-MsgGUID: TK+9ch38SJqftaJ7onmVNg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="109498568" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orviesa005.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 12 Jan 2025 22:49:02 -0800 Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.44; Sun, 12 Jan 2025 22:49:01 -0800 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.44 via Frontend Transport; Sun, 12 Jan 2025 22:49:01 -0800 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.41) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.44; Sun, 12 Jan 2025 22:49:01 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Rk0qsSDPWd95e8OIJkGs9aXS6APaaHW+4P4/oJukkO6uQPS5Zcw3vs7E8Ey+gayfKKVYyXqAFQ16T3r0d+ZPmb24SSJqZATDjHSYx99Eh3D3RulTh65ael7Sx6bY8MC5W4UcTyeZqXZiv6dtWkODikZ4peZHZqKODY+p/RefShiy/h3iVAikYIbxIfx1KfkgtNV6WhUFw6KnCfXbJpt4bdOSHgVdD4R9LCfOijTqQxz9XfbcPFaiK1FbB3LwVt0ybDjorWRmAbM5sqweKjfJfvU6ZnV0RYqTMxOYMJo4lFGq2XAZ0TEqC0junDu41aGaBFQavlbnroDjk9S1wzuyQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=TFhzAmgUAMJrj5LDjuo7/BRfvLxN3nm5sVmevKhKDFM=; b=g/0NZq84YjFE71mx6W1OKLfn1amdSQNd4KAu4HDEjf2/7hvh2iDI8AeKhG7Py4Ug7F1KUsRXYVwmuHGWm9qyIG9/jHQg1+g78KcxM3xMsPCo6HOOgZ9ZdP+u4XMr5lKSH0eXvgl/ZQiE3I6/YlKki4eKqvOReTk7bZZu8Xw7wcFs437954vmwUbPeChQBk58z5aQn2bF674GYY8QjROZylY31Aqxg1ibSPgGbMrDCbtNsuFLA5iXuDFbGoyjQRBrHfJLGOF6yvJcYTpHON+bj24n2b5U5SpJFbZymYJBjWoH+wffOuNBARFo1aPKNc6+FhzsGRuw/SRkukTPpk1v/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DS7PR11MB5966.namprd11.prod.outlook.com (2603:10b6:8:71::6) by MW5PR11MB5787.namprd11.prod.outlook.com (2603:10b6:303:192::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.18; Mon, 13 Jan 2025 06:48:59 +0000 Received: from DS7PR11MB5966.namprd11.prod.outlook.com ([fe80::e971:d8f4:66c4:12ca]) by DS7PR11MB5966.namprd11.prod.outlook.com ([fe80::e971:d8f4:66c4:12ca%4]) with mapi id 15.20.8335.017; Mon, 13 Jan 2025 06:48:59 +0000 Date: Mon, 13 Jan 2025 14:48:05 +0800 From: Yan Zhao To: Sean Christopherson CC: Paolo Bonzini , , , Peter Xu , Maxim Levitsky Subject: Re: [PATCH 1/5] KVM: Bound the number of dirty ring entries in a single reset at INT_MAX Message-ID: Reply-To: Yan Zhao References: <20250111010409.1252942-1-seanjc@google.com> <20250111010409.1252942-2-seanjc@google.com> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20250111010409.1252942-2-seanjc@google.com> X-ClientProxiedBy: SG2PR02CA0065.apcprd02.prod.outlook.com (2603:1096:4:54::29) To DS7PR11MB5966.namprd11.prod.outlook.com (2603:10b6:8:71::6) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR11MB5966:EE_|MW5PR11MB5787:EE_ X-MS-Office365-Filtering-Correlation-Id: b61a1e17-d878-47e2-d578-08dd339e5baa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?9K34FwzEMtQUyWTIjbzh9dp0n8oYkS7g/5VlTKSbFLwyPE9spLyOQceWrS0x?= =?us-ascii?Q?6kCZKACjLha1YSZA4HpuFytGsevsHLeJEbdj9kaiepHoFwQC/Hx9B+tm6T8I?= =?us-ascii?Q?miqkvkWKbWbLYeimaHxjBgPCavdUzgUqOCl7hFqL3ezx2GunKccUjvgPBr2U?= =?us-ascii?Q?EQhSPPf2GP06W/sKdS2G3FX66gh9wa7gC7/GrE/oL6vilC+VsjnyKT+O0x2v?= =?us-ascii?Q?THdxMNia5n2CzrUAEa2Q4tB0NvX0Y0zL+cw7nmh1HeJjLjgZoWKmScN7IyqE?= =?us-ascii?Q?oo8DX4XHAFSsElJeEFYB/ZQH1zLgZ5KSMiW3RBE7V6WixTcb+Ds4g1gb12lS?= =?us-ascii?Q?fPp/wrmNQbvuQAysq3QuP5spGir/ac//pg3CjO5H+aCQ614QBKZgReVKIHJB?= =?us-ascii?Q?kCtmFGM1LzSVkqnnt3WW+a731RWpk8CGNFeFnj5cU/PFJhg+lKwumrkNIYa0?= =?us-ascii?Q?iRjPgrhNMGeqSbX2FncGUZPh4sVQrwPRkfqCXMoi7IawD6Y5Q/duUZz3mYrK?= =?us-ascii?Q?L1lc+cpoUS6veu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.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR11MB5966.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(366016)(7053199007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?KhQDLkd3+JusYpbkcGKSXgS5W0R9t7lTwMLqfH6Z0MHfMz7hL7DNiHVyNoNj?= =?us-ascii?Q?sHSQEi2EfkpaY/6pSzxahZteXM7UAQBN0WOHDXCsuN7Hidiqp6ymCb407GoG?= =?us-ascii?Q?Fie5tdKbcsFN1E7sjw6mjsn7qE8UsJaacEvITjVot4FY3pBxavAif7HLlPHc?= =?us-ascii?Q?fzOnNmrRF/1OQWHMjkRDBe4nsi9dVZEZoGZAxqGVXEAfCAqMlbyV7peCrsHs?= =?us-ascii?Q?oW8ZixmSG0IAMn6A7TTkUTws0IarJWsGbQDHt0CVuO3yzjQc4VJW/pFVN5Jw?= =?us-ascii?Q?Y+qAv43l5bAHKfZca4MuJJiynAQTAuGEi/u2FQ3wepXNk2TYOnQbLQZO6hSn?= =?us-ascii?Q?VN6Sr0mVAB/sZ2Y3uEucooEj6jluRXyScpbVTmxdB+BDqiAtJePmTKgWGTlT?= =?us-ascii?Q?cRweHKAJNYWSu2pwiE1GERj/xeTnJ8v2mFonuK4RCDjjCrCRwMZncEOViw4T?= =?us-ascii?Q?HXSZXlatQfSmLtZJl5xGqP1ToVkakcwZn8ulnmr9ZVc9eU1pQPO1zxaFU+mu?= =?us-ascii?Q?2uTcNP7OO5FuAx/yKNMQnC41abXeXTK1SarfvI/C5f/oi42Xxmpb3b8JOz7J?= =?us-ascii?Q?7+InLjx2fmrkNfW7qq3/ai5DoVTUVY2gCdWlEBZp2pgICJfXuRPUz964BmL7?= =?us-ascii?Q?iyfMn79Vk8ot5hcntTVcxff19KUr+mUQtM8UIhnkg/h16BSwl00LAJ8VFm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bwkG4aAPtmyyBKB42Lj?= X-MS-Exchange-CrossTenant-Network-Message-Id: b61a1e17-d878-47e2-d578-08dd339e5baa X-MS-Exchange-CrossTenant-AuthSource: DS7PR11MB5966.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jan 2025 06:48:59.4221 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: BP9FuSdD0xF0LdP6GBaBGzh6FoekC9iT/XjwJcrOWWCbMnFGkhr175fVt4emjZJd2Hl0IJ5Q8BFaI/wcMmV37g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR11MB5787 X-OriginatorOrg: intel.com On Fri, Jan 10, 2025 at 05:04:05PM -0800, Sean Christopherson wrote: > Cap the number of ring entries that are reset in a single ioctl to INT_MAX > to ensure userspace isn't confused by a wrap into negative space, and so > that, in a truly pathological scenario, KVM doesn't miss a TLB flush due > to the count wrapping to zero. While the size of the ring is fixed at > 0x10000 entries and KVM (currently) supports at most 4096, userspace is > allowed to harvest entries from the ring while the reset is in-progress, > i.e. it's possible for the ring to always harvested entries. > > Opportunistically return an actual error code from the helper so that a > future fix to handle pending signals can gracefully return -EINTR. > > Cc: Peter Xu > Cc: Yan Zhao > Cc: Maxim Levitsky > Fixes: fb04a1eddb1a ("KVM: X86: Implement ring-based dirty memory tracking") > Signed-off-by: Sean Christopherson > --- > include/linux/kvm_dirty_ring.h | 8 +++++--- > virt/kvm/dirty_ring.c | 10 +++++----- > virt/kvm/kvm_main.c | 9 ++++++--- > 3 files changed, 16 insertions(+), 11 deletions(-) > > diff --git a/include/linux/kvm_dirty_ring.h b/include/linux/kvm_dirty_ring.h > index 4862c98d80d3..82829243029d 100644 > --- a/include/linux/kvm_dirty_ring.h > +++ b/include/linux/kvm_dirty_ring.h > @@ -49,9 +49,10 @@ static inline int kvm_dirty_ring_alloc(struct kvm_dirty_ring *ring, > } > > static inline int kvm_dirty_ring_reset(struct kvm *kvm, > - struct kvm_dirty_ring *ring) > + struct kvm_dirty_ring *ring, > + int *nr_entries_reset) > { > - return 0; > + return -ENOENT; > } > > static inline void kvm_dirty_ring_push(struct kvm_vcpu *vcpu, > @@ -81,7 +82,8 @@ int kvm_dirty_ring_alloc(struct kvm_dirty_ring *ring, int index, u32 size); > * called with kvm->slots_lock held, returns the number of > * processed pages. > */ > -int kvm_dirty_ring_reset(struct kvm *kvm, struct kvm_dirty_ring *ring); > +int kvm_dirty_ring_reset(struct kvm *kvm, struct kvm_dirty_ring *ring, > + int *nr_entries_reset); > > /* > * returns =0: successfully pushed > diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c > index 7bc74969a819..2faf894dec5a 100644 > --- a/virt/kvm/dirty_ring.c > +++ b/virt/kvm/dirty_ring.c > @@ -104,19 +104,19 @@ static inline bool kvm_dirty_gfn_harvested(struct kvm_dirty_gfn *gfn) > return smp_load_acquire(&gfn->flags) & KVM_DIRTY_GFN_F_RESET; > } > > -int kvm_dirty_ring_reset(struct kvm *kvm, struct kvm_dirty_ring *ring) > +int kvm_dirty_ring_reset(struct kvm *kvm, struct kvm_dirty_ring *ring, > + int *nr_entries_reset) > { > u32 cur_slot, next_slot; > u64 cur_offset, next_offset; > unsigned long mask; > - int count = 0; > struct kvm_dirty_gfn *entry; > bool first_round = true; > > /* This is only needed to make compilers happy */ > cur_slot = cur_offset = mask = 0; > > - while (true) { > + while (likely((*nr_entries_reset) < INT_MAX)) { > entry = &ring->dirty_gfns[ring->reset_index & (ring->size - 1)]; > > if (!kvm_dirty_gfn_harvested(entry)) > @@ -129,7 +129,7 @@ int kvm_dirty_ring_reset(struct kvm *kvm, struct kvm_dirty_ring *ring) > kvm_dirty_gfn_set_invalid(entry); > > ring->reset_index++; > - count++; > + (*nr_entries_reset)++; > /* > * Try to coalesce the reset operations when the guest is > * scanning pages in the same slot. > @@ -166,7 +166,7 @@ int kvm_dirty_ring_reset(struct kvm *kvm, struct kvm_dirty_ring *ring) > > trace_kvm_dirty_ring_reset(ring); > > - return count; > + return 0; > } > > void kvm_dirty_ring_push(struct kvm_vcpu *vcpu, u32 slot, u64 offset) > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 9d54473d18e3..2d63b4d46ccb 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -4877,15 +4877,18 @@ static int kvm_vm_ioctl_reset_dirty_pages(struct kvm *kvm) > { > unsigned long i; > struct kvm_vcpu *vcpu; > - int cleared = 0; > + int cleared = 0, r; > > if (!kvm->dirty_ring_size) > return -EINVAL; > > mutex_lock(&kvm->slots_lock); > > - kvm_for_each_vcpu(i, vcpu, kvm) > - cleared += kvm_dirty_ring_reset(vcpu->kvm, &vcpu->dirty_ring); Previously "cleared" counts all cleared count in all vCPUs. > + kvm_for_each_vcpu(i, vcpu, kvm) { > + r = kvm_dirty_ring_reset(vcpu->kvm, &vcpu->dirty_ring, &cleared); Here it's reset to the cleared count in the last vCPU, possibly causing loss of kvm_flush_remote_tlbs((). > + if (r) > + break; > + } > > mutex_unlock(&kvm->slots_lock); > > -- > 2.47.1.613.gc27f4b7a9f-goog >