Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1180690rbb; Mon, 26 Feb 2024 00:56:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVauBMgbumgis6JrAEL0spqTaU+4ISm7tCM22eOAGKiqjyI88t/qb1+xlFmXu6sL+Or6JLn3K+qMs4utjlndxly+mlDag6O/dweKlF0ww== X-Google-Smtp-Source: AGHT+IEEHsFnVaLy80mSB1EQy3qy19Pp9+RRmf5nwR/MA1OsyMA1HTyMXrSmUt+pNm1eUcEp511Q X-Received: by 2002:aa7:c919:0:b0:565:ff53:5359 with SMTP id b25-20020aa7c919000000b00565ff535359mr622688edt.41.1708937797092; Mon, 26 Feb 2024 00:56:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708937797; cv=pass; d=google.com; s=arc-20160816; b=Va41iISDuPOt0//iqxBVBOY32rzQhAYGOWn5c49+vGGNfymMho7H+kM96Rwbwj+7uu w5LrJCncaJ3GBZ4leKdpIZT2PW9SzOILzF7m8DsXPRxf3t2PgDDuF0V8tykxZvzspQy5 JcFxuchjIqrxhOX7DH/Teeym4oQo9leqJ8p/th+LrO+qAlp1E0qOSE1C/sz5BqpoihFi esyvoh+aLGN/9tru07N/lI0AFePPDwnRV+rtxYRy5tqwjN7GNMHTpJBYQc7dinW6aqfO vNTB77i7mcRR9LJEIG76i51IEGxztmZKS2ivpOwxmkRRfj5hVVy8FHDp+BhFrKxzn12v dNKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nu6+pg+vq75PeMAKVZxsN21Hu5cvZnJ/yW+NgOuK2ac=; fh=GU4KR9NKf1qQHjmWlEi4zSAEAxyD6Pa0rUGDupPjr4Q=; b=YK2YOb0O00tnbQ1BbTInWLO2nNfr1KI2b/Qu1ZwCZwr01dysraCI3nT/4awM6RWcit nXjKBJuhYBKUjos+3VhVvtzc1qzJ+a5bcJK7FsawMgIMvXnuv2blBRUU840RZCoshyBu GEM1DAnayT3FNeDKd3PRvhmb0phRsXIv1/Cq2Uk7i3KT5VHQW6I/PlNd+NjLRZCIaayN sFlQbUC1Kin72RlEB1dG1ljBPLmQRageYhKAHGvxXVMfz12/g0RqTxSTYmpjlsF1V4fE 1y9VpI/KRvE9BvVfLNzmNw0K+ZD9SWIVIBfKBLNj+LJVkU9cptuNs08GLMgebNrrjfXI lK5g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="l2Z44U/U"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-80823-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80823-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. [147.75.80.249]) by mx.google.com with ESMTPS id a19-20020a05640213d300b00565aec519f8si1799272edx.191.2024.02.26.00.56.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 00:56:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80823-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="l2Z44U/U"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-80823-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80823-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 D22161F26556 for ; Mon, 26 Feb 2024 08:47:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7414462143; Mon, 26 Feb 2024 08:28:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="l2Z44U/U" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 01BEA60876; Mon, 26 Feb 2024 08:28:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936105; cv=none; b=sGhgyqEdFUf8lWb7lOV77o+02SbrUKwPdJtp/cW9WLAoMPYBQs/QSmrVrc8v9XruHABGFOvqP02GRH8qb15y7LoG3/H5OzC1e+cPMp3S/Waah4Yh0W4PuvqwbS1NJhH2AS946qZqKgVB67x4JR9lsG1FP01p09CG/ijyH/K+OVw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936105; c=relaxed/simple; bh=JTMod/uEmH5xtpRfr6dh/AqM/hDApc2nFe1BtZqLSW4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qmkJLLocgZ0XIpEJcN+G4fUDMZJTZGWnM2St24jtGUGzzEOkX/QBIm3bskK/hllzxkFrx36De0wuyB6GocyxfAxA5uxRkIF51Z1++NEE/9KeEpsWoL8CnCJtUEFWeZn2fM6shm5ZZy9DPcXYc3Rq4h8TDoXXgatefOsf0RJT6fQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=l2Z44U/U; arc=none smtp.client-ip=192.198.163.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708936103; x=1740472103; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JTMod/uEmH5xtpRfr6dh/AqM/hDApc2nFe1BtZqLSW4=; b=l2Z44U/URH/LRmIQ0ckFvOKQ6Lej7k8IXtDGoTHnQ01PVXyma/zelY/U daFBvg8qSpMGN4QlU/5APDZRApfa9/a25p+uLwH8TNsoqVWQ2KHYZWt39 0SZpnRgiI+5Q8MCbjw3p9GvweEVq6inR1bHn0K2LEHv2QS1Ao5BVb3Msq NpHVEzQ2+YCJPxnuAQ7XwdDiZkJarOLh4g9yJ62Fkl6XsoIQDyBR7QeUN XGMosTlpZud4fOIM9n23tHbJ0Cz9ezhVG7nhuZjjlJBRti34eSMHt1RYA imdZOZd1hMqvDZ4mxN/rSbu5iJjWUuVTc1YwLULC/CAMHorFh+IA358ex A==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="6155436" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="6155436" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:28:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="6615905" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:28:18 -0800 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, 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, Binbin Wu Subject: [PATCH v19 060/130] KVM: x86/tdp_mmu: Apply mmu notifier callback to only shared GPA Date: Mon, 26 Feb 2024 00:26:02 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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_young()() and change_pte(). Make 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 Reviewed-by: Binbin Wu --- v19: - type: test_gfn() => test_young() v18: - newly added Signed-off-by: Isaku Yamahata --- 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..10507920f36b 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_young()(), and + * 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(); -- 2.25.1