Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp88178lqp; Sun, 9 Jun 2024 18:19:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVxFXm8kcq9chyCxXXnWIf2SbqBCblnctFMk1eLC6AFFhN10NXMfUhirb5EG5jYOkXG6ii1An+fy0FgECoHhsHHC5L+9oplCJ5zotxQ+w== X-Google-Smtp-Source: AGHT+IHEROP3BFI0XGxblssRdwr/exFxKcJ/IELAnf69PIj3DUekxNNPSLGWh5ZmZU5IZWAx9ZJt X-Received: by 2002:a05:6808:13ca:b0:3d2:19da:9573 with SMTP id 5614622812f47-3d219da96b2mr9289821b6e.15.1717982361243; Sun, 09 Jun 2024 18:19:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717982361; cv=pass; d=google.com; s=arc-20160816; b=V76AGSPxe4OFMcnjCI0EGdXLe4FXr0/sF+qC5lXeiz3stJvKcJgACa/eWDxwBzrHiG ejS9hGzrDibSEUx+OekUt1s1S6zQAvu2Ni7mcXbePVnGkwGW3tDAvdzUfkxe5HnmV2D7 lNnseNs1jA0QwcvSnWV3fyUv6zGBsdMsOqR2qVn4v583akywLPlFMbEp/oNUi/HNqP9f y07vULFRT/Sb+sj2pRDOUYL0I9NYbY7HuD04RHyA17CpoHKiowdWAYtLpmp5mrufkFDZ Jvt9CN9zF9Uqju+MgWC+xbQcsY3hfA18XumMPwhDhUeDjK8LIcpBvFAjLgt7Hs4LEIuJ xCNg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8uqVpGiW41LdDIPZDGk2krTR1nMbUR1Dbs/h7+D4MIY=; fh=j9nnfeBvIx3g2V21SGRFxMM4l/cnXxo00zKmU7KDkrE=; b=ehDPr/RM3FU44kWdhK6NVUCGHmjoHim8zaaJH6+8mVa0fJfu4vM1EQqYXIoEoywAwI oQHo02ylXZ2obCeDtqPmeHiOoAdP/ZNxhGZnvlTTCX676TFX3RLsQYMGfQWBiVkVzAcy MirU8tO2K1CyaKH2Gu7LISMOMUz7MrAawP0OzfYaW4wttJoOgK8LsEhX013flXIOpo98 306B5L+ToZWyr5bcA64a7yGB4XMRvxc9OBLdQvgYTlJyn3sXtK6zeasSL1S4Bcr/i8bR rxJh49nUM5Irc6Zhnl1H8qWN0w9WbNoa44K/leUMYm8RV8qBrZ1ACOaT6vzoJ9okO7KG q3Pg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VEUQCCzl; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-207585-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207585-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-44038a7ed1dsi65801271cf.163.2024.06.09.18.19.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 18:19:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207585-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VEUQCCzl; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-207585-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207585-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D3CDD1C214E1 for ; Mon, 10 Jun 2024 01:19:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A4DC187F; Mon, 10 Jun 2024 01:19:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VEUQCCzl" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 75C0C17C2 for ; Mon, 10 Jun 2024 01:19:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717982354; cv=none; b=dZtYdFROZ+17YjQTGrR6P96vyaQMz0vxQXqm8+WhnFR9+9Y7CcIoKO0mFBNKF4XNqciamCl6QZ9Yb1HMCWvZERq9iyqxqBe6SaR4QFkjgFJZTpEkfaSaP1c4D30vGmhSioVorhVOnt3l/BgEBAD8zh39TB7OKM4BNsXG1b6CmHY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717982354; c=relaxed/simple; bh=fqBk4xUxelINKuqmz+ewnOVgrq3/8aUv13chp0wuTaM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=diK5RyVW3/gXrkdfFrXEFMcUQnnjo27IB08ZaBmEwHVdbvRDIS+/Ka013lpo4uciSR3xAAW/mnAYk57Pt1liTRq0sK0MkbG3kjHt/OnMDIMLb5m7Pnu/W1zUIGO9TQQs39Yym3jOmv5e6wDoBM8p3pKYd9A240qOU8qaBt3ef4U= 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=VEUQCCzl; arc=none smtp.client-ip=170.10.129.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717982351; 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: in-reply-to:in-reply-to:references:references; bh=8uqVpGiW41LdDIPZDGk2krTR1nMbUR1Dbs/h7+D4MIY=; b=VEUQCCzlJGsP+gBWWFgEcEXt5nVUlSW7ghcIovM+Tyv9hPW/FSEOwePpZqzdJHEPcc0fP7 F+2uGEDEbR9PyExixG21qPwHUtTWdArDoBZBFGQTjCBPf1uN4ekp7hBpVkzngtTbqKhM5L dgOqogFrb0C09Zfs77VBZBFvWD7I/fE= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-389-OYqCyoXeOyS0ZDmtYLfsgg-1; Sun, 09 Jun 2024 21:19:04 -0400 X-MC-Unique: OYqCyoXeOyS0ZDmtYLfsgg-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F0954195608B; Mon, 10 Jun 2024 01:19:01 +0000 (UTC) Received: from localhost (unknown [10.72.113.124]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C3D5630000C3; Mon, 10 Jun 2024 01:18:58 +0000 (UTC) Date: Mon, 10 Jun 2024 09:18:53 +0800 From: Baoquan He To: Coiby Xu Cc: kexec@lists.infradead.org, Ondrej Kozina , Milan Broz , Thomas Staudt , Daniel P =?iso-8859-1?Q?=2E_Berrang=E9?= , Kairui Song , Jan Pazdziora , Pingfan Liu , Dave Young , linux-kernel@vger.kernel.org, x86@kernel.org, Dave Hansen , Vitaly Kuznetsov , Vivek Goyal , Kees Cook , "Gustavo A. R. Silva" , "open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_byb" Subject: Re: [PATCH v4 2/7] crash_dump: make dm crypt keys persist for the kdump kernel Message-ID: References: <20240523050451.788754-1-coxu@redhat.com> <20240523050451.788754-3-coxu@redhat.com> <5gj3rxxf7tgolj72mxwnbjirxrlx3pezvqcegyiuenwr55njoo@6dg2toxu6vah> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5gj3rxxf7tgolj72mxwnbjirxrlx3pezvqcegyiuenwr55njoo@6dg2toxu6vah> X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 On 06/07/24 at 08:27pm, Coiby Xu wrote: > On Wed, Jun 05, 2024 at 04:22:12PM +0800, Baoquan He wrote: > > On 05/23/24 at 01:04pm, Coiby Xu wrote: > > ..... > > > diff --git a/kernel/crash_dump_dm_crypt.c b/kernel/crash_dump_dm_crypt.c > > > new file mode 100644 > > > index 000000000000..78809189084a > > > --- /dev/null > > > +++ b/kernel/crash_dump_dm_crypt.c > > > @@ -0,0 +1,113 @@ > > > +// SPDX-License-Identifier: GPL-2.0-only > [...] > > > + > > > +static unsigned int key_count; > > > +static size_t keys_header_size; > > > > These two global variables seems not so necessary. Please see comment at > > below. > > Thanks for the comment! But I think it's better to keep these two static > variables for reasons as will be explained later. > > > > > > + > > > +struct dm_crypt_key { > > > + unsigned int key_size; > > > + char key_desc[KEY_DESC_LEN]; > > > + u8 data[KEY_SIZE_MAX]; > > > +}; > > > + > > > +static struct keys_header { > > > + unsigned int key_count; > > ~~~~~~~~ > > This is the max number a system have from init(); > > You can add one field member to record how many key slots have been > > used. > > > + struct dm_crypt_key keys[] __counted_by(key_count); > > > +} *keys_header; > > > > Maybe we can rearrange the keys_header like below, the name may not be > > very appropriate though. > > > > static struct keys_header { > > unsigned int max_key_slots; > > unsigned int used_key_slots; > > struct dm_crypt_key keys[] __counted_by(key_count); > > } *keys_header; > > Thanks for the suggestion! Since 1) KEY_NUM_MAX already defines the > maximum number of dm crypt keys 2) we only need to let the kdump kernel > now how many keys are saved, so I simply use total_keys instead of > key_count in struct keys_header in v5, > > static struct keys_header { > unsigned int total_keys; > struct dm_crypt_key keys[] __counted_by(total_keys); > } *keys_header; > > Hopefully this renaming will improve code readability. If you add key_count into keys_header, then kdump kernel will know how many keys are really saved and need be retrieved. What's your concern when you have to put key_count outside and take it as a global variable? > > > > > > > > > > > + > > > +static size_t get_keys_header_size(struct keys_header *keys_header, > > > + size_t key_count) > > > +{ > > > + return struct_size(keys_header, keys, key_count); > > > +} > > > > I personally don't think get_keys_header_size is so necessary. If we > > have to keep it, may be we can remove the global variable > > keys_header_size, we can call get_keys_header_size() and use local > > variable to record the value instead. > > Thanks for the suggestion! But the kdump kernel also need to call > get_keys_header_size in later patches. If so, you can remove keys_header_size now. You can define local variable to take the newly calculated value. keys_header_size seems not so necesary. By the way, you don't need to rush to post v5. When people review patches, agreement need be reached after discussion. Then next version can be posted.