From patchwork Tue Aug 6 20:30:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 11079605 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60FD8746 for ; Tue, 6 Aug 2019 20:31:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D6B5288C5 for ; Tue, 6 Aug 2019 20:31:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 413E02898B; Tue, 6 Aug 2019 20:31:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4EC01288EA for ; Tue, 6 Aug 2019 20:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aZ2MuWE6sZM1WIqVdhYJmXFHh74kPxc8CB0OE0jB0R8=; b=neIvnU6aTZyh+r 9ZmR9NaQPWMF2x2eQDtQHBxE5+Aa4mVF+5azqlAAmquNd0q5+7CJAH/8O89ECsnLGm+eYXyyU8+pI 8uylmAPXj5QYTDsGY1dgbnMkmzuECO6JLiMHBadCV/hUjaK5GtkW6Rw9xJVgNUuntd+y8IP/85/uA zzX9+ALzgCqnZJxbk/DaGxElad/D1vvi6miQMUFnaBR+vVGRn5l5yZIKKfqtjQ39RZzzUrBfDdRqX 3OiNpc/I4BNeAbZd8EvLMW0b9RH3T2d0AP4Cagol/1Yn3RZPjb64+RFwQn/lLcrSNaZWCUaFGk7Jc 5w7vIP2K3039sjfGFGYQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hv66x-0005hh-Nl; Tue, 06 Aug 2019 20:31:11 +0000 Received: from mail-eopbgr690092.outbound.protection.outlook.com ([40.107.69.92] helo=NAM04-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hv66j-0005WH-1k for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2019 20:30:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=POndwhj59HAlFylWKvaDUyckSqjQTSQr5Pdvp1I7Mv+Q8ONhbfiS2to0OWys7LCE9ToQRAGD0PJ1ImlGrOXZOLlWQtWwomyHmHxBInm9l87mwKsekuM2aC73nRUyut80zIW9ILIpW+fiJTRPAY7tIH0MbfrdfvYlewwMG1l0A/SDTq16lAOYhMEBIY1a45eH8QIk25l/5BDyLySOVTRI/GWI8TeG/T1oEpL11zN97tlGkaKUz+g1sunI8hblafNz3Q8YSM9RB/iLIPFyOARpt+ALiirL9oM8FqxeRWBJ/YLhARvan5/R+EEGRLWH76AVfvw2xgHCe5BIMNPhhDuqdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=okNn/r1zGf7JSzyO9cz5htFo9euxczWyzmqy3oQv29Q=; b=GZVd0CnjwsPpwdOaj0hTVOxxhtrLfsg3WGmyh6Rzy1mEFNzWNWX/Ugn/FOvMfNWRACiJA/ZFrFRgRXutP5EiFd6Ts0zzCoaz8fnPMsdaV18ZFHjtKk1sUHxIvVnP5boIcpGM1iOm8G2VmHDxDd6PUidPx09MgaBzTC2YINYDpL5UXChUJNbfLYoII/oV1Dv7ACW14xHHqpeqZHKOOnwOvYCvZnTTf+yK+wIwPfU+FL1EnHeQNOwXKJ5/nCyWJZA5eZc5smyzOJAHqR4vWl7iXzwtZPSkaniU1mK+joiJEXCSMo9EzWyy+ZQWWPIjHqSLZYRY1i8ElcSfrVQP/9wFvg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none 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:X-MS-Exchange-SenderADCheck; bh=okNn/r1zGf7JSzyO9cz5htFo9euxczWyzmqy3oQv29Q=; b=QiOfGx+4y1GTj0V9hQo7MposaWN5EPw4+0BwgO0FfVEVpUlxrk6FPdwR6RQji+xo3z3iVDrrspTljdSo6Sc8fYJikb/Dw8g7QEn+vxye4aBdUQnwfWQS42jyXuj0+q0bYjbPaXpc+3kdEBPMz5qN0f4EIxxB0TSBje0NVrg530M= Received: from BYAPR21MB1335.namprd21.prod.outlook.com (20.179.60.209) by BYAPR21MB1206.namprd21.prod.outlook.com (20.179.57.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2157.13; Tue, 6 Aug 2019 20:30:54 +0000 Received: from BYAPR21MB1335.namprd21.prod.outlook.com ([fe80::819:aea0:eda4:9301]) by BYAPR21MB1335.namprd21.prod.outlook.com ([fe80::819:aea0:eda4:9301%9]) with mapi id 15.20.2157.001; Tue, 6 Aug 2019 20:30:54 +0000 From: Michael Kelley To: "will.deacon@arm.com" , "catalin.marinas@arm.com" , "mark.rutland@arm.com" , "marc.zyngier@arm.com" , "linux-arm-kernel@lists.infradead.org" , "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , "linux-hyperv@vger.kernel.org" , "devel@linuxdriverproject.org" , "olaf@aepfle.de" , "apw@canonical.com" , vkuznets , "jasowang@redhat.com" , "marcelo.cerri@canonical.com" , KY Srinivasan Subject: [PATCH v4 1/8] arm64: hyperv: Add core Hyper-V include files Thread-Topic: [PATCH v4 1/8] arm64: hyperv: Add core Hyper-V include files Thread-Index: AQHVTJXYMOS6C9L2tEO2MJcPqZGzmg== Date: Tue, 6 Aug 2019 20:30:54 +0000 Message-ID: <1565122133-9086-2-git-send-email-mikelley@microsoft.com> References: <1565122133-9086-1-git-send-email-mikelley@microsoft.com> In-Reply-To: <1565122133-9086-1-git-send-email-mikelley@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR01CA0030.prod.exchangelabs.com (2603:10b6:300:101::16) To BYAPR21MB1335.namprd21.prod.outlook.com (2603:10b6:a03:115::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=mikelley@microsoft.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.8.3.1 x-originating-ip: [131.107.174.8] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 5ab8c4f0-a7f2-4b71-5875-08d71aacfaf5 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:BYAPR21MB1206; x-ms-traffictypediagnostic: BYAPR21MB1206:|BYAPR21MB1206: x-ms-exchange-transport-forked: True x-ms-exchange-purlcount: 1 x-ld-processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7691; x-forefront-prvs: 0121F24F22 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(376002)(39860400002)(396003)(366004)(346002)(189003)(199004)(110136005)(14444005)(14454004)(476003)(102836004)(68736007)(966005)(446003)(99286004)(6436002)(81156014)(8676002)(10290500003)(478600001)(66066001)(2616005)(11346002)(6306002)(316002)(6486002)(76176011)(186003)(81166006)(486006)(54906003)(386003)(1511001)(36756003)(2501003)(10090500001)(2201001)(305945005)(7736002)(26005)(25786009)(6506007)(50226002)(4326008)(256004)(66476007)(6512007)(71200400001)(71190400001)(5660300002)(30864003)(4720700003)(6116002)(6636002)(52116002)(3846002)(66556008)(22452003)(64756008)(66946007)(66446008)(7416002)(86362001)(53936002)(8936002)(53946003)(2906002)(921003)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:BYAPR21MB1206; H:BYAPR21MB1335.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 4WBk+22/hB3ptpQy1SVm9xl0KMFA1pWkPbfkba7tasG2IrVwku0UBp5P4Nv5u1KLAJ135Q70CLyJJ18IxoSrf1ktU2Q2xihfBZAp5CScCJEb+RA7JxINeDb3lmaqDcAFNIKPj7fHEGOsa3vpREMW3sMu0ymGpBXmZJ7WvdUiAsk2IoHWcxhl/LgA/0d1SmMYyb4iarjdFN756h+XfdEUyUJzPn14eZIzimbrr2AGIjcgGjwsBT6583DbbsC5KaKlgFB06qnbxi+8InUCoSeb5ExcSDSstZyxtsgtNKl5aJopcKaykjil58A6QIgyVPrgo2TyHrbozdhsdD/45z5lxnNeZs1/n7heHk1EBvocHN6zbRHJzKKEYwb72TeMzRJHy4b5DCqbNpe3sOXiX+vgajIUUm7kJ6rifkn4mVol5T8= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5ab8c4f0-a7f2-4b71-5875-08d71aacfaf5 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2019 20:30:54.4588 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 7Q/dTWqqnnosd072COu0GYLLeCC3OnuoeuC4vnNtkNKNBQGoD4tl/Vp43lnyUmouTMCSUT4D6Qxmv3kb7dvj5A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR21MB1206 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190806_133057_157672_A10DE43E X-CRM114-Status: GOOD ( 18.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sunil Muthuswamy , "boqun.feng" , Michael Kelley Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP hyperv-tlfs.h defines Hyper-V interfaces from the Hyper-V Top Level Functional Spec (TLFS). The TLFS is distinctly oriented to x86/x64, and Hyper-V has not separated out the architecture-dependent parts into x86/x64 vs. ARM64. So hyperv-tlfs.h includes information for ARM64 that is not yet formally published. The TLFS is available here: docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/tlfs mshyperv.h defines Linux-specific structures and routines for interacting with Hyper-V on ARM64, and #includes the architecture- independent part of mshyperv.h in include/asm-generic. Signed-off-by: Michael Kelley --- MAINTAINERS | 2 + arch/arm64/include/asm/hyperv-tlfs.h | 408 +++++++++++++++++++++++++++++++++++ arch/arm64/include/asm/mshyperv.h | 105 +++++++++ 3 files changed, 515 insertions(+) create mode 100644 arch/arm64/include/asm/hyperv-tlfs.h create mode 100644 arch/arm64/include/asm/mshyperv.h diff --git a/MAINTAINERS b/MAINTAINERS index cf2225b..fa98b21 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7486,6 +7486,8 @@ F: arch/x86/include/asm/trace/hyperv.h F: arch/x86/include/asm/hyperv-tlfs.h F: arch/x86/kernel/cpu/mshyperv.c F: arch/x86/hyperv +F: arch/arm64/include/asm/hyperv-tlfs.h +F: arch/arm64/include/asm/mshyperv.h F: drivers/clocksource/hyperv_timer.c F: drivers/hid/hid-hyperv.c F: drivers/hv/ diff --git a/arch/arm64/include/asm/hyperv-tlfs.h b/arch/arm64/include/asm/hyperv-tlfs.h new file mode 100644 index 0000000..fe167c4 --- /dev/null +++ b/arch/arm64/include/asm/hyperv-tlfs.h @@ -0,0 +1,408 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * This file contains definitions from the Hyper-V Hypervisor Top-Level + * Functional Specification (TLFS): + * https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/tlfs + * + * Copyright (C) 2019, Microsoft, Inc. + * + * Author : Michael Kelley + */ + +#ifndef _ASM_HYPERV_TLFS_H +#define _ASM_HYPERV_TLFS_H + +#include + +/* + * All data structures defined in the TLFS that are shared between Hyper-V + * and a guest VM use Little Endian byte ordering. This matches the default + * byte ordering of Linux running on ARM64, so no special handling is required. + */ + + +/* + * While not explicitly listed in the TLFS, Hyper-V always runs with a page + * size of 4096. These definitions are used when communicating with Hyper-V + * using guest physical pages and guest physical page addresses, since the + * guest page size may not be 4096 on ARM64. + */ +#define HV_HYP_PAGE_SHIFT 12 +#define HV_HYP_PAGE_SIZE (1 << HV_HYP_PAGE_SHIFT) +#define HV_HYP_PAGE_MASK (~(HV_HYP_PAGE_SIZE - 1)) + +/* + * These Hyper-V registers provide information equivalent to the CPUID + * instruction on x86/x64. + */ +#define HV_REGISTER_HYPERVISOR_VERSION 0x00000100 /*CPUID 0x40000002 */ +#define HV_REGISTER_PRIVILEGES_AND_FEATURES 0x00000200 /*CPUID 0x40000003 */ +#define HV_REGISTER_FEATURES 0x00000201 /*CPUID 0x40000004 */ +#define HV_REGISTER_IMPLEMENTATION_LIMITS 0x00000202 /*CPUID 0x40000005 */ +#define HV_ARM64_REGISTER_INTERFACE_VERSION 0x00090006 /*CPUID 0x40000001 */ + +/* + * Feature identification. HvRegisterPrivilegesAndFeaturesInfo returns a + * 128-bit value with flags indicating which features are available to the + * partition based upon the current partition privileges. The 128-bit + * value is broken up with different portions stored in different 32-bit + * fields in the ms_hyperv structure. + */ + +/* Partition Reference Counter available*/ +#define HV_MSR_TIME_REF_COUNT_AVAILABLE BIT(1) + +/* + * Synthetic Timers available + */ +#define HV_MSR_SYNTIMER_AVAILABLE BIT(3) + +/* Frequency MSRs available */ +#define HV_FEATURE_FREQUENCY_MSRS_AVAILABLE BIT(8) + +/* Reference TSC available */ +#define HV_MSR_REFERENCE_TSC_AVAILABLE BIT(9) + +/* Crash MSR available */ +#define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE BIT(10) + + +/* + * This group of flags is in the high order 64-bits of the returned + * 128-bit value. + */ + +/* STIMER direct mode is available */ +#define HV_STIMER_DIRECT_MODE_AVAILABLE BIT(19) + +/* + * Implementation recommendations in register + * HvRegisterFeaturesInfo. Indicates which behaviors the hypervisor + * recommends the OS implement for optimal performance. + */ + +/* + * Recommend not using Auto EOI + */ +#define HV_DEPRECATING_AEOI_RECOMMENDED BIT(9) + +/* + * Synthetic register definitions equivalent to MSRs on x86/x64 + */ +#define HV_REGISTER_CRASH_P0 0x00000210 +#define HV_REGISTER_CRASH_P1 0x00000211 +#define HV_REGISTER_CRASH_P2 0x00000212 +#define HV_REGISTER_CRASH_P3 0x00000213 +#define HV_REGISTER_CRASH_P4 0x00000214 +#define HV_REGISTER_CRASH_CTL 0x00000215 + +#define HV_REGISTER_GUEST_OSID 0x00090002 +#define HV_REGISTER_VPINDEX 0x00090003 +#define HV_REGISTER_TIME_REFCOUNT 0x00090004 +#define HV_REGISTER_REFERENCE_TSC 0x00090017 + +#define HV_REGISTER_SINT0 0x000A0000 +#define HV_REGISTER_SINT1 0x000A0001 +#define HV_REGISTER_SINT2 0x000A0002 +#define HV_REGISTER_SINT3 0x000A0003 +#define HV_REGISTER_SINT4 0x000A0004 +#define HV_REGISTER_SINT5 0x000A0005 +#define HV_REGISTER_SINT6 0x000A0006 +#define HV_REGISTER_SINT7 0x000A0007 +#define HV_REGISTER_SINT8 0x000A0008 +#define HV_REGISTER_SINT9 0x000A0009 +#define HV_REGISTER_SINT10 0x000A000A +#define HV_REGISTER_SINT11 0x000A000B +#define HV_REGISTER_SINT12 0x000A000C +#define HV_REGISTER_SINT13 0x000A000D +#define HV_REGISTER_SINT14 0x000A000E +#define HV_REGISTER_SINT15 0x000A000F +#define HV_REGISTER_SCONTROL 0x000A0010 +#define HV_REGISTER_SVERSION 0x000A0011 +#define HV_REGISTER_SIFP 0x000A0012 +#define HV_REGISTER_SIPP 0x000A0013 +#define HV_REGISTER_EOM 0x000A0014 +#define HV_REGISTER_SIRBP 0x000A0015 + +#define HV_REGISTER_STIMER0_CONFIG 0x000B0000 +#define HV_REGISTER_STIMER0_COUNT 0x000B0001 +#define HV_REGISTER_STIMER1_CONFIG 0x000B0002 +#define HV_REGISTER_STIMER1_COUNT 0x000B0003 +#define HV_REGISTER_STIMER2_CONFIG 0x000B0004 +#define HV_REGISTER_STIMER2_COUNT 0x000B0005 +#define HV_REGISTER_STIMER3_CONFIG 0x000B0006 +#define HV_REGISTER_STIMER3_COUNT 0x000B0007 + +/* + * Crash notification flags. + */ +#define HV_CRASH_CTL_CRASH_NOTIFY_MSG BIT_ULL(62) +#define HV_CRASH_CTL_CRASH_NOTIFY BIT_ULL(63) + +/* + * The guest OS needs to register the guest ID with the hypervisor. + * The guest ID is a 64 bit entity and the structure of this ID is + * specified in the Hyper-V TLFS. + */ +#define HV_LINUX_VENDOR_ID 0x8100 + +/* Declare the various hypercall operations. */ +#define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE 0x0002 +#define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST 0x0003 +#define HVCALL_NOTIFY_LONG_SPIN_WAIT 0x0008 +#define HVCALL_SEND_IPI 0x000b +#define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX 0x0013 +#define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX 0x0014 +#define HVCALL_SEND_IPI_EX 0x0015 +#define HVCALL_GET_VP_REGISTERS 0x0050 +#define HVCALL_SET_VP_REGISTERS 0x0051 +#define HVCALL_POST_MESSAGE 0x005c +#define HVCALL_SIGNAL_EVENT 0x005d +#define HVCALL_RETARGET_INTERRUPT 0x007e +#define HVCALL_START_VIRTUAL_PROCESSOR 0x0099 + +/* Declare standard hypercall field values. */ +#define HV_PARTITION_ID_SELF ((u64)-1) +#define HV_VP_INDEX_SELF ((u32)-2) + +#define HV_HYPERCALL_FAST_BIT BIT(16) +#define HV_HYPERCALL_REP_COUNT_1 BIT_ULL(32) +#define HV_HYPERCALL_RESULT_MASK GENMASK_ULL(15, 0) + +/* Define the hypercall status result */ + +union hv_hypercall_status { + u64 as_uint64; + struct { + u16 status; + u16 reserved; + u16 reps_completed; /* Low 12 bits */ + u16 reserved2; + }; +}; + +/* hypercall status code */ +#define HV_STATUS_SUCCESS 0 +#define HV_STATUS_INVALID_HYPERCALL_CODE 2 +#define HV_STATUS_INVALID_HYPERCALL_INPUT 3 +#define HV_STATUS_INVALID_ALIGNMENT 4 +#define HV_STATUS_INSUFFICIENT_MEMORY 11 +#define HV_STATUS_INVALID_CONNECTION_ID 18 +#define HV_STATUS_INSUFFICIENT_BUFFERS 19 + +/* Define output layout for Get VP Register hypercall */ +struct hv_get_vp_register_output { + u64 registervaluelow; + u64 registervaluehigh; +}; + +#define HV_FLUSH_ALL_PROCESSORS BIT(0) +#define HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES BIT(1) +#define HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY BIT(2) +#define HV_FLUSH_USE_EXTENDED_RANGE_FORMAT BIT(3) + +enum HV_GENERIC_SET_FORMAT { + HV_GENERIC_SET_SPARSE_4K, + HV_GENERIC_SET_ALL, +}; + +/* + * The Hyper-V TimeRefCount register and the TSC + * page provide a guest VM clock with 100ns tick rate + */ +#define HV_CLOCK_HZ (NSEC_PER_SEC/100) + +/* + * The fields in this structure are set by Hyper-V and read + * by the Linux guest. They should be accessed with READ_ONCE() + * so the compiler doesn't optimize in a way that will cause + * problems. The union pads the size out to the page size + * used in communication with Hyper-V. + */ +struct ms_hyperv_tsc_page { + union { + struct { + u32 tsc_sequence; + u32 reserved1; + u64 tsc_scale; + s64 tsc_offset; + } __packed; + u8 reserved2[HV_HYP_PAGE_SIZE]; + }; +}; + +/* Define the number of synthetic interrupt sources. */ +#define HV_SYNIC_SINT_COUNT (16) +/* Define the expected SynIC version. */ +#define HV_SYNIC_VERSION_1 (0x1) + +#define HV_SYNIC_CONTROL_ENABLE (1ULL << 0) +#define HV_SYNIC_SIMP_ENABLE (1ULL << 0) +#define HV_SYNIC_SIEFP_ENABLE (1ULL << 0) +#define HV_SYNIC_SINT_MASKED (1ULL << 16) +#define HV_SYNIC_SINT_AUTO_EOI (1ULL << 17) +#define HV_SYNIC_SINT_VECTOR_MASK (0xFF) + +#define HV_SYNIC_STIMER_COUNT (4) + +/* Define synthetic interrupt controller message constants. */ +#define HV_MESSAGE_SIZE (256) +#define HV_MESSAGE_PAYLOAD_BYTE_COUNT (240) +#define HV_MESSAGE_PAYLOAD_QWORD_COUNT (30) + +/* Define hypervisor message types. */ +enum hv_message_type { + HVMSG_NONE = 0x00000000, + + /* Memory access messages. */ + HVMSG_UNMAPPED_GPA = 0x80000000, + HVMSG_GPA_INTERCEPT = 0x80000001, + + /* Timer notification messages. */ + HVMSG_TIMER_EXPIRED = 0x80000010, + + /* Error messages. */ + HVMSG_INVALID_VP_REGISTER_VALUE = 0x80000020, + HVMSG_UNRECOVERABLE_EXCEPTION = 0x80000021, + HVMSG_UNSUPPORTED_FEATURE = 0x80000022, + + /* Trace buffer complete messages. */ + HVMSG_EVENTLOG_BUFFERCOMPLETE = 0x80000040, +}; + +/* Define synthetic interrupt controller message flags. */ +union hv_message_flags { + __u8 asu8; + struct { + __u8 msg_pending:1; + __u8 reserved:7; + } __packed; +}; + +/* Define port identifier type. */ +union hv_port_id { + __u32 asu32; + struct { + __u32 id:24; + __u32 reserved:8; + } __packed u; +}; + +/* Define synthetic interrupt controller message header. */ +struct hv_message_header { + __u32 message_type; + __u8 payload_size; + union hv_message_flags message_flags; + __u8 reserved[2]; + union { + __u64 sender; + union hv_port_id port; + }; +} __packed; + +/* Define synthetic interrupt controller message format. */ +struct hv_message { + struct hv_message_header header; + union { + __u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT]; + } u; +} __packed; + +/* Define the synthetic interrupt message page layout. */ +struct hv_message_page { + struct hv_message sint_message[HV_SYNIC_SINT_COUNT]; +} __packed; + +/* Define timer message payload structure. */ +struct hv_timer_message_payload { + __u32 timer_index; + __u32 reserved; + __u64 expiration_time; /* When the timer expired */ + __u64 delivery_time; /* When the message was delivered */ +} __packed; + +#define HV_STIMER_ENABLE (1ULL << 0) +#define HV_STIMER_PERIODIC (1ULL << 1) +#define HV_STIMER_LAZY (1ULL << 2) +#define HV_STIMER_AUTOENABLE (1ULL << 3) +#define HV_STIMER_SINT(config) (__u8)(((config) >> 16) & 0x0F) + + +/* Define synthetic interrupt controller flag constants. */ +#define HV_EVENT_FLAGS_COUNT (256 * 8) +#define HV_EVENT_FLAGS_LONG_COUNT (256 / sizeof(unsigned long)) + +/* + * Timer configuration register. + */ +union hv_stimer_config { + u64 as_uint64; + struct { + u64 enable:1; + u64 periodic:1; + u64 lazy:1; + u64 auto_enable:1; + u64 apic_vector:8; + u64 direct_mode:1; + u64 reserved_z0:3; + u64 sintx:4; + u64 reserved_z1:44; + } __packed; +}; + + +/* Define the synthetic interrupt controller event flags format. */ +union hv_synic_event_flags { + unsigned long flags[HV_EVENT_FLAGS_LONG_COUNT]; +}; + +/* Define SynIC control register. */ +union hv_synic_scontrol { + u64 as_uint64; + struct { + u64 enable:1; + u64 reserved:63; + } __packed; +}; + +/* Define synthetic interrupt source. */ +union hv_synic_sint { + u64 as_uint64; + struct { + u64 vector:8; + u64 reserved1:8; + u64 masked:1; + u64 auto_eoi:1; + u64 reserved2:46; + } __packed; +}; + +/* Define the format of the SIMP register */ +union hv_synic_simp { + u64 as_uint64; + struct { + u64 simp_enabled:1; + u64 preserved:11; + u64 base_simp_gpa:52; + } __packed; +}; + +/* Define the format of the SIEFP register */ +union hv_synic_siefp { + u64 as_uint64; + struct { + u64 siefp_enabled:1; + u64 preserved:11; + u64 base_siefp_gpa:52; + } __packed; +}; + +struct hv_vpset { + u64 format; + u64 valid_bank_mask; + u64 bank_contents[]; +} __packed; + + +#endif diff --git a/arch/arm64/include/asm/mshyperv.h b/arch/arm64/include/asm/mshyperv.h new file mode 100644 index 0000000..a8468a6 --- /dev/null +++ b/arch/arm64/include/asm/mshyperv.h @@ -0,0 +1,105 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Linux-specific definitions for managing interactions with Microsoft's + * Hyper-V hypervisor. The definitions in this file are specific to + * the ARM64 architecture. See include/asm-generic/mshyperv.h for + * definitions are that architecture independent. + * + * Definitions that are specified in the Hyper-V Top Level Functional + * Spec (TLFS) should not go in this file, but should instead go in + * hyperv-tlfs.h. + * + * Copyright (C) 2019, Microsoft, Inc. + * + * Author : Michael Kelley + */ + +#ifndef _ASM_MSHYPERV_H +#define _ASM_MSHYPERV_H + +#include +#include +#include +#include +#include +#include + +/* + * Define the IRQ numbers/vectors used by Hyper-V VMbus interrupts + * and by STIMER0 Direct Mode interrupts. Hyper-V should be supplying + * these values through ACPI, but there are no other interrupting + * devices in a Hyper-V VM on ARM64, so it's OK to hard code for now. + * The "CALLBACK_VECTOR" terminology is a left-over from the x86/x64 + * world that is used in architecture independent Hyper-V code. + */ +#define HYPERVISOR_CALLBACK_VECTOR 16 +#define HV_STIMER0_IRQNR 17 + +extern u64 hv_do_hvc(u64 control, ...); +extern u64 hv_do_hvc_fast_get(u64 control, u64 input1, u64 input2, u64 input3, + struct hv_get_vp_register_output *output); + +/* + * Declare calls to get and set Hyper-V VP register values on ARM64, which + * requires a hypercall. + */ +extern void hv_set_vpreg(u32 reg, u64 value); +extern u64 hv_get_vpreg(u32 reg); +extern void hv_get_vpreg_128(u32 reg, struct hv_get_vp_register_output *result); + +/* + * Use the Hyper-V provided stimer0 as the timer that is made + * available to the architecture independent Hyper-V drivers. + */ +#define hv_init_timer(timer, tick) \ + hv_set_vpreg(HV_REGISTER_STIMER0_COUNT + (2*timer), tick) +#define hv_init_timer_config(timer, val) \ + hv_set_vpreg(HV_REGISTER_STIMER0_CONFIG + (2*timer), val) +#define hv_get_current_tick(tick) \ + (tick = hv_get_vpreg(HV_REGISTER_TIME_REFCOUNT)) + +#define hv_get_simp(val) (val = hv_get_vpreg(HV_REGISTER_SIPP)) +#define hv_set_simp(val) hv_set_vpreg(HV_REGISTER_SIPP, val) + +#define hv_get_siefp(val) (val = hv_get_vpreg(HV_REGISTER_SIFP)) +#define hv_set_siefp(val) hv_set_vpreg(HV_REGISTER_SIFP, val) + +#define hv_get_synic_state(val) (val = hv_get_vpreg(HV_REGISTER_SCONTROL)) +#define hv_set_synic_state(val) hv_set_vpreg(HV_REGISTER_SCONTROL, val) + +#define hv_get_vp_index(index) (index = hv_get_vpreg(HV_REGISTER_VPINDEX)) + +#define hv_signal_eom() hv_set_vpreg(HV_REGISTER_EOM, 0) + +/* + * Hyper-V SINT registers are numbered sequentially, so we can just + * add the SINT number to the register number of SINT0 + */ +#define hv_get_synint_state(sint_num, val) \ + (val = hv_get_vpreg(HV_REGISTER_SINT0 + sint_num)) +#define hv_set_synint_state(sint_num, val) \ + hv_set_vpreg(HV_REGISTER_SINT0 + sint_num, val) + +#define hv_get_crash_ctl(val) \ + (val = hv_get_vpreg(HV_REGISTER_CRASH_CTL)) +#define hv_get_time_ref_count(val) \ + (val = hv_get_vpreg(HV_REGISTER_TIME_REFCOUNT)) +#define hv_get_reference_tsc(val) \ + (val = hv_get_vpreg(HV_REGISTER_REFERENCE_TSC)) +#define hv_set_reference_tsc(val) \ + hv_set_vpreg(HV_REGISTER_REFERENCE_TSC, val) +#define hv_set_clocksource_vdso(val) \ + ((val).archdata.vdso_direct = false) + +#if IS_ENABLED(CONFIG_HYPERV) +#define hv_enable_stimer0_percpu_irq(irq) enable_percpu_irq(irq, 0) +#define hv_disable_stimer0_percpu_irq(irq) disable_percpu_irq(irq) +#endif + +/* ARM64 specific code to read the hardware clock */ +#define hv_get_raw_timer() arch_timer_read_counter() + +#include + +#endif From patchwork Tue Aug 6 20:30:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 11079607 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4BF26112C for ; Tue, 6 Aug 2019 20:31:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A248288D9 for ; Tue, 6 Aug 2019 20:31:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D708288EE; Tue, 6 Aug 2019 20:31:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7DA4B288D9 for ; Tue, 6 Aug 2019 20:31:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BUDDmY8oXM8e6j1qTL84+vah2tTV6nOKB2haWIDOgm4=; b=lB+9jFNXJmRKvG ENkKL4vb/5FvQIW2HjmVOJ21J5ayGS4Nmayczh+gsPe4DtIql1oMSc8UhM7CbYgcVR9VuU/LMU41C rdYIDIcAvNJTxqaB8TlvjEb2hzpxib4X1ksS4Ji19C6VRVLftH3Z7Fj70hpqCuFvh6HgHUFU5GVrZ biShbCFfVkKWcpUBG+HwSY398EoQM5Rk0AxPqnjVTYI0WIROiy2yPXt6H6srEYqmvRngdqwi944Q2 5N0WpQfe9nS7wd1J8RUZ11xge0m/vAZ/rSPbXMu7Z/UuxVEcyP8pKDMKd2yIwKuUlTKBGODXJgcZB +yIRcY/SbpLA0mSGQBCg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hv67N-00068y-QX; Tue, 06 Aug 2019 20:31:37 +0000 Received: from mail-eopbgr690092.outbound.protection.outlook.com ([40.107.69.92] helo=NAM04-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hv66l-0005WH-Tj for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2019 20:31:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RhP8NZk6huaupzfsz7rY7JIRui1qP049ESANvtVmtHHUWN+cHoIONZbKrQrjum124d6Y1EZNNdC2kPWErF5ph1US3wJv820fQiRne8e+qjJ2F2aS+ENTNlunRGQoN5c1/ZSRPqh0uWdfasqJuvzVqKz2AvTD5ObU8B+HiTA0JhnSlPO8URDnjkrtinTjhx90/zpQiF1EzjKkEKb2q/UN6mFXL2Ccgdn0twJ8Rx+hs6dX6G7zVrocE/jztcZEhu4bSbUneMm3zPOhl5fvx2NDIrw4EfX48t6OWp0ndoyRss6gmbwlI+QuSQHETRbmfbxRgSIR1uwpg/zoq/5dUOaC4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YDsPry1dqclrqfZpj9q42HyZAinvrXaxVtX84yy0bC4=; b=JUfp94v+qrHScnh9EEEkeYCnT4SQC4lFhDoZuaK/I3g9CWN6PAUkoMdmsTvwd49/m0ZNAJfH0frIalQDJDIAcEm0Q7lr4cGtG/jL60mjNvcr+4rQbwoZh0aZvAZtNvRyJGxKjWs7ZIfPseyq4XXDmpsiOVyG8NHaqDY/WMyO6CORSlAgPfBOEg+yKZMDoynhZyKaZRrtZRafK/8ITDxTq5CeDgy6V6BDTmjBxax8kkV+GuwG6QMKxwKh8OlWjOSXnYJELw2FQotk3rfiNXkB/huraeHeliXfxa3lLZglwjkBJBtaVoL+NJq2rxbOw5d6/cvXQzhiuXEbDD1j7C/21w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none 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:X-MS-Exchange-SenderADCheck; bh=YDsPry1dqclrqfZpj9q42HyZAinvrXaxVtX84yy0bC4=; b=XXzZT8vMMQ/qdtDPP/P6I5wJdmU6h5mASuMbm7EgRvKZH147ZO69zN3b9Qcrw7I9xLwqdYq4dg9rU8xmvTV+d+tYk0I5aeWoWMcpDe7FVV3/li5c/rnST7g5ALhkUI/EPVnkAb6aHrvgCRjVOXEmYtzYGZEejAigUtPtcfuF9Bg= Received: from BYAPR21MB1335.namprd21.prod.outlook.com (20.179.60.209) by BYAPR21MB1206.namprd21.prod.outlook.com (20.179.57.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2157.13; Tue, 6 Aug 2019 20:30:57 +0000 Received: from BYAPR21MB1335.namprd21.prod.outlook.com ([fe80::819:aea0:eda4:9301]) by BYAPR21MB1335.namprd21.prod.outlook.com ([fe80::819:aea0:eda4:9301%9]) with mapi id 15.20.2157.001; Tue, 6 Aug 2019 20:30:57 +0000 From: Michael Kelley To: "will.deacon@arm.com" , "catalin.marinas@arm.com" , "mark.rutland@arm.com" , "marc.zyngier@arm.com" , "linux-arm-kernel@lists.infradead.org" , "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , "linux-hyperv@vger.kernel.org" , "devel@linuxdriverproject.org" , "olaf@aepfle.de" , "apw@canonical.com" , vkuznets , "jasowang@redhat.com" , "marcelo.cerri@canonical.com" , KY Srinivasan Subject: [PATCH v4 2/8] arm64: hyperv: Add hypercall and register access functions Thread-Topic: [PATCH v4 2/8] arm64: hyperv: Add hypercall and register access functions Thread-Index: AQHVTJXaTWO/EaovdkmugTcFFLBxjA== Date: Tue, 6 Aug 2019 20:30:57 +0000 Message-ID: <1565122133-9086-3-git-send-email-mikelley@microsoft.com> References: <1565122133-9086-1-git-send-email-mikelley@microsoft.com> In-Reply-To: <1565122133-9086-1-git-send-email-mikelley@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR01CA0030.prod.exchangelabs.com (2603:10b6:300:101::16) To BYAPR21MB1335.namprd21.prod.outlook.com (2603:10b6:a03:115::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=mikelley@microsoft.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.8.3.1 x-originating-ip: [131.107.174.8] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 953e605d-8103-46a8-8248-08d71aacfcd9 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:BYAPR21MB1206; x-ms-traffictypediagnostic: BYAPR21MB1206:|BYAPR21MB1206: x-ms-exchange-transport-forked: True x-ld-processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2733; x-forefront-prvs: 0121F24F22 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(376002)(39860400002)(396003)(366004)(346002)(189003)(199004)(110136005)(14444005)(14454004)(476003)(102836004)(68736007)(446003)(99286004)(6436002)(81156014)(8676002)(10290500003)(478600001)(66066001)(2616005)(11346002)(316002)(6486002)(76176011)(186003)(81166006)(486006)(54906003)(386003)(1511001)(36756003)(2501003)(10090500001)(2201001)(305945005)(7736002)(26005)(25786009)(6506007)(50226002)(4326008)(256004)(66476007)(6512007)(71200400001)(71190400001)(5660300002)(4720700003)(6116002)(6636002)(52116002)(3846002)(66556008)(22452003)(64756008)(66946007)(66446008)(7416002)(86362001)(53936002)(8936002)(2906002)(921003)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:BYAPR21MB1206; H:BYAPR21MB1335.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: C2xM6G4nQWhi5W7uyGvHTE6GrP3QL824T9oYUlUVoHq+9N6xdtl4DRmNfa8FnrmG5r83lnmbzOezGrEf3rqfqynP99bGle5EIk+0hZ7ICtBDiy3/PCLWWJYY8e8NLUVtQhj2TAALU2f4Y07ck6knPvoNZiRgm8JXKevk19Cyjf9LSSvT/BpcAOCJUfo5Anez8sTRVJ+eYQF72k5xn+O2xrmjpRGy6MQpQm9Blh0IeKYD1Cc5ukYJ3mI8KAKbYxZoq1V6RgLrQPbe/e1BegiL3jwQCxIPr9pI5xxdfpf4VtVATeBNqm2WnmzJ1KTxsukhgHr85bRV0pX6/SLH8gQLgBAvoeccVwBOc6xAJKEA9jNMJdf6B0xMWDLS9lvTwwRmM53C4nF3sEgAFls734olyLBqLIa03cE5eRwVSH6LbOI= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 953e605d-8103-46a8-8248-08d71aacfcd9 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2019 20:30:57.6309 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: tTv3RfKFBdMT85EBM9FmPqJRygilWkq+1IoVbPIyNPtRoVKvfEL9VNKbCUzwLvEnv+vtSn8BqRCeWJ9qg4Xxwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR21MB1206 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190806_133100_113496_B5B9EC9B X-CRM114-Status: GOOD ( 18.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sunil Muthuswamy , "boqun.feng" , Michael Kelley Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add ARM64-specific code to make Hyper-V hypercalls and to access virtual processor synthetic registers via hypercalls. Hypercalls use a Hyper-V specific calling sequence with a non-zero immediate value per Section 2.9 of the SMC Calling Convention spec. This code is architecture dependent and is mostly driven by architecture independent code in the VMbus driver and the Hyper-V timer clocksource driver. This code is built only when CONFIG_HYPERV is enabled. Signed-off-by: Michael Kelley --- MAINTAINERS | 1 + arch/arm64/Makefile | 1 + arch/arm64/hyperv/Makefile | 2 + arch/arm64/hyperv/hv_hvc.S | 44 +++++++++++++++ arch/arm64/hyperv/hv_init.c | 133 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 181 insertions(+) create mode 100644 arch/arm64/hyperv/Makefile create mode 100644 arch/arm64/hyperv/hv_hvc.S create mode 100644 arch/arm64/hyperv/hv_init.c diff --git a/MAINTAINERS b/MAINTAINERS index fa98b21..71a8276 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7488,6 +7488,7 @@ F: arch/x86/kernel/cpu/mshyperv.c F: arch/x86/hyperv F: arch/arm64/include/asm/hyperv-tlfs.h F: arch/arm64/include/asm/mshyperv.h +F: arch/arm64/hyperv F: drivers/clocksource/hyperv_timer.c F: drivers/hid/hid-hyperv.c F: drivers/hv/ diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index bb1f1db..1f014e6 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -140,6 +140,7 @@ core-y += arch/arm64/kernel/ arch/arm64/mm/ core-$(CONFIG_NET) += arch/arm64/net/ core-$(CONFIG_KVM) += arch/arm64/kvm/ core-$(CONFIG_XEN) += arch/arm64/xen/ +core-$(CONFIG_HYPERV) += arch/arm64/hyperv/ core-$(CONFIG_CRYPTO) += arch/arm64/crypto/ libs-y := arch/arm64/lib/ $(libs-y) core-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a diff --git a/arch/arm64/hyperv/Makefile b/arch/arm64/hyperv/Makefile new file mode 100644 index 0000000..6bd8439 --- /dev/null +++ b/arch/arm64/hyperv/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-y := hv_init.o hv_hvc.o diff --git a/arch/arm64/hyperv/hv_hvc.S b/arch/arm64/hyperv/hv_hvc.S new file mode 100644 index 0000000..09324ac --- /dev/null +++ b/arch/arm64/hyperv/hv_hvc.S @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Microsoft Hyper-V hypervisor invocation routines + * + * Copyright (C) 2018, Microsoft, Inc. + * + * Author : Michael Kelley + */ + +#include + + .text +/* + * Do the HVC instruction. For Hyper-V the argument is always 1. + * x0 contains the hypercall control value, while additional registers + * vary depending on the hypercall, and whether the hypercall arguments + * are in memory or in registers (a "fast" hypercall per the Hyper-V + * TLFS). When the arguments are in memory x1 is the guest physical + * address of the input arguments, and x2 is the guest physical + * address of the output arguments. When the arguments are in + * registers, the register values depends on the hypercall. Note + * that this version cannot return any values in registers. + */ +ENTRY(hv_do_hvc) + hvc #1 + ret +ENDPROC(hv_do_hvc) + +/* + * This variant of HVC invocation is for hv_get_vpreg and + * hv_get_vpreg_128. The input parameters are passed in registers + * along with a pointer in x4 to where the output result should + * be stored. The output is returned in x15 and x16. x18 is used as + * scratch space to avoid buildng a stack frame, as Hyper-V does + * not preserve registers x0-x17. + */ +ENTRY(hv_do_hvc_fast_get) + mov x18, x4 + hvc #1 + str x15,[x18] + str x16,[x18,#8] + ret +ENDPROC(hv_do_hvc_fast_get) diff --git a/arch/arm64/hyperv/hv_init.c b/arch/arm64/hyperv/hv_init.c new file mode 100644 index 0000000..6808bc8 --- /dev/null +++ b/arch/arm64/hyperv/hv_init.c @@ -0,0 +1,133 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Initialization of the interface with Microsoft's Hyper-V hypervisor, + * and various low level utility routines for interacting with Hyper-V. + * + * Copyright (C) 2019, Microsoft, Inc. + * + * Author : Michael Kelley + */ + + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * hv_do_hypercall- Invoke the specified hypercall + */ +u64 hv_do_hypercall(u64 control, void *input, void *output) +{ + u64 input_address; + u64 output_address; + + input_address = input ? virt_to_phys(input) : 0; + output_address = output ? virt_to_phys(output) : 0; + return hv_do_hvc(control, input_address, output_address); +} +EXPORT_SYMBOL_GPL(hv_do_hypercall); + +/* + * hv_do_fast_hypercall8 -- Invoke the specified hypercall + * with arguments in registers instead of physical memory. + * Avoids the overhead of virt_to_phys for simple hypercalls. + */ + +u64 hv_do_fast_hypercall8(u16 code, u64 input) +{ + u64 control; + + control = (u64)code | HV_HYPERCALL_FAST_BIT; + return hv_do_hvc(control, input); +} +EXPORT_SYMBOL_GPL(hv_do_fast_hypercall8); + + +/* + * Set a single VP register to a 64-bit value. + */ +void hv_set_vpreg(u32 msr, u64 value) +{ + union hv_hypercall_status status; + + status.as_uint64 = hv_do_hvc( + HVCALL_SET_VP_REGISTERS | HV_HYPERCALL_FAST_BIT | + HV_HYPERCALL_REP_COUNT_1, + HV_PARTITION_ID_SELF, + HV_VP_INDEX_SELF, + msr, + 0, + value, + 0); + + /* + * Something is fundamentally broken in the hypervisor if + * setting a VP register fails. There's really no way to + * continue as a guest VM, so panic. + */ + BUG_ON(status.status != HV_STATUS_SUCCESS); +} +EXPORT_SYMBOL_GPL(hv_set_vpreg); + + +/* + * Get the value of a single VP register, and only the low order 64 bits. + */ +u64 hv_get_vpreg(u32 msr) +{ + union hv_hypercall_status status; + struct hv_get_vp_register_output output; + + status.as_uint64 = hv_do_hvc_fast_get( + HVCALL_GET_VP_REGISTERS | HV_HYPERCALL_FAST_BIT | + HV_HYPERCALL_REP_COUNT_1, + HV_PARTITION_ID_SELF, + HV_VP_INDEX_SELF, + msr, + &output); + + /* + * Something is fundamentally broken in the hypervisor if + * getting a VP register fails. There's really no way to + * continue as a guest VM, so panic. + */ + BUG_ON(status.status != HV_STATUS_SUCCESS); + + return output.registervaluelow; +} +EXPORT_SYMBOL_GPL(hv_get_vpreg); + +/* + * Get the value of a single VP register that is 128 bits in size. This is a + * separate call in order to avoid complicating the calling sequence for + * the much more frequently used 64-bit version. + */ +void hv_get_vpreg_128(u32 msr, struct hv_get_vp_register_output *result) +{ + union hv_hypercall_status status; + + status.as_uint64 = hv_do_hvc_fast_get( + HVCALL_GET_VP_REGISTERS | HV_HYPERCALL_FAST_BIT | + HV_HYPERCALL_REP_COUNT_1, + HV_PARTITION_ID_SELF, + HV_VP_INDEX_SELF, + msr, + result); + + /* + * Something is fundamentally broken in the hypervisor if + * getting a VP register fails. There's really no way to + * continue as a guest VM, so panic. + */ + BUG_ON(status.status != HV_STATUS_SUCCESS); + + return; + +} +EXPORT_SYMBOL_GPL(hv_get_vpreg_128); From patchwork Tue Aug 6 20:31:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 11079609 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 68AB6746 for ; Tue, 6 Aug 2019 20:32:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5663C288EA for ; Tue, 6 Aug 2019 20:32:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A3FF2897D; Tue, 6 Aug 2019 20:32:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2009D288EA for ; Tue, 6 Aug 2019 20:31:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5tAnCybqPQSq5ItpXCEG2ba+/qg+l+zwcoZjZFtB/2U=; b=HuHEcMyUICRdh7 ljCMEjP0Bl19VKmJEFY0iD340W1P88wCZ7Ax+QYBfYMNzN5GRad4svGlN1BHFhO8DK1RVsVi/2XGs S95Yzq0HkTcBDmZwyK8rAkM/XhBEw+8+Ky4oWkKA4WXE4qm29BojpZRPa6XvvpwidI1icMHkKe2Cv YNKBqYq+eziKtwzaVRVc8O6gFzmfAKOYczW+BZrDFEMtE6oRhyppiGFCF2fk3SAXuAcuWLKRSmiGn b/eZ4gPxVLCVpwAU1gGCD/yD8NbIY+mGob7w9EQhwXje0sJ5LHftdHDUnCXyz/Nf7LSRNdgReOKNg A2oD4Aeuk3ZNuTU6nwyw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hv67f-0006Qk-L1; Tue, 06 Aug 2019 20:31:55 +0000 Received: from mail-eopbgr780139.outbound.protection.outlook.com ([40.107.78.139] helo=NAM03-BY2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hv66o-0005bp-Ev for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2019 20:31:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P8cM9sEGKR3h/uQFKI9rVOP5S3Bv3Syxgxg/UxtJd05MjzJz+Ay+b6nIObwEQEOdTKDfbylnUcwYkdAT2eFEKKCLiWNBKgYC7F/Nh4UCFgoJE0UzAwo8N9fKTJzo+7Zji9cb6HXMXmbKonRtkCihcvvODFYj8pzqajTJZgL+ZrQFkZVnFz+EAIDCAOoBoUNULQl/jJJfO72Ibm1iLjPSUKEofXX5yQpx2mEiJmwWUEdtT8GqVNP2pVoJjSqObwm/DCoR47Yu/+lMEwwGfhkkVZU8W6bAAPsBlJ8q6NUIwC0D5ZXwnqytzTeiIchxWdt14yZ93cciea+x+3hKAZlnCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aYcH0tBd+rkNdHnFqLew4qdC23mYSO5/7ShL6K33obw=; b=VluSh1Zoajs3ldbaEv2Ml5foZljyJByPKPo8Mzq4oCGAQ4ZPlA9DE/vZhUpp3X5RTKcCkhXT+LWOWlfPMYjtKL8WROJTq1ae8gxN/B5eEU+xMpzEBU1+VmAQ3x5dO9nSF4fneYqx+MITw/7PaDMtveI13bTrFZ+bMKG3IRhGyfH7ycLqkGcSpUHSOs3t73PnAfjpxu3S/kXLut+LkqcxkkxtnejjYiZDCB1VppJlXK0EYNp8L2O+aeZX9eePrELahe51kUVXRnOqiNtKsKhgfWdq7BIoI5vRHHNOUGa6U/90Y3IAY0ypWk7M6ZDxLIPY+Cyzga4vZe2+UkfVK6EYTw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none 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:X-MS-Exchange-SenderADCheck; bh=aYcH0tBd+rkNdHnFqLew4qdC23mYSO5/7ShL6K33obw=; b=JmxISn0ry28qxtkpZz7O8PGwwGPdx7qQqlpO1LNR/PkztwDh04rm/HWi0BPt4COBb2H3Zc7lYG2KUyqVWjp2jET33em8yPHnnLzq9rNBmOKNo1Ay9wDNXNBoFXPnnRhEfQfinyv70ivq65tsErAoCzbfd4qNC1iHfqP0Lm6lPMQ= Received: from BYAPR21MB1335.namprd21.prod.outlook.com (20.179.60.209) by BYAPR21MB1255.namprd21.prod.outlook.com (20.179.57.159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2157.9; Tue, 6 Aug 2019 20:31:00 +0000 Received: from BYAPR21MB1335.namprd21.prod.outlook.com ([fe80::819:aea0:eda4:9301]) by BYAPR21MB1335.namprd21.prod.outlook.com ([fe80::819:aea0:eda4:9301%9]) with mapi id 15.20.2157.001; Tue, 6 Aug 2019 20:31:00 +0000 From: Michael Kelley To: "will.deacon@arm.com" , "catalin.marinas@arm.com" , "mark.rutland@arm.com" , "marc.zyngier@arm.com" , "linux-arm-kernel@lists.infradead.org" , "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , "linux-hyperv@vger.kernel.org" , "devel@linuxdriverproject.org" , "olaf@aepfle.de" , "apw@canonical.com" , vkuznets , "jasowang@redhat.com" , "marcelo.cerri@canonical.com" , KY Srinivasan Subject: [PATCH v4 3/8] arm64: hyperv: Add memory alloc/free functions for Hyper-V size pages Thread-Topic: [PATCH v4 3/8] arm64: hyperv: Add memory alloc/free functions for Hyper-V size pages Thread-Index: AQHVTJXcm7BY2ovIUkea7Rzw5X4O8g== Date: Tue, 6 Aug 2019 20:31:00 +0000 Message-ID: <1565122133-9086-4-git-send-email-mikelley@microsoft.com> References: <1565122133-9086-1-git-send-email-mikelley@microsoft.com> In-Reply-To: <1565122133-9086-1-git-send-email-mikelley@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR01CA0030.prod.exchangelabs.com (2603:10b6:300:101::16) To BYAPR21MB1335.namprd21.prod.outlook.com (2603:10b6:a03:115::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=mikelley@microsoft.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.8.3.1 x-originating-ip: [131.107.174.8] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 324a3256-89a8-44c6-d3b6-08d71aacfe6e x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:BYAPR21MB1255; x-ms-traffictypediagnostic: BYAPR21MB1255:|BYAPR21MB1255: x-ms-exchange-transport-forked: True x-ld-processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3968; x-forefront-prvs: 0121F24F22 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(366004)(39860400002)(396003)(376002)(136003)(346002)(189003)(199004)(71200400001)(102836004)(71190400001)(386003)(6636002)(6512007)(66446008)(7416002)(10090500001)(6506007)(10290500003)(66946007)(316002)(50226002)(110136005)(14454004)(4326008)(6116002)(1511001)(52116002)(64756008)(99286004)(2501003)(2201001)(25786009)(68736007)(476003)(11346002)(446003)(86362001)(8936002)(3846002)(14444005)(486006)(6486002)(256004)(8676002)(54906003)(76176011)(26005)(4720700003)(186003)(7736002)(81166006)(81156014)(2616005)(66066001)(66476007)(22452003)(5660300002)(2906002)(53936002)(305945005)(478600001)(6436002)(36756003)(66556008)(921003)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:BYAPR21MB1255; H:BYAPR21MB1335.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: KGX42rvmlnd8UbMFHQcJJTji9DHlnSgCXk5GeNea3aidmVbFjMa9q9bGPx7FQiiSKFLD6OnGhIeL69QMggREBJyff8+gm6YN6MCYq53LE9Ks7NsU2lHHsPdJsL7MU5zz4zPYgQxWK4Y8c0MCssE9UFGb1+CguwU3RWqIatMXlORqZfwdsHpKtnLUEz+AYKu2wyDkJbHI3HUZGA32Ek8BTqz0/bJHUTpbXv0+rhg/mg3y4OaeqFKMbWx5l1uTV+WWCCjR6bh4wqD8yroe4/t3wk096mfuJ7FxG0VAcNCA0IJ0VI+SJuGR0KoQqxDks1SgOZPmlIzcPN2rB/UE6KnJkq6AmRI/oE8yzo8jErVZETstpFtJUr0mZVET10686Vk6ze/TjyJMm6ExrMycZtE3p79qiRCfhyw3yvW8Ypnk3fw= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 324a3256-89a8-44c6-d3b6-08d71aacfe6e X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2019 20:31:00.2991 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: R04ucd1E6jBT5Y/K20dcqHkX7yTvSHlbmAR7cXQ13e10glteWS24u1CCBE5cGTCIuqbthyeE6hnBPtKgbv7ihA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR21MB1255 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190806_133102_793709_1FF69F06 X-CRM114-Status: GOOD ( 14.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sunil Muthuswamy , "boqun.feng" , Michael Kelley Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add ARM64-specific code to allocate memory with HV_HYP_PAGE_SIZE size and alignment. These are for use when pages need to be shared with Hyper-V. Separate functions are needed as the page size used by Hyper-V may not be the same as the guest page size. Free operations are rarely done, so no attempt is made to combine freed pages into larger chunks. This code is built only when CONFIG_HYPERV is enabled. Signed-off-by: Michael Kelley --- arch/arm64/hyperv/hv_init.c | 68 ++++++++++++++++++++++++++++++++++++++++++ include/asm-generic/mshyperv.h | 5 ++++ 2 files changed, 73 insertions(+) diff --git a/arch/arm64/hyperv/hv_init.c b/arch/arm64/hyperv/hv_init.c index 6808bc8..9c294f6 100644 --- a/arch/arm64/hyperv/hv_init.c +++ b/arch/arm64/hyperv/hv_init.c @@ -15,10 +15,78 @@ #include #include #include +#include +#include +#include #include #include #include + +/* + * Functions for allocating and freeing memory with size and + * alignment HV_HYP_PAGE_SIZE. These functions are needed because + * the guest page size may not be the same as the Hyper-V page + * size. And while kalloc() could allocate the memory, it does not + * guarantee the required alignment. So a separate small memory + * allocator is needed. The free function is rarely used, so it + * does not try to combine freed pages into larger chunks. + * + * These functions are used by arm64 specific code as well as + * arch independent Hyper-V drivers. + */ + +static DEFINE_SPINLOCK(free_list_lock); +static struct list_head free_list = LIST_HEAD_INIT(free_list); + +void *hv_alloc_hyperv_page(void) +{ + int i; + struct list_head *hv_page; + unsigned long addr; + + BUILD_BUG_ON(HV_HYP_PAGE_SIZE > PAGE_SIZE); + + spin_lock(&free_list_lock); + if (list_empty(&free_list)) { + spin_unlock(&free_list_lock); + addr = __get_free_page(GFP_KERNEL); + spin_lock(&free_list_lock); + for (i = 0; i < PAGE_SIZE; i += HV_HYP_PAGE_SIZE) + list_add_tail((struct list_head *)(addr + i), + &free_list); + } + hv_page = free_list.next; + list_del(hv_page); + spin_unlock(&free_list_lock); + + return hv_page; +} +EXPORT_SYMBOL_GPL(hv_alloc_hyperv_page); + +void *hv_alloc_hyperv_zeroed_page(void) +{ + void *memp; + + memp = hv_alloc_hyperv_page(); + memset(memp, 0, HV_HYP_PAGE_SIZE); + + return memp; +} +EXPORT_SYMBOL_GPL(hv_alloc_hyperv_zeroed_page); + + +void hv_free_hyperv_page(unsigned long addr) +{ + if (!addr) + return; + spin_lock(&free_list_lock); + list_add((struct list_head *)addr, &free_list); + spin_unlock(&free_list_lock); +} +EXPORT_SYMBOL_GPL(hv_free_hyperv_page); + + /* * hv_do_hypercall- Invoke the specified hypercall */ diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index 0becb7d..30a9f3e 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -99,6 +99,11 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type) void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs)); void hv_remove_crash_handler(void); +void *hv_alloc_hyperv_page(void); +void *hv_alloc_hyperv_zeroed_page(void); +void hv_free_hyperv_page(unsigned long addr); + + #if IS_ENABLED(CONFIG_HYPERV) /* * Hypervisor's notion of virtual processor ID is different from From patchwork Tue Aug 6 20:31:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 11079611 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ECF9F112C for ; Tue, 6 Aug 2019 20:32:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D75D228681 for ; Tue, 6 Aug 2019 20:32:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAFDE28893; Tue, 6 Aug 2019 20:32:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BF276288D0 for ; Tue, 6 Aug 2019 20:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jt2ejburVZbkJdEz2HO84V2VAekGSgOafZoiUITrMpI=; b=MwsqBcZKN6v6DI ZonmJYkXqFhdTwV9nJv1c+oGZWNf6D5r6yokKbwgvl4w08op7Qxb+ugUynNSEyV3nLhhrbzPkrmW8 5Ge+FHZUm1nzB7tJ+ZsmXNizdd9p1w0pAolzf2DpKG4FAtB9PZSfrQao6ALqrEgKODs4GdhEVENgD VAOzZr+IbtHzak8e18HeGAIChLc3F0LBLxFBYjThG2TU2CpwFVLe8YjWoLUFZWjZ+Sh6qFC0y/HD2 /2Zv8Mjg/XSR0O/IhnlaZMavoJe/Zh5kQY5/5IWxs4FhK2NGASTOmnc3QPB9AtK6n1mdxZIt+NlMW FJ42D016YGTG0iT7gVjA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hv67v-0006kG-Ts; Tue, 06 Aug 2019 20:32:11 +0000 Received: from mail-eopbgr780139.outbound.protection.outlook.com ([40.107.78.139] helo=NAM03-BY2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hv66q-0005bp-E8 for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2019 20:31:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nhKYnqn7NGFzQhPZQt0XpUXG0S4PrGDKjP5PfpgQUvBQe41cb/VJ4DS3dB+Ho/dUYtQSCSFtV9DnjLN19TsNFpQ3KMlu2Wob0LdMeIVvkXFa5Z0NnIVs1YQ1lNPNPetKIMGdXvppR7s2Kz7ZMgsV18k6hnKQZa+BRxR76lrYFEkWm9tg2f7s/Gn7XUSmlMvSzsQqDfX1PGj3x8e9h14W0wIdJaIEL2q4pXSP4fqaSvUj4op2rTRRwO4tNmoVcJiUikQUJDAuuWQaLdvrG1m4YdXd4Zy/uhkp0rkGMV/Q6IuGNDGH8TpJ5TFnND4/1ah+WDwn3AKbq569iCQnPAt+kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sDKx44wLEdTf4Pm93D0E5iRcN75+gRZgRy0PE4B1J00=; b=gUdm9dTdpZfW9HlzsnI0R9L9yXW/k+9qfHQI1RL3WuqC6SYjD7yCzWwWXikHv5Z0hL5d6bc3P5yU5Mjzq8IvCzN/sR7ty1ZbxEpLUetNfeXjty2C4X56ETaezbtWVUFW820Lugp9+2Siz9eeFRuE/ZujKBzP+ISDifY7E8QmHivElN5IRoCRM/XByQ+Bjr0ewolzqaZWOii9w9cf6iNoOwc2tp9CRjIS8bCoS1Rioibm0Ro+rzJmx+g0u9V4VOoMTle0FlMcwXP+zu+s9aysp5COVIMC8O/aW5DxZg05572wcJbesrSbi9UxP4qcnmH/H8toB09hSJJKcE29yuFq6A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none 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:X-MS-Exchange-SenderADCheck; bh=sDKx44wLEdTf4Pm93D0E5iRcN75+gRZgRy0PE4B1J00=; b=Rffzh3n5qPFMHHzabMbZCP8S6krWMtirVVDV8/cbK274/4t7KIEsTG60eJsCdKuT7YaFzxTjAChhJtfMky29M5ovY0Koc/Zph9cQN0Gk42ALJjDGOzBqNWEynnMD8yzJnlrv/sDsI/Gj7Ms4WKG5O5AiDxCLwKFiMY45TNP9auc= Received: from BYAPR21MB1335.namprd21.prod.outlook.com (20.179.60.209) by BYAPR21MB1255.namprd21.prod.outlook.com (20.179.57.159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2157.9; Tue, 6 Aug 2019 20:31:03 +0000 Received: from BYAPR21MB1335.namprd21.prod.outlook.com ([fe80::819:aea0:eda4:9301]) by BYAPR21MB1335.namprd21.prod.outlook.com ([fe80::819:aea0:eda4:9301%9]) with mapi id 15.20.2157.001; Tue, 6 Aug 2019 20:31:02 +0000 From: Michael Kelley To: "will.deacon@arm.com" , "catalin.marinas@arm.com" , "mark.rutland@arm.com" , "marc.zyngier@arm.com" , "linux-arm-kernel@lists.infradead.org" , "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , "linux-hyperv@vger.kernel.org" , "devel@linuxdriverproject.org" , "olaf@aepfle.de" , "apw@canonical.com" , vkuznets , "jasowang@redhat.com" , "marcelo.cerri@canonical.com" , KY Srinivasan Subject: [PATCH v4 4/8] arm64: hyperv: Add interrupt handlers for VMbus and stimer Thread-Topic: [PATCH v4 4/8] arm64: hyperv: Add interrupt handlers for VMbus and stimer Thread-Index: AQHVTJXd5SwxP8v4zUOVe4An72JhEA== Date: Tue, 6 Aug 2019 20:31:02 +0000 Message-ID: <1565122133-9086-5-git-send-email-mikelley@microsoft.com> References: <1565122133-9086-1-git-send-email-mikelley@microsoft.com> In-Reply-To: <1565122133-9086-1-git-send-email-mikelley@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR01CA0030.prod.exchangelabs.com (2603:10b6:300:101::16) To BYAPR21MB1335.namprd21.prod.outlook.com (2603:10b6:a03:115::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=mikelley@microsoft.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.8.3.1 x-originating-ip: [131.107.174.8] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 160c64a0-f598-4c16-c341-08d71aacfff1 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:BYAPR21MB1255; x-ms-traffictypediagnostic: BYAPR21MB1255:|BYAPR21MB1255: x-ms-exchange-transport-forked: True x-ld-processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6430; x-forefront-prvs: 0121F24F22 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(366004)(39860400002)(396003)(376002)(136003)(346002)(189003)(199004)(71200400001)(102836004)(71190400001)(386003)(6636002)(6512007)(66446008)(7416002)(10090500001)(6506007)(10290500003)(66946007)(316002)(50226002)(110136005)(14454004)(4326008)(6116002)(1511001)(52116002)(64756008)(99286004)(2501003)(2201001)(25786009)(68736007)(476003)(11346002)(446003)(86362001)(8936002)(3846002)(14444005)(486006)(6486002)(256004)(8676002)(54906003)(76176011)(26005)(4720700003)(186003)(7736002)(81166006)(81156014)(2616005)(66066001)(66476007)(22452003)(5660300002)(2906002)(53936002)(305945005)(478600001)(6436002)(36756003)(66556008)(921003)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:BYAPR21MB1255; H:BYAPR21MB1335.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: jIZ+Bd69boEahusaRsJanoE+I/1ervhQdz7sxrrzaPQp0SLXdeMSjgZbeSGLNYj33MmwLYpxQDunPLOeGkCw3g0J1yrnuHJioFQozkfCzn4AK3pFnU496sgnsPNgIPQL0ozJmYDNv1pW32hFoj+IXqW37zghSMOfhG5moF/nkHCAG4EPI2CCog+TA6+cmi/03bxiAPr81SMIzrGO/0NmHyaZ2d+ZGeOBsDvk1QLsoLZEnvL4sOzGhZlubv/Z1HuUqyd5eWjvmaAAJVzJ+Z0Pyr/OSAT8ssfMcEZPXkzERex2CCtV9BTfhqf3gKV/UAPvYuKD2o+i9etAQypKXf3KAoUAd+UnQ50Iuf9MBJnaj5bKg5BuNrxK/kRkPFwOdXeLFV5yOhYRQmfTfQOeSFAGfQF9WO5fZ33khGi8DdP8lYQ= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 160c64a0-f598-4c16-c341-08d71aacfff1 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2019 20:31:02.8499 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: vEjVyf+thTaRdStJOW+XohTbE9sGsHZYKau3gd6CUrUpVjIvZ1ZtMY+c11trKlZfF+RyIsA28uR5poZKcGbeLw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR21MB1255 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190806_133104_519733_076D21EB X-CRM114-Status: GOOD ( 15.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sunil Muthuswamy , "boqun.feng" , Michael Kelley Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add ARM64-specific code to set up and handle the interrupts generated by Hyper-V for VMbus messages and for stimer expiration. This code is architecture dependent and is mostly driven by architecture independent code in the VMbus driver and the Hyper-V timer clocksource driver. This code is built only when CONFIG_HYPERV is enabled. Signed-off-by: Michael Kelley --- arch/arm64/hyperv/Makefile | 2 +- arch/arm64/hyperv/mshyperv.c | 139 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/hyperv/mshyperv.c diff --git a/arch/arm64/hyperv/Makefile b/arch/arm64/hyperv/Makefile index 6bd8439..988eda5 100644 --- a/arch/arm64/hyperv/Makefile +++ b/arch/arm64/hyperv/Makefile @@ -1,2 +1,2 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y := hv_init.o hv_hvc.o +obj-y := hv_init.o hv_hvc.o mshyperv.o diff --git a/arch/arm64/hyperv/mshyperv.c b/arch/arm64/hyperv/mshyperv.c new file mode 100644 index 0000000..ae6ece6 --- /dev/null +++ b/arch/arm64/hyperv/mshyperv.c @@ -0,0 +1,139 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Core routines for interacting with Microsoft's Hyper-V hypervisor, + * including setting up VMbus and STIMER interrupts, and handling + * crashes and kexecs. These interactions are through a set of + * static "handler" variables set by the architecture independent + * VMbus and STIMER drivers. + * + * Copyright (C) 2019, Microsoft, Inc. + * + * Author : Michael Kelley + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static void (*vmbus_handler)(void); +static void (*hv_stimer0_handler)(void); + +static int vmbus_irq; +static long __percpu *vmbus_evt; +static long __percpu *stimer0_evt; + +irqreturn_t hyperv_vector_handler(int irq, void *dev_id) +{ + vmbus_handler(); + return IRQ_HANDLED; +} + +/* Must be done just once */ +void hv_setup_vmbus_irq(void (*handler)(void)) +{ + int result; + + vmbus_handler = handler; + vmbus_irq = acpi_register_gsi(NULL, HYPERVISOR_CALLBACK_VECTOR, + ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_HIGH); + if (vmbus_irq <= 0) { + pr_err("Can't register Hyper-V VMBus GSI. Error %d", + vmbus_irq); + vmbus_irq = 0; + return; + } + vmbus_evt = alloc_percpu(long); + result = request_percpu_irq(vmbus_irq, hyperv_vector_handler, + "Hyper-V VMbus", vmbus_evt); + if (result) { + pr_err("Can't request Hyper-V VMBus IRQ %d. Error %d", + vmbus_irq, result); + free_percpu(vmbus_evt); + acpi_unregister_gsi(vmbus_irq); + vmbus_irq = 0; + } +} +EXPORT_SYMBOL_GPL(hv_setup_vmbus_irq); + +/* Must be done just once */ +void hv_remove_vmbus_irq(void) +{ + if (vmbus_irq) { + free_percpu_irq(vmbus_irq, vmbus_evt); + free_percpu(vmbus_evt); + acpi_unregister_gsi(vmbus_irq); + } +} +EXPORT_SYMBOL_GPL(hv_remove_vmbus_irq); + +/* Must be done by each CPU */ +void hv_enable_vmbus_irq(void) +{ + enable_percpu_irq(vmbus_irq, 0); +} +EXPORT_SYMBOL_GPL(hv_enable_vmbus_irq); + +/* Must be done by each CPU */ +void hv_disable_vmbus_irq(void) +{ + disable_percpu_irq(vmbus_irq); +} +EXPORT_SYMBOL_GPL(hv_disable_vmbus_irq); + +/* Routines to do per-architecture handling of STIMER0 when in Direct Mode */ + +static irqreturn_t hv_stimer0_vector_handler(int irq, void *dev_id) +{ + if (hv_stimer0_handler) + hv_stimer0_handler(); + return IRQ_HANDLED; +} + +int hv_setup_stimer0_irq(int *irq, int *vector, void (*handler)(void)) +{ + int localirq; + int result; + + localirq = acpi_register_gsi(NULL, HV_STIMER0_IRQNR, + ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_HIGH); + if (localirq <= 0) { + pr_err("Can't register Hyper-V stimer0 GSI. Error %d", + localirq); + *irq = 0; + return -1; + } + stimer0_evt = alloc_percpu(long); + result = request_percpu_irq(localirq, hv_stimer0_vector_handler, + "Hyper-V stimer0", stimer0_evt); + if (result) { + pr_err("Can't request Hyper-V stimer0 IRQ %d. Error %d", + localirq, result); + free_percpu(stimer0_evt); + acpi_unregister_gsi(localirq); + *irq = 0; + return -1; + } + + hv_stimer0_handler = handler; + *vector = HV_STIMER0_IRQNR; + *irq = localirq; + return 0; +} +EXPORT_SYMBOL_GPL(hv_setup_stimer0_irq); + +void hv_remove_stimer0_irq(int irq) +{ + hv_stimer0_handler = NULL; + if (irq) { + free_percpu_irq(irq, stimer0_evt); + free_percpu(stimer0_evt); + acpi_unregister_gsi(irq); + } +} +EXPORT_SYMBOL_GPL(hv_remove_stimer0_irq); From patchwork Tue Aug 6 20:31:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 11079613 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8AA60112C for ; Tue, 6 Aug 2019 20:32:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79E52288D0 for ; Tue, 6 Aug 2019 20:32:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DE8F288F6; Tue, 6 Aug 2019 20:32:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E6CA4288EE for ; Tue, 6 Aug 2019 20:32:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FGD10QrmPDFoOquxCZR6vFzeLhCBed4c/SBWhkKYUNQ=; b=O7VGzkiTa6b4pM 1aJdLHymH0+bOdjyD1gFuN4VymVGNGgMI1wQE3sqM1ly8sLP/f3zIRH97304NNsROuycN/HBzREbW RXrjT/hREpmyo4xlwfALruZEKGoGCepR2gpvmvx8JJQq7ca8qw4o+alwxeqRWVSVnVzFMpO9JbFZF CyQcuZ8qydw3NfZZNvNcBTSt/giJqAA4cXxRpuI8hcvu5VsP6CkFcfRsfFokSCXcFmipEGrtZsVUM nQU7v2LEMvGgoTUHG528axhy/iU4HhPUS++Br8MrV2IY3J5gUqlUCKwQAy5WouYTPdokzUaPVzK/Y SXTH8xKdlp7zBrRtkedA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hv68L-00079t-7Y; Tue, 06 Aug 2019 20:32:37 +0000 Received: from mail-eopbgr820111.outbound.protection.outlook.com ([40.107.82.111] helo=NAM01-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hv66w-0005kG-Kw for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2019 20:31:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d5OiMmyZFl71fxWZiiAEC995k9jThY+EXeDqQBKU7QKjw/k0EjLc+iHB92s0E5nStPLDLZRBJr3qjph5APKgQ6k4XOa1QwB4EXMMw+M9q6ZpkeMga5MXaNjClwOHLT9pN+A9gpOdbQq5SyAvW8ztgw2Hspq5LG7vaBg2urJdPedKxiCKfuGS3xo36XW5Rluy2VXUwsMoE13I8x4abrTPBOhCRucuJQaMdNpUuDsN7R2wsYOieLL7X63U0pqxs2dGFHf/j86BoBXxWqtQr6MonbtKYe28p3K12i1BFSLAwggQkNBLIqbdmkwG1yG/B+0pccRBpVEAfUWxFas0If7kaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PJ4JKZIyEkt+ZqlOZNewTe208jaLwJVudybMI898C8A=; b=Zm8H87C3RKO5/u8+lPreosWTQjUgzYfOTTTbJ4TFlmcoZp3z+25F6vkFUJ/8HCfrFQ5K4NbtxC1nET5XWPPcF+W7TZsoxhp0eB72eMwiHliXXzxS5eGh2pPSl/IMNZxWparjrUmBE4SD8KmcVagODsmisSEGW2WxNntTIqMMf8xnYLdZjU//3uWec+5t8LiErpzqD8KEwgZrk5nxzVoVdNuf1RwqGXHnOEZbssT4kQ7f36EV3erTF2DDOWb2ReIhWvqrrBSvsB1GrTzbOppPaJqp3SJ5HkAfby/ecMJi5N3J2u2I647w24VH4JfsGr4Kn4om3hrDYKMRVb9seSkuqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none 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:X-MS-Exchange-SenderADCheck; bh=PJ4JKZIyEkt+ZqlOZNewTe208jaLwJVudybMI898C8A=; b=kUgaWYOa9MTKrC6sX+HuVdHXO6cA8tJZIso8tFQiMPN/VB5b7S0IE/RgLMw22ZNoQcCRxzQpobzXiZKzmFsnLbTBTAtvh/Ab+Fuushd88+ScI/Ub3Y2mRd9YwZ4AnLgokwFjrq01XTK16I3lf/NQ3NuTfDjUdt7R//TCexToOOo= Received: from BYAPR21MB1335.namprd21.prod.outlook.com (20.179.60.209) by BYAPR21MB1255.namprd21.prod.outlook.com (20.179.57.159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2157.9; Tue, 6 Aug 2019 20:31:06 +0000 Received: from BYAPR21MB1335.namprd21.prod.outlook.com ([fe80::819:aea0:eda4:9301]) by BYAPR21MB1335.namprd21.prod.outlook.com ([fe80::819:aea0:eda4:9301%9]) with mapi id 15.20.2157.001; Tue, 6 Aug 2019 20:31:06 +0000 From: Michael Kelley To: "will.deacon@arm.com" , "catalin.marinas@arm.com" , "mark.rutland@arm.com" , "marc.zyngier@arm.com" , "linux-arm-kernel@lists.infradead.org" , "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , "linux-hyperv@vger.kernel.org" , "devel@linuxdriverproject.org" , "olaf@aepfle.de" , "apw@canonical.com" , vkuznets , "jasowang@redhat.com" , "marcelo.cerri@canonical.com" , KY Srinivasan Subject: [PATCH v4 5/8] arm64: hyperv: Add kexec and panic handlers Thread-Topic: [PATCH v4 5/8] arm64: hyperv: Add kexec and panic handlers Thread-Index: AQHVTJXfLSWJuU36KkieVE028kSu1Q== Date: Tue, 6 Aug 2019 20:31:06 +0000 Message-ID: <1565122133-9086-6-git-send-email-mikelley@microsoft.com> References: <1565122133-9086-1-git-send-email-mikelley@microsoft.com> In-Reply-To: <1565122133-9086-1-git-send-email-mikelley@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR01CA0030.prod.exchangelabs.com (2603:10b6:300:101::16) To BYAPR21MB1335.namprd21.prod.outlook.com (2603:10b6:a03:115::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=mikelley@microsoft.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.8.3.1 x-originating-ip: [131.107.174.8] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 254d8428-1ebc-4fca-9d8b-08d71aad0200 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:BYAPR21MB1255; x-ms-traffictypediagnostic: BYAPR21MB1255:|BYAPR21MB1255: x-ms-exchange-transport-forked: True x-ld-processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 0121F24F22 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(366004)(39860400002)(396003)(376002)(136003)(346002)(189003)(199004)(71200400001)(102836004)(71190400001)(386003)(6636002)(6512007)(66446008)(7416002)(10090500001)(6506007)(10290500003)(66946007)(316002)(50226002)(110136005)(14454004)(4326008)(6116002)(1511001)(52116002)(64756008)(99286004)(2501003)(2201001)(25786009)(68736007)(476003)(11346002)(446003)(86362001)(8936002)(3846002)(486006)(6486002)(256004)(8676002)(54906003)(76176011)(26005)(4720700003)(186003)(7736002)(81166006)(81156014)(2616005)(66066001)(66476007)(22452003)(5660300002)(2906002)(53936002)(305945005)(478600001)(6436002)(36756003)(66556008)(921003)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:BYAPR21MB1255; H:BYAPR21MB1335.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 1nzbvI+QD6rW7PZhvXLe9NRgGAu6yaksfefYnIk20wfEgZTG4E77Mt8cmdNOfEx/NiaSIxcLT4JjA6Hsx24B/U8Ez/8L+4LArQCcb1HLmuL3wS2by+S4N1nRyyG6/t8RXs+GMeBZztdyH0E9uWYeNrVP7JBr1no7THze+BVe/yftmoEu6BVTLPn+SeMdatbANBjbCWeiXH8vyQkcdnKw+HgXcxYRvsvsCuQCl5YRQcq0Mtv99b/2PZzPz8kPKv0ty+sbYXUBbGRuHtgNHzP+6+qaEWUySsPvphENFMsdfEfvwDkJrPVa/wr3zyk+Wm39VEHcFHDHs5LTnuiMc1M+fl/Z3bCZa+gZuO1wRZj1ifpHwyvNBAf0ruABoCd7sIh+fcwE1bxk0UfmKjV2/yzehcQkYmkxuSmnc3XCqV64RA0= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 254d8428-1ebc-4fca-9d8b-08d71aad0200 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2019 20:31:06.2957 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: gMeyABJJ1P8PGxXALb49e5mdiJB8FZLFCeU+FpllfeX4efYh7M90BnQRb5TPFsoMlXXAuzRZ87QeS9FAHlweUA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR21MB1255 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190806_133110_777515_61AF74AF X-CRM114-Status: GOOD ( 13.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sunil Muthuswamy , "boqun.feng" , Michael Kelley Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add functions to set up and remove kexec and panic handlers, and to inform Hyper-V about a guest panic. These functions are called from architecture independent code in the VMbus driver. This code is built only when CONFIG_HYPERV is enabled. Signed-off-by: Michael Kelley --- arch/arm64/hyperv/hv_init.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ arch/arm64/hyperv/mshyperv.c | 26 +++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/arch/arm64/hyperv/hv_init.c b/arch/arm64/hyperv/hv_init.c index 9c294f6..67350ec 100644 --- a/arch/arm64/hyperv/hv_init.c +++ b/arch/arm64/hyperv/hv_init.c @@ -199,3 +199,64 @@ void hv_get_vpreg_128(u32 msr, struct hv_get_vp_register_output *result) } EXPORT_SYMBOL_GPL(hv_get_vpreg_128); + +void hyperv_report_panic(struct pt_regs *regs, long err) +{ + static bool panic_reported; + u64 guest_id; + + /* + * We prefer to report panic on 'die' chain as we have proper + * registers to report, but if we miss it (e.g. on BUG()) we need + * to report it on 'panic'. + */ + if (panic_reported) + return; + panic_reported = true; + + guest_id = hv_get_vpreg(HV_REGISTER_GUEST_OSID); + + /* + * Hyper-V provides the ability to store only 5 values. + * Pick the passed in error value, the guest_id, and the PC. + * The first two general registers are added arbitrarily. + */ + hv_set_vpreg(HV_REGISTER_CRASH_P0, err); + hv_set_vpreg(HV_REGISTER_CRASH_P1, guest_id); + hv_set_vpreg(HV_REGISTER_CRASH_P2, regs->pc); + hv_set_vpreg(HV_REGISTER_CRASH_P3, regs->regs[0]); + hv_set_vpreg(HV_REGISTER_CRASH_P4, regs->regs[1]); + + /* + * Let Hyper-V know there is crash data available + */ + hv_set_vpreg(HV_REGISTER_CRASH_CTL, HV_CRASH_CTL_CRASH_NOTIFY); +} +EXPORT_SYMBOL_GPL(hyperv_report_panic); + +/* + * hyperv_report_panic_msg - report panic message to Hyper-V + * @pa: physical address of the panic page containing the message + * @size: size of the message in the page + */ +void hyperv_report_panic_msg(phys_addr_t pa, size_t size) +{ + /* + * P3 to contain the physical address of the panic page & P4 to + * contain the size of the panic data in that page. Rest of the + * registers are no-op when the NOTIFY_MSG flag is set. + */ + hv_set_vpreg(HV_REGISTER_CRASH_P0, 0); + hv_set_vpreg(HV_REGISTER_CRASH_P1, 0); + hv_set_vpreg(HV_REGISTER_CRASH_P2, 0); + hv_set_vpreg(HV_REGISTER_CRASH_P3, pa); + hv_set_vpreg(HV_REGISTER_CRASH_P4, size); + + /* + * Let Hyper-V know there is crash data available along with + * the panic message. + */ + hv_set_vpreg(HV_REGISTER_CRASH_CTL, + (HV_CRASH_CTL_CRASH_NOTIFY | HV_CRASH_CTL_CRASH_NOTIFY_MSG)); +} +EXPORT_SYMBOL_GPL(hyperv_report_panic_msg); diff --git a/arch/arm64/hyperv/mshyperv.c b/arch/arm64/hyperv/mshyperv.c index ae6ece6..c58940d 100644 --- a/arch/arm64/hyperv/mshyperv.c +++ b/arch/arm64/hyperv/mshyperv.c @@ -23,6 +23,8 @@ static void (*vmbus_handler)(void); static void (*hv_stimer0_handler)(void); +static void (*hv_kexec_handler)(void); +static void (*hv_crash_handler)(struct pt_regs *regs); static int vmbus_irq; static long __percpu *vmbus_evt; @@ -137,3 +139,27 @@ void hv_remove_stimer0_irq(int irq) } } EXPORT_SYMBOL_GPL(hv_remove_stimer0_irq); + +void hv_setup_kexec_handler(void (*handler)(void)) +{ + hv_kexec_handler = handler; +} +EXPORT_SYMBOL_GPL(hv_setup_kexec_handler); + +void hv_remove_kexec_handler(void) +{ + hv_kexec_handler = NULL; +} +EXPORT_SYMBOL_GPL(hv_remove_kexec_handler); + +void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs)) +{ + hv_crash_handler = handler; +} +EXPORT_SYMBOL_GPL(hv_setup_crash_handler); + +void hv_remove_crash_handler(void) +{ + hv_crash_handler = NULL; +} +EXPORT_SYMBOL_GPL(hv_remove_crash_handler); From patchwork Tue Aug 6 20:31:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 11079615 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E048746 for ; Tue, 6 Aug 2019 20:32:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B786288EE for ; Tue, 6 Aug 2019 20:32:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F8FC288EA; Tue, 6 Aug 2019 20:32:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A60A9288C6 for ; Tue, 6 Aug 2019 20:32:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yzfVzZCM4gFkwL6fcUZJoBFbuDJNhbr17dRFbMSgEOI=; b=JvrTHFzf3DdJmd ZxwdYo+zXLntPPNbeszq8u9l2qCvtH8ZuQPe1X8ufQ47diEZjMqGZevSVklQe5ykyih9Flznqwxx4 r1l//ykI4m1IYW6UJOTZ+FVsX2tlxsIlzJnaJ1is2Ick1IHtz0f310Eip5XY2gnRUuEVvpKXGyhuX u80i1tzinLANEh72Z+k/AY8EWaOYG8q78L3weMI3KnokvuWluaa6J+siWKY1ZR2Qp16LI68toFGmC U9cW2EJjXjphkhciU6yyWMfpyPCCkKtgkAgmXOanUJeZLiZepiWyVZwJ5nt9pnALnUWLUMEXDX0os 6UjzX5IAj/nPTuIvb8Hw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hv68c-0007Qp-0X; Tue, 06 Aug 2019 20:32:54 +0000 Received: from mail-eopbgr820111.outbound.protection.outlook.com ([40.107.82.111] helo=NAM01-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hv66y-0005kG-GP for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2019 20:31:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kaet/brycjWE2MlRzNXxh9U7R7MCW9FB/6Jg2ePOl8HFoqFfvRxfZQjkZnBiwAtUKdsTMYDwUuFB7e6jVr6zRz34FHPAzcQDpNim2Ij/zCwF3KWTkZvYqpexFLtssM4Nfz0MzEkrZoJRYCw1XUvEHDQ0FhGyfolcH5ncRhZZpeVtW5zwTR6CQhAyRr0O9svnfDVPgimzGroFtBhc/za6arBXcvNUKp+HIbpbInwO6IukHhGBhTjlyn90zsQn0oW4PpEpZ7y5CAJ79KrvC+ySplyaYyLqykTsDFw1WwgsgtJ/Vc79n0S9ZnZ0L1aR5F2saQPgaA03wXVvS7oeBlzkrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZRcjUKuffbdIk6r+FeTJNIGuzF+267fwX53srmE9/o8=; b=KJr4yEjSRCl4UHHR07Rbqt9zGH/8PkKW3DvHjUD+gm14mggCxWZPEKNLxY+vEO+v984pNzhPKWyay6wvLAO0MgU7tmViqr1uQMgExd5sE19YSAS4xXdJED0HCYkIe2LA5EDjUgY2WA0uIfKhinNi99lfK/yc5R8P1l2LQdZqPah5gZFl0k+HiO8mbAXEDiEtI1Mfs9j7kYdc4dmu9xBjEhFckZ+Nq7je1bbTkGXPaGhCITLFeB75gakfFqxP8HL0g7Pe0X7Zxwj3itqbt/mBqFlHQ7myrHc/we5I3dSbKjT80fN06kod1Q8RpuQzWzZCkqzqphWowF2HUS6YzXom/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none 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:X-MS-Exchange-SenderADCheck; bh=ZRcjUKuffbdIk6r+FeTJNIGuzF+267fwX53srmE9/o8=; b=R/t2X4JbeaMrhpuR+8LqWSyOpdv7y2LdDs3CiWbheuaY9RpA+9FPsss9v8yXD41Up7SXTCFh8Fsf0FHrwYGd82LNAxdYdEnp0rDwhuNB5gL8y1u8WicKVHQGvi/W2Lpx0NllFnwnkYSp1zVRg5ZW3MFSnjZ11h0M94Mb+OT+eJs= Received: from BYAPR21MB1335.namprd21.prod.outlook.com (20.179.60.209) by BYAPR21MB1255.namprd21.prod.outlook.com (20.179.57.159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2157.9; Tue, 6 Aug 2019 20:31:08 +0000 Received: from BYAPR21MB1335.namprd21.prod.outlook.com ([fe80::819:aea0:eda4:9301]) by BYAPR21MB1335.namprd21.prod.outlook.com ([fe80::819:aea0:eda4:9301%9]) with mapi id 15.20.2157.001; Tue, 6 Aug 2019 20:31:08 +0000 From: Michael Kelley To: "will.deacon@arm.com" , "catalin.marinas@arm.com" , "mark.rutland@arm.com" , "marc.zyngier@arm.com" , "linux-arm-kernel@lists.infradead.org" , "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , "linux-hyperv@vger.kernel.org" , "devel@linuxdriverproject.org" , "olaf@aepfle.de" , "apw@canonical.com" , vkuznets , "jasowang@redhat.com" , "marcelo.cerri@canonical.com" , KY Srinivasan Subject: [PATCH v4 6/8] arm64: hyperv: Initialize hypervisor on boot Thread-Topic: [PATCH v4 6/8] arm64: hyperv: Initialize hypervisor on boot Thread-Index: AQHVTJXgt0yg3J047E6hlDw+N0KjAQ== Date: Tue, 6 Aug 2019 20:31:08 +0000 Message-ID: <1565122133-9086-7-git-send-email-mikelley@microsoft.com> References: <1565122133-9086-1-git-send-email-mikelley@microsoft.com> In-Reply-To: <1565122133-9086-1-git-send-email-mikelley@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR01CA0030.prod.exchangelabs.com (2603:10b6:300:101::16) To BYAPR21MB1335.namprd21.prod.outlook.com (2603:10b6:a03:115::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=mikelley@microsoft.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.8.3.1 x-originating-ip: [131.107.174.8] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 81d6f7e0-db2d-4b70-bf3a-08d71aad034f x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:BYAPR21MB1255; x-ms-traffictypediagnostic: BYAPR21MB1255:|BYAPR21MB1255: x-ms-exchange-transport-forked: True x-ld-processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6790; x-forefront-prvs: 0121F24F22 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(366004)(39860400002)(396003)(376002)(136003)(346002)(189003)(199004)(71200400001)(102836004)(71190400001)(386003)(6636002)(6512007)(66446008)(7416002)(10090500001)(6506007)(10290500003)(66946007)(316002)(50226002)(110136005)(14454004)(4326008)(6116002)(1511001)(52116002)(64756008)(99286004)(2501003)(2201001)(25786009)(68736007)(476003)(11346002)(446003)(86362001)(8936002)(3846002)(486006)(6486002)(256004)(8676002)(54906003)(76176011)(26005)(4720700003)(186003)(7736002)(81166006)(81156014)(2616005)(66066001)(66476007)(22452003)(5660300002)(2906002)(53936002)(305945005)(478600001)(6436002)(36756003)(66556008)(921003)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:BYAPR21MB1255; H:BYAPR21MB1335.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: SEbN97AgD73W4F1tMogEwiXnNDKgmqwGf8ZXmNmGP4okr45zVAsZA/dCp3wJyaZgAt8Uht7Shk+R/lF18M5B1cm3z/qhUzXmyeXV9oYtKGmaOfLoFRe2wPoXKMcrPkzi43O/ZfmDfuuQ4UKlURDVXMc6b3Xj9AmyJ2+Fok/MkE+uoR442tk4aGquYdu447juBK0BTiGAZOYKqtzdSx3Cp9NN7pj8WjGSy4zHTay/8E085XEkJgg7EK4Dg9HdAjY7Gnz6mPBR9+JW99qnf1cFCW+Jb7UpKtR9b7nIWPjG/dLYQ0GcSFc79DJgKQwNdlzcnHAqkmP0nG+ylFM0oPQwNN0d1RTq+7JO0SLFGatutXkYK3Sbr800UPv8ZNw2dmouVDuC+3AF4QWOcMKXLf0Ug8ihkQr8GLD3ugGgyYnUSRo= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 81d6f7e0-db2d-4b70-bf3a-08d71aad034f X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2019 20:31:08.4641 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: hva4QnbQLWBsv0oN5sSBGfkPWGcgNAs2IEPPNdPcsepPGyyUn/y6gMopD9paP4N2PHO9yAtPdXZHweaxOb7Wlg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR21MB1255 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190806_133112_658414_D47C0AA2 X-CRM114-Status: GOOD ( 16.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sunil Muthuswamy , "boqun.feng" , Michael Kelley Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add ARM64-specific code to initialize the Hyper-V hypervisor when booting as a guest VM. Provide functions and data structures indicating hypervisor status that are needed by VMbus driver. This code is built only when CONFIG_HYPERV is enabled. Signed-off-by: Michael Kelley --- arch/arm64/hyperv/hv_init.c | 142 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/arch/arm64/hyperv/hv_init.c b/arch/arm64/hyperv/hv_init.c index 67350ec..7179e12 100644 --- a/arch/arm64/hyperv/hv_init.c +++ b/arch/arm64/hyperv/hv_init.c @@ -13,15 +13,47 @@ #include #include #include +#include #include +#include +#include #include #include #include #include +#include +#include +#include #include #include #include +#include +#include +static bool hyperv_initialized; + +struct ms_hyperv_info ms_hyperv __ro_after_init; +EXPORT_SYMBOL_GPL(ms_hyperv); + +u32 *hv_vp_index; +EXPORT_SYMBOL_GPL(hv_vp_index); + +u32 hv_max_vp_index; +EXPORT_SYMBOL_GPL(hv_max_vp_index); + +static int hv_cpu_init(unsigned int cpu) +{ + u64 msr_vp_index; + + hv_get_vp_index(msr_vp_index); + + hv_vp_index[smp_processor_id()] = msr_vp_index; + + if (msr_vp_index > hv_max_vp_index) + hv_max_vp_index = msr_vp_index; + + return 0; +} /* * Functions for allocating and freeing memory with size and @@ -88,6 +120,110 @@ void hv_free_hyperv_page(unsigned long addr) /* + * This function is invoked via the ACPI clocksource probe mechanism. We + * don't actually use any values from the ACPI GTDT table, but we set up + * the Hyper-V synthetic clocksource and do other initialization for + * interacting with Hyper-V the first time. Using early_initcall to invoke + * this function is too late because interrupts are already enabled at that + * point, and hv_init_clocksource() must run before interrupts are enabled. + * + * 1. Setup the guest ID. + * 2. Get features and hints info from Hyper-V + * 3. Setup per-cpu VP indices. + * 4. Initialize the Hyper-V clocksource. + */ + +static int __init hyperv_init(struct acpi_table_header *table) +{ + struct hv_get_vp_register_output result; + u32 a, b, c, d; + u64 guest_id; + int i; + + /* + * If we're in a VM on Hyper-V, the ACPI hypervisor_id field will + * have the string "MsHyperV". + */ + if (strncmp((char *)&acpi_gbl_FADT.hypervisor_id, "MsHyperV", 8)) + return -EINVAL; + + /* Setup the guest ID */ + guest_id = generate_guest_id(0, LINUX_VERSION_CODE, 0); + hv_set_vpreg(HV_REGISTER_GUEST_OSID, guest_id); + + /* Get the features and hints from Hyper-V */ + hv_get_vpreg_128(HV_REGISTER_PRIVILEGES_AND_FEATURES, &result); + ms_hyperv.features = lower_32_bits(result.registervaluelow); + ms_hyperv.misc_features = upper_32_bits(result.registervaluehigh); + + hv_get_vpreg_128(HV_REGISTER_FEATURES, &result); + ms_hyperv.hints = lower_32_bits(result.registervaluelow); + + pr_info("Hyper-V: Features 0x%x, hints 0x%x\n", + ms_hyperv.features, ms_hyperv.hints); + + /* + * Direct mode is the only option for STIMERs provided Hyper-V + * on ARM64, so Hyper-V doesn't actually set the flag. But add + * the flag so the architecture independent code in + * drivers/clocksource/hyperv_timer.c will correctly use that mode. + */ + ms_hyperv.misc_features |= HV_STIMER_DIRECT_MODE_AVAILABLE; + + /* + * Hyper-V on ARM64 doesn't support AutoEOI. Add the hint + * that tells architecture independent code not to use this + * feature. + */ + ms_hyperv.hints |= HV_DEPRECATING_AEOI_RECOMMENDED; + + /* Get information about the Hyper-V host version */ + hv_get_vpreg_128(HV_REGISTER_HYPERVISOR_VERSION, &result); + a = lower_32_bits(result.registervaluelow); + b = upper_32_bits(result.registervaluelow); + c = lower_32_bits(result.registervaluehigh); + d = upper_32_bits(result.registervaluehigh); + pr_info("Hyper-V: Host Build %d.%d.%d.%d-%d-%d\n", + b >> 16, b & 0xFFFF, a, d & 0xFFFFFF, c, d >> 24); + + /* Allocate and initialize percpu VP index array */ + hv_vp_index = kmalloc_array(num_possible_cpus(), sizeof(*hv_vp_index), + GFP_KERNEL); + if (!hv_vp_index) + return -ENOMEM; + + for (i = 0; i < num_possible_cpus(); i++) + hv_vp_index[i] = VP_INVAL; + + if (cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "arm64/hyperv_init:online", + hv_cpu_init, NULL) < 0) + goto free_vp_index; + + hv_init_clocksource(); + + hyperv_initialized = true; + return 0; + +free_vp_index: + kfree(hv_vp_index); + hv_vp_index = NULL; + return -EINVAL; +} +TIMER_ACPI_DECLARE(hyperv, ACPI_SIG_GTDT, hyperv_init); + +/* + * This routine is called before kexec/kdump, it does the required cleanup. + */ +void hyperv_cleanup(void) +{ + /* Reset our OS id */ + hv_set_vpreg(HV_REGISTER_GUEST_OSID, 0); + +} +EXPORT_SYMBOL_GPL(hyperv_cleanup); + + +/* * hv_do_hypercall- Invoke the specified hypercall */ u64 hv_do_hypercall(u64 control, void *input, void *output) @@ -260,3 +396,9 @@ void hyperv_report_panic_msg(phys_addr_t pa, size_t size) (HV_CRASH_CTL_CRASH_NOTIFY | HV_CRASH_CTL_CRASH_NOTIFY_MSG)); } EXPORT_SYMBOL_GPL(hyperv_report_panic_msg); + +bool hv_is_hyperv_initialized(void) +{ + return hyperv_initialized; +} +EXPORT_SYMBOL_GPL(hv_is_hyperv_initialized); From patchwork Tue Aug 6 20:31:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 11079617 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 46B94112C for ; Tue, 6 Aug 2019 20:33:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36BF528849 for ; Tue, 6 Aug 2019 20:33:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A9832897C; Tue, 6 Aug 2019 20:33:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B737728849 for ; Tue, 6 Aug 2019 20:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8yZ2WutxwR0rHcae23NWXQhqhseJSN8NwsmKa0Cl13Q=; b=MSmYyoE6nC+2yf JG/4deITZS5k15tOCqyjXd65nli+hunD6SSWDwXK0uKdlLgZnAdgx4hFJ+o5w4p46ihIVaabIW117 PEVJqWAyCPs8PZBxLuroEOmX9e85IU4lmyflo6JshYhutXC8gx9p2epaGLQK/wEG1z7NbhhmEfEok VZlX4Kc0MliBqS4OyXhIOfoJ4uxB9E8Pfi81tIsavuNIxBJ7KuStjhU1CWC/Kd+DbEG5+HfY0gE4f 7O8nem5igdrKivOXxcmqSzoB4/BV2fyj9haY7H6fHmILbGiMtHomiHj/Oar2Weo+nNyYJUPXGU2iF Uxn4kHmCEMM7/klAdNhQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hv68t-0007lX-OW; Tue, 06 Aug 2019 20:33:11 +0000 Received: from mail-eopbgr820111.outbound.protection.outlook.com ([40.107.82.111] helo=NAM01-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hv671-0005kG-AM for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2019 20:31:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MHP6RNtDZ/bxwTkE7LTcYy2yi2ndI4e9kZD+r9Xe7Xn4P9s4r9QPRt/Gu9vlDHdbWcyzHZfF9j4SJUrW/ZxJSIfDfNqAnGKUoLke2WUuQO8qLKoCnAHL+P5B0qgaqtk8c7nth4JPYoho4Xc70Ds4S1aORN3ENA3i1f/hTMq+Jn4ZvyzmrnesrAKDpnAfbukTepdehil+C+Axt7Zu9HqVjkv7rl8qi7wZE+fLObHZXn28wMujwWGx3v/zpM4HIUbyM7vqXMulfyZZMKr4pwwumzS8clXb8eoIfY7I7Ewxs8iqJhZgbc0dLNmAVZD+NZPrrt8LjHn4erO3TFgRdRk6pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ax0dn0iS/KfEV1e+P4MVCkf7bW8prZ0KC7OdzfuPdXM=; b=OAOH0uFOyHwDplp9Ok23vkHZWM/IPnTTuRaKhuEsXALfCNEhBF8fBuNDdjcpr7LjOCusCCaA1vHH+GeGDk+mdXJ+Lx7OwlMOuM5mZ3H5E7ISXKl1ri7qIhOTa4/RiCSuUNngIUBRoyMzMdqNnJBQQ7HCpfbpIQaiDQoqYwmiJ0VlU5FH5PCCUnDvGdJOxQn23AbNYcE2cRNhwbnJ128QuXYfP/Dhxs7wiuSbCBODLspcxLjwz2Rmi6m5iPdfqO6FtaFnKJOaDLgJrpunz8cTQehab9AUAGcCd0M6q5Fk9ZVCs+cHSP+AfMAzV7T/muHJkhw3kIZdB4B897d3crmEuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none 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:X-MS-Exchange-SenderADCheck; bh=ax0dn0iS/KfEV1e+P4MVCkf7bW8prZ0KC7OdzfuPdXM=; b=kSLaYlionJtKdRNbuhoY8fQ/xfcNRBV6ZMWUQfXbX7hqRmqA10vBfkAJtZNOUoZW6r7lvMNQVhR7E+2vwiw/U9tAst+A9V//3yAoJiap3o8W99x77eYHz2d7SzUMdn5WSqAOUjuYLo/7a3P4/iMcSLjClvUosCfxjsFLtRUco84= Received: from BYAPR21MB1335.namprd21.prod.outlook.com (20.179.60.209) by BYAPR21MB1255.namprd21.prod.outlook.com (20.179.57.159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2157.9; Tue, 6 Aug 2019 20:31:11 +0000 Received: from BYAPR21MB1335.namprd21.prod.outlook.com ([fe80::819:aea0:eda4:9301]) by BYAPR21MB1335.namprd21.prod.outlook.com ([fe80::819:aea0:eda4:9301%9]) with mapi id 15.20.2157.001; Tue, 6 Aug 2019 20:31:11 +0000 From: Michael Kelley To: "will.deacon@arm.com" , "catalin.marinas@arm.com" , "mark.rutland@arm.com" , "marc.zyngier@arm.com" , "linux-arm-kernel@lists.infradead.org" , "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , "linux-hyperv@vger.kernel.org" , "devel@linuxdriverproject.org" , "olaf@aepfle.de" , "apw@canonical.com" , vkuznets , "jasowang@redhat.com" , "marcelo.cerri@canonical.com" , KY Srinivasan Subject: [PATCH v4 7/8] Drivers: hv: vmbus: Add hooks for per-CPU IRQ Thread-Topic: [PATCH v4 7/8] Drivers: hv: vmbus: Add hooks for per-CPU IRQ Thread-Index: AQHVTJXiq1nf/PrTQEeROpHi9r13SA== Date: Tue, 6 Aug 2019 20:31:11 +0000 Message-ID: <1565122133-9086-8-git-send-email-mikelley@microsoft.com> References: <1565122133-9086-1-git-send-email-mikelley@microsoft.com> In-Reply-To: <1565122133-9086-1-git-send-email-mikelley@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR01CA0030.prod.exchangelabs.com (2603:10b6:300:101::16) To BYAPR21MB1335.namprd21.prod.outlook.com (2603:10b6:a03:115::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=mikelley@microsoft.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.8.3.1 x-originating-ip: [131.107.174.8] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: abb0d250-d848-41b6-06d3-08d71aad04e2 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:BYAPR21MB1255; x-ms-traffictypediagnostic: BYAPR21MB1255:|BYAPR21MB1255: x-ms-exchange-transport-forked: True x-ld-processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-forefront-prvs: 0121F24F22 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(366004)(39860400002)(396003)(376002)(136003)(346002)(189003)(199004)(71200400001)(102836004)(71190400001)(386003)(6636002)(6512007)(66446008)(7416002)(10090500001)(6506007)(10290500003)(66946007)(316002)(50226002)(110136005)(14454004)(4326008)(6116002)(1511001)(52116002)(64756008)(99286004)(2501003)(2201001)(25786009)(68736007)(476003)(11346002)(446003)(86362001)(8936002)(3846002)(486006)(6486002)(256004)(8676002)(54906003)(76176011)(26005)(4720700003)(186003)(7736002)(81166006)(81156014)(2616005)(66066001)(66476007)(22452003)(5660300002)(2906002)(53936002)(305945005)(478600001)(6436002)(36756003)(66556008)(921003)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:BYAPR21MB1255; H:BYAPR21MB1335.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: P6mxwQvPGqTwmd0jC161SaVFeyZonp/UdEUH1XlhQJ77oqUoX/JDFmLBpNJOrCrJv/6bc/LR/o/X/7yxUqphVdL3QHUg5Wk5sV1riU09u3PzR7Jd69Am8UxQhhaOe97X1ArvdupMZu9G/0qrRDTy93xGcP8NCO3H/7X4WQo2YZtUd9m/5uFbMEjqeHwIqElFOvoAuYRLOa4QmctpNvsd03zF2GceCGG+aM7o6nsGeEeUaRQN6PTeL3qZLW70idekt7gzIvV6M+M/KjHEnWc9RiqYyGShAZw6H85zjnUpLLwQjpQrbYwvAcV4Ozf0spP/1A7tGI9CtSmVfqA7QUZGq3r+ogjlOjMSJjAmZGkQpA7WVMrgXweB8Q5mYP0/7v4AXmiyRwIx7i+UXOtVwdaJN8t17ef45mppiNccX+Kqjd4= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: abb0d250-d848-41b6-06d3-08d71aad04e2 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2019 20:31:11.1353 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 0BN77rop+1aEAoLcn5qHr8NbQmjvN1cNNI/hZf6Rph0wC5RGEVc4N3xp/WY0mj1Ln+YlSGCLYmgJQgPM8Y4KkA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR21MB1255 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190806_133115_463331_30415713 X-CRM114-Status: GOOD ( 10.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sunil Muthuswamy , "boqun.feng" , Michael Kelley Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add hooks to enable/disable a per-CPU IRQ for VMbus. These hooks are in the architecture independent setup and shutdown paths for Hyper-V, and are needed by Linux guests on Hyper-V on ARM64. The x86/x64 implementation is null because VMbus interrupts on x86/x64 don't use an IRQ. Signed-off-by: Michael Kelley --- arch/x86/include/asm/mshyperv.h | 4 ++++ drivers/hv/hv.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index f4138ae..583e1ce 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -56,6 +56,10 @@ typedef int (*hyperv_fill_flush_list_func)( #endif void hyperv_vector_handler(struct pt_regs *regs); +/* On x86/x64, there isn't a real IRQ to be enabled/disable */ +static inline void hv_enable_vmbus_irq(void) {} +static inline void hv_disable_vmbus_irq(void) {} + /* * Routines for stimer0 Direct Mode handling. * On x86/x64, there are no percpu actions to take. diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 6188fb7..86f5435 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -180,6 +180,7 @@ int hv_synic_init(unsigned int cpu) hv_set_siefp(siefp.as_uint64); /* Setup the shared SINT. */ + hv_enable_vmbus_irq(); hv_get_synint_state(VMBUS_MESSAGE_SINT, shared_sint.as_uint64); shared_sint.vector = HYPERVISOR_CALLBACK_VECTOR; @@ -272,6 +273,7 @@ int hv_synic_cleanup(unsigned int cpu) /* Disable the global synic bit */ sctrl.enable = 0; hv_set_synic_state(sctrl.as_uint64); + hv_disable_vmbus_irq(); return 0; } From patchwork Tue Aug 6 20:31:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 11079619 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 499F3746 for ; Tue, 6 Aug 2019 20:33:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37395288D7 for ; Tue, 6 Aug 2019 20:33:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B039288F6; Tue, 6 Aug 2019 20:33:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CFB20288D7 for ; Tue, 6 Aug 2019 20:33:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LJTiS5JEAttJTR98HJ6UnBpU4AuEHfNPpsf50HfUlGk=; b=jiIxzPflVt0I2U Edtj/VVXW66ELaNyzh3z7MU8Yhb5Kdjz83g9shLIz90EZlaWWwxNJd5/eYqnzefRkp4FUuInPj90j 2NjAY5KH21vXaj7PiPdOmheROcd1AuVeZWinluWuQ+S2ARjgoEBjVfPK4La93OpjLHD8r0jNPtpFV 5kLc8qr5CiQ0Xqa7eip3RjTGLv7qO5OohjwVEVECmSfYrKinCS7LKN3xFHGuhQ/La/s3lSykd5Aci yjrNceUYGgEkTP09pqEGR46UWvoTJ6tUmO/PWcFD4MNSag0ucdt2fkJxhHlx4e/htyKdHoJB7KgCs Nas8LRzPwWbU+nE0yc9Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hv69E-0008AR-UL; Tue, 06 Aug 2019 20:33:33 +0000 Received: from mail-eopbgr820111.outbound.protection.outlook.com ([40.107.82.111] helo=NAM01-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hv673-0005kG-6Y for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2019 20:31:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nAc7t8kncGOA2Nvyw1SIppDWdTbZRSVnSeqzuSkY2qWLXjU2u8aTy2PKSI+nA/ynCCQcQgZGw/KBKJy35o7v0MIEjUDSeBRRzQ6TkmHfzpaTbn27gtCO3KGFpvuQDAHzAv3AfdS9aCXqidcMGNtsmz2r6eialuZBBGEfoHrfI5zNIHTHDPnVTX0X5XXUv1NOYuPvZOZKbYKGLew0LDy2AN49KoEVerzquL1pWhmDSeLsPyGWM6sw0NMIiLCgHtTL8QsikLhOR3ydR2y2Z7nkhvo0lWAYkKBsivpoY/CKWxkUNYhhTTC20Y5L3UJLgWj507qivt5iYVHWjWiUl43usQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kksfFcm3GBFsZkms/2CzgqzxYkQ6KvCxhAIvLS/Bzo0=; b=VbaWGXhlsLl2Boy61bpkMw7kUxoZ3R0KAZyf6QKKx21dePL+f/U6NtcklIfMvJxcZdhP1fL2JL9V8OPP1tAfT1Fd+rdYyD3nEq2MBvxsZkOnChGaOqct+BROCLzrRuyFujniRRQpuX1pKwif1Wi7ytkIO5SZ8vP4dVkHubpuuiriuuV8YYdBIn1itg8CvMUqkAGlmjgbMJjRVYvysbtG3Tlx7pd9ml8CRa5G+B9qEsFz94oLBcQk0zRj1PqSdSpF4vl7j9uMb6hLEhRRvHFLKGS+mq2c+e30jXAK9lHdZ0ept43Dhhder8Sg80aZJ0E7lEZk93uHw7UGHDwjSf1OXg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none 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:X-MS-Exchange-SenderADCheck; bh=kksfFcm3GBFsZkms/2CzgqzxYkQ6KvCxhAIvLS/Bzo0=; b=eVTPAmRoFhJDZPLWmKpzlmCCHE6JfGf7G4//Uulk9nlvGga8tkwgp+5j3f1Rx/livn88o8EzYsvNEhINcFlRf29zG3DPh5z/Ucg6wtcAtiYJRwNXiNY0xbk12IEWEz7HMlr6/qszGEeLFc83FqlahGL7UqwI6rdIXZYT/DUkKfY= Received: from BYAPR21MB1335.namprd21.prod.outlook.com (20.179.60.209) by BYAPR21MB1255.namprd21.prod.outlook.com (20.179.57.159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2157.9; Tue, 6 Aug 2019 20:31:13 +0000 Received: from BYAPR21MB1335.namprd21.prod.outlook.com ([fe80::819:aea0:eda4:9301]) by BYAPR21MB1335.namprd21.prod.outlook.com ([fe80::819:aea0:eda4:9301%9]) with mapi id 15.20.2157.001; Tue, 6 Aug 2019 20:31:13 +0000 From: Michael Kelley To: "will.deacon@arm.com" , "catalin.marinas@arm.com" , "mark.rutland@arm.com" , "marc.zyngier@arm.com" , "linux-arm-kernel@lists.infradead.org" , "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , "linux-hyperv@vger.kernel.org" , "devel@linuxdriverproject.org" , "olaf@aepfle.de" , "apw@canonical.com" , vkuznets , "jasowang@redhat.com" , "marcelo.cerri@canonical.com" , KY Srinivasan Subject: [PATCH v4 8/8] Drivers: hv: Enable Hyper-V code to be built on ARM64 Thread-Topic: [PATCH v4 8/8] Drivers: hv: Enable Hyper-V code to be built on ARM64 Thread-Index: AQHVTJXj8v6XQum5DEe1djG7y0U7wg== Date: Tue, 6 Aug 2019 20:31:13 +0000 Message-ID: <1565122133-9086-9-git-send-email-mikelley@microsoft.com> References: <1565122133-9086-1-git-send-email-mikelley@microsoft.com> In-Reply-To: <1565122133-9086-1-git-send-email-mikelley@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR01CA0030.prod.exchangelabs.com (2603:10b6:300:101::16) To BYAPR21MB1335.namprd21.prod.outlook.com (2603:10b6:a03:115::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=mikelley@microsoft.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.8.3.1 x-originating-ip: [131.107.174.8] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c453a1ff-561f-4dfa-d7ba-08d71aad0637 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:BYAPR21MB1255; x-ms-traffictypediagnostic: BYAPR21MB1255:|BYAPR21MB1255: x-ms-exchange-transport-forked: True x-ld-processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1332; x-forefront-prvs: 0121F24F22 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(366004)(39860400002)(396003)(376002)(136003)(346002)(189003)(199004)(71200400001)(102836004)(71190400001)(386003)(6636002)(6512007)(66446008)(7416002)(10090500001)(6506007)(10290500003)(66946007)(316002)(50226002)(110136005)(14454004)(4326008)(6116002)(1511001)(52116002)(64756008)(99286004)(2501003)(4744005)(2201001)(25786009)(68736007)(476003)(11346002)(446003)(86362001)(8936002)(3846002)(14444005)(486006)(6486002)(256004)(8676002)(54906003)(76176011)(26005)(4720700003)(186003)(7736002)(81166006)(81156014)(2616005)(66066001)(66476007)(22452003)(5660300002)(2906002)(53936002)(305945005)(478600001)(6436002)(36756003)(66556008)(921003)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:BYAPR21MB1255; H:BYAPR21MB1335.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: +WDWPP+NTP/4pti+i5drAz9nT/q8NkoE9503eYu5m4zGbmi+BzeYP4SRIftOMUSyDtZKbSBfdsYIA1qlj8JANqUxaljmOxUyJw0+IpH8F5vFosEVtDuthBffUYfeKdHWPFv57T19RsgUPDfmOAlwyU/I0Pac83V8vmFqM6CrU7uuZnvPVRadMeu2Yp7UC76QtcwUI+ImKswimBUar/T3u4CcXPj11jp9WxXakQ5WUvu4VKxqEjlyfrv+mGD1KogopryogWqld/wCLiqi0JEWAxYVoEyextjaRP6X4Q3PlWwe5q+1bXGpn0Ndv0OK3yR3xMzD0BfJL0CsSc4ZnOIJXFcpjuT5allHYuXBmXXb4OYfcNSh/vDq8NTfFgkDVzrRDXefV4iAD/9SFOOWwZsxM3+VuVQ8ItRAqWLP6cGs8ZA= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: c453a1ff-561f-4dfa-d7ba-08d71aad0637 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2019 20:31:13.3565 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: cQ0R+KiVYV+6SGp9gZLytL7vYfJ/rteM3114ZgPMBKb75JP8fxS2Pip//r+OdbMIQt0D7H7C4aLYXx/youMe9w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR21MB1255 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190806_133117_397868_04045C13 X-CRM114-Status: UNSURE ( 9.69 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sunil Muthuswamy , "boqun.feng" , Michael Kelley Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Update drivers/hv/Kconfig so CONFIG_HYPERV and CONFIG_HYPERV_TSCPAGE can be selected on ARM64, causing the Hyper-V specific code to be built. Signed-off-by: Michael Kelley --- drivers/hv/Kconfig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig index 9a59957..6f8808f 100644 --- a/drivers/hv/Kconfig +++ b/drivers/hv/Kconfig @@ -4,7 +4,8 @@ menu "Microsoft Hyper-V guest support" config HYPERV tristate "Microsoft Hyper-V client drivers" - depends on X86 && ACPI && X86_LOCAL_APIC && HYPERVISOR_GUEST + depends on ACPI && \ + ((X86 && X86_LOCAL_APIC && HYPERVISOR_GUEST) || ARM64) select PARAVIRT select X86_HV_CALLBACK_VECTOR help @@ -15,7 +16,7 @@ config HYPERV_TIMER def_bool HYPERV config HYPERV_TSCPAGE - def_bool HYPERV && X86_64 + def_bool HYPERV && (X86_64 || ARM64) config HYPERV_UTILS tristate "Microsoft Hyper-V Utilities driver"