Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2033369rwd; Thu, 15 Jun 2023 20:46:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7/YkqGckzoxHLBhanz8KzG2d3Asjg3EhVIyqqHye9iz9oHes5fAauBgjSdBFBC+ZcApp8E X-Received: by 2002:a54:4805:0:b0:39c:944e:1a6b with SMTP id j5-20020a544805000000b0039c944e1a6bmr904230oij.57.1686887214290; Thu, 15 Jun 2023 20:46:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686887214; cv=none; d=google.com; s=arc-20160816; b=PwRMKxK7uX1HlcKK5t7nZqHkqaWcIx1PtvpmqoCtW2k9rnnWL+V0bld+JGYWg8C4+F n/Jvd7iELf0BJuK9vUXHEjQUh2jAFrtmMxf0mF8fqkHRztvjsF/P5v1xBK61GCRBLPfa Ml/iTfm5RYTuKf//TLot7ad+CvNiUarJrd6aD4XUV+b4+i8r/GxybVCvqLlJcmXWQUMg 01bN/SptGCu0t97F3dPQlsazLaFwlJcbamnbSbRWj0kgm5De/PHEKAu6RiePbPghEm5Q R2tTmYw3bm+N+HphWSVhlxzgUvt1ecP6jUtadwHm1iEp+EMV4dajTd62si/gMu5hxNo3 vVaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=o7zLa5fRTN/RtmSvcUQ0HebZNyQL1X00X12foM68gMs=; b=usYCM6HCQwgOXBrWojFsAOCT7MQKXP7JaqozjULa4FI7HKc5xN7C3/eNDgrMu3mIin IT9r8lhvXI3UvKojJJWvirOES7dbtHojPp3O49DWkvNWUIygOiv0iLdrZ2ax/8boEjJF w7xKwyKqvZ9VNYS7uZ919kN45YxKyoPHNe5NEXyYyqQDRIW9wBcy1HC7x1N/rvHUKSfK MW9P92Qj3VeBTPv9K1nD0d5J3A/iHcx+i7TBEfqoDDTzVbCYQd1HPuK/pc9ZPyKmIKTH 1ZLo7F9gmAl+WXb7PUEHzTo5r2t2sqwwh7Z95R2Ar25eabfu6oYJ83DgrRYmbCbXexAe 19eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dwTMP8ZK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z14-20020a17090a66ce00b00256001d8f68si767198pjl.2.2023.06.15.20.46.41; Thu, 15 Jun 2023 20:46:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dwTMP8ZK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242028AbjFPDQH (ORCPT + 99 others); Thu, 15 Jun 2023 23:16:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242054AbjFPDPJ (ORCPT ); Thu, 15 Jun 2023 23:15:09 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A030F1FD7; Thu, 15 Jun 2023 20:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686885298; x=1718421298; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=o7zLa5fRTN/RtmSvcUQ0HebZNyQL1X00X12foM68gMs=; b=dwTMP8ZK5iVpnYNeSbvJZ23050JTHCK7uUpsiz1ml8xIbL2YPmArMXXr g9UrysWBENqhlGazrOYrysXQN51l9PcwO34utWIsgL7zct+CmL1KEfAyQ Qrco9tOxvMfyzhyGh+9mB3l9T74aTDzi7UMsr4Hif8GZqnla9XnL9l4ee SksBsTkSWy0ISamgO+jWn2QAxVRbNLlJS27dK4QZDHvWnXMWhK2oFhe/C O5v6dB7GvBee3xoMIQgM/q7IpJIwd64TwaEwUAT3C35hcaLmkyEA1MlXK YPU7DXzJrBVhJLYgoiA26q1BVhuf4doRSeNuQOqVxKtKKlScDGEAlK2kZ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="445484187" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="445484187" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 20:14:58 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="745966001" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="745966001" Received: from ckale-mobl1.amr.corp.intel.com (HELO desk) ([10.212.176.170]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 20:14:57 -0700 Date: Thu, 15 Jun 2023 20:14:47 -0700 From: Pawan Gupta To: Phillip Potter Cc: linux-kernel@vger.kernel.org, jordyzomer@google.com, linux-block@vger.kernel.org Subject: Re: [PATCH v2 1/1] cdrom: Fix spectre-v1 gadget Message-ID: <20230616031447.yslq6ep7lxe6sjv4@desk> References: <20230612110040.849318-1-jordyzomer@google.com> <20230612110040.849318-2-jordyzomer@google.com> <20230615163125.td3aodpfwth5n4mc@desk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 16, 2023 at 12:31:50AM +0100, Phillip Potter wrote: > I've now looked at this. It is possible for cdi->capacity to be > 1, as > it is set via get_capabilities() -> cdrom_number_of_slots(), if the > device is an individual or cartridge changer. Ohk. Is there an upper limit to cdi->capacity? If not, we are left with barrier_nospec(). > Therefore, I think using CDI_MAX_CAPACITY of 1 is not the correct > approach. Jordy's V2 patch is fine therefore, but perhaps using > array_index_nospec() with cdi->capacity is still better than a > do/while loop from a performance perspective, given it would be cached > etc. at that point, so possibly quicker. Thoughts? (I'm no expert on > spectre-v1 I'll admit). array_index_nospec() can only clip the arg correctly if the upper bound is correct. Problem with array_index_nospec(arg, cdi->capacity) is cdi->capacity is not a constant, so it suffers from the same problem as arg i.e. cdi->capacity could also be speculated. Although having to control 2 loads makes the attack difficult, but does not rules out completely. barrier_nospec() makes the CPU wait for all previous loads to retire before executing following instructions speculatively. This causes the conditional branch to resolve correctly. I hope this does not fall into a hotpath.