linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Milan Broz <gmazyland@gmail.com>
To: linux-usb@vger.kernel.org
Cc: usb-storage@lists.one-eyed-alien.net, linux-scsi@vger.kernel.org,
	stern@rowland.harvard.edu, gregkh@linuxfoundation.org,
	oneukum@suse.com, Milan Broz <gmazyland@gmail.com>
Subject: [PATCH 0/7] usb-storage,uas: Support OPAL commands on USB attached devices.
Date: Mon, 16 Oct 2023 09:25:57 +0200	[thread overview]
Message-ID: <20231016072604.40179-1-gmazyland@gmail.com> (raw)
In-Reply-To: <20231006125445.122380-1-gmazyland@gmail.com>

This patchset adds support for OPAL commands (self-encrypted drives)
through USB-attached storage (usb-storage and UAS drivers).

The related SCSI change was sent in a separate patch
https://lore.kernel.org/linux-scsi/20231016070211.39502-1-gmazyland@gmail.com/

The first part (64-bit quirks) is generic and will be needed later anyway
once new flags appear.

1) Patches 1-5 only add support for 64-bit quirks for USB storage
(unfortunately, USB device info can be 32-bit on 32-bit platforms,
and we are out of space for flags now).

2) Patches 6-7 enable OPAL commands on USB devices and adds
IGNORE_OPAL quirk. The last patch uses the flag for Realtek 9210
devices that do not behave correctly.

More info

1) 64bit USB storage quirk flags

The quirks are transferred through the device info value, which
is unsigned long (and as a part of USB infrastructure, it cannot
be changed).
After discussion on the USB list, I used high bit as an indicator
that the values need to be translated/unpacked to 64bit
(while lower values are used directly).

This is implemented through a host-compiled program that
generates device tables and uses a translation function.
As both usb-storage and UAS drivers share a lot of headers and
definitions, we need to generate separate files for usb-storage
and UAS. Note that due to the linking of both UAS and mass-storage
together, it must use separate names for translation tables.

(I also tried to use a statically generated array for flags,
but this increased the size of drivers significantly and
the code was quite ugly...)

2) Support for OPAL on USB attached storage.

The main support for OPAL on USB-attached storage is
straightforward (it depends on ATA-12 pass-thru support
for security commands).
Patch 6 enables the SCSI security flag for USB mass storage
and UAS device by default.

During device detection, the USB driver (mass-storage, UAS) enables
the security driver flag to allow SED OPAL code to run OPAL discovery
command for the device. If it receives a correct reply, OPAL is enabled
for the device. If not (or if SCSI command is rejected), OPAL
remains disabled.

Enabling OPAL support may uncover many issues, as OPAL-locked devices
often tend to generate errors on the locked range.

Anyway, cryptsetup will soon support OPAL devices, and I think support
for USB devices is a nice feature that enables users to unlock drives
even if they are attached through USB adapters.

There are also bugs in firmware implementations, so I added a quirk
flag that can disable security commands for particular devices.

The last patch uses this quirk for Realtek 9210, which seems to support
OPAL commands, but after configuring OPAL locking range, it also sets
the write-protected flag for the whole device.
This is perhaps a bug in firmware (all versions I tried), and I will
report that later to Realtek.


Milan Broz (7):
  usb-storage: remove UNUSUAL_VENDOR_INTF macro
  usb-storage,uas: make internal quirks flags 64bit
  usb-storage: use fflags index only in usb-storage driver
  usb-storage,uas: use host helper to generate driver info
  usb-storage,uas: do not convert device_info for 64-bit platforms
  usb-storage,uas: enable security commands for USB-attached storage
  usb-storage,uas: disable security commands (OPAL) for RT9210 chip
    family

 .../admin-guide/kernel-parameters.txt         |   2 +
 drivers/usb/storage/Makefile                  |  28 +++
 drivers/usb/storage/alauda.c                  |   2 +-
 drivers/usb/storage/cypress_atacb.c           |   2 +-
 drivers/usb/storage/datafab.c                 |   2 +-
 drivers/usb/storage/ene_ub6250.c              |   2 +-
 drivers/usb/storage/freecom.c                 |   2 +-
 drivers/usb/storage/isd200.c                  |   2 +-
 drivers/usb/storage/jumpshot.c                |   2 +-
 drivers/usb/storage/karma.c                   |   2 +-
 drivers/usb/storage/mkflags.c                 | 235 ++++++++++++++++++
 drivers/usb/storage/onetouch.c                |   2 +-
 drivers/usb/storage/realtek_cr.c              |   2 +-
 drivers/usb/storage/scsiglue.c                |   4 +
 drivers/usb/storage/sddr09.c                  |   2 +-
 drivers/usb/storage/sddr55.c                  |   2 +-
 drivers/usb/storage/shuttle_usbat.c           |   2 +-
 drivers/usb/storage/uas-detect.h              |   6 +-
 drivers/usb/storage/uas.c                     |  29 +--
 drivers/usb/storage/unusual_devs.h            |  11 +
 drivers/usb/storage/unusual_uas.h             |  11 +
 drivers/usb/storage/usb-ids.h                 |  37 +++
 drivers/usb/storage/usb.c                     |  44 ++--
 drivers/usb/storage/usb.h                     |   7 +-
 drivers/usb/storage/usual-tables.c            |  38 +--
 include/linux/usb_usual.h                     |   2 +
 26 files changed, 385 insertions(+), 95 deletions(-)
 create mode 100644 drivers/usb/storage/mkflags.c
 create mode 100644 drivers/usb/storage/usb-ids.h

-- 
2.42.0


  parent reply	other threads:[~2023-10-16  7:26 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-06 12:54 [RFC PATCH 0/6] usb-storage,uas,scsi: Support OPAL commands on USB attached devices Milan Broz
2023-10-06 12:54 ` [RFC PATCH 1/6] usb-storage: remove UNUSUAL_VENDOR_INTF macro Milan Broz
2023-10-06 17:16   ` Alan Stern
2023-10-08 10:28     ` Milan Broz
2023-10-06 12:54 ` [RFC PATCH 2/6] usb-storage: make internal quirks flags 64bit Milan Broz
2023-10-06 17:26   ` Alan Stern
2023-10-06 12:54 ` [RFC PATCH 3/6] usb-storage: use fflags index only in usb-storage driver Milan Broz
2023-10-06 17:35   ` Alan Stern
2023-10-06 12:54 ` [RFC PATCH 4/6] usb-storage,uas: use host helper to generate driver info Milan Broz
2023-10-06 18:44   ` Alan Stern
2023-10-08 10:41     ` Milan Broz
2023-10-08 13:15       ` Alan Stern
2023-10-06 12:54 ` [RFC PATCH 5/6] usb-storage,uas,scsi: allow to pass through security commands (OPAL) Milan Broz
2023-10-06 18:53   ` Alan Stern
2023-10-06 12:54 ` [RFC PATCH 6/6] usb-storage,uas: Disable security commands (OPAL) for RT9210 chip family Milan Broz
2023-10-06 18:57   ` Alan Stern
2023-10-08 10:54     ` Milan Broz
2023-10-16  7:25 ` Milan Broz [this message]
2023-10-16  7:25   ` [PATCH 1/7] usb-storage: remove UNUSUAL_VENDOR_INTF macro Milan Broz
2023-10-16  7:25   ` [PATCH 2/7] usb-storage,uas: make internal quirks flags 64bit Milan Broz
2023-10-21 10:19     ` Greg KH
2023-10-16  7:26   ` [PATCH 3/7] usb-storage: use fflags index only in usb-storage driver Milan Broz
2023-10-21 10:21     ` Greg KH
2023-10-26 10:27       ` Milan Broz
2023-10-16  7:26   ` [PATCH 4/7] usb-storage,uas: use host helper to generate driver info Milan Broz
2023-10-16 18:49     ` Alan Stern
2023-10-26 10:24       ` Milan Broz
2023-10-26 10:16     ` [PATCH v3] " Milan Broz
2023-10-27 15:45       ` Alan Stern
2023-10-28 17:41       ` [PATCH v4] " Milan Broz
2023-10-30 17:40         ` Alan Stern
2023-10-30 18:16           ` Milan Broz
2023-11-03 20:17         ` [PATCH v5] " Milan Broz
2023-11-03 20:30           ` Alan Stern
2023-11-04  8:01             ` Milan Broz
2023-11-04 14:12               ` Alan Stern
2023-11-05 18:20           ` [PATCH v6] " Milan Broz
2024-01-28  1:50             ` Greg KH
2024-01-29 12:15               ` Milan Broz
2023-10-16  7:26   ` [PATCH 5/7] usb-storage,uas: do not convert device_info for 64-bit platforms Milan Broz
2023-10-21 10:21     ` Greg KH
2023-10-21 10:22     ` Greg KH
2023-10-16  7:26   ` [PATCH 6/7] usb-storage,uas: enable security commands for USB-attached storage Milan Broz
2023-10-16  7:26   ` [PATCH 7/7] usb-storage,uas: disable security commands (OPAL) for RT9210 chip family Milan Broz
2023-10-16 17:33   ` [PATCH 0/7] usb-storage,uas: Support OPAL commands on USB attached devices Alan Stern
2023-10-16 17:48     ` Milan Broz

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=20231016072604.40179-1-gmazyland@gmail.com \
    --to=gmazyland@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=oneukum@suse.com \
    --cc=stern@rowland.harvard.edu \
    --cc=usb-storage@lists.one-eyed-alien.net \
    /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).