Skip to contentSkip to conversation

Xen 4.15 release schedule and feature tracking

ANNOUNCE Superseded Ian Jackson 13 participants 144 messages Jan 7, 2021 – Mar 6, 2021 Page 1 of 2

v4 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

Hi. As the Release Manage for Xen 4.15 I am going to start tracking the status of features which people are looking to get into Xen 4.15.

NB that the Last Posting Date is just over a week from now.

If you are working on a feature you want in 4.15 please let me know about it. Ideally I'd like a little stanza like this:

S: feature name
O: feature owner (proponent) name
E: feature owner (proponent) email address
P: your current estimate of the probability it making 4.15, as a %age

But free-form text is OK too. Please reply to this mail.

NB the primary responsibility for driving a feature's progress to meet the release schedule, lies with the feature's proponent(s).

As a reminder, here is the release schedule:

Friday 15th January Last posting date

Patches adding new features should be posted to the mailing list by this cate, although perhaps not in their final version.

Friday 29th January Feature freeze

Patches adding new features should be committed by this date. Straightforward bugfixes may continue to be accepted by maintainers.

Friday 12th February **tentatve** Code freeze

Bugfixes only, all changes to be approved by the Release Manager.

Week of 12th March **tentative** Release
(probably Tuesday or Wednesday)

Any patches containing substantial refactoring are to treated as new features, even if they intent is to fix bugs.

Freeze exceptions will not be routine, but may be granted in exceptional cases for small changes on the basis of risk assessment. Large series will not get exceptions. Contributors *must not* rely on getting, or expect, a freeze exception.

The codefreeze and release dates are very much provisional and will be adjusted in the light of apparent code quality etc.

If as a feature proponent you feel your feature is at risk and there is something the Xen Project could do to help, please consult me or the Community Manager. In such situations please reach out earlier rather than later.

Ian.

#1 lore raw

On 07.01.21 16:35, Ian Jackson wrote:

Hi Ian

Quoted 7 lines

Hi. As the Release Manage for Xen 4.15 I am going to start tracking the status of features which people are looking to get into Xen 4.15.

NB that the Last Posting Date is just over a week from now.

If you are working on a feature you want in 4.15 please let me know about it.

I work on virtio-mmio on Arm which involves x86's IOREQ/DM features.
Currently I am working on making the said features common, implementing missing bits, code cleanup an hardening, etc. I don't think the virtio-mmio is a 4.15 material, but it would be great have at least "common" IOREQ/DM in 4.15.

Quoted 3 lines

Ideally I'd like a little stanza like this:

S: feature name

The corresponding thread named:
IOREQ feature (+ virtio-mmio) on Arm
https://www.mail-archive.com/[email protected]/msg87002.html

Quoted 2 lines

O: feature owner (proponent) name
E: feature owner (proponent) email address

Julien as initiator of this activity, me as a person who continues this activity and tries to get it upstreamed:
Julien Grall <[email protected]>
Oleksandr Tyshchenko <[email protected]>

Quoted 1 line

P: your current estimate of the probability it making 4.15, as a %age

Difficult to say, it depends ...
RFC was posted Aug 3, 2020, The last posted version is V3. Currently I am in the middle of preparing v4, still need to find a common ground for few bits.

Quoted 44 lines

But free-form text is OK too. Please reply to this mail.

NB the primary responsibility for driving a feature's progress to meet the release schedule, lies with the feature's proponent(s).

As a reminder, here is the release schedule:

Friday 15th January Last posting date

Patches adding new features should be posted to the mailing list by this cate, although perhaps not in their final version.

Friday 29th January Feature freeze

Patches adding new features should be committed by this date. Straightforward bugfixes may continue to be accepted by maintainers.

Friday 12th February **tentatve** Code freeze

Bugfixes only, all changes to be approved by the Release Manager.

Week of 12th March **tentative** Release
(probably Tuesday or Wednesday)

Any patches containing substantial refactoring are to treated as new features, even if they intent is to fix bugs.

Freeze exceptions will not be routine, but may be granted in exceptional cases for small changes on the basis of risk assessment. Large series will not get exceptions. Contributors *must not* rely on getting, or expect, a freeze exception.

The codefreeze and release dates are very much provisional and will be adjusted in the light of apparent code quality etc.

If as a feature proponent you feel your feature is at risk and there is something the Xen Project could do to help, please consult me or the Community Manager. In such situations please reach out earlier rather than later.

Ian.

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
#2 lore raw

Re: [PATCH V4 00/24] IOREQ feature (+ virtio-mmio) on Arm

Hi, thanks for giving this update.

Since you were the only person who took the time to send such an update I feel I can spend some time on trying to help with any obstacles you may face. Hence this enquiry:

Oleksandr writes ("Re: [ANNOUNCE] Xen 4.15 release schedule and feature tracking"):

Quoted 5 lines

I work on virtio-mmio on Arm which involves x86's IOREQ/DM features. Currently I am working on making the said features common, implementing missing bits, code cleanup an hardening, etc.
I don't think the virtio-mmio is a 4.15 material, but it would be great have at least "common" IOREQ/DM in 4.15.

..

Quoted 6 lines
Quoted 1 line

P: your current estimate of the probability it making 4.15, as a %age

Difficult to say, it depends ...
RFC was posted Aug 3, 2020, The last posted version is V3. Currently I am in the middle of preparing v4, still need to find a common ground for few bits.

So, I'm replying to V4 here. Did you resolve your issues ? What are the major outstanding risks to this series and do you need any help from the Xen Project (eg from me as Release Manager) ?

NB I have not been following this series in detail - I'm just looking at your mail and your 00/ posting and so on. So if there is some blocker or risk I am probably unaware of it.

I notice that there's one libxl RFC patch in there. Since that's in my bailiwick I will try to review it soon.

Regards,
Ian.

#3 lore raw

Re: [PATCH V4 00/24] IOREQ feature (+ virtio-mmio) on Arm

On 14.01.21 18:11, Ian Jackson wrote:

Hi Ian

Quoted 5 lines

Hi, thanks for giving this update.

Since you were the only person who took the time to send such an update I feel I can spend some time on trying to help with any obstacles you may face.

Thank you.

Quoted 9 lines

Hence this enquiry:

Oleksandr writes ("Re: [ANNOUNCE] Xen 4.15 release schedule and feature tracking"):

Quoted 5 lines

I work on virtio-mmio on Arm which involves x86's IOREQ/DM features. Currently I am working on making the said features common, implementing missing bits, code cleanup an hardening, etc.
I don't think the virtio-mmio is a 4.15 material, but it would be great have at least "common" IOREQ/DM in 4.15.

Quoted 7 lines

..

Quoted 5 lines
Quoted 1 line

P: your current estimate of the probability it making 4.15, as a %age

Difficult to say, it depends ...
RFC was posted Aug 3, 2020, The last posted version is V3. Currently I am in the middle of preparing v4, still need to find a common ground for few bits.

So, I'm replying to V4 here. Did you resolve your issues ?

I think, yes. I hope, I addressed all review сomments/requests for V3.

Quoted 2 lines

What are the major outstanding risks to this series and do you need any help from the Xen Project (eg from me as Release Manager) ?

I would like to get the review for V4 for me to be able to make the required changes in time. Last 2 patches could be skipped for now, I don't expect the VirtIO to be in 4.15 (I keep these patches for visibility reason and test purposes):
- libxl: Introduce basic virtio-mmio support on Arm
- [RFC] libxl: Add support for virtio-disk configuration
But, first 22 patches (IOREQ/DM) I would like to see in 4.15.

Also what worries me the most is that a quite big series hasn't been fully tested on x86 (only build tested).

Quoted 7 lines

NB I have not been following this series in detail - I'm just looking at your mail and your 00/ posting and so on. So if there is some blocker or risk I am probably unaware of it.

I notice that there's one libxl RFC patch in there. Since that's in my bailiwick I will try to review it soon.

Thank you, please note, this RFC patch is not a target for 4.15, no rush) For the next version I will drop these VirtIO related patches.

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
#4 lore raw
In reply to Ian Jackson

The last posting date for new feature patches for Xen 4.15 is tomorrow. [1] We seem to be getting a reasonable good flood of stuff trying to meet this deadline :-).

Patches for new fetures posted after tomorrow will be deferred to the next Xen release after 4.15. NB the primary responsibility for driving a feature's progress to meet the release schedule, lies with the feature's proponent(s).

As a reminder, here is the release schedule:
+ (unchanged information indented with spaces):

Friday 15th January Last posting date

Patches adding new features should be posted to the mailing list by this cate, although perhaps not in their final version.

Friday 29th January Feature freeze

Patches adding new features should be committed by this date. Straightforward bugfixes may continue to be accepted by maintainers.

Friday 12th February **tentatve** Code freeze

Bugfixes only, all changes to be approved by the Release Manager.

Week of 12th March **tentative** Release
(probably Tuesday or Wednesday)

Any patches containing substantial refactoring are to treated as new features, even if they intent is to fix bugs.

Freeze exceptions will not be routine, but may be granted in exceptional cases for small changes on the basis of risk assessment. Large series will not get exceptions. Contributors *must not* rely on getting, or expect, a freeze exception.

+ New or improved tests (supposing they do not involve refactoring,
+ even build system reorganisation), and documentation improvements,
+ will generally be treated as bugfixes.

The codefreeze and release dates are provisional and will be adjusted in the light of apparent code quality etc.

If as a feature proponent you feel your feature is at risk and there is something the Xen Project could do to help, please consult me or the Community Manager. In such situations please reach out earlier rather than later.

In my last update I asked this:

Quoted 9 lines

If you are working on a feature you want in 4.15 please let me know about it. Ideally I'd like a little stanza like this:

S: feature name
O: feature owner (proponent) name
E: feature owner (proponent) email address
P: your current estimate of the probability it making 4.15, as a %age

But free-form text is OK too. Please reply to this mail.

I received one mail. Thanks to Oleksandr Andrushchenko for his update on the following feeature:

IOREQ feature (+ virtio-mmio) on Arm
https://www.mail-archive.com/[email protected]/msg87002.html

Julien Grall <[email protected]>
Oleksandr Tyshchenko <[email protected]>

I see that V4 of this series was just posted. Thanks, Oleksandr. I'll make a separate enquiry about your series.

I think if people don't find the traditional feature tracking useful, I will try to assemble Release Notes information later, during the freeze, when fewer people are rushing to try to meet the deadlines.

Thanks,
Ian.

[1] The precise nominal cutoff time is 2020-01-14 23:59:00 in time zone International Date Line West
https://en.wikipedia.org/wiki/UTC%E2%88%9212:00
based on the timestamp recorded in the earliest Received: line inserted by lists.xenproject.org, in the message containing the last-received patch of the series.

#5 lore raw
Quoted 72 lines · Ian Jackson

The last posting date for new feature patches for Xen 4.15 is tomorrow. [1] We seem to be getting a reasonable good flood of stuff trying to meet this deadline :-).

Patches for new fetures posted after tomorrow will be deferred to the next Xen release after 4.15. NB the primary responsibility for driving a feature's progress to meet the release schedule, lies with the feature's proponent(s).

As a reminder, here is the release schedule:
+ (unchanged information indented with spaces):

Friday 15th January Last posting date

Patches adding new features should be posted to the mailing list by this cate, although perhaps not in their final version.

Friday 29th January Feature freeze

Patches adding new features should be committed by this date. Straightforward bugfixes may continue to be accepted by maintainers.

Friday 12th February **tentatve** Code freeze

Bugfixes only, all changes to be approved by the Release Manager.

Week of 12th March **tentative** Release
(probably Tuesday or Wednesday)

Any patches containing substantial refactoring are to treated as new features, even if they intent is to fix bugs.

Freeze exceptions will not be routine, but may be granted in exceptional cases for small changes on the basis of risk assessment. Large series will not get exceptions. Contributors *must not* rely on getting, or expect, a freeze exception.

+ New or improved tests (supposing they do not involve refactoring,
+ even build system reorganisation), and documentation improvements,
+ will generally be treated as bugfixes.

The codefreeze and release dates are provisional and will be adjusted in the light of apparent code quality etc.

If as a feature proponent you feel your feature is at risk and there is something the Xen Project could do to help, please consult me or the Community Manager. In such situations please reach out earlier rather than later.

In my last update I asked this:

Quoted 9 lines

If you are working on a feature you want in 4.15 please let me know about it. Ideally I'd like a little stanza like this:

S: feature name
O: feature owner (proponent) name
E: feature owner (proponent) email address
P: your current estimate of the probability it making 4.15, as a %age

But free-form text is OK too. Please reply to this mail.

I received one mail. Thanks to Oleksandr Andrushchenko for his update on the following feeature:

IOREQ feature (+ virtio-mmio) on Arm
https://www.mail-archive.com/[email protected]/msg87002.html

Julien Grall <[email protected]>
Oleksandr Tyshchenko <[email protected]>

Quoted 6 lines

I see that V4 of this series was just posted. Thanks, Oleksandr. I'll make a separate enquiry about your series.

I think if people don't find the traditional feature tracking useful, I will try to assemble Release Notes information later, during the freeze, when fewer people are rushing to try to meet the deadlines.

(Now I have working email).

Features:

1) acquire_resource fixes.

Not really a new feature - entirely bugfixing a preexisting one. Developed by me to help 2).  Reasonably well acked, but awaiting feedback on v3.

2) External Processor Trace support.

Development by Michał.  Depends on 1), and awaiting a new version being posted.

As far as I'm aware, both Intel and CERT have production systems deployed using this functionality, so it is very highly desirable to get into 4.15.

3) Initial Trenchboot+SKINIT support.

I've got two patches I need to clean up and submit which is the first part of the Trenchboot + Dynamic Root of Trust on AMD support.  This will get Xen into a position where it can be started via the new grub "secure_launch" protocol.

Later patches (i.e. post 4.15) will do support for Intel TXT (i.e. without tboot), as well as the common infrastructure for the TPM event log and further measurements during the boot process.

4) "simple" autotest support.

Bugs:

1) HPET/PIT issue on newer Intel systems.  This has had literally tens of reports across the devel and users mailing lists, and prevents Xen from booting at all on the past two generations of Intel laptop.  I've finally got a repro and posted a fix to the list, but still in progress.

2) "scheduler broken" bugs.  We've had 4 or 5 reports of Xen not working, and very little investigation on whats going on.  Suspicion is that there might be two bugs, one with smt=0 on recent AMD hardware, and one more general "some workloads cause negative credit" and might or might not be specific to credit2 (debugging feedback differs - also might be 3 underlying issue).

All of these have had repeated bug reports.  I'd classify them as blockers, given the impact they're having on people.

~Andrew

#6 lore raw
Quoted 14 lines · Andrew Cooper

Bugs:

1) HPET/PIT issue on newer Intel systems.  This has had literally tens of reports across the devel and users mailing lists, and prevents Xen from booting at all on the past two generations of Intel laptop.  I've finally got a repro and posted a fix to the list, but still in progress.

2) "scheduler broken" bugs.  We've had 4 or 5 reports of Xen not working, and very little investigation on whats going on.  Suspicion is that there might be two bugs, one with smt=0 on recent AMD hardware, and one more general "some workloads cause negative credit" and might or might not be specific to credit2 (debugging feedback differs - also might be 3 underlying issue).

Quoted 2 lines

All of these have had repeated bug reports.  I'd classify them as blockers, given the impact they're having on people.

3) Fallout from MSR handling behavioral change.

Jan

#7 lore raw
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Andrew Cooper

Bugs:

1) HPET/PIT issue on newer Intel systems.  This has had literally tens of reports across the devel and users mailing lists, and prevents Xen from booting at all on the past two generations of Intel laptop.  I've finally got a repro and posted a fix to the list, but still in progress.

2) "scheduler broken" bugs.  We've had 4 or 5 reports of Xen not working, and very little investigation on whats going on.  Suspicion is that there might be two bugs, one with smt=0 on recent AMD hardware, and one more general "some workloads cause negative credit" and might or might not be specific to credit2 (debugging feedback differs - also might be 3 underlying issue).

Quoted 4 lines
Quoted 2 lines

All of these have had repeated bug reports.  I'd classify them as blockers, given the impact they're having on people.

3) Fallout from MSR handling behavioral change.

4) Use-after-free in the IOMMU code (this should be a blocker).

See "xen/iommu: Collection of bug fixes for IOMMU teadorwn"

<[email protected]>

Cheers,

Quoted 3 lines

Jan

Signature · 1 line
Julien Grall
#8 lore raw
In reply to Jan Beulich
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Andrew Cooper

Bugs:

1) HPET/PIT issue on newer Intel systems.  This has had literally tens of reports across the devel and users mailing lists, and prevents Xen from booting at all on the past two generations of Intel laptop.  I've finally got a repro and posted a fix to the list, but still in progress.

2) "scheduler broken" bugs.  We've had 4 or 5 reports of Xen not working, and very little investigation on whats going on.  Suspicion is that there might be two bugs, one with smt=0 on recent AMD hardware, and one more general "some workloads cause negative credit" and might or might not be specific to credit2 (debugging feedback differs - also might be 3 underlying issue).

Quoted 3 lines
Quoted 2 lines

All of these have had repeated bug reports.  I'd classify them as blockers, given the impact they're having on people.

3) Fallout from MSR handling behavioral change.

Yes, sorry for forgetting.  I was literally working on it while writing this email - no idea why I forgot it.

4) zstd support to unbreak Fedora.  (I'm deliberately putting this in the bugs rather than feature cateogry).

~Andrew

#9 lore raw
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Andrew Cooper

Bugs:

1) HPET/PIT issue on newer Intel systems.  This has had literally tens of reports across the devel and users mailing lists, and prevents Xen from booting at all on the past two generations of Intel laptop.  I've finally got a repro and posted a fix to the list, but still in progress.

2) "scheduler broken" bugs.  We've had 4 or 5 reports of Xen not working, and very little investigation on whats going on.  Suspicion is that there might be two bugs, one with smt=0 on recent AMD hardware, and one more general "some workloads cause negative credit" and might or might not be specific to credit2 (debugging feedback differs - also might be 3 underlying issue).

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

All of these have had repeated bug reports.  I'd classify them as blockers, given the impact they're having on people.

3) Fallout from MSR handling behavioral change.

Yes, sorry for forgetting.  I was literally working on it while writing this email - no idea why I forgot it.

4) zstd support to unbreak Fedora.  (I'm deliberately putting this in the bugs rather than feature cateogry).

Ha!  I should have read further through my emails before replying.

But we do at least want this item tracking.

~Andrew

#10 lore raw
Quoted 5 lines · Andrew Cooper
Quoted 2 lines · Andrew Cooper

4) zstd support to unbreak Fedora.  (I'm deliberately putting this in the bugs rather than feature cateogry).

Ha!  I should have read further through my emails before replying.

What I've sent doesn't cover DomU-s, though, so ...

Quoted 1 line

But we do at least want this item tracking.

... I definitely agree here from whichever perspective I take.

Jan

#11 lore raw
In reply to Andrew Cooper

Hi,

Quoted 108 lines · Andrew Cooper
Quoted 72 lines · Ian Jackson

The last posting date for new feature patches for Xen 4.15 is tomorrow. [1] We seem to be getting a reasonable good flood of stuff trying to meet this deadline :-).

Patches for new fetures posted after tomorrow will be deferred to the next Xen release after 4.15. NB the primary responsibility for driving a feature's progress to meet the release schedule, lies with the feature's proponent(s).

As a reminder, here is the release schedule:
+ (unchanged information indented with spaces):

Friday 15th January Last posting date

Patches adding new features should be posted to the mailing list by this cate, although perhaps not in their final version.

Friday 29th January Feature freeze

Patches adding new features should be committed by this date. Straightforward bugfixes may continue to be accepted by maintainers.

Friday 12th February **tentatve** Code freeze

Bugfixes only, all changes to be approved by the Release Manager.

Week of 12th March **tentative** Release
(probably Tuesday or Wednesday)

Any patches containing substantial refactoring are to treated as new features, even if they intent is to fix bugs.

Freeze exceptions will not be routine, but may be granted in exceptional cases for small changes on the basis of risk assessment. Large series will not get exceptions. Contributors *must not* rely on getting, or expect, a freeze exception.

+ New or improved tests (supposing they do not involve refactoring,
+ even build system reorganisation), and documentation improvements,
+ will generally be treated as bugfixes.

The codefreeze and release dates are provisional and will be adjusted in the light of apparent code quality etc.

If as a feature proponent you feel your feature is at risk and there is something the Xen Project could do to help, please consult me or the Community Manager. In such situations please reach out earlier rather than later.

In my last update I asked this:

Quoted 9 lines

If you are working on a feature you want in 4.15 please let me know about it. Ideally I'd like a little stanza like this:

S: feature name
O: feature owner (proponent) name
E: feature owner (proponent) email address
P: your current estimate of the probability it making 4.15, as a %age

But free-form text is OK too. Please reply to this mail.

I received one mail. Thanks to Oleksandr Andrushchenko for his update on the following feeature:

IOREQ feature (+ virtio-mmio) on Arm
https://www.mail-archive.com/[email protected]/msg87002.html

Julien Grall <[email protected]>
Oleksandr Tyshchenko <[email protected]>

Quoted 6 lines

I see that V4 of this series was just posted. Thanks, Oleksandr. I'll make a separate enquiry about your series.

I think if people don't find the traditional feature tracking useful, I will try to assemble Release Notes information later, during the freeze, when fewer people are rushing to try to meet the deadlines.

(Now I have working email).

Features:

1) acquire_resource fixes.

Not really a new feature - entirely bugfixing a preexisting one. Developed by me to help 2). Reasonably well acked, but awaiting feedback on v3.

2) External Processor Trace support.

Development by Michał. Depends on 1), and awaiting a new version being posted.

As far as I'm aware, both Intel and CERT have production systems deployed using this functionality, so it is very highly desirable to get into 4.15.

3) Initial Trenchboot+SKINIT support.

I've got two patches I need to clean up and submit which is the first part of the Trenchboot + Dynamic Root of Trust on AMD support. This will get Xen into a position where it can be started via the new grub "secure_launch" protocol.

Quoted 5 lines

Later patches (i.e. post 4.15) will do support for Intel TXT (i.e. without tboot), as well as the common infrastructure for the TPM event log and further measurements during the boot process.

4) "simple" autotest support.

5) SMMU-v3 Support from Rahul Singh

See "xen/arm: Add support for SMMUv3 driver”
https://lists.xenproject.org/archives/html/xen-devel/2021-01/msg00429.html

Almost everything in the serie is already acked.

Cheers
Bertrand

Quoted 20 lines

Bugs:

1) HPET/PIT issue on newer Intel systems. This has had literally tens of reports across the devel and users mailing lists, and prevents Xen from booting at all on the past two generations of Intel laptop. I've finally got a repro and posted a fix to the list, but still in progress.

2) "scheduler broken" bugs. We've had 4 or 5 reports of Xen not working, and very little investigation on whats going on. Suspicion is that there might be two bugs, one with smt=0 on recent AMD hardware, and one more general "some workloads cause negative credit" and might or might not be specific to credit2 (debugging feedback differs - also might be 3 underlying issue).

All of these have had repeated bug reports. I'd classify them as blockers, given the impact they're having on people.

~Andrew

#12 lore raw
In reply to Andrew Cooper
Quoted 8 lines

Features:

1) acquire_resource fixes.

Not really a new feature - entirely bugfixing a preexisting one. Developed by me to help 2).  Reasonably well acked, but awaiting feedback on v3.

Quoted 7 lines

2) External Processor Trace support.

Development by Michał.  Depends on 1), and awaiting a new version being posted.

As far as I'm aware, both Intel and CERT have production systems deployed using this functionality, so it is very highly desirable to get into 4.15.

We are actively using a backported version on top of 4.14.1, having this in 4.15 would be absolutely huge. We've ran over 10 billion fuzz cycles using it so far using VM forks, works great. Several other researchers in the community are using it as well.

Quoted 4 lines

1) HPET/PIT issue on newer Intel systems.  This has had literally tens of reports across the devel and users mailing lists, and prevents Xen from booting at all on the past two generations of Intel laptop.  I've finally got a repro and posted a fix to the list, but still in progress.

We've ran into this on multiple systems, Andrew's patch does fix it.

Quoted 6 lines

2) "scheduler broken" bugs.  We've had 4 or 5 reports of Xen not working, and very little investigation on whats going on.  Suspicion is that there might be two bugs, one with smt=0 on recent AMD hardware, and one more general "some workloads cause negative credit" and might or might not be specific to credit2 (debugging feedback differs - also might be 3 underlying issue).

We've also ran into intermittent Xen lockups requiring power-cycling servers. We switched back to credit1 and had no issues since. Hard to tell if it was related to the scheduler or the pile of other experimental stuff we are running with but right now we have stable systems across the board with credit1.

Quoted 3 lines

All of these have had repeated bug reports.  I'd classify them as blockers, given the impact they're having on people.

+1

Thanks,
Tamas

#13 lore raw
Quoted 12 lines · Tamas
Quoted 11 lines

2) "scheduler broken" bugs.  We've had 4 or 5 reports of Xen not working,
and very little investigation on whats going on.  Suspicion is that there
might be two bugs, one with smt=0 on recent AMD hardware, and one more general "some workloads cause negative credit" and might or might
not be specific to credit2 (debugging feedback differs - also might be 3
underlying issue).

Quoted 3 lines

We've also ran into intermittent Xen lockups requiring power-cycling servers. We switched back to credit1 and had no issues since.

Ah, that's interesting... Among the issues that I listed in my other email, when trying to do a quick summary, "only" number 1 is about Credit working when Credit2 does not. This one you're mentioning here may be the second... or it may be the same! :-O

As said there, my theory so far is that there's a bug somewhere, not necessarily in scheduling code, to which the two algorithms react differently. Of course this is a theory, and I've not been able to confirm it yet (otherwise I also would have fixed the problem. :-P).

But really, it would be interesting to double check if at least the symptoms are the same than the ones of the issue reported here.

Quoted 4 lines

Hard to tell if it was related to the scheduler or the pile of other experimental stuff we are running with but right now we have stable systems across the board with credit1.

Well, sure, that's understandable. :-) Which is why it's tricky at times to debug these issue. In fact, I cannot reproduce them myself, and users, rightfully, move on if they found a workaround.

Anyway, if at some point you decide to investigate, I'll be happy to help.

Regards

Signature · 6 lines
Dario Faggioli, Ph.D
http://about.me/dario.faggioli
Virtualization Software Engineer
SUSE Labs, SUSE https://www.suse.com/
-------------------------------------------------------------------
<<This happens because _I_ choose it to happen!>> (Raistlin Majere)
#14 lore raw
In reply to Andrew Cooper
Quoted 144 lines · Andrew Cooper
Quoted 89 lines · Ian Jackson

The last posting date for new feature patches for Xen 4.15 is tomorrow. [1]  We seem to be getting a reasonable good flood of stuff
trying to meet this deadline :-).

Patches for new fetures posted after tomorrow will be deferred to the
next Xen release after 4.15.  NB the primary responsibility for driving a feature's progress to meet the release schedule, lies with
the feature's proponent(s).

  As a reminder, here is the release schedule:
+ (unchanged information indented with spaces):

   Friday 15th January    Last posting date

       Patches adding new features should be posted to the mailing list
       by this cate, although perhaps not in their final version.

   Friday 29th January    Feature freeze

       Patches adding new features should be committed by this date.
       Straightforward bugfixes may continue to be accepted by maintainers.

   Friday 12th February **tentatve**   Code freeze

       Bugfixes only, all changes to be approved by the Release Manager.

   Week of 12th March **tentative**    Release
       (probably Tuesday or Wednesday)

  Any patches containing substantial refactoring are to treated as new features, even if they intent is to fix bugs.

  Freeze exceptions will not be routine, but may be granted in exceptional cases for small changes on the basis of risk assessment.
  Large series will not get exceptions.  Contributors *must not* rely on
  getting, or expect, a freeze exception.

+ New or improved tests (supposing they do not involve refactoring,
+ even build system reorganisation), and documentation improvements,
+ will generally be treated as bugfixes.

  The codefreeze and release dates are provisional and will be adjusted
  in the light of apparent code quality etc.

  If as a feature proponent you feel your feature is at risk and there
  is something the Xen Project could do to help, please consult me or
  the Community Manager.  In such situations please reach out earlier
  rather than later.

In my last update I asked this:

Quoted 11 lines

If you are working on a feature you want in 4.15 please let me know
about it.  Ideally I'd like a little stanza like this:

S: feature name
O: feature owner (proponent) name
E: feature owner (proponent) email address
P: your current estimate of the probability it making 4.15, as a %age

But free-form text is OK too.  Please reply to this mail.

I received one mail.  Thanks to Oleksandr Andrushchenko for his update
on the following feeature:

  IOREQ feature (+ virtio-mmio) on Arm

https://www.mail-archive.com/[email protected]/msg87002.html

  Julien Grall <[email protected]>
  Oleksandr Tyshchenko <[email protected]>

Quoted 7 lines

I see that V4 of this series was just posted.  Thanks, Oleksandr. I'll make a separate enquiry about your series.

I think if people don't find the traditional feature tracking useful,
I will try to assemble Release Notes information later, during the freeze, when fewer people are rushing to try to meet the deadlines.

(Now I have working email).

Features:

1) acquire_resource fixes.

Not really a new feature - entirely bugfixing a preexisting one. Developed by me to help 2).  Reasonably well acked, but awaiting feedback on v3.

2) External Processor Trace support.

Development by Michał.  Depends on 1), and awaiting a new version being
posted.

As far as I'm aware, both Intel and CERT have production systems deployed using this functionality, so it is very highly desirable to get
into 4.15.

3) Initial Trenchboot+SKINIT support.

I've got two patches I need to clean up and submit which is the first part of the Trenchboot + Dynamic Root of Trust on AMD support.  This will get Xen into a position where it can be started via the new grub "secure_launch" protocol.

Later patches (i.e. post 4.15) will do support for Intel TXT (i.e. without tboot), as well as the common infrastructure for the TPM event
log and further measurements during the boot process.

4) "simple" autotest support.

Bugs:

1) HPET/PIT issue on newer Intel systems.  This has had literally tens
of reports across the devel and users mailing lists, and prevents Xen from booting at all on the past two generations of Intel laptop. I've
finally got a repro and posted a fix to the list, but still in progress.

Quoted 9 lines

2) "scheduler broken" bugs.  We've had 4 or 5 reports of Xen not working, and very little investigation on whats going on.  Suspicion is
that there might be two bugs, one with smt=0 on recent AMD hardware, and
one more general "some workloads cause negative credit" and might or might not be specific to credit2 (debugging feedback differs - also might be 3 underlying issue).

Yep, so, let's try to summarize/collect the ones I think you may be referring to:

1) There is one report about Credit2 not working, while Credit1 was fine. It's this one:

https://lists.xenproject.org/archives/html/xen-devel/2020-10/msg01561.html

It's the one where it somehow happens that one or more vCPUs manage to run for a really really long timeslice, much more than the scheduler would have allowed them to, and this cause problems. _If_ that's it, my investigation so far seems to show that this happens despite scheduler code tries to enforce (via timers) the proper timeslice limits. when it happens, makes the scheduler very unhappy. I've see reports of it occurring both on Credit and Credit2, but definitely Credit2 seems to be more sensitive to it.

I've actually been trying to track it down for a while now, but I can't easily reproduce it, so it's proving to be challenging.

2) Then there has been his one:

https://lists.xenproject.org/archives/html/xen-devel/2020-10/msg01005.html

Here, the where reporter said that "[credit1] results is an observable delay, unusable performance; credit2 seems to be the only usable scheduler". This is the one that also Andrew mention, happening on Ryzen and with SMT disabled (as this is on QubesOS, IIRC).

Here, doing "dom0_max_vcpus=1 dom0_vcpus_pin" seemed to mitigate the problem but, of course, with obvious limitations. I don't have a Ryzen handy, but I have a Zen and a Zen2. I checked there and again could not reproduce (although, what I tried was upstream Xen, not QubesOS).

3) Then I recall this one:

https://lists.xenproject.org/archives/html/xen-devel/2020-10/msg01800.html

This also started as a "scheduler, probably Credit2" bug. But it then turned out manifests on both Credit1 and Credit2 and it started to happen on 4.14, while it was not there in 4.13... And nothing major changed in scheduling between these two releases, I think.

During the analysis, we thought we identified a livelock, but then could not pinpoint what was exactly going on. Oh, and then it was also discovered that Credit2 + PVH dom0 seemed to be a working configuration, and it's weird for a scheduling issue to have a (dom0) domain type dependency, I think. But that could be anything really... and I'm sure happy to keep digging.

4) There's the NULL scheduler + ARM + vwfi=native issue:

https://lists.xenproject.org/archives/html/xen-devel/2021-01/msg01634.html

This looks like something that we saw before, but remained unfixed, although not exactly like that. If it's that one, analysis is done, and we're working on a patch. If it's something else or even something similar but slightly different... Well, we'll have to see when we have the patch.

5) We're also dealing with this bugreport, although this is being reported against Xen 4.13 (openSUSE 's packaged version of it):

https://bugzilla.opensuse.org/show_bug.cgi?id=1179246

This is again on recent AMD hardware and here, "dom0_max_vcpus=4 dom0_vcpus_pin" works ok, but only until a (Windows) HVM guest is started. When that happens, though, we have crashes/hangs.

If guests are PV, things are apparently fine. If the HVM guests use a different set of CPUs than dom0 (e.g., vm.cpumask="4-63" in xl.conf), thinks are fine as well.

Again a scheduler issue and a scheduling algorithm dependency was theorized and will be investigated (if the user can come back with answers, which may take some time, as explained in the report). The different behavior with different kind of guests is a little weird for an issue of this kind, IME, but let's see.

6) If we want, we can include this too (hopefully just for reference):

https://lists.xenproject.org/archives/html/xen-devel/2021-01/msg01376.html

As indeed the symptoms were similar, such as hanging during boot, but all fine with dom0_max_vcpus=1. However, Jan is currently investigating this one, and they're heading toward problems with TSC reliability reporting and rendezvous, but let's see.

Did I forget any?

As for "the plan", I am currently working on 4 (trying to come up with a patch that fixes it) and on 1 (trying to come up with a way to track down and uncover what I believe is the real issue).

Regards

Signature · 6 lines
Dario Faggioli, Ph.D
http://about.me/dario.faggioli
Virtualization Software Engineer
SUSE Labs, SUSE https://www.suse.com/
-------------------------------------------------------------------
<<This happens because _I_ choose it to happen!>> (Raistlin Majere)
#15 lore raw
Quoted 14 lines · Dario Faggioli

[...]

2) Then there has been his one:

https://lists.xenproject.org/archives/html/xen-devel/2020-10/msg01005.html

Here, the where reporter said that "[credit1] results is an observable
delay, unusable performance; credit2 seems to be the only usable scheduler". This is the one that also Andrew mention, happening on Ryzen and with SMT disabled (as this is on QubesOS, IIRC).

Quoted 5 lines

Here, doing "dom0_max_vcpus=1 dom0_vcpus_pin" seemed to mitigate the problem but, of course, with obvious limitations. I don't have a Ryzen
handy, but I have a Zen and a Zen2.

And, what I meant here was "I have an EPYC and an EPYC2". Sorry.

Also, in my previous email, I forgot to properly trim the context above my actual reply.

Sorry about that too.

Signature · 6 lines
Dario Faggioli, Ph.D
http://about.me/dario.faggioli
Virtualization Software Engineer
SUSE Labs, SUSE https://www.suse.com/
-------------------------------------------------------------------
<<This happens because _I_ choose it to happen!>> (Raistlin Majere)
#16 lore raw
In reply to Dario Faggioli
Quoted 91 lines · Dario Faggioli
Quoted 9 lines · Andrew Cooper

2) "scheduler broken" bugs.  We've had 4 or 5 reports of Xen not working, and very little investigation on whats going on.  Suspicion is
that there might be two bugs, one with smt=0 on recent AMD hardware, and
one more general "some workloads cause negative credit" and might or might not be specific to credit2 (debugging feedback differs - also might be 3 underlying issue).

Yep, so, let's try to summarize/collect the ones I think you may be referring to:

1) There is one report about Credit2 not working, while Credit1 was fine. It's this one:

https://lists.xenproject.org/archives/html/xen-devel/2020-10/msg01561.html

It's the one where it somehow happens that one or more vCPUs manage to run for a really really long timeslice, much more than the scheduler would have allowed them to, and this cause problems. _If_ that's it, my investigation so far seems to show that this happens despite scheduler code tries to enforce (via timers) the proper timeslice limits. when it happens, makes the scheduler very unhappy. I've see reports of it occurring both on Credit and Credit2, but definitely Credit2 seems to be more sensitive to it.

I've actually been trying to track it down for a while now, but I can't easily reproduce it, so it's proving to be challenging.

2) Then there has been his one:

https://lists.xenproject.org/archives/html/xen-devel/2020-10/msg01005.html

Here, the where reporter said that "[credit1] results is an observable delay, unusable performance; credit2 seems to be the only usable scheduler". This is the one that also Andrew mention, happening on Ryzen and with SMT disabled (as this is on QubesOS, IIRC).

Here, doing "dom0_max_vcpus=1 dom0_vcpus_pin" seemed to mitigate the problem but, of course, with obvious limitations. I don't have a Ryzen handy, but I have a Zen and a Zen2. I checked there and again could not reproduce (although, what I tried was upstream Xen, not QubesOS).

3) Then I recall this one:

https://lists.xenproject.org/archives/html/xen-devel/2020-10/msg01800.html

This also started as a "scheduler, probably Credit2" bug. But it then turned out manifests on both Credit1 and Credit2 and it started to happen on 4.14, while it was not there in 4.13... And nothing major changed in scheduling between these two releases, I think.

During the analysis, we thought we identified a livelock, but then could not pinpoint what was exactly going on. Oh, and then it was also discovered that Credit2 + PVH dom0 seemed to be a working configuration, and it's weird for a scheduling issue to have a (dom0) domain type dependency, I think. But that could be anything really... and I'm sure happy to keep digging.

4) There's the NULL scheduler + ARM + vwfi=native issue:

https://lists.xenproject.org/archives/html/xen-devel/2021-01/msg01634.html

This looks like something that we saw before, but remained unfixed, although not exactly like that. If it's that one, analysis is done, and we're working on a patch. If it's something else or even something similar but slightly different... Well, we'll have to see when we have the patch.

5) We're also dealing with this bugreport, although this is being reported against Xen 4.13 (openSUSE 's packaged version of it):

https://bugzilla.opensuse.org/show_bug.cgi?id=1179246

This is again on recent AMD hardware and here, "dom0_max_vcpus=4 dom0_vcpus_pin" works ok, but only until a (Windows) HVM guest is started. When that happens, though, we have crashes/hangs.

If guests are PV, things are apparently fine. If the HVM guests use a different set of CPUs than dom0 (e.g., vm.cpumask="4-63" in xl.conf), thinks are fine as well.

Again a scheduler issue and a scheduling algorithm dependency was theorized and will be investigated (if the user can come back with answers, which may take some time, as explained in the report). The different behavior with different kind of guests is a little weird for an issue of this kind, IME, but let's see.

6) If we want, we can include this too (hopefully just for reference):

Quoted 8 lines

https://lists.xenproject.org/archives/html/xen-devel/2021-01/msg01376.html

As indeed the symptoms were similar, such as hanging during boot, but all fine with dom0_max_vcpus=1. However, Jan is currently investigating this one, and they're heading toward problems with TSC reliability reporting and rendezvous, but let's see.

Did I forget any?

Going just from my mailbox, where I didn't keep all of the still unaddressed reports, but some (another one I have there is among the ones you've mentioned above):

https://lists.xen.org/archives/html/xen-devel/2020-03/msg01251.html
https://lists.xen.org/archives/html/xen-devel/2020-05/msg01985.html

Jan

#17 lore raw
Quoted 10 lines · Jan Beulich
Quoted 2 lines · Dario Faggioli

Did I forget any?

Going just from my mailbox, where I didn't keep all of the still unaddressed reports, but some (another one I have there is among the ones you've mentioned above):

https://lists.xen.org/archives/html/xen-devel/2020-03/msg01251.html

Yes, thanks! Now that you mention it, I do remember this one. It definitely does look like scheduling related (not scheduling algorithm probably, but "scheduling as a whole").

Well, I now have boxes that supports suspend that I can use, so I will try *again* to reproduce it locally.

Quoted 2 lines

https://lists.xen.org/archives/html/xen-devel/2020-05/msg01985.html

Yes. So, my working theory is that this is the same issue as:

https://lists.xenproject.org/archives/html/xen-devel/2020-10/msg01561.html

I.e., the one that I listed as 1) in my "recap" (actually, I though I mentioned it there somewhere, but now that I check, I actually didn't, so thanks for this too).

Regards

Signature · 6 lines
Dario Faggioli, Ph.D
http://about.me/dario.faggioli
Virtualization Software Engineer
SUSE Labs, SUSE https://www.suse.com/
-------------------------------------------------------------------
<<This happens because _I_ choose it to happen!>> (Raistlin Majere)
#18 lore raw

v4 cover IOREQ feature (+ virtio-mmio) on Arm

From: Oleksandr Tyshchenko <[email protected]>

Hello all.

The purpose of this patch series is to add IOREQ/DM support to Xen on Arm. You can find an initial discussion at [1] and RFC-V3 series at [2]-[5]. Xen on Arm requires some implementation to forward guest MMIO access to a device model in order to implement virtio-mmio backend or even mediator outside of hypervisor. As Xen on x86 already contains required support this series tries to make it common and introduce Arm specific bits plus some new functionality. Patch series is based on Julien's PoC "xen/arm: Add support for Guest IO forwarding to a device emulator". Besides splitting existing IOREQ/DM support and introducing Arm side, the series also includes virtio-mmio related changes (last 2 patches for toolstack) for the reviewers to be able to see how the whole picture could look like and give it a try.

According to the initial/subsequent discussions there are a few open questions/concerns regarding security, performance in VirtIO solution:
1. virtio-mmio vs virtio-pci, SPI vs MSI, or even a composition of virtio-mmio + MSI, different use-cases require different transport...
2. virtio backend is able to access all guest memory, some kind of protection is needed: 'virtio-iommu in Xen' vs 'pre-shared-memory & memcpys in guest', etc (for the first two Alex have provided valuable input at [6])
3. interface between toolstack and 'out-of-qemu' virtio backend, avoid using Xenstore in virtio backend if possible. Also, there is a desire to make VirtIO backend hypervisor-agnostic.
4. a lot of 'foreing mapping' could lead to the memory exhaustion at the host side, as we are stealing the page from host memory in order to map the guest page. Julien has some idea regarding that.
5. Julien also has some ideas how to optimize the IOREQ code:
5.1 vcpu_ioreq_handle_completion (former handle_hvm_io_completion) which is called in
an hotpath on Arm (everytime we are re-entering to the guest):
Ideally, vcpu_ioreq_handle_completion should be a NOP (at max a few instructions) if there is nothing to do (if we don't have I/O forwarded to an IOREQ server). Maybe we want to introduce a per-vCPU flag indicating if an I/O has been forwarded to an IOREQ server. This would allow us to bypass most of the function if there is nothing to do.
5.2 The current way to handle MMIO is the following:
- Pause the vCPU
- Forward the access to the backend domain
- Schedule the backend domain
- Wait for the access to be handled
- Unpause the vCPU
The sequence is going to be fairly expensive on Xen.
It might be possible to optimize the ACK and avoid to wait for the backend to handle the access.

Looks like all of them are valid and worth considering, but the first thing which we need on Arm is a mechanism to forward guest IO to a device emulator, so let's focus on it in the first place.

***

There are a lot of changes since RFC series, almost all TODOs were resolved on Arm, Arm code was improved and hardened, common IOREQ/DM code became really arch-agnostic (without HVM-ism), the "legacy" mechanism of mapping magic pages for the IOREQ servers was left x86 specific, etc. Also patch that makes DM code public was reworked to have the top level dm-op handling arch-specific and call into ioreq_server_dm_op() for otherwise unhandled ops.
But one TODO still remains which is "PIO handling" on Arm.
The "PIO handling" TODO is expected to left unaddressed for the current series. It is not an big issue for now while Xen doesn't have support for vPCI on Arm. On Arm64 they are only used for PCI IO Bar and we would probably want to expose them to emulator as PIO access to make a DM completely arch-agnostic. So "PIO handling" should be implemented when we add support for vPCI.

I left interface untouched in the following patch "xen/dm: Introduce xendevicemodel_set_irq_level DM op" since there is still an open discussion what interface to use/what information to pass to the hypervisor.

There are patches on review this series depends on:
https://patchwork.kernel.org/patch/11816689
https://patchwork.kernel.org/patch/11803383

Please note, that IOREQ feature is disabled by default on Arm within current series.

***

Patch series [7] was rebased on recent "staging branch"
(7ba2ab4 x86/p2m: Fix paging_gva_to_gfn() for nested virt) and tested on Renesas Salvator-X board + H3 ES3.0 SoC (Arm64) with virtio-mmio disk backend [8] running in driver domain and unmodified Linux Guest running on existing virtio-blk driver (frontend). No issues were observed. Guest domain 'reboot/destroy' use-cases work properly. Patch series was only build-tested on x86.

Please note, build-test passed for the following modes:
1. x86: CONFIG_HVM=y / CONFIG_IOREQ_SERVER=y (default)
2. x86: #CONFIG_HVM is not set / #CONFIG_IOREQ_SERVER is not set
3. Arm64: CONFIG_HVM=y / CONFIG_IOREQ_SERVER=y
4. Arm64: CONFIG_HVM=y / #CONFIG_IOREQ_SERVER is not set (default)
5. Arm32: CONFIG_HVM=y / CONFIG_IOREQ_SERVER=y
6. Arm32: CONFIG_HVM=y / #CONFIG_IOREQ_SERVER is not set (default)

***

Any feedback/help would be highly appreciated.

[1] https://lists.xenproject.org/archives/html/xen-devel/2020-07/msg00825.html
[2] https://lists.xenproject.org/archives/html/xen-devel/2020-08/msg00071.html
[3] https://lists.xenproject.org/archives/html/xen-devel/2020-09/msg00732.html
[4] https://lists.xenproject.org/archives/html/xen-devel/2020-10/msg01077.html
[5] https://lists.xenproject.org/archives/html/xen-devel/2020-11/msg02188.html
[6] https://lists.xenproject.org/archives/html/xen-devel/2020-11/msg02212.html
[7] https://github.com/otyshchenko1/xen/commits/ioreq_4.14_ml5
[8] https://github.com/xen-troops/virtio-disk/commits/ioreq_ml1

Julien Grall (5):
xen/ioreq: Make x86's IOREQ related dm-op handling common xen/mm: Make x86's XENMEM_resource_ioreq_server handling common arm/ioreq: Introduce arch specific bits for IOREQ/DM features xen/dm: Introduce xendevicemodel_set_irq_level DM op
libxl: Introduce basic virtio-mmio support on Arm

Oleksandr Tyshchenko (19):
x86/ioreq: Prepare IOREQ feature for making it common x86/ioreq: Add IOREQ_STATUS_* #define-s and update code for moving x86/ioreq: Provide out-of-line wrapper for the handle_mmio() xen/ioreq: Make x86's IOREQ feature common
xen/ioreq: Make x86's hvm_ioreq_needs_completion() common xen/ioreq: Make x86's hvm_mmio_first(last)_byte() common xen/ioreq: Make x86's hvm_ioreq_(page/vcpu/server) structs common xen/ioreq: Move x86's ioreq_server to struct domain xen/ioreq: Move x86's io_completion/io_req fields to struct vcpu xen/ioreq: Remove "hvm" prefixes from involved function names xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg() xen/arm: Stick around in leave_hypervisor_to_guest until I/O has
completed
xen/mm: Handle properly reference in set_foreign_p2m_entry() on Arm xen/ioreq: Introduce domain_has_ioreq_server()
xen/arm: io: Abstract sign-extension
xen/arm: io: Harden sign extension check
xen/ioreq: Make x86's send_invalidate_req() common xen/arm: Add mapcache invalidation handling
[RFC] libxl: Add support for virtio-disk configuration

 MAINTAINERS                                  |    8 +-
 tools/include/xendevicemodel.h               |    4 +
 tools/libs/devicemodel/core.c                |   18 +
 tools/libs/devicemodel/libxendevicemodel.map |    1 +
 tools/libs/light/Makefile                    |    1 +
 tools/libs/light/libxl_arm.c                 |   94 +-
 tools/libs/light/libxl_create.c              |    1 +
 tools/libs/light/libxl_internal.h            |    1 +
 tools/libs/light/libxl_types.idl             |   16 +
 tools/libs/light/libxl_types_internal.idl    |    1 +
 tools/libs/light/libxl_virtio_disk.c         |  109 ++
 tools/xl/Makefile                            |    2 +-
 tools/xl/xl.h                                |    3 +
 tools/xl/xl_cmdtable.c                       |   15 +
 tools/xl/xl_parse.c                          |  116 +++
 tools/xl/xl_virtio_disk.c                    |   46 +
 xen/arch/arm/Makefile                        |    2 +
 xen/arch/arm/dm.c                            |  174 ++++
 xen/arch/arm/domain.c                        |    9 +
 xen/arch/arm/io.c                            |   30 +-
 xen/arch/arm/ioreq.c                         |  198 ++++
 xen/arch/arm/p2m.c                           |   51 +-
 xen/arch/arm/traps.c                         |   72 +-
 xen/arch/x86/Kconfig                         |    1 +
 xen/arch/x86/hvm/dm.c                        |  107 +-
 xen/arch/x86/hvm/emulate.c                   |  220 ++--
 xen/arch/x86/hvm/hvm.c                       |   14 +-
 xen/arch/x86/hvm/hypercall.c                 |    9 +-
 xen/arch/x86/hvm/intercept.c                 |    5 +-
 xen/arch/x86/hvm/io.c                        |   52 +-
 xen/arch/x86/hvm/ioreq.c                     | 1375 ++-----------------------
 xen/arch/x86/hvm/stdvga.c                    |   12 +-
 xen/arch/x86/hvm/svm/nestedsvm.c             |    2 +-
 xen/arch/x86/hvm/vmx/realmode.c              |    8 +-
 xen/arch/x86/hvm/vmx/vvmx.c                  |    5 +-
 xen/arch/x86/mm.c                            |   46 +-
 xen/arch/x86/mm/p2m.c                        |   17 +-
 xen/arch/x86/mm/shadow/common.c              |    2 +-
 xen/common/Kconfig                           |    3 +
 xen/common/Makefile                          |    1 +
 xen/common/ioreq.c                           | 1426 ++++++++++++++++++++++++++
 xen/common/memory.c                          |   72 +-
 xen/include/asm-arm/domain.h                 |    3 +
 xen/include/asm-arm/hvm/ioreq.h              |   72 ++
 xen/include/asm-arm/mm.h                     |    8 -
 xen/include/asm-arm/mmio.h                   |    1 +
 xen/include/asm-arm/p2m.h                    |   19 +-
 xen/include/asm-arm/traps.h                  |   25 +
 xen/include/asm-x86/hvm/domain.h             |   43 -
 xen/include/asm-x86/hvm/emulate.h            |    2 +-
 xen/include/asm-x86/hvm/io.h                 |   17 -
 xen/include/asm-x86/hvm/ioreq.h              |   39 +-
 xen/include/asm-x86/hvm/vcpu.h               |   18 -
 xen/include/asm-x86/mm.h                     |    4 -
 xen/include/asm-x86/p2m.h                    |   27 +-
 xen/include/public/arch-arm.h                |    5 +
 xen/include/public/hvm/dm_op.h               |   16 +
 xen/include/xen/dm.h                         |   39 +
 xen/include/xen/ioreq.h                      |  140 +++
 xen/include/xen/p2m-common.h                 |    4 +
 xen/include/xen/sched.h                      |   34 +
 xen/include/xsm/dummy.h                      |    4 +-
 xen/include/xsm/xsm.h                        |    6 +-
 xen/xsm/dummy.c                              |    2 +-
 xen/xsm/flask/hooks.c                        |    5 +-
 65 files changed, 3073 insertions(+), 1809 deletions(-)
 create mode 100644 tools/libs/light/libxl_virtio_disk.c
 create mode 100644 tools/xl/xl_virtio_disk.c
 create mode 100644 xen/arch/arm/dm.c
 create mode 100644 xen/arch/arm/ioreq.c
 create mode 100644 xen/common/ioreq.c
 create mode 100644 xen/include/asm-arm/hvm/ioreq.h
 create mode 100644 xen/include/xen/dm.h
 create mode 100644 xen/include/xen/ioreq.h
Signature · 1 line
2.7.4
#19 lore raw

PATCH v4 1/24 x86/ioreq: Prepare IOREQ feature for making it common

From: Oleksandr Tyshchenko <[email protected]>

As a lot of x86 code can be re-used on Arm later on, this patch makes some preparation to x86/hvm/ioreq.c before moving to the common code. This way we will get a verbatim copy for a code movement in subsequent patch.

This patch mostly introduces specific hooks to abstract arch specific materials taking into the account the requirment to leave the "legacy" mechanism of mapping magic pages for the IOREQ servers x86 specific and not expose it to the common code.

These hooks are named according to the more consistent new naming scheme right away (including dropping the "hvm" prefixes and infixes):
- IOREQ server functions should start with "ioreq_server_"
- IOREQ functions should start with "ioreq_"
other functions will be renamed in subsequent patches.

Also re-order #include-s alphabetically.

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- new patch, was split from:
"[RFC PATCH V1 01/12] hvm/ioreq: Make x86's IOREQ feature common"
- fold the check of p->type into hvm_get_ioreq_server_range_type() and make it return success/failure
- remove relocate_portio_handler() call from arch_hvm_ioreq_destroy()

     in arch/x86/hvm/ioreq.c

- introduce arch_hvm_destroy_ioreq_server()/arch_handle_hvm_io_completion()

Changes V1 -> V2:
- update patch description
- make arch functions inline and put them into arch header
to achieve a truly rename by the subsequent patch
- return void in arch_hvm_destroy_ioreq_server()
- return bool in arch_hvm_ioreq_destroy()
- bring relocate_portio_handler() back to arch_hvm_ioreq_destroy()
- rename IOREQ_IO* to IOREQ_STATUS*
- remove *handle* from arch_handle_hvm_io_completion()
- re-order #include-s alphabetically
- rename hvm_get_ioreq_server_range_type() to hvm_ioreq_server_get_type_addr() and add "const" to several arguments

Changes V2 -> V3:
- update patch description
- name new arch hooks according to the new naming scheme
- don't make arch hooks inline, move them ioreq.c
- make get_ioreq_server() local again
- rework the whole patch taking into the account that "legacy" interface should remain x86 specific (additional arch hooks, etc)
- update the code to be able to use hvm_map_mem_type_to_ioreq_server() in the common code (an extra arch hook, etc)
- don’t include <asm/hvm/emulate.h> from arch header
- add "arch" prefix to hvm_ioreq_server_get_type_addr()
- move IOREQ_STATUS_* #define-s introduction to the separate patch
- move HANDLE_BUFIOREQ to the arch header
- just return relocate_portio_handler() from arch_ioreq_server_destroy_all()
- misc adjustments proposed by Jan (adding const, unsigned int instead of uint32_t)

Changes V3 -> V4:
- add Alex's R-b
- update patch description
- make arch_ioreq_server_get_type_addr return bool
- drop #include <xen/ctype.h>
- use two arch hooks in hvm_map_mem_type_to_ioreq_server() to avoid calling p2m_change_entry_type_global() with lock held

---
 xen/arch/x86/hvm/ioreq.c        | 179 ++++++++++++++++++++++++++--------------
 xen/include/asm-x86/hvm/ioreq.h |  22 +++++
 2 files changed, 141 insertions(+), 60 deletions(-)
xen/arch/x86/hvm/ioreq.c +119 -60
index 1cc27df..468fe84 100644
@@ -16,16 +16,15 @@
  * this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <xen/ctype.h>
+#include <xen/domain.h>
+#include <xen/event.h>
 #include <xen/init.h>
+#include <xen/irq.h>
 #include <xen/lib.h>
-#include <xen/trace.h>
+#include <xen/paging.h>
 #include <xen/sched.h>
-#include <xen/irq.h>
 #include <xen/softirq.h>
-#include <xen/domain.h>
-#include <xen/event.h>
-#include <xen/paging.h>
+#include <xen/trace.h>
 #include <xen/vpci.h>
 
 #include <asm/hvm/emulate.h>
@@ -170,6 +169,29 @@ static bool hvm_wait_for_io(struct hvm_ioreq_vcpu *sv, ioreq_t *p)
     return true;
 }
 
+bool arch_vcpu_ioreq_completion(enum hvm_io_completion io_completion)
+{
+    switch ( io_completion )
+    {
+    case HVMIO_realmode_completion:
+    {
+        struct hvm_emulate_ctxt ctxt;
+
+        hvm_emulate_init_once(&ctxt, NULL, guest_cpu_user_regs());
+        vmx_realmode_emulate_one(&ctxt);
+        hvm_emulate_writeback(&ctxt);
+
+        break;
+    }
+
+    default:
+        ASSERT_UNREACHABLE();
+        break;
+    }
+
+    return true;
+}
+
 bool handle_hvm_io_completion(struct vcpu *v)
 {
     struct domain *d = v->domain;
@@ -209,19 +231,8 @@ bool handle_hvm_io_completion(struct vcpu *v)
         return handle_pio(vio->io_req.addr, vio->io_req.size,
                           vio->io_req.dir);
 
-    case HVMIO_realmode_completion:
-    {
-        struct hvm_emulate_ctxt ctxt;
-
-        hvm_emulate_init_once(&ctxt, NULL, guest_cpu_user_regs());
-        vmx_realmode_emulate_one(&ctxt);
-        hvm_emulate_writeback(&ctxt);
-
-        break;
-    }
     default:
-        ASSERT_UNREACHABLE();
-        break;
+        return arch_vcpu_ioreq_completion(io_completion);
     }
 
     return true;
@@ -477,9 +488,6 @@ static void hvm_update_ioreq_evtchn(struct hvm_ioreq_server *s,
     }
 }
 
-#define HANDLE_BUFIOREQ(s) \
-    ((s)->bufioreq_handling != HVM_IOREQSRV_BUFIOREQ_OFF)
-
 static int hvm_ioreq_server_add_vcpu(struct hvm_ioreq_server *s,
                                      struct vcpu *v)
 {
@@ -586,7 +594,7 @@ static void hvm_ioreq_server_remove_all_vcpus(struct hvm_ioreq_server *s)
     spin_unlock(&s->lock);
 }
 
-static int hvm_ioreq_server_map_pages(struct hvm_ioreq_server *s)
+int arch_ioreq_server_map_pages(struct hvm_ioreq_server *s)
 {
     int rc;
 
@@ -601,7 +609,7 @@ static int hvm_ioreq_server_map_pages(struct hvm_ioreq_server *s)
     return rc;
 }
 
-static void hvm_ioreq_server_unmap_pages(struct hvm_ioreq_server *s)
+void arch_ioreq_server_unmap_pages(struct hvm_ioreq_server *s)
 {
     hvm_unmap_ioreq_gfn(s, true);
     hvm_unmap_ioreq_gfn(s, false);
@@ -674,6 +682,12 @@ static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server *s,
     return rc;
 }
 
+void arch_ioreq_server_enable(struct hvm_ioreq_server *s)
+{
+    hvm_remove_ioreq_gfn(s, false);
+    hvm_remove_ioreq_gfn(s, true);
+}
+
 static void hvm_ioreq_server_enable(struct hvm_ioreq_server *s)
 {
     struct hvm_ioreq_vcpu *sv;
@@ -683,8 +697,7 @@ static void hvm_ioreq_server_enable(struct hvm_ioreq_server *s)
     if ( s->enabled )
         goto done;
 
-    hvm_remove_ioreq_gfn(s, false);
-    hvm_remove_ioreq_gfn(s, true);
+    arch_ioreq_server_enable(s);
 
     s->enabled = true;
 
@@ -697,6 +710,12 @@ static void hvm_ioreq_server_enable(struct hvm_ioreq_server *s)
     spin_unlock(&s->lock);
 }
 
+void arch_ioreq_server_disable(struct hvm_ioreq_server *s)
+{
+    hvm_add_ioreq_gfn(s, true);
+    hvm_add_ioreq_gfn(s, false);
+}
+
 static void hvm_ioreq_server_disable(struct hvm_ioreq_server *s)
 {
     spin_lock(&s->lock);
@@ -704,8 +723,7 @@ static void hvm_ioreq_server_disable(struct hvm_ioreq_server *s)
     if ( !s->enabled )
         goto done;
 
-    hvm_add_ioreq_gfn(s, true);
-    hvm_add_ioreq_gfn(s, false);
+    arch_ioreq_server_disable(s);
 
     s->enabled = false;
 
@@ -750,7 +768,7 @@ static int hvm_ioreq_server_init(struct hvm_ioreq_server *s,
 
  fail_add:
     hvm_ioreq_server_remove_all_vcpus(s);
-    hvm_ioreq_server_unmap_pages(s);
+    arch_ioreq_server_unmap_pages(s);
 
     hvm_ioreq_server_free_rangesets(s);
 
@@ -764,7 +782,7 @@ static void hvm_ioreq_server_deinit(struct hvm_ioreq_server *s)
     hvm_ioreq_server_remove_all_vcpus(s);
 
     /*
-     * NOTE: It is safe to call both hvm_ioreq_server_unmap_pages() and
+     * NOTE: It is safe to call both arch_ioreq_server_unmap_pages() and
      *       hvm_ioreq_server_free_pages() in that order.
      *       This is because the former will do nothing if the pages
      *       are not mapped, leaving the page to be freed by the latter.
@@ -772,7 +790,7 @@ static void hvm_ioreq_server_deinit(struct hvm_ioreq_server *s)
      *       the page_info pointer to NULL, meaning the latter will do
      *       nothing.
      */
-    hvm_ioreq_server_unmap_pages(s);
+    arch_ioreq_server_unmap_pages(s);
     hvm_ioreq_server_free_pages(s);
 
     hvm_ioreq_server_free_rangesets(s);
@@ -836,6 +854,12 @@ int hvm_create_ioreq_server(struct domain *d, int bufioreq_handling,
     return rc;
 }
 
+/* Called when target domain is paused */
+void arch_ioreq_server_destroy(struct hvm_ioreq_server *s)
+{
+    p2m_set_ioreq_server(s->target, 0, s);
+}
+
 int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id)
 {
     struct hvm_ioreq_server *s;
@@ -855,7 +879,7 @@ int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id)
 
     domain_pause(d);
 
-    p2m_set_ioreq_server(d, 0, s);
+    arch_ioreq_server_destroy(s);
 
     hvm_ioreq_server_disable(s);
 
@@ -900,7 +924,7 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,
 
     if ( ioreq_gfn || bufioreq_gfn )
     {
-        rc = hvm_ioreq_server_map_pages(s);
+        rc = arch_ioreq_server_map_pages(s);
         if ( rc )
             goto out;
     }
@@ -1080,6 +1104,27 @@ int hvm_unmap_io_range_from_ioreq_server(struct domain *d, ioservid_t id,
     return rc;
 }
 
+/* Called with ioreq_server lock held */
+int arch_ioreq_server_map_mem_type(struct domain *d,
+                                   struct hvm_ioreq_server *s,
+                                   uint32_t flags)
+{
+    return p2m_set_ioreq_server(d, flags, s);
+}
+
+void arch_ioreq_server_map_mem_type_completed(struct domain *d,
+                                              struct hvm_ioreq_server *s,
+                                              uint32_t flags)
+{
+    if ( flags == 0 )
+    {
+        const struct p2m_domain *p2m = p2m_get_hostp2m(d);
+
+        if ( read_atomic(&p2m->ioreq.entry_count) )
+            p2m_change_entry_type_global(d, p2m_ioreq_server, p2m_ram_rw);
+    }
+}
+
 /*
  * Map or unmap an ioreq server to specific memory type. For now, only
  * HVMMEM_ioreq_server is supported, and in the future new types can be
@@ -1112,18 +1157,13 @@ int hvm_map_mem_type_to_ioreq_server(struct domain *d, ioservid_t id,
     if ( s->emulator != current->domain )
         goto out;
 
-    rc = p2m_set_ioreq_server(d, flags, s);
+    rc = arch_ioreq_server_map_mem_type(d, s, flags);
 
  out:
     spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
 
-    if ( rc == 0 && flags == 0 )
-    {
-        struct p2m_domain *p2m = p2m_get_hostp2m(d);
-
-        if ( read_atomic(&p2m->ioreq.entry_count) )
-            p2m_change_entry_type_global(d, p2m_ioreq_server, p2m_ram_rw);
-    }
+    if ( rc == 0 )
+        arch_ioreq_server_map_mem_type_completed(d, s, flags);
 
     return rc;
 }
@@ -1210,12 +1250,17 @@ void hvm_all_ioreq_servers_remove_vcpu(struct domain *d, struct vcpu *v)
     spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
 }
 
+bool arch_ioreq_server_destroy_all(struct domain *d)
+{
+    return relocate_portio_handler(d, 0xcf8, 0xcf8, 4);
+}
+
 void hvm_destroy_all_ioreq_servers(struct domain *d)
 {
     struct hvm_ioreq_server *s;
     unsigned int id;
 
-    if ( !relocate_portio_handler(d, 0xcf8, 0xcf8, 4) )
+    if ( !arch_ioreq_server_destroy_all(d) )
         return;
 
     spin_lock_recursive(&d->arch.hvm.ioreq_server.lock);
@@ -1239,33 +1284,28 @@ void hvm_destroy_all_ioreq_servers(struct domain *d)
     spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
 }
 
-struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,
-                                                 ioreq_t *p)
+bool arch_ioreq_server_get_type_addr(const struct domain *d,
+                                     const ioreq_t *p,
+                                     uint8_t *type,
+                                     uint64_t *addr)
 {
-    struct hvm_ioreq_server *s;
-    uint32_t cf8;
-    uint8_t type;
-    uint64_t addr;
-    unsigned int id;
+    unsigned int cf8 = d->arch.hvm.pci_cf8;
 
     if ( p->type != IOREQ_TYPE_COPY && p->type != IOREQ_TYPE_PIO )
-        return NULL;
-
-    cf8 = d->arch.hvm.pci_cf8;
+        return false;
 
     if ( p->type == IOREQ_TYPE_PIO &&
          (p->addr & ~3) == 0xcfc &&
          CF8_ENABLED(cf8) )
     {
-        uint32_t x86_fam;
+        unsigned int x86_fam, reg;
         pci_sbdf_t sbdf;
-        unsigned int reg;
 
         reg = hvm_pci_decode_addr(cf8, p->addr, &sbdf);
 
         /* PCI config data cycle */
-        type = XEN_DMOP_IO_RANGE_PCI;
-        addr = ((uint64_t)sbdf.sbdf << 32) | reg;
+        *type = XEN_DMOP_IO_RANGE_PCI;
+        *addr = ((uint64_t)sbdf.sbdf << 32) | reg;
         /* AMD extended configuration space access? */
         if ( CF8_ADDR_HI(cf8) &&
              d->arch.cpuid->x86_vendor == X86_VENDOR_AMD &&
@@ -1277,16 +1317,30 @@ struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,
 
             if ( !rdmsr_safe(MSR_AMD64_NB_CFG, msr_val) &&
                  (msr_val & (1ULL << AMD64_NB_CFG_CF8_EXT_ENABLE_BIT)) )
-                addr |= CF8_ADDR_HI(cf8);
+                *addr |= CF8_ADDR_HI(cf8);
         }
     }
     else
     {
-        type = (p->type == IOREQ_TYPE_PIO) ?
-                XEN_DMOP_IO_RANGE_PORT : XEN_DMOP_IO_RANGE_MEMORY;
-        addr = p->addr;
+        *type = (p->type == IOREQ_TYPE_PIO) ?
+                 XEN_DMOP_IO_RANGE_PORT : XEN_DMOP_IO_RANGE_MEMORY;
+        *addr = p->addr;
     }
 
+    return true;
+}
+
+struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,
+                                                 ioreq_t *p)
+{
+    struct hvm_ioreq_server *s;
+    uint8_t type;
+    uint64_t addr;
+    unsigned int id;
+
+    if ( !arch_ioreq_server_get_type_addr(d, p, &type, &addr) )
+        return NULL;
+
     FOR_EACH_IOREQ_SERVER(d, id, s)
     {
         struct rangeset *r;
@@ -1515,11 +1569,16 @@ static int hvm_access_cf8(
     return X86EMUL_UNHANDLEABLE;
 }
 
+void arch_ioreq_domain_init(struct domain *d)
+{
+    register_portio_handler(d, 0xcf8, 4, hvm_access_cf8);
+}
+
 void hvm_ioreq_init(struct domain *d)
 {
     spin_lock_init(&d->arch.hvm.ioreq_server.lock);
 
-    register_portio_handler(d, 0xcf8, 4, hvm_access_cf8);
+    arch_ioreq_domain_init(d);
 }
 
 /*
xen/include/asm-x86/hvm/ioreq.h +22 -0
index e2588e9..13d35e1 100644
@@ -19,6 +19,9 @@
 #ifndef __ASM_X86_HVM_IOREQ_H__
 #define __ASM_X86_HVM_IOREQ_H__
 
+#define HANDLE_BUFIOREQ(s) \
+    ((s)->bufioreq_handling != HVM_IOREQSRV_BUFIOREQ_OFF)
+
 bool hvm_io_pending(struct vcpu *v);
 bool handle_hvm_io_completion(struct vcpu *v);
 bool is_ioreq_server_page(struct domain *d, const struct page_info *page);
@@ -55,6 +58,25 @@ unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered);
 
 void hvm_ioreq_init(struct domain *d);
 
+bool arch_vcpu_ioreq_completion(enum hvm_io_completion io_completion);
+int arch_ioreq_server_map_pages(struct hvm_ioreq_server *s);
+void arch_ioreq_server_unmap_pages(struct hvm_ioreq_server *s);
+void arch_ioreq_server_enable(struct hvm_ioreq_server *s);
+void arch_ioreq_server_disable(struct hvm_ioreq_server *s);
+void arch_ioreq_server_destroy(struct hvm_ioreq_server *s);
+int arch_ioreq_server_map_mem_type(struct domain *d,
+                                   struct hvm_ioreq_server *s,
+                                   uint32_t flags);
+void arch_ioreq_server_map_mem_type_completed(struct domain *d,
+                                              struct hvm_ioreq_server *s,
+                                              uint32_t flags);
+bool arch_ioreq_server_destroy_all(struct domain *d);
+bool arch_ioreq_server_get_type_addr(const struct domain *d,
+                                     const ioreq_t *p,
+                                     uint8_t *type,
+                                     uint64_t *addr);
+void arch_ioreq_domain_init(struct domain *d);
+
 #endif /* __ASM_X86_HVM_IOREQ_H__ */
 
 /*
Signature · 1 line
2.7.4
Reviewed-by on v4 1/24
#20 lore raw

Re: [PATCH V4 01/24] x86/ioreq: Prepare IOREQ feature for making it common

Hi Oleksandr,

Quoted 18 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

As a lot of x86 code can be re-used on Arm later on, this patch makes some preparation to x86/hvm/ioreq.c before moving to the common code. This way we will get a verbatim copy for a code movement in subsequent patch.

This patch mostly introduces specific hooks to abstract arch specific materials taking into the account the requirment to leave the "legacy" mechanism of mapping magic pages for the IOREQ servers x86 specific and not expose it to the common code.

These hooks are named according to the more consistent new naming scheme right away (including dropping the "hvm" prefixes and infixes):
- IOREQ server functions should start with "ioreq_server_"
- IOREQ functions should start with "ioreq_"
other functions will be renamed in subsequent patches.

Quoted 7 lines

Also re-order #include-s alphabetically.

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

Cheers,

Signature · 1 line
Julien Grall
#21 lore raw

Re: [PATCH V4 01/24] x86/ioreq: Prepare IOREQ feature for making it common

In reply to Oleksandr Tyshchenko
Quoted 12 lines · Oleksandr Tyshchenko
xen/arch/x86/hvm/ioreq.c +8 -0
@@ -1080,6 +1104,27 @@ int hvm_unmap_io_range_from_ioreq_server(struct domain *d, ioservid_t id,
     return rc;
 }
 
+/* Called with ioreq_server lock held */
+int arch_ioreq_server_map_mem_type(struct domain *d,
+                                   struct hvm_ioreq_server *s,
+                                   uint32_t flags)
+{
+    return p2m_set_ioreq_server(d, flags, s);
+}
+

xen/arch/x86/hvm/ioreq.c int hvm_unmap_io_range_from_ioreq_server(struct domain *d, ioservid_t id, · line 1124

Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10 -0
+void arch_ioreq_server_map_mem_type_completed(struct domain *d,
+                                              struct hvm_ioreq_server *s,
+                                              uint32_t flags)
+{
+    if ( flags == 0 )
+    {
+        const struct p2m_domain *p2m = p2m_get_hostp2m(d);
+
+        if ( read_atomic(&p2m->ioreq.entry_count) )
+            p2m_change_entry_type_global(d, p2m_ioreq_server, p2m_ram_rw);

If I was the maintainer of this code, I'd ask that such single use variables, unless needed to sensibly deal with line length restrictions, be removed.

Quoted 24 lines
xen/include/asm-x86/hvm/ioreq.h +11 -0
@@ -19,6 +19,9 @@
 #ifndef __ASM_X86_HVM_IOREQ_H__
 #define __ASM_X86_HVM_IOREQ_H__
 
+#define HANDLE_BUFIOREQ(s) \
+    ((s)->bufioreq_handling != HVM_IOREQSRV_BUFIOREQ_OFF)
+
 bool hvm_io_pending(struct vcpu *v);
 bool handle_hvm_io_completion(struct vcpu *v);
 bool is_ioreq_server_page(struct domain *d, const struct page_info *page);
@@ -55,6 +58,25 @@ unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered);
 
 void hvm_ioreq_init(struct domain *d);
 
+bool arch_vcpu_ioreq_completion(enum hvm_io_completion io_completion);
+int arch_ioreq_server_map_pages(struct hvm_ioreq_server *s);
+void arch_ioreq_server_unmap_pages(struct hvm_ioreq_server *s);
+void arch_ioreq_server_enable(struct hvm_ioreq_server *s);
+void arch_ioreq_server_disable(struct hvm_ioreq_server *s);
+void arch_ioreq_server_destroy(struct hvm_ioreq_server *s);
+int arch_ioreq_server_map_mem_type(struct domain *d,
+                                   struct hvm_ioreq_server *s,

xen/include/asm-x86/hvm/ioreq.h unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered); · line 78

Quoted 10 lines
xen/include/asm-x86/hvm/ioreq.h +10 -0
+                                   uint32_t flags);
+void arch_ioreq_server_map_mem_type_completed(struct domain *d,
+                                              struct hvm_ioreq_server *s,
+                                              uint32_t flags);
+bool arch_ioreq_server_destroy_all(struct domain *d);
+bool arch_ioreq_server_get_type_addr(const struct domain *d,
+                                     const ioreq_t *p,
+                                     uint8_t *type,
+                                     uint64_t *addr);
+void arch_ioreq_domain_init(struct domain *d);

As indicated before, I don't think these declarations should live here. Even if a later patch moves them I wouldn't see why they couldn't be put in their final resting place right away.

Also where possible without violating line length restrictions please still try to put multiple parameters on a single line, as is done higher up in this file.

Jan

#22 lore raw

Re: [PATCH V4 01/24] x86/ioreq: Prepare IOREQ feature for making it common

On 15.01.21 18:41, Jan Beulich wrote:

Hi Jan

Quoted 18 lines · Oleksandr Tyshchenko
Quoted 17 lines
xen/arch/x86/hvm/ioreq.c +13 -0
@@ -1080,6 +1104,27 @@ int hvm_unmap_io_range_from_ioreq_server(struct domain *d, ioservid_t id,
      return rc;
  }
 
+/* Called with ioreq_server lock held */
+int arch_ioreq_server_map_mem_type(struct domain *d,
+                                   struct hvm_ioreq_server *s,
+                                   uint32_t flags)
+{
+    return p2m_set_ioreq_server(d, flags, s);
+}
+
+void arch_ioreq_server_map_mem_type_completed(struct domain *d,
+                                              struct hvm_ioreq_server *s,
+                                              uint32_t flags)
+{
+    if ( flags == 0 )
Quoted 8 lines

xen/arch/x86/hvm/ioreq.c int hvm_unmap_io_range_from_ioreq_server(struct domain *d, ioservid_t id, · line 1124

Quoted 5 lines
xen/arch/x86/hvm/ioreq.c +5 -0
+    {
+        const struct p2m_domain *p2m = p2m_get_hostp2m(d);
+
+        if ( read_atomic(&p2m->ioreq.entry_count) )
+            p2m_change_entry_type_global(d, p2m_ioreq_server, p2m_ram_rw);

If I was the maintainer of this code, I'd ask that such single use variables, unless needed to sensibly deal with line length restrictions, be removed.

ok, will remove. With that we could omit the braces and have a combined condition on a single line.

Quoted 31 lines
Quoted 31 lines
xen/include/asm-x86/hvm/ioreq.h +17 -0
@@ -19,6 +19,9 @@
  #ifndef __ASM_X86_HVM_IOREQ_H__
  #define __ASM_X86_HVM_IOREQ_H__
 
+#define HANDLE_BUFIOREQ(s) \
+    ((s)->bufioreq_handling != HVM_IOREQSRV_BUFIOREQ_OFF)
+
  bool hvm_io_pending(struct vcpu *v);
  bool handle_hvm_io_completion(struct vcpu *v);
  bool is_ioreq_server_page(struct domain *d, const struct page_info *page);
@@ -55,6 +58,25 @@ unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered);
 
  void hvm_ioreq_init(struct domain *d);
 
+bool arch_vcpu_ioreq_completion(enum hvm_io_completion io_completion);
+int arch_ioreq_server_map_pages(struct hvm_ioreq_server *s);
+void arch_ioreq_server_unmap_pages(struct hvm_ioreq_server *s);
+void arch_ioreq_server_enable(struct hvm_ioreq_server *s);
+void arch_ioreq_server_disable(struct hvm_ioreq_server *s);
+void arch_ioreq_server_destroy(struct hvm_ioreq_server *s);
+int arch_ioreq_server_map_mem_type(struct domain *d,
+                                   struct hvm_ioreq_server *s,
+                                   uint32_t flags);
+void arch_ioreq_server_map_mem_type_completed(struct domain *d,
+                                              struct hvm_ioreq_server *s,
+                                              uint32_t flags);
+bool arch_ioreq_server_destroy_all(struct domain *d);
+bool arch_ioreq_server_get_type_addr(const struct domain *d,
Quoted 8 lines

xen/include/asm-x86/hvm/ioreq.h unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered); · line 78

Quoted 4 lines
xen/include/asm-x86/hvm/ioreq.h +4 -0
+                                     const ioreq_t *p,
+                                     uint8_t *type,
+                                     uint64_t *addr);
+void arch_ioreq_domain_init(struct domain *d);

As indicated before, I don't think these declarations should live here. Even if a later patch moves them I wouldn't see why they couldn't be put in their final resting place right away.

Well, will introduce common ioreq.h right away.

Quoted 4 lines

Also where possible without violating line length restrictions please still try to put multiple parameters on a single line, as is done higher up in this file.

Got it.

Quoted 2 lines

Jan

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
Reviewed-by on v4 1/24
#23 lore raw

RE: [PATCH V4 01/24] x86/ioreq: Prepare IOREQ feature for making it common

In reply to Oleksandr Tyshchenko
Quoted 28 lines

-----Original Message-----
From: Oleksandr Tyshchenko <[email protected]>
Sent: 12 January 2021 21:52
To: [email protected]
Cc: Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH V4 01/24] x86/ioreq: Prepare IOREQ feature for making it common

From: Oleksandr Tyshchenko <[email protected]>

As a lot of x86 code can be re-used on Arm later on, this patch makes some preparation to x86/hvm/ioreq.c before moving to the common code. This way we will get a verbatim copy for a code movement in subsequent patch.

This patch mostly introduces specific hooks to abstract arch specific materials taking into the account the requirment to leave the "legacy" mechanism of mapping magic pages for the IOREQ servers x86 specific and not expose it to the common code.

These hooks are named according to the more consistent new naming scheme right away (including dropping the "hvm" prefixes and infixes):
- IOREQ server functions should start with "ioreq_server_"
- IOREQ functions should start with "ioreq_"
other functions will be renamed in subsequent patches.

Quoted 6 lines

Also re-order #include-s alphabetically.

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

Quoted 475 lines

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- new patch, was split from:
"[RFC PATCH V1 01/12] hvm/ioreq: Make x86's IOREQ feature common"
- fold the check of p->type into hvm_get_ioreq_server_range_type() and make it return success/failure
- remove relocate_portio_handler() call from arch_hvm_ioreq_destroy()

     in arch/x86/hvm/ioreq.c

- introduce arch_hvm_destroy_ioreq_server()/arch_handle_hvm_io_completion()

Changes V1 -> V2:
- update patch description
- make arch functions inline and put them into arch header
to achieve a truly rename by the subsequent patch
- return void in arch_hvm_destroy_ioreq_server()
- return bool in arch_hvm_ioreq_destroy()
- bring relocate_portio_handler() back to arch_hvm_ioreq_destroy()
- rename IOREQ_IO* to IOREQ_STATUS*
- remove *handle* from arch_handle_hvm_io_completion()
- re-order #include-s alphabetically
- rename hvm_get_ioreq_server_range_type() to hvm_ioreq_server_get_type_addr() and add "const" to several arguments

Changes V2 -> V3:
- update patch description
- name new arch hooks according to the new naming scheme
- don't make arch hooks inline, move them ioreq.c
- make get_ioreq_server() local again
- rework the whole patch taking into the account that "legacy" interface should remain x86 specific (additional arch hooks, etc)
- update the code to be able to use hvm_map_mem_type_to_ioreq_server() in the common code (an extra arch hook, etc)
- don’t include <asm/hvm/emulate.h> from arch header
- add "arch" prefix to hvm_ioreq_server_get_type_addr()
- move IOREQ_STATUS_* #define-s introduction to the separate patch
- move HANDLE_BUFIOREQ to the arch header
- just return relocate_portio_handler() from arch_ioreq_server_destroy_all()
- misc adjustments proposed by Jan (adding const, unsigned int instead of uint32_t)

Changes V3 -> V4:
- add Alex's R-b
- update patch description
- make arch_ioreq_server_get_type_addr return bool
- drop #include <xen/ctype.h>
- use two arch hooks in hvm_map_mem_type_to_ioreq_server() to avoid calling p2m_change_entry_type_global() with lock held

---
 xen/arch/x86/hvm/ioreq.c        | 179 ++++++++++++++++++++++++++--------------
 xen/include/asm-x86/hvm/ioreq.h |  22 +++++
 2 files changed, 141 insertions(+), 60 deletions(-)
xen/arch/x86/hvm/ioreq.c +119 -60
index 1cc27df..468fe84 100644
@@ -16,16 +16,15 @@
  * this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <xen/ctype.h>
+#include <xen/domain.h>
+#include <xen/event.h>
 #include <xen/init.h>
+#include <xen/irq.h>
 #include <xen/lib.h>
-#include <xen/trace.h>
+#include <xen/paging.h>
 #include <xen/sched.h>
-#include <xen/irq.h>
 #include <xen/softirq.h>
-#include <xen/domain.h>
-#include <xen/event.h>
-#include <xen/paging.h>
+#include <xen/trace.h>
 #include <xen/vpci.h>
 
 #include <asm/hvm/emulate.h>
@@ -170,6 +169,29 @@ static bool hvm_wait_for_io(struct hvm_ioreq_vcpu *sv, ioreq_t *p)
     return true;
 }
 
+bool arch_vcpu_ioreq_completion(enum hvm_io_completion io_completion)
+{
+    switch ( io_completion )
+    {
+    case HVMIO_realmode_completion:
+    {
+        struct hvm_emulate_ctxt ctxt;
+
+        hvm_emulate_init_once(&ctxt, NULL, guest_cpu_user_regs());
+        vmx_realmode_emulate_one(&ctxt);
+        hvm_emulate_writeback(&ctxt);
+
+        break;
+    }
+
+    default:
+        ASSERT_UNREACHABLE();
+        break;
+    }
+
+    return true;
+}
+
 bool handle_hvm_io_completion(struct vcpu *v)
 {
     struct domain *d = v->domain;
@@ -209,19 +231,8 @@ bool handle_hvm_io_completion(struct vcpu *v)
         return handle_pio(vio->io_req.addr, vio->io_req.size,
                           vio->io_req.dir);
 
-    case HVMIO_realmode_completion:
-    {
-        struct hvm_emulate_ctxt ctxt;
-
-        hvm_emulate_init_once(&ctxt, NULL, guest_cpu_user_regs());
-        vmx_realmode_emulate_one(&ctxt);
-        hvm_emulate_writeback(&ctxt);
-
-        break;
-    }
     default:
-        ASSERT_UNREACHABLE();
-        break;
+        return arch_vcpu_ioreq_completion(io_completion);
     }
 
     return true;
@@ -477,9 +488,6 @@ static void hvm_update_ioreq_evtchn(struct hvm_ioreq_server *s,
     }
 }
 
-#define HANDLE_BUFIOREQ(s) \
-    ((s)->bufioreq_handling != HVM_IOREQSRV_BUFIOREQ_OFF)
-
 static int hvm_ioreq_server_add_vcpu(struct hvm_ioreq_server *s,
                                      struct vcpu *v)
 {
@@ -586,7 +594,7 @@ static void hvm_ioreq_server_remove_all_vcpus(struct hvm_ioreq_server *s)
     spin_unlock(&s->lock);
 }
 
-static int hvm_ioreq_server_map_pages(struct hvm_ioreq_server *s)
+int arch_ioreq_server_map_pages(struct hvm_ioreq_server *s)
 {
     int rc;
 
@@ -601,7 +609,7 @@ static int hvm_ioreq_server_map_pages(struct hvm_ioreq_server *s)
     return rc;
 }
 
-static void hvm_ioreq_server_unmap_pages(struct hvm_ioreq_server *s)
+void arch_ioreq_server_unmap_pages(struct hvm_ioreq_server *s)
 {
     hvm_unmap_ioreq_gfn(s, true);
     hvm_unmap_ioreq_gfn(s, false);
@@ -674,6 +682,12 @@ static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server *s,
     return rc;
 }
 
+void arch_ioreq_server_enable(struct hvm_ioreq_server *s)
+{
+    hvm_remove_ioreq_gfn(s, false);
+    hvm_remove_ioreq_gfn(s, true);
+}
+
 static void hvm_ioreq_server_enable(struct hvm_ioreq_server *s)
 {
     struct hvm_ioreq_vcpu *sv;
@@ -683,8 +697,7 @@ static void hvm_ioreq_server_enable(struct hvm_ioreq_server *s)
     if ( s->enabled )
         goto done;
 
-    hvm_remove_ioreq_gfn(s, false);
-    hvm_remove_ioreq_gfn(s, true);
+    arch_ioreq_server_enable(s);
 
     s->enabled = true;
 
@@ -697,6 +710,12 @@ static void hvm_ioreq_server_enable(struct hvm_ioreq_server *s)
     spin_unlock(&s->lock);
 }
 
+void arch_ioreq_server_disable(struct hvm_ioreq_server *s)
+{
+    hvm_add_ioreq_gfn(s, true);
+    hvm_add_ioreq_gfn(s, false);
+}
+
 static void hvm_ioreq_server_disable(struct hvm_ioreq_server *s)
 {
     spin_lock(&s->lock);
@@ -704,8 +723,7 @@ static void hvm_ioreq_server_disable(struct hvm_ioreq_server *s)
     if ( !s->enabled )
         goto done;
 
-    hvm_add_ioreq_gfn(s, true);
-    hvm_add_ioreq_gfn(s, false);
+    arch_ioreq_server_disable(s);
 
     s->enabled = false;
 
@@ -750,7 +768,7 @@ static int hvm_ioreq_server_init(struct hvm_ioreq_server *s,
 
  fail_add:
     hvm_ioreq_server_remove_all_vcpus(s);
-    hvm_ioreq_server_unmap_pages(s);
+    arch_ioreq_server_unmap_pages(s);
 
     hvm_ioreq_server_free_rangesets(s);
 
@@ -764,7 +782,7 @@ static void hvm_ioreq_server_deinit(struct hvm_ioreq_server *s)
     hvm_ioreq_server_remove_all_vcpus(s);
 
     /*
-     * NOTE: It is safe to call both hvm_ioreq_server_unmap_pages() and
+     * NOTE: It is safe to call both arch_ioreq_server_unmap_pages() and
      *       hvm_ioreq_server_free_pages() in that order.
      *       This is because the former will do nothing if the pages
      *       are not mapped, leaving the page to be freed by the latter.
@@ -772,7 +790,7 @@ static void hvm_ioreq_server_deinit(struct hvm_ioreq_server *s)
      *       the page_info pointer to NULL, meaning the latter will do
      *       nothing.
      */
-    hvm_ioreq_server_unmap_pages(s);
+    arch_ioreq_server_unmap_pages(s);
     hvm_ioreq_server_free_pages(s);
 
     hvm_ioreq_server_free_rangesets(s);
@@ -836,6 +854,12 @@ int hvm_create_ioreq_server(struct domain *d, int bufioreq_handling,
     return rc;
 }
 
+/* Called when target domain is paused */
+void arch_ioreq_server_destroy(struct hvm_ioreq_server *s)
+{
+    p2m_set_ioreq_server(s->target, 0, s);
+}
+
 int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id)
 {
     struct hvm_ioreq_server *s;
@@ -855,7 +879,7 @@ int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id)
 
     domain_pause(d);
 
-    p2m_set_ioreq_server(d, 0, s);
+    arch_ioreq_server_destroy(s);
 
     hvm_ioreq_server_disable(s);
 
@@ -900,7 +924,7 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,
 
     if ( ioreq_gfn || bufioreq_gfn )
     {
-        rc = hvm_ioreq_server_map_pages(s);
+        rc = arch_ioreq_server_map_pages(s);
         if ( rc )
             goto out;
     }
@@ -1080,6 +1104,27 @@ int hvm_unmap_io_range_from_ioreq_server(struct domain *d, ioservid_t id,
     return rc;
 }
 
+/* Called with ioreq_server lock held */
+int arch_ioreq_server_map_mem_type(struct domain *d,
+                                   struct hvm_ioreq_server *s,
+                                   uint32_t flags)
+{
+    return p2m_set_ioreq_server(d, flags, s);
+}
+
+void arch_ioreq_server_map_mem_type_completed(struct domain *d,
+                                              struct hvm_ioreq_server *s,
+                                              uint32_t flags)
+{
+    if ( flags == 0 )
+    {
+        const struct p2m_domain *p2m = p2m_get_hostp2m(d);
+
+        if ( read_atomic(&p2m->ioreq.entry_count) )
+            p2m_change_entry_type_global(d, p2m_ioreq_server, p2m_ram_rw);
+    }
+}
+
 /*
  * Map or unmap an ioreq server to specific memory type. For now, only
  * HVMMEM_ioreq_server is supported, and in the future new types can be
@@ -1112,18 +1157,13 @@ int hvm_map_mem_type_to_ioreq_server(struct domain *d, ioservid_t id,
     if ( s->emulator != current->domain )
         goto out;
 
-    rc = p2m_set_ioreq_server(d, flags, s);
+    rc = arch_ioreq_server_map_mem_type(d, s, flags);
 
  out:
     spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
 
-    if ( rc == 0 && flags == 0 )
-    {
-        struct p2m_domain *p2m = p2m_get_hostp2m(d);
-
-        if ( read_atomic(&p2m->ioreq.entry_count) )
-            p2m_change_entry_type_global(d, p2m_ioreq_server, p2m_ram_rw);
-    }
+    if ( rc == 0 )
+        arch_ioreq_server_map_mem_type_completed(d, s, flags);
 
     return rc;
 }
@@ -1210,12 +1250,17 @@ void hvm_all_ioreq_servers_remove_vcpu(struct domain *d, struct vcpu *v)
     spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
 }
 
+bool arch_ioreq_server_destroy_all(struct domain *d)
+{
+    return relocate_portio_handler(d, 0xcf8, 0xcf8, 4);
+}
+
 void hvm_destroy_all_ioreq_servers(struct domain *d)
 {
     struct hvm_ioreq_server *s;
     unsigned int id;
 
-    if ( !relocate_portio_handler(d, 0xcf8, 0xcf8, 4) )
+    if ( !arch_ioreq_server_destroy_all(d) )
         return;
 
     spin_lock_recursive(&d->arch.hvm.ioreq_server.lock);
@@ -1239,33 +1284,28 @@ void hvm_destroy_all_ioreq_servers(struct domain *d)
     spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
 }
 
-struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,
-                                                 ioreq_t *p)
+bool arch_ioreq_server_get_type_addr(const struct domain *d,
+                                     const ioreq_t *p,
+                                     uint8_t *type,
+                                     uint64_t *addr)
 {
-    struct hvm_ioreq_server *s;
-    uint32_t cf8;
-    uint8_t type;
-    uint64_t addr;
-    unsigned int id;
+    unsigned int cf8 = d->arch.hvm.pci_cf8;
 
     if ( p->type != IOREQ_TYPE_COPY && p->type != IOREQ_TYPE_PIO )
-        return NULL;
-
-    cf8 = d->arch.hvm.pci_cf8;
+        return false;
 
     if ( p->type == IOREQ_TYPE_PIO &&
          (p->addr & ~3) == 0xcfc &&
          CF8_ENABLED(cf8) )
     {
-        uint32_t x86_fam;
+        unsigned int x86_fam, reg;
         pci_sbdf_t sbdf;
-        unsigned int reg;
 
         reg = hvm_pci_decode_addr(cf8, p->addr, &sbdf);
 
         /* PCI config data cycle */
-        type = XEN_DMOP_IO_RANGE_PCI;
-        addr = ((uint64_t)sbdf.sbdf << 32) | reg;
+        *type = XEN_DMOP_IO_RANGE_PCI;
+        *addr = ((uint64_t)sbdf.sbdf << 32) | reg;
         /* AMD extended configuration space access? */
         if ( CF8_ADDR_HI(cf8) &&
              d->arch.cpuid->x86_vendor == X86_VENDOR_AMD &&
@@ -1277,16 +1317,30 @@ struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,
 
             if ( !rdmsr_safe(MSR_AMD64_NB_CFG, msr_val) &&
                  (msr_val & (1ULL << AMD64_NB_CFG_CF8_EXT_ENABLE_BIT)) )
-                addr |= CF8_ADDR_HI(cf8);
+                *addr |= CF8_ADDR_HI(cf8);
         }
     }
     else
     {
-        type = (p->type == IOREQ_TYPE_PIO) ?
-                XEN_DMOP_IO_RANGE_PORT : XEN_DMOP_IO_RANGE_MEMORY;
-        addr = p->addr;
+        *type = (p->type == IOREQ_TYPE_PIO) ?
+                 XEN_DMOP_IO_RANGE_PORT : XEN_DMOP_IO_RANGE_MEMORY;
+        *addr = p->addr;
     }
 
+    return true;
+}
+
+struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,
+                                                 ioreq_t *p)
+{
+    struct hvm_ioreq_server *s;
+    uint8_t type;
+    uint64_t addr;
+    unsigned int id;
+
+    if ( !arch_ioreq_server_get_type_addr(d, p, &type, &addr) )
+        return NULL;
+
     FOR_EACH_IOREQ_SERVER(d, id, s)
     {
         struct rangeset *r;
@@ -1515,11 +1569,16 @@ static int hvm_access_cf8(
     return X86EMUL_UNHANDLEABLE;
 }
 
+void arch_ioreq_domain_init(struct domain *d)
+{
+    register_portio_handler(d, 0xcf8, 4, hvm_access_cf8);
+}
+
 void hvm_ioreq_init(struct domain *d)
 {
     spin_lock_init(&d->arch.hvm.ioreq_server.lock);
 
-    register_portio_handler(d, 0xcf8, 4, hvm_access_cf8);
+    arch_ioreq_domain_init(d);
 }
 
 /*
xen/include/asm-x86/hvm/ioreq.h +22 -1
index e2588e9..13d35e1 100644
@@ -19,6 +19,9 @@
 #ifndef __ASM_X86_HVM_IOREQ_H__
 #define __ASM_X86_HVM_IOREQ_H__
 
+#define HANDLE_BUFIOREQ(s) \
+    ((s)->bufioreq_handling != HVM_IOREQSRV_BUFIOREQ_OFF)
+
 bool hvm_io_pending(struct vcpu *v);
 bool handle_hvm_io_completion(struct vcpu *v);
 bool is_ioreq_server_page(struct domain *d, const struct page_info *page);
@@ -55,6 +58,25 @@ unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered);
 
 void hvm_ioreq_init(struct domain *d);
 
+bool arch_vcpu_ioreq_completion(enum hvm_io_completion io_completion);
+int arch_ioreq_server_map_pages(struct hvm_ioreq_server *s);
+void arch_ioreq_server_unmap_pages(struct hvm_ioreq_server *s);
+void arch_ioreq_server_enable(struct hvm_ioreq_server *s);
+void arch_ioreq_server_disable(struct hvm_ioreq_server *s);
+void arch_ioreq_server_destroy(struct hvm_ioreq_server *s);
+int arch_ioreq_server_map_mem_type(struct domain *d,
+                                   struct hvm_ioreq_server *s,
+                                   uint32_t flags);
+void arch_ioreq_server_map_mem_type_completed(struct domain *d,
+                                              struct hvm_ioreq_server *s,
+                                              uint32_t flags);
+bool arch_ioreq_server_destroy_all(struct domain *d);
+bool arch_ioreq_server_get_type_addr(const struct domain *d,
+                                     const ioreq_t *p,
+                                     uint8_t *type,
+                                     uint64_t *addr);
+void arch_ioreq_domain_init(struct domain *d);
+
 #endif /* __ASM_X86_HVM_IOREQ_H__ */
 
 /*
--

2.7.4

#24 lore raw

PATCH v4 2/24 x86/ioreq: Add IOREQ_STATUS_* #define-s and update code for moving

In reply to Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

This patch continues to make some preparation to x86/hvm/ioreq.c before moving to the common code.

Add IOREQ_STATUS_* #define-s and update candidates for moving since X86EMUL_* shouldn't be exposed to the common code in that form.

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes V2 -> V3:
- new patch, was split from
[PATCH V2 01/23] x86/ioreq: Prepare IOREQ feature for making it common

Changes V3 -> V4:
- add Alex's R-b and Jan's A-b
- add a comment above IOREQ_STATUS_* #define-s

---
 xen/arch/x86/hvm/ioreq.c        | 16 ++++++++--------
 xen/include/asm-x86/hvm/ioreq.h |  5 +++++
 2 files changed, 13 insertions(+), 8 deletions(-)
xen/arch/x86/hvm/ioreq.c +8 -8
index 468fe84..ff9a546 100644
@@ -1405,7 +1405,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p)
     pg = iorp->va;
 
     if ( !pg )
-        return X86EMUL_UNHANDLEABLE;
+        return IOREQ_STATUS_UNHANDLED;
 
     /*
      * Return 0 for the cases we can't deal with:
@@ -1435,7 +1435,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p)
         break;
     default:
         gdprintk(XENLOG_WARNING, "unexpected ioreq size: %u\n", p->size);
-        return X86EMUL_UNHANDLEABLE;
+        return IOREQ_STATUS_UNHANDLED;
     }
 
     spin_lock(&s->bufioreq_lock);
@@ -1445,7 +1445,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p)
     {
         /* The queue is full: send the iopacket through the normal path. */
         spin_unlock(&s->bufioreq_lock);
-        return X86EMUL_UNHANDLEABLE;
+        return IOREQ_STATUS_UNHANDLED;
     }
 
     pg->buf_ioreq[pg->ptrs.write_pointer % IOREQ_BUFFER_SLOT_NUM] = bp;
@@ -1476,7 +1476,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p)
     notify_via_xen_event_channel(d, s->bufioreq_evtchn);
     spin_unlock(&s->bufioreq_lock);
 
-    return X86EMUL_OKAY;
+    return IOREQ_STATUS_HANDLED;
 }
 
 int hvm_send_ioreq(struct hvm_ioreq_server *s, ioreq_t *proto_p,
@@ -1492,7 +1492,7 @@ int hvm_send_ioreq(struct hvm_ioreq_server *s, ioreq_t *proto_p,
         return hvm_send_buffered_ioreq(s, proto_p);
 
     if ( unlikely(!vcpu_start_shutdown_deferral(curr)) )
-        return X86EMUL_RETRY;
+        return IOREQ_STATUS_RETRY;
 
     list_for_each_entry ( sv,
                           &s->ioreq_vcpu_list,
@@ -1532,11 +1532,11 @@ int hvm_send_ioreq(struct hvm_ioreq_server *s, ioreq_t *proto_p,
             notify_via_xen_event_channel(d, port);
 
             sv->pending = true;
-            return X86EMUL_RETRY;
+            return IOREQ_STATUS_RETRY;
         }
     }
 
-    return X86EMUL_UNHANDLEABLE;
+    return IOREQ_STATUS_UNHANDLED;
 }
 
 unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered)
@@ -1550,7 +1550,7 @@ unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered)
         if ( !s->enabled )
             continue;
 
-        if ( hvm_send_ioreq(s, p, buffered) == X86EMUL_UNHANDLEABLE )
+        if ( hvm_send_ioreq(s, p, buffered) == IOREQ_STATUS_UNHANDLED )
             failed++;
     }
 
xen/include/asm-x86/hvm/ioreq.h +5 -0
index 13d35e1..f140ef4 100644
@@ -77,6 +77,11 @@ bool arch_ioreq_server_get_type_addr(const struct domain *d,
                                      uint64_t *addr);
 void arch_ioreq_domain_init(struct domain *d);
 
+/* This correlation must not be altered */
+#define IOREQ_STATUS_HANDLED     X86EMUL_OKAY
+#define IOREQ_STATUS_UNHANDLED   X86EMUL_UNHANDLEABLE
+#define IOREQ_STATUS_RETRY       X86EMUL_RETRY
+
 #endif /* __ASM_X86_HVM_IOREQ_H__ */
 
 /*
Signature · 1 line
2.7.4
Reviewed-by on v4 2/24
#25 lore raw

Re: [PATCH V4 02/24] x86/ioreq: Add IOREQ_STATUS_* #define-s and update code for moving

Hi Oleksandr,

Quoted 9 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

This patch continues to make some preparation to x86/hvm/ioreq.c before moving to the common code.

Add IOREQ_STATUS_* #define-s and update candidates for moving since X86EMUL_* shouldn't be exposed to the common code in that form.

Quoted 6 lines

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

Cheers,

Signature · 1 line
Julien Grall
Reviewed-by on v4 2/24
#26 lore raw

RE: [PATCH V4 02/24] x86/ioreq: Add IOREQ_STATUS_* #define-s and update code for moving

In reply to Oleksandr Tyshchenko
Quoted 15 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Oleksandr Tyshchenko
Sent: 12 January 2021 21:52
To: [email protected]
Cc: Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH V4 02/24] x86/ioreq: Add IOREQ_STATUS_* #define-s and update code for moving

From: Oleksandr Tyshchenko <[email protected]>

This patch continues to make some preparation to x86/hvm/ioreq.c before moving to the common code.

Quoted 8 lines

Add IOREQ_STATUS_* #define-s and update candidates for moving since X86EMUL_* shouldn't be exposed to the common code in that form.

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

Quoted 113 lines

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes V2 -> V3:
- new patch, was split from
[PATCH V2 01/23] x86/ioreq: Prepare IOREQ feature for making it common

Changes V3 -> V4:
- add Alex's R-b and Jan's A-b
- add a comment above IOREQ_STATUS_* #define-s

---
 xen/arch/x86/hvm/ioreq.c        | 16 ++++++++--------
 xen/include/asm-x86/hvm/ioreq.h |  5 +++++
 2 files changed, 13 insertions(+), 8 deletions(-)
xen/arch/x86/hvm/ioreq.c +8 -8
index 468fe84..ff9a546 100644
@@ -1405,7 +1405,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p)
     pg = iorp->va;
 
     if ( !pg )
-        return X86EMUL_UNHANDLEABLE;
+        return IOREQ_STATUS_UNHANDLED;
 
     /*
      * Return 0 for the cases we can't deal with:
@@ -1435,7 +1435,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p)
         break;
     default:
         gdprintk(XENLOG_WARNING, "unexpected ioreq size: %u\n", p->size);
-        return X86EMUL_UNHANDLEABLE;
+        return IOREQ_STATUS_UNHANDLED;
     }
 
     spin_lock(&s->bufioreq_lock);
@@ -1445,7 +1445,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p)
     {
         /* The queue is full: send the iopacket through the normal path. */
         spin_unlock(&s->bufioreq_lock);
-        return X86EMUL_UNHANDLEABLE;
+        return IOREQ_STATUS_UNHANDLED;
     }
 
     pg->buf_ioreq[pg->ptrs.write_pointer % IOREQ_BUFFER_SLOT_NUM] = bp;
@@ -1476,7 +1476,7 @@ static int hvm_send_buffered_ioreq(struct hvm_ioreq_server *s, ioreq_t *p)
     notify_via_xen_event_channel(d, s->bufioreq_evtchn);
     spin_unlock(&s->bufioreq_lock);
 
-    return X86EMUL_OKAY;
+    return IOREQ_STATUS_HANDLED;
 }
 
 int hvm_send_ioreq(struct hvm_ioreq_server *s, ioreq_t *proto_p,
@@ -1492,7 +1492,7 @@ int hvm_send_ioreq(struct hvm_ioreq_server *s, ioreq_t *proto_p,
         return hvm_send_buffered_ioreq(s, proto_p);
 
     if ( unlikely(!vcpu_start_shutdown_deferral(curr)) )
-        return X86EMUL_RETRY;
+        return IOREQ_STATUS_RETRY;
 
     list_for_each_entry ( sv,
                           &s->ioreq_vcpu_list,
@@ -1532,11 +1532,11 @@ int hvm_send_ioreq(struct hvm_ioreq_server *s, ioreq_t *proto_p,
             notify_via_xen_event_channel(d, port);
 
             sv->pending = true;
-            return X86EMUL_RETRY;
+            return IOREQ_STATUS_RETRY;
         }
     }
 
-    return X86EMUL_UNHANDLEABLE;
+    return IOREQ_STATUS_UNHANDLED;
 }
 
 unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered)
@@ -1550,7 +1550,7 @@ unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered)
         if ( !s->enabled )
             continue;
 
-        if ( hvm_send_ioreq(s, p, buffered) == X86EMUL_UNHANDLEABLE )
+        if ( hvm_send_ioreq(s, p, buffered) == IOREQ_STATUS_UNHANDLED )
             failed++;
     }
 
xen/include/asm-x86/hvm/ioreq.h +5 -1
index 13d35e1..f140ef4 100644
@@ -77,6 +77,11 @@ bool arch_ioreq_server_get_type_addr(const struct domain *d,
                                      uint64_t *addr);
 void arch_ioreq_domain_init(struct domain *d);
 
+/* This correlation must not be altered */
+#define IOREQ_STATUS_HANDLED     X86EMUL_OKAY
+#define IOREQ_STATUS_UNHANDLED   X86EMUL_UNHANDLEABLE
+#define IOREQ_STATUS_RETRY       X86EMUL_RETRY
+
 #endif /* __ASM_X86_HVM_IOREQ_H__ */
 
 /*
--

2.7.4

#27 lore raw

PATCH v4 3/24 x86/ioreq: Provide out-of-line wrapper for the handle_mmio()

In reply to Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is about to be common feature and Arm will have its own implementation.

But the name of the function is pretty generic and can be confusing on Arm (we already have a try_handle_mmio()).

In order not to rename the function (which is used for a varying set of purposes on x86) globally and get non-confusing variant on Arm provide a wrapper arch_ioreq_complete_mmio() to be used on common and Arm code.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- new patch

Changes V1 -> V2:
- remove "handle"
- add Jan's A-b

Changes V2 -> V3:
- remove Jan's A-b
- update patch subject/description
- use out-of-line function instead of #define
- put earlier in the series to avoid breakage

Changes V3 -> V4:
- add Jan's R-b
- rename ioreq_complete_mmio() to arch_ioreq_complete_mmio()

---
 xen/arch/x86/hvm/ioreq.c        | 7 ++++++-
 xen/include/asm-x86/hvm/ioreq.h | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/ioreq.c +6 -1
index ff9a546..00c68f5 100644
@@ -35,6 +35,11 @@
 #include <public/hvm/ioreq.h>
 #include <public/hvm/params.h>
 
+bool arch_ioreq_complete_mmio(void)
+{
+    return handle_mmio();
+}
+
 static void set_ioreq_server(struct domain *d, unsigned int id,
                              struct hvm_ioreq_server *s)
 {
@@ -225,7 +230,7 @@ bool handle_hvm_io_completion(struct vcpu *v)
         break;
 
     case HVMIO_mmio_completion:
-        return handle_mmio();
+        return arch_ioreq_complete_mmio();
 
     case HVMIO_pio_completion:
         return handle_pio(vio->io_req.addr, vio->io_req.size,
xen/include/asm-x86/hvm/ioreq.h +1 -0
index f140ef4..0e64e76 100644
@@ -58,6 +58,7 @@ unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered);
 
 void hvm_ioreq_init(struct domain *d);
 
+bool arch_ioreq_complete_mmio(void);
 bool arch_vcpu_ioreq_completion(enum hvm_io_completion io_completion);
 int arch_ioreq_server_map_pages(struct hvm_ioreq_server *s);
 void arch_ioreq_server_unmap_pages(struct hvm_ioreq_server *s);
Signature · 1 line
2.7.4
Reviewed-by on v4 3/24
#28 lore raw

Re: [PATCH V4 03/24] x86/ioreq: Provide out-of-line wrapper for the handle_mmio()

Quoted 13 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is about to be common feature and Arm will have its own implementation.

But the name of the function is pretty generic and can be confusing on Arm (we already have a try_handle_mmio()).

In order not to rename the function (which is used for a varying set of purposes on x86) globally and get non-confusing variant on Arm provide a wrapper arch_ioreq_complete_mmio() to be used on common and Arm code.

Quoted 5 lines
Signature · 1 line
Alex Bennée
Reviewed-by on v4 3/24
#29 lore raw

Re: [PATCH V4 03/24] x86/ioreq: Provide out-of-line wrapper for the handle_mmio()

In reply to Oleksandr Tyshchenko

Hi Oleksandr,

Quoted 13 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is about to be common feature and Arm will have its own implementation.

But the name of the function is pretty generic and can be confusing on Arm (we already have a try_handle_mmio()).

In order not to rename the function (which is used for a varying set of purposes on x86) globally and get non-confusing variant on Arm provide a wrapper arch_ioreq_complete_mmio() to be used on common and Arm code.

Quoted 5 lines

Cheers,

Signature · 1 line
Julien Grall
Reviewed-by on v4 3/24
#30 lore raw

RE: [PATCH V4 03/24] x86/ioreq: Provide out-of-line wrapper for the handle_mmio()

In reply to Oleksandr Tyshchenko
Quoted 18 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Oleksandr Tyshchenko
Sent: 12 January 2021 21:52
To: [email protected]
Cc: Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH V4 03/24] x86/ioreq: Provide out-of-line wrapper for the handle_mmio()

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is about to be common feature and Arm will have its own implementation.

But the name of the function is pretty generic and can be confusing on Arm (we already have a try_handle_mmio()).

Quoted 6 lines

In order not to rename the function (which is used for a varying set of purposes on x86) globally and get non-confusing variant on Arm provide a wrapper arch_ioreq_complete_mmio() to be used on common and Arm code.

Quoted 70 lines
CC Julien Grall <[email protected]>
[On Arm only]

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- new patch

Changes V1 -> V2:
- remove "handle"
- add Jan's A-b

Changes V2 -> V3:
- remove Jan's A-b
- update patch subject/description
- use out-of-line function instead of #define
- put earlier in the series to avoid breakage

Changes V3 -> V4:
- add Jan's R-b
- rename ioreq_complete_mmio() to arch_ioreq_complete_mmio()

---
 xen/arch/x86/hvm/ioreq.c        | 7 ++++++-
 xen/include/asm-x86/hvm/ioreq.h | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/ioreq.c +6 -1
index ff9a546..00c68f5 100644
@@ -35,6 +35,11 @@
 #include <public/hvm/ioreq.h>
 #include <public/hvm/params.h>
 
+bool arch_ioreq_complete_mmio(void)
+{
+    return handle_mmio();
+}
+
 static void set_ioreq_server(struct domain *d, unsigned int id,
                              struct hvm_ioreq_server *s)
 {
@@ -225,7 +230,7 @@ bool handle_hvm_io_completion(struct vcpu *v)
         break;
 
     case HVMIO_mmio_completion:
-        return handle_mmio();
+        return arch_ioreq_complete_mmio();
 
     case HVMIO_pio_completion:
         return handle_pio(vio->io_req.addr, vio->io_req.size,
xen/include/asm-x86/hvm/ioreq.h +1 -1
index f140ef4..0e64e76 100644
@@ -58,6 +58,7 @@ unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered);
 
 void hvm_ioreq_init(struct domain *d);
 
+bool arch_ioreq_complete_mmio(void);
 bool arch_vcpu_ioreq_completion(enum hvm_io_completion io_completion);
 int arch_ioreq_server_map_pages(struct hvm_ioreq_server *s);
 void arch_ioreq_server_unmap_pages(struct hvm_ioreq_server *s);
--

2.7.4

#31 lore raw

PATCH v4 4/24 xen/ioreq: Make x86's IOREQ feature common

In reply to Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

As a lot of x86 code can be re-used on Arm later on, this patch moves previously prepared IOREQ support to the common code (the code movement is verbatim copy).

The "legacy" mechanism of mapping magic pages for the IOREQ servers remains x86 specific and not exposed to the common code.

The common IOREQ feature is supposed to be built with IOREQ_SERVER option enabled, which is selected for x86's config HVM for now.

In order to avoid having a gigantic patch here, the subsequent patches will update remaining bits in the common code step by step:
- Make IOREQ related structs/materials common
- Drop the "hvm" prefixes and infixes
- Remove layering violation by moving corresponding fields out of *arch.hvm* or abstracting away accesses to them

Also include <xen/domain_page.h> which will be needed on Arm to avoid touch the common code again when introducing Arm specific bits.

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

***
Please note, this patch depends on the following which is on review:
https://patchwork.kernel.org/patch/11816689/
***

Changes RFC -> V1:
- was split into three patches:
- x86/ioreq: Prepare IOREQ feature for making it common
- xen/ioreq: Make x86's IOREQ feature common
- xen/ioreq: Make x86's hvm_ioreq_needs_completion() common
- update MAINTAINERS file
- do not use a separate subdir for the IOREQ stuff, move it to:
- xen/common/ioreq.c
- xen/include/xen/ioreq.h
- update x86's files to include xen/ioreq.h
- remove unneeded headers in arch/x86/hvm/ioreq.c
- re-order the headers alphabetically in common/ioreq.c
- update common/ioreq.c according to the newly introduced arch functions:
arch_hvm_destroy_ioreq_server()/arch_handle_hvm_io_completion()

Changes V1 -> V2:
- update patch description
- make everything needed in the previous patch to achieve a truly rename here
- don't include unnecessary headers from asm-x86/hvm/ioreq.h and xen/ioreq.h
- use __XEN_IOREQ_H__ instead of __IOREQ_H__
- move get_ioreq_server() to common/ioreq.c

Changes V2 -> V3:
- update patch description
- make everything needed in the previous patch to not expose "legacy" interface to the common code here
- update patch according the "legacy interface" is x86 specific
- include <xen/domain_page.h> in common ioreq.c

Changes V3 -> V4:
- rebase
- don't include <xen/ioreq.h> from arch header
- мove all arch hook declarations to the common header

---
 MAINTAINERS                     |    8 +-
 xen/arch/x86/Kconfig            |    1 +
 xen/arch/x86/hvm/dm.c           |    2 +-
 xen/arch/x86/hvm/emulate.c      |    2 +-
 xen/arch/x86/hvm/hvm.c          |    2 +-
 xen/arch/x86/hvm/io.c           |    2 +-
 xen/arch/x86/hvm/ioreq.c        | 1347 ++-------------------------------------
 xen/arch/x86/hvm/stdvga.c       |    2 +-
 xen/arch/x86/hvm/vmx/vvmx.c     |    3 +-
 xen/arch/x86/mm.c               |    2 +-
 xen/arch/x86/mm/shadow/common.c |    2 +-
 xen/common/Kconfig              |    3 +
 xen/common/Makefile             |    1 +
 xen/common/ioreq.c              | 1290 +++++++++++++++++++++++++++++++++++++
 xen/include/asm-x86/hvm/ioreq.h |   59 --
 xen/include/xen/ioreq.h         |   93 +++
 16 files changed, 1455 insertions(+), 1364 deletions(-)
 create mode 100644 xen/common/ioreq.c
 create mode 100644 xen/include/xen/ioreq.h
MAINTAINERS +7 -1
index 6dbd99a..0160cab 100644
@@ -333,6 +333,13 @@ X:	xen/drivers/passthrough/vtd/
 X:	xen/drivers/passthrough/device_tree.c
 F:	xen/include/xen/iommu.h
 
+I/O EMULATION (IOREQ)
+M:	Paul Durrant <[email protected]>
+S:	Supported
+F:	xen/common/ioreq.c
+F:	xen/include/xen/ioreq.h
+F:	xen/include/public/hvm/ioreq.h
+
 KCONFIG
 M:	Doug Goldstein <[email protected]>
 S:	Supported
@@ -549,7 +556,6 @@ F:	xen/arch/x86/hvm/ioreq.c
 F:	xen/include/asm-x86/hvm/emulate.h
 F:	xen/include/asm-x86/hvm/io.h
 F:	xen/include/asm-x86/hvm/ioreq.h
-F:	xen/include/public/hvm/ioreq.h
 
 X86 MEMORY MANAGEMENT
 M:	Jan Beulich <[email protected]>
xen/arch/x86/Kconfig +1 -0
index 24868aa..abe0fce 100644
@@ -91,6 +91,7 @@ config PV_LINEAR_PT
 
 config HVM
 	def_bool !PV_SHIM_EXCLUSIVE
+	select IOREQ_SERVER
 	prompt "HVM support"
 	---help---
 	  Interfaces to support HVM domains.  HVM domains require hardware
xen/arch/x86/hvm/dm.c +1 -1
index 71f5ca4..d3e2a9e 100644
@@ -17,12 +17,12 @@
 #include <xen/event.h>
 #include <xen/guest_access.h>
 #include <xen/hypercall.h>
+#include <xen/ioreq.h>
 #include <xen/nospec.h>
 #include <xen/sched.h>
 
 #include <asm/hap.h>
 #include <asm/hvm/cacheattr.h>
-#include <asm/hvm/ioreq.h>
 #include <asm/shadow.h>
 
 #include <xsm/xsm.h>
xen/arch/x86/hvm/emulate.c +1 -1
index 24cf85f..60ca465 100644
@@ -10,6 +10,7 @@
  */
 
 #include <xen/init.h>
+#include <xen/ioreq.h>
 #include <xen/lib.h>
 #include <xen/sched.h>
 #include <xen/paging.h>
@@ -20,7 +21,6 @@
 #include <asm/xstate.h>
 #include <asm/hvm/emulate.h>
 #include <asm/hvm/hvm.h>
-#include <asm/hvm/ioreq.h>
 #include <asm/hvm/monitor.h>
 #include <asm/hvm/trace.h>
 #include <asm/hvm/support.h>
xen/arch/x86/hvm/hvm.c +1 -1
index 54e32e4..bc96947 100644
@@ -20,6 +20,7 @@
 
 #include <xen/ctype.h>
 #include <xen/init.h>
+#include <xen/ioreq.h>
 #include <xen/lib.h>
 #include <xen/trace.h>
 #include <xen/sched.h>
@@ -64,7 +65,6 @@
 #include <asm/hvm/trace.h>
 #include <asm/hvm/nestedhvm.h>
 #include <asm/hvm/monitor.h>
-#include <asm/hvm/ioreq.h>
 #include <asm/hvm/viridian.h>
 #include <asm/hvm/vm_event.h>
 #include <asm/altp2m.h>
xen/arch/x86/hvm/io.c +1 -1
index 3e09d9b..11e007d 100644
@@ -19,6 +19,7 @@
  */
 
 #include <xen/init.h>
+#include <xen/ioreq.h>
 #include <xen/mm.h>
 #include <xen/lib.h>
 #include <xen/errno.h>
@@ -35,7 +36,6 @@
 #include <asm/shadow.h>
 #include <asm/p2m.h>
 #include <asm/hvm/hvm.h>
-#include <asm/hvm/ioreq.h>
 #include <asm/hvm/support.h>
 #include <asm/hvm/vpt.h>
 #include <asm/hvm/vpic.h>
xen/arch/x86/hvm/ioreq.c +51 -1296

1,425 lines not on this page · raw message

xen/arch/x86/hvm/stdvga.c +1 -1
index e267513..fd7cadb 100644
@@ -27,10 +27,10 @@
  *  can have side effects.
  */
 
+#include <xen/ioreq.h>
 #include <xen/types.h>
 #include <xen/sched.h>
 #include <xen/domain_page.h>
-#include <asm/hvm/ioreq.h>
 #include <asm/hvm/support.h>
 #include <xen/numa.h>
 #include <xen/paging.h>
xen/arch/x86/hvm/vmx/vvmx.c +2 -1
index 3a37e9e..0ddb6a4 100644
@@ -19,10 +19,11 @@
  *
  */
 
+#include <xen/ioreq.h>
+
 #include <asm/types.h>
 #include <asm/mtrr.h>
 #include <asm/p2m.h>
-#include <asm/hvm/ioreq.h>
 #include <asm/hvm/vmx/vmx.h>
 #include <asm/hvm/vmx/vvmx.h>
 #include <asm/hvm/nestedhvm.h>
xen/arch/x86/mm.c +1 -1
index 79acf20..f6e128e 100644
@@ -100,6 +100,7 @@
  */
 
 #include <xen/init.h>
+#include <xen/ioreq.h>
 #include <xen/kernel.h>
 #include <xen/lib.h>
 #include <xen/mm.h>
@@ -140,7 +141,6 @@
 #include <asm/io_apic.h>
 #include <asm/pci.h>
 #include <asm/guest.h>
-#include <asm/hvm/ioreq.h>
 #include <asm/pv/domain.h>
 #include <asm/pv/mm.h>
 
xen/arch/x86/mm/shadow/common.c +1 -1
index 3298711..5012a9c 100644
@@ -20,6 +20,7 @@
  * along with this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <xen/ioreq.h>
 #include <xen/types.h>
 #include <xen/mm.h>
 #include <xen/trace.h>
@@ -34,7 +35,6 @@
 #include <asm/current.h>
 #include <asm/flushtlb.h>
 #include <asm/shadow.h>
-#include <asm/hvm/ioreq.h>
 #include <xen/numa.h>
 #include "private.h"
 
xen/common/Kconfig +3 -0
index 0661328..fa049a6 100644
@@ -136,6 +136,9 @@ config HYPFS_CONFIG
 	  Disable this option in case you want to spare some memory or you
 	  want to hide the .config contents from dom0.
 
+config IOREQ_SERVER
+	bool
+
 config KEXEC
 	bool "kexec support"
 	default y
xen/common/Makefile +1 -0
index 7a4e652..b161381 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_GRANT_TABLE) += grant_table.o
 obj-y += guestcopy.o
 obj-bin-y += gunzip.init.o
 obj-$(CONFIG_HYPFS) += hypfs.o
+obj-$(CONFIG_IOREQ_SERVER) += ioreq.o
 obj-y += irq.o
 obj-y += kernel.o
 obj-y += keyhandler.o
xen/common/ioreq.c new file +1290 -0

1,290 lines not on this page · raw message

xen/include/asm-x86/hvm/ioreq.h +0 -59

65 lines not on this page · raw message

xen/include/xen/ioreq.h new file +93 -0

71 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.7.4

Part of the diff is not shown here. View the raw message.

#32 lore raw

Re: [PATCH V4 04/24] xen/ioreq: Make x86's IOREQ feature common

Quoted 34 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

As a lot of x86 code can be re-used on Arm later on, this patch moves previously prepared IOREQ support to the common code (the code movement is verbatim copy).

The "legacy" mechanism of mapping magic pages for the IOREQ servers remains x86 specific and not exposed to the common code.

The common IOREQ feature is supposed to be built with IOREQ_SERVER option enabled, which is selected for x86's config HVM for now.

In order to avoid having a gigantic patch here, the subsequent patches will update remaining bits in the common code step by step:
- Make IOREQ related structs/materials common
- Drop the "hvm" prefixes and infixes
- Remove layering violation by moving corresponding fields out of *arch.hvm* or abstracting away accesses to them

Also include <xen/domain_page.h> which will be needed on Arm to avoid touch the common code again when introducing Arm specific bits.

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Quoted 5 lines

***
Please note, this patch depends on the following which is on review:
https://patchwork.kernel.org/patch/11816689/
***

Just a note on process because I got tripped up again after applying the series to a clean branch.

I tend to just include any pre-requisite patches in my series just to make them easy to apply as a standalone series even if I'm expecting the master version of the patch to get merged before my series. It usually disappears on the next re-base ;-)

Signature · 1 line
Alex Bennée
#33 lore raw

Re: [PATCH V4 04/24] xen/ioreq: Make x86's IOREQ feature common

In reply to Oleksandr Tyshchenko

Hi Oleksandr,

Quoted 34 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

As a lot of x86 code can be re-used on Arm later on, this patch moves previously prepared IOREQ support to the common code (the code movement is verbatim copy).

The "legacy" mechanism of mapping magic pages for the IOREQ servers remains x86 specific and not exposed to the common code.

The common IOREQ feature is supposed to be built with IOREQ_SERVER option enabled, which is selected for x86's config HVM for now.

In order to avoid having a gigantic patch here, the subsequent patches will update remaining bits in the common code step by step:
- Make IOREQ related structs/materials common
- Drop the "hvm" prefixes and infixes
- Remove layering violation by moving corresponding fields out of *arch.hvm* or abstracting away accesses to them

Also include <xen/domain_page.h> which will be needed on Arm to avoid touch the common code again when introducing Arm specific bits.

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Quoted 5 lines

***
Please note, this patch depends on the following which is on review:
https://patchwork.kernel.org/patch/11816689/
***

The effort was paused because we found a security issue around that code (see XSA-348). @Paul do you plan to revive it for 4.15?

Cheers,

Signature · 1 line
Julien Grall
Reviewed-by on v4 4/24
#34 lore raw

RE: [PATCH V4 04/24] xen/ioreq: Make x86's IOREQ feature common

In reply to Oleksandr Tyshchenko
Quoted 31 lines

-----Original Message-----
From: Oleksandr Tyshchenko <[email protected]>
Sent: 12 January 2021 21:52
To: [email protected]
Cc: Oleksandr Tyshchenko <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Jan Beulich <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>; Paul Durrant <[email protected]>; Jun Nakajima <[email protected]>; Kevin Tian <[email protected]>; Tim Deegan <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH V4 04/24] xen/ioreq: Make x86's IOREQ feature common

From: Oleksandr Tyshchenko <[email protected]>

As a lot of x86 code can be re-used on Arm later on, this patch moves previously prepared IOREQ support to the common code (the code movement is verbatim copy).

The "legacy" mechanism of mapping magic pages for the IOREQ servers remains x86 specific and not exposed to the common code.

The common IOREQ feature is supposed to be built with IOREQ_SERVER option enabled, which is selected for x86's config HVM for now.

In order to avoid having a gigantic patch here, the subsequent patches will update remaining bits in the common code step by step:
- Make IOREQ related structs/materials common
- Drop the "hvm" prefixes and infixes
- Remove layering violation by moving corresponding fields out of *arch.hvm* or abstracting away accesses to them

Quoted 7 lines

Also include <xen/domain_page.h> which will be needed on Arm to avoid touch the common code again when introducing Arm specific bits.

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

#35 lore raw

PATCH v4 5/24 xen/ioreq: Make x86's hvm_ioreq_needs_completion() common

In reply to Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and this helper will be used on Arm as is. Move it to xen/ioreq.h and remove "hvm" prefix.

Although PIO handling on Arm is not introduced with the current series (it will be implemented when we add support for vPCI), technically the PIOs exist on Arm (however they are accessed the same way as MMIO) and it would be better not to diverge now.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- new patch, was split from:
"[RFC PATCH V1 01/12] hvm/ioreq: Make x86's IOREQ feature common"

Changes V1 -> V2:
- remove "hvm" prefix

Changes V2 -> V3:
- add Paul's R-b

Changes V3 -> V4:
- add Jan's A-b

---
 xen/arch/x86/hvm/emulate.c     | 4 ++--
 xen/arch/x86/hvm/io.c          | 2 +-
 xen/common/ioreq.c             | 4 ++--
 xen/include/asm-x86/hvm/vcpu.h | 7 -------
 xen/include/xen/ioreq.h        | 7 +++++++
 5 files changed, 12 insertions(+), 12 deletions(-)
xen/arch/x86/hvm/emulate.c +2 -2
index 60ca465..c3487b5 100644
@@ -336,7 +336,7 @@ static int hvmemul_do_io(
             rc = hvm_send_ioreq(s, &p, 0);
             if ( rc != X86EMUL_RETRY || currd->is_shutting_down )
                 vio->io_req.state = STATE_IOREQ_NONE;
-            else if ( !hvm_ioreq_needs_completion(&vio->io_req) )
+            else if ( !ioreq_needs_completion(&vio->io_req) )
                 rc = X86EMUL_OKAY;
         }
         break;
@@ -2649,7 +2649,7 @@ static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
     if ( rc == X86EMUL_OKAY && vio->mmio_retry )
         rc = X86EMUL_RETRY;
 
-    if ( !hvm_ioreq_needs_completion(&vio->io_req) )
+    if ( !ioreq_needs_completion(&vio->io_req) )
         completion = HVMIO_no_completion;
     else if ( completion == HVMIO_no_completion )
         completion = (vio->io_req.type != IOREQ_TYPE_PIO ||
xen/arch/x86/hvm/io.c +1 -1
index 11e007d..ef8286b 100644
@@ -135,7 +135,7 @@ bool handle_pio(uint16_t port, unsigned int size, int dir)
 
     rc = hvmemul_do_pio_buffer(port, size, dir, &data);
 
-    if ( hvm_ioreq_needs_completion(&vio->io_req) )
+    if ( ioreq_needs_completion(&vio->io_req) )
         vio->io_completion = HVMIO_pio_completion;
 
     switch ( rc )
xen/common/ioreq.c +2 -2
index 8a004c4..47e38b6 100644
@@ -160,7 +160,7 @@ static bool hvm_wait_for_io(struct hvm_ioreq_vcpu *sv, ioreq_t *p)
     }
 
     p = &sv->vcpu->arch.hvm.hvm_io.io_req;
-    if ( hvm_ioreq_needs_completion(p) )
+    if ( ioreq_needs_completion(p) )
         p->data = data;
 
     sv->pending = false;
@@ -186,7 +186,7 @@ bool handle_hvm_io_completion(struct vcpu *v)
     if ( sv && !hvm_wait_for_io(sv, get_ioreq(s, v)) )
         return false;
 
-    vio->io_req.state = hvm_ioreq_needs_completion(&vio->io_req) ?
+    vio->io_req.state = ioreq_needs_completion(&vio->io_req) ?
         STATE_IORESP_READY : STATE_IOREQ_NONE;
 
     msix_write_completion(v);
xen/include/asm-x86/hvm/vcpu.h +0 -7
index 5ccd075..6c1feda 100644
@@ -91,13 +91,6 @@ struct hvm_vcpu_io {
     const struct g2m_ioport *g2m_ioport;
 };
 
-static inline bool hvm_ioreq_needs_completion(const ioreq_t *ioreq)
-{
-    return ioreq->state == STATE_IOREQ_READY &&
-           !ioreq->data_is_ptr &&
-           (ioreq->type != IOREQ_TYPE_PIO || ioreq->dir != IOREQ_WRITE);
-}
-
 struct nestedvcpu {
     bool_t nv_guestmode; /* vcpu in guestmode? */
     void *nv_vvmcx; /* l1 guest virtual VMCB/VMCS */
xen/include/xen/ioreq.h +7 -0
index 7b67950..750d884 100644
@@ -21,6 +21,13 @@
 
 #include <xen/sched.h>
 
+static inline bool ioreq_needs_completion(const ioreq_t *ioreq)
+{
+    return ioreq->state == STATE_IOREQ_READY &&
+           !ioreq->data_is_ptr &&
+           (ioreq->type != IOREQ_TYPE_PIO || ioreq->dir != IOREQ_WRITE);
+}
+
 #define HANDLE_BUFIOREQ(s) \
     ((s)->bufioreq_handling != HVM_IOREQSRV_BUFIOREQ_OFF)
 
Signature · 1 line
2.7.4
Reviewed-by on v4 5/24
#36 lore raw

Re: [PATCH V4 05/24] xen/ioreq: Make x86's hvm_ioreq_needs_completion() common

Hi Oleksandr,

Quoted 5 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and this helper will be used on Arm as is. Move it to xen/ioreq.h and remove "hvm" prefix.

Quoted 8 lines

Although PIO handling on Arm is not introduced with the current series (it will be implemented when we add support for vPCI), technically the PIOs exist on Arm (however they are accessed the same way as MMIO) and it would be better not to diverge now.

Cheers,

Signature · 1 line
Julien Grall
Reviewed-by on v4 5/24
#37 lore raw

Re: [PATCH V4 05/24] xen/ioreq: Make x86's hvm_ioreq_needs_completion() common

In reply to Oleksandr Tyshchenko
Quoted 9 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and this helper will be used on Arm as is. Move it to xen/ioreq.h and remove "hvm" prefix.

Although PIO handling on Arm is not introduced with the current series (it will be implemented when we add support for vPCI), technically the PIOs exist on Arm (however they are accessed the same way as MMIO) and it would be better not to diverge now.

I find this description a little confusing. When you say PIO do you mean using instructions like in/out on the x86? If so then AFAIK it's a legacy feature of x86 as everything I've come across since just does MMIO, including PCI.

The code changes look fine to me though:

Signature · 1 line
Alex Bennée
#38 lore raw

Re: [PATCH V4 05/24] xen/ioreq: Make x86's hvm_ioreq_needs_completion() common

Hi Alex,

Quoted 13 lines · Alex Bennée
Quoted 9 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and this helper will be used on Arm as is. Move it to xen/ioreq.h and remove "hvm" prefix.

Although PIO handling on Arm is not introduced with the current series (it will be implemented when we add support for vPCI), technically the PIOs exist on Arm (however they are accessed the same way as MMIO) and it would be better not to diverge now.

Quoted 4 lines

I find this description a little confusing. When you say PIO do you mean using instructions like in/out on the x86? If so then AFAIK it's a legacy feature of x86 as everything I've come across since just does MMIO, including PCI.

Stefano and I had quite a long discussion about this a few months ago (see [1]).

From my understanding, while Arm will access the PCI I/O BAR via MMIO, the BAR itself will be configured using an offset from a fixed I/O window base address. IOW, we don't configure the BAR with a full MMIO address.

In the case the hostbridge is emulated in Xen, I would like to re-use the TYPE_PIO for such access because it makes the device model arch-agnostic.

I believe this would behave the same way as a real PCI device card: you can plug it anywhere without having to understand the underlying architecture.

If we were going to use the MMIO type, then we would need:
1) Inform each device model where is the I/O Window (necessary to be
able to know we are accessing the I/O BAR)
2) Have arch boiler plate in the device model

Quoted 5 lines

The code changes look fine to me though:

Cheers,

[1] <[email protected]>

Signature · 1 line
Julien Grall
#39 lore raw

PATCH v4 6/24 xen/ioreq: Make x86's hvm_mmio_first(last)_byte() common

In reply to Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and these helpers will be used on Arm as is. Move them to xen/ioreq.h and replace "hvm" prefixes with "ioreq".

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- new patch

Changes V1 -> V2:
- replace "hvm" prefix by "ioreq"

Changes V2 -> V3:
- add Paul's R-b

Changes V32 -> V4:
- add Jan's A-b

---
 xen/arch/x86/hvm/intercept.c |  5 +++--
 xen/arch/x86/hvm/stdvga.c    |  4 ++--
 xen/common/ioreq.c           |  4 ++--
 xen/include/asm-x86/hvm/io.h | 16 ----------------
 xen/include/xen/ioreq.h      | 16 ++++++++++++++++
 5 files changed, 23 insertions(+), 22 deletions(-)
xen/arch/x86/hvm/intercept.c +3 -2
index cd4c4c1..02ca3b0 100644
@@ -17,6 +17,7 @@
  * this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <xen/ioreq.h>
 #include <xen/types.h>
 #include <xen/sched.h>
 #include <asm/regs.h>
@@ -34,7 +35,7 @@
 static bool_t hvm_mmio_accept(const struct hvm_io_handler *handler,
                               const ioreq_t *p)
 {
-    paddr_t first = hvm_mmio_first_byte(p), last;
+    paddr_t first = ioreq_mmio_first_byte(p), last;
 
     BUG_ON(handler->type != IOREQ_TYPE_COPY);
 
@@ -42,7 +43,7 @@ static bool_t hvm_mmio_accept(const struct hvm_io_handler *handler,
         return 0;
 
     /* Make sure the handler will accept the whole access. */
-    last = hvm_mmio_last_byte(p);
+    last = ioreq_mmio_last_byte(p);
     if ( last != first &&
          !handler->mmio.ops->check(current, last) )
         domain_crash(current->domain);
xen/arch/x86/hvm/stdvga.c +2 -2
index fd7cadb..17dee74 100644
@@ -524,8 +524,8 @@ static bool_t stdvga_mem_accept(const struct hvm_io_handler *handler,
      * deadlock when hvm_mmio_internal() is called from
      * hvm_copy_to/from_guest_phys() in hvm_process_io_intercept().
      */
-    if ( (hvm_mmio_first_byte(p) < VGA_MEM_BASE) ||
-         (hvm_mmio_last_byte(p) >= (VGA_MEM_BASE + VGA_MEM_SIZE)) )
+    if ( (ioreq_mmio_first_byte(p) < VGA_MEM_BASE) ||
+         (ioreq_mmio_last_byte(p) >= (VGA_MEM_BASE + VGA_MEM_SIZE)) )
         return 0;
 
     spin_lock(&s->lock);
xen/common/ioreq.c +2 -2
index 47e38b6..a196e14 100644
@@ -1078,8 +1078,8 @@ struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,
             break;
 
         case XEN_DMOP_IO_RANGE_MEMORY:
-            start = hvm_mmio_first_byte(p);
-            end = hvm_mmio_last_byte(p);
+            start = ioreq_mmio_first_byte(p);
+            end = ioreq_mmio_last_byte(p);
 
             if ( rangeset_contains_range(r, start, end) )
                 return s;
xen/include/asm-x86/hvm/io.h +0 -16
index 558426b..fb64294 100644
@@ -40,22 +40,6 @@ struct hvm_mmio_ops {
     hvm_mmio_write_t write;
 };
 
-static inline paddr_t hvm_mmio_first_byte(const ioreq_t *p)
-{
-    return unlikely(p->df) ?
-           p->addr - (p->count - 1ul) * p->size :
-           p->addr;
-}
-
-static inline paddr_t hvm_mmio_last_byte(const ioreq_t *p)
-{
-    unsigned long size = p->size;
-
-    return unlikely(p->df) ?
-           p->addr + size - 1:
-           p->addr + (p->count * size) - 1;
-}
-
 typedef int (*portio_action_t)(
     int dir, unsigned int port, unsigned int bytes, uint32_t *val);
 
xen/include/xen/ioreq.h +16 -0
index 750d884..aeea67e 100644
@@ -21,6 +21,22 @@
 
 #include <xen/sched.h>
 
+static inline paddr_t ioreq_mmio_first_byte(const ioreq_t *p)
+{
+    return unlikely(p->df) ?
+           p->addr - (p->count - 1ul) * p->size :
+           p->addr;
+}
+
+static inline paddr_t ioreq_mmio_last_byte(const ioreq_t *p)
+{
+    unsigned long size = p->size;
+
+    return unlikely(p->df) ?
+           p->addr + size - 1:
+           p->addr + (p->count * size) - 1;
+}
+
 static inline bool ioreq_needs_completion(const ioreq_t *ioreq)
 {
     return ioreq->state == STATE_IOREQ_READY &&
Signature · 1 line
2.7.4
Reviewed-by on v4 6/24
#40 lore raw

Re: [PATCH V4 06/24] xen/ioreq: Make x86's hvm_mmio_first(last)_byte() common

Hi Oleksandr,

Quoted 11 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and these helpers will be used on Arm as is. Move them to xen/ioreq.h and replace "hvm" prefixes with "ioreq".

Cheers,

Signature · 1 line
Julien Grall
Reviewed-by on v4 6/24
#41 lore raw

Re: [PATCH V4 06/24] xen/ioreq: Make x86's hvm_mmio_first(last)_byte() common

In reply to Oleksandr Tyshchenko
Quoted 11 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and these helpers will be used on Arm as is. Move them to xen/ioreq.h and replace "hvm" prefixes with "ioreq".

Signature · 1 line
Alex Bennée
#42 lore raw

Re: [PATCH V4 06/24] xen/ioreq: Make x86's hvm_mmio_first(last)_byte() common

In reply to Oleksandr Tyshchenko
Quoted 19 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and these helpers will be used on Arm as is. Move them to xen/ioreq.h and replace "hvm" prefixes with "ioreq".

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- new patch

Quoted 8 lines

Changes V1 -> V2:
- replace "hvm" prefix by "ioreq"

Changes V2 -> V3:
- add Paul's R-b

Changes V32 -> V4:
- add Jan's A-b

Did you?

Jan

#43 lore raw

Re: [PATCH V4 06/24] xen/ioreq: Make x86's hvm_mmio_first(last)_byte() common

On 20.01.21 18:15, Jan Beulich wrote:

Hi Jan

Quoted 23 lines · Oleksandr Tyshchenko
Quoted 22 lines

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and these helpers will be used on Arm as is. Move them to xen/ioreq.h and replace "hvm" prefixes with "ioreq".

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- new patch

Changes V1 -> V2:
- replace "hvm" prefix by "ioreq"

Quoted 6 lines
Quoted 5 lines

Changes V2 -> V3:
- add Paul's R-b

Changes V32 -> V4:
- add Jan's A-b

Did you?

Oops, I didn't. I will add.

Quoted 2 lines

Jan

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
#44 lore raw

PATCH v4 7/24 xen/ioreq: Make x86's hvm_ioreq_(page/vcpu/server) structs common

In reply to Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and these structs will be used on Arm as is. Move them to xen/ioreq.h and remove "hvm" prefixes.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- new patch

Changes V1 -> V2:
- remove "hvm" prefix

Changes V2 -> V3:
- update patch according the "legacy interface" is x86 specific

Changes V3 -> V4:
- add Jan's A-b

---
 xen/arch/x86/hvm/emulate.c       |   2 +-
 xen/arch/x86/hvm/ioreq.c         |  38 +++++++-------
 xen/arch/x86/hvm/stdvga.c        |   2 +-
 xen/arch/x86/mm/p2m.c            |   8 +--
 xen/common/ioreq.c               | 108 +++++++++++++++++++--------------------
 xen/include/asm-x86/hvm/domain.h |  36 +------------
 xen/include/asm-x86/p2m.h        |   8 +--
 xen/include/xen/ioreq.h          |  54 ++++++++++++++++----
 8 files changed, 128 insertions(+), 128 deletions(-)
xen/arch/x86/hvm/emulate.c +1 -1
index c3487b5..4d62199 100644
@@ -287,7 +287,7 @@ static int hvmemul_do_io(
          * However, there's no cheap approach to avoid above situations in xen,
          * so the device model side needs to check the incoming ioreq event.
          */
-        struct hvm_ioreq_server *s = NULL;
+        struct ioreq_server *s = NULL;
         p2m_type_t p2mt = p2m_invalid;
 
         if ( is_mmio )
xen/arch/x86/hvm/ioreq.c +19 -19
index 177b964..8393922 100644
@@ -63,7 +63,7 @@ bool arch_vcpu_ioreq_completion(enum hvm_io_completion io_completion)
     return true;
 }
 
-static gfn_t hvm_alloc_legacy_ioreq_gfn(struct hvm_ioreq_server *s)
+static gfn_t hvm_alloc_legacy_ioreq_gfn(struct ioreq_server *s)
 {
     struct domain *d = s->target;
     unsigned int i;
@@ -79,7 +79,7 @@ static gfn_t hvm_alloc_legacy_ioreq_gfn(struct hvm_ioreq_server *s)
     return INVALID_GFN;
 }
 
-static gfn_t hvm_alloc_ioreq_gfn(struct hvm_ioreq_server *s)
+static gfn_t hvm_alloc_ioreq_gfn(struct ioreq_server *s)
 {
     struct domain *d = s->target;
     unsigned int i;
@@ -97,7 +97,7 @@ static gfn_t hvm_alloc_ioreq_gfn(struct hvm_ioreq_server *s)
     return hvm_alloc_legacy_ioreq_gfn(s);
 }
 
-static bool hvm_free_legacy_ioreq_gfn(struct hvm_ioreq_server *s,
+static bool hvm_free_legacy_ioreq_gfn(struct ioreq_server *s,
                                       gfn_t gfn)
 {
     struct domain *d = s->target;
@@ -115,7 +115,7 @@ static bool hvm_free_legacy_ioreq_gfn(struct hvm_ioreq_server *s,
     return true;
 }
 
-static void hvm_free_ioreq_gfn(struct hvm_ioreq_server *s, gfn_t gfn)
+static void hvm_free_ioreq_gfn(struct ioreq_server *s, gfn_t gfn)
 {
     struct domain *d = s->target;
     unsigned int i = gfn_x(gfn) - d->arch.hvm.ioreq_gfn.base;
@@ -129,9 +129,9 @@ static void hvm_free_ioreq_gfn(struct hvm_ioreq_server *s, gfn_t gfn)
     }
 }
 
-static void hvm_unmap_ioreq_gfn(struct hvm_ioreq_server *s, bool buf)
+static void hvm_unmap_ioreq_gfn(struct ioreq_server *s, bool buf)
 {
-    struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;
+    struct ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;
 
     if ( gfn_eq(iorp->gfn, INVALID_GFN) )
         return;
@@ -143,10 +143,10 @@ static void hvm_unmap_ioreq_gfn(struct hvm_ioreq_server *s, bool buf)
     iorp->gfn = INVALID_GFN;
 }
 
-static int hvm_map_ioreq_gfn(struct hvm_ioreq_server *s, bool buf)
+static int hvm_map_ioreq_gfn(struct ioreq_server *s, bool buf)
 {
     struct domain *d = s->target;
-    struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;
+    struct ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;
     int rc;
 
     if ( iorp->page )
@@ -179,11 +179,11 @@ static int hvm_map_ioreq_gfn(struct hvm_ioreq_server *s, bool buf)
     return rc;
 }
 
-static void hvm_remove_ioreq_gfn(struct hvm_ioreq_server *s, bool buf)
+static void hvm_remove_ioreq_gfn(struct ioreq_server *s, bool buf)
 
 {
     struct domain *d = s->target;
-    struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;
+    struct ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;
 
     if ( gfn_eq(iorp->gfn, INVALID_GFN) )
         return;
@@ -194,10 +194,10 @@ static void hvm_remove_ioreq_gfn(struct hvm_ioreq_server *s, bool buf)
     clear_page(iorp->va);
 }
 
-static int hvm_add_ioreq_gfn(struct hvm_ioreq_server *s, bool buf)
+static int hvm_add_ioreq_gfn(struct ioreq_server *s, bool buf)
 {
     struct domain *d = s->target;
-    struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;
+    struct ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;
     int rc;
 
     if ( gfn_eq(iorp->gfn, INVALID_GFN) )
@@ -213,7 +213,7 @@ static int hvm_add_ioreq_gfn(struct hvm_ioreq_server *s, bool buf)
     return rc;
 }
 
-int arch_ioreq_server_map_pages(struct hvm_ioreq_server *s)
+int arch_ioreq_server_map_pages(struct ioreq_server *s)
 {
     int rc;
 
@@ -228,40 +228,40 @@ int arch_ioreq_server_map_pages(struct hvm_ioreq_server *s)
     return rc;
 }
 
-void arch_ioreq_server_unmap_pages(struct hvm_ioreq_server *s)
+void arch_ioreq_server_unmap_pages(struct ioreq_server *s)
 {
     hvm_unmap_ioreq_gfn(s, true);
     hvm_unmap_ioreq_gfn(s, false);
 }
 
-void arch_ioreq_server_enable(struct hvm_ioreq_server *s)
+void arch_ioreq_server_enable(struct ioreq_server *s)
 {
     hvm_remove_ioreq_gfn(s, false);
     hvm_remove_ioreq_gfn(s, true);
 }
 
-void arch_ioreq_server_disable(struct hvm_ioreq_server *s)
+void arch_ioreq_server_disable(struct ioreq_server *s)
 {
     hvm_add_ioreq_gfn(s, true);
     hvm_add_ioreq_gfn(s, false);
 }
 
 /* Called when target domain is paused */
-void arch_ioreq_server_destroy(struct hvm_ioreq_server *s)
+void arch_ioreq_server_destroy(struct ioreq_server *s)
 {
     p2m_set_ioreq_server(s->target, 0, s);
 }
 
 /* Called with ioreq_server lock held */
 int arch_ioreq_server_map_mem_type(struct domain *d,
-                                   struct hvm_ioreq_server *s,
+                                   struct ioreq_server *s,
                                    uint32_t flags)
 {
     return p2m_set_ioreq_server(d, flags, s);
 }
 
 void arch_ioreq_server_map_mem_type_completed(struct domain *d,
-                                              struct hvm_ioreq_server *s,
+                                              struct ioreq_server *s,
                                               uint32_t flags)
 {
     if ( flags == 0 )
xen/arch/x86/hvm/stdvga.c +1 -1
index 17dee74..ee13449 100644
@@ -466,7 +466,7 @@ static int stdvga_mem_write(const struct hvm_io_handler *handler,
         .dir = IOREQ_WRITE,
         .data = data,
     };
-    struct hvm_ioreq_server *srv;
+    struct ioreq_server *srv;
 
     if ( !stdvga_cache_is_enabled(s) || !s->stdvga )
         goto done;
xen/arch/x86/mm/p2m.c +4 -4
index ad4bb94..71fda06 100644
@@ -372,7 +372,7 @@ void p2m_memory_type_changed(struct domain *d)
 
 int p2m_set_ioreq_server(struct domain *d,
                          unsigned int flags,
-                         struct hvm_ioreq_server *s)
+                         struct ioreq_server *s)
 {
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
     int rc;
@@ -420,11 +420,11 @@ int p2m_set_ioreq_server(struct domain *d,
     return rc;
 }
 
-struct hvm_ioreq_server *p2m_get_ioreq_server(struct domain *d,
-                                              unsigned int *flags)
+struct ioreq_server *p2m_get_ioreq_server(struct domain *d,
+                                          unsigned int *flags)
 {
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
-    struct hvm_ioreq_server *s;
+    struct ioreq_server *s;
 
     spin_lock(&p2m->ioreq.lock);
 
xen/common/ioreq.c +54 -54

352 lines not on this page · raw message

xen/include/asm-x86/hvm/domain.h +1 -35
index 9d247ba..1c4ca47 100644
@@ -30,40 +30,6 @@
 
 #include <public/hvm/dm_op.h>
 
-struct hvm_ioreq_page {
-    gfn_t gfn;
-    struct page_info *page;
-    void *va;
-};
-
-struct hvm_ioreq_vcpu {
-    struct list_head list_entry;
-    struct vcpu      *vcpu;
-    evtchn_port_t    ioreq_evtchn;
-    bool             pending;
-};
-
-#define NR_IO_RANGE_TYPES (XEN_DMOP_IO_RANGE_PCI + 1)
-#define MAX_NR_IO_RANGES  256
-
-struct hvm_ioreq_server {
-    struct domain          *target, *emulator;
-
-    /* Lock to serialize toolstack modifications */
-    spinlock_t             lock;
-
-    struct hvm_ioreq_page  ioreq;
-    struct list_head       ioreq_vcpu_list;
-    struct hvm_ioreq_page  bufioreq;
-
-    /* Lock to serialize access to buffered ioreq ring */
-    spinlock_t             bufioreq_lock;
-    evtchn_port_t          bufioreq_evtchn;
-    struct rangeset        *range[NR_IO_RANGE_TYPES];
-    bool                   enabled;
-    uint8_t                bufioreq_handling;
-};
-
 #ifdef CONFIG_MEM_SHARING
 struct mem_sharing_domain
 {
@@ -110,7 +76,7 @@ struct hvm_domain {
     /* Lock protects all other values in the sub-struct and the default */
     struct {
         spinlock_t              lock;
-        struct hvm_ioreq_server *server[MAX_NR_IOREQ_SERVERS];
+        struct ioreq_server *server[MAX_NR_IOREQ_SERVERS];
     } ioreq_server;
 
     /* Cached CF8 for guest PCI config cycles */
xen/include/asm-x86/p2m.h +4 -4
index 6447696..7df2878 100644
@@ -363,7 +363,7 @@ struct p2m_domain {
           * ioreq server who's responsible for the emulation of
           * gfns with specific p2m type(for now, p2m_ioreq_server).
           */
-         struct hvm_ioreq_server *server;
+         struct ioreq_server *server;
          /*
           * flags specifies whether read, write or both operations
           * are to be emulated by an ioreq server.
@@ -937,9 +937,9 @@ static inline unsigned int p2m_get_iommu_flags(p2m_type_t p2mt, mfn_t mfn)
 }
 
 int p2m_set_ioreq_server(struct domain *d, unsigned int flags,
-                         struct hvm_ioreq_server *s);
-struct hvm_ioreq_server *p2m_get_ioreq_server(struct domain *d,
-                                              unsigned int *flags);
+                         struct ioreq_server *s);
+struct ioreq_server *p2m_get_ioreq_server(struct domain *d,
+                                          unsigned int *flags);
 
 static inline int p2m_entry_modify(struct p2m_domain *p2m, p2m_type_t nt,
                                    p2m_type_t ot, mfn_t nfn, mfn_t ofn,
xen/include/xen/ioreq.h +44 -10

75 lines not on this page · raw message

Signature · 1 line
2.7.4
Reviewed-by on v4 7/24
#45 lore raw

Re: [PATCH V4 07/24] xen/ioreq: Make x86's hvm_ioreq_(page/vcpu/server) structs common

Hi Oleksandr,

Quoted 10 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and these structs will be used on Arm as is. Move them to xen/ioreq.h and remove "hvm" prefixes.

Cheers,

Signature · 1 line
Julien Grall
Reviewed-by on v4 7/24
#46 lore raw

RE: [PATCH V4 07/24] xen/ioreq: Make x86's hvm_ioreq_(page/vcpu/server) structs common

In reply to Oleksandr Tyshchenko
Quoted 10 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Oleksandr Tyshchenko
Sent: 12 January 2021 21:52
To: [email protected]
Cc: Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH V4 07/24] xen/ioreq: Make x86's hvm_ioreq_(page/vcpu/server) structs common

Quoted 6 lines

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and these structs will be used on Arm as is. Move them to xen/ioreq.h and remove "hvm" prefixes.

... with one small nit below (if you happen to do a v5)

Quoted 31 lines

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- new patch

Changes V1 -> V2:
- remove "hvm" prefix

Changes V2 -> V3:
- update patch according the "legacy interface" is x86 specific

Changes V3 -> V4:
- add Jan's A-b

---
 xen/arch/x86/hvm/emulate.c       |   2 +-
 xen/arch/x86/hvm/ioreq.c         |  38 +++++++-------
 xen/arch/x86/hvm/stdvga.c        |   2 +-
 xen/arch/x86/mm/p2m.c            |   8 +--
 xen/common/ioreq.c               | 108 +++++++++++++++++++--------------------
 xen/include/asm-x86/hvm/domain.h |  36 +------------
 xen/include/asm-x86/p2m.h        |   8 +--
 xen/include/xen/ioreq.h          |  54 ++++++++++++++++----
 8 files changed, 128 insertions(+), 128 deletions(-)

[snip]

xen/include/asm-x86/hvm/domain.h struct hvm_domain { · line 79

Quoted 9 lines

#ifdef CONFIG_MEM_SHARING
struct mem_sharing_domain
{

xen/include/asm-x86/hvm/domain.h +1 -1
@@ -110,7 +76,7 @@ struct hvm_domain {
     /* Lock protects all other values in the sub-struct and the default */
     struct {
         spinlock_t              lock;
-        struct hvm_ioreq_server *server[MAX_NR_IOREQ_SERVERS];
+        struct ioreq_server *server[MAX_NR_IOREQ_SERVERS];

NIT: this breaks the alignment... you should also remove some of the indent from the line above.

Quoted 3 lines
xen/include/asm-x86/hvm/domain.h +0 -0
     } ioreq_server;
 
     /* Cached CF8 for guest PCI config cycles */
Reviewed-by on v4 7/24
#47 lore raw

Re: [PATCH V4 07/24] xen/ioreq: Make x86's hvm_ioreq_(page/vcpu/server) structs common

In reply to Oleksandr Tyshchenko
Quoted 10 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and these structs will be used on Arm as is. Move them to xen/ioreq.h and remove "hvm" prefixes.

Signature · 1 line
Alex Bennée
#48 lore raw

PATCH v4 8/24 xen/ioreq: Move x86's ioreq_server to struct domain

In reply to Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and this struct will be used on Arm as is. Move it to common struct domain. This also significantly reduces the layering violation in the common code (*arch.hvm* usage).

We don't move ioreq_gfn since it is not used in the common code (the "legacy" mechanism is x86 specific).

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes V1 -> V2:
- new patch

Changes V2 -> V3:
- remove the mention of "ioreq_gfn" from patch subject/description
- update patch according the "legacy interface" is x86 specific
- drop hvm_params related changes in arch/x86/hvm/hvm.c
- leave ioreq_gfn in hvm_domain

Changes V3 -> V4:
- rebase
- drop the stale part of the comment above struct ioreq_server
- add Jan's A-b

---
 xen/common/ioreq.c               | 60 ++++++++++++++++++++--------------------
 xen/include/asm-x86/hvm/domain.h |  8 ------
 xen/include/xen/sched.h          | 10 +++++++
 3 files changed, 40 insertions(+), 38 deletions(-)
xen/common/ioreq.c +30 -30
index 3f631ec..a319c88 100644
@@ -38,13 +38,13 @@ static void set_ioreq_server(struct domain *d, unsigned int id,
                              struct ioreq_server *s)
 {
     ASSERT(id < MAX_NR_IOREQ_SERVERS);
-    ASSERT(!s || !d->arch.hvm.ioreq_server.server[id]);
+    ASSERT(!s || !d->ioreq_server.server[id]);
 
-    d->arch.hvm.ioreq_server.server[id] = s;
+    d->ioreq_server.server[id] = s;
 }
 
 #define GET_IOREQ_SERVER(d, id) \
-    (d)->arch.hvm.ioreq_server.server[id]
+    (d)->ioreq_server.server[id]
 
 static struct ioreq_server *get_ioreq_server(const struct domain *d,
                                              unsigned int id)
@@ -285,7 +285,7 @@ bool is_ioreq_server_page(struct domain *d, const struct page_info *page)
     unsigned int id;
     bool found = false;
 
-    spin_lock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_lock_recursive(&d->ioreq_server.lock);
 
     FOR_EACH_IOREQ_SERVER(d, id, s)
     {
@@ -296,7 +296,7 @@ bool is_ioreq_server_page(struct domain *d, const struct page_info *page)
         }
     }
 
-    spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_unlock_recursive(&d->ioreq_server.lock);
 
     return found;
 }
@@ -606,7 +606,7 @@ int hvm_create_ioreq_server(struct domain *d, int bufioreq_handling,
         return -ENOMEM;
 
     domain_pause(d);
-    spin_lock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_lock_recursive(&d->ioreq_server.lock);
 
     for ( i = 0; i < MAX_NR_IOREQ_SERVERS; i++ )
     {
@@ -634,13 +634,13 @@ int hvm_create_ioreq_server(struct domain *d, int bufioreq_handling,
     if ( id )
         *id = i;
 
-    spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_unlock_recursive(&d->ioreq_server.lock);
     domain_unpause(d);
 
     return 0;
 
  fail:
-    spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_unlock_recursive(&d->ioreq_server.lock);
     domain_unpause(d);
 
     xfree(s);
@@ -652,7 +652,7 @@ int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id)
     struct ioreq_server *s;
     int rc;
 
-    spin_lock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_lock_recursive(&d->ioreq_server.lock);
 
     s = get_ioreq_server(d, id);
 
@@ -684,7 +684,7 @@ int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id)
     rc = 0;
 
  out:
-    spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_unlock_recursive(&d->ioreq_server.lock);
 
     return rc;
 }
@@ -697,7 +697,7 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,
     struct ioreq_server *s;
     int rc;
 
-    spin_lock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_lock_recursive(&d->ioreq_server.lock);
 
     s = get_ioreq_server(d, id);
 
@@ -731,7 +731,7 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,
     rc = 0;
 
  out:
-    spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_unlock_recursive(&d->ioreq_server.lock);
 
     return rc;
 }
@@ -744,7 +744,7 @@ int hvm_get_ioreq_server_frame(struct domain *d, ioservid_t id,
 
     ASSERT(is_hvm_domain(d));
 
-    spin_lock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_lock_recursive(&d->ioreq_server.lock);
 
     s = get_ioreq_server(d, id);
 
@@ -782,7 +782,7 @@ int hvm_get_ioreq_server_frame(struct domain *d, ioservid_t id,
     }
 
  out:
-    spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_unlock_recursive(&d->ioreq_server.lock);
 
     return rc;
 }
@@ -798,7 +798,7 @@ int hvm_map_io_range_to_ioreq_server(struct domain *d, ioservid_t id,
     if ( start > end )
         return -EINVAL;
 
-    spin_lock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_lock_recursive(&d->ioreq_server.lock);
 
     s = get_ioreq_server(d, id);
 
@@ -834,7 +834,7 @@ int hvm_map_io_range_to_ioreq_server(struct domain *d, ioservid_t id,
     rc = rangeset_add_range(r, start, end);
 
  out:
-    spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_unlock_recursive(&d->ioreq_server.lock);
 
     return rc;
 }
@@ -850,7 +850,7 @@ int hvm_unmap_io_range_from_ioreq_server(struct domain *d, ioservid_t id,
     if ( start > end )
         return -EINVAL;
 
-    spin_lock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_lock_recursive(&d->ioreq_server.lock);
 
     s = get_ioreq_server(d, id);
 
@@ -886,7 +886,7 @@ int hvm_unmap_io_range_from_ioreq_server(struct domain *d, ioservid_t id,
     rc = rangeset_remove_range(r, start, end);
 
  out:
-    spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_unlock_recursive(&d->ioreq_server.lock);
 
     return rc;
 }
@@ -911,7 +911,7 @@ int hvm_map_mem_type_to_ioreq_server(struct domain *d, ioservid_t id,
     if ( flags & ~XEN_DMOP_IOREQ_MEM_ACCESS_WRITE )
         return -EINVAL;
 
-    spin_lock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_lock_recursive(&d->ioreq_server.lock);
 
     s = get_ioreq_server(d, id);
 
@@ -926,7 +926,7 @@ int hvm_map_mem_type_to_ioreq_server(struct domain *d, ioservid_t id,
     rc = arch_ioreq_server_map_mem_type(d, s, flags);
 
  out:
-    spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_unlock_recursive(&d->ioreq_server.lock);
 
     if ( rc == 0 )
         arch_ioreq_server_map_mem_type_completed(d, s, flags);
@@ -940,7 +940,7 @@ int hvm_set_ioreq_server_state(struct domain *d, ioservid_t id,
     struct ioreq_server *s;
     int rc;
 
-    spin_lock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_lock_recursive(&d->ioreq_server.lock);
 
     s = get_ioreq_server(d, id);
 
@@ -964,7 +964,7 @@ int hvm_set_ioreq_server_state(struct domain *d, ioservid_t id,
     rc = 0;
 
  out:
-    spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_unlock_recursive(&d->ioreq_server.lock);
     return rc;
 }
 
@@ -974,7 +974,7 @@ int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v)
     unsigned int id;
     int rc;
 
-    spin_lock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_lock_recursive(&d->ioreq_server.lock);
 
     FOR_EACH_IOREQ_SERVER(d, id, s)
     {
@@ -983,7 +983,7 @@ int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v)
             goto fail;
     }
 
-    spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_unlock_recursive(&d->ioreq_server.lock);
 
     return 0;
 
@@ -998,7 +998,7 @@ int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v)
         hvm_ioreq_server_remove_vcpu(s, v);
     }
 
-    spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_unlock_recursive(&d->ioreq_server.lock);
 
     return rc;
 }
@@ -1008,12 +1008,12 @@ void hvm_all_ioreq_servers_remove_vcpu(struct domain *d, struct vcpu *v)
     struct ioreq_server *s;
     unsigned int id;
 
-    spin_lock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_lock_recursive(&d->ioreq_server.lock);
 
     FOR_EACH_IOREQ_SERVER(d, id, s)
         hvm_ioreq_server_remove_vcpu(s, v);
 
-    spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_unlock_recursive(&d->ioreq_server.lock);
 }
 
 void hvm_destroy_all_ioreq_servers(struct domain *d)
@@ -1024,7 +1024,7 @@ void hvm_destroy_all_ioreq_servers(struct domain *d)
     if ( !arch_ioreq_server_destroy_all(d) )
         return;
 
-    spin_lock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_lock_recursive(&d->ioreq_server.lock);
 
     /* No need to domain_pause() as the domain is being torn down */
 
@@ -1042,7 +1042,7 @@ void hvm_destroy_all_ioreq_servers(struct domain *d)
         xfree(s);
     }
 
-    spin_unlock_recursive(&d->arch.hvm.ioreq_server.lock);
+    spin_unlock_recursive(&d->ioreq_server.lock);
 }
 
 struct ioreq_server *hvm_select_ioreq_server(struct domain *d,
@@ -1274,7 +1274,7 @@ unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered)
 
 void hvm_ioreq_init(struct domain *d)
 {
-    spin_lock_init(&d->arch.hvm.ioreq_server.lock);
+    spin_lock_init(&d->ioreq_server.lock);
 
     arch_ioreq_domain_init(d);
 }
xen/include/asm-x86/hvm/domain.h +0 -8
index 1c4ca47..b8be1ad 100644
@@ -63,8 +63,6 @@ struct hvm_pi_ops {
     void (*vcpu_block)(struct vcpu *);
 };
 
-#define MAX_NR_IOREQ_SERVERS 8
-
 struct hvm_domain {
     /* Guest page range used for non-default ioreq servers */
     struct {
@@ -73,12 +71,6 @@ struct hvm_domain {
         unsigned long legacy_mask; /* indexed by HVM param number */
     } ioreq_gfn;
 
-    /* Lock protects all other values in the sub-struct and the default */
-    struct {
-        spinlock_t              lock;
-        struct ioreq_server *server[MAX_NR_IOREQ_SERVERS];
-    } ioreq_server;
-
     /* Cached CF8 for guest PCI config cycles */
     uint32_t                pci_cf8;
 
xen/include/xen/sched.h +10 -0
index 3e46384..ad0d761 100644
@@ -318,6 +318,8 @@ struct sched_unit {
 
 struct evtchn_port_ops;
 
+#define MAX_NR_IOREQ_SERVERS 8
+
 struct domain
 {
     domid_t          domain_id;
@@ -533,6 +535,14 @@ struct domain
     struct {
         unsigned int val;
     } teardown;
+
+#ifdef CONFIG_IOREQ_SERVER
+    /* Lock protects all other values in the sub-struct */
+    struct {
+        spinlock_t              lock;
+        struct ioreq_server     *server[MAX_NR_IOREQ_SERVERS];
+    } ioreq_server;
+#endif
 };
 
 static inline struct page_list_head *page_to_list(
Signature · 1 line
2.7.4
Reviewed-by on v4 8/24
#49 lore raw

Re: [PATCH V4 08/24] xen/ioreq: Move x86's ioreq_server to struct domain

Hi Oleksandr,

Quoted 7 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and this struct will be used on Arm as is. Move it to common struct domain. This also significantly reduces the layering violation in the common code (*arch.hvm* usage).

Quoted 8 lines

We don't move ioreq_gfn since it is not used in the common code (the "legacy" mechanism is x86 specific).

Cheers,

Signature · 1 line
Julien Grall
Reviewed-by on v4 8/24
#50 lore raw

RE: [PATCH V4 08/24] xen/ioreq: Move x86's ioreq_server to struct domain

In reply to Oleksandr Tyshchenko
Quoted 18 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Oleksandr Tyshchenko
Sent: 12 January 2021 21:52
To: [email protected]
Cc: Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Jan Beulich <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH V4 08/24] xen/ioreq: Move x86's ioreq_server to struct domain

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and this struct will be used on Arm as is. Move it to common struct domain. This also significantly reduces the layering violation in the common code (*arch.hvm* usage).

Quoted 4 lines

We don't move ioreq_gfn since it is not used in the common code (the "legacy" mechanism is x86 specific).

...and I see you fix the alignment issue as part of the code movement in this patch :-)

Reviewed-by on v4 8/24
#51 lore raw

Re: [PATCH V4 08/24] xen/ioreq: Move x86's ioreq_server to struct domain

In reply to Oleksandr Tyshchenko
Quoted 7 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and this struct will be used on Arm as is. Move it to common struct domain. This also significantly reduces the layering violation in the common code (*arch.hvm* usage).

Quoted 8 lines

We don't move ioreq_gfn since it is not used in the common code (the "legacy" mechanism is x86 specific).

Signature · 1 line
Alex Bennée
#52 lore raw

PATCH v4 9/24 xen/ioreq: Make x86's IOREQ related dm-op handling common

In reply to Oleksandr Tyshchenko

From: Julien Grall <[email protected]>

As a lot of x86 code can be re-used on Arm later on, this patch moves the IOREQ related dm-op handling to the common code.

The idea is to have the top level dm-op handling arch-specific and call into ioreq_server_dm_op() for otherwise unhandled ops. Pros:
- More natural than doing it other way around (top level dm-op handling common).
- Leave compat_dm_op() in x86 code.
Cons:
- Code duplication. Both arches have to duplicate do_dm_op(), etc.

Also update XSM code a bit to let dm-op be used on Arm.

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

***
I decided to leave common dm.h to keep struct dmop_args declaration (to be included by Arm's dm.c), alternatively we could avoid introducing new header by moving the declaration into the existing header, but failed to find a suitable one which context would fit.
***

Changes RFC -> V1:
- update XSM, related changes were pulled from:
[RFC PATCH V1 04/12] xen/arm: Introduce arch specific bits for IOREQ/DM features

Changes V1 -> V2:
- update the author of a patch
- update patch description
- introduce xen/dm.h and move definitions here

Changes V2 -> V3:
- no changes

Changes V3 -> V4:
- rework to have the top level dm-op handling arch-specific
- update patch subject/description, was "xen/dm: Make x86's DM feature common"
- make a few functions static in common ioreq.c

---
 xen/arch/x86/hvm/dm.c   | 101 +-----------------------------------
 xen/common/ioreq.c      | 135 ++++++++++++++++++++++++++++++++++++++++++------
 xen/include/xen/dm.h    |  39 ++++++++++++++
 xen/include/xen/ioreq.h |  17 +-----
 xen/include/xsm/dummy.h |   4 +-
 xen/include/xsm/xsm.h   |   6 +--
 xen/xsm/dummy.c         |   2 +-
 xen/xsm/flask/hooks.c   |   5 +-
 8 files changed, 171 insertions(+), 138 deletions(-)
 create mode 100644 xen/include/xen/dm.h
xen/arch/x86/hvm/dm.c +2 -99
index d3e2a9e..dc8e47d 100644
@@ -16,6 +16,7 @@
 
 #include <xen/event.h>
 #include <xen/guest_access.h>
+#include <xen/dm.h>
 #include <xen/hypercall.h>
 #include <xen/ioreq.h>
 #include <xen/nospec.h>
@@ -29,13 +30,6 @@
 
 #include <public/hvm/hvm_op.h>
 
-struct dmop_args {
-    domid_t domid;
-    unsigned int nr_bufs;
-    /* Reserve enough buf elements for all current hypercalls. */
-    struct xen_dm_op_buf buf[2];
-};
-
 static bool _raw_copy_from_guest_buf_offset(void *dst,
                                             const struct dmop_args *args,
                                             unsigned int buf_idx,
@@ -408,71 +402,6 @@ static int dm_op(const struct dmop_args *op_args)
 
     switch ( op.op )
     {
-    case XEN_DMOP_create_ioreq_server:
-    {
-        struct xen_dm_op_create_ioreq_server *data =
-            &op.u.create_ioreq_server;
-
-        const_op = false;
-
-        rc = -EINVAL;
-        if ( data->pad[0] || data->pad[1] || data->pad[2] )
-            break;
-
-        rc = hvm_create_ioreq_server(d, data->handle_bufioreq,
-                                     &data->id);
-        break;
-    }
-
-    case XEN_DMOP_get_ioreq_server_info:
-    {
-        struct xen_dm_op_get_ioreq_server_info *data =
-            &op.u.get_ioreq_server_info;
-        const uint16_t valid_flags = XEN_DMOP_no_gfns;
-
-        const_op = false;
-
-        rc = -EINVAL;
-        if ( data->flags & ~valid_flags )
-            break;
-
-        rc = hvm_get_ioreq_server_info(d, data->id,
-                                       (data->flags & XEN_DMOP_no_gfns) ?
-                                       NULL : &data->ioreq_gfn,
-                                       (data->flags & XEN_DMOP_no_gfns) ?
-                                       NULL : &data->bufioreq_gfn,
-                                       &data->bufioreq_port);
-        break;
-    }
-
-    case XEN_DMOP_map_io_range_to_ioreq_server:
-    {
-        const struct xen_dm_op_ioreq_server_range *data =
-            &op.u.map_io_range_to_ioreq_server;
-
-        rc = -EINVAL;
-        if ( data->pad )
-            break;
-
-        rc = hvm_map_io_range_to_ioreq_server(d, data->id, data->type,
-                                              data->start, data->end);
-        break;
-    }
-
-    case XEN_DMOP_unmap_io_range_from_ioreq_server:
-    {
-        const struct xen_dm_op_ioreq_server_range *data =
-            &op.u.unmap_io_range_from_ioreq_server;
-
-        rc = -EINVAL;
-        if ( data->pad )
-            break;
-
-        rc = hvm_unmap_io_range_from_ioreq_server(d, data->id, data->type,
-                                                  data->start, data->end);
-        break;
-    }
-
     case XEN_DMOP_map_mem_type_to_ioreq_server:
     {
         struct xen_dm_op_map_mem_type_to_ioreq_server *data =
@@ -523,32 +452,6 @@ static int dm_op(const struct dmop_args *op_args)
         break;
     }
 
-    case XEN_DMOP_set_ioreq_server_state:
-    {
-        const struct xen_dm_op_set_ioreq_server_state *data =
-            &op.u.set_ioreq_server_state;
-
-        rc = -EINVAL;
-        if ( data->pad )
-            break;
-
-        rc = hvm_set_ioreq_server_state(d, data->id, !!data->enabled);
-        break;
-    }
-
-    case XEN_DMOP_destroy_ioreq_server:
-    {
-        const struct xen_dm_op_destroy_ioreq_server *data =
-            &op.u.destroy_ioreq_server;
-
-        rc = -EINVAL;
-        if ( data->pad )
-            break;
-
-        rc = hvm_destroy_ioreq_server(d, data->id);
-        break;
-    }
-
     case XEN_DMOP_track_dirty_vram:
     {
         const struct xen_dm_op_track_dirty_vram *data =
@@ -703,7 +606,7 @@ static int dm_op(const struct dmop_args *op_args)
     }
 
     default:
-        rc = -EOPNOTSUPP;
+        rc = ioreq_server_dm_op(&op, d, &const_op);
         break;
     }
 
xen/common/ioreq.c +120 -15

177 lines not on this page · raw message

xen/include/xen/dm.h new file +39 -0
new file mode 100644
index 0000000..2c9952d
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2016 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __XEN_DM_H__
+#define __XEN_DM_H__
+
+#include <xen/sched.h>
+
+struct dmop_args {
+    domid_t domid;
+    unsigned int nr_bufs;
+    /* Reserve enough buf elements for all current hypercalls. */
+    struct xen_dm_op_buf buf[2];
+};
+
+#endif /* __XEN_DM_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/xen/ioreq.h +2 -15
index bc79c37..7a90873 100644
@@ -85,25 +85,10 @@ bool hvm_io_pending(struct vcpu *v);
 bool handle_hvm_io_completion(struct vcpu *v);
 bool is_ioreq_server_page(struct domain *d, const struct page_info *page);
 
-int hvm_create_ioreq_server(struct domain *d, int bufioreq_handling,
-                            ioservid_t *id);
-int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id);
-int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,
-                              unsigned long *ioreq_gfn,
-                              unsigned long *bufioreq_gfn,
-                              evtchn_port_t *bufioreq_port);
 int hvm_get_ioreq_server_frame(struct domain *d, ioservid_t id,
                                unsigned long idx, mfn_t *mfn);
-int hvm_map_io_range_to_ioreq_server(struct domain *d, ioservid_t id,
-                                     uint32_t type, uint64_t start,
-                                     uint64_t end);
-int hvm_unmap_io_range_from_ioreq_server(struct domain *d, ioservid_t id,
-                                         uint32_t type, uint64_t start,
-                                         uint64_t end);
 int hvm_map_mem_type_to_ioreq_server(struct domain *d, ioservid_t id,
                                      uint32_t type, uint32_t flags);
-int hvm_set_ioreq_server_state(struct domain *d, ioservid_t id,
-                               bool enabled);
 
 int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v);
 void hvm_all_ioreq_servers_remove_vcpu(struct domain *d, struct vcpu *v);
@@ -117,6 +102,8 @@ unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered);
 
 void hvm_ioreq_init(struct domain *d);
 
+int ioreq_server_dm_op(struct xen_dm_op *op, struct domain *d, bool *const_op);
+
 bool arch_ioreq_complete_mmio(void);
 bool arch_vcpu_ioreq_completion(enum hvm_io_completion io_completion);
 int arch_ioreq_server_map_pages(struct ioreq_server *s);
xen/include/xsm/dummy.h +2 -2
index 7ae3c40..5c61d8e 100644
@@ -707,14 +707,14 @@ static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int
     }
 }
 
+#endif /* CONFIG_X86 */
+
 static XSM_INLINE int xsm_dm_op(XSM_DEFAULT_ARG struct domain *d)
 {
     XSM_ASSERT_ACTION(XSM_DM_PRIV);
     return xsm_default_action(action, current->domain, d);
 }
 
-#endif /* CONFIG_X86 */
-
 #ifdef CONFIG_ARGO
 static XSM_INLINE int xsm_argo_enable(const struct domain *d)
 {
xen/include/xsm/xsm.h +3 -3
index 7bd03d8..91ecff4 100644
@@ -176,8 +176,8 @@ struct xsm_operations {
     int (*ioport_permission) (struct domain *d, uint32_t s, uint32_t e, uint8_t allow);
     int (*ioport_mapping) (struct domain *d, uint32_t s, uint32_t e, uint8_t allow);
     int (*pmu_op) (struct domain *d, unsigned int op);
-    int (*dm_op) (struct domain *d);
 #endif
+    int (*dm_op) (struct domain *d);
     int (*xen_version) (uint32_t cmd);
     int (*domain_resource_map) (struct domain *d);
 #ifdef CONFIG_ARGO
@@ -682,13 +682,13 @@ static inline int xsm_pmu_op (xsm_default_t def, struct domain *d, unsigned int
     return xsm_ops->pmu_op(d, op);
 }
 
+#endif /* CONFIG_X86 */
+
 static inline int xsm_dm_op(xsm_default_t def, struct domain *d)
 {
     return xsm_ops->dm_op(d);
 }
 
-#endif /* CONFIG_X86 */
-
 static inline int xsm_xen_version (xsm_default_t def, uint32_t op)
 {
     return xsm_ops->xen_version(op);
xen/xsm/dummy.c +1 -1
index 9e09512..8bdffe7 100644
@@ -147,8 +147,8 @@ void __init xsm_fixup_ops (struct xsm_operations *ops)
     set_to_dummy_if_null(ops, ioport_permission);
     set_to_dummy_if_null(ops, ioport_mapping);
     set_to_dummy_if_null(ops, pmu_op);
-    set_to_dummy_if_null(ops, dm_op);
 #endif
+    set_to_dummy_if_null(ops, dm_op);
     set_to_dummy_if_null(ops, xen_version);
     set_to_dummy_if_null(ops, domain_resource_map);
 #ifdef CONFIG_ARGO
xen/xsm/flask/hooks.c +2 -3
index 19b0d9e..11784d7 100644
@@ -1656,14 +1656,13 @@ static int flask_pmu_op (struct domain *d, unsigned int op)
         return -EPERM;
     }
 }
+#endif /* CONFIG_X86 */
 
 static int flask_dm_op(struct domain *d)
 {
     return current_has_perm(d, SECCLASS_HVM, HVM__DM);
 }
 
-#endif /* CONFIG_X86 */
-
 static int flask_xen_version (uint32_t op)
 {
     u32 dsid = domain_sid(current->domain);
@@ -1865,8 +1864,8 @@ static struct xsm_operations flask_ops = {
     .ioport_permission = flask_ioport_permission,
     .ioport_mapping = flask_ioport_mapping,
     .pmu_op = flask_pmu_op,
-    .dm_op = flask_dm_op,
 #endif
+    .dm_op = flask_dm_op,
     .xen_version = flask_xen_version,
     .domain_resource_map = flask_domain_resource_map,
 #ifdef CONFIG_ARGO
Signature · 1 line
2.7.4
#53 lore raw

RE: [PATCH V4 09/24] xen/ioreq: Make x86's IOREQ related dm-op handling common

Quoted 219 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Oleksandr Tyshchenko
Sent: 12 January 2021 21:52
To: [email protected]
Cc: Julien Grall <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Paul Durrant <[email protected]>; Daniel De Graaf <[email protected]>; Oleksandr Tyshchenko <[email protected]>
Subject: [PATCH V4 09/24] xen/ioreq: Make x86's IOREQ related dm-op handling common

From: Julien Grall <[email protected]>

As a lot of x86 code can be re-used on Arm later on, this patch moves the IOREQ related dm-op handling to the common code.

The idea is to have the top level dm-op handling arch-specific and call into ioreq_server_dm_op() for otherwise unhandled ops. Pros:
- More natural than doing it other way around (top level dm-op handling common).
- Leave compat_dm_op() in x86 code.
Cons:
- Code duplication. Both arches have to duplicate do_dm_op(), etc.

Also update XSM code a bit to let dm-op be used on Arm.

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

***
I decided to leave common dm.h to keep struct dmop_args declaration (to be included by Arm's dm.c), alternatively we could avoid introducing new header by moving the declaration into the existing header, but failed to find a suitable one which context would fit.
***

Changes RFC -> V1:
- update XSM, related changes were pulled from:
[RFC PATCH V1 04/12] xen/arm: Introduce arch specific bits for IOREQ/DM features

Changes V1 -> V2:
- update the author of a patch
- update patch description
- introduce xen/dm.h and move definitions here

Changes V2 -> V3:
- no changes

Changes V3 -> V4:
- rework to have the top level dm-op handling arch-specific
- update patch subject/description, was "xen/dm: Make x86's DM feature common"
- make a few functions static in common ioreq.c

---
 xen/arch/x86/hvm/dm.c   | 101 +-----------------------------------
 xen/common/ioreq.c      | 135 ++++++++++++++++++++++++++++++++++++++++++------
 xen/include/xen/dm.h    |  39 ++++++++++++++
 xen/include/xen/ioreq.h |  17 +-----
 xen/include/xsm/dummy.h |   4 +-
 xen/include/xsm/xsm.h   |   6 +--
 xen/xsm/dummy.c         |   2 +-
 xen/xsm/flask/hooks.c   |   5 +-
 8 files changed, 171 insertions(+), 138 deletions(-)
 create mode 100644 xen/include/xen/dm.h
xen/arch/x86/hvm/dm.c +2 -99
index d3e2a9e..dc8e47d 100644
@@ -16,6 +16,7 @@
 
 #include <xen/event.h>
 #include <xen/guest_access.h>
+#include <xen/dm.h>
 #include <xen/hypercall.h>
 #include <xen/ioreq.h>
 #include <xen/nospec.h>
@@ -29,13 +30,6 @@
 
 #include <public/hvm/hvm_op.h>
 
-struct dmop_args {
-    domid_t domid;
-    unsigned int nr_bufs;
-    /* Reserve enough buf elements for all current hypercalls. */
-    struct xen_dm_op_buf buf[2];
-};
-
 static bool _raw_copy_from_guest_buf_offset(void *dst,
                                             const struct dmop_args *args,
                                             unsigned int buf_idx,
@@ -408,71 +402,6 @@ static int dm_op(const struct dmop_args *op_args)
 
     switch ( op.op )
     {
-    case XEN_DMOP_create_ioreq_server:
-    {
-        struct xen_dm_op_create_ioreq_server *data =
-            &op.u.create_ioreq_server;
-
-        const_op = false;
-
-        rc = -EINVAL;
-        if ( data->pad[0] || data->pad[1] || data->pad[2] )
-            break;
-
-        rc = hvm_create_ioreq_server(d, data->handle_bufioreq,
-                                     &data->id);
-        break;
-    }
-
-    case XEN_DMOP_get_ioreq_server_info:
-    {
-        struct xen_dm_op_get_ioreq_server_info *data =
-            &op.u.get_ioreq_server_info;
-        const uint16_t valid_flags = XEN_DMOP_no_gfns;
-
-        const_op = false;
-
-        rc = -EINVAL;
-        if ( data->flags & ~valid_flags )
-            break;
-
-        rc = hvm_get_ioreq_server_info(d, data->id,
-                                       (data->flags & XEN_DMOP_no_gfns) ?
-                                       NULL : &data->ioreq_gfn,
-                                       (data->flags & XEN_DMOP_no_gfns) ?
-                                       NULL : &data->bufioreq_gfn,
-                                       &data->bufioreq_port);
-        break;
-    }
-
-    case XEN_DMOP_map_io_range_to_ioreq_server:
-    {
-        const struct xen_dm_op_ioreq_server_range *data =
-            &op.u.map_io_range_to_ioreq_server;
-
-        rc = -EINVAL;
-        if ( data->pad )
-            break;
-
-        rc = hvm_map_io_range_to_ioreq_server(d, data->id, data->type,
-                                              data->start, data->end);
-        break;
-    }
-
-    case XEN_DMOP_unmap_io_range_from_ioreq_server:
-    {
-        const struct xen_dm_op_ioreq_server_range *data =
-            &op.u.unmap_io_range_from_ioreq_server;
-
-        rc = -EINVAL;
-        if ( data->pad )
-            break;
-
-        rc = hvm_unmap_io_range_from_ioreq_server(d, data->id, data->type,
-                                                  data->start, data->end);
-        break;
-    }
-
     case XEN_DMOP_map_mem_type_to_ioreq_server:
     {
         struct xen_dm_op_map_mem_type_to_ioreq_server *data =
@@ -523,32 +452,6 @@ static int dm_op(const struct dmop_args *op_args)
         break;
     }
 
-    case XEN_DMOP_set_ioreq_server_state:
-    {
-        const struct xen_dm_op_set_ioreq_server_state *data =
-            &op.u.set_ioreq_server_state;
-
-        rc = -EINVAL;
-        if ( data->pad )
-            break;
-
-        rc = hvm_set_ioreq_server_state(d, data->id, !!data->enabled);
-        break;
-    }
-
-    case XEN_DMOP_destroy_ioreq_server:
-    {
-        const struct xen_dm_op_destroy_ioreq_server *data =
-            &op.u.destroy_ioreq_server;
-
-        rc = -EINVAL;
-        if ( data->pad )
-            break;
-
-        rc = hvm_destroy_ioreq_server(d, data->id);
-        break;
-    }
-
     case XEN_DMOP_track_dirty_vram:
     {
         const struct xen_dm_op_track_dirty_vram *data =
@@ -703,7 +606,7 @@ static int dm_op(const struct dmop_args *op_args)
     }
 
     default:
-        rc = -EOPNOTSUPP;
+        rc = ioreq_server_dm_op(&op, d, &const_op);
         break;
     }
 
xen/common/ioreq.c +0 -0
index a319c88..72b5da0 100644

xen/common/ioreq.c static void hvm_ioreq_server_deinit(struct ioreq_server *s) · line 595

Quoted 7 lines
xen/common/ioreq.c +2 -2
@@ -591,8 +591,8 @@ static void hvm_ioreq_server_deinit(struct ioreq_server *s)
     put_domain(s->emulator);
 }
 
-int hvm_create_ioreq_server(struct domain *d, int bufioreq_handling,
-                            ioservid_t *id)
+static int hvm_create_ioreq_server(struct domain *d, int bufioreq_handling,
+                                   ioservid_t *id)

Would this not be a good opportunity to drop the 'hvm_' prefix (here and elsewhere)?

Paul

#54 lore raw

Re: [PATCH V4 09/24] xen/ioreq: Make x86's IOREQ related dm-op handling common

On 18.01.21 11:17, Paul Durrant wrote:

Hi Paul

Quoted 222 lines
Quoted 222 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Oleksandr Tyshchenko
Sent: 12 January 2021 21:52
To: [email protected]
Cc: Julien Grall <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Paul Durrant <[email protected]>; Daniel De Graaf <[email protected]>; Oleksandr Tyshchenko <[email protected]>
Subject: [PATCH V4 09/24] xen/ioreq: Make x86's IOREQ related dm-op handling common

From: Julien Grall <[email protected]>

As a lot of x86 code can be re-used on Arm later on, this patch moves the IOREQ related dm-op handling to the common code.

The idea is to have the top level dm-op handling arch-specific and call into ioreq_server_dm_op() for otherwise unhandled ops. Pros:
- More natural than doing it other way around (top level dm-op handling common).
- Leave compat_dm_op() in x86 code.
Cons:
- Code duplication. Both arches have to duplicate do_dm_op(), etc.

Also update XSM code a bit to let dm-op be used on Arm.

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

***
I decided to leave common dm.h to keep struct dmop_args declaration (to be included by Arm's dm.c), alternatively we could avoid introducing new header by moving the declaration into the existing header, but failed to find a suitable one which context would fit.
***

Changes RFC -> V1:
- update XSM, related changes were pulled from:
[RFC PATCH V1 04/12] xen/arm: Introduce arch specific bits for IOREQ/DM features

Changes V1 -> V2:
- update the author of a patch
- update patch description
- introduce xen/dm.h and move definitions here

Changes V2 -> V3:
- no changes

Changes V3 -> V4:
- rework to have the top level dm-op handling arch-specific
- update patch subject/description, was "xen/dm: Make x86's DM feature common"
- make a few functions static in common ioreq.c

---
  xen/arch/x86/hvm/dm.c   | 101 +-----------------------------------
  xen/common/ioreq.c      | 135 ++++++++++++++++++++++++++++++++++++++++++------
  xen/include/xen/dm.h    |  39 ++++++++++++++
  xen/include/xen/ioreq.h |  17 +-----
  xen/include/xsm/dummy.h |   4 +-
  xen/include/xsm/xsm.h   |   6 +--
  xen/xsm/dummy.c         |   2 +-
  xen/xsm/flask/hooks.c   |   5 +-
  8 files changed, 171 insertions(+), 138 deletions(-)

create mode 100644 xen/include/xen/dm.h

xen/arch/x86/hvm/dm.c +2 -99
index d3e2a9e..dc8e47d 100644
@@ -16,6 +16,7 @@
 
  #include <xen/event.h>
  #include <xen/guest_access.h>
+#include <xen/dm.h>
  #include <xen/hypercall.h>
  #include <xen/ioreq.h>
  #include <xen/nospec.h>
@@ -29,13 +30,6 @@
 
  #include <public/hvm/hvm_op.h>
 
-struct dmop_args {
-    domid_t domid;
-    unsigned int nr_bufs;
-    /* Reserve enough buf elements for all current hypercalls. */
-    struct xen_dm_op_buf buf[2];
-};
-
  static bool _raw_copy_from_guest_buf_offset(void *dst,
                                              const struct dmop_args *args,
                                              unsigned int buf_idx,
@@ -408,71 +402,6 @@ static int dm_op(const struct dmop_args *op_args)
 
      switch ( op.op )
      {
-    case XEN_DMOP_create_ioreq_server:
-    {
-        struct xen_dm_op_create_ioreq_server *data =
-            &op.u.create_ioreq_server;
-
-        const_op = false;
-
-        rc = -EINVAL;
-        if ( data->pad[0] || data->pad[1] || data->pad[2] )
-            break;
-
-        rc = hvm_create_ioreq_server(d, data->handle_bufioreq,
-                                     &data->id);
-        break;
-    }
-
-    case XEN_DMOP_get_ioreq_server_info:
-    {
-        struct xen_dm_op_get_ioreq_server_info *data =
-            &op.u.get_ioreq_server_info;
-        const uint16_t valid_flags = XEN_DMOP_no_gfns;
-
-        const_op = false;
-
-        rc = -EINVAL;
-        if ( data->flags & ~valid_flags )
-            break;
-
-        rc = hvm_get_ioreq_server_info(d, data->id,
-                                       (data->flags & XEN_DMOP_no_gfns) ?
-                                       NULL : &data->ioreq_gfn,
-                                       (data->flags & XEN_DMOP_no_gfns) ?
-                                       NULL : &data->bufioreq_gfn,
-                                       &data->bufioreq_port);
-        break;
-    }
-
-    case XEN_DMOP_map_io_range_to_ioreq_server:
-    {
-        const struct xen_dm_op_ioreq_server_range *data =
-            &op.u.map_io_range_to_ioreq_server;
-
-        rc = -EINVAL;
-        if ( data->pad )
-            break;
-
-        rc = hvm_map_io_range_to_ioreq_server(d, data->id, data->type,
-                                              data->start, data->end);
-        break;
-    }
-
-    case XEN_DMOP_unmap_io_range_from_ioreq_server:
-    {
-        const struct xen_dm_op_ioreq_server_range *data =
-            &op.u.unmap_io_range_from_ioreq_server;
-
-        rc = -EINVAL;
-        if ( data->pad )
-            break;
-
-        rc = hvm_unmap_io_range_from_ioreq_server(d, data->id, data->type,
-                                                  data->start, data->end);
-        break;
-    }
-
      case XEN_DMOP_map_mem_type_to_ioreq_server:
      {
          struct xen_dm_op_map_mem_type_to_ioreq_server *data =
@@ -523,32 +452,6 @@ static int dm_op(const struct dmop_args *op_args)
          break;
      }
 
-    case XEN_DMOP_set_ioreq_server_state:
-    {
-        const struct xen_dm_op_set_ioreq_server_state *data =
-            &op.u.set_ioreq_server_state;
-
-        rc = -EINVAL;
-        if ( data->pad )
-            break;
-
-        rc = hvm_set_ioreq_server_state(d, data->id, !!data->enabled);
-        break;
-    }
-
-    case XEN_DMOP_destroy_ioreq_server:
-    {
-        const struct xen_dm_op_destroy_ioreq_server *data =
-            &op.u.destroy_ioreq_server;
-
-        rc = -EINVAL;
-        if ( data->pad )
-            break;
-
-        rc = hvm_destroy_ioreq_server(d, data->id);
-        break;
-    }
-
      case XEN_DMOP_track_dirty_vram:
      {
          const struct xen_dm_op_track_dirty_vram *data =
@@ -703,7 +606,7 @@ static int dm_op(const struct dmop_args *op_args)
      }
 
      default:
-        rc = -EOPNOTSUPP;
+        rc = ioreq_server_dm_op(&op, d, &const_op);
          break;
      }
 
xen/common/ioreq.c +0 -0
index a319c88..72b5da0 100644
@@ -591,8 +591,8 @@ static void hvm_ioreq_server_deinit(struct ioreq_server *s)
      put_domain(s->emulator);
  }
 
Quoted 5 lines

xen/common/ioreq.c static void hvm_ioreq_server_deinit(struct ioreq_server *s) · line 595

Quoted 4 lines
xen/common/ioreq.c +2 -2
-int hvm_create_ioreq_server(struct domain *d, int bufioreq_handling,
-                            ioservid_t *id)
+static int hvm_create_ioreq_server(struct domain *d, int bufioreq_handling,
+                                   ioservid_t *id)

Would this not be a good opportunity to drop the 'hvm_' prefix (here and elsewhere)?

It would be, I will drop.

May I ask, are you ok with that alternative approach proposed by Jan and already implemented in current version (top level dm-op handling arch-specific and call into ioreq_server_dm_op() for otherwise unhandled ops)?

Initial discussion here:
https://lore.kernel.org/xen-devel/[email protected]/

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
#55 lore raw

RE: [PATCH V4 09/24] xen/ioreq: Make x86's IOREQ related dm-op handling common

Quoted 1 line

-----Original Message-----

[snip]

Quoted 14 lines
Quoted 8 lines
Quoted 8 lines
xen/common/ioreq.c +0 -0
index a319c88..72b5da0 100644
@@ -591,8 +591,8 @@ static void hvm_ioreq_server_deinit(struct ioreq_server *s)
      put_domain(s->emulator);
  }
 
Quoted 5 lines

xen/common/ioreq.c static void hvm_ioreq_server_deinit(struct ioreq_server *s) · line 595

Quoted 4 lines
xen/common/ioreq.c +2 -2
-int hvm_create_ioreq_server(struct domain *d, int bufioreq_handling,
-                            ioservid_t *id)
+static int hvm_create_ioreq_server(struct domain *d, int bufioreq_handling,
+                                   ioservid_t *id)

Would this not be a good opportunity to drop the 'hvm_' prefix (here and elsewhere)?

Quoted 8 lines

It would be, I will drop.

May I ask, are you ok with that alternative approach proposed by Jan and already implemented in current version (top level dm-op handling arch-specific
and call into ioreq_server_dm_op() for otherwise unhandled ops)?

Yes, I think per-arch hypercall handlers is the tidiest way to go.

Paul

Quoted 7 lines

Initial discussion here:
https://lore.kernel.org/xen-devel/[email protected]/

--
Regards,

Oleksandr Tyshchenko

Acked-by on v4 9/24
#56 lore raw

Re: [PATCH V4 09/24] xen/ioreq: Make x86's IOREQ related dm-op handling common

In reply to Oleksandr Tyshchenko
Quoted 16 lines · Oleksandr Tyshchenko

From: Julien Grall <[email protected]>

As a lot of x86 code can be re-used on Arm later on, this patch moves the IOREQ related dm-op handling to the common code.

The idea is to have the top level dm-op handling arch-specific and call into ioreq_server_dm_op() for otherwise unhandled ops. Pros:
- More natural than doing it other way around (top level dm-op handling common).
- Leave compat_dm_op() in x86 code.
Cons:
- Code duplication. Both arches have to duplicate do_dm_op(), etc.

Also update XSM code a bit to let dm-op be used on Arm.

Quoted 7 lines

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

Assuming the moved code is indeed just being moved (which is quite hard to ascertain by just looking at the diff), applicable parts

Jan

#57 lore raw

Re: [PATCH V4 09/24] xen/ioreq: Make x86's IOREQ related dm-op handling common

On 20.01.21 18:21, Jan Beulich wrote:

Hi Jan

Quoted 20 lines · Oleksandr Tyshchenko
Quoted 19 lines

From: Julien Grall <[email protected]>

As a lot of x86 code can be re-used on Arm later on, this patch moves the IOREQ related dm-op handling to the common code.

The idea is to have the top level dm-op handling arch-specific and call into ioreq_server_dm_op() for otherwise unhandled ops. Pros:
- More natural than doing it other way around (top level dm-op handling common).
- Leave compat_dm_op() in x86 code.
Cons:
- Code duplication. Both arches have to duplicate do_dm_op(), etc.

Also update XSM code a bit to let dm-op be used on Arm.

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

Quoted 6 lines
Quoted 4 lines

Assuming the moved code is indeed just being moved (which is quite hard to ascertain by just looking at the diff),

I have checked and will double-check again.

Quoted 2 lines

applicable parts

Thanks.

I would like to clarify regarding do_dm_op() which is identical for both arches and could *probably* be moved to the common code (we can return common dm.c back to put it there) and make dm_op() global. Would you/Paul be happy with that change? Or there are some reasons (which we are not aware of yet) for not doing it this way?

Initial discussion happened in [1] (which, let say, suffers from the duplication) and more precise in [2].

[1] https://lore.kernel.org/xen-devel/[email protected]/
[2] https://lore.kernel.org/xen-devel/alpine.DEB.2.21.2101191620050.14528@sstabellini-ThinkPad-T480s/

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
#58 lore raw

Re: [PATCH V4 09/24] xen/ioreq: Make x86's IOREQ related dm-op handling common

Quoted 5 lines · Oleksandr

I would like to clarify regarding do_dm_op() which is identical for both arches and could *probably* be moved to the common code (we can return common dm.c back to put it there) and make dm_op() global. Would you/Paul be happy with that change? Or there are some reasons (which we are not aware of yet) for not doing it this way?

Probably reasonable to do; the only reason not to that I could see is that then dm_op() has to become non-static.

Jan

#59 lore raw

Re: [PATCH V4 09/24] xen/ioreq: Make x86's IOREQ related dm-op handling common

On 21.01.21 12:27, Jan Beulich wrote:

Hi Jan

Quoted 8 lines · Oleksandr
Quoted 5 lines

I would like to clarify regarding do_dm_op() which is identical for both arches and could *probably* be moved to the common code (we can return common dm.c back to put it there) and make dm_op() global. Would you/Paul be happy with that change? Or there are some reasons (which we are not aware of yet) for not doing it this way?

Probably reasonable to do; the only reason not to that I could see is that then dm_op() has to become non-static.

Thank you for the clarification. So I will make this change for V5 if no objections during these days. I am going to leave your ack, please let me know if you think otherwise.

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
#60 lore raw

PATCH v4 10/24 xen/ioreq: Move x86's io_completion/io_req fields to struct vcpu

In reply to Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and these fields will be used on Arm as is. Move them to common struct vcpu as a part of new struct vcpu_io and drop duplicating "io" prefixes. Also move enum hvm_io_completion to xen/sched.h and remove "hvm" prefixes.

This patch completely removes layering violation in the common code.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes V1 -> V2:
- new patch

Changes V2 -> V3:
- update patch according the "legacy interface" is x86 specific
- update patch description
- drop the "io" prefixes from the field names
- wrap IO_realmode_completion

Changes V3 -> V4:
- rename all hvm_vcpu_io locals to "hvio"
- rename according to the new renaming scheme IO_ -> VIO_ (io_ -> vio_)
- drop "io" prefix from io_completion locals

---
 xen/arch/x86/hvm/emulate.c        | 210 +++++++++++++++++++-------------------
 xen/arch/x86/hvm/hvm.c            |   2 +-
 xen/arch/x86/hvm/io.c             |  32 +++---
 xen/arch/x86/hvm/ioreq.c          |   6 +-
 xen/arch/x86/hvm/svm/nestedsvm.c  |   2 +-
 xen/arch/x86/hvm/vmx/realmode.c   |   8 +-
 xen/common/ioreq.c                |  26 ++---
 xen/include/asm-x86/hvm/emulate.h |   2 +-
 xen/include/asm-x86/hvm/vcpu.h    |  11 --
 xen/include/xen/ioreq.h           |   2 +-
 xen/include/xen/sched.h           |  19 ++++
 11 files changed, 164 insertions(+), 156 deletions(-)
xen/arch/x86/hvm/emulate.c +105 -105
index 4d62199..21051ce 100644
@@ -140,15 +140,15 @@ static const struct hvm_io_handler ioreq_server_handler = {
  */
 void hvmemul_cancel(struct vcpu *v)
 {
-    struct hvm_vcpu_io *vio = &v->arch.hvm.hvm_io;
+    struct hvm_vcpu_io *hvio = &v->arch.hvm.hvm_io;
 
-    vio->io_req.state = STATE_IOREQ_NONE;
-    vio->io_completion = HVMIO_no_completion;
-    vio->mmio_cache_count = 0;
-    vio->mmio_insn_bytes = 0;
-    vio->mmio_access = (struct npfec){};
-    vio->mmio_retry = false;
-    vio->g2m_ioport = NULL;
+    v->io.req.state = STATE_IOREQ_NONE;
+    v->io.completion = VIO_no_completion;
+    hvio->mmio_cache_count = 0;
+    hvio->mmio_insn_bytes = 0;
+    hvio->mmio_access = (struct npfec){};
+    hvio->mmio_retry = false;
+    hvio->g2m_ioport = NULL;
 
     hvmemul_cache_disable(v);
 }
@@ -159,7 +159,7 @@ static int hvmemul_do_io(
 {
     struct vcpu *curr = current;
     struct domain *currd = curr->domain;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
+    struct vcpu_io *vio = &curr->io;
     ioreq_t p = {
         .type = is_mmio ? IOREQ_TYPE_COPY : IOREQ_TYPE_PIO,
         .addr = addr,
@@ -184,13 +184,13 @@ static int hvmemul_do_io(
         return X86EMUL_UNHANDLEABLE;
     }
 
-    switch ( vio->io_req.state )
+    switch ( vio->req.state )
     {
     case STATE_IOREQ_NONE:
         break;
     case STATE_IORESP_READY:
-        vio->io_req.state = STATE_IOREQ_NONE;
-        p = vio->io_req;
+        vio->req.state = STATE_IOREQ_NONE;
+        p = vio->req;
 
         /* Verify the emulation request has been correctly re-issued */
         if ( (p.type != (is_mmio ? IOREQ_TYPE_COPY : IOREQ_TYPE_PIO)) ||
@@ -238,7 +238,7 @@ static int hvmemul_do_io(
     }
     ASSERT(p.count);
 
-    vio->io_req = p;
+    vio->req = p;
 
     rc = hvm_io_intercept(&p);
 
@@ -247,12 +247,12 @@ static int hvmemul_do_io(
      * our callers and mirror this into latched state.
      */
     ASSERT(p.count <= *reps);
-    *reps = vio->io_req.count = p.count;
+    *reps = vio->req.count = p.count;
 
     switch ( rc )
     {
     case X86EMUL_OKAY:
-        vio->io_req.state = STATE_IOREQ_NONE;
+        vio->req.state = STATE_IOREQ_NONE;
         break;
     case X86EMUL_UNHANDLEABLE:
     {
@@ -305,7 +305,7 @@ static int hvmemul_do_io(
                 if ( s == NULL )
                 {
                     rc = X86EMUL_RETRY;
-                    vio->io_req.state = STATE_IOREQ_NONE;
+                    vio->req.state = STATE_IOREQ_NONE;
                     break;
                 }
 
@@ -316,7 +316,7 @@ static int hvmemul_do_io(
                 if ( dir == IOREQ_READ )
                 {
                     rc = hvm_process_io_intercept(&ioreq_server_handler, &p);
-                    vio->io_req.state = STATE_IOREQ_NONE;
+                    vio->req.state = STATE_IOREQ_NONE;
                     break;
                 }
             }
@@ -329,14 +329,14 @@ static int hvmemul_do_io(
         if ( !s )
         {
             rc = hvm_process_io_intercept(&null_handler, &p);
-            vio->io_req.state = STATE_IOREQ_NONE;
+            vio->req.state = STATE_IOREQ_NONE;
         }
         else
         {
             rc = hvm_send_ioreq(s, &p, 0);
             if ( rc != X86EMUL_RETRY || currd->is_shutting_down )
-                vio->io_req.state = STATE_IOREQ_NONE;
-            else if ( !ioreq_needs_completion(&vio->io_req) )
+                vio->req.state = STATE_IOREQ_NONE;
+            else if ( !ioreq_needs_completion(&vio->req) )
                 rc = X86EMUL_OKAY;
         }
         break;
@@ -1005,14 +1005,14 @@ static int hvmemul_phys_mmio_access(
  * cache indexed by linear MMIO address.
  */
 static struct hvm_mmio_cache *hvmemul_find_mmio_cache(
-    struct hvm_vcpu_io *vio, unsigned long gla, uint8_t dir, bool create)
+    struct hvm_vcpu_io *hvio, unsigned long gla, uint8_t dir, bool create)
 {
     unsigned int i;
     struct hvm_mmio_cache *cache;
 
-    for ( i = 0; i < vio->mmio_cache_count; i ++ )
+    for ( i = 0; i < hvio->mmio_cache_count; i ++ )
     {
-        cache = &vio->mmio_cache[i];
+        cache = &hvio->mmio_cache[i];
 
         if ( gla == cache->gla &&
              dir == cache->dir )
@@ -1022,13 +1022,13 @@ static struct hvm_mmio_cache *hvmemul_find_mmio_cache(
     if ( !create )
         return NULL;
 
-    i = vio->mmio_cache_count;
-    if( i == ARRAY_SIZE(vio->mmio_cache) )
+    i = hvio->mmio_cache_count;
+    if( i == ARRAY_SIZE(hvio->mmio_cache) )
         return NULL;
 
-    ++vio->mmio_cache_count;
+    ++hvio->mmio_cache_count;
 
-    cache = &vio->mmio_cache[i];
+    cache = &hvio->mmio_cache[i];
     memset(cache, 0, sizeof (*cache));
 
     cache->gla = gla;
@@ -1037,26 +1037,26 @@ static struct hvm_mmio_cache *hvmemul_find_mmio_cache(
     return cache;
 }
 
-static void latch_linear_to_phys(struct hvm_vcpu_io *vio, unsigned long gla,
+static void latch_linear_to_phys(struct hvm_vcpu_io *hvio, unsigned long gla,
                                  unsigned long gpa, bool_t write)
 {
-    if ( vio->mmio_access.gla_valid )
+    if ( hvio->mmio_access.gla_valid )
         return;
 
-    vio->mmio_gla = gla & PAGE_MASK;
-    vio->mmio_gpfn = PFN_DOWN(gpa);
-    vio->mmio_access = (struct npfec){ .gla_valid = 1,
-                                       .read_access = 1,
-                                       .write_access = write };
+    hvio->mmio_gla = gla & PAGE_MASK;
+    hvio->mmio_gpfn = PFN_DOWN(gpa);
+    hvio->mmio_access = (struct npfec){ .gla_valid = 1,
+                                        .read_access = 1,
+                                        .write_access = write };
 }
 
 static int hvmemul_linear_mmio_access(
     unsigned long gla, unsigned int size, uint8_t dir, void *buffer,
     uint32_t pfec, struct hvm_emulate_ctxt *hvmemul_ctxt, bool_t known_gpfn)
 {
-    struct hvm_vcpu_io *vio = &current->arch.hvm.hvm_io;
+    struct hvm_vcpu_io *hvio = &current->arch.hvm.hvm_io;
     unsigned long offset = gla & ~PAGE_MASK;
-    struct hvm_mmio_cache *cache = hvmemul_find_mmio_cache(vio, gla, dir, true);
+    struct hvm_mmio_cache *cache = hvmemul_find_mmio_cache(hvio, gla, dir, true);
     unsigned int chunk, buffer_offset = 0;
     paddr_t gpa;
     unsigned long one_rep = 1;
@@ -1068,7 +1068,7 @@ static int hvmemul_linear_mmio_access(
     chunk = min_t(unsigned int, size, PAGE_SIZE - offset);
 
     if ( known_gpfn )
-        gpa = pfn_to_paddr(vio->mmio_gpfn) | offset;
+        gpa = pfn_to_paddr(hvio->mmio_gpfn) | offset;
     else
     {
         rc = hvmemul_linear_to_phys(gla, &gpa, chunk, &one_rep, pfec,
@@ -1076,7 +1076,7 @@ static int hvmemul_linear_mmio_access(
         if ( rc != X86EMUL_OKAY )
             return rc;
 
-        latch_linear_to_phys(vio, gla, gpa, dir == IOREQ_WRITE);
+        latch_linear_to_phys(hvio, gla, gpa, dir == IOREQ_WRITE);
     }
 
     for ( ;; )
@@ -1122,22 +1122,22 @@ static inline int hvmemul_linear_mmio_write(
 
 static bool known_gla(unsigned long addr, unsigned int bytes, uint32_t pfec)
 {
-    const struct hvm_vcpu_io *vio = &current->arch.hvm.hvm_io;
+    const struct hvm_vcpu_io *hvio = &current->arch.hvm.hvm_io;
 
     if ( pfec & PFEC_write_access )
     {
-        if ( !vio->mmio_access.write_access )
+        if ( !hvio->mmio_access.write_access )
             return false;
     }
     else if ( pfec & PFEC_insn_fetch )
     {
-        if ( !vio->mmio_access.insn_fetch )
+        if ( !hvio->mmio_access.insn_fetch )
             return false;
     }
-    else if ( !vio->mmio_access.read_access )
+    else if ( !hvio->mmio_access.read_access )
             return false;
 
-    return (vio->mmio_gla == (addr & PAGE_MASK) &&
+    return (hvio->mmio_gla == (addr & PAGE_MASK) &&
             (addr & ~PAGE_MASK) + bytes <= PAGE_SIZE);
 }
 
@@ -1145,7 +1145,7 @@ static int linear_read(unsigned long addr, unsigned int bytes, void *p_data,
                        uint32_t pfec, struct hvm_emulate_ctxt *hvmemul_ctxt)
 {
     pagefault_info_t pfinfo;
-    struct hvm_vcpu_io *vio = &current->arch.hvm.hvm_io;
+    struct hvm_vcpu_io *hvio = &current->arch.hvm.hvm_io;
     unsigned int offset = addr & ~PAGE_MASK;
     int rc = HVMTRANS_bad_gfn_to_mfn;
 
@@ -1167,7 +1167,7 @@ static int linear_read(unsigned long addr, unsigned int bytes, void *p_data,
      * we handle this access in the same way to guarantee completion and hence
      * clean up any interim state.
      */
-    if ( !hvmemul_find_mmio_cache(vio, addr, IOREQ_READ, false) )
+    if ( !hvmemul_find_mmio_cache(hvio, addr, IOREQ_READ, false) )
         rc = hvm_copy_from_guest_linear(p_data, addr, bytes, pfec, &pfinfo);
 
     switch ( rc )
@@ -1200,7 +1200,7 @@ static int linear_write(unsigned long addr, unsigned int bytes, void *p_data,
                         uint32_t pfec, struct hvm_emulate_ctxt *hvmemul_ctxt)
 {
     pagefault_info_t pfinfo;
-    struct hvm_vcpu_io *vio = &current->arch.hvm.hvm_io;
+    struct hvm_vcpu_io *hvio = &current->arch.hvm.hvm_io;
     unsigned int offset = addr & ~PAGE_MASK;
     int rc = HVMTRANS_bad_gfn_to_mfn;
 
@@ -1222,7 +1222,7 @@ static int linear_write(unsigned long addr, unsigned int bytes, void *p_data,
      * we handle this access in the same way to guarantee completion and hence
      * clean up any interim state.
      */
-    if ( !hvmemul_find_mmio_cache(vio, addr, IOREQ_WRITE, false) )
+    if ( !hvmemul_find_mmio_cache(hvio, addr, IOREQ_WRITE, false) )
         rc = hvm_copy_to_guest_linear(addr, p_data, bytes, pfec, &pfinfo);
 
     switch ( rc )
@@ -1599,7 +1599,7 @@ static int hvmemul_cmpxchg(
     struct vcpu *curr = current;
     unsigned long addr;
     uint32_t pfec = PFEC_page_present | PFEC_write_access;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
+    struct hvm_vcpu_io *hvio = &curr->arch.hvm.hvm_io;
     int rc;
     void *mapping = NULL;
 
@@ -1625,8 +1625,8 @@ static int hvmemul_cmpxchg(
         /* Fix this in case the guest is really relying on r-m-w atomicity. */
         return hvmemul_linear_mmio_write(addr, bytes, p_new, pfec,
                                          hvmemul_ctxt,
-                                         vio->mmio_access.write_access &&
-                                         vio->mmio_gla == (addr & PAGE_MASK));
+                                         hvio->mmio_access.write_access &&
+                                         hvio->mmio_gla == (addr & PAGE_MASK));
     }
 
     switch ( bytes )
@@ -1823,7 +1823,7 @@ static int hvmemul_rep_movs(
     struct hvm_emulate_ctxt *hvmemul_ctxt =
         container_of(ctxt, struct hvm_emulate_ctxt, ctxt);
     struct vcpu *curr = current;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
+    struct hvm_vcpu_io *hvio = &curr->arch.hvm.hvm_io;
     unsigned long saddr, daddr, bytes;
     paddr_t sgpa, dgpa;
     uint32_t pfec = PFEC_page_present;
@@ -1846,18 +1846,18 @@ static int hvmemul_rep_movs(
     if ( hvmemul_ctxt->seg_reg[x86_seg_ss].dpl == 3 )
         pfec |= PFEC_user_mode;
 
-    if ( vio->mmio_access.read_access &&
-         (vio->mmio_gla == (saddr & PAGE_MASK)) &&
+    if ( hvio->mmio_access.read_access &&
+         (hvio->mmio_gla == (saddr & PAGE_MASK)) &&
          /*
           * Upon initial invocation don't truncate large batches just because
           * of a hit for the translation: Doing the guest page table walk is
           * cheaper than multiple round trips through the device model. Yet
           * when processing a response we can always re-use the translation.
           */
-         (vio->io_req.state == STATE_IORESP_READY ||
+         (curr->io.req.state == STATE_IORESP_READY ||
           ((!df || *reps == 1) &&
            PAGE_SIZE - (saddr & ~PAGE_MASK) >= *reps * bytes_per_rep)) )
-        sgpa = pfn_to_paddr(vio->mmio_gpfn) | (saddr & ~PAGE_MASK);
+        sgpa = pfn_to_paddr(hvio->mmio_gpfn) | (saddr & ~PAGE_MASK);
     else
     {
         rc = hvmemul_linear_to_phys(saddr, &sgpa, bytes_per_rep, reps, pfec,
@@ -1867,13 +1867,13 @@ static int hvmemul_rep_movs(
     }
 
     bytes = PAGE_SIZE - (daddr & ~PAGE_MASK);
-    if ( vio->mmio_access.write_access &&
-         (vio->mmio_gla == (daddr & PAGE_MASK)) &&
+    if ( hvio->mmio_access.write_access &&
+         (hvio->mmio_gla == (daddr & PAGE_MASK)) &&
          /* See comment above. */
-         (vio->io_req.state == STATE_IORESP_READY ||
+         (curr->io.req.state == STATE_IORESP_READY ||
           ((!df || *reps == 1) &&
            PAGE_SIZE - (daddr & ~PAGE_MASK) >= *reps * bytes_per_rep)) )
-        dgpa = pfn_to_paddr(vio->mmio_gpfn) | (daddr & ~PAGE_MASK);
+        dgpa = pfn_to_paddr(hvio->mmio_gpfn) | (daddr & ~PAGE_MASK);
     else
     {
         rc = hvmemul_linear_to_phys(daddr, &dgpa, bytes_per_rep, reps,
@@ -1892,14 +1892,14 @@ static int hvmemul_rep_movs(
 
     if ( sp2mt == p2m_mmio_dm )
     {
-        latch_linear_to_phys(vio, saddr, sgpa, 0);
+        latch_linear_to_phys(hvio, saddr, sgpa, 0);
         return hvmemul_do_mmio_addr(
             sgpa, reps, bytes_per_rep, IOREQ_READ, df, dgpa);
     }
 
     if ( dp2mt == p2m_mmio_dm )
     {
-        latch_linear_to_phys(vio, daddr, dgpa, 1);
+        latch_linear_to_phys(hvio, daddr, dgpa, 1);
         return hvmemul_do_mmio_addr(
             dgpa, reps, bytes_per_rep, IOREQ_WRITE, df, sgpa);
     }
@@ -1992,7 +1992,7 @@ static int hvmemul_rep_stos(
     struct hvm_emulate_ctxt *hvmemul_ctxt =
         container_of(ctxt, struct hvm_emulate_ctxt, ctxt);
     struct vcpu *curr = current;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
+    struct hvm_vcpu_io *hvio = &curr->arch.hvm.hvm_io;
     unsigned long addr, bytes;
     paddr_t gpa;
     p2m_type_t p2mt;
@@ -2004,13 +2004,13 @@ static int hvmemul_rep_stos(
         return rc;
 
     bytes = PAGE_SIZE - (addr & ~PAGE_MASK);
-    if ( vio->mmio_access.write_access &&
-         (vio->mmio_gla == (addr & PAGE_MASK)) &&
+    if ( hvio->mmio_access.write_access &&
+         (hvio->mmio_gla == (addr & PAGE_MASK)) &&
          /* See respective comment in MOVS processing. */
-         (vio->io_req.state == STATE_IORESP_READY ||
+         (curr->io.req.state == STATE_IORESP_READY ||
           ((!df || *reps == 1) &&
            PAGE_SIZE - (addr & ~PAGE_MASK) >= *reps * bytes_per_rep)) )
-        gpa = pfn_to_paddr(vio->mmio_gpfn) | (addr & ~PAGE_MASK);
+        gpa = pfn_to_paddr(hvio->mmio_gpfn) | (addr & ~PAGE_MASK);
     else
     {
         uint32_t pfec = PFEC_page_present | PFEC_write_access;
@@ -2103,7 +2103,7 @@ static int hvmemul_rep_stos(
         return X86EMUL_UNHANDLEABLE;
 
     case p2m_mmio_dm:
-        latch_linear_to_phys(vio, addr, gpa, 1);
+        latch_linear_to_phys(hvio, addr, gpa, 1);
         return hvmemul_do_mmio_buffer(gpa, reps, bytes_per_rep, IOREQ_WRITE, df,
                                       p_data);
     }
@@ -2613,18 +2613,18 @@ static const struct x86_emulate_ops hvm_emulate_ops_no_write = {
 };
 
 /*
- * Note that passing HVMIO_no_completion into this function serves as kind
+ * Note that passing VIO_no_completion into this function serves as kind
  * of (but not fully) an "auto select completion" indicator.  When there's
  * no completion needed, the passed in value will be ignored in any case.
  */
 static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
     const struct x86_emulate_ops *ops,
-    enum hvm_io_completion completion)
+    enum vio_completion completion)
 {
     const struct cpu_user_regs *regs = hvmemul_ctxt->ctxt.regs;
     struct vcpu *curr = current;
     uint32_t new_intr_shadow;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
+    struct hvm_vcpu_io *hvio = &curr->arch.hvm.hvm_io;
     int rc;
 
     /*
@@ -2632,45 +2632,45 @@ static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
      * untouched if it's already enabled, for re-execution to consume
      * entries populated by an earlier pass.
      */
-    if ( vio->cache->num_ents > vio->cache->max_ents )
+    if ( hvio->cache->num_ents > hvio->cache->max_ents )
     {
-        ASSERT(vio->io_req.state == STATE_IOREQ_NONE);
-        vio->cache->num_ents = 0;
+        ASSERT(curr->io.req.state == STATE_IOREQ_NONE);
+        hvio->cache->num_ents = 0;
     }
     else
-        ASSERT(vio->io_req.state == STATE_IORESP_READY);
+        ASSERT(curr->io.req.state == STATE_IORESP_READY);
 
-    hvm_emulate_init_per_insn(hvmemul_ctxt, vio->mmio_insn,
-                              vio->mmio_insn_bytes);
+    hvm_emulate_init_per_insn(hvmemul_ctxt, hvio->mmio_insn,
+                              hvio->mmio_insn_bytes);
 
-    vio->mmio_retry = 0;
+    hvio->mmio_retry = 0;
 
     rc = x86_emulate(&hvmemul_ctxt->ctxt, ops);
-    if ( rc == X86EMUL_OKAY && vio->mmio_retry )
+    if ( rc == X86EMUL_OKAY && hvio->mmio_retry )
         rc = X86EMUL_RETRY;
 
-    if ( !ioreq_needs_completion(&vio->io_req) )
-        completion = HVMIO_no_completion;
-    else if ( completion == HVMIO_no_completion )
-        completion = (vio->io_req.type != IOREQ_TYPE_PIO ||
-                      hvmemul_ctxt->is_mem_access) ? HVMIO_mmio_completion
-                                                   : HVMIO_pio_completion;
+    if ( !ioreq_needs_completion(&curr->io.req) )
+        completion = VIO_no_completion;
+    else if ( completion == VIO_no_completion )
+        completion = (curr->io.req.type != IOREQ_TYPE_PIO ||
+                      hvmemul_ctxt->is_mem_access) ? VIO_mmio_completion
+                                                   : VIO_pio_completion;
 
-    switch ( vio->io_completion = completion )
+    switch ( curr->io.completion = completion )
     {
-    case HVMIO_no_completion:
-    case HVMIO_pio_completion:
-        vio->mmio_cache_count = 0;
-        vio->mmio_insn_bytes = 0;
-        vio->mmio_access = (struct npfec){};
+    case VIO_no_completion:
+    case VIO_pio_completion:
+        hvio->mmio_cache_count = 0;
+        hvio->mmio_insn_bytes = 0;
+        hvio->mmio_access = (struct npfec){};
         hvmemul_cache_disable(curr);
         break;
 
-    case HVMIO_mmio_completion:
-    case HVMIO_realmode_completion:
-        BUILD_BUG_ON(sizeof(vio->mmio_insn) < sizeof(hvmemul_ctxt->insn_buf));
-        vio->mmio_insn_bytes = hvmemul_ctxt->insn_buf_bytes;
-        memcpy(vio->mmio_insn, hvmemul_ctxt->insn_buf, vio->mmio_insn_bytes);
+    case VIO_mmio_completion:
+    case VIO_realmode_completion:
+        BUILD_BUG_ON(sizeof(hvio->mmio_insn) < sizeof(hvmemul_ctxt->insn_buf));
+        hvio->mmio_insn_bytes = hvmemul_ctxt->insn_buf_bytes;
+        memcpy(hvio->mmio_insn, hvmemul_ctxt->insn_buf, hvio->mmio_insn_bytes);
         break;
 
     default:
@@ -2716,7 +2716,7 @@ static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
 
 int hvm_emulate_one(
     struct hvm_emulate_ctxt *hvmemul_ctxt,
-    enum hvm_io_completion completion)
+    enum vio_completion completion)
 {
     return _hvm_emulate_one(hvmemul_ctxt, &hvm_emulate_ops, completion);
 }
@@ -2754,7 +2754,7 @@ int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)
                           guest_cpu_user_regs());
     ctxt.ctxt.data = &mmio_ro_ctxt;
 
-    switch ( rc = _hvm_emulate_one(&ctxt, ops, HVMIO_no_completion) )
+    switch ( rc = _hvm_emulate_one(&ctxt, ops, VIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
     case X86EMUL_UNIMPLEMENTED:
@@ -2782,28 +2782,28 @@ void hvm_emulate_one_vm_event(enum emul_kind kind, unsigned int trapnr,
     {
     case EMUL_KIND_NOWRITE:
         rc = _hvm_emulate_one(&ctx, &hvm_emulate_ops_no_write,
-                              HVMIO_no_completion);
+                              VIO_no_completion);
         break;
     case EMUL_KIND_SET_CONTEXT_INSN: {
         struct vcpu *curr = current;
-        struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
+        struct hvm_vcpu_io *hvio = &curr->arch.hvm.hvm_io;
 
-        BUILD_BUG_ON(sizeof(vio->mmio_insn) !=
+        BUILD_BUG_ON(sizeof(hvio->mmio_insn) !=
                      sizeof(curr->arch.vm_event->emul.insn.data));
-        ASSERT(!vio->mmio_insn_bytes);
+        ASSERT(!hvio->mmio_insn_bytes);
 
         /*
          * Stash insn buffer into mmio buffer here instead of ctx
          * to avoid having to add more logic to hvm_emulate_one.
          */
-        vio->mmio_insn_bytes = sizeof(vio->mmio_insn);
-        memcpy(vio->mmio_insn, curr->arch.vm_event->emul.insn.data,
-               vio->mmio_insn_bytes);
+        hvio->mmio_insn_bytes = sizeof(hvio->mmio_insn);
+        memcpy(hvio->mmio_insn, curr->arch.vm_event->emul.insn.data,
+               hvio->mmio_insn_bytes);
     }
     /* Fall-through */
     default:
         ctx.set_context = (kind == EMUL_KIND_SET_CONTEXT_DATA);
-        rc = hvm_emulate_one(&ctx, HVMIO_no_completion);
+        rc = hvm_emulate_one(&ctx, VIO_no_completion);
     }
 
     switch ( rc )
xen/arch/x86/hvm/hvm.c +1 -1
index bc96947..4ed929c 100644
@@ -3800,7 +3800,7 @@ void hvm_ud_intercept(struct cpu_user_regs *regs)
         return;
     }
 
-    switch ( hvm_emulate_one(&ctxt, HVMIO_no_completion) )
+    switch ( hvm_emulate_one(&ctxt, VIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
     case X86EMUL_UNIMPLEMENTED:
xen/arch/x86/hvm/io.c +16 -16
index ef8286b..dd733e1 100644
@@ -85,7 +85,7 @@ bool hvm_emulate_one_insn(hvm_emulate_validate_t *validate, const char *descr)
 
     hvm_emulate_init_once(&ctxt, validate, guest_cpu_user_regs());
 
-    switch ( rc = hvm_emulate_one(&ctxt, HVMIO_no_completion) )
+    switch ( rc = hvm_emulate_one(&ctxt, VIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
         hvm_dump_emulation_state(XENLOG_G_WARNING, descr, &ctxt, rc);
@@ -109,20 +109,20 @@ bool hvm_emulate_one_insn(hvm_emulate_validate_t *validate, const char *descr)
 bool handle_mmio_with_translation(unsigned long gla, unsigned long gpfn,
                                   struct npfec access)
 {
-    struct hvm_vcpu_io *vio = &current->arch.hvm.hvm_io;
+    struct hvm_vcpu_io *hvio = &current->arch.hvm.hvm_io;
 
-    vio->mmio_access = access.gla_valid &&
-                       access.kind == npfec_kind_with_gla
-                       ? access : (struct npfec){};
-    vio->mmio_gla = gla & PAGE_MASK;
-    vio->mmio_gpfn = gpfn;
+    hvio->mmio_access = access.gla_valid &&
+                        access.kind == npfec_kind_with_gla
+                        ? access : (struct npfec){};
+    hvio->mmio_gla = gla & PAGE_MASK;
+    hvio->mmio_gpfn = gpfn;
     return handle_mmio();
 }
 
 bool handle_pio(uint16_t port, unsigned int size, int dir)
 {
     struct vcpu *curr = current;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
+    struct vcpu_io *vio = &curr->io;
     unsigned int data;
     int rc;
 
@@ -135,8 +135,8 @@ bool handle_pio(uint16_t port, unsigned int size, int dir)
 
     rc = hvmemul_do_pio_buffer(port, size, dir, &data);
 
-    if ( ioreq_needs_completion(&vio->io_req) )
-        vio->io_completion = HVMIO_pio_completion;
+    if ( ioreq_needs_completion(&vio->req) )
+        vio->completion = VIO_pio_completion;
 
     switch ( rc )
     {
@@ -175,7 +175,7 @@ static bool_t g2m_portio_accept(const struct hvm_io_handler *handler,
 {
     struct vcpu *curr = current;
     const struct hvm_domain *hvm = &curr->domain->arch.hvm;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
+    struct hvm_vcpu_io *hvio = &curr->arch.hvm.hvm_io;
     struct g2m_ioport *g2m_ioport;
     unsigned int start, end;
 
@@ -185,7 +185,7 @@ static bool_t g2m_portio_accept(const struct hvm_io_handler *handler,
         end = start + g2m_ioport->np;
         if ( (p->addr >= start) && (p->addr + p->size <= end) )
         {
-            vio->g2m_ioport = g2m_ioport;
+            hvio->g2m_ioport = g2m_ioport;
             return 1;
         }
     }
@@ -196,8 +196,8 @@ static bool_t g2m_portio_accept(const struct hvm_io_handler *handler,
 static int g2m_portio_read(const struct hvm_io_handler *handler,
                            uint64_t addr, uint32_t size, uint64_t *data)
 {
-    struct hvm_vcpu_io *vio = &current->arch.hvm.hvm_io;
-    const struct g2m_ioport *g2m_ioport = vio->g2m_ioport;
+    struct hvm_vcpu_io *hvio = &current->arch.hvm.hvm_io;
+    const struct g2m_ioport *g2m_ioport = hvio->g2m_ioport;
     unsigned int mport = (addr - g2m_ioport->gport) + g2m_ioport->mport;
 
     switch ( size )
@@ -221,8 +221,8 @@ static int g2m_portio_read(const struct hvm_io_handler *handler,
 static int g2m_portio_write(const struct hvm_io_handler *handler,
                             uint64_t addr, uint32_t size, uint64_t data)
 {
-    struct hvm_vcpu_io *vio = &current->arch.hvm.hvm_io;
-    const struct g2m_ioport *g2m_ioport = vio->g2m_ioport;
+    struct hvm_vcpu_io *hvio = &current->arch.hvm.hvm_io;
+    const struct g2m_ioport *g2m_ioport = hvio->g2m_ioport;
     unsigned int mport = (addr - g2m_ioport->gport) + g2m_ioport->mport;
 
     switch ( size )
xen/arch/x86/hvm/ioreq.c +3 -3
index 8393922..c00ee8e 100644
@@ -40,11 +40,11 @@ bool arch_ioreq_complete_mmio(void)
     return handle_mmio();
 }
 
-bool arch_vcpu_ioreq_completion(enum hvm_io_completion io_completion)
+bool arch_vcpu_ioreq_completion(enum vio_completion completion)
 {
-    switch ( io_completion )
+    switch ( completion )
     {
-    case HVMIO_realmode_completion:
+    case VIO_realmode_completion:
     {
         struct hvm_emulate_ctxt ctxt;
 
xen/arch/x86/hvm/svm/nestedsvm.c +1 -1
index fcfccf7..6d90630 100644
@@ -1266,7 +1266,7 @@ enum hvm_intblk nsvm_intr_blocked(struct vcpu *v)
          * Delay the injection because this would result in delivering
          * an interrupt *within* the execution of an instruction.
          */
-        if ( v->arch.hvm.hvm_io.io_req.state != STATE_IOREQ_NONE )
+        if ( v->io.req.state != STATE_IOREQ_NONE )
             return hvm_intblk_shadow;
 
         if ( !nv->nv_vmexit_pending && n2vmcb->exit_int_info.v )
xen/arch/x86/hvm/vmx/realmode.c +4 -4
index 768f01e..cc23afa 100644
@@ -101,7 +101,7 @@ void vmx_realmode_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt)
 
     perfc_incr(realmode_emulations);
 
-    rc = hvm_emulate_one(hvmemul_ctxt, HVMIO_realmode_completion);
+    rc = hvm_emulate_one(hvmemul_ctxt, VIO_realmode_completion);
 
     if ( rc == X86EMUL_UNHANDLEABLE )
     {
@@ -153,7 +153,7 @@ void vmx_realmode(struct cpu_user_regs *regs)
     struct vcpu *curr = current;
     struct hvm_emulate_ctxt hvmemul_ctxt;
     struct segment_register *sreg;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
+    struct hvm_vcpu_io *hvio = &curr->arch.hvm.hvm_io;
     unsigned long intr_info;
     unsigned int emulations = 0;
 
@@ -188,7 +188,7 @@ void vmx_realmode(struct cpu_user_regs *regs)
 
         vmx_realmode_emulate_one(&hvmemul_ctxt);
 
-        if ( vio->io_req.state != STATE_IOREQ_NONE || vio->mmio_retry )
+        if ( curr->io.req.state != STATE_IOREQ_NONE || hvio->mmio_retry )
             break;
 
         /* Stop emulating unless our segment state is not safe */
@@ -202,7 +202,7 @@ void vmx_realmode(struct cpu_user_regs *regs)
     }
 
     /* Need to emulate next time if we've started an IO operation */
-    if ( vio->io_req.state != STATE_IOREQ_NONE )
+    if ( curr->io.req.state != STATE_IOREQ_NONE )
         curr->arch.hvm.vmx.vmx_emulate = 1;
 
     if ( !curr->arch.hvm.vmx.vmx_emulate && !curr->arch.hvm.vmx.vmx_realmode )
xen/common/ioreq.c +13 -13
index 72b5da0..273683f 100644
@@ -159,7 +159,7 @@ static bool hvm_wait_for_io(struct ioreq_vcpu *sv, ioreq_t *p)
         break;
     }
 
-    p = &sv->vcpu->arch.hvm.hvm_io.io_req;
+    p = &sv->vcpu->io.req;
     if ( ioreq_needs_completion(p) )
         p->data = data;
 
@@ -171,10 +171,10 @@ static bool hvm_wait_for_io(struct ioreq_vcpu *sv, ioreq_t *p)
 bool handle_hvm_io_completion(struct vcpu *v)
 {
     struct domain *d = v->domain;
-    struct hvm_vcpu_io *vio = &v->arch.hvm.hvm_io;
+    struct vcpu_io *vio = &v->io;
     struct ioreq_server *s;
     struct ioreq_vcpu *sv;
-    enum hvm_io_completion io_completion;
+    enum vio_completion completion;
 
     if ( has_vpci(d) && vpci_process_pending(v) )
     {
@@ -186,29 +186,29 @@ bool handle_hvm_io_completion(struct vcpu *v)
     if ( sv && !hvm_wait_for_io(sv, get_ioreq(s, v)) )
         return false;
 
-    vio->io_req.state = ioreq_needs_completion(&vio->io_req) ?
+    vio->req.state = ioreq_needs_completion(&vio->req) ?
         STATE_IORESP_READY : STATE_IOREQ_NONE;
 
     msix_write_completion(v);
     vcpu_end_shutdown_deferral(v);
 
-    io_completion = vio->io_completion;
-    vio->io_completion = HVMIO_no_completion;
+    completion = vio->completion;
+    vio->completion = VIO_no_completion;
 
-    switch ( io_completion )
+    switch ( completion )
     {
-    case HVMIO_no_completion:
+    case VIO_no_completion:
         break;
 
-    case HVMIO_mmio_completion:
+    case VIO_mmio_completion:
         return arch_ioreq_complete_mmio();
 
-    case HVMIO_pio_completion:
-        return handle_pio(vio->io_req.addr, vio->io_req.size,
-                          vio->io_req.dir);
+    case VIO_pio_completion:
+        return handle_pio(vio->req.addr, vio->req.size,
+                          vio->req.dir);
 
     default:
-        return arch_vcpu_ioreq_completion(io_completion);
+        return arch_vcpu_ioreq_completion(completion);
     }
 
     return true;
xen/include/asm-x86/hvm/emulate.h +1 -1
index 1620cc7..610078b 100644
@@ -65,7 +65,7 @@ bool __nonnull(1, 2) hvm_emulate_one_insn(
     const char *descr);
 int hvm_emulate_one(
     struct hvm_emulate_ctxt *hvmemul_ctxt,
-    enum hvm_io_completion completion);
+    enum vio_completion completion);
 void hvm_emulate_one_vm_event(enum emul_kind kind,
     unsigned int trapnr,
     unsigned int errcode);
xen/include/asm-x86/hvm/vcpu.h +0 -11
index 6c1feda..8adf455 100644
@@ -28,13 +28,6 @@
 #include <asm/mtrr.h>
 #include <public/hvm/ioreq.h>
 
-enum hvm_io_completion {
-    HVMIO_no_completion,
-    HVMIO_mmio_completion,
-    HVMIO_pio_completion,
-    HVMIO_realmode_completion
-};
-
 struct hvm_vcpu_asid {
     uint64_t generation;
     uint32_t asid;
@@ -52,10 +45,6 @@ struct hvm_mmio_cache {
 };
 
 struct hvm_vcpu_io {
-    /* I/O request in flight to device model. */
-    enum hvm_io_completion io_completion;
-    ioreq_t                io_req;
-
     /*
      * HVM emulation:
      *  Linear address @mmio_gla maps to MMIO physical frame @mmio_gpfn.
xen/include/xen/ioreq.h +1 -1
index 7a90873..dffed60 100644
@@ -105,7 +105,7 @@ void hvm_ioreq_init(struct domain *d);
 int ioreq_server_dm_op(struct xen_dm_op *op, struct domain *d, bool *const_op);
 
 bool arch_ioreq_complete_mmio(void);
-bool arch_vcpu_ioreq_completion(enum hvm_io_completion io_completion);
+bool arch_vcpu_ioreq_completion(enum vio_completion completion);
 int arch_ioreq_server_map_pages(struct ioreq_server *s);
 void arch_ioreq_server_unmap_pages(struct ioreq_server *s);
 void arch_ioreq_server_enable(struct ioreq_server *s);
xen/include/xen/sched.h +19 -0
index ad0d761..7aea2bb 100644
@@ -147,6 +147,21 @@ void evtchn_destroy_final(struct domain *d); /* from complete_domain_destroy */
 
 struct waitqueue_vcpu;
 
+enum vio_completion {
+    VIO_no_completion,
+    VIO_mmio_completion,
+    VIO_pio_completion,
+#ifdef CONFIG_X86
+    VIO_realmode_completion,
+#endif
+};
+
+struct vcpu_io {
+    /* I/O request in flight to device model. */
+    enum vio_completion  completion;
+    ioreq_t              req;
+};
+
 struct vcpu
 {
     int              vcpu_id;
@@ -258,6 +273,10 @@ struct vcpu
     struct vpci_vcpu vpci;
 
     struct arch_vcpu arch;
+
+#ifdef CONFIG_IOREQ_SERVER
+    struct vcpu_io io;
+#endif
 };
 
 struct sched_unit {
Signature · 1 line
2.7.4
Reviewed-by on v4 10/24
#61 lore raw

Re: [PATCH V4 10/24] xen/ioreq: Move x86's io_completion/io_req fields to struct vcpu

Hi Oleksandr,

Quoted 7 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and these fields will be used on Arm as is. Move them to common struct vcpu as a part of new struct vcpu_io and drop duplicating "io" prefixes. Also move enum hvm_io_completion to xen/sched.h and remove "hvm" prefixes.

Quoted 6 lines

This patch completely removes layering violation in the common code.

Cheers,

Signature · 1 line
Julien Grall
Reviewed-by on v4 10/24
#62 lore raw

RE: [PATCH V4 10/24] xen/ioreq: Move x86's io_completion/io_req fields to struct vcpu

In reply to Oleksandr Tyshchenko
Quoted 14 lines

-----Original Message-----
From: Oleksandr Tyshchenko <[email protected]>
Sent: 12 January 2021 21:52
To: [email protected]
Cc: Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Jun Nakajima <[email protected]>; Kevin Tian <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH V4 10/24] xen/ioreq: Move x86's io_completion/io_req fields to struct vcpu

From: Oleksandr Tyshchenko <[email protected]>

Quoted 8 lines

The IOREQ is a common feature now and these fields will be used on Arm as is. Move them to common struct vcpu as a part of new struct vcpu_io and drop duplicating "io" prefixes. Also move enum hvm_io_completion to xen/sched.h and remove "hvm" prefixes.

This patch completely removes layering violation in the common code.

Acked-by on v4 10/24
#63 lore raw

Re: [PATCH V4 10/24] xen/ioreq: Move x86's io_completion/io_req fields to struct vcpu

In reply to Oleksandr Tyshchenko
Quoted 7 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The IOREQ is a common feature now and these fields will be used on Arm as is. Move them to common struct vcpu as a part of new struct vcpu_io and drop duplicating "io" prefixes. Also move enum hvm_io_completion to xen/sched.h and remove "hvm" prefixes.

Quoted 6 lines

This patch completely removes layering violation in the common code.

Applicable parts

Jan

#64 lore raw

PATCH v4 11/24 xen/mm: Make x86's XENMEM_resource_ioreq_server handling common

In reply to Oleksandr Tyshchenko

From: Julien Grall <[email protected]>

As x86 implementation of XENMEM_resource_ioreq_server can be re-used on Arm later on, this patch makes it common and removes arch_acquire_resource as unneeded.

Also re-order #include-s alphabetically.

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- no changes

Changes V1 -> V2:
- update the author of a patch

Changes V2 -> V3:
- don't wrap #include <xen/ioreq.h>
- limit the number of #ifdef-s
- re-order #include-s alphabetically

Changes V3 -> V4:
- rebase
- Add Jan's R-b

---
 xen/arch/x86/mm.c        | 44 ---------------------------------
 xen/common/memory.c      | 63 +++++++++++++++++++++++++++++++++++++++---------
 xen/include/asm-arm/mm.h |  8 ------
 xen/include/asm-x86/mm.h |  4 ---
 4 files changed, 51 insertions(+), 68 deletions(-)
xen/arch/x86/mm.c +0 -44
index f6e128e..54ac398 100644
@@ -4587,50 +4587,6 @@ static int handle_iomem_range(unsigned long s, unsigned long e, void *p)
     return err || s > e ? err : _handle_iomem_range(s, e, p);
 }
 
-int arch_acquire_resource(struct domain *d, unsigned int type,
-                          unsigned int id, unsigned long frame,
-                          unsigned int nr_frames, xen_pfn_t mfn_list[])
-{
-    int rc;
-
-    switch ( type )
-    {
-#ifdef CONFIG_HVM
-    case XENMEM_resource_ioreq_server:
-    {
-        ioservid_t ioservid = id;
-        unsigned int i;
-
-        rc = -EINVAL;
-        if ( !is_hvm_domain(d) )
-            break;
-
-        if ( id != (unsigned int)ioservid )
-            break;
-
-        rc = 0;
-        for ( i = 0; i < nr_frames; i++ )
-        {
-            mfn_t mfn;
-
-            rc = hvm_get_ioreq_server_frame(d, id, frame + i, &mfn);
-            if ( rc )
-                break;
-
-            mfn_list[i] = mfn_x(mfn);
-        }
-        break;
-    }
-#endif
-
-    default:
-        rc = -EOPNOTSUPP;
-        break;
-    }
-
-    return rc;
-}
-
 long arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     int rc;
xen/common/memory.c +51 -12

88 lines not on this page · raw message

xen/include/asm-arm/mm.h +0 -8
index f8ba49b..0b7de31 100644
@@ -358,14 +358,6 @@ static inline void put_page_and_type(struct page_info *page)
 
 void clear_and_clean_page(struct page_info *page);
 
-static inline
-int arch_acquire_resource(struct domain *d, unsigned int type, unsigned int id,
-                          unsigned long frame, unsigned int nr_frames,
-                          xen_pfn_t mfn_list[])
-{
-    return -EOPNOTSUPP;
-}
-
 unsigned int arch_get_dma_bitsize(void);
 
 #endif /*  __ARCH_ARM_MM__ */
xen/include/asm-x86/mm.h +0 -4
index deeba75..859214e 100644
@@ -639,8 +639,4 @@ static inline bool arch_mfn_in_directmap(unsigned long mfn)
     return mfn <= (virt_to_mfn(eva - 1) + 1);
 }
 
-int arch_acquire_resource(struct domain *d, unsigned int type,
-                          unsigned int id, unsigned long frame,
-                          unsigned int nr_frames, xen_pfn_t mfn_list[]);
-
 #endif /* __ASM_X86_MM_H__ */
Signature · 1 line
2.7.4
#65 lore raw

RE: [PATCH V4 11/24] xen/mm: Make x86's XENMEM_resource_ioreq_server handling common

Hi Oleksandr,

Quoted 220 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Oleksandr Tyshchenko
Sent: 2021年1月13日 5:52
To: [email protected]
Cc: Julien Grall <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Volodymyr Babchuk <[email protected]>; Oleksandr Tyshchenko <[email protected]>
Subject: [PATCH V4 11/24] xen/mm: Make x86's XENMEM_resource_ioreq_server handling common

From: Julien Grall <[email protected]>

As x86 implementation of XENMEM_resource_ioreq_server can be re-used on Arm later on, this patch makes it common and removes arch_acquire_resource as unneeded.

Also re-order #include-s alphabetically.

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- no changes

Changes V1 -> V2:
- update the author of a patch

Changes V2 -> V3:
- don't wrap #include <xen/ioreq.h>
- limit the number of #ifdef-s
- re-order #include-s alphabetically

Changes V3 -> V4:
- rebase
- Add Jan's R-b

---
 xen/arch/x86/mm.c        | 44 ---------------------------------
 xen/common/memory.c      | 63
+++++++++++++++++++++++++++++++++++++++---------
 xen/include/asm-arm/mm.h |  8 ------
 xen/include/asm-x86/mm.h |  4 ---
 4 files changed, 51 insertions(+), 68 deletions(-)
xen/arch/x86/mm.c +0 -44
index f6e128e..54ac398 100644
@@ -4587,50 +4587,6 @@ static int handle_iomem_range(unsigned long s,
 unsigned long e, void *p)
     return err || s > e ? err : _handle_iomem_range(s, e, p);
 }
 
-int arch_acquire_resource(struct domain *d, unsigned int type,
-                          unsigned int id, unsigned long frame,
-                          unsigned int nr_frames, xen_pfn_t mfn_list[])
-{
-    int rc;
-
-    switch ( type )
-    {
-#ifdef CONFIG_HVM
-    case XENMEM_resource_ioreq_server:
-    {
-        ioservid_t ioservid = id;
-        unsigned int i;
-
-        rc = -EINVAL;
-        if ( !is_hvm_domain(d) )
-            break;
-
-        if ( id != (unsigned int)ioservid )
-            break;
-
-        rc = 0;
-        for ( i = 0; i < nr_frames; i++ )
-        {
-            mfn_t mfn;
-
-            rc = hvm_get_ioreq_server_frame(d, id, frame + i, &mfn);
-            if ( rc )
-                break;
-
-            mfn_list[i] = mfn_x(mfn);
-        }
-        break;
-    }
-#endif
-
-    default:
-        rc = -EOPNOTSUPP;
-        break;
-    }
-
-    return rc;
-}
-
 long arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void)
 arg)
 {
     int rc;
xen/common/memory.c +45 -10
index b21b6c4..7e560b5 100644
@@ -8,22 +8,23 @@
  */
 
 #include <xen/domain_page.h>
-#include <xen/types.h>
+#include <xen/errno.h>
+#include <xen/event.h>
+#include <xen/grant_table.h>
+#include <xen/guest_access.h>
+#include <xen/hypercall.h>
+#include <xen/iocap.h>
+#include <xen/ioreq.h>
 #include <xen/lib.h>
+#include <xen/mem_access.h>
 #include <xen/mm.h>
+#include <xen/numa.h>
+#include <xen/paging.h>
 #include <xen/param.h>
 #include <xen/perfc.h>
 #include <xen/sched.h>
-#include <xen/event.h>
-#include <xen/paging.h>
-#include <xen/iocap.h>
-#include <xen/guest_access.h>
-#include <xen/hypercall.h>
-#include <xen/errno.h>
-#include <xen/numa.h>
-#include <xen/mem_access.h>
 #include <xen/trace.h>
-#include <xen/grant_table.h>
+#include <xen/types.h>
 #include <asm/current.h>
 #include <asm/hardirq.h>
 #include <asm/p2m.h>
@@ -1090,6 +1091,40 @@ static int acquire_grant_table(struct domain *d,
 unsigned int id,
     return 0;
 }
 
+static int acquire_ioreq_server(struct domain *d,
+                                unsigned int id,
+                                unsigned long frame,
+                                unsigned int nr_frames,
+                                xen_pfn_t mfn_list[])
+{
+#ifdef CONFIG_IOREQ_SERVER
+    ioservid_t ioservid = id;
+    unsigned int i;
+    int rc;
+
+    if ( !is_hvm_domain(d) )
+        return -EINVAL;
+
+    if ( id != (unsigned int)ioservid )
+        return -EINVAL;
+
+    for ( i = 0; i < nr_frames; i++ )
+    {
+        mfn_t mfn;
+
+        rc = hvm_get_ioreq_server_frame(d, id, frame + i, &mfn);
+        if ( rc )
+            return rc;
+
+        mfn_list[i] = mfn_x(mfn);
+    }
+
+    return 0;
+#else
+    return -EOPNOTSUPP;
+#endif
+}
+
 static int acquire_resource(
     XEN_GUEST_HANDLE_PARAM(xen_mem_acquire_resource_t) arg)

{

xen/common/memory.c +6 -2
@@ -1148,9 +1183,13 @@ static int acquire_resource(
                                  mfn_list);
         break;
 
+    case XENMEM_resource_ioreq_server:
+        rc = acquire_ioreq_server(d, xmar.id, xmar.frame, xmar.nr_frames,
+                                  mfn_list);
+        break;
+
     default:
-        rc = arch_acquire_resource(d, xmar.type, xmar.id, xmar.frame,
-                                   xmar.nr_frames, mfn_list);
+        rc = -EOPNOTSUPP;
         break;
     }
 
xen/include/asm-arm/mm.h +0 -0
index f8ba49b..0b7de31 100644
@@ -358,14 +358,6 @@ static inline void put_page_and_type(struct page_info
 *page)
 
 void clear_and_clean_page(struct page_info *page);
 

xen/include/asm-arm/mm.h static inline void put_page_and_type(struct page_info · line 363

Quoted 10 lines
xen/include/asm-arm/mm.h +0 -8
-static inline
-int arch_acquire_resource(struct domain *d, unsigned int type, unsigned int id,
-                          unsigned long frame, unsigned int nr_frames,
-                          xen_pfn_t mfn_list[])
-{
-    return -EOPNOTSUPP;
-}
-
 unsigned int arch_get_dma_bitsize(void);
 

This change could not be applied to the latest staging branch.

Quoted 18 lines

#endif /* __ARCH_ARM_MM__ */

xen/include/asm-x86/mm.h +0 -4
index deeba75..859214e 100644
@@ -639,8 +639,4 @@ static inline bool arch_mfn_in_directmap(unsigned long
 mfn)
     return mfn <= (virt_to_mfn(eva - 1) + 1);
 }
 
-int arch_acquire_resource(struct domain *d, unsigned int type,
-                          unsigned int id, unsigned long frame,
-                          unsigned int nr_frames, xen_pfn_t mfn_list[]);
-

#endif /* __ASM_X86_MM_H__ */
--
2.7.4

#66 lore raw

Re: [PATCH V4 11/24] xen/mm: Make x86's XENMEM_resource_ioreq_server handling common

Quoted 1 line · Wei Chen

Hi Oleksandr,

Hi Wei

Quoted 221 lines
Quoted 221 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Oleksandr Tyshchenko
Sent: 2021年1月13日 5:52
To: [email protected]
Cc: Julien Grall <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Volodymyr Babchuk <[email protected]>; Oleksandr Tyshchenko <[email protected]>
Subject: [PATCH V4 11/24] xen/mm: Make x86's XENMEM_resource_ioreq_server handling common

From: Julien Grall <[email protected]>

As x86 implementation of XENMEM_resource_ioreq_server can be re-used on Arm later on, this patch makes it common and removes arch_acquire_resource as unneeded.

Also re-order #include-s alphabetically.

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- no changes

Changes V1 -> V2:
- update the author of a patch

Changes V2 -> V3:
- don't wrap #include <xen/ioreq.h>
- limit the number of #ifdef-s
- re-order #include-s alphabetically

Changes V3 -> V4:
- rebase
- Add Jan's R-b

---
  xen/arch/x86/mm.c        | 44 ---------------------------------
  xen/common/memory.c      | 63
+++++++++++++++++++++++++++++++++++++++---------
  xen/include/asm-arm/mm.h |  8 ------
  xen/include/asm-x86/mm.h |  4 ---
  4 files changed, 51 insertions(+), 68 deletions(-)
xen/arch/x86/mm.c +0 -44
index f6e128e..54ac398 100644
@@ -4587,50 +4587,6 @@ static int handle_iomem_range(unsigned long s,
 unsigned long e, void *p)
      return err || s > e ? err : _handle_iomem_range(s, e, p);
  }
 
-int arch_acquire_resource(struct domain *d, unsigned int type,
-                          unsigned int id, unsigned long frame,
-                          unsigned int nr_frames, xen_pfn_t mfn_list[])
-{
-    int rc;
-
-    switch ( type )
-    {
-#ifdef CONFIG_HVM
-    case XENMEM_resource_ioreq_server:
-    {
-        ioservid_t ioservid = id;
-        unsigned int i;
-
-        rc = -EINVAL;
-        if ( !is_hvm_domain(d) )
-            break;
-
-        if ( id != (unsigned int)ioservid )
-            break;
-
-        rc = 0;
-        for ( i = 0; i < nr_frames; i++ )
-        {
-            mfn_t mfn;
-
-            rc = hvm_get_ioreq_server_frame(d, id, frame + i, &mfn);
-            if ( rc )
-                break;
-
-            mfn_list[i] = mfn_x(mfn);
-        }
-        break;
-    }
-#endif
-
-    default:
-        rc = -EOPNOTSUPP;
-        break;
-    }
-
-    return rc;
-}
-
  long arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void)
 arg)
  {
      int rc;
xen/common/memory.c +45 -10
index b21b6c4..7e560b5 100644
@@ -8,22 +8,23 @@
   */
 
  #include <xen/domain_page.h>
-#include <xen/types.h>
+#include <xen/errno.h>
+#include <xen/event.h>
+#include <xen/grant_table.h>
+#include <xen/guest_access.h>
+#include <xen/hypercall.h>
+#include <xen/iocap.h>
+#include <xen/ioreq.h>
  #include <xen/lib.h>
+#include <xen/mem_access.h>
  #include <xen/mm.h>
+#include <xen/numa.h>
+#include <xen/paging.h>
  #include <xen/param.h>
  #include <xen/perfc.h>
  #include <xen/sched.h>
-#include <xen/event.h>
-#include <xen/paging.h>
-#include <xen/iocap.h>
-#include <xen/guest_access.h>
-#include <xen/hypercall.h>
-#include <xen/errno.h>
-#include <xen/numa.h>
-#include <xen/mem_access.h>
  #include <xen/trace.h>
-#include <xen/grant_table.h>
+#include <xen/types.h>
  #include <asm/current.h>
  #include <asm/hardirq.h>
  #include <asm/p2m.h>
@@ -1090,6 +1091,40 @@ static int acquire_grant_table(struct domain *d,
 unsigned int id,
      return 0;
  }
 
+static int acquire_ioreq_server(struct domain *d,
+                                unsigned int id,
+                                unsigned long frame,
+                                unsigned int nr_frames,
+                                xen_pfn_t mfn_list[])
+{
+#ifdef CONFIG_IOREQ_SERVER
+    ioservid_t ioservid = id;
+    unsigned int i;
+    int rc;
+
+    if ( !is_hvm_domain(d) )
+        return -EINVAL;
+
+    if ( id != (unsigned int)ioservid )
+        return -EINVAL;
+
+    for ( i = 0; i < nr_frames; i++ )
+    {
+        mfn_t mfn;
+
+        rc = hvm_get_ioreq_server_frame(d, id, frame + i, &mfn);
+        if ( rc )
+            return rc;
+
+        mfn_list[i] = mfn_x(mfn);
+    }
+
+    return 0;
+#else
+    return -EOPNOTSUPP;
+#endif
+}
+
  static int acquire_resource(
      XEN_GUEST_HANDLE_PARAM(xen_mem_acquire_resource_t) arg)
  {
xen/common/memory.c +6 -2
@@ -1148,9 +1183,13 @@ static int acquire_resource(
                                   mfn_list);
          break;
 
+    case XENMEM_resource_ioreq_server:
+        rc = acquire_ioreq_server(d, xmar.id, xmar.frame, xmar.nr_frames,
+                                  mfn_list);
+        break;
+
      default:
-        rc = arch_acquire_resource(d, xmar.type, xmar.id, xmar.frame,
-                                   xmar.nr_frames, mfn_list);
+        rc = -EOPNOTSUPP;
          break;
      }
 
xen/include/asm-arm/mm.h +0 -0
index f8ba49b..0b7de31 100644
@@ -358,14 +358,6 @@ static inline void put_page_and_type(struct page_info
 *page)
 
  void clear_and_clean_page(struct page_info *page);
 
Quoted 11 lines

xen/include/asm-arm/mm.h static inline void put_page_and_type(struct page_info *page) · line 362

Quoted 10 lines
xen/include/asm-arm/mm.h +0 -8
-static inline
-int arch_acquire_resource(struct domain *d, unsigned int type, unsigned int id,
-                          unsigned long frame, unsigned int nr_frames,
-                          xen_pfn_t mfn_list[])
-{
-    return -EOPNOTSUPP;
-}
-
  unsigned int arch_get_dma_bitsize(void);
 

This change could not be applied to the latest staging branch.

Yes, thank you noticing that.  The code around was changed a bit (patch series is based on 10-days old staging), I will update for the next version.

Quoted 19 lines
Quoted 19 lines
  #endif /*  __ARCH_ARM_MM__ */
xen/include/asm-x86/mm.h +0 -4
index deeba75..859214e 100644
@@ -639,8 +639,4 @@ static inline bool arch_mfn_in_directmap(unsigned long
 mfn)
      return mfn <= (virt_to_mfn(eva - 1) + 1);
  }
 
-int arch_acquire_resource(struct domain *d, unsigned int type,
-                          unsigned int id, unsigned long frame,
-                          unsigned int nr_frames, xen_pfn_t mfn_list[]);
-

#endif /* __ASM_X86_MM_H__ */
--
2.7.4

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
#67 lore raw

Re: [PATCH V4 11/24] xen/mm: Make x86's XENMEM_resource_ioreq_server handling common

Quoted 4 lines · Oleksandr
Quoted 1 line · Wei Chen

Hi Oleksandr,

Hi Wei

<snip>

Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
xen/common/memory.c +34 -0
@@ -1090,6 +1091,40 @@ static int acquire_grant_table(struct domain *d,
 unsigned int id,
      return 0;
  }
 
+static int acquire_ioreq_server(struct domain *d,
+                                unsigned int id,
+                                unsigned long frame,
+                                unsigned int nr_frames,
+                                xen_pfn_t mfn_list[])
+{
+#ifdef CONFIG_IOREQ_SERVER
+    ioservid_t ioservid = id;
+    unsigned int i;
+    int rc;
+
+    if ( !is_hvm_domain(d) )
+        return -EINVAL;
+
+    if ( id != (unsigned int)ioservid )
+        return -EINVAL;
+
+    for ( i = 0; i < nr_frames; i++ )
+    {
+        mfn_t mfn;
+
+        rc = hvm_get_ioreq_server_frame(d, id, frame + i, &mfn);
+        if ( rc )
+            return rc;
+
+        mfn_list[i] = mfn_x(mfn);
+    }
+
+    return 0;
+#else
+    return -EOPNOTSUPP;
+#endif
+}
+

<snip>

Quoted 6 lines
Quoted 2 lines
Quoted 1 line

This change could not be applied to the latest staging branch.

Yes, thank you noticing that. The code around was changed a bit (patch series is based on 10-days old staging), I will update for the next version.

I think the commit that introduced config ARCH_ACQUIRE_RESOURCE could probably be reverted as it achieves pretty much the same thing as the above code by moving the logic into the common code path.

The only real practical difference is a inline stub vs a general purpose function with an IOREQ specific #ifdeferry.
<snip>

Signature · 1 line
Alex Bennée
#68 lore raw

Re: [PATCH V4 11/24] xen/mm: Make x86's XENMEM_resource_ioreq_server handling common

On 15.01.21 16:35, Alex Bennée wrote:

Hi Alex

Quoted 50 lines
Quoted 3 lines · Oleksandr
Quoted 1 line · Wei Chen

Hi Oleksandr,

Hi Wei

<snip>

Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
xen/common/memory.c +34 -0
@@ -1090,6 +1091,40 @@ static int acquire_grant_table(struct domain *d,
 unsigned int id,
       return 0;
   }
 
+static int acquire_ioreq_server(struct domain *d,
+                                unsigned int id,
+                                unsigned long frame,
+                                unsigned int nr_frames,
+                                xen_pfn_t mfn_list[])
+{
+#ifdef CONFIG_IOREQ_SERVER
+    ioservid_t ioservid = id;
+    unsigned int i;
+    int rc;
+
+    if ( !is_hvm_domain(d) )
+        return -EINVAL;
+
+    if ( id != (unsigned int)ioservid )
+        return -EINVAL;
+
+    for ( i = 0; i < nr_frames; i++ )
+    {
+        mfn_t mfn;
+
+        rc = hvm_get_ioreq_server_frame(d, id, frame + i, &mfn);
+        if ( rc )
+            return rc;
+
+        mfn_list[i] = mfn_x(mfn);
+    }
+
+    return 0;
+#else
+    return -EOPNOTSUPP;
+#endif
+}
+

<snip>

Quoted 4 lines
Quoted 1 line

This change could not be applied to the latest staging branch.

Yes, thank you noticing that. The code around was changed a bit (patch series is based on 10-days old staging), I will update for the next version.

Quoted 7 lines

I think the commit that introduced config ARCH_ACQUIRE_RESOURCE could probably be reverted as it achieves pretty much the same thing as the above code by moving the logic into the common code path.

The only real practical difference is a inline stub vs a general purpose function with an IOREQ specific #ifdeferry.
<snip>

Hmm, thank you for noticing that.
So, yes, I should either add an extra patch for V5 to revert ARCH_ACQUIRE_RESOURCE before applying this one
or rebase it to the current codebase (and likely drop all collected R-bs because of an additional changes of removing ARCH_ACQUIRE_RESOURCE bits).

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
Reviewed-by on v4 11/24
#69 lore raw

RE: [PATCH V4 11/24] xen/mm: Make x86's XENMEM_resource_ioreq_server handling common

In reply to Oleksandr Tyshchenko
Quoted 19 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Oleksandr Tyshchenko
Sent: 12 January 2021 21:52
To: [email protected]
Cc: Julien Grall <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Volodymyr Babchuk <[email protected]>; Oleksandr Tyshchenko <[email protected]>
Subject: [PATCH V4 11/24] xen/mm: Make x86's XENMEM_resource_ioreq_server handling common

From: Julien Grall <[email protected]>

As x86 implementation of XENMEM_resource_ioreq_server can be re-used on Arm later on, this patch makes it common and removes arch_acquire_resource as unneeded.

Also re-order #include-s alphabetically.

Quoted 9 lines

This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor.

#70 lore raw

PATCH v4 12/24 xen/ioreq: Remove "hvm" prefixes from involved function names

In reply to Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

This patch removes "hvm" prefixes and infixes from IOREQ related function names in the common code and performs a renaming where appropriate according to the more consistent new naming scheme:
- IOREQ server functions should start with "ioreq_server_"
- IOREQ functions should start with "ioreq_"

A few function names are clarified to better fit into their purposes:
handle_hvm_io_completion -> vcpu_ioreq_handle_completion

hvm_io_pending           -> vcpu_ioreq_pending
hvm_ioreq_init           -> ioreq_domain_init
hvm_alloc_ioreq_mfn      -> ioreq_server_alloc_mfn
hvm_free_ioreq_mfn       -> ioreq_server_free_mfn

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes V1 -> V2:
- new patch

Changes V2 -> V3:
- update patch according the "legacy interface" is x86 specific
- update patch description
- rename everything touched according to new naming scheme

Changes V3 -> V4:
- rebase
- rename ioreq_update_evtchn() to ioreq_server_update_evtchn()
- add Jan's R-b

---
 xen/arch/x86/hvm/dm.c       |   4 +-
 xen/arch/x86/hvm/emulate.c  |   6 +-
 xen/arch/x86/hvm/hvm.c      |  10 +--
 xen/arch/x86/hvm/io.c       |   6 +-
 xen/arch/x86/hvm/ioreq.c    |   2 +-
 xen/arch/x86/hvm/stdvga.c   |   4 +-
 xen/arch/x86/hvm/vmx/vvmx.c |   2 +-
 xen/common/ioreq.c          | 202 ++++++++++++++++++++++----------------------
 xen/common/memory.c         |   2 +-
 xen/include/xen/ioreq.h     |  30 +++----
 10 files changed, 134 insertions(+), 134 deletions(-)
xen/arch/x86/hvm/dm.c +2 -2
index dc8e47d..f770536 100644
@@ -415,8 +415,8 @@ static int dm_op(const struct dmop_args *op_args)
             break;
 
         if ( first_gfn == 0 )
-            rc = hvm_map_mem_type_to_ioreq_server(d, data->id,
-                                                  data->type, data->flags);
+            rc = ioreq_server_map_mem_type(d, data->id,
+                                           data->type, data->flags);
         else
             rc = 0;
 
xen/arch/x86/hvm/emulate.c +3 -3
index 21051ce..425c8dd 100644
@@ -261,7 +261,7 @@ static int hvmemul_do_io(
          * an ioreq server that can handle it.
          *
          * Rules:
-         * A> PIO or MMIO accesses run through hvm_select_ioreq_server() to
+         * A> PIO or MMIO accesses run through ioreq_server_select() to
          * choose the ioreq server by range. If no server is found, the access
          * is ignored.
          *
@@ -323,7 +323,7 @@ static int hvmemul_do_io(
         }
 
         if ( !s )
-            s = hvm_select_ioreq_server(currd, &p);
+            s = ioreq_server_select(currd, &p);
 
         /* If there is no suitable backing DM, just ignore accesses */
         if ( !s )
@@ -333,7 +333,7 @@ static int hvmemul_do_io(
         }
         else
         {
-            rc = hvm_send_ioreq(s, &p, 0);
+            rc = ioreq_send(s, &p, 0);
             if ( rc != X86EMUL_RETRY || currd->is_shutting_down )
                 vio->req.state = STATE_IOREQ_NONE;
             else if ( !ioreq_needs_completion(&vio->req) )
xen/arch/x86/hvm/hvm.c +5 -5
index 4ed929c..0d7bb42 100644
@@ -546,7 +546,7 @@ void hvm_do_resume(struct vcpu *v)
 
     pt_restore_timer(v);
 
-    if ( !handle_hvm_io_completion(v) )
+    if ( !vcpu_ioreq_handle_completion(v) )
         return;
 
     if ( unlikely(v->arch.vm_event) )
@@ -677,7 +677,7 @@ int hvm_domain_initialise(struct domain *d)
     register_g2m_portio_handler(d);
     register_vpci_portio_handler(d);
 
-    hvm_ioreq_init(d);
+    ioreq_domain_init(d);
 
     hvm_init_guest_time(d);
 
@@ -739,7 +739,7 @@ void hvm_domain_relinquish_resources(struct domain *d)
 
     viridian_domain_deinit(d);
 
-    hvm_destroy_all_ioreq_servers(d);
+    ioreq_server_destroy_all(d);
 
     msixtbl_pt_cleanup(d);
 
@@ -1582,7 +1582,7 @@ int hvm_vcpu_initialise(struct vcpu *v)
     if ( rc )
         goto fail5;
 
-    rc = hvm_all_ioreq_servers_add_vcpu(d, v);
+    rc = ioreq_server_add_vcpu_all(d, v);
     if ( rc != 0 )
         goto fail6;
 
@@ -1618,7 +1618,7 @@ void hvm_vcpu_destroy(struct vcpu *v)
 {
     viridian_vcpu_deinit(v);
 
-    hvm_all_ioreq_servers_remove_vcpu(v->domain, v);
+    ioreq_server_remove_vcpu_all(v->domain, v);
 
     if ( hvm_altp2m_supported() )
         altp2m_vcpu_destroy(v);
xen/arch/x86/hvm/io.c +3 -3
index dd733e1..66a37ee 100644
@@ -60,7 +60,7 @@ void send_timeoffset_req(unsigned long timeoff)
     if ( timeoff == 0 )
         return;
 
-    if ( hvm_broadcast_ioreq(&p, true) != 0 )
+    if ( ioreq_broadcast(&p, true) != 0 )
         gprintk(XENLOG_ERR, "Unsuccessful timeoffset update\n");
 }
 
@@ -74,7 +74,7 @@ void send_invalidate_req(void)
         .data = ~0UL, /* flush all */
     };
 
-    if ( hvm_broadcast_ioreq(&p, false) != 0 )
+    if ( ioreq_broadcast(&p, false) != 0 )
         gprintk(XENLOG_ERR, "Unsuccessful map-cache invalidate\n");
 }
 
@@ -155,7 +155,7 @@ bool handle_pio(uint16_t port, unsigned int size, int dir)
          * We should not advance RIP/EIP if the domain is shutting down or
          * if X86EMUL_RETRY has been returned by an internal handler.
          */
-        if ( curr->domain->is_shutting_down || !hvm_io_pending(curr) )
+        if ( curr->domain->is_shutting_down || !vcpu_ioreq_pending(curr) )
             return false;
         break;
 
xen/arch/x86/hvm/ioreq.c +1 -1
index c00ee8e..5c9f3a5 100644
@@ -153,7 +153,7 @@ static int hvm_map_ioreq_gfn(struct ioreq_server *s, bool buf)
     {
         /*
          * If a page has already been allocated (which will happen on
-         * demand if hvm_get_ioreq_server_frame() is called), then
+         * demand if ioreq_server_get_frame() is called), then
          * mapping a guest frame is not permitted.
          */
         if ( gfn_eq(iorp->gfn, INVALID_GFN) )
xen/arch/x86/hvm/stdvga.c +2 -2
index ee13449..ab9781d 100644
@@ -507,11 +507,11 @@ static int stdvga_mem_write(const struct hvm_io_handler *handler,
     }
 
  done:
-    srv = hvm_select_ioreq_server(current->domain, &p);
+    srv = ioreq_server_select(current->domain, &p);
     if ( !srv )
         return X86EMUL_UNHANDLEABLE;
 
-    return hvm_send_ioreq(srv, &p, 1);
+    return ioreq_send(srv, &p, 1);
 }
 
 static bool_t stdvga_mem_accept(const struct hvm_io_handler *handler,
xen/arch/x86/hvm/vmx/vvmx.c +1 -1
index 0ddb6a4..e9f94da 100644
@@ -1517,7 +1517,7 @@ void nvmx_switch_guest(void)
      * don't want to continue as this setup is not implemented nor supported
      * as of right now.
      */
-    if ( hvm_io_pending(v) )
+    if ( vcpu_ioreq_pending(v) )
         return;
     /*
      * a softirq may interrupt us between a virtual vmentry is
xen/common/ioreq.c +101 -101

568 lines not on this page · raw message

xen/common/memory.c +1 -1
index 7e560b5..66828d9 100644
@@ -1112,7 +1112,7 @@ static int acquire_ioreq_server(struct domain *d,
     {
         mfn_t mfn;
 
-        rc = hvm_get_ioreq_server_frame(d, id, frame + i, &mfn);
+        rc = ioreq_server_get_frame(d, id, frame + i, &mfn);
         if ( rc )
             return rc;
 
xen/include/xen/ioreq.h +15 -15
index dffed60..ec7e98d 100644
@@ -81,26 +81,26 @@ static inline bool ioreq_needs_completion(const ioreq_t *ioreq)
 #define HANDLE_BUFIOREQ(s) \
     ((s)->bufioreq_handling != HVM_IOREQSRV_BUFIOREQ_OFF)
 
-bool hvm_io_pending(struct vcpu *v);
-bool handle_hvm_io_completion(struct vcpu *v);
+bool vcpu_ioreq_pending(struct vcpu *v);
+bool vcpu_ioreq_handle_completion(struct vcpu *v);
 bool is_ioreq_server_page(struct domain *d, const struct page_info *page);
 
-int hvm_get_ioreq_server_frame(struct domain *d, ioservid_t id,
-                               unsigned long idx, mfn_t *mfn);
-int hvm_map_mem_type_to_ioreq_server(struct domain *d, ioservid_t id,
-                                     uint32_t type, uint32_t flags);
+int ioreq_server_get_frame(struct domain *d, ioservid_t id,
+                           unsigned long idx, mfn_t *mfn);
+int ioreq_server_map_mem_type(struct domain *d, ioservid_t id,
+                              uint32_t type, uint32_t flags);
 
-int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v);
-void hvm_all_ioreq_servers_remove_vcpu(struct domain *d, struct vcpu *v);
-void hvm_destroy_all_ioreq_servers(struct domain *d);
+int ioreq_server_add_vcpu_all(struct domain *d, struct vcpu *v);
+void ioreq_server_remove_vcpu_all(struct domain *d, struct vcpu *v);
+void ioreq_server_destroy_all(struct domain *d);
 
-struct ioreq_server *hvm_select_ioreq_server(struct domain *d,
-                                             ioreq_t *p);
-int hvm_send_ioreq(struct ioreq_server *s, ioreq_t *proto_p,
-                   bool buffered);
-unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered);
+struct ioreq_server *ioreq_server_select(struct domain *d,
+                                         ioreq_t *p);
+int ioreq_send(struct ioreq_server *s, ioreq_t *proto_p,
+               bool buffered);
+unsigned int ioreq_broadcast(ioreq_t *p, bool buffered);
 
-void hvm_ioreq_init(struct domain *d);
+void ioreq_domain_init(struct domain *d);
 
 int ioreq_server_dm_op(struct xen_dm_op *op, struct domain *d, bool *const_op);
 
Signature · 1 line
2.7.4
Reviewed-by on v4 12/24
#71 lore raw

RE: [PATCH V4 12/24] xen/ioreq: Remove "hvm" prefixes from involved function names

Quoted 27 lines

-----Original Message-----
From: Oleksandr Tyshchenko <[email protected]>
Sent: 12 January 2021 21:52
To: [email protected]
Cc: Oleksandr Tyshchenko <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Paul Durrant <[email protected]>; Jun Nakajima <[email protected]>; Kevin Tian <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH V4 12/24] xen/ioreq: Remove "hvm" prefixes from involved function names

From: Oleksandr Tyshchenko <[email protected]>

This patch removes "hvm" prefixes and infixes from IOREQ related function names in the common code and performs a renaming where appropriate according to the more consistent new naming scheme:
- IOREQ server functions should start with "ioreq_server_"
- IOREQ functions should start with "ioreq_"

A few function names are clarified to better fit into their purposes:
handle_hvm_io_completion -> vcpu_ioreq_handle_completion

hvm_io_pending           -> vcpu_ioreq_pending
hvm_ioreq_init           -> ioreq_domain_init
hvm_alloc_ioreq_mfn      -> ioreq_server_alloc_mfn
hvm_free_ioreq_mfn       -> ioreq_server_free_mfn
Quoted 6 lines
#72 lore raw

PATCH v4 13/24 xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()

In reply to Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The cmpxchg() in ioreq_send_buffered() operates on memory shared with the emulator domain (and the target domain if the legacy interface is used).

In order to be on the safe side we need to switch to guest_cmpxchg64() to prevent a domain to DoS Xen on Arm.

As there is no plan to support the legacy interface on Arm, we will have a page to be mapped in a single domain at the time, so we can use s->emulator in guest_cmpxchg64() safely.

Thankfully the only user of the legacy interface is x86 so far and there is not concern regarding the atomics operations.

Please note, that the legacy interface *must* not be used on Arm without revisiting the code.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- new patch

Changes V1 -> V2:
- move earlier to avoid breaking arm32 compilation
- add an explanation to commit description and hvm_allow_set_param()
- pass s->emulator

Changes V2 -> V3:
- update patch description

Changes V3 -> V4:
- add Stefano's A-b
- drop comment from arm/hvm.c

---
 xen/common/ioreq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/common/ioreq.c +2 -1
index d233a49..d5f4dd3 100644
@@ -29,6 +29,7 @@
 #include <xen/trace.h>
 #include <xen/vpci.h>
 
+#include <asm/guest_atomics.h>
 #include <asm/hvm/ioreq.h>
 
 #include <public/hvm/ioreq.h>
@@ -1185,7 +1186,7 @@ static int ioreq_send_buffered(struct ioreq_server *s, ioreq_t *p)
 
         new.read_pointer = old.read_pointer - n * IOREQ_BUFFER_SLOT_NUM;
         new.write_pointer = old.write_pointer - n * IOREQ_BUFFER_SLOT_NUM;
-        cmpxchg(&pg->ptrs.full, old.full, new.full);
+        guest_cmpxchg64(s->emulator, &pg->ptrs.full, old.full, new.full);
     }
 
     notify_via_xen_event_channel(d, s->bufioreq_evtchn);
Signature · 1 line
2.7.4
#73 lore raw

Re: [PATCH V4 13/24] xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()

Hi Oleksandr,

Quoted 6 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The cmpxchg() in ioreq_send_buffered() operates on memory shared with the emulator domain (and the target domain if the legacy interface is used).

Quoted 6 lines

In order to be on the safe side we need to switch to guest_cmpxchg64() to prevent a domain to DoS Xen on Arm.

As there is no plan to support the legacy interface on Arm, we will have a page to be mapped in a single domain at the time, so we can use s->emulator in guest_cmpxchg64() safely.

I think you want to explain why you are using the 64-bit version of helper.

Quoted 49 lines

Thankfully the only user of the legacy interface is x86 so far and there is not concern regarding the atomics operations.

Please note, that the legacy interface *must* not be used on Arm without revisiting the code.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- new patch

Changes V1 -> V2:
- move earlier to avoid breaking arm32 compilation
- add an explanation to commit description and hvm_allow_set_param()
- pass s->emulator

Changes V2 -> V3:
- update patch description

Changes V3 -> V4:
- add Stefano's A-b
- drop comment from arm/hvm.c

---
  xen/common/ioreq.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
xen/common/ioreq.c +1 -0
index d233a49..d5f4dd3 100644
@@ -29,6 +29,7 @@
  #include <xen/trace.h>
  #include <xen/vpci.h>
 
+#include <asm/guest_atomics.h>
  #include <asm/hvm/ioreq.h>
 
  #include <public/hvm/ioreq.h>

xen/common/ioreq.c static int ioreq_send_buffered(struct ioreq_server *s, ioreq_t *p) · line 1192

Quoted 8 lines
xen/common/ioreq.c +1 -1
@@ -1185,7 +1186,7 @@ static int ioreq_send_buffered(struct ioreq_server *s, ioreq_t *p)
 
          new.read_pointer = old.read_pointer - n * IOREQ_BUFFER_SLOT_NUM;
          new.write_pointer = old.write_pointer - n * IOREQ_BUFFER_SLOT_NUM;
-        cmpxchg(&pg->ptrs.full, old.full, new.full);
+        guest_cmpxchg64(s->emulator, &pg->ptrs.full, old.full, new.full);
      }
 
      notify_via_xen_event_channel(d, s->bufioreq_evtchn);

Cheers,

Signature · 1 line
Julien Grall
#74 lore raw

Re: [PATCH V4 13/24] xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()

Quoted 1 line · Julien Grall

Hi Oleksandr,

Hi Julien

Quoted 8 lines · Oleksandr Tyshchenko
Quoted 6 lines

From: Oleksandr Tyshchenko <[email protected]>

The cmpxchg() in ioreq_send_buffered() operates on memory shared with the emulator domain (and the target domain if the legacy interface is used).

Quoted 8 lines
Quoted 6 lines

In order to be on the safe side we need to switch to guest_cmpxchg64() to prevent a domain to DoS Xen on Arm.

As there is no plan to support the legacy interface on Arm, we will have a page to be mapped in a single domain at the time, so we can use s->emulator in guest_cmpxchg64() safely.

I think you want to explain why you are using the 64-bit version of helper.

The point to use 64-bit version of helper is to support Arm32 since the IOREQ code uses cmpxchg() with 64-bit value.

I will update patch description.

Quoted 59 lines
Quoted 48 lines

Thankfully the only user of the legacy interface is x86 so far and there is not concern regarding the atomics operations.

Please note, that the legacy interface *must* not be used on Arm without revisiting the code.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
    - new patch

Changes V1 -> V2:
    - move earlier to avoid breaking arm32 compilation
    - add an explanation to commit description and hvm_allow_set_param()
    - pass s->emulator

Changes V2 -> V3:
    - update patch description

Changes V3 -> V4:
    - add Stefano's A-b
    - drop comment from arm/hvm.c
---
  xen/common/ioreq.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
xen/common/ioreq.c +0 -0
index d233a49..d5f4dd3 100644
@@ -29,6 +29,7 @@
   #include <xen/trace.h>
   #include <xen/vpci.h>

  +#include <asm/guest_atomics.h>
  #include <asm/hvm/ioreq.h>
    #include <public/hvm/ioreq.h>

xen/common/ioreq.c static int ioreq_send_buffered(struct · line 1192

Quoted 8 lines
xen/common/ioreq.c +1 -1
@@ -1185,7 +1186,7 @@ static int ioreq_send_buffered(struct 
 ioreq_server *s, ioreq_t *p)
             new.read_pointer = old.read_pointer - n * IOREQ_BUFFER_SLOT_NUM;
           new.write_pointer = old.write_pointer - n * IOREQ_BUFFER_SLOT_NUM;
-        cmpxchg(&pg->ptrs.full, old.full, new.full);
+        guest_cmpxchg64(s->emulator, &pg->ptrs.full, old.full, 
 new.full);
       }
         notify_via_xen_event_channel(d, s->bufioreq_evtchn);

Cheers,

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
Reviewed-by on v4 13/24
#75 lore raw

RE: [PATCH V4 13/24] xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()

In reply to Oleksandr Tyshchenko
Quoted 24 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Oleksandr Tyshchenko
Sent: 12 January 2021 21:52
To: [email protected]
Cc: Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH V4 13/24] xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg()

From: Oleksandr Tyshchenko <[email protected]>

The cmpxchg() in ioreq_send_buffered() operates on memory shared with the emulator domain (and the target domain if the legacy interface is used).

In order to be on the safe side we need to switch to guest_cmpxchg64() to prevent a domain to DoS Xen on Arm.

As there is no plan to support the legacy interface on Arm, we will have a page to be mapped in a single domain at the time, so we can use s->emulator in guest_cmpxchg64() safely.

Thankfully the only user of the legacy interface is x86 so far and there is not concern regarding the atomics operations.

Quoted 8 lines

Please note, that the legacy interface *must* not be used on Arm without revisiting the code.

#76 lore raw

PATCH v4 14/24 arm/ioreq: Introduce arch specific bits for IOREQ/DM features

In reply to Oleksandr Tyshchenko

From: Julien Grall <[email protected]>

This patch adds basic IOREQ/DM support on Arm. The subsequent patches will improve functionality and add remaining bits.

The IOREQ/DM features are supposed to be built with IOREQ_SERVER option enabled, which is disabled by default on Arm for now.

Please note, the "PIO handling" TODO is expected to left unaddressed for the current series. It is not an big issue for now while Xen doesn't have support for vPCI on Arm. On Arm64 they are only used for PCI IO Bar and we would probably want to expose them to emulator as PIO access to make a DM completely arch-agnostic. So "PIO handling" should be implemented when we add support for vPCI.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- was split into:
- arm/ioreq: Introduce arch specific bits for IOREQ/DM features
- xen/mm: Handle properly reference in set_foreign_p2m_entry() on Arm
- update patch description
- update asm-arm/hvm/ioreq.h according to the newly introduced arch functions:
- arch_hvm_destroy_ioreq_server()
- arch_handle_hvm_io_completion()
- update arch files to include xen/ioreq.h
- remove HVMOP plumbing
- rewrite a logic to handle properly case when hvm_send_ioreq() returns IO_RETRY
- add a logic to handle properly handle_hvm_io_completion() return value
- rename handle_mmio() to ioreq_handle_complete_mmio()
- move paging_mark_pfn_dirty() to asm-arm/paging.h
- remove forward declaration for hvm_ioreq_server in asm-arm/paging.h
- move try_fwd_ioserv() to ioreq.c, provide stubs if !CONFIG_IOREQ_SERVER
- do not remove #ifdef CONFIG_IOREQ_SERVER in memory.c for guarding xen/ioreq.h
- use gdprintk in try_fwd_ioserv(), remove unneeded prints
- update list of #include-s
- move has_vpci() to asm-arm/domain.h
- add a comment (TODO) to unimplemented yet handle_pio()
- remove hvm_mmio_first(last)_byte() and hvm_ioreq_(page/vcpu/server) structs from the arch files, they were already moved to the common code
- remove set_foreign_p2m_entry() changes, they will be properly implemented in the follow-up patch
- select IOREQ_SERVER for Arm instead of Arm64 in Kconfig
- remove x86's realmode and other unneeded stubs from xen/ioreq.h
- clafify ioreq_t p.df usage in try_fwd_ioserv()
- set ioreq_t p.count to 1 in try_fwd_ioserv()

Changes V1 -> V2:
- was split into:
- arm/ioreq: Introduce arch specific bits for IOREQ/DM features
- xen/arm: Stick around in leave_hypervisor_to_guest until I/O has completed
- update the author of a patch
- update patch description
- move a loop in leave_hypervisor_to_guest() to a separate patch
- set IOREQ_SERVER disabled by default
- remove already clarified /* XXX */
- replace BUG() by ASSERT_UNREACHABLE() in handle_pio()
- remove default case for handling the return value of try_handle_mmio()
- remove struct hvm_domain, enum hvm_io_completion, struct hvm_vcpu_io, struct hvm_vcpu from asm-arm/domain.h, these are common materials now
- update everything according to the recent changes (IOREQ related function names don't contain "hvm" prefixes/infixes anymore, IOREQ related fields are part of common struct vcpu/domain now, etc)

Changes V2 -> V3:
- update patch according the "legacy interface" is x86 specific
- add dummy arch hooks
- remove dummy paging_mark_pfn_dirty()
- don’t include <xen/domain_page.h> in common ioreq.c
- don’t include <public/hvm/ioreq.h> in arch ioreq.h
- remove #define ioreq_params(d, i)

Changes V3 -> V4:
- rebase
- update patch according to the renaming IO_ -> VIO_ (io_ -> vio_) and misc changes to arch hooks
- update patch according to the IOREQ related dm-op handling changes
- don't include <xen/ioreq.h> from arch header
- make all arch hooks out-of-line
- add a comment above IOREQ_STATUS_* #define-s

---
 xen/arch/arm/Makefile           |   2 +
 xen/arch/arm/dm.c               | 122 +++++++++++++++++++++++
 xen/arch/arm/domain.c           |   9 ++
 xen/arch/arm/io.c               |  12 ++-
 xen/arch/arm/ioreq.c            | 213 ++++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/traps.c            |  13 +++
 xen/include/asm-arm/domain.h    |   3 +
 xen/include/asm-arm/hvm/ioreq.h |  72 ++++++++++++++
 xen/include/asm-arm/mmio.h      |   1 +
 9 files changed, 446 insertions(+), 1 deletion(-)
 create mode 100644 xen/arch/arm/dm.c
 create mode 100644 xen/arch/arm/ioreq.c
 create mode 100644 xen/include/asm-arm/hvm/ioreq.h
xen/arch/arm/Makefile +2 -0
index 512ffdd..16e6523 100644
@@ -13,6 +13,7 @@ obj-y += cpuerrata.o
 obj-y += cpufeature.o
 obj-y += decode.o
 obj-y += device.o
+obj-$(CONFIG_IOREQ_SERVER) += dm.o
 obj-y += domain.o
 obj-y += domain_build.init.o
 obj-y += domctl.o
@@ -27,6 +28,7 @@ obj-y += guest_atomics.o
 obj-y += guest_walk.o
 obj-y += hvm.o
 obj-y += io.o
+obj-$(CONFIG_IOREQ_SERVER) += ioreq.o
 obj-y += irq.o
 obj-y += kernel.init.o
 obj-$(CONFIG_LIVEPATCH) += livepatch.o
xen/arch/arm/dm.c new file +122 -0

122 lines not on this page · raw message

xen/arch/arm/domain.c +9 -0
index 18cafcd..8f55aba 100644
@@ -15,6 +15,7 @@
 #include <xen/guest_access.h>
 #include <xen/hypercall.h>
 #include <xen/init.h>
+#include <xen/ioreq.h>
 #include <xen/lib.h>
 #include <xen/livepatch.h>
 #include <xen/sched.h>
@@ -696,6 +697,10 @@ int arch_domain_create(struct domain *d,
 
     ASSERT(config != NULL);
 
+#ifdef CONFIG_IOREQ_SERVER
+    ioreq_domain_init(d);
+#endif
+
     /* p2m_init relies on some value initialized by the IOMMU subsystem */
     if ( (rc = iommu_domain_init(d, config->iommu_opts)) != 0 )
         goto fail;
@@ -1014,6 +1019,10 @@ int domain_relinquish_resources(struct domain *d)
         if (ret )
             return ret;
 
+#ifdef CONFIG_IOREQ_SERVER
+        ioreq_server_destroy_all(d);
+#endif
+
     PROGRESS(xen):
         ret = relinquish_memory(d, &d->xenpage_list);
         if ( ret )
xen/arch/arm/io.c +11 -1
index ae7ef96..9814481 100644
@@ -16,6 +16,7 @@
  * GNU General Public License for more details.
  */
 
+#include <xen/ioreq.h>
 #include <xen/lib.h>
 #include <xen/spinlock.h>
 #include <xen/sched.h>
@@ -23,6 +24,7 @@
 #include <asm/cpuerrata.h>
 #include <asm/current.h>
 #include <asm/mmio.h>
+#include <asm/hvm/ioreq.h>
 
 #include "decode.h"
 
@@ -123,7 +125,15 @@ enum io_state try_handle_mmio(struct cpu_user_regs *regs,
 
     handler = find_mmio_handler(v->domain, info.gpa);
     if ( !handler )
-        return IO_UNHANDLED;
+    {
+        int rc;
+
+        rc = try_fwd_ioserv(regs, v, &info);
+        if ( rc == IO_HANDLED )
+            return handle_ioserv(regs, v);
+
+        return rc;
+    }
 
     /* All the instructions used on emulated MMIO region should be valid */
     if ( !dabt.valid )
xen/arch/arm/ioreq.c new file +213 -0

213 lines not on this page · raw message

xen/arch/arm/traps.c +13 -0
index 22bd1bd..036b13f 100644
@@ -21,6 +21,7 @@
 #include <xen/hypercall.h>
 #include <xen/init.h>
 #include <xen/iocap.h>
+#include <xen/ioreq.h>
 #include <xen/irq.h>
 #include <xen/lib.h>
 #include <xen/mem_access.h>
@@ -1385,6 +1386,9 @@ static arm_hypercall_t arm_hypercall_table[] = {
 #ifdef CONFIG_HYPFS
     HYPERCALL(hypfs_op, 5),
 #endif
+#ifdef CONFIG_IOREQ_SERVER
+    HYPERCALL(dm_op, 3),
+#endif
 };
 
 #ifndef NDEBUG
@@ -1956,6 +1960,9 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs,
             case IO_HANDLED:
                 advance_pc(regs, hsr);
                 return;
+            case IO_RETRY:
+                /* finish later */
+                return;
             case IO_UNHANDLED:
                 /* IO unhandled, try another way to handle it. */
                 break;
@@ -2254,6 +2261,12 @@ static void check_for_vcpu_work(void)
 {
     struct vcpu *v = current;
 
+#ifdef CONFIG_IOREQ_SERVER
+    local_irq_enable();
+    vcpu_ioreq_handle_completion(v);
+    local_irq_disable();
+#endif
+
     if ( likely(!v->arch.need_flush_to_ram) )
         return;
 
xen/include/asm-arm/domain.h +3 -0
index 6819a3b..c235e5b 100644
@@ -10,6 +10,7 @@
 #include <asm/gic.h>
 #include <asm/vgic.h>
 #include <asm/vpl011.h>
+#include <public/hvm/dm_op.h>
 #include <public/hvm/params.h>
 
 struct hvm_domain
@@ -262,6 +263,8 @@ static inline void arch_vcpu_block(struct vcpu *v) {}
 
 #define arch_vm_assist_valid_mask(d) (1UL << VMASST_TYPE_runstate_update_flag)
 
+#define has_vpci(d)    ({ (void)(d); false; })
+
 #endif /* __ASM_DOMAIN_H__ */
 
 /*
xen/include/asm-arm/hvm/ioreq.h new file +72 -0

72 lines not on this page · raw message

xen/include/asm-arm/mmio.h +1 -0
index 8dbfb27..7ab873c 100644
@@ -37,6 +37,7 @@ enum io_state
     IO_ABORT,       /* The IO was handled by the helper and led to an abort. */
     IO_HANDLED,     /* The IO was successfully handled by the helper. */
     IO_UNHANDLED,   /* The IO was not handled by the helper. */
+    IO_RETRY,       /* Retry the emulation for some reason */
 };
 
 typedef int (*mmio_read_t)(struct vcpu *v, mmio_info_t *info,
Signature · 1 line
2.7.4
#77 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

Quoted 230 lines · Oleksandr Tyshchenko

From: Julien Grall <[email protected]>

This patch adds basic IOREQ/DM support on Arm. The subsequent patches will improve functionality and add remaining bits.

The IOREQ/DM features are supposed to be built with IOREQ_SERVER option enabled, which is disabled by default on Arm for now.

Please note, the "PIO handling" TODO is expected to left unaddressed for the current series. It is not an big issue for now while Xen doesn't have support for vPCI on Arm. On Arm64 they are only used for PCI IO Bar and we would probably want to expose them to emulator as PIO access to make a DM completely arch-agnostic. So "PIO handling" should be implemented when we add support for vPCI.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- was split into:
- arm/ioreq: Introduce arch specific bits for IOREQ/DM features
- xen/mm: Handle properly reference in set_foreign_p2m_entry() on Arm
- update patch description
- update asm-arm/hvm/ioreq.h according to the newly introduced arch functions:
- arch_hvm_destroy_ioreq_server()
- arch_handle_hvm_io_completion()
- update arch files to include xen/ioreq.h
- remove HVMOP plumbing
- rewrite a logic to handle properly case when hvm_send_ioreq() returns IO_RETRY
- add a logic to handle properly handle_hvm_io_completion() return value
- rename handle_mmio() to ioreq_handle_complete_mmio()
- move paging_mark_pfn_dirty() to asm-arm/paging.h
- remove forward declaration for hvm_ioreq_server in asm-arm/paging.h
- move try_fwd_ioserv() to ioreq.c, provide stubs if !CONFIG_IOREQ_SERVER
- do not remove #ifdef CONFIG_IOREQ_SERVER in memory.c for guarding xen/ioreq.h
- use gdprintk in try_fwd_ioserv(), remove unneeded prints
- update list of #include-s
- move has_vpci() to asm-arm/domain.h
- add a comment (TODO) to unimplemented yet handle_pio()
- remove hvm_mmio_first(last)_byte() and hvm_ioreq_(page/vcpu/server) structs from the arch files, they were already moved to the common code
- remove set_foreign_p2m_entry() changes, they will be properly implemented in the follow-up patch
- select IOREQ_SERVER for Arm instead of Arm64 in Kconfig
- remove x86's realmode and other unneeded stubs from xen/ioreq.h
- clafify ioreq_t p.df usage in try_fwd_ioserv()
- set ioreq_t p.count to 1 in try_fwd_ioserv()

Changes V1 -> V2:
- was split into:
- arm/ioreq: Introduce arch specific bits for IOREQ/DM features
- xen/arm: Stick around in leave_hypervisor_to_guest until I/O has completed
- update the author of a patch
- update patch description
- move a loop in leave_hypervisor_to_guest() to a separate patch
- set IOREQ_SERVER disabled by default
- remove already clarified /* XXX */
- replace BUG() by ASSERT_UNREACHABLE() in handle_pio()
- remove default case for handling the return value of try_handle_mmio()
- remove struct hvm_domain, enum hvm_io_completion, struct hvm_vcpu_io, struct hvm_vcpu from asm-arm/domain.h, these are common materials now
- update everything according to the recent changes (IOREQ related function names don't contain "hvm" prefixes/infixes anymore, IOREQ related fields are part of common struct vcpu/domain now, etc)

Changes V2 -> V3:
- update patch according the "legacy interface" is x86 specific
- add dummy arch hooks
- remove dummy paging_mark_pfn_dirty()
- don’t include <xen/domain_page.h> in common ioreq.c
- don’t include <public/hvm/ioreq.h> in arch ioreq.h
- remove #define ioreq_params(d, i)

Changes V3 -> V4:
- rebase
- update patch according to the renaming IO_ -> VIO_ (io_ -> vio_) and misc changes to arch hooks
- update patch according to the IOREQ related dm-op handling changes
- don't include <xen/ioreq.h> from arch header
- make all arch hooks out-of-line
- add a comment above IOREQ_STATUS_* #define-s

---
 xen/arch/arm/Makefile           |   2 +
 xen/arch/arm/dm.c               | 122 +++++++++++++++++++++++
 xen/arch/arm/domain.c           |   9 ++
 xen/arch/arm/io.c               |  12 ++-
 xen/arch/arm/ioreq.c            | 213 ++++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/traps.c            |  13 +++
 xen/include/asm-arm/domain.h    |   3 +
 xen/include/asm-arm/hvm/ioreq.h |  72 ++++++++++++++
 xen/include/asm-arm/mmio.h      |   1 +
 9 files changed, 446 insertions(+), 1 deletion(-)
 create mode 100644 xen/arch/arm/dm.c
 create mode 100644 xen/arch/arm/ioreq.c
 create mode 100644 xen/include/asm-arm/hvm/ioreq.h
xen/arch/arm/Makefile +2 -0
index 512ffdd..16e6523 100644
@@ -13,6 +13,7 @@ obj-y += cpuerrata.o
 obj-y += cpufeature.o
 obj-y += decode.o
 obj-y += device.o
+obj-$(CONFIG_IOREQ_SERVER) += dm.o
 obj-y += domain.o
 obj-y += domain_build.init.o
 obj-y += domctl.o
@@ -27,6 +28,7 @@ obj-y += guest_atomics.o
 obj-y += guest_walk.o
 obj-y += hvm.o
 obj-y += io.o
+obj-$(CONFIG_IOREQ_SERVER) += ioreq.o
 obj-y += irq.o
 obj-y += kernel.init.o
 obj-$(CONFIG_LIVEPATCH) += livepatch.o
xen/arch/arm/dm.c new file +102 -0
new file mode 100644
index 0000000..e6dedf4
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2019 Arm ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/dm.h>
+#include <xen/guest_access.h>
+#include <xen/hypercall.h>
+#include <xen/ioreq.h>
+#include <xen/nospec.h>
+
+static int dm_op(const struct dmop_args *op_args)
+{
+    struct domain *d;
+    struct xen_dm_op op;
+    bool const_op = true;
+    long rc;
+    size_t offset;
+
+    static const uint8_t op_size[] = {
+        [XEN_DMOP_create_ioreq_server]              = sizeof(struct xen_dm_op_create_ioreq_server),
+        [XEN_DMOP_get_ioreq_server_info]            = sizeof(struct xen_dm_op_get_ioreq_server_info),
+        [XEN_DMOP_map_io_range_to_ioreq_server]     = sizeof(struct xen_dm_op_ioreq_server_range),
+        [XEN_DMOP_unmap_io_range_from_ioreq_server] = sizeof(struct xen_dm_op_ioreq_server_range),
+        [XEN_DMOP_set_ioreq_server_state]           = sizeof(struct xen_dm_op_set_ioreq_server_state),
+        [XEN_DMOP_destroy_ioreq_server]             = sizeof(struct xen_dm_op_destroy_ioreq_server),
+    };
+
+    rc = rcu_lock_remote_domain_by_id(op_args->domid, &d);
+    if ( rc )
+        return rc;
+
+    rc = xsm_dm_op(XSM_DM_PRIV, d);
+    if ( rc )
+        goto out;
+
+    offset = offsetof(struct xen_dm_op, u);
+
+    rc = -EFAULT;
+    if ( op_args->buf[0].size < offset )
+        goto out;
+
+    if ( copy_from_guest_offset((void *)&op, op_args->buf[0].h, 0, offset) )
+        goto out;
+
+    if ( op.op >= ARRAY_SIZE(op_size) )
+    {
+        rc = -EOPNOTSUPP;
+        goto out;
+    }
+
+    op.op = array_index_nospec(op.op, ARRAY_SIZE(op_size));
+
+    if ( op_args->buf[0].size < offset + op_size[op.op] )
+        goto out;
+
+    if ( copy_from_guest_offset((void *)&op.u, op_args->buf[0].h, offset,
+                                op_size[op.op]) )
+        goto out;
+
+    rc = -EINVAL;
+    if ( op.pad )
+        goto out;
+
+    rc = ioreq_server_dm_op(&op, d, &const_op);
+
+    if ( (!rc || rc == -ERESTART) &&
+         !const_op && copy_to_guest_offset(op_args->buf[0].h, offset,
+                                           (void *)&op.u, op_size[op.op]) )
+        rc = -EFAULT;
+
+ out:
+    rcu_unlock_domain(d);
+
+    return rc;
+}
+
+long do_dm_op(domid_t domid,
+              unsigned int nr_bufs,
+              XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs)
+{
+    struct dmop_args args;
+    int rc;
+
+    if ( nr_bufs > ARRAY_SIZE(args.buf) )
+        return -E2BIG;
+
+    args.domid = domid;
+    args.nr_bufs = array_index_nospec(nr_bufs, ARRAY_SIZE(args.buf) + 1);
+
+    if ( copy_from_guest_offset(&args.buf[0], bufs, 0, args.nr_bufs) )

xen/arch/arm/dm.c line 112

Quoted 10 lines
xen/arch/arm/dm.c new file +10 -0
+        return -EFAULT;
+
+    rc = dm_op(&args);
+
+    if ( rc == -ERESTART )
+        rc = hypercall_create_continuation(__HYPERVISOR_dm_op, "iih",
+                                           domid, nr_bufs, bufs);
+
+    return rc;
+}

I might have missed something in the discussions but this function is identical to xen/arch/x86/hvm/dm.c:do_dm_op, why not make it common?

Also the previous function dm_op is very similar to xen/arch/x86/hvm/dm.c:dm_op I would prefer to make them common if possible. Was this already discussed?

Quoted 458 lines
xen/arch/arm/dm.c new file +9 -0
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/domain.c +9 -0
index 18cafcd..8f55aba 100644
@@ -15,6 +15,7 @@
 #include <xen/guest_access.h>
 #include <xen/hypercall.h>
 #include <xen/init.h>
+#include <xen/ioreq.h>
 #include <xen/lib.h>
 #include <xen/livepatch.h>
 #include <xen/sched.h>
@@ -696,6 +697,10 @@ int arch_domain_create(struct domain *d,
 
     ASSERT(config != NULL);
 
+#ifdef CONFIG_IOREQ_SERVER
+    ioreq_domain_init(d);
+#endif
+
     /* p2m_init relies on some value initialized by the IOMMU subsystem */
     if ( (rc = iommu_domain_init(d, config->iommu_opts)) != 0 )
         goto fail;
@@ -1014,6 +1019,10 @@ int domain_relinquish_resources(struct domain *d)
         if (ret )
             return ret;
 
+#ifdef CONFIG_IOREQ_SERVER
+        ioreq_server_destroy_all(d);
+#endif
+
     PROGRESS(xen):
         ret = relinquish_memory(d, &d->xenpage_list);
         if ( ret )
xen/arch/arm/io.c +11 -1
index ae7ef96..9814481 100644
@@ -16,6 +16,7 @@
  * GNU General Public License for more details.
  */
 
+#include <xen/ioreq.h>
 #include <xen/lib.h>
 #include <xen/spinlock.h>
 #include <xen/sched.h>
@@ -23,6 +24,7 @@
 #include <asm/cpuerrata.h>
 #include <asm/current.h>
 #include <asm/mmio.h>
+#include <asm/hvm/ioreq.h>
 
 #include "decode.h"
 
@@ -123,7 +125,15 @@ enum io_state try_handle_mmio(struct cpu_user_regs *regs,
 
     handler = find_mmio_handler(v->domain, info.gpa);
     if ( !handler )
-        return IO_UNHANDLED;
+    {
+        int rc;
+
+        rc = try_fwd_ioserv(regs, v, &info);
+        if ( rc == IO_HANDLED )
+            return handle_ioserv(regs, v);
+
+        return rc;
+    }
 
     /* All the instructions used on emulated MMIO region should be valid */
     if ( !dabt.valid )
xen/arch/arm/ioreq.c new file +213 -0
new file mode 100644
index 0000000..3c4a24d
@@ -0,0 +1,213 @@
+/*
+ * arm/ioreq.c: hardware virtual machine I/O emulation
+ *
+ * Copyright (c) 2019 Arm ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/domain.h>
+#include <xen/ioreq.h>
+
+#include <asm/traps.h>
+
+#include <public/hvm/ioreq.h>
+
+enum io_state handle_ioserv(struct cpu_user_regs *regs, struct vcpu *v)
+{
+    const union hsr hsr = { .bits = regs->hsr };
+    const struct hsr_dabt dabt = hsr.dabt;
+    /* Code is similar to handle_read */
+    uint8_t size = (1 << dabt.size) * 8;
+    register_t r = v->io.req.data;
+
+    /* We are done with the IO */
+    v->io.req.state = STATE_IOREQ_NONE;
+
+    if ( dabt.write )
+        return IO_HANDLED;
+
+    /*
+     * Sign extend if required.
+     * Note that we expect the read handler to have zeroed the bits
+     * outside the requested access size.
+     */
+    if ( dabt.sign && (r & (1UL << (size - 1))) )
+    {
+        /*
+         * We are relying on register_t using the same as
+         * an unsigned long in order to keep the 32-bit assembly
+         * code smaller.
+         */
+        BUILD_BUG_ON(sizeof(register_t) != sizeof(unsigned long));
+        r |= (~0UL) << size;
+    }
+
+    set_user_reg(regs, dabt.reg, r);
+
+    return IO_HANDLED;
+}
+
+enum io_state try_fwd_ioserv(struct cpu_user_regs *regs,
+                             struct vcpu *v, mmio_info_t *info)
+{
+    struct vcpu_io *vio = &v->io;
+    ioreq_t p = {
+        .type = IOREQ_TYPE_COPY,
+        .addr = info->gpa,
+        .size = 1 << info->dabt.size,
+        .count = 1,
+        .dir = !info->dabt.write,
+        /*
+         * On x86, df is used by 'rep' instruction to tell the direction
+         * to iterate (forward or backward).
+         * On Arm, all the accesses to MMIO region will do a single
+         * memory access. So for now, we can safely always set to 0.
+         */
+        .df = 0,
+        .data = get_user_reg(regs, info->dabt.reg),
+        .state = STATE_IOREQ_READY,
+    };
+    struct ioreq_server *s = NULL;
+    enum io_state rc;
+
+    switch ( vio->req.state )
+    {
+    case STATE_IOREQ_NONE:
+        break;
+
+    case STATE_IORESP_READY:
+        return IO_HANDLED;
+
+    default:
+        gdprintk(XENLOG_ERR, "wrong state %u\n", vio->req.state);
+        return IO_ABORT;
+    }
+
+    s = ioreq_server_select(v->domain, &p);
+    if ( !s )
+        return IO_UNHANDLED;
+
+    if ( !info->dabt.valid )
+        return IO_ABORT;
+
+    vio->req = p;
+
+    rc = ioreq_send(s, &p, 0);
+    if ( rc != IO_RETRY || v->domain->is_shutting_down )
+        vio->req.state = STATE_IOREQ_NONE;
+    else if ( !ioreq_needs_completion(&vio->req) )
+        rc = IO_HANDLED;
+    else
+        vio->completion = VIO_mmio_completion;
+
+    return rc;
+}
+
+bool arch_ioreq_complete_mmio(void)
+{
+    struct vcpu *v = current;
+    struct cpu_user_regs *regs = guest_cpu_user_regs();
+    const union hsr hsr = { .bits = regs->hsr };
+    paddr_t addr = v->io.req.addr;
+
+    if ( try_handle_mmio(regs, hsr, addr) == IO_HANDLED )
+    {
+        advance_pc(regs, hsr);
+        return true;
+    }
+
+    return false;
+}
+
+bool arch_vcpu_ioreq_completion(enum vio_completion completion)
+{
+    ASSERT_UNREACHABLE();
+    return true;
+}
+
+/*
+ * The "legacy" mechanism of mapping magic pages for the IOREQ servers
+ * is x86 specific, so the following hooks don't need to be implemented on Arm:
+ * - arch_ioreq_server_map_pages
+ * - arch_ioreq_server_unmap_pages
+ * - arch_ioreq_server_enable
+ * - arch_ioreq_server_disable
+ */
+int arch_ioreq_server_map_pages(struct ioreq_server *s)
+{
+    return -EOPNOTSUPP;
+}
+
+void arch_ioreq_server_unmap_pages(struct ioreq_server *s)
+{
+}
+
+void arch_ioreq_server_enable(struct ioreq_server *s)
+{
+}
+
+void arch_ioreq_server_disable(struct ioreq_server *s)
+{
+}
+
+void arch_ioreq_server_destroy(struct ioreq_server *s)
+{
+}
+
+int arch_ioreq_server_map_mem_type(struct domain *d,
+                                   struct ioreq_server *s,
+                                   uint32_t flags)
+{
+    return -EOPNOTSUPP;
+}
+
+void arch_ioreq_server_map_mem_type_completed(struct domain *d,
+                                              struct ioreq_server *s,
+                                              uint32_t flags)
+{
+}
+
+bool arch_ioreq_server_destroy_all(struct domain *d)
+{
+    return true;
+}
+
+bool arch_ioreq_server_get_type_addr(const struct domain *d,
+                                     const ioreq_t *p,
+                                     uint8_t *type,
+                                     uint64_t *addr)
+{
+    if ( p->type != IOREQ_TYPE_COPY && p->type != IOREQ_TYPE_PIO )
+        return false;
+
+    *type = (p->type == IOREQ_TYPE_PIO) ?
+             XEN_DMOP_IO_RANGE_PORT : XEN_DMOP_IO_RANGE_MEMORY;
+    *addr = p->addr;
+
+    return true;
+}
+
+void arch_ioreq_domain_init(struct domain *d)
+{
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/traps.c +13 -0
index 22bd1bd..036b13f 100644
@@ -21,6 +21,7 @@
 #include <xen/hypercall.h>
 #include <xen/init.h>
 #include <xen/iocap.h>
+#include <xen/ioreq.h>
 #include <xen/irq.h>
 #include <xen/lib.h>
 #include <xen/mem_access.h>
@@ -1385,6 +1386,9 @@ static arm_hypercall_t arm_hypercall_table[] = {
 #ifdef CONFIG_HYPFS
     HYPERCALL(hypfs_op, 5),
 #endif
+#ifdef CONFIG_IOREQ_SERVER
+    HYPERCALL(dm_op, 3),
+#endif
 };
 
 #ifndef NDEBUG
@@ -1956,6 +1960,9 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs,
             case IO_HANDLED:
                 advance_pc(regs, hsr);
                 return;
+            case IO_RETRY:
+                /* finish later */
+                return;
             case IO_UNHANDLED:
                 /* IO unhandled, try another way to handle it. */
                 break;
@@ -2254,6 +2261,12 @@ static void check_for_vcpu_work(void)
 {
     struct vcpu *v = current;
 
+#ifdef CONFIG_IOREQ_SERVER
+    local_irq_enable();
+    vcpu_ioreq_handle_completion(v);
+    local_irq_disable();
+#endif
+
     if ( likely(!v->arch.need_flush_to_ram) )
         return;
 
xen/include/asm-arm/domain.h +3 -0
index 6819a3b..c235e5b 100644
@@ -10,6 +10,7 @@
 #include <asm/gic.h>
 #include <asm/vgic.h>
 #include <asm/vpl011.h>
+#include <public/hvm/dm_op.h>
 #include <public/hvm/params.h>
 
 struct hvm_domain
@@ -262,6 +263,8 @@ static inline void arch_vcpu_block(struct vcpu *v) {}
 
 #define arch_vm_assist_valid_mask(d) (1UL << VMASST_TYPE_runstate_update_flag)
 
+#define has_vpci(d)    ({ (void)(d); false; })
+
 #endif /* __ASM_DOMAIN_H__ */
 
 /*
xen/include/asm-arm/hvm/ioreq.h new file +72 -0
new file mode 100644
index 0000000..19e1247
@@ -0,0 +1,72 @@
+/*
+ * hvm.h: Hardware virtual machine assist interface definitions.
+ *
+ * Copyright (c) 2016 Citrix Systems Inc.
+ * Copyright (c) 2019 Arm ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ASM_ARM_HVM_IOREQ_H__
+#define __ASM_ARM_HVM_IOREQ_H__
+
+#ifdef CONFIG_IOREQ_SERVER
+enum io_state handle_ioserv(struct cpu_user_regs *regs, struct vcpu *v);
+enum io_state try_fwd_ioserv(struct cpu_user_regs *regs,
+                             struct vcpu *v, mmio_info_t *info);
+#else
+static inline enum io_state handle_ioserv(struct cpu_user_regs *regs,
+                                          struct vcpu *v)
+{
+    return IO_UNHANDLED;
+}
+
+static inline enum io_state try_fwd_ioserv(struct cpu_user_regs *regs,
+                                           struct vcpu *v, mmio_info_t *info)
+{
+    return IO_UNHANDLED;
+}
+#endif
+
+bool ioreq_complete_mmio(void);
+
+static inline bool handle_pio(uint16_t port, unsigned int size, int dir)
+{
+    /*
+     * TODO: For Arm64, the main user will be PCI. So this should be
+     * implemented when we add support for vPCI.
+     */
+    ASSERT_UNREACHABLE();
+    return true;
+}
+
+static inline void msix_write_completion(struct vcpu *v)
+{
+}
+
+/* This correlation must not be altered */
+#define IOREQ_STATUS_HANDLED     IO_HANDLED
+#define IOREQ_STATUS_UNHANDLED   IO_UNHANDLED
+#define IOREQ_STATUS_RETRY       IO_RETRY
+
+#endif /* __ASM_ARM_HVM_IOREQ_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/asm-arm/mmio.h +1 -0
index 8dbfb27..7ab873c 100644
@@ -37,6 +37,7 @@ enum io_state
     IO_ABORT,       /* The IO was handled by the helper and led to an abort. */
     IO_HANDLED,     /* The IO was successfully handled by the helper. */
     IO_UNHANDLED,   /* The IO was not handled by the helper. */
+    IO_RETRY,       /* Retry the emulation for some reason */
 };
 
 typedef int (*mmio_read_t)(struct vcpu *v, mmio_info_t *info,
Signature · 1 line
2.7.4
#78 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

On 15.01.21 02:55, Stefano Stabellini wrote:

Hi Stefano

Quoted 244 lines · Oleksandr Tyshchenko
Quoted 230 lines

From: Julien Grall <[email protected]>

This patch adds basic IOREQ/DM support on Arm. The subsequent patches will improve functionality and add remaining bits.

The IOREQ/DM features are supposed to be built with IOREQ_SERVER option enabled, which is disabled by default on Arm for now.

Please note, the "PIO handling" TODO is expected to left unaddressed for the current series. It is not an big issue for now while Xen doesn't have support for vPCI on Arm. On Arm64 they are only used for PCI IO Bar and we would probably want to expose them to emulator as PIO access to make a DM completely arch-agnostic. So "PIO handling" should be implemented when we add support for vPCI.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- was split into:
- arm/ioreq: Introduce arch specific bits for IOREQ/DM features
- xen/mm: Handle properly reference in set_foreign_p2m_entry() on Arm
- update patch description
- update asm-arm/hvm/ioreq.h according to the newly introduced arch functions:
- arch_hvm_destroy_ioreq_server()
- arch_handle_hvm_io_completion()
- update arch files to include xen/ioreq.h
- remove HVMOP plumbing
- rewrite a logic to handle properly case when hvm_send_ioreq() returns IO_RETRY
- add a logic to handle properly handle_hvm_io_completion() return value
- rename handle_mmio() to ioreq_handle_complete_mmio()
- move paging_mark_pfn_dirty() to asm-arm/paging.h
- remove forward declaration for hvm_ioreq_server in asm-arm/paging.h
- move try_fwd_ioserv() to ioreq.c, provide stubs if !CONFIG_IOREQ_SERVER
- do not remove #ifdef CONFIG_IOREQ_SERVER in memory.c for guarding xen/ioreq.h
- use gdprintk in try_fwd_ioserv(), remove unneeded prints
- update list of #include-s
- move has_vpci() to asm-arm/domain.h
- add a comment (TODO) to unimplemented yet handle_pio()
- remove hvm_mmio_first(last)_byte() and hvm_ioreq_(page/vcpu/server) structs from the arch files, they were already moved to the common code
- remove set_foreign_p2m_entry() changes, they will be properly implemented in the follow-up patch
- select IOREQ_SERVER for Arm instead of Arm64 in Kconfig
- remove x86's realmode and other unneeded stubs from xen/ioreq.h
- clafify ioreq_t p.df usage in try_fwd_ioserv()
- set ioreq_t p.count to 1 in try_fwd_ioserv()

Changes V1 -> V2:
- was split into:
- arm/ioreq: Introduce arch specific bits for IOREQ/DM features
- xen/arm: Stick around in leave_hypervisor_to_guest until I/O has completed
- update the author of a patch
- update patch description
- move a loop in leave_hypervisor_to_guest() to a separate patch
- set IOREQ_SERVER disabled by default
- remove already clarified /* XXX */
- replace BUG() by ASSERT_UNREACHABLE() in handle_pio()
- remove default case for handling the return value of try_handle_mmio()
- remove struct hvm_domain, enum hvm_io_completion, struct hvm_vcpu_io, struct hvm_vcpu from asm-arm/domain.h, these are common materials now
- update everything according to the recent changes (IOREQ related function names don't contain "hvm" prefixes/infixes anymore, IOREQ related fields are part of common struct vcpu/domain now, etc)

Changes V2 -> V3:
- update patch according the "legacy interface" is x86 specific
- add dummy arch hooks
- remove dummy paging_mark_pfn_dirty()
- don’t include <xen/domain_page.h> in common ioreq.c
- don’t include <public/hvm/ioreq.h> in arch ioreq.h
- remove #define ioreq_params(d, i)

Changes V3 -> V4:
- rebase
- update patch according to the renaming IO_ -> VIO_ (io_ -> vio_) and misc changes to arch hooks
- update patch according to the IOREQ related dm-op handling changes
- don't include <xen/ioreq.h> from arch header
- make all arch hooks out-of-line
- add a comment above IOREQ_STATUS_* #define-s

---
  xen/arch/arm/Makefile           |   2 +
  xen/arch/arm/dm.c               | 122 +++++++++++++++++++++++
  xen/arch/arm/domain.c           |   9 ++
  xen/arch/arm/io.c               |  12 ++-
  xen/arch/arm/ioreq.c            | 213 ++++++++++++++++++++++++++++++++++++++++
  xen/arch/arm/traps.c            |  13 +++
  xen/include/asm-arm/domain.h    |   3 +
  xen/include/asm-arm/hvm/ioreq.h |  72 ++++++++++++++
  xen/include/asm-arm/mmio.h      |   1 +
  9 files changed, 446 insertions(+), 1 deletion(-)

create mode 100644 xen/arch/arm/dm.c create mode 100644 xen/arch/arm/ioreq.c create mode 100644 xen/include/asm-arm/hvm/ioreq.h

xen/arch/arm/Makefile +2 -0
index 512ffdd..16e6523 100644
@@ -13,6 +13,7 @@ obj-y += cpuerrata.o
  obj-y += cpufeature.o
  obj-y += decode.o
  obj-y += device.o
+obj-$(CONFIG_IOREQ_SERVER) += dm.o
  obj-y += domain.o
  obj-y += domain_build.init.o
  obj-y += domctl.o
@@ -27,6 +28,7 @@ obj-y += guest_atomics.o
  obj-y += guest_walk.o
  obj-y += hvm.o
  obj-y += io.o
+obj-$(CONFIG_IOREQ_SERVER) += ioreq.o
  obj-y += irq.o
  obj-y += kernel.init.o
  obj-$(CONFIG_LIVEPATCH) += livepatch.o
xen/arch/arm/dm.c new file +102 -0
new file mode 100644
index 0000000..e6dedf4
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2019 Arm ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/dm.h>
+#include <xen/guest_access.h>
+#include <xen/hypercall.h>
+#include <xen/ioreq.h>
+#include <xen/nospec.h>
+
+static int dm_op(const struct dmop_args *op_args)
+{
+    struct domain *d;
+    struct xen_dm_op op;
+    bool const_op = true;
+    long rc;
+    size_t offset;
+
+    static const uint8_t op_size[] = {
+        [XEN_DMOP_create_ioreq_server]              = sizeof(struct xen_dm_op_create_ioreq_server),
+        [XEN_DMOP_get_ioreq_server_info]            = sizeof(struct xen_dm_op_get_ioreq_server_info),
+        [XEN_DMOP_map_io_range_to_ioreq_server]     = sizeof(struct xen_dm_op_ioreq_server_range),
+        [XEN_DMOP_unmap_io_range_from_ioreq_server] = sizeof(struct xen_dm_op_ioreq_server_range),
+        [XEN_DMOP_set_ioreq_server_state]           = sizeof(struct xen_dm_op_set_ioreq_server_state),
+        [XEN_DMOP_destroy_ioreq_server]             = sizeof(struct xen_dm_op_destroy_ioreq_server),
+    };
+
+    rc = rcu_lock_remote_domain_by_id(op_args->domid, &d);
+    if ( rc )
+        return rc;
+
+    rc = xsm_dm_op(XSM_DM_PRIV, d);
+    if ( rc )
+        goto out;
+
+    offset = offsetof(struct xen_dm_op, u);
+
+    rc = -EFAULT;
+    if ( op_args->buf[0].size < offset )
+        goto out;
+
+    if ( copy_from_guest_offset((void *)&op, op_args->buf[0].h, 0, offset) )
+        goto out;
+
+    if ( op.op >= ARRAY_SIZE(op_size) )
+    {
+        rc = -EOPNOTSUPP;
+        goto out;
+    }
+
+    op.op = array_index_nospec(op.op, ARRAY_SIZE(op_size));
+
+    if ( op_args->buf[0].size < offset + op_size[op.op] )
+        goto out;
+
+    if ( copy_from_guest_offset((void *)&op.u, op_args->buf[0].h, offset,
+                                op_size[op.op]) )
+        goto out;
+
+    rc = -EINVAL;
+    if ( op.pad )
+        goto out;
+
+    rc = ioreq_server_dm_op(&op, d, &const_op);
+
+    if ( (!rc || rc == -ERESTART) &&
+         !const_op && copy_to_guest_offset(op_args->buf[0].h, offset,
+                                           (void *)&op.u, op_size[op.op]) )
+        rc = -EFAULT;
+
+ out:
+    rcu_unlock_domain(d);
+
+    return rc;
+}
+
+long do_dm_op(domid_t domid,
+              unsigned int nr_bufs,
+              XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs)
+{
+    struct dmop_args args;
+    int rc;
+
+    if ( nr_bufs > ARRAY_SIZE(args.buf) )
+        return -E2BIG;
+
+    args.domid = domid;
+    args.nr_bufs = array_index_nospec(nr_bufs, ARRAY_SIZE(args.buf) + 1);
+
+    if ( copy_from_guest_offset(&args.buf[0], bufs, 0, args.nr_bufs) )

xen/arch/arm/dm.c line 112

Quoted 10 lines
xen/arch/arm/dm.c new file +10 -0
+        return -EFAULT;
+
+    rc = dm_op(&args);
+
+    if ( rc == -ERESTART )
+        rc = hypercall_create_continuation(__HYPERVISOR_dm_op, "iih",
+                                           domid, nr_bufs, bufs);
+
+    return rc;
+}

I might have missed something in the discussions but this function is identical to xen/arch/x86/hvm/dm.c:do_dm_op, why not make it common?

Quoted 3 lines

Also the previous function dm_op is very similar to xen/arch/x86/hvm/dm.c:dm_op I would prefer to make them common if possible. Was this already discussed?

Well, let me explain. Both dm_op() and do_dm_op() were indeed common (top level dm-op handling common) for previous versions, so Arm's dm.c didn't contain this stuff. The idea to make it other way around (top level dm-op handling arch-specific and call into ioreq_server_dm_op() for otherwise unhandled ops) was discussed at [1] which besides it's Pros leads to code duplication, so Arm's dm.c has to duplicate some stuff, etc.
I was thinking about moving do_dm_op() which is _same_ for both arches to common code, but I am not sure whether it is conceptually correct which that new "alternative" approach of handling dm-op. Please see [2].

[1] https://lore.kernel.org/xen-devel/[email protected]/
[2] https://lore.kernel.org/xen-devel/[email protected]/

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
#79 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

Quoted 274 lines · Oleksandr
Quoted 270 lines · Stefano Stabellini
Quoted 256 lines · Oleksandr Tyshchenko

From: Julien Grall <[email protected]>

This patch adds basic IOREQ/DM support on Arm. The subsequent patches will improve functionality and add remaining bits.

The IOREQ/DM features are supposed to be built with IOREQ_SERVER option enabled, which is disabled by default on Arm for now.

Please note, the "PIO handling" TODO is expected to left unaddressed for the current series. It is not an big issue for now while Xen doesn't have support for vPCI on Arm. On Arm64 they are only used for PCI IO Bar and we would probably want to expose them to emulator as PIO access to make a DM completely arch-agnostic. So "PIO handling" should be implemented when we add support for vPCI.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- was split into:
- arm/ioreq: Introduce arch specific bits for IOREQ/DM features
- xen/mm: Handle properly reference in set_foreign_p2m_entry() on
Arm
- update patch description
- update asm-arm/hvm/ioreq.h according to the newly introduced arch
functions:
- arch_hvm_destroy_ioreq_server()
- arch_handle_hvm_io_completion()
- update arch files to include xen/ioreq.h
- remove HVMOP plumbing
- rewrite a logic to handle properly case when hvm_send_ioreq()
returns IO_RETRY
- add a logic to handle properly handle_hvm_io_completion() return
value
- rename handle_mmio() to ioreq_handle_complete_mmio()
- move paging_mark_pfn_dirty() to asm-arm/paging.h
- remove forward declaration for hvm_ioreq_server in asm-arm/paging.h
- move try_fwd_ioserv() to ioreq.c, provide stubs if
!CONFIG_IOREQ_SERVER
- do not remove #ifdef CONFIG_IOREQ_SERVER in memory.c for guarding
xen/ioreq.h
- use gdprintk in try_fwd_ioserv(), remove unneeded prints
- update list of #include-s
- move has_vpci() to asm-arm/domain.h
- add a comment (TODO) to unimplemented yet handle_pio()
- remove hvm_mmio_first(last)_byte() and hvm_ioreq_(page/vcpu/server)
structs
from the arch files, they were already moved to the common code
- remove set_foreign_p2m_entry() changes, they will be properly
implemented
in the follow-up patch
- select IOREQ_SERVER for Arm instead of Arm64 in Kconfig
- remove x86's realmode and other unneeded stubs from xen/ioreq.h
- clafify ioreq_t p.df usage in try_fwd_ioserv()
- set ioreq_t p.count to 1 in try_fwd_ioserv()

Changes V1 -> V2:
- was split into:
- arm/ioreq: Introduce arch specific bits for IOREQ/DM features
- xen/arm: Stick around in leave_hypervisor_to_guest until I/O has
completed
- update the author of a patch
- update patch description
- move a loop in leave_hypervisor_to_guest() to a separate patch
- set IOREQ_SERVER disabled by default
- remove already clarified /* XXX */
- replace BUG() by ASSERT_UNREACHABLE() in handle_pio()
- remove default case for handling the return value of
try_handle_mmio()
- remove struct hvm_domain, enum hvm_io_completion, struct
hvm_vcpu_io,
struct hvm_vcpu from asm-arm/domain.h, these are common materials
now
- update everything according to the recent changes (IOREQ related
function
names don't contain "hvm" prefixes/infixes anymore, IOREQ related
fields
are part of common struct vcpu/domain now, etc)

Changes V2 -> V3:
- update patch according the "legacy interface" is x86 specific
- add dummy arch hooks
- remove dummy paging_mark_pfn_dirty()
- don’t include <xen/domain_page.h> in common ioreq.c
- don’t include <public/hvm/ioreq.h> in arch ioreq.h
- remove #define ioreq_params(d, i)

Changes V3 -> V4:
- rebase
- update patch according to the renaming IO_ -> VIO_ (io_ -> vio_) and misc changes to arch hooks
- update patch according to the IOREQ related dm-op handling changes
- don't include <xen/ioreq.h> from arch header
- make all arch hooks out-of-line
- add a comment above IOREQ_STATUS_* #define-s

---
  xen/arch/arm/Makefile           |   2 +
  xen/arch/arm/dm.c               | 122 +++++++++++++++++++++++
  xen/arch/arm/domain.c           |   9 ++
  xen/arch/arm/io.c               |  12 ++-
  xen/arch/arm/ioreq.c            | 213
++++++++++++++++++++++++++++++++++++++++
  xen/arch/arm/traps.c            |  13 +++
  xen/include/asm-arm/domain.h    |   3 +
  xen/include/asm-arm/hvm/ioreq.h |  72 ++++++++++++++
  xen/include/asm-arm/mmio.h      |   1 +
  9 files changed, 446 insertions(+), 1 deletion(-)

create mode 100644 xen/arch/arm/dm.c create mode 100644 xen/arch/arm/ioreq.c create mode 100644 xen/include/asm-arm/hvm/ioreq.h

xen/arch/arm/Makefile +2 -0
index 512ffdd..16e6523 100644
@@ -13,6 +13,7 @@ obj-y += cpuerrata.o
  obj-y += cpufeature.o
  obj-y += decode.o
  obj-y += device.o
+obj-$(CONFIG_IOREQ_SERVER) += dm.o
  obj-y += domain.o
  obj-y += domain_build.init.o
  obj-y += domctl.o
@@ -27,6 +28,7 @@ obj-y += guest_atomics.o
  obj-y += guest_walk.o
  obj-y += hvm.o
  obj-y += io.o
+obj-$(CONFIG_IOREQ_SERVER) += ioreq.o
  obj-y += irq.o
  obj-y += kernel.init.o
  obj-$(CONFIG_LIVEPATCH) += livepatch.o
xen/arch/arm/dm.c new file +4 -0
new file mode 100644
index 0000000..e6dedf4
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2019 Arm ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify

it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */

xen/arch/arm/dm.c new file +17 -0
+
+#include <xen/dm.h>
+#include <xen/guest_access.h>
+#include <xen/hypercall.h>
+#include <xen/ioreq.h>
+#include <xen/nospec.h>
+
+static int dm_op(const struct dmop_args *op_args)
+{
+    struct domain *d;
+    struct xen_dm_op op;
+    bool const_op = true;
+    long rc;
+    size_t offset;
+
+    static const uint8_t op_size[] = {
+        [XEN_DMOP_create_ioreq_server]              = sizeof(struct

xen_dm_op_create_ioreq_server),
+ [XEN_DMOP_get_ioreq_server_info] = sizeof(struct
xen_dm_op_get_ioreq_server_info),
+ [XEN_DMOP_map_io_range_to_ioreq_server] = sizeof(struct
xen_dm_op_ioreq_server_range),
+ [XEN_DMOP_unmap_io_range_from_ioreq_server] = sizeof(struct
xen_dm_op_ioreq_server_range),
+ [XEN_DMOP_set_ioreq_server_state] = sizeof(struct
xen_dm_op_set_ioreq_server_state),
+ [XEN_DMOP_destroy_ioreq_server] = sizeof(struct
xen_dm_op_destroy_ioreq_server),

xen/arch/arm/dm.c new file +17 -0
+    };
+
+    rc = rcu_lock_remote_domain_by_id(op_args->domid, &d);
+    if ( rc )
+        return rc;
+
+    rc = xsm_dm_op(XSM_DM_PRIV, d);
+    if ( rc )
+        goto out;
+
+    offset = offsetof(struct xen_dm_op, u);
+
+    rc = -EFAULT;
+    if ( op_args->buf[0].size < offset )
+        goto out;
+
+    if ( copy_from_guest_offset((void *)&op, op_args->buf[0].h, 0,

offset) )

xen/arch/arm/dm.c new file +26 -0
+        goto out;
+
+    if ( op.op >= ARRAY_SIZE(op_size) )
+    {
+        rc = -EOPNOTSUPP;
+        goto out;
+    }
+
+    op.op = array_index_nospec(op.op, ARRAY_SIZE(op_size));
+
+    if ( op_args->buf[0].size < offset + op_size[op.op] )
+        goto out;
+
+    if ( copy_from_guest_offset((void *)&op.u, op_args->buf[0].h, offset,
+                                op_size[op.op]) )
+        goto out;
+
+    rc = -EINVAL;
+    if ( op.pad )
+        goto out;
+
+    rc = ioreq_server_dm_op(&op, d, &const_op);
+
+    if ( (!rc || rc == -ERESTART) &&
+         !const_op && copy_to_guest_offset(op_args->buf[0].h, offset,
+                                           (void *)&op.u, op_size[op.op])

)

xen/arch/arm/dm.c new file +22 -0
+        rc = -EFAULT;
+
+ out:
+    rcu_unlock_domain(d);
+
+    return rc;
+}
+
+long do_dm_op(domid_t domid,
+              unsigned int nr_bufs,
+              XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs)
+{
+    struct dmop_args args;
+    int rc;
+
+    if ( nr_bufs > ARRAY_SIZE(args.buf) )
+        return -E2BIG;
+
+    args.domid = domid;
+    args.nr_bufs = array_index_nospec(nr_bufs, ARRAY_SIZE(args.buf) + 1);
+
+    if ( copy_from_guest_offset(&args.buf[0], bufs, 0, args.nr_bufs) )

xen/arch/arm/dm.c line 112

Quoted 10 lines
xen/arch/arm/dm.c new file +10 -0
+        return -EFAULT;
+
+    rc = dm_op(&args);
+
+    if ( rc == -ERESTART )
+        rc = hypercall_create_continuation(__HYPERVISOR_dm_op, "iih",
+                                           domid, nr_bufs, bufs);
+
+    return rc;
+}

I might have missed something in the discussions but this function is identical to xen/arch/x86/hvm/dm.c:do_dm_op, why not make it common?

Quoted 3 lines

Also the previous function dm_op is very similar to xen/arch/x86/hvm/dm.c:dm_op I would prefer to make them common if possible. Was this already discussed?

Quoted 11 lines

Well, let me explain. Both dm_op() and do_dm_op() were indeed common (top level dm-op handling common) for previous versions, so Arm's dm.c didn't contain this stuff.
The idea to make it other way around (top level dm-op handling arch-specific and call into ioreq_server_dm_op() for otherwise unhandled ops) was discussed at [1] which besides
it's Pros leads to code duplication, so Arm's dm.c has to duplicate some stuff, etc.
I was thinking about moving do_dm_op() which is _same_ for both arches to common code, but I am not sure whether it is conceptually correct which that new "alternative" approach of handling dm-op.

Yes, I think it makes sense to make do_dm_op common because it is identical. That should be easy.

I realize that the common part of dm_op is the initial boilerplate which is similar for every hypercall, so I think it is also OK if we don't share it and leave it as it is in this version of the series.

#80 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

On 20.01.21 02:23, Stefano Stabellini wrote:

Hi Stefano

Quoted 286 lines · Oleksandr
Quoted 274 lines · Stefano Stabellini
Quoted 270 lines · Oleksandr Tyshchenko
Quoted 256 lines

From: Julien Grall <[email protected]>

This patch adds basic IOREQ/DM support on Arm. The subsequent patches will improve functionality and add remaining bits.

The IOREQ/DM features are supposed to be built with IOREQ_SERVER option enabled, which is disabled by default on Arm for now.

Please note, the "PIO handling" TODO is expected to left unaddressed for the current series. It is not an big issue for now while Xen doesn't have support for vPCI on Arm. On Arm64 they are only used for PCI IO Bar and we would probably want to expose them to emulator as PIO access to make a DM completely arch-agnostic. So "PIO handling" should be implemented when we add support for vPCI.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
- was split into:
- arm/ioreq: Introduce arch specific bits for IOREQ/DM features
- xen/mm: Handle properly reference in set_foreign_p2m_entry() on
Arm
- update patch description
- update asm-arm/hvm/ioreq.h according to the newly introduced arch
functions:
- arch_hvm_destroy_ioreq_server()
- arch_handle_hvm_io_completion()
- update arch files to include xen/ioreq.h
- remove HVMOP plumbing
- rewrite a logic to handle properly case when hvm_send_ioreq()
returns IO_RETRY
- add a logic to handle properly handle_hvm_io_completion() return
value
- rename handle_mmio() to ioreq_handle_complete_mmio()
- move paging_mark_pfn_dirty() to asm-arm/paging.h
- remove forward declaration for hvm_ioreq_server in asm-arm/paging.h
- move try_fwd_ioserv() to ioreq.c, provide stubs if
!CONFIG_IOREQ_SERVER
- do not remove #ifdef CONFIG_IOREQ_SERVER in memory.c for guarding
xen/ioreq.h
- use gdprintk in try_fwd_ioserv(), remove unneeded prints
- update list of #include-s
- move has_vpci() to asm-arm/domain.h
- add a comment (TODO) to unimplemented yet handle_pio()
- remove hvm_mmio_first(last)_byte() and hvm_ioreq_(page/vcpu/server)
structs
from the arch files, they were already moved to the common code
- remove set_foreign_p2m_entry() changes, they will be properly
implemented
in the follow-up patch
- select IOREQ_SERVER for Arm instead of Arm64 in Kconfig
- remove x86's realmode and other unneeded stubs from xen/ioreq.h
- clafify ioreq_t p.df usage in try_fwd_ioserv()
- set ioreq_t p.count to 1 in try_fwd_ioserv()

Changes V1 -> V2:
- was split into:
- arm/ioreq: Introduce arch specific bits for IOREQ/DM features
- xen/arm: Stick around in leave_hypervisor_to_guest until I/O has
completed
- update the author of a patch
- update patch description
- move a loop in leave_hypervisor_to_guest() to a separate patch
- set IOREQ_SERVER disabled by default
- remove already clarified /* XXX */
- replace BUG() by ASSERT_UNREACHABLE() in handle_pio()
- remove default case for handling the return value of
try_handle_mmio()
- remove struct hvm_domain, enum hvm_io_completion, struct
hvm_vcpu_io,
struct hvm_vcpu from asm-arm/domain.h, these are common materials
now
- update everything according to the recent changes (IOREQ related
function
names don't contain "hvm" prefixes/infixes anymore, IOREQ related
fields
are part of common struct vcpu/domain now, etc)

Changes V2 -> V3:
- update patch according the "legacy interface" is x86 specific
- add dummy arch hooks
- remove dummy paging_mark_pfn_dirty()
- don’t include <xen/domain_page.h> in common ioreq.c
- don’t include <public/hvm/ioreq.h> in arch ioreq.h
- remove #define ioreq_params(d, i)

Changes V3 -> V4:
- rebase
- update patch according to the renaming IO_ -> VIO_ (io_ -> vio_) and misc changes to arch hooks
- update patch according to the IOREQ related dm-op handling changes
- don't include <xen/ioreq.h> from arch header
- make all arch hooks out-of-line
- add a comment above IOREQ_STATUS_* #define-s

---
   xen/arch/arm/Makefile           |   2 +
   xen/arch/arm/dm.c               | 122 +++++++++++++++++++++++
   xen/arch/arm/domain.c           |   9 ++
   xen/arch/arm/io.c               |  12 ++-
   xen/arch/arm/ioreq.c            | 213
++++++++++++++++++++++++++++++++++++++++
   xen/arch/arm/traps.c            |  13 +++
   xen/include/asm-arm/domain.h    |   3 +
   xen/include/asm-arm/hvm/ioreq.h |  72 ++++++++++++++
   xen/include/asm-arm/mmio.h      |   1 +
   9 files changed, 446 insertions(+), 1 deletion(-)

create mode 100644 xen/arch/arm/dm.c create mode 100644 xen/arch/arm/ioreq.c create mode 100644 xen/include/asm-arm/hvm/ioreq.h

xen/arch/arm/Makefile +2 -0
index 512ffdd..16e6523 100644
@@ -13,6 +13,7 @@ obj-y += cpuerrata.o
   obj-y += cpufeature.o
   obj-y += decode.o
   obj-y += device.o
+obj-$(CONFIG_IOREQ_SERVER) += dm.o
   obj-y += domain.o
   obj-y += domain_build.init.o
   obj-y += domctl.o
@@ -27,6 +28,7 @@ obj-y += guest_atomics.o
   obj-y += guest_walk.o
   obj-y += hvm.o
   obj-y += io.o
+obj-$(CONFIG_IOREQ_SERVER) += ioreq.o
   obj-y += irq.o
   obj-y += kernel.init.o
   obj-$(CONFIG_LIVEPATCH) += livepatch.o
xen/arch/arm/dm.c new file +4 -0
new file mode 100644
index 0000000..e6dedf4
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2019 Arm ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify

it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */

xen/arch/arm/dm.c new file +17 -0
+
+#include <xen/dm.h>
+#include <xen/guest_access.h>
+#include <xen/hypercall.h>
+#include <xen/ioreq.h>
+#include <xen/nospec.h>
+
+static int dm_op(const struct dmop_args *op_args)
+{
+    struct domain *d;
+    struct xen_dm_op op;
+    bool const_op = true;
+    long rc;
+    size_t offset;
+
+    static const uint8_t op_size[] = {
+        [XEN_DMOP_create_ioreq_server]              = sizeof(struct

xen_dm_op_create_ioreq_server),
+ [XEN_DMOP_get_ioreq_server_info] = sizeof(struct
xen_dm_op_get_ioreq_server_info),
+ [XEN_DMOP_map_io_range_to_ioreq_server] = sizeof(struct
xen_dm_op_ioreq_server_range),
+ [XEN_DMOP_unmap_io_range_from_ioreq_server] = sizeof(struct
xen_dm_op_ioreq_server_range),
+ [XEN_DMOP_set_ioreq_server_state] = sizeof(struct
xen_dm_op_set_ioreq_server_state),
+ [XEN_DMOP_destroy_ioreq_server] = sizeof(struct
xen_dm_op_destroy_ioreq_server),

xen/arch/arm/dm.c new file +17 -0
+    };
+
+    rc = rcu_lock_remote_domain_by_id(op_args->domid, &d);
+    if ( rc )
+        return rc;
+
+    rc = xsm_dm_op(XSM_DM_PRIV, d);
+    if ( rc )
+        goto out;
+
+    offset = offsetof(struct xen_dm_op, u);
+
+    rc = -EFAULT;
+    if ( op_args->buf[0].size < offset )
+        goto out;
+
+    if ( copy_from_guest_offset((void *)&op, op_args->buf[0].h, 0,

offset) )

xen/arch/arm/dm.c new file +26 -0
+        goto out;
+
+    if ( op.op >= ARRAY_SIZE(op_size) )
+    {
+        rc = -EOPNOTSUPP;
+        goto out;
+    }
+
+    op.op = array_index_nospec(op.op, ARRAY_SIZE(op_size));
+
+    if ( op_args->buf[0].size < offset + op_size[op.op] )
+        goto out;
+
+    if ( copy_from_guest_offset((void *)&op.u, op_args->buf[0].h, offset,
+                                op_size[op.op]) )
+        goto out;
+
+    rc = -EINVAL;
+    if ( op.pad )
+        goto out;
+
+    rc = ioreq_server_dm_op(&op, d, &const_op);
+
+    if ( (!rc || rc == -ERESTART) &&
+         !const_op && copy_to_guest_offset(op_args->buf[0].h, offset,
+                                           (void *)&op.u, op_size[op.op])

)

xen/arch/arm/dm.c new file +22 -0
+        rc = -EFAULT;
+
+ out:
+    rcu_unlock_domain(d);
+
+    return rc;
+}
+
+long do_dm_op(domid_t domid,
+              unsigned int nr_bufs,
+              XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs)
+{
+    struct dmop_args args;
+    int rc;
+
+    if ( nr_bufs > ARRAY_SIZE(args.buf) )
+        return -E2BIG;
+
+    args.domid = domid;
+    args.nr_bufs = array_index_nospec(nr_bufs, ARRAY_SIZE(args.buf) + 1);
+
+    if ( copy_from_guest_offset(&args.buf[0], bufs, 0, args.nr_bufs) )

xen/arch/arm/dm.c line 112

Quoted 10 lines
xen/arch/arm/dm.c new file +10 -0
+        return -EFAULT;
+
+    rc = dm_op(&args);
+
+    if ( rc == -ERESTART )
+        rc = hypercall_create_continuation(__HYPERVISOR_dm_op, "iih",
+                                           domid, nr_bufs, bufs);
+
+    return rc;
+}

I might have missed something in the discussions but this function is identical to xen/arch/x86/hvm/dm.c:do_dm_op, why not make it common?

Quoted 3 lines

Also the previous function dm_op is very similar to xen/arch/x86/hvm/dm.c:dm_op I would prefer to make them common if possible. Was this already discussed?

Quoted 11 lines

Well, let me explain. Both dm_op() and do_dm_op() were indeed common (top level dm-op handling common) for previous versions, so Arm's dm.c didn't contain this stuff.
The idea to make it other way around (top level dm-op handling arch-specific and call into ioreq_server_dm_op() for otherwise unhandled ops) was discussed at [1] which besides
it's Pros leads to code duplication, so Arm's dm.c has to duplicate some stuff, etc.
I was thinking about moving do_dm_op() which is _same_ for both arches to common code, but I am not sure whether it is conceptually correct which that new "alternative" approach of handling dm-op.

Quoted 2 lines

Yes, I think it makes sense to make do_dm_op common because it is identical. That should be easy.

Absolutely identical) Agree, technically it is not hard. Well, let's continue discussion in [1] (which actually leads to the duplication) to see if all parties are happy with that.

Quoted 4 lines

I realize that the common part of dm_op is the initial boilerplate which is similar for every hypercall, so I think it is also OK if we don't share it and leave it as it is in this version of the series.

ok

[1] https://lore.kernel.org/xen-devel/[email protected]/

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
#81 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

In reply to Oleksandr Tyshchenko
Quoted 24 lines · Oleksandr Tyshchenko
xen/arch/arm/domain.c +5 -0
index 18cafcd..8f55aba 100644
@@ -15,6 +15,7 @@
  #include <xen/guest_access.h>
  #include <xen/hypercall.h>
  #include <xen/init.h>
+#include <xen/ioreq.h>
  #include <xen/lib.h>
  #include <xen/livepatch.h>
  #include <xen/sched.h>
@@ -696,6 +697,10 @@ int arch_domain_create(struct domain *d,
 
      ASSERT(config != NULL);
 
+#ifdef CONFIG_IOREQ_SERVER
+    ioreq_domain_init(d);
+#endif
+
      /* p2m_init relies on some value initialized by the IOMMU subsystem */
      if ( (rc = iommu_domain_init(d, config->iommu_opts)) != 0 )
          goto fail;

xen/arch/arm/domain.c int domain_relinquish_resources(struct domain *d) · line 1024

Quoted 6 lines
xen/arch/arm/domain.c +3 -0
@@ -1014,6 +1019,10 @@ int domain_relinquish_resources(struct domain *d)
          if (ret )
              return ret;
 
+#ifdef CONFIG_IOREQ_SERVER
+        ioreq_server_destroy_all(d);
+#endif

The placement of this call feels quite odd. Shouldn't this moved in case 0?

Quoted 17 lines
xen/arch/arm/domain.c +1 -0
+
      PROGRESS(xen):
          ret = relinquish_memory(d, &d->xenpage_list);
          if ( ret )
xen/arch/arm/io.c +1 -0
index ae7ef96..9814481 100644
@@ -16,6 +16,7 @@
   * GNU General Public License for more details.
   */
 
+#include <xen/ioreq.h>
  #include <xen/lib.h>
  #include <xen/spinlock.h>
  #include <xen/sched.h>

xen/arch/arm/io.c line 27

Quoted 4 lines
xen/arch/arm/io.c +1 -0
@@ -23,6 +24,7 @@
  #include <asm/cpuerrata.h>
  #include <asm/current.h>
  #include <asm/mmio.h>
+#include <asm/hvm/ioreq.h>

Shouldn't this have been included by "xen/ioreq.h"?

Quoted 70 lines
xen/arch/arm/io.c +9 -1
  #include "decode.h"
 
@@ -123,7 +125,15 @@ enum io_state try_handle_mmio(struct cpu_user_regs *regs,
 
      handler = find_mmio_handler(v->domain, info.gpa);
      if ( !handler )
-        return IO_UNHANDLED;
+    {
+        int rc;
+
+        rc = try_fwd_ioserv(regs, v, &info);
+        if ( rc == IO_HANDLED )
+            return handle_ioserv(regs, v);
+
+        return rc;
+    }
 
      /* All the instructions used on emulated MMIO region should be valid */
      if ( !dabt.valid )
xen/arch/arm/ioreq.c new file +44 -0
new file mode 100644
index 0000000..3c4a24d
@@ -0,0 +1,213 @@
+/*
+ * arm/ioreq.c: hardware virtual machine I/O emulation
+ *
+ * Copyright (c) 2019 Arm ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/domain.h>
+#include <xen/ioreq.h>
+
+#include <asm/traps.h>
+
+#include <public/hvm/ioreq.h>
+
+enum io_state handle_ioserv(struct cpu_user_regs *regs, struct vcpu *v)
+{
+    const union hsr hsr = { .bits = regs->hsr };
+    const struct hsr_dabt dabt = hsr.dabt;
+    /* Code is similar to handle_read */
+    uint8_t size = (1 << dabt.size) * 8;
+    register_t r = v->io.req.data;
+
+    /* We are done with the IO */
+    v->io.req.state = STATE_IOREQ_NONE;
+
+    if ( dabt.write )
+        return IO_HANDLED;
+
+    /*
+     * Sign extend if required.
+     * Note that we expect the read handler to have zeroed the bits
+     * outside the requested access size.
+     */

xen/arch/arm/ioreq.c line 54

Quoted 10 lines
xen/arch/arm/ioreq.c new file +10 -0
+    if ( dabt.sign && (r & (1UL << (size - 1))) )
+    {
+        /*
+         * We are relying on register_t using the same as
+         * an unsigned long in order to keep the 32-bit assembly
+         * code smaller.
+         */
+        BUILD_BUG_ON(sizeof(register_t) != sizeof(unsigned long));
+        r |= (~0UL) << size;
+    }

Looking at the rest of the series, this code is going to be refactored in patch #19 and then hardened. It would have been better to do the refactoring first and then use it.

This helps a lot for the review and to reduce what I would call churn in the series.

I am OK to keep it like that for this series.

Quoted 26 lines
xen/arch/arm/ioreq.c new file +26 -0
+
+    set_user_reg(regs, dabt.reg, r);
+
+    return IO_HANDLED;
+}
+
+enum io_state try_fwd_ioserv(struct cpu_user_regs *regs,
+                             struct vcpu *v, mmio_info_t *info)
+{
+    struct vcpu_io *vio = &v->io;
+    ioreq_t p = {
+        .type = IOREQ_TYPE_COPY,
+        .addr = info->gpa,
+        .size = 1 << info->dabt.size,
+        .count = 1,
+        .dir = !info->dabt.write,
+        /*
+         * On x86, df is used by 'rep' instruction to tell the direction
+         * to iterate (forward or backward).
+         * On Arm, all the accesses to MMIO region will do a single
+         * memory access. So for now, we can safely always set to 0.
+         */
+        .df = 0,
+        .data = get_user_reg(regs, info->dabt.reg),
+        .state = STATE_IOREQ_READY,
+    };

xen/arch/arm/ioreq.c line 90

Quoted 10 lines
xen/arch/arm/ioreq.c new file +10 -0
+    struct ioreq_server *s = NULL;
+    enum io_state rc;
+
+    switch ( vio->req.state )
+    {
+    case STATE_IOREQ_NONE:
+        break;
+
+    case STATE_IORESP_READY:
+        return IO_HANDLED;

With the Arm code in mind, I am a bit confused with this check. If vio->req.state == STATE_IORESP_READY, then it would imply that the previous I/O emulation was somehow not completed (from Xen PoV).

If you return IO_HANDLED here, then it means the we will take care of previous I/O but the current one is going to be ignored. So shouldn't we use the default path here as well?

Quoted 173 lines
xen/arch/arm/ioreq.c new file +123 -0
+
+    default:
+        gdprintk(XENLOG_ERR, "wrong state %u\n", vio->req.state);
+        return IO_ABORT;
+    }
+
+    s = ioreq_server_select(v->domain, &p);
+    if ( !s )
+        return IO_UNHANDLED;
+
+    if ( !info->dabt.valid )
+        return IO_ABORT;
+
+    vio->req = p;
+
+    rc = ioreq_send(s, &p, 0);
+    if ( rc != IO_RETRY || v->domain->is_shutting_down )
+        vio->req.state = STATE_IOREQ_NONE;
+    else if ( !ioreq_needs_completion(&vio->req) )
+        rc = IO_HANDLED;
+    else
+        vio->completion = VIO_mmio_completion;
+
+    return rc;
+}
+
+bool arch_ioreq_complete_mmio(void)
+{
+    struct vcpu *v = current;
+    struct cpu_user_regs *regs = guest_cpu_user_regs();
+    const union hsr hsr = { .bits = regs->hsr };
+    paddr_t addr = v->io.req.addr;
+
+    if ( try_handle_mmio(regs, hsr, addr) == IO_HANDLED )
+    {
+        advance_pc(regs, hsr);
+        return true;
+    }
+
+    return false;
+}
+
+bool arch_vcpu_ioreq_completion(enum vio_completion completion)
+{
+    ASSERT_UNREACHABLE();
+    return true;
+}
+
+/*
+ * The "legacy" mechanism of mapping magic pages for the IOREQ servers
+ * is x86 specific, so the following hooks don't need to be implemented on Arm:
+ * - arch_ioreq_server_map_pages
+ * - arch_ioreq_server_unmap_pages
+ * - arch_ioreq_server_enable
+ * - arch_ioreq_server_disable
+ */
+int arch_ioreq_server_map_pages(struct ioreq_server *s)
+{
+    return -EOPNOTSUPP;
+}
+
+void arch_ioreq_server_unmap_pages(struct ioreq_server *s)
+{
+}
+
+void arch_ioreq_server_enable(struct ioreq_server *s)
+{
+}
+
+void arch_ioreq_server_disable(struct ioreq_server *s)
+{
+}
+
+void arch_ioreq_server_destroy(struct ioreq_server *s)
+{
+}
+
+int arch_ioreq_server_map_mem_type(struct domain *d,
+                                   struct ioreq_server *s,
+                                   uint32_t flags)
+{
+    return -EOPNOTSUPP;
+}
+
+void arch_ioreq_server_map_mem_type_completed(struct domain *d,
+                                              struct ioreq_server *s,
+                                              uint32_t flags)
+{
+}
+
+bool arch_ioreq_server_destroy_all(struct domain *d)
+{
+    return true;
+}
+
+bool arch_ioreq_server_get_type_addr(const struct domain *d,
+                                     const ioreq_t *p,
+                                     uint8_t *type,
+                                     uint64_t *addr)
+{
+    if ( p->type != IOREQ_TYPE_COPY && p->type != IOREQ_TYPE_PIO )
+        return false;
+
+    *type = (p->type == IOREQ_TYPE_PIO) ?
+             XEN_DMOP_IO_RANGE_PORT : XEN_DMOP_IO_RANGE_MEMORY;
+    *addr = p->addr;
+
+    return true;
+}
+
+void arch_ioreq_domain_init(struct domain *d)
+{
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/traps.c +13 -0
index 22bd1bd..036b13f 100644
@@ -21,6 +21,7 @@
  #include <xen/hypercall.h>
  #include <xen/init.h>
  #include <xen/iocap.h>
+#include <xen/ioreq.h>
  #include <xen/irq.h>
  #include <xen/lib.h>
  #include <xen/mem_access.h>
@@ -1385,6 +1386,9 @@ static arm_hypercall_t arm_hypercall_table[] = {
  #ifdef CONFIG_HYPFS
      HYPERCALL(hypfs_op, 5),
  #endif
+#ifdef CONFIG_IOREQ_SERVER
+    HYPERCALL(dm_op, 3),
+#endif
  };
 
  #ifndef NDEBUG
@@ -1956,6 +1960,9 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs,
              case IO_HANDLED:
                  advance_pc(regs, hsr);
                  return;
+            case IO_RETRY:
+                /* finish later */
+                return;
              case IO_UNHANDLED:
                  /* IO unhandled, try another way to handle it. */
                  break;
@@ -2254,6 +2261,12 @@ static void check_for_vcpu_work(void)
  {
      struct vcpu *v = current;
 
+#ifdef CONFIG_IOREQ_SERVER
+    local_irq_enable();
+    vcpu_ioreq_handle_completion(v);
+    local_irq_disable();
+#endif
+
      if ( likely(!v->arch.need_flush_to_ram) )
          return;
 
xen/include/asm-arm/domain.h +0 -0
index 6819a3b..c235e5b 100644

xen/include/asm-arm/domain.h line 13

Quoted 4 lines
xen/include/asm-arm/domain.h +1 -0
@@ -10,6 +10,7 @@
  #include <asm/gic.h>
  #include <asm/vgic.h>
  #include <asm/vpl011.h>
+#include <public/hvm/dm_op.h>

May I ask, why do you need to include dm_op.h here?

xen/include/asm-arm/hvm/ioreq.h

Quoted 17 lines
xen/include/asm-arm/domain.h +2 -0
  #include <public/hvm/params.h>
 
  struct hvm_domain
@@ -262,6 +263,8 @@ static inline void arch_vcpu_block(struct vcpu *v) {}
 
  #define arch_vm_assist_valid_mask(d) (1UL << VMASST_TYPE_runstate_update_flag)
 
+#define has_vpci(d)    ({ (void)(d); false; })
+
  #endif /* __ASM_DOMAIN_H__ */
 
  /*
xen/include/asm-arm/hvm/ioreq.h new file +0 -0
new file mode 100644
index 0000000..19e1247

Shouldn't this directly be under asm-arm/ rather than asm-arm/hvm/ as the IOREQ is now meant to be agnostic?

Quoted 86 lines
xen/include/asm-arm/hvm/ioreq.h new file +72 -0
@@ -0,0 +1,72 @@
+/*
+ * hvm.h: Hardware virtual machine assist interface definitions.
+ *
+ * Copyright (c) 2016 Citrix Systems Inc.
+ * Copyright (c) 2019 Arm ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ASM_ARM_HVM_IOREQ_H__
+#define __ASM_ARM_HVM_IOREQ_H__
+
+#ifdef CONFIG_IOREQ_SERVER
+enum io_state handle_ioserv(struct cpu_user_regs *regs, struct vcpu *v);
+enum io_state try_fwd_ioserv(struct cpu_user_regs *regs,
+                             struct vcpu *v, mmio_info_t *info);
+#else
+static inline enum io_state handle_ioserv(struct cpu_user_regs *regs,
+                                          struct vcpu *v)
+{
+    return IO_UNHANDLED;
+}
+
+static inline enum io_state try_fwd_ioserv(struct cpu_user_regs *regs,
+                                           struct vcpu *v, mmio_info_t *info)
+{
+    return IO_UNHANDLED;
+}
+#endif
+
+bool ioreq_complete_mmio(void);
+
+static inline bool handle_pio(uint16_t port, unsigned int size, int dir)
+{
+    /*
+     * TODO: For Arm64, the main user will be PCI. So this should be
+     * implemented when we add support for vPCI.
+     */
+    ASSERT_UNREACHABLE();
+    return true;
+}
+
+static inline void msix_write_completion(struct vcpu *v)
+{
+}
+
+/* This correlation must not be altered */
+#define IOREQ_STATUS_HANDLED     IO_HANDLED
+#define IOREQ_STATUS_UNHANDLED   IO_UNHANDLED
+#define IOREQ_STATUS_RETRY       IO_RETRY
+
+#endif /* __ASM_ARM_HVM_IOREQ_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/asm-arm/mmio.h +1 -0
index 8dbfb27..7ab873c 100644
@@ -37,6 +37,7 @@ enum io_state
      IO_ABORT,       /* The IO was handled by the helper and led to an abort. */
      IO_HANDLED,     /* The IO was successfully handled by the helper. */
      IO_UNHANDLED,   /* The IO was not handled by the helper. */
+    IO_RETRY,       /* Retry the emulation for some reason */
  };
 
  typedef int (*mmio_read_t)(struct vcpu *v, mmio_info_t *info,
Signature · 1 line
Julien Grall
#82 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

On 15.01.21 22:26, Julien Grall wrote:

Hi Julien

Quoted 24 lines · Oleksandr Tyshchenko
Quoted 21 lines
xen/arch/arm/domain.c +1 -0
index 18cafcd..8f55aba 100644
@@ -15,6 +15,7 @@
   #include <xen/guest_access.h>
   #include <xen/hypercall.h>
   #include <xen/init.h>
+#include <xen/ioreq.h>
   #include <xen/lib.h>
   #include <xen/livepatch.h>
   #include <xen/sched.h>
@@ -696,6 +697,10 @@ int arch_domain_create(struct domain *d,
         ASSERT(config != NULL);

  +#ifdef CONFIG_IOREQ_SERVER
+    ioreq_domain_init(d);

xen/arch/arm/domain.c +2 -0
+#endif
+

      /* p2m_init relies on some value initialized by the IOMMU subsystem */ if ( (rc = iommu_domain_init(d, config->iommu_opts)) != 0 ) goto fail;

Quoted 8 lines
Quoted 6 lines
xen/arch/arm/domain.c +0 -0
@@ -1014,6 +1019,10 @@ int domain_relinquish_resources(struct domain *d)
           if (ret )
               return ret;

  +#ifdef CONFIG_IOREQ_SERVER
+        ioreq_server_destroy_all(d);
+#endif

The placement of this call feels quite odd. Shouldn't this moved in case 0?

Indeed it is odd to call it here, will move.

Quoted 15 lines
Quoted 15 lines

+
      PROGRESS(xen):
          ret = relinquish_memory(d, &d->xenpage_list); if ( ret )

xen/arch/arm/io.c +0 -0
index ae7ef96..9814481 100644
@@ -16,6 +16,7 @@
    * GNU General Public License for more details.
    */

  +#include <xen/ioreq.h>
  #include <xen/lib.h>
  #include <xen/spinlock.h>

Quoted 8 lines

xen/arch/arm/io.c line 27

Quoted 6 lines

  #include <xen/sched.h>

xen/arch/arm/io.c +1 -0
@@ -23,6 +24,7 @@
   #include <asm/cpuerrata.h>
   #include <asm/current.h>
   #include <asm/mmio.h>
+#include <asm/hvm/ioreq.h>

Shouldn't this have been included by "xen/ioreq.h"?

Well, for V1 asm/hvm/ioreq.h was included by xen/ioreq.h. But, it turned out that there was nothing inside common header required arch one to be included and I was asked to include arch header where it was indeed needed (several *.c files).

Quoted 86 lines
Quoted 73 lines
xen/arch/arm/io.c +0 -0
     #include "decode.h"
   @@ -123,7 +125,15 @@ enum io_state try_handle_mmio(struct cpu_user_regs *regs,
         handler = find_mmio_handler(v->domain, info.gpa);

      if ( !handler )
-        return IO_UNHANDLED;
+    {
+        int rc;

xen/arch/arm/io.c +7 -0
+
+        rc = try_fwd_ioserv(regs, v, &info);
+        if ( rc == IO_HANDLED )
+            return handle_ioserv(regs, v);
+
+        return rc;
+    }

        /* All the instructions used on emulated MMIO region should be valid */ if ( !dabt.valid )

xen/arch/arm/ioreq.c new file +6 -0
new file mode 100644
index 0000000..3c4a24d
@@ -0,0 +1,213 @@
+/*
+ * arm/ioreq.c: hardware virtual machine I/O emulation
+ *
+ * Copyright (c) 2019 Arm ltd.
+ *
+ * This program is free software; you can redistribute it and/or 

modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */

xen/arch/arm/ioreq.c new file +27 -0
+
+#include <xen/domain.h>
+#include <xen/ioreq.h>
+
+#include <asm/traps.h>
+
+#include <public/hvm/ioreq.h>
+
+enum io_state handle_ioserv(struct cpu_user_regs *regs, struct vcpu *v)
+{
+    const union hsr hsr = { .bits = regs->hsr };
+    const struct hsr_dabt dabt = hsr.dabt;
+    /* Code is similar to handle_read */
+    uint8_t size = (1 << dabt.size) * 8;
+    register_t r = v->io.req.data;
+
+    /* We are done with the IO */
+    v->io.req.state = STATE_IOREQ_NONE;
+
+    if ( dabt.write )
+        return IO_HANDLED;
+
+    /*
+     * Sign extend if required.
+     * Note that we expect the read handler to have zeroed the bits
+     * outside the requested access size.
+     */

xen/arch/arm/ioreq.c

Quoted 10 lines
xen/arch/arm/ioreq.c new file +10 -0
+    if ( dabt.sign && (r & (1UL << (size - 1))) )
+    {
+        /*
+         * We are relying on register_t using the same as
+         * an unsigned long in order to keep the 32-bit assembly
+         * code smaller.
+         */
+        BUILD_BUG_ON(sizeof(register_t) != sizeof(unsigned long));
+        r |= (~0UL) << size;
+    }

Looking at the rest of the series, this code is going to be refactored in patch #19 and then hardened. It would have been better to do the refactoring first and then use it.

Quoted 1 line

This helps a lot for the review and to reduce what I would call churn in the series.

Agree, it would be better.

Quoted 3 lines

I am OK to keep it like that for this series.

Thank you, this saves me some time.

Quoted 33 lines
Quoted 33 lines
xen/arch/arm/ioreq.c new file +18 -0
+
+    set_user_reg(regs, dabt.reg, r);
+
+    return IO_HANDLED;
+}
+
+enum io_state try_fwd_ioserv(struct cpu_user_regs *regs,
+                             struct vcpu *v, mmio_info_t *info)
+{
+    struct vcpu_io *vio = &v->io;
+    ioreq_t p = {
+        .type = IOREQ_TYPE_COPY,
+        .addr = info->gpa,
+        .size = 1 << info->dabt.size,
+        .count = 1,
+        .dir = !info->dabt.write,
+        /*
+         * On x86, df is used by 'rep' instruction to tell the 

direction
+         * to iterate (forward or backward).
+         * On Arm, all the accesses to MMIO region will do a single +         * memory access. So for now, we can safely always set to 0. +         */
+        .df = 0,
+        .data = get_user_reg(regs, info->dabt.reg),
+        .state = STATE_IOREQ_READY,
+    };
+    struct ioreq_server *s = NULL;
+    enum io_state rc;
+
+    switch ( vio->req.state )

Quoted 8 lines
Quoted 6 lines

+    {
+    case STATE_IOREQ_NONE:
+        break;
+
+    case STATE_IORESP_READY:
+        return IO_HANDLED;

With the Arm code in mind, I am a bit confused with this check. If vio->req.state == STATE_IORESP_READY, then it would imply that the previous I/O emulation was somehow not completed (from Xen PoV).

Agree

Quoted 2 lines

If you return IO_HANDLED here, then it means the we will take care of previous I/O but the current one is going to be ignored.

Which current one? As I understand, if try_fwd_ioserv() gets called with vio->req.state == STATE_IORESP_READY then this is a second round after emulator completes the emulation (the first round was when we returned IO_RETRY down the function and claimed that we would need a completion), so we are still dealing with previous I/O.
vcpu_ioreq_handle_completion() -> arch_ioreq_complete_mmio() -> try_handle_mmio() -> try_fwd_ioserv() -> handle_ioserv()
And after we return IO_HANDLED here, handle_ioserv() will be called to complete the handling of this previous I/O emulation.
Or I really missed something?

Quoted 1 line

So shouldn't we use the default path here as well?

I am afraid, I don't entirely get the suggestion.

Quoted 172 lines
Quoted 172 lines
xen/arch/arm/ioreq.c new file +51 -0
+
+    default:
+        gdprintk(XENLOG_ERR, "wrong state %u\n", vio->req.state);
+        return IO_ABORT;
+    }
+
+    s = ioreq_server_select(v->domain, &p);
+    if ( !s )
+        return IO_UNHANDLED;
+
+    if ( !info->dabt.valid )
+        return IO_ABORT;
+
+    vio->req = p;
+
+    rc = ioreq_send(s, &p, 0);
+    if ( rc != IO_RETRY || v->domain->is_shutting_down )
+        vio->req.state = STATE_IOREQ_NONE;
+    else if ( !ioreq_needs_completion(&vio->req) )
+        rc = IO_HANDLED;
+    else
+        vio->completion = VIO_mmio_completion;
+
+    return rc;
+}
+
+bool arch_ioreq_complete_mmio(void)
+{
+    struct vcpu *v = current;
+    struct cpu_user_regs *regs = guest_cpu_user_regs();
+    const union hsr hsr = { .bits = regs->hsr };
+    paddr_t addr = v->io.req.addr;
+
+    if ( try_handle_mmio(regs, hsr, addr) == IO_HANDLED )
+    {
+        advance_pc(regs, hsr);
+        return true;
+    }
+
+    return false;
+}
+
+bool arch_vcpu_ioreq_completion(enum vio_completion completion)
+{
+    ASSERT_UNREACHABLE();
+    return true;
+}
+
+/*
+ * The "legacy" mechanism of mapping magic pages for the IOREQ servers
+ * is x86 specific, so the following hooks don't need to be 

implemented on Arm:
+ * - arch_ioreq_server_map_pages
+ * - arch_ioreq_server_unmap_pages
+ * - arch_ioreq_server_enable
+ * - arch_ioreq_server_disable
+ */

xen/arch/arm/ioreq.c new file +67 -0
+int arch_ioreq_server_map_pages(struct ioreq_server *s)
+{
+    return -EOPNOTSUPP;
+}
+
+void arch_ioreq_server_unmap_pages(struct ioreq_server *s)
+{
+}
+
+void arch_ioreq_server_enable(struct ioreq_server *s)
+{
+}
+
+void arch_ioreq_server_disable(struct ioreq_server *s)
+{
+}
+
+void arch_ioreq_server_destroy(struct ioreq_server *s)
+{
+}
+
+int arch_ioreq_server_map_mem_type(struct domain *d,
+                                   struct ioreq_server *s,
+                                   uint32_t flags)
+{
+    return -EOPNOTSUPP;
+}
+
+void arch_ioreq_server_map_mem_type_completed(struct domain *d,
+                                              struct ioreq_server *s,
+                                              uint32_t flags)
+{
+}
+
+bool arch_ioreq_server_destroy_all(struct domain *d)
+{
+    return true;
+}
+
+bool arch_ioreq_server_get_type_addr(const struct domain *d,
+                                     const ioreq_t *p,
+                                     uint8_t *type,
+                                     uint64_t *addr)
+{
+    if ( p->type != IOREQ_TYPE_COPY && p->type != IOREQ_TYPE_PIO )
+        return false;
+
+    *type = (p->type == IOREQ_TYPE_PIO) ?
+             XEN_DMOP_IO_RANGE_PORT : XEN_DMOP_IO_RANGE_MEMORY;
+    *addr = p->addr;
+
+    return true;
+}
+
+void arch_ioreq_domain_init(struct domain *d)
+{
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/traps.c +4 -0
index 22bd1bd..036b13f 100644
@@ -21,6 +21,7 @@
   #include <xen/hypercall.h>
   #include <xen/init.h>
   #include <xen/iocap.h>
+#include <xen/ioreq.h>
   #include <xen/irq.h>
   #include <xen/lib.h>
   #include <xen/mem_access.h>
@@ -1385,6 +1386,9 @@ static arm_hypercall_t arm_hypercall_table[] = {
   #ifdef CONFIG_HYPFS
       HYPERCALL(hypfs_op, 5),
   #endif
+#ifdef CONFIG_IOREQ_SERVER
+    HYPERCALL(dm_op, 3),
+#endif
   };
     #ifndef NDEBUG
@@ -1956,6 +1960,9 @@ static void do_trap_stage2_abort_guest(struct 
 cpu_user_regs *regs,

              case IO_HANDLED:
                  advance_pc(regs, hsr);
                  return;
+            case IO_RETRY:
+                /* finish later */
+                return;
              case IO_UNHANDLED:
                  /* IO unhandled, try another way to handle it. */ break;

xen/arch/arm/traps.c +0 -0
@@ -2254,6 +2261,12 @@ static void check_for_vcpu_work(void)
   {
       struct vcpu *v = current;

  +#ifdef CONFIG_IOREQ_SERVER
+    local_irq_enable();
+    vcpu_ioreq_handle_completion(v);
+    local_irq_disable();

xen/arch/arm/traps.c +2 -0
+#endif
+

      if ( likely(!v->arch.need_flush_to_ram) )
          return;
  diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index 6819a3b..c235e5b 100644
--- a/xen/include/asm-arm/domain.h

Quoted 8 lines

xen/arch/arm/traps.c line 13

Quoted 6 lines

+++ b/xen/include/asm-arm/domain.h

xen/arch/arm/traps.c +1 -0
@@ -10,6 +10,7 @@
   #include <asm/gic.h>
   #include <asm/vgic.h>
   #include <asm/vpl011.h>
+#include <public/hvm/dm_op.h>

May I ask, why do you need to include dm_op.h here?

I needed to include that header to make some bits visible (XEN_DMOP_IO_RANGE_PCI, struct xen_dm_op_buf, etc). Why here - is a really good question. I don't remember exactly, probably I followed x86's domain.h which also included it.
So, trying to remove the inclusion here, I get several build failures on Arm which could be fixed if I include that header from dm.h and ioreq.h:

Shall I do this way?

xen/include/asm-arm/domain.h +0 -0
index 6bd2d85..9de7c4e 100644
@@ -10,7 +10,6 @@

 #include <asm/gic.h>
 #include <asm/vgic.h>
 #include <asm/vpl011.h>
-#include <public/hvm/dm_op.h>
 #include <public/hvm/params.h>

 struct hvm_domain

xen/include/xen/dm.h +0 -0
index 2c9952d..4ce6655 100644
@@ -19,6 +19,8 @@
 

 #include <xen/sched.h>

+#include <public/hvm/dm_op.h>
+
 struct dmop_args {
     domid_t domid;
     unsigned int nr_bufs;

xen/include/xen/ioreq.h +0 -0
index dc47ec7..7b74983 100644
@@ -21,6 +21,8 @@
 

 #include <xen/sched.h>

+#include <public/hvm/dm_op.h>
+
 struct ioreq_page {
     gfn_t gfn;
     struct page_info *page;
(END)

Quoted 18 lines

xen/include/asm-arm/hvm/ioreq.h

Quoted 16 lines
xen/arch/arm/traps.c +0 -0
   #include <public/hvm/params.h>

    struct hvm_domain

xen/arch/arm/traps.c +1 -0
@@ -262,6 +263,8 @@ static inline void arch_vcpu_block(struct vcpu 
 *v) {}
     #define arch_vm_assist_valid_mask(d) (1UL << VMASST_TYPE_runstate_update_flag)
   +#define has_vpci(d)    ({ (void)(d); false; })
+
   #endif /* __ASM_DOMAIN_H__ */
     /*
xen/include/asm-arm/hvm/ioreq.h new file +0 -0
new file mode 100644
index 0000000..19e1247

Shouldn't this directly be under asm-arm/ rather than asm-arm/hvm/ as the IOREQ is now meant to be agnostic?

Good question... The _common_ IOREQ code is indeed arch-agnostic. But, can the _arch_ IOREQ code be treated as really subarch-agnostic? I think, on Arm it can and it is most likely ok to keep it in "asm-arm/", but how it would be correlated with x86's IOREQ code which is HVM specific and located in "hvm" subdir?

Quoted 95 lines
Quoted 94 lines
xen/include/asm-arm/hvm/ioreq.h new file +7 -0
@@ -0,0 +1,72 @@
+/*
+ * hvm.h: Hardware virtual machine assist interface definitions.
+ *
+ * Copyright (c) 2016 Citrix Systems Inc.
+ * Copyright (c) 2019 Arm ltd.
+ *
+ * This program is free software; you can redistribute it and/or 

modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */

xen/include/asm-arm/hvm/ioreq.h new file +6 -0
+
+#ifndef __ASM_ARM_HVM_IOREQ_H__
+#define __ASM_ARM_HVM_IOREQ_H__
+
+#ifdef CONFIG_IOREQ_SERVER
+enum io_state handle_ioserv(struct cpu_user_regs *regs, struct vcpu 

*v);

xen/include/asm-arm/hvm/ioreq.h new file +11 -0
+enum io_state try_fwd_ioserv(struct cpu_user_regs *regs,
+                             struct vcpu *v, mmio_info_t *info);
+#else
+static inline enum io_state handle_ioserv(struct cpu_user_regs *regs,
+                                          struct vcpu *v)
+{
+    return IO_UNHANDLED;
+}
+
+static inline enum io_state try_fwd_ioserv(struct cpu_user_regs *regs,
+                                           struct vcpu *v, 

mmio_info_t *info)

xen/include/asm-arm/hvm/ioreq.h new file +8 -0
+{
+    return IO_UNHANDLED;
+}
+#endif
+
+bool ioreq_complete_mmio(void);
+
+static inline bool handle_pio(uint16_t port, unsigned int size, int 

dir)

xen/include/asm-arm/hvm/ioreq.h new file +29 -0
+{
+    /*
+     * TODO: For Arm64, the main user will be PCI. So this should be
+     * implemented when we add support for vPCI.
+     */
+    ASSERT_UNREACHABLE();
+    return true;
+}
+
+static inline void msix_write_completion(struct vcpu *v)
+{
+}
+
+/* This correlation must not be altered */
+#define IOREQ_STATUS_HANDLED     IO_HANDLED
+#define IOREQ_STATUS_UNHANDLED   IO_UNHANDLED
+#define IOREQ_STATUS_RETRY       IO_RETRY
+
+#endif /* __ASM_ARM_HVM_IOREQ_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/asm-arm/mmio.h +0 -0
index 8dbfb27..7ab873c 100644
@@ -37,6 +37,7 @@ enum io_state

      IO_ABORT,       /* The IO was handled by the helper and led to an abort. */ IO_HANDLED,     /* The IO was successfully handled by the helper. */ IO_UNHANDLED,   /* The IO was not handled by the helper. */
+    IO_RETRY,       /* Retry the emulation for some reason */
  };
    typedef int (*mmio_read_t)(struct vcpu *v, mmio_info_t *info,

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
#83 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

Quoted 4 lines · Oleksandr

On 15.01.21 22:26, Julien Grall wrote:

Hi Julien

Hi Oleksandr,

Quoted 23 lines
Quoted 15 lines
Quoted 15 lines

+
      PROGRESS(xen):
          ret = relinquish_memory(d, &d->xenpage_list); if ( ret )

xen/arch/arm/io.c +0 -0
index ae7ef96..9814481 100644
@@ -16,6 +16,7 @@
    * GNU General Public License for more details.
    */

  +#include <xen/ioreq.h>
  #include <xen/lib.h>
  #include <xen/spinlock.h>

Quoted 8 lines

xen/arch/arm/io.c line 27

Quoted 6 lines

  #include <xen/sched.h>

xen/arch/arm/io.c +1 -0
@@ -23,6 +24,7 @@
   #include <asm/cpuerrata.h>
   #include <asm/current.h>
   #include <asm/mmio.h>
+#include <asm/hvm/ioreq.h>

Shouldn't this have been included by "xen/ioreq.h"?

Quoted 2 lines

Well, for V1 asm/hvm/ioreq.h was included by xen/ioreq.h. But, it turned out that there was nothing inside common header required arch one to be included and I was asked to include arch header where it was indeed needed (several *.c files).

Fair enough.

[...]

Quoted 7 lines
Quoted 2 lines

If you return IO_HANDLED here, then it means the we will take care of previous I/O but the current one is going to be ignored.

Which current one? As I understand, if try_fwd_ioserv() gets called with vio->req.state == STATE_IORESP_READY then this is a second round after emulator completes the emulation (the first round was when we returned IO_RETRY down the function and claimed that we would need a completion), so we are still dealing with previous I/O.
vcpu_ioreq_handle_completion() -> arch_ioreq_complete_mmio() -> try_handle_mmio() -> try_fwd_ioserv() -> handle_ioserv()
And after we return IO_HANDLED here, handle_ioserv() will be called to complete the handling of this previous I/O emulation.
Or I really missed something?

Hmmm... I somehow thought try_fw_ioserv() would only be called the first time. Do you have a branch with your code applied? This would help to follow the different paths.

Quoted 11 lines
Quoted 11 lines

xen/include/asm-arm/domain.h line 13

Quoted 9 lines

  diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index 6819a3b..c235e5b 100644

xen/include/asm-arm/domain.h +1 -0
@@ -10,6 +10,7 @@
   #include <asm/gic.h>
   #include <asm/vgic.h>
   #include <asm/vpl011.h>
+#include <public/hvm/dm_op.h>

May I ask, why do you need to include dm_op.h here?

Quoted 5 lines

I needed to include that header to make some bits visible (XEN_DMOP_IO_RANGE_PCI, struct xen_dm_op_buf, etc). Why here - is a really good question. I don't remember exactly, probably I followed x86's domain.h which also included it.
So, trying to remove the inclusion here, I get several build failures on Arm which could be fixed if I include that header from dm.h and ioreq.h:

Shall I do this way?

If the failure are indeded because ioreq.h and dm.h use definition from public/hvm/dm_op.h, then yes. Can you post the errors?

[...]

Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
xen/include/asm-arm/domain.h +0 -0
   #include <public/hvm/params.h>

    struct hvm_domain

xen/include/asm-arm/domain.h +1 -0
@@ -262,6 +263,8 @@ static inline void arch_vcpu_block(struct vcpu 
 *v) {}
     #define arch_vm_assist_valid_mask(d) (1UL << VMASST_TYPE_runstate_update_flag)
   +#define has_vpci(d)    ({ (void)(d); false; })
+
   #endif /* __ASM_DOMAIN_H__ */
Quoted 8 lines

xen/include/asm-arm/hvm/ioreq.h

Quoted 6 lines
xen/include/asm-arm/domain.h +0 -0
     /*
xen/include/asm-arm/hvm/ioreq.h new file +0 -0
new file mode 100644
index 0000000..19e1247

Shouldn't this directly be under asm-arm/ rather than asm-arm/hvm/ as the IOREQ is now meant to be agnostic?

Quoted 3 lines

Good question... The _common_ IOREQ code is indeed arch-agnostic. But, can the _arch_ IOREQ code be treated as really subarch-agnostic? I think, on Arm it can and it is most likely ok to keep it in "asm-arm/", but how it would be correlated with x86's IOREQ code which is HVM specific and located in "hvm" subdir?

Sorry, I don't understand your answer/questions. So let me ask the question differently, is asm-arm/hvm/ioreq.h going to be included from common code?

If the answer is no, then I see no reason to follow the x86 here.
If the answer is yes, then I am quite confused why half of the series tried to remove "hvm" from the function name but we still include "asm/hvm/ioreq.h".

Cheers,

Signature · 1 line
Julien Grall
#84 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

Quoted 9 lines · Julien Grall
Quoted 4 lines · Oleksandr

On 15.01.21 22:26, Julien Grall wrote:

Hi Julien

Hi Oleksandr,

Hi Julien

Quoted 32 lines
Quoted 24 lines
Quoted 16 lines
Quoted 16 lines

+
      PROGRESS(xen):
          ret = relinquish_memory(d, &d->xenpage_list); if ( ret )

xen/arch/arm/io.c +0 -0
index ae7ef96..9814481 100644
@@ -16,6 +16,7 @@
    * GNU General Public License for more details.
    */

  +#include <xen/ioreq.h>
  #include <xen/lib.h>
  #include <xen/spinlock.h>

Quoted 8 lines

xen/arch/arm/io.c line 27

Quoted 6 lines

  #include <xen/sched.h>

xen/arch/arm/io.c +1 -0
@@ -23,6 +24,7 @@
   #include <asm/cpuerrata.h>
   #include <asm/current.h>
   #include <asm/mmio.h>
+#include <asm/hvm/ioreq.h>

Shouldn't this have been included by "xen/ioreq.h"?

Quoted 2 lines

Well, for V1 asm/hvm/ioreq.h was included by xen/ioreq.h. But, it turned out that there was nothing inside common header required arch one to be included and I was asked to include arch header where it was indeed needed (several *.c files).

Fair enough.

[...]

Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

If you return IO_HANDLED here, then it means the we will take care of previous I/O but the current one is going to be ignored.

Which current one? As I understand, if try_fwd_ioserv() gets called with vio->req.state == STATE_IORESP_READY then this is a second round after emulator completes the emulation (the first round was when we returned IO_RETRY down the function and claimed that we would need a completion), so we are still dealing with previous I/O.
vcpu_ioreq_handle_completion() -> arch_ioreq_complete_mmio() -> try_handle_mmio() -> try_fwd_ioserv() -> handle_ioserv()
And after we return IO_HANDLED here, handle_ioserv() will be called to complete the handling of this previous I/O emulation.
Or I really missed something?

Hmmm... I somehow thought try_fw_ioserv() would only be called the first time. Do you have a branch with your code applied? This would help to follow the different paths.

Yes, I mentioned about it in cover letter.

Please see
https://github.com/otyshchenko1/xen/commits/ioreq_4.14_ml5
why 5 - because I started counting from the RFC)

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

xen/include/asm-arm/domain.h line 13

Quoted 10 lines

  diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index 6819a3b..c235e5b 100644

xen/include/asm-arm/domain.h +1 -0
@@ -10,6 +10,7 @@
   #include <asm/gic.h>
   #include <asm/vgic.h>
   #include <asm/vpl011.h>
+#include <public/hvm/dm_op.h>

May I ask, why do you need to include dm_op.h here?

Quoted 7 lines
Quoted 5 lines

I needed to include that header to make some bits visible (XEN_DMOP_IO_RANGE_PCI, struct xen_dm_op_buf, etc). Why here - is a really good question. I don't remember exactly, probably I followed x86's domain.h which also included it.
So, trying to remove the inclusion here, I get several build failures on Arm which could be fixed if I include that header from dm.h and ioreq.h:

Shall I do this way?

If the failure are indeded because ioreq.h and dm.h use definition from public/hvm/dm_op.h, then yes. Can you post the errors?

Please see attached, although I built for Arm32 (and the whole series), I think errors are valid for Arm64 also. error1.txt - when remove #include <public/hvm/dm_op.h> from asm-arm/domain.h
error2.txt - when add #include <public/hvm/dm_op.h> to xen/ioreq.h
error3.txt - when add #include <public/hvm/dm_op.h> to xen/dm.h

Quoted 20 lines

[...]

Quoted 16 lines
Quoted 16 lines

xen/include/asm-arm/hvm/ioreq.h

Quoted 14 lines

  #include <public/hvm/params.h>
    struct hvm_domain

xen/include/asm-arm/domain.h +1 -0
@@ -262,6 +263,8 @@ static inline void arch_vcpu_block(struct vcpu 
 *v) {}
     #define arch_vm_assist_valid_mask(d) (1UL << VMASST_TYPE_runstate_update_flag)
   +#define has_vpci(d)    ({ (void)(d); false; })
+
   #endif /* __ASM_DOMAIN_H__ */
     /*
xen/include/asm-arm/hvm/ioreq.h new file +0 -0
new file mode 100644
index 0000000..19e1247

Shouldn't this directly be under asm-arm/ rather than asm-arm/hvm/ as the IOREQ is now meant to be agnostic?

Quoted 5 lines
Quoted 3 lines

Good question... The _common_ IOREQ code is indeed arch-agnostic. But, can the _arch_ IOREQ code be treated as really subarch-agnostic? I think, on Arm it can and it is most likely ok to keep it in "asm-arm/", but how it would be correlated with x86's IOREQ code which is HVM specific and located in "hvm" subdir?

Sorry, I don't understand your answer/questions. So let me ask the question differently, is asm-arm/hvm/ioreq.h going to be included from common code?

Sorry if I was unclear.

Quoted 3 lines

If the answer is no, then I see no reason to follow the x86 here.
If the answer is yes, then I am quite confused why half of the series tried to remove "hvm" from the function name but we still include "asm/hvm/ioreq.h".

Answer is yes. Even if we could to avoid including that header from the common code somehow, we would still have #include <public/hvm/*>, is_hvm_domain().

Quoted 4 lines

Cheers,

Signature · 3 lines
Regards,

Oleksandr Tyshchenko

make xen XEN_TARGET_ARCH=arm32 CROSS_COMPILE=/home/otyshchenko/work/projects/toolchain/gcc-linaro-7.5.0-2019.12-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- make -C xen install
make[1]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen' make -f Rules.mk _install
make[2]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen' make -C tools
make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/tools' make symbols
make[4]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/tools' make[4]: 'symbols' is up to date.
make[4]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/tools' make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/tools' make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk include/xen/compile.h make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen'
Xen 4.15-unstable
make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen' [ -e include/asm ] || ln -sf asm-arm include/asm

[ -e arch/arm/efi ] && for f in $(cd common/efi; echo *.[ch]); \
	do test -r arch/arm/efi/$f || \
	   ln -nsf ../../../common/efi/$f arch/arm/efi/; \
	done; \
	true

make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C include
make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include'
make[3]: Nothing to be done for 'all'.
make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C arch/arm asm-offsets.s
make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm'
make[3]: 'asm-offsets.s' is up to date.
make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk include/asm-arm/asm-offsets.h
make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen'
make[3]: 'include/asm-arm/asm-offsets.h' is up to date.
make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C arch/arm /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xen make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common built_in.o make[4]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common'
sed "s! $PWD/! !" .ioreq.o.d >.ioreq.o.d2.tmp && mv -f .ioreq.o.d2.tmp .ioreq.o.d2
sed "s! $PWD/! !" .memory.o.d >.memory.o.d2.tmp && mv -f .memory.o.d2.tmp .memory.o.d2
sed "s! $PWD/! !" .version.o.d >.version.o.d2.tmp && mv -f .version.o.d2.tmp .version.o.d2
/home/otyshchenko/work/projects/toolchain/gcc-linaro-7.5.0-2019.12-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -MMD -MP -MF ./.ioreq.o.d -marm -DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wdeclaration-after-statement -Wno-unused-but-set-variable -Wno-unused-local-typedefs -O1 -fno-omit-frame-pointer -nostdinc -fno-builtin -fno-common -Werror -Wredundant-decls -Wno-pointer-arith -Wvla -pipe -D__XEN__ -include /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/config.h -Wa,--strip-local-absolute -g -msoft-float -mcpu=cortex-a15 -I/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include -fno-stack-protector -fno-exceptions -fno-asynchronous-unwind-tables -Wnested-externs '-D__OBJECT_FILE__="ioreq.o"' -c ioreq.c -o ioreq.o
In file included from ioreq.c:23:0:
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/ioreq.h:39:28: error: ‘XEN_DMOP_IO_RANGE_PCI’ undeclared here (not in a function); did you mean ‘XEN_DOMCTL_DEV_PCI’?

 #define NR_IO_RANGE_TYPES (XEN_DMOP_IO_RANGE_PCI + 1)
                            ^
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/ioreq.h:55:35: note: in expansion of macro ‘NR_IO_RANGE_TYPES’
     struct rangeset        *range[NR_IO_RANGE_TYPES];
                                   ^~~~~~~~~~~~~~~~~
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/ioreq.h:92:46: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 int ioreq_server_get_frame(struct domain *d, ioservid_t id,
                                              ^~~~~~~~~~
                                              nodeid_t
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/ioreq.h:94:49: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 int ioreq_server_map_mem_type(struct domain *d, ioservid_t id,
                                                 ^~~~~~~~~~
                                                 nodeid_t
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/ioreq.h:110:31: error: ‘struct xen_dm_op’ declared inside parameter list will not be visible outside of this definition or declaration [-Werror]
 int ioreq_server_dm_op(struct xen_dm_op *op, struct domain *d, bool *const_op);
                               ^~~~~~~~~
ioreq.c:484:41: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
                                         ioservid_t id)
                                         ^~~~~~~~~~
                                         nodeid_t
ioreq.c:560:30: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
                              ioservid_t id)
                              ^~~~~~~~~~
                              nodeid_t
ioreq.c:626:32: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
                                ioservid_t *id)
                                ^~~~~~~~~~
                                nodeid_t
ioreq.c:681:51: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 static int ioreq_server_destroy(struct domain *d, ioservid_t id)
                                                   ^~~~~~~~~~
                                                   nodeid_t
ioreq.c:723:52: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 static int ioreq_server_get_info(struct domain *d, ioservid_t id,
                                                    ^~~~~~~~~~
                                                    nodeid_t
ioreq.c:770:46: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 int ioreq_server_get_frame(struct domain *d, ioservid_t id,
                                              ^~~~~~~~~~
                                              nodeid_t
ioreq.c:821:56: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 static int ioreq_server_map_io_range(struct domain *d, ioservid_t id,
                                                        ^~~~~~~~~~
                                                        nodeid_t
ioreq.c:873:58: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 static int ioreq_server_unmap_io_range(struct domain *d, ioservid_t id,
                                                          ^~~~~~~~~~
                                                          nodeid_t
ioreq.c:933:49: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 int ioreq_server_map_mem_type(struct domain *d, ioservid_t id,
                                                 ^~~~~~~~~~
                                                 nodeid_t
ioreq.c:968:53: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 static int ioreq_server_set_state(struct domain *d, ioservid_t id,
                                                     ^~~~~~~~~~
                                                     nodeid_t
ioreq.c: In function ‘ioreq_server_select’:
ioreq.c:1103:14: error: ‘XEN_DMOP_IO_RANGE_PORT’ undeclared (first use in this function); did you mean ‘XEN_DMOP_IO_RANGE_PCI’?
         case XEN_DMOP_IO_RANGE_PORT:
              ^~~~~~~~~~~~~~~~~~~~~~
              XEN_DMOP_IO_RANGE_PCI
ioreq.c:1103:14: note: each undeclared identifier is reported only once for each function it appears in
ioreq.c:1111:14: error: ‘XEN_DMOP_IO_RANGE_MEMORY’ undeclared (first use in this function); did you mean ‘XEN_DMOP_IO_RANGE_PORT’?
         case XEN_DMOP_IO_RANGE_MEMORY:
              ^~~~~~~~~~~~~~~~~~~~~~~~
              XEN_DMOP_IO_RANGE_PORT
ioreq.c: At top level:
ioreq.c:1313:31: error: ‘struct xen_dm_op’ declared inside parameter list will not be visible outside of this definition or declaration [-Werror]
 int ioreq_server_dm_op(struct xen_dm_op *op, struct domain *d, bool *const_op)
                               ^~~~~~~~~
ioreq.c:1313:5: error: conflicting types for ‘ioreq_server_dm_op’
 int ioreq_server_dm_op(struct xen_dm_op *op, struct domain *d, bool *const_op)
     ^~~~~~~~~~~~~~~~~~
In file included from ioreq.c:23:0:
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/ioreq.h:110:5: note: previous declaration of ‘ioreq_server_dm_op’ was here
 int ioreq_server_dm_op(struct xen_dm_op *op, struct domain *d, bool *const_op);
     ^~~~~~~~~~~~~~~~~~
ioreq.c: In function ‘ioreq_server_dm_op’:
ioreq.c:1317:16: error: dereferencing pointer to incomplete type ‘struct xen_dm_op’
     switch ( op->op )
                ^~
ioreq.c:1319:10: error: ‘XEN_DMOP_create_ioreq_server’ undeclared (first use in this function); did you mean ‘XENMEM_resource_ioreq_server’?
     case XEN_DMOP_create_ioreq_server:
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
          XENMEM_resource_ioreq_server
ioreq.c:1327:18: error: dereferencing pointer to incomplete type ‘struct xen_dm_op_create_ioreq_server’
         if ( data->pad[0] || data->pad[1] || data->pad[2] )
                  ^~
ioreq.c:1330:14: error: implicit declaration of function ‘ioreq_server_create’; did you mean ‘ioreq_server_disable’? [-Werror=implicit-function-declaration]
         rc = ioreq_server_create(d, data->handle_bufioreq,
              ^~~~~~~~~~~~~~~~~~~
              ioreq_server_disable
ioreq.c:1330:14: error: nested extern declaration of ‘ioreq_server_create’ [-Werror=nested-externs]
ioreq.c:1335:10: error: ‘XEN_DMOP_get_ioreq_server_info’ undeclared (first use in this function); did you mean ‘XEN_DMOP_create_ioreq_server’?
     case XEN_DMOP_get_ioreq_server_info:
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          XEN_DMOP_create_ioreq_server
ioreq.c:1339:38: error: ‘XEN_DMOP_no_gfns’ undeclared (first use in this function)
         const uint16_t valid_flags = XEN_DMOP_no_gfns;
                                      ^~~~~~~~~~~~~~~~
ioreq.c:1344:18: error: dereferencing pointer to incomplete type ‘struct xen_dm_op_get_ioreq_server_info’
         if ( data->flags & ~valid_flags )
                  ^~
ioreq.c:1347:14: error: implicit declaration of function ‘ioreq_server_get_info’; did you mean ‘ioreq_server_deinit’? [-Werror=implicit-function-declaration]
         rc = ioreq_server_get_info(d, data->id,
              ^~~~~~~~~~~~~~~~~~~~~
              ioreq_server_deinit
ioreq.c:1347:14: error: nested extern declaration of ‘ioreq_server_get_info’ [-Werror=nested-externs]
ioreq.c:1356:10: error: ‘XEN_DMOP_map_io_range_to_ioreq_server’ undeclared (first use in this function); did you mean ‘XEN_DMOP_create_ioreq_server’?
     case XEN_DMOP_map_io_range_to_ioreq_server:
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          XEN_DMOP_create_ioreq_server
ioreq.c:1362:18: error: dereferencing pointer to incomplete type ‘const struct xen_dm_op_ioreq_server_range’
         if ( data->pad )
                  ^~
ioreq.c:1365:14: error: implicit declaration of function ‘ioreq_server_map_io_range’; did you mean ‘ioreq_server_alloc_pages’? [-Werror=implicit-function-declaration]
         rc = ioreq_server_map_io_range(d, data->id, data->type,
              ^~~~~~~~~~~~~~~~~~~~~~~~~
              ioreq_server_alloc_pages
ioreq.c:1365:14: error: nested extern declaration of ‘ioreq_server_map_io_range’ [-Werror=nested-externs]
ioreq.c:1370:10: error: ‘XEN_DMOP_unmap_io_range_from_ioreq_server’ undeclared (first use in this function); did you mean ‘XEN_DMOP_map_io_range_to_ioreq_server’?
     case XEN_DMOP_unmap_io_range_from_ioreq_server:
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          XEN_DMOP_map_io_range_to_ioreq_server
ioreq.c:1376:18: error: dereferencing pointer to incomplete type ‘const struct xen_dm_op_ioreq_server_range’
         if ( data->pad )
                  ^~
ioreq.c:1379:14: error: implicit declaration of function ‘ioreq_server_unmap_io_range’; did you mean ‘ioreq_server_alloc_pages’? [-Werror=implicit-function-declaration]
         rc = ioreq_server_unmap_io_range(d, data->id, data->type,
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~
              ioreq_server_alloc_pages
ioreq.c:1379:14: error: nested extern declaration of ‘ioreq_server_unmap_io_range’ [-Werror=nested-externs]
ioreq.c:1384:10: error: ‘XEN_DMOP_set_ioreq_server_state’ undeclared (first use in this function); did you mean ‘XEN_DMOP_get_ioreq_server_info’?
     case XEN_DMOP_set_ioreq_server_state:
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          XEN_DMOP_get_ioreq_server_info
ioreq.c:1390:18: error: dereferencing pointer to incomplete type ‘const struct xen_dm_op_set_ioreq_server_state’
         if ( data->pad )
                  ^~
ioreq.c:1393:14: error: implicit declaration of function ‘ioreq_server_set_state’; did you mean ‘ioreq_server_select’? [-Werror=implicit-function-declaration]
         rc = ioreq_server_set_state(d, data->id, !!data->enabled);
              ^~~~~~~~~~~~~~~~~~~~~~
              ioreq_server_select
ioreq.c:1393:14: error: nested extern declaration of ‘ioreq_server_set_state’ [-Werror=nested-externs]
ioreq.c:1397:10: error: ‘XEN_DMOP_destroy_ioreq_server’ undeclared (first use in this function); did you mean ‘XEN_DMOP_create_ioreq_server’?
     case XEN_DMOP_destroy_ioreq_server:
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          XEN_DMOP_create_ioreq_server
ioreq.c:1403:18: error: dereferencing pointer to incomplete type ‘const struct xen_dm_op_destroy_ioreq_server’
         if ( data->pad )
                  ^~
ioreq.c:1406:14: error: implicit declaration of function ‘ioreq_server_destroy’; did you mean ‘ioreq_server_destroy_all’? [-Werror=implicit-function-declaration]
         rc = ioreq_server_destroy(d, data->id);
              ^~~~~~~~~~~~~~~~~~~~
              ioreq_server_destroy_all

ioreq.c:1406:14: error: nested extern declaration of ‘ioreq_server_destroy’ [-Werror=nested-externs] At top level:
ioreq.c:521:13: error: ‘ioreq_server_enable’ defined but not used [-Werror=unused-function]
static void ioreq_server_enable(struct ioreq_server *s)

             ^~~~~~~~~~~~~~~~~~~
ioreq.c:454:12: error: ‘ioreq_server_alloc_pages’ defined but not used [-Werror=unused-function]
 static int ioreq_server_alloc_pages(struct ioreq_server *s)
            ^~~~~~~~~~~~~~~~~~~~~~~~
ioreq.c:64:29: error: ‘get_ioreq_server’ defined but not used [-Werror=unused-function]
 static struct ioreq_server *get_ioreq_server(const struct domain *d,
                             ^~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk:197: recipe for target 'ioreq.o' failed
make[4]: *** [ioreq.o] Error 1
make[4]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common' /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk:180: recipe for target '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common/built_in.o' failed make[3]: *** [/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common/built_in.o] Error 2
make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm'
Makefile:359: recipe for target '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xen' failed
make[2]: *** [/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xen] Error 2
make[2]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen'
Makefile:263: recipe for target 'install' failed
make[1]: *** [install] Error 2
make[1]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen'
Makefile:130: recipe for target 'install-xen' failed
make: *** [install-xen] Error 2
otyshchenko@otyshchenko:/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git$

make xen XEN_TARGET_ARCH=arm32 CROSS_COMPILE=/home/otyshchenko/work/projects/toolchain/gcc-linaro-7.5.0-2019.12-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- make -C xen install
make[1]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen' make -f Rules.mk _install
make[2]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen' make -C tools
make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/tools' make symbols
make[4]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/tools' make[4]: 'symbols' is up to date.
make[4]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/tools' make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/tools' make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk include/xen/compile.h make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen'
Xen 4.15-unstable
make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen' [ -e include/asm ] || ln -sf asm-arm include/asm

[ -e arch/arm/efi ] && for f in $(cd common/efi; echo *.[ch]); \
	do test -r arch/arm/efi/$f || \
	   ln -nsf ../../../common/efi/$f arch/arm/efi/; \
	done; \
	true

make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C include
make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include'
make[3]: Nothing to be done for 'all'.
make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C arch/arm asm-offsets.s
make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm'
make[3]: 'asm-offsets.s' is up to date.
make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk include/asm-arm/asm-offsets.h
make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen'
make[3]: 'include/asm-arm/asm-offsets.h' is up to date.
make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C arch/arm /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xen
make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common built_in.o
make[4]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common'
/home/otyshchenko/work/projects/toolchain/gcc-linaro-7.5.0-2019.12-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -MMD -MP -MF ./.ioreq.o.d -marm -DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wdeclaration-after-statement -Wno-unused-but-set-variable -Wno-unused-local-typedefs -O1 -fno-omit-frame-pointer -nostdinc -fno-builtin -fno-common -Werror -Wredundant-decls -Wno-pointer-arith -Wvla -pipe -D__XEN__ -include /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/config.h -Wa,--strip-local-absolute -g -msoft-float -mcpu=cortex-a15 -I/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include -fno-stack-protector -fno-exceptions -fno-asynchronous-unwind-tables -Wnested-externs '-D__OBJECT_FILE__="ioreq.o"' -c ioreq.c -o ioreq.o
/home/otyshchenko/work/projects/toolchain/gcc-linaro-7.5.0-2019.12-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -MMD -MP -MF ./.memory.o.d -marm -DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wdeclaration-after-statement -Wno-unused-but-set-variable -Wno-unused-local-typedefs -O1 -fno-omit-frame-pointer -nostdinc -fno-builtin -fno-common -Werror -Wredundant-decls -Wno-pointer-arith -Wvla -pipe -D__XEN__ -include /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/config.h -Wa,--strip-local-absolute -g -msoft-float -mcpu=cortex-a15 -I/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include -fno-stack-protector -fno-exceptions -fno-asynchronous-unwind-tables -Wnested-externs '-D__OBJECT_FILE__="memory.o"' -c memory.c -o memory.o
/home/otyshchenko/work/projects/toolchain/gcc-linaro-7.5.0-2019.12-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -MMD -MP -MF ./.version.o.d -marm -DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wdeclaration-after-statement -Wno-unused-but-set-variable -Wno-unused-local-typedefs -O1 -fno-omit-frame-pointer -nostdinc -fno-builtin -fno-common -Werror -Wredundant-decls -Wno-pointer-arith -Wvla -pipe -D__XEN__ -include /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/config.h -Wa,--strip-local-absolute -g -msoft-float -mcpu=cortex-a15 -I/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include -fno-stack-protector -fno-exceptions -fno-asynchronous-unwind-tables -Wnested-externs '-D__OBJECT_FILE__="version.o"' -c version.c -o version.o
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C sched built_in.o
make[5]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common/sched'
make[5]: 'built_in.o' is up to date.
make[5]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common/sched'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C libfdt built_in.o
make[5]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common/libfdt'
make[5]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common/libfdt'
/home/otyshchenko/work/projects/toolchain/gcc-linaro-7.5.0-2019.12-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ld -EL -r -o built_in.o bitmap.o config_data.o cpu.o device_tree.o domain.o event_2l.o event_channel.o event_fifo.o grant_table.o guestcopy.o hypfs.o ioreq.o irq.o kernel.o keyhandler.o lib.o memory.o multicall.o notifier.o page_alloc.o pdx.o preempt.o random.o rangeset.o radix-tree.o rcupdate.o rwlock.o shutdown.o softirq.o smp.o spinlock.o stop_machine.o string.o symbols.o tasklet.o time.o timer.o trace.o version.o virtual_region.o vm_event.o vmap.o vsprintf.o wait.o xmalloc_tlsf.o domctl.o monitor.o sysctl.o sched/built_in.o libfdt/built_in.o gunzip.init.o warning.init.o
make[4]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/drivers built_in.o
make[4]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/drivers'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C char built_in.o
make[5]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/drivers/char'
make[5]: 'built_in.o' is up to date.
make[5]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/drivers/char'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C passthrough built_in.o
make[5]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/drivers/passthrough'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C arm built_in.o
make[6]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/drivers/passthrough/arm'
make[6]: 'built_in.o' is up to date.
make[6]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/drivers/passthrough/arm'
make[5]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/drivers/passthrough'
make[4]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/drivers'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/lib built_in.o
make[4]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/lib'
make[4]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/lib'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xsm built_in.o
make[4]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xsm'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C flask built_in.o
make[5]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xsm/flask'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C ss built_in.o
make[6]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xsm/flask/ss'
make[6]: 'built_in.o' is up to date.
make[6]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xsm/flask/ss'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/../tools/flask/policy/Makefile.common -C /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/../tools/flask/policy FLASK_BUILD_DIR=/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xsm/flask make[6]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/tools/flask/policy'
make[6]: Nothing to be done for 'all'.
make[6]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/tools/flask/policy'
cmp -s /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xsm/flask/xenpolicy-4.15-unstable policy.bin || cp /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xsm/flask/xenpolicy-4.15-unstable policy.bin
make[5]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xsm/flask'
make[4]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xsm'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm built_in.o
make[4]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C arm32 built_in.o
make[5]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm/arm32'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C lib built_in.o
make[6]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm/arm32/lib'
make[6]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm/arm32/lib'
make[5]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm/arm32'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C platforms built_in.o
make[5]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm/platforms'
make[5]: 'built_in.o' is up to date.
make[5]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm/platforms'
/home/otyshchenko/work/projects/toolchain/gcc-linaro-7.5.0-2019.12-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -MMD -MP -MF ./.dm.o.d -marm -DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wdeclaration-after-statement -Wno-unused-but-set-variable -Wno-unused-local-typedefs -O1 -fno-omit-frame-pointer -nostdinc -fno-builtin -fno-common -Werror -Wredundant-decls -Wno-pointer-arith -Wvla -pipe -D__XEN__ -include /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/config.h -Wa,--strip-local-absolute -g -msoft-float -mcpu=cortex-a15 -I/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include -fno-stack-protector -fno-exceptions -fno-asynchronous-unwind-tables -Wnested-externs '-D__OBJECT_FILE__="dm.o"' -c dm.c -o dm.o
In file included from dm.c:17:0:
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/dm.h:28:26: error: array type has incomplete element type ‘struct xen_dm_op_buf’

     struct xen_dm_op_buf buf[2];
                          ^~~
In file included from /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/asm/system.h:5:0,
                 from /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/asm/time.h:5,
                 from /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/time.h:76,
                 from /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/spinlock.h:4,
                 from /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/sched.h:6,
                 from /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/dm.h:20,
                 from dm.c:17:
dm.c: In function ‘do_dm_op’:
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/lib.h:45:36: error: expression in static assertion is not an integer
     sizeof(struct { _Static_assert(!(cond), "!(" #cond ")"); })
                                    ^

/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/compiler.h:94:3: note: in expansion of macro ‘BUILD_BUG_ON_ZERO’
BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0])))
^~~~~~~~~~~~~~~~~
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/lib.h:76:53: note: in expansion of macro ‘__must_be_array’

 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x))
                                                     ^~~~~~~~~~~~~~~

dm.c:148:20: note: in expansion of macro ‘ARRAY_SIZE’
if ( nr_bufs > ARRAY_SIZE(args.buf) )
^~~~~~~~~~
In file included from /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/sched.h:18:0,

                 from /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/dm.h:20,
                 from dm.c:17:
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/lib.h:45:36: error: expression in static assertion is not an integer
     sizeof(struct { _Static_assert(!(cond), "!(" #cond ")"); })
                                    ^
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/nospec.h:54:12: note: in definition of macro ‘array_index_nospec’
     typeof(size) _s = (size);                                           \
            ^~~~

/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/compiler.h:94:3: note: in expansion of macro ‘BUILD_BUG_ON_ZERO’
BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0])))
^~~~~~~~~~~~~~~~~
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/lib.h:76:53: note: in expansion of macro ‘__must_be_array’

 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x))
                                                     ^~~~~~~~~~~~~~~
dm.c:152:48: note: in expansion of macro ‘ARRAY_SIZE’
     args.nr_bufs = array_index_nospec(nr_bufs, ARRAY_SIZE(args.buf) + 1);
                                                ^~~~~~~~~~
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/lib.h:45:36: error: expression in static assertion is not an integer
     sizeof(struct { _Static_assert(!(cond), "!(" #cond ")"); })
                                    ^
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/nospec.h:54:24: note: in definition of macro ‘array_index_nospec’
     typeof(size) _s = (size);                                           \
                        ^~~~

/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/compiler.h:94:3: note: in expansion of macro ‘BUILD_BUG_ON_ZERO’
BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0])))
^~~~~~~~~~~~~~~~~
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/lib.h:76:53: note: in expansion of macro ‘__must_be_array’

 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x))
                                                     ^~~~~~~~~~~~~~~
dm.c:152:48: note: in expansion of macro ‘ARRAY_SIZE’
     args.nr_bufs = array_index_nospec(nr_bufs, ARRAY_SIZE(args.buf) + 1);
                                                ^~~~~~~~~~
In file included from dm.c:18:0:
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/guest_access.h:83:32: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
     const typeof(*(ptr)) *_s = (hnd).p;                 \
                                ^
dm.c:154:10: note: in expansion of macro ‘copy_from_guest_offset’
     if ( copy_from_guest_offset(&args.buf[0], bufs, 0, args.nr_bufs) )
          ^~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk:197: recipe for target 'dm.o' failed
make[4]: *** [dm.o] Error 1
make[4]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm' /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk:180: recipe for target '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm/built_in.o' failed make[3]: *** [/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm/built_in.o] Error 2
make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm'
Makefile:359: recipe for target '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xen' failed
make[2]: *** [/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xen] Error 2
make[2]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen'
Makefile:263: recipe for target 'install' failed
make[1]: *** [install] Error 2
make[1]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen'
Makefile:130: recipe for target 'install-xen' failed
make: *** [install-xen] Error 2
otyshchenko@otyshchenko:/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git$

make xen XEN_TARGET_ARCH=arm32 CROSS_COMPILE=/home/otyshchenko/work/projects/toolchain/gcc-linaro-7.5.0-2019.12-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- make -C xen install
make[1]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen' make -f Rules.mk _install
make[2]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen' sed "s! $PWD/! !" ..xen-syms.0.o.d >..xen-syms.0.o.d2.tmp && mv -f ..xen-syms.0.o.d2.tmp ..xen-syms.0.o.d2
sed "s! $PWD/! !" ..xen-syms.1.o.d >..xen-syms.1.o.d2.tmp && mv -f ..xen-syms.1.o.d2.tmp ..xen-syms.1.o.d2
make -C tools
make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/tools' make symbols
make[4]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/tools' make[4]: 'symbols' is up to date.
make[4]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/tools' make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/tools' make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk include/xen/compile.h make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen'
Xen 4.15-unstable
make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen' [ -e include/asm ] || ln -sf asm-arm include/asm

[ -e arch/arm/efi ] && for f in $(cd common/efi; echo *.[ch]); \
	do test -r arch/arm/efi/$f || \
	   ln -nsf ../../../common/efi/$f arch/arm/efi/; \
	done; \
	true

make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C include
make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include'
make[3]: Nothing to be done for 'all'.
make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C arch/arm asm-offsets.s
make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm'
make[3]: 'asm-offsets.s' is up to date.
make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk include/asm-arm/asm-offsets.h
make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen'
make[3]: 'include/asm-arm/asm-offsets.h' is up to date.
make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C arch/arm /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xen make[3]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm'
make -f /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk -C /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common built_in.o make[4]: Entering directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common'
sed "s! $PWD/! !" .version.o.d >.version.o.d2.tmp && mv -f .version.o.d2.tmp .version.o.d2
/home/otyshchenko/work/projects/toolchain/gcc-linaro-7.5.0-2019.12-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -MMD -MP -MF ./.ioreq.o.d -marm -DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wdeclaration-after-statement -Wno-unused-but-set-variable -Wno-unused-local-typedefs -O1 -fno-omit-frame-pointer -nostdinc -fno-builtin -fno-common -Werror -Wredundant-decls -Wno-pointer-arith -Wvla -pipe -D__XEN__ -include /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/config.h -Wa,--strip-local-absolute -g -msoft-float -mcpu=cortex-a15 -I/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include -fno-stack-protector -fno-exceptions -fno-asynchronous-unwind-tables -Wnested-externs '-D__OBJECT_FILE__="ioreq.o"' -c ioreq.c -o ioreq.o
In file included from ioreq.c:23:0:
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/ioreq.h:39:28: error: ‘XEN_DMOP_IO_RANGE_PCI’ undeclared here (not in a function); did you mean ‘XEN_DOMCTL_DEV_PCI’?

 #define NR_IO_RANGE_TYPES (XEN_DMOP_IO_RANGE_PCI + 1)
                            ^
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/ioreq.h:55:35: note: in expansion of macro ‘NR_IO_RANGE_TYPES’
     struct rangeset        *range[NR_IO_RANGE_TYPES];
                                   ^~~~~~~~~~~~~~~~~
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/ioreq.h:92:46: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 int ioreq_server_get_frame(struct domain *d, ioservid_t id,
                                              ^~~~~~~~~~
                                              nodeid_t
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/ioreq.h:94:49: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 int ioreq_server_map_mem_type(struct domain *d, ioservid_t id,
                                                 ^~~~~~~~~~
                                                 nodeid_t
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/ioreq.h:110:31: error: ‘struct xen_dm_op’ declared inside parameter list will not be visible outside of this definition or declaration [-Werror]
 int ioreq_server_dm_op(struct xen_dm_op *op, struct domain *d, bool *const_op);
                               ^~~~~~~~~
ioreq.c:484:41: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
                                         ioservid_t id)
                                         ^~~~~~~~~~
                                         nodeid_t
ioreq.c:560:30: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
                              ioservid_t id)
                              ^~~~~~~~~~
                              nodeid_t
ioreq.c:626:32: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
                                ioservid_t *id)
                                ^~~~~~~~~~
                                nodeid_t
ioreq.c:681:51: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 static int ioreq_server_destroy(struct domain *d, ioservid_t id)
                                                   ^~~~~~~~~~
                                                   nodeid_t
ioreq.c:723:52: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 static int ioreq_server_get_info(struct domain *d, ioservid_t id,
                                                    ^~~~~~~~~~
                                                    nodeid_t
ioreq.c:770:46: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 int ioreq_server_get_frame(struct domain *d, ioservid_t id,
                                              ^~~~~~~~~~
                                              nodeid_t
ioreq.c:821:56: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 static int ioreq_server_map_io_range(struct domain *d, ioservid_t id,
                                                        ^~~~~~~~~~
                                                        nodeid_t
ioreq.c:873:58: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 static int ioreq_server_unmap_io_range(struct domain *d, ioservid_t id,
                                                          ^~~~~~~~~~
                                                          nodeid_t
ioreq.c:933:49: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 int ioreq_server_map_mem_type(struct domain *d, ioservid_t id,
                                                 ^~~~~~~~~~
                                                 nodeid_t
ioreq.c:968:53: error: unknown type name ‘ioservid_t’; did you mean ‘nodeid_t’?
 static int ioreq_server_set_state(struct domain *d, ioservid_t id,
                                                     ^~~~~~~~~~
                                                     nodeid_t
ioreq.c: In function ‘ioreq_server_select’:
ioreq.c:1103:14: error: ‘XEN_DMOP_IO_RANGE_PORT’ undeclared (first use in this function); did you mean ‘XEN_DMOP_IO_RANGE_PCI’?
         case XEN_DMOP_IO_RANGE_PORT:
              ^~~~~~~~~~~~~~~~~~~~~~
              XEN_DMOP_IO_RANGE_PCI
ioreq.c:1103:14: note: each undeclared identifier is reported only once for each function it appears in
ioreq.c:1111:14: error: ‘XEN_DMOP_IO_RANGE_MEMORY’ undeclared (first use in this function); did you mean ‘XEN_DMOP_IO_RANGE_PORT’?
         case XEN_DMOP_IO_RANGE_MEMORY:
              ^~~~~~~~~~~~~~~~~~~~~~~~
              XEN_DMOP_IO_RANGE_PORT
ioreq.c: At top level:
ioreq.c:1313:31: error: ‘struct xen_dm_op’ declared inside parameter list will not be visible outside of this definition or declaration [-Werror]
 int ioreq_server_dm_op(struct xen_dm_op *op, struct domain *d, bool *const_op)
                               ^~~~~~~~~
ioreq.c:1313:5: error: conflicting types for ‘ioreq_server_dm_op’
 int ioreq_server_dm_op(struct xen_dm_op *op, struct domain *d, bool *const_op)
     ^~~~~~~~~~~~~~~~~~
In file included from ioreq.c:23:0:
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/include/xen/ioreq.h:110:5: note: previous declaration of ‘ioreq_server_dm_op’ was here
 int ioreq_server_dm_op(struct xen_dm_op *op, struct domain *d, bool *const_op);
     ^~~~~~~~~~~~~~~~~~
ioreq.c: In function ‘ioreq_server_dm_op’:
ioreq.c:1317:16: error: dereferencing pointer to incomplete type ‘struct xen_dm_op’
     switch ( op->op )
                ^~
ioreq.c:1319:10: error: ‘XEN_DMOP_create_ioreq_server’ undeclared (first use in this function); did you mean ‘XENMEM_resource_ioreq_server’?
     case XEN_DMOP_create_ioreq_server:
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
          XENMEM_resource_ioreq_server
ioreq.c:1327:18: error: dereferencing pointer to incomplete type ‘struct xen_dm_op_create_ioreq_server’
         if ( data->pad[0] || data->pad[1] || data->pad[2] )
                  ^~
ioreq.c:1330:14: error: implicit declaration of function ‘ioreq_server_create’; did you mean ‘ioreq_server_disable’? [-Werror=implicit-function-declaration]
         rc = ioreq_server_create(d, data->handle_bufioreq,
              ^~~~~~~~~~~~~~~~~~~
              ioreq_server_disable
ioreq.c:1330:14: error: nested extern declaration of ‘ioreq_server_create’ [-Werror=nested-externs]
ioreq.c:1335:10: error: ‘XEN_DMOP_get_ioreq_server_info’ undeclared (first use in this function); did you mean ‘XEN_DMOP_create_ioreq_server’?
     case XEN_DMOP_get_ioreq_server_info:
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          XEN_DMOP_create_ioreq_server
ioreq.c:1339:38: error: ‘XEN_DMOP_no_gfns’ undeclared (first use in this function)
         const uint16_t valid_flags = XEN_DMOP_no_gfns;
                                      ^~~~~~~~~~~~~~~~
ioreq.c:1344:18: error: dereferencing pointer to incomplete type ‘struct xen_dm_op_get_ioreq_server_info’
         if ( data->flags & ~valid_flags )
                  ^~
ioreq.c:1347:14: error: implicit declaration of function ‘ioreq_server_get_info’; did you mean ‘ioreq_server_deinit’? [-Werror=implicit-function-declaration]
         rc = ioreq_server_get_info(d, data->id,
              ^~~~~~~~~~~~~~~~~~~~~
              ioreq_server_deinit
ioreq.c:1347:14: error: nested extern declaration of ‘ioreq_server_get_info’ [-Werror=nested-externs]
ioreq.c:1356:10: error: ‘XEN_DMOP_map_io_range_to_ioreq_server’ undeclared (first use in this function); did you mean ‘XEN_DMOP_create_ioreq_server’?
     case XEN_DMOP_map_io_range_to_ioreq_server:
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          XEN_DMOP_create_ioreq_server
ioreq.c:1362:18: error: dereferencing pointer to incomplete type ‘const struct xen_dm_op_ioreq_server_range’
         if ( data->pad )
                  ^~
ioreq.c:1365:14: error: implicit declaration of function ‘ioreq_server_map_io_range’; did you mean ‘ioreq_server_alloc_pages’? [-Werror=implicit-function-declaration]
         rc = ioreq_server_map_io_range(d, data->id, data->type,
              ^~~~~~~~~~~~~~~~~~~~~~~~~
              ioreq_server_alloc_pages
ioreq.c:1365:14: error: nested extern declaration of ‘ioreq_server_map_io_range’ [-Werror=nested-externs]
ioreq.c:1370:10: error: ‘XEN_DMOP_unmap_io_range_from_ioreq_server’ undeclared (first use in this function); did you mean ‘XEN_DMOP_map_io_range_to_ioreq_server’?
     case XEN_DMOP_unmap_io_range_from_ioreq_server:
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          XEN_DMOP_map_io_range_to_ioreq_server
ioreq.c:1376:18: error: dereferencing pointer to incomplete type ‘const struct xen_dm_op_ioreq_server_range’
         if ( data->pad )
                  ^~
ioreq.c:1379:14: error: implicit declaration of function ‘ioreq_server_unmap_io_range’; did you mean ‘ioreq_server_alloc_pages’? [-Werror=implicit-function-declaration]
         rc = ioreq_server_unmap_io_range(d, data->id, data->type,
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~
              ioreq_server_alloc_pages
ioreq.c:1379:14: error: nested extern declaration of ‘ioreq_server_unmap_io_range’ [-Werror=nested-externs]
ioreq.c:1384:10: error: ‘XEN_DMOP_set_ioreq_server_state’ undeclared (first use in this function); did you mean ‘XEN_DMOP_get_ioreq_server_info’?
     case XEN_DMOP_set_ioreq_server_state:
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          XEN_DMOP_get_ioreq_server_info
ioreq.c:1390:18: error: dereferencing pointer to incomplete type ‘const struct xen_dm_op_set_ioreq_server_state’
         if ( data->pad )
                  ^~
ioreq.c:1393:14: error: implicit declaration of function ‘ioreq_server_set_state’; did you mean ‘ioreq_server_select’? [-Werror=implicit-function-declaration]
         rc = ioreq_server_set_state(d, data->id, !!data->enabled);
              ^~~~~~~~~~~~~~~~~~~~~~
              ioreq_server_select
ioreq.c:1393:14: error: nested extern declaration of ‘ioreq_server_set_state’ [-Werror=nested-externs]
ioreq.c:1397:10: error: ‘XEN_DMOP_destroy_ioreq_server’ undeclared (first use in this function); did you mean ‘XEN_DMOP_create_ioreq_server’?
     case XEN_DMOP_destroy_ioreq_server:
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          XEN_DMOP_create_ioreq_server
ioreq.c:1403:18: error: dereferencing pointer to incomplete type ‘const struct xen_dm_op_destroy_ioreq_server’
         if ( data->pad )
                  ^~
ioreq.c:1406:14: error: implicit declaration of function ‘ioreq_server_destroy’; did you mean ‘ioreq_server_destroy_all’? [-Werror=implicit-function-declaration]
         rc = ioreq_server_destroy(d, data->id);
              ^~~~~~~~~~~~~~~~~~~~
              ioreq_server_destroy_all

ioreq.c:1406:14: error: nested extern declaration of ‘ioreq_server_destroy’ [-Werror=nested-externs] At top level:
ioreq.c:521:13: error: ‘ioreq_server_enable’ defined but not used [-Werror=unused-function]
static void ioreq_server_enable(struct ioreq_server *s)

             ^~~~~~~~~~~~~~~~~~~
ioreq.c:454:12: error: ‘ioreq_server_alloc_pages’ defined but not used [-Werror=unused-function]
 static int ioreq_server_alloc_pages(struct ioreq_server *s)
            ^~~~~~~~~~~~~~~~~~~~~~~~
ioreq.c:64:29: error: ‘get_ioreq_server’ defined but not used [-Werror=unused-function]
 static struct ioreq_server *get_ioreq_server(const struct domain *d,
                             ^~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk:197: recipe for target 'ioreq.o' failed
make[4]: *** [ioreq.o] Error 1
make[4]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common' /media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/Rules.mk:180: recipe for target '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common/built_in.o' failed make[3]: *** [/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/common/built_in.o] Error 2
make[3]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/arch/arm'
Makefile:359: recipe for target '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xen' failed
make[2]: *** [/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen/xen] Error 2
make[2]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen'
Makefile:263: recipe for target 'install' failed
make[1]: *** [install] Error 2
make[1]: Leaving directory '/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git/xen'
Makefile:130: recipe for target 'install-xen' failed
make: *** [install-xen] Error 2
otyshchenko@otyshchenko:/media/b/build/build/tmp/work/x86_64-xt-linux/domd-image-weston/1.0-r0/repo/build/tmp/work/aarch64-poky-linux/xen/4.14.0+gitAUTOINC+2c6e5a8ceb-r0/git$

#85 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

Hi Oleksandr,

Quoted 56 lines · Oleksandr
Quoted 9 lines · Julien Grall
Quoted 4 lines · Oleksandr

On 15.01.21 22:26, Julien Grall wrote:

Hi Julien

Hi Oleksandr,

Hi Julien

Quoted 39 lines
Quoted 24 lines
Quoted 16 lines
Quoted 16 lines

+
      PROGRESS(xen):
          ret = relinquish_memory(d, &d->xenpage_list); if ( ret )

xen/arch/arm/io.c +0 -0
index ae7ef96..9814481 100644
@@ -16,6 +16,7 @@
    * GNU General Public License for more details.
    */

  +#include <xen/ioreq.h>
  #include <xen/lib.h>
  #include <xen/spinlock.h>

Quoted 8 lines

xen/arch/arm/io.c line 27

Quoted 6 lines

  #include <xen/sched.h>

xen/arch/arm/io.c +1 -0
@@ -23,6 +24,7 @@
   #include <asm/cpuerrata.h>
   #include <asm/current.h>
   #include <asm/mmio.h>
+#include <asm/hvm/ioreq.h>

Shouldn't this have been included by "xen/ioreq.h"?

Quoted 2 lines

Well, for V1 asm/hvm/ioreq.h was included by xen/ioreq.h. But, it turned out that there was nothing inside common header required arch one to be included and I was asked to include arch header where it was indeed needed (several *.c files).

Fair enough.

[...]

Quoted 7 lines
Quoted 2 lines

If you return IO_HANDLED here, then it means the we will take care of previous I/O but the current one is going to be ignored.

Which current one? As I understand, if try_fwd_ioserv() gets called with vio->req.state == STATE_IORESP_READY then this is a second round after emulator completes the emulation (the first round was when we returned IO_RETRY down the function and claimed that we would need a completion), so we are still dealing with previous I/O.
vcpu_ioreq_handle_completion() -> arch_ioreq_complete_mmio() -> try_handle_mmio() -> try_fwd_ioserv() -> handle_ioserv()
And after we return IO_HANDLED here, handle_ioserv() will be called to complete the handling of this previous I/O emulation.
Or I really missed something?

Quoted 6 lines
Quoted 1 line

Hmmm... I somehow thought try_fw_ioserv() would only be called the first time. Do you have a branch with your code applied? This would help to follow the different paths.

Yes, I mentioned about it in cover letter.

Please see
https://github.com/otyshchenko1/xen/commits/ioreq_4.14_ml5
why 5 - because I started counting from the RFC)

Oh, I looked at the cover letter and didn't find it. Hence why I asked. I should have looked more carefully. Thanks!

I have looked closer at the question and I am not sure to understand why arch_ioreq_complete_mmio() is going to call try_handle_mmio().

This looks pretty innefficient to me because we already now the IO was handled by the IOREQ server.

I realize that x86 is calling handle_mmio() again. However, I don't think we need the same on Arm because the instruction for accessing device memory are a lot simpler (you can only read or store at most a 64-bit value).

So I would like to keep our emulation simple and not rely on try_ioserv_fw() to always return true when call from completion (AFAICT it is not possible to return false then).

I will answer to the rest separately.

Cheers,

Signature · 1 line
Julien Grall
#86 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

Hi Julien

Quoted 48 lines
Quoted 41 lines
Quoted 41 lines
Quoted 26 lines
Quoted 18 lines
Quoted 18 lines

+
      PROGRESS(xen):
          ret = relinquish_memory(d, &d->xenpage_list); if ( ret )

xen/arch/arm/io.c +0 -0
index ae7ef96..9814481 100644
@@ -16,6 +16,7 @@
    * GNU General Public License for more details.
    */

  +#include <xen/ioreq.h>
  #include <xen/lib.h>
  #include <xen/spinlock.h>

Quoted 8 lines

xen/arch/arm/io.c line 27

Quoted 6 lines

  #include <xen/sched.h>

xen/arch/arm/io.c +1 -0
@@ -23,6 +24,7 @@
   #include <asm/cpuerrata.h>
   #include <asm/current.h>
   #include <asm/mmio.h>
+#include <asm/hvm/ioreq.h>

Shouldn't this have been included by "xen/ioreq.h"?

Quoted 2 lines

Well, for V1 asm/hvm/ioreq.h was included by xen/ioreq.h. But, it turned out that there was nothing inside common header required arch one to be included and I was asked to include arch header where it was indeed needed (several *.c files).

Fair enough.

[...]

Quoted 7 lines
Quoted 2 lines

If you return IO_HANDLED here, then it means the we will take care of previous I/O but the current one is going to be ignored.

Which current one? As I understand, if try_fwd_ioserv() gets called with vio->req.state == STATE_IORESP_READY then this is a second round after emulator completes the emulation (the first round was when we returned IO_RETRY down the function and claimed that we would need a completion), so we are still dealing with previous I/O.
vcpu_ioreq_handle_completion() -> arch_ioreq_complete_mmio() -> try_handle_mmio() -> try_fwd_ioserv() -> handle_ioserv()
And after we return IO_HANDLED here, handle_ioserv() will be called to complete the handling of this previous I/O emulation.
Or I really missed something?

Quoted 6 lines
Quoted 1 line

Hmmm... I somehow thought try_fw_ioserv() would only be called the first time. Do you have a branch with your code applied? This would help to follow the different paths.

Yes, I mentioned about it in cover letter.

Please see
https://github.com/otyshchenko1/xen/commits/ioreq_4.14_ml5
why 5 - because I started counting from the RFC)

Quoted 7 lines

Oh, I looked at the cover letter and didn't find it. Hence why I asked. I should have looked more carefully. Thanks!

I have looked closer at the question and I am not sure to understand why arch_ioreq_complete_mmio() is going to call try_handle_mmio().

This looks pretty innefficient to me because we already now the IO was handled by the IOREQ server.

I realize that x86 is calling handle_mmio() again. However, I don't think we need the same on Arm because the instruction for accessing device memory are a lot simpler (you can only read or store at most a 64-bit value).

I think, I agree.

Quoted 2 lines

So I would like to keep our emulation simple and not rely on try_ioserv_fw() to always return true when call from completion (AFAICT it is not possible to return false then).

So what you are proposing is just a replacement try_ioserv_fw() by handle_ioserv() technically?

xen/arch/arm/ioreq.c +0 -0
index 40b9e59..0508bd8 100644
@@ -101,12 +101,10 @@ enum io_state try_fwd_ioserv(struct cpu_user_regs *regs,
 

 bool arch_ioreq_complete_mmio(void)
 {
-    struct vcpu *v = current;
     struct cpu_user_regs *regs = guest_cpu_user_regs(); const union hsr hsr = { .bits = regs->hsr }; -    paddr_t addr = v->io.req.addr;

-    if ( try_handle_mmio(regs, hsr, addr) == IO_HANDLED ) +    if ( handle_ioserv(regs, current) == IO_HANDLED ) {
         advance_pc(regs, hsr);
         return true;

Quoted 2 lines

I will answer to the rest separately.

Thank you.

Quoted 3 lines

Cheers,

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
#87 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

Quoted 60 lines · Oleksandr
Quoted 60 lines
Quoted 45 lines
Quoted 45 lines
Quoted 21 lines
Quoted 13 lines
Quoted 13 lines

      PROGRESS(xen):
          ret = relinquish_memory(d, &d->xenpage_list); if ( ret )

xen/arch/arm/io.c +0 -0
index ae7ef96..9814481 100644
@@ -16,6 +16,7 @@
    * GNU General Public License for more details.
    */

  +#include <xen/ioreq.h>
  #include <xen/lib.h>
  #include <xen/spinlock.h>

Quoted 8 lines

xen/arch/arm/io.c line 27

Quoted 6 lines

  #include <xen/sched.h>

xen/arch/arm/io.c +1 -0
@@ -23,6 +24,7 @@
   #include <asm/cpuerrata.h>
   #include <asm/current.h>
   #include <asm/mmio.h>
+#include <asm/hvm/ioreq.h>

Shouldn't this have been included by "xen/ioreq.h"?

Quoted 5 lines

Well, for V1 asm/hvm/ioreq.h was included by xen/ioreq.h. But, it turned out that there was nothing inside common header required arch one to be included and
I was asked to include arch header where it was indeed needed (several *.c files).

Fair enough.

[...]

Quoted 13 lines
Quoted 3 lines

If you return IO_HANDLED here, then it means the we will take care of previous I/O but the current one is going to be ignored.

Which current one? As I understand, if try_fwd_ioserv() gets called with vio->req.state == STATE_IORESP_READY then this is a second round after emulator completes the emulation (the first round was when we returned IO_RETRY down the function and claimed that we would need a completion), so we are still dealing with previous I/O. vcpu_ioreq_handle_completion() -> arch_ioreq_complete_mmio() -> try_handle_mmio() -> try_fwd_ioserv() -> handle_ioserv() And after we return IO_HANDLED here, handle_ioserv() will be called to complete the handling of this previous I/O emulation.
Or I really missed something?

Quoted 8 lines
Quoted 3 lines

Hmmm... I somehow thought try_fw_ioserv() would only be called the first time. Do you have a branch with your code applied? This would help to follow the different paths.

Yes, I mentioned about it in cover letter.

Please see
https://github.com/otyshchenko1/xen/commits/ioreq_4.14_ml5
why 5 - because I started counting from the RFC)

Oh, I looked at the cover letter and didn't find it. Hence why I asked. I should have looked more carefully. Thanks!

I have looked closer at the question and I am not sure to understand why arch_ioreq_complete_mmio() is going to call try_handle_mmio().

Quoted 8 lines
Quoted 6 lines

This looks pretty innefficient to me because we already now the IO was handled by the IOREQ server.

I realize that x86 is calling handle_mmio() again. However, I don't think we need the same on Arm because the instruction for accessing device memory are a lot simpler (you can only read or store at most a 64-bit value).

I think, I agree.

Yes I agree too

Quoted 17 lines
Quoted 3 lines

So I would like to keep our emulation simple and not rely on try_ioserv_fw() to always return true when call from completion (AFAICT it is not possible to return false then).

So what you are proposing is just a replacement try_ioserv_fw() by handle_ioserv() technically?

xen/arch/arm/ioreq.c +0 -0
index 40b9e59..0508bd8 100644
@@ -101,12 +101,10 @@ enum io_state try_fwd_ioserv(struct cpu_user_regs *regs,
 
  bool arch_ioreq_complete_mmio(void)
  {

xen/arch/arm/ioreq.c enum io_state try_fwd_ioserv(struct cpu_user_regs *regs, · line 110

Quoted 10 lines
xen/arch/arm/ioreq.c +1 -3
-    struct vcpu *v = current;
      struct cpu_user_regs *regs = guest_cpu_user_regs();
      const union hsr hsr = { .bits = regs->hsr };
-    paddr_t addr = v->io.req.addr;
 
-    if ( try_handle_mmio(regs, hsr, addr) == IO_HANDLED )
+    if ( handle_ioserv(regs, current) == IO_HANDLED )
      {
          advance_pc(regs, hsr);
          return true;

Yes, but I think we want to keep the check

    vio->req.state == STATE_IORESP_READY

So maybe (uncompiled, untested):

    if ( v->io.req.state != STATE_IORESP_READY )
        return false;

    if ( handle_ioserv(regs, current) == IO_HANDLED )
    {
        advance_pc(regs, hsr);
        return true;
    }
#88 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

Hi Stefano,

Quoted 22 lines · Stefano Stabellini
Quoted 8 lines · Oleksandr
xen/arch/arm/ioreq.c +0 -0
index 40b9e59..0508bd8 100644
@@ -101,12 +101,10 @@ enum io_state try_fwd_ioserv(struct cpu_user_regs *regs,
 
  bool arch_ioreq_complete_mmio(void)
  {

xen/arch/arm/ioreq.c enum io_state try_fwd_ioserv(struct cpu_user_regs *regs, · line 110

Quoted 10 lines
xen/arch/arm/ioreq.c +1 -3
-    struct vcpu *v = current;
      struct cpu_user_regs *regs = guest_cpu_user_regs();
      const union hsr hsr = { .bits = regs->hsr };
-    paddr_t addr = v->io.req.addr;
 
-    if ( try_handle_mmio(regs, hsr, addr) == IO_HANDLED )
+    if ( handle_ioserv(regs, current) == IO_HANDLED )
      {
          advance_pc(regs, hsr);
          return true;

Yes, but I think we want to keep the check

Quoted 6 lines
     vio->req.state == STATE_IORESP_READY

So maybe (uncompiled, untested):

     if ( v->io.req.state != STATE_IORESP_READY )
         return false;

Is it possible to reach this function with v->io.req.state != STATE_IORESP_READY? If not, then I would suggest to add an ASSERT_UNREACHABLE() before the return.

Cheers,

Signature · 1 line
Julien Grall
#89 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

Quoted 28 lines · Julien Grall

Hi Stefano,

Quoted 25 lines · Stefano Stabellini
Quoted 18 lines · Oleksandr
xen/arch/arm/ioreq.c +1 -3
index 40b9e59..0508bd8 100644
@@ -101,12 +101,10 @@ enum io_state try_fwd_ioserv(struct cpu_user_regs
 *regs,
 
  bool arch_ioreq_complete_mmio(void)
  {
-    struct vcpu *v = current;
      struct cpu_user_regs *regs = guest_cpu_user_regs();
      const union hsr hsr = { .bits = regs->hsr };
-    paddr_t addr = v->io.req.addr;
 
-    if ( try_handle_mmio(regs, hsr, addr) == IO_HANDLED )
+    if ( handle_ioserv(regs, current) == IO_HANDLED )
      {
          advance_pc(regs, hsr);
Quoted 1 line

         return true;

Yes, but I think we want to keep the check

     vio->req.state == STATE_IORESP_READY
Quoted 8 lines
Quoted 4 lines

So maybe (uncompiled, untested):

     if ( v->io.req.state != STATE_IORESP_READY )
         return false;

Is it possible to reach this function with v->io.req.state != STATE_IORESP_READY? If not, then I would suggest to add an ASSERT_UNREACHABLE() before the return.

If I am reading the state machine right it should *not* be possible to get here with v->io.req.state != STATE_IORESP_READY, so yes, ASSERT_UNREACHABLE() would work.

#90 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

On 20.01.21 21:47, Stefano Stabellini wrote:

Hi Julien, Stefano

Quoted 30 lines · Julien Grall
Quoted 29 lines

Hi Stefano,

Quoted 26 lines · Stefano Stabellini
Quoted 18 lines · Oleksandr
xen/arch/arm/ioreq.c +1 -3
index 40b9e59..0508bd8 100644
@@ -101,12 +101,10 @@ enum io_state try_fwd_ioserv(struct cpu_user_regs
 *regs,
 
   bool arch_ioreq_complete_mmio(void)
   {
-    struct vcpu *v = current;
       struct cpu_user_regs *regs = guest_cpu_user_regs();
       const union hsr hsr = { .bits = regs->hsr };
-    paddr_t addr = v->io.req.addr;
 
-    if ( try_handle_mmio(regs, hsr, addr) == IO_HANDLED )
+    if ( handle_ioserv(regs, current) == IO_HANDLED )
       {
           advance_pc(regs, hsr);
Quoted 1 line

         return true;

Yes, but I think we want to keep the check

      vio->req.state == STATE_IORESP_READY

So maybe (uncompiled, untested):

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
      if ( v->io.req.state != STATE_IORESP_READY )
          return false;

Is it possible to reach this function with v->io.req.state != STATE_IORESP_READY? If not, then I would suggest to add an ASSERT_UNREACHABLE() before the return.

If I am reading the state machine right it should *not* be possible to get here with v->io.req.state != STATE_IORESP_READY, so yes, ASSERT_UNREACHABLE() would work.

Agree here. If the assumption is not correct (unlikely), I think I will catch this during testing. In addition, we can probably drop case STATE_IORESP_READY in try_fwd_ioserv().

[not tested]

xen/arch/arm/ioreq.c +0 -0
index 40b9e59..c7ee1a7 100644
@@ -71,9 +71,6 @@ enum io_state try_fwd_ioserv(struct cpu_user_regs *regs,

     case STATE_IOREQ_NONE:
         break;

-    case STATE_IORESP_READY:
-        return IO_HANDLED;
-
     default:
         gdprintk(XENLOG_ERR, "wrong state %u\n", vio->req.state); return IO_ABORT;
@@ -104,9 +101,14 @@ bool arch_ioreq_complete_mmio(void) struct vcpu *v = current;
     struct cpu_user_regs *regs = guest_cpu_user_regs(); const union hsr hsr = { .bits = regs->hsr };
-    paddr_t addr = v->io.req.addr;

-    if ( try_handle_mmio(regs, hsr, addr) == IO_HANDLED ) +    if ( v->io.req.state != STATE_IORESP_READY ) +    {
+        ASSERT_UNREACHABLE();
+        return false;
+    }
+
+    if ( handle_ioserv(regs, v) == IO_HANDLED ) {
         advance_pc(regs, hsr);
         return true;

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
#91 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

Quoted 40 lines · Oleksandr
Quoted 31 lines · Stefano Stabellini
Quoted 30 lines · Julien Grall

Hi Stefano,

Quoted 27 lines · Stefano Stabellini
Quoted 15 lines · Oleksandr
xen/arch/arm/ioreq.c +0 -0
index 40b9e59..0508bd8 100644
@@ -101,12 +101,10 @@ enum io_state try_fwd_ioserv(struct

cpu_user_regs
*regs,

 bool arch_ioreq_complete_mmio(void)
 {
-    struct vcpu *v = current;
     struct cpu_user_regs *regs = guest_cpu_user_regs(); const union hsr hsr = { .bits = regs->hsr };
-    paddr_t addr = v->io.req.addr;

Quoted 5 lines

-    if ( try_handle_mmio(regs, hsr, addr) == IO_HANDLED ) +    if ( handle_ioserv(regs, current) == IO_HANDLED )
     {
         advance_pc(regs, hsr);
         return true;

Yes, but I think we want to keep the check

      vio->req.state == STATE_IORESP_READY

So maybe (uncompiled, untested):

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
      if ( v->io.req.state != STATE_IORESP_READY )
          return false;

Is it possible to reach this function with v->io.req.state != STATE_IORESP_READY? If not, then I would suggest to add an ASSERT_UNREACHABLE() before the return.

If I am reading the state machine right it should *not* be possible to get here with v->io.req.state != STATE_IORESP_READY, so yes, ASSERT_UNREACHABLE() would work.

Quoted 6 lines

Agree here. If the assumption is not correct (unlikely), I think I will catch this during testing.
In addition, we can probably drop case STATE_IORESP_READY in try_fwd_ioserv().

[not tested]

Yes, looks OK

Quoted 31 lines
xen/arch/arm/ioreq.c +0 -0
index 40b9e59..c7ee1a7 100644
@@ -71,9 +71,6 @@ enum io_state try_fwd_ioserv(struct cpu_user_regs *regs,

     case STATE_IOREQ_NONE:
         break;

-    case STATE_IORESP_READY:
-        return IO_HANDLED;
-
     default:
         gdprintk(XENLOG_ERR, "wrong state %u\n", vio->req.state); return IO_ABORT;

xen/arch/arm/ioreq.c +7 -2
@@ -104,9 +101,14 @@ bool arch_ioreq_complete_mmio(void)
      struct vcpu *v = current;
      struct cpu_user_regs *regs = guest_cpu_user_regs();
      const union hsr hsr = { .bits = regs->hsr };
-    paddr_t addr = v->io.req.addr;
 
-    if ( try_handle_mmio(regs, hsr, addr) == IO_HANDLED )
+    if ( v->io.req.state != STATE_IORESP_READY )
+    {
+        ASSERT_UNREACHABLE();
+        return false;
+    }
+
+    if ( handle_ioserv(regs, v) == IO_HANDLED )
      {
          advance_pc(regs, hsr);
          return true;
#92 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

In reply to Oleksandr

Hi Oleksandr,

Quoted 11 lines · Oleksandr
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

xen/include/asm-arm/domain.h line 13

Quoted 9 lines

  diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index 6819a3b..c235e5b 100644

xen/include/asm-arm/domain.h +1 -0
@@ -10,6 +10,7 @@
   #include <asm/gic.h>
   #include <asm/vgic.h>
   #include <asm/vpl011.h>
+#include <public/hvm/dm_op.h>

May I ask, why do you need to include dm_op.h here?

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

I needed to include that header to make some bits visible (XEN_DMOP_IO_RANGE_PCI, struct xen_dm_op_buf, etc). Why here - is a really good question. I don't remember exactly, probably I followed x86's domain.h which also included it.
So, trying to remove the inclusion here, I get several build failures on Arm which could be fixed if I include that header from dm.h and ioreq.h:

Shall I do this way?

If the failure are indeded because ioreq.h and dm.h use definition from public/hvm/dm_op.h, then yes. Can you post the errors?

Please see attached, although I built for Arm32 (and the whole series), I think errors are valid for Arm64 also.

Thanks!

Quoted 1 line

error1.txt - when remove #include <public/hvm/dm_op.h> from asm-arm/domain.h

For this one, I agree that including <public/hvm/dm_op.h> in xen.h looks the best solution.

Quoted 1 line

error2.txt - when add #include <public/hvm/dm_op.h> to xen/ioreq.h

It looks like the error is happening in dm.c rather than xen/dm.h. Any reason to not include <public/hvm/dm_op.h> in dm.c directly?

Quoted 1 line

error3.txt - when add #include <public/hvm/dm_op.h> to xen/dm.h

I am a bit confused with this one. Isn't it the same as error1.txt?

Quoted 28 lines
Quoted 22 lines

[...]

Quoted 16 lines
Quoted 16 lines

xen/include/asm-arm/hvm/ioreq.h

Quoted 14 lines

  #include <public/hvm/params.h>
    struct hvm_domain

xen/include/asm-arm/domain.h +1 -0
@@ -262,6 +263,8 @@ static inline void arch_vcpu_block(struct vcpu 
 *v) {}
     #define arch_vm_assist_valid_mask(d) (1UL << VMASST_TYPE_runstate_update_flag)
   +#define has_vpci(d)    ({ (void)(d); false; })
+
   #endif /* __ASM_DOMAIN_H__ */
     /*
xen/include/asm-arm/hvm/ioreq.h new file +0 -0
new file mode 100644
index 0000000..19e1247

Shouldn't this directly be under asm-arm/ rather than asm-arm/hvm/ as the IOREQ is now meant to be agnostic?

Quoted 5 lines
Quoted 3 lines

Good question... The _common_ IOREQ code is indeed arch-agnostic. But, can the _arch_ IOREQ code be treated as really subarch-agnostic? I think, on Arm it can and it is most likely ok to keep it in "asm-arm/", but how it would be correlated with x86's IOREQ code which is HVM specific and located in "hvm" subdir?

Sorry, I don't understand your answer/questions. So let me ask the question differently, is asm-arm/hvm/ioreq.h going to be included from common code?

Quoted 8 lines

Sorry if I was unclear.

Quoted 3 lines

If the answer is no, then I see no reason to follow the x86 here.
If the answer is yes, then I am quite confused why half of the series tried to remove "hvm" from the function name but we still include "asm/hvm/ioreq.h".

Answer is yes. Even if we could to avoid including that header from the common code somehow, we would still have #include <public/hvm/*>, is_hvm_domain().

I saw Jan answered about this one. Let me know if you need more input.

Cheers,

Signature · 1 line
Julien Grall
#93 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

Quoted 1 line · Julien Grall

Hi Oleksandr,

Hi Julien

Quoted 19 lines · Oleksandr
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 11 lines

xen/include/asm-arm/domain.h line 13

Quoted 9 lines

  diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index 6819a3b..c235e5b 100644

xen/include/asm-arm/domain.h +1 -0
@@ -10,6 +10,7 @@
   #include <asm/gic.h>
   #include <asm/vgic.h>
   #include <asm/vpl011.h>
+#include <public/hvm/dm_op.h>

May I ask, why do you need to include dm_op.h here?

I needed to include that header to make some bits visible (XEN_DMOP_IO_RANGE_PCI, struct xen_dm_op_buf, etc). Why here - is a really good question. I don't remember exactly, probably I followed x86's domain.h which also included it.
So, trying to remove the inclusion here, I get several build failures on Arm which could be fixed if I include that header from dm.h and ioreq.h:

Shall I do this way?

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

If the failure are indeded because ioreq.h and dm.h use definition from public/hvm/dm_op.h, then yes. Can you post the errors?

Please see attached, although I built for Arm32 (and the whole series), I think errors are valid for Arm64 also.

Thanks!

Quoted 1 line

error1.txt - when remove #include <public/hvm/dm_op.h> from asm-arm/domain.h

For this one, I agree that including <public/hvm/dm_op.h> in xen.h looks the best solution.

Yes, I assume you meant in "ioreq.h"

Quoted 5 lines
Quoted 3 lines

error2.txt - when add #include <public/hvm/dm_op.h> to xen/ioreq.h

It looks like the error is happening in dm.c rather than xen/dm.h. Any reason to not include <public/hvm/dm_op.h> in dm.c directly?

Including it directly doesn't solve build issue.
If I am not mistaken in order to follow requirements how to include headers (alphabetic order, public* should be included after xen* and asm* ones, etc) the dm.h gets included the first in dm.c, and dm_op.h gets included the last. We can avoid build issue if we change inclusion order a bit, what I mean is to include dm.h after hypercall.h at least (because hypercall.h already includes dm_op.h). But this breaks the requirements and is not way to go. Now I am in doubt how to overcome this.

Quoted 6 lines
Quoted 4 lines

error3.txt - when add #include <public/hvm/dm_op.h> to xen/dm.h

I am a bit confused with this one. Isn't it the same as error1.txt?

The same, please ignore them, sorry for the confusion.

Quoted 34 lines
Quoted 34 lines
Quoted 24 lines

[...]

Quoted 16 lines
Quoted 16 lines

xen/include/asm-arm/hvm/ioreq.h

Quoted 14 lines

  #include <public/hvm/params.h>
    struct hvm_domain

xen/include/asm-arm/domain.h +1 -0
@@ -262,6 +263,8 @@ static inline void arch_vcpu_block(struct 
 vcpu *v) {}
     #define arch_vm_assist_valid_mask(d) (1UL << VMASST_TYPE_runstate_update_flag)
   +#define has_vpci(d)    ({ (void)(d); false; })
+
   #endif /* __ASM_DOMAIN_H__ */
     /*
xen/include/asm-arm/hvm/ioreq.h new file +0 -0
new file mode 100644
index 0000000..19e1247

Shouldn't this directly be under asm-arm/ rather than asm-arm/hvm/ as the IOREQ is now meant to be agnostic?

Quoted 5 lines
Quoted 3 lines

Good question... The _common_ IOREQ code is indeed arch-agnostic. But, can the _arch_ IOREQ code be treated as really subarch-agnostic? I think, on Arm it can and it is most likely ok to keep it in "asm-arm/", but how it would be correlated with x86's IOREQ code which is HVM specific and located in "hvm" subdir?

Sorry, I don't understand your answer/questions. So let me ask the question differently, is asm-arm/hvm/ioreq.h going to be included from common code?

Sorry if I was unclear.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

If the answer is no, then I see no reason to follow the x86 here.
If the answer is yes, then I am quite confused why half of the series tried to remove "hvm" from the function name but we still include "asm/hvm/ioreq.h".

Answer is yes. Even if we could to avoid including that header from the common code somehow, we would still have #include <public/hvm/*>, is_hvm_domain().

I saw Jan answered about this one. Let me know if you need more input.

Thank you, I think, no. Everything is clear at the moment.

Quoted 3 lines

Cheers,

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
#94 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

Quoted 6 lines · Oleksandr
Quoted 5 lines · Julien Grall
Quoted 1 line · Oleksandr

error2.txt - when add #include <public/hvm/dm_op.h> to xen/ioreq.h

It looks like the error is happening in dm.c rather than xen/dm.h. Any reason to not include <public/hvm/dm_op.h> in dm.c directly?

Quoted 10 lines

Including it directly doesn't solve build issue.
If I am not mistaken in order to follow requirements how to include headers (alphabetic order, public* should be included after xen* and asm* ones, etc)
the dm.h gets included the first in dm.c, and dm_op.h gets included the last. We can avoid build issue if we change inclusion order a bit, what I mean is to include dm.h after hypercall.h at least (because hypercall.h already includes dm_op.h). But this breaks the requirements and is not way to go.
Now I am in doubt how to overcome this.

First, violating the alphabetic ordering rule is perhaps less of a problem than putting seemingly stray #include-s anywhere. However, as soon as ordering starts mattering, this is indicative of problems with the headers: Either the (seemingly) too early included one lacks some #include-s, or you've run into a circular dependency. In the former case the needed #include-s should be added, and all ought to be fine. In the latter case, however, disentangling may be a significant effort, and hence it may be sensible and acceptable to instead use unusual ordering of #include-s in the one place where it matters (suitably justified in the description). Ideally such would come with a promise to try to sort this later on, when time is less constrained.

Jan

#95 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

On 27.01.21 12:24, Jan Beulich wrote:

Hi Jan

Quoted 16 lines · Oleksandr
Quoted 5 lines · Julien Grall
Quoted 4 lines · Oleksandr
Quoted 1 line

error2.txt - when add #include <public/hvm/dm_op.h> to xen/ioreq.h

It looks like the error is happening in dm.c rather than xen/dm.h. Any reason to not include <public/hvm/dm_op.h> in dm.c directly?

Quoted 10 lines

Including it directly doesn't solve build issue.
If I am not mistaken in order to follow requirements how to include headers (alphabetic order, public* should be included after xen* and asm* ones, etc)
the dm.h gets included the first in dm.c, and dm_op.h gets included the last. We can avoid build issue if we change inclusion order a bit, what I mean is to include dm.h after hypercall.h at least (because hypercall.h already includes dm_op.h). But this breaks the requirements and is not way to go.
Now I am in doubt how to overcome this.

Quoted 13 lines

First, violating the alphabetic ordering rule is perhaps less of a problem than putting seemingly stray #include-s anywhere. However, as soon as ordering starts mattering, this is indicative of problems with the headers: Either the (seemingly) too early included one lacks some #include-s, or you've run into a circular dependency. In the former case the needed #include-s should be added, and all ought to be fine. In the latter case, however, disentangling may be a significant effort, and hence it may be sensible and acceptable to instead use unusual ordering of #include-s in the one place where it matters (suitably justified in the description). Ideally such would come with a promise to try to sort this later on, when time is less constrained.

Thank you for the explanation. I think, I am facing the former case (too early included one lacks some #include-s), actually both common/dm.c and arch/arm/dm.c suffer from that.
It works for me if I add the following to both files (violating the alphabetic ordering rule):

+#include <xen/types.h>
+#include <public/hvm/dm_op.h>
+
 #include <xen/dm.h>

So, if I got your point correctly, we could include these both headers by dm.h) Would it be appropriate (with suitable justification of course)? I think, we could avoid including xen/sched.h by dm.h (need to recheck), just these two headers above.

Quoted 2 lines

Jan

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
#96 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

Quoted 42 lines · Oleksandr
Quoted 16 lines · Jan Beulich
Quoted 5 lines · Oleksandr
Quoted 4 lines · Julien Grall
Quoted 1 line · Oleksandr

error2.txt - when add #include <public/hvm/dm_op.h> to xen/ioreq.h

It looks like the error is happening in dm.c rather than xen/dm.h. Any reason to not include <public/hvm/dm_op.h> in dm.c directly?

Quoted 10 lines

Including it directly doesn't solve build issue.
If I am not mistaken in order to follow requirements how to include headers (alphabetic order, public* should be included after xen* and asm* ones, etc)
the dm.h gets included the first in dm.c, and dm_op.h gets included the last. We can avoid build issue if we change inclusion order a bit, what I mean is to include dm.h after hypercall.h at least (because hypercall.h already includes dm_op.h). But this breaks the requirements and is not way to go.
Now I am in doubt how to overcome this.

Quoted 13 lines

First, violating the alphabetic ordering rule is perhaps less of a problem than putting seemingly stray #include-s anywhere. However, as soon as ordering starts mattering, this is indicative of problems with the headers: Either the (seemingly) too early included one lacks some #include-s, or you've run into a circular dependency. In the former case the needed #include-s should be added, and all ought to be fine. In the latter case, however, disentangling may be a significant effort, and hence it may be sensible and acceptable to instead use unusual ordering of #include-s in the one place where it matters (suitably justified in the description). Ideally such would come with a promise to try to sort this later on, when time is less constrained.

Thank you for the explanation. I think, I am facing the former case (too early included one lacks some #include-s),
actually both common/dm.c and arch/arm/dm.c suffer from that. It works for me if I add the following to both files (violating the alphabetic ordering rule):

(quoted diff) +3 -0
+#include <xen/types.h>
+#include <public/hvm/dm_op.h>
+
  #include <xen/dm.h>
Quoted 2 lines

So, if I got your point correctly, we could include these both headers by dm.h) Would it be appropriate (with suitable justification of course)?

Perhaps - this is a header you introduce aiui, so it's up to you to arrange for it to include all further headers it depends upon. In such a case (new header) you don't need to explicitly justify what you include, but of course you don't want to include excessive ones, or you risk getting back "Why?" from reviewers.

Jan

#97 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

In reply to Oleksandr
Quoted 18 lines · Oleksandr
Quoted 17 lines · Julien Grall
Quoted 10 lines · Oleksandr Tyshchenko
xen/arch/arm/io.c +0 -0
@@ -16,6 +16,7 @@
    * GNU General Public License for more details.
    */

  +#include <xen/ioreq.h>
  #include <xen/lib.h>
  #include <xen/spinlock.h>
  #include <xen/sched.h>

xen/arch/arm/io.c line 27

Quoted 4 lines
xen/arch/arm/io.c +1 -0
@@ -23,6 +24,7 @@
   #include <asm/cpuerrata.h>
   #include <asm/current.h>
   #include <asm/mmio.h>
+#include <asm/hvm/ioreq.h>

Shouldn't this have been included by "xen/ioreq.h"?

Quoted 5 lines

Well, for V1 asm/hvm/ioreq.h was included by xen/ioreq.h. But, it turned out that there was nothing inside common header required arch one to be included and
I was asked to include arch header where it was indeed needed (several *.c files).

I guess the general usage model of the two headers needs to be established first: If the per-arch header declares only stuff needed by the soon common/ioreq.c, then indeed it should be only that file and the producer(s) of the arch_*() functions which include that header; it should then in particular not be included by xen/ioreq.h.

However, with the change request on patch 1 I think that usage model goes away at least for now, at which point the question is what exactly the per-arch header still declares, and based on that it would need to be decided whether xen/ioreq.h should include it.

Quoted 17 lines
Quoted 9 lines

xen/include/asm-arm/domain.h line 13

Quoted 7 lines
xen/include/asm-arm/domain.h +1 -0
@@ -10,6 +10,7 @@
   #include <asm/gic.h>
   #include <asm/vgic.h>
   #include <asm/vpl011.h>
+#include <public/hvm/dm_op.h>

May I ask, why do you need to include dm_op.h here?

I needed to include that header to make some bits visible (XEN_DMOP_IO_RANGE_PCI, struct xen_dm_op_buf, etc). Why here - is a really good question.
I don't remember exactly, probably I followed x86's domain.h which also included it.
So, trying to remove the inclusion here, I get several build failures on Arm which could be fixed if I include that header from dm.h and ioreq.h:

Quoted 1 line

Shall I do this way?

The general rule ought to be that header include what they need, but not more. Header dependencies are quite problematic already, so every dependency we can avoid (or eliminate) will help. This goes as far as only forward declaring structure where possible.

Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
xen/include/asm-arm/domain.h +1 -0
@@ -262,6 +263,8 @@ static inline void arch_vcpu_block(struct vcpu 
 *v) {}
     #define arch_vm_assist_valid_mask(d) (1UL << 
 VMASST_TYPE_runstate_update_flag)
   +#define has_vpci(d)    ({ (void)(d); false; })
+
   #endif /* __ASM_DOMAIN_H__ */
     /*
(quoted diff) +0 -0
Quoted 8 lines

xen/include/asm-arm/hvm/ioreq.h

Quoted 5 lines

b/xen/include/asm-arm/hvm/ioreq.h
new file mode 100644
index 0000000..19e1247

xen/include/asm-arm/hvm/ioreq.h new file +0 -0

Shouldn't this directly be under asm-arm/ rather than asm-arm/hvm/ as the IOREQ is now meant to be agnostic?

Quoted 6 lines

Good question... The _common_ IOREQ code is indeed arch-agnostic. But, can the _arch_ IOREQ code be treated as really subarch-agnostic? I think, on Arm it can and it is most likely ok to keep it in "asm-arm/", but how it would be correlated with x86's IOREQ code which is HVM specific and located
in "hvm" subdir?

I think for Arm's sake this should be used as asm/ioreq.h, where x86 would gain a new header consisting of just

#include <asm/hvm/ioreq.h>

as there the functionality is needed for HVM only.

Jan

#98 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

On 18.01.21 12:44, Jan Beulich wrote:

Hi Jan

Quoted 17 lines · Oleksandr
Quoted 16 lines · Julien Grall
Quoted 7 lines · Oleksandr Tyshchenko
Quoted 6 lines
xen/arch/arm/io.c +0 -0
@@ -16,6 +16,7 @@
    * GNU General Public License for more details.
    */
   +#include <xen/ioreq.h>
Quoted 8 lines

xen/arch/arm/io.c line 27

Quoted 8 lines
xen/arch/arm/io.c +1 -0
   #include <xen/lib.h>
   #include <xen/spinlock.h>
   #include <xen/sched.h>
@@ -23,6 +24,7 @@
   #include <asm/cpuerrata.h>
   #include <asm/current.h>
   #include <asm/mmio.h>
+#include <asm/hvm/ioreq.h>

Note to self:

Remove obsolete bool ioreq_complete_mmio(void) from asm-arm/hvm/ioreq.h

Quoted 13 lines
Quoted 6 lines
Quoted 1 line

Shouldn't this have been included by "xen/ioreq.h"?

Well, for V1 asm/hvm/ioreq.h was included by xen/ioreq.h. But, it turned out that there was nothing inside common header required arch one to be included and
I was asked to include arch header where it was indeed needed (several *.c files).

I guess the general usage model of the two headers needs to be established first: If the per-arch header declares only stuff needed by the soon common/ioreq.c, then indeed it should be only that file and the producer(s) of the arch_*() functions which include that header; it should then in particular not be included by xen/ioreq.h.

Quoted 5 lines

However, with the change request on patch 1 I think that usage model goes away at least for now, at which point the question is what exactly the per-arch header still declares, and based on that it would need to be decided whether xen/ioreq.h should include it.

ok, well.

x86's arch header now contains few IOREQ_STATUS_* #define-s, but Arm's contains more stuff besides that:
- stuff which is needed by common/ioreq.c, mostly stubs which are not implemented yet (handle_pio, etc)
- stuff which is not needed by common/ioreq.c, internal Arm bits (handle_ioserv, try_fwd_ioserv)

Could we please decide based on the information above?

Quoted 17 lines
Quoted 17 lines
Quoted 9 lines

xen/include/asm-arm/domain.h line 13

Quoted 8 lines
xen/include/asm-arm/domain.h +1 -0
@@ -10,6 +10,7 @@
   #include <asm/gic.h>
   #include <asm/vgic.h>
   #include <asm/vpl011.h>
+#include <public/hvm/dm_op.h>

May I ask, why do you need to include dm_op.h here?

I needed to include that header to make some bits visible (XEN_DMOP_IO_RANGE_PCI, struct xen_dm_op_buf, etc). Why here - is a really good question.
I don't remember exactly, probably I followed x86's domain.h which also included it.
So, trying to remove the inclusion here, I get several build failures on Arm which could be fixed if I include that header from dm.h and ioreq.h:

Quoted 5 lines
Quoted 1 line

Shall I do this way?

The general rule ought to be that header include what they need, but not more. Header dependencies are quite problematic already, so every dependency we can avoid (or eliminate) will help. This goes as far as only forward declaring structure where possible.

I got it.

Quoted 23 lines
Quoted 17 lines
Quoted 17 lines

xen/include/asm-arm/hvm/ioreq.h

Quoted 15 lines
xen/include/asm-arm/domain.h +1 -0
@@ -262,6 +263,8 @@ static inline void arch_vcpu_block(struct vcpu
 *v) {}
     #define arch_vm_assist_valid_mask(d) (1UL <<
 VMASST_TYPE_runstate_update_flag)
   +#define has_vpci(d)    ({ (void)(d); false; })
+
   #endif /* __ASM_DOMAIN_H__ */
     /*
xen/include/asm-arm/hvm/ioreq.h new file +0 -0
new file mode 100644
index 0000000..19e1247

Shouldn't this directly be under asm-arm/ rather than asm-arm/hvm/ as the IOREQ is now meant to be agnostic?

Quoted 6 lines

Good question... The _common_ IOREQ code is indeed arch-agnostic. But, can the _arch_ IOREQ code be treated as really subarch-agnostic? I think, on Arm it can and it is most likely ok to keep it in "asm-arm/", but how it would be correlated with x86's IOREQ code which is HVM specific and located
in "hvm" subdir?

Quoted 6 lines

I think for Arm's sake this should be used as asm/ioreq.h, where x86 would gain a new header consisting of just

#include <asm/hvm/ioreq.h>

as there the functionality is needed for HVM only.

For me this sounds perfectly fine. I think, this would also address Julien's question. May I introduce that new header together with moving IOREQ to the common code (patch #4)?

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
#99 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

Quoted 55 lines · Oleksandr
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Oleksandr
Quoted 15 lines · Julien Grall
Quoted 10 lines · Oleksandr Tyshchenko
xen/arch/arm/io.c +0 -0
@@ -16,6 +16,7 @@
    * GNU General Public License for more details.
    */
   +#include <xen/ioreq.h>
   #include <xen/lib.h>
   #include <xen/spinlock.h>
   #include <xen/sched.h>

xen/arch/arm/io.c line 27

Quoted 4 lines
xen/arch/arm/io.c +1 -0
@@ -23,6 +24,7 @@
   #include <asm/cpuerrata.h>
   #include <asm/current.h>
   #include <asm/mmio.h>
+#include <asm/hvm/ioreq.h>

Note to self:

Remove obsolete bool ioreq_complete_mmio(void) from asm-arm/hvm/ioreq.h

Quoted 13 lines
Quoted 6 lines
Quoted 1 line

Shouldn't this have been included by "xen/ioreq.h"?

Well, for V1 asm/hvm/ioreq.h was included by xen/ioreq.h. But, it turned out that there was nothing inside common header required arch one to be included and
I was asked to include arch header where it was indeed needed (several *.c files).

I guess the general usage model of the two headers needs to be established first: If the per-arch header declares only stuff needed by the soon common/ioreq.c, then indeed it should be only that file and the producer(s) of the arch_*() functions which include that header; it should then in particular not be included by xen/ioreq.h.

Quoted 5 lines

However, with the change request on patch 1 I think that usage model goes away at least for now, at which point the question is what exactly the per-arch header still declares, and based on that it would need to be decided whether xen/ioreq.h should include it.

ok, well.

x86's arch header now contains few IOREQ_STATUS_* #define-s, but Arm's contains more stuff
besides that:
- stuff which is needed by common/ioreq.c, mostly stubs which are not implemented yet (handle_pio, etc)
- stuff which is not needed by common/ioreq.c, internal Arm bits (handle_ioserv, try_fwd_ioserv)

Quoted 1 line

Could we please decide based on the information above?

You're in the best position to tell. The IOREQ_STATUS_* you mention may require including from xen/ioreq.h, but as said,
...

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 8 lines

xen/include/asm-arm/domain.h line 13

Quoted 7 lines
xen/include/asm-arm/domain.h +1 -0
@@ -10,6 +10,7 @@
   #include <asm/gic.h>
   #include <asm/vgic.h>
   #include <asm/vpl011.h>
+#include <public/hvm/dm_op.h>

May I ask, why do you need to include dm_op.h here?

I needed to include that header to make some bits visible (XEN_DMOP_IO_RANGE_PCI, struct xen_dm_op_buf, etc). Why here - is a really good question.
I don't remember exactly, probably I followed x86's domain.h which also included it.
So, trying to remove the inclusion here, I get several build failures on Arm which could be fixed if I include that header from dm.h and ioreq.h:

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Shall I do this way?

The general rule ought to be that header include what they need, but not more. Header dependencies are quite problematic already, so every dependency we can avoid (or eliminate) will help. This goes as far as only forward declaring structure where possible.

I got it.

... it depends. If xen/ioreq.h needs nothing from asm/ioreq.h, the I wouldn't see why it should include it.

Quoted 25 lines
Quoted 25 lines
Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
xen/include/asm-arm/domain.h +1 -0
@@ -262,6 +263,8 @@ static inline void arch_vcpu_block(struct vcpu
 *v) {}
     #define arch_vm_assist_valid_mask(d) (1UL <<
 VMASST_TYPE_runstate_update_flag)
   +#define has_vpci(d)    ({ (void)(d); false; })
+
   #endif /* __ASM_DOMAIN_H__ */
     /*
Quoted 8 lines

xen/include/asm-arm/hvm/ioreq.h

Quoted 6 lines
xen/include/asm-arm/hvm/ioreq.h new file +0 -0
new file mode 100644
index 0000000..19e1247

Shouldn't this directly be under asm-arm/ rather than asm-arm/hvm/ as the IOREQ is now meant to be agnostic?

Quoted 6 lines

Good question... The _common_ IOREQ code is indeed arch-agnostic. But, can the _arch_ IOREQ code be treated as really subarch-agnostic? I think, on Arm it can and it is most likely ok to keep it in "asm-arm/", but how it would be correlated with x86's IOREQ code which is HVM specific and located
in "hvm" subdir?

I think for Arm's sake this should be used as asm/ioreq.h, where x86 would gain a new header consisting of just

Quoted 7 lines
Quoted 3 lines

#include <asm/hvm/ioreq.h>

as there the functionality is needed for HVM only.

For me this sounds perfectly fine. I think, this would also address Julien's question.
May I introduce that new header together with moving IOREQ to the common code (patch #4)?

As with about everything, introduce new things the first time you need them, unless this results in overly big patches (in which case suitably splitting up is desirable, but of course no always possible). IOW if you introduce xen/ioreq.h and it needs to include asm/ioreq.h, then of course at this point you also need to introduce the asm-x86/ioreq.h wrapper.

Jan

#100 lore raw

Re: [PATCH V4 14/24] arm/ioreq: Introduce arch specific bits for IOREQ/DM features

On 18.01.21 18:00, Jan Beulich wrote:

Hi Jan

Quoted 116 lines · Oleksandr
Quoted 53 lines · Jan Beulich
Quoted 17 lines · Oleksandr
Quoted 16 lines · Julien Grall
Quoted 7 lines · Oleksandr Tyshchenko
Quoted 6 lines
xen/arch/arm/io.c +0 -0
@@ -16,6 +16,7 @@
     * GNU General Public License for more details.
     */
    +#include <xen/ioreq.h>
Quoted 8 lines

xen/arch/arm/io.c line 27

Quoted 8 lines
xen/arch/arm/io.c +1 -0
    #include <xen/lib.h>
    #include <xen/spinlock.h>
    #include <xen/sched.h>
@@ -23,6 +24,7 @@
    #include <asm/cpuerrata.h>
    #include <asm/current.h>
    #include <asm/mmio.h>
+#include <asm/hvm/ioreq.h>

Note to self:

Remove obsolete bool ioreq_complete_mmio(void) from asm-arm/hvm/ioreq.h

Quoted 13 lines
Quoted 6 lines
Quoted 1 line

Shouldn't this have been included by "xen/ioreq.h"?

Well, for V1 asm/hvm/ioreq.h was included by xen/ioreq.h. But, it turned out that there was nothing inside common header required arch one to be included and
I was asked to include arch header where it was indeed needed (several *.c files).

I guess the general usage model of the two headers needs to be established first: If the per-arch header declares only stuff needed by the soon common/ioreq.c, then indeed it should be only that file and the producer(s) of the arch_*() functions which include that header; it should then in particular not be included by xen/ioreq.h.

Quoted 5 lines

However, with the change request on patch 1 I think that usage model goes away at least for now, at which point the question is what exactly the per-arch header still declares, and based on that it would need to be decided whether xen/ioreq.h should include it.

ok, well.

x86's arch header now contains few IOREQ_STATUS_* #define-s, but Arm's contains more stuff
besides that:
- stuff which is needed by common/ioreq.c, mostly stubs which are not implemented yet (handle_pio, etc)
- stuff which is not needed by common/ioreq.c, internal Arm bits (handle_ioserv, try_fwd_ioserv)

Quoted 1 line

Could we please decide based on the information above?

You're in the best position to tell. The IOREQ_STATUS_* you mention may require including from xen/ioreq.h, but as said,
...

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 8 lines

xen/include/asm-arm/domain.h line 13

Quoted 7 lines
xen/include/asm-arm/domain.h +1 -0
@@ -10,6 +10,7 @@
    #include <asm/gic.h>
    #include <asm/vgic.h>
    #include <asm/vpl011.h>
+#include <public/hvm/dm_op.h>

May I ask, why do you need to include dm_op.h here?

I needed to include that header to make some bits visible (XEN_DMOP_IO_RANGE_PCI, struct xen_dm_op_buf, etc). Why here - is a really good question.
I don't remember exactly, probably I followed x86's domain.h which also included it.
So, trying to remove the inclusion here, I get several build failures on Arm which could be fixed if I include that header from dm.h and ioreq.h:

Quoted 6 lines
Quoted 5 lines
Quoted 1 line

Shall I do this way?

The general rule ought to be that header include what they need, but not more. Header dependencies are quite problematic already, so every dependency we can avoid (or eliminate) will help. This goes as far as only forward declaring structure where possible.

I got it.

... it depends. If xen/ioreq.h needs nothing from asm/ioreq.h, the I wouldn't see why it should include it.

Quoted 25 lines
Quoted 25 lines
Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
xen/include/asm-arm/domain.h +1 -0
@@ -262,6 +263,8 @@ static inline void arch_vcpu_block(struct vcpu
 *v) {}
      #define arch_vm_assist_valid_mask(d) (1UL <<
 VMASST_TYPE_runstate_update_flag)
    +#define has_vpci(d)    ({ (void)(d); false; })
+
    #endif /* __ASM_DOMAIN_H__ */
      /*
Quoted 8 lines

xen/include/asm-arm/hvm/ioreq.h

Quoted 6 lines
xen/include/asm-arm/hvm/ioreq.h new file +0 -0
new file mode 100644
index 0000000..19e1247

Shouldn't this directly be under asm-arm/ rather than asm-arm/hvm/ as the IOREQ is now meant to be agnostic?

Quoted 6 lines

Good question... The _common_ IOREQ code is indeed arch-agnostic. But, can the _arch_ IOREQ code be treated as really subarch-agnostic? I think, on Arm it can and it is most likely ok to keep it in "asm-arm/", but how it would be correlated with x86's IOREQ code which is HVM specific and located
in "hvm" subdir?

I think for Arm's sake this should be used as asm/ioreq.h, where x86 would gain a new header consisting of just

Quoted 7 lines
Quoted 3 lines

#include <asm/hvm/ioreq.h>

as there the functionality is needed for HVM only.

For me this sounds perfectly fine. I think, this would also address Julien's question.
May I introduce that new header together with moving IOREQ to the common code (patch #4)?

Quoted 6 lines

As with about everything, introduce new things the first time you need them, unless this results in overly big patches (in which case suitably splitting up is desirable, but of course no always possible). IOW if you introduce xen/ioreq.h and it needs to include asm/ioreq.h, then of course at this point you also need to introduce the asm-x86/ioreq.h wrapper.

Thank you for the clarification.

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
#101 lore raw

PATCH v4 15/24 xen/arm: Stick around in leave_hypervisor_to_guest until I/O has completed

In reply to Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

This patch adds proper handling of return value of vcpu_ioreq_handle_completion() which involves using a loop in leave_hypervisor_to_guest().

The reason to use an unbounded loop here is the fact that vCPU shouldn't continue until the I/O has completed.

The IOREQ code is using wait_on_xen_event_channel(). Yet, this can still "exit" early if an event has been received. But this doesn't mean the I/O has completed (in can be just a spurious wake-up). So we need to check if the I/O has completed and wait again if it hasn't (we will block the vCPU again until an event is received). This loop makes sure that all the vCPU works are done before we return to the guest.

The call chain below:
check_for_vcpu_work -> vcpu_ioreq_handle_completion -> wait_for_io -> wait_on_xen_event_channel

The worse that can happen here if the vCPU will never run again (the I/O will never complete). But, in Xen case, if the I/O never completes then it most likely means that something went horribly wrong with the Device Emulator. And it is most likely not safe to continue. So letting the vCPU to spin forever if the I/O never completes is a safer action than letting it continue and leaving the guest in unclear state and is the best what we can do for now.

Please note, using this loop we will not spin forever on a pCPU, preventing any other vCPUs from being scheduled. At every loop we will call check_for_pcpu_work() that will process pending softirqs. In case of failure, the guest will crash and the vCPU will be unscheduled. In normal case, if the rescheduling is necessary (might be set by a timer or by a caller in check_for_vcpu_work(), where wait_for_io() is a preemption point) the vCPU will be rescheduled to give place to someone else.

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes V1 -> V2:
- new patch, changes were derived from (+ new explanation):
arm/ioreq: Introduce arch specific bits for IOREQ/DM features

Changes V2 -> V3:
- update patch description

Changes V3 -> V4:
- update patch description and comment in code

---
 xen/arch/arm/traps.c | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)
xen/arch/arm/traps.c +33 -5
index 036b13f..4a83e1e 100644
@@ -2257,18 +2257,23 @@ static void check_for_pcpu_work(void)
  * Process pending work for the vCPU. Any call should be fast or
  * implement preemption.
  */
-static void check_for_vcpu_work(void)
+static bool check_for_vcpu_work(void)
 {
     struct vcpu *v = current;
 
 #ifdef CONFIG_IOREQ_SERVER
+    bool handled;
+
     local_irq_enable();
-    vcpu_ioreq_handle_completion(v);
+    handled = vcpu_ioreq_handle_completion(v);
     local_irq_disable();
+
+    if ( !handled )
+        return true;
 #endif
 
     if ( likely(!v->arch.need_flush_to_ram) )
-        return;
+        return false;
 
     /*
      * Give a chance for the pCPU to process work before handling the vCPU
@@ -2279,6 +2284,8 @@ static void check_for_vcpu_work(void)
     local_irq_enable();
     p2m_flush_vm(v);
     local_irq_disable();
+
+    return false;
 }
 
 /*
@@ -2291,8 +2298,29 @@ void leave_hypervisor_to_guest(void)
 {
     local_irq_disable();
 
-    check_for_vcpu_work();
-    check_for_pcpu_work();
+    /*
+     * The reason to use an unbounded loop here is the fact that vCPU
+     * shouldn't continue until the I/O has completed.
+     *
+     * The worse that can happen here if the vCPU will never run again
+     * (the I/O will never complete). But, in Xen case, if the I/O never
+     * completes then it most likely means that something went horribly
+     * wrong with the Device Emulator. And it is most likely not safe
+     * to continue. So letting the vCPU to spin forever if the I/O never
+     * completes is a safer action than letting it continue and leaving
+     * the guest in unclear state and is the best what we can do for now.
+     *
+     * Please note, using this loop we will not spin forever on a pCPU,
+     * preventing any other vCPUs from being scheduled. At every loop
+     * we will call check_for_pcpu_work() that will process pending
+     * softirqs. In case of failure, the guest will crash and the vCPU
+     * will be unscheduled. In normal case, if the rescheduling is necessary
+     * (might be set by a timer or by a caller in check_for_vcpu_work(),
+     * the vCPU will be rescheduled to give place to someone else.
+     */
+    do {
+        check_for_pcpu_work();
+    } while ( check_for_vcpu_work() );
 
     vgic_sync_to_lrs();
 
Signature · 1 line
2.7.4
Reviewed-by on v4 15/24
#102 lore raw

Re: [PATCH V4 15/24] xen/arm: Stick around in leave_hypervisor_to_guest until I/O has completed

Quoted 37 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

This patch adds proper handling of return value of vcpu_ioreq_handle_completion() which involves using a loop in leave_hypervisor_to_guest().

The reason to use an unbounded loop here is the fact that vCPU shouldn't continue until the I/O has completed.

The IOREQ code is using wait_on_xen_event_channel(). Yet, this can still "exit" early if an event has been received. But this doesn't mean the I/O has completed (in can be just a spurious wake-up). So we need to check if the I/O has completed and wait again if it hasn't (we will block the vCPU again until an event is received). This loop makes sure that all the vCPU works are done before we return to the guest.

The call chain below:
check_for_vcpu_work -> vcpu_ioreq_handle_completion -> wait_for_io -> wait_on_xen_event_channel

The worse that can happen here if the vCPU will never run again (the I/O will never complete). But, in Xen case, if the I/O never completes then it most likely means that something went horribly wrong with the Device Emulator. And it is most likely not safe to continue. So letting the vCPU to spin forever if the I/O never completes is a safer action than letting it continue and leaving the guest in unclear state and is the best what we can do for now.

Please note, using this loop we will not spin forever on a pCPU, preventing any other vCPUs from being scheduled. At every loop we will call check_for_pcpu_work() that will process pending softirqs. In case of failure, the guest will crash and the vCPU will be unscheduled. In normal case, if the rescheduling is necessary (might be set by a timer or by a caller in check_for_vcpu_work(), where wait_for_io() is a preemption point) the vCPU will be rescheduled to give place to someone else.

Quoted 4 lines
Quoted 92 lines

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes V1 -> V2:
- new patch, changes were derived from (+ new explanation):
arm/ioreq: Introduce arch specific bits for IOREQ/DM features

Changes V2 -> V3:
- update patch description

Changes V3 -> V4:
- update patch description and comment in code

---
 xen/arch/arm/traps.c | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)
xen/arch/arm/traps.c +33 -5
index 036b13f..4a83e1e 100644
@@ -2257,18 +2257,23 @@ static void check_for_pcpu_work(void)
  * Process pending work for the vCPU. Any call should be fast or
  * implement preemption.
  */
-static void check_for_vcpu_work(void)
+static bool check_for_vcpu_work(void)
 {
     struct vcpu *v = current;
 
 #ifdef CONFIG_IOREQ_SERVER
+    bool handled;
+
     local_irq_enable();
-    vcpu_ioreq_handle_completion(v);
+    handled = vcpu_ioreq_handle_completion(v);
     local_irq_disable();
+
+    if ( !handled )
+        return true;
 #endif
 
     if ( likely(!v->arch.need_flush_to_ram) )
-        return;
+        return false;
 
     /*
      * Give a chance for the pCPU to process work before handling the vCPU
@@ -2279,6 +2284,8 @@ static void check_for_vcpu_work(void)
     local_irq_enable();
     p2m_flush_vm(v);
     local_irq_disable();
+
+    return false;
 }
 
 /*
@@ -2291,8 +2298,29 @@ void leave_hypervisor_to_guest(void)
 {
     local_irq_disable();
 
-    check_for_vcpu_work();
-    check_for_pcpu_work();
+    /*
+     * The reason to use an unbounded loop here is the fact that vCPU
+     * shouldn't continue until the I/O has completed.
+     *
+     * The worse that can happen here if the vCPU will never run again
+     * (the I/O will never complete). But, in Xen case, if the I/O never
+     * completes then it most likely means that something went horribly
+     * wrong with the Device Emulator. And it is most likely not safe
+     * to continue. So letting the vCPU to spin forever if the I/O never
+     * completes is a safer action than letting it continue and leaving
+     * the guest in unclear state and is the best what we can do for now.
+     *
+     * Please note, using this loop we will not spin forever on a pCPU,
+     * preventing any other vCPUs from being scheduled. At every loop
+     * we will call check_for_pcpu_work() that will process pending
+     * softirqs. In case of failure, the guest will crash and the vCPU
+     * will be unscheduled. In normal case, if the rescheduling is necessary
+     * (might be set by a timer or by a caller in check_for_vcpu_work(),
+     * the vCPU will be rescheduled to give place to someone else.
+     */
+    do {
+        check_for_pcpu_work();
+    } while ( check_for_vcpu_work() );
 
     vgic_sync_to_lrs();
 
Signature · 1 line
2.7.4