Re: [PATCH for-next 5/8] IB/core: Use __be32 for LIDs in opa_is_extended_lid

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Oct 03, 2017 at 09:07:35PM +0300, Leon Romanovsky wrote:
> On Tue, Oct 03, 2017 at 05:05:06PM +0000, Hefty, Sean wrote:
> > > > > >  	if ((be32_to_cpu(dlid) >=
> > > > > >  	     be16_to_cpu(IB_MULTICAST_LID_BASE)) ||
> > > > > >  	    (be32_to_cpu(slid) >=
> > > > > >  	     be16_to_cpu(IB_MULTICAST_LID_BASE)))
> > > > >
> > > > > You can drop be32_to_cpu and be16_to_cpu now.
> > > > > The dlid is __be32 and IB_MULTICAST_LID_BASE is __be16. The direct
> > > > > comparison will work.
> > > >
> > > > It won't order properly for >=, the swap is still needed...
> > >
> > > Jason,
> > > Do you have reference for that?
> > >
> > > I tried to find any information about comparison of values from one
> > > endianess on machine with another endianess and didn't find anything
> > > relevant.
> >
> > The bytes are out of order, so the comparisons won't work.
>
> I understand it for the "manual" comparison (C-like arrays), but does it apply
> for the compiler-aware comparison? Both these variables are marked as
> __be32 for the compiler.

OK, I finally found time to test my question and you and Jason are right.
Thank you for your time.

For curious readers, the snippet below, tested on x86:

diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index bcc4c2db81d0..234105716120 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -4754,6 +4754,15 @@ static int __init mlx5_ib_init(void)
 {
 	int err;

+	uint32_t u1 = 0x2233;
+	uint32_t u2 = 0x4411;
+
+	__be32 b1 = cpu_to_be32(u1);
+	__be32 b2 = cpu_to_be32(u2);
+
+	printk(KERN_ERR "test: u1 %s u1\n", (u1 < u2 ) ? "<":">");
+	printk(KERN_ERR "test: b1 %s b1\n", (b1 < b2 ) ? "<":">");
+
 	mlx5_ib_odp_init();

 	err = mlx5_register_interface(&mlx5_ib_interface);

and the result:
[    6.566979] test: u1 < u1
[    6.567147] test: b1 > b1

Thanks

>
> Thanks


Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux