Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp3976962rwb; Sun, 30 Jul 2023 21:54:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlEvLR4y0OVfwEC6236AKpsaSrQlsLNNNr4xXo4Vtwdmt/bxYnJNzzBZJzd2ol1DrQfe9yfj X-Received: by 2002:a17:906:74ce:b0:993:fe68:569c with SMTP id z14-20020a17090674ce00b00993fe68569cmr5604026ejl.6.1690779246430; Sun, 30 Jul 2023 21:54:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690779246; cv=none; d=google.com; s=arc-20160816; b=zJhv6Es3zMFk31rP8GFyh2ccpAUxCCGyeDNiNrxr9DpsglPPKyd4D0wZMRrCnYEMcu tEccAp6P+kTIkozMvSinXYSW5b6QxXpA65ZLkDvAW11sn7i3W9vbw17RzsLvbfLgoYyv kL7xjlvXapX2NBXBjLLlvmCEtCXdEWiSvZaSQi4iUXfdU9oOMww6tL7gdCQhpx/aQWL+ +K26qRHBld/4S37+N5rnQ/LnGcQUojyH1zc9q7JwB38OrmQryj/XeMD1Y1eCKFY1BW8c QYIlgAogzT88QyckrLFWJGBlTNUbdvHKtuy3+OTdJPw0gNPEuJxTbgFbdJ3GrqBAI67H r90A== 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=su5D+Tmrapqcznb46Ug6phpVwO6dH713+EUewY3lEfg=; fh=H1IgyJ0Ak4BYnhr64t0AkHWT2Xy5iO5fYyZRayU6/gM=; b=SzwWnThgprZiTZnp6OWNMaasj9Dt+oQ0OWW5AWs6edy8rWoeKDEuhP5KK0LeTx8xbh P0/pODj2CNWgBNsMyKNm4x41Zm1KJ9HdrJetKLHHuZmnKgEYFZNnvjiP0LlcbdH6G0r8 8fDBG6oumo5QfHOB/hK0TDBIc1cau+0zJW285ltzckKhHPDmHKAdZvUXtTjMseD0yqVg 46lQBZa1GCNpJRK//a9gXbvkUCKDnNpxXANJjNdiCdxw8fzbhBTfkPrlghtg1P6AzZs9 ALRjgqCnyBNc70rGeIn1glLNaCl6ej3s+H7hIepuvGD/ugkW17ZDXvwS7elXVxZqI652 IkAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rrWW6dyd; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o5-20020a17090608c500b009787b15aa51si2734823eje.713.2023.07.30.21.53.11; Sun, 30 Jul 2023 21:54:06 -0700 (PDT) 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=@linaro.org header.s=google header.b=rrWW6dyd; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229641AbjGaEGd (ORCPT + 99 others); Mon, 31 Jul 2023 00:06:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229573AbjGaEGb (ORCPT ); Mon, 31 Jul 2023 00:06:31 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B1DD1BE for ; Sun, 30 Jul 2023 21:06:29 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2b9540031acso61173161fa.3 for ; Sun, 30 Jul 2023 21:06:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690776387; x=1691381187; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=su5D+Tmrapqcznb46Ug6phpVwO6dH713+EUewY3lEfg=; b=rrWW6dydtNphoiXUZjHrvk4yiuLdtpoCeql0RX/1BIAnOzKrZBGkWUic1Vu+Fjlji4 J8HegS+wuDEOUBdA7hlLqzoxCOe7GZI4zVv7njw5G4XzlcHmuaRy9CDJqOGhgHQs6k91 UbyGx4GTNCoWvHbUdl3oUVoBIvI9PUf+93aYMJU6dHp/1VgNNsunfd5mYoHfAwinzepS 8ILHNlSNJl0Y9L9n1kTpKTubSa4LrMJGY+ubDkXoMASgF+eEbbK8zb38HdWDf18tpnFe LXhe0nYo+Rz2c7RcRYesW692NSwnSWlMKs5oGHaH3+su+GK2ZM6LunSBGR6YTfaKekE4 L/ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690776387; x=1691381187; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=su5D+Tmrapqcznb46Ug6phpVwO6dH713+EUewY3lEfg=; b=QsY64C9E4u+DhGGg4fM2ZPKdCe0RqUvUlGRrnwWcLBKJ2PTkocUby82dnZlR7P1AiI v0XjTgcDGXYsudP902lmzTYFZSz/CR3nsUGWAzh7vLD8viZOOcarbWrtKoDmUL8m5O8Z Kd4XkHPf8ElyVmm3Hvdi+YlxK0igxbz8nFJJfYA0nlWg4MQigBzcN+ypUOEvVjD/Skcg o4ddc6Hs7iG14A0Wu+Ede7PspVZ20gyEU9xtIzmwsJjiV3ekgLf1KIBAcF78zmIAh1gi 3cjyZ0vn6Msw/flqfcV/ndiDq4WdUajl86HDICk/S2tc8J1UUq+v+a9GNJF3gRohUKUm HdOA== X-Gm-Message-State: ABy/qLbvfFrmMDxTwl3cUjUYLEvQqwS7ZATRDdjWb0IMzsJhxKZDCH4k MQ7ogs80WawLc6ce+q7LgEznIQ== X-Received: by 2002:a2e:3e17:0:b0:2b5:89a6:c12b with SMTP id l23-20020a2e3e17000000b002b589a6c12bmr5505065lja.10.1690776387508; Sun, 30 Jul 2023 21:06:27 -0700 (PDT) Received: from ?IPV6:2001:14ba:a0db:1f00::8a5? (dzdqv0yyyyyyyyyyybcwt-3.rev.dnainternet.fi. [2001:14ba:a0db:1f00::8a5]) by smtp.gmail.com with ESMTPSA id x24-20020a05651c105800b002b9aea70f9dsm1552983ljm.85.2023.07.30.21.06.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 30 Jul 2023 21:06:26 -0700 (PDT) Message-ID: Date: Mon, 31 Jul 2023 07:06:26 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH RFC v5 06/10] drm/atomic: Move framebuffer checks to helper Content-Language: en-GB To: Jessica Zhang , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Rob Clark , Sean Paul , Marijn Suijten Cc: quic_abhinavk@quicinc.com, ppaalanen@gmail.com, contact@emersion.fr, laurent.pinchart@ideasonboard.com, sebastian.wick@redhat.com, ville.syrjala@linux.intel.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, wayland-devel@lists.freedesktop.org References: <20230728-solid-fill-v5-0-053dbefa909c@quicinc.com> <20230728-solid-fill-v5-6-053dbefa909c@quicinc.com> From: Dmitry Baryshkov In-Reply-To: <20230728-solid-fill-v5-6-053dbefa909c@quicinc.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On 28/07/2023 20:02, Jessica Zhang wrote: > Currently framebuffer checks happen directly in > drm_atomic_plane_check(). Move these checks into their own helper > method. > > Signed-off-by: Jessica Zhang > --- > drivers/gpu/drm/drm_atomic.c | 130 ++++++++++++++++++++++++------------------- > 1 file changed, 73 insertions(+), 57 deletions(-) > > diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c > index 1ee7d08041bc..017ce0e6570f 100644 > --- a/drivers/gpu/drm/drm_atomic.c > +++ b/drivers/gpu/drm/drm_atomic.c > @@ -580,6 +580,76 @@ plane_switching_crtc(const struct drm_plane_state *old_plane_state, > return true; > } > > +static int drm_atomic_check_fb(const struct drm_plane_state *state) Maybe drm_atomic_plane_check_fb()? Other than that: Reviewed-by: Dmitry Baryshkov > +{ > + struct drm_plane *plane = state->plane; > + const struct drm_framebuffer *fb = state->fb; > + struct drm_mode_rect *clips; > + > + uint32_t num_clips; > + unsigned int fb_width, fb_height; > + int ret; > + > + /* Check whether this plane supports the fb pixel format. */ > + ret = drm_plane_check_pixel_format(plane, fb->format->format, > + fb->modifier); > + > + if (ret) { > + drm_dbg_atomic(plane->dev, > + "[PLANE:%d:%s] invalid pixel format %p4cc, modifier 0x%llx\n", > + plane->base.id, plane->name, > + &fb->format->format, fb->modifier); > + return ret; > + } > + > + fb_width = fb->width << 16; > + fb_height = fb->height << 16; > + > + /* Make sure source coordinates are inside the fb. */ > + if (state->src_w > fb_width || > + state->src_x > fb_width - state->src_w || > + state->src_h > fb_height || > + state->src_y > fb_height - state->src_h) { > + drm_dbg_atomic(plane->dev, > + "[PLANE:%d:%s] invalid source coordinates " > + "%u.%06ux%u.%06u+%u.%06u+%u.%06u (fb %ux%u)\n", > + plane->base.id, plane->name, > + state->src_w >> 16, > + ((state->src_w & 0xffff) * 15625) >> 10, > + state->src_h >> 16, > + ((state->src_h & 0xffff) * 15625) >> 10, > + state->src_x >> 16, > + ((state->src_x & 0xffff) * 15625) >> 10, > + state->src_y >> 16, > + ((state->src_y & 0xffff) * 15625) >> 10, > + fb->width, fb->height); > + return -ENOSPC; > + } > + > + clips = __drm_plane_get_damage_clips(state); > + num_clips = drm_plane_get_damage_clips_count(state); > + > + /* Make sure damage clips are valid and inside the fb. */ > + while (num_clips > 0) { > + if (clips->x1 >= clips->x2 || > + clips->y1 >= clips->y2 || > + clips->x1 < 0 || > + clips->y1 < 0 || > + clips->x2 > fb_width || > + clips->y2 > fb_height) { > + drm_dbg_atomic(plane->dev, > + "[PLANE:%d:%s] invalid damage clip %d %d %d %d\n", > + plane->base.id, plane->name, clips->x1, > + clips->y1, clips->x2, clips->y2); > + return -EINVAL; > + } > + clips++; > + num_clips--; > + } > + > + return 0; > +} > + > /** > * drm_atomic_plane_check - check plane state > * @old_plane_state: old plane state to check > @@ -596,9 +666,6 @@ static int drm_atomic_plane_check(const struct drm_plane_state *old_plane_state, > struct drm_plane *plane = new_plane_state->plane; > struct drm_crtc *crtc = new_plane_state->crtc; > const struct drm_framebuffer *fb = new_plane_state->fb; > - unsigned int fb_width, fb_height; > - struct drm_mode_rect *clips; > - uint32_t num_clips; > int ret; > > /* either *both* CRTC and FB must be set, or neither */ > @@ -625,17 +692,6 @@ static int drm_atomic_plane_check(const struct drm_plane_state *old_plane_state, > return -EINVAL; > } > > - /* Check whether this plane supports the fb pixel format. */ > - ret = drm_plane_check_pixel_format(plane, fb->format->format, > - fb->modifier); > - if (ret) { > - drm_dbg_atomic(plane->dev, > - "[PLANE:%d:%s] invalid pixel format %p4cc, modifier 0x%llx\n", > - plane->base.id, plane->name, > - &fb->format->format, fb->modifier); > - return ret; > - } > - > /* Give drivers some help against integer overflows */ > if (new_plane_state->crtc_w > INT_MAX || > new_plane_state->crtc_x > INT_MAX - (int32_t) new_plane_state->crtc_w || > @@ -649,50 +705,10 @@ static int drm_atomic_plane_check(const struct drm_plane_state *old_plane_state, > return -ERANGE; > } > > - fb_width = fb->width << 16; > - fb_height = fb->height << 16; > > - /* Make sure source coordinates are inside the fb. */ > - if (new_plane_state->src_w > fb_width || > - new_plane_state->src_x > fb_width - new_plane_state->src_w || > - new_plane_state->src_h > fb_height || > - new_plane_state->src_y > fb_height - new_plane_state->src_h) { > - drm_dbg_atomic(plane->dev, > - "[PLANE:%d:%s] invalid source coordinates " > - "%u.%06ux%u.%06u+%u.%06u+%u.%06u (fb %ux%u)\n", > - plane->base.id, plane->name, > - new_plane_state->src_w >> 16, > - ((new_plane_state->src_w & 0xffff) * 15625) >> 10, > - new_plane_state->src_h >> 16, > - ((new_plane_state->src_h & 0xffff) * 15625) >> 10, > - new_plane_state->src_x >> 16, > - ((new_plane_state->src_x & 0xffff) * 15625) >> 10, > - new_plane_state->src_y >> 16, > - ((new_plane_state->src_y & 0xffff) * 15625) >> 10, > - fb->width, fb->height); > - return -ENOSPC; > - } > - > - clips = __drm_plane_get_damage_clips(new_plane_state); > - num_clips = drm_plane_get_damage_clips_count(new_plane_state); > - > - /* Make sure damage clips are valid and inside the fb. */ > - while (num_clips > 0) { > - if (clips->x1 >= clips->x2 || > - clips->y1 >= clips->y2 || > - clips->x1 < 0 || > - clips->y1 < 0 || > - clips->x2 > fb_width || > - clips->y2 > fb_height) { > - drm_dbg_atomic(plane->dev, > - "[PLANE:%d:%s] invalid damage clip %d %d %d %d\n", > - plane->base.id, plane->name, clips->x1, > - clips->y1, clips->x2, clips->y2); > - return -EINVAL; > - } > - clips++; > - num_clips--; > - } > + ret = drm_atomic_check_fb(new_plane_state); > + if (ret) > + return ret; > > if (plane_switching_crtc(old_plane_state, new_plane_state)) { > drm_dbg_atomic(plane->dev, > -- With best wishes Dmitry