Page MenuHomeFreeBSD

TCP and checksum offloading for Hyper-V
ClosedPublic

Authored by whu on May 12 2015, 5:45 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Nov 24, 12:15 PM
Unknown Object (File)
Sun, Nov 24, 9:55 AM
Unknown Object (File)
Thu, Nov 21, 8:31 AM
Unknown Object (File)
Wed, Nov 20, 2:56 PM
Unknown Object (File)
Thu, Nov 7, 6:13 AM
Unknown Object (File)
Oct 30 2024, 11:41 AM
Unknown Object (File)
Oct 12 2024, 5:09 AM
Unknown Object (File)
Oct 5 2024, 6:01 AM
Subscribers

Details

Summary

Netvsc TCP and checksum offloading for Hyper-V. Also fixed some bugs
in the netvsc driver.

This is for the head branch. We are targeting this for 10.2 release once
this is in the head.

Test Plan

Tested by Microsoft OSTC.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
  • Incorporate internal review comments
  • Fix white space issue left from previous change
whu added a reviewer: royger.
whu added a subscriber: gibbs.

I cannot really comment on the specific implementation since I don't know anything about the HyperV net protocol. I have however found quite a lot of coding style errors, and a couple of minor comments/improvements.

sys/dev/hyperv/netvsc/hv_net_vsc.c
146

Parentheses around return value.

151

No need for braces in single line statements.

156

Parentheses around return value.

311

2 casts? Why not use uint64_t directly?

335

I see that you use M_DEVBUF in the driver, could you create a new tag to be used by the net driver? M_NETVSC sounds like a suitable name.

591

Adding braces in the for case would make this code easier to read (not that they are really needed).

603

Can you use device_printf here?

sys/dev/hyperv/netvsc/hv_net_vsc.h
869

Is this 4096 because it's limited by PAGE_SIZE, or it is not related?

912

uint8_t?

1003

Please indent using 4 spaces (here and below).

1005

Following the style used in this file I don't think there should be a line break here.

sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
214

IMHO I would set ret_val = TRANSPORT_TYPE_NOT_IP here so the flow is clearer.

sys/dev/hyperv/netvsc/hv_rndis.h
652

Missing space.

1057

Coding style, and why are those declared as extern?

sys/dev/hyperv/netvsc/hv_rndis_filter.c
84

This is not the FreeBSD coding style, please fix it. Also why are you using extern here?

108

Extern?

115

Missing parentheses.

342

Missing parentheses around return value, and no minus sign please.

374

Missing space between ) and {, here and in several other places.

378

What does this value mean? Can't you use a proper error value (if it's indeed an error)?

873

Missing space between ) and {.

whu marked 19 inline comments as done.May 25 2015, 6:11 AM

Thanks for the review. I have addressed most of them. Only have a question regarding to creating a new tag for M_DEVBUF.

sys/dev/hyperv/netvsc/hv_net_vsc.c
335

Hmm.... why do we need to create a new one while the existing M_DEVBUF could serve the purpose?

sys/dev/hyperv/netvsc/hv_net_vsc.h
869

This was inherited from its Windows counterpart. I believe it is somewhat related to PAGE_SIZE.

sys/dev/hyperv/netvsc/hv_net_vsc.c
335

So that when you use vmstat -m it's not listed as a generic "devbuf" allocation. It's quite helpful when debugging memory leaks or track memory usage of each driver.

sys/dev/hyperv/netvsc/hv_net_vsc.h
869

IMHO, if this is related to page size I would rather use PAGE_SIZE directly.

whu marked 3 inline comments as done.May 28 2015, 5:52 AM
whu edited edge metadata.
  • Incorporate review comments from royger

I've still found quite a lot of coding style errors, please try to check those before sending patches for review or else they just slow down the review process.

sys/dev/hyperv/netvsc/hv_net_vsc.c
67

This should be aligned using 4 spaces after a line break.

130

extern in function definition???

149

This is defined inside of the Xen headers, you might want to use atomic_testandset_long in the machine/atomic.h header instead.

179

contigmalloc assumes M_WAITOK unless M_NOWAIT is specified, so you can drop the check against NULL.

290

Stray change, or is it an alignment fix? Sorry but phabric is quite crappy with tabs vs spaces.

333
net_dev->bitsmap_words = howmany(net_dev->send_section_count, BITS_PER_LONG);
494

After a line break align using 4 spaces.

577

If this always has to be the number of items in the static array initialized above I would rather use:

int protocol_number = nitems(protocol_list);
596

device_printf?

771

Align using 4 spaces after a line break.

796

Again this is defined in Xen headers. You should be able to find a suitable equivalent in machine/atomic.h. I plan to remove those Xen specific bitops and replace them with the FreeBSD native ones in Xen code.

870

This is not FreeBSD coding style, please fix it.

885

device_printf

894

device_printf

902

device_printf

941

4 spaces after line break, and please place both in the same line.

1006

device_printf

1022

device_printf

1028

IMHO you should consider removing this unbound loop, using this kind of constructions can lead to infinite loops in kernel code. Can't you use ret as a condition here and avoid the breaks in the inner code?

sys/dev/hyperv/netvsc/hv_net_vsc.h
941

IMHO I think you should be able to use LONG_BIT from sys/limits.h instead of rolling your own. Or in any case this should be:

#ifdef  __LP64__
#define BITS_PER_LONG 64
#else
#define BITS_PER_LONG 32
#endif

Although I would recommend to simply set:

#define BITS_PER_LONG LONG_BIT
1005–1009

there's no reason to add a line break between tid and status. Also, could you remove the "extern" from function prototypes? IMHO unless I'm wrong it simply makes no sense, function declarations are always extern in C.

sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
428

Don't add this alignment here, the reset of the local variables are aligned using a space.

468–471

device_printf

494–496

device_printf

673
atop(hv_get_phys_addr(rndis_mesg))
675

Use PAGE_MASK instead of PAGE_SIZE - 1

849

This is not FreeBSD coding style.

889

device_printf and no exclamation marks.

sys/dev/hyperv/netvsc/hv_rndis.h
1050

4 spaces after line break.

1053

4 spaces after line break.

sys/dev/hyperv/netvsc/hv_rndis_filter.c
74

4 spaces after line break.

231

4 spaces after line break.

315

4 spaces after line break.

359

device_printf

365

device_printf

371

device_printf

397
switch (indicate->status) {
case RNDIS_STATUS_MEDIA_CONNECT:
...
case RNDIS_STATUS_MEDIA_DISCONNECT:
...
default:
...
402

Should you add a device_printf here indicating that an unknown change has been received, and thus will be ignored?

430

device_printf, and please write complete error messages (total, length). Those are supposed to be understood by users.

875

device_printf

sys/dev/hyperv/netvsc/hv_rndis_filter.h
102–103

Why all those externs in function declarations?

whu marked 38 inline comments as done.Jun 17 2015, 8:58 AM

Sorry it took a while to get this done. I was out of office due to family issues.

sys/dev/hyperv/netvsc/hv_net_vsc.c
796

I don't find similar one in atomic.h using 'btcl' instruction.

1028

In the cases of either (ret == 0 && bytes_rxed > 0) or (ret == ENOBUFS), we still want to keep reading the ring buffer until there is nothing left. The only case to break out of the while loop is (ret ==0 && bytes_rxed == 0).

If you don't mind, I would like to maintain its current code logic to make it in consistence to its Windows and Linux counterparts.

  • More review comments from royger
royger edited edge metadata.
In D2517#54874, @whu wrote:
  • More review comments from royger

I'm happy with the code now. I've just added a couple of comments, please make sure to read the ones about the atomic_ and synch_ ops, since they may affect your code (and sorry for giving a wrong advice in the first place).

Once that's done, you can commit it.

sys/dev/hyperv/netvsc/hv_net_vsc.c
149

Is "bitsmap" shared between the VM and another entity on the system (another VM or the hypervisor)?

If that's the case please ignore my previous comment and keep using the synch_* functions, or else it won't work properly when used on a kernel without SMP support.

796

Right, this is missing from the native FreeBSD atomic ops. I've also realized that on UP kernels (kernels compiled without SMP) the native FreeBSD atomic ops drop the "lock" prefix, which means they cannot be safely used inside of a VM if the memory is shared between another VM or the hypervisor.

I guess it's fine to use the synch_* ones for now. I will try to come up with a patch to properly remove them when I have some time...

1028

As you wish, this was just a suggestion. At the end of day you are the one that's going to maintain the code :).

This revision is now accepted and ready to land.Jun 19 2015, 2:26 PM

Thanks Roger for the review!

sys/dev/hyperv/netvsc/hv_net_vsc.c
149

Thanks so much Roger! I didn't realize it. You are absolutely right. It just uses MPLOCK which could cause problem in UP VMs. I will change it back to use synch_* as it is likely this bitmap is being shared by hypervisor and VMs.

This revision was automatically updated to reflect the committed changes.