From nobody Fri Jun 19 02:06:34 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0EA4C433F5 for ; Sat, 9 Apr 2022 01:27:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240276AbiDIB3g (ORCPT ); Fri, 8 Apr 2022 21:29:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240229AbiDIB32 (ORCPT ); Fri, 8 Apr 2022 21:29:28 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E88110242B; Fri, 8 Apr 2022 18:27:22 -0700 (PDT) Date: Sat, 09 Apr 2022 01:27:19 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1649467640; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hS4ThWOQAWnwSJVvu+j6r1vOFuoOlOSD6fagvzGDZVc=; b=XRrKYUzhsDjucfwgrpksrzLOymNLLByTrfkfi/V1klMbPjKrTfi7mR1fsO87LNE5UdIP5x X947FmLyibAVAvojl4Io8uUb5KlnQofQ4694rWZKbK8kWHKtFUwLlYqNz7qEInropJB3Yw QM4/ST10OLNuKIf8hqtTR4TB/PMIYNfbPV5l6KFeTldWopiQF0PvGZdnwVeExypOihEe19 XQ4smlcqtVyhfvSswhal5s0cD5Dv1tkgxbeLUgcvWPqqOL1XW6ltmUM2ghPoCGbSOhk/Xl hI6K77VEwKdLRcqf4IHfy7kv1mzQBdynp8PWj4tumo0PN0xgEAZgoupVHZ9XBg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1649467640; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hS4ThWOQAWnwSJVvu+j6r1vOFuoOlOSD6fagvzGDZVc=; b=38J0srL9TOHW2OheyU9GV28GzjDQMpigEvpsr0c1hcLf64Wwx2Ub3cFyz/V92nAdXQOfqR /v0vQwDpPypTEhBQ== From: "tip-bot2 for Isaku Yamahata" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/tdx] x86/tdx/ioapic: Add shared bit for IOAPIC base address Cc: Isaku Yamahata , Kuppuswamy Sathyanarayanan , "Kirill A. Shutemov" , Dave Hansen , Andi Kleen , Tony Luck , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220405232939.73860-29-kirill.shutemov@linux.intel.com> References: <20220405232939.73860-29-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Message-ID: <164946763982.4207.6455220351838692404.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/tdx branch of tip: Commit-ID: f4c9361f97c40d365c34f9cb8b8bc3eae0ee7778 Gitweb: https://git.kernel.org/tip/f4c9361f97c40d365c34f9cb8b8bc3eae= 0ee7778 Author: Isaku Yamahata AuthorDate: Wed, 06 Apr 2022 02:29:37 +03:00 Committer: Dave Hansen CommitterDate: Thu, 07 Apr 2022 08:27:53 -07:00 x86/tdx/ioapic: Add shared bit for IOAPIC base address The kernel interacts with each bare-metal IOAPIC with a special MMIO page. When running under KVM, the guest's IOAPICs are emulated by KVM. When running as a TDX guest, the guest needs to mark each IOAPIC mapping as "shared" with the host. This ensures that TDX private protections are not applied to the page, which allows the TDX host emulation to work. ioremap()-created mappings such as virtio will be marked as shared by default. However, the IOAPIC code does not use ioremap() and instead uses the fixmap mechanism. Introduce a special fixmap helper just for the IOAPIC code. Ensure that it marks IOAPIC pages as "shared". This replaces set_fixmap_nocache() with __set_fixmap() since __set_fixmap() allows custom 'prot' values. AMD SEV gets IOAPIC pages shared because FIXMAP_PAGE_NOCACHE has _ENC bit clear. TDX has to set bit to share the page with the host. Signed-off-by: Isaku Yamahata Signed-off-by: Kuppuswamy Sathyanarayanan Signed-off-by: Kirill A. Shutemov Signed-off-by: Dave Hansen Reviewed-by: Andi Kleen Reviewed-by: Tony Luck Reviewed-by: Dave Hansen Reviewed-by: Thomas Gleixner Link: https://lkml.kernel.org/r/20220405232939.73860-29-kirill.shutemov@lin= ux.intel.com --- arch/x86/kernel/apic/io_apic.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c index c1bb384..a868b76 100644 --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c @@ -65,6 +65,7 @@ #include #include #include +#include =20 #define for_each_ioapic(idx) \ for ((idx) =3D 0; (idx) < nr_ioapics; (idx)++) @@ -2677,6 +2678,19 @@ static struct resource * __init ioapic_setup_resourc= es(void) return res; } =20 +static void io_apic_set_fixmap(enum fixed_addresses idx, phys_addr_t phys) +{ + pgprot_t flags =3D FIXMAP_PAGE_NOCACHE; + + /* + * Ensure fixmaps for IOAPIC MMIO respect memory encryption pgprot + * bits, just like normal ioremap(): + */ + flags =3D pgprot_decrypted(flags); + + __set_fixmap(idx, phys, flags); +} + void __init io_apic_init_mappings(void) { unsigned long ioapic_phys, idx =3D FIX_IO_APIC_BASE_0; @@ -2709,7 +2723,7 @@ fake_ioapic_page: __func__, PAGE_SIZE, PAGE_SIZE); ioapic_phys =3D __pa(ioapic_phys); } - set_fixmap_nocache(idx, ioapic_phys); + io_apic_set_fixmap(idx, ioapic_phys); apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08lx (%08lx)\n", __fix_to_virt(idx) + (ioapic_phys & ~PAGE_MASK), ioapic_phys); @@ -2838,7 +2852,7 @@ int mp_register_ioapic(int id, u32 address, u32 gsi_b= ase, ioapics[idx].mp_config.flags =3D MPC_APIC_USABLE; ioapics[idx].mp_config.apicaddr =3D address; =20 - set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address); + io_apic_set_fixmap(FIX_IO_APIC_BASE_0 + idx, address); if (bad_ioapic_register(idx)) { clear_fixmap(FIX_IO_APIC_BASE_0 + idx); return -ENODEV;