From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.797.1669137089616348119 for ; Tue, 22 Nov 2022 09:11:29 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=QUJ6C9Qh; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: srs0=2rl2=3w=zx2c4.com=jason@kernel.org) 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 03011617D0 for ; Tue, 22 Nov 2022 17:11:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 264A9C433C1 for ; Tue, 22 Nov 2022 17:11:28 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="QUJ6C9Qh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1669137084; 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=fOKmSE4/iRZoJ+K3C/FuA6Aqqt31iXjIbeB9PpBxzv0=; b=QUJ6C9QhAGgN6xTn9SVCoQcXDxLNZGBf+rNGblyXtXhslPGJN6Sgbl43Nlm+ZiB+MMEtUw etqELOnmeQP7HrG57JwJ95YBbx2Xw9lG3EkrWqrAU9PXJK1/DByOZ3BzoD+Priv6gNcyP4 7yzyk5CywMAa86xWfKsZ6vP+QGZrdu0= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id f1006bc7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 22 Nov 2022 17:11:24 +0000 (UTC) Received: by mail-vs1-f41.google.com with SMTP id 128so15074087vsz.12 for ; Tue, 22 Nov 2022 09:11:24 -0800 (PST) X-Gm-Message-State: ANoB5pm4NG48ZRxMx9eaIVmfYAT6koIJJFbWXqXQ2t9GEhDp1CKtRWJT GTz4C0WuUWYxuO5dkqeSow3hMMypCVMHa6oF6Yo= X-Google-Smtp-Source: AA0mqf79FveqDnKEPvWtqRxO6bic7ypIFlL+SSnDPd0CPIQM4LEA97k7iaxuEsP8r82yx9aiC4mla/XCn8xLSaN8+Lo= X-Received: by 2002:a67:f817:0:b0:3aa:2fb3:dcac with SMTP id l23-20020a67f817000000b003aa2fb3dcacmr4366712vso.55.1669137083827; Tue, 22 Nov 2022 09:11:23 -0800 (PST) MIME-Version: 1.0 References: <20221122153212.570984-1-pedro.falcato@gmail.com> In-Reply-To: From: "Jason A. Donenfeld" Date: Tue, 22 Nov 2022 18:11:12 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/1] MdePkg/BaseRngLib: Add a smoketest for RDRAND and check CPUID To: Pedro Falcato Cc: devel@edk2.groups.io, Michael D Kinney , Liming Gao , Zhiguang Liu Content-Type: text/plain; charset="UTF-8" On Tue, Nov 22, 2022 at 4:56 PM Pedro Falcato wrote: > > On Tue, Nov 22, 2022 at 3:39 PM Jason A. Donenfeld wrote: >> >> On Tue, Nov 22, 2022 at 4:32 PM Pedro Falcato wrote: >> > + // Testing algorithm inspired by linux's arch/x86/kernel/cpu/rdrand.c:x86_init_rdrand >> > + // as relicensed by the author, Jason Donenfeld, in the EDK2 mailing list. >> > + // As is, the algorithm samples rdrand $RDRAND_TEST_SAMPLES times and expects >> > + // a different result $RDRAND_MIN_CHANGE times for reliable RDRAND usage. >> >> You don't need to pepper my name all over the source. :) > > > I just wanted to properly credit you :) If you're not okay with it I can remove it in a v3. Yes, please remove. >> > + for (TestIteration = 0; TestIteration < RDRAND_TEST_SAMPLES; TestIteration++) { >> > + UINT32 Sample; >> > + // >> > + // Note: We use a retry loop for rdrand. Normal users get this in BaseRng.c >> > + // Any failure to get a random number will assume RDRAND does not work. >> > + // >> > + for (Idx = 0; Idx < RDRAND_RETRIES; Idx++) { >> > + if (AsmRdRand32 (&Sample)) { >> >> The linux code will use a 64bit value on 64bit machines. I suggest you >> do the same here -- use native word size. I think EFI calls this a >> "UINTN". > > > Hmm, do you reckon it makes a difference? Yes, it does. Please account for this. Use an ifdef or something if you need. It's not very hard. Jason