Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2261689pxm; Fri, 4 Mar 2022 12:34:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzXnKY17L/DszvFU1fF/sA5yxOurhDT5xEXAjRzFGMSAYLEOzJNAMg0L6ZZYFsN+M3vpI5 X-Received: by 2002:a05:6a00:805:b0:4f0:fea7:d3c7 with SMTP id m5-20020a056a00080500b004f0fea7d3c7mr217772pfk.54.1646426080669; Fri, 04 Mar 2022 12:34:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646426080; cv=none; d=google.com; s=arc-20160816; b=O1emu+T0R9+FmKqJ6J/u8Rz1GSfbuCUjLHqRdaE4Q/xA0xVdPSj2lJq7iOSHYnLN2L 0Cu/SLbJ63gg/Gqi3YYMvFqCc74Krzzq2BY8sDV9tQAziVzxILXeYFgsAE9vc8bKMOpX BrG1QZcgEWxMylSyjGQxrfy9zBftXrFLljNkvIcoEzJHLlUkjVJ2dz0W4+2dlJsHo/fa 0PqyiBlIzF2B73fuE2vkMu8N4hvjwEJNgdz9LCD8V/uCK9ppsLQWFC3M8T4q8szjJp3J TgTXLjMr1GAUAIu3Z3pbn9W4UUruqs6NqjK8EG9wbgATd/9Mwiy0o5UegXQLYVWXPMlU 0xOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bAIFSLYCWT/esVnMu+sC7iFliZEeb3TRg4l/378c4Tc=; b=bO0i0OnwQKMKUyRDIkbJm9SVP7Wvzu85/M9wd1aljPfXR2btheAqCCIDUcda8dB1KC q+pgfmS0CFbl2N9ZgJhsAHJbtLHy9QL9JkxIc+YbsxokGdjxnMFFSfra1BsWgi11OUvc PwkRSPwTHWx6LqpIzRVXuibrCm6C8/jcheDGKnDxMeUTzLkcNVlD6ZTTIN4WlAS5HfEU 39Ud60WCiKiiPWRy84pmbprtfusGkPIbwfTU7cbfHwFa9smpzxJW9S2Vg8SQL4EKqvia BMEMN3GNzITxXZ0I3a4fOQpELZiDXtDbp/4H+eB8qCkW6O+Ug9MkOb0kDW2QZlunF43D bGag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IwfV0R+u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x1-20020a170902ec8100b001519d03da99si5684872plg.407.2022.03.04.12.34.25; Fri, 04 Mar 2022 12:34:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IwfV0R+u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231130AbiCDUe0 (ORCPT + 99 others); Fri, 4 Mar 2022 15:34:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229946AbiCDUcU (ORCPT ); Fri, 4 Mar 2022 15:32:20 -0500 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4920B1EE260; Fri, 4 Mar 2022 12:31:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646425888; x=1677961888; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JN/QmgwHHgOhVkALs0KxzUApbbVjylIiYKcWhfxJUeE=; b=IwfV0R+uo368ekZvHfTpv6rOKRgjOY0BJp3JaZqEwL7tv/UXGRN329zr GrspQpGFDWz7DeGcVMPKJ5aTKLoOQfnDYfQVJqyWsle7Z7ihEnpfEOaAh eLzEO2bFnYecpZM1CD5kMP/mTIMvEqobuV7YmGIzS6pmOu6h+OhpMjbGR w6538oi6IFWv0psnNn9n9LEPYkKJ15JNUR6eb8cATebUdHDAko4eogV65 JTFX3U/BxkmRRZrNEslZiePjvcBUbVP8AItvtl2VhJ/BHZEykfnWcO9Gi 6o9RLN3RRpmrhd5L/cBSSBd+NlyIb4etH+cHUmkA8C/ECDJdmEjj9xPdx Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10276"; a="251624224" X-IronPort-AV: E=Sophos;i="5.90,156,1643702400"; d="scan'208";a="251624224" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2022 11:50:27 -0800 X-IronPort-AV: E=Sophos;i="5.90,156,1643702400"; d="scan'208";a="552344403" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2022 11:50:27 -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 , Jim Mattson , erdemaktas@google.com, Connor Kuehl , Sean Christopherson Subject: [RFC PATCH v5 055/104] KVM: x86/tdp_mmu: prevent private/shared map based on PRIVATE_PROHIBIT Date: Fri, 4 Mar 2022 11:49:11 -0800 Message-Id: <273543bac1c40c869a68d3f72eb2abc03106e8d9.1646422845.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Isaku Yamahata Use the bit SPTE_PRIVATE_PROHIBIT in shared and private EPT to determine which mapping, shared or private, is allowed. If requested mapping isn't allowed, return RET_PF_RETRY to wait for other vcpu to change it. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/mmu/spte.h | 2 +- arch/x86/kvm/mmu/tdp_mmu.c | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h index 25dffdb488d1..9c37381a6762 100644 --- a/arch/x86/kvm/mmu/spte.h +++ b/arch/x86/kvm/mmu/spte.h @@ -223,7 +223,7 @@ extern u64 __read_mostly shadow_init_value; static inline bool is_removed_spte(u64 spte) { - return spte == SHADOW_REMOVED_SPTE; + return (spte & ~SPTE_PRIVATE_PROHIBIT) == SHADOW_REMOVED_SPTE; } static inline bool is_private_prohibit_spte(u64 spte) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 6d750563824d..f6bd35831e32 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1038,9 +1038,25 @@ static int tdp_mmu_map_handle_target_level(struct kvm_vcpu *vcpu, WARN_ON(sp->role.level != fault->goal_level); - /* TDX shared GPAs are no executable, enforce this for the SDV. */ - if (!kvm_is_private_gfn(vcpu->kvm, iter->gfn)) - pte_access &= ~ACC_EXEC_MASK; + if (kvm_gfn_stolen_mask(vcpu->kvm)) { + if (is_private_spte(iter->sptep)) { + /* + * This GPA is not allowed to map as private. Let + * vcpu loop in page fault until other vcpu change it + * by MapGPA hypercall. + */ + if (fault->slot && + is_private_prohibit_spte(iter->old_spte)) + return RET_PF_RETRY; + } else { + /* This GPA is not allowed to map as shared. */ + if (fault->slot && + !is_private_prohibit_spte(iter->old_spte)) + return RET_PF_RETRY; + /* TDX shared GPAs are no executable, enforce this. */ + pte_access &= ~ACC_EXEC_MASK; + } + } if (unlikely(!fault->slot)) new_spte = make_mmio_spte(vcpu, -- 2.25.1