Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1403024rda; Mon, 23 Oct 2023 11:24:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHU26Uithvv7e9ftYYyT+nXerjzbwCoaGwqCnF9aEwEKEwRCkyFinG8SdW87u+jGMEIoNXX X-Received: by 2002:a05:6a00:1704:b0:68a:4bef:5f9a with SMTP id h4-20020a056a00170400b0068a4bef5f9amr9612655pfc.0.1698085479294; Mon, 23 Oct 2023 11:24:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698085479; cv=none; d=google.com; s=arc-20160816; b=qlzaPOfGgh+JGxU2Z1hnJ4EVAxaSPmX0EdRlDOyGuDTWmCsJG9AhuDCKQqTBAm4+td +daQarC70CUSNciIZrc87P0UcKhK6mX3Uvaragk10FtB/EX3H1koDGS4lNP+HvYMu0wr LN3DTABni3GbqidZyMaEIWNfwJ9Zjf4i2GiEoBTgi8wS3hzC4YfEUMZb228jY+wJi6G5 8sDkIfq/JMqmRVX3AgaOp+bmaXfL1Np9Fyf0jD9gZFnMqXAenZmTRcqHyZdXSCwTJ+Se AFXiKq2cD3mXwKdZIFvHs3XRoYGBAu5xEg871Rnu0jnPyOZd4VI0pCN9XkVuXuh/WxK1 XP1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=pRUzO+vkA/3Zt2fqE2RqLUfgJAG2Koxv6V/JjBYAdSo=; fh=sRf2Is1JKPivK1hpqTG7CZfbs2gXnnUVv79/+AnWzes=; b=YV9M5I/NBJH0VI7uJXCYvbZyDdJDQsQPu3MpOpHDrcpEjx2EapMbo3fU2jW+INQfMC rkTlWdEsET5Ddo52TcMhluJuLza+1gKo+JPZDALfMGf5n9QV8EZ6hsSpm+ZN9Xr8P4MH SPFDbPqAP0OGtP0BK9ikV0xg98Cso6dFXD3xbj4c6ZqpiCK43hNomq5e2A0k4A+lJpvr //pUYruHv+DLGvs5mZS7t2063TXp9ioyiw+hjbhfxaayOpTuJOlbW4ekDYHpgTvor3Fs 92aCTDXfa8yswm00l39ksG4osaJs3yKU4DnFh4rAUwQBoRwaFauF6qnJFls6o+QFZjQG dLcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=udM3V4sC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id f13-20020a056a001acd00b006be062e4ecbsi6881154pfv.32.2023.10.23.11.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 11:24:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=udM3V4sC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id D482180A0557; Mon, 23 Oct 2023 11:24:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233449AbjJWSYY (ORCPT + 99 others); Mon, 23 Oct 2023 14:24:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230201AbjJWSYX (ORCPT ); Mon, 23 Oct 2023 14:24:23 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E9C38E for ; Mon, 23 Oct 2023 11:24:21 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-578b4981526so1981330a12.0 for ; Mon, 23 Oct 2023 11:24:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698085461; x=1698690261; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=pRUzO+vkA/3Zt2fqE2RqLUfgJAG2Koxv6V/JjBYAdSo=; b=udM3V4sCt/BN1axuSpiL9PRQuAI/CqASmIvE7/B9TXdV4y3TsnKD2CvHq95xhG4QhE 8+Y6dhFkrLPjnnseMaXF05ub93djmLvwcxdpCK4wuCKKeLGn5iV/3egrkPQQSV8mwFTO jB/Ka3G9+jbkSnhohuCim6yXdN4lywd+NUVKIRSa/SB9hZ7MA+rQgQYphzvWcC9Sw6uy 5SBt9o+oTrPXDk2/6Jt/ZBJvp5IFwawPPi2dSac38KtqNvIHUwyzkBOiI/b7s+eT8vjC fxzEaeonMUx56SlZTjAwU0KQUsv/uW49CLwp43Ue5mNkvjfz6f0L+RTPJiGD/HWHhW9P ZnKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698085461; x=1698690261; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pRUzO+vkA/3Zt2fqE2RqLUfgJAG2Koxv6V/JjBYAdSo=; b=lNOPT4jDpf58ip5hvi31EscXIc/KOKh5akwsxDMpSnFwrzkUGkwVDO0HOrEGWSGOjx SuLcx9VCAL/QfxCerTSvvGG76x3YsEO82OCX2k1ls7w+l4q3bpdwxHCjwqGf5W+7yGb3 6rjyhW+DoRwvVgfLnzrPPF19eKo+S/zZJaQshr4oaHLBwt0d2JrRmbpOOcS+dXF5qJk9 y3USHfvN19YIysBmA6Kw32OeSeEwCU0HyYhRqDWKQIr6yRspQuPZFYNN/cV2brcH9787 g5q5rrwWYDnk0ZlsDybo7bB0KvRg5xMdn+z47lhCf/VNnO/ofBCvCHbqNL5a5qOkwuke e4nw== X-Gm-Message-State: AOJu0Yw2NQ8AnQnyJoNM1sr7tOm9ozBBwGTlC8PfAVSY35txFAgQe6ls 9Lqz3AfQiUEufABSx1GKdTkEiA== X-Received: by 2002:a05:6a20:c19d:b0:16b:aad0:effe with SMTP id bg29-20020a056a20c19d00b0016baad0effemr358243pzb.62.1698085460734; Mon, 23 Oct 2023 11:24:20 -0700 (PDT) Received: from google.com (175.199.125.34.bc.googleusercontent.com. [34.125.199.175]) by smtp.gmail.com with ESMTPSA id p9-20020a63e649000000b0057412d84d25sm6055619pgj.4.2023.10.23.11.24.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 11:24:19 -0700 (PDT) Date: Mon, 23 Oct 2023 11:24:15 -0700 From: David Matlack To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Al Viro Subject: Re: [PATCH 2/3] KVM: Always flush async #PF workqueue when vCPU is being destroyed Message-ID: References: <20231018204624.1905300-1-seanjc@google.com> <20231018204624.1905300-3-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231018204624.1905300-3-seanjc@google.com> X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 23 Oct 2023 11:24:37 -0700 (PDT) On 2023-10-18 01:46 PM, Sean Christopherson wrote: > Always flush the per-vCPU async #PF workqueue when a vCPU is clearing its > completion queue, i.e. when a VM and all its vCPUs is being destroyed. nit: ... or when the guest toggles CR0.PG or async_pf support. > KVM must ensure that none of its workqueue callbacks is running when the > last reference to the KVM _module_ is put. Gifting a reference to the > associated VM prevents the workqueue callback from dereferencing freed > vCPU/VM memory, but does not prevent the KVM module from being unloaded > before the callback completes. > > Drop the misguided VM refcount gifting, as calling kvm_put_kvm() from > async_pf_execute() if kvm_put_kvm() flushes the async #PF workqueue will > result in deadlock. async_pf_execute() can't return until kvm_put_kvm() > finishes, and kvm_put_kvm() can't return until async_pf_execute() finishes: > [...] > > Note, commit 5f6de5cbebee ("KVM: Prevent module exit until all VMs are > freed") *tried* to fix the module refcounting issue by having VMs grab a > reference to the module, but that only made the bug slightly harder to hit > as it gave async_pf_execute() a bit more time to complete before the KVM > module could be unloaded. Blegh! Thanks for the fix. > > Fixes: af585b921e5d ("KVM: Halt vcpu if page it tries to access is swapped out") > Cc: stable@vger.kernel.org > Cc: David Matlack > Signed-off-by: Sean Christopherson Reviewed-by: David Matlack