Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2326343rdg; Mon, 16 Oct 2023 00:06:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGXGWBLzUOKHGkOWiYn9ECg+0UpqFaq0+NTaftOlktCdpacyRhy7xA4yh/cJN87Dua0C+/E X-Received: by 2002:a05:6a00:1630:b0:6b3:f29c:dde1 with SMTP id e16-20020a056a00163000b006b3f29cdde1mr5197866pfc.21.1697439972931; Mon, 16 Oct 2023 00:06:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697439972; cv=none; d=google.com; s=arc-20160816; b=1GCvwpXcnxx6kZwlYdcdzD318FdVy82nbHHG3gBTKE+kH5oYHNbyS20GhmPvLu91pH +Ln46ErLUdO0q5o/XDhgYyioaBrdICS5JoZFVNrHCgOnlDBQjuHefY1oqAMNi3ivqYk/ 5fT1W0k90kYe4MODQUUO+qVIoAZjVhFYMVz6EonLvM/4YWissdEcWvDe7ZEVYgoWhIfa 4eRahlmkxlc6AQ4JqsY0Lq6GDTEJicMCupQ6bWraw2XF0eDBlHiw5m5kKGU1cbuONE7i bQD2RDmWR5x0N3LfNS9pTuePw3QIbBDrchRXMgLqlBiBStqdp49SBsRW4fX6Rkvi/4yv oh3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=Bdeq/1WECB0lHiYdMNjawiZICAsk0g59tiMZIlxuisY=; fh=dddrWTLl0Wv7eVIBTNUT/fZDLScOYMT+MxzGct56FbM=; b=JUiwmzy2r9A0Bap1c8NhpVkFHjRFfuiIiFzTfzXyvEuI2w0TFCL5GfmTAm676UVJF6 r8kljUuQ24zKzyJP0K0UmAaAxSr/r5hR5G4lBNnlLjsggxV6gF3/HqTC8xaadza1hzVU u3SJ1jsUQkkh7OlZpEhwWCbTTdgPr6EOujKjaPDEk2h4a/YEXE6xZI7eOz2QcCZS6yMs wtUkkZirLWlTdlu/rncbYK6oER/x09JBIOEAEL8G50A1p1yYtfjY0BpPNGPigGZE+wcr YUMf/L04MgiOqIKnuOrpyfRrwuNe6TPz/BqN4uDGZD/PnZPNg7dplLKTf2LqHYEQR+p8 PJtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id h131-20020a636c89000000b0056ad01ddc36si9610599pgc.509.2023.10.16.00.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 00:06:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id BA3E48075DFE; Mon, 16 Oct 2023 00:05:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229953AbjJPHFk (ORCPT + 99 others); Mon, 16 Oct 2023 03:05:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231841AbjJPHFh (ORCPT ); Mon, 16 Oct 2023 03:05:37 -0400 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 629E3D9; Mon, 16 Oct 2023 00:05:35 -0700 (PDT) Received: by verein.lst.de (Postfix, from userid 2407) id 6A2B468AA6; Mon, 16 Oct 2023 09:05:31 +0200 (CEST) Date: Mon, 16 Oct 2023 09:05:31 +0200 From: Christoph Hellwig To: Milan Broz Cc: linux-scsi@vger.kernel.org, jejb@linux.ibm.com, martin.petersen@oracle.com, hch@lst.de, linux-kernel@vger.kernel.org Subject: Re: [PATCH] scsi: use ATA-12 pass-thru for OPAL as fallback Message-ID: <20231016070531.GA28537@lst.de> References: <20231016070211.39502-1-gmazyland@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231016070211.39502-1-gmazyland@gmail.com> User-Agent: Mutt/1.5.17 (2007-11-01) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 16 Oct 2023 00:05:55 -0700 (PDT) On Mon, Oct 16, 2023 at 09:02:11AM +0200, Milan Broz wrote: > All common USB/SATA or USB/NVMe adapters I tested need this patch. > > In short, these steps are run for OPAL support check: > 1) Storage driver enables security driver flag (security_supported). > USB-attached storage drivers will enable it in a separate patchset. > SCSI and NNVMe drivers do it already. If the flag is not enabled, > no following steps are run, and OPAL remains disabled. > 2) SCSI device enumerates SECURITY IN/OUT command support. If detected, > SECURITY ON/OUT wrapper is used (as in the current code). > If not, new ATA-12 pass-thru wrapper is used instead. > 3) SED OPAL code tries OPAL discovery command for the device. > If it receives a correct reply, OPAL is enabled for the device. > If SCSI SECURITY or ATA-12 command with discovery command is rejected, > OPAL remains disabled. > > Note, USB attached storage needs an additional patchset sent separately > as requested by USB driver maintainers (it contains required changes > related to USB quirk processing). This just feels wrong. These adapters are broken if they can't translated, and we should not put ATA command submission into sd.c. > + cdb[0] = ATA_12; > + cdb[1] = (send ? 5 /* ATA_PROTOCOL_PIO_DATA_IN */ : 4 /* ATA_PROTOCOL_PIO_DATA_OUT */) << 1; > + cdb[2] = 2 /* t_length */ | (1 << 2) /* byt_blok */ | ((send ? 0 : 1) << 3) /* t_dir */; > + cdb[3] = secp; > + put_unaligned_le16(len / 512, &cdb[4]); > + put_unaligned_le16(spsp, &cdb[6]); > + cdb[9] = send ? 0x5e /* ATA_CMD_TRUSTED_SND */: 0x5c /* ATA_CMD_TRUSTED_RCV */; Also avoid all these crazy long lines, and please use the actual constants. Using a good old if/else is actually a very good way to structure the code in a somewhat readable way. > + if (sdkp->security) > + sdkp->opal_dev = init_opal_dev(sdkp, &sd_sec_submit); > + else > + sdkp->opal_dev = init_opal_dev(sdkp, &sd_ata12_submit); Messed up indentation here. besides the fact that the statement is fundamentally wrong and you'll start sending ATA command to random devices.