All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tadeusz Struk <tadeusz.struk@intel.com>
To: Sowmini Varadhan <sowmini.varadhan@oracle.com>,
	linux-kernel@vger.kernel.org
Cc: herbert@gondor.apana.org.au, smueller@chronox.de,
	mmarek@suse.com, arnd@arndb.de, andrew.zaborowski@intel.com
Subject: Re: [PATCH] lib/mpi: Fix kernel unaligned acces in mpi_write_to_sgl
Date: Thu, 21 Apr 2016 10:23:20 -0700	[thread overview]
Message-ID: <57190C88.8000608@intel.com> (raw)
In-Reply-To: <20160421110736.GL22060@oracle.com>

On 04/21/2016 04:07 AM, Sowmini Varadhan wrote:
> 
> Commit 2d4d1eea540b ("lib/mpi: Add mpi sgl helpers") added
> mpi_write_to_sgl() which generates traps due to unaligned
> access on some platforms like sparc. Fix this by using
> the get_unaligned* and put_unaligned* functions.
> 
> Fixes: 2d4d1eea540b ("lib/mpi: Add mpi sgl helpers")
> Signed-off-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
> ---
>  lib/mpi/mpicoder.c |   12 ++++++++----
>  1 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/mpi/mpicoder.c b/lib/mpi/mpicoder.c
> index eb15e7d..6771378 100644
> --- a/lib/mpi/mpicoder.c
> +++ b/lib/mpi/mpicoder.c
> @@ -21,6 +21,7 @@
>  #include <linux/bitops.h>
>  #include <linux/count_zeros.h>
>  #include "mpi-internal.h"
> +#include <asm/unaligned.h>
>  
>  #define MAX_EXTERN_MPI_BITS 16384
>  
> @@ -405,10 +406,13 @@ int mpi_write_to_sgl(MPI a, struct scatterlist *sgl, unsigned *nbytes,
>  				p -= sizeof(alimb);
>  				continue;
>  			} else {
> -				mpi_limb_t *limb1 = (void *)p - sizeof(alimb);
> -				mpi_limb_t *limb2 = (void *)p - sizeof(alimb)
> -							+ lzeros;
> -				*limb1 = *limb2;
> +				mpi_limb_t tmp;
> +
> +				tmp = get_unaligned_be32((void *)p -
> +							 sizeof(alimb) +
> +							 lzeros);
> +				put_unaligned_be32(tmp,
> +						   (void *)p - sizeof(alimb));
>  				p -= lzeros;
>  				y = lzeros;
>  			}

What if the mpi_limb_t will happen to be 64 bit? 
Thanks,
-- 
TS

  reply	other threads:[~2016-04-21 17:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-21 11:07 [PATCH] lib/mpi: Fix kernel unaligned acces in mpi_write_to_sgl Sowmini Varadhan
2016-04-21 17:23 ` Tadeusz Struk [this message]
2016-04-21 17:44   ` Sowmini Varadhan

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=57190C88.8000608@intel.com \
    --to=tadeusz.struk@intel.com \
    --cc=andrew.zaborowski@intel.com \
    --cc=arnd@arndb.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmarek@suse.com \
    --cc=smueller@chronox.de \
    --cc=sowmini.varadhan@oracle.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 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.