Received: by 2002:a05:6520:2586:b029:fa:41f3:c225 with SMTP id u6csp30562lky; Wed, 9 Jun 2021 14:59:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVG/Ud4MazuYzocs+9MmCOSHvVsPUAwyyU4VVC/78Qb31YjU3Q55JQrObi2mpStdJSVHQd X-Received: by 2002:a05:6402:348f:: with SMTP id v15mr1405093edc.135.1623275980070; Wed, 09 Jun 2021 14:59:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623275980; cv=none; d=google.com; s=arc-20160816; b=xKqN9R7a1JMl8xrrUgzR9LdoJbrA4/AocSzhhejcCoh1WJP/Lxa01C9jrz6UNhOyvn o/pDqpzfBhA0GDApsns2bAfVD9jjaudeVgZ6Lcr6AOCS5Rd2UNKCeeThAdKy1dyx7y2o EjhMZ501x23CEBWXjW4wyHdsZjLpCiOxvI5q9u4knCQkJLt7YDth9MZkb8Kw3UOb2wJc o4qRIW7sfFBC/OM8nyTrc89SgTJYy/NhvYLoDWSIj/aKhvuJuXzymg7ev+yV1jHsW6Rp YVTpI+BAog4a2u/sNE6imefr2m5JG51zuNJo0ov+OjmeT2tBuVRBDasSFKf0qCe8s6Y+ 1ONQ== 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 :ironport-sdr:ironport-sdr; bh=UZutIoEKME9rFRL95/G1MgvrGGbHneELuoCR9cEWQcQ=; b=TnUQJI6qYUfrIiQBASuycPD51IEbGZF+mMCTAQPXITrvm8hg4qAXTwQVomhELe68rM OcZJjcMUNeUJH/qa7SRd20gZCPcG7OpwrCpd7d7uVZBK9afJosG26DsINIG5KAbV/4zI j1VPDLwtSXeUcpn8188KhxggyE0ZgyKGk+XWm17b9DSpZxFoAr9nZswCeXcjUUFpOuQs qoYeR2jSX8D2e6tueDl54H1AQGgu7GMeBew3JyN2Lp3tu9hbvCZCaRA+njE4ltjiKwaq oP4NbU8QZ+X4xzCT99zlVx7xe3VjSuMMxSpJDon/K9MupycXbUXgOICzp4XhwzewaPOF aWZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b18si612413edd.11.2021.06.09.14.59.16; Wed, 09 Jun 2021 14:59:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229874AbhFIV56 (ORCPT + 99 others); Wed, 9 Jun 2021 17:57:58 -0400 Received: from mga03.intel.com ([134.134.136.65]:1785 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230117AbhFIV5w (ORCPT ); Wed, 9 Jun 2021 17:57:52 -0400 IronPort-SDR: I6vUEEguE45+dtganhvWiaZKoowq9hiegE5oO8aio3YRgrFx7/BtBG/9fXT9V6bT7FL+VWWaFm sPL+62akjwcQ== X-IronPort-AV: E=McAfee;i="6200,9189,10010"; a="205208556" X-IronPort-AV: E=Sophos;i="5.83,261,1616482800"; d="scan'208";a="205208556" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2021 14:55:57 -0700 IronPort-SDR: ViFDCffI0mrQ+APe5GDGyNL44qnQ8RLZzPA4Re/cAeDC0Ak66hbdkGvxN6cvVLApnR+DJCZkvK iKtL4bWNip3w== X-IronPort-AV: E=Sophos;i="5.83,261,1616482800"; d="scan'208";a="482555119" Received: from qwang4-mobl1.ccr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.35.228]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2021 14:55:56 -0700 From: Kuppuswamy Sathyanarayanan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Andy Lutomirski Cc: Peter H Anvin , Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Sean Christopherson , Kuppuswamy Sathyanarayanan , x86@kernel.org, linux-kernel@vger.kernel.org, Isaku Yamahata Subject: [PATCH v1 7/7] x86/tdx: ioapic: Add shared bit for IOAPIC base address Date: Wed, 9 Jun 2021 14:55:37 -0700 Message-Id: <20210609215537.1956150-8-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210609215537.1956150-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20210609215537.1956150-1-sathyanarayanan.kuppuswamy@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Isaku Yamahata 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. Earlier patches in this series modified ioremap() so that ioremap()-created mappings such as virtio will be marked as shared. 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. Signed-off-by: Isaku Yamahata Reviewed-by: Andi Kleen Reviewed-by: Tony Luck Signed-off-by: Kuppuswamy Sathyanarayanan --- arch/x86/kernel/apic/io_apic.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c index d5c691a3208b..95639072c986 100644 --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -2675,6 +2676,18 @@ static struct resource * __init ioapic_setup_resources(void) return res; } +static void io_apic_set_fixmap_nocache(enum fixed_addresses idx, + phys_addr_t phys) +{ + pgprot_t flags = FIXMAP_PAGE_NOCACHE; + + /* Set TDX guest shared bit in pgprot flags */ + if (prot_guest_has(PR_GUEST_SHARED_MAPPING_INIT)) + flags = pgprot_protected_guest(flags); + + __set_fixmap(idx, phys, flags); +} + void __init io_apic_init_mappings(void) { unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0; @@ -2707,7 +2720,7 @@ void __init io_apic_init_mappings(void) __func__, PAGE_SIZE, PAGE_SIZE); ioapic_phys = __pa(ioapic_phys); } - set_fixmap_nocache(idx, ioapic_phys); + io_apic_set_fixmap_nocache(idx, ioapic_phys); apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08lx (%08lx)\n", __fix_to_virt(idx) + (ioapic_phys & ~PAGE_MASK), ioapic_phys); @@ -2836,7 +2849,7 @@ int mp_register_ioapic(int id, u32 address, u32 gsi_base, ioapics[idx].mp_config.flags = MPC_APIC_USABLE; ioapics[idx].mp_config.apicaddr = address; - set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address); + io_apic_set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address); if (bad_ioapic_register(idx)) { clear_fixmap(FIX_IO_APIC_BASE_0 + idx); return -ENODEV; -- 2.25.1