Wed Aug 9 08:38:47 2023 UTC ()
xvif(4): Omit needless membars in xennetback_rx_copy_process.

- No need for barrier around touching req_cons and rsp_prod_pvt,
  which are private.

- RING_PUSH_RESPONSES_AND_CHECK_NOTIFY updates the shared req_prod and
  then issues xen_mb, which is all that we need between the update of
  shared req_prod and hypervisor_notify_via_evtchn.

  (Between updating the shared req_prod and issuing
  hypervisor_notify_via_evtchn, only xen_wmb is needed.  But after
  writing to the shared req_prod, RING_PUSH_REQUESTS_AND_CHECK_NOTIFY
  must also read from the shared rsp_event, which requires the
  store-before-load ordering that only xen_mb provides.)


(riastradh)
diff -r1.121 -r1.122 src/sys/arch/xen/xen/xennetback_xenbus.c

cvs diff -r1.121 -r1.122 src/sys/arch/xen/xen/xennetback_xenbus.c (expand / switch to unified diff)

--- src/sys/arch/xen/xen/xennetback_xenbus.c 2023/08/09 08:38:37 1.121
+++ src/sys/arch/xen/xen/xennetback_xenbus.c 2023/08/09 08:38:47 1.122
@@ -1,41 +1,41 @@ @@ -1,41 +1,41 @@
1/* $NetBSD: xennetback_xenbus.c,v 1.121 2023/08/09 08:38:37 riastradh Exp $ */ 1/* $NetBSD: xennetback_xenbus.c,v 1.122 2023/08/09 08:38:47 riastradh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2006 Manuel Bouyer. 4 * Copyright (c) 2006 Manuel Bouyer.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27#include <sys/cdefs.h> 27#include <sys/cdefs.h>
28__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.121 2023/08/09 08:38:37 riastradh Exp $"); 28__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.122 2023/08/09 08:38:47 riastradh Exp $");
29 29
30#include <sys/types.h> 30#include <sys/types.h>
31#include <sys/param.h> 31#include <sys/param.h>
32#include <sys/systm.h> 32#include <sys/systm.h>
33#include <sys/kmem.h> 33#include <sys/kmem.h>
34#include <sys/queue.h> 34#include <sys/queue.h>
35#include <sys/kernel.h> 35#include <sys/kernel.h>
36#include <sys/mbuf.h> 36#include <sys/mbuf.h>
37#include <sys/protosw.h> 37#include <sys/protosw.h>
38#include <sys/socket.h> 38#include <sys/socket.h>
39#include <sys/ioctl.h> 39#include <sys/ioctl.h>
40#include <sys/errno.h> 40#include <sys/errno.h>
41#include <sys/device.h> 41#include <sys/device.h>
@@ -1014,34 +1014,32 @@ xennetback_ifstart(struct ifnet *ifp) @@ -1014,34 +1014,32 @@ xennetback_ifstart(struct ifnet *ifp)
1014static void 1014static void
1015xennetback_rx_copy_process(struct ifnet *ifp, struct xnetback_instance *xneti, 1015xennetback_rx_copy_process(struct ifnet *ifp, struct xnetback_instance *xneti,
1016 int queued, int copycnt) 1016 int queued, int copycnt)
1017{ 1017{
1018 int notify; 1018 int notify;
1019 struct xnetback_xstate *xst; 1019 struct xnetback_xstate *xst;
1020 1020
1021 if (xennetback_copy(ifp, xneti->xni_gop_copy, copycnt, "Rx") != 0) { 1021 if (xennetback_copy(ifp, xneti->xni_gop_copy, copycnt, "Rx") != 0) {
1022 /* message already displayed */ 1022 /* message already displayed */
1023 goto free_mbufs; 1023 goto free_mbufs;
1024 } 1024 }
1025 1025
1026 /* update pointer */ 1026 /* update pointer */
1027 xen_rmb(); 
1028 xneti->xni_rxring.req_cons += queued; 1027 xneti->xni_rxring.req_cons += queued;
1029 xneti->xni_rxring.rsp_prod_pvt += queued; 1028 xneti->xni_rxring.rsp_prod_pvt += queued;
1030 RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&xneti->xni_rxring, notify); 1029 RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&xneti->xni_rxring, notify);
1031 1030
1032 /* send event */ 1031 /* send event */
1033 if (notify) { 1032 if (notify) {
1034 xen_rmb(); 
1035 XENPRINTF(("%s receive event\n", 1033 XENPRINTF(("%s receive event\n",
1036 xneti->xni_if.if_xname)); 1034 xneti->xni_if.if_xname));
1037 hypervisor_notify_via_evtchn(xneti->xni_evtchn); 1035 hypervisor_notify_via_evtchn(xneti->xni_evtchn);
1038 } 1036 }
1039 1037
1040free_mbufs: 1038free_mbufs:
1041 /* now that data was copied we can free the mbufs */ 1039 /* now that data was copied we can free the mbufs */
1042 for (int j = 0; j < queued; j++) { 1040 for (int j = 0; j < queued; j++) {
1043 xst = &xneti->xni_xstate[j]; 1041 xst = &xneti->xni_xstate[j];
1044 if (xst->xs_loaded) { 1042 if (xst->xs_loaded) {
1045 bus_dmamap_unload(xneti->xni_xbusd->xbusd_dmat, 1043 bus_dmamap_unload(xneti->xni_xbusd->xbusd_dmat,
1046 xst->xs_dmamap); 1044 xst->xs_dmamap);
1047 xst->xs_loaded = false; 1045 xst->xs_loaded = false;