Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2333360rdg; Mon, 16 Oct 2023 00:24:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHvHkuveNvrnMg6SEuJjWLdBvr9rEu+RGAiihIc5JOphFWVtmnQuwk6B4EtlMFG/xFCnveq X-Received: by 2002:a05:6358:24a6:b0:134:d617:e2c9 with SMTP id m38-20020a05635824a600b00134d617e2c9mr41406928rwc.29.1697441087621; Mon, 16 Oct 2023 00:24:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697441087; cv=none; d=google.com; s=arc-20160816; b=N4jXIz/xQrgUqWG/7tYw8/tc5NOgeQk4htftgX9dpjnszPDZ+Fyx30uGO5kn9J5La4 asnoQDbTsErbeOo1KRngSBh9U/+TyO0kWf17kVfzXKOqd/PAX7ulBg3mR/g+Q0niPoNz OuocnHTWu7Udheem6Ps/6YY2iopE+6ACer4mC1ETDdMEFg2Zj/FxmWSqFp6l/D1AzgR6 RldWrBc9COIr+SM4oOYwSrFxjaYIBvtfOEdNvJGL9opdra9OaCSNhAUv4UHru/9c5l+l 7pV7+zJ+4LjnAw4dz9O3BqaZc3IezEO/Xankxa1/LsAZziGTdZKPdbKRlyfMDqmMeAAR N9/A== 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:content-language:references:cc:to:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=wSC7zHohO45xUvqiXG5UdWP7+MJE4ZAs27gchq8/dWs=; fh=hzhzAqbQqdhpV7/gQ+5B8wjQPhlnusfY5sGqUKMN9aU=; b=fm1RZ3k6CdtA/rMF6wV4Bs00LIwEJoCqKeGFAX7zfbE0+ouBZnZthqBHS0eFESqmwt l6rdRJp2coI3WV2MtN6a5bRxmYRnQbBggx892Y8CRL4PB9f3hlVk/J275enc0H2QaZD+ mnmwNbcZhRHudqASHK2i839K/XkHQ6iDeftE9joYuna+BfT3cntZgRxOq7ITGzCjYscy zhkGcPVhs8snlvbVgAZ00gnFFg1lDTwTZeF2WtYpFgln9a0rWTrnKlsokcxT3WMQrmN1 ax8CoVP2ReO16Xw6OtnkLlFcZgWSMRCO7aA+7hxlZIoq9fk3DKUbNQ/R68qwe/ZAHG++ rKpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BqCPm7pe; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id w8-20020a63f508000000b00578bea3c10esi10226541pgh.756.2023.10.16.00.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 00:24:47 -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; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BqCPm7pe; 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; 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 morse.vger.email (Postfix) with ESMTP id D27F680C2839; Mon, 16 Oct 2023 00:24:44 -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 S231841AbjJPHYW (ORCPT + 99 others); Mon, 16 Oct 2023 03:24:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229590AbjJPHYV (ORCPT ); Mon, 16 Oct 2023 03:24:21 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B23CBAD; Mon, 16 Oct 2023 00:24:19 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-53dd3f169d8so6962938a12.3; Mon, 16 Oct 2023 00:24:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697441058; x=1698045858; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=wSC7zHohO45xUvqiXG5UdWP7+MJE4ZAs27gchq8/dWs=; b=BqCPm7peQAcvCNhiSP86dSk+6kWGR46/Zv+djxFT8hjXv6epSszeee5CttS6U6tIVQ q+9ocP22/zFu3UbRD5daJptu9lNzWs2GbwRJ7JCODMzaTAwBW1r6ADIuJk77/bhoS8fo Qw0YapQBLOhz9JKcsV/RVrYqLZN8G8y+e/SUT7vCkdPQ7qsn1rOgBvJyQL4pnFBY3MX4 rktGIeFI3W3sIQ+wgJROspNYOU/bn81ip7A7hl4Si1Be5k8+FpBy3XK/BwU5Ra2/X0Gv 5XriI2Lace4SWKTgEBNDowyjTJjFb+Dbd387ZkleQeSXFLMRhlAu/If84IrcWyoiRGJj xyog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697441058; x=1698045858; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=wSC7zHohO45xUvqiXG5UdWP7+MJE4ZAs27gchq8/dWs=; b=bYPvzOZ+BrRs4V1W3iMUsVuGY2JKiDB83uRI3/nIRxIYU3Mnqx0rI//wOA3OqUgWBo ZCeZyyspmOLLzAWHe0/yeGbOSxX91mYv8f1b8yM6PdwpnqVssoiOyJvcdUvIaY2x5ufd Z3iweSNDLLFQPrrXqyHJhZvPzjclgyO3EB+8gqC+VoQa3z4RPev+yowzZImv7bXetyOE YfMOz3DtxtOY3ua6lPgcKRdwDCZOHnQYPHvsj6353PSCg1oUfh5pYKQ/P7Fuk7lHaLQu 5zVuyMHFt94r0KOm9hzZIH5sQSD4K+gEDs4Z0S5X9oI+Wgivyaxz95zhd33uSbYnCw/M 5RFQ== X-Gm-Message-State: AOJu0YxpOyZ6vyHtJXybjPLX+aolv+SXU9+gb3c9DOHkWBsYmtcRYp3F ncoYwQPdOI9L7Q5bIb3b0wc= X-Received: by 2002:a17:907:1c9e:b0:9bd:f031:37b6 with SMTP id nb30-20020a1709071c9e00b009bdf03137b6mr6620155ejc.49.1697441057766; Mon, 16 Oct 2023 00:24:17 -0700 (PDT) Received: from [147.251.42.107] (laomedon.fi.muni.cz. [147.251.42.107]) by smtp.gmail.com with ESMTPSA id 29-20020a170906209d00b0099bc038eb2bsm3399712ejq.58.2023.10.16.00.24.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Oct 2023 00:24:17 -0700 (PDT) Message-ID: Date: Mon, 16 Oct 2023 09:24:16 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] scsi: use ATA-12 pass-thru for OPAL as fallback To: 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> Content-Language: en-US From: Milan Broz Autocrypt: addr=gmazyland@gmail.com; keydata= xsFNBE94p38BEADZRET8y1gVxlfDk44/XwBbFjC7eM6EanyCuivUPMmPwYDo9qRey0J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Kg4Pvi1wZh9Snr+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: <20231016070531.GA28537@lst.de> 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 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:24:45 -0700 (PDT) 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. Milan