Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6363445rwb; Mon, 5 Dec 2022 11:12:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf790sFCKWA3Hv2GWH3+21AhU1kfQhTuSi+qswYAEQrM7x5OlxgwKvDHU/UcQKcUEeB7Kx3G X-Received: by 2002:a63:4c01:0:b0:478:b7ab:2f72 with SMTP id z1-20020a634c01000000b00478b7ab2f72mr6079633pga.186.1670267540942; Mon, 05 Dec 2022 11:12:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670267540; cv=none; d=google.com; s=arc-20160816; b=z9FR2/mcv1XwwWtGoVJLxNj8lCSqBV61vaEzjc34ySCRkJtF00IMdRd0yKj8znsw5P pBq6Nax8O0K/MyJsDcX64ZMaY32k1Ha0tDHraKpHeg+sW74K7QV8dkcwgM0iLsxmO32F Fm3k4QTNSVjxNv1V7inX/pRKxHCvewxndWb9qjfwDrVF2uoM0MOI3QM+a47kmAoF3w26 T24A4wFT2chucwatp2tHZwk4jlqTs4ZuqQuQLqqbkyg+tB1BTN3P8xPYv5MOG4odfLb1 7xH7ol4qCZU/s5gtWesPJw/ApgIyPO1FRMqgPD1Psmur4/LFBEzEtGzX/POqdLLU9ueT w6kw== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=oDteMypEpYpY0CiDbGvFEDl48gIcKWjcXZEnNb6r76Y=; b=VWDoaZrVS+yG33GNhhqbgIBXf3J11iZ+er+7UtN5WlxzpN9Zor0QxQ6fQLbVxH50oN EX72UK/DkYaSH1NI5xnq5cLv+LDBIVwTmxh8YLU8fWUEAc1LrWja5yv6tFUwo+oWj1T+ E0tmShNVo6WKKiQdkx6RkbgJjVCeGiwcwqaGSfDzcAE5ZRXtp84WL24A39x1BtT0J+FJ 3nA5t4YhS7hXhVjf7kDQLq2H87GHFFUQv8EbhhtwqyhZ7JPSAUF8Pv28FVpZ1EXNsG2o aiPPe/YFIsYxKv6lV7MiOB763dP/PShscmyovrOprfnGdIc//lWxcBg1lYSZ+rrYyEWB N+6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=cKDSYYzt; 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=QUARANTINE sp=QUARANTINE 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 u15-20020a170902e80f00b00186e8526793si16415450plg.143.2022.12.05.11.12.10; Mon, 05 Dec 2022 11:12:20 -0800 (PST) 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=@zx2c4.com header.s=20210105 header.b=cKDSYYzt; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233277AbiLETE0 (ORCPT + 81 others); Mon, 5 Dec 2022 14:04:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232709AbiLETEX (ORCPT ); Mon, 5 Dec 2022 14:04:23 -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 50E3123EA6; Mon, 5 Dec 2022 11:04:22 -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 E197761300; Mon, 5 Dec 2022 19:04:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EF08C433D6; Mon, 5 Dec 2022 19:04:19 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="cKDSYYzt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1670267058; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oDteMypEpYpY0CiDbGvFEDl48gIcKWjcXZEnNb6r76Y=; b=cKDSYYztUncnpgz7a4ytBhfxGrSYZJQLpGzEUm7tNme//NgWpesMDn2Ig8uWOMo9VwKDzr A6sxXCwW4OT4aDtUGf7XbOJLdTVIcIY0sw1R2oyamOP9bvmPR+7aGY/z+WpYCdEpUW3Bba TnnqdkN95DzYDy4IyphCEAmnvJJ+W30= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id ac339290 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 5 Dec 2022 19:04:18 +0000 (UTC) Date: Mon, 5 Dec 2022 20:04:15 +0100 From: "Jason A. Donenfeld" To: Florian Weimer Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, tglx@linutronix.de, linux-crypto@vger.kernel.org, linux-api@vger.kernel.org, x86@kernel.org, Greg Kroah-Hartman , Adhemerval Zanella Netto , Carlos O'Donell , Arnd Bergmann , Christian Brauner Subject: Re: [PATCH v11 3/4] random: introduce generic vDSO getrandom() implementation Message-ID: References: <20221205020046.1876356-1-Jason@zx2c4.com> <20221205020046.1876356-4-Jason@zx2c4.com> <878rjlr85s.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <878rjlr85s.fsf@oldenburg.str.redhat.com> 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 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 Hi Florian, On Mon, Dec 05, 2022 at 07:56:47PM +0100, Florian Weimer wrote: > * Jason A. Donenfeld: > > > +retry_generation: > > + /* > > + * @rng_info->generation must always be read here, as it serializes @state->key with the > > + * kernel's RNG reseeding schedule. > > + */ > > + current_generation = READ_ONCE(rng_info->generation); > > > + if (unlikely(READ_ONCE(state->generation) != READ_ONCE(rng_info- > > I'm pretty sure you need some sort of barrier here. We have a similar > TM-lite construct in glibc ld.so for locating link maps by address, and > there the compiler performed reordering. > > _dl_find_object miscompilation on powerpc64le > > > I'm not familiar with READ_ONCE, but Documentation/atomic_t.txt suggests > it's a “regular LOAD”, and include/asm-generic/rwonce.h concurs. Do you mean compiler barriers or SMP barriers? > Likewise, the signal safety mechanism needs compiler barriers (signal > fences). READ_ONCE() should prevent the compiler from reordering the read. > I'm also not sure how READ_ONCE realizes atomic 64-bit reads on 32-bit > platforms. i386 can do them in user space via the FPU worst-case (if > the control word hasn't been corrupted). CMPXCHG8B is not applicable > here because it's a read-only mapping. Maybe add a comment at least > about that “strong prevailing wind”? There's read tearing in that case, which isn't super, but perhaps not all together harmful. Jason