Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2054331rwb; Thu, 17 Nov 2022 06:03:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf7S0B5YOM5W9kFa5hk1r/MlbF9myNp+wfeRGaPjKaxMQfdT+w55J5l7wNspKP+pbkcBTIew X-Received: by 2002:a50:ec01:0:b0:461:8dc1:10b with SMTP id g1-20020a50ec01000000b004618dc1010bmr2317554edr.113.1668693831736; Thu, 17 Nov 2022 06:03:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668693831; cv=none; d=google.com; s=arc-20160816; b=t1gRVUxxKYNn/i12N5M1Jp2bX30Lu5SEcJA5KZ+GQnnvBLyFXfxxKVbUEV40HA8VsB T6BbdlmDMhVmqWabMTqEEvW64i0Dxl1MlhP48GkxhwOKtQXMqLHL4q6bnNe0+a0aTjnY fyqVXyQg1kWj8XzwPEAZIZWOsfg0M9ALEGWFXbgrw1/mf6enVMDOCQ6k/FHjZ7sGENtd A7Be7sJP6hofQASAkcZsEBQwAz0TdF43f4vI3Tb9dQt8kmue5kf1DyTlnDSuAA2XaXCN vvdgAmFbNiA3gmD7iNu3NixLUqdTGTUDtkFi3RG2ikn7739Wwk90MVtJNMD6ffR+7HDK zrMg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Yo+o8EdA5bPV/zh4RxNdT7hyIiZjbKc3uqQfmoP3TwQ=; b=StRKGx32uB1yB+BpoQZMRBru9vAyK6RXVI221z0yT5i7hxy2q3mtPLA7uLiZG61y1P 2dxaPADWJOaYfpMip/zBCU4jGZ5ev8jZ/eKO47KLr29HsK+7xHrmh2OQzuBy9kMbbVwn GjpLoFSvEoZi7C/aTwExd6IqfYL3gs2MGeZxQ2C0J4wwKw2BvxRE7C8ZrTfbcjP7MVGu Nep52fjD01K6yifog5PYElpkzGHjq4fodGPPwo02hfd+JzAVHc9yzm0uP9gjllGI7t29 eayyJhUmviBRMPRmm8Fpk9rMa5FaCYNnGCP9AZNBlv8/NZ4sLbDceTk4IedAfKQhJJq2 iPmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZVYUWfNz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g35-20020a056402322300b0045ccd2c9944si908071eda.233.2022.11.17.06.03.28; Thu, 17 Nov 2022 06:03:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZVYUWfNz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240203AbiKQNqj (ORCPT + 93 others); Thu, 17 Nov 2022 08:46:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239645AbiKQNqf (ORCPT ); Thu, 17 Nov 2022 08:46:35 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D087C71F29; Thu, 17 Nov 2022 05:46:31 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6A8CA61E38; Thu, 17 Nov 2022 13:46:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 807B5C433C1; Thu, 17 Nov 2022 13:46:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668692790; bh=jwrKHq8lqrVCytRmbVBCOLUIrbyqXrDKHErC15q+x7I=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZVYUWfNzSW5qOrsXH5425h8Res0qNWH6lXbS5xlr8vmHQ/PtWZthcWDOx6KgKe4HX 0TzcYSLuZx/hrZ4H86Bl4s0rsh2/E9hRMAbWLp4SseTVjPOaBzH7aRvWyE5shozlJF akUK6fXyj5hRx2pgVQEzJ3SUI83XHwuyAP+y6lWN3+5/OUu7psy51T4DCq0dZ7TSS9 JZfDjvqS8GcOzw5fb3hkbJRuXz62MNFJtvUBT4SdyXSaq9tHp53qou1Xh/x0jkWejO XJUMrfQvAQwUvLwmWj/PtiPpsIHJ+NCZPqfwgkYlHouNg7X5sLGioAmXbb3M2qdX3N LLUDmFcEFUFGQ== Date: Thu, 17 Nov 2022 13:46:26 +0000 From: Lee Jones To: Greg KH Cc: balbi@kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: Re: [PATCH 1/1] usb: gadget: f_hid: Conduct proper refcounting on shared f_hidg pointer Message-ID: References: <20221117120813.1257583-1-lee@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 On Thu, 17 Nov 2022, Greg KH wrote: > On Thu, Nov 17, 2022 at 12:08:13PM +0000, Lee Jones wrote: > > +static inline bool f_hidg_is_open(struct f_hidg *hidg) > > +{ > > + return !!kref_read(&hidg->cdev.kobj.kref); > > +} > > Ick, sorry, no, that's not going to work and is not allowed at all. > That's some major layering violations there, AND it can change after you > get the value as well. This cdev belongs solely to this driver. Hence the *.*.* and not *->*->*. What is preventing us from reading our own data? If we cannot do this directly, can I create an API to do it 'officially'? I do, however, appreciate that a little locking wouldn't go amiss. If this solution is not acceptable either, then we're left up the creak without a paddle. The rules you've communicated are not compatible with each other. Rule 1: Only one item in a data structure can reference count. Due to the embedded cdev struct, this rules out my first solution of giving f_hidg its own kref so that it can conduct its own life-time management. A potential option to satisfy this rule would be to remove the cdev attribute and create its data dynamically instead. However, the staticness of cdev is used to obtain f_hidg (with container_of()) in the character device handling component, so it cannot be removed. Rule 2: Reading the present refcount causes a laying violation So we're essentially saying, if data is already being reference counted, you have to use the present implementation instead of adding additional counts, but there is no way to actually do that, which kind of puts us at stalemate. Since this is a genuine issue, doing anything is not really an option either. So where do we go from here? -- Lee Jones [李琼斯]