Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4408935pxb; Mon, 21 Feb 2022 20:38:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxhixR9SlufJZy+tnKClUwu8/OiAa0EuEeOkXlbkJJUc6EVJU7+1w9DZunPWUj7qpd3k84A X-Received: by 2002:a05:6a00:c95:b0:4e1:1f5a:35cf with SMTP id a21-20020a056a000c9500b004e11f5a35cfmr23280311pfv.56.1645504713196; Mon, 21 Feb 2022 20:38:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645504713; cv=none; d=google.com; s=arc-20160816; b=hQW5BFGihH+Pgnyu6kDW73tQ5v78U3Ht12/vXsnFHw5pTSxEEbE2W6W10AN4i6ssKY 65yQFXqIQ+JT/0D0GqtsvA0xZt+GU7429CJTp3oY1h+UAhQ3F+tP3w/GiOMnZOzKPzO9 tO26dlj6T10e68EfGUeBKZ280PEhhnJRYlmGK4BxVotcFEUxfYtGjB7CWoi3QaEnHFhh zd5tXuU9fRqXAzqJNUZlASfVd7nz5+TUPpd/CFmM1zMnI3E+el6b9m4kVMYDox1baBS7 LZiCE2J9kQ1Qt/CbrEEwd+mKS1l/zJH/fyaYTY5ilzKmB3L2VU0WDLbK03JLAw7R6AOa Z+hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=X9BeRJcZSSZze7JRyDJH3PybPrLEA2YnLuJEnI8H+Ro=; b=LAfNntoj7iCxVSntN3V21pSgkairxuIW6HgnkKrWUngT+4taLOWEDcA8GW/MWBYNic 3Zb6w1ESkYeH2lSepYBf+e0Ob3aAWSkyj4I+00WtQhOA8krgYawZvDPGk8ut4OtazHze NlZOJ6trzbsMHirISD5u9LDOWY4/c5AsHD4e5S3+qM24yAitoH1otJdhyNRsHakaEkSX juWnf1MyGwlSNDPQ/9gjsbUVk7zt5DDHEOE/26ELewpHy4wyQgelh6j1BYZPzXVZ0tCB DMYjW4cauYs1nMMqgJBC2YTPWLmYATj/lWod5bsC8dL3+p/0wyV2KD+vp75ciN2nwzwG z5yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kapsi.fi header.s=20161220 header.b=FUtxbuhW; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d21si333101pls.430.2022.02.21.20.38.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 20:38:33 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=fail header.i=@kapsi.fi header.s=20161220 header.b=FUtxbuhW; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B48F69F3A5; Mon, 21 Feb 2022 20:26:35 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357284AbiBUMHU (ORCPT + 99 others); Mon, 21 Feb 2022 07:07:20 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:39180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345377AbiBUMHS (ORCPT ); Mon, 21 Feb 2022 07:07:18 -0500 Received: from mail.kapsi.fi (mail.kapsi.fi [IPv6:2001:67c:1be8::25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 677856457; Mon, 21 Feb 2022 04:06:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=X9BeRJcZSSZze7JRyDJH3PybPrLEA2YnLuJEnI8H+Ro=; b=FUtxbuhW1rqJy9qhbUuNnzjwac rnwAmWQoTeFq7x/FZCBG9IBUIOf6yTDLaVhvHTocrJRibQKfdal8Fiw9T+v4RVtEuug0rNi1rbRAv Dl8wHNERdybmv2HkyO+q7NcIpJJjI+HJqn1g+m4Yzw9unJ7f2SlRK0hW9JgYw1B/DKnHLsX0OYSEM KCBnPuGjZ2QW6IhMAwGIQ0XqzDL+BdsSgzpadj/CPaN6dsZf/hgAOL5iZSzym8/Z4CXcSgjI+akI1 TFBukz+TD0093D2MSqqDgp0HJpSNMp7dxY7SBWH9hsYELN36Jj8lzAM94nvIzOoB2vsBDNVR23B/i RbLMduVg==; Received: from 91-158-25-70.elisa-laajakaista.fi ([91.158.25.70] helo=[192.168.1.10]) by mail.kapsi.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1nM7Sl-0001x6-KF; Mon, 21 Feb 2022 14:06:43 +0200 Message-ID: Date: Mon, 21 Feb 2022 14:06:43 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.1 Subject: Re: [PATCH v3 9/9] drm/tegra: Support context isolation Content-Language: en-US To: Dmitry Osipenko , Mikko Perttunen , thierry.reding@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, will@kernel.org, robh+dt@kernel.org, robin.murphy@arm.com Cc: linux-tegra@vger.kernel.org, dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20220218113952.3077606-1-mperttunen@nvidia.com> <20220218113952.3077606-10-mperttunen@nvidia.com> <2b4dd244-f918-4d26-2322-00a0bb226ccf@gmail.com> From: Mikko Perttunen In-Reply-To: <2b4dd244-f918-4d26-2322-00a0bb226ccf@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 91.158.25.70 X-SA-Exim-Mail-From: cyndis@kapsi.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 2/19/22 20:35, Dmitry Osipenko wrote: > 18.02.2022 14:39, Mikko Perttunen пишет: >> + if (context->memory_context && context->client->ops->get_streamid_offset) { > ^^^ >> + int offset = context->client->ops->get_streamid_offset(context->client); >> + >> + if (offset >= 0) { >> + job->context = context->memory_context; >> + job->engine_streamid_offset = offset; >> + host1x_context_get(job->context); >> + } > > You should bump refcount unconditionally or you'll get refcnt underflow > on put, when offset < 0. This refcount is intended to be dropped from 'release_job', where it's dropped if job->context is set, which it is from this path. > >> + } >> + >> /* >> * job_data is now part of job reference counting, so don't release >> * it from here. >> diff --git a/drivers/gpu/drm/tegra/uapi.c b/drivers/gpu/drm/tegra/uapi.c >> index 9ab9179d2026..be33da54d12c 100644 >> --- a/drivers/gpu/drm/tegra/uapi.c >> +++ b/drivers/gpu/drm/tegra/uapi.c >> @@ -33,6 +33,9 @@ static void tegra_drm_channel_context_close(struct tegra_drm_context *context) >> struct tegra_drm_mapping *mapping; >> unsigned long id; >> >> + if (context->memory_context) >> + host1x_context_put(context->memory_context); > > The "if (context->memory_context && > context->client->ops->get_streamid_offset)" above doesn't match the "if > (context->memory_context)". You'll get refcount underflow. And this drop is for the refcount implicitly added when allocating the memory context through host1x_context_alloc; so these two places should be independent. Please elaborate if I missed something. Thanks, Mikko