From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8AF31B21A4 for ; Thu, 14 Nov 2024 15:38:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731598699; cv=none; b=Xbak+g3ZUvUjAWO8O2nZOqYST5jjsx2YkKA5ME4m0Hre4teFfvfPyBOfpCHgYVxqpBIEN/wDPRwavlLB0wWM38ohTf/Xose/URCgFpXlCpZqOiYvMnUM/kp/y5TAm7HgA7Ldo5WUIzo7+SJTiItYcBr7zxoIqkGLeW0g7v8QqYw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731598699; c=relaxed/simple; bh=8uAKE4ueNMd0aSGsxS2kQiRNaOcMtz5ZCAAuLV4T9+c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FIL5E3TmI6aV3yNglSEFcXrhC7aijNx2oPNKGTWYmjH/KcJpbok5COTzaZygvuY3ivqSbqVITdREY8XDmmgIXaoVx+LUlclKHQpJbieeeb+COtWHPSQ671qLN/cQ3NvpXSclTTkC4X3Erb2mJXPJcl8GgZ6Cs1vwGSQFr+Gt1dA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=BK4SWUBu; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BK4SWUBu" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2e2bd9a523bso873016a91.0 for ; Thu, 14 Nov 2024 07:38:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731598697; x=1732203497; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nrghbEI+TsYbtMq/izvt1GHrUUl0ZnJFsIi7cn6pUdA=; b=BK4SWUBueAtOtlT1Ir5u97O8rdsKZM4HfxczgTwryffhm9yzxYfD4Yc4Xlbom1wXsp OAxZ4lLoRx8aEHqICPwGsWnMBz50HRdVnAOWVuxkH0S7z8b07HeHEzdKP7+pA1Ex6qSG dyFYHGKNnaie5J6hvBC/u9lRwtg0nKW9wl0Fp8YRDxfipHV26YY5WlFzGZn+9DwwFFHP tWsIECYp29yO63AVKzErnvtcyD5TeNhwfoyTGPlSj7Xcz7ufxiXzM0A64OtkiKvQT1iN 5+5Tpstbrg5KTADvF06sk6cS7ejRAvjArzBHu4jP4c/aHwU+dzjrUf5REZ2/6hV+AhHf j0pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731598697; x=1732203497; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nrghbEI+TsYbtMq/izvt1GHrUUl0ZnJFsIi7cn6pUdA=; b=mZJ23WJJFYq4XCXugV2wopGXHU7imSC9Nww+6uHQT60bMaGIWNHwSkgSxSPVUArrfp KNR6BMCGt1vOnt07DFW09SCa0fXIAxgz8Y5ApO1HU4P2vl9uVlToU2FWgwncPZ/YHcF0 roN+ZjaXRzl1zgxEIGyvpju2IyiHFtfIuWI4jxQR2i5uTBf236sKMjSKMZKjGQFs8H5o MYtrzDi5yo0zAoEsjmGxAoxQSICpbpgfOLD7OwN1xHM7LA8ORuDhK4f67ncRktBIZPuZ fZntDbQIgLX15CdObwYsbiwUsk3eMhcFCWEo9L5dTUdHxcvz/AvYJEiUN8s5d6LvRETI ucig== X-Gm-Message-State: AOJu0YxIZwDz/E0llxCoJ+qWlvvyuaBDO3IGSSSYMaYx5ix5GkywHL0B D/vSwHO15V4V47QgpLri2E6bZ1VJJ/BQludQbY9af2ztAWo4PuHX81Yr0F/rjEGWfczB93qA2s6 NUA== X-Google-Smtp-Source: AGHT+IFZkSoZg3ul1mmW5lhfWd9c1u9W2ZDRyrepFRM02g+D3CvPh2OtOXG2/DORJfcwlC16RJHonxT9FHs= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a17:90b:8ca:b0:2ea:b9a:f6bb with SMTP id 98e67ed59e1d1-2ea0b9af9d4mr2901a91.7.1731598697039; Thu, 14 Nov 2024 07:38:17 -0800 (PST) Date: Thu, 14 Nov 2024 07:38:15 -0800 In-Reply-To: <70ee319f-b9ec-448a-a068-8165c8e38e6d@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241108130737.126567-1-pbonzini@redhat.com> <70ee319f-b9ec-448a-a068-8165c8e38e6d@redhat.com> Message-ID: Subject: Re: [PATCH] KVM: x86: switch hugepage recovery thread to vhost_task From: Sean Christopherson To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, michael.christie@oracle.com, Tejun Heo , Luca Boccassi Content-Type: text/plain; charset="us-ascii" On Thu, Nov 14, 2024, Paolo Bonzini wrote: > On 11/14/24 00:56, Sean Christopherson wrote: > > > +static bool kvm_nx_huge_page_recovery_worker(void *data) > > > +{ > > > + struct kvm *kvm = data; > > > long remaining_time; > > > - while (true) { > > > - start_time = get_jiffies_64(); > > > - remaining_time = get_nx_huge_page_recovery_timeout(start_time); > > > + if (kvm->arch.nx_huge_page_next == NX_HUGE_PAGE_DISABLED) > > > + return false; > > > > The "next" concept is broken. Once KVM sees NX_HUGE_PAGE_DISABLED for a given VM, > > KVM will never re-evaluate nx_huge_page_next. Similarly, if the recovery period > > and/or ratio changes, KVM won't recompute the "next" time until the current timeout > > has expired. > > > > I fiddled around with various ideas, but I don't see a better solution that something > > along the lines of KVM's request system, e.g. set a bool to indicate the params > > changed, and sprinkle smp_{r,w}mb() barriers to ensure the vhost task sees the > > new params. > > "next" is broken, but there is a much better way to fix it. You just > track the *last* time that the recovery ran. This is also better > behaved when you flip recovery back and forth to disabled and back > to enabled: if your recovery period is 1 minute, it will run the > next recovery after 1 minute independent of how many times you flipped > the parameter. Heh, I my brain was trying to get there last night, but I couldn't quite piece things together. Reviewed-by: Sean Christopherson