From patchwork Thu Sep 26 09:46:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11162105 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 509EC13B1 for ; Thu, 26 Sep 2019 09:50:06 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C9F8222C0 for ; Thu, 26 Sep 2019 09:50:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="WcOdG9xQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C9F8222C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDQOh-0005pF-5d; Thu, 26 Sep 2019 09:49:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDQOf-0005lY-4d for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 09:49:13 +0000 X-Inumbo-ID: e14891cc-e042-11e9-bf31-bc764e2007e4 Received: from smtp-fw-6002.amazon.com (unknown [52.95.49.90]) by localhost (Halon) with ESMTPS id e14891cc-e042-11e9-bf31-bc764e2007e4; Thu, 26 Sep 2019 09:49:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1569491346; x=1601027346; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=s4mefAb4N0ny9YTycU16/nUjrF+aqb1Mt3BdhB6r1z8=; b=WcOdG9xQamKv8wIdB9Z1hRPoMnth/HFK8f1H8VAf4LMJ3gWkO/J19E9L 9dZAJu2Xs8xD91VGnOhnNBSfG8+73+2x2pyAUc4NkU5QpmpjXC9oiuTry L85Ruigkt+N5QZiX2az/aUhO5BI61J2D5VprPg341UQUKNa26wXADMWV9 g=; X-IronPort-AV: E=Sophos;i="5.64,551,1559520000"; d="scan'208";a="423750636" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 26 Sep 2019 09:49:06 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com (Postfix) with ESMTPS id 3A17FA2685; Thu, 26 Sep 2019 09:49:04 +0000 (UTC) Received: from EX13D19UWA003.ant.amazon.com (10.43.160.170) by EX13MTAUWA001.ant.amazon.com (10.43.160.58) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 26 Sep 2019 09:48:39 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13D19UWA003.ant.amazon.com (10.43.160.170) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 26 Sep 2019 09:48:38 +0000 Received: from u9d785c4ba99158.ant.amazon.com (10.125.106.58) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 26 Sep 2019 09:48:37 +0000 From: To: Date: Thu, 26 Sep 2019 10:46:20 +0100 Message-ID: <4401db4cb6eafd307444ecbc6340c6e39c446418.1569489002.git.hongyax@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [RFC PATCH 57/84] x86: add Persistent Map (PMAP) infrastructure X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_?= =?utf-8?q?Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Wei Liu The basic idea is like Persistent Kernel Map (PKMAP) in linux. We pre-populate all the relevant page tables before system is fully set up. It is needed to bootstrap map domain page infrastructure -- we need some way to map pages to set up per-cpu region without a direct map. In order to keep the number of entries minimal, this infrastructure can only be used by one CPU at a time. Signed-off-by: Wei Liu --- xen/arch/x86/Makefile | 1 + xen/arch/x86/pmap.c | 82 ++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/fixmap.h | 3 ++ xen/include/asm-x86/pmap.h | 12 ++++++ 4 files changed, 98 insertions(+) create mode 100644 xen/arch/x86/pmap.c create mode 100644 xen/include/asm-x86/pmap.h diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile index 2443fd2cc5..7508219686 100644 --- a/xen/arch/x86/Makefile +++ b/xen/arch/x86/Makefile @@ -55,6 +55,7 @@ obj-y += pci.o obj-y += percpu.o obj-y += physdev.o x86_64/physdev.o obj-y += platform_hypercall.o x86_64/platform_hypercall.o +obj-y += pmap.o obj-y += psr.o obj-y += setup.o obj-y += shutdown.o diff --git a/xen/arch/x86/pmap.c b/xen/arch/x86/pmap.c new file mode 100644 index 0000000000..4ae16b0212 --- /dev/null +++ b/xen/arch/x86/pmap.c @@ -0,0 +1,82 @@ +#include +#include +#include + +#include +#include + +/* + * Simple mapping infrastructure to map / unmap pages in fixed map. + * This is used to set up percpu page table for mapcache, which is + * used by map domain page infrastructure. + * + * There is a restriction that only one CPU can use this + * infrastructure at a time. So this infrastructure _should not_ be + * used anywhere else other than the stated purpose above. + */ + +static DEFINE_SPINLOCK(lock); +/* Bitmap to track which slot is used */ +static unsigned long inuse; + +void pmap_lock(void) +{ + spin_lock(&lock); +} + +void pmap_unlock(void) +{ + spin_unlock(&lock); +} + +void *pmap_map(struct page_info *page) +{ + unsigned int idx; + void *linear = NULL; + enum fixed_addresses slot; + + ASSERT(!in_irq()); + ASSERT(spin_is_locked(&lock)); + + idx = find_first_zero_bit(&inuse, NUM_FIX_PMAP); + if ( idx == NUM_FIX_PMAP ) + panic("Out of PMAP slots\n"); + + __set_bit(idx, &inuse); + + slot = idx + FIX_PMAP_BEGIN; + ASSERT(slot >= FIX_PMAP_BEGIN && slot <= FIX_PMAP_END); + + set_fixmap(slot, mfn_x(page_to_mfn(page))); + linear = (void *)__fix_to_virt(slot); + + return linear; +} + +void pmap_unmap(void *p) +{ + unsigned int idx; + enum fixed_addresses slot = __virt_to_fix((unsigned long)p); + + ASSERT(!in_irq()); + ASSERT(slot >= FIX_PMAP_BEGIN && slot <= FIX_PMAP_END); + ASSERT(spin_is_locked(&lock)); + + idx = slot - FIX_PMAP_BEGIN; + __clear_bit(idx, &inuse); + clear_fixmap(slot); +} + +static void __maybe_unused build_assertions(void) +{ + BUILD_BUG_ON(sizeof(inuse) * BITS_PER_LONG < NUM_FIX_PMAP); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-x86/fixmap.h b/xen/include/asm-x86/fixmap.h index 9fb2f47946..85885f8950 100644 --- a/xen/include/asm-x86/fixmap.h +++ b/xen/include/asm-x86/fixmap.h @@ -23,6 +23,7 @@ #include #include #include +#include #include /* @@ -48,6 +49,8 @@ enum fixed_addresses { FIX_XEN_SHARED_INFO, #endif /* CONFIG_XEN_GUEST */ /* Everything else should go further down. */ + FIX_PMAP_BEGIN, + FIX_PMAP_END = FIX_PMAP_BEGIN + NUM_FIX_PMAP - 1, FIX_APIC_BASE, FIX_IO_APIC_BASE_0, FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS-1, diff --git a/xen/include/asm-x86/pmap.h b/xen/include/asm-x86/pmap.h new file mode 100644 index 0000000000..42cd4c7793 --- /dev/null +++ b/xen/include/asm-x86/pmap.h @@ -0,0 +1,12 @@ +#ifndef __X86_PMAP_H__ +#define __X86_PMAP_H__ + +/* Large enough for mapping 5 levels of page tables */ +#define NUM_FIX_PMAP 5 + +void pmap_lock(void); +void pmap_unlock(void); +void *pmap_map(struct page_info *page); +void pmap_unmap(void *p); + +#endif /* __X86_PMAP_H__ */