From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 530BA1422B4 for ; Fri, 12 Jul 2024 07:30:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720769407; cv=none; b=Q5BhsQBbEwUsoVmh4dWiXwbLUfrFaM0Yb77Yuq1D6+Uvyef8hxA8V1jnIxEwxmYXD4Whbca+IKKx+rdhyZ6uXkYO7ab+m5RwokYv3TmrEElKDW0MnWFYrJbDV53fH1hDkAD0u40YOruEwdWtct4KiejPoyBU6MKi+ZMCa+5nelU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720769407; c=relaxed/simple; bh=cWObtkrQ/W2rBwxO/CryoOoAf5fvCGGgv8tIzCaY3bc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=QMCbPGDu9+1x38sB/zLlzuZ8e/YqsD8T0EUfuWc6j9LswRMI26+yWluuFFzBZxgIcyDpuv/e5nqKoEXI0HdecPaIE8w1zSr30B7iL1uDggYqKgP+smnAJKFJUS/6op8adWUbP5M7tur4hsumBfTFkTAbv8YoCw1FjF5jQgytstg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TEBswgtF; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TEBswgtF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720769404; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ILAmKBMNHWPnZ2pjReNeFpsObqxNz8daqyUuTWpbm+o=; b=TEBswgtFea34CHA3LWOXr3kM5dOmGBygMozcr5CTjDoxQ80Ml7g7W2YvaKWpKW2ZE2XYp3 6mZAIA26nRzysLhFNp6DJAiVPV9ONVjy5aFKCmOHBtcq9v5GsaLheqQEsRmhTgiipRQ1nE yiSI6HwqFNOkWoHd3n7hPYok2e3GMXk= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-582-gNqd5kWnOtGqZClW2TBpiQ-1; Fri, 12 Jul 2024 03:30:02 -0400 X-MC-Unique: gNqd5kWnOtGqZClW2TBpiQ-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2ee9b383ffbso15996181fa.1 for ; Fri, 12 Jul 2024 00:30:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720769401; x=1721374201; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ILAmKBMNHWPnZ2pjReNeFpsObqxNz8daqyUuTWpbm+o=; b=fcGQR7cSpwmp7ff7GXYU372cvuU5f70pXT0NNgUV+P/JJ5WlQLt9bAemrWTAwjlt8n h5WgO3NhA2CjwgJjUj2do9QShMjHpoXnItRzNlx/K6sh3fx/TT5IJz4+rs0tFmwoRLW1 cEApAGBDfBRpQSR2Rhwz4salmpBJw7eMVEvlgjgkKbyWr56lGGihQ/vrZDKC8gyC/JA3 CYBomEwfaJizXvIBobtiejJOUzMS2I3O0BCXrEnPG0ihRotbYMUXj1Vkp3UwLRbJILI2 HPRa/gnuMpHODSie6Z94GciPS1h94IW0qlnktTVG75C6Iqecjyxo4C+7aO2/j/yZ+sEC eFtA== X-Forwarded-Encrypted: i=1; AJvYcCUzV54RqHoBWpDHNQBleADPKkxvV56o9tv/hTMeX/dFbVZwqUY4J50Ol8L7uKqx6iagXChntXyHl2D/eHftzDprHOBNC4sW9snA91Y8Db0= X-Gm-Message-State: AOJu0YwJfsLrf/B6Se07akQqvITxvdVeD8ZmfB+7M+EKFdl+72QzT/g7 NGxYHTYqQw7IAcuWSHG6WyfqCoOLluK+8JkBEdAvrq9fFvIlVT/rwXYwsMIsRj4o6wi3sJXTz97 nQQDo5K5GicEjBDiotRkv8hPxgHFxn6PAbOnLx+BG1BExjVvatjpwn1VXWriXail2 X-Received: by 2002:a2e:9807:0:b0:2ee:7b93:5209 with SMTP id 38308e7fff4ca-2eeb318ab22mr65445421fa.45.1720769401023; Fri, 12 Jul 2024 00:30:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzHmvOfNeAufY8WCgrB3W4dZCi5V0aic+d0AtYJyfpAXNcvaXnAhrQm6IfEMXXxggTNKyIzQ== X-Received: by 2002:a2e:9807:0:b0:2ee:7b93:5209 with SMTP id 38308e7fff4ca-2eeb318ab22mr65445191fa.45.1720769400563; Fri, 12 Jul 2024 00:30:00 -0700 (PDT) Received: from ?IPV6:2a01:e0a:c:37e0:ced3:55bd:f454:e722? ([2a01:e0a:c:37e0:ced3:55bd:f454:e722]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4279f2ba7b0sm12846045e9.37.2024.07.12.00.29.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 00:29:59 -0700 (PDT) Message-ID: Date: Fri, 12 Jul 2024 09:29:58 +0200 Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 4/4] drm/panic: Add a QR code panic screen To: Alice Ryhl Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , Bjorn Roy Baron , Benno Lossin , Andreas Hindborg , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org, Danilo Krummrich References: <20240710140057.347384-1-jfalempe@redhat.com> <20240710140057.347384-5-jfalempe@redhat.com> From: Jocelyn Falempe In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US, fr Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 11/07/2024 23:00, Alice Ryhl wrote: > On Wed, Jul 10, 2024 at 4:01 PM Jocelyn Falempe wrote: >> >> This patch adds a new panic screen, with a QR code and the kmsg data >> embedded. >> If DRM_PANIC_SCREEN_QR_CODE_URL is set, then the kmsg data will be >> compressed with zlib and encoded as a numerical segment, and appended >> to the URL as a URL parameter. This allows to save space, and put >> about ~7500 bytes of kmsg data, in a V40 QR code. >> Linux distributions can customize the URL, and put a web frontend to >> directly open a bug report with the kmsg data. >> >> Otherwise the kmsg data will be encoded as a binary segment (ie raw >> ascii) and only a maximum of 2953 bytes of kmsg data will be >> available in the QR code. >> >> You can also limit the QR code size with DRM_PANIC_SCREEN_QR_VERSION. >> >> v2: >> * Rewrite the rust comments with Markdown (Alice Ryhl) >> * Mark drm_panic_qr_generate() as unsafe (Alice Ryhl) >> * Use CStr directly, and remove the call to as_str_unchecked() >> (Alice Ryhl) >> * Add a check for data_len <= data_size (Greg KH) >> >> v3: >> * Fix all rust comments (typo, punctuation) (Miguel Ojeda) >> * Change the wording of safety comments (Alice Ryhl) >> * Add a link to the javascript decoder in the Kconfig (Greg KH) >> * Fix data_size and tmp_size check in drm_panic_qr_generate() >> >> Signed-off-by: Jocelyn Falempe >> --- > > Overall, it looks reasonable to me. Some comments below. > > The changelog should go below the --- or in the cover letter. > >> + if (stream.total_out > max_qr_data_size) { >> + /* too much data for the QR code, so skip the first line and try again */ >> + kmsg = strchr(kmsg + 1, '\n'); >> + if (!kmsg) >> + return -EINVAL; >> + kmsg_len = strlen(kmsg); >> + goto try_again; > > It seems like kmsg will start with a newline character when this retry > routine runs. Is that really what you want? Why not instead strchr and > then do the plus one afterwards? Good catch, yes I should increment kmsg after the strchr, to skip the '\n' character. > > This would also simplify the logic for why `kmsg + 1` doesn't go out > of bounds. Right now I have to check that there's no codepath where > kmsg points at the nul terminator byte. sure, I will do that for v4. > >> +const __LOG_PREFIX: &[u8] = b"rust_qrcode\0"; > > I guess this constant is because you're not using the module! macro? I think it's a leftover of when I used pr_info!() to debug my rust code. Drm panic is built within the main drm module, and is not a module on its own, so I'm not sure if I can use the module! macro here. > >> +/// C entry point for the rust QR Code generator. >> +/// >> +/// Write the QR code image in the data buffer, and return the QR code width, >> +/// or 0, if the data doesn't fit in a QR code. >> +/// >> +/// * `url`: The base URL of the QR code. It will be encoded as Binary segment. >> +/// * `data`: A pointer to the binary data, to be encoded. if URL is NULL, it >> +/// will be encoded as binary segment, otherwise it will be encoded >> +/// efficiently as a numeric segment, and appended to the URL. >> +/// * `data_len`: Length of the data, that needs to be encoded, must be less >> +/// than data_size. >> +/// * `data_size`: Size of data buffer, it should be at least 4071 bytes to hold >> +/// a V40 QR code. It will then be overwritten with the QR code image. >> +/// * `tmp`: A temporary buffer that the QR code encoder will use, to write the >> +/// segments and ECC. >> +/// * `tmp_size`: Size of the temporary buffer, it must be at least 3706 bytes >> +/// long for V40. >> +/// >> +/// # Safety >> +/// >> +/// * `url` must be null or point at a nul-terminated string. >> +/// * `data` must be valid for reading and writing for `data_size` bytes. >> +/// * `tmp` must be valid for reading and writing for `tmp_size` bytes. >> +/// >> +/// They must remain valid for the duration of the function call. >> + >> +#[no_mangle] >> +pub unsafe extern "C" fn drm_panic_qr_generate( >> + url: *const i8, >> + data: *mut u8, >> + data_len: usize, >> + data_size: usize, >> + tmp: *mut u8, >> + tmp_size: usize, >> +) -> u8 { >> + if data_size < 4071 || tmp_size < 3706 || data_len > data_size { >> + return 0; >> + } >> + // SAFETY: The caller ensures that `data` is a valid pointer for reading and >> + // writing `data_size` bytes. >> + let data_slice: &mut [u8] = unsafe { core::slice::from_raw_parts_mut(data, data_size) }; >> + // SAFETY: The caller ensures that `tmp` is a valid pointer for reading and >> + // writing `tmp_size` bytes. >> + let tmp_slice: &mut [u8] = unsafe { core::slice::from_raw_parts_mut(tmp, tmp_size) }; >> + if url.is_null() { >> + match EncodedMsg::new(&[&Segment::Binary(&data_slice[0..data_len])], tmp_slice) { >> + None => 0, >> + Some(em) => { >> + let qr_image = QrImage::new(&em, data_slice); >> + qr_image.width >> + } >> + } >> + } else { >> + // SAFETY: The caller ensures that `url` is a valid pointer to a >> + // nul-terminated string. >> + let url_cstr: &CStr = unsafe { CStr::from_char_ptr(url) }; >> + let segments = &[ >> + &Segment::Binary(url_cstr.as_bytes()), >> + &Segment::Numeric(&data_slice[0..data_len]), >> + ]; >> + match EncodedMsg::new(segments, tmp_slice) { >> + None => 0, >> + Some(em) => { >> + let qr_image = QrImage::new(&em, data_slice); >> + qr_image.width >> + } >> + } >> + } >> +} > > This looks good to me. :) Thanks a lot > > Alice > -- Jocelyn