All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools: ROUNDUP() related adjustments
@ 2021-08-10 10:03 Jan Beulich
  2021-08-19  5:45 ` Juergen Gross
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Beulich @ 2021-08-10 10:03 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson, Wei Liu, Juergen Gross

For one xc_private.h needlessly repeats xen-tools/libs.h's definition.

And then there are two suspicious uses (resulting from the inconsistency
with the respective 2nd parameter of DIV_ROUNDUP()): While the one in
tools/console/daemon/io.c - as per the code comment - intentionally uses
8 as the second argument (meaning to align to a multiple of 256), the
one in alloc_magic_pages_hvm() pretty certainly does not: There the goal
is to align to a uint64_t boundary, for the following module struct to
end up aligned.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
xg_dom_x86.c's HVM guest command line handling has further oddities: The
command line gets copied twice, yet in only one case enforcing the
MAX_GUEST_CMDLINE upper bound on the length. The length calculation also
doesn't take this bound into account, despite the assumption that all of
start info fits into a single page. A terminating nul character gets
forced in place in only one of the two cases, too.

--- a/tools/libs/ctrl/xc_private.h
+++ b/tools/libs/ctrl/xc_private.h
@@ -63,8 +63,6 @@ struct iovec {
 #include <sys/uio.h>
 #endif
 
-#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
-
 #define DECLARE_DOMCTL struct xen_domctl domctl
 #define DECLARE_SYSCTL struct xen_sysctl sysctl
 #define DECLARE_PHYSDEV_OP struct physdev_op physdev_op
--- a/tools/libs/guest/xg_dom_x86.c
+++ b/tools/libs/guest/xg_dom_x86.c
@@ -678,7 +678,7 @@ static int alloc_magic_pages_hvm(struct
     {
         if ( dom->cmdline )
         {
-            dom->cmdline_size = ROUNDUP(strlen(dom->cmdline) + 1, 8);
+            dom->cmdline_size = ROUNDUP(strlen(dom->cmdline) + 1, 3);
             start_info_size += dom->cmdline_size;
         }
     }



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tools: ROUNDUP() related adjustments
  2021-08-10 10:03 [PATCH] tools: ROUNDUP() related adjustments Jan Beulich
@ 2021-08-19  5:45 ` Juergen Gross
  2021-09-02 16:40   ` Ian Jackson
  0 siblings, 1 reply; 3+ messages in thread
From: Juergen Gross @ 2021-08-19  5:45 UTC (permalink / raw)
  To: Jan Beulich, xen-devel; +Cc: Ian Jackson, Wei Liu


[-- Attachment #1.1.1: Type: text/plain, Size: 699 bytes --]

On 10.08.21 12:03, Jan Beulich wrote:
> For one xc_private.h needlessly repeats xen-tools/libs.h's definition.
> 
> And then there are two suspicious uses (resulting from the inconsistency
> with the respective 2nd parameter of DIV_ROUNDUP()): While the one in
> tools/console/daemon/io.c - as per the code comment - intentionally uses
> 8 as the second argument (meaning to align to a multiple of 256), the
> one in alloc_magic_pages_hvm() pretty certainly does not: There the goal
> is to align to a uint64_t boundary, for the following module struct to
> end up aligned.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tools: ROUNDUP() related adjustments
  2021-08-19  5:45 ` Juergen Gross
@ 2021-09-02 16:40   ` Ian Jackson
  0 siblings, 0 replies; 3+ messages in thread
From: Ian Jackson @ 2021-09-02 16:40 UTC (permalink / raw)
  To: Juergen Gross; +Cc: Jan Beulich, xen-devel, Wei Liu

Juergen Gross writes ("Re: [PATCH] tools: ROUNDUP() related adjustments"):
> On 10.08.21 12:03, Jan Beulich wrote:
> > For one xc_private.h needlessly repeats xen-tools/libs.h's definition.
> > 
> > And then there are two suspicious uses (resulting from the inconsistency
> > with the respective 2nd parameter of DIV_ROUNDUP()): While the one in
> > tools/console/daemon/io.c - as per the code comment - intentionally uses
> > 8 as the second argument (meaning to align to a multiple of 256), the
> > one in alloc_magic_pages_hvm() pretty certainly does not: There the goal
> > is to align to a uint64_t boundary, for the following module struct to
> > end up aligned.

This is really quite unpleasnt, to my mind.  ROUNDUP taking a bit
length is bad enough, but the magic knowledge about alignment is
really poor too.  It may not be right on all future architectures,
although I think your changae is correct on all the ones we support
(or which people are working on).

So IOW I think your change is correct and warranted, but I really
dislike the code here.

Therefore:

Acked-by: Ian Jackson <iwj@xenproject.org>

> > Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
> Reviewed-by: Juergen Gross <jgross@suse.com>

Thanks for the review!

Ian.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-02 16:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-10 10:03 [PATCH] tools: ROUNDUP() related adjustments Jan Beulich
2021-08-19  5:45 ` Juergen Gross
2021-09-02 16:40   ` Ian Jackson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.