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: 113123 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 53B5FB71AB for ; Fri, 2 Sep 2011 21:17:46 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933495Ab1IBLRl (ORCPT ); Fri, 2 Sep 2011 07:17:41 -0400 Received: from mail.vipri.net ([89.207.250.2]:52879 "EHLO mail.vipri.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933431Ab1IBLRk (ORCPT ); Fri, 2 Sep 2011 07:17:40 -0400 X-Greylist: delayed 558 seconds by postgrey-1.27 at vger.kernel.org; Fri, 02 Sep 2011 07:17:39 EDT 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 Cc: netdev@vger.kernel.org, Russell King , "David S. Miller" 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> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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; }