From nobody Sun Nov 24 10:33:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1724207246; cv=none; d=zohomail.com; s=zohoarc; b=fXlJkmlBjuF6od9d4z6Dfil6gkwvhVrM8xVPmUAtQKHFErNUk0/Q3JKz98nVRoNECdBsWuuB84/N/AO/Y0yT+3KYUzgfMRMz2i2uELmJ+XYUownlA1yXE6Tvkkgu+YfI0cQ5Sklz5xrKAteZ9GzxXQWylBgpjoCNIt04z5uTGLc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724207246; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=S39pbsi04lxxgffqB3S31UEXKo2fS7pxTQUq/De0mMM=; b=dxJQ+YGPqTGLixUoiwb0Yaj20gdqho+4bR4cJDlv+JQxQ4ID7Er0q1OtriveRCVxVbF0eVWURLjRnboEv4FVS1yXcm9xEkXeuszAmC04wZ26HSHgpVRxZ0HVucBkXjgP+qOQ3/TREggxikmsMoGtlVU+JeJlo+BdwhDEdATLnM8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724207246394926.2325261797351; Tue, 20 Aug 2024 19:27:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sgb30-0000eO-A9; Tue, 20 Aug 2024 22:26:06 -0400 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 1sgb2y-0000VH-Ac for qemu-devel@nongnu.org; Tue, 20 Aug 2024 22:26:04 -0400 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sgb2v-0006DM-Uc for qemu-devel@nongnu.org; Tue, 20 Aug 2024 22:26:03 -0400 Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-7093c94435bso2381032a34.0 for ; Tue, 20 Aug 2024 19:25:57 -0700 (PDT) Received: from stoup.. ([203.56.140.20]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127af1888esm9210774b3a.149.2024.08.20.19.25.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 19:25:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724207157; x=1724811957; 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=S39pbsi04lxxgffqB3S31UEXKo2fS7pxTQUq/De0mMM=; b=Ff83HT2+bhzCkN8PtwxeEw6vJ26ve01tJoWokh4hhWdjQ1UwFvds7mJSdpB+AVW1bh Z+APVO99bbSGnYnlcVxG9rv2MT/1p2k8xbuaOyWP8F/EVybAhlMa6shEvuBUbGLs3WUf zWvU3b5gsXwPNbIKLPObzQP5pUsmM1NGpUATORAqFWxP+M7JF6dhVFIaidYSAcgWz3YL Ooe6YBvL7j9ignw/TEzBDRT9n44xO1PYX+jN2AZmC7nq73SiE9ZRPMWPhFlpa7yS3pPQ 1tyx5REKwVvqQneq7elKdJhFjaeAj0Fuebat/lbEzf7NFt8zE9DlagV52fkyGIzMjjOj GTvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724207157; x=1724811957; 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=S39pbsi04lxxgffqB3S31UEXKo2fS7pxTQUq/De0mMM=; b=ehxB/ypFojd7qNpBmlyQq+J+xvfoEcsDX8YvQEYc8xYQPcJw2/7NMCFHf63SrAEN08 Zyhhu37w1b1NGzWh3yW0Mw1aypkzDIN8olG/bHF773f3EXsT/YjoHEZT8Z9BLtF5sSzm Dtoiwy5wKBAIiYaV+8i3+8X9hpSAP7Sd/4uJyq/k3y1CPxduRl2k3Kj006vxHDNcRGhU 9KhyCb82uFipLMcjR3fFi4b3TZ8Fp9mSBTZozNmp8MddJH+Al+64aAy+flR1PlBIQoGt 3J7kWB2xB3q5iNuzktq1xAoIJdHHYR74k7t8qdvUbxUdu7InLHua3lMPFejTvMSbPt2X WXfQ== X-Gm-Message-State: AOJu0YyAfSFZOwCr+XskAz+g66w/Xku7AeEQYJBSZAGtnZJmu71rOWQx hZ9EVVkGkOXlGrkcq+Xixb1st13qf1wbdb2AzMhe8nvK0yfrWCrPuBBd30W6v/kn6uM/RaBIlB+ 0HiM= X-Google-Smtp-Source: AGHT+IFUZosUPjiuiQ4dDhrvSmPTEOjvr/XEeQxubZowfYq4JejiOT2H++HI9lL7R6H1OLficxKBpg== X-Received: by 2002:a05:6870:82a2:b0:258:5143:a21a with SMTP id 586e51a60fabf-2737ef0023bmr845403fac.13.1724207156792; Tue, 20 Aug 2024 19:25:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 1/5] linux-user: Handle short reads in mmap_h_gt_g Date: Wed, 21 Aug 2024 12:25:44 +1000 Message-ID: <20240821022548.421745-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240821022548.421745-1-richard.henderson@linaro.org> References: <20240821022548.421745-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::336; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x336.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1724207247569116600 In particular, if an image has a large bss, we can hit EOF before reading all host_len bytes of the mapping. Create a helper, mmap_pread to handle the job for both the larger block in mmap_h_gt_g itself, as well as the smaller block in mmap_frag. Cc: qemu-stable@nongnu.org Fixes: eb5027ac618 ("linux-user: Split out mmap_h_gt_g") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2504 Signed-off-by: Richard Henderson Message-Id: <20240820050848.165253-2-richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/mmap.c | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 6418e811f6..e4bf5d5f39 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -283,6 +283,40 @@ static int do_munmap(void *addr, size_t len) return munmap(addr, len); } =20 +/* + * Perform a pread on behalf of target_mmap. We can reach EOF, we can be + * interrupted by signals, and in general there's no good error return pat= h. + * If @zero, zero the rest of the block at EOF. + * Return true on success. + */ +static bool mmap_pread(int fd, void *p, size_t len, off_t offset, bool zer= o) +{ + while (1) { + ssize_t r =3D pread(fd, p, len, offset); + + if (likely(r =3D=3D len)) { + /* Complete */ + return true; + } + if (r =3D=3D 0) { + /* EOF */ + if (zero) { + memset(p, 0, len); + } + return true; + } + if (r > 0) { + /* Short read */ + p +=3D r; + len -=3D r; + offset +=3D r; + } else if (errno !=3D EINTR) { + /* Error */ + return false; + } + } +} + /* * Map an incomplete host page. * @@ -357,10 +391,9 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong = start, abi_ulong last, /* Read or zero the new guest pages. */ if (flags & MAP_ANONYMOUS) { memset(g2h_untagged(start), 0, last - start + 1); - } else { - if (pread(fd, g2h_untagged(start), last - start + 1, offset) =3D= =3D -1) { - return false; - } + } else if (!mmap_pread(fd, g2h_untagged(start), last - start + 1, + offset, true)) { + return false; } =20 /* Put final protection */ @@ -853,8 +886,7 @@ static abi_long mmap_h_gt_g(abi_ulong start, abi_ulong = len, } =20 if (misaligned_offset) { - /* TODO: The read could be short. */ - if (pread(fd, p, host_len, offset + real_start - start) !=3D host_= len) { + if (!mmap_pread(fd, p, host_len, offset + real_start - start, fals= e)) { do_munmap(p, host_len); return -1; } --=20 2.43.0 From nobody Sun Nov 24 10:33:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1724207245; cv=none; d=zohomail.com; s=zohoarc; b=QM9yGgpLlF6PF4/jlP1TyWk7ZHv6BYTquwf72YXo1y1f3qbiJBUaFSkNKNWwB6uPGnLmB8UsQ/wgul2mLuy8lBak2W/tKEy0tMPADeC6qAV4C6Njg325lyP0OAjEKEW4FIcbXK6qqCf9dV7nT+Ykftw4ajW4kiqIz0fr3PurrbE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724207245; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DVcCgltg45eJ8LECAIKCmNL12zJBy0OXmSR3imxiWNo=; b=WN2i6wbf2cbc4NjLZNijdAQB9nNC6V/V2AwPo7g2YFxLC9vxts8FL5yauYyTBt51WiUZp3x6ZXJZYAl+71Ew6sOC9R3siAr//Cmm0nCB4L0rs82+ZQA0VHPFmvYax3NjqmuttvAs8kowPQAqP3jb9VNzV0FVrgWFrj2m5luzOnk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724207245030236.28981663092384; Tue, 20 Aug 2024 19:27:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sgb30-0000in-Sb; Tue, 20 Aug 2024 22:26:06 -0400 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 1sgb2z-0000Yd-21 for qemu-devel@nongnu.org; Tue, 20 Aug 2024 22:26:05 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sgb2v-0006DX-WE for qemu-devel@nongnu.org; Tue, 20 Aug 2024 22:26:04 -0400 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-7c3ebba7fbbso4784544a12.1 for ; Tue, 20 Aug 2024 19:26:00 -0700 (PDT) Received: from stoup.. ([203.56.140.20]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127af1888esm9210774b3a.149.2024.08.20.19.25.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 19:25:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724207159; x=1724811959; 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=DVcCgltg45eJ8LECAIKCmNL12zJBy0OXmSR3imxiWNo=; b=evdP1HR6rlLBMhqk2yOACd+DmV4AsUz1kPdFQbvIglXi/LFRTSDaVY4bDI1I7cyf9k W2eY97VhaEeims1gftMuYUYEO/pJ7q29Hv95OgyvPwlChFp14JOWOfImIqpqE//ymmfn aZUvBPfHWonKPH1U99Pj1CQqpZogXhmYYf/BkEat/dvgQuH9LxN1/rkJlGZ9XfYq3AU+ VNd9y/JQAUXu/HSHCH2nI+kMPGbW32X7yJYFEhYdEbn/F9GI5SDA4EUlVcQsg7ZBD75b eQoG1+i8qQWEroCEBzSnAzqMRljDTaA1+gZKzl6yBAvr7kp9i7RvE3JjtJIHweKSZFvg hJsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724207159; x=1724811959; 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=DVcCgltg45eJ8LECAIKCmNL12zJBy0OXmSR3imxiWNo=; b=u3/TrkC+OPjojhKMDKhh/UUqiM3zZS61AlwMunDaJe/3sdnJBwc6gcdS6VZEbttM98 F5J+yaV4AwpahHD6+/lkYS77y0U1T7XzF+WrAajgwMZUCQYNhc+0/MvPdpOFH2mz9/UY rLhyD7CQ1pNyDTwMdWVcCIoyhFYp5A8Rd6BT7UcY8osQXPROrOW0tDSfCkV+F6fhnESP Vz+X8imNsYmSMPXuPfm9T0iJqAi+TWg1WlVbLYZui45/W2Jdf36kCaq7BqB+jo4SWuLr 5PZwiWCEECqX5IxI6PkBMEMeWHudUX8v8vgWT73mhvWjcbrp+mTTduPDhOTPVveoh2LX y/Zg== X-Gm-Message-State: AOJu0Yw88uC/s9F15hWCrsYDSQjn+gcsRqbWfofOW4y6zuI6hL3XdaeU UWRF0h74OqMeiKNQPt8V4ebXttlXzGKZJVNEKBewtzdOFVSWvxH9eSTW+b/mjaHo2R6A+Ksxit2 4XIc= X-Google-Smtp-Source: AGHT+IHvJWj7ZeU3TEX8jUo74HytAI/ZtpH/4KCUGpP9VgWJNcBS7Lj0OIScHIKn76qE5ClgqVXM9w== X-Received: by 2002:a05:6a21:920b:b0:1be:c5d9:5a19 with SMTP id adf61e73a8af0-1cad7fb1d21mr1970420637.24.1724207158960; Tue, 20 Aug 2024 19:25:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 2/5] bsd-user: Handle short reads in mmap_h_gt_g Date: Wed, 21 Aug 2024 12:25:45 +1000 Message-ID: <20240821022548.421745-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240821022548.421745-1-richard.henderson@linaro.org> References: <20240821022548.421745-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x530.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1724207245862116600 In particular, if an image has a large bss, we can hit EOF before reading all bytes of the mapping. Mirror the similar change to linux-user. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20240820050848.165253-3-richard.henderson@linaro.org> --- bsd-user/mmap.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index f3a4f1712d..775e905960 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -128,6 +128,40 @@ error: return ret; } =20 +/* + * Perform a pread on behalf of target_mmap. We can reach EOF, we can be + * interrupted by signals, and in general there's no good error return pat= h. + * If @zero, zero the rest of the block at EOF. + * Return true on success. + */ +static bool mmap_pread(int fd, void *p, size_t len, off_t offset, bool zer= o) +{ + while (1) { + ssize_t r =3D pread(fd, p, len, offset); + + if (likely(r =3D=3D len)) { + /* Complete */ + return true; + } + if (r =3D=3D 0) { + /* EOF */ + if (zero) { + memset(p, 0, len); + } + return true; + } + if (r > 0) { + /* Short read */ + p +=3D r; + len -=3D r; + offset +=3D r; + } else if (errno !=3D EINTR) { + /* Error */ + return false; + } + } +} + /* * map an incomplete host page * @@ -190,7 +224,7 @@ static int mmap_frag(abi_ulong real_start, mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE); =20 /* read the corresponding file data */ - if (pread(fd, g2h_untagged(start), end - start, offset) =3D=3D -1)= { + if (!mmap_pread(fd, g2h_untagged(start), end - start, offset, true= )) { return -1; } =20 @@ -565,7 +599,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, -1, 0); if (retaddr =3D=3D -1) goto fail; - if (pread(fd, g2h_untagged(start), len, offset) =3D=3D -1) { + if (!mmap_pread(fd, g2h_untagged(start), len, offset, false)) { goto fail; } if (!(prot & PROT_WRITE)) { --=20 2.43.0 From nobody Sun Nov 24 10:33:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1724207233; cv=none; d=zohomail.com; s=zohoarc; b=dX1CCDiB4XkzdzVBku/HA50DgZity/vNjl5172Javlz486YWvguPZHIeoNqtWfYr21MSqL0CxumWd9MCafqE1bKEwxBPk6XujfQ2XmtnZNfLg/Cday9UTy/SYO/CKoHXc54oJg5RjyJJcTpxC4kI+Lfk1dvFgBJoFa1aPY/T38k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724207233; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/AkyOxiQ4TXnW/njwRxZXuZWiuFAeAcYAa7CbQEQtFY=; b=V7i2vIRUEfW0oMIxablqgo8AZFoVeiVvMBDpTNjAnmC93PfO1zyH8xttjad9MpIB2HYliWQE/+uA2ukwbfIboyM03i8pxKNoEOgyDO+a3NNKKkcs0/7G9J4/LQzBnlrqL1xPwgiszqm312ZugzuP4qyQ5zY03AUAgkVvGPpBFeM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724207233261967.0638334775168; Tue, 20 Aug 2024 19:27:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sgb33-0000rT-Or; Tue, 20 Aug 2024 22:26:09 -0400 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 1sgb2z-0000ZC-5J for qemu-devel@nongnu.org; Tue, 20 Aug 2024 22:26:05 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sgb2x-0006Dd-8N for qemu-devel@nongnu.org; Tue, 20 Aug 2024 22:26:04 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-7141feed424so596650b3a.2 for ; Tue, 20 Aug 2024 19:26:02 -0700 (PDT) Received: from stoup.. ([203.56.140.20]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127af1888esm9210774b3a.149.2024.08.20.19.25.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 19:26:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724207161; x=1724811961; 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=/AkyOxiQ4TXnW/njwRxZXuZWiuFAeAcYAa7CbQEQtFY=; b=klDUVP8eBfq9v2JfJGtK3FMah2hyg1jKq8VX2grggjbkX4/b1xZpBaxkFDqaRbpxSO GVcQeZHy8yTg5Q5Vpe7OTqeqpbCcNXUX+hOa1Io1NnDhG4SMVVMzn+Vt6t6tShyeUhE1 j7Tbw+ZDnDY9XSvbAs4RvC5SY7gQyuhWp41cMCx3UE+AZ7HZS+E7Jixbp7XMJgDrpQ7a VIDqWoHx7sKop35HWeBq3eBqpQAfecF02BmXHvZkDv+DNYBflllP/KXTHNJn43RJ/SZ2 FOxYKhEh1dsPsAWb2Mc0GOMpp75LnP/FQW9bHftDLBVWRZKToS/MDEx8/f+zm21TQ3xG sPaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724207161; x=1724811961; 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=/AkyOxiQ4TXnW/njwRxZXuZWiuFAeAcYAa7CbQEQtFY=; b=iS3KOVkf7I/8qXi6N/1pYMVqBsZu99f+u2OYEi8O7LlHnILrYN+G/xx841KqD/C33m 3dYDZP/IMebWPSgYOnSoXP4B760ujfVYEZvMFaWDiCd1cT8KV1xbLx7ulpr4mYOH3nna /TM8q1FBP7Hu94nKWwqj9z9XYf8IdCERNMxf8VgcP7Al8qSx+DG/Lojgzl/ByAnWCXfm ugUlsXZeTvwHzypEQqKj6t+hvlqrVWcKAW2b/wftMHGA5ZKBrX8/zeLwxfGMEmH5YW2A VsAEcAzl3VcgF4yOm+HaAGZyXIb8xFnHoLhxcRDErPDzAwwWu7CY358zxp/sXwx65Dn5 xa+A== X-Gm-Message-State: AOJu0YxyJPFLtKs8bu18sL1/AIF+tvXE9MiIhV7gehXXrMvp5wVdFph8 LEVybabpDgjkOAfZlJxZQDH5pjXkVgBEB92TzxkyBRE5E5hqAyvHuf6zSVQJ/bOXjelAaEviBxO VYhY= X-Google-Smtp-Source: AGHT+IEqPvyaMfUMiUScTKLqmqWoTARQPmnfxf+B0WuQgPe4ut/Ps2au5QJuCba8i8KtJktXSunx6A== X-Received: by 2002:a05:6a00:10c4:b0:702:3e36:b7c4 with SMTP id d2e1a72fcca58-7142342f6c1mr1358111b3a.5.1724207161207; Tue, 20 Aug 2024 19:26:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 3/5] target/i386: Split out gen_prepare_val_nz Date: Wed, 21 Aug 2024 12:25:46 +1000 Message-ID: <20240821022548.421745-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240821022548.421745-1-richard.henderson@linaro.org> References: <20240821022548.421745-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1724207233451116600 Split out the TCG_COND_TSTEQ logic from gen_prepare_eflags_z, and use it for CC_OP_BMILG* as well. Prepare for requiring both zero and non-zero senses. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson Message-Id: <20240801075845.573075-2-richard.henderson@linaro.org> --- target/i386/tcg/translate.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index b72864bf01..4af282e626 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -865,6 +865,18 @@ static CCPrepare gen_prepare_sign_nz(TCGv src, MemOp s= ize) } } =20 +static CCPrepare gen_prepare_val_nz(TCGv src, MemOp size, bool eqz) +{ + if (size =3D=3D MO_TL) { + return (CCPrepare) { .cond =3D eqz ? TCG_COND_EQ : TCG_COND_NE, + .reg =3D src }; + } else { + return (CCPrepare) { .cond =3D eqz ? TCG_COND_TSTEQ : TCG_COND_TST= NE, + .imm =3D MAKE_64BIT_MASK(0, 8 << size), + .reg =3D src }; + } +} + /* compute eflags.C, trying to store it in reg if not NULL */ static CCPrepare gen_prepare_eflags_c(DisasContext *s, TCGv reg) { @@ -908,8 +920,7 @@ static CCPrepare gen_prepare_eflags_c(DisasContext *s, = TCGv reg) =20 case CC_OP_BMILGB ... CC_OP_BMILGQ: size =3D s->cc_op - CC_OP_BMILGB; - gen_ext_tl(cpu_cc_src, cpu_cc_src, size, false); - return (CCPrepare) { .cond =3D TCG_COND_EQ, .reg =3D cpu_cc_src }; + return gen_prepare_val_nz(cpu_cc_src, size, true); =20 case CC_OP_ADCX: case CC_OP_ADCOX: @@ -1006,12 +1017,7 @@ static CCPrepare gen_prepare_eflags_z(DisasContext *= s, TCGv reg) default: { MemOp size =3D (s->cc_op - CC_OP_ADDB) & 3; - if (size =3D=3D MO_TL) { - return (CCPrepare) { .cond =3D TCG_COND_EQ, .reg =3D cpu_c= c_dst }; - } else { - return (CCPrepare) { .cond =3D TCG_COND_TSTEQ, .reg =3D cp= u_cc_dst, - .imm =3D (1ull << (8 << size)) - 1 }; - } + return gen_prepare_val_nz(cpu_cc_dst, size, true); } } } --=20 2.43.0 From nobody Sun Nov 24 10:33:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1724207189; cv=none; d=zohomail.com; s=zohoarc; b=gzVtjqIP0Yc0sGjPXLAAs9xY5DxodK8D1TjkESVmx3StMVDkXEgszUxeIGrTAw2eToAYWgLJeyFraHi8kaE8CBskcPrPdm3ugslpdGqXrCB+Xdy0nDN64HScDpL35DtbtUJx1IO1IvquCFZj/uYcQH5DN88thVkdG0smFkG7bxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724207189; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MzQq+okHryK0atM5VhMyw1ZWBZUUJZorcvwNEKWon4U=; b=buARlQzdeFfpyAqpDQISN/ueH1nE/Xv582z61Q77S6EYQq7XrEi3YAPfJ3o6jNZ27x14mA3gV8+jAKhN/p4xlRjBol2TO5J+uONqhjgyjZd92BG3bxKdeI16FiuVDXgs1lbuQQtThqfNbHqkP7cDfKwOCJpaDqnqG9y/7DRl+TA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724207189206681.649736871718; Tue, 20 Aug 2024 19:26:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sgb32-0000oE-SK; Tue, 20 Aug 2024 22:26:09 -0400 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 1sgb30-0000it-Rz for qemu-devel@nongnu.org; Tue, 20 Aug 2024 22:26:06 -0400 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sgb2y-0006Dz-Pw for qemu-devel@nongnu.org; Tue, 20 Aug 2024 22:26:06 -0400 Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3db19caec60so3891745b6e.1 for ; Tue, 20 Aug 2024 19:26:04 -0700 (PDT) Received: from stoup.. ([203.56.140.20]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127af1888esm9210774b3a.149.2024.08.20.19.26.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 19:26:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724207163; x=1724811963; 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=MzQq+okHryK0atM5VhMyw1ZWBZUUJZorcvwNEKWon4U=; b=yNxWZUbhGeas6gyHp9lmNoqadOLSd0jXjoQd+Qp9yN0jRXgEau80K6Sxikrq4yEpRJ IIooa1Lxa3ytceqDu8cxxCfzI5YziO2nuIYKqHmSFO6NK+wW9wq7cwnAoY1yaxfpDfFd 0qbrvLac7HrTyDNz4DKhUQbgF+Z7ALtuiJrfbI1mrh+dUuX/7vhHWJs3971RkPzJcwqj 9ILUHdleqMbAhu0/2gSjt8G4djKi3CKdmSO+2RPqvLexaC/lqCvo40zZBzPT4GEShvec x4E8KaB82q4QLrs4iOJUI64qW5fKsQqTkmMh4K4CffBbfgaunVpTBV5h39ul6FZVYMAO kG3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724207163; x=1724811963; 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=MzQq+okHryK0atM5VhMyw1ZWBZUUJZorcvwNEKWon4U=; b=wJ1tAaWWk3150KMV2ms0Xmy2xIcZasyGK8hEPTtOIA8Fmk+u8WEiwmdtv5MocvyvfL O/PwPc3vwTDtdxeSS9BCqAkZTX65fUIjBVYE/mEatggxX1w9NoxfThXom3Bf5+qprELk H4AwhkHoHsqPvxBKQ7pBdwaA1mL+pdPHZf/nLXXhSOznCSmmf/kEk5NfKnFZqsc617qa U5iqeEYtuwGgML488Af0CUN6JwwOPRNTbjhB9We7lgtkcYtQ2fPJan+rG8a+m7sjKE2P CxUljoHluOlwEk7tWgQjO6GCMMNyoKwK3xQNF63hpqJvZe9uqEhhQuMKFKtWSvbLuv9n as7Q== X-Gm-Message-State: AOJu0YzfgkIPmXhu1mW6SEV5vlXVA1zrIjhTrtnC+YxrfDJFjMZ8T5hz mcn2tg+SL8spi/LVk8L+Pu4iK1TdepuxaYy+nwraagi8DLQiWekuuM1dg0gWzNNa7JVs+Ujb2IY 7ZtE= X-Google-Smtp-Source: AGHT+IEhf6mfNsGUhGyQG356To4ct+NPhJHgeeBstI8HsvX1KGLMn27A02ToUTILb3vxqG8tznFAfw== X-Received: by 2002:a05:6808:1491:b0:3d9:2def:21b4 with SMTP id 5614622812f47-3de19526360mr1667062b6e.14.1724207163495; Tue, 20 Aug 2024 19:26:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 4/5] target/i386: Fix carry flag for BLSI Date: Wed, 21 Aug 2024 12:25:47 +1000 Message-ID: <20240821022548.421745-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240821022548.421745-1-richard.henderson@linaro.org> References: <20240821022548.421745-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::233; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x233.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1724207191321116600 BLSI has inverted semantics for C as compared to the other two BMI1 instructions, BLSMSK and BLSR. Introduce CC_OP_BLSI* for this purpose. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2175 Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20240801075845.573075-3-richard.henderson@linaro.org> --- target/i386/cpu.h | 5 +++++ target/i386/tcg/cc_helper.c | 18 ++++++++++++++++++ target/i386/tcg/translate.c | 5 +++++ tests/tcg/x86_64/test-2175.c | 24 ++++++++++++++++++++++++ target/i386/tcg/cc_helper_template.h.inc | 18 ++++++++++++++++++ target/i386/tcg/emit.c.inc | 2 +- tests/tcg/x86_64/Makefile.target | 1 + 7 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/x86_64/test-2175.c diff --git a/target/i386/cpu.h b/target/i386/cpu.h index c6cc035df3..14edd57a37 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1339,6 +1339,11 @@ typedef enum { CC_OP_BMILGL, CC_OP_BMILGQ, =20 + CC_OP_BLSIB, /* Z,S via CC_DST, C =3D SRC!=3D0; O=3D0; P,A undefined */ + CC_OP_BLSIW, + CC_OP_BLSIL, + CC_OP_BLSIQ, + /* * Note that only CC_OP_POPCNT (i.e. the one with MO_TL size) * is used or implemented, because the translation needs diff --git a/target/i386/tcg/cc_helper.c b/target/i386/tcg/cc_helper.c index 301ed95406..dbddaa2fcb 100644 --- a/target/i386/tcg/cc_helper.c +++ b/target/i386/tcg/cc_helper.c @@ -186,6 +186,13 @@ target_ulong helper_cc_compute_all(target_ulong dst, t= arget_ulong src1, case CC_OP_BMILGL: return compute_all_bmilgl(dst, src1); =20 + case CC_OP_BLSIB: + return compute_all_blsib(dst, src1); + case CC_OP_BLSIW: + return compute_all_blsiw(dst, src1); + case CC_OP_BLSIL: + return compute_all_blsil(dst, src1); + case CC_OP_ADCX: return compute_all_adcx(dst, src1, src2); case CC_OP_ADOX: @@ -216,6 +223,8 @@ target_ulong helper_cc_compute_all(target_ulong dst, ta= rget_ulong src1, return compute_all_sarq(dst, src1); case CC_OP_BMILGQ: return compute_all_bmilgq(dst, src1); + case CC_OP_BLSIQ: + return compute_all_blsiq(dst, src1); #endif } } @@ -308,6 +317,13 @@ target_ulong helper_cc_compute_c(target_ulong dst, tar= get_ulong src1, case CC_OP_BMILGL: return compute_c_bmilgl(dst, src1); =20 + case CC_OP_BLSIB: + return compute_c_blsib(dst, src1); + case CC_OP_BLSIW: + return compute_c_blsiw(dst, src1); + case CC_OP_BLSIL: + return compute_c_blsil(dst, src1); + #ifdef TARGET_X86_64 case CC_OP_ADDQ: return compute_c_addq(dst, src1); @@ -321,6 +337,8 @@ target_ulong helper_cc_compute_c(target_ulong dst, targ= et_ulong src1, return compute_c_shlq(dst, src1); case CC_OP_BMILGQ: return compute_c_bmilgq(dst, src1); + case CC_OP_BLSIQ: + return compute_c_blsiq(dst, src1); #endif } } diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 4af282e626..98f5fe61ed 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -304,6 +304,7 @@ static const uint8_t cc_op_live[CC_OP_NB] =3D { [CC_OP_SHLB ... CC_OP_SHLQ] =3D USES_CC_DST | USES_CC_SRC, [CC_OP_SARB ... CC_OP_SARQ] =3D USES_CC_DST | USES_CC_SRC, [CC_OP_BMILGB ... CC_OP_BMILGQ] =3D USES_CC_DST | USES_CC_SRC, + [CC_OP_BLSIB ... CC_OP_BLSIQ] =3D USES_CC_DST | USES_CC_SRC, [CC_OP_ADCX] =3D USES_CC_DST | USES_CC_SRC, [CC_OP_ADOX] =3D USES_CC_SRC | USES_CC_SRC2, [CC_OP_ADCOX] =3D USES_CC_DST | USES_CC_SRC | USES_CC_SRC2, @@ -922,6 +923,10 @@ static CCPrepare gen_prepare_eflags_c(DisasContext *s,= TCGv reg) size =3D s->cc_op - CC_OP_BMILGB; return gen_prepare_val_nz(cpu_cc_src, size, true); =20 + case CC_OP_BLSIB ... CC_OP_BLSIQ: + size =3D s->cc_op - CC_OP_BLSIB; + return gen_prepare_val_nz(cpu_cc_src, size, false); + case CC_OP_ADCX: case CC_OP_ADCOX: return (CCPrepare) { .cond =3D TCG_COND_NE, .reg =3D cpu_cc_dst, diff --git a/tests/tcg/x86_64/test-2175.c b/tests/tcg/x86_64/test-2175.c new file mode 100644 index 0000000000..aafd037bce --- /dev/null +++ b/tests/tcg/x86_64/test-2175.c @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* See https://gitlab.com/qemu-project/qemu/-/issues/2185 */ + +#include + +int test_setc(unsigned int x, unsigned int y) +{ + asm("blsi %1, %0; setc %b0" : "+r"(x) : "r"(y)); + return (unsigned char)x; +} + +int test_pushf(unsigned int x, unsigned int y) +{ + asm("blsi %1, %0; pushf; pop %q0" : "+r"(x) : "r"(y)); + return x & 1; +} + +int main() +{ + assert(test_setc(1, 0xedbf530a)); + assert(test_pushf(1, 0xedbf530a)); + return 0; +} + diff --git a/target/i386/tcg/cc_helper_template.h.inc b/target/i386/tcg/cc_= helper_template.h.inc index bb611feb04..c5425e57cf 100644 --- a/target/i386/tcg/cc_helper_template.h.inc +++ b/target/i386/tcg/cc_helper_template.h.inc @@ -235,6 +235,24 @@ static int glue(compute_c_bmilg, SUFFIX)(DATA_TYPE dst= , DATA_TYPE src1) return src1 =3D=3D 0; } =20 +static int glue(compute_all_blsi, SUFFIX)(DATA_TYPE dst, DATA_TYPE src1) +{ + int cf, pf, af, zf, sf, of; + + cf =3D (src1 !=3D 0); + pf =3D 0; /* undefined */ + af =3D 0; /* undefined */ + zf =3D (dst =3D=3D 0) * CC_Z; + sf =3D lshift(dst, 8 - DATA_BITS) & CC_S; + of =3D 0; + return cf | pf | af | zf | sf | of; +} + +static int glue(compute_c_blsi, SUFFIX)(DATA_TYPE dst, DATA_TYPE src1) +{ + return src1 !=3D 0; +} + #undef DATA_BITS #undef SIGN_MASK #undef DATA_TYPE diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 22a06897fb..9b50419918 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1304,7 +1304,7 @@ static void gen_BLSI(DisasContext *s, X86DecodedInsn = *decode) /* input in T1, which is ready for prepare_update2_cc */ tcg_gen_neg_tl(s->T0, s->T1); tcg_gen_and_tl(s->T0, s->T0, s->T1); - prepare_update2_cc(decode, s, CC_OP_BMILGB + ot); + prepare_update2_cc(decode, s, CC_OP_BLSIB + ot); } =20 static void gen_BLSMSK(DisasContext *s, X86DecodedInsn *decode) diff --git a/tests/tcg/x86_64/Makefile.target b/tests/tcg/x86_64/Makefile.t= arget index eda9bd7396..783ab5b21a 100644 --- a/tests/tcg/x86_64/Makefile.target +++ b/tests/tcg/x86_64/Makefile.target @@ -16,6 +16,7 @@ X86_64_TESTS +=3D noexec X86_64_TESTS +=3D cmpxchg X86_64_TESTS +=3D adox X86_64_TESTS +=3D test-1648 +X86_64_TESTS +=3D test-2175 TESTS=3D$(MULTIARCH_TESTS) $(X86_64_TESTS) test-x86_64 else TESTS=3D$(MULTIARCH_TESTS) --=20 2.43.0 From nobody Sun Nov 24 10:33:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1724207217; cv=none; d=zohomail.com; s=zohoarc; b=B/+QQLIlGxF/jsM/3BMwWocVtgzRJWpJztRJGPVrsXyLI606imTKE5VoetHLNixsKH3oqphBTcxGx82lyd0bOw2pvkaDO+rdh9rVouh3iq781pqhYZIGv41I4QWG2eTA+I7BYr+I6jGydT2pcWbbs1gQsMXCJnmFUeWXVCwJX7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724207217; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=w37pH7YuBGYOWjqIybzdzbU05nLwB6boAQ2yePJtIGM=; b=aPzc/Y/pt//3s4GykzN/mjBilhFkPIDK+sl5pwEkhwaNur5EfUlUMCnxep+hgRCWPAMW56J1MLbgDkFx3osPTK7i4yngfZeqg4kAHLNW+pjb8k0iAmfHv/6XDSAAuMsE0AVF6zUDV2EbTsYISY5gQgo5DSzRLulNXfQqByr1H6M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724207217018550.8981609787354; Tue, 20 Aug 2024 19:26:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sgb36-00014I-6g; Tue, 20 Aug 2024 22:26:12 -0400 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 1sgb33-0000vn-Uc for qemu-devel@nongnu.org; Tue, 20 Aug 2024 22:26:09 -0400 Received: from mail-oa1-x2f.google.com ([2001:4860:4864:20::2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sgb31-0006F5-IQ for qemu-devel@nongnu.org; Tue, 20 Aug 2024 22:26:09 -0400 Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-2703e8d3f7bso2178596fac.2 for ; Tue, 20 Aug 2024 19:26:06 -0700 (PDT) Received: from stoup.. ([203.56.140.20]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127af1888esm9210774b3a.149.2024.08.20.19.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 19:26:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724207166; x=1724811966; 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=w37pH7YuBGYOWjqIybzdzbU05nLwB6boAQ2yePJtIGM=; b=FgPjS0elR7adqfmFvdyCELWKXa10VB0afTjv/lBhF0120+G/hspjcrfLh7YYxIQ5qz Pnqm/EOHFR4RCD/Wj7CeVnAqgelhVsXeUEL86U/5kFhuLaaXUuhkIrrJVwGRVoDXc58V NkD/E03gLcn72QqBpVpE4o4EV/sYOAsrQWOsbMAx8ZXvEqOMP3oNvpfay51hGsBPE7Pp AekjuQsGoBHl/3nA6K3oUCYkmETtP7XxWI++ZUmihxXVmC2QnTwsBF3LKCjE49lzYRP6 9d1xP5FH9c54k2xy3ZbVeL3V5yA4LWysHXNYaPzB0gEhMejzbfAFhvniGEQRzkxKGLQX VTvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724207166; x=1724811966; 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=w37pH7YuBGYOWjqIybzdzbU05nLwB6boAQ2yePJtIGM=; b=AfLvile5NeGhPmNNyKk4mpVOaOssMfFUhjUWPnSilHIMJdir4mnegqLhIRWBtO+dZH HqyuAPrd4P2JgiZByiZB1FbBYFd6N5izj0Hm+eBpmFbiu88bzH2Z5YuAw9UkdKH3mg+Y k1UxWVQDWDNrExDsv28ronNxGZLit+InCKh7he3bt2HRu44RI4/Xu3KQuxApZDiCjYcM tj2sMm53TmWYsEHQncFwXm7a/0xBgINGsU45tgzGY8qdlOangxpykriL8+fPtnj9gPoE e9ZAC0MLoAyCYYBqfOw2+K+iWfM7PytSx4EwDsLLpt8TN2rJODGza8YWeHgUWUuPzEGB fuyw== X-Gm-Message-State: AOJu0YwOv8NO3YtURRVMh3E7n5hRuVfs6Y4AT9UATwpUw1qu7ULjM8ZY vMy3rcsZN2REX2cBKpEKNepo4uEVjRrbZhy9FE9jQYyYfGD0n0oASW1YAVocv2ZxGI2p5mX1eRd NXT4= X-Google-Smtp-Source: AGHT+IEWPdOVoSnv5hUqmi6fOvUVlTxyYQ/Zmo+uBXnjaaPFyDq4nVpatIbvBQLodFeL9Y+I+NUVHQ== X-Received: by 2002:a05:6870:169a:b0:270:4500:bdc2 with SMTP id 586e51a60fabf-2738be2e0f4mr966674fac.32.1724207165931; Tue, 20 Aug 2024 19:26:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell , Pierrick Bouvier Subject: [PULL 5/5] target/i386: Fix tss access size in switch_tss_ra Date: Wed, 21 Aug 2024 12:25:48 +1000 Message-ID: <20240821022548.421745-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240821022548.421745-1-richard.henderson@linaro.org> References: <20240821022548.421745-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:4860:4864:20::2f; envelope-from=richard.henderson@linaro.org; helo=mail-oa1-x2f.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1724207217396116600 Content-Type: text/plain; charset="utf-8" The two limit_max variables represent size - 1, just like the encoding in the GDT, thus the 'old' access was off by one. Access the minimal size of the new tss: the complete tss contains the iopb, which may be a larger block than the access api expects, and irrelevant because the iopb is not accessed during the switch itself. Fixes: 8b131065080a ("target/i386/tcg: use X86Access for TSS access") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2511 Signed-off-by: Richard Henderson Message-Id: <20240819074052.207783-1-richard.henderson@linaro.org> Reviewed-by: Peter Maydell Reviewed-by: Pierrick Bouvier --- target/i386/tcg/seg_helper.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/target/i386/tcg/seg_helper.c b/target/i386/tcg/seg_helper.c index bab552cd53..3b8fd827e1 100644 --- a/target/i386/tcg/seg_helper.c +++ b/target/i386/tcg/seg_helper.c @@ -378,7 +378,7 @@ static int switch_tss_ra(CPUX86State *env, int tss_sele= ctor, =20 /* X86Access avoids memory exceptions during the task switch */ mmu_index =3D cpu_mmu_index_kernel(env); - access_prepare_mmu(&old, env, env->tr.base, old_tss_limit_max, + access_prepare_mmu(&old, env, env->tr.base, old_tss_limit_max + 1, MMU_DATA_STORE, mmu_index, retaddr); =20 if (source =3D=3D SWITCH_TSS_CALL) { @@ -386,7 +386,8 @@ static int switch_tss_ra(CPUX86State *env, int tss_sele= ctor, probe_access(env, tss_base, 2, MMU_DATA_STORE, mmu_index, retaddr); } - access_prepare_mmu(&new, env, tss_base, tss_limit, + /* While true tss_limit may be larger, we don't access the iopb here. = */ + access_prepare_mmu(&new, env, tss_base, tss_limit_max + 1, MMU_DATA_LOAD, mmu_index, retaddr); =20 /* save the current state in the old TSS */ --=20 2.43.0