From patchwork Fri Dec 10 10:01:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shirley Ma X-Patchwork-Id: 397932 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBAA25hG007478 for ; Fri, 10 Dec 2010 10:02:05 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752293Ab0LJKBa (ORCPT ); Fri, 10 Dec 2010 05:01:30 -0500 Received: from e35.co.us.ibm.com ([32.97.110.153]:52336 "EHLO e35.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751004Ab0LJKB3 (ORCPT ); Fri, 10 Dec 2010 05:01:29 -0500 Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by e35.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id oBA9n3mN005203; Fri, 10 Dec 2010 02:49:04 -0700 Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id oBAA1QOp129758; Fri, 10 Dec 2010 03:01:26 -0700 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id oBAA1Pfw007463; Fri, 10 Dec 2010 03:01:26 -0700 Received: from [9.65.207.31] (sig-9-65-207-31.mts.ibm.com [9.65.207.31]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id oBAA1ND7007352; Fri, 10 Dec 2010 03:01:23 -0700 Subject: [RFC PATCH V2 3/5] Add userspace buffers callback in skb_share_info From: Shirley Ma To: Avi Kivity , Arnd Bergmann , mst@redhat.com Cc: xiaohui.xin@intel.com, netdev@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 10 Dec 2010 02:01:22 -0800 Message-ID: <1291975282.2167.35.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 (2.28.3-1.fc12) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Fri, 10 Dec 2010 10:02:06 +0000 (UTC) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index e6ba898..938a7cb 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -183,6 +183,15 @@ enum { SKBTX_DRV_NEEDS_SK_REF = 1 << 3, }; +/* The callback notifies userspace to release buffers when skb DMA is done in + * lower device, the desc is used to track userspace buffer index. + */ +struct skb_ubuf_info { + /* support buffers allocation from userspace */ + void (*callback)(struct sk_buff *); + size_t desc; +}; + /* This data is invariant across clones and lives at * the end of the header data, ie. at skb->end. */ @@ -205,6 +214,10 @@ struct skb_shared_info { /* Intermediate layers must ensure that destructor_arg * remains valid until skb destructor */ void * destructor_arg; + + /* DMA mapping from userspace buffers */ + struct skb_ubuf_info ubuf; + /* must be last field, see pskb_expand_head() */ skb_frag_t frags[MAX_SKB_FRAGS]; }; diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 104f844..f9468a0 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -210,6 +210,7 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask, shinfo = skb_shinfo(skb); memset(shinfo, 0, offsetof(struct skb_shared_info, dataref)); atomic_set(&shinfo->dataref, 1); + shinfo->ubuf.callback = NULL; if (fclone) { struct sk_buff *child = skb + 1; @@ -329,6 +330,15 @@ static void skb_release_data(struct sk_buff *skb) if (skb_has_frag_list(skb)) skb_drop_fraglist(skb); + + /* + * if skb buf is from userspace, we need to notify the caller + * the lower device DMA has done; + */ + if (skb_shinfo(skb)->ubuf.callback) { + skb_shinfo(skb)->ubuf.callback(skb); + skb_shinfo(skb)->ubuf.callback = NULL; + } kfree(skb->head); } @@ -492,6 +502,7 @@ bool skb_recycle_check(struct sk_buff *skb, int skb_size) shinfo = skb_shinfo(skb); memset(shinfo, 0, offsetof(struct skb_shared_info, dataref)); atomic_set(&shinfo->dataref, 1); + shinfo->ubuf.callback = NULL; memset(skb, 0, offsetof(struct sk_buff, tail)); skb->data = skb->head + NET_SKB_PAD;