From patchwork Wed Jan 18 19:55:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9524647 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 E9FBF60113 for ; Wed, 18 Jan 2017 19:56:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D112D28629 for ; Wed, 18 Jan 2017 19:56:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C23792862C; Wed, 18 Jan 2017 19:56:53 +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=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 558EA28629 for ; Wed, 18 Jan 2017 19:56:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751423AbdART4w (ORCPT ); Wed, 18 Jan 2017 14:56:52 -0500 Received: from mail-pf0-f179.google.com ([209.85.192.179]:36478 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751820AbdART4u (ORCPT ); Wed, 18 Jan 2017 14:56:50 -0500 Received: by mail-pf0-f179.google.com with SMTP id 189so6665003pfu.3 for ; Wed, 18 Jan 2017 11:55:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=DI6uBs/JfuxBBSI7Ig9DB/+bmQaCxInW1ZvAoCuzIWM=; b=fpbz2le1ykc4q3B8s6ulGAI4rdYNaibxRn5Z0hMeuST2K22L/2/pkZ64IzwzWGvfzX IzJY/TlR7NqnamuvdtjugC3P5LrF0E9TXUrX+K1SeK5Phhs620hGqnkJfSEjF8oCibd/ tUtAkhyPWhkOrNFMjQuZs6SwFtkWE3qjP1Ds01jTG5EWvTYQi5yomWiud0Z+qHmP1SGM qDw9uhMojUnBL4xn1D0KgZMKtK0GZLoUwMxnv/DMna0j4roACVLpvQlmYIoRfp/SIHZ9 WQBh7kUQ16iQJFsQQlcFoiiDxGMRPiyLZW6sv3wU5Bw2+3PP1DjGu85ARt76LUMjmHzF Axpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=DI6uBs/JfuxBBSI7Ig9DB/+bmQaCxInW1ZvAoCuzIWM=; b=SKeCHG42d9PD+skaJuK4oPgBvGMPbeYfJSOf4xJ5g3Hr6fzDtRepiq/nCJ41KFOqlF YlMWinDRIglp+Fp5LlFkPQgSLa+BUMCvWV6q67JcB/kg2oijaPQ1tgFpVod9RdtmRsRj 8cl2in3tDmPa72gI9k8Ke4uDoPF7m34QB2+Bs31H4ervF9f3eI/KxIgiyMPpGYwVBRtY Ss379Yw+2/XoXmDYIoSX0hLr7r3g+c45bMsXysUSHe2nfimQy6bwz9o2F4zeOYUYE3H0 7mC/Y3F0CNiJHgfGqXDBgs53TKOkLwYHi6oNftRoSsvxUOECYQajY0wgzNkZUMWLzmaT R+Tw== X-Gm-Message-State: AIkVDXKZRmB+Twuj4mkV4Ggm/226UnNMIGIx95BKHZnvMlttljAfFWkhgzK9yAvdHwLZwyMV X-Received: by 10.98.13.203 with SMTP id 72mr5671965pfn.64.1484769351669; Wed, 18 Jan 2017 11:55:51 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:200::b:f7ec]) by smtp.gmail.com with ESMTPSA id t14sm2596424pfk.85.2017.01.18.11.55.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jan 2017 11:55:51 -0800 (PST) From: Omar Sandoval To: Jens Axboe , linux-block@vger.kernel.org Cc: Martin Raiber , kernel-team@fb.com Subject: [PATCH 1/2] sbitmap: use smp_mb__after_atomic() in sbq_wake_up() Date: Wed, 18 Jan 2017 11:55:21 -0800 Message-Id: X-Mailer: git-send-email 2.11.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval We always do an atomic clear_bit() right before we call sbq_wake_up(), so we can use smp_mb__after_atomic(). While we're here, comment the memory barriers in here a little more. Signed-off-by: Omar Sandoval --- lib/sbitmap.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/sbitmap.c b/lib/sbitmap.c index 2cecf05c82fd..df4e472df8a3 100644 --- a/lib/sbitmap.c +++ b/lib/sbitmap.c @@ -299,8 +299,14 @@ static void sbq_wake_up(struct sbitmap_queue *sbq) struct sbq_wait_state *ws; int wait_cnt; - /* Ensure that the wait list checks occur after clear_bit(). */ - smp_mb(); + /* + * Pairs with the memory barrier in set_current_state() to ensure the + * proper ordering of clear_bit()/waitqueue_active() in the waker and + * test_and_set_bit()/prepare_to_wait()/finish_wait() in the waiter. See + * the comment on waitqueue_active(). This is __after_atomic because we + * just did clear_bit() in the caller. + */ + smp_mb__after_atomic(); ws = sbq_wake_ptr(sbq); if (!ws) @@ -331,7 +337,8 @@ void sbitmap_queue_wake_all(struct sbitmap_queue *sbq) int i, wake_index; /* - * Make sure all changes prior to this are visible from other CPUs. + * Pairs with the memory barrier in set_current_state() like in + * sbq_wake_up(). */ smp_mb(); wake_index = atomic_read(&sbq->wake_index);