Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1808841rdb; Sat, 20 Jan 2024 14:56:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHtkQXP5G6v5V9ay8A09Lwe+10WZk3g8oIykoaWQ94jhJYlivl+jgqIGQG+qAvt6rZQSeHw X-Received: by 2002:a05:6a00:130a:b0:6da:23d7:3786 with SMTP id j10-20020a056a00130a00b006da23d73786mr2941590pfu.21.1705791398419; Sat, 20 Jan 2024 14:56:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705791398; cv=pass; d=google.com; s=arc-20160816; b=Z1TzErtMz8B8cOotzuLCh2s81xsYoM/MNQhOwt2sY6mvMrtY1tXRfpQLbt535GFw68 Yg1KQtWkDBDLqeXalB8xOpdYJ/zCilE4sl0aFwYI3MhLl3S+weV0pH6omC9u0RyuJlsH zYbeJLWW1IoHeq9w1sxOZhSeITO5zHze7VulWVFpOxoJ0adZBtUXHXzX60hnXJYYx4nx KNYS0e8SRcxhdbLNrMAgDDLoq8/OanSIp8Vesjtss2Ox1YZRSu9zqJ2J7y5uTyfVHV8w j9px8IkZZ0q17wvm1MJuvtLLCfsdY5JZl45zZG620Z+xwwNAUkJbfZb4fOCE2jB+mFBZ zcwA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=XclqFB9/WM7DnGJsIIIh4KZSvpOLunIsY5T22XTyDo8=; fh=975nUjm/5Tvv+TwDZcgMRfki0UMZiSZXCwYjYR8WL5I=; b=IYemGeLBfmjd8PE/FFmv00efkCLIwZpQyFOubhoo+yVK1UWlzkxE3WU0nxRYSzskri o37NAGL6C6nC3YArcqZZisjMTfcHYHoVT6Q3CNuQzhcF77Ev9/e13c5mwZokMcdKY8Hh 4qkpAg1OzZm4X/Zmm1nQy/DXdiYdjOA2nAoSqMvg4e5Zyacnb8HYx8Sd/T31TcqZeJLr lAWNjavEZzS0LbN1M0YnO/BQkSoxRjX+eouut+sXsml5PRDlTo3RyWUCvJmWxHmXjJFQ 8NDlje9/MpQmsYQJcNbna8peJqcVt2qHp9Y7Yn+kKkGnWwIyRkVu3ouLNy/rRm/A8KPs P/cQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TMsp9W2X; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-31833-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31833-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o18-20020a635a12000000b005c179c00758si5835119pgb.891.2024.01.20.14.56.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 14:56:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31833-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TMsp9W2X; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-31833-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31833-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 85EAA28448B for ; Sat, 20 Jan 2024 15:27:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 69E9E12B95; Sat, 20 Jan 2024 15:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="TMsp9W2X" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 3618511C94; Sat, 20 Jan 2024 15:27:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705764467; cv=none; b=U0fJJ7qwsijK4EVJBJEPRj1D5hKa5DdSeEkKafCYLMVpOFohtK0rQsFqObJh4FSVFfwATrw1ZFL6wo3To8oaZntA4WmXOBnv+r0M/b9RPyC30mU1BB8NKA4VyBzpgIVVIqw5+uPhnkeaXLqzIzplsbOXbt3SvKI+c5MiQ0tuRyI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705764467; c=relaxed/simple; bh=/mXGlIyQCY4NHrPWDhvtkkDReoY5hcLaj9tfxnmilYM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=f+cqgI/b9FYxkl94rDgr2Ky/EKypb8+4wPbXuFNmeyzE/+xF+YcE0TqitBNy9zdV4Ufk+jaKIeNgJxsOr0yc24lectNpPhPtWbKRJ4uTqpFnSiPAwRgkBpJj7KpAedDB7hCQnLGbzBLj3qymspBNWKbZipmF/EghUnfKJoqi2lE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=TMsp9W2X; arc=none smtp.client-ip=192.198.163.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705764466; x=1737300466; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=/mXGlIyQCY4NHrPWDhvtkkDReoY5hcLaj9tfxnmilYM=; b=TMsp9W2XjHaAQgP0CojKNXvoKza/TtsECa/fLhVjclIMDO7I18oslPop L2ngBoS4s2GOoG44wd/UwC9Tsb8Ef7sfI4HypS2kD4fsCEuCdtquu7wSK CW7kzMnULIzktPwd+18kHlaQTaIkkKWtids9FPOCeLGyILB+GyHJtPNV0 EizggAoc9/FGPXYtwZZ2mxz1fooG+oWuK331tX28WHYOjxJUKihYgF3yP p+mTpwtewfCSqYO7RUJ2yG4Cwwe2QA0vjKIhe8hNfPryb6CN9cvm7lQ0U a+g4+xDdt2WSRYe9Dj2o8mJCi8ZFJg60ZzBrCaZwv/RZ1KH1UUT84HqEx A==; X-IronPort-AV: E=McAfee;i="6600,9927,10959"; a="820818" X-IronPort-AV: E=Sophos;i="6.05,208,1701158400"; d="scan'208";a="820818" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jan 2024 07:27:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10959"; a="928631934" X-IronPort-AV: E=Sophos;i="6.05,208,1701158400"; d="scan'208";a="928631934" Received: from yilunxu-optiplex-7050.sh.intel.com (HELO localhost) ([10.239.159.165]) by fmsmga001.fm.intel.com with ESMTP; 20 Jan 2024 07:27:43 -0800 Date: Sat, 20 Jan 2024 23:24:31 +0800 From: Xu Yilun To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack Subject: Re: [PATCH 4/4] KVM: Nullify async #PF worker's "apf" pointer as soon as it might be freed Message-ID: References: <20240110011533.503302-1-seanjc@google.com> <20240110011533.503302-5-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240110011533.503302-5-seanjc@google.com> On Tue, Jan 09, 2024 at 05:15:33PM -0800, Sean Christopherson wrote: > Nullify the async #PF worker's local "apf" pointer immediately after the > point where the structure can be freed by the vCPU. The existing comment > is helpful, but easy to overlook as there is no associated code. > > Update the comment to clarify that it can be freed by as soon as the lock > is dropped, as "after this point" isn't strictly accurate, nor does it > help understand what prevents the structure from being freed earlier. > > Signed-off-by: Sean Christopherson Reviewed-by: Xu Yilun > --- > virt/kvm/async_pf.c | 11 ++++++----- > 1 file changed, 6 insertions(+), 5 deletions(-) > > diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c > index c3f4f351a2ae..1088c6628de9 100644 > --- a/virt/kvm/async_pf.c > +++ b/virt/kvm/async_pf.c > @@ -83,13 +83,14 @@ static void async_pf_execute(struct work_struct *work) > apf->vcpu = NULL; > spin_unlock(&vcpu->async_pf.lock); > > - if (!IS_ENABLED(CONFIG_KVM_ASYNC_PF_SYNC) && first) > - kvm_arch_async_page_present_queued(vcpu); > - > /* > - * apf may be freed by kvm_check_async_pf_completion() after > - * this point > + * The apf struct may freed by kvm_check_async_pf_completion() as soon > + * as the lock is dropped. Nullify it to prevent improper usage. > */ > + apf = NULL; > + > + if (!IS_ENABLED(CONFIG_KVM_ASYNC_PF_SYNC) && first) > + kvm_arch_async_page_present_queued(vcpu); > > trace_kvm_async_pf_completed(addr, cr2_or_gpa); > > -- > 2.43.0.472.g3155946c3a-goog >