Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp926468rdb; Tue, 30 Jan 2024 02:57:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHIZbkzTdtvcxguRs7XJppZwVnrZv5SjQ4cyuI2TEpmuR7LNID3vO5mVeAZIT4hTZbSxRAx X-Received: by 2002:a17:906:af06:b0:a35:543a:f0b1 with SMTP id lx6-20020a170906af0600b00a35543af0b1mr1193275ejb.17.1706612232979; Tue, 30 Jan 2024 02:57:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706612232; cv=pass; d=google.com; s=arc-20160816; b=EdLLVTCEobb8Am3Jsf0epjT6SzEfvJi4+WSJN5qjw21fyxnUan0bhUoeF9ldD42C+I flVMO2ZhwOZFS281iFDQN4xA4Yot2wbM7gJkGNYMtxOUMuiHWWAIu5xU5j04+UlHumTX j7/TbEJLB0FHgZeTU4nGkHV+RJFWbT+O5rJaK2yjwolSVMx63UMVqhGY/AsVAiCENyPP rxlT2X5ipItLoSLVnBJu0b2t/33Zyq8rLrLOAbRd/UGY/ODh36EXSaItgnAX3fABgH7Q NzZOjNexRzaikYC9u1ht4+z1AEiMVfGHb9m+1WkiiGrX/Kz+f8ldrB2eEg+N3jJzuSDm qAXQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=zDBLylnVCyMn/+gsGrBXk42SAJRVjuRum6mWEeuvzj0=; fh=8scsGQn+hJ1HvbMI23kGOdGh/wtWpH4wdCi8Q1zCFc4=; b=j7pUwpfnOPz0Ar+6SKEoc55PqRost4nNBMywzzE+HcryAn5MJGW7vsDYHcfHzGpuFv C4K45XL+zyrkRPHaiNeR0FCwS3eeg0Z5MNi4oqleXpPj0K3xnth4a3CaR4HZHSZSLttg 1RHuwlTxVwpJAW3KaUL9KkZY8h8YlXHPe9lHeVyEWgpPfO0pxjsjGvq827bcxakuhBVk 4wnXIfSLOMx1QWGqukDvaGQxOp3i9sQD4cx7BecnssZIVIZ9TeN9ED2HsTDXCysCPI9v DF3CJf2VDvmyMiZ/jJx/J6c0SOu4VF5rcGMeKHca8BVp/UKrqgUw46dpyQRwFPbmbRdL tC3Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V+MwBcZg; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-44031-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44031-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id p3-20020a170906a00300b00a35375c329asi3532709ejy.1019.2024.01.30.02.57.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 02:57:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44031-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V+MwBcZg; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-44031-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44031-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 am.mirrors.kernel.org (Postfix) with ESMTPS id C5A401F26817 for ; Tue, 30 Jan 2024 07:19:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 16CB94EB49; Tue, 30 Jan 2024 07:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="V+MwBcZg" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) (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 4DF123C498; Tue, 30 Jan 2024 07:19:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.115 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706599186; cv=none; b=NWy6I0cboMQlQ3hkac7+GTWF4PYKCXGU39hIv3li+QEwEpRJf4ggYBWuPVbsACLSplI05YIrbSN3Z3zTT8AciPDqVk7cSQOSBOUR/d/kBVX9lzE+2PrS/ygBtVxGCC3hkle11xqpf7B0PfVU5q+wZfe98ronA0/ycyMz0Cmtc3I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706599186; c=relaxed/simple; bh=JIWHomHQ/bgABZFIZYxMyetlwrTR/dSFit34KIYnSjk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=JOQg2pLg1ndC12AV8Ey5FuAJo2NkxLmrKX2Jk3CnVTgKM2nJijFvJ/aUARkByMVxvBDdAHRlzByGw7+oo1+GiB1dgixDRCNW+/mP7bnaGzjuC+idtWj2VTXmt0XoWfTDkR3TAKYb6KfSBvTV7VPpI4JVJQ5f17KMTpPDJQYGq9g= 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=V+MwBcZg; arc=none smtp.client-ip=192.55.52.115 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=1706599184; x=1738135184; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=JIWHomHQ/bgABZFIZYxMyetlwrTR/dSFit34KIYnSjk=; b=V+MwBcZgyJWO/qgB4AnYbQJKmVk71IHPHUXG8ok9FBhxsg1V1GZ3pXbZ 5v/vmpRoCrUbe9LLP8sXq7mokyMSJQ6aqp+8NBWHpAw0LhPPChl7db0V6 hqvGiuLS1+1eKb1zJF0HvMN63zgzV+2FXkEdAfzvyt2UC8eK8I2M6UpaR u5Ket2z/svXFFcIiFjkvKLV3um7cWWbEjEeURg8GyI1GlIUSOLX5iHV89 ggWLnGmV1IPzhR9VBT5lwUupcFlNgjEBOaY6YQdRZklOyU0nzpFUiWPvq ZNEIrNPyyVaNDCxilJFZfFhNIsagP0o6UfXs/DRVRhpvno+KGi9xB87GH Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10968"; a="402824433" X-IronPort-AV: E=Sophos;i="6.05,707,1701158400"; d="scan'208";a="402824433" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2024 23:19:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,707,1701158400"; d="scan'208";a="3652047" Received: from binbinwu-mobl.ccr.corp.intel.com (HELO [10.238.10.49]) ([10.238.10.49]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2024 23:19:41 -0800 Message-ID: Date: Tue, 30 Jan 2024 15:19:37 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v18 049/121] KVM: x86/tdp_mmu: Apply mmu notifier callback to only shared GPA To: isaku.yamahata@intel.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com References: <9f64fe39a205b769bf08f2996efb0b5afc6c1900.1705965635.git.isaku.yamahata@intel.com> From: Binbin Wu In-Reply-To: <9f64fe39a205b769bf08f2996efb0b5afc6c1900.1705965635.git.isaku.yamahata@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/23/2024 7:53 AM, isaku.yamahata@intel.com wrote: > From: Isaku Yamahata > > The private GPAs that typically guest memfd backs aren't subject to MMU > notifier because it isn't mapped into virtual address of user process. > kvm_tdp_mmu_handle_gfn() handles the callback of the MMU notifier, > clear_flush_young(), clear_young(), test_gfn() and change_pte(). Make Nit: test_gfn() -> test_young(), and a same typo in the comment below. Reviewed-by: Binbin Wu > kvm_tdp_mmu_handle_gfn() aware of private mapping and skip private mapping. > > Even with AS_UNMOVABLE set, those mmu notifier are called. For example, > ksmd triggers change_pte(). > > Signed-off-by: Isaku Yamahata > --- > v18: > - newly added > --- > arch/x86/kvm/mmu/tdp_mmu.c | 22 +++++++++++++++++++++- > 1 file changed, 21 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c > index e7514a807134..fdc6e2221c33 100644 > --- a/arch/x86/kvm/mmu/tdp_mmu.c > +++ b/arch/x86/kvm/mmu/tdp_mmu.c > @@ -1157,9 +1157,29 @@ static __always_inline bool kvm_tdp_mmu_handle_gfn(struct kvm *kvm, > * into this helper allow blocking; it'd be dead, wasteful code. > */ > for_each_tdp_mmu_root(kvm, root, range->slot->as_id) { > + gfn_t start, end; > + > + /* > + * This function is called on behalf of mmu_notifier of > + * clear_flush_young(), clear_young(), test_gfn(), and test_gfn() should be test_young() > + * change_pte(). They apply to only shared GPAs. > + */ > + WARN_ON_ONCE(range->only_private); > + WARN_ON_ONCE(!range->only_shared); > + if (is_private_sp(root)) > + continue; > + > + /* > + * For TDX shared mapping, set GFN shared bit to the range, > + * so the handler() doesn't need to set it, to avoid duplicated > + * code in multiple handler()s. > + */ > + start = kvm_gfn_to_shared(kvm, range->start); > + end = kvm_gfn_to_shared(kvm, range->end); > + > rcu_read_lock(); > > - tdp_root_for_each_leaf_pte(iter, root, range->start, range->end) > + tdp_root_for_each_leaf_pte(iter, root, start, end) > ret |= handler(kvm, &iter, range); > > rcu_read_unlock();