kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: joshc@eso.teric.us (Josh Cartwright)
To: kernelnewbies@lists.kernelnewbies.org
Subject: single, comprehensive kernel data types document?
Date: Thu, 21 Apr 2016 14:34:27 -0500	[thread overview]
Message-ID: <20160421193427.GA26872@kryptos> (raw)
In-Reply-To: <1461243064.2108.2.camel@rtd-VirtualBox>

On Thu, Apr 21, 2016 at 08:51:04AM -0400, Rob Groner wrote:
> On Thu, 2016-04-21 at 11:51 +0900, Greg KH wrote:
> > On Wed, Apr 20, 2016 at 04:37:07PM -0400, Rob Groner wrote:
> > > Sorry if this isn't related, it seemed like it was...
> > > 
> > > I recently discovered one of our drivers isn't written correctly for
> > > 64-bit.  It uses a uint32_t to hold an address. Whoops.
> > > 
> > > In previous drivers when I've needed to hold an address, I've used an
> > > "unsigned long", as (so far as I could tell) that would give me the
> > > correct number of bytes whether on 32 or 64-bit systems.
> > > 
> > > Now that I have to fix this driver, I'd rather do whatever the
> > > "standard" method is for storing an address value.
> > > 
> > > Looking at code in the kernel and linux/types.h, I see "phys_addr_t and
> > > dma_addr_t.  Is that what I want to use?  What if it's a virtual
> > > address?  void *?
> > 
> > You want to use '__u64' and cast properly within the kernel to a
> > pointer.
> > 
> > hope this helps,
> > 
> > greg k-h
> 
> Thank you Greg.
> 
> I was thinking there was a type that would hold a memory address (like
> an allocated DMA buffer address, or a PCI address) that would be the
> correct size on a 32-bit or 64-bit system without me having to specify a
> size.  If I use __u64 to hold a memory address, won't that be the wrong
> size on a 32-bit system?

It will be bigger than is strictly necessary in that specific case, but
is that a problem?

Also, please consider the case where a user is running a 32-bit
userspace and a 64-bit kernel.  Not making datastructures which cross
the user/kernel boundaries make use of the largest fixed-width[1] type
means that the kernel would have to handle this case differently (in
fact, you can find many 'compat' examples in the kernel tree which do
just that, because the types were incorrectly used).  And, that's just
terrible :(.

  Josh

1: Just wanted to add it's not just about size of these datatypes,
   either.  It's about their alignment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160421/24c44cbd/attachment.bin 

  reply	other threads:[~2016-04-21 19:34 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-15 12:04 single, comprehensive kernel data types document? Robert P. J. Day
2016-04-15 12:27 ` Greg KH
2016-04-15 12:37   ` John Chludzinski
2016-04-15 13:08     ` Silvan Jegen
2016-04-15 13:09     ` Daniel.
2016-04-15 13:55       ` Greg KH
2016-04-15 16:28         ` Daniel.
2016-04-15 13:53     ` Greg KH
2016-04-15 15:59   ` Nicholas Mc Guire
2016-04-15 16:18     ` Greg KH
2016-04-15 17:07       ` Valdis.Kletnieks at vt.edu
2016-04-15 20:15         ` Greg KH
2016-04-20 20:37           ` Rob Groner
2016-04-21  2:51             ` Greg KH
2016-04-21 12:51               ` Rob Groner
2016-04-21 19:34                 ` Josh Cartwright [this message]
2016-04-22  2:37                 ` Greg KH
2016-04-22  3:02                   ` Valdis.Kletnieks at vt.edu
2016-04-22  3:13                     ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160421193427.GA26872@kryptos \
    --to=joshc@eso.teric.us \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).