Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1084274ybl; Wed, 14 Aug 2019 10:26:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwAu+NJSr1u0GS2yUr+8fICyqaO7BgSjL9mC5Sz/3y0xClUu2RD6vLiyE/LEjoy/t75Jujn X-Received: by 2002:a17:90a:2764:: with SMTP id o91mr772863pje.57.1565803581369; Wed, 14 Aug 2019 10:26:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565803581; cv=none; d=google.com; s=arc-20160816; b=qUYWLh/2qFZKTjH3/csS2Js8pG6mil/qkjV1MAbIYeMCn7pzrJG63jkAPeHGfAIJ8A nwiBngGcAeTuO4XRF2Y1PvTufaf6nl5IiLxqWFAgYl710K49s+/0BNskBKl6B+hm58xH +MtizjApdkbzi18luIj3+7x+p6l1k9u/U4W++MhY1YXq5svjEk+A7JnNJUPT6PBQbh/p 7MnRU0akCzj+AkaxREzhQgeEvTMfP2ZOYNQ1j66y2oYwW4epFNHnJxDi0+GCK8X1l02e /r95WoS31qO6FfEbbNDsJde59D1QPQEcHdk9KfCvynTm0NJgjA3Q/VAX72uER7+rnRQl OM1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jhUuNmJf32azQyju3oNAHprWF9ZNHdFGLxdLjIN4+x8=; b=YYpuAEGwX5pOfg+8E+lb3hhos6UI+CIiX2UyMgOkeh9KtwUdrcMvmANPrEFYPjnfz3 imG5dty6xH3SVSTSdSRATG95XPpRAY6yR4GzirdQO0DqaM07M4/gEgh006DPy/2ldtEj fdbhfGUouBKsHoPjrdsyRpcIRAGfYcym2zy8t33t+eVOBTKZWwwvrLvan1vVGlnXIH23 UrrDlu/oXfIiZqwXtOGmG8Zag+5wBkYmWPNOJGf4BLWHFNu9to89uz7wkmCzuhRdpxFO Xl6q5HwV3b0T29x6xx0erkl/slH/AnJU8B9M8OLU0T/0qgsxNI3k94IFn5Mn/PzP196i kZmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Zx/x3+iQ"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7si259215pll.330.2019.08.14.10.26.05; Wed, 14 Aug 2019 10:26:21 -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=@kernel.org header.s=default header.b="Zx/x3+iQ"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729524AbfHNRZc (ORCPT + 99 others); Wed, 14 Aug 2019 13:25:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:54722 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729479AbfHNRFq (ORCPT ); Wed, 14 Aug 2019 13:05:46 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 075FE2084D; Wed, 14 Aug 2019 17:05:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802345; bh=b2zNZyKjcECupHNHtgikwqMvVgIIB0qbiiwmrBACDAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zx/x3+iQPhZuniANkZKN+dMjavidf3MmfERdoJ0WNeMgRQC0ZqK0JiMjiOkcAeqpw FWyxOgughTWwN6HXX2NrHCc1KwRucyD8FaURiEgnf2e7HPZE3WgIf6phaFpJx3BNb0 BxK3GfFVSv920ATqrXcj84B26FHDrUo8/HJTrOd8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oleg Nesterov , Josef Bacik , Jens Axboe , Sasha Levin Subject: [PATCH 5.2 062/144] rq-qos: use a mb for got_token Date: Wed, 14 Aug 2019 19:00:18 +0200 Message-Id: <20190814165802.430179590@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165759.466811854@linuxfoundation.org> References: <20190814165759.466811854@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit ac38297f7038cd5b80d66f8809c7bbf5b70031f3 ] Oleg noticed that our checking of data.got_token is unsafe in the cleanup case, and should really use a memory barrier. Use a wmb on the write side, and a rmb() on the read side. We don't need one in the main loop since we're saved by set_current_state(). Reviewed-by: Oleg Nesterov Signed-off-by: Josef Bacik Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-rq-qos.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/blk-rq-qos.c b/block/blk-rq-qos.c index e3ab75e4df9ea..06d024204f504 100644 --- a/block/blk-rq-qos.c +++ b/block/blk-rq-qos.c @@ -202,6 +202,7 @@ static int rq_qos_wake_function(struct wait_queue_entry *curr, return -1; data->got_token = true; + smp_wmb(); list_del_init(&curr->entry); wake_up_process(data->task); return 1; @@ -245,6 +246,7 @@ void rq_qos_wait(struct rq_wait *rqw, void *private_data, prepare_to_wait_exclusive(&rqw->wait, &data.wq, TASK_UNINTERRUPTIBLE); do { + /* The memory barrier in set_task_state saves us here. */ if (data.got_token) break; if (!has_sleeper && acquire_inflight_cb(rqw, private_data)) { @@ -255,6 +257,7 @@ void rq_qos_wait(struct rq_wait *rqw, void *private_data, * which means we now have two. Put our local token * and wake anyone else potentially waiting for one. */ + smp_rmb(); if (data.got_token) cleanup_cb(rqw, private_data); break; -- 2.20.1