iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Joao Martins <joao.m.martins@oracle.com>
To: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Cc: iommu@lists.linux-foundation.org, "Grimm,
	Jon" <jon.grimm@amd.com>,
	linux-kernel@vger.kernel.org,
	Maxim Levitsky <mlevitsk@redhat.com>
Subject: Re: [PATCH] iommu/amd: fix interrupt remapping for avic
Date: Tue, 15 Sep 2020 14:19:06 +0100	[thread overview]
Message-ID: <b323b9d5-8149-5e6f-c24e-43b64bc6f2f6@oracle.com> (raw)
In-Reply-To: <dd0b9a98-149a-286c-2793-8ea0e8b60e2e@amd.com>

On 9/15/20 1:30 PM, Suravee Suthikulpanit wrote:
> On 9/15/20 6:25 PM, Maxim Levitsky wrote:
>> On Mon, 2020-09-14 at 21:48 +0700, Suravee Suthikulpanit wrote:
>>> Could you please try with the following patch instead?
>>>
>>> --- a/drivers/iommu/amd/iommu.c
>>> +++ b/drivers/iommu/amd/iommu.c
>>> @@ -3840,14 +3840,18 @@ int amd_iommu_activate_guest_mode(void *data)
>>>    {
>>>           struct amd_ir_data *ir_data = (struct amd_ir_data *)data;
>>>           struct irte_ga *entry = (struct irte_ga *) ir_data->entry;
>>> +       u64 valid;
>>>
>>>           if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) ||
>>>               !entry || entry->lo.fields_vapic.guest_mode)
>>>                   return 0;
>>>
>>> +       valid = entry->lo.fields_vapic.valid;
>>> +
>>>           entry->lo.val = 0;
>>>           entry->hi.val = 0;
>>>
>>> +       entry->lo.fields_vapic.valid       = valid;
>>>           entry->lo.fields_vapic.guest_mode  = 1;
>>>           entry->lo.fields_vapic.ga_log_intr = 1;
>>>           entry->hi.fields.ga_root_ptr       = ir_data->ga_root_ptr;
>>> @@ -3864,12 +3868,14 @@ int amd_iommu_deactivate_guest_mode(void *data)
>>>           struct amd_ir_data *ir_data = (struct amd_ir_data *)data;
>>>           struct irte_ga *entry = (struct irte_ga *) ir_data->entry;
>>>           struct irq_cfg *cfg = ir_data->cfg;
>>> -       u64 valid = entry->lo.fields_remap.valid;
>>> +       u64 valid;
>>>
>>>           if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) ||
>>>               !entry || !entry->lo.fields_vapic.guest_mode)
>>>                   return 0;
>>>
>>> +       valid = entry->lo.fields_remap.valid;
>>> +
>>>           entry->lo.val = 0;
>>>           entry->hi.val = 0;
>> I see. I based my approach on the fact that valid bit was
>> set always to true anyway before, plus that amd_iommu_activate_guest_mode
>> should be really only called when someone activates a valid interrupt remapping
>> entry, but IMHO the approach of preserving the valid bit is safer anyway.
>>
>> It works on my system (I applied the patch manually, since either your or my email client,
>> seems to mangle the patch)
>>
> 
> Sorry for the mangled patch. I'll submit the patch w/ your information. Thanks for your help reporting, debugging, and 
> testing the patch.
> 
I assume you're only doing the valid bit preservation in amd_iommu_activate_guest_mode() ?
The null deref fix in amd_iommu_deactivate_guest_mode() was fixed elsewhere[0], or are you
planning on merging both changes like the diff you attached?

Asking also because commit 26e495f341 ("iommu/amd: Restore IRTE.RemapEn bit after
programming IRTE") was added in v5.4 and v5.8 stable trees but the v5.4 backport didn't
include e52d58d54a321 ("iommu/amd: Use cmpxchg_double() when updating 128-bit IRTE").

	Joao

[0] https://lore.kernel.org/linux-iommu/20200910171621.12879-1-joao.m.martins@oracle.com/
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2020-09-15 13:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-13 12:42 Maxim Levitsky
2020-09-14 14:48 ` Suravee Suthikulpanit
2020-09-15 11:25   ` Maxim Levitsky
2020-09-15 12:30     ` Suravee Suthikulpanit
2020-09-15 13:19       ` Joao Martins [this message]
2020-09-16 10:38         ` Suravee Suthikulpanit

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=b323b9d5-8149-5e6f-c24e-43b64bc6f2f6@oracle.com \
    --to=joao.m.martins@oracle.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jon.grimm@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mlevitsk@redhat.com \
    --cc=suravee.suthikulpanit@amd.com \
    --subject='Re: [PATCH] iommu/amd: fix interrupt remapping for avic' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).