Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp238531pxt; Wed, 4 Aug 2021 21:21:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjHRo3FyeGLeGDbF3Po9hpTKUtadrbDzHHWoMyTz+BNQfexnLJAuc4KyT7jMzwBXavJMl2 X-Received: by 2002:a92:cec5:: with SMTP id z5mr528282ilq.226.1628137299440; Wed, 04 Aug 2021 21:21:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628137299; cv=none; d=google.com; s=arc-20160816; b=kEKc8TVFOqGOO3ObVBn1yDFN8cGgFrnFj25jfdISGk/XL3KvteMWHYb8M4b6vxiYnR MPTE+O7L44/92xuhKvlscAiVI/KkVxbCCgjsOpKibq34Ns2iE7a8Twd8a1iHoFKn1+g4 3YF5yP0YZr1wNxTl3N6XRB1nQNERBedDTKOA0td8KSpt6EGhkncn8w6LscQsciR+eYuf 2gHblT4pM/pr5AU/nGWezyb8Q5XhU+Rjk4G/HaWHG6tZenf9F2mmzNJfJTPNewQNF71r VMKvS10gn1nOgT9pgk817M5yHXIyEW9UiAD1OFBHJGA6Xv9Eiyt0lo3yK6H0UORaDFqf lkng== 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; bh=Q51GYUjIJS7+pjiZnQ2WZs/I8qHD1AVNE7MU8qdhSQQ=; b=BIzC11yrzTs9HMmaTs88PGcW+blC7D8i5R5b6amTx3kgnXU8jwvjcY74Z+nCQIJy6J Bi71QT5PtPx/zRdyqswpmkbzBX0RLWRbaeQbsMkLmBqgwYxRuhcjG958/BpZn+y8IIYk uDtwo5lehRm89uHh/vFTNz/FQNofvs61p+CkUJSuqfuldNn4kWHiY3Il1azZ8bUC7G2F roi6CSXccIAnobiKfnA0K896+s7toLFc26zCD0S1VAhb8AikdHqMoaHrqfE1b7OgFt4M PknHJpAtJQ4MAZS/MeuJL6GN4EynLnGcipu4zAJugrQ8gcPbWGJRPqSWmrPcFgnLalFJ 0fmg== 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 m6si4448116iol.83.2021.08.04.21.21.26; Wed, 04 Aug 2021 21:21:39 -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 S236741AbhHEAx5 (ORCPT + 99 others); Wed, 4 Aug 2021 20:53:57 -0400 Received: from mga02.intel.com ([134.134.136.20]:12131 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236751AbhHEAxt (ORCPT ); Wed, 4 Aug 2021 20:53:49 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10066"; a="201215440" X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="201215440" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2021 17:53:36 -0700 X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="437617232" Received: from mjkendri-mobl.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.17.117]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2021 17:53:33 -0700 From: Kuppuswamy Sathyanarayanan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , Bjorn Helgaas , Richard Henderson , Thomas Bogendoerfer , James E J Bottomley , Helge Deller , "David S . Miller" , Arnd Bergmann , Jonathan Corbet , "Michael S . Tsirkin" 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, linux-pci@vger.kernel.org, linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v4 07/15] x86/tdx: ioapic: Add shared bit for IOAPIC base address Date: Wed, 4 Aug 2021 17:52:10 -0700 Message-Id: <20210805005218.2912076-8-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210805005218.2912076-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20210805005218.2912076-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 --- Changes since v3: * Rebased on top of Tom Lendacky's protected guest changes (https://lore.kernel.org/patchwork/cover/1468760/) 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 d5c691a3208b..5154efe8c4f7 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 @@ -65,6 +66,7 @@ #include #include #include +#include #define for_each_ioapic(idx) \ for ((idx) = 0; (idx) < nr_ioapics; (idx)++) @@ -2675,6 +2677,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(PATTR_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 +2721,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 +2850,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