From patchwork Wed Oct 26 20:26:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikulas Patocka X-Patchwork-Id: 9398237 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 2FF4B60231 for ; Wed, 26 Oct 2016 20:26:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14CC829DD8 for ; Wed, 26 Oct 2016 20:26:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 077DD29DE3; Wed, 26 Oct 2016 20:26:38 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 9D50B29DD8 for ; Wed, 26 Oct 2016 20:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933618AbcJZU0h (ORCPT ); Wed, 26 Oct 2016 16:26:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33270 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932320AbcJZU0g (ORCPT ); Wed, 26 Oct 2016 16:26:36 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C73C61B83; Wed, 26 Oct 2016 20:26:36 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9QKQZMU002097 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 26 Oct 2016 16:26:36 -0400 Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id u9QKQZDe013012; Wed, 26 Oct 2016 16:26:35 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id u9QKQZ74013008; Wed, 26 Oct 2016 16:26:35 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Wed, 26 Oct 2016 16:26:35 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Jens Axboe cc: Mike Snitzer , Christoph Hellwig , dm-devel@redhat.com, "Alasdair G. Kergon" , linux-block@vger.kernel.org Subject: [PATCH 2/4] brd: extend rcu read sections In-Reply-To: Message-ID: References: <20161021200022.GA12580@redhat.com> <20161024155756.GA48306@redhat.com> <20161025130712.GA12717@infradead.org> <20161025143719.GA51266@redhat.com> <710b07a3-9091-6935-37c4-ea1dcedcab4f@kernel.dk> User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 26 Oct 2016 20:26:36 +0000 (UTC) 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 This patch extends rcu read sections, so that all manipulations of the page and its data are within read sections. This patch is a prerequisite for discarding pages using rcu. Note that the page pointer escapes the rcu section in the function brd_direct_access, however, direct access is not supposed to race with discard. Signed-off-by: Mikulas Patocka --- drivers/block/brd.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-block" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-2.6/drivers/block/brd.c =================================================================== --- linux-2.6.orig/drivers/block/brd.c +++ linux-2.6/drivers/block/brd.c @@ -71,10 +71,8 @@ static struct page *brd_lookup_page(stru * safe here (we don't have total exclusion from radix tree updates * here, only deletes). */ - rcu_read_lock(); idx = sector >> PAGE_SECTORS_SHIFT; /* sector to page index */ page = radix_tree_lookup(&brd->brd_pages, idx); - rcu_read_unlock(); BUG_ON(page && page->index != idx); @@ -92,7 +90,12 @@ static struct page *brd_insert_page(stru struct page *page; gfp_t gfp_flags; + rcu_read_lock(); + page = brd_lookup_page(brd, sector); + + rcu_read_unlock(); + if (page) return page; @@ -151,9 +154,13 @@ static void brd_zero_page(struct brd_dev { struct page *page; + rcu_read_lock(); + page = brd_lookup_page(brd, sector); if (page) clear_highpage(page); + + rcu_read_unlock(); } /* @@ -246,6 +253,8 @@ static void copy_to_brd(struct brd_devic unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT; size_t copy; + rcu_read_lock(); + copy = min_t(size_t, n, PAGE_SIZE - offset); page = brd_lookup_page(brd, sector); BUG_ON(!page); @@ -265,6 +274,8 @@ static void copy_to_brd(struct brd_devic memcpy(dst, src, copy); kunmap_atomic(dst); } + + rcu_read_unlock(); } /* @@ -278,6 +289,8 @@ static void copy_from_brd(void *dst, str unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT; size_t copy; + rcu_read_lock(); + copy = min_t(size_t, n, PAGE_SIZE - offset); page = brd_lookup_page(brd, sector); if (page) { @@ -299,6 +312,8 @@ static void copy_from_brd(void *dst, str } else memset(dst, 0, copy); } + + rcu_read_unlock(); } /*