Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp473539lqh; Thu, 28 Mar 2024 07:27:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW6Rr6OIbGJoGRPniS6UabI6ttYviVbNxEr/jJK07C7Fv9HFVkS/RdFc5H9kVgETyypCF1icN1JKjgvqSwk/ps4ifHIpXg/aUpArAGR7A== X-Google-Smtp-Source: AGHT+IGHBol8ND2Dmjmc+cGzqRy3FZlp44vJl1uFkiynMwq0539K+ag0lNhau9mYRuxBkToAG1Vu X-Received: by 2002:a17:906:1b54:b0:a4e:23d4:ab83 with SMTP id p20-20020a1709061b5400b00a4e23d4ab83mr972768ejg.3.1711636029829; Thu, 28 Mar 2024 07:27:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711636029; cv=pass; d=google.com; s=arc-20160816; b=mevNfSGUyzJ0+pGeIiN2vFORCQDCeb17Ua8SqMoEPBRJek7AK+CmDk0dH8lIR57vnn dXIEFSebZNZhYAU/uAU+5lkafnE4AO+vwwBzmGFvabzbX7gt6by5HHHIcy4Q1U1ff+DT Sl36olsUVkaTwrABYV4gZ66By7ESt2gQ/CDi+5CCUQqRuHoEm5ej+HVg/aR+GZvyWzXv qAAaKKo7gZ9wmRTHi4TSS9eXTlzUzfCB8TRy3gXH8koKu3QJpC6Y6+3Jh946dywQ571G 5B2qdjWundlpFpRAH1ItxHzdXGvzFzle+JgD7ah9DqbUfLR3GsLkCTAnfYvrLg+lxOyv RmXw== 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=I1wLwsm6h4uj7jUGmmgFRO/+7Gk1aP2PWPCbGaTOABY=; fh=8scsGQn+hJ1HvbMI23kGOdGh/wtWpH4wdCi8Q1zCFc4=; b=IoAbUGyKFcbHYDdV8sYfhj6gm0Xi58ITZFDfTvcgQMGE1exGb7N/9o2VyjyPOpVZ3X /5oc2mrBq3Svl19VAt+++zEw6cqETLFXZ6ugjiH8rPxlV3lPYtt1fTAXx/MilswLET6U i5XOgj0z325mMFVDH9eYU54Mw7+2Pv+J1eCPqoATz0P8ZNge3fHDVHx5xHsIP3WcLSXX UVFaMktwIhYaDv+nEiKnznN5QpOAWDmgKfTdIi4klfvHYQ/sMvn/p91BPpKSk26Gdtyc 3qKKk8VM1zKNJ2bwCqOpaF9DfU4E9UMuu3CEfksIiLxOXuxi4DXS7RJr2VVIHoBBqT5x 2yBA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=euVUhZE7; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-122585-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122585-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 o17-20020a1709061d5100b00a4e2b8acd37si103254ejh.787.2024.03.28.07.27.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 07:27:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122585-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=euVUhZE7; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-122585-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122585-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 C42141F26E24 for ; Thu, 28 Mar 2024 08:30:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E91555E6C; Thu, 28 Mar 2024 08:29:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="euVUhZE7" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (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 C294B26AD8; Thu, 28 Mar 2024 08:29:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.21 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711614597; cv=none; b=N7sSZAQf9HIjXtyts8QBNj4JvS/0cUzLAcFTwi4xFbS0vdb8cp/F+1Ye3xBbifKhsvQh2MWzFDvXy/EJDHpJiHpiLJsWMWT4VlFQOFS/XBpW+1XQWfrb+uBvjzFfy9SJUY19H7yYMOAZswucgimPgOr21uoIsp3Trovkw6Y3vAk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711614597; c=relaxed/simple; bh=Xn5SRbo/tLLp83oxDcrfhoXAe/uHOAEhMew1J903Plo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Pgjs8zvUEtoPWhI5kXV+7ox5QroeZo7JYhZpzB3MJQXkwCvnnVBur7IoXamv1W2xrDjG5nI07MrbTYyIcPakJytjbzpAT4DMc9e7+cqos+j0mW5YiFQvVkxjeNH0aFX/ZDXWABib0sCuv/2yS2a3VeaMT0KBhEKO2c3PnngGUS4= 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=euVUhZE7; arc=none smtp.client-ip=198.175.65.21 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=1711614596; x=1743150596; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=Xn5SRbo/tLLp83oxDcrfhoXAe/uHOAEhMew1J903Plo=; b=euVUhZE7FIukN1euL84833Fd+GVjjvNXQqoyhHjHC2ocVPkjoOYPe1Bd lBVkMAqt+uatu41qeCwLs+j57F2DL3RYiHJpuVbFzkCwfS62ngtcSeVQ1 vhxBV+PJ74bxus0SYxsd2szQU5z8HoJFgzHX8+kDqFyGXJZGz8zwcxOR3 7xKGPI1hl0939YP6hrYoe3t33kCt6wg1D2k1QYJ6/GsxKR3GbcxHplvmv VR+3G4/L26hY+VXdQw+JB3TMtILfnmacg1YKQmGuxg8jvDNyws28m4Cq+ g3Aih16rx2KonZ1T/bf5/oyJkf4CsQW39fDsHXi4kQGRz3PcRfApL+wTI w==; X-CSE-ConnectionGUID: Pep6WMONSfWA3qWYbL29iQ== X-CSE-MsgGUID: b4zQk01GR9urSzFUcOgUbA== X-IronPort-AV: E=McAfee;i="6600,9927,11026"; a="6689945" X-IronPort-AV: E=Sophos;i="6.07,161,1708416000"; d="scan'208";a="6689945" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2024 01:29:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,161,1708416000"; d="scan'208";a="16518109" Received: from binbinwu-mobl.ccr.corp.intel.com (HELO [10.238.10.225]) ([10.238.10.225]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2024 01:29:52 -0700 Message-ID: <2f2b4b37-2b99-4373-8d0d-cc6bc5eed33f@linux.intel.com> Date: Thu, 28 Mar 2024 16:29:50 +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 v19 060/130] 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: From: Binbin Wu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2/26/2024 4:26 PM, 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_young()() and change_pte(). Make                                                    ^                                                    an extra "()" > 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(). The description about the "AS_UNMOVABLE", you are refering to shared memory, right? Then, it seems not related to the change of this patch. > > 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 ^                                                                an extra "()"" > + * 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();