Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp11254pxb; Fri, 5 Mar 2021 12:55:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJxI9/3hATSv4bmezVPyrxMMyHVXw4wHT33WJW3AhyAhvFHLcqVLCrHP0tWCP5Hvmsktdhdt X-Received: by 2002:a17:906:5495:: with SMTP id r21mr4196009ejo.59.1614977739573; Fri, 05 Mar 2021 12:55:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1614977739; cv=pass; d=google.com; s=arc-20160816; b=t7n92qJJ67aLYNCl644W9sF0AUN9KDWywlg4vuSb6YBCRTVLMT7hE4gnF0u2qWbOsN fkT68mJ4eEXyPgASpMuiv0Zajl6Kw28T70ec0v9djHqbWIN/s18/TwBh9hpECpCJRfu1 IXiisiZt1kOsjoh08Srge+zIFbc/2fopmgd6dS/kKJ2HCa77TX5kUvpQUH+Qg2GTWk+w /SDdLTZ584sv64PsV+ilx82M4U9aMhsR7Oa7doWCNrdroiTz+jKeCmh3ttzh6WFMBaaf 6zMdsyXAVdqeswwUjaUtGoKEgQNIxTYcp0mDtkjgCFVOjavdIy0A0dlVSYuT5PGJEbvL g9eA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :msip_labels:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :dkim-signature; bh=83cTk3Z0YSbNWJEdRTLEYkjLf2nQa2VvkDGR0ZJTF9Y=; b=VLNJyc4jvuWJnTlki6Y1/+Ye1lHi09kles8crJeVCD/1OxNnKL2kZ33sJ5D1lo9TQU 4GGR4S5iKCJBFrHF55mCbUsDL3kaUSmE65sedhVXFRYsyBDKLa1CufVkGnGZHcXHKLeB kIyx7LLAdvx0H01wcAnEo1eK4SjkBgsH8HQ82LUmDQGv9N02csLmOwq3hr1S2BxbPH+U 31+GWywWbGTA0TSBtfThLFlMWN617IQhzF2DIYnafZdkJsXpkF9HUzRW5D68jxdIdWjc +bMTQ0iMIk3fkqTlFGjy2ifzp/Eb8LgQgF2NeS0/mAcL8og4FCLTfH8P1rmgAv+RwZJb YUZQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=RxsJF8wM; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s11si2167659edd.147.2021.03.05.12.55.16; Fri, 05 Mar 2021 12:55:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=RxsJF8wM; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229875AbhCEUvD (ORCPT + 99 others); Fri, 5 Mar 2021 15:51:03 -0500 Received: from mail-bn7nam10on2105.outbound.protection.outlook.com ([40.107.92.105]:26497 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229690AbhCEUuw (ORCPT ); Fri, 5 Mar 2021 15:50:52 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jbT5FT5t3aexXJmD6xy0KnTZc7zc4UUr2qSeNnmhNJX35qRb8hBbxsMA8XOwmLGMHfua3JU+tOXe2BwrcMCvCJnEhTfebSFEC/0yA9oxsOjFwdjsblpcq+x+jiA1xUE2L88vMuYaN/24YgtEaHFjnfTCDZ3EvRuY8mVaOlLaesXyDnqSZ4zcp6QXa2kCamXxY9Sn+2bNVswG9HWxd3yPQhRjcaGU+gPHUHEiAGQS2RmjK8s1Bc9ylrImtcSyKzupEuzXc/fGstiZsn0H4sXsMckOBqMzabcfEFlfrXJ/UBiaK/ijsA4VDR572BxxRNtVV8z2NrIDJsJPbGvltKplWg== 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=83cTk3Z0YSbNWJEdRTLEYkjLf2nQa2VvkDGR0ZJTF9Y=; b=bQ4edCjQzjc4KDuHJV3getjq8h0/uXnWYJ71hG5LuSiyWzMiawxrvmy8natCYsa0hNuE9S0ipd+osLFGvkwwvfltYRQbwNWlFh5VZPRpg0UEprrYGtqDxwV5L2a3JKtQb08t2ynZMk5nKQRUfN6Kske0350yMDEBKPSlVponWGXeQJw88cNTULd7ELAbdJmLQ0ElNnq1bRO3uM8mXlNt6hBpXyIjBwbxW526al7qlea8x+ToKd+KN2Wv7REVKzNxXeqCICZim+PCY2LS6syEjqX2n3P3mbmOdpzAyNnXtzrluYMPWJyzpgnXlMv8tUC5HI0RdahZhylXTSF1OYfe/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=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=83cTk3Z0YSbNWJEdRTLEYkjLf2nQa2VvkDGR0ZJTF9Y=; b=RxsJF8wMqqLKjkhN61x4JDhwG9xspY3DGFg3uZqLJKqDvE5Bi6vqgW0NvVF4/1DHxR59KmIebDRnEqMfNr9B8z8JwFX9GD6KnC4KHgLB1WOlZaEx2uOIqbAt/NHOOEiYIKI7qQDs0uoYdnz/R/7KUju9DfmoornQiY1lNV8wt1g= Received: from MWHPR21MB1593.namprd21.prod.outlook.com (2603:10b6:301:7c::11) by MW4PR21MB1956.namprd21.prod.outlook.com (2603:10b6:303:7a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.14; Fri, 5 Mar 2021 20:50:49 +0000 Received: from MWHPR21MB1593.namprd21.prod.outlook.com ([fe80::9c8:94c9:faf1:17c2]) by MWHPR21MB1593.namprd21.prod.outlook.com ([fe80::9c8:94c9:faf1:17c2%9]) with mapi id 15.20.3912.025; Fri, 5 Mar 2021 20:50:49 +0000 From: Michael Kelley To: Boqun Feng CC: "will@kernel.org" , "catalin.marinas@arm.com" , Mark Rutland , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "linux-hyperv@vger.kernel.org" , "linux-efi@vger.kernel.org" , "arnd@arndb.de" , "wei.liu@kernel.org" , "ardb@kernel.org" , "daniel.lezcano@linaro.org" , KY Srinivasan Subject: RE: [PATCH v8 1/6] arm64: hyperv: Add Hyper-V hypercall and register access utilities Thread-Topic: [PATCH v8 1/6] arm64: hyperv: Add Hyper-V hypercall and register access utilities Thread-Index: AQHXBkw53oUu1j5MYUuXintiG4xa8apmn1UAgA9VSHA= Date: Fri, 5 Mar 2021 20:50:49 +0000 Message-ID: References: <1613690194-102905-1-git-send-email-mikelley@microsoft.com> <1613690194-102905-2-git-send-email-mikelley@microsoft.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=true; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2021-03-05T20:50:47Z; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Method=Standard; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=Internal; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ActionId=dad554c7-b4cd-4baf-9f02-f5cd66f0d316; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ContentBits=0 authentication-results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=microsoft.com; x-originating-ip: [24.22.167.197] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 31b97a24-ac1a-4c03-8585-08d8e0185be8 x-ms-traffictypediagnostic: MW4PR21MB1956: 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-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ES6M9QN15Q/iqEV0RZEv1whcHkIbKCUzDDDSpQqtwcb3zIcbkQjftQN/wGvARKMr4nKTdTEvWlGkk7F4bKzpVx7RhIWYo3cHpUfCNXKpADzBNt+ENMslo5N8Z6VFpC+UxXSLD4NVYWI5qtLfgdkTovfl4bYjh/kfPcHc8ikGcwESi2zt/+VpzIk3GDe4hBRg2B5irJ0EXCBgfXxfQ11WUqrWvbKEershxxM71IaXw1I3JNMc9L8CPURj5xlRPAIfEpX2zf8R0Df5Fm4UNEVkXODHtvvDjmN0kgd29KngJXF+SfAP6D0lZrzduUhQ5dh6myDmby8PAmn6EPK0mI5XADLi0N+Nb4esOjzU2zf3Dl9NLdUACTChWraqQJObz74Sk9rr6mr/t/kqnEzHafpn27C0/EM9F5E/eCd/ksBuLcTuzNbsjAotSWTmIVomfEHrZ1GSX0zO/7xGt5czB/+yu1nl4bDb99/nEpJP2y7wYC4KlUM7x9T3uQ2nJXQheN3MkIrvfsXmwsnDrNhzALPL3lK2hz3W8GY+mbwxxwlWw0C2EJRJftQbLjXGY4NMx2xR x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR21MB1593.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(346002)(396003)(39860400002)(376002)(136003)(55016002)(71200400001)(52536014)(478600001)(26005)(66446008)(7696005)(33656002)(6506007)(83380400001)(5660300002)(8990500004)(186003)(6916009)(86362001)(64756008)(82950400001)(316002)(82960400001)(10290500003)(66556008)(8936002)(9686003)(66476007)(7416002)(2906002)(4326008)(54906003)(8676002)(76116006)(66946007)(107886003);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?IlMO8uGqjmHZyzkkhcN5BjfNNJFiBOqAQxDCDtsSYgOtD/oHTdUyC34jLig4?= =?us-ascii?Q?adgz5tSlLpvFn5PHPZutBLGEtFMVN8qE4OMUZ6UPLBk9N22NZ7+NTbMnIXLR?= =?us-ascii?Q?/ZfOopoWkkx5yhbYgGEwyaniQi4OON1VegBL/h4Y7TfKd2hTLSYjM2OoMCZ7?= =?us-ascii?Q?sd0RoVPfGIEP5TQYDNHjqEdVp8XyRC2BntTEjDzbl0apPrF8Zf/76Dlrieay?= =?us-ascii?Q?VeZTw44tfW4LiitYgtDhHeYMGWWJS50VqFi/ZBiy1nOFfHxetjMS8JqoNj6c?= =?us-ascii?Q?MLhK73CcEx745oWxXRIEACccWCePuFZAd+GuJCoOsQnQHS42uGrqm8PPpZZ1?= =?us-ascii?Q?6EkFpL2FtXSyRGf2zDjSsDoViVGj+hBfzz2nyOc3dExW/zkkuNgnW7ZRCMm5?= =?us-ascii?Q?5IQeCTBq0Lh8nA7g525uUtBnb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sDimb858nhsYJ0DXBrwpvcl?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR21MB1593.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 31b97a24-ac1a-4c03-8585-08d8e0185be8 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Mar 2021 20:50:49.7408 (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: MZbkvtg1LT1ulSyTia0U8t3ZV0hGrwWUQWvIkTRUlEG4sgo0ZrpnVAA00EXHUxxTxrABIPAiexSC6ikIBHbG95UmTbqMj4A8EKAjZZ9V2q0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1956 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Boqun Feng Sent: Tuesday, February 23, 2021 6:= 37 PM >=20 > On Thu, Feb 18, 2021 at 03:16:29PM -0800, Michael Kelley wrote: > [...] > > + > > +/* > > + * Get the value of a single VP register. One version > > + * returns just 64 bits and another returns the full 128 bits. > > + * The two versions are separate to avoid complicating the > > + * calling sequence for the more frequently used 64 bit version. > > + */ > > + > > +void __hv_get_vpreg_128(u32 msr, > > + struct hv_get_vp_registers_input *input, > > + struct hv_get_vp_registers_output *res) > > +{ > > + u64 status; > > + > > + input->header.partitionid =3D HV_PARTITION_ID_SELF; > > + input->header.vpindex =3D HV_VP_INDEX_SELF; > > + input->header.inputvtl =3D 0; > > + input->element[0].name0 =3D msr; > > + input->element[0].name1 =3D 0; > > + > > + > > + status =3D hv_do_hypercall( > > + HVCALL_GET_VP_REGISTERS | HV_HYPERCALL_REP_COMP_1, > > + input, res); > > + > > + /* > > + * 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 & HV_HYPERCALL_RESULT_MASK) !=3D HV_STATUS_SUCCESS); > > +} > > + > > +u64 hv_get_vpreg(u32 msr) > > +{ > > + struct hv_get_vp_registers_input *input; > > + struct hv_get_vp_registers_output *output; > > + u64 result; > > + > > + /* > > + * Allocate a power of 2 size so alignment to that size is > > + * guaranteed, since the hypercall input and output areas > > + * must not cross a page boundary. > > + */ > > + input =3D kzalloc(roundup_pow_of_two(sizeof(input->header) + > > + sizeof(input->element[0])), GFP_ATOMIC); > > + output =3D kmalloc(roundup_pow_of_two(sizeof(*output)), GFP_ATOMIC); > > + >=20 > Do we need to BUG_ON(!input || !output)? Or we expect the page fault > (for input being NULL) or the failure of hypercall (for output being > NULL) to tell us the allocation failed? >=20 > Hmm.. think a bit more on this, maybe we'd better retry the allocation > if it failed. Because say we are under memory pressusre, and only have > memory enough for doing one hvcall, and one thread allocates that memory > but gets preempted by another thread trying to do another hvcall: >=20 > > hv_get_vpreg(): > input =3D kzalloc(...); > output =3D kmalloc(...); > > hv_get_vpreg(): > intput =3D kzalloc(...); // allocation fails, but actually if > // we wait for thread 1 to finish its > // hvcall, we can get enough memory. >=20 > , in this case, if thread 2 retried, it might get the enough memory, > therefore there is no need to BUG_ON() on allocation failure. That said, > I don't think this is likely to happen, and there may be better > solutions for this, so maybe we can keep it as it is (assuming that > memory allocation for hvcall never fails) and improve later. >=20 > Regards, > Boqun Having to do these memory allocations in order to make a hypercall results in a lot of messiness. I've just gone back to try again at doing hv_get_vpreg() and hv_get_vpreg_128() as "fast" hypercalls that pass inputs (and outputs) in registers like hv_set_vpreg(). I have it working now, with some tweaks to arm_smccc_1_1_hvc() to allow outputs in a wider range of registers than just X0 thru X3. This wider range of registers is allowed by the SMCCC version 1.2 and 1.3 specs, so hopefully is acceptable. I'll send out a new version using this "fast" hypercall approach that completely avoids all these memory allocation problems. Michael >=20 > > + __hv_get_vpreg_128(msr, input, output); > > + > > + result =3D output->as64.low; > > + kfree(input); > > + kfree(output); > > + return result; > > +} > > +EXPORT_SYMBOL_GPL(hv_get_vpreg); > > + > > +void hv_get_vpreg_128(u32 msr, struct hv_get_vp_registers_output *res) > > +{ > > + struct hv_get_vp_registers_input *input; > > + struct hv_get_vp_registers_output *output; > > + > > + /* > > + * Allocate a power of 2 size so alignment to that size is > > + * guaranteed, since the hypercall input and output areas > > + * must not cross a page boundary. > > + */ > > + input =3D kzalloc(roundup_pow_of_two(sizeof(input->header) + > > + sizeof(input->element[0])), GFP_ATOMIC); > > + output =3D kmalloc(roundup_pow_of_two(sizeof(*output)), GFP_ATOMIC); > > + > > + __hv_get_vpreg_128(msr, input, output); > > + > > + res->as64.low =3D output->as64.low; > > + res->as64.high =3D output->as64.high; > > + kfree(input); > > + kfree(output); > > +} > [...]