All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Li, ZhenHua" <zhen-hual-VXdhtT5mjnY@public.gmane.org>
To: joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	"Li, Zhen-Hua" <zhen-hual-VXdhtT5mjnY@public.gmane.org>,
	dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 1/1] x86/iommu: fix incorrect bit operations in setting values
Date: Wed, 05 Nov 2014 15:35:50 +0800	[thread overview]
Message-ID: <5459D356.1040604@hp.com> (raw)
In-Reply-To: <1415172619-4801-1-git-send-email-zhen-hual-VXdhtT5mjnY@public.gmane.org>

Hi Joerg,

While debugging Bill's patches, I found this problem:
When copying iommu data from old kernel to the kdump kernel, the 
original function context_set_address_root() may cause kdump kernel 
using incorrect address root value.

So I created this patch to fix it.

Zhenhua

On 11/05/2014 03:30 PM, Li, Zhen-Hua wrote:
> The function context_set_address_root() and set_root_value are setting new
> address in a wrong way, and this patch is trying to fix this problem.
>
> According to Intel Vt-d specs(Feb 2011, Revision 1.3), Chapter 9.1 and 9.2,
> field ctp in root entry is using bits 12:63, field asr in context entry is
> using bits 12:63.
>
> To set these fields, the following functions are used:
> static inline void context_set_address_root(struct context_entry *context,
>          unsigned long value);
> and
> static inline void set_root_value(struct root_entry *root, unsigned long value)
>
> But they are using an invalid method to set these fields, in current code, only
> a '|' operator is used to set it. This will not set the asr to the expected
> value if it has an old value.
>
> For example:
> Before calling this function,
> 	context->lo = 0x3456789012111;
> 	value = 0x123456789abcef12;
>
> After we call context_set_address_root(context, value), expected result is
> 	context->lo == 0x123456789abce111;
>
> But the actual result is:
> 	context->lo == 0x1237577f9bbde111;
>
> So we need to clear bits 12:63 before setting the new value, this will fix
> this problem.
>
> Signed-off-by: Li, Zhen-Hua <zhen-hual-VXdhtT5mjnY@public.gmane.org>
> ---
>   drivers/iommu/intel-iommu.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
> index a27d6cb..11ac47b 100644
> --- a/drivers/iommu/intel-iommu.c
> +++ b/drivers/iommu/intel-iommu.c
> @@ -195,6 +195,7 @@ static inline void set_root_present(struct root_entry *root)
>   }
>   static inline void set_root_value(struct root_entry *root, unsigned long value)
>   {
> +	root->val &= ~VTD_PAGE_MASK;
>   	root->val |= value & VTD_PAGE_MASK;
>   }
>
> @@ -247,6 +248,7 @@ static inline void context_set_translation_type(struct context_entry *context,
>   static inline void context_set_address_root(struct context_entry *context,
>   					    unsigned long value)
>   {
> +	context->lo &= ~VTD_PAGE_MASK;
>   	context->lo |= value & VTD_PAGE_MASK;
>   }
>
>

WARNING: multiple messages have this Message-ID (diff)
From: "Li, ZhenHua" <zhen-hual@hp.com>
To: joro@8bytes.org
Cc: "Li, Zhen-Hua" <zhen-hual@hp.com>,
	iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
	dwmw2@infradead.org
Subject: Re: [PATCH 1/1] x86/iommu: fix incorrect bit operations in setting values
Date: Wed, 05 Nov 2014 15:35:50 +0800	[thread overview]
Message-ID: <5459D356.1040604@hp.com> (raw)
In-Reply-To: <1415172619-4801-1-git-send-email-zhen-hual@hp.com>

Hi Joerg,

While debugging Bill's patches, I found this problem:
When copying iommu data from old kernel to the kdump kernel, the 
original function context_set_address_root() may cause kdump kernel 
using incorrect address root value.

So I created this patch to fix it.

Zhenhua

On 11/05/2014 03:30 PM, Li, Zhen-Hua wrote:
> The function context_set_address_root() and set_root_value are setting new
> address in a wrong way, and this patch is trying to fix this problem.
>
> According to Intel Vt-d specs(Feb 2011, Revision 1.3), Chapter 9.1 and 9.2,
> field ctp in root entry is using bits 12:63, field asr in context entry is
> using bits 12:63.
>
> To set these fields, the following functions are used:
> static inline void context_set_address_root(struct context_entry *context,
>          unsigned long value);
> and
> static inline void set_root_value(struct root_entry *root, unsigned long value)
>
> But they are using an invalid method to set these fields, in current code, only
> a '|' operator is used to set it. This will not set the asr to the expected
> value if it has an old value.
>
> For example:
> Before calling this function,
> 	context->lo = 0x3456789012111;
> 	value = 0x123456789abcef12;
>
> After we call context_set_address_root(context, value), expected result is
> 	context->lo == 0x123456789abce111;
>
> But the actual result is:
> 	context->lo == 0x1237577f9bbde111;
>
> So we need to clear bits 12:63 before setting the new value, this will fix
> this problem.
>
> Signed-off-by: Li, Zhen-Hua <zhen-hual@hp.com>
> ---
>   drivers/iommu/intel-iommu.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
> index a27d6cb..11ac47b 100644
> --- a/drivers/iommu/intel-iommu.c
> +++ b/drivers/iommu/intel-iommu.c
> @@ -195,6 +195,7 @@ static inline void set_root_present(struct root_entry *root)
>   }
>   static inline void set_root_value(struct root_entry *root, unsigned long value)
>   {
> +	root->val &= ~VTD_PAGE_MASK;
>   	root->val |= value & VTD_PAGE_MASK;
>   }
>
> @@ -247,6 +248,7 @@ static inline void context_set_translation_type(struct context_entry *context,
>   static inline void context_set_address_root(struct context_entry *context,
>   					    unsigned long value)
>   {
> +	context->lo &= ~VTD_PAGE_MASK;
>   	context->lo |= value & VTD_PAGE_MASK;
>   }
>
>


  parent reply	other threads:[~2014-11-05  7:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-05  7:30 [PATCH 1/1] x86/iommu: fix incorrect bit operations in setting values Li, Zhen-Hua
2014-11-05  7:30 ` Li, Zhen-Hua
     [not found] ` <1415172619-4801-1-git-send-email-zhen-hual-VXdhtT5mjnY@public.gmane.org>
2014-11-05  7:35   ` Li, ZhenHua [this message]
2014-11-05  7:35     ` Li, ZhenHua
2014-11-06 13:41   ` Joerg Roedel
2014-11-06 13:41     ` Joerg Roedel
2014-11-12 11:28 ` Minfei Huang
2014-11-12 11:28   ` Minfei Huang
2014-11-12 11:28   ` Minfei Huang
2014-11-13  9:06   ` Li, ZhenHua
2014-11-13  9:06     ` Li, ZhenHua
2014-11-13  9:06     ` Li, ZhenHua
2014-11-13 13:37     ` Baoquan He
2014-11-13 13:37       ` Baoquan He
2014-11-13 13:37       ` Baoquan He
2014-11-14  1:29       ` Li, ZhenHua
2014-11-14  1:29         ` Li, ZhenHua
2014-11-14  1:29         ` Li, ZhenHua
2014-11-14  8:12         ` Li, ZhenHua
2014-11-14  8:12           ` Li, ZhenHua
2014-11-14  8:12           ` Li, ZhenHua

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=5459D356.1040604@hp.com \
    --to=zhen-hual-vxdhtt5mjny@public.gmane.org \
    --cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /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.