Page MenuHomeFreeBSD

Define and use standard functions for alignment checking
ClosedPublic

Authored by dougm on Dec 28 2021, 10:09 PM.
Tags
None
Referenced Files
F102346123: D33685.id100677.diff
Mon, Nov 11, 12:21 AM
Unknown Object (File)
Mon, Oct 21, 9:48 AM
Unknown Object (File)
Mon, Oct 21, 2:22 AM
Unknown Object (File)
Wed, Oct 16, 6:30 AM
Unknown Object (File)
Tue, Oct 15, 5:37 AM
Unknown Object (File)
Mon, Oct 14, 5:20 PM
Unknown Object (File)
Oct 12 2024, 6:20 PM
Unknown Object (File)
Oct 12 2024, 9:13 AM

Details

Summary

Define simple functions for alignment and boundary checks and use them everywhere instead of having slightly different implementations scattered about. Define them in vm_page.h and use them where possible where vm_page.h is included.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dougm created this revision.

You may also convert sys/dev/iommu/iommu.h iommu_test_boundary()

sys/vm/vm_phys.h
90 ↗(On Diff #100677)

We usually put a blank lines around functions definitions.

93 ↗(On Diff #100677)

Isn't this line missed ';' ?

In D33685#761212, @kib wrote:

You may also convert sys/dev/iommu/iommu.h iommu_test_boundary()

What header file would work for that?

sys/vm/vm_phys.h
93 ↗(On Diff #100677)

Yes.

dougm marked an inline comment as done.
In D33685#761212, @kib wrote:

You may also convert sys/dev/iommu/iommu.h iommu_test_boundary()

What header file would work for that?

I think that vm/vm_param.h would work for this, similarly how roundup() or powerof2() live in sys/param.h. Not sure about vm_phys_ prefix, might be vm_addr_ is a better choice, also from the functional PoV.

I suggest to commit vm_phys_set_pool() separately.

Drop set_pool. Move alignment checks to vm_page.h. Use them in sys/dev/iommu.

Find more places to use align_ok and bound_ok.

common.boundary -> boundary, on some architectures.

dougm retitled this revision from Cleanups to Define and use standard functions for alignment checking.Dec 29 2021, 6:51 AM
dougm edited the summary of this revision. (Show Details)

Drop a redundant zero-check.

FYI D33684

sys/vm/vm_page.h
1029 ↗(On Diff #100692)

I think some comment would be very useful there, at least about use of '-' instead of '~' (so that zero boundary is handled automatically, AFAIU).

This revision is now accepted and ready to land.Dec 29 2021, 12:09 PM

IMO vm_phys.h makes more sense than vm_page.h for these routines. The vm_page_ prefix is usually for functions that operate on a vm_page_t. Is there some reason these can't live in vm_param.h as kib suggested?

IMO vm_phys.h makes more sense than vm_page.h for these routines. The vm_page_ prefix is usually for functions that operate on a vm_page_t. Is there some reason these can't live in vm_param.h as kib suggested?

Using vm_phys would require that I include vm_phys.h in more files. vm file already included everywhere are:
#include <vm/vm.h>
#include <vm/vm_extern.h>
#include <vm/vm_kern.h>
#include <vm/vm_page.h>
#include <vm/vm_map.h>

If vm_param.h is indirectly included everywhere, I can use that.

IMO vm_phys.h makes more sense than vm_page.h for these routines. The vm_page_ prefix is usually for functions that operate on a vm_page_t. Is there some reason these can't live in vm_param.h as kib suggested?

Using vm_phys would require that I include vm_phys.h in more files. vm file already included everywhere are:
#include <vm/vm.h>
#include <vm/vm_extern.h>
#include <vm/vm_kern.h>
#include <vm/vm_page.h>
#include <vm/vm_map.h>

If vm_param.h is indirectly included everywhere, I can use that.

It's only included directly. All of the C files in sys/vm already have it, and I think it wouldn't be to onerous to add includes elsewhere where needed.

That said, vm_extern.h makes even more sense since these routines are used outside of sys/vm, and vm_extern.h already assumes that vm_paddr_t is defined. So I would suggest trying to add these routines there.

Move the functions from vm_page.h to vm_extern.h. Rename them, and add a couple of comments.

This revision now requires review to proceed.Dec 29 2021, 6:16 PM
This revision is now accepted and ready to land.Dec 30 2021, 2:09 PM
kib added inline comments.
sys/vm/vm_extern.h
138

I would add asserts that power of two args are indeed power of two. This probably needs to come under #ifdef _KERNEL. You may do this as a follow-up.