From: Denis Vlasenko <vda@port.imtp.ilyichevsk.odessa.ua>
To: Francois Romieu <romieu@cogenit.fr>, linux-kernel@vger.kernel.org
Cc: acme@conectiva.com.br, peterd@pnd-pc.demon.co.uk
Subject: Re: [PATCH] cli()/sti() fix for drivers/net/depca.c
Date: Thu, 3 Oct 2002 10:55:23 -0200 [thread overview]
Message-ID: <200210030801.g9381Vp01598@Port.imtp.ilyichevsk.odessa.ua> (raw)
In-Reply-To: <20021003001228.A18629@fafner.intra.cogenit.fr>
On 2 October 2002 20:12, Francois Romieu wrote:
> Denis Vlasenko <vda@port.imtp.ilyichevsk.odessa.ua> :
> [...]
>
> > Ho to do it properly? Make a copy on stack under lock, release
> > lock, proceed with copy_to_user? That's 88 bytes at least...
>
> Please see ETHTOOL_GSTATS usage in drivers/net/8139cp.c.
>
> > > - on SMP, pktStat can be updated while the copy progresses, see
> > > depca_rx().
> >
> > Should I place these pktStat updates under lp->lock?
>
> You may.
It's already under the lock: depca_rx is called from depca_interrupt
which acqures the lock.
New patch attached. Testers with hw wanted ;-)
--
vda
diff -u --recursive linux-2.5.40org/drivers/net/depca.c linux-2.5.40/drivers/net/depca.c
--- linux-2.5.40org/drivers/net/depca.c Tue Oct 1 05:07:01 2002
+++ linux-2.5.40/drivers/net/depca.c Thu Oct 3 10:52:09 2002
@@ -951,6 +951,7 @@
}
+/* Called with lp->lock held */
static int
depca_rx(struct net_device *dev)
{
@@ -1052,6 +1053,7 @@
/*
** Buffer sent - check for buffer errors.
+** Called with lp->lock held
*/
static int
depca_tx(struct net_device *dev)
@@ -1910,6 +1912,7 @@
struct depca_ioctl *ioc = (struct depca_ioctl *) &rq->ifr_data;
int i, status = 0;
u_long ioaddr = dev->base_addr;
+ unsigned long flags;
union {
u8 addr[(HASH_TABLE_LEN * ETH_ALEN)];
u16 sval[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
@@ -1998,19 +2001,27 @@
set_multicast_list(dev);
break;
- case DEPCA_GET_STATS: /* Get the driver statistics */
- cli();
+ case DEPCA_GET_STATS: { /* Get the driver statistics */
+ typeof(lp->pktStats) *tmp_stats =
+ kmalloc(sizeof(lp->pktStats), GFP_KERNEL);
+ if (!tmp_stats) return -ENOMEM;
+
+ spin_lock_irqsave(&lp->lock, flags);
+ memcpy(tmp_stats, &lp->pktStats, sizeof(lp->pktStats));
+ spin_unlock_irqrestore(&lp->lock, flags);
+
ioc->len = sizeof(lp->pktStats);
- if (copy_to_user(ioc->data, &lp->pktStats, ioc->len))
+ if (copy_to_user(ioc->data, tmp_stats, sizeof(lp->pktStats)))
status = -EFAULT;
- sti();
+ kfree(tmp_stats);
break;
+ }
case DEPCA_CLR_STATS: /* Zero out the driver statistics */
if (!capable(CAP_NET_ADMIN)) return -EPERM;
- cli();
+ spin_lock_irqsave(&lp->lock, flags);
memset(&lp->pktStats, 0, sizeof(lp->pktStats));
- sti();
+ spin_unlock_irqrestore(&lp->lock, flags);
break;
case DEPCA_GET_REG: /* Get the DEPCA Registers */
prev parent reply other threads:[~2002-10-03 8:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-03 0:58 [PATCH] cli()/sti() fix for drivers/net/depca.c Denis Vlasenko
2002-10-02 20:40 ` Francois Romieu
2002-10-03 2:26 ` Denis Vlasenko
2002-10-02 22:12 ` Francois Romieu
2002-10-03 12:37 ` Denis Vlasenko
2002-10-03 16:40 ` Francois Romieu
2002-10-03 12:55 ` Denis Vlasenko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200210030801.g9381Vp01598@Port.imtp.ilyichevsk.odessa.ua \
--to=vda@port.imtp.ilyichevsk.odessa.ua \
--cc=acme@conectiva.com.br \
--cc=linux-kernel@vger.kernel.org \
--cc=peterd@pnd-pc.demon.co.uk \
--cc=romieu@cogenit.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).