lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <202410160958.518EB9DB6@keescook>
Date: Wed, 16 Oct 2024 09:59:29 -0700
From: Kees Cook <kees@...nel.org>
To: Jonathan Cameron <Jonathan.Cameron@...wei.com>
Cc: Ira Weiny <ira.weiny@...el.com>, Dave Jiang <dave.jiang@...el.com>,
	Fan Ni <fan.ni@...sung.com>,
	Navneet Singh <navneet.singh@...el.com>,
	Jonathan Corbet <corbet@....net>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Dan Williams <dan.j.williams@...el.com>,
	Davidlohr Bueso <dave@...olabs.net>,
	Alison Schofield <alison.schofield@...el.com>,
	Vishal Verma <vishal.l.verma@...el.com>,
	linux-btrfs@...r.kernel.org, linux-cxl@...r.kernel.org,
	linux-doc@...r.kernel.org, nvdimm@...ts.linux.dev,
	linux-kernel@...r.kernel.org, "Li, Ming" <ming4.li@...el.com>,
	"Gustavo A . R . Silva" <gustavoars@...nel.org>
Subject: Re: [PATCH v4 08/28] cxl/mem: Read dynamic capacity configuration
 from the device

On Wed, Oct 16, 2024 at 04:54:15PM +0100, Jonathan Cameron wrote:
> On Sun, 13 Oct 2024 19:05:11 -0500
> Ira Weiny <ira.weiny@...el.com> wrote:
> 
> > Jonathan Cameron wrote:
> > > On Mon, 07 Oct 2024 18:16:14 -0500
> > > ira.weiny@...el.com wrote:
> > >   
> > > > From: Navneet Singh <navneet.singh@...el.com>
> > > > 
> > > > Devices which optionally support Dynamic Capacity (DC) are configured
> > > > via mailbox commands.  CXL 3.1 requires the host to issue the Get DC
> > > > Configuration command in order to properly configure DCDs.  Without the
> > > > Get DC Configuration command DCD can't be supported.
> > > > 
> > > > Implement the DC mailbox commands as specified in CXL 3.1 section
> > > > 8.2.9.9.9 (opcodes 48XXh) to read and store the DCD configuration
> > > > information.  Disable DCD if DCD is not supported.  Leverage the Get DC
> > > > Configuration command supported bit to indicate if DCD support.
> > > > 
> > > > Linux has no use for the trailing fields of the Get Dynamic Capacity
> > > > Configuration Output Payload (Total number of supported extents, number
> > > > of available extents, total number of supported tags, and number of
> > > > available tags). Avoid defining those fields to use the more useful
> > > > dynamic C array.
> > > > 
> > > > Cc: "Li, Ming" <ming4.li@...el.com>
> > > > Signed-off-by: Navneet Singh <navneet.singh@...el.com>
> > > > Co-developed-by: Ira Weiny <ira.weiny@...el.com>
> > > > Signed-off-by: Ira Weiny <ira.weiny@...el.com>  
> > > 
> > > Looks fine to me.  Trivial comment inline  
> > 
> > Thanks.
> > 
> > > Reviewed-by: Jonathan Cameron <Jonathan.Cameron@...wei.com>
> > > 
> > > 
> > >   
> > > > diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
> > > > index e8907c403edb..0690b917b1e0 100644
> > > > --- a/drivers/cxl/cxlmem.h
> > > > +++ b/drivers/cxl/cxlmem.h  
> > > ...
> > >   
> > > > +/* See CXL 3.1 Table 8-164 get dynamic capacity config Output Payload */
> > > > +struct cxl_mbox_get_dc_config_out {
> > > > +	u8 avail_region_count;
> > > > +	u8 regions_returned;
> > > > +	u8 rsvd[6];
> > > > +	/* See CXL 3.1 Table 8-165 */
> > > > +	struct cxl_dc_region_config {
> > > > +		__le64 region_base;
> > > > +		__le64 region_decode_length;
> > > > +		__le64 region_length;
> > > > +		__le64 region_block_size;
> > > > +		__le32 region_dsmad_handle;
> > > > +		u8 flags;
> > > > +		u8 rsvd[3];
> > > > +	} __packed region[];  
> > > 
> > > Could throw in a __counted_by I think?  
> > 
> > I was not sure if this would work considering this is coming from the hardware.
> > From what I have read I think it will but only because the region count can't
> > be byte swapped.
> 
> __counted_by_le() deals potentially larger values by just making
> the __counted_by go away on big endian architectures.
> 
> 
> > 
> > Is this something we want to do with structs coming from hardware when we can?
> 
> I think we still do.  Gustavo, Kees?

As long as "regions_returned" got correctly set by hardware before
anything in the kernel touches the "region" array, it can totally be
used by a __counted_by annotation.

-- 
Kees Cook

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ