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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 B126EC11F68 for ; Wed, 30 Jun 2021 09:42:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5494461D0B for ; Wed, 30 Jun 2021 09:42:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5494461D0B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B005F8D019B; Wed, 30 Jun 2021 05:42:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8A168D019C; Wed, 30 Jun 2021 05:42:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8DABB8D019B; Wed, 30 Jun 2021 05:42:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 600C88D017A for ; Wed, 30 Jun 2021 05:42:45 -0400 (EDT) Received: from smtpin34.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2CF541829805C for ; Wed, 30 Jun 2021 09:42:45 +0000 (UTC) X-FDA: 78309900690.34.4BEEAEB Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf07.hostedemail.com (Postfix) with ESMTP id A254510000B5 for ; Wed, 30 Jun 2021 09:42:44 +0000 (UTC) Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 53DDC2223B; Wed, 30 Jun 2021 09:42:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1625046163; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=A3MNoSLnXHqAMX3jqPxgl/njzLp8ToXYl4dULk/puSI=; b=XfyYwT5Qi1Ku2shGh7rKtTc077cKu4YiKz6Hkm6eA5BM9h8Cyz80261+7bD1msJ3HqlCN7 9Rb8/wORqTX98zfvCfUhm0zX0bJ00n3IFJkAXKuzZOyEKD9nIrJ9VE1PILPZ0Tsy1TPzcG Qz0OZjdAnNscjQTuOi71viTOLYCvnGE= Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 2044311906; Wed, 30 Jun 2021 09:42:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1625046163; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=A3MNoSLnXHqAMX3jqPxgl/njzLp8ToXYl4dULk/puSI=; b=XfyYwT5Qi1Ku2shGh7rKtTc077cKu4YiKz6Hkm6eA5BM9h8Cyz80261+7bD1msJ3HqlCN7 9Rb8/wORqTX98zfvCfUhm0zX0bJ00n3IFJkAXKuzZOyEKD9nIrJ9VE1PILPZ0Tsy1TPzcG Qz0OZjdAnNscjQTuOi71viTOLYCvnGE= Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id jC7GBpM83GD1bAAALh3uQQ (envelope-from ); Wed, 30 Jun 2021 09:42:43 +0000 Date: Wed, 30 Jun 2021 11:42:41 +0200 From: Michal =?iso-8859-1?Q?Koutn=FD?= To: Dan Schatzberg Cc: Andrew Morton , "open list:BLOCK LAYER" , open list , "open list:CONTROL GROUP (CGROUP)" , "open list:MEMORY MANAGEMENT" , Johannes Weiner , Jens Axboe Subject: Re: [PATCH 3/3] loop: Charge i/o to mem and blk cg Message-ID: References: <20210610173944.1203706-1-schatzberg.dan@gmail.com> <20210610173944.1203706-4-schatzberg.dan@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="d+pAxhfHeN1kdV+F" Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: A254510000B5 X-Stat-Signature: 86paez45bajncbc8og16ghjz6jgw3sn5 Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=XfyYwT5Q; dkim=pass header.d=suse.com header.s=susede1 header.b=XfyYwT5Q; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf07.hostedemail.com: domain of mkoutny@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mkoutny@suse.com X-HE-Tag: 1625046164-268375 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: --d+pAxhfHeN1kdV+F Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jun 29, 2021 at 10:03:33AM -0400, Dan Schatzberg wrote: > Hmm, perhaps I'm not understanding how the reference counting works, > but my understanding is that we enter loop_queue_rq with presumably > some code earlier holding a reference to the blkcg, we only need to > acquire a reference sometime before returning from loop_queue_rq. The > "window" between loop_queue_rq and loop_queue_work is all > straight-line code so there's no possibility for the earlier code to > get control back and drop the reference. I don't say the current implementation is wrong, it just looked suspicious to me when the css address is copied without taking the reference. The straight path is clear, I'm not sure about later invocations through loop_workfn where the blkcg_css is accessed via the cmd->blkcg_css. > Where would you suggest putting such a comment? This is how I understand it: --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -996,6 +996,7 @@ static void loop_queue_work(struct loop_device *lo, struct loop_cmd *cmd) rb_insert_color(&worker->rb_node, &lo->worker_tree); queue_work: if (worker) { + WARN_ON_ONCE(worker->blkcg_css != cmd->blkcg_css); /* * We need to remove from the idle list here while * holding the lock so that the idle timer doesn't @@ -2106,6 +2107,8 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx, cmd->memcg_css = NULL; #ifdef CONFIG_BLK_CGROUP if (rq->bio && rq->bio->bi_blkg) { + /* reference to blkcg_css will be held by loop_worker (outlives + * cmd) or it is the eternal root css */ cmd->blkcg_css = &bio_blkcg(rq->bio)->css; #ifdef CONFIG_MEMCG cmd->memcg_css = (On further thoughts, maybe the blkcg_css reference isn't needed even in the loop_worker if it can be reasoned that blkcg_css won't go away while there's an outstanding rq.) HTH, Michal --d+pAxhfHeN1kdV+F Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEEoQaUCWq8F2Id1tNia1+riC5qSgFAmDcPI4ACgkQia1+riC5 qShVnw//Z/ZtMKu1mO3W3DY9zAZG/2xeZlqAQuz4x1tWnQOb/vdX3yqhyX0JcIjI 8e4a2pF5XnYaPJs8kRU+4T7uUsaX/9Xb/ZAxOfcJWVFNWOZ+lO6VtK5OJSFFldVB SyZLb6mHnE4s5ZFGZOHVA8T9rK7oY4buwZL4LL7PCqu9gc3hMPrS9okHNjzrb5lU QmXUS/SZue0mqSJayQudE54BZ3y9tqWDxoE68SZ83DsxbRomVnVQ8RKFlB/3CQLc FtjRJ709budI1jnZ54H1O1LOlolRMT6eY+8+gcY9LCcTCWUFs5iRXCwOGzekOPED e39Ts7/msQv5NeQpIYNA0IqbaNW4ooJPXCAO3NKqKCwmM8zaQk66MrVfqhzbY8+I W2WXep5pC9+tUD/jRvWW+cb+A1RnoLQ9qhYQ1xT6My+Uiy4M1IZDSzz3zA8O+5pD l9SjDIe2VCi31ERgx/5s6rANquPKRx6N5CjYoxtU/KXD4HorQFKEzxBovuGtytAs bPGQSHHM8/Zulgk4lENFywYX8NpqxyB9cvZr9q4tybth5fqvZSV+EY08JqXoNarV GmQ1qaORP+0S7xoPBo+2RQweG7lm5kWzAehl4+bQKZnIOTxqqeP2aKuvcd7oELKE VNVS4tpqppXaC2rLpb7LleZoPL+Qq+du+7e8Czui0RaDkO0Cw4I= =IVGr -----END PGP SIGNATURE----- --d+pAxhfHeN1kdV+F--