* [PATCH v2 1/2] hv_balloon: Use kernel macros to simplify open coded sequences @ 2024-05-01 15:14 mhkelley58 2024-05-01 15:14 ` [PATCH v2 2/2] hv_balloon: Enable hot-add for memblock sizes > 128 MiB mhkelley58 2024-05-02 7:06 ` [PATCH v2 1/2] hv_balloon: Use kernel macros to simplify open coded sequences David Hildenbrand 0 siblings, 2 replies; 7+ messages in thread From: mhkelley58 @ 2024-05-01 15:14 UTC (permalink / raw) To: haiyangz, wei.liu, decui, linux-kernel, linux-hyperv; +Cc: david From: Michael Kelley <mhklinux@outlook.com> Code sequences equivalent to ALIGN(), ALIGN_DOWN(), and umin() are currently open coded. Change these to use the kernel macro to improve code clarity. ALIGN() and ALIGN_DOWN() require the alignment value to be a power of 2, which is the case here. Signed-off-by: Michael Kelley <mhklinux@outlook.com> --- Changes in v2: * No changes. This is a new patch that goes with v2 of patch 2 of this series. drivers/hv/hv_balloon.c | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index e000fa3b9f97..9f45b8a6762c 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -729,15 +729,8 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size, scoped_guard(spinlock_irqsave, &dm_device.ha_lock) { has->ha_end_pfn += HA_CHUNK; - - if (total_pfn > HA_CHUNK) { - processed_pfn = HA_CHUNK; - total_pfn -= HA_CHUNK; - } else { - processed_pfn = total_pfn; - total_pfn = 0; - } - + processed_pfn = umin(total_pfn, HA_CHUNK); + total_pfn -= processed_pfn; has->covered_end_pfn += processed_pfn; } @@ -800,7 +793,7 @@ static int pfn_covered(unsigned long start_pfn, unsigned long pfn_cnt) { struct hv_hotadd_state *has; struct hv_hotadd_gap *gap; - unsigned long residual, new_inc; + unsigned long residual; int ret = 0; guard(spinlock_irqsave)(&dm_device.ha_lock); @@ -836,15 +829,9 @@ static int pfn_covered(unsigned long start_pfn, unsigned long pfn_cnt) * our current limit; extend it. */ if ((start_pfn + pfn_cnt) > has->end_pfn) { + /* Extend the region by multiples of HA_CHUNK */ residual = (start_pfn + pfn_cnt - has->end_pfn); - /* - * Extend the region by multiples of HA_CHUNK. - */ - new_inc = (residual / HA_CHUNK) * HA_CHUNK; - if (residual % HA_CHUNK) - new_inc += HA_CHUNK; - - has->end_pfn += new_inc; + has->end_pfn += ALIGN(residual, HA_CHUNK); } ret = 1; @@ -915,9 +902,7 @@ static unsigned long handle_pg_range(unsigned long pg_start, */ size = (has->end_pfn - has->ha_end_pfn); if (pfn_cnt <= size) { - size = ((pfn_cnt / HA_CHUNK) * HA_CHUNK); - if (pfn_cnt % HA_CHUNK) - size += HA_CHUNK; + size = ALIGN(pfn_cnt, HA_CHUNK); } else { pfn_cnt = size; } @@ -1011,9 +996,6 @@ static void hot_add_req(struct work_struct *dummy) rg_sz = dm->ha_wrk.ha_region_range.finfo.page_cnt; if ((rg_start == 0) && (!dm->host_specified_ha_region)) { - unsigned long region_size; - unsigned long region_start; - /* * The host has not specified the hot-add region. * Based on the hot-add page range being specified, @@ -1021,14 +1003,8 @@ static void hot_add_req(struct work_struct *dummy) * that need to be hot-added while ensuring the alignment * and size requirements of Linux as it relates to hot-add. */ - region_size = (pfn_cnt / HA_CHUNK) * HA_CHUNK; - if (pfn_cnt % HA_CHUNK) - region_size += HA_CHUNK; - - region_start = (pg_start / HA_CHUNK) * HA_CHUNK; - - rg_start = region_start; - rg_sz = region_size; + rg_start = ALIGN_DOWN(pg_start, HA_CHUNK); + rg_sz = ALIGN(pfn_cnt, HA_CHUNK); } if (do_hot_add) -- 2.25.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/2] hv_balloon: Enable hot-add for memblock sizes > 128 MiB 2024-05-01 15:14 [PATCH v2 1/2] hv_balloon: Use kernel macros to simplify open coded sequences mhkelley58 @ 2024-05-01 15:14 ` mhkelley58 2024-05-02 7:17 ` David Hildenbrand ` (2 more replies) 2024-05-02 7:06 ` [PATCH v2 1/2] hv_balloon: Use kernel macros to simplify open coded sequences David Hildenbrand 1 sibling, 3 replies; 7+ messages in thread From: mhkelley58 @ 2024-05-01 15:14 UTC (permalink / raw) To: haiyangz, wei.liu, decui, linux-kernel, linux-hyperv; +Cc: david From: Michael Kelley <mhklinux@outlook.com> The Hyper-V balloon driver supports hot-add of memory in addition to ballooning. Current code hot-adds in fixed size chunks of 128 MiB (fixed constant HA_CHUNK in the code). While this works in Hyper-V VMs with 64 GiB or less or memory where the Linux memblock size is 128 MiB, the hot-add fails for larger memblock sizes because add_memory() expects memory to be added in chunks that match the memblock size. Messages like the following are reported when Linux has a 256 MiB memblock size: [ 312.668859] Block size [0x10000000] unaligned hotplug range: start 0x310000000, size 0x8000000 [ 312.668880] hv_balloon: hot_add memory failed error is -22 [ 312.668984] hv_balloon: Memory hot add failed Larger memblock sizes are usually used in VMs with more than 64 GiB of memory, depending on the alignment of the VM's physical address space. Fix this problem by having the Hyper-V balloon driver determine the Linux memblock size, and process hot-add requests in that chunk size instead of a fixed 128 MiB. Also update the hot-add alignment requested of the Hyper-V host to match the memblock size. The code changes look significant, but in fact are just a simple text substitution of a new global variable for the previous HA_CHUNK constant. No algorithms are changed except to initialize the new global variable and to calculate the alignment value to pass to Hyper-V. Testing with memblock sizes of 256 MiB and 2 GiB shows correct operation. Signed-off-by: Michael Kelley <mhklinux@outlook.com> --- Changes in v2: * Change new global variable name from ha_chunk_pgs to ha_pages_in_chunk [David Hildenbrand] * Use kernel macros ALIGN(), ALIGN_DOWN(), and umin() to simplify code and reduce references to HA_CHUNK. For ease of review, this is done in a new patch preceeding this one. [David Hildenbrand] drivers/hv/hv_balloon.c | 55 +++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index 9f45b8a6762c..e0a1a18041ca 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -425,11 +425,11 @@ struct dm_info_msg { * The range start_pfn : end_pfn specifies the range * that the host has asked us to hot add. The range * start_pfn : ha_end_pfn specifies the range that we have - * currently hot added. We hot add in multiples of 128M - * chunks; it is possible that we may not be able to bring - * online all the pages in the region. The range + * currently hot added. We hot add in chunks equal to the + * memory block size; it is possible that we may not be able + * to bring online all the pages in the region. The range * covered_start_pfn:covered_end_pfn defines the pages that can - * be brough online. + * be brought online. */ struct hv_hotadd_state { @@ -505,8 +505,9 @@ enum hv_dm_state { static __u8 recv_buffer[HV_HYP_PAGE_SIZE]; static __u8 balloon_up_send_buffer[HV_HYP_PAGE_SIZE]; +static unsigned long ha_pages_in_chunk; + #define PAGES_IN_2M (2 * 1024 * 1024 / PAGE_SIZE) -#define HA_CHUNK (128 * 1024 * 1024 / PAGE_SIZE) struct hv_dynmem_device { struct hv_device *dev; @@ -724,21 +725,21 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size, unsigned long processed_pfn; unsigned long total_pfn = pfn_count; - for (i = 0; i < (size/HA_CHUNK); i++) { - start_pfn = start + (i * HA_CHUNK); + for (i = 0; i < (size/ha_pages_in_chunk); i++) { + start_pfn = start + (i * ha_pages_in_chunk); scoped_guard(spinlock_irqsave, &dm_device.ha_lock) { - has->ha_end_pfn += HA_CHUNK; - processed_pfn = umin(total_pfn, HA_CHUNK); + has->ha_end_pfn += ha_pages_in_chunk; + processed_pfn = umin(total_pfn, ha_pages_in_chunk); total_pfn -= processed_pfn; - has->covered_end_pfn += processed_pfn; + has->covered_end_pfn += processed_pfn; } reinit_completion(&dm_device.ol_waitevent); nid = memory_add_physaddr_to_nid(PFN_PHYS(start_pfn)); ret = add_memory(nid, PFN_PHYS((start_pfn)), - (HA_CHUNK << PAGE_SHIFT), MHP_MERGE_RESOURCE); + (ha_pages_in_chunk << PAGE_SHIFT), MHP_MERGE_RESOURCE); if (ret) { pr_err("hot_add memory failed error is %d\n", ret); @@ -753,7 +754,7 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size, do_hot_add = false; } scoped_guard(spinlock_irqsave, &dm_device.ha_lock) { - has->ha_end_pfn -= HA_CHUNK; + has->ha_end_pfn -= ha_pages_in_chunk; has->covered_end_pfn -= processed_pfn; } break; @@ -829,9 +830,9 @@ static int pfn_covered(unsigned long start_pfn, unsigned long pfn_cnt) * our current limit; extend it. */ if ((start_pfn + pfn_cnt) > has->end_pfn) { - /* Extend the region by multiples of HA_CHUNK */ + /* Extend the region by multiples of ha_pages_in_chunk */ residual = (start_pfn + pfn_cnt - has->end_pfn); - has->end_pfn += ALIGN(residual, HA_CHUNK); + has->end_pfn += ALIGN(residual, ha_pages_in_chunk); } ret = 1; @@ -897,12 +898,12 @@ static unsigned long handle_pg_range(unsigned long pg_start, * We have some residual hot add range * that needs to be hot added; hot add * it now. Hot add a multiple of - * HA_CHUNK that fully covers the pages + * ha_pages_in_chunk that fully covers the pages * we have. */ size = (has->end_pfn - has->ha_end_pfn); if (pfn_cnt <= size) { - size = ALIGN(pfn_cnt, HA_CHUNK); + size = ALIGN(pfn_cnt, ha_pages_in_chunk); } else { pfn_cnt = size; } @@ -1003,8 +1004,8 @@ static void hot_add_req(struct work_struct *dummy) * that need to be hot-added while ensuring the alignment * and size requirements of Linux as it relates to hot-add. */ - rg_start = ALIGN_DOWN(pg_start, HA_CHUNK); - rg_sz = ALIGN(pfn_cnt, HA_CHUNK); + rg_start = ALIGN_DOWN(pg_start, ha_pages_in_chunk); + rg_sz = ALIGN(pfn_cnt, ha_pages_in_chunk); } if (do_hot_add) @@ -1807,10 +1808,13 @@ static int balloon_connect_vsp(struct hv_device *dev) cap_msg.caps.cap_bits.hot_add = hot_add_enabled(); /* - * Specify our alignment requirements as it relates - * memory hot-add. Specify 128MB alignment. + * Specify our alignment requirements for memory hot-add. The value is + * the log base 2 of the number of megabytes in a chunk. For example, + * with 256 MiB chunks, the value is 8. The number of MiB in a chunk + * must be a power of 2. */ - cap_msg.caps.cap_bits.hot_add_alignment = 7; + cap_msg.caps.cap_bits.hot_add_alignment = + ilog2(ha_pages_in_chunk >> (20 - PAGE_SHIFT)); /* * Currently the host does not use these @@ -2132,6 +2136,15 @@ static struct hv_driver balloon_drv = { static int __init init_balloon_drv(void) { + /* + * Hot-add must operate in chunks that are of size + * equal to the memory block size because that's + * what the core add_memory() interface requires. + * The Hyper-V interface requires that the memory block + * size be a power of 2, which is guaranteed by the + * check in memory_dev_init(). + */ + ha_pages_in_chunk = memory_block_size_bytes() / PAGE_SIZE; return vmbus_driver_register(&balloon_drv); } -- 2.25.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] hv_balloon: Enable hot-add for memblock sizes > 128 MiB 2024-05-01 15:14 ` [PATCH v2 2/2] hv_balloon: Enable hot-add for memblock sizes > 128 MiB mhkelley58 @ 2024-05-02 7:17 ` David Hildenbrand 2024-05-02 22:40 ` Michael Kelley 2024-05-02 17:29 ` kernel test robot 2024-05-02 20:49 ` kernel test robot 2 siblings, 1 reply; 7+ messages in thread From: David Hildenbrand @ 2024-05-02 7:17 UTC (permalink / raw) To: mhklinux, haiyangz, wei.liu, decui, linux-kernel, linux-hyperv On 01.05.24 17:14, mhkelley58@gmail.com wrote: > From: Michael Kelley <mhklinux@outlook.com> > > The Hyper-V balloon driver supports hot-add of memory in addition > to ballooning. Current code hot-adds in fixed size chunks of > 128 MiB (fixed constant HA_CHUNK in the code). While this works > in Hyper-V VMs with 64 GiB or less or memory where the Linux > memblock size is 128 MiB, the hot-add fails for larger memblock > sizes because add_memory() expects memory to be added in chunks > that match the memblock size. Messages like the following are > reported when Linux has a 256 MiB memblock size: > > [ 312.668859] Block size [0x10000000] unaligned hotplug range: > start 0x310000000, size 0x8000000 > [ 312.668880] hv_balloon: hot_add memory failed error is -22 > [ 312.668984] hv_balloon: Memory hot add failed > > Larger memblock sizes are usually used in VMs with more than > 64 GiB of memory, depending on the alignment of the VM's > physical address space. > > Fix this problem by having the Hyper-V balloon driver determine > the Linux memblock size, and process hot-add requests in that > chunk size instead of a fixed 128 MiB. Also update the hot-add > alignment requested of the Hyper-V host to match the memblock > size. > > The code changes look significant, but in fact are just a > simple text substitution of a new global variable for the > previous HA_CHUNK constant. No algorithms are changed except > to initialize the new global variable and to calculate the > alignment value to pass to Hyper-V. Testing with memblock > sizes of 256 MiB and 2 GiB shows correct operation. > > Signed-off-by: Michael Kelley <mhklinux@outlook.com> > --- > Changes in v2: > * Change new global variable name from ha_chunk_pgs to > ha_pages_in_chunk [David Hildenbrand] > * Use kernel macros ALIGN(), ALIGN_DOWN(), and umin() > to simplify code and reduce references to HA_CHUNK. For > ease of review, this is done in a new patch preceeding > this one. [David Hildenbrand] > > drivers/hv/hv_balloon.c | 55 +++++++++++++++++++++++++---------------- > 1 file changed, 34 insertions(+), 21 deletions(-) > > diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c > index 9f45b8a6762c..e0a1a18041ca 100644 > --- a/drivers/hv/hv_balloon.c > +++ b/drivers/hv/hv_balloon.c > @@ -425,11 +425,11 @@ struct dm_info_msg { > * The range start_pfn : end_pfn specifies the range > * that the host has asked us to hot add. The range > * start_pfn : ha_end_pfn specifies the range that we have > - * currently hot added. We hot add in multiples of 128M > - * chunks; it is possible that we may not be able to bring > - * online all the pages in the region. The range > + * currently hot added. We hot add in chunks equal to the > + * memory block size; it is possible that we may not be able > + * to bring online all the pages in the region. The range > * covered_start_pfn:covered_end_pfn defines the pages that can > - * be brough online. > + * be brought online. > */ > > struct hv_hotadd_state { > @@ -505,8 +505,9 @@ enum hv_dm_state { > > static __u8 recv_buffer[HV_HYP_PAGE_SIZE]; > static __u8 balloon_up_send_buffer[HV_HYP_PAGE_SIZE]; > +static unsigned long ha_pages_in_chunk; > + > #define PAGES_IN_2M (2 * 1024 * 1024 / PAGE_SIZE) > -#define HA_CHUNK (128 * 1024 * 1024 / PAGE_SIZE) > > struct hv_dynmem_device { > struct hv_device *dev; > @@ -724,21 +725,21 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size, > unsigned long processed_pfn; > unsigned long total_pfn = pfn_count; > > - for (i = 0; i < (size/HA_CHUNK); i++) { > - start_pfn = start + (i * HA_CHUNK); > + for (i = 0; i < (size/ha_pages_in_chunk); i++) { > + start_pfn = start + (i * ha_pages_in_chunk); > > scoped_guard(spinlock_irqsave, &dm_device.ha_lock) { > - has->ha_end_pfn += HA_CHUNK; > - processed_pfn = umin(total_pfn, HA_CHUNK); > + has->ha_end_pfn += ha_pages_in_chunk; > + processed_pfn = umin(total_pfn, ha_pages_in_chunk); > total_pfn -= processed_pfn; > - has->covered_end_pfn += processed_pfn; > + has->covered_end_pfn += processed_pfn; > } > > reinit_completion(&dm_device.ol_waitevent); > > nid = memory_add_physaddr_to_nid(PFN_PHYS(start_pfn)); > ret = add_memory(nid, PFN_PHYS((start_pfn)), > - (HA_CHUNK << PAGE_SHIFT), MHP_MERGE_RESOURCE); > + (ha_pages_in_chunk << PAGE_SHIFT), MHP_MERGE_RESOURCE); > HA_BYTES_IN_CHUNK might be reasonable to have (see below) > if (do_hot_add) > @@ -1807,10 +1808,13 @@ static int balloon_connect_vsp(struct hv_device *dev) > cap_msg.caps.cap_bits.hot_add = hot_add_enabled(); > > /* > - * Specify our alignment requirements as it relates > - * memory hot-add. Specify 128MB alignment. > + * Specify our alignment requirements for memory hot-add. The value is > + * the log base 2 of the number of megabytes in a chunk. For example, > + * with 256 MiB chunks, the value is 8. The number of MiB in a chunk > + * must be a power of 2. > */ > - cap_msg.caps.cap_bits.hot_add_alignment = 7; > + cap_msg.caps.cap_bits.hot_add_alignment = > + ilog2(ha_pages_in_chunk >> (20 - PAGE_SHIFT)); I was wondering if we can remove some of the magic here. Something along the lines of: ilog2(ha_pages_in_chunk / (SZ_1M >> PAGE_SHIFT)) or simply #define HA_BYTES_IN_CHUNK (ha_pages_in_chunk << PAGE_SHIFT) ilog2(HA_BYTES_IN_CHUNK / SZ_1M) Apart from that nothing jumped at me; looks much cleaner. Reviewed-by: David Hildenbrand <david@redhat.com> -- Cheers, David / dhildenb ^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH v2 2/2] hv_balloon: Enable hot-add for memblock sizes > 128 MiB 2024-05-02 7:17 ` David Hildenbrand @ 2024-05-02 22:40 ` Michael Kelley 0 siblings, 0 replies; 7+ messages in thread From: Michael Kelley @ 2024-05-02 22:40 UTC (permalink / raw) To: David Hildenbrand, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org From: David Hildenbrand <david@redhat.com> Sent: Thursday, May 2, 2024 12:17 AM > > On 01.05.24 17:14, mhkelley58@gmail.com wrote: > > From: Michael Kelley <mhklinux@outlook.com> > > > > The Hyper-V balloon driver supports hot-add of memory in addition > > to ballooning. Current code hot-adds in fixed size chunks of > > 128 MiB (fixed constant HA_CHUNK in the code). While this works > > in Hyper-V VMs with 64 GiB or less or memory where the Linux > > memblock size is 128 MiB, the hot-add fails for larger memblock > > sizes because add_memory() expects memory to be added in chunks > > that match the memblock size. Messages like the following are > > reported when Linux has a 256 MiB memblock size: > > > > [ 312.668859] Block size [0x10000000] unaligned hotplug range: > > start 0x310000000, size 0x8000000 > > [ 312.668880] hv_balloon: hot_add memory failed error is -22 > > [ 312.668984] hv_balloon: Memory hot add failed > > > > Larger memblock sizes are usually used in VMs with more than > > 64 GiB of memory, depending on the alignment of the VM's > > physical address space. > > > > Fix this problem by having the Hyper-V balloon driver determine > > the Linux memblock size, and process hot-add requests in that > > chunk size instead of a fixed 128 MiB. Also update the hot-add > > alignment requested of the Hyper-V host to match the memblock > > size. > > > > The code changes look significant, but in fact are just a > > simple text substitution of a new global variable for the > > previous HA_CHUNK constant. No algorithms are changed except > > to initialize the new global variable and to calculate the > > alignment value to pass to Hyper-V. Testing with memblock > > sizes of 256 MiB and 2 GiB shows correct operation. > > > > Signed-off-by: Michael Kelley <mhklinux@outlook.com> > > --- > > Changes in v2: > > * Change new global variable name from ha_chunk_pgs to > > ha_pages_in_chunk [David Hildenbrand] > > * Use kernel macros ALIGN(), ALIGN_DOWN(), and umin() > > to simplify code and reduce references to HA_CHUNK. For > > ease of review, this is done in a new patch preceeding > > this one. [David Hildenbrand] > > > > drivers/hv/hv_balloon.c | 55 +++++++++++++++++++++++++---------------- > > 1 file changed, 34 insertions(+), 21 deletions(-) > > > > diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c > > index 9f45b8a6762c..e0a1a18041ca 100644 > > --- a/drivers/hv/hv_balloon.c > > +++ b/drivers/hv/hv_balloon.c > > @@ -425,11 +425,11 @@ struct dm_info_msg { > > * The range start_pfn : end_pfn specifies the range > > * that the host has asked us to hot add. The range > > * start_pfn : ha_end_pfn specifies the range that we have > > - * currently hot added. We hot add in multiples of 128M > > - * chunks; it is possible that we may not be able to bring > > - * online all the pages in the region. The range > > + * currently hot added. We hot add in chunks equal to the > > + * memory block size; it is possible that we may not be able > > + * to bring online all the pages in the region. The range > > * covered_start_pfn:covered_end_pfn defines the pages that can > > - * be brough online. > > + * be brought online. > > */ > > > > struct hv_hotadd_state { > > @@ -505,8 +505,9 @@ enum hv_dm_state { > > > > static __u8 recv_buffer[HV_HYP_PAGE_SIZE]; > > static __u8 balloon_up_send_buffer[HV_HYP_PAGE_SIZE]; > > +static unsigned long ha_pages_in_chunk; > > + > > #define PAGES_IN_2M (2 * 1024 * 1024 / PAGE_SIZE) > > -#define HA_CHUNK (128 * 1024 * 1024 / PAGE_SIZE) > > > > struct hv_dynmem_device { > > struct hv_device *dev; > > @@ -724,21 +725,21 @@ static void hv_mem_hot_add(unsigned long start, > unsigned long size, > > unsigned long processed_pfn; > > unsigned long total_pfn = pfn_count; > > > > - for (i = 0; i < (size/HA_CHUNK); i++) { > > - start_pfn = start + (i * HA_CHUNK); > > + for (i = 0; i < (size/ha_pages_in_chunk); i++) { > > + start_pfn = start + (i * ha_pages_in_chunk); > > > > scoped_guard(spinlock_irqsave, &dm_device.ha_lock) { > > - has->ha_end_pfn += HA_CHUNK; > > - processed_pfn = umin(total_pfn, HA_CHUNK); > > + has->ha_end_pfn += ha_pages_in_chunk; > > + processed_pfn = umin(total_pfn, ha_pages_in_chunk); > > total_pfn -= processed_pfn; > > - has->covered_end_pfn += processed_pfn; > > + has->covered_end_pfn += processed_pfn; > > } > > > > reinit_completion(&dm_device.ol_waitevent); > > > > nid = memory_add_physaddr_to_nid(PFN_PHYS(start_pfn)); > > ret = add_memory(nid, PFN_PHYS((start_pfn)), > > - (HA_CHUNK << PAGE_SHIFT), MHP_MERGE_RESOURCE); > > + (ha_pages_in_chunk << PAGE_SHIFT), MHP_MERGE_RESOURCE); > > > > HA_BYTES_IN_CHUNK might be reasonable to have (see below) > > > if (do_hot_add) > > @@ -1807,10 +1808,13 @@ static int balloon_connect_vsp(struct hv_device *dev) > > cap_msg.caps.cap_bits.hot_add = hot_add_enabled(); > > > > /* > > - * Specify our alignment requirements as it relates > > - * memory hot-add. Specify 128MB alignment. > > + * Specify our alignment requirements for memory hot-add. The value is > > + * the log base 2 of the number of megabytes in a chunk. For example, > > + * with 256 MiB chunks, the value is 8. The number of MiB in a chunk > > + * must be a power of 2. > > */ > > - cap_msg.caps.cap_bits.hot_add_alignment = 7; > > + cap_msg.caps.cap_bits.hot_add_alignment = > > + ilog2(ha_pages_in_chunk >> (20 - PAGE_SHIFT)); > > I was wondering if we can remove some of the magic here. Something along > the lines of: > > ilog2(ha_pages_in_chunk / (SZ_1M >> PAGE_SHIFT)) > > or simply > > #define HA_BYTES_IN_CHUNK (ha_pages_in_chunk << PAGE_SHIFT) > > ilog2(HA_BYTES_IN_CHUNK / SZ_1M) > > > Apart from that nothing jumped at me; looks much cleaner. > > Reviewed-by: David Hildenbrand <david@redhat.com> > David -- I need to respin anyway because I missed a dependency on CONFIG_MEMORY_HOTPLUG as pointed out by the kernel test robot. I'll add your suggestion to that respin. Michael ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] hv_balloon: Enable hot-add for memblock sizes > 128 MiB 2024-05-01 15:14 ` [PATCH v2 2/2] hv_balloon: Enable hot-add for memblock sizes > 128 MiB mhkelley58 2024-05-02 7:17 ` David Hildenbrand @ 2024-05-02 17:29 ` kernel test robot 2024-05-02 20:49 ` kernel test robot 2 siblings, 0 replies; 7+ messages in thread From: kernel test robot @ 2024-05-02 17:29 UTC (permalink / raw) To: mhkelley58, haiyangz, wei.liu, decui, linux-kernel, linux-hyperv Cc: oe-kbuild-all, david Hi, kernel test robot noticed the following build errors: [auto build test ERROR on linus/master] [also build test ERROR on v6.9-rc6 next-20240502] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/mhkelley58-gmail-com/hv_balloon-Enable-hot-add-for-memblock-sizes-128-MiB/20240501-232643 base: linus/master patch link: https://lore.kernel.org/r/20240501151458.2807-2-mhklinux%40outlook.com patch subject: [PATCH v2 2/2] hv_balloon: Enable hot-add for memblock sizes > 128 MiB config: x86_64-buildonly-randconfig-001-20240502 (https://download.01.org/0day-ci/archive/20240503/202405030141.oWhfOhdl-lkp@intel.com/config) compiler: gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240503/202405030141.oWhfOhdl-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202405030141.oWhfOhdl-lkp@intel.com/ All errors (new ones prefixed by >>, old ones prefixed by <<): WARNING: modpost: missing MODULE_DESCRIPTION() in arch/x86/crypto/crc32-pclmul.o WARNING: modpost: missing MODULE_DESCRIPTION() in kernel/locking/test-ww_mutex.o WARNING: modpost: missing MODULE_DESCRIPTION() in kernel/time/time_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in kernel/scftorture.o WARNING: modpost: missing MODULE_DESCRIPTION() in mm/kasan/kasan_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/ext4/ext4-inode-test.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/fat/fat_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp855.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp857.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp862.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp865.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp866.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp1251.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_ascii.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_iso8859-5.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp1255.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_iso8859-14.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_iso8859-15.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_koi8-r.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_utf8.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/mac-centeuro.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/mac-gaelic.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/mac-greek.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_ucs2_utils.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/unicode/utf8data.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/unicode/utf8-selftest.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/bcachefs/mean_and_variance_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/minix/minix.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/ufs/ufs.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/efs/efs.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/adfs/adfs.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/pstore/pstore.o WARNING: modpost: missing MODULE_DESCRIPTION() in security/keys/trusted-keys/trusted.o WARNING: modpost: missing MODULE_DESCRIPTION() in block/t10-pi.o WARNING: modpost: missing MODULE_DESCRIPTION() in lib/kunit/kunit.o WARNING: modpost: missing MODULE_DESCRIPTION() in lib/kunit/kunit-test.o WARNING: modpost: missing MODULE_DESCRIPTION() in lib/kunit/kunit-example-test.o WARNING: modpost: missing MODULE_DESCRIPTION() in lib/math/prime_numbers.o WARNING: modpost: missing MODULE_DESCRIPTION() in lib/crypto/libdes.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/pinctrl/pinctrl-mcp23s08_i2c.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/pinctrl/pinctrl-mcp23s08_spi.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/pinctrl/pinctrl-mcp23s08.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/video/fbdev/goldfishfb.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/virtio/virtio_dma_buf.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_kunit_helpers.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_buddy_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_cmdline_parser_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_connector_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_damage_helper_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_dp_mst_helper_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_exec_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_format_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_framebuffer_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_gem_shmem_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_managed_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_mm_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_modes_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_plane_helper_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_probe_helper_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_rect_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/panel/panel-auo-a030jtn01.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/panel/panel-orisetech-ota5601a.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/drm_panel_orientation_quirks.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/drm_mipi_dbi.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/base/regmap/regmap-kunit.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/base/regmap/regmap-ram.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/base/regmap/regmap-raw-ram.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/base/regmap/regmap-w1.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/base/regmap/regmap-spi-avmm.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mfd/arizona.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/scsi/scsi_common.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/spi/spi-altera-core.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/input/touchscreen/cyttsp_i2c_common.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/input/vivaldi-fmap.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mmc/core/mmc_core.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/fbtft/fbtft.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-loopback.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-power-supply.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-raw.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-vibrator.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-gbphy.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-i2c.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-sdio.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-spi.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-spilib.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_simpleondemand.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_powersave.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/hwtracing/intel_th/intel_th_msu_sink.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/uio/uio.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/hwmon/mr75203.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/greybus/greybus.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/iio/buffer/kfifo_buf.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/siox/siox-bus-gpio.o WARNING: modpost: missing MODULE_DESCRIPTION() in sound/core/sound_kunit.o WARNING: modpost: missing MODULE_DESCRIPTION() in samples/vfio-mdev/mtty.o WARNING: modpost: missing MODULE_DESCRIPTION() in samples/vfio-mdev/mbochs.o WARNING: modpost: missing MODULE_DESCRIPTION() in samples/configfs/configfs_sample.o WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kobject/kobject-example.o WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kobject/kset-example.o WARNING: modpost: missing MODULE_DESCRIPTION() in arch/x86/video/fbdev.o >> ERROR: modpost: "memory_block_size_bytes" [drivers/hv/hv_balloon.ko] undefined! -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] hv_balloon: Enable hot-add for memblock sizes > 128 MiB 2024-05-01 15:14 ` [PATCH v2 2/2] hv_balloon: Enable hot-add for memblock sizes > 128 MiB mhkelley58 2024-05-02 7:17 ` David Hildenbrand 2024-05-02 17:29 ` kernel test robot @ 2024-05-02 20:49 ` kernel test robot 2 siblings, 0 replies; 7+ messages in thread From: kernel test robot @ 2024-05-02 20:49 UTC (permalink / raw) To: mhkelley58, haiyangz, wei.liu, decui, linux-kernel, linux-hyperv Cc: oe-kbuild-all, david Hi, kernel test robot noticed the following build errors: [auto build test ERROR on linus/master] [also build test ERROR on v6.9-rc6 next-20240502] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/mhkelley58-gmail-com/hv_balloon-Enable-hot-add-for-memblock-sizes-128-MiB/20240501-232643 base: linus/master patch link: https://lore.kernel.org/r/20240501151458.2807-2-mhklinux%40outlook.com patch subject: [PATCH v2 2/2] hv_balloon: Enable hot-add for memblock sizes > 128 MiB config: i386-randconfig-011-20240502 (https://download.01.org/0day-ci/archive/20240503/202405030421.x7E4hUI7-lkp@intel.com/config) compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240503/202405030421.x7E4hUI7-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202405030421.x7E4hUI7-lkp@intel.com/ All errors (new ones prefixed by >>): ld: drivers/hv/hv_balloon.o: in function `init_balloon_drv': >> drivers/hv/hv_balloon.c:2147:(.init.text+0x4): undefined reference to `memory_block_size_bytes' vim +2147 drivers/hv/hv_balloon.c 2136 2137 static int __init init_balloon_drv(void) 2138 { 2139 /* 2140 * Hot-add must operate in chunks that are of size 2141 * equal to the memory block size because that's 2142 * what the core add_memory() interface requires. 2143 * The Hyper-V interface requires that the memory block 2144 * size be a power of 2, which is guaranteed by the 2145 * check in memory_dev_init(). 2146 */ > 2147 ha_pages_in_chunk = memory_block_size_bytes() / PAGE_SIZE; 2148 2149 return vmbus_driver_register(&balloon_drv); 2150 } 2151 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/2] hv_balloon: Use kernel macros to simplify open coded sequences 2024-05-01 15:14 [PATCH v2 1/2] hv_balloon: Use kernel macros to simplify open coded sequences mhkelley58 2024-05-01 15:14 ` [PATCH v2 2/2] hv_balloon: Enable hot-add for memblock sizes > 128 MiB mhkelley58 @ 2024-05-02 7:06 ` David Hildenbrand 1 sibling, 0 replies; 7+ messages in thread From: David Hildenbrand @ 2024-05-02 7:06 UTC (permalink / raw) To: mhklinux, haiyangz, wei.liu, decui, linux-kernel, linux-hyperv On 01.05.24 17:14, mhkelley58@gmail.com wrote: > From: Michael Kelley <mhklinux@outlook.com> > > Code sequences equivalent to ALIGN(), ALIGN_DOWN(), and umin() are > currently open coded. Change these to use the kernel macro to > improve code clarity. ALIGN() and ALIGN_DOWN() require the > alignment value to be a power of 2, which is the case here. > > Signed-off-by: Michael Kelley <mhklinux@outlook.com> > --- > Changes in v2: > * No changes. This is a new patch that goes with v2 of patch 2 of this series. > Reviewed-by: David Hildenbrand <david@redhat.com> -- Cheers, David / dhildenb ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-05-02 22:40 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-05-01 15:14 [PATCH v2 1/2] hv_balloon: Use kernel macros to simplify open coded sequences mhkelley58 2024-05-01 15:14 ` [PATCH v2 2/2] hv_balloon: Enable hot-add for memblock sizes > 128 MiB mhkelley58 2024-05-02 7:17 ` David Hildenbrand 2024-05-02 22:40 ` Michael Kelley 2024-05-02 17:29 ` kernel test robot 2024-05-02 20:49 ` kernel test robot 2024-05-02 7:06 ` [PATCH v2 1/2] hv_balloon: Use kernel macros to simplify open coded sequences David Hildenbrand
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox