mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: kys@microsoft.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com,
	jasowang@redhat.com
Subject: Re: [PATCH V2 1/6] Drivers: net: hyperv: Enable scatter gather I/O
Date: Fri, 07 Mar 2014 16:47:56 -0500 (EST)	[thread overview]
Message-ID: <20140307.164756.1488071770631289333.davem@davemloft.net> (raw)
In-Reply-To: <1394170361-1043-1-git-send-email-kys@microsoft.com>

From: "K. Y. Srinivasan" <kys@microsoft.com>
Date: Thu,  6 Mar 2014 21:32:36 -0800

> +static u32 fill_pg_buf(struct page *page, u32 offset, u32 len,
> +			struct hv_page_buffer *pb)
> +{
> +	int j = 0;
> +
> +	/* Deal with compund pages by ignoring unused part
> +	 * of the page.
> +	 */
> +	page += offset  >> PAGE_SHIFT;

Please only one space between "offset" and ">>"

> +	offset &= ~PAGE_MASK;
> +
> +	while (len > 0) {
> +		unsigned long bytes;
> +
> +		bytes = PAGE_SIZE - offset;
> +		if (bytes > len)
> +			bytes = len;
> +		pb[j].pfn = page_to_pfn(page);
> +		pb[j].offset = offset;
> +		pb[j].len = bytes;
> +
> +		offset += bytes;
> +		len -= bytes;
> +
> +		if (offset == PAGE_SIZE && len) {
> +			page++;
> +			offset = 0;
> +			j++;
> +		}
> +	}
> +
> +	return j + 1;
> +}

I think this function has some edge case errors.

As I understand it, this function returns how many page buffer entries
were filled in.

But if we fill exactly the end of a page, we will report one too many
in the return value.

Consider an "offset" of X, where X is smaller than PAGE_SIZE.  And a
"len" which is exactly "PAGE_SIZE - offset".

We will fill in exactly one page buffer entry, however we will
erroneously return 2 from this function.

I believe the fix is to first replace the test at the end of the loop
with:

	page++;
	offset = 0;
	j++;

And subsequently change the function to just return plain "j".

  parent reply	other threads:[~2014-03-07 21:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-07  5:32 [PATCH V2 0/6] Drivers: net: hyperv: Enable various offloads K. Y. Srinivasan
2014-03-07  5:32 ` [PATCH V2 1/6] Drivers: net: hyperv: Enable scatter gather I/O K. Y. Srinivasan
2014-03-07  5:32   ` [PATCH V2 2/6] Drivers: net: hyperv: Cleanup the send path K. Y. Srinivasan
2014-03-07  5:32   ` [PATCH V3 3/6] Drivers: net: hyperv: Enable offloads on the host K. Y. Srinivasan
2014-03-07  5:32   ` [PATCH V2 4/6] Drivers: net: hyperv: Enable receive side IP checksum offload K. Y. Srinivasan
2014-03-07  5:32   ` [PATCH V2 5/6] Drivers: net: hyperv: Enable send side " K. Y. Srinivasan
2014-03-07  5:32   ` [PATCH V2 6/6] Drivers: net: hyperv: Enable large send offload K. Y. Srinivasan
2014-03-07 21:47   ` David Miller [this message]
2014-03-08  4:12     ` [PATCH V2 1/6] Drivers: net: hyperv: Enable scatter gather I/O KY Srinivasan
2014-03-08  6:36       ` David Miller
2014-03-08 10:27         ` KY Srinivasan
2014-03-08 23:38           ` David Miller

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=20140307.164756.1488071770631289333.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=apw@canonical.com \
    --cc=devel@linuxdriverproject.org \
    --cc=jasowang@redhat.com \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olaf@aepfle.de \
    /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

all inboxes | Powered by JetHome®