Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp1870445rdb; Sun, 27 Aug 2023 00:20:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE8gDuT8EkKwh0gRhuVIJI27TDHlOr24zrkPkxDn11GVoJbBCWvM4ip5Uo8TECSdkJQctv5 X-Received: by 2002:aca:e1d6:0:b0:3a7:25c6:7b85 with SMTP id y205-20020acae1d6000000b003a725c67b85mr6568315oig.47.1693120813173; Sun, 27 Aug 2023 00:20:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693120813; cv=none; d=google.com; s=arc-20160816; b=LoZW1171e7aF1EpQUSzgVszkemAWZ+kGv12A5jBxhZMfnEID2ORc6WaE4VgAVbI43Q 11IN54uKLW3sfE/Xct2pnVfJpYlBVuJzIwawb/0mr8F2rjSpCMzr+f0/oZ+VfIjUsNnf BkI3lPwFF7f9Vyi6N//GSpM7q73g880Am3fADVHSrZ0VuaXu3m5Vf62oBXweyerVrV2C 1FaNBi4iN6OEtyHbIyAcws1j35SgPakNEloFi0n/6CIP/v1dx0Fp8q44OSQS1OJqokAV d2lYoAbHlxnX+YYmmQ0hopFPIsoa9Ca487wc6+MHPrs2SL0EUuHMJXL9VBQjRem+OE71 6E2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=a2QNVHpCy69phGF1UsAYo4X/AG2eDB3F/Vurqfii8Wo=; fh=T+vLOkvralpMwlq7MZLt75E0BAMkOxziO/RjZQGe3ak=; b=EMrwviEvuX143xvE7JuRV/7rolhmi88Uv9nUxGlNfAkNs5+2AqZy1g1VWUsb37LRUp OHSWnMzASlaiURkCzUGXdi9798zymZUrfZDxH2rTelEiZ8n87wXRgIvFJYkhN8FXOyQB kR3ghlS1aEq4y4f5mwsw3btrQuReWnTkngZrZ0zucGmyLcm9QdcYckjqFHXrpFJeUNPk mVjmGJfG98QMEg/Eath7shJ3OmBgrqkHbhkHSOJB+cFZNeik+SkRS5zoyI5YeNenNFI7 JfsMRloIsdcdmmFiT30x+rw41ww9OBO/2eIPeHptIIAfGHu6D23tV9esDgwBWgG8r/D8 ONPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@equiv.tech header.s=mx header.b=XoLrmrvv; 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=REJECT sp=REJECT dis=NONE) header.from=equiv.tech Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x10-20020a17090a8a8a00b0026d44039e32si5005320pjn.16.2023.08.27.00.19.53; Sun, 27 Aug 2023 00:20:13 -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=@equiv.tech header.s=mx header.b=XoLrmrvv; 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=REJECT sp=REJECT dis=NONE) header.from=equiv.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229923AbjH0HG5 (ORCPT + 88 others); Sun, 27 Aug 2023 03:06:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229888AbjH0HG3 (ORCPT ); Sun, 27 Aug 2023 03:06:29 -0400 Received: from so254-32.mailgun.net (so254-32.mailgun.net [198.61.254.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D37018F for ; Sun, 27 Aug 2023 00:06:25 -0700 (PDT) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=equiv.tech; q=dns/txt; s=mx; t=1693119984; x=1693127184; h=In-Reply-To: Content-Type: MIME-Version: References: Message-ID: Subject: Subject: Cc: To: To: From: From: Date: Sender: Sender; bh=a2QNVHpCy69phGF1UsAYo4X/AG2eDB3F/Vurqfii8Wo=; b=XoLrmrvvUEMbf1dzDmEFxWOfhNfO+VVJIak4YGVIXVwsqOqVwm+MVfnlUj2zZhVoEYB/iy1tLE6Tm896zz+Z5c79bW1tl5OBFL2H/7TvWVa5uUmOe+Mqc+JHd80F/w7dykkyqr3RB7lLWYw01B4IIH7nu1MBsQ5RinPBSlOB36jBYhxK95CxCwuQ+ciVvxZJCOup3/9zklPvzTugULv9zV8cw8v7HC7ii53VJQW0swniiIMD49u6Aa5ILJVuBReUOoTYZTFyg4dLKABCZBgdeEobaCZX2v+DIMpv5mgvpvwV0sWtmwJ3WhVMeRCuA3wuF4aGxKRJY4BFzmExSUcvDQ== X-Mailgun-Sending-Ip: 198.61.254.32 X-Mailgun-Sid: WyI4ZWI3MiIsImxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmciLCI5M2Q1YWIiXQ== Received: from mail.equiv.tech (equiv.tech [142.93.28.83]) by 6fa3ba917c3f with SMTP id 64eaf5f0cd2de71bad0a6c9f (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Sun, 27 Aug 2023 07:06:24 GMT Sender: james@equiv.tech Date: Sun, 27 Aug 2023 00:06:23 -0700 From: James Seo To: Kees Cook Cc: Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani , "James E.J. Bottomley" , "Martin K. Petersen" , "Gustavo A. R. Silva" , MPT-FusionLinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 03/12] scsi: mpt3sas: Make MPI2_CONFIG_PAGE_RAID_VOL_0::PhysDisk[] a flexible array Message-ID: References: <20230806170604.16143-1-james@equiv.tech> <20230806170604.16143-4-james@equiv.tech> <202308251357.38AF364@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <202308251357.38AF364@keescook> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,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_PASS 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 Fri, Aug 25, 2023 at 02:03:23PM -0700, Kees Cook wrote: > On Sun, Aug 06, 2023 at 10:05:55AM -0700, James Seo wrote: >> This terminal 1-length variable array can be directly converted into >> a C99 flexible array member. >> >> As all users of MPI2_CONFIG_PAGE_RAID_VOL_0 (Mpi2RaidVolPage0_t) >> either calculate its size without depending on its sizeof() or do not >> use PhysDisk[], no further source changes are required: > > Tons of binary changes in this file too. I see this: > > Mpi2RaidVolPage0_t config_page; > ... > r = _config_request(ioc, &mpi_request, &mpi_reply, > MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, &config_page, > sizeof(Mpi2RaidVolPage0_t)); > > So it's already changing this size (and possibly under-allocating now). Yes. I didn't explicitly identify _config_request() as a user of the five structs for which I parted out changes into their own commits, as it's a generalized helper indirectly called when working with other config page structs as well. Rest assured that I took it into account, and that the reduced struct sizes don't represent under-allocations (see below). >> - mpt3sas_config.c:mpt3sas_config_get_number_pds() fetches a >> Mpi2RaidVolPage0_t for itself, but does not use PhysDisk[]. > > Is it certain that _config_request()'s use of mpt3sas_wait_for_ioc() > won't result in the hardware being upset that config_page_sz shrank? Sorry if I missed it, but I don't see what config_page_sz has to do with _config_request()'s use of mpt3sas_wait_for_ioc(). Could you explain what you meant? More generally, changes in config_page_sz shouldn't faze the hardware because all usages of _config_request() occur in pairs - a preparatory call that returns the actual size of a given config page in mpi_reply, then a follow-up call during which a temporary DMA-capable buffer is allocated per the size in mpi_reply and the hardware reads/writes the entirety of this buffer. config_page_sz just determines the number of bytes copied between config_page and the temp buffer after a hardware read/before a hardware write. Well, as far I can tell, anyway. Maybe Broadcom knows otherwise. >> @@ -1826,8 +1823,7 @@ typedef struct _MPI2_CONFIG_PAGE_RAID_VOL_0 { >> U8 Reserved2; /*0x25 */ >> U8 Reserved3; /*0x26 */ >> U8 InactiveStatus; /*0x27 */ >> - MPI2_RAIDVOL0_PHYS_DISK >> - PhysDisk[MPI2_RAID_VOL_PAGE_0_PHYSDISK_MAX]; /*0x28 */ >> + MPI2_RAIDVOL0_PHYS_DISK PhysDisk[]; /*0x28 */ >> } MPI2_CONFIG_PAGE_RAID_VOL_0, > > Without the mpt3sas maintainers chiming in on this, I think the only > safe changes to make here are those with 0 binary differences. So for > things like this, it'll need to be: > > - MPI2_RAIDVOL0_PHYS_DISK > - PhysDisk[MPI2_RAID_VOL_PAGE_0_PHYSDISK_MAX]; /*0x28 */ > + union { > + MPI2_RAIDVOL0_PHYS_DISK legacy_padding; /*0x28 */ > + DECLARE_FLEX_ARRAY(MPI2_RAIDVOL0_PHYS_DISK, PhysDisk); > + }; > > -- > Kees Cook Thanks for clearing that up. Here's hoping those mpt3sas maintainers do chime in. I'll go with the union workaround if they don't. James