Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3181495pxk; Mon, 21 Sep 2020 07:16:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXcgX4M2WqIchpR55Qg+EGV2gNdDTDPV5NGFLzf8aMj1cm2Fv+fP9byiz3cKv14rZMiYIN X-Received: by 2002:a50:9b19:: with SMTP id o25mr5135243edi.340.1600697803743; Mon, 21 Sep 2020 07:16:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600697803; cv=none; d=google.com; s=arc-20160816; b=IQcXO9UKpFhuj4GVjhwaZ9iZWHakj7++BnAFqsTMp8FGPoqnx5k3ksI6bBiprMuNNS 0P5Hbkph2CruInVYFv6ZG041dUQcj5jOpVPtwQcJ17vvDmp5MS4/NfMbuj7pJj5yYpD3 3fUmDircWG4Lvuwn6Cmc34NYgoG1G5bYfOOIU0zK9r9Jk6Vwjo4bhDoOBGTBUu4Oy83x Qpjivr3Fx8m43bHSlW12hrRn+9FxW/q5wtu2mW6cn5BaXgGnnDQYnllHgY55DpJf6daA XTtV/xjpQla0qQP/HGyGKZQivt9gwPNyv8zpuyvET6QRnji6LOVQnfeVYKEKK/mY7gSp lx9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=FXSTMgr9KsZO5bhwAXiYmzvLsd+XZ5yHo8Li1d5acyA=; b=KGARFrDCtOn2fPPu8RmtDaFl+HlL1uEpG4ZBcZVNFmoPsCscstoAe5sDjng6iP+7Nc hKnMRFwGZmHu/Fg0AT7ZVrajPZ36zQlZyxQ5eVK28T2FtdTzWOe1keUoiTkDix/bf8tF W6HTiXtpjf675L1ggiV8GuRWtZgnFL+fgQCKhNGzUkjcWx6NT+r132OOklEythxN8FTk KXCpn6PODLph4y/dUQm7zoz1hkPujvJX909gCDqDftTZHOijltJX4ZhyOJAa2nET9276 hpfhaQHJ59OTPVww6c+wN2lRnGYj/Y3Yoaq1Y+69Fxb5PCQ0YE3v9Bs2+zD/quCbTrTe vX/Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gv24si8296603ejb.258.2020.09.21.07.16.19; Mon, 21 Sep 2020 07:16:43 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727246AbgIUOPG convert rfc822-to-8bit (ORCPT + 99 others); Mon, 21 Sep 2020 10:15:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727229AbgIUOPF (ORCPT ); Mon, 21 Sep 2020 10:15:05 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1377C061755 for ; Mon, 21 Sep 2020 07:15:05 -0700 (PDT) Received: from lupine.hi.pengutronix.de ([2001:67c:670:100:3ad5:47ff:feaf:1a17] helo=lupine) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kKMau-0000CD-8Z; Mon, 21 Sep 2020 16:15:04 +0200 Received: from pza by lupine with local (Exim 4.92) (envelope-from ) id 1kKMar-0000oz-T0; Mon, 21 Sep 2020 16:15:01 +0200 Message-ID: Subject: Re: [Re-send][PATCH] gpu/ipu-v3:reduce protected code area in ipu idmac get/put From: Philipp Zabel To: Bernard , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: opensource.kernel@vivo.com Date: Mon, 21 Sep 2020 16:15:01 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.30.5-1.1 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:3ad5:47ff:feaf:1a17 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Bernard, On Mon, 2020-09-21 at 19:11 +0800, Bernard wrote: > This change will speed-up a bit these ipu_idmac_get & > ipu_idmac_put processing and there is no need to protect > kzalloc & kfree. I don't think that will be measurable, the channel lock is very unlikely to be contended. It might make more sense to replace the list walk with a bitfield. > Signed-off-by: Bernard Zhao > --- > drivers/gpu/ipu-v3/ipu-common.c | 24 +++++++++++++----------- > 1 file changed, 13 insertions(+), 11 deletions(-) > > diff --git a/drivers/gpu/ipu-v3/ipu-common.c b/drivers/gpu/ipu-v3/ipu-common.c > index b3dae9ec1a38..8b3a57864c2e 100644 > --- a/drivers/gpu/ipu-v3/ipu-common.c > +++ b/drivers/gpu/ipu-v3/ipu-common.c > @@ -267,29 +267,30 @@ EXPORT_SYMBOL_GPL(ipu_rot_mode_to_degrees); > struct ipuv3_channel *ipu_idmac_get(struct ipu_soc *ipu, unsigned num) > { > struct ipuv3_channel *channel; > + struct ipuv3_channel *entry; > > dev_dbg(ipu->dev, "%s %d\n", __func__, num); > > if (num > 63) > return ERR_PTR(-ENODEV); > > + channel = kzalloc(sizeof(*channel), GFP_KERNEL); > + if (!channel) > + return ERR_PTR(-ENOMEM); > + > + channel->num = num; > + channel->ipu = ipu; > + > mutex_lock(&ipu->channel_lock); > > - list_for_each_entry(channel, &ipu->channels, list) { > - if (channel->num == num) { > + list_for_each_entry(entry, &ipu->channels, list) { > + if (entry->num == num) { > + kfree(channel); > channel = ERR_PTR(-EBUSY); > goto out; This leaks the channel memory allocated above. > } > } > > - channel = kzalloc(sizeof(*channel), GFP_KERNEL); > - if (!channel) { > - channel = ERR_PTR(-ENOMEM); > - goto out; > - } > - > - channel->num = num; > - channel->ipu = ipu; > list_add(&channel->list, &ipu->channels); > > out: > @@ -308,9 +309,10 @@ void ipu_idmac_put(struct ipuv3_channel *channel) > mutex_lock(&ipu->channel_lock); > > list_del(&channel->list); > - kfree(channel); > > mutex_unlock(&ipu->channel_lock); > + > + kfree(channel); > } > EXPORT_SYMBOL_GPL(ipu_idmac_put); regards Philipp