From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Tvrtko Ursulin <tursulin@ursulin.net>,
Masahiro Yamada <yamada.masahiro@socionext.com>,
Intel-gfx@lists.freedesktop.org,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Subject: Re: [Intel-gfx] [PATCH v4] lib/scatterlist: Avoid potential scatterlist entry overflow
Date: Mon, 16 Jan 2017 10:05:58 +0000 [thread overview]
Message-ID: <2eab0dc7-9e1d-ae4c-ef6a-2bca0644f339@linux.intel.com> (raw)
In-Reply-To: <CAHp75VfsXeHDNfJ86zpmRAgObO_ToBjbqJXGAX31jfUZbFjbFg@mail.gmail.com>
On 13/01/2017 22:23, Andy Shevchenko wrote:
>>>> @@ -402,9 +403,16 @@ int sg_alloc_table_from_pages(struct sg_table *sgt,
>>>>
>>>> /* compute number of contiguous chunks */
>>>> chunks = 1;
>>>> - for (i = 1; i < n_pages; ++i)
>>>> - if (page_to_pfn(pages[i]) != page_to_pfn(pages[i - 1]) +
>>>> 1)
>>>> + seg_len = PAGE_SIZE;
>>>> + for (i = 1; i < n_pages; ++i) {
>>>> + if (seg_len >= max_segment ||
>>>> + page_to_pfn(pages[i]) != page_to_pfn(pages[i - 1]) +
>>>> 1) {
>>>> ++chunks;
>>>> + seg_len = PAGE_SIZE;
>>>> + } else {
>>>> + seg_len += PAGE_SIZE;
>>>> + }
>>>> + }
>>>
>>>
>>> Wouldn't be following looks more readable?
>>>
>>> seg_len = 0;
>>> // Are compilers so stupid doing calculation per iteration in
>>> for-conditional?
>>> // for (i = 0; i + 1 < n_pages; i++) ?
>>
>>
>> I didn't get what you meant here?
>
> Why do we start from 1? I see here two micro (?) optimizations:
> 1) starting from 1 on believe that compiler dumb enough to every time
> do a calculation in condition;
The existing code starts from 1 because the pfn condition looks up page
i - 1. I don't feel there is a need to change that as well.
> 2) ++i instead of i++, but this is just matter of style, it's not a c++.
Note that I haven't changed the existing code in this respect. I am
happy to change it though.
>>> for (i = 1; i < n_pages; ++i) {
>>> seg_len += PAGE_SIZE;
>>> if (seg_len >= max_segment || page_to_pfn(pages[i]) !=
>>> page_to_pfn(pages[i - 1]) + 1) {
>>> ++chunks;
>>> seg_len = PAGE_SIZE;
>>> }
>>> }
>>
>>
>> Tried it in my unit tester but it doesn't work for all scenarios, guess
>> there is a subtle bug somewhere. I don't find it that unreadable so would
>> prefer to leave it since it works.
>
> Last seems has to be
> seg_len = 0;
Oh right, of course. Your suggestion generates a tiny bit smaller binary
so I am happy to change that as well. I'll resend the patch hopefully today.
Regards,
Tvrtko
next prev parent reply other threads:[~2017-01-16 10:06 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-11 9:00 [PATCH 1/4] lib/scatterlist: Fix offset type in sg_alloc_table_from_pages Tvrtko Ursulin
2017-01-11 9:00 ` [PATCH 2/4] lib/scatterlist: Avoid potential scatterlist entry overflow Tvrtko Ursulin
2017-01-11 11:58 ` [PATCH v4] " Tvrtko Ursulin
2017-01-11 23:59 ` Andy Shevchenko
2017-01-13 8:37 ` [Intel-gfx] " Tvrtko Ursulin
2017-01-13 22:23 ` Andy Shevchenko
2017-01-16 10:05 ` Tvrtko Ursulin [this message]
2017-01-16 10:12 ` Andy Shevchenko
2017-01-11 9:00 ` [PATCH 3/4] lib/scatterlist: Introduce and export __sg_alloc_table_from_pages Tvrtko Ursulin
2017-01-11 9:00 ` [PATCH 4/4] drm/i915: Use __sg_alloc_table_from_pages for userptr allocations Tvrtko Ursulin
2017-01-11 11:59 ` [PATCH v6] " Tvrtko Ursulin
2017-01-12 18:20 ` [Intel-gfx] " kbuild test robot
2017-01-11 11:59 ` [PATCH v5] lib/scatterlist: Introduce and export __sg_alloc_table_from_pages Tvrtko Ursulin
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=2eab0dc7-9e1d-ae4c-ef6a-2bca0644f339@linux.intel.com \
--to=tvrtko.ursulin@linux.intel.com \
--cc=Intel-gfx@lists.freedesktop.org \
--cc=andy.shevchenko@gmail.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tursulin@ursulin.net \
--cc=yamada.masahiro@socionext.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