Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2785417rdb; Fri, 22 Sep 2023 08:19:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFsLzTtl+to4lu32PShZ1mJMkP6jcV8bIhnvvhUnUHUeLnOYSoT30ZHQgvxZKKgyJ02UPTJ X-Received: by 2002:a17:90a:8b03:b0:274:dd15:87bf with SMTP id y3-20020a17090a8b0300b00274dd1587bfmr4283478pjn.20.1695395968797; Fri, 22 Sep 2023 08:19:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695395968; cv=none; d=google.com; s=arc-20160816; b=ncsFLFNUiLDaQ2r6e1Ur1IIhA4NcDF9paVk7umBl7TliTIzYeckUKFzFbUNMmDOZ0x uajvdNnl3dWmufvsCMu4Q/wAp1bHfw0b8FvUBBwvzlka8aH86PFgLzw9K8F7zyyRAxVi EBMYzXt3FdKlwW9/XcB5vGzposSorSz2UpjDtPSoDLUEZEkizWGNjVuW1t6eZb1jhDwi ncsDPKU4OWCryvv1qqOZM0wbmcsTKsA+iABr5+hnR0KI6A3N1QaIPYHCzvpUvq1HZs4A EmAGM4IKi8/B5KQUSJZ6ZKIJRbKrtjC22vcH9rE4hbRw70eAqVHjKtVp5QgQkIHWpfvd FN8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:user-agent :references:organization:in-reply-to:subject:cc:to:from :dkim-signature; bh=uHDbDGcnezPT4bKowgq6lQs64vPnJa0qQhHe7lIWSKs=; fh=krMbsNiZvqwPDyzx32nLsZI8L+PVKtUhULAUUycWWVU=; b=yOkN+E3a6Pk+JIwfiEKg/9+jUXuIl5e9O3oWvcHDnzTNlXGvnZoPWNyjFwtyhtYVz9 7bi1HQHKhsPwA5o4qh8hQm2WRy6miecvT2gOeNtuSCfmsOKyCoXXWBJSTMAIxliaFZwy 9exkniHeZcZHMTzoPE31EH5W528UjJpEZ38r+ER76PCxDxURatfHBfdC6gIKbfwkcnm/ Ur4O1JsrvP2JXQ6DKgtFulNYwjogZ35Ka1Nu6cKYFH09PBBKU5BMr+ey+BXM4FHXFont EgTutYAokWP+hHF9kZpbnG1JatiO0qdmwuggyoChBxv7X3PW0DcM2wUdFefKprsFgq48 G3LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gbZRAIh9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id ot13-20020a17090b3b4d00b00263bfa6e205si7029388pjb.50.2023.09.22.08.19.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 08:19:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gbZRAIh9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id ACB318212A9F; Fri, 22 Sep 2023 05:26:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230009AbjIVM1A (ORCPT + 99 others); Fri, 22 Sep 2023 08:27:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbjIVM07 (ORCPT ); Fri, 22 Sep 2023 08:26:59 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7F5F99 for ; Fri, 22 Sep 2023 05:26:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695385567; h=from:from:reply-to:subject:subject: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=uHDbDGcnezPT4bKowgq6lQs64vPnJa0qQhHe7lIWSKs=; b=gbZRAIh9gxlYz7J70eUzfOUEQJqPaU6/I8WBdTVohgPvxZlYPYrskhEM90FPmKmRIIkPK4 FT619WNrCELmhmVmH52U8t+ar7XHYIxwhD+klDc6MLGV74JQCQoa4+i6A00FoP5FwYSLxw n4Q/so0WX/JUrzCbrXdDsR2aRsGtOw0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-608-ruUtV3wVOKWDAIjl1KTNjA-1; Fri, 22 Sep 2023 08:26:01 -0400 X-MC-Unique: ruUtV3wVOKWDAIjl1KTNjA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BC9C38039CB; Fri, 22 Sep 2023 12:26:00 +0000 (UTC) Received: from localhost (unknown [10.39.193.134]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F0376140E950; Fri, 22 Sep 2023 12:25:59 +0000 (UTC) From: Cornelia Huck To: Halil Pasic , Dinghao Liu Cc: Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Julian Wiedmann , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Halil Pasic Subject: Re: [PATCH] s390/cio: Fix a memleak in css_alloc_subchannel In-Reply-To: <20230922141700.10895474.pasic@linux.ibm.com> Organization: "Red Hat GmbH, Sitz: Werner-von-Siemens-Ring 12, D-85630 Grasbrunn, Handelsregister: Amtsgericht =?utf-8?Q?M=C3=BCnchen=2C?= HRB 153243, =?utf-8?Q?Gesch=C3=A4ftsf=C3=BChrer=3A?= Ryan Barnhart, Charles Cachera, Michael O'Neill, Amy Ross" References: <20230921071412.13806-1-dinghao.liu@zju.edu.cn> <20230922141700.10895474.pasic@linux.ibm.com> User-Agent: Notmuch/0.37 (https://notmuchmail.org) Date: Fri, 22 Sep 2023 14:25:58 +0200 Message-ID: <87sf76z961.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 22 Sep 2023 05:26:57 -0700 (PDT) On Fri, Sep 22 2023, Halil Pasic wrote: > On Thu, 21 Sep 2023 15:14:12 +0800 > Dinghao Liu wrote: > >> When dma_set_coherent_mask() fails, sch->lock has not been >> freed, which is allocated in css_sch_create_locks(), leading >> to a memleak. >> >> Fixes: 4520a91a976e ("s390/cio: use dma helpers for setting masks") >> Signed-off-by: Dinghao Liu > > Reviewed-by: Halil Pasic > > @Vineeth: Do you know why is the spinlock "*sch->lock" allocated > dynamically and referenced via a pointer instead of making the > spinlock simply a member of struct subchannel and getting rid > of the extra allocation? > > I did some archaeology together with Peter. The > lock used to be a member but then commit 2ec2298412e1 ("[S390] > subchannel lock conversion.") switched to (mostly) allocating > the lock separately. Mostly because of this hunk: > > @@ -520,9 +530,15 @@ cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid) > /* Nuke all fields. */ > memset(sch, 0, sizeof(struct subchannel)); > > - spin_lock_init(&sch->lock); > + sch->schid = schid; > + if (cio_is_console(schid)) { > + sch->lock = cio_get_console_lock(); > + } else { > + err = cio_create_sch_lock(sch); > + if (err) > + goto out; > + } > > I did not spend a huge amount of time looking at this but this > is the only reason I found for sch->lock being made a pointer. There may > be others, I'm just saying that is all I've found. Author of 2ec2298412e1 here. If I don't completely misremember things, this was for the orphanage stuff (i.e. ccw devices that were still kept as disconnected, like dasd still in use, that had to be moved from their old subchannel object because a different device appeared on that subchannel.) That orphanage used a single dummy subchannel for all ccw devices moved there. I have no idea how the current common I/O layer works, but that might give you a hint about what to look for :) > > Since 863fc8492734 ("s390/cio: get rid of static console subchannel") > that reason with the console_lock is no more. And that brings me back to > the question: "Why?" > > Regards, > Halil > > [..]