Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp624883rdb; Thu, 18 Jan 2024 13:45:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFDJFUZV5DQBi9klbFMCsfWAEwdlmWYcIZYjfpKPHo9t723R3EL0V4tkAnIUSilyOZb+HrG X-Received: by 2002:ac8:5bc7:0:b0:429:d5a8:7e73 with SMTP id b7-20020ac85bc7000000b00429d5a87e73mr1650602qtb.24.1705614336624; Thu, 18 Jan 2024 13:45:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705614336; cv=pass; d=google.com; s=arc-20160816; b=VU42uT2SjpfVPPr7qdBYEft0FwcGGu5E5QPmM9dM1jzKJfkKMWJwO4lS2UHjSLCEQY 2ALKiPEiEZv8/y4PBaiY0KIYfMVNjXIAcIPUVebrAK50eUesOW2EUm41fOgoCoIsF5n6 jUCGevBtG0mdgeklnny5wHFog3wYYiv9MRIapi80jms4jZL5f+C7mT0tvLDuhqksZC3G NX5rJSPaHQAIjaaD2hF9jW4sJ+0Di6ytQPyYhi1LcDIjPOL3Yu3rEqhgp8sbmOdKsUAy UAji5DPMHgI5kn6D3ZDFvtSgkxN50Er75Qv12Uza0OZaqDgpcDca51O1MD44m/e9vWAN T8dA== 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=9qcvr779tsFmLU3fVdciuJVenOuSlBTRmE5MjSs68ZE=; fh=i5baoZHTgNYq7pA/Pa1Y+CPNCimF4oTXxWxU53KoRxw=; b=IAhqOZOSCcPUoZaVoEKpZqMSip/MU5Scil7n/YE+e83dEujFDuorQbEgBbjUrUu1Ru s10mz7iKnmNpXhBYQ8RNLY2xDAOKGztmD3oAl+WotVlVItrJq+1Z5IejL61lQ4IAA6XE kNr+bwz3tYHaNQHk76PnwGqWDnj5GhM89yQdg1eB39QtDarXH5dHPqT2msWQo7vnF2+Y ONw2gDyVlb8QtLxOtFk8QO0gBhO+94k+SNRnp7BtdaQT9xfDnCz53mZ6d7nk3nYpscjp MoNUWMS2xWHj4aeQrv953MkOCAoJxU4KII3vbPkKGWhf3kxVD/POEO2lW7tpmDwI5Sn+ eUSw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HkIoxE7D; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-30359-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30359-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w13-20020a05622a190d00b00429be6b6a64si15237548qtc.580.2024.01.18.13.45.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 13:45:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30359-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HkIoxE7D; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-30359-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30359-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 36FAD1C232B1 for ; Thu, 18 Jan 2024 16:41:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4FCDA2C1BD; Thu, 18 Jan 2024 16:41:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="HkIoxE7D" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (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 278D22C194; Thu, 18 Jan 2024 16:41:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.120 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705596110; cv=none; b=eKvHW9JQ315kdNS4WjqKNJN0dN/Hd1RlkN8EVp+oceQ4MkEeMhz8Tl+UxeZyERnAkucpgxVAxocTx+X2pnrBGUEq0hJMOQV/eK7YIIDHor5h7viG8d6dp8F3bcqXdXeRrVq1JR6PwoDyybUWwIaEYfFKu2qBaci3sJGIn9DbCIU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705596110; c=relaxed/simple; bh=8ZoeWyhYJAXsI3uEm8LqP0ONHfsUFdg+kjcwc5JHX1o=; h=DKIM-Signature:X-IronPort-AV:X-IronPort-AV:Received:X-ExtLoop1: X-IronPort-AV:Received:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To; b=BzbMUSsO9Kreovj1QBtJC+rwbJeABQJqNDCvDpzYDw5/7S/0HNgoZcEbvQqPGXC8rQjOcQPg/qquYXrbK6ILkhIMtXh7c4Ut3Q5uu27F2gYsZUJKCK2vIdmM99yOvuAIgr39JjKm7ryA3ug3KT30RmbTf+5iksUJQaRlz9CNRmU= 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=HkIoxE7D; arc=none smtp.client-ip=192.55.52.120 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=1705596108; x=1737132108; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=8ZoeWyhYJAXsI3uEm8LqP0ONHfsUFdg+kjcwc5JHX1o=; b=HkIoxE7DPgJUQqsN5lLnsT3OBRDBUETfzqVHTa4SYWkLTwXJsAq/Ot8P 7FeQDCEc0XdRPwUXE7vum6wQODM9/+fEwMpjUBat7+ufKuLB8NErVbNkM RApnaL9CsyvYl9YCK12qTKh7i1VWlflSL9GTAR8L4Pb7HqE0h6C48cFIF GXKzXl2+l8B1BXSmADT7NXOA9QdGz4rEbweGHdOGN5urxG0j78VU9PLyZ Lmg7tx1Sp5Ndr79EKu4GmTBSr8T5wJRs7Ncr2d4W3oHtWYatoRqYZMrnc 5CNrXXaDaVCKO0wM/lG4Vw/7fEjyCBpWNSrzNGOghqiLIqI+bz3eVJ0m2 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10956"; a="399376808" X-IronPort-AV: E=Sophos;i="6.05,203,1701158400"; d="scan'208";a="399376808" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2024 08:41:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,203,1701158400"; d="scan'208";a="405234" Received: from yilunxu-optiplex-7050.sh.intel.com (HELO localhost) ([10.239.159.165]) by fmviesa004.fm.intel.com with ESMTP; 18 Jan 2024 08:41:47 -0800 Date: Fri, 19 Jan 2024 00:38:36 +0800 From: Xu Yilun To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yan Zhao , Kai Huang Subject: Re: [PATCH v2] KVM: x86/mmu: Retry fault before acquiring mmu_lock if mapping is changing Message-ID: References: <20240110012045.505046-1-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: <20240110012045.505046-1-seanjc@google.com> On Tue, Jan 09, 2024 at 05:20:45PM -0800, Sean Christopherson wrote: > Retry page faults without acquiring mmu_lock if the resolved gfn is covered > by an active invalidation. Contending for mmu_lock is especially > problematic on preemptible kernels as the mmu_notifier invalidation task > will yield mmu_lock (see rwlock_needbreak()), delay the in-progress Is it possible fault-in task avoids contending mmu_lock by using _trylock()? Like: while (!read_trylock(&vcpu->kvm->mmu_lock)) cpu_relax(); if (is_page_fault_stale(vcpu, fault)) goto out_unlock; r = kvm_tdp_mmu_map(vcpu, fault); out_unlock: read_unlock(&vcpu->kvm->mmu_lock) > invalidation, and ultimately increase the latency of resolving the page > fault. And in the worst case scenario, yielding will be accompanied by a > remote TLB flush, e.g. if the invalidation covers a large range of memory > and vCPUs are accessing addresses that were already zapped. This case covers all usage of mmu_invalidate_retry_gfn(), is it? Should we also consider vmx_set_apic_access_page_addr()? Thanks, Yilun