Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp1374248rwp; Thu, 13 Jul 2023 09:54:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlHeG4yeLnq7No4O3jggwEVBkm1LG5MYR7FCQUa+hvd7CD6yQnc3f6A3xg//ydTOoMlkR4/9 X-Received: by 2002:aa7:dc11:0:b0:51d:d5f2:121e with SMTP id b17-20020aa7dc11000000b0051dd5f2121emr2096013edu.5.1689267255039; Thu, 13 Jul 2023 09:54:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689267255; cv=none; d=google.com; s=arc-20160816; b=x4l9sZGO0gwHW/iU4DfgBeabrcmrN6etGRQ/1mqitAVG7l0fppZfx2ox/IYFN0XvBS 4T30g0rYEPD46qSi+SxcUtWNCNvM2qrLKs2QAoCW6nTG9wwm1Fo3br8Q161U7TSsFtTr 6eAGu+oez+C96ELqclzzBaIDae0aIvlP129/Jugx+ctwoklALTjPO4KE1+QGHqc3AtWT SB/8+2GWhph2NI/sOlXk8vGLXETXdzObf6A3BJbxi4OKhiSN6ZvD5fNqd8338vI3USJj QkKq0WYhTASrl+QzYGarrWptjyr4szLuDdb1pemU2UpZmv6ZcR9RaO8gqUQk+bKwBLzH YJtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=hA4oXFz7iMz2TN7Oq1WGXGk81ddHsb/K8fUHUI+fX50=; fh=xQLzqvagBaT/JxUJ9S2F9j2c9SChg5Xo7G9xUwKva9s=; b=i7BAHRytV9aWxu/bLJ8ue8dBR2hTLVt6Eb2idE8U0MKNXpG7FUEZj7kk9Zsxu6q3XN +3/eTMc/vwnu66aSYLxSw3ok7gHVKhhiGSgSUB2p5+PKqQgm4bM26Uy0MtaR7YnoQDJQ K2oFFGWarjKppTaIdQ1NDB9RVvQ2d5/Nm793jVMDPkUo/cWJCW0I6RYSlkmIed18kykH QzdnQiiq8a5U5cY4Y30GmByvZZ3XlhHZtyDHW6v8G3EoqdwaPhVA5o3nozQ5av4uPRjQ 7YiLzASSwTiggZQn5Nvt5qiE/JKRwunMzydm40NbuBrmvsvGDMkNWFhPbW38b35BZXT8 tFww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OtLS2MwF; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r18-20020aa7da12000000b0051ff2b7561fsi1195868eds.140.2023.07.13.09.53.47; Thu, 13 Jul 2023 09:54:15 -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=@redhat.com header.s=mimecast20190719 header.b=OtLS2MwF; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233535AbjGMQde (ORCPT + 99 others); Thu, 13 Jul 2023 12:33:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231559AbjGMQdT (ORCPT ); Thu, 13 Jul 2023 12:33:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0B33273E for ; Thu, 13 Jul 2023 09:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689265952; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=hA4oXFz7iMz2TN7Oq1WGXGk81ddHsb/K8fUHUI+fX50=; b=OtLS2MwFZtmhHALcbAOqfg0VM3aSQMTAgIKTdSrM3b77CGvvEQpJHjvIedSPQPRuTehfxi GiGKEQ2VUkSo2oAEQK9kNIqbeMwrmpAh7hI1X+gwODxTDPsP1rTe4zvcqD5BMccoRxW/ak gm9BJnfR2BzdEIY63e/ekEIYfEUS6ho= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-342-z80AxN_PNIqPEgABguwkCQ-1; Thu, 13 Jul 2023 12:32:24 -0400 X-MC-Unique: z80AxN_PNIqPEgABguwkCQ-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-315998d6e7fso591135f8f.3 for ; Thu, 13 Jul 2023 09:32:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689265942; x=1691857942; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hA4oXFz7iMz2TN7Oq1WGXGk81ddHsb/K8fUHUI+fX50=; b=H9AUQeY03zwN0DOv7L9l9pcU6X2PUyjopt+uorXgPjnH/agQtheuTYxZ28DV6q+Z3G GBVmsa6yi/NkRc/dYMMUeHTtXWJsFIJPAVKNjbfT6OVMeGTglzprBKzVhiDQdtRR9IAm T+fx+kh9mhA135D9xZYFhTSkgFwyIfgKI280GI8bSIB+sMFqWXDKo1llSXdDfrLCoUqH 50RtqKwfxrCdkUc0pWi49s8XciBpJ/KgXYnDrb7QwK6MbXG85Rs4ByBRNmC6z0fFciD0 gJ9z+FFPpLfqBOctyTqey+46OrHUKE7qUdpzytX0WnmKbI9spOGdlCeFAX4KVO/3LA10 Ncow== X-Gm-Message-State: ABy/qLaTN1BJLNP1u6MVtdw+LksBMWxRFtpLMRbzKmjdA4fq4BJXAHPL Abof2X/jxrcX4g4to+1cd1bObOK16hV9YnqGD9ClSnE11WQDDt6YElmmNDZDDjQWJwppstJDqZ6 SeKUnu5nS8joUCAJhQkcKq68M4JBI2rYZU+y+AugHuRjT8ReQlQ2bNO498A3N1EaQKZNKy/0vIp j1MU414RM= X-Received: by 2002:a05:6000:87:b0:314:449e:8536 with SMTP id m7-20020a056000008700b00314449e8536mr2005175wrx.10.1689265941820; Thu, 13 Jul 2023 09:32:21 -0700 (PDT) X-Received: by 2002:a05:6000:87:b0:314:449e:8536 with SMTP id m7-20020a056000008700b00314449e8536mr2005152wrx.10.1689265941523; Thu, 13 Jul 2023 09:32:21 -0700 (PDT) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id z13-20020adfe54d000000b003143ac73fd0sm8486974wrm.1.2023.07.13.09.32.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 09:32:21 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Javier Martinez Canillas , Geert Uytterhoeven , Daniel Vetter , David Airlie , dri-devel@lists.freedesktop.org Subject: [PATCH] drm/ssd130x: Fix an oops when attempting to update a disabled plane Date: Thu, 13 Jul 2023 18:32:06 +0200 Message-ID: <20230713163213.1028952-1-javierm@redhat.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Geert reports that the following NULL pointer dereference happens for him after commit 49d7d581ceaf ("drm/ssd130x: Don't allocate buffers on each plane update"): [drm] Initialized ssd130x 1.0.0 20220131 for 0-003c on minor 0 ssd130x-i2c 0-003c: [drm] surface width(128), height(32), bpp(1) and format(R1 little-endian (0x20203152)) Unable to handle kernel NULL pointer dereference at virtual address 00000000 Oops [#1] CPU: 0 PID: 1 Comm: swapper Not tainted 6.5.0-rc1-orangecrab-02219-g0a529a1e4bf4 #565 epc : ssd130x_update_rect.isra.0+0x13c/0x340 ra : ssd130x_update_rect.isra.0+0x2bc/0x340 ... status: 00000120 badaddr: 00000000 cause: 0000000f [] ssd130x_update_rect.isra.0+0x13c/0x340 [] ssd130x_primary_plane_helper_atomic_update+0x26c/0x284 [] drm_atomic_helper_commit_planes+0xfc/0x27c [] drm_atomic_helper_commit_tail+0x5c/0xb4 [] commit_tail+0x190/0x1b8 [] drm_atomic_helper_commit+0x194/0x1c0 [] drm_atomic_commit+0xa4/0xe4 [] drm_client_modeset_commit_atomic+0x244/0x278 [] drm_client_modeset_commit_locked+0x7c/0x1bc [] drm_client_modeset_commit+0x34/0x64 [] __drm_fb_helper_restore_fbdev_mode_unlocked+0xc4/0xe8 [] drm_fb_helper_set_par+0x38/0x58 [] fbcon_init+0x294/0x534 ... The problem is that fbcon calls fbcon_init() which triggers a DRM modeset and this leads to drm_atomic_helper_commit_planes() attempting to commit the atomic state for all planes, even the ones whose CRTC is not enabled. Since the primary plane buffer is allocated in the encoder .atomic_enable callback, this happens after that initial modeset commit and leads to the mentioned NULL pointer dereference. Fix this by not using the default drm_atomic_helper_commit_tail() helper, but instead the drm_atomic_helper_commit_tail_rpm() function that doesn't attempt to commit the atomic state for planes related to inactive CRTCs. Reported-by: Geert Uytterhoeven Signed-off-by: Javier Martinez Canillas --- drivers/gpu/drm/solomon/ssd130x.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ssd130x.c index afb08a8aa9fc..12820d16b15b 100644 --- a/drivers/gpu/drm/solomon/ssd130x.c +++ b/drivers/gpu/drm/solomon/ssd130x.c @@ -795,6 +795,10 @@ static const struct drm_mode_config_funcs ssd130x_mode_config_funcs = { .atomic_commit = drm_atomic_helper_commit, }; +static const struct drm_mode_config_helper_funcs ssd130x_mode_config_helpers = { + .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm, +}; + static const uint32_t ssd130x_formats[] = { DRM_FORMAT_XRGB8888, }; @@ -923,6 +927,7 @@ static int ssd130x_init_modeset(struct ssd130x_device *ssd130x) drm->mode_config.max_height = max_height; drm->mode_config.preferred_depth = 24; drm->mode_config.funcs = &ssd130x_mode_config_funcs; + drm->mode_config.helper_private = &ssd130x_mode_config_helpers; /* Primary plane */ -- 2.41.0