Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp226956pxm; Wed, 2 Mar 2022 14:02:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBxUeoBzlPyGuAbpHyQLUR2FtWH3j2ikYhJNoNcuy3ppnt9YlvE2tcxDtxCGEn1MJgoCzu X-Received: by 2002:a17:906:a20c:b0:6ce:a87e:5013 with SMTP id r12-20020a170906a20c00b006cea87e5013mr23567551ejy.379.1646258550195; Wed, 02 Mar 2022 14:02:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646258550; cv=none; d=google.com; s=arc-20160816; b=JD9c0CNTHblITNnEntxVQgkhjalKy/th9uCilnxhL+lSmUSazWhlZBgSYwcIcoDsuU xi/NJeWXWU4NGtsNTM3B59u70+N13i5Wu7tlZOBkOYa1lzLL/yFH+VEJolD76VKeEmxQ cn19QNm2ebnMjw0uQTEh9fOmzKSgFIvSkAPi2/ad/z+mfKrEQTzFn/MHG4+hpOgH2aV8 SKS2qiIJejp3IZJQ4Z24PLg8cXx9Y2YeILn2Zw2/2tVWvT79wVWRV6hgl5gxbCfrl21O xBqrnKQjea5dL3ekZ7wkH/sZAn/oP8g6hUxkDKl5fTthDaLLmcBTqLbj92p6d5wQztip 7wXA== 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=SpVcuA/WXuSF2VylmDTidLRP/fq6dnIG3IJK6i0yAko=; b=o0uFfSwJQGY2n2TY+0BPdGCyLkyN2w+D8qcoZRtSZR5R90m0QW66Dq0+fXYjTsDVTF RZEeN35JRrEkWptaeES1vuCA+JG1i5ea4FM+noXuSLQ2Ty0ko5JCHOa/4WXIS+LBdx8k FhHyAxfi+2O2d0hQ7tORr5mSSv2l61LnFWVof/FMayEPz/hv1E/GCD4VqnC2X+Gbkw5G 84p83WkNvlX4j1JN87LdjMYYZma3eb1T/JvrrRzHEm4NL1W6LTKyIg/Vga5KPqx2RgPP 6C8A9z+IRaxdetQP++u2lOmZFOdpMVjzgprPkIQrEkbYRx5d2kfTymx15FnmuosA5zL6 /6OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=kpzYHDtU; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k6-20020a170906054600b006a79e13f94esi149189eja.294.2022.03.02.14.00.44; Wed, 02 Mar 2022 14:02:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-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=@zx2c4.com header.s=20210105 header.b=kpzYHDtU; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239786AbiCBN4i (ORCPT + 99 others); Wed, 2 Mar 2022 08:56:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234460AbiCBN4f (ORCPT ); Wed, 2 Mar 2022 08:56:35 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 152DF2B18E; Wed, 2 Mar 2022 05:55:44 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9FEF560B13; Wed, 2 Mar 2022 13:55:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB550C004E1; Wed, 2 Mar 2022 13:55:40 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="kpzYHDtU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1646229339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=SpVcuA/WXuSF2VylmDTidLRP/fq6dnIG3IJK6i0yAko=; b=kpzYHDtUAlCnEdVEte//Tt36NxH+/Ez0o+kl3YdWmtGk9TZCjSHm6oGL/AbSTrC8Y1PuRg jZ3NV3d2m9tjm6vre8HArSM79be/kQc4jqSkH3qUrcSXgTDy8VV6MN3iqBxSC6PUytw5x2 eJFYg/LLjTsXb0gq+k1Xln0G4fDjTNE= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id fd2dbd60 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Wed, 2 Mar 2022 13:55:38 +0000 (UTC) Date: Wed, 2 Mar 2022 14:55:29 +0100 From: "Jason A. Donenfeld" To: "Michael S. Tsirkin" Cc: Laszlo Ersek , LKML , KVM list , QEMU Developers , linux-hyperv@vger.kernel.org, Linux Crypto Mailing List , Alexander Graf , "Michael Kelley (LINUX)" , Greg Kroah-Hartman , adrian@parity.io, Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= , Dominik Brodowski , Jann Horn , "Rafael J. Wysocki" , "Brown, Len" , Pavel Machek , Linux PM , Colm MacCarthaigh , Theodore Ts'o , Arnd Bergmann Subject: Re: propagating vmgenid outward and upward Message-ID: References: <223f858c-34c5-3ccd-b9e8-7585a976364d@redhat.com> <20220301121419-mutt-send-email-mst@kernel.org> <20220302031738-mutt-send-email-mst@kernel.org> <20220302074503-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220302074503-mutt-send-email-mst@kernel.org> X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-crypto@vger.kernel.org Hi Michael, On Wed, Mar 02, 2022 at 07:58:33AM -0500, Michael S. Tsirkin wrote: > > There's also the atomicity aspect, which I think makes your benchmark > > not quite accurate. Those 16 bytes could change between the first and > > second word (or between the Nth and N+1th word for N<=3 on 32-bit). > > What if in that case the word you read second doesn't change, but the > > word you read first did? So then you find yourself having to do a > > hi-lo-hi dance. > > And then consider the 32-bit case, where that's even > > more annoying. This is just one of those things that comes up when you > > compare the semantics of a "large unique ID" and "word-sized counter", > > as general topics. (My suggestion is that vmgenid provide both.) > > I don't see how this matters for any applications at all. Feel free to > present a case that would be race free with a word but not a 16 > byte value, I could not imagine one. It's human to err of course. Word-size reads happen all at once on systems that Linux supports, whereas this is not the case for 16 bytes (with a few niche exceptions like cmpxchg16b and such). If you read the counter atomically, you can check to see whether it's changed just after encrypting but before transmitting and not transmit if it has changed, and voila, no race. With 16 bytes, synchronization of that read is pretty tricky (though maybe not all together impossible), because, as I mentioned, the first word might have changed by the time you read a matching second word. I'm sure you're familiar with the use of seqlocks in the kernel for solving a somewhat related problem. Jason