From nobody Sun Dec 29 19:22:57 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1720582227; cv=none; d=zohomail.com; s=zohoarc; b=a1nQbHg1nIcMIaTOMZA5XSMlx8Et74Alk45IgDCnlT0A+wn6vFXv1qrig7Ya/cJsgan658EJIXENcADxKLEF6swx8pO39+81GoNtCNm3wcrUolnM4v81JgxF0uNumURKrrEcgullyrkBgfb5eqH67SGUEHyZA6/u6oUA8KkcdGw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720582227; 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=Yqp8Kca9jeo/K5Zxv4t0koVy6btVrx9+gEVO+dirNNk=; b=eddu953hR0HXuaPaXACb1T1E0GeqW2qfimPcAcZAs+XWFk0/vheNuChz8CGha+V9X945KIKbwvGowiprilG6lxOYKwwNAHa9DnH9flY+gAVKd94Eb6Kz7Vt1H9Ajzd0+m7QbbS860cIeH3wlGdoQroX7i/iX52V1DJpnq7eA1cw= 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+importer2=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 1720582227691927.5848062288871; Tue, 9 Jul 2024 20:30:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRO0e-0001IO-Mg; Tue, 09 Jul 2024 23:28:48 -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 1sRO0b-00014R-EP for qemu-devel@nongnu.org; Tue, 09 Jul 2024 23:28:45 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sRO0L-0003ol-TR for qemu-devel@nongnu.org; Tue, 09 Jul 2024 23:28:45 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-70b0e7f6f8bso4156659b3a.3 for ; Tue, 09 Jul 2024 20:28:28 -0700 (PDT) Received: from stoup.. (174-21-76-141.tukw.qwest.net. [174.21.76.141]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b438f5679sm2687280b3a.90.2024.07.09.20.28.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jul 2024 20:28:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720582108; x=1721186908; 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=Yqp8Kca9jeo/K5Zxv4t0koVy6btVrx9+gEVO+dirNNk=; b=ItpXi5GcTSNEhRfM53Q2CZ0BTaxz3ptTHLXXWOBRIPm3VEnaizEKkn/tFyvlMHhs5a /JY15flXpxsARig0Luor5ijed+XqmqWs1PDDW+dU2kq3/xuWlYFbteL0HwXbZZHTMPBC Q5cCt/12r4WHUrknyXSshd9kOVnDRTzYEqB9N1VUGGe7GlrEO+c+cJB+nslr05oCGIHI S86EWwuPixrd2t/w0E5GJKsBnzQuH8Dz4qxWbx0mRR8p4l3tudMBeRAMbGJpIJMLCZgO UnJ9OJpewvbd8xY1JdTEkx+1teB32wUVWomo3aoafiRQVNK5GXk+ZMXoYn6HKXubeAV6 lp6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720582108; x=1721186908; 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=Yqp8Kca9jeo/K5Zxv4t0koVy6btVrx9+gEVO+dirNNk=; b=n/FMK5DwZBFdB7FfinhyOv0pyckxmB6keE1zX3/EJWtybMWtaKEaNa7Z8lt3/0Lc7A TxzyW0QxEsjZm5baSy4lXNQpRmVyOpLgkffLEtPrJe3qWZ63fuO8PNzGjGzsnpeCXqne /zBbUGbfotO6MqYY7vcXsN6r2Xk3Y5zUnW/GsDgO54TbX8fnQSx0M8l+w4i9vgQ1eU0Z P0ElVcC6oWwFRtLGhKRsTLPYPJK4M6PI16qhTML24zgPtB7/JBWWg5Qu0zHODdPCGZ1X MLuQ54GbGwAYPJuiN9CwMinFZEmobPnGRRvlKRYfdndYcZh1eilu8ZcMDNG8kr/d6QsS Vo4Q== X-Gm-Message-State: AOJu0YzdtM+vwCXDRq0b0ZneHN4bIGosPb64InVqoyQnISjDLmw/QZHs q7BpGlIfkiJyxJVPpmFJHORacQzmni6SK4+Z3P60lLHBEt+F0/7abou8WX+qbi+aKFXAv4OLDBk DGGo= X-Google-Smtp-Source: AGHT+IFLUD29yffT5cJpGs88RJlDRYYC8+Gqtr8VqtBz17Z69M0QP0ygTr1Qt78KEuGtJ9QNw+Fnvw== X-Received: by 2002:a05:6a00:21cd:b0:70a:f38c:74ba with SMTP id d2e1a72fcca58-70b435eaa3fmr5320187b3a.22.1720582107678; Tue, 09 Jul 2024 20:28:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-ppc@nongu.org, qemu-s390x@nongnu.org, qemu-riscv@nongnu.org, balaton@eik.bme.hu, max.chou@sifive.com Subject: [PATCH v2 12/13] target/s390x: Use set/clear_helper_retaddr in mem_helper.c Date: Tue, 9 Jul 2024 20:28:13 -0700 Message-ID: <20240710032814.104643-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240710032814.104643-1-richard.henderson@linaro.org> References: <20240710032814.104643-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x434.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 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, SUSPICIOUS_RECIPS=2.51 autolearn=no 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1720582228372116300 Content-Type: text/plain; charset="utf-8" Avoid a race condition with munmap in another thread. For access_memset and access_memmove, manage the value within the helper. For uses of access_{get,set}_byte, manage the value across the for loops. Signed-off-by: Richard Henderson --- target/s390x/tcg/mem_helper.c | 43 ++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c index a76eb6182f..eb1f8880cd 100644 --- a/target/s390x/tcg/mem_helper.c +++ b/target/s390x/tcg/mem_helper.c @@ -238,14 +238,14 @@ static void do_access_memset(CPUS390XState *env, vadd= r vaddr, char *haddr, static void access_memset(CPUS390XState *env, S390Access *desta, uint8_t byte, uintptr_t ra) { - + set_helper_retaddr(ra); do_access_memset(env, desta->vaddr1, desta->haddr1, byte, desta->size1, desta->mmu_idx, ra); - if (likely(!desta->size2)) { - return; + if (unlikely(desta->size2)) { + do_access_memset(env, desta->vaddr2, desta->haddr2, byte, + desta->size2, desta->mmu_idx, ra); } - do_access_memset(env, desta->vaddr2, desta->haddr2, byte, desta->size2, - desta->mmu_idx, ra); + clear_helper_retaddr(); } =20 static uint8_t access_get_byte(CPUS390XState *env, S390Access *access, @@ -366,6 +366,8 @@ static uint32_t do_helper_nc(CPUS390XState *env, uint32= _t l, uint64_t dest, access_prepare(&srca1, env, src, l, MMU_DATA_LOAD, mmu_idx, ra); access_prepare(&srca2, env, dest, l, MMU_DATA_LOAD, mmu_idx, ra); access_prepare(&desta, env, dest, l, MMU_DATA_STORE, mmu_idx, ra); + set_helper_retaddr(ra); + for (i =3D 0; i < l; i++) { const uint8_t x =3D access_get_byte(env, &srca1, i, ra) & access_get_byte(env, &srca2, i, ra); @@ -373,6 +375,8 @@ static uint32_t do_helper_nc(CPUS390XState *env, uint32= _t l, uint64_t dest, c |=3D x; access_set_byte(env, &desta, i, x, ra); } + + clear_helper_retaddr(); return c !=3D 0; } =20 @@ -407,6 +411,7 @@ static uint32_t do_helper_xc(CPUS390XState *env, uint32= _t l, uint64_t dest, return 0; } =20 + set_helper_retaddr(ra); for (i =3D 0; i < l; i++) { const uint8_t x =3D access_get_byte(env, &srca1, i, ra) ^ access_get_byte(env, &srca2, i, ra); @@ -414,6 +419,7 @@ static uint32_t do_helper_xc(CPUS390XState *env, uint32= _t l, uint64_t dest, c |=3D x; access_set_byte(env, &desta, i, x, ra); } + clear_helper_retaddr(); return c !=3D 0; } =20 @@ -441,6 +447,8 @@ static uint32_t do_helper_oc(CPUS390XState *env, uint32= _t l, uint64_t dest, access_prepare(&srca1, env, src, l, MMU_DATA_LOAD, mmu_idx, ra); access_prepare(&srca2, env, dest, l, MMU_DATA_LOAD, mmu_idx, ra); access_prepare(&desta, env, dest, l, MMU_DATA_STORE, mmu_idx, ra); + set_helper_retaddr(ra); + for (i =3D 0; i < l; i++) { const uint8_t x =3D access_get_byte(env, &srca1, i, ra) | access_get_byte(env, &srca2, i, ra); @@ -448,6 +456,8 @@ static uint32_t do_helper_oc(CPUS390XState *env, uint32= _t l, uint64_t dest, c |=3D x; access_set_byte(env, &desta, i, x, ra); } + + clear_helper_retaddr(); return c !=3D 0; } =20 @@ -484,11 +494,13 @@ static uint32_t do_helper_mvc(CPUS390XState *env, uin= t32_t l, uint64_t dest, } else if (!is_destructive_overlap(env, dest, src, l)) { access_memmove(env, &desta, &srca, ra); } else { + set_helper_retaddr(ra); for (i =3D 0; i < l; i++) { uint8_t byte =3D access_get_byte(env, &srca, i, ra); =20 access_set_byte(env, &desta, i, byte, ra); } + clear_helper_retaddr(); } =20 return env->cc_op; @@ -514,10 +526,12 @@ void HELPER(mvcrl)(CPUS390XState *env, uint64_t l, ui= nt64_t dest, uint64_t src) access_prepare(&srca, env, src, l, MMU_DATA_LOAD, mmu_idx, ra); access_prepare(&desta, env, dest, l, MMU_DATA_STORE, mmu_idx, ra); =20 + set_helper_retaddr(ra); for (i =3D l - 1; i >=3D 0; i--) { uint8_t byte =3D access_get_byte(env, &srca, i, ra); access_set_byte(env, &desta, i, byte, ra); } + clear_helper_retaddr(); } =20 /* move inverse */ @@ -534,11 +548,13 @@ void HELPER(mvcin)(CPUS390XState *env, uint32_t l, ui= nt64_t dest, uint64_t src) src =3D wrap_address(env, src - l + 1); access_prepare(&srca, env, src, l, MMU_DATA_LOAD, mmu_idx, ra); access_prepare(&desta, env, dest, l, MMU_DATA_STORE, mmu_idx, ra); + + set_helper_retaddr(ra); for (i =3D 0; i < l; i++) { const uint8_t x =3D access_get_byte(env, &srca, l - i - 1, ra); - access_set_byte(env, &desta, i, x, ra); } + clear_helper_retaddr(); } =20 /* move numerics */ @@ -555,12 +571,15 @@ void HELPER(mvn)(CPUS390XState *env, uint32_t l, uint= 64_t dest, uint64_t src) access_prepare(&srca1, env, src, l, MMU_DATA_LOAD, mmu_idx, ra); access_prepare(&srca2, env, dest, l, MMU_DATA_LOAD, mmu_idx, ra); access_prepare(&desta, env, dest, l, MMU_DATA_STORE, mmu_idx, ra); + + set_helper_retaddr(ra); for (i =3D 0; i < l; i++) { const uint8_t x =3D (access_get_byte(env, &srca1, i, ra) & 0x0f) | (access_get_byte(env, &srca2, i, ra) & 0xf0); =20 access_set_byte(env, &desta, i, x, ra); } + clear_helper_retaddr(); } =20 /* move with offset */ @@ -580,6 +599,8 @@ void HELPER(mvo)(CPUS390XState *env, uint32_t l, uint64= _t dest, uint64_t src) =20 /* Handle rightmost byte */ byte_dest =3D cpu_ldub_data_ra(env, dest + len_dest - 1, ra); + + set_helper_retaddr(ra); byte_src =3D access_get_byte(env, &srca, len_src - 1, ra); byte_dest =3D (byte_dest & 0x0f) | (byte_src << 4); access_set_byte(env, &desta, len_dest - 1, byte_dest, ra); @@ -595,6 +616,7 @@ void HELPER(mvo)(CPUS390XState *env, uint32_t l, uint64= _t dest, uint64_t src) byte_dest |=3D byte_src << 4; access_set_byte(env, &desta, i, byte_dest, ra); } + clear_helper_retaddr(); } =20 /* move zones */ @@ -611,12 +633,15 @@ void HELPER(mvz)(CPUS390XState *env, uint32_t l, uint= 64_t dest, uint64_t src) access_prepare(&srca1, env, src, l, MMU_DATA_LOAD, mmu_idx, ra); access_prepare(&srca2, env, dest, l, MMU_DATA_LOAD, mmu_idx, ra); access_prepare(&desta, env, dest, l, MMU_DATA_STORE, mmu_idx, ra); + + set_helper_retaddr(ra); for (i =3D 0; i < l; i++) { const uint8_t x =3D (access_get_byte(env, &srca1, i, ra) & 0xf0) | (access_get_byte(env, &srca2, i, ra) & 0x0f); =20 access_set_byte(env, &desta, i, x, ra); } + clear_helper_retaddr(); } =20 /* compare unsigned byte arrays */ @@ -961,15 +986,19 @@ uint32_t HELPER(mvst)(CPUS390XState *env, uint32_t r1= , uint32_t r2) */ access_prepare(&srca, env, s, len, MMU_DATA_LOAD, mmu_idx, ra); access_prepare(&desta, env, d, len, MMU_DATA_STORE, mmu_idx, ra); + + set_helper_retaddr(ra); for (i =3D 0; i < len; i++) { const uint8_t v =3D access_get_byte(env, &srca, i, ra); =20 access_set_byte(env, &desta, i, v, ra); if (v =3D=3D c) { + clear_helper_retaddr(); set_address_zero(env, r1, d + i); return 1; } } + clear_helper_retaddr(); set_address_zero(env, r1, d + len); set_address_zero(env, r2, s + len); return 3; @@ -1060,6 +1089,7 @@ static inline uint32_t do_mvcl(CPUS390XState *env, *dest =3D wrap_address(env, *dest + len); } else { access_prepare(&desta, env, *dest, len, MMU_DATA_STORE, mmu_idx, r= a); + set_helper_retaddr(ra); =20 /* The remaining length selects the padding byte. */ for (i =3D 0; i < len; (*destlen)--, i++) { @@ -1069,6 +1099,7 @@ static inline uint32_t do_mvcl(CPUS390XState *env, access_set_byte(env, &desta, i, pad >> 8, ra); } } + clear_helper_retaddr(); *dest =3D wrap_address(env, *dest + len); } =20 --=20 2.43.0