From nobody Fri Apr 26 18:41:35 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=fail; 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=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1596021258; cv=none; d=zohomail.com; s=zohoarc; b=mUUOLc2EeAPYXDy2cejDvjZw/fji66U+u7/RHOjY3DrN+EyA/pP+rHXt1uoISA0kfrvtebQrUNHNw+T/Q04vs5bvQUb0D1is9vfz1ShRKPAxryLd0BgRGI1jXR2XFd9eL5oc45NcJ1/fF8RDWThbLti6vX4xowdT70VwflAH2Tk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596021258; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=5GFD7JLl8XTPwCWPAVkrrZr/SzFSGGygRF6lvqrPRbY=; b=YlfN4VZeU4BkpzmbCEeKtkdBkQR8U8AknhOsLxXtD/GR5PhDR31CiW+YN1M7PL4IlfPG7G6IC6eLH+Nxph8yU/qDcbigZNdAhi5YYiMd6nCvynqwuZi2h09ErgM2wxLwo/IRjzLhUJAvC0agSW+c7I/ptTWYEWyIrSuIRjD3BT8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1596021258492130.25714305807696; Wed, 29 Jul 2020 04:14:18 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k0k1x-0005MF-48; Wed, 29 Jul 2020 11:13:53 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k0k1v-0005MA-P0 for xen-devel@lists.xenproject.org; Wed, 29 Jul 2020 11:13:51 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 93e4c694-d18c-11ea-a9a4-12813bfff9fa; Wed, 29 Jul 2020 11:13:50 +0000 (UTC) X-Inumbo-ID: 93e4c694-d18c-11ea-a9a4-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1596021230; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=ltCUzbEZ2+9uj7fZHbzDVa+LQOjGccZT024Lno+r4Hw=; b=IgGC2XarEt7HNnPZAa5DdyyU/e8EnXYUmm0UIy+STiLQ5OqBW74USwbM SZ+HKQcCgtkXxp+dCsI/N1JCbEkOwZlInKGtCjzikQ5k8wcpPogzr0Y1P FBeGmu23mJ3sXAAA486YlvlnyF6gkOJLwJACSngFQdeZTn3Wnwj/3HHSq k=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: nvPtda8nmZUyePAFIgJ5GzuHipQyvX5GSfEe328YF4FLzBeOV5SLGXjhTpTIuJmZHkv0sV3Scj hVakrvywlKyKXFiSRJAGQmaXr7Fs87YSYfUz2bWrPcsWkET1G/fn+N4ZDI7geZzn9WkanZxY/9 mBlwDlY18mHV6E+CTT1ZQR/mzdg+zOwgxtvshZbWPijKXDN9KGdcAzL7AZBdevwx7h27J1CZoy XJEM7Xk3vGua0kXu1/u2xMqZW3CNnJPc2f8dyMoGpXHmdi8D35Utj2E0Mjs2fpDPYiCu56BJjN h+4= X-SBRS: 2.7 X-MesageID: 23442515 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.75,410,1589256000"; d="scan'208";a="23442515" From: Roger Pau Monne To: Subject: [PATCH] xen/spinlock: move debug helpers inside the locked regions Date: Wed, 29 Jul 2020 13:13:30 +0200 Message-ID: <20200729111330.64549-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Igor Druzhinin , Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Ian Jackson , George Dunlap , Jan Beulich , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Debug helpers such as lock profiling or the invariant pCPU assertions must strictly be performed inside the exclusive locked region, or else races might happen. Note the issue was not strictly introduced by the pointed commit in the Fixes tag, since lock stats where already incremented before the barrier, but that commit made it more apparent as manipulating the cpu field could happen outside of the locked regions and thus trigger the BUG_ON. This is only enabled on debug builds, and thus releases are not affected. Fixes: 80cba391a35 ('spinlocks: in debug builds store cpu holding the lock') Reported-by: Igor Druzhinin Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Julien Grall --- xen/common/spinlock.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 17f4519fc7..ce3106e2d3 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -170,9 +170,9 @@ void inline _spin_lock_cb(spinlock_t *lock, void (*cb)(= void *), void *data) cb(data); arch_lock_relax(); } + arch_lock_acquire_barrier(); got_lock(&lock->debug); LOCK_PROFILE_GOT; - arch_lock_acquire_barrier(); } =20 void _spin_lock(spinlock_t *lock) @@ -198,9 +198,9 @@ unsigned long _spin_lock_irqsave(spinlock_t *lock) =20 void _spin_unlock(spinlock_t *lock) { - arch_lock_release_barrier(); LOCK_PROFILE_REL; rel_lock(&lock->debug); + arch_lock_release_barrier(); add_sized(&lock->tickets.head, 1); arch_lock_signal(); preempt_enable(); @@ -249,15 +249,15 @@ int _spin_trylock(spinlock_t *lock) preempt_enable(); return 0; } + /* + * cmpxchg() is a full barrier so no need for an + * arch_lock_acquire_barrier(). + */ got_lock(&lock->debug); #ifdef CONFIG_DEBUG_LOCK_PROFILE if (lock->profile) lock->profile->time_locked =3D NOW(); #endif - /* - * cmpxchg() is a full barrier so no need for an - * arch_lock_acquire_barrier(). - */ return 1; } =20 --=20 2.27.0