From patchwork Wed Oct 5 17:09:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 9363259 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7E708600C8 for ; Wed, 5 Oct 2016 17:17:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69DE428CC6 for ; Wed, 5 Oct 2016 17:17:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EA1D28CCC; Wed, 5 Oct 2016 17:17: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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D516B28CC6 for ; Wed, 5 Oct 2016 17:17:33 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1brpmW-0003ui-F9; Wed, 05 Oct 2016 17:15:00 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1brpmU-0003ub-TE for xen-devel@lists.xenproject.org; Wed, 05 Oct 2016 17:14:58 +0000 Received: from [85.158.143.35] by server-10.bemta-6.messagelabs.com id 56/57-21986-21535F75; Wed, 05 Oct 2016 17:14:58 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrGLMWRWlGSWpSXmKPExsUyZ7p8oK6g6dd wg76FGhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8aFmcsZC+bwVHy/OYexgXEnVxcjF4eQwAQm iZ+vbzBCOJ8ZJZbNfckM4WxglDj79TYbhNPDKDHhZB9QGScHm4CRxNmj08FsEQEdifszz7ODF DELbGSU+HDpMStIQljASmL70xtsIDaLgKrEjtW3wOK8Al4Sn95PAGuWEFCQmPLwPTOEbSjxee NS5gmMPAsYGVYxahSnFpWlFukamuglFWWmZ5TkJmbm6BoamOnlphYXJ6an5iQmFesl5+duYgT 6nwEIdjBe3xhwiFGSg0lJlHcTx9dwIb6k/JTKjMTijPii0pzU4kOMMhwcShK8y42BcoJFqemp FWmZOcBAhElLcPAoifB+AUnzFhck5hZnpkOkTjEqSonzZoMkBEASGaV5cG2w4L/EKCslzMsId IgQT0FqUW5mCar8K0ZxDkYlYd7bIFN4MvNK4Ka/AlrMBLQ4f+kXkMUliQgpqQZGs8kLz9z7Pe 2jzsx/D2KPH2bTWjaPd8cchYL7fd/93uxMnCiizd4otVe7fptJ9H85Xr2Cfd0yj0/uK69pibf 7pn/y4tnLjy63n5xvuLEpP2Zq3aYO7lVTfW+csg316kyNslh0/H+57N/SHb0b2iLj5uguzz37 6R6fadC33YV6qwTZ4qZa+JYXKbEUZyQaajEXFScCAI2O0ux5AgAA X-Env-Sender: boris.ostrovsky@oracle.com X-Msg-Ref: server-14.tower-21.messagelabs.com!1475687695!31271123!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 41476 invoked from network); 5 Oct 2016 17:14:57 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-14.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 5 Oct 2016 17:14:57 -0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u95HEpJk028323 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 5 Oct 2016 17:14:51 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id u95HEorF022061 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 5 Oct 2016 17:14:50 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u95HEi8t028249; Wed, 5 Oct 2016 17:14:49 GMT Received: from ovs104.us.oracle.com (/10.149.76.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 05 Oct 2016 10:14:39 -0700 From: Boris Ostrovsky To: david.vrabel@citrix.com, jgross@suse.com Date: Wed, 5 Oct 2016 13:09:33 -0400 Message-Id: <1475687373-14589-1-git-send-email-boris.ostrovsky@oracle.com> X-Mailer: git-send-email 1.8.3.1 X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: xen-devel@lists.xenproject.org, Boris Ostrovsky , linux-kernel@vger.kernel.org, stable@vger.kernel.org, andrew.cooper3@citrix.com Subject: [Xen-devel] [PATCH] xen/x86: Update topology map for PV VCPUs X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Early during boot topology_update_package_map() computes logical_pkg_ids for all present processors. Later, when processors are brought up, identify_cpu() updates these values based on phys_pkg_id which is a function of initial_apicid. On PV guests the latter may point to a non-existing node, causing logical_pkg_ids to be set to -1. Intel's RAPL uses logical_pkg_id (as topology_logical_package_id()) to index its arrays and therefore in this case will point to index 65535 (since logical_pkg_id is a u16). This could lead to either a crash or may actually access random memory location. As a workaround, we recompute topology during CPU bringup to reset logical_pkg_id to a valid value. (The reason for initial_apicid being bogus is because it is initial_apicid of the processor from which the guest is launched. This value is CPUID(1).EBX[31:24]) Signed-off-by: Boris Ostrovsky Cc: stable@vger.kernel.org --- Copying Andrew for the CPUID part. arch/x86/xen/smp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c index 311acad..9fa27ce 100644 --- a/arch/x86/xen/smp.c +++ b/arch/x86/xen/smp.c @@ -87,6 +87,12 @@ static void cpu_bringup(void) cpu_data(cpu).x86_max_cores = 1; set_cpu_sibling_map(cpu); + /* + * identify_cpu() may have set logical_pkg_id to -1 due + * to incorrect phys_proc_id. Let's re-comupte it. + */ + topology_update_package_map(apic->cpu_present_to_apicid(cpu), cpu); + xen_setup_cpu_clockevents(); notify_cpu_starting(cpu);