Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp167349pxv; Wed, 30 Jun 2021 02:44:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZx+wttNq5FFve9OZ0TWceb0QvQHVFJ5uW7bISkmmbDmjbJjcPcbIxFXdHs0MRiJtXYv1Y X-Received: by 2002:aa7:cdc8:: with SMTP id h8mr44590549edw.323.1625046280188; Wed, 30 Jun 2021 02:44:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625046280; cv=none; d=google.com; s=arc-20160816; b=wHo/anRnWP0wKS9HduVRB6d9NGUYm/eRksmScXKQivxndeP9QZFSI5wngJlTB8yTxA MSxAmUIKOUUyem4gHNZnSkx4p3urxXGpsj/4nTBSR0AixTjSYSEhKac/X+ObJ66F7Zce 5CNlx0MdJVKhexbwIXUXteAFomhu3D7XHRYeI3yS6G0GNLnh2fkMSScAdqjmwH9u0nTP pVo0kIkp6pgodzZE16rsXHHIrbDXj9QuoiC68hLZz488zlyfgjymRdvKVsSJLYGYypPK XPabh7MMqagzeK9tTGiWf9JRF17h0WyzPBDQ265Y2hGYw1k400ZLhyCni4vOwSVv/AtF Okbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=A3MNoSLnXHqAMX3jqPxgl/njzLp8ToXYl4dULk/puSI=; b=e/h3R0Wqz2BybUG4agBTN3Tz1z52v5dwiXI8dfSPunhnrdzlfMVen/Xj5uOgUWV+Hr daHfXfUJhzSXBAhUAU2ZrKrI++eKG3sRpBBQ3kF+yZ3Z4y6QMy2Ugx7TpgnNrM2JIe0X HkwJhxakCQINmLsHM0WHvAUzHLHP8H2iP1LY73Y7/JkNcEpRjLnyMxYO5kzy/A3NSo0U yGlcccuX8/tKe12ydp2rHLTrftaJs9wedIWDGiiMgd0FledSQ2c69+2abqcFXoBz0Sad pk+tcvyHBljgGFtyTjVt889L5NGEa7iwRUdpKzkycdLtLt2zBA23Dezs+4a4I5FIha12 VTPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=XfyYwT5Q; dkim=pass header.i=@suse.com header.s=susede1 header.b=XfyYwT5Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jy12si19979728ejc.729.2021.06.30.02.44.16; Wed, 30 Jun 2021 02:44:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=XfyYwT5Q; dkim=pass header.i=@suse.com header.s=susede1 header.b=XfyYwT5Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233994AbhF3JpN (ORCPT + 99 others); Wed, 30 Jun 2021 05:45:13 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:47566 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233541AbhF3JpN (ORCPT ); Wed, 30 Jun 2021 05:45:13 -0400 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --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--