Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp935867ybl; Wed, 11 Dec 2019 09:46:46 -0800 (PST) X-Google-Smtp-Source: APXvYqzCPpy/tHmPOYMm79rJBNuRk0fOZ8XkIaN2rJeWUYeDi6o9jDmKzB+N30aQpGX7kfVHcLdV X-Received: by 2002:a9d:7342:: with SMTP id l2mr3152133otk.98.1576086406779; Wed, 11 Dec 2019 09:46:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576086406; cv=none; d=google.com; s=arc-20160816; b=dxslPLG5sdkXBw6pt/I9MMtQWs8uD8WcigoFMSnSEdNX7iXj/0CPoaQMwg2HKugufD KKK5d/y5TOCBFcitDj/x41Iq7SMA1CGNnF819VJAAT4RyQ98mY27ibyWKpciDSfFmf45 1ygPo3dZ0eZQxVb5XWdkKjy1EusrETcE2u0ExMCeU8SnkdYnWgy8Ri9thb9Y1K5gkiWS 2vsnSQ8pWH9YtFHACrv/1ktTws2+96V2i204QDwiWFqHnJ6PodN/5pGFjWRcmerJShUE RrBmpwFBNCKEvSKog0BDMYGG/4cjRW5PAdz9+nh2pt/hNylkMw57bHNH/7f45DqNEPIU KXVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=94bkKDX3iw5T6vY4cRorDa6czepFB9WT9mUYiyzVC3k=; b=pmSsC9YM7Nlbd/fpwcMfxeqlEpC+wvHLGBUtMa4oS3/1TPU3bK3Ck1huAPEYItw9/i JqptLaSZniphVw/jxCKIUa5n6T8ooGcJvig+Roo5yqri3badMeDMyngIHHjk4/PZ9HqW ac1w91BiCwEr/PJKtGgZtQtZwJBSVNzSwe4mjopz5p8GptLyMxXWwAcmTZRyTE+T1+xy H1hzsMIWk/UW+JCpL/yeMWUrXfQpv1RNIf9f9+ZWtm7mVgBMcExV8SEEZXg7aY5Z2Hnh VK1N9O8EzY/6kBGytZ7qwYmcKwpwr7SYbKzo3bwMyxOn8D3/8d/99t/+vrFOUMhYGSC3 ga2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 65si1511665otw.204.2019.12.11.09.46.34; Wed, 11 Dec 2019 09:46:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730612AbfLKRpm (ORCPT + 99 others); Wed, 11 Dec 2019 12:45:42 -0500 Received: from mga04.intel.com ([192.55.52.120]:59055 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729524AbfLKRpm (ORCPT ); Wed, 11 Dec 2019 12:45:42 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2019 09:45:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,302,1571727600"; d="scan'208";a="210841921" Received: from cmclough-mobl.ger.corp.intel.com (HELO localhost) ([10.251.85.152]) by fmsmga008.fm.intel.com with ESMTP; 11 Dec 2019 09:45:38 -0800 Date: Wed, 11 Dec 2019 19:45:36 +0200 From: Jarkko Sakkinen To: Tadeusz Struk Cc: Will Deacon , Jeffrin Jose , peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, peterhuewe@gmx.de, jgg@ziepe.ca Subject: Re: [PROBLEM]: WARNING: lock held when returning to user space! (5.4.1 #16 Tainted: G ) Message-ID: <20191211174536.GG4516@linux.intel.com> References: <20191207173420.GA5280@debian> <20191209103432.GC3306@willie-the-truck> <20191209202552.GK19243@linux.intel.com> <34e5340f-de75-f20e-7898-6142eac45c13@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <34e5340f-de75-f20e-7898-6142eac45c13@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 09, 2019 at 01:34:29PM -0800, Tadeusz Struk wrote: > I think that's expected for a non-blocking operation. What do you mean by "expected"? It is a locking bug. When you implemented the feature you failed to free locks before going back to the user space and I failed to notice this when I reviewed the code. > To get rid of the warning it should be changed to something like this: > > diff --git a/drivers/char/tpm/tpm-dev-common.c > b/drivers/char/tpm/tpm-dev-common.c > index 2ec47a69a2a6..47f1c0c5c8de 100644 > --- a/drivers/char/tpm/tpm-dev-common.c > +++ b/drivers/char/tpm/tpm-dev-common.c > @@ -61,6 +61,12 @@ static void tpm_dev_async_work(struct work_struct *work) > > mutex_lock(&priv->buffer_mutex); > priv->command_enqueued = false; > + ret = tpm_try_get_ops(priv->chip); > + if (ret) { > + priv->response_length = ret; > + goto out; > + } > + > ret = tpm_dev_transmit(priv->chip, priv->space, priv->data_buffer, > sizeof(priv->data_buffer)); > tpm_put_ops(priv->chip); > @@ -68,6 +74,7 @@ static void tpm_dev_async_work(struct work_struct *work) > priv->response_length = ret; > mod_timer(&priv->user_read_timer, jiffies + (120 * HZ)); > } > +out: > mutex_unlock(&priv->buffer_mutex); > wake_up_interruptible(&priv->async_wait); > } > @@ -205,6 +212,7 @@ ssize_t tpm_common_write(struct file *file, const > char __user *buf, > priv->command_enqueued = true; > queue_work(tpm_dev_wq, &priv->async_work); > mutex_unlock(&priv->buffer_mutex); > + tpm_put_ops(priv->chip); > return size; > } > > > > -- > Tadeusz The fix looks appropriate but needs to be formalized as a patch. /Jarkko