From patchwork Wed Jun 4 00:15:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Neri X-Patchwork-Id: 894022 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 8032D78F5E; Wed, 4 Jun 2025 00:18:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748996289; cv=none; b=TBYFuLNbLnUdkGNL/edLgfE4QRf4i41+T+vAy/3QLCuriKHub9FU4l3b87KsC8gRPCZs4GrrVCRtBr8frzk7/oMaLK3Tmm5TMGA9zE7W9dUu7bv8Hz+rdPe9CPz5T4dXqIupeIyOWXHoFb79GQK4Qxq2rQdQ4UJhXcPCT1VSCrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748996289; c=relaxed/simple; bh=ahMl9gGZluKayAijS2KHGKWb3QX1PeyP1wqA7nZwVBg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eHiEMGBqf3OHhQ7d2yg7mPqQpgTRj9CIP0u8rtgW5z4MKL33PFhKtOnN/GYNxAz8vYMBB6i9sexx5uUtSXl4ZJOYziynlxVQENVzrMIHZWGONtdkFlR2Acb6rBCPmG8+Raq86Zf0eJgTiVTBSXevh+kTqGhzaAZBlG4r+TSzGQc= 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=K99x7mJt; arc=none smtp.client-ip=198.175.65.13 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="K99x7mJt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1748996288; x=1780532288; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=ahMl9gGZluKayAijS2KHGKWb3QX1PeyP1wqA7nZwVBg=; b=K99x7mJt8/2wUpgWOUP6SQTQSa15em2y9fMXS12F9+NZXvqRNjJ8OgUm z+Ovx8WY0qD+kY0iTMuqlHPvcJ/O8meZHStjjZ0//LcmnN8StAnSkoZ39 FPJq1pV05dHkm+qbSplBHcbwYNnFrOpwwLNfiOZlmY2dp+OXyUlp/+eWh eA9EZqtNyiDt3m1g4nB8/xSetHL1FiAnGLmwiXANyGKF/TbQaBXZJ7MFS 13NGegkZCqvrxow6z03x+OrvvxLrlL3zPJoZybaDvnNCScU4YlslbOwOy gGC7zrL3biD0/U8cWH+PxSWSqgDUdR5tjDVZkyHTrE36+T3xwDfnoHtso g==; X-CSE-ConnectionGUID: w41gQkwnRm+XiZxxYSm8xQ== X-CSE-MsgGUID: ssOr0ge8T1+I3a5zrviMEA== X-IronPort-AV: E=McAfee;i="6700,10204,11453"; a="62112972" X-IronPort-AV: E=Sophos;i="6.16,207,1744095600"; d="scan'208";a="62112972" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2025 17:18:02 -0700 X-CSE-ConnectionGUID: o7KteomWTiqC13zvEWT8Wg== X-CSE-MsgGUID: mvkNHSwNQEeigQfJHs5PAw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,207,1744095600"; d="scan'208";a="149904483" Received: from unknown (HELO [172.25.112.21]) ([172.25.112.21]) by fmviesa005.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2025 17:18:01 -0700 From: Ricardo Neri Date: Tue, 03 Jun 2025 17:15:21 -0700 Subject: [PATCH v4 09/10] x86/hyperv/vtl: Mark the wakeup mailbox page as private Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250603-rneri-wakeup-mailbox-v4-9-d533272b7232@linux.intel.com> References: <20250603-rneri-wakeup-mailbox-v4-0-d533272b7232@linux.intel.com> In-Reply-To: <20250603-rneri-wakeup-mailbox-v4-0-d533272b7232@linux.intel.com> To: x86@kernel.org, Krzysztof Kozlowski , Conor Dooley , Rob Herring , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Michael Kelley , "Rafael J. Wysocki" Cc: Saurabh Sengar , Chris Oo , "Kirill A. Shutemov" , linux-hyperv@vger.kernel.org, devicetree@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, "Ravi V. Shankar" , Ricardo Neri , Yunhong Jiang , Ricardo Neri X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1748996287; l=2300; i=ricardo.neri-calderon@linux.intel.com; s=20250602; h=from:subject:message-id; bh=bKxLwQiFT1mEsXYGzQ6fKI1YFK6+0GKv4TRntu2AgMw=; b=1/Up4bCIx6mjNMhO3/oBdQNhSi1JTQh0eBL63IT62HJsLKEIAIhu05Pw+DbatnHJ9Z2zHctxn /Bu7utPgztACFr6NPwggXF+tRgD5FLgG6C4BhnOuuf8o2Z+maIsN9T0 X-Developer-Key: i=ricardo.neri-calderon@linux.intel.com; a=ed25519; pk=NfZw5SyQ2lxVfmNMaMR6KUj3+0OhcwDPyRzFDH9gY2w= From: Yunhong Jiang The current code maps MMIO devices as shared (decrypted) by default in a confidential computing VM. In a TDX environment, secondary CPUs are booted using the Multiprocessor Wakeup Structure defined in the ACPI specification. The virtual firmware and the operating system function in the guest context, without intervention from the VMM. Map the physical memory of the mailbox as private. Use the is_private_mmio() callback. Reviewed-by: Michael Kelley Signed-off-by: Yunhong Jiang Signed-off-by: Ricardo Neri --- Changes since v3: - Updated to use the renamed function acpi_get_mp_wakeup_mailbox_paddr(). - Added Reviewed-by tag from Michael. Thanks! Changes since v2: - Use the new helper function get_mp_wakeup_mailbox_paddr(). - Edited the commit message for clarity. Changes since v1: - Added the helper function within_page() to improve readability - Override the is_private_mmio() callback when detecting a TDX environment. The address of the mailbox is checked in hv_is_private_mmio_tdx(). --- arch/x86/hyperv/hv_vtl.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c index 8b497c8292d3..995d1de7a9be 100644 --- a/arch/x86/hyperv/hv_vtl.c +++ b/arch/x86/hyperv/hv_vtl.c @@ -54,6 +54,18 @@ static void __noreturn hv_vtl_restart(char __maybe_unused *cmd) hv_vtl_emergency_restart(); } +static inline bool within_page(u64 addr, u64 start) +{ + return addr >= start && addr < (start + PAGE_SIZE); +} + +static bool hv_vtl_is_private_mmio_tdx(u64 addr) +{ + u64 mb_addr = acpi_get_mp_wakeup_mailbox_paddr(); + + return mb_addr && within_page(addr, mb_addr); +} + void __init hv_vtl_init_platform(void) { pr_info("Linux runs in Hyper-V Virtual Trust Level\n"); @@ -61,6 +73,8 @@ void __init hv_vtl_init_platform(void) /* There is no paravisor present if we are here. */ if (hv_isolation_type_tdx()) { x86_init.resources.realmode_limit = SZ_4G; + x86_platform.hyper.is_private_mmio = hv_vtl_is_private_mmio_tdx; + } else { x86_platform.realmode_reserve = x86_init_noop; x86_platform.realmode_init = x86_init_noop;