Received: by 10.192.165.148 with SMTP id m20csp345972imm; Thu, 26 Apr 2018 23:13:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrKoXqgI1SPJu5E0hesitJy/2yumJnB/kfukD5Kk/uCcx62L3c2uibbCdqPcno8S8I/Jl+H X-Received: by 10.98.207.67 with SMTP id b64mr1019380pfg.248.1524809586207; Thu, 26 Apr 2018 23:13:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524809586; cv=none; d=google.com; s=arc-20160816; b=w8bBD2hbUSIQflxHtr/r1VhmNjZqC545l3G0cG7a7M7OtUYghdQVEB7icdt9jQMNa/ K/cifvk4g/szrmTFG2K83c+mtayour4FUSXJgFvJIvvTgVhGASD6L7Z/Cq+tGXs1cK4i zIETHbO7KnHYcp/0eQV2b1lfymChTuj4Q+pPqwX8aORaIOBQYvWyCbeHYyk0McoZOYqI kDfiysNKQhnu8Trfx25XEzqW085BFW7IE++9aym01xwGsbgk1bkiJW9ETzZzl1Ep3lpa xfXAq04XZDn0574+xbZktYp4arZ/w1D5oEFyBvL568VmR+JZtfbwCC+ull3/UqMVTqTq QnnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=AF9MMynmxi11Ck66W4Q1itb4blbR1n0htQMYG7tQw24=; b=lJsPoX+aVNk0pSnOaxwinShASFiFqF3Mk8368zJqAoB/CulK5S+ufuo1IbPUH1uAOC NUF7Nsz7MbgosSv4DHOt28OZQQrR2Pp8FVpiWv1L8IF4eRlUlc1jczqsTUXQUm+laM93 RJRdW0VfVCKKM0wzChXcfpOoHMre7ouQcppxXGsUqQPzjH/VCp/IRYtzg2D+sj9UZmuu i3/nqhP0PLEjl3PJvdID/OSSyVVMq0g8RDwrXOmPKzXM89PacGYUB16V2OUR2FsFfYPL xguA20j25WZ6N/7Ky+BeSTewZtmRaY7/vNxLOrykHSwDJfgMWagbIAqbaLbXR9BekHdu CPVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=fuPvK11F; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r12si640827pfd.193.2018.04.26.23.12.51; Thu, 26 Apr 2018 23:13:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=fuPvK11F; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757420AbeD0GLW (ORCPT + 99 others); Fri, 27 Apr 2018 02:11:22 -0400 Received: from mail-by2nam03on0091.outbound.protection.outlook.com ([104.47.42.91]:10688 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751348AbeD0GLU (ORCPT ); Fri, 27 Apr 2018 02:11:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=AF9MMynmxi11Ck66W4Q1itb4blbR1n0htQMYG7tQw24=; b=fuPvK11FKUQe1y7gwzhCCcNHUS9HA0pmbqeQPqFDOaDItzMrV1bSwaxBbuEmuSrExr6f9gXyCJc/2O3JpYdG0wgSLw6lAhzIF/ij1Vc9CJq/l4oHcCiLyJ6bvoSih9OSctE8QhxLdMVGllotJpq3cPoxPqChCbsTBEd7qxGqw2c= Received: from MW2PR2101MB1113.namprd21.prod.outlook.com (52.132.149.30) by MW2PR2101MB1065.namprd21.prod.outlook.com (52.132.149.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.735.4; Fri, 27 Apr 2018 06:11:17 +0000 Received: from MW2PR2101MB1113.namprd21.prod.outlook.com ([fe80::25f2:4462:8810:c22d]) by MW2PR2101MB1113.namprd21.prod.outlook.com ([fe80::25f2:4462:8810:c22d%4]) with mapi id 15.20.0735.005; Fri, 27 Apr 2018 06:11:17 +0000 From: KY Srinivasan To: Thomas Gleixner CC: "x86@kernel.org" , "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , "devel@linuxdriverproject.org" , "olaf@aepfle.de" , "apw@canonical.com" , "jasowang@redhat.com" , "hpa@zytor.com" , Stephen Hemminger , "Michael Kelley (EOSG)" , "vkuznets@redhat.com" Subject: RE: [PATCH 2/5] X86: Hyper-V: Enable IPI enlightenments Thread-Topic: [PATCH 2/5] X86: Hyper-V: Enable IPI enlightenments Thread-Index: AQHT3MEu4uYWJdgpmkipM8S1SvacPaQTnMUAgACBqNA= Date: Fri, 27 Apr 2018 06:11:17 +0000 Message-ID: References: <20180425181110.8683-1-kys@linuxonhyperv.com> <20180425181250.8740-1-kys@linuxonhyperv.com> <20180425181250.8740-2-kys@linuxonhyperv.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [2601:600:a280:b50:3d34:9b63:3fe:d485] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MW2PR2101MB1065;7:H0CupVo9XfVx0Q5CgXfEU2aloPE/RSXEBchyYP1IcuVromCvTCDW93uHLMcn8cx9dWxmfVlUxDFb+1pzz+tSvNuXjQD/UuIK8CxgfEDAADZQO9HnIHJ05jXlb/mtkLC8q5yvZU99p8qFijem0wAi/kS1Qea8YsGo+jtL+SvC0DRbNiUcKZYgSEXNxmUaUJkMKFgNjy1XnuOpb2A1UAy4KA+vKdoiaPRuNBS79NO0byvzaVB3soPC3V7Rz7twljs2;20:Bv/kWN+ZRI7gsez5FA8x3+FkDSWEVc/vG6iH//w1ZrR3qg1hrps6IJ40jpII/gO73cOOUNEVdJnG3AWN9MZm3w/0AnX8BMQPDcZTAj68OCsWa8qmhNDhUzwnVrznYXHdFFd0FSc8bQFvP893t4RvdUHOPnEkpWnXQRd5is1G94o= x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(48565401081)(2017052603328)(7193020);SRVR:MW2PR2101MB1065; x-ms-traffictypediagnostic: MW2PR2101MB1065: authentication-results: spf=none (sender IP is ) smtp.mailfrom=kys@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(209352067349851)(9452136761055)(198206253151910); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(3231232)(944501410)(52105095)(10201501046)(93006095)(93001095)(6055026)(6041310)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011);SRVR:MW2PR2101MB1065;BCL:0;PCL:0;RULEID:;SRVR:MW2PR2101MB1065; x-forefront-prvs: 0655F9F006 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(396003)(39380400002)(376002)(346002)(366004)(13464003)(189003)(199004)(11346002)(81166006)(97736004)(81156014)(6116002)(476003)(3280700002)(59450400001)(46003)(446003)(6436002)(2906002)(486006)(8936002)(8676002)(5250100002)(55016002)(2900100001)(186003)(33656002)(9686003)(68736007)(6246003)(10090500001)(3660700001)(14454004)(102836004)(4326008)(8990500004)(54906003)(25786009)(99286004)(305945005)(316002)(5660300001)(76176011)(106356001)(22452003)(93886005)(6506007)(7416002)(478600001)(86362001)(86612001)(10290500003)(74316002)(53936002)(7736002)(6916009)(105586002)(7696005)(53546011)(229853002);DIR:OUT;SFP:1102;SCL:1;SRVR:MW2PR2101MB1065;H:MW2PR2101MB1113.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-microsoft-antispam-message-info: FJCMcFGM17yhZ5r7FZg/qtJ5afVYyxJ3V+j6UkH2vkDugQtnyIXXvfrM/N9Dut+U8k2M8A8wvo47DPMiHX91x8VjKP5ek9Hdp7Pg1dTuSDC7sOpTGSrDNIK+GspYaYtEztrvkrq11lGvBPYZQdPBX+Sn8fbXM2HnBfjKCDdldUbIhWiqMfJwYWXbnkvY9YVr spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 60d109e8-9715-470c-e8f9-08d5ac05b050 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 60d109e8-9715-470c-e8f9-08d5ac05b050 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Apr 2018 06:11:17.3568 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR2101MB1065 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: Thomas Gleixner > Sent: Thursday, April 26, 2018 3:09 PM > To: KY Srinivasan > Cc: x86@kernel.org; gregkh@linuxfoundation.org; linux- > kernel@vger.kernel.org; devel@linuxdriverproject.org; olaf@aepfle.de; > apw@canonical.com; jasowang@redhat.com; hpa@zytor.com; Stephen > Hemminger ; Michael Kelley (EOSG) > ; vkuznets@redhat.com > Subject: Re: [PATCH 2/5] X86: Hyper-V: Enable IPI enlightenments >=20 > On Wed, 25 Apr 2018, kys@linuxonhyperv.com wrote: > > +static int __send_ipi_mask(const struct cpumask *mask, int vector) > > +{ > > + int cur_cpu, vcpu; > > + struct ipi_arg_non_ex **arg; > > + struct ipi_arg_non_ex *ipi_arg; > > + int ret =3D 1; >=20 > So this indicates whether __send_ipi_mask() can send to @mask or not. So > please make it a bool and let it return false when it does not work, true > otherwise. If you had used -Exxxx then it would have been more obvious, > but > this is really a boolean decision. Agreed. >=20 > > + unsigned long flags; > > + > > + if (cpumask_empty(mask)) > > + return 0; > > + > > + if (!hv_hypercall_pg) > > + return ret; > > + > > + if ((vector < HV_IPI_LOW_VECTOR) || (vector > > HV_IPI_HIGH_VECTOR)) > > + return ret; > > + > > + local_irq_save(flags); > > + arg =3D (struct ipi_arg_non_ex > **)this_cpu_ptr(hyperv_pcpu_input_arg); > > + > > + ipi_arg =3D *arg; > > + if (unlikely(!ipi_arg)) > > + goto ipi_mask_done; > > + > > + >=20 > Stray newline >=20 > > + ipi_arg->vector =3D vector; > > + ipi_arg->reserved =3D 0; > > + ipi_arg->cpu_mask =3D 0; > > + > > + for_each_cpu(cur_cpu, mask) { > > + vcpu =3D hv_cpu_number_to_vp_number(cur_cpu); > > + if (vcpu >=3D 64) > > + goto ipi_mask_done; >=20 > This is completely magic and deserves a comment. >=20 > > + > > + __set_bit(vcpu, (unsigned long *)&ipi_arg->cpu_mask); > > + } > > + > > + ret =3D hv_do_hypercall(HVCALL_SEND_IPI, ipi_arg, NULL); > > + > > +ipi_mask_done: > > + local_irq_restore(flags); > > + return ret; > > +} >=20 > .... >=20 > > static int hv_cpu_init(unsigned int cpu) > > { > > u64 msr_vp_index; > > struct hv_vp_assist_page **hvp =3D > &hv_vp_assist_page[smp_processor_id()]; > > + void **input_arg; > > + > > + input_arg =3D (void **)this_cpu_ptr(hyperv_pcpu_input_arg); > > + *input_arg =3D page_address(alloc_page(GFP_ATOMIC)); >=20 > This is called from the cpu hotplug thread and there is no need for an > atomic allocation. Please use GFP_KERNEL. >=20 > > hv_get_vp_index(msr_vp_index); > > > > @@ -217,6 +224,10 @@ static int hv_cpu_die(unsigned int cpu) > > { > > struct hv_reenlightenment_control re_ctrl; > > unsigned int new_cpu; > > + void **input_arg; > > + > > + input_arg =3D (void **)this_cpu_ptr(hyperv_pcpu_input_arg); > > + free_page((unsigned long)*input_arg); >=20 > Hrm. Again this is called from the CPU hotplug thread when the cou is abo= ut > to go down. But you can be scheduled out after free() and before disablin= g > the assist thing below and the pointer persist. There is no guarantee tha= t > nothing sends an IPI anymore after this point. >=20 > So you have two options here: >=20 > 1) Disable interrupts, get the pointer, set the per cpu pointer to NULL= , > reenable interruots and free the page I will implement this approach. >=20 > 2) Keep the page around and check for it in the CPU UP path and avoid t= he > allocation when the CPU comes online again. >=20 > > if (hv_vp_assist_page && hv_vp_assist_page[cpu]) > > wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, 0); > > @@ -260,6 +271,12 @@ void __init hyperv_init(void) > > if ((ms_hyperv.features & required_msrs) !=3D required_msrs) > > return; > > > > + /* Allocate the per-CPU state for the hypercall input arg */ > > + hyperv_pcpu_input_arg =3D alloc_percpu(void *); > > + > > + if (hyperv_pcpu_input_arg =3D=3D NULL) > > + return; >=20 > Huch. When that allocation fails, you return and ignore the rest of the > function which has been there before. Weird decision. I should have explained this. Failure of this allocation means that we woul= d not have the per-cpu hypercall input page which in turn would mean that we would not be = able to invoke any hypercalls.=20 Regards, K. Y