All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yi Liu <yi.l.liu@intel.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"CLEMENT MATHIEU--DRIF" <clement.mathieu--drif@eviden.com>
Cc: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"jasowang@redhat.com" <jasowang@redhat.com>,
	"zhenzhong.duan@intel.com" <zhenzhong.duan@intel.com>,
	 "kevin.tian@intel.com" <kevin.tian@intel.com>,
	"peterx@redhat.com" <peterx@redhat.com>
Subject: Re: [PATCH] intel_iommu: Take the bql before registering a new address space
Date: Tue, 15 Apr 2025 16:36:52 +0800	[thread overview]
Message-ID: <c335d240-dcb7-4f4d-a6bf-ec01914ef97d@intel.com> (raw)
In-Reply-To: <b0a898ef-93cf-4ce9-8737-cac94ed4f731@linaro.org>

On 2025/4/15 16:03, Philippe Mathieu-Daudé wrote:
> On 15/4/25 09:42, Michael S. Tsirkin wrote:
>> On Tue, Apr 15, 2025 at 07:28:34AM +0000, CLEMENT MATHIEU--DRIF wrote:
>>>
>>>
>>> On 15/04/2025 8:53 am, Philippe Mathieu-Daudé wrote:
>>>> Caution: External email. Do not open attachments or click links, unless
>>>> this email comes from a known sender and you know the content is safe.
>>>>
>>>>
>>>> On 15/4/25 08:18, CLEMENT MATHIEU--DRIF wrote:
>>>>> Address space creation might end up being called without holding the
>>>>> bql as it is exposed through the IOMMU ops.
>>>>>
>>>>> Signed-off-by: Clement Mathieu--Drif <clement.mathieu--drif@eviden.com>
>>>>> ---
>>>>>    hw/i386/intel_iommu.c | 10 ++++++++++
>>>>>    1 file changed, 10 insertions(+)
>>>>>
>>>>> diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
>>>>> index dffd7ee885..fea2220013 100644
>>>>> --- a/hw/i386/intel_iommu.c
>>>>> +++ b/hw/i386/intel_iommu.c
>>>>> @@ -4216,6 +4216,7 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState
>>>>> *s, PCIBus *bus,
>>>>>        vtd_dev_as = g_hash_table_lookup(s->vtd_address_spaces, &key);
>>>>>        if (!vtd_dev_as) {
>>>>>            struct vtd_as_key *new_key = g_malloc(sizeof(*new_key));
>>>>> +        bool take_bql = !bql_locked();
>>>>>
>>>>>            new_key->bus = bus;
>>>>>            new_key->devfn = devfn;
>>>>> @@ -4238,6 +4239,11 @@ VTDAddressSpace
>>>>> *vtd_find_add_as(IntelIOMMUState *s, PCIBus *bus,
>>>>>            vtd_dev_as->context_cache_entry.context_cache_gen = 0;
>>>>>            vtd_dev_as->iova_tree = iova_tree_new();
>>>>>
>>>>> +        /* Some functions in this branch require the bql, make sure
>>>>> we own it */
>>>>> +        if (take_bql) {
>>>>> +            bql_lock();
>>>>> +        }
>>>>> +
>>>>>            memory_region_init(&vtd_dev_as->root, OBJECT(s), name,
>>>>> UINT64_MAX);
>>>>>            address_space_init(&vtd_dev_as->as, &vtd_dev_as->root, "vtd-
>>>>> root");
>>>>>
>>>>> @@ -4305,6 +4311,10 @@ VTDAddressSpace
>>>>> *vtd_find_add_as(IntelIOMMUState *s, PCIBus *bus,
>>>>>
>>>>>            vtd_switch_address_space(vtd_dev_as);
>>>>
>>>> Would it help clarifying to propagate this argument down?
>>>> vtd_switch_address_space(VTDAddressSpace *as, bool need_lock);
>>>
>>> Hi phil, vtd_switch_address_space already does the same kind of check
>>>
>>>>
>>>>>
>>>>> +        if (take_bql) {
>>>>> +            bql_unlock();
>>>>> +        }
>>>>> +
>>>>>            g_hash_table_insert(s->vtd_address_spaces, new_key,
>>>>> vtd_dev_as);
>>>>>        }
>>>>>        return vtd_dev_as;
>>>>
>>
>>
>> As an apropos, I think any caller of bql_lock really should call
>> bql_lock_impl so we know who took BQL. Or just use BQL_LOCK_GUARD.
>> But, that's an unrelated cleanup.
>>
> 
> Yeah unrelated cleanup. Although I don't understand why these
> code paths don't use memory_region_transaction_begin/commit and
> have to access BQL.

The below two functions would call memory_region_transaction_begin/commit().
So these paths need BQL.

memory_region_set_enabled()
memory_region_add_subregion_overlap()

-- 
Regards,
Yi Liu


  reply	other threads:[~2025-04-15  8:31 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-15  6:18 [PATCH] intel_iommu: Take the bql before registering a new address space CLEMENT MATHIEU--DRIF
2025-04-15  6:53 ` Philippe Mathieu-Daudé
2025-04-15  7:28   ` CLEMENT MATHIEU--DRIF
2025-04-15  7:42     ` Michael S. Tsirkin
2025-04-15  8:03       ` Philippe Mathieu-Daudé
2025-04-15  8:36         ` Yi Liu [this message]
2025-04-15  6:55 ` Michael S. Tsirkin
2025-04-15  7:11 ` Michael S. Tsirkin
2025-04-15 12:33   ` Stefan Hajnoczi
2025-04-15 13:24     ` Paolo Bonzini
2025-04-15 14:03     ` Michael S. Tsirkin
2025-04-15 14:14     ` CLEMENT MATHIEU--DRIF
2025-04-15 14:31       ` Stefan Hajnoczi
2025-04-15  8:33 ` Yi Liu
2025-04-15  9:30 ` Paolo Bonzini
2025-04-15 11:49   ` Philippe Mathieu-Daudé
2025-04-15 11:52     ` Philippe Mathieu-Daudé
2025-04-15 11:50   ` CLEMENT MATHIEU--DRIF
2025-04-15 11:51     ` Paolo Bonzini
2025-04-15 11:55       ` Philippe Mathieu-Daudé
2025-04-15 12:59         ` Paolo Bonzini
2025-04-15 15:27           ` CLEMENT MATHIEU--DRIF
2025-04-15 13:08 ` Paolo Bonzini

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=c335d240-dcb7-4f4d-a6bf-ec01914ef97d@intel.com \
    --to=yi.l.liu@intel.com \
    --cc=clement.mathieu--drif@eviden.com \
    --cc=jasowang@redhat.com \
    --cc=kevin.tian@intel.com \
    --cc=mst@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=zhenzhong.duan@intel.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.