From patchwork Mon Jul 27 15:19:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 247192 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp4892129ilg; Mon, 27 Jul 2020 08:21:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxefuqyRKDbkMlMqwctBYcX/1I2srfE8t1Rslz+JhJIYLJeFNRxoT8NMWdzhHDAY6z/LnnC X-Received: by 2002:a25:31d4:: with SMTP id x203mr35929314ybx.396.1595863317014; Mon, 27 Jul 2020 08:21:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595863317; cv=none; d=google.com; s=arc-20160816; b=Ych+nys1VYZ2YMdY/nOAK46eVYDKb7VVbKOvz1Vq5Fvkvq8+lRswQS89oWTjA0s9Cu RuncP0NxU/eoJtldoVbuFlwYWA2PrArFvnioN3qXy0EeBk/MNGFSl8v5K4senLPTrWad Mnrdh2ZyWUmWFz3V5JBk1leYtTKyljL6yXWCHMTTx9XSI6DAiX/aB0EzDHXJIwskkmVt XynCvezNStRgw+j+2a45Up91/KUtshhlTDuRhuRTeN1NihT9db//Xvyr2s4S/IALeXI6 dah+MKVo9WPS41PIlgGSIr9ZLgOqsoXZ/yG4vvVuzW5pHS8FxfATzleP6Vyo6Hny3M9C z9gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Df26pyr1FoUci06b9bgZLyVGVD2YeeZNhUfL4mWRueY=; b=pezwIrpvF8WW/UAAjyGr6NnKuxxI55/L3J+2sFeeCUy+S3PnvCNGWz58eJHpePFfyf o4crLP+KpDZlOCUWpKITSJWkiq/NWevIAW8a5xXzBacYisphvsSa88nLv3ql8KA29evI kSGMgsmSxnjHhUuKJgPqK5soPeVbqgMK45vBhObJTa7rQ/exL4t9hl1CwHUxKGo+Tiom UFMKCt7+URA/ssWnbQId9aKlXckAFAdkopp3Kzs5vItzuc85r2cQfkl/lduWKkVnLDBP 5QUl1WLRNoX7Yo+/9mr5ReQvklfE9D1u9Js+azla7XzBta7jewPgRaBiskqYQSo0+Gvt LMdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uL8MCJQl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l62si9491971ybb.395.2020.07.27.08.21.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jul 2020 08:21:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uL8MCJQl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k04wu-0004Lk-Eo for patch@linaro.org; Mon, 27 Jul 2020 11:21:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k04uh-0001o5-M8 for qemu-devel@nongnu.org; Mon, 27 Jul 2020 11:19:39 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:34067) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k04uf-0001NP-T8 for qemu-devel@nongnu.org; Mon, 27 Jul 2020 11:19:39 -0400 Received: by mail-wm1-x335.google.com with SMTP id g10so13606087wmc.1 for ; Mon, 27 Jul 2020 08:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Df26pyr1FoUci06b9bgZLyVGVD2YeeZNhUfL4mWRueY=; b=uL8MCJQlncq3jVP207n1hpGBN56b9iLP6py9pa1w75Ls1qKB1pJeUKfe243G3y+wjU RoODpdIT7pRaPSBz1lBLQwFmTJqjvqEZu3JZfloyGnCPuAYS5VbFgD0mvLeI8fYU4NVK /R6DByaYkt18gl/JMzms/M/YOc98hlJDr8JxklxfcQhxjk1ovkQhMTwEchCwJz77EKkE SIKp72GrCuZacC2vi/gGWLdKFO95UdDn+w1Bdy2WFajKhM2U/GDRlZFeufTyv+xz4sOu CJZOOuhmZIwZ4cPog3qZzNidSBgReATUPWqVqrFrqzqqsMMngktOBQVkLXsEshEQNNzy evaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Df26pyr1FoUci06b9bgZLyVGVD2YeeZNhUfL4mWRueY=; b=gCo43rTb2/WeYiKHUPCUojDA0+YcsrLdZp/FQlPGBjRZ/X4gEE0/ueL16binQH4sn8 GJDHtCu5vukNx0yboH5gcEhKspj1fHNJIAtBXZTLhQBj6TqWf1cEqHxY9rZp83Jxjx5b I2fzzTkkytJb7nWLlIEMiD3EOsJSZKgUBOBTvZKGoOsi6MvtV4t5HPnLpNdfmKPgJiUV evkiOIACKrxbi33EisQdA+SDeM7JheeaFXEQ/heApZEz2ObIG7Nk+VioJ/dQUkbYr/WL gR9Q290Os3yLG0oO4kYnHN8l37LdtSm4e2Gtp3kOJQ2KaiBZaEOUWCQdSTkJATfKZCIg caiw== X-Gm-Message-State: AOAM531wDlBNm10QbNnGO/m2SoOJg6Dku/+A7YToZKu6Tpd4WIgJ1VMO xZXDL+KFOsgNx61l1juD0aIlqYVsWcfwBA== X-Received: by 2002:a1c:7e02:: with SMTP id z2mr8175969wmc.138.1595863173102; Mon, 27 Jul 2020 08:19:33 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id h199sm18744996wme.42.2020.07.27.08.19.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 08:19:32 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 7/7] target/arm: Improve IMPDEF algorithm for IRG Date: Mon, 27 Jul 2020 16:19:20 +0100 Message-Id: <20200727151920.19150-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200727151920.19150-1-peter.maydell@linaro.org> References: <20200727151920.19150-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x335.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson When GCR_EL1.RRND==1, the choosing of the random value is IMPDEF, and the kernel is not expected to have set RGSR_EL1. Force a non-zero value into SEED, so that we do not continually return the same tag. Reported-by: Vincenzo Frascino Signed-off-by: Richard Henderson Message-id: 20200724163853.504655-4-richard.henderson@linaro.org Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- target/arm/mte_helper.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) -- 2.20.1 diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c index 5ea57d487a4..104752041f7 100644 --- a/target/arm/mte_helper.c +++ b/target/arm/mte_helper.c @@ -24,6 +24,8 @@ #include "exec/ram_addr.h" #include "exec/cpu_ldst.h" #include "exec/helper-proto.h" +#include "qapi/error.h" +#include "qemu/guest-random.h" static int choose_nonexcluded_tag(int tag, int offset, uint16_t exclude) @@ -211,16 +213,37 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx, uint64_t HELPER(irg)(CPUARMState *env, uint64_t rn, uint64_t rm) { - int rtag; - - /* - * Our IMPDEF choice for GCR_EL1.RRND==1 is to behave as if - * GCR_EL1.RRND==0, always producing deterministic results. - */ uint16_t exclude = extract32(rm | env->cp15.gcr_el1, 0, 16); + int rrnd = extract32(env->cp15.gcr_el1, 16, 1); int start = extract32(env->cp15.rgsr_el1, 0, 4); int seed = extract32(env->cp15.rgsr_el1, 8, 16); - int offset, i; + int offset, i, rtag; + + /* + * Our IMPDEF choice for GCR_EL1.RRND==1 is to continue to use the + * deterministic algorithm. Except that with RRND==1 the kernel is + * not required to have set RGSR_EL1.SEED != 0, which is required for + * the deterministic algorithm to function. So we force a non-zero + * SEED for that case. + */ + if (unlikely(seed == 0) && rrnd) { + do { + Error *err = NULL; + uint16_t two; + + if (qemu_guest_getrandom(&two, sizeof(two), &err) < 0) { + /* + * Failed, for unknown reasons in the crypto subsystem. + * Best we can do is log the reason and use a constant seed. + */ + qemu_log_mask(LOG_UNIMP, "IRG: Crypto failure: %s\n", + error_get_pretty(err)); + error_free(err); + two = 1; + } + seed = two; + } while (seed == 0); + } /* RandomTag */ for (i = offset = 0; i < 4; ++i) {