From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F3F5C433DF for ; Mon, 19 Oct 2020 02:46:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A05D52231B for ; Mon, 19 Oct 2020 02:46:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TADDJSnS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A05D52231B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C09DD6B005D; Sun, 18 Oct 2020 22:46:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B91F56B0062; Sun, 18 Oct 2020 22:46:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A80946B0068; Sun, 18 Oct 2020 22:46:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0223.hostedemail.com [216.40.44.223]) by kanga.kvack.org (Postfix) with ESMTP id 72D7E6B005D for ; Sun, 18 Oct 2020 22:46:06 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0A7F0180AD806 for ; Mon, 19 Oct 2020 02:46:06 +0000 (UTC) X-FDA: 77387135532.06.wrist75_5011bc727233 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id DED18100683C2 for ; Mon, 19 Oct 2020 02:46:05 +0000 (UTC) X-HE-Tag: wrist75_5011bc727233 X-Filterd-Recvd-Size: 5973 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Mon, 19 Oct 2020 02:46:05 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id t9so9589683wrq.11 for ; Sun, 18 Oct 2020 19:46:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=7V26HkKgGmmx148aRxJJhCJa2HTwJxofxiia5WgrIJ0=; b=TADDJSnS6084IlUlij7J+1XwQyf0CDw/res6Hws/81NlI4OPl3m0Y9jwWOvCC3HYy8 84SuQ3b8ib1pztQo6M7HZyd+LCXS1yQjqDiqgdBdxP1C+ti3xq8BR1zn3FHdS7rOYQKR njedkoe5I1akQe/L/2Xs1pqtyRuer6fEUwo/Q4/KUCUT7Lqx8LLE3vNvT8J3mEuCoVJ9 0hPkPbxDLujM7CdhDctec4OX6BCj2DW6fBSG5FjOuLbVSQaoMft8JipWh+8hTeUQVswo eLxl+sZVp0ueEjBaTgBu4nCXzH8ZjX+2K15Pf6dT67an7TMXlaVOv4SdNpXBZ+AXNN9t ncxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=7V26HkKgGmmx148aRxJJhCJa2HTwJxofxiia5WgrIJ0=; b=BSi9Dc7VjvaJfEYe/cY3ZuRjsvrEt+y063oFIk7+fwDl/SPgwGN1o4t2a3ywYvLFl7 UDd1ggcGbyfYHcFcPY2Bk1VdeVXVyqtYhNlATjnK/b+t5/+H7G0i03VDC4hFb4QNGEvS Z9/324DGmq5h2ImqBJUiHn+woKMYqx36PZ2ZqOq3rhCGs6GT6NpSVzFr/BRwv77Jxut0 pTp49LFizbEzDYt2iyewAtvQV4JTIKKrwMQ3+cGIQBY5G0wFcFgeDpqPbOWZsHG4Oz7U goloF4F3gHQJHATdv1ZtUjeq5jJfPX4wER9nUo7tt2PRuLjNBaeJEltxbmEPV0BmOaEs qwSQ== X-Gm-Message-State: AOAM532bGYRB/bzak1jRbV77UDCi6Qu5F1/LzsW1ExfWWMsy6ALFVJ18 apVoCc2dpXVOETL6Eo5JneI= X-Google-Smtp-Source: ABdhPJw5OtqTNTNZ7PeRrETTk9CHvwy7bEQaxGCgi/7l3VXUpCcBjOJT3n86PD6BRx/fjyL7f5ThcA== X-Received: by 2002:adf:8484:: with SMTP id 4mr17741191wrg.334.1603075564377; Sun, 18 Oct 2020 19:46:04 -0700 (PDT) Received: from homer.simpson.net ([185.191.217.9]) by smtp.googlemail.com with ESMTPSA id c130sm15330601wma.1.2020.10.18.19.46.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 19:46:03 -0700 (PDT) Message-ID: <198af4a540faf0c11869894a2f8239cf50701b15.camel@gmail.com> Subject: Re: [PATCH v3 7/7] zram: Use local lock to protect per-CPU data From: Mike Galbraith To: Yu Zhao , Sebastian Andrzej Siewior Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Steven Rostedt , Will Deacon , Thomas Gleixner , "Paul E . McKenney" , Linus Torvalds , Matthew Wilcox , Minchan Kim , Nitin Gupta , Sergey Senozhatsky , linux-mm@kvack.org Date: Mon, 19 Oct 2020 04:46:02 +0200 In-Reply-To: <20201019015252.GA61728@google.com> References: <20200527201119.1692513-1-bigeasy@linutronix.de> <20200527201119.1692513-8-bigeasy@linutronix.de> <20201019015252.GA61728@google.com> Content-Type: text/plain; charset="ISO-8859-15" User-Agent: Evolution 3.34.4 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sun, 2020-10-18 at 19:52 -0600, Yu Zhao wrote: > On Wed, May 27, 2020 at 10:11:19PM +0200, Sebastian Andrzej Siewior wrote: > > From: Mike Galbraith > > > > The zcomp driver uses per-CPU compression. The per-CPU data pointer is > > acquired with get_cpu_ptr() which implicitly disables preemption. > > It allocates memory inside the preempt disabled region which conflicts > > with the PREEMPT_RT semantics. > > > > Replace the implicit preemption control with an explicit local lock. > > This allows RT kernels to substitute it with a real per CPU lock, which > > serializes the access but keeps the code section preemptible. On non RT > > kernels this maps to preempt_disable() as before, i.e. no functional > > change. > > Hi, > > This change seems to have introduced a potential deadlock. Can you > please take a look? Hm, looks like I'm getting undeserved credit for uncovering a locking bug. In reality, Sebastian was generous with attribution of derivative work, so he should ge credit.. and it looks like peterz fixed it. Date: Fri, 16 Oct 2020 14:40:09 +0200 From: Peter Zijlstra --- diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 9100ac36670a..c1e2c2e1cde8 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1216,10 +1216,11 @@ static void zram_free_page(struct zram *zram, size_t index) static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, struct bio *bio, bool partial_io) { - int ret; + struct zcomp_strm *zstrm; unsigned long handle; unsigned int size; void *src, *dst; + int ret; zram_slot_lock(zram, index); if (zram_test_flag(zram, index, ZRAM_WB)) { @@ -1250,6 +1251,9 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, size = zram_get_obj_size(zram, index); + if (size != PAGE_SIZE) + zstrm = zcomp_stream_get(zram->comp); + src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); if (size == PAGE_SIZE) { dst = kmap_atomic(page); @@ -1257,8 +1261,6 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, kunmap_atomic(dst); ret = 0; } else { - struct zcomp_strm *zstrm = zcomp_stream_get(zram->comp); - dst = kmap_atomic(page); ret = zcomp_decompress(zstrm, src, size, dst); kunmap_atomic(dst);