From nobody Fri May 17 08:39:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1663250604; cv=none; d=zohomail.com; s=zohoarc; b=EuUnjaotIZ1mPUhnxNR+tb39686yxIGZcTQXmA8BOYMuB+SkIWMzsUtvdpW/B+J+quXxti1Fc6qiZe/BfijIoVx+bCH06T79J96+4MMhg4FCQ5A6leYPB/BzatQXKzXRvSbxugqUUirryfBTDmGS5yF2rLVhdjZETThDKJgK15w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663250604; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=pZvTQlV9TmWAcRSelXEpMBHiiGqGP/gBmTcF40FbwhM=; b=V7BH4S+B1QjV/63eeeu3NhX1EVW7IdZ+dNi3UqVNqRCDZa+q2yDOfcJ/tkRgjX0SV6q4A4WPk0UNZrizwgUD23KDJaaCWU86kA9t9nKvzYwG0wGOrmWZ674d4+2DlsEN2xzsKL96wK4LKo9YXiZ1COPPOrACoAowirAkmSGyfmQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1663250603926486.1534515912067; Thu, 15 Sep 2022 07:03:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.407393.649899 (Exim 4.92) (envelope-from ) id 1oYpRj-00054N-Da; Thu, 15 Sep 2022 14:02:27 +0000 Received: by outflank-mailman (output) from mailman id 407393.649899; Thu, 15 Sep 2022 14:02:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oYpRj-00054G-Ak; Thu, 15 Sep 2022 14:02:27 +0000 Received: by outflank-mailman (input) for mailman id 407393; Thu, 15 Sep 2022 14:02:25 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oYpRh-00054A-HJ for xen-devel@lists.xenproject.org; Thu, 15 Sep 2022 14:02:25 +0000 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0336e94c-34ff-11ed-9761-273f2230c3a0; Thu, 15 Sep 2022 16:02:21 +0200 (CEST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2022 07:02:12 -0700 Received: from tlengyel-mobl3.amr.corp.intel.com (HELO ubuntu.localdomain) ([10.209.176.180]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2022 07:02:11 -0700 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0336e94c-34ff-11ed-9761-273f2230c3a0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663250542; x=1694786542; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=nm8d2LCDVjaNR+AJEi3DoLWSkOMQhFvCTPiTWL4iOaU=; b=mhJOYPgXKLNASBATZypDeG4Vw2L7sVtbQHbWY8DM6K2pXz9Bn62CabrB oSyp07pubq2o/jLpzg4Vcb9PTdwWIf2wuNMPSm5R1/SWCBV26C+9A7Unx dvYxDy+rGDaZLeX6cBkxuVwhsv3JVP6pAOxWcfX9uyqRzX37/ZIcbo6U1 0SNMwV7zqi7jf/yA8p2yqESocPb9JTuSmX6S8HzfSM6jfLqCQe+TW6LvA /2EYHRhc/g9kVcTUtPp+EiEdehGsSYRu/S06zu9dcwtkEtZ7DP07H18tG Dw/++cl3xl+Px7ooSiuXboHVDCrBjZOS76HN+zK8G4ZnY70p+5BSmBCh2 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10470"; a="324981275" X-IronPort-AV: E=Sophos;i="5.93,318,1654585200"; d="scan'208";a="324981275" X-IronPort-AV: E=Sophos;i="5.93,318,1654585200"; d="scan'208";a="685735205" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Cc: Tamas K Lengyel , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH] x86/vpmu: fix race-condition in vpmu_load Date: Thu, 15 Sep 2022 10:01:59 -0400 Message-Id: <8294476a707d7f20799a40479cc0bf9a1cf07673.1663249988.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1663250606118100001 Content-Type: text/plain; charset="utf-8" While experimenting with the vPMU subsystem an ASSERT failure was observed in vmx_find_msr because the vcpu_runnable state was true. The root cause of the bug appears to be the fact that the vPMU subsystem doesn't save its state on context_switch. The vpmu_load function will attem= pt to gather the PMU state if its still loaded two different ways: 1. if the current pcpu is not where the vcpu ran before doing a remote = save 2. if the current pcpu had another vcpu active before doing a local save However, in case the prev vcpu is being rescheduled on another pcpu its sta= te has already changed and vcpu_runnable is returning true, thus #2 will trip = the ASSERT. The only way to avoid this race condition is to make sure the prev vcpu is paused while being checked and its context saved. Once the prev vcpu is resumed and does #1 it will find its state already saved. Signed-off-by: Tamas K Lengyel --- xen/arch/x86/cpu/vpmu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xen/arch/x86/cpu/vpmu.c b/xen/arch/x86/cpu/vpmu.c index cacc24a30f..076c2e5a8d 100644 --- a/xen/arch/x86/cpu/vpmu.c +++ b/xen/arch/x86/cpu/vpmu.c @@ -419,8 +419,10 @@ int vpmu_load(struct vcpu *v, bool_t from_guest) vpmu =3D vcpu_vpmu(prev); =20 /* Someone ran here before us */ + vcpu_pause(prev); vpmu_save_force(prev); vpmu_reset(vpmu, VPMU_CONTEXT_LOADED); + vcpu_unpause(prev); =20 vpmu =3D vcpu_vpmu(v); } --=20 2.34.1