Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2470992rdg; Mon, 16 Oct 2023 05:46:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZ+/2A3iRL2sk6jYRblmMdG9HbQ7d8XJo7+y1xnYhdTEFSaT2yFFhOma+FKjZQlFFeLHri X-Received: by 2002:a17:902:ba8c:b0:1c6:28f6:954a with SMTP id k12-20020a170902ba8c00b001c628f6954amr32043896pls.64.1697460391792; Mon, 16 Oct 2023 05:46:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697460391; cv=none; d=google.com; s=arc-20160816; b=S2l6ius+uihxte/BRNB1l9Xf+xavm0Cc42Qqv/Qy5T9ov191go28piS4KkdDBB6Il3 dZXdbLJXu+Hlunl9q44nYGXY1Wu5owrMDidqduegmxKhhzd18FzJee9GVsoYUj5NP2Jy LcSi4CTyJyHZ2s5CAoxhJSTHDDTYNouF2/1b9ykdA6Xdmi3MGqftrhuH54FwyGefuX4E S2hwv7V81EHNSRs4ehqnPzyQHz6CULQfu6P8hadr+TeiwyhF3LMSE7BWglVmpUrftqto yrEnoTuLWyeePuNKIVqMI4izVaN3UXYj2WDwcsuUkEZr7xae/QP4wJpb+b1Dwawqtc+8 X09Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:autocrypt :from:references:cc:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=0FOmIupFfwbmtqNKkRyVeoiyqw11JCFa3LHyfh4EX3o=; fh=BQz/0eWIssDsw5eohYL/2tmvc1Gj/ZwSLCx3u1uy+po=; b=WO1vIaTXYEUL1yE6CAUb/2ivmTVx2f/ZsWcXBakMOAAX6pQiJolvAzRXThaGy20OaK 56br54MKqqhGeAg7+XHUSczadphRh+TCM8mJdpb2BVCkZ/vCBsQ4fl4hIpnnabxijEge sBHJRhk5GFrS/o/Y1+qICefOzwTkIcj64Z7IHdc16UR4Pn9cmrAaKxHV4AE56FJXYVjc h1TubYePJDzMmC+iQq7GmVHUVw3XS0CP2s1toE0jPQbhh6Bi9JAoeoFpghV/X/HP9ETT ZX+6kB9vKuy0Amktu7AgtScGeivNNEHu8n0dubwW2tD2qWfrwb486cOAz8lG01JhCxzc Ojtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=YWuaIFdk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id a17-20020a170902ee9100b001ca22632ea7si5961852pld.213.2023.10.16.05.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 05:46:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=YWuaIFdk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 88AD2805366D; Mon, 16 Oct 2023 05:46:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233390AbjJPMqJ (ORCPT + 99 others); Mon, 16 Oct 2023 08:46:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232094AbjJPMqI (ORCPT ); Mon, 16 Oct 2023 08:46:08 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F6219B; Mon, 16 Oct 2023 05:46:06 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-53d8320f0easo7583367a12.3; Mon, 16 Oct 2023 05:46:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697460364; x=1698065164; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=0FOmIupFfwbmtqNKkRyVeoiyqw11JCFa3LHyfh4EX3o=; b=YWuaIFdkHf/BRXn+WkmQFTV8g1NLu2k2TC2SZApQfGIGQLCbf1BJdV7LJQZFsNlp28 KqI06yyK+nsFPQdeNKTfhmgmgNeIH0xFjppSMBBempKYXqIgfM3n55fNCOo8n7O20Kc4 UcjUqXgORS4O2TVkdtRhlxLq6GG+6fh96EO7WwVXyACgfl9jDzz8PyEytGYxOXYM15oT 0fbHqlkEBr4czmDUGGBIdxdQQq9CqnC7ihi8T0vRjHxDNsSrOyYcyrPltCRP5Zwjs1+S Sl8leiR3mDe71gRgOzKHwtonglMtqlTunufxOagECCbmyU+QDhj3cJU5Bkzibpznjljy Xy4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697460364; x=1698065164; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0FOmIupFfwbmtqNKkRyVeoiyqw11JCFa3LHyfh4EX3o=; b=ENoC7GkOU34hl3dDJnDpKTjY24+V1/oZtlp8toEKi6ZJlutxwa0z7Su57C14EAJhrx K7lHuJBBdAju0kwFZvwoMqZZLQi59UTfxcKX5EIiNXHZf+CXBZ9pPXPEpukLVVsd/BKK 0p+oFAknqKYqT0AQIl+tpG1JlOVJfzvBRQ6/psof0/4dmO3VoXUs+/kh5pEEBd3wM0MC ycbQi3OPzfNYCRB8i4Ozpwna3hjxKrcU+BPqwOImt9lOP4G6vpANkXcmJQlqDWQT8mXd 19yL4XsUDlQ8Naou2uoVTaQBuAATRce8ygutB6aW0F+IeopbWRnVtxR7kSNsfLiuVg5K G8+w== X-Gm-Message-State: AOJu0YwJr8a+y6ms4MfJha2gabKEUBcY/s4qmuXXSXXy4MVsIYTB/JJw r6IMHRs+cPKjJWxnMWtBFA0= X-Received: by 2002:a05:6402:4415:b0:53d:ff0e:df0 with SMTP id y21-20020a056402441500b0053dff0e0df0mr15676856eda.5.1697460364555; Mon, 16 Oct 2023 05:46:04 -0700 (PDT) Received: from [147.251.42.107] (laomedon.fi.muni.cz. [147.251.42.107]) by smtp.gmail.com with ESMTPSA id f18-20020a50a6d2000000b0053e5f67d637sm4408988edc.9.2023.10.16.05.46.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Oct 2023 05:46:04 -0700 (PDT) Message-ID: <5831286b-e3d0-4b87-9c5c-dbcb420d1b67@gmail.com> Date: Mon, 16 Oct 2023 14:46:03 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] scsi: use ATA-12 pass-thru for OPAL as fallback Content-Language: en-US To: Damien Le Moal , Christoph Hellwig Cc: linux-scsi@vger.kernel.org, jejb@linux.ibm.com, martin.petersen@oracle.com, linux-kernel@vger.kernel.org References: <20231016070211.39502-1-gmazyland@gmail.com> <20231016070531.GA28537@lst.de> <0c7f0599-40de-417a-842d-d0aba842d115@kernel.org> From: Milan Broz Autocrypt: addr=gmazyland@gmail.com; keydata= xs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sV6nJyD vktsLTyMW5BW9q4NC1rgQC8GQXjrQ+iyQLNwy5ESe2MzGKkHogxKg4Pvi1wZh9Snr+RyB0Rq rIrzbXhyi47+7wcAEQEAAcLBfAQYAQgAJgIbDBYhBCopGCQ/3kZkjQaG+dmwV3vZPpj8BQJh pRSXBQkk+HAYAAoJENmwV3vZPpj8BPMP/iZV+XROOhs/MsKd7ngQeFgETkmt8YVhb2Rg3Vgp AQe9cn6aw9jk3CnB0ecNBdoyyt33t3vGNau6iCwlRfaTdXg9qtIyctuCQSewY2YMk5AS8Mmb XoGvjH1Z/irrVsoSz+N7HFPKIlAy8D/aRwS1CHm9saPQiGoeR/zThciVYncRG/U9J6sV8XH9 OEPnQQR4w/V1bYI9Sk+suGcSFN7pMRMsSslOma429A3bEbZ7Ikt9WTJnUY9XfL5ZqQnjLeRl 8243OTfuHSth26upjZIQ2esccZMYpQg0/MOlHvuFuFu6MFL/gZDNzH8jAcBrNd/6ABKsecYT nBInKH2TONc0kC65oAhrSSBNLudTuPHce/YBCsUCAEMwgJTybdpMQh9NkS68WxQtXxU6neoQ U7kEJGGFsc7/yXiQXuVvJUkK/Xs04X6j0l1f/6KLoNQ9ep/2In596B0BcvvaKv7gdDt1Trgg vlB+GpT+iFRLvhCBe5kAERREfRfmWJq1bHod/ulrp/VLGAaZlOBTgsCzufWF5SOLbZkmV2b5 xy2F/AU3oQUZncCvFMTWpBC+gO/o3kZCyyGCaQdQe4jS/FUJqR1suVwNMzcOJOP/LMQwujE/ Ch7XLM35VICo9qqhih4OvLHUAWzC5dNSipL+rSGHvWBdfXDhbezJIl6sp7/1rJfS8qPs In-Reply-To: <0c7f0599-40de-417a-842d-d0aba842d115@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 16 Oct 2023 05:46:26 -0700 (PDT) On 10/16/23 13:54, Damien Le Moal wrote: > On 10/16/23 16:24, Milan Broz wrote: >> On 10/16/23 09:05, Christoph Hellwig wrote: >>> 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. >> >> I think it is blocked in USB layer as not running command enumeration, >> SCSI SECURITY will be never sent to the adapter through USB. >> >> I understand the problem, but if you configure OPAL from userspace, ATA-12 is sent >> to these devices already - so why kernel cannot use it too? >> >>> >>>> + 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. >> >> Sure, I was trying to no add additional includes that will mess this up, I'll reformat it if needed. >> >> Otherwise, this wrapper is exactly what is used is sedutils and also in our test utility >> that tries to work with OPAL commands directly >> https://github.com/mbroz/opal-toolset >> >>> >>>> + 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. >> >> sorry, my bad, I hate such formatting myself and missed it here :-) >> >>> besides the fact that the statement is fundamentally wrong and you'll >>> start sending ATA command to random devices. >> >> So what do you suggest? As I said, this exactly happen if you configure it from userspace. >> >> Can this be somehow limited? I did not find and way how to do it. > The translation of SECURITY IN/OUT commands should go into usb uas.c, at the > very least. And even having it there is not great in my opinion. If the adapter > does not support Opal, don't use that feature, or use it only to lock/unlock the > drive from user space with passthrough. I was resisting to support OPAL hw for long time, but once we decided to add it as an additional (and optional) layer for LUKS, I would like it to be supported also for external drives (if technically possible). The problem is that we (for simplicity) decided to use kernel SED-ioctl interface that internally wraps OPAL command to SCSI SECURITY command only. It means, that all devices that can use ATA-12 just cannot work with this kernel interface (unlike userspace which can decide which wrapper to use). And IMO it is not correct - if it was designed only for some servers with directly connected devices, then it is really not generic OPAL support. It should work for any hw that supports it. For USB, it actually works quite nice with the patch (ignoring usual bugs in firmware). > > Note that nowhere in your patch do you test if you are talking to an ATA device. Yes, I know. I expected the command to be rejected if not supported. > This can be done by testing for the existence of VPD page 89h. See > scsi_cdl_enable() in drivers/scsi/scsi.c for an example where we had to check > for that. But also note that we do not issue ATA commands based on that test. We > keep issuing SCSI commands and libata takes care of the translation. uas does > not use libata though, so if translation is needed, do it there. So, you mean translate SCSI SECURITY to ATA-12 inside USB storage drivers? (There are actually two places, UAS driver and then SCSI glue for mass-storage - unfortunately, we need both.) > But I have the same opinion as Christoph: working around USB adapters lack of > support for a feature with passthrough commands issued from the kernel is really > not ideal. Well, I have several adapters and many OPAL drives, none works with SCSI commands if connected through USB. Partially it is missing support in USB layer, but the rest is mess in hw. I know it is **** but that's how it is; people have these and want to use it (including myself). IMO it is quite similar to discard/TRIM support... Thanks, Milan