Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3840538pxj; Mon, 24 May 2021 16:33:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbTuUkIHhIii0DAO+lmEoe5xT0LEZMVKlyxoNru95XiHnNFi9EqO7VMUv1fBTExzTAxz54 X-Received: by 2002:aa7:cad4:: with SMTP id l20mr28173850edt.382.1621899220497; Mon, 24 May 2021 16:33:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621899220; cv=none; d=google.com; s=arc-20160816; b=QgBcCIiZY2VHMCc7sGS/O2ppl4v9IhbntSTIJCPsKMb0bSaQRjCoHz1P1qDJYu2yLJ gghDw4MB/GDFqkK/l2/sgZ7qY358buVu/TKizl4k+dwDcXxS4M4g9OW8tfnt8w23SDc8 V6Bby8U1aMg7ZeOCLwkS2URSBI13o/9p0QofI+YbgcTkEDy7anCsh0i7GCg0wE8KA83H uANH/xqWslBGeWWbQDTHw8RnEEt09PTyGabTCLyJQyMQfNyuIg4S8fXZyUReZfbnpEps 6ZT1vROz99ZXylBsjngx09FYRdLny+yZQsmtyzblbaPXWoUQWveLWVnrNAOUWr5Hc1/B 6cGw== 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=yfqN1eSnkeU2dDWDrhOS+3KnJWHmo2xA6HzOKBKemX0=; b=AS1jMOdeDALKAuaHS+O4078f80gvOC8bx9ZeNqK1Xzspr+bKUOYLvOm99JsA1zmhjD k/TOHNc1wYyG12PYbRr+UqnQsWgSyaocaezNIxqqwWn8S7BWucQv4gCUN2hkQQYfbVn2 yzfhY2IFsxKWZU4QSbmzf++udOBE9LVTZwRJFXXC8mvnRRDQcwS587HtR5MH86m5zLx9 25i21ep0sGsADT45aj1SqljyZoNVk59NJ9B9/5GuvNlyD8TPA5JLwvtsyDQ0vWLV3ymm 3ACI1Vyeq8mQG0Qx7ts1lnC0v5dFQTf7LAGitbAVU5VOyZUzWqTf9nP5lvvT4ij6sR5O 60NA== 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 m5si13979406eds.484.2021.05.24.16.33.17; Mon, 24 May 2021 16:33: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 S229798AbhEXXbk (ORCPT + 99 others); Mon, 24 May 2021 19:31:40 -0400 Received: from mga06.intel.com ([134.134.136.31]:58415 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229805AbhEXXbj (ORCPT ); Mon, 24 May 2021 19:31:39 -0400 IronPort-SDR: 9wqGk1BihCDeA8Deblt5RIdO6s3wYZEN/nY0a7E2kQ6zPGTnc20HuYcI6lqpMHkS/Jk54blEWf 4zxgkenCrECg== X-IronPort-AV: E=McAfee;i="6200,9189,9994"; a="263261450" X-IronPort-AV: E=Sophos;i="5.82,327,1613462400"; d="scan'208";a="263261450" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 May 2021 16:30:07 -0700 IronPort-SDR: Kn0RxLpXpj4DNd+UWvaze1z10BcVXvyFfCtE4Tt7wkY9FJzQm6n/BhaGl49+B12YGukRLbxXFX s0ZBklWXyVLA== X-IronPort-AV: E=Sophos;i="5.82,327,1613462400"; d="scan'208";a="476126018" Received: from eyoukerh-mobl.ger.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.2.69]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 May 2021 16:30:06 -0700 From: Kuppuswamy Sathyanarayanan To: Peter Zijlstra , Andy Lutomirski , Dave Hansen Cc: Tony Luck , Andi Kleen , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Dan Williams , Raj Ashok , Sean Christopherson , Kuppuswamy Sathyanarayanan , linux-kernel@vger.kernel.org Subject: [RFC v2-fix-v2 1/1] x86/tdx: ioapic: Add shared bit for IOAPIC base address Date: Mon, 24 May 2021 16:29:40 -0700 Message-Id: <20210524232940.801877-1-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <79ada9f9-6b3e-73e3-c1a9-3d4e0b7ff42c@intel.com> References: <79ada9f9-6b3e-73e3-c1a9-3d4e0b7ff42c@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 Signed-off-by: Kuppuswamy Sathyanarayanan --- Changes since RFC v2: * Fixed commit log and comment as per review comments. arch/x86/kernel/apic/io_apic.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c index 73ff4dd426a8..810fc58e3c42 100644 --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c @@ -2675,6 +2675,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 (is_tdx_guest()) + flags = pgprot_tdg_shared(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 +2719,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 +2848,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