Received: by 10.223.176.46 with SMTP id f43csp272323wra; Tue, 23 Jan 2018 20:46:40 -0800 (PST) X-Google-Smtp-Source: AH8x227pAnQWtCnR2LCMMKM3OvmElrYMtI3E+12qhDcgEQePGrbqaQr/JZNxIJWq8VV/rLzRKinM X-Received: by 2002:a17:902:8c81:: with SMTP id t1-v6mr6872588plo.363.1516769200105; Tue, 23 Jan 2018 20:46:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516769200; cv=none; d=google.com; s=arc-20160816; b=oEe3qtRvMbfSWRDVcDJL/RbfhOoM+fjAppuXI92E2AaF+B1LX+wfVDIPO3d9GRMqtc vtJ2pXVtEH5BRMii+Nswgt4oBYkHlbr8J/3MLNRgCkKPuFnBXCHtRW/K3eRQNhp10lCL M96gau9Iir+dCqRsHD5W5Rytfu0HGDsAqbY1KAV1tVvtcGhl6UFgF3X4zC3l6L3ClFUP SMIF4gRvEV0XXZ1wuMXm9CwKy1TQpz+9+iohBnkd0diXMuvVose+0jWITosOr8MeB+SP DBXJf8DaDda89/5zIWR17U+EV+ieSWuGfDkrlORcUJogRqahMFBaa5Ob/0ltuRs6CqpR Us5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=rin6leA+i6y9orhTheFWYPSchJxv3t6yUOaBszrlGsE=; b=ciIJhdL5+FZ3X81Zyuw4TqPDtVdKEnmXAYktCQOWGBOhpAPTmy7+lMmBt21HmIHYIT 8l18D3M075tmRF5aMECKOdjn43Hb/8cpqlK1bVdEl2K++qMlchkoIarjDX43maKwyWTO 3PrKX9/sWbL0rO+rJSF2ROKk5zxXzj6LfFkb1MqnYIiae5I//v24rquuc0tKVH1hnG2c qLCE7kLw4rUFSDe0Oy9bU2uLBf0+3qnsjr9vUvqyXsOYS0/QvZMfpczd1bquQNLGRb+c kIBaqlc5ifXvRYcLq4aAjl9KSjnVDrOPgPjjOPRW+GU21LQw8gqjv49QfRURDQw2+k6w gxsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=UhDqTQ91; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l36-v6si3307497plg.7.2018.01.23.20.46.26; Tue, 23 Jan 2018 20:46:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=UhDqTQ91; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932762AbeAXEo6 (ORCPT + 99 others); Tue, 23 Jan 2018 23:44:58 -0500 Received: from mail-sn1nam01on0139.outbound.protection.outlook.com ([104.47.32.139]:26809 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932626AbeAXEQq (ORCPT ); Tue, 23 Jan 2018 23:16:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=rin6leA+i6y9orhTheFWYPSchJxv3t6yUOaBszrlGsE=; b=UhDqTQ91YbcKp9vGOjIbU7YCbFh0Bbw/FfHMJ2p6y9nJl4K9F9GwBzabjkgk798f4owJfPHsS3mtGTy6RQYhpf9YbcbLqH0xccMvJaeQbUn4AyHL71MPqSjVF3Z7wVBkKZ4qq/t2lb7/YmJewKgqdn6Nk21NGaTwwqUET0MwYEA= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0727.namprd21.prod.outlook.com (10.167.110.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.464.1; Wed, 24 Jan 2018 04:16:40 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7%2]) with mapi id 15.20.0464.000; Wed, 24 Jan 2018 04:16:40 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Juergen Gross , Thomas Gleixner , "xen-devel@lists.xenproject.org" , "boris.ostrovsky@oracle.com" , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 098/100] x86/xen: Support early interrupts in xen pv guests Thread-Topic: [PATCH AUTOSEL for 4.14 098/100] x86/xen: Support early interrupts in xen pv guests Thread-Index: AQHTlMnwTFaHU41nXkShIkgK/xWPCw== Date: Wed, 24 Jan 2018 04:15:17 +0000 Message-ID: <20180124041414.32065-98-alexander.levin@microsoft.com> References: <20180124041414.32065-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041414.32065-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0727;7:GUT+WBK5p18EP/31lD3f3uyxFlS2M5ns7cMEbTzHVIjp4qABy1Mpv6WMP+LLVfTBBkI5MdChLGRGd35zA6/XsBFd7Ap80zCK3Ku83m4pfS0I9qnnz2Dc7yt6cAsOA+uxuSSSY9EEsewKHQNOwfnpQRGEpcF+CpBIWyy4rfWZVt3oMc0Ii+lonATA5sVXvvDDuvXkUpxOJHJVcCTOfA6bdDEza0HZu/Luyml+2nZgamapldJQmzsDuy1Vxgdnfu+/ x-ms-office365-filtering-correlation-id: e349ab20-ea12-46ed-590f-08d562e144fc x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7193020);SRVR:DM5PR2101MB0727; x-ms-traffictypediagnostic: DM5PR2101MB0727: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(42068640409301)(146099531331640); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(3231046)(2400081)(944501161)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041288)(20161123560045)(20161123558120)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB0727;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0727; x-forefront-prvs: 056297E276 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(396003)(366004)(39380400002)(39860400002)(376002)(189003)(199004)(86612001)(6506007)(106356001)(76176011)(59450400001)(6346003)(54906003)(575784001)(86362001)(2501003)(110136005)(966005)(1076002)(7736002)(5250100002)(3660700001)(316002)(26005)(102836004)(2950100002)(6666003)(99286004)(97736004)(22452003)(107886003)(6436002)(53936002)(478600001)(66066001)(14454004)(6306002)(2900100001)(6512007)(2906002)(5660300001)(8936002)(4326008)(10290500003)(305945005)(10090500001)(68736007)(25786009)(81166006)(72206003)(36756003)(8676002)(81156014)(3846002)(6116002)(3280700002)(105586002)(6486002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0727;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: l3aHR/JY/FHC5uUefziwjhWqEYDEKeNrQQmfGMgg3rPmX9DkMjDLczo+/XuTs+ZLSXVLtMvOMHOX7CXtkqpyYw== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: e349ab20-ea12-46ed-590f-08d562e144fc X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2018 04:15:17.0561 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0727 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Juergen Gross [ Upstream commit 42b3a4cb5609de757f5445fcad18945ba9239a07 ] Add early interrupt handlers activated by idt_setup_early_handler() to the handlers supported by Xen pv guests. This will allow for early WARN() calls not crashing the guest. Suggested-by: Andy Lutomirski Signed-off-by: Juergen Gross Signed-off-by: Thomas Gleixner Cc: xen-devel@lists.xenproject.org Cc: boris.ostrovsky@oracle.com Link: https://lkml.kernel.org/r/20171124084221.30172-1-jgross@suse.com Signed-off-by: Sasha Levin --- arch/x86/include/asm/segment.h | 12 ++++++++++++ arch/x86/mm/extable.c | 4 +++- arch/x86/xen/enlighten_pv.c | 37 ++++++++++++++++++++++++------------- arch/x86/xen/xen-asm_64.S | 14 ++++++++++++++ 4 files changed, 53 insertions(+), 14 deletions(-) diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.= h index b20f9d623f9c..8f09012b92e7 100644 --- a/arch/x86/include/asm/segment.h +++ b/arch/x86/include/asm/segment.h @@ -236,11 +236,23 @@ */ #define EARLY_IDT_HANDLER_SIZE 9 =20 +/* + * xen_early_idt_handler_array is for Xen pv guests: for each entry in + * early_idt_handler_array it contains a prequel in the form of + * pop %rcx; pop %r11; jmp early_idt_handler_array[i]; summing up to + * max 8 bytes. + */ +#define XEN_EARLY_IDT_HANDLER_SIZE 8 + #ifndef __ASSEMBLY__ =20 extern const char early_idt_handler_array[NUM_EXCEPTION_VECTORS][EARLY_IDT= _HANDLER_SIZE]; extern void early_ignore_irq(void); =20 +#if defined(CONFIG_X86_64) && defined(CONFIG_XEN_PV) +extern const char xen_early_idt_handler_array[NUM_EXCEPTION_VECTORS][XEN_E= ARLY_IDT_HANDLER_SIZE]; +#endif + /* * Load a segment. Fall back on loading the zero segment if something goes * wrong. This variant assumes that loading zero fully clears the segment= . diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c index 30bc4812ceb8..9fe656c42aa5 100644 --- a/arch/x86/mm/extable.c +++ b/arch/x86/mm/extable.c @@ -1,6 +1,7 @@ #include #include #include +#include =20 #include #include @@ -212,8 +213,9 @@ void __init early_fixup_exception(struct pt_regs *regs,= int trapnr) * Old CPUs leave the high bits of CS on the stack * undefined. I'm not sure which CPUs do this, but at least * the 486 DX works this way. + * Xen pv domains are not using the default __KERNEL_CS. */ - if (regs->cs !=3D __KERNEL_CS) + if (!xen_pv_domain() && regs->cs !=3D __KERNEL_CS) goto fail; =20 /* diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index ae3a071e1d0f..899a22a02e95 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -622,7 +622,7 @@ static struct trap_array_entry trap_array[] =3D { { simd_coprocessor_error, xen_simd_coprocessor_error, false }, }; =20 -static bool get_trap_addr(void **addr, unsigned int ist) +static bool __ref get_trap_addr(void **addr, unsigned int ist) { unsigned int nr; bool ist_okay =3D false; @@ -644,6 +644,14 @@ static bool get_trap_addr(void **addr, unsigned int is= t) } } =20 + if (nr =3D=3D ARRAY_SIZE(trap_array) && + *addr >=3D (void *)early_idt_handler_array[0] && + *addr < (void *)early_idt_handler_array[NUM_EXCEPTION_VECTORS]) { + nr =3D (*addr - (void *)early_idt_handler_array[0]) / + EARLY_IDT_HANDLER_SIZE; + *addr =3D (void *)xen_early_idt_handler_array[nr]; + } + if (WARN_ON(ist !=3D 0 && !ist_okay)) return false; =20 @@ -1261,6 +1269,21 @@ asmlinkage __visible void __init xen_start_kernel(vo= id) xen_setup_gdt(0); =20 xen_init_irq_ops(); + + /* Let's presume PV guests always boot on vCPU with id 0. */ + per_cpu(xen_vcpu_id, 0) =3D 0; + + /* + * Setup xen_vcpu early because idt_setup_early_handler needs it for + * local_irq_disable(), irqs_disabled(). + * + * Don't do the full vcpu_info placement stuff until we have + * the cpu_possible_mask and a non-dummy shared_info. + */ + xen_vcpu_info_reset(0); + + idt_setup_early_handler(); + xen_init_capabilities(); =20 #ifdef CONFIG_X86_LOCAL_APIC @@ -1294,18 +1317,6 @@ asmlinkage __visible void __init xen_start_kernel(vo= id) */ acpi_numa =3D -1; #endif - /* Let's presume PV guests always boot on vCPU with id 0. */ - per_cpu(xen_vcpu_id, 0) =3D 0; - - /* - * Setup xen_vcpu early because start_kernel needs it for - * local_irq_disable(), irqs_disabled(). - * - * Don't do the full vcpu_info placement stuff until we have - * the cpu_possible_mask and a non-dummy shared_info. - */ - xen_vcpu_info_reset(0); - WARN_ON(xen_cpuhp_setup(xen_cpu_up_prepare_pv, xen_cpu_dead_pv)); =20 local_irq_disable(); diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S index 8a10c9a9e2b5..417b339e5c8e 100644 --- a/arch/x86/xen/xen-asm_64.S +++ b/arch/x86/xen/xen-asm_64.S @@ -15,6 +15,7 @@ =20 #include =20 +#include #include =20 .macro xen_pv_trap name @@ -54,6 +55,19 @@ xen_pv_trap entry_INT80_compat #endif xen_pv_trap hypervisor_callback =20 + __INIT +ENTRY(xen_early_idt_handler_array) + i =3D 0 + .rept NUM_EXCEPTION_VECTORS + pop %rcx + pop %r11 + jmp early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE + i =3D i + 1 + .fill xen_early_idt_handler_array + i*XEN_EARLY_IDT_HANDLER_SIZE - ., 1, = 0xcc + .endr +END(xen_early_idt_handler_array) + __FINIT + hypercall_iret =3D hypercall_page + __HYPERVISOR_iret * 32 /* * Xen64 iret frame: --=20 2.11.0