From: Shuah Khan <skhan@linuxfoundation.org>
To: valentina.manea.m@gmail.com, shuah@kernel.org,
gregkh@linuxfoundation.org, keescook@chromium.org,
peterz@infradead.org
Cc: Shuah Khan <skhan@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 10/13] usb: usbip/vhci: convert seqno to seqnum_ops
Date: Tue, 10 Nov 2020 12:53:36 -0700 [thread overview]
Message-ID: <712082d8bd92cab57865b65d853b3206c004a92c.1605027593.git.skhan@linuxfoundation.org> (raw)
In-Reply-To: <cover.1605027593.git.skhan@linuxfoundation.org>
seqnum_ops api is introduced to be used when a variable is used as
a sequence/stat counter and doesn't guard object lifetimes. This
clearly differentiates atomic_t usages that guard object lifetimes.
seqnum32 variables wrap around to INT_MIN when it overflows and
should not be used to guard resource lifetimes, device usage and
open counts that control state changes, and pm states.
Convert it to use seqnum_ops. This conversion replaces inc_return()
with _inc() followed by _read().
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
---
drivers/usb/usbip/vhci.h | 3 ++-
drivers/usb/usbip/vhci_hcd.c | 9 ++++++---
drivers/usb/usbip/vhci_rx.c | 3 ++-
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
index 5659dce1526e..cb76747f423b 100644
--- a/drivers/usb/usbip/vhci.h
+++ b/drivers/usb/usbip/vhci.h
@@ -15,6 +15,7 @@
#include <linux/usb.h>
#include <linux/usb/hcd.h>
#include <linux/wait.h>
+#include <linux/seqnum_ops.h>
struct vhci_device {
struct usb_device *udev;
@@ -108,7 +109,7 @@ struct vhci_hcd {
unsigned resuming:1;
unsigned long re_timeout;
- atomic_t seqnum;
+ struct seqnum32 seqnum;
/*
* NOTE:
diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
index 66cde5e5f796..0d854d9707e5 100644
--- a/drivers/usb/usbip/vhci_hcd.c
+++ b/drivers/usb/usbip/vhci_hcd.c
@@ -11,6 +11,7 @@
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
+#include <linux/seqnum_ops.h>
#include "usbip_common.h"
#include "vhci.h"
@@ -665,7 +666,8 @@ static void vhci_tx_urb(struct urb *urb, struct vhci_device *vdev)
spin_lock_irqsave(&vdev->priv_lock, flags);
- priv->seqnum = atomic_inc_return(&vhci_hcd->seqnum);
+ seqnum32_inc(&vhci_hcd->seqnum);
+ priv->seqnum = seqnum32_read(&vhci_hcd->seqnum);
if (priv->seqnum == 0xffff)
dev_info(&urb->dev->dev, "seqnum max\n");
@@ -921,7 +923,8 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
return -ENOMEM;
}
- unlink->seqnum = atomic_inc_return(&vhci_hcd->seqnum);
+ seqnum32_inc(&vhci_hcd->seqnum);
+ unlink->seqnum = seqnum32_read(&vhci_hcd->seqnum);
if (unlink->seqnum == 0xffff)
pr_info("seqnum max\n");
@@ -1181,7 +1184,7 @@ static int vhci_start(struct usb_hcd *hcd)
vdev->rhport = rhport;
}
- atomic_set(&vhci_hcd->seqnum, 0);
+ seqnum32_set(&vhci_hcd->seqnum, 0);
hcd->power_budget = 0; /* no limit */
hcd->uses_new_polling = 1;
diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
index 266024cbb64f..0d0def7ccfee 100644
--- a/drivers/usb/usbip/vhci_rx.c
+++ b/drivers/usb/usbip/vhci_rx.c
@@ -5,6 +5,7 @@
#include <linux/kthread.h>
#include <linux/slab.h>
+#include <linux/seqnum_ops.h>
#include "usbip_common.h"
#include "vhci.h"
@@ -68,7 +69,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
if (!urb) {
pr_err("cannot find a urb of seqnum %u max seqnum %d\n",
pdu->base.seqnum,
- atomic_read(&vhci_hcd->seqnum));
+ seqnum32_read(&vhci_hcd->seqnum));
usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
return;
}
--
2.27.0
next prev parent reply other threads:[~2020-11-10 19:55 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-10 19:53 [PATCH 00/13] Introduce seqnum_ops Shuah Khan
2020-11-10 19:53 ` [PATCH 01/13] seqnum_ops: Introduce Sequence Number Ops Shuah Khan
2020-11-10 20:41 ` Greg KH
2020-11-10 20:43 ` Greg KH
2020-11-11 0:18 ` Kees Cook
2020-11-11 19:23 ` Shuah Khan
2020-11-12 12:36 ` Matthew Wilcox
2020-11-12 16:17 ` Shuah Khan
2020-11-12 16:45 ` Greg KH
2020-11-12 16:59 ` Shuah Khan
2020-11-12 21:27 ` Shuah Khan
2020-11-17 12:27 ` Peter Zijlstra
2020-11-10 21:03 ` Matthew Wilcox
2020-11-10 22:58 ` Shuah Khan
2020-11-11 0:20 ` Kees Cook
2020-11-11 15:42 ` Shuah Khan
2020-11-11 8:23 ` Peter Zijlstra
2020-11-11 15:56 ` Shuah Khan
2020-11-11 16:04 ` Peter Zijlstra
2020-11-11 17:34 ` Shuah Khan
2020-11-11 17:50 ` Peter Zijlstra
2020-11-11 18:28 ` Shuah Khan
2020-11-11 20:15 ` Peter Zijlstra
2020-11-12 13:29 ` Greg KH
2020-11-10 19:53 ` [PATCH 02/13] selftests:lib:test_seqnum_ops: add new test for seqnum_ops Shuah Khan
2020-11-10 19:53 ` [PATCH 03/13] drivers/acpi: convert seqno seqnum_ops Shuah Khan
2020-11-10 19:53 ` [PATCH 04/13] drivers/acpi/apei: convert seqno to seqnum_ops Shuah Khan
2020-11-10 19:53 ` [PATCH 05/13] drivers/base/test/test_async_driver_probe: convert to use seqnum_ops Shuah Khan
2020-11-10 19:53 ` [PATCH 06/13] drivers/char/ipmi: convert stats " Shuah Khan
2020-11-10 19:53 ` [PATCH 07/13] drivers/edac: convert pci counters to seqnum_ops Shuah Khan
2020-11-10 19:53 ` [PATCH 08/13] drivers/oprofile: convert stats to use seqnum_ops Shuah Khan
2020-11-10 19:53 ` [PATCH 09/13] drivers/staging/rtl8723bs: " Shuah Khan
2020-11-10 19:53 ` Shuah Khan [this message]
2020-11-10 19:53 ` [PATCH 11/13] drivers/staging/rtl8188eu: " Shuah Khan
2020-11-10 19:53 ` [PATCH 12/13] drivers/staging/unisys/visorhba: " Shuah Khan
2020-11-10 20:42 ` Greg KH
2020-11-10 21:02 ` Shuah Khan
2020-11-10 19:53 ` [PATCH 13/13] security/integrity/ima: converts stats to seqnum_ops Shuah Khan
2020-11-10 20:44 ` [PATCH 00/13] Introduce seqnum_ops Alan Stern
2020-11-10 22:42 ` Shuah Khan
2020-11-11 4:33 ` Matthew Wilcox
2020-11-11 16:03 ` Shuah Khan
2020-11-11 16:41 ` Matthew Wilcox
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=712082d8bd92cab57865b65d853b3206c004a92c.1605027593.git.skhan@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=shuah@kernel.org \
--cc=valentina.manea.m@gmail.com \
/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).