From patchwork Mon Feb 26 08:29:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 206485 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1957053dyb; Mon, 26 Feb 2024 01:22:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWb06mlmtAVAuz5PL9LhkkkTb3UluHRgV2hV8895fM6OiITBgVrsXVJEPEaI4rye37XbBzClC3i0LnVMXKBoxPes3DwXQ== X-Google-Smtp-Source: AGHT+IE6wtPexOIWGJDhecfpP2X5IR2J13QjobXGGKTzPnn6MeBQiliVjU4YHhbEQD7WEyn1kDem X-Received: by 2002:a17:906:1e93:b0:a3f:6942:a213 with SMTP id e19-20020a1709061e9300b00a3f6942a213mr4017903ejj.32.1708939364574; Mon, 26 Feb 2024 01:22:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708939364; cv=pass; d=google.com; s=arc-20160816; b=mu2aErYjgiZ0lPBAHUlSJ0AtZOkT6mVO7pyNopLE+JtDeKKSWYFoTzck247ES+64CM n4L7brnrzYnXvwOwHgIpUyHw6pzGDHi6t5ZJEXNC49H94dTDWu/39s+8fE36ukY3bpf2 LrUU/0QdWW/wCHJQQ+JcH2+TDdP+CmI2QUjM0wnd4pIjd5jAK2M/+25UYTfzmINkWLDY pUXbYZ9rHeGD6JdktKt+4c1Eg9xdFwk+xS8PKQuYK2M+WczPdh4E2Fs12FTyoYgxhWiv 95NBS9/Riws3uDT4Lu2Oo9GDjVvVOWdpPK0unNYtmkTDr5pAhAS2Qo1mf38sNmpLcpdA +c9A== 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=8N9nOucbqRuxh9xPPBgQhti6DMnryK6L7yN/1ibiVAc=; fh=sMdP/xP2j0mAr7mmqXKi/DmIqVqVXObmf3aqGFg9BJU=; b=N7ZDuRSWvpMYObM5sXAXNuyvcjABcxwMdLdKDwefVhJi0FLO3qd/H3xLND1cs73o+j nr044suSwfyEKNgrHfBUzYie2cp6Hcv1eZ9Sib56c8v1TsBrvzgtoINu+EQdgotC6YuQ 2EGXPIj60qdHEcKUhRRbpu5b/5LFKKYAXtepEVoso/EVafdK36qD3ahsEh1Cw8zDCL/7 Nrv2mhYZZwnFWWpzoOJB2YUHmYamrFsUmj5s/qLrqMTxNqua4IaXsm8ZWMD64vglNxNq KIU8ZZyO8pMOcGO1LOXyRmjALTZY4hkuWWHT73O5fpv++nTTiU8iz807G8NrsLIhdopy ssGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CHw7tusO; 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-80898-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80898-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ji10-20020a170907980a00b00a3e3fab918csi1931497ejc.428.2024.02.26.01.22.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:22:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80898-ouuuleilei=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=CHw7tusO; 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-80898-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80898-ouuuleilei=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 73C1D1F265BD for ; Mon, 26 Feb 2024 09:13:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 394E113399F; Mon, 26 Feb 2024 08:29:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CHw7tusO" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 9DE32132C04; Mon, 26 Feb 2024 08:29:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936177; cv=none; b=eQxBxC+JuxIrMUfsEMtdyc6+oQ/nYIXIkhvxIv8EoP65OzhmrmppQK7jH0ciIRa2r3c+cJzd4AezGKddqvnWkesnLZoT/zuXfqTQjBety/uiY5XYGpiAvPo85MPEjH264KBOzj6RylDKZgIdLDy+r5c3atkbwQF+7H2MexmAoao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936177; c=relaxed/simple; bh=9sC+tVDstlmuTrpJLRIwemasGuxQzkEeVSSJPRH35IY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iFiqQRoJyvnsqkc3S5UJ0gahvKswEBwiZ/QG2TqkEcewXYQAPH3LlM1Jw4T0XhznidAUSUwM9aMprQnIF0wfcl9gZ29V9btWXadSQ7SK9Q0cZX3KLKdPI3brNlObp/8IM26ChSEkKi3xfrJJQjp0wE/fI3HkNMYRaL9mM0EXNLg= 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=CHw7tusO; arc=none smtp.client-ip=192.198.163.8 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=1708936175; x=1740472175; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9sC+tVDstlmuTrpJLRIwemasGuxQzkEeVSSJPRH35IY=; b=CHw7tusO+9QApu9CBLSO1jjmYdVkdRcJYNkHU4Xm/YgCzF8h66DDDW51 3oJs8ZQOZENdtdLA+N/iYff626xsvL9JC2clWRAN5OpKWCd1efpzryxc0 MaJklo0T+2Xz3N1FKadOyZQQSkPAM+zE/PmuQfMnEwI676b8x3W/kAAnw 7gQEACu6p54VVGRr1krZ8R+sl+/RPv0WMv5XFX9Oi3F9nH82o2geFF7zR kqzzUHq3wd4qb71TyjPj0i6KZUmSBPPNeMzU4oK5dUz5Nj+6urF2ciEFE t9EnuUv2xGBy5Jpij8LjCCx++/kDlzD6FH1yfYWb0DgJmpbr1E2hsWv4x w==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="20751505" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="20751505" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:29:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="6735293" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:29:32 -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, Xiaoyao Li Subject: [PATCH v8 03/14] KVM: TDX: Pass KVM page level to tdh_mem_page_aug() Date: Mon, 26 Feb 2024 00:29:17 -0800 Message-Id: <8f4125c90898652317ae6bec5d46fe45d3f11eef.1708933624.git.isaku.yamahata@intel.com> 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791952803017271539 X-GMAIL-MSGID: 1791952803017271539 From: Xiaoyao Li Level info is needed in tdx_clflush_page() to generate the correct page size. Besides, explicitly pass level info to SEAMCALL instead of assuming it's zero. It works naturally when 2MB support lands. Signed-off-by: Xiaoyao Li Signed-off-by: Isaku Yamahata --- v7: - Don't pass level to tdh_mem_page_add() as it supports only 4K page. - catch up for change of tdx_seamcall() --- arch/x86/kvm/vmx/tdx.c | 2 +- arch/x86/kvm/vmx/tdx_ops.h | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index a71093f7c3e3..fd992966379c 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1470,7 +1470,7 @@ static int tdx_mem_page_aug(struct kvm *kvm, gfn_t gfn, union tdx_sept_entry entry; u64 err; - err = tdh_mem_page_aug(kvm_tdx->tdr_pa, gpa, hpa, &out); + err = tdh_mem_page_aug(kvm_tdx->tdr_pa, gpa, tdx_level, hpa, &out); if (unlikely(err == TDX_ERROR_SEPT_BUSY)) { tdx_unpin(kvm, pfn); return -EAGAIN; diff --git a/arch/x86/kvm/vmx/tdx_ops.h b/arch/x86/kvm/vmx/tdx_ops.h index 3af124711e98..ef4748943ac7 100644 --- a/arch/x86/kvm/vmx/tdx_ops.h +++ b/arch/x86/kvm/vmx/tdx_ops.h @@ -51,6 +51,11 @@ static inline int pg_level_to_tdx_sept_level(enum pg_level level) return level - 1; } +static inline enum pg_level tdx_sept_level_to_pg_level(int tdx_level) +{ + return tdx_level + 1; +} + static inline void tdx_clflush_page(hpa_t addr, enum pg_level level) { clflush_cache_range(__va(addr), KVM_HPAGE_SIZE(level)); @@ -100,6 +105,7 @@ static inline u64 tdh_mng_addcx(hpa_t tdr, hpa_t addr) static inline u64 tdh_mem_page_add(hpa_t tdr, gpa_t gpa, hpa_t hpa, hpa_t source, struct tdx_module_args *out) { + /* TDH.MEM.PAGE.ADD() suports only 4K page. tdx 4K page level = 0 */ struct tdx_module_args in = { .rcx = gpa, .rdx = tdr, @@ -170,16 +176,16 @@ static inline u64 tdh_mem_page_relocate(hpa_t tdr, gpa_t gpa, hpa_t hpa, return tdx_seamcall_sept(TDH_MEM_PAGE_RELOCATE, &in, out); } -static inline u64 tdh_mem_page_aug(hpa_t tdr, gpa_t gpa, hpa_t hpa, +static inline u64 tdh_mem_page_aug(hpa_t tdr, gpa_t gpa, int level, hpa_t hpa, struct tdx_module_args *out) { struct tdx_module_args in = { - .rcx = gpa, + .rcx = gpa | level, .rdx = tdr, .r8 = hpa, }; - tdx_clflush_page(hpa, PG_LEVEL_4K); + tdx_clflush_page(hpa, tdx_sept_level_to_pg_level(level)); return tdx_seamcall_sept(TDH_MEM_PAGE_AUG, &in, out); }