Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3036716pxj; Mon, 31 May 2021 18:29:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrK4zqPnRnw3e49CsElz0R02bFCeYPVBwwKQTIJT0YUIMmMS55htzQi5YOxHJ+YKdh25dH X-Received: by 2002:a5d:8485:: with SMTP id t5mr19128438iom.89.1622510972895; Mon, 31 May 2021 18:29:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622510972; cv=none; d=google.com; s=arc-20160816; b=ty8ll8gkTUNeq99BQqZzhthQZskB6rtm2adLDex2rTOfAFE7Kgu5bliio0jo9Br0SJ aTGhw5yYzBFeIHRSXHBU+dz+dqmJCUje7WMx5/RImZgZxi2/uwQ8qqVL8ouUPImWBZYz sUlz/tZbgqVSO2zpV21xB4b+1IyAGyxBe2awbKxvk7y2b0Wargulu4/2lm4CBcXxgUpT 7cdZZJXr3mvwP1+0QtiAotAWbGZqXF7wKOEo+MKjxnNZohmaa+MylJezpsHOqv1Z0nAc Imo9+VnOWTyj7oukSRMFUH8yFZJqOmFeErAVzgqIB3WK2SMFMALxf2ZHhF491tc0omr2 83fA== 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=tkzbZPFuPvP4xBjfw8yEXyV4Jd4XfTOvFWqq2+nXYhA=; b=rApYc9KtU2ieC2Ky6zN/aSOAMb+U5tMtbfnmBBZWBJiqUkLPLAdIEtFqJT57UpeA7C ZX9KUojUZwppcb6XANaHHAca9gUVgeN+IehuczkGVX+OP882nRJ/zb6x3rneJYXHDHoI v0+hDcJXxHbRNrciPJmYl9hAjnr/QqUR+RqFMHGAvEeGmCgpnL5m6AGrazq7PeZZ3VBx B6WyBdyR2oKFSue5GZt+k8KMg3kFUHnOsmEQ/b46mM3wOX2AvC2iZid4+zEZSLS41/6c 2pU43oRPSpeFTymWDE9MWbcrsQa/4HqgDGu/FhnFxgA6hXtXiQx6/WER0mYK+NNCQ5yn 5l/g== 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 q3si17770173ilu.88.2021.05.31.18.29.19; Mon, 31 May 2021 18:29:32 -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 S232517AbhFAB35 (ORCPT + 99 others); Mon, 31 May 2021 21:29:57 -0400 Received: from mga04.intel.com ([192.55.52.120]:3203 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231714AbhFAB35 (ORCPT ); Mon, 31 May 2021 21:29:57 -0400 IronPort-SDR: v5u3useogAbn07TsB0wy6tmSRllfL+G1JqHlkr4/IIfDP/AgKkjhMqBIg1KBkj7p54/8dADw+d rmCCP6VQ+X7Q== X-IronPort-AV: E=McAfee;i="6200,9189,10001"; a="201581159" X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="201581159" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2021 18:28:16 -0700 IronPort-SDR: LdflEPn/pqMd1nuxECE8lFxsc4K+3L/1UEpfsLCaBHPxYmMv31o8M4L3UIabZ/T24I7C0K3/1z icAgTLaEa5Zg== X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="548894154" Received: from mjdelaro-mobl.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.3.23]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2021 18:28:15 -0700 From: Kuppuswamy Sathyanarayanan To: Peter Zijlstra , Andy Lutomirski , Dave Hansen , Tony Luck Cc: Andi Kleen , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Dan Williams , Raj Ashok , Sean Christopherson , Kuppuswamy Sathyanarayanan , linux-kernel@vger.kernel.org Subject: [RFC v2-fix-v3 1/1] x86/tdx: ioapic: Add shared bit for IOAPIC base address Date: Mon, 31 May 2021 18:28:05 -0700 Message-Id: <20210601012805.3559-1-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524232940.801877-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20210524232940.801877-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 Signed-off-by: Kuppuswamy Sathyanarayanan --- Changes since RFC v2-fix-v2: * Replaced is_tdx_guest() call with protected_guest_has() call. * Used pgprot_protected_guest() instead of prot_tdg_shared(). Changes since RFC v2: * Fixed commit log and comment as per review comment 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 73ff4dd426a8..9c0dff0d7aa4 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 (protected_guest_has(VM_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