Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1215189rdb; Mon, 19 Feb 2024 07:51:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXT6QmRhVVc9QGjliu1MlO87rJ/b/aF/swoJZ0OPH65ZZ01wMmm1eNE1gj6lpbybbJzbNogeZ72bmpOCnM2XVrVWP/idrvrMUc35/DSlg== X-Google-Smtp-Source: AGHT+IHnwohOdHbixVTljeFxCb5uooVfnHIBzXFcBdM62IJ4d7seOAoMPvx7576mkjjxRY6fiOD7 X-Received: by 2002:a05:6102:94e:b0:470:48ea:1966 with SMTP id a14-20020a056102094e00b0047048ea1966mr4209407vsi.14.1708357899193; Mon, 19 Feb 2024 07:51:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708357899; cv=pass; d=google.com; s=arc-20160816; b=LXXnk4fq1cTd5DtzAnJ+NQ4W0NmRZ006QVLDTLicyv1jsFv/fe7Wpmzcxh7K0oO59J jNd9B7ZsjZ0i//0OV/X1ubqhdcdcoS2bEvzjks514o4K8ZVjg2N0SiI63OITKD/bDQeB hjwTvAvofh4nHOm+YpEsXDYaDf6MPr/SeQmYVXfYb5NOgGZfToaxLKEQ3Q+CpXkFqL5t SqHWaWngutiweqe7O3zsdtfmEgRiRfnb98a60EonX4xY+epObASxQFBev+QXSEARK7mP AywipnI1o6RDqv0wz8ch4RD1AEXsditViQSfqk6Hv/8ilIY4gsUgJQW1zUJKbMtcH+bJ ztDg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=g37j1FtPF8B2B6ahbdjOo4C4cedCCq5D/gQif5NDL0M=; fh=tCOc5L2NuLrFb5uub/QkPtiODRw0ibp+wTyYVIWnexU=; b=omOO6968lopYKUrjk93iRXfK2JyBCryrEeTI5FIxKqXO7+n+/W2JquyaxHwMBb3CFy 0bmLWHV2OHevL5VUSuXxizrZs0PbqP94+86T5FwTVkkZvEPIC+d+Ig4Nnwbr7H50AewQ +EZNgMIjo9OaxddW8vtdSx8jREkW6A/laDHkMGQI/Oi4xedaYxT1OVTU3XmEt/fiv+Xk xeg9dSaS3J2BIE4OaUWBHsYN+r4g8cxy5c+jL+bK6IlcaPpNFplc4EEn92SKXYchAaVD wxep0GXSDE4on3txmF0dRTXfUBQsr+RUoJFeBQ/bPeAfCpv1dXHtTlbo9UvDzY1NpmkY q2fw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0iHY6Oex; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-71617-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71617-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id dg15-20020a056102570f00b0046d26f16e32si844688vsb.38.2024.02.19.07.51.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 07:51:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71617-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0iHY6Oex; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-71617-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71617-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E71C01C22BF5 for ; Mon, 19 Feb 2024 15:51:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06F153C6BF; Mon, 19 Feb 2024 15:51:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0iHY6Oex" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 B72BE3C082 for ; Mon, 19 Feb 2024 15:51:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708357888; cv=none; b=I929k7sBF4Tta2dygrHp8qdtp7d4O7lwmfpNG1ZByL8IC1pF27wL+GJBIPLGt1EYdWgGlUpEy55tcmh93XFpanOCkegQ5RQArjyDJSabaylIwztvzP8N8YOiINYiD1vPq4XVJ4H2U3ibFb4bhApr/26Cj5SOhlbD1SNxMU9wtEs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708357888; c=relaxed/simple; bh=YROZrjdq3gYQCAeXMRavVSWhGIfjVKco/8EJ0nQwWjQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mYpZue5vcAjiuPMr16QFP3SKnP/eYc4Fq67+r1kzVKM5A1yVEQDgB2Xj6UwACjc7hsM42VCxx4zcjpKS4EO9B1h+J1vO7sacaVf80ip3l39OjjTnUJktbHeZERM6IHeQboFwxhYsXLkelTLtUxiQnMZfJgtGSGcOt6ei6WdnbE0= 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=0iHY6Oex; arc=none smtp.client-ip=209.85.219.201 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 Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b26eef6cso6515013276.3 for ; Mon, 19 Feb 2024 07:51:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708357886; x=1708962686; 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=g37j1FtPF8B2B6ahbdjOo4C4cedCCq5D/gQif5NDL0M=; b=0iHY6OexxSF1ZaZ6jqNaL0QyczVhARwrhhpqwrbHzrq3S/dJnAldeOhBMa1CjE4ybp m5p4wajY3UPQyGhGEZe3j10fN+zbXfRMmOvpfV2+/32Kav3bntgMpapZMCMPwEZCBM1T AGJdfiHEWFSXXk+Fx58AjCZtSRT0vyDY5ShZKoNDVlACwu+vVz2lknV9On4JyXJDgyKe yVa19KbLy0FMy3EamvIs/uIf9nCk/dy3oCZInJFH5WJ/5XuTm1RYYYDYfB7V2SqUCENS VNveEGcFzsSdMOqIMxce0lgvcxREVDn0e6GvGl6CVdz896aNUyw45d1MsEg5g2bb3h2O je5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708357886; x=1708962686; 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=g37j1FtPF8B2B6ahbdjOo4C4cedCCq5D/gQif5NDL0M=; b=g5P+4RxhZ+iSTcKCuAQOYMwwi53ZtHlVx6LT/p9ybvUuC8eDqhO3GzlNkvC8yQTPvR KOINQ61nKWuN0XEu3KaTqBHAv6HWg2FLhcpp+O4qnyr6WMjKOoqFwXgU/Pgu6lp3HE5B V+/QMxjIsIcG7rwPy2hMdSG8NsAKe+4G3x491nXuBwCF2jML8lk0t2oZ0OQ0Z+tIG2D6 93hjKhboHqEEkzfmeTHP5OlUvTWzQB/q/ls2iBjonRNawUeYyPEWzwjueT+pwFoiHL8z 0dsP6cTBUc5GGdiNg+5O5hHxc/PuIGBSkOTdg4fnueq4hg0aFTZVGMkZQ0wbWF02/c61 xxSg== X-Forwarded-Encrypted: i=1; AJvYcCVXMb7Jaft+imYmMXJmgz/KAKGIdjGf0GuQ6EWFztKcOcAYhQ013KMTW9dDtu1JiE2cJ9cn6NWr6QqkEWLKdhw7aNpGvVX//ZIxEB4t X-Gm-Message-State: AOJu0Yz5FX6jEl+sWvqVC7RKSacWbw/sO8bdbHnei7lRQcikkhWfeAna uQPFvBeBZgMo+WXoRMvyCWd7wZh+fLwY9AiDqtI7e5kUPgyKdIHw5LocfUF8WBtTSiTi3o2FYOG Keg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:a8e:b0:dc7:6cfa:dc59 with SMTP id cd14-20020a0569020a8e00b00dc76cfadc59mr427758ybb.4.1708357885861; Mon, 19 Feb 2024 07:51:25 -0800 (PST) Date: Mon, 19 Feb 2024 07:51:24 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240110011533.503302-1-seanjc@google.com> <20240110011533.503302-2-seanjc@google.com> Message-ID: Subject: Re: [PATCH 1/4] KVM: Always flush async #PF workqueue when vCPU is being destroyed From: Sean Christopherson To: Xu Yilun Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack Content-Type: text/plain; charset="us-ascii" On Mon, Feb 19, 2024, Xu Yilun wrote: > > void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu) > > @@ -114,7 +132,6 @@ void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu) > > #else > > if (cancel_work_sync(&work->work)) { > > mmput(work->mm); > > - kvm_put_kvm(vcpu->kvm); /* == work->vcpu->kvm */ > > kmem_cache_free(async_pf_cache, work); > > } > > #endif > > @@ -126,7 +143,18 @@ void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu) > > list_first_entry(&vcpu->async_pf.done, > > typeof(*work), link); > > list_del(&work->link); > > - kmem_cache_free(async_pf_cache, work); > > + > > + spin_unlock(&vcpu->async_pf.lock); > > + > > + /* > > + * The async #PF is "done", but KVM must wait for the work item > > + * itself, i.e. async_pf_execute(), to run to completion. If > > + * KVM is a module, KVM must ensure *no* code owned by the KVM > > + * (the module) can be run after the last call to module_put(), > > + * i.e. after the last reference to the last vCPU's file is put. > > + */ > > + kvm_flush_and_free_async_pf_work(work); > > I have a new concern when I re-visit this patchset. > > Form kvm_check_async_pf_completion(), I see async_pf.queue is always a > superset of async_pf.done (except wake-all work, which is not within > concern). And done work would be skipped from sync (cancel_work_sync()) by: > > if (!work->vcpu) > continue; > > But now with this patch we also sync done works, how about we just sync all > queued work instead. Hmm, IIUC, I think we can simply revert commit 22583f0d9c85 ("KVM: async_pf: avoid recursive flushing of work items").