From patchwork Fri Sep 2 11:08:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Sutter X-Patchwork-Id: 1121692 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p82B8oge005569 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 2 Sep 2011 11:09:11 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QzRbs-0000QM-QX; Fri, 02 Sep 2011 11:08:32 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QzRbs-0006LM-C9; Fri, 02 Sep 2011 11:08:32 +0000 Received: from mail.vipri.net ([89.207.250.2]) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QzRbq-0006L2-2L for linux-arm-kernel@lists.infradead.org; Fri, 02 Sep 2011 11:08:30 +0000 Received: from phil.computerman.de ([80.242.149.18]) by mail.vipri.net with ESMTP (Sitejets 3); Fri, 2 Sep 2011 13:08:17 +0200 From: Phil Sutter To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] af_packet: flush complete kernel cache in packet_sendmsg Date: Fri, 2 Sep 2011 13:08:06 +0200 Message-Id: <1314961686-30870-1-git-send-email-phil.sutter@viprinet.com> X-Mailer: git-send-email 1.7.6.1 In-Reply-To: <20110505141107.GC30443@orbit.nwl.cc> References: <20110505141107.GC30443@orbit.nwl.cc> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110902_070830_258638_C85150EB X-CRM114-Status: GOOD ( 13.54 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- Cc: netdev@vger.kernel.org, Russell King , "David S. Miller" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 02 Sep 2011 11:09:11 +0000 (UTC) This flushes the cache before and after accessing the mmapped packet buffer. It seems like the call to flush_dcache_page from inside __packet_get_status is not enough on Kirkwood (or ARM in general). --- I know this is far from an optimal solution, but it's in fact the only working one I found. And it shouldn't interfere with unaffected target systems. So anyone relying on a working TX_RING on Kirkwood may refer to this patch. Any ARM/cache/Marvell/Kirkwood experts out there feel free to improve this. --- net/packet/af_packet.c | 24 ++++++++++++++++++++---- 1 files changed, 20 insertions(+), 4 deletions(-) diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 243946d..d7b5c2e 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -87,6 +87,14 @@ #include #endif +/* whether we need additional cacheflushing between user- and kernel-space */ +#ifdef CONFIG_ARCH_KIRKWOOD +# define ENABLE_CACHEPROB_WORKAROUND +# define kw_extra_cache_flush() flush_cache_all() +#else +# define kw_extra_cache_flush() /* nothing */ +#endif + /* Assumptions: - if device has no dev->hard_header routine, it adds and removes ll header @@ -1239,10 +1247,13 @@ static int packet_sendmsg(struct kiocb *iocb, struct socket *sock, { struct sock *sk = sock->sk; struct packet_sock *po = pkt_sk(sk); - if (po->tx_ring.pg_vec) - return tpacket_snd(po, msg); - else - return packet_snd(sock, msg, len); + int rc; + + kw_extra_cache_flush(); + rc = po->tx_ring.pg_vec ? tpacket_snd(po, msg) : + packet_snd(sock, msg, len); + kw_extra_cache_flush(); + return rc; } /* @@ -2622,6 +2633,11 @@ static int __init packet_init(void) sock_register(&packet_family_ops); register_pernet_subsys(&packet_net_ops); register_netdevice_notifier(&packet_netdev_notifier); + +#ifdef ENABLE_CACHEPROB_WORKAROUND + printk(KERN_INFO "af_packet: cache coherency workaround for kirkwood is active!\n"); +#endif + out: return rc; }