From patchwork Sun Jan 21 00:20:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 764467 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:10c4:b0:337:62d3:c6d5 with SMTP id b4csp530407wrx; Sat, 20 Jan 2024 16:22:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4sjOCC5EJNAo3hd00cWqWpGQb9mLMbJmx/QgsV/9EG7mks1dMaOU96v32vNo1aCGmXX86 X-Received: by 2002:a05:622a:44b:b0:42a:2b2d:610b with SMTP id o11-20020a05622a044b00b0042a2b2d610bmr3628925qtx.103.1705796563628; Sat, 20 Jan 2024 16:22:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705796563; cv=none; d=google.com; s=arc-20160816; b=AVz65JlrwefNy0jaRzgtp+N+MMzv65/BFMWFPhhQVy9i89fq+XpT18TrMSsD/JZDXN Vm8gAKQbMvIab3hnApmidKBp2hN+WfcdtppYWxoWZ5tixFSOg8av0YymQzCa2bbMqHw0 CA7Q60b1gK+WiGBj8I6EVE54ctaXTfp8h1yYX6FaxUfBll2srGlRiqwp1Co0BSKC+PwQ 8aw9ssYq6j+rAquoeAgv00loIxwh/tKsoP4KVlN+DQy9MANdtKZn3WGWNvvNAV0JvFVs uU6JKpiMWxC/fCm1q6Kn0iZPHB8IGg/Vdmk0rrBRTdmOlLcg67wMy3/b5/hviq+nfVqO 0MvA== 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:cc:to :from:dkim-signature; bh=8KxhZwbZAcm1asBjHob1LgeGTJkXdHPPGTQpwmtvThw=; fh=Po6svqgyYqJzxZwR3KQKdPHXCr391FTx5wiDQXhlWnU=; b=SaBjYavxVYbuStzSqXC/pI0dOZrG7Ecd5JwcMaYQSyf6ojImQVFmn/fXqyE9h0K1Wu S8PqGoCzAKA8h5sFMh25H1uvy15YvV6gHLG9xcyZX3yqqG6lqFgKQm7UOFOVYsw13KfZ MrJNLGjM6PcEMoVFnmAMA2utBXbger5nyPkIpsHHjPF7VLb46FH60p/KLYc5J6Cf3cOO EEWLX7XqahDIgR0/a3fnFF60QOPpVv1344Jy37xF5Ll60Wyt3cgoERMUgSMj0/7Vf4Es 1JwK5Bk2OncUpHgfIYEiO5De9k4ERxo6SG0hfYibkIXHFwH6Tdlrmbr86iiOlH2ha+XC yG8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=luDG2Cf9; 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 f20-20020ac87f14000000b0042a2b19539csi2532633qtk.214.2024.01.20.16.22.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 20 Jan 2024 16:22:43 -0800 (PST) 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=luDG2Cf9; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rRLaA-0002VK-7D; Sat, 20 Jan 2024 19:21:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rRLa7-0002UO-Sm for qemu-devel@nongnu.org; Sat, 20 Jan 2024 19:21:00 -0500 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rRLa6-0007Mr-3U for qemu-devel@nongnu.org; Sat, 20 Jan 2024 19:20:59 -0500 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-2906dffd8ddso553458a91.3 for ; Sat, 20 Jan 2024 16:20:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705796456; x=1706401256; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8KxhZwbZAcm1asBjHob1LgeGTJkXdHPPGTQpwmtvThw=; b=luDG2Cf9OECkgoT3f/VB0mWaYPwAh2Y+OYkGJ/3eVyX9u5ZwE6OHVG6bDvqBznyL9/ 4sbfcBagNHPbY1ICyoj86Gh1/ic+vMs+NC8cw++tK7/uVvWRKwhk96pcIvkopryK4/HP H74IagG9x0KNn/KvImZMsTNqPU6pGzyXvD/KZbHQvNkGiLHMEy+RuHPRdBA1IHtItoGo gqIl2UJYSOCDVFzKDdlslTZBbjyZIyYVAoH09+1RMIHKfhSMI868qM2EC3EBtG/kGxUX nhQH37YwtGP5sMRSFnAXR6CspJMmfH9wgGSD2pYVM0kAZvQm3x+QPaFT0fewTUq6YrUA /V2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705796456; x=1706401256; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8KxhZwbZAcm1asBjHob1LgeGTJkXdHPPGTQpwmtvThw=; b=hw9nybuIBXs6oJwlaTeD2zfsUZcxjAulfflCNO1X5u7B6upQxlDRNCF8fT4vDFaKHh /7J+KlouwRwrOClB3ibABeFA2LFE1KBh+MUbe1xBizXR7Bt689ewuFJ5a6NaKpzRej8D CkdN88l2eBNYe3M0v2utYdzjDvzc0lG30WzyRIkKI9tRcLcxfXey9IEuUSiiUki/wIP0 gQhAwoSCTTiev8ysM2VLWedIPmt5jzP8J7fqtjfcWasB5ahKPbb+KGbSnrrp8k0sA1Ij 4/CntH+XJ8Z5tGLeQyOwfwdSRvDD0o8xc773uGrWC/Gixidh3VLyQtMoHEUtiNx0jarR hU4Q== X-Gm-Message-State: AOJu0YyoziZrD0XJaT0Y6n2NwlIHHrlasTqbNywexmlEkCAxMcjgcEMJ IReU/HiH7Wu5JjFxzp+x5q3RDONHMGp+sk0HpR9bw0f+ZAHvNswcHMQRu5rUo4FBPDGRfduCrXk 6GLo= X-Received: by 2002:a17:902:b78a:b0:1d6:fbab:d40b with SMTP id e10-20020a170902b78a00b001d6fbabd40bmr2467590pls.85.1705796456442; Sat, 20 Jan 2024 16:20:56 -0800 (PST) Received: from stoup.net ([2001:8004:5170:1e39:1361:3840:4873:7990]) by smtp.gmail.com with ESMTPSA id j4-20020a17090276c400b001d5af7fbda0sm5023546plt.122.2024.01.20.16.20.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 16:20:56 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Samuel Tardieu , Peter Maydell Subject: [PULL 1/8] tcg: Remove unreachable code Date: Sun, 21 Jan 2024 11:20:40 +1100 Message-Id: <20240121002047.89234-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240121002047.89234-1-richard.henderson@linaro.org> References: <20240121002047.89234-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.google.com 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+patch=linaro.org@nongnu.org From: Samuel Tardieu The `fail_rx`/`fail` block is only entered while `buf_rx` is equal to its initial value `MAP_FAILED`. The `munmap(buf_rx, size);` was never executed. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2030 Signed-off-by: Samuel Tardieu Reviewed-by: Peter Maydell Message-Id: <20231219182212.455952-2-sam@rfc1149.net> Signed-off-by: Richard Henderson --- tcg/region.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index 86692455c0..467e51cf6f 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -597,9 +597,7 @@ static int alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) fail_rx: error_setg_errno(errp, errno, "failed to map shared memory for execute"); fail: - if (buf_rx != MAP_FAILED) { - munmap(buf_rx, size); - } + /* buf_rx is always equal to MAP_FAILED here and does not require cleanup */ if (buf_rw) { munmap(buf_rw, size); } From patchwork Sun Jan 21 00:20:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 764462 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:10c4:b0:337:62d3:c6d5 with SMTP id b4csp530284wrx; Sat, 20 Jan 2024 16:22:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IEw1/S77RYdaK5v9jNRzd8jBcKQSA8MNhBRS837eQUSMff/8+ZZBrgiU4A8Ral4yH1n/6X6 X-Received: by 2002:a05:622a:40e:b0:429:caf9:f3af with SMTP id n14-20020a05622a040e00b00429caf9f3afmr2685753qtx.137.1705796539223; Sat, 20 Jan 2024 16:22:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705796539; cv=none; d=google.com; s=arc-20160816; b=NrjZh4Clahpr+WDNFvDoRZeG8FXNSXtlZ6NhcFqWwWMErfU8J7XU95PPXifhXlEht+ wTVwhnhpfl9ZQlPDiVpGLS0wCdjnacQFBBRvBAbHE7yVW3tXeLA/ekfiG+KCqrmFP0we yV2ABc9yZH5TXRTmJS3BumDUyMb9H1X8cF2D7IvhYEpmQy5Vrr/UrZzkvy2IQEwOlEdC 4R5K2Lsoz44S5kYVJdzID5yFOmhdIAygQyhaiWq6WlgPQOQyyN+BO7/IcoGNEGJz3K9o 1S5u8W7iPSFTS4LQJhJKtLYSZ0wePlBHFAQl4IxGe3KcH95HLM5itdxo0wa/SSP0p/FN yeEw== 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:cc:to :from:dkim-signature; bh=0EKsORzhcd/voY/5GCXD+0ZH5a0YI/B7BiYyHrdge+w=; fh=Po6svqgyYqJzxZwR3KQKdPHXCr391FTx5wiDQXhlWnU=; b=SdsSmscUC6sHqZnfRz2vVuEiotA5PTSBC4MnLnHdodjK8LPPVbdV0yRrR8n2I2TZ/L p0oufPbROFwy9Vljton9DtRH9yZrdimDfl6BMe0dmIRfwYKMCu56p27hLbC5EhOeJsGy +SNmoKzd8flb+yuyc12smasjvShKNpD40XQVX+4W5gfeDoWcCA3FCUrDhVk0mBjKF9JT KiDEvBy3J4YiUjwDzIVQ7bdkE/bsTQM/pEiypcQAFT29GpS6/89zeiP5oRMGpty7oZ67 t30c190TEzhjVWZ4YGEGn0me6ldOBz1d/Xdfe2YbQSSbwa4K0yxRWO2AnIsqYbLWwnvp +NpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nqalHe+r; 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 k14-20020a05622a03ce00b0042a26a6d43esi2525296qtx.101.2024.01.20.16.22.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 20 Jan 2024 16:22:19 -0800 (PST) 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=nqalHe+r; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rRLaB-0002Vl-E7; Sat, 20 Jan 2024 19:21:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rRLaA-0002VV-8l for qemu-devel@nongnu.org; Sat, 20 Jan 2024 19:21:02 -0500 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rRLa8-0007NJ-Ll for qemu-devel@nongnu.org; Sat, 20 Jan 2024 19:21:02 -0500 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-2907a17fa34so321870a91.1 for ; Sat, 20 Jan 2024 16:21:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705796459; x=1706401259; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0EKsORzhcd/voY/5GCXD+0ZH5a0YI/B7BiYyHrdge+w=; b=nqalHe+rh82CZBZ1Z/S67KA8JIcjQHp7CLdyJwb1G8HPF6tCcI1DF+Hnv2uyRe8gNu q7ggjET41HzG9uutAQKUzdacn9s9CMBTOf4NBXdbe5mv8m5uSC0m+u9JVBDf8WWkdqa+ zYV6+fFJoQancPRxF50YJjWHBjD+4ev1Zk5KuhS0xxTJsYbn/VBpfV53DTYOHoltzBBK vJbVmBR3f8UOHj8vujYo6YbL77yG7mldXfCMa8JDDMzmcfw5VIf77KTAfr6Vcf/XZtR8 7Te/gFg+bTdjp5i9tcti2qgrdVT5RblfsfMvdo/OqoXsRWHQwPaDKxqhxNOshaGgvHS9 Gp5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705796459; x=1706401259; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0EKsORzhcd/voY/5GCXD+0ZH5a0YI/B7BiYyHrdge+w=; b=wriyRuX0FdbwcvFLiL4zV1IYrFVys44JzojlCpzcg2F2jLy6vdct4pYGjlpJfsrqzu btfh/udgvYsj/xRyV7A6PcCAh3OZXPJ1Oqe9BuTnQH2ZgPzk7f/EIqdhNHqpPzsy853C 6Cy/PeosrPLN+nlC8VxtZmVwI2bqaMxjf++Q2847Fi+6ImRHjEpz20JtuAPkTO7yOrTW 3n2PQzrcXe8xoqVVwVJ576/Dv14daLLYKUwJuHAtn3MGV/iq58DcKdooKIBK4QokcmfG wQhEpHnsUIg+8/yMocYfNqoH9kGLphPv/VkrOLGrgHOff5WDOpQfZtfoYbouQ6Fm5x0s jVog== X-Gm-Message-State: AOJu0Yw7GapxQbnG9IL5bVA8tXMWQu+sbCVkZA9TitwNv0yUK77EOxvG uqY3HjA2zz9aFakXvzPiJ6dUVgC8dbEPVfebyDmRUMsWU51IGo4oYi3BK6xBmLG56qHfxHDlwGY CwKI= X-Received: by 2002:a17:902:7601:b0:1d7:4821:b567 with SMTP id k1-20020a170902760100b001d74821b567mr151074pll.139.1705796459447; Sat, 20 Jan 2024 16:20:59 -0800 (PST) Received: from stoup.net ([2001:8004:5170:1e39:1361:3840:4873:7990]) by smtp.gmail.com with ESMTPSA id j4-20020a17090276c400b001d5af7fbda0sm5023546plt.122.2024.01.20.16.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 16:20:59 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Samuel Tardieu , Peter Maydell Subject: [PULL 2/8] tcg: Make the cleanup-on-error path unique Date: Sun, 21 Jan 2024 11:20:41 +1100 Message-Id: <20240121002047.89234-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240121002047.89234-1-richard.henderson@linaro.org> References: <20240121002047.89234-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.google.com 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+patch=linaro.org@nongnu.org From: Samuel Tardieu By calling `error_setg_errno()` before jumping to the cleanup-on-error path at the `fail` label, the cleanup path is clearer. Signed-off-by: Samuel Tardieu Reviewed-by: Peter Maydell Message-Id: <20231219182212.455952-3-sam@rfc1149.net> Signed-off-by: Richard Henderson --- tcg/region.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index 467e51cf6f..478ec051c4 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -584,7 +584,9 @@ static int alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) buf_rx = mmap(NULL, size, host_prot_read_exec(), MAP_SHARED, fd, 0); if (buf_rx == MAP_FAILED) { - goto fail_rx; + error_setg_errno(errp, errno, + "failed to map shared memory for execute"); + goto fail; } close(fd); @@ -594,8 +596,6 @@ static int alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) return PROT_READ | PROT_WRITE; - fail_rx: - error_setg_errno(errp, errno, "failed to map shared memory for execute"); fail: /* buf_rx is always equal to MAP_FAILED here and does not require cleanup */ if (buf_rw) { From patchwork Sun Jan 21 00:20:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 764463 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:10c4:b0:337:62d3:c6d5 with SMTP id b4csp530293wrx; Sat, 20 Jan 2024 16:22:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVrqeE8jOQSXXstv3rbA9zE/eoCHb7b7Nscjm+8ad5KRLVOGy8QQxuEdSh4+uJIub3+cUB X-Received: by 2002:a05:6214:5016:b0:685:8ac0:c027 with SMTP id jo22-20020a056214501600b006858ac0c027mr2170273qvb.23.1705796541484; Sat, 20 Jan 2024 16:22:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705796541; cv=none; d=google.com; s=arc-20160816; b=Fs8RwE/+RVrYvfWerrZPiyUV4v5rZFxIL2MK4Fkle6OA2xY8E57N/mfkemWRmGrIoa tHPhzy6RGnZd7NxC9w5g125fmXp2Wipa1Cs6qs8LqmTtIcE1HCh3VfCXY31HMj7UKkMP CKl0FGgqSkzfh5EoBIiHFFVSt8hu6Rf4CjvDnqN1wcH0L1gYJEkmBTETQgO7UrW8QeCv jlgXfyVJqQGuxCdlE1CqStyk5hBmyxBuC1ulGBvjP4FNm9LF8mxE25mKUD66cTp74PtW CNNGcsH4ItDwrxnm0S8AaVu6gnVAqh0F299Nl2kIeTVZQ0fXwsyTjMIn1VPz+WMkbqVK HP2A== 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:cc:to :from:dkim-signature; bh=CJwQ5ZzhzO00+g0UGwDiX0qf7mCAm8ExrbTS/sZFCpk=; fh=hnz9pG8FMO+tm2obdPt4dhu6yqTXgplMe/ouKJtcwQs=; b=FGlu1EdQYK83O9I89hqMm0jUrRYXm6T8n7TUXgqcaWfCz/aoFCeBTfrfxi5yoDgmub 8Haj1kFDrJ0r5Zt3TcvwWqI++I59BvCRiJyNMoGKUeDPRTSY8omfiahd+McAyDnYo3FM 0U95tk2BM5TeykCOIXEXqPOUFMwbP96tBuRUMLGbH0BXCCKUdXqSJpfQVf+OZAmeFtI2 uglH/66isBLu/HOdTg0So8iCkWJ8LMdeUK8BmVKCAwGF6goTSIC3xo2c/HYYUdM0VDv8 NAHWQ+0hOoKznnIhHh+gv6y3V1AM1+NXaIVm3tv6hIfcUjmewpIMH4chfavtdfzeqa6m H/CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EyhLAyNP; 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 r16-20020a0ce290000000b0067f4709cff1si2583357qvl.99.2024.01.20.16.22.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 20 Jan 2024 16:22:21 -0800 (PST) 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=EyhLAyNP; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rRLaG-0002WZ-6H; Sat, 20 Jan 2024 19:21:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rRLaE-0002W3-23 for qemu-devel@nongnu.org; Sat, 20 Jan 2024 19:21:06 -0500 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rRLaB-0007P5-F1 for qemu-devel@nongnu.org; Sat, 20 Jan 2024 19:21:04 -0500 Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-36201722a7cso2146745ab.2 for ; Sat, 20 Jan 2024 16:21:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705796462; x=1706401262; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CJwQ5ZzhzO00+g0UGwDiX0qf7mCAm8ExrbTS/sZFCpk=; b=EyhLAyNPKBwEvxm+EbslBqz2LEavZEf8npnFeBgBmiSZMDo/KxRSJ5wH+QbF3WCaoW +64tw6cz6We529M0BB6eh8dCona0SFRAzClv217WkFF3LOKILtCf+X7wiCdKxJVqjIw0 NUFVEqljjPAxzb0yOAcTt96Dzjbr6OL8BRg/+3DMq7S5T5ZNC19HJVS8ptiZc6KMxjWK 4oE6hGWLlI5EsDJ9iYtk0tKj9l2DK1o0i7B1drrIf3vfve86/FWSqu0aqTB1j+JKMj1H B0tUQpfmHNVd8whrsaE3HyUkbKziYkczEOiioQ3q2WCcltpGGn6IV1QwEDVUxTQsz/ak wXyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705796462; x=1706401262; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CJwQ5ZzhzO00+g0UGwDiX0qf7mCAm8ExrbTS/sZFCpk=; b=th6LYheDEQgWRjdQPS9jbQ4CPqd990axatt+k4N77BiPsdvLwIt+8rf6aLjXZ2yKQu GquaYYevQMCIE/cdlm5mBfNs6I0KiGOGYaL4XAH35dr27M/4QVIbWUdZlbYQ/8CMaf7o wpwSrwZ4dgkn/7xOlLfLNM099dE61mt4wMverMR1x4O0WL52he9OTAZlQU5XMLF//tHF eWA0C0uTSRjy/x7ydrYplg/wIJRre6utHTs0giHNVdgOOgPgYoGdVzYCF6JlnYO9uH47 N8NfSE+4B3QeyUUT36df/l7hfwEsuUeLdJef1AfjFxpvPXeLV7fSOYizfsj6EAD0680v Vqkw== X-Gm-Message-State: AOJu0YxxjBeopel6rGDDURcRSdxXK//UZKdgi5jS77LPPWgyq7U5oKUv 8AT5L7UTItokZIwO2CKI5VvexHz7Z4xQrJlQjbVLhv35M0yh/4yaYWWlYfdzcGpTr0ZKKaVtxE6 mfFM= X-Received: by 2002:a92:c6c3:0:b0:361:9665:da9d with SMTP id v3-20020a92c6c3000000b003619665da9dmr3520252ilm.9.1705796462205; Sat, 20 Jan 2024 16:21:02 -0800 (PST) Received: from stoup.net ([2001:8004:5170:1e39:1361:3840:4873:7990]) by smtp.gmail.com with ESMTPSA id j4-20020a17090276c400b001d5af7fbda0sm5023546plt.122.2024.01.20.16.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 16:21:01 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Robbin Ehn , Palmer Dabbelt Subject: [PULL 3/8] linux-user: Fixed cpu restore with pc 0 on SIGBUS Date: Sun, 21 Jan 2024 11:20:42 +1100 Message-Id: <20240121002047.89234-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240121002047.89234-1-richard.henderson@linaro.org> References: <20240121002047.89234-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::133; envelope-from=richard.henderson@linaro.org; helo=mail-il1-x133.google.com 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+patch=linaro.org@nongnu.org From: Robbin Ehn Commit f4e1168198 (linux-user: Split out host_sig{segv,bus}_handler) introduced a bug, when returning from host_sigbus_handler the PC is never set. Thus cpu_loop_exit_restore is called with a zero PC and we immediate get a SIGSEGV. Signed-off-by: Robbin Ehn Fixes: f4e1168198 ("linux-user: Split out host_sig{segv,bus}_handler") Reviewed-by: Palmer Dabbelt Message-Id: <33f27425878fb529b9e39ef22c303f6e0d90525f.camel@rivosinc.com> Signed-off-by: Richard Henderson --- linux-user/signal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index b35d1e512f..c9527adfa3 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -925,7 +925,7 @@ static void host_sigsegv_handler(CPUState *cpu, siginfo_t *info, cpu_loop_exit_sigsegv(cpu, guest_addr, access_type, maperr, pc); } -static void host_sigbus_handler(CPUState *cpu, siginfo_t *info, +static uintptr_t host_sigbus_handler(CPUState *cpu, siginfo_t *info, host_sigcontext *uc) { uintptr_t pc = host_signal_pc(uc); @@ -947,6 +947,7 @@ static void host_sigbus_handler(CPUState *cpu, siginfo_t *info, sigprocmask(SIG_SETMASK, host_signal_mask(uc), NULL); cpu_loop_exit_sigbus(cpu, guest_addr, access_type, pc); } + return pc; } static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) @@ -974,7 +975,7 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) host_sigsegv_handler(cpu, info, uc); return; case SIGBUS: - host_sigbus_handler(cpu, info, uc); + pc = host_sigbus_handler(cpu, info, uc); sync_sig = true; break; case SIGILL: From patchwork Sun Jan 21 00:20:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 764464 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:10c4:b0:337:62d3:c6d5 with SMTP id b4csp530315wrx; Sat, 20 Jan 2024 16:22:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgmGVNr4Uzr+IIkJPT9mrrI/9tv+RR8S4fF0w3n7+BZlLfAuRE5kgS7LVOTPsRPahexBF4 X-Received: by 2002:ac8:5c88:0:b0:42a:3508:b20 with SMTP id r8-20020ac85c88000000b0042a35080b20mr1559897qta.93.1705796544135; Sat, 20 Jan 2024 16:22:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705796544; cv=none; d=google.com; s=arc-20160816; b=AJ04bZwgO12Q0RC83kwRVo7UaxcKsY2WNVngjtVMDvLd8MfGBKMHvdZ19LFk/ssOiN 765mj1cWSaTukXbDVsjiWhaOiZjEmN9OD39HNs0Tbr77TgBZY2gT6hN8/o2SbVgoSHmT zkx2BH3vzxXZefDavLR/NvLhLMbX25p7lq/aL8u731Q8IVjt/C2D41LJ4b0XV6i5lqmk MgdefNpfozF0eNMAK6yAyDgCv1qucdfZr4Ls/gyES4qcSkkaXRrfk9XeRW4MBCwXNEBA Q/6ZeesMl+ktgnJFEBj+CmiyThuol313dPWjrYulsd0jxb4pCEAAmz5zOALcQALGBPkE 6PKQ== 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:cc:to :from:dkim-signature; bh=lU9aH7ZY0n7uAdgAxQsFLjxICAM1xx6kGJSgqsKuTsU=; fh=HbLj/5yooXb+Hoe1WPA3vZVKPDdpNdYNbhwpVZI8wJI=; b=uKd1ezTT5RtEGNEUUW/8KvbbeyDxkEwZLmd5Q48NwpmZFlBoosl3UNMsjtzoRQFR2e dywrDG2lBxGzN9/3Aq/XDpnHxmr7R4MFLDcE1vVQtD63C0lKVS2MEyfGlXZbEZzYdfuh een9GQ8QipC5BIiu6ieONZvwud9Vfug77yHfOOfLPNrem/Ok1kiIt1tmhVzom3rnZaly LVP+KCbyxRiSgyJIIMVIFOa8ndnhZScYICKnEgVmnxrOmv0dmRMzFFsTv9tC9eLxxvB6 5woJoq7BRO5Fftor9dTG3E87bsnrbFcWQ99fyzyJGvlFZP9AphcfYLClY5XniGwgloVr k0zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ju3VHi3Y; 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 k14-20020a05620a0b8e00b007833d302d75si2490432qkh.75.2024.01.20.16.22.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 20 Jan 2024 16:22:24 -0800 (PST) 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=Ju3VHi3Y; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rRLaJ-0002XR-4W; Sat, 20 Jan 2024 19:21:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rRLaH-0002X0-6S for qemu-devel@nongnu.org; Sat, 20 Jan 2024 19:21:09 -0500 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rRLaF-0007Pj-8P for qemu-devel@nongnu.org; Sat, 20 Jan 2024 19:21:08 -0500 Received: by mail-il1-x132.google.com with SMTP id e9e14a558f8ab-361ae51a4d9so5617515ab.1 for ; Sat, 20 Jan 2024 16:21:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705796465; x=1706401265; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lU9aH7ZY0n7uAdgAxQsFLjxICAM1xx6kGJSgqsKuTsU=; b=Ju3VHi3YYiapsoWoAe9WLa2G13rKjQjHhckC23XlODTyXeG7CsqBgBvxOIy9tA3cIp ec45kYs0+aDEwpLKe7qcuQXWsMWPR+tAMVlwsgbYRSZ5UzejQarvE7VdvxE8r9hkQ2d5 I9iKfS04DskQUO1Gp/7EStO3G+7eo3Z+rzyadSVxupS9PDx7TdeYX9IrekC9Pm2bSdXc 7oBb+LfX5HRafrEtQDS2UoYV+FtWhpAWv3qCw7QS07sWbDRNeEnZlhiCMfSDipvEZ1Mq XGeCo61rfzTCJM6jJTPvZWux7JLtFTHCTctnCchNgBW2JS+V+KeL5ai4/YRQHhVpvo2z pxgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705796465; x=1706401265; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lU9aH7ZY0n7uAdgAxQsFLjxICAM1xx6kGJSgqsKuTsU=; b=S6ewddz4Hn7Wyd+NaCw2pa4GBIH9bT0LMr73nwVCkPM2F4JW2MJCCAnfC2TcKJ64+l CB54NPVyi93j96v2oj63x6nkN/aKvCI5u3StlrjDLRjbmz7L+kBf/qSdE00CTRSlsKWy XUojmyq6MHhoZ8LU7bu39IC9gYCyewyYocLdlGZZAIGhL0FoXY+QIj7Je657l5qqKc6G woPnzVdjkgIv6JewVge+Od/k71+GedfZ4eDyoxWhBRCSadjPZdZclGDbL+7t2aa8V0RU 8XlmevUJQwJw3eWObqRpf9NNGLlt/Bfq/RfKsWndeRbQT7p5trsZL3Vn0Ht74HJq7r4Z 1aLw== X-Gm-Message-State: AOJu0YyqjsjWvBgGpsmfAf/qKE8IX3UoYetc9+Uz3HZ2IPEgPDxFCoJX Woob8itbEHHfBuj8Pv291HxMbieQyPF+ZTdwTmbcdEWAhRLOJu+pRltnivY0L9MO2YnrQGH6Bxe DOM0= X-Received: by 2002:a92:c110:0:b0:361:a867:5881 with SMTP id p16-20020a92c110000000b00361a8675881mr3558335ile.14.1705796465565; Sat, 20 Jan 2024 16:21:05 -0800 (PST) Received: from stoup.net ([2001:8004:5170:1e39:1361:3840:4873:7990]) by smtp.gmail.com with ESMTPSA id j4-20020a17090276c400b001d5af7fbda0sm5023546plt.122.2024.01.20.16.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 16:21:05 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Michael Tokarev , Thomas Huth Subject: [PULL 4/8] tcg/s390x: Fix encoding of VRIc, VRSa, VRSc insns Date: Sun, 21 Jan 2024 11:20:43 +1100 Message-Id: <20240121002047.89234-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240121002047.89234-1-richard.henderson@linaro.org> References: <20240121002047.89234-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::132; envelope-from=richard.henderson@linaro.org; helo=mail-il1-x132.google.com 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+patch=linaro.org@nongnu.org While the format names the second vector register 'v3', it is still in the second position (bits 12-15) and the argument to RXB must match. Example error: - e7 00 00 10 2a 33 verllf %v16,%v0,16 + e7 00 00 10 2c 33 verllf %v16,%v16,16 Cc: qemu-stable@nongnu.org Reported-by: Michael Tokarev Fixes: 22cb37b4172 ("tcg/s390x: Implement vector shift operations") Fixes: 79cada8693d ("tcg/s390x: Implement tcg_out_dup*_vec") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2054 Reviewed-by: Thomas Huth Tested-by: Michael Tokarev Message-Id: <20240117213646.159697-2-richard.henderson@linaro.org> Signed-off-by: Richard Henderson --- tcg/s390x/tcg-target.c.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tcg/s390x/tcg-target.c.inc b/tcg/s390x/tcg-target.c.inc index fbee43d3b0..7f6b84aa2c 100644 --- a/tcg/s390x/tcg-target.c.inc +++ b/tcg/s390x/tcg-target.c.inc @@ -683,7 +683,7 @@ static void tcg_out_insn_VRIc(TCGContext *s, S390Opcode op, tcg_debug_assert(is_vector_reg(v3)); tcg_out16(s, (op & 0xff00) | ((v1 & 0xf) << 4) | (v3 & 0xf)); tcg_out16(s, i2); - tcg_out16(s, (op & 0x00ff) | RXB(v1, 0, v3, 0) | (m4 << 12)); + tcg_out16(s, (op & 0x00ff) | RXB(v1, v3, 0, 0) | (m4 << 12)); } static void tcg_out_insn_VRRa(TCGContext *s, S390Opcode op, @@ -738,7 +738,7 @@ static void tcg_out_insn_VRSa(TCGContext *s, S390Opcode op, TCGReg v1, tcg_debug_assert(is_vector_reg(v3)); tcg_out16(s, (op & 0xff00) | ((v1 & 0xf) << 4) | (v3 & 0xf)); tcg_out16(s, b2 << 12 | d2); - tcg_out16(s, (op & 0x00ff) | RXB(v1, 0, v3, 0) | (m4 << 12)); + tcg_out16(s, (op & 0x00ff) | RXB(v1, v3, 0, 0) | (m4 << 12)); } static void tcg_out_insn_VRSb(TCGContext *s, S390Opcode op, TCGReg v1, @@ -762,7 +762,7 @@ static void tcg_out_insn_VRSc(TCGContext *s, S390Opcode op, TCGReg r1, tcg_debug_assert(is_vector_reg(v3)); tcg_out16(s, (op & 0xff00) | (r1 << 4) | (v3 & 0xf)); tcg_out16(s, b2 << 12 | d2); - tcg_out16(s, (op & 0x00ff) | RXB(0, 0, v3, 0) | (m4 << 12)); + tcg_out16(s, (op & 0x00ff) | RXB(0, v3, 0, 0) | (m4 << 12)); } static void tcg_out_insn_VRX(TCGContext *s, S390Opcode op, TCGReg v1, From patchwork Sun Jan 21 00:20:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 764465 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:10c4:b0:337:62d3:c6d5 with SMTP id b4csp530345wrx; Sat, 20 Jan 2024 16:22:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IH3/9QVfVGQiY0zMUeEvPqSMaOvD7xdVChhbf6Sh6xpGL2+FgVJTpFR1MDCswZVA0E4rLUD X-Received: by 2002:a05:622a:508:b0:42a:269:993 with SMTP id l8-20020a05622a050800b0042a02690993mr3764940qtx.124.1705796549440; Sat, 20 Jan 2024 16:22:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705796549; cv=none; d=google.com; s=arc-20160816; b=lbdbsI2ec4yvGLzL30xMm1w9OMrnBKbIDGl+4V0JWvgtF3SQEiMUV/HTZaiE0GTS7v 0+nFE7UeZKgcXd38Pa8DbaH5Lc91WhMBwziTOmXY0QCWAERO3SxureHazTLjHlwSoN2N MSksJI/FLkfU3vfMvE3aFpP6BlkorwSIp8UBm/62DQwcsDg2+DDHOpFxHq7RLNFqPwyr iArcuaxZEVJaRPJJu09Oj5soHKcPvaAIrxVofCC8YKipZXFA4KV30POcoOx9hauCS/o0 JFNpxl12zU1depiUP9qR96CvzFaDmmnXFIAI4sh4oVKTnruaHpcr5rCf7UIYlvQQdm2J uBgw== 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:cc:to :from:dkim-signature; bh=hlgMoCbNlbK2kYnDr6aEn76H+rXWsz2BjY76x4m7kmQ=; fh=3dp7BTtPb6AzS2/TPKRpfEU20JkvSMAcs18YYYSYN4I=; b=J8vC/RvaPvqskjdb8tOKO0CVWR//KlbNOBziR8hBiZ4Z3sG/HidEnsK4gq7kfF+KOd I4e04E37yKTyQMrIaG+3PLo/DWsuCT+kF/zgYoajnFssGhDfYhPt6DU1TPwRuYePGE2u M/vdKtBXns20iQ9EK7Zu6lepGHsv1SyUYTN9yZLrjfpAwpZYQ59ZOyTBRgS09T5llJ4i BmzvL9d42D7o/ENgV65ORYNSQga4Z0RM32WQqwdwgR+lu7mzTcSj9rWSgyVV+Ckj+v+f KMlgfelid4zaetQo+wG8Sz+KsjqdNWigxUYGc0n3Pjni+scfUnbvXm+pgDsQYFuNEHZx HFOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dxpicevo; 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 h15-20020a05622a170f00b0042a35b6799fsi1104805qtk.407.2024.01.20.16.22.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 20 Jan 2024 16:22:29 -0800 (PST) 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=dxpicevo; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rRLaN-0002Xv-8R; Sat, 20 Jan 2024 19:21:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rRLaL-0002Xm-9e for qemu-devel@nongnu.org; Sat, 20 Jan 2024 19:21:13 -0500 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rRLaH-0007QJ-Ti for qemu-devel@nongnu.org; Sat, 20 Jan 2024 19:21:13 -0500 Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-7bf617dcedaso92352739f.0 for ; Sat, 20 Jan 2024 16:21:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705796469; x=1706401269; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hlgMoCbNlbK2kYnDr6aEn76H+rXWsz2BjY76x4m7kmQ=; b=dxpicevosLthobJj7mqrQNSfJH0Qitxn8m1/JJNkdjAtoyaceeh5kWgVfEOQkuXxVQ U+QORA90rlP7+5wfz4o9w4k2mzRfAK78EDrdqnFi61mYlMogwwioSZIFzBEc3wHCCCkS hGKheBTdY858gu/kKamDPB4kvttxn8SqfU+RPQnqPllOxJkqyv4EAubNiwFFTsW/IW4Q rBAL04ygKcuqt0wndvycnzSGwZOJvMSrPPXnq4CbhteyEr6XNsA/bhL8ZuxyXVHV5hfS 1U0hkNRj/8nHXJ9ejwyOxZtm5R5lKywQHphpQCmzfCFmvfMOp/9QsBpnCqqqLWpr4cFJ EeVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705796469; x=1706401269; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hlgMoCbNlbK2kYnDr6aEn76H+rXWsz2BjY76x4m7kmQ=; b=BKwv/nhj6sqe+CANlA1W7/oA25IjFfb3omyKs+0DoY7IHiUDHOxgE8kqqm42kdH0q0 EVtQHOUM3P+cRAFhG7lmp0ckOFZLXTrMEXW2lYRViYGlL5uTFltepLECUuTtehrDsRx4 sBilkrVA/UyGBo363zCa/P44NLFWAARECuiLpaLHLkDtcKqod+saLEf6hejtbsatkaW1 UsNAdOHQbPg+kB0sOSsA7Z0rtrvHsKZdrsdkH2YSbSt/CPQOugGkxW51VRX5jJQ17Upe iR3qN8rd1Ba0oEGFqzN9V8P3QpEiT+4CTg8OLpchJInZ7Dt+zSxYMGx0u+1YkibWewPS DzfA== X-Gm-Message-State: AOJu0YyiCjgo60/ljFghZgwXBdMgMLcmhcAgk90uooMg/oYHDdRDHDQJ 1R3ycGICw4xx/mMalz/qv2AWZsSBVZtXR8Wd8piQNjM9k+9n+Dz7EGlDvlPRfyfxZEv01dBSIbH AnR4= X-Received: by 2002:a92:d24d:0:b0:361:ae2c:f8c3 with SMTP id v13-20020a92d24d000000b00361ae2cf8c3mr3298337ilg.52.1705796468694; Sat, 20 Jan 2024 16:21:08 -0800 (PST) Received: from stoup.net ([2001:8004:5170:1e39:1361:3840:4873:7990]) by smtp.gmail.com with ESMTPSA id j4-20020a17090276c400b001d5af7fbda0sm5023546plt.122.2024.01.20.16.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 16:21:08 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Michael Tokarev , Thomas Huth Subject: [PULL 5/8] tests/tcg/s390x: Import linux tools/testing/crypto/chacha20-s390 Date: Sun, 21 Jan 2024 11:20:44 +1100 Message-Id: <20240121002047.89234-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240121002047.89234-1-richard.henderson@linaro.org> References: <20240121002047.89234-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::d2c; envelope-from=richard.henderson@linaro.org; helo=mail-io1-xd2c.google.com 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+patch=linaro.org@nongnu.org Modify and simplify the driver, as we're really only interested in correctness of translation of chacha-vx.S. Tested-by: Michael Tokarev Tested-by: Thomas Huth Message-Id: <20240117213646.159697-3-richard.henderson@linaro.org> Signed-off-by: Richard Henderson --- tests/tcg/s390x/chacha.c | 341 ++++++++++++ tests/tcg/s390x/Makefile.target | 4 + tests/tcg/s390x/chacha-vx.S | 914 ++++++++++++++++++++++++++++++++ 3 files changed, 1259 insertions(+) create mode 100644 tests/tcg/s390x/chacha.c create mode 100644 tests/tcg/s390x/chacha-vx.S diff --git a/tests/tcg/s390x/chacha.c b/tests/tcg/s390x/chacha.c new file mode 100644 index 0000000000..ca9e4c1959 --- /dev/null +++ b/tests/tcg/s390x/chacha.c @@ -0,0 +1,341 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Derived from linux kernel sources: + * ./include/crypto/chacha.h + * ./crypto/chacha_generic.c + * ./arch/s390/crypto/chacha-glue.c + * ./tools/testing/crypto/chacha20-s390/test-cipher.c + * ./tools/testing/crypto/chacha20-s390/run-tests.sh + */ + +#include +#include +#include +#include +#include +#include + +typedef uint8_t u8; +typedef uint32_t u32; +typedef uint64_t u64; + +static unsigned data_size; +static bool debug; + +#define CHACHA_IV_SIZE 16 +#define CHACHA_KEY_SIZE 32 +#define CHACHA_BLOCK_SIZE 64 +#define CHACHAPOLY_IV_SIZE 12 +#define CHACHA_STATE_WORDS (CHACHA_BLOCK_SIZE / sizeof(u32)) + +static u32 rol32(u32 val, u32 sh) +{ + return (val << (sh & 31)) | (val >> (-sh & 31)); +} + +static u32 get_unaligned_le32(const void *ptr) +{ + u32 val; + memcpy(&val, ptr, 4); + return __builtin_bswap32(val); +} + +static void put_unaligned_le32(u32 val, void *ptr) +{ + val = __builtin_bswap32(val); + memcpy(ptr, &val, 4); +} + +static void chacha_permute(u32 *x, int nrounds) +{ + for (int i = 0; i < nrounds; i += 2) { + x[0] += x[4]; x[12] = rol32(x[12] ^ x[0], 16); + x[1] += x[5]; x[13] = rol32(x[13] ^ x[1], 16); + x[2] += x[6]; x[14] = rol32(x[14] ^ x[2], 16); + x[3] += x[7]; x[15] = rol32(x[15] ^ x[3], 16); + + x[8] += x[12]; x[4] = rol32(x[4] ^ x[8], 12); + x[9] += x[13]; x[5] = rol32(x[5] ^ x[9], 12); + x[10] += x[14]; x[6] = rol32(x[6] ^ x[10], 12); + x[11] += x[15]; x[7] = rol32(x[7] ^ x[11], 12); + + x[0] += x[4]; x[12] = rol32(x[12] ^ x[0], 8); + x[1] += x[5]; x[13] = rol32(x[13] ^ x[1], 8); + x[2] += x[6]; x[14] = rol32(x[14] ^ x[2], 8); + x[3] += x[7]; x[15] = rol32(x[15] ^ x[3], 8); + + x[8] += x[12]; x[4] = rol32(x[4] ^ x[8], 7); + x[9] += x[13]; x[5] = rol32(x[5] ^ x[9], 7); + x[10] += x[14]; x[6] = rol32(x[6] ^ x[10], 7); + x[11] += x[15]; x[7] = rol32(x[7] ^ x[11], 7); + + x[0] += x[5]; x[15] = rol32(x[15] ^ x[0], 16); + x[1] += x[6]; x[12] = rol32(x[12] ^ x[1], 16); + x[2] += x[7]; x[13] = rol32(x[13] ^ x[2], 16); + x[3] += x[4]; x[14] = rol32(x[14] ^ x[3], 16); + + x[10] += x[15]; x[5] = rol32(x[5] ^ x[10], 12); + x[11] += x[12]; x[6] = rol32(x[6] ^ x[11], 12); + x[8] += x[13]; x[7] = rol32(x[7] ^ x[8], 12); + x[9] += x[14]; x[4] = rol32(x[4] ^ x[9], 12); + + x[0] += x[5]; x[15] = rol32(x[15] ^ x[0], 8); + x[1] += x[6]; x[12] = rol32(x[12] ^ x[1], 8); + x[2] += x[7]; x[13] = rol32(x[13] ^ x[2], 8); + x[3] += x[4]; x[14] = rol32(x[14] ^ x[3], 8); + + x[10] += x[15]; x[5] = rol32(x[5] ^ x[10], 7); + x[11] += x[12]; x[6] = rol32(x[6] ^ x[11], 7); + x[8] += x[13]; x[7] = rol32(x[7] ^ x[8], 7); + x[9] += x[14]; x[4] = rol32(x[4] ^ x[9], 7); + } +} + +static void chacha_block_generic(u32 *state, u8 *stream, int nrounds) +{ + u32 x[16]; + + memcpy(x, state, 64); + chacha_permute(x, nrounds); + + for (int i = 0; i < 16; i++) { + put_unaligned_le32(x[i] + state[i], &stream[i * sizeof(u32)]); + } + state[12]++; +} + +static void crypto_xor_cpy(u8 *dst, const u8 *src1, + const u8 *src2, unsigned len) +{ + while (len--) { + *dst++ = *src1++ ^ *src2++; + } +} + +static void chacha_crypt_generic(u32 *state, u8 *dst, const u8 *src, + unsigned int bytes, int nrounds) +{ + u8 stream[CHACHA_BLOCK_SIZE]; + + while (bytes >= CHACHA_BLOCK_SIZE) { + chacha_block_generic(state, stream, nrounds); + crypto_xor_cpy(dst, src, stream, CHACHA_BLOCK_SIZE); + bytes -= CHACHA_BLOCK_SIZE; + dst += CHACHA_BLOCK_SIZE; + src += CHACHA_BLOCK_SIZE; + } + if (bytes) { + chacha_block_generic(state, stream, nrounds); + crypto_xor_cpy(dst, src, stream, bytes); + } +} + +enum chacha_constants { /* expand 32-byte k */ + CHACHA_CONSTANT_EXPA = 0x61707865U, + CHACHA_CONSTANT_ND_3 = 0x3320646eU, + CHACHA_CONSTANT_2_BY = 0x79622d32U, + CHACHA_CONSTANT_TE_K = 0x6b206574U +}; + +static void chacha_init_generic(u32 *state, const u32 *key, const u8 *iv) +{ + state[0] = CHACHA_CONSTANT_EXPA; + state[1] = CHACHA_CONSTANT_ND_3; + state[2] = CHACHA_CONSTANT_2_BY; + state[3] = CHACHA_CONSTANT_TE_K; + state[4] = key[0]; + state[5] = key[1]; + state[6] = key[2]; + state[7] = key[3]; + state[8] = key[4]; + state[9] = key[5]; + state[10] = key[6]; + state[11] = key[7]; + state[12] = get_unaligned_le32(iv + 0); + state[13] = get_unaligned_le32(iv + 4); + state[14] = get_unaligned_le32(iv + 8); + state[15] = get_unaligned_le32(iv + 12); +} + +void chacha20_vx(u8 *out, const u8 *inp, size_t len, const u32 *key, + const u32 *counter); + +static void chacha20_crypt_s390(u32 *state, u8 *dst, const u8 *src, + unsigned int nbytes, const u32 *key, + u32 *counter) +{ + chacha20_vx(dst, src, nbytes, key, counter); + *counter += (nbytes + CHACHA_BLOCK_SIZE - 1) / CHACHA_BLOCK_SIZE; +} + +static void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, + unsigned int bytes, int nrounds) +{ + /* + * s390 chacha20 implementation has 20 rounds hard-coded, + * it cannot handle a block of data or less, but otherwise + * it can handle data of arbitrary size + */ + if (bytes <= CHACHA_BLOCK_SIZE || nrounds != 20) { + chacha_crypt_generic(state, dst, src, bytes, nrounds); + } else { + chacha20_crypt_s390(state, dst, src, bytes, &state[4], &state[12]); + } +} + +static void print_hex_dump(const char *prefix_str, const void *buf, int len) +{ + for (int i = 0; i < len; i += 16) { + printf("%s%.8x: ", prefix_str, i); + for (int j = 0; j < 16; ++j) { + printf("%02x%c", *(u8 *)(buf + i + j), j == 15 ? '\n' : ' '); + } + } +} + +/* Perform cipher operations with the chacha lib */ +static int test_lib_chacha(u8 *revert, u8 *cipher, u8 *plain, bool generic) +{ + u32 chacha_state[CHACHA_STATE_WORDS]; + u8 iv[16], key[32]; + + memset(key, 'X', sizeof(key)); + memset(iv, 'I', sizeof(iv)); + + if (debug) { + print_hex_dump("key: ", key, 32); + print_hex_dump("iv: ", iv, 16); + } + + /* Encrypt */ + chacha_init_generic(chacha_state, (u32*)key, iv); + + if (generic) { + chacha_crypt_generic(chacha_state, cipher, plain, data_size, 20); + } else { + chacha_crypt_arch(chacha_state, cipher, plain, data_size, 20); + } + + if (debug) { + print_hex_dump("encr:", cipher, + (data_size > 64 ? 64 : data_size)); + } + + /* Decrypt */ + chacha_init_generic(chacha_state, (u32 *)key, iv); + + if (generic) { + chacha_crypt_generic(chacha_state, revert, cipher, data_size, 20); + } else { + chacha_crypt_arch(chacha_state, revert, cipher, data_size, 20); + } + + if (debug) { + print_hex_dump("decr:", revert, + (data_size > 64 ? 64 : data_size)); + } + return 0; +} + +static int chacha_s390_test_init(void) +{ + u8 *plain = NULL, *revert = NULL; + u8 *cipher_generic = NULL, *cipher_s390 = NULL; + int ret = -1; + + printf("s390 ChaCha20 test module: size=%d debug=%d\n", + data_size, debug); + + /* Allocate and fill buffers */ + plain = malloc(data_size); + if (!plain) { + printf("could not allocate plain buffer\n"); + ret = -2; + goto out; + } + + memset(plain, 'a', data_size); + for (unsigned i = 0, n = data_size > 256 ? 256 : data_size; i < n; ) { + ssize_t t = getrandom(plain + i, n - i, 0); + if (t < 0) { + break; + } + i -= t; + } + + cipher_generic = calloc(1, data_size); + if (!cipher_generic) { + printf("could not allocate cipher_generic buffer\n"); + ret = -2; + goto out; + } + + cipher_s390 = calloc(1, data_size); + if (!cipher_s390) { + printf("could not allocate cipher_s390 buffer\n"); + ret = -2; + goto out; + } + + revert = calloc(1, data_size); + if (!revert) { + printf("could not allocate revert buffer\n"); + ret = -2; + goto out; + } + + if (debug) { + print_hex_dump("src: ", plain, + (data_size > 64 ? 64 : data_size)); + } + + /* Use chacha20 lib */ + test_lib_chacha(revert, cipher_generic, plain, true); + if (memcmp(plain, revert, data_size)) { + printf("generic en/decryption check FAILED\n"); + ret = -2; + goto out; + } + printf("generic en/decryption check OK\n"); + + test_lib_chacha(revert, cipher_s390, plain, false); + if (memcmp(plain, revert, data_size)) { + printf("lib en/decryption check FAILED\n"); + ret = -2; + goto out; + } + printf("lib en/decryption check OK\n"); + + if (memcmp(cipher_generic, cipher_s390, data_size)) { + printf("lib vs generic check FAILED\n"); + ret = -2; + goto out; + } + printf("lib vs generic check OK\n"); + + printf("--- chacha20 s390 test end ---\n"); + +out: + free(plain); + free(cipher_generic); + free(cipher_s390); + free(revert); + return ret; +} + +int main(int ac, char **av) +{ + static const unsigned sizes[] = { + 63, 64, 65, 127, 128, 129, 511, 512, 513, 4096, 65611, + /* too slow for tcg: 6291456, 62914560 */ + }; + + debug = ac >= 2; + for (int i = 0; i < sizeof(sizes) / sizeof(sizes[0]); ++i) { + data_size = sizes[i]; + if (chacha_s390_test_init() != -1) { + return 1; + } + } + return 0; +} diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target index 30994dcf9c..b9dc12dc8a 100644 --- a/tests/tcg/s390x/Makefile.target +++ b/tests/tcg/s390x/Makefile.target @@ -66,9 +66,13 @@ Z13_TESTS+=vcksm Z13_TESTS+=vstl Z13_TESTS+=vrep Z13_TESTS+=precise-smc-user +Z13_TESTS+=chacha $(Z13_TESTS): CFLAGS+=-march=z13 -O2 TESTS+=$(Z13_TESTS) +chacha: chacha.c chacha-vx.S + $(CC) $(LDFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) $^ -o $@ + ifneq ($(CROSS_CC_HAS_Z14),) Z14_TESTS=vfminmax vfminmax: LDFLAGS+=-lm diff --git a/tests/tcg/s390x/chacha-vx.S b/tests/tcg/s390x/chacha-vx.S new file mode 100644 index 0000000000..dcb55b4324 --- /dev/null +++ b/tests/tcg/s390x/chacha-vx.S @@ -0,0 +1,914 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Original implementation written by Andy Polyakov, @dot-asm. + * This is an adaptation of the original code for kernel use. + * + * Copyright (C) 2006-2019 CRYPTOGAMS by . All Rights Reserved. + * + * For qemu testing, drop and assume assembler support. + */ + +#define SP %r15 +#define FRAME (16 * 8 + 4 * 8) + + .data + .balign 32 + +sigma: + .long 0x61707865,0x3320646e,0x79622d32,0x6b206574 # endian-neutral + .long 1,0,0,0 + .long 2,0,0,0 + .long 3,0,0,0 + .long 0x03020100,0x07060504,0x0b0a0908,0x0f0e0d0c # byte swap + + .long 0,1,2,3 + .long 0x61707865,0x61707865,0x61707865,0x61707865 # smashed sigma + .long 0x3320646e,0x3320646e,0x3320646e,0x3320646e + .long 0x79622d32,0x79622d32,0x79622d32,0x79622d32 + .long 0x6b206574,0x6b206574,0x6b206574,0x6b206574 + + .type sigma, @object + .size sigma, . - sigma + + .previous + + .text + +############################################################################# +# void chacha20_vx_4x(u8 *out, counst u8 *inp, size_t len, +# counst u32 *key, const u32 *counter) + +#define OUT %r2 +#define INP %r3 +#define LEN %r4 +#define KEY %r5 +#define COUNTER %r6 + +#define BEPERM %v31 +#define CTR %v26 + +#define K0 %v16 +#define K1 %v17 +#define K2 %v18 +#define K3 %v19 + +#define XA0 %v0 +#define XA1 %v1 +#define XA2 %v2 +#define XA3 %v3 + +#define XB0 %v4 +#define XB1 %v5 +#define XB2 %v6 +#define XB3 %v7 + +#define XC0 %v8 +#define XC1 %v9 +#define XC2 %v10 +#define XC3 %v11 + +#define XD0 %v12 +#define XD1 %v13 +#define XD2 %v14 +#define XD3 %v15 + +#define XT0 %v27 +#define XT1 %v28 +#define XT2 %v29 +#define XT3 %v30 + + .balign 32 +chacha20_vx_4x: + stmg %r6,%r7,6*8(SP) + + larl %r7,sigma + lhi %r0,10 + lhi %r1,0 + + vl K0,0(%r7) # load sigma + vl K1,0(KEY) # load key + vl K2,16(KEY) + vl K3,0(COUNTER) # load counter + + vl BEPERM,0x40(%r7) + vl CTR,0x50(%r7) + + vlm XA0,XA3,0x60(%r7),4 # load [smashed] sigma + + vrepf XB0,K1,0 # smash the key + vrepf XB1,K1,1 + vrepf XB2,K1,2 + vrepf XB3,K1,3 + + vrepf XD0,K3,0 + vrepf XD1,K3,1 + vrepf XD2,K3,2 + vrepf XD3,K3,3 + vaf XD0,XD0,CTR + + vrepf XC0,K2,0 + vrepf XC1,K2,1 + vrepf XC2,K2,2 + vrepf XC3,K2,3 + +.Loop_4x: + vaf XA0,XA0,XB0 + vx XD0,XD0,XA0 + verllf XD0,XD0,16 + + vaf XA1,XA1,XB1 + vx XD1,XD1,XA1 + verllf XD1,XD1,16 + + vaf XA2,XA2,XB2 + vx XD2,XD2,XA2 + verllf XD2,XD2,16 + + vaf XA3,XA3,XB3 + vx XD3,XD3,XA3 + verllf XD3,XD3,16 + + vaf XC0,XC0,XD0 + vx XB0,XB0,XC0 + verllf XB0,XB0,12 + + vaf XC1,XC1,XD1 + vx XB1,XB1,XC1 + verllf XB1,XB1,12 + + vaf XC2,XC2,XD2 + vx XB2,XB2,XC2 + verllf XB2,XB2,12 + + vaf XC3,XC3,XD3 + vx XB3,XB3,XC3 + verllf XB3,XB3,12 + + vaf XA0,XA0,XB0 + vx XD0,XD0,XA0 + verllf XD0,XD0,8 + + vaf XA1,XA1,XB1 + vx XD1,XD1,XA1 + verllf XD1,XD1,8 + + vaf XA2,XA2,XB2 + vx XD2,XD2,XA2 + verllf XD2,XD2,8 + + vaf XA3,XA3,XB3 + vx XD3,XD3,XA3 + verllf XD3,XD3,8 + + vaf XC0,XC0,XD0 + vx XB0,XB0,XC0 + verllf XB0,XB0,7 + + vaf XC1,XC1,XD1 + vx XB1,XB1,XC1 + verllf XB1,XB1,7 + + vaf XC2,XC2,XD2 + vx XB2,XB2,XC2 + verllf XB2,XB2,7 + + vaf XC3,XC3,XD3 + vx XB3,XB3,XC3 + verllf XB3,XB3,7 + + vaf XA0,XA0,XB1 + vx XD3,XD3,XA0 + verllf XD3,XD3,16 + + vaf XA1,XA1,XB2 + vx XD0,XD0,XA1 + verllf XD0,XD0,16 + + vaf XA2,XA2,XB3 + vx XD1,XD1,XA2 + verllf XD1,XD1,16 + + vaf XA3,XA3,XB0 + vx XD2,XD2,XA3 + verllf XD2,XD2,16 + + vaf XC2,XC2,XD3 + vx XB1,XB1,XC2 + verllf XB1,XB1,12 + + vaf XC3,XC3,XD0 + vx XB2,XB2,XC3 + verllf XB2,XB2,12 + + vaf XC0,XC0,XD1 + vx XB3,XB3,XC0 + verllf XB3,XB3,12 + + vaf XC1,XC1,XD2 + vx XB0,XB0,XC1 + verllf XB0,XB0,12 + + vaf XA0,XA0,XB1 + vx XD3,XD3,XA0 + verllf XD3,XD3,8 + + vaf XA1,XA1,XB2 + vx XD0,XD0,XA1 + verllf XD0,XD0,8 + + vaf XA2,XA2,XB3 + vx XD1,XD1,XA2 + verllf XD1,XD1,8 + + vaf XA3,XA3,XB0 + vx XD2,XD2,XA3 + verllf XD2,XD2,8 + + vaf XC2,XC2,XD3 + vx XB1,XB1,XC2 + verllf XB1,XB1,7 + + vaf XC3,XC3,XD0 + vx XB2,XB2,XC3 + verllf XB2,XB2,7 + + vaf XC0,XC0,XD1 + vx XB3,XB3,XC0 + verllf XB3,XB3,7 + + vaf XC1,XC1,XD2 + vx XB0,XB0,XC1 + verllf XB0,XB0,7 + brct %r0,.Loop_4x + + vaf XD0,XD0,CTR + + vmrhf XT0,XA0,XA1 # transpose data + vmrhf XT1,XA2,XA3 + vmrlf XT2,XA0,XA1 + vmrlf XT3,XA2,XA3 + vpdi XA0,XT0,XT1,0b0000 + vpdi XA1,XT0,XT1,0b0101 + vpdi XA2,XT2,XT3,0b0000 + vpdi XA3,XT2,XT3,0b0101 + + vmrhf XT0,XB0,XB1 + vmrhf XT1,XB2,XB3 + vmrlf XT2,XB0,XB1 + vmrlf XT3,XB2,XB3 + vpdi XB0,XT0,XT1,0b0000 + vpdi XB1,XT0,XT1,0b0101 + vpdi XB2,XT2,XT3,0b0000 + vpdi XB3,XT2,XT3,0b0101 + + vmrhf XT0,XC0,XC1 + vmrhf XT1,XC2,XC3 + vmrlf XT2,XC0,XC1 + vmrlf XT3,XC2,XC3 + vpdi XC0,XT0,XT1,0b0000 + vpdi XC1,XT0,XT1,0b0101 + vpdi XC2,XT2,XT3,0b0000 + vpdi XC3,XT2,XT3,0b0101 + + vmrhf XT0,XD0,XD1 + vmrhf XT1,XD2,XD3 + vmrlf XT2,XD0,XD1 + vmrlf XT3,XD2,XD3 + vpdi XD0,XT0,XT1,0b0000 + vpdi XD1,XT0,XT1,0b0101 + vpdi XD2,XT2,XT3,0b0000 + vpdi XD3,XT2,XT3,0b0101 + + vaf XA0,XA0,K0 + vaf XB0,XB0,K1 + vaf XC0,XC0,K2 + vaf XD0,XD0,K3 + + vperm XA0,XA0,XA0,BEPERM + vperm XB0,XB0,XB0,BEPERM + vperm XC0,XC0,XC0,BEPERM + vperm XD0,XD0,XD0,BEPERM + + vlm XT0,XT3,0(INP),0 + + vx XT0,XT0,XA0 + vx XT1,XT1,XB0 + vx XT2,XT2,XC0 + vx XT3,XT3,XD0 + + vstm XT0,XT3,0(OUT),0 + + la INP,0x40(INP) + la OUT,0x40(OUT) + aghi LEN,-0x40 + + vaf XA0,XA1,K0 + vaf XB0,XB1,K1 + vaf XC0,XC1,K2 + vaf XD0,XD1,K3 + + vperm XA0,XA0,XA0,BEPERM + vperm XB0,XB0,XB0,BEPERM + vperm XC0,XC0,XC0,BEPERM + vperm XD0,XD0,XD0,BEPERM + + clgfi LEN,0x40 + jl .Ltail_4x + + vlm XT0,XT3,0(INP),0 + + vx XT0,XT0,XA0 + vx XT1,XT1,XB0 + vx XT2,XT2,XC0 + vx XT3,XT3,XD0 + + vstm XT0,XT3,0(OUT),0 + + la INP,0x40(INP) + la OUT,0x40(OUT) + aghi LEN,-0x40 + je .Ldone_4x + + vaf XA0,XA2,K0 + vaf XB0,XB2,K1 + vaf XC0,XC2,K2 + vaf XD0,XD2,K3 + + vperm XA0,XA0,XA0,BEPERM + vperm XB0,XB0,XB0,BEPERM + vperm XC0,XC0,XC0,BEPERM + vperm XD0,XD0,XD0,BEPERM + + clgfi LEN,0x40 + jl .Ltail_4x + + vlm XT0,XT3,0(INP),0 + + vx XT0,XT0,XA0 + vx XT1,XT1,XB0 + vx XT2,XT2,XC0 + vx XT3,XT3,XD0 + + vstm XT0,XT3,0(OUT),0 + + la INP,0x40(INP) + la OUT,0x40(OUT) + aghi LEN,-0x40 + je .Ldone_4x + + vaf XA0,XA3,K0 + vaf XB0,XB3,K1 + vaf XC0,XC3,K2 + vaf XD0,XD3,K3 + + vperm XA0,XA0,XA0,BEPERM + vperm XB0,XB0,XB0,BEPERM + vperm XC0,XC0,XC0,BEPERM + vperm XD0,XD0,XD0,BEPERM + + clgfi LEN,0x40 + jl .Ltail_4x + + vlm XT0,XT3,0(INP),0 + + vx XT0,XT0,XA0 + vx XT1,XT1,XB0 + vx XT2,XT2,XC0 + vx XT3,XT3,XD0 + + vstm XT0,XT3,0(OUT),0 + +.Ldone_4x: + lmg %r6,%r7,6*8(SP) + br %r14 + +.Ltail_4x: + vlr XT0,XC0 + vlr XT1,XD0 + + vst XA0,8*8+0x00(SP) + vst XB0,8*8+0x10(SP) + vst XT0,8*8+0x20(SP) + vst XT1,8*8+0x30(SP) + + lghi %r1,0 + +.Loop_tail_4x: + llgc %r5,0(%r1,INP) + llgc %r6,8*8(%r1,SP) + xr %r6,%r5 + stc %r6,0(%r1,OUT) + la %r1,1(%r1) + brct LEN,.Loop_tail_4x + + lmg %r6,%r7,6*8(SP) + br %r14 + + .type chacha20_vx_4x, @function + .size chacha20_vx_4x, . - chacha20_vx_4x + +#undef OUT +#undef INP +#undef LEN +#undef KEY +#undef COUNTER + +#undef BEPERM + +#undef K0 +#undef K1 +#undef K2 +#undef K3 + + +############################################################################# +# void chacha20_vx(u8 *out, counst u8 *inp, size_t len, +# counst u32 *key, const u32 *counter) + +#define OUT %r2 +#define INP %r3 +#define LEN %r4 +#define KEY %r5 +#define COUNTER %r6 + +#define BEPERM %v31 + +#define K0 %v27 +#define K1 %v24 +#define K2 %v25 +#define K3 %v26 + +#define A0 %v0 +#define B0 %v1 +#define C0 %v2 +#define D0 %v3 + +#define A1 %v4 +#define B1 %v5 +#define C1 %v6 +#define D1 %v7 + +#define A2 %v8 +#define B2 %v9 +#define C2 %v10 +#define D2 %v11 + +#define A3 %v12 +#define B3 %v13 +#define C3 %v14 +#define D3 %v15 + +#define A4 %v16 +#define B4 %v17 +#define C4 %v18 +#define D4 %v19 + +#define A5 %v20 +#define B5 %v21 +#define C5 %v22 +#define D5 %v23 + +#define T0 %v27 +#define T1 %v28 +#define T2 %v29 +#define T3 %v30 + + .balign 32 +chacha20_vx: + clgfi LEN,256 + jle chacha20_vx_4x + stmg %r6,%r7,6*8(SP) + + lghi %r1,-FRAME + lgr %r0,SP + la SP,0(%r1,SP) + stg %r0,0(SP) # back-chain + + larl %r7,sigma + lhi %r0,10 + + vlm K1,K2,0(KEY),0 # load key + vl K3,0(COUNTER) # load counter + + vlm K0,BEPERM,0(%r7),4 # load sigma, increments, ... + +.Loop_outer_vx: + vlr A0,K0 + vlr B0,K1 + vlr A1,K0 + vlr B1,K1 + vlr A2,K0 + vlr B2,K1 + vlr A3,K0 + vlr B3,K1 + vlr A4,K0 + vlr B4,K1 + vlr A5,K0 + vlr B5,K1 + + vlr D0,K3 + vaf D1,K3,T1 # K[3]+1 + vaf D2,K3,T2 # K[3]+2 + vaf D3,K3,T3 # K[3]+3 + vaf D4,D2,T2 # K[3]+4 + vaf D5,D2,T3 # K[3]+5 + + vlr C0,K2 + vlr C1,K2 + vlr C2,K2 + vlr C3,K2 + vlr C4,K2 + vlr C5,K2 + + vlr T1,D1 + vlr T2,D2 + vlr T3,D3 + +.Loop_vx: + vaf A0,A0,B0 + vaf A1,A1,B1 + vaf A2,A2,B2 + vaf A3,A3,B3 + vaf A4,A4,B4 + vaf A5,A5,B5 + vx D0,D0,A0 + vx D1,D1,A1 + vx D2,D2,A2 + vx D3,D3,A3 + vx D4,D4,A4 + vx D5,D5,A5 + verllf D0,D0,16 + verllf D1,D1,16 + verllf D2,D2,16 + verllf D3,D3,16 + verllf D4,D4,16 + verllf D5,D5,16 + + vaf C0,C0,D0 + vaf C1,C1,D1 + vaf C2,C2,D2 + vaf C3,C3,D3 + vaf C4,C4,D4 + vaf C5,C5,D5 + vx B0,B0,C0 + vx B1,B1,C1 + vx B2,B2,C2 + vx B3,B3,C3 + vx B4,B4,C4 + vx B5,B5,C5 + verllf B0,B0,12 + verllf B1,B1,12 + verllf B2,B2,12 + verllf B3,B3,12 + verllf B4,B4,12 + verllf B5,B5,12 + + vaf A0,A0,B0 + vaf A1,A1,B1 + vaf A2,A2,B2 + vaf A3,A3,B3 + vaf A4,A4,B4 + vaf A5,A5,B5 + vx D0,D0,A0 + vx D1,D1,A1 + vx D2,D2,A2 + vx D3,D3,A3 + vx D4,D4,A4 + vx D5,D5,A5 + verllf D0,D0,8 + verllf D1,D1,8 + verllf D2,D2,8 + verllf D3,D3,8 + verllf D4,D4,8 + verllf D5,D5,8 + + vaf C0,C0,D0 + vaf C1,C1,D1 + vaf C2,C2,D2 + vaf C3,C3,D3 + vaf C4,C4,D4 + vaf C5,C5,D5 + vx B0,B0,C0 + vx B1,B1,C1 + vx B2,B2,C2 + vx B3,B3,C3 + vx B4,B4,C4 + vx B5,B5,C5 + verllf B0,B0,7 + verllf B1,B1,7 + verllf B2,B2,7 + verllf B3,B3,7 + verllf B4,B4,7 + verllf B5,B5,7 + + vsldb C0,C0,C0,8 + vsldb C1,C1,C1,8 + vsldb C2,C2,C2,8 + vsldb C3,C3,C3,8 + vsldb C4,C4,C4,8 + vsldb C5,C5,C5,8 + vsldb B0,B0,B0,4 + vsldb B1,B1,B1,4 + vsldb B2,B2,B2,4 + vsldb B3,B3,B3,4 + vsldb B4,B4,B4,4 + vsldb B5,B5,B5,4 + vsldb D0,D0,D0,12 + vsldb D1,D1,D1,12 + vsldb D2,D2,D2,12 + vsldb D3,D3,D3,12 + vsldb D4,D4,D4,12 + vsldb D5,D5,D5,12 + + vaf A0,A0,B0 + vaf A1,A1,B1 + vaf A2,A2,B2 + vaf A3,A3,B3 + vaf A4,A4,B4 + vaf A5,A5,B5 + vx D0,D0,A0 + vx D1,D1,A1 + vx D2,D2,A2 + vx D3,D3,A3 + vx D4,D4,A4 + vx D5,D5,A5 + verllf D0,D0,16 + verllf D1,D1,16 + verllf D2,D2,16 + verllf D3,D3,16 + verllf D4,D4,16 + verllf D5,D5,16 + + vaf C0,C0,D0 + vaf C1,C1,D1 + vaf C2,C2,D2 + vaf C3,C3,D3 + vaf C4,C4,D4 + vaf C5,C5,D5 + vx B0,B0,C0 + vx B1,B1,C1 + vx B2,B2,C2 + vx B3,B3,C3 + vx B4,B4,C4 + vx B5,B5,C5 + verllf B0,B0,12 + verllf B1,B1,12 + verllf B2,B2,12 + verllf B3,B3,12 + verllf B4,B4,12 + verllf B5,B5,12 + + vaf A0,A0,B0 + vaf A1,A1,B1 + vaf A2,A2,B2 + vaf A3,A3,B3 + vaf A4,A4,B4 + vaf A5,A5,B5 + vx D0,D0,A0 + vx D1,D1,A1 + vx D2,D2,A2 + vx D3,D3,A3 + vx D4,D4,A4 + vx D5,D5,A5 + verllf D0,D0,8 + verllf D1,D1,8 + verllf D2,D2,8 + verllf D3,D3,8 + verllf D4,D4,8 + verllf D5,D5,8 + + vaf C0,C0,D0 + vaf C1,C1,D1 + vaf C2,C2,D2 + vaf C3,C3,D3 + vaf C4,C4,D4 + vaf C5,C5,D5 + vx B0,B0,C0 + vx B1,B1,C1 + vx B2,B2,C2 + vx B3,B3,C3 + vx B4,B4,C4 + vx B5,B5,C5 + verllf B0,B0,7 + verllf B1,B1,7 + verllf B2,B2,7 + verllf B3,B3,7 + verllf B4,B4,7 + verllf B5,B5,7 + + vsldb C0,C0,C0,8 + vsldb C1,C1,C1,8 + vsldb C2,C2,C2,8 + vsldb C3,C3,C3,8 + vsldb C4,C4,C4,8 + vsldb C5,C5,C5,8 + vsldb B0,B0,B0,12 + vsldb B1,B1,B1,12 + vsldb B2,B2,B2,12 + vsldb B3,B3,B3,12 + vsldb B4,B4,B4,12 + vsldb B5,B5,B5,12 + vsldb D0,D0,D0,4 + vsldb D1,D1,D1,4 + vsldb D2,D2,D2,4 + vsldb D3,D3,D3,4 + vsldb D4,D4,D4,4 + vsldb D5,D5,D5,4 + brct %r0,.Loop_vx + + vaf A0,A0,K0 + vaf B0,B0,K1 + vaf C0,C0,K2 + vaf D0,D0,K3 + vaf A1,A1,K0 + vaf D1,D1,T1 # +K[3]+1 + + vperm A0,A0,A0,BEPERM + vperm B0,B0,B0,BEPERM + vperm C0,C0,C0,BEPERM + vperm D0,D0,D0,BEPERM + + clgfi LEN,0x40 + jl .Ltail_vx + + vaf D2,D2,T2 # +K[3]+2 + vaf D3,D3,T3 # +K[3]+3 + vlm T0,T3,0(INP),0 + + vx A0,A0,T0 + vx B0,B0,T1 + vx C0,C0,T2 + vx D0,D0,T3 + + vlm K0,T3,0(%r7),4 # re-load sigma and increments + + vstm A0,D0,0(OUT),0 + + la INP,0x40(INP) + la OUT,0x40(OUT) + aghi LEN,-0x40 + je .Ldone_vx + + vaf B1,B1,K1 + vaf C1,C1,K2 + + vperm A0,A1,A1,BEPERM + vperm B0,B1,B1,BEPERM + vperm C0,C1,C1,BEPERM + vperm D0,D1,D1,BEPERM + + clgfi LEN,0x40 + jl .Ltail_vx + + vlm A1,D1,0(INP),0 + + vx A0,A0,A1 + vx B0,B0,B1 + vx C0,C0,C1 + vx D0,D0,D1 + + vstm A0,D0,0(OUT),0 + + la INP,0x40(INP) + la OUT,0x40(OUT) + aghi LEN,-0x40 + je .Ldone_vx + + vaf A2,A2,K0 + vaf B2,B2,K1 + vaf C2,C2,K2 + + vperm A0,A2,A2,BEPERM + vperm B0,B2,B2,BEPERM + vperm C0,C2,C2,BEPERM + vperm D0,D2,D2,BEPERM + + clgfi LEN,0x40 + jl .Ltail_vx + + vlm A1,D1,0(INP),0 + + vx A0,A0,A1 + vx B0,B0,B1 + vx C0,C0,C1 + vx D0,D0,D1 + + vstm A0,D0,0(OUT),0 + + la INP,0x40(INP) + la OUT,0x40(OUT) + aghi LEN,-0x40 + je .Ldone_vx + + vaf A3,A3,K0 + vaf B3,B3,K1 + vaf C3,C3,K2 + vaf D2,K3,T3 # K[3]+3 + + vperm A0,A3,A3,BEPERM + vperm B0,B3,B3,BEPERM + vperm C0,C3,C3,BEPERM + vperm D0,D3,D3,BEPERM + + clgfi LEN,0x40 + jl .Ltail_vx + + vaf D3,D2,T1 # K[3]+4 + VLM A1,D1,0(INP),0 + + vx A0,A0,A1 + vx B0,B0,B1 + vx C0,C0,C1 + vx D0,D0,D1 + + vstm A0,D0,0(OUT),0 + + la INP,0x40(INP) + la OUT,0x40(OUT) + aghi LEN,-0x40 + je .Ldone_vx + + vaf A4,A4,K0 + vaf B4,B4,K1 + vaf C4,C4,K2 + vaf D4,D4,D3 # +K[3]+4 + vaf D3,D3,T1 # K[3]+5 + vaf K3,D2,T3 # K[3]+=6 + + vperm A0,A4,A4,BEPERM + vperm B0,B4,B4,BEPERM + vperm C0,C4,C4,BEPERM + vperm D0,D4,D4,BEPERM + + clgfi LEN,0x40 + jl .Ltail_vx + + vlm A1,D1,0(INP),0 + + vx A0,A0,A1 + vx B0,B0,B1 + vx C0,C0,C1 + vx D0,D0,D1 + + vstm A0,D0,0(OUT),0 + + la INP,0x40(INP) + la OUT,0x40(OUT) + aghi LEN,-0x40 + je .Ldone_vx + + vaf A5,A5,K0 + vaf B5,B5,K1 + vaf C5,C5,K2 + vaf D5,D5,D3 # +K[3]+5 + + vperm A0,A5,A5,BEPERM + vperm B0,B5,B5,BEPERM + vperm C0,C5,C5,BEPERM + vperm D0,D5,D5,BEPERM + + clgfi LEN,0x40 + jl .Ltail_vx + + vlm A1,D1,0(INP),0 + + vx A0,A0,A1 + vx B0,B0,B1 + vx C0,C0,C1 + vx D0,D0,D1 + + vstm A0,D0,0(OUT),0 + + la INP,0x40(INP) + la OUT,0x40(OUT) + lhi %r0,10 + aghi LEN,-0x40 + jne .Loop_outer_vx + +.Ldone_vx: + lmg %r6,%r7,FRAME+6*8(SP) + la SP,FRAME(SP) + br %r14 + +.Ltail_vx: + vstm A0,D0,8*8(SP),3 + lghi %r1,0 + +.Loop_tail_vx: + llgc %r5,0(%r1,INP) + llgc %r6,8*8(%r1,SP) + xr %r6,%r5 + stc %r6,0(%r1,OUT) + la %r1,1(%r1) + brct LEN,.Loop_tail_vx + + lmg %r6,%r7,FRAME+6*8(SP) + la SP,FRAME(SP) + br %r14 + + .type chacha20_vx, @function + .size chacha20_vx, . - chacha20_vx + .globl chacha20_vx + +.previous +.section .note.GNU-stack,"",%progbits From patchwork Sun Jan 21 00:20:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 764468 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:10c4:b0:337:62d3:c6d5 with SMTP id b4csp530411wrx; Sat, 20 Jan 2024 16:22:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6AzzZgEbhpD4tkfMGSdePGc4WZ6liR7r6EKMZoKWqx8QHjYfzUv3vukQzWiUn+WnQYfMm X-Received: by 2002:ac8:5705:0:b0:42a:3355:8e9 with SMTP id 5-20020ac85705000000b0042a335508e9mr1416316qtw.10.1705796565159; Sat, 20 Jan 2024 16:22:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705796565; cv=none; d=google.com; s=arc-20160816; b=owh9vyw1h1d3Lt0aH0WAvDbuGXiwBH7Bwsq13YEzeRFgjnfKMlBnR21s2cIKlqT6OP +hywsslPrI2y2GK92Tb7jXgvfBgopooUMwv/ui2xc+e8lFWfMy58Frb2unffP1GJYeIs m2mci+Z9hItJQZ76i6P/eQT+7aT1mh1kdJwmEo2k8umskpEGhMMH2JG7jcvaJDReITtj rJpXht5quC1WC3ITJVdZ4AlGODoFio1cfWvRniqpYa3OWpgzdJ5QatPMUIKBIxMCLOdL MfpVnYVGfqmCAzQMuaHoQUN1UICTQZTwC/llr+spDGb0z7PbhJgPeYzD9+oWIlzQBpRh S8Qw== 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:cc:to :from:dkim-signature; bh=9Xu/nq6hQa8ZLXYCRSmO5dgODT19xrskc9XyMf3C3fg=; fh=rygklo3k8rDrOxbqyqXzMeN1qJGr+RWlL94hCpxMPcs=; b=NqA3LGN1gtJFR8DiSCiRMz0EBCIIkeyci8csx0tArgZ4c8rNm7J134EpoEwVw9/eHQ 6vSCmv7T71xQlzP9hsLa2mOhqqRyFO45/2x5w5ZpxjRQdC3cE2ZICMT83lzIfntHmTzD +9zkk0+PThH7lOCpnK35l1aKX3biSl+GK+5zIgvn/nOyUWBYpRU3PY8x4JWk7pjYdsqS KhCraLZaQgzWRTBCyd44cveGsOePKQc3a6atG4vPCmYu3oPNkEMqP3HtzBdI+3ltP26J /zmqH45++6S0esZJBpS0LrBSPZ5xEwQ4ZVhfAbKhTpzWKNIzelje2tN7s4mugPPcVZPS 5Hmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Lh/EN2ES"; 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 pc47-20020a05620a842f00b00781a14c43besi2502223qkn.674.2024.01.20.16.22.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 20 Jan 2024 16:22:45 -0800 (PST) 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="Lh/EN2ES"; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rRLaO-0002YT-QF; Sat, 20 Jan 2024 19:21:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rRLaM-0002Xu-IV for qemu-devel@nongnu.org; Sat, 20 Jan 2024 19:21:15 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rRLaK-0007QS-Lc for qemu-devel@nongnu.org; Sat, 20 Jan 2024 19:21:14 -0500 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1d70c3c2212so13633335ad.1 for ; Sat, 20 Jan 2024 16:21:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705796471; x=1706401271; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9Xu/nq6hQa8ZLXYCRSmO5dgODT19xrskc9XyMf3C3fg=; b=Lh/EN2ESLax+74ILHQBcm1S3B7ftNg9aSWElRluOvgCpPyL0jmSSkr0uZtSzc01GnM dh1aOdgFEZ2JFWjalR0ZmknGa2HdhByJe1L2kEoU2Nl4VW9a4VBAB+EhOmOd3Nlp0s+3 5W37GqMe19udQ3/6v6nXCHms1pZMOAjTcXnb4F7tNxxWlkh7yLUvt9dT9YEHm5iXfz1k GA1yC8smVNHSRODsvjLzP85QSybcUbZCqpGbIFvAICkisymd96kXmiPknOi6jnoTELs0 EbOPpLwM+QdxIhIJijpO+64BCfzswFbtw+czPPVqX7RAGwAf48d4wTND4sWhm5xxG9AH J0jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705796471; x=1706401271; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9Xu/nq6hQa8ZLXYCRSmO5dgODT19xrskc9XyMf3C3fg=; b=OsT2Xw0zaa4v8oelyYwH/eTL1GqYXvUUl/irgutLhSUCNFzmxzVgkmbjFZvlCQOwfG C3wFMXnN5HN8M6/sDF17b8aaUmkZJe+4nbnQODczqI/+pUJWpqz7XU0EaqIJWsGRcLtl MIqthVA/bPvoPpONFK+wSHyTRaKfcO3w/0/Bo0tDjYnBvAyY9BOqnH/fxn5yqa0t7GAG 0lMazKZ7mMc/j4tps4jV6ewJKmc3zZFmnG01HSAFx/lidT+d+6eGaQ3mF9BC/wIyW8YM uBMSPGKjey4dTxNK2GUySZepRU/tsxYnaUvsARu+twTTAthO0A4I23MfKDKkcMAvK6t4 cUtA== X-Gm-Message-State: AOJu0Yw8Dzhqfb8kVoy8dF7r24+1UVtCArfOhsy3s62rWyJLVBRX/hip m7whCbhbIVVfw17lmMI7G78VYa1BXF0UnnjWETfhUQvSqnhjr+vzC4a29RU1txBDXWQoKbZTkf9 FTzc= X-Received: by 2002:a17:903:2306:b0:1d3:f344:6b01 with SMTP id d6-20020a170903230600b001d3f3446b01mr2831284plh.3.1705796471153; Sat, 20 Jan 2024 16:21:11 -0800 (PST) Received: from stoup.net ([2001:8004:5170:1e39:1361:3840:4873:7990]) by smtp.gmail.com with ESMTPSA id j4-20020a17090276c400b001d5af7fbda0sm5023546plt.122.2024.01.20.16.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 16:21:10 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Vineet Gupta Subject: [PULL 6/8] linux-user/riscv: Adjust vdso signal frame cfa offsets Date: Sun, 21 Jan 2024 11:20:45 +1100 Message-Id: <20240121002047.89234-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240121002047.89234-1-richard.henderson@linaro.org> References: <20240121002047.89234-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.google.com 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+patch=linaro.org@nongnu.org A typo in sizeof_reg put the registers at the wrong offset. Simplify the expressions to use positive addresses from the start of uc_mcontext instead of negative addresses from the end of uc_mcontext. Reported-by: Vineet Gupta Signed-off-by: Richard Henderson --- linux-user/riscv/vdso-32.so | Bin 2900 -> 2980 bytes linux-user/riscv/vdso-64.so | Bin 3856 -> 3944 bytes linux-user/riscv/vdso.S | 8 ++++---- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/linux-user/riscv/vdso-32.so b/linux-user/riscv/vdso-32.so index 1ad1e5cbbbb8b1fe36b0fe4bcb6c06fab8219ecd..c2ce2a4757900a16b891bb98f7a027ac30c47a5f 100755 GIT binary patch delta 643 zcmYjPOH5Ni6ur|gwzc+9XhF0TMNp`GR6Zh~mKGzXLQ}j z)#}rFqIBkAs)(L%{#f{&3ii(}e_yh8Pgey7+LRKpj+~BYkcbM&LN$yL<+mtroa4HJ zZMB#&#N4vYgN#$Ed?)jGwn>u^j$uL6%5;@6#JIs26v~>`CEXn6`%uX09<>tLIBejZ zFY)AcUK{^`w8`*U60=@WX3@OR=)D9Xp?Lu9eduPPPr;Cc@g53huwxpgyD;B@WePiQ z!+Hz5CSkh?Bv5z*_UkB`K=C*n*Cd=*Q4&Y#73{u@vN7x##oicPmry ze%vHqR9p0zd0b`2Q|4;3R+vXr`7g}X=20v*GSM6w@2yKvwky9(Ht|*2WbKiW=;xN^G26tL(qVS~ E1D4W)y8r+H delta 565 zcmZ1?eno780^^#AispCEGBkVi#XS5FJ{d(y6ALK`0fjZ#F<&4uOCj9 zVB90Pf`x%0f`NfSh=GSe3rO=!e#$6sXaLm50TmSm(hNX850vi%q*ajQ?SOoV&8AHG zjA8N59(ymx)f3 z946aMv6*T$&0@OQ43n8gvkYeI&C!{wHBV!{+5(q_PELy)7TYbcS!%V+V!7E0la)rR z3|8x{(OIjtPGh~=29=FUn-n(7ZIRh3wM}BX*bb4MLc0WZ^X=i;%e9YVKO5Mwb2h(Z zS%t*xcjTq|2?Y1y{IoJiPMVG&Z%B2pwIB5I9(EFvNz z?)pL^MhuHse{pSyL_`lkFFpi~An2jTdJL*3ANrQJmv!LB`8el0AAG-~d%k&ezwB?w z2F6$=o7t~c%+g;}vY+2KKi``ijg36bKRDF->-VRR@qD&8Un;XH#&qseT&%$Rm2UT< z5wR{OC8yv~N7E5BABJ-bD-Xhz0JX&79!2Xuw2ffZFjf!2GYIbPUycy@b0)t*m;96aGkL08X> zzGUeUrG%_8_LX0>9{X?YDUqp`qVpeCm%D6~@^8O6!(HS))fFn#xbF-%SEEbG?2`}67j2EFQ> zo3}9LFfy7BQ|eju4WV! zVPs&i0SYMq=>Q<@1Ed)yJF+U*UjQfLI5JPe5rP#V`Xz00DDVP%r~yjRT`J z57PlQR)-eG#s?tWjs-3YofbJbEw)=?v(##t#d5P1CM%6r8LZY@qqA0P zoyK~#4JsRzHYseD+aj}7YMaD%u^l2ig?0(-=G()wmunx#evpSj4qh<1k!|y419kyW za5-|gGn!0n6rMbX!-TP6@k;>oa*G zP}TuWFGF&2M1Z-gk@Mz*obD`4Zx|+X@#%5GYydif&z`YjawDHTFrX$M;kzXAEcnEna diff --git a/linux-user/riscv/vdso.S b/linux-user/riscv/vdso.S index a86d8fc488..c37275233a 100644 --- a/linux-user/riscv/vdso.S +++ b/linux-user/riscv/vdso.S @@ -101,12 +101,12 @@ endf __vdso_flush_icache .cfi_startproc simple .cfi_signal_frame -#define sizeof_reg (__riscv_xlen / 4) +#define sizeof_reg (__riscv_xlen / 8) #define sizeof_freg 8 -#define B_GR (offsetof_uc_mcontext - sizeof_rt_sigframe) -#define B_FR (offsetof_uc_mcontext - sizeof_rt_sigframe + offsetof_freg0) +#define B_GR 0 +#define B_FR offsetof_freg0 - .cfi_def_cfa 2, sizeof_rt_sigframe + .cfi_def_cfa 2, offsetof_uc_mcontext /* Return address */ .cfi_return_column 64 From patchwork Sun Jan 21 00:20:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 764469 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:10c4:b0:337:62d3:c6d5 with SMTP id b4csp530441wrx; Sat, 20 Jan 2024 16:22:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFDeaB3zP3VLXS6BtTiwqn2Fkb65axCMy8tg9l5nhjS+bPfYG+3yIg93FPOHYwCgzUq5Hwt X-Received: by 2002:a05:620a:4095:b0:783:4386:71a4 with SMTP id f21-20020a05620a409500b00783438671a4mr3242804qko.116.1705796570648; Sat, 20 Jan 2024 16:22:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705796570; cv=none; d=google.com; s=arc-20160816; b=KxmaK1Ha1RRgd3uknDBiFZ7xirow6FvQZ1KSgIYJdh1PrXc9rV3v3nZG5BS+FRjH0u nLZ/Ct8p+8IrG9cErcqaxV/9hX5Ekzhj88idB0+qWPW8NkDVn1bedP9U85y4rTKwxdps V1YhT3mG7m7n5HItXV1ZZpoxEM/IKJviIN42LyMkNEF5ZOmm3ujiltD90XXHfrgxCixX TaVxyIyzTLZUPToIxbnoV6iJTyh2Na6nkdz0+HQLOEs5iUTT3RyR/pjKY2tREZ+11i0D HgXZPKvCbrA3JYzzqLXiSXTQXMI6KuqcvA00aqNtd/Xljto2/JU71r4w8K8Dd9ijPWEL AO2g== 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:cc:to :from:dkim-signature; bh=xu2jaDl0CebkWF1EGwbc5gC+5GyuWO8TNdEnyUmyH68=; fh=bMwgPfaZtp2zWGFrNOM6woPJjiMxnLFtehHnbkwxg4U=; b=VIIa7+WL0idndxC+W1RXm9+tjDv2xZY6+2j5sf/XhMCSWwaLxXcAzQRWpLrEaqK/X0 zOF5vQvgIPgEcDQtHTN1kNxmTIxm0R/7IqfucZVh7v+v539DYInePdn7lFC5KYumf9jx ULaYYR3mNIME58/lexMlaFl7EjRKz7oBPewaKnqrlTPVpvNl4NR3XgJ4oDuEgi3murVk 6KEXcXECxdRnSzTY/xCqbX+hVOSh1KqUk2HzNgeNAJYVhfR3V7YxKFEDes1cXKZHEUQu B9jtD56cOakAV51xi0PfxXH747fcQ3nJWEqubMqYcsWhnuTjHOm788f/y3Pix8T5MhAH 0xAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zB1ECvkm; 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 v19-20020a05620a0a9300b0078368f6a499si2485039qkg.742.2024.01.20.16.22.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 20 Jan 2024 16:22:50 -0800 (PST) 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=zB1ECvkm; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rRLaP-0002Yk-IQ; Sat, 20 Jan 2024 19:21:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rRLaO-0002YQ-MY for qemu-devel@nongnu.org; Sat, 20 Jan 2024 19:21:16 -0500 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rRLaN-0007Qn-7O for qemu-devel@nongnu.org; Sat, 20 Jan 2024 19:21:16 -0500 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1d6fbaaec91so16701885ad.3 for ; Sat, 20 Jan 2024 16:21:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705796473; x=1706401273; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xu2jaDl0CebkWF1EGwbc5gC+5GyuWO8TNdEnyUmyH68=; b=zB1ECvkmgrwdiPenZzDGtE9p4m1jwc6vpFoDjMd1cduNtOx/E929wuuMPYda6+eviD MWW/AKc4H7ENq2NfdjXW2wt5P8NTOD+p0zQULfV4UnQyxqyx6Z8uwZlvxqUK1AdRE0ML lQlz/AcoSmMqEYwmVhzthfFYPTM7CyhVQJi63hKdVRHfG4QYkoDXrzhFEE8kCaltIhAy g6W7iLyTYs2yfI6XN76SVsQfOJlHBujBn80Zp5/7SgtiWgd/UMd/Mqy4KJJnjznV3avi U9eEAvFkB/ADh8e9Thukz2ng9wiLQ2S69tkr/5zvOOPu9tQmTT1qTMZWvOE3oW7yktkJ xq4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705796473; x=1706401273; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xu2jaDl0CebkWF1EGwbc5gC+5GyuWO8TNdEnyUmyH68=; b=ewAIsSmCbFXPHmbryPZIuGUJA0hyWjv7s8sk+4QvZoKDA0OvpC5Gb6tvztLXeCdKBH lzMkJptjyqB+Ciyel6YhpAvSLTxolVloaHrLieY13RsNWjbCtX1iASzgouciXzNMVJbb C0vQk7kPcAbak6PFJiWz3trOQOraN8qxYQK/PBrfB7zx/1B4eVIsLIcAS+Q69fYieYOY vKUkH4vaT3ZhAVv9wUWPC/DK6haLs/kl4qu5bUI821SC9k/DO//uOtC/cpF/lSo5KFPZ h6LpP1LiDZvgzDQSEbgpk9Hxwa5WZHQccoxSU5hL+LcO6SVQJK4bLjqQUfn0gHoV8Buv rsCQ== X-Gm-Message-State: AOJu0Yzr9aM/FdUn3NzO0WFEjL+CcO+J8AdVAaWUZOnQIimPWMw5Mk2s 83FiVPxJe9LEr+5j+3z4Iw6unoEuaV8wvZoPQ54ti85wNLLPfpoIaVNaFanKL3GAyLlPdQ3QHLh Q5Gc= X-Received: by 2002:a17:902:e852:b0:1d7:41b7:332b with SMTP id t18-20020a170902e85200b001d741b7332bmr875256plg.14.1705796473556; Sat, 20 Jan 2024 16:21:13 -0800 (PST) Received: from stoup.net ([2001:8004:5170:1e39:1361:3840:4873:7990]) by smtp.gmail.com with ESMTPSA id j4-20020a17090276c400b001d5af7fbda0sm5023546plt.122.2024.01.20.16.21.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 16:21:13 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PULL 7/8] linux-user/elfload: test return value of getrlimit Date: Sun, 21 Jan 2024 11:20:46 +1100 Message-Id: <20240121002047.89234-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240121002047.89234-1-richard.henderson@linaro.org> References: <20240121002047.89234-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.google.com 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+patch=linaro.org@nongnu.org From: Thomas Weißschuh Should getrlimit() fail the value of dumpsize.rlimit_cur may not be initialized. Avoid reading garbage data by checking the return value of getrlimit. Reviewed-by: Richard Henderson Signed-off-by: Thomas Weißschuh Message-Id: <20240120-qemu-user-dumpable-v3-1-6aa410c933f1@t-8ch.de> Signed-off-by: Richard Henderson --- linux-user/elfload.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index cf9e74468b..c596871938 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4667,9 +4667,9 @@ static int elf_core_dump(int signr, const CPUArchState *env) init_note_info(&info); errno = 0; - getrlimit(RLIMIT_CORE, &dumpsize); - if (dumpsize.rlim_cur == 0) + if (getrlimit(RLIMIT_CORE, &dumpsize) == 0 && dumpsize.rlim_cur == 0) { return 0; + } corefile = core_dump_filename(ts); From patchwork Sun Jan 21 00:20:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 764461 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:10c4:b0:337:62d3:c6d5 with SMTP id b4csp530283wrx; Sat, 20 Jan 2024 16:22:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGs3q+IYUhNBCy3WVDvtTIM1leI3nMfsH4zpcNY745kV8n68+qYZXL6Dh3KaWjn/ss8I20H X-Received: by 2002:a05:620a:24d0:b0:781:45db:8024 with SMTP id m16-20020a05620a24d000b0078145db8024mr3243206qkn.53.1705796539228; Sat, 20 Jan 2024 16:22:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705796539; cv=none; d=google.com; s=arc-20160816; b=PzosWsQZwx2K4wsbsVW2c/TfNrhqyW2E405FvNf5S27iwmOxgRdflm3ANNUEPJmqer HB0l3QiPCp6rgMK66nr7F5TsL1K1ICEg1rRcdGuLbuQ7Wx1UST9AL6fUYyoPStd/YBZW OXVrgnE6qXkFazLI1ovsA+FnLTTOlJpWsAkY031af8Vms53NbkFMB2u6vDfvGY7Ump2d mBBL6123NKH1Hk5j1L4OjvgZks+z//ptDhhSaBe2A4bqGVDbwpoKHyqDEwB2WkwH5dQQ jdtoDYcFFV4qlBPOuHit7ktip8XYfTtn+qwjiiO4pYMEXa1hQGqEqOxHI0FIyB4azfnl SsgQ== 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:cc:to :from:dkim-signature; bh=AszAzFAp6jrF5ZpcMELuMynXb9ZnBs+nghMoHKpvVGo=; fh=bMwgPfaZtp2zWGFrNOM6woPJjiMxnLFtehHnbkwxg4U=; b=E6ftDf+Gj2+jlOtaD0fBnHODaFgYOhcqN02P1I8vfw9J45xrbhl59LXawVTiLZrbED tbNU4LppHB4E3EzIBa5e3pLOAqbu/8kcRxHhj15CD8jzV+GR1oq2nx4ZxYZnZCEYu3mR y9IcFBkZssRmPOoaN6emmwX08Nr30mzR8LloLJwKQ83pYaAlrkhDhjrJ8jmcupNkfh5V 5mRfj1/QidPrtMC/4nxtnR6QKnWRz3x8r8BSCPk9L58PosccO1wK1r6eTw3j915OIt6B HVskmZrhhQW+AG8PUPxQbgnDKxqDoOM+vV6BPTNPhnR4QF3zXGAue6NqS+NEijT5MShE LLRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rusVckiW; 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 c21-20020a37e115000000b0078314d62c12si2528914qkm.676.2024.01.20.16.22.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 20 Jan 2024 16:22:19 -0800 (PST) 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=rusVckiW; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rRLaS-0002ZG-Dz; Sat, 20 Jan 2024 19:21:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rRLaQ-0002Yr-DT for qemu-devel@nongnu.org; Sat, 20 Jan 2024 19:21:18 -0500 Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rRLaO-0007RM-TH for qemu-devel@nongnu.org; Sat, 20 Jan 2024 19:21:18 -0500 Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-361ae51a4d9so5617905ab.1 for ; Sat, 20 Jan 2024 16:21:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705796476; x=1706401276; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AszAzFAp6jrF5ZpcMELuMynXb9ZnBs+nghMoHKpvVGo=; b=rusVckiWhew5o9FyoD9wdQAgIw9aUm8aOym54TDh1ozMzNfdcwXeoBLZnLEJyyxrx3 vczkPgABUICoEKlNWX78cNhZz4vx15AivBIIJlwg+wFWmdgFGgLT4iK0rasZzQBOYGYB ZkQjvQZhHadzMtRSp3rJw8EPwNXaau4YBVc0UNKu7wF7yokm8n5WP3TSEXI2bZljOgLx bAz6WufDn+x3Q4PpBqoS9EnEHMIxPd9gfHqYVTRnjoUka+/oJ91UysJAeTpIyKzb9qh8 Q/DszWP0V0UAA+zJ2byhoCz6Oxmf08L8mGY5/PuSjmaabvfacxonS/WG+VmHM9npsEsh QW+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705796476; x=1706401276; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AszAzFAp6jrF5ZpcMELuMynXb9ZnBs+nghMoHKpvVGo=; b=V3ERk6n/Rb4hlwrYafJTexuinREbjcxnANg1dZrx2TESrF7esLrdNe57PZcNfR6Zh1 xR4eAYhSd5AgGX7I9N+GzD46TIlSvwFCHyW09QCjzTFD1C8z2ZyEZtyUg6uVIaFkNlP9 FS7S9ucGEmThMYIS1MICFqLerZMpYW/3Bl2VcWrDh5EP55KljiQAYlE40MyTFQqrwvf7 3tlQsJVAmrOK6REt3hH7QMHARFEEBx49rXjOwQt1hc5J7m9YTL5YDOA32ms++3x0gcuu Mk6lZe6dTgka9phPhzO3Is0p3UP/1hXUUt0MvN6nNt13N7Iro6RHhjEHUJeW3GVMs4/n mrmw== X-Gm-Message-State: AOJu0YzKUHZ8kQeer9vs/RajK8byugWw/cP1Al2Mzvd6QZHcB6t/yoT5 5X0qKb3/l3y38xkRjITcHQZd/93Tc83EHU5KjJ96WKV3+2DVFaC0rkVRjbXDUPIsO3lOAJO9VZ9 mWD4= X-Received: by 2002:a05:6e02:f14:b0:35f:ca9d:6c42 with SMTP id x20-20020a056e020f1400b0035fca9d6c42mr3071536ilj.4.1705796475892; Sat, 20 Jan 2024 16:21:15 -0800 (PST) Received: from stoup.net ([2001:8004:5170:1e39:1361:3840:4873:7990]) by smtp.gmail.com with ESMTPSA id j4-20020a17090276c400b001d5af7fbda0sm5023546plt.122.2024.01.20.16.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 16:21:15 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PULL 8/8] linux-user/elfload: check PR_GET_DUMPABLE before creating coredump Date: Sun, 21 Jan 2024 11:20:47 +1100 Message-Id: <20240121002047.89234-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240121002047.89234-1-richard.henderson@linaro.org> References: <20240121002047.89234-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::134; envelope-from=richard.henderson@linaro.org; helo=mail-il1-x134.google.com 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+patch=linaro.org@nongnu.org From: Thomas Weißschuh A process can opt-out of coredump creation by calling prctl(PR_SET_DUMPABLE, 0). linux-user passes this call from the guest through to the operating system. >From there it can be read back again to avoid creating coredumps from qemu-user itself if the guest chose so. Reviewed-by: Richard Henderson Signed-off-by: Thomas Weißschuh Message-Id: <20240120-qemu-user-dumpable-v3-2-6aa410c933f1@t-8ch.de> Signed-off-by: Richard Henderson --- linux-user/elfload.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index c596871938..daf7ef8435 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2,6 +2,7 @@ #include "qemu/osdep.h" #include +#include #include #include @@ -4667,6 +4668,11 @@ static int elf_core_dump(int signr, const CPUArchState *env) init_note_info(&info); errno = 0; + + if (prctl(PR_GET_DUMPABLE) == 0) { + return 0; + } + if (getrlimit(RLIMIT_CORE, &dumpsize) == 0 && dumpsize.rlim_cur == 0) { return 0; }