Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1453933lqh; Mon, 6 May 2024 08:10:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUgLQHqQfXVRw9KZYvMKwHopKLguebHSxAPpOXbqf9/0soCT+FHdRgtrSwNEhxjkxWxljvigQoiv2490XBcc9TnUv8OAm9EegVBg99Wdw== X-Google-Smtp-Source: AGHT+IEQzrT3SAVigFJJXWjOh4ktOzqCWP9emIjcY3F5+1ObZWAlo5+Du+MRp5qdcAieOuAeQUEu X-Received: by 2002:a05:6a21:3a82:b0:1af:9633:b8a1 with SMTP id zv2-20020a056a213a8200b001af9633b8a1mr9301851pzb.47.1715008232873; Mon, 06 May 2024 08:10:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715008232; cv=pass; d=google.com; s=arc-20160816; b=q+ql/4zMPa3W33W3umNDH600s9/SgTkdHb7rnBc240vvWWStRU3cwshM6c7OxH0kD8 o25yLVe1r2APEbNTEzahj9qfk7JfOicieusKIH37JWxjKLG5HEbP84J95gHgmTbJxeBC J4PKD++3dlxv7sQblDqy2ak7JoKlbMMbWafHoNAR7UGaBgyjPLiHo9KEqM2KThJDOCLM 0CJ08AaMQhdTLecAzTIbWFtUyQmRbwRBGRJjcLbl1390F/U9ZJ+kegel4PbYl1ccX6G+ ruZNU5PPvhteRUKnWwDwbPCaq/w/M22CJ8VgJs3un4X68jxAtDGU+4z0ppS0Xz6Kohmr sNNw== 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=AkKBgZ/dTQE0ehe1GEv1kO1UNMKQB32X06WHTnj9X5o=; fh=v5fQD61/3lFRgyOwuTPBxnbBxoqvt+owkNJYiKbYYTQ=; b=MuhkuB2vg7N2RH7llIWoa5EyM8VObMsEPWdhb2ROt3LM6VzMgVF7YuUDgKA7zKZqRK Uq3hSGjB610VGEqbSFPlw0h5Wq486oSs6axrDKbJCXrEXar4CEzDvQoIPVIdGEfYE0IL 8Zdn6aMferMxL+Fx1H9gwz0LCGCxByXaVa3UB20Ho8wyPnXgfkUVb7jrEeUhPOUiWqwf aXscP2tnBtjImwxzmDPRaT6UxH7amr4V4dhogmfOvqgu9Uj30xcgEb+fTGdcnYmfACA+ EdkkFaj4WnAUnXPV8dVzxvX0AhnXSdWm4ELY+lxntNJpt4Rv6VRiCIsK9dKHZHeUfntg o5nQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YCyP90g5; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-169785-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169785-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s127-20020a637785000000b0061bc3b59f15si7381257pgc.701.2024.05.06.08.10.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 08:10:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169785-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YCyP90g5; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-169785-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169785-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id ED4E7285367 for ; Mon, 6 May 2024 12:16:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0241F14430A; Mon, 6 May 2024 12:16:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YCyP90g5" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 DA8A9143C4E for ; Mon, 6 May 2024 12:16:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714997763; cv=none; b=DC1C2dw70/0KhbPWfDWgXm7OCcK7HryXVwSmhdd+gTPWDpRQLIjoBSPaSmunMHENhhcTrOXSokIRL6/tHe+Sd4DYmGSorR8CBKOR0UbYttkJWdXF2+AtYNahNqZyaLfgrDjeAmf1XCQu5vbZF5bWZ9QTevimQphZ9vaLGOMJ3Vc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714997763; c=relaxed/simple; bh=UWI7SZcBOgCHA8M9jnJU6XD2NRmEw9ukmCbYEbQq3A4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LQTzUvuQAisi+2H4Qr6STq2CGWb9dUVBmSCpoHlzAHvpTV2LZ8lx6Kj2vs5J9jGXLcPNANzLXR0qPRBBXeRnG00QiXADamJZgyMHOWf4HQRFmOU0ldoNonPaKDjsgBiiRLPYxs6TfZ5jc/ya6pY7jrVfRSwhgt07nRJqPclQeCM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.helo=mgamail.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=YCyP90g5; arc=none smtp.client-ip=192.198.163.12 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.helo=mgamail.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714997762; x=1746533762; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UWI7SZcBOgCHA8M9jnJU6XD2NRmEw9ukmCbYEbQq3A4=; b=YCyP90g5jShosYMbGTwgEXoXTcXK05SWfcEulNIut1H71uYKlyL4Zs2e rfvClZFOpuw9OClc4hpjTDZxqP3A61lp0oaPw/gNgUZ5RjHn13HpeS6z7 4k41oV3lFYMMQyAws267bf3W3znGPPOLD4bMqhlWbjLubtUehIhLBpkJN M6V1vrZsWykHkyZkgKDhYkhsDJhgk5eFBeKBwP7G287YNAleQatuAcvOm Fl3WX7JTU9cebwN1ftz0WyvoOhM8w7s+TU149cAgz+FwEAD1lOZ7ICtC8 Y6zlqdkxRoguskiTkPsDR7oXbCcmuIgzkMTix2t0maAAycTj8CPrLd9pL A==; X-CSE-ConnectionGUID: CyzDtEFsSXiqf8VWlYY4aQ== X-CSE-MsgGUID: sdYBnUS+RXCFzCw1YC3HFA== X-IronPort-AV: E=McAfee;i="6600,9927,11064"; a="14544143" X-IronPort-AV: E=Sophos;i="6.07,258,1708416000"; d="scan'208";a="14544143" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 05:15:58 -0700 X-CSE-ConnectionGUID: OKLBKEwtQieC/6PqpPobyQ== X-CSE-MsgGUID: irIzFggdSm6mCpgEpf1how== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,258,1708416000"; d="scan'208";a="32951441" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa004.jf.intel.com with ESMTP; 06 May 2024 05:15:56 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id DC7D5161; Mon, 06 May 2024 15:15:54 +0300 (EEST) From: "Kirill A. Shutemov" To: "Kirill A. Shutemov" , Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Cc: linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Kai Huang , Kuppuswamy Sathyanarayanan Subject: [PATCHv3 1/4] x86/tdx: Factor out TD metadata write TDCALL Date: Mon, 6 May 2024 15:15:50 +0300 Message-ID: <20240506121553.3824346-2-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240506121553.3824346-1-kirill.shutemov@linux.intel.com> References: <20240506121553.3824346-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The TDG_VM_WR TDCALL is used to ask the TDX module to change some TD-specific VM configuration. There is currently only one user in the kernel of this TDCALL leaf. More will be added shortly. Refactor to make way for more users of TDG_VM_WR who will need to modify other TD configuration values. Signed-off-by: Kirill A. Shutemov Reviewed-by: Kai Huang Reviewed-by: Kuppuswamy Sathyanarayanan --- arch/x86/coco/tdx/tdx.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 59776ce1c1d7..b926221f1264 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -77,6 +77,18 @@ static inline void tdcall(u64 fn, struct tdx_module_args *args) panic("TDCALL %lld failed (Buggy TDX module!)\n", fn); } +/* Write TD-scoped metadata */ +static inline u64 tdg_vm_wr(u64 field, u64 value, u64 mask) +{ + struct tdx_module_args args = { + .rdx = field, + .r8 = value, + .r9 = mask, + }; + + return __tdcall(TDG_VM_WR, &args); +} + /** * tdx_mcall_get_report0() - Wrapper to get TDREPORT0 (a.k.a. TDREPORT * subtype 0) using TDG.MR.REPORT TDCALL. @@ -902,10 +914,6 @@ static void tdx_kexec_unshare_mem(void) void __init tdx_early_init(void) { - struct tdx_module_args args = { - .rdx = TDCS_NOTIFY_ENABLES, - .r9 = -1ULL, - }; u64 cc_mask; u32 eax, sig[3]; @@ -924,7 +932,7 @@ void __init tdx_early_init(void) cc_set_mask(cc_mask); /* Kernel does not use NOTIFY_ENABLES and does not need random #VEs */ - tdcall(TDG_VM_WR, &args); + tdg_vm_wr(TDCS_NOTIFY_ENABLES, 0, -1ULL); /* * All bits above GPA width are reserved and kernel treats shared bit -- 2.43.0