netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Raghu Vatsavayi <rvatsavayi@caviumnetworks.com>
Cc: David Miller <davem@davemloft.net>, netdev@vger.kernel.org
Subject: [cavium] weirdness in cnnic_alloc_aligned_dma()
Date: Sat, 12 Dec 2015 18:41:28 +0000	[thread overview]
Message-ID: <20151212184128.GP20997@ZenIV.linux.org.uk> (raw)

IMO
                ptr =
                    (void *)__get_free_pages(GFP_KERNEL,
                                             get_order(size));
                if ((unsigned long)ptr & 0x07) {
                        free_pages((unsigned long)ptr, get_order(size));
                        ptr = NULL;
                        /* Increment the size required if the first
                         * attempt failed.
                         */
                        if (!retries)
                                size += 7;
                }

in drivers/net/ethernet/cavium/liquidio/octeon_main.h:cnnic_alloc_aligned_dma()
takes defensive programming a bit too far - "if the page returned by
__get_free_pages() is not 64bit-aligned" is not going to trigger until
we start to support an architecture with page size lower than 8 bytes,
which is... unlikely.

Either this code takes paranoia to a truly impressive level, or something
else had been intended.  I tried to guess what that something might've
been, but it's hard to do without seeing the history prior to the
moment when it went into mainline.  The bit in the end is particularly
interesting:
        if ((unsigned long)ptr & 0x07)
                ptr = (void *)(((unsigned long)ptr + 7) & ~(7UL));
That - after having rejected such misaligned pointers.

Something's fishy in that code...

                 reply	other threads:[~2015-12-12 18:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20151212184128.GP20997@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=rvatsavayi@caviumnetworks.com \
    /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).