Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2647559rwd; Fri, 16 Jun 2023 06:33:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ77TAXbKv1DdBV1E+MhWWHYPXo6A3dntEnZCoFpIA89mUkWVTwneN12mGg35ulpwHil9txb X-Received: by 2002:a05:6a00:b92:b0:659:7d45:a52c with SMTP id g18-20020a056a000b9200b006597d45a52cmr2466301pfj.30.1686922400955; Fri, 16 Jun 2023 06:33:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686922400; cv=none; d=google.com; s=arc-20160816; b=WjewQFdAsFnrC+e3pLAkq2oyJxDgea7VjME4NKB4ZJEOC7IMp99ESUub/6p/lPHcXt VcK0SR8kaPspHl4dI5nVRXjuk2RZXpXHrYdiTkPpPbfH/kNTMm4d4/3ODmfEtsYiTn5X RNYFGRNtiBNm6gGcC/NXEurqila0EHW6sez9TfILzobXPRoVpdtu+uU9/67uWa9Ydzs/ XBi4Kf/QOu8YyNZuH6dHUa93PvgUYISgjGdnXMo7Ieco8XGoRnQLmFWDu1xLexKcftDm 9H6TmRsaPAgMz6U909D9Bxzki5ogsJsacAWt2+iReQj6g2nj40OJigQeKrSBwLs8xmHh gTqA== 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:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=xc0rFww4DDidrWoBZkAi7FUYLAiSH50b8oCJnfR9dZ4=; b=wQGUHtoyt/l2A0gswdYh367PJ/nAJHv/7wwlZdntRdSGIBBVa/3qRds7mixBf/tp0/ u+tjWiwBFcMRnwwgIyvXqdVhEcTtS+fMalYgZUs8o+F2ge8hjDOE3b+qlZx3P3Vdmz3U sly+lsgPgwXRXmWVPVpuNr/tLSy3vlqpOH6kqPld3TzXdP4gxN+PkfybdzXsJKNyGcHu jyq73/UhM8c6N6rDVHDLPXqvVmnE8f09Yg+geT+1jPrb6JEwMJbJcgY+LKRq64zxhdKm kHUbGkW7D1UEFg83lbMoYApF37zAYNVjJvzqnInemCyYaN41lmk7vzuLcvPfOk0jkNoB JwFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=j2z5IAKH; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x27-20020aa78f1b000000b0065b4e2b52c6si15289756pfr.341.2023.06.16.06.33.07; Fri, 16 Jun 2023 06:33:20 -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=@infradead.org header.s=bombadil.20210309 header.b=j2z5IAKH; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345011AbjFPM71 (ORCPT + 99 others); Fri, 16 Jun 2023 08:59:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232489AbjFPM70 (ORCPT ); Fri, 16 Jun 2023 08:59:26 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33EA83581; Fri, 16 Jun 2023 05:59:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Sender:Reply-To:Content-ID:Content-Description; bh=xc0rFww4DDidrWoBZkAi7FUYLAiSH50b8oCJnfR9dZ4=; b=j2z5IAKHx+iYyWyLz2HFE50zJ/ Jhh4tgKe4YJEQr6oI0WEHTxShrKgtDl8stsJaY/dOoZ9vna81ZCN4XwQplvFkW8/haHb6omkttGT+ UpOAo65ikQVFI1E7A47AistDWYV+VSIJUM2w8KE3GAzCu0tRCkBbdT0zscpvs6e5krwZNRZCe9RZe uTQhd7AkCWHdwfHmX69TV0jzW+xKMUcdOdy4WIDRHcssEkkCVFZz3UGQKXanUtM8VAAAcZB3SgLu5 FPAxg7yRIIpo4TFPZIHwX+GMBJm0AR/zz7RKHRFhztKcC9TsW/wysILWTFx6leAC4utwq81CNMGZ1 blemVp9Q==; Received: from [2601:1c2:980:9ec0::2764] by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qA92m-000crn-1T; Fri, 16 Jun 2023 12:59:12 +0000 Message-ID: Date: Fri, 16 Jun 2023 05:59:11 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 Subject: Re: [PATCH v2 1/1] cdrom: Fix spectre-v1 gadget Content-Language: en-US To: Jordy Zomer , Pawan Gupta Cc: Phillip Potter , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org References: <20230612110040.849318-1-jordyzomer@google.com> <20230612110040.849318-2-jordyzomer@google.com> <20230615163125.td3aodpfwth5n4mc@desk> <20230616031447.yslq6ep7lxe6sjv4@desk> From: Randy Dunlap In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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 6/16/23 02:39, Jordy Zomer wrote: > Thanks for the explanation Pawan, a little bit off-topic for this patch but > shall I send a patch to add this to the documentation of array_index_nospec() > and fix other calls to that function where the upper bound is not a constant? :) > Yes, please. We don't want to lose that info. Thanks. > On Fri, Jun 16, 2023 at 5:15 AM Pawan Gupta > wrote: >> >> 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. -- ~Randy