Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3111917pxb; Tue, 24 Aug 2021 15:40:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzvrbHQhDqeiEl4UCENQXBbvrwDKcaHh/BzXhv4ufliSFm2NWfMH+WhefLWrA1bCWt/fU+ X-Received: by 2002:a05:6402:51c7:: with SMTP id r7mr45142913edd.65.1629844844699; Tue, 24 Aug 2021 15:40:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629844844; cv=none; d=google.com; s=arc-20160816; b=WyYLK9fO/mfjLyH5dNaOCYs9ucyNGXlQyw8ir242CMd93TwOlG/ajBSzbN8N3waoGM ufIGYhpViZSzSwOMWdksRtb9LAoj2K596fIUlIYHuhMw1KEVbXnAXWd7D+TjvgAiCg8u nIxvExUD8hIu1fKxddgTCeipeJuiKNWnrQlK+3YZGXpRybUW8ApqQHpuRB4c0HEdcgkn mQ8KG5pkzqjp1hf/8S/7US5BdqJdxoHZjJkILUpLthGr+3waab/gfWhj/b9euDIjpud1 vqb06JMYo/nO1GAXde3L9HmC5qbmsEh9SorKDZzbPFyVKqLB614QR1DrcmnpfmYpl4hu doGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Td/u1Sn1tUZu8969rNtU4fTsswCeKHjwQrWdew+s+rM=; b=HNsQa+tLcqH6O7eqaTb/wgBJHXwhkR7Z3Gs5ypia/oCxby5iv2UyRbGImW/yaAFZVr ncD8BgXc6uEw3CoPOTdslHV1LsWKkdd3cO3+0NkkK4t6a4H8TthOS4Fe26ECEhX4qjXQ c33mYjs8c49uDm9k9oop3p+y3nFJQngF+KxjBA8CMj5sPeVAxFHW+3dQ0XuqGBmR/udT +6PHYTBBa/1tn7Km2c2FoEJxskD7QIu6kRcUIbypi8TH4KQQO1jSn2VL6pOsDyBZNHWa jRBjzv8sVa1eL6dRNF7rlrsO8JVixecYP6mi3Vq0ZEB8jUKItKGGyFPbF/wPi8YGj3kn LFdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BOQ3wE1N; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f10si18586973ejf.597.2021.08.24.15.40.21; Tue, 24 Aug 2021 15:40:44 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BOQ3wE1N; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229840AbhHXWip (ORCPT + 99 others); Tue, 24 Aug 2021 18:38:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:45564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbhHXWip (ORCPT ); Tue, 24 Aug 2021 18:38:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 986E2613AB for ; Tue, 24 Aug 2021 22:38:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629844680; bh=trvQSX2rJRWjrNLaSeH+EoF98vW2AeDpatiSlRzrcrM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=BOQ3wE1NmwwPIhLseOygSis856eUvkrahEq4aiqKLmaO3y9KYD64UwBdzswDFfqCb Kp3yOn6+0ib0Fdes7D0p0skaQ/9i4sskpzE3VaHTjQw2HL6TAg122msA9RhoLPv++t 0IJDPVMi7TlacxqI5dozaMeJAiFbTzB26TYaIQsl1KdT9X2siLWEd5HvO3pBYfTPZj YS7mbExQ05LT9xslKXZ78ctoqv+EbULUMqnb+M9Pr4IRqyB3t7te6vwHUVfiadFpOb elf66iqlxjfm9ey9vDLYq526GDegXBwIrfowaFaYZ4y1l/1RqrCh2cIH3HGeKElqDd u/k2xp4vbsavg== Received: by mail-ed1-f49.google.com with SMTP id d6so34068206edt.7 for ; Tue, 24 Aug 2021 15:38:00 -0700 (PDT) X-Gm-Message-State: AOAM531fHiOi2syUrZ0TrHoXpQS8pKv8S+RdgAd82DJ4c48YWLf6/LEw XeLDKlOiU5wru6Jy9DIhb8PcRsqQ126pI7B78Q== X-Received: by 2002:aa7:c487:: with SMTP id m7mr25907783edq.62.1629844679242; Tue, 24 Aug 2021 15:37:59 -0700 (PDT) MIME-Version: 1.0 References: <20210824173028.7528-1-alyssa.rosenzweig@collabora.com> In-Reply-To: <20210824173028.7528-1-alyssa.rosenzweig@collabora.com> From: Rob Herring Date: Tue, 24 Aug 2021 17:37:47 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 0/4] drm/panfrost: Bug fixes for lock_region To: Alyssa Rosenzweig Cc: dri-devel , Tomeu Vizoso , Steven Price , David Airlie , Daniel Vetter , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 24, 2021 at 12:30 PM Alyssa Rosenzweig wrote: > > Chris Morgan reported UBSAN errors in panfrost and tracked them down to > the size computation in lock_region. This calculation is overcomplicated > (cargo culted from kbase) and can be simplified with kernel helpers and > some mathematical identities. The first patch in the series rewrites the > calculation in a form avoiding undefined behaviour; Chris confirms it > placates UBSAN. > > While researching this function, I noticed a pair of other potential > bugs: Bifrost can lock more than 4GiB at a time, but must lock at least > 32KiB at a time. The latter patches in the series handle these cases. > > In review of v1 of this series, Steven pointed out a fourth potential > bug: rounding down the iova can truncate the lock region. v2 adds a new > patch for this case. > > The size computation was unit-tested in userspace. Relevant code below, > just missing some copypaste definitions for fls64/clamp/etc: > > #define MIN_LOCK (1ULL << 12) > #define MAX_LOCK (1ULL << 48) > > struct { > uint64_t size; > uint8_t encoded; > } tests[] = { > /* Clamping */ > { 0, 11 }, > { 1, 11 }, > { 2, 11 }, > { 4095, 11 }, > /* Power of two */ > { 4096, 11 }, > /* Round up */ > { 4097, 12 }, > { 8192, 12 }, > { 16384, 13 }, > { 16385, 14 }, > /* Maximum */ > { ~0ULL, 47 }, > }; > > static uint8_t region_width(uint64_t size) > { > size = clamp(size, MIN_LOCK, MAX_LOCK); > return fls64(size - 1) - 1; > } > > int main(int argc, char **argv) > { > for (unsigned i = 0; i < ARRAY_SIZE(tests); ++i) { > uint64_t test = tests[i].size; > uint8_t expected = tests[i].encoded; > uint8_t actual = region_width(test); > > assert(expected == actual); > } > } > > Changes in v2: > > * New patch for non-aligned lock addresses > * Commit message improvements. > * Add Steven's tags. > > Alyssa Rosenzweig (4): > drm/panfrost: Simplify lock_region calculation > drm/panfrost: Use u64 for size in lock_region > drm/panfrost: Clamp lock region to Bifrost minimum > drm/panfrost: Handle non-aligned lock addresses > > drivers/gpu/drm/panfrost/panfrost_mmu.c | 32 ++++++++++-------------- > drivers/gpu/drm/panfrost/panfrost_regs.h | 2 ++ > 2 files changed, 15 insertions(+), 19 deletions(-) For the series, Reviewed-by: Rob Herring