2020-10-12 13:28:22

by David Hildenbrand

[permalink] [raw]
Subject: [PATCH v1 06/29] virtio-mem: generalize virtio_mem_owned_mb()

Avoid using memory block ids. Rename it to virtio_mem_contains_range().

Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Jason Wang <[email protected]>
Cc: Pankaj Gupta <[email protected]>
Signed-off-by: David Hildenbrand <[email protected]>
---
drivers/virtio/virtio_mem.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c
index 6bbd1cfd10d3..821143db14fe 100644
--- a/drivers/virtio/virtio_mem.c
+++ b/drivers/virtio/virtio_mem.c
@@ -500,12 +500,13 @@ static bool virtio_mem_overlaps_range(struct virtio_mem *vm,
}

/*
- * Test if a virtio-mem device owns a memory block. Can be called from
+ * Test if a virtio-mem device contains a given range. Can be called from
* (notifier) callbacks lockless.
*/
-static bool virtio_mem_owned_mb(struct virtio_mem *vm, unsigned long mb_id)
+static bool virtio_mem_contains_range(struct virtio_mem *vm, uint64_t start,
+ uint64_t size)
{
- return mb_id >= vm->first_mb_id && mb_id <= vm->last_mb_id;
+ return start >= vm->addr && start + size <= vm->addr + vm->region_size;
}

static int virtio_mem_notify_going_online(struct virtio_mem *vm,
@@ -800,7 +801,7 @@ static void virtio_mem_online_page_cb(struct page *page, unsigned int order)
*/
rcu_read_lock();
list_for_each_entry_rcu(vm, &virtio_mem_devices, next) {
- if (!virtio_mem_owned_mb(vm, mb_id))
+ if (!virtio_mem_contains_range(vm, addr, PFN_PHYS(1 << order)))
continue;

sb_id = virtio_mem_phys_to_sb_id(vm, addr);
--
2.26.2


2020-10-15 18:25:08

by Wei Yang

[permalink] [raw]
Subject: Re: [PATCH v1 06/29] virtio-mem: generalize virtio_mem_owned_mb()

On Mon, Oct 12, 2020 at 02:53:00PM +0200, David Hildenbrand wrote:
>Avoid using memory block ids. Rename it to virtio_mem_contains_range().
>
>Cc: "Michael S. Tsirkin" <[email protected]>
>Cc: Jason Wang <[email protected]>
>Cc: Pankaj Gupta <[email protected]>
>Signed-off-by: David Hildenbrand <[email protected]>
>---
> drivers/virtio/virtio_mem.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
>diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c
>index 6bbd1cfd10d3..821143db14fe 100644
>--- a/drivers/virtio/virtio_mem.c
>+++ b/drivers/virtio/virtio_mem.c
>@@ -500,12 +500,13 @@ static bool virtio_mem_overlaps_range(struct virtio_mem *vm,
> }
>
> /*
>- * Test if a virtio-mem device owns a memory block. Can be called from
>+ * Test if a virtio-mem device contains a given range. Can be called from
> * (notifier) callbacks lockless.
> */
>-static bool virtio_mem_owned_mb(struct virtio_mem *vm, unsigned long mb_id)
>+static bool virtio_mem_contains_range(struct virtio_mem *vm, uint64_t start,
>+ uint64_t size)
> {
>- return mb_id >= vm->first_mb_id && mb_id <= vm->last_mb_id;
>+ return start >= vm->addr && start + size <= vm->addr + vm->region_size;

Do we have some reason to do this change?

> }
>
> static int virtio_mem_notify_going_online(struct virtio_mem *vm,
>@@ -800,7 +801,7 @@ static void virtio_mem_online_page_cb(struct page *page, unsigned int order)
> */
> rcu_read_lock();
> list_for_each_entry_rcu(vm, &virtio_mem_devices, next) {
>- if (!virtio_mem_owned_mb(vm, mb_id))
>+ if (!virtio_mem_contains_range(vm, addr, PFN_PHYS(1 << order)))
> continue;
>
> sb_id = virtio_mem_phys_to_sb_id(vm, addr);
>--
>2.26.2

--
Wei Yang
Help you, Help me

2020-10-15 18:26:01

by David Hildenbrand

[permalink] [raw]
Subject: Re: [PATCH v1 06/29] virtio-mem: generalize virtio_mem_owned_mb()

On 15.10.20 10:32, Wei Yang wrote:
> On Mon, Oct 12, 2020 at 02:53:00PM +0200, David Hildenbrand wrote:
>> Avoid using memory block ids. Rename it to virtio_mem_contains_range().
>>
>> Cc: "Michael S. Tsirkin" <[email protected]>
>> Cc: Jason Wang <[email protected]>
>> Cc: Pankaj Gupta <[email protected]>
>> Signed-off-by: David Hildenbrand <[email protected]>
>> ---
>> drivers/virtio/virtio_mem.c | 9 +++++----
>> 1 file changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c
>> index 6bbd1cfd10d3..821143db14fe 100644
>> --- a/drivers/virtio/virtio_mem.c
>> +++ b/drivers/virtio/virtio_mem.c
>> @@ -500,12 +500,13 @@ static bool virtio_mem_overlaps_range(struct virtio_mem *vm,
>> }
>>
>> /*
>> - * Test if a virtio-mem device owns a memory block. Can be called from
>> + * Test if a virtio-mem device contains a given range. Can be called from
>> * (notifier) callbacks lockless.
>> */
>> -static bool virtio_mem_owned_mb(struct virtio_mem *vm, unsigned long mb_id)
>> +static bool virtio_mem_contains_range(struct virtio_mem *vm, uint64_t start,
>> + uint64_t size)
>> {
>> - return mb_id >= vm->first_mb_id && mb_id <= vm->last_mb_id;
>> + return start >= vm->addr && start + size <= vm->addr + vm->region_size;
>
> Do we have some reason to do this change?

Big Block Mode :)

--
Thanks,

David / dhildenb

2020-10-15 22:24:57

by Pankaj Gupta

[permalink] [raw]
Subject: Re: [PATCH v1 06/29] virtio-mem: generalize virtio_mem_owned_mb()

> Avoid using memory block ids. Rename it to virtio_mem_contains_range().
>
> Cc: "Michael S. Tsirkin" <[email protected]>
> Cc: Jason Wang <[email protected]>
> Cc: Pankaj Gupta <[email protected]>
> Signed-off-by: David Hildenbrand <[email protected]>
> ---
> drivers/virtio/virtio_mem.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c
> index 6bbd1cfd10d3..821143db14fe 100644
> --- a/drivers/virtio/virtio_mem.c
> +++ b/drivers/virtio/virtio_mem.c
> @@ -500,12 +500,13 @@ static bool virtio_mem_overlaps_range(struct virtio_mem *vm,
> }
>
> /*
> - * Test if a virtio-mem device owns a memory block. Can be called from
> + * Test if a virtio-mem device contains a given range. Can be called from
> * (notifier) callbacks lockless.
> */
> -static bool virtio_mem_owned_mb(struct virtio_mem *vm, unsigned long mb_id)
> +static bool virtio_mem_contains_range(struct virtio_mem *vm, uint64_t start,
> + uint64_t size)
> {
> - return mb_id >= vm->first_mb_id && mb_id <= vm->last_mb_id;
> + return start >= vm->addr && start + size <= vm->addr + vm->region_size;
> }
>
> static int virtio_mem_notify_going_online(struct virtio_mem *vm,
> @@ -800,7 +801,7 @@ static void virtio_mem_online_page_cb(struct page *page, unsigned int order)
> */
> rcu_read_lock();
> list_for_each_entry_rcu(vm, &virtio_mem_devices, next) {
> - if (!virtio_mem_owned_mb(vm, mb_id))
> + if (!virtio_mem_contains_range(vm, addr, PFN_PHYS(1 << order)))
> continue;
>
> sb_id = virtio_mem_phys_to_sb_id(vm, addr);

Looks good.
Reviewed-by: Pankaj Gupta <[email protected]>