Displaying 20 results from an estimated 274 matches for "div_round_up".
2008 Aug 02
0
[PATCH 10/10] drivers/net/xen-netfront.c: Use DIV_ROUND_UP
From: Julia Lawall <julia at diku.dk>
The kernel.h macro DIV_ROUND_UP performs the computation (((n) + (d) - 1) /
(d)) but is perhaps more readable.
An extract of the semantic patch that makes this change is as follows:
(http://www.emn.fr/x-info/coccinelle/)
// <smpl>
@haskernel@
@@
#include <linux/kernel.h>
@depends on haskernel@
expression n,d;
@@...
2015 Mar 02
0
[PATCH] VMCI: Guard against overflow in queue pair allocation
...drivers/misc/vmw_vmci/vmci_queue_pair.c
index 35f19a6..6d5144c 100644
--- a/drivers/misc/vmw_vmci/vmci_queue_pair.c
+++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c
@@ -295,12 +295,20 @@ static void *qp_alloc_queue(u64 size, u32 flags)
{
u64 i;
struct vmci_queue *queue;
- const size_t num_pages = DIV_ROUND_UP(size, PAGE_SIZE) + 1;
- const size_t pas_size = num_pages * sizeof(*queue->kernel_if->u.g.pas);
- const size_t vas_size = num_pages * sizeof(*queue->kernel_if->u.g.vas);
- const size_t queue_size =
- sizeof(*queue) + sizeof(*queue->kernel_if) +
- pas_size + vas_size;
+ size_t pas_s...
2015 Mar 02
0
[PATCH] VMCI: Guard against overflow in queue pair allocation
...drivers/misc/vmw_vmci/vmci_queue_pair.c
index 35f19a6..6d5144c 100644
--- a/drivers/misc/vmw_vmci/vmci_queue_pair.c
+++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c
@@ -295,12 +295,20 @@ static void *qp_alloc_queue(u64 size, u32 flags)
{
u64 i;
struct vmci_queue *queue;
- const size_t num_pages = DIV_ROUND_UP(size, PAGE_SIZE) + 1;
- const size_t pas_size = num_pages * sizeof(*queue->kernel_if->u.g.pas);
- const size_t vas_size = num_pages * sizeof(*queue->kernel_if->u.g.vas);
- const size_t queue_size =
- sizeof(*queue) + sizeof(*queue->kernel_if) +
- pas_size + vas_size;
+ size_t pas_s...
2018 Jan 26
2
[PATCH nbdkit] filters: cache, cow: Handle bitmap overflow on 32 bit architectures.
...1;
static uint8_t *bitmap;
/* Size of the bitmap in bytes. */
-static uint64_t bm_size;
+static size_t bm_size;
enum bm_entry {
BLOCK_NOT_CACHED = 0,
@@ -167,7 +167,14 @@ blk_set_size (uint64_t new_size)
{
uint8_t *new_bm;
const size_t old_bm_size = bm_size;
- size_t new_bm_size = DIV_ROUND_UP (new_size, BLKSIZE*8/2);
+ uint64_t new_bm_size_u64 = DIV_ROUND_UP (new_size, BLKSIZE*8/2);
+ size_t new_bm_size;
+
+ if (new_bm_size_u64 > SIZE_MAX) {
+ nbdkit_error ("bitmap too large for this architecture");
+ return -1;
+ }
+ new_bm_size = (size_t) new_bm_size_u64;...
2023 Mar 10
3
[PATCH v3 2/6] erofs: convert to use i_blockmask()
On Thu, Mar 09, 2023 at 11:21:23PM +0800, Yangtao Li wrote:
> Use i_blockmask() to simplify code.
Umm... What's the branchpoint for that series? Not the mainline -
there we have i_blocksize() open-coded...
> Signed-off-by: Yangtao Li <frank.li at vivo.com>
> ---
> v3:
> -none
> v2:
> -convert to i_blockmask()
> fs/erofs/data.c | 2 +-
> 1 file changed, 1
2013 Jul 10
13
[PATCH v2 1/1] xen/netback: correctly calculate required slots of skb.
When counting required slots for skb, netback directly uses DIV_ROUND_UP to get
slots required by header data. This is wrong when offset in the page of header
data is not zero, and is also inconsistent with following calculation for
required slot in netbk_gop_skb.
In netbk_gop_skb, required slots are calculated based on offset and len in page
of header data. It is poss...
2018 Sep 17
2
[PATCH nbdkit v2] common: Introduce round up, down; and divide round
Since we're using ({ .. }) gcc/clang extension, let's rewrite the
rounding.h change too.
Rich.
2018 Sep 17
0
[PATCH nbdkit v2] common: Introduce round up, down; and divide round up functions.
...next multiple of n (n must be a power of 2).
+ */
+#define ROUND_DOWN(i, n) ({ \
+ assert (is_power_of_2 (n)); \
+ (i) & ~((n) - 1); \
+})
+
+/* Return n / d, rounding the result up to the next integer. */
+#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+
+#endif /* NBDKIT_ROUNDING_H */
diff --git a/filters/cache/Makefile.am b/filters/cache/Makefile.am
index 867812e..827ff17 100644
--- a/filters/cache/Makefile.am
+++ b/filters/cache/Makefile.am
@@ -41,7 +41,8 @@ nbdkit_cache_filter_la_SOURCES = \
$(top_srcdir)/inclu...
2013 Aug 23
0
[PATCH 2/2] VMCI: Add support for virtual IOMMU
...*pas;
+ void **vas;
+ } g; /* Used by the guest. */
+ struct {
+ struct page **page;
+ struct page **header_page;
+ } h; /* Used by the host. */
+ } u;
};
/*
@@ -263,59 +272,65 @@ static void qp_free_queue(void *q, u64 size)
struct vmci_queue *queue = q;
if (queue) {
- u64 i = DIV_ROUND_UP(size, PAGE_SIZE);
+ u64 i;
- while (i)
- __free_page(queue->kernel_if->page[--i]);
+ /* Given size does not include header, so add in a page here. */
+ for (i = 0; i < DIV_ROUND_UP(size, PAGE_SIZE) + 1; i++) {
+ dma_free_coherent(&vmci_pdev->dev, PAGE_SIZE,
+ queue-&...
2012 Aug 13
9
[PATCH RFC] xen/netback: Count ring slots properly when larger MTU sizes are used
Hi,
I ran into an issue where netback driver is crashing with BUG_ON(npo.meta_prod > ARRAY_SIZE(netbk->meta)). It is happening in Intel 10Gbps network when larger mtu values are used. The problem seems to be the way the slots are counted. After applying this patch things ran fine in my environment. I request to validate my changes.
Thanks
Siva
2017 Nov 02
2
Possible unsafe usage of skb->cb in virtio-net
...s,
> Ilya
Thanks a lot for the pointer.
I think this was in response to this:
https://patchwork.ozlabs.org/patch/558324/
> >
> > + skb_push(skb, skb->data - skb_data_orig);
> > sq->skb[pi] = skb;
> >
> > MLX5E_TX_SKB_CB(skb)->num_wqebbs = DIV_ROUND_UP(ds_cnt,
>
> And in the middle of this we have:
>
> skb_pull_inline(skb, ihs);
>
> This is looks illegal.
>
> You must not modify the data pointers of any SKB that you receive for
> sending via ->ndo_start_xmit() unless you know that absolutely you a...
2017 Nov 02
2
Possible unsafe usage of skb->cb in virtio-net
...s,
> Ilya
Thanks a lot for the pointer.
I think this was in response to this:
https://patchwork.ozlabs.org/patch/558324/
> >
> > + skb_push(skb, skb->data - skb_data_orig);
> > sq->skb[pi] = skb;
> >
> > MLX5E_TX_SKB_CB(skb)->num_wqebbs = DIV_ROUND_UP(ds_cnt,
>
> And in the middle of this we have:
>
> skb_pull_inline(skb, ihs);
>
> This is looks illegal.
>
> You must not modify the data pointers of any SKB that you receive for
> sending via ->ndo_start_xmit() unless you know that absolutely you a...
2014 Nov 10
1
[PATCH 2/2] drm/edid: fix Baseline_ELD_Len field in drm_edid_to_eld()
...is variable size in multiple of 4 bytes, and its size is defined
> in the header block Baseline_ELD_Len field (in number of
> DWords).
>
> Do not include the header size in Baseline_ELD_Len field. Fix all known
> users of eld[2].
>
> While at it, switch to DIV_ROUND_UP instead of open coding it.
>
> Signed-off-by: Jani Nikula <jani.nikula at intel.com>
>
> ---
>
> This is based on an audio rework series which is mid-way being merged to
> i915. I don't think this should be cc: stable worthy, as, AFAICT, we
> don't use the vend...
2013 Jul 09
20
[PATCH 1/1] xen/netback: correctly calculate required slots of skb.
When counting required slots for skb, netback directly uses DIV_ROUND_UP to get
slots required by header data. This is wrong when offset in the page of header
data is not zero, and is also inconsistent with following calculation for
required slot in netbk_gop_skb.
In netbk_gop_skb, required slots are calculated based on offset and len in page
of header data. It is poss...
2023 Mar 10
1
[PATCH v3 4/6] ext4: convert to use i_blockmask()
...a_data *mpd,
> {
> struct inode *inode = mpd->inode;
> int err;
> - ext4_lblk_t blocks = (i_size_read(inode) + i_blocksize(inode) - 1)
> + ext4_lblk_t blocks = (i_size_read(inode) + i_blockmask(inode))
> >> inode->i_blkbits;
Umm... That actually asks for DIV_ROUND_UP(i_size_read_inode(), i_blocksize(inode)) -
compiler should bloody well be able to figure out that division by (1 << n) is
shift down by n and it's easier to follow that way...
2023 Mar 10
1
erofs: convert to use i_blockmask()
...have i_blocksize() open-coded...
>
> Sorry, I'm based on the latest branch of the erofs repository.
>
> https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git/log/?h=dev-test
>
> I think I can resend based on mainline.
>
> > Umm... That actually asks for DIV_ROUND_UP(i_size_read_inode(), i_blocksize(inode))
> > - compiler should bloody well be able to figure out that division by (1 << n)
> > is shift down by n and it's easier to follow that way...
>
> So it seems better to change to DIV_ROUND_UP(i_size_read_inode(), i_blocksize(inod...
2017 Jun 01
4
[PATCH] virtio_net: lower limit on buffer size
...dr_len);
+ rq->min_buf_len, PAGE_SIZE - hdr_len);
return ALIGN(len, L1_CACHE_BYTES);
}
@@ -2039,7 +2039,8 @@ static unsigned int mergeable_min_buf_len(struct virtnet_info *vi, struct virtqu
unsigned int buf_len = hdr_len + ETH_HLEN + VLAN_HLEN + packet_len;
unsigned int min_buf_len = DIV_ROUND_UP(buf_len, rq_size);
- return max(min_buf_len, hdr_len);
+ return max(max(min_buf_len, hdr_len) - hdr_len,
+ (unsigned int)GOOD_PACKET_LEN);
}
static int virtnet_find_vqs(struct virtnet_info *vi)
--
MST
2017 Jun 01
4
[PATCH] virtio_net: lower limit on buffer size
...dr_len);
+ rq->min_buf_len, PAGE_SIZE - hdr_len);
return ALIGN(len, L1_CACHE_BYTES);
}
@@ -2039,7 +2039,8 @@ static unsigned int mergeable_min_buf_len(struct virtnet_info *vi, struct virtqu
unsigned int buf_len = hdr_len + ETH_HLEN + VLAN_HLEN + packet_len;
unsigned int min_buf_len = DIV_ROUND_UP(buf_len, rq_size);
- return max(min_buf_len, hdr_len);
+ return max(max(min_buf_len, hdr_len) - hdr_len,
+ (unsigned int)GOOD_PACKET_LEN);
}
static int virtnet_find_vqs(struct virtnet_info *vi)
--
MST
2018 Sep 17
0
[PATCH nbdkit v3 2/3] common: Introduce round up, down; and divide round up functions.
...next multiple of n (n must be a power of 2).
+ */
+#define ROUND_DOWN(i, n) ({ \
+ assert (is_power_of_2 (n)); \
+ (i) & -((typeof (i))(n)); \
+})
+
+/* Return n / d, rounding the result up to the next integer. */
+#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+
+#endif /* NBDKIT_ROUNDING_H */
diff --git a/filters/cache/Makefile.am b/filters/cache/Makefile.am
index 867812e..827ff17 100644
--- a/filters/cache/Makefile.am
+++ b/filters/cache/Makefile.am
@@ -41,7 +41,8 @@ nbdkit_cache_filter_la_SOURCES = \
$(top_srcdir)/inclu...
2016 Mar 11
16
[PATCH 00/16] clk/gm20b: add basic driver
This series does some refactoring in the GK20A's volt and clk drivers
(fixing a few things while we are at it) to let GM20B benefit from the
GK20A's logic with which it is compatible.
GM20B is capable of more sophisticated (and power-efficient) reclocking
which will follow later. Even after this more fancy reclocking is merged,
the present logic will remain used in the lowest speedo of