On 09/10/2020 1:44, Sagi Grimberg wrote:
>> crc offload of the nvme capsule. Check if all the skb bits
>> are on, and if not recalculate the crc in SW and check it.
> Can you clarify in the patch description that this is only
> for pdu data digest and not header digest?

Will do

>
>> This patch reworks the receive-side crc calculation to always
>> run at the end, so as to keep a single flow for both offload
>> and non-offload. This change simplifies the code, but it may degrade
>> performance for non-offload crc calculation.
> ??
>
>  From my scan it doeesn't look like you do that.. Am I missing something?
> Can you explain?

The performance of CRC data digest in the offload's fallback path may be less 
good compared to CRC calculation with skb_copy_and_hash.
To be clear, the fallback path is occurs when `queue->data_digest && 
test_bit(NVME_TCP_Q_OFF_CRC_RX, &queue->flags)`, while we receive SKBs where 
`skb->ddp_crc = 0`

>
>>      rq = blk_mq_tag_to_rq(nvme_tcp_tagset(queue), pdu->command_id);
>>      if (!rq) {
>>              dev_err(queue->ctrl->ctrl.device,
>> @@ -992,7 +1031,7 @@ static int nvme_tcp_recv_data(struct nvme_tcp_queue 
>> *queue, struct sk_buff *skb,
>>              recv_len = min_t(size_t, recv_len,
>>                              iov_iter_count(&req->iter));
>>   
>> -            if (queue->data_digest)
>> +            if (queue->data_digest && !test_bit(NVME_TCP_Q_OFFLOADS, 
>> &queue->flags))
>>                      ret = skb_copy_and_hash_datagram_iter(skb, *offset,
>>                              &req->iter, recv_len, queue->rcv_hash);
> This is the skb copy and hash, not clear why you say that you move this
> to the end...

See the offload fallback path below

>
>>              else
>> @@ -1012,7 +1051,6 @@ static int nvme_tcp_recv_data(struct nvme_tcp_queue 
>> *queue, struct sk_buff *skb,
>>   
>>      if (!queue->data_remaining) {
>>              if (queue->data_digest) {
>> -                    nvme_tcp_ddgst_final(queue->rcv_hash, 
>> &queue->exp_ddgst);
> If I instead do:
>                       if (!test_bit(NVME_TCP_Q_OFFLOADS,
>                                        &queue->flags))
>                               nvme_tcp_ddgst_final(queue->rcv_hash,
>                                                    &queue->exp_ddgst);
>
> Does that help the mess in nvme_tcp_recv_ddgst?

Not really, as the code path there takes care of the fallback path, i.e. 
offloaded requested, but didn't succeed.

>
>>                      queue->ddgst_remaining = NVME_TCP_DIGEST_LENGTH;
>>              } else {
>>                      if (pdu->hdr.flags & NVME_TCP_F_DATA_SUCCESS) {
>> @@ -1033,8 +1071,11 @@ static int nvme_tcp_recv_ddgst(struct nvme_tcp_queue 
>> *queue,
>>      char *ddgst = (char *)&queue->recv_ddgst;
>>      size_t recv_len = min_t(size_t, *len, queue->ddgst_remaining);
>>      off_t off = NVME_TCP_DIGEST_LENGTH - queue->ddgst_remaining;
>> +    bool ddgst_offload_fail;
>>      int ret;
>>   
>> +    if (test_bit(NVME_TCP_Q_OFFLOADS, &queue->flags))
>> +            nvme_tcp_device_ddgst_update(queue, skb);
>>      ret = skb_copy_bits(skb, *offset, &ddgst[off], recv_len);
>>      if (unlikely(ret))
>>              return ret;
>> @@ -1045,12 +1086,21 @@ static int nvme_tcp_recv_ddgst(struct nvme_tcp_queue 
>> *queue,
>>      if (queue->ddgst_remaining)
>>              return 0;
>>   
>> -    if (queue->recv_ddgst != queue->exp_ddgst) {
>> -            dev_err(queue->ctrl->ctrl.device,
>> -                    "data digest error: recv %#x expected %#x\n",
>> -                    le32_to_cpu(queue->recv_ddgst),
>> -                    le32_to_cpu(queue->exp_ddgst));
>> -            return -EIO;
>> +    ddgst_offload_fail = !nvme_tcp_device_ddgst_ok(queue);
>> +    if (!test_bit(NVME_TCP_Q_OFFLOADS, &queue->flags) ||
>> +        ddgst_offload_fail) {
>> +            if (test_bit(NVME_TCP_Q_OFFLOADS, &queue->flags) &&
>> +                ddgst_offload_fail)
>> +                    nvme_tcp_crc_recalculate(queue, pdu);
>> +
>> +            nvme_tcp_ddgst_final(queue->rcv_hash, &queue->exp_ddgst);
>> +            if (queue->recv_ddgst != queue->exp_ddgst) {
>> +                    dev_err(queue->ctrl->ctrl.device,
>> +                            "data digest error: recv %#x expected %#x\n",
>> +                            le32_to_cpu(queue->recv_ddgst),
>> +                            le32_to_cpu(queue->exp_ddgst));
>> +                    return -EIO;
> This gets convoluted here...

Will try to simplify, the general idea is that there are 3 paths with common 
code:
1. non-offload
2. offload failed
3. offload success
(1) and (2) share the code for finalizing checking the data digest, while (3) 
skips this entirely.

In other words, how about this:
```
          offload_fail = !nvme_tcp_ddp_ddgst_ok(queue);                         
                      
          offload = test_bit(NVME_TCP_Q_OFF_CRC_RX, &queue->flags);             
                      
          if (!offload || offload_fail) {                                       
                      
                  if (offload && offload_fail) // software-fallback             
                      
                          nvme_tcp_ddp_ddgst_recalc(queue, pdu);                
                      
                                                                                
                      
                  nvme_tcp_ddgst_final(queue->rcv_hash, &queue->exp_ddgst);     
                      
                  if (queue->recv_ddgst != queue->exp_ddgst) {                  
                      
                          dev_err(queue->ctrl->ctrl.device,                     
                      
                                  "data digest error: recv %#x expected %#x\n", 
                      
                                  le32_to_cpu(queue->recv_ddgst),               
                      
                                  le32_to_cpu(queue->exp_ddgst));               
                      
                          return -EIO;                                          
                      
                  }                                                             
                      
          } 
```

>
>> +            }
>>      }
>>   
>>      if (pdu->hdr.flags & NVME_TCP_F_DATA_SUCCESS) {
>>

Reply via email to