From nobody Mon Feb 9 04:44:35 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1579724680; cv=none; d=zohomail.com; s=zohoarc; b=H0QAEud/i0XihztlR4Q3qzNYIw1072X/nq1HHwLc1bUKjlmPy5io26XAfMTiZS0vRWrZcQKoGnNET/KkTt0WTNiGmizPN1N9paiEMlqddULdAfhTM4orHrtft1JjamL77oASHBSjGLFmbe/waZzTAo9oRnNpLANndAHr2ifu3GY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579724680; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mEnd2B5X9gKOLqWCcH+UOUtTJKaKonUYwskT/HaMneE=; b=ERyVRckew6cUAQJMnUXRVVBGiHerrKpCSekWLzbLIzuPVPfASBfOzl8fyqNOvfYJLpvlWndZ5lKBQijLBIryA0gxVLtxez/XIal0fgs5xoA68ainuWkqhxQRXsI42ULlT0XJM1BHnhipuKkWlott4LazVJwha7LCr/lCq34owNM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 15797246807861002.4428877426086; Wed, 22 Jan 2020 12:24:40 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXa-0006EX-2Y; Wed, 22 Jan 2020 20:23:54 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXZ-0006ES-0A for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 20:23:53 +0000 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 187ed5e2-3d55-11ea-aecd-bc764e2007e4; Wed, 22 Jan 2020 20:23:48 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id q10so469430wrm.11 for ; Wed, 22 Jan 2020 12:23:48 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id r6sm60267992wrq.92.2020.01.22.12.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 12:23:46 -0800 (PST) X-Inumbo-ID: 187ed5e2-3d55-11ea-aecd-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e3XL4uu/8zRUT3kMySEH+EKr0ciyiwuAqAEdw4QD6CY=; b=KsxSjogJ5n6kFS4/uLZMahdXLGE5/YcqDmekfNe8r/OW8+vxOKEIFSUpg2uamcIkEB UV0SU1M1b+NigKiGN7aHAYxrOlYohWJitqorzQNpkABLDQ3MClva1u2XnDvN9ehvDwh8 7O+ozmWr/vdQT4otGp/FwHB7pruUMlOZkAdkhb3oZ+/PW+qiROAST1VbsX375v5ue/Gq 7AWuiCP6cAbCR7amNzMEKGmRJ7/Ch+Ocsm0DoEHifnSCLDwBR2Oh9vqVMUDG+T/LEMEs OadiVx3QO4fy9dTvCg7w2DBzqVAb47dsYxohzHCXfnzvqtq+YRwwg1ucrC3+BVWqPU8e JYPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=e3XL4uu/8zRUT3kMySEH+EKr0ciyiwuAqAEdw4QD6CY=; b=ArGJqJ4+glI9XoOg5OAUpIbJoHfG1r3Vf6f/BJ6Ht82Azi9sjq75HQ40NBcflHdv43 qFGjmoDUlK4Q7PB+bK1RvVakEnDutXS8LvkkkeeTP6aSHUuZ5D1y/CubYwNEdzsuc+s4 HVDfRcQByZFS4htqSAOZHYvei98VfeInMRcxW81GbJWcIm9vCoy4zR0TnIavt/6pUm+3 oUrViGkoXI9cvqrw5RaitWXNba27Xz8q/59jfXUYMe4hHxMYUsEI4Q1hnTvv+9iEsS9Q hC3ISfkuNchgTrHE06AxrDq+KJIzI8QNo84IrQ30T9gZrTCmKH9Fh+VNdQ+xsHOSIrcF Rzww== X-Gm-Message-State: APjAAAXvuQU4XaHFDQguWpNZVkGtCTZHqF50BA5mMRgzAyS0BPyPJkdo oDAYVoSmIzRLGTcGyHZoX04eoRp0Dj4nYQ== X-Google-Smtp-Source: APXvYqzctyQ+QsaZCC5gfEhH2QFbzam5/HHNBlp2+lxvCJljHLJoN66rCroMvX4NlYrnAOCf+jJoYQ== X-Received: by 2002:adf:f1d0:: with SMTP id z16mr12716601wro.209.1579724627415; Wed, 22 Jan 2020 12:23:47 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 22 Jan 2020 20:23:37 +0000 Message-Id: <20200122202343.5703-2-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200122202343.5703-1-liuwe@microsoft.com> References: <20200122202343.5703-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 1/7] x86: provide executable fixmap facility X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Konrad Rzeszutek Wilk , Michael Kelley , Ross Lagerwall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This allows us to set aside some address space for executable mapping. This fixed map range starts from XEN_VIRT_END so that it is within reach of the .text section. Shift the percpu stub range and livepatch range accordingly. Signed-off-by: Wei Liu --- xen/arch/x86/boot/x86_64.S | 10 +++++++++- xen/arch/x86/livepatch.c | 3 ++- xen/arch/x86/mm.c | 9 +++++++++ xen/arch/x86/smpboot.c | 2 +- xen/arch/x86/xen.lds.S | 3 +++ xen/include/asm-x86/config.h | 2 +- xen/include/asm-x86/fixmap.h | 28 ++++++++++++++++++++++++++++ 7 files changed, 53 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/boot/x86_64.S b/xen/arch/x86/boot/x86_64.S index 1cbf5acdfb..605d01f1dd 100644 --- a/xen/arch/x86/boot/x86_64.S +++ b/xen/arch/x86/boot/x86_64.S @@ -85,7 +85,15 @@ GLOBAL(l2_directmap) * 4k page. */ GLOBAL(l2_xenmap) - .fill L2_PAGETABLE_ENTRIES, 8, 0 + idx =3D 0 + .rept L2_PAGETABLE_ENTRIES + .if idx =3D=3D l2_table_offset(FIXADDR_X_TOP - 1) + .quad sym_offs(l1_fixmap_x) + __PAGE_HYPERVISOR + .else + .quad 0 + .endif + idx =3D idx + 1 + .endr .size l2_xenmap, . - l2_xenmap =20 /* L2 mapping the fixmap. Uses 1x 4k page. */ diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c index 2749cbc5cf..513b0f3841 100644 --- a/xen/arch/x86/livepatch.c +++ b/xen/arch/x86/livepatch.c @@ -12,6 +12,7 @@ #include #include =20 +#include #include #include =20 @@ -311,7 +312,7 @@ void __init arch_livepatch_init(void) void *start, *end; =20 start =3D (void *)xen_virt_end; - end =3D (void *)(XEN_VIRT_END - NR_CPUS * PAGE_SIZE); + end =3D (void *)(XEN_VIRT_END - FIXADDR_X_SIZE - NR_CPUS * PAGE_SIZE); =20 BUG_ON(end <=3D start); =20 diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 654190e9e9..aabe1a4c64 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -157,6 +157,8 @@ /* Mapping of the fixmap space needed early. */ l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) l1_fixmap[L1_PAGETABLE_ENTRIES]; +l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) + l1_fixmap_x[L1_PAGETABLE_ENTRIES]; =20 paddr_t __read_mostly mem_hotplug; =20 @@ -5763,6 +5765,13 @@ void __set_fixmap( map_pages_to_xen(__fix_to_virt(idx), _mfn(mfn), 1, flags); } =20 +void __set_fixmap_x( + enum fixed_addresses_x idx, unsigned long mfn, unsigned long flags) +{ + BUG_ON(idx >=3D __end_of_fixed_addresses_x); + map_pages_to_xen(__fix_x_to_virt(idx), _mfn(mfn), 1, flags); +} + void *__init arch_vmap_virt_end(void) { return fix_to_virt(__end_of_fixed_addresses); diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index c9d1ab4423..2da42fb691 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -640,7 +640,7 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigne= d long *mfn) unmap_domain_page(memset(__map_domain_page(pg), 0xcc, PAGE_SIZE)); } =20 - stub_va =3D XEN_VIRT_END - (cpu + 1) * PAGE_SIZE; + stub_va =3D XEN_VIRT_END - FIXADDR_X_SIZE - (cpu + 1) * PAGE_SIZE; if ( map_pages_to_xen(stub_va, page_to_mfn(pg), 1, PAGE_HYPERVISOR_RX | MAP_SMALL_PAGES) ) { diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index 07c6448dbb..cbc5701214 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -3,6 +3,8 @@ =20 #include #include + +#include #include #undef ENTRY #undef ALIGN @@ -353,6 +355,7 @@ SECTIONS } =20 ASSERT(__2M_rwdata_end <=3D XEN_VIRT_END - XEN_VIRT_START + __XEN_VIRT_STA= RT - + MAX_FIXADDR_X_SIZE - DIV_ROUND_UP(NR_CPUS, STUBS_PER_PAGE) * PAGE_SIZ= E, "Xen image overlaps stubs area") =20 diff --git a/xen/include/asm-x86/config.h b/xen/include/asm-x86/config.h index d0cfbb70a8..4fa56ea0a9 100644 --- a/xen/include/asm-x86/config.h +++ b/xen/include/asm-x86/config.h @@ -218,7 +218,7 @@ extern unsigned char boot_edid_info[128]; /* Slot 261: high read-only compat machine-to-phys conversion table (1GB).= */ #define HIRO_COMPAT_MPT_VIRT_START RDWR_COMPAT_MPT_VIRT_END #define HIRO_COMPAT_MPT_VIRT_END (HIRO_COMPAT_MPT_VIRT_START + GB(1)) -/* Slot 261: xen text, static data and bss (1GB). */ +/* Slot 261: xen text, static data, bss and executable fixmap (1GB). */ #define XEN_VIRT_START (HIRO_COMPAT_MPT_VIRT_END) #define XEN_VIRT_END (XEN_VIRT_START + GB(1)) =20 diff --git a/xen/include/asm-x86/fixmap.h b/xen/include/asm-x86/fixmap.h index 9fb2f47946..c2a9d2b50a 100644 --- a/xen/include/asm-x86/fixmap.h +++ b/xen/include/asm-x86/fixmap.h @@ -15,6 +15,9 @@ #include =20 #define FIXADDR_TOP (VMAP_VIRT_END - PAGE_SIZE) +#define FIXADDR_X_TOP (XEN_VIRT_END - PAGE_SIZE) +/* This constant is derived from enum fixed_addresses_x below */ +#define MAX_FIXADDR_X_SIZE (2 << PAGE_SHIFT) =20 #ifndef __ASSEMBLY__ =20 @@ -89,6 +92,31 @@ static inline unsigned long virt_to_fix(const unsigned l= ong vaddr) return __virt_to_fix(vaddr); } =20 +enum fixed_addresses_x { + /* Index 0 is reserved since fix_x_to_virt(0) =3D=3D FIXADDR_X_TOP. */ + FIX_X_RESERVED, +#ifdef CONFIG_HYPERV_GUEST + FIX_X_HYPERV_HCALL, +#endif + __end_of_fixed_addresses_x +}; + +#define FIXADDR_X_SIZE (__end_of_fixed_addresses_x << PAGE_SHIFT) +#define FIXADDR_X_START (FIXADDR_X_TOP - FIXADDR_X_SIZE) + +extern void __set_fixmap_x( + enum fixed_addresses_x idx, unsigned long mfn, unsigned long flags); + +#define set_fixmap_x(idx, phys) \ + __set_fixmap_x(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR_RX | MAP_SMALL= _PAGES) + +#define clear_fixmap_x(idx) __set_fixmap_x(idx, 0, 0) + +#define __fix_x_to_virt(x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT)) +#define __virt_to_fix_x(x) ((FIXADDR_X_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIF= T) + +#define fix_x_to_virt(x) ((void *)__fix_x_to_virt(x)) + #endif /* __ASSEMBLY__ */ =20 #endif --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel