<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Patch has been applied to <span style="background-color:white;">
our internal amd-staging-drm-next tree</span>.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Thanks.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Best Regards</p>
<p style="margin-top:0;margin-bottom:0">Rex<br>
</p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Christian König <ckoenig.leichtzumerken@gmail.com><br>
<b>Sent:</b> Tuesday, July 17, 2018 2:58:21 PM<br>
<b>To:</b> Zhu, Rex; Kees Cook; Deucher, Alexander<br>
<b>Cc:</b> Zhou, David(ChunMing); David Airlie; Kuehling, Felix; LKML; amd-gfx list; Huang, Ray; Maling list - DRI developers; Koenig, Christian<br>
<b>Subject:</b> Re: [PATCH] drm/amdgpu/pm: Remove VLA usage</font>
<div> </div>
</div>
<meta content="text/html; charset=Windows-1252">
<div style="background-color:#FFFFFF">
<div class="x_moz-cite-prefix">
<blockquote type="cite"><font size="2"><span style="font-size:11pt">Who's tree should this go through?</span></font></blockquote>
To answer the question: When Rex is ok with that he pushes it to our internal amd-staging-drm-next tree.<br>
<br>
Alex then pushes that tree to a public server and at some point sends a pull request for inclusion in drm-next.<br>
<br>
Regards,<br>
Christian.<br>
<br>
Am 17.07.2018 um 08:23 schrieb Zhu, Rex:<br>
</div>
<blockquote type="cite"><style type="text/css" style="display:none">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<div dir="auto" style="direction:ltr; margin:0px; padding:0px; font-family:sans-serif,serif,"EmojiFont"; font-size:11pt; color:black">
Patch is:<br>
Reviewed-by: Rex Zhu<<a href="mailto:rezhu@amd.com" target="_blank" rel="noopener noreferrer" id="LPlnk600685" class="x_OWAAutoLink">rezhu@amd.com</a>> <br>
<br>
<br>
<br>
</div>
<div align="left">
<div dir="auto" style="direction:ltr; margin:0px; padding:0px; font-family:sans-serif,serif,"EmojiFont"; font-size:11pt; color:black">
<font color="#000000">Best Regards</font><br>
</div>
</div>
<font color="#000000">Rex</font><br>
<br>
<br>
<div style="color:rgb(0,0,0)">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font color="#000000" face="Calibri, sans-serif" style="font-size:11pt"><b>From:</b>
<a class="x_moz-txt-link-abbreviated" href="mailto:keescook@google.com">keescook@google.com</a>
<a class="x_moz-txt-link-rfc2396E" href="mailto:keescook@google.com"><keescook@google.com></a> on behalf of Kees Cook
<a class="x_moz-txt-link-rfc2396E" href="mailto:keescook@chromium.org"><keescook@chromium.org></a><br>
<b>Sent:</b> Tuesday, July 17, 2018 11:59 AM<br>
<b>To:</b> Deucher, Alexander<br>
<b>Cc:</b> LKML; Koenig, Christian; Zhou, David(ChunMing); David Airlie; Zhu, Rex; Huang, Ray; Kuehling, Felix; amd-gfx list; Maling list - DRI developers<br>
<b>Subject:</b> Re: [PATCH] drm/amdgpu/pm: Remove VLA usage</font>
<div> </div>
</div>
<div class="x_BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="x_PlainText">On Wed, Jun 20, 2018 at 11:26 AM, Kees Cook <a class="x_moz-txt-link-rfc2396E" href="mailto:keescook@chromium.org">
<keescook@chromium.org></a> wrote:<br>
> In the quest to remove all stack VLA usage from the kernel[1], this<br>
> uses the maximum sane buffer size and removes copy/paste code.<br>
><br>
> [1] <a href="https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com" id="LPlnk141741" class="x_OWAAutoLink">
https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com</a><br>
><br>
> Signed-off-by: Kees Cook <a class="x_moz-txt-link-rfc2396E" href="mailto:keescook@chromium.org">
<keescook@chromium.org></a><br>
<br>
Friendly ping! Who's tree should this go through?<br>
<br>
Thanks!<br>
<br>
-Kees<br>
<br>
> ---<br>
>  drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 100 +++++++++++--------------<br>
>  1 file changed, 42 insertions(+), 58 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
> index b455da487782..5eb98cde22ed 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
> @@ -593,40 +593,59 @@ static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,<br>
>                 return snprintf(buf, PAGE_SIZE, "\n");<br>
>  }<br>
><br>
> -static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev,<br>
> -               struct device_attribute *attr,<br>
> -               const char *buf,<br>
> -               size_t count)<br>
> +/*<br>
> + * Worst case: 32 bits individually specified, in octal at 12 characters<br>
> + * per line (+1 for \n).<br>
> + */<br>
> +#define AMDGPU_MASK_BUF_MAX    (32 * 13)<br>
> +<br>
> +static ssize_t amdgpu_read_mask(const char *buf, size_t count, uint32_t *mask)<br>
>  {<br>
> -       struct drm_device *ddev = dev_get_drvdata(dev);<br>
> -       struct amdgpu_device *adev = ddev->dev_private;<br>
>         int ret;<br>
>         long level;<br>
> -       uint32_t mask = 0;<br>
>         char *sub_str = NULL;<br>
>         char *tmp;<br>
> -       char buf_cpy[count];<br>
> +       char buf_cpy[AMDGPU_MASK_BUF_MAX + 1];<br>
>         const char delimiter[3] = {' ', '\n', '\0'};<br>
> +       size_t bytes;<br>
><br>
> -       memcpy(buf_cpy, buf, count+1);<br>
> +       *mask = 0;<br>
> +<br>
> +       bytes = min(count, sizeof(buf_cpy) - 1);<br>
> +       memcpy(buf_cpy, buf, bytes);<br>
> +       buf_cpy[bytes] = '\0';<br>
>         tmp = buf_cpy;<br>
>         while (tmp[0]) {<br>
> -               sub_str =  strsep(&tmp, delimiter);<br>
> +               sub_str = strsep(&tmp, delimiter);<br>
>                 if (strlen(sub_str)) {<br>
>                         ret = kstrtol(sub_str, 0, &level);<br>
> -<br>
> -                       if (ret) {<br>
> -                               count = -EINVAL;<br>
> -                               goto fail;<br>
> -                       }<br>
> -                       mask |= 1 << level;<br>
> +                       if (ret)<br>
> +                               return -EINVAL;<br>
> +                       *mask |= 1 << level;<br>
>                 } else<br>
>                         break;<br>
>         }<br>
> +<br>
> +       return 0;<br>
> +}<br>
> +<br>
> +static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev,<br>
> +               struct device_attribute *attr,<br>
> +               const char *buf,<br>
> +               size_t count)<br>
> +{<br>
> +       struct drm_device *ddev = dev_get_drvdata(dev);<br>
> +       struct amdgpu_device *adev = ddev->dev_private;<br>
> +       int ret;<br>
> +       uint32_t mask = 0;<br>
> +<br>
> +       ret = amdgpu_read_mask(buf, count, &mask);<br>
> +       if (ret)<br>
> +               return ret;<br>
> +<br>
>         if (adev->powerplay.pp_funcs->force_clock_level)<br>
>                 amdgpu_dpm_force_clock_level(adev, PP_SCLK, mask);<br>
><br>
> -fail:<br>
>         return count;<br>
>  }<br>
><br>
> @@ -651,32 +670,15 @@ static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev,<br>
>         struct drm_device *ddev = dev_get_drvdata(dev);<br>
>         struct amdgpu_device *adev = ddev->dev_private;<br>
>         int ret;<br>
> -       long level;<br>
>         uint32_t mask = 0;<br>
> -       char *sub_str = NULL;<br>
> -       char *tmp;<br>
> -       char buf_cpy[count];<br>
> -       const char delimiter[3] = {' ', '\n', '\0'};<br>
><br>
> -       memcpy(buf_cpy, buf, count+1);<br>
> -       tmp = buf_cpy;<br>
> -       while (tmp[0]) {<br>
> -               sub_str =  strsep(&tmp, delimiter);<br>
> -               if (strlen(sub_str)) {<br>
> -                       ret = kstrtol(sub_str, 0, &level);<br>
> +       ret = amdgpu_read_mask(buf, count, &mask);<br>
> +       if (ret)<br>
> +               return ret;<br>
><br>
> -                       if (ret) {<br>
> -                               count = -EINVAL;<br>
> -                               goto fail;<br>
> -                       }<br>
> -                       mask |= 1 << level;<br>
> -               } else<br>
> -                       break;<br>
> -       }<br>
>         if (adev->powerplay.pp_funcs->force_clock_level)<br>
>                 amdgpu_dpm_force_clock_level(adev, PP_MCLK, mask);<br>
><br>
> -fail:<br>
>         return count;<br>
>  }<br>
><br>
> @@ -701,33 +703,15 @@ static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev,<br>
>         struct drm_device *ddev = dev_get_drvdata(dev);<br>
>         struct amdgpu_device *adev = ddev->dev_private;<br>
>         int ret;<br>
> -       long level;<br>
>         uint32_t mask = 0;<br>
> -       char *sub_str = NULL;<br>
> -       char *tmp;<br>
> -       char buf_cpy[count];<br>
> -       const char delimiter[3] = {' ', '\n', '\0'};<br>
> -<br>
> -       memcpy(buf_cpy, buf, count+1);<br>
> -       tmp = buf_cpy;<br>
><br>
> -       while (tmp[0]) {<br>
> -               sub_str =  strsep(&tmp, delimiter);<br>
> -               if (strlen(sub_str)) {<br>
> -                       ret = kstrtol(sub_str, 0, &level);<br>
> +       ret = amdgpu_read_mask(buf, count, &mask);<br>
> +       if (ret)<br>
> +               return ret;<br>
><br>
> -                       if (ret) {<br>
> -                               count = -EINVAL;<br>
> -                               goto fail;<br>
> -                       }<br>
> -                       mask |= 1 << level;<br>
> -               } else<br>
> -                       break;<br>
> -       }<br>
>         if (adev->powerplay.pp_funcs->force_clock_level)<br>
>                 amdgpu_dpm_force_clock_level(adev, PP_PCIE, mask);<br>
><br>
> -fail:<br>
>         return count;<br>
>  }<br>
><br>
> --<br>
> 2.17.1<br>
><br>
><br>
> --<br>
> Kees Cook<br>
> Pixel Security<br>
<br>
<br>
<br>
-- <br>
Kees Cook<br>
Pixel Security<br>
</div>
</span></font></div>
</div>
</div>
<br>
<fieldset class="x_mimeAttachmentHeader"></fieldset> <br>
<pre>_______________________________________________
amd-gfx mailing list
<a class="x_moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>
<a class="x_moz-txt-link-freetext" href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a>
</pre>
</blockquote>
<br>
</div>
</body>
</html>